Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE][needs-doc] Vertex tool can work on the current layer only
  • Loading branch information
pblottiere authored and nyalldawson committed Jul 20, 2018
1 parent 9259d60 commit 6363aba
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 1 deletion.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -626,6 +626,7 @@
<file>themes/default/mIconSnappingSegment.svg</file>
<file>themes/default/mIconTopologicalEditing.svg</file>
<file>themes/default/mIconSnappingIntersection.svg</file>
<file>themes/default/mIconEditVerticesAllLayers.svg</file>
<file>themes/default/mActionMoveFeatureCopy.svg</file>
<file>themes/default/mActionMoveFeatureCopyLine.svg</file>
<file>themes/default/mActionMoveFeatureCopyPoint.svg</file>
Expand Down
124 changes: 124 additions & 0 deletions images/themes/default/mIconEditVerticesAllLayers.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions python/core/auto_generated/qgssnappingconfig.sip.in
Expand Up @@ -191,6 +191,10 @@ Returns if the snapping on intersection is enabled
Sets if the snapping on intersection is enabled
%End

bool editVerticesOnAllLayers() const;

void setEditVerticesOnAllLayers( bool enabled );

SIP_PYDICT individualLayerSettings() const;
%Docstring
Returns individual snapping settings for all layers
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -969,6 +969,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti

//default snap mode
mSnappingEnabledDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), false ).toBool() );
mEditVerticesOnAllLayersDefault->setChecked( mSettings->value( QStringLiteral( "/qgis/digitizing/default_edit_vertices_on_all_layers_enabled" ), true ).toBool() );
mDefaultSnapModeComboBox->addItem( tr( "Vertex" ), QgsSnappingConfig::Vertex );
mDefaultSnapModeComboBox->addItem( tr( "Vertex and segment" ), QgsSnappingConfig::VertexAndSegment );
mDefaultSnapModeComboBox->addItem( tr( "Segment" ), QgsSnappingConfig::Segment );
Expand Down Expand Up @@ -1517,6 +1518,7 @@ void QgsOptions::saveOptions()
//default snap mode
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), mSnappingEnabledDefault->isChecked() );
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snap_type" ), ( QgsSnappingConfig::SnappingType )mDefaultSnapModeComboBox->currentData().toInt() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_edit_vertices_on_all_layers_enabled" ), mEditVerticesOnAllLayersDefault->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), mDefaultSnappingToleranceSpinBox->value() );
mSettings->setValue( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit" ), mSearchRadiusVertexEditSpinBox->value() );
mSettings->setEnumValue( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ),
Expand Down
26 changes: 26 additions & 0 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -194,6 +194,14 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
tracingMenu->addAction( widgetAction );
mEnableTracingAction->setMenu( tracingMenu );

// vertex tool may select vertices from all layers
mEditVerticesAllLayersAction = new QAction( tr( "Edit vertices of all editable layers at once" ), this );
mEditVerticesAllLayersAction->setCheckable( true );
mEditVerticesAllLayersAction->setIcon( QIcon( QgsApplication::getThemeIcon( "/mIconEditVerticesAllLayers.svg" ) ) );
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" ) );
mEditVerticesAllLayersAction->setObjectName( QStringLiteral( "EditVerticesAllLayersAction" ) );
connect( mEditVerticesAllLayersAction, &QAction::toggled, this, &QgsSnappingWidget::enableEditVerticesOnAllLayers );

// layout
if ( mDisplayMode == ToolBar )
{
Expand Down Expand Up @@ -221,6 +229,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
tb->addAction( mTopologicalEditingAction );
tb->addAction( mIntersectionSnappingAction );
tb->addAction( mEnableTracingAction );
tb->addAction( mEditVerticesAllLayersAction );
}
else
{
Expand Down Expand Up @@ -249,6 +258,12 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
interButton->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
layout->addWidget( interButton );

QToolButton *editButton = new QToolButton();
editButton->addAction( mEditVerticesAllLayersAction );
editButton->setDefaultAction( mEditVerticesAllLayersAction );
editButton->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
layout->addWidget( editButton );

layout->setContentsMargins( 0, 0, 0, 0 );
layout->setAlignment( Qt::AlignRight );
layout->setSpacing( mDisplayMode == Widget ? 3 : 0 );
Expand Down Expand Up @@ -343,6 +358,11 @@ void QgsSnappingWidget::projectSnapSettingsChanged()
mIntersectionSnappingAction->setChecked( config.intersectionSnapping() );
}

if ( config.editVerticesOnAllLayers() != mEditVerticesAllLayersAction->isChecked() )
{
mEditVerticesAllLayersAction->setChecked( config.editVerticesOnAllLayers() );
}

toggleSnappingWidgets( config.enabled() );
}

Expand Down Expand Up @@ -401,6 +421,12 @@ void QgsSnappingWidget::enableIntersectionSnapping( bool enabled )
mProject->setSnappingConfig( mConfig );
}

void QgsSnappingWidget::enableEditVerticesOnAllLayers( bool enabled )
{
mConfig.setEditVerticesOnAllLayers( enabled );
mProject->setSnappingConfig( mConfig );
}

void QgsSnappingWidget::onSnappingTreeLayersChanged()
{
mLayerTreeView->expandAll();
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgssnappingwidget.h
Expand Up @@ -106,6 +106,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget

void enableIntersectionSnapping( bool enabled );

void enableEditVerticesOnAllLayers( bool enabled );

void modeButtonTriggered( QAction *action );
void typeButtonTriggered( QAction *action );

Expand Down Expand Up @@ -152,6 +154,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
QTreeView *mLayerTreeView = nullptr;
QgsFloatingWidget *mAdvancedConfigContainer = nullptr;

QAction *mEditVerticesAllLayersAction = nullptr;

void cleanGroup( QgsLayerTreeNode *node );
};

