Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh layer remove datasetgroup #59382

Merged
merged 36 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fe82786
add removeDatasetGroup() function for mesh data provider and mesh layer
JanCaha Nov 8, 2024
2b412a2
make dataset group names unique
JanCaha Nov 8, 2024
8ec6907
fix typo
JanCaha Nov 8, 2024
026fc1e
add mesh removing to the widget
JanCaha Nov 8, 2024
b94696f
fix icon
JanCaha Nov 8, 2024
86abd25
add check that added dataset group path is unique to avoid duplicate …
JanCaha Nov 8, 2024
2b17242
sipify
JanCaha Nov 8, 2024
173e2fa
fix mistake
JanCaha Nov 8, 2024
55ce924
check if uri is correct - just for case
JanCaha Nov 8, 2024
ded8cf7
add tests
JanCaha Nov 8, 2024
43f1474
add tests
JanCaha Nov 8, 2024
7127e9a
fix docstring
JanCaha Nov 9, 2024
e7b8fa8
add docstring
JanCaha Nov 9, 2024
89c25f1
add missing override
JanCaha Nov 9, 2024
3d10a38
explicitly convert number to string
JanCaha Nov 10, 2024
06cc58c
update tests to reflect that you cannot add same file as dataset grou…
JanCaha Nov 10, 2024
35d9b22
fix docstring
JanCaha Nov 23, 2024
207d36a
pass by value
JanCaha Nov 23, 2024
bc36e88
fix docstrings
JanCaha Nov 23, 2024
96ac70b
const variables
JanCaha Nov 23, 2024
104edef
rename signal
JanCaha Nov 23, 2024
7affb05
drop include
JanCaha Nov 23, 2024
5b60fc1
simplify regex
JanCaha Nov 23, 2024
f92c373
make test better
JanCaha Nov 23, 2024
27ad6dd
sipify
JanCaha Nov 23, 2024
edc0f8d
add docstring
JanCaha Nov 23, 2024
f49b520
fix styling and typo
JanCaha Nov 23, 2024
9521cba
fix tests
JanCaha Nov 24, 2024
1888510
Merge branch 'master' into meshlayer-remove-datasetgroup
JanCaha Dec 5, 2024
dd6b4c8
fix precommit issues
JanCaha Dec 5, 2024
6a76e36
fix issue
JanCaha Dec 5, 2024
00f8120
Update src/core/mesh/qgsmeshlayer.h
JanCaha Dec 11, 2024
3320239
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
9bab444
const stuff
JanCaha Dec 11, 2024
608e904
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
62d87a7
sipify
JanCaha Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,17 @@ Returns the mesh driver metadata of the provider
Closes the data provider and free every resources used

.. versionadded:: 3.22
%End

virtual bool removeDatasetGroup( int index ) = 0;
%Docstring
Remove dataset group from the mesh

emits dataChanged when successful

:return: ``True`` on success

.. versionadded:: 3.42
%End

signals:
Expand Down
24 changes: 23 additions & 1 deletion python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,23 @@ Returns the provider type for this layer
%Docstring
Adds datasets to the mesh from file with ``path``. Use the the time ``defaultReferenceTime`` as reference time is not provided in the file

:param path: the path to the atasets file
:param path: the path to the datasets file
:param defaultReferenceTime: reference time used if not provided in the file

:return: whether the dataset is added

.. versionadded:: 3.14
%End

bool removeDatasets( const QString &name );
%Docstring
Removes datasets from the mesh with given ``name``.

:param name: name of dataset group to remove

:return: whether the dataset is removed

.. versionadded:: 3.42
%End

bool addDatasets( QgsMeshDatasetGroup *datasetGroup /Transfer/ );
Expand Down Expand Up @@ -905,6 +916,17 @@ Sets labeling configuration. Takes ownership of the object.
.. versionadded:: 3.36
%End

bool datasetsPathUnique( const QString &path );
%Docstring
Checks whether that datasets path is already added to this mesh layer. Return ``True`` if the
dataset path is not already added.

:param path: the path to the datasets file

:return: whether the datasets path is unique

.. versionadded:: 3.42
%End

public slots:

Expand Down
11 changes: 11 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,17 @@ Returns the mesh driver metadata of the provider
Closes the data provider and free every resources used

.. versionadded:: 3.22
%End

virtual bool removeDatasetGroup( int index ) = 0;
%Docstring
Remove dataset group from the mesh

emits dataChanged when successful

:return: ``True`` on success

.. versionadded:: 3.42
%End

