Хранилища Subversion OpenInventory

Редакция

Редакция 61 | Редакция 63 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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
 
218
//ui->tableView->setModel(model);
219
ui->tableView->setModel(mymodel);
56 pingvin 220
//tableForDescription = new QTableView();
221
ui->tableView_2->setModel(modelForDescription);
222
ui->tableView_2->setAlternatingRowColors(true);
223
ui->tableView_2->resizeColumnsToContents();
224
//tableForDescription->show();
50 pingvin 225
 
226
 
45 pingvin 227
ui->tableView->setAlternatingRowColors(true);
228
ui->tableView->resizeColumnsToContents();
60 pingvin 229
ui->tableView->hideColumn(0);
55 pingvin 230
ui->tableView->hideColumn(3);
60 pingvin 231
ui->tableView->hideColumn(2);
45 pingvin 232
 
62 pingvin 233
ui->tableView_2->hideColumn(0);
234
ui->tableView_2->hideColumn(5);
235
ui->tableView_2->hideColumn(2);
45 pingvin 236
 
62 pingvin 237
currIndexOfClassesTable = modelForDescription->index(0, 1);
238
QModelIndex index_temp;
239
 
240
currClassID = mymodel->data(mymodel->index(0,0)).toString();
241
QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
242
 
243
QModelIndex topLeft;
244
QModelIndex bottomRight;
245
 
246
     topLeft = mymodel->index(0, 0, QModelIndex());
247
     bottomRight = mymodel->index(0, 1, QModelIndex());
248
 
249
QItemSelection selection(topLeft, bottomRight);
250
selectionModel->select(selection, QItemSelectionModel::Select);
251
 
252
 
253
 
55 pingvin 254
//connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
62 pingvin 255
connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex)));
256
connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex)));
257
 
42 pingvin 258
}
259
 
45 pingvin 260
 
261
 
262
 
263
 
264
 
265
 
266
 
267
 
268
 
269
 
24 pingvin 270
ClassEditor::~ClassEditor()
271
{
272
    delete ui;
38 pingvin 273
 //    delete field;
24 pingvin 274
   // delete settdialog;
275
}
276
 
277
void ClassEditor::changeEvent(QEvent *e)
278
{
279
    QMainWindow::changeEvent(e);
280
    switch (e->type()) {
281
    case QEvent::LanguageChange:
282
        ui->retranslateUi(this);
283
        break;
284
    default:
285
        break;
286
    }
287
}
51 pingvin 288
 
289
 
290
 
291
void  ClassEditor::addNewClass(){
292
 
293
    int row = model->rowCount();
294
 
295
    model->insertRows(row, 1);
54 pingvin 296
    model->setData(model->index(row, 1), tr("New class")); //     " "
51 pingvin 297
 
298
 
299
    // model->setData(model->index(row, 1), tr("   "));
300
    // model->setData(model->index(row, 2) , tr("  ,    1"));
301
 
302
 
303
    model->submitAll();
304
 
305
    row = model->rowCount();
306
    QString tmp_str;
307
    int i_tmp;
308
    i_tmp = model->data(model->index(row-1, 0)).toInt();
309
    tmp_str = model->data(model->index(row-1, 0)).toString(); //   -  
310
 
311
    tmp_str.append(tr("_Inctance"));
312
    model->setData(model->index(row-1, 3), tmp_str );  //     
313
 
314
    model->submitAll();
315
    mymodel->select();
316
 
317
 
318
}
319
 
320
 
54 pingvin 321
void  ClassEditor::addNewClass_new(){
322
 
323
    int row = mymodel->rowCount();
324
 
325
    mymodel->insertRows(row, 1);
326
    mymodel->setData(mymodel->index(row, 1), QVariant(tr("New classs")), Qt::EditRole); //     " "
327
 
328
    mymodel->submitAll();
329
 
330
    row = mymodel->rowCount();
331
    QString tmp_str1;
332
    int i_tmp1;
333
    i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt();
334
    tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); //   -  
335
 
336
    tmp_str1.append(tr("_Inctance"));
337
    mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole);  //     
338
 
339
    // model->setData(model->index(row, 1), tr("   "));
340
    // model->setData(model->index(row, 2) , tr("  ,    1"));
341
 
342
 
56 pingvin 343
    //mymodel->submitAll();
54 pingvin 344
 
345
    //row = mymodel->rowCount();
346
 
347
 
56 pingvin 348
  //mymodel->select();
54 pingvin 349
 
350
 
351
}
352
 
353
 
62 pingvin 354
void ClassEditor::addNewField(){
355
    // QSqlRecord rec = mymodel->record(1);
356
     //bool ok;
357
     //ok = rec.isEmpty();
358
     //QString currientClassID;
359
     //currientClassID = rec.value(1).toString();
360
    int row = modelForDescription->rowCount();
361
    modelForDescription->insertRows(row, 1);
362
    modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole);
363
    modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole);
364
 
365
    modelForDescription->submitAll();
366
}
367
 
368
 
369
 
370
 
371
 
372
 
373
 
374
 
375
 
376
 
377
 
51 pingvin 378
void ClassEditor::on_pushButton_clicked(){
54 pingvin 379
//int i;
380
//i++;
381
/////ClassEditor::addNewClass();
382
ClassEditor::addNewClass_new();
383
 mymodel->select();
384
//ui->tableView->setModel(mymodel);
385
 
51 pingvin 386
}
54 pingvin 387
 
55 pingvin 388
void ClassEditor::on_tableView_clicked(const QModelIndex & index ){
389
    int i, row, column;
390
    i++;
391
    row = index.row();
392
    column = index.column();
62 pingvin 393
    currIndexOfClassesTable = index;
394
    QModelIndex index_tmp;
56 pingvin 395
    QString tmp_str, filter_str;
396
   index_tmp = ui->tableView->model()->index(row, 0);
397
   tmp_str = ui->tableView->model()->data(index_tmp).toString();
62 pingvin 398
   currClassID = tmp_str;
399
  // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
56 pingvin 400
   filter_str = tr("ClassIdentifer = ");
401
   filter_str.append(tmp_str);
402
   modelForDescription->setFilter(filter_str);
62 pingvin 403
   ui->tableView_2->resizeColumnsToContents();
56 pingvin 404
   i++;
55 pingvin 405
}
54 pingvin 406
 
59 pingvin 407
 
408
 
409
void ClassEditor::on_pushButton_2_clicked(){
410
    int i;
411
    i++;
412
 
413
}
414
 
415
void ClassEditor::on_pushButton_3_clicked(){         //    " "
416
    int i;
417
    i++;
62 pingvin 418
    ClassEditor::addNewField();
419
    ClassEditor::modelForDescription->select();
59 pingvin 420
}
421
void ClassEditor::on_pushButton_4_clicked(){         //    " "
422
    int i;
423
    i++;
62 pingvin 424
    QModelIndex model_index;
425
    QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
426
    QModelIndexList indexes = selectionModel->selectedIndexes();
427
    //model_index = mymodel->selec;
428
    //modelList = ui->tableView->SelectItems;
429
    i = indexes.size();
430
 
431
    if (i > 0) model_index = indexes.at(0);
432
    i++;
59 pingvin 433
}
62 pingvin 434
 
435
 
436
void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){
437
int i;
438
i++;
439
ui->tableView->resizeColumnsToContents();
440
}
441
 
442
void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){
443
    ui->tableView_2->resizeColumnsToContents();
444
}