Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Remove child features when parent's add feature form is cancelled
- Loading branch information
Showing
with
192 additions
and 6 deletions.
- +1 −0 python/gui/gui.sip
- +38 −0 python/gui/qgstrackedvectorlayertools.sip
- +2 −0 src/gui/CMakeLists.txt
- +15 −2 src/gui/qgsattributedialog.cpp
- +5 −4 src/gui/qgsattributedialog.h
- +75 −0 src/gui/qgstrackedvectorlayertools.cpp
- +48 −0 src/gui/qgstrackedvectorlayertools.h
- +8 −0 src/gui/qgsvectorlayertools.h
@@ -0,0 +1,38 @@ | ||
/*************************************************************************** | ||
qgstrackedvectorlayertools.sip - QgsTrackedVectorLayerTools | ||
|
||
--------------------- | ||
begin : 16.5.2016 | ||
copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
class QgsTrackedVectorLayerTools : QgsVectorLayerTools | ||
{ | ||
%TypeHeaderCode | ||
#include "qgstrackedvectorlayertools.h" | ||
%End | ||
public: | ||
QgsTrackedVectorLayerTools(); | ||
|
||
bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues, const QgsGeometry& defaultGeometry, QgsFeature* feature ) const; | ||
bool startEditing( QgsVectorLayer* layer ) const ; | ||
bool stopEditing( QgsVectorLayer* layer, bool allowCancel ) const ; | ||
bool saveEdits( QgsVectorLayer* layer ) const ; | ||
|
||
/** | ||
* Set the vector layer tools that will be used to interact with the data | ||
*/ | ||
void setVectorLayerTools(const QgsVectorLayerTools* tools ); | ||
|
||
/** | ||
* Delete all features which have been added via this object. | ||
*/ | ||
void rollback(); | ||
}; |
@@ -0,0 +1,75 @@ | ||
/*************************************************************************** | ||
qgstrackedvectorlayertools.cpp - QgsTrackedVectorLayerTools | ||
--------------------- | ||
begin : 16.5.2016 | ||
copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgstrackedvectorlayertools.h" | ||
#include "qgsvectorlayer.h" | ||
|
||
QgsTrackedVectorLayerTools::QgsTrackedVectorLayerTools() | ||
: mBackend( nullptr ) | ||
{ | ||
} | ||
|
||
bool QgsTrackedVectorLayerTools::addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues, const QgsGeometry& defaultGeometry, QgsFeature* feature ) const | ||
{ | ||
QgsFeature* f = feature; | ||
if ( !feature ) | ||
f = new QgsFeature(); | ||
|
||
if ( mBackend->addFeature( layer, defaultValues, defaultGeometry, f ) ) | ||
{ | ||
mAddedFeatures[layer].insert( f->id() ); | ||
if ( !feature ) | ||
delete f; | ||
return true; | ||
} | ||
else | ||
{ | ||
if ( !feature ) | ||
delete f; | ||
return false; | ||
} | ||
} | ||
|
||
bool QgsTrackedVectorLayerTools::startEditing( QgsVectorLayer* layer ) const | ||
{ | ||
return mBackend->startEditing( layer ); | ||
} | ||
|
||
bool QgsTrackedVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCancel ) const | ||
{ | ||
return mBackend->stopEditing( layer, allowCancel ); | ||
} | ||
|
||
bool QgsTrackedVectorLayerTools::saveEdits( QgsVectorLayer* layer ) const | ||
{ | ||
return mBackend->saveEdits( layer ); | ||
} | ||
|
||
void QgsTrackedVectorLayerTools::setVectorLayerTools( const QgsVectorLayerTools* tools ) | ||
{ | ||
mBackend = tools; | ||
} | ||
|
||
void QgsTrackedVectorLayerTools::rollback() | ||
{ | ||
QMapIterator<QgsVectorLayer*, QgsFeatureIds> it( mAddedFeatures ); | ||
while ( it.hasNext() ) | ||
{ | ||
it.next(); | ||
it.key()->deleteFeatures( it.value() ); | ||
} | ||
|
||
mAddedFeatures.clear(); | ||
} |
@@ -0,0 +1,48 @@ | ||
/*************************************************************************** | ||
qgstrackedvectorlayertools.h - QgsTrackedVectorLayerTools | ||
--------------------- | ||
begin : 16.5.2016 | ||
copyright : (C) 2016 by Matthias Kuhn, OPENGIS.ch | ||
email : matthias@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSTRACKEDVECTORLAYERTOOLS_H | ||
#define QGSTRACKEDVECTORLAYERTOOLS_H | ||
|
||
#include "qgsvectorlayertools.h" | ||
|
||
class GUI_EXPORT QgsTrackedVectorLayerTools : public QgsVectorLayerTools | ||
{ | ||
public: | ||
QgsTrackedVectorLayerTools(); | ||
|
||
bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues, const QgsGeometry& defaultGeometry, QgsFeature* feature ) const override; | ||
bool startEditing( QgsVectorLayer* layer ) const override; | ||
bool stopEditing( QgsVectorLayer* layer, bool allowCancel ) const override; | ||
bool saveEdits( QgsVectorLayer* layer ) const override; | ||
|
||
/** | ||
* Set the vector layer tools that will be used to interact with the data | ||
*/ | ||
void setVectorLayerTools( const QgsVectorLayerTools* tools ); | ||
|
||
/** | ||
* Delete all features which have been added via this object. | ||
*/ | ||
void rollback(); | ||
|
||
private: | ||
|
||
const QgsVectorLayerTools* mBackend; | ||
// TODO QGIS3: remove mutable once methods are no longer const | ||
mutable QMap<QgsVectorLayer*, QgsFeatureIds> mAddedFeatures; | ||
}; | ||
|
||
#endif // QGSTRACKEDVECTORLAYERTOOLS_H |