Krita Source Code Documentation
Loading...
Searching...
No Matches
ShapeLayerTypeCheck.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef SHAPELAYERTYPECHECK_H
8#define SHAPELAYERTYPECHECK_H
9
10
12#include <KoID.h>
13#include <klocalizedstring.h>
14#include <kis_assert.h>
15#include <kis_image.h>
17#include <kis_node_visitor.h>
18#include <kis_group_layer.h>
19#include <KoShapeLayer.h>
20#include <KoShapeGroup.h>
21#include <KoPathShape.h>
22
24{
25public:
26
28
29 ShapeLayerTypeCheckVisitor (QString shapeId, QString pathId)
30 : m_count(0)
31 , m_shapeId(shapeId)
32 , m_pathShapeId(pathId)
33 {
34 }
35
36 quint32 count() {
37 return m_count;
38 }
39
40 bool visit(KisNode*) override {return true;}
41
42 bool visit(KisPaintLayer *) override {return true;}
43
44 bool visit(KisGroupLayer *layer) override {
45 return visitAll(layer);
46 }
47
48
49 bool visit(KisAdjustmentLayer *) override {return true;}
50
51 bool visit(KisExternalLayer * layer) override {
52 if (KoShapeLayer *shapeLayer = dynamic_cast<KoShapeLayer*>(layer)) {
53 check(shapeLayer->shapes());
54 }
55 return true;
56 }
57
58 bool visit(KisCloneLayer *) override {return true;}
59
60 bool visit(KisGeneratorLayer *) override {return true;}
61
62 bool visit(KisFilterMask *) override {return true;}
63
64 bool visit(KisTransformMask *) override {return true;}
65
66 bool visit(KisTransparencyMask *) override {return true;}
67
68 bool visit(KisSelectionMask *) override {return true;}
69
70 bool visit(KisColorizeMask *) override {return true;}
71
72
73
74private:
75 bool check(QList<KoShape*> shapes) {
76 Q_FOREACH(KoShape* shape, shapes) {
77 if (KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(shape)) {
78 // ShapeGroups have no id...
79 if (m_shapeId == "KoShapeGroup") {
80 m_count ++;
81 }
82 check(group->shapes());
83 } else if (KoPathShape *path = dynamic_cast<KoPathShape*>(shape)) {
84 if (!m_pathShapeId.isEmpty()) {
85 if (path->pathShapeId() == m_pathShapeId
86 && m_shapeId == path->shapeId()) {
87 m_count ++;
88 }
89 } else if (m_shapeId == path->shapeId()) {
90 m_count ++;
91 }
92 } else if (m_shapeId == shape->shapeId()) {
93 m_count ++;
94 }
95 }
96 return true;
97 }
98
99 quint32 m_count;
100 const QString m_shapeId;
101 const QString m_pathShapeId;
102
103};
104
105
107{
108public:
109
110 ShapeLayerTypeCheck(const QString &ShapeId, const QString &PathShapeId, const QString &id, Level level, const QString &customWarning = QString())
111 : KisExportCheckBase(id, level, customWarning)
112 , m_shapeId(ShapeId)
113 , m_pathShapeId(PathShapeId)
114 {
115 if (customWarning.isEmpty()) {
116 if (m_pathShapeId.isEmpty()) {
117 QString name = m_shapeId;
118 m_warning = i18nc("image conversion warning", "The image contains a Vector Layer with Shapes of type <b>%1</b>, which is not supported, these will not be saved.", name);
119 } else {
120 m_warning = i18nc("image conversion warning", "The image contains a Vector Layer with Shapes of type <b>%1</b>, which is not supported, these will be saved as paths", m_pathShapeId);
121 }
122 }
123 }
124
125 bool checkNeeded(KisImageSP image) const override
126 {
128 image->rootLayer()->accept(v);
129 return (v.count() > 0);
130 }
131
132 Level check(KisImageSP /*image*/) const override
133 {
134 return m_level;
135 }
136
137 QString m_shapeId;
139};
140
142{
143public:
144
145 ShapeLayerTypeCheckFactory(const QString &ShapeId, const QString &PathShapeId = "")
146 : m_shapeId(ShapeId)
147 , m_pathShapeId(PathShapeId)
148 {
149 }
150
152
153 KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
154 {
155 return new ShapeLayerTypeCheck(m_shapeId, m_pathShapeId, id(), level, customWarning);
156 }
157
158 QString id() const override {
159 if (m_pathShapeId.isEmpty()) {
160 return "ShapeLayerTypeCheck/" + m_shapeId;
161 }
162 return "ShapeLayerTypeCheck/" + m_shapeId + "/" + m_pathShapeId;
163 }
164
165 const QString m_shapeId;
166 const QString m_pathShapeId;
167};
168#endif // SHAPELAYERTYPECHECK_H
qreal v
The KisExportCheckBase class defines the interface of the individual checks of an export filter's cap...
virtual QString id() const
KisGroupLayerSP rootLayer() const
virtual bool visit(KisNode *node)=0
bool visitAll(KisNode *node, bool breakOnFail=false)
The position of a path point within a path shape.
Definition KoPathShape.h:63
QString shapeId() const
Definition KoShape.cpp:1057
QString id() const override
ShapeLayerTypeCheckFactory(const QString &ShapeId, const QString &PathShapeId="")
KisExportCheckBase * create(KisExportCheckBase::Level level, const QString &customWarning) override
bool visit(KisGeneratorLayer *) override
bool visit(KisColorizeMask *) override
bool visit(KisPaintLayer *) override
bool visit(KisExternalLayer *layer) override
bool visit(KisTransparencyMask *) override
bool visit(KisNode *) override
bool visit(KisAdjustmentLayer *) override
bool check(QList< KoShape * > shapes)
ShapeLayerTypeCheckVisitor(QString shapeId, QString pathId)
bool visit(KisGroupLayer *layer) override
bool visit(KisFilterMask *) override
bool visit(KisSelectionMask *) override
bool visit(KisTransformMask *) override
bool visit(KisCloneLayer *) override
bool checkNeeded(KisImageSP image) const override
Level check(KisImageSP) const override
ShapeLayerTypeCheck(const QString &ShapeId, const QString &PathShapeId, const QString &id, Level level, const QString &customWarning=QString())
bool accept(KisNodeVisitor &v) override