QGIS API Documentation  2.99.0-Master (19b062c)
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 "qgis.h"
23 #include "qgis_gui.h"
24 
25 class QToolButton;
26 class QgsAnimatedIcon;
27 
38 class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
39 {
40 
41 #ifdef SIP_RUN
43  if ( qobject_cast<QgsFilterLineEdit *>( sipCpp ) )
44  sipType = sipType_QgsFilterLineEdit;
45  else
46  sipType = NULL;
47  SIP_END
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:
60 
62  enum ClearMode
63  {
64  ClearToNull = 0,
66  };
67  Q_ENUM( ClearMode );
68 
74  QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = 0, const QString &nullValue = QString() );
75 
81  bool showClearButton() const { return mClearButtonVisible; }
82 
89  void setShowClearButton( bool visible );
90 
97  ClearMode clearMode() const { return mClearMode; }
98 
105  void setClearMode( ClearMode mode ) { mClearMode = mode; }
106 
114  void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
115 
121  QString nullValue() const { return mNullValue; }
122 
129  void setShowSearchIcon( bool visible );
130 
136  bool showSearchIcon() const { return mSearchIconVisible; }
137 
147  void setDefaultValue( const QString &defaultValue ) { mDefaultValue = defaultValue; }
148 
157  QString defaultValue() const { return mDefaultValue; }
158 
166  void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
167 
176  QString value() const { return isNull() ? QString() : text(); }
177 
184  inline bool isNull() const { return text() == mNullValue; }
185 
192  bool showSpinner() const;
193 
200  void setShowSpinner( bool showSpinner );
201 
207  bool selectOnFocus() const;
208 
214  void setSelectOnFocus( bool selectOnFocus );
215 
216  public slots:
217 
223  virtual void clearValue();
224 
225  signals:
226 
231  void cleared();
232 
238  void valueChanged( const QString &value );
239 
246  void showSpinnerChanged();
247 
248 
254  void selectOnFocusChanged();
255 
256  protected:
257  void mousePressEvent( QMouseEvent *e ) override;
258  void mouseMoveEvent( QMouseEvent *e ) override;
259  void focusInEvent( QFocusEvent *e ) override;
260  void paintEvent( QPaintEvent *e ) override;
261  void leaveEvent( QEvent *e ) override;
262 
263  private slots:
264  void onTextChanged( const QString &text );
265  void updateBusySpinner();
266 
267  private:
268 
269  bool mClearButtonVisible = true;
270  bool mSearchIconVisible = false;
271  bool mShowSpinner = false;
272 
273  ClearMode mClearMode = ClearToNull;
274 
275  QString mNullValue;
276  QString mDefaultValue;
277  QString mStyleSheet;
278  bool mFocusInEvent = false;
279  bool mClearHover = false;
280  bool mSelectOnFocus = false;
281 
282  QSize mClearIconSize;
283  QPixmap mClearIconPixmap;
284  QPixmap mClearHoverPixmap;
285 
286  QSize mSearchIconSize;
287  QPixmap mSearchIconPixmap;
288  QgsAnimatedIcon *mBusySpinner = nullptr;
289 
291  bool shouldShowClear() const;
292 
293  QRect clearRect() const;
294  QRect searchRect() const;
295  QRect busySpinnerRect() const;
296 };
297 
299 
306 class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
307 {
308  Q_OBJECT
309 
310  public:
311 
312  QgsSpinBoxLineEdit( QWidget *parent = nullptr )
313  : QgsFilterLineEdit( parent )
314  {}
315 
316  public slots:
317 
318  virtual void clearValue() override
319  {
320  // don't change the value - let spin boxes handle that by detecting cleared() signal
321  setCursor( Qt::IBeamCursor );
322  setModified( true );
323  emit cleared();
324  }
325 };
327 
328 #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.