Skip to content

Commit

Permalink
show "show more" item only when it is required (if there are more than 5
Browse files Browse the repository at this point in the history
hidden items in the list)
  • Loading branch information
alexbruy committed Aug 19, 2020
1 parent 602011a commit 7485602
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/app/browser/qgsinbuiltdataitemproviders.cpp
Expand Up @@ -177,6 +177,7 @@ void QgsAppDirectoryItemGuiProvider::populateContextMenu( QgsDataItem *item, QMe
QMenu *hiddenMenu = new QMenu( tr( "Hidden Items" ), menu ); QMenu *hiddenMenu = new QMenu( tr( "Hidden Items" ), menu );
int count = 0; int count = 0;
const QStringList hiddenPathList = settings.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList(); const QStringList hiddenPathList = settings.value( QStringLiteral( "/browser/hiddenPaths" ) ).toStringList();
static int MAX_HIDDEN_ENTRIES = 5;
for ( const QString &path : hiddenPathList ) for ( const QString &path : hiddenPathList )
{ {
QAction *action = new QAction( QDir::toNativeSeparators( path ), hiddenMenu ); QAction *action = new QAction( QDir::toNativeSeparators( path ), hiddenMenu );
Expand All @@ -202,17 +203,23 @@ void QgsAppDirectoryItemGuiProvider::populateContextMenu( QgsDataItem *item, QMe
} ); } );
hiddenMenu->addAction( action ); hiddenMenu->addAction( action );
count += 1; count += 1;
if ( count == 5 ) if ( count == MAX_HIDDEN_ENTRIES )
{ {
break; 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->addSeparator();
} );
hiddenMenu->addAction( moreAction ); 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 ) if ( count > 0 )
{ {
menu->addMenu( hiddenMenu ); menu->addMenu( hiddenMenu );
Expand Down

0 comments on commit 7485602

Please sign in to comment.