From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- .../guiSQLiteStudio/common/numericspinbox.h | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 SQLiteStudio3/guiSQLiteStudio/common/numericspinbox.h (limited to 'SQLiteStudio3/guiSQLiteStudio/common/numericspinbox.h') diff --git a/SQLiteStudio3/guiSQLiteStudio/common/numericspinbox.h b/SQLiteStudio3/guiSQLiteStudio/common/numericspinbox.h new file mode 100644 index 0000000..79cd56c --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/common/numericspinbox.h @@ -0,0 +1,57 @@ +#ifndef QNUMERICSPINBOX_H +#define QNUMERICSPINBOX_H + +#include "guiSQLiteStudio_global.h" +#include + +/** + * @brief The NumericSpinBox class + * This class implements a spinbox for numeric SQLite types. + * This includes integers, as well as decimals. + * User is also allowed to type in any text value (unless "strict" property is set), + * but once he uses "step up" or "step down", the text value + * gets replaced with 0. + * If strict propery is set, also the allowEmpty property starts to matter. + * Otherwise allowEmpty is ignored. + */ +class GUI_API_EXPORT NumericSpinBox : public QAbstractSpinBox +{ + Q_OBJECT + public: + explicit NumericSpinBox(QWidget *parent = 0); + + void stepBy(int steps); + QValidator::State validate(QString& input, int& pos) const; + + QVariant getValue() const; + void setValue(const QVariant& newValue, bool nullAsZero = true); + + bool isStrict() const; + void setStrict(bool value, bool allowEmpty = true); + + bool getAllowEmpty() const; + void setAllowEmpty(bool value); + + protected: + StepEnabled stepEnabled() const; + + private: + QVariant getFixedVariant(const QVariant& value); + void setValueInternal(const QVariant& newValue); + void stepIntBy(int steps); + void stepDoubleBy(int steps); + void updateText(); + QValidator::State validateStrict(QString &input, int &pos) const; + + QVariant value; + bool strict = false; + bool allowEmpty = true; + + private slots: + void valueEdited(const QString& value); + + signals: + void modified() const; +}; + +#endif // QNUMERICSPINBOX_H -- cgit v1.2.3