void QgsWelcomePage::showContextMenuForProjects( QPoint point ) { QModelIndex index = mRecentProjectsListView->indexAt( point ); if ( !index.isValid() ) return; bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool(); QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString(); if ( path.isEmpty() ) return; bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled; QMenu *menu = new QMenu( this ); if ( enabled ) { if ( !pin ) { QAction *pinAction = new QAction( tr( "Pin to List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->pinProject( index ); emit projectPinned( index.row() ); } ); menu->addAction( pinAction ); } else { QAction *pinAction = new QAction( tr( "Unpin from List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->unpinProject( index ); emit projectUnpinned( index.row() ); } ); menu->addAction( pinAction ); } QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu ); connect( openFolderAction, &QAction::triggered, this, [path] { QFileInfo fi( path ); QString folder = fi.path(); QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) ); } ); menu->addAction( openFolderAction ); } else { QAction *rescanAction = new QAction( tr( "Refresh" ), menu ); connect( rescanAction, &QAction::triggered, this, [this, index] { mModel->recheckProject( index ); } ); menu->addAction( rescanAction ); } QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu ); connect( removeProjectAction, &QAction::triggered, this, [this, index] { mModel->removeProject( index ); emit projectRemoved( index.row() ); } ); menu->addAction( removeProjectAction ); menu->popup( mapToGlobal( point ) ); }
void QgsWelcomePage::showContextMenuForProjects( QPoint point ) { QModelIndex index = mRecentProjectsListView->indexAt( point ); if ( !index.isValid() ) return; bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool(); QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString(); if ( path.isEmpty() ) return; bool enabled = mModel->flags( index ) & Qt::ItemIsEnabled; QMenu *menu = new QMenu( this ); if ( enabled ) { if ( !pin ) { QAction *pinAction = new QAction( tr( "Pin to List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->pinProject( index ); emit projectPinned( index.row() ); } ); menu->addAction( pinAction ); } else { QAction *pinAction = new QAction( tr( "Unpin from List" ), menu ); connect( pinAction, &QAction::triggered, this, [this, index] { mModel->unpinProject( index ); emit projectUnpinned( index.row() ); } ); menu->addAction( pinAction ); } QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu ); connect( openFolderAction, &QAction::triggered, this, [path] { QgsGui::instance()->nativePlatformInterface()->openFileExplorerAndSelectFile( path ); } ); menu->addAction( openFolderAction ); } else { QAction *rescanAction = new QAction( tr( "Refresh" ), menu ); connect( rescanAction, &QAction::triggered, this, [this, index] { mModel->recheckProject( index ); } ); menu->addAction( rescanAction ); // add an entry to open the closest existing path to the original project file location // to help users re-find moved/renamed projects! const QString closestPath = QgsFileUtils::findClosestExistingPath( path ); QAction *openFolderAction = new QAction( tr( "Open “%1”…" ).arg( QDir::toNativeSeparators( closestPath ) ), menu ); connect( openFolderAction, &QAction::triggered, this, [closestPath] { QDesktopServices::openUrl( QUrl::fromLocalFile( closestPath ) ); } ); menu->addAction( openFolderAction ); } QAction *removeProjectAction = new QAction( tr( "Remove from List" ), menu ); connect( removeProjectAction, &QAction::triggered, this, [this, index] { mModel->removeProject( index ); emit projectRemoved( index.row() ); } ); menu->addAction( removeProjectAction ); menu->popup( mapToGlobal( point ) ); }