Skip to content

Commit 6363aba

Browse files
pblottierenyalldawson
authored andcommittedJul 20, 2018
[FEATURE][needs-doc] Vertex tool can work on the current layer only
1 parent 9259d60 commit 6363aba

File tree

10 files changed

+212
-1
lines changed

10 files changed

+212
-1
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@
626626
<file>themes/default/mIconSnappingSegment.svg</file>
627627
<file>themes/default/mIconTopologicalEditing.svg</file>
628628
<file>themes/default/mIconSnappingIntersection.svg</file>
629+
<file>themes/default/mIconEditVerticesAllLayers.svg</file>
629630
<file>themes/default/mActionMoveFeatureCopy.svg</file>
630631
<file>themes/default/mActionMoveFeatureCopyLine.svg</file>
631632
<file>themes/default/mActionMoveFeatureCopyPoint.svg</file>
Lines changed: 124 additions & 0 deletions
Loading

‎python/core/auto_generated/qgssnappingconfig.sip.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ Returns if the snapping on intersection is enabled
191191
Sets if the snapping on intersection is enabled
192192
%End
193193

194+
bool editVerticesOnAllLayers() const;
195+
196+
void setEditVerticesOnAllLayers( bool enabled );
197+
194198
SIP_PYDICT individualLayerSettings() const;
195199
%Docstring
196200
Returns individual snapping settings for all layers

‎src/app/qgsoptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
969969

970970
//default snap mode
971971
mSnappingEnabledDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool() );
972+
mEditVerticesOnAllLayersDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_edit_vertices_on_all_layers_enabled" ), true ).toBool() );
972973
mDefaultSnapModeComboBox->addItem( tr( "Vertex" ), QgsSnappingConfig::Vertex );
973974
mDefaultSnapModeComboBox->addItem( tr( "Vertex and segment" ), QgsSnappingConfig::VertexAndSegment );
974975
mDefaultSnapModeComboBox->addItem( tr( "Segment" ), QgsSnappingConfig::Segment );
@@ -1517,6 +1518,7 @@ void QgsOptions::saveOptions()
15171518
//default snap mode
15181519
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), mSnappingEnabledDefault->isChecked() );
15191520
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), ( QgsSnappingConfig::SnappingType )mDefaultSnapModeComboBox->currentData().toInt() );
1521+
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_edit_vertices_on_all_layers_enabled" ), mEditVerticesOnAllLayersDefault->isChecked() );
15201522
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), mDefaultSnappingToleranceSpinBox->value() );
15211523
mSettings->setValue( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit" ), mSearchRadiusVertexEditSpinBox->value() );
15221524
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ),

‎src/app/qgssnappingwidget.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
194194
tracingMenu->addAction( widgetAction );
195195
mEnableTracingAction->setMenu( tracingMenu );
196196

197+
// vertex tool may select vertices from all layers
198+
mEditVerticesAllLayersAction = new QAction( tr( "Edit vertices of all editable layers at once" ), this );
199+
mEditVerticesAllLayersAction->setCheckable( true );
200+
mEditVerticesAllLayersAction->setIcon( QIcon( QgsApplication::getThemeIcon( "/mIconEditVerticesAllLayers.svg" ) ) );
201+
mEditVerticesAllLayersAction->setToolTip( tr( "The vertex editor tool allows to edit vertices from many layers at once. This option allows to restore previous behavior, ie only edit active layer. Useful with transaction groups and database trigger design interfering with multi layer editing" ) );
202+
mEditVerticesAllLayersAction->setObjectName( QStringLiteral( "EditVerticesAllLayersAction" ) );
203+
connect( mEditVerticesAllLayersAction, &QAction::toggled, this, &QgsSnappingWidget::enableEditVerticesOnAllLayers );
204+
197205
// layout
198206
if ( mDisplayMode == ToolBar )
199207
{
@@ -221,6 +229,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
221229
tb->addAction( mTopologicalEditingAction );
222230
tb->addAction( mIntersectionSnappingAction );
223231
tb->addAction( mEnableTracingAction );
232+
tb->addAction( mEditVerticesAllLayersAction );
224233
}
225234
else
226235
{
@@ -249,6 +258,12 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
249258
interButton->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
250259
layout->addWidget( interButton );
251260

261+
QToolButton *editButton = new QToolButton();
262+
editButton->addAction( mEditVerticesAllLayersAction );
263+
editButton->setDefaultAction( mEditVerticesAllLayersAction );
264+
editButton->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
265+
layout->addWidget( editButton );
266+
252267
layout->setContentsMargins( 0, 0, 0, 0 );
253268
layout->setAlignment( Qt::AlignRight );
254269
layout->setSpacing( mDisplayMode == Widget ? 3 : 0 );
@@ -343,6 +358,11 @@ void QgsSnappingWidget::projectSnapSettingsChanged()
343358
mIntersectionSnappingAction->setChecked( config.intersectionSnapping() );
344359
}
345360

