QGIS API Documentation  2.99.0-Master (9fdd060)
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 
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 
58  public:
59 
61  enum ClearMode
62  {
63  ClearToNull = 0,
65  };
66  Q_ENUM( ClearMode );
67 
73  QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = 0, const QString &nullValue = QString() );
74 
80  bool showClearButton() const { return mClearButtonVisible; }
81 
88  void setShowClearButton( bool visible );
89 
96  ClearMode clearMode() const { return mClearMode; }
97 
104  void setClearMode( ClearMode mode ) { mClearMode = mode; }
105 
113  void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
114 
120  QString nullValue() const { return mNullValue; }
121 
128  void setShowSearchIcon( bool visible );
129 
135  bool showSearchIcon() const { return mSearchIconVisible; }
136 
146  void setDefaultValue( const QString &defaultValue ) { mDefaultValue = defaultValue; }
147 
156  QString defaultValue() const { return mDefaultValue; }
157 
165  void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
166 
175  QString value() const { return isNull() ? QString() : text(); }
176 
183  inline bool isNull() const { return text() == mNullValue; }
184 
185  public slots:
186 
192  virtual void clearValue();
193 
194  signals:
195 
200  void cleared();
201 
207  void valueChanged( const QString &value );
208 
209  protected:
210  void mousePressEvent( QMouseEvent *e ) override;
211  void mouseMoveEvent( QMouseEvent *e ) override;
212  void focusInEvent( QFocusEvent *e ) override;
213  void paintEvent( QPaintEvent *e ) override;
214  void leaveEvent( QEvent *e ) override;
215 
216  private slots:
217  void onTextChanged( const QString &text );
218 
219  private:
220 
221  bool mClearButtonVisible = true;
222  bool mSearchIconVisible = false;
223 
224  ClearMode mClearMode = ClearToNull;
225 
226  QString mNullValue;
227  QString mDefaultValue;
228  QString mStyleSheet;
229  bool mFocusInEvent = false;
230  bool mClearHover = false;
231 
232  QSize mClearIconSize;
233  QPixmap mClearIconPixmap;
234  QPixmap mClearHoverPixmap;
235 
236  QSize mSearchIconSize;
237  QPixmap mSearchIconPixmap;
238 
240  bool shouldShowClear() const;
241 
242  QRect clearRect() const;
243  QRect searchRect() const;
244 };
245 
247 
254 class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
255 {
256  Q_OBJECT
257 
258  public:
259 
260  QgsSpinBoxLineEdit( QWidget *parent = nullptr )
261  : QgsFilterLineEdit( parent )
262  {}
263 
264  public slots:
265 
266  virtual void clearValue() override
267  {
268  // don't change the value - let spin boxes handle that by detecting cleared() signal
269  setCursor( Qt::IBeamCursor );
270  setModified( true );
271  emit cleared();
272  }
273 };
275 
276 #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...
#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.