Krita

FillLayer.cpp
1/*
2 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
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
16FillLayer::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
22FillLayer::FillLayer(KisGeneratorLayerSP layer, QObject *parent):
23 Node(layer->image(), layer, parent)
24{
25
26}
27
28FillLayer::~FillLayer()
29{
30
31}
32
33QString FillLayer::generatorName()
34{
35 const KisGeneratorLayer *layer = qobject_cast<const KisGeneratorLayer*>(this->node());
36 return layer->filter()->name();
37}
38
39InfoObject * 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
50bool 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}
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
bool setGenerator(const QString &generatorName, InfoObject *filterConfig)
setGenerator set the given generator for this fill layer
Definition FillLayer.cpp:50
InfoObject wrap a properties map.
Definition InfoObject.h:20
QVariant property(const QString &key)
return the value for the property identified by key, or None if there is no such key.
QMap< QString, QVariant > properties() const
Return all properties this InfoObject manages.
Node represents a layer or mask in a Krita image's Node hierarchy.
Definition Node.h:24
Selection represents a selection on Krita.
Definition Selection.h:31
QVariant property(const char *name) const const
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.