Редакция 64 | Редакция 67 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 64 | Редакция 65 | ||
---|---|---|---|
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 | model->setEditStrategy(QSqlTableModel::OnFieldChange);
|
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 | modelForDescription->setFilter(tr("ClassIdentifer = 1")); |
205 | modelForDescription->setFilter(tr("ClassIdentifer = 1")); |
206 | modelForDescription->select(); |
206 | modelForDescription->select(); |
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 | //ui->tableView->setModel(model);
|
219 | //ui->tableView->setModel(model);
|
219 | ui->tableView->setModel(mymodel); |
220 | ui->tableView->setModel(mymodel); |
220 | //tableForDescription = new QTableView();
|
221 | //tableForDescription = new QTableView();
|
221 | ui->tableView_2->setModel(modelForDescription); |
222 | ui->tableView_2->setModel(modelForDescription); |
222 | ui->tableView_2->setAlternatingRowColors(true); |
223 | ui->tableView_2->setAlternatingRowColors(true); |
223 | ui->tableView_2->resizeColumnsToContents(); |
224 | ui->tableView_2->resizeColumnsToContents(); |
224 | //tableForDescription->show();
|
225 | //tableForDescription->show();
|
225 | 226 | ||
226 | 227 | ||
227 | ui->tableView->setAlternatingRowColors(true); |
228 | ui->tableView->setAlternatingRowColors(true); |
228 | ui->tableView->resizeColumnsToContents(); |
229 | ui->tableView->resizeColumnsToContents(); |
- | 230 | ||
229 | ui->tableView->hideColumn(0); |
231 | ui->tableView->hideColumn(0); |
230 | ui->tableView->hideColumn(3); |
232 | ui->tableView->hideColumn(3); |
231 | ui->tableView->hideColumn(2); |
233 | ui->tableView->hideColumn(2); |
232 | 234 | ||
- | 235 | /*
|
|
233 | ui->tableView_2->hideColumn(0); |
236 | ui->tableView_2->hideColumn(0);
|
234 | ui->tableView_2->hideColumn(5); |
237 | ui->tableView_2->hideColumn(5);
|
235 | ui->tableView_2->hideColumn(2); |
238 | ui->tableView_2->hideColumn(2);
|
- | 239 | */
|
|
- | 240 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
|
236 | 241 | ||
237 | currIndexOfClassesTable = modelForDescription->index(0, 1); |
242 | currIndexOfClassesTable = modelForDescription->index(0, 1); |
238 | QModelIndex index_temp;
|
243 | QModelIndex index_temp;
|
239 | 244 | ||
240 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
245 | currClassID = mymodel->data(mymodel->index(0,0)).toString(); |
241 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
246 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
242 | 247 | ||
243 | QModelIndex topLeft;
|
248 | QModelIndex topLeft;
|
244 | QModelIndex bottomRight;
|
249 | QModelIndex bottomRight;
|
245 | 250 | ||
246 | topLeft = mymodel->index(0, 0, QModelIndex()); |
251 | topLeft = mymodel->index(0, 0, QModelIndex()); |
247 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
252 | bottomRight = mymodel->index(0, 1, QModelIndex()); |
248 | 253 | ||
249 | QItemSelection selection(topLeft, bottomRight); |
254 | QItemSelection selection(topLeft, bottomRight); |
250 | selectionModel->select(selection, QItemSelectionModel::Select); |
255 | selectionModel->select(selection, QItemSelectionModel::Select); |
251 | 256 | ||
252 | 257 | ||
253 | 258 | ||
254 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
259 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
255 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
260 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
256 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
261 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
257 | - | ||
- | 262 | connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool))); |
|
- | 263 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
|
- | 264 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); |
|
- | 265 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); |
|
258 | }
|
266 | }
|
259 | 267 | ||
260 | 268 | ||
261 | 269 | ||
262 | 270 | ||
263 | 271 | ||
264 | 272 | ||
265 | 273 | ||
266 | 274 | ||
267 | 275 | ||
268 | 276 | ||
269 | 277 | ||
270 | ClassEditor::~ClassEditor() |
278 | ClassEditor::~ClassEditor() |
271 | {
|
279 | {
|
272 | delete ui; |
280 | delete ui; |
273 | // delete field;
|
281 | // delete field;
|
274 | // delete settdialog;
|
282 | // delete settdialog;
|
275 | }
|
283 | }
|
276 | 284 | ||
277 | void ClassEditor::changeEvent(QEvent *e) |
285 | void ClassEditor::changeEvent(QEvent *e) |
278 | {
|
286 | {
|
279 | QMainWindow::changeEvent(e); |
287 | QMainWindow::changeEvent(e); |
280 | switch (e->type()) { |
288 | switch (e->type()) { |
281 | case QEvent::LanguageChange: |
289 | case QEvent::LanguageChange: |
282 | ui->retranslateUi(this); |
290 | ui->retranslateUi(this); |
283 | break; |
291 | break; |
284 | default: |
292 | default: |
285 | break; |
293 | break; |
286 | }
|
294 | }
|
287 | }
|
295 | }
|
288 | 296 | ||
289 | 297 | ||
290 | 298 | ||
291 | void ClassEditor::addNewClass(){ |
299 | void ClassEditor::addNewClass(){ |
292 | 300 | ||
293 | int row = model->rowCount(); |
301 | int row = model->rowCount(); |
294 | 302 | ||
295 | model->insertRows(row, 1); |
303 | model->insertRows(row, 1); |
296 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
304 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
297 | 305 | ||
298 | 306 | ||
299 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
307 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
300 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
308 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
301 | 309 | ||
302 | 310 | ||
303 | model->submitAll(); |
311 | model->submitAll(); |
304 | 312 | ||
305 | row = model->rowCount(); |
313 | row = model->rowCount(); |
306 | QString tmp_str;
|
314 | QString tmp_str;
|
307 | int i_tmp; |
315 | int i_tmp; |
308 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
316 | i_tmp = model->data(model->index(row-1, 0)).toInt(); |
309 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
317 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
310 | 318 | ||
311 | tmp_str.append(tr("_Inctance")); |
319 | tmp_str.append(tr("_Inctance")); |
312 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó |
320 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó |
313 | 321 | ||
314 | model->submitAll(); |
322 | model->submitAll(); |
315 | mymodel->select(); |
323 | mymodel->select(); |
316 | 324 | ||
317 | 325 | ||
318 | }
|
326 | }
|
319 | 327 | ||
320 | 328 | ||
321 | void ClassEditor::addNewClass_new(){ |
329 | void ClassEditor::addNewClass_new(){ |
322 | 330 | ||
323 | int row = mymodel->rowCount(); |
331 | int row = mymodel->rowCount(); |
324 | 332 | ||
325 | mymodel->insertRows(row, 1); |
333 | mymodel->insertRows(row, 1); |
326 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New classs")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
334 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New classs")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
327 | 335 | ||
328 | mymodel->submitAll(); |
336 | mymodel->submitAll(); |
329 | 337 | ||
330 | row = mymodel->rowCount(); |
338 | row = mymodel->rowCount(); |
331 | QString tmp_str1;
|
339 | QString tmp_str1;
|
332 | int i_tmp1; |
340 | int i_tmp1; |
333 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
341 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
334 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
342 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
335 | 343 | ||
336 | tmp_str1.append(tr("_Inctance")); |
344 | tmp_str1.append(tr("_Inctance")); |
337 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
345 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
338 | 346 | ||
339 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
347 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
340 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
348 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
341 | 349 | ||
342 | 350 | ||
343 | //mymodel->submitAll();
|
351 | //mymodel->submitAll();
|
344 | 352 | ||
345 | //row = mymodel->rowCount();
|
353 | //row = mymodel->rowCount();
|
346 | 354 | ||
347 | 355 | ||
348 | //mymodel->select();
|
356 | //mymodel->select();
|
349 | 357 | ||
350 | 358 | ||
351 | }
|
359 | }
|
352 | 360 | ||
353 | 361 | ||
354 | void ClassEditor::addNewField(){ |
362 | void ClassEditor::addNewField(){ |
355 | // QSqlRecord rec = mymodel->record(1);
|
363 | // QSqlRecord rec = mymodel->record(1);
|
356 | //bool ok;
|
364 | //bool ok;
|
357 | //ok = rec.isEmpty();
|
365 | //ok = rec.isEmpty();
|
358 | //QString currientClassID;
|
366 | //QString currientClassID;
|
359 | //currientClassID = rec.value(1).toString();
|
367 | //currientClassID = rec.value(1).toString();
|
360 | int row = modelForDescription->rowCount(); |
368 | int row = modelForDescription->rowCount(); |
361 | modelForDescription->insertRows(row, 1); |
369 | modelForDescription->insertRows(row, 1); |
362 | modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
370 | modelForDescription->setData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
363 | modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
371 | modelForDescription->setData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
364 | 372 | ||
365 | modelForDescription->submitAll(); |
373 | modelForDescription->submitAll(); |
366 | }
|
374 | }
|
367 | 375 | ||
368 | 376 | ||
369 | 377 | ||
370 | 378 | ||
371 | 379 | ||
372 | 380 | ||
373 | 381 | ||
374 | 382 | ||
375 | 383 | ||
376 | 384 | ||
377 | 385 | ||
378 | void ClassEditor::on_pushButton_clicked(){ |
386 | void ClassEditor::on_pushButton_clicked(){ |
379 | //int i;
|
387 | //int i;
|
380 | //i++;
|
388 | //i++;
|
381 | /////ClassEditor::addNewClass();
|
389 | /////ClassEditor::addNewClass();
|
382 | ClassEditor::addNewClass_new(); |
390 | ClassEditor::addNewClass_new(); |
383 | mymodel->select(); |
391 | mymodel->select(); |
384 | //ui->tableView->setModel(mymodel);
|
392 | //ui->tableView->setModel(mymodel);
|
385 | 393 | ||
386 | }
|
394 | }
|
387 | 395 | ||
388 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
396 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
389 | int i, row, column; |
397 | int i, row, column; |
390 | i++; |
398 | i++; |
391 | row = index.row(); |
399 | row = index.row(); |
392 | column = index.column(); |
400 | column = index.column(); |
393 | currIndexOfClassesTable = index; |
401 | currIndexOfClassesTable = index; |
394 | QModelIndex index_tmp;
|
402 | QModelIndex index_tmp;
|
395 | QString tmp_str, filter_str;
|
403 | QString tmp_str, filter_str;
|
396 | index_tmp = ui->tableView->model()->index(row, 0); |
404 | index_tmp = ui->tableView->model()->index(row, 0); |
397 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
405 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
398 | currClassID = tmp_str; |
406 | currClassID = tmp_str; |
399 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
407 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
400 | filter_str = tr("ClassIdentifer = "); |
408 | filter_str = tr("ClassIdentifer = "); |
401 | filter_str.append(tmp_str); |
409 | filter_str.append(tmp_str); |
402 | modelForDescription->setFilter(filter_str); |
410 | modelForDescription->setFilter(filter_str); |
403 | ui->tableView_2->resizeColumnsToContents(); |
411 | ui->tableView_2->resizeColumnsToContents(); |
404 | i++; |
412 | i++; |
405 | }
|
413 | }
|
406 | 414 | ||
407 | 415 | ||
408 | 416 | ||
409 | void ClassEditor::on_pushButton_2_clicked(){ |
417 | void ClassEditor::on_pushButton_2_clicked(){ |
410 | int i; |
418 | int i; |
411 | i++; |
419 | i++; |
412 | 420 | ||
413 | }
|
421 | }
|
414 | 422 | ||
415 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
423 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
416 | int i; |
424 | int i; |
417 | i++; |
425 | i++; |
418 | ClassEditor::addNewField(); |
426 | ClassEditor::addNewField(); |
419 | ClassEditor::modelForDescription->select(); |
427 | ClassEditor::modelForDescription->select(); |
420 | ui->tableView_2->resizeColumnsToContents(); |
428 | ui->tableView_2->resizeColumnsToContents(); |
421 | }
|
429 | }
|
422 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
430 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
423 | int i; |
431 | int i; |
424 | i++; |
432 | i++; |
425 | QModelIndex model_index;
|
433 | QModelIndex model_index;
|
426 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
434 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
427 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
435 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
428 | //model_index = mymodel->selec;
|
436 | //model_index = mymodel->selec;
|
429 | //modelList = ui->tableView->SelectItems;
|
437 | //modelList = ui->tableView->SelectItems;
|
430 | i = indexes.size(); |
438 | i = indexes.size(); |
431 | QList<int> selectedRows; |
439 | QList<int> selectedRows; |
432 | selectedRows.clear(); |
440 | selectedRows.clear(); |
433 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
441 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
434 | if (!selectedRows.contains(model_index.row())) selectedRows.append(model_index.row()); |
442 | if (!selectedRows.contains(model_index.row())) selectedRows.append(model_index.row()); |
435 | 443 | ||
436 | }
|
444 | }
|
437 | i = selectedRows.size(); |
445 | i = selectedRows.size(); |
438 | 446 | ||
439 | if (i > 0) model_index = indexes.at(0); |
447 | if (i > 0) model_index = indexes.at(0); |
440 | i++; |
448 | i++; |
441 | }
|
449 | }
|
442 | 450 | ||
443 | 451 | ||
444 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
452 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
445 | int row; |
453 | int row; |
446 | row = ClassEditor::modelForDescription->rowCount(); |
454 | row = ClassEditor::modelForDescription->rowCount(); |
447 | ClassEditor::modelForDescription->removeRows(0, row); |
455 | ClassEditor::modelForDescription->removeRows(0, row); |
448 | ClassEditor::modelForDescription->submitAll(); |
456 | ClassEditor::modelForDescription->submitAll(); |
449 | }
|
457 | }
|
450 | 458 | ||
451 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
459 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
452 | int i; |
460 | int i; |
453 | i++; |
461 | i++; |
454 | ui->tableView->resizeColumnsToContents(); |
462 | ui->tableView->resizeColumnsToContents(); |
455 | }
|
463 | }
|
456 | 464 | ||
457 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
465 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
458 | ui->tableView_2->resizeColumnsToContents(); |
466 | ui->tableView_2->resizeColumnsToContents(); |
459 | }
|
467 | }
|
- | 468 | ||
- | 469 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
|
- | 470 | if (is_checked) ui->tableView->showColumn(0); |
|
- | 471 | else ui->tableView->hideColumn(0); |
|
- | 472 | ui->tableView->resizeColumnsToContents(); |
|
- | 473 | }
|
|
- | 474 | ||
- | 475 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
|
- | 476 | if (is_checked) ui->tableView->showColumn(2); |
|
- | 477 | else ui->tableView->hideColumn(2); |
|
- | 478 | ui->tableView->resizeColumnsToContents(); |
|
- | 479 | }
|
|
- | 480 | ||
- | 481 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ |
|
- | 482 | if (is_checked) ui->tableView->showColumn(3); |
|
- | 483 | else ui->tableView->hideColumn(3); |
|
- | 484 | ui->tableView->resizeColumnsToContents(); |
|
- | 485 | }
|
|
460 | 486 |