File indexing completed on 2024-05-12 16:01:52

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISBASEOPTION_H
0008 #define KISBASEOPTION_H
0009 
0010 #include <kis_types.h>
0011 #include <kritaui_export.h>
0012 #include "kis_pointer_utils.h"
0013 
0014 class KoResource;
0015 using KoResourceSP = QSharedPointer<KoResource>;
0016 
0017 class KisResourcesInterface;
0018 using KisResourcesInterfaceSP = QSharedPointer<KisResourcesInterface>;
0019 
0020 class KoCanvasResourcesInterface;
0021 using KoCanvasResourcesInterfaceSP = QSharedPointer<KoCanvasResourcesInterface>;
0022 
0023 class KoResourceLoadResult;
0024 
0025 /**
0026  * This is a special base class for all the options that load/save
0027  * settings into a properties objects and do *not* store the properties
0028  * themselves. A KisPaintOpOption derived class generates a QWidget for
0029  * its configuration page. This cannot be created from a KisPaintO[
0030  *
0031  * This class adapts your option to allow its easy use with
0032  * both raw pointers and shared pointers.
0033  *
0034  * Motivation:
0035  * In quite a lot of places we call some options from the KisPaintOpSettings
0036  * class itself with patting 'this' as a parameter into
0037  * read/writeOptionSetting(). Conversion of 'this' into a shared pointer is
0038  * extremely dangerous, and, ideally, should be prohibited. We cannot prohibit
0039  * it atm, but we still can create a special interface for accepting raw pointers,
0040  * which will be used automatically, when 'this' is passed.
0041  */
0042 class KRITAUI_EXPORT KisPaintopPropertiesCanvasResourcesBase
0043 {
0044 public:
0045     virtual ~KisPaintopPropertiesCanvasResourcesBase();
0046 
0047     template <typename KisPropertiesConfigurationPointer>
0048     void readOptionSetting(KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface, KoCanvasResourcesInterfaceSP canvasResourcesInterface)
0049     {
0050         readOptionSettingResourceImpl(removeSharedPointer(settings), resourcesInterface, canvasResourcesInterface);
0051     }
0052 
0053     template <typename KisPropertiesConfigurationPointer>
0054     void writeOptionSetting(KisPropertiesConfigurationPointer settings) const
0055     {
0056         writeOptionSettingImpl(removeSharedPointer(settings));
0057     }
0058 
0059     template <typename KisPropertiesConfigurationPointer>
0060     QList<KoResourceLoadResult> prepareLinkedResources(const KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface) const
0061     {
0062         return prepareLinkedResourcesImpl(removeSharedPointer(settings), resourcesInterface);
0063     }
0064 
0065     template <typename KisPropertiesConfigurationPointer>
0066     QList<KoResourceLoadResult> prepareEmbeddedResources(const KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface) const
0067     {
0068         return prepareEmbeddedResourcesImpl(removeSharedPointer(settings), resourcesInterface);
0069     }
0070 
0071 protected:
0072     virtual void readOptionSettingResourceImpl(const KisPropertiesConfiguration *settings, KisResourcesInterfaceSP resourcesInterface, KoCanvasResourcesInterfaceSP canvasResourcesInterface) = 0;
0073     virtual void writeOptionSettingImpl(KisPropertiesConfiguration *settings) const = 0;
0074     virtual QList<KoResourceLoadResult> prepareLinkedResourcesImpl(const KisPropertiesConfiguration *settings, KisResourcesInterfaceSP resourcesInterface) const = 0;
0075     virtual QList<KoResourceLoadResult> prepareEmbeddedResourcesImpl(const KisPropertiesConfiguration *settings, KisResourcesInterfaceSP resourcesInterface) const = 0;
0076 };
0077 
0078 class KRITAUI_EXPORT KisPaintopPropertiesResourcesBase
0079 {
0080 public:
0081     virtual ~KisPaintopPropertiesResourcesBase();
0082 
0083     template <typename KisPropertiesConfigurationPointer>
0084     void readOptionSetting(KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface)
0085     {
0086         readOptionSettingResourceImpl(removeSharedPointer(settings), resourcesInterface);
0087     }
0088 
0089     template <typename KisPropertiesConfigurationPointer>
0090     void writeOptionSetting(KisPropertiesConfigurationPointer settings) const
0091     {
0092         writeOptionSettingImpl(removeSharedPointer(settings));
0093     }
0094 
0095     template <typename KisPropertiesConfigurationPointer>
0096     QList<KoResourceLoadResult> prepareLinkedResources(const KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface) const
0097     {
0098         return prepareLinkedResourcesImpl(removeSharedPointer(settings), resourcesInterface);
0099     }
0100 
0101     template <typename KisPropertiesConfigurationPointer>
0102     QList<KoResourceLoadResult> prepareEmbeddedResources(const KisPropertiesConfigurationPointer settings, KisResourcesInterfaceSP resourcesInterface) const
0103     {
0104         return prepareEmbeddedResourcesImpl(removeSharedPointer(settings), resourcesInterface);
0105     }
0106 
0107 
0108 protected:
0109     virtual void readOptionSettingResourceImpl(const KisPropertiesConfiguration *settings, KisResourcesInterfaceSP resourcesInterface) = 0;
0110     virtual void writeOptionSettingImpl(KisPropertiesConfiguration *settings) const = 0;
0111     virtual QList<KoResourceLoadResult> prepareLinkedResourcesImpl(const KisPropertiesConfiguration *settings, KisResourcesInterfaceSP resourcesInterface) const = 0;
0112     virtual QList<KoResourceLoadResult> prepareEmbeddedResourcesImpl(const KisPropertiesConfiguration *settings, KisResourcesInterfaceSP resourcesInterface) const = 0;
0113 };
0114 
0115 class KRITAUI_EXPORT KisPaintopPropertiesBase /*: public KisPaintopPropertiesResourcesBase*/
0116 {
0117 public:
0118     virtual ~KisPaintopPropertiesBase();
0119 
0120     template <typename KisPropertiesConfigurationPointer>
0121     void readOptionSetting(KisPropertiesConfigurationPointer settings)
0122     {
0123         readOptionSettingImpl(removeSharedPointer(settings));
0124     }
0125 
0126     template <typename KisPropertiesConfigurationPointer>
0127     void writeOptionSetting(KisPropertiesConfigurationPointer settings) const
0128     {
0129         writeOptionSettingImpl(removeSharedPointer(settings));
0130 
0131     }
0132 
0133 protected:
0134     virtual void readOptionSettingImpl(const KisPropertiesConfiguration *settings) = 0;
0135     virtual void writeOptionSettingImpl(KisPropertiesConfiguration *settings) const = 0;
0136 };
0137 
0138 #endif // KISBASEOPTION_H