QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgstracer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstracer.h
3 --------------------------------------
4 Date : January 2016
5 Copyright : (C) 2016 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
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#ifndef QGSTRACER_H
17#define QGSTRACER_H
18
19class QgsVectorLayer;
20
21#include <memory>
22
23#include "qgis_core.h"
26#include "qgsfeatureid.h"
27#include "qgsgeometry.h"
28#include "qgsrectangle.h"
29
30#include <QSet>
31#include <QVector>
32
33struct QgsTracerGraph;
36
44class CORE_EXPORT QgsTracer : public QObject
45{
46 Q_OBJECT
47 public:
48
53 ~QgsTracer() override;
54
56 QList<QgsVectorLayer *> layers() const { return mLayers; }
58 void setLayers( const QList<QgsVectorLayer *> &layers );
59
65
70 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
71
76 void setRenderContext( const QgsRenderContext *renderContext );
77
79 QgsRectangle extent() const { return mExtent; }
81 void setExtent( const QgsRectangle &extent );
82
87 double offset() const { return mOffset; }
88
93 void setOffset( double offset );
94
95 // TODO QGIS 4.0 -- use Qgis::JoinStyle instead of int!
96
100 void offsetParameters( int &quadSegments SIP_OUT, int &joinStyle SIP_OUT, double &miterLimit SIP_OUT );
101
102 // TODO QGIS 4.0 -- use Qgis::JoinStyle instead of int!
103
107 void setOffsetParameters( int quadSegments, int joinStyle, double miterLimit );
108
110 int maxFeatureCount() const { return mMaxFeatureCount; }
112 void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
113
120 bool init();
121
123 bool isInitialized() const { return static_cast< bool >( mGraph ); }
124
129 bool hasTopologyProblem() const { return mHasTopologyProblem; }
130
140
146 QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
147
149 bool isPointSnapped( const QgsPointXY &pt );
150
156 void setAddPointsOnIntersectionsEnabled( bool enable );
157
163 bool addPointsOnIntersectionsEnabled() const { return mAddPointsOnIntersections; }
164 protected:
165
171 virtual void configure() {}
172
173 protected slots:
175 void invalidateGraph();
176
177 private:
178 bool initGraph();
179
180 private slots:
181 void onFeatureAdded( QgsFeatureId fid );
182 void onFeatureDeleted( QgsFeatureId fid );
183 void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
184 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
185 void onDataChanged( );
186 void onStyleChanged( );
187 void onLayerDestroyed( QObject *obj );
188
189 private:
191 std::unique_ptr< QgsTracerGraph > mGraph;
193 QList<QgsVectorLayer *> mLayers;
197 QgsCoordinateTransformContext mTransformContext;
199 std::unique_ptr<QgsRenderContext> mRenderContext;
201 QgsRectangle mExtent;
203 bool mAddPointsOnIntersections = true;
205 QgsGeometry mIntersections;
206
208 double mOffset = 0;
210 int mOffsetSegments = 8;
212 Qgis::JoinStyle mOffsetJoinStyle = Qgis::JoinStyle::Miter;
214 double mOffsetMiterLimit = 5.;
215
220 int mMaxFeatureCount = 0;
221
226 bool mHasTopologyProblem = false;
227};
228
229
230#endif // QGSTRACER_H
JoinStyle
Join styles for buffers.
Definition qgis.h:2121
@ Miter
Use mitered joins.
Definition qgis.h:2123
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for all 2D vector feature renderers.
A geometry is the spatial representation of a feature.
Represents a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
Contains information about the context of a rendering operation.
void setMaxFeatureCount(int count)
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition qgstracer.h:112
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition qgstracer.h:129
PathError
Possible errors that may happen when calling findShortestPath().
Definition qgstracer.h:133
@ ErrNoPath
Points are not connected in the graph.
Definition qgstracer.h:138
@ ErrPoint2
End point cannot be joined to the graph.
Definition qgstracer.h:137
@ ErrPoint1
Start point cannot be joined to the graph.
Definition qgstracer.h:136
@ ErrNone
No error.
Definition qgstracer.h:134
@ ErrTooManyFeatures
Max feature count threshold was reached while reading features.
Definition qgstracer.h:135
QgsTracer()
Constructor for QgsTracer.
QgsRectangle extent() const
Gets extent to which graph's features will be limited (empty extent means no limit).
Definition qgstracer.h:79
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition qgstracer.h:110
bool addPointsOnIntersectionsEnabled() const
Returns whether the shortest path's straight segments will include vertices where the input layers in...
Definition qgstracer.h:163
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath().
Definition qgstracer.h:87
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition qgstracer.h:64
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition qgstracer.h:56
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition qgstracer.h:171
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition qgstracer.h:123
Represents a vector layer which manages a vector based dataset.
#define SIP_OUT
Definition qgis_sip.h:58
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Simple graph structure for shortest path search.
Definition qgstracer.cpp:99