Редакция 87 | Редакция 135 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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 | |
11 | |||
12 | |||
13 | // settdialog = new SettingsDialog(this); |
||
14 | ///////////////////////////////////////////////////// settdialog.show(); |
||
24 | pingvin | 15 | sql.setDatabaseName(tr("an_db")); |
56 | pingvin | 16 | |
60 | pingvin | 17 | /* |
35 | pingvin | 18 | field = new TableField(tr(""), this); |
38 | pingvin | 19 | field->setNotNull(true); |
35 | pingvin | 20 | field->setDefaultValue(tr("")); |
33 | pingvin | 21 | |
38 | pingvin | 22 | table = new SqlTable (tr("NewTable"), this); |
23 | table->setName(tr("NewTable")); |
||
39 | pingvin | 24 | table->fields().at(0)->setNotNull(true); |
25 | if (!(table->setPrimaryKey(tr("ID")))) { |
||
26 | ui->label_3->setText(table->lastError()); |
||
27 | } |
||
28 | else ui->label_3->setText(table->primaryKey()); |
||
29 | table->append(field); |
||
30 | |||
31 | field = new TableField(tr(""), this); |
||
32 | field->setNotNull(true); |
||
33 | field->setDefaultValue(tr("")); |
||
34 | table->append(field); |
||
35 | |||
40 | pingvin | 36 | field = new TableField(tr(""), this); |
37 | field->setNotNull(true); |
||
38 | field->setDefaultValue(tr("")); |
||
39 | table->append(field); |
||
40 | |||
41 | field = new TableField(tr(" ()"), this); |
||
42 | field->setNotNull(true); |
||
43 | field->setType(tr("INTEGER")); |
||
44 | field->setDefaultValue(tr("1")); |
||
45 | table->append(field); |
||
46 | |||
47 | field = new TableField(tr(" "), this); |
||
48 | field->setNotNull(false); |
||
49 | field->setType(tr("DATE")); |
||
50 | field->setDefaultValue(tr("NULL")); |
||
51 | table->append(field); |
||
52 | |||
38 | pingvin | 53 | ui->label_2->setText(table->name()); |
54 | ui->label->setText(table->fields().at(0)->sqlString()); |
||
39 | pingvin | 55 | ui->label_4->setText(table->sqlString()); |
40 | pingvin | 56 | ////// ui->lineEdit->insert(table->sqlString()); |
38 | pingvin | 57 | |
60 | pingvin | 58 | */ |
45 | pingvin | 59 | /********************************************** |
60 | |||
40 | pingvin | 61 | QTextDocument *document; |
62 | // = ui->textEdit->document(); |
||
63 | QTextCursor *cursor; |
||
45 | pingvin | 64 | |
40 | pingvin | 65 | document = ui->textEdit->document(); |
66 | cursor = new QTextCursor(document); |
||
67 | cursor->movePosition(QTextCursor::Start); |
||
68 | QTextCharFormat format(cursor->charFormat()); |
||
69 | //format.setFontFamily("Courier"); |
||
70 | format.setFontFamily("Arial"); |
||
71 | //format.setFontItalic(false); |
||
72 | |||
73 | format.setFontWeight(QFont::Normal); |
||
74 | QTextCharFormat boldFormat = format; |
||
75 | boldFormat.setFontWeight(QFont::Bold); |
||
76 | |||
77 | QTextCharFormat italicFormat = format; |
||
78 | //format.setFontFamily("Courier"); |
||
79 | // format.setFontFamily("Arial"); |
||
80 | italicFormat.setFontItalic(true); |
||
81 | |||
82 | cursor->insertText(table->sqlString(), format); |
||
41 | pingvin | 83 | |
45 | pingvin | 84 | ****************************************************/ |
85 | |||
41 | pingvin | 86 | QString errorString; |
87 | |||
88 | sql.setDatabaseName(tr("an_db")); |
||
134 | pingvin | 89 | // sql.setDatabaseName(tr("inventory")); |
41 | pingvin | 90 | sql.setHostName(tr("localhost")); |
91 | sql.setUserName(tr("an")); |
||
92 | sql.setPassword(tr("393939")); |
||
93 | |||
94 | bool ok; |
||
44 | pingvin | 95 | ok = sql.connect(); |
41 | pingvin | 96 | if (!ok) { |
97 | QMessageBox::critical( // . |
||
98 | this, // . |
||
99 | QObject::tr("Database Error"), // . |
||
45 | pingvin | 100 | sql.lasError()); // . |
41 | pingvin | 101 | |
102 | } |
||
103 | else { |
||
104 | |||
105 | QMessageBox::information( // . |
||
106 | this, // . |
||
107 | QObject::tr("Database Connect"), // . |
||
108 | QObject::tr(" .")); // . |
||
109 | |||
110 | |||
111 | |||
112 | |||
113 | |||
24 | pingvin | 114 | } |
115 | |||
60 | pingvin | 116 | /* |
44 | pingvin | 117 | ok = sql.createTable(table); |
42 | pingvin | 118 | if (!ok) { |
119 | QMessageBox::critical( // . |
||
120 | this, // . |
||
121 | QObject::tr("Database Error"), // . |
||
45 | pingvin | 122 | sql.lasError()); // . |
123 | } |
||
42 | pingvin | 124 | else { |
125 | |||
126 | QMessageBox::information( // . |
||
127 | this, // . |
||
128 | QObject::tr("Database Connect"), // . |
||
129 | QObject::tr(" .")); // . |
||
45 | pingvin | 130 | } |
42 | pingvin | 131 | |
132 | |||
133 | |||
60 | pingvin | 134 | */ |
42 | pingvin | 135 | |
56 | pingvin | 136 | ok = sql.createListOfClassesTable(); |
41 | pingvin | 137 | |
45 | pingvin | 138 | if (!ok) { |
139 | QMessageBox::critical( // . |
||
140 | this, // . |
||
141 | QObject::tr("Database Error"), // . |
||
142 | sql.lasError()); // . |
||
143 | |||
144 | } |
||
145 | else { |
||
146 | |||
147 | QMessageBox::information( // . |
||
148 | this, // . |
||
149 | QObject::tr("Database Create"), // . |
||
150 | QObject::tr(" .")); // . |
||
151 | } |
||
152 | |||
153 | |||
56 | pingvin | 154 | |
155 | |||
156 | ok = sql.createDescriptionOfClassesTable(); |
||
157 | |||
158 | if (!ok) { |
||
159 | QMessageBox::critical( // . |
||
160 | this, // . |
||
161 | QObject::tr("Database Error"), // . |
||
162 | sql.lasError()); // . |
||
163 | |||
164 | } |
||
165 | else { |
||
166 | |||
167 | QMessageBox::information( // . |
||
168 | this, // . |
||
169 | QObject::tr("Database Create"), // . |
||
170 | QObject::tr(" .")); // . |
||
171 | } |
||
172 | |||
173 | |||
174 | |||
175 | |||
176 | |||
177 | |||
178 | |||
72 | pingvin | 179 | model = new QSqlTableModel(); // |
180 | tableForInstance = new QTableView(); |
||
50 | pingvin | 181 | mymodel = new MyModel(this); |
82 | pingvin | 182 | modelForPointers = new ModelForPointers(this); // // |
183 | |||
61 | pingvin | 184 | //modelForDescription = new QSqlTableModel(this); |
185 | modelForDescription = new ModelForDescriptionTable(this); |
||
50 | pingvin | 186 | |
61 | pingvin | 187 | |
56 | pingvin | 188 | /////////////////model->setTable(tr("ListOfClasses")); |
50 | pingvin | 189 | mymodel->setTable(tr("ListOfClasses")); |
56 | pingvin | 190 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
191 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
50 | pingvin | 192 | |
45 | pingvin | 193 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
50 | pingvin | 194 | |
87 | pingvin | 195 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit); |
196 | |||
197 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
198 | |||
82 | pingvin | 199 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
50 | pingvin | 200 | |
201 | |||
82 | pingvin | 202 | |
203 | |||
71 | pingvin | 204 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange); |
205 | |||
206 | |||
207 | |||
56 | pingvin | 208 | //////////////////model->setSort(0, Qt::AscendingOrder); |
50 | pingvin | 209 | mymodel->setSort(0, Qt::AscendingOrder); |
56 | pingvin | 210 | modelForDescription->setSort(0, Qt::AscendingOrder); |
82 | pingvin | 211 | modelForPointers->setSort(0, Qt::AscendingOrder); |
50 | pingvin | 212 | |
45 | pingvin | 213 | // model->setFilter(tr("__ = '7' and _ = 'i09090909'")); |
56 | pingvin | 214 | ////////////////////model->select(); |
50 | pingvin | 215 | mymodel->select(); |
82 | pingvin | 216 | // modelForPointers->select(); |
50 | pingvin | 217 | |
56 | pingvin | 218 | |
68 | pingvin | 219 | |
220 | |||
56 | pingvin | 221 | /////////////////////////model->setHeaderData(1, Qt::Horizontal, tr(" ")); |
50 | pingvin | 222 | mymodel->setHeaderData(1, Qt::Horizontal, tr(" ")); |
223 | |||
224 | |||
225 | |||
56 | pingvin | 226 | ////////////////////////model->setHeaderData(2, Qt::Horizontal, tr(" ")); |
50 | pingvin | 227 | mymodel->setHeaderData(2, Qt::Horizontal, tr(" ")); |
60 | pingvin | 228 | mymodel->setHeaderData(4, Qt::Horizontal, tr("")); |
50 | pingvin | 229 | |
82 | pingvin | 230 | //ui->tableView_3->setModel(modelForPointers); |
65 | pingvin | 231 | |
50 | pingvin | 232 | //ui->tableView->setModel(model); |
233 | ui->tableView->setModel(mymodel); |
||
56 | pingvin | 234 | //tableForDescription = new QTableView(); |
235 | ui->tableView_2->setModel(modelForDescription); |
||
236 | ui->tableView_2->setAlternatingRowColors(true); |
||
237 | ui->tableView_2->resizeColumnsToContents(); |
||
238 | //tableForDescription->show(); |
||
50 | pingvin | 239 | |
240 | |||
45 | pingvin | 241 | ui->tableView->setAlternatingRowColors(true); |
242 | ui->tableView->resizeColumnsToContents(); |
||
65 | pingvin | 243 | |
60 | pingvin | 244 | ui->tableView->hideColumn(0); |
55 | pingvin | 245 | ui->tableView->hideColumn(3); |
60 | pingvin | 246 | ui->tableView->hideColumn(2); |
45 | pingvin | 247 | |
65 | pingvin | 248 | /* |
62 | pingvin | 249 | ui->tableView_2->hideColumn(0); |
250 | ui->tableView_2->hideColumn(5); |
||
251 | ui->tableView_2->hideColumn(2); |
||
65 | pingvin | 252 | */ |
253 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
||
45 | pingvin | 254 | |
134 | pingvin | 255 | delegateForDefaultValueColomn.getItems(); |
256 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
||
257 | |||
258 | |||
259 | |||
260 | if (mymodel->rowCount() > 0) currIndexOfClassesTable = mymodel->index(0, 1); |
||
62 | pingvin | 261 | QModelIndex index_temp; |
262 | |||
75 | pingvin | 263 | |
264 | |||
62 | pingvin | 265 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
266 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
267 | |||
268 | QModelIndex topLeft; |
||
269 | QModelIndex bottomRight; |
||
270 | |||
271 | topLeft = mymodel->index(0, 0, QModelIndex()); |
||
272 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
||
273 | |||
274 | QItemSelection selection(topLeft, bottomRight); |
||
275 | selectionModel->select(selection, QItemSelectionModel::Select); |
||
276 | |||
277 | |||
71 | pingvin | 278 | QString class_indx, class_instance; |
68 | pingvin | 279 | QString str_fltr = tr("ClassIdentifer = "); |
280 | class_indx = mymodel->data(mymodel->index(0,0)).toString(); |
||
71 | pingvin | 281 | class_instance = mymodel->data(mymodel->index(0,3)).toString(); |
75 | pingvin | 282 | |
283 | currInctanceTable = class_instance; // |
||
284 | modelForDescription->setInctance(class_instance); // - |
||
71 | pingvin | 285 | //class_instance.append(tr("_inctance")); |
68 | pingvin | 286 | str_fltr.append(class_indx); |
83 | pingvin | 287 | str_fltr.append(tr(" AND FieldType <> \"pointer\"")); |
62 | pingvin | 288 | |
71 | pingvin | 289 | model->setTable(class_instance); |
290 | //model->setTable(tr("memory")); |
||
72 | pingvin | 291 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
71 | pingvin | 292 | model->select(); |
72 | pingvin | 293 | tableForInstance->setModel(model); |
294 | tableForInstance->resizeColumnsToContents(); |
||
295 | tableForInstance->setWindowTitle(class_instance); |
||
296 | tableForInstance->show(); |
||
71 | pingvin | 297 | |
68 | pingvin | 298 | modelForDescription->setFilter(str_fltr); |
299 | modelForDescription->select(); |
||
69 | pingvin | 300 | ui->tableView_2->resizeColumnsToContents(); |
68 | pingvin | 301 | |
83 | pingvin | 302 | |
303 | str_fltr = tr("ClassIdentifer = "); |
||
304 | modelForPointers->setInctance(class_instance); // - |
||
305 | str_fltr.append(class_indx); |
||
306 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
||
82 | pingvin | 307 | // str_fltr.append( tr(" FieldType = pointer ")); |
83 | pingvin | 308 | |
309 | |||
310 | |||
311 | modelForPointers->setFilter(str_fltr); |
||
82 | pingvin | 312 | modelForPointers->select(); |
313 | ui->tableView_3->setModel(modelForPointers); |
||
83 | pingvin | 314 | ui->tableView_3->resizeColumnsToContents(); |
68 | pingvin | 315 | |
55 | pingvin | 316 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex))); |
62 | pingvin | 317 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
318 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
||
72 | pingvin | 319 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool))); |
65 | pingvin | 320 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
68 | pingvin | 321 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // |
322 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // |
||
323 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // |
||
324 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // |
||
325 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // |
||
73 | pingvin | 326 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // |
327 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // |
||
328 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // |
||
86 | pingvin | 329 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // - |
330 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // - |
||
87 | pingvin | 331 | |
332 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // |
||
86 | pingvin | 333 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // |
334 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // |
||
335 | |||
336 | |||
87 | pingvin | 337 | |
42 | pingvin | 338 | } |
339 | |||
45 | pingvin | 340 | |
341 | |||
342 | |||
343 | |||
344 | |||
345 | |||
346 | |||
347 | |||
348 | |||
349 | |||
24 | pingvin | 350 | ClassEditor::~ClassEditor() |
351 | { |
||
352 | delete ui; |
||
72 | pingvin | 353 | delete model; |
354 | delete tableForInstance; |
||
38 | pingvin | 355 | // delete field; |
24 | pingvin | 356 | // delete settdialog; |
357 | } |
||
358 | |||
359 | void ClassEditor::changeEvent(QEvent *e) |
||
360 | { |
||
361 | QMainWindow::changeEvent(e); |
||
362 | switch (e->type()) { |
||
363 | case QEvent::LanguageChange: |
||
364 | ui->retranslateUi(this); |
||
365 | break; |
||
366 | default: |
||
367 | break; |
||
368 | } |
||
369 | } |
||
51 | pingvin | 370 | |
371 | |||
71 | pingvin | 372 | /* |
51 | pingvin | 373 | void ClassEditor::addNewClass(){ |
374 | |||
375 | int row = model->rowCount(); |
||
376 | |||
377 | model->insertRows(row, 1); |
||
54 | pingvin | 378 | model->setData(model->index(row, 1), tr("New class")); // " " |
51 | pingvin | 379 | |
380 | |||
381 | // model->setData(model->index(row, 1), tr(" ")); |
||
382 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
383 | |||
384 | |||
385 | model->submitAll(); |
||
386 | |||
387 | row = model->rowCount(); |
||
388 | QString tmp_str; |
||
389 | int i_tmp; |
||
390 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
||
391 | tmp_str = model->data(model->index(row-1, 0)).toString(); // - |
||
392 | |||
393 | tmp_str.append(tr("_Inctance")); |
||
394 | model->setData(model->index(row-1, 3), tmp_str ); // |
||
395 | |||
396 | model->submitAll(); |
||
397 | mymodel->select(); |
||
398 | |||
399 | |||
400 | } |
||
71 | pingvin | 401 | */ |
51 | pingvin | 402 | |
54 | pingvin | 403 | void ClassEditor::addNewClass_new(){ |
404 | |||
405 | int row = mymodel->rowCount(); |
||
406 | |||
407 | mymodel->insertRows(row, 1); |
||
70 | pingvin | 408 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // " " |
54 | pingvin | 409 | |
70 | pingvin | 410 | |
54 | pingvin | 411 | mymodel->submitAll(); |
412 | row = mymodel->rowCount(); |
||
70 | pingvin | 413 | QString tmp_str1, sql_str; |
54 | pingvin | 414 | int i_tmp1; |
415 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
||
416 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // - |
||
417 | |||
418 | tmp_str1.append(tr("_Inctance")); |
||
70 | pingvin | 419 | SqlTable* tbl; |
420 | tbl = new SqlTable(tmp_str1); // |
||
421 | sql_str = tbl->sqlString(); |
||
422 | bool ok; |
||
423 | |||
424 | ok = sql.createTable(tbl); |
||
425 | |||
426 | if (!ok) { |
||
427 | QMessageBox::critical( // . |
||
428 | this, // . |
||
429 | QObject::tr("Database Error"), // . |
||
430 | sql.lasError()); // . |
||
431 | delete tbl; |
||
432 | mymodel->removeRow(row-1); |
||
433 | mymodel->submitAll(); |
||
434 | mymodel->select(); |
||
435 | ui->tableView_2->resizeRowsToContents(); |
||
436 | return; // |
||
437 | |||
438 | } |
||
439 | |||
440 | delete tbl; |
||
54 | pingvin | 441 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // |
442 | |||
70 | pingvin | 443 | |
444 | |||
54 | pingvin | 445 | // model->setData(model->index(row, 1), tr(" ")); |
446 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
447 | |||
448 | |||
56 | pingvin | 449 | //mymodel->submitAll(); |
54 | pingvin | 450 | |
451 | //row = mymodel->rowCount(); |
||
452 | |||
453 | |||
56 | pingvin | 454 | //mymodel->select(); |
54 | pingvin | 455 | |
456 | |||
457 | } |
||
458 | |||
459 | |||
62 | pingvin | 460 | void ClassEditor::addNewField(){ |
461 | // QSqlRecord rec = mymodel->record(1); |
||
462 | //bool ok; |
||
463 | //ok = rec.isEmpty(); |
||
464 | //QString currientClassID; |
||
465 | //currientClassID = rec.value(1).toString(); |
||
73 | pingvin | 466 | QString Inctance_str; // - |
467 | QString query_str = tr("ALTER TABLE "); |
||
468 | QString db_error; |
||
469 | QSqlQuery q; |
||
72 | pingvin | 470 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
471 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
73 | pingvin | 472 | query_str.append( Inctance_str); |
82 | pingvin | 473 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
73 | pingvin | 474 | bool ok = q.prepare(query_str); |
72 | pingvin | 475 | |
73 | pingvin | 476 | ok = q.exec(); |
477 | if (!ok) { |
||
478 | QMessageBox::critical( // . |
||
479 | this, // . |
||
480 | QObject::tr("Database Error"), // . |
||
481 | q.lastError().text()); // . |
||
482 | |||
483 | return; // |
||
484 | |||
485 | } |
||
486 | |||
62 | pingvin | 487 | int row = modelForDescription->rowCount(); |
488 | modelForDescription->insertRows(row, 1); |
||
81 | pingvin | 489 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
490 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 491 | |
492 | modelForDescription->submitAll(); |
||
73 | pingvin | 493 | |
494 | delete model; |
||
495 | delete tableForInstance; |
||
496 | model = new QSqlTableModel(); |
||
497 | tableForInstance = new QTableView(); |
||
498 | model->setTable(Inctance_str); |
||
499 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
500 | tableForInstance->setModel(model); |
||
501 | tableForInstance->setWindowTitle(Inctance_str); |
||
502 | tableForInstance->show(); |
||
62 | pingvin | 503 | } |
504 | |||
505 | |||
506 | |||
86 | pingvin | 507 | void ClassEditor::addNewPointer(){ // , - |
508 | QString Inctance_str; // - |
||
509 | QString query_str = tr("ALTER TABLE "); |
||
510 | QString db_error; |
||
511 | QSqlQuery q; |
||
512 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
||
513 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
514 | query_str.append( Inctance_str); |
||
515 | query_str.append(tr(" ADD COLUMN `lass-container ID` CHAR(30)")); |
||
516 | bool ok = q.prepare(query_str); |
||
62 | pingvin | 517 | |
86 | pingvin | 518 | ok = q.exec(); |
519 | if (!ok) { |
||
520 | QMessageBox::critical( // . |
||
521 | this, // . |
||
522 | QObject::tr("Database Error"), // . |
||
523 | q.lastError().text()); // . |
||
62 | pingvin | 524 | |
86 | pingvin | 525 | return; // |
62 | pingvin | 526 | |
86 | pingvin | 527 | } |
62 | pingvin | 528 | |
529 | |||
86 | pingvin | 530 | int row = ClassEditor::modelForPointers->rowCount(); |
531 | modelForPointers->insertRows(row, 1); |
||
62 | pingvin | 532 | |
86 | pingvin | 533 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("lass-container ID")), Qt::EditRole); |
534 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
||
535 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
||
536 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 537 | |
86 | pingvin | 538 | |
539 | modelForPointers->submitAll(); |
||
540 | |||
541 | ClassEditor::refreshInctance(); |
||
542 | |||
543 | |||
544 | |||
545 | |||
546 | |||
547 | |||
548 | |||
549 | |||
550 | |||
551 | } |
||
552 | |||
553 | |||
554 | |||
555 | |||
556 | |||
68 | pingvin | 557 | // |
51 | pingvin | 558 | void ClassEditor::on_pushButton_clicked(){ |
54 | pingvin | 559 | //int i; |
560 | //i++; |
||
561 | /////ClassEditor::addNewClass(); |
||
562 | ClassEditor::addNewClass_new(); |
||
563 | mymodel->select(); |
||
564 | //ui->tableView->setModel(mymodel); |
||
565 | |||
51 | pingvin | 566 | } |
54 | pingvin | 567 | |
55 | pingvin | 568 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
569 | int i, row, column; |
||
570 | i++; |
||
571 | row = index.row(); |
||
572 | column = index.column(); |
||
62 | pingvin | 573 | currIndexOfClassesTable = index; |
71 | pingvin | 574 | QModelIndex index_tmp, index_instance; |
575 | QString tmp_str, filter_str, instance_str; |
||
56 | pingvin | 576 | index_tmp = ui->tableView->model()->index(row, 0); |
71 | pingvin | 577 | index_instance = ui->tableView->model()->index(row, 3); |
56 | pingvin | 578 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
71 | pingvin | 579 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
75 | pingvin | 580 | modelForDescription->setInctance(instance_str); // - |
83 | pingvin | 581 | modelForPointers->setInctance(instance_str); |
75 | pingvin | 582 | |
134 | pingvin | 583 | delegateForDefaultValueColomn.getItems(); // |
75 | pingvin | 584 | |
71 | pingvin | 585 | // instance_str.append(tr("_inctance")); |
72 | pingvin | 586 | /* |
587 | Inctance_model.clear(); |
||
588 | Inctance_model.setTable(instance_str); |
||
589 | Inctance_model.select(); |
||
590 | tableForInstance_new.setModel(&Inctance_model); |
||
591 | tableForInstance_new.show(); |
||
592 | */ |
||
593 | // model->clear(); |
||
594 | tableForInstance->close(); |
||
595 | delete model; |
||
596 | delete tableForInstance; |
||
597 | model = new QSqlTableModel(); |
||
598 | tableForInstance = new QTableView(); |
||
599 | model->setTable(instance_str); |
||
600 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
601 | tableForInstance->setModel(model); |
||
71 | pingvin | 602 | |
603 | model->select(); |
||
72 | pingvin | 604 | tableForInstance->setWindowTitle(instance_str); |
605 | tableForInstance->show(); |
||
606 | |||
71 | pingvin | 607 | // tableForInstance.setModel(model); |
72 | pingvin | 608 | tableForInstance->resizeColumnsToContents(); |
71 | pingvin | 609 | |
62 | pingvin | 610 | currClassID = tmp_str; |
611 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
56 | pingvin | 612 | filter_str = tr("ClassIdentifer = "); |
613 | filter_str.append(tmp_str); |
||
83 | pingvin | 614 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
56 | pingvin | 615 | modelForDescription->setFilter(filter_str); |
68 | pingvin | 616 | modelForDescription->select(); |
62 | pingvin | 617 | ui->tableView_2->resizeColumnsToContents(); |
83 | pingvin | 618 | |
619 | filter_str = tr("ClassIdentifer = "); |
||
620 | filter_str.append(tmp_str); |
||
621 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
||
622 | modelForPointers->setFilter(filter_str); |
||
623 | modelForPointers->select(); |
||
624 | ui->tableView_3->resizeColumnsToContents(); |
||
625 | |||
626 | |||
627 | |||
628 | |||
56 | pingvin | 629 | i++; |
55 | pingvin | 630 | } |
54 | pingvin | 631 | |
59 | pingvin | 632 | |
633 | |||
68 | pingvin | 634 | void ClassEditor::on_pushButton_2_clicked(){ // " " |
635 | QModelIndex model_index; |
||
636 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
637 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
638 | QList<int> selectedRows; |
||
639 | selectedRows.clear(); |
||
640 | foreach (model_index, indexes){ // |
||
641 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
59 | pingvin | 642 | |
68 | pingvin | 643 | } |
644 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
645 | |||
646 | |||
647 | for (int m =0; m < selectedRows.size(); ++m){ |
||
648 | |||
649 | ClassEditor::removeClass(selectedRows.at(m)); |
||
650 | |||
651 | |||
652 | |||
653 | } |
||
654 | mymodel->submitAll(); |
||
655 | ClassEditor::modelForDescription->select(); |
||
656 | |||
59 | pingvin | 657 | } |
658 | |||
659 | void ClassEditor::on_pushButton_3_clicked(){ // " " |
||
660 | int i; |
||
661 | i++; |
||
62 | pingvin | 662 | ClassEditor::addNewField(); |
663 | ClassEditor::modelForDescription->select(); |
||
64 | pingvin | 664 | ui->tableView_2->resizeColumnsToContents(); |
59 | pingvin | 665 | } |
68 | pingvin | 666 | |
667 | |||
59 | pingvin | 668 | void ClassEditor::on_pushButton_4_clicked(){ // " " |
69 | pingvin | 669 | // int i; |
62 | pingvin | 670 | QModelIndex model_index; |
63 | pingvin | 671 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
62 | pingvin | 672 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
69 | pingvin | 673 | //QModelIndexList indexes_fo_first_col; // ( ) |
62 | pingvin | 674 | //model_index = mymodel->selec; |
675 | //modelList = ui->tableView->SelectItems; |
||
69 | pingvin | 676 | //i = indexes.size(); |
63 | pingvin | 677 | QList<int> selectedRows; |
69 | pingvin | 678 | //indexes_fo_first_col.clear(); |
679 | /* |
||
67 | pingvin | 680 | foreach (model_index, indexes){ // |
681 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // |
||
682 | |||
683 | } |
||
69 | pingvin | 684 | */ |
63 | pingvin | 685 | selectedRows.clear(); |
686 | foreach (model_index, indexes){ // |
||
73 | pingvin | 687 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
688 | selectedRows.append(model_index.row()); // |
||
689 | } |
||
63 | pingvin | 690 | } |
67 | pingvin | 691 | |
692 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
693 | |||
74 | pingvin | 694 | QString Inctance_str; // - |
695 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
67 | pingvin | 696 | for (int m =0; m < selectedRows.size(); ++m){ |
697 | |||
74 | pingvin | 698 | |
699 | QString query_str; |
||
700 | QString field_name_str; // |
||
701 | QSqlQuery q; |
||
702 | |||
703 | query_str.clear(); |
||
704 | |||
705 | |||
706 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
||
707 | |||
708 | query_str.append(tr("ALTER TABLE ")); |
||
709 | query_str.append(Inctance_str); |
||
710 | query_str.append(tr(" DROP COLUMN `")); |
||
711 | query_str.append(field_name_str); |
||
712 | query_str.append(tr("`")); |
||
713 | q.prepare(query_str); |
||
714 | bool ok = q.exec(); |
||
715 | if (!ok) { |
||
716 | QMessageBox::critical( // . |
||
717 | this, // . |
||
718 | QObject::tr("Database Error"), // . |
||
719 | q.lastError().text()); // . |
||
720 | |||
721 | return; // |
||
722 | |||
723 | } |
||
724 | |||
725 | |||
726 | |||
727 | modelForDescription->removeRow(selectedRows.at(m)); |
||
728 | |||
67 | pingvin | 729 | } |
74 | pingvin | 730 | delete model; |
731 | delete tableForInstance; |
||
732 | model = new QSqlTableModel(); |
||
733 | tableForInstance = new QTableView(); |
||
734 | model->setTable(Inctance_str); |
||
735 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
736 | tableForInstance->setModel(model); |
||
737 | tableForInstance->setWindowTitle(Inctance_str); |
||
738 | tableForInstance->show(); |
||
69 | pingvin | 739 | //i = selectedRows.size(); |
63 | pingvin | 740 | |
69 | pingvin | 741 | //if (i > 0) model_index = indexes.at(0); |
59 | pingvin | 742 | } |
62 | pingvin | 743 | |
744 | |||
87 | pingvin | 745 | void ClassEditor::on_action_removeSelectedPointers(){ // |
746 | QModelIndex model_index; |
||
747 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
||
748 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
749 | QList<int> selectedRows; |
||
750 | |||
751 | selectedRows.clear(); |
||
752 | |||
753 | foreach (model_index, indexes){ // |
||
754 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
||
755 | selectedRows.append(model_index.row()); // |
||
756 | } |
||
757 | } |
||
758 | |||
759 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
760 | |||
761 | QString Inctance_str; // - |
||
762 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
763 | for (int m =0; m < selectedRows.size(); ++m){ |
||
764 | |||
765 | |||
766 | QString query_str; |
||
767 | QString field_name_str; // |
||
768 | QSqlQuery q; |
||
769 | |||
770 | query_str.clear(); |
||
771 | |||
772 | |||
773 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
||
774 | |||
775 | query_str.append(tr("ALTER TABLE ")); |
||
776 | query_str.append(Inctance_str); |
||
777 | query_str.append(tr(" DROP COLUMN `")); |
||
778 | query_str.append(field_name_str); |
||
779 | query_str.append(tr("`")); |
||
780 | q.prepare(query_str); |
||
781 | bool ok = q.exec(); |
||
782 | if (!ok) { |
||
783 | QMessageBox::critical( // . |
||
784 | this, // . |
||
785 | QObject::tr("Database Error"), // . |
||
786 | q.lastError().text()); // . |
||
787 | |||
788 | return; // |
||
789 | |||
790 | } |
||
791 | |||
792 | |||
793 | |||
794 | modelForPointers->removeRow(selectedRows.at(m)); |
||
795 | |||
796 | } |
||
797 | |||
798 | |||
799 | refreshInctance(); |
||
800 | |||
801 | |||
802 | |||
803 | } |
||
804 | |||
805 | |||
806 | |||
807 | |||
808 | |||
63 | pingvin | 809 | void ClassEditor::on_pushButton_5_clicked(){ // " " |
810 | int row; |
||
811 | row = ClassEditor::modelForDescription->rowCount(); |
||
812 | ClassEditor::modelForDescription->removeRows(0, row); |
||
813 | ClassEditor::modelForDescription->submitAll(); |
||
814 | } |
||
815 | |||
62 | pingvin | 816 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
75 | pingvin | 817 | |
62 | pingvin | 818 | int i; |
819 | i++; |
||
820 | ui->tableView->resizeColumnsToContents(); |
||
75 | pingvin | 821 | |
822 | |||
823 | |||
824 | |||
825 | |||
62 | pingvin | 826 | } |
827 | |||
828 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
||
829 | ui->tableView_2->resizeColumnsToContents(); |
||
75 | pingvin | 830 | |
831 | /* |
||
832 | QString instance_str; |
||
833 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
834 | tableForInstance->close(); |
||
835 | delete model; |
||
836 | delete tableForInstance; |
||
837 | model = new QSqlTableModel(); |
||
838 | tableForInstance = new QTableView(); |
||
839 | model->setTable(instance_str); |
||
840 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
841 | tableForInstance->setModel(model); |
||
842 | |||
843 | model->select(); |
||
844 | tableForInstance->setWindowTitle(instance_str); |
||
845 | tableForInstance->show(); |
||
846 | */ |
||
62 | pingvin | 847 | } |
65 | pingvin | 848 | |
849 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // " ID" |
||
850 | if (is_checked) ui->tableView->showColumn(0); |
||
851 | else ui->tableView->hideColumn(0); |
||
852 | ui->tableView->resizeColumnsToContents(); |
||
853 | } |
||
854 | |||
855 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // " " |
||
856 | if (is_checked) ui->tableView->showColumn(2); |
||
857 | else ui->tableView->hideColumn(2); |
||
858 | ui->tableView->resizeColumnsToContents(); |
||
859 | } |
||
860 | |||
68 | pingvin | 861 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // " " |
65 | pingvin | 862 | if (is_checked) ui->tableView->showColumn(3); |
863 | else ui->tableView->hideColumn(3); |
||
864 | ui->tableView->resizeColumnsToContents(); |
||
865 | } |
||
68 | pingvin | 866 | |
867 | |||
868 | |||
869 | void ClassEditor::on_action_removeAllClasses(){ // " " |
||
870 | int row; |
||
871 | row = ClassEditor::mymodel->rowCount(); |
||
872 | for (int m=0; m < row; ++m){ |
||
873 | ClassEditor::removeClass(0); |
||
874 | //ClassEditor::mymodel->removeRows(0, row); |
||
875 | } |
||
876 | ClassEditor::mymodel->submitAll(); |
||
877 | ClassEditor::modelForDescription->select(); |
||
878 | } |
||
879 | |||
880 | void ClassEditor::removeClass(int class_row){ // , class_row |
||
881 | QModelIndex index_tmp; |
||
882 | QString tmp_str, filter_str; |
||
883 | index_tmp = ui->tableView->model()->index(class_row, 0); |
||
884 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
||
885 | currClassID = tmp_str; |
||
886 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
887 | filter_str = tr("ClassIdentifer = "); |
||
888 | filter_str.append(tmp_str); |
||
889 | modelForDescription->setFilter(filter_str); // |
||
890 | ClassEditor::on_pushButton_5_clicked(); // |
||
891 | mymodel->removeRow(class_row); // |
||
892 | mymodel->submitAll(); // |
||
893 | ui->tableView->resizeColumnsToContents(); |
||
894 | ui->tableView_2->resizeColumnsToContents(); |
||
895 | |||
896 | } |
||
76 | pingvin | 897 | |
898 | |||
77 | pingvin | 899 | void ClassEditor::on_field_changed(){ // |
76 | pingvin | 900 | ClassEditor::refreshInctance(); |
901 | } |
||
902 | |||
903 | |||
904 | |||
905 | |||
906 | void ClassEditor::refreshInctance(){ // - |
||
907 | |||
908 | QString Inctance_str; // - |
||
909 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
910 | delete model; |
||
911 | delete tableForInstance; |
||
912 | model = new QSqlTableModel(); |
||
913 | tableForInstance = new QTableView(); |
||
914 | model->setTable(Inctance_str); |
||
915 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
78 | pingvin | 916 | model->select(); |
76 | pingvin | 917 | tableForInstance->setModel(model); |
918 | tableForInstance->setWindowTitle(Inctance_str); |
||
919 | tableForInstance->resizeRowsToContents(); |
||
920 | tableForInstance->show(); |
||
921 | |||
922 | } |
||
86 | pingvin | 923 | |
924 | |||
925 | |||
926 | |||
87 | pingvin | 927 | void ClassEditor::on_action_newPointer(){ // - |
86 | pingvin | 928 | ClassEditor::addNewPointer(); |
929 | ClassEditor::modelForPointers->select(); |
||
930 | ui->tableView_3->resizeColumnsToContents(); |
||
931 | |||
932 | } |
||
933 |