QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsTracer
Definition: qgstracer.h:43
qgsrectangle.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsTracer::ErrNoPath
@ ErrNoPath
Points are not connected in the graph.
Definition: qgstracer.h:138
QgsTracer::offset
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath().
Definition: qgstracer.h:87
qgsfeatureid.h
QgsTracer::layers
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition: qgstracer.h:55
QgsRectangle
Definition: qgsrectangle.h:41
QgsTracer::ErrPoint2
@ ErrPoint2
End point cannot be joined to the graph.
Definition: qgstracer.h:137
QgsTracer::isInitialized
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:122
QgsTracer::extent
QgsRectangle extent() const
Gets extent to which graph's features will be limited (empty extent means no limit)
Definition: qgstracer.h:78
QgsTracer::ErrTooManyFeatures
@ ErrTooManyFeatures
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:135
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:111
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:109
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsTracer::hasTopologyProblem
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition: qgstracer.h:129
QgsPointXY
Definition: qgspointxy.h:43
QgsTracer::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition: qgstracer.h:63
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsTracer::ErrNone
@ ErrNone
No error.
Definition: qgstracer.h:134
QgsGeometry
Definition: qgsgeometry.h:122
QgsTracerGraph
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:94
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsTracer::configure
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:158
QgsTracer::PathError
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:132
qgscoordinatereferencesystem.h
QgsTracer::ErrPoint1
@ ErrPoint1
Start point cannot be joined to the graph.
Definition: qgstracer.h:136
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25