Skip to content

Commit

Permalink
#223 Fix horizontal / vertical edge selection.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Feb 20, 2024
1 parent ae6ea81 commit f6f6b6a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/qanGraphView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//-----------------------------------------------------------------------------

// Qt headers
#include <QtNumeric>
#include <QQuickItem>

// QuickQanava headers
Expand Down Expand Up @@ -146,8 +147,12 @@ void GraphView::selectionRectActivated(const QRectF& rect)
auto edgeItem = qobject_cast<qan::EdgeItem*>(item);
if (edgeItem != nullptr &&
edgeItem->getEdge() != nullptr) {
const auto itemBr = item->mapRectToItem(_graph->getContainerItem(),
auto itemBr = item->mapRectToItem(_graph->getContainerItem(),
item->boundingRect());
if (qFuzzyIsNull(itemBr.height())) // Note: rect.contains does not work with 0 width/height
itemBr.setHeight(0.5); // br, set minimum width/height to 0.5, to allow vertical /
if (qFuzzyIsNull(itemBr.width())) // horizontal line selection for example.
itemBr.setWidth(0.5);
if (!rect.contains(itemBr)) {
_graph->setEdgeSelected(edgeItem->getEdge(), false);
_selectedItems.remove(item);
Expand Down Expand Up @@ -177,11 +182,14 @@ void GraphView::selectionRectActivated(const QRectF& rect)
auto edgeItem = qobject_cast<qan::EdgeItem*>(item);
if (edgeItem != nullptr &&
edgeItem->getEdge() != nullptr) {
const auto itemBr = item->mapRectToItem(_graph->getContainerItem(),
item->boundingRect());
auto itemBr = item->mapRectToItem(_graph->getContainerItem(),
item->boundingRect());
if (qFuzzyIsNull(itemBr.height())) // Note: rect.contains does not work with 0 width/height
itemBr.setHeight(0.5); // br, set minimum width/height to 0.5, to allow vertical /
if (qFuzzyIsNull(itemBr.width())) // horizontal line selection for example.
itemBr.setWidth(0.5);
if (rect.contains(itemBr)) {
auto edge = edgeItem->getEdge();

_graph->setEdgeSelected(edge, true);
_selectedItems.insert(edgeItem);
}
Expand Down

0 comments on commit f6f6b6a

Please sign in to comment.