Addition of a "lock" property in the groups API.

This commit is contained in:
Maxime Gimeno 2016-04-19 15:48:53 +02:00
parent e1eaa8307a
commit 0e66c54b27
4 changed files with 54 additions and 3 deletions

View File

@ -127,12 +127,14 @@ Scene::replaceItem(Scene::Item_id index, CGAL::Three::Scene_item* item, bool emi
Scene::Item_id
Scene::erase(Scene::Item_id index)
{
CGAL::Three::Scene_item* item = m_entries[index];
if(item->parentGroup()
&& item->parentGroup()->isChildLocked(item))
return -1;
clear();
index_map.clear();
if(index < 0 || index >= m_entries.size())
return -1;
CGAL::Three::Scene_item* item = m_entries[index];
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(item);
if(group)
@ -173,6 +175,9 @@ Scene::erase(QList<int> indices)
max_index = (std::max)(max_index, index);
CGAL::Three::Scene_item* item = m_entries[index];
if(item->parentGroup()
&& item->parentGroup()->isChildLocked(item))
continue;
if(!to_be_removed.contains(item))
to_be_removed.push_back(item);
}
@ -747,7 +752,9 @@ bool Scene::dropMimeData(const QMimeData * /*data*/,
Q_FOREACH(int i, selected_items_list)
{
if(!groups_children.contains(i))
{
items << item(i);
}
}
//Gets the group at the drop position
CGAL::Three::Scene_group_item* group =
@ -1108,7 +1115,11 @@ void Scene::changeGroup(Scene_item *item, CGAL::Three::Scene_group_item *target_
{
//remove item from the containing group if any
if(item->parentGroup())
item->parentGroup()->removeChild(item);
{
if(item->parentGroup()->isChildLocked(item))
return;
item->parentGroup()->removeChild(item);
}
//add the item to the target group
target_group->addChild(item);
item->moveToGroup(target_group);

View File

@ -1165,10 +1165,12 @@ void Scene_c3t3_item::show_spheres(bool b)
connect(spheres, SIGNAL(destroyed()), this, SLOT(reset_spheres()));
last_known_scene->addItem(spheres);
last_known_scene->changeGroup(spheres, this);
lockChild(spheres);
compute_spheres();
}
else if (!b && spheres!=NULL)
{
unlockChild(spheres);
last_known_scene->erase(last_known_scene->item_id(spheres));
}
Q_EMIT redraw();

View File

@ -213,3 +213,23 @@ void Scene_group_item::draw_splats(CGAL::Three::Viewer_interface* viewer) const
child->draw_splats(viewer);
}
}
void Scene_group_item::lockChild(Scene_item *child)
{
if(!children.contains(child))
return;
child->setProperty("lock", true);
}
void Scene_group_item::unlockChild(Scene_item *child)
{
if(!children.contains(child))
return;
child->setProperty("lock", false);
}
bool Scene_group_item::isChildLocked(Scene_item *child)
{
if(!children.contains(child)
|| (!child->property("lock").toBool()) )
return false;
return true;
}

View File

@ -46,6 +46,22 @@ public :
bool isFinite() const;
//!Returns true to avoid disturbing the BBox of the scene.
bool isEmpty() const ;
/*!
* \brief Locks a child
* A locked child cannot be moved out of the group nor can it be deleted.
*/
void lockChild(CGAL::Three::Scene_item*);
/*!
* \brief Unlocks a child
* @see lockChild()
*/
void unlockChild(CGAL::Three::Scene_item*);
/*!
* \brief Tells if a child is locked.
* \return true if the child is locked.
* @see lockChild()
*/
bool isChildLocked(CGAL::Three::Scene_item*);
//!Returns if the group_item is currently expanded or collapsed in the view.
//! True means expanded, false means collapsed.
//! @see setExpanded.
@ -122,6 +138,8 @@ public :
//!@see getChildren @see addChild
void removeChild( Scene_item* item)
{
if(isChildLocked(item))
return;
update_group_number(item,0);
children.removeOne(item);
}