start implementing model for koto artist
This commit is contained in:
parent
e3a00ab8ac
commit
ddfd17c67c
12 changed files with 267 additions and 34 deletions
45
desktop/datalake/models.cpp
Normal file
45
desktop/datalake/models.cpp
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue