diff --git a/SHinterface.pro b/SHinterface.pro index ab27aa7..c7ff09f 100644 --- a/SHinterface.pro +++ b/SHinterface.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui widgets network multimedia +QT += core gui widgets network multimedia QT += serialport diff --git a/src/microcontroller.cpp b/src/microcontroller.cpp index c244796..ba5f54b 100644 --- a/src/microcontroller.cpp +++ b/src/microcontroller.cpp @@ -127,11 +127,16 @@ std::shared_ptr Microcontroller::processRelayLine(const QString& buffer) if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:")) { QString name; - for(int i = 10; i < bufferList.size(); i++) name.append(bufferList[i] + ' '); - if(name.size() > 1)name.remove(name.size()-1, 1); - else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2)); - return std::shared_ptr( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), - bufferList[8].toInt())); + for(int i = 10; i < bufferList.size(); i++) + name.append(bufferList[i] + ' '); + if(name.size() > 1) + name.remove(name.size()-1, 1); + else + name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2)); + return std::shared_ptr(new Relay(bufferList[2].toInt(), + name, + bufferList[6].toInt(nullptr, 2), + bufferList[8].toInt())); } return nullptr; } diff --git a/src/ui/actorwidgets/polynomalactorwidget.cpp b/src/ui/actorwidgets/polynomalactorwidget.cpp index 1c9476b..930a3f8 100644 --- a/src/ui/actorwidgets/polynomalactorwidget.cpp +++ b/src/ui/actorwidgets/polynomalactorwidget.cpp @@ -46,5 +46,5 @@ void PolynomalActorWidget::setPow() void PolynomalActorWidget::setSensor(const QModelIndex &index) { - actor_->setSensor(sensors_->getSensors()->at(index.row())); + actor_->setSensor(ui->listView->getSensorForIndex(index)); } diff --git a/src/ui/actorwidgets/regulatorwdiget.cpp b/src/ui/actorwidgets/regulatorwdiget.cpp index 30b0623..0fdddbf 100644 --- a/src/ui/actorwidgets/regulatorwdiget.cpp +++ b/src/ui/actorwidgets/regulatorwdiget.cpp @@ -47,7 +47,7 @@ void RegulatorWdiget::setBand(double band) void RegulatorWdiget::setSensor(const QModelIndex &index) { - regulator_->setSensor(sensors_->getSensors()->at(index.row())); + regulator_->setSensor(ui->listView->getSensorForIndex(index)); setPoint(sensors_->getSensors()->at(index.row()).field); ui->doubleSpinBox_setPoint->setValue(sensors_->getSensors()->at(index.row()).field); } diff --git a/src/ui/actorwidgets/sensoractorwidget.cpp b/src/ui/actorwidgets/sensoractorwidget.cpp index 41276e9..2718b1b 100644 --- a/src/ui/actorwidgets/sensoractorwidget.cpp +++ b/src/ui/actorwidgets/sensoractorwidget.cpp @@ -17,9 +17,12 @@ SensorActorWidget::SensorActorWidget(std::shared_ptr sensorActor, S ui->label->hide(); } - if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) ui->comboBox_slope->setCurrentIndex(0); - else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) ui->comboBox_slope->setCurrentIndex(1); - else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH) ui->comboBox_slope->setCurrentIndex(2); + if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) + ui->comboBox_slope->setCurrentIndex(0); + else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) + ui->comboBox_slope->setCurrentIndex(1); + else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH) + ui->comboBox_slope->setCurrentIndex(2); ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold()); @@ -47,6 +50,5 @@ void SensorActorWidget::setSlope(int index) void SensorActorWidget::setSensor(const QModelIndex &index) { - sensorActor_->setSensor(sensors_->getSensors()->at(index.row())); - qDebug()<<"Selected "<getSensors()->at(index.row()).name; + sensorActor_->setSensor(ui->listView->getSensorForIndex(index)); } diff --git a/src/ui/sensorlistwidget.cpp b/src/ui/sensorlistwidget.cpp index ce4fe4f..827ab2e 100644 --- a/src/ui/sensorlistwidget.cpp +++ b/src/ui/sensorlistwidget.cpp @@ -56,7 +56,7 @@ void SensorListWidget::sensorsChanged(std::vector sensors) else itemString.append("\"Silent\""); } - setItem(static_cast(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? " (H)" : ""))); + setItem(static_cast(row), 0, new SensorListItem(sensors[i].name + (sensors[i].hidden ? " (H)" : ""), sensors[i])); setItem(static_cast(row), 1, new QTableWidgetItem(itemString)); if(sensors[i].type <= 128) setItem(static_cast(row), 2, new QTableWidgetItem(sensors[i].lastSeen.time().toString("hh:mm"))); @@ -67,8 +67,23 @@ void SensorListWidget::sensorsChanged(std::vector sensors) resizeColumnsToContents(); } +const Sensor& SensorListWidget::getSensorForIndex(const QModelIndex &index) +{ + return static_cast(item(index.row(), 0))->getSensor(); +} + void SensorListWidget::setShowHidden(const bool showHidden) { showHidden_=showHidden; } +const Sensor& SensorListItem::getSensor() +{ + return sensor; +} + +SensorListItem::SensorListItem(const QString& text, const Sensor& sensor): + QTableWidgetItem(text, 1001), sensor(sensor) +{ +} + diff --git a/src/ui/sensorlistwidget.h b/src/ui/sensorlistwidget.h index 13776a6..c963a05 100644 --- a/src/ui/sensorlistwidget.h +++ b/src/ui/sensorlistwidget.h @@ -3,6 +3,15 @@ #include #include "../sensors/sensor.h" +class SensorListItem : public QTableWidgetItem +{ + Sensor sensor; + +public: + const Sensor& getSensor(); + SensorListItem(const QString& text, const Sensor& sensor); +}; + class SensorListWidget : public QTableWidget { Q_OBJECT @@ -11,10 +20,11 @@ class SensorListWidget : public QTableWidget public: - SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr); + SensorListWidget(const bool showHidden = true, QWidget* parent = nullptr); SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr); virtual ~SensorListWidget() {} void setShowHidden(const bool showHidden); + const Sensor& getSensorForIndex(const QModelIndex &index); public slots: