2022-01-06 19:29:19 +00:00
|
|
|
#include "model.h"
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
namespace Modules
|
|
|
|
{
|
|
|
|
namespace Startup
|
|
|
|
{
|
|
|
|
namespace Onboarding
|
|
|
|
{
|
|
|
|
Model::Model(QObject* parent)
|
2022-02-21 18:03:38 +00:00
|
|
|
: QAbstractListModel(parent)
|
2022-01-06 19:29:19 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
QHash<int, QByteArray> Model::roleNames() const
|
|
|
|
{
|
2022-02-21 18:03:38 +00:00
|
|
|
QHash<int, QByteArray> roles;
|
|
|
|
roles[Id] = "accountId";
|
|
|
|
roles[Alias] = "username";
|
|
|
|
roles[Identicon] = "identicon";
|
|
|
|
roles[Address] = "address";
|
|
|
|
roles[KeyUid] = "keyUid";
|
|
|
|
return roles;
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Model::rowCount(const QModelIndex& parent = QModelIndex()) const
|
|
|
|
{
|
2022-02-21 18:03:38 +00:00
|
|
|
return m_items.size();
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Model::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
2022-02-21 18:03:38 +00:00
|
|
|
if(!index.isValid())
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
if(index.row() < 0 || index.row() > m_items.size())
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
Item item = m_items[index.row()];
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
switch(role)
|
|
|
|
{
|
|
|
|
case Id: return QVariant(item.getId());
|
|
|
|
case Alias: return QVariant(item.getAlias());
|
|
|
|
case Identicon: return QVariant(item.getIdenticon());
|
|
|
|
case Address: return QVariant(item.getAddress());
|
|
|
|
case KeyUid: return QVariant(item.getKeyUid());
|
|
|
|
}
|
2022-01-06 19:29:19 +00:00
|
|
|
|
2022-02-21 18:03:38 +00:00
|
|
|
return QVariant();
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Model::setItems(QVector<Item> items)
|
|
|
|
{
|
2022-02-21 18:03:38 +00:00
|
|
|
beginResetModel();
|
|
|
|
m_items = items;
|
|
|
|
endResetModel();
|
2022-01-06 19:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Onboarding
|
|
|
|
} // namespace Startup
|
2022-02-21 18:03:38 +00:00
|
|
|
} // namespace Modules
|