Tue, 05 Mar 2024 10:25:15 +0100
Clear mash measurments when duplicating a product.
310 | 1 | /** |
2 | * MonNodes.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 "MonNodes.h" | |
346
792058058c2f
Added nodes monitor detail screen.
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
18 | #include "DetailNode.h" |
310 | 19 | #include "MainWindow.h" |
20 | #include "config.h" | |
21 | ||
22 | ||
23 | ||
24 | /* | |
25 | * Build the table and buttons on the mainscreen. | |
26 | * Don't use a ui file, do it dynamicly. | |
27 | */ | |
28 | MonNodes::MonNodes(QWidget *parent) : QDialog(parent) | |
29 | { | |
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:
346
diff
changeset
|
30 | #ifdef DEBUG_MONITOR |
310 | 31 | qDebug() << "MonNodes 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:
346
diff
changeset
|
32 | #endif |
310 | 33 | |
34 | gridLayout = new QGridLayout(this); | |
35 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); | |
36 | tableNodes = new QTableWidget(this); | |
37 | tableNodes->setObjectName(QString::fromUtf8("tableNodes")); | |
38 | tableNodes->setEnabled(true); | |
39 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | |
40 | sizePolicy.setHorizontalStretch(0); | |
41 | sizePolicy.setVerticalStretch(0); | |
42 | sizePolicy.setHeightForWidth(tableNodes->sizePolicy().hasHeightForWidth()); | |
43 | tableNodes->setSizePolicy(sizePolicy); | |
44 | tableNodes->setMinimumSize(QSize(974, 0)); | |
45 | gridLayout->addWidget(tableNodes, 0, 0, 1, 1); | |
46 | ||
47 | groupBox = new QGroupBox(this); | |
48 | groupBox->setObjectName(QString::fromUtf8("groupBox")); | |
49 | groupBox->setEnabled(true); | |
50 | groupBox->setFlat(false); | |
51 | horizontalLayout = new QHBoxLayout(groupBox); | |
52 | horizontalLayout->setSpacing(6); | |
53 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); | |
54 | horizontalLayout->setContentsMargins(0, 0, 0, 0); | |
55 | quitButton = new QPushButton(groupBox); | |
56 | quitButton->setObjectName(QString::fromUtf8("quitButton")); | |
57 | quitButton->setMinimumSize(QSize(80, 24)); | |
58 | quitButton->setText(tr("Quit")); | |
59 | QIcon icon; | |
60 | icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); | |
61 | quitButton->setIcon(icon); | |
62 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter); | |
63 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); | |
64 | ||
65 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMonNodes())); | |
66 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); | |
67 | connect(parent, SIGNAL(updateNodes(QString)), this, SLOT(refreshNodes(QString))); | |
68 | emit refreshTable(); | |
69 | } | |
70 | ||
71 | ||
72 | void MonNodes::refreshTable() | |
73 | { | |
74 | QTableWidgetItem *item; | |
75 | ||
76 | QSqlQuery query("SELECT record,node,online,group_id,lastseen,net_address,up_interval FROM mon_nodes ORDER BY node"); | |
312
251b9aaae916
Added monitor fermenters overview
Michiel Broek <mbroek@mbse.eu>
parents:
310
diff
changeset
|
77 | const QStringList labels({tr("Node"), tr("Status"), tr("Group"), tr("Last seen"), tr("Address"), tr("Interval"), tr("Details")}); |
310 | 78 | |
79 | this->tableNodes->setColumnCount(7); | |
80 | this->tableNodes->setColumnWidth(0, 200); /* Node */ | |
81 | this->tableNodes->setColumnWidth(1, 100); /* Status */ | |
82 | this->tableNodes->setColumnWidth(2, 150); /* Group */ | |
83 | this->tableNodes->setColumnWidth(3, 200); /* Last seen */ | |
84 | this->tableNodes->setColumnWidth(4, 120); /* Address */ | |
85 | this->tableNodes->setColumnWidth(5, 90); /* Interval */ | |
86 | this->tableNodes->setColumnWidth(6, 90); /* Edit button */ | |
87 | this->tableNodes->setRowCount(query.size()); | |
88 | this->tableNodes->setHorizontalHeaderLabels(labels); | |
89 | this->tableNodes->verticalHeader()->hide(); | |
90 | /* Set the widget size to 1054 x 575 in the ui. */ | |
91 | ||
92 | query.first(); | |
93 | for (int i = 0 ; i < query.size() ; i++ ) { | |
94 | this->tableNodes->setItem(i, 0, new QTableWidgetItem(query.value("node").toString())); | |
95 | ||
96 | if (query.value("online").toInt()) { | |
97 | item = new QTableWidgetItem(QString("Ok")); | |
98 | } else { | |
99 | item = new QTableWidgetItem(QString("Offline")); | |
100 | item->setForeground(QBrush(QColor(Qt::red))); | |
101 | } | |
102 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
103 | this->tableNodes->setItem(i, 1, item); | |
104 | ||
105 | item = new QTableWidgetItem(query.value("group_id").toString()); | |
106 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
107 | this->tableNodes->setItem(i, 2, item); | |
108 | ||
109 | item = new QTableWidgetItem(query.value("lastseen").toDateTime().toString("dd MMM yyyy HH:mm:ss")); | |
110 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
111 | this->tableNodes->setItem(i, 3, item); | |
112 | ||
113 | this->tableNodes->setItem(i, 4, new QTableWidgetItem(query.value("net_address").toString())); | |
114 | ||
115 | item = new QTableWidgetItem(query.value("up_interval").toString()); | |
116 | item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); | |
117 | this->tableNodes->setItem(i, 5, item); | |
118 | ||
119 | /* Add the Edit button */ | |
120 | QWidget* pWidget = new QWidget(); | |
121 | QPushButton* btn_edit = new QPushButton(); | |
122 | btn_edit->setObjectName(QString("%1").arg(query.value("record").toString())); /* Send record with the button */ | |
123 | btn_edit->setText(tr("Details")); | |
124 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); | |
125 | QHBoxLayout* pLayout = new QHBoxLayout(pWidget); | |
126 | pLayout->addWidget(btn_edit); | |
127 | pLayout->setContentsMargins(5, 0, 5, 0); | |
128 | pWidget->setLayout(pLayout); | |
129 | this->tableNodes->setCellWidget(i, 6, pWidget); | |
130 | query.next(); | |
131 | } | |
132 | emit setStatus(QString(tr("Total items: %1")).arg(query.size())); | |
133 | } | |
134 | ||
135 | ||
136 | MonNodes::~MonNodes() {} | |
137 | ||
138 | ||
139 | void MonNodes::refreshNodes(QString node) | |
140 | { | |
141 | emit refreshTable(); | |
346
792058058c2f
Added nodes monitor detail screen.
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
142 | emit updateNode(node); |
310 | 143 | } |
144 | ||
145 | ||
146 | void MonNodes::edit(int recno) | |
147 | { | |
346
792058058c2f
Added nodes monitor detail screen.
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
148 | DetailNode dialog(recno, this); |
792058058c2f
Added nodes monitor detail screen.
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
149 | dialog.setModal(true); |
792058058c2f
Added nodes monitor detail screen.
Michiel Broek <mbroek@mbse.eu>
parents:
312
diff
changeset
|
150 | dialog.exec(); |
310 | 151 | } |
152 | ||
153 | ||
154 | void MonNodes::on_editButton_clicked() | |
155 | { | |
156 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
157 | int recno = pb->objectName().toInt(); | |
158 | edit(recno); | |
159 | } | |
160 | ||
161 |