QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsdoublespinbox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdoublespinbox.h
3  --------------------------------------
4  Date : 09.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSDOUBLESPINBOX_H
17 #define QGSDOUBLESPINBOX_H
18 
19 #include <QDoubleSpinBox>
20 
21 class QgsSpinBoxLineEdit;
22 
28 class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
29 {
30  Q_OBJECT
31  Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
32  Q_PROPERTY( bool clearValue READ clearValue WRITE setClearValue )
33  Q_PROPERTY( bool expressionsEnabled READ expressionsEnabled WRITE setExpressionsEnabled )
34 
35  public:
36 
39  {
43  };
44 
48  explicit QgsDoubleSpinBox( QWidget *parent = nullptr );
49 
55  void setShowClearButton( const bool showClearButton );
56 
60  bool showClearButton() const {return mShowClearButton;}
61 
67  void setExpressionsEnabled( const bool enabled );
68 
74  bool expressionsEnabled() const {return mExpressionsEnabled;}
75 
77  virtual void clear() override;
78 
85  void setClearValue( double customValue, const QString& clearValueText = QString() );
86 
92  void setClearValueMode( ClearValueMode mode, const QString& clearValueText = QString() );
93 
97  double clearValue() const;
98 
99  virtual double valueFromText( const QString & text ) const override;
100  virtual QValidator::State validate( QString & input, int & pos ) const override;
101  void paintEvent( QPaintEvent* e ) override;
102 
103  protected:
104  virtual void changeEvent( QEvent* event ) override;
105 
106  private slots:
107  void changed( double value );
108 
109  private:
110  int frameWidth() const;
111  bool shouldShowClearForValue( const double value ) const;
112 
113  QgsSpinBoxLineEdit* mLineEdit;
114 
115  bool mShowClearButton;
116  ClearValueMode mClearValueMode;
117  double mCustomClearValue;
118 
119  bool mExpressionsEnabled;
120 
121  QString stripped( const QString &originalText ) const;
122 };
123 
124 #endif // QGSDOUBLESPINBOX_H
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
virtual QValidator::State validate(QString &text, int &pos) const
virtual void clear()
Reset value to custom value (see setClearValue() )
Reset value to maximum()
ClearValueMode
Behaviour when widget is cleared.
bool showClearButton() const
Returns whether the widget is showing a clear button.
bool expressionsEnabled() const
Returns whether the widget will allow entry of simple expressions, which are evaluated and then disca...
virtual void paintEvent(QPaintEvent *event)
virtual void changeEvent(QEvent *event)
virtual double valueFromText(const QString &text) const
Reset value to minimum()