QGIS API Documentation  2.99.0-Master (ef89a62)
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 
37 class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
38 {
39 
40 #ifdef SIP_RUN
42  if ( qobject_cast<QgsFilterLineEdit *>( sipCpp ) )
43  sipType = sipType_QgsFilterLineEdit;
44  else
45  sipType = NULL;
46  SIP_END
47 #endif
48 
49  Q_OBJECT
50  Q_ENUMS( ClearMode )
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 
71  QgsFilterLineEdit( QWidget *parent SIP_TRANSFERTHIS = 0, const QString &nullValue = QString() );
72 
77  bool showClearButton() const { return mClearButtonVisible; }
78 
84  void setShowClearButton( bool visible );
85 
91  ClearMode clearMode() const { return mClearMode; }
92 
98  void setClearMode( ClearMode mode ) { mClearMode = mode; }
99 
106  void setNullValue( const QString &nullValue ) { mNullValue = nullValue; }
107 
112  QString nullValue() const { return mNullValue; }
113 
119  void setShowSearchIcon( bool visible );
120 
125  bool showSearchIcon() const { return mSearchIconVisible; }
126 
135  void setDefaultValue( const QString &defaultValue ) { mDefaultValue = defaultValue; }
136 
144  QString defaultValue() const { return mDefaultValue; }
145 
153  void setValue( const QString &value ) { setText( value.isNull() ? mNullValue : value ); }
154 
163  QString value() const { return isNull() ? QString() : text(); }
164 
171  inline bool isNull() const { return text() == mNullValue; }
172 
173  public slots:
174 
179  virtual void clearValue();
180 
181  signals:
182 
186  void cleared();
187 
193  void valueChanged( const QString &value );
194 
195  protected:
196  void mousePressEvent( QMouseEvent *e ) override;
197  void mouseMoveEvent( QMouseEvent *e ) override;
198  void focusInEvent( QFocusEvent *e ) override;
199  void paintEvent( QPaintEvent *e ) override;
200  void leaveEvent( QEvent *e ) override;
201 
202  private slots:
203  void onTextChanged( const QString &text );
204 
205  private:
206 
207  bool mClearButtonVisible;
208  bool mSearchIconVisible;
209 
210  ClearMode mClearMode;
211 
212  QString mNullValue;
213  QString mDefaultValue;
214  QString mStyleSheet;
215  bool mFocusInEvent;
216  bool mClearHover;
217 
218  QSize mClearIconSize;
219  QPixmap mClearIconPixmap;
220  QPixmap mClearHoverPixmap;
221 
222  QSize mSearchIconSize;
223  QPixmap mSearchIconPixmap;
224 
226  bool shouldShowClear() const;
227 
228  QRect clearRect() const;
229  QRect searchRect() const;
230 };
231 
233 
239 class SIP_SKIP QgsSpinBoxLineEdit : public QgsFilterLineEdit
240 {
241  Q_OBJECT
242 
243  public:
244 
245  QgsSpinBoxLineEdit( QWidget *parent = nullptr )
246  : QgsFilterLineEdit( parent )
247  {}
248 
249  public slots:
250 
251  virtual void clearValue() override
252  {
253  // don't change the value - let spin boxes handle that by detecting cleared() signal
254  setCursor( Qt::IBeamCursor );
255  setModified( true );
256  emit cleared();
257  }
258 };
260 
261 #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.