Skip to content
Permalink
Browse files

Add missing qHash implementations for QTime, QDate, QDateTime

These were added in Qt5, so for Qt4 builds we now include a variant
of the upstream Qt5 implementations
  • Loading branch information
nyalldawson committed May 10, 2016
1 parent c32acaa commit e359a8ee93fabf9d07a116585e5f0d432c138b6b
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/core/qgis.h
@@ -23,6 +23,10 @@
#include <QRegExp>
#include <QMetaType>
#include <QVariant>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QHash>
#include <stdlib.h>
#include <cfloat>
#include <cmath>
@@ -373,6 +377,32 @@ inline double qgsRound( double x )
return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
}

// Add missing qHash implementation for QDate, QTime, QDateTime
// implementations taken from upstream Qt5 versions
#if QT_VERSION < 0x050000

//! Hash implementation for QDateTime
//! @note not available in Python bindings
inline uint qHash( const QDateTime &key )
{
return qHash( key.toMSecsSinceEpoch() );
}

//! Hash implementation for QDate
//! @note not available in Python bindings
inline uint qHash( const QDate &key )
{
return qHash( key.toJulianDay() );
}

//! Hash implementation for QTime
//! @note not available in Python bindings
inline uint qHash( const QTime &key )
{
return QTime( 0, 0, 0, 0 ).msecsTo( key );
}
#endif

//! 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)

0 comments on commit e359a8e

Please sign in to comment.
You can’t perform that action at this time.