From ba3f36db0c9343c73ced94903ebeff53ebe4a46c Mon Sep 17 00:00:00 2001 From: Alekseev Date: Fri, 4 Jul 2025 02:50:08 +0700 Subject: [PATCH] added label state --- Src/mainwindow.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Src/mainwindow.cpp b/Src/mainwindow.cpp index c006d51..d7085d8 100644 --- a/Src/mainwindow.cpp +++ b/Src/mainwindow.cpp @@ -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);