QGIS API Documentation 3.39.0-Master (699c004a5df)
Loading...
Searching...
No Matches
qgsmaptoolcapturelayergeometry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolcapturelayergeometry.cpp - base class for map tools digitizing layer geometries
3 ---------------------
4 begin : January 2022
5 copyright : (C) Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
18#include "qgsproject.h"
19#include "qgscurvepolygon.h"
20#include "qgscurve.h"
21
22
23
24
25void QgsMapToolCaptureLayerGeometry::geometryCaptured( const QgsGeometry &geometry )
26{
27 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer() );
28 if ( !vlayer )
29 return;
30
31 QgsGeometry g( geometry );
32
33 switch ( mode() )
34 {
37 break;
40 //does provider support circular strings?
41 const bool datasetIsCurved = QgsWkbTypes::isCurvedType( vlayer->wkbType() );
42 const bool providerSupportsCurvedSegments = vlayer && ( vlayer->dataProvider()->capabilities() & Qgis::VectorProviderCapability::CircularGeometries );
43 if ( !datasetIsCurved || !providerSupportsCurvedSegments )
44 g = QgsGeometry( g.constGet()->segmentize() );
45
46 QList<QgsVectorLayer *> avoidIntersectionsLayers;
47 switch ( QgsProject::instance()->avoidIntersectionsMode() )
48 {
50 if ( vlayer )
51 avoidIntersectionsLayers.append( vlayer );
52 break;
54 avoidIntersectionsLayers = QgsProject::instance()->avoidIntersectionsLayers();
55 break;
57 break;
58 }
59 if ( avoidIntersectionsLayers.size() > 0 )
60 {
61 const Qgis::GeometryOperationResult avoidIntersectionsReturn = g.avoidIntersectionsV2( avoidIntersectionsLayers );
62 if ( avoidIntersectionsReturn == Qgis::GeometryOperationResult::InvalidBaseGeometry )
63 {
64 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 );
65 }
66 if ( g.isEmpty() ) //avoid intersection might have removed the whole geometry
67 {
68 emit messageEmitted( tr( "The feature cannot be added because its geometry collapsed due to intersection avoidance" ), Qgis::MessageLevel::Critical );
70 return;
71 }
72 }
73 break;
74 }
75
76 layerGeometryCaptured( g );
77
78 switch ( mode() )
79 {
81 break;
83 layerPointCaptured( *qgsgeometry_cast<const QgsPoint *>( g.constGet() ) );
84 break;
86 layerLineCaptured( qgsgeometry_cast<const QgsCurve *>( g.constGet() ) );
87 break;
89 layerPolygonCaptured( qgsgeometry_cast<const QgsCurvePolygon *>( g.constGet() ) );
90 break;
91 }
92}
@ CircularGeometries
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
GeometryOperationResult
Success or failure of a geometry operation.
Definition qgis.h:1889
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ Warning
Warning message.
Definition qgis.h:156
@ Critical
Critical/error message.
Definition qgis.h:157
@ AvoidIntersectionsLayers
Overlap with features from a specified list of layers when digitizing new features not allowed.
@ AllowIntersections
Overlap with any feature allowed when digitizing new features.
@ AvoidIntersectionsCurrentLayer
Overlap with features from the active layer when digitizing new features not allowed.
A geometry is the spatial representation of a feature.
virtual QgsMapLayer * layer() const
Returns the layer associated with the map tool.
void stopCapturing()
Stop capturing.
CaptureMode mode() const
The capture mode.
@ CapturePolygon
Capture polygons.
@ CaptureNone
Do not capture / determine mode from layer geometry type.
@ CapturePoint
Capture points.
@ CaptureLine
Capture lines.
void messageEmitted(const QString &message, Qgis::MessageLevel=Qgis::MessageLevel::Info)
emit a message
static QgsProject * instance()
Returns the QgsProject singleton instance.
QList< QgsVectorLayer * > avoidIntersectionsLayers
Definition qgsproject.h:119
virtual Q_INVOKABLE Qgis::VectorProviderCapabilities capabilities() const
Returns flags containing the supported capabilities.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
static bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.