Skip to content

Commit

Permalink
Fix auto expand issue when unloading a class.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 4, 2015
1 parent 74be569 commit 67f64ec
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1577,7 +1577,25 @@ bool LibraryTreeModel::unloadClass(LibraryTreeItem *pLibraryTreeItem, bool askQu
If deleteClass is successfull remove the class from Library Browser and delete the corresponding ModelWidget.
*/
if (mpLibraryWidget->getMainWindow()->getOMCProxy()->deleteClass(pLibraryTreeItem->getNameStructure())) {
/* QSortFilterProxy::filterAcceptRows changes the expand/collapse behavior of indexes or I am using it in some stupid way.
* If index is expanded and we delete it then the next sibling index automatically becomes expanded.
* The following code overcomes this issue. It stores the next index expand state and then apply it after deletion.
*/
int row = pLibraryTreeItem->row();
LibraryTreeItem *pNextLibraryTreeItem = 0;
bool expandState;
if (pLibraryTreeItem->parent()->getChildren().size() > row + 1) {
pNextLibraryTreeItem = pLibraryTreeItem->parent()->child(row + 1);
QModelIndex modelIndex = libraryTreeItemIndex(pNextLibraryTreeItem);
QModelIndex proxyIndex = mpLibraryWidget->getLibraryTreeProxyModel()->mapFromSource(modelIndex);
expandState = mpLibraryWidget->getLibraryTreeView()->isExpanded(proxyIndex);
}
unloadClassChildren(pLibraryTreeItem);
if (pNextLibraryTreeItem) {
QModelIndex modelIndex = libraryTreeItemIndex(pNextLibraryTreeItem);
QModelIndex proxyIndex = mpLibraryWidget->getLibraryTreeProxyModel()->mapFromSource(modelIndex);
mpLibraryWidget->getLibraryTreeView()->setExpanded(proxyIndex, expandState);
}
/* Update the model switcher toolbar button. */
mpLibraryWidget->getMainWindow()->updateModelSwitcherMenu(0);
return true;
Expand Down

0 comments on commit 67f64ec

Please sign in to comment.