Commit 22d1a061 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added recursive setting of graph listener into KisNode::setGraphListener()

Otherwise, the child nodes will get the listener only in case they were
added to the parent *after* the parent is connected to the listener.

BUG:289150
parent 6fdff715
......@@ -141,6 +141,12 @@ KisNodeGraphListener *KisNode::graphListener() const
void KisNode::setGraphListener(KisNodeGraphListener *graphListener)
{
m_d->graphListener = graphListener;
KisSafeReadNodeList::const_iterator iter;
FOREACH_SAFE(iter, m_d->nodes) {
KisNodeSP child = (*iter);
child->setGraphListener(graphListener);
}
}
KisNodeSP KisNode::parent() const
......
......@@ -20,11 +20,58 @@
#include <qtest_kde.h>
#include "kis_node_graph_listener.h"
#include "kis_node_facade.h"
#include "testutil.h"
void KisNodeGraphListenerTest::testCreation()
void KisNodeGraphListenerTest::testUpdateOfListener()
{
KisNodeFacade nodeFacade;
TestUtil::TestGraphListener listener;
KisNodeSP rootNode = new TestNode();
KisNodeSP child1 = new TestNode();
KisNodeSP child2 = new TestNode();
rootNode->setGraphListener(&listener);
QCOMPARE(rootNode->graphListener(), &listener);
QCOMPARE(child1->graphListener(), (KisNodeGraphListener*)0);
QCOMPARE(child2->graphListener(), (KisNodeGraphListener*)0);
nodeFacade.addNode(child1, rootNode);
nodeFacade.addNode(child2, rootNode);
QCOMPARE(rootNode->graphListener(), &listener);
QCOMPARE(child1->graphListener(), &listener);
QCOMPARE(child2->graphListener(), &listener);
}
void KisNodeGraphListenerTest::testRecursiveUpdateOfListener()
{
KisNodeFacade nodeFacade;
TestUtil::TestGraphListener listener;
KisNodeSP rootNode = new TestNode();
KisNodeSP child1 = new TestNode();
KisNodeSP child2 = new TestNode();
QCOMPARE(rootNode->graphListener(), (KisNodeGraphListener*)0);
QCOMPARE(child1->graphListener(), (KisNodeGraphListener*)0);
QCOMPARE(child2->graphListener(), (KisNodeGraphListener*)0);
nodeFacade.addNode(child1, rootNode);
nodeFacade.addNode(child2, rootNode);
QCOMPARE(rootNode->graphListener(), (KisNodeGraphListener*)0);
QCOMPARE(child1->graphListener(), (KisNodeGraphListener*)0);
QCOMPARE(child2->graphListener(), (KisNodeGraphListener*)0);
rootNode->setGraphListener(&listener);
QCOMPARE(rootNode->graphListener(), &listener);
QCOMPARE(child1->graphListener(), &listener);
QCOMPARE(child2->graphListener(), &listener);
}
QTEST_KDEMAIN(KisNodeGraphListenerTest, GUI)
QTEST_KDEMAIN(KisNodeGraphListenerTest, NoGUI)
#include "kis_node_graph_listener_test.moc"
......@@ -21,13 +21,34 @@
#include <QtTest/QtTest>
#include "kis_node.h"
class TestNode : public KisNode
{
Q_OBJECT
public:
KisNodeSP clone() const {
return new TestNode(*this);
}
bool allowAsChild(KisNodeSP) const {
return true;
}
const KoColorSpace * colorSpace() const {
return 0;
}
virtual const KoCompositeOp * compositeOp() const {
return 0;
}
};
class KisNodeGraphListenerTest : public QObject
{
Q_OBJECT
private slots:
void testCreation();
void testUpdateOfListener();
void testRecursiveUpdateOfListener();
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment