File indexing completed on 2024-05-12 15:59:55
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KORESOURCELOADRESULT_H 0007 #define KORESOURCELOADRESULT_H 0008 0009 #include <QSharedPointer> 0010 #include <KoResourceSignature.h> 0011 #include <KoEmbeddedResource.h> 0012 0013 class KoResource; 0014 typedef QSharedPointer<KoResource> KoResourceSP; 0015 0016 class KRITARESOURCES_EXPORT KoResourceLoadResult 0017 { 0018 public: 0019 enum Type { 0020 ExistingResource, 0021 EmbeddedResource, 0022 FailedLink 0023 }; 0024 public: 0025 KoResourceLoadResult(KoResourceSP resource); 0026 KoResourceLoadResult(KoEmbeddedResource embeddedRresource); 0027 KoResourceLoadResult(KoResourceSignature signature); 0028 0029 template <typename T, typename = typename std::is_convertible<T*, KoResource*>::type> 0030 KoResourceLoadResult(QSharedPointer<T> resource) 0031 : KoResourceLoadResult(KoResourceSP(resource)) 0032 { 0033 } 0034 0035 KoResourceLoadResult(const KoResourceLoadResult &rhs); 0036 KoResourceLoadResult& operator=(const KoResourceLoadResult &rhs); 0037 0038 ~KoResourceLoadResult(); 0039 0040 /** 0041 * Returns existing resource that has been loaded from the Krita 0042 * database. 0043 * 0044 * Returns non-null pointer only when `type()` is equal to 0045 * `ExistingResource` 0046 */ 0047 KoResourceSP resource() const; 0048 0049 /** 0050 * Same as resource(), but returns a resource that is dynamically 0051 * cast to the destination type T 0052 */ 0053 template <typename T> 0054 QSharedPointer<T> resource() const { 0055 return this->resource().dynamicCast<T>(); 0056 } 0057 0058 /** 0059 * Returns the embedded resource, for which there was no instance 0060 * has been found in the resource database. This resource should 0061 * be imported into the database manually. 0062 * 0063 * Returns a valid object only when `type()` is equal to 0064 * `EmbeddedResource` 0065 */ 0066 KoEmbeddedResource embeddedResource() const; 0067 0068 /** 0069 * Return a signature for the embedded/linked resource. This is 0070 * the only information available when `type()` is equal to 0071 * `FailedLink` 0072 */ 0073 KoResourceSignature signature() const; 0074 0075 /** 0076 * Describes the result of the resource loading. A copy of the resource 0077 * can be either found in the resource database, it can be loaded from 0078 * some embedded storage (and yet should be imported into the database 0079 * manually) or it can just fail to be found (e.g. when the resource 0080 * is not embedded and still not found in the database). 0081 */ 0082 Type type() const; 0083 0084 private: 0085 struct Private; 0086 const QScopedPointer<Private> m_d; 0087 }; 0088 0089 #endif // KORESOURCELOADRESULT_H