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