Krita Source Code Documentation
Loading...
Searching...
No Matches
ColorModelPerLayerCheck.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef ColorModelPerLayerCHECK_H
8#define ColorModelPerLayerCHECK_H
9
11#include <KoID.h>
12#include <klocalizedstring.h>
13#include <kis_image.h>
14#include <KoColorSpace.h>
16#include <kis_layer.h>
17#include <kis_node_visitor.h>
18#include "kis_node.h"
19#include "kis_paint_layer.h"
20#include "kis_group_layer.h"
23#include "kis_clone_layer.h"
25
27{
28public:
29
31
32 KisColorModelCheckVisitor (KoID colorModelID, KoID colorDepthID)
33 : m_count(0)
34 , m_colorModelID(colorModelID)
35 , m_colorDepthID(colorDepthID)
36 {
37 }
38
39 quint32 count() {
40 return m_count;
41 }
42
43 bool visit(KisNode* node) override {
44 return check(node);
45 }
46
47 bool visit(KisPaintLayer *layer) override {
48 return check(layer);
49 }
50
51 bool visit(KisGroupLayer *layer) override {
52 return check(layer);
53 }
54
55
56 bool visit(KisAdjustmentLayer *layer) override {
57 return check(layer);
58 }
59
60 bool visit(KisExternalLayer *layer) override {
61 return check(layer);
62 }
63
64 bool visit(KisCloneLayer *layer) override {
65 return check(layer);
66 }
67
68 bool visit(KisGeneratorLayer * layer) override {
69 return check(layer);
70 }
71
72 bool visit(KisFilterMask *) override {return true;}
73
74 bool visit(KisTransformMask *) override {return true;}
75
76 bool visit(KisTransparencyMask *) override {return true;}
77
78 bool visit(KisSelectionMask *) override {return true;}
79
80 bool visit(KisColorizeMask *) override {return true;}
81
82
83private:
84 bool check(KisNode * node)
85 {
86 KisLayer *layer = dynamic_cast<KisLayer*>(node);
87 if (layer) {
88 const KoColorSpace * cs = layer->colorSpace();
89 if (cs->colorModelId() == m_colorModelID && cs->colorDepthId() == m_colorDepthID) {
90 m_count++;
91 }
92 }
93 visitAll(node);
94 return true;
95 }
96
97 quint32 m_count;
100
101};
102
104{
105public:
106
107 ColorModelPerLayerCheck(const KoID &colorModelID, const KoID &colorDepthID, const QString &id, Level level, const QString &customWarning = QString())
108 : KisExportCheckBase(id, level, customWarning, true)
109 , m_ColorModelID(colorModelID)
110 , m_colorDepthID(colorDepthID)
111 {
112 Q_ASSERT(!colorModelID.name().isEmpty());
113 Q_ASSERT(!colorDepthID.name().isEmpty());
114
115 if (customWarning.isEmpty()) {
116 m_warning = i18nc("image conversion warning", "Your image contains layers with the color model <b>%1</b> and channel depth <b>%2</b> which cannot be saved to this format. The layers will be converted."
119 }
120 }
121
122 bool checkNeeded(KisImageSP image) const override
123 {
125 image->rootLayer()->accept(v);
126 return (v.count() > 0);
127 }
128
129 Level check(KisImageSP /*image*/) const override
130 {
131 return m_level;
132 }
133
136};
137
139{
140public:
141
142 ColorModelPerLayerCheckFactory(const KoID &ColorModelID, const KoID &colorDepthId)
143 : m_colorModelID(ColorModelID)
144 , m_colorDepthID(colorDepthId)
145 {
146 }
147
149
150 KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
151 {
152 return new ColorModelPerLayerCheck(m_colorModelID, m_colorDepthID, id(), level, customWarning);
153 }
154
155 QString id() const override {
156 return "ColorModelPerLayerCheck/" + m_colorModelID.id() + "/" + m_colorDepthID.id();
157 }
158
161};
162
163#endif // ColorModelPerLayerCHECK_H
qreal v
KisExportCheckBase * create(KisExportCheckBase::Level level, const QString &customWarning) override
ColorModelPerLayerCheckFactory(const KoID &ColorModelID, const KoID &colorDepthId)
Level check(KisImageSP) const override
ColorModelPerLayerCheck(const KoID &colorModelID, const KoID &colorDepthID, const QString &id, Level level, const QString &customWarning=QString())
bool checkNeeded(KisImageSP image) const override
bool visit(KisCloneLayer *layer) override
bool visit(KisGroupLayer *layer) override
bool visit(KisFilterMask *) override
bool visit(KisExternalLayer *layer) override
bool visit(KisNode *node) override
KisColorModelCheckVisitor(KoID colorModelID, KoID colorDepthID)
bool visit(KisColorizeMask *) override
bool visit(KisGeneratorLayer *layer) override
bool visit(KisTransformMask *) override
bool visit(KisAdjustmentLayer *layer) override
bool visit(KisSelectionMask *) override
bool visit(KisPaintLayer *layer) override
bool visit(KisTransparencyMask *) override
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)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
Definition KoID.h:30
QString name() const
Definition KoID.cpp:68
QString id() const
Definition KoID.cpp:63
bool accept(KisNodeVisitor &v) override
const KoColorSpace * colorSpace() const override
returns the image's colorSpace or null, if there is no image
Definition kis_layer.cc:225