Редакция 183 | Редакция 232 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 183 | Редакция 210 | ||
---|---|---|---|
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 | // iconFrm.show();
|
11 | // iconFrm.show();
|
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
15 | readSettings(); |
15 | readSettings(); |
16 | 16 | ||
17 | 17 | ||
18 | initDataBase(); // íàñòðàèâàåì è óñòàíàâëèâàåì ñîåäèíåíèå |
18 | initDataBase(); // íàñòðàèâàåì è óñòàíàâëèâàåì ñîåäèíåíèå |
19 | createMainTables(); // ñîçäàåì ñòðóêòóðó íàøåé áàçû - äâå ãëàâíûå òàáëèöû DescriptionOfClasses è ListOfClasses |
19 | createMainTables(); // ñîçäàåì ñòðóêòóðó íàøåé áàçû - äâå ãëàâíûå òàáëèöû DescriptionOfClasses è ListOfClasses |
20 | 20 | ||
21 | 21 | ||
22 | 22 | ||
23 | /*
|
23 | /*
|
24 | field = new TableField(tr("Ñîòðóäíèêè"), this);
|
24 | field = new TableField(tr("Ñîòðóäíèêè"), this);
|
25 | field->setNotNull(true);
|
25 | field->setNotNull(true);
|
26 | field->setDefaultValue(tr("ñîòðóäíèê"));
|
26 | field->setDefaultValue(tr("ñîòðóäíèê"));
|
27 | 27 | ||
28 | table = new SqlTable (tr("NewTable"), this);
|
28 | table = new SqlTable (tr("NewTable"), this);
|
29 | table->setName(tr("NewTable"));
|
29 | table->setName(tr("NewTable"));
|
30 | table->fields().at(0)->setNotNull(true);
|
30 | table->fields().at(0)->setNotNull(true);
|
31 | if (!(table->setPrimaryKey(tr("ID")))) {
|
31 | if (!(table->setPrimaryKey(tr("ID")))) {
|
32 | ui->label_3->setText(table->lastError());
|
32 | ui->label_3->setText(table->lastError());
|
33 | }
|
33 | }
|
34 | else ui->label_3->setText(table->primaryKey());
|
34 | else ui->label_3->setText(table->primaryKey());
|
35 | table->append(field);
|
35 | table->append(field);
|
36 | 36 | ||
37 | field = new TableField(tr("Êîìïüþòåðû"), this);
|
37 | field = new TableField(tr("Êîìïüþòåðû"), this);
|
38 | field->setNotNull(true);
|
38 | field->setNotNull(true);
|
39 | field->setDefaultValue(tr("êîìïüþòåð"));
|
39 | field->setDefaultValue(tr("êîìïüþòåð"));
|
40 | table->append(field);
|
40 | table->append(field);
|
41 | 41 | ||
42 | field = new TableField(tr("Ìîíèòîðû"), this);
|
42 | field = new TableField(tr("Ìîíèòîðû"), this);
|
43 | field->setNotNull(true);
|
43 | field->setNotNull(true);
|
44 | field->setDefaultValue(tr("ìîíèòîð"));
|
44 | field->setDefaultValue(tr("ìîíèòîð"));
|
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(true);
|
48 | field->setNotNull(true);
|
49 | field->setType(tr("INTEGER"));
|
49 | field->setType(tr("INTEGER"));
|
50 | field->setDefaultValue(tr("1"));
|
50 | field->setDefaultValue(tr("1"));
|
51 | table->append(field);
|
51 | table->append(field);
|
52 | 52 | ||
53 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this);
|
53 | field = new TableField(tr("Äåíü ðîæäåíèÿ"), this);
|
54 | field->setNotNull(false);
|
54 | field->setNotNull(false);
|
55 | field->setType(tr("DATE"));
|
55 | field->setType(tr("DATE"));
|
56 | field->setDefaultValue(tr("NULL"));
|
56 | field->setDefaultValue(tr("NULL"));
|
57 | table->append(field);
|
57 | table->append(field);
|
58 | 58 | ||
59 | ui->label_2->setText(table->name());
|
59 | ui->label_2->setText(table->name());
|
60 | ui->label->setText(table->fields().at(0)->sqlString());
|
60 | ui->label->setText(table->fields().at(0)->sqlString());
|
61 | ui->label_4->setText(table->sqlString());
|
61 | ui->label_4->setText(table->sqlString());
|
62 | ////// ui->lineEdit->insert(table->sqlString());
|
62 | ////// ui->lineEdit->insert(table->sqlString());
|
63 | 63 | ||
64 | */
|
64 | */
|
65 | /**********************************************
|
65 | /**********************************************
|
66 | 66 | ||
67 | QTextDocument *document;
|
67 | QTextDocument *document;
|
68 | // = ui->textEdit->document();
|
68 | // = ui->textEdit->document();
|
69 | QTextCursor *cursor;
|
69 | QTextCursor *cursor;
|
70 | 70 | ||
71 | document = ui->textEdit->document();
|
71 | document = ui->textEdit->document();
|
72 | cursor = new QTextCursor(document);
|
72 | cursor = new QTextCursor(document);
|
73 | cursor->movePosition(QTextCursor::Start);
|
73 | cursor->movePosition(QTextCursor::Start);
|
74 | QTextCharFormat format(cursor->charFormat());
|
74 | QTextCharFormat format(cursor->charFormat());
|
75 | //format.setFontFamily("Courier");
|
75 | //format.setFontFamily("Courier");
|
76 | format.setFontFamily("Arial");
|
76 | format.setFontFamily("Arial");
|
77 | //format.setFontItalic(false);
|
77 | //format.setFontItalic(false);
|
78 | 78 | ||
79 | format.setFontWeight(QFont::Normal);
|
79 | format.setFontWeight(QFont::Normal);
|
80 | QTextCharFormat boldFormat = format;
|
80 | QTextCharFormat boldFormat = format;
|
81 | boldFormat.setFontWeight(QFont::Bold);
|
81 | boldFormat.setFontWeight(QFont::Bold);
|
82 | 82 | ||
83 | QTextCharFormat italicFormat = format;
|
83 | QTextCharFormat italicFormat = format;
|
84 | //format.setFontFamily("Courier");
|
84 | //format.setFontFamily("Courier");
|
85 | // format.setFontFamily("Arial");
|
85 | // format.setFontFamily("Arial");
|
86 | italicFormat.setFontItalic(true);
|
86 | italicFormat.setFontItalic(true);
|
87 | 87 | ||
88 | cursor->insertText(table->sqlString(), format);
|
88 | cursor->insertText(table->sqlString(), format);
|
89 | 89 | ||
90 | ****************************************************/
|
90 | ****************************************************/
|
91 | 91 | ||
92 | QString errorString;
|
92 | QString errorString;
|
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | ||
97 | /*
|
97 | /*
|
98 | ok = sql.createTable(table);
|
98 | ok = sql.createTable(table);
|
99 | if (!ok) {
|
99 | if (!ok) {
|
100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
101 | this, // Ðîäèòåëüñêèé âèäæåò.
|
101 | this, // Ðîäèòåëüñêèé âèäæåò.
|
102 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
102 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ.
|
103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ.
|
104 | }
|
104 | }
|
105 | else {
|
105 | else {
|
106 | 106 | ||
107 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
107 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
108 | this, // Ðîäèòåëüñêèé âèäæåò.
|
108 | this, // Ðîäèòåëüñêèé âèäæåò.
|
109 | QObject::tr("Database Connect"), // Çàãîëîâîê.
|
109 | QObject::tr("Database Connect"), // Çàãîëîâîê.
|
110 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
|
110 | QObject::tr("Òàáëèöà â áàçå äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
|
111 | }
|
111 | }
|
112 | 112 | ||
113 | 113 | ||
114 | 114 | ||
115 | */
|
115 | */
|
116 | 116 | ||
117 | 117 | ||
118 | 118 | ||
119 | 119 | ||
120 | model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà |
120 | model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà |
121 | tableForInstance = new QTableView(); |
121 | tableForInstance = new QTableView(); |
122 | mymodel = new MyModel(this); |
122 | mymodel = new MyModel(this); |
123 | modelForPointers = new ModelForPointers(this); // // ìîäåëü äëÿ òàáëèöû ñ óêàçàòåëÿìè |
123 | modelForPointers = new ModelForPointers(this); // // ìîäåëü äëÿ òàáëèöû ñ óêàçàòåëÿìè |
124 | 124 | ||
125 | //modelForDescription = new QSqlTableModel(this);
|
125 | //modelForDescription = new QSqlTableModel(this);
|
126 | modelForDescription = new ModelForDescriptionTable(this); |
126 | modelForDescription = new ModelForDescriptionTable(this); |
127 | 127 | ||
128 | 128 | ||
129 | 129 | ||
130 | initClassListTable(); |
130 | initClassListTable(); |
131 | 131 | ||
132 | initFieldsTable(); |
132 | initFieldsTable(); |
133 | 133 | ||
134 | initPointersTable(); |
134 | initPointersTable(); |
135 | 135 | ||
136 | /////////////////model->setTable(tr("ListOfClasses"));
|
136 | /////////////////model->setTable(tr("ListOfClasses"));
|
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
140 | /////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
141 | 141 | ||
142 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
142 | // modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
143 | 143 | ||
144 | 144 | ||
145 | 145 | ||
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
149 | //mymodel->setEditStrategy(QSqlTableModel::OnFieldChange);
|
150 | 150 | ||
151 | 151 | ||
152 | 152 | ||
153 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
153 | //////////////////model->setSort(0, Qt::AscendingOrder);
|
154 | 154 | ||
155 | 155 | ||
156 | 156 | ||
157 | 157 | ||
158 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
158 | // model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
|
159 | ////////////////////model->select();
|
159 | ////////////////////model->select();
|
160 | 160 | ||
161 | //tableForDescription = new QTableView();
|
161 | //tableForDescription = new QTableView();
|
162 | 162 | ||
163 | //tableForDescription->show();
|
163 | //tableForDescription->show();
|
164 | 164 | ||
165 | 165 | ||
166 | 166 | ||
167 | 167 | ||
168 | /*
|
168 | /*
|
169 | ui->tableView_2->hideColumn(0);
|
169 | ui->tableView_2->hideColumn(0);
|
170 | ui->tableView_2->hideColumn(5);
|
170 | ui->tableView_2->hideColumn(5);
|
171 | ui->tableView_2->hideColumn(2);
|
171 | ui->tableView_2->hideColumn(2);
|
172 | */
|
172 | */
|
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | 176 | ||
177 | 177 | ||
178 | 178 | ||
179 | //if (mymodel->rowCount() > 0) {
|
179 | //if (mymodel->rowCount() > 0) {
|
180 | 180 | ||
181 | 181 | ||
182 | 182 | ||
183 | /*
|
183 | /*
|
184 | 184 | ||
185 | currIndexOfClassesTable = mymodel->index(0, 1);
|
185 | currIndexOfClassesTable = mymodel->index(0, 1);
|
186 | 186 | ||
187 | 187 | ||
188 | QModelIndex index_temp;
|
188 | QModelIndex index_temp;
|
189 | 189 | ||
190 | 190 | ||
191 | 191 | ||
192 | currClassID = mymodel->data(mymodel->index(0,0)).toString();
|
192 | currClassID = mymodel->data(mymodel->index(0,0)).toString();
|
193 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
|
193 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel();
|
194 | 194 | ||
195 | QModelIndex topLeft;
|
195 | QModelIndex topLeft;
|
196 | QModelIndex bottomRight;
|
196 | QModelIndex bottomRight;
|
197 | 197 | ||
198 | topLeft = mymodel->index(0, 0, QModelIndex());
|
198 | topLeft = mymodel->index(0, 0, QModelIndex());
|
199 | bottomRight = mymodel->index(0, 1, QModelIndex());
|
199 | bottomRight = mymodel->index(0, 1, QModelIndex());
|
200 | 200 | ||
201 | QItemSelection selection(topLeft, bottomRight);
|
201 | QItemSelection selection(topLeft, bottomRight);
|
202 | selectionModel->select(selection, QItemSelectionModel::Select);
|
202 | selectionModel->select(selection, QItemSelectionModel::Select);
|
203 | 203 | ||
204 | 204 | ||
205 | QString class_indx, class_instance;
|
205 | QString class_indx, class_instance;
|
206 | QString str_fltr = tr("ClassIdentifer = ");
|
206 | QString str_fltr = tr("ClassIdentifer = ");
|
207 | class_indx = mymodel->data(mymodel->index(0,0)).toString();
|
207 | class_indx = mymodel->data(mymodel->index(0,0)).toString();
|
208 | class_instance = mymodel->data(mymodel->index(0,3)).toString();
|
208 | class_instance = mymodel->data(mymodel->index(0,3)).toString();
|
209 | 209 | ||
210 | currInctanceTable = class_instance; //
|
210 | currInctanceTable = class_instance; //
|
211 | 211 | ||
212 | 212 | ||
213 | 213 | ||
214 | modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
214 | modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
215 | //class_instance.append(tr("_inctance"));
|
215 | //class_instance.append(tr("_inctance"));
|
216 | str_fltr.append(class_indx);
|
216 | str_fltr.append(class_indx);
|
217 | str_fltr.append(tr(" AND FieldType <> \"pointer\""));
|
217 | str_fltr.append(tr(" AND FieldType <> \"pointer\""));
|
218 | 218 | ||
219 | model->setTable(class_instance);
|
219 | model->setTable(class_instance);
|
220 | //model->setTable(tr("memory"));
|
220 | //model->setTable(tr("memory"));
|
221 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
221 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
222 | model->select();
|
222 | model->select();
|
223 | tableForInstance->setModel(model);
|
223 | tableForInstance->setModel(model);
|
224 | tableForInstance->resizeColumnsToContents();
|
224 | tableForInstance->resizeColumnsToContents();
|
225 | tableForInstance->setWindowTitle(class_instance);
|
225 | tableForInstance->setWindowTitle(class_instance);
|
226 | tableForInstance->show();
|
226 | tableForInstance->show();
|
227 | 227 | ||
228 | modelForDescription->setFilter(str_fltr);
|
228 | modelForDescription->setFilter(str_fltr);
|
229 | modelForDescription->select();
|
229 | modelForDescription->select();
|
230 | ui->tableView_2->resizeColumnsToContents();
|
230 | ui->tableView_2->resizeColumnsToContents();
|
231 | 231 | ||
232 | 232 | ||
233 | str_fltr = tr("ClassIdentifer = ");
|
233 | str_fltr = tr("ClassIdentifer = ");
|
234 | modelForPointers->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
234 | modelForPointers->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
235 | str_fltr.append(class_indx);
|
235 | str_fltr.append(class_indx);
|
236 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
236 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
237 | // str_fltr.append( tr(" FieldType = pointer "));
|
237 | // str_fltr.append( tr(" FieldType = pointer "));
|
238 | 238 | ||
239 | 239 | ||
240 | 240 | ||
241 | modelForPointers->setFilter(str_fltr);
|
241 | modelForPointers->setFilter(str_fltr);
|
242 | modelForPointers->select();
|
242 | modelForPointers->select();
|
243 | 243 | ||
244 | 244 | ||
245 | */
|
245 | */
|
246 | 246 | ||
247 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
247 | //connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
|
248 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
248 | connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex))); |
249 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
249 | connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex))); |
250 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
250 | //connect(ui->newClassAction, SIGNAL(triggered(bool)), this, SLOT(on_pushButton_clicked(bool)));
|
251 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
251 | connect(ui->action_ID, SIGNAL(triggered(bool)), this, SLOT(on_action_ID_triggered(bool))); |
252 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
252 | connect(ui->action_showAlias, SIGNAL(triggered(bool)), this, SLOT(on_action_showAlias_triggered(bool))); // ïîêàçûâàòü ïñåâäîíèìû |
253 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
253 | connect(ui->action_showInstance, SIGNAL(triggered(bool)), this, SLOT(on_action_showInstance_triggered(bool))); // ïîêàçûâàòü õðàíèëèùà îáúåêòîâ |
254 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
254 | connect(ui->action_removeSelectedFields, SIGNAL(triggered()), this, SLOT(on_pushButton_4_clicked())); // óäàëèòü âûäåëåííûå ïîëÿ |
255 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
255 | connect(ui->action_removeAllFields, SIGNAL(triggered()), this, SLOT(on_pushButton_5_clicked())); // óäàëèòü âñå ïîëÿ |
256 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
256 | connect(ui->action_removeSelectedClasses, SIGNAL(triggered()), this, SLOT(on_pushButton_2_clicked())); // óäàëèòü âûäåëåííûå êëàññû |
257 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
257 | connect(ui->action_removeAllClasses, SIGNAL(triggered()), this, SLOT(on_action_removeAllClasses())); // óäàëèòü âñå êëàññû |
258 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
258 | connect(ui->action_newClass, SIGNAL(triggered()), this, SLOT(on_pushButton_clicked())); // äîáàâèòü íîâûé êëàññ |
259 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
259 | connect(ui->action_newField, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå |
260 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû |
260 | connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_action_newPointer())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû |
261 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû
|
261 | // connect(ui->action_newPointer, SIGNAL(triggered()), this, SLOT(on_pushButton_3_clicked())); // äîáàâèòü íîâîå ïîëå äëÿ óêàçàòåëåé íà êëàññû-êîíòåéíåðû
|
262 | 262 | ||
263 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // óäàëèòü âûäåëåííûå êëàññû |
263 | connect(ui->action_removeSelectedPointers, SIGNAL(triggered()), this, SLOT(on_action_removeSelectedPointers())); // óäàëèòü âûäåëåííûå êëàññû |
264 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå ïîëåé ïðîèçîøëè èçìåíåíèÿ |
264 | connect(modelForDescription, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå ïîëåé ïðîèçîøëè èçìåíåíèÿ |
265 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå óêàçàòåëåé ïðîèçîøëè èçìåíåíèÿ |
265 | connect(ClassEditor::modelForPointers, SIGNAL(field_changed()), this, SLOT(on_field_changed())); // â òàáëèöå óêàçàòåëåé ïðîèçîøëè èçìåíåíèÿ |
266 | 266 | ||
267 | 267 | ||
268 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ" |
268 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ" |
269 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
269 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
270 | 270 | ||
271 | 271 | ||
272 | 272 | ||
273 | 273 | ||
274 | }
|
274 | }
|
275 | 275 | ||
276 | 276 | ||
277 | 277 | ||
278 | 278 | ||
279 | 279 | ||
280 | 280 | ||
281 | 281 | ||
282 | 282 | ||
283 | 283 | ||
284 | 284 | ||
285 | 285 | ||
286 | ClassEditor::~ClassEditor() |
286 | ClassEditor::~ClassEditor() |
287 | {
|
287 | {
|
288 | // tableForInstance->close();
|
288 | // tableForInstance->close();
|
289 | delete tableForInstance; |
289 | delete tableForInstance; |
290 | delete model; |
290 | delete model; |
291 | 291 | ||
292 | delete ui; |
292 | delete ui; |
293 | // delete field;
|
293 | // delete field;
|
294 | // delete settdialog;
|
294 | // delete settdialog;
|
295 | }
|
295 | }
|
296 | 296 | ||
297 | void ClassEditor::changeEvent(QEvent *e) |
297 | void ClassEditor::changeEvent(QEvent *e) |
298 | {
|
298 | {
|
299 | QMainWindow::changeEvent(e); |
299 | QMainWindow::changeEvent(e); |
300 | switch (e->type()) { |
300 | switch (e->type()) { |
301 | case QEvent::LanguageChange: |
301 | case QEvent::LanguageChange: |
302 | ui->retranslateUi(this); |
302 | ui->retranslateUi(this); |
303 | break; |
303 | break; |
304 | default: |
304 | default: |
305 | break; |
305 | break; |
306 | }
|
306 | }
|
307 | }
|
307 | }
|
308 | 308 | ||
309 | 309 | ||
310 | /*
|
310 | /*
|
311 | void ClassEditor::addNewClass(){
|
311 | void ClassEditor::addNewClass(){
|
312 | 312 | ||
313 | int row = model->rowCount();
|
313 | int row = model->rowCount();
|
314 | 314 | ||
315 | model->insertRows(row, 1);
|
315 | model->insertRows(row, 1);
|
316 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
316 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
317 | 317 | ||
318 | 318 | ||
319 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
319 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
320 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
320 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
321 | 321 | ||
322 | 322 | ||
323 | model->submitAll();
|
323 | model->submitAll();
|
324 | 324 | ||
325 | row = model->rowCount();
|
325 | row = model->rowCount();
|
326 | QString tmp_str;
|
326 | QString tmp_str;
|
327 | int i_tmp;
|
327 | int i_tmp;
|
328 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
328 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
329 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
329 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
330 | 330 | ||
331 | tmp_str.append(tr("_Inctance"));
|
331 | tmp_str.append(tr("_Inctance"));
|
332 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
332 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
333 | 333 | ||
334 | model->submitAll();
|
334 | model->submitAll();
|
335 | mymodel->select();
|
335 | mymodel->select();
|
336 | 336 | ||
337 | 337 | ||
338 | }
|
338 | }
|
339 | */
|
339 | */
|
340 | 340 | ||
341 | void ClassEditor::addNewClass_new(){ |
341 | void ClassEditor::addNewClass_new(){ |
342 | 342 | ||
343 | int row = mymodel->rowCount(); |
343 | int row = mymodel->rowCount(); |
344 | 344 | ||
345 | mymodel->insertRows(row, 1); |
345 | mymodel->insertRows(row, 1); |
346 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
346 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
347 | 347 | ||
348 | 348 | ||
349 | mymodel->submitAll(); |
349 | mymodel->submitAll(); |
350 | row = mymodel->rowCount(); |
350 | row = mymodel->rowCount(); |
351 | QString tmp_str1, sql_str;
|
351 | QString tmp_str1, sql_str;
|
352 | int i_tmp1; |
352 | int i_tmp1; |
353 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
353 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
354 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
354 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
355 | 355 | ||
356 | tmp_str1.append(tr("_Inctance")); |
356 | tmp_str1.append(tr("_Inctance")); |
357 | SqlTable* tbl; |
357 | SqlTable* tbl; |
358 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
358 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
359 | sql_str = tbl->sqlString(); |
359 | sql_str = tbl->sqlString(); |
360 | bool ok; |
360 | bool ok; |
361 | 361 | ||
362 | ok = sql.createTable(tbl); |
362 | ok = sql.createTable(tbl); |
363 | 363 | ||
364 | if (!ok) { |
364 | if (!ok) { |
365 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
365 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
366 | this, // Ðîäèòåëüñêèé âèäæåò. |
366 | this, // Ðîäèòåëüñêèé âèäæåò. |
367 | QObject::tr("Database Error"), // Çàãîëîâîê. |
367 | QObject::tr("Database Error"), // Çàãîëîâîê. |
368 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
368 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
369 | delete tbl; |
369 | delete tbl; |
370 | mymodel->removeRow(row-1); |
370 | mymodel->removeRow(row-1); |
371 | mymodel->submitAll(); |
371 | mymodel->submitAll(); |
372 | mymodel->select(); |
372 | mymodel->select(); |
373 | ui->tableView_2->resizeRowsToContents(); |
373 | ui->tableView_2->resizeRowsToContents(); |
374 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
374 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
375 | 375 | ||
376 | }
|
376 | }
|
377 | 377 | ||
378 | delete tbl; |
378 | delete tbl; |
379 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
379 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
380 | 380 | ||
381 | 381 | ||
382 | 382 | ||
383 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
383 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
384 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
384 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
385 | 385 | ||
386 | 386 | ||
387 | //mymodel->submitAll();
|
387 | //mymodel->submitAll();
|
388 | 388 | ||
389 | //row = mymodel->rowCount();
|
389 | //row = mymodel->rowCount();
|
390 | 390 | ||
391 | 391 | ||
392 | //mymodel->select();
|
392 | //mymodel->select();
|
393 | 393 | ||
394 | 394 | ||
395 | }
|
395 | }
|
396 | 396 | ||
397 | 397 | ||
398 | void ClassEditor::addNewField(){ |
398 | void ClassEditor::addNewField(){ |
399 | // QSqlRecord rec = mymodel->record(1);
|
399 | // QSqlRecord rec = mymodel->record(1);
|
400 | //bool ok;
|
400 | //bool ok;
|
401 | //ok = rec.isEmpty();
|
401 | //ok = rec.isEmpty();
|
402 | //QString currientClassID;
|
402 | //QString currientClassID;
|
403 | //currientClassID = rec.value(1).toString();
|
403 | //currientClassID = rec.value(1).toString();
|
404 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
404 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
405 | QString query_str = tr("ALTER TABLE "); |
405 | QString query_str = tr("ALTER TABLE "); |
406 | QString db_error;
|
406 | QString db_error;
|
407 | QSqlQuery q;
|
407 | QSqlQuery q;
|
408 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
408 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
409 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
409 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
410 | query_str.append( Inctance_str); |
410 | query_str.append( Inctance_str); |
411 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
411 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
412 | bool ok = q.prepare(query_str); |
412 | bool ok = q.prepare(query_str); |
413 | 413 | ||
414 | ok = q.exec(); |
414 | ok = q.exec(); |
415 | if (!ok) { |
415 | if (!ok) { |
416 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
416 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
417 | this, // Ðîäèòåëüñêèé âèäæåò. |
417 | this, // Ðîäèòåëüñêèé âèäæåò. |
418 | QObject::tr("Database Error"), // Çàãîëîâîê. |
418 | QObject::tr("Database Error"), // Çàãîëîâîê. |
419 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
419 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
420 | 420 | ||
421 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
421 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
422 | 422 | ||
423 | }
|
423 | }
|
424 | 424 | ||
425 | int row = modelForDescription->rowCount(); |
425 | int row = modelForDescription->rowCount(); |
426 | modelForDescription->insertRows(row, 1); |
426 | modelForDescription->insertRows(row, 1); |
427 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
427 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
428 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
428 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
429 | 429 | ||
430 | modelForDescription->submitAll(); |
430 | modelForDescription->submitAll(); |
431 | 431 | ||
432 | delete model; |
432 | delete model; |
433 | delete tableForInstance; |
433 | delete tableForInstance; |
434 | model = new QSqlTableModel(); |
434 | model = new QSqlTableModel(); |
435 | tableForInstance = new QTableView(); |
435 | tableForInstance = new QTableView(); |
436 | model->setTable(Inctance_str); |
436 | model->setTable(Inctance_str); |
437 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
437 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
438 | tableForInstance->setModel(model); |
438 | tableForInstance->setModel(model); |
439 | tableForInstance->setWindowTitle(Inctance_str); |
439 | tableForInstance->setWindowTitle(Inctance_str); |
440 | tableForInstance->show(); |
440 | tableForInstance->show(); |
441 | }
|
441 | }
|
442 | 442 | ||
443 | 443 | ||
444 | 444 | ||
445 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
445 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
446 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
446 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
447 | QString query_str = tr("ALTER TABLE "); |
447 | QString query_str = tr("ALTER TABLE "); |
448 | QString db_error;
|
448 | QString db_error;
|
449 | QSqlQuery q;
|
449 | QSqlQuery q;
|
450 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
450 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
451 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
451 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
452 | query_str.append( Inctance_str); |
452 | query_str.append( Inctance_str); |
453 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
453 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
454 | bool ok = q.prepare(query_str); |
454 | bool ok = q.prepare(query_str); |
455 | 455 | ||
456 | ok = q.exec(); |
456 | ok = q.exec(); |
457 | if (!ok) { |
457 | if (!ok) { |
458 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
458 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
459 | this, // Ðîäèòåëüñêèé âèäæåò. |
459 | this, // Ðîäèòåëüñêèé âèäæåò. |
460 | QObject::tr("Database Error"), // Çàãîëîâîê. |
460 | QObject::tr("Database Error"), // Çàãîëîâîê. |
461 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
461 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
462 | 462 | ||
463 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
463 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
464 | 464 | ||
465 | }
|
465 | }
|
466 | 466 | ||
467 | 467 | ||
468 | int row = ClassEditor::modelForPointers->rowCount(); |
468 | int row = ClassEditor::modelForPointers->rowCount(); |
469 | modelForPointers->insertRows(row, 1); |
469 | modelForPointers->insertRows(row, 1); |
470 | 470 | ||
471 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
471 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
473 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
473 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
474 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
474 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
475 | 475 | ||
476 | 476 | ||
477 | modelForPointers->submitAll(); |
477 | modelForPointers->submitAll(); |
478 | 478 | ||
479 | 479 | ||
480 | 480 | ||
481 | 481 | ||
482 | 482 | ||
483 | 483 | ||
484 | 484 | ||
485 | 485 | ||
486 | /*
|
486 | /*
|
487 | 487 | ||
488 | str_fltr = tr("ClassIdentifer = ");
|
488 | str_fltr = tr("ClassIdentifer = ");
|
489 | modelForPointers->setInctance(Inctance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
489 | modelForPointers->setInctance(Inctance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
490 | str_fltr.append(class_indx);
|
490 | str_fltr.append(class_indx);
|
491 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
491 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
492 | // str_fltr.append( tr(" FieldType = pointer "));
|
492 | // str_fltr.append( tr(" FieldType = pointer "));
|
493 | 493 | ||
494 | 494 | ||
495 | 495 | ||
496 | modelForPointers->setFilter(str_fltr);
|
496 | modelForPointers->setFilter(str_fltr);
|
497 | modelForPointers->select();
|
497 | modelForPointers->select();
|
498 | ui->tableView_3->setModel(modelForPointers);
|
498 | ui->tableView_3->setModel(modelForPointers);
|
499 | ui->tableView_3->resizeColumnsToContents();
|
499 | ui->tableView_3->resizeColumnsToContents();
|
500 | */
|
500 | */
|
501 | 501 | ||
502 | 502 | ||
503 | 503 | ||
504 | 504 | ||
505 | // modelForPointers->select();
|
505 | // modelForPointers->select();
|
506 | 506 | ||
507 | 507 | ||
508 | 508 | ||
509 | 509 | ||
510 | 510 | ||
511 | ClassEditor::refreshInctance(); |
511 | ClassEditor::refreshInctance(); |
512 | 512 | ||
513 | 513 | ||
514 | 514 | ||
515 | 515 | ||
516 | 516 | ||
517 | 517 | ||
518 | 518 | ||
519 | 519 | ||
520 | 520 | ||
521 | }
|
521 | }
|
522 | 522 | ||
523 | 523 | ||
524 | 524 | ||
525 | 525 | ||
526 | 526 | ||
527 | // äîáàâëÿåì íîâûé êëàññ
|
527 | // äîáàâëÿåì íîâûé êëàññ
|
528 | void ClassEditor::on_pushButton_clicked(){ |
528 | void ClassEditor::on_pushButton_clicked(){ |
529 | //int i;
|
529 | //int i;
|
530 | //i++;
|
530 | //i++;
|
531 | /////ClassEditor::addNewClass();
|
531 | /////ClassEditor::addNewClass();
|
532 | ClassEditor::addNewClass_new(); |
532 | ClassEditor::addNewClass_new(); |
533 | mymodel->select(); |
533 | mymodel->select(); |
534 | ui->tableView->resizeColumnsToContents(); |
534 | ui->tableView->resizeColumnsToContents(); |
535 | ui->tableView->resizeRowsToContents(); |
535 | ui->tableView->resizeRowsToContents(); |
536 | 536 | ||
537 | //ui->tableView->setModel(mymodel);
|
537 | //ui->tableView->setModel(mymodel);
|
538 | 538 | ||
539 | }
|
539 | }
|
540 | 540 | ||
541 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
541 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
542 | bool indexIsValid; |
542 | bool indexIsValid; |
543 | int i, row, column; |
543 | int i, row, column; |
544 | i++; |
544 | i++; |
545 | indexIsValid = index.isValid(); |
545 | indexIsValid = index.isValid(); |
546 | row = index.row(); |
546 | row = index.row(); |
547 | column = index.column(); |
547 | column = index.column(); |
548 | currIndexOfClassesTable = index; |
548 | currIndexOfClassesTable = index; |
549 | QModelIndex index_tmp, index_instance;
|
549 | QModelIndex index_tmp, index_instance;
|
550 | QString tmp_str, filter_str, instance_str;
|
550 | QString tmp_str, filter_str, instance_str;
|
551 | index_tmp = ui->tableView->model()->index(row, 0); |
551 | index_tmp = ui->tableView->model()->index(row, 0); |
552 | index_instance = ui->tableView->model()->index(row, 3); |
552 | index_instance = ui->tableView->model()->index(row, 3); |
553 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
553 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
554 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
554 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
555 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
555 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
556 | modelForPointers->setInctance(instance_str); |
556 | modelForPointers->setInctance(instance_str); |
557 | 557 | ||
558 | delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ |
558 | delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ |
559 | 559 | ||
560 | // instance_str.append(tr("_inctance"));
|
560 | // instance_str.append(tr("_inctance"));
|
561 | /*
|
561 | /*
|
562 | Inctance_model.clear();
|
562 | Inctance_model.clear();
|
563 | Inctance_model.setTable(instance_str);
|
563 | Inctance_model.setTable(instance_str);
|
564 | Inctance_model.select();
|
564 | Inctance_model.select();
|
565 | tableForInstance_new.setModel(&Inctance_model);
|
565 | tableForInstance_new.setModel(&Inctance_model);
|
566 | tableForInstance_new.show();
|
566 | tableForInstance_new.show();
|
567 | */
|
567 | */
|
568 | // model->clear();
|
568 | // model->clear();
|
569 | tableForInstance->close(); |
569 | tableForInstance->close(); |
570 | delete model; |
570 | delete model; |
571 | delete tableForInstance; |
571 | delete tableForInstance; |
572 | model = new QSqlTableModel(); |
572 | model = new QSqlTableModel(); |
573 | tableForInstance = new QTableView(); |
573 | tableForInstance = new QTableView(); |
574 | model->setTable(instance_str); |
574 | model->setTable(instance_str); |
575 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
575 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
576 | tableForInstance->setModel(model); |
576 | tableForInstance->setModel(model); |
577 | 577 | ||
578 | model->select(); |
578 | model->select(); |
579 | tableForInstance->setWindowTitle(instance_str); |
579 | tableForInstance->setWindowTitle(instance_str); |
580 | // // // tableForInstance->show();
|
580 | // // // tableForInstance->show();
|
581 | 581 | ||
582 | // tableForInstance.setModel(model);
|
582 | // tableForInstance.setModel(model);
|
583 | tableForInstance->resizeColumnsToContents(); |
583 | tableForInstance->resizeColumnsToContents(); |
584 | 584 | ||
585 | currClassID = tmp_str; |
585 | currClassID = tmp_str; |
586 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
586 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
587 | filter_str = tr("ClassIdentifer = "); |
587 | filter_str = tr("ClassIdentifer = "); |
588 | filter_str.append(tmp_str); |
588 | filter_str.append(tmp_str); |
589 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
589 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
590 | modelForDescription->setFilter(filter_str); |
590 | modelForDescription->setFilter(filter_str); |
591 | modelForDescription->select(); |
591 | modelForDescription->select(); |
592 | ui->tableView_2->resizeColumnsToContents(); |
592 | ui->tableView_2->resizeColumnsToContents(); |
593 | 593 | ||
594 | filter_str = tr("ClassIdentifer = "); |
594 | filter_str = tr("ClassIdentifer = "); |
595 | filter_str.append(tmp_str); |
595 | filter_str.append(tmp_str); |
596 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
596 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
597 | modelForPointers->setFilter(filter_str); |
597 | modelForPointers->setFilter(filter_str); |
598 | modelForPointers->select(); |
598 | modelForPointers->select(); |
599 | ui->tableView_3->resizeColumnsToContents(); |
599 | ui->tableView_3->resizeColumnsToContents(); |
600 | 600 | ||
601 | 601 | ||
602 | 602 | ||
603 | 603 | ||
604 | i++; |
604 | i++; |
605 | }
|
605 | }
|
606 | 606 | ||
607 | 607 | ||
608 | 608 | ||
609 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
609 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
610 | QModelIndex model_index;
|
610 | QModelIndex model_index;
|
611 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
611 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
612 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
612 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
613 | QList<int> selectedRows; |
613 | QList<int> selectedRows; |
614 | selectedRows.clear(); |
614 | selectedRows.clear(); |
615 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
615 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
616 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
616 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
617 | 617 | ||
618 | }
|
618 | }
|
619 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
619 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
620 | 620 | ||
621 | 621 | ||
622 | for (int m =0; m < selectedRows.size(); ++m){ |
622 | for (int m =0; m < selectedRows.size(); ++m){ |
623 | 623 | ||
624 | ClassEditor::removeClass(selectedRows.at(m)); |
624 | ClassEditor::removeClass(selectedRows.at(m)); |
625 | 625 | ||
626 | 626 | ||
627 | 627 | ||
628 | }
|
628 | }
|
629 | mymodel->submitAll(); |
629 | mymodel->submitAll(); |
630 | ClassEditor::modelForDescription->select(); |
630 | ClassEditor::modelForDescription->select(); |
631 | ui->tableView->resizeColumnsToContents(); |
631 | ui->tableView->resizeColumnsToContents(); |
632 | ui->tableView->resizeRowsToContents(); |
632 | ui->tableView->resizeRowsToContents(); |
633 | }
|
633 | }
|
634 | 634 | ||
635 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
635 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
636 | int i; |
636 | int i; |
637 | i++; |
637 | i++; |
638 | ClassEditor::addNewField(); |
638 | ClassEditor::addNewField(); |
639 | ClassEditor::modelForDescription->select(); |
639 | ClassEditor::modelForDescription->select(); |
640 | ui->tableView_2->resizeColumnsToContents(); |
640 | ui->tableView_2->resizeColumnsToContents(); |
641 | }
|
641 | }
|
642 | 642 | ||
643 | 643 | ||
644 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
644 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
645 | // int i;
|
645 | // int i;
|
646 | QModelIndex model_index;
|
646 | QModelIndex model_index;
|
647 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
647 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
648 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
648 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
649 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
649 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
650 | //model_index = mymodel->selec;
|
650 | //model_index = mymodel->selec;
|
651 | //modelList = ui->tableView->SelectItems;
|
651 | //modelList = ui->tableView->SelectItems;
|
652 | //i = indexes.size();
|
652 | //i = indexes.size();
|
653 | QList<int> selectedRows; |
653 | QList<int> selectedRows; |
654 | //indexes_fo_first_col.clear();
|
654 | //indexes_fo_first_col.clear();
|
655 | /*
|
655 | /*
|
656 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
656 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
657 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
657 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
658 | 658 | ||
659 | }
|
659 | }
|
660 | */
|
660 | */
|
661 | selectedRows.clear(); |
661 | selectedRows.clear(); |
662 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
662 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
663 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
663 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
664 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
664 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
665 | }
|
665 | }
|
666 | }
|
666 | }
|
667 | 667 | ||
668 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
668 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
669 | 669 | ||
670 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
670 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
671 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
671 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
672 | for (int m =0; m < selectedRows.size(); ++m){ |
672 | for (int m =0; m < selectedRows.size(); ++m){ |
673 | 673 | ||
674 | 674 | ||
675 | QString query_str;
|
675 | QString query_str;
|
676 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
676 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
677 | QSqlQuery q;
|
677 | QSqlQuery q;
|
678 | 678 | ||
679 | query_str.clear(); |
679 | query_str.clear(); |
680 | 680 | ||
681 | 681 | ||
682 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
682 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
683 | 683 | ||
684 | query_str.append(tr("ALTER TABLE ")); |
684 | query_str.append(tr("ALTER TABLE ")); |
685 | query_str.append(Inctance_str); |
685 | query_str.append(Inctance_str); |
686 | query_str.append(tr(" DROP COLUMN `")); |
686 | query_str.append(tr(" DROP COLUMN `")); |
687 | query_str.append(field_name_str); |
687 | query_str.append(field_name_str); |
688 | query_str.append(tr("`")); |
688 | query_str.append(tr("`")); |
689 | q.prepare(query_str); |
689 | q.prepare(query_str); |
690 | bool ok = q.exec(); |
690 | bool ok = q.exec(); |
691 | if (!ok) { |
691 | if (!ok) { |
692 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
692 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
693 | this, // Ðîäèòåëüñêèé âèäæåò. |
693 | this, // Ðîäèòåëüñêèé âèäæåò. |
694 | QObject::tr("Database Error"), // Çàãîëîâîê. |
694 | QObject::tr("Database Error"), // Çàãîëîâîê. |
695 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
695 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
696 | 696 | ||
697 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
697 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
698 | 698 | ||
699 | }
|
699 | }
|
700 | 700 | ||
701 | 701 | ||
702 | 702 | ||
703 | modelForDescription->removeRow(selectedRows.at(m)); |
703 | modelForDescription->removeRow(selectedRows.at(m)); |
704 | 704 | ||
705 | }
|
705 | }
|
706 | delete model; |
706 | delete model; |
707 | delete tableForInstance; |
707 | delete tableForInstance; |
708 | model = new QSqlTableModel(); |
708 | model = new QSqlTableModel(); |
709 | tableForInstance = new QTableView(); |
709 | tableForInstance = new QTableView(); |
710 | model->setTable(Inctance_str); |
710 | model->setTable(Inctance_str); |
711 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
711 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
712 | tableForInstance->setModel(model); |
712 | tableForInstance->setModel(model); |
713 | tableForInstance->setWindowTitle(Inctance_str); |
713 | tableForInstance->setWindowTitle(Inctance_str); |
714 | tableForInstance->show(); |
714 | tableForInstance->show(); |
715 | //i = selectedRows.size();
|
715 | //i = selectedRows.size();
|
716 | 716 | ||
717 | //if (i > 0) model_index = indexes.at(0);
|
717 | //if (i > 0) model_index = indexes.at(0);
|
718 | }
|
718 | }
|
719 | 719 | ||
720 | 720 | ||
721 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
721 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
722 | QModelIndex model_index;
|
722 | QModelIndex model_index;
|
723 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
723 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
724 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
724 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
725 | QList<int> selectedRows; |
725 | QList<int> selectedRows; |
726 | 726 | ||
727 | selectedRows.clear(); |
727 | selectedRows.clear(); |
728 | 728 | ||
729 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
729 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
730 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
730 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
731 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
731 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
732 | }
|
732 | }
|
733 | }
|
733 | }
|
734 | 734 | ||
735 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
735 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
736 | 736 | ||
737 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
737 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
738 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
738 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
739 | for (int m =0; m < selectedRows.size(); ++m){ |
739 | for (int m =0; m < selectedRows.size(); ++m){ |
740 | 740 | ||
741 | 741 | ||
742 | QString query_str;
|
742 | QString query_str;
|
743 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
743 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
744 | QSqlQuery q;
|
744 | QSqlQuery q;
|
745 | 745 | ||
746 | query_str.clear(); |
746 | query_str.clear(); |
747 | 747 | ||
748 | 748 | ||
749 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
749 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
750 | 750 | ||
751 | query_str.append(tr("ALTER TABLE ")); |
751 | query_str.append(tr("ALTER TABLE ")); |
752 | query_str.append(Inctance_str); |
752 | query_str.append(Inctance_str); |
753 | query_str.append(tr(" DROP COLUMN `")); |
753 | query_str.append(tr(" DROP COLUMN `")); |
754 | query_str.append(field_name_str); |
754 | query_str.append(field_name_str); |
755 | query_str.append(tr("`")); |
755 | query_str.append(tr("`")); |
756 | q.prepare(query_str); |
756 | q.prepare(query_str); |
757 | bool ok = q.exec(); |
757 | bool ok = q.exec(); |
758 | if (!ok) { |
758 | if (!ok) { |
759 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
759 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
760 | this, // Ðîäèòåëüñêèé âèäæåò. |
760 | this, // Ðîäèòåëüñêèé âèäæåò. |
761 | QObject::tr("Database Error"), // Çàãîëîâîê. |
761 | QObject::tr("Database Error"), // Çàãîëîâîê. |
762 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
762 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
763 | 763 | ||
764 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
764 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
765 | 765 | ||
766 | }
|
766 | }
|
767 | 767 | ||
768 | 768 | ||
769 | 769 | ||
770 | modelForPointers->removeRow(selectedRows.at(m)); |
770 | modelForPointers->removeRow(selectedRows.at(m)); |
771 | 771 | ||
772 | }
|
772 | }
|
773 | 773 | ||
774 | 774 | ||
775 | refreshInctance(); |
775 | refreshInctance(); |
776 | 776 | ||
777 | 777 | ||
778 | 778 | ||
779 | }
|
779 | }
|
780 | 780 | ||
781 | 781 | ||
782 | 782 | ||
783 | 783 | ||
784 | 784 | ||
785 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
785 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
786 | int row; |
786 | int row; |
787 | row = ClassEditor::modelForDescription->rowCount(); |
787 | row = ClassEditor::modelForDescription->rowCount(); |
788 | ClassEditor::modelForDescription->removeRows(0, row); |
788 | ClassEditor::modelForDescription->removeRows(0, row); |
789 | ClassEditor::modelForDescription->submitAll(); |
789 | ClassEditor::modelForDescription->submitAll(); |
790 | }
|
790 | }
|
791 | 791 | ||
792 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
792 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
793 | QString fileName;
|
793 | QString fileName;
|
794 | QPixmap pixmap;
|
794 | QPixmap pixmap;
|
795 | fileName = QFileDialog::getOpenFileName(this, |
795 | fileName = QFileDialog::getOpenFileName(this, |
796 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
796 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
797 | pixmap.load(fileName); |
797 | pixmap.load(fileName); |
798 | ui->label_4->setPixmap(pixmap); |
798 | ui->label_4->setPixmap(pixmap); |
799 | QImage currentImage = pixmap.toImage(); |
799 | QImage currentImage = pixmap.toImage(); |
800 | QByteArray bytes;
|
800 | QByteArray bytes;
|
801 | QBuffer buffer(&bytes); |
801 | QBuffer buffer(&bytes); |
802 | buffer.open(QIODevice::WriteOnly); |
802 | buffer.open(QIODevice::WriteOnly); |
803 | currentImage.save(&buffer, "PNG"); |
803 | currentImage.save(&buffer, "PNG"); |
804 | 804 | ||
805 | if (currIndexOfClassesTable.isValid()) { |
805 | if (currIndexOfClassesTable.isValid()) { |
806 | bool ok; |
806 | bool ok; |
807 | 807 | ||
808 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
808 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
809 | mymodel->submitAll(); |
809 | mymodel->submitAll(); |
810 | 810 | ||
811 | 811 | ||
812 | }
|
812 | }
|
813 | 813 | ||
814 | 814 | ||
815 | }
|
815 | }
|
816 | 816 | ||
817 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
817 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
818 | 818 | ||
819 | int i; |
819 | int i; |
820 | i++; |
820 | i++; |
821 | ui->tableView->resizeColumnsToContents(); |
821 | ui->tableView->resizeColumnsToContents(); |
822 | ui->tableView->resizeRowsToContents(); |
822 | ui->tableView->resizeRowsToContents(); |
823 | 823 | ||
824 | 824 | ||
825 | 825 | ||
826 | 826 | ||
827 | }
|
827 | }
|
828 | 828 | ||
829 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
829 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
830 | ui->tableView_2->resizeColumnsToContents(); |
830 | ui->tableView_2->resizeColumnsToContents(); |
831 | 831 | ||
832 | /*
|
832 | /*
|
833 | QString instance_str;
|
833 | QString instance_str;
|
834 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
834 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
835 | tableForInstance->close();
|
835 | tableForInstance->close();
|
836 | delete model;
|
836 | delete model;
|
837 | delete tableForInstance;
|
837 | delete tableForInstance;
|
838 | model = new QSqlTableModel();
|
838 | model = new QSqlTableModel();
|
839 | tableForInstance = new QTableView();
|
839 | tableForInstance = new QTableView();
|
840 | model->setTable(instance_str);
|
840 | model->setTable(instance_str);
|
841 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
841 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
842 | tableForInstance->setModel(model);
|
842 | tableForInstance->setModel(model);
|
843 | 843 | ||
844 | model->select();
|
844 | model->select();
|
845 | tableForInstance->setWindowTitle(instance_str);
|
845 | tableForInstance->setWindowTitle(instance_str);
|
846 | tableForInstance->show();
|
846 | tableForInstance->show();
|
847 | */
|
847 | */
|
848 | }
|
848 | }
|
849 | 849 | ||
850 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
850 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
851 | if (is_checked) ui->tableView->showColumn(0); |
851 | if (is_checked) ui->tableView->showColumn(0); |
852 | else ui->tableView->hideColumn(0); |
852 | else ui->tableView->hideColumn(0); |
853 | ui->tableView->resizeColumnsToContents(); |
853 | ui->tableView->resizeColumnsToContents(); |
854 | }
|
854 | }
|
855 | 855 | ||
856 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
856 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
857 | if (is_checked) ui->tableView->showColumn(2); |
857 | if (is_checked) ui->tableView->showColumn(2); |
858 | else ui->tableView->hideColumn(2); |
858 | else ui->tableView->hideColumn(2); |
859 | ui->tableView->resizeColumnsToContents(); |
859 | ui->tableView->resizeColumnsToContents(); |
860 | }
|
860 | }
|
861 | 861 | ||
862 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
862 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
863 | if (is_checked) ui->tableView->showColumn(3); |
863 | if (is_checked) ui->tableView->showColumn(3); |
864 | else ui->tableView->hideColumn(3); |
864 | else ui->tableView->hideColumn(3); |
865 | ui->tableView->resizeColumnsToContents(); |
865 | ui->tableView->resizeColumnsToContents(); |
866 | }
|
866 | }
|
867 | 867 | ||
868 | 868 | ||
869 | 869 | ||
870 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
870 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
871 | int row; |
871 | int row; |
872 | row = ClassEditor::mymodel->rowCount(); |
872 | row = ClassEditor::mymodel->rowCount(); |
873 | for (int m=0; m < row; ++m){ |
873 | for (int m=0; m < row; ++m){ |
874 | ClassEditor::removeClass(0); |
874 | ClassEditor::removeClass(0); |
875 | //ClassEditor::mymodel->removeRows(0, row);
|
875 | //ClassEditor::mymodel->removeRows(0, row);
|
876 | }
|
876 | }
|
877 | ClassEditor::mymodel->submitAll(); |
877 | ClassEditor::mymodel->submitAll(); |
878 | ClassEditor::modelForDescription->select(); |
878 | ClassEditor::modelForDescription->select(); |
879 | }
|
879 | }
|
880 | 880 | ||
881 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
881 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
882 | QModelIndex index_tmp;
|
882 | QModelIndex index_tmp;
|
883 | QString tmp_str, filter_str;
|
883 | QString tmp_str, filter_str;
|
884 | index_tmp = ui->tableView->model()->index(class_row, 0); |
884 | index_tmp = ui->tableView->model()->index(class_row, 0); |
885 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
885 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
886 | currClassID = tmp_str; |
886 | currClassID = tmp_str; |
887 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
887 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
888 | filter_str = tr("ClassIdentifer = "); |
888 | filter_str = tr("ClassIdentifer = "); |
889 | filter_str.append(tmp_str); |
889 | filter_str.append(tmp_str); |
890 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
890 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
891 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
891 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
892 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
892 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
893 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
893 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
894 | ui->tableView->resizeColumnsToContents(); |
894 | ui->tableView->resizeColumnsToContents(); |
895 | ui->tableView_2->resizeColumnsToContents(); |
895 | ui->tableView_2->resizeColumnsToContents(); |
896 | 896 | ||
897 | }
|
897 | }
|
898 | 898 | ||
899 | 899 | ||
900 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
900 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
901 | ClassEditor::refreshInctance(); |
901 | ClassEditor::refreshInctance(); |
902 | }
|
902 | }
|
903 | 903 | ||
904 | 904 | ||
905 | 905 | ||
906 | 906 | ||
907 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
907 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
908 | 908 | ||
909 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
909 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
910 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
910 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
911 | delete model; |
911 | delete model; |
912 | delete tableForInstance; |
912 | delete tableForInstance; |
913 | model = new QSqlTableModel(); |
913 | model = new QSqlTableModel(); |
914 | tableForInstance = new QTableView(); |
914 | tableForInstance = new QTableView(); |
915 | model->setTable(Inctance_str); |
915 | model->setTable(Inctance_str); |
916 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
916 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
917 | model->select(); |
917 | model->select(); |
918 | tableForInstance->setModel(model); |
918 | tableForInstance->setModel(model); |
919 | tableForInstance->setWindowTitle(Inctance_str); |
919 | tableForInstance->setWindowTitle(Inctance_str); |
920 | tableForInstance->resizeRowsToContents(); |
920 | tableForInstance->resizeRowsToContents(); |
921 | tableForInstance->show(); |
921 | tableForInstance->show(); |
922 | 922 | ||
923 | }
|
923 | }
|
924 | 924 | ||
925 | 925 | ||
926 | 926 | ||
927 | 927 | ||
928 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
928 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
929 | ClassEditor::addNewPointer(); |
929 | ClassEditor::addNewPointer(); |
930 | ClassEditor::modelForPointers->select(); |
930 | ClassEditor::modelForPointers->select(); |
931 | ui->tableView_3->resizeColumnsToContents(); |
931 | ui->tableView_3->resizeColumnsToContents(); |
932 | 932 | ||
933 | }
|
933 | }
|
934 | 934 | ||
935 | 935 | ||
936 | // Ñ÷èòûâàåì íàñòðîéêè
|
936 | // Ñ÷èòûâàåì íàñòðîéêè
|
937 | 937 | ||
938 | void ClassEditor::readSettings() |
938 | void ClassEditor::readSettings() |
939 | {
|
939 | {
|
940 | QSettings settings("Trolltech", "Application Example"); |
940 | QSettings settings("Trolltech", "Application Example"); |
941 | baseName = settings.value("baseName", "an_db").toString(); |
941 | baseName = settings.value("baseName", "an_db").toString(); |
942 | userName = settings.value("userName", "an").toString(); |
942 | userName = settings.value("userName", "an").toString(); |
943 | password = settings.value("password", "393939").toString(); |
943 | password = settings.value("password", "393939").toString(); |
944 | tableName = settings.value("tableName", "inventar").toString(); |
944 | tableName = settings.value("tableName", "inventar").toString(); |
945 | hostName = settings.value("hostName", "server").toString(); |
945 | hostName = settings.value("hostName", "server").toString(); |
946 | // resize(size);
|
946 | // resize(size);
|
947 | // move(pos);tableName
|
947 | // move(pos);tableName
|
948 | }
|
948 | }
|
949 | 949 | ||
950 | 950 | ||
951 | void ClassEditor::writeSettings() |
951 | void ClassEditor::writeSettings() |
952 | {
|
952 | {
|
953 | QSettings settings("Trolltech", "Application Example"); |
953 | QSettings settings("Trolltech", "Application Example"); |
954 | settings.setValue("baseName", baseName); |
954 | settings.setValue("baseName", baseName); |
955 | settings.setValue("userName", userName); |
955 | settings.setValue("userName", userName); |
956 | settings.setValue("password", password); |
956 | settings.setValue("password", password); |
957 | settings.setValue("tableName", tableName); |
957 | settings.setValue("tableName", tableName); |
958 | settings.setValue("hostName", hostName); |
958 | settings.setValue("hostName", hostName); |
959 | }
|
959 | }
|
960 | 960 | ||
961 | 961 | ||
962 | void ClassEditor::applySetting() |
962 | void ClassEditor::applySetting() |
963 | {
|
963 | {
|
964 | bool ok; |
964 | bool ok; |
965 | baseName = setFrm.lineEdit->text(); |
965 | baseName = setFrm.lineEdit->text(); |
966 | userName = setFrm.lineEdit_2->text(); |
966 | userName = setFrm.lineEdit_2->text(); |
967 | password = setFrm.lineEdit_3->text(); |
967 | password = setFrm.lineEdit_3->text(); |
968 | // tableName = setFrm->lineEdit_4->text();
|
968 | // tableName = setFrm->lineEdit_4->text();
|
969 | hostName = setFrm.lineEdit_5->text(); |
969 | hostName = setFrm.lineEdit_5->text(); |
970 | writeSettings(); |
970 | writeSettings(); |
971 | 971 | ||
972 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
972 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
973 | 973 | ||
974 | sql.setDatabaseName(baseName); |
974 | sql.setDatabaseName(baseName); |
975 | // sql.setDatabaseName(tr("inventory"));
|
975 | // sql.setDatabaseName(tr("inventory"));
|
976 | 976 | ||
977 | // sql.setHostName(tr("localhost"));
|
977 | // sql.setHostName(tr("localhost"));
|
978 | sql.setHostName(hostName); |
978 | sql.setHostName(hostName); |
979 | 979 | ||
980 | // sql.setUserName(tr("an"));
|
980 | // sql.setUserName(tr("an"));
|
981 | 981 | ||
982 | sql.setUserName(userName); |
982 | sql.setUserName(userName); |
983 | 983 | ||
984 | // sql.setPassword(tr("393939"));
|
984 | // sql.setPassword(tr("393939"));
|
985 | 985 | ||
986 | sql.setPassword(password); |
986 | sql.setPassword(password); |
987 | 987 | ||
988 | ok = sql.connect(); |
988 | ok = sql.connect(); |
989 | if (!ok) { |
989 | if (!ok) { |
990 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
990 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
991 | this, // Ðîäèòåëüñêèé âèäæåò. |
991 | this, // Ðîäèòåëüñêèé âèäæåò. |
992 | QObject::tr("Database Error"), // Çàãîëîâîê. |
992 | QObject::tr("Database Error"), // Çàãîëîâîê. |
993 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
993 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
994 | 994 | ||
995 | }
|
995 | }
|
996 | else { |
996 | else { |
997 | 997 | ||
998 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
998 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
999 | this, // Ðîäèòåëüñêèé âèäæåò. |
999 | this, // Ðîäèòåëüñêèé âèäæåò. |
1000 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1000 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1001 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1001 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1002 | 1002 | ||
1003 | 1003 | ||
1004 | 1004 | ||
1005 | 1005 | ||
1006 | 1006 | ||
1007 | }
|
1007 | }
|
1008 | 1008 | ||
1009 | 1009 | ||
1010 | mymodel->select(); |
1010 | mymodel->select(); |
1011 | model->select(); |
1011 | model->select(); |
1012 | modelForDescription->select(); |
1012 | modelForDescription->select(); |
1013 | 1013 | ||
1014 | //////////// ok=openDataBase();
|
1014 | //////////// ok=openDataBase();
|
1015 | //////////// if (!ok) return;
|
1015 | //////////// if (!ok) return;
|
1016 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1016 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1017 | 1017 | ||
1018 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1018 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1019 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1019 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1020 | //////////// initComboBox();
|
1020 | //////////// initComboBox();
|
1021 | // // // getDatabaseData();
|
1021 | // // // getDatabaseData();
|
1022 | // delete setFrm;
|
1022 | // delete setFrm;
|
1023 | setFrm.close(); |
1023 | setFrm.close(); |
1024 | }
|
1024 | }
|
1025 | 1025 | ||
1026 | void ClassEditor::getSetting() |
1026 | void ClassEditor::getSetting() |
1027 | {
|
1027 | {
|
1028 | // setFrm = new settingForm;
|
1028 | // setFrm = new settingForm;
|
1029 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1029 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1030 | setFrm.lineEdit->setText(baseName); |
1030 | setFrm.lineEdit->setText(baseName); |
1031 | setFrm.lineEdit_2->setText(userName); |
1031 | setFrm.lineEdit_2->setText(userName); |
1032 | setFrm.lineEdit_3->setText(password); |
1032 | setFrm.lineEdit_3->setText(password); |
1033 | // setFrm->lineEdit_4->setText(tableName);
|
1033 | // setFrm->lineEdit_4->setText(tableName);
|
1034 | setFrm.lineEdit_5->setText(hostName); |
1034 | setFrm.lineEdit_5->setText(hostName); |
1035 | setFrm.show(); |
1035 | setFrm.show(); |
1036 | 1036 | ||
1037 | 1037 | ||
1038 | 1038 | ||
1039 | }
|
1039 | }
|
1040 | 1040 | ||
1041 | 1041 | ||
1042 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1042 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1043 | 1043 | ||
1044 | sql.setDatabaseName(baseName); |
1044 | sql.setDatabaseName(baseName); |
1045 | sql.setHostName(hostName); |
1045 | sql.setHostName(hostName); |
1046 | sql.setUserName(userName); |
1046 | sql.setUserName(userName); |
1047 | sql.setPassword(password); |
1047 | sql.setPassword(password); |
1048 | 1048 | ||
1049 | bool ok; |
1049 | bool ok; |
1050 | ok = sql.connect(); |
1050 | ok = sql.connect(); |
1051 | if (!ok) { |
1051 | if (!ok) { |
1052 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1052 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1053 | this, // Ðîäèòåëüñêèé âèäæåò. |
1053 | this, // Ðîäèòåëüñêèé âèäæåò. |
1054 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1054 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1055 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1055 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1056 | 1056 | ||
1057 | }
|
1057 | }
|
1058 | else { |
1058 | else { |
1059 | 1059 | ||
1060 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1060 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1061 | this, // Ðîäèòåëüñêèé âèäæåò. |
1061 | this, // Ðîäèòåëüñêèé âèäæåò. |
1062 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1062 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1063 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1063 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1064 | 1064 | ||
1065 | 1065 | ||
1066 | 1066 | ||
1067 | 1067 | ||
1068 | 1068 | ||
1069 | }
|
1069 | }
|
1070 | 1070 | ||
1071 | }
|
1071 | }
|
1072 | 1072 | ||
1073 | 1073 | ||
1074 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1074 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1075 | 1075 | ||
1076 | bool ok; |
1076 | bool ok; |
1077 | ok = sql.createListOfClassesTable(); |
1077 | ok = sql.createListOfClassesTable(); |
1078 | 1078 | ||
1079 | if (!ok) { |
1079 | if (!ok) { |
1080 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1080 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1081 | this, // Ðîäèòåëüñêèé âèäæåò. |
1081 | this, // Ðîäèòåëüñêèé âèäæåò. |
1082 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1082 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1083 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1083 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1084 | 1084 | ||
1085 | }
|
1085 | }
|
1086 | else { |
1086 | else { |
1087 | 1087 | ||
1088 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1088 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1089 | this, // Ðîäèòåëüñêèé âèäæåò. |
1089 | this, // Ðîäèòåëüñêèé âèäæåò. |
1090 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1090 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1091 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1091 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1092 | }
|
1092 | }
|
1093 | 1093 | ||
1094 | 1094 | ||
1095 | 1095 | ||
1096 | 1096 | ||
1097 | ok = sql.createDescriptionOfClassesTable(); |
1097 | ok = sql.createDescriptionOfClassesTable(); |
1098 | 1098 | ||
1099 | if (!ok) { |
1099 | if (!ok) { |
1100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1101 | this, // Ðîäèòåëüñêèé âèäæåò. |
1101 | this, // Ðîäèòåëüñêèé âèäæåò. |
1102 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1102 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1104 | 1104 | ||
1105 | }
|
1105 | }
|
1106 | else { |
1106 | else { |
1107 | 1107 | ||
1108 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1108 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1109 | this, // Ðîäèòåëüñêèé âèäæåò. |
1109 | this, // Ðîäèòåëüñêèé âèäæåò. |
1110 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1110 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1111 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1111 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1112 | }
|
1112 | }
|
1113 | 1113 | ||
1114 | 1114 | ||
1115 | ok = sql.createListModelsTable(); |
1115 | ok = sql.createListModelsTable(); |
1116 | 1116 | ||
1117 | if (!ok) { |
1117 | if (!ok) { |
1118 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1118 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1119 | this, // Ðîäèòåëüñêèé âèäæåò. |
1119 | this, // Ðîäèòåëüñêèé âèäæåò. |
1120 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1120 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1121 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1121 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1122 | 1122 | ||
1123 | }
|
1123 | }
|
1124 | else { |
1124 | else { |
1125 | 1125 | ||
1126 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1126 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1127 | this, // Ðîäèòåëüñêèé âèäæåò. |
1127 | this, // Ðîäèòåëüñêèé âèäæåò. |
1128 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1128 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1129 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1129 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1130 | }
|
1130 | }
|
1131 | 1131 | ||
1132 | 1132 | ||
1133 | 1133 | ||
1134 | 1134 | ||
- | 1135 | ||
- | 1136 | ok = sql.createFiltersTable(); |
|
- | 1137 | ||
- | 1138 | if (!ok) { |
|
- | 1139 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 1140 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 1141 | QObject::tr("Database Error"), // Çàãîëîâîê. |
|
- | 1142 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
|
- | 1143 | ||
- | 1144 | }
|
|
- | 1145 | else { |
|
- | 1146 | ||
- | 1147 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 1148 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 1149 | QObject::tr("Database Create"), // Çàãîëîâîê. |
|
- | 1150 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
|
- | 1151 | }
|
|
- | 1152 | ||
- | 1153 | ||
1135 | }
|
1154 | }
|
1136 | 1155 | ||
1137 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1156 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1138 | 1157 | ||
1139 | mymodel->setTable(tr("ListOfClasses")); |
1158 | mymodel->setTable(tr("ListOfClasses")); |
1140 | mymodel->setSort(0, Qt::AscendingOrder); |
1159 | mymodel->setSort(0, Qt::AscendingOrder); |
1141 | mymodel->select(); |
1160 | mymodel->select(); |
1142 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1161 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1143 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1162 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1144 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1163 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1145 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1164 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1146 | ui->tableView->setModel(mymodel); |
1165 | ui->tableView->setModel(mymodel); |
1147 | ui->tableView->setAlternatingRowColors(true); |
1166 | ui->tableView->setAlternatingRowColors(true); |
1148 | ui->tableView->resizeColumnsToContents(); |
1167 | ui->tableView->resizeColumnsToContents(); |
1149 | ui->tableView->resizeRowsToContents(); |
1168 | ui->tableView->resizeRowsToContents(); |
1150 | ui->tableView->hideColumn(0); |
1169 | ui->tableView->hideColumn(0); |
1151 | ui->tableView->hideColumn(3); |
1170 | ui->tableView->hideColumn(3); |
1152 | ui->tableView->hideColumn(2); |
1171 | ui->tableView->hideColumn(2); |
1153 | CPictureDelegate *pictureDelegate; |
1172 | CPictureDelegate *pictureDelegate; |
1154 | pictureDelegate = new CPictureDelegate(this); |
1173 | pictureDelegate = new CPictureDelegate(this); |
1155 | pictureDelegate->setTableView(ui->tableView); |
1174 | pictureDelegate->setTableView(ui->tableView); |
1156 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1175 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1157 | ui->tableView->resizeColumnsToContents(); |
1176 | ui->tableView->resizeColumnsToContents(); |
1158 | ui->tableView->resizeRowsToContents(); |
1177 | ui->tableView->resizeRowsToContents(); |
1159 | /*
|
1178 | /*
|
1160 | for (int i=0; i < mymodel->rowCount(); i++){
|
1179 | for (int i=0; i < mymodel->rowCount(); i++){
|
1161 | ui->tableView->setRowHeight(i, 100);
|
1180 | ui->tableView->setRowHeight(i, 100);
|
1162 | }
|
1181 | }
|
1163 | */
|
1182 | */
|
1164 | 1183 | ||
1165 | }
|
1184 | }
|
1166 | 1185 | ||
1167 | 1186 | ||
1168 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1187 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1169 | 1188 | ||
1170 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1189 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1171 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1190 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1172 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1191 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1173 | ui->tableView_2->setModel(modelForDescription); |
1192 | ui->tableView_2->setModel(modelForDescription); |
1174 | ui->tableView_2->setAlternatingRowColors(true); |
1193 | ui->tableView_2->setAlternatingRowColors(true); |
1175 | ui->tableView_2->resizeColumnsToContents(); |
1194 | ui->tableView_2->resizeColumnsToContents(); |
1176 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1195 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1177 | }
|
1196 | }
|
1178 | 1197 | ||
1179 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1198 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1180 | 1199 | ||
1181 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1200 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1182 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1201 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1183 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1202 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1184 | ui->tableView_3->setModel(modelForPointers); |
1203 | ui->tableView_3->setModel(modelForPointers); |
1185 | delegateForDefaultValueColomn.getItems(); |
1204 | delegateForDefaultValueColomn.getItems(); |
1186 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1205 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1187 | 1206 | ||
1188 | // ui->tableView_3->resizeColumnsToContents();
|
1207 | // ui->tableView_3->resizeColumnsToContents();
|
1189 | 1208 | ||
1190 | }
|
1209 | }
|
1191 | 1210 |