signals:
Expand Down
24 changes: 23 additions & 1 deletion python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,23 @@ Returns the provider type for this layer
%Docstring
Adds datasets to the mesh from file with ``path``. Use the the time ``defaultReferenceTime`` as reference time is not provided in the file

:param path: the path to the atasets file
:param path: the path to the datasets file
:param defaultReferenceTime: reference time used if not provided in the file

:return: whether the dataset is added

.. versionadded:: 3.14
%End

bool removeDatasets( const QString &name );
%Docstring
Removes datasets from the mesh with given ``name``.

:param name: name of dataset group to remove

:return: whether the dataset is removed

.. versionadded:: 3.42
%End

bool addDatasets( QgsMeshDatasetGroup *datasetGroup /Transfer/ );
Expand Down Expand Up @@ -905,6 +916,17 @@ Sets labeling configuration. Takes ownership of the object.
.. versionadded:: 3.36
%End

bool datasetsPathUnique( const QString &path );
%Docstring
Checks whether that datasets path is already added to this mesh layer. Return ``True`` if the
dataset path is not already added.

:param path: the path to the datasets file

:return: whether the datasets path is unique

.. versionadded:: 3.42
%End

public slots:

Expand Down
11 changes: 11 additions & 0 deletions src/core/mesh/qgsmeshdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,17 @@ class CORE_EXPORT QgsMeshDataProvider: public QgsDataProvider, public QgsMeshDat
*/
virtual void close() = 0;

/**
* \brief Remove dataset group from the mesh
*
* emits dataChanged when successful
*
* \return TRUE on success
*
* \since QGIS 3.42
*/
virtual bool removeDatasetGroup( int index ) = 0;

signals:
//! Emitted when some new dataset groups have been added
void datasetGroupsAdded( int count );
Expand Down
44 changes: 41 additions & 3 deletions src/core/mesh/qgsmeshdatasetgroupstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ bool QgsMeshDatasetGroupStore::addDatasetGroup( QgsMeshDatasetGroup *group )
return true;
}

void QgsMeshDatasetGroupStore::removeDatasetGroup( int index )
{
const QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index );
if ( group.first == mPersistentProvider )
mPersistentProvider->removeDatasetGroup( group.second );
else if ( group.first == &mExtraDatasets )
eraseExtraDataset( group.second );

reindexDatasetGroups();
}

void QgsMeshDatasetGroupStore::reindexDatasetGroups()
{
mRegistry.clear();
mPersistentExtraDatasetGroupIndexes.clear();
mGroupNameToGlobalIndex.clear();

int globalIndex = 0;

for ( int i = 0; i < mPersistentProvider->datasetGroupCount(); i++ )
{
const QString name = mPersistentProvider->datasetGroupMetadata( i ).name();
mRegistry[globalIndex] = DatasetGroup{mPersistentProvider, i};
mPersistentExtraDatasetGroupIndexes.append( globalIndex );
mGroupNameToGlobalIndex.insert( name, globalIndex );
globalIndex++;
}

for ( int i = 0; i < mExtraDatasets.datasetGroupCount(); i++ )
{
QgsMeshDatasetSourceInterface *source = &mExtraDatasets;
const QString name = source->datasetGroupMetadata( i ).name();
mRegistry[globalIndex] = DatasetGroup{source, i};
mGroupNameToGlobalIndex.insert( name, globalIndex );
globalIndex++;
}
}

