QGIS API Documentation  2.14.0-Essen
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 <QSet>
22 #include <QVector>
23 
25 #include "qgsfeature.h"
26 #include "qgspoint.h"
27 #include "qgsrectangle.h"
28 
29 struct QgsTracerGraph;
30 
38 class CORE_EXPORT QgsTracer : public QObject
39 {
40  Q_OBJECT
41  public:
42  QgsTracer();
43  ~QgsTracer();
44 
46  QList<QgsVectorLayer*> layers() const { return mLayers; }
48  void setLayers( const QList<QgsVectorLayer*>& layers );
49 
51  bool hasCrsTransformEnabled() const { return mReprojectionEnabled; }
53  void setCrsTransformEnabled( bool enabled );
54 
58  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
59 
61  QgsRectangle extent() const { return mExtent; }
63  void setExtent( const QgsRectangle& extent );
64 
66  int maxFeatureCount() const { return mMaxFeatureCount; }
68  void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
69 
74  bool init();
75 
77  bool isInitialized() const { return mGraph != nullptr; }
78 
80  enum PathError
81  {
87  };
88 
92  QVector<QgsPoint> findShortestPath( const QgsPoint& p1, const QgsPoint& p2, PathError* error = nullptr );
93 
95  bool isPointSnapped( const QgsPoint& pt );
96 
97  protected:
101  virtual void configure() {}
102 
103  protected slots:
105  void invalidateGraph();
106 
107  private:
108  bool initGraph();
109 
110  private slots:
111  void onFeatureAdded( QgsFeatureId fid );
112  void onFeatureDeleted( QgsFeatureId fid );
113  void onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom );
114  void onLayerDestroyed( QObject* obj );
115 
116  private:
118  QgsTracerGraph* mGraph;
120  QList<QgsVectorLayer*> mLayers;
122  bool mReprojectionEnabled;
126  QgsRectangle mExtent;
129  int mMaxFeatureCount;
130 };
131 
132 
133 #endif // QGSTRACER_H
bool hasCrsTransformEnabled() const
Return true if reprojection to destination CRS is enabled.
Definition: qgstracer.h:51
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:101
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition: qgstracer.h:38
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
int maxFeatureCount() const
Get maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:66
QgsCoordinateReferenceSystem destinationCrs() const
Get CRS used for tracing.
Definition: qgstracer.h:56
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:83
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:80
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:87
QList< QgsVectorLayer * > layers() const
Get layers used for tracing.
Definition: qgstracer.h:46
A class to represent a point.
Definition: qgspoint.h:65
End point cannot be joined to the graph.
Definition: qgstracer.h:85
void setMaxFeatureCount(int count)
Get maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:68
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:77
Class for storing a coordinate reference system (CRS)
qint64 QgsFeatureId
Definition: qgsfeature.h:31
No error.
Definition: qgstracer.h:82
QgsRectangle extent() const
Get extent to which graph&#39;s features will be limited (empty extent means no limit) ...
Definition: qgstracer.h:61
Represents a vector layer which manages a vector based data sets.
Points are not connected in the graph.
Definition: qgstracer.h:86
Start point cannot be joined to the graph.
Definition: qgstracer.h:84