Added class QMLArray()
This commit is contained in:
parent
2b2cb019fa
commit
3738b3c712
5 changed files with 87 additions and 8 deletions
36
telldus-gui/Plugins/QML/qmlarray.cpp
Normal file
36
telldus-gui/Plugins/QML/qmlarray.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "qmlarray.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class QMLArray::PrivateData {
|
||||
public:
|
||||
QList<QScriptValue> list;
|
||||
};
|
||||
|
||||
QMLArray::QMLArray(QObject *parent) :
|
||||
QAbstractListModel(parent)
|
||||
{
|
||||
d = new PrivateData;
|
||||
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Qt::UserRole+1] = "modelData";
|
||||
setRoleNames(roles);
|
||||
}
|
||||
|
||||
QMLArray::~QMLArray() {
|
||||
delete d;
|
||||
}
|
||||
|
||||
int QMLArray::rowCount(const QModelIndex &parent) const {
|
||||
return d->list.size();
|
||||
}
|
||||
|
||||
QVariant QMLArray::data(const QModelIndex &index, int role) const {
|
||||
return d->list.at(index.row()).toVariant();
|
||||
}
|
||||
|
||||
void QMLArray::push(const QScriptValue &v) {
|
||||
beginInsertRows( QModelIndex(), d->list.size(), d->list.size() );
|
||||
d->list << v;
|
||||
endInsertRows();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue