Krita

FillLayer.cpp
1 /*
2  * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #include "FillLayer.h"
7 #include <kis_generator_layer.h>
8 #include <kis_image.h>
9 #include <kis_filter_configuration.h>
10 #include <kis_generator_registry.h>
11 #include <InfoObject.h>
12 #include <kis_selection.h>
13 #include <KisGlobalResourcesInterface.h>
14 #include <kis_assert.h>
15 
16 FillLayer::FillLayer(KisImageSP image, QString name, KisFilterConfigurationSP filterConfig, Selection &selection, QObject *parent) :
17  Node(image, new KisGeneratorLayer(image, name, filterConfig->cloneWithResourcesSnapshot(), selection.selection()), parent)
18 {
19 
20 }
21 
22 FillLayer::FillLayer(KisGeneratorLayerSP layer, QObject *parent):
23  Node(layer->image(), layer, parent)
24 {
25 
26 }
27 
28 FillLayer::~FillLayer()
29 {
30 
31 }
32 
33 QString FillLayer::generatorName()
34 {
35  const KisGeneratorLayer *layer = qobject_cast<const KisGeneratorLayer*>(this->node());
36  return layer->filter()->name();
37 }
38 
39 InfoObject * FillLayer::filterConfig()
40 {
41  const KisGeneratorLayer *layer = qobject_cast<const KisGeneratorLayer*>(this->node());
42  return new InfoObject(layer->filter());
43 }
44 
46 {
47  return "filllayer";
48 }
49 
50 bool FillLayer::setGenerator(const QString &generatorName, InfoObject *config)
51 {
52  KisGeneratorLayer *layer = dynamic_cast<KisGeneratorLayer*>(this->node().data());
53  KIS_ASSERT_RECOVER_RETURN_VALUE(layer, false);
54 
55  //getting the default configuration here avoids trouble with versioning.
56  KisGeneratorSP generator = KisGeneratorRegistry::instance()->value(generatorName);
57 
58  if (generator) {
59  KisFilterConfigurationSP cfg = generator->factoryConfiguration(KisGlobalResourcesInterface::instance());
60  Q_FOREACH(const QString property, config->properties().keys()) {
61  cfg->setProperty(property, config->property(property));
62  }
63  layer->setFilter(cfg->cloneWithResourcesSnapshot(), false);
64  if (layer->hasPendingTimedUpdates()) {
65  layer->forceUpdateTimedNode();
66  }
67  image()->waitForDone();
68  return true;
69  }
70  return false;
71 }
InfoObject wrap a properties map.
Definition: InfoObject.h:19
virtual QString type() const override
type Krita has several types of nodes, split in layers and masks.
Definition: FillLayer.cpp:45
FillLayer(KisImageSP image, QString name, KisFilterConfigurationSP filterConfig, Selection &selection, QObject *parent=0)
FillLayer Create a new fill layer with the given generator plugin.
Definition: FillLayer.cpp:16
Selection represents a selection on Krita.
Definition: Selection.h:30
bool setGenerator(const QString &generatorName, InfoObject *filterConfig)
setGenerator set the given generator for this fill layer
Definition: FillLayer.cpp:50
Node represents a layer or mask in a Krita image's Node hierarchy.
Definition: Node.h:21
QVariant property(const char *name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 04:09:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.