QGIS API Documentation  2.99.0-Master (90ae728)
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_gui.h"
23 
24 class QToolButton;
25 
35 class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
36 {
37  Q_OBJECT
38  Q_ENUMS( ClearMode )
39  Q_PROPERTY( ClearMode clearMode READ clearMode WRITE setClearMode )
40  Q_PROPERTY( QString nullValue READ nullValue WRITE setNullValue )
41  Q_PROPERTY( QString defaultValue READ defaultValue WRITE setDefaultValue )
42  Q_PROPERTY( QString value READ value WRITE setValue NOTIFY valueChanged )
43  Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
44  Q_PROPERTY( bool showSearchIcon READ showSearchIcon WRITE setShowSearchIcon )
45 
46  public:
47 
49  enum ClearMode
50  {
51  ClearToNull = 0,
53  };
54 
59  QgsFilterLineEdit( QWidget* parent = nullptr, const QString& nullValue = QString::null );
60 
65  bool showClearButton() const { return mClearButtonVisible; }
66 
72  void setShowClearButton( bool visible );
73 
79  ClearMode clearMode() const { return mClearMode; }
80 
86  void setClearMode( ClearMode mode ) { mClearMode = mode; }
87 
94  void setNullValue( const QString& nullValue ) { mNullValue = nullValue; }
95 
100  QString nullValue() const { return mNullValue; }
101 
107  void setShowSearchIcon( bool visible );
108 
113  bool showSearchIcon() const { return mSearchIconVisible; }
114 
123  void setDefaultValue( const QString& defaultValue ) { mDefaultValue = defaultValue; }
124 
132  QString defaultValue() const { return mDefaultValue; }
133 
141  void setValue( const QString& value ) { setText( value.isNull() ? mNullValue : value ); }
142 
151  QString value() const { return isNull() ? QString::null : text(); }
152 
159  inline bool isNull() const { return text() == mNullValue; }
160 
161  public slots:
162 
167  virtual void clearValue();
168 
169  signals:
170 
174  void cleared();
175 
181  void valueChanged( const QString& value );
182 
183  protected:
184  void mousePressEvent( QMouseEvent* e ) override;
185  void mouseMoveEvent( QMouseEvent* e ) override;
186  void focusInEvent( QFocusEvent* e ) override;
187  void paintEvent( QPaintEvent* e ) override;
188  void leaveEvent( QEvent* e ) override;
189 
190  private slots:
191  void onTextChanged( const QString &text );
192 
193  private:
194 
195  bool mClearButtonVisible;
196  bool mSearchIconVisible;
197 
198  ClearMode mClearMode;
199 
200  QString mNullValue;
201  QString mDefaultValue;
202  QString mStyleSheet;
203  bool mFocusInEvent;
204  bool mClearHover;
205 
206  QSize mClearIconSize;
207  QPixmap mClearIconPixmap;
208  QPixmap mClearHoverPixmap;
209 
210  QSize mSearchIconSize;
211  QPixmap mSearchIconPixmap;
212 
214  bool shouldShowClear() const;
215 
216  QRect clearRect() const;
217  QRect searchRect() const;
218 };
219 
221 
227 class QgsSpinBoxLineEdit : public QgsFilterLineEdit
228 {
229  Q_OBJECT
230 
231  public:
232 
233  QgsSpinBoxLineEdit( QWidget* parent = nullptr )
234  : QgsFilterLineEdit( parent )
235  {}
236 
237  public slots:
238 
239  virtual void clearValue() override
240  {
241  // don't change the value - let spin boxes handle that by detecting cleared() signal
242  setCursor( Qt::IBeamCursor );
243  setModified( true );
244  emit cleared();
245  }
246 };
248 
249 #endif // QGSFILTERLINEEDIT_H
ClearMode clearMode() const
Returns the clear mode for the widget.
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.
ClearMode
Behavior when clearing value of widget.
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.
void setNullValue(const QString &nullValue)
Sets the string representation for null values in the widget.
bool isNull(const QVariant &v)
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.