Added support for editable grid cells.
This commit is contained in:
@@ -83,6 +83,10 @@ public:
|
||||
|
||||
return Qt::AlignLeft;
|
||||
}
|
||||
if (role == Qt::EditRole)
|
||||
{
|
||||
return dispData;
|
||||
}
|
||||
|
||||
return QVariant::Invalid;
|
||||
}
|
||||
@@ -208,6 +212,22 @@ private:
|
||||
QList<QSharedPointer<T> > m_fullList;
|
||||
bool filtered;
|
||||
|
||||
|
||||
// QAbstractItemModel interface
|
||||
public:
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
|
||||
{
|
||||
if (role == Qt::EditRole)
|
||||
{
|
||||
QSharedPointer<T> entity = m_list.at(index.row());
|
||||
QObject *rawEntity = (QObject*)entity.data();
|
||||
|
||||
rawEntity->setProperty(rawEntity->metaObject()->property(index.column() + 1).name(), value);
|
||||
}
|
||||
|
||||
emit editCompleted();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ODBTABLEMODEL_H
|
||||
|
||||
Reference in New Issue
Block a user