switched from qsettings to json added editng of actors
This commit is contained in:
parent
b04fbfb5bc
commit
df27b622a0
141 changed files with 4402 additions and 5068 deletions
111
src/actors/regulator.cpp
Normal file
111
src/actors/regulator.cpp
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include "regulator.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Regulator::Regulator(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Regulator::Regulator(QObject* parent): Actor(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Regulator::setSensor(const Sensor sensor)
|
||||
{
|
||||
sensor_ = sensor;
|
||||
}
|
||||
|
||||
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_) )
|
||||
{
|
||||
trigger();
|
||||
sigValue(triggerValue);
|
||||
}
|
||||
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_) )
|
||||
{
|
||||
trigger();
|
||||
sigValue(!triggerValue);
|
||||
}
|
||||
sensor_ = sensor;
|
||||
}
|
||||
}
|
||||
|
||||
void Regulator::setPoint(float setPoint)
|
||||
{
|
||||
setPoint_ = setPoint;
|
||||
}
|
||||
|
||||
void Regulator::setBand ( float band )
|
||||
{
|
||||
band_ = band;
|
||||
}
|
||||
|
||||
void Regulator::setInvert( bool invert )
|
||||
{
|
||||
invert_ = invert;
|
||||
}
|
||||
|
||||
void Regulator::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Regulator";
|
||||
Actor::store(json);
|
||||
json["Band"] = band_;
|
||||
json["SetPoint"] = setPoint_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
}
|
||||
|
||||
void Regulator::load(const QJsonObject& json)
|
||||
{
|
||||
Actor::load(json);
|
||||
band_ = json["Band"].toInt(1);
|
||||
setPoint_ = json["SetPoint"].toInt(22);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
}
|
||||
|
||||
void Regulator::store(QString subsecton, QSettings* settings)
|
||||
{
|
||||
settings->setValue(subsecton + "Type", "Regulator");
|
||||
Actor::store(subsecton, settings);
|
||||
settings->setValue(subsecton + "Band", band_);
|
||||
settings->setValue(subsecton + "SetPoint", setPoint_);
|
||||
settings->setValue(subsecton + "SensorType", static_cast<int>(sensor_.type));
|
||||
settings->setValue(subsecton + "SensorId", static_cast<int>(sensor_.id));
|
||||
settings->setValue(subsecton + "SensorField", sensor_.field);
|
||||
settings->setValue(subsecton + "SensorName", sensor_.name);
|
||||
}
|
||||
|
||||
void Regulator::load(QString subsecton, QSettings* settings)
|
||||
{
|
||||
Actor::load(subsecton, settings);
|
||||
|
||||
setPoint_ = settings->value(subsecton + "SetPoint").toUInt();
|
||||
band_ = settings->value(subsecton + "Band").toFloat();
|
||||
sensor_.type = settings->value(subsecton + "SensorType").toUInt();
|
||||
sensor_.id = settings->value(subsecton + "SensorId").toUInt();
|
||||
sensor_.field = settings->value(subsecton + "SensorField").toFloat();
|
||||
sensor_.name = settings->value(subsecton + "SensorName").toString();
|
||||
}
|
||||
|
||||
QString Regulator::getName()
|
||||
{
|
||||
if(name.size() > 0) return name;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Regulate \"" + sensor_.name + "\" to ";
|
||||
string.append(QString::number(setPoint_) + " ");
|
||||
return string;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue