QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgis_gui.h"
20#include "qgis_sip.h"
21
22#include <QDoubleSpinBox>
23
24class QgsSpinBoxLineEdit;
25
26
27#ifdef SIP_RUN
28//%ModuleHeaderCode
29// fix to allow compilation with sip that for some reason
30// doesn't add this include to the file where the code from
31// ConvertToSubClassCode goes.
32#include <qgsdoublespinbox.h>
33//%End
34#endif
35
36
45class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
46{
47#ifdef SIP_RUN
49 if ( qobject_cast<QgsDoubleSpinBox *>( sipCpp ) )
50 sipType = sipType_QgsDoubleSpinBox;
51 else
52 sipType = NULL;
54#endif
55
56 Q_OBJECT
58 Q_PROPERTY( bool clearValue READ clearValue WRITE setClearValue )
60
61 public:
69
74 explicit QgsDoubleSpinBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
75
82 void setShowClearButton( bool showClearButton );
83
88 bool showClearButton() const { return mShowClearButton; }
89
95 void setExpressionsEnabled( bool enabled );
96
102 bool expressionsEnabled() const { return mExpressionsEnabled; }
103
105 void clear() override;
106
113 void setClearValue( double customValue, const QString &clearValueText = QString() );
114
120 void setClearValueMode( ClearValueMode mode, const QString &clearValueText = QString() );
121
126 double clearValue() const;
127
135 bool isCleared() const;
136
141 void setLineEditAlignment( Qt::Alignment alignment );
142
148 void setSpecialValueText( const QString &txt );
149
150 double valueFromText( const QString &text ) const override;
151 QValidator::State validate( QString &input, int &pos ) const override;
152 void paintEvent( QPaintEvent *e ) override;
153 void stepBy( int steps ) override;
154
163 int editingTimeoutInterval() const;
164
165 public slots:
166
176 void setEditingTimeoutInterval( int timeout );
177
178 signals:
179
185
190 void textEdited( const QString &text );
191
205 void editingTimeout( double value );
206
207 protected:
208 void changeEvent( QEvent *event ) override;
209 void wheelEvent( QWheelEvent *event ) override;
210 void focusOutEvent( QFocusEvent *event ) override;
211 // This is required because private implementation of
212 // QAbstractSpinBoxPrivate may trigger a second
213 // undesired event from the auto-repeat mouse timer
214 void timerEvent( QTimerEvent *event ) override;
215
216 private slots:
217 void changed( double value );
218 void onLastEditTimeout();
219
220 private:
221 int frameWidth() const;
222 bool shouldShowClearForValue( double value ) const;
223
224 QgsSpinBoxLineEdit *mLineEdit = nullptr;
225
226 bool mShowClearButton = true;
227 ClearValueMode mClearValueMode = MinimumValue;
228 double mCustomClearValue = 0.0;
229
230 bool mExpressionsEnabled = true;
231
232 QTimer *mLastEditTimer = nullptr;
233 double mLastEditTimeoutValue = std::numeric_limits<double>::quiet_NaN();
234
235 QString stripped( const QString &originalText ) const;
236
238};
239
240#endif // QGSDOUBLESPINBOX_H
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
void wheelEvent(QWheelEvent *event) override
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.
void focusOutEvent(QFocusEvent *event) override
void changeEvent(QEvent *event) override
ClearValueMode
Behavior when widget is cleared.
@ MaximumValue
Reset value to maximum().
@ CustomValue
Reset value to custom value (see setClearValue() ).
@ MinimumValue
Reset value to minimum().
friend class TestQgsRangeWidgetWrapper
QgsDoubleSpinBox(QWidget *parent=nullptr)
Constructor for QgsDoubleSpinBox.
void setExpressionsEnabled(bool enabled)
Sets if the widget will allow entry of simple expressions, which are evaluated and then discarded.
void setClearValue(double customValue, const QString &clearValueText=QString())
Defines the clear value as a custom value and will automatically set the clear value mode to CustomVa...
void setShowClearButton(bool showClearButton)
Sets whether the widget will show a clear button.
void timerEvent(QTimerEvent *event) override
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:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:216