Sensors now work over broadcast pipe
Added Polynomal actor Added Item adding dialog Added Factor Actor
This commit is contained in:
		
							parent
							
								
									f6aaebafc6
								
							
						
					
					
						commit
						772d21a982
					
				
					 63 changed files with 1450 additions and 225 deletions
				
			
		| 
						 | 
				
			
			@ -5,8 +5,10 @@
 | 
			
		|||
#include "sensoractor.h"
 | 
			
		||||
#include "timeractor.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)
 | 
			
		||||
    {
 | 
			
		||||
        trigger();
 | 
			
		||||
        sigValue(triggerValue);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -61,17 +62,17 @@ bool Actor::isExausted()
 | 
			
		|||
 | 
			
		||||
void Actor::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
    json["Active"] =  active;
 | 
			
		||||
    json["Exausted"] = exausted;
 | 
			
		||||
    if(!name.isEmpty()) json["Name"] = name;
 | 
			
		||||
    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();
 | 
			
		||||
    exausted = json["Exausted"].toBool();
 | 
			
		||||
    name = json["Name"].toString("");
 | 
			
		||||
    triggerValue = json["TriggerValue"].toInt();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -85,12 +86,6 @@ uint8_t Actor::getTriggerValue()
 | 
			
		|||
    return  triggerValue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Actor::getName()
 | 
			
		||||
{
 | 
			
		||||
    if(name.size() > 0) return  name;
 | 
			
		||||
    else return "Actor";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 == "Timer") actor = new TimerActor();
 | 
			
		||||
    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();
 | 
			
		||||
    return actor;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -114,3 +111,10 @@ Actor* Actor::loadActor(const QJsonObject &json)
 | 
			
		|||
    if(actor) actor->load(json);
 | 
			
		||||
    return actor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    Item::setValue(value);
 | 
			
		||||
    setActive(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,9 @@
 | 
			
		|||
#include <QString>
 | 
			
		||||
#include <QJsonObject>
 | 
			
		||||
 | 
			
		||||
class Actor : public QObject
 | 
			
		||||
#include "../items/item.h"
 | 
			
		||||
 | 
			
		||||
class Actor : public Item
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
| 
						 | 
				
			
			@ -18,12 +20,9 @@ protected:
 | 
			
		|||
 | 
			
		||||
    void performAction();
 | 
			
		||||
 | 
			
		||||
    QString name;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void sigValue(uint8_t value);
 | 
			
		||||
    void trigger();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    virtual void makeActive();
 | 
			
		||||
| 
						 | 
				
			
			@ -31,6 +30,7 @@ public slots:
 | 
			
		|||
    virtual void setActive(uint8_t state);
 | 
			
		||||
    virtual void onValueChanged(uint8_t state);
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    Actor(QObject* parent = nullptr);
 | 
			
		||||
| 
						 | 
				
			
			@ -39,8 +39,6 @@ public:
 | 
			
		|||
 | 
			
		||||
    virtual QString actionName();
 | 
			
		||||
 | 
			
		||||
    virtual QString getName();
 | 
			
		||||
 | 
			
		||||
    bool isActive();
 | 
			
		||||
    void setTriggerValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -49,7 +47,7 @@ public:
 | 
			
		|||
    static Actor* createActor(const QString& type);
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ AlarmTime::AlarmTime(const QDateTime time, QObject *parent) : Actor(parent), tim
 | 
			
		|||
{
 | 
			
		||||
    connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
    timer.setInterval(1000);
 | 
			
		||||
    run();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AlarmTime::~AlarmTime()
 | 
			
		||||
| 
						 | 
				
			
			@ -26,9 +27,9 @@ void AlarmTime::makeActive()
 | 
			
		|||
    run();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString AlarmTime::getName()
 | 
			
		||||
QString AlarmTime::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name.size() > 0)return  name;
 | 
			
		||||
    if(name_.size() > 0)return  name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +112,7 @@ void AlarmTime::doTick()
 | 
			
		|||
void AlarmTime::changeTime(const QDateTime& time)
 | 
			
		||||
{
 | 
			
		||||
    time_=time;
 | 
			
		||||
    qDebug()<<"time: "<<time_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -122,9 +124,11 @@ void AlarmTime::store(QJsonObject& json)
 | 
			
		|||
    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(""));
 | 
			
		||||
    repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
 | 
			
		||||
    if(oldActive != isActive()) setActive(isActive());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,7 @@ public:
 | 
			
		|||
    QDateTime getDateTime();
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
 | 
			
		||||
    uint8_t getRepeat();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ public slots:
 | 
			
		|||
    void run();
 | 
			
		||||
    virtual void makeActive();
 | 
			
		||||
    virtual void makeInactive();
 | 
			
		||||
    virtual QString getName();
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    void doTick();
 | 
			
		||||
    void changeTime(const QDateTime& time);
 | 
			
		||||
    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_)
 | 
			
		||||
    {
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
        first = false;
 | 
			
		||||
        sensor_ = sensor;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -63,9 +62,9 @@ void Regulator::store(QJsonObject& json)
 | 
			
		|||
    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);
 | 
			
		||||
    setPoint_ = json["SetPoint"].toInt(22);
 | 
			
		||||
    sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
| 
						 | 
				
			
			@ -74,9 +73,9 @@ void Regulator::load(const QJsonObject& json)
 | 
			
		|||
    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
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,8 @@ private:
 | 
			
		|||
    float band_ = 1;
 | 
			
		||||
    bool invert_ = false;
 | 
			
		||||
 | 
			
		||||
    bool first = true;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void sensorEvent(Sensor sensor);
 | 
			
		||||
| 
						 | 
				
			
			@ -28,9 +30,9 @@ public:
 | 
			
		|||
    Regulator(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
    Regulator(QObject* parent = nullptr);
 | 
			
		||||
    Sensor getSensor(){return sensor_;}
 | 
			
		||||
    virtual QString getName();
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    virtual ~Regulator(){}    
 | 
			
		||||
    
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
    threshold_ = json["Threshold"].toDouble(0);
 | 
			
		||||
    sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
| 
						 | 
				
			
			@ -70,9 +70,9 @@ void SensorActor::load(const QJsonObject& json)
 | 
			
		|||
    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
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,14 +29,14 @@ public:
 | 
			
		|||
    SensorActor(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
    SensorActor(QObject* parent = nullptr);
 | 
			
		||||
    Sensor getSensor(){return sensor_;}
 | 
			
		||||
    virtual QString getName();
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    virtual ~SensorActor(){}
 | 
			
		||||
 | 
			
		||||
    float getThreshold();
 | 
			
		||||
    uint8_t getSloap();
 | 
			
		||||
    
 | 
			
		||||
    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_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -45,9 +45,9 @@ void TimerActor::timeout()
 | 
			
		|||
    performAction();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString TimerActor::getName()
 | 
			
		||||
QString TimerActor::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name.size() > 0) return name;
 | 
			
		||||
    if(name_.size() > 0) return name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,10 +21,10 @@ public slots:
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
    explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
 | 
			
		||||
    virtual QString getName();
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
 | 
			
		||||
    int getTimeout();
 | 
			
		||||
 | 
			
		||||
    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()<<document.toJson().data();
 | 
			
		||||
        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
 | 
			
		||||
        {
 | 
			
		||||
            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()
 | 
			
		||||
| 
						 | 
				
			
			@ -106,4 +111,5 @@ void BroadCast::readyRead()
 | 
			
		|||
        }
 | 
			
		||||
        else buffer_.clear();
 | 
			
		||||
    }
 | 
			
		||||
    else if(buffer_.contains('\n')) buffer_.clear();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#include <QObject>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QJsonObject>
 | 
			
		||||
#include "sensors/sensor.h"
 | 
			
		||||
 | 
			
		||||
class BroadCast: public QObject
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +39,7 @@ signals:
 | 
			
		|||
 | 
			
		||||
    void jsonRequested();
 | 
			
		||||
    void gotJson(QJsonObject json);
 | 
			
		||||
    void gotSensorState(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
#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);
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#include "../microcontroller.h"
 | 
			
		||||
#include "../actors/sensoractor.h"
 | 
			
		||||
#include "../actors/regulator.h"
 | 
			
		||||
#include "../actors/polynomalactor.h"
 | 
			
		||||
 | 
			
		||||
#include <QJsonArray>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -37,32 +38,34 @@ uint32_t ItemData::id() const
 | 
			
		|||
 | 
			
		||||
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)
 | 
			
		||||
{
 | 
			
		||||
    json["Name"] = name_;
 | 
			
		||||
    json["ItemId"] = static_cast<double>(itemId_);
 | 
			
		||||
    json["ActorsActive"] = actorsActive_;
 | 
			
		||||
    QJsonArray actorsArray;
 | 
			
		||||
    for(size_t i = 0; i < actors_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        QJsonObject actorObject;
 | 
			
		||||
        actors_[i]->store(actorObject);
 | 
			
		||||
        actorsArray.append(actorObject);
 | 
			
		||||
        if(!actors_[i]->isExausted())
 | 
			
		||||
        {
 | 
			
		||||
            QJsonObject actorObject;
 | 
			
		||||
            actors_[i]->store(actorObject);
 | 
			
		||||
            actorsArray.append(actorObject);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    json["Actors"] = actorsArray;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +77,6 @@ void Item::load(const QJsonObject &json, const bool preserve)
 | 
			
		|||
        name_ = json["Name"].toString(name_);
 | 
			
		||||
        itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
 | 
			
		||||
    }
 | 
			
		||||
    actorsActive_ = json["ActorsActive"].toBool(true);
 | 
			
		||||
    const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
 | 
			
		||||
    for(int i = 0; i < actorsArray.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -101,17 +103,21 @@ void Item::addActor(Actor* actor)
 | 
			
		|||
{
 | 
			
		||||
    actor->setParent(this);
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
    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();
 | 
			
		||||
    else actor->makeInactive();
 | 
			
		||||
    PolynomalActor* polynomalActor = dynamic_cast<PolynomalActor*>(actor);
 | 
			
		||||
    if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor, &PolynomalActor::sensorEvent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Item::removeActor(Actor* actor)
 | 
			
		||||
| 
						 | 
				
			
			@ -146,6 +152,5 @@ bool Item::hasActors()
 | 
			
		|||
 | 
			
		||||
void Item::setActorsActive(bool in)
 | 
			
		||||
{
 | 
			
		||||
    actorsActive_ = in;
 | 
			
		||||
    for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,8 +5,7 @@
 | 
			
		|||
#include <QSettings>
 | 
			
		||||
#include <QJsonObject>
 | 
			
		||||
 | 
			
		||||
#include "../actors/actor.h"
 | 
			
		||||
#include "../sensors/sensor.h"
 | 
			
		||||
class Actor;
 | 
			
		||||
 | 
			
		||||
class ItemData
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -24,9 +23,9 @@ public:
 | 
			
		|||
 | 
			
		||||
    uint32_t id() const;
 | 
			
		||||
 | 
			
		||||
    QString getName() const;
 | 
			
		||||
    void setName(QString name);
 | 
			
		||||
    uint8_t getValue() const;
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -35,12 +34,10 @@ class Item: public QObject, public ItemData
 | 
			
		|||
    Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    std::vector< Actor* > actors_;
 | 
			
		||||
    bool actorsActive_ = true;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    static bool secondaryFlag;
 | 
			
		||||
    SensorStore* sensors_;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -52,19 +49,18 @@ public slots:
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    Item(SensorStore* sensors = nullptr, 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(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,  QObject *parent = nullptr);
 | 
			
		||||
    Item(const ItemData& itemData,  QObject *parent = nullptr);
 | 
			
		||||
 | 
			
		||||
    virtual ~Item();
 | 
			
		||||
 | 
			
		||||
    std::vector< Actor* >& getActors();
 | 
			
		||||
    bool hasActors();
 | 
			
		||||
    void addActor(Actor* actor);
 | 
			
		||||
    bool removeActor(Actor* actor);
 | 
			
		||||
    void removeAllActors();
 | 
			
		||||
    bool actorsActive() const;
 | 
			
		||||
    void setActorsActive(bool in);
 | 
			
		||||
    void informValue(uint8_t value);
 | 
			
		||||
    void setSensorStore(SensorStore* sensors){sensors_ = sensors;}
 | 
			
		||||
    SensorStore* getSensorStore(){return sensors_;}
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,9 @@
 | 
			
		|||
#include "itemstore.h"
 | 
			
		||||
#include "relay.h"
 | 
			
		||||
#include "messageitem.h"
 | 
			
		||||
#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)
 | 
			
		||||
    {
 | 
			
		||||
        items_.push_back(std::shared_ptr<Item>(item));
 | 
			
		||||
        items_.back()->setSensorStore(sensors_);
 | 
			
		||||
        itemAdded(std::weak_ptr<Item>(items_.back()));
 | 
			
		||||
        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()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -91,10 +103,14 @@ void ItemStore::load(const QJsonObject& json, Microcontroller * const micro)
 | 
			
		|||
        if(itemsArray[i].isObject())
 | 
			
		||||
        {
 | 
			
		||||
            const QJsonObject itemObject = itemsArray[i].toObject();
 | 
			
		||||
            std::shared_ptr<Relay> newItem;
 | 
			
		||||
            std::shared_ptr<Item> newItem;
 | 
			
		||||
            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")
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,11 +13,9 @@ class ItemStore: public QObject
 | 
			
		|||
private:
 | 
			
		||||
    std::vector< std::shared_ptr<Item> > items_;
 | 
			
		||||
 | 
			
		||||
    SensorStore* sensors_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    ItemStore(SensorStore* sensors_ = nullptr, QObject *parent = nullptr);
 | 
			
		||||
    ItemStore(QObject *parent = nullptr);
 | 
			
		||||
    virtual ~ItemStore(){}
 | 
			
		||||
 | 
			
		||||
    inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +32,7 @@ signals:
 | 
			
		|||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void removeItem(const ItemData& item);
 | 
			
		||||
    void addItem(std::shared_ptr<Item> item);
 | 
			
		||||
    void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
 | 
			
		||||
    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 <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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ void PowerItem::setValue(uint8_t value)
 | 
			
		|||
    if(!value)
 | 
			
		||||
    {
 | 
			
		||||
       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);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    PowerItem(SensorStore* sensors, 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));}
 | 
			
		||||
    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, "Shutdown Imminent", true));}
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
//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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -38,9 +38,9 @@ void Relay::store(QJsonObject& json)
 | 
			
		|||
    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));
 | 
			
		||||
    address_ = static_cast<uint16_t>(json["Address"].toInt(0));
 | 
			
		||||
    itemId_ = address_ | (static_cast<uint32_t>(id_) << 16);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,13 +26,13 @@ public slots:
 | 
			
		|||
    void toggle();
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
    uint8_t getId() const;
 | 
			
		||||
    void setId(uint8_t id);
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
};
 | 
			
		||||
#endif // RELAY_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
#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);
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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';
 | 
			
		||||
        masterIODevice = microPort;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
 | 
			
		||||
 | 
			
		||||
    #else
 | 
			
		||||
        QTcpSocket* microSocket = new QTcpSocket;
 | 
			
		||||
        microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
 | 
			
		||||
| 
						 | 
				
			
			@ -106,14 +109,16 @@ int main(int argc, char *argv[])
 | 
			
		|||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        masterIODevice = microSocket;
 | 
			
		||||
 | 
			
		||||
        MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
 | 
			
		||||
 | 
			
		||||
    //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(&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!");
 | 
			
		||||
 | 
			
		||||
    w.show();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,40 +6,35 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
 | 
			
		|||
    masterIODevice(ioDevice),
 | 
			
		||||
    ioMultiplexer(masterIODevice),
 | 
			
		||||
    micro(ioMultiplexer.getIoDevice()),
 | 
			
		||||
    broadCast(ioMultiplexer.getIoDevice()),
 | 
			
		||||
    broadCast(ioMultiplexer.getIoDevice(), masterIn),
 | 
			
		||||
    settingsPath(settingsPathIn),
 | 
			
		||||
    sunSensorSource(49.884450, 8.650536),
 | 
			
		||||
    items(&sensors),
 | 
			
		||||
    powerItem(&sensors),
 | 
			
		||||
    rgbItem(new RgbItem(&sensors, µ, 5487422, "Rgb Lights")),
 | 
			
		||||
    auxItem(new AuxItem(&sensors, µ, 5487421, "Desk Light"))
 | 
			
		||||
    rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
 | 
			
		||||
    auxItem(new AuxItem(µ, 5487421, "Desk Light"))
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"Is master:"<<master;
 | 
			
		||||
    //connect sensors subsystem
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::gotSensorState, &sensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&livingroomSpeakerSensorSource, &SpeakerSensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&sensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
 | 
			
		||||
    QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
 | 
			
		||||
 | 
			
		||||
    QMetaObject::invokeMethod(&livingroomSpeakerSensorSource, "run", Qt::QueuedConnection);
 | 
			
		||||
    sunSensorSource.run();
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
 | 
			
		||||
    QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
 | 
			
		||||
    //connect item store
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
 | 
			
		||||
 | 
			
		||||
    //special items
 | 
			
		||||
    QObject::connect(&powerItem, &PowerItem::stateChanged, &sensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&powerItem, &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
    powerItem.emmitSensor();
 | 
			
		||||
    items.addItem(rgbItem);
 | 
			
		||||
    items.addItem(auxItem);
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
    {
 | 
			
		||||
        broadCast.requestJson();
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +51,7 @@ MainObject::~MainObject()
 | 
			
		|||
    {
 | 
			
		||||
        QJsonObject json;
 | 
			
		||||
        store(json);
 | 
			
		||||
        storeJsonObjectToDisk(json, settingsPath);
 | 
			
		||||
        if(!noSave)storeJsonObjectToDisk(json, settingsPath);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -73,6 +68,7 @@ void MainObject::load(const QJsonObject& json)
 | 
			
		|||
    items.clear();
 | 
			
		||||
    rgbItem->removeAllActors();
 | 
			
		||||
    auxItem->removeAllActors();
 | 
			
		||||
    powerItem.removeAllActors();
 | 
			
		||||
    items.addItem(rgbItem);
 | 
			
		||||
    items.addItem(auxItem);
 | 
			
		||||
    items.load(json, µ);
 | 
			
		||||
| 
						 | 
				
			
			@ -99,7 +95,7 @@ void MainObject::sendJson()
 | 
			
		|||
    broadCast.sendJson(json);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath)
 | 
			
		||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* error)
 | 
			
		||||
{
 | 
			
		||||
    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;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QJsonDocument document(QJsonDocument::fromJson(file.readAll()));
 | 
			
		||||
        QJsonParseError qerror;
 | 
			
		||||
        QJsonDocument document(QJsonDocument::fromJson(file.readAll(), &qerror));
 | 
			
		||||
        file.close();
 | 
			
		||||
        if(qerror.error != QJsonParseError::NoError)
 | 
			
		||||
        {
 | 
			
		||||
            qDebug()<<filePath<<" "<<qerror.errorString();
 | 
			
		||||
            if(error) (*error) = true;
 | 
			
		||||
        }
 | 
			
		||||
        return document.object();
 | 
			
		||||
    }
 | 
			
		||||
    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
 | 
			
		||||
    if(filePath.size() > 0) file.setFileName(filePath);
 | 
			
		||||
    else
 | 
			
		||||
    if(filePath.size() == 0)
 | 
			
		||||
    #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);
 | 
			
		||||
    if(!file.isOpen())
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -145,6 +146,8 @@ bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, const QString& f
 | 
			
		|||
        QJsonDocument document(json);
 | 
			
		||||
        file.write(document.toJson());
 | 
			
		||||
        file.close();
 | 
			
		||||
        QFile::remove(filePath);
 | 
			
		||||
        file.rename(filePath);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,8 @@ public:
 | 
			
		|||
    //io
 | 
			
		||||
    const bool master;
 | 
			
		||||
 | 
			
		||||
    bool noSave = false;
 | 
			
		||||
 | 
			
		||||
    QIODevice * const masterIODevice = nullptr;
 | 
			
		||||
    IoMuliplexer ioMultiplexer;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -50,12 +52,9 @@ public:
 | 
			
		|||
    const QString settingsPath;
 | 
			
		||||
 | 
			
		||||
    //sensors
 | 
			
		||||
    SpeakerSensorSource livingroomSpeakerSensorSource;
 | 
			
		||||
    SunSensorSource     sunSensorSource;
 | 
			
		||||
    OcupancySensorSource ocupancySensor;
 | 
			
		||||
 | 
			
		||||
    SensorStore sensors;
 | 
			
		||||
 | 
			
		||||
    //items
 | 
			
		||||
    ItemStore items;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,8 +64,8 @@ public:
 | 
			
		|||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    static QJsonObject getJsonObjectFromDisk(const QString& filePath = "");
 | 
			
		||||
    static bool storeJsonObjectToDisk(const QJsonObject& json, const QString& filePath = "");
 | 
			
		||||
    static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
 | 
			
		||||
    static bool storeJsonObjectToDisk(const QJsonObject& json, QString filePath = "");
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    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);
 | 
			
		||||
        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();
 | 
			
		||||
        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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -160,10 +160,8 @@ void Microcontroller::processRelayState(const QString& buffer)
 | 
			
		|||
 | 
			
		||||
void Microcontroller::processSensorState(const QString& buffer)
 | 
			
		||||
{
 | 
			
		||||
    QStringList bufferList = buffer.split(' ');
 | 
			
		||||
    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;
 | 
			
		||||
    if(bufferList.size() >= 7)gotSensorState(sensor);
 | 
			
		||||
    Sensor sensor = Sensor::sensorFromString(buffer);
 | 
			
		||||
    if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@
 | 
			
		|||
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
SensorStore globalSensors;
 | 
			
		||||
 | 
			
		||||
SensorStore::SensorStore(QObject *parent): QObject(parent)
 | 
			
		||||
{
 | 
			
		||||
    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_PRESSURE = 3;
 | 
			
		||||
    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_SHUTDOWN_IMMINENT = 251;
 | 
			
		||||
    static constexpr uint8_t TYPE_OCUPANCY = 252;
 | 
			
		||||
| 
						 | 
				
			
			@ -26,23 +27,36 @@ public:
 | 
			
		|||
    float field;
 | 
			
		||||
    QString name;
 | 
			
		||||
    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();
 | 
			
		||||
        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();
 | 
			
		||||
    }
 | 
			
		||||
    inline bool operator==(const Sensor& in){ return type==in.type && id == in.id; }
 | 
			
		||||
    inline bool operator!=(const Sensor& in){ return !(*this==in); }
 | 
			
		||||
    inline bool operator==(const Sensor& in) const{ return type==in.type && id == in.id; }
 | 
			
		||||
    inline bool operator!=(const Sensor& in) const{ return !(*this==in); }
 | 
			
		||||
    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()
 | 
			
		||||
    {
 | 
			
		||||
        if(type == TYPE_TEMPERATURE) name = "Temperature " + 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_HUMIDITY)  name = "Humidity " + QString::number(id);
 | 
			
		||||
        else if(type == TYPE_SUN_ALTITUDE)  name = "Solar Altitude";
 | 
			
		||||
| 
						 | 
				
			
			@ -64,6 +78,7 @@ public:
 | 
			
		|||
 | 
			
		||||
    inline std::vector<Sensor>* getSensors(){ return &sensors_; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void sensorGotState(const Sensor& sensor);
 | 
			
		||||
| 
						 | 
				
			
			@ -75,3 +90,5 @@ signals:
 | 
			
		|||
    void sensorDeleted(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern SensorStore globalSensors;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -179,9 +179,3 @@ double Sun::declination()
 | 
			
		|||
	double meanSolarAnomalyValue  = meanSolarAnomaly(meanSolarNoonValue);
 | 
			
		||||
	return solarDeclination(eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
double maximumAltitude()
 | 
			
		||||
{
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
#include "actorsettingsdialog.h"
 | 
			
		||||
#include "ui_actorsettingsdialog.h"
 | 
			
		||||
#include "itemsettingsdialog.h"
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QSpinBox>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -14,25 +15,25 @@ ActorSettingsDialog::ActorSettingsDialog(AlarmTime* alarm, QWidget *parent):
 | 
			
		|||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(SensorActor* actor, SensorStore* sensors, QWidget *parent) :
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(SensorActor* actor, QWidget *parent) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
actor_(actor),
 | 
			
		||||
ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
 | 
			
		||||
    widget = new SensorActorWidget(actor, sensors, this);
 | 
			
		||||
    widget = new SensorActorWidget(actor, &globalSensors, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(Regulator* actor, SensorStore* sensors, QWidget *parent) :
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(Regulator* actor, QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    actor_(actor),
 | 
			
		||||
    ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
 | 
			
		||||
    widget = new RegulatorWdiget(actor, sensors, this);
 | 
			
		||||
    widget = new RegulatorWdiget(actor, &globalSensors, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +48,26 @@ ui(new Ui::ActorSettingsDialog)
 | 
			
		|||
    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) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
| 
						 | 
				
			
			@ -61,6 +82,7 @@ void ActorSettingsDialog::init()
 | 
			
		|||
    ui->setupUi(this);
 | 
			
		||||
    connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(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->setValue(actor_->getTriggerValue());
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +96,12 @@ ActorSettingsDialog::~ActorSettingsDialog()
 | 
			
		|||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActorSettingsDialog::editAsItem()
 | 
			
		||||
{
 | 
			
		||||
    ItemSettingsDialog itemSettingsDiag(actor_, this);
 | 
			
		||||
    itemSettingsDiag.exec();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActorSettingsDialog::valueChanged(int value)
 | 
			
		||||
{
 | 
			
		||||
    actor_->setTriggerValue(value);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,8 @@
 | 
			
		|||
#include "actorwidgets/sensoractorwidget.h"
 | 
			
		||||
#include "actorwidgets/timeractorwidget.h"
 | 
			
		||||
#include "actorwidgets/regulatorwdiget.h"
 | 
			
		||||
#include "actorwidgets/polynomalactorwidget.h"
 | 
			
		||||
#include "actorwidgets/factoractorwidget.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ActorSettingsDialog;
 | 
			
		||||
| 
						 | 
				
			
			@ -24,9 +26,11 @@ private:
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
    ActorSettingsDialog(AlarmTime* actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(SensorActor* actor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(Regulator* actor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(TimerActor* actor, QWidget *parent);
 | 
			
		||||
    ActorSettingsDialog(SensorActor* actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(Regulator* actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(TimerActor* actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(PolynomalActor* actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(MultiFactorActor* actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(Actor* actor, QWidget *parent);
 | 
			
		||||
    ~ActorSettingsDialog();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +39,7 @@ public:
 | 
			
		|||
private slots:
 | 
			
		||||
    void changeAction(int index);
 | 
			
		||||
    void valueChanged(int value);
 | 
			
		||||
    void editAsItem();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,6 +63,13 @@
 | 
			
		|||
       </item>
 | 
			
		||||
      </layout>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="pushButton_editItem">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Edit as item</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ public:
 | 
			
		|||
 | 
			
		||||
private slots:
 | 
			
		||||
    void toggleRepeating(int state);
 | 
			
		||||
        void setRepeatingType();
 | 
			
		||||
    void setRepeatingType();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    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 "ui_relayscrollbox.h"
 | 
			
		||||
#include "../items/auxitem.h"
 | 
			
		||||
#include "../items/messageitem.h"
 | 
			
		||||
 | 
			
		||||
ItemScrollBox::ItemScrollBox(QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
| 
						 | 
				
			
			@ -24,11 +25,17 @@ void ItemScrollBox::addItem(std::weak_ptr<Item> item)
 | 
			
		|||
        {
 | 
			
		||||
            widgets_.push_back(new ItemWidget(item, true));
 | 
			
		||||
        }
 | 
			
		||||
        else if(dynamic_cast<MessageItem*>(workItem.get()))
 | 
			
		||||
        {
 | 
			
		||||
            widgets_.push_back(new ItemWidget(item, false, true));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            widgets_.push_back(new ItemWidget(item));
 | 
			
		||||
        }
 | 
			
		||||
        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:
 | 
			
		||||
    std::vector< ItemWidget* > widgets_;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void deleteRequest(const ItemData& item);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ItemScrollBox(QWidget *parent = nullptr);
 | 
			
		||||
    ~ItemScrollBox();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,7 @@
 | 
			
		|||
#include "../actors/sensoractor.h"
 | 
			
		||||
#include "../actors/timeractor.h"
 | 
			
		||||
#include "../actors/regulator.h"
 | 
			
		||||
#include "../actors/factoractor.h"
 | 
			
		||||
 | 
			
		||||
#include<memory>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,21 +32,17 @@ ItemSettingsDialog::ItemSettingsDialog(Item* item, QWidget *parent) :
 | 
			
		|||
        ui->label_address_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_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
 | 
			
		||||
    connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
 | 
			
		||||
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Acts on"));
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem("Enabled"));
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->resizeSection(2, 60);
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->resizeSection(3, 75);
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
 | 
			
		||||
    loadActorList();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -63,8 +60,7 @@ void ItemSettingsDialog::loadActorList()
 | 
			
		|||
    {
 | 
			
		||||
        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, 2, new QTableWidgetItem("Item"));
 | 
			
		||||
        ui->tableWidget->setItem(i, 3, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
 | 
			
		||||
        ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -79,11 +75,11 @@ void ItemSettingsDialog::addActor()
 | 
			
		|||
        actor = alarm;
 | 
			
		||||
        dialog = new ActorSettingsDialog(alarm, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Sensor" &&  item_->getSensorStore() != nullptr)
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Sensor")
 | 
			
		||||
    {
 | 
			
		||||
        SensorActor* sensorActor = new SensorActor();
 | 
			
		||||
        actor = sensorActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(sensorActor, item_->getSensorStore(), this);
 | 
			
		||||
        dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Timer" )
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -91,11 +87,25 @@ void ItemSettingsDialog::addActor()
 | 
			
		|||
        actor = timerActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Regulator" &&  item_->getSensorStore() != nullptr)
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Regulator")
 | 
			
		||||
    {
 | 
			
		||||
        Regulator* regulator = new 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);
 | 
			
		||||
        SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
 | 
			
		||||
        TimerActor* timerActor = dynamic_cast<TimerActor*>(actor);
 | 
			
		||||
        PolynomalActor* polynomalActor = dynamic_cast<PolynomalActor*>(actor);
 | 
			
		||||
        MultiFactorActor* factorActor = dynamic_cast<MultiFactorActor*>(actor);
 | 
			
		||||
 | 
			
		||||
        ActorSettingsDialog* dialog;
 | 
			
		||||
 | 
			
		||||
        if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
 | 
			
		||||
        else if(regulator)  dialog = new ActorSettingsDialog(regulator, nullptr, this);
 | 
			
		||||
        else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, nullptr, this);
 | 
			
		||||
        else if(regulator)  dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
        else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, 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);
 | 
			
		||||
        dialog->setParent(this);
 | 
			
		||||
        dialog->show();
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +163,7 @@ void ItemSettingsDialog::editActor()
 | 
			
		|||
        {
 | 
			
		||||
            ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
 | 
			
		||||
            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>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QCheckBox" name="checkBox_auto">
 | 
			
		||||
     <property name="text">
 | 
			
		||||
      <string>Actors enabled</string>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QTableWidget" name="tableWidget">
 | 
			
		||||
     <property name="frameShape">
 | 
			
		||||
| 
						 | 
				
			
			@ -143,7 +136,7 @@
 | 
			
		|||
      <number>0</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="columnCount">
 | 
			
		||||
      <number>4</number>
 | 
			
		||||
      <number>3</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <attribute name="horizontalHeaderVisible">
 | 
			
		||||
      <bool>false</bool>
 | 
			
		||||
| 
						 | 
				
			
			@ -163,7 +156,6 @@
 | 
			
		|||
     <column/>
 | 
			
		||||
     <column/>
 | 
			
		||||
     <column/>
 | 
			
		||||
     <column/>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
| 
						 | 
				
			
			@ -214,7 +206,7 @@
 | 
			
		|||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>Linear</string>
 | 
			
		||||
         <string>Polynomal</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
| 
						 | 
				
			
			@ -232,6 +224,11 @@
 | 
			
		|||
         <string>Timer</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>Multi Factor</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@
 | 
			
		|||
#include <QDebug>
 | 
			
		||||
#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),
 | 
			
		||||
    item_(item),
 | 
			
		||||
    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->checkBox->hide();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    else if(nameOnly)
 | 
			
		||||
    {
 | 
			
		||||
        ui->checkBox->hide();
 | 
			
		||||
        ui->slider->hide();
 | 
			
		||||
    }
 | 
			
		||||
    else ui->slider->hide();
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
        connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
 | 
			
		||||
        connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
 | 
			
		||||
        connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    else disable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::deleteItem()
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingItem = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        deleteRequest(*workingItem);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::moveToValue(int value)
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingItem = item_.lock()) workingItem->setValue(value);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,13 +18,18 @@ private:
 | 
			
		|||
 | 
			
		||||
    void disable();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void deleteRequest(const ItemData& item);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void showSettingsDialog();
 | 
			
		||||
    void moveToState(bool state);
 | 
			
		||||
    void moveToValue(int value);
 | 
			
		||||
    void deleteItem();
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
    bool controles(const ItemData& relay);
 | 
			
		||||
    ~ItemWidget();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -67,6 +67,25 @@
 | 
			
		|||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </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>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,42 +1,47 @@
 | 
			
		|||
#include "mainwindow.h"
 | 
			
		||||
#include "ui_mainwindow.h"
 | 
			
		||||
#include "itemscrollbox.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),
 | 
			
		||||
    ui(new Ui::MainWindow),
 | 
			
		||||
    colorChooser(this),
 | 
			
		||||
    _micro(micro),
 | 
			
		||||
    _powerItem(powerItem)
 | 
			
		||||
    _micro(&mainObject->micro),
 | 
			
		||||
    _powerItem(&mainObject->powerItem)
 | 
			
		||||
{
 | 
			
		||||
    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();
 | 
			
		||||
 | 
			
		||||
    connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
 | 
			
		||||
 | 
			
		||||
    //Relays
 | 
			
		||||
    connect(ui->pushButton_refesh, SIGNAL(clicked()), _micro, SLOT(requestState()));
 | 
			
		||||
    connect(itemStore, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
 | 
			
		||||
    connect(itemStore, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
 | 
			
		||||
    if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
 | 
			
		||||
    else connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
    ui->sensorListView->sensorsChanged(*(sensorStore->getSensors()));
 | 
			
		||||
    connect(sensorStore, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
 | 
			
		||||
    ui->sensorListView->setShowHidden(false);
 | 
			
		||||
    ui->sensorListView->sensorsChanged(*globalSensors.getSensors());
 | 
			
		||||
    connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
 | 
			
		||||
 | 
			
		||||
    //RGB Leds
 | 
			
		||||
    connect(&colorChooser, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
 | 
			
		||||
    connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
 | 
			
		||||
    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()
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +61,16 @@ void MainWindow::slotChangedRgb(const QColor color)
 | 
			
		|||
    _micro->changeRgbColor(color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::showItemCreationDialog()
 | 
			
		||||
{
 | 
			
		||||
    ItemCreationDialog diag(this);
 | 
			
		||||
    diag.show();
 | 
			
		||||
    if(diag.exec())
 | 
			
		||||
    {
 | 
			
		||||
        createdItem(diag.item);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::changeHeaderLableText(QString string)
 | 
			
		||||
{
 | 
			
		||||
    if(string.size() > 28)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,8 @@
 | 
			
		|||
#include "../broadcast.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MainObject;
 | 
			
		||||
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class MainWindow;
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +26,7 @@ class MainWindow : public QMainWindow
 | 
			
		|||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
| 
						 | 
				
			
			@ -39,12 +41,14 @@ private:
 | 
			
		|||
signals:
 | 
			
		||||
 | 
			
		||||
    void sigBrodcast();
 | 
			
		||||
    void createdItem(std::shared_ptr<Item> item);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    //RGB
 | 
			
		||||
    void slotChangedRgb(const QColor color);
 | 
			
		||||
    void showPowerItemDialog();
 | 
			
		||||
    void showItemCreationDialog();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,7 @@
 | 
			
		|||
   </property>
 | 
			
		||||
   <layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0,1">
 | 
			
		||||
    <item>
 | 
			
		||||
     <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
 | 
			
		||||
     <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QLabel" name="label_serialRecive">
 | 
			
		||||
        <property name="sizePolicy">
 | 
			
		||||
| 
						 | 
				
			
			@ -81,15 +81,9 @@
 | 
			
		|||
           <property name="selectionMode">
 | 
			
		||||
            <enum>QAbstractItemView::NoSelection</enum>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="showGrid">
 | 
			
		||||
           <property name="showGrid" stdset="0">
 | 
			
		||||
            <bool>false</bool>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="gridStyle">
 | 
			
		||||
            <enum>Qt::NoPen</enum>
 | 
			
		||||
           </property>
 | 
			
		||||
           <attribute name="verticalHeaderVisible">
 | 
			
		||||
            <bool>false</bool>
 | 
			
		||||
           </attribute>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
| 
						 | 
				
			
			@ -190,7 +184,14 @@
 | 
			
		|||
        <item>
 | 
			
		||||
         <widget class="QPushButton" name="pushButton_broadcast">
 | 
			
		||||
          <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>
 | 
			
		||||
         </widget>
 | 
			
		||||
        </item>
 | 
			
		||||
| 
						 | 
				
			
			@ -219,17 +220,17 @@
 | 
			
		|||
 </widget>
 | 
			
		||||
 <layoutdefault spacing="6" margin="11"/>
 | 
			
		||||
 <customwidgets>
 | 
			
		||||
  <customwidget>
 | 
			
		||||
   <class>SensorListWidget</class>
 | 
			
		||||
   <extends>QListView</extends>
 | 
			
		||||
   <header location="global">../src/ui/sensorlistwidget.h</header>
 | 
			
		||||
  </customwidget>
 | 
			
		||||
  <customwidget>
 | 
			
		||||
   <class>ItemScrollBox</class>
 | 
			
		||||
   <extends>QWidget</extends>
 | 
			
		||||
   <header location="global">../src/ui/itemscrollbox.h</header>
 | 
			
		||||
   <container>1</container>
 | 
			
		||||
  </customwidget>
 | 
			
		||||
  <customwidget>
 | 
			
		||||
   <class>SensorListWidget</class>
 | 
			
		||||
   <extends>QTableWidget</extends>
 | 
			
		||||
   <header location="global">../src/ui/sensorlistwidget.h</header>
 | 
			
		||||
  </customwidget>
 | 
			
		||||
 </customwidgets>
 | 
			
		||||
 <resources>
 | 
			
		||||
  <include location="../../resources.qrc"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
#include <QDebug>
 | 
			
		||||
#include <QHeaderView>
 | 
			
		||||
 | 
			
		||||
SensorListWidget::SensorListWidget(QWidget *parent): QTableWidget(parent)
 | 
			
		||||
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), showHidden_(showHidden)
 | 
			
		||||
{
 | 
			
		||||
    setColumnCount(2);
 | 
			
		||||
    setSelectionBehavior(QAbstractItemView::SelectRows);
 | 
			
		||||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ SensorListWidget::SensorListWidget(QWidget *parent): QTableWidget(parent)
 | 
			
		|||
    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()));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -23,25 +23,47 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
 | 
			
		|||
    clear();
 | 
			
		||||
    setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
 | 
			
		||||
    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)
 | 
			
		||||
    {
 | 
			
		||||
        QString itemString;
 | 
			
		||||
        itemString.append(QString::number(sensors[i].field));
 | 
			
		||||
        itemString.append(' ');
 | 
			
		||||
        if(showHidden_ || !sensors[i].hidden)
 | 
			
		||||
        {
 | 
			
		||||
            QString itemString;
 | 
			
		||||
            itemString.append(QString::number(sensors[i].field));
 | 
			
		||||
            itemString.append(' ');
 | 
			
		||||
 | 
			
		||||
        if(sensors[i].type == Sensor::TYPE_DOOR)
 | 
			
		||||
        {
 | 
			
		||||
            if(sensors[i].field) itemString.append("\"Open\"");
 | 
			
		||||
            else itemString.append("\"Closed\"");
 | 
			
		||||
            if(sensors[i].type == Sensor::TYPE_DOOR)
 | 
			
		||||
            {
 | 
			
		||||
                if(static_cast<bool>(sensors[i].field)) itemString.append("\"Open\"");
 | 
			
		||||
                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
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    bool showHidden_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    SensorListWidget(QWidget *parent = nullptr);
 | 
			
		||||
    SensorListWidget(SensorStore& sensorStore, QWidget* parent = nullptr);
 | 
			
		||||
    SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr);
 | 
			
		||||
    SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr);
 | 
			
		||||
    virtual ~SensorListWidget(){}
 | 
			
		||||
    void setShowHidden(const bool showHidden);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue