Skip to content

Commit

Permalink
Additional debug info to trace drop row
Browse files Browse the repository at this point in the history
  • Loading branch information
joern274 committed May 5, 2024
1 parent e05b5c5 commit ef0c66c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ namespace hal
void handleRenameClicked();
void handleDuplicateContextClicked();
void handleDeleteClicked();
void handleMoveToplevelClicked();

void handleContextMenuRequest(const QPoint& point);
void handleSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
Expand Down Expand Up @@ -245,10 +244,6 @@ namespace hal
QString mOpenIconPath;
QString mOpenIconStyle;

QAction* mMoveToplevelAction;
QString mMoveToplevelPath;
QString mMoveToplevelStyle;

QString mSearchIconPath;
QString mSearchIconStyle;
QString mSearchActiveIconStyle;
Expand Down
3 changes: 2 additions & 1 deletion plugins/gui/include/gui/user_action/action_move_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace hal
{
u32 mSourceParentId;
u32 mTargetParentId;
int mTargetRow;

public:
/**
Expand All @@ -51,7 +52,7 @@ namespace hal
* Will move the tree item to new parent,
* action object must indicate tree item
*/
ActionMoveItem(u32 tgtId = 0, u32 srcId = 0);
ActionMoveItem(u32 tgtId = 0, u32 srcId = 0, int tgtRow = -1);

bool exec() override;
QString tagname() const override;
Expand Down
3 changes: 2 additions & 1 deletion plugins/gui/src/basic_tree_model/base_tree_item.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "gui/basic_tree_model/base_tree_item.h"

#include <iostream>

namespace hal
{
Expand Down Expand Up @@ -45,6 +45,7 @@ namespace hal
void BaseTreeItem::insertChild(int index, BaseTreeItem *child)
{
child->setParent(this);
std::cerr << "...chld " << index << std::endl;
mChildren.insert(index, child);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/gui/src/basic_tree_model/base_tree_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace hal
if (row < 0) row = parentItem->getChildCount();
QModelIndex index = getIndexFromItem(parentItem);
beginInsertRows(index, row, row);
parentItem->appendChild(childItem);
parentItem->insertChild(row,childItem);
endInsertRows();
}

Expand Down
36 changes: 2 additions & 34 deletions plugins/gui/src/context_manager_widget/context_manager_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace hal
{
ContextManagerWidget::ContextManagerWidget(GraphTabWidget* tab_view, QWidget* parent)
: ContentWidget("Views", parent), mSearchbar(new Searchbar(this)), mNewDirectoryAction(new QAction(this)), mNewViewAction(new QAction(this)), mRenameAction(new QAction(this)), mDuplicateAction(new QAction(this)),
mDeleteAction(new QAction(this)), mOpenAction(new QAction(this)), mMoveToplevelAction(new QAction(this))
mDeleteAction(new QAction(this)), mOpenAction(new QAction(this))
{
//needed to load the properties
ensurePolished();
Expand All @@ -52,7 +52,6 @@ namespace hal
mRenameAction->setIcon(gui_utility::getStyledSvgIcon(mRenameIconStyle, mRenameIconPath));
mDuplicateAction->setIcon(gui_utility::getStyledSvgIcon(mDuplicateIconStyle, mDuplicateIconPath));
mDeleteAction->setIcon(gui_utility::getStyledSvgIcon(mDeleteIconStyle, mDeleteIconPath));
mMoveToplevelAction->setIcon(gui_utility::getStyledSvgIcon(mMoveToplevelStyle, mMoveToplevelPath));
mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mSearchIconStyle, mSearchIconPath));

mOpenAction->setToolTip("Open");
Expand All @@ -61,7 +60,6 @@ namespace hal
mRenameAction->setToolTip("Rename");
mDuplicateAction->setToolTip("Duplicate");
mDeleteAction->setToolTip("Delete");
mMoveToplevelAction->setToolTip("to toplevel");
mSearchAction->setToolTip("Search");

mOpenAction->setText("Open view");
Expand All @@ -70,7 +68,6 @@ namespace hal
mRenameAction->setText("Rename item");
mDuplicateAction->setText("Duplicate view");
mDeleteAction->setText("Delete item");
mMoveToplevelAction->setText("Move to toplevel");
mSearchAction->setText("Search");

//mOpenAction->setEnabled(false);
Expand Down Expand Up @@ -110,7 +107,6 @@ namespace hal
connect(mRenameAction, &QAction::triggered, this, &ContextManagerWidget::handleRenameClicked);
connect(mDuplicateAction, &QAction::triggered, this, &ContextManagerWidget::handleDuplicateContextClicked);
connect(mDeleteAction, &QAction::triggered, this, &ContextManagerWidget::handleDeleteClicked);
connect(mMoveToplevelAction, &QAction::triggered, this, &ContextManagerWidget::handleMoveToplevelClicked);
connect(mSearchAction, &QAction::triggered, this, &ContextManagerWidget::toggleSearchbar);

connect(mContextTreeView, &QTreeView::customContextMenuRequested, this, &ContextManagerWidget::handleContextMenuRequest);
Expand Down Expand Up @@ -175,30 +171,6 @@ namespace hal
mTabView->showContext(defaultContext);
}

void ContextManagerWidget::handleMoveToplevelClicked()
{
ContextTreeItem* clicked_item = getCurrentItem();
if (!clicked_item) return;

UserActionObject uao;
if (clicked_item->isContext())
uao = UserActionObject(clicked_item->context()->id(), UserActionObjectType::ContextView);
else if (clicked_item->isDirectory())
uao = UserActionObject(clicked_item->directory()->id(), UserActionObjectType::ContextDir);
else
return;

BaseTreeItem* bti = clicked_item->getParent();
while (bti->getParent())
bti = bti->getParent();

ActionMoveItem* act = new ActionMoveItem(0);
act->setObject(uao);
act->exec();

mContextTreeModel->moveItem(clicked_item,bti);
}

void ContextManagerWidget::handleItemDoubleClicked(const QModelIndex &proxyIndex)
{
QModelIndex sourceIndex = mContextTreeProxyModel->mapToSource(proxyIndex);
Expand Down Expand Up @@ -371,10 +343,6 @@ namespace hal
context_menu.addAction(mRenameAction);
}

// unless parent is rootItem thus not a ContextTreeItem
if (dynamic_cast<ContextTreeItem*>(item->getParent()))
context_menu.addAction(mMoveToplevelAction);

context_menu.exec(mContextTreeView->viewport()->mapToGlobal(point));
}

