QGIS API Documentation  3.17.0-Master (3b262f2a79)
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"
28 #include "qgsrectangle.h"
29 #include "qgsgeometry.h"
30 
31 struct QgsTracerGraph;
32 class QgsFeatureRenderer;
33 class QgsRenderContext;
34 
43 class CORE_EXPORT QgsTracer : public QObject
44 {
45  Q_OBJECT
46  public:
47 
51  QgsTracer();
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 
87  double offset() const { return mOffset; }
88 
94  void setOffset( double offset );
95 
100  void offsetParameters( int &quadSegments SIP_OUT, int &joinStyle SIP_OUT, double &miterLimit SIP_OUT );
101 
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 
129  bool hasTopologyProblem() const { return mHasTopologyProblem; }
130 
133  {
139  };
140 
146  QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
147 
149  bool isPointSnapped( const QgsPointXY &pt );
150 
151  protected:
152 
158  virtual void configure() {}
159 
160  protected slots:
162  void invalidateGraph();
163 
164  private:
165  bool initGraph();
166 
167  private slots:
168  void onFeatureAdded( QgsFeatureId fid );
169  void onFeatureDeleted( QgsFeatureId fid );
170  void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
171  void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
172  void onDataChanged( );
173  void onStyleChanged( );
174  void onLayerDestroyed( QObject *obj );
175 
176  private:
178  std::unique_ptr< QgsTracerGraph > mGraph;
180  QList<QgsVectorLayer *> mLayers;
184  QgsCoordinateTransformContext mTransformContext;
186  std::unique_ptr<QgsRenderContext> mRenderContext;
188  QgsRectangle mExtent;
189 
191  double mOffset = 0;
193  int mOffsetSegments = 8;
195  int mOffsetJoinStyle = 2;
197  double mOffsetMiterLimit = 5.;
198 
203  int mMaxFeatureCount = 0;
204 
209  bool mHasTopologyProblem = false;
210 };
211 
212 
213 #endif // QGSTRACER_H
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition: qgstracer.h:55
A rectangle specified with double values.
Definition: qgsrectangle.h:41
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:122
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:158
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition: qgstracer.h:43
A class to represent a 2D point.
Definition: qgspointxy.h:43
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition: qgstracer.h:63
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:123
const QgsCoordinateReferenceSystem & crs
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition: qgstracer.h:129
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath()...
Definition: qgstracer.h:87
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:109
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:135
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:132
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:94
Contains information about the context in which a coordinate transform is executed.
End point cannot be joined to the graph.
Definition: qgstracer.h:137
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:111
#define SIP_OUT
Definition: qgis_sip.h:58
This class represents a coordinate reference system (CRS).
QgsRectangle extent() const
Gets extent to which graph&#39;s features will be limited (empty extent means no limit) ...
Definition: qgstracer.h:78
No error.
Definition: qgstracer.h:134
Represents a vector layer which manages a vector based data sets.
Points are not connected in the graph.
Definition: qgstracer.h:138
Start point cannot be joined to the graph.
Definition: qgstracer.h:136