Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaintOpPreset Class Reference

#include <kis_paintop_preset.h>

+ Inheritance diagram for KisPaintOpPreset:

Classes

class  UpdatedPostponer
 The UpdatedPostponer class. More...
 
struct  UpdateListener
 

Public Member Functions

KoCanvasResourcesInterfaceSP canvasResourcesInterface () const
 
void clearSideLoadedResources () override
 
KoResourceSP clone () const override
 
KisPaintOpPresetSP cloneWithResourcesSnapshot (KisResourcesInterfaceSP globalResourcesInterface, KoCanvasResourcesInterfaceSP canvasResourcesInterface, KoResourceCacheInterfaceSP cacheInterface) const
 
KisPaintOpPresetSP createMaskingPreset () const
 
QString defaultFileExtension () const override
 
QList< KoResourceLoadResultembeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const override
 
void fromXML (const QDomElement &elt, KisResourcesInterfaceSP resourcesInterface)
 
bool hasLocalResourcesSnapshot () const
 
bool hasMaskingPreset () const
 
 KisPaintOpPreset ()
 
 KisPaintOpPreset (const KisPaintOpPreset &rhs)
 
 KisPaintOpPreset (const QString &filename)
 
QList< KoResourceLoadResultlinkedResources (KisResourcesInterfaceSP globalResourcesInterface) const override
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
QString name () const override
 
KisPaintOpPresetoperator= (const KisPaintOpPreset &rhs)=delete
 
KoID paintOp () const
 return the id of the paintop plugin
 
 Private (KisPaintOpPreset *q)
 
void regenerateResourceCache (KoResourceCacheInterfaceSP cacheInterface)
 
bool removable () const
 
QList< int > requiredCanvasResources () const override
 
KoResourceCacheInterfaceSP resourceCacheInterface () const
 
KisResourcesInterfaceSP resourcesInterface () const
 
QPair< QString, QString > resourceType () const override
 
bool sanityCheckResourceCacheIsValid (KoResourceCacheInterfaceSP cacheInterface) const
 
bool saveToDevice (QIODevice *dev) const override
 
void setCanvasResourcesInterface (KoCanvasResourcesInterfaceSP canvasResourcesInterface)
 
void setPaintOp (const KoID &paintOp)
 set the id of the paintop plugin
 
void setResourceCacheInterface (KoResourceCacheInterfaceSP cacheInterface)
 
void setResourcesInterface (KisResourcesInterfaceSP resourcesInterface)
 
void setSettings (KisPaintOpSettingsSP settings)
 replace the current settings object with the specified settings
 
KisPaintOpSettingsSP settings () const
 return the settings that define this paintop preset
 
QList< KoResourceLoadResultsideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const override
 
void toXML (QDomDocument &doc, QDomElement &elt) const
 
QList< KisUniformPaintOpPropertySPuniformProperties ()
 
void updateLinkedResourcesMetaData ()
 
QPointer< KisPaintOpPresetUpdateProxyupdateProxy () const
 
QPointer< KisPaintOpPresetUpdateProxyupdateProxyNoCreate () const
 
 ~KisPaintOpPreset () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoResource
bool active () const
 
void addMetaData (QString key, QVariant value)
 store the given key, value pair in the resource
 
QString filename () const
 
QImage image () const
 
bool isDirty () const
 
virtual bool isEphemeral () const
 
virtual bool isSerializable () const
 
 KoResource ()
 
 KoResource (const KoResource &rhs)
 
 KoResource (const QString &filename)
 
bool load (KisResourcesInterfaceSP resourcesInterface)
 
QString md5Sum (bool generateIfEmpty=true) const
 
QMap< QString, QVariant > metadata () const
 get a map with all the metadata
 
KoResourceoperator= (const KoResource &rhs)=delete
 
bool permanent () const
 
QList< KoResourceLoadResultrequiredResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
int resourceId () const
 
bool save ()
 
void setActive (bool active)
 
void setDirty (bool value)
 Mark the preset as modified but not saved.
 
void setFilename (const QString &filename)
 
void setImage (const QImage &image)
 
void setMD5Sum (const QString &md5sum)
 Set the md5sum of this resource. It must be in hex-encoded string format.
 
void setName (const QString &name)
 
void setPermanent (bool permanent)
 
void setResourceId (int id)
 
void setStorageLocation (const QString &location)
 
void setValid (bool valid)
 
void setVersion (int version)
 
KoResourceSignature signature () const
 
QString storageLocation () const
 
QList< KoResourceLoadResulttakeSideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface)
 
virtual QImage thumbnail () const
 thumbnail the thumbnail image to use in resource selectors
 
virtual QString thumbnailPath () const
 thumbnailPath returns the path to a separate thumbnail image, outside the actual resource file itself. If the path is relative, it is supposed start in the same location as the resource itself. If it's absolute, that is, it starts with "/", it is from the root of the storage.
 
virtual void updateThumbnail ()
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 

Public Attributes

KisPaintOpSettingsSP settings {0}
 
KisPaintOpSettings::UpdateListenerSP settingsUpdateListener
 
QList< KoResourceLoadResultsideLoadedResources
 
QScopedPointer< KisPaintOpPresetUpdateProxyupdateProxy
 
QString version
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Public Attributes inherited from KoResource
bool active {true}
 
QString filename
 
QImage image
 
QString md5sum
 
QMap< QString, QVariant > metadata
 
bool modified {false}
 
QString name
 
bool permanent {false}
 
int resourceId {-1}
 
QString storageLocation
 
bool valid {false}
 
int version {-1}
 

Private Attributes

Private *const d
 

Detailed Description

A KisPaintOpPreset contains a particular set of settings associated with a paintop, like brush, paintopsettings. A new property in this class is to make it dirty. That means the user can now temporarily save any tweaks in the Preset throughout the session. The Dirty Preset setting/unsetting is handled by KisPaintOpPresetSettings

KisPaintOpPreset is a serialized representation. That is, it stores only "metadata" needed to paint with a paintop. This metadata can be used to create painting c++-objects (e.g. brushes) or caches or embedded resources, but these objects are never stored inside the preset itself.

It is done intentionally, because our GUI elements work with "metadata" only. They just read/write strings into the XML document, they don't know anything about the internal structure of the preset's C++ object. Therefore, if we stored any caches/ resources inside the preset, they would become out-of-sync with the XML representation quite easily.

To overcome this issue, we use a set of provider-like interfaces to store caches/resources outside the preset:

1) KisResourcesInterface is the interface that lets the preset to fetch dependent resources from the centralized storage. Theoretically, the preset could create dependent resources from its XML representation internally all the time, but there are two reasons against that:

1) That is inefficient to load the brushes and/or textures for every stroke. It can create significant delay in the beginning of every stroke.

2) When we show an embedded resource in the GUI, it would be nice to know the resource's 'resourceId', so we could display it correctly. If we load the embedded resource every time, 'resourceId' field would be empty.

Abstract KisResourcesInterface also allows us to replace a link to the centralized storage with a snapshot of cloned resources, when we start rendering data in the non-gui thread.

2) KoCanvasResourcesInterface is the interface that lets the preset link to the global storage of "canvas resources", like current gradient, current fg color and current bg color.

When we start a stroke, we make a snapshot of the current state of the required canvas resources and replace the link to the global storage with the created local snapshot.

Please take it into account that some of the embedded/linked resources provided by KisResourcesInterface may change while cloning. It happens when these resources "bake" the state of canvas resources into themselves (e.g. gradient may change the "fg-stop" with real fg color).

3) KoResourceCacheInterface is an interface that provides a storage for the internal preset's caches (e.g. a brush with a pregenerated pyramid or a pregenerated template for a rotated pattern).

The cache interface link is reset when any change is made to the preset's metadata (which, effectively, resets all the caches).

The cache link should also be reset manually if the preset depends on some canvas resource (e.g. fg-color) and this canvas resource has changed. That is tracked by KisPresetShadowUpdater.

Definition at line 39 of file kis_paintop_preset.cpp.

Constructor & Destructor Documentation

◆ KisPaintOpPreset() [1/3]

KisPaintOpPreset::KisPaintOpPreset ( )

Definition at line 81 of file kis_paintop_preset.cpp.

82 : KoResource(QString())
83 , d(new Private(this))
84{
85}

◆ KisPaintOpPreset() [2/3]

KisPaintOpPreset::KisPaintOpPreset ( const QString & filename)

Definition at line 87 of file kis_paintop_preset.cpp.

88 : KoResource(fileName)
89 , d(new Private(this))
90{
91 setName(name().replace("_", " "));
92}
QAction * replace(const QObject *recvr, const char *slot, QObject *parent)
QString name() const override
void setName(const QString &name)

References name(), and KoResource::setName().

◆ ~KisPaintOpPreset()

KisPaintOpPreset::~KisPaintOpPreset ( )
override

Definition at line 94 of file kis_paintop_preset.cpp.

95{
96 delete d;
97}

References d.

◆ KisPaintOpPreset() [3/3]

KisPaintOpPreset::KisPaintOpPreset ( const KisPaintOpPreset & rhs)

Definition at line 99 of file kis_paintop_preset.cpp.

100 : KoResource(rhs)
101 , d(new Private(this))
102{
103 if (rhs.settings()) {
104 setSettings(rhs.settings()); // the settings are cloned inside!
105 }
107 // only valid if we could clone the settings
108 setValid(rhs.settings());
109
110 setName(rhs.name());
111 setImage(rhs.image());
112}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
void setSettings(KisPaintOpSettingsSP settings)
replace the current settings object with the specified settings
KisPaintOpSettingsSP settings
void setValid(bool valid)
QImage image
void setImage(const QImage &image)
bool isDirty() const

References KoResource::image, KoResource::isDirty(), KIS_SAFE_ASSERT_RECOVER_NOOP, name(), KoResource::setImage(), KoResource::setName(), setSettings(), settings, and KoResource::setValid().

Member Function Documentation

◆ canvasResourcesInterface()

KoCanvasResourcesInterfaceSP KisPaintOpPreset::canvasResourcesInterface ( ) const

Returns canvas resources interface associated with the current preset.

In contrast to resourcesInterface() the canvas resources interface may be null, because the preset is created without any canvas resources. The resources are assigned to the preset only when the ser starts to paint with it.

The preset has no default canvas resources interface, because canvas resources are unique per-canvas, but the presets are unique per- application. Therefore association between the preset and canvas resources interface would be ambiguous.

Definition at line 494 of file kis_paintop_preset.cpp.

495{
496 return d->settings ? d->settings->canvasResourcesInterface() : nullptr;
497}

References d.

◆ clearSideLoadedResources()

void KisPaintOpPreset::clearSideLoadedResources ( )
overridevirtual

Clears memory under side-loaded resources. The method is called by KisResourceLocator after the resources have been fetched and added to the global store.

Reimplemented from KoResource.

Definition at line 604 of file kis_paintop_preset.cpp.

605{
606 d->sideLoadedResources.clear();
607}

References d.

◆ clone()

KoResourceSP KisPaintOpPreset::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 114 of file kis_paintop_preset.cpp.

115{
116 return KoResourceSP(new KisPaintOpPreset(*this));
117}
QSharedPointer< KoResource > KoResourceSP

References KisPaintOpPreset().

◆ cloneWithResourcesSnapshot()

KisPaintOpPresetSP KisPaintOpPreset::cloneWithResourcesSnapshot ( KisResourcesInterfaceSP globalResourcesInterface,
KoCanvasResourcesInterfaceSP canvasResourcesInterface,
KoResourceCacheInterfaceSP cacheInterface ) const
See also
KisRequiredResourcesOperators::cloneWithResourcesSnapshot

If the preset depends on any canvas resources, then we don't trust the caches that are stored inside. Instead we just reset them. If the preset is independent of the canvas resources, then its caches are, most probably valid and we can reuse them.

Definition at line 510 of file kis_paintop_preset.cpp.

511{
512 KisPaintOpPresetSP result =
513 KisRequiredResourcesOperators::cloneWithResourcesSnapshot<KisPaintOpPresetSP>(this, globalResourcesInterface);
514
515 const QList<int> canvasResources = result->requiredCanvasResources();
516 if (!canvasResources.isEmpty()) {
518 Q_FOREACH (int key, canvasResources) {
519 storage->storeResource(key, canvasResourcesInterface->resource(key));
520 }
521 result->setCanvasResourcesInterface(storage);
522 }
523
524 if (cacheInterface) {
525 result->setResourceCacheInterface(cacheInterface);
526 } else if (!canvasResources.isEmpty()) {
533 result->setResourceCacheInterface(nullptr);
534 }
535
536 return result;
537}
KoCanvasResourcesInterfaceSP canvasResourcesInterface() const

References canvasResourcesInterface().

◆ createMaskingPreset()

KisPaintOpPresetSP KisPaintOpPreset::createMaskingPreset ( ) const
Returns
a newly created preset of the masked brush that should be run alongside the current brush

Definition at line 468 of file kis_paintop_preset.cpp.

469{
470 KisPaintOpPresetSP result;
471
472 if (d->settings && d->settings->hasMaskingSettings()) {
473 result.reset(new KisPaintOpPreset());
474 result->setSettings(d->settings->createMaskingSettings());
475 if (!result->valid()) {
476 result.clear();
477 }
478 }
479
480 return result;
481}

References d, and KisPaintOpPreset().

◆ defaultFileExtension()

QString KisPaintOpPreset::defaultFileExtension ( ) const
inlineoverridevirtual
Returns
the default file extension which should be used when saving the resource

Reimplemented from KoResource.

Definition at line 159 of file kis_paintop_preset.h.

159 {
160 return ".kpp";
161 }

◆ embeddedResources()

QList< KoResourceLoadResult > KisPaintOpPreset::embeddedResources ( KisResourcesInterfaceSP globalResourcesInterface) const
overridevirtual
Returns
all the resources that were embedded into (*this) resource. If the resources were already added to the global database, then they are fetched from globalResourcesInterface to save time/memory.

