QGIS API Documentation 3.43.0-Master (c67cf405802)
qgsspinbox.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsspinbox.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 QGSSPINBOX_H
17#define QGSSPINBOX_H
18
19#include <QSpinBox>
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 4.7 that for some reason
29// doesn't add this include to the file where the code from
30// ConvertToSubClassCode goes.
31#include <qgsspinbox.h>
32//%End
33#endif
34
35
43class GUI_EXPORT QgsSpinBox : public QSpinBox
44{
45#ifdef SIP_RUN
47 if ( qobject_cast<QgsSpinBox *>( sipCpp ) )
48 sipType = sipType_QgsSpinBox;
49 else
50 sipType = NULL;
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:
67
72 explicit QgsSpinBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
73
80 void setShowClearButton( bool showClearButton );
81
86 bool showClearButton() const { return mShowClearButton; }
87
93 void setExpressionsEnabled( bool enabled );
94
100 bool expressionsEnabled() const { return mExpressionsEnabled; }
101
103 void clear() override;
104
111 void setClearValue( int customValue, const QString &clearValueText = QString() );
112
118 void setClearValueMode( ClearValueMode mode, const QString &clearValueText = QString() );
119
124 int clearValue() const;
125
130 void setLineEditAlignment( Qt::Alignment alignment );
131
137 void setSpecialValueText( const QString &txt );
138
139 int valueFromText( const QString &text ) const override;
140 QValidator::State validate( QString &input, int &pos ) const override;
141 void stepBy( int steps ) override;
142
151 int editingTimeoutInterval() const;
152
153 public slots:
154
164 void setEditingTimeoutInterval( int timeout );
165
166 signals:
167
173
178 void textEdited( const QString &text );
179
193 void editingTimeout( int value );
194
195 protected:
196 void changeEvent( QEvent *event ) override;
197 void paintEvent( QPaintEvent *event ) override;
198 void wheelEvent( QWheelEvent *event ) override;
199 // This is required because private implementation of
200 // QAbstractSpinBoxPrivate may trigger a second
201 // undesired event from the auto-repeat mouse timer
202 void timerEvent( QTimerEvent *event ) override;
203 void focusOutEvent( QFocusEvent *event ) override;
204
205 private slots:
206 void changed( int value );
207 void onLastEditTimeout();
208
209 private:
210 int frameWidth() const;
211 bool shouldShowClearForValue( int value ) const;
212
213 QgsSpinBoxLineEdit *mLineEdit = nullptr;
214
215 bool mShowClearButton = true;
216 ClearValueMode mClearValueMode = MinimumValue;
217 int mCustomClearValue = 0;
218
219 bool mExpressionsEnabled = true;
220
221 QTimer *mLastEditTimer = nullptr;
222 bool mHasEmittedEditTimeout = false;
223 int mLastEditTimeoutValue = 0;
224
225 QString stripped( const QString &originalText ) const;
226
227 friend class TestQgsRangeWidgetWrapper;
228};
229
230#endif // QGSSPINBOX_H
A spin box with a clear button that will set the value to the defined clear value.
Definition qgsspinbox.h:44
void returnPressed()
Emitted when the Return or Enter key is used in the line edit.
ClearValueMode
Behavior when widget is cleared.
Definition qgsspinbox.h:62
@ MaximumValue
Reset value to maximum()
Definition qgsspinbox.h:64
@ MinimumValue
Reset value to minimum()
Definition qgsspinbox.h:63
@ CustomValue
Reset value to custom value (see setClearValue() )
Definition qgsspinbox.h:65
bool showClearButton() const
Returns whether the widget is showing a clear button.
Definition qgsspinbox.h:86
void editingTimeout(int value)
Emitted when either:
bool expressionsEnabled() const
Returns whether the widget will allow entry of simple expressions, which are evaluated and then disca...
Definition qgsspinbox.h:100
void textEdited(const QString &text)
Emitted when the the value has been manually edited via line edit.
#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