add a list of ids for groups in the scene to allow selecting all items quicker

This commit is contained in:
Maxime Gimeno 2020-06-23 12:52:52 +02:00
parent 639a8b8e8e
commit 775a3fdb07
2 changed files with 17 additions and 3 deletions

View File

@ -90,6 +90,8 @@ Scene::addItem(CGAL::Three::Scene_item* item)
item->drawEdges(CGAL::Three::Three::mainViewer());
item->drawPoints(CGAL::Three::Three::mainViewer());
CGAL::Three::Three::mainViewer()->setDepthPeelingFbo(fbo);
if(group)
m_groups.append(id);
return id;
}
@ -110,6 +112,7 @@ Scene::replaceItem(Scene::Item_id index, CGAL::Three::Scene_item* item, bool emi
QList<Scene_item*> group_children;
if(group)
{
m_groups.removeAll(index);
Q_FOREACH(Item_id id, group->getChildren())
{
CGAL::Three::Scene_item* child = group->getChild(id);
@ -152,6 +155,7 @@ Scene::replaceItem(Scene::Item_id index, CGAL::Three::Scene_item* item, bool emi
if(group)
{
addGroup(group);
m_groups.append(index);
}
itemChanged(index);
Q_EMIT restoreCollapsedState();
@ -173,6 +177,7 @@ Scene::erase(Scene::Item_id index)
setSelectedItemsList(QList<Scene_interface::Item_id>()<<item_id(item));
return erase(selectionIndices());
}
m_groups.removeAll(index);
if(item->parentGroup()
&& item->parentGroup()->isChildLocked(item))
return -1;
@ -248,6 +253,7 @@ Scene::erase(QList<int> indices)
item->parentGroup()->removeChild(item);
children.removeAll(removed_item);
indexErased(removed_item);
m_groups.removeAll(removed_item);
m_entries.removeAll(item);
Q_EMIT itemAboutToBeDestroyed(item);
@ -1344,9 +1350,15 @@ QItemSelection Scene::createSelectionAll()
//it is not possible to directly create a selection with items that have different parents, so
//we do it iteratively.
QItemSelection sel;
for(int i=0; i< m_entries.size(); ++i)
sel.select(index_map.keys(i).at(0),
index_map.keys(i).at(4));
sel.select(this->createIndex(0, 0),
this->createIndex(m_entries.size(), LastColumn));
for(const auto& gid : m_groups)
{
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(item(gid));
sel.select(index_map.keys(group->getChildren().first()).at(0),
index_map.keys(group->getChildren().last()).at(4));
}
return sel;
}

View File

@ -64,6 +64,7 @@ public:
int numberOfEntries() const Q_DECL_OVERRIDE;
// returns the list of items.
const QList<CGAL::Three::Scene_item*>& entries() const { return m_entries; }
Q_INVOKABLE CGAL::Three::Scene_item* item(int) const Q_DECL_OVERRIDE;
int item_id(CGAL::Three::Scene_item*) const Q_DECL_OVERRIDE;
@ -280,6 +281,7 @@ private:
typedef QList<CGAL::Three::Scene_item*> Entries;
//List containing all the scene_items.
Entries m_entries;
QList<Item_id> m_groups; //used to optimize createSelectionAll()
QList<Item_id> children;
// Index of the currently selected item.
int selected_item;