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