Skip to content

Commit

Permalink
Followup #41109: fix algorithms
Browse files Browse the repository at this point in the history
Check for NULL instead of valid (because NULL is valid).

The old behavior was relying on the fact that a NULL attribute was
stored by OGR as an empty string instead of a NULL QVariant of the
corresponding field type, the conversion of the QVariant( QString())
to a numeric field was checked (and it was failing) so everything
worked (at least for non-string types).
  • Loading branch information
elpaso committed Jan 25, 2021
1 parent 13ed787 commit d66d66e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/analysis/processing/qgsalgorithmpointslayerfromtable.cpp
Expand Up @@ -132,14 +132,14 @@ QVariantMap QgsPointsLayerFromTableAlgorithm::processAlgorithm( const QVariantMa
double x = attrs.at( xFieldIndex ).toDouble( &xOk );
double y = attrs.at( yFieldIndex ).toDouble( &yOk );

if ( xOk && yOk )
if ( ! attrs.at( xFieldIndex ).isNull() && ! attrs.at( yFieldIndex ).isNull() && xOk && yOk )
{
QgsPoint point( x, y );

if ( zFieldIndex >= 0 )
if ( zFieldIndex >= 0 && ! attrs.at( zFieldIndex ).isNull() )
point.addZValue( attrs.at( zFieldIndex ).toDouble() );

if ( mFieldIndex >= 0 )
if ( mFieldIndex >= 0 && ! attrs.at( mFieldIndex ).isNull() )
point.addMValue( attrs.at( mFieldIndex ).toDouble() );

f.setGeometry( QgsGeometry( point.clone() ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsdatetimestatisticalsummary.cpp
Expand Up @@ -65,14 +65,14 @@ void QgsDateTimeStatisticalSummary::addValue( const QVariant &value )
else if ( value.type() == QVariant::Date )
{
QDate date = value.toDate();
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
testDateTime( ! date.isNull() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
testDateTime( ! time.isNull() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime() );
}
else //not a date
Expand Down

0 comments on commit d66d66e

Please sign in to comment.