Skip to content

Commit

Permalink
Add missing qHash implementations for QTime, QDate, QDateTime
Browse files Browse the repository at this point in the history
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 e359a8e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/core/qgis.h
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e359a8e

Please sign in to comment.