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