dtkWidgetsParameterFactory.h 1.85 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 18 19 20 21 22 23 24 25 26 27
    dtkWidgetsAbstractParameter *create(const QString& key) {

        dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);

        if(!widget) {
            qWarning() << "The widget with key :" << key << "could not be instanciated by the factory.";
            return nullptr;
        }

        return widget;
    }

28 29
    dtkWidgetsAbstractParameter *create(dtkCoreAbstractParameter *parameter, const QString& key) {

30
        dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
31

32 33 34 35
        if(!widget) {
            qWarning() << "The widget with key :" << key << "could not be instanciated by the factory.";
            return nullptr;
        }
36

37 38
        if(!widget->connect(parameter)) {
            qWarning() << "The parameter could not be connected to the widget.";
39 40
        }

41
        return widget;
42 43 44
    }
};

45 46 47 48 49 50 51 52 53 54
// /////////////////////////////////////////////////////////////////
// Register to dtkDiscretegeometry layer
// /////////////////////////////////////////////////////////////////

namespace dtk {
    namespace widgets {
        namespace parameters {
            DTKWIDGETS_EXPORT dtkWidgetsParameterFactory& pluginFactory();
            DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager& pluginManager();
        }
55 56
    }
}