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

Zwischenstand

parent 10a5db1a
......@@ -64,12 +64,104 @@ Item{
}
ProgramBlockEditor{
RowLayout{
anchors.left: page.right
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
programBlock: listView.currentItem.itemData;
ProgramBlockEditor{
anchors.top: parent.top
anchors.bottom: parent.bottom
Layout.fillWidth: true
id: programEditor
programBlock: listView.currentItem.itemData;
}
ColumnLayout{
anchors.top: parent.top
anchors.bottom: parent.bottom
Layout.preferredWidth: 200
Layout.maximumWidth: 200
visible: programEditor.showProperties
spacing: 0
Rectangle{
id:line
color: "lightgrey"
width: 1
anchors.top: parent.top
anchors.left: parent.left
anchors.bottom: parent.bottom
}
id: propertyPane
Label{
id:label
Layout.margins: 8
font.pointSize: 16
text:"Properties"
}
Rectangle{
color: "lightgrey"
Layout.preferredHeight: 1
anchors.left: parent.left
anchors.right: parent.right
}
ListView{
clip:true
Layout.preferredHeight: 200
Layout.fillHeight: true
Layout.preferredWidth: parent.width
id: propertiesView
model: programEditor.propertyInformationModel
delegate: ItemDelegate{
property var itemData : modelData
width: parent.width
text: modelData.name
onClicked: propertiesView.currentIndex = index
}
highlightFollowsCurrentItem: true
highlight: Rectangle{
color: "lightgrey"
}
function update(){
if(propertiesView.currentIndex<0)
return;
var data = propertiesView.currentItem.itemData;
}
}
Rectangle{
id:hline
color: "lightgrey"
Layout.preferredHeight: 1
anchors.left: parent.left
anchors.right: parent.right
}
ColumnLayout{
Layout.maximumHeight: 250
Layout.preferredHeight: 250
Label{
Layout.margins: 5
Layout.preferredHeight: contentHeight
Layout.preferredWidth: 190
clip:true
wrapMode: Text.WordWrap
text:propertiesView.currentItem.itemData.description
}
Slider{
id:slider
}
}
}
}
......
......@@ -5,6 +5,7 @@ import QtQuick.Shapes 1.0
import custom.licht 1.0
Shape{
objectName: "Shape"
property alias color : pathObj.fillColor
anchors.fill: parent;
property alias targetStartIndex: pathObj.startX
......@@ -49,11 +50,11 @@ Shape{
}
}
MouseArea{
/*MouseArea{
x: (targetStartIndex + sourceStartIndex)/2
y: targetBaseline
width: (targetLength + sourceLength)/2
height: (sourceBaseline-targetBaseline)
onClicked: color = "red"
}
}*/
}
......@@ -5,5 +5,7 @@ import custom.licht 1.0
import Qt.labs.handlers 1.0
Label{
DragHandler { }
z: 10
objectName: "Test"
//DragHandler{}
}
......@@ -410,5 +410,17 @@ void CodeEditorHelper::compile(){
emit information(result.second.replace(finfo.absoluteFilePath(),""));
}else
emit information("Compilieren erfolgreich.");
const auto p = Modules::ModuleManager::singletone()->getProgrammModules();
for(const auto & m : p){
qDebug()<< QString::fromStdString(m.name());
}
const auto f = Modules::ModuleManager::singletone()->getFilterModules();
for(const auto & m : f){
qDebug()<< QString::fromStdString(m.name());
}
const auto c = Modules::ModuleManager::singletone()->getConsumerModules();
for(const auto & m : c){
qDebug()<< QString::fromStdString(m.name());
}
}
}
......@@ -33,17 +33,47 @@
#include "driver.h"
#include "test/testloopprogramm.h"
#include "test/testmodulsystem.h"
#include "test/testmodulecontroller.h"
#include "test/testprogrammblock.h"
#include "codeeditorhelper.h"
#include "programms/programblock.h"
#include "programblockeditor.h"
namespace Modules {
Q_NAMESPACE
Q_ENUM_NS(Property::Type)
}
int main(int argc, char *argv[])
{
/*Test::TestModulSystem testModulSystem;
testModulSystem.runTest();
return 0;*/
//Modules::rgb_t t = {{{{1},{4},{3}}}};
/*{
using namespace std;
using namespace string_literals;
vector<shared_ptr<string>> vec;
vec.push_back(make_shared<string>("Hallo"));
vec.front()->append(" Wourld"s);
cout << vec.front().get() << endl;
vec[0] = make_shared<string>("TEST"s);
cout << vec.front().get() << endl;
shared_ptr<string> second = make_shared<string>("Second"s);
vec[0].swap(second);
cout << vec.front().get() << endl;
}*/
// Test::TestProgrammBlock().test();
// return 0;
class CatchingErrorApplication : public QGuiApplication{
public:
CatchingErrorApplication(int &argc, char **argv):QGuiApplication(argc,argv){}
......@@ -72,6 +102,7 @@ int main(int argc, char *argv[])
// auto defaultFormat = QSurfaceFormat::defaultFormat();
// defaultFormat.setSamples(8);
// QSurfaceFormat::setDefaultFormat(defaultFormat);
......@@ -96,6 +127,9 @@ int main(int argc, char *argv[])
qmlRegisterUncreatableType<UserManagment>("custom.licht",1,0,"Permission","Singletone in c++");
qRegisterMetaType<UserManagment::Permission>("Permission");
qRegisterMetaType<Modules::detail::PropertyInformation::Type>("Type");
//qmlRegisterType<Modules::detail::PropertyInformation::Type>("custom.licht", 1, 0, "PropertyType");
qmlRegisterUncreatableMetaObject(Modules::detail::PropertyInformation::staticMetaObject,"test",1,0,"we","no enum");
//qmlRegisterUncreatableMetaObject(Modules::Property::Type,"test",1,0,"we","no enum");
qRegisterMetaType<Modules::ValueType>("ValueType");
qRegisterMetaType<Modules::PropertiesVector*>("PropertiesVector*");
Settings settings;
......@@ -152,7 +186,18 @@ int main(int argc, char *argv[])
Modules::ModuleManager::singletone()->loadAllModulesInDir(settings.getModuleDirPath());
settings.connect(&settings,&Settings::moduleDirPathChanged,[&](){
Modules::ModuleManager::singletone()->loadAllModulesInDir(settings.getModuleDirPath());
});
});/*
auto mm = Modules::ModuleManager::singletone();
qDebug()<<"Loaded : ";
for(auto m : mm->getConsumerModules()){
qDebug() << "Consumer : "<<QString::fromStdString(m.name());
}
for(auto m : mm->getProgrammModules()){
qDebug() << "Program : "<<QString::fromStdString(m.name());
}
for(auto m : mm->getFilterModules()){
qDebug() << "Filter : "<<QString::fromStdString(m.name());
}*/
engine.rootContext()->setContextProperty("ModelManager",new ModelManager());
......@@ -199,6 +244,7 @@ int main(int argc, char *argv[])
driver.start();*/
#endif
Test::createProgrammBlockAndTestRunIt();
//ControlPanel::getLastCreated()->addDimmerGroupControl();
return app.exec();
}
......@@ -54,6 +54,8 @@ class ModelVector : public QAbstractListModel{
}*/
public:
using const_iterator = typename std::vector<Type>::const_iterator;
enum{
ModelDataRole = Qt::UserRole+1,
};
......@@ -91,6 +93,12 @@ public:
model.erase(i);
endRemoveRows();
}
void erase(const_iterator first, const_iterator last){
const auto pos = std::distance(model.cbegin(),first);
beginRemoveRows(QModelIndex(),pos,pos + std::distance(first,last) -1);
model.erase(first,last);
endRemoveRows();
}
Type erase(int i){
Q_ASSERT(i>=0 && i < size());
beginRemoveRows(QModelIndex(),i,i);
......
#include "programblockeditor.h"
#include <QQmlEngine>
#include <QPropertyAnimation>
#include "programms/property.hpp"
QQmlEngine* ProgramBlockEditor::engine = nullptr;
ProgramBlockEditor::ProgramBlockEditor():programBlockEntry(engine,QUrl("qrc:/ProgramBlockEntry.qml")),
programBlockConnection(engine,QUrl("qrc:/ProgramBlockConnection.qml"))
{
setAcceptedMouseButtons(Qt::AllButtons);
QQuickItem *c1 ;
if(programBlockEntry.isReady()){
QQuickItem* component = qobject_cast<QQuickItem*>(programBlockEntry.create());
......@@ -65,6 +67,7 @@ ProgramBlockEditor::ProgramBlockEditor():programBlockEntry(engine,QUrl("qrc:/Pro
property real targetBaseline
property real sourceBaseline*/
}
Q_DECLARE_METATYPE(Modules::PropertyBase *)
void ProgramBlockEditor::recreateView(){
for(auto i : this->childItems()){
......@@ -77,34 +80,31 @@ void ProgramBlockEditor::recreateView(){
int y = 0;
for(const auto & p : programBlock->getPrograms()){
QQuickItem* component = qobject_cast<QQuickItem*>(programBlockEntry.create());
component->setParentItem(this);
QQmlEngine::setObjectOwnership(component,QQmlEngine::JavaScriptOwnership);
component->setProperty("text",p.get()->getName());
component->setX(0);
component->setY(y);
component->setWidth(p.get()->getOutputLength());
component->setProperty("propertyBase",QVariant::fromValue(static_cast<PropertyBase*>(p.get())));
y += 70;
components[p.get()] = component;
}
for(const auto & p : programBlock->getFilter()){
QQuickItem* component = qobject_cast<QQuickItem*>(programBlockEntry.create());
component->setParentItem(this);
QQmlEngine::setObjectOwnership(component,QQmlEngine::JavaScriptOwnership);
component->setProperty("text",dynamic_cast<Named*>(p.second.source.get())->getName());
component->setX(0);
component->setY(y);
component->setWidth(p.second.source.get()->getInputLength());
component->setProperty("propertyBase",QVariant::fromValue(dynamic_cast<PropertyBase*>(p.second.source.get())));
y += 70;
components[dynamic_cast<Named*>(p.second.source.get())] = component;
}
for(const auto & p : programBlock->getConsumer()){
QQuickItem* component = qobject_cast<QQuickItem*>(programBlockEntry.create());
component->setParentItem(this);
QQmlEngine::setObjectOwnership(component,QQmlEngine::JavaScriptOwnership);
component->setProperty("text",dynamic_cast<Named*>(p.source.get())->getName());
component->setX(0);
component->setY(y);
component->setWidth(p.source.get()->getInputLength());
component->setProperty("propertyBase",QVariant::fromValue(dynamic_cast<PropertyBase*>(p.source.get())));
y += 70;
components[dynamic_cast<Named*>(p.source.get())] = component;
}
......@@ -176,4 +176,85 @@ void ProgramBlockEditor::recreateView(){
}
}
// add components after the shapes, so that the childAt finds the components and not the shapes
for(const auto & p : components){
p.second->setParentItem(this);
QQmlEngine::setObjectOwnership(p.second,QQmlEngine::JavaScriptOwnership);
}
}
template<typename SourceType>
void transferData(Modules::Property & p, ::detail::PropertyInformation &pi){
pi.setValue(p.asNumeric<SourceType>()->getValue());
pi.setMinValue(p.asNumeric<SourceType>()->getMin());
pi.setMaxValue(p.asNumeric<SourceType>()->getMax());
}
template<>
void transferData<long>(Modules::Property & p, ::detail::PropertyInformation &pi){
pi.setValue(static_cast<qlonglong>(p.asNumeric<long>()->getValue()));
pi.setMinValue(static_cast<qlonglong>(p.asNumeric<long>()->getMin()));
pi.setMaxValue(static_cast<qlonglong>(p.asNumeric<long>()->getMax()));
}
void ProgramBlockEditor::mouseReleaseEvent(QMouseEvent *event){
// find the item with the right property if exists
using namespace Modules;
auto comp = childAt(event->x(),event->y());
if(!comp){
return;
}
while (comp != this && !comp->property("propertyBase").isValid()) {
comp = comp->parentItem();
}
if(comp->property("propertyBase").isValid()){
Modules::PropertyBase * pb = comp->property("propertyBase").value<Modules::PropertyBase*>();
if(propertyInformationModel.size()>pb->getProperties().size()){
for(auto i = propertyInformationModel.cbegin()+pb->getProperties().size();i!=propertyInformationModel.cend();++i){
delete *i;
}
propertyInformationModel.erase(propertyInformationModel.cbegin()+pb->getProperties().size(),propertyInformationModel.cend());
}else{
while(propertyInformationModel.size() < pb->getProperties().size()){
propertyInformationModel.push_back(new ::detail::PropertyInformation);
}
}
auto s = pb->getProperties().cbegin();
for(auto t = propertyInformationModel.cbegin();t!=propertyInformationModel.cend();++t,++s){
auto & tp = **t;
auto & sp = **s;
tp.setDescription(QString::fromStdString(sp.getDescription()));
tp.setName(QString::fromStdString(sp.getName()));
tp.setType(sp.type);
switch (sp.type) {
case Property::Double: transferData<double>(sp,tp);
break;
case Property::Float: transferData<float>(sp,tp);
break;
case Property::Int: transferData<int>(sp,tp);
break;
case Property::Long: transferData<long>(sp,tp);
break;
case Property::Bool:
tp.setMinValue(0);
tp.setMaxValue(1);
tp.setValue(sp.asBool()->getValue());
break;
case Property::String:
tp.setValue(QString::fromStdString(sp.asString()->getString()));
}
}
setShowProperties(true);
}else{
setShowProperties(false);
}
}
void ProgramBlockEditor::mouseMoveEvent(QMouseEvent *event){
qDebug() << "moved "<<event->pos();
}void ProgramBlockEditor::mousePressEvent(QMouseEvent *event){
qDebug() << "pressed "<<event->pos();
}
......@@ -3,12 +3,134 @@
#include <QQuickItem>
#include "programms/programblock.h"
#include "programms/modulemanager.h"
namespace detail {
class PropertyInformation : public QObject{
Q_OBJECT
public:
typedef Modules::Property::Type Type;
Q_ENUM(Type)
private:
//auto generated class:
QVariant minValue;
QVariant maxValue;
QVariant value;
QString name;
QString description;
Type type;
bool forwardProperty;
QString forwardPropertyName;
Q_PROPERTY(QVariant minValue READ getMinValue WRITE setMinValue NOTIFY minValueChanged)
Q_PROPERTY(QVariant maxValue READ getMaxValue WRITE setMaxValue NOTIFY maxValueChanged)
Q_PROPERTY(QVariant value READ getValue WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged)
Q_PROPERTY(Type type READ getType WRITE setType NOTIFY typeChanged)
Q_PROPERTY(bool forwardProperty READ getForwardProperty WRITE setForwardProperty NOTIFY forwardPropertyChanged)
Q_PROPERTY(QString forwardPropertyName READ getForwardPropertyName WRITE setForwardPropertyName NOTIFY forwardPropertyNameChanged)
public:
void setMinValue( const QVariant _minValue){
if(_minValue != minValue){
minValue = _minValue;
emit minValueChanged();
}
}
QVariant getMinValue() const {
return minValue;
}
void setMaxValue( const QVariant _maxValue){
if(_maxValue != maxValue){
maxValue = _maxValue;
emit maxValueChanged();
}
}
QVariant getMaxValue() const {
return maxValue;
}
void setValue( const QVariant _value){
if(_value != value){
value = _value;
emit valueChanged();
}
}
QVariant getValue() const {
return value;
}
void setName( const QString _name){
if(_name != name){
name = _name;
emit nameChanged();
}
}
QString getName() const {
return name;
}
void setDescription( const QString _description){
if(_description != description){
description = _description;
emit descriptionChanged();
}
}
QString getDescription() const {
return description;
}
void setType( const Type _type){
if(_type != type){
type = _type;
emit typeChanged();
}
}
Type getType() const {
return type;
}
void setForwardProperty( const bool _forwardProperty){
if(_forwardProperty != forwardProperty){
forwardProperty = _forwardProperty;
emit forwardPropertyChanged();
}
}
bool getForwardProperty() const {
return forwardProperty;
}
void setForwardPropertyName( const QString _forwardPropertyName){
if(_forwardPropertyName != forwardPropertyName){
forwardPropertyName = _forwardPropertyName;
emit forwardPropertyNameChanged();
}
}
QString getForwardPropertyName() const {
return forwardPropertyName;
}
signals:
void minValueChanged();
void maxValueChanged();
void valueChanged();
void nameChanged();
void descriptionChanged();
void typeChanged();
void forwardPropertyChanged();
void forwardPropertyNameChanged();
};
}
class PropertyInformationModel : public ModelVector<detail::PropertyInformation*>{
Q_OBJECT
};
class ProgramBlockEditor : public QQuickItem
{
Q_OBJECT
Modules::ProgramBlock * programBlock;
PropertyInformationModel propertyInformationModel;
bool showProperties;
Q_PROPERTY(Modules::ProgramBlock* programBlock READ getProgramBlock WRITE setProgramBlock NOTIFY programBlockChanged)
Q_PROPERTY(PropertyInformationModel * propertyInformationModel READ getPropertyInformationModel CONSTANT)
Q_PROPERTY(bool showProperties READ getShowProperties WRITE setShowProperties NOTIFY showPropertiesChanged)
QQmlComponent programBlockEntry;
QQmlComponent programBlockConnection;
private:
......@@ -26,8 +148,25 @@ public:
Modules::ProgramBlock* getProgramBlock() const {
return programBlock;
}
PropertyInformationModel *getPropertyInformationModel() {
return &propertyInformationModel;
}
void setShowProperties( const bool _showProperties){
if(_showProperties != showProperties){
showProperties = _showProperties;
emit showPropertiesChanged();
}
}
bool getShowProperties() const {
return showProperties;
}
protected:
virtual void mouseReleaseEvent(QMouseEvent *event)override;
virtual void mouseMoveEvent(QMouseEvent *event)override;
virtual void mousePressEvent(QMouseEvent *event)override;
signals:
void programBlockChanged();
void showPropertiesChanged();
};
#endif // PROGRAMBLOCKEDITOR_H
......@@ -30,6 +30,7 @@ namespace detail {
private:
Type type;
Q_ENUM(Type)
Q_ENUMS(Type)
int max=1000,min=0,defaultValue=1;
public:
Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
......
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