From fe827866f089f36f7ddcb5e22d6598a42a6eb2ba Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:37:13 +0100 Subject: [PATCH 01/35] add removeDatasetGroup() function for mesh data provider and mesh layer --- src/core/mesh/qgsmeshdataprovider.h | 11 ++++++ src/core/mesh/qgsmeshdatasetgroupstore.cpp | 38 +++++++++++++++++++ src/core/mesh/qgsmeshdatasetgroupstore.h | 4 ++ src/core/mesh/qgsmeshlayer.cpp | 38 +++++++++++++++++++ src/core/mesh/qgsmeshlayer.h | 10 +++++ .../meshmemory/qgsmeshmemorydataprovider.cpp | 20 ++++++++++ .../meshmemory/qgsmeshmemorydataprovider.h | 3 ++ src/providers/mdal/qgsmdalprovider.cpp | 19 ++++++++++ src/providers/mdal/qgsmdalprovider.h | 3 ++ 9 files changed, 146 insertions(+) diff --git a/src/core/mesh/qgsmeshdataprovider.h b/src/core/mesh/qgsmeshdataprovider.h index 3d4bb950054a..d19c0570ecda 100644 --- a/src/core/mesh/qgsmeshdataprovider.h +++ b/src/core/mesh/qgsmeshdataprovider.h @@ -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( const int &index ) = 0; + signals: //! Emitted when some new dataset groups have been added void datasetGroupsAdded( int count ); diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.cpp b/src/core/mesh/qgsmeshdatasetgroupstore.cpp index e401da8f2616..d36f5acbbc98 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.cpp +++ b/src/core/mesh/qgsmeshdatasetgroupstore.cpp @@ -125,6 +125,44 @@ bool QgsMeshDatasetGroupStore::addDatasetGroup( QgsMeshDatasetGroup *group ) return true; } +void QgsMeshDatasetGroupStore::removeDatasetGroup( int index ) +{ + 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++ ) + { + 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; + QString name = source->datasetGroupMetadata( i ).name(); + mRegistry[globalIndex] = DatasetGroup{source, i}; + mGroupNameToGlobalIndex.insert( name, globalIndex ); + globalIndex++; + } +} + void QgsMeshDatasetGroupStore::resetDatasetGroupTreeItem() { mDatasetGroupTreeRootItem.reset( new QgsMeshDatasetGroupTreeItem ); diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.h b/src/core/mesh/qgsmeshdatasetgroupstore.h index da4bc2cbb197..963ea0ce68d2 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.h +++ b/src/core/mesh/qgsmeshdatasetgroupstore.h @@ -241,6 +241,8 @@ class QgsMeshDatasetGroupStore: public QObject */ QString groupName( int groupIndex ) const; + void removeDatasetGroup( int index ); + signals: //! Emitted after dataset groups are added void datasetGroupsAdded( QList indexes ); @@ -259,6 +261,8 @@ class QgsMeshDatasetGroupStore: public QObject void removePersistentProvider(); + void reindexDatasetGroups(); + DatasetGroup datasetGroup( int index ) const; //! Returns a index that is not already used diff --git a/src/core/mesh/qgsmeshlayer.cpp b/src/core/mesh/qgsmeshlayer.cpp index 008aa52a1920..8df688ef4f03 100644 --- a/src/core/mesh/qgsmeshlayer.cpp +++ b/src/core/mesh/qgsmeshlayer.cpp @@ -253,6 +253,30 @@ QString QgsMeshLayer::loadDefaultStyle( bool &resultFlag ) return QgsMapLayer::loadDefaultStyle( resultFlag ); } +bool QgsMeshLayer::removeDatasets( const QString &name ) +{ + int index = mDatasetGroupStore->indexFromGroupName( name ); + + if ( index == -1 ) + { + return false; + } + + 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 @@ -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 ); +} diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index c3e3f6af52dd..c55eb427d3c7 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -211,6 +211,16 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo */ bool addDatasets( const QString &path, const QDateTime &defaultReferenceTime = QDateTime() ); + /** + * Removes datasets from the mesh with given \a name. + * + * \param name of dataset group to remove + * \return whether the dataset is added + * + * \since QGIS 3.42 + */ + bool removeDatasets( const QString &name ); + /** * Adds extra datasets to the mesh. Take ownership. * diff --git a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp index 68b567a3c1ab..f190fa5ae718 100644 --- a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp +++ b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp @@ -430,6 +430,26 @@ bool QgsMeshMemoryDataProvider::addDataset( const QString &uri ) return valid; } +bool QgsMeshMemoryDataProvider::removeDatasetGroup( const int &index ) +{ + if ( index < 0 && index > datasetGroupCount() - 1 ) + { + return false; + } + else + { + 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; diff --git a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h index 8d41130cbe75..ac456a8d21f7 100644 --- a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h +++ b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h @@ -127,6 +127,9 @@ class CORE_EXPORT QgsMeshMemoryDataProvider final: public QgsMeshDataProvider * \endcode */ bool addDataset( const QString &uri ) override; + + bool removeDatasetGroup( const int &index ); + QStringList extraDatasets() const override; int datasetGroupCount() const override; int datasetCount( int groupIndex ) const override; diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index 3192d888a040..b5c5d5a57503 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -701,6 +701,25 @@ bool QgsMdalProvider::addDataset( const QString &uri ) } } +bool QgsMdalProvider::removeDatasetGroup( const int &index ) +{ + if ( index < 0 && index > datasetGroupCount() - 1 ) + { + return false; + } + else + { + QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index ); + + if ( mExtraDatasetUris.contains( datasetGroupMeta.uri() ) ) + mExtraDatasetUris.removeOne( datasetGroupMeta.uri() ); + + MDAL_M_RemoveDatasetGroup( mMeshH, index ); + emit dataChanged(); + return true; + } +} + QStringList QgsMdalProvider::extraDatasets() const { return mExtraDatasetUris; diff --git a/src/providers/mdal/qgsmdalprovider.h b/src/providers/mdal/qgsmdalprovider.h index c4260a578ddd..64db515c1df7 100644 --- a/src/providers/mdal/qgsmdalprovider.h +++ b/src/providers/mdal/qgsmdalprovider.h @@ -63,6 +63,9 @@ class QgsMdalProvider : public QgsMeshDataProvider void populateMesh( QgsMesh *mesh ) const override; bool addDataset( const QString &uri ) override; + + bool removeDatasetGroup( const int &index ) override; + QStringList extraDatasets() const override; int datasetGroupCount() const override; From 2b412a22bfc303dbf84ee31dda2ad77b96b92b86 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:38:40 +0100 Subject: [PATCH 02/35] make dataset group names unique --- src/core/mesh/qgsmeshlayer.h | 10 ++++++ src/providers/mdal/qgsmdalprovider.cpp | 44 ++++++++++++++++++++++++++ src/providers/mdal/qgsmdalprovider.h | 3 ++ 3 files changed, 57 insertions(+) diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index c55eb427d3c7..bb9c0ab395bf 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -942,6 +942,16 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo */ void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER ); + /** + * Checks that datasets path is already added to this mesh layer. Return true if the + * dataset path is unique. + * + * \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: diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index b5c5d5a57503..d1a94480ce97 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -30,6 +30,7 @@ #include #include #include +#include const QString QgsMdalProvider::MDAL_PROVIDER_KEY = QStringLiteral( "mdal" ); const QString QgsMdalProvider::MDAL_PROVIDER_DESCRIPTION = QStringLiteral( "MDAL provider" ); @@ -677,11 +678,16 @@ void QgsMdalProvider::fileMeshExtensions( QStringList &fileMeshExtensions, bool QgsMdalProvider::addDataset( const QString &uri ) { + if ( mExtraDatasetUris.contains( uri ) && dataSourceUri().contains( uri ) ) + return false; + int datasetCount = datasetGroupCount(); std::string str = uri.toStdString(); MDAL_M_LoadDatasets( mMeshH, str.c_str() ); + makeLastDatasetGroupNameUnique(); + if ( datasetCount == datasetGroupCount() ) { return false; @@ -701,6 +707,44 @@ bool QgsMdalProvider::addDataset( const QString &uri ) } } +void QgsMdalProvider::makeLastDatasetGroupNameUnique() +{ + MDAL_DatasetGroupH datasetGroupH = MDAL_M_datasetGroup( mMeshH, datasetGroupCount() - 1 ); + QString lastAddedGroupName = QString( MDAL_G_name( datasetGroupH ) ); + + QSet existingNames; + + for ( int i = 0; i < datasetGroupCount() - 1; i++ ) + { + existingNames.insert( MDAL_G_name( MDAL_M_datasetGroup( mMeshH, i ) ) ); + } + + if ( existingNames.contains( lastAddedGroupName ) ) + { + QRegularExpression reEndsNumber( "_[0-9]+$" ); + QRegularExpression reNumber( "[0-9]+$" ); + QRegularExpressionMatch match; + + while ( existingNames.find( lastAddedGroupName ) != existingNames.end() ) + { + if ( reEndsNumber.match( lastAddedGroupName ).hasMatch() ) + { + match = reNumber.match( lastAddedGroupName ); + if ( match.hasMatch() ) + { + int number = match.capturedTexts().first().toInt(); + lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() ) + QString( number + 1 ); + } + } + else + { + lastAddedGroupName = lastAddedGroupName.append( "_1" );; + } + } + MDAL_G_setName( datasetGroupH, lastAddedGroupName.toStdString().c_str() ); + } +} + bool QgsMdalProvider::removeDatasetGroup( const int &index ) { if ( index < 0 && index > datasetGroupCount() - 1 ) diff --git a/src/providers/mdal/qgsmdalprovider.h b/src/providers/mdal/qgsmdalprovider.h index 64db515c1df7..78c37a22c67d 100644 --- a/src/providers/mdal/qgsmdalprovider.h +++ b/src/providers/mdal/qgsmdalprovider.h @@ -130,6 +130,9 @@ class QgsMdalProvider : public QgsMeshDataProvider QVector faces( ) const; void loadData(); void addGroupToTemporalCapabilities( int indexGroup ); + + void makeLastDatasetGroupNameUnique(); + MDAL_MeshH mMeshH = nullptr; QStringList mExtraDatasetUris; QgsCoordinateReferenceSystem mCrs; From 8ec69078f5ab50d0afb06a7126b89839fe000743 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:39:00 +0100 Subject: [PATCH 03/35] fix typo --- src/core/mesh/qgsmeshlayer.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index bb9c0ab395bf..3b7719e4a229 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -203,7 +203,7 @@ 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 * @@ -1006,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 From 026fc1e27b3d47f265db9df356f0a608e25a06be Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:42:31 +0100 Subject: [PATCH 04/35] add mesh removing to the widget --- .../mesh/qgsmeshdatasetgrouptreewidget.cpp | 36 +++++++++++++++++++ src/gui/mesh/qgsmeshdatasetgrouptreewidget.h | 1 + .../mesh/qgsmeshdatasetgrouptreewidgetbase.ui | 14 ++++++++ 3 files changed, 51 insertions(+) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index 41a133628dc5..62aa3dc25831 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -34,6 +34,7 @@ QgsMeshDatasetGroupTreeWidget::QgsMeshDatasetGroupTreeWidget( QWidget *parent ): setupUi( this ); connect( mAddDatasetButton, &QToolButton::clicked, this, &QgsMeshDatasetGroupTreeWidget::addDataset ); + connect( mRemoveDatasetButton, &QToolButton::clicked, this, &QgsMeshDatasetGroupTreeWidget::removeDataset ); connect( mCollapseButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::collapseAll ); connect( mExpandButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::expandAll ); connect( mCheckAllButton, &QToolButton::clicked, mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::selectAllGroups ); @@ -43,6 +44,23 @@ QgsMeshDatasetGroupTreeWidget::QgsMeshDatasetGroupTreeWidget( QWidget *parent ): this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer ); } ); + connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() + { + QModelIndex index = mDatasetGroupTreeView->currentIndex(); + QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() ); + if ( meshGroupItem ) + { + if ( mMeshLayer->dataProvider()->dataSourceUri().contains( meshGroupItem->description() ) ) + { + mRemoveDatasetButton->setEnabled( false ); + } + else + { + mRemoveDatasetButton->setEnabled( true ); + } + } + } ); + connect( mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::apply, this, &QgsMeshDatasetGroupTreeWidget::apply ); } @@ -58,6 +76,24 @@ void QgsMeshDatasetGroupTreeWidget::apply() mMeshLayer->setDatasetGroupTreeRootItem( mDatasetGroupTreeView->datasetGroupTreeRootItem() ); } +void QgsMeshDatasetGroupTreeWidget::removeDataset() +{ + QModelIndex index = mDatasetGroupTreeView->currentIndex(); + QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->child( index.row() ); + QString datasetGroupName = meshGroupItem->defaultName(); + if ( mMeshLayer->removeDatasets( datasetGroupName ) ) + { + QMessageBox::warning( this, tr( "Remove mesh datasets" ), tr( "Dataset Group removed from mesh." ) ); + emit datasetGroupAdded(); + } + else + { + QMessageBox::warning( this, tr( "Remove mesh datasets" ), tr( "Could not remove mesh dataset group." ) ); + } + + mDatasetGroupTreeView->resetDefault( mMeshLayer ); +} + void QgsMeshDatasetGroupTreeWidget::addDataset() { if ( !mMeshLayer->dataProvider() ) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h index 567d3cc3c3e4..0d7a44d00503 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h @@ -48,6 +48,7 @@ class GUI_EXPORT QgsMeshDatasetGroupTreeWidget: public QWidget, private Ui::QgsM private slots: void addDataset(); + void removeDataset(); private: QgsMeshLayer *mMeshLayer; diff --git a/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui b/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui index 6035f2c27833..d631191d22f2 100644 --- a/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui +++ b/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui @@ -66,6 +66,20 @@ + + + + false + + + ... + + + + :/images/themes/default/symbologyRemove.svg:/images/themes/default/symbologyRemove.svg + + + From b94696f567db7cb51e8b2694c72a5563fefd1bc3 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:42:45 +0100 Subject: [PATCH 05/35] fix icon --- src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui b/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui index d631191d22f2..af99612eb5fe 100644 --- a/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui +++ b/src/ui/mesh/qgsmeshdatasetgrouptreewidgetbase.ui @@ -53,7 +53,7 @@ - :/images/themes/default/mActionAdd.svg:/images/themes/default/mActionAdd.svg + :/images/themes/default/symbologyAdd.svg:/images/themes/default/symbologyAdd.svg From 86abd2534993782de907a3c3e0cd53680c7bd1a0 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:43:30 +0100 Subject: [PATCH 06/35] add check that added dataset group path is unique to avoid duplicate data and emit message if it is not --- src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index 62aa3dc25831..913e61a04819 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -111,6 +111,12 @@ void QgsMeshDatasetGroupTreeWidget::addDataset() return; // canceled by the user } + if ( !mMeshLayer->datasetsPathUnique( openFileString ) ) + { + QMessageBox::warning( this, tr( "Load mesh datasets" ), tr( "Could not add dataset from path that is already added to the mesh." ) ); + return; + } + const QFileInfo openFileInfo( openFileString ); settings.setValue( QStringLiteral( "lastMeshDatasetDir" ), openFileInfo.absolutePath(), QgsSettings::App ); const QFile datasetFile( openFileString ); From 2b1724206150438aabfaa56a16c474d2c7742134 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 15:43:47 +0100 Subject: [PATCH 07/35] sipify --- .../mesh/qgsmeshdataprovider.sip.in | 11 +++++++++ .../auto_generated/mesh/qgsmeshlayer.sip.in | 23 ++++++++++++++++++- .../mesh/qgsmeshdataprovider.sip.in | 11 +++++++++ .../auto_generated/mesh/qgsmeshlayer.sip.in | 23 ++++++++++++++++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in index 4a22ff18ee99..d8fb90b6ed74 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in @@ -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( const int &index ) = 0; +%Docstring +Remove dataset group from the mesh + +emits dataChanged when successful + +:return: True on success + +.. versionadded:: 3.42 %End signals: diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in index b6cb23c2e7f0..623f5c811028 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -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: of dataset group to remove + +:return: whether the dataset is added + +.. versionadded:: 3.42 %End bool addDatasets( QgsMeshDatasetGroup *datasetGroup /Transfer/ ); @@ -905,6 +916,16 @@ Sets labeling configuration. Takes ownership of the object. .. versionadded:: 3.36 %End + bool datasetsPathUnique( const QString &path ); +%Docstring +Checks that datasets path is already added to this mesh layer. Return true if the +dataset path is unique. + +:param path: the path to the datasets file + @return whether the datasets path is unique + +.. versionadded:: 3.42 +%End public slots: diff --git a/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in b/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in index f68ef0484ae1..b1e7b09f7f0c 100644 --- a/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in @@ -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( const int &index ) = 0; +%Docstring +Remove dataset group from the mesh + +emits dataChanged when successful + +:return: True on success + +.. versionadded:: 3.42 %End signals: diff --git a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in index b6cb23c2e7f0..623f5c811028 100644 --- a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -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: of dataset group to remove + +:return: whether the dataset is added + +.. versionadded:: 3.42 %End bool addDatasets( QgsMeshDatasetGroup *datasetGroup /Transfer/ ); @@ -905,6 +916,16 @@ Sets labeling configuration. Takes ownership of the object. .. versionadded:: 3.36 %End + bool datasetsPathUnique( const QString &path ); +%Docstring +Checks that datasets path is already added to this mesh layer. Return true if the +dataset path is unique. + +:param path: the path to the datasets file + @return whether the datasets path is unique + +.. versionadded:: 3.42 +%End public slots: From 173e2fa631a8b587ca5ef67f3ee4b566aab31238 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 17:03:34 +0100 Subject: [PATCH 08/35] fix mistake --- src/providers/mdal/qgsmdalprovider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index d1a94480ce97..21723e8eb41d 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -678,7 +678,7 @@ void QgsMdalProvider::fileMeshExtensions( QStringList &fileMeshExtensions, bool QgsMdalProvider::addDataset( const QString &uri ) { - if ( mExtraDatasetUris.contains( uri ) && dataSourceUri().contains( uri ) ) + if ( mExtraDatasetUris.contains( uri ) || dataSourceUri().contains( uri ) ) return false; int datasetCount = datasetGroupCount(); From 55ce9247555f1b7b54a47e96558cee4c7705bd07 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 17:06:42 +0100 Subject: [PATCH 09/35] check if uri is correct - just for case --- src/providers/mdal/qgsmdalprovider.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index 21723e8eb41d..1764f8c54a9c 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -755,9 +755,12 @@ bool QgsMdalProvider::removeDatasetGroup( const int &index ) { QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index ); - if ( mExtraDatasetUris.contains( datasetGroupMeta.uri() ) ) - mExtraDatasetUris.removeOne( datasetGroupMeta.uri() ); + if ( !mExtraDatasetUris.contains( datasetGroupMeta.uri() ) ) + { + return false; + } + mExtraDatasetUris.removeOne( datasetGroupMeta.uri() ); MDAL_M_RemoveDatasetGroup( mMeshH, index ); emit dataChanged(); return true; From ded8cf72d4a24207dbc4ed72423bd12efa0ddfd4 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 17:07:00 +0100 Subject: [PATCH 10/35] add tests --- tests/src/providers/testqgsmdalprovider.cpp | 114 ++++++++++++++++++ ...d_triangle_vertex_vector_existing_name.dat | 21 ++++ 2 files changed, 135 insertions(+) create mode 100644 tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat diff --git a/tests/src/providers/testqgsmdalprovider.cpp b/tests/src/providers/testqgsmdalprovider.cpp index 359d01eeaaa4..9d7ae6604f3a 100644 --- a/tests/src/providers/testqgsmdalprovider.cpp +++ b/tests/src/providers/testqgsmdalprovider.cpp @@ -52,6 +52,8 @@ class TestQgsMdalProvider : public QgsTest void encodeDecodeUri(); void absoluteRelativeUri(); void preserveMeshMetadata(); + void uniqueDatasetNames(); + void addRemoveDatasetGroups(); private: QString mTestDataDir; @@ -207,5 +209,117 @@ void TestQgsMdalProvider::preserveMeshMetadata() delete mesh; } + +void TestQgsMdalProvider::uniqueDatasetNames() +{ + const QString file = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle.2dm" ); + QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( + QStringLiteral( "mdal" ), + file, + QgsDataProvider::ProviderOptions() + ); + + QgsMeshDataProvider *mp = dynamic_cast< QgsMeshDataProvider * >( provider ); + + QgsDataProvider *provider1 = QgsProviderRegistry::instance()->createProvider( + QStringLiteral( "mdal" ), + file, + QgsDataProvider::ProviderOptions() + ); + QgsMeshDataProvider *mp1 = dynamic_cast< QgsMeshDataProvider * >( provider1 ); + + // these two dataset files have the same name + const QString fileDatasetGroup1 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector.dat" ); + const QString fileDatasetGroup2 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector_existing_name.dat" ); + + // test that if added to different provider they have same names + QVERIFY( mp->addDataset( fileDatasetGroup1 ) ); + QCOMPARE( mp->datasetGroupCount(), 2 ); + + QgsMeshDatasetGroupMetadata metadata = mp->datasetGroupMetadata( 1 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); + + QVERIFY( mp1->addDataset( fileDatasetGroup2 ) ); + QCOMPARE( mp1->datasetGroupCount(), 2 ); + + metadata = mp1->datasetGroupMetadata( 1 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); + + QCOMPARE( mp1->datasetGroupMetadata( 1 ).name(), mp->datasetGroupMetadata( 1 ).name() ); + + //test that if both additional files are added to the same provider, the names will be unique + QVERIFY( mp->addDataset( fileDatasetGroup2 ) ); + QCOMPARE( mp->datasetGroupCount(), 3 ); + + metadata = mp->datasetGroupMetadata( 1 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); + metadata = mp->datasetGroupMetadata( 2 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset_1" ) ); + + delete provider; + delete provider1; +} + +void TestQgsMdalProvider::addRemoveDatasetGroups() +{ + const QString file = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle.2dm" ); + QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( + QStringLiteral( "mdal" ), + file, + QgsDataProvider::ProviderOptions() + ); + + QgsMeshDataProvider *mp = dynamic_cast< QgsMeshDataProvider * >( provider ); + QVERIFY( mp ); + QVERIFY( mp->isValid() ); + QCOMPARE( mp->datasetGroupCount(), 1 ); + + const QString fileDatasetGroup1 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector.dat" ); + QVERIFY( mp->addDataset( fileDatasetGroup1 ) ); + QCOMPARE( mp->datasetGroupCount(), 2 ); + + // cannot add the same dataset twice + QCOMPARE( mp->addDataset( fileDatasetGroup1 ), false ); + + const QString fileDatasetGroup2 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_scalar2.dat" ); + QVERIFY( mp->addDataset( fileDatasetGroup2 ) ); + QCOMPARE( mp->datasetGroupCount(), 3 ); + + QgsMeshDatasetGroupMetadata metadata = mp->datasetGroupMetadata( 0 ); + QCOMPARE( metadata.name(), QStringLiteral( "Bed Elevation" ) ); + + metadata = mp->datasetGroupMetadata( 1 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); + + metadata = mp->datasetGroupMetadata( 2 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexScalarDataset2" ) ); + + // cannot remove dataset groups with index outside of range + QCOMPARE( mp->removeDatasetGroup( -1 ), false ); + QCOMPARE( mp->removeDatasetGroup( 10 ), false ); + + // cannot remove data associated with source file + QCOMPARE( mp->removeDatasetGroup( 0 ), false ); + + // can remove other datasets group + QCOMPARE( mp->removeDatasetGroup( 1 ), true ); + + // check the dataset group that are left + QCOMPARE( mp->datasetGroupCount(), 2 ); + metadata = mp->datasetGroupMetadata( 0 ); + QCOMPARE( metadata.name(), QStringLiteral( "Bed Elevation" ) ); + metadata = mp->datasetGroupMetadata( 1 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexScalarDataset2" ) ); + + // remove the second - only the original remains + QCOMPARE( mp->removeDatasetGroup( 1 ), true ); + + // check the dataset group that are left + QCOMPARE( mp->datasetGroupCount(), 1 ); + metadata = mp->datasetGroupMetadata( 0 ); + QCOMPARE( metadata.name(), QStringLiteral( "Bed Elevation" ) ); + + delete provider; +} QGSTEST_MAIN( TestQgsMdalProvider ) #include "testqgsmdalprovider.moc" diff --git a/tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat b/tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat new file mode 100644 index 000000000000..927e6775883d --- /dev/null +++ b/tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat @@ -0,0 +1,21 @@ +DATASET +OBJTYPE "mesh2d" +RT_JULIAN 2433282.500000 +BEGVEC +ND 5 +NC 2 +NAME "VertexVectorDataset" +TIMEUNITS se +TS 0 0.000000 +1 1 +2 1 +3 2 +2 2 +1 -2 +TS 0 3600.000000 +2 2 +3 2 +4 3 +3 3 +2 -1 +ENDDS From 43f1474bd8bca3581c1ac93fd83b2869b7156f7a Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Fri, 8 Nov 2024 17:19:32 +0100 Subject: [PATCH 11/35] add tests --- tests/src/core/testqgsmeshlayer.cpp | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/src/core/testqgsmeshlayer.cpp b/tests/src/core/testqgsmeshlayer.cpp index eb9fd0fb45df..74e46def2e3d 100644 --- a/tests/src/core/testqgsmeshlayer.cpp +++ b/tests/src/core/testqgsmeshlayer.cpp @@ -107,6 +107,8 @@ class TestQgsMeshLayer : public QgsTest void testSelectByExpression(); void testSetDataSourceRetainStyle(); + void testRemoveDatasets(); + void testDatasetsUniquePath(); void keepDatasetIndexConsistency(); void symbologyConsistencyWithName(); @@ -2366,5 +2368,46 @@ void TestQgsMeshLayer::testHaveSameParentQuantity() QVERIFY( !QgsMeshLayerUtils::haveSameParentQuantity( &layer2, QgsMeshDatasetIndex( 0 ), QgsMeshDatasetIndex( 1 ) ) ); } + +void TestQgsMeshLayer::testDatasetsUniquePath() +{ + QgsMeshLayer layer( + testDataPath( "mesh/quad_and_triangle.2dm" ), + QStringLiteral( "mesh" ), + QStringLiteral( "mdal" ) ); + QVERIFY( layer.isValid() ); + + QString path = testDataPath( "/mesh/quad_and_triangle_vertex_vector.dat" ); + + // is unique + QVERIFY( layer.datasetsPathUnique( path ) ); + + // add dataset group + QVERIFY( layer.addDatasets( path ) ); + + // no longer unique - already exist + QCOMPARE( layer.datasetsPathUnique( path ), false ); +} + +void TestQgsMeshLayer::testRemoveDatasets() +{ + QgsMeshLayer layer( + testDataPath( "mesh/quad_and_triangle.2dm" ), + QStringLiteral( "mesh" ), + QStringLiteral( "mdal" ) ); + QVERIFY( layer.isValid() ); + + // add datasets with same name + QVERIFY( layer.addDatasets( testDataPath( "/mesh/quad_and_triangle_vertex_vector.dat" ) ) ); + QVERIFY( layer.addDatasets( testDataPath( "/mesh/quad_and_triangle_vertex_vector_existing_name.dat" ) ) ); + + // can remove but the second has added "_1" + QVERIFY( layer.removeDatasets( "VertexVectorDataset" ) ); + QVERIFY( layer.removeDatasets( "VertexVectorDataset_1" ) ); + + // cannot remove by name - does not exist + QCOMPARE( layer.removeDatasets( "Non Existing Dataset Group" ), false ); +} + QGSTEST_MAIN( TestQgsMeshLayer ) #include "testqgsmeshlayer.moc" From 7127e9acd27101f93116d1bb020af4dd7177cd53 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 9 Nov 2024 18:19:27 +0100 Subject: [PATCH 12/35] fix docstring --- python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in | 3 ++- python/core/auto_generated/mesh/qgsmeshlayer.sip.in | 3 ++- src/core/mesh/qgsmeshlayer.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in index 623f5c811028..e4b61363f682 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -922,7 +922,8 @@ Checks that datasets path is already added to this mesh layer. Return true if th dataset path is unique. :param path: the path to the datasets file - @return whether the datasets path is unique + +:return: whether the datasets path is unique .. versionadded:: 3.42 %End diff --git a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in index 623f5c811028..e4b61363f682 100644 --- a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -922,7 +922,8 @@ Checks that datasets path is already added to this mesh layer. Return true if th dataset path is unique. :param path: the path to the datasets file - @return whether the datasets path is unique + +:return: whether the datasets path is unique .. versionadded:: 3.42 %End diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index 3b7719e4a229..28c1179ebe33 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -947,7 +947,7 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo * dataset path is unique. * * \param path the path to the datasets file - * @return whether the datasets path is unique + * \return whether the datasets path is unique * * \since QGIS 3.42 */ From e7b8fa8acca8b7df79fca9ee65e13240f4790eb4 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 9 Nov 2024 18:19:49 +0100 Subject: [PATCH 13/35] add docstring --- src/core/mesh/qgsmeshdatasetgroupstore.cpp | 6 +++--- src/core/mesh/qgsmeshdatasetgroupstore.h | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.cpp b/src/core/mesh/qgsmeshdatasetgroupstore.cpp index d36f5acbbc98..4b96ce59fba3 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.cpp +++ b/src/core/mesh/qgsmeshdatasetgroupstore.cpp @@ -733,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(); diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.h b/src/core/mesh/qgsmeshdatasetgroupstore.h index 963ea0ce68d2..61f7f67d6943 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.h +++ b/src/core/mesh/qgsmeshdatasetgroupstore.h @@ -241,7 +241,12 @@ class QgsMeshDatasetGroupStore: public QObject */ QString groupName( int groupIndex ) const; - void removeDatasetGroup( int index ); + /** + * Removes dataset group with global index \a groupIndex + * + * \since QGIS 3.42 + */ + void removeDatasetGroup( int groupIndex ); signals: //! Emitted after dataset groups are added From 89c25f1a15483513827e01c9f5d38dc44b4f6af0 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 9 Nov 2024 18:34:06 +0100 Subject: [PATCH 14/35] add missing override --- src/core/providers/meshmemory/qgsmeshmemorydataprovider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h index ac456a8d21f7..3fc1a3fcaf0f 100644 --- a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h +++ b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h @@ -128,7 +128,7 @@ class CORE_EXPORT QgsMeshMemoryDataProvider final: public QgsMeshDataProvider */ bool addDataset( const QString &uri ) override; - bool removeDatasetGroup( const int &index ); + bool removeDatasetGroup( const int &index ) override; QStringList extraDatasets() const override; int datasetGroupCount() const override; From 3d10a38582f949af402945a8c8be4921006fbe12 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sun, 10 Nov 2024 09:15:18 +0100 Subject: [PATCH 15/35] explicitly convert number to string --- src/providers/mdal/qgsmdalprovider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index 1764f8c54a9c..20ac9bce85a0 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -733,7 +733,7 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() if ( match.hasMatch() ) { int number = match.capturedTexts().first().toInt(); - lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() ) + QString( number + 1 ); + lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() ) + QString::number( number + 1 ); } } else From 06cc58c048d8d095a154205203ee959b71add7c7 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sun, 10 Nov 2024 09:18:15 +0100 Subject: [PATCH 16/35] update tests to reflect that you cannot add same file as dataset group twice --- tests/src/core/testqgsmeshlayer.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/src/core/testqgsmeshlayer.cpp b/tests/src/core/testqgsmeshlayer.cpp index 74e46def2e3d..1b02d9b6dd96 100644 --- a/tests/src/core/testqgsmeshlayer.cpp +++ b/tests/src/core/testqgsmeshlayer.cpp @@ -1227,12 +1227,8 @@ void TestQgsMeshLayer::test_reload_extra_dataset() QCOMPARE( layer.datasetGroupCount(), 2 ); QCOMPARE( layer.datasetGroupTreeRootItem()->childCount(), 2 ); - // Add twice the same file - QVERIFY( layer.addDatasets( testFileDataSet.fileName() ) ); //dataset added - QCOMPARE( layer.dataProvider()->extraDatasets().count(), 1 ); //uri not dupplicated - QCOMPARE( layer.dataProvider()->datasetGroupCount(), 3 ); //dataset added - QCOMPARE( layer.datasetGroupCount(), 2 ); // meshLayer do not allow dataset group with same name - QCOMPARE( layer.datasetGroupTreeRootItem()->childCount(), 2 ); + // Add twice the same file - not allow since 3.42 + QCOMPARE( layer.addDatasets( testFileDataSet.fileName() ), false ); //dataset added indexes = layer.datasetGroupsIndexes(); for ( int index : std::as_const( indexes ) ) @@ -1244,7 +1240,7 @@ void TestQgsMeshLayer::test_reload_extra_dataset() QVERIFY( layer.addDatasets( testFileDataSet_3.fileName() ) ); QCOMPARE( layer.dataProvider()->extraDatasets().count(), 2 ); - QCOMPARE( layer.dataProvider()->datasetGroupCount(), 4 ); + QCOMPARE( layer.dataProvider()->datasetGroupCount(), 3 ); QCOMPARE( layer.datasetGroupCount(), 3 ); QCOMPARE( layer.datasetGroupTreeRootItem()->childCount(), 3 ); From 35d9b221724294cec0aaf0e9369a5734de0d7131 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 18:54:22 +0100 Subject: [PATCH 17/35] fix docstring --- src/core/mesh/qgsmeshdataprovider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/mesh/qgsmeshdataprovider.h b/src/core/mesh/qgsmeshdataprovider.h index d19c0570ecda..eff374846f53 100644 --- a/src/core/mesh/qgsmeshdataprovider.h +++ b/src/core/mesh/qgsmeshdataprovider.h @@ -480,7 +480,7 @@ class CORE_EXPORT QgsMeshDataProvider: public QgsDataProvider, public QgsMeshDat * * emits dataChanged when successful * - * \return True on success + * \return TRUE on success * * \since QGIS 3.42 */ From 207d36a9eae869ecf633ec9e15c272637f8e74ae Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 18:58:30 +0100 Subject: [PATCH 18/35] pass by value --- src/core/mesh/qgsmeshdataprovider.h | 2 +- src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp | 2 +- src/core/providers/meshmemory/qgsmeshmemorydataprovider.h | 2 +- src/providers/mdal/qgsmdalprovider.cpp | 2 +- src/providers/mdal/qgsmdalprovider.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/mesh/qgsmeshdataprovider.h b/src/core/mesh/qgsmeshdataprovider.h index eff374846f53..c00c2a27bb5f 100644 --- a/src/core/mesh/qgsmeshdataprovider.h +++ b/src/core/mesh/qgsmeshdataprovider.h @@ -484,7 +484,7 @@ class CORE_EXPORT QgsMeshDataProvider: public QgsDataProvider, public QgsMeshDat * * \since QGIS 3.42 */ - virtual bool removeDatasetGroup( const int &index ) = 0; + virtual bool removeDatasetGroup( int index ) = 0; signals: //! Emitted when some new dataset groups have been added diff --git a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp index f190fa5ae718..9e9d99950a8a 100644 --- a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp +++ b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp @@ -430,7 +430,7 @@ bool QgsMeshMemoryDataProvider::addDataset( const QString &uri ) return valid; } -bool QgsMeshMemoryDataProvider::removeDatasetGroup( const int &index ) +bool QgsMeshMemoryDataProvider::removeDatasetGroup( int index ) { if ( index < 0 && index > datasetGroupCount() - 1 ) { diff --git a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h index 3fc1a3fcaf0f..5c28f60cf081 100644 --- a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h +++ b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.h @@ -128,7 +128,7 @@ class CORE_EXPORT QgsMeshMemoryDataProvider final: public QgsMeshDataProvider */ bool addDataset( const QString &uri ) override; - bool removeDatasetGroup( const int &index ) override; + bool removeDatasetGroup( int index ) override; QStringList extraDatasets() const override; int datasetGroupCount() const override; diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index 20ac9bce85a0..d47964440eb9 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -745,7 +745,7 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() } } -bool QgsMdalProvider::removeDatasetGroup( const int &index ) +bool QgsMdalProvider::removeDatasetGroup( int index ) { if ( index < 0 && index > datasetGroupCount() - 1 ) { diff --git a/src/providers/mdal/qgsmdalprovider.h b/src/providers/mdal/qgsmdalprovider.h index 78c37a22c67d..70e5158bff1c 100644 --- a/src/providers/mdal/qgsmdalprovider.h +++ b/src/providers/mdal/qgsmdalprovider.h @@ -64,7 +64,7 @@ class QgsMdalProvider : public QgsMeshDataProvider bool addDataset( const QString &uri ) override; - bool removeDatasetGroup( const int &index ) override; + bool removeDatasetGroup( int index ) override; QStringList extraDatasets() const override; From bc36e88a4926b39bd004a3b2fe68e4e928b78a56 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 18:59:49 +0100 Subject: [PATCH 19/35] fix docstrings --- src/core/mesh/qgsmeshdatasetgroupstore.h | 1 + src/core/mesh/qgsmeshlayer.h | 6 +++--- src/providers/mdal/qgsmdalprovider.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.h b/src/core/mesh/qgsmeshdatasetgroupstore.h index 61f7f67d6943..2f58321cfa86 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.h +++ b/src/core/mesh/qgsmeshdatasetgroupstore.h @@ -266,6 +266,7 @@ 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(); DatasetGroup datasetGroup( int index ) const; diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index 28c1179ebe33..478a079553ee 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -215,7 +215,7 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo * Removes datasets from the mesh with given \a name. * * \param name of dataset group to remove - * \return whether the dataset is added + * \return whether the dataset is removed * * \since QGIS 3.42 */ @@ -943,8 +943,8 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo void setLabeling( QgsAbstractMeshLayerLabeling *labeling SIP_TRANSFER ); /** - * Checks that datasets path is already added to this mesh layer. Return true if the - * dataset path is unique. + * 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 diff --git a/src/providers/mdal/qgsmdalprovider.h b/src/providers/mdal/qgsmdalprovider.h index 70e5158bff1c..c6afa483c487 100644 --- a/src/providers/mdal/qgsmdalprovider.h +++ b/src/providers/mdal/qgsmdalprovider.h @@ -131,6 +131,7 @@ class QgsMdalProvider : public QgsMeshDataProvider void loadData(); void addGroupToTemporalCapabilities( int indexGroup ); + // ensures that last added dataset group has unique name (adds suffix of underscore and number to make it unique) void makeLastDatasetGroupNameUnique(); MDAL_MeshH mMeshH = nullptr; From 96ac70bd094f64b8061d1daed623a15b578f3926 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 19:00:53 +0100 Subject: [PATCH 20/35] const variables --- src/core/mesh/qgsmeshdatasetgroupstore.cpp | 2 +- src/core/mesh/qgsmeshlayer.cpp | 4 ++-- src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.cpp b/src/core/mesh/qgsmeshdatasetgroupstore.cpp index 4b96ce59fba3..e5a6ed0b7955 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.cpp +++ b/src/core/mesh/qgsmeshdatasetgroupstore.cpp @@ -127,7 +127,7 @@ bool QgsMeshDatasetGroupStore::addDatasetGroup( QgsMeshDatasetGroup *group ) void QgsMeshDatasetGroupStore::removeDatasetGroup( int index ) { - QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index ); + const QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index ); if ( group.first == mPersistentProvider ) mPersistentProvider->removeDatasetGroup( group.second ); else if ( group.first == &mExtraDatasets ) diff --git a/src/core/mesh/qgsmeshlayer.cpp b/src/core/mesh/qgsmeshlayer.cpp index 8df688ef4f03..6e770e48b42c 100644 --- a/src/core/mesh/qgsmeshlayer.cpp +++ b/src/core/mesh/qgsmeshlayer.cpp @@ -255,14 +255,14 @@ QString QgsMeshLayer::loadDefaultStyle( bool &resultFlag ) bool QgsMeshLayer::removeDatasets( const QString &name ) { - int index = mDatasetGroupStore->indexFromGroupName( name ); + const int index = mDatasetGroupStore->indexFromGroupName( name ); if ( index == -1 ) { return false; } - QgsMeshDatasetGroupMetadata groupMetadata = datasetGroupMetadata( index ); + const QgsMeshDatasetGroupMetadata groupMetadata = datasetGroupMetadata( index ); mDatasetGroupStore->removeDatasetGroup( index ); diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index 913e61a04819..860d435586e5 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -78,9 +78,9 @@ void QgsMeshDatasetGroupTreeWidget::apply() void QgsMeshDatasetGroupTreeWidget::removeDataset() { - QModelIndex index = mDatasetGroupTreeView->currentIndex(); - QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->child( index.row() ); - QString datasetGroupName = meshGroupItem->defaultName(); + const QModelIndex index = mDatasetGroupTreeView->currentIndex(); + const QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->child( index.row() ); + const QString datasetGroupName = meshGroupItem->defaultName(); if ( mMeshLayer->removeDatasets( datasetGroupName ) ) { QMessageBox::warning( this, tr( "Remove mesh datasets" ), tr( "Dataset Group removed from mesh." ) ); From 104edef9f2b00ee399b49e4c7f7c4e820d691685 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 19:01:28 +0100 Subject: [PATCH 21/35] rename signal --- src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp | 4 ++-- src/gui/mesh/qgsmeshdatasetgrouptreewidget.h | 2 +- src/gui/mesh/qgsmeshlayerproperties.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index 860d435586e5..77f700062e35 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -84,7 +84,7 @@ void QgsMeshDatasetGroupTreeWidget::removeDataset() if ( mMeshLayer->removeDatasets( datasetGroupName ) ) { QMessageBox::warning( this, tr( "Remove mesh datasets" ), tr( "Dataset Group removed from mesh." ) ); - emit datasetGroupAdded(); + emit datasetGroupsChanged(); } else { @@ -124,7 +124,7 @@ void QgsMeshDatasetGroupTreeWidget::addDataset() if ( mMeshLayer->addDatasets( openFileString, QgsProject::instance()->timeSettings()->temporalRange().begin() ) ) { QMessageBox::information( this, tr( "Load mesh datasets" ), tr( "Datasets successfully added to the mesh layer" ) ); - emit datasetGroupAdded(); + emit datasetGroupsChanged(); } else { diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h index 0d7a44d00503..3e4d7e889a68 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h @@ -44,7 +44,7 @@ class GUI_EXPORT QgsMeshDatasetGroupTreeWidget: public QWidget, private Ui::QgsM void apply(); signals: - void datasetGroupAdded(); + void datasetGroupsChanged(); private slots: void addDataset(); diff --git a/src/gui/mesh/qgsmeshlayerproperties.cpp b/src/gui/mesh/qgsmeshlayerproperties.cpp index c64c6da31432..19f746a45e2e 100644 --- a/src/gui/mesh/qgsmeshlayerproperties.cpp +++ b/src/gui/mesh/qgsmeshlayerproperties.cpp @@ -63,7 +63,7 @@ QgsMeshLayerProperties::QgsMeshLayerProperties( QgsMapLayer *lyr, QgsMapCanvas * mTemporalProviderTimeUnitComboBox->addItem( tr( "Days" ), static_cast< int >( Qgis::TemporalUnit::Days ) ); connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsMeshLayerProperties::changeCrs ); - connect( mDatasetGroupTreeWidget, &QgsMeshDatasetGroupTreeWidget::datasetGroupAdded, this, &QgsMeshLayerProperties::syncToLayer ); + connect( mDatasetGroupTreeWidget, &QgsMeshDatasetGroupTreeWidget::datasetGroupsChanged, this, &QgsMeshLayerProperties::syncToLayer ); // QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states, // switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left), From 7affb05c250c7046a64ee10f71414fffc185083e Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 19:02:01 +0100 Subject: [PATCH 22/35] drop include --- src/providers/mdal/qgsmdalprovider.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index d47964440eb9..973cb4302331 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -30,7 +30,6 @@ #include #include #include -#include const QString QgsMdalProvider::MDAL_PROVIDER_KEY = QStringLiteral( "mdal" ); const QString QgsMdalProvider::MDAL_PROVIDER_DESCRIPTION = QStringLiteral( "MDAL provider" ); From 5b60fc19701de58c86038933f5e849cd837e9c21 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 22:58:19 +0100 Subject: [PATCH 23/35] simplify regex --- src/providers/mdal/qgsmdalprovider.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index 973cb4302331..b8e1796a0dbf 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -720,20 +720,16 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() if ( existingNames.contains( lastAddedGroupName ) ) { - QRegularExpression reEndsNumber( "_[0-9]+$" ); - QRegularExpression reNumber( "[0-9]+$" ); + const thread_local QRegularExpression reEndsNumber( "_([0-9]+)$" ); QRegularExpressionMatch match; while ( existingNames.find( lastAddedGroupName ) != existingNames.end() ) { - if ( reEndsNumber.match( lastAddedGroupName ).hasMatch() ) + match = reEndsNumber.match(lastAddedGroupName); + if ( match.hasMatch() ) { - match = reNumber.match( lastAddedGroupName ); - if ( match.hasMatch() ) - { - int number = match.capturedTexts().first().toInt(); - lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() ) + QString::number( number + 1 ); - } + const int number = match.capturedTexts().last().toInt(); + lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() + 1 ) + QString::number( number + 1 ); } else { @@ -752,7 +748,7 @@ bool QgsMdalProvider::removeDatasetGroup( int index ) } else { - QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index ); + const QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index ); if ( !mExtraDatasetUris.contains( datasetGroupMeta.uri() ) ) { From f92c37370dc7cdbfa0782ab67d66bf30b1814a67 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 23:01:48 +0100 Subject: [PATCH 24/35] make test better --- tests/src/providers/testqgsmdalprovider.cpp | 16 ++++++++++++-- ...d_triangle_vertex_vector_existing_name.dat | 21 ------------------- 2 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat diff --git a/tests/src/providers/testqgsmdalprovider.cpp b/tests/src/providers/testqgsmdalprovider.cpp index 9d7ae6604f3a..6bff867d7b74 100644 --- a/tests/src/providers/testqgsmdalprovider.cpp +++ b/tests/src/providers/testqgsmdalprovider.cpp @@ -228,9 +228,16 @@ void TestQgsMdalProvider::uniqueDatasetNames() ); QgsMeshDataProvider *mp1 = dynamic_cast< QgsMeshDataProvider * >( provider1 ); - // these two dataset files have the same name + // these three dataset files have the same name const QString fileDatasetGroup1 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector.dat" ); - const QString fileDatasetGroup2 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector_existing_name.dat" ); + const QString fileDatasetGroup2 = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector.dat" ); + const QString fileDatasetGroup3 = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector.dat" ); + + QFile::remove( fileDatasetGroup2 ); + QVERIFY( QFile::copy( fileDatasetGroup1, fileDatasetGroup2 ) ); + + QFile::remove( fileDatasetGroup3 ); + QVERIFY( QFile::copy( fileDatasetGroup1, fileDatasetGroup3 ) ); // test that if added to different provider they have same names QVERIFY( mp->addDataset( fileDatasetGroup1 ) ); @@ -251,10 +258,15 @@ void TestQgsMdalProvider::uniqueDatasetNames() QVERIFY( mp->addDataset( fileDatasetGroup2 ) ); QCOMPARE( mp->datasetGroupCount(), 3 ); + QVERIFY( mp->addDataset( fileDatasetGroup3 ) ); + QCOMPARE( mp->datasetGroupCount(), 4 ); + metadata = mp->datasetGroupMetadata( 1 ); QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); metadata = mp->datasetGroupMetadata( 2 ); QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset_1" ) ); + metadata = mp->datasetGroupMetadata( 3 ); + QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset_2" ) ); delete provider; delete provider1; diff --git a/tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat b/tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat deleted file mode 100644 index 927e6775883d..000000000000 --- a/tests/testdata/mesh/quad_and_triangle_vertex_vector_existing_name.dat +++ /dev/null @@ -1,21 +0,0 @@ -DATASET -OBJTYPE "mesh2d" -RT_JULIAN 2433282.500000 -BEGVEC -ND 5 -NC 2 -NAME "VertexVectorDataset" -TIMEUNITS se -TS 0 0.000000 -1 1 -2 1 -3 2 -2 2 -1 -2 -TS 0 3600.000000 -2 2 -3 2 -4 3 -3 3 -2 -1 -ENDDS From 27ad6dde6bd0450ba23706d254f7213cb77815b9 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 23:03:03 +0100 Subject: [PATCH 25/35] sipify --- .../core/auto_generated/mesh/qgsmeshdataprovider.sip.in | 4 ++-- python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in | 6 +++--- python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in | 4 ++-- python/core/auto_generated/mesh/qgsmeshlayer.sip.in | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in index d8fb90b6ed74..81d06988f17b 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshdataprovider.sip.in @@ -467,13 +467,13 @@ Closes the data provider and free every resources used .. versionadded:: 3.22 %End - virtual bool removeDatasetGroup( const int &index ) = 0; + virtual bool removeDatasetGroup( int index ) = 0; %Docstring Remove dataset group from the mesh emits dataChanged when successful -:return: True on success +:return: ``True`` on success .. versionadded:: 3.42 %End diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in index e4b61363f682..bacced13c53c 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -186,7 +186,7 @@ Removes datasets from the mesh with given ``name``. :param name: of dataset group to remove -:return: whether the dataset is added +:return: whether the dataset is removed .. versionadded:: 3.42 %End @@ -918,8 +918,8 @@ Sets labeling configuration. Takes ownership of the object. bool datasetsPathUnique( const QString &path ); %Docstring -Checks that datasets path is already added to this mesh layer. Return true if the -dataset path is unique. +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 diff --git a/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in b/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in index b1e7b09f7f0c..eff5d28343a6 100644 --- a/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshdataprovider.sip.in @@ -467,13 +467,13 @@ Closes the data provider and free every resources used .. versionadded:: 3.22 %End - virtual bool removeDatasetGroup( const int &index ) = 0; + virtual bool removeDatasetGroup( int index ) = 0; %Docstring Remove dataset group from the mesh emits dataChanged when successful -:return: True on success +:return: ``True`` on success .. versionadded:: 3.42 %End diff --git a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in index e4b61363f682..bacced13c53c 100644 --- a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -186,7 +186,7 @@ Removes datasets from the mesh with given ``name``. :param name: of dataset group to remove -:return: whether the dataset is added +:return: whether the dataset is removed .. versionadded:: 3.42 %End @@ -918,8 +918,8 @@ Sets labeling configuration. Takes ownership of the object. bool datasetsPathUnique( const QString &path ); %Docstring -Checks that datasets path is already added to this mesh layer. Return true if the -dataset path is unique. +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 From edc0f8d9090b92f725e132e7adb001228eb2201c Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 23:09:26 +0100 Subject: [PATCH 26/35] add docstring --- src/gui/mesh/qgsmeshdatasetgrouptreewidget.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h index 3e4d7e889a68..fe12455bd53c 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h @@ -44,6 +44,7 @@ class GUI_EXPORT QgsMeshDatasetGroupTreeWidget: public QWidget, private Ui::QgsM void apply(); signals: + //! Signal emited when dataset groups changed (addition or removal) void datasetGroupsChanged(); private slots: From f49b52080adca64d05b53a3350c1bc1b46a18e93 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sat, 23 Nov 2024 23:18:26 +0100 Subject: [PATCH 27/35] fix styling and typo --- src/gui/mesh/qgsmeshdatasetgrouptreewidget.h | 2 +- src/providers/mdal/qgsmdalprovider.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h index fe12455bd53c..ca65548b2a27 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.h @@ -44,7 +44,7 @@ class GUI_EXPORT QgsMeshDatasetGroupTreeWidget: public QWidget, private Ui::QgsM void apply(); signals: - //! Signal emited when dataset groups changed (addition or removal) + //! Emitted when dataset groups changed (addition or removal) void datasetGroupsChanged(); private slots: diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index b8e1796a0dbf..31863f85a096 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -725,11 +725,11 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() while ( existingNames.find( lastAddedGroupName ) != existingNames.end() ) { - match = reEndsNumber.match(lastAddedGroupName); + match = reEndsNumber.match( lastAddedGroupName ); if ( match.hasMatch() ) { - const int number = match.capturedTexts().last().toInt(); - lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() + 1 ) + QString::number( number + 1 ); + const int number = match.capturedTexts().last().toInt(); + lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() + 1 ) + QString::number( number + 1 ); } else { From 9521cbafc8893275a6f4f6f92073c7033943f987 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Sun, 24 Nov 2024 14:22:37 +0100 Subject: [PATCH 28/35] fix tests --- tests/src/core/testqgsmeshlayer.cpp | 8 +++++++- tests/src/providers/testqgsmdalprovider.cpp | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/src/core/testqgsmeshlayer.cpp b/tests/src/core/testqgsmeshlayer.cpp index 1b02d9b6dd96..91650a4b7822 100644 --- a/tests/src/core/testqgsmeshlayer.cpp +++ b/tests/src/core/testqgsmeshlayer.cpp @@ -2395,7 +2395,13 @@ void TestQgsMeshLayer::testRemoveDatasets() // add datasets with same name QVERIFY( layer.addDatasets( testDataPath( "/mesh/quad_and_triangle_vertex_vector.dat" ) ) ); - QVERIFY( layer.addDatasets( testDataPath( "/mesh/quad_and_triangle_vertex_vector_existing_name.dat" ) ) ); + + const QString fileDatasetGroup = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector.dat" ); + + QFile::remove( fileDatasetGroup ); + QVERIFY( QFile::copy( testDataPath( "/mesh/quad_and_triangle_vertex_vector.dat" ), fileDatasetGroup ) ); + + QVERIFY( layer.addDatasets( fileDatasetGroup ) ); // can remove but the second has added "_1" QVERIFY( layer.removeDatasets( "VertexVectorDataset" ) ); diff --git a/tests/src/providers/testqgsmdalprovider.cpp b/tests/src/providers/testqgsmdalprovider.cpp index 6bff867d7b74..25d895a20ed7 100644 --- a/tests/src/providers/testqgsmdalprovider.cpp +++ b/tests/src/providers/testqgsmdalprovider.cpp @@ -230,8 +230,8 @@ void TestQgsMdalProvider::uniqueDatasetNames() // these three dataset files have the same name const QString fileDatasetGroup1 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector.dat" ); - const QString fileDatasetGroup2 = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector.dat" ); - const QString fileDatasetGroup3 = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector.dat" ); + const QString fileDatasetGroup2 = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector_1.dat" ); + const QString fileDatasetGroup3 = QDir::tempPath() + QStringLiteral( "/quad_and_triangle_vertex_vector_2.dat" ); QFile::remove( fileDatasetGroup2 ); QVERIFY( QFile::copy( fileDatasetGroup1, fileDatasetGroup2 ) ); From dd6b4c84c9258a5d497c1b828bb0bdc8c4fda388 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 5 Dec 2024 11:01:06 +0100 Subject: [PATCH 29/35] fix precommit issues --- src/providers/mdal/qgsmdalprovider.cpp | 4 +-- tests/src/core/testqgsmeshlayer.cpp | 3 +- tests/src/providers/testqgsmdalprovider.cpp | 40 ++++++++++----------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index 71404dbe686e..fdae41b4f4e2 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -699,7 +699,7 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() QSet existingNames; - for ( int i = 0; i < datasetGroupCount() - 1; i++ ) + for ( int i = 0; i < datasetGroupCount() - 1; i++ ) { existingNames.insert( MDAL_G_name( MDAL_M_datasetGroup( mMeshH, i ) ) ); } @@ -719,7 +719,7 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() } else { - lastAddedGroupName = lastAddedGroupName.append( "_1" );; + lastAddedGroupName = lastAddedGroupName.append( "_1" ); } } MDAL_G_setName( datasetGroupH, lastAddedGroupName.toStdString().c_str() ); diff --git a/tests/src/core/testqgsmeshlayer.cpp b/tests/src/core/testqgsmeshlayer.cpp index a48481bc68f4..274b6742bf1e 100644 --- a/tests/src/core/testqgsmeshlayer.cpp +++ b/tests/src/core/testqgsmeshlayer.cpp @@ -2390,7 +2390,8 @@ void TestQgsMeshLayer::testRemoveDatasets() QgsMeshLayer layer( testDataPath( "mesh/quad_and_triangle.2dm" ), QStringLiteral( "mesh" ), - QStringLiteral( "mdal" ) ); + QStringLiteral( "mdal" ) + ); QVERIFY( layer.isValid() ); // add datasets with same name diff --git a/tests/src/providers/testqgsmdalprovider.cpp b/tests/src/providers/testqgsmdalprovider.cpp index 2fb59b154926..ea086adb40d1 100644 --- a/tests/src/providers/testqgsmdalprovider.cpp +++ b/tests/src/providers/testqgsmdalprovider.cpp @@ -214,19 +214,19 @@ void TestQgsMdalProvider::uniqueDatasetNames() { const QString file = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle.2dm" ); QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( - QStringLiteral( "mdal" ), - file, - QgsDataProvider::ProviderOptions() - ); + QStringLiteral( "mdal" ), + file, + QgsDataProvider::ProviderOptions() + ); - QgsMeshDataProvider *mp = dynamic_cast< QgsMeshDataProvider * >( provider ); + QgsMeshDataProvider *mp = dynamic_cast( provider ); QgsDataProvider *provider1 = QgsProviderRegistry::instance()->createProvider( - QStringLiteral( "mdal" ), - file, - QgsDataProvider::ProviderOptions() - ); - QgsMeshDataProvider *mp1 = dynamic_cast< QgsMeshDataProvider * >( provider1 ); + QStringLiteral( "mdal" ), + file, + QgsDataProvider::ProviderOptions() + ); + QgsMeshDataProvider *mp1 = dynamic_cast( provider1 ); // these three dataset files have the same name const QString fileDatasetGroup1 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle_vertex_vector.dat" ); @@ -243,7 +243,7 @@ void TestQgsMdalProvider::uniqueDatasetNames() QVERIFY( mp->addDataset( fileDatasetGroup1 ) ); QCOMPARE( mp->datasetGroupCount(), 2 ); - QgsMeshDatasetGroupMetadata metadata = mp->datasetGroupMetadata( 1 ); + QgsMeshDatasetGroupMetadata metadata = mp->datasetGroupMetadata( 1 ); QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); QVERIFY( mp1->addDataset( fileDatasetGroup2 ) ); @@ -261,11 +261,11 @@ void TestQgsMdalProvider::uniqueDatasetNames() QVERIFY( mp->addDataset( fileDatasetGroup3 ) ); QCOMPARE( mp->datasetGroupCount(), 4 ); - metadata = mp->datasetGroupMetadata( 1 ); + metadata = mp->datasetGroupMetadata( 1 ); QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset" ) ); - metadata = mp->datasetGroupMetadata( 2 ); + metadata = mp->datasetGroupMetadata( 2 ); QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset_1" ) ); - metadata = mp->datasetGroupMetadata( 3 ); + metadata = mp->datasetGroupMetadata( 3 ); QCOMPARE( metadata.name(), QStringLiteral( "VertexVectorDataset_2" ) ); delete provider; @@ -276,12 +276,12 @@ void TestQgsMdalProvider::addRemoveDatasetGroups() { const QString file = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/quad_and_triangle.2dm" ); QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider( - QStringLiteral( "mdal" ), - file, - QgsDataProvider::ProviderOptions() - ); + QStringLiteral( "mdal" ), + file, + QgsDataProvider::ProviderOptions() + ); - QgsMeshDataProvider *mp = dynamic_cast< QgsMeshDataProvider * >( provider ); + QgsMeshDataProvider *mp = dynamic_cast( provider ); QVERIFY( mp ); QVERIFY( mp->isValid() ); QCOMPARE( mp->datasetGroupCount(), 1 ); @@ -297,7 +297,7 @@ void TestQgsMdalProvider::addRemoveDatasetGroups() QVERIFY( mp->addDataset( fileDatasetGroup2 ) ); QCOMPARE( mp->datasetGroupCount(), 3 ); - QgsMeshDatasetGroupMetadata metadata = mp->datasetGroupMetadata( 0 ); + QgsMeshDatasetGroupMetadata metadata = mp->datasetGroupMetadata( 0 ); QCOMPARE( metadata.name(), QStringLiteral( "Bed Elevation" ) ); metadata = mp->datasetGroupMetadata( 1 ); From 6a76e3657c6e79f8c988b68ae7c27e0452b6e245 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Thu, 5 Dec 2024 11:08:27 +0100 Subject: [PATCH 30/35] fix issue --- tests/src/core/testqgsmeshlayer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/core/testqgsmeshlayer.cpp b/tests/src/core/testqgsmeshlayer.cpp index 274b6742bf1e..a3291bdf1055 100644 --- a/tests/src/core/testqgsmeshlayer.cpp +++ b/tests/src/core/testqgsmeshlayer.cpp @@ -2370,7 +2370,8 @@ void TestQgsMeshLayer::testDatasetsUniquePath() QgsMeshLayer layer( testDataPath( "mesh/quad_and_triangle.2dm" ), QStringLiteral( "mesh" ), - QStringLiteral( "mdal" ) ); + QStringLiteral( "mdal" ) + ); QVERIFY( layer.isValid() ); QString path = testDataPath( "/mesh/quad_and_triangle_vertex_vector.dat" ); From 00f81201afe09122b5271dc743df207b893f72f1 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 11 Dec 2024 12:03:38 +0100 Subject: [PATCH 31/35] Update src/core/mesh/qgsmeshlayer.h fix docstring Co-authored-by: Stefanos Natsis --- src/core/mesh/qgsmeshlayer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/mesh/qgsmeshlayer.h b/src/core/mesh/qgsmeshlayer.h index 478a079553ee..11893cad2657 100644 --- a/src/core/mesh/qgsmeshlayer.h +++ b/src/core/mesh/qgsmeshlayer.h @@ -214,7 +214,7 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer, public QgsAbstractProfileSo /** * Removes datasets from the mesh with given \a name. * - * \param name of dataset group to remove + * \param name name of dataset group to remove * \return whether the dataset is removed * * \since QGIS 3.42 From 3320239191460f05b213aca46278ea194cd2673c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:05:56 +0000 Subject: [PATCH 32/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index 77f700062e35..e41a3122f8bc 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -44,8 +44,7 @@ QgsMeshDatasetGroupTreeWidget::QgsMeshDatasetGroupTreeWidget( QWidget *parent ): this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer ); } ); - connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() - { + connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() { QModelIndex index = mDatasetGroupTreeView->currentIndex(); QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() ); if ( meshGroupItem ) From 9bab444bd1168874ba02ebeaf3be8e27d3da4845 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 11 Dec 2024 12:08:57 +0100 Subject: [PATCH 33/35] const stuff --- src/core/mesh/qgsmeshdatasetgroupstore.cpp | 4 ++-- .../providers/meshmemory/qgsmeshmemorydataprovider.cpp | 2 +- src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp | 7 ++++--- src/providers/mdal/qgsmdalprovider.cpp | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/mesh/qgsmeshdatasetgroupstore.cpp b/src/core/mesh/qgsmeshdatasetgroupstore.cpp index e5a6ed0b7955..f5b1f814b861 100644 --- a/src/core/mesh/qgsmeshdatasetgroupstore.cpp +++ b/src/core/mesh/qgsmeshdatasetgroupstore.cpp @@ -146,7 +146,7 @@ void QgsMeshDatasetGroupStore::reindexDatasetGroups() for ( int i = 0; i < mPersistentProvider->datasetGroupCount(); i++ ) { - QString name = mPersistentProvider->datasetGroupMetadata( i ).name(); + const QString name = mPersistentProvider->datasetGroupMetadata( i ).name(); mRegistry[globalIndex] = DatasetGroup{mPersistentProvider, i}; mPersistentExtraDatasetGroupIndexes.append( globalIndex ); mGroupNameToGlobalIndex.insert( name, globalIndex ); @@ -156,7 +156,7 @@ void QgsMeshDatasetGroupStore::reindexDatasetGroups() for ( int i = 0; i < mExtraDatasets.datasetGroupCount(); i++ ) { QgsMeshDatasetSourceInterface *source = &mExtraDatasets; - QString name = source->datasetGroupMetadata( i ).name(); + const QString name = source->datasetGroupMetadata( i ).name(); mRegistry[globalIndex] = DatasetGroup{source, i}; mGroupNameToGlobalIndex.insert( name, globalIndex ); globalIndex++; diff --git a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp index 76d093e04a80..76b656a13d50 100644 --- a/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp +++ b/src/core/providers/meshmemory/qgsmeshmemorydataprovider.cpp @@ -438,7 +438,7 @@ bool QgsMeshMemoryDataProvider::removeDatasetGroup( int index ) } else { - QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index ); + const QgsMeshDatasetGroupMetadata datasetGroupMeta = datasetGroupMetadata( index ); mDatasetGroups.removeAt( index ); diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index e41a3122f8bc..81fa4f62b271 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -44,9 +44,10 @@ QgsMeshDatasetGroupTreeWidget::QgsMeshDatasetGroupTreeWidget( QWidget *parent ): this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer ); } ); - connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() { - QModelIndex index = mDatasetGroupTreeView->currentIndex(); - QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() ); + connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() + { + const QModelIndex index = mDatasetGroupTreeView->currentIndex(); + const QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() ); if ( meshGroupItem ) { if ( mMeshLayer->dataProvider()->dataSourceUri().contains( meshGroupItem->description() ) ) diff --git a/src/providers/mdal/qgsmdalprovider.cpp b/src/providers/mdal/qgsmdalprovider.cpp index fdae41b4f4e2..d13e476e0fcd 100644 --- a/src/providers/mdal/qgsmdalprovider.cpp +++ b/src/providers/mdal/qgsmdalprovider.cpp @@ -714,7 +714,7 @@ void QgsMdalProvider::makeLastDatasetGroupNameUnique() match = reEndsNumber.match( lastAddedGroupName ); if ( match.hasMatch() ) { - const int number = match.capturedTexts().last().toInt(); + const int number = match.capturedTexts().constLast().toInt(); lastAddedGroupName = lastAddedGroupName.left( lastAddedGroupName.length() - match.capturedLength() + 1 ) + QString::number( number + 1 ); } else From 608e904f7d17a8d69b83430c4b422bd62159f236 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:12:11 +0000 Subject: [PATCH 34/35] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp index 81fa4f62b271..ad48c20f2623 100644 --- a/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp +++ b/src/gui/mesh/qgsmeshdatasetgrouptreewidget.cpp @@ -44,8 +44,7 @@ QgsMeshDatasetGroupTreeWidget::QgsMeshDatasetGroupTreeWidget( QWidget *parent ): this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer ); } ); - connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() - { + connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this]() { const QModelIndex index = mDatasetGroupTreeView->currentIndex(); const QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() ); if ( meshGroupItem ) From 62d87a7749cbfaecd5cec853ae41bc95ef70e533 Mon Sep 17 00:00:00 2001 From: Jan Caha Date: Wed, 11 Dec 2024 12:30:33 +0100 Subject: [PATCH 35/35] sipify --- python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in | 2 +- python/core/auto_generated/mesh/qgsmeshlayer.sip.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in index bacced13c53c..fe0d4d27d99a 100644 --- a/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/PyQt6/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -184,7 +184,7 @@ Adds datasets to the mesh from file with ``path``. Use the the time ``defaultRef %Docstring Removes datasets from the mesh with given ``name``. -:param name: of dataset group to remove +:param name: name of dataset group to remove :return: whether the dataset is removed diff --git a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in index bacced13c53c..fe0d4d27d99a 100644 --- a/python/core/auto_generated/mesh/qgsmeshlayer.sip.in +++ b/python/core/auto_generated/mesh/qgsmeshlayer.sip.in @@ -184,7 +184,7 @@ Adds datasets to the mesh from file with ``path``. Use the the time ``defaultRef %Docstring Removes datasets from the mesh with given ``name``. -:param name: of dataset group to remove +:param name: name of dataset group to remove :return: whether the dataset is removed