| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef SETTINGSFILEBASE_H |
| 19 |
#define SETTINGSFILEBASE_H |
| 20 |
|
| 21 |
#include <QObject> |
| 22 |
#include <QStringList> |
| 23 |
#include <QJsonObject> |
| 24 |
#include <QJsonValue> |
| 25 |
#include <QTimer> |
| 26 |
#include "SettingsObjectBase.h" |
| 27 |
|
| 28 |
class SettingsObjectBase; |
| 29 |
class SettingsFileBase : public QObject |
| 30 |
{ |
| 31 |
Q_OBJECT |
| 32 |
|
| 33 |
Q_PROPERTY(SettingsObjectBase *object READ object CONSTANT) |
| 34 |
Q_PROPERTY(QString errorString READ errorString NOTIFY error) |
| 35 |
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) |
| 36 |
|
| 37 |
public: |
| 38 |
explicit SettingsFileBase(QObject *parent = 0); |
| 39 |
~SettingsFileBase(); |
| 40 |
QString path() const; |
| 41 |
bool setPath(const QString &path); |
| 42 |
SettingsObjectBase *object(); |
| 43 |
const SettingsObjectBase *object() const; |
| 44 |
|
| 45 |
QString errorString() const; |
| 46 |
QJsonValue read(const QJsonObject &obj, const QStringList &path); |
| 47 |
bool write(const QStringList &path, const QJsonValue &value); |
| 48 |
bool readFile(); |
| 49 |
bool writeFile(); |
| 50 |
|
| 51 |
static QStringList splitPath(const QString &input, bool &ok); |
| 52 |
|
| 53 |
signals: |
| 54 |
void error(); |
| 55 |
void pathChanged(); |
| 56 |
void modified(const QStringList &path, const QJsonValue &value); |
| 57 |
|
| 58 |
protected: |
| 59 |
void reset(); |
| 60 |
void setErrorString(const QString &msg); |
| 61 |
bool checkDirPermissions(const QString &path); |
| 62 |
|
| 63 |
private slots: |
| 64 |
void sync(); |
| 65 |
|
| 66 |
private: |
| 67 |
QString m_path; |
| 68 |
QString m_errorString; |
| 69 |
SettingsObjectBase *m_rootObject; |
| 70 |
|
| 71 |
QJsonObject m_jsonObject; |
| 72 |
QTimer m_syncTimer; |
| 73 |
friend class SettingsObjectBase; |
| 74 |
}; |
| 75 |
|
| 76 |
#endif |