Skip to content

Commit e36c5e2

Browse files
committedOct 9, 2017
Implement clear action
1 parent 2d79601 commit e36c5e2

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed
 

‎python/core/qgsauxiliarystorage.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ class QgsAuxiliaryLayer : QgsVectorLayer
9292

9393

9494

95+
bool clear();
96+
%Docstring
97+
Deletes all features from the layer. Changes are automatically committed
98+
and the layer remains editable.
99+
100+
:return: true if changes are committed without error, false otherwise.
101+
:rtype: bool
102+
%End
103+
95104
QgsVectorLayerJoinInfo joinInfo() const;
96105
%Docstring
97106
Returns information to use for joining with primary key and so on.

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
8484
, mLayer( lyr )
8585
, mOriginalSubsetSQL( lyr->subsetString() )
8686
, mAuxiliaryLayerActionNew( nullptr )
87+
, mAuxiliaryLayerActionClear( nullptr )
8788
{
8889
setupUi( this );
8990
connect( mLayerOrigNameLineEdit, &QLineEdit::textEdited, this, &QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited );
@@ -361,6 +362,10 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
361362
menu->addAction( mAuxiliaryLayerActionNew );
362363
connect( mAuxiliaryLayerActionNew, &QAction::triggered, this, &QgsVectorLayerProperties::onAuxiliaryLayerNew );
363364

365+
mAuxiliaryLayerActionClear = new QAction( tr( "Clear" ), this );
366+
menu->addAction( mAuxiliaryLayerActionClear );
367+
connect( mAuxiliaryLayerActionClear, &QAction::triggered, this, &QgsVectorLayerProperties::onAuxiliaryLayerClear );
368+
364369
mAuxiliaryStorageActions->setMenu( menu );
365370

366371
updateAuxiliaryStoragePage();
@@ -1554,3 +1559,24 @@ void QgsVectorLayerProperties::onAuxiliaryLayerNew()
15541559
updateAuxiliaryStoragePage( true );
15551560
}
15561561
}
1562+
1563+
void QgsVectorLayerProperties::onAuxiliaryLayerClear()
1564+
{
1565+
QgsAuxiliaryLayer *alayer = mLayer->auxiliaryLayer();
1566+
1567+
if ( !alayer )
1568+
return;
1569+
1570+
const QString msg = tr( "Are you sure you want to clear auxiliary data for %1" ).arg( mLayer->name() );
1571+
QMessageBox::StandardButton reply;
1572+
reply = QMessageBox::question( this, "Clear auxiliary data", msg, QMessageBox::Yes | QMessageBox::No );
1573+
1574+
if ( reply == QMessageBox::Yes )
1575+
{
1576+
QApplication::setOverrideCursor( Qt::WaitCursor );
1577+
alayer->clear();
1578+
QApplication::restoreOverrideCursor();
1579+
updateAuxiliaryStoragePage( true );
1580+
mLayer->triggerRepaint();
1581+
}
1582+
}

‎src/app/qgsvectorlayerproperties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
157157
void updateFieldsPropertiesDialog();
158158

159159
void onAuxiliaryLayerNew();
160+
void onAuxiliaryLayerClear();
160161

161162
private:
162163

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

224225
QAction *mAuxiliaryLayerActionNew;
226+
QAction *mAuxiliaryLayerActionClear;
225227

226228
private slots:
227229
void openPanel( QgsPanelWidget *panel );

‎src/core/qgsauxiliarystorage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ void QgsAuxiliaryField::init( const QgsPropertyDefinition &def )
115115
}
116116
}
117117

118+
bool QgsAuxiliaryLayer::clear()
119+
{
120+
bool rc = deleteFeatures( allFeatureIds() );
121+
commitChanges();
122+
startEditing();
123+
return rc;
124+
}
125+
118126
QString QgsAuxiliaryField::name( const QgsPropertyDefinition &def, bool joined )
119127
{
120128
QString origin;

‎src/core/qgsauxiliarystorage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
122122

123123
QgsAuxiliaryLayer &operator=( QgsAuxiliaryLayer const &rhs ) = delete;
124124

125+
/**
126+
* Deletes all features from the layer. Changes are automatically committed
127+
* and the layer remains editable.
128+
*
129+
* \returns true if changes are committed without error, false otherwise.
130+
*/
131+
bool clear();
132+
125133
/**
126134
* Returns information to use for joining with primary key and so on.
127135
*/

0 commit comments

Comments
 (0)
Please sign in to comment.