File: numericspinbox.h

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (57 lines) | stat: -rw-r--r-- 1,669 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef QNUMERICSPINBOX_H
#define QNUMERICSPINBOX_H

#include "guiSQLiteStudio_global.h"
#include <QAbstractSpinBox>

/**
 * @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