17 #include <QMouseEvent> 20 #include <QToolButton> 29 , mShowClearButton( true )
30 , mClearValueMode( MinimumValue )
31 , mCustomClearValue( 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 QgsSpinBox::changed(
int value )
74 mClearButton->
setVisible( shouldShowClearForValue( value ) );
85 mCustomClearValue = customValue;
87 if ( !specialValueText.
isEmpty() )
98 mClearValueMode = mode;
99 mCustomClearValue = 0;
101 if ( !specialValueText.
isEmpty() )
117 return mCustomClearValue;
122 if ( !mExpressionsEnabled )
127 QString trimmedText = stripped( text );
138 if ( !mExpressionsEnabled )
144 return QValidator::Acceptable;
147 int QgsSpinBox::frameWidth()
const 152 bool QgsSpinBox::shouldShowClearForValue(
const int value )
const 170 bool changed =
false;
183 text = text.
mid( from, size );
197 mClearButton->
move(
rect().right() - frameWidth() - 18 - sz.
width(),
virtual QSize minimumSizeHint() const
void setExpressionsEnabled(const bool enabled)
Sets if the widget will allow entry of simple expressions, which are evaluated and then discarded...
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 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.
virtual void resizeEvent(QResizeEvent *event) override
void setShowClearButton(const bool showClearButton)
determines if the widget will show a clear button
QgsSpinBox(QWidget *parent=nullptr)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
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())
setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or...
void setClearValue(int customValue, const QString &clearValueText=QString())
setClearValue defines the clear value for the widget and will automatically set the clear value mode ...
QString mid(int position, int n) const
virtual void paintEvent(QPaintEvent *event)
virtual void resizeEvent(QResizeEvent *event)
virtual void changeEvent(QEvent *event)
int clearValue() const
returns the value used when clear() is called.
QString specialValueText() const
virtual void changeEvent(QEvent *event) override
bool showClearButton() 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.