Sensors now work over broadcast pipe
Added Polynomal actor Added Item adding dialog Added Factor Actor
This commit is contained in:
@ -17,12 +17,19 @@ TEMPLATE = app
|
|||||||
# deprecated API in order to know how to port your code away from it.
|
# deprecated API in order to know how to port your code away from it.
|
||||||
DEFINES += QT_DEPRECATED_WARNINGS
|
DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -flto -std=c++17 -O2
|
QMAKE_CXXFLAGS += -std=c++17 -O2
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
src/actors/factoractor.cpp \
|
||||||
|
src/actors/polynomalactor.cpp \
|
||||||
src/broadcast.cpp \
|
src/broadcast.cpp \
|
||||||
src/iomuliplexer.cpp \
|
src/iomuliplexer.cpp \
|
||||||
|
src/items/messageitem.cpp \
|
||||||
|
src/ui/actorwidgets/factoractorwidget.cpp \
|
||||||
|
src/ui/itemcreationdialog.cpp \
|
||||||
|
src/ui/itemsettingswidgets/messageitemsettingswidget.cpp \
|
||||||
src/mainobject.cpp \
|
src/mainobject.cpp \
|
||||||
|
src/ui/actorwidgets/polynomalactorwidget.cpp \
|
||||||
src/ui/actorwidgets/sensoractorwidget.cpp \
|
src/ui/actorwidgets/sensoractorwidget.cpp \
|
||||||
src/ui/actorwidgets/alarmwidget.cpp \
|
src/ui/actorwidgets/alarmwidget.cpp \
|
||||||
src/ui/actorwidgets/timeractorwidget.cpp \
|
src/ui/actorwidgets/timeractorwidget.cpp \
|
||||||
@ -65,10 +72,17 @@ SOURCES += \
|
|||||||
|
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
src/actors/factoractor.h \
|
||||||
|
src/actors/polynomalactor.h \
|
||||||
src/broadcast.h \
|
src/broadcast.h \
|
||||||
src/iomuliplexer.h \
|
src/iomuliplexer.h \
|
||||||
|
src/items/messageitem.h \
|
||||||
|
src/ui/actorwidgets/factoractorwidget.h \
|
||||||
|
src/ui/itemcreationdialog.h \
|
||||||
|
src/ui/itemsettingswidgets/messageitemsettingswidget.h \
|
||||||
src/mainobject.h \
|
src/mainobject.h \
|
||||||
src/ui/actorwidgets/alarmwidget.h \
|
src/ui/actorwidgets/alarmwidget.h \
|
||||||
|
src/ui/actorwidgets/polynomalactorwidget.h \
|
||||||
src/ui/actorwidgets/sensoractorwidget.h \
|
src/ui/actorwidgets/sensoractorwidget.h \
|
||||||
src/ui/actorwidgets/timeractorwidget.h \
|
src/ui/actorwidgets/timeractorwidget.h \
|
||||||
src/ui/itemwidget.h \
|
src/ui/itemwidget.h \
|
||||||
@ -108,7 +122,11 @@ HEADERS += \
|
|||||||
src/sun.h
|
src/sun.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
src/ui/actorwidgets/factoractorwidget.ui \
|
||||||
|
src/ui/itemcreationdialog.ui \
|
||||||
|
src/ui/itemsettingswidgets/messageitemsettingswidget.ui \
|
||||||
src/ui/actorsettingsdialog.ui \
|
src/ui/actorsettingsdialog.ui \
|
||||||
|
src/ui/actorwidgets/polynomalactorwidget.ui \
|
||||||
src/ui/mainwindow.ui \
|
src/ui/mainwindow.ui \
|
||||||
src/ui/relayscrollbox.ui \
|
src/ui/relayscrollbox.ui \
|
||||||
src/ui/actorwidgets/sensoractorwidget.ui \
|
src/ui/actorwidgets/sensoractorwidget.ui \
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
#include "sensoractor.h"
|
#include "sensoractor.h"
|
||||||
#include "timeractor.h"
|
#include "timeractor.h"
|
||||||
#include "regulator.h"
|
#include "regulator.h"
|
||||||
|
#include "polynomalactor.h"
|
||||||
|
#include "factoractor.h"
|
||||||
|
|
||||||
Actor::Actor(QObject *parent): QObject(parent)
|
Actor::Actor(QObject *parent): Item(QRandomGenerator::global()->generate(), "", 0, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +21,6 @@ void Actor::performAction()
|
|||||||
{
|
{
|
||||||
if(active)
|
if(active)
|
||||||
{
|
{
|
||||||
trigger();
|
|
||||||
sigValue(triggerValue);
|
sigValue(triggerValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,17 +62,17 @@ bool Actor::isExausted()
|
|||||||
|
|
||||||
void Actor::store(QJsonObject& json)
|
void Actor::store(QJsonObject& json)
|
||||||
{
|
{
|
||||||
|
Item::store(json);
|
||||||
json["Active"] = active;
|
json["Active"] = active;
|
||||||
json["Exausted"] = exausted;
|
json["Exausted"] = exausted;
|
||||||
if(!name.isEmpty()) json["Name"] = name;
|
|
||||||
json["TriggerValue"] = triggerValue;
|
json["TriggerValue"] = triggerValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::load(const QJsonObject& json)
|
void Actor::load(const QJsonObject& json, const bool preserve)
|
||||||
{
|
{
|
||||||
|
Item::load(json, preserve);
|
||||||
active = json["Active"].toBool();
|
active = json["Active"].toBool();
|
||||||
exausted = json["Exausted"].toBool();
|
exausted = json["Exausted"].toBool();
|
||||||
name = json["Name"].toString("");
|
|
||||||
triggerValue = json["TriggerValue"].toInt();
|
triggerValue = json["TriggerValue"].toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +86,6 @@ uint8_t Actor::getTriggerValue()
|
|||||||
return triggerValue;
|
return triggerValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Actor::getName()
|
|
||||||
{
|
|
||||||
if(name.size() > 0) return name;
|
|
||||||
else return "Actor";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::onValueChanged(uint8_t value)
|
void Actor::onValueChanged(uint8_t value)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -103,6 +98,8 @@ Actor* Actor::createActor(const QString& type)
|
|||||||
else if(type == "Sensor") actor = new SensorActor();
|
else if(type == "Sensor") actor = new SensorActor();
|
||||||
else if(type == "Timer") actor = new TimerActor();
|
else if(type == "Timer") actor = new TimerActor();
|
||||||
else if(type == "Regulator") actor = new Regulator();
|
else if(type == "Regulator") actor = new Regulator();
|
||||||
|
else if(type == "Polynomal") actor = new PolynomalActor();
|
||||||
|
else if(type == "MultiFactor") actor = new MultiFactorActor();
|
||||||
else if(type == "Actor") actor = new Actor();
|
else if(type == "Actor") actor = new Actor();
|
||||||
return actor;
|
return actor;
|
||||||
}
|
}
|
||||||
@ -114,3 +111,10 @@ Actor* Actor::loadActor(const QJsonObject &json)
|
|||||||
if(actor) actor->load(json);
|
if(actor) actor->load(json);
|
||||||
return actor;
|
return actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Actor::setValue(uint8_t value)
|
||||||
|
{
|
||||||
|
Item::setValue(value);
|
||||||
|
setActive(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
class Actor : public QObject
|
#include "../items/item.h"
|
||||||
|
|
||||||
|
class Actor : public Item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@ -18,12 +20,9 @@ protected:
|
|||||||
|
|
||||||
void performAction();
|
void performAction();
|
||||||
|
|
||||||
QString name;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void sigValue(uint8_t value);
|
void sigValue(uint8_t value);
|
||||||
void trigger();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void makeActive();
|
virtual void makeActive();
|
||||||
@ -31,6 +30,7 @@ public slots:
|
|||||||
virtual void setActive(uint8_t state);
|
virtual void setActive(uint8_t state);
|
||||||
virtual void onValueChanged(uint8_t state);
|
virtual void onValueChanged(uint8_t state);
|
||||||
|
|
||||||
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Actor(QObject* parent = nullptr);
|
Actor(QObject* parent = nullptr);
|
||||||
@ -39,8 +39,6 @@ public:
|
|||||||
|
|
||||||
virtual QString actionName();
|
virtual QString actionName();
|
||||||
|
|
||||||
virtual QString getName();
|
|
||||||
|
|
||||||
bool isActive();
|
bool isActive();
|
||||||
void setTriggerValue(uint8_t value);
|
void setTriggerValue(uint8_t value);
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ public:
|
|||||||
static Actor* createActor(const QString& type);
|
static Actor* createActor(const QString& type);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json);
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
static Actor* loadActor(const QJsonObject& json);
|
static Actor* loadActor(const QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ AlarmTime::AlarmTime(const QDateTime time, QObject *parent) : Actor(parent), tim
|
|||||||
{
|
{
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||||
timer.setInterval(1000);
|
timer.setInterval(1000);
|
||||||
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlarmTime::~AlarmTime()
|
AlarmTime::~AlarmTime()
|
||||||
@ -26,9 +27,9 @@ void AlarmTime::makeActive()
|
|||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AlarmTime::getName()
|
QString AlarmTime::getName() const
|
||||||
{
|
{
|
||||||
if(name.size() > 0)return name;
|
if(name_.size() > 0)return name_;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString string;
|
QString string;
|
||||||
@ -111,6 +112,7 @@ void AlarmTime::doTick()
|
|||||||
void AlarmTime::changeTime(const QDateTime& time)
|
void AlarmTime::changeTime(const QDateTime& time)
|
||||||
{
|
{
|
||||||
time_=time;
|
time_=time;
|
||||||
|
qDebug()<<"time: "<<time_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,9 +124,11 @@ void AlarmTime::store(QJsonObject& json)
|
|||||||
json["Repeat"] = repeat_;
|
json["Repeat"] = repeat_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlarmTime::load(const QJsonObject& json)
|
void AlarmTime::load(const QJsonObject& json, const bool preserve)
|
||||||
{
|
{
|
||||||
Actor::load(json);
|
bool oldActive = isActive();
|
||||||
|
Actor::load(json, preserve);
|
||||||
time_ = QDateTime::fromString(json["Time"].toString(""));
|
time_ = QDateTime::fromString(json["Time"].toString(""));
|
||||||
repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
|
repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
|
||||||
|
if(oldActive != isActive()) setActive(isActive());
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
QDateTime getDateTime();
|
QDateTime getDateTime();
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json);
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
|
|
||||||
uint8_t getRepeat();
|
uint8_t getRepeat();
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public slots:
|
|||||||
void run();
|
void run();
|
||||||
virtual void makeActive();
|
virtual void makeActive();
|
||||||
virtual void makeInactive();
|
virtual void makeInactive();
|
||||||
virtual QString getName();
|
virtual QString getName() const;
|
||||||
void doTick();
|
void doTick();
|
||||||
void changeTime(const QDateTime& time);
|
void changeTime(const QDateTime& time);
|
||||||
void setRepeat(const uint8_t repeat);
|
void setRepeat(const uint8_t repeat);
|
||||||
|
80
src/actors/factoractor.cpp
Normal file
80
src/actors/factoractor.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "factoractor.h"
|
||||||
|
|
||||||
|
MultiFactorActor::MultiFactorActor(Actor* factorActor, const uint preCancleMin, QObject *parent):
|
||||||
|
Actor(parent),
|
||||||
|
factorActor_(factorActor),
|
||||||
|
preCancleMin_(preCancleMin)
|
||||||
|
{
|
||||||
|
activationTime.setMSecsSinceEpoch(0);
|
||||||
|
if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiFactorActor::factorActorSlot(uint8_t value)
|
||||||
|
{
|
||||||
|
if(value == factorDirection)
|
||||||
|
{
|
||||||
|
activationTime = QDateTime::currentDateTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiFactorActor::setValue(uint8_t value)
|
||||||
|
{
|
||||||
|
if(value)
|
||||||
|
{
|
||||||
|
QDateTime current = QDateTime::currentDateTime();
|
||||||
|
if(current.addSecs(-preCancleMin_*60) > activationTime )
|
||||||
|
{
|
||||||
|
performAction();
|
||||||
|
}
|
||||||
|
bool exausted = true;
|
||||||
|
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MultiFactorActor::getName() const
|
||||||
|
{
|
||||||
|
if(name_.size() > 0) return name_;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString string;
|
||||||
|
string = "Multi Factor \"" + (factorActor_ ? factorActor_->getName() : "NULL") + "\"";
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiFactorActor::setFactorActor(Actor* factorActor)
|
||||||
|
{
|
||||||
|
if(factorActor_) delete factorActor_;
|
||||||
|
factorActor_=factorActor;
|
||||||
|
connect(factorActor_, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiFactorActor::store(QJsonObject &json)
|
||||||
|
{
|
||||||
|
json["Type"] = "MultiFactor";
|
||||||
|
Actor::store(json);
|
||||||
|
json["PreCancleMinutes"] = static_cast<int>(preCancleMin_);
|
||||||
|
json["FactorDirection"] = factorDirection;
|
||||||
|
QJsonObject factorActorObject;
|
||||||
|
if(factorActor_)
|
||||||
|
{
|
||||||
|
factorActor_->store(factorActorObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiFactorActor::load(const QJsonObject &json, bool preserve)
|
||||||
|
{
|
||||||
|
Actor::load(json, preserve);
|
||||||
|
preCancleMin_ = static_cast<uint>(json["PreCancleMinutes"].toInt(10));
|
||||||
|
factorDirection = json["FacotorDirection"].toBool(true);
|
||||||
|
if(json["FactorActor"].isObject())
|
||||||
|
{
|
||||||
|
factorActor_ = Actor::loadActor(json["FactorActor"].toObject());
|
||||||
|
}
|
||||||
|
if(factorActor_)
|
||||||
|
{
|
||||||
|
connect(factorActor_, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
44
src/actors/factoractor.h
Normal file
44
src/actors/factoractor.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef REMINDERACTOR_H
|
||||||
|
#define REMINDERACTOR_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include "actor.h"
|
||||||
|
|
||||||
|
class MultiFactorActor: public Actor
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
Actor* factorActor_;
|
||||||
|
QDateTime activationTime;
|
||||||
|
uint preCancleMin_;
|
||||||
|
|
||||||
|
bool factorDirection = true;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void factorActorSlot(uint8_t value);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
virtual QString getName() const;
|
||||||
|
|
||||||
|
void setFactorActor(Actor* factorActor);
|
||||||
|
Actor* getFactorActor(){return factorActor_;}
|
||||||
|
void setFactorDirection(const bool direction){factorDirection = direction;}
|
||||||
|
bool getFactorDirection(){return factorDirection;}
|
||||||
|
uint getPreCancleTime(){return preCancleMin_;}
|
||||||
|
void setPreCancleTime(uint minutes){preCancleMin_ = minutes;}
|
||||||
|
|
||||||
|
virtual ~MultiFactorActor(){}
|
||||||
|
|
||||||
|
virtual void store(QJsonObject& json);
|
||||||
|
virtual void load(const QJsonObject& json, bool preserve);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // REMINDERACTOR_H
|
83
src/actors/polynomalactor.cpp
Normal file
83
src/actors/polynomalactor.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include "polynomalactor.h"
|
||||||
|
|
||||||
|
PolynomalActor::PolynomalActor(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PolynomalActor::PolynomalActor(QObject* parent): Actor(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolynomalActor::setSensor(const Sensor sensor)
|
||||||
|
{
|
||||||
|
sensor_ = sensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PolynomalActor::setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 )
|
||||||
|
{
|
||||||
|
pow3_=pow3;
|
||||||
|
pow2_=pow2;
|
||||||
|
pow1_=pow1;
|
||||||
|
pow0_=pow0;
|
||||||
|
}
|
||||||
|
void PolynomalActor::getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 )
|
||||||
|
{
|
||||||
|
pow3=pow3_;
|
||||||
|
pow2=pow2_;
|
||||||
|
pow1=pow1_;
|
||||||
|
pow0=pow0_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolynomalActor::sensorEvent(Sensor sensor)
|
||||||
|
{
|
||||||
|
if(active && sensor == sensor_)
|
||||||
|
{
|
||||||
|
double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field+pow0_;
|
||||||
|
if(result < 0) result = 0;
|
||||||
|
else if(result > 254) result = 255;
|
||||||
|
if(result != prevValue)sigValue(static_cast<uint8_t>(result));
|
||||||
|
prevValue = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolynomalActor::store(QJsonObject& json)
|
||||||
|
{
|
||||||
|
json["Type"] = "Polynomal";
|
||||||
|
Actor::store(json);
|
||||||
|
json["Pow3"] = pow3_;
|
||||||
|
json["Pow2"] = pow2_;
|
||||||
|
json["Pow1"] = pow1_;
|
||||||
|
json["Pow0"] = pow0_;
|
||||||
|
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||||
|
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||||
|
json["SensorField"] = sensor_.field;
|
||||||
|
json["SensorName"] = sensor_.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolynomalActor::load(const QJsonObject& json, bool preserve)
|
||||||
|
{
|
||||||
|
Actor::load(json, preserve);
|
||||||
|
pow3_ = json["Pow3"].toDouble(0);
|
||||||
|
pow2_ = json["Pow2"].toDouble(0);
|
||||||
|
pow1_ = json["Pow1"].toDouble(1);
|
||||||
|
pow0_ = json["Pow0"].toDouble(0);
|
||||||
|
sensor_.type = json["SensorType"].toInt(0);
|
||||||
|
sensor_.id = json["SensorId"].toInt(0);
|
||||||
|
sensor_.field = json["SensorField"].toInt(0);
|
||||||
|
sensor_.name = json["SensorName"].toString("Sensor");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PolynomalActor::getName() const
|
||||||
|
{
|
||||||
|
if(name_.size() > 0) return name_;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString string;
|
||||||
|
string = QString::number(pow3_) + "x^2 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
39
src/actors/polynomalactor.h
Normal file
39
src/actors/polynomalactor.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef POLYNOMALACTOR_H
|
||||||
|
#define POLYNOMALACTOR_H
|
||||||
|
#include "actor.h"
|
||||||
|
#include "../sensors/sensor.h"
|
||||||
|
|
||||||
|
class PolynomalActor: public Actor
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
Sensor sensor_;
|
||||||
|
double pow3_ = 0;
|
||||||
|
double pow2_ = 0;
|
||||||
|
double pow1_ = 1;
|
||||||
|
double pow0_ = 0;
|
||||||
|
|
||||||
|
double prevValue = -1;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void sensorEvent(Sensor sensor);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 );
|
||||||
|
void getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 );
|
||||||
|
|
||||||
|
PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
|
||||||
|
PolynomalActor(QObject* parent = nullptr);
|
||||||
|
void setSensor(const Sensor sensor);
|
||||||
|
Sensor getSensor(){return sensor_;}
|
||||||
|
virtual QString getName() const;
|
||||||
|
virtual ~PolynomalActor(){}
|
||||||
|
|
||||||
|
virtual void store(QJsonObject& json);
|
||||||
|
virtual void load(const QJsonObject& json, bool preserve);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // POLYNOMALACTOR_H
|
@ -22,16 +22,15 @@ void Regulator::sensorEvent(Sensor sensor)
|
|||||||
if(active && sensor == sensor_)
|
if(active && sensor == sensor_)
|
||||||
{
|
{
|
||||||
qDebug()<<"got sensor: "<<sensor.type<<" "<<sensor.id<<" want: "<<sensor_.type<<" "<<sensor_.id;
|
qDebug()<<"got sensor: "<<sensor.type<<" "<<sensor.id<<" want: "<<sensor_.type<<" "<<sensor_.id;
|
||||||
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_) )
|
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
||||||
{
|
{
|
||||||
trigger();
|
|
||||||
sigValue(triggerValue);
|
sigValue(triggerValue);
|
||||||
}
|
}
|
||||||
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_) )
|
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
|
||||||
{
|
{
|
||||||
trigger();
|
|
||||||
sigValue(!triggerValue);
|
sigValue(!triggerValue);
|
||||||
}
|
}
|
||||||
|
first = false;
|
||||||
sensor_ = sensor;
|
sensor_ = sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,9 +62,9 @@ void Regulator::store(QJsonObject& json)
|
|||||||
json["SensorName"] = sensor_.name;
|
json["SensorName"] = sensor_.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Regulator::load(const QJsonObject& json)
|
void Regulator::load(const QJsonObject& json, bool preserve)
|
||||||
{
|
{
|
||||||
Actor::load(json);
|
Actor::load(json, preserve);
|
||||||
band_ = json["Band"].toInt(1);
|
band_ = json["Band"].toInt(1);
|
||||||
setPoint_ = json["SetPoint"].toInt(22);
|
setPoint_ = json["SetPoint"].toInt(22);
|
||||||
sensor_.type = json["SensorType"].toInt(0);
|
sensor_.type = json["SensorType"].toInt(0);
|
||||||
@ -74,9 +73,9 @@ void Regulator::load(const QJsonObject& json)
|
|||||||
sensor_.name = json["SensorName"].toString("Sensor");
|
sensor_.name = json["SensorName"].toString("Sensor");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Regulator::getName()
|
QString Regulator::getName() const
|
||||||
{
|
{
|
||||||
if(name.size() > 0) return name;
|
if(name_.size() > 0) return name_;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString string;
|
QString string;
|
||||||
|
@ -12,6 +12,8 @@ private:
|
|||||||
float band_ = 1;
|
float band_ = 1;
|
||||||
bool invert_ = false;
|
bool invert_ = false;
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void sensorEvent(Sensor sensor);
|
void sensorEvent(Sensor sensor);
|
||||||
@ -28,9 +30,9 @@ public:
|
|||||||
Regulator(const Sensor sensor, QObject* parent = nullptr);
|
Regulator(const Sensor sensor, QObject* parent = nullptr);
|
||||||
Regulator(QObject* parent = nullptr);
|
Regulator(QObject* parent = nullptr);
|
||||||
Sensor getSensor(){return sensor_;}
|
Sensor getSensor(){return sensor_;}
|
||||||
virtual QString getName();
|
virtual QString getName() const;
|
||||||
virtual ~Regulator(){}
|
virtual ~Regulator(){}
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json);
|
virtual void load(const QJsonObject& json, bool preserve);
|
||||||
};
|
};
|
||||||
|
@ -59,9 +59,9 @@ void SensorActor::store(QJsonObject& json)
|
|||||||
json["SensorName"] = sensor_.name;
|
json["SensorName"] = sensor_.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorActor::load(const QJsonObject& json)
|
void SensorActor::load(const QJsonObject& json, bool preserve)
|
||||||
{
|
{
|
||||||
Actor::load(json);
|
Actor::load(json, preserve);
|
||||||
sloap_ = json["Sloap"].toInt(0);
|
sloap_ = json["Sloap"].toInt(0);
|
||||||
threshold_ = json["Threshold"].toDouble(0);
|
threshold_ = json["Threshold"].toDouble(0);
|
||||||
sensor_.type = json["SensorType"].toInt(0);
|
sensor_.type = json["SensorType"].toInt(0);
|
||||||
@ -70,9 +70,9 @@ void SensorActor::load(const QJsonObject& json)
|
|||||||
sensor_.name = json["SensorName"].toString("Sensor");
|
sensor_.name = json["SensorName"].toString("Sensor");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SensorActor::getName()
|
QString SensorActor::getName() const
|
||||||
{
|
{
|
||||||
if(name.size() > 0) return name;
|
if(name_.size() > 0) return name_;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString string;
|
QString string;
|
||||||
|
@ -29,14 +29,14 @@ public:
|
|||||||
SensorActor(const Sensor sensor, QObject* parent = nullptr);
|
SensorActor(const Sensor sensor, QObject* parent = nullptr);
|
||||||
SensorActor(QObject* parent = nullptr);
|
SensorActor(QObject* parent = nullptr);
|
||||||
Sensor getSensor(){return sensor_;}
|
Sensor getSensor(){return sensor_;}
|
||||||
virtual QString getName();
|
virtual QString getName() const;
|
||||||
virtual ~SensorActor(){}
|
virtual ~SensorActor(){}
|
||||||
|
|
||||||
float getThreshold();
|
float getThreshold();
|
||||||
uint8_t getSloap();
|
uint8_t getSloap();
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json);
|
virtual void load(const QJsonObject& json, bool preserve);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ void TimerActor::store(QJsonObject& json)
|
|||||||
json["Timeout"] = timeoutMsec_;
|
json["Timeout"] = timeoutMsec_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimerActor::load(const QJsonObject& json)
|
void TimerActor::load(const QJsonObject& json, bool preserve)
|
||||||
{
|
{
|
||||||
Actor::load(json);
|
Actor::load(json, preserve);
|
||||||
timeoutMsec_ = json["Timeout"].toInt(10000);
|
timeoutMsec_ = json["Timeout"].toInt(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,9 +45,9 @@ void TimerActor::timeout()
|
|||||||
performAction();
|
performAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TimerActor::getName()
|
QString TimerActor::getName() const
|
||||||
{
|
{
|
||||||
if(name.size() > 0) return name;
|
if(name_.size() > 0) return name_;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString string;
|
QString string;
|
||||||
|
@ -21,10 +21,10 @@ public slots:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
|
explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
|
||||||
virtual QString getName();
|
virtual QString getName() const;
|
||||||
|
|
||||||
int getTimeout();
|
int getTimeout();
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json);
|
virtual void load(const QJsonObject& json, bool preserve);
|
||||||
};
|
};
|
||||||
|
@ -81,12 +81,17 @@ void BroadCast::decode()
|
|||||||
qDebug()<<"after parse:";
|
qDebug()<<"after parse:";
|
||||||
qDebug()<<document.toJson().data();
|
qDebug()<<document.toJson().data();
|
||||||
QJsonObject jsonObject = document.object();
|
QJsonObject jsonObject = document.object();
|
||||||
if(error.error == QJsonParseError::NoError || document.isEmpty() || jsonObject.isEmpty()) gotJson(jsonObject);
|
if(error.error == QJsonParseError::NoError && !document.isEmpty() && !jsonObject.isEmpty()) gotJson(jsonObject);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug()<<error.errorString();
|
qDebug()<<error.errorString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(buffer_.size() >= 6 && buffer_[0] == 'S' && buffer_[1] == 'E' && buffer_[2] == 'N' && buffer_[3] == 'S' && buffer_[4] == 'O' && buffer_[5] == 'R')
|
||||||
|
{
|
||||||
|
Sensor sensor = Sensor::sensorFromString(buffer_);
|
||||||
|
if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BroadCast::readyRead()
|
void BroadCast::readyRead()
|
||||||
@ -106,4 +111,5 @@ void BroadCast::readyRead()
|
|||||||
}
|
}
|
||||||
else buffer_.clear();
|
else buffer_.clear();
|
||||||
}
|
}
|
||||||
|
else if(buffer_.contains('\n')) buffer_.clear();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include "sensors/sensor.h"
|
||||||
|
|
||||||
class BroadCast: public QObject
|
class BroadCast: public QObject
|
||||||
{
|
{
|
||||||
@ -38,6 +39,7 @@ signals:
|
|||||||
|
|
||||||
void jsonRequested();
|
void jsonRequested();
|
||||||
void gotJson(QJsonObject json);
|
void gotJson(QJsonObject json);
|
||||||
|
void gotSensorState(Sensor sensor);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "auxitem.h"
|
#include "auxitem.h"
|
||||||
|
|
||||||
AuxItem::AuxItem(SensorStore* sensors, Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(sensors, itemIdIn, name, value, parent), micro_(micro)
|
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public slots:
|
|||||||
virtual void setValue(uint8_t value);
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AuxItem(SensorStore* sensors, Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "../microcontroller.h"
|
#include "../microcontroller.h"
|
||||||
#include "../actors/sensoractor.h"
|
#include "../actors/sensoractor.h"
|
||||||
#include "../actors/regulator.h"
|
#include "../actors/regulator.h"
|
||||||
|
#include "../actors/polynomalactor.h"
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
@ -37,32 +38,34 @@ uint32_t ItemData::id() const
|
|||||||
|
|
||||||
bool Item::secondaryFlag = false;
|
bool Item::secondaryFlag = false;
|
||||||
|
|
||||||
Item::Item(SensorStore* sensors, uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name, value), sensors_(sensors)
|
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name, value)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Item(SensorStore* sensors, const ItemData& itemData, QObject *parent): QObject(parent), ItemData(itemData), sensors_(sensors)
|
Item::Item(const ItemData& itemData, QObject *parent): QObject(parent), ItemData(itemData)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::actorsActive() const
|
Item::~Item()
|
||||||
{
|
{
|
||||||
return actorsActive_;
|
for(size_t i = 0; i < actors_.size(); i++) delete actors_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::store(QJsonObject &json)
|
void Item::store(QJsonObject &json)
|
||||||
{
|
{
|
||||||
json["Name"] = name_;
|
json["Name"] = name_;
|
||||||
json["ItemId"] = static_cast<double>(itemId_);
|
json["ItemId"] = static_cast<double>(itemId_);
|
||||||
json["ActorsActive"] = actorsActive_;
|
|
||||||
QJsonArray actorsArray;
|
QJsonArray actorsArray;
|
||||||
for(size_t i = 0; i < actors_.size(); ++i)
|
for(size_t i = 0; i < actors_.size(); ++i)
|
||||||
{
|
{
|
||||||
QJsonObject actorObject;
|
if(!actors_[i]->isExausted())
|
||||||
actors_[i]->store(actorObject);
|
{
|
||||||
actorsArray.append(actorObject);
|
QJsonObject actorObject;
|
||||||
|
actors_[i]->store(actorObject);
|
||||||
|
actorsArray.append(actorObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
json["Actors"] = actorsArray;
|
json["Actors"] = actorsArray;
|
||||||
}
|
}
|
||||||
@ -74,7 +77,6 @@ void Item::load(const QJsonObject &json, const bool preserve)
|
|||||||
name_ = json["Name"].toString(name_);
|
name_ = json["Name"].toString(name_);
|
||||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||||
}
|
}
|
||||||
actorsActive_ = json["ActorsActive"].toBool(true);
|
|
||||||
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
|
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
|
||||||
for(int i = 0; i < actorsArray.size(); ++i)
|
for(int i = 0; i < actorsArray.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -101,17 +103,21 @@ void Item::addActor(Actor* actor)
|
|||||||
{
|
{
|
||||||
actor->setParent(this);
|
actor->setParent(this);
|
||||||
actors_.push_back(actor);
|
actors_.push_back(actor);
|
||||||
if(!secondaryFlag)connect(actor, &Actor::sigValue, this, &Item::setValue);
|
if(!secondaryFlag)
|
||||||
|
{
|
||||||
|
qDebug()<<"connecting actor";
|
||||||
|
connect(actor, &Actor::sigValue, this, &Item::setValue);
|
||||||
|
}
|
||||||
connect(this, &Item::valueChanged, actor, &Actor::onValueChanged);
|
connect(this, &Item::valueChanged, actor, &Actor::onValueChanged);
|
||||||
|
|
||||||
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
||||||
if(sensorActor != nullptr && sensors_ != nullptr)connect(sensors_, &SensorStore::sensorChangedState, sensorActor, &SensorActor::sensorEvent);
|
if(sensorActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor, &SensorActor::sensorEvent);
|
||||||
|
|
||||||
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
||||||
if(regulator != nullptr && sensors_ != nullptr)connect(sensors_, &SensorStore::sensorChangedState, regulator, &Regulator::sensorEvent);
|
if(regulator != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, regulator, &Regulator::sensorEvent);
|
||||||
|
|
||||||
if(actorsActive_) actor->makeActive();
|
PolynomalActor* polynomalActor = dynamic_cast<PolynomalActor*>(actor);
|
||||||
else actor->makeInactive();
|
if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor, &PolynomalActor::sensorEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::removeActor(Actor* actor)
|
bool Item::removeActor(Actor* actor)
|
||||||
@ -146,6 +152,5 @@ bool Item::hasActors()
|
|||||||
|
|
||||||
void Item::setActorsActive(bool in)
|
void Item::setActorsActive(bool in)
|
||||||
{
|
{
|
||||||
actorsActive_ = in;
|
|
||||||
for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "../actors/actor.h"
|
class Actor;
|
||||||
#include "../sensors/sensor.h"
|
|
||||||
|
|
||||||
class ItemData
|
class ItemData
|
||||||
{
|
{
|
||||||
@ -24,9 +23,9 @@ public:
|
|||||||
|
|
||||||
uint32_t id() const;
|
uint32_t id() const;
|
||||||
|
|
||||||
QString getName() const;
|
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
uint8_t getValue() const;
|
uint8_t getValue() const;
|
||||||
|
virtual QString getName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -35,12 +34,10 @@ class Item: public QObject, public ItemData
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
std::vector< Actor* > actors_;
|
std::vector< Actor* > actors_;
|
||||||
bool actorsActive_ = true;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static bool secondaryFlag;
|
static bool secondaryFlag;
|
||||||
SensorStore* sensors_;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@ -52,19 +49,18 @@ public slots:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Item(SensorStore* sensors = nullptr, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||||
Item(SensorStore* sensors, const ItemData& itemData, QObject *parent = nullptr);
|
Item(const ItemData& itemData, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
virtual ~Item();
|
||||||
|
|
||||||
std::vector< Actor* >& getActors();
|
std::vector< Actor* >& getActors();
|
||||||
bool hasActors();
|
bool hasActors();
|
||||||
void addActor(Actor* actor);
|
void addActor(Actor* actor);
|
||||||
bool removeActor(Actor* actor);
|
bool removeActor(Actor* actor);
|
||||||
void removeAllActors();
|
void removeAllActors();
|
||||||
bool actorsActive() const;
|
|
||||||
void setActorsActive(bool in);
|
void setActorsActive(bool in);
|
||||||
void informValue(uint8_t value);
|
void informValue(uint8_t value);
|
||||||
void setSensorStore(SensorStore* sensors){sensors_ = sensors;}
|
|
||||||
SensorStore* getSensorStore(){return sensors_;}
|
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "itemstore.h"
|
#include "itemstore.h"
|
||||||
#include "relay.h"
|
#include "relay.h"
|
||||||
|
#include "messageitem.h"
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
ItemStore::ItemStore(SensorStore* sensors, QObject *parent): QObject(parent), sensors_(sensors)
|
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,7 +14,6 @@ void ItemStore::addItem(std::shared_ptr<Item> item)
|
|||||||
if(!mached)
|
if(!mached)
|
||||||
{
|
{
|
||||||
items_.push_back(std::shared_ptr<Item>(item));
|
items_.push_back(std::shared_ptr<Item>(item));
|
||||||
items_.back()->setSensorStore(sensors_);
|
|
||||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||||
qDebug()<<"item added";
|
qDebug()<<"item added";
|
||||||
}
|
}
|
||||||
@ -49,6 +49,18 @@ void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemStore::removeItem(const ItemData& item)
|
||||||
|
{
|
||||||
|
for(unsigned j = 0; j < items_.size(); j++)
|
||||||
|
{
|
||||||
|
if(item == *items_[j])
|
||||||
|
{
|
||||||
|
items_.erase(items_.begin()+j);
|
||||||
|
--j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ItemStore::clear()
|
void ItemStore::clear()
|
||||||
{
|
{
|
||||||
@ -91,10 +103,14 @@ void ItemStore::load(const QJsonObject& json, Microcontroller * const micro)
|
|||||||
if(itemsArray[i].isObject())
|
if(itemsArray[i].isObject())
|
||||||
{
|
{
|
||||||
const QJsonObject itemObject = itemsArray[i].toObject();
|
const QJsonObject itemObject = itemsArray[i].toObject();
|
||||||
std::shared_ptr<Relay> newItem;
|
std::shared_ptr<Item> newItem;
|
||||||
if(itemObject["Type"].toString("") == "Relay")
|
if(itemObject["Type"].toString("") == "Relay")
|
||||||
{
|
{
|
||||||
newItem = std::shared_ptr<Relay>(new Relay(sensors_, micro));
|
newItem = std::shared_ptr<Relay>(new Relay(micro));
|
||||||
|
}
|
||||||
|
else if(itemObject["Type"].toString("") == "Message")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<MessageItem>(new MessageItem);
|
||||||
}
|
}
|
||||||
else if(itemObject["Type"].toString("") == "Aux")
|
else if(itemObject["Type"].toString("") == "Aux")
|
||||||
{
|
{
|
||||||
|
@ -13,11 +13,9 @@ class ItemStore: public QObject
|
|||||||
private:
|
private:
|
||||||
std::vector< std::shared_ptr<Item> > items_;
|
std::vector< std::shared_ptr<Item> > items_;
|
||||||
|
|
||||||
SensorStore* sensors_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ItemStore(SensorStore* sensors_ = nullptr, QObject *parent = nullptr);
|
ItemStore(QObject *parent = nullptr);
|
||||||
virtual ~ItemStore(){}
|
virtual ~ItemStore(){}
|
||||||
|
|
||||||
inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
|
inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
|
||||||
@ -34,6 +32,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
void removeItem(const ItemData& item);
|
||||||
void addItem(std::shared_ptr<Item> item);
|
void addItem(std::shared_ptr<Item> item);
|
||||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
||||||
void itemStateChanged(const ItemData& item);
|
void itemStateChanged(const ItemData& item);
|
||||||
|
72
src/items/messageitem.cpp
Normal file
72
src/items/messageitem.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "messageitem.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
MessageItem::MessageItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
|
||||||
|
Item(itemIdIn, name, value, parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageItem::MessageItem(const ItemData& itemData, QObject *parent):
|
||||||
|
Item(itemData, parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageItem::~MessageItem()
|
||||||
|
{
|
||||||
|
closeMessageBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageItem::setValue(uint8_t value)
|
||||||
|
{
|
||||||
|
Item::setValue(value);
|
||||||
|
if(value && !messageBox_)
|
||||||
|
{
|
||||||
|
messageBox_ = new QMessageBox(QMessageBox::NoIcon, name_, message_);
|
||||||
|
messageBox_->setModal(false);
|
||||||
|
connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
|
||||||
|
messageBox_->show();
|
||||||
|
//QTimer::singleShot(600000, this, &MessageItem::closeMessageBox);
|
||||||
|
}
|
||||||
|
else if(!value && messageBox_)
|
||||||
|
{
|
||||||
|
closeMessageBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageItem::closeMessageBox()
|
||||||
|
{
|
||||||
|
if(messageBox_)
|
||||||
|
{
|
||||||
|
value_ = 0;
|
||||||
|
messageBox_->hide();
|
||||||
|
delete messageBox_;
|
||||||
|
messageBox_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageItem::setMessage(const QString& in)
|
||||||
|
{
|
||||||
|
message_ = in;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MessageItem::getMessage()
|
||||||
|
{
|
||||||
|
return message_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageItem::store(QJsonObject &json)
|
||||||
|
{
|
||||||
|
json["Type"] = "Message";
|
||||||
|
Item::store(json);
|
||||||
|
json["Message"] = message_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageItem::load(const QJsonObject &json, const bool preserve)
|
||||||
|
{
|
||||||
|
Item::load(json,preserve);
|
||||||
|
message_ = json["Message"].toString("Invalid Message");
|
||||||
|
}
|
37
src/items/messageitem.h
Normal file
37
src/items/messageitem.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef MESSAGEITEM_H
|
||||||
|
#define MESSAGEITEM_H
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "item.h"
|
||||||
|
|
||||||
|
class MessageItem : public Item
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
|
||||||
|
QString message_;
|
||||||
|
QMessageBox* messageBox_ = nullptr;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void closeMessageBox();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MessageItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||||
|
MessageItem(const ItemData& itemData, QObject *parent = nullptr);
|
||||||
|
~MessageItem();
|
||||||
|
|
||||||
|
void setMessage(const QString& in);
|
||||||
|
QString getMessage();
|
||||||
|
|
||||||
|
virtual void store(QJsonObject& json);
|
||||||
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MESSAGEITEM_H
|
@ -2,9 +2,9 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
PowerItem::PowerItem(SensorStore* sensors, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(sensors, itemIdIn, name, value, parent)
|
PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent)
|
||||||
{
|
{
|
||||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0));
|
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||||
setValue(true);
|
setValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ void PowerItem::setValue(uint8_t value)
|
|||||||
if(!value)
|
if(!value)
|
||||||
{
|
{
|
||||||
QTimer::singleShot(5000, this, &PowerItem::timeout);
|
QTimer::singleShot(5000, this, &PowerItem::timeout);
|
||||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1));
|
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1, "Shutdown Imminent", true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public slots:
|
|||||||
virtual void setValue(uint8_t value);
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PowerItem(SensorStore* sensors, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
PowerItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||||
void emmitSensor(){stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0));}
|
void emmitSensor(){stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));}
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
//Relay
|
//Relay
|
||||||
|
|
||||||
Relay::Relay(SensorStore* sensors, Microcontroller* micro, uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(sensors, 0, name, state, parent), micro_(micro), id_(id), address_(address)
|
Relay::Relay(Microcontroller* micro, uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent), micro_(micro), id_(id), address_(address)
|
||||||
{
|
{
|
||||||
itemId_ = address | ((uint32_t)id << 16);
|
itemId_ = address | ((uint32_t)id << 16);
|
||||||
}
|
}
|
||||||
@ -38,9 +38,9 @@ void Relay::store(QJsonObject& json)
|
|||||||
json["Address"] = address_;
|
json["Address"] = address_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Relay::load(const QJsonObject& json)
|
void Relay::load(const QJsonObject& json, const bool preserve)
|
||||||
{
|
{
|
||||||
Item::load(json);
|
Item::load(json, preserve);
|
||||||
id_ = static_cast<uint8_t>(json["Id"].toInt(0));
|
id_ = static_cast<uint8_t>(json["Id"].toInt(0));
|
||||||
address_ = static_cast<uint16_t>(json["Address"].toInt(0));
|
address_ = static_cast<uint16_t>(json["Address"].toInt(0));
|
||||||
itemId_ = address_ | (static_cast<uint32_t>(id_) << 16);
|
itemId_ = address_ | (static_cast<uint32_t>(id_) << 16);
|
||||||
|
@ -26,13 +26,13 @@ public slots:
|
|||||||
void toggle();
|
void toggle();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Relay(SensorStore* sensors, Microcontroller* micro, uint8_t id = 0, QString name = "", uint16_t address = 0, bool state = false, QObject* parent = nullptr);
|
Relay(Microcontroller* micro, uint8_t id = 0, QString name = "", uint16_t address = 0, bool state = false, QObject* parent = nullptr);
|
||||||
|
|
||||||
uint16_t getAddress() const;
|
uint16_t getAddress() const;
|
||||||
uint8_t getId() const;
|
uint8_t getId() const;
|
||||||
void setId(uint8_t id);
|
void setId(uint8_t id);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json);
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
};
|
};
|
||||||
#endif // RELAY_H
|
#endif // RELAY_H
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "rgbitem.h"
|
#include "rgbitem.h"
|
||||||
|
|
||||||
RgbItem::RgbItem(SensorStore* sensors, Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(sensors, itemIdIn, name, value, parent), micro_(micro)
|
RgbItem::RgbItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public slots:
|
|||||||
virtual void setValue(uint8_t value);
|
virtual void setValue(uint8_t value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RgbItem(SensorStore* sensors, Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
RgbItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
@ -97,6 +97,9 @@ int main(int argc, char *argv[])
|
|||||||
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
||||||
masterIODevice = microPort;
|
masterIODevice = microPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
|
||||||
|
|
||||||
#else
|
#else
|
||||||
QTcpSocket* microSocket = new QTcpSocket;
|
QTcpSocket* microSocket = new QTcpSocket;
|
||||||
microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
|
microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
|
||||||
@ -106,14 +109,16 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
masterIODevice = microSocket;
|
masterIODevice = microSocket;
|
||||||
|
|
||||||
|
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
|
|
||||||
|
|
||||||
//mainwindow
|
//mainwindow
|
||||||
MainWindow w(&mainObject.micro, &mainObject.powerItem, &mainObject.items, &mainObject.sensors, !parser.isSet(secondaryOption));
|
MainWindow w(&mainObject);
|
||||||
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
||||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
||||||
|
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
||||||
if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
|
if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
|
||||||
|
|
||||||
w.show();
|
w.show();
|
||||||
|
@ -6,40 +6,35 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
|||||||
masterIODevice(ioDevice),
|
masterIODevice(ioDevice),
|
||||||
ioMultiplexer(masterIODevice),
|
ioMultiplexer(masterIODevice),
|
||||||
micro(ioMultiplexer.getIoDevice()),
|
micro(ioMultiplexer.getIoDevice()),
|
||||||
broadCast(ioMultiplexer.getIoDevice()),
|
broadCast(ioMultiplexer.getIoDevice(), masterIn),
|
||||||
settingsPath(settingsPathIn),
|
settingsPath(settingsPathIn),
|
||||||
sunSensorSource(49.884450, 8.650536),
|
sunSensorSource(49.884450, 8.650536),
|
||||||
items(&sensors),
|
rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
|
||||||
powerItem(&sensors),
|
auxItem(new AuxItem(µ, 5487421, "Desk Light"))
|
||||||
rgbItem(new RgbItem(&sensors, µ, 5487422, "Rgb Lights")),
|
|
||||||
auxItem(new AuxItem(&sensors, µ, 5487421, "Desk Light"))
|
|
||||||
|
|
||||||
{
|
{
|
||||||
qDebug()<<"Is master:"<<master;
|
qDebug()<<"Is master:"<<master;
|
||||||
//connect sensors subsystem
|
//connect sensors subsystem
|
||||||
QObject::connect(µ, &Microcontroller::gotSensorState, &sensors, &SensorStore::sensorGotState);
|
QObject::connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
||||||
QObject::connect(&livingroomSpeakerSensorSource, &SpeakerSensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
|
QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||||
QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
|
QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
|
||||||
QObject::connect(&sensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
|
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||||
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
|
|
||||||
|
|
||||||
QMetaObject::invokeMethod(&livingroomSpeakerSensorSource, "run", Qt::QueuedConnection);
|
|
||||||
sunSensorSource.run();
|
|
||||||
|
|
||||||
//connect item store
|
//connect item store
|
||||||
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
||||||
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
||||||
|
|
||||||
//special items
|
//special items
|
||||||
QObject::connect(&powerItem, &PowerItem::stateChanged, &sensors, &SensorStore::sensorGotState);
|
QObject::connect(&powerItem, &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||||
powerItem.emmitSensor();
|
powerItem.emmitSensor();
|
||||||
items.addItem(rgbItem);
|
items.addItem(rgbItem);
|
||||||
items.addItem(auxItem);
|
items.addItem(auxItem);
|
||||||
|
|
||||||
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
|
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
|
||||||
connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
if(master)connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
||||||
|
|
||||||
if(master) load(getJsonObjectFromDisk(settingsPath));
|
if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
broadCast.requestJson();
|
broadCast.requestJson();
|
||||||
@ -56,7 +51,7 @@ MainObject::~MainObject()
|
|||||||
{
|
{
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
store(json);
|
store(json);
|
||||||
storeJsonObjectToDisk(json, settingsPath);
|
if(!noSave)storeJsonObjectToDisk(json, settingsPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +68,7 @@ void MainObject::load(const QJsonObject& json)
|
|||||||
items.clear();
|
items.clear();
|
||||||
rgbItem->removeAllActors();
|
rgbItem->removeAllActors();
|
||||||
auxItem->removeAllActors();
|
auxItem->removeAllActors();
|
||||||
|
powerItem.removeAllActors();
|
||||||
items.addItem(rgbItem);
|
items.addItem(rgbItem);
|
||||||
items.addItem(auxItem);
|
items.addItem(auxItem);
|
||||||
items.load(json, µ);
|
items.load(json, µ);
|
||||||
@ -99,7 +95,7 @@ void MainObject::sendJson()
|
|||||||
broadCast.sendJson(json);
|
broadCast.sendJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath)
|
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* error)
|
||||||
{
|
{
|
||||||
QFile file;
|
QFile file;
|
||||||
|
|
||||||
@ -115,25 +111,30 @@ QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath)
|
|||||||
if(!file.isOpen()) std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
|
if(!file.isOpen()) std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QJsonDocument document(QJsonDocument::fromJson(file.readAll()));
|
QJsonParseError qerror;
|
||||||
|
QJsonDocument document(QJsonDocument::fromJson(file.readAll(), &qerror));
|
||||||
file.close();
|
file.close();
|
||||||
|
if(qerror.error != QJsonParseError::NoError)
|
||||||
|
{
|
||||||
|
qDebug()<<filePath<<" "<<qerror.errorString();
|
||||||
|
if(error) (*error) = true;
|
||||||
|
}
|
||||||
return document.object();
|
return document.object();
|
||||||
}
|
}
|
||||||
return QJsonObject();
|
return QJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, const QString& filePath)
|
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath)
|
||||||
{
|
{
|
||||||
QFile file;
|
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
if(filePath.size() > 0) file.setFileName(filePath);
|
if(filePath.size() == 0)
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
|
filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json";
|
||||||
}
|
}
|
||||||
std::cout<<"config file: "<<file.fileName().toLatin1().data()<<std::endl;
|
QFile file(filePath + ".out");
|
||||||
|
|
||||||
|
qDebug()<<"config file: "<<filePath;
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
if(!file.isOpen())
|
if(!file.isOpen())
|
||||||
{
|
{
|
||||||
@ -145,6 +146,8 @@ bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, const QString& f
|
|||||||
QJsonDocument document(json);
|
QJsonDocument document(json);
|
||||||
file.write(document.toJson());
|
file.write(document.toJson());
|
||||||
file.close();
|
file.close();
|
||||||
|
QFile::remove(filePath);
|
||||||
|
file.rename(filePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ public:
|
|||||||
//io
|
//io
|
||||||
const bool master;
|
const bool master;
|
||||||
|
|
||||||
|
bool noSave = false;
|
||||||
|
|
||||||
QIODevice * const masterIODevice = nullptr;
|
QIODevice * const masterIODevice = nullptr;
|
||||||
IoMuliplexer ioMultiplexer;
|
IoMuliplexer ioMultiplexer;
|
||||||
|
|
||||||
@ -50,12 +52,9 @@ public:
|
|||||||
const QString settingsPath;
|
const QString settingsPath;
|
||||||
|
|
||||||
//sensors
|
//sensors
|
||||||
SpeakerSensorSource livingroomSpeakerSensorSource;
|
|
||||||
SunSensorSource sunSensorSource;
|
SunSensorSource sunSensorSource;
|
||||||
OcupancySensorSource ocupancySensor;
|
OcupancySensorSource ocupancySensor;
|
||||||
|
|
||||||
SensorStore sensors;
|
|
||||||
|
|
||||||
//items
|
//items
|
||||||
ItemStore items;
|
ItemStore items;
|
||||||
|
|
||||||
@ -65,8 +64,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "");
|
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
|
||||||
static bool storeJsonObjectToDisk(const QJsonObject& json, const QString& filePath = "");
|
static bool storeJsonObjectToDisk(const QJsonObject& json, QString filePath = "");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent = nullptr);
|
explicit MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent = nullptr);
|
||||||
|
@ -131,7 +131,7 @@ std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
|
|||||||
if(name.size() > 1)name.remove(name.size()-1, 1);
|
if(name.size() > 1)name.remove(name.size()-1, 1);
|
||||||
else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2));
|
else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2));
|
||||||
qDebug()<<"Relay "<<bufferList[2].toInt()<<"Name "<<name<<" id "<<bufferList[4].toInt(nullptr, 2)<<" state "<<bufferList[6].toInt();
|
qDebug()<<"Relay "<<bufferList[2].toInt()<<"Name "<<name<<" id "<<bufferList[4].toInt(nullptr, 2)<<" state "<<bufferList[6].toInt();
|
||||||
return std::shared_ptr<Relay>( new Relay(nullptr, this, bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), bufferList[6].toInt()));
|
return std::shared_ptr<Relay>( new Relay(this, bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), bufferList[6].toInt()));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -160,10 +160,8 @@ void Microcontroller::processRelayState(const QString& buffer)
|
|||||||
|
|
||||||
void Microcontroller::processSensorState(const QString& buffer)
|
void Microcontroller::processSensorState(const QString& buffer)
|
||||||
{
|
{
|
||||||
QStringList bufferList = buffer.split(' ');
|
Sensor sensor = Sensor::sensorFromString(buffer);
|
||||||
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
|
if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
|
||||||
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) sensor.field = sensor.field/10;
|
|
||||||
if(bufferList.size() >= 7)gotSensorState(sensor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
SensorStore globalSensors;
|
||||||
|
|
||||||
SensorStore::SensorStore(QObject *parent): QObject(parent)
|
SensorStore::SensorStore(QObject *parent): QObject(parent)
|
||||||
{
|
{
|
||||||
sensors_.push_back(Sensor(0,1,0,"Front door"));
|
sensors_.push_back(Sensor(0,1,0,"Front door"));
|
||||||
@ -43,3 +45,5 @@ void SensorStore::sensorGotState(const Sensor& sensor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ public:
|
|||||||
static constexpr uint8_t TYPE_HUMIDITY = 2;
|
static constexpr uint8_t TYPE_HUMIDITY = 2;
|
||||||
static constexpr uint8_t TYPE_PRESSURE = 3;
|
static constexpr uint8_t TYPE_PRESSURE = 3;
|
||||||
static constexpr uint8_t TYPE_BRIGHTNESS = 4;
|
static constexpr uint8_t TYPE_BRIGHTNESS = 4;
|
||||||
|
static constexpr uint8_t TYPE_BUTTON = 5;
|
||||||
static constexpr uint8_t TYPE_LOWBATTERY = 128;
|
static constexpr uint8_t TYPE_LOWBATTERY = 128;
|
||||||
static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
|
static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
|
||||||
static constexpr uint8_t TYPE_OCUPANCY = 252;
|
static constexpr uint8_t TYPE_OCUPANCY = 252;
|
||||||
@ -26,23 +27,36 @@ public:
|
|||||||
float field;
|
float field;
|
||||||
QString name;
|
QString name;
|
||||||
QDateTime lastSeen;
|
QDateTime lastSeen;
|
||||||
|
bool hidden;
|
||||||
|
|
||||||
Sensor(uint8_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = ""): type(typeIn), id(idIn), field(fieldIn), name(nameIn)
|
Sensor(uint8_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn), id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
||||||
{
|
{
|
||||||
lastSeen = QDateTime::currentDateTime();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
if(nameIn == "") generateName();
|
if(nameIn == "") generateName();
|
||||||
}
|
}
|
||||||
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn)
|
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
|
||||||
{
|
{
|
||||||
lastSeen = QDateTime::currentDateTime();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
inline bool operator==(const Sensor& in){ return type==in.type && id == in.id; }
|
inline bool operator==(const Sensor& in) const{ return type==in.type && id == in.id; }
|
||||||
inline bool operator!=(const Sensor& in){ return !(*this==in); }
|
inline bool operator!=(const Sensor& in) const{ return !(*this==in); }
|
||||||
inline void updateSeen(){lastSeen = QDateTime::currentDateTime();}
|
inline void updateSeen(){lastSeen = QDateTime::currentDateTime();}
|
||||||
|
static Sensor sensorFromString(const QString& str)
|
||||||
|
{
|
||||||
|
QStringList bufferList = str.split(' ');
|
||||||
|
if(bufferList.size() >= 7)
|
||||||
|
{
|
||||||
|
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
|
||||||
|
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) sensor.field = sensor.field/10;
|
||||||
|
return sensor;
|
||||||
|
}
|
||||||
|
else return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
||||||
|
}
|
||||||
inline void generateName()
|
inline void generateName()
|
||||||
{
|
{
|
||||||
if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
|
if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
|
||||||
else if(type == TYPE_DOOR) name = "Door " + QString::number(id);
|
else if(type == TYPE_DOOR) name = "Door " + QString::number(id);
|
||||||
|
else if(type == TYPE_BUTTON) name = "Button " + QString::number(id);
|
||||||
else if(type == TYPE_AUDIO_OUTPUT) name = "Speakers " + QString::number(id);
|
else if(type == TYPE_AUDIO_OUTPUT) name = "Speakers " + QString::number(id);
|
||||||
else if(type == TYPE_HUMIDITY) name = "Humidity " + QString::number(id);
|
else if(type == TYPE_HUMIDITY) name = "Humidity " + QString::number(id);
|
||||||
else if(type == TYPE_SUN_ALTITUDE) name = "Solar Altitude";
|
else if(type == TYPE_SUN_ALTITUDE) name = "Solar Altitude";
|
||||||
@ -64,6 +78,7 @@ public:
|
|||||||
|
|
||||||
inline std::vector<Sensor>* getSensors(){ return &sensors_; }
|
inline std::vector<Sensor>* getSensors(){ return &sensors_; }
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void sensorGotState(const Sensor& sensor);
|
void sensorGotState(const Sensor& sensor);
|
||||||
@ -75,3 +90,5 @@ signals:
|
|||||||
void sensorDeleted(Sensor sensor);
|
void sensorDeleted(Sensor sensor);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern SensorStore globalSensors;
|
||||||
|
@ -179,9 +179,3 @@ double Sun::declination()
|
|||||||
double meanSolarAnomalyValue = meanSolarAnomaly(meanSolarNoonValue);
|
double meanSolarAnomalyValue = meanSolarAnomaly(meanSolarNoonValue);
|
||||||
return solarDeclination(eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue));
|
return solarDeclination(eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double maximumAltitude()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "actorsettingsdialog.h"
|
#include "actorsettingsdialog.h"
|
||||||
#include "ui_actorsettingsdialog.h"
|
#include "ui_actorsettingsdialog.h"
|
||||||
|
#include "itemsettingsdialog.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
|
||||||
@ -14,25 +15,25 @@ ActorSettingsDialog::ActorSettingsDialog(AlarmTime* alarm, QWidget *parent):
|
|||||||
ui->vertlayout->addWidget(widget);
|
ui->vertlayout->addWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorSettingsDialog::ActorSettingsDialog(SensorActor* actor, SensorStore* sensors, QWidget *parent) :
|
ActorSettingsDialog::ActorSettingsDialog(SensorActor* actor, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
actor_(actor),
|
actor_(actor),
|
||||||
ui(new Ui::ActorSettingsDialog)
|
ui(new Ui::ActorSettingsDialog)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
|
||||||
widget = new SensorActorWidget(actor, sensors, this);
|
widget = new SensorActorWidget(actor, &globalSensors, this);
|
||||||
ui->vertlayout->addWidget(widget);
|
ui->vertlayout->addWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorSettingsDialog::ActorSettingsDialog(Regulator* actor, SensorStore* sensors, QWidget *parent) :
|
ActorSettingsDialog::ActorSettingsDialog(Regulator* actor, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
actor_(actor),
|
actor_(actor),
|
||||||
ui(new Ui::ActorSettingsDialog)
|
ui(new Ui::ActorSettingsDialog)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
|
||||||
widget = new RegulatorWdiget(actor, sensors, this);
|
widget = new RegulatorWdiget(actor, &globalSensors, this);
|
||||||
ui->vertlayout->addWidget(widget);
|
ui->vertlayout->addWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +48,26 @@ ui(new Ui::ActorSettingsDialog)
|
|||||||
ui->vertlayout->addWidget(widget);
|
ui->vertlayout->addWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActorSettingsDialog::ActorSettingsDialog(PolynomalActor* actor, QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
actor_(actor),
|
||||||
|
ui(new Ui::ActorSettingsDialog)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
widget = new PolynomalActorWidget(actor, &globalSensors, this);
|
||||||
|
ui->vertlayout->addWidget(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
ActorSettingsDialog::ActorSettingsDialog(MultiFactorActor* actor, QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
actor_(actor),
|
||||||
|
ui(new Ui::ActorSettingsDialog)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
widget = new FactorActorWidget(actor, this);
|
||||||
|
ui->vertlayout->addWidget(widget);
|
||||||
|
}
|
||||||
|
|
||||||
ActorSettingsDialog::ActorSettingsDialog(Actor* actor, QWidget *parent) :
|
ActorSettingsDialog::ActorSettingsDialog(Actor* actor, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
@ -61,6 +82,7 @@ void ActorSettingsDialog::init()
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int)));
|
connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int)));
|
||||||
connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
|
connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
|
||||||
|
connect(ui->pushButton_editItem, &QPushButton::clicked, this, &ActorSettingsDialog::editAsItem);
|
||||||
ui->spinBox->hide();
|
ui->spinBox->hide();
|
||||||
|
|
||||||
ui->spinBox->setValue(actor_->getTriggerValue());
|
ui->spinBox->setValue(actor_->getTriggerValue());
|
||||||
@ -74,6 +96,12 @@ ActorSettingsDialog::~ActorSettingsDialog()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActorSettingsDialog::editAsItem()
|
||||||
|
{
|
||||||
|
ItemSettingsDialog itemSettingsDiag(actor_, this);
|
||||||
|
itemSettingsDiag.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void ActorSettingsDialog::valueChanged(int value)
|
void ActorSettingsDialog::valueChanged(int value)
|
||||||
{
|
{
|
||||||
actor_->setTriggerValue(value);
|
actor_->setTriggerValue(value);
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include "actorwidgets/sensoractorwidget.h"
|
#include "actorwidgets/sensoractorwidget.h"
|
||||||
#include "actorwidgets/timeractorwidget.h"
|
#include "actorwidgets/timeractorwidget.h"
|
||||||
#include "actorwidgets/regulatorwdiget.h"
|
#include "actorwidgets/regulatorwdiget.h"
|
||||||
|
#include "actorwidgets/polynomalactorwidget.h"
|
||||||
|
#include "actorwidgets/factoractorwidget.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ActorSettingsDialog;
|
class ActorSettingsDialog;
|
||||||
@ -24,9 +26,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ActorSettingsDialog(AlarmTime* actor, QWidget *parent = nullptr);
|
ActorSettingsDialog(AlarmTime* actor, QWidget *parent = nullptr);
|
||||||
ActorSettingsDialog(SensorActor* actor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
ActorSettingsDialog(SensorActor* actor, QWidget *parent = nullptr);
|
||||||
ActorSettingsDialog(Regulator* actor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
ActorSettingsDialog(Regulator* actor, QWidget *parent = nullptr);
|
||||||
ActorSettingsDialog(TimerActor* actor, QWidget *parent);
|
ActorSettingsDialog(TimerActor* actor, QWidget *parent = nullptr);
|
||||||
|
ActorSettingsDialog(PolynomalActor* actor, QWidget *parent = nullptr);
|
||||||
|
ActorSettingsDialog(MultiFactorActor* actor, QWidget *parent = nullptr);
|
||||||
ActorSettingsDialog(Actor* actor, QWidget *parent);
|
ActorSettingsDialog(Actor* actor, QWidget *parent);
|
||||||
~ActorSettingsDialog();
|
~ActorSettingsDialog();
|
||||||
|
|
||||||
@ -35,6 +39,7 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void changeAction(int index);
|
void changeAction(int index);
|
||||||
void valueChanged(int value);
|
void valueChanged(int value);
|
||||||
|
void editAsItem();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -63,6 +63,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_editItem">
|
||||||
|
<property name="text">
|
||||||
|
<string>Edit as item</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void toggleRepeating(int state);
|
void toggleRepeating(int state);
|
||||||
void setRepeatingType();
|
void setRepeatingType();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AlarmWidget *ui;
|
Ui::AlarmWidget *ui;
|
||||||
|
85
src/ui/actorwidgets/factoractorwidget.cpp
Normal file
85
src/ui/actorwidgets/factoractorwidget.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include "factoractorwidget.h"
|
||||||
|
#include "ui_factoractorwidget.h"
|
||||||
|
#include "../actorsettingsdialog.h"
|
||||||
|
|
||||||
|
FactorActorWidget::FactorActorWidget(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;
|
||||||
|
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")
|
||||||
|
{
|
||||||
|
SensorActor* sensorActor = new SensorActor();
|
||||||
|
actor = sensorActor;
|
||||||
|
dialog = new ActorSettingsDialog(sensorActor, this);
|
||||||
|
}
|
||||||
|
else if(ui->comboBox->currentText() == "Timer" )
|
||||||
|
{
|
||||||
|
TimerActor* timerActor = new TimerActor();
|
||||||
|
actor = timerActor;
|
||||||
|
dialog = new ActorSettingsDialog(timerActor, this);
|
||||||
|
}
|
||||||
|
else if(ui->comboBox->currentText() == "Regulator")
|
||||||
|
{
|
||||||
|
Regulator* regulator = new Regulator();
|
||||||
|
actor = regulator;
|
||||||
|
dialog = new ActorSettingsDialog(regulator, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(ui->comboBox->currentText() == "Polynomal")
|
||||||
|
{
|
||||||
|
PolynomalActor* 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());
|
||||||
|
}
|
||||||
|
else delete actor;
|
||||||
|
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);
|
||||||
|
}
|
30
src/ui/actorwidgets/factoractorwidget.h
Normal file
30
src/ui/actorwidgets/factoractorwidget.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef FACTORACTORWIDGET_H
|
||||||
|
#define FACTORACTORWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include "../../actors/factoractor.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class FactorActorWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class FactorActorWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
MultiFactorActor* actor_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit FactorActorWidget(MultiFactorActor* actor, QWidget *parent = nullptr);
|
||||||
|
~FactorActorWidget();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void createFactorActor();
|
||||||
|
void setDirection(const QString& direction);
|
||||||
|
void setPreCancleTime(int time);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::FactorActorWidget *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FACTORACTORWIDGET_H
|
136
src/ui/actorwidgets/factoractorwidget.ui
Normal file
136
src/ui/actorwidgets/factoractorwidget.ui
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>FactorActorWidget</class>
|
||||||
|
<widget class="QWidget" name="FactorActorWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>395</width>
|
||||||
|
<height>169</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QComboBox" name="comboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Sensor</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Polynomal</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Alarm</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Timer</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Regulator</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QLabel" name="label_FactorActor">
|
||||||
|
<property name="text">
|
||||||
|
<string>None</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Create Factor</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Factor Direciton:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QComboBox" name="comboBox_Direcion">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>True</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>False</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Current Factor:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Factor time tollerance</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="spinBox">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Min</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
48
src/ui/actorwidgets/polynomalactorwidget.cpp
Normal file
48
src/ui/actorwidgets/polynomalactorwidget.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "polynomalactorwidget.h"
|
||||||
|
#include "ui_polynomalactorwidget.h"
|
||||||
|
|
||||||
|
PolynomalActorWidget::PolynomalActorWidget(PolynomalActor* actor, SensorStore* sensors, QWidget *parent):
|
||||||
|
QWidget(parent),
|
||||||
|
sensors_(sensors),
|
||||||
|
actor_(actor),
|
||||||
|
ui(new Ui::PolynomalActorWidget)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->listView->hide();
|
||||||
|
ui->label->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
double pow3, pow2, pow1, pow0;
|
||||||
|
|
||||||
|
actor_->getCoeffiancts(pow3, pow2, pow1, pow0);
|
||||||
|
|
||||||
|
ui->doubleSpinBox_pow0->setValue(pow0);
|
||||||
|
ui->doubleSpinBox_pow1->setValue(pow1);
|
||||||
|
ui->doubleSpinBox_pow2->setValue(pow2);
|
||||||
|
ui->doubleSpinBox_pow3->setValue(pow3);
|
||||||
|
|
||||||
|
connect(ui->doubleSpinBox_pow3, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
|
||||||
|
connect(ui->doubleSpinBox_pow2, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
|
||||||
|
connect(ui->doubleSpinBox_pow1, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
|
||||||
|
connect(ui->doubleSpinBox_pow0, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
|
||||||
|
connect(ui->listView, &SensorListWidget::clicked, this, &PolynomalActorWidget::setSensor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PolynomalActorWidget::~PolynomalActorWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolynomalActorWidget::setPow()
|
||||||
|
{
|
||||||
|
actor_->setCoeffiancts(ui->doubleSpinBox_pow3->value(), ui->doubleSpinBox_pow2->value(), ui->doubleSpinBox_pow1->value(), ui->doubleSpinBox_pow0->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PolynomalActorWidget::setSensor(const QModelIndex &index)
|
||||||
|
{
|
||||||
|
actor_->setSensor(sensors_->getSensors()->at(index.row()));
|
||||||
|
}
|
30
src/ui/actorwidgets/polynomalactorwidget.h
Normal file
30
src/ui/actorwidgets/polynomalactorwidget.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef POLYNOMALACTORWIDGET_H
|
||||||
|
#define POLYNOMALACTORWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include "../../actors/polynomalactor.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class PolynomalActorWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class PolynomalActorWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
SensorStore* sensors_;
|
||||||
|
PolynomalActor* actor_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PolynomalActorWidget(PolynomalActor* regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||||
|
~PolynomalActorWidget();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void setPow();
|
||||||
|
void setSensor(const QModelIndex &index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::PolynomalActorWidget *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // POLYNOMALACTORWIDGET_H
|
140
src/ui/actorwidgets/polynomalactorwidget.ui
Normal file
140
src/ui/actorwidgets/polynomalactorwidget.ui
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>PolynomalActorWidget</class>
|
||||||
|
<widget class="QWidget" name="PolynomalActorWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>420</width>
|
||||||
|
<height>306</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Select Sensor</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="SensorListWidget" name="listView">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_pow3">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<double>0.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>x³+</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_pow2">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>x²+</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_pow1">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<double>1.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>x+</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_pow0">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>500.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>SensorListWidget</class>
|
||||||
|
<extends>QListView</extends>
|
||||||
|
<header location="global">../src/ui/sensorlistwidget.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
45
src/ui/itemcreationdialog.cpp
Normal file
45
src/ui/itemcreationdialog.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "itemcreationdialog.h"
|
||||||
|
#include "ui_itemcreationdialog.h"
|
||||||
|
|
||||||
|
#include "itemsettingswidgets/messageitemsettingswidget.h"
|
||||||
|
|
||||||
|
ItemCreationDialog::ItemCreationDialog(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::ItemCreationDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
std::shared_ptr<MessageItem> messageItem(new MessageItem);
|
||||||
|
item = messageItem;
|
||||||
|
widget = new MessageItemSettingsWidget(messageItem, this);
|
||||||
|
ui->verticalLayout->addWidget(widget);
|
||||||
|
connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged);
|
||||||
|
connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemCreationDialog::~ItemCreationDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
delete widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemCreationDialog::itemTypeChanged(const QString& type)
|
||||||
|
{
|
||||||
|
ui->verticalLayout->removeWidget(widget);
|
||||||
|
delete widget;
|
||||||
|
if(type == "Message")
|
||||||
|
{
|
||||||
|
std::shared_ptr<MessageItem> messageItem(new MessageItem);
|
||||||
|
item = messageItem;
|
||||||
|
widget = new MessageItemSettingsWidget(messageItem, this);
|
||||||
|
ui->verticalLayout_2->addWidget(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemCreationDialog::itemNameChanged(const QString& name)
|
||||||
|
{
|
||||||
|
if(item)
|
||||||
|
{
|
||||||
|
item->setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
33
src/ui/itemcreationdialog.h
Normal file
33
src/ui/itemcreationdialog.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef ITEMCREATIONDIALOG_H
|
||||||
|
#define ITEMCREATIONDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <memory>
|
||||||
|
#include "../items/item.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ItemCreationDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ItemCreationDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QWidget* widget;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ItemCreationDialog(QWidget *parent = nullptr);
|
||||||
|
~ItemCreationDialog();
|
||||||
|
|
||||||
|
std::shared_ptr<Item> item;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void itemTypeChanged(const QString& type);
|
||||||
|
void itemNameChanged(const QString& name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ItemCreationDialog *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ITEMCREATIONDIALOG_H
|
111
src/ui/itemcreationdialog.ui
Normal file
111
src/ui/itemcreationdialog.ui
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ItemCreationDialog</class>
|
||||||
|
<widget class="QDialog" name="ItemCreationDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>140</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Create Item</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="../../resources.qrc">
|
||||||
|
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Type</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Message</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Item</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../../resources.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ItemCreationDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ItemCreationDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -1,6 +1,7 @@
|
|||||||
#include "itemscrollbox.h"
|
#include "itemscrollbox.h"
|
||||||
#include "ui_relayscrollbox.h"
|
#include "ui_relayscrollbox.h"
|
||||||
#include "../items/auxitem.h"
|
#include "../items/auxitem.h"
|
||||||
|
#include "../items/messageitem.h"
|
||||||
|
|
||||||
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
@ -24,11 +25,17 @@ void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
|||||||
{
|
{
|
||||||
widgets_.push_back(new ItemWidget(item, true));
|
widgets_.push_back(new ItemWidget(item, true));
|
||||||
}
|
}
|
||||||
|
else if(dynamic_cast<MessageItem*>(workItem.get()))
|
||||||
|
{
|
||||||
|
widgets_.push_back(new ItemWidget(item, false, true));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
widgets_.push_back(new ItemWidget(item));
|
widgets_.push_back(new ItemWidget(item));
|
||||||
}
|
}
|
||||||
ui->relayWidgetVbox->addWidget(widgets_.back());
|
ui->relayWidgetVbox->addWidget(widgets_.back());
|
||||||
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
||||||
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,10 @@ class ItemScrollBox : public QWidget
|
|||||||
private:
|
private:
|
||||||
std::vector< ItemWidget* > widgets_;
|
std::vector< ItemWidget* > widgets_;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void deleteRequest(const ItemData& item);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemScrollBox(QWidget *parent = nullptr);
|
explicit ItemScrollBox(QWidget *parent = nullptr);
|
||||||
~ItemScrollBox();
|
~ItemScrollBox();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "../actors/sensoractor.h"
|
#include "../actors/sensoractor.h"
|
||||||
#include "../actors/timeractor.h"
|
#include "../actors/timeractor.h"
|
||||||
#include "../actors/regulator.h"
|
#include "../actors/regulator.h"
|
||||||
|
#include "../actors/factoractor.h"
|
||||||
|
|
||||||
#include<memory>
|
#include<memory>
|
||||||
|
|
||||||
@ -31,21 +32,17 @@ ItemSettingsDialog::ItemSettingsDialog(Item* item, QWidget *parent) :
|
|||||||
ui->label_address_lable->hide();
|
ui->label_address_lable->hide();
|
||||||
ui->label_id_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_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
|
||||||
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
|
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
|
||||||
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
|
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
|
||||||
|
|
||||||
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
||||||
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
||||||
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Acts on"));
|
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
|
||||||
ui->tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem("Enabled"));
|
|
||||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
||||||
ui->tableWidget->horizontalHeader()->resizeSection(2, 60);
|
ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
|
||||||
ui->tableWidget->horizontalHeader()->resizeSection(3, 75);
|
|
||||||
loadActorList();
|
loadActorList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +60,7 @@ void ItemSettingsDialog::loadActorList()
|
|||||||
{
|
{
|
||||||
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
|
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, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
|
||||||
ui->tableWidget->setItem(i, 2, new QTableWidgetItem("Item"));
|
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
||||||
ui->tableWidget->setItem(i, 3, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,11 +75,11 @@ void ItemSettingsDialog::addActor()
|
|||||||
actor = alarm;
|
actor = alarm;
|
||||||
dialog = new ActorSettingsDialog(alarm, this);
|
dialog = new ActorSettingsDialog(alarm, this);
|
||||||
}
|
}
|
||||||
else if(ui->comboBox->currentText() == "Sensor" && item_->getSensorStore() != nullptr)
|
else if(ui->comboBox->currentText() == "Sensor")
|
||||||
{
|
{
|
||||||
SensorActor* sensorActor = new SensorActor();
|
SensorActor* sensorActor = new SensorActor();
|
||||||
actor = sensorActor;
|
actor = sensorActor;
|
||||||
dialog = new ActorSettingsDialog(sensorActor, item_->getSensorStore(), this);
|
dialog = new ActorSettingsDialog(sensorActor, this);
|
||||||
}
|
}
|
||||||
else if(ui->comboBox->currentText() == "Timer" )
|
else if(ui->comboBox->currentText() == "Timer" )
|
||||||
{
|
{
|
||||||
@ -91,11 +87,25 @@ void ItemSettingsDialog::addActor()
|
|||||||
actor = timerActor;
|
actor = timerActor;
|
||||||
dialog = new ActorSettingsDialog(timerActor, this);
|
dialog = new ActorSettingsDialog(timerActor, this);
|
||||||
}
|
}
|
||||||
else if(ui->comboBox->currentText() == "Regulator" && item_->getSensorStore() != nullptr)
|
else if(ui->comboBox->currentText() == "Regulator")
|
||||||
{
|
{
|
||||||
Regulator* regulator = new Regulator();
|
Regulator* regulator = new Regulator();
|
||||||
actor = regulator;
|
actor = regulator;
|
||||||
dialog = new ActorSettingsDialog(regulator, item_->getSensorStore(), this);
|
dialog = new ActorSettingsDialog(regulator, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(ui->comboBox->currentText() == "Polynomal")
|
||||||
|
{
|
||||||
|
PolynomalActor* polynomalActor = new PolynomalActor();
|
||||||
|
actor = polynomalActor;
|
||||||
|
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(ui->comboBox->currentText() == "Multi Factor")
|
||||||
|
{
|
||||||
|
MultiFactorActor* polynomalActor = new MultiFactorActor();
|
||||||
|
actor = polynomalActor;
|
||||||
|
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -133,13 +143,17 @@ void ItemSettingsDialog::editActor()
|
|||||||
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
||||||
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
||||||
TimerActor* timerActor = dynamic_cast<TimerActor*>(actor);
|
TimerActor* timerActor = dynamic_cast<TimerActor*>(actor);
|
||||||
|
PolynomalActor* polynomalActor = dynamic_cast<PolynomalActor*>(actor);
|
||||||
|
MultiFactorActor* factorActor = dynamic_cast<MultiFactorActor*>(actor);
|
||||||
|
|
||||||
ActorSettingsDialog* dialog;
|
ActorSettingsDialog* dialog;
|
||||||
|
|
||||||
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
||||||
else if(regulator) dialog = new ActorSettingsDialog(regulator, nullptr, this);
|
else if(regulator) dialog = new ActorSettingsDialog(regulator, this);
|
||||||
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, nullptr, this);
|
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
|
||||||
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
||||||
|
else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||||
|
else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
|
||||||
else dialog = new ActorSettingsDialog(actor, this);
|
else dialog = new ActorSettingsDialog(actor, this);
|
||||||
dialog->setParent(this);
|
dialog->setParent(this);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
@ -149,7 +163,7 @@ void ItemSettingsDialog::editActor()
|
|||||||
{
|
{
|
||||||
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
||||||
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
||||||
ui->tableWidget->item(i, 3)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
|
ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,13 +94,6 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="checkBox_auto">
|
|
||||||
<property name="text">
|
|
||||||
<string>Actors enabled</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="tableWidget">
|
<widget class="QTableWidget" name="tableWidget">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
@ -143,7 +136,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="columnCount">
|
<property name="columnCount">
|
||||||
<number>4</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="horizontalHeaderVisible">
|
<attribute name="horizontalHeaderVisible">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -163,7 +156,6 @@
|
|||||||
<column/>
|
<column/>
|
||||||
<column/>
|
<column/>
|
||||||
<column/>
|
<column/>
|
||||||
<column/>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -214,7 +206,7 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Linear</string>
|
<string>Polynomal</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -232,6 +224,11 @@
|
|||||||
<string>Timer</string>
|
<string>Timer</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Multi Factor</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
|
|
||||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, QWidget *parent) :
|
ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, bool nameOnly, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
item_(item),
|
item_(item),
|
||||||
ui(new Ui::ItemWidget)
|
ui(new Ui::ItemWidget)
|
||||||
@ -17,10 +17,12 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, QWidget *parent) :
|
|||||||
ui->horizontalSpacer->changeSize(0,0);
|
ui->horizontalSpacer->changeSize(0,0);
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
}
|
}
|
||||||
else
|
else if(nameOnly)
|
||||||
{
|
{
|
||||||
|
ui->checkBox->hide();
|
||||||
ui->slider->hide();
|
ui->slider->hide();
|
||||||
}
|
}
|
||||||
|
else ui->slider->hide();
|
||||||
|
|
||||||
if(auto workingRelay = item_.lock())
|
if(auto workingRelay = item_.lock())
|
||||||
{
|
{
|
||||||
@ -32,11 +34,20 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, QWidget *parent) :
|
|||||||
else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
||||||
connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
||||||
|
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
|
||||||
|
|
||||||
}
|
}
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemWidget::deleteItem()
|
||||||
|
{
|
||||||
|
if(auto workingItem = item_.lock())
|
||||||
|
{
|
||||||
|
deleteRequest(*workingItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ItemWidget::moveToValue(int value)
|
void ItemWidget::moveToValue(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock()) workingItem->setValue(value);
|
if(auto workingItem = item_.lock()) workingItem->setValue(value);
|
||||||
|
@ -18,13 +18,18 @@ private:
|
|||||||
|
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
void deleteRequest(const ItemData& item);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showSettingsDialog();
|
void showSettingsDialog();
|
||||||
void moveToState(bool state);
|
void moveToState(bool state);
|
||||||
void moveToValue(int value);
|
void moveToValue(int value);
|
||||||
|
void deleteItem();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemWidget(std::weak_ptr<Item> item, bool analog = false, QWidget *parent = nullptr);
|
explicit ItemWidget(std::weak_ptr<Item> item, bool analog = false, bool nameOnly = false, QWidget *parent = nullptr);
|
||||||
std::weak_ptr<Item> getItem();
|
std::weak_ptr<Item> getItem();
|
||||||
bool controles(const ItemData& relay);
|
bool controles(const ItemData& relay);
|
||||||
~ItemWidget();
|
~ItemWidget();
|
||||||
|
@ -67,6 +67,25 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_Remove">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>30</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>X</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -1,42 +1,47 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "itemscrollbox.h"
|
#include "itemscrollbox.h"
|
||||||
|
|
||||||
#include "itemsettingsdialog.h"
|
#include "itemsettingsdialog.h"
|
||||||
|
#include "itemcreationdialog.h"
|
||||||
|
#include "../mainobject.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(Microcontroller *micro, PowerItem* powerItem, ItemStore* itemStore, SensorStore *sensorStore, bool master, QWidget *parent) :
|
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
colorChooser(this),
|
colorChooser(this),
|
||||||
_micro(micro),
|
_micro(&mainObject->micro),
|
||||||
_powerItem(powerItem)
|
_powerItem(&mainObject->powerItem)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
if(!master) connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
|
if(!mainObject->master) connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
|
||||||
else ui->pushButton_broadcast->hide();
|
else ui->pushButton_broadcast->hide();
|
||||||
|
|
||||||
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
||||||
|
|
||||||
//Relays
|
//Relays
|
||||||
connect(ui->pushButton_refesh, SIGNAL(clicked()), _micro, SLOT(requestState()));
|
if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
||||||
connect(itemStore, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
else connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
|
||||||
connect(itemStore, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
connect(&mainObject->items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
||||||
|
connect(&mainObject->items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
||||||
|
|
||||||
for(size_t i = 0; i < itemStore->getItems()->size(); ++i)
|
for(size_t i = 0; i < mainObject->items.getItems()->size(); ++i)
|
||||||
{
|
{
|
||||||
ui->relayList->addItem(itemStore->getItems()->at(i));
|
ui->relayList->addItem(mainObject->items.getItems()->at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sensors
|
//Sensors
|
||||||
|
ui->sensorListView->setShowHidden(false);
|
||||||
ui->sensorListView->sensorsChanged(*(sensorStore->getSensors()));
|
ui->sensorListView->sensorsChanged(*globalSensors.getSensors());
|
||||||
connect(sensorStore, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
||||||
|
|
||||||
//RGB Leds
|
//RGB Leds
|
||||||
connect(&colorChooser, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
|
connect(&colorChooser, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
|
||||||
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
||||||
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
||||||
|
|
||||||
|
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
||||||
|
connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -56,6 +61,16 @@ void MainWindow::slotChangedRgb(const QColor color)
|
|||||||
_micro->changeRgbColor(color);
|
_micro->changeRgbColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::showItemCreationDialog()
|
||||||
|
{
|
||||||
|
ItemCreationDialog diag(this);
|
||||||
|
diag.show();
|
||||||
|
if(diag.exec())
|
||||||
|
{
|
||||||
|
createdItem(diag.item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::changeHeaderLableText(QString string)
|
void MainWindow::changeHeaderLableText(QString string)
|
||||||
{
|
{
|
||||||
if(string.size() > 28)
|
if(string.size() > 28)
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include "../broadcast.h"
|
#include "../broadcast.h"
|
||||||
|
|
||||||
|
|
||||||
|
class MainObject;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@ -24,7 +26,7 @@ class MainWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(Microcontroller *micro, PowerItem* powerItem, ItemStore* itemStore, SensorStore *sensorStore, bool master, QWidget *parent = nullptr);
|
explicit MainWindow(MainObject * const mainObject, QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -39,12 +41,14 @@ private:
|
|||||||
signals:
|
signals:
|
||||||
|
|
||||||
void sigBrodcast();
|
void sigBrodcast();
|
||||||
|
void createdItem(std::shared_ptr<Item> item);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
//RGB
|
//RGB
|
||||||
void slotChangedRgb(const QColor color);
|
void slotChangedRgb(const QColor color);
|
||||||
void showPowerItemDialog();
|
void showPowerItemDialog();
|
||||||
|
void showItemCreationDialog();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0,1">
|
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0,1">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_serialRecive">
|
<widget class="QLabel" name="label_serialRecive">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -81,15 +81,9 @@
|
|||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::NoSelection</enum>
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="showGrid">
|
<property name="showGrid" stdset="0">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="gridStyle">
|
|
||||||
<enum>Qt::NoPen</enum>
|
|
||||||
</property>
|
|
||||||
<attribute name="verticalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -190,7 +184,14 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_broadcast">
|
<widget class="QPushButton" name="pushButton_broadcast">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Broadcast</string>
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_addItem">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add Item</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -219,17 +220,17 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>SensorListWidget</class>
|
||||||
|
<extends>QListView</extends>
|
||||||
|
<header location="global">../src/ui/sensorlistwidget.h</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ItemScrollBox</class>
|
<class>ItemScrollBox</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header location="global">../src/ui/itemscrollbox.h</header>
|
<header location="global">../src/ui/itemscrollbox.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>SensorListWidget</class>
|
|
||||||
<extends>QTableWidget</extends>
|
|
||||||
<header location="global">../src/ui/sensorlistwidget.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../resources.qrc"/>
|
<include location="../../resources.qrc"/>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
|
||||||
SensorListWidget::SensorListWidget(QWidget *parent): QTableWidget(parent)
|
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), showHidden_(showHidden)
|
||||||
{
|
{
|
||||||
setColumnCount(2);
|
setColumnCount(2);
|
||||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
@ -13,7 +13,7 @@ SensorListWidget::SensorListWidget(QWidget *parent): QTableWidget(parent)
|
|||||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorListWidget::SensorListWidget(SensorStore& sensorStore, QWidget* parent): QTableWidget (parent)
|
SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden, QWidget* parent): QTableWidget (parent), showHidden_(showHidden)
|
||||||
{
|
{
|
||||||
sensorsChanged(*(sensorStore.getSensors()));
|
sensorsChanged(*(sensorStore.getSensors()));
|
||||||
}
|
}
|
||||||
@ -23,25 +23,47 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
|
|||||||
clear();
|
clear();
|
||||||
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
||||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||||
setRowCount(sensors.size());
|
size_t nonHiddenCount = sensors.size();
|
||||||
|
if(!showHidden_)
|
||||||
|
{
|
||||||
|
nonHiddenCount = 0;
|
||||||
|
for(size_t i = 0; i < sensors.size(); ++i)
|
||||||
|
{
|
||||||
|
if(!sensors[i].hidden) nonHiddenCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size_t listLen = 0;
|
||||||
|
for(size_t i = 0; i < sensors.size(); ++i) if(showHidden_ || !sensors[i].hidden) ++listLen;
|
||||||
|
setRowCount(static_cast<int>(listLen));
|
||||||
|
size_t row = 0;
|
||||||
for(size_t i = 0; i < sensors.size(); ++i)
|
for(size_t i = 0; i < sensors.size(); ++i)
|
||||||
{
|
{
|
||||||
QString itemString;
|
if(showHidden_ || !sensors[i].hidden)
|
||||||
itemString.append(QString::number(sensors[i].field));
|
{
|
||||||
itemString.append(' ');
|
QString itemString;
|
||||||
|
itemString.append(QString::number(sensors[i].field));
|
||||||
|
itemString.append(' ');
|
||||||
|
|
||||||
if(sensors[i].type == Sensor::TYPE_DOOR)
|
if(sensors[i].type == Sensor::TYPE_DOOR)
|
||||||
{
|
{
|
||||||
if(sensors[i].field) itemString.append("\"Open\"");
|
if(static_cast<bool>(sensors[i].field)) itemString.append("\"Open\"");
|
||||||
else itemString.append("\"Closed\"");
|
else itemString.append("\"Closed\"");
|
||||||
|
}
|
||||||
|
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
|
||||||
|
{
|
||||||
|
if(static_cast<bool>(sensors[i].field)) itemString.append("\"Playing\"");
|
||||||
|
else itemString.append("\"Silent\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? "(H)" : "")));
|
||||||
|
setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString));
|
||||||
|
++row;
|
||||||
}
|
}
|
||||||
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
|
|
||||||
{
|
|
||||||
if(sensors[i].field) itemString.append("\"Playing\"");
|
|
||||||
else itemString.append("\"Silent\"");
|
|
||||||
}
|
|
||||||
setItem(i, 0, new QTableWidgetItem(sensors[i].name));
|
|
||||||
setItem(i, 1, new QTableWidgetItem(itemString));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorListWidget::setShowHidden(const bool showHidden)
|
||||||
|
{
|
||||||
|
showHidden_=showHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,15 @@
|
|||||||
class SensorListWidget : public QTableWidget
|
class SensorListWidget : public QTableWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
bool showHidden_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SensorListWidget(QWidget *parent = nullptr);
|
SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr);
|
||||||
SensorListWidget(SensorStore& sensorStore, QWidget* parent = nullptr);
|
SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr);
|
||||||
virtual ~SensorListWidget(){}
|
virtual ~SensorListWidget(){}
|
||||||
|
void setShowHidden(const bool showHidden);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user