Hide Draw on Canvas option from QgsExtentWidget in modal dialogs

When widget is shown in a modal dialog, we can't offer the
option to draw the extent on the canvas

Refs #59063
This commit is contained in:
Nyall Dawson 2024-10-16 10:56:17 +10:00
parent a09a33757a
commit fbe47ef20c
4 changed files with 27 additions and 2 deletions

View File

@ -238,6 +238,8 @@ to permit access to the map canvas)
virtual void dropEvent( QDropEvent *event );
virtual void showEvent( QShowEvent *event );
};

View File

@ -238,6 +238,8 @@ to permit access to the map canvas)
virtual void dropEvent( QDropEvent *event );
virtual void showEvent( QShowEvent *event );
};

View File

@ -585,8 +585,7 @@ void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOptio
mCurrentExtentButton->setVisible( true );
mUseCanvasExtentAction->setVisible( true );
if ( drawOnCanvasOption )
mDrawOnCanvasAction->setVisible( true );
mDrawOnCanvasAction->setVisible( drawOnCanvasOption && !mBlockDrawOnCanvas );
mCondensedToolButton->setToolTip( tr( "Set to current map canvas extent" ) );
mCondensedToolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapIdentification.svg" ) ) );
@ -667,3 +666,20 @@ void QgsExtentWidget::dropEvent( QDropEvent *event )
mCondensedLineEdit->setHighlighted( false );
update();
}
void QgsExtentWidget::showEvent( QShowEvent * )
{
if ( mFirstShow )
{
// we don't support select on canvas if the dialog is modal
if ( QWidget *parentWindow = window() )
{
if ( parentWindow->isModal() )
{
mBlockDrawOnCanvas = true;
mDrawOnCanvasAction->setVisible( false );
}
}
mFirstShow = false;
}
}

View File

@ -241,6 +241,7 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
void dragEnterEvent( QDragEnterEvent *event ) override;
void dragLeaveEvent( QDragLeaveEvent *event ) override;
void dropEvent( QDropEvent *event ) override;
void showEvent( QShowEvent *event ) override;
private slots:
@ -292,6 +293,10 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
bool mHasFixedOutputCrs = false;
QRegularExpression mCondensedRe;
bool mFirstShow = true;
bool mBlockDrawOnCanvas = false;
void setValid( bool valid );
void setExtentToLayerExtent( const QString &layerId );