Sun, 12 Feb 2023 13:58:36 +0100
In monitor iSpindel: in the chart calculate the ranges, do't let the toolkit do that. Save the path for chart image download in the user settings. In the tooltip for the battery voltage line, also show the remaining battery capacity. In the monitor window show the battery capacity digit instead of allways 0. Updated the translations.
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 | { | |
492
c3a781b4d35b
ChartCarbonate saves the image path in the settings file. Conditional debug messages in a lot on monitor files. In Fermenter monitor details make the status background red if offline. A lot more generic variables instead of continuous expensive calls to MySQL. If fermenter values for the thermometers are not OK, then do not show anything.
Michiel Broek <mbroek@mbse.eu>
parents:
329
diff
changeset
|
31 | #ifdef DEBUG_MONITOR |
310 | 32 | qDebug() << "MoniSpindels start"; |
492
c3a781b4d35b
ChartCarbonate saves the image path in the settings file. Conditional debug messages in a lot on monitor files. In Fermenter monitor details make the status background red if offline. A lot more generic variables instead of continuous expensive calls to MySQL. If fermenter values for the thermometers are not OK, then do not show anything.
Michiel Broek <mbroek@mbse.eu>
parents:
329
diff
changeset
|
33 | #endif |
310 | 34 | |
35 | gridLayout = new QGridLayout(this); | |
36 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
37 | tableiSpindels = new QTableWidget(this); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
38 | tableiSpindels->setObjectName(QString::fromUtf8("tableiSpindels")); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
39 | tableiSpindels->setEnabled(true); |
310 | 40 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
41 | sizePolicy.setHorizontalStretch(0); | |
42 | sizePolicy.setVerticalStretch(0); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
43 | sizePolicy.setHeightForWidth(tableiSpindels->sizePolicy().hasHeightForWidth()); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
44 | tableiSpindels->setSizePolicy(sizePolicy); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
45 | tableiSpindels->setMinimumSize(QSize(1054, 0)); |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
46 | gridLayout->addWidget(tableiSpindels, 0, 0, 1, 1); |
310 | 47 | |
48 | groupBox = new QGroupBox(this); | |
49 | groupBox->setObjectName(QString::fromUtf8("groupBox")); | |
50 | groupBox->setEnabled(true); | |
51 | groupBox->setFlat(false); | |
52 | horizontalLayout = new QHBoxLayout(groupBox); | |
53 | horizontalLayout->setSpacing(6); | |
54 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); | |
55 | horizontalLayout->setContentsMargins(0, 0, 0, 0); | |
56 | quitButton = new QPushButton(groupBox); | |
57 | quitButton->setObjectName(QString::fromUtf8("quitButton")); | |
58 | quitButton->setMinimumSize(QSize(80, 24)); | |
59 | quitButton->setText(tr("Quit")); | |
60 | QIcon icon; | |
61 | icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); | |
62 | quitButton->setIcon(icon); | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
63 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter); |
310 | 64 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
65 | ||
66 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMoniSpindels())); | |
67 | 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
|
68 | connect(parent, SIGNAL(updateiSpindels(QString)), this, SLOT(refreshiSpindels(QString))); |
310 | 69 | emit refreshTable(); |
70 | } | |
71 | ||
72 | ||
73 | void MoniSpindels::refreshTable() | |
74 | { | |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
75 | QTableWidgetItem *item; |
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
76 | |
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 | emit refreshTable(); |
329
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
150 | emit updateiSpindel(data); |
311
449116c083bd
Respond to websocket ping. Added iSpindels monitor overview.
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
151 | } |
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 | |
310 | 154 | void MoniSpindels::edit(int recno) |
155 | { | |
329
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
156 | DetailiSpindel dialog(recno, this); |
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
157 | dialog.setModal(true); |
b57299738980
Added iSpindel detail screen
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
158 | dialog.exec(); |
310 | 159 | } |
160 | ||
161 | ||
162 | void MoniSpindels::on_editButton_clicked() | |
163 | { | |
164 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
165 | int recno = pb->objectName().toInt(); | |
166 | edit(recno); | |
167 | } | |
168 | ||
169 |