QGIS API Documentation 4.1.0-Master (31622b25bb0)
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"
25#include "qgsrubberband.h"
26#include "qgssymbol.h"
27#include "qobjectuniqueptr.h"
28
29#define SIP_NO_FILE
30
31class QgsMapToolBlankSegmentRubberBand;
32class QgsVectorLayer;
33class QgsSymbol;
34class QgsSymbolLayer;
35
54{
55 Q_OBJECT
56
57 public:
66
71
72 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
73 void canvasPressEvent( QgsMapMouseEvent *e ) override;
74 void keyPressEvent( QKeyEvent *e ) override;
75
76 void activate() override;
77
78 protected:
79 typedef QList<QList<QPolygonF>> FeaturePoints;
81
82 private:
86 QPair<double, double> startEndDistance() const;
87
91 void updateAttribute();
92
96 void loadFeaturePoints();
97
103 virtual QgsTemplatedLineSymbolLayerBase *createRenderedPointsSymbolLayer( const QgsTemplatedLineSymbolLayerBase *original ) = 0;
104
110 int closestBlankSegmentIndex( const QPointF &point, double &distance ) const;
111
120 QPointF closestPoint( const QPointF &point, double &distance, int &partIndex, int &ringIndex, int &pointIndex ) const;
121
126 void updateStartEndRubberBand();
127
131 void updateHoveredBlankSegment( const QPoint &pos );
132
136 void setCurrentBlankSegment( int currentBlankSegmentIndex );
137
141 void selectFeature( QgsMapMouseEvent *event );
142
149
153 enum State
154 {
155 SelectFeature,
156 FeatureSelected,
157 BlankSegmentSelected,
158 BlankSegmentModificationStarted,
159 BlankSegmentCreationStarted
160 };
161
162 std::vector<QObjectUniquePtr<QgsBlankSegmentRubberBand>> mBlankSegments;
163 QgsVectorLayer *mLayer = nullptr;
164 std::unique_ptr<QgsSymbol> mSymbol;
165 QgsTemplatedLineSymbolLayerBase *mSymbolLayer = nullptr; // original symbol layer
166 QgsTemplatedLineSymbolLayerBase *mRenderedPointsSymbolLayer = nullptr; // original symbol layer clone to retrieve rendered points
167
168 int mBlankSegmentsFieldIndex = -1;
169 QgsFeatureId mCurrentFeatureId = FID_NULL;
170 QgsRectangle mExtent;
171 State mState = State::SelectFeature;
172 int mCurrentBlankSegmentIndex = -1;
173 int mHoveredBlankSegmentIndex = -1;
174 QgsPropertyOverrideButton *mPropertyButton = nullptr;
175
176 // currently edited blank segment, start point is the fixed point and end point is the currently
177 // modified one
179 QObjectUniquePtr<QgsRubberBand> mStartRubberBand;
180 QObjectUniquePtr<QgsRubberBand> mEndRubberBand;
181
183};
184
191template<class T> class GUI_EXPORT QgsMapToolEditBlankSegments : public QgsMapToolEditBlankSegmentsBase
192{
193 public:
204
206 {
207 const T *sl = dynamic_cast<const T *>( originalSl );
208 return sl ? new QgsRenderedPointsSymbolLayer( sl, mPoints ) : nullptr;
209 }
210
211 private:
216 class QgsRenderedPointsSymbolLayer : public T
217 {
218 public:
223 QgsRenderedPointsSymbolLayer( const T *original, FeaturePoints &points )
224 : T( original->rotateSymbols(), original->interval() )
225 , mPoints( points )
226 {
227 original->copyTemplateSymbolProperties( this );
228 }
229
230 void renderPolyline( const QPolygonF &points, QgsSymbolRenderContext &context ) override
231 {
232 const int iPart = context.geometryPartNum() - 1;
233 if ( iPart < 0 || QgsRenderedPointsSymbolLayer::mRingIndex < 0 )
234 return;
235
236 if ( iPart >= mPoints.count() )
237 mPoints.resize( iPart + 1 );
238
239 QVector<QPolygonF> &rings = mPoints[iPart];
240 if ( QgsRenderedPointsSymbolLayer::mRingIndex >= rings.count() )
241 rings.resize( QgsRenderedPointsSymbolLayer::mRingIndex + 1 );
242
243 rings[QgsRenderedPointsSymbolLayer::mRingIndex] = points;
244 }
245
246 private:
247 FeaturePoints &mPoints;
248 };
249};
250
251
252#endif
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
A mouse event which is the result of a user interaction with a QgsMapCanvas.
Rubber band used to draw blank segments on edition.
~QgsMapToolEditBlankSegmentsBase() override
Destructor.
QList< QList< QPolygonF > > FeaturePoints
QgsMapToolEditBlankSegmentsBase(QgsMapCanvas *canvas, QgsVectorLayer *layer, QgsTemplatedLineSymbolLayerBase *symbolLayer, QgsPropertyOverrideButton *propertyButton)
Constructor.
QgsMapToolEditBlankSegments(QgsMapCanvas *canvas, QgsVectorLayer *layer, QgsTemplatedLineSymbolLayerBase *symbolLayer, QgsPropertyOverrideButton *propertyButton)
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:423
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 button for controlling property overrides which may apply to a widget.
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:227
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