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