Хранилища Subversion OpenInventory

Редакция

Редакция 64 | Редакция 67 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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
 
178
/////////////////model = new QSqlTableModel(this);
50 pingvin 179
mymodel = new MyModel(this);
61 pingvin 180
//modelForDescription = new QSqlTableModel(this);
181
modelForDescription = new ModelForDescriptionTable(this);
50 pingvin 182
 
61 pingvin 183
 
56 pingvin 184
/////////////////model->setTable(tr("ListOfClasses"));
50 pingvin 185
mymodel->setTable(tr("ListOfClasses"));
56 pingvin 186
modelForDescription->setTable(tr("DescriptionOfClasses"));
187
modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange);
50 pingvin 188
 
45 pingvin 189
/////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
50 pingvin 190
 
191
/*
45 pingvin 192
model->setEditStrategy(QSqlTableModel::OnFieldChange);
50 pingvin 193
mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
194
*/
195
 
196
 
56 pingvin 197
//////////////////model->setSort(0, Qt::AscendingOrder);
50 pingvin 198
mymodel->setSort(0, Qt::AscendingOrder);
56 pingvin 199
modelForDescription->setSort(0, Qt::AscendingOrder);
50 pingvin 200
 
56 pingvin 201
 
45 pingvin 202
//       model->setFilter(tr("__ = '7' and _ = 'i09090909'"));
56 pingvin 203
////////////////////model->select();
50 pingvin 204
mymodel->select();
56 pingvin 205
modelForDescription->setFilter(tr("ClassIdentifer = 1"));
206
modelForDescription->select();
50 pingvin 207
 
56 pingvin 208
 
209
/////////////////////////model->setHeaderData(1, Qt::Horizontal, tr(" "));
50 pingvin 210
mymodel->setHeaderData(1, Qt::Horizontal, tr(" "));
211
 
212
 
213
 
56 pingvin 214
////////////////////////model->setHeaderData(2, Qt::Horizontal, tr(" "));
50 pingvin 215
mymodel->setHeaderData(2, Qt::Horizontal, tr(" "));
60 pingvin 216
mymodel->setHeaderData(4, Qt::Horizontal, tr(""));
50 pingvin 217
 
65 pingvin 218
 
50 pingvin 219
//ui->tableView->setModel(model);
220
ui->tableView->setModel(mymodel);
56 pingvin 221
//tableForDescription = new QTableView();
222
ui->tableView_2->setModel(modelForDescription);
223
ui->tableView_2->setAlternatingRowColors(true);
224
ui->tableView_2->resizeColumnsToContents();
225
//tableForDescription->show();
50 pingvin 226
 
227
 
45 pingvin 228
ui->tableView->setAlternatingRowColors(true);
229
ui->tableView->resizeColumnsToContents();
65 pingvin 230
 
60 pingvin 231
ui->tableView->hideColumn(0);
55 pingvin 232
ui->tableView->hideColumn(3);
60 pingvin 233
ui->tableView->hideColumn(2);
45 pingvin 234
 
65 pingvin 235
/*
62 pingvin 236
ui->tableView_2->hideColumn(0);
237
ui->tableView_2->hideColumn(5);
238
ui->tableView_2->hideColumn(2);
65 pingvin 239
*/
240
ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
45 pingvin 241
 
62 pingvin 242
currIndexOfClassesTable = modelForDescription->index(0, 1);
243
QModelIndex index_temp;
244
 
245
currClassID = mymodel->data(mymodel->index(0,0)).toString();
246
QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
247
 
248
QModelIndex topLeft;
249
QModelIndex bottomRight;
250
 
251
     topLeft = mymodel->index(0, 0, QModelIndex());
252
     bottomRight = mymodel->index(0, 1, QModelIndex());
253
 
254
QItemSelection selection(topLeft, bottomRight);
255
selectionModel->select(selection, QItemSelectionModel::Select);
256
 
257
 
258
 
55 pingvin 259
//connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
62 pingvin 260
connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex)));
261
connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex)));
65 pingvin 262
connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
263
connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool)));
264
connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool)));
265
connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool)));
42 pingvin 266
}
267
 
45 pingvin 268
 
269
 
270
 
271
 
272
 
273
 
274
 
275
 
276
 
277
 
24 pingvin 278
ClassEditor::~ClassEditor()
279
{
280
    delete ui;
38 pingvin 281
 //    delete field;
24 pingvin 282
   // delete settdialog;
283
}
284
 
285
void ClassEditor::changeEvent(QEvent *e)
286
{
287
    QMainWindow::changeEvent(e);
288
    switch (e->type()) {
289
    case QEvent::LanguageChange:
290
        ui->retranslateUi(this);
291
        break;
292
    default:
293
        break;
294
    }
295
}
51 pingvin 296
 
297
 
298
 
299
void  ClassEditor::addNewClass(){
300
 
301
    int row = model->rowCount();
302
 
303
    model->insertRows(row, 1);
54 pingvin 304
    model->setData(model->index(row, 1), tr("New class")); //     " "
51 pingvin 305
 
306
 
307
    // model->setData(model->index(row, 1), tr("   "));
308
    // model->setData(model->index(row, 2) , tr("  ,    1"));
309
 
310
 
311
    model->submitAll();
312
 
313
    row = model->rowCount();
314
    QString tmp_str;
315
    int i_tmp;
316
    i_tmp = model->data(model->index(row-1, 0)).toInt();
317
    tmp_str = model->data(model->index(row-1, 0)).toString(); //   -  
318
 
319
    tmp_str.append(tr("_Inctance"));
320
    model->setData(model->index(row-1, 3), tmp_str );  //     
321
 
322
    model->submitAll();
323
    mymodel->select();
324
 
325
 
326
}
327
 
