-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSettings.h
More file actions
82 lines (65 loc) · 3.37 KB
/
Settings.h
File metadata and controls
82 lines (65 loc) · 3.37 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef SETTINGS_H
#define SETTINGS_H
#include "cppCORE_global.h"
#include <QSettings>
#include <QStringList>
///Application settings handler
class CPPCORESHARED_EXPORT Settings
{
public:
///Read access for integer settings.
static int integer(QString key);
///Write access for integer settings.
static void setInteger(QString key, int value);
///Read access for string settings. If the string starts with 'encrypted:' it is decrypted before returning the key. If optional and not present, an empty string is returned.
static QString string(QString key, bool optional=false);
///Write access for string settings.
static void setString(QString key, QString value);
///Read access for string list settings. If optional and not present, an empty string list is returned.
static QStringList stringList(QString key, bool optional=false);
///Write access for string list settings.
static void setStringList(QString key, QStringList value);
///Read access for boolean settings. If optional and not present, 'false' is retured.
static bool boolean(QString key, bool optional=false);
///Write access for boolean settings.
static void setBoolean(QString key, bool value);
///Read access for map settings. If optional and not present, an empty map is returned.
static QMap<QString,QVariant> map(QString key, bool optional=false);
///Write access for map settings.
static void setMap(QString key, QMap<QString,QVariant> value);
///Read access for file or directory path settings. If optional and not present, an empty string is returned.
static QString path(QString key, bool optional=false);
///Write access for file or directory path settings. If the path contains a file name, it is stripped off.
static void setPath(QString key, QString path);
///Removes all settings from the user-sepecific settings file.
static void clear();
///Removes an entry from the user-sepecific settings file.
static void remove(QString key);
///Returns all available keys.
static QStringList allKeys();
///Returns if a key is present and the value is not empty.
static bool contains(QString key);
///Returns the settings files that are used (user-specific, app-specific, general).
static QStringList files();
///Settings file override (no other files are used)
static void setSettingsOverride(QString filename);
///Returns the settings override or an empty string if unset
static QString settingsOverride();
protected:
///Default constructor "declared away"
Settings() = delete;
///Retreives a value from the settings, with fallback in this order: settingsApplicationUser(), settingsApplication(), settingsGeneral().
static QVariant valueWithFallback(QString key);
static bool settingsApplicationUserExists();
///returns the user-specific settings file "[appname].ini" in the local application data folder (read-write)
static QSettings& settingsApplicationUser();
///returns the application-specific settings file "[appname].ini" in the application folder (read only)
static const QSettings& settingsApplication();
///returns the general settings file "settings.ini" in the application folder (read only)
static const QSettings& settingsGeneral();
///returns if a settings file contains a non-empty value.
static bool containsNonEmpty(const QSettings& settings, const QString& name);
static QString override_settings_file;
static QSharedPointer<QSettings> override_settings;
};
#endif //SETTINGS_H