Skip to content

Commit

Permalink
Merge pull request #30128 from m-kuhn/30118
Browse files Browse the repository at this point in the history
Keep rubberband while attribute dialog is open
  • Loading branch information
m-kuhn authored Jun 12, 2019
2 parents 83c8b5b + 655649a commit a4eb6b0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 32 deletions.
8 changes: 8 additions & 0 deletions python/gui/auto_generated/qgsmaptoolcapture.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ Clean a temporary rubberband

%Docstring
convenient method to clean members
%End

QgsRubberBand *takeRubberBand() /Factory/;
%Docstring
Returns the rubberBand currently owned by this map tool and
transfers ownership to the caller.

.. versionadded:: 3.8
%End

protected:
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
{
mLayer->destroyEditCommand();
}
emit addFeatureFinished();
}
else
{
Expand All @@ -260,12 +261,14 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
if ( !showModal )
{
setParent( dialog ); // keep dialog until the dialog is closed and destructed
connect( dialog, &QgsAttributeDialog::finished, this, &QgsFeatureAction::addFeatureFinished );
dialog->show();
mFeature = nullptr;
return true;
}

dialog->exec();
emit addFeatureFinished();
}

// Will be set in the onFeatureSaved SLOT
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgsfeatureaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ class APP_EXPORT QgsFeatureAction : public QAction
*/
void setForceSuppressFormPopup( bool force );

signals:

/**
* This signal is emitted when the add feature process is finished.
* Either during the call to addFeature() already or when the dialog is eventually
* closed (accepted or canceled).
*
* \since QGIS 3.8
*/
void addFeatureFinished();

private slots:
void onFeatureSaved( const QgsFeature &feature );

Expand Down
11 changes: 6 additions & 5 deletions src/app/qgsmaptooladdfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ bool QgsMapToolAddFeature::addFeature( QgsVectorLayer *vlayer, QgsFeature *f, bo
{
QgsExpressionContextScope *scope = QgsExpressionContextUtils::mapToolCaptureScope( snappingMatches() );
QgsFeatureAction *action = new QgsFeatureAction( tr( "add feature" ), *f, vlayer, QString(), -1, this );
QgsRubberBand *rb = takeRubberBand();
connect( action, &QgsFeatureAction::addFeatureFinished, rb, &QgsRubberBand::deleteLater );
bool res = action->addFeature( QgsAttributeMap(), showModal, scope );
if ( showModal )
delete action;
Expand All @@ -67,12 +69,11 @@ void QgsMapToolAddFeature::digitized( QgsFeature &f )

//use always topological editing for avoidIntersection.
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
QList<QgsVectorLayer *> intersectionLayers = QgsProject::instance()->avoidIntersectionsLayers();
bool avoidIntersection = !intersectionLayers.isEmpty();
if ( avoidIntersection ) //try to add topological points also to background layers
const QList<QgsVectorLayer *> intersectionLayers = QgsProject::instance()->avoidIntersectionsLayers();

if ( !intersectionLayers.isEmpty() ) //try to add topological points also to background layers
{
const auto constIntersectionLayers = intersectionLayers;
for ( QgsVectorLayer *vl : constIntersectionLayers )
for ( QgsVectorLayer *vl : intersectionLayers )
{
//can only add topological points if background layer is editable...
if ( vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )
Expand Down
40 changes: 15 additions & 25 deletions src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
return true;
}

QgsRubberBand *QgsMapToolCapture::takeRubberBand()
{
return mRubberBand.release();
}


void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
Expand All @@ -302,7 +307,7 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )

if ( !mTempRubberBand && mCaptureCurve.numPoints() > 0 )
{
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ) );
QgsPoint pt = mCaptureCurve.endPoint();
mTempRubberBand->addPoint( QgsPointXY( pt.x(), pt.y() ) );
mTempRubberBand->addPoint( point );
Expand Down Expand Up @@ -444,12 +449,12 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator

if ( !mRubberBand )
{
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
mRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry ) );
}

if ( !mTempRubberBand )
{
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ) );
}
else
{
Expand Down Expand Up @@ -500,7 +505,7 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )

if ( !mRubberBand )
{
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
mRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry ) );
}

QgsLineString *lineString = c->curveToLine();
Expand All @@ -515,7 +520,7 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )

if ( !mTempRubberBand )
{
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ) );
}
else
{
Expand Down Expand Up @@ -622,23 +627,12 @@ bool QgsMapToolCapture::isCapturing() const

void QgsMapToolCapture::stopCapturing()
{
if ( mRubberBand )
{
delete mRubberBand;
mRubberBand = nullptr;
}
mRubberBand.reset();

if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}

while ( !mGeomErrorMarkers.isEmpty() )
{
delete mGeomErrorMarkers.takeFirst();
}
deleteTempRubberBand();

qDeleteAll( mGeomErrorMarkers );
mGeomErrorMarkers.clear();
mGeomErrors.clear();

mTracingStartPoint = QgsPointXY();
Expand All @@ -652,11 +646,7 @@ void QgsMapToolCapture::stopCapturing()

void QgsMapToolCapture::deleteTempRubberBand()
{
if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}
mTempRubberBand.reset();
}

void QgsMapToolCapture::clean()
Expand Down
13 changes: 11 additions & 2 deletions src/gui/qgsmaptoolcapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgspointlocator.h"
#include "qgscompoundcurve.h"
#include "qgsgeometry.h"
#include "qobjectuniqueptr.h"

#include <QPoint>
#include <QList>
Expand Down Expand Up @@ -106,6 +107,14 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
//! convenient method to clean members
void clean() override;

/**
* Returns the rubberBand currently owned by this map tool and
* transfers ownership to the caller.
*
* \since QGIS 3.8
*/
QgsRubberBand *takeRubberBand() SIP_FACTORY;

private slots:
void addError( const QgsGeometry::Error &error );
void currentLayerChanged( QgsMapLayer *layer );
Expand Down Expand Up @@ -255,10 +264,10 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
bool mCapturing = false;

//! Rubber band for polylines and polygons
QgsRubberBand *mRubberBand = nullptr;
QObjectUniquePtr<QgsRubberBand> mRubberBand;

//! Temporary rubber band for polylines and polygons. this connects the last added point to the mouse cursor position
QgsRubberBand *mTempRubberBand = nullptr;
QObjectUniquePtr<QgsRubberBand> mTempRubberBand;

//! List to store the points of digitized lines and polygons (in layer coordinates)
QgsCompoundCurve mCaptureCurve;
Expand Down

0 comments on commit a4eb6b0

Please sign in to comment.