fix: rendering artists from cartographer

Thanks @g-fb. Resolves #32.
This commit is contained in:
Joshua Strobl 2024-10-28 19:20:35 +02:00
parent d95cfa3f36
commit 8ff470989b
6 changed files with 14 additions and 12 deletions

View file

@ -10,7 +10,7 @@ Cartographer::Cartographer(QObject* parent)
i_tracks(QHash<QUuid, KotoTrack*>()) {}
Cartographer& Cartographer::instance() {
static Cartographer _instance;
static Cartographer _instance(nullptr);
return _instance;
}

View file

@ -16,16 +16,16 @@ class Cartographer : public QObject {
QML_ELEMENT
QML_SINGLETON
// Q_PROPERTY(QQmlListProperty<KotoAlbum*> albums READ getAlbumsQml)
Q_PROPERTY(KotoArtistModel* artists READ getArtistsModel)
Q_PROPERTY(KotoArtistModel* artists READ getArtistsModel CONSTANT)
// Q_PROPERTY(QQmlListProperty<KotoTrack*> tracks READ getTracksQml)
public:
Cartographer(QObject* parent = nullptr);
Cartographer(QObject* parent);
static Cartographer& instance();
// static Cartographer* create(QQmlEngine* engine, QJSEngine*) {
// engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
// return &instance();
// }
static Cartographer* create(QQmlEngine*, QJSEngine*) {
QQmlEngine::setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
return &instance();
}
void addAlbum(KotoAlbum* album);
void addArtist(KotoArtist* artist);

View file

@ -1,5 +1,7 @@
#include "structs.hpp"
KotoArtistModel::KotoArtistModel(const QList<KotoArtist*>& artists, QObject* parent) : QAbstractListModel(parent), m_artists(artists) {}
KotoArtistModel::~KotoArtistModel() {
this->beginResetModel();
this->m_artists.clear();
@ -21,7 +23,9 @@ QVariant KotoArtistModel::data(const QModelIndex& index, int role) const {
if (index.row() >= this->m_artists.size()) { return {}; }
if (role == KotoArtistRoles::NameRole) {
if (role == Qt::DisplayRole) {
return this->m_artists.at(index.row())->getName();
} else 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();

View file

@ -65,7 +65,7 @@ class KotoArtistModel : public QAbstractListModel {
Q_OBJECT
public:
explicit KotoArtistModel(const QList<KotoArtist*>& artists, QObject* parent = nullptr) : QAbstractListModel(parent), m_artists(artists) {}
explicit KotoArtistModel(const QList<KotoArtist*>& artists, QObject* parent = nullptr);
void addArtist(KotoArtist* artist);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;