dtkWidgetsParameterFactory.h 1.69 KB
Newer Older
1 2 3 4 5 6
#pragma once

#include<dtkWidgetsExport.h>

#include "dtkWidgetsParameter.h"

7 8 9 10 11 12 13 14
class DTKWIDGETS_EXPORT dtkWidgetsParameterPlugin : public dtkCorePluginBase {};

Q_DECLARE_METATYPE(dtkWidgetsParameterPlugin*);
Q_DECLARE_INTERFACE(dtkWidgetsParameterPlugin, DTK_DECLARE_PLUGIN_INTERFACE(dtkWidgetsParameterPlugin));

class DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager : public dtkCorePluginManager<dtkWidgetsParameterPlugin> {};

class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkCorePluginFactory<dtkWidgetsAbstractParameter> {
15
public:
16 17
    template <typename T>
    dtkWidgetsAbstractParameter *create(dtkCoreParameter<T> *parameter, const QString& key) {
18 19 20 21 22
        dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
        if(!widget) {
            qWarning() << "The widget with key :" << key << "could not be instanciated by the factory.";
            return nullptr;
        }
23

24
        dtkWidgetsParameter<dtkCoreParameter<T>> *t_widget = dynamic_cast<dtkWidgetsParameter<dtkCoreParameter<T>> *>(widget);
25 26 27 28

        if(!t_widget) {
            qWarning() << "The type of the parameter is not compatible with the plugin.";
            return nullptr;
29 30
        }

31 32
        t_widget->connect(parameter);
        return t_widget;
33 34 35
    }
};

36 37 38 39 40 41 42 43 44 45
// /////////////////////////////////////////////////////////////////
// Register to dtkDiscretegeometry layer
// /////////////////////////////////////////////////////////////////

namespace dtk {
    namespace widgets {
        namespace parameters {
            DTKWIDGETS_EXPORT dtkWidgetsParameterFactory& pluginFactory();
            DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager& pluginManager();
        }
46 47
    }
}