File indexing completed on 2024-05-12 15:56:39
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KO_DERIVED_RESOURCE_CONVERTER_H 0008 #define __KO_DERIVED_RESOURCE_CONVERTER_H 0009 0010 #include <QScopedPointer> 0011 #include <QSharedPointer> 0012 #include "kritaflake_export.h" 0013 0014 class QVariant; 0015 0016 /** 0017 * \class KoDerivedResourceConverter 0018 * 0019 * Defines the abstraction of a derived resource. It should be 0020 * uploaded to the KoResourceManager during the loading phase. 0021 * The manager will use it to convert values to/from the source 0022 * resource. 0023 * 0024 * "Derived" resources are the resources that do not exist temselves. 0025 * Instead they are contained in some other resources and are updated 0026 * synchronously with the parent resources as well. 0027 * 0028 * E.g. we store opacity and composite op and opacity in the current 0029 * paintop preset, which is also a resource. So composite op and opacity 0030 * are "derived" resources. 0031 * 0032 * The main goal of this class is to make our resources comply with 0033 * a general Model-View-Controller architecture: 0034 * 0035 * Model: KisPaintOpPreset. It stores opacity, composite op, eraser mode 0036 * and other "global" properties. 0037 * 0038 * Controller: KoCanvasResourceManager. It controls access to the resources 0039 * and emits notification signals when they are changed. 0040 * 0041 * View: KisPaintOpBox and other classes that show the resources on screen 0042 * 0043 * Please take into account that according to the MVC design all the access 0044 * to the model resources should be performed through the controller. 0045 * 0046 */ 0047 class KRITAFLAKE_EXPORT KoDerivedResourceConverter 0048 { 0049 public: 0050 /** 0051 * \param key the unique id of the resource defined by this 0052 * converter 0053 * 0054 * \param sourceKey the id of the parent resource, i.e. where the 0055 * values are really loaded/saved. 0056 */ 0057 KoDerivedResourceConverter(int key, int sourceKey); 0058 virtual ~KoDerivedResourceConverter(); 0059 0060 int key() const; 0061 int sourceKey() const; 0062 0063 QVariant readFromSource(const QVariant &value); 0064 QVariant writeToSource(const QVariant &value, 0065 const QVariant &sourceValue, 0066 bool *changed); 0067 0068 virtual bool notifySourceChanged(const QVariant &sourceValue); 0069 0070 protected: 0071 /** 0072 * Converts the \p value of the source resource into the space of 0073 * the "derived" resource. E.g. preset -> opacity. 0074 */ 0075 virtual QVariant fromSource(const QVariant &value) = 0; 0076 0077 /** 0078 * Converts the value of the "derived" resource into the space of the 0079 * original ("source") resource. E.g. opacity -> preset. 0080 */ 0081 virtual QVariant toSource(const QVariant &value, const QVariant &sourceValue) = 0; 0082 0083 private: 0084 struct Private; 0085 const QScopedPointer<Private> m_d; 0086 }; 0087 0088 typedef QSharedPointer<KoDerivedResourceConverter> KoDerivedResourceConverterSP; 0089 0090 #endif /* __KO_DERIVED_RESOURCE_CONVERTER_H */