MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / contextMenuEvent

Method contextMenuEvent

gui/resultstree.cpp:608–737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606}
607
608void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
609{
610 QModelIndex index = indexAt(e->pos());
611 if (index.isValid()) {
612 bool multipleSelection = false;
613
614 mSelectionModel = selectionModel();
615 if (mSelectionModel->selectedRows().count() > 1)
616 multipleSelection = true;
617
618 mContextItem = dynamic_cast<ResultItem*>(mModel->itemFromIndex(index));
619
620 //Create a new context menu
621 QMenu menu(this);
622
623 //Create a signal mapper so we don't have to store data to class
624 //member variables
625 QSignalMapper signalMapper;
626
627 if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) {
628 //Create an action for the application
629 int defaultApplicationIndex = mApplications->getDefaultApplication();
630 defaultApplicationIndex = std::max(defaultApplicationIndex, 0);
631 const Application& app = mApplications->getApplication(defaultApplicationIndex);
632 auto *start = new QAction(app.getName(), &menu);
633 if (multipleSelection)
634 start->setDisabled(true);
635
636 //Add it to context menu
637 menu.addAction(start);
638
639 //Connect the signal to signal mapper
640 connect(start, &QAction::triggered, &signalMapper, QOverload<>::of(&QSignalMapper::map));
641
642 //Add a new mapping
643 signalMapper.setMapping(start, defaultApplicationIndex);
644
645 connect(&signalMapper, SIGNAL(mappedInt(int)),
646 this, SLOT(context(int)));
647 }
648
649 // Add popup menuitems
650 if (mContextItem) {
651 if (mApplications->getApplicationCount() > 0) {
652 menu.addSeparator();
653 }
654
655 int selectedFiles = 0;
656 int selectedResults = 0;
657
658 for (auto row : mSelectionModel->selectedRows()) {
659 auto *item = mModel->itemFromIndex(row);
660 if (!item->parent())
661 selectedFiles++;
662 else if (!item->parent()->parent())
663 selectedResults++;
664 }
665

Callers

nothing calls this directly

Calls 6

isCriticalErrorIdFunction · 0.85
getDefaultApplicationMethod · 0.80
isEmptyMethod · 0.80
QStringClass · 0.70
getApplicationCountMethod · 0.45
isCheckingMethod · 0.45

Tested by

no test coverage detected