Commit 758e568f authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix safe assert when loading an image with Reference Images layer

parent 5d17bdad
......@@ -1702,7 +1702,7 @@ void KisDocument::setAssistants(const QList<KisPaintingAssistantSP> &value)
d->assistants = value;
}
KisSharedPtr<KisReferenceImagesLayer> KisDocument::createReferenceImagesLayer(KisImageSP targetImage)
KisSharedPtr<KisReferenceImagesLayer> KisDocument::getOrCreateReferenceImagesLayer(KisImageSP targetImage)
{
if (!d->referenceImagesLayer) {
if (targetImage.isNull()) targetImage = d->image;
......@@ -1714,11 +1714,17 @@ KisSharedPtr<KisReferenceImagesLayer> KisDocument::createReferenceImagesLayer(Ki
return d->referenceImagesLayer;
}
// TODO: change signature to return a shared pointer
KisReferenceImagesLayer *KisDocument::referenceImagesLayer() const
{
return d->referenceImagesLayer.data();
}
void KisDocument::setReferenceImagesLayer(KisSharedPtr<KisReferenceImagesLayer> layer)
{
d->referenceImagesLayer = layer;
}
void KisDocument::setPreActivatedNode(KisNodeSP activatedNode)
{
d->preActivatedNode = activatedNode;
......
......@@ -592,14 +592,18 @@ public:
/**
* Get existing reference images layer or create new if none exists.
*
* TODO: use setReferenceImagesLayer() combined with undo commands instead
*/
KisSharedPtr<KisReferenceImagesLayer> createReferenceImagesLayer(KisImageSP targetImage = KisImageSP());
KRITAUI_DEPRECATED KisSharedPtr<KisReferenceImagesLayer> getOrCreateReferenceImagesLayer(KisImageSP targetImage = KisImageSP());
/**
* Get existing reference images layer or null if none exists.
*/
KisReferenceImagesLayer *referenceImagesLayer() const;
void setReferenceImagesLayer(KisSharedPtr<KisReferenceImagesLayer> layer);
bool save(bool showWarnings, KisPropertiesConfigurationSP exportConfiguration);
Q_SIGNALS:
......
......@@ -96,7 +96,7 @@ KisReferenceImagesDecoration::~KisReferenceImagesDecoration()
void KisReferenceImagesDecoration::addReferenceImage(KisReferenceImage *referenceImage)
{
KisSharedPtr<KisReferenceImagesLayer> layer = view()->document()->createReferenceImagesLayer();
KisSharedPtr<KisReferenceImagesLayer> layer = view()->document()->getOrCreateReferenceImagesLayer();
KIS_SAFE_ASSERT_RECOVER_RETURN(layer);
KUndo2Command *cmd = layer->addReferenceImage(referenceImage);
......
......@@ -559,7 +559,7 @@ KisNodeSP KisKraLoader::loadNodes(const KoXmlElement& element, KisImageSP image,
if (node.nodeName().toUpper() == LAYERS.toUpper() || node.nodeName().toUpper() == MASKS.toUpper()) {
for (child = node.lastChild(); !child.isNull(); child = child.previousSibling()) {
KisNodeSP node = loadNode(child.toElement(), image, parent);
KisNodeSP node = loadNode(child.toElement(), image);
if (node) {
image->nextLayerName(); // Make sure the nameserver is current with the number of nodes.
image->addNode(node, parent);
......@@ -575,7 +575,7 @@ KisNodeSP KisKraLoader::loadNodes(const KoXmlElement& element, KisImageSP image,
return parent;
}
KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageSP image, KisNodeSP parent)
KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageSP image)
{
// Nota bene: If you add new properties to layers, you should
// ALWAYS define a default value in case the property is not
......@@ -659,15 +659,15 @@ KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageSP image,
else if (nodeType == CLONE_LAYER)
node = loadCloneLayer(element, image, name, colorSpace, opacity);
else if (nodeType == FILTER_MASK)
node = loadFilterMask(element, parent);
node = loadFilterMask(element);
else if (nodeType == TRANSFORM_MASK)
node = loadTransformMask(element, parent);
node = loadTransformMask(element);
else if (nodeType == TRANSPARENCY_MASK)
node = loadTransparencyMask(element, parent);
node = loadTransparencyMask(element);
else if (nodeType == SELECTION_MASK)
node = loadSelectionMask(image, element, parent);
node = loadSelectionMask(image, element);
else if (nodeType == COLORIZE_MASK)
node = loadColorizeMask(image, element, parent, colorSpace);
node = loadColorizeMask(image, element, colorSpace);
else if (nodeType == FILE_LAYER)
node = loadFileLayer(element, image, name, opacity);
else if (nodeType == REFERENCE_IMAGES_LAYER)
......@@ -974,9 +974,8 @@ KisNodeSP KisKraLoader::loadCloneLayer(const KoXmlElement& element, KisImageSP i
}
KisNodeSP KisKraLoader::loadFilterMask(const KoXmlElement& element, KisNodeSP parent)
KisNodeSP KisKraLoader::loadFilterMask(const KoXmlElement& element)
{
Q_UNUSED(parent);
QString attr;
KisFilterMask* mask;
QString filtername;
......@@ -1005,10 +1004,9 @@ KisNodeSP KisKraLoader::loadFilterMask(const KoXmlElement& element, KisNodeSP pa
return mask;
}
KisNodeSP KisKraLoader::loadTransformMask(const KoXmlElement& element, KisNodeSP parent)
KisNodeSP KisKraLoader::loadTransformMask(const KoXmlElement& element)
{
Q_UNUSED(element);
Q_UNUSED(parent);
KisTransformMask* mask;
......@@ -1022,19 +1020,17 @@ KisNodeSP KisKraLoader::loadTransformMask(const KoXmlElement& element, KisNodeSP
return mask;
}
KisNodeSP KisKraLoader::loadTransparencyMask(const KoXmlElement& element, KisNodeSP parent)
KisNodeSP KisKraLoader::loadTransparencyMask(const KoXmlElement& element)
{
Q_UNUSED(element);
Q_UNUSED(parent);
KisTransparencyMask* mask = new KisTransparencyMask();
Q_CHECK_PTR(mask);
return mask;
}
KisNodeSP KisKraLoader::loadSelectionMask(KisImageSP image, const KoXmlElement& element, KisNodeSP parent)
KisNodeSP KisKraLoader::loadSelectionMask(KisImageSP image, const KoXmlElement& element)
{
Q_UNUSED(parent);
KisSelectionMaskSP mask = new KisSelectionMask(image);
bool active = element.attribute(ACTIVE, "1") == "0" ? false : true;
mask->setActive(active);
......@@ -1043,9 +1039,8 @@ KisNodeSP KisKraLoader::loadSelectionMask(KisImageSP image, const KoXmlElement&
return mask;
}
KisNodeSP KisKraLoader::loadColorizeMask(KisImageSP image, const KoXmlElement& element, KisNodeSP parent, const KoColorSpace *colorSpace)
KisNodeSP KisKraLoader::loadColorizeMask(KisImageSP image, const KoXmlElement& element, const KoColorSpace *colorSpace)
{
Q_UNUSED(parent);
KisColorizeMaskSP mask = new KisColorizeMask();
const bool editKeystrokes = element.attribute(COLORIZE_EDIT_KEYSTROKES, "1") == "0" ? false : true;
const bool showColoring = element.attribute(COLORIZE_SHOW_COLORING, "1") == "0" ? false : true;
......@@ -1186,7 +1181,10 @@ void KisKraLoader::loadAudio(const KoXmlElement& elem, KisImageSP image)
KisNodeSP KisKraLoader::loadReferenceImagesLayer(const KoXmlElement &elem, KisImageSP image)
{
KisSharedPtr<KisReferenceImagesLayer> layer = m_d->document->createReferenceImagesLayer(image);
KisSharedPtr<KisReferenceImagesLayer> layer =
new KisReferenceImagesLayer(m_d->document->shapeController(), image);
m_d->document->setReferenceImagesLayer(layer);
for (QDomElement child = elem.firstChildElement(); !child.isNull(); child = child.nextSiblingElement()) {
if (child.nodeName().toLower() == "referenceimage") {
......
......@@ -73,7 +73,7 @@ private:
KisNodeSP loadNodes(const KoXmlElement& element, KisImageSP image, KisNodeSP parent);
KisNodeSP loadNode(const KoXmlElement& elem, KisImageSP image, KisNodeSP parent);
KisNodeSP loadNode(const KoXmlElement& elem, KisImageSP image);
KisNodeSP loadPaintLayer(const KoXmlElement& elem, KisImageSP image, const QString& name, const KoColorSpace* cs, quint32 opacity);
......@@ -87,15 +87,15 @@ private:
KisNodeSP loadCloneLayer(const KoXmlElement& elem, KisImageSP image, const QString& name, const KoColorSpace* cs, quint32 opacity);
KisNodeSP loadFilterMask(const KoXmlElement& elem, KisNodeSP parent);
KisNodeSP loadFilterMask(const KoXmlElement& elem);
KisNodeSP loadTransformMask(const KoXmlElement& elem, KisNodeSP parent);
KisNodeSP loadTransformMask(const KoXmlElement& elem);
KisNodeSP loadTransparencyMask(const KoXmlElement& elem, KisNodeSP parent);
KisNodeSP loadTransparencyMask(const KoXmlElement& elem);
KisNodeSP loadSelectionMask(KisImageSP image, const KoXmlElement& elem, KisNodeSP parent);
KisNodeSP loadSelectionMask(KisImageSP image, const KoXmlElement& elem);
KisNodeSP loadColorizeMask(KisImageSP image, const KoXmlElement& elem, KisNodeSP parent, const KoColorSpace *colorSpace);
KisNodeSP loadColorizeMask(KisImageSP image, const KoXmlElement& elem, const KoColorSpace *colorSpace);
KisNodeSP loadFileLayer(const KoXmlElement& elem, KisImageSP image, const QString& name, quint32 opacity);
......
......@@ -209,7 +209,7 @@ KisReferenceImagesLayer *ToolReferenceImages::getOrCreteReferenceImagesLayer()
auto kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
KisDocument *document = kisCanvas->imageView()->document();
return document->createReferenceImagesLayer().data();
return document->getOrCreateReferenceImagesLayer().data();
}
KoSelection *ToolReferenceImages::koSelection() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment