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

Method selectionChanged

src/frontend/worksheet/WorksheetView.cpp:1602–1643  ·  view source on GitHub ↗

! * Called on selection changes in the view. * Determines which items were selected and deselected * and forwards these changes to \c Worksheet */

Source from the content-addressed store, hash-verified

1600 * and forwards these changes to \c Worksheet
1601 */
1602void WorksheetView::selectionChanged() {
1603 // if the project is being closed, the scene items are being removed and the selection can change.
1604 // don't react on these changes since this can lead crashes (worksheet object is already in the destructor).
1605 if (m_isClosing)
1606 return;
1607
1608 if (m_suppressSelectionChangedEvent)
1609 return;
1610
1611 QList<QGraphicsItem*> items = scene()->selectedItems();
1612
1613 // check, whether the previously selected items were deselected now.
1614 // Forward the deselection prior to the selection of new items
1615 // in order to avoid the unwanted multiple selection in project explorer
1616 for (auto* item : m_selectedItems) {
1617 if (items.indexOf(item) == -1)
1618 m_worksheet->setItemSelectedInView(item, false);
1619 }
1620
1621 // select new items
1622 if (items.isEmpty()) {
1623 // no items selected -> select the worksheet again.
1624 m_worksheet->setSelectedInView(true);
1625
1626 // if one of the "zoom&select" plot mouse modes was selected before, activate the default "selection mode" again
1627 // since no plots are selected now.
1628 if (m_mouseMode == MouseMode::Selection && m_cartesianPlotMouseMode != CartesianPlot::MouseMode::Selection) {
1629 cartesianPlotSelectionModeAction->setChecked(true);
1630 cartesianPlotMouseModeChanged(cartesianPlotSelectionModeAction);
1631 }
1632 } else {
1633 for (const auto* item : items)
1634 m_worksheet->setItemSelectedInView(item, true);
1635
1636 // items selected -> deselect the worksheet in the project explorer
1637 // prevents unwanted multiple selection with worksheet (if it was selected before)
1638 m_worksheet->setSelectedInView(false);
1639 }
1640
1641 m_selectedItems = std::move(items);
1642 handleCartesianPlotActions();
1643}
1644
1645void WorksheetView::handleCartesianPlotSelected(CartesianPlot* plot) {
1646 if (tbCartesianPlotAddNew) { // not available in the presenter mode

Callers 1

selectAllElementsMethod · 0.95

Calls 5

selectedItemsMethod · 0.80
setItemSelectedInViewMethod · 0.80
indexOfMethod · 0.45
isEmptyMethod · 0.45
setSelectedInViewMethod · 0.45

Tested by

no test coverage detected