switched from qsettings to json added editng of actors
This commit is contained in:
100
src/actor.cpp.autosave
Normal file
100
src/actor.cpp.autosave
Normal file
@ -0,0 +1,100 @@
|
||||
#include "actor.h"
|
||||
#include<QDebug>
|
||||
|
||||
Actor::Actor(QObject *parent): QObject(parent)
|
||||
{
|
||||
buildName();
|
||||
}
|
||||
|
||||
Actor::~Actor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Actor::performAction()
|
||||
{
|
||||
if(active)
|
||||
{
|
||||
trigger();
|
||||
if(action_ == ACTION_OFF) off();
|
||||
else if(action_ == ACTION_ON) on();
|
||||
else if(action_ != ACTION_TOGGLE) toggle();
|
||||
else if(action_ != ACTION_VALUE) sigValue(value_);
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::makeActive()
|
||||
{
|
||||
active = true;
|
||||
}
|
||||
|
||||
|
||||
void Actor::makeInactive()
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void Actor::buildName()
|
||||
{
|
||||
name = "Actor";
|
||||
appendActionToName();
|
||||
}
|
||||
|
||||
void Actor::appendActionToName()
|
||||
{
|
||||
if(action_ == ACTION_OFF || action_ == ACTION_DEFAULT ) name.append("off");
|
||||
else if(action_ == ACTION_ON ) name.append("on");
|
||||
else if(action_ == ACTION_TOGGLE ) name.append("toggle");
|
||||
else if(action_ == ACTION_VALUE ) name.append("value to " + QString::number(value_));
|
||||
}
|
||||
|
||||
void Actor::setActive(int state)
|
||||
{
|
||||
state ? makeActive() : makeInactive();
|
||||
buildName();
|
||||
}
|
||||
|
||||
bool Actor::isActive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
bool Actor::isExausted()
|
||||
{
|
||||
return exausted;
|
||||
}
|
||||
|
||||
void Actor::saveSettings(QString subsecton, QSettings* settings)
|
||||
{
|
||||
settings->setValue(subsecton + "Active", active);
|
||||
settings->setValue(subsecton + "Exausted", exausted);
|
||||
settings->setValue(subsecton + "Name", name);
|
||||
settings->setValue(subsecton + "Action", action_);
|
||||
}
|
||||
|
||||
void Actor::loadSettings(QString subsecton, QSettings* settings)
|
||||
{
|
||||
active = settings->value(subsecton + "Active").toBool();
|
||||
exausted = settings->value(subsecton + "Exausted").toBool();
|
||||
name = settings->value(subsecton + "Name").toString();
|
||||
action_ = settings->value(subsecton + "Action").toUInt();
|
||||
}
|
||||
|
||||
void Actor::setAction(uint8_t action)
|
||||
{
|
||||
action_ = action;
|
||||
qDebug()<<"setting action to "<<action;
|
||||
buildName();
|
||||
}
|
||||
|
||||
void Actor::setValue(uint8_t value)
|
||||
{
|
||||
value_=value;
|
||||
buildName();
|
||||
}
|
||||
|
||||
void Actor::onStateChanged(bool state)
|
||||
{
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user