-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITranslatable.cpp
79 lines (73 loc) · 2.09 KB
/
ITranslatable.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
#include "ITranslatable.h"
#include <QString>
#include <QWidget>
#include <QLineEdit>
#include <QCheckBox>
#include <QComboBox>
void ITranslatable::fromText(QStringList &text)
{
//Get Translation map
QMap <QString,QWidget*> paramMap = getParameterMap();
for (int i=0; i<text.count(); ++i) {
QString t = text.at(i);
//Get param key
QString key = t.section("=",0,0).trimmed();
if (paramMap.find(key) != paramMap.end()) {
QWidget* p = paramMap.find(key).value();
//Is text type.
QLineEdit* l = dynamic_cast<QLineEdit*>(p);
if (l) {
l->setText(t.section("=",1,1).trimmed());
continue;
}
//Is checkbox type.
QCheckBox* b = dynamic_cast<QCheckBox*>(p);
if (b) {
if (t.section("=",1,1).trimmed() == "yes")
b->setChecked(true);
else
b->setChecked(false);
continue;
}
}
}
}
QStringList ITranslatable::toText()
{
QStringList output;
QMap<QString,QWidget*> paramMap = getParameterMap();
QMap<QString,QWidget*>::iterator it = paramMap.begin();
for (it; it != paramMap.end(); ++it) {
QWidget* p = it.value();
if (!p->isVisible())
//Don't output non-visible params
continue;
QString key = it.key();
QString out = key + " = ";
//Is text type
QLineEdit* l = dynamic_cast<QLineEdit*>(p);
if (l) {
out += l->text();
output << out;
continue;
}
//Is checkbox type.
QCheckBox* b = dynamic_cast<QCheckBox*>(p);
if (b) {
if (b->isChecked())
out += "yes";
else
out += "no";
output << out;
continue;
}
//Is combobox type.
QComboBox* c = dynamic_cast<QComboBox*>(p);
if (c) {
out += c->currentText();
output << out;
continue;
}
}
return output;
}