Skip to content

Commit

Permalink
[cad widget] Don't assume that the canvas current layer is the
Browse files Browse the repository at this point in the history
target layer for the cad dock, but instead query the canvas map tool
for the actual target layer

Fixes (among other things) z/m controls are active when a vector
layer with z/m is selected in the layer tree, even though the
current map tool is linked to a different layer which doesn't
support z/m
  • Loading branch information
nyalldawson committed Sep 24, 2021
1 parent f9def2d commit 55a76d1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -323,17 +323,34 @@ void QgsAdvancedDigitizingDockWidget::switchZM( )
bool enableZ = false;
bool enableM = false;

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( vlayer )
if ( QgsMapLayer *layer = targetLayer() )
{
const QgsWkbTypes::Type type = vlayer->wkbType();
enableZ = QgsWkbTypes::hasZ( type );
enableM = QgsWkbTypes::hasM( type );
}
switch ( layer->type() )
{
case QgsMapLayerType::VectorLayer:
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
const QgsWkbTypes::Type type = vlayer->wkbType();
enableZ = QgsWkbTypes::hasZ( type );
enableM = QgsWkbTypes::hasM( type );
break;
}

QgsMeshLayer *mlayer = qobject_cast<QgsMeshLayer *>( mMapCanvas->currentLayer() );
if ( mlayer )
enableZ = mlayer->isEditable();
case QgsMapLayerType::MeshLayer:
{
QgsMeshLayer *mlayer = qobject_cast<QgsMeshLayer *>( layer );
enableZ = mlayer->isEditable();
break;
}

case QgsMapLayerType::RasterLayer:
case QgsMapLayerType::PluginLayer:
case QgsMapLayerType::VectorTileLayer:
case QgsMapLayerType::AnnotationLayer:
case QgsMapLayerType::PointCloudLayer:
break;
}
}

setEnabledZ( enableZ );
setEnabledM( enableM );
Expand Down Expand Up @@ -472,6 +489,18 @@ void QgsAdvancedDigitizingDockWidget::settingsButtonTriggered( QAction *action )
}
}

QgsMapLayer *QgsAdvancedDigitizingDockWidget::targetLayer()
{
if ( QgsMapToolAdvancedDigitizing *advancedTool = qobject_cast< QgsMapToolAdvancedDigitizing * >( mMapCanvas->mapTool() ) )
{
return advancedTool->layer();
}
else
{
return mMapCanvas->currentLayer();
}
}

void QgsAdvancedDigitizingDockWidget::releaseLocks( bool releaseRepeatingLocks )
{
// release all locks except construction mode
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Expand Up @@ -857,6 +857,12 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
void settingsButtonTriggered( QAction *action );

private:

/**
* Returns the layer currently associated with the map tool using the dock widget.
*/
QgsMapLayer *targetLayer();

//! updates the UI depending on activation of the tools and clear points / release locks.
void setCadEnabled( bool enabled );

Expand Down

0 comments on commit 55a76d1

Please sign in to comment.