From e87ba45edcfa0d1fd231e3944681ffa6ecd6208f Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Thu, 10 Sep 2020 14:26:42 +0200 Subject: [PATCH] make QgsRelation::RelationStrength a Q_ENUM and simplify code --- python/core/auto_additions/qgsrelation.py | 2 ++ python/core/auto_generated/qgsrelation.sip.in | 1 - src/core/qgsrelation.cpp | 9 +-------- src/core/qgsrelation.h | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 python/core/auto_additions/qgsrelation.py diff --git a/python/core/auto_additions/qgsrelation.py b/python/core/auto_additions/qgsrelation.py new file mode 100644 index 00000000000..5c9365b843d --- /dev/null +++ b/python/core/auto_additions/qgsrelation.py @@ -0,0 +1,2 @@ +# The following has been generated automatically from src/core/qgsrelation.h +QgsRelation.RelationStrength.baseClass = QgsRelation diff --git a/python/core/auto_generated/qgsrelation.sip.in b/python/core/auto_generated/qgsrelation.sip.in index 231ce7fd3c6..a7c528d5efb 100644 --- a/python/core/auto_generated/qgsrelation.sip.in +++ b/python/core/auto_generated/qgsrelation.sip.in @@ -26,7 +26,6 @@ class QgsRelation { Association, Composition - }; diff --git a/src/core/qgsrelation.cpp b/src/core/qgsrelation.cpp index e35ab483f2c..9025bd9c129 100644 --- a/src/core/qgsrelation.cpp +++ b/src/core/qgsrelation.cpp @@ -126,14 +126,7 @@ void QgsRelation::writeXml( QDomNode &node, QDomDocument &doc ) const elem.setAttribute( QStringLiteral( "name" ), d->mRelationName ); elem.setAttribute( QStringLiteral( "referencingLayer" ), d->mReferencingLayerId ); elem.setAttribute( QStringLiteral( "referencedLayer" ), d->mReferencedLayerId ); - if ( d->mRelationStrength == RelationStrength::Composition ) - { - elem.setAttribute( QStringLiteral( "strength" ), QStringLiteral( "Composition" ) ); - } - else - { - elem.setAttribute( QStringLiteral( "strength" ), QStringLiteral( "Association" ) ); - } + elem.setAttribute( QStringLiteral( "strength" ), qgsEnumValueToKey( d->mRelationStrength ) ); for ( const FieldPair &pair : qgis::as_const( d->mFieldPairs ) ) { diff --git a/src/core/qgsrelation.h b/src/core/qgsrelation.h index b9e4ac77e06..4ed8848aed2 100644 --- a/src/core/qgsrelation.h +++ b/src/core/qgsrelation.h @@ -58,8 +58,8 @@ class CORE_EXPORT QgsRelation { Association, //!< Loose relation, related elements are not part of the parent and a parent copy will not copy any children. Composition //!< Fix relation, related elements are part of the parent and a parent copy will copy any children or delete of parent will delete children - }; + Q_ENUM( RelationStrength ) #ifndef SIP_RUN