Skip to content
Permalink
Browse files

Allow skipping setting either the start of end time fields

Result is features which start at -eternity and end at the selected
end field time, or which start at the selected start field time
and end at +eternity
  • Loading branch information
nyalldawson committed May 7, 2020
1 parent 3994da6 commit d08a4c12a95e7baab499f248a2a1ed68e9f7b9fd
@@ -89,6 +89,16 @@ QgsDateTimeRange QgsTemporalUtils::calculateTemporalRangeForProject( QgsProject
std::max( vectorLayer->maximumValue( startFieldIndex ).toDateTime(),
vectorLayer->maximumValue( endFieldIndex ).toDateTime() ) );
}
else if ( startFieldIndex >= 0 )
{
layerRange = QgsDateTimeRange( vectorLayer->minimumValue( startFieldIndex ).toDateTime(),
vectorLayer->maximumValue( startFieldIndex ).toDateTime() );
}
else if ( endFieldIndex >= 0 )
{
layerRange = QgsDateTimeRange( vectorLayer->minimumValue( endFieldIndex ).toDateTime(),
vectorLayer->maximumValue( endFieldIndex ).toDateTime() );
}
break;
}
}
@@ -193,12 +193,30 @@ QString QgsVectorLayerTemporalProperties::createFilterString( QgsVectorLayer *,
dateTimeExpressionLiteral( range.end() ) );

case ModeFeatureDateTimeStartAndEndFromFields:
return QStringLiteral( "%1 %2 %3 AND %4 %5 %6" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
range.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( range.end() ),
QgsExpression::quotedColumnRef( mEndFieldName ),
range.includeBeginning() ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( range.begin() ) );
{
if ( !mStartFieldName.isEmpty() && !mEndFieldName.isEmpty() )
{
return QStringLiteral( "%1 %2 %3 AND %4 %5 %6" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
range.includeEnd() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( range.end() ),
QgsExpression::quotedColumnRef( mEndFieldName ),
range.includeBeginning() ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( range.begin() ) );
}
else if ( !mStartFieldName.isEmpty() )
{
return QStringLiteral( "%1 %2 %3" ).arg( QgsExpression::quotedColumnRef( mStartFieldName ),
range.includeBeginning() ? QStringLiteral( "<=" ) : QStringLiteral( "<" ),
dateTimeExpressionLiteral( range.end() ) );
}
else if ( !mEndFieldName.isEmpty() )
{
return QStringLiteral( "%1 %2 %3" ).arg( QgsExpression::quotedColumnRef( mEndFieldName ),
range.includeBeginning() ? QStringLiteral( ">=" ) : QStringLiteral( ">" ),
dateTimeExpressionLiteral( range.begin() ) );
}
break;
}
}

return QString();
@@ -214,10 +214,8 @@ QVariant QgsLayoutAttributeTableColumnModelBase::headerData( int section, Qt::Or
}
}
}
else
{
return QVariant();
}

return QVariant();
}

bool QgsLayoutAttributeTableColumnModelBase::setData( const QModelIndex &index, const QVariant &value, int role )
@@ -55,7 +55,9 @@ QgsVectorLayerTemporalPropertiesWidget::QgsVectorLayerTemporalPropertiesWidget(
mEndFieldComboBox->setLayer( layer );
mSingleFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
mStartFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
mStartFieldComboBox->setAllowEmptyFieldName( true );
mEndFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
mEndFieldComboBox->setAllowEmptyFieldName( true );

if ( !properties->startField().isEmpty() )
{
@@ -142,6 +142,25 @@ def testDualFieldMode(self):
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
self.assertEqual(props.createFilterString(layer, range), '"start_field" < make_datetime(2020,5,6,8,9,10) AND "end_field" >= make_datetime(2019,3,4,11,12,13)')

props.setEndField('')
self.assertEqual(props.createFilterString(layer, range), '"start_field" <= make_datetime(2020,5,6,8,9,10)')

range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeBeginning=False)
self.assertEqual(props.createFilterString(layer, range), '"start_field" < make_datetime(2020,5,6,8,9,10)')

range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
self.assertEqual(props.createFilterString(layer, range), '"start_field" <= make_datetime(2020,5,6,8,9,10)')

props.setStartField('')
props.setEndField('end_field')
self.assertEqual(props.createFilterString(layer, range), '"end_field" >= make_datetime(2019,3,4,11,12,13)')

range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeBeginning=False)
self.assertEqual(props.createFilterString(layer, range), '"end_field" > make_datetime(2019,3,4,11,12,13)')

range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
self.assertEqual(props.createFilterString(layer, range), '"end_field" >= make_datetime(2019,3,4,11,12,13)')


if __name__ == '__main__':
unittest.main()

0 comments on commit d08a4c1

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