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