Хранилища Subversion OpenInventory

Редакция

Редакция 135 | Редакция 143 | К новейшей редакции | Весь файл | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 135 Редакция 137
Строка 8... Строка 8...
8
{
8
{
9
    ui->setupUi(this);
9
    ui->setupUi(this);
10
10
11
   
11
   
12
   
12
   
13
    //    settdialog = new SettingsDialog(this);
-
 
14
  /////////////////////////////////////////////////////  settdialog.show();
-
 
-
 
13
15
14
16
    readSettings();
15
    readSettings();
17
16
18
 //   sql.setDatabaseName(tr("an_db"));
-
 
19
17
-
 
18
    initDataBase(); // íàñòðàèâàåì è óñòàíàâëèâàåì ñîåäèíåíèå
-
 
19
    createMainTables(); // ñîçäàåì ñòðóêòóðó íàøåé áàçû - äâå ãëàâíûå òàáëèöû DescriptionOfClasses è ListOfClasses
20
20
21
21
22
22
23
/*
23
/*
24
    field = new TableField(tr("Ñîòðóäíèêè"), this);
24
    field = new TableField(tr("Ñîòðóäíèêè"), this);
Строка 89... Строка 89...
89

89

90
****************************************************/
90
****************************************************/
91
91
92
QString errorString;
92
QString errorString;
93
93
94
// sql.setDatabaseName(tr("an_db"));
-
 
95
-
 
96
sql.setDatabaseName(baseName);
-
 
97
// sql.setDatabaseName(tr("inventory"));
-
 
98
-
 
99
// sql.setHostName(tr("localhost"));
-
 
100
sql.setHostName(hostName);
-
 
101
-
 
102
// sql.setUserName(tr("an"));
-
 
103
-
 
104
sql.setUserName(userName);
-
 
105
-
 
106
// sql.setPassword(tr("393939"));
-
 
107
-
 
108
sql.setPassword(password);
-
 
109
-
 
110
bool ok;
-
 
111
ok = sql.connect();
-
 
112
if (!ok) {
-
 
113
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
114
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
115
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
116
                                                                            sql.lasError());         // Òåêñò ñîîáùåíèÿ.
-
 
117
-
 
118
                     }
-
 
119
else {
-
 
120
-
 
121
    QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
122
                                                    this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
123
                                                    QObject::tr("Database Connect"),   // Çàãîëîâîê.
-
 
124
                                                    QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî."));         // Òåêñò ñîîáùåíèÿ.
-
 
125
-
 
126
94
127
95
128
96
129
-
 
130
}
-
 
131
-
 
132
/*
97
/*
133
ok = sql.createTable(table);
98
ok = sql.createTable(table);
134
if (!ok) {
99
if (!ok) {
135
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
100
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
136
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
101
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
Строка 147... Строка 112...
147

112

148

113

149

114

150
*/
115
*/
151
116
152
ok = sql.createListOfClassesTable();
-
 
153
-
 
154
if (!ok) {
-
 
155
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
156
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
157
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
158
                                                                            sql.lasError());         // Òåêñò ñîîáùåíèÿ.
-
 
159
-
 
160
                     }
-
 
161
else {
-
 
162
-
 
163
    QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
164
                                                    this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
165
                                                    QObject::tr("Database Create"),   // Çàãîëîâîê.
-
 
166
                                                    QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà."));         // Òåêñò ñîîáùåíèÿ.
-
 
167
    }
-
 
168
-
 
169
-
 
170
-
 
171
-
 
172
ok = sql.createDescriptionOfClassesTable();
-
 
173
-
 
174
if (!ok) {
-
 
175
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
176
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
177
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
178
                                                                            sql.lasError());         // Òåêñò ñîîáùåíèÿ.
-
 
179
-
 
180
                     }
-
 
181
else {
-
 
182
-
 
183
    QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
184
                                                    this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
185
                                                    QObject::tr("Database Create"),   // Çàãîëîâîê.
-
 
186
                                                    QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà."));         // Òåêñò ñîîáùåíèÿ.
-
 
187
    }
-
 
188
-
 
189
-
 
190
-
 
191
-
 
192
117
193
118
194
119
195
model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà
120
model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà
196
tableForInstance = new QTableView();
121
tableForInstance = new QTableView();
Строка 199... Строка 124...
199
124
200
//modelForDescription = new QSqlTableModel(this);
125
//modelForDescription = new QSqlTableModel(this);
201
modelForDescription = new ModelForDescriptionTable(this);
126
modelForDescription = new ModelForDescriptionTable(this);
202
127
203
128
204
/////////////////model->setTable(tr("ListOfClasses"));
-
 
205
mymodel->setTable(tr("ListOfClasses"));
-
 
206
modelForDescription->setTable(tr("DescriptionOfClasses"));
-
 
207
modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange);
-
 
208
129
209
/////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
130
initClassListTable();
210
131
211
// modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
132
initFieldsTable();
212
133
213
modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange);
134
initPointersTable();
214
135
215
modelForPointers->setTable(tr("DescriptionOfClasses"));
136
/////////////////model->setTable(tr("ListOfClasses"));
216
137
217
138
218
139
-
 
