Krita Source Code Documentation
Loading...
Searching...
No Matches
KisResourcesInterface.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KISRESOURCESINTERFACE_H
7#define KISRESOURCESINTERFACE_H
8
9#include "kritaresources_export.h"
10
11#include <QScopedPointer>
12#include <KoResource.h>
14
15class QString;
16class QByteArray;
18
40class KRITARESOURCES_EXPORT KisResourcesInterface
41{
42public:
43 class KRITARESOURCES_EXPORT ResourceSourceAdapter
44 {
45 public:
46 ResourceSourceAdapter(const QString &type);
47 virtual ~ResourceSourceAdapter();
48//protected:
50 virtual QVector<KoResourceSP> resourcesForFilename(const QString& filename) const = 0;
51 virtual QVector<KoResourceSP> resourcesForName(const QString& name) const = 0;
52 virtual QVector<KoResourceSP> resourcesForMD5(const QString& md5) const = 0;
53public:
66 KoResourceSP bestMatch(const QString md5, const QString filename, const QString name);
67
79 KoResourceSP exactMatch(const QString md5, const QString filename, const QString name);
80
87 KoResourceLoadResult bestMatchLoadResult(const QString md5, const QString filename, const QString name);
88
89 virtual KoResourceSP fallbackResource() const = 0;
90
91 private:
92 KoResourceSP findResource(const QString md5, const QString filename, const QString name, bool exactMatch);
93 private:
95 const QString m_type;
96 };
97
98 template <typename T>
100 {
101 public:
103 : m_source(adapter)
104 {
105 }
106private:
107 QVector<QSharedPointer<T>> resourcesForFilename(const QString& filename) const
108 {
110 Q_FOREACH(KoResourceSP resource, m_source->resourcesForFilename(filename)) {
111 r << resource.dynamicCast<T>();
112 }
113 return r;
114 }
115
116 QVector<QSharedPointer<T>> resourcesForName(const QString& name) const
117 {
119 Q_FOREACH(KoResourceSP resource, m_source->resourcesForName(name)) {
120 r << resource.dynamicCast<T>();
121 }
122 return r;
123 }
124
126 {
128 Q_FOREACH(KoResourceSP resource, m_source->resourcesForMD5(md5)) {
129 r << resource.dynamicCast<T>();
130 }
131 return r;
132 }
133public:
146 QSharedPointer<T> bestMatch(const QString md5, const QString filename, const QString name) {
147 return m_source->bestMatch(md5, filename, name).dynamicCast<T>();
148 }
149
161 QSharedPointer<T> exactMatch(const QString md5, const QString filename, const QString name) {
162 return m_source->exactMatch(md5, filename, name).dynamicCast<T>();
163 }
164
171 KoResourceLoadResult bestMatchLoadResult(const QString md5, const QString filename, const QString name) {
172 return m_source->bestMatchLoadResult(md5, filename, name);
173 }
174
176 {
177 return m_source->fallbackResource().dynamicCast<T>();
178 }
179
180 protected:
182 };
183
184public:
186 virtual ~KisResourcesInterface();
187
194 ResourceSourceAdapter& source(const QString &type) const;
195
209 template<typename T>
210 TypedResourceSourceAdapter<T> source(const QString &type) const {
211 return TypedResourceSourceAdapter<T>(&this->source(type));
212 }
213
214protected:
216 virtual ResourceSourceAdapter* createSourceImpl(const QString &type) const = 0;
217
218protected:
219 QScopedPointer<KisResourcesInterfacePrivate> d_ptr;
220
221private:
222 Q_DECLARE_PRIVATE(KisResourcesInterface)
223};
224
226
227#endif // KISRESOURCESINTERFACE_H
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
virtual QVector< KoResourceSP > resourcesForFilename(const QString &filename) const =0
virtual QVector< KoResourceSP > resourcesForMD5(const QString &md5) const =0
virtual QVector< KoResourceSP > resourcesForName(const QString &name) const =0
virtual KoResourceSP fallbackResource() const =0
QSharedPointer< T > bestMatch(const QString md5, const QString filename, const QString name)
bestMatch retrieves a resource, preferably by md5, but with filename and name as fallback for older f...
QVector< QSharedPointer< T > > resourcesForFilename(const QString &filename) const
QVector< QSharedPointer< T > > resourcesForName(const QString &name) const
KoResourceLoadResult bestMatchLoadResult(const QString md5, const QString filename, const QString name)
QVector< QSharedPointer< T > > resourcesForMD5(const QString &md5) const
QSharedPointer< T > exactMatch(const QString md5, const QString filename, const QString name)
exactMatch retrieves a resource, preferably by md5, but with filename and name as fallback for older ...
a provider-like interface class for accessing resource sources in Krita.
virtual ResourceSourceAdapter * createSourceImpl(const QString &type) const =0
QScopedPointer< KisResourcesInterfacePrivate > d_ptr
TypedResourceSourceAdapter< T > source(const QString &type) const