361+
if ( config.editVerticesOnAllLayers() != mEditVerticesAllLayersAction->isChecked() )
362+
{
363+
mEditVerticesAllLayersAction->setChecked( config.editVerticesOnAllLayers() );
364+
}
365+
346366
toggleSnappingWidgets( config.enabled() );
347367
}
348368

@@ -401,6 +421,12 @@ void QgsSnappingWidget::enableIntersectionSnapping( bool enabled )
401421
mProject->setSnappingConfig( mConfig );
402422
}
403423

424+
void QgsSnappingWidget::enableEditVerticesOnAllLayers( bool enabled )
425+
{
426+
mConfig.setEditVerticesOnAllLayers( enabled );
427+
mProject->setSnappingConfig( mConfig );
428+
}
429+
404430
void QgsSnappingWidget::onSnappingTreeLayersChanged()
405431
{
406432
mLayerTreeView->expandAll();

‎src/app/qgssnappingwidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
106106

107107
void enableIntersectionSnapping( bool enabled );
108108

109+
void enableEditVerticesOnAllLayers( bool enabled );
110+
109111
void modeButtonTriggered( QAction *action );
110112
void typeButtonTriggered( QAction *action );
111113

@@ -152,6 +154,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
152154
QTreeView *mLayerTreeView = nullptr;
153155
QgsFloatingWidget *mAdvancedConfigContainer = nullptr;
154156

157+
QAction *mEditVerticesAllLayersAction = nullptr;
158+
155159
void cleanGroup( QgsLayerTreeNode *node );
156160
};
157161

‎src/app/vertextool/qgsvertextool.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
470470
QList<Vertex> vertices;
471471
QList<Vertex> selectedVertices;
472472

473+
const bool allLayers = canvas()->snappingUtils()->config().editVerticesOnAllLayers();
474+
473475
// for each editable layer, select vertices
474476
const auto layers = canvas()->layers();
475477
for ( QgsMapLayer *layer : layers )
@@ -478,6 +480,9 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
478480
if ( !vlayer || !vlayer->isEditable() || !vlayer->isSpatial() )
479481
continue;
480482

483+
if ( !allLayers && vlayer != currentVectorLayer() )
484+
continue;
485+
481486
QgsRectangle layerRect = toLayerCoordinates( vlayer, map_rect );
482487
QgsFeature f;
483488
QgsFeatureIterator fi = vlayer->getFeatures( QgsFeatureRequest( layerRect ).setSubsetOfAttributes( QgsAttributeList() ) );
@@ -691,7 +696,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
691696
}
692697

693698
// if there is no match from the current layer, try to use any editable vector layer
694-
if ( !m.isValid() )
699+
if ( !m.isValid() && oldConfig.editVerticesOnAllLayers() )
695700
{
696701
const auto layers = canvas()->layers();
697702
for ( QgsMapLayer *layer : layers )

‎src/core/qgssnappingconfig.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ bool QgsSnappingConfig::operator==( const QgsSnappingConfig &other ) const
111111
&& mTolerance == other.mTolerance
112112
&& mUnits == other.mUnits
113113
&& mIntersectionSnapping == other.mIntersectionSnapping
114+
&& mEditVerticesOnAllLayers == other.mEditVerticesOnAllLayers
114115
&& mIndividualLayerSettings == other.mIndividualLayerSettings;
115116
}
116117

117118
void QgsSnappingConfig::reset()
118119
{
119120
// get defaults values. They are both used for standard and advanced configuration (per layer)
120121
bool enabled = QgsSettings().value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool();
122+
const bool editAllLayers = QgsSettings().value( QStringLiteral( "/qgis/digitizing/default_edit_vertices_on_all_layers_enabled" ), true ).toBool();
121123
SnappingMode mode = QgsSettings().enumValue( QStringLiteral( "/qgis/digitizing/default_snap_mode" ), AllLayers );
122124
if ( mode == 0 )
123125
{
@@ -130,6 +132,7 @@ void QgsSnappingConfig::reset()
130132
QgsTolerance::UnitType units = QgsSettings().enumValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ), Qgis::DEFAULT_SNAP_UNITS );
131133

132134
// assign main (standard) config
135+
mEditVerticesOnAllLayers = editAllLayers;
133136
mEnabled = enabled;
134137
mMode = mode;
135138
mType = type;
@@ -237,6 +240,16 @@ void QgsSnappingConfig::setIntersectionSnapping( bool enabled )
237240
mIntersectionSnapping = enabled;
238241
}
239242

