QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 "qgis_core.h"
22#include <QSet>
23#include <QVector>
24#include <memory>
25
26#include "qgsfeatureid.h"
29#include "qgsrectangle.h"
30#include "qgsgeometry.h"
31
32struct QgsTracerGraph;
35
43class CORE_EXPORT QgsTracer : public QObject
44{
45 Q_OBJECT
46 public:
47
52 ~QgsTracer() override;
53
55 QList<QgsVectorLayer *> layers() const { return mLayers; }
57 void setLayers( const QList<QgsVectorLayer *> &layers );
58
64
69 void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
70
75 void setRenderContext( const QgsRenderContext *renderContext );
76
78 QgsRectangle extent() const { return mExtent; }
80 void setExtent( const QgsRectangle &extent );
81
86 double offset() const { return mOffset; }
87
92 void setOffset( double offset );
93
94 // TODO QGIS 4.0 -- use Qgis::JoinStyle instead of int!
95
99 void offsetParameters( int &quadSegments SIP_OUT, int &joinStyle SIP_OUT, double &miterLimit SIP_OUT );
100
101 // TODO QGIS 4.0 -- use Qgis::JoinStyle instead of int!
102
106 void setOffsetParameters( int quadSegments, int joinStyle, double miterLimit );
107
109 int maxFeatureCount() const { return mMaxFeatureCount; }
111 void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
112
119 bool init();
120
122 bool isInitialized() const { return static_cast< bool >( mGraph ); }
123
128 bool hasTopologyProblem() const { return mHasTopologyProblem; }
129
139
145 QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
146
148 bool isPointSnapped( const QgsPointXY &pt );
149
155 void setAddPointsOnIntersectionsEnabled( bool enable );
156
162 bool addPointsOnIntersectionsEnabled() const { return mAddPointsOnIntersections; }
163 protected:
164
170 virtual void configure() {}
171
172 protected slots:
174 void invalidateGraph();
175
176 private:
177 bool initGraph();
178
179 private slots:
180 void onFeatureAdded( QgsFeatureId fid );
181 void onFeatureDeleted( QgsFeatureId fid );
182 void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
183 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
184 void onDataChanged( );
185 void onStyleChanged( );
186 void onLayerDestroyed( QObject *obj );
187
188 private:
190 std::unique_ptr< QgsTracerGraph > mGraph;
192 QList<QgsVectorLayer *> mLayers;
196 QgsCoordinateTransformContext mTransformContext;
198 std::unique_ptr<QgsRenderContext> mRenderContext;
200 QgsRectangle mExtent;
202 bool mAddPointsOnIntersections = false;
204 QgsGeometry mIntersections;
205
207 double mOffset = 0;
209 int mOffsetSegments = 8;
211 Qgis::JoinStyle mOffsetJoinStyle = Qgis::JoinStyle::Miter;
213 double mOffsetMiterLimit = 5.;
214
219 int mMaxFeatureCount = 0;
220
225 bool mHasTopologyProblem = false;
226};
227
228
229#endif // QGSTRACER_H
JoinStyle
Join styles for buffers.
Definition qgis.h:1968
@ Miter
Use mitered joins.
This class 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.
A class to represent a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition qgstracer.h:44
void setMaxFeatureCount(int count)
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition qgstracer.h:111
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition qgstracer.h:128
PathError
Possible errors that may happen when calling findShortestPath()
Definition qgstracer.h:132
@ ErrNoPath
Points are not connected in the graph.
Definition qgstracer.h:137
@ ErrPoint2
End point cannot be joined to the graph.
Definition qgstracer.h:136
@ ErrPoint1
Start point cannot be joined to the graph.
Definition qgstracer.h:135
@ ErrNone
No error.
Definition qgstracer.h:133
@ ErrTooManyFeatures
Max feature count threshold was reached while reading features.
Definition qgstracer.h:134
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:78
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition qgstracer.h:109
bool addPointsOnIntersectionsEnabled() const
Returns whether the shortest path's straight segments will include vertices where the input layers in...
Definition qgstracer.h:162
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath().
Definition qgstracer.h:86
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition qgstracer.h:63
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition qgstracer.h:55
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition qgstracer.h:170
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition qgstracer.h:122
Represents a vector layer which manages a vector based data sets.
#define SIP_OUT
Definition qgis_sip.h:58
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
const QgsCoordinateReferenceSystem & crs
Simple graph structure for shortest path search.
Definition qgstracer.cpp:97