Merge branch 'master' of https://git.bukova.info/repos/git/prodejna
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
#include <QMessageBox>
|
||||
#include <QComboBox>
|
||||
|
||||
#include "iform.h"
|
||||
#include "service.h"
|
||||
@@ -16,6 +17,7 @@
|
||||
#include "iservice.h"
|
||||
#include "iplugin.h"
|
||||
|
||||
#include "combodata.h"
|
||||
|
||||
template <class T>
|
||||
class AutoForm : public IForm
|
||||
@@ -53,6 +55,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void registerBinding(QComboBox *combo, const QList<ComboData> &values) {
|
||||
m_bindCombos[combo] = values;
|
||||
}
|
||||
|
||||
void registerValidator(IValidator *validator) {
|
||||
m_validators.append(validator);
|
||||
}
|
||||
@@ -60,18 +66,46 @@ public:
|
||||
protected:
|
||||
virtual void bindOtherToUi() {}
|
||||
virtual bool bindOtherToData() { return true; }
|
||||
virtual void registerCombos() {}
|
||||
|
||||
private:
|
||||
QSharedPointer<T> m_entity;
|
||||
QList<QWidget*> m_bindWidgets;
|
||||
QList<IValidator*> m_validators;
|
||||
QHash<QComboBox*, QList<ComboData> > m_bindCombos;
|
||||
bool m_newRec;
|
||||
|
||||
void bindToUi() {
|
||||
registerCombos();
|
||||
foreach (QWidget *widget, m_bindWidgets) {
|
||||
const char* prop = widget->metaObject()->userProperty().name();
|
||||
widget->setProperty(prop, ((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()));
|
||||
}
|
||||
|
||||
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
||||
int idx = 0;
|
||||
QVariant field = ((QObject*)m_entity.data())->property(combo->objectName().toStdString().c_str());
|
||||
|
||||
combo->clear();
|
||||
for (int i = 0; i < m_bindCombos[combo].size(); i++) {
|
||||
ComboData data = m_bindCombos[combo][i];
|
||||
combo->addItem(data.label(), data.index());
|
||||
|
||||
if (data.index().canConvert<QObject*>()) {
|
||||
ComboItem* ci = qobject_cast<ComboItem*>(data.index().value<QObject*>());
|
||||
ComboItem* ciField = qobject_cast<ComboItem*>(field.value<QObject*>());
|
||||
if (ci->eq(ciField)) {
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
else if (field == data.index()) {
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
combo->setCurrentIndex(idx);
|
||||
}
|
||||
|
||||
bindOtherToUi();
|
||||
}
|
||||
|
||||
@@ -88,6 +122,10 @@ private:
|
||||
((QObject*)m_entity.data())->setProperty(widget->objectName().toStdString().c_str(), widget->property(prop));
|
||||
}
|
||||
|
||||
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
||||
((QObject*)m_entity.data())->setProperty(combo->objectName().toStdString().c_str(), combo->currentData());
|
||||
}
|
||||
|
||||
return bindOtherToData();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user