diff --git a/CMakeLists.txt b/CMakeLists.txt index fdf32b7..5990efc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,8 @@ add_executable(smartvos src/ui/itemsettingsdialog.cpp src/ui/actorsettingsdialog.h src/ui/actorsettingsdialog.cpp + src/ui/sensorsettingsdialog.h + src/ui/sensorsettingsdialog.cpp src/ui/actorwidgets/factoractorwidget.h src/ui/actorwidgets/factoractorwidget.cpp @@ -181,6 +183,7 @@ target_sources(smartvos src/ui/itemcreationdialog.ui src/ui/itemsettingsdialog.ui src/ui/actorsettingsdialog.ui + src/ui/sensorsettingsdialog.ui src/ui/actorwidgets/factoractorwidget.ui src/ui/actorwidgets/polynomalactorwidget.ui src/ui/actorwidgets/sensoractorwidget.ui diff --git a/src/ui/sensorlistwidget.cpp b/src/ui/sensorlistwidget.cpp index b732362..ce87271 100644 --- a/src/ui/sensorlistwidget.cpp +++ b/src/ui/sensorlistwidget.cpp @@ -4,6 +4,8 @@ #include #include +#include "sensorsettingsdialog.h" + SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), showHidden_(showHidden) { @@ -15,12 +17,31 @@ SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTab setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); sensorsChanged(std::vector()); verticalHeader()->hide(); + + connect(this, &QTableWidget::doubleClicked, this, &SensorListWidget::onDoubleClick); } SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden, QWidget* parent): QTableWidget (parent), showHidden_(showHidden) { sensorsChanged(*(sensorStore.getSensors())); + connect(this, &QTableWidget::doubleClicked, this, &SensorListWidget::onDoubleClick); +} + +void SensorListWidget::onDoubleClick(const QModelIndex &index) +{ + if(index.isValid()) + { + const Sensor& sensor = getSensorForIndex(index); + SensorSettingsDialog diag(sensor, this); + if(diag.exec()) + { + Sensor updatedSensor = sensor; + updatedSensor.name = diag.getName(); + updatedSensor.hidden = diag.getHidden(); + globalSensors.sensorGotState(updatedSensor, SENSOR_UPDATE_USER); + } + } } void SensorListWidget::sensorsChanged(std::vector sensors) diff --git a/src/ui/sensorlistwidget.h b/src/ui/sensorlistwidget.h index 4c84d54..0aceabc 100644 --- a/src/ui/sensorlistwidget.h +++ b/src/ui/sensorlistwidget.h @@ -30,4 +30,6 @@ public slots: void sensorsChanged(std::vector sensors); +private slots: + void onDoubleClick(const QModelIndex &index); }; diff --git a/src/ui/sensorsettingsdialog.cpp b/src/ui/sensorsettingsdialog.cpp new file mode 100644 index 0000000..dda6a56 --- /dev/null +++ b/src/ui/sensorsettingsdialog.cpp @@ -0,0 +1,29 @@ +#include "sensorsettingsdialog.h" +#include "ui_sensorsettingsdialog.h" + +SensorSettingsDialog::SensorSettingsDialog(const Sensor& sensor, QWidget* parent) + : QDialog(parent) + , ui(new Ui::SensorSettingsDialog) +{ + ui->setupUi(this); + + ui->label_typeValue->setText(QString::number(sensor.type)); + ui->label_idValue->setText(QString::number(sensor.id)); + ui->lineEdit_Name->setText(sensor.name); + ui->checkBox_Hidden->setChecked(sensor.hidden); +} + +SensorSettingsDialog::~SensorSettingsDialog() +{ + delete ui; +} + +QString SensorSettingsDialog::getName() const +{ + return ui->lineEdit_Name->text(); +} + +bool SensorSettingsDialog::getHidden() const +{ + return ui->checkBox_Hidden->isChecked(); +} \ No newline at end of file diff --git a/src/ui/sensorsettingsdialog.h b/src/ui/sensorsettingsdialog.h new file mode 100644 index 0000000..df796c7 --- /dev/null +++ b/src/ui/sensorsettingsdialog.h @@ -0,0 +1,27 @@ +#ifndef SENSORSETTINGSDIALOG_H +#define SENSORSETTINGSDIALOG_H + +#include +#include "sensors/sensor.h" + +namespace Ui +{ +class SensorSettingsDialog; +} + +class SensorSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SensorSettingsDialog(const Sensor& sensor, QWidget* parent = nullptr); + ~SensorSettingsDialog(); + + QString getName() const; + bool getHidden() const; + +private: + Ui::SensorSettingsDialog* ui; +}; + +#endif // SENSORSETTINGSDIALOG_H \ No newline at end of file diff --git a/src/ui/sensorsettingsdialog.ui b/src/ui/sensorsettingsdialog.ui new file mode 100644 index 0000000..608883c --- /dev/null +++ b/src/ui/sensorsettingsdialog.ui @@ -0,0 +1,139 @@ + + + SensorSettingsDialog + + + + 0 + 0 + 400 + 150 + + + + Sensor Settings + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + TextLabel + + + + + + + Id: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + TextLabel + + + + + + + Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Hidden: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SensorSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SensorSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + \ No newline at end of file