Finish lerge refactor of systems

This commit is contained in:
Carl Philipp Klemm 2026-03-22 23:23:18 +01:00
parent 6d742e60db
commit 913d7df56d
36 changed files with 614 additions and 634 deletions

View file

@ -5,39 +5,47 @@
#include <QDebug>
#include <QSlider>
ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, bool nameOnly, QWidget *parent) :
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
QWidget(parent),
item_(item),
ui(new Ui::ItemWidget)
{
ui->setupUi(this);
if(analog)
if(auto workingItem = item_.lock())
{
ui->horizontalSpacer->changeSize(0,0);
ui->checkBox->hide();
}
else if(nameOnly)
{
ui->checkBox->hide();
ui->slider->hide();
}
else ui->slider->hide();
if(workingItem->getValueType() == ITEM_VALUE_UINT)
{
ui->horizontalSpacer->changeSize(0,0);
ui->checkBox->hide();
}
else if(workingItem->getValueType() == ITEM_VALUE_NO_VALUE)
{
ui->checkBox->hide();
ui->slider->hide();
}
else
{
ui->slider->hide();
}
if(auto workingRelay = item_.lock())
{
ui->checkBox->setChecked(workingRelay->getValue());
ui->checkBox->setChecked(workingItem->getValue());
ui->label->setText(workingRelay->getName());
ui->label->setText(workingItem->getName());
if(analog)connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
if(workingItem->getValueType() == ITEM_VALUE_UINT)
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
else
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
connect(workingItem.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
}
else disable();
else
{
disable();
}
}
void ItemWidget::deleteItem()
@ -50,14 +58,18 @@ void ItemWidget::deleteItem()
void ItemWidget::moveToValue(int value)
{
if(auto workingItem = item_.lock()) workingItem->setValue(value);
else disable();
if(auto workingItem = item_.lock())
workingItem->setValue(value);
else
disable();
}
void ItemWidget::moveToState(bool state)
{
if(auto workingItem = item_.lock()) workingItem->setValue(state);
else disable();
if(auto workingItem = item_.lock())
workingItem->setValue(state);
else
disable();
}
void ItemWidget::disable()
@ -70,9 +82,9 @@ void ItemWidget::disable()
bool ItemWidget::controles(const ItemData& relay)
{
if(auto workingRelay = item_.lock())
if(auto workingItem = item_.lock())
{
if(relay == *workingRelay) return true;
if(relay == *workingItem) return true;
else return false;
}
return true;
@ -80,9 +92,9 @@ bool ItemWidget::controles(const ItemData& relay)
void ItemWidget::showSettingsDialog()
{
if(auto workingRelay = item_.lock())
if(auto workingItem = item_.lock())
{
ItemSettingsDialog dialog(workingRelay, this);
ItemSettingsDialog dialog(workingItem, this);
dialog.exec();
}
else disable();
@ -95,7 +107,6 @@ std::weak_ptr<Item> ItemWidget::getItem()
void ItemWidget::stateChanged(int state)
{
qDebug()<<"widget got state "<<state;
ui->slider->blockSignals(true);
ui->slider->setValue(state);
ui->slider->blockSignals(false);