Krita Source Code Documentation
Loading...
Searching...
No Matches
KisBatchNodeUpdate.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include "kis_node.h"
10#include "kis_layer_utils.h"
11
12KisBatchNodeUpdate::KisBatchNodeUpdate(const std::vector<std::pair<KisNodeSP, QRect>> &rhs)
13 : std::vector<std::pair<KisNodeSP, QRect>>(rhs)
14{
15
16}
17
18void KisBatchNodeUpdate::addUpdate(KisNodeSP node, const QRect &rc)
19{
20 push_back(std::make_pair(node, rc));
21}
22
24{
25 *this = compressed();
26}
27
29{
30 KisBatchNodeUpdate newUpdateData;
31
32 KisNodeList rootNodes;
33
34 std::transform(begin(), end(), std::back_inserter(rootNodes),
35 [] (const std::pair<KisNodeSP, QRect> &update) {return update.first; });
36
37 rootNodes = KisLayerUtils::sortAndFilterMergeableInternalNodes(rootNodes, true);
38
39 Q_FOREACH (KisNodeSP root, rootNodes) {
40 QRect dirtyRect;
41
42 for (auto it = begin(); it != end(); ++it) {
43 if (it->first == root || KisLayerUtils::checkIsChildOf(it->first, {root})) {
44 dirtyRect |= it->second;
45 }
46 }
47
48 newUpdateData.push_back(std::make_pair(root, dirtyRect));
49 }
50
51 return newUpdateData;
52}
53
55{
56 if (this == &rhs)
57 return *this;
58
59 reserve(size() + rhs.size());
60
61 std::copy(rhs.begin(), rhs.end(), std::back_inserter(*this));
62 std::sort(begin(), end(), [](const std::pair<KisNodeSP, QRect> &lhs, const std::pair<KisNodeSP, QRect> &rhs) { return lhs.first.data() < rhs.first.data(); });
63
64 if (size() <= 1)
65 return *this;
66
67 for (auto prevIt = begin(), it = next(prevIt); it != end();) {
68 if (prevIt->first == it->first) {
69 prevIt->second |= it->second;
70 it = erase(it);
71 } else {
72 ++prevIt;
73 ++it;
74 }
75 }
76
77 return *this;
78}
79
80QDebug operator<<(QDebug dbg, const KisBatchNodeUpdate &update)
81{
82 dbg.nospace() << "KisBatchNodeUpdate (";
83
84 for (auto it = update.begin(); it != update.end(); ++it) {
85 dbg.nospace() << it->first << "->" << it->second;
86
87 if (next(it) != update.end()) {
88 dbg.nospace() << "; ";
89 }
90 }
91
92 return dbg;
93}
QDebug operator<<(QDebug dbg, const KisBatchNodeUpdate &update)
KisBatchNodeUpdate()=default
KisBatchNodeUpdate & operator|=(const KisBatchNodeUpdate &rhs)
KisBatchNodeUpdate compressed() const
void addUpdate(KisNodeSP node, const QRect &rc)
KisNodeList sortAndFilterMergeableInternalNodes(KisNodeList nodes, bool allowMasks)
bool checkIsChildOf(KisNodeSP node, const KisNodeList &parents)