File: cfgcategory.cpp

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (118 lines) | stat: -rw-r--r-- 2,396 bytes parent folder | download
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "cfgcategory.h"
#include "config_builder/cfgmain.h"
#include "config_builder/cfgentry.h"

CfgCategory* lastCreatedCfgCategory = nullptr;
extern CfgMain* lastCreatedCfgMain;

CfgCategory::CfgCategory(const CfgCategory &other) :
    QObject(), name(other.name), title(other.title), persistable(other.persistable), childs(other.childs)
{
    lastCreatedCfgCategory = this;
    lastCreatedCfgMain->childs[name] = this;
    cfgParent = lastCreatedCfgMain;
    for (CfgEntry*& entry : childs)
        entry->parent = this;
}

CfgCategory::CfgCategory(const QString &name, const QString &title) :
    name(name), title(title)
{
    this->persistable = lastCreatedCfgMain->persistable;
    lastCreatedCfgCategory = this;
    cfgParent = lastCreatedCfgMain;
    lastCreatedCfgMain->childs[name] = this;
}

CfgEntry *CfgCategory::getEntryByName(const QString& name)
{
    if (childs.contains(name))
        return childs[name];

    return nullptr;
}

QString CfgCategory::toString() const
{
    return name;
}

QHash<QString, CfgEntry *> &CfgCategory::getEntries()
{
    return childs;
}

void CfgCategory::translateTitle()
{
    // This needs to be "QObject::tr" and not just "tr", because this guarantees proper message context for retranslating
    // titles for objects initialized in global scope (as CfgCategories are).
    title = QObject::tr(title.toUtf8().constData());
    for (CfgEntry*& entry : childs)
        entry->translateTitle();

}

void CfgCategory::reset()
{
    for (CfgEntry*& entry : childs)
        entry->reset();
}

void CfgCategory::savepoint(bool transaction)
{
    for (CfgEntry*& entry : childs)
        entry->savepoint(transaction);
}

void CfgCategory::restore()
{
    for (CfgEntry*& entry : childs)
        entry->restore();
}

void CfgCategory::release()
{
    for (CfgEntry*& entry : childs)
        entry->release();
}

void CfgCategory::commit()
{
    release();
}

void CfgCategory::rollback()
{
    for (CfgEntry*& entry : childs)
        entry->rollback();
}

void CfgCategory::begin()
{
    savepoint(true);
}

QString CfgCategory::getTitle() const
{
    return title;
}

CfgMain*CfgCategory::getMain() const
{
    return cfgParent;
}

CfgCategory::operator CfgCategory *()
{
    return this;
}

void CfgCategory::handleEntryChanged()
{
    emit changed(dynamic_cast<CfgEntry*>(sender()));
}

CfgCategory::operator QString() const
{
    return name;
}