|
1 /** |
|
2 * ProfileStyles.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 "ProfileStyles.h" |
|
18 #include "EditProfileStyle.h" |
|
19 #include "../ui/ui_ProfileStyles.h" |
|
20 #include "config.h" |
|
21 #include "bmsapp.h" |
|
22 |
|
23 |
|
24 ProfileStyles::ProfileStyles(QWidget *parent) : QDialog(parent), ui(new Ui::ProfileStyles) |
|
25 { |
|
26 qDebug() << "ProfileStyles start"; |
|
27 |
|
28 ui->setupUi(this); |
|
29 emit refreshTable(); |
|
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Profile Styles").arg(VERSIONSTRING) ); |
|
32 } |
|
33 |
|
34 |
|
35 void ProfileStyles::refreshTable() |
|
36 { |
|
37 QString w; |
|
38 QWidget* pWidget; |
|
39 QLabel *label; |
|
40 QHBoxLayout* pLayout; |
|
41 |
|
42 qDebug() << "ProfileStyles reload"; |
|
43 |
|
44 QSqlQuery query("SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name"); |
|
45 const QStringList labels({tr("Guide"), tr("Gr"), tr("Name"), tr("OG"), tr("OG"), tr("FG"), tr("FG"), |
|
46 tr("IBU"), tr("IBU"), tr("EBC"), tr("EBC"), tr("Co2"), tr("Co2"), tr("ABV"), tr("ABV"), tr("Edit")}); |
|
47 |
|
48 ui->tableStyles->setColumnCount(16); |
|
49 ui->tableStyles->setColumnWidth(0, 100); /* Guide */ |
|
50 ui->tableStyles->setColumnWidth(1, 25); /* Group */ |
|
51 ui->tableStyles->setColumnWidth(2, 300); /* Name */ |
|
52 ui->tableStyles->setColumnWidth(3, 50); /* OG */ |
|
53 ui->tableStyles->setColumnWidth(4, 50); |
|
54 ui->tableStyles->setColumnWidth(5, 50); /* FG */ |
|
55 ui->tableStyles->setColumnWidth(6, 50); |
|
56 ui->tableStyles->setColumnWidth(7, 40); /* IBU */ |
|
57 ui->tableStyles->setColumnWidth(8, 40); |
|
58 ui->tableStyles->setColumnWidth(9, 40); /* EBC */ |
|
59 ui->tableStyles->setColumnWidth(10, 40); |
|
60 ui->tableStyles->setColumnWidth(11, 40); /* Co2 */ |
|
61 ui->tableStyles->setColumnWidth(12, 40); |
|
62 ui->tableStyles->setColumnWidth(13, 40); /* ABV */ |
|
63 ui->tableStyles->setColumnWidth(14, 40); |
|
64 ui->tableStyles->setColumnWidth(15, 80); /* Edit button */ |
|
65 ui->tableStyles->setRowCount(query.size()); |
|
66 ui->tableStyles->setHorizontalHeaderLabels(labels); |
|
67 ui->tableStyles->verticalHeader()->hide(); |
|
68 ui->tableStyles->setFixedSize(1025 + 24, 640); /* Even if this is too large, it works */ |
|
69 |
|
70 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
|
71 rightitem->setTextAlignment(Qt::AlignRight); |
|
72 |
|
73 query.first(); |
|
74 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
|
75 ui->tableStyles->setItem(ridx, 0, new QTableWidgetItem(query.value(5).toString())); /* Guide */ |
|
76 ui->tableStyles->setItem(ridx, 1, new QTableWidgetItem(query.value(4).toString())); /* Goup */ |
|
77 ui->tableStyles->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
|
78 |
|
79 w = QString("%1").arg(query.value(7).toDouble(), 4, 'f', 3, '0' ); /* OG */ |
|
80 QTableWidgetItem *item = new QTableWidgetItem(w); |
|
81 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
82 ui->tableStyles->setItem(ridx, 3, item); |
|
83 |
|
84 w = QString("%1").arg(query.value(8).toDouble(), 4, 'f', 3, '0' ); /* OG */ |
|
85 item = new QTableWidgetItem(w); |
|
86 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
87 ui->tableStyles->setItem(ridx, 4, item); |
|
88 |
|
89 w = QString("%1").arg(query.value(9).toDouble(), 4, 'f', 3, '0' ); /* FG */ |
|
90 item = new QTableWidgetItem(w); |
|
91 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
92 ui->tableStyles->setItem(ridx, 5, item); |
|
93 |
|
94 w = QString("%1").arg(query.value(10).toDouble(), 4, 'f', 3, '0' ); /* FG */ |
|
95 item = new QTableWidgetItem(w); |
|
96 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
97 ui->tableStyles->setItem(ridx, 6, item); |
|
98 |
|
99 w = QString("%1").arg(query.value(11).toDouble(), 1, 'f', 0, '0' ); /* IBU */ |
|
100 item = new QTableWidgetItem(w); |
|
101 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
102 ui->tableStyles->setItem(ridx, 7, item); |
|
103 |
|
104 w = QString("%1").arg(query.value(12).toDouble(), 1, 'f', 0, '0' ); /* IBU */ |
|
105 item = new QTableWidgetItem(w); |
|
106 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
107 ui->tableStyles->setItem(ridx, 8, item); |
|
108 |
|
109 w = QString("%1").arg(query.value(13).toDouble(), 1, 'f', 0, '0' ); /* EBC */ |
|
110 item = new QTableWidgetItem(w); |
|
111 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
112 ui->tableStyles->setItem(ridx, 9, item); |
|
113 |
|
114 w = QString("%1").arg(query.value(14).toDouble(), 1, 'f', 0, '0' ); /* EBC */ |
|
115 item = new QTableWidgetItem(w); |
|
116 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
117 ui->tableStyles->setItem(ridx, 10, item); |
|
118 |
|
119 w = QString("%1").arg(query.value(15).toDouble(), 2, 'f', 1, '0' ); /* Co2 */ |
|
120 item = new QTableWidgetItem(w); |
|
121 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
122 ui->tableStyles->setItem(ridx, 11, item); |
|
123 |
|
124 w = QString("%1").arg(query.value(16).toDouble(), 2, 'f', 1, '0' ); /* Co2 */ |
|
125 item = new QTableWidgetItem(w); |
|
126 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
127 ui->tableStyles->setItem(ridx, 12, item); |
|
128 |
|
129 w = QString("%1").arg(query.value(17).toDouble(), 2, 'f', 1, '0' ); /* ABV */ |
|
130 item = new QTableWidgetItem(w); |
|
131 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
132 ui->tableStyles->setItem(ridx, 13, item); |
|
133 |
|
134 w = QString("%1").arg(query.value(18).toDouble(), 2, 'f', 1, '0' ); /* ABV */ |
|
135 item = new QTableWidgetItem(w); |
|
136 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
137 ui->tableStyles->setItem(ridx, 14, item); |
|
138 |
|
139 /* Add the Edit button */ |
|
140 pWidget = new QWidget(); |
|
141 QPushButton* btn_edit = new QPushButton(); |
|
142 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
|
143 btn_edit->setText(tr("Edit")); |
|
144 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
|
145 pLayout = new QHBoxLayout(pWidget); |
|
146 pLayout->addWidget(btn_edit); |
|
147 pLayout->setContentsMargins(5, 0, 5, 0); |
|
148 pWidget->setLayout(pLayout); |
|
149 ui->tableStyles->setCellWidget(ridx, 15, pWidget); |
|
150 query.next(); |
|
151 } |
|
152 |
|
153 setWindowTitle( QString("BMSapp - %1 - Profile Styles").arg(VERSIONSTRING) ); |
|
154 } |
|
155 |
|
156 |
|
157 ProfileStyles::~ProfileStyles() |
|
158 { |
|
159 qDebug() << "ProfileStyles done"; |
|
160 delete ui; |
|
161 } |
|
162 |
|
163 |
|
164 void ProfileStyles::edit(int recno) |
|
165 { |
|
166 qDebug() << "ProfileStyles edit:" << recno; |
|
167 |
|
168 EditProfileStyle dialog(recno, this); |
|
169 /* Signal from editor if a refresh is needed */ |
|
170 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
|
171 dialog.setModal(true); |
|
172 dialog.exec(); |
|
173 } |
|
174 |
|
175 |
|
176 void ProfileStyles::on_editButton_clicked() |
|
177 { |
|
178 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
179 int recno = pb->objectName().toInt(); |
|
180 qDebug() << Q_FUNC_INFO << recno; |
|
181 edit(recno); |
|
182 } |
|
183 |
|
184 |
|
185 void ProfileStyles::on_insertButton_clicked() |
|
186 { |
|
187 qDebug() << Q_FUNC_INFO; |
|
188 edit(-1); |
|
189 } |
|
190 |
|
191 |
|
192 void ProfileStyles::on_quitButton_clicked() |
|
193 { |
|
194 emit firstWindow(); |
|
195 } |
|
196 |