switched from qsettings to json added editng of actors

This commit is contained in:
Carl Klemm 2019-06-06 21:19:12 +02:00
parent b04fbfb5bc
commit df27b622a0
141 changed files with 4402 additions and 5068 deletions

112
src/actors/sensoractor.cpp Normal file
View file

@ -0,0 +1,112 @@
#include "sensoractor.h"
#include <QDebug>
SensorActor::SensorActor(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
{
}
SensorActor::SensorActor(QObject* parent): Actor(parent)
{
}
void SensorActor::setSensor(const Sensor sensor)
{
sensor_ = sensor;
}
void SensorActor::sensorEvent(Sensor sensor)
{
if(sensor == sensor_)
{
qDebug()<<"got sensor: "<<sensor.type<<" "<<sensor.id<<" want: "<<sensor_.type<<" "<<sensor_.id;
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_ && sensor.field >= threshold_ ) performAction();
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_ && sensor.field <= threshold_) performAction();
sensor_ = sensor;
}
}
void SensorActor::setSloap(uint8_t sloap)
{
sloap_=sloap;
}
void SensorActor::setThreshold(float threshold)
{
threshold_ = threshold;
}
float SensorActor::getThreshold()
{
return threshold_;
}
uint8_t SensorActor::getSloap()
{
return sloap_;
}
void SensorActor::store(QJsonObject& json)
{
json["Type"] = "Sensor";
Actor::store(json);
json["Sloap"] = sloap_;
json["Threshold"] = threshold_;
json["SensorType"] = static_cast<int>(sensor_.type);
json["SensorId"] = static_cast<int>(sensor_.id);
json["SensorField"] = sensor_.field;
json["SensorName"] = sensor_.name;
}
void SensorActor::load(const QJsonObject& json)
{
Actor::load(json);
sloap_ = json["Sloap"].toInt(0);
threshold_ = json["Threshold"].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");
}
void SensorActor::store(QString subsecton, QSettings* settings)
{
settings->setValue(subsecton + "Type", "Sensor");
Actor::store(subsecton, settings);
settings->setValue(subsecton + "Sloap", sloap_);
settings->setValue(subsecton + "Threshold", threshold_);
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 SensorActor::load(QString subsecton, QSettings* settings)
{
Actor::load(subsecton, settings);
sloap_ = settings->value(subsecton + "Sloap").toUInt();
threshold_ = settings->value(subsecton + "Threshold").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 SensorActor::getName()
{
if(name.size() > 0) return name;
else
{
QString string;
string = "Sensor \"" + sensor_.name + "\"";
if(sloap_ == SLOPE_UP) string.append(" rises to ");
else if (sloap_ == SLOPE_DOWN) string.append(" drops to ");
else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
string.append(QString::number(threshold_) + " ");
return string;
}
}