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