Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeBulkActionLock.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <kis_debug.h>
10#include <KoShape.h>
11
13
15{
16 Q_FOREACH(KoShape *shape, shapes) {
17 // explicitly called shaped will be "updated" in both
18 // ways, using normal updates and dependent bulk updates
19 m_normalUpdateShapes.append(shape);
22 }
23}
24
26{
27 KoShapeBulkActionInterface *iface = dynamic_cast<KoShapeBulkActionInterface *>(shape);
28 if (iface) {
29 // postpone update till the end, if the shape is present
30 // multiple times
31 if (m_bulkInterfaceShapes.contains(iface)) {
32 m_bulkInterfaceShapes.removeOne(iface);
33 }
34 m_bulkInterfaceShapes.append(iface);
35 }
36};
37
39{
40 Q_FOREACH(KoShape *shape, dependees) {
43 }
44}
45
47{
48 m_finalUpdates.clear();
49
50 Q_FOREACH(KoShape *shape, m_normalUpdateShapes) {
51 m_finalUpdates[shape] |= shape->boundingRect();
52 }
53
55 iface->startBulkAction();
56 }
57
58}
59
61{
63 const QRectF update = iface->endBulkAction();
64
65 KoShape *shape = dynamic_cast<KoShape*>(iface);
66 KIS_SAFE_ASSERT_RECOVER(shape) { continue; }
67 m_finalUpdates[shape] |= update;
68 }
69
70 Q_FOREACH(KoShape *shape, m_normalUpdateShapes) {
71 m_finalUpdates[shape] |= shape->boundingRect();
72 }
73}
74
77{
78 UpdatesList result;
79 result.reserve(m_finalUpdates.size());
80
81 for (auto it = m_finalUpdates.begin(); it != m_finalUpdates.end(); ++it) {
82 result.emplace_back(it->first, it->second);
83 }
84
85 return result;
86}
87
89{
90 if (owns_lock()) {
91 qWarning() << "WARNING: KoShapeBulkActionLock is destroyed while being locked. Update rect will be lost!";
92 }
93}
94
96{
97 // TODO: implement optimization for shape managers merging
98 for (auto it = updates.begin(); it != updates.end(); ++it) {
99 it->first->updateAbsolute(it->second);
100 }
101}
KoShapeBulkActionLockAdapter(const QList< KoShape * > &shapes)
QList< KoShapeBulkActionInterface * > m_bulkInterfaceShapes
void addBulkInterfaceDependees(const QList< KoShape * > dependees)
std::unordered_map< KoShape *, QRectF > m_finalUpdates
void tryAddBulkInterfaceShape(KoShape *shape)
static void bulkShapesUpdate(const UpdatesList &updates)
QList< KoShape * > dependees() const
Returns list of shapes depending on this shape.
Definition KoShape.cpp:1054
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:299
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
Interface for bulk actions on shapes.
virtual QRectF endBulkAction()=0
virtual void startBulkAction()=0