Way to obtain destination port of `qan::Connector`?
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.
Hi @petrmanek, looking at it !
@cneben How is it going? Is there any more information that I can provide?
@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
https://github.com/cneben/QuickQanava/commit/e6001b53b87de2870ab821c86a00e9b8d71aedb9#diff-d05196eed1993514958224acf1e5b040406a8cf3cabacc9bcb50a5af3ff4e521L77
@cneben Brilliant! I will give that a test but it looks good initially.
Just tested it, works beautifully. Thank you!