Skip to content

Commit ae713b4

Browse files
committed
Move snapSegment() from map mouse event to private area of CAD dock
1 parent 22ad672 commit ae713b4

6 files changed

+59
-80
lines changed

doc/api_break.dox

+2-1
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,8 @@ QgsMapMouseEvent {#qgis_api_break_3_0_QgsMapMouseEvent}
15771577
----------------
15781578

15791579
- SnappingMode enum was removed.
1580-
- snapPoint() and snapSegment() do not take SnappingMode argument anymore. Snapping is done according to project's snapping configuration.
1580+
- snapPoint() does not take SnappingMode argument anymore. Snapping is done according to project's snapping configuration.
1581+
- snapSegment() was removed.
15811582

15821583

15831584
QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}

python/gui/qgsmapmouseevent.sip

-10
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ class QgsMapMouseEvent : QMouseEvent
6161
:rtype: QgsPointXY
6262
%End
6363

64-
QList<QgsPointXY> snapSegment( bool *snapped = 0, bool allLayers = false ) const;
65-
%Docstring
66-
Returns the first snapped segment. If the cached snapped match is a segment, it will simply return it.
67-
Otherwise it will try to snap a segment according to the event's snapping mode. In this case the cache
68-
will not be overwritten.
69-
\param snapped if given, determines if a segment has been snapped
70-
\param allLayers if true, override snapping mode
71-
:rtype: list of QgsPointXY
72-
%End
73-
7464
bool isSnapped() const;
7565
%Docstring
7666
Returns true if there is a snapped point cached.

src/gui/qgsadvanceddigitizingdockwidget.cpp

+49-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@
3030
#include "qgslinestring.h"
3131
#include "qgsfocuswatcher.h"
3232
#include "qgssettings.h"
33+
#include "qgssnappingutils.h"
3334
#include "qgsproject.h"
3435

36+
/// @cond PRIVATE
3537
struct EdgesOnlyFilter : public QgsPointLocator::MatchFilter
3638
{
3739
bool acceptMatch( const QgsPointLocator::Match &m ) override { return m.hasEdge(); }
3840
};
41+
/// @endcond
42+
3943

4044
bool QgsAdvancedDigitizingDockWidget::lineCircleIntersection( const QgsPointXY &center, const double radius, const QList<QgsPointXY> &segment, QgsPointXY &intersection )
4145
{
@@ -571,7 +575,7 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
571575

572576
QgsPointXY point = e->snapPoint();
573577

574-
mSnappedSegment = e->snapSegment();
578+
mSnappedSegment = snapSegment( e->originalMapPoint() );
575579

576580
bool previousPointExist, penulPointExist;
577581
QgsPointXY previousPt = previousPoint( &previousPointExist );
@@ -864,6 +868,49 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
864868
}
865869

866870

