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

Method selectionChanged

src/frontend/ProjectExplorer.cpp:804–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

802}
803
804void ProjectExplorer::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
805 if (m_project->isLoading())
806 return;
807
808 // QDEBUG(Q_FUNC_INFO << ", selected/deselected = " << selected << "/" << deselected)
809
810 QModelIndex index;
811 AbstractAspect* aspect = nullptr;
812
813 // there are four model indices in each row
814 //-> divide by 4 to obtain the number of selected rows (=aspects)
815 const auto& sitems = selected.indexes();
816 for (int i = 0; i < sitems.size() / 4; ++i) {
817 index = sitems.at(i * 4);
818 aspect = static_cast<AbstractAspect*>(index.internalPointer());
819 QDEBUG("sitems ASPECT =" << aspect)
820 aspect->setSelected(true);
821 }
822
823 const auto& ditems = deselected.indexes();
824 for (int i = 0; i < ditems.size() / 4; ++i) {
825 index = ditems.at(i * 4);
826 aspect = static_cast<AbstractAspect*>(index.internalPointer());
827 QDEBUG("ditems ASPECT =" << aspect)
828 aspect->setSelected(false);
829 }
830
831 const auto& items = m_treeView->selectionModel()->selectedRows();
832 QList<AbstractAspect*> selectedAspects;
833 for (const auto& index : items) {
834 aspect = static_cast<AbstractAspect*>(index.internalPointer());
835 QDEBUG("items ASPECT =" << aspect)
836 selectedAspects << aspect;
837 }
838
839 // notify GuiObserver about the new selection
840 Q_EMIT selectedAspectsChanged(selectedAspects);
841
842 // notify MainWin about the new current aspect (last selected aspect).
843 if (!selectedAspects.isEmpty())
844 Q_EMIT currentAspectChanged(selectedAspects.last());
845
846 // emitting the signal above is done to show the properties widgets for the selected aspect(s).
847 // with this the project explorer looses the focus and don't react on the key events like DEL key press, etc.
848 // If we explicitly select an item in the project explorer (not via a selection in the view), we want to keep the focus here.
849 // TODO: after the focus is set again we react on DEL in the event filter, but navigation with the arrow keys in the table
850 // is still not possible. Looks like we need to set the selection again...
851 if (!m_changeSelectionFromView)
852 setFocus();
853 else
854 m_changeSelectionFromView = false;
855}
856
857void ProjectExplorer::expandSelected() {
858 const auto& items = m_treeView->selectionModel()->selectedIndexes();

Callers

nothing calls this directly

Calls 6

isLoadingMethod · 0.80
selectedRowsMethod · 0.80
selectionModelMethod · 0.80
sizeMethod · 0.45
setSelectedMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected