188 lines
6.4 KiB
C++
188 lines
6.4 KiB
C++
#include "itemsettingsdialog.h"
|
|
#include "ui_itemsettingsdialog.h"
|
|
#include "actorsettingsdialog.h"
|
|
#include "../actors/alarmtime.h"
|
|
#include "../actors/sensoractor.h"
|
|
#include "../actors/timeractor.h"
|
|
#include "../actors/regulator.h"
|
|
#include "../actors/factoractor.h"
|
|
#include "../items/messageitem.h"
|
|
#include "../items/systemitem.h"
|
|
#include "./itemsettingswidgets/messageitemsettingswidget.h"
|
|
#include "./itemsettingswidgets/systemitemsettingswidget.h"
|
|
#include "./itemsettingswidgets/relayitemsettingswidget.h"
|
|
#include<memory>
|
|
|
|
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
|
QDialog(parent),
|
|
item_(item),
|
|
ui(new Ui::ItemSettingsDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
setModal(false);
|
|
|
|
ui->label_name->setText(item_->getName());
|
|
ui->checkBox_Override->setChecked(item_->getOverride());
|
|
|
|
|
|
if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
|
|
{
|
|
itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
|
|
}
|
|
else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
|
|
{
|
|
itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
|
|
}
|
|
else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(item_))
|
|
{
|
|
itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem);
|
|
}
|
|
|
|
if(itemSpecificWidget_)
|
|
{
|
|
ui->verticalLayout_2->addWidget(itemSpecificWidget_);
|
|
}
|
|
|
|
connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
|
|
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
|
|
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
|
|
connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
|
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
|
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
|
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
|
ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
|
|
loadActorList();
|
|
}
|
|
|
|
ItemSettingsDialog::~ItemSettingsDialog()
|
|
{
|
|
if(itemSpecificWidget_) delete itemSpecificWidget_;
|
|
delete ui;
|
|
}
|
|
|
|
void ItemSettingsDialog::changeOverride()
|
|
{
|
|
item_->setOverride(ui->checkBox_Override->isChecked());
|
|
}
|
|
|
|
void ItemSettingsDialog::loadActorList()
|
|
{
|
|
//ui->listWidget->clear();
|
|
ui->tableWidget->setRowCount(item_->getActors().size());
|
|
|
|
for(unsigned i = 0; i < item_->getActors().size(); i++)
|
|
{
|
|
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
|
|
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
|
|
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
|
}
|
|
}
|
|
|
|
void ItemSettingsDialog::addActor()
|
|
{
|
|
ActorSettingsDialog* dialog = nullptr;
|
|
std::shared_ptr<Actor> actor = nullptr;
|
|
|
|
if(ui->comboBox->currentText() == "Alarm")
|
|
{
|
|
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
|
|
actor = alarm;
|
|
dialog = new ActorSettingsDialog(alarm, this);
|
|
}
|
|
else if(ui->comboBox->currentText() == "Sensor")
|
|
{
|
|
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
|
|
actor = sensorActor;
|
|
dialog = new ActorSettingsDialog(sensorActor, this);
|
|
}
|
|
else if(ui->comboBox->currentText() == "Timer" )
|
|
{
|
|
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
|
|
actor = timerActor;
|
|
dialog = new ActorSettingsDialog(timerActor, this);
|
|
}
|
|
else if(ui->comboBox->currentText() == "Regulator")
|
|
{
|
|
std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
|
|
actor = regulator;
|
|
dialog = new ActorSettingsDialog(regulator, this);
|
|
}
|
|
|
|
else if(ui->comboBox->currentText() == "Polynomal")
|
|
{
|
|
std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
|
|
actor = polynomalActor;
|
|
dialog = new ActorSettingsDialog(polynomalActor, this);
|
|
}
|
|
|
|
else if(ui->comboBox->currentText() == "Multi Factor")
|
|
{
|
|
std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
|
|
actor = polynomalActor;
|
|
dialog = new ActorSettingsDialog(polynomalActor, this);
|
|
}
|
|
|
|
|
|
if(dialog != nullptr)
|
|
{
|
|
dialog->setParent(this);
|
|
dialog->show();
|
|
if(dialog->exec() == QDialog::Accepted)
|
|
{
|
|
item_->addActor(actor);
|
|
loadActorList();
|
|
}
|
|
delete dialog;
|
|
}
|
|
|
|
}
|
|
|
|
void ItemSettingsDialog::removeActor()
|
|
{
|
|
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow()))
|
|
{
|
|
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
|
loadActorList();
|
|
}
|
|
}
|
|
|
|
void ItemSettingsDialog::editActor()
|
|
{
|
|
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow()))
|
|
{
|
|
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
|
|
|
std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
|
|
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
|
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
|
std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
|
|
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
|
std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(actor);
|
|
|
|
ActorSettingsDialog* dialog;
|
|
|
|
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
|
else if(regulator) dialog = new ActorSettingsDialog(regulator, this);
|
|
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
|
|
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
|
else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
|
|
else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
|
|
else dialog = new ActorSettingsDialog(actor, this);
|
|
dialog->setParent(this);
|
|
dialog->show();
|
|
dialog->exec();
|
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount() && i < static_cast<size_t>(item_->getActors().size()); ++i)
|
|
{
|
|
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
|
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
|
ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
|
|
}
|
|
}
|
|
}
|