#ifndef FORMBINDER_H #define FORMBINDER_H #include #include #include #include #include #include #include "combodata.h" #include "ivalidator.h" #include "iform.h" #include "objectbinder.h" #include "../qdecimal/src/QDecDouble.hh" template class FormBinder : public IForm { public: explicit FormBinder(QWidget *parent = NULL) : IForm(parent) { connect(&m_binder, &ObjectBinder::validationError, [this](QString msg){ emit this->validationError(msg); }); } virtual ~FormBinder() { } void registerBinding(QWidget *widget) { m_binder.registerBinding(widget); } void registerBinding(QComboBox *combo, const QList &values) { m_binder.registerBinding(combo, values); } void registerValidator(IValidator *validator) { m_binder.registerValidator(validator); } void setEntity(QSharedPointer entity) { m_entity = entity; m_binder.setData(m_entity.data()); bindToUi(); } QSharedPointer entity() { return m_entity; } protected: QSharedPointer m_entity; virtual void bindOtherToUi() {} virtual bool bindOtherToData() { return true; } virtual void registerCombos() {} void bindToUi() { registerCombos(); m_binder.bindToUi(); bindOtherToUi(); } bool bindToData() { return m_binder.bindToData() && bindOtherToData(); } private: ObjectBinder m_binder; }; #endif // FORMBINDER_H