Skip to content

Commit

Permalink
fix null temporal properties
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Oct 6, 2021
1 parent a755ee9 commit 99a832e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
Expand Up @@ -89,6 +89,22 @@ Returns the method used to match dataset from temporal capabilities
Sets the method used to match dataset from temporal capabilities

:param matchingMethod: the matching method
%End

bool isValid() const;
%Docstring
Returns whether the instance is valid

.. versionadded:: 3.22
%End

void setIsValid( bool isValid );
%Docstring
Sets whether the instance is valid

:param isValid: whether the instance is valid

.. versionadded:: 3.22
%End

};
Expand Down
Expand Up @@ -747,6 +747,13 @@ Returns the active vector dataset group
Sets the active vector dataset group

.. versionadded:: 3.14
%End

bool hasSettings( int datasetGroupIndex ) const;
%Docstring
Returns whether the group with ``index`` has render settings (scalar or vector)

.. versionadded:: 3.22
%End

};
Expand Down
10 changes: 3 additions & 7 deletions src/core/mesh/qgsmeshlayer.cpp
Expand Up @@ -49,8 +49,8 @@ QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,
const QString &providerKey,
const QgsMeshLayer::LayerOptions &options )
: QgsMapLayer( QgsMapLayerType::MeshLayer, baseName, meshLayerPath ),
mDatasetGroupStore( new QgsMeshDatasetGroupStore( this ) )

mDatasetGroupStore( new QgsMeshDatasetGroupStore( this ) ),
mTemporalProperties( new QgsMeshLayerTemporalProperties( this ) )
{
mShouldValidateCrs = !options.skipCrsValidation;

Expand Down Expand Up @@ -1159,7 +1159,6 @@ void QgsMeshLayer::setDataSourcePrivate( const QString &dataSource, const QStrin

if ( !mDataSource.isEmpty() && !provider.isEmpty() )
setDataProvider( provider, options, flags );

}

QgsPointXY QgsMeshLayer::snapOnElement( QgsMesh::ElementType elementType, const QgsPointXY &point, double searchRadius )
Expand Down Expand Up @@ -1497,8 +1496,6 @@ bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &con
else
mDatasetGroupStore->readXml( elemDatasetGroupsStore, context );

mTemporalProperties = new QgsMeshLayerTemporalProperties( this );

setDataProvider( mProviderKey, providerOptions, flags );

QString errorMsg;
Expand Down Expand Up @@ -1706,9 +1703,8 @@ bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvid
return false;
}

if ( !mTemporalProperties )
if ( !mTemporalProperties->isValid() )
{
mTemporalProperties = new QgsMeshLayerTemporalProperties( this );
mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( dataProvider()->temporalCapabilities() );
}

Expand Down
13 changes: 13 additions & 0 deletions src/core/mesh/qgsmeshlayertemporalproperties.cpp
Expand Up @@ -61,6 +61,7 @@ bool QgsMeshLayerTemporalProperties::readXml( const QDomElement &element, const
mMatchingMethod = static_cast<QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod>(
temporalElement.attribute( QStringLiteral( "matching-method" ) ).toInt() );

mIsValid = true;
return true;
}

Expand All @@ -74,6 +75,8 @@ void QgsMeshLayerTemporalProperties::setDefaultsFromDataProviderTemporalCapabili

if ( mReferenceTime.isValid() )
mTimeExtent = temporalCapabilities->timeExtent();

mIsValid = true;
}

QgsDateTimeRange QgsMeshLayerTemporalProperties::calculateTemporalExtent( QgsMapLayer * ) const
Expand Down Expand Up @@ -112,3 +115,13 @@ void QgsMeshLayerTemporalProperties::setMatchingMethod( const QgsMeshDataProvide
{
mMatchingMethod = matchingMethod;
}

bool QgsMeshLayerTemporalProperties::isValid() const
{
return mIsValid;
}

void QgsMeshLayerTemporalProperties::setIsValid( bool isValid )
{
mIsValid = isValid;
}
17 changes: 17 additions & 0 deletions src/core/mesh/qgsmeshlayertemporalproperties.h
Expand Up @@ -100,11 +100,28 @@ class CORE_EXPORT QgsMeshLayerTemporalProperties : public QgsMapLayerTemporalPro
*/
void setMatchingMethod( const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod );

/**
* Returns whether the instance is valid
*
* \since QGIS 3.22
*/
bool isValid() const;

/**
* Sets whether the instance is valid
*
* \param isValid whether the instance is valid
*
* \since QGIS 3.22
*/
void setIsValid( bool isValid );

private:
QDateTime mReferenceTime;
QgsDateTimeRange mTimeExtent;
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod mMatchingMethod =
QgsMeshDataProviderTemporalCapabilities::FindClosestDatasetBeforeStartRangeTime;
bool mIsValid = false;
};

#endif // QGSMESHLAYERTEMPORALPROPERTIES_H

0 comments on commit 99a832e

Please sign in to comment.