-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAnsleDictConfigFile.cpp
66 lines (60 loc) · 1.52 KB
/
AnsleDictConfigFile.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
#include "AnsleDictConfigFile.h"
#include "QFile"
#include "QStringList"
ConfigFile::ConfigFile(const QString &path)
{
bool isExists = QFile::exists(path);
cfg = new QSettings(path, QSettings::IniFormat);
cfg->setIniCodec("GB18030");
if (!isExists)
{
initMainConfig();
}
}
ConfigFile::~ConfigFile()
{
delete cfg;
}
void ConfigFile::initMainConfig()
{
LISTMAPINFO LMI_Speech;
QMap<QString, QVariant> SpeechConfig;
SpeechConfig["SpeakMethod"] = "eSpeakTTS";
SpeechConfig["QtSpeakTTS"] = "";
SpeechConfig["SpeackRate"] = "0";
LMI_Speech << SpeechConfig;
setLMI("SpeakTTS", LMI_Speech);
}
LISTMAPINFO ConfigFile::getLMI(const QString &prefix)
{
LISTMAPINFO result;
int size = cfg->beginReadArray(prefix);
for(int i = 0; i < size; i++)
{
cfg->setArrayIndex(i);
QStringList keys = cfg->childKeys();
QMap<QString, QVariant> learnWordConfig;
for(int j = 0; j < keys.size(); j++)
{
learnWordConfig[keys[j]] = cfg->value(keys[j]).toString();
}
result << learnWordConfig;
}
cfg->endArray();
return result;
}
void ConfigFile::setLMI(const QString &prefix, LISTMAPINFO &lmi)
{
cfg->beginWriteArray(prefix);
for(int i = 0; i < lmi.size(); i++)
{
// cfg->setArrayIndex(i);
QMapIterator<QString, QVariant> iter(lmi.at(i));
while (iter.hasNext())
{
iter.next();
cfg->setValue(iter.key(), iter.value());
}
}
cfg->endArray();
}