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