src/RecipesTree.cpp

Wed, 23 Mar 2022 22:00:28 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 23 Mar 2022 22:00:28 +0100
changeset 81
562ed7d1b74d
child 82
84e5dcab868f
permissions
-rw-r--r--

Added start of the Recipes Tree to select a recipe

81
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * RecipesTree.cpp is part of bmsapp.
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "RecipesTree.h"
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 //#include "EditMisc.h"
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "MainWindow.h"
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include "config.h"
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 #include "bmsapp.h"
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 RecipesTree::RecipesTree(QWidget *parent) : QDialog(parent)
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 qDebug() << "RecipesTree start";
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 gridLayout = new QGridLayout(this);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 treeWidget = new QTreeWidget(this);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 treeWidget->setObjectName(QString::fromUtf8("treeWidget"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 sizePolicy.setHorizontalStretch(0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 sizePolicy.setVerticalStretch(0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 sizePolicy.setHeightForWidth(treeWidget->sizePolicy().hasHeightForWidth());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 treeWidget->setSizePolicy(sizePolicy);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 gridLayout->addWidget(treeWidget, 0, 0, 1, 1);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 listView = new QListView(this);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 listView->setObjectName(QString::fromUtf8("listView"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Expanding);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 sizePolicy1.setHorizontalStretch(0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 sizePolicy1.setVerticalStretch(0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 sizePolicy1.setHeightForWidth(listView->sizePolicy().hasHeightForWidth());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 listView->setSizePolicy(sizePolicy1);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 listView->setMinimumSize(QSize(500, 0));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 gridLayout->addWidget(listView, 0, 1, 2, 1);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 groupBox = new QGroupBox(this);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 groupBox->setObjectName(QString::fromUtf8("groupBox"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Preferred);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 sizePolicy2.setHorizontalStretch(0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 sizePolicy2.setVerticalStretch(0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 sizePolicy2.setHeightForWidth(groupBox->sizePolicy().hasHeightForWidth());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 groupBox->setSizePolicy(sizePolicy2);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 groupBox->setMinimumSize(QSize(0, 0));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 horizontalLayout = new QHBoxLayout(groupBox);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 horizontalLayout->setSpacing(200);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 horizontalLayout->setContentsMargins(0, 0, 0, 0);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 quitButton = new QPushButton(groupBox);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 quitButton->setObjectName(QString::fromUtf8("quitButton"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 quitButton->setText(tr("Quit"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 QIcon icon;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 quitButton->setIcon(icon);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 horizontalLayout->addWidget(quitButton);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 insertButton = new QPushButton(groupBox);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 insertButton->setObjectName(QString::fromUtf8("insertButton"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 insertButton->setText(tr("New"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 QIcon icon3;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 insertButton->setIcon(icon3);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 horizontalLayout->addWidget(insertButton);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 openButton = new QPushButton(groupBox);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 openButton->setObjectName(QString::fromUtf8("openButton"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 openButton->setText(tr("Open"));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 QIcon icon1;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 icon1.addFile(QString::fromUtf8(":icons/silk/cup_go.png"), QSize(), QIcon::Normal, QIcon::Off);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 openButton->setIcon(icon1);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 horizontalLayout->addWidget(openButton);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromRecipesTree()));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 //connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 //connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 // connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 emit refreshTable();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 void RecipesTree::refreshTable()
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 QTreeWidgetItem *st_guide, *st_group, *st_name, *name;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 qDebug() << "RecipesTree reload";
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 treeWidget->setRootIsDecorated(false);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 treeWidget->resizeColumnToContents(2);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 treeWidget->setColumnCount(5);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 treeWidget->setHeaderLabels(QStringList() << "Guide" << "Group" << "Style" << "Recipe" << "Record");
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 QSqlQuery query0;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 query0.prepare("SELECT DISTINCT st_guide FROM recipes ORDER BY st_guide");
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 query0.exec();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 query0.first();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 for (int i = 0; i < query0.size() ; i++) {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 st_guide = new QTreeWidgetItem(treeWidget);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 st_guide->setText(0, query0.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 QSqlQuery query1;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 query1.prepare("SELECT DISTINCT st_letter FROM recipes WHERE st_guide=:guide ORDER BY st_letter");
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 query1.bindValue(":guide", query0.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 query1.exec();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 query1.first();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 for (int j = 0; j < query1.size(); j++) {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 st_group = new QTreeWidgetItem(treeWidget);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 st_group->setText(1, query1.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 st_group->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 st_guide->addChild( st_group );
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 QSqlQuery query2;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 query2.prepare("SELECT DISTINCT st_name FROM recipes WHERE st_guide=:guide AND st_letter=:group ORDER BY st_name");
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 query2.bindValue(":guide", query0.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 query2.bindValue(":group", query1.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 query2.exec();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 query2.first();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 for (int k = 0; k < query2.size(); k++) {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 st_name = new QTreeWidgetItem(treeWidget);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 st_name->setText(2, query2.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 st_group->addChild( st_name );
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 QSqlQuery query3;
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 query3.prepare("SELECT name,record FROM recipes WHERE st_guide=:guide AND st_letter=:group AND st_name=:name ORDER BY name");
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 query3.bindValue(":guide", query0.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 query3.bindValue(":group", query1.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 query3.bindValue(":name", query2.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 query3.exec();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 query3.first();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 for (int l = 0; l < query3.size(); l++) {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 name = new QTreeWidgetItem(treeWidget);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 name->setText(3, query3.value(0).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 name->setText(4, query3.value(1).toString());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 st_name->addChild( name );
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 query3.next();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 // qDebug() << query0.value(0).toString() << query1.value(0).toString() << query2.value(0).toString();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 query2.next();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 query1.next();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 query0.next();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 // treeWidget->expandAll();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 // QSqlQuery query("SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name");
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 // emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 RecipesTree::~RecipesTree() {}
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 void RecipesTree::edit(int recno)
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 // EditMisc dialog(recno, this);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 /* Signal from editor if a refresh is needed */
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 // connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 // dialog.setModal(true);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 // dialog.exec();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 void RecipesTree::on_editButton_clicked()
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 int recno = pb->objectName().toInt();
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 edit(recno);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 void RecipesTree::on_insertButton_clicked()
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 {
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 edit(-1);
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 }
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
562ed7d1b74d Added start of the Recipes Tree to select a recipe
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196

mercurial