From 6b5ce6f75a1df4deeefc839ca3faf5857b78327c Mon Sep 17 00:00:00 2001 From: joern274 Date: Mon, 4 Mar 2024 20:30:02 +0100 Subject: [PATCH] Store parent-ID in UNDO action when deleting view or dir --- .../gui/graph_widget/graph_context_manager.h | 4 ++- .../context_manager_widget.cpp | 4 +++ .../graph_widget/graph_context_manager.cpp | 27 +++++++++++++++++-- .../src/user_action/action_delete_object.cpp | 10 +++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/plugins/gui/include/gui/graph_widget/graph_context_manager.h b/plugins/gui/include/gui/graph_widget/graph_context_manager.h index db15c5aa147..36582f917d0 100644 --- a/plugins/gui/include/gui/graph_widget/graph_context_manager.h +++ b/plugins/gui/include/gui/graph_widget/graph_context_manager.h @@ -122,6 +122,8 @@ namespace hal GraphContext* getContextById(u32 id) const; + u32 getParentId(u32 childId, bool isDirctory) const; + ContextDirectory* getDirectoryById(u32 id) const; /** @@ -362,7 +364,7 @@ namespace hal GraphShader* getDefaultShader(GraphContext* const context) const; /** - * Gets the table model for the contexts. + * Gets the tree model for the contexts. * * @returns the context table model */ diff --git a/plugins/gui/src/context_manager_widget/context_manager_widget.cpp b/plugins/gui/src/context_manager_widget/context_manager_widget.cpp index fd17ef992ee..9668324bc72 100644 --- a/plugins/gui/src/context_manager_widget/context_manager_widget.cpp +++ b/plugins/gui/src/context_manager_widget/context_manager_widget.cpp @@ -291,6 +291,10 @@ namespace hal { const QModelIndex clicked_index = mContextTreeView->indexAt(point); + // TODO change current directory : + // if clicked index is view : parent dir of view + // if clicked index is dir : this dir + QMenu context_menu; context_menu.addAction(mNewViewAction); diff --git a/plugins/gui/src/graph_widget/graph_context_manager.cpp b/plugins/gui/src/graph_widget/graph_context_manager.cpp index d0e22373d22..faa1ccbc928 100644 --- a/plugins/gui/src/graph_widget/graph_context_manager.cpp +++ b/plugins/gui/src/graph_widget/graph_context_manager.cpp @@ -55,6 +55,25 @@ namespace hal return contextDir; } + u32 GraphContextManager::getParentId(u32 childId, bool isDirctory) const + { + if (isDirctory) + { + BaseTreeItem* bti = mContextTreeModel->getDirectory(childId); + ContextTreeItem* parentItem = dynamic_cast(bti->getParent()); + if (parentItem) return parentItem->getId(); + return 0; + } + GraphContext* context = getContextById(childId); + if (!context) return 0; + QModelIndex inx = mContextTreeModel->getIndexFromContext(context); + if (!inx.isValid()) return 0; + BaseTreeItem* bti =mContextTreeModel->getItemFromIndex(inx); + if (!bti) return 0; + ContextTreeItem* parentItem = dynamic_cast(bti->getParent()); + if (parentItem) return parentItem->getId(); + return 0; + } GraphContext* GraphContextManager::createNewContext(const QString& name, u32 parentId) { @@ -132,8 +151,12 @@ namespace hal ContextDirectory *GraphContextManager::getDirectoryById(u32 id) const { - ContextDirectory * directory = static_cast(mContextTreeModel->getDirectory(id))->directory(); - if (directory) return directory; + BaseTreeItem* bti = mContextTreeModel->getDirectory(id); + if (bti) + { + ContextDirectory* directory = static_cast(bti)->directory(); + if (directory) return directory; + } return nullptr; } diff --git a/plugins/gui/src/user_action/action_delete_object.cpp b/plugins/gui/src/user_action/action_delete_object.cpp index cd88a0e5f95..7d5754f7c8c 100644 --- a/plugins/gui/src/user_action/action_delete_object.cpp +++ b/plugins/gui/src/user_action/action_delete_object.cpp @@ -144,7 +144,10 @@ namespace hal { UserActionCompound* act = new UserActionCompound; act->setUseCreatedObject(); - act->addAction(new ActionCreateObject(UserActionObjectType::ContextView, ctx->name())); + ActionCreateObject* actCreate = new ActionCreateObject(UserActionObjectType::ContextView, ctx->name()); + actCreate->setObject(UserActionObject(ctx->id(),UserActionObjectType::ContextView)); + actCreate->setParentId(gGraphContextManager->getParentId(ctx->id(),false)); + act->addAction(actCreate); act->addAction(new ActionAddItemsToObject(ctx->modules(), ctx->gates())); act->setParentObject(mParentObject); @@ -163,7 +166,10 @@ namespace hal } else { UserActionCompound* act = new UserActionCompound; act->setUseCreatedObject(); - act->addAction(new ActionCreateObject(UserActionObjectType::ContextDir, ctxDir->name())); + ActionCreateObject* actCreate = new ActionCreateObject(UserActionObjectType::ContextDir, ctxDir->name()); + actCreate->setObject(UserActionObject(ctxDir->id(),UserActionObjectType::ContextDir)); + actCreate->setParentId(gGraphContextManager->getParentId(ctxDir->id(),true)); + act->addAction(actCreate); act->addAction(new ActionAddItemsToObject({gNetlist->get_top_module()->get_id()}, {})); act->setParentObject(mParentObject);