Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new class QgsMapToolCaptureLayerGeometry to handle layer specific…
… operation in capture map tool such as avoiding intersections
- Loading branch information
Showing
11 changed files
with
235 additions
and
54 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
python/gui/auto_generated/maptools/qgsmaptoolcapturelayergeometry.sip.in
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,67 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/maptools/qgsmaptoolcapturelayergeometry.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsMapToolCaptureLayerGeometry : QgsMapToolCapture | ||
{ | ||
%Docstring(signature="appended") | ||
:py:class:`QgsMapToolCaptureLayerGeometry` is a base class for map tools digitizing layer geometries | ||
It will implement avoid intersections | ||
|
||
.. versionadded:: 3.24 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsmaptoolcapturelayergeometry.h" | ||
%End | ||
public: | ||
QgsMapToolCaptureLayerGeometry( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode ); | ||
%Docstring | ||
Constructor | ||
%End | ||
|
||
private: | ||
virtual void layerGeometryCaptured( const QgsGeometry &geometry ); | ||
%Docstring | ||
Called when the geometry is captured | ||
A more specific handler is also called afterwards (pointCaptured, lineCaptured or polygonCaptured) | ||
|
||
.. versionadded:: 3.24 | ||
%End | ||
virtual void layerPointCaptured( const QgsPoint &point ); | ||
%Docstring | ||
Called when a point is captured | ||
geometryCaptured is called just before | ||
|
||
.. versionadded:: 3.24 | ||
%End | ||
virtual void layerLineCaptured( const QgsCurve *line ); | ||
%Docstring | ||
Called when a line is captured | ||
geometryCaptured is called just before | ||
|
||
.. versionadded:: 3.24 | ||
%End | ||
virtual void layerPolygonCaptured( const QgsCurvePolygon *polygon ); | ||
%Docstring | ||
Called when a polygon is captured | ||
geometryCaptured is called just before | ||
|
||
.. versionadded:: 3.24 | ||
%End | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/maptools/qgsmaptoolcapturelayergeometry.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
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
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,74 @@ | ||
/*************************************************************************** | ||
qgsmaptoolcapturelayergeometry.cpp - base class for map tools digitizing layer geometries | ||
--------------------- | ||
begin : January 2022 | ||
copyright : (C) Denis Rouzaud | ||
email : denis@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 "qgsmaptoolcapturelayergeometry.h" | ||
#include "qgsproject.h" | ||
#include "qgscurvepolygon.h" | ||
#include "qgscurve.h" | ||
|
||
|
||
QgsMapToolCaptureLayerGeometry::QgsMapToolCaptureLayerGeometry( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode ) | ||
: QgsMapToolCapture( canvas, cadDockWidget, mode ) | ||
{ | ||
|
||
} | ||
|
||
|
||
void QgsMapToolCaptureLayerGeometry::geometryCaptured( const QgsGeometry &geometry ) | ||
{ | ||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer() ); | ||
if ( !vlayer ) | ||
return; | ||
|
||
QgsGeometry g( geometry ); | ||
QList<QgsVectorLayer *> avoidIntersectionsLayers; | ||
switch ( QgsProject::instance()->avoidIntersectionsMode() ) | ||
{ | ||
case QgsProject::AvoidIntersectionsMode::AvoidIntersectionsCurrentLayer: | ||
if ( vlayer ) | ||
avoidIntersectionsLayers.append( vlayer ); | ||
break; | ||
case QgsProject::AvoidIntersectionsMode::AvoidIntersectionsLayers: | ||
avoidIntersectionsLayers = QgsProject::instance()->avoidIntersectionsLayers(); | ||
break; | ||
case QgsProject::AvoidIntersectionsMode::AllowIntersections: | ||
break; | ||
} | ||
if ( avoidIntersectionsLayers.size() > 0 ) | ||
{ | ||
const int avoidIntersectionsReturn = g.avoidIntersections( avoidIntersectionsLayers ); | ||
if ( avoidIntersectionsReturn == 3 ) | ||
{ | ||
emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid. These geometries must be manually repaired." ), Qgis::MessageLevel::Warning ); | ||
} | ||
if ( g.isEmpty() ) //avoid intersection might have removed the whole geometry | ||
{ | ||
emit messageEmitted( tr( "The feature cannot be added because its geometry collapsed due to intersection avoidance" ), Qgis::MessageLevel::Critical ); | ||
stopCapturing(); | ||
return; | ||
} | ||
} | ||
|
||
layerGeometryCaptured( g ); | ||
if ( mode() == CaptureLine ) | ||
{ | ||
layerLineCaptured( qgsgeometry_cast<const QgsCurve *>( g.constGet() ) ); | ||
} | ||
else | ||
{ | ||
layerPolygonCaptured( qgsgeometry_cast<const QgsCurvePolygon *>( g.constGet() ) ); | ||
} | ||
} |
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,68 @@ | ||
/*************************************************************************** | ||
qgsmaptoolcapturelayergeometry.h - base class for map tools digitizing layer geometries | ||
--------------------- | ||
begin : January 2022 | ||
copyright : (C) Denis Rouzaud | ||
email : denis@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 QGSMAPTOOLCAPTURELAYERGEOMETRY_H | ||
#define QGSMAPTOOLCAPTURELAYERGEOMETRY_H | ||
|
||
#include "qgsmaptoolcapture.h" | ||
|
||
class QgsAdvancedDigitizingDockWidget; | ||
class QgsMapCanvas; | ||
|
||
/** | ||
* \ingroup gui | ||
* QgsMapToolCaptureLayerGeometry is a base class for map tools digitizing layer geometries | ||
* It will implement avoid intersections | ||
* \since QGIS 3.24 | ||
*/ | ||
class GUI_EXPORT QgsMapToolCaptureLayerGeometry : public QgsMapToolCapture | ||
{ | ||
public: | ||
//! Constructor | ||
QgsMapToolCaptureLayerGeometry( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode ); | ||
|
||
private: | ||
void geometryCaptured( const QgsGeometry &geometry ) override; | ||
|
||
/** | ||
* Called when the geometry is captured | ||
* A more specific handler is also called afterwards (pointCaptured, lineCaptured or polygonCaptured) | ||
* \since QGIS 3.24 | ||
*/ | ||
virtual void layerGeometryCaptured( const QgsGeometry &geometry ) {Q_UNUSED( geometry )} SIP_FORCE | ||
|
||
/** | ||
* Called when a point is captured | ||
* geometryCaptured is called just before | ||
* \since QGIS 3.24 | ||
*/ | ||
virtual void layerPointCaptured( const QgsPoint &point ) {Q_UNUSED( point )} SIP_FORCE | ||
|
||
/** | ||
* Called when a line is captured | ||
* geometryCaptured is called just before | ||
* \since QGIS 3.24 | ||
*/ | ||
virtual void layerLineCaptured( const QgsCurve *line ) {Q_UNUSED( line )} SIP_FORCE | ||
|
||
/** | ||
* Called when a polygon is captured | ||
* geometryCaptured is called just before | ||
* \since QGIS 3.24 | ||
*/ | ||
virtual void layerPolygonCaptured( const QgsCurvePolygon *polygon ) {Q_UNUSED( polygon )} SIP_FORCE | ||
}; | ||
|
||
#endif // QGSMAPTOOLCAPTURELAYERGEOMETRY_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
Oops, something went wrong.