diff --git a/python/core/auto_generated/qgseditorwidgetsetup.sip.in b/python/core/auto_generated/qgseditorwidgetsetup.sip.in index c87b87f28f42..a4e43352724d 100644 --- a/python/core/auto_generated/qgseditorwidgetsetup.sip.in +++ b/python/core/auto_generated/qgseditorwidgetsetup.sip.in @@ -49,6 +49,8 @@ Constructor for QgsEditorWidgetSetup :return: ``True`` if there is no widget configured. %End + bool operator==( const QgsEditorWidgetSetup &other ) const; + }; /************************************************************************ diff --git a/src/core/qgseditorwidgetsetup.h b/src/core/qgseditorwidgetsetup.h index 29c0f0300b72..4c4056ee4dd8 100644 --- a/src/core/qgseditorwidgetsetup.h +++ b/src/core/qgseditorwidgetsetup.h @@ -55,6 +55,12 @@ class CORE_EXPORT QgsEditorWidgetSetup */ bool isNull() const { return mType.isEmpty(); } + // TODO c++20 - replace with = default + bool operator==( const QgsEditorWidgetSetup &other ) const + { + return mType == other.mType && mConfig == other.mConfig; + } + private: QString mType; QVariantMap mConfig; diff --git a/src/core/qgsfield_p.h b/src/core/qgsfield_p.h index 58b57ab315ef..982e6d513533 100644 --- a/src/core/qgsfield_p.h +++ b/src/core/qgsfield_p.h @@ -99,7 +99,8 @@ class QgsFieldPrivate : public QSharedData && ( alias == other.alias ) && ( defaultValueDefinition == other.defaultValueDefinition ) && ( constraints == other.constraints ) && ( flags == other.flags ) && ( splitPolicy == other.splitPolicy ) - && ( isReadOnly == other.isReadOnly ) ); + && ( isReadOnly == other.isReadOnly ) + && ( editorWidgetSetup == other.editorWidgetSetup ) ); } //! Name diff --git a/tests/src/core/testqgsfield.cpp b/tests/src/core/testqgsfield.cpp index 690ad815ecd1..73c54163542e 100644 --- a/tests/src/core/testqgsfield.cpp +++ b/tests/src/core/testqgsfield.cpp @@ -372,6 +372,31 @@ void TestQgsField::equality() QVERIFY( !( constraints1 == constraints2 ) ); constraints2.setDomainName( QStringLiteral( "d" ) ); QVERIFY( constraints1 == constraints2 ); + + QgsEditorWidgetSetup setup1 { QStringLiteral( "TextEdit" ), QVariantMap() }; + QgsEditorWidgetSetup setup2 { QStringLiteral( "TextEdit" ), QVariantMap() }; + + field1.setEditorWidgetSetup( setup1 ); + field2.setEditorWidgetSetup( setup2 ); + QVERIFY( field1 == field2 ); + + setup2 = QgsEditorWidgetSetup{ QStringLiteral( "Text" ), QVariantMap() }; + field2.setEditorWidgetSetup( setup2 ); + QVERIFY( field1 != field2 ); + setup1 = QgsEditorWidgetSetup{ QStringLiteral( "Text" ), QVariantMap() }; + field1.setEditorWidgetSetup( setup1 ); + QVERIFY( field1 == field2 ); + + setup1 = QgsEditorWidgetSetup{ QStringLiteral( "TextEdit" ), QVariantMap{ { QStringLiteral( "a" ), QStringLiteral( "b" ) } } }; + setup2 = QgsEditorWidgetSetup{ QStringLiteral( "TextEdit" ), QVariantMap{ { QStringLiteral( "a" ), QStringLiteral( "b" ) } } }; + field1.setEditorWidgetSetup( setup1 ); + field2.setEditorWidgetSetup( setup2 ); + QVERIFY( field1 == field2 ); + + setup2 = QgsEditorWidgetSetup{ QStringLiteral( "TextEdit" ), QVariantMap{ { QStringLiteral( "a" ), QStringLiteral( "XXXXXX" ) } } }; + field2.setEditorWidgetSetup( setup2 ); + QVERIFY( field1 != field2 ); + } void TestQgsField::asVariant()