1 /* 2 * Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef NodeTypeCheck_H 21 #define NodeTypeCheck_H 22 23 #include "KisExportCheckRegistry.h" 24 #include <KoID.h> 25 #include <klocalizedstring.h> 26 #include <kis_image.h> 27 #include <kis_count_visitor.h> 28 29 class NodeTypeCheck : public KisExportCheckBase 30 { 31 public: 32 33 NodeTypeCheck(const QString &nodeType, const QString &description, const QString &id, Level level, const QString &customWarning = QString()) KisExportCheckBase(id,level,customWarning,true)34 : KisExportCheckBase(id, level, customWarning, true) 35 , m_nodeType(nodeType) 36 { 37 if (customWarning.isEmpty()) { 38 m_warning = i18nc("image conversion warning", "The image contains layers of unsupported type <b>%1</b>. Only the rendered result will be saved.", description); 39 } 40 } 41 checkNeeded(KisImageSP image)42 bool checkNeeded(KisImageSP image) const override 43 { 44 QStringList nodetypes = QStringList() << m_nodeType; 45 KoProperties props; 46 KisCountVisitor v(nodetypes, props); 47 image->rootLayer()->accept(v); 48 49 // There is always one group layer, the root layer. 50 if (m_nodeType == "KisGroupLayer") { 51 return (v.count() > 1); 52 } 53 else { 54 return (v.count() > 0); 55 } 56 } 57 check(KisImageSP)58 Level check(KisImageSP /*image*/) const override 59 { 60 return m_level; 61 } 62 63 QString m_nodeType; 64 }; 65 66 class NodeTypeCheckFactory : public KisExportCheckFactory 67 { 68 public: 69 NodeTypeCheckFactory(const QString & nodeType,const QString & description)70 NodeTypeCheckFactory(const QString &nodeType, const QString &description) 71 : m_nodeType(nodeType) 72 , m_description(description) 73 {} 74 ~NodeTypeCheckFactory()75 ~NodeTypeCheckFactory() override {} 76 create(KisExportCheckBase::Level level,const QString & customWarning)77 KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override 78 { 79 return new NodeTypeCheck(m_nodeType, m_description, id(), level, customWarning); 80 } 81 id()82 QString id() const override { 83 return "NodeTypeCheck/" + m_nodeType; 84 } 85 86 QString m_nodeType; 87 QString m_description; 88 89 }; 90 91 #endif // NodeTypeCheck_H 92