Commit 57f0af27 authored by Halla Rempt's avatar Halla Rempt
Browse files

Expose the node's unique id to libkis

And make it possible to find a node by uuid

(cherry picked from commit 1c59068e)
(cherry picked from commit 98331f0021f27c52c3e70052343696a3547c4f5b)
parent 1d07c893
......@@ -500,6 +500,24 @@ KisNodeSP KisNode::findChildByName(const QString &name)
return 0;
}
KisNodeSP KisNode::findChildByUniqueID(const QUuid &uuid)
{
KisNodeSP child = firstChild();
while (child) {
if (child->uuid() == uuid) {
return child;
}
if (child->childCount() > 0) {
KisNodeSP grandChild = child->findChildByUniqueID(uuid);
if (grandChild) {
return grandChild;
}
}
child = child->nextSibling();
}
return 0;
}
bool KisNode::add(KisNodeSP newNode, KisNodeSP aboveThis)
{
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(newNode, false);
......
......@@ -353,6 +353,13 @@ public: // Graph methods
*/
KisNodeSP findChildByName(const QString &name);
/**
* @brief nodeByUniqueID searches the node tree for a node with the given name and returns it.
* @param uuid the unique id of the node
* @return the node with the given unique id, or 0 if no node is found.
*/
KisNodeSP findChildByUniqueID(const QUuid &uuid);
Q_SIGNALS:
/**
* Don't use this signal anywhere other than KisNodeShape. It's a hack.
......
......@@ -168,6 +168,14 @@ Node *Document::nodeByName(const QString &name) const
return Node::createNode(d->document->image(), node);
}
Node *Document::nodeByUniqueID(const QUuid &id) const
{
if (!d->document) return 0;
KisNodeSP node = d->document->image()->rootLayer()->findChildByUniqueID(id);
if (node.isNull()) return 0;
return Node::createNode(d->document->image(), node);
}
QString Document::colorDepth() const
{
......
......@@ -121,6 +121,14 @@ public Q_SLOTS:
*/
Node *nodeByName(const QString &name) const;
/**
* @brief nodeByUniqueID searches the node tree for a node with the given name and returns it.
* @param uuid the unique id of the node
* @return the node with the given unique id, or 0 if no node is found.
*/
Node *nodeByUniqueID(const QUuid &id) const;
/**
* colorDepth A string describing the color depth of the image:
* <ul>
......
......@@ -17,6 +17,7 @@
*/
#include <QUrl>
#include <QScopedPointer>
#include <QUuid>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
......@@ -684,6 +685,12 @@ QImage Node::thumbnail(int w, int h)
return d->node->createThumbnail(w, h);
}
QUuid Node::uniqueId() const
{
if (!d->node) return QUuid();
return d->node->uuid();
}
KisPaintDeviceSP Node::paintDevice() const
{
return d->node->paintDevice();
......
......@@ -545,6 +545,9 @@ public Q_SLOTS:
*/
QImage thumbnail(int w, int h);
QUuid uniqueId() const;
private:
friend class Filter;
......
......@@ -63,6 +63,7 @@ public Q_SLOTS:
void cropNode(int x, int y, int w, int h);
void shearNode(double angleX, double angleY);
QImage thumbnail(int w, int h);
QUuid uniqueId() const;
Q_SIGNALS:
private:
};
Markdown is supported
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