Automatic column names.

print
Josef Rokos 9 years ago
parent b7cfb8c39c
commit 49b2e231c0

@ -95,6 +95,30 @@ public:
private: private:
QList<QSharedPointer<T> > m_list; QList<QSharedPointer<T> > m_list;
// QAbstractItemModel interface
public:
QVariant headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole) {
return QVariant();
}
if (orientation == Qt::Horizontal) {
QObject *entity = (QObject*)new T();
for (int i = 0; i < entity->metaObject()->propertyCount(); i++) {
if (i == section) {
QString colName(entity->metaObject()->property(i + 1).name());
return tr(colName.toStdString().c_str());
}
}
delete entity;
}
return QVariant(section + 1);
}
}; };
#endif // ODBTABLEMODEL_H #endif // ODBTABLEMODEL_H

Loading…
Cancel
Save