Skip to content

Commit

Permalink
#223 Again again again. See what it broke ;)
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <benoit@destrat.io>
  • Loading branch information
cneben committed Feb 20, 2024
1 parent f6f6b6a commit dd2888f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/qanDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void DraggableCtrl::handleMouseReleaseEvent(QMouseEvent* event)

void DraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragSelection, bool notify)
{
qWarning() << "DraggableCtrl::beginDragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection << " notify=" << notify;

if (_targetItem == nullptr ||
_target == nullptr)
return;
Expand Down Expand Up @@ -198,9 +200,9 @@ void DraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragSelec
_initialTargetScenePos = rootItem->mapFromItem(_targetItem, QPointF{0,0});

// If there is a selection, keep start position for all selected nodes.
qWarning() << "graph->hasMultipleSelection(): " << graph->hasMultipleSelection();
if (dragSelection &&
graph->hasMultipleSelection()) {

auto beginDragMoveSelected = [this, &sceneDragPos] (auto primitive) { // Call beginDragMove() on a given node or group
if (primitive != nullptr &&
primitive->getItem() != nullptr &&
Expand All @@ -225,6 +227,7 @@ void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
// _graph must be configured (non nullptr)
// _graph must have a container item for coordinate mapping
// _target and _targetItem must be configured (true)
qWarning() << "DraggableCtrl::dragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection;

if (!_target ||
!_targetItem)
Expand Down Expand Up @@ -338,7 +341,7 @@ void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
if (primitive != nullptr &&
primitive->getItem() != nullptr &&
primitiveIsNotSelf) // Note: nodes inside a group or groups might be dragged too
primitive->getItem()->draggableCtrl().dragMove(sceneDragPos, false);
primitive->getItem()->draggableCtrl().dragMove(sceneDragPos, /*dragSelection=*/false);
};

std::for_each(graph->getSelectedNodes().begin(), graph->getSelectedNodes().end(), dragMoveSelected);
Expand Down
17 changes: 14 additions & 3 deletions src/qanEdgeDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ void EdgeDraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragS
Q_UNUSED(notify)
if (!_targetItem)
return;
// FIXME #223
/*if (_target->getIsProtected() || // Prevent dragging of protected or locked objects
_target->getLocked())
return;*/
qWarning() << "EdgeDraggableCtrl::beginDragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection << " notify=" << notify;

_targetItem->setDragged(true);
_initialDragPos = sceneDragPos;
Expand Down Expand Up @@ -157,6 +162,7 @@ void EdgeDraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragS
void EdgeDraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
bool disableSnapToGrid, bool disableOrientation)
{
qWarning() << "EdgeDraggableCtrl::dragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection;
Q_UNUSED(dragSelection)
Q_UNUSED(disableSnapToGrid)
Q_UNUSED(disableOrientation)
Expand Down Expand Up @@ -201,19 +207,24 @@ void EdgeDraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelect
const auto graph = getGraph();
if (graph == nullptr)
return;
qWarning() << "selected nodes=";
for (const auto& sn: graph->getSelectedNodes())
qWarning() << " " << sn;
qWarning() << "selected edges=";
for (const auto& se: graph->getSelectedEdges())
qWarning() << " " << se;
if (dragSelection) {
auto dragMoveSelected = [this, &sceneDragPos] (auto primitive) { // Call dragMove() on a given node or group
auto dragMoveSelected = [this, &sceneDragPos] (auto primitive) { // Call dragMove() on a given node, group or edge
const auto primitiveIsNotSelf = static_cast<QQuickItem*>(primitive->getItem()) !=
static_cast<QQuickItem*>(this->_targetItem.data());
if (primitive != nullptr &&
primitive->getItem() != nullptr &&
primitiveIsNotSelf) // Note: nodes inside a group or groups might be dragged too
primitive->getItem()->draggableCtrl().dragMove(sceneDragPos, false);
primitive->getItem()->draggableCtrl().dragMove(sceneDragPos, /*dragSelection=*/false);
};
std::for_each(graph->getSelectedNodes().begin(), graph->getSelectedNodes().end(), dragMoveSelected);
std::for_each(graph->getSelectedEdges().begin(), graph->getSelectedEdges().end(), dragMoveSelected);
std::for_each(graph->getSelectedGroups().begin(), graph->getSelectedGroups().end(), dragMoveSelected);
//std::for_each(graph->getSelectedEdges().begin(), graph->getSelectedEdges().end(), dragMoveSelected);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/qanGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,9 +1438,13 @@ bool Graph::hasMultipleSelection() const
{
// Note 20231104: There is still no support for multiple edge selection,
// but an heterogeneous selection of nodes and groups is a multiple selection
return (_selectedNodes.size() +
// FIXME #223 again
/*return (_selectedNodes.size() +
_selectedGroups.size()) > 1 ||
_selectedEdges.size() > 1;
_selectedEdges.size() > 1;*/
return (_selectedNodes.size() +
_selectedGroups.size() +
_selectedEdges.size()) > 1;
}

std::vector<QQuickItem*> Graph::getSelectedItems() const
Expand Down

0 comments on commit dd2888f

Please sign in to comment.