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