QGIS API Documentation  3.0.2-Girona (307d082)
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  virtual 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 
269  private slots:
270  void onTextChanged( const QString &text );
271  void updateBusySpinner();
272  void updateClearIcon();
273 
274  private:
275  QIcon mClearIcon;
276  QAction *mClearAction = nullptr;
277  QAction *mSearchAction = nullptr;
278  QAction *mBusySpinnerAction = nullptr;
279 
280  bool mClearButtonVisible = true;
281  bool mShowSpinner = false;
282 
283  ClearMode mClearMode = ClearToNull;
284 
285  QString mNullValue;
286  QString mDefaultValue;
287  QString mStyleSheet;
288  bool mFocusInEvent = false;
289  bool mSelectOnFocus = false;
290 
291  QgsAnimatedIcon *mBusySpinnerAnimatedIcon = nullptr;
292 
294  bool shouldShowClear() const;
295 };
296 
298 
305 class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
306 {
307  Q_OBJECT
308 
309  public:
310 
311  QgsSpinBoxLineEdit( QWidget *parent = nullptr )
312  : QgsFilterLineEdit( parent )
313  {}
314 
315  public slots:
316 
317  void clearValue() override
318  {
319  // don't change the value - let spin boxes handle that by detecting cleared() signal
320  setCursor( Qt::IBeamCursor );
321  setModified( true );
322  emit cleared();
323  }
324 };
326 
327 #endif // QGSFILTERLINEEDIT_H
ClearMode clearMode() const
Returns the clear mode for the widget.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
bool showClearButton() const
Returns true if the widget&#39;s clear button is visible.
void setDefaultValue(const QString &defaultValue)
Sets the default value for the widget.
bool showSearchIcon() const
Returns if a search icon shall be shown on the left of the image when no text is entered.
QString defaultValue() const
Returns the default value for the widget.
void setClearMode(ClearMode mode)
Sets the clear mode for the widget.
Reset value to default value (see defaultValue() )
QString nullValue() const
Returns the string used for representating null values in the widget.
#define SIP_SKIP
Definition: qgis_sip.h:119
ClearMode
Behavior when clearing value of widget.
#define SIP_END
Definition: qgis_sip.h:175
QLineEdit subclass with built in support for clearing the widget&#39;s value and handling custom null val...
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
bool isNull() const
Determine if the current text represents null.
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.
QString value() const
Returns the text of this edit with support for handling null values.