17 #include <QMouseEvent> 27 #define CLEAR_ICON_SIZE 16 31 , mShowClearButton( true )
32 , mClearValueMode( MinimumValue )
33 , mCustomClearValue( 0.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 QgsDoubleSpinBox::changed(
double value )
73 mLineEdit->setShowClearButton( shouldShowClearForValue( value ) );
84 mCustomClearValue = customValue;
86 if ( !specialValueText.
isEmpty() )
97 mClearValueMode = mode;
98 mCustomClearValue = 0;
100 if ( !clearValueText.
isEmpty() )
116 return mCustomClearValue;
119 QString QgsDoubleSpinBox::stripped(
const QString &originalText )
const 128 bool changed =
false;
141 text = text.
mid( from, size );
151 if ( !mExpressionsEnabled )
156 QString trimmedText = stripped( text );
167 if ( !mExpressionsEnabled )
173 return QValidator::Acceptable;
176 int QgsDoubleSpinBox::frameWidth()
const 181 bool QgsDoubleSpinBox::shouldShowClearForValue(
const double value )
const virtual QValidator::State validate(QString &text, int &pos) const
void setLineEdit(QLineEdit *lineEdit)
virtual bool event(QEvent *event)
void paintEvent(QPaintEvent *e) override
virtual QSize minimumSizeHint() const
virtual QValidator::State validate(QString &input, int &pos) const override
Reset value to custom value (see setClearValue() )
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const=0
QgsDoubleSpinBox(QWidget *parent=nullptr)
Constructor for QgsDoubleSpinBox.
ClearValueMode
Behaviour when widget is cleared.
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.
bool showClearButton() const
Returns whether the widget is showing a clear button.
virtual double valueFromText(const QString &text) const override
void valueChanged(double d)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
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...
double clearValue() const
Returns the value used when clear() is called.
virtual void changeEvent(QEvent *event) 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...
QString mid(int position, int n) const
virtual void paintEvent(QPaintEvent *event)
virtual void changeEvent(QEvent *event)
QString specialValueText() const
virtual double valueFromText(const QString &text) const
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.
void setExpressionsEnabled(const bool enabled)
Sets if the widget will allow entry of simple expressions, which are evaluated and then discarded...