src/RecipesTree.cpp

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

mercurial