Thu, 30 Jun 2022 10:38:03 +0200
Translated to English.
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" | |
18 | #include "EditSupplier.h" | |
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 | { | |
30 | qDebug() << "MonNodes start"; | |
31 | ||
32 | gridLayout = new QGridLayout(this); | |
33 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); | |
34 | tableNodes = new QTableWidget(this); | |
35 | tableNodes->setObjectName(QString::fromUtf8("tableNodes")); | |
36 | tableNodes->setEnabled(true); | |
37 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); | |
38 | sizePolicy.setHorizontalStretch(0); | |
39 | sizePolicy.setVerticalStretch(0); | |
40 | sizePolicy.setHeightForWidth(tableNodes->sizePolicy().hasHeightForWidth()); | |
41 | tableNodes->setSizePolicy(sizePolicy); | |
42 | tableNodes->setMinimumSize(QSize(974, 0)); | |
43 | gridLayout->addWidget(tableNodes, 0, 0, 1, 1); | |
44 | ||
45 | groupBox = new QGroupBox(this); | |
46 | groupBox->setObjectName(QString::fromUtf8("groupBox")); | |
47 | groupBox->setEnabled(true); | |
48 | groupBox->setFlat(false); | |
49 | horizontalLayout = new QHBoxLayout(groupBox); | |
50 | horizontalLayout->setSpacing(6); | |
51 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); | |
52 | horizontalLayout->setContentsMargins(0, 0, 0, 0); | |
53 | quitButton = new QPushButton(groupBox); | |
54 | quitButton->setObjectName(QString::fromUtf8("quitButton")); | |
55 | quitButton->setMinimumSize(QSize(80, 24)); | |
56 | quitButton->setText(tr("Quit")); | |
57 | QIcon icon; | |
58 | icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); | |
59 | quitButton->setIcon(icon); | |
60 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter); | |
61 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); | |
62 | ||
63 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMonNodes())); | |
64 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); | |
65 | connect(parent, SIGNAL(updateNodes(QString)), this, SLOT(refreshNodes(QString))); | |
66 | emit refreshTable(); | |
67 | } | |
68 | ||
69 | ||
70 | void MonNodes::refreshTable() | |
71 | { | |
72 | QTableWidgetItem *item; | |
73 | ||
74 | qDebug() << "MonNodes reload"; | |
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 | qDebug() << "refreshNodes" << node; | |
142 | emit refreshTable(); | |
143 | } | |
144 | ||
145 | ||
146 | void MonNodes::edit(int recno) | |
147 | { | |
148 | // EditSupplier dialog(recno, this); | |
149 | /* Signal from editor if a refresh is needed */ | |
150 | // connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); | |
151 | // dialog.setModal(true); | |
152 | // dialog.exec(); | |
153 | } | |
154 | ||
155 | ||
156 | void MonNodes::on_editButton_clicked() | |
157 | { | |
158 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
159 | int recno = pb->objectName().toInt(); | |
160 | edit(recno); | |
161 | } | |
162 | ||
163 |