chalk

kis_savexml_visitor.h
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef KIS_SAVEXML_VISITOR_H_
20#define KIS_SAVEXML_VISITOR_H_
21
22#include <tqrect.h>
23
24#include "kis_adjustment_layer.h"
25#include "kis_exif_info.h"
26#include "kis_group_layer.h"
27#include "kis_image.h"
28#include "kis_layer.h"
29#include "kis_layer_visitor.h"
30#include "kis_paint_layer.h"
31#include "kis_types.h"
32
33class KisSaveXmlVisitor : public KisLayerVisitor {
34public:
35 KisSaveXmlVisitor(TQDomDocument doc, TQDomElement element, TQ_UINT32 &count, bool root=false) :
36 KisLayerVisitor(),
37 m_doc(doc),
38 m_count(count),
39 m_root(root)
40 {
41 m_elem = element;
42 }
43
44public:
45 virtual bool visit(KisPaintLayer *layer)
46 {
47 TQDomElement layerElement = m_doc.createElement("layer");
48
49 layerElement.setAttribute("name", layer->name());
50 layerElement.setAttribute("x", layer->x());
51 layerElement.setAttribute("y", layer->y());
52 layerElement.setAttribute("opacity", layer->opacity());
53 layerElement.setAttribute("compositeop", layer->compositeOp().id().id());
54 layerElement.setAttribute("visible", layer->visible());
55 layerElement.setAttribute("locked", layer->locked());
56 layerElement.setAttribute("layertype", "paintlayer");
57 layerElement.setAttribute("filename", TQString("layer%1").arg(m_count));
58 layerElement.setAttribute("colorspacename", layer->paintDevice()->colorSpace()->id().id());
59 layerElement.setAttribute("hasmask", layer->hasMask());
60 m_elem.appendChild(layerElement);
61
62 if(layer->paintDevice()->hasExifInfo())
63 {
64 TQDomElement exifElmt = layer->paintDevice()->exifInfo()->save(m_doc);
65 layerElement.appendChild(exifElmt);
66 }
67 m_count++;
68 return true;
69 }
70
71 virtual bool visit(KisGroupLayer *layer)
72 {
73 TQDomElement layerElement;
74
75 if(m_root) // if this is the root we fake so not to save it
76 layerElement = m_elem;
77 else
78 {
79 layerElement = m_doc.createElement("layer");
80
81 layerElement.setAttribute("name", layer->name());
82 layerElement.setAttribute("x", layer->x());
83 layerElement.setAttribute("y", layer->y());
84 layerElement.setAttribute("opacity", layer->opacity());
85 layerElement.setAttribute("compositeop", layer->compositeOp().id().id());
86 layerElement.setAttribute("visible", layer->visible());
87 layerElement.setAttribute("locked", layer->locked());
88 layerElement.setAttribute("layertype", "grouplayer");
89
90 m_elem.appendChild(layerElement);
91 }
92
93 TQDomElement elem = m_doc.createElement("LAYERS");
94
95 layerElement.appendChild(elem);
96
97 KisSaveXmlVisitor visitor(m_doc, elem, m_count);
98
99 KisLayerSP child = layer->firstChild();
100
101 while(child)
102 {
103 child->accept(visitor);
104 child = child->nextSibling();
105 }
106 return true;
107 }
108
109 virtual bool visit(KisPartLayer* layer)
110 {
111 bool ok = layer->saveToXML(m_doc, m_elem);
112 return ok;
113 }
114
115 virtual bool visit(KisAdjustmentLayer* layer)
116 {
117 TQDomElement layerElement = m_doc.createElement("layer");
118
119 layerElement.setAttribute("name", layer->name());
120 layerElement.setAttribute("filtername", layer->filter()->name());
121 layerElement.setAttribute("filterversion", layer->filter()->version());
122 layerElement.setAttribute("opacity", layer->opacity());
123 layerElement.setAttribute("compositeop", layer->compositeOp().id().id());
124 layerElement.setAttribute("visible", layer->visible());
125 layerElement.setAttribute("locked", layer->locked());
126 layerElement.setAttribute("layertype", "adjustmentlayer");
127 layerElement.setAttribute("filename", TQString("layer%1").arg(m_count));
128 layerElement.setAttribute("x", layer->x());
129 layerElement.setAttribute("y", layer->y());
130 m_elem.appendChild(layerElement);
131
132 m_count++;
133 return true;
134 }
135
136private:
137 TQDomDocument m_doc;
138 TQDomElement m_elem;
139 TQ_UINT32 &m_count;
140 bool m_root;
141};
142
143#endif // KIS_SAVEXML_VISITOR_H_
144
Class that contains a KisFilter and optionally a KisSelection.
const TQString & name() const
Get the unique, language independent name of the filter.
TQ_INT32 version() const
Get the version of the filter that has created this config.
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
This layer is of a type that can be painted on.
bool hasMask() const
Does this layer have a layer mask?
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.