QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
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
44class CORE_EXPORT QgsTracer : public QObject
45{
46 Q_OBJECT
47 public:
48
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
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
JoinStyle
Join styles for buffers.
Definition qgis.h:1599
@ 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.
A class to represent a 2D point.
Definition qgspointxy.h:59
A rectangle specified with double values.
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:45
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
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition qgstracer.h:134
PathError
Possible errors that may happen when calling findShortestPath()
Definition qgstracer.h:138
@ ErrNoPath
Points are not connected in the graph.
Definition qgstracer.h:143
@ ErrPoint2
End point cannot be joined to the graph.
Definition qgstracer.h:142
@ ErrPoint1
Start point cannot be joined to the graph.
Definition qgstracer.h:141
@ ErrNone
No error.
Definition qgstracer.h:139
@ ErrTooManyFeatures
Max feature count threshold was reached while reading features.
Definition qgstracer.h:140
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:79
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
Definition qgstracer.h:114
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath().
Definition qgstracer.h:88
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition qgstracer.h:64
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition qgstracer.h:56
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition qgstracer.h:163
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition qgstracer.h:127
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
const QgsCoordinateReferenceSystem & crs
Simple graph structure for shortest path search.
Definition qgstracer.cpp:96