17 #include <QMouseEvent> 27 #define CLEAR_ICON_SIZE 16 31 , mShowClearButton( true )
32 , mClearValueMode( MinimumValue )
33 , mCustomClearValue( 0 )
34 , mExpressionsEnabled( true )
36 mLineEdit =
new QgsSpinBoxLineEdit();
44 connect( mLineEdit, SIGNAL( cleared() ),
this, SLOT(
clear() ) );
51 mLineEdit->setShowClearButton( showClearButton );
62 mLineEdit->setShowClearButton( shouldShowClearForValue(
value() ) );
67 mLineEdit->setShowClearButton( shouldShowClearForValue(
value() ) );
71 void QgsSpinBox::changed(
int value )
73 mLineEdit->setShowClearButton( shouldShowClearForValue( value ) );
84 mCustomClearValue = customValue;
86 if ( !specialValueText.
isEmpty() )
97 mClearValueMode = mode;
98 mCustomClearValue = 0;
100 if ( !specialValueText.
isEmpty() )
116 return mCustomClearValue;
121 if ( !mExpressionsEnabled )
126 QString trimmedText = stripped( text );
137 if ( !mExpressionsEnabled )
143 return QValidator::Acceptable;
146 int QgsSpinBox::frameWidth()
const 151 bool QgsSpinBox::shouldShowClearForValue(
const int value )
const 169 bool changed =
false;
182 text = text.
mid( from, size );
void setLineEdit(QLineEdit *lineEdit)
virtual QSize minimumSizeHint() const
ClearValueMode
Behaviour when widget is cleared.
void setExpressionsEnabled(const bool enabled)
Sets if the widget will allow entry of simple expressions, which are evaluated and then discarded...
Reset value to custom value (see setClearValue() )
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const=0
bool showClearButton() const
Returns whether the widget is showing a clear button.
virtual QValidator::State validate(QString &input, int &pos) const override
virtual void clear() override
Set the current value to the value defined by the clear value.
void setShowClearButton(const bool showClearButton)
Sets whether the widget will show a clear button.
QgsSpinBox(QWidget *parent=nullptr)
Constructor for QgsSpinBox.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
int clearValue() const
Returns the value used when clear() is called.
virtual bool event(QEvent *event)
virtual void paintEvent(QPaintEvent *event) override
virtual int valueFromText(const QString &text) const
virtual QValidator::State validate(QString &text, int &pos) const
virtual int valueFromText(const QString &text) const override
void setClearValueMode(ClearValueMode mode, const QString &clearValueText=QString())
Defines if the clear value should be the minimum or maximum values of the widget or a custom value...
void setClearValue(int customValue, const QString &clearValueText=QString())
Defines the clear value as a custom value and will automatically set the clear value mode to CustomVa...
QString mid(int position, int n) const
virtual void paintEvent(QPaintEvent *event)
virtual void changeEvent(QEvent *event)
QString specialValueText() const
virtual void changeEvent(QEvent *event) override
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
static double evaluateToDouble(const QString &text, const double fallbackValue)
Attempts to evaluate a text string as an expression to a resultant double value.