Редакция 210 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 210 | Редакция 232 | ||
---|---|---|---|
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 | ||
- | 636 | ||
- | 637 | ||
- | 638 | ||
- | 639 | ||
- | 640 | ||
635 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
641 | void ClassEditor::on_pushButton_3_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâîå ïîëå" |
636 | int i; |
642 | int i; |
637 | i++; |
643 | i++; |
638 | ClassEditor::addNewField(); |
644 | ClassEditor::addNewField(); |
639 | ClassEditor::modelForDescription->select(); |
645 | ClassEditor::modelForDescription->select(); |
640 | ui->tableView_2->resizeColumnsToContents(); |
646 | ui->tableView_2->resizeColumnsToContents(); |
641 | }
|
647 | }
|
642 | 648 | ||
643 | 649 | ||
644 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
650 | void ClassEditor::on_pushButton_4_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ïîëå" |
645 | // int i;
|
651 | // int i;
|
646 | QModelIndex model_index;
|
652 | QModelIndex model_index;
|
647 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
653 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
648 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
654 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
649 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
655 | //QModelIndexList indexes_fo_first_col; // èíäåêñû äëÿ ïåðâîãî ñòîëáöà (èìåíà êëàññîâ)
|
650 | //model_index = mymodel->selec;
|
656 | //model_index = mymodel->selec;
|
651 | //modelList = ui->tableView->SelectItems;
|
657 | //modelList = ui->tableView->SelectItems;
|
652 | //i = indexes.size();
|
658 | //i = indexes.size();
|
653 | QList<int> selectedRows; |
659 | QList<int> selectedRows; |
654 | //indexes_fo_first_col.clear();
|
660 | //indexes_fo_first_col.clear();
|
655 | /*
|
661 | /*
|
656 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
662 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê
|
657 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
663 | if (!indexes_fo_first_col.contains(model_index) && (model_index.column()==1)) indexes_fo_first_col.append(model_index); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå
|
658 | 664 | ||
659 | }
|
665 | }
|
660 | */
|
666 | */
|
661 | selectedRows.clear(); |
667 | selectedRows.clear(); |
662 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
668 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
663 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
669 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
664 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
670 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
665 | }
|
671 | }
|
666 | }
|
672 | }
|
667 | 673 | ||
668 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
674 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
669 | 675 | ||
670 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
676 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
671 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
677 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
672 | for (int m =0; m < selectedRows.size(); ++m){ |
678 | for (int m =0; m < selectedRows.size(); ++m){ |
673 | 679 | ||
674 | 680 | ||
675 | QString query_str;
|
681 | QString query_str;
|
676 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
682 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
677 | QSqlQuery q;
|
683 | QSqlQuery q;
|
678 | 684 | ||
679 | query_str.clear(); |
685 | query_str.clear(); |
680 | 686 | ||
681 | 687 | ||
682 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
688 | field_name_str = modelForDescription->data(modelForDescription->index(selectedRows.at(m), 1)).toString(); |
683 | 689 | ||
684 | query_str.append(tr("ALTER TABLE ")); |
690 | query_str.append(tr("ALTER TABLE ")); |
685 | query_str.append(Inctance_str); |
691 | query_str.append(Inctance_str); |
686 | query_str.append(tr(" DROP COLUMN `")); |
692 | query_str.append(tr(" DROP COLUMN `")); |
687 | query_str.append(field_name_str); |
693 | query_str.append(field_name_str); |
688 | query_str.append(tr("`")); |
694 | query_str.append(tr("`")); |
689 | q.prepare(query_str); |
695 | q.prepare(query_str); |
690 | bool ok = q.exec(); |
696 | bool ok = q.exec(); |
691 | if (!ok) { |
697 | if (!ok) { |
692 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
698 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
693 | this, // Ðîäèòåëüñêèé âèäæåò. |
699 | this, // Ðîäèòåëüñêèé âèäæåò. |
694 | QObject::tr("Database Error"), // Çàãîëîâîê. |
700 | QObject::tr("Database Error"), // Çàãîëîâîê. |
695 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
701 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
696 | 702 | ||
697 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
703 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
698 | 704 | ||
699 | }
|
705 | }
|
700 | 706 | ||
701 | 707 | ||
702 | 708 | ||
703 | modelForDescription->removeRow(selectedRows.at(m)); |
709 | modelForDescription->removeRow(selectedRows.at(m)); |
704 | 710 | ||
705 | }
|
711 | }
|
706 | delete model; |
712 | delete model; |
707 | delete tableForInstance; |
713 | delete tableForInstance; |
708 | model = new QSqlTableModel(); |
714 | model = new QSqlTableModel(); |
709 | tableForInstance = new QTableView(); |
715 | tableForInstance = new QTableView(); |
710 | model->setTable(Inctance_str); |
716 | model->setTable(Inctance_str); |
711 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
717 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
712 | tableForInstance->setModel(model); |
718 | tableForInstance->setModel(model); |
713 | tableForInstance->setWindowTitle(Inctance_str); |
719 | tableForInstance->setWindowTitle(Inctance_str); |
714 | tableForInstance->show(); |
720 | tableForInstance->show(); |
715 | //i = selectedRows.size();
|
721 | //i = selectedRows.size();
|
716 | 722 | ||
717 | //if (i > 0) model_index = indexes.at(0);
|
723 | //if (i > 0) model_index = indexes.at(0);
|
718 | }
|
724 | }
|
719 | 725 | ||
720 | 726 | ||
721 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
727 | void ClassEditor::on_action_removeSelectedPointers(){ // óäàëèòü âûäåëåííûå óêàçàòåëè |
722 | QModelIndex model_index;
|
728 | QModelIndex model_index;
|
723 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
729 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
724 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
730 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
725 | QList<int> selectedRows; |
731 | QList<int> selectedRows; |
726 | 732 | ||
727 | selectedRows.clear(); |
733 | selectedRows.clear(); |
728 | 734 | ||
729 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
735 | foreach (model_index, indexes){ // ñïèñîê âñåõ âûäåëåííûõ ñòðîê |
730 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
736 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) { |
731 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
737 | selectedRows.append(model_index.row()); // îñòàâëÿåì â ñïèñêå òîëüêî âûáðàííûå â ïåðâîé êîëîíêå |
732 | }
|
738 | }
|
733 | }
|
739 | }
|
734 | 740 | ||
735 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
741 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // ñîðòèðóåì â îáðàòíîì ïîðÿäêå |
736 | 742 | ||
737 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
743 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
738 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
744 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
739 | for (int m =0; m < selectedRows.size(); ++m){ |
745 | for (int m =0; m < selectedRows.size(); ++m){ |
740 | 746 | ||
741 | 747 | ||
742 | QString query_str;
|
748 | QString query_str;
|
743 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
749 | QString field_name_str; // èìÿ óäàëÿåìîãî ïîëÿ |
744 | QSqlQuery q;
|
750 | QSqlQuery q;
|
745 | 751 | ||
746 | query_str.clear(); |
752 | query_str.clear(); |
747 | 753 | ||
748 | 754 | ||
749 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
755 | field_name_str = modelForPointers->data(modelForPointers->index(selectedRows.at(m), 1)).toString(); |
750 | 756 | ||
751 | query_str.append(tr("ALTER TABLE ")); |
757 | query_str.append(tr("ALTER TABLE ")); |
752 | query_str.append(Inctance_str); |
758 | query_str.append(Inctance_str); |
753 | query_str.append(tr(" DROP COLUMN `")); |
759 | query_str.append(tr(" DROP COLUMN `")); |
754 | query_str.append(field_name_str); |
760 | query_str.append(field_name_str); |
755 | query_str.append(tr("`")); |
761 | query_str.append(tr("`")); |
756 | q.prepare(query_str); |
762 | q.prepare(query_str); |
757 | bool ok = q.exec(); |
763 | bool ok = q.exec(); |
758 | if (!ok) { |
764 | if (!ok) { |
759 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
765 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
760 | this, // Ðîäèòåëüñêèé âèäæåò. |
766 | this, // Ðîäèòåëüñêèé âèäæåò. |
761 | QObject::tr("Database Error"), // Çàãîëîâîê. |
767 | QObject::tr("Database Error"), // Çàãîëîâîê. |
762 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
768 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
763 | 769 | ||
764 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
770 | return; // âûõîäèì íå ïðèìåíÿÿ èçìåíåíèé |
765 | 771 | ||
766 | }
|
772 | }
|
767 | 773 | ||
768 | 774 | ||
769 | 775 | ||
770 | modelForPointers->removeRow(selectedRows.at(m)); |
776 | modelForPointers->removeRow(selectedRows.at(m)); |
771 | 777 | ||
772 | }
|
778 | }
|
773 | 779 | ||
774 | 780 | ||
775 | refreshInctance(); |
781 | refreshInctance(); |
776 | 782 | ||
777 | 783 | ||
778 | 784 | ||
779 | }
|
785 | }
|
780 | 786 | ||
781 | 787 | ||
782 | 788 | ||
783 | 789 | ||
784 | 790 | ||
785 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
791 | void ClassEditor::on_pushButton_5_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
786 | int row; |
792 | int row; |
787 | row = ClassEditor::modelForDescription->rowCount(); |
793 | row = ClassEditor::modelForDescription->rowCount(); |
788 | ClassEditor::modelForDescription->removeRows(0, row); |
794 | ClassEditor::modelForDescription->removeRows(0, row); |
789 | ClassEditor::modelForDescription->submitAll(); |
795 | ClassEditor::modelForDescription->submitAll(); |
790 | }
|
796 | }
|
791 | 797 | ||
792 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
798 | void ClassEditor::on_pushButton_6_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü âñå ïîëÿ" |
793 | QString fileName;
|
799 | QString fileName;
|
794 | QPixmap pixmap;
|
800 | QPixmap pixmap;
|
795 | fileName = QFileDialog::getOpenFileName(this, |
801 | fileName = QFileDialog::getOpenFileName(this, |
796 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
802 | tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); |
797 | pixmap.load(fileName); |
803 | pixmap.load(fileName); |
798 | ui->label_4->setPixmap(pixmap); |
804 | ui->label_4->setPixmap(pixmap); |
799 | QImage currentImage = pixmap.toImage(); |
805 | QImage currentImage = pixmap.toImage(); |
800 | QByteArray bytes;
|
806 | QByteArray bytes;
|
801 | QBuffer buffer(&bytes); |
807 | QBuffer buffer(&bytes); |
802 | buffer.open(QIODevice::WriteOnly); |
808 | buffer.open(QIODevice::WriteOnly); |
803 | currentImage.save(&buffer, "PNG"); |
809 | currentImage.save(&buffer, "PNG"); |
804 | 810 | ||
805 | if (currIndexOfClassesTable.isValid()) { |
811 | if (currIndexOfClassesTable.isValid()) { |
806 | bool ok; |
812 | bool ok; |
807 | 813 | ||
808 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
814 | ok = mymodel->setData(mymodel->index(currIndexOfClassesTable.row(), 5), QVariant (bytes), Qt::EditRole); |
809 | mymodel->submitAll(); |
815 | mymodel->submitAll(); |
810 | 816 | ||
811 | 817 | ||
812 | }
|
818 | }
|
813 | 819 | ||
814 | 820 | ||
815 | }
|
821 | }
|
816 | 822 | ||
817 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
823 | void ClassEditor::on_myModel_dataChanged( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
818 | 824 | ||
819 | int i; |
825 | int i; |
820 | i++; |
826 | i++; |
821 | ui->tableView->resizeColumnsToContents(); |
827 | ui->tableView->resizeColumnsToContents(); |
822 | ui->tableView->resizeRowsToContents(); |
828 | ui->tableView->resizeRowsToContents(); |
823 | 829 | ||
824 | 830 | ||
825 | 831 | ||
826 | 832 | ||
827 | }
|
833 | }
|
828 | 834 | ||
829 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
835 | void ClassEditor::on_modelForDescription_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ |
830 | ui->tableView_2->resizeColumnsToContents(); |
836 | ui->tableView_2->resizeColumnsToContents(); |
831 | 837 | ||
832 | /*
|
838 | /*
|
833 | QString instance_str;
|
839 | QString instance_str;
|
834 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
840 | instance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString();
|
835 | tableForInstance->close();
|
841 | tableForInstance->close();
|
836 | delete model;
|
842 | delete model;
|
837 | delete tableForInstance;
|
843 | delete tableForInstance;
|
838 | model = new QSqlTableModel();
|
844 | model = new QSqlTableModel();
|
839 | tableForInstance = new QTableView();
|
845 | tableForInstance = new QTableView();
|
840 | model->setTable(instance_str);
|
846 | model->setTable(instance_str);
|
841 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
847 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
842 | tableForInstance->setModel(model);
|
848 | tableForInstance->setModel(model);
|
843 | 849 | ||
844 | model->select();
|
850 | model->select();
|
845 | tableForInstance->setWindowTitle(instance_str);
|
851 | tableForInstance->setWindowTitle(instance_str);
|
846 | tableForInstance->show();
|
852 | tableForInstance->show();
|
847 | */
|
853 | */
|
848 | }
|
854 | }
|
849 | 855 | ||
850 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
856 | void ClassEditor::on_action_ID_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ID" |
851 | if (is_checked) ui->tableView->showColumn(0); |
857 | if (is_checked) ui->tableView->showColumn(0); |
852 | else ui->tableView->hideColumn(0); |
858 | else ui->tableView->hideColumn(0); |
853 | ui->tableView->resizeColumnsToContents(); |
859 | ui->tableView->resizeColumnsToContents(); |
854 | }
|
860 | }
|
855 | 861 | ||
856 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
862 | void ClassEditor::on_action_showAlias_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü ïñåâäîíèì" |
857 | if (is_checked) ui->tableView->showColumn(2); |
863 | if (is_checked) ui->tableView->showColumn(2); |
858 | else ui->tableView->hideColumn(2); |
864 | else ui->tableView->hideColumn(2); |
859 | ui->tableView->resizeColumnsToContents(); |
865 | ui->tableView->resizeColumnsToContents(); |
860 | }
|
866 | }
|
861 | 867 | ||
862 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
868 | void ClassEditor::on_action_showInstance_triggered(bool is_checked){ // îáðàáàòûâàåì âûáîð â ìåíþ "Ïîêàçûâàòü õðàíèëèùà îáúåêòîâ" |
863 | if (is_checked) ui->tableView->showColumn(3); |
869 | if (is_checked) ui->tableView->showColumn(3); |
864 | else ui->tableView->hideColumn(3); |
870 | else ui->tableView->hideColumn(3); |
865 | ui->tableView->resizeColumnsToContents(); |
871 | ui->tableView->resizeColumnsToContents(); |
866 | }
|
872 | }
|
867 | 873 | ||
868 | 874 | ||
869 | 875 | ||
870 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
876 | void ClassEditor::on_action_removeAllClasses(){ // îáðàáàòûâàåì âûáîð â ìåíþ "Óäàëèòü âñå êëàññû" |
871 | int row; |
877 | int row; |
872 | row = ClassEditor::mymodel->rowCount(); |
878 | row = ClassEditor::mymodel->rowCount(); |
873 | for (int m=0; m < row; ++m){ |
879 | for (int m=0; m < row; ++m){ |
874 | ClassEditor::removeClass(0); |
880 | ClassEditor::removeClass(0); |
875 | //ClassEditor::mymodel->removeRows(0, row);
|
881 | //ClassEditor::mymodel->removeRows(0, row);
|
876 | }
|
882 | }
|
877 | ClassEditor::mymodel->submitAll(); |
883 | ClassEditor::mymodel->submitAll(); |
878 | ClassEditor::modelForDescription->select(); |
884 | ClassEditor::modelForDescription->select(); |
879 | }
|
885 | }
|
880 | 886 | ||
881 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
887 | void ClassEditor::removeClass(int class_row){ // ôóíêöèÿ óäàëÿåò êëàññ, íàõîäÿùèéñÿ â ñòðîêå ñ íîìåðîì class_row |
882 | QModelIndex index_tmp;
|
888 | QModelIndex index_tmp;
|
883 | QString tmp_str, filter_str;
|
889 | QString tmp_str, filter_str;
|
- | 890 | QString class_inctance;
|
|
884 | index_tmp = ui->tableView->model()->index(class_row, 0); |
891 | index_tmp = ui->tableView->model()->index(class_row, 0); |
885 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
892 | tmp_str = ui->tableView->model()->data(index_tmp).toString(); |
886 | currClassID = tmp_str; |
893 | currClassID = tmp_str; |
- | 894 | index_tmp = ui->tableView->model()->index(class_row, 3); |
|
- | 895 | class_inctance = ui->tableView->model()->data(index_tmp).toString(); |
|
- | 896 | ||
- | 897 | QSqlQuery q;
|
|
- | 898 | QString sql_str;
|
|
- | 899 | bool ok; |
|
- | 900 | sql_str = tr("drop table `"); |
|
- | 901 | sql_str.append(class_inctance); |
|
- | 902 | sql_str.append(tr("`")); |
|
- | 903 | ok = q.prepare(sql_str); |
|
- | 904 | ||
- | 905 | ||
- | 906 | ||
- | 907 | ||
- | 908 | ||
887 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
909 | // ui->label->setText(QVariant(currIndexOfClassesTable.row()).toString());
|
888 | filter_str = tr("ClassIdentifer = "); |
910 | filter_str = tr("ClassIdentifer = "); |
889 | filter_str.append(tmp_str); |
911 | filter_str.append(tmp_str); |
890 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
912 | modelForDescription->setFilter(filter_str); // îáíîâëÿåì òàáëèöó ïîëåé |
891 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
913 | ClassEditor::on_pushButton_5_clicked(); // ñíà÷àëà óäàëèì âñå ïîëÿ êëàññà |
892 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
914 | mymodel->removeRow(class_row); // òåïåðü óäàëÿåì ñàì êëàññ |
893 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
915 | mymodel->submitAll(); // ôèêñèðóåì èçìåíåíèÿ |
- | 916 | ||
- | 917 | ok = q.exec();// óäàëÿåì õðàíèëèùå îáúåêòîâ êëàññà |
|
- | 918 | if (!ok) { |
|
- | 919 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
|
- | 920 | this, // Ðîäèòåëüñêèé âèäæåò. |
|
- | 921 | QObject::tr("Database Error"), // Çàãîëîâîê. |
|
- | 922 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
|
- | 923 | ||
- | 924 | ||
- | 925 | }
|
|
- | 926 | ||
894 | ui->tableView->resizeColumnsToContents(); |
927 | ui->tableView->resizeColumnsToContents(); |
895 | ui->tableView_2->resizeColumnsToContents(); |
928 | ui->tableView_2->resizeColumnsToContents(); |
896 | 929 | ||
897 | }
|
930 | }
|
898 | 931 | ||
899 | 932 | ||
900 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
933 | void ClassEditor::on_field_changed(){ // ïîìåíÿëîñü èìÿ ïîëÿ |
901 | ClassEditor::refreshInctance(); |
934 | ClassEditor::refreshInctance(); |
902 | }
|
935 | }
|
903 | 936 | ||
904 | 937 | ||
905 | 938 | ||
906 | 939 | ||
907 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
940 | void ClassEditor::refreshInctance(){ // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà |
908 | 941 | ||
909 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
942 | QString Inctance_str; // èìÿ òàáëèöû-õðàíèëèùà |
910 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
943 | Inctance_str = mymodel->data(mymodel->index(ClassEditor::currIndexOfClassesTable.row(), 3)).toString(); |
911 | delete model; |
944 | delete model; |
912 | delete tableForInstance; |
945 | delete tableForInstance; |
913 | model = new QSqlTableModel(); |
946 | model = new QSqlTableModel(); |
914 | tableForInstance = new QTableView(); |
947 | tableForInstance = new QTableView(); |
915 | model->setTable(Inctance_str); |
948 | model->setTable(Inctance_str); |
916 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
949 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
917 | model->select(); |
950 | model->select(); |
918 | tableForInstance->setModel(model); |
951 | tableForInstance->setModel(model); |
919 | tableForInstance->setWindowTitle(Inctance_str); |
952 | tableForInstance->setWindowTitle(Inctance_str); |
920 | tableForInstance->resizeRowsToContents(); |
953 | tableForInstance->resizeRowsToContents(); |
921 | tableForInstance->show(); |
954 | tableForInstance->show(); |
922 | 955 | ||
923 | }
|
956 | }
|
924 | 957 | ||
925 | 958 | ||
926 | 959 | ||
927 | 960 | ||
928 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
961 | void ClassEditor::on_action_newPointer(){ // äîáàâëÿåì íîâîå ïîëå äëÿ óêàçàòåëåé íà îáúåêòû êëàññà-êîíòåéíåðà |
929 | ClassEditor::addNewPointer(); |
962 | ClassEditor::addNewPointer(); |
930 | ClassEditor::modelForPointers->select(); |
963 | ClassEditor::modelForPointers->select(); |
931 | ui->tableView_3->resizeColumnsToContents(); |
964 | ui->tableView_3->resizeColumnsToContents(); |
932 | 965 | ||
933 | }
|
966 | }
|
934 | 967 | ||
935 | 968 | ||
936 | // Ñ÷èòûâàåì íàñòðîéêè
|
969 | // Ñ÷èòûâàåì íàñòðîéêè
|
937 | 970 | ||
938 | void ClassEditor::readSettings() |
971 | void ClassEditor::readSettings() |
939 | {
|
972 | {
|
940 | QSettings settings("Trolltech", "Application Example"); |
973 | QSettings settings("Trolltech", "Application Example"); |
941 | baseName = settings.value("baseName", "an_db").toString(); |
974 | baseName = settings.value("baseName", "an_db").toString(); |
942 | userName = settings.value("userName", "an").toString(); |
975 | userName = settings.value("userName", "an").toString(); |
943 | password = settings.value("password", "393939").toString(); |
976 | password = settings.value("password", "393939").toString(); |
944 | tableName = settings.value("tableName", "inventar").toString(); |
977 | tableName = settings.value("tableName", "inventar").toString(); |
945 | hostName = settings.value("hostName", "server").toString(); |
978 | hostName = settings.value("hostName", "server").toString(); |
946 | // resize(size);
|
979 | // resize(size);
|
947 | // move(pos);tableName
|
980 | // move(pos);tableName
|
948 | }
|
981 | }
|
949 | 982 | ||
950 | 983 | ||
951 | void ClassEditor::writeSettings() |
984 | void ClassEditor::writeSettings() |
952 | {
|
985 | {
|
953 | QSettings settings("Trolltech", "Application Example"); |
986 | QSettings settings("Trolltech", "Application Example"); |
954 | settings.setValue("baseName", baseName); |
987 | settings.setValue("baseName", baseName); |
955 | settings.setValue("userName", userName); |
988 | settings.setValue("userName", userName); |
956 | settings.setValue("password", password); |
989 | settings.setValue("password", password); |
957 | settings.setValue("tableName", tableName); |
990 | settings.setValue("tableName", tableName); |
958 | settings.setValue("hostName", hostName); |
991 | settings.setValue("hostName", hostName); |
959 | }
|
992 | }
|
960 | 993 | ||
961 | 994 | ||
962 | void ClassEditor::applySetting() |
995 | void ClassEditor::applySetting() |
963 | {
|
996 | {
|
964 | bool ok; |
997 | bool ok; |
965 | baseName = setFrm.lineEdit->text(); |
998 | baseName = setFrm.lineEdit->text(); |
966 | userName = setFrm.lineEdit_2->text(); |
999 | userName = setFrm.lineEdit_2->text(); |
967 | password = setFrm.lineEdit_3->text(); |
1000 | password = setFrm.lineEdit_3->text(); |
968 | // tableName = setFrm->lineEdit_4->text();
|
1001 | // tableName = setFrm->lineEdit_4->text();
|
969 | hostName = setFrm.lineEdit_5->text(); |
1002 | hostName = setFrm.lineEdit_5->text(); |
970 | writeSettings(); |
1003 | writeSettings(); |
971 | 1004 | ||
972 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
1005 | sql.close(); // ðàçðûâàåì ñîåäèíåíèå ñ áàçîé |
973 | 1006 | ||
974 | sql.setDatabaseName(baseName); |
1007 | sql.setDatabaseName(baseName); |
975 | // sql.setDatabaseName(tr("inventory"));
|
1008 | // sql.setDatabaseName(tr("inventory"));
|
976 | 1009 | ||
977 | // sql.setHostName(tr("localhost"));
|
1010 | // sql.setHostName(tr("localhost"));
|
978 | sql.setHostName(hostName); |
1011 | sql.setHostName(hostName); |
979 | 1012 | ||
980 | // sql.setUserName(tr("an"));
|
1013 | // sql.setUserName(tr("an"));
|
981 | 1014 | ||
982 | sql.setUserName(userName); |
1015 | sql.setUserName(userName); |
983 | 1016 | ||
984 | // sql.setPassword(tr("393939"));
|
1017 | // sql.setPassword(tr("393939"));
|
985 | 1018 | ||
986 | sql.setPassword(password); |
1019 | sql.setPassword(password); |
987 | 1020 | ||
988 | ok = sql.connect(); |
1021 | ok = sql.connect(); |
989 | if (!ok) { |
1022 | if (!ok) { |
990 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1023 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
991 | this, // Ðîäèòåëüñêèé âèäæåò. |
1024 | this, // Ðîäèòåëüñêèé âèäæåò. |
992 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1025 | QObject::tr("Database Error"), // Çàãîëîâîê. |
993 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1026 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
994 | 1027 | ||
995 | }
|
1028 | }
|
996 | else { |
1029 | else { |
997 | 1030 | ||
998 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1031 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
999 | this, // Ðîäèòåëüñêèé âèäæåò. |
1032 | this, // Ðîäèòåëüñêèé âèäæåò. |
1000 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1033 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1001 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1034 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1002 | 1035 | ||
1003 | 1036 | ||
1004 | 1037 | ||
1005 | 1038 | ||
1006 | 1039 | ||
1007 | }
|
1040 | }
|
1008 | 1041 | ||
1009 | 1042 | ||
1010 | mymodel->select(); |
1043 | mymodel->select(); |
1011 | model->select(); |
1044 | model->select(); |
1012 | modelForDescription->select(); |
1045 | modelForDescription->select(); |
1013 | 1046 | ||
1014 | //////////// ok=openDataBase();
|
1047 | //////////// ok=openDataBase();
|
1015 | //////////// if (!ok) return;
|
1048 | //////////// if (!ok) return;
|
1016 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1049 | // // // ui->treeWidget->clear(); // î÷èùàåì äåðåâî ñ ìîäåëüþ
|
1017 | 1050 | ||
1018 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1051 | // // // buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("1"));
|
1019 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1052 | //////////// class_list_map.clear(); // î÷èùàåì ñïèñîê êëàññîâ
|
1020 | //////////// initComboBox();
|
1053 | //////////// initComboBox();
|
1021 | // // // getDatabaseData();
|
1054 | // // // getDatabaseData();
|
1022 | // delete setFrm;
|
1055 | // delete setFrm;
|
1023 | setFrm.close(); |
1056 | setFrm.close(); |
1024 | }
|
1057 | }
|
1025 | 1058 | ||
1026 | void ClassEditor::getSetting() |
1059 | void ClassEditor::getSetting() |
1027 | {
|
1060 | {
|
1028 | // setFrm = new settingForm;
|
1061 | // setFrm = new settingForm;
|
1029 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1062 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
|
1030 | setFrm.lineEdit->setText(baseName); |
1063 | setFrm.lineEdit->setText(baseName); |
1031 | setFrm.lineEdit_2->setText(userName); |
1064 | setFrm.lineEdit_2->setText(userName); |
1032 | setFrm.lineEdit_3->setText(password); |
1065 | setFrm.lineEdit_3->setText(password); |
1033 | // setFrm->lineEdit_4->setText(tableName);
|
1066 | // setFrm->lineEdit_4->setText(tableName);
|
1034 | setFrm.lineEdit_5->setText(hostName); |
1067 | setFrm.lineEdit_5->setText(hostName); |
1035 | setFrm.show(); |
1068 | setFrm.show(); |
1036 | 1069 | ||
1037 | 1070 | ||
1038 | 1071 | ||
1039 | }
|
1072 | }
|
1040 | 1073 | ||
1041 | 1074 | ||
1042 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1075 | void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ |
1043 | 1076 | ||
1044 | sql.setDatabaseName(baseName); |
1077 | sql.setDatabaseName(baseName); |
1045 | sql.setHostName(hostName); |
1078 | sql.setHostName(hostName); |
1046 | sql.setUserName(userName); |
1079 | sql.setUserName(userName); |
1047 | sql.setPassword(password); |
1080 | sql.setPassword(password); |
1048 | 1081 | ||
1049 | bool ok; |
1082 | bool ok; |
1050 | ok = sql.connect(); |
1083 | ok = sql.connect(); |
1051 | if (!ok) { |
1084 | if (!ok) { |
1052 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1085 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1053 | this, // Ðîäèòåëüñêèé âèäæåò. |
1086 | this, // Ðîäèòåëüñêèé âèäæåò. |
1054 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1087 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1055 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1088 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1056 | 1089 | ||
1057 | }
|
1090 | }
|
1058 | else { |
1091 | else { |
1059 | 1092 | ||
1060 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1093 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1061 | this, // Ðîäèòåëüñêèé âèäæåò. |
1094 | this, // Ðîäèòåëüñêèé âèäæåò. |
1062 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1095 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
1063 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1096 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
1064 | 1097 | ||
1065 | 1098 | ||
1066 | 1099 | ||
1067 | 1100 | ||
1068 | 1101 | ||
1069 | }
|
1102 | }
|
1070 | 1103 | ||
1071 | }
|
1104 | }
|
1072 | 1105 | ||
1073 | 1106 | ||
1074 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1107 | void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses |
1075 | 1108 | ||
1076 | bool ok; |
1109 | bool ok; |
1077 | ok = sql.createListOfClassesTable(); |
1110 | ok = sql.createListOfClassesTable(); |
1078 | 1111 | ||
1079 | if (!ok) { |
1112 | if (!ok) { |
1080 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1113 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1081 | this, // Ðîäèòåëüñêèé âèäæåò. |
1114 | this, // Ðîäèòåëüñêèé âèäæåò. |
1082 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1115 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1083 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1116 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1084 | 1117 | ||
1085 | }
|
1118 | }
|
1086 | else { |
1119 | else { |
1087 | 1120 | ||
1088 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1121 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1089 | this, // Ðîäèòåëüñêèé âèäæåò. |
1122 | this, // Ðîäèòåëüñêèé âèäæåò. |
1090 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1123 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1091 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1124 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1092 | }
|
1125 | }
|
1093 | 1126 | ||
1094 | 1127 | ||
1095 | 1128 | ||
1096 | 1129 | ||
1097 | ok = sql.createDescriptionOfClassesTable(); |
1130 | ok = sql.createDescriptionOfClassesTable(); |
1098 | 1131 | ||
1099 | if (!ok) { |
1132 | if (!ok) { |
1100 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1133 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1101 | this, // Ðîäèòåëüñêèé âèäæåò. |
1134 | this, // Ðîäèòåëüñêèé âèäæåò. |
1102 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1135 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1103 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1136 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1104 | 1137 | ||
1105 | }
|
1138 | }
|
1106 | else { |
1139 | else { |
1107 | 1140 | ||
1108 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1141 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1109 | this, // Ðîäèòåëüñêèé âèäæåò. |
1142 | this, // Ðîäèòåëüñêèé âèäæåò. |
1110 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1143 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1111 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1144 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1112 | }
|
1145 | }
|
1113 | 1146 | ||
1114 | 1147 | ||
1115 | ok = sql.createListModelsTable(); |
1148 | ok = sql.createListModelsTable(); |
1116 | 1149 | ||
1117 | if (!ok) { |
1150 | if (!ok) { |
1118 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1151 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1119 | this, // Ðîäèòåëüñêèé âèäæåò. |
1152 | this, // Ðîäèòåëüñêèé âèäæåò. |
1120 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1153 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1121 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1154 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1122 | 1155 | ||
1123 | }
|
1156 | }
|
1124 | else { |
1157 | else { |
1125 | 1158 | ||
1126 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1159 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1127 | this, // Ðîäèòåëüñêèé âèäæåò. |
1160 | this, // Ðîäèòåëüñêèé âèäæåò. |
1128 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1161 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1129 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1162 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1130 | }
|
1163 | }
|
1131 | 1164 | ||
1132 | 1165 | ||
1133 | 1166 | ||
1134 | 1167 | ||
1135 | 1168 | ||
1136 | ok = sql.createFiltersTable(); |
1169 | ok = sql.createFiltersTable(); |
1137 | 1170 | ||
1138 | if (!ok) { |
1171 | if (!ok) { |
1139 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1172 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1140 | this, // Ðîäèòåëüñêèé âèäæåò. |
1173 | this, // Ðîäèòåëüñêèé âèäæåò. |
1141 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1174 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1142 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1175 | sql.lasError()); // Òåêñò ñîîáùåíèÿ. |
1143 | 1176 | ||
1144 | }
|
1177 | }
|
1145 | else { |
1178 | else { |
1146 | 1179 | ||
1147 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1180 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1148 | this, // Ðîäèòåëüñêèé âèäæåò. |
1181 | this, // Ðîäèòåëüñêèé âèäæåò. |
1149 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1182 | QObject::tr("Database Create"), // Çàãîëîâîê. |
1150 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1183 | QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ. |
1151 | }
|
1184 | }
|
1152 | 1185 | ||
1153 | 1186 | ||
1154 | }
|
1187 | }
|
1155 | 1188 | ||
1156 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1189 | void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ |
1157 | 1190 | ||
1158 | mymodel->setTable(tr("ListOfClasses")); |
1191 | mymodel->setTable(tr("ListOfClasses")); |
1159 | mymodel->setSort(0, Qt::AscendingOrder); |
1192 | mymodel->setSort(0, Qt::AscendingOrder); |
1160 | mymodel->select(); |
1193 | mymodel->select(); |
1161 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1194 | mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà")); |
1162 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1195 | mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà")); |
1163 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1196 | mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé")); |
1164 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1197 | mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà")); |
1165 | ui->tableView->setModel(mymodel); |
1198 | ui->tableView->setModel(mymodel); |
1166 | ui->tableView->setAlternatingRowColors(true); |
1199 | ui->tableView->setAlternatingRowColors(true); |
1167 | ui->tableView->resizeColumnsToContents(); |
1200 | ui->tableView->resizeColumnsToContents(); |
1168 | ui->tableView->resizeRowsToContents(); |
1201 | ui->tableView->resizeRowsToContents(); |
1169 | ui->tableView->hideColumn(0); |
1202 | ui->tableView->hideColumn(0); |
1170 | ui->tableView->hideColumn(3); |
1203 | ui->tableView->hideColumn(3); |
1171 | ui->tableView->hideColumn(2); |
1204 | ui->tableView->hideColumn(2); |
1172 | CPictureDelegate *pictureDelegate; |
1205 | CPictureDelegate *pictureDelegate; |
1173 | pictureDelegate = new CPictureDelegate(this); |
1206 | pictureDelegate = new CPictureDelegate(this); |
1174 | pictureDelegate->setTableView(ui->tableView); |
1207 | pictureDelegate->setTableView(ui->tableView); |
1175 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1208 | ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
1176 | ui->tableView->resizeColumnsToContents(); |
1209 | ui->tableView->resizeColumnsToContents(); |
1177 | ui->tableView->resizeRowsToContents(); |
1210 | ui->tableView->resizeRowsToContents(); |
1178 | /*
|
1211 | /*
|
1179 | for (int i=0; i < mymodel->rowCount(); i++){
|
1212 | for (int i=0; i < mymodel->rowCount(); i++){
|
1180 | ui->tableView->setRowHeight(i, 100);
|
1213 | ui->tableView->setRowHeight(i, 100);
|
1181 | }
|
1214 | }
|
1182 | */
|
1215 | */
|
1183 | 1216 | ||
1184 | }
|
1217 | }
|
1185 | 1218 | ||
1186 | 1219 | ||
1187 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1220 | void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ |
1188 | 1221 | ||
1189 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1222 | modelForDescription->setTable(tr("DescriptionOfClasses")); |
1190 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1223 | modelForDescription->setSort(0, Qt::AscendingOrder); |
1191 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1224 | modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange); |
1192 | ui->tableView_2->setModel(modelForDescription); |
1225 | ui->tableView_2->setModel(modelForDescription); |
1193 | ui->tableView_2->setAlternatingRowColors(true); |
1226 | ui->tableView_2->setAlternatingRowColors(true); |
1194 | ui->tableView_2->resizeColumnsToContents(); |
1227 | ui->tableView_2->resizeColumnsToContents(); |
1195 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1228 | ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate); |
1196 | }
|
1229 | }
|
1197 | 1230 | ||
1198 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1231 | void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà |
1199 | 1232 | ||
1200 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1233 | modelForPointers->setTable(tr("DescriptionOfClasses")); |
1201 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1234 | modelForPointers->setSort(0, Qt::AscendingOrder); |
1202 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1235 | modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange); |
1203 | ui->tableView_3->setModel(modelForPointers); |
1236 | ui->tableView_3->setModel(modelForPointers); |
1204 | delegateForDefaultValueColomn.getItems(); |
1237 | delegateForDefaultValueColomn.getItems(); |
1205 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1238 | ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn); |
1206 | 1239 | ||
1207 | // ui->tableView_3->resizeColumnsToContents();
|
1240 | // ui->tableView_3->resizeColumnsToContents();
|
1208 | 1241 | ||
1209 | }
|
1242 | }
|
1210 | 1243 |