328
 
54 pingvin 329
void  ClassEditor::addNewClass_new(){
330
 
331
    int row = mymodel->rowCount();
332
 
333
    mymodel->insertRows(row, 1);
334
    mymodel->setData(mymodel->index(row, 1), QVariant(tr("New classs")), Qt::EditRole); //     " "
335
 
336
    mymodel->submitAll();
337
 
338
    row = mymodel->rowCount();
339
    QString tmp_str1;
340
    int i_tmp1;
341
    i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt();
342
    tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); //   -  
343
 
344
    tmp_str1.append(tr("_Inctance"));
345
    mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole);  //     
346
 
347
    // model->setData(model->index(row, 1), tr("   "));
348
    // model->setData(model->index(row, 2) , tr("  ,    1"));
349
 
350
 
56 pingvin 351
    //mymodel->submitAll();
54 pingvin 352
 
353
    //row = mymodel->rowCount();
354
 
355
 
56 pingvin 356
  //mymodel->select();
54 pingvin 357
 
358
 
359
}
360
 
361
 
62 pingvin 362
void ClassEditor::addNewField(){
363
    // QSqlRecord rec = mymodel->record(1);
364
     //bool ok;
365
     //ok = rec.isEmpty();
366
     //QString currientClassID;
367
     //currientClassID = rec.value(1).toString();
368
    int row = modelForDescription->rowCount();
369
    modelForDescription->insertRows(row, 1);
370
    modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole);
371
    modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole);
372
 
373
    modelForDescription->submitAll();
374
}
375
 
376
 
377
 
378
 
379
 
380
 
381
 
382
 
383
 
384
 
385
 
51 pingvin 386
void ClassEditor::on_pushButton_clicked(){
54 pingvin 387
//int i;
388
//i++;
389
/////ClassEditor::addNewClass();
390
ClassEditor::addNewClass_new();
391
 mymodel->select();
392
//ui->tableView->setModel(mymodel);
393
 
51 pingvin 394
}
54 pingvin 395
 
55 pingvin 396
void ClassEditor::on_tableView_clicked(const QModelIndex & index ){
397
    int i, row, column;
398
    i++;
399
    row = index.row();
400
    column = index.column();
62 pingvin 401
    currIndexOfClassesTable = index;
402
    QModelIndex index_tmp;
56 pingvin 403
    QString tmp_str, filter_str;
404
   index_tmp = ui->tableView->model()->index(row, 0);
405
   tmp_str = ui->tableView->model()->data(index_tmp).toString();
62 pingvin 406
   currClassID = tmp_str;
407
  // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
56 pingvin 408
   filter_str = tr("ClassIdentifer = ");
409
   filter_str.append(tmp_str);
410
   modelForDescription->setFilter(filter_str);
62 pingvin 411
   ui->tableView_2->resizeColumnsToContents();
56 pingvin 412
   i++;
55 pingvin 413
}
54 pingvin 414
 
59 pingvin 415
 
416
 
417
void ClassEditor::on_pushButton_2_clicked(){
418
    int i;
419
    i++;
420
 
421
}
422
 
423
void ClassEditor::on_pushButton_3_clicked(){         //    " "
424
    int i;
425
    i++;
62 pingvin 426
    ClassEditor::addNewField();
427
    ClassEditor::modelForDescription->select();
64 pingvin 428
    ui->tableView_2->resizeColumnsToContents();
59 pingvin 429
}
430
void ClassEditor::on_pushButton_4_clicked(){         //    " "
431
    int i;
432
    i++;
62 pingvin 433
    QModelIndex model_index;
63 pingvin 434
    QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel();
62 pingvin 435
    QModelIndexList indexes = selectionModel->selectedIndexes();
436
    //model_index = mymodel->selec;
437
    //modelList = ui->tableView->SelectItems;
438
    i = indexes.size();
63 pingvin 439
    QList<int> selectedRows;
440
    selectedRows.clear();
441
    foreach (model_index, indexes){ //    
442
        if (!selectedRows.contains(model_index.row()))  selectedRows.append(model_index.row());
62 pingvin 443
 
63 pingvin 444
    }
445
    i = selectedRows.size();
446
 
62 pingvin 447
    if (i > 0) model_index = indexes.at(0);
448
    i++;
59 pingvin 449
}
62 pingvin 450
 
451
 
63 pingvin 452
void ClassEditor::on_pushButton_5_clicked(){         //    "  "
453
int row;
454
row = ClassEditor::modelForDescription->rowCount();
455
ClassEditor::modelForDescription->removeRows(0, row);
456
ClassEditor::modelForDescription->submitAll();
457
}
458
 
62 pingvin 459
void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){
460
int i;
461
i++;
462
ui->tableView->resizeColumnsToContents();
463
}
464
 
465
void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){
466
    ui->tableView_2->resizeColumnsToContents();
467
}
65 pingvin 468
 
469
void ClassEditor::on_action_ID_triggered(bool is_checked){          //     " ID"
470
if (is_checked) ui->tableView->showColumn(0);
471
else ui->tableView->hideColumn(0);
472
ui->tableView->resizeColumnsToContents();
473
}
474
 
475
void ClassEditor::on_action_showAlias_triggered(bool is_checked){     //     " "
476
    if (is_checked) ui->tableView->showColumn(2);
477
    else ui->tableView->hideColumn(2);
478
    ui->tableView->resizeColumnsToContents();
479
}
480
 
481
void ClassEditor::on_action_showInstance_triggered(bool is_checked){
482
    if (is_checked) ui->tableView->showColumn(3);
483
    else ui->tableView->hideColumn(3);
484
    ui->tableView->resizeColumnsToContents();
485
}