-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegerobject.h
More file actions
48 lines (40 loc) · 1.29 KB
/
integerobject.h
File metadata and controls
48 lines (40 loc) · 1.29 KB
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
#ifndef INTEGEROBJECT_H
#define INTEGEROBJECT_H
#include <QObject>
#include <QSettings>
/// This is a integer wrapping class that provides the signals and slots
/// and some additional metadata like the default value of the instance
/// and the settings key.
class IntegerObject : public QObject
{
Q_OBJECT
public:
/// The valueAndDefault sets the default value and the
/// current value to the same value because the other value
/// is set after construction
explicit IntegerObject(int valueAndDefault, QString const& settingsKey, QObject *parent = nullptr);
/// Returns the integer value.
int value() const;
/// Returns the associated settings key.
QString const& settingsKey() const;
/// Returns the default value associated with the
/// current instance.
int defaultValue() const;
/// Implicit conversion operator.
inline operator int() const {
return this->value();
}
public slots:
/// Sets the current value.
void setValue(int value);
/// Registers the settings to the changed value setting so
/// it's updated when the value changes.
void attachSettings(QSettings *settings);
signals:
void valueChanged(int newValue);
private:
int m_value;
int m_default;
QString m_settingsKey;
};
#endif // INTEGEROBJECT_H