#ifndef CONFIGRATION_H #define CONFIGRATION_H #include #include #include #include namespace Config { class Configration : public QObject { public: explicit Configration(QObject *parent); virtual ~Configration() = default; virtual int loadFile(const QString &path) = 0; virtual QDir currentDir() const = 0; virtual void save() const = 0; virtual void deleteX(const QList &path) = 0; virtual void setConfig(const QList &path, const QString &value) = 0; virtual QString getConfig(const QList &path) const = 0; virtual void setList(const QList &path, const QList &list) = 0; virtual QList getList(const QList &path) const = 0; virtual void setMap(const QList &path, const QHash &map) = 0; virtual QHash getMap(const QList &path) const = 0; }; class ConfigHelper { public: static QString getConfigAsDefault(Configration *ins, const QList &path, const QString & default_v) { auto xval = ins->getConfig(path); if(xval.trimmed() == ""){ ins->setConfig(path, default_v); ins->save(); xval = default_v; } return xval; } static QList getListAsDefault(Configration *ins, const QList &path, const QList & default_v) { auto xval = ins->getList(path); if(xval.size() == 0){ ins->setList(path, default_v); ins->save(); xval = default_v; } return xval; } static QHash getHashAsDefault(Configration *ins, const QList &path, const QHash & default_v) { auto xval = ins->getMap(path); if(xval.size()==0){ ins->setMap(path, default_v); ins->save(); xval = default_v; } return xval; } }; inline Configration::Configration(QObject *parent) : QObject(parent){} } #endif // CONFIGRATION_H