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

Modules can habe different input and output types

parent 186c0438
...@@ -103,11 +103,43 @@ Item{ ...@@ -103,11 +103,43 @@ Item{
Label{ Label{
text: "Type:" text: "Type:"
} }
ComboBox{ RowLayout{
model: moduleTypeModel ComboBox{
Layout.preferredWidth: 200 model: moduleTypeModel
currentIndex: listView.currentItem.itemData.type Layout.preferredWidth: implicitWidth+5
onCurrentIndexChanged: listView.currentItem.itemData.type = currentIndex currentIndex: listView.currentItem.itemData.type
onCurrentIndexChanged: {
listView.currentItem.itemData.type = currentIndex;
if(currentIndex == 0/*Program*/ || currentIndex == 1/*LoopProgram*/){
outputType.visible = true;
inputType.visible = false;
}else if(currentIndex == 2/*Filter*/){
outputType.visible = true;
inputType.visible = true;
}
}
}
Label{
text: "Input:"
visible:inputType.visible
}
ComboBox{
id: inputType
model: valueTypeList
currentIndex: listView.currentItem.itemData.inputType
Layout.preferredWidth: implicitWidth+5
onCurrentIndexChanged: listView.currentItem.itemData.inputType = currentIndex;
}
Label{text: "Output:"
visible: outputType.visible
}
ComboBox{
id:outputType
model: valueTypeList
currentIndex: listView.currentItem.itemData.outputType
Layout.preferredWidth: implicitWidth+5
onCurrentIndexChanged: listView.currentItem.itemData.outputType = currentIndex;
}
} }
Label{ Label{
...@@ -119,10 +151,10 @@ Item{ ...@@ -119,10 +151,10 @@ Item{
anchors.bottomMargin: -20 anchors.bottomMargin: -20
clip: true clip: true
Layout.preferredHeight: Math.max(50,Math.min(model.rowCount() * 20,120)) Layout.preferredHeight: Math.max(50,Math.min(model.rowCount() * 20,120))
onModelChanged:{ for (var prop in model) { /*onModelChanged:{ for (var prop in model) {
print(prop += " (" + typeof(model[prop]) + ") = " + model[prop]); print(prop += " (" + typeof(model[prop]) + ") = " + model[prop]);
} }
} }*/
model: listView.currentItem.itemData.properties model: listView.currentItem.itemData.properties
delegate: ItemDelegate{ delegate: ItemDelegate{
id:delegate id:delegate
......
...@@ -325,7 +325,8 @@ void CodeEditorHelper::compile(){ ...@@ -325,7 +325,8 @@ void CodeEditorHelper::compile(){
if ( file.open(QIODevice::ReadWrite) ) if ( file.open(QIODevice::ReadWrite) )
{ {
QString typeName = toName(module->getType()); QString typeName = toName(module->getType());
QString valueName = toName(module->getValueType()); QString inputType = toName(module->getInputType());
QString outputType = toName(module->getOutputType());
QTextStream stream( &file ); QTextStream stream( &file );
stream << "#define MODULE_LIBRARY" << endl; stream << "#define MODULE_LIBRARY" << endl;
switch (module->getType()) { switch (module->getType()) {
...@@ -349,9 +350,9 @@ void CodeEditorHelper::compile(){ ...@@ -349,9 +350,9 @@ void CodeEditorHelper::compile(){
stream << "using namespace std;" << endl; stream << "using namespace std;" << endl;
stream << "" << endl; stream << "" << endl;
if(module->getType() == Modules::Module::Filter){ if(module->getType() == Modules::Module::Filter){
stream << "class Impl : public Typed" << typeName << "<"<<valueName<<","<<valueName<<">{"<< endl; stream << "class Impl : public Typed" << typeName << "<"<<inputType<<","<<outputType<<">{"<< endl;
}else{ }else{
stream << "class Impl : public Typed" << typeName << "<"<<valueName<<">{"<< endl; stream << "class Impl : public Typed" << typeName << "<"<<outputType<<">{"<< endl;
} }
for(const auto &p : module->getProperties()){ for(const auto &p : module->getProperties()){
writeDeclaration(stream,p); writeDeclaration(stream,p);
......
...@@ -92,6 +92,7 @@ int main(int argc, char *argv[]) ...@@ -92,6 +92,7 @@ int main(int argc, char *argv[])
qmlRegisterUncreatableType<UserManagment>("custom.licht",1,0,"Permission","Singletone in c++"); qmlRegisterUncreatableType<UserManagment>("custom.licht",1,0,"Permission","Singletone in c++");
qRegisterMetaType<UserManagment::Permission>("Permission"); qRegisterMetaType<UserManagment::Permission>("Permission");
qRegisterMetaType<Modules::detail::PropertyInformation::Type>("Type"); qRegisterMetaType<Modules::detail::PropertyInformation::Type>("Type");
qRegisterMetaType<Modules::ValueType>("ValueType");
qRegisterMetaType<Modules::PropertiesVector*>("PropertiesVector*"); qRegisterMetaType<Modules::PropertiesVector*>("PropertiesVector*");
Settings settings; Settings settings;
settings.setJsonSettingsFilePath("QTJSONFile.json"); settings.setJsonSettingsFilePath("QTJSONFile.json");
...@@ -114,10 +115,12 @@ int main(int argc, char *argv[]) ...@@ -114,10 +115,12 @@ int main(int argc, char *argv[])
} }
QStringList moduleTypeList; QStringList moduleTypeList;
const QMetaObject &_mom = Modules::Module::staticMetaObject; const QMetaObject &_mom = Modules::Module::staticMetaObject;
QMetaEnum _metaEnum =_mom.enumerator(mo.indexOfEnumerator("Type")); QMetaEnum _metaEnum =_mom.enumerator(_mom.indexOfEnumerator("Type"));
for (int i = 0; i < _metaEnum.keyCount(); ++i) { for (int i = 0; i < _metaEnum.keyCount(); ++i) {
moduleTypeList.append(_metaEnum.key(i)); moduleTypeList.append(_metaEnum.key(i));
} }
QStringList valueTypeList;
valueTypeList << "Brightness" << "RGB" ;
QStringList modolePropertyTypeList; QStringList modolePropertyTypeList;
modolePropertyTypeList << "Int" << "Long" << "Float" << "Double" << "Bool" << "String"; modolePropertyTypeList << "Int" << "Long" << "Float" << "Double" << "Bool" << "String";
...@@ -155,6 +158,7 @@ int main(int argc, char *argv[]) ...@@ -155,6 +158,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("devicePrototypeModel",IDBaseDataModel<DevicePrototype>::singletone()); engine.rootContext()->setContextProperty("devicePrototypeModel",IDBaseDataModel<DevicePrototype>::singletone());
engine.rootContext()->setContextProperty("modulesModel",Modules::ModuleManager::singletone()->getModules()); engine.rootContext()->setContextProperty("modulesModel",Modules::ModuleManager::singletone()->getModules());
engine.rootContext()->setContextProperty("moduleTypeModel",moduleTypeList); engine.rootContext()->setContextProperty("moduleTypeModel",moduleTypeList);
engine.rootContext()->setContextProperty("valueTypeList",valueTypeList);
engine.rootContext()->setContextProperty("modolePropertyTypeList",modolePropertyTypeList); engine.rootContext()->setContextProperty("modolePropertyTypeList",modolePropertyTypeList);
engine.rootContext()->setContextProperty("deviceModel",IDBaseDataModel<Device>::singletone()); engine.rootContext()->setContextProperty("deviceModel",IDBaseDataModel<Device>::singletone());
engine.rootContext()->setContextProperty("programmModel",IDBaseDataModel<Programm>::singletone()); engine.rootContext()->setContextProperty("programmModel",IDBaseDataModel<Programm>::singletone());
......
...@@ -29,7 +29,8 @@ namespace detail { ...@@ -29,7 +29,8 @@ namespace detail {
Module::Module(const QJsonObject &o):name(o["name"].toString("no name")), Module::Module(const QJsonObject &o):name(o["name"].toString("no name")),
description(o["description"].toString()),code(o["code"].toString()), description(o["description"].toString()),code(o["code"].toString()),
valueType(static_cast<ValueType>(o["valueType"].toInt())), inputType(static_cast<ValueType>(o["inputType"].toInt())),
outputType(static_cast<ValueType>(o["outputType"].toInt())),
type(static_cast<Type>(o["type"].toInt())){ type(static_cast<Type>(o["type"].toInt())){
QJsonArray a = o["properties"].toArray(); QJsonArray a = o["properties"].toArray();
for(const auto i : a){ for(const auto i : a){
...@@ -42,7 +43,8 @@ void Module::writeJsonObject(QJsonObject &o)const{ ...@@ -42,7 +43,8 @@ void Module::writeJsonObject(QJsonObject &o)const{
o["name"] = name; o["name"] = name;
o["description"] = description; o["description"] = description;
o["code"] = code; o["code"] = code;
o["valueType"] = valueType; o["inputType"] = inputType;
o["outputType"] = outputType;
o["type"] = type; o["type"] = type;
QJsonArray a; QJsonArray a;
for(const auto & p : properties){ for(const auto & p : properties){
......
...@@ -88,14 +88,16 @@ class Module : public QObject{ ...@@ -88,14 +88,16 @@ class Module : public QObject{
Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged) Q_PROPERTY(QString description READ getDescription WRITE setDescription NOTIFY descriptionChanged)
Q_PROPERTY(Type type READ getType WRITE setType NOTIFY typeChanged) Q_PROPERTY(Type type READ getType WRITE setType NOTIFY typeChanged)
Q_PROPERTY(ValueType valueType READ getValueType WRITE setValueType NOTIFY valueTypeChanged) Q_PROPERTY(ValueType inputType READ getInputType WRITE setInputType NOTIFY inputTypeChanged)
Q_PROPERTY(ValueType outputType READ getOutputType WRITE setOutputType NOTIFY outputTypeChanged)
Q_PROPERTY(QString code READ getCode WRITE setCode NOTIFY codeChanged) Q_PROPERTY(QString code READ getCode WRITE setCode NOTIFY codeChanged)
Q_PROPERTY(PropertiesVector * properties READ getPropertiesP CONSTANT) Q_PROPERTY(PropertiesVector * properties READ getPropertiesP CONSTANT)
QString name = "No Name"; QString name = "No Name";
QString description; QString description;
PropertiesVector properties; PropertiesVector properties;
QString code; QString code;
ValueType valueType; ValueType inputType;
ValueType outputType;
Q_ENUM(ValueType) Q_ENUM(ValueType)
//Module(Module&)=delete; //Module(Module&)=delete;
...@@ -164,14 +166,23 @@ public: ...@@ -164,14 +166,23 @@ public:
Type getType() const { Type getType() const {
return type; return type;
} }
void setValueType( const ValueType _valueType){ void setInputType( const ValueType _inputType){
if(_valueType != valueType){ if(_inputType != inputType){
valueType = _valueType; inputType = _inputType;
emit valueTypeChanged(); emit inputTypeChanged();
} }
} }
ValueType getValueType() const { ValueType getInputType() const {
return valueType; return inputType;
}
void setOutputType( const ValueType _outputType){
if(_outputType != outputType){
outputType = _outputType;
emit outputTypeChanged();
}
}
ValueType getOutputType() const {
return outputType;
} }
void setCode( const QString _code){ void setCode( const QString _code){
if(_code != code){ if(_code != code){
...@@ -187,7 +198,8 @@ signals: ...@@ -187,7 +198,8 @@ signals:
void nameChanged(); void nameChanged();
void descriptionChanged(); void descriptionChanged();
void typeChanged(); void typeChanged();
void valueTypeChanged(); void inputTypeChanged();
void outputTypeChanged();
void codeChanged(); void codeChanged();
}; };
......
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