QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 <QLineEdit>
22#include <QIcon>
23#include "qgis_sip.h"
24#include "qgis_gui.h"
25
26class QToolButton;
27class QgsAnimatedIcon;
28
39class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
40{
41#ifdef SIP_RUN
43 if ( qobject_cast<QgsFilterLineEdit *>( sipCpp ) )
44 sipType = sipType_QgsFilterLineEdit;
45 else
46 sipType = NULL;
48#endif
49
50 Q_OBJECT
51 Q_PROPERTY( ClearMode clearMode READ clearMode WRITE setClearMode )
52 Q_PROPERTY( QString nullValue READ nullValue WRITE setNullValue )
53 Q_PROPERTY( QString defaultValue READ defaultValue WRITE setDefaultValue )
54 Q_PROPERTY( QString value READ value WRITE setValue NOTIFY valueChanged )
55 Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
56 Q_PROPERTY( bool showSearchIcon READ showSearchIcon WRITE setShowSearchIcon )
57 Q_PROPERTY( bool showSpinner READ showSpinner WRITE setShowSpinner NOTIFY showSpinnerChanged )
58
59 public:
62 {
63 ClearToNull = 0,
65 };
66 Q_ENUM( ClearMode )
67
68
73 QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &nullValue = QString() );
74
79 bool showClearButton() const { return mClearButtonVisible; }
80
86 void setShowClearButton( bool visible );
87
93 ClearMode clearMode() const { return mClearMode; }
94
100 void setClearMode( ClearMode mode ) { mClearMode = mode; }
101
109 void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
110
116 QString nullValue() const { return mNullValue; }
117
123 void setShowSearchIcon( bool visible );
124
129 bool showSearchIcon() const { return static_cast<bool>( mSearchAction ); }
130
139 void setDefaultValue( const QString &defaultValue );
140
148 QString defaultValue() const { return mDefaultValue; }
149
157 void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
158
167 QString value() const { return isNull() ? QString() : text(); }
168
175 inline bool isNull() const { return text() == mNullValue; }
176
182 bool showSpinner() const;
183
189 void setShowSpinner( bool showSpinner );
190
195 bool selectOnFocus() const;
196
201 void setSelectOnFocus( bool selectOnFocus );
202
208 bool event( QEvent *event ) override;
209
214 bool hasStateStored() const { return mLineEditState.hasStateStored; }
215
216 public slots:
217
222 virtual void clearValue();
223
228 void storeState();
229
234 void restoreState();
235
236 signals:
237
242 void cleared();
243
249 void valueChanged( const QString &value );
250
257
258
264
265 protected:
266 void focusInEvent( QFocusEvent *e ) override;
267 void mouseReleaseEvent( QMouseEvent *e ) override;
268
269 private slots:
270 void onTextChanged( const QString &text );
271 void updateBusySpinner();
272 void updateClearIcon();
273
274 private:
275 struct LineEditState
276 {
277 bool hasStateStored = false;
278 QString text;
279 int selectionStart;
280 int selectionLength;
281 int cursorPosition;
282 };
283
284 QIcon mClearIcon;
285 QAction *mClearAction = nullptr;
286 QAction *mSearchAction = nullptr;
287 QAction *mBusySpinnerAction = nullptr;
288
289 bool mClearButtonVisible = true;
290 bool mShowSpinner = false;
291
292 ClearMode mClearMode = ClearToNull;
293
294 QString mNullValue;
295 QString mDefaultValue;
296 QString mStyleSheet;
297 bool mWaitingForMouseRelease = false;
298 bool mSelectOnFocus = false;
299
300 LineEditState mLineEditState;
301
302 QgsAnimatedIcon *mBusySpinnerAnimatedIcon = nullptr;
303
305 bool shouldShowClear() const;
306
307 friend class TestQgsFeatureListComboBox;
308};
309
311
318class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
319{
320 Q_OBJECT
321
322 public:
323 QgsSpinBoxLineEdit( QWidget *parent = nullptr )
324 : QgsFilterLineEdit( parent )
325 {}
326
327 public slots:
328
329 void clearValue() override
330 {
331 // don't change the value - let spin boxes handle that by detecting cleared() signal
332 setCursor( Qt::IBeamCursor );
333 setModified( true );
334 emit cleared();
335 }
336
337 protected:
338 void focusInEvent( QFocusEvent *e ) override;
339};
341
342#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.
@ 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.
bool hasStateStored() const
Returns if a state is already saved.
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.
QString value() const
Returns the text of this edit with support for handling null values.
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:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_END
Definition qgis_sip.h:208