QGIS API Documentation 3.99.0-Master (c03dd32cbdd)
Loading...
Searching...
No Matches
qgsmaptooleditblanksegments.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptooleditblanksegments.h
3 ---------------------
4 begin : 2025/08/19
5 copyright : (C) 2025 by Julien Cabieces
6 email : julien dot cabieces at oslandia 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 QGSMAPTOOLEDITBLANKSEGMENTS_H
17#define QGSMAPTOOLEDITBLANKSEGMENTS_H
18
19
20#include "qgsfeatureid.h"
21#include "qgslinesymbollayer.h"
22#include "qgsmapcanvasitem.h"
23#include "qgsmaptool.h"
24#include "qgsrubberband.h"
25#include "qgssymbol.h"
26#include "qobjectuniqueptr.h"
27
28#define SIP_NO_FILE
29
30class QgsMapToolBlankSegmentRubberBand;
31class QgsVectorLayer;
32class QgsSymbol;
33class QgsSymbolLayer;
34
53{
54 Q_OBJECT
55
56 public:
64 QgsMapToolEditBlankSegmentsBase( QgsMapCanvas *canvas, QgsVectorLayer *layer, QgsLineSymbolLayer *symbolLayer, int blankSegmentFieldIndex );
65
70
71 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
72 void canvasPressEvent( QgsMapMouseEvent *e ) override;
73 void keyPressEvent( QKeyEvent *e ) override;
74
75 void activate() override;
76
77 protected:
78 typedef QList<QList<QPolygonF>> FeaturePoints;
80
81 private:
85 QPair<double, double> startEndDistance() const;
86
90 void updateAttribute();
91
95 void loadFeaturePoints();
96
102 virtual QgsTemplatedLineSymbolLayerBase *createRenderedPointsSymbolLayer( const QgsTemplatedLineSymbolLayerBase *original ) = 0;
103
109 int closestBlankSegmentIndex( const QPointF &point, double &distance ) const;
110
119 QPointF closestPoint( const QPointF &point, double &distance, int &partIndex, int &ringIndex, int &pointIndex ) const;
120
125 void updateStartEndRubberBand();
126
130 void updateHoveredBlankSegment( const QPoint &pos );
131
135 void setCurrentBlankSegment( int currentBlankSegmentIndex );
136
143
147 enum State
148 {
149 SelectFeature,
150 FeatureSelected,
151 BlankSegmentSelected,
152 BlankSegmentModificationStarted,
153 BlankSegmentCreationStarted
154 };
155
156 std::vector<QObjectUniquePtr<QgsBlankSegmentRubberBand>> mBlankSegments;
157 QgsVectorLayer *mLayer = nullptr;
158 std::unique_ptr<QgsSymbol> mSymbol;
159 const QString mSymbolLayerId;
160 QgsTemplatedLineSymbolLayerBase *mSymbolLayer = nullptr;
161
162 int mBlankSegmentsFieldIndex = -1;
163 QgsFeatureId mCurrentFeatureId = FID_NULL;
164 QgsRectangle mExtent;
165 State mState = State::SelectFeature;
166 int mCurrentBlankSegmentIndex = -1;
167 int mHoveredBlankSegmentIndex = -1;
168
169 // currently edited blank segment, start point is the fixed point and end point is the currently
170 // modified one
172 QObjectUniquePtr<QgsRubberBand> mStartRubberBand;
173 QObjectUniquePtr<QgsRubberBand> mEndRubberBand;
174
176};
177
184template<class T>
186{
187 public:
196 : QgsMapToolEditBlankSegmentsBase( canvas, layer, symbolLayer, blankSegmentFieldIndex )
197 {
198 }
199
201 {
202 const T *sl = dynamic_cast<const T *>( originalSl );
203 return sl ? new QgsRenderedPointsSymbolLayer( sl, mPoints ) : nullptr;
204 }
205
206 private:
211 class QgsRenderedPointsSymbolLayer : public T
212 {
213 public:
218 QgsRenderedPointsSymbolLayer( const T *original, FeaturePoints &points )
219 : T( original->rotateSymbols(), original->interval() )
220 , mPoints( points )
221 {
222 original->copyTemplateSymbolProperties( this );
223 }
224
225 void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override
226 {
227 const int iPart = context.geometryPartNum() - 1;
228 if ( iPart < 0 || QgsRenderedPointsSymbolLayer::mRingIndex < 0 )
229 return;
230
231 if ( iPart >= mPoints.count() )
232 mPoints.resize( iPart + 1 );
233
234 QVector<QPolygonF> &rings = mPoints[iPart];
235 if ( QgsRenderedPointsSymbolLayer::mRingIndex >= rings.count() )
236 rings.resize( QgsRenderedPointsSymbolLayer::mRingIndex + 1 );
237
238 rings[QgsRenderedPointsSymbolLayer::mRingIndex] = points;
239 }
240
241 private:
242 FeaturePoints &mPoints;
243 };
244};
245
246
247#endif
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
Abstract base class for line symbol layers.
A mouse event which is the result of a user interaction with a QgsMapCanvas.
Rubber band used to draw blank segments on edition.
QgsMapToolEditBlankSegmentsBase(QgsMapCanvas *canvas, QgsVectorLayer *layer, QgsLineSymbolLayer *symbolLayer, int blankSegmentFieldIndex)
Constructor.
~QgsMapToolEditBlankSegmentsBase() override
Destructor.
QList< QList< QPolygonF > > FeaturePoints
QgsMapToolEditBlankSegments(QgsMapCanvas *canvas, QgsVectorLayer *layer, QgsLineSymbolLayer *symbolLayer, int blankSegmentFieldIndex)
Constructor.
QgsTemplatedLineSymbolLayerBase * createRenderedPointsSymbolLayer(const QgsTemplatedLineSymbolLayerBase *originalSl) override
Create symbol layer used to retrieve rendered points from symbol layer The feature will be rendered u...
QgsMapLayer * layer(const QString &id)
Returns the map layer with the matching ID, or nullptr if no layers could be found.
QgsMapCanvas * canvas() const
returns pointer to the tool's map canvas
QgsMapTool(QgsMapCanvas *canvas)
Constructor takes a map canvas as a parameter.
friend class QgsMapCanvas
Definition qgsmaptool.h:389
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
virtual void activate()
called when set as currently active map tool
A rectangle specified with double values.
Abstract base class for symbol layers.
int geometryPartNum() const
Part number of current geometry.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Base class for templated line symbols, e.g.
Represents a vector layer which manages a vector based dataset.
#define FID_NULL
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features