Skip to content
Permalink
Browse files

[FEATURE] Snapping feedback improvements

- tooltips with name of the layer that has been snapped
- different markers for different snap types (cross for vertex, X for intersection, box for edge)
- snapping marker color can be customized in options (default: magenta - as before)
- whether to show tooltips can be customized in options (default: off)
  • Loading branch information
wonder-sk committed Oct 25, 2017
1 parent 1edc1a7 commit 568b22d53fcde729eea5cdaeb5aa6ba9b3297c40
Showing with 76 additions and 19 deletions.
  1. +6 −0 src/app/qgsoptions.cpp
  2. +36 −2 src/gui/qgssnapindicator.cpp
  3. +34 −17 src/ui/qgsoptionsbase.ui
@@ -941,6 +941,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
}
mSearchRadiusVertexEditComboBox->setCurrentIndex( index );

mSnappingMarkerColorButton->setColor( mSettings->value( QStringLiteral( "/qgis/digitizing/snap_color" ), QColor( Qt::magenta ) ).value<QColor>() );
mSnappingTooltipsCheckbox->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/snap_tooltip" ), false ).toBool() );

//vertex marker
mMarkersOnlyForSelectedCheckBox->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/marker_only_for_selected" ), true ).toBool() );

@@ -1459,6 +1462,9 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit_unit" ),
( mSearchRadiusVertexEditComboBox->currentIndex() == 0 ? QgsTolerance::ProjectUnits : QgsTolerance::Pixels ) );

mSettings->setValue( QStringLiteral( "/qgis/digitizing/snap_color" ), mSnappingMarkerColorButton->color() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/snap_tooltip" ), mSnappingTooltipsCheckbox->isChecked() );

mSettings->setValue( QStringLiteral( "/qgis/digitizing/marker_only_for_selected" ), mMarkersOnlyForSelectedCheckBox->isChecked() );

QString markerComboText = mMarkerStyleComboBox->currentText();
@@ -15,8 +15,13 @@

#include "qgssnapindicator.h"

#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsvectorlayer.h"
#include "qgsvertexmarker.h"

#include <QToolTip>


QgsSnapIndicator::QgsSnapIndicator( QgsMapCanvas *canvas )
: mCanvas( canvas )
@@ -34,17 +39,46 @@ void QgsSnapIndicator::setMatch( const QgsPointLocator::Match &match )
if ( !mMatch.isValid() )
{
mSnappingMarker.reset();
QToolTip::hideText();
}
else
{
if ( !mSnappingMarker )
{
mSnappingMarker.reset( new QgsVertexMarker( mCanvas ) );
mSnappingMarker->setIconType( QgsVertexMarker::ICON_CROSS );
mSnappingMarker->setColor( Qt::magenta );
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_CROSS; // vertex snap
else
iconType = QgsVertexMarker::ICON_X; // intersection snap
}
else // must be segment snap
{
iconType = QgsVertexMarker::ICON_BOX;
}
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 );
}
}
}

@@ -4112,6 +4112,9 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<string>Snapping</string>
</property>
<layout class="QGridLayout" name="_10">
<item row="6" column="5">
<widget class="QgsColorButton" name="mSnappingMarkerColorButton"/>
</item>
<item row="1" column="1" colspan="6">
<widget class="QCheckBox" name="mSnappingEnabledDefault">
<property name="text">
@@ -4126,6 +4129,13 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Snapping marker color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="mDefaultSnapModeLabel">
<property name="text">
@@ -4189,6 +4199,20 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="4" column="6">
<widget class="QComboBox" name="mSearchRadiusVertexEditComboBox">
<item>
<property name="text">
<string>map units</string>
</property>
</item>
<item>
<property name="text">
<string>pixels</string>
</property>
</item>
</widget>
</item>
<item row="4" column="5">
<widget class="QDoubleSpinBox" name="mSearchRadiusVertexEditSpinBox">
<property name="decimals">
@@ -4222,19 +4246,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</spacer>
</item>
<item row="4" column="6">
<widget class="QComboBox" name="mSearchRadiusVertexEditComboBox">
<item>
<property name="text">
<string>map units</string>
</property>
</item>
<item>
<property name="text">
<string>pixels</string>
</property>
</item>
</widget>
<item row="5" column="5" colspan="2">
<widget class="QComboBox" name="mSnappingMainDialogComboBox"/>
</item>
<item row="4" column="1" colspan="3">
<widget class="QLabel" name="mVertexSearchRadiusVertexEditLabel">
@@ -4243,16 +4256,20 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="5" column="5" colspan="2">
<widget class="QComboBox" name="mSnappingMainDialogComboBox"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLabel" name="mDefaultSnappingToleranceTextLabel">
<property name="text">
<string>Default snapping tolerance</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="6">
<widget class="QCheckBox" name="mSnappingTooltipsCheckbox">
<property name="text">
<string>Show snapping tooltips</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -4829,7 +4846,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<x>0</x>
<y>0</y>
<width>866</width>
<height>822</height>
<height>930</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">

0 comments on commit 568b22d

Please sign in to comment.
You can’t perform that action at this time.