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{
Label{
text: "Type:"
}
RowLayout{
ComboBox{
model: moduleTypeModel
Layout.preferredWidth: 200
Layout.preferredWidth: implicitWidth+5
currentIndex: listView.currentItem.itemData.type
onCurrentIndexChanged: listView.currentItem.itemData.type = currentIndex
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{
......@@ -119,10 +151,10 @@ Item{
anchors.bottomMargin: -20
clip: true
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]);
}
}
}*/
model: listView.currentItem.itemData.properties
delegate: ItemDelegate{
id:delegate
......
......@@ -325,7 +325,8 @@ void CodeEditorHelper::compile(){
if ( file.open(QIODevice::ReadWrite) )
{
QString typeName = toName(module->getType());
QString valueName = toName(module->getValueType());
QString inputType = toName(module->getInputType());
QString outputType = toName(module->getOutputType());
QTextStream stream( &file );
stream << "#define MODULE_LIBRARY" << endl;
switch (module->getType()) {
......@@ -349,9 +350,9 @@ void CodeEditorHelper::compile(){
stream << "using namespace std;" << endl;
stream << "" << endl;
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{
stream << "class Impl : public Typed" << typeName << "<"<<valueName<<">{"<< endl;
stream << "class Impl : public Typed" << typeName << "<"<<outputType<<">{"<< endl;
}
for(const auto &p : module->getProperties()){
writeDeclaration(stream,p);
......
......@@ -92,6 +92,7 @@ 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");
qRegisterMetaType<Modules::ValueType>("ValueType");
qRegisterMetaType<Modules::PropertiesVector*>("PropertiesVector*");
Settings settings;
settings.setJsonSettingsFilePath("QTJSONFile.json");
......@@ -114,10 +115,12 @@ int main(int argc, char *argv[])
}
QStringList moduleTypeList;
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) {
moduleTypeList.append(_metaEnum.key(i));
}
QStringList valueTypeList;
valueTypeList << "Brightness" << "RGB" ;
QStringList modolePropertyTypeList;
modolePropertyTypeList << "Int" << "Long" << "Float" << "Double" << "Bool" << "String";
......@@ -155,6 +158,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("devicePrototypeModel",IDBaseDataModel<DevicePrototype>::singletone());
engine.rootContext()->setContextProperty("modulesModel",Modules::ModuleManager::singletone()->getModules());
engine.rootContext()->setContextProperty("moduleTypeModel",moduleTypeList);
engine.rootContext()->setContextProperty("valueTypeList",valueTypeList);
engine.rootContext()->setContextProperty("modolePropertyTypeList",modolePropertyTypeList);
engine.rootContext()->setContextProperty("deviceModel",IDBaseDataModel<Device>::singletone());
engine.rootContext()->setContextProperty("programmModel",IDBaseDataModel<Programm>::singletone());
......
......@@ -29,7 +29,8 @@ namespace detail {
Module::Module(const QJsonObject &o):name(o["name"].toString("no name")),
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())){
QJsonArray a = o["properties"].toArray();
for(const auto i : a){
......@@ -42,7 +43,8 @@ void Module::writeJsonObject(QJsonObject &o)const{
o["name"] = name;
o["description"] = description;
o["code"] = code;
o["valueType"] = valueType;
o["inputType"] = inputType;
o["outputType"] = outputType;
o["type"] = type;
QJsonArray a;
for(const auto & p : properties){
......
......@@ -88,14 +88,16 @@ class Module : public QObject{
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(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(PropertiesVector * properties READ getPropertiesP CONSTANT)
QString name = "No Name";
QString description;
PropertiesVector properties;
QString code;
ValueType valueType;
ValueType inputType;
ValueType outputType;
Q_ENUM(ValueType)
//Module(Module&)=delete;
......@@ -164,14 +166,23 @@ public:
Type getType() const {
return type;
}
void setValueType( const ValueType _valueType){
if(_valueType != valueType){
valueType = _valueType;
emit valueTypeChanged();
void setInputType( const ValueType _inputType){
if(_inputType != inputType){
inputType = _inputType;
emit inputTypeChanged();
}
}
ValueType getValueType() const {
return valueType;
ValueType getInputType() const {
return inputType;
}
void setOutputType( const ValueType _outputType){
if(_outputType != outputType){
outputType = _outputType;
emit outputTypeChanged();
}
}
ValueType getOutputType() const {
return outputType;
}
void setCode( const QString _code){
if(_code != code){
......@@ -187,7 +198,8 @@ signals:
void nameChanged();
void descriptionChanged();
void typeChanged();
void valueTypeChanged();
void inputTypeChanged();
void outputTypeChanged();
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