Редакция 210 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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 | |
168 | 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 | { |
||
183 | pingvin | 288 | // tableForInstance->close(); |
289 | delete tableForInstance; |
||
290 | delete model; |
||
291 | |||
24 | pingvin | 292 | delete ui; |
38 | pingvin | 293 | // delete field; |
24 | pingvin | 294 | // delete settdialog; |
295 | } |
||
296 | |||
297 | void ClassEditor::changeEvent(QEvent *e) |
||
298 | { |
||
299 | QMainWindow::changeEvent(e); |
||
300 | switch (e->type()) { |
||
301 | case QEvent::LanguageChange: |
||
302 | ui->retranslateUi(this); |
||
303 | break; |
||
304 | default: |
||
305 | break; |
||
306 | } |
||
307 | } |
||
51 | pingvin | 308 | |
309 | |||
71 | pingvin | 310 | /* |
51 | pingvin | 311 | void ClassEditor::addNewClass(){ |
312 | |||
313 | int row = model->rowCount(); |
||
314 | |||
315 | model->insertRows(row, 1); |
||
54 | pingvin | 316 | model->setData(model->index(row, 1), tr("New class")); // " " |
51 | pingvin | 317 | |
318 | |||
319 | // model->setData(model->index(row, 1), tr(" ")); |
||
320 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
321 | |||
322 | |||
323 | model->submitAll(); |
||
324 | |||
325 | row = model->rowCount(); |
||
326 | QString tmp_str; |
||
327 | int i_tmp; |
||
328 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
||
329 | tmp_str = model->data(model->index(row-1, 0)).toString(); // - |
||
330 | |||
331 | tmp_str.append(tr("_Inctance")); |
||
332 | model->setData(model->index(row-1, 3), tmp_str ); // |
||
333 | |||
334 | model->submitAll(); |
||
335 | mymodel->select(); |
||
336 | |||
337 | |||
338 | } |
||
71 | pingvin | 339 | */ |
51 | pingvin | 340 | |
54 | pingvin | 341 | void ClassEditor::addNewClass_new(){ |
342 | |||
343 | int row = mymodel->rowCount(); |
||
344 | |||
345 | mymodel->insertRows(row, 1); |
||
70 | pingvin | 346 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // " " |
54 | pingvin | 347 | |
70 | pingvin | 348 | |
54 | pingvin | 349 | mymodel->submitAll(); |
350 | row = mymodel->rowCount(); |
||
70 | pingvin | 351 | QString tmp_str1, sql_str; |
54 | pingvin | 352 | int i_tmp1; |
353 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
||
354 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // - |
||
355 | |||
356 | tmp_str1.append(tr("_Inctance")); |
||
70 | pingvin | 357 | SqlTable* tbl; |
358 | tbl = new SqlTable(tmp_str1); // |
||
359 | sql_str = tbl->sqlString(); |
||
360 | bool ok; |
||
361 | |||
362 | ok = sql.createTable(tbl); |
||
363 | |||
364 | if (!ok) { |
||
365 | QMessageBox::critical( // . |
||
366 | this, // . |
||
367 | QObject::tr("Database Error"), // . |
||
368 | sql.lasError()); // . |
||
369 | delete tbl; |
||
370 | mymodel->removeRow(row-1); |
||
371 | mymodel->submitAll(); |
||
372 | mymodel->select(); |
||
373 | ui->tableView_2->resizeRowsToContents(); |
||
374 | return; // |
||
375 | |||
376 | } |
||
377 | |||
378 | delete tbl; |
||
54 | pingvin | 379 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // |
380 | |||
70 | pingvin | 381 | |
382 | |||
54 | pingvin | 383 | // model->setData(model->index(row, 1), tr(" ")); |
384 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
385 | |||
386 | |||
56 | pingvin | 387 | //mymodel->submitAll(); |
54 | pingvin | 388 | |
389 | //row = mymodel->rowCount(); |
||
390 | |||
391 | |||
56 | pingvin | 392 | //mymodel->select(); |
54 | pingvin | 393 | |
394 | |||
395 | } |
||
396 | |||
397 | |||
62 | pingvin | 398 | void ClassEditor::addNewField(){ |
399 | // QSqlRecord rec = mymodel->record(1); |
||
400 | //bool ok; |
||
401 | //ok = rec.isEmpty(); |
||
402 | //QString currientClassID; |
||
403 | //currientClassID = rec.value(1).toString(); |
||
73 | pingvin | 404 | QString Inctance_str; // - |
405 | QString query_str = tr("ALTER TABLE "); |
||
406 | QString db_error; |
||
407 | QSqlQuery q; |
||
72 | pingvin | 408 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
409 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
73 | pingvin | 410 | query_str.append( Inctance_str); |
82 | pingvin | 411 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
73 | pingvin | 412 | bool ok = q.prepare(query_str); |
72 | pingvin | 413 | |
73 | pingvin | 414 | ok = q.exec(); |
415 | if (!ok) { |
||
416 | QMessageBox::critical( // . |
||
417 | this, // . |
||
418 | QObject::tr("Database Error"), // . |
||
419 | q.lastError().text()); // . |
||
420 | |||
421 | return; // |
||
422 | |||
423 | } |
||
424 | |||
62 | pingvin | 425 | int row = modelForDescription->rowCount(); |
426 | modelForDescription->insertRows(row, 1); |
||
81 | pingvin | 427 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
428 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 429 | |
430 | modelForDescription->submitAll(); |
||
73 | pingvin | 431 | |
432 | delete model; |
||
433 | delete tableForInstance; |
||
434 | model = new QSqlTableModel(); |
||
435 | tableForInstance = new QTableView(); |
||
436 | model->setTable(Inctance_str); |
||
437 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
438 | tableForInstance->setModel(model); |
||
439 | tableForInstance->setWindowTitle(Inctance_str); |
||
440 | tableForInstance->show(); |
||
62 | pingvin | 441 | } |
442 | |||
443 | |||
444 | |||
86 | pingvin | 445 | void ClassEditor::addNewPointer(){ // , - |
446 | QString Inctance_str; // - |
||
447 | QString query_str = tr("ALTER TABLE "); |
||
448 | QString db_error; |
||
449 | QSqlQuery q; |
||
450 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
||
451 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
452 | query_str.append( Inctance_str); |
||
453 | query_str.append(tr(" ADD COLUMN `lass-container ID` CHAR(30)")); |
||
454 | bool ok = q.prepare(query_str); |
||
62 | pingvin | 455 | |
86 | pingvin | 456 | ok = q.exec(); |
457 | if (!ok) { |
||
458 | QMessageBox::critical( // . |
||
459 | this, // . |
||
460 | QObject::tr("Database Error"), // . |
||
461 | q.lastError().text()); // . |
||
62 | pingvin | 462 | |
86 | pingvin | 463 | return; // |
62 | pingvin | 464 | |
86 | pingvin | 465 | } |
62 | pingvin | 466 | |
467 | |||
86 | pingvin | 468 | int row = ClassEditor::modelForPointers->rowCount(); |
469 | modelForPointers->insertRows(row, 1); |
||
62 | pingvin | 470 | |
86 | pingvin | 471 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("lass-container ID")), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
||
473 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
||
474 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 475 | |
86 | pingvin | 476 | |
477 | modelForPointers->submitAll(); |
||
478 | |||
135 | pingvin | 479 | |
480 | |||
481 | |||
482 | |||
483 | |||
484 | |||
485 | |||
486 | /* |
||
487 | |||
488 | str_fltr = tr("ClassIdentifer = "); |
||
489 | modelForPointers->setInctance(Inctance_str); // - |
||
490 | str_fltr.append(class_indx); |
||
491 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
||
492 | // str_fltr.append( tr(" FieldType = pointer ")); |
||
493 | |||
494 | |||
495 | |||
496 | modelForPointers->setFilter(str_fltr); |
||
497 | modelForPointers->select(); |
||
498 | ui->tableView_3->setModel(modelForPointers); |
||
499 | ui->tableView_3->resizeColumnsToContents(); |
||
500 | */ |
||
501 | |||
502 | |||
503 | |||
504 | |||
505 | // modelForPointers->select(); |
||
506 | |||
507 | |||
508 | |||
509 | |||
510 | |||
86 | pingvin | 511 | ClassEditor::refreshInctance(); |
512 | |||
513 | |||
514 | |||
515 | |||
516 | |||
517 | |||
518 | |||
519 | |||
520 | |||
521 | } |
||
522 | |||
523 | |||
524 | |||
525 | |||
526 | |||
68 | pingvin | 527 | // |
51 | pingvin | 528 | void ClassEditor::on_pushButton_clicked(){ |
54 | pingvin | 529 | //int i; |
530 | //i++; |
||
531 | /////ClassEditor::addNewClass(); |
||
532 | ClassEditor::addNewClass_new(); |
||
533 | mymodel->select(); |
||
166 | pingvin | 534 | ui->tableView->resizeColumnsToContents(); |
535 | ui->tableView->resizeRowsToContents(); |
||
536 | |||
54 | pingvin | 537 | //ui->tableView->setModel(mymodel); |
538 | |||
51 | pingvin | 539 | } |
54 | pingvin | 540 | |
55 | pingvin | 541 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
137 | pingvin | 542 | bool indexIsValid; |
55 | pingvin | 543 | int i, row, column; |
544 | i++; |
||
137 | pingvin | 545 | indexIsValid = index.isValid(); |
55 | pingvin | 546 | row = index.row(); |
547 | column = index.column(); |
||
62 | pingvin | 548 | currIndexOfClassesTable = index; |
71 | pingvin | 549 | QModelIndex index_tmp, index_instance; |
550 | QString tmp_str, filter_str, instance_str; |
||
56 | pingvin | 551 | index_tmp = ui->tableView->model()->index(row, 0); |
71 | pingvin | 552 | index_instance = ui->tableView->model()->index(row, 3); |
56 | pingvin | 553 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
71 | pingvin | 554 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
75 | pingvin | 555 | modelForDescription->setInctance(instance_str); // - |
83 | pingvin | 556 | modelForPointers->setInctance(instance_str); |
75 | pingvin | 557 | |
134 | pingvin | 558 | delegateForDefaultValueColomn.getItems(); // |
75 | pingvin | 559 | |
71 | pingvin | 560 | // instance_str.append(tr("_inctance")); |
72 | pingvin | 561 | /* |
562 | Inctance_model.clear(); |
||
563 | Inctance_model.setTable(instance_str); |
||
564 | Inctance_model.select(); |
||
565 | tableForInstance_new.setModel(&Inctance_model); |
||
566 | tableForInstance_new.show(); |
||
567 | */ |
||
568 | // model->clear(); |
||
569 | tableForInstance->close(); |
||
570 | delete model; |
||
571 | delete tableForInstance; |
||
572 | model = new QSqlTableModel(); |
||
573 | tableForInstance = new QTableView(); |
||
574 | model->setTable(instance_str); |
||
575 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
576 | tableForInstance->setModel(model); |
||
71 | pingvin | 577 | |
578 | model->select(); |
||
72 | pingvin | 579 | tableForInstance->setWindowTitle(instance_str); |
183 | pingvin | 580 | // // // tableForInstance->show(); |
72 | pingvin | 581 | |
71 | pingvin | 582 | // tableForInstance.setModel(model); |
72 | pingvin | 583 | tableForInstance->resizeColumnsToContents(); |
71 | pingvin | 584 | |
62 | pingvin | 585 | currClassID = tmp_str; |
586 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
56 | pingvin | 587 | filter_str = tr("ClassIdentifer = "); |
588 | filter_str.append(tmp_str); |
||
83 | pingvin | 589 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
56 | pingvin | 590 | modelForDescription->setFilter(filter_str); |
68 | pingvin | 591 | modelForDescription->select(); |
62 | pingvin | 592 | ui->tableView_2->resizeColumnsToContents(); |
83 | pingvin | 593 | |
594 | filter_str = tr("ClassIdentifer = "); |
||
595 | filter_str.append(tmp_str); |
||
596 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
||
597 | modelForPointers->setFilter(filter_str); |
||
598 | modelForPointers->select(); |
||
599 | ui->tableView_3->resizeColumnsToContents(); |
||
600 | |||
601 | |||
602 | |||
603 | |||
56 | pingvin | 604 | i++; |
55 | pingvin | 605 | } |
54 | pingvin | 606 | |
59 | pingvin | 607 | |
608 | |||
68 | pingvin | 609 | void ClassEditor::on_pushButton_2_clicked(){ // " " |
610 | QModelIndex model_index; |
||
611 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
612 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
613 | QList<int> selectedRows; |
||
614 | selectedRows.clear(); |
||
615 | foreach (model_index, indexes){ // |
||
616 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
59 | pingvin | 617 | |
68 | pingvin | 618 | } |
619 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
620 | |||
621 | |||
622 | for (int m =0; m < selectedRows.size(); ++m){ |
||
623 | |||
624 | ClassEditor::removeClass(selectedRows.at(m)); |
||
625 | |||
626 | |||
627 | |||
628 | } |
||
629 | mymodel->submitAll(); |
||
630 | ClassEditor::modelForDescription->select(); |
||
166 | pingvin | 631 | ui->tableView->resizeColumnsToContents(); |
632 | ui->tableView->resizeRowsToContents(); |
||
59 | pingvin | 633 | } |
634 | |||
232 | pingvin | 635 | |
636 | |||
637 | |||
638 | |||
639 | |||
640 | |||
59 | pingvin | 641 | void ClassEditor::on_pushButton_3_clicked(){ // " " |
642 | int i; |
||
643 | i++; |
||
62 | pingvin | 644 | ClassEditor::addNewField(); |
645 | ClassEditor::modelForDescription->select(); |
||
64 | pingvin | 646 | ui->tableView_2->resizeColumnsToContents(); |
59 | pingvin | 647 | } |
68 | pingvin | 648 | |
649 | |||
59 | pingvin | 650 | void ClassEditor::on_pushButton_4_clicked(){ // " " |
69 | pingvin | 651 | // int i; |
62 | pingvin | 652 | QModelIndex model_index; |
63 | pingvin | 653 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
62 | pingvin | 654 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
69 | pingvin | 655 | //QModelIndexList indexes_fo_first_col; // ( ) |
62 | pingvin | 656 | //model_index = mymodel->selec; |
657 | //modelList = ui->tableView->SelectItems; |
||
69 | pingvin | 658 | //i = indexes.size(); |
63 | pingvin | 659 | QList<int> selectedRows; |
69 | pingvin | 660 | //indexes_fo_first_col.clear(); |
661 | /* |
||
67 | pingvin | 662 | foreach (model_index, indexes){ // |
663 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // |
||
664 | |||
665 | } |
||
69 | pingvin | 666 | */ |
63 | pingvin | 667 | selectedRows.clear(); |
668 | foreach (model_index, indexes){ // |
||
73 | pingvin | 669 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
670 | selectedRows.append(model_index.row()); // |
||
671 | } |
||
63 | pingvin | 672 | } |
67 | pingvin | 673 | |
674 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
675 | |||
74 | pingvin | 676 | QString Inctance_str; // - |
677 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
67 | pingvin | 678 | for (int m =0; m < selectedRows.size(); ++m){ |
679 | |||
74 | pingvin | 680 | |
681 | QString query_str; |
||
682 | QString field_name_str; // |
||
683 | QSqlQuery q; |
||
684 | |||
685 | query_str.clear(); |
||
686 | |||
687 | |||
688 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
||
689 | |||
690 | query_str.append(tr("ALTER TABLE ")); |
||
691 | query_str.append(Inctance_str); |
||
692 | query_str.append(tr(" DROP COLUMN `")); |
||
693 | query_str.append(field_name_str); |
||
694 | query_str.append(tr("`")); |
||
695 | q.prepare(query_str); |
||
696 | bool ok = q.exec(); |
||
697 | if (!ok) { |
||
698 | QMessageBox::critical( // . |
||
699 | this, // . |
||
700 | QObject::tr("Database Error"), // . |
||
701 | q.lastError().text()); // . |
||
702 | |||
703 | return; // |
||
704 | |||
705 | } |
||
706 | |||
707 | |||
708 | |||
709 | modelForDescription->removeRow(selectedRows.at(m)); |
||
710 | |||
67 | pingvin | 711 | } |
74 | pingvin | 712 | delete model; |
713 | delete tableForInstance; |
||
714 | model = new QSqlTableModel(); |
||
715 | tableForInstance = new QTableView(); |
||
716 | model->setTable(Inctance_str); |
||
717 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
718 | tableForInstance->setModel(model); |
||
719 | tableForInstance->setWindowTitle(Inctance_str); |
||
720 | tableForInstance->show(); |
||
69 | pingvin | 721 | //i = selectedRows.size(); |
63 | pingvin | 722 | |
69 | pingvin | 723 | //if (i > 0) model_index = indexes.at(0); |
59 | pingvin | 724 | } |
62 | pingvin | 725 | |
726 | |||
87 | pingvin | 727 | void ClassEditor::on_action_removeSelectedPointers(){ // |
728 | QModelIndex model_index; |
||
729 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
||
730 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
731 | QList<int> selectedRows; |
||
732 | |||
733 | selectedRows.clear(); |
||
734 | |||
735 | foreach (model_index, indexes){ // |
||
736 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
||
737 | selectedRows.append(model_index.row()); // |
||
738 | } |
||
739 | } |
||
740 | |||
741 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
742 | |||
743 | QString Inctance_str; // - |
||
744 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
745 | for (int m =0; m < selectedRows.size(); ++m){ |
||
746 | |||
747 | |||
748 | QString query_str; |
||
749 | QString field_name_str; // |
||
750 | QSqlQuery q; |
||
751 | |||
752 | query_str.clear(); |
||
753 | |||
754 | |||
755 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
||
756 | |||
757 | query_str.append(tr("ALTER TABLE ")); |
||
758 | query_str.append(Inctance_str); |
||
759 | query_str.append(tr(" DROP COLUMN `")); |
||
760 | query_str.append(field_name_str); |
||
761 | query_str.append(tr("`")); |
||
762 | q.prepare(query_str); |
||
763 | bool ok = q.exec(); |
||
764 | if (!ok) { |
||
765 | QMessageBox::critical( // . |
||
766 | this, // . |
||
767 | QObject::tr("Database Error"), // . |
||
768 | q.lastError().text()); // . |
||
769 | |||
770 | return; // |
||
771 | |||
772 | } |
||
773 | |||
774 | |||
775 | |||
776 | modelForPointers->removeRow(selectedRows.at(m)); |
||
777 | |||
778 | } |
||
779 | |||
780 | |||
781 | refreshInctance(); |
||
782 | |||
783 | |||
784 | |||
785 | } |
||
786 | |||
787 | |||
788 | |||
789 | |||
790 | |||
63 | pingvin | 791 | void ClassEditor::on_pushButton_5_clicked(){ // " " |
792 | int row; |
||
793 | row = ClassEditor::modelForDescription->rowCount(); |
||
794 | ClassEditor::modelForDescription->removeRows(0, row); |
||
795 | ClassEditor::modelForDescription->submitAll(); |
||
796 | } |
||
797 | |||
161 | pingvin | 798 | void ClassEditor::on_pushButton_6_clicked(){ // " " |
799 | QString fileName; |
||
800 | QPixmap pixmap; |
||
801 | fileName = QFileDialog::getOpenFileName(this, |
||
802 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
||
803 | pixmap.load(fileName); |
||
804 | ui->label_4->setPixmap(pixmap); |
||
805 | QImage currentImage = pixmap.toImage(); |
||
806 | QByteArray bytes; |
||
807 | QBuffer buffer(&bytes); |
||
808 | buffer.open(QIODevice::WriteOnly); |
||
809 | currentImage.save(&buffer, "PNG"); |
||
810 | |||
811 | if (currIndexOfClassesTable.isValid()) { |
||
812 | bool ok; |
||
813 | |||
814 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
||
815 | mymodel->submitAll(); |
||
166 | pingvin | 816 | |
168 | pingvin | 817 | |
161 | pingvin | 818 | } |
819 | |||
820 | |||
821 | } |
||
822 | |||
62 | pingvin | 823 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
75 | pingvin | 824 | |
62 | pingvin | 825 | int i; |
826 | i++; |
||
827 | ui->tableView->resizeColumnsToContents(); |
||
168 | pingvin | 828 | ui->tableView->resizeRowsToContents(); |
75 | pingvin | 829 | |
830 | |||
831 | |||
832 | |||
62 | pingvin | 833 | } |
834 | |||
835 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
||
836 | ui->tableView_2->resizeColumnsToContents(); |
||
75 | pingvin | 837 | |
838 | /* |
||
839 | QString instance_str; |
||
840 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
841 | tableForInstance->close(); |
||
842 | delete model; |
||
843 | delete tableForInstance; |
||
844 | model = new QSqlTableModel(); |
||
845 | tableForInstance = new QTableView(); |
||
846 | model->setTable(instance_str); |
||
847 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
848 | tableForInstance->setModel(model); |
||
849 | |||
850 | model->select(); |
||
851 | tableForInstance->setWindowTitle(instance_str); |
||
852 | tableForInstance->show(); |
||
853 | */ |
||
62 | pingvin | 854 | } |
65 | pingvin | 855 | |
856 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // " ID" |
||
857 | if (is_checked) ui->tableView->showColumn(0); |
||
858 | else ui->tableView->hideColumn(0); |
||
859 | ui->tableView->resizeColumnsToContents(); |
||
860 | } |
||
861 | |||
862 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // " " |
||
863 | if (is_checked) ui->tableView->showColumn(2); |
||
864 | else ui->tableView->hideColumn(2); |
||
865 | ui->tableView->resizeColumnsToContents(); |
||
866 | } |
||
867 | |||
68 | pingvin | 868 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // " " |
65 | pingvin | 869 | if (is_checked) ui->tableView->showColumn(3); |
870 | else ui->tableView->hideColumn(3); |
||
871 | ui->tableView->resizeColumnsToContents(); |
||
872 | } |
||
68 | pingvin | 873 | |
874 | |||
875 | |||
876 | void ClassEditor::on_action_removeAllClasses(){ // " " |
||
877 | int row; |
||
878 | row = ClassEditor::mymodel->rowCount(); |
||
879 | for (int m=0; m < row; ++m){ |
||
880 | ClassEditor::removeClass(0); |
||
881 | //ClassEditor::mymodel->removeRows(0, row); |
||
882 | } |
||
883 | ClassEditor::mymodel->submitAll(); |
||
884 | ClassEditor::modelForDescription->select(); |
||
885 | } |
||
886 | |||
887 | void ClassEditor::removeClass(int class_row){ // , class_row |
||
888 | QModelIndex index_tmp; |
||
889 | QString tmp_str, filter_str; |
||
232 | pingvin | 890 | QString class_inctance; |
68 | pingvin | 891 | index_tmp = ui->tableView->model()->index(class_row, 0); |
892 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
||
893 | currClassID = tmp_str; |
||
232 | pingvin | 894 | index_tmp = ui->tableView->model()->index(class_row, 3); |
895 | class_inctance = ui->tableView->model()->data(index_tmp).toString(); |
||
896 | |||
897 | QSqlQuery q; |
||
898 | QString sql_str; |
||
899 | bool ok; |
||
900 | sql_str = tr("drop table `"); |
||
901 | sql_str.append(class_inctance); |
||
902 | sql_str.append(tr("`")); |
||
903 | ok = q.prepare(sql_str); |
||
904 | |||
905 | |||
906 | |||
907 | |||
908 | |||
68 | pingvin | 909 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
910 | filter_str = tr("ClassIdentifer = "); |
||
911 | filter_str.append(tmp_str); |
||
912 | modelForDescription->setFilter(filter_str); // |
||
913 | ClassEditor::on_pushButton_5_clicked(); // |
||
914 | mymodel->removeRow(class_row); // |
||
915 | mymodel->submitAll(); // |
||
232 | pingvin | 916 | |
917 | ok = q.exec();// |
||
918 | if (!ok) { |
||
919 | QMessageBox::critical( // . |
||
920 | this, // . |
||
921 | QObject::tr("Database Error"), // . |
||
922 | q.lastError().text()); // . |
||
923 | |||
924 | |||
925 | } |
||
926 | |||
68 | pingvin | 927 | ui->tableView->resizeColumnsToContents(); |
928 | ui->tableView_2->resizeColumnsToContents(); |
||
929 | |||
930 | } |
||
76 | pingvin | 931 | |
932 | |||
77 | pingvin | 933 | void ClassEditor::on_field_changed(){ // |
76 | pingvin | 934 | ClassEditor::refreshInctance(); |
935 | } |
||
936 | |||
937 | |||
938 | |||
939 | |||
940 | void ClassEditor::refreshInctance(){ // - |
||
941 | |||
942 | QString Inctance_str; // - |
||
943 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
944 | delete model; |
||
945 | delete tableForInstance; |
||
946 | model = new QSqlTableModel(); |
||
947 | tableForInstance = new QTableView(); |
||
948 | model->setTable(Inctance_str); |
||
949 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
78 | pingvin | 950 | model->select(); |
76 | pingvin | 951 | tableForInstance->setModel(model); |
952 | tableForInstance->setWindowTitle(Inctance_str); |
||
953 | tableForInstance->resizeRowsToContents(); |
||
954 | tableForInstance->show(); |
||
955 | |||
956 | } |
||
86 | pingvin | 957 | |
958 | |||
959 | |||
960 | |||
87 | pingvin | 961 | void ClassEditor::on_action_newPointer(){ // - |
86 | pingvin | 962 | ClassEditor::addNewPointer(); |
963 | ClassEditor::modelForPointers->select(); |
||
964 | ui->tableView_3->resizeColumnsToContents(); |
||
965 | |||
966 | } |
||
967 | |||
135 | pingvin | 968 | |
969 | // |
||
970 | |||
971 | void ClassEditor::readSettings() |
||
972 | { |
||
973 | QSettings settings("Trolltech", "Application Example"); |
||
974 | baseName = settings.value("baseName", "an_db").toString(); |
||
975 | userName = settings.value("userName", "an").toString(); |
||
976 | password = settings.value("password", "393939").toString(); |
||
977 | tableName = settings.value("tableName", "inventar").toString(); |
||
978 | hostName = settings.value("hostName", "server").toString(); |
||
979 | // resize(size); |
||
980 | // move(pos);tableName |
||
981 | } |
||
982 | |||
983 | |||
984 | void ClassEditor::writeSettings() |
||
985 | { |
||
986 | QSettings settings("Trolltech", "Application Example"); |
||
987 | settings.setValue("baseName", baseName); |
||
988 | settings.setValue("userName", userName); |
||
989 | settings.setValue("password", password); |
||
990 | settings.setValue("tableName", tableName); |
||
991 | settings.setValue("hostName", hostName); |
||
992 | } |
||
993 | |||
994 | |||
995 | void ClassEditor::applySetting() |
||
996 | { |
||
997 | bool ok; |
||
998 | baseName = setFrm.lineEdit->text(); |
||
999 | userName = setFrm.lineEdit_2->text(); |
||
1000 | password = setFrm.lineEdit_3->text(); |
||
1001 | // tableName = setFrm->lineEdit_4->text(); |
||
1002 | hostName = setFrm.lineEdit_5->text(); |
||
1003 | writeSettings(); |
||
1004 | |||
1005 | sql.close(); // |
||
1006 | |||
1007 | sql.setDatabaseName(baseName); |
||
1008 | // sql.setDatabaseName(tr("inventory")); |
||
1009 | |||
1010 | // sql.setHostName(tr("localhost")); |
||
1011 | sql.setHostName(hostName); |
||
1012 | |||
1013 | // sql.setUserName(tr("an")); |
||
1014 | |||
1015 | sql.setUserName(userName); |
||
1016 | |||
1017 | // sql.setPassword(tr("393939")); |
||
1018 | |||
1019 | sql.setPassword(password); |
||
1020 | |||
1021 | ok = sql.connect(); |
||
1022 | if (!ok) { |
||
1023 | QMessageBox::critical( // . |
||
1024 | this, // . |
||
1025 | QObject::tr("Database Error"), // . |
||
1026 | sql.lasError()); // . |
||
1027 | |||
1028 | } |
||
1029 | else { |
||
1030 | |||
1031 | QMessageBox::information( // . |
||
1032 | this, // . |
||
1033 | QObject::tr("Database Connect"), // . |
||
1034 | QObject::tr(" .")); // . |
||
1035 | |||
1036 | |||
1037 | |||
1038 | |||
1039 | |||
1040 | } |
||
1041 | |||
1042 | |||
1043 | mymodel->select(); |
||
1044 | model->select(); |
||
1045 | modelForDescription->select(); |
||
1046 | |||
1047 | //////////// ok=openDataBase(); |
||
1048 | //////////// if (!ok) return; |
||
1049 | // // // ui->treeWidget->clear(); // |
||
1050 | |||
1051 | // // // buildPreviewModel(tr(" "), tr("1")); |
||
1052 | //////////// class_list_map.clear(); // |
||
1053 | //////////// initComboBox(); |
||
1054 | // // // getDatabaseData(); |
||
1055 | // delete setFrm; |
||
1056 | setFrm.close(); |
||
1057 | } |
||
1058 | |||
1059 | void ClassEditor::getSetting() |
||
1060 | { |
||
1061 | // setFrm = new settingForm; |
||
1062 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
1063 | setFrm.lineEdit->setText(baseName); |
||
1064 | setFrm.lineEdit_2->setText(userName); |
||
1065 | setFrm.lineEdit_3->setText(password); |
||
1066 | // setFrm->lineEdit_4->setText(tableName); |
||
1067 | setFrm.lineEdit_5->setText(hostName); |
||
1068 | setFrm.show(); |
||
1069 | |||
1070 | |||
1071 | |||
1072 | } |
||
1073 | |||
1074 | |||
1075 | void ClassEditor::initDataBase(){ // |
||
1076 | |||
137 | pingvin | 1077 | sql.setDatabaseName(baseName); |
1078 | sql.setHostName(hostName); |
||
1079 | sql.setUserName(userName); |
||
1080 | sql.setPassword(password); |
||
135 | pingvin | 1081 | |
137 | pingvin | 1082 | bool ok; |
1083 | ok = sql.connect(); |
||
1084 | if (!ok) { |
||
1085 | QMessageBox::critical( // . |
||
1086 | this, // . |
||
1087 | QObject::tr("Database Error"), // . |
||
1088 | sql.lasError()); // . |
||
1089 | |||
1090 | } |
||
1091 | else { |
||
1092 | |||
1093 | QMessageBox::information( // . |
||
1094 | this, // . |
||
1095 | QObject::tr("Database Connect"), // . |
||
1096 | QObject::tr(" .")); // . |
||
1097 | |||
1098 | |||
1099 | |||
1100 | |||
1101 | |||
1102 | } |
||
1103 | |||
135 | pingvin | 1104 | } |
137 | pingvin | 1105 | |
1106 | |||
1107 | void ClassEditor::createMainTables(){// - DescriptionOfClasses ListOfClasses |
||
1108 | |||
1109 | bool ok; |
||
1110 | ok = sql.createListOfClassesTable(); |
||
1111 | |||
1112 | if (!ok) { |
||
1113 | QMessageBox::critical( // . |
||
1114 | this, // . |
||
1115 | QObject::tr("Database Error"), // . |
||
1116 | sql.lasError()); // . |
||
1117 | |||
1118 | } |
||
1119 | else { |
||
1120 | |||
1121 | QMessageBox::information( // . |
||
1122 | this, // . |
||
1123 | QObject::tr("Database Create"), // . |
||
1124 | QObject::tr(" .")); // . |
||
1125 | } |
||
1126 | |||
1127 | |||
1128 | |||
1129 | |||
1130 | ok = sql.createDescriptionOfClassesTable(); |
||
1131 | |||
1132 | if (!ok) { |
||
1133 | QMessageBox::critical( // . |
||
1134 | this, // . |
||
1135 | QObject::tr("Database Error"), // . |
||
1136 | sql.lasError()); // . |
||
1137 | |||
1138 | } |
||
1139 | else { |
||
1140 | |||
1141 | QMessageBox::information( // . |
||
1142 | this, // . |
||
1143 | QObject::tr("Database Create"), // . |
||
1144 | QObject::tr(" .")); // . |
||
1145 | } |
||
1146 | |||
1147 | |||
143 | pingvin | 1148 | ok = sql.createListModelsTable(); |
137 | pingvin | 1149 | |
143 | pingvin | 1150 | if (!ok) { |
1151 | QMessageBox::critical( // . |
||
1152 | this, // . |
||
1153 | QObject::tr("Database Error"), // . |
||
1154 | sql.lasError()); // . |
||
137 | pingvin | 1155 | |
143 | pingvin | 1156 | } |
1157 | else { |
||
137 | pingvin | 1158 | |
143 | pingvin | 1159 | QMessageBox::information( // . |
1160 | this, // . |
||
1161 | QObject::tr("Database Create"), // . |
||
1162 | QObject::tr(" .")); // . |
||
1163 | } |
||
137 | pingvin | 1164 | |
1165 | |||
143 | pingvin | 1166 | |
1167 | |||
210 | pingvin | 1168 | |
1169 | ok = sql.createFiltersTable(); |
||
1170 | |||
1171 | if (!ok) { |
||
1172 | QMessageBox::critical( // . |
||
1173 | this, // . |
||
1174 | QObject::tr("Database Error"), // . |
||
1175 | sql.lasError()); // . |
||
1176 | |||
1177 | } |
||
1178 | else { |
||
1179 | |||
1180 | QMessageBox::information( // . |
||
1181 | this, // . |
||
1182 | QObject::tr("Database Create"), // . |
||
1183 | QObject::tr(" .")); // . |
||
1184 | } |
||
1185 | |||
1186 | |||
137 | pingvin | 1187 | } |
1188 | |||
1189 | void ClassEditor::initClassListTable(){ // |
||
1190 | |||
1191 | mymodel->setTable(tr("ListOfClasses")); |
||
1192 | mymodel->setSort(0, Qt::AscendingOrder); |
||
1193 | mymodel->select(); |
||
1194 | mymodel->setHeaderData(1, Qt::Horizontal, tr(" ")); |
||
1195 | mymodel->setHeaderData(2, Qt::Horizontal, tr(" ")); |
||
1196 | mymodel->setHeaderData(4, Qt::Horizontal, tr("")); |
||
161 | pingvin | 1197 | mymodel->setHeaderData(5, Qt::Horizontal, tr("")); |
137 | pingvin | 1198 | ui->tableView->setModel(mymodel); |
1199 | ui->tableView->setAlternatingRowColors(true); |
||
166 | pingvin | 1200 | ui->tableView->resizeColumnsToContents(); |
1201 | ui->tableView->resizeRowsToContents(); |
||
137 | pingvin | 1202 | ui->tableView->hideColumn(0); |
1203 | ui->tableView->hideColumn(3); |
||
1204 | ui->tableView->hideColumn(2); |
||
161 | pingvin | 1205 | CPictureDelegate *pictureDelegate; |
1206 | pictureDelegate = new CPictureDelegate(this); |
||
165 | pingvin | 1207 | pictureDelegate->setTableView(ui->tableView); |
161 | pingvin | 1208 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
168 | pingvin | 1209 | ui->tableView->resizeColumnsToContents(); |
1210 | ui->tableView->resizeRowsToContents(); |
||
161 | pingvin | 1211 | /* |
1212 | for (int i=0; i < mymodel->rowCount(); i++){ |
||
1213 | ui->tableView->setRowHeight(i, 100); |
||
1214 | } |
||
1215 | */ |
||
1216 | |||
137 | pingvin | 1217 | } |
1218 | |||
1219 | |||
1220 | void ClassEditor::initFieldsTable(){ // |
||
1221 | |||
1222 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
||
1223 | modelForDescription->setSort(0, Qt::AscendingOrder); |
||
1224 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
1225 | ui->tableView_2->setModel(modelForDescription); |
||
1226 | ui->tableView_2->setAlternatingRowColors(true); |
||
1227 | ui->tableView_2->resizeColumnsToContents(); |
||
1228 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
||
1229 | } |
||
1230 | |||
1231 | void ClassEditor::initPointersTable(){ // - |
||
1232 | |||
1233 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
||
1234 | modelForPointers->setSort(0, Qt::AscendingOrder); |
||
1235 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
1236 | ui->tableView_3->setModel(modelForPointers); |
||
1237 | delegateForDefaultValueColomn.getItems(); |
||
1238 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
||
1239 | |||
1240 | // ui->tableView_3->resizeColumnsToContents(); |
||
1241 | |||
1242 | } |