From c1321ba80f6a9f79de698f3f1207bb4743ce5be3 Mon Sep 17 00:00:00 2001 From: Oskar Wallgren Date: Tue, 14 Feb 2017 18:24:03 +0100 Subject: [PATCH] Fix saving of multiple TempoSyncKnobModels (#3281) * Save multiple TempSyncKnobModel syncmodes * Add upgrade path for approximate version 1.2.0-rc2.42 --- include/DataFile.h | 1 + src/core/DataFile.cpp | 44 +++++++++++++++++++++++++++++++++ src/core/TempoSyncKnobModel.cpp | 4 +-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/DataFile.h b/include/DataFile.h index 85c6260ee..6b6b1a98e 100644 --- a/include/DataFile.h +++ b/include/DataFile.h @@ -126,6 +126,7 @@ private: void upgrade_1_1_0(); void upgrade_1_1_91(); void upgrade_1_2_0_rc3(); + void upgrade_1_2_0_rc2_42(); void upgrade(); diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index 18a18724f..448976023 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -929,6 +929,49 @@ void DataFile::upgrade_1_2_0_rc3() } +static void upgradeElement_1_2_0_rc2_42( QDomElement & el ) +{ + if( el.hasAttribute( "syncmode" ) ) + { + int syncmode = el.attribute( "syncmode" ).toInt(); + QStringList names; + QDomNamedNodeMap atts = el.attributes(); + for( uint i = 0; i < atts.length(); i++ ) + { + QString name = atts.item( i ).nodeName(); + if( name.endsWith( "_numerator" ) ) + { + names << name.remove( "_numerator" ) + + "_syncmode"; + } + } + for( QStringList::iterator it = names.begin(); it < names.end(); + ++it ) + { + el.setAttribute( *it, syncmode ); + } + } + + QDomElement child = el.firstChildElement(); + while ( !child.isNull() ) + { + upgradeElement_1_2_0_rc2_42( child ); + child = child.nextSiblingElement(); + } +} + + +void DataFile::upgrade_1_2_0_rc2_42() +{ + QDomElement el = firstChildElement(); + while ( !el.isNull() ) + { + upgradeElement_1_2_0_rc2_42( el ); + el = el.nextSiblingElement(); + } +} + + void DataFile::upgrade() { ProjectVersion version = @@ -1008,6 +1051,7 @@ void DataFile::upgrade() if( version < "1.2.0-rc3" ) { upgrade_1_2_0_rc3(); + upgrade_1_2_0_rc2_42(); } // update document meta data diff --git a/src/core/TempoSyncKnobModel.cpp b/src/core/TempoSyncKnobModel.cpp index 2284ae70d..e94c6e424 100644 --- a/src/core/TempoSyncKnobModel.cpp +++ b/src/core/TempoSyncKnobModel.cpp @@ -127,7 +127,7 @@ void TempoSyncKnobModel::calculateTempoSyncTime( bpm_t _bpm ) void TempoSyncKnobModel::saveSettings( QDomDocument & _doc, QDomElement & _this, const QString & _name ) { - _this.setAttribute( "syncmode", (int) syncMode() ); + _this.setAttribute( _name + "_syncmode", (int) syncMode() ); m_custom.saveSettings( _doc, _this, _name ); FloatModel::saveSettings( _doc, _this, _name ); } @@ -140,7 +140,7 @@ void TempoSyncKnobModel::loadSettings( const QDomElement & _this, { FloatModel::loadSettings( _this, _name ); m_custom.loadSettings( _this, _name ); - setSyncMode( ( TempoSyncMode ) _this.attribute( "syncmode" ).toInt() ); + setSyncMode( ( TempoSyncMode ) _this.attribute( _name + "_syncmode" ).toInt() ); }