refactoring
This commit is contained in:
@@ -304,12 +304,18 @@ void MainWindows::createUIElements() {
|
||||
m_table->setItem(i, 0, new QTableWidgetItem(label));
|
||||
|
||||
if (i < m_buttonCount) {
|
||||
auto* container = new QWidget();
|
||||
auto* containerLayout = new QHBoxLayout(container);
|
||||
auto* button = new QPushButton(QString("Register %1 Bit %2").arg(m_buttonRegisters[i]).arg(m_buttonBits[i]), this);
|
||||
button->setFont(tableFont);
|
||||
button->setCheckable(true);
|
||||
button->setMaximumHeight(button->height() - 5);
|
||||
containerLayout->addWidget(button);
|
||||
containerLayout->setAlignment(Qt::AlignCenter);
|
||||
containerLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_buttons.append(button);
|
||||
m_buttonValues.append(0);
|
||||
m_table->setCellWidget(i, 1, button);
|
||||
m_table->setCellWidget(i, 1, container);
|
||||
connect(button, &QPushButton::clicked, this, [this, i]() {
|
||||
QModbusDataUnit writeUnit(QModbusDataUnit::HoldingRegisters, m_buttonRegisters[i], 1);
|
||||
int currentValue = m_buttonValues[i];
|
||||
@@ -327,11 +333,16 @@ void MainWindows::createUIElements() {
|
||||
}
|
||||
|
||||
if (i < m_indicatorCount) {
|
||||
auto* square = new ColoredSquare(this);
|
||||
square->setFixedSize(m_table->rowHeight(i), m_table->rowHeight(i));
|
||||
auto* container = new QWidget();
|
||||
auto* containerLayout = new QHBoxLayout(container);
|
||||
auto* square = new ColoredSquare(container);
|
||||
square->setFixedSize(m_table->rowHeight(i) - 4, m_table->rowHeight(i) - 4); // Немного уменьшаем размер
|
||||
containerLayout->addWidget(square);
|
||||
containerLayout->setAlignment(Qt::AlignCenter);
|
||||
containerLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_squares.append(square);
|
||||
m_colorIndices.append(0);
|
||||
m_table->setCellWidget(i, 2, square);
|
||||
m_table->setCellWidget(i, 2, container);
|
||||
|
||||
// Add status text cell
|
||||
const auto statusItem = new QTableWidgetItem("?");
|
||||
@@ -355,7 +366,7 @@ void MainWindows::createUIElements() {
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Обновляем расчет размера окна с учетом статусной строки
|
||||
int totalWidth = m_table->horizontalHeader()->length() + 20;
|
||||
int totalWidth = m_table->horizontalHeader()->length() + 4;
|
||||
int totalHeight = m_table->verticalHeader()->length() +
|
||||
m_connectButton->height() +
|
||||
m_statusLabel->sizeHint().height() + 20;
|
||||
|
||||
Reference in New Issue
Block a user