85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
#include "factoractorwidget.h"
|
|
#include "ui_factoractorwidget.h"
|
|
#include "../actorsettingsdialog.h"
|
|
|
|
FactorActorWidget::FactorActorWidget(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) :
|
|
QWidget(parent),
|
|
actor_(actor),
|
|
ui(new Ui::FactorActorWidget)
|
|
{
|
|
ui->setupUi(this);
|
|
ui->comboBox->setCurrentText(actor_->getFactorDirection() ? "True" : "False");
|
|
ui->spinBox->setValue(actor_->getPreCancleTime());
|
|
if(actor_->getFactorActor()) ui->label_FactorActor->setText(actor_->getFactorActor()->getName());
|
|
connect(ui->pushButton, &QPushButton::clicked, this, &FactorActorWidget::createFactorActor);
|
|
connect(ui->comboBox_Direcion, &QComboBox::currentTextChanged, this, &FactorActorWidget::setDirection);
|
|
connect(ui->spinBox, qOverload<int>(&QSpinBox::valueChanged), this, &FactorActorWidget::setPreCancleTime);
|
|
}
|
|
|
|
FactorActorWidget::~FactorActorWidget()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void FactorActorWidget::createFactorActor()
|
|
{
|
|
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);
|
|
}
|
|
|
|
|
|
if(dialog != nullptr)
|
|
{
|
|
dialog->setParent(this);
|
|
dialog->show();
|
|
if(dialog->exec() == QDialog::Accepted)
|
|
{
|
|
actor_->setFactorActor(actor);
|
|
ui->label_FactorActor->setText(actor->getName());
|
|
}
|
|
delete dialog;
|
|
}
|
|
}
|
|
|
|
void FactorActorWidget::setDirection(const QString& type)
|
|
{
|
|
if(type == "True") actor_->setFactorDirection(true);
|
|
else actor_->setFactorDirection(false);
|
|
}
|
|
|
|
void FactorActorWidget::setPreCancleTime(int time)
|
|
{
|
|
actor_->setPreCancleTime(time);
|
|
}
|