status-desktop/src-cpp/app/modules/startup/onboarding/model.cpp

67 lines
1.3 KiB
C++
Raw Normal View History

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)
: QAbstractListModel(parent)
2022-01-06 19:29:19 +00:00
{ }
QHash<int, QByteArray> Model::roleNames() const
{
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
{
return m_items.size();
2022-01-06 19:29:19 +00:00
}
QVariant Model::data(const QModelIndex& index, int role) const
{
if(!index.isValid())
{
return QVariant();
}
2022-01-06 19:29:19 +00:00
if(index.row() < 0 || index.row() > m_items.size())
{
return QVariant();
}
2022-01-06 19:29:19 +00:00
Item item = m_items[index.row()];
2022-01-06 19:29:19 +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
return QVariant();
2022-01-06 19:29:19 +00:00
}
void Model::setItems(QVector<Item> items)
{
beginResetModel();
m_items = items;
endResetModel();
2022-01-06 19:29:19 +00:00
}
} // namespace Onboarding
} // namespace Startup
} // namespace Modules