Skip to content

Commit

Permalink
[qt6] Add comparison operators for QVariant
Browse files Browse the repository at this point in the history
makes them usable as QMap keys
  • Loading branch information
m-kuhn committed Mar 25, 2021
1 parent 9b07d95 commit 42b7939
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 4 additions & 1 deletion python/core/auto_generated/qgis.sip.in
Expand Up @@ -250,7 +250,6 @@ always treated as equal and 0 is not treated as equal with NULL
:return: ``True`` if values are equal
%End


bool qgsVariantGreaterThan( const QVariant &lhs, const QVariant &rhs );
%Docstring
Compares two QVariant values and returns whether the first is greater than the second.
Expand All @@ -260,6 +259,10 @@ QVariant data types (such as strings, numeric values, dates and times)
.. seealso:: :py:func:`qgsVariantLessThan`
%End

bool operator> ( const QVariant &v1, const QVariant &v2 );

bool operator< ( const QVariant &v1, const QVariant &v2 );




Expand Down
26 changes: 25 additions & 1 deletion src/core/qgis.h
Expand Up @@ -544,7 +544,6 @@ CORE_EXPORT bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs );
*/
CORE_EXPORT bool qgsVariantEqual( const QVariant &lhs, const QVariant &rhs );


/**
* Compares two QVariant values and returns whether the first is greater than the second.
* Useful for sorting lists of variants, correctly handling sorting of the various
Expand All @@ -553,6 +552,31 @@ CORE_EXPORT bool qgsVariantEqual( const QVariant &lhs, const QVariant &rhs );
*/
CORE_EXPORT bool qgsVariantGreaterThan( const QVariant &lhs, const QVariant &rhs );

/**
* Compares two QVariant values and returns whether the first is greater than the second.
* Useful for sorting lists of variants, correctly handling sorting of the various
* QVariant data types (such as strings, numeric values, dates and times)
* \see qgsVariantLessThan()
*/
inline bool operator> ( const QVariant &v1, const QVariant &v2 )
{
return qgsVariantGreaterThan( v1, v2 );
}

/**
* Compares two QVariant values and returns whether the first is less than the second.
* Useful for sorting lists of variants, correctly handling sorting of the various
* QVariant data types (such as strings, numeric values, dates and times)
*
* Invalid < NULL < Values
*
* \see qgsVariantGreaterThan()
*/
inline bool operator< ( const QVariant &v1, const QVariant &v2 )
{
return qgsVariantLessThan( v1, v2 );
}


#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

Expand Down

0 comments on commit 42b7939

Please sign in to comment.