QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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.h"
24 #include "qgis_gui.h"
25 
26 class QToolButton;
27 class QgsAnimatedIcon;
28 
39 class 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;
48  SIP_END
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 
63  enum ClearMode
64  {
65  ClearToNull = 0,
67  };
68  Q_ENUM( ClearMode )
69 
70 
75  QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &nullValue = QString() );
76 
82  bool showClearButton() const { return mClearButtonVisible; }
83 
90  void setShowClearButton( bool visible );
91 
98  ClearMode clearMode() const { return mClearMode; }
99 
106  void setClearMode( ClearMode mode ) { mClearMode = mode; }
107 
115  void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
116 
122  QString nullValue() const { return mNullValue; }
123 
130  void setShowSearchIcon( bool visible );
131 
137  bool showSearchIcon() const { return static_cast< bool >( mSearchAction ); }
138 
148  void setDefaultValue( const QString &defaultValue ) { mDefaultValue = defaultValue; }
149 
158  QString defaultValue() const { return mDefaultValue; }
159 
167  void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
168 
177  QString value() const { return isNull() ? QString() : text(); }
178 
185  inline bool isNull() const { return text() == mNullValue; }
186 
193  bool showSpinner() const;
194 
201  void setShowSpinner( bool showSpinner );
202 
208  bool selectOnFocus() const;
209 
215  void setSelectOnFocus( bool selectOnFocus );
216 
217 
224  bool event( QEvent *event ) override;
225 
226  public slots:
227 
233  virtual void clearValue();
234 
235  signals:
236 
241  void cleared();
242 
248  void valueChanged( const QString &value );
249 
256  void showSpinnerChanged();
257 
258 
264  void selectOnFocusChanged();
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  QIcon mClearIcon;
277  QAction *mClearAction = nullptr;
278  QAction *mSearchAction = nullptr;
279  QAction *mBusySpinnerAction = nullptr;
280 
281  bool mClearButtonVisible = true;
282  bool mShowSpinner = false;
283 
284  ClearMode mClearMode = ClearToNull;
285 
286  QString mNullValue;
287  QString mDefaultValue;
288  QString mStyleSheet;
289  bool mWaitingForMouseRelease = false;
290  bool mSelectOnFocus = false;
291 
292  QgsAnimatedIcon *mBusySpinnerAnimatedIcon = nullptr;
293 
295  bool shouldShowClear() const;
296 
297  friend class TestQgsFeatureListComboBox;
298 };
299 
301 
308 class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
309 {
310  Q_OBJECT
311 
312  public:
313 
314  QgsSpinBoxLineEdit( QWidget *parent = nullptr )
315  : QgsFilterLineEdit( parent )
316  {}
317 
318  public slots:
319 
320  void clearValue() override
321  {
322  // don't change the value - let spin boxes handle that by detecting cleared() signal
323  setCursor( Qt::IBeamCursor );
324  setModified( true );
325  emit cleared();
326  }
327 
328  protected:
329  void focusInEvent( QFocusEvent *e ) override;
330 };
332 
333 #endif // QGSFILTERLINEEDIT_H
QString defaultValue() const
Returns the default value for the widget.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
bool showSearchIcon() const
Returns if a search icon shall be shown on the left of the image when no text is entered.
void setDefaultValue(const QString &defaultValue)
Sets the default value for the widget.
ClearMode clearMode() const
Returns the clear mode for the widget.
void setClearMode(ClearMode mode)
Sets the clear mode for the widget.
QString nullValue() const
Returns the string used for representating null values in the widget.
QString value() const
Returns the text of this edit with support for handling null values.
Reset value to default value (see defaultValue() )
#define SIP_SKIP
Definition: qgis_sip.h:119
ClearMode
Behavior when clearing value of widget.
#define SIP_END
Definition: qgis_sip.h:182
QLineEdit subclass with built in support for clearing the widget&#39;s value and handling custom null val...
bool isNull() const
Determine if the current text represents null.
Animated icon is keeping an animation running if there are listeners connected to frameChanged...
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
void setNullValue(const QString &nullValue)
Sets the string representation for null values in the widget.
void setValue(const QString &value)
Sets the current text for the widget with support for handling null values.