QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
45  public:
46 
48  enum ClearMode
49  {
50  ClearToNull = 0,
52  };
53 
58  QgsFilterLineEdit( QWidget* parent = nullptr, const QString& nullValue = QString::null );
59 
64  bool showClearButton() const { return mClearButtonVisible; }
65 
71  void setShowClearButton( bool visible );
72 
78  ClearMode clearMode() const { return mClearMode; }
79 
85  void setClearMode( ClearMode mode ) { mClearMode = mode; }
86 
93  void setNullValue( const QString& nullValue ) { mNullValue = nullValue; }
94 
99  QString nullValue() const { return mNullValue; }
100 
109  void setDefaultValue( const QString& defaultValue ) { mDefaultValue = defaultValue; }
110 
118  QString defaultValue() const { return mDefaultValue; }
119 
127  void setValue( const QString& value ) { setText( value.isNull() ? mNullValue : value ); }
128 
137  QString value() const { return isNull() ? QString::null : text(); }
138 
145  inline bool isNull() const { return text() == mNullValue; }
146 
147  public slots:
148 
153  virtual void clearValue();
154 
155  signals:
156 
160  void cleared();
161 
167  void valueChanged( const QString& value );
168 
169  protected:
170  void mousePressEvent( QMouseEvent* e ) override;
171  void mouseMoveEvent( QMouseEvent* e ) override;
172  void focusInEvent( QFocusEvent* e ) override;
173  void paintEvent( QPaintEvent* e ) override;
174  void leaveEvent( QEvent* e ) override;
175 
176  private slots:
177  void onTextChanged( const QString &text );
178 
179  private:
180 
181  bool mClearButtonVisible;
182 
183  ClearMode mClearMode;
184 
185  QString mNullValue;
186  QString mDefaultValue;
187  QString mStyleSheet;
188  bool mFocusInEvent;
189  bool mClearHover;
190 
191  QSize mClearIconSize;
192  QPixmap mClearIconPixmap;
193  QPixmap mClearHoverPixmap;
194 
196  bool shouldShowClear() const;
197 
198  QRect clearRect() const;
199 };
200 
202 
208 class QgsSpinBoxLineEdit : public QgsFilterLineEdit
209 {
210  Q_OBJECT
211 
212  public:
213 
214  QgsSpinBoxLineEdit( QWidget* parent = nullptr )
215  : QgsFilterLineEdit( parent )
216  {}
217 
218  public slots:
219 
220  virtual void clearValue() override
221  {
222  // don't change the value - let spin boxes handle that by detecting cleared() signal
223  setCursor( Qt::IBeamCursor );
224  setModified( true );
225  emit cleared();
226  }
227 };
229 
230 #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.
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.