Expand Down
7 changes: 6 additions & 1 deletion src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -470,6 +470,8 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QList<Vertex> vertices;
QList<Vertex> selectedVertices;

const bool allLayers = canvas()->snappingUtils()->config().editVerticesOnAllLayers();

// for each editable layer, select vertices
const auto layers = canvas()->layers();
for ( QgsMapLayer *layer : layers )
Expand All @@ -478,6 +480,9 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( !vlayer || !vlayer->isEditable() || !vlayer->isSpatial() )
continue;

if ( !allLayers && vlayer != currentVectorLayer() )
continue;

QgsRectangle layerRect = toLayerCoordinates( vlayer, map_rect );
QgsFeature f;
QgsFeatureIterator fi = vlayer->getFeatures( QgsFeatureRequest( layerRect ).setSubsetOfAttributes( QgsAttributeList() ) );
Expand Down Expand Up @@ -691,7 +696,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
}

// if there is no match from the current layer, try to use any editable vector layer
if ( !m.isValid() )
if ( !m.isValid() && oldConfig.editVerticesOnAllLayers() )
{
const auto layers = canvas()->layers();
for ( QgsMapLayer *layer : layers )
Expand Down
18 changes: 18 additions & 0 deletions src/core/qgssnappingconfig.cpp
Expand Up @@ -111,13 +111,15 @@ bool QgsSnappingConfig::operator==( const QgsSnappingConfig &other ) const
&& mTolerance == other.mTolerance
&& mUnits == other.mUnits
&& mIntersectionSnapping == other.mIntersectionSnapping
&& mEditVerticesOnAllLayers == other.mEditVerticesOnAllLayers
&& mIndividualLayerSettings == other.mIndividualLayerSettings;
}

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

// assign main (standard) config
mEditVerticesOnAllLayers = editAllLayers;
mEnabled = enabled;
mMode = mode;
mType = type;
Expand Down Expand Up @@ -237,6 +240,16 @@ void QgsSnappingConfig::setIntersectionSnapping( bool enabled )
mIntersectionSnapping = enabled;
}

bool QgsSnappingConfig::editVerticesOnAllLayers() const
{
return mEditVerticesOnAllLayers;
}

void QgsSnappingConfig::setEditVerticesOnAllLayers( bool enabled )
{
mEditVerticesOnAllLayers = enabled;
}

QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> QgsSnappingConfig::individualLayerSettings() const
{
return mIndividualLayerSettings;
Expand Down Expand Up @@ -271,6 +284,7 @@ bool QgsSnappingConfig::operator!=( const QgsSnappingConfig &other ) const
|| mType != other.mType
|| mTolerance != other.mTolerance
|| mUnits != other.mUnits
|| mEditVerticesOnAllLayers != other.mEditVerticesOnAllLayers
|| mIndividualLayerSettings != other.mIndividualLayerSettings;
}

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

if ( snapSettingsElem.hasAttribute( QStringLiteral( "edit-vertices-on-all-layers" ) ) )
mEditVerticesOnAllLayers = snapSettingsElem.attribute( QStringLiteral( "edit-vertices-on-all-layers" ) ) == QLatin1String( "1" );

// do not clear the settings as they must be automatically synchronized with current layers
QDomNodeList nodes = snapSettingsElem.elementsByTagName( QStringLiteral( "individual-layer-settings" ) );
if ( nodes.count() )
Expand Down Expand Up @@ -344,6 +361,7 @@ void QgsSnappingConfig::writeProject( QDomDocument &doc )
snapSettingsElem.setAttribute( QStringLiteral( "tolerance" ), mTolerance );
snapSettingsElem.setAttribute( QStringLiteral( "unit" ), ( int )mUnits );
snapSettingsElem.setAttribute( QStringLiteral( "intersection-snapping" ), QString::number( mIntersectionSnapping ) );
snapSettingsElem.setAttribute( QStringLiteral( "edit-vertices-on-all-layers" ), QString::number( mEditVerticesOnAllLayers ) );

QDomElement ilsElement = doc.createElement( QStringLiteral( "individual-layer-settings" ) );
QHash<QgsVectorLayer *, IndividualLayerSettings>::const_iterator layerIt = mIndividualLayerSettings.constBegin();
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgssnappingconfig.h
Expand Up @@ -172,6 +172,10 @@ class CORE_EXPORT QgsSnappingConfig
//! Sets if the snapping on intersection is enabled
void setIntersectionSnapping( bool enabled );

bool editVerticesOnAllLayers() const;

void setEditVerticesOnAllLayers( bool enabled );

//! Returns individual snapping settings for all layers
#ifndef SIP_RUN
QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> individualLayerSettings() const;
Expand Down Expand Up @@ -292,6 +296,7 @@ class CORE_EXPORT QgsSnappingConfig
double mTolerance = 0.0;
QgsTolerance::UnitType mUnits = QgsTolerance::ProjectUnits;
bool mIntersectionSnapping = false;
bool mEditVerticesOnAllLayers = true;

QHash<QgsVectorLayer *, IndividualLayerSettings> mIndividualLayerSettings;

Expand Down
22 changes: 22 additions & 0 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -4207,6 +4207,28 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_30">
<property name="title">
<string>Vertex tool</string>
</property>
<layout class="QGridLayout" name="_13">
<item row="0" column="0">
<widget class="QCheckBox" name="mEditVerticesOnAllLayersDefault">
<property name="toolTip">
<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>
</property>
<property name="text">
<string>Edit vertices of all editable layers at once by default</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mVertexMarkerGroupBox">
<property name="title">
Expand Down

0 comments on commit 6363aba

Please sign in to comment.