QuickQanava icon indicating copy to clipboard operation
QuickQanava copied to clipboard

Way to obtain destination port of `qan::Connector`?

Open petrmanek opened this issue 3 years ago • 2 comments

During implementation of my custom drag-to-connect logic I found that there is no easy way to obtain the destination port item of qan::Connector inside my requestEdgeCreation() signal handler.

The default implementation exposes getSourcePort() that allows me to determine from where the drag originated. In connectorReleased() the internals of qan::Connector also retrieve the destination port that is used to bind the default edge, if enabled. Unfortunately, if I want to create my custom edge using the requestEdgeCreation signal instead, the destination port is lost in the scope of that function and not accessible anywhere else. I could implement my custom connector for this, however I believe that would be an overkill, especially given that this is would be easy to remedy. Below I propose two alternative solutions to extend the current API.

Option 1: add destinationPort as a property of qan::Connector

class Connector : public qan::NodeItem
{
    // ...
public:
    Q_PROPERTY(qan::PortItem* destinationPort READ getDestinationPort NOTIFY destinationPortChanged FINAL)
    inline qan::PortItem*   getDestinationPort() const noexcept { return _destinationPort.data(); }
private:
    QPointer<qan::PortItem> _destinationPort;
signals:
    void                    destinationPortChanged();
private slots:
    //! Called when the current destination port is destroyed.
    void                    destinationPortDestroyed();
    // ...
};

This property can be set somewhere around here and later accessed by user code in requestEdgeCreation().

Option 2: pass destination port in the signal

class Connector : public qan::NodeItem
{
    // ...
    void    requestEdgeCreation(qan::Node* src, QObject* dst, qan::PortItem* dstPort);
    // ...
};

This is a little bit out of line with the current API but it is less work. When the signal is emitted, it can be passed dstPort from here.

petrmanek avatar Sep 06 '22 10:09 petrmanek

Hi @petrmanek, looking at it !

cneben avatar Sep 07 '22 13:09 cneben

@cneben How is it going? Is there any more information that I can provide?

petrmanek avatar Sep 17 '22 19:09 petrmanek

@petrmanek Sorry for the delay, too much work ! I think I will have a test with option 2 which is much more simpler to implement and look more reusable.

Modifications are in f/#167-edge-selection

cneben avatar Oct 02 '22 08:10 cneben

https://github.com/cneben/QuickQanava/commit/e6001b53b87de2870ab821c86a00e9b8d71aedb9#diff-d05196eed1993514958224acf1e5b040406a8cf3cabacc9bcb50a5af3ff4e521L77

cneben avatar Oct 02 '22 08:10 cneben

@cneben Brilliant! I will give that a test but it looks good initially.

petrmanek avatar Oct 03 '22 08:10 petrmanek

Just tested it, works beautifully. Thank you!

petrmanek avatar Oct 11 '22 11:10 petrmanek