Compare commits

...
Author SHA1 Message Date
Jonah Brüchert 5112d0bd1b MultiIterableView: Add convinience std::vector constructor 2022-02-14 17:58:55 +01:00
Dimitris Kardarakos 2b60ae8745 Power search page list sections
The Search Page list view can present content in sections according to media type (artist, playlist, song, video). For sections to work, the model that provides the search results should sort the results accordingly.
2022-02-14 17:25:41 +01:00
4 changed files with 33 additions and 2 deletions

No files matched your search

+2 -2
View File
@@ -8,7 +8,7 @@
ArtistModel::ArtistModel(QObject *parent)
: AbstractYTMusicModel(parent)
, m_view(std::span{albums}, std::span{singles}, std::span{songs}, std::span{videos})
, m_view(albums, singles, songs, videos)
{
connect(this, &ArtistModel::channelIdChanged, this, [this] {
if (m_channelId.isEmpty()) {
@@ -32,7 +32,7 @@ ArtistModel::ArtistModel(QObject *parent)
videos = m_artist.videos ? m_artist.videos->results : std::vector<artist::Artist::Video>();
// std::span can't know if the data pointer underneath it was changed, so re-create
m_view = MultiIterableView(std::span{albums}, std::span{singles}, std::span{songs}, std::span{videos});
m_view = MultiIterableView(albums, singles, songs, videos);
endResetModel();
Q_EMIT titleChanged();
+5
View File
@@ -36,6 +36,11 @@ public:
{
}
explicit MultiIterableView(std::vector<Arguments> &...lists)
: MultiIterableView(std::span{lists}...)
{
}
[[nodiscard]] constexpr size_t size() const {
size_t s = 0;
iterate_tuple(m_vectors, [&](auto &vec) {
+25
View File
@@ -22,6 +22,10 @@ SearchModel::SearchModel(QObject *parent)
beginResetModel();
setLoading(false);
m_searchResults = results;
std::sort(m_searchResults.begin(), m_searchResults.end(),
[](search::SearchResultItem const & a, search::SearchResultItem const & b) {
return SearchModel::itemType(a) < SearchModel::itemType(b);
});
endResetModel();
});
connect(&YTMusicThread::instance().get(), &AsyncYTMusic::errorOccurred, this, [this] {
@@ -165,3 +169,24 @@ void SearchModel::triggerItem(int row)
}
}, m_searchResults.at(row));
}
int SearchModel::itemType(search::SearchResultItem const &item)
{
return std::visit([&](auto &&arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr(std::is_same_v<T, search::Album>) {
return SearchModel::Type::Album;
} else if constexpr(std::is_same_v<T, search::Artist>) {
return SearchModel::Type::Artist;
} else if constexpr(std::is_same_v<T, search::Playlist>) {
return SearchModel::Type::Playlist;
} else if constexpr(std::is_same_v<T, search::Song>) {
return SearchModel::Type::Song;
} else if constexpr(std::is_same_v<T, search::Video>) {
return SearchModel::Type::Video;
} else {
Q_UNREACHABLE();
}
}, item);
}
+1
View File
@@ -55,4 +55,5 @@ public:
private:
QString m_searchQuery;
std::vector<search::SearchResultItem> m_searchResults;
static int itemType(search::SearchResultItem const &item);
};