File indexing completed on 2024-05-12 15:59:02

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef NodeTypeCheck_H
0008 #define NodeTypeCheck_H
0009 
0010 #include "KisExportCheckRegistry.h"
0011 #include <KoID.h>
0012 #include <klocalizedstring.h>
0013 #include <kis_image.h>
0014 #include <kis_count_visitor.h>
0015 
0016 class NodeTypeCheck : public KisExportCheckBase
0017 {
0018 public:
0019 
0020     NodeTypeCheck(const QString &nodeType, const QString &description, const QString &id, Level level, const QString &customWarning = QString())
0021         : KisExportCheckBase(id, level, customWarning, true)
0022         , m_nodeType(nodeType)
0023     {
0024         if (customWarning.isEmpty()) {
0025             m_warning = i18nc("image conversion warning", "The image contains layers of unsupported type <b>%1</b>. Only the rendered result will be saved.", description);
0026         }
0027     }
0028 
0029     bool checkNeeded(KisImageSP image) const override
0030     {
0031         QStringList nodetypes = QStringList() << m_nodeType;
0032         KoProperties props;
0033         KisCountVisitor v(nodetypes, props);
0034         image->rootLayer()->accept(v);
0035 
0036         // There is always one group layer, the root layer.
0037         if (m_nodeType == "KisGroupLayer") {
0038             return (v.count() > 1);
0039         }
0040         else {
0041             return (v.count() > 0);
0042         }
0043     }
0044 
0045     Level check(KisImageSP /*image*/) const override
0046     {
0047         return m_level;
0048     }
0049 
0050     QString m_nodeType;
0051 };
0052 
0053 class NodeTypeCheckFactory : public KisExportCheckFactory
0054 {
0055 public:
0056 
0057     NodeTypeCheckFactory(const QString &nodeType, const QString &description)
0058         : m_nodeType(nodeType)
0059         , m_description(description)
0060     {}
0061 
0062     ~NodeTypeCheckFactory() override {}
0063 
0064     KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
0065     {
0066         return new NodeTypeCheck(m_nodeType, m_description, id(), level, customWarning);
0067     }
0068 
0069     QString id() const override {
0070         return "NodeTypeCheck/" + m_nodeType;
0071     }
0072 
0073     QString m_nodeType;
0074     QString m_description;
0075 
0076 };
0077 
0078 #endif // NodeTypeCheck_H