start implementing model for koto artist

This commit is contained in:
Joshua Strobl 2024-10-27 19:16:30 +02:00
parent e3a00ab8ac
commit ddfd17c67c
12 changed files with 267 additions and 34 deletions

View file

@ -0,0 +1,45 @@
#include "structs.hpp"
KotoArtistModel::~KotoArtistModel() {
this->beginResetModel();
this->m_artists.clear();
this->endResetModel();
}
void KotoArtistModel::addArtist(KotoArtist* artist) {
this->beginInsertRows(QModelIndex(), this->m_artists.count(), this->m_artists.count());
this->m_artists.append(artist);
this->endInsertRows();
}
int KotoArtistModel::rowCount(const QModelIndex& parent) const {
return this->m_artists.count();
}
QVariant KotoArtistModel::data(const QModelIndex& index, int role) const {
if (!index.isValid()) { return {}; }
if (index.row() >= this->m_artists.size()) { return {}; }
if (role == KotoArtistRoles::NameRole) {
return this->m_artists.at(index.row())->getName();
} else if (role == KotoArtistRoles::PathRole) {
return this->m_artists.at(index.row())->getPath();
} else if (role == KotoArtistRoles::UuidRole) {
return this->m_artists.at(index.row())->uuid;
} else {
return {};
}
}
QList<KotoArtist*> KotoArtistModel::getArtists() {
return this->m_artists;
}
QHash<int, QByteArray> KotoArtistModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[NameRole] = QByteArrayLiteral("name");
roles[PathRole] = QByteArrayLiteral("path");
roles[UuidRole] = QByteArrayLiteral("uuid");
return roles;
}