Commit fb456280 authored by Halla Rempt's avatar Halla Rempt

Hide the FilterChain from the filter implementations

parent 83a3da29
......@@ -45,6 +45,31 @@ KisImportExportFilter::KisImportExportFilter(QObject *parent)
{
}
KisDocument *KisImportExportFilter::inputDocument() const
{
return m_chain->inputDocument();
}
KisDocument *KisImportExportFilter::outputDocument() const
{
return m_chain->outputDocument();
}
QString KisImportExportFilter::inputFile() const
{
return m_chain->inputFile();
}
QString KisImportExportFilter::outputFile() const
{
return m_chain->outputFile();
}
bool KisImportExportFilter::getBatchMode() const
{
return m_chain->manager()->getBatchMode();
}
KisImportExportFilter::~KisImportExportFilter()
{
Q_ASSERT(d->updater);
......
......@@ -26,8 +26,10 @@ Boston, MA 02110-1301, USA.
#include <QPointer>
#include "kritaui_export.h"
class KisFilterChain;
class KoUpdater;
class KisDocument;
/**
* @brief The base class for import and export filters.
......@@ -112,6 +114,13 @@ protected:
*/
KisImportExportFilter(QObject *parent = 0);
KisDocument *inputDocument() const;
KisDocument *outputDocument() const;
QString inputFile() const;
QString outputFile() const;
bool getBatchMode() const;
private:
/**
* Use this pointer to access all information about input/output
* during the conversion. @em Don't use it in the constructor -
......
......@@ -47,8 +47,8 @@ KisImportExportFilter::ConversionStatus KisBMPExport::convert(const QByteArray&
{
dbgFile << "BMP export! From:" << from << ", To:" << to << "";
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......
......@@ -56,12 +56,12 @@ KisImportExportFilter::ConversionStatus KisBMPImport::convert(const QByteArray&
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc->prepareForImport();
......
......@@ -64,8 +64,8 @@ KisBrushExport::~KisBrushExport()
KisImportExportFilter::ConversionStatus KisBrushExport::convert(const QByteArray& from, const QByteArray& to)
{
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......@@ -97,7 +97,7 @@ KisImportExportFilter::ConversionStatus KisBrushExport::convert(const QByteArray
}
KisGbrBrush *brush;
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
KoDialog* dlgBrushExportOptions = new KoDialog(0);
dlgBrushExportOptions->setWindowTitle(i18n("Brush Tip Export Options"));
......
......@@ -61,7 +61,7 @@ KisImportExportFilter::ConversionStatus KisBrushImport::convert(const QByteArray
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
QString filename = m_chain->inputFile();
QString filename = inputFile();
if (!filename.isEmpty()) {
......@@ -93,7 +93,7 @@ KisImportExportFilter::ConversionStatus KisBrushImport::convert(const QByteArray
return KisImportExportFilter::InvalidFormat;
}
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc) {
delete brush;
......
......@@ -71,14 +71,14 @@ KisImportExportFilter::ConversionStatus KisCSVExport::convert(const QByteArray&
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument* input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument* input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
if (!checkHomogenity(input->image()->rootLayer())) {
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
QMessageBox::critical(0,
i18nc("@title:window", "CSV Export Error"),
i18n("Unable to save to the CSV format.\n"
......
......@@ -49,12 +49,12 @@ KisImportExportFilter::ConversionStatus KisCSVImport::convert(const QByteArray&,
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc -> prepareForImport();
......
......@@ -62,7 +62,7 @@ KisImportExportFilter::ConversionStatus exrExport::convert(const QByteArray& fro
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
KisDocument *input = inputDocument();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
KisImageWSP image = input->image();
......@@ -83,7 +83,7 @@ KisImportExportFilter::ConversionStatus exrExport::convert(const QByteArray& fro
widget.flatten->setChecked(cfg.getBool("flatten", false));
if (!m_chain->manager()->getBatchMode() ) {
if (!getBatchMode() ) {
QApplication::restoreOverrideCursor();
if (dialog.exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
......@@ -97,12 +97,12 @@ KisImportExportFilter::ConversionStatus exrExport::convert(const QByteArray& fro
cfg.setProperty("flatten", widget.flatten->isChecked());
KisConfig().setExportConfiguration("EXR", cfg);
QString filename = m_chain->outputFile();
QString filename = outputFile();
if (filename.isEmpty()) return KisImportExportFilter::FileNotFound;
QUrl url = QUrl::fromLocalFile(filename);
exrConverter kpc(input, !m_chain->manager()->getBatchMode());
exrConverter kpc(input, !getBatchMode());
KisImageBuilder_Result res;
......
......@@ -47,12 +47,12 @@ KisImportExportFilter::ConversionStatus exrImport::convert(const QByteArray&, co
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc->prepareForImport();
......@@ -63,7 +63,7 @@ KisImportExportFilter::ConversionStatus exrImport::convert(const QByteArray&, co
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
exrConverter ib(doc, !m_chain->manager()->getBatchMode());
exrConverter ib(doc, !getBatchMode());
switch (ib.buildImage(url)) {
......
......@@ -63,8 +63,8 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *inputDoc = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *inputDoc = inputDocument();
QString filename = outputFile();
if (!inputDoc)
return KisImportExportFilter::NoDocumentCreated;
......@@ -111,7 +111,7 @@ KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteA
optionsHeightMap.radioMac->setChecked(true);
}
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
}
......
......@@ -63,7 +63,7 @@ KisHeightMapImport::~KisHeightMapImport()
KisImportExportFilter::ConversionStatus KisHeightMapImport::convert(const QByteArray& from, const QByteArray& to)
{
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc) {
return KisImportExportFilter::NoDocumentCreated;
......@@ -86,7 +86,7 @@ KisImportExportFilter::ConversionStatus KisHeightMapImport::convert(const QByteA
return KisImportExportFilter::BadMimeType;
}
QString filename = m_chain->inputFile();
QString filename = inputFile();
if (filename.isEmpty()) {
return KisImportExportFilter::FileNotFound;
......@@ -143,7 +143,7 @@ KisImportExportFilter::ConversionStatus KisHeightMapImport::convert(const QByteA
optionsHeightMap.radioPC->setChecked(true);
}
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
}
......
......@@ -61,8 +61,8 @@ KisImportExportFilter::ConversionStatus jp2Export::convert(const QByteArray& fro
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......@@ -90,7 +90,7 @@ KisImportExportFilter::ConversionStatus jp2Export::convert(const QByteArray& fro
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
}
......
......@@ -45,12 +45,12 @@ KisImportExportFilter::ConversionStatus jp2Import::convert(const QByteArray&, co
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc->prepareForImport();
......
......@@ -72,7 +72,7 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
KisDocument *input = inputDocument();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......@@ -128,7 +128,7 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
delete kdb;
return KisImportExportFilter::UserCancelled;
......@@ -191,7 +191,7 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
delete kdb;
// XXX: Add dialog about flattening layers here
QString filename = m_chain->outputFile();
QString filename = outputFile();
if (filename.isEmpty()) return KisImportExportFilter::FileNotFound;
......@@ -200,7 +200,7 @@ KisImportExportFilter::ConversionStatus KisJPEGExport::convert(const QByteArray&
image->refreshGraph();
image->lock();
KisJPEGConverter kpc(input, m_chain->manager()->getBatchMode());
KisJPEGConverter kpc(input, getBatchMode());
KisPaintDeviceSP pd = new KisPaintDevice(*image->projection());
image->unlock();
......
......@@ -48,12 +48,12 @@ KisImportExportFilter::ConversionStatus KisJPEGImport::convert(const QByteArray&
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc->prepareForImport();
......@@ -64,7 +64,7 @@ KisImportExportFilter::ConversionStatus KisJPEGImport::convert(const QByteArray&
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
KisJPEGConverter ib(doc, m_chain->manager()->getBatchMode());
KisJPEGConverter ib(doc, getBatchMode());
// if (view != 0)
// view -> canvasSubject() -> progressDisplay() -> setSubject(&ib, false, true);
......
......@@ -59,12 +59,12 @@ KisImportExportFilter::ConversionStatus KisODGImport::convert(const QByteArray&
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
KoStore* store = KoStore::createStore(filename, KoStore::Read, from, KoStore::Zip);
if (!store || store->bad()) {
......
......@@ -79,8 +79,8 @@ KisImportExportFilter::ConversionStatus OraExport::convert(const QByteArray& fro
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......@@ -102,14 +102,14 @@ KisImportExportFilter::ConversionStatus OraExport::convert(const QByteArray& fro
supportedColorDepthIds << Integer8BitsColorDepthID.id() << Integer16BitsColorDepthID.id();
if (!supportedColorModelIds.contains(pd->colorSpace()->colorModelId().id()) ||
!supportedColorDepthIds.contains(pd->colorSpace()->colorDepthId().id())) {
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
QMessageBox::critical(0, i18nc("@title:window", "Krita OpenRaster Export"), i18n("Cannot export images in this colorspace or channel depth to OpenRaster"));
}
return KisImportExportFilter::UsageError;
}
if (hasShapeLayerChild(image->root()) && !m_chain->manager()->getBatchMode()) {
if (hasShapeLayerChild(image->root()) && !getBatchMode()) {
QMessageBox::information(0,
i18nc("@title:window", "Krita:Warning"),
i18n("This image contains vector, clone or fill layers.\nThese layers will be saved as raster layers."));
......
......@@ -44,12 +44,12 @@ KisImportExportFilter::ConversionStatus OraImport::convert(const QByteArray&, co
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc->prepareForImport();
......
......@@ -66,7 +66,7 @@ KisPDFImport::~KisPDFImport()
KisPDFImport::ConversionStatus KisPDFImport::convert(const QByteArray& , const QByteArray&)
{
QString filename = m_chain->inputFile();
QString filename = inputFile();
dbgFile << "Importing using PDFImport!" << filename;
if (filename.isEmpty())
......@@ -118,7 +118,7 @@ KisPDFImport::ConversionStatus KisPDFImport::convert(const QByteArray& , const Q
}
// Init kis's doc
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc) {
delete pdoc;
delete kdb;
......@@ -135,7 +135,7 @@ KisPDFImport::ConversionStatus KisPDFImport::convert(const QByteArray& , const Q
// create a layer
QList<int> pages = wdg->pages();
QPointer<KoUpdater> loadUpdater = m_chain->outputDocument()->progressUpdater()->startSubtask(1, "load");
QPointer<KoUpdater> loadUpdater = outputDocument()->progressUpdater()->startSubtask(1, "load");
loadUpdater->setRange(0, pages.count());
for (QList<int>::const_iterator it = pages.constBegin(); it != pages.constEnd(); ++it) {
KisPaintLayer* layer = new KisPaintLayer(image.data(),
......
......@@ -73,8 +73,8 @@ KisImportExportFilter::ConversionStatus KisPNGExport::convert(const QByteArray&
dbgFile << "Png export! From:" << from << ", To:" << to << "";
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......@@ -105,7 +105,7 @@ KisImportExportFilter::ConversionStatus KisPNGExport::convert(const QByteArray&
if (!KisPNGConverter::isColorSpaceSupported(pd->colorSpace())) {
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
QMessageBox::critical(0, i18nc("@title:window", "Krita PNG Export"), i18n("You can only save grayscale and RGB images to PNG. Convert your image before exporting to PNG."));
}
return KisImportExportFilter::UsageError;
......@@ -171,7 +171,7 @@ KisImportExportFilter::ConversionStatus KisPNGExport::convert(const QByteArray&
kdb->setMainWidget(wdg);
QApplication::restoreOverrideCursor();
if (hasVisibleWidgets()) {
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
}
......
......@@ -49,12 +49,12 @@ KisImportExportFilter::ConversionStatus KisPNGImport::convert(const QByteArray&,
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc -> prepareForImport();
......@@ -65,7 +65,7 @@ KisImportExportFilter::ConversionStatus KisPNGImport::convert(const QByteArray&,
if (url.isEmpty())
return KisImportExportFilter::FileNotFound;
KisPNGConverter ib(doc, m_chain->manager()->getBatchMode());
KisPNGConverter ib(doc, getBatchMode());
// if (view != 0)
// view -> canvasSubject() -> progressDisplay() -> setSubject(&ib, false, true);
......
......@@ -143,8 +143,8 @@ KisImportExportFilter::ConversionStatus KisPPMExport::convert(const QByteArray&
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
......@@ -169,7 +169,7 @@ KisImportExportFilter::ConversionStatus KisPPMExport::convert(const QByteArray&
optionsPPM.type->setCurrentIndex(cfg.getInt("type", 0));
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
if (kdb->exec() == QDialog::Rejected) {
return KisImportExportFilter::UserCancelled;
}
......
......@@ -61,12 +61,12 @@ KisImportExportFilter::ConversionStatus KisPPMImport::convert(const QByteArray&
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
if (filename.isEmpty()) {
return KisImportExportFilter::FileNotFound;
......
......@@ -79,15 +79,15 @@ KisImportExportFilter::ConversionStatus psdExport::convert(const QByteArray& fro
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
if (!input)
return KisImportExportFilter::NoDocumentCreated;
if (input->image()->width() > 30000 || input->image()->height() > 30000) {
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
QMessageBox::critical(0,
i18nc("@title:window", "Photoshop Export Error"),
i18n("Unable to save to the Photoshop format.\n"
......@@ -98,7 +98,7 @@ KisImportExportFilter::ConversionStatus psdExport::convert(const QByteArray& fro
if (!checkHomogenity(input->image()->rootLayer(), input->image()->colorSpace())) {
if (!m_chain->manager()->getBatchMode()) {
if (!getBatchMode()) {
QMessageBox::critical(0,
i18nc("@title:window", "Photoshop Export Error"),
i18n("Unable to save to the Photoshop format.\n"
......
......@@ -44,12 +44,12 @@ KisImportExportFilter::ConversionStatus psdImport::convert(const QByteArray&, co
if (to != "application/x-krita")
return KisImportExportFilter::BadMimeType;
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc)
return KisImportExportFilter::NoDocumentCreated;
QString filename = m_chain->inputFile();
QString filename = inputFile();
doc->prepareForImport();
......
......@@ -48,8 +48,8 @@ KisImportExportFilter::ConversionStatus QMLExport::convert(const QByteArray& fro
if (from != "application/x-krita")
return KisImportExportFilter::NotImplemented;
KisDocument *input = m_chain->inputDocument();
QString filename = m_chain->outputFile();
KisDocument *input = inputDocument();
QString filename = outputFile();
dbgKrita << "input " << input;
if (!input) {
......
......@@ -77,14 +77,14 @@ KisImportExportFilter::ConversionStatus KisRawImport::convert(const QByteArray&
dbgFile << "Krita importing from Raw";
KisDocument * doc = m_chain->outputDocument();
KisDocument * doc = outputDocument();
if (!doc) {
return KisImportExportFilter::NoDocumentCreated; </