Commit c48af24b authored by Leander Schulten's avatar Leander Schulten
Browse files

Added Methods for the Filter and JSON load save Methods

parent 2e348c32
#include "device.h"
#include <QJsonArray>
QString Device::syncServiceClassName;
Device::Device(const QJsonObject &o):NamedObject(o,&syncServiceClassName),IDBase<Device>(o),
prototype(IDBase<DevicePrototype>::getIDBaseObjectByID(o["prototype"].toString().toLong())),
startDMXChannel(o["startDMXChannel"].toInt()),
position(o["position"].toObject()["x"].toInt(),o["position"].toObject()["y"].toInt()){
const auto filter = o["filter"].toArray();
for(const auto f_:filter){
const auto f = f_.toObject();
const auto id = f["channel"].toString().toLongLong();
for(auto i = getChannels().cbegin();i!=getChannels().cend();++i){
if((**i).getID()==id){
this->filter.emplace_back(*i,new DMXChannelFilter(f["filter"].toObject()));
break;
}
}
}
}
void Device::writeJsonObject(QJsonObject &o) const{
......@@ -18,6 +28,16 @@ void Device::writeJsonObject(QJsonObject &o) const{
position.insert("y",this->position.y());
o.insert("position",position);
o.insert("startDMXChannel",static_cast<int>(startDMXChannel));
QJsonArray filter;
for(const auto f : this->filter){
QJsonObject o;
o.insert("channel",QString::number(f.first->getID().value()));
QJsonObject fil;
f.second->writeJsonData(fil);
o.insert("filter",fil);
filter.append(o);
}
o.insert("filter",filter);
}
void Device::channelRemoved(Channel *c){
......@@ -33,3 +53,21 @@ void Device::channelRemoved(Channel *c){
void Device::channelAdded(Channel *c){
filter.emplace_back(c,new DMXChannelFilter());
}
DMXChannelFilter * Device::getFilterForChannel( Channel *c){
for(auto i = filter.cbegin();i!=filter.cend();++i){
if(i->first==c)
return i->second;
}
filter.emplace_back(c,new DMXChannelFilter);
return filter.back().second;
}
DMXChannelFilter * Device::getFilterForChannelindex(int index){
for(auto i = getChannels().cbegin();i!=getChannels().cend();++i){
if((**i).getIndex()==index){
return getFilterForChannel(*i);
}
}
return nullptr;
}
......@@ -45,6 +45,9 @@ public:
Device(DevicePrototype * prototype, int startDMXChannel, QString name, QString desciption="",QPoint position = QPoint(-1,-1)):NamedObject(name,desciption,&syncServiceClassName),prototype(prototype),startDMXChannel(startDMXChannel),position(position){
connect(prototype,&DevicePrototype::channelAdded,this,&Device::channelAdded);
for(auto i = prototype->getChannels().cbegin();i != prototype->getChannels().cend();++i){
filter.emplace_back(*i,new DMXChannelFilter);
}
}
void writeJsonObject(QJsonObject &o)const;
......@@ -59,6 +62,8 @@ public:
const std::vector<std::pair<Channel*,DMXChannelFilter*>> & getChannelFilter()const{return filter;}
DMXChannelFilter * getFilterForChannel( Channel * c);
DMXChannelFilter * getFilterForChannelindex(int intdex);
// static methods for the sync service:
static void update (const ID &id, const QString &name,const QString &value){
auto d = IDBase<Device>::getIDBaseObjectByID(id);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment