AutoTableModel now can display data from related table.
Usage example of ComboBox binding in Accommodation plugin.
This commit is contained in:
@@ -60,6 +60,7 @@ public:
|
||||
protected:
|
||||
virtual void bindOtherToUi() {}
|
||||
virtual bool bindOtherToData() { return true; }
|
||||
virtual void registerCombos() {}
|
||||
|
||||
private:
|
||||
QSharedPointer<T> m_entity;
|
||||
@@ -69,6 +70,7 @@ private:
|
||||
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()));
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "core_global.h"
|
||||
#include "exprevaluator.h"
|
||||
#include "itablemodel.h"
|
||||
#include "data/comboitem.h"
|
||||
|
||||
template<class T>
|
||||
class AutoTableModel : public ITableModel
|
||||
@@ -51,7 +52,13 @@ public:
|
||||
QSharedPointer<T> entity = m_list.at(index.row());
|
||||
QObject *rawEntity = (QObject*)entity.data();
|
||||
|
||||
return rawEntity->property(rawEntity->metaObject()->property(index.column() + 1).name());
|
||||
QVariant dispData = rawEntity->property(rawEntity->metaObject()->property(index.column() + 1).name());
|
||||
if (dispData.canConvert<QObject*>() && qobject_cast<ComboItem*>(dispData.value<QObject*>()))
|
||||
{
|
||||
return qobject_cast<ComboItem*>(dispData.value<QObject*>())->toString();
|
||||
}
|
||||
|
||||
return dispData;
|
||||
}
|
||||
|
||||
return QVariant::Invalid;
|
||||
|
||||
Reference in New Issue
Block a user