File indexing completed on 2024-05-12 15:59:48

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISEMBEDDEDRESOURCESTORAGEPROXY_H
0008 #define KISEMBEDDEDRESOURCESTORAGEPROXY_H
0009 
0010 #include "kritaresources_export.h"
0011 #include "KisResourceModel.h"
0012 #include "KisLocalStrokeResources.h"
0013 
0014 /**
0015  * When PSD is loaded into a temporary document, e.g. in a thumbnailer thread,
0016  * we don't have access to the resources database. Therefore we need to load
0017  * the embedded resources into a local storage
0018  */
0019 struct KRITARESOURCES_EXPORT KisEmbeddedResourceStorageProxy {
0020     KisEmbeddedResourceStorageProxy(const QString &storageLocation);
0021 
0022     void addResource(KoResourceSP resourse);;
0023 
0024     /**
0025      * Returns the resources interface that lets you access all the embedded
0026      * resources added to the proxy, either before this call, or after it.
0027      */
0028     KisResourcesInterfaceSP resourcesInterface();
0029 
0030     /**
0031      * Return the resources interface that contains a snapshot of all the
0032      * resources that were added to the proxy by then. The returned interface
0033      * will not be linked to the proxy anymore.
0034      *
0035      * Use this interface for initializing layers styles or paintop preset,
0036      * which you plan to add to the proxy as well. It will let you avoid
0037      * cycling shared pointer links (and, therefore, memory leaks).
0038      *
0039      * PS:
0040      * When the document is not temporary and has an officially registered
0041      * storage, then resourcesInterface() and detachedResourcesInterface()
0042      * return the same interface, which is KisGlobalResourcesInterface.
0043      */
0044     KisResourcesInterfaceSP detachedResourcesInterface();
0045 
0046 private:
0047     QString m_storageLocation;
0048     QSharedPointer<KisLocalStrokeResources> m_fallbackResourcesInterface;
0049     KisResourcesInterfaceSP m_rootResourcesInterface;
0050 
0051     KisResourceModel m_stylesModel;
0052     KisResourceModel m_patternsModel;
0053     KisResourceModel m_gradientsModel;
0054 };
0055 
0056 #endif // KISEMBEDDEDRESOURCESTORAGEPROXY_H