These resources are embedded into the resource itself and are available throughout the entire lifetime of the resource.

Reimplemented from KoResource.

Definition at line 562 of file kis_paintop_preset.cpp.

563{
565
566 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(d->settings, resources);
567
570 resources << f->prepareEmbeddedResources(d->settings, globalResourcesInterface);
571
572 if (hasMaskingPreset()) {
573 KisPaintOpPresetSP maskingPreset = createMaskingPreset();
574 Q_ASSERT(maskingPreset);
575 KisPaintOpFactory* f = KisPaintOpRegistry::instance()->value(maskingPreset->paintOp().id());
577 resources << f->prepareEmbeddedResources(maskingPreset->settings(), globalResourcesInterface);
578
579 }
580
581 return resources;
582}
static KisPaintOpRegistry * instance()
const T value(const QString &id) const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
KoID paintOp() const
return the id of the paintop plugin
bool hasMaskingPreset() const
KisPaintOpPresetSP createMaskingPreset() const

References createMaskingPreset(), d, hasMaskingPreset(), KisPaintOpRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, paintOp(), and KoGenericRegistry< T >::value().

◆ fromXML()

void KisPaintOpPreset::fromXML ( const QDomElement & elt,
KisResourcesInterfaceSP resourcesInterface )

Definition at line 323 of file kis_paintop_preset.cpp.

324{
325 setName(presetElt.attribute("name"));
326 QString paintopid = presetElt.attribute("paintopid");
327
328 if (!metadata().contains("paintopid")) {
329 addMetaData("paintopid", paintopid);
330 }
331
332 if (paintopid.isEmpty()) {
333 dbgImage << "No paintopid attribute";
334 setValid(false);
335 return;
336 }
337
338 if (KisPaintOpRegistry::instance()->get(paintopid) == 0) {
339 dbgImage << "No paintop " << paintopid;
340 setValid(false);
341 return;
342 }
343
344 KoID id(paintopid, QString());
345
347 if (!settings) {
348 setValid(false);
349 warnKrita << "Could not load settings for preset" << paintopid;
350 return;
351 }
352
353 settings->fromXML(presetElt);
354
355 // sanitize the settings
356 bool hasTexture = settings->getBool("Texture/Pattern/Enabled");
357 if (!hasTexture) {
358 Q_FOREACH (const QString & key, settings->getProperties().keys()) {
359 if (key.startsWith("Texture") && key != "Texture/Pattern/Enabled") {
360 settings->removeProperty(key);
361 }
362 }
363 }
365
366}
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
KisPaintOpSettingsSP createSettings(const KoID &id, KisResourcesInterfaceSP resourcesInterface) const
Definition KoID.h:30
#define warnKrita
Definition kis_debug.h:87
#define dbgImage
Definition kis_debug.h:46
KisResourcesInterfaceSP resourcesInterface() const
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource
QMap< QString, QVariant > metadata

References KoResource::addMetaData(), KisPaintOpRegistry::createSettings(), dbgImage, get(), KisPaintOpRegistry::instance(), KoResource::metadata, resourcesInterface(), KoResource::setName(), setSettings(), settings, KoResource::setValid(), and warnKrita.

◆ hasLocalResourcesSnapshot()

bool KisPaintOpPreset::hasLocalResourcesSnapshot ( ) const

◆ hasMaskingPreset()

bool KisPaintOpPreset::hasMaskingPreset ( ) const
Returns
true if this preset demands a secondary masked brush running alongside it

Definition at line 463 of file kis_paintop_preset.cpp.

464{
465 return d->settings && d->settings->hasMaskingSettings();
466}

References d.

◆ linkedResources()

QList< KoResourceLoadResult > KisPaintOpPreset::linkedResources ( KisResourcesInterfaceSP globalResourcesInterface) const
overridevirtual
Returns
all the resources that are needed but (*this) resource and are not embedded into it. The resources are fetched from globalResourcesInterface. If fetching of some resources is failed, then (*this) resource is invalid.

Reimplemented from KoResource.

Definition at line 539 of file kis_paintop_preset.cpp.

540{
542
543 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(d->settings, resources);
544
547 resources << f->prepareLinkedResources(d->settings, globalResourcesInterface);
548
549 if (hasMaskingPreset()) {
550 KisPaintOpPresetSP maskingPreset = createMaskingPreset();
551 Q_ASSERT(maskingPreset);
552
553 KisPaintOpFactory* f = KisPaintOpRegistry::instance()->value(maskingPreset->paintOp().id());
555 resources << f->prepareLinkedResources(maskingPreset->settings(), globalResourcesInterface);
556
557 }
558
559 return resources;
560}

References createMaskingPreset(), d, hasMaskingPreset(), KisPaintOpRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, paintOp(), and KoGenericRegistry< T >::value().

