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

#include <KisAslStorage.h>

+ Inheritance diagram for KisAslStorage:

Public Member Functions

bool addResource (const QString &resourceType, KoResourceSP resource) override
 
bool isValid () const override
 
 KisAslStorage (const QString &location)
 
bool loadVersionedResource (KoResourceSP resource) override
 
KoResourceSP resource (const QString &url) override
 
KisResourceStorage::ResourceItem resourceItem (const QString &url) override
 
QSharedPointer< KisResourceStorage::ResourceIteratorresources (const QString &resourceType) override
 
bool saveAsNewVersion (const QString &resourceType, KoResourceSP resource) override
 
bool supportsVersioning () const override
 
QSharedPointer< KisResourceStorage::TagIteratortags (const QString &resourceType) override
 
virtual ~KisAslStorage ()
 
- Public Member Functions inherited from KisStoragePlugin
virtual bool exportResource (const QString &url, QIODevice *device)
 
virtual bool importResource (const QString &url, QIODevice *device)
 
 KisStoragePlugin (const QString &location)
 
virtual QVariant metaData (const QString &key) const
 
virtual QStringList metaDataKeys () const
 
virtual QString resourceFilePath (const QString &url)
 
virtual QString resourceMd5 (const QString &url)
 
virtual void setMetaData (const QString &key, const QVariant &value)
 
virtual QImage thumbnail () const
 
QDateTime timestamp ()
 
virtual ~KisStoragePlugin ()
 

Public Attributes

QSharedPointer< KisAslLayerStyleSerializerm_aslSerializer
 

Additional Inherited Members

- Protected Member Functions inherited from KisStoragePlugin
QString location () const
 
void sanitizeResourceFileNameCase (KoResourceSP resource, const QDir &parentDir)
 

Detailed Description

Definition at line 15 of file KisAslStorage.h.

Constructor & Destructor Documentation

◆ KisAslStorage()

KisAslStorage::KisAslStorage ( const QString & location)

Definition at line 141 of file KisAslStorage.cpp.

144{
145}
QSharedPointer< KisAslLayerStyleSerializer > m_aslSerializer
QString location() const
KisStoragePlugin(const QString &location)

◆ ~KisAslStorage()

KisAslStorage::~KisAslStorage ( )
virtual

Definition at line 147 of file KisAslStorage.cpp.

148{
149
150}

Member Function Documentation

◆ addResource()

bool KisAslStorage::addResource ( const QString & resourceType,
KoResourceSP resource )
overridevirtual

Reimplemented from KisStoragePlugin.

Definition at line 245 of file KisAslStorage.cpp.

246{
247 if (!resource) {
248 warnKrita << "Trying to add a null resource to KisAslStorage";
249 return false;
250 }
251 KisPSDLayerStyleSP layerStyle = resource.dynamicCast<KisPSDLayerStyle>();
252 if (!layerStyle) {
253 warnKrita << "Trying to add a resource that is not a layer style to KisAslStorage";
254 return false;
255 }
256
258 styles << layerStyle;
259 m_aslSerializer->setStyles(styles);
260 return m_aslSerializer->saveToFile(location());
261}
KoResourceSP resource(const QString &url) override
#define warnKrita
Definition kis_debug.h:87
The KisPSDLayerStyle class implements loading, saving and applying the PSD layer effects.

References KisStoragePlugin::location(), m_aslSerializer, resource(), and warnKrita.

◆ isValid()

bool KisAslStorage::isValid ( ) const
overridevirtual

Reimplemented from KisStoragePlugin.

Definition at line 263 of file KisAslStorage.cpp.

264{
265 if (!m_aslSerializer->isInitialized()) {
266 m_aslSerializer->readFromFile(location());
267 }
268 return m_aslSerializer->isValid();
269}

References KisStoragePlugin::location(), and m_aslSerializer.

◆ loadVersionedResource()

bool KisAslStorage::loadVersionedResource ( KoResourceSP resource)
overridevirtual

Implements KisStoragePlugin.

Definition at line 218 of file KisAslStorage.cpp.

219{
220 return false;
221}

◆ resource()

KoResourceSP KisAslStorage::resource ( const QString & url)
overridevirtual

Retrieve the given resource. The url is the unique identifier of the resource, for instance resourcetype plus filename.

Reimplemented from KisStoragePlugin.

Definition at line 162 of file KisAslStorage.cpp.

163{
164 if (!m_aslSerializer->isInitialized()) {
165 m_aslSerializer->readFromFile(location());
166 }
167 int indexOfUnderscore = url.lastIndexOf("_");
168 QString realUuid = url;
169 if (indexOfUnderscore >= 0) {
170 realUuid.remove(indexOfUnderscore, url.length() - indexOfUnderscore); // remove _pattern or _style added in iterator
171 }
172 // TODO: RESOURCES: Since we do get a resource type at the beginning of the path now
173 // maybe we could skip adding the _[resourcetype] at the end of the path as well?
174 realUuid = QFileInfo(realUuid).baseName(); // remove patterns/ at the beginning, if there are any
175
176 if (url.contains("pattern") || url.contains(".pat")) {
177 QHash<QString, KoPatternSP> patterns = m_aslSerializer->patterns();
178
179 if (patterns.contains(realUuid)) {
180 return patterns[realUuid];
181 }
182 }
183 else {
184 KisPSDLayerStyleSP resultingStyle;
185
186 QHash<QString, KisPSDLayerStyleSP> styles = m_aslSerializer->stylesHash();
187 if (styles.contains(realUuid)) {
188 resultingStyle = styles[realUuid];
189 } else {
190 // can be {realUuid} or {realUuid}
191 if (realUuid.startsWith("{")) {
192 realUuid = realUuid.right(realUuid.length() - 1);
193 }
194 if (realUuid.endsWith("}")) {
195 realUuid = realUuid.left(realUuid.length() - 1);
196 }
197
198 if (styles.contains(realUuid)) {
199 resultingStyle = styles[realUuid];
200 }
201 }
202
203 if (resultingStyle) {
204 KisPSDLayerStyleSP newStyle = resultingStyle->clone().dynamicCast<KisPSDLayerStyle>();
205
206 // newStyle->resourcesInterface() is guaranteed to point to a local copy of the resouces
207 // stored inside the serializer, so we need to side-load them and then reset the resources
208 // interface to the global one
209 KisAslLayerStyleSerializer::sideLoadLinkedResources(newStyle.data(), newStyle->resourcesInterface());
210 newStyle->setResourcesInterface(KisGlobalResourcesInterface::instance());
211
212 return newStyle;
213 }
214 }
215 return 0;
216}
static void sideLoadLinkedResources(KisPSDLayerStyle *style, KisResourcesInterfaceSP resourcesInterface)
static KisResourcesInterfaceSP instance()

References KisGlobalResourcesInterface::instance(), KisStoragePlugin::location(), m_aslSerializer, and KisAslLayerStyleSerializer::sideLoadLinkedResources().

◆ resourceItem()

◆ resources()

QSharedPointer< KisResourceStorage::ResourceIterator > KisAslStorage::resources ( const QString & resourceType)
overridevirtual

◆ saveAsNewVersion()

bool KisAslStorage::saveAsNewVersion ( const QString & resourceType,
KoResourceSP resource )
overridevirtual

Reimplemented from KisStoragePlugin.

Definition at line 238 of file KisAslStorage.cpp.

239{
240 // not implemented yet
241 warnKrita << "KisAslStorage::saveAsNewVersion is not implemented yet";
242 return false;
243}

References warnKrita.

◆ supportsVersioning()

bool KisAslStorage::supportsVersioning ( ) const
overridevirtual

Reimplemented from KisStoragePlugin.

Definition at line 223 of file KisAslStorage.cpp.

224{
225 return false;
226}

◆ tags()

QSharedPointer< KisResourceStorage::TagIterator > KisAslStorage::tags ( const QString & resourceType)
overridevirtual

Implements KisStoragePlugin.

Definition at line 233 of file KisAslStorage.cpp.

References KisStoragePlugin::location().

Member Data Documentation

◆ m_aslSerializer

QSharedPointer<KisAslLayerStyleSerializer> KisAslStorage::m_aslSerializer

Definition at line 33 of file KisAslStorage.h.


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