Skip to content

Commit

Permalink
Remove dedicated "show editing toolbar" action from 3d windows
Browse files Browse the repository at this point in the history
Instead add right-click menu to main 3d window toolbar to toggle
optional toolbar visibilty, just like we do for the main QGIS
window.

This avoids UI bloat in 3d map windows, and removes an action which
will be rarely used.
  • Loading branch information
nyalldawson committed Jan 28, 2025
1 parent 4737998 commit 0225742
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/app/3d/qgs3dmapcanvaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )
{
const QgsSettings setting;

mToolbarMenu = new QMenu( tr( "Toolbars" ), this );
mToolbarMenu->setObjectName( QStringLiteral( "mToolbarMenu" ) );

QToolBar *toolBar = new QToolBar( this );
toolBar->setIconSize( QgisApp::instance()->iconSize( isDocked ) );

Expand All @@ -79,6 +82,7 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )

// Editing toolbar
mEditingToolBar = new QToolBar( this );
mEditingToolBar->setWindowTitle( tr( "Editing Toolbar" ) );
mEditingToolBar->setVisible( false );

QAction *actionPointCloudChangeAttributeTool = mEditingToolBar->addAction( QIcon( QgsApplication::iconPath( "mActionSelectPolygon.svg" ) ), tr( "Change Point Cloud Attribute" ), this, &Qgs3DMapCanvasWidget::changePointCloudAttribute );
Expand All @@ -90,8 +94,6 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )
mSpinChangeAttributeValue = new QgsDoubleSpinBox();
mEditingToolBar->addWidget( new QLabel( tr( "Value" ) ) );
mEditingToolBar->addWidget( mSpinChangeAttributeValue );
QAction *actionEditingToolbar = toolBar->addAction( QIcon( QgsApplication::iconPath( "mIconPointCloudLayer.svg" ) ), tr( "Show Editing Toolbar" ), this, [this] { mEditingToolBar->setVisible( !mEditingToolBar->isVisible() ); } );
actionEditingToolbar->setCheckable( true );
connect( mCboChangeAttribute, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) { onPointCloudChangeAttributeSettingsChanged(); } );
connect( mSpinChangeAttributeValue, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, [this]( double ) { onPointCloudChangeAttributeSettingsChanged(); } );

Expand Down Expand Up @@ -342,6 +344,24 @@ Qgs3DMapCanvasWidget::Qgs3DMapCanvasWidget( const QString &name, bool isDocked )
} );

updateLayerRelatedActions( QgisApp::instance()->activeLayer() );

QList<QAction *> toolbarMenuActions;
// Set action names so that they can be used in customization
for ( QToolBar *toolBar : { mEditingToolBar } )
{
toolBar->toggleViewAction()->setObjectName( "mActionToggle" + toolBar->objectName().mid( 1 ) );
toolbarMenuActions << toolBar->toggleViewAction();
}

// sort actions in toolbar menu
std::sort( toolbarMenuActions.begin(), toolbarMenuActions.end(), []( QAction *a, QAction *b ) {
return QString::localeAwareCompare( a->text(), b->text() ) < 0;
} );

mToolbarMenu->addActions( toolbarMenuActions );

toolBar->installEventFilter( this );
mEditingToolBar->installEventFilter( this );
}

Qgs3DMapCanvasWidget::~Qgs3DMapCanvasWidget()
Expand Down Expand Up @@ -454,6 +474,26 @@ void Qgs3DMapCanvasWidget::updateLayerRelatedActions( QgsMapLayer *layer )
enableEditingTools( pcLayer->isEditable() );
}

bool Qgs3DMapCanvasWidget::eventFilter( QObject *watched, QEvent *event )
{
if ( qobject_cast< QToolBar * >( watched ) )
{
if ( event->type() != QEvent::MouseButtonPress )
return QObject::eventFilter( watched, event );

QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>( event );
if ( !mouseEvent )
return QObject::eventFilter( watched, event );

if ( mouseEvent->button() != Qt::RightButton )
return QObject::eventFilter( watched, event );

mToolbarMenu->exec( mouseEvent->globalPos() );
return false;
}
return QObject::eventFilter( watched, event );
}

void Qgs3DMapCanvasWidget::toggleNavigationWidget( bool visibility )
{
mNavigationWidget->setVisible( visibility );
Expand Down
5 changes: 5 additions & 0 deletions src/app/3d/qgs3dmapcanvaswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget

void updateLayerRelatedActions( QgsMapLayer *layer );

bool eventFilter( QObject *watched, QEvent *event ) override;


private slots:
void resetView();
void configure();
Expand Down Expand Up @@ -161,6 +164,8 @@ class APP_EXPORT Qgs3DMapCanvasWidget : public QWidget
QToolBar *mEditingToolBar = nullptr;
QComboBox *mCboChangeAttribute = nullptr;
QgsDoubleSpinBox *mSpinChangeAttributeValue = nullptr;

QMenu *mToolbarMenu = nullptr;
};

#endif // QGS3DMAPCANVASWIDGET_H

0 comments on commit 0225742

Please sign in to comment.