-
Notifications
You must be signed in to change notification settings - Fork 15
/
config.cpp
executable file
·95 lines (62 loc) · 1.61 KB
/
config.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
#include "config.h"
#include <QtCore/QtCore>
#include <QDebug>
Config::Config(QString qstrfilename)
{
if (qstrfilename.isEmpty())
{
m_qstrFileName = QDir::currentPath()+ "/Config.ini";
}
else
{
m_qstrFileName = qstrfilename;
}
m_psetting = new QSettings(m_qstrFileName, QSettings::IniFormat);
qDebug() << m_qstrFileName;
}
Config::~Config()
{
delete m_psetting;
m_psetting = 0;
}
void Config::set(QString qstrnodename,QString qstrkeyname,QVariant qvarvalue)
{
m_psetting->setValue(QString("/%1/%2").arg(qstrnodename).arg(qstrkeyname), qvarvalue);
}
QVariant Config::get(QString qstrnodename,QString qstrkeyname)
{
QVariant qvar = m_psetting->value(QString("/%1/%2").arg(qstrnodename).arg(qstrkeyname));
return qvar;
}
void Config::setValue(QString keypath,QVariant qvarvalue)
{
m_psetting->setValue(keypath, qvarvalue);
}
QVariant Config::getValue(QString keypath)
{
return m_psetting->value(keypath);
}
QStringList Config::allKeys(){
return m_psetting->allKeys();
}
QStringList Config::getKeys(QString key){
QStringList list,keys;
list= m_psetting->allKeys();
for(int i=0;i<list.size();i++){
if(list.value(i).trimmed().indexOf(QRegExp("(?:^|/)"+key+"(?:$|/)"))!=-1){
keys.append(list.value(i));
}
}
return keys;
}
void Config::remove(QString keypath){
m_psetting->remove(keypath);
}
bool Config::iskey(QString qstrnodename,QString qstrkeyname)
{
return m_psetting->contains(QString("/%1/%2").arg(qstrnodename).arg(qstrkeyname));
}
void Config::clear()
{
m_psetting->clear();
}