Implement clear action

This commit is contained in:
Blottiere Paul 2017-08-29 08:32:27 +01:00
parent 2d79601566
commit e36c5e2d41
5 changed files with 53 additions and 0 deletions

View File

@ -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.

View File

@ -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();
}
}

View File

@ -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 );

View File

@ -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;

View File

@ -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.
*/