-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdepth_dialog.cpp
More file actions
160 lines (123 loc) · 3.86 KB
/
depth_dialog.cpp
File metadata and controls
160 lines (123 loc) · 3.86 KB
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
#include"depth_dialog.h"
depthDialog::depthDialog(int ID, QWidget *parent, const char *name, bool modal, WFlags f) : QDialog(parent,name,modal,f)
{
HDM::startTransaction();
delTmp();
positionID = ID;
selectStr = "positionID=" + QString::number(ID);
buildTmpTable();
buildWidget();
}
depthDialog::depthDialog(QWidget *parent, const char *name, bool modal, WFlags f) : QDialog(parent,name,modal,f)
{
HDM::startTransaction();
delTmp();
////////////////////////////////////////////////////////////////
//
// Create a entry in the positions table to recive
// the new position
//
////////////////////////////////////////////////////////////////
QSqlQuery qa("INSERT INTO positions (positionName) VALUES ('Position Name')");
/*QSqlCursor *cur1 = new QSqlCursor("positions");
cur1->primeInsert();
cur1->setValue("positionName", "NewPosition");
cur1->insert();
*/
////////////////////////////////////////////////////////////////
//
// Fetch the key of the new position
//
////////////////////////////////////////////////////////////////
/* QSqlQuery q1("SELECT LAST_INSERT_ID()");
if(q1.next())
{
positionID = q1.value(0).toInt();
selectStr = "positionID= " + QString::number(positionID);
}
else
HDM::SqlBomb("","");
*/
QSqlQuery q1("SELECT positionID FROM positions WHERE positionName = 'Position Name'");
if(q1.next())
{
positionID = q1.value(0).toInt();
selectStr = "positionID= " + QString::number(positionID);
}
else
HDM::SqlBomb("error in DD consructor", "No positionID Available");
////////////////////////////////////////////////////////////////
//
// Create new entries in hattrick.position_order
// and hattrick.position_weight
//
////////////////////////////////////////////////////////////////
QSqlQuery q2("INSERT INTO position_weight (positionID) Values (" + QString::number(positionID) + ")");
QSqlQuery q3("INSERT INTO position_order (positionID) Values (" + QString::number(positionID) + ")");
buildTmpTable();
buildWidget();
}
void depthDialog::buildTmpTable()
{
QSqlQuery sql;
QSqlCursor fetchCursor("position_order");
fetchCursor.select(selectStr);
fetchCursor.next();
QSqlCursor fetchWeightCursor("position_weight");
fetchWeightCursor.select(selectStr);
fetchWeightCursor.next();
QStringList positionlist = fetchCursor.toStringList();
for(QStringList::Iterator it = positionlist.begin(); it!=positionlist.end(); ++it)
{
if(*it !="positionID")
{
QSqlQuery sql;
sql.prepare("INSERT INTO tmp (Name, fieldOrder, Weight) VALUES(?,?,?)");
sql.bindValue(0, *it);
sql.bindValue(1, fetchCursor.value(*it).toString());
sql.bindValue(2, fetchWeightCursor.value(*it).toString());
sql.exec();
}
}
}
void depthDialog::buildWidget()
{
tablebox = new QVBoxLayout(this);
textEditBox = new QHBoxLayout(tablebox);
setupBox = new QHBoxLayout(tablebox);
unselectedStrList= new QStringList();
/* query = new QSqlQuery();
if(!(query->exec("SELECT Name FROM tmp WHERE fieldOrder = -1")));
HDM::SqlBomb("depth_dialog A : Couldn't read tmp Table", query->lastError().text());
*/
query = new QSqlQuery("SELECT Name FROM tmp WHERE fieldOrder = -1");
if(query->isActive())
{
while(query->next())
unselectedStrList->append(query->value(0).toString());
delete query;
}
listBox = new QListBox();
listBox->insertStrList(unselectedStrList);
listBox->show();
cursor = new QSqlCursor("tmp");
cursor->select("fieldOrder > -1");
QSqlIndex idx = cursor->index(cursor->toStringList());
idx.setDescending(1,TRUE);
table = new QDataTable(cursor);
table->addColumn("Name","Name");
table->setColumnReadOnly(0, TRUE);
table->addColumn("Weight","Weight");
table->setAutoDelete(TRUE);
table->refresh();
table->verticalHeader()->hide();
table->setLeftMargin(0);
table->show();
setupBox->addWidget(listBox);
setupBox->addWidget(table);
}
void depthDialog::delTmp()
{
QSqlQuery del;
del.exec("DELETE FROM tmp");
}