| 170 | } |
| 171 | |
| 172 | void EdgeDraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection, |
| 173 | bool disableSnapToGrid, bool disableOrientation) |
| 174 | { |
| 175 | //qWarning() << "EdgeDraggableCtrl::dragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection; |
| 176 | Q_UNUSED(dragSelection) |
| 177 | Q_UNUSED(disableSnapToGrid) |
| 178 | Q_UNUSED(disableOrientation) |
| 179 | // PRECONDITIONS: |
| 180 | // _targetItem must be configured |
| 181 | if (!_targetItem) |
| 182 | return; |
| 183 | if (_targetItem->getSourceItem() == nullptr || |
| 184 | _targetItem->getDestinationItem() == nullptr) |
| 185 | return; |
| 186 | |
| 187 | // Get target edge adjacent nodes |
| 188 | qan::Node* src = _targetItem->getSourceItem()->getNode(); |
| 189 | qan::Node* dst = _targetItem->getDestinationItem()->getNode(); |
| 190 | auto srcItem = src != nullptr ? src->getItem() : nullptr; |
| 191 | auto dstItem = dst != nullptr ? dst->getItem() : nullptr; |
| 192 | if (srcItem == nullptr || |
| 193 | dstItem == nullptr) |
| 194 | return; |
| 195 | |
| 196 | // Polish snapToGrid: |
| 197 | // When edge src|dst is not vertically or horizontally aligned: disable hook. |
| 198 | // If they are vertically/horizontally aligned: allow move snapToGrid it won't generate jiterring. |
| 199 | const auto disableHooksSnapToGrid = srcItem->getDragOrientation() == qan::NodeItem::DragOrientation::DragAll || |
| 200 | srcItem->getDragOrientation() == qan::NodeItem::DragOrientation::DragAll || |
| 201 | (srcItem->getDragOrientation() != dstItem->getDragOrientation()); |
| 202 | const auto disableHooksDragOrientation = (srcItem->getDragOrientation() == qan::NodeItem::DragOrientation::DragHorizontal || |
| 203 | srcItem->getDragOrientation() == qan::NodeItem::DragOrientation::DragVertical) && |
| 204 | (srcItem->getDragOrientation() == dstItem->getDragOrientation()); |
| 205 | if (srcItem != nullptr) |
| 206 | srcItem->draggableCtrl().dragMove(sceneDragPos, |
| 207 | /*dragSelection=*/false, |
| 208 | /*disableSnapToGrid=*/disableHooksSnapToGrid, |
| 209 | disableHooksDragOrientation); |
| 210 | if (dstItem != nullptr) |
| 211 | dstItem->draggableCtrl().dragMove(sceneDragPos, |
| 212 | /*dragSelection=*/false, |
| 213 | /*disableSnapToGrid=*/disableHooksSnapToGrid, |
| 214 | disableHooksDragOrientation); |
| 215 | |
| 216 | // If there is a selection, keep start position for all selected nodes. |
| 217 | const auto graph = getGraph(); |
| 218 | if (graph == nullptr) |
| 219 | return; |
| 220 | if (dragSelection) { |
| 221 | auto dragMoveSelected = [this, &sceneDragPos] (auto primitive) { // Call dragMove() on a given node, group or edge |
| 222 | const auto primitiveIsNotSelf = static_cast<QQuickItem*>(primitive->getItem()) != |
| 223 | static_cast<QQuickItem*>(this->_targetItem.data()); |
| 224 | if (primitive != nullptr && |
| 225 | primitive->getItem() != nullptr && |
| 226 | primitiveIsNotSelf) // Note: nodes inside a group or groups might be dragged too |
| 227 | primitive->getItem()->draggableCtrl().dragMove(sceneDragPos, /*dragSelection=*/false); |
| 228 | }; |
| 229 | std::for_each(graph->getSelectedNodes().begin(), graph->getSelectedNodes().end(), dragMoveSelected); |
nothing calls this directly
no test coverage detected