MCPcopy Create free account
hub / github.com/KDE/labplot / createContextMenu

Method createContextMenu

src/backend/core/AbstractAspect.cpp:316–432  ·  view source on GitHub ↗

* \brief Return a new context menu. * * The caller takes ownership of the menu. */

Source from the content-addressed store, hash-verified

314 * The caller takes ownership of the menu.
315 */
316QMenu* 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;

Callers

nothing calls this directly

Calls 10

nameMethod · 0.95
addSeparatorMethod · 0.80
resultAvailableMethod · 0.80
dataAvailableMethod · 0.80
binsMethod · 0.80
indexOfMethod · 0.45
setTextMethod · 0.45
isEmptyMethod · 0.45
typeMethod · 0.45
setIconMethod · 0.45

Tested by

no test coverage detected