mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-16 00:06:09 -05:00
Remove child features when parent's add feature form is cancelled
This commit is contained in:
parent
307aabd66a
commit
8c402bcf42
@ -151,6 +151,7 @@
|
|||||||
%Include qgssvgannotationitem.sip
|
%Include qgssvgannotationitem.sip
|
||||||
%Include qgstablewidgetitem.sip
|
%Include qgstablewidgetitem.sip
|
||||||
%Include qgstextannotationitem.sip
|
%Include qgstextannotationitem.sip
|
||||||
|
%Include qgstrackedvectorlayertools.sip
|
||||||
%Include qgsunitselectionwidget.sip
|
%Include qgsunitselectionwidget.sip
|
||||||
%Include qgsuserinputdockwidget.sip
|
%Include qgsuserinputdockwidget.sip
|
||||||
%Include qgsvariableeditorwidget.sip
|
%Include qgsvariableeditorwidget.sip
|
||||||
|
|||||||
38
python/gui/qgstrackedvectorlayertools.sip
Normal file
38
python/gui/qgstrackedvectorlayertools.sip
Normal file
@ -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();
|
||||||
|
};
|
||||||
@ -280,6 +280,7 @@ SET(QGIS_GUI_SRCS
|
|||||||
qgssvgannotationitem.cpp
|
qgssvgannotationitem.cpp
|
||||||
qgstablewidgetitem.cpp
|
qgstablewidgetitem.cpp
|
||||||
qgstextannotationitem.cpp
|
qgstextannotationitem.cpp
|
||||||
|
qgstrackedvectorlayertools.cpp
|
||||||
qgsunitselectionwidget.cpp
|
qgsunitselectionwidget.cpp
|
||||||
qgsuserinputdockwidget.cpp
|
qgsuserinputdockwidget.cpp
|
||||||
qgsvariableeditorwidget.cpp
|
qgsvariableeditorwidget.cpp
|
||||||
@ -601,6 +602,7 @@ SET(QGIS_GUI_HDRS
|
|||||||
qgssvgannotationitem.h
|
qgssvgannotationitem.h
|
||||||
qgstablewidgetitem.h
|
qgstablewidgetitem.h
|
||||||
qgstextannotationitem.h
|
qgstextannotationitem.h
|
||||||
|
qgstrackedvectorlayertools.h
|
||||||
qgsuserinputdockwidget.h
|
qgsuserinputdockwidget.h
|
||||||
qgsvectorlayertools.h
|
qgsvectorlayertools.h
|
||||||
qgsvertexmarker.h
|
qgsvertexmarker.h
|
||||||
|
|||||||
@ -97,12 +97,25 @@ void QgsAttributeDialog::show( bool autoDelete )
|
|||||||
activateWindow();
|
activateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext &context )
|
void QgsAttributeDialog::reject()
|
||||||
{
|
{
|
||||||
|
// Delete any actions on other layers that may have been triggered from this dialog
|
||||||
|
if ( mAttributeForm->mode() == QgsAttributeForm::AddFeatureMode )
|
||||||
|
mTrackedVectorLayerTools.rollback();
|
||||||
|
|
||||||
|
QDialog::reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context )
|
||||||
|
{
|
||||||
|
QgsAttributeEditorContext trackedContext = context;
|
||||||
setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
|
setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
|
||||||
setLayout( new QGridLayout() );
|
setLayout( new QGridLayout() );
|
||||||
layout()->setMargin( 0 );
|
layout()->setMargin( 0 );
|
||||||
mAttributeForm = new QgsAttributeForm( layer, *feature, context, this );
|
mTrackedVectorLayerTools.setVectorLayerTools( trackedContext.vectorLayerTools() );
|
||||||
|
trackedContext.setVectorLayerTools( &mTrackedVectorLayerTools );
|
||||||
|
|
||||||
|
mAttributeForm = new QgsAttributeForm( layer, *feature, trackedContext, this );
|
||||||
mAttributeForm->disconnectButtonBox();
|
mAttributeForm->disconnectButtonBox();
|
||||||
layout()->addWidget( mAttributeForm );
|
layout()->addWidget( mAttributeForm );
|
||||||
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
|
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
|
||||||
|
|||||||
@ -20,17 +20,14 @@
|
|||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgsattributeeditorcontext.h"
|
#include "qgsattributeeditorcontext.h"
|
||||||
#include "qgsattributeform.h"
|
#include "qgsattributeform.h"
|
||||||
|
#include "qgstrackedvectorlayertools.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
|
||||||
class QgsDistanceArea;
|
class QgsDistanceArea;
|
||||||
class QgsFeature;
|
|
||||||
class QgsField;
|
|
||||||
class QgsHighlight;
|
class QgsHighlight;
|
||||||
class QgsVectorLayer;
|
|
||||||
class QgsVectorLayerTools;
|
|
||||||
|
|
||||||
class GUI_EXPORT QgsAttributeDialog : public QDialog
|
class GUI_EXPORT QgsAttributeDialog : public QDialog
|
||||||
{
|
{
|
||||||
@ -137,6 +134,7 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
|
void reject() override;
|
||||||
|
|
||||||
//! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form and is deleted when
|
//! Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form and is deleted when
|
||||||
//! closed.
|
//! closed.
|
||||||
@ -154,11 +152,14 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
|
|||||||
QgsAttributeForm* mAttributeForm;
|
QgsAttributeForm* mAttributeForm;
|
||||||
QgsFeature *mOwnedFeature;
|
QgsFeature *mOwnedFeature;
|
||||||
|
|
||||||
|
QgsTrackedVectorLayerTools mTrackedVectorLayerTools;
|
||||||
|
|
||||||
// true if this dialog is editable
|
// true if this dialog is editable
|
||||||
bool mEditable;
|
bool mEditable;
|
||||||
|
|
||||||
static int sFormCounter;
|
static int sFormCounter;
|
||||||
static QString sSettingsPath;
|
static QString sSettingsPath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
75
src/gui/qgstrackedvectorlayertools.cpp
Normal file
75
src/gui/qgstrackedvectorlayertools.cpp
Normal file
@ -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();
|
||||||
|
}
|
||||||
48
src/gui/qgstrackedvectorlayertools.h
Normal file
48
src/gui/qgstrackedvectorlayertools.h
Normal file
@ -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
|
||||||
@ -45,6 +45,8 @@ class GUI_EXPORT QgsVectorLayerTools
|
|||||||
* @param defaultGeometry A default geometry to add to the feature
|
* @param defaultGeometry A default geometry to add to the feature
|
||||||
* @param feature Updated feature after adding will be written back to this
|
* @param feature Updated feature after adding will be written back to this
|
||||||
* @return True in case of success, False if the operation failed/was aborted
|
* @return True in case of success, False if the operation failed/was aborted
|
||||||
|
*
|
||||||
|
* TODO QGIS 3: remove const qualifier
|
||||||
*/
|
*/
|
||||||
virtual bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry(), QgsFeature* feature = nullptr ) const = 0;
|
virtual bool addFeature( QgsVectorLayer* layer, const QgsAttributeMap& defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry(), QgsFeature* feature = nullptr ) const = 0;
|
||||||
|
|
||||||
@ -56,6 +58,8 @@ class GUI_EXPORT QgsVectorLayerTools
|
|||||||
* @param layer The layer on which to start an edit session
|
* @param layer The layer on which to start an edit session
|
||||||
*
|
*
|
||||||
* @return True, if the editing session was started
|
* @return True, if the editing session was started
|
||||||
|
*
|
||||||
|
* TODO QGIS 3: remove const qualifier
|
||||||
*/
|
*/
|
||||||
virtual bool startEditing( QgsVectorLayer* layer ) const = 0;
|
virtual bool startEditing( QgsVectorLayer* layer ) const = 0;
|
||||||
|
|
||||||
@ -66,6 +70,8 @@ class GUI_EXPORT QgsVectorLayerTools
|
|||||||
* @param layer The layer to commit
|
* @param layer The layer to commit
|
||||||
* @param allowCancel True if a cancel button should be offered
|
* @param allowCancel True if a cancel button should be offered
|
||||||
* @return True if successful
|
* @return True if successful
|
||||||
|
*
|
||||||
|
* TODO QGIS 3: remove const qualifier
|
||||||
*/
|
*/
|
||||||
virtual bool stopEditing( QgsVectorLayer* layer, bool allowCancel = true ) const = 0;
|
virtual bool stopEditing( QgsVectorLayer* layer, bool allowCancel = true ) const = 0;
|
||||||
|
|
||||||
@ -74,6 +80,8 @@ class GUI_EXPORT QgsVectorLayerTools
|
|||||||
*
|
*
|
||||||
* @param layer The layer to commit
|
* @param layer The layer to commit
|
||||||
* @return True if successful
|
* @return True if successful
|
||||||
|
*
|
||||||
|
* TODO QGIS 3: remove const qualifier
|
||||||
*/
|
*/
|
||||||
virtual bool saveEdits( QgsVectorLayer* layer ) const = 0;
|
virtual bool saveEdits( QgsVectorLayer* layer ) const = 0;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user