added label state

This commit is contained in:
2025-07-04 02:50:08 +07:00
parent d79d5c779e
commit ba3f36db0c

View File

@@ -222,8 +222,12 @@ void Mainwindows::onReadReady() {
for (int i = 0; i < m_indicatorRegisters.size(); ++i) {
if (address == m_indicatorRegisters[i]) {
static const QColor colors[] = {Qt::gray, Qt::black, Qt::green};
static const QString states[] = {"?", "Закрыт", "Открыт"};
m_colorIndices[i] = value % 3;
m_squares[i]->setColor(colors[m_colorIndices[i]]);
if (auto* item = m_table->item(i, 3)) {
item->setText(states[m_colorIndices[i]]);
}
break;
}
}
@@ -251,7 +255,7 @@ void Mainwindows::createUIElements() {
// Create table with maximum of buttons or indicators
int rowCount = qMax(m_buttonCount, m_indicatorCount);
m_table = new QTableWidget(rowCount, 3, this); // Changed from 2 to 3 columns
m_table = new QTableWidget(rowCount, 4, this); // Changed from 3 to 4 columns
// Setup table properties
m_table->verticalHeader()->setVisible(false);
@@ -301,7 +305,12 @@ void Mainwindows::createUIElements() {
square->setFixedSize(m_table->rowHeight(i), m_table->rowHeight(i));
m_squares.append(square);
m_colorIndices.append(0);
m_table->setCellWidget(i, 2, square); // Changed from column 1 to 2
m_table->setCellWidget(i, 2, square);
// Add status text cell
auto* statusItem = new QTableWidgetItem("?");
statusItem->setTextAlignment(Qt::AlignCenter);
m_table->setItem(i, 3, statusItem);
}
}
@@ -309,9 +318,11 @@ void Mainwindows::createUIElements() {
m_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
m_table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
m_table->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
m_table->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed);
m_table->setColumnWidth(0, 150); // Label column
m_table->setColumnWidth(1, 100); // Button column
m_table->setColumnWidth(2, 50); // Square column
m_table->setColumnWidth(3, 100); // Status text column
mainLayout->addWidget(m_table);
mainLayout->setContentsMargins(0, 0, 0, 0);