krita

kis_savexml_visitor.h

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *  Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 #ifndef KIS_SAVEXML_VISITOR_H_
00020 #define KIS_SAVEXML_VISITOR_H_
00021 
00022 #include <qrect.h>
00023 
00024 #include "kis_adjustment_layer.h"
00025 #include "kis_exif_info.h"
00026 #include "kis_group_layer.h"
00027 #include "kis_image.h"
00028 #include "kis_layer.h"
00029 #include "kis_layer_visitor.h"
00030 #include "kis_paint_layer.h"
00031 #include "kis_types.h"
00032 
00033 class KisSaveXmlVisitor : public KisLayerVisitor {
00034 public:
00035     KisSaveXmlVisitor(QDomDocument doc, QDomElement element, Q_UINT32 &count, bool root=false) :
00036         KisLayerVisitor(),
00037         m_doc(doc),
00038         m_count(count),
00039         m_root(root)
00040     {
00041         m_elem = element;
00042     }
00043 
00044 public:
00045     virtual bool visit(KisPaintLayer *layer)
00046     {
00047         QDomElement layerElement = m_doc.createElement("layer");
00048 
00049         layerElement.setAttribute("name", layer->name());
00050         layerElement.setAttribute("x", layer->x());
00051         layerElement.setAttribute("y", layer->y());
00052         layerElement.setAttribute("opacity", layer->opacity());
00053         layerElement.setAttribute("compositeop", layer->compositeOp().id().id());
00054         layerElement.setAttribute("visible", layer->visible());
00055         layerElement.setAttribute("locked", layer->locked());
00056         layerElement.setAttribute("layertype", "paintlayer");
00057         layerElement.setAttribute("filename", QString("layer%1").arg(m_count));
00058         layerElement.setAttribute("colorspacename", layer->paintDevice()->colorSpace()->id().id());
00059 
00060         m_elem.appendChild(layerElement);
00061 
00062         if(layer->paintDevice()->hasExifInfo())
00063         {
00064             QDomElement exifElmt = layer->paintDevice()->exifInfo()->save(m_doc);
00065             layerElement.appendChild(exifElmt);
00066         }
00067         m_count++;
00068         return true;
00069     }
00070 
00071     virtual bool visit(KisGroupLayer *layer)
00072     {
00073         QDomElement layerElement;
00074 
00075         if(m_root) // if this is the root we fake so not to save it
00076             layerElement = m_elem;
00077         else
00078         {
00079             layerElement = m_doc.createElement("layer");
00080 
00081             layerElement.setAttribute("name", layer->name());
00082             layerElement.setAttribute("x", layer->x());
00083             layerElement.setAttribute("y", layer->y());
00084             layerElement.setAttribute("opacity", layer->opacity());
00085             layerElement.setAttribute("compositeop", layer->compositeOp().id().id());
00086             layerElement.setAttribute("visible", layer->visible());
00087             layerElement.setAttribute("locked", layer->locked());
00088             layerElement.setAttribute("layertype", "grouplayer");
00089 
00090             m_elem.appendChild(layerElement);
00091        }
00092 
00093         QDomElement elem = m_doc.createElement("LAYERS");
00094 
00095         layerElement.appendChild(elem);
00096 
00097         KisSaveXmlVisitor visitor(m_doc, elem, m_count);
00098 
00099         KisLayerSP child = layer->firstChild();
00100 
00101         while(child)
00102         {
00103             child->accept(visitor);
00104             child = child->nextSibling();
00105         }
00106         return true;
00107     }
00108 
00109     virtual bool visit(KisPartLayer* layer)
00110     {
00111         bool ok = layer->saveToXML(m_doc, m_elem);
00112         return ok;
00113     }
00114 
00115     virtual bool visit(KisAdjustmentLayer* layer)
00116     {
00117         QDomElement layerElement = m_doc.createElement("layer");
00118 
00119         layerElement.setAttribute("name", layer->name());
00120         layerElement.setAttribute("filtername", layer->filter()->name());
00121         layerElement.setAttribute("filterversion", layer->filter()->version());
00122         layerElement.setAttribute("opacity", layer->opacity());
00123         layerElement.setAttribute("compositeop", layer->compositeOp().id().id());
00124         layerElement.setAttribute("visible", layer->visible());
00125         layerElement.setAttribute("locked", layer->locked());
00126         layerElement.setAttribute("layertype", "adjustmentlayer");
00127         layerElement.setAttribute("filename", QString("layer%1").arg(m_count));
00128         layerElement.setAttribute("x", layer->x());
00129         layerElement.setAttribute("y", layer->y());
00130         m_elem.appendChild(layerElement);
00131 
00132         m_count++;
00133         return true;
00134     }
00135 
00136 private:
00137     QDomDocument m_doc;
00138     QDomElement m_elem;
00139     Q_UINT32 &m_count;
00140     bool m_root;
00141 };
00142 
00143 #endif // KIS_SAVEXML_VISITOR_H_
00144 
KDE Home | KDE Accessibility Home | Description of Access Keys