mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-05 10:12:46 +00:00
Move QObject-wrapping code into templates
Previously, this pattern was copy-pasted in a few places. This is undesirable, so the code has been moved into templates. Fixes #30
This commit is contained in:
parent
0fafb19c7d
commit
b8933ddca4
5 changed files with 87 additions and 17 deletions
|
@ -22,6 +22,7 @@
|
|||
#include "JellyfinQt/loader/http/items.h"
|
||||
#include "JellyfinQt/loader/http/userlibrary.h"
|
||||
#include "JellyfinQt/viewmodel/userdata.h"
|
||||
#include "JellyfinQt/viewmodel/utils.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace ViewModel {
|
||||
|
@ -81,11 +82,9 @@ void Item::updateMediaStreams() {
|
|||
qDebug() << m_audioStreams.size() << " audio streams, " << m_videoStreams.size() << " video streams, "
|
||||
<< m_subtitleStreams.size() << " subtitle streams, " << m_allMediaStreams.size() << " streams total";
|
||||
|
||||
m_artistItems.clear();
|
||||
const QList<DTO::NameGuidPair> artists = m_data->artistItems();
|
||||
for (auto it = artists.cbegin(); it != artists.cend(); it++) {
|
||||
m_artistItems.append(new NameGuidPair(QSharedPointer<DTO::NameGuidPair>::create(*it), this));
|
||||
}
|
||||
qDeleteAll(m_artistItems);
|
||||
m_artistItems = wrapQObjectList<NameGuidPair, DTO::NameGuidPair>(artists.cbegin(), artists.cend(), this);
|
||||
}
|
||||
|
||||
void Item::setUserData(DTO::UserItemDataDto &newData) {
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "JellyfinQt/loader/http/tvshows.h"
|
||||
|
||||
#include "JellyfinQt/viewmodel/userdata.h"
|
||||
#include "JellyfinQt/viewmodel/utils.h"
|
||||
|
||||
#define JF_CASE(roleName) case roleName: \
|
||||
try { \
|
||||
|
@ -96,12 +97,8 @@ QVariant ItemModel::data(const QModelIndex &index, int role) const {
|
|||
return QVariant(item->runTimeTicks().value_or(0));
|
||||
JF_CASE(artists)
|
||||
case RoleNames::artistItems: {
|
||||
QVariantList data;
|
||||
auto artists = item->artistItems();
|
||||
for (auto it = artists.cbegin(); it != artists.cend(); it++) {
|
||||
data.append(QVariant::fromValue(new NameGuidPair(QSharedPointer<DTO::NameGuidPair>::create(*it), const_cast<ItemModel *>(this))));
|
||||
}
|
||||
return data;
|
||||
return wrapQVariantList<NameGuidPair, DTO::NameGuidPair>(artists.cbegin(), artists.cend(), const_cast<ItemModel *>(this));
|
||||
}
|
||||
case RoleNames::isFolder:
|
||||
return QVariant(item->isFolder().value_or(false));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "JellyfinQt/viewmodel/playlist.h"
|
||||
|
||||
#include "JellyfinQt/viewmodel/item.h"
|
||||
#include "JellyfinQt/viewmodel/utils.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace ViewModel {
|
||||
|
@ -87,14 +88,8 @@ QVariant Playlist::data(const QModelIndex &index, int role) const {
|
|||
case RoleNames::artists:
|
||||
return QVariant(rowData->artists());
|
||||
case RoleNames::artistItems: {
|
||||
QVariantList result;
|
||||
|
||||
auto items = rowData->artistItems();
|
||||
for (auto it = items.cbegin(); it != items.cend(); it++) {
|
||||
result.append(QVariant::fromValue(new NameGuidPair(QSharedPointer<DTO::NameGuidPair>::create(*it), const_cast<Playlist *>(this))));
|
||||
}
|
||||
|
||||
return result;
|
||||
auto artists = rowData->artistItems();
|
||||
return wrapQVariantList<NameGuidPair, DTO::NameGuidPair>(artists.cbegin(), artists.cend(), const_cast<Playlist *>(this));
|
||||
}
|
||||
case RoleNames::runTimeTicks:
|
||||
return QVariant(rowData->runTimeTicks().value_or(-1));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue