[ui] Make the show bookmarks action focus on browser panel's bookmark node

This commit is contained in:
nirvn 2019-09-05 17:44:04 +07:00 committed by Mathieu Pellerin
parent 3af35b5844
commit c1cce181b4
8 changed files with 52 additions and 12 deletions

View File

@ -121,6 +121,10 @@ Sets filter case sensitivity
void setFilter();
%Docstring
Apply filter to the model
%End
void setActiveIndex( const QModelIndex &index );
%Docstring
Sets the selection to ``index`` and expand it
%End
void updateProjectHome();
%Docstring

View File

@ -930,7 +930,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
connect( showBookmarksDock, &QShortcut::activated, mBookMarksDockWidget, &QgsDockWidget::toggleUserVisible );
showBookmarksDock->setObjectName( QStringLiteral( "ShowBookmarksPanel" ) );
showBookmarksDock->setWhatsThis( tr( "Show Bookmarks Panel" ) );
mBookMarksDockWidget->setToggleVisibilityAction( mActionShowBookmarks );
mBookMarksDockWidget->setToggleVisibilityAction( mActionShowBookmarkManager );
connect( mActionShowBookmarks, &QAction::triggered, this, [ = ] { showBookmarks(); } );
endProfile();
@ -3541,6 +3543,7 @@ void QgisApp::setTheme( const QString &themeName )
mActionMeasureArea->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMeasureArea.svg" ) ) );
mActionMeasureAngle->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMeasureAngle.svg" ) ) );
mActionMapTips->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapTips.svg" ) ) );
mActionShowBookmarkManager->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowBookmarks.svg" ) ) );
mActionShowBookmarks->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowBookmarks.svg" ) ) );
mActionNewBookmark->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewBookmark.svg" ) ) );
mActionCustomProjection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionCustomProjection.svg" ) ) );
@ -13788,7 +13791,14 @@ void QgisApp::newBookmark( bool inProject )
dlg->show();
}
void QgisApp::showBookmarks( bool show )
void QgisApp::showBookmarks()
{
mBrowserWidget->setUserVisible( true );
QModelIndex index = browserModel()->findPath( QStringLiteral( "bookmarks:" ) );
mBrowserWidget->setActiveIndex( index );
}
void QgisApp::showBookmarkManager( bool show )
{
mBookMarksDockWidget->setUserVisible( show );
}

View File

@ -479,6 +479,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionMapTips() { return mActionMapTips; }
QAction *actionNewBookmark() { return mActionNewBookmark; }
QAction *actionShowBookmarks() { return mActionShowBookmarks; }
QAction *actionShowBookmarkManager() { return mActionShowBookmarkManager; }
QAction *actionDraw() { return mActionDraw; }
QAction *actionDataSourceManager() { return mActionDataSourceManager; }
@ -1070,8 +1071,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Create a new file from a template project
bool fileNewFromTemplate( const QString &fileName );
//! Show the spatial bookmarks dialog
void showBookmarks( bool show );
//! Show the spatial bookmark manager panel
void showBookmarkManager( bool show );
//! Show and focus the browser panel to spatial bookmarks
void showBookmarks();
//! Create a new spatial bookmark
void newBookmark( bool inProject = false );

View File

@ -972,10 +972,10 @@ void QgsBookmarksItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu
QgisApp::instance()->newBookmark();
} );
menu->addAction( addBookmark );
QAction *showBookmarksPanel = new QAction( tr( "Show Spatial Bookmarks Panel" ), menu );
QAction *showBookmarksPanel = new QAction( tr( "Show Spatial Bookmarks Manager" ), menu );
connect( showBookmarksPanel, &QAction::triggered, this, [ = ]
{
QgisApp::instance()->showBookmarks( true );
QgisApp::instance()->showBookmarkManager( true );
} );
menu->addAction( showBookmarksPanel );
menu->addSeparator();

View File

@ -588,6 +588,16 @@ void QgsBrowserDockWidget::enablePropertiesWidget( bool enable )
}
}
void QgsBrowserDockWidget::setActiveIndex( const QModelIndex &index )
{
if ( index.isValid() )
{
QModelIndex proxyIndex = mProxyModel->mapFromSource( index );
mBrowserView->expand( proxyIndex );
mBrowserView->setCurrentIndex( proxyIndex );
}
}
void QgsBrowserDockWidget::splitterMoved()
{
QList<int> sizes = mSplitter->sizes();

View File

@ -127,6 +127,8 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
void setCaseSensitive( bool caseSensitive );
//! Apply filter to the model
void setFilter();
//! Sets the selection to \a index and expand it
void setActiveIndex( const QModelIndex &index );
//! Update project home directory
void updateProjectHome();

View File

@ -144,6 +144,7 @@
<addaction name="mActionMapTips"/>
<addaction name="mActionNewBookmark"/>
<addaction name="mActionShowBookmarks"/>
<addaction name="mActionShowBookmarkManager"/>
<addaction name="mActionDraw"/>
<addaction name="separator"/>
<addaction name="mActionShowAllLayers"/>
@ -1373,13 +1374,25 @@
<normaloff>:/images/themes/default/mActionNewBookmark.svg</normaloff>:/images/themes/default/mActionNewBookmark.svg</iconset>
</property>
<property name="text">
<string>New Bookmark…</string>
<string>New Spatial Bookmark…</string>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</action>
<action name="mActionShowBookmarks">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionShowBookmarks.svg</normaloff>:/images/themes/default/mActionShowBookmarks.svg</iconset>
</property>
<property name="text">
<string>Show Spatial Bookmarks</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+B</string>
</property>
</action>
<action name="mActionShowBookmarkManager">
<property name="checkable">
<bool>true</bool>
</property>
@ -1388,10 +1401,7 @@
<normaloff>:/images/themes/default/mActionShowBookmarks.svg</normaloff>:/images/themes/default/mActionShowBookmarks.svg</iconset>
</property>
<property name="text">
<string>Show Bookmarks</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+B</string>
<string>Show Spatial Bookmark Manager</string>
</property>
</action>
<action name="mActionDraw">

View File

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Spatial Bookmarks</string>
<string>Spatial Bookmark Manager</string>
</property>
<widget class="QWidget" name="bookmarksDockContents">
<layout class="QGridLayout" name="gridLayout">