aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/config_builder/cfgmain.h
blob: 4e84befddc44905308c141d9a9d72585a53252f8 (plain) (blame)
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
#ifndef CFGMAIN_H
#define CFGMAIN_H

#include "coreSQLiteStudio_global.h"
#include <QVariant>
#include <QList>
#include <QHash>
#include <QString>

class CfgCategory;
class CfgEntry;

class API_EXPORT CfgMain
{
    friend class CfgCategory;

    public:
        CfgMain(const QString& name, bool persistable, const char* metaName, const QString& title);
        ~CfgMain();

        static void staticInit();
        static QList<CfgMain*> getInstances();
        static QList<CfgMain*> getPersistableInstances();
        static CfgCategory* getCategoryByName(const QString& name);
        static CfgEntry* getEntryByName(const QString& categoryName, const QString& name);
        static CfgEntry* getEntryByPath(const QString& path);

        QHash<QString,CfgCategory*>& getCategories();
        void translateTitle();
        void reset();
        void savepoint(bool transaction = false);
        void restore();
        void release();
        void begin();
        void commit();
        void rollback();
        QStringList getPaths() const;
        QList<CfgEntry*> getEntries() const;

        /**
         * @brief Accepts QVariant produced by toQVariant().
         *
         * This method assumes that the QVariant is actually a multi-level QHash
         * produced by toQVariant() method.
         * It sets all values recursivly using values from provided QVariant.
         */
        void setValuesFromQVariant(const QVariant& cfgMainHash);

        bool isPersistable() const;
        QString getName() const;
        const char* getMetaName() const;
        QString getTitle() const;
        operator CfgMain*();

        /**
         * @brief Serializes this CfgMain to recursive QHash.
         * @return Recursive QHash, where top level has one entry (name of CfgMain), then next level has keys as CfgCategory names, and last one has keys as CfgEntry names.
         */
        QVariant toQVariant() const;

    private:
        QString name;
        const char* metaName;
        QString title;
        bool persistable = true;
        QHash<QString,CfgCategory*> childs;

        static QList<CfgMain*>* instances;
};

Q_DECLARE_METATYPE(CfgMain*)

#endif // CFGMAIN_H