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

Method setItemSelectedInView

src/backend/worksheet/Worksheet.cpp:434–478  ·  view source on GitHub ↗

! * Emits the signal to select or to deselect the aspect corresponding to \c QGraphicsItem \c item in the project explorer, * if \c selected=true or \c selected=false, respectively. * The signal is handled in \c AspectTreeModel and forwarded to the tree view in \c ProjectExplorer. * This function is called in \c WorksheetView upon selection changes. */

Source from the content-addressed store, hash-verified

432 * This function is called in \c WorksheetView upon selection changes.
433 */
434void Worksheet::setItemSelectedInView(const QGraphicsItem* item, const bool b) {
435 // determine the corresponding aspect
436 AbstractAspect* aspect(nullptr);
437 for (const auto* child : children<WorksheetElement>(ChildIndexFlag::IncludeHidden)) {
438 aspect = this->aspectFromGraphicsItem(child, item);
439 if (aspect)
440 break;
441 }
442
443 if (!aspect)
444 return;
445
446 // forward selection/deselection to AbstractTreeModel
447 if (b)
448 Q_EMIT childAspectSelectedInView(aspect);
449 else
450 Q_EMIT childAspectDeselectedInView(aspect);
451
452 // handle the resize items on selection changes
453 if (layout() == Worksheet::Layout::NoLayout) {
454 // only one selected plot can be made resizable
455 if (b) {
456 const auto& items = m_view->selectedItems();
457 if (items.size() == 1) {
458 // only one object is selected.
459 // make it resiable if its a container
460 auto* container = dynamic_cast<WorksheetElementContainer*>(aspect);
461 if (container)
462 container->setResizeEnabled(true);
463 } else if (items.size() > 1) {
464 // multiple objects are selected, make all containers non-resizable
465 const auto& elements = children<WorksheetElement>();
466 for (auto* element : elements) {
467 auto* container = dynamic_cast<WorksheetElementContainer*>(element);
468 if (container)
469 container->setResizeEnabled(false);
470 }
471 }
472 } else {
473 auto* container = dynamic_cast<WorksheetElementContainer*>(aspect);
474 if (container)
475 container->setResizeEnabled(false);
476 }
477 }
478}
479
480/*!
481 * helper function: checks whether \c aspect or one of its children has the \c GraphicsItem \c item

Callers 4

selectAllElementsMethod · 0.80
selectionChangedMethod · 0.80
navigateNextPrevCurveMethod · 0.80

Calls 4

selectedItemsMethod · 0.80
setResizeEnabledMethod · 0.80
sizeMethod · 0.45

Tested by 1