Skip to content

Commit

Permalink
Store parent-ID in UNDO action when deleting view or dir
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed Mar 4, 2024
1 parent 33d7e8e commit 6b5ce6f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 3 additions & 1 deletion plugins/gui/include/gui/graph_widget/graph_context_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ namespace hal
GraphContext* getContextById(u32 id) const;


u32 getParentId(u32 childId, bool isDirctory) const;

ContextDirectory* getDirectoryById(u32 id) const;

/**
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 25 additions & 2 deletions plugins/gui/src/graph_widget/graph_context_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextTreeItem*>(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<ContextTreeItem*>(bti->getParent());
if (parentItem) return parentItem->getId();
return 0;
}

GraphContext* GraphContextManager::createNewContext(const QString& name, u32 parentId)
{
Expand Down Expand Up @@ -132,8 +151,12 @@ namespace hal

ContextDirectory *GraphContextManager::getDirectoryById(u32 id) const
{
ContextDirectory * directory = static_cast<ContextTreeItem *>(mContextTreeModel->getDirectory(id))->directory();
if (directory) return directory;
BaseTreeItem* bti = mContextTreeModel->getDirectory(id);
if (bti)
{
ContextDirectory* directory = static_cast<ContextTreeItem*>(bti)->directory();
if (directory) return directory;
}

return nullptr;
}
Expand Down
10 changes: 8 additions & 2 deletions plugins/gui/src/user_action/action_delete_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 6b5ce6f

Please sign in to comment.