From 748560255571684ae8fac79352c47d044e9d5fca Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Wed, 19 Aug 2020 15:38:28 +0300 Subject: [PATCH] show "show more" item only when it is required (if there are more than 5 hidden items in the list) --- .../browser/qgsinbuiltdataitemproviders.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/browser/qgsinbuiltdataitemproviders.cpp b/src/app/browser/qgsinbuiltdataitemproviders.cpp index 4b7f16ed6c5..524f8244083 100644 --- a/src/app/browser/qgsinbuiltdataitemproviders.cpp +++ b/src/app/browser/qgsinbuiltdataitemproviders.cpp @@ -177,6 +177,7 @@ void QgsAppDirectoryItemGuiProvider::populateContextMenu( QgsDataItem *item, QMe QMenu *hiddenMenu = new QMenu( tr( "Hidden Items" ), menu ); int count = 0; const QStringList hiddenPathList = settings.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList(); + static int MAX_HIDDEN_ENTRIES = 5; for ( const QString &path : hiddenPathList ) { QAction *action = new QAction( QDir::toNativeSeparators( path ), hiddenMenu ); @@ -202,17 +203,23 @@ void QgsAppDirectoryItemGuiProvider::populateContextMenu( QgsDataItem *item, QMe } ); hiddenMenu->addAction( action ); count += 1; - if ( count == 5 ) + if ( count == MAX_HIDDEN_ENTRIES ) { break; } } - QAction *moreAction = new QAction( tr( "Show More…" ), hiddenMenu ); - connect( moreAction, &QAction::triggered, this, [ = ] + + if ( hiddenPathList.size() > MAX_HIDDEN_ENTRIES ) { - QgisApp::instance()->showOptionsDialog( QgisApp::instance(), QStringLiteral( "mOptionsPageDataSources" ) ); - } ); - hiddenMenu->addAction( moreAction ); + hiddenMenu->addSeparator(); + + QAction *moreAction = new QAction( tr( "Show More…" ), hiddenMenu ); + connect( moreAction, &QAction::triggered, this, [ = ] + { + QgisApp::instance()->showOptionsDialog( QgisApp::instance(), QStringLiteral( "mOptionsPageDataSources" ) ); + } ); + hiddenMenu->addAction( moreAction ); + } if ( count > 0 ) { menu->addMenu( hiddenMenu );