Редакция 165 | Редакция 168 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
24 | pingvin | 1 | #include "classeditor.h" |
2 | #include "ui_classeditor.h" |
||
3 | |||
45 | pingvin | 4 | |
24 | pingvin | 5 | ClassEditor::ClassEditor(QWidget *parent) : |
6 | QMainWindow(parent), |
||
7 | ui(new Ui::ClassEditor) |
||
8 | { |
||
9 | ui->setupUi(this); |
||
60 | pingvin | 10 | |
165 | pingvin | 11 | iconFrm.show(); |
60 | pingvin | 12 | |
56 | pingvin | 13 | |
137 | pingvin | 14 | |
135 | pingvin | 15 | readSettings(); |
16 | |||
17 | |||
137 | pingvin | 18 | initDataBase(); // |
19 | createMainTables(); // - DescriptionOfClasses ListOfClasses |
||
135 | pingvin | 20 | |
21 | |||
22 | |||
60 | pingvin | 23 | /* |
35 | pingvin | 24 | field = new TableField(tr(""), this); |
38 | pingvin | 25 | field->setNotNull(true); |
35 | pingvin | 26 | field->setDefaultValue(tr("")); |
33 | pingvin | 27 | |
38 | pingvin | 28 | table = new SqlTable (tr("NewTable"), this); |
29 | table->setName(tr("NewTable")); |
||
39 | pingvin | 30 | table->fields().at(0)->setNotNull(true); |
31 | if (!(table->setPrimaryKey(tr("ID")))) { |
||
32 | ui->label_3->setText(table->lastError()); |
||
33 | } |
||
34 | else ui->label_3->setText(table->primaryKey()); |
||
35 | table->append(field); |
||
36 | |||
37 | field = new TableField(tr(""), this); |
||
38 | field->setNotNull(true); |
||
39 | field->setDefaultValue(tr("")); |
||
40 | table->append(field); |
||
41 | |||
40 | pingvin | 42 | field = new TableField(tr(""), this); |
43 | field->setNotNull(true); |
||
44 | field->setDefaultValue(tr("")); |
||
45 | table->append(field); |
||
46 | |||
47 | field = new TableField(tr(" ()"), this); |
||
48 | field->setNotNull(true); |
||
49 | field->setType(tr("INTEGER")); |
||
50 | field->setDefaultValue(tr("1")); |
||
51 | table->append(field); |
||
52 | |||
53 | field = new TableField(tr(" "), this); |
||
54 | field->setNotNull(false); |
||
55 | field->setType(tr("DATE")); |
||
56 | field->setDefaultValue(tr("NULL")); |
||
57 | table->append(field); |
||
58 | |||
38 | pingvin | 59 | ui->label_2->setText(table->name()); |
60 | ui->label->setText(table->fields().at(0)->sqlString()); |
||
39 | pingvin | 61 | ui->label_4->setText(table->sqlString()); |
40 | pingvin | 62 | ////// ui->lineEdit->insert(table->sqlString()); |
38 | pingvin | 63 | |
60 | pingvin | 64 | */ |
45 | pingvin | 65 | /********************************************** |
66 | |||
40 | pingvin | 67 | QTextDocument *document; |
68 | // = ui->textEdit->document(); |
||
69 | QTextCursor *cursor; |
||
45 | pingvin | 70 | |
40 | pingvin | 71 | document = ui->textEdit->document(); |
72 | cursor = new QTextCursor(document); |
||
73 | cursor->movePosition(QTextCursor::Start); |
||
74 | QTextCharFormat format(cursor->charFormat()); |
||
75 | //format.setFontFamily("Courier"); |
||
76 | format.setFontFamily("Arial"); |
||
77 | //format.setFontItalic(false); |
||
78 | |||
79 | format.setFontWeight(QFont::Normal); |
||
80 | QTextCharFormat boldFormat = format; |
||
81 | boldFormat.setFontWeight(QFont::Bold); |
||
82 | |||
83 | QTextCharFormat italicFormat = format; |
||
84 | //format.setFontFamily("Courier"); |
||
85 | // format.setFontFamily("Arial"); |
||
86 | italicFormat.setFontItalic(true); |
||
87 | |||
88 | cursor->insertText(table->sqlString(), format); |
||
41 | pingvin | 89 | |
45 | pingvin | 90 | ****************************************************/ |
91 | |||
41 | pingvin | 92 | QString errorString; |
93 | |||
135 | pingvin | 94 | |
41 | pingvin | 95 | |
135 | pingvin | 96 | |
60 | pingvin | 97 | /* |
44 | pingvin | 98 | ok = sql.createTable(table); |
42 | pingvin | 99 | if (!ok) { |
100 | QMessageBox::critical( // . |
||
101 | this, // . |
||
102 | QObject::tr("Database Error"), // . |
||
45 | pingvin | 103 | sql.lasError()); // . |
104 | } |
||
42 | pingvin | 105 | else { |
106 | |||
107 | QMessageBox::information( // . |
||
108 | this, // . |
||
109 | QObject::tr("Database Connect"), // . |
||
110 | QObject::tr(" .")); // . |
||
45 | pingvin | 111 | } |
42 | pingvin | 112 | |
113 | |||
114 | |||
60 | pingvin | 115 | */ |
42 | pingvin | 116 | |
41 | pingvin | 117 | |
45 | pingvin | 118 | |
119 | |||
72 | pingvin | 120 | model = new QSqlTableModel(); // |
121 | tableForInstance = new QTableView(); |
||
50 | pingvin | 122 | mymodel = new MyModel(this); |
82 | pingvin | 123 | modelForPointers = new ModelForPointers(this); // // |
124 | |||
61 | pingvin | 125 | //modelForDescription = new QSqlTableModel(this); |
126 | modelForDescription = new ModelForDescriptionTable(this); |
||
50 | pingvin | 127 | |
61 | pingvin | 128 | |
137 | pingvin | 129 | |
130 | initClassListTable(); |
||
131 | |||
132 | initFieldsTable(); |
||
133 | |||
134 | initPointersTable(); |
||
135 | |||
56 | pingvin | 136 | /////////////////model->setTable(tr("ListOfClasses")); |
50 | pingvin | 137 | |
137 | pingvin | 138 | |
139 | |||
45 | pingvin | 140 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
50 | pingvin | 141 | |
87 | pingvin | 142 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit); |
143 | |||
144 | |||
50 | pingvin | 145 | |
146 | |||
82 | pingvin | 147 | |
148 | |||
71 | pingvin | 149 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange); |
150 | |||
151 | |||
152 | |||
56 | pingvin | 153 | //////////////////model->setSort(0, Qt::AscendingOrder); |
50 | pingvin | 154 | |
155 | |||
56 | pingvin | 156 | |
68 | pingvin | 157 | |
137 | pingvin | 158 | // model->setFilter(tr("__ = '7' and _ = 'i09090909'")); |
159 | ////////////////////model->select(); |
||
68 | pingvin | 160 | |
137 | pingvin | 161 | //tableForDescription = new QTableView(); |
50 | pingvin | 162 | |
56 | pingvin | 163 | //tableForDescription->show(); |
50 | pingvin | 164 | |
165 | |||
65 | pingvin | 166 | |
45 | pingvin | 167 | |
65 | pingvin | 168 | /* |
62 | pingvin | 169 | ui->tableView_2->hideColumn(0); |
170 | ui->tableView_2->hideColumn(5); |
||
171 | ui->tableView_2->hideColumn(2); |
||
65 | pingvin | 172 | */ |
45 | pingvin | 173 | |
134 | pingvin | 174 | |
175 | |||
176 | |||
135 | pingvin | 177 | |
178 | |||
137 | pingvin | 179 | //if (mymodel->rowCount() > 0) { |
135 | pingvin | 180 | |
137 | pingvin | 181 | |
182 | |||
183 | /* |
||
184 | |||
185 | currIndexOfClassesTable = mymodel->index(0, 1); |
||
186 | |||
187 | |||
62 | pingvin | 188 | QModelIndex index_temp; |
189 | |||
75 | pingvin | 190 | |
191 | |||
62 | pingvin | 192 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
193 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
194 | |||
195 | QModelIndex topLeft; |
||
196 | QModelIndex bottomRight; |
||
197 | |||
198 | topLeft = mymodel->index(0, 0, QModelIndex()); |
||
199 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
||
200 | |||
201 | QItemSelection selection(topLeft, bottomRight); |
||
202 | selectionModel->select(selection, QItemSelectionModel::Select); |
||
203 | |||
204 | |||
71 | pingvin | 205 | QString class_indx, class_instance; |
68 | pingvin | 206 | QString str_fltr = tr("ClassIdentifer = "); |
207 | class_indx = mymodel->data(mymodel->index(0,0)).toString(); |
||
71 | pingvin | 208 | class_instance = mymodel->data(mymodel->index(0,3)).toString(); |
75 | pingvin | 209 | |
210 | currInctanceTable = class_instance; // |
||
137 | pingvin | 211 | |
212 | |||
213 | |||
75 | pingvin | 214 | modelForDescription->setInctance(class_instance); // - |
71 | pingvin | 215 | //class_instance.append(tr("_inctance")); |
68 | pingvin | 216 | str_fltr.append(class_indx); |
83 | pingvin | 217 | str_fltr.append(tr(" AND FieldType <> \"pointer\"")); |
62 | pingvin | 218 | |
71 | pingvin | 219 | model->setTable(class_instance); |
220 | //model->setTable(tr("memory")); |
||
72 | pingvin | 221 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
71 | pingvin | 222 | model->select(); |
72 | pingvin | 223 | tableForInstance->setModel(model); |
224 | tableForInstance->resizeColumnsToContents(); |
||
225 | tableForInstance->setWindowTitle(class_instance); |
||
226 | tableForInstance->show(); |
||
71 | pingvin | 227 | |
68 | pingvin | 228 | modelForDescription->setFilter(str_fltr); |
229 | modelForDescription->select(); |
||
69 | pingvin | 230 | ui->tableView_2->resizeColumnsToContents(); |
68 | pingvin | 231 | |
83 | pingvin | 232 | |
233 | str_fltr = tr("ClassIdentifer = "); |
||
234 | modelForPointers->setInctance(class_instance); // - |
||
235 | str_fltr.append(class_indx); |
||
236 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
||
82 | pingvin | 237 | // str_fltr.append( tr(" FieldType = pointer ")); |
83 | pingvin | 238 | |
239 | |||
240 | |||
241 | modelForPointers->setFilter(str_fltr); |
||
82 | pingvin | 242 | modelForPointers->select(); |
68 | pingvin | 243 | |
135 | pingvin | 244 | |
137 | pingvin | 245 | */ |
246 | |||
55 | pingvin | 247 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex))); |
62 | pingvin | 248 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
249 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
||
72 | pingvin | 250 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool))); |
65 | pingvin | 251 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
68 | pingvin | 252 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // |
253 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // |
||
254 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // |
||
255 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // |
||
256 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // |
||
73 | pingvin | 257 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // |
258 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // |
||
259 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // |
||
86 | pingvin | 260 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // - |
261 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // - |
||
87 | pingvin | 262 | |
263 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // |
||
86 | pingvin | 264 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // |
265 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // |
||
266 | |||
267 | |||
135 | pingvin | 268 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // " " " " |
269 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
87 | pingvin | 270 | |
135 | pingvin | 271 | |
272 | |||
273 | |||
42 | pingvin | 274 | } |
275 | |||
45 | pingvin | 276 | |
277 | |||
278 | |||
279 | |||
280 | |||
281 | |||
282 | |||
283 | |||
284 | |||
285 | |||
24 | pingvin | 286 | ClassEditor::~ClassEditor() |
287 | { |
||
288 | delete ui; |
||
72 | pingvin | 289 | delete model; |
290 | delete tableForInstance; |
||
38 | pingvin | 291 | // delete field; |
24 | pingvin | 292 | // delete settdialog; |
293 | } |
||
294 | |||
295 | void ClassEditor::changeEvent(QEvent *e) |
||
296 | { |
||
297 | QMainWindow::changeEvent(e); |
||
298 | switch (e->type()) { |
||
299 | case QEvent::LanguageChange: |
||
300 | ui->retranslateUi(this); |
||
301 | break; |
||
302 | default: |
||
303 | break; |
||
304 | } |
||
305 | } |
||
51 | pingvin | 306 | |
307 | |||
71 | pingvin | 308 | /* |
51 | pingvin | 309 | void ClassEditor::addNewClass(){ |
310 | |||
311 | int row = model->rowCount(); |
||
312 | |||
313 | model->insertRows(row, 1); |
||
54 | pingvin | 314 | model->setData(model->index(row, 1), tr("New class")); // " " |
51 | pingvin | 315 | |
316 | |||
317 | // model->setData(model->index(row, 1), tr(" ")); |
||
318 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
319 | |||
320 | |||
321 | model->submitAll(); |
||
322 | |||
323 | row = model->rowCount(); |
||
324 | QString tmp_str; |
||
325 | int i_tmp; |
||
326 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
||
327 | tmp_str = model->data(model->index(row-1, 0)).toString(); // - |
||
328 | |||
329 | tmp_str.append(tr("_Inctance")); |
||
330 | model->setData(model->index(row-1, 3), tmp_str ); // |
||
331 | |||
332 | model->submitAll(); |
||
333 | mymodel->select(); |
||
334 | |||
335 | |||
336 | } |
||
71 | pingvin | 337 | */ |
51 | pingvin | 338 | |
54 | pingvin | 339 | void ClassEditor::addNewClass_new(){ |
340 | |||
341 | int row = mymodel->rowCount(); |
||
342 | |||
343 | mymodel->insertRows(row, 1); |
||
70 | pingvin | 344 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // " " |
54 | pingvin | 345 | |
70 | pingvin | 346 | |
54 | pingvin | 347 | mymodel->submitAll(); |
348 | row = mymodel->rowCount(); |
||
70 | pingvin | 349 | QString tmp_str1, sql_str; |
54 | pingvin | 350 | int i_tmp1; |
351 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
||
352 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // - |
||
353 | |||
354 | tmp_str1.append(tr("_Inctance")); |
||
70 | pingvin | 355 | SqlTable* tbl; |
356 | tbl = new SqlTable(tmp_str1); // |
||
357 | sql_str = tbl->sqlString(); |
||
358 | bool ok; |
||
359 | |||
360 | ok = sql.createTable(tbl); |
||
361 | |||
362 | if (!ok) { |
||
363 | QMessageBox::critical( // . |
||
364 | this, // . |
||
365 | QObject::tr("Database Error"), // . |
||
366 | sql.lasError()); // . |
||
367 | delete tbl; |
||
368 | mymodel->removeRow(row-1); |
||
369 | mymodel->submitAll(); |
||
370 | mymodel->select(); |
||
371 | ui->tableView_2->resizeRowsToContents(); |
||
372 | return; // |
||
373 | |||
374 | } |
||
375 | |||
376 | delete tbl; |
||
54 | pingvin | 377 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // |
378 | |||
70 | pingvin | 379 | |
380 | |||
54 | pingvin | 381 | // model->setData(model->index(row, 1), tr(" ")); |
382 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
383 | |||
384 | |||
56 | pingvin | 385 | //mymodel->submitAll(); |
54 | pingvin | 386 | |
387 | //row = mymodel->rowCount(); |
||
388 | |||
389 | |||
56 | pingvin | 390 | //mymodel->select(); |
54 | pingvin | 391 | |
392 | |||
393 | } |
||
394 | |||
395 | |||
62 | pingvin | 396 | void ClassEditor::addNewField(){ |
397 | // QSqlRecord rec = mymodel->record(1); |
||
398 | //bool ok; |
||
399 | //ok = rec.isEmpty(); |
||
400 | //QString currientClassID; |
||
401 | //currientClassID = rec.value(1).toString(); |
||
73 | pingvin | 402 | QString Inctance_str; // - |
403 | QString query_str = tr("ALTER TABLE "); |
||
404 | QString db_error; |
||
405 | QSqlQuery q; |
||
72 | pingvin | 406 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
407 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
73 | pingvin | 408 | query_str.append( Inctance_str); |
82 | pingvin | 409 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
73 | pingvin | 410 | bool ok = q.prepare(query_str); |
72 | pingvin | 411 | |
73 | pingvin | 412 | ok = q.exec(); |
413 | if (!ok) { |
||
414 | QMessageBox::critical( // . |
||
415 | this, // . |
||
416 | QObject::tr("Database Error"), // . |
||
417 | q.lastError().text()); // . |
||
418 | |||
419 | return; // |
||
420 | |||
421 | } |
||
422 | |||
62 | pingvin | 423 | int row = modelForDescription->rowCount(); |
424 | modelForDescription->insertRows(row, 1); |
||
81 | pingvin | 425 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
426 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 427 | |
428 | modelForDescription->submitAll(); |
||
73 | pingvin | 429 | |
430 | delete model; |
||
431 | delete tableForInstance; |
||
432 | model = new QSqlTableModel(); |
||
433 | tableForInstance = new QTableView(); |
||
434 | model->setTable(Inctance_str); |
||
435 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
436 | tableForInstance->setModel(model); |
||
437 | tableForInstance->setWindowTitle(Inctance_str); |
||
438 | tableForInstance->show(); |
||
62 | pingvin | 439 | } |
440 | |||
441 | |||
442 | |||
86 | pingvin | 443 | void ClassEditor::addNewPointer(){ // , - |
444 | QString Inctance_str; // - |
||
445 | QString query_str = tr("ALTER TABLE "); |
||
446 | QString db_error; |
||
447 | QSqlQuery q; |
||
448 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
||
449 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
450 | query_str.append( Inctance_str); |
||
451 | query_str.append(tr(" ADD COLUMN `lass-container ID` CHAR(30)")); |
||
452 | bool ok = q.prepare(query_str); |
||
62 | pingvin | 453 | |
86 | pingvin | 454 | ok = q.exec(); |
455 | if (!ok) { |
||
456 | QMessageBox::critical( // . |
||
457 | this, // . |
||
458 | QObject::tr("Database Error"), // . |
||
459 | q.lastError().text()); // . |
||
62 | pingvin | 460 | |
86 | pingvin | 461 | return; // |
62 | pingvin | 462 | |
86 | pingvin | 463 | } |
62 | pingvin | 464 | |
465 | |||
86 | pingvin | 466 | int row = ClassEditor::modelForPointers->rowCount(); |
467 | modelForPointers->insertRows(row, 1); |
||
62 | pingvin | 468 | |
86 | pingvin | 469 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("lass-container ID")), Qt::EditRole); |
470 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
||
471 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
||
472 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 473 | |
86 | pingvin | 474 | |
475 | modelForPointers->submitAll(); |
||
476 | |||
135 | pingvin | 477 | |
478 | |||
479 | |||
480 | |||
481 | |||
482 | |||
483 | |||
484 | /* |
||
485 | |||
486 | str_fltr = tr("ClassIdentifer = "); |
||
487 | modelForPointers->setInctance(Inctance_str); // - |
||
488 | str_fltr.append(class_indx); |
||
489 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
||
490 | // str_fltr.append( tr(" FieldType = pointer ")); |
||
491 | |||
492 | |||
493 | |||
494 | modelForPointers->setFilter(str_fltr); |
||
495 | modelForPointers->select(); |
||
496 | ui->tableView_3->setModel(modelForPointers); |
||
497 | ui->tableView_3->resizeColumnsToContents(); |
||
498 | */ |
||
499 | |||
500 | |||
501 | |||
502 | |||
503 | // modelForPointers->select(); |
||
504 | |||
505 | |||
506 | |||
507 | |||
508 | |||
86 | pingvin | 509 | ClassEditor::refreshInctance(); |
510 | |||
511 | |||
512 | |||
513 | |||
514 | |||
515 | |||
516 | |||
517 | |||
518 | |||
519 | } |
||
520 | |||
521 | |||
522 | |||
523 | |||
524 | |||
68 | pingvin | 525 | // |
51 | pingvin | 526 | void ClassEditor::on_pushButton_clicked(){ |
54 | pingvin | 527 | //int i; |
528 | //i++; |
||
529 | /////ClassEditor::addNewClass(); |
||
530 | ClassEditor::addNewClass_new(); |
||
531 | mymodel->select(); |
||
166 | pingvin | 532 | ui->tableView->resizeColumnsToContents(); |
533 | ui->tableView->resizeRowsToContents(); |
||
534 | |||
54 | pingvin | 535 | //ui->tableView->setModel(mymodel); |
536 | |||
51 | pingvin | 537 | } |
54 | pingvin | 538 | |
55 | pingvin | 539 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
137 | pingvin | 540 | bool indexIsValid; |
55 | pingvin | 541 | int i, row, column; |
542 | i++; |
||
137 | pingvin | 543 | indexIsValid = index.isValid(); |
55 | pingvin | 544 | row = index.row(); |
545 | column = index.column(); |
||
62 | pingvin | 546 | currIndexOfClassesTable = index; |
71 | pingvin | 547 | QModelIndex index_tmp, index_instance; |
548 | QString tmp_str, filter_str, instance_str; |
||
56 | pingvin | 549 | index_tmp = ui->tableView->model()->index(row, 0); |
71 | pingvin | 550 | index_instance = ui->tableView->model()->index(row, 3); |
56 | pingvin | 551 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
71 | pingvin | 552 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
75 | pingvin | 553 | modelForDescription->setInctance(instance_str); // - |
83 | pingvin | 554 | modelForPointers->setInctance(instance_str); |
75 | pingvin | 555 | |
134 | pingvin | 556 | delegateForDefaultValueColomn.getItems(); // |
75 | pingvin | 557 | |
71 | pingvin | 558 | // instance_str.append(tr("_inctance")); |
72 | pingvin | 559 | /* |
560 | Inctance_model.clear(); |
||
561 | Inctance_model.setTable(instance_str); |
||
562 | Inctance_model.select(); |
||
563 | tableForInstance_new.setModel(&Inctance_model); |
||
564 | tableForInstance_new.show(); |
||
565 | */ |
||
566 | // model->clear(); |
||
567 | tableForInstance->close(); |
||
568 | delete model; |
||
569 | delete tableForInstance; |
||
570 | model = new QSqlTableModel(); |
||
571 | tableForInstance = new QTableView(); |
||
572 | model->setTable(instance_str); |
||
573 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
574 | tableForInstance->setModel(model); |
||
71 | pingvin | 575 | |
576 | model->select(); |
||
72 | pingvin | 577 | tableForInstance->setWindowTitle(instance_str); |
578 | tableForInstance->show(); |
||
579 | |||
71 | pingvin | 580 | // tableForInstance.setModel(model); |
72 | pingvin | 581 | tableForInstance->resizeColumnsToContents(); |
71 | pingvin | 582 | |
62 | pingvin | 583 | currClassID = tmp_str; |
584 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
56 | pingvin | 585 | filter_str = tr("ClassIdentifer = "); |
586 | filter_str.append(tmp_str); |
||
83 | pingvin | 587 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
56 | pingvin | 588 | modelForDescription->setFilter(filter_str); |
68 | pingvin | 589 | modelForDescription->select(); |
62 | pingvin | 590 | ui->tableView_2->resizeColumnsToContents(); |
83 | pingvin | 591 | |
592 | filter_str = tr("ClassIdentifer = "); |
||
593 | filter_str.append(tmp_str); |
||
594 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
||
595 | modelForPointers->setFilter(filter_str); |
||
596 | modelForPointers->select(); |
||
597 | ui->tableView_3->resizeColumnsToContents(); |
||
598 | |||
599 | |||
600 | |||
601 | |||
56 | pingvin | 602 | i++; |
55 | pingvin | 603 | } |
54 | pingvin | 604 | |
59 | pingvin | 605 | |
606 | |||
68 | pingvin | 607 | void ClassEditor::on_pushButton_2_clicked(){ // " " |
608 | QModelIndex model_index; |
||
609 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
610 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
611 | QList<int> selectedRows; |
||
612 | selectedRows.clear(); |
||
613 | foreach (model_index, indexes){ // |
||
614 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
59 | pingvin | 615 | |
68 | pingvin | 616 | } |
617 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
618 | |||
619 | |||
620 | for (int m =0; m < selectedRows.size(); ++m){ |
||
621 | |||
622 | ClassEditor::removeClass(selectedRows.at(m)); |
||
623 | |||
624 | |||
625 | |||
626 | } |
||
627 | mymodel->submitAll(); |
||
628 | ClassEditor::modelForDescription->select(); |
||
166 | pingvin | 629 | ui->tableView->resizeColumnsToContents(); |
630 | ui->tableView->resizeRowsToContents(); |
||
59 | pingvin | 631 | } |
632 | |||
633 | void ClassEditor::on_pushButton_3_clicked(){ // " " |
||
634 | int i; |
||
635 | i++; |
||
62 | pingvin | 636 | ClassEditor::addNewField(); |
637 | ClassEditor::modelForDescription->select(); |
||
64 | pingvin | 638 | ui->tableView_2->resizeColumnsToContents(); |
59 | pingvin | 639 | } |
68 | pingvin | 640 | |
641 | |||
59 | pingvin | 642 | void ClassEditor::on_pushButton_4_clicked(){ // " " |
69 | pingvin | 643 | // int i; |
62 | pingvin | 644 | QModelIndex model_index; |
63 | pingvin | 645 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
62 | pingvin | 646 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
69 | pingvin | 647 | //QModelIndexList indexes_fo_first_col; // ( ) |
62 | pingvin | 648 | //model_index = mymodel->selec; |
649 | //modelList = ui->tableView->SelectItems; |
||
69 | pingvin | 650 | //i = indexes.size(); |
63 | pingvin | 651 | QList<int> selectedRows; |
69 | pingvin | 652 | //indexes_fo_first_col.clear(); |
653 | /* |
||
67 | pingvin | 654 | foreach (model_index, indexes){ // |
655 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // |
||
656 | |||
657 | } |
||
69 | pingvin | 658 | */ |
63 | pingvin | 659 | selectedRows.clear(); |
660 | foreach (model_index, indexes){ // |
||
73 | pingvin | 661 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
662 | selectedRows.append(model_index.row()); // |
||
663 | } |
||
63 | pingvin | 664 | } |
67 | pingvin | 665 | |
666 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
667 | |||
74 | pingvin | 668 | QString Inctance_str; // - |
669 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
67 | pingvin | 670 | for (int m =0; m < selectedRows.size(); ++m){ |
671 | |||
74 | pingvin | 672 | |
673 | QString query_str; |
||
674 | QString field_name_str; // |
||
675 | QSqlQuery q; |
||
676 | |||
677 | query_str.clear(); |
||
678 | |||
679 | |||
680 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
||
681 | |||
682 | query_str.append(tr("ALTER TABLE ")); |
||
683 | query_str.append(Inctance_str); |
||
684 | query_str.append(tr(" DROP COLUMN `")); |
||
685 | query_str.append(field_name_str); |
||
686 | query_str.append(tr("`")); |
||
687 | q.prepare(query_str); |
||
688 | bool ok = q.exec(); |
||
689 | if (!ok) { |
||
690 | QMessageBox::critical( // . |
||
691 | this, // . |
||
692 | QObject::tr("Database Error"), // . |
||
693 | q.lastError().text()); // . |
||
694 | |||
695 | return; // |
||
696 | |||
697 | } |
||
698 | |||
699 | |||
700 | |||
701 | modelForDescription->removeRow(selectedRows.at(m)); |
||
702 | |||
67 | pingvin | 703 | } |
74 | pingvin | 704 | delete model; |
705 | delete tableForInstance; |
||
706 | model = new QSqlTableModel(); |
||
707 | tableForInstance = new QTableView(); |
||
708 | model->setTable(Inctance_str); |
||
709 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
710 | tableForInstance->setModel(model); |
||
711 | tableForInstance->setWindowTitle(Inctance_str); |
||
712 | tableForInstance->show(); |
||
69 | pingvin | 713 | //i = selectedRows.size(); |
63 | pingvin | 714 | |
69 | pingvin | 715 | //if (i > 0) model_index = indexes.at(0); |
59 | pingvin | 716 | } |
62 | pingvin | 717 | |
718 | |||
87 | pingvin | 719 | void ClassEditor::on_action_removeSelectedPointers(){ // |
720 | QModelIndex model_index; |
||
721 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
||
722 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
723 | QList<int> selectedRows; |
||
724 | |||
725 | selectedRows.clear(); |
||
726 | |||
727 | foreach (model_index, indexes){ // |
||
728 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
||
729 | selectedRows.append(model_index.row()); // |
||
730 | } |
||
731 | } |
||
732 | |||
733 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
734 | |||
735 | QString Inctance_str; // - |
||
736 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
737 | for (int m =0; m < selectedRows.size(); ++m){ |
||
738 | |||
739 | |||
740 | QString query_str; |
||
741 | QString field_name_str; // |
||
742 | QSqlQuery q; |
||
743 | |||
744 | query_str.clear(); |
||
745 | |||
746 | |||
747 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
||
748 | |||
749 | query_str.append(tr("ALTER TABLE ")); |
||
750 | query_str.append(Inctance_str); |
||
751 | query_str.append(tr(" DROP COLUMN `")); |
||
752 | query_str.append(field_name_str); |
||
753 | query_str.append(tr("`")); |
||
754 | q.prepare(query_str); |
||
755 | bool ok = q.exec(); |
||
756 | if (!ok) { |
||
757 | QMessageBox::critical( // . |
||
758 | this, // . |
||
759 | QObject::tr("Database Error"), // . |
||
760 | q.lastError().text()); // . |
||
761 | |||
762 | return; // |
||
763 | |||
764 | } |
||
765 | |||
766 | |||
767 | |||
768 | modelForPointers->removeRow(selectedRows.at(m)); |
||
769 | |||
770 | } |
||
771 | |||
772 | |||
773 | refreshInctance(); |
||
774 | |||
775 | |||
776 | |||
777 | } |
||
778 | |||
779 | |||
780 | |||
781 | |||
782 | |||
63 | pingvin | 783 | void ClassEditor::on_pushButton_5_clicked(){ // " " |
784 | int row; |
||
785 | row = ClassEditor::modelForDescription->rowCount(); |
||
786 | ClassEditor::modelForDescription->removeRows(0, row); |
||
787 | ClassEditor::modelForDescription->submitAll(); |
||
788 | } |
||
789 | |||
161 | pingvin | 790 | void ClassEditor::on_pushButton_6_clicked(){ // " " |
791 | QString fileName; |
||
792 | QPixmap pixmap; |
||
793 | fileName = QFileDialog::getOpenFileName(this, |
||
794 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
||
795 | pixmap.load(fileName); |
||
796 | ui->label_4->setPixmap(pixmap); |
||
797 | QImage currentImage = pixmap.toImage(); |
||
798 | QByteArray bytes; |
||
799 | QBuffer buffer(&bytes); |
||
800 | buffer.open(QIODevice::WriteOnly); |
||
801 | currentImage.save(&buffer, "PNG"); |
||
802 | |||
803 | if (currIndexOfClassesTable.isValid()) { |
||
804 | bool ok; |
||
805 | |||
806 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
||
807 | mymodel->submitAll(); |
||
166 | pingvin | 808 | |
161 | pingvin | 809 | } |
810 | |||
811 | |||
812 | } |
||
813 | |||
62 | pingvin | 814 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
75 | pingvin | 815 | |
62 | pingvin | 816 | int i; |
817 | i++; |
||
818 | ui->tableView->resizeColumnsToContents(); |
||
75 | pingvin | 819 | |
820 | |||
821 | |||
822 | |||
823 | |||
62 | pingvin | 824 | } |
825 | |||
826 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
||
827 | ui->tableView_2->resizeColumnsToContents(); |
||
75 | pingvin | 828 | |
829 | /* |
||
830 | QString instance_str; |
||
831 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
832 | tableForInstance->close(); |
||
833 | delete model; |
||
834 | delete tableForInstance; |
||
835 | model = new QSqlTableModel(); |
||
836 | tableForInstance = new QTableView(); |
||
837 | model->setTable(instance_str); |
||
838 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
839 | tableForInstance->setModel(model); |
||
840 | |||
841 | model->select(); |
||
842 | tableForInstance->setWindowTitle(instance_str); |
||
843 | tableForInstance->show(); |
||
844 | */ |
||
62 | pingvin | 845 | } |
65 | pingvin | 846 | |
847 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // " ID" |
||
848 | if (is_checked) ui->tableView->showColumn(0); |
||
849 | else ui->tableView->hideColumn(0); |
||
850 | ui->tableView->resizeColumnsToContents(); |
||
851 | } |
||
852 | |||
853 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // " " |
||
854 | if (is_checked) ui->tableView->showColumn(2); |
||
855 | else ui->tableView->hideColumn(2); |
||
856 | ui->tableView->resizeColumnsToContents(); |
||
857 | } |
||
858 | |||
68 | pingvin | 859 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // " " |
65 | pingvin | 860 | if (is_checked) ui->tableView->showColumn(3); |
861 | else ui->tableView->hideColumn(3); |
||
862 | ui->tableView->resizeColumnsToContents(); |
||
863 | } |
||
68 | pingvin | 864 | |
865 | |||
866 | |||
867 | void ClassEditor::on_action_removeAllClasses(){ // " " |
||
868 | int row; |
||
869 | row = ClassEditor::mymodel->rowCount(); |
||
870 | for (int m=0; m < row; ++m){ |
||
871 | ClassEditor::removeClass(0); |
||
872 | //ClassEditor::mymodel->removeRows(0, row); |
||
873 | } |
||
874 | ClassEditor::mymodel->submitAll(); |
||
875 | ClassEditor::modelForDescription->select(); |
||
876 | } |
||
877 | |||
878 | void ClassEditor::removeClass(int class_row){ // , class_row |
||
879 | QModelIndex index_tmp; |
||
880 | QString tmp_str, filter_str; |
||
881 | index_tmp = ui->tableView->model()->index(class_row, 0); |
||
882 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
||
883 | currClassID = tmp_str; |
||
884 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
885 | filter_str = tr("ClassIdentifer = "); |
||
886 | filter_str.append(tmp_str); |
||
887 | modelForDescription->setFilter(filter_str); // |
||
888 | ClassEditor::on_pushButton_5_clicked(); // |
||
889 | mymodel->removeRow(class_row); // |
||
890 | mymodel->submitAll(); // |
||
891 | ui->tableView->resizeColumnsToContents(); |
||
892 | ui->tableView_2->resizeColumnsToContents(); |
||
893 | |||
894 | } |
||
76 | pingvin | 895 | |
896 | |||
77 | pingvin | 897 | void ClassEditor::on_field_changed(){ // |
76 | pingvin | 898 | ClassEditor::refreshInctance(); |
899 | } |
||
900 | |||
901 | |||
902 | |||
903 | |||
904 | void ClassEditor::refreshInctance(){ // - |
||
905 | |||
906 | QString Inctance_str; // - |
||
907 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
908 | delete model; |
||
909 | delete tableForInstance; |
||
910 | model = new QSqlTableModel(); |
||
911 | tableForInstance = new QTableView(); |
||
912 | model->setTable(Inctance_str); |
||
913 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
78 | pingvin | 914 | model->select(); |
76 | pingvin | 915 | tableForInstance->setModel(model); |
916 | tableForInstance->setWindowTitle(Inctance_str); |
||
917 | tableForInstance->resizeRowsToContents(); |
||
918 | tableForInstance->show(); |
||
919 | |||
920 | } |
||
86 | pingvin | 921 | |
922 | |||
923 | |||
924 | |||
87 | pingvin | 925 | void ClassEditor::on_action_newPointer(){ // - |
86 | pingvin | 926 | ClassEditor::addNewPointer(); |
927 | ClassEditor::modelForPointers->select(); |
||
928 | ui->tableView_3->resizeColumnsToContents(); |
||
929 | |||
930 | } |
||
931 | |||
135 | pingvin | 932 | |
933 | // |
||
934 | |||
935 | void ClassEditor::readSettings() |
||
936 | { |
||
937 | QSettings settings("Trolltech", "Application Example"); |
||
938 | baseName = settings.value("baseName", "an_db").toString(); |
||
939 | userName = settings.value("userName", "an").toString(); |
||
940 | password = settings.value("password", "393939").toString(); |
||
941 | tableName = settings.value("tableName", "inventar").toString(); |
||
942 | hostName = settings.value("hostName", "server").toString(); |
||
943 | // resize(size); |
||
944 | // move(pos);tableName |
||
945 | } |
||
946 | |||
947 | |||
948 | void ClassEditor::writeSettings() |
||
949 | { |
||
950 | QSettings settings("Trolltech", "Application Example"); |
||
951 | settings.setValue("baseName", baseName); |
||
952 | settings.setValue("userName", userName); |
||
953 | settings.setValue("password", password); |
||
954 | settings.setValue("tableName", tableName); |
||
955 | settings.setValue("hostName", hostName); |
||
956 | } |
||
957 | |||
958 | |||
959 | void ClassEditor::applySetting() |
||
960 | { |
||
961 | bool ok; |
||
962 | baseName = setFrm.lineEdit->text(); |
||
963 | userName = setFrm.lineEdit_2->text(); |
||
964 | password = setFrm.lineEdit_3->text(); |
||
965 | // tableName = setFrm->lineEdit_4->text(); |
||
966 | hostName = setFrm.lineEdit_5->text(); |
||
967 | writeSettings(); |
||
968 | |||
969 | sql.close(); // |
||
970 | |||
971 | sql.setDatabaseName(baseName); |
||
972 | // sql.setDatabaseName(tr("inventory")); |
||
973 | |||
974 | // sql.setHostName(tr("localhost")); |
||
975 | sql.setHostName(hostName); |
||
976 | |||
977 | // sql.setUserName(tr("an")); |
||
978 | |||
979 | sql.setUserName(userName); |
||
980 | |||
981 | // sql.setPassword(tr("393939")); |
||
982 | |||
983 | sql.setPassword(password); |
||
984 | |||
985 | ok = sql.connect(); |
||
986 | if (!ok) { |
||
987 | QMessageBox::critical( // . |
||
988 | this, // . |
||
989 | QObject::tr("Database Error"), // . |
||
990 | sql.lasError()); // . |
||
991 | |||
992 | } |
||
993 | else { |
||
994 | |||
995 | QMessageBox::information( // . |
||
996 | this, // . |
||
997 | QObject::tr("Database Connect"), // . |
||
998 | QObject::tr(" .")); // . |
||
999 | |||
1000 | |||
1001 | |||
1002 | |||
1003 | |||
1004 | } |
||
1005 | |||
1006 | |||
1007 | mymodel->select(); |
||
1008 | model->select(); |
||
1009 | modelForDescription->select(); |
||
1010 | |||
1011 | //////////// ok=openDataBase(); |
||
1012 | //////////// if (!ok) return; |
||
1013 | // // // ui->treeWidget->clear(); // |
||
1014 | |||
1015 | // // // buildPreviewModel(tr(" "), tr("1")); |
||
1016 | //////////// class_list_map.clear(); // |
||
1017 | //////////// initComboBox(); |
||
1018 | // // // getDatabaseData(); |
||
1019 | // delete setFrm; |
||
1020 | setFrm.close(); |
||
1021 | } |
||
1022 | |||
1023 | void ClassEditor::getSetting() |
||
1024 | { |
||
1025 | // setFrm = new settingForm; |
||
1026 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
1027 | setFrm.lineEdit->setText(baseName); |
||
1028 | setFrm.lineEdit_2->setText(userName); |
||
1029 | setFrm.lineEdit_3->setText(password); |
||
1030 | // setFrm->lineEdit_4->setText(tableName); |
||
1031 | setFrm.lineEdit_5->setText(hostName); |
||
1032 | setFrm.show(); |
||
1033 | |||
1034 | |||
1035 | |||
1036 | } |
||
1037 | |||
1038 | |||
1039 | void ClassEditor::initDataBase(){ // |
||
1040 | |||
137 | pingvin | 1041 | sql.setDatabaseName(baseName); |
1042 | sql.setHostName(hostName); |
||
1043 | sql.setUserName(userName); |
||
1044 | sql.setPassword(password); |
||
135 | pingvin | 1045 | |
137 | pingvin | 1046 | bool ok; |
1047 | ok = sql.connect(); |
||
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 Connect"), // . |
||
1060 | QObject::tr(" .")); // . |
||
1061 | |||
1062 | |||
1063 | |||
1064 | |||
1065 | |||
1066 | } |
||
1067 | |||
135 | pingvin | 1068 | } |
137 | pingvin | 1069 | |
1070 | |||
1071 | void ClassEditor::createMainTables(){// - DescriptionOfClasses ListOfClasses |
||
1072 | |||
1073 | bool ok; |
||
1074 | ok = sql.createListOfClassesTable(); |
||
1075 | |||
1076 | if (!ok) { |
||
1077 | QMessageBox::critical( // . |
||
1078 | this, // . |
||
1079 | QObject::tr("Database Error"), // . |
||
1080 | sql.lasError()); // . |
||
1081 | |||
1082 | } |
||
1083 | else { |
||
1084 | |||
1085 | QMessageBox::information( // . |
||
1086 | this, // . |
||
1087 | QObject::tr("Database Create"), // . |
||
1088 | QObject::tr(" .")); // . |
||
1089 | } |
||
1090 | |||
1091 | |||
1092 | |||
1093 | |||
1094 | ok = sql.createDescriptionOfClassesTable(); |
||
1095 | |||
1096 | if (!ok) { |
||
1097 | QMessageBox::critical( // . |
||
1098 | this, // . |
||
1099 | QObject::tr("Database Error"), // . |
||
1100 | sql.lasError()); // . |
||
1101 | |||
1102 | } |
||
1103 | else { |
||
1104 | |||
1105 | QMessageBox::information( // . |
||
1106 | this, // . |
||
1107 | QObject::tr("Database Create"), // . |
||
1108 | QObject::tr(" .")); // . |
||
1109 | } |
||
1110 | |||
1111 | |||
143 | pingvin | 1112 | ok = sql.createListModelsTable(); |
137 | pingvin | 1113 | |
143 | pingvin | 1114 | if (!ok) { |
1115 | QMessageBox::critical( // . |
||
1116 | this, // . |
||
1117 | QObject::tr("Database Error"), // . |
||
1118 | sql.lasError()); // . |
||
137 | pingvin | 1119 | |
143 | pingvin | 1120 | } |
1121 | else { |
||
137 | pingvin | 1122 | |
143 | pingvin | 1123 | QMessageBox::information( // . |
1124 | this, // . |
||
1125 | QObject::tr("Database Create"), // . |
||
1126 | QObject::tr(" .")); // . |
||
1127 | } |
||
137 | pingvin | 1128 | |
1129 | |||
143 | pingvin | 1130 | |
1131 | |||
137 | pingvin | 1132 | } |
1133 | |||
1134 | void ClassEditor::initClassListTable(){ // |
||
1135 | |||
1136 | mymodel->setTable(tr("ListOfClasses")); |
||
1137 | mymodel->setSort(0, Qt::AscendingOrder); |
||
1138 | mymodel->select(); |
||
1139 | mymodel->setHeaderData(1, Qt::Horizontal, tr(" ")); |
||
1140 | mymodel->setHeaderData(2, Qt::Horizontal, tr(" ")); |
||
1141 | mymodel->setHeaderData(4, Qt::Horizontal, tr("")); |
||
161 | pingvin | 1142 | mymodel->setHeaderData(5, Qt::Horizontal, tr("")); |
137 | pingvin | 1143 | ui->tableView->setModel(mymodel); |
1144 | ui->tableView->setAlternatingRowColors(true); |
||
166 | pingvin | 1145 | ui->tableView->resizeColumnsToContents(); |
1146 | ui->tableView->resizeRowsToContents(); |
||
137 | pingvin | 1147 | ui->tableView->hideColumn(0); |
1148 | ui->tableView->hideColumn(3); |
||
1149 | ui->tableView->hideColumn(2); |
||
161 | pingvin | 1150 | CPictureDelegate *pictureDelegate; |
1151 | pictureDelegate = new CPictureDelegate(this); |
||
165 | pingvin | 1152 | pictureDelegate->setTableView(ui->tableView); |
161 | pingvin | 1153 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1154 | |||
1155 | /* |
||
1156 | for (int i=0; i < mymodel->rowCount(); i++){ |
||
1157 | ui->tableView->setRowHeight(i, 100); |
||
1158 | } |
||
1159 | */ |
||
1160 | |||
137 | pingvin | 1161 | } |
1162 | |||
1163 | |||
1164 | void ClassEditor::initFieldsTable(){ // |
||
1165 | |||
1166 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
||
1167 | modelForDescription->setSort(0, Qt::AscendingOrder); |
||
1168 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
1169 | ui->tableView_2->setModel(modelForDescription); |
||
1170 | ui->tableView_2->setAlternatingRowColors(true); |
||
1171 | ui->tableView_2->resizeColumnsToContents(); |
||
1172 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
||
1173 | } |
||
1174 | |||
1175 | void ClassEditor::initPointersTable(){ // - |
||
1176 | |||
1177 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
||
1178 | modelForPointers->setSort(0, Qt::AscendingOrder); |
||
1179 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
1180 | ui->tableView_3->setModel(modelForPointers); |
||
1181 | delegateForDefaultValueColomn.getItems(); |
||
1182 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
||
1183 | |||
1184 | // ui->tableView_3->resizeColumnsToContents(); |
||
1185 | |||
1186 | } |