QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
inputwidgetfactory.h
1 #ifndef QTMVVM_INPUTWIDGETFACTORY_H
2 #define QTMVVM_INPUTWIDGETFACTORY_H
3 
4 #include <functional>
5 
6 #include <QtCore/qobject.h>
7 #include <QtCore/qscopedpointer.h>
8 
9 #include <QtWidgets/qwidget.h>
10 
11 #include "QtMvvmWidgets/qtmvvmwidgets_global.h"
12 
13 namespace QtMvvm {
14 
15 class InputWidgetFactoryPrivate;
18 {
19  Q_OBJECT
20 
21 public:
23  Q_INVOKABLE explicit InputWidgetFactory(QObject *parent = nullptr);
24  virtual ~InputWidgetFactory();
25 
27  virtual QWidget *createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties);
28 
30  template <typename TType, typename TWidget>
31  inline void addSimpleWidget();
33  virtual void addSimpleWidget(const QByteArray &type, const std::function<QWidget*(QWidget*)> &creator);
34 
36  template <typename TAliasType, typename TTargetType>
37  inline void addAlias();
39  virtual void addAlias(const QByteArray &alias, const QByteArray &targetType);
40 
41 private:
43 };
44 
45 template<typename TType, typename TWidget>
47 {
48  addSimpleWidget(QMetaType::typeName(qMetaTypeId<TType>()), [](QWidget *parent){
49  return new TWidget(parent);
50  });
51 }
52 
53 template<typename TAliasType, typename TTargetType>
55 {
56  addAlias(QMetaType::typeName(qMetaTypeId<TAliasType>()), QMetaType::typeName(qMetaTypeId<TTargetType>()));
57 }
58 
59 }
60 
61 #endif // QTMVVM_INPUTWIDGETFACTORY_H
void addAlias()
Adds a type name alias.
virtual QWidget * createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties)
Create a new input widget of the given input type.
const char * typeName(int typeId)
A factory class to generate input edit widgets by their type names.
Q_INVOKABLE InputWidgetFactory(QObject *parent=nullptr)
Default constructor.
The primary namespace of the QtMvvm library.
Definition: binding.h:10
QObject * parent() const
void addSimpleWidget()
Adds a new generator to create widgets for the given type.