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 this->roles = QAbstractListModel::roleNames();
91 this->roles[Qt::DisplayRole] =
"modelData";
100 QAbstractListModel(parent), lst(list)
102 this->roles = QAbstractListModel::roleNames();
103 this->roles[Qt::DisplayRole] =
"modelData";
106QVariantListModel::~QVariantListModel() {
125int QVariantListModel::rowCount(
const QModelIndex &parent)
const
127 if (parent.isValid())
137 const QModelIndex &idx)
const
139 if (!idx.isValid() || column != 0 || row >= lst.count())
140 return QModelIndex();
142 return createIndex(row, 0);
156 if (index.row() < 0 || index.row() >= lst.size())
159 if (role == Qt::DisplayRole || role == Qt::EditRole)
160 return lst.at(index.row());
177 if (index.row() >= 0 && index.row() < lst.size()
178 && (role == Qt::EditRole || role == Qt::DisplayRole))
180 lst.replace(index.row(), value);
181 dataChanged(index, index, QVector<int>() << role);
199 const QModelIndex &parent)
201 if (count < 1 || row < 0 || row > rowCount(parent))
204 beginInsertRows(QModelIndex(), row, row + count - 1);
206 for (
int r = 0; r < count; ++r)
207 lst.insert(row, QVariant());
226 const QModelIndex &parent)
228 if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
231 beginRemoveRows(QModelIndex(), row, row + count - 1);
233 for (
int r = 0; r < count; ++r)
257 int size = lst.size();
258 bool sameSize = list.size() == size;
269 dataChanged(QAbstractListModel::index(0),
270 QAbstractListModel::index(size - 1));
QHash< int, QByteArray > roleNames() const override
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
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