From ee05523319dbc137c1e39cae484590fd832ecc69 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Tue, 1 Jan 2019 20:58:16 +0100 Subject: [PATCH] Extend quoting for AutomatableModels This now also quotes, if required: - non automated models - models controlled by controller --- include/AutomatableModel.h | 2 ++ src/core/AutomatableModel.cpp | 44 +++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index 8dbe80efd..78f4882b4 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -283,6 +283,8 @@ protected: private: + static bool mustQuoteName(const QString &name); + virtual void saveSettings( QDomDocument& doc, QDomElement& element ) { saveSettings( doc, element, "value" ); diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index cb8aa7046..62b783da4 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -89,16 +89,23 @@ bool AutomatableModel::isAutomated() const } + +bool AutomatableModel::mustQuoteName(const QString& name) +{ + QRegExp reg("^[A-Za-z0-9._-]+$"); + return !reg.exactMatch(name); +} + void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, const QString& name ) { + bool mustQuote = mustQuoteName(name); + if( isAutomated() || m_scaleType != Linear ) { // automation needs tuple of data (name, id, value) // scale type also needs an extra value // => it must be appended as a node - 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 ); @@ -110,8 +117,18 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co } else { - // non automation, linear scale (default), can be saved as attribute - element.setAttribute( name, m_value ); + if(mustQuote) + { + QDomElement me = doc.createElement( "automatablemodel" ); + me.setAttribute( "nodename", name ); + me.setAttribute( "value", m_value ); + element.appendChild( me ); + } + else + { + // non automation, linear scale (default), can be saved as attribute + element.setAttribute( name, m_value ); + } } if( m_controllerConnection && m_controllerConnection->getController()->type() @@ -131,7 +148,13 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co element.appendChild( controllerElement ); } - QDomElement element = doc.createElement( name ); + bool mustQuote = mustQuoteName(name); + QString elementName = mustQuote ? "controllerconnection" + : name; + + QDomElement element = doc.createElement( elementName ); + if(mustQuote) + element.setAttribute( "nodename", name ); m_controllerConnection->saveSettings( doc, element ); controllerElement.appendChild( element ); @@ -170,6 +193,17 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString& if( connectionNode.isElement() ) { QDomNode thisConnection = connectionNode.toElement().namedItem( name ); + if( !thisConnection.isElement() ) + { + thisConnection = connectionNode.toElement().namedItem( "controllerconnection" ); + QDomElement tcElement = thisConnection.toElement(); + // sanity check + if( tcElement.isNull() || tcElement.attribute( "nodename" ) != name ) + { + // no, that wasn't it, act as if we never found one + thisConnection.clear(); + } + } if( thisConnection.isElement() ) { setControllerConnection( new ControllerConnection( (Controller*)NULL ) );