Link the application browser dock to the application message bar

This commit is contained in:
Nyall Dawson 2018-10-27 11:08:46 +10:00
parent 153f1b1138
commit 310d4f94fa
4 changed files with 55 additions and 0 deletions

View File

@ -34,6 +34,26 @@ Constructor for QgsBrowserDockWidget
void addFavoriteDirectory( const QString &favDir, const QString &name = QString() );
%Docstring
Add directory to favorites
%End
void setMessageBar( QgsMessageBar *bar );
%Docstring
Sets a message ``bar`` to use alongside the dock widget. Setting this allows items
to utilise the message bar to provide non-blocking feedback to users, e.g.
success or failure of actions.
.. seealso:: :py:func:`messageBar`
.. versionadded:: 3.6
%End
QgsMessageBar *messageBar();
%Docstring
Returns the message bar associated with the dock.
.. seealso:: :py:func:`setMessageBar`
.. versionadded:: 3.6
%End
public slots:

View File

@ -1020,6 +1020,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mBrowserModel = new QgsBrowserModel( this );
mBrowserWidget = new QgsBrowserDockWidget( tr( "Browser" ), mBrowserModel, this );
mBrowserWidget->setObjectName( QStringLiteral( "Browser" ) );
mBrowserWidget->setMessageBar( mInfoBar );
QShortcut *showBrowserDock = new QShortcut( QKeySequence( tr( "Ctrl+2" ) ), this );
connect( showBrowserDock, &QShortcut::activated, mBrowserWidget, &QgsDockWidget::toggleUserVisible );

View File

@ -339,6 +339,7 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
}
QgsDataItemGuiContext context;
context.setMessageBar( mMessageBar );
const QList< QgsDataItemGuiProvider * > providers = QgsGui::instance()->dataItemGuiProviderRegistry()->providers();
for ( QgsDataItemGuiProvider *provider : providers )
@ -383,6 +384,16 @@ void QgsBrowserDockWidget::addFavoriteDirectory( const QString &favDir, const QS
mModel->addFavoriteDirectory( favDir, name );
}
void QgsBrowserDockWidget::setMessageBar( QgsMessageBar *bar )
{
mMessageBar = bar;
}
QgsMessageBar *QgsBrowserDockWidget::messageBar()
{
return mMessageBar;
}
void QgsBrowserDockWidget::removeFavorite()
{
mModel->removeFavorite( mProxyModel->mapToSource( mBrowserView->currentIndex() ) );

View File

@ -33,6 +33,7 @@ class QgsDockBrowserTreeView;
class QgsLayerItem;
class QgsDataItem;
class QgsBrowserProxyModel;
class QgsMessageBar;
/**
* \ingroup gui
@ -55,6 +56,26 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
//! Add directory to favorites
void addFavoriteDirectory( const QString &favDir, const QString &name = QString() );
/**
* Sets a message \a bar to use alongside the dock widget. Setting this allows items
* to utilise the message bar to provide non-blocking feedback to users, e.g.
* success or failure of actions.
*
* \see messageBar()
*
* \since QGIS 3.6
*/
void setMessageBar( QgsMessageBar *bar );
/**
* Returns the message bar associated with the dock.
*
* \see setMessageBar()
*
* \since QGIS 3.6
*/
QgsMessageBar *messageBar();
public slots:
/**
@ -144,6 +165,8 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
// height fraction
float mPropertiesWidgetHeight;
QgsMessageBar *mMessageBar = nullptr;
};