Skip to content

Commit

Permalink
Link the application browser dock to the application message bar
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2018
1 parent 153f1b1 commit 310d4f9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/gui/auto_generated/qgsbrowserdockwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() ) );
Expand Down
23 changes: 23 additions & 0 deletions src/gui/qgsbrowserdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class QgsDockBrowserTreeView;
class QgsLayerItem;
class QgsDataItem;
class QgsBrowserProxyModel;
class QgsMessageBar;

/**
* \ingroup gui
Expand All @@ -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:

/**
Expand Down Expand Up @@ -144,6 +165,8 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
// height fraction
float mPropertiesWidgetHeight;

QgsMessageBar *mMessageBar = nullptr;

};


Expand Down

0 comments on commit 310d4f9

Please sign in to comment.