QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
132 {
138 };
139
145 QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
146
148 bool isPointSnapped( const QgsPointXY &pt );
149
150 protected:
151
157 virtual void configure() {}
158
159 protected slots:
161 void invalidateGraph();
162
163 private:
164 bool initGraph();
165
166 private slots:
167 void onFeatureAdded( QgsFeatureId fid );
168 void onFeatureDeleted( QgsFeatureId fid );
169 void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
170 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
171 void onDataChanged( );
172 void onStyleChanged( );
173 void onLayerDestroyed( QObject *obj );
174
175 private:
177 std::unique_ptr< QgsTracerGraph > mGraph;
179 QList<QgsVectorLayer *> mLayers;
183 QgsCoordinateTransformContext mTransformContext;
185 std::unique_ptr<QgsRenderContext> mRenderContext;
187 QgsRectangle mExtent;
188
190 double mOffset = 0;
192 int mOffsetSegments = 8;
194 Qgis::JoinStyle mOffsetJoinStyle = Qgis::JoinStyle::Miter;
196 double mOffsetMiterLimit = 5.;
197
202 int mMaxFeatureCount = 0;
203
208 bool mHasTopologyProblem = false;
209};
210
211
212#endif // QGSTRACER_H
JoinStyle
Join styles for buffers.
Definition: qgis.h:1694
@ Miter
Use mitered joins.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:162
A class to represent a 2D point.
Definition: qgspointxy.h:60
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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
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:157
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
Definition: qgsfeatureid.h:28
const QgsCoordinateReferenceSystem & crs
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:96