Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
QgsMapToolCapture support circular curve
  • Loading branch information
vcloarec committed Jul 29, 2020
1 parent 24b1b3b commit 2e3fabf
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 73 deletions.
11 changes: 9 additions & 2 deletions python/gui/auto_generated/qgsgeometryrubberband.sip.in
Expand Up @@ -9,6 +9,7 @@




%ModuleHeaderCode
// For ConvertToSubClassCode.
#include <qgsgeometryrubberband.h>
Expand Down Expand Up @@ -48,9 +49,9 @@ A rubberband class for QgsAbstractGeometry (considering curved geometries)*
};

QgsGeometryRubberBand( QgsMapCanvas *mapCanvas, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::LineGeometry );
~QgsGeometryRubberBand();
virtual ~QgsGeometryRubberBand();

void setGeometry( QgsAbstractGeometry *geom /Transfer/ );
virtual void setGeometry( QgsAbstractGeometry *geom /Transfer/ );
%Docstring
Sets geometry (takes ownership). Geometry is expected to be in map coordinates
%End
Expand Down Expand Up @@ -85,14 +86,20 @@ Sets brush style
void setIconType( IconType iconType );
%Docstring
Sets vertex marker icon type
%End
void setIsVerticesDrawn( bool isVerticesDrawn );
%Docstring
Sets whether the vertices are drawn
%End

protected:
virtual void paint( QPainter *painter );

QgsWkbTypes::GeometryType geometryType() const;

};


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1571,6 +1571,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QShortcut *shortcutTracing = new QShortcut( QKeySequence( tr( "Ctrl+Shift+." ) ), this );
connect( shortcutTracing, &QShortcut::activated, this, &QgisApp::toggleEventTracing );

QShortcut *shortcutToggleLinearCircularDigitizing = new QShortcut( QKeySequence( tr( "Ctrl+Shift+G" ) ), this );
connect( shortcutToggleLinearCircularDigitizing, &QShortcut::activated, mMapTools.mAddFeature, &QgsMapToolCapture::toggleLinearCircularDigitizing );
connect( shortcutToggleLinearCircularDigitizing, &QShortcut::activated,
static_cast<QgsMapToolSplitFeatures *>( mMapTools.mSplitFeatures ), &QgsMapToolCapture::toggleLinearCircularDigitizing );

if ( ! QTouchDevice::devices().isEmpty() )
{
//add reacting to long click in touch
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolsplitfeatures.cpp
Expand Up @@ -94,7 +94,7 @@ void QgsMapToolSplitFeatures::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
//bring up dialog if a split was not possible (polygon) or only done once (line)
int topologicalEditing = QgsProject::instance()->topologicalEditing();
vlayer->beginEditCommand( tr( "Features split" ) );
QgsGeometry::OperationResult returnCode = vlayer->splitFeatures( pointsZM(), topologicalEditing );
QgsGeometry::OperationResult returnCode = vlayer->splitFeatures( captureCurve(), true, topologicalEditing );
vlayer->endEditCommand();
if ( returnCode == QgsGeometry::OperationResult::NothingHappened )
{
Expand Down
17 changes: 14 additions & 3 deletions src/gui/qgsgeometryrubberband.cpp
Expand Up @@ -30,7 +30,6 @@ QgsGeometryRubberBand::QgsGeometryRubberBand( QgsMapCanvas *mapCanvas, QgsWkbTyp

QgsGeometryRubberBand::~QgsGeometryRubberBand()
{
delete mGeometry;
}

void QgsGeometryRubberBand::paint( QPainter *painter )
Expand Down Expand Up @@ -59,6 +58,9 @@ void QgsGeometryRubberBand::paint( QPainter *painter )
paintGeom->transform( mMapCanvas->getCoordinateTransform()->transform() );
paintGeom->draw( *painter );

if ( !mDrawVertices )
return;

//draw vertices
QgsVertexId vertexId;
QgsPoint vertex;
Expand All @@ -68,6 +70,11 @@ void QgsGeometryRubberBand::paint( QPainter *painter )
}
}

QgsWkbTypes::GeometryType QgsGeometryRubberBand::geometryType() const
{
return mGeometryType;
}

void QgsGeometryRubberBand::drawVertex( QPainter *p, double x, double y )
{
qreal s = ( mIconSize - 1 ) / 2.0;
Expand Down Expand Up @@ -106,8 +113,7 @@ void QgsGeometryRubberBand::drawVertex( QPainter *p, double x, double y )

void QgsGeometryRubberBand::setGeometry( QgsAbstractGeometry *geom )
{
delete mGeometry;
mGeometry = geom;
mGeometry.reset( geom );

if ( mGeometry )
{
Expand Down Expand Up @@ -149,6 +155,11 @@ void QgsGeometryRubberBand::setBrushStyle( Qt::BrushStyle brushStyle )
mBrush.setStyle( brushStyle );
}

void QgsGeometryRubberBand::setIsVerticesDrawn( bool isVerticesDrawn )
{
mDrawVertices = isVerticesDrawn;
}

QgsRectangle QgsGeometryRubberBand::rubberBandRectangle() const
{
qreal scale = mMapCanvas->mapUnitsPerPixel();
Expand Down
19 changes: 15 additions & 4 deletions src/gui/qgsgeometryrubberband.h
Expand Up @@ -24,6 +24,12 @@
#include <QPen>
#include "qgis_gui.h"

#include "qgscompoundcurve.h"
#include "qgscurvepolygon.h"
#include "qgscircularstring.h"
#include "qgslinestring.h"
#include "qgspoint.h"

#ifdef SIP_RUN
% ModuleHeaderCode
// For ConvertToSubClassCode.
Expand Down Expand Up @@ -86,12 +92,12 @@ class GUI_EXPORT QgsGeometryRubberBand: public QgsMapCanvasItem
};

QgsGeometryRubberBand( QgsMapCanvas *mapCanvas, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::LineGeometry );
~QgsGeometryRubberBand() override;
virtual ~QgsGeometryRubberBand() override;

//! Sets geometry (takes ownership). Geometry is expected to be in map coordinates
void setGeometry( QgsAbstractGeometry *geom SIP_TRANSFER );
virtual void setGeometry( QgsAbstractGeometry *geom SIP_TRANSFER );
//! Returns a pointer to the geometry
const QgsAbstractGeometry *geometry() { return mGeometry; }
const QgsAbstractGeometry *geometry() { return mGeometry.get(); }
//! Moves vertex to new position (in map coordinates)
void moveVertex( QgsVertexId id, const QgsPoint &newPos );
//! Sets fill color for vertex markers
Expand All @@ -106,20 +112,25 @@ class GUI_EXPORT QgsGeometryRubberBand: public QgsMapCanvasItem
void setBrushStyle( Qt::BrushStyle brushStyle );
//! Sets vertex marker icon type
void setIconType( IconType iconType ) { mIconType = iconType; }
//! Sets whether the vertices are drawn
void setIsVerticesDrawn( bool isVerticesDrawn );

protected:
void paint( QPainter *painter ) override;
QgsWkbTypes::GeometryType geometryType() const;

private:
QgsAbstractGeometry *mGeometry = nullptr;
std::unique_ptr<QgsAbstractGeometry> mGeometry = nullptr;
QBrush mBrush;
QPen mPen;
int mIconSize;
IconType mIconType;
QgsWkbTypes::GeometryType mGeometryType;
bool mDrawVertices = true;

void drawVertex( QPainter *p, double x, double y );
QgsRectangle rubberBandRectangle() const;
};


#endif // QGSGEOMETRYRUBBERBAND_H

0 comments on commit 2e3fabf

Please sign in to comment.