Редакция 73 | Редакция 75 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 73 | Редакция 74 | ||
---|---|---|---|
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 | //modelForDescription = new QSqlTableModel(this);
|
181 | //modelForDescription = new QSqlTableModel(this);
|
182 | modelForDescription = new ModelForDescriptionTable(this); |
182 | modelForDescription = new ModelForDescriptionTable(this); |
183 | 183 | ||
184 | 184 | ||
185 | /////////////////model->setTable(tr("ListOfClasses"));
|
185 | /////////////////model->setTable(tr("ListOfClasses"));
|
186 | mymodel->setTable(tr("ListOfClasses")); |
186 | mymodel->setTable(tr("ListOfClasses")); |
187 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
187 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
188 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
188 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
189 | 189 | ||
190 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
190 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
191 | 191 | ||
192 | 192 | ||
193 | 193 | ||
194 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
194 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
195 | 195 | ||
196 | 196 | ||
197 | 197 | ||
198 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
198 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
199 | mymodel->setSort(0, Qt::AscendingOrder); |
199 | mymodel->setSort(0, Qt::AscendingOrder); |
200 | modelForDescription->setSort(0, Qt::AscendingOrder); |
200 | modelForDescription->setSort(0, Qt::AscendingOrder); |
201 | 201 | ||
202 | 202 | ||
203 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
203 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
204 | ////////////////////model->select();
|
204 | ////////////////////model->select();
|
205 | mymodel->select(); |
205 | mymodel->select(); |
206 | 206 | ||
207 | 207 | ||
208 | 208 | ||
209 | 209 | ||
210 | /////////////////////////model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
|
210 | /////////////////////////model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
|
211 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
211 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
212 | 212 | ||
213 | 213 | ||
214 | 214 | ||
215 | ////////////////////////model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
|
215 | ////////////////////////model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
|
216 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
216 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
217 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
217 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
218 | 218 | ||
219 | 219 | ||
220 | //ui->tableView->setModel(model);
|
220 | //ui->tableView->setModel(model);
|
221 | ui->tableView->setModel(mymodel); |
221 | ui->tableView->setModel(mymodel); |
222 | //tableForDescription = new QTableView();
|
222 | //tableForDescription = new QTableView();
|
223 | ui->tableView_2->setModel(modelForDescription); |
223 | ui->tableView_2->setModel(modelForDescription); |
224 | ui->tableView_2->setAlternatingRowColors(true); |
224 | ui->tableView_2->setAlternatingRowColors(true); |
225 | ui->tableView_2->resizeColumnsToContents(); |
225 | ui->tableView_2->resizeColumnsToContents(); |
226 | //tableForDescription->show();
|
226 | //tableForDescription->show();
|
227 | 227 | ||
228 | 228 | ||
229 | ui->tableView->setAlternatingRowColors(true); |
229 | ui->tableView->setAlternatingRowColors(true); |
230 | ui->tableView->resizeColumnsToContents(); |
230 | ui->tableView->resizeColumnsToContents(); |
231 | 231 | ||
232 | ui->tableView->hideColumn(0); |
232 | ui->tableView->hideColumn(0); |
233 | ui->tableView->hideColumn(3); |
233 | ui->tableView->hideColumn(3); |
234 | ui->tableView->hideColumn(2); |
234 | ui->tableView->hideColumn(2); |
235 | 235 | ||
236 | /*
|
236 | /*
|
237 | ui->tableView_2->hideColumn(0);
|
237 | ui->tableView_2->hideColumn(0);
|
238 | ui->tableView_2->hideColumn(5);
|
238 | ui->tableView_2->hideColumn(5);
|
239 | ui->tableView_2->hideColumn(2);
|
239 | ui->tableView_2->hideColumn(2);
|
240 | */
|
240 | */
|
241 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
241 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
242 | 242 | ||
243 | currIndexOfClassesTable = mymodel->index(0, 1); |
243 | currIndexOfClassesTable = mymodel->index(0, 1); |
244 | QModelIndex index_temp;
|
244 | QModelIndex index_temp;
|
245 | 245 | ||
246 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
246 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
247 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
247 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
248 | 248 | ||
249 | QModelIndex topLeft;
|
249 | QModelIndex topLeft;
|
250 | QModelIndex bottomRight;
|
250 | QModelIndex bottomRight;
|
251 | 251 | ||
252 | topLeft = mymodel->index(0, 0, QModelIndex()); |
252 | topLeft = mymodel->index(0, 0, QModelIndex()); |
253 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
253 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
254 | 254 | ||
255 | QItemSelection selection(topLeft, bottomRight); |
255 | QItemSelection selection(topLeft, bottomRight); |
256 | selectionModel->select(selection, QItemSelectionModel::Select); |
256 | selectionModel->select(selection, QItemSelectionModel::Select); |
257 | 257 | ||
258 | 258 | ||
259 | QString class_indx, class_instance;
|
259 | QString class_indx, class_instance;
|
260 | QString str_fltr = tr("ClassIdentifer = "); |
260 | QString str_fltr = tr("ClassIdentifer = "); |
261 | class_indx = mymodel->data(mymodel->index(0,0)).toString(); |
261 | class_indx = mymodel->data(mymodel->index(0,0)).toString(); |
262 | class_instance = mymodel->data(mymodel->index(0,3)).toString(); |
262 | class_instance = mymodel->data(mymodel->index(0,3)).toString(); |
263 | //class_instance.append(tr("_inctance"));
|
263 | //class_instance.append(tr("_inctance"));
|
264 | str_fltr.append(class_indx); |
264 | str_fltr.append(class_indx); |
265 | 265 | ||
266 | model->setTable(class_instance); |
266 | model->setTable(class_instance); |
267 | //model->setTable(tr("memory"));
|
267 | //model->setTable(tr("memory"));
|
268 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
268 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
269 | model->select(); |
269 | model->select(); |
270 | tableForInstance->setModel(model); |
270 | tableForInstance->setModel(model); |
271 | tableForInstance->resizeColumnsToContents(); |
271 | tableForInstance->resizeColumnsToContents(); |
272 | tableForInstance->setWindowTitle(class_instance); |
272 | tableForInstance->setWindowTitle(class_instance); |
273 | tableForInstance->show(); |
273 | tableForInstance->show(); |
274 | 274 | ||
275 | modelForDescription->setFilter(str_fltr); |
275 | modelForDescription->setFilter(str_fltr); |
276 | modelForDescription->select(); |
276 | modelForDescription->select(); |
277 | ui->tableView_2->resizeColumnsToContents(); |
277 | ui->tableView_2->resizeColumnsToContents(); |
278 | 278 | ||
279 | 279 | ||
280 | 280 | ||
281 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
281 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
282 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
282 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
283 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
283 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
284 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
284 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
285 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
285 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
286 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
286 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
287 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
287 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
288 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
288 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
289 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
289 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
290 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
290 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
291 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
291 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
292 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
292 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
293 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
293 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
294 | }
|
294 | }
|
295 | 295 | ||
296 | 296 | ||
297 | 297 | ||
298 | 298 | ||
299 | 299 | ||
300 | 300 | ||
301 | 301 | ||
302 | 302 | ||
303 | 303 | ||
304 | 304 | ||
305 | 305 | ||
306 | ClassEditor::~ClassEditor() |
306 | ClassEditor::~ClassEditor() |
307 | {
|
307 | {
|
308 | delete ui; |
308 | delete ui; |
309 | delete model; |
309 | delete model; |
310 | delete tableForInstance; |
310 | delete tableForInstance; |
311 | // delete field;
|
311 | // delete field;
|
312 | // delete settdialog;
|
312 | // delete settdialog;
|
313 | }
|
313 | }
|
314 | 314 | ||
315 | void ClassEditor::changeEvent(QEvent *e) |
315 | void ClassEditor::changeEvent(QEvent *e) |
316 | {
|
316 | {
|
317 | QMainWindow::changeEvent(e); |
317 | QMainWindow::changeEvent(e); |
318 | switch (e->type()) { |
318 | switch (e->type()) { |
319 | case QEvent::LanguageChange: |
319 | case QEvent::LanguageChange: |
320 | ui->retranslateUi(this); |
320 | ui->retranslateUi(this); |
321 | break; |
321 | break; |
322 | default: |
322 | default: |
323 | break; |
323 | break; |
324 | }
|
324 | }
|
325 | }
|
325 | }
|
326 | 326 | ||
327 | 327 | ||
328 | /*
|
328 | /*
|
329 | void ClassEditor::addNewClass(){
|
329 | void ClassEditor::addNewClass(){
|
330 | 330 | ||
331 | int row = model->rowCount();
|
331 | int row = model->rowCount();
|
332 | 332 | ||
333 | model->insertRows(row, 1);
|
333 | model->insertRows(row, 1);
|
334 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
334 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
335 | 335 | ||
336 | 336 | ||
337 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
337 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
338 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
338 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
339 | 339 | ||
340 | 340 | ||
341 | model->submitAll();
|
341 | model->submitAll();
|
342 | 342 | ||
343 | row = model->rowCount();
|
343 | row = model->rowCount();
|
344 | QString tmp_str;
|
344 | QString tmp_str;
|
345 | int i_tmp;
|
345 | int i_tmp;
|
346 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
346 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
347 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
347 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
348 | 348 | ||
349 | tmp_str.append(tr("_Inctance"));
|
349 | tmp_str.append(tr("_Inctance"));
|
350 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
350 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
351 | 351 | ||
352 | model->submitAll();
|
352 | model->submitAll();
|
353 | mymodel->select();
|
353 | mymodel->select();
|
354 | 354 | ||
355 | 355 | ||
356 | }
|
356 | }
|
357 | */
|
357 | */
|
358 | 358 | ||
359 | void ClassEditor::addNewClass_new(){ |
359 | void ClassEditor::addNewClass_new(){ |
360 | 360 | ||
361 | int row = mymodel->rowCount(); |
361 | int row = mymodel->rowCount(); |
362 | 362 | ||
363 | mymodel->insertRows(row, 1); |
363 | mymodel->insertRows(row, 1); |
364 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
364 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
365 | 365 | ||
366 | 366 | ||
367 | mymodel->submitAll(); |
367 | mymodel->submitAll(); |
368 | row = mymodel->rowCount(); |
368 | row = mymodel->rowCount(); |
369 | QString tmp_str1, sql_str;
|
369 | QString tmp_str1, sql_str;
|
370 | int i_tmp1; |
370 | int i_tmp1; |
371 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
371 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
372 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
372 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
373 | 373 | ||
374 | tmp_str1.append(tr("_Inctance")); |
374 | tmp_str1.append(tr("_Inctance")); |
375 | SqlTable* tbl; |
375 | SqlTable* tbl; |
376 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
376 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
377 | sql_str = tbl->sqlString(); |
377 | sql_str = tbl->sqlString(); |
378 | bool ok; |
378 | bool ok; |
379 | 379 | ||
380 | ok = sql.createTable(tbl); |
380 | ok = sql.createTable(tbl); |
381 | 381 | ||
382 | if (!ok) { |
382 | if (!ok) { |
383 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
383 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
384 | this, // Ðîäèòåëüñêèé âèäæåò. |
384 | this, // Ðîäèòåëüñêèé âèäæåò. |
385 | QObject::tr("Database Error"), // Çàãîëîâîê. |
385 | QObject::tr("Database Error"), // Çàãîëîâîê. |
386 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
386 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
387 | delete tbl; |
387 | delete tbl; |
388 | mymodel->removeRow(row-1); |
388 | mymodel->removeRow(row-1); |
389 | mymodel->submitAll(); |
389 | mymodel->submitAll(); |
390 | mymodel->select(); |
390 | mymodel->select(); |
391 | ui->tableView_2->resizeRowsToContents(); |
391 | ui->tableView_2->resizeRowsToContents(); |
392 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
392 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
393 | 393 | ||
394 | }
|
394 | }
|
395 | 395 | ||
396 | delete tbl; |
396 | delete tbl; |
397 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
397 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
398 | 398 | ||
399 | 399 | ||
400 | 400 | ||
401 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
401 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
402 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
402 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
403 | 403 | ||
404 | 404 | ||
405 | //mymodel->submitAll();
|
405 | //mymodel->submitAll();
|
406 | 406 | ||
407 | //row = mymodel->rowCount();
|
407 | //row = mymodel->rowCount();
|
408 | 408 | ||
409 | 409 | ||
410 | //mymodel->select();
|
410 | //mymodel->select();
|
411 | 411 | ||
412 | 412 | ||
413 | }
|
413 | }
|
414 | 414 | ||
415 | 415 | ||
416 | void ClassEditor::addNewField(){ |
416 | void ClassEditor::addNewField(){ |
417 | // QSqlRecord rec = mymodel->record(1);
|
417 | // QSqlRecord rec = mymodel->record(1);
|
418 | //bool ok;
|
418 | //bool ok;
|
419 | //ok = rec.isEmpty();
|
419 | //ok = rec.isEmpty();
|
420 | //QString currientClassID;
|
420 | //QString currientClassID;
|
421 | //currientClassID = rec.value(1).toString();
|
421 | //currientClassID = rec.value(1).toString();
|
422 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
422 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
423 | QString query_str = tr("ALTER TABLE "); |
423 | QString query_str = tr("ALTER TABLE "); |
424 | QString db_error;
|
424 | QString db_error;
|
425 | QSqlQuery q;
|
425 | QSqlQuery q;
|
426 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
426 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
427 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
427 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
428 | query_str.append( Inctance_str); |
428 | query_str.append( Inctance_str); |
429 | query_str.append(tr(" ADD COLUMN `New field` CHAR(10)")); |
429 | query_str.append(tr(" ADD COLUMN `New field` CHAR(10)")); |
430 | bool ok = q.prepare(query_str); |
430 | bool ok = q.prepare(query_str); |
431 | 431 | ||
432 | ok = q.exec(); |
432 | ok = q.exec(); |
433 | if (!ok) { |
433 | if (!ok) { |
434 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
434 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
435 | this, // Ðîäèòåëüñêèé âèäæåò. |
435 | this, // Ðîäèòåëüñêèé âèäæåò. |
436 | QObject::tr("Database Error"), // Çàãîëîâîê. |
436 | QObject::tr("Database Error"), // Çàãîëîâîê. |
437 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
437 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
438 | 438 | ||
439 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
439 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
440 | 440 | ||
441 | }
|
441 | }
|
442 | 442 | ||
443 | int row = modelForDescription->rowCount(); |
443 | int row = modelForDescription->rowCount(); |
444 | modelForDescription->insertRows(row, 1); |
444 | modelForDescription->insertRows(row, 1); |
445 | modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
445 | modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
446 | modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
446 | modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
447 | 447 | ||
448 | modelForDescription->submitAll(); |
448 | modelForDescription->submitAll(); |
449 | 449 | ||
450 | delete model; |
450 | delete model; |
451 | delete tableForInstance; |
451 | delete tableForInstance; |
452 | model = new QSqlTableModel(); |
452 | model = new QSqlTableModel(); |
453 | tableForInstance = new QTableView(); |
453 | tableForInstance = new QTableView(); |
454 | model->setTable(Inctance_str); |
454 | model->setTable(Inctance_str); |
455 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
455 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
456 | tableForInstance->setModel(model); |
456 | tableForInstance->setModel(model); |
457 | tableForInstance->setWindowTitle(Inctance_str); |
457 | tableForInstance->setWindowTitle(Inctance_str); |
458 | tableForInstance->show(); |
458 | tableForInstance->show(); |
459 | }
|
459 | }
|
460 | 460 | ||
461 | 461 | ||
462 | 462 | ||
463 | 463 | ||
464 | 464 | ||
465 | 465 | ||
466 | 466 | ||
467 | 467 | ||
468 | 468 | ||
469 | 469 | ||
470 | // äîáàâëÿåì íîâûé êëàññ
|
470 | // äîáàâëÿåì íîâûé êëàññ
|
471 | void ClassEditor::on_pushButton_clicked(){ |
471 | void ClassEditor::on_pushButton_clicked(){ |
472 | //int i;
|
472 | //int i;
|
473 | //i++;
|
473 | //i++;
|
474 | /////ClassEditor::addNewClass();
|
474 | /////ClassEditor::addNewClass();
|
475 | ClassEditor::addNewClass_new(); |
475 | ClassEditor::addNewClass_new(); |
476 | mymodel->select(); |
476 | mymodel->select(); |
477 | //ui->tableView->setModel(mymodel);
|
477 | //ui->tableView->setModel(mymodel);
|
478 | 478 | ||
479 | }
|
479 | }
|
480 | 480 | ||
481 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
481 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
482 | int i, row, column; |
482 | int i, row, column; |
483 | i++; |
483 | i++; |
484 | row = index.row(); |
484 | row = index.row(); |
485 | column = index.column(); |
485 | column = index.column(); |
486 | currIndexOfClassesTable = index; |
486 | currIndexOfClassesTable = index; |
487 | QModelIndex index_tmp, index_instance;
|
487 | QModelIndex index_tmp, index_instance;
|
488 | QString tmp_str, filter_str, instance_str;
|
488 | QString tmp_str, filter_str, instance_str;
|
489 | index_tmp = ui->tableView->model()->index(row, 0); |
489 | index_tmp = ui->tableView->model()->index(row, 0); |
490 | index_instance = ui->tableView->model()->index(row, 3); |
490 | index_instance = ui->tableView->model()->index(row, 3); |
491 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
491 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
492 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
492 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
493 | // instance_str.append(tr("_inctance"));
|
493 | // instance_str.append(tr("_inctance"));
|
494 | /*
|
494 | /*
|
495 | Inctance_model.clear();
|
495 | Inctance_model.clear();
|
496 | Inctance_model.setTable(instance_str);
|
496 | Inctance_model.setTable(instance_str);
|
497 | Inctance_model.select();
|
497 | Inctance_model.select();
|
498 | tableForInstance_new.setModel(&Inctance_model);
|
498 | tableForInstance_new.setModel(&Inctance_model);
|
499 | tableForInstance_new.show();
|
499 | tableForInstance_new.show();
|
500 | */
|
500 | */
|
501 | // model->clear();
|
501 | // model->clear();
|
502 | tableForInstance->close(); |
502 | tableForInstance->close(); |
503 | delete model; |
503 | delete model; |
504 | delete tableForInstance; |
504 | delete tableForInstance; |
505 | model = new QSqlTableModel(); |
505 | model = new QSqlTableModel(); |
506 | tableForInstance = new QTableView(); |
506 | tableForInstance = new QTableView(); |
507 | model->setTable(instance_str); |
507 | model->setTable(instance_str); |
508 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
508 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
509 | tableForInstance->setModel(model); |
509 | tableForInstance->setModel(model); |
510 | 510 | ||
511 | model->select(); |
511 | model->select(); |
512 | tableForInstance->setWindowTitle(instance_str); |
512 | tableForInstance->setWindowTitle(instance_str); |
513 | tableForInstance->show(); |
513 | tableForInstance->show(); |
514 | 514 | ||
515 | // tableForInstance.setModel(model);
|
515 | // tableForInstance.setModel(model);
|
516 | tableForInstance->resizeColumnsToContents(); |
516 | tableForInstance->resizeColumnsToContents(); |
517 | 517 | ||
518 | currClassID = tmp_str; |
518 | currClassID = tmp_str; |
519 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
519 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
520 | filter_str = tr("ClassIdentifer = "); |
520 | filter_str = tr("ClassIdentifer = "); |
521 | filter_str.append(tmp_str); |
521 | filter_str.append(tmp_str); |
522 | modelForDescription->setFilter(filter_str); |
522 | modelForDescription->setFilter(filter_str); |
523 | modelForDescription->select(); |
523 | modelForDescription->select(); |
524 | ui->tableView_2->resizeColumnsToContents(); |
524 | ui->tableView_2->resizeColumnsToContents(); |
525 | i++; |
525 | i++; |
526 | }
|
526 | }
|
527 | 527 | ||
528 | 528 | ||
529 | 529 | ||
530 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
530 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
531 | QModelIndex model_index;
|
531 | QModelIndex model_index;
|
532 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
532 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
533 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
533 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
534 | QList<int> selectedRows; |
534 | QList<int> selectedRows; |
535 | selectedRows.clear(); |
535 | selectedRows.clear(); |
536 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
536 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
537 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
537 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
538 | 538 | ||
539 | }
|
539 | }
|
540 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
540 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
541 | 541 | ||
542 | 542 | ||
543 | for (int m =0; m < selectedRows.size(); ++m){ |
543 | for (int m =0; m < selectedRows.size(); ++m){ |
544 | 544 | ||
545 | ClassEditor::removeClass(selectedRows.at(m)); |
545 | ClassEditor::removeClass(selectedRows.at(m)); |
546 | 546 | ||
547 | 547 | ||
548 | 548 | ||
549 | }
|
549 | }
|
550 | mymodel->submitAll(); |
550 | mymodel->submitAll(); |
551 | ClassEditor::modelForDescription->select(); |
551 | ClassEditor::modelForDescription->select(); |
552 | 552 | ||
553 | }
|
553 | }
|
554 | 554 | ||
555 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
555 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
556 | int i; |
556 | int i; |
557 | i++; |
557 | i++; |
558 | ClassEditor::addNewField(); |
558 | ClassEditor::addNewField(); |
559 | ClassEditor::modelForDescription->select(); |
559 | ClassEditor::modelForDescription->select(); |
560 | ui->tableView_2->resizeColumnsToContents(); |
560 | ui->tableView_2->resizeColumnsToContents(); |
561 | }
|
561 | }
|
562 | 562 | ||
563 | 563 | ||
564 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
564 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
565 | // int i;
|
565 | // int i;
|
566 | QModelIndex model_index;
|
566 | QModelIndex model_index;
|
567 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
567 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
568 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
568 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
569 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
569 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
570 | //model_index = mymodel->selec;
|
570 | //model_index = mymodel->selec;
|
571 | //modelList = ui->tableView->SelectItems;
|
571 | //modelList = ui->tableView->SelectItems;
|
572 | //i = indexes.size();
|
572 | //i = indexes.size();
|
573 | QList<int> selectedRows; |
573 | QList<int> selectedRows; |
574 | //indexes_fo_first_col.clear();
|
574 | //indexes_fo_first_col.clear();
|
575 | /*
|
575 | /*
|
576 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
576 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
577 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
577 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
578 | 578 | ||
579 | }
|
579 | }
|
580 | */
|
580 | */
|
581 | selectedRows.clear(); |
581 | selectedRows.clear(); |
582 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
582 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
583 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
583 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
584 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
584 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
585 | }
|
585 | }
|
586 | }
|
586 | }
|
587 | 587 | ||
588 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
588 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
589 | 589 | ||
590 | - | ||
- | 590 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
|
- | 591 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
|
591 | for (int m =0; m < selectedRows.size(); ++m){ |
592 | for (int m =0; m < selectedRows.size(); ++m){ |
592 | 593 | ||
- | 594 | ||
- | 595 | QString query_str;
|
|
- | 596 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
|
- | 597 | QSqlQuery q;
|
|
- | 598 | ||
- | 599 | query_str.clear(); |
|
- | 600 | ||
- | 601 | ||
593 | modelForDescription->removeRow(selectedRows.at(m)); |
602 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
- | 603 | ||
- | 604 | query_str.append(tr("ALTER TABLE ")); |
|
- | 605 | query_str.append(Inctance_str); |
|
- | 606 | query_str.append(tr(" DROP COLUMN `")); |
|
- | 607 | query_str.append(field_name_str); |
|
- | 608 | query_str.append(tr("`")); |
|
- | 609 | q.prepare(query_str); |
|
- | 610 | bool ok = q.exec(); |
|
- | 611 | if (!ok) { |
|
- | 612 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 613 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 614 | QObject::tr("Database Error"), // Çàãîëîâîê. |
|
- | 615 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
|
- | 616 | ||
- | 617 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
|
- | 618 | ||
594 | }
|
619 | }
|
595 | 620 | ||
- | 621 | ||
- | 622 | ||
- | 623 | modelForDescription->removeRow(selectedRows.at(m)); |
|
- | 624 | ||
- | 625 | }
|
|
- | 626 | delete model; |
|
- | 627 | delete tableForInstance; |
|
- | 628 | model = new QSqlTableModel(); |
|
- | 629 | tableForInstance = new QTableView(); |
|
- | 630 | model->setTable(Inctance_str); |
|
- | 631 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
|
- | 632 | tableForInstance->setModel(model); |
|
- | 633 | tableForInstance->setWindowTitle(Inctance_str); |
|
- | 634 | tableForInstance->show(); |
|
596 | //i = selectedRows.size();
|
635 | //i = selectedRows.size();
|
597 | 636 | ||
598 | //if (i > 0) model_index = indexes.at(0);
|
637 | //if (i > 0) model_index = indexes.at(0);
|
599 | }
|
638 | }
|
600 | 639 | ||
601 | 640 | ||
602 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
641 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
603 | int row; |
642 | int row; |
604 | row = ClassEditor::modelForDescription->rowCount(); |
643 | row = ClassEditor::modelForDescription->rowCount(); |
605 | ClassEditor::modelForDescription->removeRows(0, row); |
644 | ClassEditor::modelForDescription->removeRows(0, row); |
606 | ClassEditor::modelForDescription->submitAll(); |
645 | ClassEditor::modelForDescription->submitAll(); |
607 | }
|
646 | }
|
608 | 647 | ||
609 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
648 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
610 | int i; |
649 | int i; |
611 | i++; |
650 | i++; |
612 | ui->tableView->resizeColumnsToContents(); |
651 | ui->tableView->resizeColumnsToContents(); |
613 | }
|
652 | }
|
614 | 653 | ||
615 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
654 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
616 | ui->tableView_2->resizeColumnsToContents(); |
655 | ui->tableView_2->resizeColumnsToContents(); |
617 | }
|
656 | }
|
618 | 657 | ||
619 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
658 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
620 | if (is_checked) ui->tableView->showColumn(0); |
659 | if (is_checked) ui->tableView->showColumn(0); |
621 | else ui->tableView->hideColumn(0); |
660 | else ui->tableView->hideColumn(0); |
622 | ui->tableView->resizeColumnsToContents(); |
661 | ui->tableView->resizeColumnsToContents(); |
623 | }
|
662 | }
|
624 | 663 | ||
625 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
664 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
626 | if (is_checked) ui->tableView->showColumn(2); |
665 | if (is_checked) ui->tableView->showColumn(2); |
627 | else ui->tableView->hideColumn(2); |
666 | else ui->tableView->hideColumn(2); |
628 | ui->tableView->resizeColumnsToContents(); |
667 | ui->tableView->resizeColumnsToContents(); |
629 | }
|
668 | }
|
630 | 669 | ||
631 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
670 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
632 | if (is_checked) ui->tableView->showColumn(3); |
671 | if (is_checked) ui->tableView->showColumn(3); |
633 | else ui->tableView->hideColumn(3); |
672 | else ui->tableView->hideColumn(3); |
634 | ui->tableView->resizeColumnsToContents(); |
673 | ui->tableView->resizeColumnsToContents(); |
635 | }
|
674 | }
|
636 | 675 | ||
637 | 676 | ||
638 | 677 | ||
639 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
678 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
640 | int row; |
679 | int row; |
641 | row = ClassEditor::mymodel->rowCount(); |
680 | row = ClassEditor::mymodel->rowCount(); |
642 | for (int m=0; m < row; ++m){ |
681 | for (int m=0; m < row; ++m){ |
643 | ClassEditor::removeClass(0); |
682 | ClassEditor::removeClass(0); |
644 | //ClassEditor::mymodel->removeRows(0, row);
|
683 | //ClassEditor::mymodel->removeRows(0, row);
|
645 | }
|
684 | }
|
646 | ClassEditor::mymodel->submitAll(); |
685 | ClassEditor::mymodel->submitAll(); |
647 | ClassEditor::modelForDescription->select(); |
686 | ClassEditor::modelForDescription->select(); |
648 | }
|
687 | }
|
649 | 688 | ||
650 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
689 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
651 | QModelIndex index_tmp;
|
690 | QModelIndex index_tmp;
|
652 | QString tmp_str, filter_str;
|
691 | QString tmp_str, filter_str;
|
653 | index_tmp = ui->tableView->model()->index(class_row, 0); |
692 | index_tmp = ui->tableView->model()->index(class_row, 0); |
654 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
693 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
655 | currClassID = tmp_str; |
694 | currClassID = tmp_str; |
656 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
695 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
657 | filter_str = tr("ClassIdentifer = "); |
696 | filter_str = tr("ClassIdentifer = "); |
658 | filter_str.append(tmp_str); |
697 | filter_str.append(tmp_str); |
659 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
698 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
660 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
699 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
661 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
700 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
662 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
701 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
663 | ui->tableView->resizeColumnsToContents(); |
702 | ui->tableView->resizeColumnsToContents(); |
664 | ui->tableView_2->resizeColumnsToContents(); |
703 | ui->tableView_2->resizeColumnsToContents(); |
665 | 704 | ||
666 | }
|
705 | }
|
667 | 706 |