Skip to content

Commit

Permalink
BROWSER add optional button box to dock widget
Browse files Browse the repository at this point in the history
The button box holds Close and Help buttons
and it is hidden by default. Signals are
forwarded.

Fix #54171
  • Loading branch information
elpaso authored and nyalldawson committed Oct 6, 2023
1 parent b9bfaf5 commit 3ecf3d5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/gui/auto_generated/qgsbrowserdockwidget.sip.in
Expand Up @@ -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
Expand All @@ -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

};
Expand Down
15 changes: 15 additions & 0 deletions src/gui/qgsbrowserdockwidget.cpp
Expand Up @@ -23,6 +23,7 @@

#include <QVBoxLayout>
#include <QFileDialog>
#include <QDialogButtonBox>

QgsBrowserDockWidget::QgsBrowserDockWidget( const QString &name, QgsBrowserGuiModel *browserModel, QWidget *parent )
: QgsDockWidget( parent )
Expand All @@ -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 );
Expand Down Expand Up @@ -226,3 +236,8 @@ void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
void QgsBrowserDockWidget::splitterMoved()
{
}

void QgsBrowserDockWidget::setButtonBoxVisibility( bool visible )
{
mButtonBox->setVisible( visible );
}
22 changes: 22 additions & 0 deletions src/gui/qgsbrowserdockwidget.h
Expand Up @@ -22,6 +22,8 @@

class QgsMessageBar;
class QgsBrowserWidget;
class QDialogButtonBox;
class QAbstractButton;

/**
* \ingroup gui
Expand Down Expand Up @@ -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() );
Expand All @@ -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
6 changes: 6 additions & 0 deletions src/gui/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -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( );
Expand Down

0 comments on commit 3ecf3d5

Please sign in to comment.