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