Expand Down Expand Up @@ -659,6 +627,7 @@ namespace hal

void ContextManagerWidget::handleFocusChanged(QWidget* oldWidget, QWidget* newWidget)
{
Q_UNUSED(oldWidget);
if(!newWidget) return;
if(newWidget->parent() == this)
{
Expand All @@ -671,5 +640,4 @@ namespace hal
return;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace hal
{
case 0:
return mDirectory->name();
case 1:
return mDirectory->id();
default:
return "";
}
Expand Down Expand Up @@ -230,10 +232,30 @@ namespace hal
Q_UNUSED(column)
Q_UNUSED(action)
Q_UNUSED(row)

std::cerr << " test " << row << (parent.isValid() ? " valid" : " root") << std::endl;

if (!parent.isValid())
return true; // can always drop on root

int moveRow = -1;
quintptr moveParent = 0;
if(!mimeData->formats().contains("contexttreemodel/item")) return false;

/*
{
if (parent.isValid())
{
ContextTreeItem* cti = dynamic_cast<ContextTreeItem*>(getItemFromIndex(parent));
if (cti)
qDebug() << "drop on " << (cti->isDirectory() ? "directory" : "view") << cti->getId() << row << column;
else
qDebug() << "drop on root " << row << column;
}
else
qDebug() << "drop no parent " << row << column;
}
*/
BaseTreeItem* targetParentItem = getItemFromIndex(parent);
if (targetParentItem == mRootItem) return true;
ContextTreeItem* parentItem = dynamic_cast<ContextTreeItem*>(getItemFromIndex(parent));
Expand Down Expand Up @@ -264,43 +286,50 @@ namespace hal
int sourceRow = -1;
quintptr sourceParent = 0;

std::cerr << "***drop " << row << (parent.isValid() ? " valid" : " root") << std::endl;
auto encItem = mimeData->data("contexttreemodel/item");
QDataStream dataStream(&encItem, QIODevice::ReadOnly);
dataStream >> type >> id >> sourceRow >> sourceParent;

BaseTreeItem* targetParentItem = getItemFromIndex(parent);
ContextTreeItem* sourceParentItem = dynamic_cast<ContextTreeItem*>((BaseTreeItem*) sourceParent);

u32 targetId = 0;
ContextTreeItem* cti = dynamic_cast<ContextTreeItem*>(targetParentItem);
if (cti) targetId = cti->getId();

UserActionObject uao;

QModelIndex moveInx = index(sourceRow, 0, getIndexFromItem((BaseTreeItem*) sourceParent));
ContextTreeItem* itemToMove = dynamic_cast<ContextTreeItem*>(getItemFromIndex(moveInx));
UserActionObject uao;
if (itemToMove->isContext())
uao = UserActionObject(itemToMove->context()->id(), UserActionObjectType::ContextView);
else if (itemToMove->isDirectory())
uao = UserActionObject(itemToMove->directory()->id(), UserActionObjectType::ContextDir);
else
return false;

ActionMoveItem* act = new ActionMoveItem(targetId, sourceParentItem ? sourceParentItem->getId() : 0);
u32 targetId = 0;

if (parent.isValid())
{
BaseTreeItem* targetParentItem = getItemFromIndex(parent);
ContextTreeItem* cti = dynamic_cast<ContextTreeItem*>(targetParentItem);
if (cti)
{
if (!cti->isDirectory()) return false;
targetId = cti->directory()->id();
}

}

ActionMoveItem* act = new ActionMoveItem(targetId, sourceParentItem ? sourceParentItem->getId() : 0, row);
act->setObject(uao);
act->exec();
return true;
}


BaseTreeItem* ContextTreeModel::getDirectory(u32 directoryId) const
{
return getItemInternal(mRootItem, directoryId, true);
}

BaseTreeItem* ContextTreeModel::getContext(u32 contextId) const
{
return getItemInternal(mRootItem, contextId, true);
return getItemInternal(mRootItem, contextId, false);
}

BaseTreeItem* ContextTreeModel::getItemInternal(BaseTreeItem *parentItem, u32 id, bool isDirectory) const
Expand Down Expand Up @@ -511,6 +540,7 @@ namespace hal

bool ContextTreeModel::moveItem(ContextTreeItem* itemToMove, BaseTreeItem *newParent, int row)
{
std::cerr << "...move " << row << std::endl;
if (!itemToMove || !newParent ) return false;
if (newParent != mRootItem)
{
Expand Down
12 changes: 9 additions & 3 deletions plugins/gui/src/user_action/action_move_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace hal
return new ActionMoveItem;
}

ActionMoveItem::ActionMoveItem(u32 tgtId, u32 srcId)
: mSourceParentId(srcId), mTargetParentId(tgtId)
ActionMoveItem::ActionMoveItem(u32 tgtId, u32 srcId, int tgtRow)
: mSourceParentId(srcId), mTargetParentId(tgtId), mTargetRow(tgtRow)
{;}

QString ActionMoveItem::tagname() const
Expand Down Expand Up @@ -54,16 +54,19 @@ namespace hal

bool ActionMoveItem::exec()
{
if (!mTargetParentId || !mObject.id()) return false;
if (!mObject.id()) return false;

std::cerr << " actx " << mTargetRow << std::endl;
BaseTreeItem* bti = nullptr;
bool isDirectory = false;

switch (mObject.type()) {
case UserActionObjectType::ContextView:
bti = gGraphContextManager->getContextTreeModel()->getContext(mObject.id());
break;
case UserActionObjectType::ContextDir:
bti = gGraphContextManager->getContextTreeModel()->getDirectory(mObject.id());
isDirectory = true;
break;
default:
break;
Expand All @@ -77,6 +80,9 @@ namespace hal
}

mUndoAction = new ActionMoveItem(mSourceParentId, mTargetParentId);
mUndoAction->setObject(mObject);

gGraphContextManager->moveItem(mObject.id(), isDirectory, mTargetParentId, mTargetRow);

return UserAction::exec();
}
Expand Down

0 comments on commit ef0c66c

Please sign in to comment.