void QgsBrowserDockWidget::showContextMenu( QPoint pt ) { QModelIndex index = mProxyModel->mapToSource( mBrowserView->indexAt( pt ) ); QgsDataItem *item = mModel->dataItem( index ); if ( !item ) return; QMenu *menu = new QMenu( this ); if ( item->type() == QgsDataItem::Directory ) { QgsSettings settings; QStringList favDirs = settings.value( QStringLiteral( "browser/favourites" ) ).toStringList(); bool inFavDirs = item->parent() && item->parent()->type() == QgsDataItem::Favorites; if ( item->parent() && !inFavDirs ) { // only non-root directories can be added as favorites menu->addAction( tr( "Add as a Favorite" ), this, SLOT( addFavorite() ) ); } else if ( inFavDirs ) { // only favorites can be removed menu->addAction( tr( "Remove Favorite" ), this, SLOT( removeFavorite() ) ); } menu->addAction( tr( "Properties..." ), this, SLOT( showProperties() ) ); menu->addAction( tr( "Hide from Browser" ), this, SLOT( hideItem() ) ); QAction *action = menu->addAction( tr( "Fast Scan this Directory" ), this, SLOT( toggleFastScan() ) ); action->setCheckable( true ); action->setChecked( settings.value( QStringLiteral( "qgis/scanItemsFastScanUris" ), QStringList() ).toStringList().contains( item->path() ) ); } else if ( item->type() == QgsDataItem::Layer ) { menu->addAction( tr( "Add Selected Layer(s)" ), this, SLOT( addSelectedLayers() ) ); menu->addAction( tr( "Properties..." ), this, SLOT( showProperties() ) ); } else if ( item->type() == QgsDataItem::Favorites ) { menu->addAction( tr( "Add a Directory..." ), this, SLOT( addFavoriteDirectory() ) ); } QList<QAction *> actions = item->actions(); if ( !actions.isEmpty() ) { if ( !menu->actions().isEmpty() ) menu->addSeparator(); // add action to the menu menu->addActions( actions ); } if ( menu->actions().isEmpty() ) { delete menu; return; } menu->popup( mBrowserView->mapToGlobal( pt ) ); }
void QgsBrowserDockWidget::showContextMenu( const QPoint & pt ) { QModelIndex idx = mBrowserView->indexAt( pt ); QgsDataItem* item = mModel->dataItem( idx ); if ( !item ) return; QMenu *menu = new QMenu( this ); if ( item->type() == QgsDataItem::Directory ) { QSettings settings; QStringList favDirs = settings.value( "/browser/favourites" ).toStringList(); bool inFavDirs = favDirs.contains( item->path() ); if ( item->parent() != NULL && !inFavDirs ) { // only non-root directories can be added as favourites menu->addAction( tr( "Add as a favourite" ), this, SLOT( addFavourite() ) ); } else if ( inFavDirs ) { // only favourites can be removed menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) ); } } else if ( item->type() == QgsDataItem::Layer ) { menu->addAction( tr( "Add Layer" ), this, SLOT( addCurrentLayer( ) ) ); menu->addAction( tr( "Add Selected Layers" ), this, SLOT( addSelectedLayers() ) ); menu->addAction( tr( "Properties" ), this, SLOT( showProperties( ) ) ); } else if ( item->type() == QgsDataItem::Favourites ) { menu->addAction( tr( "Add a directory" ), this, SLOT( addFavouriteDirectory() ) ); } QList<QAction*> actions = item->actions(); if ( !actions.isEmpty() ) { if ( !menu->actions().isEmpty() ) menu->addSeparator(); // add action to the menu menu->addActions( actions ); } if ( menu->actions().count() == 0 ) { delete menu; return; } menu->popup( mBrowserView->mapToGlobal( pt ) ); }