Редакция 166 | Редакция 183 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 166 | Редакция 168 | ||
---|---|---|---|
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 | delete ui; |
288 | delete ui; |
289 | delete model; |
289 | delete model; |
290 | delete tableForInstance; |
290 | delete tableForInstance; |
291 | // delete field;
|
291 | // delete field;
|
292 | // delete settdialog;
|
292 | // delete settdialog;
|
293 | }
|
293 | }
|
294 | 294 | ||
295 | void ClassEditor::changeEvent(QEvent *e) |
295 | void ClassEditor::changeEvent(QEvent *e) |
296 | {
|
296 | {
|
297 | QMainWindow::changeEvent(e); |
297 | QMainWindow::changeEvent(e); |
298 | switch (e->type()) { |
298 | switch (e->type()) { |
299 | case QEvent::LanguageChange: |
299 | case QEvent::LanguageChange: |
300 | ui->retranslateUi(this); |
300 | ui->retranslateUi(this); |
301 | break; |
301 | break; |
302 | default: |
302 | default: |
303 | break; |
303 | break; |
304 | }
|
304 | }
|
305 | }
|
305 | }
|
306 | 306 | ||
307 | 307 | ||
308 | /*
|
308 | /*
|
309 | void ClassEditor::addNewClass(){
|
309 | void ClassEditor::addNewClass(){
|
310 | 310 | ||
311 | int row = model->rowCount();
|
311 | int row = model->rowCount();
|
312 | 312 | ||
313 | model->insertRows(row, 1);
|
313 | model->insertRows(row, 1);
|
314 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
314 | model->setData(model->index(row, 1), tr("New class")); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà"
|
315 | 315 | ||
316 | 316 | ||
317 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
317 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
318 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
318 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
319 | 319 | ||
320 | 320 | ||
321 | model->submitAll();
|
321 | model->submitAll();
|
322 | 322 | ||
323 | row = model->rowCount();
|
323 | row = model->rowCount();
|
324 | QString tmp_str;
|
324 | QString tmp_str;
|
325 | int i_tmp;
|
325 | int i_tmp;
|
326 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
326 | i_tmp = model->data(model->index(row-1, 0)).toInt();
|
327 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
327 | tmp_str = model->data(model->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà
|
328 | 328 | ||
329 | tmp_str.append(tr("_Inctance"));
|
329 | tmp_str.append(tr("_Inctance"));
|
330 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
330 | model->setData(model->index(row-1, 3), tmp_str ); // è çàíîñèì çíà÷åíèå â òàáëèöó
|
331 | 331 | ||
332 | model->submitAll();
|
332 | model->submitAll();
|
333 | mymodel->select();
|
333 | mymodel->select();
|
334 | 334 | ||
335 | 335 | ||
336 | }
|
336 | }
|
337 | */
|
337 | */
|
338 | 338 | ||
339 | void ClassEditor::addNewClass_new(){ |
339 | void ClassEditor::addNewClass_new(){ |
340 | 340 | ||
341 | int row = mymodel->rowCount(); |
341 | int row = mymodel->rowCount(); |
342 | 342 | ||
343 | mymodel->insertRows(row, 1); |
343 | mymodel->insertRows(row, 1); |
344 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
344 | mymodel->setData(mymodel->index(row, 1), QVariant(tr("New class")), Qt::EditRole); // ïðèñâàèâàåì íîâîå çíà÷åíèå ïîëþ "èìÿ êëàññà" |
345 | 345 | ||
346 | 346 | ||
347 | mymodel->submitAll(); |
347 | mymodel->submitAll(); |
348 | row = mymodel->rowCount(); |
348 | row = mymodel->rowCount(); |
349 | QString tmp_str1, sql_str;
|
349 | QString tmp_str1, sql_str;
|
350 | int i_tmp1; |
350 | int i_tmp1; |
351 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
351 | i_tmp1 = mymodel->data(mymodel->index(row-1, 0)).toInt(); |
352 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
352 | tmp_str1 = mymodel->data(mymodel->index(row-1, 0)).toString(); // ãåíåðèì èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ êëàññà |
353 | 353 | ||
354 | tmp_str1.append(tr("_Inctance")); |
354 | tmp_str1.append(tr("_Inctance")); |
355 | SqlTable* tbl; |
355 | SqlTable* tbl; |
356 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
356 | tbl = new SqlTable(tmp_str1); // ñîçäàåì õðàíèëèùå îáúåêòîâ |
357 | sql_str = tbl->sqlString(); |
357 | sql_str = tbl->sqlString(); |
358 | bool ok; |
358 | bool ok; |
359 | 359 | ||
360 | ok = sql.createTable(tbl); |
360 | ok = sql.createTable(tbl); |
361 | 361 | ||
362 | if (!ok) { |
362 | if (!ok) { |
363 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
363 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
364 | this, // Ðîäèòåëüñêèé âèäæåò. |
364 | this, // Ðîäèòåëüñêèé âèäæåò. |
365 | QObject::tr("Database Error"), // Çàãîëîâîê. |
365 | QObject::tr("Database Error"), // Çàãîëîâîê. |
366 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
366 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
367 | delete tbl; |
367 | delete tbl; |
368 | mymodel->removeRow(row-1); |
368 | mymodel->removeRow(row-1); |
369 | mymodel->submitAll(); |
369 | mymodel->submitAll(); |
370 | mymodel->select(); |
370 | mymodel->select(); |
371 | ui->tableView_2->resizeRowsToContents(); |
371 | ui->tableView_2->resizeRowsToContents(); |
372 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
372 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
373 | 373 | ||
374 | }
|
374 | }
|
375 | 375 | ||
376 | delete tbl; |
376 | delete tbl; |
377 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
377 | mymodel->setData(mymodel->index(row-1, 3), QVariant(tmp_str1), Qt::EditRole); // è çàíîñèì çíà÷åíèå â òàáëèöó |
378 | 378 | ||
379 | 379 | ||
380 | 380 | ||
381 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
381 | // model->setData(model->index(row, 1), tr("Âàñÿ Ïóïê èí"));
|
382 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
382 | // model->setData(model->index(row, 2) , tr("Ìóõîñðà íñê, Çàæîïèíñêèå âûñåëêè ä 1"));
|
383 | 383 | ||
384 | 384 | ||
385 | //mymodel->submitAll();
|
385 | //mymodel->submitAll();
|
386 | 386 | ||
387 | //row = mymodel->rowCount();
|
387 | //row = mymodel->rowCount();
|
388 | 388 | ||
389 | 389 | ||
390 | //mymodel->select();
|
390 | //mymodel->select();
|
391 | 391 | ||
392 | 392 | ||
393 | }
|
393 | }
|
394 | 394 | ||
395 | 395 | ||
396 | void ClassEditor::addNewField(){ |
396 | void ClassEditor::addNewField(){ |
397 | // QSqlRecord rec = mymodel->record(1);
|
397 | // QSqlRecord rec = mymodel->record(1);
|
398 | //bool ok;
|
398 | //bool ok;
|
399 | //ok = rec.isEmpty();
|
399 | //ok = rec.isEmpty();
|
400 | //QString currientClassID;
|
400 | //QString currientClassID;
|
401 | //currientClassID = rec.value(1).toString();
|
401 | //currientClassID = rec.value(1).toString();
|
402 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
402 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
403 | QString query_str = tr("ALTER TABLE "); |
403 | QString query_str = tr("ALTER TABLE "); |
404 | QString db_error;
|
404 | QString db_error;
|
405 | QSqlQuery q;
|
405 | QSqlQuery q;
|
406 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
406 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
407 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
407 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
408 | query_str.append( Inctance_str); |
408 | query_str.append( Inctance_str); |
409 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
409 | query_str.append(tr(" ADD COLUMN `New field` CHAR(30)")); |
410 | bool ok = q.prepare(query_str); |
410 | bool ok = q.prepare(query_str); |
411 | 411 | ||
412 | ok = q.exec(); |
412 | ok = q.exec(); |
413 | if (!ok) { |
413 | if (!ok) { |
414 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
414 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
415 | this, // Ðîäèòåëüñêèé âèäæåò. |
415 | this, // Ðîäèòåëüñêèé âèäæåò. |
416 | QObject::tr("Database Error"), // Çàãîëîâîê. |
416 | QObject::tr("Database Error"), // Çàãîëîâîê. |
417 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
417 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
418 | 418 | ||
419 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
419 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
420 | 420 | ||
421 | }
|
421 | }
|
422 | 422 | ||
423 | int row = modelForDescription->rowCount(); |
423 | int row = modelForDescription->rowCount(); |
424 | modelForDescription->insertRows(row, 1); |
424 | modelForDescription->insertRows(row, 1); |
425 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
425 | modelForDescription->onlySetData(modelForDescription->index(row, 5), QVariant(currClassID), Qt::EditRole); |
426 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
426 | modelForDescription->onlySetData(modelForDescription->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
427 | 427 | ||
428 | modelForDescription->submitAll(); |
428 | modelForDescription->submitAll(); |
429 | 429 | ||
430 | delete model; |
430 | delete model; |
431 | delete tableForInstance; |
431 | delete tableForInstance; |
432 | model = new QSqlTableModel(); |
432 | model = new QSqlTableModel(); |
433 | tableForInstance = new QTableView(); |
433 | tableForInstance = new QTableView(); |
434 | model->setTable(Inctance_str); |
434 | model->setTable(Inctance_str); |
435 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
435 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
436 | tableForInstance->setModel(model); |
436 | tableForInstance->setModel(model); |
437 | tableForInstance->setWindowTitle(Inctance_str); |
437 | tableForInstance->setWindowTitle(Inctance_str); |
438 | tableForInstance->show(); |
438 | tableForInstance->show(); |
439 | }
|
439 | }
|
440 | 440 | ||
441 | 441 | ||
442 | 442 | ||
443 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
443 | void ClassEditor::addNewPointer(){ //äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà |
444 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
444 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà îáúåêòîâ äëÿ âûáðàííîãî êëàññà |
445 | QString query_str = tr("ALTER TABLE "); |
445 | QString query_str = tr("ALTER TABLE "); |
446 | QString db_error;
|
446 | QString db_error;
|
447 | QSqlQuery q;
|
447 | QSqlQuery q;
|
448 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
448 | int currRow = ClassEditor::currIndexOfClassesTable.row(); // |
449 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
449 | Inctance_str = mymodel->data(mymodel->index(currRow, 3)).toString(); |
450 | query_str.append( Inctance_str); |
450 | query_str.append( Inctance_str); |
451 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
451 | query_str.append(tr(" ADD COLUMN `Ñlass-container ID` CHAR(30)")); |
452 | bool ok = q.prepare(query_str); |
452 | bool ok = q.prepare(query_str); |
453 | 453 | ||
454 | ok = q.exec(); |
454 | ok = q.exec(); |
455 | if (!ok) { |
455 | if (!ok) { |
456 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
456 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
457 | this, // Ðîäèòåëüñêèé âèäæåò. |
457 | this, // Ðîäèòåëüñêèé âèäæåò. |
458 | QObject::tr("Database Error"), // Çàãîëîâîê. |
458 | QObject::tr("Database Error"), // Çàãîëîâîê. |
459 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
459 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
460 | 460 | ||
461 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
461 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
462 | 462 | ||
463 | }
|
463 | }
|
464 | 464 | ||
465 | 465 | ||
466 | int row = ClassEditor::modelForPointers->rowCount(); |
466 | int row = ClassEditor::modelForPointers->rowCount(); |
467 | modelForPointers->insertRows(row, 1); |
467 | modelForPointers->insertRows(row, 1); |
468 | 468 | ||
469 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
469 | modelForPointers->onlySetData(modelForPointers->index(row, 1), QVariant(tr("Ñlass-container ID")), Qt::EditRole); |
470 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
470 | modelForPointers->onlySetData(modelForPointers->index(row, 3), QVariant(tr("pointer")), Qt::EditRole); |
471 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
471 | modelForPointers->onlySetData(modelForPointers->index(row, 5), QVariant(currClassID), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
472 | modelForPointers->onlySetData(modelForPointers->index(row, 4), QVariant(tr("NULL")), Qt::EditRole); |
473 | 473 | ||
474 | 474 | ||
475 | modelForPointers->submitAll(); |
475 | modelForPointers->submitAll(); |
476 | 476 | ||
477 | 477 | ||
478 | 478 | ||
479 | 479 | ||
480 | 480 | ||
481 | 481 | ||
482 | 482 | ||
483 | 483 | ||
484 | /*
|
484 | /*
|
485 | 485 | ||
486 | str_fltr = tr("ClassIdentifer = ");
|
486 | str_fltr = tr("ClassIdentifer = ");
|
487 | modelForPointers->setInctance(Inctance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
487 | modelForPointers->setInctance(Inctance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
|
488 | str_fltr.append(class_indx);
|
488 | str_fltr.append(class_indx);
|
489 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
489 | str_fltr.append(tr(" AND FieldType = \"pointer\""));
|
490 | // str_fltr.append( tr(" FieldType = pointer "));
|
490 | // str_fltr.append( tr(" FieldType = pointer "));
|
491 | 491 | ||
492 | 492 | ||
493 | 493 | ||
494 | modelForPointers->setFilter(str_fltr);
|
494 | modelForPointers->setFilter(str_fltr);
|
495 | modelForPointers->select();
|
495 | modelForPointers->select();
|
496 | ui->tableView_3->setModel(modelForPointers);
|
496 | ui->tableView_3->setModel(modelForPointers);
|
497 | ui->tableView_3->resizeColumnsToContents();
|
497 | ui->tableView_3->resizeColumnsToContents();
|
498 | */
|
498 | */
|
499 | 499 | ||
500 | 500 | ||
501 | 501 | ||
502 | 502 | ||
503 | // modelForPointers->select();
|
503 | // modelForPointers->select();
|
504 | 504 | ||
505 | 505 | ||
506 | 506 | ||
507 | 507 | ||
508 | 508 | ||
509 | ClassEditor::refreshInctance(); |
509 | ClassEditor::refreshInctance(); |
510 | 510 | ||
511 | 511 | ||
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 | void ClassEditor::on_pushButton_clicked(){ |
526 | void ClassEditor::on_pushButton_clicked(){ |
527 | //int i;
|
527 | //int i;
|
528 | //i++;
|
528 | //i++;
|
529 | /////ClassEditor::addNewClass();
|
529 | /////ClassEditor::addNewClass();
|
530 | ClassEditor::addNewClass_new(); |
530 | ClassEditor::addNewClass_new(); |
531 | mymodel->select(); |
531 | mymodel->select(); |
532 | ui->tableView->resizeColumnsToContents(); |
532 | ui->tableView->resizeColumnsToContents(); |
533 | ui->tableView->resizeRowsToContents(); |
533 | ui->tableView->resizeRowsToContents(); |
534 | 534 | ||
535 | //ui->tableView->setModel(mymodel);
|
535 | //ui->tableView->setModel(mymodel);
|
536 | 536 | ||
537 | }
|
537 | }
|
538 | 538 | ||
539 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
539 | void ClassEditor::on_tableView_clicked(const QModelIndex & index ){ |
540 | bool indexIsValid; |
540 | bool indexIsValid; |
541 | int i, row, column; |
541 | int i, row, column; |
542 | i++; |
542 | i++; |
543 | indexIsValid = index.isValid(); |
543 | indexIsValid = index.isValid(); |
544 | row = index.row(); |
544 | row = index.row(); |
545 | column = index.column(); |
545 | column = index.column(); |
546 | currIndexOfClassesTable = index; |
546 | currIndexOfClassesTable = index; |
547 | QModelIndex index_tmp, index_instance;
|
547 | QModelIndex index_tmp, index_instance;
|
548 | QString tmp_str, filter_str, instance_str;
|
548 | QString tmp_str, filter_str, instance_str;
|
549 | index_tmp = ui->tableView->model()->index(row, 0); |
549 | index_tmp = ui->tableView->model()->index(row, 0); |
550 | index_instance = ui->tableView->model()->index(row, 3); |
550 | index_instance = ui->tableView->model()->index(row, 3); |
551 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
551 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
552 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
552 | instance_str = ui->tableView->model()->data(index_instance).toString(); |
553 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
553 | modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà |
554 | modelForPointers->setInctance(instance_str); |
554 | modelForPointers->setInctance(instance_str); |
555 | 555 | ||
556 | delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ |
556 | delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ |
557 | 557 | ||
558 | // instance_str.append(tr("_inctance"));
|
558 | // instance_str.append(tr("_inctance"));
|
559 | /*
|
559 | /*
|
560 | Inctance_model.clear();
|
560 | Inctance_model.clear();
|
561 | Inctance_model.setTable(instance_str);
|
561 | Inctance_model.setTable(instance_str);
|
562 | Inctance_model.select();
|
562 | Inctance_model.select();
|
563 | tableForInstance_new.setModel(&Inctance_model);
|
563 | tableForInstance_new.setModel(&Inctance_model);
|
564 | tableForInstance_new.show();
|
564 | tableForInstance_new.show();
|
565 | */
|
565 | */
|
566 | // model->clear();
|
566 | // model->clear();
|
567 | tableForInstance->close(); |
567 | tableForInstance->close(); |
568 | delete model; |
568 | delete model; |
569 | delete tableForInstance; |
569 | delete tableForInstance; |
570 | model = new QSqlTableModel(); |
570 | model = new QSqlTableModel(); |
571 | tableForInstance = new QTableView(); |
571 | tableForInstance = new QTableView(); |
572 | model->setTable(instance_str); |
572 | model->setTable(instance_str); |
573 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
573 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
574 | tableForInstance->setModel(model); |
574 | tableForInstance->setModel(model); |
575 | 575 | ||
576 | model->select(); |
576 | model->select(); |
577 | tableForInstance->setWindowTitle(instance_str); |
577 | tableForInstance->setWindowTitle(instance_str); |
578 | tableForInstance->show(); |
578 | tableForInstance->show(); |
579 | 579 | ||
580 | // tableForInstance.setModel(model);
|
580 | // tableForInstance.setModel(model);
|
581 | tableForInstance->resizeColumnsToContents(); |
581 | tableForInstance->resizeColumnsToContents(); |
582 | 582 | ||
583 | currClassID = tmp_str; |
583 | currClassID = tmp_str; |
584 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
584 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
585 | filter_str = tr("ClassIdentifer = "); |
585 | filter_str = tr("ClassIdentifer = "); |
586 | filter_str.append(tmp_str); |
586 | filter_str.append(tmp_str); |
587 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
587 | filter_str.append(tr(" AND FieldType <> \"pointer\"")); |
588 | modelForDescription->setFilter(filter_str); |
588 | modelForDescription->setFilter(filter_str); |
589 | modelForDescription->select(); |
589 | modelForDescription->select(); |
590 | ui->tableView_2->resizeColumnsToContents(); |
590 | ui->tableView_2->resizeColumnsToContents(); |
591 | 591 | ||
592 | filter_str = tr("ClassIdentifer = "); |
592 | filter_str = tr("ClassIdentifer = "); |
593 | filter_str.append(tmp_str); |
593 | filter_str.append(tmp_str); |
594 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
594 | filter_str.append(tr(" AND FieldType = \"pointer\"")); |
595 | modelForPointers->setFilter(filter_str); |
595 | modelForPointers->setFilter(filter_str); |
596 | modelForPointers->select(); |
596 | modelForPointers->select(); |
597 | ui->tableView_3->resizeColumnsToContents(); |
597 | ui->tableView_3->resizeColumnsToContents(); |
598 | 598 | ||
599 | 599 | ||
600 | 600 | ||
601 | 601 | ||
602 | i++; |
602 | i++; |
603 | }
|
603 | }
|
604 | 604 | ||
605 | 605 | ||
606 | 606 | ||
607 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
607 | void ClassEditor::on_pushButton_2_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïðêè "Óäàëèòü êëàññ" |
608 | QModelIndex model_index;
|
608 | QModelIndex model_index;
|
609 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
609 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
610 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
610 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
611 | QList<int> selectedRows; |
611 | QList<int> selectedRows; |
612 | selectedRows.clear(); |
612 | selectedRows.clear(); |
613 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
613 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
614 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
614 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
615 | 615 | ||
616 | }
|
616 | }
|
617 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
617 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
618 | 618 | ||
619 | 619 | ||
620 | for (int m =0; m < selectedRows.size(); ++m){ |
620 | for (int m =0; m < selectedRows.size(); ++m){ |
621 | 621 | ||
622 | ClassEditor::removeClass(selectedRows.at(m)); |
622 | ClassEditor::removeClass(selectedRows.at(m)); |
623 | 623 | ||
624 | 624 | ||
625 | 625 | ||
626 | }
|
626 | }
|
627 | mymodel->submitAll(); |
627 | mymodel->submitAll(); |
628 | ClassEditor::modelForDescription->select(); |
628 | ClassEditor::modelForDescription->select(); |
629 | ui->tableView->resizeColumnsToContents(); |
629 | ui->tableView->resizeColumnsToContents(); |
630 | ui->tableView->resizeRowsToContents(); |
630 | ui->tableView->resizeRowsToContents(); |
631 | }
|
631 | }
|
632 | 632 | ||
633 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
633 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
634 | int i; |
634 | int i; |
635 | i++; |
635 | i++; |
636 | ClassEditor::addNewField(); |
636 | ClassEditor::addNewField(); |
637 | ClassEditor::modelForDescription->select(); |
637 | ClassEditor::modelForDescription->select(); |
638 | ui->tableView_2->resizeColumnsToContents(); |
638 | ui->tableView_2->resizeColumnsToContents(); |
639 | }
|
639 | }
|
640 | 640 | ||
641 | 641 | ||
642 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
642 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
643 | // int i;
|
643 | // int i;
|
644 | QModelIndex model_index;
|
644 | QModelIndex model_index;
|
645 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
645 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
646 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
646 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
647 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
647 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
648 | //model_index = mymodel->selec;
|
648 | //model_index = mymodel->selec;
|
649 | //modelList = ui->tableView->SelectItems;
|
649 | //modelList = ui->tableView->SelectItems;
|
650 | //i = indexes.size();
|
650 | //i = indexes.size();
|
651 | QList<int> selectedRows; |
651 | QList<int> selectedRows; |
652 | //indexes_fo_first_col.clear();
|
652 | //indexes_fo_first_col.clear();
|
653 | /*
|
653 | /*
|
654 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
654 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
655 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
655 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
656 | 656 | ||
657 | }
|
657 | }
|
658 | */
|
658 | */
|
659 | selectedRows.clear(); |
659 | selectedRows.clear(); |
660 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
660 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
661 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
661 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
662 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
662 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
663 | }
|
663 | }
|
664 | }
|
664 | }
|
665 | 665 | ||
666 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
666 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
667 | 667 | ||
668 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
668 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
669 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
669 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
670 | for (int m =0; m < selectedRows.size(); ++m){ |
670 | for (int m =0; m < selectedRows.size(); ++m){ |
671 | 671 | ||
672 | 672 | ||
673 | QString query_str;
|
673 | QString query_str;
|
674 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
674 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
675 | QSqlQuery q;
|
675 | QSqlQuery q;
|
676 | 676 | ||
677 | query_str.clear(); |
677 | query_str.clear(); |
678 | 678 | ||
679 | 679 | ||
680 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
680 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
681 | 681 | ||
682 | query_str.append(tr("ALTER TABLE ")); |
682 | query_str.append(tr("ALTER TABLE ")); |
683 | query_str.append(Inctance_str); |
683 | query_str.append(Inctance_str); |
684 | query_str.append(tr(" DROP COLUMN `")); |
684 | query_str.append(tr(" DROP COLUMN `")); |
685 | query_str.append(field_name_str); |
685 | query_str.append(field_name_str); |
686 | query_str.append(tr("`")); |
686 | query_str.append(tr("`")); |
687 | q.prepare(query_str); |
687 | q.prepare(query_str); |
688 | bool ok = q.exec(); |
688 | bool ok = q.exec(); |
689 | if (!ok) { |
689 | if (!ok) { |
690 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
690 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
691 | this, // Ðîäèòåëüñêèé âèäæåò. |
691 | this, // Ðîäèòåëüñêèé âèäæåò. |
692 | QObject::tr("Database Error"), // Çàãîëîâîê. |
692 | QObject::tr("Database Error"), // Çàãîëîâîê. |
693 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
693 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
694 | 694 | ||
695 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
695 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
696 | 696 | ||
697 | }
|
697 | }
|
698 | 698 | ||
699 | 699 | ||
700 | 700 | ||
701 | modelForDescription->removeRow(selectedRows.at(m)); |
701 | modelForDescription->removeRow(selectedRows.at(m)); |
702 | 702 | ||
703 | }
|
703 | }
|
704 | delete model; |
704 | delete model; |
705 | delete tableForInstance; |
705 | delete tableForInstance; |
706 | model = new QSqlTableModel(); |
706 | model = new QSqlTableModel(); |
707 | tableForInstance = new QTableView(); |
707 | tableForInstance = new QTableView(); |
708 | model->setTable(Inctance_str); |
708 | model->setTable(Inctance_str); |
709 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
709 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
710 | tableForInstance->setModel(model); |
710 | tableForInstance->setModel(model); |
711 | tableForInstance->setWindowTitle(Inctance_str); |
711 | tableForInstance->setWindowTitle(Inctance_str); |
712 | tableForInstance->show(); |
712 | tableForInstance->show(); |
713 | //i = selectedRows.size();
|
713 | //i = selectedRows.size();
|
714 | 714 | ||
715 | //if (i > 0) model_index = indexes.at(0);
|
715 | //if (i > 0) model_index = indexes.at(0);
|
716 | }
|
716 | }
|
717 | 717 | ||
718 | 718 | ||
719 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
719 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
720 | QModelIndex model_index;
|
720 | QModelIndex model_index;
|
721 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
721 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
722 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
722 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
723 | QList<int> selectedRows; |
723 | QList<int> selectedRows; |
724 | 724 | ||
725 | selectedRows.clear(); |
725 | selectedRows.clear(); |
726 | 726 | ||
727 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
727 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
728 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
728 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
729 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
729 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
730 | }
|
730 | }
|
731 | }
|
731 | }
|
732 | 732 | ||
733 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
733 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
734 | 734 | ||
735 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
735 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
736 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
736 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
737 | for (int m =0; m < selectedRows.size(); ++m){ |
737 | for (int m =0; m < selectedRows.size(); ++m){ |
738 | 738 | ||
739 | 739 | ||
740 | QString query_str;
|
740 | QString query_str;
|
741 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
741 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
742 | QSqlQuery q;
|
742 | QSqlQuery q;
|
743 | 743 | ||
744 | query_str.clear(); |
744 | query_str.clear(); |
745 | 745 | ||
746 | 746 | ||
747 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
747 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
748 | 748 | ||
749 | query_str.append(tr("ALTER TABLE ")); |
749 | query_str.append(tr("ALTER TABLE ")); |
750 | query_str.append(Inctance_str); |
750 | query_str.append(Inctance_str); |
751 | query_str.append(tr(" DROP COLUMN `")); |
751 | query_str.append(tr(" DROP COLUMN `")); |
752 | query_str.append(field_name_str); |
752 | query_str.append(field_name_str); |
753 | query_str.append(tr("`")); |
753 | query_str.append(tr("`")); |
754 | q.prepare(query_str); |
754 | q.prepare(query_str); |
755 | bool ok = q.exec(); |
755 | bool ok = q.exec(); |
756 | if (!ok) { |
756 | if (!ok) { |
757 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
757 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
758 | this, // Ðîäèòåëüñêèé âèäæåò. |
758 | this, // Ðîäèòåëüñêèé âèäæåò. |
759 | QObject::tr("Database Error"), // Çàãîëîâîê. |
759 | QObject::tr("Database Error"), // Çàãîëîâîê. |
760 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
760 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
761 | 761 | ||
762 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
762 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
763 | 763 | ||
764 | }
|
764 | }
|
765 | 765 | ||
766 | 766 | ||
767 | 767 | ||
768 | modelForPointers->removeRow(selectedRows.at(m)); |
768 | modelForPointers->removeRow(selectedRows.at(m)); |
769 | 769 | ||
770 | }
|
770 | }
|
771 | 771 | ||
772 | 772 | ||
773 | refreshInctance(); |
773 | refreshInctance(); |
774 | 774 | ||
775 | 775 | ||
776 | 776 | ||
777 | }
|
777 | }
|
778 | 778 | ||
779 | 779 | ||
780 | 780 | ||
781 | 781 | ||
782 | 782 | ||
783 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
783 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
784 | int row; |
784 | int row; |
785 | row = ClassEditor::modelForDescription->rowCount(); |
785 | row = ClassEditor::modelForDescription->rowCount(); |
786 | ClassEditor::modelForDescription->removeRows(0, row); |
786 | ClassEditor::modelForDescription->removeRows(0, row); |
787 | ClassEditor::modelForDescription->submitAll(); |
787 | ClassEditor::modelForDescription->submitAll(); |
788 | }
|
788 | }
|
789 | 789 | ||
790 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
790 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
791 | QString fileName;
|
791 | QString fileName;
|
792 | QPixmap pixmap;
|
792 | QPixmap pixmap;
|
793 | fileName = QFileDialog::getOpenFileName(this, |
793 | fileName = QFileDialog::getOpenFileName(this, |
794 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
794 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
795 | pixmap.load(fileName); |
795 | pixmap.load(fileName); |
796 | ui->label_4->setPixmap(pixmap); |
796 | ui->label_4->setPixmap(pixmap); |
797 | QImage currentImage = pixmap.toImage(); |
797 | QImage currentImage = pixmap.toImage(); |
798 | QByteArray bytes;
|
798 | QByteArray bytes;
|
799 | QBuffer buffer(&bytes); |
799 | QBuffer buffer(&bytes); |
800 | buffer.open(QIODevice::WriteOnly); |
800 | buffer.open(QIODevice::WriteOnly); |
801 | currentImage.save(&buffer, "PNG"); |
801 | currentImage.save(&buffer, "PNG"); |
802 | 802 | ||
803 | if (currIndexOfClassesTable.isValid()) { |
803 | if (currIndexOfClassesTable.isValid()) { |
804 | bool ok; |
804 | bool ok; |
805 | 805 | ||
806 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
806 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
807 | mymodel->submitAll(); |
807 | mymodel->submitAll(); |
808 | 808 | ||
- | 809 | ||
809 | }
|
810 | }
|
810 | 811 | ||
811 | 812 | ||
812 | }
|
813 | }
|
813 | 814 | ||
814 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
815 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
815 | 816 | ||
816 | int i; |
817 | int i; |
817 | i++; |
818 | i++; |
818 | ui->tableView->resizeColumnsToContents(); |
819 | ui->tableView->resizeColumnsToContents(); |
819 | - | ||
- | 820 | ui->tableView->resizeRowsToContents(); |
|
820 | 821 | ||
821 | 822 | ||
822 | 823 | ||
823 | 824 | ||
824 | }
|
825 | }
|
825 | 826 | ||
826 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
827 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
827 | ui->tableView_2->resizeColumnsToContents(); |
828 | ui->tableView_2->resizeColumnsToContents(); |
828 | 829 | ||
829 | /*
|
830 | /*
|
830 | QString instance_str;
|
831 | QString instance_str;
|
831 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
832 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
832 | tableForInstance->close();
|
833 | tableForInstance->close();
|
833 | delete model;
|
834 | delete model;
|
834 | delete tableForInstance;
|
835 | delete tableForInstance;
|
835 | model = new QSqlTableModel();
|
836 | model = new QSqlTableModel();
|
836 | tableForInstance = new QTableView();
|
837 | tableForInstance = new QTableView();
|
837 | model->setTable(instance_str);
|
838 | model->setTable(instance_str);
|
838 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
839 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
839 | tableForInstance->setModel(model);
|
840 | tableForInstance->setModel(model);
|
840 | 841 | ||
841 | model->select();
|
842 | model->select();
|
842 | tableForInstance->setWindowTitle(instance_str);
|
843 | tableForInstance->setWindowTitle(instance_str);
|
843 | tableForInstance->show();
|
844 | tableForInstance->show();
|
844 | */
|
845 | */
|
845 | }
|
846 | }
|
846 | 847 | ||
847 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
848 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
848 | if (is_checked) ui->tableView->showColumn(0); |
849 | if (is_checked) ui->tableView->showColumn(0); |
849 | else ui->tableView->hideColumn(0); |
850 | else ui->tableView->hideColumn(0); |
850 | ui->tableView->resizeColumnsToContents(); |
851 | ui->tableView->resizeColumnsToContents(); |
851 | }
|
852 | }
|
852 | 853 | ||
853 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
854 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
854 | if (is_checked) ui->tableView->showColumn(2); |
855 | if (is_checked) ui->tableView->showColumn(2); |
855 | else ui->tableView->hideColumn(2); |
856 | else ui->tableView->hideColumn(2); |
856 | ui->tableView->resizeColumnsToContents(); |
857 | ui->tableView->resizeColumnsToContents(); |
857 | }
|
858 | }
|
858 | 859 | ||
859 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
860 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
860 | if (is_checked) ui->tableView->showColumn(3); |
861 | if (is_checked) ui->tableView->showColumn(3); |
861 | else ui->tableView->hideColumn(3); |
862 | else ui->tableView->hideColumn(3); |
862 | ui->tableView->resizeColumnsToContents(); |
863 | ui->tableView->resizeColumnsToContents(); |
863 | }
|
864 | }
|
864 | 865 | ||
865 | 866 | ||
866 | 867 | ||
867 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
868 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
868 | int row; |
869 | int row; |
869 | row = ClassEditor::mymodel->rowCount(); |
870 | row = ClassEditor::mymodel->rowCount(); |
870 | for (int m=0; m < row; ++m){ |
871 | for (int m=0; m < row; ++m){ |
871 | ClassEditor::removeClass(0); |
872 | ClassEditor::removeClass(0); |
872 | //ClassEditor::mymodel->removeRows(0, row);
|
873 | //ClassEditor::mymodel->removeRows(0, row);
|
873 | }
|
874 | }
|
874 | ClassEditor::mymodel->submitAll(); |
875 | ClassEditor::mymodel->submitAll(); |
875 | ClassEditor::modelForDescription->select(); |
876 | ClassEditor::modelForDescription->select(); |
876 | }
|
877 | }
|
877 | 878 | ||
878 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
879 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
879 | QModelIndex index_tmp;
|
880 | QModelIndex index_tmp;
|
880 | QString tmp_str, filter_str;
|
881 | QString tmp_str, filter_str;
|
881 | index_tmp = ui->tableView->model()->index(class_row, 0); |
882 | index_tmp = ui->tableView->model()->index(class_row, 0); |
882 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
883 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
883 | currClassID = tmp_str; |
884 | currClassID = tmp_str; |
884 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
885 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
885 | filter_str = tr("ClassIdentifer = "); |
886 | filter_str = tr("ClassIdentifer = "); |
886 | filter_str.append(tmp_str); |
887 | filter_str.append(tmp_str); |
887 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
888 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
888 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
889 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
889 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
890 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
890 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
891 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
891 | ui->tableView->resizeColumnsToContents(); |
892 | ui->tableView->resizeColumnsToContents(); |
892 | ui->tableView_2->resizeColumnsToContents(); |
893 | ui->tableView_2->resizeColumnsToContents(); |
893 | 894 | ||
894 | }
|
895 | }
|
895 | 896 | ||
896 | 897 | ||
897 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
898 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
898 | ClassEditor::refreshInctance(); |
899 | ClassEditor::refreshInctance(); |
899 | }
|
900 | }
|
900 | 901 | ||
901 | 902 | ||
902 | 903 | ||
903 | 904 | ||
904 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
905 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
905 | 906 | ||
906 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
907 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
907 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
908 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
908 | delete model; |
909 | delete model; |
909 | delete tableForInstance; |
910 | delete tableForInstance; |
910 | model = new QSqlTableModel(); |
911 | model = new QSqlTableModel(); |
911 | tableForInstance = new QTableView(); |
912 | tableForInstance = new QTableView(); |
912 | model->setTable(Inctance_str); |
913 | model->setTable(Inctance_str); |
913 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
914 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
914 | model->select(); |
915 | model->select(); |
915 | tableForInstance->setModel(model); |
916 | tableForInstance->setModel(model); |
916 | tableForInstance->setWindowTitle(Inctance_str); |
917 | tableForInstance->setWindowTitle(Inctance_str); |
917 | tableForInstance->resizeRowsToContents(); |
918 | tableForInstance->resizeRowsToContents(); |
918 | tableForInstance->show(); |
919 | tableForInstance->show(); |
919 | 920 | ||
920 | }
|
921 | }
|
921 | 922 | ||
922 | 923 | ||
923 | 924 | ||
924 | 925 | ||
925 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
926 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
926 | ClassEditor::addNewPointer(); |
927 | ClassEditor::addNewPointer(); |
927 | ClassEditor::modelForPointers->select(); |
928 | ClassEditor::modelForPointers->select(); |
928 | ui->tableView_3->resizeColumnsToContents(); |
929 | ui->tableView_3->resizeColumnsToContents(); |
929 | 930 | ||
930 | }
|
931 | }
|
931 | 932 | ||
932 | 933 | ||
933 | // Ñ÷èòûâàåì íàñòðîéêè
|
934 | // Ñ÷èòûâàåì íàñòðîéêè
|
934 | 935 | ||
935 | void ClassEditor::readSettings() |
936 | void ClassEditor::readSettings() |
936 | {
|
937 | {
|
937 | QSettings settings("Trolltech", "Application Example"); |
938 | QSettings settings("Trolltech", "Application Example"); |
938 | baseName = settings.value("baseName", "an_db").toString(); |
939 | baseName = settings.value("baseName", "an_db").toString(); |
939 | userName = settings.value("userName", "an").toString(); |
940 | userName = settings.value("userName", "an").toString(); |
940 | password = settings.value("password", "393939").toString(); |
941 | password = settings.value("password", "393939").toString(); |
941 | tableName = settings.value("tableName", "inventar").toString(); |
942 | tableName = settings.value("tableName", "inventar").toString(); |
942 | hostName = settings.value("hostName", "server").toString(); |
943 | hostName = settings.value("hostName", "server").toString(); |
943 | // resize(size);
|
944 | // resize(size);
|
944 | // move(pos);tableName
|
945 | // move(pos);tableName
|
945 | }
|
946 | }
|
946 | 947 | ||
947 | 948 | ||
948 | void ClassEditor::writeSettings() |
949 | void ClassEditor::writeSettings() |
949 | {
|
950 | {
|
950 | QSettings settings("Trolltech", "Application Example"); |
951 | QSettings settings("Trolltech", "Application Example"); |
951 | settings.setValue("baseName", baseName); |
952 | settings.setValue("baseName", baseName); |
952 | settings.setValue("userName", userName); |
953 | settings.setValue("userName", userName); |
953 | settings.setValue("password", password); |
954 | settings.setValue("password", password); |
954 | settings.setValue("tableName", tableName); |
955 | settings.setValue("tableName", tableName); |
955 | settings.setValue("hostName", hostName); |
956 | settings.setValue("hostName", hostName); |
956 | }
|
957 | }
|
957 | 958 | ||
958 | 959 | ||
959 | void ClassEditor::applySetting() |
960 | void ClassEditor::applySetting() |
960 | {
|
961 | {
|
961 | bool ok; |
962 | bool ok; |
962 | baseName = setFrm.lineEdit->text(); |
963 | baseName = setFrm.lineEdit->text(); |
963 | userName = setFrm.lineEdit_2->text(); |
964 | userName = setFrm.lineEdit_2->text(); |
964 | password = setFrm.lineEdit_3->text(); |
965 | password = setFrm.lineEdit_3->text(); |
965 | // tableName = setFrm->lineEdit_4->text();
|
966 | // tableName = setFrm->lineEdit_4->text();
|
966 | hostName = setFrm.lineEdit_5->text(); |
967 | hostName = setFrm.lineEdit_5->text(); |
967 | writeSettings(); |
968 | writeSettings(); |
968 | 969 | ||
969 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
970 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
970 | 971 | ||
971 | sql.setDatabaseName(baseName); |
972 | sql.setDatabaseName(baseName); |
972 | // sql.setDatabaseName(tr("inventory"));
|
973 | // sql.setDatabaseName(tr("inventory"));
|
973 | 974 | ||
974 | // sql.setHostName(tr("localhost"));
|
975 | // sql.setHostName(tr("localhost"));
|
975 | sql.setHostName(hostName); |
976 | sql.setHostName(hostName); |
976 | 977 | ||
977 | // sql.setUserName(tr("an"));
|
978 | // sql.setUserName(tr("an"));
|
978 | 979 | ||
979 | sql.setUserName(userName); |
980 | sql.setUserName(userName); |
980 | 981 | ||
981 | // sql.setPassword(tr("393939"));
|
982 | // sql.setPassword(tr("393939"));
|
982 | 983 | ||
983 | sql.setPassword(password); |
984 | sql.setPassword(password); |
984 | 985 | ||
985 | ok = sql.connect(); |
986 | ok = sql.connect(); |
986 | if (!ok) { |
987 | if (!ok) { |
987 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
988 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
988 | this, // Ðîäèòåëüñêèé âèäæåò. |
989 | this, // Ðîäèòåëüñêèé âèäæåò. |
989 | QObject::tr("Database Error"), // Çàãîëîâîê. |
990 | QObject::tr("Database Error"), // Çàãîëîâîê. |
990 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
991 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
991 | 992 | ||
992 | }
|
993 | }
|
993 | else { |
994 | else { |
994 | 995 | ||
995 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
996 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
996 | this, // Ðîäèòåëüñêèé âèäæåò. |
997 | this, // Ðîäèòåëüñêèé âèäæåò. |
997 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
998 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
998 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
999 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
999 | 1000 | ||
1000 | 1001 | ||
1001 | 1002 | ||
1002 | 1003 | ||
1003 | 1004 | ||
1004 | }
|
1005 | }
|
1005 | 1006 | ||
1006 | 1007 | ||
1007 | mymodel->select(); |
1008 | mymodel->select(); |
1008 | model->select(); |
1009 | model->select(); |
1009 | modelForDescription->select(); |
1010 | modelForDescription->select(); |
1010 | 1011 | ||
1011 | //////////// ok=openDataBase();
|
1012 | //////////// ok=openDataBase();
|
1012 | //////////// if (!ok) return;
|
1013 | //////////// if (!ok) return;
|
1013 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1014 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1014 | 1015 | ||
1015 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1016 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1016 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1017 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1017 | //////////// initComboBox();
|
1018 | //////////// initComboBox();
|
1018 | // // // getDatabaseData();
|
1019 | // // // getDatabaseData();
|
1019 | // delete setFrm;
|
1020 | // delete setFrm;
|
1020 | setFrm.close(); |
1021 | setFrm.close(); |
1021 | }
|
1022 | }
|
1022 | 1023 | ||
1023 | void ClassEditor::getSetting() |
1024 | void ClassEditor::getSetting() |
1024 | {
|
1025 | {
|
1025 | // setFrm = new settingForm;
|
1026 | // setFrm = new settingForm;
|
1026 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1027 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1027 | setFrm.lineEdit->setText(baseName); |
1028 | setFrm.lineEdit->setText(baseName); |
1028 | setFrm.lineEdit_2->setText(userName); |
1029 | setFrm.lineEdit_2->setText(userName); |
1029 | setFrm.lineEdit_3->setText(password); |
1030 | setFrm.lineEdit_3->setText(password); |
1030 | // setFrm->lineEdit_4->setText(tableName);
|
1031 | // setFrm->lineEdit_4->setText(tableName);
|
1031 | setFrm.lineEdit_5->setText(hostName); |
1032 | setFrm.lineEdit_5->setText(hostName); |
1032 | setFrm.show(); |
1033 | setFrm.show(); |
1033 | 1034 | ||
1034 | 1035 | ||
1035 | 1036 | ||
1036 | }
|
1037 | }
|
1037 | 1038 | ||
1038 | 1039 | ||
1039 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1040 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1040 | 1041 | ||
1041 | sql.setDatabaseName(baseName); |
1042 | sql.setDatabaseName(baseName); |
1042 | sql.setHostName(hostName); |
1043 | sql.setHostName(hostName); |
1043 | sql.setUserName(userName); |
1044 | sql.setUserName(userName); |
1044 | sql.setPassword(password); |
1045 | sql.setPassword(password); |
1045 | 1046 | ||
1046 | bool ok; |
1047 | bool ok; |
1047 | ok = sql.connect(); |
1048 | ok = sql.connect(); |
1048 | if (!ok) { |
1049 | if (!ok) { |
1049 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1050 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1050 | this, // Ðîäèòåëüñêèé âèäæåò. |
1051 | this, // Ðîäèòåëüñêèé âèäæåò. |
1051 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1052 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1052 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1053 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1053 | 1054 | ||
1054 | }
|
1055 | }
|
1055 | else { |
1056 | else { |
1056 | 1057 | ||
1057 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1058 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1058 | this, // Ðîäèòåëüñêèé âèäæåò. |
1059 | this, // Ðîäèòåëüñêèé âèäæåò. |
1059 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1060 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1060 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1061 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1061 | 1062 | ||
1062 | 1063 | ||
1063 | 1064 | ||
1064 | 1065 | ||
1065 | 1066 | ||
1066 | }
|
1067 | }
|
1067 | 1068 | ||
1068 | }
|
1069 | }
|
1069 | 1070 | ||
1070 | 1071 | ||
1071 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1072 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1072 | 1073 | ||
1073 | bool ok; |
1074 | bool ok; |
1074 | ok = sql.createListOfClassesTable(); |
1075 | ok = sql.createListOfClassesTable(); |
1075 | 1076 | ||
1076 | if (!ok) { |
1077 | if (!ok) { |
1077 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1078 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1078 | this, // Ðîäèòåëüñêèé âèäæåò. |
1079 | this, // Ðîäèòåëüñêèé âèäæåò. |
1079 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1080 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1080 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1081 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1081 | 1082 | ||
1082 | }
|
1083 | }
|
1083 | else { |
1084 | else { |
1084 | 1085 | ||
1085 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1086 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1086 | this, // Ðîäèòåëüñêèé âèäæåò. |
1087 | this, // Ðîäèòåëüñêèé âèäæåò. |
1087 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1088 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1088 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1089 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1089 | }
|
1090 | }
|
1090 | 1091 | ||
1091 | 1092 | ||
1092 | 1093 | ||
1093 | 1094 | ||
1094 | ok = sql.createDescriptionOfClassesTable(); |
1095 | ok = sql.createDescriptionOfClassesTable(); |
1095 | 1096 | ||
1096 | if (!ok) { |
1097 | if (!ok) { |
1097 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1098 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1098 | this, // Ðîäèòåëüñêèé âèäæåò. |
1099 | this, // Ðîäèòåëüñêèé âèäæåò. |
1099 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1100 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1100 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1101 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1101 | 1102 | ||
1102 | }
|
1103 | }
|
1103 | else { |
1104 | else { |
1104 | 1105 | ||
1105 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1106 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1106 | this, // Ðîäèòåëüñêèé âèäæåò. |
1107 | this, // Ðîäèòåëüñêèé âèäæåò. |
1107 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1108 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1108 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1109 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1109 | }
|
1110 | }
|
1110 | 1111 | ||
1111 | 1112 | ||
1112 | ok = sql.createListModelsTable(); |
1113 | ok = sql.createListModelsTable(); |
1113 | 1114 | ||
1114 | if (!ok) { |
1115 | if (!ok) { |
1115 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1116 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1116 | this, // Ðîäèòåëüñêèé âèäæåò. |
1117 | this, // Ðîäèòåëüñêèé âèäæåò. |
1117 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1118 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1118 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1119 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1119 | 1120 | ||
1120 | }
|
1121 | }
|
1121 | else { |
1122 | else { |
1122 | 1123 | ||
1123 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1124 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1124 | this, // Ðîäèòåëüñêèé âèäæåò. |
1125 | this, // Ðîäèòåëüñêèé âèäæåò. |
1125 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1126 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1126 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1127 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1127 | }
|
1128 | }
|
1128 | 1129 | ||
1129 | 1130 | ||
1130 | 1131 | ||
1131 | 1132 | ||
1132 | }
|
1133 | }
|
1133 | 1134 | ||
1134 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1135 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1135 | 1136 | ||
1136 | mymodel->setTable(tr("ListOfClasses")); |
1137 | mymodel->setTable(tr("ListOfClasses")); |
1137 | mymodel->setSort(0, Qt::AscendingOrder); |
1138 | mymodel->setSort(0, Qt::AscendingOrder); |
1138 | mymodel->select(); |
1139 | mymodel->select(); |
1139 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1140 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1140 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1141 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1141 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1142 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1142 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1143 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1143 | ui->tableView->setModel(mymodel); |
1144 | ui->tableView->setModel(mymodel); |
1144 | ui->tableView->setAlternatingRowColors(true); |
1145 | ui->tableView->setAlternatingRowColors(true); |
1145 | ui->tableView->resizeColumnsToContents(); |
1146 | ui->tableView->resizeColumnsToContents(); |
1146 | ui->tableView->resizeRowsToContents(); |
1147 | ui->tableView->resizeRowsToContents(); |
1147 | ui->tableView->hideColumn(0); |
1148 | ui->tableView->hideColumn(0); |
1148 | ui->tableView->hideColumn(3); |
1149 | ui->tableView->hideColumn(3); |
1149 | ui->tableView->hideColumn(2); |
1150 | ui->tableView->hideColumn(2); |
1150 | CPictureDelegate *pictureDelegate; |
1151 | CPictureDelegate *pictureDelegate; |
1151 | pictureDelegate = new CPictureDelegate(this); |
1152 | pictureDelegate = new CPictureDelegate(this); |
1152 | pictureDelegate->setTableView(ui->tableView); |
1153 | pictureDelegate->setTableView(ui->tableView); |
1153 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1154 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1154 | - | ||
- | 1155 | ui->tableView->resizeColumnsToContents(); |
|
- | 1156 | ui->tableView->resizeRowsToContents(); |
|
1155 | /*
|
1157 | /*
|
1156 | for (int i=0; i < mymodel->rowCount(); i++){
|
1158 | for (int i=0; i < mymodel->rowCount(); i++){
|
1157 | ui->tableView->setRowHeight(i, 100);
|
1159 | ui->tableView->setRowHeight(i, 100);
|
1158 | }
|
1160 | }
|
1159 | */
|
1161 | */
|
1160 | 1162 | ||
1161 | }
|
1163 | }
|
1162 | 1164 | ||
1163 | 1165 | ||
1164 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1166 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1165 | 1167 | ||
1166 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1168 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1167 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1169 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1168 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1170 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1169 | ui->tableView_2->setModel(modelForDescription); |
1171 | ui->tableView_2->setModel(modelForDescription); |
1170 | ui->tableView_2->setAlternatingRowColors(true); |
1172 | ui->tableView_2->setAlternatingRowColors(true); |
1171 | ui->tableView_2->resizeColumnsToContents(); |
1173 | ui->tableView_2->resizeColumnsToContents(); |
1172 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1174 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1173 | }
|
1175 | }
|
1174 | 1176 | ||
1175 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1177 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1176 | 1178 | ||
1177 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1179 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1178 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1180 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1179 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1181 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1180 | ui->tableView_3->setModel(modelForPointers); |
1182 | ui->tableView_3->setModel(modelForPointers); |
1181 | delegateForDefaultValueColomn.getItems(); |
1183 | delegateForDefaultValueColomn.getItems(); |
1182 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1184 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1183 | 1185 | ||
1184 | // ui->tableView_3->resizeColumnsToContents();
|
1186 | // ui->tableView_3->resizeColumnsToContents();
|
1185 | 1187 | ||
1186 | }
|
1188 | }
|
1187 | 1189 |