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 FavoriteItemWidget::on_removeFavoriteButton_clicked() { emit removeFavorite(item); }