collapsing problems fix + clean-up

This commit is contained in:
Maxime Gimeno 2015-11-16 11:20:02 +01:00
parent 836e9c5d65
commit f1c3a3f51d
4 changed files with 8 additions and 18 deletions

View File

@ -1077,7 +1077,6 @@ void MainWindow::selectSceneItem(int i)
sceneView->selectionModel()->select(s, sceneView->selectionModel()->select(s,
QItemSelectionModel::ClearAndSelect); QItemSelectionModel::ClearAndSelect);
} }
restoreCollapseState();
} }

View File

@ -95,7 +95,7 @@ public :
if(selected_group->getChildren().contains(item)) if(selected_group->getChildren().contains(item))
{ {
//selected_group->removeChild(item); //selected_group->removeChild(item);
trueScene->check_empty_group(item); trueScene->remove_item_from_groups(item);
item->has_group = 0; item->has_group = 0;
} }

View File

@ -59,7 +59,6 @@ Scene::addItem(Scene_item* item)
this, SLOT(callDraw())); this, SLOT(callDraw()));
if(bbox_before + item->bbox() != bbox_before) if(bbox_before + item->bbox() != bbox_before)
{ Q_EMIT updated_bbox(); } { Q_EMIT updated_bbox(); }
QStandardItemModel::beginResetModel();
QList<QStandardItem*> list; QList<QStandardItem*> list;
for(int i=0; i<5; i++) for(int i=0; i<5; i++)
{ {
@ -70,9 +69,8 @@ Scene::addItem(Scene_item* item)
for(int i=0; i<5; i++){ for(int i=0; i<5; i++){
index_map[list.at(i)->index()] = m_entries.size() -1; index_map[list.at(i)->index()] = m_entries.size() -1;
} }
Q_EMIT restoreCollapsedState();
Q_EMIT updated(); Q_EMIT updated();
QStandardItemModel::endResetModel(); Q_EMIT restoreCollapsedState();
Item_id id = m_entries.size() - 1; Item_id id = m_entries.size() - 1;
Q_EMIT newItem(id); Q_EMIT newItem(id);
return id; return id;
@ -130,6 +128,7 @@ Scene::erase(int index)
QStandardItemModel::beginResetModel(); QStandardItemModel::beginResetModel();
Q_EMIT updated(); Q_EMIT updated();
QStandardItemModel::endResetModel(); QStandardItemModel::endResetModel();
Q_EMIT restoreCollapsedState();
if(--index >= 0) if(--index >= 0)
return index; return index;
if(!m_entries.isEmpty()) if(!m_entries.isEmpty())
@ -178,6 +177,7 @@ Scene::erase(QList<int> indices)
QStandardItemModel::beginResetModel(); QStandardItemModel::beginResetModel();
Q_EMIT updated(); Q_EMIT updated();
QStandardItemModel::endResetModel(); QStandardItemModel::endResetModel();
Q_EMIT restoreCollapsedState();
int index = max_index + 1 - indices.size(); int index = max_index + 1 - indices.size();
if(index >= m_entries.size()) { if(index >= m_entries.size()) {
@ -191,19 +191,13 @@ Scene::erase(QList<int> indices)
} }
void Scene::check_empty_group(Scene_item* item) void Scene::remove_item_from_groups(Scene_item* item)
{ {
Q_FOREACH(Scene_group_item* group, m_group_entries) Q_FOREACH(Scene_group_item* group, m_group_entries)
{ {
if(group->getChildren().contains(item)) if(group->getChildren().contains(item))
{ {
group->removeChild(item); group->removeChild(item);
if (group->getChildren().isEmpty())
{
check_empty_group(group);
m_group_entries.removeOne(group);
m_entries.removeOne(group);
}
} }
} }
check_first_group(); check_first_group();
@ -496,7 +490,7 @@ Scene::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
int id = index_map[index];\ int id = index_map[index];
if(id < 0 || id >= m_entries.size()) if(id < 0 || id >= m_entries.size())
return QVariant(); return QVariant();
if(role == ::Qt::ToolTipRole) if(role == ::Qt::ToolTipRole)
@ -972,8 +966,6 @@ QList<Scene_item*> Scene::item_entries() const
void Scene::check_first_group() void Scene::check_first_group()
{ {
if(m_group_entries.isEmpty() || m_group_entries.first()->name() != "new group") if(m_group_entries.isEmpty() || m_group_entries.first()->name() != "new group")
{ {
m_group_entries.prepend(new Scene_group_item("new group")); m_group_entries.prepend(new Scene_group_item("new group"));
@ -1009,8 +1001,7 @@ void Scene::changeGroup(Scene_item *item, Scene_group_item *target_group)
{ {
if(group->getChildren().contains(item)) if(group->getChildren().contains(item))
{ {
//group->removeChild(item); remove_item_from_groups(item);
check_empty_group(item);
break; break;
} }
} }

View File

@ -118,7 +118,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
//!insures that the groupview and data always has a "new group" in first position. //!insures that the groupview and data always has a "new group" in first position.
void check_first_group(); void check_first_group();
void check_empty_group(Scene_item* item); void remove_item_from_groups(Scene_item* item);
void group_added(); void group_added();
// Notify the scene that an item was modified // Notify the scene that an item was modified
void itemChanged(); // slots called by items themself void itemChanged(); // slots called by items themself