243+
bool QgsSnappingConfig::editVerticesOnAllLayers() const
244+
{
245+
return mEditVerticesOnAllLayers;
246+
}
247+
248+
void QgsSnappingConfig::setEditVerticesOnAllLayers( bool enabled )
249+
{
250+
mEditVerticesOnAllLayers = enabled;
251+
}
252+
240253
QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> QgsSnappingConfig::individualLayerSettings() const
241254
{
242255
return mIndividualLayerSettings;
@@ -271,6 +284,7 @@ bool QgsSnappingConfig::operator!=( const QgsSnappingConfig &other ) const
271284
|| mType != other.mType
272285
|| mTolerance != other.mTolerance
273286
|| mUnits != other.mUnits
287+
|| mEditVerticesOnAllLayers != other.mEditVerticesOnAllLayers
274288
|| mIndividualLayerSettings != other.mIndividualLayerSettings;
275289
}
276290

@@ -301,6 +315,9 @@ void QgsSnappingConfig::readProject( const QDomDocument &doc )
301315
if ( snapSettingsElem.hasAttribute( QStringLiteral( "intersection-snapping" ) ) )
302316
mIntersectionSnapping = snapSettingsElem.attribute( QStringLiteral( "intersection-snapping" ) ) == QLatin1String( "1" );
303317

318+
if ( snapSettingsElem.hasAttribute( QStringLiteral( "edit-vertices-on-all-layers" ) ) )
319+
mEditVerticesOnAllLayers = snapSettingsElem.attribute( QStringLiteral( "edit-vertices-on-all-layers" ) ) == QLatin1String( "1" );
320+
304321
// do not clear the settings as they must be automatically synchronized with current layers
305322
QDomNodeList nodes = snapSettingsElem.elementsByTagName( QStringLiteral( "individual-layer-settings" ) );
306323
if ( nodes.count() )
@@ -344,6 +361,7 @@ void QgsSnappingConfig::writeProject( QDomDocument &doc )
344361
snapSettingsElem.setAttribute( QStringLiteral( "tolerance" ), mTolerance );
345362
snapSettingsElem.setAttribute( QStringLiteral( "unit" ), ( int )mUnits );
346363
snapSettingsElem.setAttribute( QStringLiteral( "intersection-snapping" ), QString::number( mIntersectionSnapping ) );
364+
snapSettingsElem.setAttribute( QStringLiteral( "edit-vertices-on-all-layers" ), QString::number( mEditVerticesOnAllLayers ) );
347365

348366
QDomElement ilsElement = doc.createElement( QStringLiteral( "individual-layer-settings" ) );
349367
QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();

‎src/core/qgssnappingconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ class CORE_EXPORT QgsSnappingConfig
172172
//! Sets if the snapping on intersection is enabled
173173
void setIntersectionSnapping( bool enabled );
174174

175+
bool editVerticesOnAllLayers() const;
176+
177+
void setEditVerticesOnAllLayers( bool enabled );
178+
175179
//! Returns individual snapping settings for all layers
176180
#ifndef SIP_RUN
177181
QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
@@ -292,6 +296,7 @@ class CORE_EXPORT QgsSnappingConfig
292296
double mTolerance = 0.0;
293297
QgsTolerance::UnitType mUnits = QgsTolerance::ProjectUnits;
294298
bool mIntersectionSnapping = false;
299+
bool mEditVerticesOnAllLayers = true;
295300

296301
QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;
297302

‎src/ui/qgsoptionsbase.ui

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,6 +4207,28 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
42074207
</layout>
42084208
</widget>
42094209
</item>
4210+
<item>
4211+
<widget class="QGroupBox" name="groupBox_30">
4212+
<property name="title">
4213+
<string>Vertex tool</string>
4214+
</property>
4215+
<layout class="QGridLayout" name="_13">
4216+
<item row="0" column="0">
4217+
<widget class="QCheckBox" name="mEditVerticesOnAllLayersDefault">
4218+
<property name="toolTip">
4219+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The vertex editor tool allows to edit vertices from many layers at once. This option allows to restore previous behavior, ie only edit active layer. Useful with transaction groups and database trigger design interfering with multi layer editing&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
4220+
</property>
4221+
<property name="text">
4222+
<string>Edit vertices of all editable layers at once by default</string>
4223+
</property>
4224+
<property name="checked">
4225+
<bool>false</bool>
4226+
</property>
4227+
</widget>
4228+
</item>
4229+
</layout>
4230+
</widget>
4231+
</item>
42104232
<item>
42114233
<widget class="QgsCollapsibleGroupBox" name="mVertexMarkerGroupBox">
42124234
<property name="title">

0 commit comments

Comments
 (0)
Please sign in to comment.