12345678910111213141516171819202122232425262728293031323334353637 |
- #include "listview_ad.h"
- Listview_ad::Listview_ad(QObject *parent)
- : QAbstractListModel(parent)
- {
- }
- void Listview_ad::setData(const QVariantList &data)
- {
- beginResetModel();
- m_data = data;
- endResetModel();
- }
- int Listview_ad::rowCount(const QModelIndex &parent) const
- {
- Q_UNUSED(parent)
- return m_data.count();
- }
- QVariant Listview_ad::data(const QModelIndex &index, int role) const
- {
- if (!index.isValid())
- return QVariant();
- if (role == Qt::DisplayRole || role == Qt::EditRole)
- return m_data.at(index.row()).toMap()["header"];
- return QVariant();
- }
- QHash<int, QByteArray> Listview_ad::roleNames() const
- {
- QHash<int, QByteArray> roles;
- roles[Qt::DisplayRole] = "display";
- roles[Qt::EditRole] = "edit";
- return roles;
- }
|