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*>()) {} i_tracks(QHash<QUuid, KotoTrack*>()) {}
Cartographer& Cartographer::instance() { Cartographer& Cartographer::instance() {
static Cartographer _instance; static Cartographer _instance(nullptr);
return _instance; return _instance;
} }

View file

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

View file

@ -1,5 +1,7 @@
#include "structs.hpp" #include "structs.hpp"
KotoArtistModel::KotoArtistModel(const QList<KotoArtist*>& artists, QObject* parent) : QAbstractListModel(parent), m_artists(artists) {}
KotoArtistModel::~KotoArtistModel() { KotoArtistModel::~KotoArtistModel() {
this->beginResetModel(); this->beginResetModel();
this->m_artists.clear(); 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 (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(); return this->m_artists.at(index.row())->getName();
} else if (role == KotoArtistRoles::PathRole) { } else if (role == KotoArtistRoles::PathRole) {
return this->m_artists.at(index.row())->getPath(); return this->m_artists.at(index.row())->getPath();

View file

@ -65,7 +65,7 @@ class KotoArtistModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: 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); void addArtist(KotoArtist* artist);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;

View file

@ -21,14 +21,11 @@ int main(int argc, char* argv[]) {
if (engine.rootObjects().isEmpty()) { return -1; } if (engine.rootObjects().isEmpty()) { return -1; }
std::thread([]() { std::thread([]() {
// Cartographer::create();
KotoConfig::create(); KotoConfig::create();
KotoDatabase::create(); KotoDatabase::create();
KotoDatabase::instance().connect(); KotoDatabase::instance().connect();
std::cout << "???" << std::endl;
// If we needed to bootstrap, index all libraries, otherwise load the database // If we needed to bootstrap, index all libraries, otherwise load the database
if (KotoDatabase::instance().requiredBootstrap()) { if (KotoDatabase::instance().requiredBootstrap()) {
indexAllLibraries(); indexAllLibraries();

View file

@ -2,6 +2,7 @@ import QtQuick
import QtQuick.Controls as Controls import QtQuick.Controls as Controls
import QtQuick.Layouts import QtQuick.Layouts
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import com.github.joshstrobl.koto
Kirigami.ScrollablePage { Kirigami.ScrollablePage {
Component { Component {