-
Notifications
You must be signed in to change notification settings - Fork 5
/
pagefeatures.cpp
183 lines (162 loc) · 5.17 KB
/
pagefeatures.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "featurefilterproxy.h"
#include "pagefeatures.h"
#include "global.h"
#include "condition.h"
#include <QKeyEvent>
#include <QMessageBox>
#include <QStandardItemModel>
#include <featuresmodel.h>
#include <qtlitedialog.h>
PageFeatures::PageFeatures(ConfigManager *config, QWidget *parent)
: WizardPageBase(config, parent)
{
setupUi(this);
featuresModel = _config->featuresModel();
featuresFilter = new FeatureFilterProxy(this);
featuresFilter->setFilterKeyColumn(0);
featuresFilter->setSourceModel(featuresModel);
treeView->installEventFilter(this);
treeView->setModel(featuresFilter);
connect(_config, &ConfigManager::configuresUpdated,
this, &PageFeatures::config_configuresUpdated);
#ifndef WEB_REQUEST_LIB
pushButtonQtLite->hide();
#endif
}
void PageFeatures::config_configuresUpdated()
{
comboBoxModules->clear();
comboBoxModules->addItem("");
comboBoxModules->addItems(_config->selectedModules());
treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
treeView->header()->setSectionResizeMode(1, QHeaderView::Interactive);
}
void PageFeatures::on_pushButtonFeatureInclude_clicked()
{
setSelectedFeaturesState(Qt::Checked);
}
void PageFeatures::on_pushButtonFeatureExclude_clicked()
{
setSelectedFeaturesState(Qt::Unchecked);
}
void PageFeatures::on_pushButtonFeatureUncheck_clicked()
{
setSelectedFeaturesState(Qt::PartiallyChecked);
}
void PageFeatures::setSelectedFeaturesState(const Qt::CheckState &state)
{
QString text;
QVariant color;
switch (state) {
case Qt::Checked:
text = "Yes";
color = QColor(Qt::green);
break;
case Qt::Unchecked:
text = "No";
color = QColor(Qt::red);
break;
case Qt::PartiallyChecked:
break;
}
auto selectionModel = treeView->selectionModel();
foreach (QModelIndex idx, selectionModel->selectedIndexes()){
auto mapped = featuresFilter->mapToSource(idx);
featuresModel->setState(mapped, state);
}
}
bool PageFeatures::eventFilter(QObject *watched, QEvent *event)
{
if (watched == treeView && event->type() == QEvent::KeyPress) {
auto e = dynamic_cast<QKeyEvent*>(event);
switch (e->key()) {
case Qt::Key_Plus:
setSelectedFeaturesState(Qt::Checked);
break;
case Qt::Key_Minus:
setSelectedFeaturesState(Qt::Unchecked);
break;
case Qt::Key_Equal:
setSelectedFeaturesState(Qt::PartiallyChecked);
break;
default:
break;
}
}
return WizardPageBase::eventFilter(watched, event);
}
void PageFeatures::checkItem(QStandardItem *item) {
for (int i = 0; i < item->rowCount(); ++i) {
auto child = item->child(i, 0);
checkItem(child);
}
QVariant v = item->data(DataRole);
if (v.isValid()) {
QModelIndex idx = featuresModel->index(item->index().row(), 1, item->index().parent());
Feature *ft = v.value<Feature*>();
Qt::CheckState state = featuresModel->data(idx, CheckStateRole).value<Qt::CheckState>();
QString name = ft->name;
if (state != Qt::PartiallyChecked)
_config->setFeatureState(name, state);
}
}
bool PageFeatures::validatePage()
{
_config->clearFeatureStates();
// for (int i = 0; i < featuresModel->rowCount(); ++i) {
// auto moduleItem = featuresModel->item(i, 0);
// checkItem(moduleItem);
// }
return true;
}
void PageFeatures::on_treeView_activated(const QModelIndex &index)
{
auto ft = featuresModel->feature(featuresFilter->mapToSource(index));
if (ft) {
auto condition = ft->condition.join(" && ");
cond = Condition(condition, _config);
cond.check();
labelName->setText(ft->name);
labelLabel->setText(ft->label);
labelSection->setText(ft->section);
labelPurpose->setText(ft->purpose);
labelCondition->setText(condition);
auto requirement = cond.requirement();
if (requirement.size())
labelRequires->setText(requirement.join(", "));
else
labelRequires->setText("None");
// if (condition.isEmpty())
// labelCondition->clear();
// else {
bool cc = cond.result();
labelCondition->setText(QString(cc ? "True" : "False") + " (<a href=#>Explain</a>)");
// }
// qDebug() << cond.check() << condition;
}
}
void PageFeatures::on_lineEditFilterFeature_textChanged(const QString &s)
{
featuresFilter->setSearchName(s);
}
void PageFeatures::on_comboBoxModules_currentTextChanged(const QString &s)
{
featuresFilter->setModuleName(s);
}
void PageFeatures::on_labelCondition_linkActivated(const QString &link)
{
Q_UNUSED(link)
QMessageBox::information(this, "Condition result",
cond.cond() + "\n" +
cond.toString());
}
void PageFeatures::on_pushButtonQtLite_clicked()
{
QtLiteDialog d(this);
if (d.exec() == QDialog::Accepted) {
auto fs = d.features();
foreach (QString f, fs)
_config->setFeatureState(f, Qt::Unchecked);
config_configuresUpdated();
}
}