140
/////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
219
141
220
//mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
142
// modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
221
143
222
144
223
145
224
//////////////////model->setSort(0, Qt::AscendingOrder);
-
 
225
mymodel->setSort(0, Qt::AscendingOrder);
-
 
226
modelForDescription->setSort(0, Qt::AscendingOrder);
-
 
227
modelForPointers->setSort(0, Qt::AscendingOrder);
-
 
228
146
229
//       model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
-
 
230
////////////////////model->select();
-
 
231
mymodel->select();
-
 
232
// modelForPointers->select();
-
 
233
147
234
148
-
 
149
//mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
235
150
236
151
237
/////////////////////////model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
-
 
238
mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
-
 
239
152
-
 
153
//////////////////model->setSort(0, Qt::AscendingOrder);
240
154
241
155
242
////////////////////////model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
-
 
243
mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
-
 
244
mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé"));
-
 
245
156
246
//ui->tableView_3->setModel(modelForPointers);
-
 
247
157
248
//ui->tableView->setModel(model);
158
//       model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
249
ui->tableView->setModel(mymodel);
159
////////////////////model->select();
-
 
160
250
//tableForDescription = new QTableView();
161
//tableForDescription = new QTableView();
251
ui->tableView_2->setModel(modelForDescription);
-
 
252
ui->tableView_2->setAlternatingRowColors(true);
-
 
253
ui->tableView_2->resizeColumnsToContents();
-
 
-
 
162
254
//tableForDescription->show();
163
//tableForDescription->show();
255
164
256
165
257
ui->tableView->setAlternatingRowColors(true);
-
 
258
ui->tableView->resizeColumnsToContents();
-
 
259
166
260
ui->tableView->hideColumn(0);
-
 
261
ui->tableView->hideColumn(3);
-
 
262
ui->tableView->hideColumn(2);
-
 
263
167
264
/*
168
/*
265
ui->tableView_2->hideColumn(0);
169
ui->tableView_2->hideColumn(0);
266
ui->tableView_2->hideColumn(5);
170
ui->tableView_2->hideColumn(5);
267
ui->tableView_2->hideColumn(2);
171
ui->tableView_2->hideColumn(2);
268
*/
172
*/
269
ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
-
 
270
173
271
delegateForDefaultValueColomn.getItems();
-
 
272
ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn);
-
 
273
174
274
175
275
176
276
if (mymodel->rowCount() > 0) {
-
 
277
177
278
178
-
 
179
//if (mymodel->rowCount() > 0) {
-
 
180
-
 
181
-
 
182
-
 
183
/*
-
 
184

-
 
185
currIndexOfClassesTable = mymodel->index(0, 1);
-
 
186

279
187

280
    currIndexOfClassesTable = mymodel->index(0, 1);
-
 
281
QModelIndex index_temp;
188
QModelIndex index_temp;
282
189

283
190

284
191

285
currClassID = mymodel->data(mymodel->index(0,0)).toString();
192
currClassID = mymodel->data(mymodel->index(0,0)).toString();
Строка 299... Строка 206...
299
QString str_fltr = tr("ClassIdentifer = ");
206
QString str_fltr = tr("ClassIdentifer = ");
300
class_indx = mymodel->data(mymodel->index(0,0)).toString();
207
class_indx = mymodel->data(mymodel->index(0,0)).toString();
301
class_instance = mymodel->data(mymodel->index(0,3)).toString();
208
class_instance = mymodel->data(mymodel->index(0,3)).toString();
302
209

303
currInctanceTable = class_instance; //
210
currInctanceTable = class_instance; //
-
 
211

-
 
212

-
 
213

304
modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
214
modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
305
//class_instance.append(tr("_inctance"));
215
//class_instance.append(tr("_inctance"));
306
str_fltr.append(class_indx);
216
str_fltr.append(class_indx);
307
str_fltr.append(tr(" AND FieldType <> \"pointer\""));
217
str_fltr.append(tr(" AND FieldType <> \"pointer\""));
308
218

Строка 328... Строка 238...
328
238

329
239

330
240

331
 modelForPointers->setFilter(str_fltr);
241
 modelForPointers->setFilter(str_fltr);
332
modelForPointers->select();
242
modelForPointers->select();
333
ui->tableView_3->setModel(modelForPointers);
-
 
334
ui->tableView_3->resizeColumnsToContents();
-
 
335
243

336
}
244

-
 
245
*/
337
246
338
//connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
247
//connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
339
connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex)));
248
connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex)));
340
connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex)));
249
connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex)));
341
//connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
250
//connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
Строка 623... Строка 532...
623
//ui->tableView->setModel(mymodel);
532
//ui->tableView->setModel(mymodel);
624
533
625
}
534
}
626
535
627
void ClassEditor::on_tableView_clicked(const QModelIndex & index ){
536
void ClassEditor::on_tableView_clicked(const QModelIndex & index ){
-
 
537
    bool indexIsValid;
628
    int i, row, column;
538
    int i, row, column;
629
    i++;
539
    i++;
-
 
540
    indexIsValid = index.isValid();
630
    row = index.row();
541
    row = index.row();
631
    column = index.column();
542
    column = index.column();
632
    currIndexOfClassesTable = index;
543
    currIndexOfClassesTable = index;
633
    QModelIndex index_tmp, index_instance;
544
    QModelIndex index_tmp, index_instance;
634
    QString tmp_str, filter_str, instance_str;
545
    QString tmp_str, filter_str, instance_str;
Строка 1097... Строка 1008...
1097
}
1008
}
1098
1009
1099
1010
1100
void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ
1011
void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ
1101
1012
-
 
