Skip to content
Permalink
Browse files

Use QgsGeometry API for offset tool instead of raw geos calls

  • Loading branch information
nyalldawson committed Nov 28, 2017
1 parent dacced8 commit 9aa5752643b0f3a268ebc893b5e5ba9077fc0a89
Showing with 24 additions and 32 deletions.
  1. +20 −28 src/app/qgsmaptooloffsetcurve.cpp
  2. +4 −4 src/app/qgsmaptooloffsetcurve.h
@@ -25,7 +25,6 @@
#include "qgssnappingconfig.h"
#include "qgssettings.h"
#include "qgisapp.h"
#include "qgsgeos.h"

#include <QGraphicsProxyWidget>
#include <QMouseEvent>
@@ -360,34 +359,27 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
return;
}

QgsGeometry geomCopy( mOriginalGeometry );
geos::unique_ptr geosGeom( geomCopy.exportToGeos() );
if ( geosGeom )
{
QgsSettings s;
int joinStyle = s.value( QStringLiteral( "/qgis/digitizing/offset_join_style" ), 0 ).toInt();
int quadSegments = s.value( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), 8 ).toInt();
double miterLimit = s.value( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), 5.0 ).toDouble();

geos::unique_ptr offsetGeom( GEOSOffsetCurve_r( QgsGeometry::getGEOSHandler(), geosGeom.get(), offset, quadSegments, joinStyle, miterLimit ) );
if ( !offsetGeom )
{
deleteRubberBandAndGeometry();
deleteDistanceWidget();
delete mSnapVertexMarker;
mSnapVertexMarker = nullptr;
mForceCopy = false;
mGeometryModified = false;
deleteDistanceWidget();
emit messageEmitted( tr( "Creating offset geometry failed" ), QgsMessageBar::CRITICAL );
return;
}
QgsSettings s;
QgsGeometry::JoinStyle joinStyle = static_cast< QgsGeometry::JoinStyle >( s.value( QStringLiteral( "/qgis/digitizing/offset_join_style" ), 0 ).toInt() );
int quadSegments = s.value( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), 8 ).toInt();
double miterLimit = s.value( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), 5.0 ).toDouble();

if ( offsetGeom )
{
mModifiedGeometry.fromGeos( offsetGeom.release() );
mRubberBand->setToGeometry( mModifiedGeometry, sourceLayer );
}
QgsGeometry offsetGeom = mOriginalGeometry.offsetCurve( offset, quadSegments, joinStyle, miterLimit );
if ( !offsetGeom )
{
deleteRubberBandAndGeometry();
deleteDistanceWidget();
delete mSnapVertexMarker;
mSnapVertexMarker = nullptr;
mForceCopy = false;
mGeometryModified = false;
deleteDistanceWidget();
emit messageEmitted( tr( "Creating offset geometry failed: %1" ).arg( offsetGeom.lastError() ), QgsMessageBar::CRITICAL );
}
else
{
mModifiedGeometry = offsetGeom;
mRubberBand->setToGeometry( mModifiedGeometry, sourceLayer );
}
}

@@ -49,18 +49,18 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
//! Geometry after manipulation
QgsGeometry mModifiedGeometry;
//! ID of manipulated feature
QgsFeatureId mModifiedFeature;
QgsFeatureId mModifiedFeature = -1;
//! Layer ID of source layer
QString mSourceLayerId;
//! Internal flag to distinguish move from click
bool mGeometryModified;
bool mGeometryModified = false;
//! Shows current distance value and allows numerical editing
QgsDoubleSpinBox *mDistanceWidget = nullptr;
//! Marker to show the cursor was snapped to another location
QgsVertexMarker *mSnapVertexMarker = nullptr;
//! Forces geometry copy (no modification of geometry in current layer)
bool mForceCopy;
bool mMultiPartGeometry;
bool mForceCopy = false;
bool mMultiPartGeometry = false;


void deleteRubberBandAndGeometry();

0 comments on commit 9aa5752

Please sign in to comment.
You can’t perform that action at this time.