Skip to content

Commit

Permalink
#185 Fix multiple selection problems. +cosmetic.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Dec 25, 2022
1 parent 1816199 commit 381eaeb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
13 changes: 8 additions & 5 deletions src/qanDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ bool DraggableCtrl::handleMouseMoveEvent(QMouseEvent* event)
const auto sceneDragPos = rootItem->mapFromGlobal(event->globalPos());
if (!_targetItem->getDragged()) {
// Project in scene rect (for example is a node is part of a group)
const auto sceneTargetPos = rootItem->mapFromItem(_targetItem, QPointF{0,0});
_initialTargetPos = sceneTargetPos;
//const auto sceneTargetPos = rootItem->mapFromItem(_targetItem, QPointF{0,0});
//_initialTargetPos = sceneTargetPos;
beginDragMove(sceneDragPos, _targetItem->getSelected());
return true;
} else {
Expand Down Expand Up @@ -165,6 +165,9 @@ void DraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragSelec
emit graph->nodeAboutToBeMoved(_target);
_targetItem->setDragged(true);
_initialDragPos = sceneDragPos;
const auto rootItem = getGraph()->getContainerItem();
if (rootItem != nullptr) // Project in scene rect (for example is a node is part of a group)
_initialTargetPos = rootItem->mapFromItem(_targetItem, QPointF{0,0});

// If there is a selection, keep start position for all selected nodes.
if (dragSelection) {
Expand Down Expand Up @@ -267,9 +270,9 @@ void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection)
auto dragMoveSelected = [this, &sceneDragPos] (auto primitive) { // Call dragMove() on a given node or group
const auto primitiveIsNotSelf = static_cast<QQuickItem*>(primitive->getItem()) !=
static_cast<QQuickItem*>(this->_targetItem.data());
if ( primitive != nullptr &&
primitive->getItem() != nullptr &&
primitiveIsNotSelf) // Note: Contrary to beginDragMove(), drag nodes that are inside a group
if (primitive != nullptr &&
primitive->getItem() != nullptr &&
primitiveIsNotSelf) // Note: Contrary to beginDragMove(), drag nodes that are inside a group
primitive->getItem()->draggableCtrl().dragMove(sceneDragPos, false);
};

Expand Down
44 changes: 22 additions & 22 deletions src/qanGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,33 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>

public:
//! Alias to VisualConnector::edgeColor property (default to Black).
Q_PROPERTY( QColor connectorEdgeColor READ getConnectorEdgeColor WRITE setConnectorEdgeColor NOTIFY connectorEdgeColorChanged FINAL )
inline QColor getConnectorEdgeColor() const noexcept { return _connectorEdgeColor; }
void setConnectorEdgeColor( QColor connectorEdgeColor ) noexcept;
Q_PROPERTY(QColor connectorEdgeColor READ getConnectorEdgeColor WRITE setConnectorEdgeColor NOTIFY connectorEdgeColorChanged FINAL)
QColor getConnectorEdgeColor() const noexcept { return _connectorEdgeColor; }
void setConnectorEdgeColor(QColor connectorEdgeColor) noexcept;
signals:
void connectorEdgeColorChanged();
void connectorEdgeColorChanged();
private:
QColor _connectorEdgeColor{Qt::black};
QColor _connectorEdgeColor{Qt::black};

public:
//! Alias to VisualConnector::connectorColor property (default to DodgerBlue).
Q_PROPERTY( QColor connectorColor READ getConnectorColor WRITE setConnectorColor NOTIFY connectorColorChanged FINAL )
Q_PROPERTY(QColor connectorColor READ getConnectorColor WRITE setConnectorColor NOTIFY connectorColorChanged FINAL)
inline QColor getConnectorColor() const noexcept { return _connectorColor; }
void setConnectorColor( QColor connectorColor ) noexcept;
void setConnectorColor(QColor connectorColor) noexcept;
signals:
void connectorColorChanged();
private:
QColor _connectorColor{30, 144, 255}; // dodgerblue=rgb(30, 144, 255)

public:
//! Alias to VisualConnector::createDefaultEdge (default to true).
Q_PROPERTY( bool connectorCreateDefaultEdge READ getConnectorCreateDefaultEdge WRITE setConnectorCreateDefaultEdge NOTIFY connectorCreateDefaultEdgeChanged FINAL )
Q_PROPERTY(bool connectorCreateDefaultEdge READ getConnectorCreateDefaultEdge WRITE setConnectorCreateDefaultEdge NOTIFY connectorCreateDefaultEdgeChanged FINAL)
inline bool getConnectorCreateDefaultEdge() const noexcept { return _connectorCreateDefaultEdge; }
void setConnectorCreateDefaultEdge( bool connectorCreateDefaultEdge ) noexcept;
void setConnectorCreateDefaultEdge(bool connectorCreateDefaultEdge) noexcept;
signals:
void connectorCreateDefaultEdgeChanged();
private:
bool _connectorCreateDefaultEdge{true};
bool _connectorCreateDefaultEdge = true;

public:
//! Alias to qan::Connector::connectorItem property (default to nullptr, ie default connector item).
Expand All @@ -204,13 +204,13 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>

public:
//! Enable or disable visual connector of nodes in the graph (default to false).
Q_PROPERTY( bool connectorEnabled READ getConnectorEnabled WRITE setConnectorEnabled NOTIFY connectorEnabledChanged FINAL )
Q_PROPERTY(bool connectorEnabled READ getConnectorEnabled WRITE setConnectorEnabled NOTIFY connectorEnabledChanged FINAL)
inline bool getConnectorEnabled() const noexcept { return _connectorEnabled; }
void setConnectorEnabled( bool connectorEnabled ) noexcept;
void setConnectorEnabled(bool connectorEnabled) noexcept;
signals:
void connectorEnabledChanged();
private:
bool _connectorEnabled{false};
bool _connectorEnabled = false;

public:
//! Control node used as a connector when \c connectorEnabled is set to true (might be nullptr).
Expand All @@ -227,7 +227,7 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>
//@{
public:
//! Default delegate for qan::Node and Qan.Node nodes.
Q_PROPERTY( QQmlComponent* nodeDelegate READ getNodeDelegate WRITE setNodeDelegate NOTIFY nodeDelegateChanged FINAL )
Q_PROPERTY(QQmlComponent* nodeDelegate READ getNodeDelegate WRITE setNodeDelegate NOTIFY nodeDelegateChanged FINAL)
inline QQmlComponent* getNodeDelegate() noexcept { return _nodeDelegate.get(); }
protected:
void setNodeDelegate(QQmlComponent* nodeDelegate) noexcept;
Expand All @@ -239,7 +239,7 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>

public:
//! Default delegate for qan::Edge and Qan.Edge edges.
Q_PROPERTY( QQmlComponent* edgeDelegate READ getEdgeDelegate WRITE setEdgeDelegate NOTIFY edgeDelegateChanged FINAL )
Q_PROPERTY(QQmlComponent* edgeDelegate READ getEdgeDelegate WRITE setEdgeDelegate NOTIFY edgeDelegateChanged FINAL)
inline QQmlComponent* getEdgeDelegate() noexcept { return _edgeDelegate.get(); }
protected:
void setEdgeDelegate(QQmlComponent* edgeDelegate) noexcept;
Expand All @@ -251,7 +251,7 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>

public:
//! Default delegate for qan::Group and Qan.Group groups.
Q_PROPERTY( QQmlComponent* groupDelegate READ getGroupDelegate WRITE setGroupDelegate NOTIFY groupDelegateChanged FINAL )
Q_PROPERTY(QQmlComponent* groupDelegate READ getGroupDelegate WRITE setGroupDelegate NOTIFY groupDelegateChanged FINAL)
inline QQmlComponent* getGroupDelegate() noexcept { return _groupDelegate.get(); }
protected:
void setGroupDelegate(QQmlComponent* groupDelegate) noexcept;
Expand All @@ -263,14 +263,14 @@ class Graph : public gtpo::graph<QQuickItem, qan::Node, qan::Group, qan::Edge>

protected:
//! Create a _styleable_ graph primitive using the given delegate \c component with either a source \c node or \c edge.
QQuickItem* createFromComponent( QQmlComponent* component,
qan::Style& style,
qan::Node* node = nullptr,
qan::Edge* edge = nullptr,
qan::Group* group = nullptr ) noexcept;
QQuickItem* createFromComponent(QQmlComponent* component,
qan::Style& style,
qan::Node* node = nullptr,
qan::Edge* edge = nullptr,
qan::Group* group = nullptr ) noexcept;

//! Shortcut to createComponent(), mainly used in Qan.StyleList View to generate item for style pre visualization.
Q_INVOKABLE QQuickItem* createFromComponent( QQmlComponent* component, qan::Style* style );
Q_INVOKABLE QQuickItem* createFromComponent(QQmlComponent* component, qan::Style* style);

public:
/*! \brief QML component used to create qan::NodeItem or qan::GroupItem \c selectionItem, could be dynamically changed from either c++ or QML.
Expand Down
2 changes: 0 additions & 2 deletions src/qanGraphView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ void GraphView::setGraph(qan::Graph* graph)
disconnect(_graph, 0, this, 0);
_graph = graph;
auto graphViewQmlContext = qmlContext(this);
// FIXME remove that
//auto containerQmlContext = qmlContext(getContainerItem());
QQmlEngine::setContextForObject(getContainerItem(), graphViewQmlContext);
_graph->setContainerItem(getContainerItem());
connect(_graph, &qan::Graph::nodeClicked,
Expand Down

0 comments on commit 381eaeb

Please sign in to comment.