|
Krita Source Code Documentation
|
#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< KoResourceLoadResult > | embeddedResources (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< KoResourceLoadResult > | linkedResources (KisResourcesInterfaceSP globalResourcesInterface) const override |
| bool | loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override |
| QString | name () const override |
| KisPaintOpPreset & | operator= (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< KoResourceLoadResult > | sideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const override |
| void | toXML (QDomDocument &doc, QDomElement &elt) const |
| QList< KisUniformPaintOpPropertySP > | uniformProperties () |
| void | updateLinkedResourcesMetaData () |
| QPointer< KisPaintOpPresetUpdateProxy > | updateProxy () const |
| QPointer< KisPaintOpPresetUpdateProxy > | updateProxyNoCreate () 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 | |
| KoResource & | operator= (const KoResource &rhs)=delete |
| bool | permanent () const |
| QList< KoResourceLoadResult > | requiredResources (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< KoResourceLoadResult > | takeSideLoadedResources (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< KoResourceLoadResult > | sideLoadedResources |
| QScopedPointer< KisPaintOpPresetUpdateProxy > | updateProxy |
| QString | version |
Public Attributes inherited from Private | |
| KisCanvas2 * | canvas |
| 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 |
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.
| KisPaintOpPreset::KisPaintOpPreset | ( | ) |
Definition at line 81 of file kis_paintop_preset.cpp.
| KisPaintOpPreset::KisPaintOpPreset | ( | const QString & | filename | ) |
Definition at line 87 of file kis_paintop_preset.cpp.
References name(), and KoResource::setName().
|
override |
| KisPaintOpPreset::KisPaintOpPreset | ( | const KisPaintOpPreset & | rhs | ) |
Definition at line 99 of file kis_paintop_preset.cpp.
References KoResource::image, KoResource::isDirty(), KIS_SAFE_ASSERT_RECOVER_NOOP, name(), KoResource::setImage(), KoResource::setName(), setSettings(), settings, and KoResource::setValid().
| 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.
References d.
|
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.
References d.
|
overridevirtual |
Implements KoResource.
Definition at line 114 of file kis_paintop_preset.cpp.
References KisPaintOpPreset().
| KisPaintOpPresetSP KisPaintOpPreset::cloneWithResourcesSnapshot | ( | KisResourcesInterfaceSP | globalResourcesInterface, |
| KoCanvasResourcesInterfaceSP | canvasResourcesInterface, | ||
| KoResourceCacheInterfaceSP | cacheInterface ) const |
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.
References canvasResourcesInterface().
| KisPaintOpPresetSP KisPaintOpPreset::createMaskingPreset | ( | ) | const |
Definition at line 468 of file kis_paintop_preset.cpp.
References d, and KisPaintOpPreset().
|
inlineoverridevirtual |
Reimplemented from KoResource.
Definition at line 159 of file kis_paintop_preset.h.
|
overridevirtual |
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.
References createMaskingPreset(), d, hasMaskingPreset(), KisPaintOpRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, paintOp(), and KoGenericRegistry< T >::value().
| void KisPaintOpPreset::fromXML | ( | const QDomElement & | elt, |
| KisResourcesInterfaceSP | resourcesInterface ) |
Definition at line 323 of file kis_paintop_preset.cpp.
References KoResource::addMetaData(), KisPaintOpRegistry::createSettings(), dbgImage, get(), KisPaintOpRegistry::instance(), KoResource::metadata, resourcesInterface(), KoResource::setName(), setSettings(), settings, KoResource::setValid(), and warnKrita.
| bool KisPaintOpPreset::hasLocalResourcesSnapshot | ( | ) | const |
Definition at line 505 of file kis_paintop_preset.cpp.
References KisRequiredResourcesOperators::hasLocalResourcesSnapshot().
| bool KisPaintOpPreset::hasMaskingPreset | ( | ) | const |
Definition at line 463 of file kis_paintop_preset.cpp.
References d.
|
overridevirtual |
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.
References createMaskingPreset(), d, hasMaskingPreset(), KisPaintOpRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, paintOp(), and KoGenericRegistry< T >::value().
|
overridevirtual |
Implements KoResource.
Definition at line 168 of file kis_paintop_preset.cpp.
References d, dbgImage, KoResource::filename, fromXML(), KoResource::md5sum, name(), resourcesInterface(), resourceType(), KoResource::setImage(), KoResource::setValid(), and updateLinkedResourcesMetaData().
|
overridevirtual |
Reimplemented from KoResource.
Definition at line 131 of file kis_paintop_preset.cpp.
References KoResource::name.
|
delete |
| KoID KisPaintOpPreset::paintOp | ( | ) | const |
|
inline |
Definition at line 67 of file kis_paintop_preset.cpp.
| 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.
References d, and KIS_SAFE_ASSERT_RECOVER_RETURN.
|
inline |
Definition at line 155 of file kis_paintop_preset.h.
|
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.
Reimplemented from KoResource.
Definition at line 609 of file kis_paintop_preset.cpp.
References d.
| KoResourceCacheInterfaceSP KisPaintOpPreset::resourceCacheInterface | ( | ) | const |
Return the saved cache interface or null if not available
Definition at line 620 of file kis_paintop_preset.cpp.
References d.
| KisResourcesInterfaceSP KisPaintOpPreset::resourcesInterface | ( | ) | const |
Definition at line 483 of file kis_paintop_preset.cpp.
References d.
|
inlineoverridevirtual |
Implements KoResource.
Definition at line 144 of file kis_paintop_preset.h.
References ResourceType::PaintOpPresets.
| 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.
References d.
|
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.
References d, KoResource::image, toXML(), and updateLinkedResourcesMetaData().
| void KisPaintOpPreset::setCanvasResourcesInterface | ( | KoCanvasResourcesInterfaceSP | canvasResourcesInterface | ) |
Sets canvas resources interface used for initializing the preset
Definition at line 499 of file kis_paintop_preset.cpp.
References canvasResourcesInterface(), d, and KIS_SAFE_ASSERT_RECOVER_RETURN.
set the id of the paintop plugin
Definition at line 119 of file kis_paintop_preset.cpp.
References d, KoID::id(), and paintOp().
| 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 (
Definition at line 614 of file kis_paintop_preset.cpp.
References d, and KIS_SAFE_ASSERT_RECOVER_RETURN.
| 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.
References d, KIS_SAFE_ASSERT_RECOVER_RETURN, and resourcesInterface().
| void KisPaintOpPreset::setSettings | ( | KisPaintOpSettingsSP | settings | ) |
replace the current settings object with the specified settings
Definition at line 136 of file kis_paintop_preset.cpp.
References d, settings, and KoResource::setValid().
| KisPaintOpSettingsSP KisPaintOpPreset::settings | ( | ) | const |
return the settings that define this paintop preset
|
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.
| void KisPaintOpPreset::toXML | ( | QDomDocument & | doc, |
| QDomElement & | elt ) const |
Definition at line 258 of file kis_paintop_preset.cpp.
References d, KoResourceLoadResult::EmbeddedResource, KisResourceModel::exportResource(), KoResource::filename, KIS_SAFE_ASSERT_RECOVER, linkedResources(), name(), KoResourceLoadResult::resource(), resourcesInterface(), KoResourceLoadResult::signature(), and KoResourceLoadResult::type().
| 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.
References d, and updateProxy.
| 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.
References KoResource::addMetaData(), d, KoResource::filename, KoResourceSignature::filename, linkedResources(), KritaUtils::makeContainerUnique(), and KoResourceLoadResult::signature().
| QPointer< KisPaintOpPresetUpdateProxy > KisPaintOpPreset::updateProxy | ( | ) | const |
| QPointer< KisPaintOpPresetUpdateProxy > KisPaintOpPreset::updateProxyNoCreate | ( | ) | const |
Definition at line 450 of file kis_paintop_preset.cpp.
References d.
|
private |
Definition at line 271 of file kis_paintop_preset.h.
| KisPaintOpSettingsSP KisPaintOpPreset::settings {0} |
Definition at line 73 of file kis_paintop_preset.cpp.
| KisPaintOpSettings::UpdateListenerSP KisPaintOpPreset::settingsUpdateListener |
Definition at line 75 of file kis_paintop_preset.cpp.
| 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.
| QPointer< KisPaintOpPresetUpdateProxy > KisPaintOpPreset::updateProxy |
Definition at line 74 of file kis_paintop_preset.cpp.
| QString KisPaintOpPreset::version |
Definition at line 76 of file kis_paintop_preset.cpp.