Krita Source Code Documentation
Loading...
Searching...
No Matches
KoFlakeUtils.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef KOFLAKEUTILS_H
8#define KOFLAKEUTILS_H
9
10#include <KoShape.h>
11#include <KoFlakeTypes.h>
12#include <KoShapeStroke.h>
13
14#include "kis_global.h"
16
17
18namespace KoFlake {
19
20template <typename ModifyFunction>
21 auto modifyShapesStrokes(QList<KoShape*> shapes, ModifyFunction modifyFunction)
22 -> decltype(modifyFunction(KoShapeStrokeSP()), (KUndo2Command*)(0))
23 {
24 if (shapes.isEmpty()) return 0;
25
27
28 Q_FOREACH(KoShape *shape, shapes) {
29 KoShapeStrokeSP shapeStroke = shape->stroke() ?
30 qSharedPointerDynamicCast<KoShapeStroke>(shape->stroke()) :
32
33 KoShapeStrokeSP newStroke =
34 toQShared(shapeStroke ?
35 new KoShapeStroke(*shapeStroke) :
36 new KoShapeStroke());
37
38 modifyFunction(newStroke);
39
40 newStrokes << newStroke;
41 }
42
43 return new KoShapeStrokeCommand(shapes, newStrokes);
44}
45
46template <class Policy>
47bool compareShapePropertiesEqual(const QList<KoShape*> shapes, const Policy &policy)
48{
49 if (shapes.size() == 1) return true;
50
51 typename Policy::PointerType bg =
52 policy.getProperty(shapes.first());
53
54 Q_FOREACH (KoShape *shape, shapes) {
55 typename Policy::PointerType otherBg = policy.getProperty(shape);
56
57 if (
58 !(
59 (!bg && !otherBg) ||
60 (bg && otherBg && policy.compareTo(bg, otherBg))
61 )) {
62
63 return false;
64 }
65 }
66
67 return true;
68}
69
70template <class Policy>
72{
73 return compareShapePropertiesEqual<Policy>(shapes, Policy());
74}
75
76}
77
78#endif // KOFLAKEUTILS_H
79
QSharedPointer< KoShapeStroke > KoShapeStrokeSP
The undo / redo command for setting the shape stroke.
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067
QSharedPointer< T > toQShared(T *ptr)
auto modifyShapesStrokes(QList< KoShape * > shapes, ModifyFunction modifyFunction) -> decltype(modifyFunction(KoShapeStrokeSP()),(KUndo2Command *)(0))
bool compareShapePropertiesEqual(const QList< KoShape * > shapes, const Policy &policy)