QGIS API Documentation 3.43.0-Master (0bee5d6404c)
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 : denis.rouzaud@gmail.com
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_sip.h"
21#include "qgis_gui.h"
22
23class 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
44class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
45{
46#ifdef SIP_RUN
48 if ( qobject_cast<QgsDoubleSpinBox *>( sipCpp ) )
49 sipType = sipType_QgsDoubleSpinBox;
50 else
51 sipType = NULL;
53#endif
54
55 Q_OBJECT
56 Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
57 Q_PROPERTY( bool clearValue READ clearValue WRITE setClearValue )
58 Q_PROPERTY( bool expressionsEnabled READ expressionsEnabled WRITE setExpressionsEnabled )
59
60 public:
68
73 explicit QgsDoubleSpinBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
74
81 void setShowClearButton( bool showClearButton );
82
87 bool showClearButton() const { return mShowClearButton; }
88
94 void setExpressionsEnabled( bool enabled );
95
101 bool expressionsEnabled() const { return mExpressionsEnabled; }
102
104 void clear() override;
105
112 void setClearValue( double customValue, const QString &clearValueText = QString() );
113
119 void setClearValueMode( ClearValueMode mode, const QString &clearValueText = QString() );
120
125 double clearValue() const;
126
134 bool isCleared() const;
135
140 void setLineEditAlignment( Qt::Alignment alignment );
141
147 void setSpecialValueText( const QString &txt );
148
149 double valueFromText( const QString &text ) const override;
150 QValidator::State validate( QString &input, int &pos ) const override;
151 void paintEvent( QPaintEvent *e ) override;
152 void stepBy( int steps ) override;
153
162 int editingTimeoutInterval() const;
163
164 public slots:
165
175 void setEditingTimeoutInterval( int timeout );
176
177 signals:
178
184
189 void textEdited( const QString &text );
190
204 void editingTimeout( double value );
205
206 protected:
207 void changeEvent( QEvent *event ) override;
208 void wheelEvent( QWheelEvent *event ) override;
209 void focusOutEvent( QFocusEvent *event ) override;
210 // This is required because private implementation of
211 // QAbstractSpinBoxPrivate may trigger a second
212 // undesired event from the auto-repeat mouse timer
213 void timerEvent( QTimerEvent *event ) override;
214
215 private slots:
216 void changed( double value );
217 void onLastEditTimeout();
218
219 private:
220 int frameWidth() const;
221 bool shouldShowClearForValue( double value ) const;
222
223 QgsSpinBoxLineEdit *mLineEdit = nullptr;
224
225 bool mShowClearButton = true;
226 ClearValueMode mClearValueMode = MinimumValue;
227 double mCustomClearValue = 0.0;
228
229 bool mExpressionsEnabled = true;
230
231 QTimer *mLastEditTimer = nullptr;
232 double mLastEditTimeoutValue = std::numeric_limits<double>::quiet_NaN();
233
234 QString stripped( const QString &originalText ) const;
235
236 friend class TestQgsRangeWidgetWrapper;
237};
238
239#endif // QGSDOUBLESPINBOX_H
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
void textEdited(const QString &text)
Emitted when the the value has been manually edited via line edit.
void editingTimeout(double value)
Emitted when either:
bool showClearButton() const
Returns whether the widget is showing a clear button.
ClearValueMode
Behavior when widget is cleared.
@ MaximumValue
Reset value to maximum()
@ CustomValue
Reset value to custom value (see setClearValue() )
@ MinimumValue
Reset value to minimum()
void returnPressed()
Emitted when the Return or Enter key is used in the line edit.
bool expressionsEnabled() const
Returns whether the widget will allow entry of simple expressions, which are evaluated and then disca...
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:208