1013
    sql.setDatabaseName(baseName);
-
 
1014
    sql.setHostName(hostName);
-
 
1015
    sql.setUserName(userName);
-
 
1016
    sql.setPassword(password);
-
 
1017
-
 
1018
    bool ok;
-
 
1019
    ok = sql.connect();
-
 
1020
    if (!ok) {
-
 
1021
                                QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
1022
                                                                                this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
1023
                                                                                QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
1024
                                                                                sql.lasError());         // Òåêñò ñîîáùåíèÿ.
-
 
1025
-
 
1026
                         }
-
 
1027
    else {
-
 
1028
-
 
1029
        QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
1030
                                                        this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
1031
                                                        QObject::tr("Database Connect"),   // Çàãîëîâîê.
-
 
1032
                                                        QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî."));         // Òåêñò ñîîáùåíèÿ.
-
 
1033
-
 
1034
-
 
1035
-
 
1036
-
 
1037
-
 
1038
    }
-
 
1039
-
 
1040
}
-
 
1041
-
 
1042
-
 
1043
void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses
-
 
1044
-
 
1045
    bool ok;
-
 
1046
    ok = sql.createListOfClassesTable();
-
 
1047
-
 
1048
    if (!ok) {
-
 
1049
                                QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
1050
                                                                                this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
1051
                                                                                QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
1052
                                                                                sql.lasError());         // Òåêñò ñîîáùåíèÿ.
-
 
1053
-
 
1054
                         }
-
 
1055
    else {
-
 
1056
-
 
1057
        QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
1058
                                                        this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
1059
                                                        QObject::tr("Database Create"),   // Çàãîëîâîê.
-
 
1060
                                                        QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà."));         // Òåêñò ñîîáùåíèÿ.
-
 
1061
        }
-
 
1062
-
 
1063
-
 
1064
-
 
1065
-
 
1066
    ok = sql.createDescriptionOfClassesTable();
-
 
1067
-
 
1068
    if (!ok) {
-
 
1069
                                QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
1070
                                                                                this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
1071
                                                                                QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
1072
                                                                                sql.lasError());         // Òåêñò ñîîáùåíèÿ.
-
 
1073
-
 
1074
                         }
-
 
1075
    else {
-
 
1076
-
 
1077
        QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
1078
                                                        this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
1079
                                                        QObject::tr("Database Create"),   // Çàãîëîâîê.
-
 
1080
                                                        QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà."));         // Òåêñò ñîîáùåíèÿ.
-
 
1081
        }
-
 
1082
-
 
1083
-
 
1084
-
 
1085
-
 
1086
-
 
1087
-
 
1088
-
 
1089
}
-
 
1090
-
 
1091
void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ
-
 
1092
-
 
1093
    mymodel->setTable(tr("ListOfClasses"));
-
 
1094
    mymodel->setSort(0, Qt::AscendingOrder);
-
 
1095
    mymodel->select();
-
 
1096
    mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
-
 
1097
    mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
-
 
1098
    mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé"));
-
 
1099
    ui->tableView->setModel(mymodel);
-
 
1100
    ui->tableView->setAlternatingRowColors(true);
-
 
1101
    ui->tableView->resizeColumnsToContents();
-
 
1102
-
 
1103
    ui->tableView->hideColumn(0);
-
 
1104
    ui->tableView->hideColumn(3);
-
 
1105
    ui->tableView->hideColumn(2);
-
 
1106
}
-
 
1107
-
 
1108
-
 
1109
void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ
-
 
1110
-
 
1111
    modelForDescription->setTable(tr("DescriptionOfClasses"));
-
 
1112
    modelForDescription->setSort(0, Qt::AscendingOrder);
-
 
1113
    modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange);
-
 
1114
    ui->tableView_2->setModel(modelForDescription);
-
 
1115
    ui->tableView_2->setAlternatingRowColors(true);
-
 
1116
    ui->tableView_2->resizeColumnsToContents();
-
 
1117
    ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
-
 
1118
}
-
 
1119
-
 
1120
void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà
-
 
1121
-
 
1122
    modelForPointers->setTable(tr("DescriptionOfClasses"));
-
 
1123
    modelForPointers->setSort(0, Qt::AscendingOrder);
-
 
1124
    modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange);
-
 
1125
    ui->tableView_3->setModel(modelForPointers);
-
 
1126
    delegateForDefaultValueColomn.getItems();
-
 
1127
    ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn);
-
 
1128
-
 
1129
  //  ui->tableView_3->resizeColumnsToContents();
1102
1130
1103
}
1131
}