Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix accessing active node state from the Python scripts
Dmitry Kazakovb1994c61454a
diff --git a/libs/global/KisSynchronizedConnection.cpp b/libs/global/KisSynchronizedConnection.cppindex 35be8524e2..57c442244b 100644--- a/libs/global/KisSynchronizedConnection.cpp+++ b/libs/global/KisSynchronizedConnection.cpp@@ -78,6 +78,12 @@ bool KisSynchronizedConnectionBase::isAutoModeForUnittestsEnabled()return s_instance->enableAutoModeForUnittests;}+void KisSynchronizedConnectionBase::forceDeliverAllSynchronizedEvents()+{+ KIS_SAFE_ASSERT_RECOVER_RETURN(s_barrier->callback);+ s_barrier->callback();+}+bool KisSynchronizedConnectionBase::event(QEvent *event){if (event->type() == s_instance->eventType) {diff --git a/libs/global/KisSynchronizedConnection.h b/libs/global/KisSynchronizedConnection.hindex 7e5055ff91..a52fc495da 100644--- a/libs/global/KisSynchronizedConnection.h+++ b/libs/global/KisSynchronizedConnection.h@@ -61,6 +61,7 @@ public:static void setAutoModeForUnittestsEnabled(bool value);static bool isAutoModeForUnittestsEnabled();+ static void forceDeliverAllSynchronizedEvents();protected:bool event(QEvent *event) override;diff --git a/libs/libkis/Document.cpp b/libs/libkis/Document.cppindex aa2d807932..bb71fdfb67 100644--- a/libs/libkis/Document.cpp+++ b/libs/libkis/Document.cpp@@ -8,6 +8,7 @@#include <QUrl>#include <QDomDocument>+#include <KisSynchronizedConnection.h>#include <KoColorSpaceConstants.h>#include <KisDocument.h>#include <kis_image.h>@@ -116,6 +117,9 @@ void Document::setBatchmode(bool value)Node *Document::activeNode() const{+ // see a related comment in Document::setActiveNode+ KisSynchronizedConnectionBase::forceDeliverAllSynchronizedEvents();+QList<KisNodeSP> activeNodes;Q_FOREACH(QPointer<KisView> view, KisPart::instance()->views()) {if (view && view->document() == d->document) {@@ -144,8 +148,16 @@ void Document::setActiveNode(Node* value)if (!nodeManager) return;KisNodeSelectionAdapter *selectionAdapter = nodeManager->nodeSelectionAdapter();if (!selectionAdapter) return;- selectionAdapter->setActiveNode(value->node());+ /**+ * If we created any nodes via the same script, then dummies state+ * may be not synchronized with the actual state of the nodes in the+ * image. Hence, we should explicitly deliver the synchronized events+ * before we try to manipulate with the GUI representation of nodes.+ */+ KisSynchronizedConnectionBase::forceDeliverAllSynchronizedEvents();++ selectionAdapter->setActiveNode(value->node());}QList<Node *> Document::topLevelNodes() const