From 7a5c1367dd2f1b5897bdae6358f641883d71987b Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Thu, 8 Feb 2024 15:13:49 +0100 Subject: [PATCH 1/2] QgsField fix equality with editorWidgetSetup Fix #55873 --- .../qgseditorwidgetsetup.sip.in | 2 ++ ...qgscoordinateboundspreviewmapwidget.sip.in | 2 ++ src/core/qgseditorwidgetsetup.h | 6 +++++ src/core/qgsfield_p.h | 3 ++- tests/src/core/testqgsfield.cpp | 25 +++++++++++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) 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/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in b/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in index 2764e8c6bee9..96818318e583 100644 --- a/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in +++ b/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in @@ -51,6 +51,8 @@ Sets the "preview" rectangle for the bounds overview map. Must be in EPSG:4326 coordinate reference system. %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() From 0b57a5192fc0aa2e776b5c707cdbc2a49c082ebf Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Fri, 9 Feb 2024 10:26:49 +0100 Subject: [PATCH 2/2] Remove rogue SIP file change --- .../auto_generated/qgscoordinateboundspreviewmapwidget.sip.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in b/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in index 96818318e583..2764e8c6bee9 100644 --- a/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in +++ b/python/gui/auto_generated/qgscoordinateboundspreviewmapwidget.sip.in @@ -51,8 +51,6 @@ Sets the "preview" rectangle for the bounds overview map. Must be in EPSG:4326 coordinate reference system. %End - bool operator==( const QgsEditorWidgetSetup &other ) const; - }; /************************************************************************