Skip to content
Permalink
Browse files
Disable Z/M parts when layer is not 3D or Measure
  • Loading branch information
lbartoletti authored and nyalldawson committed Sep 12, 2021
1 parent 0706585 commit 453d85c6a2764128dba983e0da3257f10325d2bd
@@ -212,6 +212,13 @@ Clear any cached previous clicks and helper lines
bool cadEnabled() const;
%Docstring
determines if CAD tools are enabled or if map tools behaves "nomally"
%End

void switchZM( void );
%Docstring
Determines if Z or M will be enabled.

.. versionadded:: 3.20
%End

bool constructionMode() const;
@@ -312,9 +312,41 @@ void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
clear();
setConstructionMode( false );

switchZM();
emit cadEnabledChanged( enabled );
}


void QgsAdvancedDigitizingDockWidget::switchZM( void )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( vlayer )
{

const QgsWkbTypes::Type type = vlayer->wkbType();
mRelativeZButton->setEnabled( QgsWkbTypes::hasZ( type ) );
mZLabel->setEnabled( QgsWkbTypes::hasZ( type ) );
mZLineEdit->setEnabled( QgsWkbTypes::hasZ( type ) );
if ( mZLineEdit->isEnabled() )
mZLineEdit->setText( QLocale().toString( QgsMapToolEdit( mMapCanvas ).defaultZValue(), 'f', 6 ) );
else
mZLineEdit->clear();
mLockZButton->setEnabled( QgsWkbTypes::hasZ( type ) );
mRepeatingLockZButton->setEnabled( QgsWkbTypes::hasZ( type ) );

mRelativeMButton->setEnabled( QgsWkbTypes::hasM( type ) );
mMLabel->setEnabled( QgsWkbTypes::hasM( type ) );
mMLineEdit->setEnabled( QgsWkbTypes::hasM( type ) );
if ( mMLineEdit->isEnabled() )
mMLineEdit->setText( QLocale().toString( 0.0, 'f', 6 ) );
else
mMLineEdit->clear();
mLockMButton->setEnabled( QgsWkbTypes::hasM( type ) );
mRepeatingLockMButton->setEnabled( QgsWkbTypes::hasM( type ) );
}

}

void QgsAdvancedDigitizingDockWidget::activateCad( bool enabled )
{
enabled &= mCurrentMapToolSupportsCad;
@@ -1346,24 +1378,6 @@ void QgsAdvancedDigitizingDockWidget::enable()
mErrorLabel->hide();
mCadWidget->show();

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( vlayer )
{

const QgsWkbTypes::Type type = vlayer->wkbType();
mRelativeZButton->setEnabled( QgsWkbTypes::hasZ( type ) );
mZLabel->setEnabled( QgsWkbTypes::hasZ( type ) );
mZLineEdit->setEnabled( QgsWkbTypes::hasZ( type ) );
mLockZButton->setEnabled( QgsWkbTypes::hasZ( type ) );
mRepeatingLockZButton->setEnabled( QgsWkbTypes::hasZ( type ) );

mRelativeMButton->setEnabled( QgsWkbTypes::hasM( type ) );
mMLabel->setEnabled( QgsWkbTypes::hasM( type ) );
mMLineEdit->setEnabled( QgsWkbTypes::hasM( type ) );
mLockMButton->setEnabled( QgsWkbTypes::hasM( type ) );
mRepeatingLockMButton->setEnabled( QgsWkbTypes::hasM( type ) );
}

mCurrentMapToolSupportsCad = true;

if ( mSessionActive && !isVisible() )
@@ -250,6 +250,12 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
//! determines if CAD tools are enabled or if map tools behaves "nomally"
bool cadEnabled() const { return mCadEnabled; }

/**
* Determines if Z or M will be enabled.
* \since QgIS 3.20
*/
void switchZM( void );

//! construction mode is used to draw intermediate points. These points won't be given any further (i.e. to the map tools)
bool constructionMode() const { return mConstructionMode; }

@@ -151,6 +151,7 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
mTempRubberBand->setRubberBandGeometryType( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );

resetRubberBand();
cadDockWidget()->switchZM();
}


0 comments on commit 453d85c

Please sign in to comment.