Aufgrund einer Störung des s3 Storage, könnten in nächster Zeit folgende GitLab Funktionen nicht zur Verfügung stehen: LFS, Container Registry, Job Artifacs, Uploads (Wiki, Bilder, Projekt-Exporte). Wir bitten um Verständnis. Es wird mit Hochdruck an der Behebung des Problems gearbeitet. Weitere Informationen zur Störung des Object Storage finden Sie hier: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/59-object-storage-pilot

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

ControlPane: Move the creation of QQMLComponents in separate method. Set the...

ControlPane: Move the creation of QQMLComponents in separate method. Set the ownership of ControlItemData, so that this objects gets deleted, when ControlItems gets delete. Sets the "controlData" property before the creation of a ControlItem, so that you do not get errors like "controlData.foo" is null
parent 52d5025d
......@@ -6,7 +6,8 @@ ControlItemData::ControlItemData(Type t,QObject *parent) : QObject(parent),type(
}
ControlItemData::ControlItemData(const QJsonObject &o):
ControlItemData::ControlItemData(const QJsonObject &o, QObject *parent):
QObject(parent),
startXBlock(o["startXBlock"].toInt()),
startYBlock(o["startYBlock"].toInt()),
type(static_cast<Type>(o["type"].toInt())){
......@@ -38,8 +39,8 @@ ProgrammControlItemData::ProgrammControlItemData(Programm * p,QObject *parent):C
}
ProgrammControlItemData::ProgrammControlItemData(const QJsonObject &o):
ControlItemData(o),
ProgrammControlItemData::ProgrammControlItemData(const QJsonObject &o, QObject *parent):
ControlItemData(o,parent),
programm(IDBase<Programm>::getIDBaseObjectByID(o["programm"])){
}
......@@ -85,7 +86,7 @@ void GroupModel::handleRowsRemoved(const QModelIndex &parent, int first, int las
// GroupControlItemData
GroupControlItemData::GroupControlItemData(const QJsonObject &o):ControlItemData(o),name(o["name"].toString()){
GroupControlItemData::GroupControlItemData(const QJsonObject &o, QObject *parent):ControlItemData(o,parent),name(o["name"].toString()){
const auto enabled = o["enabledDevices"].toArray();
auto iter = IDBase<Device>::getAllIDBases().cbegin();
int index = 0;
......@@ -149,7 +150,7 @@ void GroupControlItemData::setName(QString n){
}
// SwitchGroupControlItemData
SwitchGroupControlItemData::SwitchGroupControlItemData(const QJsonObject &o):GroupControlItemData(o),
SwitchGroupControlItemData::SwitchGroupControlItemData(const QJsonObject &o, QObject *parent):GroupControlItemData(o,parent),
activated(o["activated"].toBool()),
activateCooldown(o["activateCooldown"].toInt()),
deactivateCooldown(o["deactivateCooldown"].toInt()){
......
......@@ -18,9 +18,10 @@ public:
private:
Type type;
public:
ControlItemData(){}
ControlItemData() = default;
virtual ~ControlItemData() = default;
explicit ControlItemData(Type t, QObject *parent = nullptr);
ControlItemData(const QJsonObject &o);
ControlItemData(const QJsonObject &o, QObject *parent = nullptr);
virtual void writeJsonObject(QJsonObject &o);
int getStartXBlock()const{return startXBlock;}
int getStartYBlock()const{return startYBlock;}
......@@ -37,7 +38,7 @@ class ProgrammControlItemData : public ControlItemData{
Programm * programm=nullptr;
public:
ProgrammControlItemData(Programm * p,QObject *parent = nullptr);
ProgrammControlItemData(const QJsonObject &o);
ProgrammControlItemData(const QJsonObject &o,QObject *parent = nullptr);
virtual void writeJsonObject(QJsonObject &o);
void setProgramm(Programm * );
Programm * getProgramm()const{return programm;}
......@@ -112,7 +113,7 @@ class GroupControlItemData : public ControlItemData{
QString name;
public:
GroupControlItemData(ControlItemData::Type t, QObject *parent = nullptr):ControlItemData(t,parent){}
GroupControlItemData(const QJsonObject &o);
GroupControlItemData(const QJsonObject &o,QObject *parent = nullptr);
virtual void writeJsonObject(QJsonObject &o);
GroupModel * getGroupModel(){return &groupModel;}
void forEach(std::function<void(Device*)> f);
......@@ -134,7 +135,7 @@ class SwitchGroupControlItemData : public GroupControlItemData{
int deactivateCooldown = 1000;
public:
SwitchGroupControlItemData(QObject *parent = nullptr):GroupControlItemData(SWITCH_GROUP,parent){}
SwitchGroupControlItemData(const QJsonObject &o);
SwitchGroupControlItemData(const QJsonObject &o,QObject *parent = nullptr);
virtual void writeJsonObject(QJsonObject &o);
void setActivated(bool a);
bool isActivated()const{return activated;}
......
......@@ -3,6 +3,7 @@
#include "controlitem.h"
#include <QJsonArray>
#include <exception>
#include <QQmlContext>
ControlPanel * ControlPanel::lastCreated = nullptr;
......@@ -37,27 +38,25 @@ void ControlPanel::writeJsonObject(QJsonObject &o){
o.insert("ControlItems",a);
}
void ControlPanel::createControlItem(QQmlComponent &component, ControlItemData *data){
QQmlContext* context = new QQmlContext(engine->rootContext(),engine);
context->setContextProperty("__controlData",data);
ControlItem * item = static_cast<ControlItem*>(component.create(context));
item->setParentItem(this);
data->setParent(item);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
}
void ControlPanel::loadFromJsonObject(const QJsonObject &o){
const auto array = o["ControlItems"].toArray();
for(const auto o_ : array){
const auto o = o_.toObject();
if(o["type"].toInt()==ControlItemData::PROGRAMM){
ControlItem * item = static_cast<ControlItem*>(programm.create());
item->setControlData(new ProgrammControlItemData(o));
item->setParentItem(this);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
createControlItem(programm,new ProgrammControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::SWITCH_GROUP){
ControlItem * item = static_cast<ControlItem*>(switchGroup.create());
assert(item!=nullptr);
item->setControlData(new SwitchGroupControlItemData(o));
item->setParentItem(this);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
createControlItem(switchGroup,new SwitchGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::DIMMER_GROUP){
ControlItem * item = static_cast<ControlItem*>(dimmerGroup.create());
assert(item!=nullptr);
item->setControlData(new DimmerGroupControlItemData(o));
item->setParentItem(this);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
createControlItem(dimmerGroup,new DimmerGroupControlItemData(o));
}
}
}
......@@ -65,24 +64,14 @@ void ControlPanel::loadFromJsonObject(const QJsonObject &o){
void ControlPanel::addProgrammControl(Programm *p){
if(p==nullptr)
throw std::runtime_error("Nullpointer für neues Object");
QQmlEngine::setObjectOwnership(p,QQmlEngine::CppOwnership);
ControlItem * item = static_cast<ControlItem*>(programm.create());
item->setControlData(new ProgrammControlItemData(p,item));
item->setParentItem(this);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
createControlItem(programm,new ProgrammControlItemData(p));
}
void ControlPanel::addSwitchGroupControl(){
ControlItem * item = static_cast<ControlItem*>(switchGroup.create());
item->setControlData(new SwitchGroupControlItemData(item));
item->setParentItem(this);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
createControlItem(switchGroup,new SwitchGroupControlItemData());
}
void ControlPanel::addDimmerGroupControl(){
ControlItem * item = static_cast<ControlItem*>(dimmerGroup.create());
item->setControlData(new DimmerGroupControlItemData(item));
item->setParentItem(this);
QQmlEngine::setObjectOwnership(item,QQmlEngine::JavaScriptOwnership);
createControlItem(dimmerGroup,new DimmerGroupControlItemData());
}
......
......@@ -3,6 +3,7 @@
#include <QQuickItem>
#include "programm.h"
#include "controlitemdata.h"
/**
* @brief The ControlPanel is the Component, that holds multiple ControlItems
......@@ -19,6 +20,13 @@ class ControlPanel : public QQuickItem
QQmlComponent dimmerGroup;
int menuHeight;
int menuWidth;
protected:
/**
* @brief createControlItem creates an ControlItem defined by component and set the ControlItemData field of the ControlData to data
* @param component The component that should be defined, must be a subclass of "qrc:/ControlPane/ControlItem.qml"
* @param data The DataObject that holds the information, this object is owned by the instance created from the component
*/
void createControlItem(QQmlComponent & component, ControlItemData * data);
public:
ControlPanel();
static ControlPanel * getLastCreated(){return lastCreated;}
......
......@@ -7,6 +7,7 @@ import custom.licht 1.0
ControlItemTemplate{
controlData: __controlData
moveable: UserManagment.currentUser.havePermission(Permission.MOVE_CONTROL_ITEM);
id:item
property bool pressed: false
......
Markdown is supported
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