-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptionwidget.cpp
145 lines (137 loc) · 4.15 KB
/
optionwidget.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "optionwidget.h"
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
OptionWidget::OptionWidget( QWidget *parent) : QWidget(parent)
{
}
OptionWidget::OptionWidget(QStringList options, QMap<QString, QString>* sdkConfig, QWidget *parent) : QWidget(parent)
{
this->options = options;
this->sdkConfig = sdkConfig;
init(options, sdkConfig) ;
}
void OptionWidget::init(QStringList options, QMap<QString, QString> *sdkConfig)
{
this->options = options;
this->sdkConfig = sdkConfig;
if(!initDone)
{
setMinimumHeight(100);
QScrollArea* scrollArea = new QScrollArea();
setLayout(new QVBoxLayout());
panel = new QWidget();
panel->setLayout(new QVBoxLayout());
scrollArea->setWidget(panel);
scrollArea->setWidgetResizable(true);
layout()->addWidget(scrollArea);
initDone = true;
}
else
{
while ( QWidget* w = panel->findChild<QWidget*>() )
delete w;
}
foreach (QString line, options)
{
if(line.isEmpty())
{
QLabel* label = new QLabel(line);
panel->layout()->addWidget(label);
continue;
}
if(line.startsWith("#"))
{
if(!line.endsWith(" is not set"))
{
QLabel* label = new QLabel(line);
panel->layout()->addWidget(label);
continue;
}
else
{
QStringList sl = line.split(" ");
if(sl.count() >= 3)
{
QWidget* panel1 = new QWidget();
QHBoxLayout* pane11Layout = new QHBoxLayout(panel1);
QLabel* label = new QLabel(sl.at(1));
pane11Layout->addWidget(label, 1, Qt::AlignLeft);
QLineEdit* le = new QLineEdit();
le->setPlaceholderText("not active");
le->setToolTip(tr("enter 'y', number or text"));
pane11Layout->addWidget(le, 0, Qt::AlignRight);
connect(le, &QLineEdit::textEdited, [=]{
updateOption(sl.at(1), le->text());
});
panel->layout()->addWidget(panel1);
continue;
}
}
}
else
{
QStringList sl = line.split("=");
if(sl.count() >= 2)
{
QWidget* panel1 = new QWidget();
QHBoxLayout* pane11Layout = new QHBoxLayout(panel1);
QLabel* label = new QLabel(sl.at(0));
pane11Layout->addWidget(label, 1, Qt::AlignLeft);
QLineEdit* le = new QLineEdit();
le->setText(sl.at(1));
le->setToolTip(tr("enter 'y', number or text or blank to deactivate"));
pane11Layout->addWidget(le, 0, Qt::AlignRight);
connect(le, &QLineEdit::textEdited, [=]{
updateOption(sl.at(0), le->text());
});
panel->layout()->addWidget(panel1);
continue;
}
}
}
}
void OptionWidget::updateOption(QString name, QString value)
{
if(value.isEmpty() || value == "y" || value == "n")
sdkConfig->insert(name, value);
else
{
if(value.startsWith("\""))
{
if(value.endsWith("\""))
sdkConfig->insert(name, value);
else
{
QMessageBox::critical(this, tr("Error"), tr("missing terminating \""));
return;
}
}
else
{
bool ok;
int i;
float d;
value.toInt(&ok);
if(ok)
{
sdkConfig->insert(name, value);
return;
}
value.toInt(&ok, 16);
if(ok)
{
sdkConfig->insert(name, value);
return;
}
d= value.toFloat(&ok);
if(ok)
{
sdkConfig->insert(name, value);
return;
}
// must be a string
sdkConfig->insert(name, "\""+value+"\"");
}
}
}