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

Add ID to ProgramBlock.

Add Support for ProgramBlocks in the ControlView:
 -Adds a ProgramBlockControlItem
 -Adds a ProgramBlockControl.qml
 -Adds support in ControlPanel.h and ControlView.qml
 -The ProgramBlockModel now returns the name of a ProgramBlock for the DisplayRole
parent e3bd0639
...@@ -109,9 +109,9 @@ std::function<void()> loadData(QByteArray data){ ...@@ -109,9 +109,9 @@ std::function<void()> loadData(QByteArray data){
} }
password=QCryptographicHash::hash(QString("admin").toLatin1(),QCryptographicHash::Sha3_256); password=QCryptographicHash::hash(QString("admin").toLatin1(),QCryptographicHash::Sha3_256);
return [=](){ return [=](){
ControlPanel::getLastCreated()->loadFromJsonObject(o["ControlPanel"].toObject());
GUI::MapView::getLastCreated()->loadFromJsonObject(o["MapView"].toObject()); GUI::MapView::getLastCreated()->loadFromJsonObject(o["MapView"].toObject());
Modules::ProgramBlockManager::readFromJsonObject(o["ProgramBlockManager"].toObject()); Modules::ProgramBlockManager::readFromJsonObject(o["ProgramBlockManager"].toObject());
ControlPanel::getLastCreated()->loadFromJsonObject(o["ControlPanel"].toObject());
}; };
} }
......
...@@ -275,3 +275,38 @@ void DimmerGroupControlItemData::shouldOverrideValue(bool o){ ...@@ -275,3 +275,38 @@ void DimmerGroupControlItemData::shouldOverrideValue(bool o){
} }
} }
// start ProgramBlockControlItemData
ProgramBlockControlItemData::ProgramBlockControlItemData(Modules::ProgramBlock * p,QObject *parent):ControlItemData(ControlItemData::PROGRAM_BLOCK,parent){
setProgramBlock(p);
}
ProgramBlockControlItemData::ProgramBlockControlItemData(const QJsonObject &o,QObject *parent):
ControlItemData(o,parent){
ID id(o);
for(const auto & p : Modules::ProgramBlockManager::model){
if(p->getID() == id){
setProgramBlock(p.get());
return;
}
}
}
void ProgramBlockControlItemData::writeJsonObject(QJsonObject &o){
ControlItemData::writeJsonObject(o);
if(program)
o.insert("programBlock",QString::number(program->getID().value()));
}
void ProgramBlockControlItemData::setProgramBlock(Modules::ProgramBlock *p){
if(p!=program){
QObject::disconnect(connection);
program = p;
if(program){
QQmlEngine::setObjectOwnership(program,QQmlEngine::CppOwnership);
connection = QObject::connect(program,&QObject::destroyed,[this](){
setProgramBlock(nullptr);
});
}
emit programBlockChanged();
}
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include "programm.h" #include "programm.h"
#include "device.h" #include "device.h"
#include "programms/programblock.h"
class ControlItemData : public QObject class ControlItemData : public QObject
{ {
...@@ -14,7 +15,7 @@ private: ...@@ -14,7 +15,7 @@ private:
int startXBlock=0; int startXBlock=0;
int startYBlock=0; int startYBlock=0;
public: public:
enum Type{PROGRAMM, SWITCH_GROUP, DIMMER_GROUP}; enum Type{PROGRAMM, SWITCH_GROUP, DIMMER_GROUP, PROGRAM_BLOCK};
private: private:
Type type; Type type;
public: public:
...@@ -195,4 +196,20 @@ signals: ...@@ -195,4 +196,20 @@ signals:
void shouldOverrideValueChanged(); void shouldOverrideValueChanged();
}; };
class ProgramBlockControlItemData : public ControlItemData{
Q_OBJECT
Q_PROPERTY(Modules::ProgramBlock* programBlock READ getProgramBlock WRITE setProgramBlock NOTIFY programBlockChanged)
Modules::ProgramBlock * program=nullptr;
QMetaObject::Connection connection;
public:
ProgramBlockControlItemData(Modules::ProgramBlock * p,QObject *parent = nullptr);
ProgramBlockControlItemData(const QJsonObject &o,QObject *parent = nullptr);
~ProgramBlockControlItemData()override{QObject::disconnect(connection);}
virtual void writeJsonObject(QJsonObject &o)override;
void setProgramBlock(Modules::ProgramBlock * );
Modules::ProgramBlock * getProgramBlock()const{return program;}
signals:
void programBlockChanged();
};
#endif // CONTROLITEMDATA_H #endif // CONTROLITEMDATA_H
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
ControlPanel * ControlPanel::lastCreated = nullptr; ControlPanel * ControlPanel::lastCreated = nullptr;
QQmlEngine * ControlPanel::engine = nullptr; QQmlEngine * ControlPanel::engine = nullptr;
ControlPanel::ControlPanel():programm(engine,QUrl("qrc:/ControlPane/ProgrammControl.qml")),switchGroup(engine,QUrl("qrc:/ControlPane/SwitchGroupControl.qml")),dimmerGroup(engine,QUrl("qrc:/ControlPane/DimmerGroupControl.qml")) ControlPanel::ControlPanel():programm(engine,QUrl("qrc:/ControlPane/ProgrammControl.qml")),switchGroup(engine,QUrl("qrc:/ControlPane/SwitchGroupControl.qml")),dimmerGroup(engine,QUrl("qrc:/ControlPane/DimmerGroupControl.qml")),programBlock(engine,QUrl("qrc:/ControlPane/ProgramBlockControl.qml"))
{ {
lastCreated = this; lastCreated = this;
if(engine==nullptr){ if(engine==nullptr){
...@@ -22,6 +22,8 @@ ControlPanel::ControlPanel():programm(engine,QUrl("qrc:/ControlPane/ProgrammCont ...@@ -22,6 +22,8 @@ ControlPanel::ControlPanel():programm(engine,QUrl("qrc:/ControlPane/ProgrammCont
throw std::runtime_error(switchGroup.errorString().toStdString()); throw std::runtime_error(switchGroup.errorString().toStdString());
if(programm.isError()) if(programm.isError())
throw std::runtime_error(programm.errorString().toStdString()); throw std::runtime_error(programm.errorString().toStdString());
if(programBlock.isError())
throw std::runtime_error(programBlock.errorString().toStdString());
} }
void ControlPanel::writeJsonObject(QJsonObject &o){ void ControlPanel::writeJsonObject(QJsonObject &o){
...@@ -57,6 +59,8 @@ void ControlPanel::loadFromJsonObject(const QJsonObject &o){ ...@@ -57,6 +59,8 @@ void ControlPanel::loadFromJsonObject(const QJsonObject &o){
createControlItem(switchGroup,new SwitchGroupControlItemData(o)); createControlItem(switchGroup,new SwitchGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::DIMMER_GROUP){ }else if(o["type"].toInt()==ControlItemData::DIMMER_GROUP){
createControlItem(dimmerGroup,new DimmerGroupControlItemData(o)); createControlItem(dimmerGroup,new DimmerGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::PROGRAM_BLOCK){
createControlItem(programBlock,new ProgramBlockControlItemData(o));
} }
} }
} }
...@@ -74,6 +78,11 @@ void ControlPanel::addDimmerGroupControl(){ ...@@ -74,6 +78,11 @@ void ControlPanel::addDimmerGroupControl(){
createControlItem(dimmerGroup,new DimmerGroupControlItemData()); createControlItem(dimmerGroup,new DimmerGroupControlItemData());
} }
void ControlPanel::addProgramBlockControl(Modules::ProgramBlock *p){
if(p==nullptr)
throw std::runtime_error("Nullpointer für neues Object");
createControlItem(programBlock,new ProgramBlockControlItemData(p));
}
void ControlPanel::hoverEnterEvent(QHoverEvent *event){ void ControlPanel::hoverEnterEvent(QHoverEvent *event){
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QQuickItem> #include <QQuickItem>
#include "programm.h" #include "programm.h"
#include "programms/programblock.h"
#include "controlitemdata.h" #include "controlitemdata.h"
/** /**
...@@ -18,6 +19,7 @@ class ControlPanel : public QQuickItem ...@@ -18,6 +19,7 @@ class ControlPanel : public QQuickItem
QQmlComponent programm; QQmlComponent programm;
QQmlComponent switchGroup; QQmlComponent switchGroup;
QQmlComponent dimmerGroup; QQmlComponent dimmerGroup;
QQmlComponent programBlock;
int menuHeight; int menuHeight;
int menuWidth; int menuWidth;
protected: protected:
...@@ -42,6 +44,11 @@ public: ...@@ -42,6 +44,11 @@ public:
* @brief addDimmerGroupControl add a DimmerControlItem to the panel that set the channel values from 0 to 255 of the first channel of the selected Devices * @brief addDimmerGroupControl add a DimmerControlItem to the panel that set the channel values from 0 to 255 of the first channel of the selected Devices
*/ */
Q_INVOKABLE void addDimmerGroupControl(); Q_INVOKABLE void addDimmerGroupControl();
/**
* @brief addProgramBlockControl adds a ProgramBlockControlItem to the panel to start and stop Programblocks
* @param programBlock the ProgramBlock that the controlItem should control
*/
Q_INVOKABLE void addProgramBlockControl(Modules::ProgramBlock * programBlock);
int getMenuHeight()const{return menuHeight;} int getMenuHeight()const{return menuHeight;}
int getMenuWidth ()const{return menuWidth;} int getMenuWidth ()const{return menuWidth;}
void setMenuHeight(int i){if(i!=menuHeight){menuHeight=i;emit menuHeightChanged();}} void setMenuHeight(int i){if(i!=menuHeight){menuHeight=i;emit menuHeightChanged();}}
......
...@@ -38,7 +38,7 @@ namespace Modules { ...@@ -38,7 +38,7 @@ namespace Modules {
t->load(lo); t->load(lo);
} }
ProgramBlock::ProgramBlock(const QJsonObject& o):name(o["name"].toString()){ ProgramBlock::ProgramBlock(const QJsonObject& o):name(o["name"].toString()),id(o){
// Wir erstellen erstmal alle objecte mit passendem Typ und ID // Wir erstellen erstmal alle objecte mit passendem Typ und ID
std::map<QString,std::shared_ptr<Program>> programs; std::map<QString,std::shared_ptr<Program>> programs;
std::map<QString,std::shared_ptr<Filter>> filter; std::map<QString,std::shared_ptr<Filter>> filter;
...@@ -349,6 +349,7 @@ namespace Modules { ...@@ -349,6 +349,7 @@ namespace Modules {
} }
void ProgramBlock::writeJsonObject(QJsonObject &o){ void ProgramBlock::writeJsonObject(QJsonObject &o){
id.writeJsonObject(o);
o["name"] = name; o["name"] = name;
// Wir speichern zu jedem Programm/Filter/Consumer ein Object ab, das den Typnamen und eine ID, wir nehmen die Adresse im Arbeitsspeicher. // Wir speichern zu jedem Programm/Filter/Consumer ein Object ab, das den Typnamen und eine ID, wir nehmen die Adresse im Arbeitsspeicher.
// Wir speichern die Connections, indem wir für die Source und die Targets die Adressen(IDs) der jeweiligen Pointer speichern. // Wir speichern die Connections, indem wir für die Source und die Targets die Adressen(IDs) der jeweiligen Pointer speichern.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <QObject> #include <QObject>
#include <memory> #include <memory>
#include <modelvector.h> #include <modelvector.h>
#include "id.h"
namespace Modules { namespace Modules {
...@@ -95,6 +96,7 @@ namespace Modules { ...@@ -95,6 +96,7 @@ namespace Modules {
*/ */
QString name; QString name;
Controller * controller = nullptr; Controller * controller = nullptr;
ID id;
public: public:
enum Status{Stopped=0, Running=1, Paused=2}status = Stopped; enum Status{Stopped=0, Running=1, Paused=2}status = Stopped;
Q_ENUM(Status) Q_ENUM(Status)
...@@ -274,6 +276,7 @@ namespace Modules { ...@@ -274,6 +276,7 @@ namespace Modules {
public: public:
ProgramBlock(QString name = "No name"):name(name){} ProgramBlock(QString name = "No name"):name(name){}
ID getID()const{return id;}
void setName( const QString _name){ void setName( const QString _name){
if(_name != name){ if(_name != name){
name = _name; name = _name;
...@@ -331,6 +334,14 @@ namespace Modules { ...@@ -331,6 +334,14 @@ namespace Modules {
class ProgrammBlockVector : public ModelVector<std::shared_ptr<ProgramBlock>>{ class ProgrammBlockVector : public ModelVector<std::shared_ptr<ProgramBlock>>{
Q_OBJECT Q_OBJECT
public:
virtual QVariant data(const QModelIndex &index, int role) const override{
auto res = ModelVector<std::shared_ptr<ProgramBlock>>::data(index,role);
if(res.isValid() && role == Qt::DisplayRole){
return res.value<ProgramBlock*>()->getName();
}
return res;
}
}; };
class ProgramBlockManager{ class ProgramBlockManager{
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
<file>icons/material-pause.svg</file> <file>icons/material-pause.svg</file>
<file>icons/material-play.svg</file> <file>icons/material-play.svg</file>
<file>icons/material-stop.svg</file> <file>icons/material-stop.svg</file>
<file alias="ControlPane/ProgramBlockControl.qml">qml/ProgramBlockControl.qml</file>
<file alias="ControlPane/ControlItemBlock.qml">qml/ControlItemBlock.qml</file> <file alias="ControlPane/ControlItemBlock.qml">qml/ControlItemBlock.qml</file>
<file alias="ControlPane/ProgrammControl.qml">qml/ProgrammControl.qml</file> <file alias="ControlPane/ProgrammControl.qml">qml/ProgrammControl.qml</file>
<file alias="ControlPane/SwitchGroupControl.qml">qml/SwitchGroupControl.qml</file> <file alias="ControlPane/SwitchGroupControl.qml">qml/SwitchGroupControl.qml</file>
......
...@@ -8,14 +8,18 @@ import custom.licht 1.0 ...@@ -8,14 +8,18 @@ import custom.licht 1.0
ControlPanel{ ControlPanel{
//we can only define enums here
enum Select{
ProgramBlock,
Program
}
onExitMenuArea: programm.width = programm.height onExitMenuArea: programm.width = programm.height
menuHeight: height-switchGroup.y menuHeight: height-programBlock.y
menuWidth: width-programm.x menuWidth: width-programm.x
RoundButton{ RoundButton{
onClicked: selectProgrammDialog.visible=true onClicked: selectProgramDialog.createProgram()
visible: UserManagment.currentUser.havePermission(Permission.ADD_CONTROL_ITEM); visible: UserManagment.currentUser.havePermission(Permission.ADD_CONTROL_ITEM);
id:programm id:programm
text: "+" text: "+"
...@@ -35,10 +39,13 @@ ControlPanel{ ...@@ -35,10 +39,13 @@ ControlPanel{
textAnimation.newText="Add Programm"; textAnimation.newText="Add Programm";
dimmerGroup.y = programm.y; dimmerGroup.y = programm.y;
switchGroup.y = programm.y; switchGroup.y = programm.y;
programBlock.y = programm.y;
}else if(!running&&programm.hovered){ }else if(!running&&programm.hovered){
textAnimation.newText="+"; textAnimation.newText="+";
dimmerGroup.y = programm.y-programm.height; dimmerGroup.y = programm.y-programm.height;
switchGroup.y = programm.y-programm.height*2; switchGroup.y = programm.y-programm.height*2;
switchGroup.y = programm.y-programm.height*2;
programBlock.y = programm.y-programm.height*3;
} }
} }
} }
...@@ -47,9 +54,11 @@ ControlPanel{ ...@@ -47,9 +54,11 @@ ControlPanel{
if(width!=height){ if(width!=height){
dimmerGroup.y = programm.y-programm.height dimmerGroup.y = programm.y-programm.height
switchGroup.y = programm.y-programm.height*2; switchGroup.y = programm.y-programm.height*2;
programBlock.y = programm.y-programm.height*3;
}else{ }else{
dimmerGroup.y = programm.y; dimmerGroup.y = programm.y;
switchGroup.y = programm.y; switchGroup.y = programm.y;
programBlock.y = programm.y;
} }
} }
...@@ -108,12 +117,33 @@ ControlPanel{ ...@@ -108,12 +117,33 @@ ControlPanel{
} }
onClicked: addDimmerGroupControl() onClicked: addDimmerGroupControl()
} }
RoundButton{
visible: UserManagment.currentUser.havePermission(Permission.ADD_CONTROL_ITEM);
z:1.3
id: programBlock
text:"ProgramBlock"
anchors.right: programm.right
anchors.left: programm.left
Behavior on y{
NumberAnimation{duration: 100}
}
onClicked: selectProgramDialog.createProgramBlock()
}
Dialog{ Dialog{
modality: Qt.WindowModal modality: Qt.WindowModal
id:selectProgrammDialog id:selectProgramDialog
title: "Select Programm" property int select: ControlView.Select.Program
title: select === ControlView.Select.Program?"Select Program":"Select ProgramBlock"
width:300 width:300
function createProgram(){
select = ControlView.Select.Program;
visible = true;
}
function createProgramBlock(){
select = ControlView.Select.ProgramBlock;
visible = true;
}
contentItem: RowLayout { contentItem: RowLayout {
Pane{ Pane{
Layout.fillWidth: true Layout.fillWidth: true
...@@ -124,21 +154,25 @@ ControlPanel{ ...@@ -124,21 +154,25 @@ ControlPanel{
ComboBox{ ComboBox{
Layout.fillWidth: true Layout.fillWidth: true
id:programmSelect id:programmSelect
model: programmModel model: selectProgramDialog.select === ControlView.Select.Program?programmModel:programBlocksModel
textRole: "display" textRole: "display"
} }
RowLayout{ RowLayout{
Button{ Button{
Layout.fillWidth: true Layout.fillWidth: true
text:"Abbrechen" text:"Abbrechen"
onClicked: selectProgrammDialog.visible = false onClicked: selectProgramDialog.visible = false
} }
Button{ Button{
Layout.fillWidth: true Layout.fillWidth: true
text:"Hinzufügen" text:"Hinzufügen"
onClicked: { onClicked: {
selectProgrammDialog.visible = false; selectProgramDialog.visible = false;
if(selectProgramDialog.select === ControlView.Select.Program){
addProgrammControl(programmModel.data(programmModel.index(programmSelect.currentIndex,0),-1)); addProgrammControl(programmModel.data(programmModel.index(programmSelect.currentIndex,0),-1));
}else{
addProgramBlockControl(programBlocksModel.data(programBlocksModel.index(programmSelect.currentIndex,0),-1));
}
} }
} }
......
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