◆ loadFromDevice()

bool KisPaintOpPreset::loadFromDevice ( QIODevice * dev,
KisResourcesInterfaceSP resourcesInterface )
overridevirtual

Implements KoResource.

Definition at line 168 of file kis_paintop_preset.cpp.

169{
170 QImageReader reader(dev, "PNG");
171
172 d->version = reader.text("version");
173 QString preset = reader.text("preset");
174
175 if (!(d->version == "2.2" || d->version == "5.0")) {
176 return false;
177 }
178
179 QImage img;
180 if (!reader.read(&img)) {
181 dbgImage << "Fail to decode PNG";
182 return false;
183 }
184
185 //Workaround for broken presets
186 //Presets was saved with nested cdata section
187 preset.replace("<curve><![CDATA[", "<curve>");
188 preset.replace("]]></curve>", "</curve>");
189 //Presets with non-base64 pattern md5
190 QRegularExpressionMatch patternMd5 = QRegularExpression("<param (?:type=\"string\" )?name=\"Texture/Pattern/PatternMD5\"(?: type=\"string\")?><!\\[CDATA\\[(.+?)\\]\\]></param>").match(preset);
191 if (patternMd5.hasMatch() && patternMd5.captured(1).contains(QRegularExpression("[^a-zA-Z0-9+/=]"))) {
192 preset.replace(patternMd5.captured(0), "");
193 }
194
195 QDomDocument doc;
196 if (!doc.setContent(preset)) {
197 return false;
198 }
199
200 QDomElement root = doc.documentElement();
201
202 if (d->version == "5.0") {
203 // Load any embedded resources
204 QDomElement e = root.firstChildElement("resources");
205 if (!e.isNull()) {
206 for (e = e.firstChildElement("resource"); !e.isNull(); e = e.nextSiblingElement("resource")) {
207 QString name = e.attribute("name");
208 QString filename = e.attribute("filename");
209 QString resourceType = e.attribute("type");
210 QString md5sum = e.attribute("md5sum");
211
212 KoResourceSP existingResource = resourcesInterface
213 ->source(resourceType)
214 .bestMatch(md5sum, filename, name);
215
216 if (existingResource) {
217 continue;
218 }
219
220 QByteArray ba = QByteArray::fromBase64(e.text().toLatin1());
221 QBuffer buf(&ba);
222 buf.open(QBuffer::ReadOnly);
223
224 d->sideLoadedResources.append(
227 ba));
228 }
229 }
230 }
231
233
234 if (!d->settings) {
235 return false;
236 }
237
238 setValid(d->settings->isValid());
239
240 if (!img.textKeys().isEmpty()) {
241 QImage strippedImage(img.size(), img.format());
242 memcpy(strippedImage.bits(), img.bits(), img.sizeInBytes());
243
244 if (img.format() == QImage::Format_Indexed8) {
245 strippedImage.setColorTable(img.colorTable());
246 }
247
248 setImage(strippedImage);
249 } else {
250 setImage(img);
251 }
252
254
255 return true;
256}
A simple wrapper object for the main information about the resource.
void fromXML(const QDomElement &elt, KisResourcesInterfaceSP resourcesInterface)
QPair< QString, QString > resourceType() const override
QString filename
QString md5sum

References d, dbgImage, KoResource::filename, fromXML(), KoResource::md5sum, name(), resourcesInterface(), resourceType(), KoResource::setImage(), KoResource::setValid(), and updateLinkedResourcesMetaData().

◆ name()

QString KisPaintOpPreset::name ( ) const
overridevirtual
Returns
the user-visible name of the resource

Reimplemented from KoResource.

Definition at line 131 of file kis_paintop_preset.cpp.

132{
133 return KoResource::name().replace("_", " ");
134}
QString name

References KoResource::name.

◆ operator=()

KisPaintOpPreset & KisPaintOpPreset::operator= ( const KisPaintOpPreset & rhs)
delete

◆ paintOp()

KoID KisPaintOpPreset::paintOp ( ) const

return the id of the paintop plugin

Definition at line 125 of file kis_paintop_preset.cpp.

126{
127 Q_ASSERT(d->settings);
128 return KoID(d->settings->getString("paintop"));
129}

References d.

◆ Private()

KisPaintOpPreset::Private ( KisPaintOpPreset * q)
inline

Definition at line 67 of file kis_paintop_preset.cpp.

68 : settingsUpdateListener(new UpdateListener(q)),
69 version("5.0")
70 {
71 }
KisPaintOpSettings::UpdateListenerSP settingsUpdateListener

◆ regenerateResourceCache()

void KisPaintOpPreset::regenerateResourceCache ( KoResourceCacheInterfaceSP cacheInterface)

Recalculates all the internal caches and stores them in the cache interface.