void QgsMeshDatasetGroupStore::resetDatasetGroupTreeItem()
{
mDatasetGroupTreeRootItem.reset( new QgsMeshDatasetGroupTreeItem );
Expand Down Expand Up @@ -695,10 +733,10 @@ int QgsMeshExtraDatasetStore::addDatasetGroup( QgsMeshDatasetGroup *datasetGroup
return mGroups.size() - 1;
}

void QgsMeshExtraDatasetStore::removeDatasetGroup( int index )
void QgsMeshExtraDatasetStore::removeDatasetGroup( int groupIndex )
{
if ( index < datasetGroupCount() )
mGroups.erase( mGroups.begin() + index );
if ( groupIndex < datasetGroupCount() )
mGroups.erase( mGroups.begin() + groupIndex );


updateTemporalCapabilities();
Expand Down
10 changes: 10 additions & 0 deletions src/core/mesh/qgsmeshdatasetgroupstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ class QgsMeshDatasetGroupStore: public QObject
*/
QString groupName( int groupIndex ) const;

/**
* Removes dataset group with global index \a groupIndex
*
* \since QGIS 3.42
*/
void removeDatasetGroup( int groupIndex );

signals:
//! Emitted after dataset groups are added
void datasetGroupsAdded( QList<int> indexes );
Expand All @@ -259,6 +266,9 @@ class QgsMeshDatasetGroupStore: public QObject

void removePersistentProvider();

//! reindex dataset group stores variables from provider and extra datasets, to keep data in sync after removal of dataset group
void reindexDatasetGroups();
JanCaha marked this conversation as resolved.
Show resolved Hide resolved

DatasetGroup datasetGroup( int index ) const;

//! Returns a index that is not already used
Expand Down
38 changes: 38 additions & 0 deletions src/core/mesh/qgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ QString QgsMeshLayer::loadDefaultStyle( bool &resultFlag )
return QgsMapLayer::loadDefaultStyle( resultFlag );
}

bool QgsMeshLayer::removeDatasets( const QString &name )
{
const int index = mDatasetGroupStore->indexFromGroupName( name );

if ( index == -1 )
{
return false;
}

const QgsMeshDatasetGroupMetadata groupMetadata = datasetGroupMetadata( index );

mDatasetGroupStore->removeDatasetGroup( index );

if ( mExtraDatasetUri.contains( groupMetadata.uri() ) )
{
mExtraDatasetUri.removeOne( groupMetadata.uri() );
}

resetDatasetGroupTreeItem();

emit dataSourceChanged();
return true;
}

bool QgsMeshLayer::addDatasets( const QString &path, const QDateTime &defaultReferenceTime )
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Expand Down Expand Up @@ -2210,3 +2234,17 @@ void QgsMeshLayer::setLabeling( QgsAbstractMeshLayerLabeling *labeling )
mLabeling = labeling;
triggerRepaint();
}

bool QgsMeshLayer::datasetsPathUnique( const QString &path )
{
if ( ! mDataProvider )
{
QgsDebugMsgLevel( QStringLiteral( "Unable to get mesh data provider" ), 2 );
return false;
}

if ( mDataProvider->dataSourceUri().contains( path ) )
return false;

return !mExtraDatasetUri.contains( path );
}
23 changes: 21 additions & 2 deletions src/core/mesh/qgsmeshlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,24 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo
/**
* Adds datasets to the mesh from file with \a path. Use the the time \a defaultReferenceTime as reference time is not provided in the file
*
* \param path the path to the atasets file
* \param path the path to the datasets file
* \param defaultReferenceTime reference time used if not provided in the file
* \return whether the dataset is added
*
* \since QGIS 3.14
*/
bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() );

/**
* Removes datasets from the mesh with given \a name.
*
* \param name name of dataset group to remove
* \return whether the dataset is removed
*
* \since QGIS 3.42
*/
bool removeDatasets( const QString &name );
uclaros marked this conversation as resolved.
Show resolved Hide resolved

/**
* Adds extra datasets to the mesh. Take ownership.
*
Expand Down Expand Up @@ -932,6 +942,16 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo
*/
void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER );

/**
* Checks whether that datasets path is already added to this mesh layer. Return TRUE if the
* dataset path is not already added.
*
* \param path the path to the datasets file
* \return whether the datasets path is unique
*
* \since QGIS 3.42
*/
bool datasetsPathUnique( const QString &path );

public slots:

Expand Down Expand Up @@ -986,7 +1006,6 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo
* \param flags provider flags since QGIS 3.16
*/
bool setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );

#ifdef SIP_RUN
QgsMeshLayer( const QgsMeshLayer &rhs );
#endif
Expand Down
20 changes: 20 additions & 0 deletions src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,26 @@ bool QgsMeshMemoryDataProvider::addDataset( const QString &uri )
return valid;
}

bool QgsMeshMemoryDataProvider::removeDatasetGroup( int index )
{
if ( index < 0 && index > datasetGroupCount() - 1 )
{
return false;
}
else
{
const QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index );

mDatasetGroups.removeAt( index );

if ( !mExtraDatasetUris.contains( datasetGroupMeta.uri() ) )
mExtraDatasetUris.removeAll( datasetGroupMeta.uri() );

emit dataChanged();
return true;
}
}

QStringList QgsMeshMemoryDataProvider::extraDatasets() const
{
return mExtraDatasetUris;
Expand Down
3 changes: 3 additions & 0 deletions src/core/providers/meshmemory/qgsmeshmemorydataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class CORE_EXPORT QgsMeshMemoryDataProvider final: public QgsMeshDataProvider
* \endcode
*/
bool addDataset( const QString &uri ) override;

bool removeDatasetGroup( int index ) override;

QStringList extraDatasets() const override;
int datasetGroupCount() const override;
int datasetCount( int groupIndex ) const override;
Expand Down
Loading
Loading