Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_image_command.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
3 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
9#include <klocalizedstring.h>
10
11#include "kis_image.h"
12#include "kis_layer.h"
13
14
15
17 : KUndo2Command(name, parent)
18 , m_image(image)
19{
20}
21
25
26static inline bool isLayer(KisNodeSP node) {
27 return qobject_cast<KisLayer*>(node.data());
28}
29
31 KisNodeSP removedNode,
32 const QRect &updateRect)
33 : m_image(image), m_updateRect(updateRect)
34{
40 m_removedNodeParent = removedNode->parent();
42}
43
45 if (!m_removedNodeParent) return;
46 KIS_ASSERT_RECOVER_RETURN(m_removedNodeIndex >= 0);
47
48 KisNodeSP node;
49 int index = m_removedNodeIndex;
50
51 while ((node = m_removedNodeParent->at(index)) && !isLayer(node)) {
52 index++;
53 }
54
55 if (!node) {
56 index = qMax(0, m_removedNodeIndex - 1);
57
58 while ((node = m_removedNodeParent->at(index)) && !isLayer(node)) {
59 index--;
60 }
61 }
62
63 if (node) {
64 node->setDirty(m_updateRect);
65 } else {
67 if (image) {
68 image->refreshGraphAsync(m_removedNodeParent);
69 m_removedNodeParent->setDirty(m_updateRect);
70 }
71 }
72}
UpdateTarget(KisImageWSP image, KisNodeSP removedNode, const QRect &updateRect)
KisImageCommand(const KUndo2MagicString &name, KisImageWSP image, KUndo2Command *parent=0)
~KisImageCommand() override
void refreshGraphAsync(KisNodeSP root, const QVector< QRect > &rects, const QRect &cropRect, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None) override
KisSharedPtr< T > toStrongRef() const
toStrongRef returns a KisSharedPtr which may be dereferenced.
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
static bool isLayer(KisNodeSP node)
int index(const KisNodeSP node) const
Definition kis_node.cpp:432
KisNodeWSP parent
Definition kis_node.cpp:86
KisNodeSP at(quint32 index) const
Definition kis_node.cpp:421
virtual void setDirty()
Definition kis_node.cpp:577