switched from qsettings to json added editng of actors
This commit is contained in:
148
src/ui/itemsettingsdialog.cpp
Normal file
148
src/ui/itemsettingsdialog.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
#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<memory>
|
||||
|
||||
ItemSettingsDialog::ItemSettingsDialog(Item* item, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
item_(item),
|
||||
ui(new Ui::ItemSettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setModal(false);
|
||||
|
||||
ui->label_name->setText(item_->getName());
|
||||
|
||||
if(Relay* relay = dynamic_cast<Relay*>(item_))
|
||||
{
|
||||
ui->label_address->setText(QString::number(relay->getAddress(), 2));
|
||||
ui->label_id->setText(QString::number(relay->getId(), 10));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label_address->hide();
|
||||
ui->label_id->hide();
|
||||
ui->label_address_lable->hide();
|
||||
ui->label_id_lable->hide();
|
||||
}
|
||||
ui->checkBox_auto->setChecked(item_->actorsActive());
|
||||
|
||||
connect(ui->checkBox_auto, &QCheckBox::toggled, item_, &Relay::setActorsActive);
|
||||
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);
|
||||
|
||||
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
||||
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
||||
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Acts on"));
|
||||
ui->tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem("Enabled"));
|
||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
||||
ui->tableWidget->horizontalHeader()->resizeSection(2, 60);
|
||||
ui->tableWidget->horizontalHeader()->resizeSection(3, 75);
|
||||
loadActorList();
|
||||
}
|
||||
|
||||
ItemSettingsDialog::~ItemSettingsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
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"));
|
||||
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
||||
}
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::addActor()
|
||||
{
|
||||
ActorSettingsDialog* dialog = nullptr;
|
||||
Actor* actor = nullptr;
|
||||
|
||||
if(ui->comboBox->currentText() == "Alarm")
|
||||
{
|
||||
AlarmTime* alarm = new AlarmTime;
|
||||
actor = alarm;
|
||||
dialog = new ActorSettingsDialog(alarm, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Sensor" && item_->getSensorStore() != nullptr)
|
||||
{
|
||||
SensorActor* sensorActor = new SensorActor();
|
||||
actor = sensorActor;
|
||||
dialog = new ActorSettingsDialog(sensorActor, item_->getSensorStore(), this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Timer" )
|
||||
{
|
||||
TimerActor* timerActor = new TimerActor();
|
||||
actor = timerActor;
|
||||
dialog = new ActorSettingsDialog(timerActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Regulator" && item_->getSensorStore() != nullptr)
|
||||
{
|
||||
Regulator* regulator = new Regulator();
|
||||
actor = regulator;
|
||||
dialog = new ActorSettingsDialog(regulator, item_->getSensorStore(), this);
|
||||
}
|
||||
|
||||
|
||||
if(dialog != nullptr)
|
||||
{
|
||||
dialog->setParent(this);
|
||||
dialog->show();
|
||||
if(dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
item_->addActor(actor);
|
||||
loadActorList();
|
||||
}
|
||||
else delete actor;
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::removeActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
{
|
||||
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
||||
loadActorList();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::editActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
{
|
||||
Actor* actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||
|
||||
AlarmTime* alarmTime = dynamic_cast<AlarmTime*>(actor);
|
||||
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
||||
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
||||
TimerActor* timerActor = dynamic_cast<TimerActor*>(actor);
|
||||
|
||||
ActorSettingsDialog* dialog;
|
||||
|
||||
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
||||
else if(regulator) dialog = new ActorSettingsDialog(regulator, nullptr, this);
|
||||
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, nullptr, this);
|
||||
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
||||
else dialog = new ActorSettingsDialog(actor, this);
|
||||
dialog->setParent(this);
|
||||
dialog->show();
|
||||
dialog->exec();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user