Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Remove child features when parent's add feature form is cancelled
- Loading branch information
Showing
8 changed files
with
192 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters