Commit 7971e922 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Cleanup: move utility functions into utils

parent d9cb55b6
......@@ -643,6 +643,23 @@ namespace KisLayerUtils {
}
}
KisNodeList findNodesWithProps(KisNodeSP root, const KoProperties &props, bool excludeRoot)
{
KisNodeList nodes;
if ((!excludeRoot || root->parent()) && root->check(props)) {
nodes << root;
}
KisNodeSP node = root->firstChild();
while (node) {
nodes += findNodesWithProps(node, props, excludeRoot);
node = node->nextSibling();
}
return nodes;
}
void mergeMultipleLayersImpl(KisImageSP image, QList<KisNodeSP> mergedNodes, KisNodeSP putAfter, bool flattenSingleLayer, const KUndo2MagicString &actionName)
{
filterMergableNodes(mergedNodes);
......
......@@ -19,11 +19,15 @@
#ifndef __KIS_LAYER_UTILS_H
#define __KIS_LAYER_UTILS_H
#include <functional>
#include "kundo2command.h"
#include "kis_types.h"
#include "kritaimage_export.h"
#include "kis_command_utils.h"
class KoProperties;
namespace KisMetaData
{
class MergeStrategy;
......@@ -47,6 +51,7 @@ namespace KisLayerUtils
KRITAIMAGE_EXPORT void flattenImage(KisImageSP image);
KRITAIMAGE_EXPORT void addCopyOfNameTag(KisNodeSP node);
KRITAIMAGE_EXPORT KisNodeList findNodesWithProps(KisNodeSP root, const KoProperties &props, bool excludeRoot);
typedef QMap<int, QSet<KisNodeSP> > FrameJobs;
void updateFrameJobs(FrameJobs *jobs, KisNodeSP node);
......@@ -97,6 +102,24 @@ namespace KisLayerUtils
private:
KisNodeList m_nodes;
};
template <typename T>
bool checkNodesDiffer(KisNodeList nodes, std::function<T(KisNodeSP)> checkerFunc)
{
bool valueDiffers = false;
bool initialized = false;
T currentValue;
Q_FOREACH (KisNodeSP node, nodes) {
if (!initialized) {
currentValue = checkerFunc(node);
initialized = true;
} else if (currentValue != checkerFunc(node)) {
valueDiffers = true;
break;
}
}
return valueDiffers;
}
};
#endif /* __KIS_LAYER_UTILS_H */
......@@ -116,7 +116,7 @@ KisDlgLayerProperties::KisDlgLayerProperties(KisNodeList nodes, KisViewManager *
d->compositeOpProperty->connectValueChangedSignal(&d->updatesCompressor, SLOT(start()));
connect(d->page->cmbComposite, SIGNAL(currentIndexChanged(int)), SLOT(slotCompositeOpValueChangedExternally()));
if (!checkNodesDiffer<const KoColorSpace*>(d->nodes, [](KisNodeSP node) { return node->colorSpace(); })) {
if (!KisLayerUtils::checkNodesDiffer<const KoColorSpace*>(d->nodes, [](KisNodeSP node) { return node->colorSpace(); })) {
d->page->lblColorSpace->setText(d->colorSpace->name());
if (const KoColorProfile* profile = d->colorSpace->profile()) {
......
......@@ -31,6 +31,7 @@
#include "kis_node.h"
#include "kis_layer.h"
#include "kis_layer_utils.h"
class KisMultinodePropertyInterface;
class MultinodePropertyBaseConnector;
......@@ -189,27 +190,6 @@ private:
QString m_propName;
};
// TODO: move to KisLayerUtils
#include <functional>
template <typename T>
bool checkNodesDiffer(KisNodeList nodes, std::function<T(KisNodeSP)> checkerFunc)
{
bool valueDiffers = false;
bool initialized = false;
T currentValue;
Q_FOREACH (KisNodeSP node, nodes) {
if (!initialized) {
currentValue = checkerFunc(node);
initialized = true;
} else if (currentValue != checkerFunc(node)) {
valueDiffers = true;
break;
}
}
return valueDiffers;
}
struct ChannelFlagAdapter : public BaseAdapter {
typedef bool ValueType;
typedef MultinodePropertyBoolConnector<ChannelFlagAdapter> ConnectorType;
......@@ -258,7 +238,7 @@ struct ChannelFlagAdapter : public BaseAdapter {
PropertyList props;
{
bool nodesDiffer = checkNodesDiffer<const KoColorSpace*>(nodes, [](KisNodeSP node) { return node->colorSpace(); });
bool nodesDiffer = KisLayerUtils::checkNodesDiffer<const KoColorSpace*>(nodes, [](KisNodeSP node) { return node->colorSpace(); });
if (nodesDiffer) {
return props;
......
......@@ -1200,32 +1200,15 @@ void KisNodeManager::createQuickClippingGroup()
juggler->addNode(KisNodeList() << maskLayer, parent, above);
}
KisNodeList findNodesWithProps(KisNodeSP root, const KoProperties &props, bool excludeRoot)
{
KisNodeList nodes;
if ((!excludeRoot || root->parent()) && root->check(props)) {
nodes << root;
}
KisNodeSP node = root->firstChild();
while (node) {
nodes += findNodesWithProps(node, props, excludeRoot);
node = node->nextSibling();
}
return nodes;
}
void KisNodeManager::selectLayersImpl(const KoProperties &props, const KoProperties &invertedProps)
{
KisImageSP image = m_d->view->image();
KisNodeList nodes = findNodesWithProps(image->root(), props, true);
KisNodeList nodes = KisLayerUtils::findNodesWithProps(image->root(), props, true);
KisNodeList selectedNodes = this->selectedNodes();
if (KritaUtils::compareListsUnordered(nodes, selectedNodes)) {
nodes = findNodesWithProps(image->root(), invertedProps, true);
nodes = KisLayerUtils::findNodesWithProps(image->root(), invertedProps, true);
}
if (!nodes.isEmpty()) {
......
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