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