Commit a9b68dbb authored by Victor Wåhlström's avatar Victor Wåhlström

Change Document::createFilterMask API to require either a Selection or a Node...

Change Document::createFilterMask API to require either a Selection or a Node from which to initialize the selection with.

This prevents a crash that would occur when parenting a FilterMask without a selection to a node.

BUG:395000
parent efb062b8
......@@ -665,13 +665,41 @@ VectorLayer *Document::createVectorLayer(const QString &name)
return new VectorLayer(d->document->shapeController(), image, name);
}
FilterMask *Document::createFilterMask(const QString &name, Filter &filter)
FilterMask *Document::createFilterMask(const QString &name, Filter &filter, const Node *selection_source)
{
if (!d->document) return 0;
if (!d->document->image()) return 0;
if (!d->document)
return 0;
if (!d->document->image())
return 0;
if(!selection_source)
return 0;
KisLayerSP layer = qobject_cast<KisLayer*>(selection_source->node().data());
if(layer.isNull())
return 0;
KisImageSP image = d->document->image();
FilterMask* mask = new FilterMask(image, name, filter);
qobject_cast<KisMask*>(mask->node().data())->initSelection(layer);
return mask;
}
FilterMask *Document::createFilterMask(const QString &name, Filter &filter, Selection &selection)
{
if (!d->document)
return 0;
if (!d->document->image())
return 0;
KisImageSP image = d->document->image();
FilterMask* mask = new FilterMask(image, name, filter);
qobject_cast<KisMask*>(mask->node().data())->setSelection(selection.selection());
return new FilterMask(image, name, filter);
return mask;
}
SelectionMask *Document::createSelectionMask(const QString &name)
......
......@@ -648,9 +648,20 @@ print(root.childNodes())
* Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.
* @param name the name of the layer.
* @param filter the filter assigned.
* @param selection the selection to be used by the filter mask
* @return a FilterMask
*/
FilterMask* createFilterMask(const QString &name, Filter &filter);
FilterMask* createFilterMask(const QString &name, Filter &filter, Selection &selection);
/**
* @brief createFilterMask
* Creates a filter mask object that much like a filterlayer can apply a filter non-destructively.
* @param name the name of the layer.
* @param filter the filter assigned.
* @param selection_source a node from which the selection should be initialized
* @return a FilterMask
*/
FilterMask* createFilterMask(const QString &name, Filter &filter, const Node* selection_source);
/**
* @brief createSelectionMask
......
......@@ -68,7 +68,8 @@ public Q_SLOTS:
FilterLayer *createFilterLayer(const QString &name, Filter &filter, Selection &selection) /Factory/;
FillLayer *createFillLayer(const QString &name, const QString filterName, InfoObject &configuration, Selection &selection) /Factory/;
VectorLayer *createVectorLayer(const QString &name) /Factory/;
FilterMask *createFilterMask(const QString &name, Filter &filter) /Factory/;
FilterMask *createFilterMask(const QString &name, Filter &filter, Selection &selection) /Factory/;
FilterMask *createFilterMask(const QString &name, Filter &filter, const Node *selection_source) /Factory/;
SelectionMask *createSelectionMask(const QString &name) /Factory/;
QImage projection(int x = 0, int y = 0, int w = 0, int h = 0) const;
QImage thumbnail(int w, int h) 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