Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to obtain destination port of qan::Connector? #164

Closed
petrmanek opened this issue Sep 6, 2022 · 6 comments
Closed

Way to obtain destination port of qan::Connector? #164

petrmanek opened this issue Sep 6, 2022 · 6 comments
Assignees
Milestone

Comments

@petrmanek
Copy link

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 petrmanek changed the title Way for obtain destination port of qan::Connector? Way to obtain destination port of qan::Connector? Sep 6, 2022
@cneben
Copy link
Owner

cneben commented Sep 7, 2022

Hi @petrmanek, looking at it !

@petrmanek
Copy link
Author

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

cneben added a commit that referenced this issue Oct 2, 2022
Signed-off-by: cneben <[email protected]>
@cneben
Copy link
Owner

cneben commented Oct 2, 2022

@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 added a commit that referenced this issue Oct 2, 2022
cneben added a commit that referenced this issue Oct 2, 2022
@cneben
Copy link
Owner

cneben commented Oct 2, 2022

@cneben cneben self-assigned this Oct 2, 2022
@cneben cneben added this to the 2.2.0 milestone Oct 2, 2022
@petrmanek
Copy link
Author

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

@petrmanek
Copy link
Author

Just tested it, works beautifully. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants