Commit 20a85537 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Move sortAndFilterAnyMergableNodesSafe into KisLayerUtils

All node sorting algorithms should be in one place
parent d740abcb
...@@ -1178,6 +1178,30 @@ namespace KisLayerUtils { ...@@ -1178,6 +1178,30 @@ namespace KisLayerUtils {
return result; return result;
} }
KisNodeList sortAndFilterAnyMergableNodesSafe(const KisNodeList &nodes, KisImageSP image) {
KisNodeList filteredNodes = nodes;
KisNodeList sortedNodes;
KisLayerUtils::filterMergableNodes(filteredNodes, true);
bool haveExternalNodes = false;
Q_FOREACH (KisNodeSP node, nodes) {
if (node->graphListener() != image->root()->graphListener()) {
haveExternalNodes = true;
break;
}
}
if (!haveExternalNodes) {
KisLayerUtils::sortMergableNodes(image->root(), filteredNodes, sortedNodes);
} else {
sortedNodes = filteredNodes;
}
return sortedNodes;
}
void addCopyOfNameTag(KisNodeSP node) void addCopyOfNameTag(KisNodeSP node)
{ {
const QString prefix = i18n("Copy of"); const QString prefix = i18n("Copy of");
......
...@@ -40,6 +40,7 @@ namespace KisLayerUtils ...@@ -40,6 +40,7 @@ namespace KisLayerUtils
KRITAIMAGE_EXPORT void sortMergableNodes(KisNodeSP root, QList<KisNodeSP> &inputNodes, QList<KisNodeSP> &outputNodes); KRITAIMAGE_EXPORT void sortMergableNodes(KisNodeSP root, QList<KisNodeSP> &inputNodes, QList<KisNodeSP> &outputNodes);
KRITAIMAGE_EXPORT KisNodeList sortMergableNodes(KisNodeSP root, KisNodeList nodes); KRITAIMAGE_EXPORT KisNodeList sortMergableNodes(KisNodeSP root, KisNodeList nodes);
KRITAIMAGE_EXPORT void filterMergableNodes(KisNodeList &nodes, bool allowMasks = false); KRITAIMAGE_EXPORT void filterMergableNodes(KisNodeList &nodes, bool allowMasks = false);
KRITAIMAGE_EXPORT KisNodeList sortAndFilterAnyMergableNodesSafe(const KisNodeList &nodes, KisImageSP image);
KRITAIMAGE_EXPORT bool checkIsChildOf(KisNodeSP node, const KisNodeList &parents); KRITAIMAGE_EXPORT bool checkIsChildOf(KisNodeSP node, const KisNodeList &parents);
KRITAIMAGE_EXPORT void filterUnlockedNodes(KisNodeList &nodes); KRITAIMAGE_EXPORT void filterUnlockedNodes(KisNodeList &nodes);
......
...@@ -310,28 +310,6 @@ private: ...@@ -310,28 +310,6 @@ private:
QList<KisSelectionMaskSP> m_activeAfter; QList<KisSelectionMaskSP> m_activeAfter;
}; };
KisNodeList sortAndFilterNodes(const KisNodeList &nodes, KisImageSP image) {
KisNodeList filteredNodes = nodes;
KisNodeList sortedNodes;
KisLayerUtils::filterMergableNodes(filteredNodes, true);
bool haveExternalNodes = false;
Q_FOREACH (KisNodeSP node, nodes) {
if (node->graphListener() != image->root()->graphListener()) {
haveExternalNodes = true;
break;
}
}
if (!haveExternalNodes) {
KisLayerUtils::sortMergableNodes(image->root(), filteredNodes, sortedNodes);
} else {
sortedNodes = filteredNodes;
}
return sortedNodes;
}
/** /**
* A generalized command to muve up/down a set of layer * A generalized command to muve up/down a set of layer
...@@ -369,7 +347,7 @@ struct LowerRaiseLayer : public KisCommandUtils::AggregateCommand { ...@@ -369,7 +347,7 @@ struct LowerRaiseLayer : public KisCommandUtils::AggregateCommand {
} }
void populateChildCommands() override { void populateChildCommands() override {
KisNodeList sortedNodes = sortAndFilterNodes(m_nodes, m_image); KisNodeList sortedNodes = KisLayerUtils::sortAndFilterAnyMergableNodesSafe(m_nodes, m_image);
KisNodeSP headNode = m_lower ? sortedNodes.first() : sortedNodes.last(); KisNodeSP headNode = m_lower ? sortedNodes.first() : sortedNodes.last();
const NodesType nodesType = getNodesType(sortedNodes); const NodesType nodesType = getNodesType(sortedNodes);
...@@ -493,7 +471,7 @@ struct DuplicateLayers : public KisCommandUtils::AggregateCommand { ...@@ -493,7 +471,7 @@ struct DuplicateLayers : public KisCommandUtils::AggregateCommand {
m_mode(mode) {} m_mode(mode) {}
void populateChildCommands() override { void populateChildCommands() override {
KisNodeList filteredNodes = sortAndFilterNodes(m_nodes, m_image); KisNodeList filteredNodes = KisLayerUtils::sortAndFilterAnyMergableNodesSafe(m_nodes, m_image);
if (filteredNodes.isEmpty()) return; if (filteredNodes.isEmpty()) return;
......
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