Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_34] QgsField fix equality with editorWidgetSetup #56272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgseditorwidgetsetup.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Constructor for QgsEditorWidgetSetup
:return: ``True`` if there is no widget configured.
%End

bool operator==( const QgsEditorWidgetSetup &other ) const;

};

/************************************************************************
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgseditorwidgetsetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsfield_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions tests/src/core/testqgsfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading