Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ConfigStore.h
Go to the documentation of this file.
1#pragma once
2#include <QSettings>
3#include <QString>
4#include <QTreeView>
5#include <misc/global.h>
6
7class QFile;
8
9namespace sf
10{
11
17{
18 public:
22 class _MISC_CLASS Values : public QMap<QString, QString>
23 {
24 public:
25 using QMap::QMap;
26 typedef ssize_t index_type;
27 static constexpr index_type npos{-1};
28
32 index_type indexOfKey(QAnyStringView key) const;
33 };
34
39 explicit ConfigStore(bool app = false);
40
45 explicit ConfigStore(const ConfigStore& cs);
46
52 explicit ConfigStore(const QString& filepath, QSettings::Format format);
53
58 explicit ConfigStore(const QSettings& settings);
59
63 explicit ConfigStore(ConfigStore&&) noexcept;
64
68 ConfigStore& operator=(const ConfigStore&) noexcept;
69
73 ConfigStore& operator=(ConfigStore&&) noexcept;
74
79
83 ConfigStore& assign(const ConfigStore& cs);
84
88 ConfigStore& setPath(const QString& filepath);
89
94 QSettings& operator()();
95
100 QString getPath() const;
101
109 QByteArray getByteArray(QAnyStringView section, QAnyStringView key, QByteArray def = {}) const;
110
117 void setByteArray(QAnyStringView section, QAnyStringView key, const QByteArray& value);
118
126 QString getString(QAnyStringView section, QAnyStringView key, QAnyStringView def = {}) const;
127
134 void setString(QAnyStringView section, QAnyStringView key, QAnyStringView value);
135
143 QStringList getStringList(QAnyStringView section, QAnyStringView key, const QStringList& def = {}) const;
144
151 void setStringList(QAnyStringView section, QAnyStringView key, const QStringList& value);
152
160 std::string getStdString(const std::string& section, const std::string& key, const std::string& def = {}) const;
161
168 void setStdString(const std::string& section, const std::string& key, const std::string& value);
169
177 bool getBool(QAnyStringView section, QAnyStringView key, bool def) const;
178
185 void setBool(QAnyStringView section, QAnyStringView key, bool value);
186
194 double getFloat(QAnyStringView section, QAnyStringView key, double def) const;
195
202 void setFloat(QAnyStringView section, QAnyStringView key, double value);
203
211 int getInt(QAnyStringView section, QAnyStringView key, int def = 0) const;
212
219 void setInt(QAnyStringView section, QAnyStringView key, int value);
220
227 QVariant getValue(QAnyStringView section, QAnyStringView key) const;
228
236 QVariant getValue(QAnyStringView section, QAnyStringView key, const QVariant& def) const;
237
244 void setValue(QAnyStringView section, QAnyStringView key, const QVariant& value);
245
253 void storeWindow(QAnyStringView section, QAnyStringView key, QWidget* widget, bool rd);
254
262 void storeTreeView(QAnyStringView section, QAnyStringView name, const QTreeView* tv, bool rd);
263
269 void getKeys(QAnyStringView section, QStringList& keys) const;
270
276 QStringList getKeys(QAnyStringView section) const;
277
282 void removeKeys(QAnyStringView section);
283
288 void removeSection(QAnyStringView section);
289
295 bool isSection(QAnyStringView section) const;
296
302 void removeKey(QAnyStringView section, QAnyStringView key);
303
309 void setSectionValues(QAnyStringView section, const Values& values);
310
316 void getSectionValues(QAnyStringView section, Values& values) const;
317
321 QStringList getSections() const;
322
327 bool exists();
328
333 void setSectionOffset(QAnyStringView section);
334
339 void setSectionDefault(QAnyStringView section);
340
345
351 {
352 public:
361 explicit Scope(ConfigStore& cs, QAnyStringView section);
362
366 Scope(const Scope&) = delete;
367
371 Scope(Scope&& cs) noexcept;
372
376 Scope& operator=(Scope&& cs) noexcept;
377
382
387
391 QSettings& settings();
392
397
398 private:
400 ConfigStore* _configStore;
401 };
402
406 QSettings& settings();
407
413 Scope scope(QAnyStringView section);
414
415 private:
416 class Private;
417 Private* _p;
418};
419
420}// namespace sf
Begins and ends a scope of settings for a section. When create it calls beginGroup(....
Definition ConfigStore.h:351
ConfigStore & configStore()
Gets the linked config store.
QSettings & settings()
Gets the settings instance with the section/group set.
Scope(ConfigStore &cs, QAnyStringView section)
Constructor passing a section of the scope.
Scope(const Scope &)=delete
Forbidden copy constructor.
Scope(Scope &&cs) noexcept
Move constructor.
ConfigStore * operator->()
Allows access to temporary settings having a group on the stack.
Scope & operator=(Scope &&cs) noexcept
Move constructor.
Type to create a string list accessible by keys.
Definition ConfigStore.h:23
ssize_t index_type
Definition ConfigStore.h:26
index_type indexOfKey(QAnyStringView key) const
Gets the index of the given key in the map.
Class to store application configuration. Uses the global application settings or a given ini-file.
Definition ConfigStore.h:17
ConfigStore(bool app=false)
Constructor initializing the instance using ApplicationSettings::global().getNewSettings().
int getInt(QAnyStringView section, QAnyStringView key, int def=0) const
Gets a section value from the store.
void removeKey(QAnyStringView section, QAnyStringView key)
Removes the given key from the store.
void getSectionValues(QAnyStringView section, Values &values) const
Gets the section content as mapped key-values.
QStringList getKeys(QAnyStringView section) const
Gets all keys from the given section.
void setInt(QAnyStringView section, QAnyStringView key, int value)
Sets a section integer value in the store.
std::string getStdString(const std::string &section, const std::string &key, const std::string &def={}) const
Gets a section's value from the store.
QString getSectionDefault()
Gets default section when the given section is empty '{}'.
QString getString(QAnyStringView section, QAnyStringView key, QAnyStringView def={}) const
Gets a section's string value from the store.
bool getBool(QAnyStringView section, QAnyStringView key, bool def) const
Gets a section value from the store.
bool isSection(QAnyStringView section) const
Check if a section exists.
ConfigStore(const ConfigStore &cs)
Copy constructor. Creates a duplicate instance of the passed config store.
void setSectionValues(QAnyStringView section, const Values &values)
Replaces the section content with the given key-values.
bool exists()
Checks if the path exists.
void removeSection(QAnyStringView section)
Deletes all keys including the section.
void setString(QAnyStringView section, QAnyStringView key, QAnyStringView value)
Sets a section's string value in the store.
QStringList getStringList(QAnyStringView section, QAnyStringView key, const QStringList &def={}) const
Gets a section's string-list value from the store.
ConfigStore(ConfigStore &&) noexcept
Move constructor.
void setSectionOffset(QAnyStringView section)
Sets a section offset call QSettings::beginGroup().
void setStdString(const std::string &section, const std::string &key, const std::string &value)
Sets a section value in the store.
ConfigStore(const QString &filepath, QSettings::Format format)
Constructor creating.
void getKeys(QAnyStringView section, QStringList &keys) const
Gets all keys from the given section.
double getFloat(QAnyStringView section, QAnyStringView key, double def) const
Gets a section value from the store.
Scope scope(QAnyStringView section)
Adds a section onto the stack of section.
void setFloat(QAnyStringView section, QAnyStringView key, double value)
Sets a section value in the store.
void setBool(QAnyStringView section, QAnyStringView key, bool value)
Sets a section value in the store.
void setValue(QAnyStringView section, QAnyStringView key, const QVariant &value)
Sets a section QVariant value in the store.
void removeKeys(QAnyStringView section)
Deletes the keys but keeps the group/section.
void storeWindow(QAnyStringView section, QAnyStringView key, QWidget *widget, bool rd)
Stores or restores the window position and size from the settings file onto the passed widget.
QVariant getValue(QAnyStringView section, QAnyStringView key, const QVariant &def) const
Gets a section value from the store.
void setSectionDefault(QAnyStringView section)
Sets default section when the given section is empty '{}'.
QVariant getValue(QAnyStringView section, QAnyStringView key) const
Gets a section value from the store.
void setStringList(QAnyStringView section, QAnyStringView key, const QStringList &value)
Sets a section's string-list value in the store.
void setByteArray(QAnyStringView section, QAnyStringView key, const QByteArray &value)
Sets a section's byte array value in the store.
ConfigStore(const QSettings &settings)
Constructor creating a copy of a passed store.
QStringList getSections() const
Gets all sections from the store in a list.
QSettings & settings()
Gets a reference to the settings currently used by this instance.
void storeTreeView(QAnyStringView section, QAnyStringView name, const QTreeView *tv, bool rd)
Stores or restores column widths of a QTreeView.
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10