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