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