Хранилища Subversion OpenInventory

Редакция

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