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