diff --git a/core/autoform.h b/core/autoform.h index 84fa1b0..cc86616 100644 --- a/core/autoform.h +++ b/core/autoform.h @@ -15,7 +15,6 @@ #include "ivalidator.h" #include "combodata.h" - template class AutoForm : public IForm { @@ -84,7 +83,14 @@ private: ComboData data = m_bindCombos[combo][i]; combo->addItem(data.label(), data.index()); - if (field == data.index()) { + if (data.index().canConvert()) { + ComboItem* ci = qobject_cast(data.index().value()); + ComboItem* ciField = qobject_cast(field.value()); + if (ci->eq(ciField)) { + idx = i; + } + } + else if (field == data.index()) { idx = i; } } diff --git a/core/combodata.cpp b/core/combodata.cpp index b7ffef3..8f02b40 100644 --- a/core/combodata.cpp +++ b/core/combodata.cpp @@ -6,10 +6,21 @@ ComboData::ComboData(const QVariant &index, const QString &label) m_label = label; } -ComboData::~ComboData() +ComboData::ComboData(const QSharedPointer &index) { + m_index = QVariant::fromValue(index); + ComboItem *ci = qobject_cast(index.data()); + + if (ci != NULL) + { + m_label = ci->toString(); + } +} +ComboData::~ComboData() +{ } + QVariant ComboData::index() const { return m_index; @@ -19,6 +30,7 @@ void ComboData::setIndex(const QVariant &index) { m_index = index; } + QString ComboData::label() const { return m_label; @@ -28,6 +40,3 @@ void ComboData::setLabel(const QString &label) { m_label = label; } - - - diff --git a/core/combodata.h b/core/combodata.h index 37d7ff9..2e8bfff 100644 --- a/core/combodata.h +++ b/core/combodata.h @@ -2,13 +2,16 @@ #define COMBODATA_H #include +#include #include "core_global.h" +#include "data/comboitem.h" class CORESHARED_EXPORT ComboData { public: ComboData(const QVariant &index, const QString &label); + ComboData(const QSharedPointer &index); ~ComboData(); QVariant index() const; diff --git a/core/core.h b/core/core.h index 0bfc109..851755f 100644 --- a/core/core.h +++ b/core/core.h @@ -8,5 +8,6 @@ #include "transaction.h" #include "gridform.h" #include "permissionservice.h" +#include "combodata.h" #endif // CORE_H diff --git a/core/core.pro b/core/core.pro index 474644a..ea2edf0 100644 --- a/core/core.pro +++ b/core/core.pro @@ -44,7 +44,8 @@ SOURCES += \ filterdialog.cpp \ itablemodel.cpp \ iservice.cpp \ - combodata.cpp + combodata.cpp \ + data/comboitem.cpp HEADERS += core.h\ core_global.h \ @@ -86,7 +87,8 @@ HEADERS += core.h\ itablemodel.h \ data/core_global.h \ iservice.h \ - combodata.h + combodata.h \ + data/comboitem.h unix { target.path = /usr/lib @@ -123,3 +125,5 @@ FORMS += \ OTHER_FILES += \ users/metaData.json \ roles/metaData.json + +TRANSLATIONS = core_cz.ts diff --git a/core/data/comboitem.cpp b/core/data/comboitem.cpp new file mode 100644 index 0000000..04f2b3b --- /dev/null +++ b/core/data/comboitem.cpp @@ -0,0 +1,11 @@ +#include "comboitem.h" + +ComboItem::ComboItem(QObject *parent) + :QObject(parent) +{ +} + +ComboItem::~ComboItem() +{ +} + diff --git a/core/data/comboitem.h b/core/data/comboitem.h new file mode 100644 index 0000000..6540e65 --- /dev/null +++ b/core/data/comboitem.h @@ -0,0 +1,21 @@ +#ifndef COMBOITEM_H +#define COMBOITEM_H + +#include "core_global.h" +#include +#include +#include + +class CORESHARED_EXPORT ComboItem : public QObject +{ + Q_OBJECT + +public: + explicit ComboItem(QObject *parent = NULL); + ~ComboItem(); + + virtual bool eq(ComboItem *other) = 0; + virtual QString toString() = 0; +}; + +#endif // COMBOITEM_H