Commit a0379dbb authored by Cyrille Berger's avatar Cyrille Berger

split the visitors into an header file and a source file

svn path=/trunk/koffice/; revision=663672
parent 0ab03e4f
......@@ -57,7 +57,9 @@ set(kritaui_LIB_SRCS
kis_label_progress.cc
kis_label_zoom.cc
kis_layer_manager.cc
kis_layermap_visitor.cc
kis_layerbox.cc
kis_load_visitor.cc
kis_matrix_widget.cpp
kis_multi_bool_filter_widget.cc
kis_multi_double_filter_widget.cc
......@@ -78,6 +80,8 @@ set(kritaui_LIB_SRCS
kis_resource_mediator.cc
kis_resource_provider.cc
kis_resourceserver.cc
kis_save_visitor.cc
kis_savexml_visitor.cc
kis_selection_manager.cc
kis_selection_options.cc
kis_statusbar.cc
......
......@@ -59,10 +59,12 @@
#include <KoSelection.h>
// Krita Image
#include "kis_types.h"
#include "kis_adjustment_layer.h"
#include "kis_annotation.h"
#include "kis_debug_areas.h"
#include "kis_exif_info.h"
#include "kis_fill_painter.h"
#include "kis_group_layer.h"
#include "kis_image.h"
#include "kis_layer.h"
#include "kis_paint_device_action.h"
......
/*
* Copyright (c) 2006 Boudewijn Rempt (boud@valdyas.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <kis_layermap_visitor.h>
#include <KoShape.h>
#include <KoShapeContainer.h>
#include "kis_global.h"
#include "kis_types.h"
#include "kis_layer_visitor.h"
#include "kis_external_layer_iface.h"
#include <kis_layer_shape.h>
#include <kis_paint_layer.h>
#include <kis_shape_layer.h>
#include <kis_layer_container_shape.h>
#include <kis_group_layer.h>
#include <kis_adjustment_layer.h>
KisLayerMapVisitor::KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap)
: m_layerMap( layerMap )
{
}
QMap<KisLayerSP, KoShape*> & KisLayerMapVisitor::layerMap()
{
return m_layerMap;
}
bool KisLayerMapVisitor::visit( KisExternalLayer * layer)
{
// kDebug(41007) << "KisLayerMap visitor adding external layer: " << layer->name() << endl;
KisShapeLayer * layerShape = dynamic_cast<KisShapeLayer*>( layer );
if ( !layerShape ) {
// kDebug(41007) << "this external layer is not a shape layer!\n";
return false;
}
m_layerMap[layer] = layerShape;
return true;
}
bool KisLayerMapVisitor::visit(KisPaintLayer *layer)
{
// kDebug(41007) << "KisLayerMap visitor adding paint layer: " << layer->name() << endl;
kDebug() << layer << " " << layer->parentLayer().data() << endl;
Q_ASSERT( layer->parentLayer() );
Q_ASSERT( m_layerMap.contains( layer->parentLayer() ) );
if ( m_layerMap.contains( layer->parentLayer() ) ) {
KoShapeContainer * parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
KisLayerShape * layerShape = new KisLayerShape( parent, layer );
m_layerMap[layer] = layerShape;
return true;
}
return false;
}
bool KisLayerMapVisitor::visit(KisGroupLayer *layer)
{
// kDebug(41007) << "KisLayerMap visitor adding group layer: " << layer->name() << endl;
KoShapeContainer * parent = 0;
if ( m_layerMap.contains( layer->parentLayer() ) ) {
parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
}
KisLayerContainerShape * layerContainer = new KisLayerContainerShape(parent, layer);
m_layerMap[layer] = layerContainer;
KisLayerSP child = layer->firstChild();
while (child) {
kDebug() << layer << " " << child->parentLayer().data() << " " << child.data() << endl;
child->accept(*this);
child = child->nextSibling();
}
return true;
}
bool KisLayerMapVisitor::visit(KisAdjustmentLayer *layer)
{
// kDebug(41007) << "KisLayerMap visitor adding adjustment layer: " << layer->name() << endl;
Q_ASSERT( m_layerMap.contains( layer->parentLayer() ) );
KoShapeContainer * parent = 0;
if ( m_layerMap.contains( layer->parentLayer() ) ) {
parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
KisLayerShape * layerShape = new KisLayerShape( parent, layer );
m_layerMap[layer] = layerShape;
return true;
}
return false;
}
......@@ -26,13 +26,6 @@
#include "kis_layer_visitor.h"
#include "kis_external_layer_iface.h"
#include <kis_layer_shape.h>
#include <kis_paint_layer.h>
#include <kis_shape_layer.h>
#include <kis_layer_container_shape.h>
#include <kis_group_layer.h>
#include <kis_adjustment_layer.h>
/**
* Creates the right layershape for all layers and puts them in the
* right order
......@@ -43,88 +36,20 @@ public:
/**
* @param layerMap: the map that maps layers to layer shapes
*/
KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap)
: m_layerMap( layerMap )
{
};
KisLayerMapVisitor(QMap<KisLayerSP, KoShape*> & layerMap);
virtual ~KisLayerMapVisitor() {};
QMap<KisLayerSP, KoShape*> & layerMap() {
return m_layerMap;
}
QMap<KisLayerSP, KoShape*> & layerMap();
public:
bool visit( KisExternalLayer * layer)
{
// kDebug(41007) << "KisLayerMap visitor adding external layer: " << layer->name() << endl;
KisShapeLayer * layerShape = dynamic_cast<KisShapeLayer*>( layer );
if ( !layerShape ) {
// kDebug(41007) << "this external layer is not a shape layer!\n";
return false;
}
m_layerMap[layer] = layerShape;
return true;
}
bool visit(KisPaintLayer *layer)
{
// kDebug(41007) << "KisLayerMap visitor adding paint layer: " << layer->name() << endl;
kDebug() << layer << " " << layer->parentLayer().data() << endl;
Q_ASSERT( layer->parentLayer() );
Q_ASSERT( m_layerMap.contains( layer->parentLayer() ) );
if ( m_layerMap.contains( layer->parentLayer() ) ) {
KoShapeContainer * parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
KisLayerShape * layerShape = new KisLayerShape( parent, layer );
m_layerMap[layer] = layerShape;
return true;
}
return false;
}
bool visit(KisGroupLayer *layer)
{
// kDebug(41007) << "KisLayerMap visitor adding group layer: " << layer->name() << endl;
KoShapeContainer * parent = 0;
if ( m_layerMap.contains( layer->parentLayer() ) ) {
parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
}
KisLayerContainerShape * layerContainer = new KisLayerContainerShape(parent, layer);
m_layerMap[layer] = layerContainer;
KisLayerSP child = layer->firstChild();
while (child) {
kDebug() << layer << " " << child->parentLayer().data() << " " << child.data() << endl;
child->accept(*this);
child = child->nextSibling();
}
return true;
}
bool visit(KisAdjustmentLayer *layer)
{
// kDebug(41007) << "KisLayerMap visitor adding adjustment layer: " << layer->name() << endl;
Q_ASSERT( m_layerMap.contains( layer->parentLayer() ) );
KoShapeContainer * parent = 0;
if ( m_layerMap.contains( layer->parentLayer() ) ) {
parent = static_cast<KoShapeContainer*>( m_layerMap[layer->parentLayer()] );
KisLayerShape * layerShape = new KisLayerShape( parent, layer );
m_layerMap[layer] = layerShape;
bool visit( KisExternalLayer * layer);
return true;
}
bool visit(KisPaintLayer *layer);
return false;
bool visit(KisGroupLayer *layer);
}
bool visit(KisAdjustmentLayer *layer);
private:
QMap<KisLayerSP, KoShape*> m_layerMap;
......
/*
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_load_visitor.h"
#include <QRect>
#include <KoColorSpaceRegistry.h>
#include <KoColorProfile.h>
#include <KoStore.h>
// kritaimage
#include "kis_types.h"
#include "kis_layer_visitor.h"
#include "kis_image.h"
#include "kis_selection.h"
#include "kis_layer.h"
#include "kis_paint_layer.h"
#include "kis_group_layer.h"
#include "kis_adjustment_layer.h"
#include "kis_filter_configuration.h"
#include "kis_datamanager.h"
KisLoadVisitor::KisLoadVisitor(KisImageSP img, KoStore *store, QMap<KisLayer *, QString> &layerFilenames) :
KisLayerVisitor(),
m_layerFilenames(layerFilenames)
{
m_external = false;
m_img = img;
m_store = store;
}
void KisLoadVisitor::setExternalUri(QString &uri)
{
m_external = true;
m_uri = uri;
}
bool KisLoadVisitor::visit( KisExternalLayer * )
{
return true;
}
bool KisLoadVisitor::visit(KisPaintLayer *layer)
{ //connect(*layer->paintDevice(), SIGNAL(ioProgress(qint8)), m_img, SLOT(slotIOProgress(qint8)));
QString location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer];
// Layer data
if (m_store->open(location)) {
if (!layer->paintDevice()->read(m_store)) {
layer->paintDevice()->disconnect();
m_store->close();
//IODone();
return false;
}
m_store->close();
}
// icc profile
location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".icc";
if (m_store->hasFile(location)) {
QByteArray data;
m_store->open(location);
data = m_store->read(m_store->size());
m_store->close();
// Create a colorspace with the embedded profile
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace(layer->paintDevice()->colorSpace()->id(), new KoColorProfile(data));
// replace the old colorspace
layer->paintDevice()->setData(layer->paintDevice()->dataManager(), cs);
QRect rc = layer->paintDevice()->extent();
layer->setDirty(rc);
}
// mask
if (layer->hasMask()) { // We set this in KisDoc::loadPaintLayer
KisPaintDeviceSP mask = layer->getMask();
location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".mask";
// Layer data
if (m_store->open(location)) {
if (!mask->read(m_store)) {
mask->disconnect();
m_store->close();
//IODone();
return false;
}
m_store->close();
}
layer->setDirty(); // Update the entire layer
}
return true;
}
bool KisLoadVisitor::visit(KisGroupLayer *layer)
{
KisLoadVisitor visitor(m_img, m_store, m_layerFilenames);
if(m_external)
visitor.setExternalUri(m_uri);
KisLayerSP child = layer->firstChild();
while(child)
{
child->accept(visitor);
child = child->nextSibling();
}
layer->setDirty(m_img->bounds());
return true;
}
bool KisLoadVisitor::visit(KisAdjustmentLayer* layer)
{
//connect(*layer->paintDevice(), SIGNAL(ioProgress(qint8)), m_img, SLOT(slotIOProgress(qint8)));
// The selection -- if present. If not, we simply cannot open the dratted thing.
QString location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".selection";
if (m_store->hasFile(location)) {
m_store->open(location);
KisSelectionSP selection = KisSelectionSP(new KisSelection());
if (!selection->read(m_store)) {
selection->disconnect();
m_store->close();
}
else {
layer->setSelection( selection );
}
m_store->close();
}
// filter configuration
location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".filterconfig";
if (m_store->hasFile(location) && layer->filter()) {
QByteArray data;
m_store->open(location);
data = m_store->read(m_store->size());
m_store->close();
if (!data.isEmpty()) {
KisFilterConfiguration * kfc = layer->filter();
kfc->fromXML(QString(data));
}
}
return true;
}
......@@ -24,155 +24,22 @@
// kritaimage
#include "kis_types.h"
#include "kis_layer_visitor.h"
#include "kis_image.h"
#include "kis_selection.h"
#include "kis_layer.h"
#include "kis_paint_layer.h"
#include "kis_group_layer.h"
#include "kis_adjustment_layer.h"
#include "kis_filter_configuration.h"
#include "kis_datamanager.h"
class KoStore;
class KisLoadVisitor : public KisLayerVisitor {
public:
KisLoadVisitor(KisImageSP img, KoStore *store, QMap<KisLayer *, QString> &layerFilenames) :
KisLayerVisitor(),
m_layerFilenames(layerFilenames)
{
m_external = false;
m_img = img;
m_store = store;
}
KisLoadVisitor(KisImageSP img, KoStore *store, QMap<KisLayer *, QString> &layerFilenames);
public:
void setExternalUri(QString &uri)
{
m_external = true;
m_uri = uri;
}
bool visit( KisExternalLayer * )
{
return true;
}
bool visit(KisPaintLayer *layer)
{ //connect(*layer->paintDevice(), SIGNAL(ioProgress(qint8)), m_img, SLOT(slotIOProgress(qint8)));
QString location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer];
// Layer data
if (m_store->open(location)) {
if (!layer->paintDevice()->read(m_store)) {
layer->paintDevice()->disconnect();
m_store->close();
//IODone();
return false;
}
m_store->close();
}
// icc profile
location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".icc";
if (m_store->hasFile(location)) {
QByteArray data;
m_store->open(location);
data = m_store->read(m_store->size());
m_store->close();
// Create a colorspace with the embedded profile
KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace(layer->paintDevice()->colorSpace()->id(),
new KoColorProfile(data));
// replace the old colorspace
layer->paintDevice()->setData(layer->paintDevice()->dataManager(), cs);
QRect rc = layer->paintDevice()->extent();
layer->setDirty(rc);
}
// mask
if (layer->hasMask()) { // We set this in KisDoc::loadPaintLayer
KisPaintDeviceSP mask = layer->getMask();
location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".mask";
// Layer data
if (m_store->open(location)) {
if (!mask->read(m_store)) {
mask->disconnect();
m_store->close();
//IODone();
return false;
}
m_store->close();
}
layer->setDirty(); // Update the entire layer
}
return true;
}
bool visit(KisGroupLayer *layer)
{
KisLoadVisitor visitor(m_img, m_store, m_layerFilenames);
if(m_external)
visitor.setExternalUri(m_uri);
KisLayerSP child = layer->firstChild();
while(child)
{
child->accept(visitor);
child = child->nextSibling();
}
layer->setDirty(m_img->bounds());
return true;
}
bool visit(KisAdjustmentLayer* layer)
{
//connect(*layer->paintDevice(), SIGNAL(ioProgress(qint8)), m_img, SLOT(slotIOProgress(qint8)));
// The selection -- if present. If not, we simply cannot open the dratted thing.
QString location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".selection";
if (m_store->hasFile(location)) {
m_store->open(location);
KisSelectionSP selection = KisSelectionSP(new KisSelection());
if (!selection->read(m_store)) {
selection->disconnect();
m_store->close();
}
else {
layer->setSelection( selection );
}
m_store->close();
}
// filter configuration
location = m_external ? QString::null : m_uri;
location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".filterconfig";
void setExternalUri(QString &uri);
if (m_store->hasFile(location) && layer->filter()) {
QByteArray data;
m_store->open(location);
data = m_store->read(m_store->size());
m_store->close();
if (!data.isEmpty()) {
KisFilterConfiguration * kfc = layer->filter();
kfc->fromXML(QString(data));
}
}
bool visit( KisExternalLayer * );
return true;
bool visit(KisPaintLayer *layer);
bool visit(KisGroupLayer *layer);
}
bool visit(KisAdjustmentLayer* layer);
private:
KisImageSP m_img;
......
/*
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <kis_save_visitor.h>
#include <KoColorProfile.h>
#include <KoStore.h>
#include "kis_adjustment_layer.h"
#include "kis_annotation.h"
#include "kis_filter_configuration.h"
#include "kis_group_layer.h"
#include "kis_image.h"
#include "kis_layer.h"
#include "kis_paint_layer.h"
#include "kis_selection.h"
KisSaveVisitor::KisSaveVisitor(KisImageSP img, KoStore *store, quint32 &count) :
KisLayerVisitor(),
m_count(count)
{
m_external = false;
m_img = img;
m_store = store;
}
void KisSaveVisitor::setExternalUri(QString &uri)
{
m_external = true;
m_uri = uri;
}
bool KisSaveVisitor::visit( KisExternalLayer * )
{
return true;
}
bool KisSaveVisitor::visit(KisPaintLayer *layer)
{
//connect(*layer->paintDevice(), SIGNAL(ioProgress(qint8)), m_img, SLOT(slotIOProgress(qint8)));
QString location = m_external ? QString::null : m_uri;
location += m_img->name() + QString("/layers/layer%1").arg(m_count);
// Layer data
if (m_store->open(location)) {
if (!layer->paintDevice()->write(m_store)) {
layer->paintDevice()->disconnect();
m_store->close();
//IODone();
return false;
}
m_store->close();
}
if (layer->paintDevice()->colorSpace()->profile()) {
KoColorProfile *profile = layer->paintDevice()->colorSpace()->profile();
KisAnnotationSP annotation;
if (profile)
{
// XXX we hardcode icc, this is correct for lcms?
// XXX productName(), or just "ICC Profile"?
if (!profile->rawData().isEmpty())
annotation = new KisAnnotation("icc", profile->productName(), profile->rawData());
}
if (annotation) {
// save layer profile