diff --git a/python/core/qgsauxiliarystorage.sip b/python/core/qgsauxiliarystorage.sip index 5e42332ad76..20552537725 100644 --- a/python/core/qgsauxiliarystorage.sip +++ b/python/core/qgsauxiliarystorage.sip @@ -92,6 +92,15 @@ class QgsAuxiliaryLayer : QgsVectorLayer + bool clear(); +%Docstring + Deletes all features from the layer. Changes are automatically committed + and the layer remains editable. + + :return: true if changes are committed without error, false otherwise. + :rtype: bool +%End + QgsVectorLayerJoinInfo joinInfo() const; %Docstring Returns information to use for joining with primary key and so on. diff --git a/src/app/qgsvectorlayerproperties.cpp b/src/app/qgsvectorlayerproperties.cpp index ed221fccdd3..59c9861b6ad 100644 --- a/src/app/qgsvectorlayerproperties.cpp +++ b/src/app/qgsvectorlayerproperties.cpp @@ -84,6 +84,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties( , mLayer( lyr ) , mOriginalSubsetSQL( lyr->subsetString() ) , mAuxiliaryLayerActionNew( nullptr ) + , mAuxiliaryLayerActionClear( nullptr ) { setupUi( this ); connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited ); @@ -361,6 +362,10 @@ QgsVectorLayerProperties::QgsVectorLayerProperties( menu->addAction( mAuxiliaryLayerActionNew ); connect( mAuxiliaryLayerActionNew, &QAction::triggered, this, &QgsVectorLayerProperties::onAuxiliaryLayerNew ); + mAuxiliaryLayerActionClear = new QAction( tr( "Clear" ), this ); + menu->addAction( mAuxiliaryLayerActionClear ); + connect( mAuxiliaryLayerActionClear, &QAction::triggered, this, &QgsVectorLayerProperties::onAuxiliaryLayerClear ); + mAuxiliaryStorageActions->setMenu( menu ); updateAuxiliaryStoragePage(); @@ -1554,3 +1559,24 @@ void QgsVectorLayerProperties::onAuxiliaryLayerNew() updateAuxiliaryStoragePage( true ); } } + +void QgsVectorLayerProperties::onAuxiliaryLayerClear() +{ + QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer(); + + if ( !alayer ) + return; + + const QString msg = tr( "Are you sure you want to clear auxiliary data for %1" ).arg( mLayer->name() ); + QMessageBox::StandardButton reply; + reply = QMessageBox::question( this, "Clear auxiliary data", msg, QMessageBox::Yes | QMessageBox::No ); + + if ( reply == QMessageBox::Yes ) + { + QApplication::setOverrideCursor( Qt::WaitCursor ); + alayer->clear(); + QApplication::restoreOverrideCursor(); + updateAuxiliaryStoragePage( true ); + mLayer->triggerRepaint(); + } +} diff --git a/src/app/qgsvectorlayerproperties.h b/src/app/qgsvectorlayerproperties.h index f90ac57901b..bcb7002b694 100644 --- a/src/app/qgsvectorlayerproperties.h +++ b/src/app/qgsvectorlayerproperties.h @@ -157,6 +157,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private void updateFieldsPropertiesDialog(); void onAuxiliaryLayerNew(); + void onAuxiliaryLayerClear(); private: @@ -222,6 +223,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private QgsMetadataWidget *mMetadataWidget = nullptr; QAction *mAuxiliaryLayerActionNew; + QAction *mAuxiliaryLayerActionClear; private slots: void openPanel( QgsPanelWidget *panel ); diff --git a/src/core/qgsauxiliarystorage.cpp b/src/core/qgsauxiliarystorage.cpp index 28aae2b8b44..6ec2d528ecc 100644 --- a/src/core/qgsauxiliarystorage.cpp +++ b/src/core/qgsauxiliarystorage.cpp @@ -115,6 +115,14 @@ void QgsAuxiliaryField::init( const QgsPropertyDefinition &def ) } } +bool QgsAuxiliaryLayer::clear() +{ + bool rc = deleteFeatures( allFeatureIds() ); + commitChanges(); + startEditing(); + return rc; +} + QString QgsAuxiliaryField::name( const QgsPropertyDefinition &def, bool joined ) { QString origin; diff --git a/src/core/qgsauxiliarystorage.h b/src/core/qgsauxiliarystorage.h index 8bc46ff5dc9..1107b0c4163 100644 --- a/src/core/qgsauxiliarystorage.h +++ b/src/core/qgsauxiliarystorage.h @@ -122,6 +122,14 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer QgsAuxiliaryLayer &operator=( QgsAuxiliaryLayer const &rhs ) = delete; + /** + * Deletes all features from the layer. Changes are automatically committed + * and the layer remains editable. + * + * \returns true if changes are committed without error, false otherwise. + */ + bool clear(); + /** * Returns information to use for joining with primary key and so on. */