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