QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsfilterlineedit.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfilterlineedit.h
3 ------------------------
4 begin : October 27, 2012
5 copyright : (C) 2012 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSFILTERLINEEDIT_H
19#define QGSFILTERLINEEDIT_H
20
21#include "qgis_gui.h"
22#include "qgis_sip.h"
23
24#include <QIcon>
25#include <QLineEdit>
26
27class QToolButton;
28class QgsAnimatedIcon;
29
40class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
41{
42#ifdef SIP_RUN
44 if ( qobject_cast<QgsFilterLineEdit *>( sipCpp ) )
45 sipType = sipType_QgsFilterLineEdit;
46 else
47 sipType = NULL;
49#endif
50
51 Q_OBJECT
52 Q_PROPERTY( ClearMode clearMode READ clearMode WRITE setClearMode )
53 Q_PROPERTY( QString nullValue READ nullValue WRITE setNullValue )
54 Q_PROPERTY( QString defaultValue READ defaultValue WRITE setDefaultValue )
55 Q_PROPERTY( QString value READ value WRITE setValue NOTIFY valueChanged )
57 Q_PROPERTY( bool showSearchIcon READ showSearchIcon WRITE setShowSearchIcon )
58 Q_PROPERTY( bool showSpinner READ showSpinner WRITE setShowSpinner NOTIFY showSpinnerChanged )
59
60 public:
67 Q_ENUM( ClearMode )
68
69
74 QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &nullValue = QString() );
75
80 bool showClearButton() const { return mClearButtonVisible; }
81
87 void setShowClearButton( bool visible );
88
94 ClearMode clearMode() const { return mClearMode; }
95
101 void setClearMode( ClearMode mode ) { mClearMode = mode; }
102
110 void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
111
117 QString nullValue() const { return mNullValue; }
118
124 void setShowSearchIcon( bool visible );
125
130 bool showSearchIcon() const { return static_cast<bool>( mSearchAction ); }
131
140 void setDefaultValue( const QString &defaultValue );
141
149 QString defaultValue() const { return mDefaultValue; }
150
158 void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
159
168 QString value() const { return isNull() ? QString() : text(); }
169
176 inline bool isNull() const { return text() == mNullValue; }
177
183 bool showSpinner() const;
184
190 void setShowSpinner( bool showSpinner );
191
196 bool selectOnFocus() const;
197
202 void setSelectOnFocus( bool selectOnFocus );
203
209 bool event( QEvent *event ) override;
210
215 bool hasStateStored() const { return mLineEditState.hasStateStored; }
216
217 public slots:
218
223 virtual void clearValue();
224
229 void storeState();
230
235 void restoreState();
236
237 signals:
238
243 void cleared();
244
250 void valueChanged( const QString &value );
251
258
259
265
266 protected:
267 void focusInEvent( QFocusEvent *e ) override;
268 void mouseReleaseEvent( QMouseEvent *e ) override;
269
270 private slots:
271 void onTextChanged( const QString &text );
272 void updateBusySpinner();
273 void updateClearIcon();
274
275 private:
276 struct LineEditState
277 {
278 bool hasStateStored = false;
279 QString text;
280 int selectionStart;
281 int selectionLength;
282 int cursorPosition;
283 };
284
285 QIcon mClearIcon;
286 QAction *mClearAction = nullptr;
287 QAction *mSearchAction = nullptr;
288 QAction *mBusySpinnerAction = nullptr;
289
290 bool mClearButtonVisible = true;
291 bool mShowSpinner = false;
292
293 ClearMode mClearMode = ClearToNull;
294
295 QString mNullValue;
296 QString mDefaultValue;
297 QString mStyleSheet;
298 bool mWaitingForMouseRelease = false;
299 bool mSelectOnFocus = false;
300
301 LineEditState mLineEditState;
302
303 QgsAnimatedIcon *mBusySpinnerAnimatedIcon = nullptr;
304
306 bool shouldShowClear() const;
307
309};
310
312
319class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
320{
321 Q_OBJECT
322
323 public:
324 QgsSpinBoxLineEdit( QWidget *parent = nullptr )
325 : QgsFilterLineEdit( parent )
326 {}
327
328 public slots:
329
330 void clearValue() override
331 {
332 // don't change the value - let spin boxes handle that by detecting cleared() signal
333 setCursor( Qt::IBeamCursor );
334 setModified( true );
335 emit cleared();
336 }
337
338 protected:
339 void focusInEvent( QFocusEvent *e ) override;
340};
342
343#endif // QGSFILTERLINEEDIT_H
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void focusInEvent(QFocusEvent *e) override
void selectOnFocusChanged()
Will select all text when this widget receives the focus.
void showSpinnerChanged()
Show a spinner icon.
ClearMode clearMode() const
Returns the clear mode for the widget.
bool showClearButton() const
Returns true if the widget's clear button is visible.
virtual void clearValue()
Clears the widget and resets it to the null value.
bool showSearchIcon() const
Returns if a search icon shall be shown on the left of the image when no text is entered.
ClearMode
Behavior when clearing value of widget.
@ ClearToNull
Reset value to null.
@ ClearToDefault
Reset value to default value (see defaultValue() ).
bool isNull() const
Determine if the current text represents null.
QString nullValue() const
Returns the string used for representing null values in the widget.
void setValue(const QString &value)
Sets the current text for the widget with support for handling null values.
void setShowSearchIcon(bool visible)
Define if a search icon shall be shown on the left of the image when no text is entered.
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
friend class TestQgsFeatureListComboBox
QgsFilterLineEdit(QWidget *parent=nullptr, const QString &nullValue=QString())
Constructor for QgsFilterLineEdit.
bool hasStateStored() const
Returns if a state is already saved.
void mouseReleaseEvent(QMouseEvent *e) override
QString defaultValue() const
Returns the default value for the widget.
void setNullValue(const QString &nullValue)
Sets the string representation for null values in the widget.
void cleared()
Emitted when the widget is cleared.
void setDefaultValue(const QString &defaultValue)
Sets the default value for the widget.
QString value() const
Returns the text of this edit with support for handling null values.
void setShowSpinner(bool showSpinner)
Show a spinner icon.
void setClearMode(ClearMode mode)
Sets the clear mode for the widget.
void valueChanged(const QString &value)
Same as textChanged() but with support for null values.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_END
Definition qgis_sip.h:216