Skip to content
Permalink
Browse files

Move favorites action handling from gui to app

  • Loading branch information
nyalldawson committed Oct 27, 2018
1 parent fab4154 commit c085d0edd54f412d08d4be44ae458f7756b4be67
@@ -31,9 +31,12 @@ Constructor for QgsBrowserDockWidget
:param parent: parent widget
%End
~QgsBrowserDockWidget();
void addFavoriteDirectory( const QString &favDir, const QString &name = QString() );

void addFavoriteDirectory( const QString &favDir, const QString &name = QString() ) /Deprecated/;
%Docstring
Add directory to favorites
Add directory to favorites.

.. deprecated:: will be removed in QGIS 4.0 - use the methods in QgsBrowserModel instead
%End

void setMessageBar( QgsMessageBar *bar );
@@ -78,9 +81,11 @@ Add current item to favorite.
.. deprecated:: will be removed in QGIS 4.0 - use the methods in QgsBrowserModel instead
%End

void addFavoriteDirectory();
void addFavoriteDirectory() /Deprecated/;
%Docstring
Add directory from file dialog to favorite
Add directory from file dialog to favorite.

.. deprecated:: will be removed in QGIS 4.0 - use the methods in QgsBrowserModel instead
%End

void removeFavorite() /Deprecated/;
@@ -246,3 +246,29 @@ void QgsProjectHomeItemGuiProvider::populateContextMenu( QgsDataItem *item, QMen
else
menu->addAction( setHome );
}

//
// QgsFavoritesItemGuiProvider
//

QString QgsFavoritesItemGuiProvider::name()
{
return QStringLiteral( "favorites_item" );
}

void QgsFavoritesItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
{
if ( item->type() != QgsDataItem::Favorites )
return;

QAction *addAction = new QAction( tr( "Add a Directory…" ), menu );
connect( addAction, &QAction::triggered, this, [ = ]
{
QString directory = QFileDialog::getExistingDirectory( QgisApp::instance(), tr( "Add Directory to Favorites" ) );
if ( !directory.isEmpty() )
{
QgisApp::instance()->browserModel()->addFavoriteDirectory( directory );
}
} );
menu->addAction( addAction );
}
@@ -65,6 +65,21 @@ class QgsProjectHomeItemGuiProvider : public QObject, public QgsDataItemGuiProvi
};


class QgsFavoritesItemGuiProvider : public QObject, public QgsDataItemGuiProvider
{
Q_OBJECT

public:

QgsFavoritesItemGuiProvider() = default;

QString name() override;

void populateContextMenu( QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context ) override;

};


#endif // QGSINBUILTDATAITEMPROVIDERS_H

@@ -1027,6 +1027,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsFavoritesItemGuiProvider() );

QShortcut *showBrowserDock = new QShortcut( QKeySequence( tr( "Ctrl+2" ) ), this );
connect( showBrowserDock, &QShortcut::activated, mBrowserWidget, &QgsDockWidget::toggleUserVisible );
@@ -194,6 +194,7 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )

const QModelIndexList selection = mBrowserView->selectionModel()->selectedIndexes();
QList< QgsDataItem * > selectedItems;
selectedItems.reserve( selection.size() );
for ( const QModelIndex &selectedIndex : selection )
{
QgsDataItem *selectedItem = mProxyModel->dataItem( selectedIndex );
@@ -255,10 +256,6 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
} );
}
}
else if ( item->type() == QgsDataItem::Favorites )
{
menu->addAction( tr( "Add a Directory…" ), this, SLOT( addFavoriteDirectory() ) );
}

const QList<QMenu *> menus = item->menus( menu );
QList<QAction *> actions = item->actions( menu );
@@ -308,15 +305,19 @@ void QgsBrowserDockWidget::addFavorite()
if ( !dirItem )
return;

Q_NOWARN_DEPRECATED_PUSH
addFavoriteDirectory( dirItem->dirPath() );
Q_NOWARN_DEPRECATED_POP
}

void QgsBrowserDockWidget::addFavoriteDirectory()
{
QString directory = QFileDialog::getExistingDirectory( this, tr( "Add directory to favorites" ) );
if ( !directory.isEmpty() )
{
Q_NOWARN_DEPRECATED_PUSH
addFavoriteDirectory( directory );
Q_NOWARN_DEPRECATED_POP
}
}

@@ -53,8 +53,12 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
*/
explicit QgsBrowserDockWidget( const QString &name, QgsBrowserModel *browserModel, QWidget *parent SIP_TRANSFERTHIS = nullptr );
~QgsBrowserDockWidget() override;
//! Add directory to favorites
void addFavoriteDirectory( const QString &favDir, const QString &name = QString() );

/**
* Add directory to favorites.
* \deprecated will be removed in QGIS 4.0 - use the methods in QgsBrowserModel instead
*/
Q_DECL_DEPRECATED void addFavoriteDirectory( const QString &favDir, const QString &name = QString() ) SIP_DEPRECATED;

/**
* Sets a message \a bar to use alongside the dock widget. Setting this allows items
@@ -95,8 +99,11 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
*/
Q_DECL_DEPRECATED void addFavorite() SIP_DEPRECATED;

//! Add directory from file dialog to favorite
void addFavoriteDirectory();
/**
* Add directory from file dialog to favorite.
* \deprecated will be removed in QGIS 4.0 - use the methods in QgsBrowserModel instead
*/
Q_DECL_DEPRECATED void addFavoriteDirectory() SIP_DEPRECATED;

/**
* Remove from favorite.

0 comments on commit c085d0e

Please sign in to comment.
You can’t perform that action at this time.