49#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
51#include "qvariantlistmodel.h"
53#include <QtCore/qvector.h>
88 QAbstractListModel(parent)
90 QHash<int, QByteArray> roles(roleNames());
91 roles[Qt::DisplayRole] =
"modelData";
101 QAbstractListModel(parent), lst(list)
103 QHash<int, QByteArray> roles(roleNames());
104 roles[Qt::DisplayRole] =
"modelData";
108QVariantListModel::~QVariantListModel() {
124 if (parent.isValid())
134 const QModelIndex &idx)
const
136 if (!idx.isValid() || column != 0 || row >= lst.count())
137 return QModelIndex();
139 return createIndex(row, 0);
153 if (index.row() < 0 || index.row() >= lst.size())
156 if (role == Qt::DisplayRole || role == Qt::EditRole)
157 return lst.at(index.row());
174 if (index.row() >= 0 && index.row() < lst.size()
175 && (role == Qt::EditRole || role == Qt::DisplayRole))
177 lst.replace(index.row(), value);
178 dataChanged(index, index, QVector<int>() << role);
196 const QModelIndex &parent)
198 if (count < 1 || row < 0 || row >
rowCount(parent))
201 beginInsertRows(QModelIndex(), row, row + count - 1);
203 for (
int r = 0; r < count; ++r)
204 lst.insert(row, QVariant());
223 const QModelIndex &parent)
225 if (count <= 0 || row < 0 || (row + count) >
rowCount(parent))
228 beginRemoveRows(QModelIndex(), row, row + count - 1);
230 for (
int r = 0; r < count; ++r)
254 int size = lst.size();
255 bool sameSize = list.size() == size;
266 dataChanged(QAbstractListModel::index(0),
267 QAbstractListModel::index(size - 1));
QModelIndex sibling(int row, int column, const QModelIndex &idx) const override
QVariantListModel(QObject *parent=0)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QVariantList variantList() const
void setVariantList(const QVariantList &list)
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override