Krita Source Code Documentation
Loading...
Searching...
No Matches
KisExrLayersSorter::Private Struct Reference

Public Member Functions

void createOrderingMap ()
 
 Private (const QDomDocument &_extraData, KisImageSP _image)
 
void processLayers (KisNodeSP root)
 
void sortLayers (KisNodeSP root)
 

Public Attributes

const QDomDocument & extraData
 
KisImageSP image
 
QMap< KisNodeSP, int > nodeToOrderingMap
 
QMap< QString, QDomElement > pathToElementMap
 
QMap< QString, int > pathToOrderingMap
 

Detailed Description

Definition at line 18 of file kis_exr_layers_sorter.cpp.

Constructor & Destructor Documentation

◆ Private()

KisExrLayersSorter::Private::Private ( const QDomDocument & _extraData,
KisImageSP _image )
inline

Definition at line 20 of file kis_exr_layers_sorter.cpp.

21 : extraData(_extraData), image(_image) {}

Member Function Documentation

◆ createOrderingMap()

void KisExrLayersSorter::Private::createOrderingMap ( )

Definition at line 55 of file kis_exr_layers_sorter.cpp.

56{
57 int index = 0;
58 QDomElement el = extraData.documentElement().firstChildElement();
59
60
61 while (!el.isNull()) {
62 QString path = el.attribute(EXR_NAME);
63 pathToElementMap.insert(path, el);
64 pathToOrderingMap.insert(path, index);
65
66 el = el.nextSiblingElement();
67 index++;
68 }
69}
const char EXR_NAME[]
QMap< QString, QDomElement > pathToElementMap

References EXR_NAME, extraData, pathToElementMap, and pathToOrderingMap.

◆ processLayers()

void KisExrLayersSorter::Private::processLayers ( KisNodeSP root)

In older files (before Krita 5.2.7) we used to save the layer offset into the XML metadata, while loading the pixel data at the origin. Since 5.2.7 we stopped saving offsets (we save null instead of them), we let's just make sure we don't load garbage from older files).

Hence, we pass false for loading the offset

Definition at line 89 of file kis_exr_layers_sorter.cpp.

90{
91 if (root && root->parent()) {
92 QString path = getNodePath(root);
93
95
96 if (KisPaintLayer *paintLayer = dynamic_cast<KisPaintLayer*>(root.data())) {
97 QDomElement el = pathToElementMap[path];
98
107 KisSaveXmlVisitor::loadPaintLayerAttributes(el, paintLayer, false);
108 }
109 }
110
111 KisNodeSP child = root->firstChild();
112 while (child) {
113 processLayers(child);
114 child = child->nextSibling();
115 }
116}
static void loadPaintLayerAttributes(const QDomElement &el, KisPaintLayer *layer, bool loadLayerOffset)
T fetchMapValueLazy(const QMap< QString, T > &map, QString path)
QString getNodePath(KisNodeSP node)
QMap< KisNodeSP, int > nodeToOrderingMap
KisNodeSP firstChild() const
Definition kis_node.cpp:361
KisNodeWSP parent
Definition kis_node.cpp:86
KisNodeSP nextSibling() const
Definition kis_node.cpp:408

References KisSharedPtr< T >::data(), fetchMapValueLazy(), KisNode::firstChild(), getNodePath(), KisSaveXmlVisitor::loadPaintLayerAttributes(), KisNode::nextSibling(), and KisNode::parent.

◆ sortLayers()

void KisExrLayersSorter::Private::sortLayers ( KisNodeSP root)

Definition at line 132 of file kis_exr_layers_sorter.cpp.

133{
134 QList<KisNodeSP> childNodes;
135
136 // first move all the children to the list
137 KisNodeSP child = root->firstChild();
138 while (child) {
139 KisNodeSP lastChild = child;
140 child = child->nextSibling();
141
142 childNodes.append(lastChild);
143 image->removeNode(lastChild);
144 }
145
146 // sort the list
147 std::stable_sort(childNodes.begin(), childNodes.end(), CompareNodesFunctor(nodeToOrderingMap));
148
149 // put the children back
150 Q_FOREACH (KisNodeSP node, childNodes) {
151 image->addNode(node, root, root->childCount());
152 }
153
154 // recursive calls
155 child = root->firstChild();
156 while (child) {
157 sortLayers(child);
158 child = child->nextSibling();
159 }
160}
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
bool removeNode(KisNodeSP node)
quint32 childCount() const
Definition kis_node.cpp:414

References KisNode::childCount(), KisNode::firstChild(), and KisNode::nextSibling().

Member Data Documentation

◆ extraData

const QDomDocument& KisExrLayersSorter::Private::extraData

Definition at line 23 of file kis_exr_layers_sorter.cpp.

◆ image

KisImageSP KisExrLayersSorter::Private::image

Definition at line 24 of file kis_exr_layers_sorter.cpp.

◆ nodeToOrderingMap

QMap<KisNodeSP, int> KisExrLayersSorter::Private::nodeToOrderingMap

Definition at line 29 of file kis_exr_layers_sorter.cpp.

◆ pathToElementMap

QMap<QString, QDomElement> KisExrLayersSorter::Private::pathToElementMap

Definition at line 26 of file kis_exr_layers_sorter.cpp.

◆ pathToOrderingMap

QMap<QString, int> KisExrLayersSorter::Private::pathToOrderingMap

Definition at line 27 of file kis_exr_layers_sorter.cpp.


The documentation for this struct was generated from the following file: