Krita Source Code Documentation
Loading...
Searching...
No Matches
KisBatchUpdateLayerModificationCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7
8#include <kis_image.h>
9#include <kis_node.h>
10
12 RecipeSP recipe,
14 KUndo2Command *parent)
15 : KisCommandUtils::FlipFlopCommand(state)
16 , m_image(image)
17 , m_recipe(recipe)
18{
19}
20
22{
24 if (!image) {
25 return;
26 }
27
28 // TODO: reuse compression from the KisUpdateCommandEx and KisBatchNodeUpdate
29 // to avoid double updates
30
31 if (getState() == INITIALIZING) {
32 KIS_SAFE_ASSERT_RECOVER(m_recipe->removedNodesUpdateTargets.empty()) {
33 m_recipe->removedNodesUpdateTargets.clear();
34 }
35
36 for (auto it = m_recipe->nodesToRemove.begin();
37 it != m_recipe->nodesToRemove.end();
38 ++it) {
39
40 if (!it->doRedoUpdates) continue;
41 m_recipe->removedNodesUpdateTargets.emplace_back(image, it->node, image->bounds());
42 }
43 } else {
44 for (auto it = m_recipe->removedNodesUpdateTargets.begin();
45 it != m_recipe->removedNodesUpdateTargets.end();
46 ++it) {
47
48 it->update();
49 }
50 m_recipe->removedNodesUpdateTargets.clear();
51
52 for (auto it = m_recipe->nodesToAdd.begin();
53 it != m_recipe->nodesToAdd.end();
54 ++it) {
55
56 if (!it->doRedoUpdates) continue;
57 it->node->setDirty(image->bounds());
58 }
59 }
61}
62
64{
66
68 if (!image) {
69 return;
70 }
71
72 if (getState() == FINALIZING) {
73 KIS_SAFE_ASSERT_RECOVER(m_recipe->addedNodesUpdateTargets.empty()) {
74 m_recipe->addedNodesUpdateTargets.clear();
75 }
76
77 for (auto it = m_recipe->nodesToAdd.begin();
78 it != m_recipe->nodesToAdd.end();
79 ++it) {
80
81 if (!it->doUndoUpdates) continue;
82 m_recipe->addedNodesUpdateTargets.emplace_back(image, it->node, image->bounds());
83 }
84 } else {
85 for (auto it = m_recipe->addedNodesUpdateTargets.begin();
86 it != m_recipe->addedNodesUpdateTargets.end();
87 ++it) {
88
89 it->update();
90 }
91 m_recipe->addedNodesUpdateTargets.clear();
92
93 for (auto it = m_recipe->nodesToRemove.begin();
94 it != m_recipe->nodesToRemove.end();
95 ++it) {
96
97 if (!it->doUndoUpdates) continue;
98 image->refreshGraphAsync(it->node, image->bounds());
99 }
100 }
101}
KisBatchUpdateLayerModificationCommand(KisImageWSP image, RecipeSP recipe, KisCommandUtils::FlipFlopCommand::State state, KUndo2Command *parent=0)
void refreshGraphAsync(KisNodeSP root, const QVector< QRect > &rects, const QRect &cropRect, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None) override
QRect bounds() const override
KisSharedPtr< T > toStrongRef() const
toStrongRef returns a KisSharedPtr which may be dereferenced.
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126