BROWSER add optional button box to dock widget

The button box holds Close and Help buttons
and it is hidden by default. Signals are
forwarded.

Fix #54171
This commit is contained in:
Alessandro Pasotti 2023-09-28 11:07:53 +02:00 committed by Nyall Dawson
parent b9bfaf5c49
commit 3ecf3d5f61
4 changed files with 68 additions and 0 deletions

View File

@ -234,6 +234,17 @@ Splitter has been moved.
no longer used.
%End
void setButtonBoxVisibility( bool visible );
%Docstring
Set button box visibility to ``visible``.
.. note::
The button box is hidden by default.
.. versionadded:: 3.34
%End
signals:
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
%Docstring
@ -246,6 +257,20 @@ Emitted when drop uri list needs to be handled
void connectionsChanged();
%Docstring
Connections changed in the browser
%End
void helpRequested();
%Docstring
Emitted when the help button in the button box is clicked
.. versionadded:: 3.34
%End
void rejected();
%Docstring
Emitted when the close button in the button box is clicked
.. versionadded:: 3.34
%End
};

View File

@ -23,6 +23,7 @@
#include <QVBoxLayout>
#include <QFileDialog>
#include <QDialogButtonBox>
QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent )
: QgsDockWidget( parent )
@ -39,6 +40,15 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiMo
mWidget = new QgsBrowserWidget( browserModel );
layout->addWidget( mWidget );
mButtonBox = new QDialogButtonBox( QDialogButtonBox::StandardButton::Close | QDialogButtonBox::StandardButton::Help, this );
mButtonBox->setVisible( false );
layout->addWidget( mButtonBox );
// Forward signals from button box
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsBrowserDockWidget::helpRequested );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsBrowserDockWidget::rejected );
// Connect action signals
connect( mWidget, &QgsBrowserWidget::openFile, this, &QgsBrowserDockWidget::openFile );
connect( mWidget, &QgsBrowserWidget::handleDropUriList, this, &QgsBrowserDockWidget::handleDropUriList );
connect( mWidget, &QgsBrowserWidget::connectionsChanged, this, &QgsBrowserDockWidget::connectionsChanged );
@ -226,3 +236,8 @@ void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
void QgsBrowserDockWidget::splitterMoved()
{
}
void QgsBrowserDockWidget::setButtonBoxVisibility( bool visible )
{
mButtonBox->setVisible( visible );
}

View File

@ -22,6 +22,8 @@
class QgsMessageBar;
class QgsBrowserWidget;
class QDialogButtonBox;
class QAbstractButton;
/**
* \ingroup gui
@ -221,6 +223,13 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget
*/
Q_DECL_DEPRECATED void splitterMoved() SIP_DEPRECATED;
/**
* Set button box visibility to \a visible.
* \note The button box is hidden by default.
* \since QGIS 3.34
*/
void setButtonBoxVisibility( bool visible );
signals:
//! Emitted when a file needs to be opened
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
@ -229,9 +238,22 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget
//! Connections changed in the browser
void connectionsChanged();
/**
* Emitted when the help button in the button box is clicked
* \since QGIS 3.34
*/
void helpRequested();
/**
* Emitted when the close button in the button box is clicked
* \since QGIS 3.34
*/
void rejected();
private:
QgsBrowserWidget *mWidget = nullptr;
QDialogButtonBox *mButtonBox = nullptr;
};
#endif // QGSBROWSERDOCKWIDGET_H

View File

@ -67,6 +67,12 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsBrowserGuiModel *brow
connect( mBrowserWidget, &QgsBrowserDockWidget::openFile, this, &QgsDataSourceManagerDialog::openFile );
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgsDataSourceManagerDialog::connectionsChanged );
connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget->browserWidget(), &QgsBrowserWidget::updateProjectHome );
connect( mBrowserWidget, &QgsBrowserDockWidget::helpRequested, this, [ = ]()
{
QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#the-browser-panel" ) );
} );
connect( mBrowserWidget, &QgsBrowserDockWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
mBrowserWidget->setButtonBoxVisibility( true );
// Add registered source select dialogs
const QList<QgsSourceSelectProvider *> sourceSelectProviders = QgsGui::sourceSelectProviderRegistry()->providers( );