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
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue