QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
19 class 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 
32 struct QgsTracerGraph;
33 class QgsFeatureRenderer;
34 class QgsRenderContext;
35 
44 class CORE_EXPORT QgsTracer : public QObject
45 {
46  Q_OBJECT
47  public:
48 
52  QgsTracer();
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 
88  double offset() const { return mOffset; }
89 
95  void setOffset( double offset );
96 
97  // TODO QGIS 4.0 -- use Qgis::JoinStyle instead of int!
98 
103  void offsetParameters( int &quadSegments SIP_OUT, int &joinStyle SIP_OUT, double &miterLimit SIP_OUT );
104 
105  // TODO QGIS 4.0 -- use Qgis::JoinStyle instead of int!
106 
111  void setOffsetParameters( int quadSegments, int joinStyle, double miterLimit );
112 
114  int maxFeatureCount() const { return mMaxFeatureCount; }
116  void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
117 
124  bool init();
125 
127  bool isInitialized() const { return static_cast< bool >( mGraph ); }
128 
134  bool hasTopologyProblem() const { return mHasTopologyProblem; }
135 
138  {
144  };
145 
151  QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
152 
154  bool isPointSnapped( const QgsPointXY &pt );
155 
156  protected:
157 
163  virtual void configure() {}
164 
165  protected slots:
167  void invalidateGraph();
168 
169  private:
170  bool initGraph();
171 
172  private slots:
173  void onFeatureAdded( QgsFeatureId fid );
174  void onFeatureDeleted( QgsFeatureId fid );
175  void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
176  void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
177  void onDataChanged( );
178  void onStyleChanged( );
179  void onLayerDestroyed( QObject *obj );
180 
181  private:
183  std::unique_ptr< QgsTracerGraph > mGraph;
185  QList<QgsVectorLayer *> mLayers;
189  QgsCoordinateTransformContext mTransformContext;
191  std::unique_ptr<QgsRenderContext> mRenderContext;
193  QgsRectangle mExtent;
194 
196  double mOffset = 0;
198  int mOffsetSegments = 8;
200  Qgis::JoinStyle mOffsetJoinStyle = Qgis::JoinStyle::Miter;
202  double mOffsetMiterLimit = 5.;
203 
208  int mMaxFeatureCount = 0;
209 
214  bool mHasTopologyProblem = false;
215 };
216 
217 
218 #endif // QGSTRACER_H
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsTracer
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition: qgstracer.h:44
qgsrectangle.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
qgscoordinatetransformcontext.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsTracer::ErrNoPath
@ ErrNoPath
Points are not connected in the graph.
Definition: qgstracer.h:143
QgsTracer::offset
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath().
Definition: qgstracer.h:88
qgsfeatureid.h
QgsTracer::layers
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition: qgstracer.h:56
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsTracer::ErrPoint2
@ ErrPoint2
End point cannot be joined to the graph.
Definition: qgstracer.h:142
QgsTracer::isInitialized
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:127
QgsTracer::extent
QgsRectangle extent() const
Gets extent to which graph's features will be limited (empty extent means no limit)
Definition: qgstracer.h:79
QgsTracer::ErrTooManyFeatures
@ ErrTooManyFeatures
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:140
QgsTracer::setMaxFeatureCount
void setMaxFeatureCount(int count)
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition: qgstracer.h:116
Qgis::JoinStyle
JoinStyle
Join styles for buffers.
Definition: qgis.h:979
QgsTracer::maxFeatureCount
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition: qgstracer.h:114
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsTracer::hasTopologyProblem
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition: qgstracer.h:134
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsTracer::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition: qgstracer.h:64
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsTracer::ErrNone
@ ErrNone
No error.
Definition: qgstracer.h:139
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsTracerGraph
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:95
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsTracer::configure
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:163
QgsTracer::PathError
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:137
qgscoordinatereferencesystem.h
QgsTracer::ErrPoint1
@ ErrPoint1
Start point cannot be joined to the graph.
Definition: qgstracer.h:141
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28