Skip to content
Permalink
Browse files

Show some more diverse format for an interval

Before showing an interval of two hours would show you:
interval: 0.0833333 days
Now depending on the range of the interval you will see output
in days, minutes or seconds:

make_interval(years:=0.75)
<interval: 273.938 days>

make_interval(days:=2, hours:=3)
<interval: 2.125 days>

make_interval(hours:=3,days:=1)
<interval: 1.125 days>

make_interval(minutes:=30)
<interval: 30 minutes>

make_interval(minutes:=0.5,seconds:=5)
<interval: 35 seconds>
  • Loading branch information
rduivenvoorde authored and nyalldawson committed Oct 5, 2020
1 parent 667af7f commit 51b650afdf641566defe6874d52cbe9e3b4d1e14
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/core/expression/qgsexpression.cpp
@@ -975,7 +975,22 @@ QString QgsExpression::formatPreviewString( const QVariant &value, const bool ht
else if ( value.canConvert< QgsInterval >() )
{
QgsInterval interval = value.value<QgsInterval>();
return startToken + tr( "interval: %1 days" ).arg( interval.days() ) + endToken;
if ( interval.days() > 1 )
{
return startToken + tr( "interval: %1 days" ).arg( interval.days() ) + endToken;
}
else if ( interval.hours() > 1 )
{
return startToken + tr( "interval: %1 hours" ).arg( interval.hours() ) + endToken;
}
else if ( interval.minutes() > 1 )
{
return startToken + tr( "interval: %1 minutes" ).arg( interval.minutes() ) + endToken;
}
else
{
return startToken + tr( "interval: %1 seconds" ).arg( interval.seconds() ) + endToken;
}
}
else if ( value.canConvert< QgsGradientColorRamp >() )
{

0 comments on commit 51b650a

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