* \brief Return a new context menu. * * The caller takes ownership of the menu. */
| 314 | * The caller takes ownership of the menu. |
| 315 | */ |
| 316 | QMenu* AbstractAspect::createContextMenu() { |
| 317 | QMenu* menu = new QMenu(); |
| 318 | menu->addSection(this->name()); |
| 319 | |
| 320 | // TODO: activate this again when the functionality is implemented |
| 321 | // menu->addAction( KStandardAction::cut(this) ); |
| 322 | |
| 323 | QAction* actionDuplicate = nullptr; |
| 324 | if (!isFixed() && m_type != AspectType::Project && m_type != AspectType::Notebook) { |
| 325 | // copy action: |
| 326 | // don't allow to copy fixed aspects |
| 327 | auto* action = KStandardAction::copy(this); |
| 328 | connect(action, &QAction::triggered, this, &AbstractAspect::copy); |
| 329 | menu->addAction(action); |
| 330 | |
| 331 | // duplicate action: |
| 332 | // don't allow to duplicate legends in the plots |
| 333 | if (m_type != AspectType::CartesianPlotLegend) { |
| 334 | actionDuplicate = new QAction(QIcon::fromTheme(QLatin1String("edit-copy")), i18n("Duplicate Here"), this); |
| 335 | actionDuplicate->setShortcut(Qt::CTRL | Qt::Key_D); |
| 336 | connect(actionDuplicate, &QAction::triggered, this, &AbstractAspect::duplicate); |
| 337 | menu->addAction(actionDuplicate); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // paste action: |
| 342 | // determine the aspect type of the content available in the clipboard |
| 343 | // and enable the paste entry if the content is labplot specific |
| 344 | // and if it can be pasted into the current aspect |
| 345 | QString name; |
| 346 | auto t = clipboardAspectType(name); |
| 347 | if (t != AspectType::AbstractAspect && pasteTypes().indexOf(t) != -1) { |
| 348 | auto* action = KStandardAction::paste(this); |
| 349 | action->setText(i18n("Paste '%1'", name)); |
| 350 | if (actionDuplicate) |
| 351 | menu->insertAction(actionDuplicate, action); |
| 352 | else |
| 353 | menu->addAction(action); |
| 354 | connect(action, &QAction::triggered, [=]() { |
| 355 | paste(); |
| 356 | }); |
| 357 | } |
| 358 | menu->addSeparator(); |
| 359 | |
| 360 | // action to create data spreadsheet based on the results of the calculations for types that support it |
| 361 | QAction* actionDataSpreadsheet = new QAction(QIcon::fromTheme(QLatin1String("labplot-spreadsheet")), i18n("Create Data Spreadsheet"), this); |
| 362 | |
| 363 | // handle types that support it |
| 364 | bool dataAvailable = false; |
| 365 | if (const auto* analysisCurve = dynamic_cast<XYAnalysisCurve*>(this)) { |
| 366 | if (analysisCurve->resultAvailable()) { |
| 367 | connect(actionDataSpreadsheet, &QAction::triggered, static_cast<XYAnalysisCurve*>(this), &XYAnalysisCurve::createDataSpreadsheet); |
| 368 | dataAvailable = true; |
| 369 | } |
| 370 | } else if (const auto* equationCurve = dynamic_cast<XYEquationCurve*>(this)) { |
| 371 | if (equationCurve->dataAvailable()) { |
| 372 | connect(actionDataSpreadsheet, &QAction::triggered, static_cast<XYEquationCurve*>(this), &XYEquationCurve::createDataSpreadsheet); |
| 373 | dataAvailable = true; |
nothing calls this directly
no test coverage detected