File indexing completed on 2024-05-12 15:59:05
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "FillLayer.h" 0007 #include <kis_generator_layer.h> 0008 #include <kis_image.h> 0009 #include <kis_filter_configuration.h> 0010 #include <kis_generator_registry.h> 0011 #include <InfoObject.h> 0012 #include <kis_selection.h> 0013 #include <KisGlobalResourcesInterface.h> 0014 #include <kis_assert.h> 0015 0016 FillLayer::FillLayer(KisImageSP image, QString name, KisFilterConfigurationSP filterConfig, Selection &selection, QObject *parent) : 0017 Node(image, new KisGeneratorLayer(image, name, filterConfig->cloneWithResourcesSnapshot(), selection.selection()), parent) 0018 { 0019 0020 } 0021 0022 FillLayer::FillLayer(KisGeneratorLayerSP layer, QObject *parent): 0023 Node(layer->image(), layer, parent) 0024 { 0025 0026 } 0027 0028 FillLayer::~FillLayer() 0029 { 0030 0031 } 0032 0033 QString FillLayer::generatorName() 0034 { 0035 const KisGeneratorLayer *layer = qobject_cast<const KisGeneratorLayer*>(this->node()); 0036 return layer->filter()->name(); 0037 } 0038 0039 InfoObject * FillLayer::filterConfig() 0040 { 0041 const KisGeneratorLayer *layer = qobject_cast<const KisGeneratorLayer*>(this->node()); 0042 return new InfoObject(layer->filter()); 0043 } 0044 0045 QString FillLayer::type() const 0046 { 0047 return "filllayer"; 0048 } 0049 0050 bool FillLayer::setGenerator(const QString &generatorName, InfoObject *config) 0051 { 0052 KisGeneratorLayer *layer = dynamic_cast<KisGeneratorLayer*>(this->node().data()); 0053 KIS_ASSERT_RECOVER_RETURN_VALUE(layer, false); 0054 0055 //getting the default configuration here avoids trouble with versioning. 0056 KisGeneratorSP generator = KisGeneratorRegistry::instance()->value(generatorName); 0057 0058 if (generator) { 0059 KisFilterConfigurationSP cfg = generator->factoryConfiguration(KisGlobalResourcesInterface::instance()); 0060 Q_FOREACH(const QString property, config->properties().keys()) { 0061 cfg->setProperty(property, config->property(property)); 0062 } 0063 layer->setFilter(cfg->cloneWithResourcesSnapshot(), false); 0064 if (layer->hasPendingTimedUpdates()) { 0065 layer->forceUpdateTimedNode(); 0066 } 0067 image()->waitForDone(); 0068 return true; 0069 } 0070 return false; 0071 }