Definition at line 625 of file kis_paintop_preset.cpp.

626{
628
629 d->settings->regenerateResourceCache(cacheInterface);
630 cacheInterface->setRelatedResourceCookie(d->settings->sanityVersionCookie());
631}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References d, and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ removable()

bool KisPaintOpPreset::removable ( ) const
inline

Definition at line 155 of file kis_paintop_preset.h.

155 {
156 return true;
157 }

◆ requiredCanvasResources()

QList< int > KisPaintOpPreset::requiredCanvasResources ( ) const
overridevirtual

A list of per-canvas active resources that are needed for this resource to function properly. E.g. some gradients may require Fg/Bg colors and some presets would like to know about the current gradient selection.

Returns
a list of canvas resources needed for the current resource

Reimplemented from KoResource.

Definition at line 609 of file kis_paintop_preset.cpp.

610{
611 return d->settings ? d->settings->requiredCanvasResources() : QList<int>();
612}

References d.

◆ resourceCacheInterface()

KoResourceCacheInterfaceSP KisPaintOpPreset::resourceCacheInterface ( ) const

Return the saved cache interface or null if not available

Definition at line 620 of file kis_paintop_preset.cpp.

621{
622 return d->settings ? d->settings->resourceCacheInterface() : KoResourceCacheInterfaceSP();
623}
QSharedPointer< KoResourceCacheInterface > KoResourceCacheInterfaceSP

References d.

◆ resourcesInterface()

KisResourcesInterfaceSP KisPaintOpPreset::resourcesInterface ( ) const
Returns
resource interface that is used by KisPaintOpSettings object for loading linked resources

Definition at line 483 of file kis_paintop_preset.cpp.

484{
485 return d->settings ? d->settings->resourcesInterface() : nullptr;
486}

References d.

◆ resourceType()

QPair< QString, QString > KisPaintOpPreset::resourceType ( ) const
inlineoverridevirtual
Returns
the resource type

Implements KoResource.

Definition at line 144 of file kis_paintop_preset.h.

145 {
146 return QPair<QString, QString>(ResourceType::PaintOpPresets, "");
147 }
const QString PaintOpPresets

References ResourceType::PaintOpPresets.

◆ sanityCheckResourceCacheIsValid()

bool KisPaintOpPreset::sanityCheckResourceCacheIsValid ( KoResourceCacheInterfaceSP cacheInterface) const

Verifies if the cache object was actually created for this preset. It actually does anything only when a corresponding define is added in kis_paintop_settings.cpp. Otherwise it just returns true;

Definition at line 633 of file kis_paintop_preset.cpp.

634{
635 return d->settings->sanityVersionCookie() == cacheInterface->relatedResourceCookie();
636}

References d.

◆ saveToDevice()

bool KisPaintOpPreset::saveToDevice ( QIODevice * dev) const
overridevirtual

HACK ALERT: We update the version of the resource format on the first save operation, even though there is no guarantee that it was "save" operation, but not "export" operation.

The only point it affects now is whether we need to check for the presence of the linkedResources() in updateLinkedResourcesMetaData(). The new version of the preset format ("5.0") has all the linked resources embedded outside KisPaintOpSettings, which are automatically loaded on the resource activation. We we shouldn't add them into metaData()["dependent_resources_filenames"].

Reimplemented from KoResource.

Definition at line 368 of file kis_paintop_preset.cpp.

369{
370 QImageWriter writer(dev, "PNG");
371
372 QDomDocument doc;
373 QDomElement root = doc.createElement("Preset");
374
375 toXML(doc, root);
376
377 doc.appendChild(root);
378
392 d->version = "5.0";
393
395
396 writer.setText("version", d->version);
397 writer.setText("preset", doc.toString());
398
399 QImage img;
400
401 if (image().isNull()) {
402 img = QImage(1, 1, QImage::Format_RGB32);
403 } else {
404 img = image();
405 }
406
407 return writer.write(img);
408}
void toXML(QDomDocument &doc, QDomElement &elt) const

References d, KoResource::image, toXML(), and updateLinkedResourcesMetaData().

◆ setCanvasResourcesInterface()

void KisPaintOpPreset::setCanvasResourcesInterface ( KoCanvasResourcesInterfaceSP canvasResourcesInterface)

Sets canvas resources interface used for initializing the preset

See also
canvasResourcesInterface()

Definition at line 499 of file kis_paintop_preset.cpp.

500{
502 d->settings->setCanvasResourcesInterface(canvasResourcesInterface);
503}

References canvasResourcesInterface(), d, and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ setPaintOp()

void KisPaintOpPreset::setPaintOp ( const KoID & paintOp)

set the id of the paintop plugin

Definition at line 119 of file kis_paintop_preset.cpp.

