Fri, 29 Jul 2022 13:12:26 +0200
First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
310 | 1 | /** |
2 | * MoniSpindels.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 "MoniSpindels.h" | |
329
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
18 | #include "DetailiSpindel.h" |
310 | 19 | #include "MainWindow.h" |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
20 | #include "Utils.h" |
310 | 21 | #include "config.h" |
22 | ||
23 | ||
24 | ||
25 | /* | |
26 | * Build the table and buttons on the mainscreen. | |
27 | * Don't use a ui file, do it dynamicly. | |
28 | */ | |
29 | MoniSpindels::MoniSpindels(QWidget *parent) : QDialog(parent) | |
30 | { | |
31 | qDebug() << "MoniSpindels start"; | |
32 | ||
33 | gridLayout = new QGridLayout(this); | |
34 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
35 | tableiSpindels = new QTableWidget(this); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
36 | tableiSpindels->setObjectName(QString::fromUtf8("tableiSpindels")); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
37 | tableiSpindels->setEnabled(true); |
310 | 38 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
39 | sizePolicy.setHorizontalStretch(0); | |
40 | sizePolicy.setVerticalStretch(0); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
41 | sizePolicy.setHeightForWidth(tableiSpindels->sizePolicy().hasHeightForWidth()); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
42 | tableiSpindels->setSizePolicy(sizePolicy); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
43 | tableiSpindels->setMinimumSize(QSize(1054, 0)); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
44 | gridLayout->addWidget(tableiSpindels, 0, 0, 1, 1); |
310 | 45 | |
46 | groupBox = new QGroupBox(this); | |
47 | groupBox->setObjectName(QString::fromUtf8("groupBox")); | |
48 | groupBox->setEnabled(true); | |
49 | groupBox->setFlat(false); | |
50 | horizontalLayout = new QHBoxLayout(groupBox); | |
51 | horizontalLayout->setSpacing(6); | |
52 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); | |
53 | horizontalLayout->setContentsMargins(0, 0, 0, 0); | |
54 | quitButton = new QPushButton(groupBox); | |
55 | quitButton->setObjectName(QString::fromUtf8("quitButton")); | |
56 | quitButton->setMinimumSize(QSize(80, 24)); | |
57 | quitButton->setText(tr("Quit")); | |
58 | QIcon icon; | |
59 | icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); | |
60 | quitButton->setIcon(icon); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
61 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter); |
310 | 62 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
63 | ||
64 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMoniSpindels())); | |
65 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
66 | connect(parent, SIGNAL(updateiSpindels(QString)), this, SLOT(refreshiSpindels(QString))); |
310 | 67 | emit refreshTable(); |
68 | } | |
69 | ||
70 | ||
71 | void MoniSpindels::refreshTable() | |
72 | { | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
73 | QTableWidgetItem *item; |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
74 | |
310 | 75 | qDebug() << "MoniSpindels reload"; |
76 | ||
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
77 | QSqlQuery query("SELECT record,alias,node,online,mode,temperature,gravity,beercode,beername FROM mon_ispindels ORDER BY alias"); |
312
251b9aaae916
Added monitor fermenters overview
Michiel Broek <mbroek@mbse.eu>
parents:
311
diff
changeset
|
78 | const QStringList labels({tr("Unit"), tr("Node"), tr("Status"), tr("Beer"), tr("Temperature"), tr("SG"), tr("Details")}); |
310 | 79 | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
80 | this->tableiSpindels->setColumnCount(7); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
81 | this->tableiSpindels->setColumnWidth(0, 150); /* Alias */ |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
82 | this->tableiSpindels->setColumnWidth(1, 120); /* Node */ |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
83 | this->tableiSpindels->setColumnWidth(2, 100); /* Status */ |
312
251b9aaae916
Added monitor fermenters overview
Michiel Broek <mbroek@mbse.eu>
parents:
311
diff
changeset
|
84 | this->tableiSpindels->setColumnWidth(3, 390); /* Beer */ |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
85 | this->tableiSpindels->setColumnWidth(4, 90); /* Temperature */ |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
86 | this->tableiSpindels->setColumnWidth(5, 90); /* Gravity */ |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
87 | this->tableiSpindels->setColumnWidth(6, 90); /* Edit button */ |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
88 | this->tableiSpindels->setRowCount(query.size()); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
89 | this->tableiSpindels->setHorizontalHeaderLabels(labels); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
90 | this->tableiSpindels->verticalHeader()->hide(); |
310 | 91 | /* Set the widget size to 1054 x 575 in the ui. */ |
92 | ||
93 | query.first(); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
94 | for (int i = 0 ; i < query.size() ; i++ ) { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
95 | this->tableiSpindels->setItem(i, 0, new QTableWidgetItem(query.value("alias").toString())); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
96 | this->tableiSpindels->setItem(i, 1, new QTableWidgetItem(query.value("node").toString())); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
97 | |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
98 | if (query.value("online").toInt()) { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
99 | item = new QTableWidgetItem(QString("Ok")); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
100 | } else { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
101 | item = new QTableWidgetItem(QString("Offline")); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
102 | item->setForeground(QBrush(QColor(Qt::red))); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
103 | } |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
104 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
105 | this->tableiSpindels->setItem(i, 2, item); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
106 | |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
107 | if (query.value("mode").toString() == "ON") { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
108 | item = new QTableWidgetItem(query.value("beercode").toString()+" - "+query.value("beername").toString()); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
109 | this->tableiSpindels->setItem(i, 3, item); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
110 | } else { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
111 | this->tableiSpindels->setItem(i, 3, new QTableWidgetItem(QString(""))); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
112 | } |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
113 | |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
114 | if (query.value("online").toInt()) { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
115 | item = new QTableWidgetItem(QString("%1°C").arg(query.value("temperature").toDouble(), 4, 'f', 3, '0')); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
116 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
117 | this->tableiSpindels->setItem(i, 4, item); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
118 | double sg = Utils::plato_to_sg(query.value("gravity").toDouble()); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
119 | item = new QTableWidgetItem(QString("%1").arg(sg, 5, 'f', 4, '0')); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
120 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
121 | this->tableiSpindels->setItem(i, 5, item); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
122 | } else { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
123 | this->tableiSpindels->setItem(i, 4, new QTableWidgetItem(QString(""))); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
124 | this->tableiSpindels->setItem(i, 5, new QTableWidgetItem(QString(""))); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
125 | } |
310 | 126 | |
127 | /* Add the Edit button */ | |
128 | QWidget* pWidget = new QWidget(); | |
129 | QPushButton* btn_edit = new QPushButton(); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
130 | btn_edit->setObjectName(QString("%1").arg(query.value("record").toString())); /* Send record with the button */ |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
131 | btn_edit->setText(tr("Details")); |
310 | 132 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
133 | QHBoxLayout* pLayout = new QHBoxLayout(pWidget); | |
134 | pLayout->addWidget(btn_edit); | |
135 | pLayout->setContentsMargins(5, 0, 5, 0); | |
136 | pWidget->setLayout(pLayout); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
137 | this->tableiSpindels->setCellWidget(i, 6, pWidget); |
310 | 138 | query.next(); |
139 | } | |
140 | emit setStatus(QString(tr("Total items: %1")).arg(query.size())); | |
141 | } | |
142 | ||
143 | ||
144 | MoniSpindels::~MoniSpindels() {} | |
145 | ||
146 | ||
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
147 | void MoniSpindels::refreshiSpindels(QString data) |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
148 | { |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
149 | qDebug() << "refreshiSpindels" << data; |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
150 | emit refreshTable(); |
329
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
151 | emit updateiSpindel(data); |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
152 | } |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
153 | |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
154 | |
310 | 155 | void MoniSpindels::edit(int recno) |
156 | { | |
329
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
157 | DetailiSpindel dialog(recno, this); |
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
158 | dialog.setModal(true); |
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
159 | dialog.exec(); |
310 | 160 | } |
161 | ||
162 | ||
163 | void MoniSpindels::on_editButton_clicked() | |
164 | { | |
165 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
166 | int recno = pb->objectName().toInt(); | |
167 | edit(recno); | |
168 | } | |
169 | ||
170 |