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 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){
}
password=QCryptographicHash::hash(QString("admin").toLatin1(),QCryptographicHash::Sha3_256);
return [=](){
ControlPanel::getLastCreated()->loadFromJsonObject(o["ControlPanel"].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){
}
}
// 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 @@
#include <QObject>
#include "programm.h"
#include "device.h"
#include "programms/programblock.h"
class ControlItemData : public QObject
{
......@@ -14,7 +15,7 @@ private:
int startXBlock=0;
int startYBlock=0;
public:
enum Type{PROGRAMM, SWITCH_GROUP, DIMMER_GROUP};
enum Type{PROGRAMM, SWITCH_GROUP, DIMMER_GROUP, PROGRAM_BLOCK};
private:
Type type;
public:
......@@ -195,4 +196,20 @@ signals:
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
......@@ -9,7 +9,7 @@
ControlPanel * ControlPanel::lastCreated = 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;
if(engine==nullptr){
......@@ -22,6 +22,8 @@ ControlPanel::ControlPanel():programm(engine,QUrl("qrc:/ControlPane/ProgrammCont
throw std::runtime_error(switchGroup.errorString().toStdString());
if(programm.isError())
throw std::runtime_error(programm.errorString().toStdString());
if(programBlock.isError())
throw std::runtime_error(programBlock.errorString().toStdString());
}
void ControlPanel::writeJsonObject(QJsonObject &o){
......@@ -57,6 +59,8 @@ void ControlPanel::loadFromJsonObject(const QJsonObject &o){
createControlItem(switchGroup,new SwitchGroupControlItemData(o));
}else if(o["type"].toInt()==ControlItemData::DIMMER_GROUP){
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(){
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){
......
......@@ -3,6 +3,7 @@
#include <QQuickItem>
#include "programm.h"
#include "programms/programblock.h"
#include "controlitemdata.h"
/**
......@@ -18,6 +19,7 @@ class ControlPanel : public QQuickItem
QQmlComponent programm;
QQmlComponent switchGroup;
QQmlComponent dimmerGroup;
QQmlComponent programBlock;
int menuHeight;
int menuWidth;
protected:
......@@ -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
*/
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 getMenuWidth ()const{return menuWidth;}
void setMenuHeight(int i){if(i!=menuHeight){menuHeight=i;emit menuHeightChanged();}}
......
......@@ -38,7 +38,7 @@ namespace Modules {
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
std::map<QString,std::shared_ptr<Program>> programs;
std::map<QString,std::shared_ptr<Filter>> filter;
......@@ -349,6 +349,7 @@ namespace Modules {
}
void ProgramBlock::writeJsonObject(QJsonObject &o){
id.writeJsonObject(o);
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 die Connections, indem wir für die Source und die Targets die Adressen(IDs) der jeweiligen Pointer speichern.
......
......@@ -11,6 +11,7 @@
#include <QObject>
#include <memory>
#include <modelvector.h>
#include "id.h"
namespace Modules {
......@@ -95,6 +96,7 @@ namespace Modules {
*/
QString name;
Controller * controller = nullptr;
ID id;
public:
enum Status{Stopped=0, Running=1, Paused=2}status = Stopped;
Q_ENUM(Status)
......@@ -274,6 +276,7 @@ namespace Modules {
public:
ProgramBlock(QString name = "No name"):name(name){}
ID getID()const{return id;}
void setName( const QString _name){
if(_name != name){
name = _name;
......@@ -331,6 +334,14 @@ namespace Modules {
class ProgrammBlockVector : public ModelVector<std::shared_ptr<ProgramBlock>>{
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{
......
......@@ -49,6 +49,7 @@
<file>icons/material-pause.svg</file>
<file>icons/material-play.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/ProgrammControl.qml">qml/ProgrammControl.qml</file>
<file alias="ControlPane/SwitchGroupControl.qml">qml/SwitchGroupControl.qml</file>
......
......@@ -8,14 +8,18 @@ import custom.licht 1.0
ControlPanel{
//we can only define enums here
enum Select{
ProgramBlock,
Program
}
onExitMenuArea: programm.width = programm.height
menuHeight: height-switchGroup.y
menuHeight: height-programBlock.y
menuWidth: width-programm.x
RoundButton{
onClicked: selectProgrammDialog.visible=true
onClicked: selectProgramDialog.createProgram()
visible: UserManagment.currentUser.havePermission(Permission.ADD_CONTROL_ITEM);
id:programm
text: "+"
......@@ -35,10 +39,13 @@ ControlPanel{
textAnimation.newText="Add Programm";
dimmerGroup.y = programm.y;
switchGroup.y = programm.y;
programBlock.y = programm.y;
}else if(!running&&programm.hovered){
textAnimation.newText="+";
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;
}
}
}
......@@ -47,9 +54,11 @@ ControlPanel{
if(width!=height){
dimmerGroup.y = programm.y-programm.height
switchGroup.y = programm.y-programm.height*2;
programBlock.y = programm.y-programm.height*3;
}else{
dimmerGroup.y = programm.y;
switchGroup.y = programm.y;
programBlock.y = programm.y;
}
}
......@@ -108,12 +117,33 @@ ControlPanel{
}
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{
modality: Qt.WindowModal
id:selectProgrammDialog
title: "Select Programm"
id:selectProgramDialog
property int select: ControlView.Select.Program
title: select === ControlView.Select.Program?"Select Program":"Select ProgramBlock"
width:300
function createProgram(){
select = ControlView.Select.Program;
visible = true;
}
function createProgramBlock(){
select = ControlView.Select.ProgramBlock;
visible = true;
}
contentItem: RowLayout {
Pane{
Layout.fillWidth: true
......@@ -124,21 +154,25 @@ ControlPanel{
ComboBox{
Layout.fillWidth: true
id:programmSelect
model: programmModel
model: selectProgramDialog.select === ControlView.Select.Program?programmModel:programBlocksModel
textRole: "display"
}
RowLayout{
Button{
Layout.fillWidth: true
text:"Abbrechen"
onClicked: selectProgrammDialog.visible = false
onClicked: selectProgramDialog.visible = false
}
Button{
Layout.fillWidth: true
text:"Hinzufügen"
onClicked: {
selectProgrammDialog.visible = false;
selectProgramDialog.visible = false;
if(selectProgramDialog.select === ControlView.Select.Program){
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