[Development] QML and QAbstractListModel
Nils Jeisecke
njeisecke at saltation.de
Sat Jan 12 23:59:05 CET 2013
Hi,
what about adding a new Quick item for "enhanced QAbstractItemModel access".
ListModelAdapter {
id: myModelAdapter
sourceModel: myModel
}
ListView {
model: myModelAdapter.sourceModel
delegate: Text {
MouseArea {
onClicked: console.log(myModelAdapter.data(model.index, "myRole")
}
}
}
Something like this:
#ifndef QQUICKLISTMODELADAPTER_H
#define QQUICKLISTMODELADAPTER_H
#include <QObject>
#include <QAbstractItemModel>
class QQuickListModelAdapter : public QObject
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE
setSourceModel NOTIFY sourceModelChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
explicit QQuickListModelAdapter(QObject *parent = 0);
void setSourceModel(QAbstractItemModel *model);
QAbstractItemModel *sourceModel() const;
Q_INVOKABLE QVariant data(int row, const QString &role);
Q_INVOKABLE bool setData(row, const QString &role, const QVariant &value);
/* other useful methods */
signals:
void sourceModelChanged();
};
#endif // QLISTMODELADAPTER_H
Nils
More information about the Development
mailing list