30 #include <QFileSystemWatcher> 37 class ZFileSystemWatcher;
61 : m_dataPath(dataPath){}
64 : m_metaPath(metaPath),
65 m_dataPath(dataPath){}
67 SettingsBundle(
const QString& meta,
const QString& dataPath,
bool metaAtomic)
68 :m_dataPath(dataPath){
if(metaAtomic) m_metaData = meta;
else m_metaPath = meta;}
71 QSettings::Scope scope = QSettings::UserScope,
72 const QString& organization = QString(),
73 const QString& application = QString())
74 : m_metaPath(metaPath),
75 m_organization(organization),
76 m_application(application),
92 explicit ZSettings(QObject *parent =
nullptr);
99 static void registerType();
111 Q_PROPERTY(QVariant tags READ getTags)
117 Q_PROPERTY(QVariant fileName READ getFileName CONSTANT)
126 Q_PROPERTY(QStringList allKeys READ getAllKeys)
132 Q_PROPERTY(QStringList childKeys READ getChildKeys)
138 Q_PROPERTY(QStringList childGroups READ getChildGroups)
144 Q_PROPERTY(
bool isWritable READ getWritable)
150 Q_PROPERTY(
int format READ getFormat)
156 Q_PROPERTY(
int scope READ getScope)
162 Q_PROPERTY(QString organizationName READ getOrganizationName)
168 Q_PROPERTY(QString applicationName READ getApplicationName)
175 QString getFileName() const;
177 QStringList getAllKeys() const;
178 QStringList getChildKeys() const;
179 QStringList getChildGroups() const;
180 bool getWritable() const;
181 int getFormat() const;
182 int getScope() const;
183 QString getOrganizationName() const;
184 QString getApplicationName() const;
198 static
bool readFunc(QIODevice &device, QSettings::SettingsMap &map);
207 static
bool writeFunc(QIODevice &device, const QSettings::SettingsMap &map);
218 Q_INVOKABLE
bool open(
int scope = static_cast<
int>(QSettings::UserScope),
219 const QString& application = QString(),
220 const QString& organization = QString());
228 Q_INVOKABLE
bool open(const QString& filePath);
246 Q_INVOKABLE
bool setFileWatcher(
bool enabled);
249 Q_INVOKABLE
void clear();
250 Q_INVOKABLE
void sync();
251 Q_INVOKABLE
int status() const;
253 Q_INVOKABLE
void setValue(const QString &key, const QVariant &value);
254 Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
256 Q_INVOKABLE
void remove(const QString &key);
257 Q_INVOKABLE
bool contains(const QString &key) const;
259 Q_INVOKABLE
void beginGroup(const QString &prefix);
260 Q_INVOKABLE
void endGroup();
261 Q_INVOKABLE QString group() const;
263 Q_INVOKABLE
int beginReadArray(const QString &prefix);
264 Q_INVOKABLE
void beginWriteArray(const QString &prefix,
int size = -1);
265 Q_INVOKABLE
void endArray();
266 Q_INVOKABLE
void setArrayIndex(
int i);
269 static
bool containsBundle(const QString&
id);
281 static
bool insertBundle(
283 const QString& metaPath,
284 QSettings::Scope scope = QSettings::UserScope,
285 const QString organization = QString(),
286 const QString application = QString());
316 static
bool insertBundle(
319 const QString& dataPath,
320 bool metaAtomic = false);
322 static QVariant getBundle(const QString&
id);
334 static
ZSettings* getBundleSettings(const QString&
id);
335 static QString getBundleMetapath(const QString&
id);
336 static QString getBundleMetadata(const QString&
id);
337 static QVariant getAllBundles();
339 static
bool mapConfigSettings(const
char* configFilePath);
351 static
bool realizeSettings(const QString&
id, const
SettingsBundle& settingsBundle);
353 static QString scopeToText(QSettings::Scope scope);
354 static QSettings::Scope textToScope(const QString& text);
357 Q_INVOKABLE
bool hasBundle(const QString&
id) const;
358 Q_INVOKABLE
bool insertBundle(const QString&
id, QVariant bundle);
359 Q_INVOKABLE QVariant bundle(const QString&
id) const;
360 Q_INVOKABLE QVariant allBundles() const;
418 void settingsModified(const QString& path);
436 const QString& settingPath,
437 const QString& settingName,
448 static
void createTags();
450 static
void dumpMap(const QSettings::SettingsMap &map);
451 static
void dumpGroup(const QString& groupKey, const QVariant& group);
452 inline
void validateStatus() const;
455 static QString rectifySettingsDataPath(const QString& dataPath);
456 static
bool ensureFileExists(const QString& filePath);
457 inline
void validateWatcher() const;
459 void onFileChanged(const QString &path);
466 static QVariant m_tags;
480 static QSettings::Format m_format;
486 static const QString m_ext;
492 static qint64 m_maxFileSize;
498 static bundleMap m_bundles;
522 "Use ZSettings::open method to open the settings object.");
528 throw ZblException(
"Settings watcher not initialized.");
536 #endif // ZSETTINGS_H SettingsBundle(const QString &metaPath, const QString &dataPath)
#define ZBLCORESHARED_EXPORT
This class wraps QFileSystemWatcher and adds path reference counting.
SettingsBundle(const QString &meta, const QString &dataPath, bool metaAtomic)
#define ZBL_DECLARE_LOGGED_OBJECT
SettingsBundle(const QString &dataPath)
QMap< QString, SettingsBundle > bundleMap
SettingsBundle(const QString &metaPath, QSettings::Scope scope=QSettings::UserScope, const QString &organization=QString(), const QString &application=QString())
Wraps the QSettings class and implements a JSON-based backend for storing the settings data...
Zuble's Qt Exception Object.
void validateWatcher() const
QScopedPointer< ZSettings > ZScopedSettings
This inner class allows ZSettings to store settings bundles.