QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgis.h"
21 #include "qgis_gui.h"
22 
23 class QgsSpinBoxLineEdit;
24 
25 
26 #ifdef SIP_RUN
27 % ModuleHeaderCode
28 // fix to allow compilation with sip that for some reason
29 // doesn't add this include to the file where the code from
30 // ConvertToSubClassCode goes.
31 #include <qgsdoublespinbox.h>
32 % End
33 #endif
34 
35 
42 class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
43 {
44 
45 #ifdef SIP_RUN
47  if ( qobject_cast<QgsDoubleSpinBox *>( sipCpp ) )
48  sipType = sipType_QgsDoubleSpinBox;
49  else
50  sipType = NULL;
51  SIP_END
52 #endif
53 
54  Q_OBJECT
55  Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
56  Q_PROPERTY( bool clearValue READ clearValue WRITE setClearValue )
57  Q_PROPERTY( bool expressionsEnabled READ expressionsEnabled WRITE setExpressionsEnabled )
58 
59  public:
60 
63  {
67  };
68 
73  explicit QgsDoubleSpinBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
74 
81  void setShowClearButton( bool showClearButton );
82 
87  bool showClearButton() const {return mShowClearButton;}
88 
95  void setExpressionsEnabled( bool enabled );
96 
103  bool expressionsEnabled() const {return mExpressionsEnabled;}
104 
106  void clear() override;
107 
114  void setClearValue( double customValue, const QString &clearValueText = QString() );
115 
121  void setClearValueMode( ClearValueMode mode, const QString &clearValueText = QString() );
122 
127  double clearValue() const;
128 
133  void setLineEditAlignment( Qt::Alignment alignment );
134 
140  void setSpecialValueText( const QString &txt );
141 
142  double valueFromText( const QString &text ) const override;
143  QValidator::State validate( QString &input, int &pos ) const override;
144  void paintEvent( QPaintEvent *e ) override;
145 
146  protected:
147  void changeEvent( QEvent *event ) override;
148  void wheelEvent( QWheelEvent *event ) override;
149 
150  private slots:
151  void changed( double value );
152 
153  private:
154  int frameWidth() const;
155  bool shouldShowClearForValue( double value ) const;
156 
157  QgsSpinBoxLineEdit *mLineEdit = nullptr;
158 
159  bool mShowClearButton = true;
160  ClearValueMode mClearValueMode = MinimumValue;
161  double mCustomClearValue = 0.0;
162 
163  bool mExpressionsEnabled = true;
164 
165  QString stripped( const QString &originalText ) const;
166 
167  // This is required because private implementation of
168  // QAbstractSpinBoxPrivate checks for specialText emptiness
169  // and skips specialText handling if it's empty
170  static QString SPECIAL_TEXT_WHEN_EMPTY;
171 
172  friend class TestQgsRangeWidgetWrapper;
173 };
174 
175 #endif // QGSDOUBLESPINBOX_H
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Reset value to custom value (see setClearValue() )
bool showClearButton() const
Returns whether the widget is showing a clear button.
Reset value to maximum()
ClearValueMode
Behavior when widget is cleared.
bool expressionsEnabled() const
Returns whether the widget will allow entry of simple expressions, which are evaluated and then disca...
#define SIP_END
Definition: qgis_sip.h:182
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
Reset value to minimum()