forked from bnufree/Hq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stkinfofilemanage.cpp
99 lines (91 loc) · 2.43 KB
/
stkinfofilemanage.cpp
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
#include "stkinfofilemanage.h"
StkInfoFileManage::StkInfoFileManage(const QString& filenm, QObject *parent) :
configSettings(NULL),
QObject(parent)
{
configSettings = new QSettings(QString("data/%1").arg(filenm), QSettings::IniFormat);
configSettings->setIniCodec(QTextCodec::codecForName("GB18030"));
}
StkInfoFileManage::~StkInfoFileManage()
{
if(configSettings)
{
configSettings->deleteLater();
}
}
/*-------------------------------------------
*
* 设置默认值
*
---------------------------------------------*/
void StkInfoFileManage::setDefault(const QString & prefix,const QString &key, const QVariant &value)
{
configSettings->beginGroup(prefix);
if(configSettings->value(key).toString().isEmpty())
{
configSettings->setValue(key, value);
}
configSettings->endGroup();
}
/*-------------------------------------------
*
* 设置配置文件值
*
---------------------------------------------*/
void StkInfoFileManage::setValue(const QString & prefix,const QString & key, const QVariant & value)
{
//qDebug()<<"prefix:"<<prefix<<" key:"<<key<<" value:"<<value;
configSettings->beginGroup(prefix);
{
configSettings->setValue(key, value);
}
configSettings->endGroup();
configSettings->sync();
}
/*-------------------------------------------
*
* 返回值
*
---------------------------------------------*/
QVariant StkInfoFileManage::value(const QString & prefix,const QString &keys, const QVariant &defaultValue)
{
QVariant values;
configSettings->beginGroup(prefix);
{
values = configSettings->value( keys,defaultValue);
}
configSettings->endGroup();
return values;
}
QStringList StkInfoFileManage::getAllSections()
{
return configSettings->childGroups();
}
void StkInfoFileManage::clear()
{
configSettings->clear();
}
QStringList StkInfoFileManage::subkeys(const QString &prefix)
{
QStringList keys;
configSettings->beginGroup(prefix);
{
keys = configSettings->childKeys();
}
configSettings->endGroup();
return keys;
}
void StkInfoFileManage::removeKeys(const QString &prefix, const QStringList &keys)
{
configSettings->beginGroup(prefix);
{
foreach (QString key, keys) {
configSettings->remove(key);
}
}
configSettings->endGroup();
}
void StkInfoFileManage::removeGroup(const QString &prefix)
{
removeKeys(prefix, subkeys(prefix));
}