#ifndef QTMVVM_INPUTWIDGETFACTORY_H #define QTMVVM_INPUTWIDGETFACTORY_H #include #include #include #include #include "QtMvvmWidgets/qtmvvmwidgets_global.h" namespace QtMvvm { class InputWidgetFactoryPrivate; //! A factory class to generate input edit widgets by their type names class InputWidgetFactory : public QObject { Q_OBJECT public: //! Default constructor Q_INVOKABLE explicit InputWidgetFactory(QObject *parent = nullptr); virtual ~InputWidgetFactory(); //! Create a new input widget of the given input type virtual QWidget *createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties); //! Adds a new generator to create widgets for the given type template inline void addSimpleWidget(); //! @copybrief addSimpleWidget() virtual void addSimpleWidget(const QByteArray &type, const std::function &creator); //! Adds a type name alias template inline void addAlias(); //! @copybrief addAlias() virtual void addAlias(const QByteArray &alias, const QByteArray &targetType); private: QScopedPointer d; }; template inline void InputWidgetFactory::addSimpleWidget() { addSimpleWidget(QMetaType::typeName(qMetaTypeId()), [](QWidget *parent){ return new TWidget(parent); }); } template inline void InputWidgetFactory::addAlias() { addAlias(QMetaType::typeName(qMetaTypeId()), QMetaType::typeName(qMetaTypeId())); } } #endif // QTMVVM_INPUTWIDGETFACTORY_H