Commit d9c6c126 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Remove the use of the KisFilterGraph and KisFilterChain

We never supported chained input/output anyway; that is barely
useful for image files and would never perform well. This makes
the whole import/export system much simpler.

Plus, apparently all the chain stuff took some noticeable time
because the export dialogs now appear much, much quicker.
parent c1fa7d92
......@@ -282,10 +282,6 @@ class KisKeyframe;
typedef QSharedPointer<KisKeyframe> KisKeyframeSP;
typedef QWeakPointer<KisKeyframe> KisKeyframeWSP;
class KisFilterChain;
typedef KisSharedPtr<KisFilterChain> KisFilterChainSP;
struct KisProofingConfiguration;
typedef QSharedPointer<KisProofingConfiguration> KisProofingConfigurationSP;
typedef QWeakPointer<KisProofingConfiguration> KisProofingConfigurationWSP;
......
......@@ -320,15 +320,9 @@ set(kritaui_LIB_SRCS
KisNodeToolTip.cpp
KisNodeView.cpp
kis_node_view_color_scheme.cpp
KisFilterChain.cpp
KisFilterChainLink.cpp
KisFilterChainLinkList.cpp
KisImportExportFilter.cpp
KisFilterEdge.cpp
KisFilterEntry.cpp
KisFilterGraph.cpp
KisImportExportManager.cpp
KisFilterVertex.cpp
KisMainWindow.cpp
KisOpenPane.cpp
KisPart.cpp
......
......@@ -45,6 +45,7 @@
#include <KoUpdater.h>
#include <KoXmlWriter.h>
#include <KoXmlReader.h>
#include <KoStoreDevice.h>
#include <klocalizedstring.h>
#include <kis_debug.h>
......@@ -814,7 +815,7 @@ void KisDocument::setConfirmNonNativeSave(const bool exporting, const bool on)
bool KisDocument::fileBatchMode() const
{
return d->importExportManager->getBatchMode();
return d->importExportManager->batchMode();
}
void KisDocument::setFileBatchMode(const bool batchMode)
......@@ -2121,7 +2122,7 @@ KisNodeSP KisDocument::preActivatedNode() const
void KisDocument::setFileProgressUpdater(const QString &text)
{
d->suppressProgress = d->importExportManager->getBatchMode();
d->suppressProgress = d->importExportManager->batchMode();
if (!d->suppressProgress) {
d->progressUpdater = new KoProgressUpdater(d->progressProxy, KoProgressUpdater::Unthreaded);
......@@ -2146,7 +2147,7 @@ void KisDocument::clearFileProgressUpdater()
void KisDocument::setFileProgressProxy()
{
if (!d->progressProxy && !d->importExportManager->getBatchMode()) {
if (!d->progressProxy && !d->importExportManager->batchMode()) {
d->fileProgressProxy = progressProxy();
} else {
d->fileProgressProxy = 0;
......
This diff is collapsed.
/* This file is part of the Calligra libraries
Copyright (C) 2001 Werner Trobin <trobin@kde.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 KIS_FILTER_CHAIN_H
#define KIS_FILTER_CHAIN_H
#include <QHash>
#include <QList>
#include <QStringList>
#include <KoStoreDevice.h>
#include "kis_shared_ptr.h"
#include "KisFilterEntry.h"
#include "KisImportExportFilter.h"
#include "KisFilterChainLinkList.h"
#include "kis_shared.h"
#include "kritaui_export.h"
class QTemporaryFile;
class KisImportExportManager;
class KisDocument;
namespace CalligraFilter
{
class Graph;
class ChainLink;
class Vertex;
class Edge;
}
/**
* @brief This class represents a chain of plain @ref KisImportExportFilter instances.
*
* @author Werner Trobin <trobin@kde.org>
* @todo the class has no constructor and therefore cannot initialize its private class
*/
class KRITAUI_EXPORT KisFilterChain : public KisShared
{
public:
explicit KisFilterChain(const KisImportExportManager *manager);
virtual ~KisFilterChain();
/**
* The filter manager returned may be 0!
*/
const KisImportExportManager* manager() const {
return m_manager;
}
/**
* Starts the filtering process.
* @return The return status of the conversion. KisImportExportFilter::OK
* if everything is alright.
*/
KisImportExportFilter::ConversionStatus invokeChain();
/**
* Tells the @ref KisFilterManager the output file of the
* filter chain in case of an import operation. If it's
* an empty QString we directly manipulated the document.
*/
QString chainOutput() const;
/**
* Get the current file to read from. This part of the API
* is for the filters in our chain.
*/
QString inputFile();
/**
* Get the current file to write to. This part of the API
* is for the filters in our chain.
*/
QString outputFile();
void setOutputFile(const QString &outputFile);
/**
* This method allows your filter to work directly on the
* @ref KisDocument of the application.
* This part of the API is for the filters in our chain.
* @return The document containing the data. May return 0 on error.
*/
KisDocument *inputDocument();
/**
* This method allows your filter to work directly on the
* @ref KisDocument of the application.
* This part of the API is for the filters in our chain.
* @return The document you have to write to. May return 0 on error.
*/
KisDocument *outputDocument();
KisPropertiesConfigurationSP filterManagerExportConfiguration() const;
/// returns the amount of filters this chain contains representing the weight
int weight() const;
private:
// ### API for Calligra::Graph:
// Construct a filter chain belonging to some KisFilterManager.
// The parent filter manager may be 0.
friend class CalligraFilter::Graph;
friend class KisImportExportFilter;
friend class KisImportExportManager;
friend class CalligraFilter::ChainLink;
void prependChainLink(KisFilterEntrySP filterEntry, const QByteArray& from, const QByteArray& to);
// These methods are friends of KisFilterManager and provide access
// to a private part of its API. As I don't want to include
// koFilterManager.h in this header the direction is "int" here.
QString filterManagerImportFile() const;
QString filterManagerExportFile() const;
KisDocument* filterManagerKisDocument() const;
int filterManagerDirection() const;
// Helper methods which keep track of all the temp files and documents,
// and properly delete them as soon as they are not
// needed anymore.
void manageIO();
void finalizeIO();
bool createTempFile(QTemporaryFile** tempFile, bool autoDelete = true);
void inputFileHelper(KisDocument* document, const QString& alternativeFile);
void outputFileHelper(bool autoDelete);
// "A whole is that which has beginning, middle, and end" - Aristotle
// ...but we also need to signal "Done" state, Mr. Aristotle
enum Whole { Beginning = 1, Middle = 2, End = 4, Done = 8 };
// Don't copy or assign filter chains
KisFilterChain(const KisFilterChain& rhs);
KisFilterChain& operator=(const KisFilterChain& rhs);
const KisImportExportManager* const m_manager;
CalligraFilter::ChainLinkList m_chainLinks;
// stuff needed for bookkeeping
int m_state;
QString m_inputFile; // Did we pass around plain files?
QString m_outputFile;
KisDocument* m_inputDocument; // ...or even documents?
KisDocument* m_outputDocument;
QTemporaryFile* m_inputTempFile;
QTemporaryFile* m_outputTempFile;
// These two flags keep track of the input/output the
// filter (=user) asked for
enum IOState { Nil, File, Document };
IOState m_inputQueried, m_outputQueried;
class Private;
Private * const d;
};
#endif // __KO_FILTER_CHAIN_H__
/* This file is part of the Calligra libraries
Copyright (C) 2001 Werner Trobin <trobin@kde.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 "KisFilterChainLink.h"
#include <QMetaMethod>
#include <QPluginLoader>
#include <kis_debug.h>
#include "KisFilterEntry.h"
#include "KisImportExportManager.h"
#include "KoProgressUpdater.h"
#include "KoUpdater.h"
#include <QFile>
namespace
{
KoUpdater *createUpdater(KisFilterChainSP chain)
{
QPointer<KoUpdater> updater = 0;
Q_ASSERT(chain);
Q_ASSERT(chain->manager());
KoProgressUpdater *pu = chain->manager()->progressUpdater();
if (pu) {
updater = pu->startSubtask(1, "filter");
updater->setProgress(0);
}
return updater;
}
}
namespace CalligraFilter {
ChainLink::ChainLink(KisFilterChainSP chain, KisFilterEntrySP filterEntry,
const QByteArray& from, const QByteArray& to)
: m_chain(chain)
, m_filterEntry(filterEntry)
, m_from(from)
, m_to(to)
, m_filter(0)
, m_updater(createUpdater(chain))
{
}
ChainLink::~ChainLink() {
}
KisImportExportFilter::ConversionStatus ChainLink::invokeFilter()
{
if (!m_filterEntry) {
errFile << "This filter entry is null. Strange stuff going on." << endl;
return KisImportExportFilter::FilterEntryNull;
}
m_filter = m_filterEntry->createFilter(m_chain);
if (!m_filter) {
errFile << "Couldn't create the filter." << endl;
return KisImportExportFilter::FilterCreationError;
}
Q_ASSERT(m_updater);
if (m_updater) {
// if there is an updater, use that for progress reporting
m_filter->setUpdater(m_updater);
}
KisImportExportFilter::ConversionStatus status;
if (static_cast<KisImportExportManager::Direction>(m_chain->filterManagerDirection()) == KisImportExportManager::Export) {
m_filter->setMimeType(m_to);
KisDocument *doc = m_chain->inputDocument();
QFile fi(m_chain->outputFile());
if (!fi.open(QIODevice::WriteOnly)) {
status = KisImportExportFilter::CreationError;
}
else {
status = m_filter->convert(doc, &fi, m_chain->filterManagerExportConfiguration());
fi.close();
}
}
else {
KisDocument *doc = m_chain->outputDocument();
m_filter->setMimeType(m_from);
QFile fi(m_chain->inputFile());
if (!fi.exists() || !fi.open(QIODevice::ReadOnly)) {
status = KisImportExportFilter::FileNotFound;
}
else {
status = m_filter->convert(doc, &fi, m_chain->filterManagerExportConfiguration());
fi.close();
}
}
delete m_filter;
m_filter = 0;
if (m_updater) {
m_updater->setProgress(100);
}
return status;
}
void ChainLink::dump() const
{
dbgFile << " Link:" << m_filterEntry->loader()->fileName();
}
}
/* This file is part of the Calligra libraries
Copyright (C) 2001 Werner Trobin <trobin@kde.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 KISFILTERCHAINLINK_H
#define KISFILTERCHAINLINK_H
#include <KisFilterChain.h>
class QByteArray;
namespace CalligraFilter {
/**
* A small private helper class with represents one single filter
* (one link of the chain)
* @internal
*/
class ChainLink
{
public:
ChainLink(KisFilterChainSP chain, KisFilterEntrySP filterEntry,
const QByteArray& from, const QByteArray& to);
~ChainLink();
KisImportExportFilter::ConversionStatus invokeFilter();
QByteArray from() const {
return m_from;
}
QByteArray to() const {
return m_to;
}
// debugging
void dump() const;
QPointer<KoUpdater> updater() const {
return m_updater;
}
private:
ChainLink(const ChainLink& rhs);
ChainLink& operator=(const ChainLink& rhs);
KisFilterChainSP m_chain;
KisFilterEntrySP m_filterEntry;
QByteArray m_from, m_to;
// This hack is only needed due to crappy Microsoft design and
// circular dependencies in their embedded files :}
KisImportExportFilter *m_filter;
QPointer<KoUpdater> const m_updater;
};
}
#endif // KOFILTERCHAINLINK_H
/* This file is part of the Calligra libraries
Copyright (C) 2009 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 "KisFilterChainLinkList.h"
#include "KisFilterChainLink.h"
namespace CalligraFilter {
ChainLinkList::ChainLinkList() {}
ChainLinkList::~ChainLinkList()
{
deleteAll();
}
void ChainLinkList::deleteAll()
{
while(!m_chainLinks.isEmpty()) {
delete m_chainLinks.takeFirst();
}
}
int ChainLinkList::count() const
{
return m_chainLinks.count();
}
ChainLink* ChainLinkList::current() const
{
// use value() because m_current might be out of range for m_chainLinks
return m_chainLinks.value(m_current);
}
ChainLink* ChainLinkList::first()
{
m_current = 0;
return current();
}
ChainLink* ChainLinkList::next()
{
++m_current;
return current();
}
void ChainLinkList::prepend(ChainLink* link)
{
Q_ASSERT(link);
m_chainLinks.prepend(link);
m_current = 0;
}
void ChainLinkList::append(ChainLink* link)
{
Q_ASSERT(link);
m_chainLinks.append(link);
m_current = m_chainLinks.count() -1;
}
}
/* This file is part of the Calligra libraries
Copyright (C) 2009 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 KISFILTERCHAINLINKLIST_H
#define KISFILTERCHAINLINKLIST_H
#include <QList>
namespace CalligraFilter {
class ChainLink;
class ChainLinkList
{
public:
ChainLinkList();
~ChainLinkList();
void deleteAll();
int count() const;
/**
* Return a pointer to the current position in the chain.
* @return pointer to the current ChainLink or 0 if the ChainLinkList is empty.
**/
ChainLink* current() const;
/**
* Move the position to the first position in the chain.
* @return pointer to the first ChainLink or 0 if the ChainLinkList is empty.
**/
ChainLink* first();
ChainLink* next();
void prepend(ChainLink* link);
void append(ChainLink* link);
private:
QList<ChainLink*> m_chainLinks;
int m_current;
};
}
#endif // KOFILTERCHAINLINKLIST_H
/* This file is part of the Calligra libraries
Copyright (C) 2001 Werner Trobin <trobin@kde.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 "KisFilterEdge.h"
#include "KisFilterVertex.h"
#include "PriorityQueue_p.h"
namespace CalligraFilter {
Edge::Edge(Vertex* vertex, KisFilterEntrySP filterEntry) :
m_vertex(vertex), m_filterEntry(filterEntry), d(0)
{
}
void Edge::relax(const Vertex* predecessor, PriorityQueue<Vertex>& queue)
{
if (!m_vertex || !predecessor || !m_filterEntry)
return;
if (m_vertex->setKey(predecessor->key() + m_filterEntry->weight)) {
queue.keyDecreased(m_vertex); // maintain the heap property
m_vertex->setPredecessor(predecessor);
}
}
void Edge::dump(const QByteArray& indent) const
{
if (m_vertex)
dbgFile << indent << "Edge -> '" << m_vertex->mimeType()
<< "' (" << m_filterEntry->weight << ")" << endl;
else
dbgFile << indent << "Edge -> '(null)' ("
<< m_filterEntry->weight << ")" << endl;
}
}
/* This file is part of the Calligra libraries
Copyright (C) 2001 Werner Trobin <trobin@kde.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 KISFILTEREDGE_H
#define KISFILTEREDGE_H
#include "KisFilterChain.h"
#include "PriorityQueue_p.h"
namespace CalligraFilter {
/**
* An internal class representing a filter (=edge) in the filter graph.
* @internal
*/
class Edge
{
public:
// creates a new edge to "vertex" with the given weight.
Edge(Vertex* vertex, KisFilterEntrySP filterEntry);
~Edge() {}
unsigned int weight() const {
return m_filterEntry ? m_filterEntry->weight : 0;
}
KisFilterEntrySP filterEntry() const {
return m_filterEntry;
}
const Vertex* vertex() const {
return m_vertex;
}
// Relaxes the "connected" vertex (i.e. the weight of the
// connected vertex = "predec.->key()" (parameter) + weight of this edge
// As this will only be called once we calculate the weight
// of the edge "on the fly"
// Note: We have to pass the queue as we have to call keyDecreased :}
void relax(const Vertex* predecessor, PriorityQueue<Vertex>& queue);
// debugging
void dump(const QByteArray& indent) const;
private:
Edge(const Edge& rhs);
Edge& operator=(const Edge& rhs);
Vertex* m_vertex;
KisFilterEntrySP m_filterEntry;
class Private;
Private * const d;
};
}
#endif // KOFILTEREDGE_H
......@@ -27,7 +27,6 @@ Boston, MA 02110-1301, USA.
#include <KoJsonTrader.h>
#include <kpluginfactory.h>
#include <QFile>
#include <KisFilterChain.h>
#include <limits.h> // UINT_MAX
......@@ -64,7 +63,7 @@ QList<KisFilterEntrySP> KisFilterEntry::query()
return lst;
}
KisImportExportFilter* KisFilterEntry::createFilter(KisFilterChainSP chain)
KisImportExportFilter* KisFilterEntry::createFilter()
{
KLibFactory *factory = qobject_cast<KLibFactory *>(m_loader->instance());