krita
kis_save_visitor.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KIS_SAVE_VISITOR_H_
00020 #define KIS_SAVE_VISITOR_H_
00021
00022 #include <qrect.h>
00023 #include "kis_types.h"
00024 #include "kis_layer_visitor.h"
00025 #include "kis_image.h"
00026 #include "kis_layer.h"
00027 #include "kis_paint_layer.h"
00028 #include "kis_group_layer.h"
00029
00030 class KisSaveVisitor : public KisLayerVisitor {
00031 public:
00032 KisSaveVisitor(KisImageSP img, KoStore *store, Q_UINT32 &count) :
00033 KisLayerVisitor(),
00034 m_count(count)
00035 {
00036 m_external = false;
00037 m_img = img;
00038 m_store = store;
00039 }
00040
00041 public:
00042 void setExternalUri(QString &uri)
00043 {
00044 m_external = true;
00045 m_uri = uri;
00046 }
00047
00048 virtual bool visit(KisPaintLayer *layer)
00049 {
00050
00051
00052 QString location = m_external ? QString::null : m_uri;
00053 location += m_img->name() + QString("/layers/layer%1").arg(m_count);
00054
00055
00056 if (m_store->open(location)) {
00057 if (!layer->paintDevice()->write(m_store)) {
00058 layer->paintDevice()->disconnect();
00059 m_store->close();
00060
00061 return false;
00062 }
00063
00064 m_store->close();
00065 }
00066
00067 if (layer->paintDevice()->colorSpace()->getProfile()) {
00068 KisAnnotationSP annotation = layer->paintDevice()->colorSpace()->getProfile()->annotation();
00069
00070 if (annotation) {
00071
00072 location = m_external ? QString::null : m_uri;
00073 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".icc";
00074
00075 if (m_store->open(location)) {
00076 m_store->write(annotation->annotation());
00077 m_store->close();
00078 }
00079 }
00080 }
00081
00082 m_count++;
00083 return true;
00084 }
00085
00086 virtual bool visit(KisGroupLayer *layer)
00087 {
00088 KisSaveVisitor visitor(m_img, m_store, m_count);
00089
00090 if(m_external)
00091 visitor.setExternalUri(m_uri);
00092
00093 KisLayerSP child = layer->firstChild();
00094
00095 while(child)
00096 {
00097 child->accept(visitor);
00098 child = child->nextSibling();
00099 }
00100 return true;
00101 }
00102
00103 virtual bool visit(KisPartLayer *)
00104 {
00105 return true;
00106 }
00107
00108 virtual bool visit(KisAdjustmentLayer* layer)
00109 {
00110
00111 if (layer->selection()) {
00112 QString location = m_external ? QString::null : m_uri;
00113 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".selection";
00114
00115
00116 if (m_store->open(location)) {
00117 if (!layer->selection()->write(m_store)) {
00118 layer->selection()->disconnect();
00119 m_store->close();
00120
00121 return false;
00122 }
00123 m_store->close();
00124 }
00125 }
00126
00127 if (layer->filter()) {
00128 QString location = m_external ? QString::null : m_uri;
00129 location = m_external ? QString::null : m_uri;
00130 location += m_img->name() + QString("/layers/layer%1").arg(m_count) + ".filterconfig";
00131
00132 if (m_store->open(location)) {
00133 QString s = layer->filter()->toString();
00134 m_store->write(s.utf8(), qstrlen(s.utf8()));
00135 m_store->close();
00136 }
00137 }
00138 m_count++;
00139 return true;
00140 }
00141
00142 private:
00143 KisImageSP m_img;
00144 KoStore *m_store;
00145 bool m_external;
00146 QString m_uri;
00147 Q_UINT32 &m_count;
00148 };
00149
00150 #endif // KIS_SAVE_VISITOR_H_
00151
|