Редакция 86 | Редакция 134 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 86 | Редакция 87 | ||
---|---|---|---|
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);
|
13 | // settdialog = new SettingsDialog(this);
|
14 | ///////////////////////////////////////////////////// settdialog.show();
|
14 | ///////////////////////////////////////////////////// settdialog.show();
|
15 | sql.setDatabaseName(tr("an_db")); |
15 | sql.setDatabaseName(tr("an_db")); |
16 | 16 | ||
17 | /*
|
17 | /*
|
18 | field = new TableField(tr("Ñîòðóäíèêè"), this);
|
18 | field = new TableField(tr("Ñîòðóäíèêè"), this);
|
19 | field->setNotNull(true);
|
19 | field->setNotNull(true);
|
20 | field->setDefaultValue(tr("ñîòðóäíèê"));
|
20 | field->setDefaultValue(tr("ñîòðóäíèê"));
|
21 | 21 | ||
22 | table = new SqlTable (tr("NewTable"), this);
|
22 | table = new SqlTable (tr("NewTable"), this);
|
23 | table->setName(tr("NewTable"));
|
23 | table->setName(tr("NewTable"));
|
24 | table->fields().at(0)->setNotNull(true);
|
24 | table->fields().at(0)->setNotNull(true);
|
25 | if (!(table->setPrimaryKey(tr("ID")))) {
|
25 | if (!(table->setPrimaryKey(tr("ID")))) {
|
26 | ui->label_3->setText(table->lastError());
|
26 | ui->label_3->setText(table->lastError());
|
27 | }
|
27 | }
|
28 | else ui->label_3->setText(table->primaryKey());
|
28 | else ui->label_3->setText(table->primaryKey());
|
29 | table->append(field);
|
29 | table->append(field);
|
30 | 30 | ||
31 | field = new TableField(tr("Êîìïüþòåðû"), this);
|
31 | field = new TableField(tr("Êîìïüþòåðû"), this);
|
32 | field->setNotNull(true);
|
32 | field->setNotNull(true);
|
33 | field->setDefaultValue(tr("êîìïüþòåð"));
|
33 | field->setDefaultValue(tr("êîìïüþòåð"));
|
34 | table->append(field);
|
34 | table->append(field);
|
35 | 35 | ||
36 | field = new TableField(tr("Ìîíèòîðû"), this);
|
36 | field = new TableField(tr("Ìîíèòîðû"), this);
|
37 | field->setNotNull(true);
|
37 | field->setNotNull(true);
|
38 | field->setDefaultValue(tr("ìîíèòîð"));
|
38 | field->setDefaultValue(tr("ìîíèòîð"));
|
39 | table->append(field);
|
39 | table->append(field);
|
40 | 40 | ||
41 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this);
|
41 | field = new TableField(tr("Êîëè÷åñòâî (øòóê)"), this);
|
42 | field->setNotNull(true);
|
42 | field->setNotNull(true);
|
43 | field->setType(tr("INTEGER"));
|
43 | field->setType(tr("INTEGER"));
|
44 | field->setDefaultValue(tr("1"));
|
44 | field->setDefaultValue(tr("1"));
|
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(false);
|
48 | field->setNotNull(false);
|
49 | field->setType(tr("DATE"));
|
49 | field->setType(tr("DATE"));
|
50 | field->setDefaultValue(tr("NULL"));
|
50 | field->setDefaultValue(tr("NULL"));
|
51 | table->append(field);
|
51 | table->append(field);
|
52 | 52 | ||
53 | ui->label_2->setText(table->name());
|
53 | ui->label_2->setText(table->name());
|
54 | ui->label->setText(table->fields().at(0)->sqlString());
|
54 | ui->label->setText(table->fields().at(0)->sqlString());
|
55 | ui->label_4->setText(table->sqlString());
|
55 | ui->label_4->setText(table->sqlString());
|
56 | ////// ui->lineEdit->insert(table->sqlString());
|
56 | ////// ui->lineEdit->insert(table->sqlString());
|
57 | 57 | ||
58 | */
|
58 | */
|
59 | /**********************************************
|
59 | /**********************************************
|
60 | 60 | ||
61 | QTextDocument *document;
|
61 | QTextDocument *document;
|
62 | // = ui->textEdit->document();
|
62 | // = ui->textEdit->document();
|
63 | QTextCursor *cursor;
|
63 | QTextCursor *cursor;
|
64 | 64 | ||
65 | document = ui->textEdit->document();
|
65 | document = ui->textEdit->document();
|
66 | cursor = new QTextCursor(document);
|
66 | cursor = new QTextCursor(document);
|
67 | cursor->movePosition(QTextCursor::Start);
|
67 | cursor->movePosition(QTextCursor::Start);
|
68 | QTextCharFormat format(cursor->charFormat());
|
68 | QTextCharFormat format(cursor->charFormat());
|
69 | //format.setFontFamily("Courier");
|
69 | //format.setFontFamily("Courier");
|
70 | format.setFontFamily("Arial");
|
70 | format.setFontFamily("Arial");
|
71 | //format.setFontItalic(false);
|
71 | //format.setFontItalic(false);
|
72 | 72 | ||
73 | format.setFontWeight(QFont::Normal);
|
73 | format.setFontWeight(QFont::Normal);
|
74 | QTextCharFormat boldFormat = format;
|
74 | QTextCharFormat boldFormat = format;
|
75 | boldFormat.setFontWeight(QFont::Bold);
|
75 | boldFormat.setFontWeight(QFont::Bold);
|
76 | 76 | ||
77 | QTextCharFormat italicFormat = format;
|
77 | QTextCharFormat italicFormat = format;
|
78 | //format.setFontFamily("Courier");
|
78 | //format.setFontFamily("Courier");
|
79 | // format.setFontFamily("Arial");
|
79 | // format.setFontFamily("Arial");
|
80 | italicFormat.setFontItalic(true);
|
80 | italicFormat.setFontItalic(true);
|
81 | 81 | ||
82 | cursor->insertText(table->sqlString(), format);
|
82 | cursor->insertText(table->sqlString(), format);
|
83 | 83 | ||
84 | ****************************************************/
|
84 | ****************************************************/
|
85 | 85 | ||
86 | QString errorString;
|
86 | QString errorString;
|
87 | 87 | ||
88 | sql.setDatabaseName(tr("an_db")); |
88 | sql.setDatabaseName(tr("an_db")); |
89 | sql.setHostName(tr("localhost")); |
89 | sql.setHostName(tr("localhost")); |
90 | sql.setUserName(tr("an")); |
90 | sql.setUserName(tr("an")); |
91 | sql.setPassword(tr("393939")); |
91 | sql.setPassword(tr("393939")); |
92 | 92 | ||
93 | bool ok; |
93 | bool ok; |
94 | ok = sql.connect(); |
94 | ok = sql.connect(); |
95 | if (!ok) { |
95 | if (!ok) { |
96 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
96 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
97 | this, // Ðîäèòåëüñêèé âèäæåò. |
97 | this, // Ðîäèòåëüñêèé âèäæåò. |
98 | QObject::tr("Database Error"), // Çàãîëîâîê. |
98 | QObject::tr("Database Error"), // Çàãîëîâîê. |
99 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
99 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
100 | 100 | ||
101 | }
|
101 | }
|
102 | else { |
102 | else { |
103 | 103 | ||
104 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
104 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
105 | this, // Ðîäèòåëüñêèé âèäæåò. |
105 | this, // Ðîäèòåëüñêèé âèäæåò. |
106 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
106 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
107 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
107 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
108 | 108 | ||
109 | 109 | ||
110 | 110 | ||
111 | 111 | ||
112 | 112 | ||
113 | }
|
113 | }
|
114 | 114 | ||
115 | /*
|
115 | /*
|
116 | ok = sql.createTable(table);
|
116 | ok = sql.createTable(table);
|
117 | if (!ok) {
|
117 | if (!ok) {
|
118 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
118 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
119 | this, // Ðîäèòåëüñêèé âèäæåò.
|
119 | this, // Ðîäèòåëüñêèé âèäæåò.
|
120 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
120 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
121 | sql.lasError()); // Òåêñò ñîîáùåíèÿ.
|
121 | sql.lasError()); // Òåêñò ñîîáùåíèÿ.
|
122 | }
|
122 | }
|
123 | else {
|
123 | else {
|
124 | 124 | ||
125 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
125 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
126 | this, // Ðîäèòåëüñêèé âèäæåò.
|
126 | this, // Ðîäèòåëüñêèé âèäæåò.
|
127 | QObject::tr("Database Connect"), // Çàãîëîâîê.
|
127 | QObject::tr("Database Connect"), // Çàãîëîâîê.
|
128 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
|
128 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
|
129 | }
|
129 | }
|
130 | 130 | ||
131 | 131 | ||
132 | 132 | ||
133 | */
|
133 | */
|
134 | 134 | ||
135 | ok = sql.createListOfClassesTable(); |
135 | ok = sql.createListOfClassesTable(); |
136 | 136 | ||
137 | if (!ok) { |
137 | if (!ok) { |
138 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
138 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
139 | this, // Ðîäèòåëüñêèé âèäæåò. |
139 | this, // Ðîäèòåëüñêèé âèäæåò. |
140 | QObject::tr("Database Error"), // Çàãîëîâîê. |
140 | QObject::tr("Database Error"), // Çàãîëîâîê. |
141 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
141 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
142 | 142 | ||
143 | }
|
143 | }
|
144 | else { |
144 | else { |
145 | 145 | ||
146 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
146 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
147 | this, // Ðîäèòåëüñêèé âèäæåò. |
147 | this, // Ðîäèòåëüñêèé âèäæåò. |
148 | QObject::tr("Database Create"), // Çàãîëîâîê. |
148 | QObject::tr("Database Create"), // Çàãîëîâîê. |
149 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
149 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
150 | }
|
150 | }
|
151 | 151 | ||
152 | 152 | ||
153 | 153 | ||
154 | 154 | ||
155 | ok = sql.createDescriptionOfClassesTable(); |
155 | ok = sql.createDescriptionOfClassesTable(); |
156 | 156 | ||
157 | if (!ok) { |
157 | if (!ok) { |
158 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
158 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
159 | this, // Ðîäèòåëüñêèé âèäæåò. |
159 | this, // Ðîäèòåëüñêèé âèäæåò. |
160 | QObject::tr("Database Error"), // Çàãîëîâîê. |
160 | QObject::tr("Database Error"), // Çàãîëîâîê. |
161 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
161 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
162 | 162 | ||
163 | }
|
163 | }
|
164 | else { |
164 | else { |
165 | 165 | ||
166 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
166 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
167 | this, // Ðîäèòåëüñêèé âèäæåò. |
167 | this, // Ðîäèòåëüñêèé âèäæåò. |
168 | QObject::tr("Database Create"), // Çàãîëîâîê. |
168 | QObject::tr("Database Create"), // Çàãîëîâîê. |
169 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
169 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
170 | }
|
170 | }
|
171 | 171 | ||
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | 176 | ||
177 | 177 | ||
178 | model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà |
178 | model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà |
179 | tableForInstance = new QTableView(); |
179 | tableForInstance = new QTableView(); |
180 | mymodel = new MyModel(this); |
180 | mymodel = new MyModel(this); |
181 | modelForPointers = new ModelForPointers(this); // // ìîäåëü äëÿ òàáëèöû ñ óêàçàòåëÿìè |
181 | modelForPointers = new ModelForPointers(this); // // ìîäåëü äëÿ òàáëèöû ñ óêàçàòåëÿìè |
182 | 182 | ||
183 | //modelForDescription = new QSqlTableModel(this);
|
183 | //modelForDescription = new QSqlTableModel(this);
|
184 | modelForDescription = new ModelForDescriptionTable(this); |
184 | modelForDescription = new ModelForDescriptionTable(this); |
185 | 185 | ||
186 | 186 | ||
187 | /////////////////model->setTable(tr("ListOfClasses"));
|
187 | /////////////////model->setTable(tr("ListOfClasses"));
|
188 | mymodel->setTable(tr("ListOfClasses")); |
188 | mymodel->setTable(tr("ListOfClasses")); |
189 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
189 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
190 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
190 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
191 | 191 | ||
192 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
192 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
193 | 193 | ||
194 | modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit); |
194 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
- | 195 | ||
- | 196 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
|
- | 197 | ||
195 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
198 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
196 | 199 | ||
197 | 200 | ||
198 | 201 | ||
199 | 202 | ||
200 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
203 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
201 | 204 | ||
202 | 205 | ||
203 | 206 | ||
204 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
207 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
205 | mymodel->setSort(0, Qt::AscendingOrder); |
208 | mymodel->setSort(0, Qt::AscendingOrder); |
206 | modelForDescription->setSort(0, Qt::AscendingOrder); |
209 | modelForDescription->setSort(0, Qt::AscendingOrder); |
207 | modelForPointers->setSort(0, Qt::AscendingOrder); |
210 | modelForPointers->setSort(0, Qt::AscendingOrder); |
208 | 211 | ||
209 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
212 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
210 | ////////////////////model->select();
|
213 | ////////////////////model->select();
|
211 | mymodel->select(); |
214 | mymodel->select(); |
212 | // modelForPointers->select();
|
215 | // modelForPointers->select();
|
213 | 216 | ||
214 | 217 | ||
215 | 218 | ||
216 | 219 | ||
217 | /////////////////////////model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
|
220 | /////////////////////////model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
|
218 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
221 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
219 | 222 | ||
220 | 223 | ||
221 | 224 | ||
222 | ////////////////////////model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
|
225 | ////////////////////////model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
|
223 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
226 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
224 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
227 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
225 | 228 | ||
226 | //ui->tableView_3->setModel(modelForPointers);
|
229 | //ui->tableView_3->setModel(modelForPointers);
|
227 | 230 | ||
228 | //ui->tableView->setModel(model);
|
231 | //ui->tableView->setModel(model);
|
229 | ui->tableView->setModel(mymodel); |
232 | ui->tableView->setModel(mymodel); |
230 | //tableForDescription = new QTableView();
|
233 | //tableForDescription = new QTableView();
|
231 | ui->tableView_2->setModel(modelForDescription); |
234 | ui->tableView_2->setModel(modelForDescription); |
232 | ui->tableView_2->setAlternatingRowColors(true); |
235 | ui->tableView_2->setAlternatingRowColors(true); |
233 | ui->tableView_2->resizeColumnsToContents(); |
236 | ui->tableView_2->resizeColumnsToContents(); |
234 | //tableForDescription->show();
|
237 | //tableForDescription->show();
|
235 | 238 | ||
236 | 239 | ||
237 | ui->tableView->setAlternatingRowColors(true); |
240 | ui->tableView->setAlternatingRowColors(true); |
238 | ui->tableView->resizeColumnsToContents(); |
241 | ui->tableView->resizeColumnsToContents(); |
239 | 242 | ||
240 | ui->tableView->hideColumn(0); |
243 | ui->tableView->hideColumn(0); |
241 | ui->tableView->hideColumn(3); |
244 | ui->tableView->hideColumn(3); |
242 | ui->tableView->hideColumn(2); |
245 | ui->tableView->hideColumn(2); |
243 | 246 | ||
244 | /*
|
247 | /*
|
245 | ui->tableView_2->hideColumn(0);
|
248 | ui->tableView_2->hideColumn(0);
|
246 | ui->tableView_2->hideColumn(5);
|
249 | ui->tableView_2->hideColumn(5);
|
247 | ui->tableView_2->hideColumn(2);
|
250 | ui->tableView_2->hideColumn(2);
|
248 | */
|
251 | */
|
249 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
252 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
250 | 253 | ||
251 | currIndexOfClassesTable = mymodel->index(0, 1); |
254 | currIndexOfClassesTable = mymodel->index(0, 1); |
252 | QModelIndex index_temp;
|
255 | QModelIndex index_temp;
|
253 | 256 | ||
254 | 257 | ||
255 | 258 | ||
256 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
259 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
257 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
260 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
258 | 261 | ||
259 | QModelIndex topLeft;
|
262 | QModelIndex topLeft;
|
260 | QModelIndex bottomRight;
|
263 | QModelIndex bottomRight;
|
261 | 264 | ||
262 | topLeft = mymodel->index(0, 0, QModelIndex()); |
265 | topLeft = mymodel->index(0, 0, QModelIndex()); |
263 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
266 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
264 | 267 | ||
265 | QItemSelection selection(topLeft, bottomRight); |
268 | QItemSelection selection(topLeft, bottomRight); |
266 | selectionModel->select(selection, QItemSelectionModel::Select); |
269 | selectionModel->select(selection, QItemSelectionModel::Select); |
267 | 270 | ||
268 | 271 | ||
269 | QString class_indx, class_instance;
|
272 | QString class_indx, class_instance;
|
270 | QString str_fltr = tr("ClassIdentifer = "); |
273 | QString str_fltr = tr("ClassIdentifer = "); |
271 | class_indx = mymodel->data(mymodel->index(0,0)).toString(); |
274 | class_indx = mymodel->data(mymodel->index(0,0)).toString(); |
272 | class_instance = mymodel->data(mymodel->index(0,3)).toString(); |
275 | class_instance = mymodel->data(mymodel->index(0,3)).toString(); |
273 | 276 | ||
274 | currInctanceTable = class_instance; // |
277 | currInctanceTable = class_instance; // |
275 | modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
278 | modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
276 | //class_instance.append(tr("_inctance"));
|
279 | //class_instance.append(tr("_inctance"));
|
277 | str_fltr.append(class_indx); |
280 | str_fltr.append(class_indx); |
278 | str_fltr.append(tr(" AND FieldType <> \"pointer\"")); |
281 | str_fltr.append(tr(" AND FieldType <> \"pointer\"")); |
279 | 282 | ||
280 | model->setTable(class_instance); |
283 | model->setTable(class_instance); |
281 | //model->setTable(tr("memory"));
|
284 | //model->setTable(tr("memory"));
|
282 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
285 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
283 | model->select(); |
286 | model->select(); |
284 | tableForInstance->setModel(model); |
287 | tableForInstance->setModel(model); |
285 | tableForInstance->resizeColumnsToContents(); |
288 | tableForInstance->resizeColumnsToContents(); |
286 | tableForInstance->setWindowTitle(class_instance); |
289 | tableForInstance->setWindowTitle(class_instance); |
287 | tableForInstance->show(); |
290 | tableForInstance->show(); |
288 | 291 | ||
289 | modelForDescription->setFilter(str_fltr); |
292 | modelForDescription->setFilter(str_fltr); |
290 | modelForDescription->select(); |
293 | modelForDescription->select(); |
291 | ui->tableView_2->resizeColumnsToContents(); |
294 | ui->tableView_2->resizeColumnsToContents(); |
292 | 295 | ||
293 | 296 | ||
294 | str_fltr = tr("ClassIdentifer = "); |
297 | str_fltr = tr("ClassIdentifer = "); |
295 | modelForPointers->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
298 | modelForPointers->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
296 | str_fltr.append(class_indx); |
299 | str_fltr.append(class_indx); |
297 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
300 | str_fltr.append(tr(" AND FieldType = \"pointer\"")); |
298 | // str_fltr.append( tr(" FieldType = pointer "));
|
301 | // str_fltr.append( tr(" FieldType = pointer "));
|
299 | 302 | ||
300 | 303 | ||
301 | 304 | ||
302 | modelForPointers->setFilter(str_fltr); |
305 | modelForPointers->setFilter(str_fltr); |
303 | modelForPointers->select(); |
306 | modelForPointers->select(); |
304 | ui->tableView_3->setModel(modelForPointers); |
307 | ui->tableView_3->setModel(modelForPointers); |
305 | ui->tableView_3->resizeColumnsToContents(); |
308 | ui->tableView_3->resizeColumnsToContents(); |
306 | 309 | ||
307 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
310 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
308 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
311 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
309 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
312 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
310 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
313 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
311 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
314 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
312 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
315 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
313 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
316 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
314 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
317 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
315 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
318 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
316 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
319 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
317 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
320 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
318 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
321 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
319 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
322 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
320 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû |
323 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû |
321 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû
|
324 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû
|
- | 325 | ||
- | 326 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // óäàëèòü âûäåëåííûå êëàññû |
|
322 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå ïîëåé ïðîèçîøëè èçìåíåíèÿ |
327 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå ïîëåé ïðîèçîøëè èçìåíåíèÿ |
323 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå óêàçàòåëåé ïðîèçîøëè èçìåíåíèÿ |
328 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå óêàçàòåëåé ïðîèçîøëè èçìåíåíèÿ |
324 | 329 | ||
325 | 330 | ||
- | 331 | ||
326 | }
|
332 | }
|
327 | 333 | ||
328 | 334 | ||
329 | 335 | ||
330 | 336 | ||
331 | 337 | ||
332 | 338 | ||
333 | 339 | ||
334 | 340 | ||
335 | 341 | ||
336 | 342 | ||
337 | 343 | ||
338 | ClassEditor::~ClassEditor() |
344 | ClassEditor::~ClassEditor() |
339 | {
|
345 | {
|
340 | delete ui; |
346 | delete ui; |
341 | delete model; |
347 | delete model; |
342 | delete tableForInstance; |
348 | delete tableForInstance; |
343 | // delete field;
|
349 | // delete field;
|
344 | // delete settdialog;
|
350 | // delete settdialog;
|
345 | }
|
351 | }
|
346 | 352 | ||
347 | void ClassEditor::changeEvent(QEvent *e) |
353 | void ClassEditor::changeEvent(QEvent *e) |
348 | {
|
354 | {
|
349 | QMainWindow::changeEvent(e); |
355 | QMainWindow::changeEvent(e); |
350 | switch (e->type()) { |
356 | switch (e->type()) { |
351 | case QEvent::LanguageChange: |
357 | case QEvent::LanguageChange: |
352 | ui->retranslateUi(this); |
358 | ui->retranslateUi(this); |
353 | break; |
359 | break; |
354 | default: |
360 | default: |
355 | break; |
361 | break; |
356 | }
|
362 | }
|
357 | }
|
363 | }
|
358 | 364 | ||
359 | 365 | ||
360 | /*
|
366 | /*
|
361 | void ClassEditor::addNewClass(){
|
367 | void ClassEditor::addNewClass(){
|
362 | 368 | ||
363 | int row = model->rowCount();
|
369 | int row = model->rowCount();
|
364 | 370 | ||
365 | model->insertRows(row, 1);
|
371 | model->insertRows(row, 1);
|
366 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
372 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
367 | 373 | ||
368 | 374 | ||
369 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
375 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
370 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
376 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
371 | 377 | ||
372 | 378 | ||
373 | model->submitAll();
|
379 | model->submitAll();
|
374 | 380 | ||
375 | row = model->rowCount();
|
381 | row = model->rowCount();
|
376 | QString tmp_str;
|
382 | QString tmp_str;
|
377 | int i_tmp;
|
383 | int i_tmp;
|
378 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
384 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
379 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
385 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
380 | 386 | ||
381 | tmp_str.append(tr("_Inctance"));
|
387 | tmp_str.append(tr("_Inctance"));
|
382 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
388 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
383 | 389 | ||
384 | model->submitAll();
|
390 | model->submitAll();
|
385 | mymodel->select();
|
391 | mymodel->select();
|
386 | 392 | ||
387 | 393 | ||
388 | }
|
394 | }
|
389 | */
|
395 | */
|
390 | 396 | ||
391 | void ClassEditor::addNewClass_new(){ |
397 | void ClassEditor::addNewClass_new(){ |
392 | 398 | ||
393 | int row = mymodel->rowCount(); |
399 | int row = mymodel->rowCount(); |
394 | 400 | ||
395 | mymodel->insertRows(row, 1); |
401 | mymodel->insertRows(row, 1); |
396 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
402 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
397 | 403 | ||
398 | 404 | ||
399 | mymodel->submitAll(); |
405 | mymodel->submitAll(); |
400 | row = mymodel->rowCount(); |
406 | row = mymodel->rowCount(); |
401 | QString tmp_str1, sql_str;
|
407 | QString tmp_str1, sql_str;
|
402 | int i_tmp1; |
408 | int i_tmp1; |
403 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
409 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
404 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
410 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
405 | 411 | ||
406 | tmp_str1.append(tr("_Inctance")); |
412 | tmp_str1.append(tr("_Inctance")); |
407 | SqlTable* tbl; |
413 | SqlTable* tbl; |
408 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
414 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
409 | sql_str = tbl->sqlString(); |
415 | sql_str = tbl->sqlString(); |
410 | bool ok; |
416 | bool ok; |
411 | 417 | ||
412 | ok = sql.createTable(tbl); |
418 | ok = sql.createTable(tbl); |
413 | 419 | ||
414 | if (!ok) { |
420 | if (!ok) { |
415 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
421 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
416 | this, // Ðîäèòåëüñêèé âèäæåò. |
422 | this, // Ðîäèòåëüñêèé âèäæåò. |
417 | QObject::tr("Database Error"), // Çàãîëîâîê. |
423 | QObject::tr("Database Error"), // Çàãîëîâîê. |
418 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
424 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
419 | delete tbl; |
425 | delete tbl; |
420 | mymodel->removeRow(row-1); |
426 | mymodel->removeRow(row-1); |
421 | mymodel->submitAll(); |
427 | mymodel->submitAll(); |
422 | mymodel->select(); |
428 | mymodel->select(); |
423 | ui->tableView_2->resizeRowsToContents(); |
429 | ui->tableView_2->resizeRowsToContents(); |
424 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
430 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
425 | 431 | ||
426 | }
|
432 | }
|
427 | 433 | ||
428 | delete tbl; |
434 | delete tbl; |
429 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
435 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
430 | 436 | ||
431 | 437 | ||
432 | 438 | ||
433 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
439 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
434 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
440 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
435 | 441 | ||
436 | 442 | ||
437 | //mymodel->submitAll();
|
443 | //mymodel->submitAll();
|
438 | 444 | ||
439 | //row = mymodel->rowCount();
|
445 | //row = mymodel->rowCount();
|
440 | 446 | ||
441 | 447 | ||
442 | //mymodel->select();
|
448 | //mymodel->select();
|
443 | 449 | ||
444 | 450 | ||
445 | }
|
451 | }
|
446 | 452 | ||
447 | 453 | ||
448 | void ClassEditor::addNewField(){ |
454 | void ClassEditor::addNewField(){ |
449 | // QSqlRecord rec = mymodel->record(1);
|
455 | // QSqlRecord rec = mymodel->record(1);
|
450 | //bool ok;
|
456 | //bool ok;
|
451 | //ok = rec.isEmpty();
|
457 | //ok = rec.isEmpty();
|
452 | //QString currientClassID;
|
458 | //QString currientClassID;
|
453 | //currientClassID = rec.value(1).toString();
|
459 | //currientClassID = rec.value(1).toString();
|
454 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
460 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
455 | QString query_str = tr("ALTER TABLE "); |
461 | QString query_str = tr("ALTER TABLE "); |
456 | QString db_error;
|
462 | QString db_error;
|
457 | QSqlQuery q;
|
463 | QSqlQuery q;
|
458 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
464 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
459 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
465 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
460 | query_str.append( Inctance_str); |
466 | query_str.append( Inctance_str); |
461 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
467 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
462 | bool ok = q.prepare(query_str); |
468 | bool ok = q.prepare(query_str); |
463 | 469 | ||
464 | ok = q.exec(); |
470 | ok = q.exec(); |
465 | if (!ok) { |
471 | if (!ok) { |
466 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
472 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
467 | this, // Ðîäèòåëüñêèé âèäæåò. |
473 | this, // Ðîäèòåëüñêèé âèäæåò. |
468 | QObject::tr("Database Error"), // Çàãîëîâîê. |
474 | QObject::tr("Database Error"), // Çàãîëîâîê. |
469 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
475 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
470 | 476 | ||
471 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
477 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
472 | 478 | ||
473 | }
|
479 | }
|
474 | 480 | ||
475 | int row = modelForDescription->rowCount(); |
481 | int row = modelForDescription->rowCount(); |
476 | modelForDescription->insertRows(row, 1); |
482 | modelForDescription->insertRows(row, 1); |
477 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
483 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
478 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
484 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
479 | 485 | ||
480 | modelForDescription->submitAll(); |
486 | modelForDescription->submitAll(); |
481 | 487 | ||
482 | delete model; |
488 | delete model; |
483 | delete tableForInstance; |
489 | delete tableForInstance; |
484 | model = new QSqlTableModel(); |
490 | model = new QSqlTableModel(); |
485 | tableForInstance = new QTableView(); |
491 | tableForInstance = new QTableView(); |
486 | model->setTable(Inctance_str); |
492 | model->setTable(Inctance_str); |
487 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
493 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
488 | tableForInstance->setModel(model); |
494 | tableForInstance->setModel(model); |
489 | tableForInstance->setWindowTitle(Inctance_str); |
495 | tableForInstance->setWindowTitle(Inctance_str); |
490 | tableForInstance->show(); |
496 | tableForInstance->show(); |
491 | }
|
497 | }
|
492 | 498 | ||
493 | 499 | ||
494 | 500 | ||
495 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
501 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
496 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
502 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
497 | QString query_str = tr("ALTER TABLE "); |
503 | QString query_str = tr("ALTER TABLE "); |
498 | QString db_error;
|
504 | QString db_error;
|
499 | QSqlQuery q;
|
505 | QSqlQuery q;
|
500 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
506 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
501 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
507 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
502 | query_str.append( Inctance_str); |
508 | query_str.append( Inctance_str); |
503 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
509 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
504 | bool ok = q.prepare(query_str); |
510 | bool ok = q.prepare(query_str); |
505 | 511 | ||
506 | ok = q.exec(); |
512 | ok = q.exec(); |
507 | if (!ok) { |
513 | if (!ok) { |
508 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
514 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
509 | this, // Ðîäèòåëüñêèé âèäæåò. |
515 | this, // Ðîäèòåëüñêèé âèäæåò. |
510 | QObject::tr("Database Error"), // Çàãîëîâîê. |
516 | QObject::tr("Database Error"), // Çàãîëîâîê. |
511 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
517 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
512 | 518 | ||
513 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
519 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
514 | 520 | ||
515 | }
|
521 | }
|
516 | 522 | ||
517 | 523 | ||
518 | int row = ClassEditor::modelForPointers->rowCount(); |
524 | int row = ClassEditor::modelForPointers->rowCount(); |
519 | modelForPointers->insertRows(row, 1); |
525 | modelForPointers->insertRows(row, 1); |
520 | 526 | ||
521 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
527 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
522 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
528 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
523 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
529 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
524 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
530 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
525 | 531 | ||
526 | 532 | ||
527 | modelForPointers->submitAll(); |
533 | modelForPointers->submitAll(); |
528 | 534 | ||
529 | ClassEditor::refreshInctance(); |
535 | ClassEditor::refreshInctance(); |
530 | 536 | ||
531 | 537 | ||
532 | 538 | ||
533 | 539 | ||
534 | 540 | ||
535 | 541 | ||
536 | 542 | ||
537 | 543 | ||
538 | 544 | ||
539 | }
|
545 | }
|
540 | 546 | ||
541 | 547 | ||
542 | 548 | ||
543 | 549 | ||
544 | 550 | ||
545 | // äîáàâëÿåì íîâûé êëàññ
|
551 | // äîáàâëÿåì íîâûé êëàññ
|
546 | void ClassEditor::on_pushButton_clicked(){ |
552 | void ClassEditor::on_pushButton_clicked(){ |
547 | //int i;
|
553 | //int i;
|
548 | //i++;
|
554 | //i++;
|
549 | /////ClassEditor::addNewClass();
|
555 | /////ClassEditor::addNewClass();
|
550 | ClassEditor::addNewClass_new(); |
556 | ClassEditor::addNewClass_new(); |
551 | mymodel->select(); |
557 | mymodel->select(); |
552 | //ui->tableView->setModel(mymodel);
|
558 | //ui->tableView->setModel(mymodel);
|
553 | 559 | ||
554 | }
|
560 | }
|
555 | 561 | ||
556 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
562 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
557 | int i, row, column; |
563 | int i, row, column; |
558 | i++; |
564 | i++; |
559 | row = index.row(); |
565 | row = index.row(); |
560 | column = index.column(); |
566 | column = index.column(); |
561 | currIndexOfClassesTable = index; |
567 | currIndexOfClassesTable = index; |
562 | QModelIndex index_tmp, index_instance;
|
568 | QModelIndex index_tmp, index_instance;
|
563 | QString tmp_str, filter_str, instance_str;
|
569 | QString tmp_str, filter_str, instance_str;
|
564 | index_tmp = ui->tableView->model()->index(row, 0); |
570 | index_tmp = ui->tableView->model()->index(row, 0); |
565 | index_instance = ui->tableView->model()->index(row, 3); |
571 | index_instance = ui->tableView->model()->index(row, 3); |
566 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
572 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
567 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
573 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
568 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
574 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
569 | modelForPointers->setInctance(instance_str); |
575 | modelForPointers->setInctance(instance_str); |
570 | 576 | ||
571 | 577 | ||
572 | 578 | ||
573 | // instance_str.append(tr("_inctance"));
|
579 | // instance_str.append(tr("_inctance"));
|
574 | /*
|
580 | /*
|
575 | Inctance_model.clear();
|
581 | Inctance_model.clear();
|
576 | Inctance_model.setTable(instance_str);
|
582 | Inctance_model.setTable(instance_str);
|
577 | Inctance_model.select();
|
583 | Inctance_model.select();
|
578 | tableForInstance_new.setModel(&Inctance_model);
|
584 | tableForInstance_new.setModel(&Inctance_model);
|
579 | tableForInstance_new.show();
|
585 | tableForInstance_new.show();
|
580 | */
|
586 | */
|
581 | // model->clear();
|
587 | // model->clear();
|
582 | tableForInstance->close(); |
588 | tableForInstance->close(); |
583 | delete model; |
589 | delete model; |
584 | delete tableForInstance; |
590 | delete tableForInstance; |
585 | model = new QSqlTableModel(); |
591 | model = new QSqlTableModel(); |
586 | tableForInstance = new QTableView(); |
592 | tableForInstance = new QTableView(); |
587 | model->setTable(instance_str); |
593 | model->setTable(instance_str); |
588 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
594 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
589 | tableForInstance->setModel(model); |
595 | tableForInstance->setModel(model); |
590 | 596 | ||
591 | model->select(); |
597 | model->select(); |
592 | tableForInstance->setWindowTitle(instance_str); |
598 | tableForInstance->setWindowTitle(instance_str); |
593 | tableForInstance->show(); |
599 | tableForInstance->show(); |
594 | 600 | ||
595 | // tableForInstance.setModel(model);
|
601 | // tableForInstance.setModel(model);
|
596 | tableForInstance->resizeColumnsToContents(); |
602 | tableForInstance->resizeColumnsToContents(); |
597 | 603 | ||
598 | currClassID = tmp_str; |
604 | currClassID = tmp_str; |
599 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
605 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
600 | filter_str = tr("ClassIdentifer = "); |
606 | filter_str = tr("ClassIdentifer = "); |
601 | filter_str.append(tmp_str); |
607 | filter_str.append(tmp_str); |
602 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
608 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
603 | modelForDescription->setFilter(filter_str); |
609 | modelForDescription->setFilter(filter_str); |
604 | modelForDescription->select(); |
610 | modelForDescription->select(); |
605 | ui->tableView_2->resizeColumnsToContents(); |
611 | ui->tableView_2->resizeColumnsToContents(); |
606 | 612 | ||
607 | filter_str = tr("ClassIdentifer = "); |
613 | filter_str = tr("ClassIdentifer = "); |
608 | filter_str.append(tmp_str); |
614 | filter_str.append(tmp_str); |
609 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
615 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
610 | modelForPointers->setFilter(filter_str); |
616 | modelForPointers->setFilter(filter_str); |
611 | modelForPointers->select(); |
617 | modelForPointers->select(); |
612 | ui->tableView_3->resizeColumnsToContents(); |
618 | ui->tableView_3->resizeColumnsToContents(); |
613 | 619 | ||
614 | 620 | ||
615 | 621 | ||
616 | 622 | ||
617 | i++; |
623 | i++; |
618 | }
|
624 | }
|
619 | 625 | ||
620 | 626 | ||
621 | 627 | ||
622 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
628 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
623 | QModelIndex model_index;
|
629 | QModelIndex model_index;
|
624 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
630 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
625 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
631 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
626 | QList<int> selectedRows; |
632 | QList<int> selectedRows; |
627 | selectedRows.clear(); |
633 | selectedRows.clear(); |
628 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
634 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
629 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
635 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
630 | 636 | ||
631 | }
|
637 | }
|
632 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
638 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
633 | 639 | ||
634 | 640 | ||
635 | for (int m =0; m < selectedRows.size(); ++m){ |
641 | for (int m =0; m < selectedRows.size(); ++m){ |
636 | 642 | ||
637 | ClassEditor::removeClass(selectedRows.at(m)); |
643 | ClassEditor::removeClass(selectedRows.at(m)); |
638 | 644 | ||
639 | 645 | ||
640 | 646 | ||
641 | }
|
647 | }
|
642 | mymodel->submitAll(); |
648 | mymodel->submitAll(); |
643 | ClassEditor::modelForDescription->select(); |
649 | ClassEditor::modelForDescription->select(); |
644 | 650 | ||
645 | }
|
651 | }
|
646 | 652 | ||
647 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
653 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
648 | int i; |
654 | int i; |
649 | i++; |
655 | i++; |
650 | ClassEditor::addNewField(); |
656 | ClassEditor::addNewField(); |
651 | ClassEditor::modelForDescription->select(); |
657 | ClassEditor::modelForDescription->select(); |
652 | ui->tableView_2->resizeColumnsToContents(); |
658 | ui->tableView_2->resizeColumnsToContents(); |
653 | }
|
659 | }
|
654 | 660 | ||
655 | 661 | ||
656 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
662 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
657 | // int i;
|
663 | // int i;
|
658 | QModelIndex model_index;
|
664 | QModelIndex model_index;
|
659 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
665 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
660 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
666 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
661 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
667 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
662 | //model_index = mymodel->selec;
|
668 | //model_index = mymodel->selec;
|
663 | //modelList = ui->tableView->SelectItems;
|
669 | //modelList = ui->tableView->SelectItems;
|
664 | //i = indexes.size();
|
670 | //i = indexes.size();
|
665 | QList<int> selectedRows; |
671 | QList<int> selectedRows; |
666 | //indexes_fo_first_col.clear();
|
672 | //indexes_fo_first_col.clear();
|
667 | /*
|
673 | /*
|
668 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
674 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
669 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
675 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
670 | 676 | ||
671 | }
|
677 | }
|
672 | */
|
678 | */
|
673 | selectedRows.clear(); |
679 | selectedRows.clear(); |
674 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
680 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
675 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
681 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
676 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
682 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
677 | }
|
683 | }
|
678 | }
|
684 | }
|
679 | 685 | ||
680 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
686 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
681 | 687 | ||
682 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
688 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
683 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
689 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
684 | for (int m =0; m < selectedRows.size(); ++m){ |
690 | for (int m =0; m < selectedRows.size(); ++m){ |
685 | 691 | ||
686 | 692 | ||
687 | QString query_str;
|
693 | QString query_str;
|
688 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
694 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
689 | QSqlQuery q;
|
695 | QSqlQuery q;
|
690 | 696 | ||
691 | query_str.clear(); |
697 | query_str.clear(); |
692 | 698 | ||
693 | 699 | ||
694 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
700 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
695 | 701 | ||
696 | query_str.append(tr("ALTER TABLE ")); |
702 | query_str.append(tr("ALTER TABLE ")); |
697 | query_str.append(Inctance_str); |
703 | query_str.append(Inctance_str); |
698 | query_str.append(tr(" DROP COLUMN `")); |
704 | query_str.append(tr(" DROP COLUMN `")); |
699 | query_str.append(field_name_str); |
705 | query_str.append(field_name_str); |
700 | query_str.append(tr("`")); |
706 | query_str.append(tr("`")); |
701 | q.prepare(query_str); |
707 | q.prepare(query_str); |
702 | bool ok = q.exec(); |
708 | bool ok = q.exec(); |
703 | if (!ok) { |
709 | if (!ok) { |
704 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
710 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
705 | this, // Ðîäèòåëüñêèé âèäæåò. |
711 | this, // Ðîäèòåëüñêèé âèäæåò. |
706 | QObject::tr("Database Error"), // Çàãîëîâîê. |
712 | QObject::tr("Database Error"), // Çàãîëîâîê. |
707 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
713 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
708 | 714 | ||
709 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
715 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
710 | 716 | ||
711 | }
|
717 | }
|
712 | 718 | ||
713 | 719 | ||
714 | 720 | ||
715 | modelForDescription->removeRow(selectedRows.at(m)); |
721 | modelForDescription->removeRow(selectedRows.at(m)); |
716 | 722 | ||
717 | }
|
723 | }
|
718 | delete model; |
724 | delete model; |
719 | delete tableForInstance; |
725 | delete tableForInstance; |
720 | model = new QSqlTableModel(); |
726 | model = new QSqlTableModel(); |
721 | tableForInstance = new QTableView(); |
727 | tableForInstance = new QTableView(); |
722 | model->setTable(Inctance_str); |
728 | model->setTable(Inctance_str); |
723 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
729 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
724 | tableForInstance->setModel(model); |
730 | tableForInstance->setModel(model); |
725 | tableForInstance->setWindowTitle(Inctance_str); |
731 | tableForInstance->setWindowTitle(Inctance_str); |
726 | tableForInstance->show(); |
732 | tableForInstance->show(); |
727 | //i = selectedRows.size();
|
733 | //i = selectedRows.size();
|
728 | 734 | ||
729 | //if (i > 0) model_index = indexes.at(0);
|
735 | //if (i > 0) model_index = indexes.at(0);
|
730 | }
|
736 | }
|
731 | 737 | ||
732 | 738 | ||
- | 739 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
|
- | 740 | QModelIndex model_index;
|
|
- | 741 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
|
- | 742 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
|
- | 743 | QList<int> selectedRows; |
|
- | 744 | ||
- | 745 | selectedRows.clear(); |
|
- | 746 | ||
- | 747 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
|
- | 748 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
|
- | 749 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
|
- | 750 | }
|
|
- | 751 | }
|
|
- | 752 | ||
- | 753 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
|
- | 754 | ||
- | 755 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
|
- | 756 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
|
- | 757 | for (int m =0; m < selectedRows.size(); ++m){ |
|
- | 758 | ||
- | 759 | ||
- | 760 | QString query_str;
|
|
- | 761 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
|
- | 762 | QSqlQuery q;
|
|
- | 763 | ||
- | 764 | query_str.clear(); |
|
- | 765 | ||
- | 766 | ||
- | 767 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
|
- | 768 | ||
- | 769 | query_str.append(tr("ALTER TABLE ")); |
|
- | 770 | query_str.append(Inctance_str); |
|
- | 771 | query_str.append(tr(" DROP COLUMN `")); |
|
- | 772 | query_str.append(field_name_str); |
|
- | 773 | query_str.append(tr("`")); |
|
- | 774 | q.prepare(query_str); |
|
- | 775 | bool ok = q.exec(); |
|
- | 776 | if (!ok) { |
|
- | 777 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 778 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 779 | QObject::tr("Database Error"), // Çàãîëîâîê. |
|
- | 780 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
|
- | 781 | ||
- | 782 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
|
- | 783 | ||
- | 784 | }
|
|
- | 785 | ||
- | 786 | ||
- | 787 | ||
- | 788 | modelForPointers->removeRow(selectedRows.at(m)); |
|
- | 789 | ||
- | 790 | }
|
|
- | 791 | ||
- | 792 | ||
- | 793 | refreshInctance(); |
|
- | 794 | ||
- | 795 | ||
- | 796 | ||
- | 797 | }
|
|
- | 798 | ||
- | 799 | ||
- | 800 | ||
- | 801 | ||
- | 802 | ||
733 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
803 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
734 | int row; |
804 | int row; |
735 | row = ClassEditor::modelForDescription->rowCount(); |
805 | row = ClassEditor::modelForDescription->rowCount(); |
736 | ClassEditor::modelForDescription->removeRows(0, row); |
806 | ClassEditor::modelForDescription->removeRows(0, row); |
737 | ClassEditor::modelForDescription->submitAll(); |
807 | ClassEditor::modelForDescription->submitAll(); |
738 | }
|
808 | }
|
739 | 809 | ||
740 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
810 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
741 | 811 | ||
742 | int i; |
812 | int i; |
743 | i++; |
813 | i++; |
744 | ui->tableView->resizeColumnsToContents(); |
814 | ui->tableView->resizeColumnsToContents(); |
745 | 815 | ||
746 | 816 | ||
747 | 817 | ||
748 | 818 | ||
749 | 819 | ||
750 | }
|
820 | }
|
751 | 821 | ||
752 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
822 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
753 | ui->tableView_2->resizeColumnsToContents(); |
823 | ui->tableView_2->resizeColumnsToContents(); |
754 | 824 | ||
755 | /*
|
825 | /*
|
756 | QString instance_str;
|
826 | QString instance_str;
|
757 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
827 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
758 | tableForInstance->close();
|
828 | tableForInstance->close();
|
759 | delete model;
|
829 | delete model;
|
760 | delete tableForInstance;
|
830 | delete tableForInstance;
|
761 | model = new QSqlTableModel();
|
831 | model = new QSqlTableModel();
|
762 | tableForInstance = new QTableView();
|
832 | tableForInstance = new QTableView();
|
763 | model->setTable(instance_str);
|
833 | model->setTable(instance_str);
|
764 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
834 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
765 | tableForInstance->setModel(model);
|
835 | tableForInstance->setModel(model);
|
766 | 836 | ||
767 | model->select();
|
837 | model->select();
|
768 | tableForInstance->setWindowTitle(instance_str);
|
838 | tableForInstance->setWindowTitle(instance_str);
|
769 | tableForInstance->show();
|
839 | tableForInstance->show();
|
770 | */
|
840 | */
|
771 | }
|
841 | }
|
772 | 842 | ||
773 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
843 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
774 | if (is_checked) ui->tableView->showColumn(0); |
844 | if (is_checked) ui->tableView->showColumn(0); |
775 | else ui->tableView->hideColumn(0); |
845 | else ui->tableView->hideColumn(0); |
776 | ui->tableView->resizeColumnsToContents(); |
846 | ui->tableView->resizeColumnsToContents(); |
777 | }
|
847 | }
|
778 | 848 | ||
779 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
849 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
780 | if (is_checked) ui->tableView->showColumn(2); |
850 | if (is_checked) ui->tableView->showColumn(2); |
781 | else ui->tableView->hideColumn(2); |
851 | else ui->tableView->hideColumn(2); |
782 | ui->tableView->resizeColumnsToContents(); |
852 | ui->tableView->resizeColumnsToContents(); |
783 | }
|
853 | }
|
784 | 854 | ||
785 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
855 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
786 | if (is_checked) ui->tableView->showColumn(3); |
856 | if (is_checked) ui->tableView->showColumn(3); |
787 | else ui->tableView->hideColumn(3); |
857 | else ui->tableView->hideColumn(3); |
788 | ui->tableView->resizeColumnsToContents(); |
858 | ui->tableView->resizeColumnsToContents(); |
789 | }
|
859 | }
|
790 | 860 | ||
791 | 861 | ||
792 | 862 | ||
793 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
863 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
794 | int row; |
864 | int row; |
795 | row = ClassEditor::mymodel->rowCount(); |
865 | row = ClassEditor::mymodel->rowCount(); |
796 | for (int m=0; m < row; ++m){ |
866 | for (int m=0; m < row; ++m){ |
797 | ClassEditor::removeClass(0); |
867 | ClassEditor::removeClass(0); |
798 | //ClassEditor::mymodel->removeRows(0, row);
|
868 | //ClassEditor::mymodel->removeRows(0, row);
|
799 | }
|
869 | }
|
800 | ClassEditor::mymodel->submitAll(); |
870 | ClassEditor::mymodel->submitAll(); |
801 | ClassEditor::modelForDescription->select(); |
871 | ClassEditor::modelForDescription->select(); |
802 | }
|
872 | }
|
803 | 873 | ||
804 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
874 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
805 | QModelIndex index_tmp;
|
875 | QModelIndex index_tmp;
|
806 | QString tmp_str, filter_str;
|
876 | QString tmp_str, filter_str;
|
807 | index_tmp = ui->tableView->model()->index(class_row, 0); |
877 | index_tmp = ui->tableView->model()->index(class_row, 0); |
808 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
878 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
809 | currClassID = tmp_str; |
879 | currClassID = tmp_str; |
810 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
880 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
811 | filter_str = tr("ClassIdentifer = "); |
881 | filter_str = tr("ClassIdentifer = "); |
812 | filter_str.append(tmp_str); |
882 | filter_str.append(tmp_str); |
813 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
883 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
814 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
884 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
815 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
885 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
816 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
886 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
817 | ui->tableView->resizeColumnsToContents(); |
887 | ui->tableView->resizeColumnsToContents(); |
818 | ui->tableView_2->resizeColumnsToContents(); |
888 | ui->tableView_2->resizeColumnsToContents(); |
819 | 889 | ||
820 | }
|
890 | }
|
821 | 891 | ||
822 | 892 | ||
823 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
893 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
824 | ClassEditor::refreshInctance(); |
894 | ClassEditor::refreshInctance(); |
825 | }
|
895 | }
|
826 | 896 | ||
827 | 897 | ||
828 | 898 | ||
829 | 899 | ||
830 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
900 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
831 | 901 | ||
832 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
902 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
833 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
903 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
834 | delete model; |
904 | delete model; |
835 | delete tableForInstance; |
905 | delete tableForInstance; |
836 | model = new QSqlTableModel(); |
906 | model = new QSqlTableModel(); |
837 | tableForInstance = new QTableView(); |
907 | tableForInstance = new QTableView(); |
838 | model->setTable(Inctance_str); |
908 | model->setTable(Inctance_str); |
839 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
909 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
840 | model->select(); |
910 | model->select(); |
841 | tableForInstance->setModel(model); |
911 | tableForInstance->setModel(model); |
842 | tableForInstance->setWindowTitle(Inctance_str); |
912 | tableForInstance->setWindowTitle(Inctance_str); |
843 | tableForInstance->resizeRowsToContents(); |
913 | tableForInstance->resizeRowsToContents(); |
844 | tableForInstance->show(); |
914 | tableForInstance->show(); |
845 | 915 | ||
846 | }
|
916 | }
|
847 | 917 | ||
848 | 918 | ||
849 | 919 | ||
850 | 920 | ||
851 | void ClassEditor::on_action_newPointer(){ |
921 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
852 | ClassEditor::addNewPointer(); |
922 | ClassEditor::addNewPointer(); |
853 | ClassEditor::modelForPointers->select(); |
923 | ClassEditor::modelForPointers->select(); |
854 | ui->tableView_3->resizeColumnsToContents(); |
924 | ui->tableView_3->resizeColumnsToContents(); |
855 | 925 | ||
856 | }
|
926 | }
|
857 | 927 | ||
858 | 928 |