Commit 14ee3a70 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add initial framework for the export capabilities checker

See https://phabricator.kde.org/T3535 for the design
parent 00e51452
......@@ -14,6 +14,7 @@ add_subdirectory( psd )
add_subdirectory( color )
add_subdirectory( image )
add_subdirectory( ui )
add_subdirectory( impex )
if (SHOULD_BUILD_LIB_KOVECTORIMAGE)
add_subdirectory( vectorimage )
......
......@@ -79,7 +79,7 @@ class KRITAIMAGE_EXPORT KisImage : public QObject,
public:
/// @param colorSpace can be null. in that case it will be initialised to a default color space.
KisImage(KisUndoStore *undoStore, qint32 width, qint32 height, const KoColorSpace * colorSpace, const QString& name);
KisImage(KisUndoStore *undoStore, qint32 width, qint32 height, const KoColorSpace *colorSpace, const QString& name);
virtual ~KisImage();
public: // KisNodeGraphListener implementation
......
set(kritaimpex_LIB_SRCS
KisExportCheckBase.cpp
KisExportConverterBase.cpp
KisPreExportChecker.cpp
)
add_library(kritaimpex SHARED ${kritaimpex_HEADERS_MOC} ${kritaimpex_LIB_SRCS} )
generate_export_header(kritaimpex BASE_NAME kritaimpex)
target_link_libraries(kritaimpex KF5::CoreAddons KF5::I18n kritaimage
)
set_target_properties(kritaimpex
PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION}
)
install(TARGETS kritaimpex ${INSTALL_TARGETS_DEFAULT_ARGS})
/* This file is part of the KDE project
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisExportCheckBase.h"
#include "KisExportConverterBase.h"
KisExportCheckBase::KisExportCheckBase(Level level, const QString &customWarning)
: m_level(level)
, m_converter(0)
{
if (!customWarning.isEmpty()) {
m_message = customWarning;
}
}
KisExportCheckBase::~KisExportCheckBase()
{
delete m_converter;
}
KisExportConverterBase *KisExportCheckBase::converter() const
{
return m_converter;
}
QString KisExportCheckBase::message() const
{
return m_message;
}
/* This file is part of the KDE project
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISEXPORTCHECKBASE_H
#define KISEXPORTCHECKBASE_H
#include <kis_types.h>
#include <QString>
#include "kritaimpex_export.h"
class KisExportConverterBase;
/**
* @brief The KisExportCheckBase class defines the interface
* of the individual checks of an export filter's capabilities
*/
class KRITAIMPEX_EXPORT KisExportCheckBase
{
public:
/// The level determines the level of support the export
/// filter has for the given feature.
enum Level {
SUPPORTED, //< The filter fully supports this
PARTIALLY, //< The filter can handle this, but the user needs to be warned about possible degradation
UNSUPPORTED //< This cannot be saved using this filter
};
/**
* @brief KisExportCheckBase
* @param level the level of support the filter has for the given feature
* @param customWarning A custom warning to use instead of the default one
*/
KisExportCheckBase(Level level, const QString &customWarning = QString());
virtual ~KisExportCheckBase();
/// @return the unique id of the check
virtual QString id() const = 0;
/// @return whether the image uses this feature
virtual bool checkNeeded(KisImageSP image) const = 0;
/// @return the level of support for this feature
virtual Level check(KisImageSP image) const = 0;
/// @return the message to show the user
QString message() const;
KisExportConverterBase *converter() const;
private:
Level m_level;
QString m_message;
KisExportConverterBase *m_converter;
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisExportConverterBase.h"
/* This file is part of the KDE project
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISEXPORTCONVERTERBASE_H
#define KISEXPORTCONVERTERBASE_H
#include <kis_types.h>
#include "kritaimpex_export.h"
/**
* @brief The KisExportConverterBase class defines the interface
* of converter classes that can convert an aspect of an image
* before exporting.
*/
class KRITAIMPEX_EXPORT KisExportConverterBase
{
public:
KisExportConverterBase();
virtual ~KisExportConverterBase();
virtual QString id() const = 0;
virtual bool convert(KisImageSP image) const = 0;
virtual int priority() const = 0;
};
#endif // KISEXPORTCONVERTERBASE_H
/* This file is part of the KDE project
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisPreExportChecker.h"
#include "KisExportCheckBase.h"
#include "KisExportConverterBase.h"
#include <kis_image.h>
KisPreExportChecker::KisPreExportChecker()
{
initializeChecks();
}
void KisPreExportChecker::check(KisImageSP image, QMap<QString, KisExportCheckBase*> filterChecks)
{
Q_FOREACH(const KisExportCheckBase *check, m_checks) {
if (check->checkNeeded(image)) {
if (!filterChecks.contains(check->id())) {
m_warnings << check->message();
}
else if (filterChecks[check->id()]->check(image) != KisExportCheckBase::SUPPORTED) {
m_warnings << filterChecks[check->id()]->message();
}
else {
continue;
}
if (check->converter()) {
m_conversions[check->converter()->id()] = check->converter();
}
}
}
}
KisImageSP KisPreExportChecker::convertedImage(KisImageSP originalImage) const
{
// Sort the conversions on priority
// Copy the image
// KisImageSP copy = new KisImage(originalImage.data());
// Apply the conversions
Q_FOREACH(KisExportConverterBase *converter, m_conversions.values()) {
if (!converter->convert(originalImage)) {
qDebug() << "Failed to apply conversion" << converter->id();
return 0;
}
}
return originalImage;
}
QStringList KisPreExportChecker::warnings() const
{
return m_warnings;
}
bool KisPreExportChecker::conversionNeeded() const
{
return !m_conversions.isEmpty();
}
void KisPreExportChecker::initializeChecks()
{
// ...
}
/* This file is part of the KDE project
* Copyright (C) 2016 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISPREEXPORTCHECKER_H
#define KISPREEXPORTCHECKER_H
#include <kis_types.h>
#include "kritaimpex_export.h"
class KisExportCheckBase;
class KisExportConverterBase;
class KRITAIMPEX_EXPORT KisPreExportChecker
{
public:
KisPreExportChecker();
void check(KisImageSP image, QMap<QString, KisExportCheckBase *> filterChecks);
KisImageSP convertedImage(KisImageSP) const;
QStringList warnings() const;
bool conversionNeeded() const;
private:
void initializeChecks();
QMap<QString, KisExportCheckBase*> m_checks;
QStringList m_warnings;
QMap<QString, KisExportConverterBase*> m_conversions;
};
#endif // KISPREEXPORTCHECKER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment