Редакция 83 | Редакция 87 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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); |
83 | pingvin | 278 | str_fltr.append(tr(" AND FieldType <> \"pointer\"")); |
62 | pingvin | 279 | |
71 | pingvin | 280 | model->setTable(class_instance); |
281 | //model->setTable(tr("memory")); |
||
72 | pingvin | 282 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
71 | pingvin | 283 | model->select(); |
72 | pingvin | 284 | tableForInstance->setModel(model); |
285 | tableForInstance->resizeColumnsToContents(); |
||
286 | tableForInstance->setWindowTitle(class_instance); |
||
287 | tableForInstance->show(); |
||
71 | pingvin | 288 | |
68 | pingvin | 289 | modelForDescription->setFilter(str_fltr); |
290 | modelForDescription->select(); |
||
69 | pingvin | 291 | ui->tableView_2->resizeColumnsToContents(); |
68 | pingvin | 292 | |
83 | pingvin | 293 | |
294 | str_fltr = tr("ClassIdentifer = "); |
||
295 | modelForPointers->setInctance(class_instance); // - |
||
296 | str_fltr.append(class_indx); |
||
297 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
||
82 | pingvin | 298 | // str_fltr.append( tr(" FieldType = pointer ")); |
83 | pingvin | 299 | |
300 | |||
301 | |||
302 | modelForPointers->setFilter(str_fltr); |
||
82 | pingvin | 303 | modelForPointers->select(); |
304 | ui->tableView_3->setModel(modelForPointers); |
||
83 | pingvin | 305 | ui->tableView_3->resizeColumnsToContents(); |
68 | pingvin | 306 | |
55 | pingvin | 307 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex))); |
62 | pingvin | 308 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
309 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
||
72 | pingvin | 310 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool))); |
65 | pingvin | 311 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
68 | pingvin | 312 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // |
313 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // |
||
314 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // |
||
315 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // |
||
316 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // |
||
73 | pingvin | 317 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // |
318 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // |
||
319 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // |
||
86 | pingvin | 320 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // - |
321 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // - |
||
322 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // |
||
323 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // |
||
324 | |||
325 | |||
42 | pingvin | 326 | } |
327 | |||
45 | pingvin | 328 | |
329 | |||
330 | |||
331 | |||
332 | |||
333 | |||
334 | |||
335 | |||
336 | |||
337 | |||
24 | pingvin | 338 | ClassEditor::~ClassEditor() |
339 | { |
||
340 | delete ui; |
||
72 | pingvin | 341 | delete model; |
342 | delete tableForInstance; |
||
38 | pingvin | 343 | // delete field; |
24 | pingvin | 344 | // delete settdialog; |
345 | } |
||
346 | |||
347 | void ClassEditor::changeEvent(QEvent *e) |
||
348 | { |
||
349 | QMainWindow::changeEvent(e); |
||
350 | switch (e->type()) { |
||
351 | case QEvent::LanguageChange: |
||
352 | ui->retranslateUi(this); |
||
353 | break; |
||
354 | default: |
||
355 | break; |
||
356 | } |
||
357 | } |
||
51 | pingvin | 358 | |
359 | |||
71 | pingvin | 360 | /* |
51 | pingvin | 361 | void ClassEditor::addNewClass(){ |
362 | |||
363 | int row = model->rowCount(); |
||
364 | |||
365 | model->insertRows(row, 1); |
||
54 | pingvin | 366 | model->setData(model->index(row, 1), tr("New class")); // " " |
51 | pingvin | 367 | |
368 | |||
369 | // model->setData(model->index(row, 1), tr(" ")); |
||
370 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
371 | |||
372 | |||
373 | model->submitAll(); |
||
374 | |||
375 | row = model->rowCount(); |
||
376 | QString tmp_str; |
||
377 | int i_tmp; |
||
378 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
||
379 | tmp_str = model->data(model->index(row-1, 0)).toString(); // - |
||
380 | |||
381 | tmp_str.append(tr("_Inctance")); |
||
382 | model->setData(model->index(row-1, 3), tmp_str ); // |
||
383 | |||
384 | model->submitAll(); |
||
385 | mymodel->select(); |
||
386 | |||
387 | |||
388 | } |
||
71 | pingvin | 389 | */ |
51 | pingvin | 390 | |
54 | pingvin | 391 | void ClassEditor::addNewClass_new(){ |
392 | |||
393 | int row = mymodel->rowCount(); |
||
394 | |||
395 | mymodel->insertRows(row, 1); |
||
70 | pingvin | 396 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // " " |
54 | pingvin | 397 | |
70 | pingvin | 398 | |
54 | pingvin | 399 | mymodel->submitAll(); |
400 | row = mymodel->rowCount(); |
||
70 | pingvin | 401 | QString tmp_str1, sql_str; |
54 | pingvin | 402 | int i_tmp1; |
403 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
||
404 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // - |
||
405 | |||
406 | tmp_str1.append(tr("_Inctance")); |
||
70 | pingvin | 407 | SqlTable* tbl; |
408 | tbl = new SqlTable(tmp_str1); // |
||
409 | sql_str = tbl->sqlString(); |
||
410 | bool ok; |
||
411 | |||
412 | ok = sql.createTable(tbl); |
||
413 | |||
414 | if (!ok) { |
||
415 | QMessageBox::critical( // . |
||
416 | this, // . |
||
417 | QObject::tr("Database Error"), // . |
||
418 | sql.lasError()); // . |
||
419 | delete tbl; |
||
420 | mymodel->removeRow(row-1); |
||
421 | mymodel->submitAll(); |
||
422 | mymodel->select(); |
||
423 | ui->tableView_2->resizeRowsToContents(); |
||
424 | return; // |
||
425 | |||
426 | } |
||
427 | |||
428 | delete tbl; |
||
54 | pingvin | 429 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // |
430 | |||
70 | pingvin | 431 | |
432 | |||
54 | pingvin | 433 | // model->setData(model->index(row, 1), tr(" ")); |
434 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
435 | |||
436 | |||
56 | pingvin | 437 | //mymodel->submitAll(); |
54 | pingvin | 438 | |
439 | //row = mymodel->rowCount(); |
||
440 | |||
441 | |||
56 | pingvin | 442 | //mymodel->select(); |
54 | pingvin | 443 | |
444 | |||
445 | } |
||
446 | |||
447 | |||
62 | pingvin | 448 | void ClassEditor::addNewField(){ |
449 | // QSqlRecord rec = mymodel->record(1); |
||
450 | //bool ok; |
||
451 | //ok = rec.isEmpty(); |
||
452 | //QString currientClassID; |
||
453 | //currientClassID = rec.value(1).toString(); |
||
73 | pingvin | 454 | QString Inctance_str; // - |
455 | QString query_str = tr("ALTER TABLE "); |
||
456 | QString db_error; |
||
457 | QSqlQuery q; |
||
72 | pingvin | 458 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
459 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
73 | pingvin | 460 | query_str.append( Inctance_str); |
82 | pingvin | 461 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
73 | pingvin | 462 | bool ok = q.prepare(query_str); |
72 | pingvin | 463 | |
73 | pingvin | 464 | ok = q.exec(); |
465 | if (!ok) { |
||
466 | QMessageBox::critical( // . |
||
467 | this, // . |
||
468 | QObject::tr("Database Error"), // . |
||
469 | q.lastError().text()); // . |
||
470 | |||
471 | return; // |
||
472 | |||
473 | } |
||
474 | |||
62 | pingvin | 475 | int row = modelForDescription->rowCount(); |
476 | modelForDescription->insertRows(row, 1); |
||
81 | pingvin | 477 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
478 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 479 | |
480 | modelForDescription->submitAll(); |
||
73 | pingvin | 481 | |
482 | delete model; |
||
483 | delete tableForInstance; |
||
484 | model = new QSqlTableModel(); |
||
485 | tableForInstance = new QTableView(); |
||
486 | model->setTable(Inctance_str); |
||
487 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
488 | tableForInstance->setModel(model); |
||
489 | tableForInstance->setWindowTitle(Inctance_str); |
||
490 | tableForInstance->show(); |
||
62 | pingvin | 491 | } |
492 | |||
493 | |||
494 | |||
86 | pingvin | 495 | void ClassEditor::addNewPointer(){ // , - |
496 | QString Inctance_str; // - |
||
497 | QString query_str = tr("ALTER TABLE "); |
||
498 | QString db_error; |
||
499 | QSqlQuery q; |
||
500 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
||
501 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
502 | query_str.append( Inctance_str); |
||
503 | query_str.append(tr(" ADD COLUMN `lass-container ID` CHAR(30)")); |
||
504 | bool ok = q.prepare(query_str); |
||
62 | pingvin | 505 | |
86 | pingvin | 506 | ok = q.exec(); |
507 | if (!ok) { |
||
508 | QMessageBox::critical( // . |
||
509 | this, // . |
||
510 | QObject::tr("Database Error"), // . |
||
511 | q.lastError().text()); // . |
||
62 | pingvin | 512 | |
86 | pingvin | 513 | return; // |
62 | pingvin | 514 | |
86 | pingvin | 515 | } |
62 | pingvin | 516 | |
517 | |||
86 | pingvin | 518 | int row = ClassEditor::modelForPointers->rowCount(); |
519 | modelForPointers->insertRows(row, 1); |
||
62 | pingvin | 520 | |
86 | pingvin | 521 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("lass-container ID")), Qt::EditRole); |
522 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
||
523 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
||
524 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
62 | pingvin | 525 | |
86 | pingvin | 526 | |
527 | modelForPointers->submitAll(); |
||
528 | |||
529 | ClassEditor::refreshInctance(); |
||
530 | |||
531 | |||
532 | |||
533 | |||
534 | |||
535 | |||
536 | |||
537 | |||
538 | |||
539 | } |
||
540 | |||
541 | |||
542 | |||
543 | |||
544 | |||
68 | pingvin | 545 | // |
51 | pingvin | 546 | void ClassEditor::on_pushButton_clicked(){ |
54 | pingvin | 547 | //int i; |
548 | //i++; |
||
549 | /////ClassEditor::addNewClass(); |
||
550 | ClassEditor::addNewClass_new(); |
||
551 | mymodel->select(); |
||
552 | //ui->tableView->setModel(mymodel); |
||
553 | |||
51 | pingvin | 554 | } |
54 | pingvin | 555 | |
55 | pingvin | 556 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
557 | int i, row, column; |
||
558 | i++; |
||
559 | row = index.row(); |
||
560 | column = index.column(); |
||
62 | pingvin | 561 | currIndexOfClassesTable = index; |
71 | pingvin | 562 | QModelIndex index_tmp, index_instance; |
563 | QString tmp_str, filter_str, instance_str; |
||
56 | pingvin | 564 | index_tmp = ui->tableView->model()->index(row, 0); |
71 | pingvin | 565 | index_instance = ui->tableView->model()->index(row, 3); |
56 | pingvin | 566 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
71 | pingvin | 567 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
75 | pingvin | 568 | modelForDescription->setInctance(instance_str); // - |
83 | pingvin | 569 | modelForPointers->setInctance(instance_str); |
75 | pingvin | 570 | |
571 | |||
572 | |||
71 | pingvin | 573 | // instance_str.append(tr("_inctance")); |
72 | pingvin | 574 | /* |
575 | Inctance_model.clear(); |
||
576 | Inctance_model.setTable(instance_str); |
||
577 | Inctance_model.select(); |
||
578 | tableForInstance_new.setModel(&Inctance_model); |
||
579 | tableForInstance_new.show(); |
||
580 | */ |
||
581 | // model->clear(); |
||
582 | tableForInstance->close(); |
||
583 | delete model; |
||
584 | delete tableForInstance; |
||
585 | model = new QSqlTableModel(); |
||
586 | tableForInstance = new QTableView(); |
||
587 | model->setTable(instance_str); |
||
588 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
589 | tableForInstance->setModel(model); |
||
71 | pingvin | 590 | |
591 | model->select(); |
||
72 | pingvin | 592 | tableForInstance->setWindowTitle(instance_str); |
593 | tableForInstance->show(); |
||
594 | |||
71 | pingvin | 595 | // tableForInstance.setModel(model); |
72 | pingvin | 596 | tableForInstance->resizeColumnsToContents(); |
71 | pingvin | 597 | |
62 | pingvin | 598 | currClassID = tmp_str; |
599 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
56 | pingvin | 600 | filter_str = tr("ClassIdentifer = "); |
601 | filter_str.append(tmp_str); |
||
83 | pingvin | 602 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
56 | pingvin | 603 | modelForDescription->setFilter(filter_str); |
68 | pingvin | 604 | modelForDescription->select(); |
62 | pingvin | 605 | ui->tableView_2->resizeColumnsToContents(); |
83 | pingvin | 606 | |
607 | filter_str = tr("ClassIdentifer = "); |
||
608 | filter_str.append(tmp_str); |
||
609 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
||
610 | modelForPointers->setFilter(filter_str); |
||
611 | modelForPointers->select(); |
||
612 | ui->tableView_3->resizeColumnsToContents(); |
||
613 | |||
614 | |||
615 | |||
616 | |||
56 | pingvin | 617 | i++; |
55 | pingvin | 618 | } |
54 | pingvin | 619 | |
59 | pingvin | 620 | |
621 | |||
68 | pingvin | 622 | void ClassEditor::on_pushButton_2_clicked(){ // " " |
623 | QModelIndex model_index; |
||
624 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
625 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
626 | QList<int> selectedRows; |
||
627 | selectedRows.clear(); |
||
628 | foreach (model_index, indexes){ // |
||
629 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
59 | pingvin | 630 | |
68 | pingvin | 631 | } |
632 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
633 | |||
634 | |||
635 | for (int m =0; m < selectedRows.size(); ++m){ |
||
636 | |||
637 | ClassEditor::removeClass(selectedRows.at(m)); |
||
638 | |||
639 | |||
640 | |||
641 | } |
||
642 | mymodel->submitAll(); |
||
643 | ClassEditor::modelForDescription->select(); |
||
644 | |||
59 | pingvin | 645 | } |
646 | |||
647 | void ClassEditor::on_pushButton_3_clicked(){ // " " |
||
648 | int i; |
||
649 | i++; |
||
62 | pingvin | 650 | ClassEditor::addNewField(); |
651 | ClassEditor::modelForDescription->select(); |
||
64 | pingvin | 652 | ui->tableView_2->resizeColumnsToContents(); |
59 | pingvin | 653 | } |
68 | pingvin | 654 | |
655 | |||
59 | pingvin | 656 | void ClassEditor::on_pushButton_4_clicked(){ // " " |
69 | pingvin | 657 | // int i; |
62 | pingvin | 658 | QModelIndex model_index; |
63 | pingvin | 659 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
62 | pingvin | 660 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
69 | pingvin | 661 | //QModelIndexList indexes_fo_first_col; // ( ) |
62 | pingvin | 662 | //model_index = mymodel->selec; |
663 | //modelList = ui->tableView->SelectItems; |
||
69 | pingvin | 664 | //i = indexes.size(); |
63 | pingvin | 665 | QList<int> selectedRows; |
69 | pingvin | 666 | //indexes_fo_first_col.clear(); |
667 | /* |
||
67 | pingvin | 668 | foreach (model_index, indexes){ // |
669 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // |
||
670 | |||
671 | } |
||
69 | pingvin | 672 | */ |
63 | pingvin | 673 | selectedRows.clear(); |
674 | foreach (model_index, indexes){ // |
||
73 | pingvin | 675 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
676 | selectedRows.append(model_index.row()); // |
||
677 | } |
||
63 | pingvin | 678 | } |
67 | pingvin | 679 | |
680 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
681 | |||
74 | pingvin | 682 | QString Inctance_str; // - |
683 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
67 | pingvin | 684 | for (int m =0; m < selectedRows.size(); ++m){ |
685 | |||
74 | pingvin | 686 | |
687 | QString query_str; |
||
688 | QString field_name_str; // |
||
689 | QSqlQuery q; |
||
690 | |||
691 | query_str.clear(); |
||
692 | |||
693 | |||
694 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
||
695 | |||
696 | query_str.append(tr("ALTER TABLE ")); |
||
697 | query_str.append(Inctance_str); |
||
698 | query_str.append(tr(" DROP COLUMN `")); |
||
699 | query_str.append(field_name_str); |
||
700 | query_str.append(tr("`")); |
||
701 | q.prepare(query_str); |
||
702 | bool ok = q.exec(); |
||
703 | if (!ok) { |
||
704 | QMessageBox::critical( // . |
||
705 | this, // . |
||
706 | QObject::tr("Database Error"), // . |
||
707 | q.lastError().text()); // . |
||
708 | |||
709 | return; // |
||
710 | |||
711 | } |
||
712 | |||
713 | |||
714 | |||
715 | modelForDescription->removeRow(selectedRows.at(m)); |
||
716 | |||
67 | pingvin | 717 | } |
74 | pingvin | 718 | delete model; |
719 | delete tableForInstance; |
||
720 | model = new QSqlTableModel(); |
||
721 | tableForInstance = new QTableView(); |
||
722 | model->setTable(Inctance_str); |
||
723 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
724 | tableForInstance->setModel(model); |
||
725 | tableForInstance->setWindowTitle(Inctance_str); |
||
726 | tableForInstance->show(); |
||
69 | pingvin | 727 | //i = selectedRows.size(); |
63 | pingvin | 728 | |
69 | pingvin | 729 | //if (i > 0) model_index = indexes.at(0); |
59 | pingvin | 730 | } |
62 | pingvin | 731 | |
732 | |||
63 | pingvin | 733 | void ClassEditor::on_pushButton_5_clicked(){ // " " |
734 | int row; |
||
735 | row = ClassEditor::modelForDescription->rowCount(); |
||
736 | ClassEditor::modelForDescription->removeRows(0, row); |
||
737 | ClassEditor::modelForDescription->submitAll(); |
||
738 | } |
||
739 | |||
62 | pingvin | 740 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
75 | pingvin | 741 | |
62 | pingvin | 742 | int i; |
743 | i++; |
||
744 | ui->tableView->resizeColumnsToContents(); |
||
75 | pingvin | 745 | |
746 | |||
747 | |||
748 | |||
749 | |||
62 | pingvin | 750 | } |
751 | |||
752 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
||
753 | ui->tableView_2->resizeColumnsToContents(); |
||
75 | pingvin | 754 | |
755 | /* |
||
756 | QString instance_str; |
||
757 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
758 | tableForInstance->close(); |
||
759 | delete model; |
||
760 | delete tableForInstance; |
||
761 | model = new QSqlTableModel(); |
||
762 | tableForInstance = new QTableView(); |
||
763 | model->setTable(instance_str); |
||
764 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
765 | tableForInstance->setModel(model); |
||
766 | |||
767 | model->select(); |
||
768 | tableForInstance->setWindowTitle(instance_str); |
||
769 | tableForInstance->show(); |
||
770 | */ |
||
62 | pingvin | 771 | } |
65 | pingvin | 772 | |
773 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // " ID" |
||
774 | if (is_checked) ui->tableView->showColumn(0); |
||
775 | else ui->tableView->hideColumn(0); |
||
776 | ui->tableView->resizeColumnsToContents(); |
||
777 | } |
||
778 | |||
779 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // " " |
||
780 | if (is_checked) ui->tableView->showColumn(2); |
||
781 | else ui->tableView->hideColumn(2); |
||
782 | ui->tableView->resizeColumnsToContents(); |
||
783 | } |
||
784 | |||
68 | pingvin | 785 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // " " |
65 | pingvin | 786 | if (is_checked) ui->tableView->showColumn(3); |
787 | else ui->tableView->hideColumn(3); |
||
788 | ui->tableView->resizeColumnsToContents(); |
||
789 | } |
||
68 | pingvin | 790 | |
791 | |||
792 | |||
793 | void ClassEditor::on_action_removeAllClasses(){ // " " |
||
794 | int row; |
||
795 | row = ClassEditor::mymodel->rowCount(); |
||
796 | for (int m=0; m < row; ++m){ |
||
797 | ClassEditor::removeClass(0); |
||
798 | //ClassEditor::mymodel->removeRows(0, row); |
||
799 | } |
||
800 | ClassEditor::mymodel->submitAll(); |
||
801 | ClassEditor::modelForDescription->select(); |
||
802 | } |
||
803 | |||
804 | void ClassEditor::removeClass(int class_row){ // , class_row |
||
805 | QModelIndex index_tmp; |
||
806 | QString tmp_str, filter_str; |
||
807 | index_tmp = ui->tableView->model()->index(class_row, 0); |
||
808 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
||
809 | currClassID = tmp_str; |
||
810 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
811 | filter_str = tr("ClassIdentifer = "); |
||
812 | filter_str.append(tmp_str); |
||
813 | modelForDescription->setFilter(filter_str); // |
||
814 | ClassEditor::on_pushButton_5_clicked(); // |
||
815 | mymodel->removeRow(class_row); // |
||
816 | mymodel->submitAll(); // |
||
817 | ui->tableView->resizeColumnsToContents(); |
||
818 | ui->tableView_2->resizeColumnsToContents(); |
||
819 | |||
820 | } |
||
76 | pingvin | 821 | |
822 | |||
77 | pingvin | 823 | void ClassEditor::on_field_changed(){ // |
76 | pingvin | 824 | ClassEditor::refreshInctance(); |
825 | } |
||
826 | |||
827 | |||
828 | |||
829 | |||
830 | void ClassEditor::refreshInctance(){ // - |
||
831 | |||
832 | QString Inctance_str; // - |
||
833 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
||
834 | delete model; |
||
835 | delete tableForInstance; |
||
836 | model = new QSqlTableModel(); |
||
837 | tableForInstance = new QTableView(); |
||
838 | model->setTable(Inctance_str); |
||
839 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
78 | pingvin | 840 | model->select(); |
76 | pingvin | 841 | tableForInstance->setModel(model); |
842 | tableForInstance->setWindowTitle(Inctance_str); |
||
843 | tableForInstance->resizeRowsToContents(); |
||
844 | tableForInstance->show(); |
||
845 | |||
846 | } |
||
86 | pingvin | 847 | |
848 | |||
849 | |||
850 | |||
851 | void ClassEditor::on_action_newPointer(){ |
||
852 | ClassEditor::addNewPointer(); |
||
853 | ClassEditor::modelForPointers->select(); |
||
854 | ui->tableView_3->resizeColumnsToContents(); |
||
855 | |||
856 | } |
||
857 |