17 #include <QMouseEvent>
20 #include <QToolButton>
29 , mShowClearButton( true )
30 , mClearValueMode( MinimumValue )
31 , mCustomClearValue( 0.0 )
32 , mExpressionsEnabled( true )
36 mClearButton->
setCursor( Qt::ArrowCursor );
37 mClearButton->
setStyleSheet(
"position: absolute; border: none; padding: 0px;" );
38 connect( mClearButton, SIGNAL( clicked() ),
this, SLOT(
clear() ) );
72 void QgsDoubleSpinBox::changed(
const double& value )
74 mClearButton->
setVisible( shouldShowClearForValue( value ) );
85 mCustomClearValue = customValue;
87 if ( !specialValueText.
isEmpty() )
98 mClearValueMode = mode;
99 mCustomClearValue = 0;
101 if ( !clearValueText.
isEmpty() )
117 return mCustomClearValue;
120 QString QgsDoubleSpinBox::stripped(
const QString &originalText )
const
129 bool changed =
false;
142 text = text.
mid( from, size );
152 if ( !mExpressionsEnabled )
157 QString trimmedText = stripped( text );
168 if ( !mExpressionsEnabled )
174 return QValidator::Acceptable;
177 int QgsDoubleSpinBox::frameWidth()
const
182 bool QgsDoubleSpinBox::shouldShowClearForValue(
const double value )
const
197 mClearButton->
move(
rect().right() - frameWidth() - 18 - sz.
width(),
virtual QValidator::State validate(QString &text, int &pos) const
virtual QSize minimumSizeHint() const
virtual QValidator::State validate(QString &input, int &pos) const override
virtual void resizeEvent(QResizeEvent *event) override
bool showClearButton() const
QgsDoubleSpinBox(QWidget *parent=0)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
virtual void clear() override
Set the current value to the value defined by the clear value.
void setClearValue(double customValue, QString clearValueText=QString())
setClearValue defines the clear value as a custom value and will automatically set the clear value mo...
void setShowClearButton(const bool showClearButton)
determines if the widget will show a clear button
virtual void paintEvent(QPaintEvent *event) override
virtual double valueFromText(const QString &text) const override
void valueChanged(double d)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setClearValueMode(ClearValueMode mode, QString clearValueText=QString())
setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or...
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
virtual void changeEvent(QEvent *event) override
QString mid(int position, int n) const
virtual void paintEvent(QPaintEvent *event)
virtual void resizeEvent(QResizeEvent *event)
double clearValue() const
returns the value used when clear() is called.
virtual void changeEvent(QEvent *event)
void setSpecialValueText(const QString &txt)
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...