Skip to content
Permalink
Browse files
Add a simple qHash for QVariant
Allows creation of QSet<QVariant>
  • Loading branch information
nyalldawson committed Apr 25, 2017
1 parent 66f4ff9 commit 13b44722cadbd3c49e13dfdce6068d3e37acaf10
Showing with 49 additions and 0 deletions.
  1. +46 −0 src/core/qgis.cpp
  2. +3 −0 src/core/qgis.h
@@ -222,3 +222,49 @@ QString qgsVsiPrefix( const QString &path )
else
return QLatin1String( "" );
}

uint qHash( const QVariant &variant )
{
if ( !variant.isValid() || variant.isNull() )
return -1;

switch ( variant.type() )
{
case QVariant::Int:
return qHash( variant.toInt() );
case QVariant::UInt:
return qHash( variant.toUInt() );
case QVariant::Bool:
return qHash( variant.toBool() );
case QVariant::Double:
return qHash( variant.toDouble() );
case QVariant::LongLong:
return qHash( variant.toLongLong() );
case QVariant::ULongLong:
return qHash( variant.toULongLong() );
case QVariant::String:
return qHash( variant.toString() );
case QVariant::Char:
return qHash( variant.toChar() );
case QVariant::List:
return qHash( variant.toList() );
case QVariant::StringList:
return qHash( variant.toStringList() );
case QVariant::ByteArray:
return qHash( variant.toByteArray() );
case QVariant::Date:
return qHash( variant.toDate() );
case QVariant::Time:
return qHash( variant.toTime() );
case QVariant::DateTime:
return qHash( variant.toDateTime() );
case QVariant::Url:
case QVariant::Locale:
case QVariant::RegExp:
return qHash( variant.toString() );
default:
return -1;
}

return -1;
}
@@ -180,6 +180,9 @@ template<class Object> inline QgsSignalBlocker<Object> whileBlocking( Object *ob
return QgsSignalBlocker<Object>( object );
}

//! Hash for QVariant
uint qHash( const QVariant &variant );

//! Returns a string representation of a double
//! \param a double value
//! \param precision number of decimal places to retain

0 comments on commit 13b4472

Please sign in to comment.