Fix case where the ganged channel is channel 0

This commit is contained in:
Carl Philipp Klemm 2025-10-13 11:05:11 +02:00
parent 81e7e1a5b3
commit af9263b041
3 changed files with 10 additions and 20 deletions

View file

@ -1,4 +1,3 @@
#include "channelwidget.h" #include "channelwidget.h"
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
@ -27,7 +26,6 @@ ChannelWidget::ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber,
line.setFrameShadow(QFrame::Sunken); line.setFrameShadow(QFrame::Sunken);
vlayout.addWidget(&line); vlayout.addWidget(&line);
// Add Unganged option first
gangcombo.addItem("Unganged"); gangcombo.addItem("Unganged");
hlayout.addStretch(); hlayout.addStretch();
@ -35,7 +33,6 @@ ChannelWidget::ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber,
hlayout.addWidget(&gangcombo); hlayout.addWidget(&gangcombo);
hlayout.addWidget(&checkbox); hlayout.addWidget(&checkbox);
// Connect signals
connect(&checkbox, &QCheckBox::toggled, this, &ChannelWidget::onChannelToggled); connect(&checkbox, &QCheckBox::toggled, this, &ChannelWidget::onChannelToggled);
connect(&gangcombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ChannelWidget::onGangComboChanged); connect(&gangcombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ChannelWidget::onGangComboChanged);
@ -47,7 +44,7 @@ ChannelWidget::ChannelWidget(uint16_t deviceSerial, uint16_t channelNumber,
ChannelWidget::~ChannelWidget() ChannelWidget::~ChannelWidget()
{ {
// Nothing to clean up
} }
uint16_t ChannelWidget::getDeviceSerial() const uint16_t ChannelWidget::getDeviceSerial() const
@ -83,7 +80,7 @@ void ChannelWidget::onChannelToggled(bool checked)
qWarning() << "Failed to connect channel" << channelNumber << "on device" << deviceSerial; qWarning() << "Failed to connect channel" << channelNumber << "on device" << deviceSerial;
checkbox.blockSignals(true); checkbox.blockSignals(true);
checkbox.setChecked(false); checkbox.setChecked(false);
setEnabled(false); // Gray out the widget setEnabled(false);
} }
} }
else else
@ -95,7 +92,7 @@ void ChannelWidget::onChannelToggled(bool checked)
qWarning() << "Failed to disconnect channel" << channelNumber << "on device" << deviceSerial; qWarning() << "Failed to disconnect channel" << channelNumber << "on device" << deviceSerial;
checkbox.blockSignals(true); checkbox.blockSignals(true);
checkbox.setChecked(true); checkbox.setChecked(true);
setEnabled(false); // Gray out the widget setEnabled(false);
} }
} }
@ -107,11 +104,11 @@ void ChannelWidget::onGangComboChanged(int index)
{ {
if (index == 0) { if (index == 0) {
// Unganged selected - reset ganged channel tracking // Unganged selected - reset ganged channel tracking
gangedDeviceSerial = 0; gangedDeviceSerial = -1;
gangedChannelNumber = 0; gangedChannelNumber = -1;
checkbox.setEnabled(true); checkbox.setEnabled(true);
checkbox.setChecked(false); checkbox.setChecked(false);
checkbox.setChecked(false); // Reset to false to avoid leaving it checked when unganged checkbox.setChecked(false);
} else { } else {
// A ganged channel was selected // A ganged channel was selected
QString currentText = gangcombo.currentText(); QString currentText = gangcombo.currentText();
@ -149,12 +146,9 @@ void ChannelWidget::updateGangCombo()
void ChannelWidget::updateCheckboxState() void ChannelWidget::updateCheckboxState()
{ {
// If we're ganged, update our state to match the ganged channel if (gangedDeviceSerial >= 0 && gangedChannelNumber >= 0) {
if (gangedDeviceSerial != 0 && gangedChannelNumber != 0) {
checkbox.setEnabled(false); checkbox.setEnabled(false);
// We need to check the state of the ganged channel and sync // TODO check current ganged channel state
// This would typically be done by querying the actual channel state
// but for now we'll assume the ganged channel's state is known
} else { } else {
checkbox.setEnabled(true); checkbox.setEnabled(true);
} }

View file

@ -1,5 +1,3 @@
#ifndef CHANNELWIDGET_H #ifndef CHANNELWIDGET_H
#define CHANNELWIDGET_H #define CHANNELWIDGET_H
@ -58,8 +56,8 @@ private:
QVBoxLayout labellayout; QVBoxLayout labellayout;
// Track the channel this one is ganged to (if any) // Track the channel this one is ganged to (if any)
uint16_t gangedDeviceSerial = 0; int gangedDeviceSerial = -1;
uint16_t gangedChannelNumber = 0; int gangedChannelNumber = -1;
}; };
#endif // CHANNELWIDGET_H #endif // CHANNELWIDGET_H

View file

@ -1,5 +1,3 @@
#include <eismultiplexer.h> #include <eismultiplexer.h>
#include <QMessageBox> #include <QMessageBox>
#include "mainwindow.h" #include "mainwindow.h"