dtkWidgetsParameterFactory.cpp 2.35 KB
Newer Older
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Version: $Id$
//
//

// Commentary:
//
//

// Change Log:
//
//

// Code:

15 16 17 18
#include "dtkWidgetsParameterFactory.h"

#include "dtkWidgets.h"

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
19 20 21 22
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////

23
dtkWidgetsParameter *dtkWidgetsParameterFactory::create(const QString& key)
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
24
{
25
    dtkWidgetsParameter *widget = dtkCorePluginFactory<dtkWidgetsParameter>::create(key);
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
26 27 28 29 30 31 32
    if(!widget) {
        qWarning() << Q_FUNC_INFO << "The widget with key :" << key << "could not be instanciated by the factory.";
        return nullptr;
    }
    return widget;
}

33
dtkWidgetsParameter *dtkWidgetsParameterFactory::create(dtkCoreParameter *parameter, const QString& key)
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
34 35 36 37 38 39
{
    if (!parameter) {
        qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done. Return nullptr.";
        return nullptr;
    }

40
    dtkWidgetsParameter *widget = dtkCorePluginFactory<dtkWidgetsParameter>::create(key);
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54
    if(!widget) {
        qWarning() << Q_FUNC_INFO << "The widget with key :" << key << "could not be instanciated by the factory.";
        return nullptr;
    }
    if(!widget->connect(parameter)) {
        qWarning() << Q_FUNC_INFO << "The parameter could not be connected to the widget.";
    }
    return widget;
}

// ///////////////////////////////////////////////////////////////////
// Register to dtkWidgets layer implementation
// ///////////////////////////////////////////////////////////////////

55 56 57 58
namespace dtk
{
    namespace widgets
    {
59
        namespace parameters
60
        {
61 62 63 64 65
            namespace _private
            {
                dtkWidgetsParameterFactory       factory;
                dtkWidgetsParameterPluginManager manager;
            }
66

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
67
            dtkWidgetsParameterFactory& pluginFactory(void)
68 69 70
            {
                return _private::factory;
            }
71

KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
72
            dtkWidgetsParameterPluginManager& pluginManager(void)
73 74 75
            {
                return _private::manager;
            }
76

77 78 79 80 81
            namespace _private
            {
                dtkCorePluginManagerRecorder mrecorder(&dtk::widgets::manager(), &pluginManager(), "dtkWidgetsParameter");
                dtkCorePluginFactoryRecorder frecorder(&dtk::widgets::manager(), &pluginFactory(), "dtkWidgetsParameter");
            }
82 83 84
        }
    }
}
KLOCZKO Thibaud's avatar
KLOCZKO Thibaud committed
85 86 87

//
// dtkWidgetsParameterFactory.cpp ends here