Skip to content

Commit

Permalink
do only return true if both values are null and none of them is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Aug 15, 2019
1 parent 6bbf5da commit f2073bd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/qgis.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsconfig.h"
#include "qgslogger.h"
#include "qgswkbtypes.h"
#include <QDebug>

#include <gdal.h>
#include <ogr_api.h>
Expand Down Expand Up @@ -297,5 +298,5 @@ uint qHash( const QVariant &variant )

bool qgsVariantEqual( const QVariant &lhs, const QVariant &rhs )
{
return ( lhs.isNull() == rhs.isNull() && lhs == rhs ) || ( lhs.isNull() && rhs.isNull() );
return ( lhs.isNull() == rhs.isNull() && lhs == rhs ) || ( lhs.isNull() && rhs.isNull() && lhs.isValid() && rhs.isValid() );
}
3 changes: 3 additions & 0 deletions tests/src/core/testqgis.cpp
Expand Up @@ -395,6 +395,9 @@ void TestQgis::testQgsVariantEqual()
QVERIFY( qgsVariantEqual( QVariant( QVariant::Double ), QVariant( QVariant::Double ) ) );
QVERIFY( qgsVariantEqual( QVariant( QVariant::Int ), QVariant( QVariant::Double ) ) );
QVERIFY( qgsVariantEqual( QVariant( QVariant::Int ), QVariant( QVariant::String ) ) );

// NULL should not be equal to invalid
QVERIFY( !qgsVariantEqual( QVariant(), QVariant( QVariant::Int ) ) );
}

void TestQgis::testQgsEnumValueToKey()
Expand Down

0 comments on commit f2073bd

Please sign in to comment.