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