| 419 | } |
| 420 | |
| 421 | QMenu* MainWindow::createPopupMenu() |
| 422 | { |
| 423 | // The menu created in this function appears as the context menu of the main menu. |
| 424 | // QMainWindow::createPopupMenu() returns a menu that contains the following actions (in order): |
| 425 | // 1) dock widget actions; |
| 426 | // 2) a separator action if there is at least one dock widget action; |
| 427 | // 3) toolbar actions. |
| 428 | // |
| 429 | // When a tool view is hidden, IdealController::showDockWidget() removes its dock widget from |
| 430 | // the main window. So dock widget actions for some tool views are absent from the popup menu. |
| 431 | // Triggering a dock widget action in the popup menu shows/closes the dock widget but does not check/uncheck |
| 432 | // the associated tool view action. This causes an inconsistency between the visibility of a dock widget |
| 433 | // and the checked state of its tool view action. Work around the incompleteness and the inconsistency |
| 434 | // by removing the dock widget actions and the no longer useful separator from the popup menu. |
| 435 | // A tool view action is a correct replacement for a dock widget action. All available |
| 436 | // tool view actions can be found in the main menu => Window => Tool Views menu. |
| 437 | |
| 438 | auto* const menu = KParts::MainWindow::createPopupMenu(); |
| 439 | if (!menu) { |
| 440 | return menu; // empty menu => nothing to do |
| 441 | } |
| 442 | |
| 443 | const auto actions = menu->actions(); |
| 444 | const auto separatorIt = std::find_if(actions.cbegin(), actions.cend(), [](const QAction* action) { |
| 445 | return action->isSeparator(); |
| 446 | }); |
| 447 | if (separatorIt == actions.cend()) { |
| 448 | // the absence of a separator means that there are no dock widgets => nothing to do |
| 449 | return menu; |
| 450 | } |
| 451 | |
| 452 | std::for_each(actions.cbegin(), separatorIt + 1, [menu](QAction* action) { |
| 453 | // Do not delete the actions, because the dock widget actions are reused via QDockWidget::toggleViewAction(), |
| 454 | // so destroying such an action causes a segmentation fault the next time it is used. The separator action |
| 455 | // is not reused and could be deleted here, but do not bother to, because the menu is its parent and will |
| 456 | // be destroyed soon enough - when closed. Besides, the separator action might be reused too in the future. |
| 457 | menu->removeAction(action); |
| 458 | }); |
| 459 | |
| 460 | return menu; |
| 461 | } |
| 462 | |
| 463 | void MainWindow::tabDoubleClicked(View* view) |
| 464 | { |
nothing calls this directly
no test coverage detected