871+
872+
QList<QgsPointXY> QgsAdvancedDigitizingDockWidget::snapSegment( const QgsPointXY &originalMapPoint, bool *snapped, bool allLayers ) const
873+
{
874+
QList<QgsPointXY> segment;
875+
QgsPointXY pt1, pt2;
876+
QgsPointLocator::Match match;
877+
878+
if ( !allLayers )
879+
{
880+
// run snapToMap with only segments
881+
EdgesOnlyFilter filter;
882+
match = mMapCanvas->snappingUtils()->snapToMap( originalMapPoint, &filter );
883+
}
884+
else
885+
{
886+
// run snapToMap with only edges on all layers
887+
QgsSnappingUtils *snappingUtils = mMapCanvas->snappingUtils();
888+
889+
QgsSnappingConfig canvasConfig = snappingUtils->config();
890+
QgsSnappingConfig localConfig = snappingUtils->config();
891+
892+
localConfig.setMode( QgsSnappingConfig::AllLayers );
893+
localConfig.setType( QgsSnappingConfig::Segment );
894+
snappingUtils->setConfig( localConfig );
895+
896+
match = snappingUtils->snapToMap( originalMapPoint );
897+
898+
snappingUtils->setConfig( canvasConfig );
899+
}
900+
if ( match.isValid() && match.hasEdge() )
901+
{
902+
match.edgePoints( pt1, pt2 );
903+
segment << pt1 << pt2;
904+
}
905+
906+
if ( snapped )
907+
{
908+
*snapped = segment.count() == 2;
909+
}
910+
911+
return segment;
912+
}
913+
867914
bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadConstraint::LockMode lockMode )
868915
{
869916
if ( mAdditionalConstraint == NoConstraint )
@@ -874,7 +921,7 @@ bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadCo
874921
bool previousPointExist, penulPointExist, snappedSegmentExist;
875922
QgsPointXY previousPt = previousPoint( &previousPointExist );
876923
QgsPointXY penultimatePt = penultimatePoint( &penulPointExist );
877-
mSnappedSegment = e->snapSegment( &snappedSegmentExist, true );
924+
mSnappedSegment = snapSegment( e->originalMapPoint(), &snappedSegmentExist, true );
878925

879926
if ( !previousPointExist || !snappedSegmentExist )
880927
{

src/gui/qgsadvanceddigitizingdockwidget.h

+8
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
408408
//! If additional constraints are used, this will determine the angle to be locked depending on the snapped segment.
409409
bool alignToSegment( QgsMapMouseEvent *e, CadConstraint::LockMode lockMode = CadConstraint::HardLock );
410410

411+
/**
412+
* Returns the first snapped segment. Will try to snap a segment according to the event's snapping mode.
413+
* \param originalMapPoint point to be snapped (in map coordinates)
414+
* \param snapped if given, determines if a segment has been snapped
415+
* \param allLayers if true, override snapping mode
416+
*/
417+
QList<QgsPointXY> snapSegment( const QgsPointXY &originalMapPoint, bool *snapped = nullptr, bool allLayers = false ) const;
418+
411419
//! add point to the CAD point list
412420
void addPoint( const QgsPointXY &point );
413421
//! update the current point in the CAD point list

src/gui/qgsmapmouseevent.cpp

-58
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
#include "qgssnappingutils.h"
2121
#include "qgssnappingconfig.h"
2222

23-
/// @cond PRIVATE
24-
struct EdgesOnlyFilter : public QgsPointLocator::MatchFilter
25-
{
26-
bool acceptMatch( const QgsPointLocator::Match &m ) override { return m.hasEdge(); }
27-
};
28-
/// @endcond
29-
3023
QgsMapMouseEvent::QgsMapMouseEvent( QgsMapCanvas *mapCanvas, QMouseEvent *event )
3124
: QMouseEvent( event->type(), event->pos(), event->button(), event->buttons(), event->modifiers() )
3225
, mHasCachedSnapResult( false )
@@ -72,57 +65,6 @@ QgsPointXY QgsMapMouseEvent::snapPoint()
7265
return mMapPoint;
7366
}
7467

75-
QList<QgsPointXY> QgsMapMouseEvent::snapSegment( bool *snapped, bool allLayers ) const
76-
{
77-
QList<QgsPointXY> segment;
78-
QgsPointXY pt1, pt2;
79-
80-
// If there's a cached snapping result we use it
81-
if ( mHasCachedSnapResult && mSnapMatch.hasEdge() )
82-
{
83-
mSnapMatch.edgePoints( pt1, pt2 );
84-
segment << pt1 << pt2;
85-
}
86-
else
87-
{
88-
QgsPointLocator::Match match;
89-
if ( !allLayers )
90-
{
91-
// run snapToMap with only segments
92-
EdgesOnlyFilter filter;
93-
match = mMapCanvas->snappingUtils()->snapToMap( mOriginalMapPoint, &filter );
94-
}
95-
else
96-
{
97-
// run snapToMap with only edges on all layers
98-
QgsSnappingUtils *snappingUtils = mMapCanvas->snappingUtils();
99-
100-
QgsSnappingConfig canvasConfig = snappingUtils->config();
101-
QgsSnappingConfig localConfig = snappingUtils->config();
102-
103-
localConfig.setMode( QgsSnappingConfig::AllLayers );
104-
localConfig.setType( QgsSnappingConfig::Segment );
105-
snappingUtils->setConfig( localConfig );
106-
107-
match = snappingUtils->snapToMap( mOriginalMapPoint );
108-
109-
snappingUtils->setConfig( canvasConfig );
110-
}
111-
if ( match.isValid() && match.hasEdge() )
112-
{
113-
match.edgePoints( pt1, pt2 );
114-
segment << pt1 << pt2;
115-
}
116-
}
117-
118-
if ( snapped )
119-
{
120-
*snapped = segment.count() == 2;
121-
}
122-
123-
return segment;
124-
}
125-
12668
void QgsMapMouseEvent::setMapPoint( const QgsPointXY &point )
12769
{
12870
mMapPoint = point;

src/gui/qgsmapmouseevent.h

-9
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ class GUI_EXPORT QgsMapMouseEvent : public QMouseEvent
7272
*/
7373
QgsPointXY snapPoint();
7474

75-
/**
76-
* Returns the first snapped segment. If the cached snapped match is a segment, it will simply return it.
77-
* Otherwise it will try to snap a segment according to the event's snapping mode. In this case the cache
78-
* will not be overwritten.
79-
* \param snapped if given, determines if a segment has been snapped
80-
* \param allLayers if true, override snapping mode
81-
*/
82-
QList<QgsPointXY> snapSegment( bool *snapped = nullptr, bool allLayers = false ) const;
83-
8475
/**
8576
* Returns true if there is a snapped point cached.
8677
* Will only be useful after snapPoint has previously been called.

0 commit comments

Comments
 (0)