|
Krita Source Code Documentation
|
#include <KoResource.h>
Inheritance diagram for KoResource:Public Member Functions | |
| bool | active () const |
| void | addMetaData (QString key, QVariant value) |
| store the given key, value pair in the resource | |
| virtual void | clearSideLoadedResources () |
| virtual KoResourceSP | clone () const =0 |
| virtual QString | defaultFileExtension () const |
| virtual QList< KoResourceLoadResult > | embeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const |
| 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) | |
| virtual QList< KoResourceLoadResult > | linkedResources (KisResourcesInterfaceSP globalResourcesInterface) const |
| bool | load (KisResourcesInterfaceSP resourcesInterface) |
| virtual bool | loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface)=0 |
| QString | md5Sum (bool generateIfEmpty=true) const |
| QMap< QString, QVariant > | metadata () const |
| get a map with all the metadata | |
| virtual QString | name () const |
| KoResource & | operator= (const KoResource &rhs)=delete |
| bool | permanent () const |
| virtual QList< int > | requiredCanvasResources () const |
| QList< KoResourceLoadResult > | requiredResources (KisResourcesInterfaceSP globalResourcesInterface) const |
| int | resourceId () const |
| virtual QPair< QString, QString > | resourceType () const =0 |
| bool | save () |
| virtual bool | saveToDevice (QIODevice *dev) const |
| 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) |
| virtual QList< KoResourceLoadResult > | sideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const |
| 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 Member Functions inherited from Private | |
| Private (KisCanvas2 *c) | |
Public Attributes | |
| 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} |
Public Attributes inherited from Private | |
| KisCanvas2 * | canvas |
| int | displayedFrame |
| int | intendedFrame |
Private Attributes | |
| Private *const | d |
The KoResource class provides a representation of resources. This includes, but not limited to, brushes and patterns.
A resource knows its filename, but not the location where it's stored. A new version of a resource is stored with an updated filename, the old version isn't renamed.
Definition at line 27 of file KoResource.cpp.
| KoResource::KoResource | ( | ) |
Creates a new KoResource object using filename. No file is opened in the constructor, you have to call load.
| filename | the file name to save and load from. |
Definition at line 42 of file KoResource.cpp.
|
explicit |
Definition at line 47 of file KoResource.cpp.
|
virtual |
| KoResource::KoResource | ( | const KoResource & | rhs | ) |
Definition at line 59 of file KoResource.cpp.
| bool KoResource::active | ( | ) | const |
| void KoResource::addMetaData | ( | QString | key, |
| QVariant | value ) |
store the given key, value pair in the resource
It is responsibility of the resource itself to load all the necessary metadata right on loading in loadFromDevice(). The resource locator will not try to load this information from the database. Database only caches metadata.
To make sure that metadata is correctly populated in the database, it should be set up right in loadFromDevice().
Definition at line 289 of file KoResource.cpp.
|
virtual |
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 in KisPaintOpPreset.
Definition at line 265 of file KoResource.cpp.
|
pure virtual |
Implemented in KisAbrBrush, KisAutoBrush, KisGbrBrush, KisImagePipeBrush, KisPngBrush, KisSvgBrush, KisTextBrush, KisSeExprScript, KoCssStylePreset, KoFontFamily, KoGamutMask, KoSvgSymbolCollectionResource, KisPaintOpPreset, KisPSDLayerStyle, KoCachedGradient, KoColorSet, KoPattern, KoSegmentGradient, KoStopGradient, KisWorkspaceResource, KisSessionResource, KisWindowLayoutResource, TasksetResource, and KisMyPaintPaintOpPreset.
|
virtual |
Reimplemented in KisAbrBrush, KisGbrBrush, KisImagePipeBrush, KisPngBrush, KisSvgBrush, KisSeExprScript, KoCssStylePreset, KoGamutMask, KoSvgSymbolCollectionResource, KisPaintOpPreset, KoColorSet, KoPattern, KoSegmentGradient, KoStopGradient, KisWorkspaceResource, KisSessionResource, KisWindowLayoutResource, and TasksetResource.
Definition at line 212 of file KoResource.cpp.
|
virtual |
globalResourcesInterface to save time/memory.These resources are embedded into the resource itself and are available throughout the entire lifetime of the resource.
Reimplemented in KisPaintOpPreset, and KisPSDLayerStyle.
Definition at line 246 of file KoResource.cpp.
| QString KoResource::filename | ( | ) | const |
| QImage KoResource::image | ( | ) | const |
This image could be null. The image can be in any valid format.
| bool KoResource::isDirty | ( | ) | const |
Definition at line 284 of file KoResource.cpp.
References d.
|
virtual |
Ephemeral resource is a type of resource that has no physical representation on disk. Therefore, its load()/save() calls do nothing. Such resources will always have empty md5Sum() and, therefore, will never be stored in the resources database.
This type of resources is created directly by the corresponding factory or other object (e.g. KisAutoBrushFactory).
Ephemeral resource cannot be serializable.
Reimplemented in KisAutoBrush, and KisTextBrush.
Definition at line 328 of file KoResource.cpp.
|
virtual |
Serializable resource is the one which can be saved/loaded into a specific storage via saveToDevice()/loadFromDevice() methods. Some resources, like KisAbrBrush or KisPsdLayerStyle, are stored in specific libraries in "batches". Such resources cannot be saved individually. They are created by the corresponding factories.
In contrast to ephemeral resource, non-serializable resource will always have a correct md5Sum() and may be stored in the resources database.
Reimplemented in KisAbrBrush, KoFontFamily, and KisPSDLayerStyle.
Definition at line 333 of file KoResource.cpp.
References isEphemeral().
|
virtual |
globalResourcesInterface. If fetching of some resources is failed, then (*this) resource is invalid. Reimplemented in KisPaintOpPreset.
Definition at line 237 of file KoResource.cpp.
| bool KoResource::load | ( | KisResourcesInterfaceSP | resourcesInterface | ) |
Load this resource.
Definition at line 64 of file KoResource.cpp.
References filename, and loadFromDevice().
|
pure virtual |
Implemented in KisAbrBrush, KisAutoBrush, KisGbrBrush, KisImagePipeBrush, KisPngBrush, KisSvgBrush, KisTextBrush, KisSeExprScript, KoCssStylePreset, KoFontFamily, KoGamutMask, KoSvgSymbolCollectionResource, KisPaintOpPreset, KisPSDLayerStyle, KoCachedGradient, KoColorSet, KoPattern, KoSegmentGradient, KoStopGradient, KisWorkspaceResource, KisWindowLayoutResource, TasksetResource, and KisMyPaintPaintOpPreset.
| QString KoResource::md5Sum | ( | bool | generateIfEmpty = true | ) | const |
| generateIfEmpty | if the resource does not have an md5sum set, if this is true, the resource saves itself into a buffer and calculates the md5sum over that. This may be different from the actual md5sum you would get calculated over the actual resource file. |
Definition at line 141 of file KoResource.cpp.
References d, dbgResources, KoMD5Generator::generateHash(), isEphemeral(), isSerializable(), KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, name, saveToDevice(), and setMD5Sum().
| QMap< QString, QVariant > KoResource::metadata | ( | ) | const |
get a map with all the metadata
|
virtual |
Reimplemented in KisSeExprScript, KisPaintOpPreset, and KisPSDLayerStyle.
|
delete |
| bool KoResource::permanent | ( | ) | const |
|
virtual |
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 in KisPaintOpPreset, KisPSDLayerStyle, KoSegmentGradient, and KoStopGradient.
Definition at line 269 of file KoResource.cpp.
| QList< KoResourceLoadResult > KoResource::requiredResources | ( | KisResourcesInterfaceSP | globalResourcesInterface | ) | const |
Loads all the required resources either from globalResourcesInterface or from embedded data. The preset first tries to fetch the required resource from the global source, and only if it fails, tries to load it from the embedded data. One can check if the loaded resource is embedded by checking its resourceId().
The set of resources returned is basically: linkedResources() + embeddedResources()
Definition at line 232 of file KoResource.cpp.
References embeddedResources(), and linkedResources().
| int KoResource::resourceId | ( | ) | const |
|
pure virtual |
Implemented in KisAbrBrush, KisBrush, KisGbrBrush, KisPngBrush, KisSvgBrush, KisSeExprScript, KoCssStylePreset, KoFontFamily, KoGamutMask, KoSvgSymbolCollectionResource, KisPaintOpPreset, KisPSDLayerStyle, KoCachedGradient, KoColorSet, KoPattern, KoSegmentGradient, KoStopGradient, KisWorkspaceResource, KisSessionResource, KisWindowLayoutResource, TasksetResource, and KisMyPaintPaintOpPreset.
| bool KoResource::save | ( | ) |
Save this resource.
Definition at line 94 of file KoResource.cpp.
References filename, saveToDevice(), and warnKrita.
|
virtual |
Reimplemented in KisAbrBrush, KisAutoBrush, KisGbrBrush, KisImagePipeBrush, KisPngBrush, KisSvgBrush, KisTextBrush, KisSeExprScript, KoCssStylePreset, KoGamutMask, KoSvgSymbolCollectionResource, KisPaintOpPreset, KisPSDLayerStyle, KoColorSet, KoPattern, KoSegmentGradient, KoStopGradient, KisWorkspaceResource, KisWindowLayoutResource, and TasksetResource.
Definition at line 111 of file KoResource.cpp.
| void KoResource::setActive | ( | bool | active | ) |
Definition at line 206 of file KoResource.cpp.
| void KoResource::setDirty | ( | bool | value | ) |
| void KoResource::setFilename | ( | const QString & | filename | ) |
| void KoResource::setImage | ( | const QImage & | image | ) |
Definition at line 136 of file KoResource.cpp.
| void KoResource::setMD5Sum | ( | const QString & | md5sum | ) |
Set the md5sum of this resource. It must be in hex-encoded string format.
ephemeral resources have no md5, trying to assign them one is considered an error
Definition at line 159 of file KoResource.cpp.
References d, isEphemeral(), KIS_SAFE_ASSERT_RECOVER_RETURN, md5sum, and valid.
| void KoResource::setName | ( | const QString & | name | ) |
| void KoResource::setPermanent | ( | bool | permanent | ) |
Definition at line 222 of file KoResource.cpp.
| void KoResource::setResourceId | ( | int | id | ) |
| void KoResource::setStorageLocation | ( | const QString & | location | ) |
Definition at line 338 of file KoResource.cpp.
References d.
| void KoResource::setValid | ( | bool | valid | ) |
| void KoResource::setVersion | ( | int | version | ) |
Definition at line 313 of file KoResource.cpp.
|
virtual |
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 in KisPaintOpPreset.
Definition at line 259 of file KoResource.cpp.
| KoResourceSignature KoResource::signature | ( | ) | const |
Definition at line 323 of file KoResource.cpp.
References filename, md5Sum(), name, and resourceType().
| QString KoResource::storageLocation | ( | ) | const |
| QList< KoResourceLoadResult > KoResource::takeSideLoadedResources | ( | KisResourcesInterfaceSP | globalResourcesInterface | ) |
Returns all the side-loaded resources and clears the memory under them, the caller is expected to add them into the global store.
It is basically a combination of sideLoadedResources() + clearSideLoadedResources().
Definition at line 252 of file KoResource.cpp.
References clearSideLoadedResources(), and sideLoadedResources().
|
virtual |
thumbnail the thumbnail image to use in resource selectors
Definition at line 126 of file KoResource.cpp.
References image.
|
virtual |
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.
Reimplemented in KisMyPaintPaintOpPreset.
Definition at line 131 of file KoResource.cpp.
|
virtual |
updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
Reimplemented in KoCssStylePreset, KoFontFamily, KoColorSet, and KisMyPaintPaintOpPreset.
Definition at line 122 of file KoResource.cpp.
| bool KoResource::valid | ( | ) | const |
| int KoResource::version | ( | ) | const |
Get the version of the resource.
| bool KoResource::active {true} |
Definition at line 31 of file KoResource.cpp.
|
private |
Definition at line 274 of file KoResource.h.
| QString KoResource::filename |
Definition at line 35 of file KoResource.cpp.
| QImage KoResource::image |
Definition at line 38 of file KoResource.cpp.
| QString KoResource::md5sum |
Definition at line 37 of file KoResource.cpp.
| QMap< QString, QVariant > KoResource::metadata |
Definition at line 39 of file KoResource.cpp.
| bool KoResource::modified {false} |
Definition at line 33 of file KoResource.cpp.
| QString KoResource::name |
Definition at line 34 of file KoResource.cpp.
| bool KoResource::permanent {false} |
Definition at line 32 of file KoResource.cpp.
| int KoResource::resourceId {-1} |
Definition at line 29 of file KoResource.cpp.
| QString KoResource::storageLocation |
Definition at line 36 of file KoResource.cpp.
| bool KoResource::valid {false} |
Definition at line 30 of file KoResource.cpp.
| int KoResource::version {-1} |
Definition at line 28 of file KoResource.cpp.