QuickQanava uses the qan::Behaviour concept to allow developers to react to changes in the graph topology. You can define custom behaviors by subclassing qan::NodeBehaviour (or similar for edges/groups) and overriding lifecycle methods like inNodeInserted() or inNodeRemoved().
To use a behavior, instantiate it and attach it to a primitive using attachBehaviour() (or installBehaviour() for nodes).
class CustomBehaviour : public qan::NodeBehaviour
{
Q_OBJECT
public:
explicit NodeBehaviour(QObject* parent = nullptr) :
qan::NodeBehaviour{"Custom Behaviour", parent} { }
virtual ~NodeBehaviour() override { /* Nil */ }
NodeBehaviour(const NodeBehaviour&) = delete;
protected:
virtual void inNodeInserted(qan::Node& inNode, qan::Edge& edge) noexcept override;
virtual void inNodeRemoved(qan::Node& inNode, qan::Edge& edge) noexcept override;
};
// Usage
{
qan::Graph graph;
auto node = graph.insertNode();
node->attachBehaviour(std::make_unique<CustomBehaviour>());
auto source = graph.insertNode();
auto edge = graph.insertEdge(source, node); // Triggers CustomBehaviour::inNodeInserted
graph.removeEdge(edge); // Triggers CustomBehaviour::inNodeRemoved
}