Krita Source Code Documentation
Loading...
Searching...
No Matches
KisBatchNodeUpdate Class Reference

#include <KisBatchNodeUpdate.h>

+ Inheritance diagram for KisBatchNodeUpdate:

Public Member Functions

void addUpdate (KisNodeSP node, const QRect &rc)
 
void compress ()
 
KisBatchNodeUpdate compressed () const
 
 KisBatchNodeUpdate ()=default
 
 KisBatchNodeUpdate (const KisBatchNodeUpdate &rhs)=default
 
 KisBatchNodeUpdate (const std::vector< std::pair< KisNodeSP, QRect > > &rhs)
 
 KisBatchNodeUpdate (KisBatchNodeUpdate &&rhs)=default
 
KisBatchNodeUpdateoperator= (const KisBatchNodeUpdate &rhs)=default
 
KisBatchNodeUpdateoperator|= (const KisBatchNodeUpdate &rhs)
 

Detailed Description

A simple class for storing the updates of multiple nodes in a single place. These updates may later be "compressed", which means that only the topmost root layers will get updates. In such a case the update should be issued as refreshGraphAsync().

Definition at line 23 of file KisBatchNodeUpdate.h.

Constructor & Destructor Documentation

◆ KisBatchNodeUpdate() [1/4]

KisBatchNodeUpdate::KisBatchNodeUpdate ( )
default

◆ KisBatchNodeUpdate() [2/4]

KisBatchNodeUpdate::KisBatchNodeUpdate ( const KisBatchNodeUpdate & rhs)
default

◆ KisBatchNodeUpdate() [3/4]

KisBatchNodeUpdate::KisBatchNodeUpdate ( KisBatchNodeUpdate && rhs)
default

◆ KisBatchNodeUpdate() [4/4]

KisBatchNodeUpdate::KisBatchNodeUpdate ( const std::vector< std::pair< KisNodeSP, QRect > > & rhs)

Definition at line 12 of file KisBatchNodeUpdate.cpp.

13 : std::vector<std::pair<KisNodeSP, QRect>>(rhs)
14{
15
16}

Member Function Documentation

◆ addUpdate()

void KisBatchNodeUpdate::addUpdate ( KisNodeSP node,
const QRect & rc )

Add an update designated for node with dirty rect rc

Please node that adding multiple updates for the same node, will result in multiple records added into the internal vector. These duplicated records may be resolved by calling compress() method.

See also
compress()

Definition at line 18 of file KisBatchNodeUpdate.cpp.

19{
20 push_back(std::make_pair(node, rc));
21}

◆ compress()

void KisBatchNodeUpdate::compress ( )

Compress the stored updates:

1) All updates for the same node will be merged into one

2) If the list contains a child and its parent, the two updates will be merged into one. This new update record will be designated for the parent.

The idea is that the parent will be updated with refreshGraphAsync(), which would update the child anyway.

Definition at line 23 of file KisBatchNodeUpdate.cpp.

24{
25 *this = compressed();
26}
KisBatchNodeUpdate compressed() const

References compressed().

◆ compressed()

KisBatchNodeUpdate KisBatchNodeUpdate::compressed ( ) const
See also
compress()

Definition at line 28 of file KisBatchNodeUpdate.cpp.

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}
KisNodeList sortAndFilterMergeableInternalNodes(KisNodeList nodes, bool allowMasks)
bool checkIsChildOf(KisNodeSP node, const KisNodeList &parents)
bool update(QSpinBox *spinBox)

References KisLayerUtils::checkIsChildOf(), and KisLayerUtils::sortAndFilterMergeableInternalNodes().

◆ operator=()

KisBatchNodeUpdate & KisBatchNodeUpdate::operator= ( const KisBatchNodeUpdate & rhs)
default

◆ operator|=()

KisBatchNodeUpdate & KisBatchNodeUpdate::operator|= ( const KisBatchNodeUpdate & rhs)

Merge two update batches. The updates for the same nodes will be merged. This merge operation does not do parent-child compression though. You need to call compress() separately for that.

Definition at line 54 of file KisBatchNodeUpdate.cpp.

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}
QAction * next(const QObject *recvr, const char *slot, QObject *parent)
int size(const Forest< T > &forest)
Definition KisForest.h:1232

The documentation for this class was generated from the following files: