Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement clear action
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent 2d79601 commit e36c5e2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/core/qgsauxiliarystorage.sip
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -157,6 +157,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
void updateFieldsPropertiesDialog();

void onAuxiliaryLayerNew();
void onAuxiliaryLayerClear();

private:

Expand Down Expand Up @@ -222,6 +223,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
QgsMetadataWidget *mMetadataWidget = nullptr;

QAction *mAuxiliaryLayerActionNew;
QAction *mAuxiliaryLayerActionClear;

private slots:
void openPanel( QgsPanelWidget *panel );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsauxiliarystorage.cpp
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsauxiliarystorage.h
Expand Up @@ -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.
*/
Expand Down

0 comments on commit e36c5e2

Please sign in to comment.