-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5451 from wonder-sk/snap-indicators
Snap indicators improvements
- Loading branch information
Showing
15 changed files
with
299 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgssnapindicator.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
class QgsSnapIndicator | ||
{ | ||
%Docstring | ||
Class that shows snapping marker on map canvas for the current snapping match. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgssnapindicator.h" | ||
%End | ||
public: | ||
QgsSnapIndicator( QgsMapCanvas *canvas ); | ||
%Docstring | ||
Constructs an indicator for the given map canvas | ||
%End | ||
~QgsSnapIndicator(); | ||
|
||
void setMatch( const QgsPointLocator::Match &match ); | ||
%Docstring | ||
Sets snapping match that should be displayed in map canvas. Invalid match hides the indicator | ||
%End | ||
QgsPointLocator::Match match() const; | ||
%Docstring | ||
Returns currently displayed snapping match | ||
:rtype: QgsPointLocator.Match | ||
%End | ||
|
||
void setVisible( bool visible = true ); | ||
%Docstring | ||
Sets whether the snapping indicator is visible | ||
%End | ||
bool isVisible() const; | ||
%Docstring | ||
Returns whether the snapping indicator is visible | ||
:rtype: bool | ||
%End | ||
|
||
private: | ||
QgsSnapIndicator( const QgsSnapIndicator &rh ); | ||
QgsSnapIndicator &operator=( const QgsSnapIndicator & ); | ||
%Docstring | ||
:rtype: QgsSnapIndicator | ||
%End | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgssnapindicator.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*************************************************************************** | ||
qgssnapindicator.cpp | ||
-------------------------------------- | ||
Date : October 2017 | ||
Copyright : (C) 2017 by Martin Dobias | ||
Email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgssnapindicator.h" | ||
|
||
#include "qgsmapcanvas.h" | ||
#include "qgssettings.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsvertexmarker.h" | ||
|
||
#include <QToolTip> | ||
|
||
|
||
QgsSnapIndicator::QgsSnapIndicator( QgsMapCanvas *canvas ) | ||
: mCanvas( canvas ) | ||
{ | ||
} | ||
|
||
QgsSnapIndicator::~QgsSnapIndicator() = default; | ||
|
||
|
||
void QgsSnapIndicator::setMatch( const QgsPointLocator::Match &match ) | ||
{ | ||
mMatch = match; | ||
|
||
if ( !mMatch.isValid() ) | ||
{ | ||
mSnappingMarker.reset(); | ||
QToolTip::hideText(); | ||
} | ||
else | ||
{ | ||
if ( !mSnappingMarker ) | ||
{ | ||
mSnappingMarker.reset( new QgsVertexMarker( mCanvas ) ); | ||
mSnappingMarker->setPenWidth( 3 ); | ||
} | ||
|
||
QgsSettings s; | ||
|
||
QColor color = s.value( QStringLiteral( "/qgis/digitizing/snap_color" ), QColor( Qt::magenta ) ).value<QColor>(); | ||
mSnappingMarker->setColor( color ); | ||
|
||
int iconType; | ||
if ( match.hasVertex() ) | ||
{ | ||
if ( match.layer() ) | ||
iconType = QgsVertexMarker::ICON_BOX; // vertex snap | ||
else | ||
iconType = QgsVertexMarker::ICON_X; // intersection snap | ||
} | ||
else // must be segment snap | ||
{ | ||
iconType = QgsVertexMarker::ICON_DOUBLE_TRIANGLE; | ||
} | ||
mSnappingMarker->setIconType( iconType ); | ||
|
||
mSnappingMarker->setCenter( match.point() ); | ||
|
||
// tooltip | ||
if ( s.value( QStringLiteral( "/qgis/digitizing/snap_tooltip" ), false ).toBool() ) | ||
{ | ||
QPoint ptCanvas = mSnappingMarker->toCanvasCoordinates( match.point() ).toPoint(); | ||
QPoint ptGlobal = mCanvas->mapToGlobal( ptCanvas ); | ||
QRect rect( ptCanvas.x(), ptCanvas.y(), 1, 1 ); // area where is the tooltip valid | ||
QString layerName = match.layer() ? match.layer()->name() : QString(); | ||
QToolTip::showText( ptGlobal, layerName, mCanvas, rect ); | ||
} | ||
} | ||
} | ||
|
||
void QgsSnapIndicator::setVisible( bool visible ) | ||
{ | ||
mSnappingMarker->setVisible( visible ); | ||
} | ||
|
||
bool QgsSnapIndicator::isVisible() const | ||
{ | ||
return mSnappingMarker->isVisible(); | ||
} |
Oops, something went wrong.