| 236 | } |
| 237 | |
| 238 | void ProblemTreeView::contextMenuEvent(QContextMenuEvent* event) |
| 239 | { |
| 240 | QModelIndex index = indexAt(event->pos()); |
| 241 | if (!index.isValid()) |
| 242 | return; |
| 243 | |
| 244 | const auto problem = index.data(ProblemModel::ProblemRole).value<IProblem::Ptr>(); |
| 245 | if (!problem) { |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | QPointer<QMenu> m = new QMenu(this); |
| 250 | |
| 251 | m->addSection(i18nc("@title:menu", "Problem")); |
| 252 | auto copyDescriptionAction = m->addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), |
| 253 | i18nc("@action:inmenu", "&Copy Description")); |
| 254 | connect(copyDescriptionAction, &QAction::triggered, this, [problem]() { |
| 255 | QApplication::clipboard()->setText(descriptionFromProblem(problem), QClipboard::Clipboard); |
| 256 | }); |
| 257 | |
| 258 | QExplicitlySharedDataPointer<KDevelop::IAssistant> solution = problem->solutionAssistant(); |
| 259 | if (solution && !solution->actions().isEmpty()) { |
| 260 | QList<QAction*> actions; |
| 261 | const auto solutionActions = solution->actions(); |
| 262 | actions.reserve(solutionActions.size()); |
| 263 | for (auto assistantAction : solutionActions) { |
| 264 | auto action = assistantAction->toQAction(m.data()); |
| 265 | action->setIcon(QIcon::fromTheme(QStringLiteral("dialog-ok-apply"))); |
| 266 | actions << action; |
| 267 | } |
| 268 | |
| 269 | QString title = solution->title(); |
| 270 | title = KDevelop::htmlToPlainText(title); |
| 271 | title.replace(QLatin1String("'"), QLatin1String("\'")); |
| 272 | m->addSection(i18nc("@title:menu", "Solve: %1", title)); |
| 273 | m->addActions(actions); |
| 274 | } |
| 275 | |
| 276 | m->exec(event->globalPos()); |
| 277 | delete m; |
| 278 | |
| 279 | } |
| 280 | |
| 281 | void ProblemTreeView::resizeEvent(QResizeEvent* event) |
| 282 | { |
nothing calls this directly
no test coverage detected