Редакция 236 | Редакция 238 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 236 | Редакция 237 | ||
---|---|---|---|
1 | #include "mainwindow.h"
|
1 | #include "mainwindow.h"
|
2 | #include "ui_mainwindow.h"
|
2 | #include "ui_mainwindow.h"
|
3 | 3 | ||
4 | MainWindow::MainWindow(QWidget *parent) : |
4 | MainWindow::MainWindow(QWidget *parent) : |
5 | QMainWindow(parent), |
5 | QMainWindow(parent), |
6 | ui(new Ui::MainWindow) |
6 | ui(new Ui::MainWindow) |
7 | {
|
7 | {
|
8 | ui->setupUi(this); |
8 | ui->setupUi(this); |
9 | /*
|
9 | /*
|
10 | QPalette p = this->palette();
|
10 | QPalette p = this->palette();
|
11 | p.setBrush(this->backgroundRole(), QBrush(QColor(255,255,255,128)));
|
11 | p.setBrush(this->backgroundRole(), QBrush(QColor(255,255,255,128)));
|
12 | this->setAutoFillBackground(true);
|
12 | this->setAutoFillBackground(true);
|
13 | this->setPalette(p);
|
13 | this->setPalette(p);
|
14 | */
|
14 | */
|
15 | 15 | ||
16 | ui->centralWidget->setLayout(ui->verticalLayout); |
16 | ui->centralWidget->setLayout(ui->verticalLayout); |
17 | ui->tab->setLayout(ui->horizontalLayout); |
17 | ui->tab->setLayout(ui->horizontalLayout); |
18 | ui->tab_2->setLayout(ui->horizontalLayout_3); |
18 | ui->tab_2->setLayout(ui->horizontalLayout_3); |
19 | ui->tab_3->setLayout(ui->horizontalLayout_7); |
19 | ui->tab_3->setLayout(ui->horizontalLayout_7); |
- | 20 | ui->tab_4->setLayout(ui->horizontalLayout_8); |
|
20 | // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int)));
|
21 | // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int)));
|
21 | model_is_build = false; |
22 | model_is_build = false; |
22 | // MainWindow::readModel();
|
23 | // MainWindow::readModel();
|
23 | 24 | ||
24 | //QString model_str;
|
25 | //QString model_str;
|
25 | 26 | ||
26 | 27 | ||
27 | /*
|
28 | /*
|
28 | MainWindow::creatModelString();
|
29 | MainWindow::creatModelString();
|
29 | int i;
|
30 | int i;
|
30 | i++;
|
31 | i++;
|
31 | QFile file_tmp("./temp.txt");
|
32 | QFile file_tmp("./temp.txt");
|
32 | bool ok;
|
33 | bool ok;
|
33 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
|
34 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
|
34 | QTextStream out(&file_tmp);
|
35 | QTextStream out(&file_tmp);
|
35 | out << MainWindow::modelString;
|
36 | out << MainWindow::modelString;
|
36 | file_tmp.close();
|
37 | file_tmp.close();
|
37 | */
|
38 | */
|
38 | 39 | ||
39 | 40 | ||
40 | 41 | ||
41 | 42 | ||
42 | ui->treeWidget->setAlternatingRowColors(true); |
43 | ui->treeWidget->setAlternatingRowColors(true); |
43 | ui->treeWidget_2->setAlternatingRowColors(true); |
44 | ui->treeWidget_2->setAlternatingRowColors(true); |
44 | 45 | ||
45 | ui->treeWidget->setIconSize(QSize(30,30)); |
46 | ui->treeWidget->setIconSize(QSize(30,30)); |
46 | ui->treeWidget->setColumnWidth(0, 400); |
47 | ui->treeWidget->setColumnWidth(0, 400); |
47 | ui->treeWidget_2->setIconSize(QSize(128,128)); |
48 | ui->treeWidget_2->setIconSize(QSize(128,128)); |
48 | 49 | ||
49 | MainWindow::readSettings(); |
50 | MainWindow::readSettings(); |
50 | 51 | ||
51 | MainWindow::openDataBase(); |
52 | MainWindow::openDataBase(); |
52 | 53 | ||
53 | classesIcons = MainWindow::getClassesIcons(); // ïîëó÷èì èêîíêè äëÿ êëàññîâ |
54 | classesIcons = MainWindow::getClassesIcons(); // ïîëó÷èì èêîíêè äëÿ êëàññîâ |
54 | 55 | ||
55 | MainWindow::initComboBox(); |
56 | MainWindow::initComboBox(); |
56 | 57 | ||
57 | // MainWindow::buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("11"));
|
58 | // MainWindow::buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("11"));
|
58 | 59 | ||
59 | MainWindow::initListModelsTablle(); |
60 | MainWindow::initListModelsTablle(); |
60 | 61 | ||
61 | MainWindow::readModels(); |
62 | MainWindow::readModels(); |
62 | 63 | ||
63 | // MainWindow::creatModelString();
|
64 | // MainWindow::creatModelString();
|
64 | //int i;
|
65 | //int i;
|
65 | //i++;
|
66 | //i++;
|
66 | 67 | ||
67 | /*
|
68 | /*
|
68 | QFile file_tmp("./modelstring.txt");
|
69 | QFile file_tmp("./modelstring.txt");
|
69 | bool ok;
|
70 | bool ok;
|
70 | file_tmp.remove();
|
71 | file_tmp.remove();
|
71 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
|
72 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
|
72 | QTextStream out(&file_tmp);
|
73 | QTextStream out(&file_tmp);
|
73 | out.setCodec("cp1251");
|
74 | out.setCodec("cp1251");
|
74 | out << MainWindow::modelString;
|
75 | out << MainWindow::modelString;
|
75 | file_tmp.close();
|
76 | file_tmp.close();
|
76 | */
|
77 | */
|
77 | 78 | ||
78 | 79 | ||
79 | ui->treeWidget_2->hideColumn(1); |
80 | ui->treeWidget_2->hideColumn(1); |
80 | ui->treeWidget_2->hideColumn(2); |
81 | ui->treeWidget_2->hideColumn(2); |
81 | ui->treeWidget_2->hideColumn(3); |
82 | ui->treeWidget_2->hideColumn(3); |
82 | ui->treeWidget_2->hideColumn(4); |
83 | ui->treeWidget_2->hideColumn(4); |
83 | ui->treeWidget_2->hideColumn(5); |
84 | ui->treeWidget_2->hideColumn(5); |
84 | 85 | ||
85 | 86 | ||
86 | getDatabaseData(); |
87 | getDatabaseData(); |
87 | //// sql_mogel = new QSqlTableModel();
|
88 | //// sql_mogel = new QSqlTableModel();
|
88 | sql_mogel = new MyModel(); |
89 | sql_mogel = new MyModel(); |
89 | 90 | ||
90 | /// filter_model = new MyModel();
|
91 | /// filter_model = new MyModel();
|
91 | filter_model = new QSqlTableModel(); |
92 | filter_model = new QSqlTableModel(); |
92 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
93 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
93 | 94 | ||
94 | model_is_build = true; |
95 | model_is_build = true; |
95 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
96 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
96 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
97 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
97 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
98 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
98 | 99 | ||
99 | 100 | ||
100 | ui->pushButton_3->setEnabled(false); |
101 | ui->pushButton_3->setEnabled(false); |
101 | ui->pushButton_4->setEnabled(false); |
102 | ui->pushButton_4->setEnabled(false); |
102 | 103 | ||
103 | 104 | ||
104 | ui->pushButton_9->setEnabled(false); |
105 | ui->pushButton_9->setEnabled(false); |
105 | ui->pushButton_10->setEnabled(false); |
106 | ui->pushButton_10->setEnabled(false); |
106 | ui->pushButton_11->setEnabled(false); |
107 | ui->pushButton_11->setEnabled(false); |
107 | ui->pushButton_12->setEnabled(false); |
108 | ui->pushButton_12->setEnabled(false); |
108 | 109 | ||
109 | // setFrm.show();
|
110 | // setFrm.show();
|
110 | 111 | ||
111 | // treeForm.show();
|
112 | // treeForm.show();
|
112 | 113 | ||
113 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ" |
114 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ" |
114 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
115 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
115 | 116 | ||
116 | // connect(ui->tableView_2,SIGNAL(activated(QModelIndex)),ui->tableView_2,SLOT(edit(QModelIndex)));
|
117 | // connect(ui->tableView_2,SIGNAL(activated(QModelIndex)),ui->tableView_2,SLOT(edit(QModelIndex)));
|
117 | 118 | ||
118 | picture_delegate = new CPictureDelegate(this); |
119 | picture_delegate = new CPictureDelegate(this); |
119 | iconDelegate = new IconDelegate(this); |
120 | iconDelegate = new IconDelegate(this); |
120 | fileDelegate = new FileDelegate(this); |
121 | fileDelegate = new FileDelegate(this); |
121 | 122 | ||
122 | // fileForm.show();
|
123 | // fileForm.show();
|
123 | 124 | ||
124 | doc = ui->textEdit->document(); |
125 | doc = ui->textEdit->document(); |
125 | cursor = new QTextCursor(doc); |
126 | cursor = new QTextCursor(doc); |
126 | // buildReport(true);
|
127 | // buildReport(true);
|
127 | 128 | ||
128 | 129 | ||
129 | }
|
130 | }
|
130 | 131 | ||
131 | MainWindow::~MainWindow() |
132 | MainWindow::~MainWindow() |
132 | {
|
133 | {
|
133 | delete sql_mogel; |
134 | delete sql_mogel; |
134 | delete filter_model; |
135 | delete filter_model; |
135 | delete ui; |
136 | delete ui; |
136 | delete model_for_ListModelsTable; |
137 | delete model_for_ListModelsTable; |
137 | }
|
138 | }
|
138 | 139 | ||
139 | void MainWindow::changeEvent(QEvent *e) |
140 | void MainWindow::changeEvent(QEvent *e) |
140 | {
|
141 | {
|
141 | QMainWindow::changeEvent(e); |
142 | QMainWindow::changeEvent(e); |
142 | switch (e->type()) { |
143 | switch (e->type()) { |
143 | case QEvent::LanguageChange: |
144 | case QEvent::LanguageChange: |
144 | ui->retranslateUi(this); |
145 | ui->retranslateUi(this); |
145 | break; |
146 | break; |
146 | default: |
147 | default: |
147 | break; |
148 | break; |
148 | }
|
149 | }
|
149 | }
|
150 | }
|
150 | 151 | ||
151 | 152 | ||
152 | bool MainWindow::readModel(){ |
153 | bool MainWindow::readModel(){ |
153 | bool result; |
154 | bool result; |
154 | QString model_str;
|
155 | QString model_str;
|
155 | QFile file("modelstring.txt"); |
156 | QFile file("modelstring.txt"); |
156 | // QFile file("model.txt");
|
157 | // QFile file("model.txt");
|
157 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
158 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
158 | rootItem1->setText(0, tr("Óðîâåíü 1")); |
159 | rootItem1->setText(0, tr("Óðîâåíü 1")); |
159 | // rootItem2 = new QTreeWidgetItem(rootItem1);
|
160 | // rootItem2 = new QTreeWidgetItem(rootItem1);
|
160 | // rootItem2->setText(0, tr("óðîâåíü 2"));
|
161 | // rootItem2->setText(0, tr("óðîâåíü 2"));
|
161 | rootItem1->setCheckState(0,Qt::Checked); |
162 | rootItem1->setCheckState(0,Qt::Checked); |
162 | // rootItem2->setCheckState(0,Qt::Checked);
|
163 | // rootItem2->setCheckState(0,Qt::Checked);
|
163 | 164 | ||
164 | 165 | ||
165 | 166 | ||
166 | result = file.open(QIODevice::ReadOnly); |
167 | result = file.open(QIODevice::ReadOnly); |
167 | if (result) { |
168 | if (result) { |
168 | model_str = QString(tr(file.readAll())); |
169 | model_str = QString(tr(file.readAll())); |
169 | }
|
170 | }
|
170 | 171 | ||
171 | setupModelData(model_str.split(QString("\n")), rootItem1, -1, tr("1")); |
172 | setupModelData(model_str.split(QString("\n")), rootItem1, -1, tr("1")); |
172 | 173 | ||
173 | 174 | ||
174 | return result; |
175 | return result; |
175 | 176 | ||
176 | }
|
177 | }
|
177 | 178 | ||
178 | 179 | ||
179 | void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row, QString model_id) |
180 | void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row, QString model_id) |
180 | {
|
181 | {
|
181 | QList<QTreeWidgetItem*> parents; |
182 | QList<QTreeWidgetItem*> parents; |
182 | QList<int> indentations; |
183 | QList<int> indentations; |
183 | parents << parent; |
184 | parents << parent; |
184 | indentations << 0; |
185 | indentations << 0; |
185 | 186 | ||
186 | int number = 0; |
187 | int number = 0; |
187 | 188 | ||
188 | while (number < lines.count()) { |
189 | while (number < lines.count()) { |
189 | int position = 0; |
190 | int position = 0; |
190 | while (position < lines[number].length()) { |
191 | while (position < lines[number].length()) { |
191 | if (lines[number].mid(position, 1) != " ") |
192 | if (lines[number].mid(position, 1) != " ") |
192 | break; |
193 | break; |
193 | position++; |
194 | position++; |
194 | }
|
195 | }
|
195 | 196 | ||
196 | QString lineData = lines[number].mid(position).trimmed(); |
197 | QString lineData = lines[number].mid(position).trimmed(); |
197 | 198 | ||
198 | if (!lineData.isEmpty()) { |
199 | if (!lineData.isEmpty()) { |
199 | // Read the column data from the rest of the line.
|
200 | // Read the column data from the rest of the line.
|
200 | QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
201 | QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
201 | QList<QVariant> columnData; |
202 | QList<QVariant> columnData; |
202 | for (int column = 0; column < columnStrings.count(); ++column) |
203 | for (int column = 0; column < columnStrings.count(); ++column) |
203 | columnData << columnStrings[column]; |
204 | columnData << columnStrings[column]; |
204 | 205 | ||
205 | if (position > indentations.last()) { |
206 | if (position > indentations.last()) { |
206 | // The last child of the current parent is now the new parent
|
207 | // The last child of the current parent is now the new parent
|
207 | // unless the current parent has no children.
|
208 | // unless the current parent has no children.
|
208 | 209 | ||
209 | if (parents.last()->childCount() > 0) { |
210 | if (parents.last()->childCount() > 0) { |
210 | parents << parents.last()->child(parents.last()->childCount()-1); |
211 | parents << parents.last()->child(parents.last()->childCount()-1); |
211 | indentations << position; |
212 | indentations << position; |
212 | }
|
213 | }
|
213 | } else { |
214 | } else { |
214 | while (position < indentations.last() && parents.count() > 0) { |
215 | while (position < indentations.last() && parents.count() > 0) { |
215 | parents.pop_back(); |
216 | parents.pop_back(); |
216 | indentations.pop_back(); |
217 | indentations.pop_back(); |
217 | }
|
218 | }
|
218 | }
|
219 | }
|
219 | 220 | ||
220 | // Append a new item to the current parent's list of children.
|
221 | // Append a new item to the current parent's list of children.
|
221 | // // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last()));
|
222 | // // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last()));
|
222 | QTreeWidgetItem* itm_tmp; |
223 | QTreeWidgetItem* itm_tmp; |
223 | itm_tmp = new QTreeWidgetItem( parents.last()); |
224 | itm_tmp = new QTreeWidgetItem( parents.last()); |
224 | // itm_tmp->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
225 | // itm_tmp->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
225 | 226 | ||
226 | /*
|
227 | /*
|
227 | QLineEdit * edit_line;
|
228 | QLineEdit * edit_line;
|
228 | edit_line = new QLineEdit(this);
|
229 | edit_line = new QLineEdit(this);
|
229 | ui->treeWidget->setItemWidget(itm_tmp, 5, edit_line);
|
230 | ui->treeWidget->setItemWidget(itm_tmp, 5, edit_line);
|
230 | */
|
231 | */
|
231 | //static QStandartDelegate delegate;
|
232 | //static QStandartDelegate delegate;
|
232 | ui->treeWidget->setItemDelegateForColumn(5, &standart_delegate); |
233 | ui->treeWidget->setItemDelegateForColumn(5, &standart_delegate); |
233 | 234 | ||
234 | 235 | ||
235 | itm_tmp->setText(0, QString(columnData.at(0).toString())); |
236 | itm_tmp->setText(0, QString(columnData.at(0).toString())); |
236 | if (columnData.at(1).toString() == "true") { |
237 | if (columnData.at(1).toString() == "true") { |
237 | itm_tmp->setCheckState(0,Qt::Checked); |
238 | itm_tmp->setCheckState(0,Qt::Checked); |
238 | }
|
239 | }
|
239 | else itm_tmp->setCheckState(0,Qt::Unchecked); |
240 | else itm_tmp->setCheckState(0,Qt::Unchecked); |
240 | if (columnData.count()>2) |
241 | if (columnData.count()>2) |
241 | {
|
242 | {
|
242 | QString class_id;
|
243 | QString class_id;
|
243 | QString filtr_str;
|
244 | QString filtr_str;
|
244 | QPixmap pxmp;
|
245 | QPixmap pxmp;
|
245 | QIcon icon;
|
246 | QIcon icon;
|
246 | class_id = QString(columnData.at(2).toString()); |
247 | class_id = QString(columnData.at(2).toString()); |
247 | pxmp = MainWindow::classesIcons.value(class_id); |
248 | pxmp = MainWindow::classesIcons.value(class_id); |
248 | 249 | ||
249 | // itm_tmp->setText(1, QString(columnData.at(2).toString())); // id êëàññà
|
250 | // itm_tmp->setText(1, QString(columnData.at(2).toString())); // id êëàññà
|
250 | itm_tmp->setText(1, class_id); // id êëàññà |
251 | itm_tmp->setText(1, class_id); // id êëàññà |
251 | itm_tmp->setText(6, model_id); // id ìîäåëè |
252 | itm_tmp->setText(6, model_id); // id ìîäåëè |
252 | itm_tmp->setText(2, QVariant(number).toString()); // íîìåð ñòðîêè â ôàéëå-ìîäåëè îòîáðàæåíèÿ |
253 | itm_tmp->setText(2, QVariant(number).toString()); // íîìåð ñòðîêè â ôàéëå-ìîäåëè îòîáðàæåíèÿ |
253 | itm_tmp->setText(3, QVariant(indentations.size()).toString()); // óðîâåíü âëîæåíèÿ |
254 | itm_tmp->setText(3, QVariant(indentations.size()).toString()); // óðîâåíü âëîæåíèÿ |
254 | itm_tmp->setText(4, QVariant(row).toString()); // íîìåð ñòðîêè â ôàéëå |
255 | itm_tmp->setText(4, QVariant(row).toString()); // íîìåð ñòðîêè â ôàéëå |
255 | filtr_str = getFiltrString(model_id,class_id); |
256 | filtr_str = getFiltrString(model_id,class_id); |
256 | itm_tmp->setText(5,filtr_str); |
257 | itm_tmp->setText(5,filtr_str); |
257 | 258 | ||
258 | if (!pxmp.isNull()) |
259 | if (!pxmp.isNull()) |
259 | {
|
260 | {
|
260 | icon.addPixmap(pxmp); |
261 | icon.addPixmap(pxmp); |
261 | itm_tmp->setIcon(0, icon); |
262 | itm_tmp->setIcon(0, icon); |
262 | }
|
263 | }
|
263 | }
|
264 | }
|
264 | }
|
265 | }
|
265 | 266 | ||
266 | number++; |
267 | number++; |
267 | }
|
268 | }
|
268 | }
|
269 | }
|
269 | 270 | ||
270 | 271 | ||
271 | /*
|
272 | /*
|
272 | void MainWindow::openBase()
|
273 | void MainWindow::openBase()
|
273 | {
|
274 | {
|
274 | 275 | ||
275 | db = QSqlDatabase::addDatabase("QMYSQL");
|
276 | db = QSqlDatabase::addDatabase("QMYSQL");
|
276 | pdb = &db;
|
277 | pdb = &db;
|
277 | raportFrm.pdb = &db;
|
278 | raportFrm.pdb = &db;
|
278 | 279 | ||
279 | pdb->setHostName(hostName);
|
280 | pdb->setHostName(hostName);
|
280 | pdb->setDatabaseName(baseName);
|
281 | pdb->setDatabaseName(baseName);
|
281 | pdb->setUserName(userName);
|
282 | pdb->setUserName(userName);
|
282 | pdb->setPassword(password);
|
283 | pdb->setPassword(password);
|
283 | bool ok = pdb->open();
|
284 | bool ok = pdb->open();
|
284 | if (!ok) {
|
285 | if (!ok) {
|
285 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
286 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
286 | this, // Ðîäèòåëüñêèé âèäæåò.
|
287 | this, // Ðîäèòåëüñêèé âèäæåò.
|
287 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
288 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
288 | pdb->lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
289 | pdb->lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
289 | }
|
290 | }
|
290 | if (ok)
|
291 | if (ok)
|
291 | {lineEdit-> insert(tr("Áàçà óñïåøíî îòêðûòà"));
|
292 | {lineEdit-> insert(tr("Áàçà óñïåøíî îòêðûòà"));
|
292 | }
|
293 | }
|
293 | else {lineEdit-> insert(tr("Áàçà íåäîñòóïíà. Êîä îøèáêè: "));
|
294 | else {lineEdit-> insert(tr("Áàçà íåäîñòóïíà. Êîä îøèáêè: "));
|
294 | lineEdit-> insert(pdb->lastError().text());
|
295 | lineEdit-> insert(pdb->lastError().text());
|
295 | }
|
296 | }
|
296 | 297 | ||
297 | 298 | ||
298 | 299 | ||
299 | model = new QSqlTableModel(this);
|
300 | model = new QSqlTableModel(this);
|
300 | model->setTable(tableName);
|
301 | model->setTable(tableName);
|
301 | 302 | ||
302 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
303 | model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
303 | model->setSort(0, Qt::AscendingOrder);
|
304 | model->setSort(0, Qt::AscendingOrder);
|
304 | 305 | ||
305 | model->select();
|
306 | model->select();
|
306 | 307 | ||
307 | 308 | ||
308 | QSqlField field(tr("age"), QVariant::Int);
|
309 | QSqlField field(tr("age"), QVariant::Int);
|
309 | field.setValue(QString(tr("123")));
|
310 | field.setValue(QString(tr("123")));
|
310 | 311 | ||
311 | bool okey;
|
312 | bool okey;
|
312 | int index;
|
313 | int index;
|
313 | QSqlRecord record;
|
314 | QSqlRecord record;
|
314 | 315 | ||
315 | 316 | ||
316 | tableView->setModel(model);
|
317 | tableView->setModel(model);
|
317 | view.setModel(model);
|
318 | view.setModel(model);
|
318 | 319 | ||
319 | 320 | ||
320 | tableView->setAlternatingRowColors(true);
|
321 | tableView->setAlternatingRowColors(true);
|
321 | view.setAlternatingRowColors(true);
|
322 | view.setAlternatingRowColors(true);
|
322 | 323 | ||
323 | tableView->resizeColumnsToContents();
|
324 | tableView->resizeColumnsToContents();
|
324 | 325 | ||
325 | 326 | ||
326 | view.resizeColumnsToContents();
|
327 | view.resizeColumnsToContents();
|
327 | 328 | ||
328 | tableView->show();
|
329 | tableView->show();
|
329 | 330 | ||
330 | 331 | ||
331 | 332 | ||
332 | initTreeWidget();
|
333 | initTreeWidget();
|
333 | }
|
334 | }
|
334 | */
|
335 | */
|
335 | 336 | ||
336 | 337 | ||
337 | QString MainWindow::creatModelString(QTreeWidgetItem* model){ |
338 | QString MainWindow::creatModelString(QTreeWidgetItem* model){ |
338 | 339 | ||
339 | MainWindow::modelString.clear(); // î÷èùàåì ñòðîêó ìîäåëè |
340 | MainWindow::modelString.clear(); // î÷èùàåì ñòðîêó ìîäåëè |
340 | // for (int i =0; i < rootItem1->childCount(); ++i )
|
341 | // for (int i =0; i < rootItem1->childCount(); ++i )
|
341 | 342 | ||
342 | {MainWindow::addChildsString(model, 0);} |
343 | {MainWindow::addChildsString(model, 0);} |
343 | 344 | ||
344 | return MainWindow::modelString; |
345 | return MainWindow::modelString; |
345 | // {MainWindow::addChildsString(ui->treeWidget, 0);}
|
346 | // {MainWindow::addChildsString(ui->treeWidget, 0);}
|
346 | /*
|
347 | /*
|
347 | int root_item_child_count;
|
348 | int root_item_child_count;
|
348 | int i;
|
349 | int i;
|
349 | root_item_child_count = rootItem1->childCount();
|
350 | root_item_child_count = rootItem1->childCount();
|
350 | i++;
|
351 | i++;
|
351 | */
|
352 | */
|
352 | }
|
353 | }
|
353 | 354 | ||
354 | 355 | ||
355 | void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){ |
356 | void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){ |
356 | int child_count; |
357 | int child_count; |
357 | child_count = parentItem->childCount(); |
358 | child_count = parentItem->childCount(); |
358 | for (int i=0; i < child_count; ++i){ |
359 | for (int i=0; i < child_count; ++i){ |
359 | for (int m=0; m < level; ++m){ |
360 | for (int m=0; m < level; ++m){ |
360 | modelString.append(tr(" ")); // ÷åòûðå ïðîáåëà - ïðèçíàê òîãî, ÷òî ýòî íîâûé óðîâåíü âëîæåíèÿ |
361 | modelString.append(tr(" ")); // ÷åòûðå ïðîáåëà - ïðèçíàê òîãî, ÷òî ýòî íîâûé óðîâåíü âëîæåíèÿ |
361 | }
|
362 | }
|
362 | modelString.append(parentItem->child(i)->text(0)); // â ïåðâîé êîëîíêå - èìÿ êëàññà |
363 | modelString.append(parentItem->child(i)->text(0)); // â ïåðâîé êîëîíêå - èìÿ êëàññà |
363 | modelString.append(tr("\t\t\t\t")); // ÷åòûðå òàáóëÿöèè - ïðèçíàê íîâîãî ñòîëáöà |
364 | modelString.append(tr("\t\t\t\t")); // ÷åòûðå òàáóëÿöèè - ïðèçíàê íîâîãî ñòîëáöà |
364 | if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // åñëè ãàëî÷êà ñòîèò, çàíîñèì "true", ýëåìåíòû êëàññà â ïðåäñòàâëåíèè îòîáðàæàòüñÿ áóäóò |
365 | if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // åñëè ãàëî÷êà ñòîèò, çàíîñèì "true", ýëåìåíòû êëàññà â ïðåäñòàâëåíèè îòîáðàæàòüñÿ áóäóò |
365 | else {modelString.append(tr("false"));} // åñëè êëàññ íå âûáðàí - çàíîñèì "false", ýëåìåíòû êëàññà â ïðåäñòàâëåíèè îòîáðàæàòüñÿ íå áóäóò |
366 | else {modelString.append(tr("false"));} // åñëè êëàññ íå âûáðàí - çàíîñèì "false", ýëåìåíòû êëàññà â ïðåäñòàâëåíèè îòîáðàæàòüñÿ íå áóäóò |
366 | modelString.append(tr("\t\t\t\t")); // ÷åòûðå òàáóëÿöèè - ïðèçíàê íîâîãî ñòîëáöà |
367 | modelString.append(tr("\t\t\t\t")); // ÷åòûðå òàáóëÿöèè - ïðèçíàê íîâîãî ñòîëáöà |
367 | modelString.append(parentItem->child(i)->text(1)); // âî âòîðîé êîëîíêå - ID êëàññà |
368 | modelString.append(parentItem->child(i)->text(1)); // âî âòîðîé êîëîíêå - ID êëàññà |
368 | modelString.append(tr("\n")); // êîíåö ñòðîêè |
369 | modelString.append(tr("\n")); // êîíåö ñòðîêè |
369 | if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);} |
370 | if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);} |
370 | 371 | ||
371 | }
|
372 | }
|
372 | int i; |
373 | int i; |
373 | i++; |
374 | i++; |
374 | }
|
375 | }
|
375 | 376 | ||
376 | 377 | ||
377 | bool MainWindow::openDataBase(){ |
378 | bool MainWindow::openDataBase(){ |
378 | QString errorString;
|
379 | QString errorString;
|
379 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
380 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
380 | // sql.setDatabaseName(tr("an_db"));
|
381 | // sql.setDatabaseName(tr("an_db"));
|
381 | 382 | ||
382 | // // // sql.setDatabaseName(tr("inventory"));
|
383 | // // // sql.setDatabaseName(tr("inventory"));
|
383 | 384 | ||
384 | sql.setDatabaseName(baseName); |
385 | sql.setDatabaseName(baseName); |
385 | 386 | ||
386 | 387 | ||
387 | 388 | ||
388 | // // // sql.setHostName(tr("localhost"));
|
389 | // // // sql.setHostName(tr("localhost"));
|
389 | 390 | ||
390 | sql.setHostName(hostName); |
391 | sql.setHostName(hostName); |
391 | 392 | ||
392 | 393 | ||
393 | // // // sql.setUserName(tr("an"));
|
394 | // // // sql.setUserName(tr("an"));
|
394 | 395 | ||
395 | sql.setUserName(userName); |
396 | sql.setUserName(userName); |
396 | 397 | ||
397 | 398 | ||
398 | 399 | ||
399 | // // // sql.setPassword(tr("393939"));
|
400 | // // // sql.setPassword(tr("393939"));
|
400 | 401 | ||
401 | 402 | ||
402 | sql.setPassword(password); |
403 | sql.setPassword(password); |
403 | 404 | ||
404 | 405 | ||
405 | 406 | ||
406 | bool ok; |
407 | bool ok; |
407 | ok = sql.open(); |
408 | ok = sql.open(); |
408 | 409 | ||
409 | /*
|
410 | /*
|
410 | if (!ok) {
|
411 | if (!ok) {
|
411 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
412 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
412 | this, // Ðîäèòåëüñêèé âèäæåò.
|
413 | this, // Ðîäèòåëüñêèé âèäæåò.
|
413 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
414 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
414 | sql.lastError().text() ); // Òåêñò ñîîáùåíèÿ.
|
415 | sql.lastError().text() ); // Òåêñò ñîîáùåíèÿ.
|
415 | 416 | ||
416 | 417 | ||
417 | }
|
418 | }
|
418 | 419 | ||
419 | */
|
420 | */
|
420 | if (!ok) { |
421 | if (!ok) { |
421 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
422 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
422 | this, // Ðîäèòåëüñêèé âèäæåò. |
423 | this, // Ðîäèòåëüñêèé âèäæåò. |
423 | QObject::tr("Database Error"), // Çàãîëîâîê. |
424 | QObject::tr("Database Error"), // Çàãîëîâîê. |
424 | sql.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
425 | sql.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
425 | }
|
426 | }
|
426 | else { |
427 | else { |
427 | 428 | ||
428 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
429 | QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
429 | this, // Ðîäèòåëüñêèé âèäæåò. |
430 | this, // Ðîäèòåëüñêèé âèäæåò. |
430 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
431 | QObject::tr("Database Connect"), // Çàãîëîâîê. |
431 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
432 | QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ. |
432 | 433 | ||
433 | 434 | ||
434 | 435 | ||
435 | 436 | ||
436 | 437 | ||
437 | }
|
438 | }
|
438 | 439 | ||
439 | return ok; |
440 | return ok; |
440 | }
|
441 | }
|
441 | 442 | ||
442 | 443 | ||
443 | bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){ |
444 | bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){ |
444 | QSqlQuery q;
|
445 | QSqlQuery q;
|
445 | QString sql_str;
|
446 | QString sql_str;
|
446 | QString field_name_str;
|
447 | QString field_name_str;
|
447 | QString root_class_name;
|
448 | QString root_class_name;
|
448 | //bool ok;
|
449 | //bool ok;
|
449 | //int field_name;
|
450 | //int field_name;
|
450 | 451 | ||
451 | //ui->treeWidget->clear();
|
452 | //ui->treeWidget->clear();
|
452 | 453 | ||
453 | root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà |
454 | root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà |
454 | 455 | ||
455 | 456 | ||
456 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
457 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
457 | root_items_list << rootItem1; |
458 | root_items_list << rootItem1; |
458 | rootItem1->setText(0, modelName); |
459 | rootItem1->setText(0, modelName); |
459 | 460 | ||
460 | rootItem1->setCheckState(0,Qt::Checked); |
461 | rootItem1->setCheckState(0,Qt::Checked); |
461 | rootItems.append(rootItem1); |
462 | rootItems.append(rootItem1); |
462 | 463 | ||
463 | 464 | ||
464 | 465 | ||
465 | rootItem2 = new QTreeWidgetItem(rootItem1); |
466 | rootItem2 = new QTreeWidgetItem(rootItem1); |
466 | rootItem2->setText(0, root_class_name); |
467 | rootItem2->setText(0, root_class_name); |
467 | rootItem2->setText(1, rootClassID); |
468 | rootItem2->setText(1, rootClassID); |
468 | rootItem2->setCheckState(0,Qt::Checked); |
469 | rootItem2->setCheckState(0,Qt::Checked); |
469 | 470 | ||
470 | addChildsItems(rootItem2, -1); |
471 | addChildsItems(rootItem2, -1); |
471 | 472 | ||
472 | 473 | ||
473 | /*
|
474 | /*
|
474 | 475 | ||
475 | sql_str = tr("select * "
|
476 | sql_str = tr("select * "
|
476 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
|
477 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
|
477 | );
|
478 | );
|
478 | sql_str.append(rootClassID);
|
479 | sql_str.append(rootClassID);
|
479 | 480 | ||
480 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
|
481 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
|
481 | 482 | ||
482 | q.prepare(sql_str);
|
483 | q.prepare(sql_str);
|
483 | 484 | ||
484 | ok = q.exec();
|
485 | ok = q.exec();
|
485 | if (!ok) {
|
486 | if (!ok) {
|
486 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
487 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
487 | this, // Ðîäèòåëüñêèé âèäæåò.
|
488 | this, // Ðîäèòåëüñêèé âèäæåò.
|
488 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
489 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
489 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
490 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
490 | }
|
491 | }
|
491 | field_name = q.record().indexOf(tr("FieldName"));
|
492 | field_name = q.record().indexOf(tr("FieldName"));
|
492 | while(q.next()){
|
493 | while(q.next()){
|
493 | 494 | ||
494 | field_name_str = q.value(field_name).toString();
|
495 | field_name_str = q.value(field_name).toString();
|
495 | 496 | ||
496 | }
|
497 | }
|
497 | 498 | ||
498 | 499 | ||
499 | 500 | ||
500 | 501 | ||
501 | */
|
502 | */
|
502 | 503 | ||
503 | 504 | ||
504 | }
|
505 | }
|
505 | 506 | ||
506 | 507 | ||
507 | bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID, int row){ |
508 | bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID, int row){ |
508 | QSqlQuery q;
|
509 | QSqlQuery q;
|
509 | QString sql_str;
|
510 | QString sql_str;
|
510 | QString field_name_str;
|
511 | QString field_name_str;
|
511 | QString root_class_name;
|
512 | QString root_class_name;
|
512 | //bool ok;
|
513 | //bool ok;
|
513 | //int field_name;
|
514 | //int field_name;
|
514 | 515 | ||
515 | //ui->treeWidget->clear();
|
516 | //ui->treeWidget->clear();
|
516 | 517 | ||
517 | root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà |
518 | root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà |
518 | 519 | ||
519 | 520 | ||
520 | // rootItem1 = new QTreeWidgetItem(ui->treeWidget);
|
521 | // rootItem1 = new QTreeWidgetItem(ui->treeWidget);
|
521 | // root_items_list << rootItem1;
|
522 | // root_items_list << rootItem1;
|
522 | // rootItem1->setText(0, modelName);
|
523 | // rootItem1->setText(0, modelName);
|
523 | 524 | ||
524 | // rootItem1->setCheckState(0,Qt::Checked);
|
525 | // rootItem1->setCheckState(0,Qt::Checked);
|
525 | // rootItems.append(rootItem1);
|
526 | // rootItems.append(rootItem1);
|
526 | 527 | ||
527 | // root_item->removeChild(root_item->child(0)); // î÷èùàåì ñïèñîê äî÷åðíèõ êëàññîâ
|
528 | // root_item->removeChild(root_item->child(0)); // î÷èùàåì ñïèñîê äî÷åðíèõ êëàññîâ
|
528 | if (root_item->childCount()==0){ // íåò êîðíåâîãî êëàññà, ñîçäàäèì åãî |
529 | if (root_item->childCount()==0){ // íåò êîðíåâîãî êëàññà, ñîçäàäèì åãî |
529 | QTreeWidgetItem* item_tmp; |
530 | QTreeWidgetItem* item_tmp; |
530 | item_tmp = new QTreeWidgetItem (root_item); |
531 | item_tmp = new QTreeWidgetItem (root_item); |
531 | item_tmp->setText(4, QVariant(row).toString()); |
532 | item_tmp->setText(4, QVariant(row).toString()); |
532 | 533 | ||
533 | }
|
534 | }
|
534 | 535 | ||
535 | if (root_item->childCount()==1){ // êîðíåâîé êëàññ åñòü è îí ïóñòîé, î÷èùàòü åãî íå íàäî |
536 | if (root_item->childCount()==1){ // êîðíåâîé êëàññ åñòü è îí ïóñòîé, î÷èùàòü åãî íå íàäî |
536 | root_item->child(0)->setText(0, root_class_name); |
537 | root_item->child(0)->setText(0, root_class_name); |
537 | root_item->child(0)->setText(1, rootClassID); |
538 | root_item->child(0)->setText(1, rootClassID); |
538 | root_item->child(0)->setCheckState(0,Qt::Checked); |
539 | root_item->child(0)->setCheckState(0,Qt::Checked); |
539 | root_item->setText(4, QVariant(row).toString()); |
540 | root_item->setText(4, QVariant(row).toString()); |
540 | 541 | ||
541 | }
|
542 | }
|
542 | 543 | ||
543 | 544 | ||
544 | 545 | ||
545 | //delete rootItem2;
|
546 | //delete rootItem2;
|
546 | 547 | ||
547 | 548 | ||
548 | // rootItem2 = new QTreeWidgetItem(rootItem1);
|
549 | // rootItem2 = new QTreeWidgetItem(rootItem1);
|
549 | 550 | ||
550 | 551 | ||
551 | 552 | ||
552 | // rootItem2->setText(0, root_class_name);
|
553 | // rootItem2->setText(0, root_class_name);
|
553 | // rootItem2->setText(1, rootClassID);
|
554 | // rootItem2->setText(1, rootClassID);
|
554 | // rootItem2->setCheckState(0,Qt::Checked);
|
555 | // rootItem2->setCheckState(0,Qt::Checked);
|
555 | 556 | ||
556 | int child_count = root_item->child(0)->childCount(); |
557 | int child_count = root_item->child(0)->childCount(); |
557 | 558 | ||
558 | 559 | ||
559 | for (int i=0; i < child_count; i++){ // åñëè êîðíåâîé êëàññ åñòü è íå ïóñòîé, î÷èùàåì åãî |
560 | for (int i=0; i < child_count; i++){ // åñëè êîðíåâîé êëàññ åñòü è íå ïóñòîé, î÷èùàåì åãî |
560 | root_item->child(0)->removeChild(root_item->child(0)->child(0)); |
561 | root_item->child(0)->removeChild(root_item->child(0)->child(0)); |
561 | }
|
562 | }
|
562 | 563 | ||
563 | child_count = root_item->child(0)->childCount(); |
564 | child_count = root_item->child(0)->childCount(); |
564 | addChildsItems(root_item->child(0), row); |
565 | addChildsItems(root_item->child(0), row); |
565 | /*
|
566 | /*
|
566 | sql_str = tr("select * "
|
567 | sql_str = tr("select * "
|
567 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
|
568 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
|
568 | );
|
569 | );
|
569 | sql_str.append(rootClassID);
|
570 | sql_str.append(rootClassID);
|
570 | 571 | ||
571 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
|
572 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
|
572 | 573 | ||
573 | q.prepare(sql_str);
|
574 | q.prepare(sql_str);
|
574 | 575 | ||
575 | ok = q.exec();
|
576 | ok = q.exec();
|
576 | if (!ok) {
|
577 | if (!ok) {
|
577 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
578 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
578 | this, // Ðîäèòåëüñêèé âèäæåò.
|
579 | this, // Ðîäèòåëüñêèé âèäæåò.
|
579 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
580 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
580 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
581 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
581 | }
|
582 | }
|
582 | field_name = q.record().indexOf(tr("FieldName"));
|
583 | field_name = q.record().indexOf(tr("FieldName"));
|
583 | while(q.next()){
|
584 | while(q.next()){
|
584 | 585 | ||
585 | field_name_str = q.value(field_name).toString();
|
586 | field_name_str = q.value(field_name).toString();
|
586 | 587 | ||
587 | }
|
588 | }
|
588 | 589 | ||
589 | */
|
590 | */
|
590 | 591 | ||
591 | 592 | ||
592 | }
|
593 | }
|
593 | 594 | ||
594 | 595 | ||
595 | 596 | ||
596 | 597 | ||
597 | QString MainWindow::ClassName(QString class_id){ //âîçâðàùàåò èìÿ êëàññà ïî åãî ID |
598 | QString MainWindow::ClassName(QString class_id){ //âîçâðàùàåò èìÿ êëàññà ïî åãî ID |
598 | QSqlQuery q;
|
599 | QSqlQuery q;
|
599 | QString sql_str;
|
600 | QString sql_str;
|
600 | QString class_name_str;
|
601 | QString class_name_str;
|
601 | bool ok; |
602 | bool ok; |
602 | int field_class_name; |
603 | int field_class_name; |
603 | 604 | ||
604 | sql_str = tr("select * " |
605 | sql_str = tr("select * " |
605 | " from ListOfClasses where ListOfClasses.ID = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì |
606 | " from ListOfClasses where ListOfClasses.ID = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì |
606 | ); |
607 | ); |
607 | 608 | ||
608 | sql_str.append(class_id); |
609 | sql_str.append(class_id); |
609 | sql_str.append(tr("' ")); |
610 | sql_str.append(tr("' ")); |
610 | 611 | ||
611 | q.prepare(sql_str); |
612 | q.prepare(sql_str); |
612 | 613 | ||
613 | ok = q.exec(); |
614 | ok = q.exec(); |
614 | 615 | ||
615 | 616 | ||
616 | if (!ok) { |
617 | if (!ok) { |
617 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
618 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
618 | this, // Ðîäèòåëüñêèé âèäæåò. |
619 | this, // Ðîäèòåëüñêèé âèäæåò. |
619 | QObject::tr("Database Error"), // Çàãîëîâîê. |
620 | QObject::tr("Database Error"), // Çàãîëîâîê. |
620 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
621 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
621 | }
|
622 | }
|
622 | 623 | ||
623 | field_class_name = q.record().indexOf(tr("ClassName")); |
624 | field_class_name = q.record().indexOf(tr("ClassName")); |
624 | while(q.next()){ |
625 | while(q.next()){ |
625 | 626 | ||
626 | class_name_str = q.value(field_class_name).toString(); |
627 | class_name_str = q.value(field_class_name).toString(); |
627 | 628 | ||
628 | }
|
629 | }
|
629 | 630 | ||
630 | return class_name_str; |
631 | return class_name_str; |
631 | 632 | ||
632 | }
|
633 | }
|
633 | 634 | ||
634 | void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item, int row){ // äîáîâëÿåì ê ýëåìåíòó äåðåâà â êà÷åñòâå äî÷åðíèõ ýëåìåíòîâ âñå êëàññû, äëÿ êîòîðûõ êëàññ ýëåìåíòà ÿâëÿåòñÿ êîíòåéíåðîì |
635 | void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item, int row){ // äîáîâëÿåì ê ýëåìåíòó äåðåâà â êà÷åñòâå äî÷åðíèõ ýëåìåíòîâ âñå êëàññû, äëÿ êîòîðûõ êëàññ ýëåìåíòà ÿâëÿåòñÿ êîíòåéíåðîì |
635 | QStringList chields_list;
|
636 | QStringList chields_list;
|
636 | QString parent_ID;
|
637 | QString parent_ID;
|
637 | QTreeWidgetItem *Item_tmp; |
638 | QTreeWidgetItem *Item_tmp; |
638 | parent_ID = perent_class_item->text(1); |
639 | parent_ID = perent_class_item->text(1); |
639 | int chields_count, i; |
640 | int chields_count, i; |
640 | 641 | ||
641 | chields_list = MainWindow::classChields(parent_ID); |
642 | chields_list = MainWindow::classChields(parent_ID); |
642 | if(chields_list.isEmpty()) return; |
643 | if(chields_list.isEmpty()) return; |
643 | chields_count = chields_list.size(); |
644 | chields_count = chields_list.size(); |
644 | for (int l = 0; l < chields_count; ++l){ |
645 | for (int l = 0; l < chields_count; ++l){ |
645 | QString chield_class_name, chield_id;
|
646 | QString chield_class_name, chield_id;
|
646 | chield_id = chields_list.at(l); |
647 | chield_id = chields_list.at(l); |
647 | chield_class_name = MainWindow::ClassName(chield_id); |
648 | chield_class_name = MainWindow::ClassName(chield_id); |
648 | Item_tmp = new QTreeWidgetItem(perent_class_item); |
649 | Item_tmp = new QTreeWidgetItem(perent_class_item); |
649 | Item_tmp->setText(0, chield_class_name); |
650 | Item_tmp->setText(0, chield_class_name); |
650 | Item_tmp->setText(1, chield_id); |
651 | Item_tmp->setText(1, chield_id); |
651 | Item_tmp->setCheckState(0, Qt::Checked); |
652 | Item_tmp->setCheckState(0, Qt::Checked); |
652 | Item_tmp->setText(4, QVariant(row).toString()); |
653 | Item_tmp->setText(4, QVariant(row).toString()); |
653 | MainWindow::addChildsItems(Item_tmp, row); |
654 | MainWindow::addChildsItems(Item_tmp, row); |
654 | }
|
655 | }
|
655 | 656 | ||
656 | i++; |
657 | i++; |
657 | 658 | ||
658 | }
|
659 | }
|
659 | 660 | ||
660 | 661 | ||
661 | /********************************************************
|
662 | /********************************************************
|
662 | * Ôóíêöèÿ âîçâðàùàåò ñïèñîê "äî÷åðíèõ" êëàññîâ
|
663 | * Ôóíêöèÿ âîçâðàùàåò ñïèñîê "äî÷åðíèõ" êëàññîâ
|
663 | *
|
664 | *
|
664 | *
|
665 | *
|
665 | *
|
666 | *
|
666 | ********************************************************/
|
667 | ********************************************************/
|
667 | 668 | ||
668 | QStringList MainWindow::classChields(QString class_id){ |
669 | QStringList MainWindow::classChields(QString class_id){ |
669 | // QMap<QString, QString> map;
|
670 | // QMap<QString, QString> map;
|
670 | // TClass class_tmp;
|
671 | // TClass class_tmp;
|
671 | // QList <TClass> chields_class_list; // ñïèñîê äî÷åðíèõ êëàññîâ
|
672 | // QList <TClass> chields_class_list; // ñïèñîê äî÷åðíèõ êëàññîâ
|
672 | QStringList result;
|
673 | QStringList result;
|
673 | QSqlQuery q;
|
674 | QSqlQuery q;
|
674 | QString sql_str;
|
675 | QString sql_str;
|
675 | QString classIdentifer_str; // â ýòîì ïîëå ëåæèò èäåíòèôèêàòîð êëàññà-êîíòåéíåðà |
676 | QString classIdentifer_str; // â ýòîì ïîëå ëåæèò èäåíòèôèêàòîð êëàññà-êîíòåéíåðà |
676 | QString field_id_str;
|
677 | QString field_id_str;
|
677 | bool ok; |
678 | bool ok; |
678 | int field_classIdentifer; |
679 | int field_classIdentifer; |
679 | sql_str = tr("select * " |
680 | sql_str = tr("select * " |
680 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì |
681 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì |
681 | ); |
682 | ); |
682 | sql_str.append(class_id); |
683 | sql_str.append(class_id); |
683 | 684 | ||
684 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
685 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
685 | 686 | ||
686 | q.prepare(sql_str); |
687 | q.prepare(sql_str); |
687 | 688 | ||
688 | ok = q.exec(); |
689 | ok = q.exec(); |
689 | if (!ok) { |
690 | if (!ok) { |
690 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
691 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
691 | this, // Ðîäèòåëüñêèé âèäæåò. |
692 | this, // Ðîäèòåëüñêèé âèäæåò. |
692 | QObject::tr("Database Error"), // Çàãîëîâîê. |
693 | QObject::tr("Database Error"), // Çàãîëîâîê. |
693 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
694 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
694 | }
|
695 | }
|
695 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
696 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
696 | while(q.next()){ |
697 | while(q.next()){ |
697 | 698 | ||
698 | classIdentifer_str = q.value(field_classIdentifer).toString(); |
699 | classIdentifer_str = q.value(field_classIdentifer).toString(); |
699 | result.append(classIdentifer_str); |
700 | result.append(classIdentifer_str); |
700 | }
|
701 | }
|
701 | 702 | ||
702 | return result; |
703 | return result; |
703 | 704 | ||
704 | }
|
705 | }
|
705 | 706 | ||
706 | 707 | ||
707 | QMap <QString, QString> MainWindow::getClassList(){ // ïîëó÷àåì ñïèñîê êëàññîâ |
708 | QMap <QString, QString> MainWindow::getClassList(){ // ïîëó÷àåì ñïèñîê êëàññîâ |
708 | QMap <QString, QString> result_map; |
709 | QMap <QString, QString> result_map; |
709 | QSqlQuery q;
|
710 | QSqlQuery q;
|
710 | QString sql_str;
|
711 | QString sql_str;
|
711 | QString class_name_str, class_id_str;
|
712 | QString class_name_str, class_id_str;
|
712 | 713 | ||
713 | int field_class_id, field_class_name; |
714 | int field_class_id, field_class_name; |
714 | bool ok; |
715 | bool ok; |
715 | sql_str = tr("select * " |
716 | sql_str = tr("select * " |
716 | " from ListOfClasses " //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì |
717 | " from ListOfClasses " //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì |
717 | ); |
718 | ); |
718 | q.prepare(sql_str); |
719 | q.prepare(sql_str); |
719 | ok = q.exec(); |
720 | ok = q.exec(); |
720 | if (!ok) { |
721 | if (!ok) { |
721 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
722 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
722 | this, // Ðîäèòåëüñêèé âèäæåò. |
723 | this, // Ðîäèòåëüñêèé âèäæåò. |
723 | QObject::tr("Database Error"), // Çàãîëîâîê. |
724 | QObject::tr("Database Error"), // Çàãîëîâîê. |
724 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
725 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
725 | return result_map; // åñëè îøèáêà - âîçâðàùàåì ïóñòîé ñïèñîê |
726 | return result_map; // åñëè îøèáêà - âîçâðàùàåì ïóñòîé ñïèñîê |
726 | }
|
727 | }
|
727 | field_class_id = q.record().indexOf(tr("ID")); |
728 | field_class_id = q.record().indexOf(tr("ID")); |
728 | field_class_name = q.record().indexOf(tr("ClassName")); |
729 | field_class_name = q.record().indexOf(tr("ClassName")); |
729 | 730 | ||
730 | while(q.next()){ |
731 | while(q.next()){ |
731 | 732 | ||
732 | class_name_str = q.value(field_class_name).toString(); |
733 | class_name_str = q.value(field_class_name).toString(); |
733 | class_id_str = q.value(field_class_id).toString(); |
734 | class_id_str = q.value(field_class_id).toString(); |
734 | result_map[class_id_str] = class_name_str; |
735 | result_map[class_id_str] = class_name_str; |
735 | }
|
736 | }
|
736 | return result_map; |
737 | return result_map; |
737 | }
|
738 | }
|
738 | 739 | ||
739 | 740 | ||
740 | 741 | ||
741 | 742 | ||
742 | 743 | ||
743 | void MainWindow::initComboBox(){ |
744 | void MainWindow::initComboBox(){ |
744 | 745 | ||
745 | 746 | ||
746 | QStringList classesNameList;
|
747 | QStringList classesNameList;
|
747 | QStringList classesID_list;
|
748 | QStringList classesID_list;
|
748 | QStringList tmp_stringList;
|
749 | QStringList tmp_stringList;
|
749 | 750 | ||
750 | 751 | ||
751 | 752 | ||
752 | QString tmp_str;
|
753 | QString tmp_str;
|
753 | 754 | ||
754 | class_list_map = MainWindow::getClassList(); |
755 | class_list_map = MainWindow::getClassList(); |
755 | classesID_list = class_list_map.keys(); |
756 | classesID_list = class_list_map.keys(); |
756 | classesNameList = class_list_map.values(); |
757 | classesNameList = class_list_map.values(); |
757 | QMapIterator<QString, QString> interator(class_list_map); |
758 | QMapIterator<QString, QString> interator(class_list_map); |
758 | // ui->comboBox->addItems(classesID_list);
|
759 | // ui->comboBox->addItems(classesID_list);
|
759 | // ui->comboBox->addItems(classesNameList);
|
760 | // ui->comboBox->addItems(classesNameList);
|
760 | 761 | ||
761 | while (interator.hasNext()) { |
762 | while (interator.hasNext()) { |
762 | interator.next(); |
763 | interator.next(); |
763 | tmp_str = interator.value(); |
764 | tmp_str = interator.value(); |
764 | tmp_str.append(tr(" \t(ID=")); |
765 | tmp_str.append(tr(" \t(ID=")); |
765 | tmp_str.append(interator.key()); |
766 | tmp_str.append(interator.key()); |
766 | tmp_str.append(tr(")")); |
767 | tmp_str.append(tr(")")); |
767 | tmp_stringList << tmp_str; |
768 | tmp_stringList << tmp_str; |
768 | 769 | ||
769 | }
|
770 | }
|
770 | tmp_stringList << tr("íå çàäàíî"); |
771 | tmp_stringList << tr("íå çàäàíî"); |
771 | // int count = ui->comboBox->count();
|
772 | // int count = ui->comboBox->count();
|
772 | 773 | ||
773 | ui->comboBox->clear(); |
774 | ui->comboBox->clear(); |
774 | ui->comboBox->addItems(tmp_stringList); |
775 | ui->comboBox->addItems(tmp_stringList); |
775 | 776 | ||
776 | 777 | ||
777 | }
|
778 | }
|
778 | 779 | ||
779 | 780 | ||
780 | void MainWindow::on_comboBox_currentIndexChanged( int index ){ |
781 | void MainWindow::on_comboBox_currentIndexChanged( int index ){ |
781 | QStringList classesNameList;
|
782 | QStringList classesNameList;
|
782 | QStringList classesID_list;
|
783 | QStringList classesID_list;
|
783 | QString ID_str;
|
784 | QString ID_str;
|
784 | if (index == -1) return;// èíäåêñ íå âåðíûé èëè èíäåêñ ñòðîêè "íå îïðåäåëåíî" |
785 | if (index == -1) return;// èíäåêñ íå âåðíûé èëè èíäåêñ ñòðîêè "íå îïðåäåëåíî" |
785 | if (ui->comboBox->itemText(index) == tr("íå çàäàíî")) return; |
786 | if (ui->comboBox->itemText(index) == tr("íå çàäàíî")) return; |
786 | if (!comboBox_slot_enable) return; // èíäåêñ ïîìåíÿëà ïðîãðàììà, îí íå áûë èçìåíåí âðó÷íóþ, âûõîäèì |
787 | if (!comboBox_slot_enable) return; // èíäåêñ ïîìåíÿëà ïðîãðàììà, îí íå áûë èçìåíåí âðó÷íóþ, âûõîäèì |
787 | int row; |
788 | int row; |
788 | 789 | ||
789 | classesID_list = class_list_map.keys(); |
790 | classesID_list = class_list_map.keys(); |
790 | classesNameList = class_list_map.values(); |
791 | classesNameList = class_list_map.values(); |
791 | ID_str = classesID_list[index]; |
792 | ID_str = classesID_list[index]; |
792 | ui->label->setText(ID_str); |
793 | ui->label->setText(ID_str); |
793 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
794 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
794 | {
|
795 | {
|
795 | row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt(); |
796 | row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt(); |
796 | model_is_build = false; // ÷òîáû íå âûçûâàëîñü ñîáûòèå on_treeWidget_itemChanged |
797 | model_is_build = false; // ÷òîáû íå âûçûâàëîñü ñîáûòèå on_treeWidget_itemChanged |
797 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row); |
798 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row); |
798 | model_is_build = true; // òåïåðü ïóñòü âûçûâàåòñÿ |
799 | model_is_build = true; // òåïåðü ïóñòü âûçûâàåòñÿ |
799 | QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); // |
800 | QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); // |
800 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str)); |
801 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str)); |
801 | }
|
802 | }
|
802 | getDatabaseData(); |
803 | getDatabaseData(); |
803 | 804 | ||
804 | 805 | ||
805 | }
|
806 | }
|
806 | 807 | ||
807 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
808 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
808 | int i; |
809 | int i; |
809 | i++; |
810 | i++; |
810 | QTreeWidgetItem * item_tmp; |
811 | QTreeWidgetItem * item_tmp; |
811 | QString mdl_str;
|
812 | QString mdl_str;
|
812 | QString row; // íîìåð ñòðîêè â òàáëèöå ìîäåëåé, ñîîòâåòñòâóþùèé èçìåíåííîé ìîäåëå |
813 | QString row; // íîìåð ñòðîêè â òàáëèöå ìîäåëåé, ñîîòâåòñòâóþùèé èçìåíåííîé ìîäåëå |
813 | QList <QTreeWidgetItem *> mdl_itm_list; |
814 | QList <QTreeWidgetItem *> mdl_itm_list; |
814 | QList <int> rows_list; |
815 | QList <int> rows_list; |
815 | 816 | ||
816 | 817 | ||
817 | if ((column) == 0 && (model_is_build)) { |
818 | if ((column) == 0 && (model_is_build)) { |
818 | // if (!model_is_build) return; // ìîäåëü åù¸ íå ïîñòðîåíà
|
819 | // if (!model_is_build) return; // ìîäåëü åù¸ íå ïîñòðîåíà
|
819 | 820 | ||
820 | mdl_itm_list = models_items.values(); |
821 | mdl_itm_list = models_items.values(); |
821 | rows_list = models_items.keys(); |
822 | rows_list = models_items.keys(); |
822 | row= item->text(4); |
823 | row= item->text(4); |
823 | 824 | ||
824 | 825 | ||
825 | if ( mdl_itm_list.indexOf(item) != -1){ // èçìåí¸í êîðíåâîé èòåì (ñàìà ìîäåëü) |
826 | if ( mdl_itm_list.indexOf(item) != -1){ // èçìåí¸í êîðíåâîé èòåì (ñàìà ìîäåëü) |
826 | if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1)); |
827 | if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1)); |
827 | else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0)); |
828 | else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0)); |
828 | }
|
829 | }
|
829 | 830 | ||
830 | 831 | ||
831 | 832 | ||
832 | 833 | ||
833 | if (!row.isEmpty()){ |
834 | if (!row.isEmpty()){ |
834 | 835 | ||
835 | 836 | ||
836 | int row_int; |
837 | int row_int; |
837 | row_int = QVariant(row).toInt(); |
838 | row_int = QVariant(row).toInt(); |
838 | if (rows_list.indexOf(row_int) != -1) |
839 | if (rows_list.indexOf(row_int) != -1) |
839 | {
|
840 | {
|
840 | item_tmp = models_items[row_int]; |
841 | item_tmp = models_items[row_int]; |
841 | mdl_str = MainWindow::creatModelString(item_tmp); |
842 | mdl_str = MainWindow::creatModelString(item_tmp); |
842 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str)); |
843 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str)); |
843 | }
|
844 | }
|
844 | 845 | ||
845 | 846 | ||
846 | }
|
847 | }
|
847 | 848 | ||
848 | 849 | ||
849 | }
|
850 | }
|
850 | 851 | ||
851 | /*
|
852 | /*
|
852 | QTreeWidgetItem * item_tmp;
|
853 | QTreeWidgetItem * item_tmp;
|
853 | item_tmp = item;
|
854 | item_tmp = item;
|
854 | while (item_tmp ){
|
855 | while (item_tmp ){
|
855 | item_tmp = item_tmp->parent();
|
856 | item_tmp = item_tmp->parent();
|
856 | }
|
857 | }
|
857 | */
|
858 | */
|
858 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
859 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
859 | 860 | ||
860 | 861 | ||
861 | }
|
862 | }
|
862 | 863 | ||
863 | 864 | ||
864 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
865 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
865 | int i; |
866 | int i; |
866 | i++; |
867 | i++; |
867 | if (root_items_list.indexOf(item) != -1) { // Åñëè âûáðàííûé èòåì ñîäåðæèò íàçâàíèå ìîäåëè |
868 | if (root_items_list.indexOf(item) != -1) { // Åñëè âûáðàííûé èòåì ñîäåðæèò íàçâàíèå ìîäåëè |
868 | QStringList classesNameList;
|
869 | QStringList classesNameList;
|
869 | QStringList classesID_list;
|
870 | QStringList classesID_list;
|
870 | 871 | ||
871 | ui->pushButton_9->setEnabled(false); |
872 | ui->pushButton_9->setEnabled(false); |
872 | ui->pushButton_10->setEnabled(false); |
873 | ui->pushButton_10->setEnabled(false); |
873 | ui->pushButton_11->setEnabled(false); |
874 | ui->pushButton_11->setEnabled(false); |
874 | ui->pushButton_12->setEnabled(false); |
875 | ui->pushButton_12->setEnabled(false); |
875 | // ui->tableView->reset();
|
876 | // ui->tableView->reset();
|
876 | // MainWindow::filtr_model->clear();
|
877 | // MainWindow::filtr_model->clear();
|
877 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
878 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
878 | delete filter_model; |
879 | delete filter_model; |
879 | 880 | ||
880 | filter_model = new QSqlTableModel(); |
881 | filter_model = new QSqlTableModel(); |
881 | /// filter_model = new MyModel();
|
882 | /// filter_model = new MyModel();
|
882 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
883 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
883 | 884 | ||
884 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
885 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
885 | int index; |
886 | int index; |
886 | classesID_list = class_list_map.keys(); |
887 | classesID_list = class_list_map.keys(); |
887 | classesNameList = class_list_map.values(); |
888 | classesNameList = class_list_map.values(); |
888 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // åñëè ìîäåëü íå ïóñòàÿ, óçíàåì êîðíåâîé êëàññ |
889 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // åñëè ìîäåëü íå ïóñòàÿ, óçíàåì êîðíåâîé êëàññ |
889 | else { // åñëè ïóñòàÿ |
890 | else { // åñëè ïóñòàÿ |
890 | index = classesID_list.count(); |
891 | index = classesID_list.count(); |
891 | comboBox_slot_enable = false; // ÷òîáû ñëîò comboBox íå ìåíÿë ñòðîêó ìîäåëè |
892 | comboBox_slot_enable = false; // ÷òîáû ñëîò comboBox íå ìåíÿë ñòðîêó ìîäåëè |
892 | ui->comboBox->setCurrentIndex(index); |
893 | ui->comboBox->setCurrentIndex(index); |
893 | ui->comboBox->setEnabled(true); |
894 | ui->comboBox->setEnabled(true); |
894 | comboBox_slot_enable = true; |
895 | comboBox_slot_enable = true; |
895 | return; |
896 | return; |
896 | 897 | ||
897 | }
|
898 | }
|
898 | comboBox_slot_enable = false; // ÷òîáû ñëîò comboBox íå ìåíÿë ñòðîêó ìîäåëè |
899 | comboBox_slot_enable = false; // ÷òîáû ñëîò comboBox íå ìåíÿë ñòðîêó ìîäåëè |
899 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
900 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
900 | comboBox_slot_enable = true; |
901 | comboBox_slot_enable = true; |
901 | ui->comboBox->setEnabled(true); |
902 | ui->comboBox->setEnabled(true); |
902 | 903 | ||
903 | 904 | ||
904 | }
|
905 | }
|
905 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true);
|
906 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true);
|
906 | else // âûáðàííûé èòåì ñîäåðæèò íàçâàíèå êëàññà |
907 | else // âûáðàííûé èòåì ñîäåðæèò íàçâàíèå êëàññà |
907 | {
|
908 | {
|
908 | QString class_id;
|
909 | QString class_id;
|
909 | QString model_id;
|
910 | QString model_id;
|
910 | QString filtr_str;
|
911 | QString filtr_str;
|
911 | QString inctance;
|
912 | QString inctance;
|
912 | QStringList conditionList;
|
913 | QStringList conditionList;
|
913 | class_id = item->text(1); |
914 | class_id = item->text(1); |
914 | model_id = item->text(6); |
915 | model_id = item->text(6); |
915 | inctance = MainWindow::getClassInctance(class_id); |
916 | inctance = MainWindow::getClassInctance(class_id); |
916 | 917 | ||
917 | filtr_str = tr("`Model_ID` = "); |
918 | filtr_str = tr("`Model_ID` = "); |
918 | filtr_str.append(model_id); |
919 | filtr_str.append(model_id); |
919 | filtr_str.append(tr(" AND `Class_ID` = ")); |
920 | filtr_str.append(tr(" AND `Class_ID` = ")); |
920 | filtr_str.append(class_id); |
921 | filtr_str.append(class_id); |
921 | // filtr_str.append(tr("`"));
|
922 | // filtr_str.append(tr("`"));
|
922 | 923 | ||
923 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
924 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
924 | delete filter_model; |
925 | delete filter_model; |
925 | /// filter_model = new MyModel();
|
926 | /// filter_model = new MyModel();
|
926 | 927 | ||
927 | filter_model = new QSqlTableModel(); |
928 | filter_model = new QSqlTableModel(); |
928 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
929 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
929 | 930 | ||
930 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
931 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
931 | filter_model->setTable(tr("Filters")); |
932 | filter_model->setTable(tr("Filters")); |
932 | filter_model->setFilter(filtr_str); |
933 | filter_model->setFilter(filtr_str); |
933 | 934 | ||
934 | 935 | ||
935 | 936 | ||
936 | filter_model->select(); |
937 | filter_model->select(); |
937 | 938 | ||
938 | filter_model->sort(0,Qt::AscendingOrder); |
939 | filter_model->sort(0,Qt::AscendingOrder); |
939 | 940 | ||
940 | ui->tableView_3->setModel(filter_model); |
941 | ui->tableView_3->setModel(filter_model); |
941 | 942 | ||
942 | 943 | ||
943 | ui->tableView_3->hideColumn(0); |
944 | ui->tableView_3->hideColumn(0); |
944 | ui->tableView_3->hideColumn(1); |
945 | ui->tableView_3->hideColumn(1); |
945 | ui->tableView_3->hideColumn(2); |
946 | ui->tableView_3->hideColumn(2); |
946 | 947 | ||
947 | 948 | ||
948 | filterSpinDelegate.setClassID(class_id); |
949 | filterSpinDelegate.setClassID(class_id); |
949 | filterSpinDelegate.getItems(); |
950 | filterSpinDelegate.getItems(); |
950 | ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate); |
951 | ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate); |
951 | 952 | ||
952 | // ui->tableView_3->setItemDelegate();
|
953 | // ui->tableView_3->setItemDelegate();
|
953 | conditionList <<"" << "and" << "or" << "(" << "and (" << "or ("; |
954 | conditionList <<"" << "and" << "or" << "(" << "and (" << "or ("; |
954 | filterConditionDelegate.setItems(conditionList); |
955 | filterConditionDelegate.setItems(conditionList); |
955 | ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate); |
956 | ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate); |
956 | 957 | ||
957 | conditionList.clear(); |
958 | conditionList.clear(); |
958 | conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL"; |
959 | conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL"; |
959 | filterConditionDelegate_1.setItems(conditionList); |
960 | filterConditionDelegate_1.setItems(conditionList); |
960 | ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1); |
961 | ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1); |
961 | 962 | ||
962 | 963 | ||
963 | 964 | ||
964 | 965 | ||
965 | conditionList.clear(); |
966 | conditionList.clear(); |
966 | conditionList <<"" << ")"; |
967 | conditionList <<"" << ")"; |
967 | filterConditionDelegate_2.setItems(conditionList); |
968 | filterConditionDelegate_2.setItems(conditionList); |
968 | ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2); |
969 | ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2); |
969 | 970 | ||
970 | ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate); |
971 | ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate); |
971 | 972 | ||
972 | 973 | ||
973 | 974 | ||
974 | 975 | ||
975 | ui->pushButton_9->setEnabled(true); |
976 | ui->pushButton_9->setEnabled(true); |
976 | ui->pushButton_10->setEnabled(true); |
977 | ui->pushButton_10->setEnabled(true); |
977 | 978 | ||
978 | ui->comboBox->setEnabled(false); |
979 | ui->comboBox->setEnabled(false); |
979 | 980 | ||
980 | 981 | ||
981 | }
|
982 | }
|
982 | }
|
983 | }
|
983 | 984 | ||
984 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // ïîëó÷àåì ñïèñîê ïîëåé êëàññà |
985 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // ïîëó÷àåì ñïèñîê ïîëåé êëàññà |
985 | 986 | ||
986 | }
|
987 | }
|
987 | 988 | ||
988 | 989 | ||
989 | void MainWindow::initListModelsTablle(){ |
990 | void MainWindow::initListModelsTablle(){ |
990 | model_for_ListModelsTable = new QSqlTableModel(); |
991 | model_for_ListModelsTable = new QSqlTableModel(); |
991 | 992 | ||
992 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
993 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
993 | // model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange);
|
994 | // model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange);
|
994 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit); |
995 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit); |
995 | ui->tableView_2->setModel(model_for_ListModelsTable); |
996 | ui->tableView_2->setModel(model_for_ListModelsTable); |
996 | 997 | ||
997 | model_for_ListModelsTable->select(); |
998 | model_for_ListModelsTable->select(); |
998 | 999 | ||
999 | 1000 | ||
1000 | ui->treeWidget->hideColumn(1); |
1001 | ui->treeWidget->hideColumn(1); |
1001 | ui->treeWidget->hideColumn(2); |
1002 | ui->treeWidget->hideColumn(2); |
1002 | ui->treeWidget->hideColumn(3); |
1003 | ui->treeWidget->hideColumn(3); |
1003 | ui->treeWidget->hideColumn(4); |
1004 | ui->treeWidget->hideColumn(4); |
1004 | // ui->treeWidget->hideColumn(5);
|
1005 | // ui->treeWidget->hideColumn(5);
|
1005 | ui->treeWidget->hideColumn(6); |
1006 | ui->treeWidget->hideColumn(6); |
1006 | 1007 | ||
1007 | ui->tableView_2->hideColumn(0); |
1008 | ui->tableView_2->hideColumn(0); |
1008 | ui->tableView_2->hideColumn(2); |
1009 | ui->tableView_2->hideColumn(2); |
1009 | ui->tableView_2->hideColumn(3); |
1010 | ui->tableView_2->hideColumn(3); |
1010 | ui->tableView_2->hideColumn(4); |
1011 | ui->tableView_2->hideColumn(4); |
1011 | 1012 | ||
1012 | ui->tableView_2->resizeColumnsToContents(); |
1013 | ui->tableView_2->resizeColumnsToContents(); |
1013 | ui->tableView_2->setAlternatingRowColors(true); |
1014 | ui->tableView_2->setAlternatingRowColors(true); |
1014 | 1015 | ||
1015 | ui->pushButton_7->setEnabled(false); |
1016 | ui->pushButton_7->setEnabled(false); |
1016 | ui->pushButton_8->setEnabled(false); |
1017 | ui->pushButton_8->setEnabled(false); |
1017 | 1018 | ||
1018 | 1019 | ||
1019 | }
|
1020 | }
|
1020 | 1021 | ||
1021 | void MainWindow::buildReport(bool advanced){ |
1022 | void MainWindow::buildReport(bool advanced){ |
1022 | 1023 | ||
1023 | // QTreeWidgetItem * hitm;
|
1024 | // QTreeWidgetItem * hitm;
|
1024 | 1025 | ||
1025 | // hitm = ui->treeWidget_2->headerItem();
|
1026 | // hitm = ui->treeWidget_2->headerItem();
|
1026 | 1027 | ||
1027 | // int count = root_items_list.count();
|
1028 | // int count = root_items_list.count();
|
1028 | 1029 | ||
1029 | //int count = ui->treeWidget_2->rootIndex();
|
1030 | //int count = ui->treeWidget_2->rootIndex();
|
1030 | 1031 | ||
1031 | 1032 | ||
1032 | doc->clear();//î÷èùàåì äîêóìåíò |
1033 | doc->clear();//î÷èùàåì äîêóìåíò |
1033 | 1034 | ||
1034 | int list_count; |
1035 | int list_count; |
1035 | if (rootItems.isEmpty()) return; |
1036 | if (rootItems.isEmpty()) return; |
1036 | 1037 | ||
1037 | 1038 | ||
1038 | 1039 | ||
1039 | list_count = rootItems.count(); |
1040 | list_count = rootItems.count(); |
1040 | 1041 | ||
1041 | for (int i=0; i < list_count; i++){ |
1042 | for (int i=0; i < list_count; i++){ |
1042 | 1043 | ||
1043 | getReport(rootItems.at(i), advanced); |
1044 | getReport(rootItems.at(i), advanced); |
1044 | 1045 | ||
1045 | 1046 | ||
1046 | 1047 | ||
1047 | }
|
1048 | }
|
1048 | // (bool)QTextDocumentWriter("raport.odt").write(doc);
|
1049 | // (bool)QTextDocumentWriter("raport.odt").write(doc);
|
1049 | }
|
1050 | }
|
1050 | 1051 | ||
1051 | 1052 | ||
1052 | void MainWindow::getReport(QTreeWidgetItem * model_item, bool advanced){ // ñîçäàåò îò÷åò äëÿ êîíêðåòíîé ìîäåëè |
1053 | void MainWindow::getReport(QTreeWidgetItem * model_item, bool advanced){ // ñîçäàåò îò÷åò äëÿ êîíêðåòíîé ìîäåëè |
1053 | 1054 | ||
1054 | 1055 | ||
1055 | // QTextDocument doc;
|
1056 | // QTextDocument doc;
|
1056 | // QTextCursor cursor(&doc);
|
1057 | // QTextCursor cursor(&doc);
|
1057 | QTextCharFormat char_fmt;
|
1058 | QTextCharFormat char_fmt;
|
1058 | bool ok; |
1059 | bool ok; |
1059 | 1060 | ||
1060 | /**************
|
1061 | /**************
|
1061 | 1062 | ||
1062 | // char_fmt.setBackground(Qt::red);
|
1063 | // char_fmt.setBackground(Qt::red);
|
1063 | cursor.insertText(tr("Ì1\n"),char_fmt);
|
1064 | cursor.insertText(tr("Ì1\n"),char_fmt);
|
1064 | QImage img;
|
1065 | QImage img;
|
1065 | ok = img.load("./hdd5.png");
|
1066 | ok = img.load("./hdd5.png");
|
1066 | doc.addResource(QTextDocument::ImageResource, QUrl("myimage"), img);
|
1067 | doc.addResource(QTextDocument::ImageResource, QUrl("myimage"), img);
|
1067 | cursor.insertImage("myimage");
|
1068 | cursor.insertImage("myimage");
|
1068 | cursor.insertText(tr("Æåñòêèé äèñê\n"),char_fmt);
|
1069 | cursor.insertText(tr("Æåñòêèé äèñê\n"),char_fmt);
|
1069 | 1070 | ||
1070 | (bool)QTextDocumentWriter("test.odt").write(&doc);
|
1071 | (bool)QTextDocumentWriter("test.odt").write(&doc);
|
1071 | ***************/
|
1072 | ***************/
|
1072 | 1073 | ||
1073 | QString model_name;
|
1074 | QString model_name;
|
1074 | QString rootClassID;
|
1075 | QString rootClassID;
|
1075 | QString rootClassInctance;
|
1076 | QString rootClassInctance;
|
1076 | QFont font;
|
1077 | QFont font;
|
1077 | QBrush brush;
|
1078 | QBrush brush;
|
1078 | 1079 | ||
1079 | brush.setColor(Qt::darkRed); |
1080 | brush.setColor(Qt::darkRed); |
1080 | char_fmt.setForeground(brush); |
1081 | char_fmt.setForeground(brush); |
1081 | font.setBold(true); |
1082 | font.setBold(true); |
1082 | char_fmt.setFont(font); |
1083 | char_fmt.setFont(font); |
1083 | 1084 | ||
1084 | model_name = model_item->text(0); |
1085 | model_name = model_item->text(0); |
1085 | if (model_item->checkState(0) == false) return; // ìîäåëü íå âûäåëåíà äëÿ îòîáðàæåíèÿ |
1086 | if (model_item->checkState(0) == false) return; // ìîäåëü íå âûäåëåíà äëÿ îòîáðàæåíèÿ |
1086 | 1087 | ||
1087 | 1088 | ||
1088 | newPage(); |
1089 | newPage(); |
1089 | /*******************
|
1090 | /*******************
|
1090 | QTextBlockFormat textFormat;
|
1091 | QTextBlockFormat textFormat;
|
1091 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
|
1092 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
|
1092 | cursor->setBlockFormat(textFormat);
|
1093 | cursor->setBlockFormat(textFormat);
|
1093 | 1094 | ||
1094 | cursor->insertText(tr("Íîâàÿ ñòðàíèöà"));
|
1095 | cursor->insertText(tr("Íîâàÿ ñòðàíèöà"));
|
1095 | cursor->insertBlock();
|
1096 | cursor->insertBlock();
|
1096 | 1097 | ||
1097 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
|
1098 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
|
1098 | cursor->setBlockFormat(textFormat);
|
1099 | cursor->setBlockFormat(textFormat);
|
1099 | ********************/
|
1100 | ********************/
|
1100 | 1101 | ||
1101 | 1102 | ||
1102 | 1103 | ||
1103 | if (!(model_item->childCount() > 0)) return; // ìîäåëü ïóñòà (íå ñîäåðæèò êëàññîâ) |
1104 | if (!(model_item->childCount() > 0)) return; // ìîäåëü ïóñòà (íå ñîäåðæèò êëàññîâ) |
1104 | 1105 | ||
1105 | rootClassID = model_item->child(0)->text(1); |
1106 | rootClassID = model_item->child(0)->text(1); |
1106 | rootClassInctance = getClassInctance(rootClassID); |
1107 | rootClassInctance = getClassInctance(rootClassID); |
1107 | 1108 | ||
1108 | cursor->insertText(model_name, char_fmt); |
1109 | cursor->insertText(model_name, char_fmt); |
1109 | cursor->insertText(tr("\n")); |
1110 | cursor->insertText(tr("\n")); |
1110 | 1111 | ||
1111 | if (model_item->child(0)->checkState(0)) // åñëè â ìîäåëè êîðíåâîé êëàññ âûáðàí äëÿ îòîáðàæåíèÿ (ñòîèò ãàëî÷êà), òî |
1112 | if (model_item->child(0)->checkState(0)) // åñëè â ìîäåëè êîðíåâîé êëàññ âûáðàí äëÿ îòîáðàæåíèÿ (ñòîèò ãàëî÷êà), òî |
1112 | {
|
1113 | {
|
1113 | ///// QTreeWidgetItem * item_tmp;
|
1114 | ///// QTreeWidgetItem * item_tmp;
|
1114 | ///// item_tmp = new QTreeWidgetItem(item); // â äåðåâå, îòîáðàæàþùåì îáúåêòû êëàññîâ, ñîçäàåì íîâûé óçåë
|
1115 | ///// item_tmp = new QTreeWidgetItem(item); // â äåðåâå, îòîáðàæàþùåì îáúåêòû êëàññîâ, ñîçäàåì íîâûé óçåë
|
1115 | ///// item_tmp->setText(0, model_item->child(0)->text(0)); // ñ íàçâàíèåì êëàññà
|
1116 | ///// item_tmp->setText(0, model_item->child(0)->text(0)); // ñ íàçâàíèåì êëàññà
|
1116 | 1117 | ||
1117 | //showClassObjects(item_tmp, model_item->child(0)); // è âûâîäèì âñå îáúåêòû äàííîãî êëàññà
|
1118 | //showClassObjects(item_tmp, model_item->child(0)); // è âûâîäèì âñå îáúåêòû äàííîãî êëàññà
|
1118 | 1119 | ||
1119 | ///// showObjects(item_tmp, model_item->child(0), tr(""));
|
1120 | ///// showObjects(item_tmp, model_item->child(0), tr(""));
|
1120 | printChild(model_item->child(0), tr(""), advanced, 1); |
1121 | printChild(model_item->child(0), tr(""), advanced, 1); |
1121 | 1122 | ||
1122 | }
|
1123 | }
|
1123 | 1124 | ||
1124 | 1125 | ||
1125 | 1126 | ||
1126 | 1127 | ||
1127 | }
|
1128 | }
|
1128 | 1129 | ||
1129 | void MainWindow::printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos){//â ðàïîðò äîáàâëÿåì äî÷åðíèå êëàññû |
1130 | void MainWindow::printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos){//â ðàïîðò äîáàâëÿåì äî÷åðíèå êëàññû |
1130 | QString classID; // èäåíòèôèêàòîð êëàññà |
1131 | QString classID; // èäåíòèôèêàòîð êëàññà |
1131 | QString parentClassID; // èäåíòèôèêàòîð ðîäèòåëüñêîãî êëàññà |
1132 | QString parentClassID; // èäåíòèôèêàòîð ðîäèòåëüñêîãî êëàññà |
1132 | QString pointerField; // èìÿ ïîëÿ-óêàçàòåëÿ íà ðîäèòåëüñêèé êëàññ |
1133 | QString pointerField; // èìÿ ïîëÿ-óêàçàòåëÿ íà ðîäèòåëüñêèé êëàññ |
1133 | QString inctance; // èìÿ òàáëèöû, õðàíèëèùà |
1134 | QString inctance; // èìÿ òàáëèöû, õðàíèëèùà |
1134 | QString className; // èìÿ êëàññà |
1135 | QString className; // èìÿ êëàññà |
1135 | QString modelID; // èäåíòèôèêàòîð ìîäåëè |
1136 | QString modelID; // èäåíòèôèêàòîð ìîäåëè |
1136 | QString add_filtr; // äîïîëíèòåëüíûé ôèëüòð |
1137 | QString add_filtr; // äîïîëíèòåëüíûé ôèëüòð |
1137 | int field_ID; |
1138 | int field_ID; |
1138 | int icon_field_index; |
1139 | int icon_field_index; |
1139 | bool filtr_empty; |
1140 | bool filtr_empty; |
1140 | bool ok; |
1141 | bool ok; |
1141 | QSqlQuery q;
|
1142 | QSqlQuery q;
|
1142 | QString sql_str;
|
1143 | QString sql_str;
|
1143 | QString str_tmp;
|
1144 | QString str_tmp;
|
1144 | QTreeWidgetItem * title_item; |
1145 | QTreeWidgetItem * title_item; |
1145 | 1146 | ||
1146 | QIcon icon;
|
1147 | QIcon icon;
|
1147 | QMap<QString, QString> fieldsTypesList;//çäåñü â êà÷åñòâå êëþ÷å áóäåì õðàíèòü èìåíà ïîëåé, çíà÷åíèÿìè áóäóò èõ òèïû |
1148 | QMap<QString, QString> fieldsTypesList;//çäåñü â êà÷åñòâå êëþ÷å áóäåì õðàíèòü èìåíà ïîëåé, çíà÷åíèÿìè áóäóò èõ òèïû |
1148 | //QList<TField> FieldsList; //ñïèñîê ïîëåé êëàññà
|
1149 | //QList<TField> FieldsList; //ñïèñîê ïîëåé êëàññà
|
1149 | 1150 | ||
1150 | 1151 | ||
1151 | 1152 | ||
1152 | 1153 | ||
1153 | // // // font.setBold(true);
|
1154 | // // // font.setBold(true);
|
1154 | filtr_empty = filtr.isEmpty(); |
1155 | filtr_empty = filtr.isEmpty(); |
1155 | 1156 | ||
1156 | classID = model_item->text(1); |
1157 | classID = model_item->text(1); |
1157 | modelID = model_item->text(6); |
1158 | modelID = model_item->text(6); |
1158 | add_filtr = MainWindow::getFiltrString(modelID, classID); |
1159 | add_filtr = MainWindow::getFiltrString(modelID, classID); |
1159 | 1160 | ||
1160 | 1161 | ||
1161 | icon = model_item->icon(0); |
1162 | icon = model_item->icon(0); |
1162 | 1163 | ||
1163 | parentClassID = model_item->parent()->text(1); |
1164 | parentClassID = model_item->parent()->text(1); |
1164 | 1165 | ||
1165 | pointerField = getPointerFieldName(parentClassID, classID); |
1166 | pointerField = getPointerFieldName(parentClassID, classID); |
1166 | 1167 | ||
1167 | className = model_item->text(0); |
1168 | className = model_item->text(0); |
1168 | inctance = getClassInctance(classID); |
1169 | inctance = getClassInctance(classID); |
1169 | 1170 | ||
1170 | if (!model_item->checkState(0)) return; |
1171 | if (!model_item->checkState(0)) return; |
1171 | 1172 | ||
1172 | 1173 | ||
1173 | 1174 | ||
1174 | 1175 | ||
1175 | QTextCharFormat charFormatItalic, charFormatBase, charFormatItalicBold, charFormatItalicOnly;
|
1176 | QTextCharFormat charFormatItalic, charFormatBase, charFormatItalicBold, charFormatItalicOnly;
|
1176 | QTextTableFormat tableFormat;
|
1177 | QTextTableFormat tableFormat;
|
1177 | 1178 | ||
1178 | 1179 | ||
1179 | // QPen pen;
|
1180 | // QPen pen;
|
1180 | QBrush brush;
|
1181 | QBrush brush;
|
1181 | QFont font;
|
1182 | QFont font;
|
1182 | // pen.setColor(Qt::red);
|
1183 | // pen.setColor(Qt::red);
|
1183 | // charFormatItalic.setTextOutline(pen);
|
1184 | // charFormatItalic.setTextOutline(pen);
|
1184 | 1185 | ||
1185 | //QFont font;
|
1186 | //QFont font;
|
1186 | 1187 | ||
1187 | brush.setColor(Qt::blue); |
1188 | brush.setColor(Qt::blue); |
1188 | 1189 | ||
1189 | font.setItalic(true); |
1190 | font.setItalic(true); |
1190 | 1191 | ||
1191 | charFormatItalicOnly.setFont(font); |
1192 | charFormatItalicOnly.setFont(font); |
1192 | //charFormatItalic.setFontItalic(true);
|
1193 | //charFormatItalic.setFontItalic(true);
|
1193 | 1194 | ||
1194 | font.setBold(true);///////////////// |
1195 | font.setBold(true);///////////////// |
1195 | charFormatItalic.setFont(font); |
1196 | charFormatItalic.setFont(font); |
1196 | 1197 | ||
1197 | 1198 | ||
1198 | charFormatItalic.setForeground(brush); |
1199 | charFormatItalic.setForeground(brush); |
1199 | 1200 | ||
1200 | 1201 | ||
1201 | 1202 | ||
1202 | charFormatItalicBold.setFont(font); |
1203 | charFormatItalicBold.setFont(font); |
1203 | charFormatItalicBold.setForeground(brush); |
1204 | charFormatItalicBold.setForeground(brush); |
1204 | 1205 | ||
1205 | 1206 | ||
1206 | 1207 | ||
1207 | //charFormatItalic.setFontWeight(16);
|
1208 | //charFormatItalic.setFontWeight(16);
|
1208 | pos++; |
1209 | pos++; |
1209 | for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1210 | for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1210 | cursor->insertText(className, charFormatItalic); |
1211 | cursor->insertText(className, charFormatItalic); |
1211 | cursor->setCharFormat(charFormatBase); |
1212 | cursor->setCharFormat(charFormatBase); |
1212 | cursor->insertText(tr("\n")); |
1213 | cursor->insertText(tr("\n")); |
1213 | 1214 | ||
1214 | 1215 | ||
1215 | 1216 | ||
1216 | sql_str = tr("select * " |
1217 | sql_str = tr("select * " |
1217 | " from " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà |
1218 | " from " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà |
1218 | ); |
1219 | ); |
1219 | sql_str.append(inctance); |
1220 | sql_str.append(inctance); |
1220 | 1221 | ||
1221 | 1222 | ||
1222 | if (filtr.isEmpty() && (!add_filtr.isEmpty())) // ôèëüòð ïóñòîé, äîïîëíèòåëüíûé ôèëüòð íå ïóñòîé |
1223 | if (filtr.isEmpty() && (!add_filtr.isEmpty())) // ôèëüòð ïóñòîé, äîïîëíèòåëüíûé ôèëüòð íå ïóñòîé |
1223 | {
|
1224 | {
|
1224 | filtr.append(tr ("where ")); |
1225 | filtr.append(tr ("where ")); |
1225 | filtr.append(add_filtr); |
1226 | filtr.append(add_filtr); |
1226 | }
|
1227 | }
|
1227 | 1228 | ||
1228 | 1229 | ||
1229 | if (!filtr.isEmpty()) { // åñëè ôèëüòð íå ïóñòîé |
1230 | if (!filtr.isEmpty()) { // åñëè ôèëüòð íå ïóñòîé |
1230 | sql_str.append(tr(" ")); |
1231 | sql_str.append(tr(" ")); |
1231 | sql_str.append(filtr); // äîáàâëÿåì â çàïðîñ ôèëüòð |
1232 | sql_str.append(filtr); // äîáàâëÿåì â çàïðîñ ôèëüòð |
1232 | }
|
1233 | }
|
1233 | 1234 | ||
1234 | q.prepare(sql_str); |
1235 | q.prepare(sql_str); |
1235 | 1236 | ||
1236 | ok = q.exec(); |
1237 | ok = q.exec(); |
1237 | 1238 | ||
1238 | if (!ok) { |
1239 | if (!ok) { |
1239 | QString debug_str;
|
1240 | QString debug_str;
|
1240 | debug_str.append(tr("ôóí showObjects(): Database Error ")); |
1241 | debug_str.append(tr("ôóí showObjects(): Database Error ")); |
1241 | debug_str.append(tr(" õð: ")); |
1242 | debug_str.append(tr(" õð: ")); |
1242 | debug_str.append(inctance); |
1243 | debug_str.append(inctance); |
1243 | debug_str.append(tr(" ô: ")); |
1244 | debug_str.append(tr(" ô: ")); |
1244 | debug_str.append(filtr); |
1245 | debug_str.append(filtr); |
1245 | debug_str.append(q.lastError().text()); |
1246 | debug_str.append(q.lastError().text()); |
1246 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1247 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1247 | this, // Ðîäèòåëüñêèé âèäæåò. |
1248 | this, // Ðîäèòåëüñêèé âèäæåò. |
1248 | QObject::tr("ôóíêöèÿ showObjects(): Database Error"), // Çàãîëîâîê. |
1249 | QObject::tr("ôóíêöèÿ showObjects(): Database Error"), // Çàãîëîâîê. |
1249 | debug_str |
1250 | debug_str |
1250 | // q.lastError().text()
|
1251 | // q.lastError().text()
|
1251 | ); // Òåêñò ñîîáùåíèÿ. |
1252 | ); // Òåêñò ñîîáùåíèÿ. |
1252 | return; |
1253 | return; |
1253 | }
|
1254 | }
|
1254 | 1255 | ||
1255 | field_ID = q.record().indexOf(tr("ID")); |
1256 | field_ID = q.record().indexOf(tr("ID")); |
1256 | 1257 | ||
1257 | icon_field_index = q.record().indexOf(tr("Icon")); |
1258 | icon_field_index = q.record().indexOf(tr("Icon")); |
1258 | 1259 | ||
1259 | int k=0; |
1260 | int k=0; |
1260 | QStringList fieldsNamesList;// ñïèñîê èì¸í ïîëåé òàáëèöû |
1261 | QStringList fieldsNamesList;// ñïèñîê èì¸í ïîëåé òàáëèöû |
1261 | QList<TField> FieldsList; //ñïèñîê ïîëåé êëàññà |
1262 | QList<TField> FieldsList; //ñïèñîê ïîëåé êëàññà |
1262 | QMap<QString, TField> fieldsMap;// çäåñü áóäåì â êà÷åñòâå êëþ÷åé õðàíèòü èìåíà ïîëåé, à â êà÷åñòâå çíà÷åíèé - íåïîñðåäñòâåííî ñîîòâåòñòâóþùèå ïîëÿ |
1263 | QMap<QString, TField> fieldsMap;// çäåñü áóäåì â êà÷åñòâå êëþ÷åé õðàíèòü èìåíà ïîëåé, à â êà÷åñòâå çíà÷åíèé - íåïîñðåäñòâåííî ñîîòâåòñòâóþùèå ïîëÿ |
1263 | QMap <QString, QString> fieldsValues;// çäåñü áóäåì õðàíèòü çíà÷åíèÿ ïîëåé, êëþ÷àìè áóäóò ñëóæèòü èìåíà ïîëåé |
1264 | QMap <QString, QString> fieldsValues;// çäåñü áóäåì õðàíèòü çíà÷åíèÿ ïîëåé, êëþ÷àìè áóäóò ñëóæèòü èìåíà ïîëåé |
1264 | FieldsList = getFieldList(classID); // ïîëó÷àåì ñïèñîê ïîëåé |
1265 | FieldsList = getFieldList(classID); // ïîëó÷àåì ñïèñîê ïîëåé |
1265 | 1266 | ||
1266 | 1267 | ||
1267 | 1268 | ||
1268 | 1269 | ||
1269 | 1270 | ||
1270 | if(FieldsList.count()>0){ |
1271 | if(FieldsList.count()>0){ |
1271 | for(int i=0; i < FieldsList.count(); i++){ //ñîñòàâèì ïàðû (èìÿ ïîëÿ-òèï ïîëÿ) |
1272 | for(int i=0; i < FieldsList.count(); i++){ //ñîñòàâèì ïàðû (èìÿ ïîëÿ-òèï ïîëÿ) |
1272 | fieldsTypesList.insert(FieldsList.at(i).FieldName, FieldsList.at(i).FieldType); |
1273 | fieldsTypesList.insert(FieldsList.at(i).FieldName, FieldsList.at(i).FieldType); |
1273 | fieldsMap.insert(FieldsList.at(i).FieldName, FieldsList.at(i)); |
1274 | fieldsMap.insert(FieldsList.at(i).FieldName, FieldsList.at(i)); |
1274 | }
|
1275 | }
|
1275 | 1276 | ||
1276 | // fieldsNamesList = fieldsTypesList.keys(); // ïîëó÷èì ñïèñîê èìåí ïîëåé
|
1277 | // fieldsNamesList = fieldsTypesList.keys(); // ïîëó÷èì ñïèñîê èìåí ïîëåé
|
1277 | }
|
1278 | }
|
1278 | 1279 | ||
1279 | // icon_field_index = fieldsNamesList.indexOf(tr("Icon"));//îïðåäåëèì èíäåêñ ïîëÿ ñ èêîíêîé
|
1280 | // icon_field_index = fieldsNamesList.indexOf(tr("Icon"));//îïðåäåëèì èíäåêñ ïîëÿ ñ èêîíêîé
|
1280 | 1281 | ||
1281 | 1282 | ||
1282 | 1283 | ||
1283 | while(!q.record().fieldName(k).isEmpty()){// ïîêà íå ïåðåáåð¸ì âñå ïîëÿ |
1284 | while(!q.record().fieldName(k).isEmpty()){// ïîêà íå ïåðåáåð¸ì âñå ïîëÿ |
1284 | fieldsNamesList.append(q.record().fieldName(k++)); |
1285 | fieldsNamesList.append(q.record().fieldName(k++)); |
1285 | }
|
1286 | }
|
1286 | 1287 | ||
1287 | 1288 | ||
1288 | //icon_field_index = fieldsNamesList.indexOf(tr("Icon"));//îïðåäåëèì èíäåêñ ïîëÿ ñ èêîíêîé
|
1289 | //icon_field_index = fieldsNamesList.indexOf(tr("Icon"));//îïðåäåëèì èíäåêñ ïîëÿ ñ èêîíêîé
|
1289 | 1290 | ||
1290 | 1291 | ||
1291 | while(q.next()){ |
1292 | while(q.next()){ |
1292 | if (q.record().count() > 1) |
1293 | if (q.record().count() > 1) |
1293 | {
|
1294 | {
|
1294 | QString value_tmp;
|
1295 | QString value_tmp;
|
1295 | QString ID_tmp;
|
1296 | QString ID_tmp;
|
1296 | QString space;
|
1297 | QString space;
|
1297 | 1298 | ||
1298 | // // // // QTreeWidgetItem * itm;
|
1299 | // // // // QTreeWidgetItem * itm;
|
1299 | ID_tmp = q.value(field_ID).toString(); // îïðåäåëÿåì èäåíòèôèêàòîð îáúåêòà |
1300 | ID_tmp = q.value(field_ID).toString(); // îïðåäåëÿåì èäåíòèôèêàòîð îáúåêòà |
1300 | value_tmp = q.value(1).toString(); // îïðåäåëÿåì èìÿ îáúåêòà (äîëæíî õðàíèòüñÿ â ïåðâîì ïîëå) |
1301 | value_tmp = q.value(1).toString(); // îïðåäåëÿåì èìÿ îáúåêòà (äîëæíî õðàíèòüñÿ â ïåðâîì ïîëå) |
1301 | // itm = new QTreeWidgetItem(parent_object_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
|
1302 | // itm = new QTreeWidgetItem(parent_object_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
|
1302 | 1303 | ||
1303 | 1304 | ||
1304 | 1305 | ||
1305 | 1306 | ||
1306 | /***************************
|
1307 | /***************************
|
1307 | itm = new QTreeWidgetItem(title_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
|
1308 | itm = new QTreeWidgetItem(title_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
|
1308 | itm->setText(0, value_tmp);
|
1309 | itm->setText(0, value_tmp);
|
1309 | itm->setText(1, tr("object"));
|
1310 | itm->setText(1, tr("object"));
|
1310 | itm->setText(2, ID_tmp);
|
1311 | itm->setText(2, ID_tmp);
|
1311 | ******************************/
|
1312 | ******************************/
|
1312 | 1313 | ||
1313 | if (icon_field_index != -1){ // åñëè èìååòñÿ ïîëå ñ èêîíêàìè |
1314 | if (icon_field_index != -1){ // åñëè èìååòñÿ ïîëå ñ èêîíêàìè |
1314 | 1315 | ||
1315 | QVariant data;
|
1316 | QVariant data;
|
1316 | QByteArray bytes;
|
1317 | QByteArray bytes;
|
1317 | QPixmap pix;
|
1318 | QPixmap pix;
|
1318 | QIcon icn;
|
1319 | QIcon icn;
|
1319 | QMap <QString, QPixmap> pixmap_map; |
1320 | QMap <QString, QPixmap> pixmap_map; |
1320 | QList <QString> id_list; |
1321 | QList <QString> id_list; |
1321 | QList <QPixmap> pixmap_list; |
1322 | QList <QPixmap> pixmap_list; |
1322 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
1323 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
1323 | if (!pixmap_map.isEmpty()) { |
1324 | if (!pixmap_map.isEmpty()) { |
1324 | id_list = pixmap_map.keys(); |
1325 | id_list = pixmap_map.keys(); |
1325 | pixmap_list = pixmap_map.values(); |
1326 | pixmap_list = pixmap_map.values(); |
1326 | }
|
1327 | }
|
1327 | if (id_list.indexOf(ID_tmp) != -1) { |
1328 | if (id_list.indexOf(ID_tmp) != -1) { |
1328 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
1329 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
1329 | }
|
1330 | }
|
1330 | // data = q.record().value(icon_field_index);
|
1331 | // data = q.record().value(icon_field_index);
|
1331 | // bytes = q.record().value(icon_field_index).toByteArray();
|
1332 | // bytes = q.record().value(icon_field_index).toByteArray();
|
1332 | // if (data.isValid() && (!data.isNull())) {
|
1333 | // if (data.isValid() && (!data.isNull())) {
|
1333 | // if (!bytes.isEmpty()){
|
1334 | // if (!bytes.isEmpty()){
|
1334 | // pix.loadFromData(data.toByteArray());
|
1335 | // pix.loadFromData(data.toByteArray());
|
1335 | // pix.loadFromData(bytes);
|
1336 | // pix.loadFromData(bytes);
|
1336 | 1337 | ||
1337 | 1338 | ||
1338 | if(!pix.isNull()) { |
1339 | if(!pix.isNull()) { |
1339 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
1340 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
1340 | QString fname = value_tmp; |
1341 | QString fname = value_tmp; |
1341 | fname.append(tr(".png")); |
1342 | fname.append(tr(".png")); |
1342 | 1343 | ||
1343 | 1344 | ||
1344 | pix.toImage().save(fname); |
1345 | pix.toImage().save(fname); |
1345 | doc->addResource(QTextDocument::ImageResource, QUrl(fname), pix.toImage()); |
1346 | doc->addResource(QTextDocument::ImageResource, QUrl(fname), pix.toImage()); |
1346 | 1347 | ||
1347 | // for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
|
1348 | // for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
|
1348 | 1349 | ||
1349 | 1350 | ||
1350 | for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1351 | for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1351 | cursor->insertImage(fname); |
1352 | cursor->insertImage(fname); |
1352 | // cursor->insertText(tr("\n"));
|
1353 | // cursor->insertText(tr("\n"));
|
1353 | 1354 | ||
1354 | }
|
1355 | }
|
1355 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1356 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1356 | 1357 | ||
1357 | 1358 | ||
1358 | 1359 | ||
1359 | 1360 | ||
1360 | // // // icn.addPixmap(pix);
|
1361 | // // // icn.addPixmap(pix);
|
1361 | // // // itm->setIcon(0, icn);
|
1362 | // // // itm->setIcon(0, icn);
|
1362 | // }
|
1363 | // }
|
1363 | 1364 | ||
1364 | 1365 | ||
1365 | }
|
1366 | }
|
1366 | 1367 | ||
1367 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1368 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû |
1368 | cursor->insertText( value_tmp); |
1369 | cursor->insertText( value_tmp); |
1369 | cursor->insertText( tr("\n")); |
1370 | cursor->insertText( tr("\n")); |
1370 | 1371 | ||
1371 | 1372 | ||
1372 | 1373 | ||
1373 | // q.first();
|
1374 | // q.first();
|
1374 | 1375 | ||
1375 | 1376 | ||
1376 | if(advanced && (fieldsNamesList.count()>0)){ // åñëè îò÷åò ðàñøèðåííûé |
1377 | if(advanced && (fieldsNamesList.count()>0)){ // åñëè îò÷åò ðàñøèðåííûé |
1377 | 1378 | ||
1378 | QString tmp_string;
|
1379 | QString tmp_string;
|
1379 | sql_str.clear(); |
1380 | sql_str.clear(); |
1380 | 1381 | ||
1381 | // // // QTextTable *table = cursor->insertTable(fieldsNamesList.count()-2, 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
|
1382 | // // // QTextTable *table = cursor->insertTable(fieldsNamesList.count()-2, 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
|
1382 | 1383 | ||
1383 | 1384 | ||
1384 | 1385 | ||
1385 | /************************
|
1386 | /************************
|
1386 | QTextTable *table = cursor->insertTable(fieldsNamesList.count(), 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
|
1387 | QTextTable *table = cursor->insertTable(fieldsNamesList.count(), 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
|
1387 | 1388 | ||
1388 | ************************/
|
1389 | ************************/
|
1389 | 1390 | ||
1390 | 1391 | ||
1391 | 1392 | ||
1392 | 1393 | ||
1393 | 1394 | ||
1394 | 1395 | ||
1395 | 1396 | ||
1396 | 1397 | ||
1397 | 1398 | ||
1398 | 1399 | ||
1399 | // cursor->insertText(tr("Ïðîâåðêà òàáëèöû"));
|
1400 | // cursor->insertText(tr("Ïðîâåðêà òàáëèöû"));
|
1400 | 1401 | ||
1401 | 1402 | ||
1402 | // *cursor = table->cellAt(0,1).firstCursorPosition();
|
1403 | // *cursor = table->cellAt(0,1).firstCursorPosition();
|
1403 | // cursor->insertText(tr("Ïðîâåðêà òàáëèöû 2"));
|
1404 | // cursor->insertText(tr("Ïðîâåðêà òàáëèöû 2"));
|
1404 | // *cursor = table->cellAt(1,1).lastCursorPosition();
|
1405 | // *cursor = table->cellAt(1,1).lastCursorPosition();
|
1405 | // cursor->insertText(tr("Ïðîâåðêà òàáëèöû 4"));
|
1406 | // cursor->insertText(tr("Ïðîâåðêà òàáëèöû 4"));
|
1406 | 1407 | ||
1407 | 1408 | ||
1408 | // cursor->movePosition(QTextCursor::End);
|
1409 | // cursor->movePosition(QTextCursor::End);
|
1409 | 1410 | ||
1410 | 1411 | ||
1411 | 1412 | ||
1412 | //table->cellAt(1,1).firstCursorPosition().insertText(tr("1"));
|
1413 | //table->cellAt(1,1).firstCursorPosition().insertText(tr("1"));
|
1413 | //table->cellAt(1,2).firstCursorPosition().insertText(tr("2"));
|
1414 | //table->cellAt(1,2).firstCursorPosition().insertText(tr("2"));
|
1414 | //table->cellAt(2,1).firstCursorPosition().insertText(tr("3"));
|
1415 | //table->cellAt(2,1).firstCursorPosition().insertText(tr("3"));
|
1415 | 1416 | ||
1416 | //table->cellAt(2,2).firstCursorPosition().insertText(tr("4"));
|
1417 | //table->cellAt(2,2).firstCursorPosition().insertText(tr("4"));
|
1417 | // cursor->insertText(tr("1 \t 2"));
|
1418 | // cursor->insertText(tr("1 \t 2"));
|
1418 | // cursor->insertText(tr("3 \t 4"));
|
1419 | // cursor->insertText(tr("3 \t 4"));
|
1419 | 1420 | ||
1420 | for(int i=0; i < fieldsNamesList.count(); i++) |
1421 | for(int i=0; i < fieldsNamesList.count(); i++) |
1421 | {
|
1422 | {
|
1422 | 1423 | ||
1423 | 1424 | ||
1424 | if (fieldsNamesList.at(i)== tr("Icon") || fieldsNamesList.at(i)== tr("ID")) { tmp_string = tr("íå âîçìîæíî îòîáðàçèòü"); |
1425 | if (fieldsNamesList.at(i)== tr("Icon") || fieldsNamesList.at(i)== tr("ID")) { tmp_string = tr("íå âîçìîæíî îòîáðàçèòü"); |
1425 | continue; |
1426 | continue; |
1426 | }
|
1427 | }
|
1427 | 1428 | ||
1428 | QString fieldType;
|
1429 | QString fieldType;
|
1429 | fieldType = fieldsTypesList.value(fieldsNamesList.at(i)); //îïðåäåëÿåì òèï ïîëÿ |
1430 | fieldType = fieldsTypesList.value(fieldsNamesList.at(i)); //îïðåäåëÿåì òèï ïîëÿ |
1430 | if(fieldType == tr("pointer")) // åñëè òèï ïîëÿ - óêàçàòåëü |
1431 | if(fieldType == tr("pointer")) // åñëè òèï ïîëÿ - óêàçàòåëü |
1431 | {
|
1432 | {
|
1432 | QSqlQuery q_tmp;
|
1433 | QSqlQuery q_tmp;
|
1433 | QString sql_str;
|
1434 | QString sql_str;
|
1434 | // QString val_str;
|
1435 | // QString val_str;
|
1435 | QString parent_class_id;// èäåíòèôèêàòîð êëàññà, íà îáúåêòû êîòîðîãî ññûëàåòñÿ ïîëå |
1436 | QString parent_class_id;// èäåíòèôèêàòîð êëàññà, íà îáúåêòû êîòîðîãî ññûëàåòñÿ ïîëå |
1436 | QString parent_class_inctance; // õðàíèëèùå îáúåêòîâ ðîäèòåëüñêîãî êëàññà |
1437 | QString parent_class_inctance; // õðàíèëèùå îáúåêòîâ ðîäèòåëüñêîãî êëàññà |
1437 | bool ok; |
1438 | bool ok; |
1438 | TField field_tmp;
|
1439 | TField field_tmp;
|
1439 | field_tmp = fieldsMap.value(fieldsNamesList.at(i)); |
1440 | field_tmp = fieldsMap.value(fieldsNamesList.at(i)); |
1440 | parent_class_id = field_tmp.DefaultValue; |
1441 | parent_class_id = field_tmp.DefaultValue; |
1441 | if (parent_class_id.isEmpty()) continue; // íå ñìîãëè îïðåäåëèòü id ðîäèòåëüñêîãî êëàññà |
1442 | if (parent_class_id.isEmpty()) continue; // íå ñìîãëè îïðåäåëèòü id ðîäèòåëüñêîãî êëàññà |
1442 | else parent_class_inctance = getClassInctance(parent_class_id); |
1443 | else parent_class_inctance = getClassInctance(parent_class_id); |
1443 | if (parent_class_inctance.isEmpty()) continue; // íå ñìîãëè îïðåäåëèòü id ðîäèòåëüñêîãî êëàññà |
1444 | if (parent_class_inctance.isEmpty()) continue; // íå ñìîãëè îïðåäåëèòü id ðîäèòåëüñêîãî êëàññà |
1444 | sql_str = tr("select * from `"); |
1445 | sql_str = tr("select * from `"); |
1445 | sql_str.append(parent_class_inctance); |
1446 | sql_str.append(parent_class_inctance); |
1446 | sql_str.append(tr("` where `ID` = '")); |
1447 | sql_str.append(tr("` where `ID` = '")); |
1447 | sql_str.append(q.record().value(i).asString()); |
1448 | sql_str.append(q.record().value(i).asString()); |
1448 | sql_str.append(tr("'")); |
1449 | sql_str.append(tr("'")); |
1449 | ok = q_tmp.prepare(sql_str); |
1450 | ok = q_tmp.prepare(sql_str); |
1450 | ok = q_tmp.exec(); |
1451 | ok = q_tmp.exec(); |
1451 | 1452 | ||
1452 | if (!ok) { |
1453 | if (!ok) { |
1453 | QString debug_str;
|
1454 | QString debug_str;
|
1454 | debug_str.append(tr("ôóí showObjects(): Database Error ")); |
1455 | debug_str.append(tr("ôóí showObjects(): Database Error ")); |
1455 | debug_str.append(tr(" õð: ")); |
1456 | debug_str.append(tr(" õð: ")); |
1456 | debug_str.append(inctance); |
1457 | debug_str.append(inctance); |
1457 | debug_str.append(tr(" ô: ")); |
1458 | debug_str.append(tr(" ô: ")); |
1458 | debug_str.append(filtr); |
1459 | debug_str.append(filtr); |
1459 | debug_str.append(q.lastError().text()); |
1460 | debug_str.append(q.lastError().text()); |
1460 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1461 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1461 | this, // Ðîäèòåëüñêèé âèäæåò. |
1462 | this, // Ðîäèòåëüñêèé âèäæåò. |
1462 | QObject::tr("ôóíêöèÿ showObjects(): Database Error"), // Çàãîëîâîê. |
1463 | QObject::tr("ôóíêöèÿ showObjects(): Database Error"), // Çàãîëîâîê. |
1463 | debug_str |
1464 | debug_str |
1464 | // q.lastError().text()
|
1465 | // q.lastError().text()
|
1465 | ); // Òåêñò ñîîáùåíèÿ. |
1466 | ); // Òåêñò ñîîáùåíèÿ. |
1466 | return; |
1467 | return; |
1467 | }
|
1468 | }
|
1468 | 1469 | ||
1469 | tmp_string.clear(); |
1470 | tmp_string.clear(); |
1470 | while (q_tmp.next()){ |
1471 | while (q_tmp.next()){ |
1471 | tmp_string = q_tmp.record().value(1).asString(); |
1472 | tmp_string = q_tmp.record().value(1).asString(); |
1472 | 1473 | ||
1473 | }
|
1474 | }
|
1474 | 1475 | ||
1475 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// äîáàâëÿåì çíà÷åíèå â ñïèñîê çíà÷åíèé |
1476 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// äîáàâëÿåì çíà÷åíèå â ñïèñîê çíà÷åíèé |
1476 | 1477 | ||
1477 | continue;// ïåðåõîäèì ê ñëåäóþùåé èíòåðàöèè |
1478 | continue;// ïåðåõîäèì ê ñëåäóþùåé èíòåðàöèè |
1478 | 1479 | ||
1479 | } // äàëüøå åñëè òèï ïîëÿ íå pointer |
1480 | } // äàëüøå åñëè òèï ïîëÿ íå pointer |
1480 | 1481 | ||
1481 | if(fieldType == tr("file")){ // åñëè òèï ïîëÿ - ôàéë, íå áóäåì îòîáðàæàòü |
1482 | if(fieldType == tr("file")){ // åñëè òèï ïîëÿ - ôàéë, íå áóäåì îòîáðàæàòü |
1482 | 1483 | ||
1483 | tmp_string = tr("íå âîçìîæíî îòîáðàçèòü"); |
1484 | tmp_string = tr("íå âîçìîæíî îòîáðàçèòü"); |
1484 | continue; |
1485 | continue; |
1485 | 1486 | ||
1486 | }
|
1487 | }
|
1487 | 1488 | ||
1488 | tmp_string = q.record().value(i).asString(); // ýòî íå èêîíêà, íå ôàéë è íå ïîëå-óêàçàòåëü, ïðîñòî îòîáðàæàåì çíà÷åíèå |
1489 | tmp_string = q.record().value(i).asString(); // ýòî íå èêîíêà, íå ôàéë è íå ïîëå-óêàçàòåëü, ïðîñòî îòîáðàæàåì çíà÷åíèå |
1489 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// äîáàâëÿåì çíà÷åíèå â ñïèñîê çíà÷åíèé |
1490 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// äîáàâëÿåì çíà÷åíèå â ñïèñîê çíà÷åíèé |
1490 | 1491 | ||
1491 | 1492 | ||
1492 | }
|
1493 | }
|
1493 | 1494 | ||
1494 | 1495 | ||
1495 | 1496 | ||
1496 | 1497 | ||
1497 | 1498 | ||
1498 | // for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
|
1499 | // for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
|
1499 | tableFormat.setAlignment(Qt::AlignLeft); |
1500 | tableFormat.setAlignment(Qt::AlignLeft); |
1500 | tableFormat.setBackground(QColor("#e0e0e0")); |
1501 | tableFormat.setBackground(QColor("#e0e0e0")); |
1501 | // tableFormat.setCellPadding(2);
|
1502 | // tableFormat.setCellPadding(2);
|
1502 | // tableFormat.setCellSpacing(4);
|
1503 | // tableFormat.setCellSpacing(4);
|
1503 | tableFormat.setLeftMargin(pos*7); |
1504 | tableFormat.setLeftMargin(pos*7); |
1504 | tableFormat.setBorder(1); |
1505 | tableFormat.setBorder(1); |
1505 | tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); |
1506 | tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); |
1506 | 1507 | ||
1507 | QTextTable *table = cursor->insertTable(fieldsValues.count(), 2, tableFormat);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà) |
1508 | QTextTable *table = cursor->insertTable(fieldsValues.count(), 2, tableFormat);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà) |
1508 | // table->setFormat(tableFormat);
|
1509 | // table->setFormat(tableFormat);
|
1509 | 1510 | ||
1510 | 1511 | ||
1511 | for(int i=0; i < fieldsValues.count(); i++){ // ïðîïóñòèì ïîëÿ: ID è ïîëå, ñîäåðæàùåå èìÿ îáúåêòà (îíî è òàê óæå îòîáðàæåíî) |
1512 | for(int i=0; i < fieldsValues.count(); i++){ // ïðîïóñòèì ïîëÿ: ID è ïîëå, ñîäåðæàùåå èìÿ îáúåêòà (îíî è òàê óæå îòîáðàæåíî) |
1512 | QStringList keys_list = fieldsValues.keys(); |
1513 | QStringList keys_list = fieldsValues.keys(); |
1513 | QStringList values_list = fieldsValues.values(); |
1514 | QStringList values_list = fieldsValues.values(); |
1514 | *cursor = table->cellAt(i,0).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö ïåðâûé |
1515 | *cursor = table->cellAt(i,0).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö ïåðâûé |
1515 | cursor->insertText(keys_list.at(i), charFormatItalicOnly);//ñþäà çàíîñèì èìÿ ïîëÿ |
1516 | cursor->insertText(keys_list.at(i), charFormatItalicOnly);//ñþäà çàíîñèì èìÿ ïîëÿ |
1516 | *cursor = table->cellAt(i,1).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö âòîðîé |
1517 | *cursor = table->cellAt(i,1).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö âòîðîé |
1517 | cursor->insertText(values_list.at(i));//ñþäà çàíîñèì èìÿ ïîëÿ |
1518 | cursor->insertText(values_list.at(i));//ñþäà çàíîñèì èìÿ ïîëÿ |
1518 | }
|
1519 | }
|
1519 | 1520 | ||
1520 | // table->setFormat(tableFormat);
|
1521 | // table->setFormat(tableFormat);
|
1521 | cursor->movePosition(QTextCursor::End);//âûõîäèì èç òàáëèöû |
1522 | cursor->movePosition(QTextCursor::End);//âûõîäèì èç òàáëèöû |
1522 | cursor->insertText( tr("\n")); |
1523 | cursor->insertText( tr("\n")); |
1523 | 1524 | ||
1524 | 1525 | ||
1525 | 1526 | ||
1526 | /******************************
|
1527 | /******************************
|
1527 | 1528 | ||
1528 | table = cursor->insertTable(fieldsNamesList.count(), 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
|
1529 | table = cursor->insertTable(fieldsNamesList.count(), 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
|
1529 | 1530 | ||
1530 | for(int i=2; i < fieldsNamesList.count(); i++){ // ïðîïóñòèì ïîëÿ: ID è ïîëå, ñîäåðæàùåå èìÿ îáúåêòà (îíî è òàê óæå îòîáðàæåíî)
|
1531 | for(int i=2; i < fieldsNamesList.count(); i++){ // ïðîïóñòèì ïîëÿ: ID è ïîëå, ñîäåðæàùåå èìÿ îáúåêòà (îíî è òàê óæå îòîáðàæåíî)
|
1531 | // if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // åñëè ýòî íå èêîíêà, òî ñ÷èòûâàåì çíà÷åíèå êàê ñòðîêó
|
1532 | // if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // åñëè ýòî íå èêîíêà, òî ñ÷èòûâàåì çíà÷åíèå êàê ñòðîêó
|
1532 | if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // åñëè ýòî íå èêîíêà, òî ñ÷èòûâàåì çíà÷åíèå êàê ñòðîêó
|
1533 | if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // åñëè ýòî íå èêîíêà, òî ñ÷èòûâàåì çíà÷åíèå êàê ñòðîêó
|
1533 | 1534 | ||
1534 | 1535 | ||
1535 | else tmp_string = tr("íåâîçìîæíî îòîáðàçèòü");
|
1536 | else tmp_string = tr("íåâîçìîæíî îòîáðàçèòü");
|
1536 | //// if (i !=icon_field_index) {
|
1537 | //// if (i !=icon_field_index) {
|
1537 | for(int i=0; i<pos+2; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
|
1538 | for(int i=0; i<pos+2; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
|
1538 | *cursor = table->cellAt(i-2,0).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö ïåðâûé
|
1539 | *cursor = table->cellAt(i-2,0).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö ïåðâûé
|
1539 | cursor->insertText( fieldsNamesList.at(i));//ñþäà çàíîñèì èìÿ ïîëÿ
|
1540 | cursor->insertText( fieldsNamesList.at(i));//ñþäà çàíîñèì èìÿ ïîëÿ
|
1540 | *cursor = table->cellAt(i-2,1).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö âòîðîé
|
1541 | *cursor = table->cellAt(i-2,1).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö âòîðîé
|
1541 | //cursor->insertText( tr(":\t"));
|
1542 | //cursor->insertText( tr(":\t"));
|
1542 | 1543 | ||
1543 | cursor->insertText(tmp_string);//ñþäà çíà÷åíèå ïîëÿ
|
1544 | cursor->insertText(tmp_string);//ñþäà çíà÷åíèå ïîëÿ
|
1544 | // cursor->insertText( tr("\n"));
|
1545 | // cursor->insertText( tr("\n"));
|
1545 | }
|
1546 | }
|
1546 | 1547 | ||
1547 | //// }
|
1548 | //// }
|
1548 | 1549 | ||
1549 | 1550 | ||
1550 | 1551 | ||
1551 | 1552 | ||
1552 | 1553 | ||
1553 | 1554 | ||
1554 | 1555 | ||
1555 | 1556 | ||
1556 | 1557 | ||
1557 | 1558 | ||
1558 | cursor->movePosition(QTextCursor::End);//âûõîäèì èç òàáëèöû
|
1559 | cursor->movePosition(QTextCursor::End);//âûõîäèì èç òàáëèöû
|
1559 | cursor->insertText( tr("\n"));
|
1560 | cursor->insertText( tr("\n"));
|
1560 | 1561 | ||
1561 | *********************************/
|
1562 | *********************************/
|
1562 | 1563 | ||
1563 | }
|
1564 | }
|
1564 | 1565 | ||
1565 | 1566 | ||
1566 | 1567 | ||
1567 | /********************************************************
|
1568 | /********************************************************
|
1568 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
|
1569 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
|
1569 | cursor->setBlockFormat(textFormat);
|
1570 | cursor->setBlockFormat(textFormat);
|
1570 | 1571 | ||
1571 | cursor->insertText(tr("Íîâàÿ ñòðàíèöà "));
|
1572 | cursor->insertText(tr("Íîâàÿ ñòðàíèöà "));
|
1572 | cursor->insertBlock();
|
1573 | cursor->insertBlock();
|
1573 | 1574 | ||
1574 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
|
1575 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
|
1575 | cursor->setBlockFormat(textFormat);
|
1576 | cursor->setBlockFormat(textFormat);
|
1576 | **********************************************************/
|
1577 | **********************************************************/
|
1577 | 1578 | ||
1578 | 1579 | ||
1579 | // itm->setIcon(0, icon);
|
1580 | // itm->setIcon(0, icon);
|
1580 | 1581 | ||
1581 | 1582 | ||
1582 | for (int i=0; i < model_item->childCount(); i++) // ïðîâåðÿåì, åñòü ëè ó êëàññà äî÷åðíèå êëàññû |
1583 | for (int i=0; i < model_item->childCount(); i++) // ïðîâåðÿåì, åñòü ëè ó êëàññà äî÷åðíèå êëàññû |
1583 | {
|
1584 | {
|
1584 | QTreeWidgetItem * model_item_tmp; // åñëè åñòü |
1585 | QTreeWidgetItem * model_item_tmp; // åñëè åñòü |
1585 | QString pointer_name;
|
1586 | QString pointer_name;
|
1586 | QString filtr_tmp;
|
1587 | QString filtr_tmp;
|
1587 | bool pointer_isEmpty; |
1588 | bool pointer_isEmpty; |
1588 | model_item_tmp = model_item->child(i); // îòîáðàæàåì îáúåêòû äî÷åðíèõ êëàññîâ |
1589 | model_item_tmp = model_item->child(i); // îòîáðàæàåì îáúåêòû äî÷åðíèõ êëàññîâ |
1589 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
1590 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
1590 | // // // // itm->setText(4, pointer_name);
|
1591 | // // // // itm->setText(4, pointer_name);
|
1591 | 1592 | ||
1592 | // title_item->setText(4, pointer_name);
|
1593 | // title_item->setText(4, pointer_name);
|
1593 | 1594 | ||
1594 | 1595 | ||
1595 | pointer_isEmpty = pointer_name.isEmpty(); |
1596 | pointer_isEmpty = pointer_name.isEmpty(); |
1596 | filtr_tmp = tr("where "); |
1597 | filtr_tmp = tr("where "); |
1597 | filtr_tmp.append(tr("`")); |
1598 | filtr_tmp.append(tr("`")); |
1598 | filtr_tmp.append(pointer_name); |
1599 | filtr_tmp.append(pointer_name); |
1599 | filtr_tmp.append(tr("` = '")); |
1600 | filtr_tmp.append(tr("` = '")); |
1600 | filtr_tmp.append(ID_tmp); |
1601 | filtr_tmp.append(ID_tmp); |
1601 | filtr_tmp.append(tr("'")); |
1602 | filtr_tmp.append(tr("'")); |
1602 | 1603 | ||
1603 | printChild(model_item_tmp, filtr_tmp, advanced, pos+1); |
1604 | printChild(model_item_tmp, filtr_tmp, advanced, pos+1); |
1604 | 1605 | ||
1605 | // // // // showObjects(itm, model_item_tmp, filtr_tmp);
|
1606 | // // // // showObjects(itm, model_item_tmp, filtr_tmp);
|
1606 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp);
|
1607 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp);
|
1607 | 1608 | ||
1608 | }
|
1609 | }
|
1609 | // if(pos==2) newPage(); // åñëè ýòî êîðíåâîé êëàññ, âñòàâèì ðàçäåë ñòðàíèöû
|
1610 | // if(pos==2) newPage(); // åñëè ýòî êîðíåâîé êëàññ, âñòàâèì ðàçäåë ñòðàíèöû
|
1610 | 1611 | ||
1611 | }
|
1612 | }
|
1612 | 1613 | ||
1613 | }
|
1614 | }
|
1614 | 1615 | ||
1615 | 1616 | ||
1616 | 1617 | ||
1617 | 1618 | ||
1618 | 1619 | ||
1619 | 1620 | ||
1620 | 1621 | ||
1621 | 1622 | ||
1622 | 1623 | ||
1623 | 1624 | ||
1624 | }
|
1625 | }
|
1625 | 1626 | ||
1626 | 1627 | ||
1627 | void MainWindow::newPage(int page_number){ //âñòàâëÿåì â äîêóìåíò íîâóþ ñòðàíèöó |
1628 | void MainWindow::newPage(int page_number){ //âñòàâëÿåì â äîêóìåíò íîâóþ ñòðàíèöó |
1628 | 1629 | ||
1629 | QTextBlockFormat textFormat;
|
1630 | QTextBlockFormat textFormat;
|
1630 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
1631 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
1631 | cursor->setBlockFormat(textFormat); |
1632 | cursor->setBlockFormat(textFormat); |
1632 | 1633 | ||
1633 | cursor->insertText(tr("Íîâàÿ ñòðàíèöà %1").arg(page_number)); |
1634 | cursor->insertText(tr("Íîâàÿ ñòðàíèöà %1").arg(page_number)); |
1634 | cursor->insertBlock(); |
1635 | cursor->insertBlock(); |
1635 | 1636 | ||
1636 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
1637 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
1637 | cursor->setBlockFormat(textFormat); |
1638 | cursor->setBlockFormat(textFormat); |
1638 | 1639 | ||
1639 | 1640 | ||
1640 | }
|
1641 | }
|
1641 | void MainWindow::newPage(){ //âñòàâëÿåì â äîêóìåíò íîâóþ ñòðàíèöó |
1642 | void MainWindow::newPage(){ //âñòàâëÿåì â äîêóìåíò íîâóþ ñòðàíèöó |
1642 | 1643 | ||
1643 | QTextBlockFormat textFormat;
|
1644 | QTextBlockFormat textFormat;
|
1644 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
1645 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
1645 | cursor->setBlockFormat(textFormat); |
1646 | cursor->setBlockFormat(textFormat); |
1646 | 1647 | ||
1647 | //cursor->insertText(tr("Íîâàÿ ñòðàíèöà %1").arg(page_number));
|
1648 | //cursor->insertText(tr("Íîâàÿ ñòðàíèöà %1").arg(page_number));
|
1648 | cursor->insertBlock(); |
1649 | cursor->insertBlock(); |
1649 | 1650 | ||
1650 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
1651 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
1651 | cursor->setBlockFormat(textFormat); |
1652 | cursor->setBlockFormat(textFormat); |
1652 | 1653 | ||
1653 | 1654 | ||
1654 | }
|
1655 | }
|
1655 | 1656 | ||
1656 | QList<TField> MainWindow::getFieldList(QString class_id){// ïîëó÷àåì ñïèñîê ïîëåé êëàññà |
1657 | QList<TField> MainWindow::getFieldList(QString class_id){// ïîëó÷àåì ñïèñîê ïîëåé êëàññà |
1657 | 1658 | ||
1658 | QSqlQuery q;
|
1659 | QSqlQuery q;
|
1659 | QString sql_str;
|
1660 | QString sql_str;
|
1660 | QList<TField> result_list; |
1661 | QList<TField> result_list; |
1661 | 1662 | ||
1662 | int field_id, field_name, field_alias, field_type, field_default_value, field_classIdentifer, field_comment; |
1663 | int field_id, field_name, field_alias, field_type, field_default_value, field_classIdentifer, field_comment; |
1663 | 1664 | ||
1664 | bool ok; |
1665 | bool ok; |
1665 | sql_str = tr("select * " |
1666 | sql_str = tr("select * " |
1666 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`ClassIdentifer` = " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà |
1667 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`ClassIdentifer` = " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà |
1667 | ); |
1668 | ); |
1668 | 1669 | ||
1669 | sql_str.append(tr("'")); |
1670 | sql_str.append(tr("'")); |
1670 | sql_str.append(class_id); |
1671 | sql_str.append(class_id); |
1671 | sql_str.append(tr("' ")); |
1672 | sql_str.append(tr("' ")); |
1672 | ok = q.prepare(sql_str); |
1673 | ok = q.prepare(sql_str); |
1673 | 1674 | ||
1674 | ok = q.exec(); |
1675 | ok = q.exec(); |
1675 | if (!ok) { |
1676 | if (!ok) { |
1676 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1677 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
1677 | this, // Ðîäèòåëüñêèé âèäæåò. |
1678 | this, // Ðîäèòåëüñêèé âèäæåò. |
1678 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1679 | QObject::tr("Database Error"), // Çàãîëîâîê. |
1679 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
1680 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ. |
1680 | return result_list; |
1681 | return result_list; |
1681 | }
|
1682 | }
|
1682 | 1683 | ||
1683 | 1684 | ||
1684 | field_id = q.record().indexOf(tr("ID")); |
1685 | field_id = q.record().indexOf(tr("ID")); |
1685 | field_name = q.record().indexOf(tr("FieldName")); |
1686 | field_name = q.record().indexOf(tr("FieldName")); |
1686 | field_alias = q.record().indexOf(tr("FieldAlias")); |
1687 | field_alias = q.record().indexOf(tr("FieldAlias")); |
1687 | field_type = q.record().indexOf(tr("FieldType")); |
1688 | field_type = q.record().indexOf(tr("FieldType")); |
1688 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
1689 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
1689 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
1690 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
1690 | field_comment = q.record().indexOf(tr("Comment")); |
1691 | field_comment = q.record().indexOf(tr("Comment")); |
1691 | 1692 | ||
1692 | while(q.next()){ |
1693 | while(q.next()){ |
1693 | 1694 | ||
1694 | TField field_tmp;
|
1695 | TField field_tmp;
|
1695 | field_tmp.ID = q.value(field_id).toString(); |
1696 | field_tmp.ID = q.value(field_id).toString(); |
1696 | field_tmp.FieldName = q.value(field_name).toString(); |
1697 | field_tmp.FieldName = q.value(field_name).toString(); |
1697 | field_tmp.FieldAlias = q.value(field_alias).toString(); |
1698 | field_tmp.FieldAlias = q.value(field_alias).toString(); |
1698 | field_tmp.FieldType = q.value(field_type).toString(); |
1699 | field_tmp.FieldType = q.value(field_type).toString(); |
1699 | field_tmp.DefaultValue = q.value(field_default_value).toString(); |
1700 | field_tmp.DefaultValue = q.value(field_default_value).toString(); |
1700 | field_tmp.ClassIdentifer = q.value(field_classIdentifer).toString(); |
1701 | field_tmp.ClassIdentifer = q.value(field_classIdentifer).toString(); |
1701 | field_tmp.Comment = q.value(field_comment).toString(); |
1702 | field_tmp.Comment = q.value(field_comment).toString(); |
1702 | result_list << field_tmp; |
1703 | result_list << field_tmp; |
1703 | 1704 | ||
1704 | 1705 | ||
1705 | 1706 | ||
1706 | 1707 | ||
1707 | // parentClassID = q.value(field_default_value).toString();
|
1708 | // parentClassID = q.value(field_default_value).toString();
|
1708 | // parentClassInctance = getClassInctance(parentClassID);
|
1709 | // parentClassInctance = getClassInctance(parentClassID);
|
1709 | // result_map.insert(pointerFieldName, parentClassInctance);
|
1710 | // result_map.insert(pointerFieldName, parentClassInctance);
|
1710 | 1711 | ||
1711 | 1712 | ||
1712 | 1713 | ||
1713 | }
|
1714 | }
|
1714 | 1715 | ||
1715 | return result_list; |
1716 | return result_list; |
1716 | 1717 | ||
1717 | }
|
1718 | }
|
1718 | 1719 |