Редакция 161 | Редакция 166 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 161 | Редакция 165 | ||
---|---|---|---|
1 | #include "classeditor.h"
|
1 | #include "classeditor.h"
|
2 | #include "ui_classeditor.h"
|
2 | #include "ui_classeditor.h"
|
3 | 3 | ||
4 | 4 | ||
5 | ClassEditor::ClassEditor(QWidget *parent) : |
5 | ClassEditor::ClassEditor(QWidget *parent) : |
6 | QMainWindow(parent), |
6 | QMainWindow(parent), |
7 | ui(new Ui::ClassEditor) |
7 | ui(new Ui::ClassEditor) |
8 | {
|
8 | {
|
9 | ui->setupUi(this); |
9 | ui->setupUi(this); |
10 | 10 | ||
11 | - | ||
- | 11 | iconFrm.show(); |
|
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
15 | readSettings(); |
15 | readSettings(); |
16 | 16 | ||
17 | 17 | ||
18 | initDataBase(); // íàñòðàèâàåì è óñòàíàâëèâàåì ñîåäèíåíèå |
18 | initDataBase(); // íàñòðàèâàåì è óñòàíàâëèâàåì ñîåäèíåíèå |
19 | createMainTables(); // ñîçäàåì ñòðóêòóðó íàøåé áàçû - äâå ãëàâíûå òàáëèöû DescriptionOfClasses è ListOfClasses |
19 | createMainTables(); // ñîçäàåì ñòðóêòóðó íàøåé áàçû - äâå ãëàâíûå òàáëèöû DescriptionOfClasses è ListOfClasses |
20 | 20 | ||
21 | 21 | ||
22 | 22 | ||
23 | /*
|
23 | /*
|
24 | field = new TableField(tr("Ñîòðóäíèêè"), this);
|
24 | field = new TableField(tr("Ñîòðóäíèêè"), this);
|
25 | field->setNotNull(true);
|
25 | field->setNotNull(true);
|
26 | field->setDefaultValue(tr("ñîòðóäíèê"));
|
26 | field->setDefaultValue(tr("ñîòðóäíèê"));
|
27 | 27 | ||
28 | table = new SqlTable (tr("NewTable"), this);
|
28 | table = new SqlTable (tr("NewTable"), this);
|
29 | table->setName(tr("NewTable"));
|
29 | table->setName(tr("NewTable"));
|
30 | table->fields().at(0)->setNotNull(true);
|
30 | table->fields().at(0)->setNotNull(true);
|
31 | if (!(table->setPrimaryKey(tr("ID")))) {
|
31 | if (!(table->setPrimaryKey(tr("ID")))) {
|
32 | ui->label_3->setText(table->lastError());
|
32 | ui->label_3->setText(table->lastError());
|
33 | }
|
33 | }
|
34 | else ui->label_3->setText(table->primaryKey());
|
34 | else ui->label_3->setText(table->primaryKey());
|
35 | table->append(field);
|
35 | table->append(field);
|
36 | 36 | ||
37 | field = new TableField(tr("Êîìïüþòåðû"), this);
|
37 | field = new TableField(tr("Êîìïüþòåðû"), this);
|
38 | field->setNotNull(true);
|
38 | field->setNotNull(true);
|
39 | field->setDefaultValue(tr("êîìïüþòåð"));
|
39 | field->setDefaultValue(tr("êîìïüþòåð"));
|
40 | table->append(field);
|
40 | table->append(field);
|
41 | 41 | ||
42 | field = new TableField(tr("Ìîíèòîðû"), this);
|
42 | field = new TableField(tr("Ìîíèòîðû"), this);
|
43 | field->setNotNull(true);
|
43 | field->setNotNull(true);
|
44 | field->setDefaultValue(tr("ìîíèòîð"));
|
44 | field->setDefaultValue(tr("ìîíèòîð"));
|
45 | table->append(field);
|
45 | table->append(field);
|
46 | 46 | ||
47 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this);
|
47 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this);
|
48 | field->setNotNull(true);
|
48 | field->setNotNull(true);
|
49 | field->setType(tr("INTEGER"));
|
49 | field->setType(tr("INTEGER"));
|
50 | field->setDefaultValue(tr("1"));
|
50 | field->setDefaultValue(tr("1"));
|
51 | table->append(field);
|
51 | table->append(field);
|
52 | 52 | ||
53 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this);
|
53 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this);
|
54 | field->setNotNull(false);
|
54 | field->setNotNull(false);
|
55 | field->setType(tr("DATE"));
|
55 | field->setType(tr("DATE"));
|
56 | field->setDefaultValue(tr("NULL"));
|
56 | field->setDefaultValue(tr("NULL"));
|
57 | table->append(field);
|
57 | table->append(field);
|
58 | 58 | ||
59 | ui->label_2->setText(table->name());
|
59 | ui->label_2->setText(table->name());
|
60 | ui->label->setText(table->fields().at(0)->sqlString());
|
60 | ui->label->setText(table->fields().at(0)->sqlString());
|
61 | ui->label_4->setText(table->sqlString());
|
61 | ui->label_4->setText(table->sqlString());
|
62 | ////// ui->lineEdit->insert(table->sqlString());
|
62 | ////// ui->lineEdit->insert(table->sqlString());
|
63 | 63 | ||
64 | */
|
64 | */
|
65 | /**********************************************
|
65 | /**********************************************
|
66 | 66 | ||
67 | QTextDocument *document;
|
67 | QTextDocument *document;
|
68 | // = ui->textEdit->document();
|
68 | // = ui->textEdit->document();
|
69 | QTextCursor *cursor;
|
69 | QTextCursor *cursor;
|
70 | 70 | ||
71 | document = ui->textEdit->document();
|
71 | document = ui->textEdit->document();
|
72 | cursor = new QTextCursor(document);
|
72 | cursor = new QTextCursor(document);
|
73 | cursor->movePosition(QTextCursor::Start);
|
73 | cursor->movePosition(QTextCursor::Start);
|
74 | QTextCharFormat format(cursor->charFormat());
|
74 | QTextCharFormat format(cursor->charFormat());
|
75 | //format.setFontFamily("Courier");
|
75 | //format.setFontFamily("Courier");
|
76 | format.setFontFamily("Arial");
|
76 | format.setFontFamily("Arial");
|
77 | //format.setFontItalic(false);
|
77 | //format.setFontItalic(false);
|
78 | 78 | ||
79 | format.setFontWeight(QFont::Normal);
|
79 | format.setFontWeight(QFont::Normal);
|
80 | QTextCharFormat boldFormat = format;
|
80 | QTextCharFormat boldFormat = format;
|
81 | boldFormat.setFontWeight(QFont::Bold);
|
81 | boldFormat.setFontWeight(QFont::Bold);
|
82 | 82 | ||
83 | QTextCharFormat italicFormat = format;
|
83 | QTextCharFormat italicFormat = format;
|
84 | //format.setFontFamily("Courier");
|
84 | //format.setFontFamily("Courier");
|
85 | // format.setFontFamily("Arial");
|
85 | // format.setFontFamily("Arial");
|
86 | italicFormat.setFontItalic(true);
|
86 | italicFormat.setFontItalic(true);
|
87 | 87 | ||
88 | cursor->insertText(table->sqlString(), format);
|
88 | cursor->insertText(table->sqlString(), format);
|
89 | 89 | ||
90 | ****************************************************/
|
90 | ****************************************************/
|
91 | 91 | ||
92 | QString errorString;
|
92 | QString errorString;
|
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | ||
97 | /*
|
97 | /*
|
98 | ok = sql.createTable(table);
|
98 | ok = sql.createTable(table);
|
99 | if (!ok) {
|
99 | if (!ok) {
|
100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
101 | this, // Ðîäèòåëüñêèé âèäæåò.
|
101 | this, // Ðîäèòåëüñêèé âèäæåò.
|
102 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
102 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ.
|
103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ.
|
104 | }
|
104 | }
|
105 | else {
|
105 | else {
|
106 | 106 | ||
107 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
107 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
108 | this, // Ðîäèòåëüñêèé âèäæåò.
|
108 | this, // Ðîäèòåëüñêèé âèäæåò.
|
109 | QObject::tr("Database Connect"), // Çàãîëîâîê.
|
109 | QObject::tr("Database Connect"), // Çàãîëîâîê.
|
110 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
|
110 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
|
111 | }
|
111 | }
|
112 | 112 | ||
113 | 113 | ||
114 | 114 | ||
115 | */
|
115 | */
|
116 | 116 | ||
117 | 117 | ||
118 | 118 | ||
119 | 119 | ||
120 | model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà |
120 | model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà |
121 | tableForInstance = new QTableView(); |
121 | tableForInstance = new QTableView(); |
122 | mymodel = new MyModel(this); |
122 | mymodel = new MyModel(this); |
123 | modelForPointers = new ModelForPointers(this); // // ìîäåëü äëÿ òàáëèöû ñ óêàçàòåëÿìè |
123 | modelForPointers = new ModelForPointers(this); // // ìîäåëü äëÿ òàáëèöû ñ óêàçàòåëÿìè |
124 | 124 | ||
125 | //modelForDescription = new QSqlTableModel(this);
|
125 | //modelForDescription = new QSqlTableModel(this);
|
126 | modelForDescription = new ModelForDescriptionTable(this); |
126 | modelForDescription = new ModelForDescriptionTable(this); |
127 | 127 | ||
128 | 128 | ||
129 | 129 | ||
130 | initClassListTable(); |
130 | initClassListTable(); |
131 | 131 | ||
132 | initFieldsTable(); |
132 | initFieldsTable(); |
133 | 133 | ||
134 | initPointersTable(); |
134 | initPointersTable(); |
135 | 135 | ||
136 | /////////////////model->setTable(tr("ListOfClasses"));
|
136 | /////////////////model->setTable(tr("ListOfClasses"));
|
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
140 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
141 | 141 | ||
142 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
142 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
143 | 143 | ||
144 | 144 | ||
145 | 145 | ||
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
149 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
150 | 150 | ||
151 | 151 | ||
152 | 152 | ||
153 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
153 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
154 | 154 | ||
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
158 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
159 | ////////////////////model->select();
|
159 | ////////////////////model->select();
|
160 | 160 | ||
161 | //tableForDescription = new QTableView();
|
161 | //tableForDescription = new QTableView();
|
162 | 162 | ||
163 | //tableForDescription->show();
|
163 | //tableForDescription->show();
|
164 | 164 | ||
165 | 165 | ||
166 | 166 | ||
167 | 167 | ||
168 | /*
|
168 | /*
|
169 | ui->tableView_2->hideColumn(0);
|
169 | ui->tableView_2->hideColumn(0);
|
170 | ui->tableView_2->hideColumn(5);
|
170 | ui->tableView_2->hideColumn(5);
|
171 | ui->tableView_2->hideColumn(2);
|
171 | ui->tableView_2->hideColumn(2);
|
172 | */
|
172 | */
|
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | 176 | ||
177 | 177 | ||
178 | 178 | ||
179 | //if (mymodel->rowCount() > 0) {
|
179 | //if (mymodel->rowCount() > 0) {
|
180 | 180 | ||
181 | 181 | ||
182 | 182 | ||
183 | /*
|
183 | /*
|
184 | 184 | ||
185 | currIndexOfClassesTable = mymodel->index(0, 1);
|
185 | currIndexOfClassesTable = mymodel->index(0, 1);
|
186 | 186 | ||
187 | 187 | ||
188 | QModelIndex index_temp;
|
188 | QModelIndex index_temp;
|
189 | 189 | ||
190 | 190 | ||
191 | 191 | ||
192 | currClassID = mymodel->data(mymodel->index(0,0)).toString();
|
192 | currClassID = mymodel->data(mymodel->index(0,0)).toString();
|
193 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
|
193 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
|
194 | 194 | ||
195 | QModelIndex topLeft;
|
195 | QModelIndex topLeft;
|
196 | QModelIndex bottomRight;
|
196 | QModelIndex bottomRight;
|
197 | 197 | ||
198 | topLeft = mymodel->index(0, 0, QModelIndex());
|
198 | topLeft = mymodel->index(0, 0, QModelIndex());
|
199 | bottomRight = mymodel->index(0, 1, QModelIndex());
|
199 | bottomRight = mymodel->index(0, 1, QModelIndex());
|
200 | 200 | ||
201 | QItemSelection selection(topLeft, bottomRight);
|
201 | QItemSelection selection(topLeft, bottomRight);
|
202 | selectionModel->select(selection, QItemSelectionModel::Select);
|
202 | selectionModel->select(selection, QItemSelectionModel::Select);
|
203 | 203 | ||
204 | 204 | ||
205 | QString class_indx, class_instance;
|
205 | QString class_indx, class_instance;
|
206 | QString str_fltr = tr("ClassIdentifer = ");
|
206 | QString str_fltr = tr("ClassIdentifer = ");
|
207 | class_indx = mymodel->data(mymodel->index(0,0)).toString();
|
207 | class_indx = mymodel->data(mymodel->index(0,0)).toString();
|
208 | class_instance = mymodel->data(mymodel->index(0,3)).toString();
|
208 | class_instance = mymodel->data(mymodel->index(0,3)).toString();
|
209 | 209 | ||
210 | currInctanceTable = class_instance; //
|
210 | currInctanceTable = class_instance; //
|
211 | 211 | ||
212 | 212 | ||
213 | 213 | ||
214 | modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
214 | modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
215 | //class_instance.append(tr("_inctance"));
|
215 | //class_instance.append(tr("_inctance"));
|
216 | str_fltr.append(class_indx);
|
216 | str_fltr.append(class_indx);
|
217 | str_fltr.append(tr(" AND FieldType <> \"pointer\""));
|
217 | str_fltr.append(tr(" AND FieldType <> \"pointer\""));
|
218 | 218 | ||
219 | model->setTable(class_instance);
|
219 | model->setTable(class_instance);
|
220 | //model->setTable(tr("memory"));
|
220 | //model->setTable(tr("memory"));
|
221 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
221 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
222 | model->select();
|
222 | model->select();
|
223 | tableForInstance->setModel(model);
|
223 | tableForInstance->setModel(model);
|
224 | tableForInstance->resizeColumnsToContents();
|
224 | tableForInstance->resizeColumnsToContents();
|
225 | tableForInstance->setWindowTitle(class_instance);
|
225 | tableForInstance->setWindowTitle(class_instance);
|
226 | tableForInstance->show();
|
226 | tableForInstance->show();
|
227 | 227 | ||
228 | modelForDescription->setFilter(str_fltr);
|
228 | modelForDescription->setFilter(str_fltr);
|
229 | modelForDescription->select();
|
229 | modelForDescription->select();
|
230 | ui->tableView_2->resizeColumnsToContents();
|
230 | ui->tableView_2->resizeColumnsToContents();
|
231 | 231 | ||
232 | 232 | ||
233 | str_fltr = tr("ClassIdentifer = ");
|
233 | str_fltr = tr("ClassIdentifer = ");
|
234 | modelForPointers->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
234 | modelForPointers->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
235 | str_fltr.append(class_indx);
|
235 | str_fltr.append(class_indx);
|
236 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
236 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
237 | // str_fltr.append( tr(" FieldType = pointer "));
|
237 | // str_fltr.append( tr(" FieldType = pointer "));
|
238 | 238 | ||
239 | 239 | ||
240 | 240 | ||
241 | modelForPointers->setFilter(str_fltr);
|
241 | modelForPointers->setFilter(str_fltr);
|
242 | modelForPointers->select();
|
242 | modelForPointers->select();
|
243 | 243 | ||
244 | 244 | ||
245 | */
|
245 | */
|
246 | 246 | ||
247 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
247 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
248 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
248 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
249 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
249 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
250 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
250 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
251 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
251 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
252 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
252 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
253 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
253 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
254 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
254 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
255 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
255 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
256 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
256 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
257 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
257 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
258 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
258 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
259 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
259 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
260 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû |
260 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû |
261 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû
|
261 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû
|
262 | 262 | ||
263 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // óäàëèòü âûäåëåííûå êëàññû |
263 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // óäàëèòü âûäåëåííûå êëàññû |
264 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå ïîëåé ïðîèçîøëè èçìåíåíèÿ |
264 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå ïîëåé ïðîèçîøëè èçìåíåíèÿ |
265 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå óêàçàòåëåé ïðîèçîøëè èçìåíåíèÿ |
265 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå óêàçàòåëåé ïðîèçîøëè èçìåíåíèÿ |
266 | 266 | ||
267 | 267 | ||
268 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ" |
268 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ" |
269 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
269 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
270 | 270 | ||
271 | 271 | ||
272 | 272 | ||
273 | 273 | ||
274 | }
|
274 | }
|
275 | 275 | ||
276 | 276 | ||
277 | 277 | ||
278 | 278 | ||
279 | 279 | ||
280 | 280 | ||
281 | 281 | ||
282 | 282 | ||
283 | 283 | ||
284 | 284 | ||
285 | 285 | ||
286 | ClassEditor::~ClassEditor() |
286 | ClassEditor::~ClassEditor() |
287 | {
|
287 | {
|
288 | delete ui; |
288 | delete ui; |
289 | delete model; |
289 | delete model; |
290 | delete tableForInstance; |
290 | delete tableForInstance; |
291 | // delete field;
|
291 | // delete field;
|
292 | // delete settdialog;
|
292 | // delete settdialog;
|
293 | }
|
293 | }
|
294 | 294 | ||
295 | void ClassEditor::changeEvent(QEvent *e) |
295 | void ClassEditor::changeEvent(QEvent *e) |
296 | {
|
296 | {
|
297 | QMainWindow::changeEvent(e); |
297 | QMainWindow::changeEvent(e); |
298 | switch (e->type()) { |
298 | switch (e->type()) { |
299 | case QEvent::LanguageChange: |
299 | case QEvent::LanguageChange: |
300 | ui->retranslateUi(this); |
300 | ui->retranslateUi(this); |
301 | break; |
301 | break; |
302 | default: |
302 | default: |
303 | break; |
303 | break; |
304 | }
|
304 | }
|
305 | }
|
305 | }
|
306 | 306 | ||
307 | 307 | ||
308 | /*
|
308 | /*
|
309 | void ClassEditor::addNewClass(){
|
309 | void ClassEditor::addNewClass(){
|
310 | 310 | ||
311 | int row = model->rowCount();
|
311 | int row = model->rowCount();
|
312 | 312 | ||
313 | model->insertRows(row, 1);
|
313 | model->insertRows(row, 1);
|
314 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
314 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
315 | 315 | ||
316 | 316 | ||
317 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
317 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
318 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
318 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
319 | 319 | ||
320 | 320 | ||
321 | model->submitAll();
|
321 | model->submitAll();
|
322 | 322 | ||
323 | row = model->rowCount();
|
323 | row = model->rowCount();
|
324 | QString tmp_str;
|
324 | QString tmp_str;
|
325 | int i_tmp;
|
325 | int i_tmp;
|
326 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
326 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
327 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
327 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
328 | 328 | ||
329 | tmp_str.append(tr("_Inctance"));
|
329 | tmp_str.append(tr("_Inctance"));
|
330 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
330 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
331 | 331 | ||
332 | model->submitAll();
|
332 | model->submitAll();
|
333 | mymodel->select();
|
333 | mymodel->select();
|
334 | 334 | ||
335 | 335 | ||
336 | }
|
336 | }
|
337 | */
|
337 | */
|
338 | 338 | ||
339 | void ClassEditor::addNewClass_new(){ |
339 | void ClassEditor::addNewClass_new(){ |
340 | 340 | ||
341 | int row = mymodel->rowCount(); |
341 | int row = mymodel->rowCount(); |
342 | 342 | ||
343 | mymodel->insertRows(row, 1); |
343 | mymodel->insertRows(row, 1); |
344 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
344 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
345 | 345 | ||
346 | 346 | ||
347 | mymodel->submitAll(); |
347 | mymodel->submitAll(); |
348 | row = mymodel->rowCount(); |
348 | row = mymodel->rowCount(); |
349 | QString tmp_str1, sql_str;
|
349 | QString tmp_str1, sql_str;
|
350 | int i_tmp1; |
350 | int i_tmp1; |
351 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
351 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
352 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
352 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
353 | 353 | ||
354 | tmp_str1.append(tr("_Inctance")); |
354 | tmp_str1.append(tr("_Inctance")); |
355 | SqlTable* tbl; |
355 | SqlTable* tbl; |
356 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
356 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
357 | sql_str = tbl->sqlString(); |
357 | sql_str = tbl->sqlString(); |
358 | bool ok; |
358 | bool ok; |
359 | 359 | ||
360 | ok = sql.createTable(tbl); |
360 | ok = sql.createTable(tbl); |
361 | 361 | ||
362 | if (!ok) { |
362 | if (!ok) { |
363 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
363 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
364 | this, // Ðîäèòåëüñêèé âèäæåò. |
364 | this, // Ðîäèòåëüñêèé âèäæåò. |
365 | QObject::tr("Database Error"), // Çàãîëîâîê. |
365 | QObject::tr("Database Error"), // Çàãîëîâîê. |
366 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
366 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
367 | delete tbl; |
367 | delete tbl; |
368 | mymodel->removeRow(row-1); |
368 | mymodel->removeRow(row-1); |
369 | mymodel->submitAll(); |
369 | mymodel->submitAll(); |
370 | mymodel->select(); |
370 | mymodel->select(); |
371 | ui->tableView_2->resizeRowsToContents(); |
371 | ui->tableView_2->resizeRowsToContents(); |
372 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
372 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
373 | 373 | ||
374 | }
|
374 | }
|
375 | 375 | ||
376 | delete tbl; |
376 | delete tbl; |
377 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
377 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
378 | 378 | ||
379 | 379 | ||
380 | 380 | ||
381 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
381 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
382 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
382 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
383 | 383 | ||
384 | 384 | ||
385 | //mymodel->submitAll();
|
385 | //mymodel->submitAll();
|
386 | 386 | ||
387 | //row = mymodel->rowCount();
|
387 | //row = mymodel->rowCount();
|
388 | 388 | ||
389 | 389 | ||
390 | //mymodel->select();
|
390 | //mymodel->select();
|
391 | 391 | ||
392 | 392 | ||
393 | }
|
393 | }
|
394 | 394 | ||
395 | 395 | ||
396 | void ClassEditor::addNewField(){ |
396 | void ClassEditor::addNewField(){ |
397 | // QSqlRecord rec = mymodel->record(1);
|
397 | // QSqlRecord rec = mymodel->record(1);
|
398 | //bool ok;
|
398 | //bool ok;
|
399 | //ok = rec.isEmpty();
|
399 | //ok = rec.isEmpty();
|
400 | //QString currientClassID;
|
400 | //QString currientClassID;
|
401 | //currientClassID = rec.value(1).toString();
|
401 | //currientClassID = rec.value(1).toString();
|
402 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
402 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
403 | QString query_str = tr("ALTER TABLE "); |
403 | QString query_str = tr("ALTER TABLE "); |
404 | QString db_error;
|
404 | QString db_error;
|
405 | QSqlQuery q;
|
405 | QSqlQuery q;
|
406 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
406 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
407 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
407 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
408 | query_str.append( Inctance_str); |
408 | query_str.append( Inctance_str); |
409 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
409 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
410 | bool ok = q.prepare(query_str); |
410 | bool ok = q.prepare(query_str); |
411 | 411 | ||
412 | ok = q.exec(); |
412 | ok = q.exec(); |
413 | if (!ok) { |
413 | if (!ok) { |
414 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
414 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
415 | this, // Ðîäèòåëüñêèé âèäæåò. |
415 | this, // Ðîäèòåëüñêèé âèäæåò. |
416 | QObject::tr("Database Error"), // Çàãîëîâîê. |
416 | QObject::tr("Database Error"), // Çàãîëîâîê. |
417 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
417 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
418 | 418 | ||
419 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
419 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
420 | 420 | ||
421 | }
|
421 | }
|
422 | 422 | ||
423 | int row = modelForDescription->rowCount(); |
423 | int row = modelForDescription->rowCount(); |
424 | modelForDescription->insertRows(row, 1); |
424 | modelForDescription->insertRows(row, 1); |
425 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
425 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
426 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
426 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
427 | 427 | ||
428 | modelForDescription->submitAll(); |
428 | modelForDescription->submitAll(); |
429 | 429 | ||
430 | delete model; |
430 | delete model; |
431 | delete tableForInstance; |
431 | delete tableForInstance; |
432 | model = new QSqlTableModel(); |
432 | model = new QSqlTableModel(); |
433 | tableForInstance = new QTableView(); |
433 | tableForInstance = new QTableView(); |
434 | model->setTable(Inctance_str); |
434 | model->setTable(Inctance_str); |
435 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
435 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
436 | tableForInstance->setModel(model); |
436 | tableForInstance->setModel(model); |
437 | tableForInstance->setWindowTitle(Inctance_str); |
437 | tableForInstance->setWindowTitle(Inctance_str); |
438 | tableForInstance->show(); |
438 | tableForInstance->show(); |
439 | }
|
439 | }
|
440 | 440 | ||
441 | 441 | ||
442 | 442 | ||
443 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
443 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
444 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
444 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
445 | QString query_str = tr("ALTER TABLE "); |
445 | QString query_str = tr("ALTER TABLE "); |
446 | QString db_error;
|
446 | QString db_error;
|
447 | QSqlQuery q;
|
447 | QSqlQuery q;
|
448 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
448 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
449 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
449 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
450 | query_str.append( Inctance_str); |
450 | query_str.append( Inctance_str); |
451 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
451 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
452 | bool ok = q.prepare(query_str); |
452 | bool ok = q.prepare(query_str); |
453 | 453 | ||
454 | ok = q.exec(); |
454 | ok = q.exec(); |
455 | if (!ok) { |
455 | if (!ok) { |
456 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
456 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
457 | this, // Ðîäèòåëüñêèé âèäæåò. |
457 | this, // Ðîäèòåëüñêèé âèäæåò. |
458 | QObject::tr("Database Error"), // Çàãîëîâîê. |
458 | QObject::tr("Database Error"), // Çàãîëîâîê. |
459 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
459 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
460 | 460 | ||
461 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
461 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
462 | 462 | ||
463 | }
|
463 | }
|
464 | 464 | ||
465 | 465 | ||
466 | int row = ClassEditor::modelForPointers->rowCount(); |
466 | int row = ClassEditor::modelForPointers->rowCount(); |
467 | modelForPointers->insertRows(row, 1); |
467 | modelForPointers->insertRows(row, 1); |
468 | 468 | ||
469 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
469 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
470 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
470 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
471 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
471 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
473 | 473 | ||
474 | 474 | ||
475 | modelForPointers->submitAll(); |
475 | modelForPointers->submitAll(); |
476 | 476 | ||
477 | 477 | ||
478 | 478 | ||
479 | 479 | ||
480 | 480 | ||
481 | 481 | ||
482 | 482 | ||
483 | 483 | ||
484 | /*
|
484 | /*
|
485 | 485 | ||
486 | str_fltr = tr("ClassIdentifer = ");
|
486 | str_fltr = tr("ClassIdentifer = ");
|
487 | modelForPointers->setInctance(Inctance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
487 | modelForPointers->setInctance(Inctance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
488 | str_fltr.append(class_indx);
|
488 | str_fltr.append(class_indx);
|
489 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
489 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
490 | // str_fltr.append( tr(" FieldType = pointer "));
|
490 | // str_fltr.append( tr(" FieldType = pointer "));
|
491 | 491 | ||
492 | 492 | ||
493 | 493 | ||
494 | modelForPointers->setFilter(str_fltr);
|
494 | modelForPointers->setFilter(str_fltr);
|
495 | modelForPointers->select();
|
495 | modelForPointers->select();
|
496 | ui->tableView_3->setModel(modelForPointers);
|
496 | ui->tableView_3->setModel(modelForPointers);
|
497 | ui->tableView_3->resizeColumnsToContents();
|
497 | ui->tableView_3->resizeColumnsToContents();
|
498 | */
|
498 | */
|
499 | 499 | ||
500 | 500 | ||
501 | 501 | ||
502 | 502 | ||
503 | // modelForPointers->select();
|
503 | // modelForPointers->select();
|
504 | 504 | ||
505 | 505 | ||
506 | 506 | ||
507 | 507 | ||
508 | 508 | ||
509 | ClassEditor::refreshInctance(); |
509 | ClassEditor::refreshInctance(); |
510 | 510 | ||
511 | 511 | ||
512 | 512 | ||
513 | 513 | ||
514 | 514 | ||
515 | 515 | ||
516 | 516 | ||
517 | 517 | ||
518 | 518 | ||
519 | }
|
519 | }
|
520 | 520 | ||
521 | 521 | ||
522 | 522 | ||
523 | 523 | ||
524 | 524 | ||
525 | // äîáàâëÿåì íîâûé êëàññ
|
525 | // äîáàâëÿåì íîâûé êëàññ
|
526 | void ClassEditor::on_pushButton_clicked(){ |
526 | void ClassEditor::on_pushButton_clicked(){ |
527 | //int i;
|
527 | //int i;
|
528 | //i++;
|
528 | //i++;
|
529 | /////ClassEditor::addNewClass();
|
529 | /////ClassEditor::addNewClass();
|
530 | ClassEditor::addNewClass_new(); |
530 | ClassEditor::addNewClass_new(); |
531 | mymodel->select(); |
531 | mymodel->select(); |
532 | //ui->tableView->setModel(mymodel);
|
532 | //ui->tableView->setModel(mymodel);
|
533 | 533 | ||
534 | }
|
534 | }
|
535 | 535 | ||
536 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
536 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
537 | bool indexIsValid; |
537 | bool indexIsValid; |
538 | int i, row, column; |
538 | int i, row, column; |
539 | i++; |
539 | i++; |
540 | indexIsValid = index.isValid(); |
540 | indexIsValid = index.isValid(); |
541 | row = index.row(); |
541 | row = index.row(); |
542 | column = index.column(); |
542 | column = index.column(); |
543 | currIndexOfClassesTable = index; |
543 | currIndexOfClassesTable = index; |
544 | QModelIndex index_tmp, index_instance;
|
544 | QModelIndex index_tmp, index_instance;
|
545 | QString tmp_str, filter_str, instance_str;
|
545 | QString tmp_str, filter_str, instance_str;
|
546 | index_tmp = ui->tableView->model()->index(row, 0); |
546 | index_tmp = ui->tableView->model()->index(row, 0); |
547 | index_instance = ui->tableView->model()->index(row, 3); |
547 | index_instance = ui->tableView->model()->index(row, 3); |
548 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
548 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
549 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
549 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
550 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
550 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
551 | modelForPointers->setInctance(instance_str); |
551 | modelForPointers->setInctance(instance_str); |
552 | 552 | ||
553 | delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ |
553 | delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ |
554 | 554 | ||
555 | // instance_str.append(tr("_inctance"));
|
555 | // instance_str.append(tr("_inctance"));
|
556 | /*
|
556 | /*
|
557 | Inctance_model.clear();
|
557 | Inctance_model.clear();
|
558 | Inctance_model.setTable(instance_str);
|
558 | Inctance_model.setTable(instance_str);
|
559 | Inctance_model.select();
|
559 | Inctance_model.select();
|
560 | tableForInstance_new.setModel(&Inctance_model);
|
560 | tableForInstance_new.setModel(&Inctance_model);
|
561 | tableForInstance_new.show();
|
561 | tableForInstance_new.show();
|
562 | */
|
562 | */
|
563 | // model->clear();
|
563 | // model->clear();
|
564 | tableForInstance->close(); |
564 | tableForInstance->close(); |
565 | delete model; |
565 | delete model; |
566 | delete tableForInstance; |
566 | delete tableForInstance; |
567 | model = new QSqlTableModel(); |
567 | model = new QSqlTableModel(); |
568 | tableForInstance = new QTableView(); |
568 | tableForInstance = new QTableView(); |
569 | model->setTable(instance_str); |
569 | model->setTable(instance_str); |
570 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
570 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
571 | tableForInstance->setModel(model); |
571 | tableForInstance->setModel(model); |
572 | 572 | ||
573 | model->select(); |
573 | model->select(); |
574 | tableForInstance->setWindowTitle(instance_str); |
574 | tableForInstance->setWindowTitle(instance_str); |
575 | tableForInstance->show(); |
575 | tableForInstance->show(); |
576 | 576 | ||
577 | // tableForInstance.setModel(model);
|
577 | // tableForInstance.setModel(model);
|
578 | tableForInstance->resizeColumnsToContents(); |
578 | tableForInstance->resizeColumnsToContents(); |
579 | 579 | ||
580 | currClassID = tmp_str; |
580 | currClassID = tmp_str; |
581 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
581 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
582 | filter_str = tr("ClassIdentifer = "); |
582 | filter_str = tr("ClassIdentifer = "); |
583 | filter_str.append(tmp_str); |
583 | filter_str.append(tmp_str); |
584 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
584 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
585 | modelForDescription->setFilter(filter_str); |
585 | modelForDescription->setFilter(filter_str); |
586 | modelForDescription->select(); |
586 | modelForDescription->select(); |
587 | ui->tableView_2->resizeColumnsToContents(); |
587 | ui->tableView_2->resizeColumnsToContents(); |
588 | 588 | ||
589 | filter_str = tr("ClassIdentifer = "); |
589 | filter_str = tr("ClassIdentifer = "); |
590 | filter_str.append(tmp_str); |
590 | filter_str.append(tmp_str); |
591 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
591 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
592 | modelForPointers->setFilter(filter_str); |
592 | modelForPointers->setFilter(filter_str); |
593 | modelForPointers->select(); |
593 | modelForPointers->select(); |
594 | ui->tableView_3->resizeColumnsToContents(); |
594 | ui->tableView_3->resizeColumnsToContents(); |
595 | 595 | ||
596 | 596 | ||
597 | 597 | ||
598 | 598 | ||
599 | i++; |
599 | i++; |
600 | }
|
600 | }
|
601 | 601 | ||
602 | 602 | ||
603 | 603 | ||
604 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
604 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
605 | QModelIndex model_index;
|
605 | QModelIndex model_index;
|
606 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
606 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
607 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
607 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
608 | QList<int> selectedRows; |
608 | QList<int> selectedRows; |
609 | selectedRows.clear(); |
609 | selectedRows.clear(); |
610 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
610 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
611 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
611 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
612 | 612 | ||
613 | }
|
613 | }
|
614 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
614 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
615 | 615 | ||
616 | 616 | ||
617 | for (int m =0; m < selectedRows.size(); ++m){ |
617 | for (int m =0; m < selectedRows.size(); ++m){ |
618 | 618 | ||
619 | ClassEditor::removeClass(selectedRows.at(m)); |
619 | ClassEditor::removeClass(selectedRows.at(m)); |
620 | 620 | ||
621 | 621 | ||
622 | 622 | ||
623 | }
|
623 | }
|
624 | mymodel->submitAll(); |
624 | mymodel->submitAll(); |
625 | ClassEditor::modelForDescription->select(); |
625 | ClassEditor::modelForDescription->select(); |
626 | 626 | ||
627 | }
|
627 | }
|
628 | 628 | ||
629 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
629 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
630 | int i; |
630 | int i; |
631 | i++; |
631 | i++; |
632 | ClassEditor::addNewField(); |
632 | ClassEditor::addNewField(); |
633 | ClassEditor::modelForDescription->select(); |
633 | ClassEditor::modelForDescription->select(); |
634 | ui->tableView_2->resizeColumnsToContents(); |
634 | ui->tableView_2->resizeColumnsToContents(); |
635 | }
|
635 | }
|
636 | 636 | ||
637 | 637 | ||
638 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
638 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
639 | // int i;
|
639 | // int i;
|
640 | QModelIndex model_index;
|
640 | QModelIndex model_index;
|
641 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
641 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
642 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
642 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
643 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
643 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
644 | //model_index = mymodel->selec;
|
644 | //model_index = mymodel->selec;
|
645 | //modelList = ui->tableView->SelectItems;
|
645 | //modelList = ui->tableView->SelectItems;
|
646 | //i = indexes.size();
|
646 | //i = indexes.size();
|
647 | QList<int> selectedRows; |
647 | QList<int> selectedRows; |
648 | //indexes_fo_first_col.clear();
|
648 | //indexes_fo_first_col.clear();
|
649 | /*
|
649 | /*
|
650 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
650 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
651 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
651 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
652 | 652 | ||
653 | }
|
653 | }
|
654 | */
|
654 | */
|
655 | selectedRows.clear(); |
655 | selectedRows.clear(); |
656 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
656 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
657 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
657 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
658 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
658 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
659 | }
|
659 | }
|
660 | }
|
660 | }
|
661 | 661 | ||
662 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
662 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
663 | 663 | ||
664 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
664 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
665 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
665 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
666 | for (int m =0; m < selectedRows.size(); ++m){ |
666 | for (int m =0; m < selectedRows.size(); ++m){ |
667 | 667 | ||
668 | 668 | ||
669 | QString query_str;
|
669 | QString query_str;
|
670 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
670 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
671 | QSqlQuery q;
|
671 | QSqlQuery q;
|
672 | 672 | ||
673 | query_str.clear(); |
673 | query_str.clear(); |
674 | 674 | ||
675 | 675 | ||
676 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
676 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
677 | 677 | ||
678 | query_str.append(tr("ALTER TABLE ")); |
678 | query_str.append(tr("ALTER TABLE ")); |
679 | query_str.append(Inctance_str); |
679 | query_str.append(Inctance_str); |
680 | query_str.append(tr(" DROP COLUMN `")); |
680 | query_str.append(tr(" DROP COLUMN `")); |
681 | query_str.append(field_name_str); |
681 | query_str.append(field_name_str); |
682 | query_str.append(tr("`")); |
682 | query_str.append(tr("`")); |
683 | q.prepare(query_str); |
683 | q.prepare(query_str); |
684 | bool ok = q.exec(); |
684 | bool ok = q.exec(); |
685 | if (!ok) { |
685 | if (!ok) { |
686 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
686 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
687 | this, // Ðîäèòåëüñêèé âèäæåò. |
687 | this, // Ðîäèòåëüñêèé âèäæåò. |
688 | QObject::tr("Database Error"), // Çàãîëîâîê. |
688 | QObject::tr("Database Error"), // Çàãîëîâîê. |
689 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
689 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
690 | 690 | ||
691 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
691 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
692 | 692 | ||
693 | }
|
693 | }
|
694 | 694 | ||
695 | 695 | ||
696 | 696 | ||
697 | modelForDescription->removeRow(selectedRows.at(m)); |
697 | modelForDescription->removeRow(selectedRows.at(m)); |
698 | 698 | ||
699 | }
|
699 | }
|
700 | delete model; |
700 | delete model; |
701 | delete tableForInstance; |
701 | delete tableForInstance; |
702 | model = new QSqlTableModel(); |
702 | model = new QSqlTableModel(); |
703 | tableForInstance = new QTableView(); |
703 | tableForInstance = new QTableView(); |
704 | model->setTable(Inctance_str); |
704 | model->setTable(Inctance_str); |
705 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
705 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
706 | tableForInstance->setModel(model); |
706 | tableForInstance->setModel(model); |
707 | tableForInstance->setWindowTitle(Inctance_str); |
707 | tableForInstance->setWindowTitle(Inctance_str); |
708 | tableForInstance->show(); |
708 | tableForInstance->show(); |
709 | //i = selectedRows.size();
|
709 | //i = selectedRows.size();
|
710 | 710 | ||
711 | //if (i > 0) model_index = indexes.at(0);
|
711 | //if (i > 0) model_index = indexes.at(0);
|
712 | }
|
712 | }
|
713 | 713 | ||
714 | 714 | ||
715 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
715 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
716 | QModelIndex model_index;
|
716 | QModelIndex model_index;
|
717 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
717 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
718 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
718 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
719 | QList<int> selectedRows; |
719 | QList<int> selectedRows; |
720 | 720 | ||
721 | selectedRows.clear(); |
721 | selectedRows.clear(); |
722 | 722 | ||
723 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
723 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
724 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
724 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
725 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
725 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
726 | }
|
726 | }
|
727 | }
|
727 | }
|
728 | 728 | ||
729 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
729 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
730 | 730 | ||
731 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
731 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
732 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
732 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
733 | for (int m =0; m < selectedRows.size(); ++m){ |
733 | for (int m =0; m < selectedRows.size(); ++m){ |
734 | 734 | ||
735 | 735 | ||
736 | QString query_str;
|
736 | QString query_str;
|
737 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
737 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
738 | QSqlQuery q;
|
738 | QSqlQuery q;
|
739 | 739 | ||
740 | query_str.clear(); |
740 | query_str.clear(); |
741 | 741 | ||
742 | 742 | ||
743 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
743 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
744 | 744 | ||
745 | query_str.append(tr("ALTER TABLE ")); |
745 | query_str.append(tr("ALTER TABLE ")); |
746 | query_str.append(Inctance_str); |
746 | query_str.append(Inctance_str); |
747 | query_str.append(tr(" DROP COLUMN `")); |
747 | query_str.append(tr(" DROP COLUMN `")); |
748 | query_str.append(field_name_str); |
748 | query_str.append(field_name_str); |
749 | query_str.append(tr("`")); |
749 | query_str.append(tr("`")); |
750 | q.prepare(query_str); |
750 | q.prepare(query_str); |
751 | bool ok = q.exec(); |
751 | bool ok = q.exec(); |
752 | if (!ok) { |
752 | if (!ok) { |
753 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
753 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
754 | this, // Ðîäèòåëüñêèé âèäæåò. |
754 | this, // Ðîäèòåëüñêèé âèäæåò. |
755 | QObject::tr("Database Error"), // Çàãîëîâîê. |
755 | QObject::tr("Database Error"), // Çàãîëîâîê. |
756 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
756 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
757 | 757 | ||
758 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
758 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
759 | 759 | ||
760 | }
|
760 | }
|
761 | 761 | ||
762 | 762 | ||
763 | 763 | ||
764 | modelForPointers->removeRow(selectedRows.at(m)); |
764 | modelForPointers->removeRow(selectedRows.at(m)); |
765 | 765 | ||
766 | }
|
766 | }
|
767 | 767 | ||
768 | 768 | ||
769 | refreshInctance(); |
769 | refreshInctance(); |
770 | 770 | ||
771 | 771 | ||
772 | 772 | ||
773 | }
|
773 | }
|
774 | 774 | ||
775 | 775 | ||
776 | 776 | ||
777 | 777 | ||
778 | 778 | ||
779 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
779 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
780 | int row; |
780 | int row; |
781 | row = ClassEditor::modelForDescription->rowCount(); |
781 | row = ClassEditor::modelForDescription->rowCount(); |
782 | ClassEditor::modelForDescription->removeRows(0, row); |
782 | ClassEditor::modelForDescription->removeRows(0, row); |
783 | ClassEditor::modelForDescription->submitAll(); |
783 | ClassEditor::modelForDescription->submitAll(); |
784 | }
|
784 | }
|
785 | 785 | ||
786 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
786 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
787 | QString fileName;
|
787 | QString fileName;
|
788 | QPixmap pixmap;
|
788 | QPixmap pixmap;
|
789 | fileName = QFileDialog::getOpenFileName(this, |
789 | fileName = QFileDialog::getOpenFileName(this, |
790 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
790 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
791 | pixmap.load(fileName); |
791 | pixmap.load(fileName); |
792 | ui->label_4->setPixmap(pixmap); |
792 | ui->label_4->setPixmap(pixmap); |
793 | QImage currentImage = pixmap.toImage(); |
793 | QImage currentImage = pixmap.toImage(); |
794 | QByteArray bytes;
|
794 | QByteArray bytes;
|
795 | QBuffer buffer(&bytes); |
795 | QBuffer buffer(&bytes); |
796 | buffer.open(QIODevice::WriteOnly); |
796 | buffer.open(QIODevice::WriteOnly); |
797 | currentImage.save(&buffer, "PNG"); |
797 | currentImage.save(&buffer, "PNG"); |
798 | 798 | ||
799 | if (currIndexOfClassesTable.isValid()) { |
799 | if (currIndexOfClassesTable.isValid()) { |
800 | bool ok; |
800 | bool ok; |
801 | 801 | ||
802 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
802 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
803 | mymodel->submitAll(); |
803 | mymodel->submitAll(); |
804 | }
|
804 | }
|
805 | 805 | ||
806 | 806 | ||
807 | }
|
807 | }
|
808 | 808 | ||
809 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
809 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
810 | 810 | ||
811 | int i; |
811 | int i; |
812 | i++; |
812 | i++; |
813 | ui->tableView->resizeColumnsToContents(); |
813 | ui->tableView->resizeColumnsToContents(); |
814 | 814 | ||
815 | 815 | ||
816 | 816 | ||
817 | 817 | ||
818 | 818 | ||
819 | }
|
819 | }
|
820 | 820 | ||
821 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
821 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
822 | ui->tableView_2->resizeColumnsToContents(); |
822 | ui->tableView_2->resizeColumnsToContents(); |
823 | 823 | ||
824 | /*
|
824 | /*
|
825 | QString instance_str;
|
825 | QString instance_str;
|
826 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
826 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
827 | tableForInstance->close();
|
827 | tableForInstance->close();
|
828 | delete model;
|
828 | delete model;
|
829 | delete tableForInstance;
|
829 | delete tableForInstance;
|
830 | model = new QSqlTableModel();
|
830 | model = new QSqlTableModel();
|
831 | tableForInstance = new QTableView();
|
831 | tableForInstance = new QTableView();
|
832 | model->setTable(instance_str);
|
832 | model->setTable(instance_str);
|
833 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
833 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
834 | tableForInstance->setModel(model);
|
834 | tableForInstance->setModel(model);
|
835 | 835 | ||
836 | model->select();
|
836 | model->select();
|
837 | tableForInstance->setWindowTitle(instance_str);
|
837 | tableForInstance->setWindowTitle(instance_str);
|
838 | tableForInstance->show();
|
838 | tableForInstance->show();
|
839 | */
|
839 | */
|
840 | }
|
840 | }
|
841 | 841 | ||
842 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
842 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
843 | if (is_checked) ui->tableView->showColumn(0); |
843 | if (is_checked) ui->tableView->showColumn(0); |
844 | else ui->tableView->hideColumn(0); |
844 | else ui->tableView->hideColumn(0); |
845 | ui->tableView->resizeColumnsToContents(); |
845 | ui->tableView->resizeColumnsToContents(); |
846 | }
|
846 | }
|
847 | 847 | ||
848 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
848 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
849 | if (is_checked) ui->tableView->showColumn(2); |
849 | if (is_checked) ui->tableView->showColumn(2); |
850 | else ui->tableView->hideColumn(2); |
850 | else ui->tableView->hideColumn(2); |
851 | ui->tableView->resizeColumnsToContents(); |
851 | ui->tableView->resizeColumnsToContents(); |
852 | }
|
852 | }
|
853 | 853 | ||
854 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
854 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
855 | if (is_checked) ui->tableView->showColumn(3); |
855 | if (is_checked) ui->tableView->showColumn(3); |
856 | else ui->tableView->hideColumn(3); |
856 | else ui->tableView->hideColumn(3); |
857 | ui->tableView->resizeColumnsToContents(); |
857 | ui->tableView->resizeColumnsToContents(); |
858 | }
|
858 | }
|
859 | 859 | ||
860 | 860 | ||
861 | 861 | ||
862 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
862 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
863 | int row; |
863 | int row; |
864 | row = ClassEditor::mymodel->rowCount(); |
864 | row = ClassEditor::mymodel->rowCount(); |
865 | for (int m=0; m < row; ++m){ |
865 | for (int m=0; m < row; ++m){ |
866 | ClassEditor::removeClass(0); |
866 | ClassEditor::removeClass(0); |
867 | //ClassEditor::mymodel->removeRows(0, row);
|
867 | //ClassEditor::mymodel->removeRows(0, row);
|
868 | }
|
868 | }
|
869 | ClassEditor::mymodel->submitAll(); |
869 | ClassEditor::mymodel->submitAll(); |
870 | ClassEditor::modelForDescription->select(); |
870 | ClassEditor::modelForDescription->select(); |
871 | }
|
871 | }
|
872 | 872 | ||
873 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
873 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
874 | QModelIndex index_tmp;
|
874 | QModelIndex index_tmp;
|
875 | QString tmp_str, filter_str;
|
875 | QString tmp_str, filter_str;
|
876 | index_tmp = ui->tableView->model()->index(class_row, 0); |
876 | index_tmp = ui->tableView->model()->index(class_row, 0); |
877 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
877 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
878 | currClassID = tmp_str; |
878 | currClassID = tmp_str; |
879 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
879 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
880 | filter_str = tr("ClassIdentifer = "); |
880 | filter_str = tr("ClassIdentifer = "); |
881 | filter_str.append(tmp_str); |
881 | filter_str.append(tmp_str); |
882 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
882 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
883 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
883 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
884 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
884 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
885 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
885 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
886 | ui->tableView->resizeColumnsToContents(); |
886 | ui->tableView->resizeColumnsToContents(); |
887 | ui->tableView_2->resizeColumnsToContents(); |
887 | ui->tableView_2->resizeColumnsToContents(); |
888 | 888 | ||
889 | }
|
889 | }
|
890 | 890 | ||
891 | 891 | ||
892 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
892 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
893 | ClassEditor::refreshInctance(); |
893 | ClassEditor::refreshInctance(); |
894 | }
|
894 | }
|
895 | 895 | ||
896 | 896 | ||
897 | 897 | ||
898 | 898 | ||
899 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
899 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
900 | 900 | ||
901 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
901 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
902 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
902 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
903 | delete model; |
903 | delete model; |
904 | delete tableForInstance; |
904 | delete tableForInstance; |
905 | model = new QSqlTableModel(); |
905 | model = new QSqlTableModel(); |
906 | tableForInstance = new QTableView(); |
906 | tableForInstance = new QTableView(); |
907 | model->setTable(Inctance_str); |
907 | model->setTable(Inctance_str); |
908 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
908 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
909 | model->select(); |
909 | model->select(); |
910 | tableForInstance->setModel(model); |
910 | tableForInstance->setModel(model); |
911 | tableForInstance->setWindowTitle(Inctance_str); |
911 | tableForInstance->setWindowTitle(Inctance_str); |
912 | tableForInstance->resizeRowsToContents(); |
912 | tableForInstance->resizeRowsToContents(); |
913 | tableForInstance->show(); |
913 | tableForInstance->show(); |
914 | 914 | ||
915 | }
|
915 | }
|
916 | 916 | ||
917 | 917 | ||
918 | 918 | ||
919 | 919 | ||
920 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
920 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
921 | ClassEditor::addNewPointer(); |
921 | ClassEditor::addNewPointer(); |
922 | ClassEditor::modelForPointers->select(); |
922 | ClassEditor::modelForPointers->select(); |
923 | ui->tableView_3->resizeColumnsToContents(); |
923 | ui->tableView_3->resizeColumnsToContents(); |
924 | 924 | ||
925 | }
|
925 | }
|
926 | 926 | ||
927 | 927 | ||
928 | // Ñ÷èòûâàåì íàñòðîéêè
|
928 | // Ñ÷èòûâàåì íàñòðîéêè
|
929 | 929 | ||
930 | void ClassEditor::readSettings() |
930 | void ClassEditor::readSettings() |
931 | {
|
931 | {
|
932 | QSettings settings("Trolltech", "Application Example"); |
932 | QSettings settings("Trolltech", "Application Example"); |
933 | baseName = settings.value("baseName", "an_db").toString(); |
933 | baseName = settings.value("baseName", "an_db").toString(); |
934 | userName = settings.value("userName", "an").toString(); |
934 | userName = settings.value("userName", "an").toString(); |
935 | password = settings.value("password", "393939").toString(); |
935 | password = settings.value("password", "393939").toString(); |
936 | tableName = settings.value("tableName", "inventar").toString(); |
936 | tableName = settings.value("tableName", "inventar").toString(); |
937 | hostName = settings.value("hostName", "server").toString(); |
937 | hostName = settings.value("hostName", "server").toString(); |
938 | // resize(size);
|
938 | // resize(size);
|
939 | // move(pos);tableName
|
939 | // move(pos);tableName
|
940 | }
|
940 | }
|
941 | 941 | ||
942 | 942 | ||
943 | void ClassEditor::writeSettings() |
943 | void ClassEditor::writeSettings() |
944 | {
|
944 | {
|
945 | QSettings settings("Trolltech", "Application Example"); |
945 | QSettings settings("Trolltech", "Application Example"); |
946 | settings.setValue("baseName", baseName); |
946 | settings.setValue("baseName", baseName); |
947 | settings.setValue("userName", userName); |
947 | settings.setValue("userName", userName); |
948 | settings.setValue("password", password); |
948 | settings.setValue("password", password); |
949 | settings.setValue("tableName", tableName); |
949 | settings.setValue("tableName", tableName); |
950 | settings.setValue("hostName", hostName); |
950 | settings.setValue("hostName", hostName); |
951 | }
|
951 | }
|
952 | 952 | ||
953 | 953 | ||
954 | void ClassEditor::applySetting() |
954 | void ClassEditor::applySetting() |
955 | {
|
955 | {
|
956 | bool ok; |
956 | bool ok; |
957 | baseName = setFrm.lineEdit->text(); |
957 | baseName = setFrm.lineEdit->text(); |
958 | userName = setFrm.lineEdit_2->text(); |
958 | userName = setFrm.lineEdit_2->text(); |
959 | password = setFrm.lineEdit_3->text(); |
959 | password = setFrm.lineEdit_3->text(); |
960 | // tableName = setFrm->lineEdit_4->text();
|
960 | // tableName = setFrm->lineEdit_4->text();
|
961 | hostName = setFrm.lineEdit_5->text(); |
961 | hostName = setFrm.lineEdit_5->text(); |
962 | writeSettings(); |
962 | writeSettings(); |
963 | 963 | ||
964 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
964 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
965 | 965 | ||
966 | sql.setDatabaseName(baseName); |
966 | sql.setDatabaseName(baseName); |
967 | // sql.setDatabaseName(tr("inventory"));
|
967 | // sql.setDatabaseName(tr("inventory"));
|
968 | 968 | ||
969 | // sql.setHostName(tr("localhost"));
|
969 | // sql.setHostName(tr("localhost"));
|
970 | sql.setHostName(hostName); |
970 | sql.setHostName(hostName); |
971 | 971 | ||
972 | // sql.setUserName(tr("an"));
|
972 | // sql.setUserName(tr("an"));
|
973 | 973 | ||
974 | sql.setUserName(userName); |
974 | sql.setUserName(userName); |
975 | 975 | ||
976 | // sql.setPassword(tr("393939"));
|
976 | // sql.setPassword(tr("393939"));
|
977 | 977 | ||
978 | sql.setPassword(password); |
978 | sql.setPassword(password); |
979 | 979 | ||
980 | ok = sql.connect(); |
980 | ok = sql.connect(); |
981 | if (!ok) { |
981 | if (!ok) { |
982 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
982 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
983 | this, // Ðîäèòåëüñêèé âèäæåò. |
983 | this, // Ðîäèòåëüñêèé âèäæåò. |
984 | QObject::tr("Database Error"), // Çàãîëîâîê. |
984 | QObject::tr("Database Error"), // Çàãîëîâîê. |
985 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
985 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
986 | 986 | ||
987 | }
|
987 | }
|
988 | else { |
988 | else { |
989 | 989 | ||
990 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
990 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
991 | this, // Ðîäèòåëüñêèé âèäæåò. |
991 | this, // Ðîäèòåëüñêèé âèäæåò. |
992 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
992 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
993 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
993 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
994 | 994 | ||
995 | 995 | ||
996 | 996 | ||
997 | 997 | ||
998 | 998 | ||
999 | }
|
999 | }
|
1000 | 1000 | ||
1001 | 1001 | ||
1002 | mymodel->select(); |
1002 | mymodel->select(); |
1003 | model->select(); |
1003 | model->select(); |
1004 | modelForDescription->select(); |
1004 | modelForDescription->select(); |
1005 | 1005 | ||
1006 | //////////// ok=openDataBase();
|
1006 | //////////// ok=openDataBase();
|
1007 | //////////// if (!ok) return;
|
1007 | //////////// if (!ok) return;
|
1008 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1008 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1009 | 1009 | ||
1010 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1010 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1011 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1011 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1012 | //////////// initComboBox();
|
1012 | //////////// initComboBox();
|
1013 | // // // getDatabaseData();
|
1013 | // // // getDatabaseData();
|
1014 | // delete setFrm;
|
1014 | // delete setFrm;
|
1015 | setFrm.close(); |
1015 | setFrm.close(); |
1016 | }
|
1016 | }
|
1017 | 1017 | ||
1018 | void ClassEditor::getSetting() |
1018 | void ClassEditor::getSetting() |
1019 | {
|
1019 | {
|
1020 | // setFrm = new settingForm;
|
1020 | // setFrm = new settingForm;
|
1021 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1021 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1022 | setFrm.lineEdit->setText(baseName); |
1022 | setFrm.lineEdit->setText(baseName); |
1023 | setFrm.lineEdit_2->setText(userName); |
1023 | setFrm.lineEdit_2->setText(userName); |
1024 | setFrm.lineEdit_3->setText(password); |
1024 | setFrm.lineEdit_3->setText(password); |
1025 | // setFrm->lineEdit_4->setText(tableName);
|
1025 | // setFrm->lineEdit_4->setText(tableName);
|
1026 | setFrm.lineEdit_5->setText(hostName); |
1026 | setFrm.lineEdit_5->setText(hostName); |
1027 | setFrm.show(); |
1027 | setFrm.show(); |
1028 | 1028 | ||
1029 | 1029 | ||
1030 | 1030 | ||
1031 | }
|
1031 | }
|
1032 | 1032 | ||
1033 | 1033 | ||
1034 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1034 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1035 | 1035 | ||
1036 | sql.setDatabaseName(baseName); |
1036 | sql.setDatabaseName(baseName); |
1037 | sql.setHostName(hostName); |
1037 | sql.setHostName(hostName); |
1038 | sql.setUserName(userName); |
1038 | sql.setUserName(userName); |
1039 | sql.setPassword(password); |
1039 | sql.setPassword(password); |
1040 | 1040 | ||
1041 | bool ok; |
1041 | bool ok; |
1042 | ok = sql.connect(); |
1042 | ok = sql.connect(); |
1043 | if (!ok) { |
1043 | if (!ok) { |
1044 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1044 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1045 | this, // Ðîäèòåëüñêèé âèäæåò. |
1045 | this, // Ðîäèòåëüñêèé âèäæåò. |
1046 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1046 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1047 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1047 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1048 | 1048 | ||
1049 | }
|
1049 | }
|
1050 | else { |
1050 | else { |
1051 | 1051 | ||
1052 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1052 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1053 | this, // Ðîäèòåëüñêèé âèäæåò. |
1053 | this, // Ðîäèòåëüñêèé âèäæåò. |
1054 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1054 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1055 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1055 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1056 | 1056 | ||
1057 | 1057 | ||
1058 | 1058 | ||
1059 | 1059 | ||
1060 | 1060 | ||
1061 | }
|
1061 | }
|
1062 | 1062 | ||
1063 | }
|
1063 | }
|
1064 | 1064 | ||
1065 | 1065 | ||
1066 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1066 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1067 | 1067 | ||
1068 | bool ok; |
1068 | bool ok; |
1069 | ok = sql.createListOfClassesTable(); |
1069 | ok = sql.createListOfClassesTable(); |
1070 | 1070 | ||
1071 | if (!ok) { |
1071 | if (!ok) { |
1072 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1072 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1073 | this, // Ðîäèòåëüñêèé âèäæåò. |
1073 | this, // Ðîäèòåëüñêèé âèäæåò. |
1074 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1074 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1075 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1075 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1076 | 1076 | ||
1077 | }
|
1077 | }
|
1078 | else { |
1078 | else { |
1079 | 1079 | ||
1080 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1080 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1081 | this, // Ðîäèòåëüñêèé âèäæåò. |
1081 | this, // Ðîäèòåëüñêèé âèäæåò. |
1082 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1082 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1083 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1083 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1084 | }
|
1084 | }
|
1085 | 1085 | ||
1086 | 1086 | ||
1087 | 1087 | ||
1088 | 1088 | ||
1089 | ok = sql.createDescriptionOfClassesTable(); |
1089 | ok = sql.createDescriptionOfClassesTable(); |
1090 | 1090 | ||
1091 | if (!ok) { |
1091 | if (!ok) { |
1092 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1092 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1093 | this, // Ðîäèòåëüñêèé âèäæåò. |
1093 | this, // Ðîäèòåëüñêèé âèäæåò. |
1094 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1094 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1095 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1095 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1096 | 1096 | ||
1097 | }
|
1097 | }
|
1098 | else { |
1098 | else { |
1099 | 1099 | ||
1100 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1100 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1101 | this, // Ðîäèòåëüñêèé âèäæåò. |
1101 | this, // Ðîäèòåëüñêèé âèäæåò. |
1102 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1102 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1103 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1103 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1104 | }
|
1104 | }
|
1105 | 1105 | ||
1106 | 1106 | ||
1107 | ok = sql.createListModelsTable(); |
1107 | ok = sql.createListModelsTable(); |
1108 | 1108 | ||
1109 | if (!ok) { |
1109 | if (!ok) { |
1110 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1110 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1111 | this, // Ðîäèòåëüñêèé âèäæåò. |
1111 | this, // Ðîäèòåëüñêèé âèäæåò. |
1112 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1112 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1113 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1113 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1114 | 1114 | ||
1115 | }
|
1115 | }
|
1116 | else { |
1116 | else { |
1117 | 1117 | ||
1118 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1118 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1119 | this, // Ðîäèòåëüñêèé âèäæåò. |
1119 | this, // Ðîäèòåëüñêèé âèäæåò. |
1120 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1120 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1121 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1121 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1122 | }
|
1122 | }
|
1123 | 1123 | ||
1124 | 1124 | ||
1125 | 1125 | ||
1126 | 1126 | ||
1127 | }
|
1127 | }
|
1128 | 1128 | ||
1129 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1129 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1130 | 1130 | ||
1131 | mymodel->setTable(tr("ListOfClasses")); |
1131 | mymodel->setTable(tr("ListOfClasses")); |
1132 | mymodel->setSort(0, Qt::AscendingOrder); |
1132 | mymodel->setSort(0, Qt::AscendingOrder); |
1133 | mymodel->select(); |
1133 | mymodel->select(); |
1134 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1134 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1135 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1135 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1136 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1136 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1137 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1137 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1138 | ui->tableView->setModel(mymodel); |
1138 | ui->tableView->setModel(mymodel); |
1139 | ui->tableView->setAlternatingRowColors(true); |
1139 | ui->tableView->setAlternatingRowColors(true); |
1140 | ui->tableView->resizeColumnsToContents(); |
1140 | // ui->tableView->resizeColumnsToContents();
|
1141 | 1141 | ||
1142 | ui->tableView->hideColumn(0); |
1142 | ui->tableView->hideColumn(0); |
1143 | ui->tableView->hideColumn(3); |
1143 | ui->tableView->hideColumn(3); |
1144 | ui->tableView->hideColumn(2); |
1144 | ui->tableView->hideColumn(2); |
1145 | CPictureDelegate *pictureDelegate; |
1145 | CPictureDelegate *pictureDelegate; |
1146 | pictureDelegate = new CPictureDelegate(this); |
1146 | pictureDelegate = new CPictureDelegate(this); |
- | 1147 | pictureDelegate->setTableView(ui->tableView); |
|
1147 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1148 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1148 | 1149 | ||
1149 | /*
|
1150 | /*
|
1150 | for (int i=0; i < mymodel->rowCount(); i++){
|
1151 | for (int i=0; i < mymodel->rowCount(); i++){
|
1151 | ui->tableView->setRowHeight(i, 100);
|
1152 | ui->tableView->setRowHeight(i, 100);
|
1152 | }
|
1153 | }
|
1153 | */
|
1154 | */
|
1154 | 1155 | ||
1155 | }
|
1156 | }
|
1156 | 1157 | ||
1157 | 1158 | ||
1158 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1159 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1159 | 1160 | ||
1160 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1161 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1161 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1162 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1162 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1163 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1163 | ui->tableView_2->setModel(modelForDescription); |
1164 | ui->tableView_2->setModel(modelForDescription); |
1164 | ui->tableView_2->setAlternatingRowColors(true); |
1165 | ui->tableView_2->setAlternatingRowColors(true); |
1165 | ui->tableView_2->resizeColumnsToContents(); |
1166 | ui->tableView_2->resizeColumnsToContents(); |
1166 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1167 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1167 | }
|
1168 | }
|
1168 | 1169 | ||
1169 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1170 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1170 | 1171 | ||
1171 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1172 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1172 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1173 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1173 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1174 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1174 | ui->tableView_3->setModel(modelForPointers); |
1175 | ui->tableView_3->setModel(modelForPointers); |
1175 | delegateForDefaultValueColomn.getItems(); |
1176 | delegateForDefaultValueColomn.getItems(); |
1176 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1177 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1177 | 1178 | ||
1178 | // ui->tableView_3->resizeColumnsToContents();
|
1179 | // ui->tableView_3->resizeColumnsToContents();
|
1179 | 1180 | ||
1180 | }
|
1181 | }
|
1181 | 1182 |