Skip to content

Commit

Permalink
fix qt640 build - QgsInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and nyalldawson committed Nov 11, 2022
1 parent 5c6c63d commit 794f1e1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpressioncontextutils.cpp
Expand Up @@ -498,7 +498,7 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg

scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_start_time" ), mapSettings.isTemporal() ? mapSettings.temporalRange().begin() : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_end_time" ), mapSettings.isTemporal() ? mapSettings.temporalRange().end() : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_interval" ), mapSettings.isTemporal() ? ( mapSettings.temporalRange().end() - mapSettings.temporalRange().begin() ) : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_interval" ), mapSettings.isTemporal() ? QgsInterval( mapSettings.temporalRange().end() - mapSettings.temporalRange().begin() ) : QVariant(), true ) );

// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpressionnodeimpl.cpp
Expand Up @@ -295,7 +295,7 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
ENSURE_NO_EVAL_ERROR
QDateTime datetime2 = QgsExpressionUtils::getDateTimeValue( vR, parent );
ENSURE_NO_EVAL_ERROR
return datetime1 - datetime2;
return QgsInterval( datetime1 - datetime2 );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -1724,7 +1724,7 @@ QgsExpressionContext QgsLayoutItemMap::createExpressionContext() const

scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_start_time" ), isTemporal() ? temporalRange().begin() : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_end_time" ), isTemporal() ? temporalRange().end() : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_interval" ), isTemporal() ? ( temporalRange().end() - temporalRange().begin() ) : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_interval" ), isTemporal() ? QgsInterval( temporalRange().end() - temporalRange().begin() ) : QVariant(), true ) );

#if 0 // not relevant here! (but left so as to respect all the dangerous warnings in QgsExpressionContextUtils::mapSettingsScope)
if ( mapSettings.frameRate() >= 0 )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsconditionalstyle.h
Expand Up @@ -16,6 +16,7 @@
#define QGSCONDITIONALSTYLE_H

#include "qgis_core.h"
#include <QObject>
#include <QFont>
#include <QColor>
#include <QPixmap>
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsinterval.cpp
Expand Up @@ -37,6 +37,14 @@ QgsInterval::QgsInterval( double seconds )
{
}

QgsInterval::QgsInterval( std::chrono::milliseconds milliseconds )
: mSeconds( milliseconds.count() / 1000.0 )
, mValid( true )
, mOriginalDuration( milliseconds.count() )
, mOriginalUnit( QgsUnitTypes::TemporalMilliseconds )
{
}

QgsInterval::QgsInterval( double duration, QgsUnitTypes::TemporalUnit unit )
: mSeconds( duration * QgsUnitTypes::fromUnitToUnitFactor( unit, QgsUnitTypes::TemporalSeconds ) )
, mValid( true )
Expand Down Expand Up @@ -296,12 +304,16 @@ QDebug operator<<( QDebug dbg, const QgsInterval &interval )
return dbg.maybeSpace();
}

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

QgsInterval operator-( const QDateTime &dt1, const QDateTime &dt2 )
{
const qint64 mSeconds = dt2.msecsTo( dt1 );
return QgsInterval( mSeconds / 1000.0 );
}

#endif

QDateTime operator+( const QDateTime &start, const QgsInterval &interval )
{
return start.addMSecs( static_cast<qint64>( interval.seconds() * 1000.0 ) );
Expand All @@ -318,3 +330,4 @@ QgsInterval operator-( QTime time1, QTime time2 )
const qint64 mSeconds = time2.msecsTo( time1 );
return QgsInterval( mSeconds / 1000.0 );
}

15 changes: 14 additions & 1 deletion src/core/qgsinterval.h
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/

#include <QVariant>
#include <chrono>

#include "qgis_sip.h"
#include "qgis_core.h"
Expand Down Expand Up @@ -68,6 +69,12 @@ class CORE_EXPORT QgsInterval
*/
QgsInterval( double seconds );

/**
* Constructor for QgsInterval.
* \param milliseconds duration of interval in milliseconds
*/
QgsInterval( std::chrono::milliseconds milliseconds ) SIP_SKIP;

/**
* Constructor for QgsInterval, using the specified \a duration and \a units.
*/
Expand Down Expand Up @@ -343,6 +350,8 @@ Q_DECLARE_METATYPE( QgsInterval )

#ifndef SIP_RUN

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

/**
* Returns the interval between two datetimes.
* \param datetime1 start datetime
Expand All @@ -352,6 +361,8 @@ Q_DECLARE_METATYPE( QgsInterval )
*/
QgsInterval CORE_EXPORT operator-( const QDateTime &datetime1, const QDateTime &datetime2 );

#endif

/**
* Returns the interval between two dates.
* \param date1 start date
Expand Down Expand Up @@ -381,7 +392,9 @@ QDateTime CORE_EXPORT operator+( const QDateTime &start, const QgsInterval &inte

//! Debug string representation of interval
QDebug CORE_EXPORT operator<<( QDebug dbg, const QgsInterval &interval );
\



#endif

#endif // QGSINTERVAL_H
4 changes: 2 additions & 2 deletions src/core/qgstemporalnavigationobject.cpp
Expand Up @@ -81,7 +81,7 @@ QgsExpressionContextScope *QgsTemporalNavigationObject::createExpressionContextS
scope->setVariable( QStringLiteral( "frame_timestep_units" ), QgsUnitTypes::toString( mFrameDuration.originalUnit() ), true );
scope->setVariable( QStringLiteral( "animation_start_time" ), mTemporalExtents.begin(), true );
scope->setVariable( QStringLiteral( "animation_end_time" ), mTemporalExtents.end(), true );
scope->setVariable( QStringLiteral( "animation_interval" ), mTemporalExtents.end() - mTemporalExtents.begin(), true );
scope->setVariable( QStringLiteral( "animation_interval" ), QgsInterval( mTemporalExtents.end() - mTemporalExtents.begin() ), true );

scope->addHiddenVariable( QStringLiteral( "frame_timestep_unit" ) );

Expand Down Expand Up @@ -371,7 +371,7 @@ long long QgsTemporalNavigationObject::findBestFrameNumberForFrameStart( const Q
// We tend to receive a framestart of 'now()' upon startup for example
if ( mTemporalExtents.contains( frameStart ) )
{
roughFrameStart = static_cast< long long >( std::floor( ( frameStart - mTemporalExtents.begin() ).seconds() / mFrameDuration.seconds() ) );
roughFrameStart = static_cast< long long >( std::floor( QgsInterval( frameStart - mTemporalExtents.begin() ).seconds() / mFrameDuration.seconds() ) );
}
roughFrameEnd = roughFrameStart + 100; // just in case we miss the guess
}
Expand Down

0 comments on commit 794f1e1

Please sign in to comment.