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