Skip to content

Commit

Permalink
Add missing QgsInterval != operator
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 6, 2021
1 parent c25a9e8 commit 3d23cb6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsinterval.sip.in
Expand Up @@ -288,6 +288,8 @@ QgsInterval instance or interval was set with a mix of units.

bool operator==( QgsInterval other ) const;

bool operator!=( QgsInterval other ) const;

static QgsInterval fromString( const QString &string );
%Docstring
Converts a string to an interval
Expand Down
13 changes: 0 additions & 13 deletions src/core/qgsinterval.cpp
Expand Up @@ -14,7 +14,6 @@
***************************************************************************/

#include "qgsinterval.h"
#include "qgis.h"
#include <QString>
#include <QStringList>
#include <QMap>
Expand Down Expand Up @@ -207,18 +206,6 @@ void QgsInterval::setSeconds( double seconds )
mOriginalUnit = QgsUnitTypes::TemporalSeconds;
}

bool QgsInterval::operator==( QgsInterval other ) const
{
if ( !mValid && !other.mValid )
return true;
else if ( mValid && other.mValid && ( mOriginalUnit != QgsUnitTypes::TemporalUnknownUnit || other.mOriginalUnit != QgsUnitTypes::TemporalUnknownUnit ) )
return mOriginalUnit == other.mOriginalUnit && mOriginalDuration == other.mOriginalDuration;
else if ( mValid && other.mValid )
return qgsDoubleNear( mSeconds, other.mSeconds );
else
return false;
}

QgsInterval QgsInterval::fromString( const QString &string )
{
double seconds = 0;
Expand Down
18 changes: 17 additions & 1 deletion src/core/qgsinterval.h
Expand Up @@ -27,6 +27,7 @@
#include "qgis_sip.h"
#include "qgis_core.h"
#include "qgsunittypes.h"
#include "qgis.h"

class QString;

Expand Down Expand Up @@ -293,7 +294,22 @@ class CORE_EXPORT QgsInterval
*/
QgsUnitTypes::TemporalUnit originalUnit() const { return mOriginalUnit; }

bool operator==( QgsInterval other ) const;
bool operator==( QgsInterval other ) const
{
if ( !mValid && !other.mValid )
return true;
else if ( mValid && other.mValid && ( mOriginalUnit != QgsUnitTypes::TemporalUnknownUnit || other.mOriginalUnit != QgsUnitTypes::TemporalUnknownUnit ) )
return mOriginalUnit == other.mOriginalUnit && mOriginalDuration == other.mOriginalDuration;
else if ( mValid && other.mValid )
return qgsDoubleNear( mSeconds, other.mSeconds );
else
return false;
}

bool operator!=( QgsInterval other ) const
{
return !( *this == other );
}

/**
* Converts a string to an interval
Expand Down

0 comments on commit 3d23cb6

Please sign in to comment.