From a0737a4efc301d80d32d1a2d46b32327c2bc2a0e Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 22 Sep 2018 11:14:07 +0200 Subject: [PATCH] Add `AutomatableModel` nodename attribute (#4578) * Save `AutomatableModel` nodename in attribute if it must be quoted * Loading an `AutomatableModel` with name now means it - either must be `QDomElement::nodeName()` (as before) *and* must not have a `nodename` attribute (new) - or must have a `nodename` attribute with value --- src/core/AutomatableModel.cpp | 58 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index da5a2d15b..cb8aa7046 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -96,10 +96,16 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co // automation needs tuple of data (name, id, value) // scale type also needs an extra value // => it must be appended as a node - QDomElement me = doc.createElement( name ); + + QRegExp reg("^[A-Za-z0-9._-]+$"); + bool mustQuote = !reg.exactMatch(name); + QDomElement me = doc.createElement( mustQuote ? QString("automatablemodel") : name ); me.setAttribute( "id", ProjectJournal::idToSave( id() ) ); me.setAttribute( "value", m_value ); me.setAttribute( "scale_type", m_scaleType == Logarithmic ? "log" : "linear" ); + if(mustQuote) { + me.setAttribute( "nodename", name ); + } element.appendChild( me ); } else @@ -177,22 +183,48 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString& // // // element => there is automation data, or scaletype information - node = element.namedItem( name ); + + node = element.namedItem( name ); // maybe we have luck? + + // either: no node with name "name" found + // => look for nodes with attribute name="nodename" + // or: element with namedItem() "name" was found, but it's real nodename + // is given as attribute and does not match + // => look for the right node + if(node.isNull() || + ( node.isElement() && + node.toElement().hasAttribute("nodename") && + node.toElement().attribute("nodename") != name)) + { + for(QDomElement othernode = element.firstChildElement(); + !othernode.isNull(); + othernode = othernode.nextSiblingElement()) + { + if((!othernode.hasAttribute("nodename") && + othernode.nodeName() == name) || + othernode.attribute("nodename") == name) + { + node = othernode; + break; + } + } + } if( node.isElement() ) { - changeID( node.toElement().attribute( "id" ).toInt() ); - setValue( LocaleHelper::toFloat( node.toElement().attribute( "value" ) ) ); - if( node.toElement().hasAttribute( "scale_type" ) ) + QDomElement nodeElement = node.toElement(); + changeID( nodeElement.attribute( "id" ).toInt() ); + setValue( LocaleHelper::toFloat( nodeElement.attribute( "value" ) ) ); + if( nodeElement.hasAttribute( "scale_type" ) ) + { + if( nodeElement.attribute( "scale_type" ) == "linear" ) { - if( node.toElement().attribute( "scale_type" ) == "linear" ) - { - setScaleType( Linear ); - } - else if( node.toElement().attribute( "scale_type" ) == "log" ) - { - setScaleType( Logarithmic ); - } + setScaleType( Linear ); } + else if( nodeElement.attribute( "scale_type" ) == "log" ) + { + setScaleType( Logarithmic ); + } + } } else {