QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsdoublespinbox.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdoublespinbox.h
3 --------------------------------------
4 Date : 09.2014
5 Copyright : (C) 2014 Denis Rouzaud
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
42class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
43{
44#ifdef SIP_RUN
46 if ( qobject_cast<QgsDoubleSpinBox *>( sipCpp ) )
47 sipType = sipType_QgsDoubleSpinBox;
48 else
49 sipType = NULL;
51#endif
52
53 Q_OBJECT
54 Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
55 Q_PROPERTY( bool clearValue READ clearValue WRITE setClearValue )
56 Q_PROPERTY( bool expressionsEnabled READ expressionsEnabled WRITE setExpressionsEnabled )
57
58 public:
66
71 explicit QgsDoubleSpinBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
72
79 void setShowClearButton( bool showClearButton );
80
85 bool showClearButton() const { return mShowClearButton; }
86
92 void setExpressionsEnabled( bool enabled );
93
99 bool expressionsEnabled() const { return mExpressionsEnabled; }
100
102 void clear() override;
103
110 void setClearValue( double customValue, const QString &clearValueText = QString() );
111
117 void setClearValueMode( ClearValueMode mode, const QString &clearValueText = QString() );
118
123 double clearValue() const;
124
131 bool isCleared() const;
132
137 void setLineEditAlignment( Qt::Alignment alignment );
138
144 void setSpecialValueText( const QString &txt );
145
146 double valueFromText( const QString &text ) const override;
147 QValidator::State validate( QString &input, int &pos ) const override;
148 void paintEvent( QPaintEvent *e ) override;
149 void stepBy( int steps ) override;
150
159 int editingTimeoutInterval() const;
160
161 public slots:
162
172 void setEditingTimeoutInterval( int timeout );
173
174 signals:
175
181
186 void textEdited( const QString &text );
187
201 void editingTimeout( double value );
202
203 protected:
204 void changeEvent( QEvent *event ) override;
205 void wheelEvent( QWheelEvent *event ) override;
206 void focusOutEvent( QFocusEvent *event ) override;
207 // This is required because private implementation of
208 // QAbstractSpinBoxPrivate may trigger a second
209 // undesired event from the auto-repeat mouse timer
210 void timerEvent( QTimerEvent *event ) override;
211
212 private slots:
213 void changed( double value );
214 void onLastEditTimeout();
215
216 private:
217 int frameWidth() const;
218 bool shouldShowClearForValue( double value ) const;
219
220 QgsSpinBoxLineEdit *mLineEdit = nullptr;
221
222 bool mShowClearButton = true;
223 ClearValueMode mClearValueMode = MinimumValue;
224 double mCustomClearValue = 0.0;
225
226 bool mExpressionsEnabled = true;
227
228 QTimer *mLastEditTimer = nullptr;
229 double mLastEditTimeoutValue = std::numeric_limits<double>::quiet_NaN();
230
231 QString stripped( const QString &originalText ) const;
232
233 friend class TestQgsRangeWidgetWrapper;
234};
235
236#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