-
Notifications
You must be signed in to change notification settings - Fork 0
/
movetargetdlg.cpp
127 lines (108 loc) · 3.34 KB
/
movetargetdlg.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
#include "movetargetdlg.h"
#include "ui_movetargetdlg.h"
#include <QPushButton>
#include <QMessageBox>
#include <QDebug>
MoveTargetDlg::MoveTargetDlg(QWidget *parent, RHSType type, int &moduleID, int &testID) :
QDialog(parent),
m_moduleID(moduleID),
m_testID(testID),
ui(new Ui::MoveTargetDlg)
{
ui->setupUi(this);
enableButtons(false);
if (type == RHS_Features)
fill(TestProperties::CDC, "Civil Designer component", 1, 10, TestProperties::ACC, "AllyCAD component", 11, 25);
else if (type == RHS_Regressions)
fill(TestProperties::CDR, "Civil Designer regression", 1, 10, TestProperties::ACR, "AllyCAD regression", 26, 26);
}
void MoveTargetDlg::enableButtons(bool enable)
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
}
void MoveTargetDlg::fill(TestProperties::TestType type1, const QString &label1, int start1, int end1, TestProperties::TestType type2, const QString &label2, int start2, int end2)
{
QTreeWidgetItem *initial = nullptr;
auto item1 = Utils::NewTreeItem(nullptr, { type1 }, label1);
auto item2 = Utils::NewTreeItem(nullptr, { type2 }, label2);
QSqlQuery query;
query.prepare("SELECT ModuleID, ModuleName FROM ModuleTbl");
auto Between = [](int test, int start, int end) -> bool { return start <= test && test <= end; };
if (Utils::ExecQuery(query))
{
while (query.next())
{
int id = query.value("ModuleID").toInt();
QString name = query.value("ModuleName").toString();
QTreeWidgetItem *newItem = nullptr;
if (Between(id, start1, end1))
newItem = Utils::NewTreeItem(item1, { type1, id }, name);
else if (Between(id, start2, end2))
newItem = Utils::NewTreeItem(item2, { type2, id }, name);
if (id == m_moduleID)
initial = newItem;
}
}
ui->treeWidget->setColumnCount(1);
ui->treeWidget->setHeaderLabel("Test types");
ui->treeWidget->insertTopLevelItem(0, item1);
ui->treeWidget->insertTopLevelItem(1, item2);
ui->treeWidget->setCurrentItem(initial);
}
MoveTargetDlg::~MoveTargetDlg()
{
delete ui;
}
void MoveTargetDlg::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *)
{
enableButtons(false);
QVariant var = current->data(0, Qt::UserRole);
if (!var.isNull() && var.isValid())
{
TestProperties props = var.value<TestProperties>();
bool hasChildren = current->childCount() > 0;
switch (props.testType)
{
case TestProperties::CDC:
case TestProperties::ACC:
if (props.testID == 0)
{
if (props.moduleID > 0 && !hasChildren)
{
// populate with child items
Utils::ComponentTestsSubtree(current, props);
ui->treeWidget->expandItem(current);
}
}
else
{
// enable OK button if valid selection
bool isValid = props.moduleID > 0 && props.testID > 0 && props.testID != m_testID;
enableButtons(isValid);
}
break;
}
}
}
void MoveTargetDlg::on_MoveTargetDlg_accepted()
{
m_moduleID = 0;
m_testID = 0;
QTreeWidgetItem *current = ui->treeWidget->currentItem();
if (current)
{
QVariant var = current->data(0, Qt::UserRole);
if (!var.isNull() && var.isValid())
{
TestProperties props = var.value<TestProperties>();
m_moduleID = props.moduleID;
m_testID = props.testID;
return;
}
else
qDebug() << "Current item data is null or invalid.";
}
else
qDebug() << "No current item selected.";
QMessageBox::critical(this, "Error", QString("Invalid target destination, very unexpected."));
}