QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
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 )
56 Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
57 Q_PROPERTY( bool showSearchIcon READ showSearchIcon WRITE setShowSearchIcon )
58 Q_PROPERTY( bool showSpinner READ showSpinner WRITE setShowSpinner NOTIFY showSpinnerChanged )
59
60 public:
61
64 {
65 ClearToNull = 0,
67 };
68 Q_ENUM( ClearMode )
69
70
75 QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &nullValue = QString() );
76
81 bool showClearButton() const { return mClearButtonVisible; }
82
88 void setShowClearButton( bool visible );
89
95 ClearMode clearMode() const { return mClearMode; }
96
102 void setClearMode( ClearMode mode ) { mClearMode = mode; }
103
111 void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
112
118 QString nullValue() const { return mNullValue; }
119
125 void setShowSearchIcon( bool visible );
126
131 bool showSearchIcon() const { return static_cast< bool >( mSearchAction ); }
132
141 void setDefaultValue( const QString &defaultValue );
142
150 QString defaultValue() const { return mDefaultValue; }
151
159 void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
160
169 QString value() const { return isNull() ? QString() : text(); }
170
177 inline bool isNull() const { return text() == mNullValue; }
178
184 bool showSpinner() const;
185
191 void setShowSpinner( bool showSpinner );
192
197 bool selectOnFocus() const;
198
203 void setSelectOnFocus( bool selectOnFocus );
204
210 bool event( QEvent *event ) override;
211
216 bool hasStateStored() const {return mLineEditState.hasStateStored;}
217
218 public slots:
219
224 virtual void clearValue();
225
230 void storeState();
231
236 void restoreState();
237
238 signals:
239
244 void cleared();
245
251 void valueChanged( const QString &value );
252
259
260
266
267 protected:
268 void focusInEvent( QFocusEvent *e ) override;
269 void mouseReleaseEvent( QMouseEvent *e ) override;
270
271 private slots:
272 void onTextChanged( const QString &text );
273 void updateBusySpinner();
274 void updateClearIcon();
275
276 private:
277 struct LineEditState
278 {
279 bool hasStateStored = false;
280 QString text;
281 int selectionStart;
282 int selectionLength;
283 int cursorPosition;
284 };
285
286 QIcon mClearIcon;
287 QAction *mClearAction = nullptr;
288 QAction *mSearchAction = nullptr;
289 QAction *mBusySpinnerAction = nullptr;
290
291 bool mClearButtonVisible = true;
292 bool mShowSpinner = false;
293
294 ClearMode mClearMode = ClearToNull;
295
296 QString mNullValue;
297 QString mDefaultValue;
298 QString mStyleSheet;
299 bool mWaitingForMouseRelease = false;
300 bool mSelectOnFocus = false;
301
302 LineEditState mLineEditState;
303
304 QgsAnimatedIcon *mBusySpinnerAnimatedIcon = nullptr;
305
307 bool shouldShowClear() const;
308
309 friend class TestQgsFeatureListComboBox;
310};
311
313
320class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
321{
322 Q_OBJECT
323
324 public:
325
326 QgsSpinBoxLineEdit( QWidget *parent = nullptr )
327 : QgsFilterLineEdit( parent )
328 {}
329
330 public slots:
331
332 void clearValue() override
333 {
334 // don't change the value - let spin boxes handle that by detecting cleared() signal
335 setCursor( Qt::IBeamCursor );
336 setModified( true );
337 emit cleared();
338 }
339
340 protected:
341 void focusInEvent( QFocusEvent *e ) override;
342};
344
345#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