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