120{
121 Q_ASSERT(d->settings);
122 d->settings->setProperty("paintop", paintOp.id());
123}
QString id() const
Definition KoID.cpp:63

References d, KoID::id(), and paintOp().

◆ setResourceCacheInterface()

void KisPaintOpPreset::setResourceCacheInterface ( KoResourceCacheInterfaceSP cacheInterface)

Set resource cache object generated for this preset (or its clone). After calling this method with non-null cache interface all the internal caches of this preset will be initialized. The cache interface itself will be stored inside the preset and will be preserved while cloning the preset.

Changing any property of the preset will reset both, internal caches and cache interface to null.

Calling this method with nullptr resets internal caches. It is needed, e.g. when some canvas resources have changed (

See also
requiredCanvasResources()).

Definition at line 614 of file kis_paintop_preset.cpp.

615{
617 d->settings->setResourceCacheInterface(cacheInterface);
618}

References d, and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ setResourcesInterface()

void KisPaintOpPreset::setResourcesInterface ( KisResourcesInterfaceSP resourcesInterface)

Set resource interface that will be used by KisPaintOpSettings object for loading linked resources

Definition at line 488 of file kis_paintop_preset.cpp.

489{
491 d->settings->setResourcesInterface(resourcesInterface);
492}

References d, KIS_SAFE_ASSERT_RECOVER_RETURN, and resourcesInterface().

◆ setSettings()

void KisPaintOpPreset::setSettings ( KisPaintOpSettingsSP settings)

replace the current settings object with the specified settings

Definition at line 136 of file kis_paintop_preset.cpp.

137{
138 Q_ASSERT(settings);
139 Q_ASSERT(!settings->getString("paintop", QString()).isEmpty());
140
141 KisDirtyStateSaver<KisPaintOpPreset*> dirtyStateSaver(this);
142
143 if (d->settings) {
144 d->settings->setUpdateListener(KisPaintOpSettings::UpdateListenerWSP());
145 d->settings = 0;
146 }
147
148 if (settings) {
149 d->settings = settings->clone();
150 d->settings->setUpdateListener(d->settingsUpdateListener);
151 }
152
153 if (d->updateProxy) {
154 d->updateProxy->notifyUniformPropertiesChanged();
155 d->updateProxy->notifySettingsChanged();
156 }
157 setValid(true);
158}

References d, settings, and KoResource::setValid().

◆ settings()

KisPaintOpSettingsSP KisPaintOpPreset::settings ( ) const

return the settings that define this paintop preset

◆ sideLoadedResources()

QList< KoResourceLoadResult > KisPaintOpPreset::sideLoadedResources ( KisResourcesInterfaceSP globalResourcesInterface) const
overridevirtual

Side-loaded resources are the resources embedded into the file format and loaded alongside the main resource. After being loaded in loadFromDevice() they are stored separately and may be fetched by the resource locator.

After the locator has loaded them into the global storage, it can free the memory by calling clearSideLoadedResources().

Reimplemented from KoResource.

◆ toXML()

void KisPaintOpPreset::toXML ( QDomDocument & doc,
QDomElement & elt ) const

Definition at line 258 of file kis_paintop_preset.cpp.

259{
260 QString paintopid = d->settings->getString("paintop", QString());
261
262 elt.setAttribute("paintopid", paintopid);
263 elt.setAttribute("name", name());
264
265
267
268 elt.setAttribute("embedded_resources", linkedResources.count());
269
270 if (!linkedResources.isEmpty()) {
271 QDomElement resourcesElement = doc.createElement("resources");
272 elt.appendChild(resourcesElement);
273 Q_FOREACH(KoResourceLoadResult linkedResource, linkedResources) {
274 // we have requested linked resources, how can it be an embedded one?
276
277 KoResourceSP resource = linkedResource.resource();
278
279 if (!resource) {
280 qWarning() << "WARNING: KisPaintOpPreset::toXML couldn't fetch a linked resource" << linkedResource.signature();
281 continue;
282 }
283
284 //KIS_SAFE_ASSERT_RECOVER_NOOP(resource->isSerializable() && "embedding non-serializable resources is not yet implemented");
285 if (!resource->isSerializable()) {
286 qWarning() << "embedding non-serializable resources is not yet implemented. Resource: " << filename() << name()
287 << "cannot embed" << resource->filename() << resource->name() << resource->resourceType().first << resource->resourceType().second;
288 continue;
289 }
290
291 QBuffer buf;
292 buf.open(QBuffer::WriteOnly);
293 KisResourceModel model(resource->resourceType().first);
294 bool r = model.exportResource(resource, &buf);
295 buf.close();
296 if (r) {
297 QDomText text = doc.createCDATASection(QString::fromLatin1(buf.data().toBase64()));
298 QDomElement e = doc.createElement("resource");
299 e.setAttribute("type", resource->resourceType().first);
300 e.setAttribute("md5sum", resource->md5Sum());
301 e.setAttribute("name", resource->name());
302 e.setAttribute("filename", resource->filename());
303 e.appendChild(text);
304 resourcesElement.appendChild(e);
305
306 }
307 }
308 }
309
310 // sanitize the settings
311 bool hasTexture = d->settings->getBool("Texture/Pattern/Enabled");
312 if (!hasTexture) {
313 Q_FOREACH (const QString & key, d->settings->getProperties().keys()) {
314 if (key.startsWith("Texture") && key != "Texture/Pattern/Enabled") {
315 d->settings->removeProperty(key);
316 }
317 }
318 }
319
320 d->settings->toXML(doc, elt);
321}
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
KoResourceSP resource() const noexcept
KoResourceSignature signature() const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
QList< KoResourceLoadResult > linkedResources(KisResourcesInterfaceSP globalResourcesInterface) const override

