Редакция 71 | Редакция 73 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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())); // |
||
291 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // |
||
72 | pingvin | 292 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // |
42 | pingvin | 293 | } |
294 | |||
45 | pingvin | 295 | |
296 | |||
297 | |||
298 | |||
299 | |||
300 | |||
301 | |||
302 | |||
303 | |||
304 | |||
24 | pingvin | 305 | ClassEditor::~ClassEditor() |
306 | { |
||
307 | delete ui; |
||
72 | pingvin | 308 | delete model; |
309 | delete tableForInstance; |
||
38 | pingvin | 310 | // delete field; |
24 | pingvin | 311 | // delete settdialog; |
312 | } |
||
313 | |||
314 | void ClassEditor::changeEvent(QEvent *e) |
||
315 | { |
||
316 | QMainWindow::changeEvent(e); |
||
317 | switch (e->type()) { |
||
318 | case QEvent::LanguageChange: |
||
319 | ui->retranslateUi(this); |
||
320 | break; |
||
321 | default: |
||
322 | break; |
||
323 | } |
||
324 | } |
||
51 | pingvin | 325 | |
326 | |||
71 | pingvin | 327 | /* |
51 | pingvin | 328 | void ClassEditor::addNewClass(){ |
329 | |||
330 | int row = model->rowCount(); |
||
331 | |||
332 | model->insertRows(row, 1); |
||
54 | pingvin | 333 | model->setData(model->index(row, 1), tr("New class")); // " " |
51 | pingvin | 334 | |
335 | |||
336 | // model->setData(model->index(row, 1), tr(" ")); |
||
337 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
338 | |||
339 | |||
340 | model->submitAll(); |
||
341 | |||
342 | row = model->rowCount(); |
||
343 | QString tmp_str; |
||
344 | int i_tmp; |
||
345 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
||
346 | tmp_str = model->data(model->index(row-1, 0)).toString(); // - |
||
347 | |||
348 | tmp_str.append(tr("_Inctance")); |
||
349 | model->setData(model->index(row-1, 3), tmp_str ); // |
||
350 | |||
351 | model->submitAll(); |
||
352 | mymodel->select(); |
||
353 | |||
354 | |||
355 | } |
||
71 | pingvin | 356 | */ |
51 | pingvin | 357 | |
54 | pingvin | 358 | void ClassEditor::addNewClass_new(){ |
359 | |||
360 | int row = mymodel->rowCount(); |
||
361 | |||
362 | mymodel->insertRows(row, 1); |
||
70 | pingvin | 363 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // " " |
54 | pingvin | 364 | |
70 | pingvin | 365 | |
54 | pingvin | 366 | mymodel->submitAll(); |
367 | row = mymodel->rowCount(); |
||
70 | pingvin | 368 | QString tmp_str1, sql_str; |
54 | pingvin | 369 | int i_tmp1; |
370 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
||
371 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // - |
||
372 | |||
373 | tmp_str1.append(tr("_Inctance")); |
||
70 | pingvin | 374 | SqlTable* tbl; |
375 | tbl = new SqlTable(tmp_str1); // |
||
376 | sql_str = tbl->sqlString(); |
||
377 | bool ok; |
||
378 | |||
379 | ok = sql.createTable(tbl); |
||
380 | |||
381 | if (!ok) { |
||
382 | QMessageBox::critical( // . |
||
383 | this, // . |
||
384 | QObject::tr("Database Error"), // . |
||
385 | sql.lasError()); // . |
||
386 | delete tbl; |
||
387 | mymodel->removeRow(row-1); |
||
388 | mymodel->submitAll(); |
||
389 | mymodel->select(); |
||
390 | ui->tableView_2->resizeRowsToContents(); |
||
391 | return; // |
||
392 | |||
393 | } |
||
394 | |||
395 | delete tbl; |
||
54 | pingvin | 396 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // |
397 | |||
70 | pingvin | 398 | |
399 | |||
54 | pingvin | 400 | // model->setData(model->index(row, 1), tr(" ")); |
401 | // model->setData(model->index(row, 2) , tr(" , 1")); |
||
402 | |||
403 | |||
56 | pingvin | 404 | //mymodel->submitAll(); |
54 | pingvin | 405 | |
406 | //row = mymodel->rowCount(); |
||
407 | |||
408 | |||
56 | pingvin | 409 | //mymodel->select(); |
54 | pingvin | 410 | |
411 | |||
412 | } |
||
413 | |||
414 | |||
62 | pingvin | 415 | void ClassEditor::addNewField(){ |
416 | // QSqlRecord rec = mymodel->record(1); |
||
417 | //bool ok; |
||
418 | //ok = rec.isEmpty(); |
||
419 | //QString currientClassID; |
||
420 | //currientClassID = rec.value(1).toString(); |
||
72 | pingvin | 421 | QString Inctance_str; |
422 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
||
423 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
||
424 | |||
62 | pingvin | 425 | int row = modelForDescription->rowCount(); |
426 | modelForDescription->insertRows(row, 1); |
||
427 | modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
||
428 | modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
||
429 | |||
430 | modelForDescription->submitAll(); |
||
431 | } |
||
432 | |||
433 | |||
434 | |||
435 | |||
436 | |||
437 | |||
438 | |||
439 | |||
440 | |||
441 | |||
68 | pingvin | 442 | // |
51 | pingvin | 443 | void ClassEditor::on_pushButton_clicked(){ |
54 | pingvin | 444 | //int i; |
445 | //i++; |
||
446 | /////ClassEditor::addNewClass(); |
||
447 | ClassEditor::addNewClass_new(); |
||
448 | mymodel->select(); |
||
449 | //ui->tableView->setModel(mymodel); |
||
450 | |||
51 | pingvin | 451 | } |
54 | pingvin | 452 | |
55 | pingvin | 453 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
454 | int i, row, column; |
||
455 | i++; |
||
456 | row = index.row(); |
||
457 | column = index.column(); |
||
62 | pingvin | 458 | currIndexOfClassesTable = index; |
71 | pingvin | 459 | QModelIndex index_tmp, index_instance; |
460 | QString tmp_str, filter_str, instance_str; |
||
56 | pingvin | 461 | index_tmp = ui->tableView->model()->index(row, 0); |
71 | pingvin | 462 | index_instance = ui->tableView->model()->index(row, 3); |
56 | pingvin | 463 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
71 | pingvin | 464 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
465 | // instance_str.append(tr("_inctance")); |
||
72 | pingvin | 466 | /* |
467 | Inctance_model.clear(); |
||
468 | Inctance_model.setTable(instance_str); |
||
469 | Inctance_model.select(); |
||
470 | tableForInstance_new.setModel(&Inctance_model); |
||
471 | tableForInstance_new.show(); |
||
472 | */ |
||
473 | // model->clear(); |
||
474 | tableForInstance->close(); |
||
475 | delete model; |
||
476 | delete tableForInstance; |
||
477 | model = new QSqlTableModel(); |
||
478 | tableForInstance = new QTableView(); |
||
479 | model->setTable(instance_str); |
||
480 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
481 | tableForInstance->setModel(model); |
||
71 | pingvin | 482 | |
483 | model->select(); |
||
72 | pingvin | 484 | tableForInstance->setWindowTitle(instance_str); |
485 | tableForInstance->show(); |
||
486 | |||
71 | pingvin | 487 | // tableForInstance.setModel(model); |
72 | pingvin | 488 | tableForInstance->resizeColumnsToContents(); |
71 | pingvin | 489 | |
62 | pingvin | 490 | currClassID = tmp_str; |
491 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
56 | pingvin | 492 | filter_str = tr("ClassIdentifer = "); |
493 | filter_str.append(tmp_str); |
||
494 | modelForDescription->setFilter(filter_str); |
||
68 | pingvin | 495 | modelForDescription->select(); |
62 | pingvin | 496 | ui->tableView_2->resizeColumnsToContents(); |
56 | pingvin | 497 | i++; |
55 | pingvin | 498 | } |
54 | pingvin | 499 | |
59 | pingvin | 500 | |
501 | |||
68 | pingvin | 502 | void ClassEditor::on_pushButton_2_clicked(){ // " " |
503 | QModelIndex model_index; |
||
504 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
505 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
506 | QList<int> selectedRows; |
||
507 | selectedRows.clear(); |
||
508 | foreach (model_index, indexes){ // |
||
509 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
59 | pingvin | 510 | |
68 | pingvin | 511 | } |
512 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
513 | |||
514 | |||
515 | for (int m =0; m < selectedRows.size(); ++m){ |
||
516 | |||
517 | ClassEditor::removeClass(selectedRows.at(m)); |
||
518 | |||
519 | |||
520 | |||
521 | } |
||
522 | mymodel->submitAll(); |
||
523 | ClassEditor::modelForDescription->select(); |
||
524 | |||
59 | pingvin | 525 | } |
526 | |||
527 | void ClassEditor::on_pushButton_3_clicked(){ // " " |
||
528 | int i; |
||
529 | i++; |
||
62 | pingvin | 530 | ClassEditor::addNewField(); |
531 | ClassEditor::modelForDescription->select(); |
||
64 | pingvin | 532 | ui->tableView_2->resizeColumnsToContents(); |
59 | pingvin | 533 | } |
68 | pingvin | 534 | |
535 | |||
59 | pingvin | 536 | void ClassEditor::on_pushButton_4_clicked(){ // " " |
69 | pingvin | 537 | // int i; |
62 | pingvin | 538 | QModelIndex model_index; |
63 | pingvin | 539 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
62 | pingvin | 540 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
69 | pingvin | 541 | //QModelIndexList indexes_fo_first_col; // ( ) |
62 | pingvin | 542 | //model_index = mymodel->selec; |
543 | //modelList = ui->tableView->SelectItems; |
||
69 | pingvin | 544 | //i = indexes.size(); |
63 | pingvin | 545 | QList<int> selectedRows; |
69 | pingvin | 546 | //indexes_fo_first_col.clear(); |
547 | /* |
||
67 | pingvin | 548 | foreach (model_index, indexes){ // |
549 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // |
||
550 | |||
551 | } |
||
69 | pingvin | 552 | */ |
63 | pingvin | 553 | selectedRows.clear(); |
554 | foreach (model_index, indexes){ // |
||
67 | pingvin | 555 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
62 | pingvin | 556 | |
63 | pingvin | 557 | } |
67 | pingvin | 558 | |
559 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
560 | |||
561 | |||
562 | for (int m =0; m < selectedRows.size(); ++m){ |
||
563 | |||
564 | modelForDescription->removeRow(selectedRows.at(m)); |
||
565 | } |
||
566 | |||
69 | pingvin | 567 | //i = selectedRows.size(); |
63 | pingvin | 568 | |
69 | pingvin | 569 | //if (i > 0) model_index = indexes.at(0); |
59 | pingvin | 570 | } |
62 | pingvin | 571 | |
572 | |||
63 | pingvin | 573 | void ClassEditor::on_pushButton_5_clicked(){ // " " |
574 | int row; |
||
575 | row = ClassEditor::modelForDescription->rowCount(); |
||
576 | ClassEditor::modelForDescription->removeRows(0, row); |
||
577 | ClassEditor::modelForDescription->submitAll(); |
||
578 | } |
||
579 | |||
62 | pingvin | 580 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
581 | int i; |
||
582 | i++; |
||
583 | ui->tableView->resizeColumnsToContents(); |
||
584 | } |
||
585 | |||
586 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
||
587 | ui->tableView_2->resizeColumnsToContents(); |
||
588 | } |
||
65 | pingvin | 589 | |
590 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // " ID" |
||
591 | if (is_checked) ui->tableView->showColumn(0); |
||
592 | else ui->tableView->hideColumn(0); |
||
593 | ui->tableView->resizeColumnsToContents(); |
||
594 | } |
||
595 | |||
596 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // " " |
||
597 | if (is_checked) ui->tableView->showColumn(2); |
||
598 | else ui->tableView->hideColumn(2); |
||
599 | ui->tableView->resizeColumnsToContents(); |
||
600 | } |
||
601 | |||
68 | pingvin | 602 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // " " |
65 | pingvin | 603 | if (is_checked) ui->tableView->showColumn(3); |
604 | else ui->tableView->hideColumn(3); |
||
605 | ui->tableView->resizeColumnsToContents(); |
||
606 | } |
||
68 | pingvin | 607 | |
608 | |||
609 | |||
610 | void ClassEditor::on_action_removeAllClasses(){ // " " |
||
611 | int row; |
||
612 | row = ClassEditor::mymodel->rowCount(); |
||
613 | for (int m=0; m < row; ++m){ |
||
614 | ClassEditor::removeClass(0); |
||
615 | //ClassEditor::mymodel->removeRows(0, row); |
||
616 | } |
||
617 | ClassEditor::mymodel->submitAll(); |
||
618 | ClassEditor::modelForDescription->select(); |
||
619 | } |
||
620 | |||
621 | void ClassEditor::removeClass(int class_row){ // , class_row |
||
622 | QModelIndex index_tmp; |
||
623 | QString tmp_str, filter_str; |
||
624 | index_tmp = ui->tableView->model()->index(class_row, 0); |
||
625 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
||
626 | currClassID = tmp_str; |
||
627 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString()); |
||
628 | filter_str = tr("ClassIdentifer = "); |
||
629 | filter_str.append(tmp_str); |
||
630 | modelForDescription->setFilter(filter_str); // |
||
631 | ClassEditor::on_pushButton_5_clicked(); // |
||
632 | mymodel->removeRow(class_row); // |
||
633 | mymodel->submitAll(); // |
||
634 | ui->tableView->resizeColumnsToContents(); |
||
635 | ui->tableView_2->resizeColumnsToContents(); |
||
636 | |||
637 | } |