diff --git a/python/core/auto_generated/processing/models/qgsprocessingmodelalgorithm.sip.in b/python/core/auto_generated/processing/models/qgsprocessingmodelalgorithm.sip.in index d1b13ec931b..a0f2edc59d2 100644 --- a/python/core/auto_generated/processing/models/qgsprocessingmodelalgorithm.sip.in +++ b/python/core/auto_generated/processing/models/qgsprocessingmodelalgorithm.sip.in @@ -21,6 +21,9 @@ Model based algorithm with processing. %TypeHeaderCode #include "qgsprocessingmodelalgorithm.h" %End + public: + static const QMetaObject staticMetaObject; + public: QgsProcessingModelAlgorithm( const QString &name = QString(), const QString &group = QString(), const QString &groupId = QString() ); @@ -575,6 +578,7 @@ run through the designer. .. versionadded:: 3.14 %End + protected: virtual QgsProcessingAlgorithm *createInstance() const /Factory/; diff --git a/src/core/processing/models/qgsprocessingmodelalgorithm.cpp b/src/core/processing/models/qgsprocessingmodelalgorithm.cpp index 2511892eba2..1dee5eb6046 100644 --- a/src/core/processing/models/qgsprocessingmodelalgorithm.cpp +++ b/src/core/processing/models/qgsprocessingmodelalgorithm.cpp @@ -1344,6 +1344,7 @@ QVariant QgsProcessingModelAlgorithm::toVariant() const map.insert( QStringLiteral( "model_name" ), mModelName ); map.insert( QStringLiteral( "model_group" ), mModelGroup ); map.insert( QStringLiteral( "help" ), mHelpContent ); + map.insert( QStringLiteral( "internal_version" ), qgsEnumValueToKey( mInternalVersion ) ); QVariantMap childMap; QMap< QString, QgsProcessingModelChildAlgorithm >::const_iterator childIt = mChildAlgorithms.constBegin(); @@ -1393,6 +1394,8 @@ bool QgsProcessingModelAlgorithm::loadVariant( const QVariant &model ) mModelGroupId = map.value( QStringLiteral( "model_group" ) ).toString(); mHelpContent = map.value( QStringLiteral( "help" ) ).toMap(); + mInternalVersion = qgsEnumKeyToValue( map.value( QStringLiteral( "internal_version" ) ).toString(), InternalVersion::Version1 ); + mVariables = map.value( QStringLiteral( "modelVariables" ) ).toMap(); mDesignerParameterValues = map.value( QStringLiteral( "designerParameterValues" ) ).toMap(); diff --git a/src/core/processing/models/qgsprocessingmodelalgorithm.h b/src/core/processing/models/qgsprocessingmodelalgorithm.h index dfc7aca00f7..fc1ea96f8be 100644 --- a/src/core/processing/models/qgsprocessingmodelalgorithm.h +++ b/src/core/processing/models/qgsprocessingmodelalgorithm.h @@ -37,6 +37,8 @@ */ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm { + Q_GADGET + public: /** @@ -523,6 +525,18 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm */ void setDesignerParameterValues( const QVariantMap &values ) { mDesignerParameterValues = values; } +#ifndef SIP_RUN + + //! Internal model versions + enum class InternalVersion + { + Version1, //!< Created in < 3.26 + Version2, //!< Created in >= 3.26 + }; + Q_ENUM( InternalVersion ) + +#endif + protected: QgsProcessingAlgorithm *createInstance() const override SIP_FACTORY; @@ -531,6 +545,8 @@ class CORE_EXPORT QgsProcessingModelAlgorithm : public QgsProcessingAlgorithm private: + InternalVersion mInternalVersion = InternalVersion::Version2; + QString mModelName; QString mModelGroup; QString mModelGroupId; diff --git a/tests/src/analysis/testqgsprocessingmodelalgorithm.cpp b/tests/src/analysis/testqgsprocessingmodelalgorithm.cpp index 6878a1cab18..e4a44961b72 100644 --- a/tests/src/analysis/testqgsprocessingmodelalgorithm.cpp +++ b/tests/src/analysis/testqgsprocessingmodelalgorithm.cpp @@ -105,6 +105,7 @@ class TestQgsProcessingModelAlgorithm: public QObject void modelSource(); void modelNameMatchesFileName(); void renameModelParameter(); + void internalVersion(); private: @@ -2204,5 +2205,21 @@ void TestQgsProcessingModelAlgorithm::renameModelParameter() QCOMPARE( m.childAlgorithm( QStringLiteral( "cx1" ) ).parameterSources()[ QStringLiteral( "EXPRESSION" ) ].constFirst().expression(), QStringLiteral( "@apricot * 2 + @int2" ) ); } +void TestQgsProcessingModelAlgorithm::internalVersion() +{ + // test internal version handling + QgsProcessingModelAlgorithm model; + + // load older model, should be version 1 + QVERIFY( model.fromFile( TEST_DATA_DIR + QStringLiteral( "/test_model.model3" ) ) ); + QCOMPARE( model.mInternalVersion, QgsProcessingModelAlgorithm::InternalVersion::Version1 ); + + // create new model and save/restore, should be version 2 + QgsProcessingModelAlgorithm model2; + QgsProcessingModelAlgorithm model3; + QVERIFY( model3.loadVariant( model2.toVariant() ) ); + QCOMPARE( model3.mInternalVersion, QgsProcessingModelAlgorithm::InternalVersion::Version2 ); +} + QGSTEST_MAIN( TestQgsProcessingModelAlgorithm ) #include "testqgsprocessingmodelalgorithm.moc"