References d, KoResourceLoadResult::EmbeddedResource, KisResourceModel::exportResource(), KoResource::filename, KIS_SAFE_ASSERT_RECOVER, linkedResources(), name(), KoResourceLoadResult::resource(), resourcesInterface(), KoResourceLoadResult::signature(), and KoResourceLoadResult::type().

◆ uniformProperties()

QList< KisUniformPaintOpPropertySP > KisPaintOpPreset::uniformProperties ( )

we pass a shared pointer to settings explicitly, because the settings will not be able to wrap itself into a shared pointer

Definition at line 455 of file kis_paintop_preset.cpp.

456{
460 return d->settings->uniformProperties(d->settings, updateProxy());
461}
QScopedPointer< KisPaintOpPresetUpdateProxy > updateProxy

References d, and updateProxy.

◆ updateLinkedResourcesMetaData()

void KisPaintOpPreset::updateLinkedResourcesMetaData ( )

The new preset format embeds all the linked resources outside KisPaintOpSettings and loads them on activation, therefore we shouldn't add them into "dependent_resources_filenames".

Definition at line 410 of file kis_paintop_preset.cpp.

411{
418 if (d->version == "2.2") {
419 KisResourcesInterfaceSP fakeResourcesInterface(new KisLocalStrokeResources());
420 QList<KoResourceLoadResult> dependentResources = this->linkedResources(fakeResourcesInterface);
421
422 QStringList resourceFileNames;
423
424 Q_FOREACH (KoResourceLoadResult resource, dependentResources) {
425 const QString filename = resource.signature().filename;
426
427 if (!filename.isEmpty()) {
428 resourceFileNames.append(filename);
429 }
430 }
431
432 KritaUtils::makeContainerUnique(resourceFileNames);
433
434 if (!resourceFileNames.isEmpty()) {
435 addMetaData("dependent_resources_filenames", resourceFileNames);
436 }
437 } else {
438 addMetaData("dependent_resources_filenames", QStringList());
439 }
440}
QList< QString > QStringList
a KisResourcesInterface-like resources storage for preloaded resources
void makeContainerUnique(C &container)

References KoResource::addMetaData(), d, KoResource::filename, KoResourceSignature::filename, linkedResources(), KritaUtils::makeContainerUnique(), and KoResourceLoadResult::signature().

◆ updateProxy()

QPointer< KisPaintOpPresetUpdateProxy > KisPaintOpPreset::updateProxy ( ) const

◆ updateProxyNoCreate()

QPointer< KisPaintOpPresetUpdateProxy > KisPaintOpPreset::updateProxyNoCreate ( ) const

Definition at line 450 of file kis_paintop_preset.cpp.

451{
452 return d->updateProxy.data();
453}

References d.

Member Data Documentation

◆ d

Private* const KisPaintOpPreset::d
private

Definition at line 271 of file kis_paintop_preset.h.

◆ settings

KisPaintOpSettingsSP KisPaintOpPreset::settings {0}

Definition at line 73 of file kis_paintop_preset.cpp.

73{0};

◆ settingsUpdateListener

KisPaintOpSettings::UpdateListenerSP KisPaintOpPreset::settingsUpdateListener

Definition at line 75 of file kis_paintop_preset.cpp.

◆ sideLoadedResources

QList< KoResourceLoadResult > KisPaintOpPreset::sideLoadedResources

Do not load the existing resources. There is no use for it.

Definition at line 77 of file kis_paintop_preset.cpp.

◆ updateProxy

QPointer< KisPaintOpPresetUpdateProxy > KisPaintOpPreset::updateProxy

Definition at line 74 of file kis_paintop_preset.cpp.

◆ version

QString KisPaintOpPreset::version

Definition at line 76 of file kis_paintop_preset.cpp.


The documentation for this class was generated from the following files: