-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillgeneraltable.cpp
395 lines (372 loc) · 14.9 KB
/
fillgeneraltable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#include "mainwindow.h"
#include <QBuffer>
#include <QDebug>
#include <QGuiApplication>
#include <QProgressDialog>
#include <QSqlError>
#include <QStringList>
int queryInsertRow(QSqlDatabase& db, const QString& question, QPixmap* image, int parent_id)
{
int row = 0;
QSqlQuery query(db);
if (image) {
QByteArray byte_array;
QBuffer in_buffer(&byte_array);
in_buffer.open(QIODevice::WriteOnly);
image->save(&in_buffer, "PNG");
query.prepare("INSERT INTO general_0 (question, image, parentId) VALUES (?, ?, ?)");
query.addBindValue(question);
query.addBindValue(byte_array);
query.addBindValue(parent_id);
} else {
query.prepare("INSERT INTO general_0 (question, parentId) VALUES (?, ?)");
query.addBindValue(question);
query.addBindValue(parent_id);
}
if (!query.exec()) {
qDebug() << "Error in SqlTreeModel::addRow:" << query.lastError().text();
query.finish();
return -1;
}
query.exec("SELECT * FROM general_0");
while (query.next()) {
++row;
}
query.finish();
return row;
}
void fillGeneralTable(QSqlDatabase& db, MainWindow* mw)
{
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QProgressDialog progress("Формирование списка общих вопросов...", "Отменить", 0, 10, mw);
progress.setWindowModality(Qt::WindowModal);
progress.setValue(0);
QStringList name_list;
int start = queryInsertRow(db, "Начало", nullptr, 0);
int what_you_want = queryInsertRow(db, "Чего хочешь?", nullptr, start);
int where_to_go = queryInsertRow(db, "Куда пойти?", nullptr, start);
QPixmap* image = new QPixmap(":/base_questions/dacha.jpg");
int dacha = queryInsertRow(db, "Дача", image, start);
delete image;
image = new QPixmap(":/base_questions/fishing.jpg");
int fishing = queryInsertRow(db, "Рыбалка", image, start);
delete image;
image = new QPixmap(":/base_questions/transport.jpg");
int transport = queryInsertRow(db, "Транспорт", image, start);
delete image;
progress.setValue(1);
// ===============================================================
// dacha 31
name_list << "Копать"
<< "Убирать траву"
<< "Делать грядки"
<< "Обрезать кусты"
<< "Чинить забор"
<< "Ремонтировать дом"
<< "Помидоры"
<< "Капуста"
<< "Огурцы"
<< "Баклажаны"
<< "Редис"
<< "Морковь"
<< "Свекла"
<< "Лук"
<< "Картофель"
<< "Петрушка"
<< "Укроп"
<< "Перцы"
<< "Персики"
<< "Яблони"
<< "Груша"
<< "Ранетка"
<< "Цветы"
<< "Лежать в кресле"
<< "Шашлык"
<< "Гости"
<< "Футбол"
<< "Волейбол"
<< "Бадминтон"
<< "Купаться"
<< "Костер";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/dacha/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, dacha);
delete image;
}
name_list.clear();
// ===============================================================
// fishing 8
name_list << "На лодке"
<< "На льду"
<< "Хариус"
<< "Щука"
<< "Окунь"
<< "Форель"
<< "Пелядь"
<< "Сиг";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/fishing/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, fishing);
delete image;
}
name_list.clear();
// ===============================================================
// transport 7
name_list << "Автобус"
<< "Троллейбус"
<< "Автомобиль"
<< "Такси"
<< "Трамвай"
<< "Самолет"
<< "Поезд";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/transport/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, transport);
delete image;
}
name_list.clear();
progress.setValue(2);
// ===============================================================
// what_you_want 19
image = new QPixmap(":/base_questions/WhatYouWant/eat.jpg");
int eat = queryInsertRow(db, "Есть", image, what_you_want);
delete image;
{
// ===============================================================
// eat 6
image = new QPixmap(":/base_questions/WhatYouWant/eat/breakfast.jpg");
int breakfast = queryInsertRow(db, "Завтрак", image, eat);
delete image;
{
// ===============================================================
// breakfast 8
image = new QPixmap(":/base_questions/WhatYouWant/eat/breakfast/porridge.jpg");
int porridge = queryInsertRow(db, "Каша", image, breakfast);
delete image;
{
progress.setValue(3);
// ===============================================================
// porridge 5
name_list << "Манная"
<< "Гречневая"
<< "Рисовая"
<< "Перловая"
<< "Овсяная";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/porridge/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, porridge);
delete image;
}
name_list.clear();
}
name_list << "Салат"
<< "Яичница"
<< "Творог"
<< "Оладьи"
<< "Сосиски"
<< "Жареная колбаса"
<< "Бутерброды";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/breakfast/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, breakfast);
delete image;
}
name_list.clear();
}
image = new QPixmap(":/base_questions/WhatYouWant/eat/fish.jpg");
int fish = queryInsertRow(db, "Блюда из рыбы", image, eat);
delete image;
{
progress.setValue(4);
// ===============================================================
// fish 5
name_list << "Запеченая"
<< "Жареная"
<< "Уха"
<< "Соленая"
<< "Копченая";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/fish/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, fish);
delete image;
}
name_list.clear();
}
image = new QPixmap(":/base_questions/WhatYouWant/eat/mushrooms.jpg");
int mushrooms = queryInsertRow(db, "Блюда с грибами", image, eat);
delete image;
{
// ===============================================================
// mushrooms 6
name_list << "Соленые"
<< "Маринованные"
<< "Жареные"
<< "Сушеные"
<< "Грабной суп"
<< "Пироги с грибами";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/mushrooms/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, mushrooms);
delete image;
}
name_list.clear();
}
image = new QPixmap(":/base_questions/WhatYouWant/eat/breakfast/porridge.jpg");
int porridge = queryInsertRow(db, "Каша", image, eat);
delete image;
{
progress.setValue(5);
// ===============================================================
// porridge 5
name_list << "Манная"
<< "Гречневая"
<< "Рисовая"
<< "Перловая"
<< "Овсяная";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/porridge/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, porridge);
delete image;
}
name_list.clear();
}
image = new QPixmap(":/base_questions/WhatYouWant/eat/potato.jpg");
int potato = queryInsertRow(db, "Блюда из картофеля", image, eat);
delete image;
{
progress.setValue(6);
// ===============================================================
// potato 3
name_list << "Отварной картофель"
<< "Жареный картофель"
<< "Пюре";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/potato/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, potato);
delete image;
}
name_list.clear();
}
image = new QPixmap(":/base_questions/WhatYouWant/eat/soup.jpg");
int soup = queryInsertRow(db, "Суп", image, eat);
delete image;
{
// ===============================================================
// soup 6
name_list << "Куриный"
<< "Борщ"
<< "Щи"
<< "Рассольник"
<< "Грибной"
<< "Окрошка";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/eat/soup/"
+ QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, soup);
delete image;
}
name_list.clear();
}
}
image = new QPixmap(":/base_questions/WhatYouWant/drink.jpg");
int drink = queryInsertRow(db, "Пить", image, what_you_want);
delete image;
progress.setValue(7);
// ===============================================================
// drink 12
name_list << "Молоко"
<< "Чай"
<< "Кофе"
<< "Сок"
<< "Вода"
<< "Какао"
<< "Квас"
<< "Кола"
<< "Вино"
<< "Пиво"
<< "Коньяк"
<< "Водка";
for (int i = 0; i < name_list.count(); i++) {
image
= new QPixmap(":/base_questions/WhatYouWant/drink/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, drink);
delete image;
}
name_list.clear();
name_list << "Чистить зубы"
<< "Расчесаться"
<< "Подстричься"
<< "Побриться"
<< "Принять ванну"
<< "В душ"
<< "Умыться"
<< "Встать"
<< "Сесть"
<< "Лечь"
<< "Одеться"
<< "Раздеться"
<< "Спать"
<< "В туалет"
<< "Измерить давление"
<< "Таблетки"
<< "Телевизор";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhatYouWant/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, what_you_want);
delete image;
}
name_list.clear();
progress.setValue(8);
// ===============================================================
// where_to_go 15
name_list << "В магазин"
<< "На прогулку"
<< "На работу"
<< "К врачу"
<< "В гости"
<< "Спать"
<< "Есть"
<< "Театр"
<< "Кинотеатр"
<< "Цирк"
<< "Пить"
<< "Смотреть телевизор"
<< "Читать"
<< "За грибами";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/WhereToGo/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, where_to_go);
delete image;
}
name_list.clear();
image = new QPixmap(":/base_questions/WhereToGo/fishing.jpg");
fishing = queryInsertRow(db, "На рыбалку", image, where_to_go);
delete image;
{
progress.setValue(9);
// ===============================================================
// fishing 8
name_list << "На лодке"
<< "На льду"
<< "Хариус"
<< "Щука"
<< "Окунь"
<< "Форель"
<< "Пелядь"
<< "Сиг";
for (int i = 0; i < name_list.count(); i++) {
image = new QPixmap(":/base_questions/fishing/" + QString::number(i + 1) + ".jpg");
queryInsertRow(db, name_list[i], image, fishing);
delete image;
}
name_list.clear();
}
progress.setValue(10);
QGuiApplication::restoreOverrideCursor();
}