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