#include "factoractorwidget.h" #include "ui_factoractorwidget.h" #include "../actorsettingsdialog.h" FactorActorWidget::FactorActorWidget(std::shared_ptr 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(&QSpinBox::valueChanged), this, &FactorActorWidget::setPreCancleTime); } FactorActorWidget::~FactorActorWidget() { delete ui; } void FactorActorWidget::createFactorActor() { ActorSettingsDialog* dialog = nullptr; std::shared_ptr actor = nullptr; if(ui->comboBox->currentText() == "Alarm") { std::shared_ptr alarm = std::shared_ptr(new AlarmTime); actor = alarm; dialog = new ActorSettingsDialog(alarm, this); } else if(ui->comboBox->currentText() == "Sensor") { std::shared_ptr sensorActor = std::shared_ptr(new SensorActor()); actor = sensorActor; dialog = new ActorSettingsDialog(sensorActor, this); } else if(ui->comboBox->currentText() == "Timer" ) { std::shared_ptr timerActor = std::shared_ptr(new TimerActor()); actor = timerActor; dialog = new ActorSettingsDialog(timerActor, this); } else if(ui->comboBox->currentText() == "Regulator") { std::shared_ptr regulator = std::shared_ptr(new Regulator()); actor = regulator; dialog = new ActorSettingsDialog(regulator, this); } else if(ui->comboBox->currentText() == "Polynomal") { std::shared_ptr polynomalActor = std::shared_ptr(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); }