Хранилища Subversion OpenInventory

Редакция

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