blob: 9eb2629175a97b1420a764970a79e447e70d7cc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* ============================================================
* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net>
* ============================================================ */
#include "playlistmodel.hpp"
#include "playlist.hpp"
PlaylistModel::PlaylistModel(Playlist *parent) : QAbstractItemModel{parent}, playlist(parent)
{
Q_CHECK_PTR(parent);
connect(parent, &Playlist::mediaAboutToBeInserted, this, &PlaylistModel::beginInsertItems);
connect(parent, &Playlist::mediaInserted, this, &PlaylistModel::endInsertItems);
}
QModelIndex PlaylistModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid()) return {};
return createIndex(row, column);
}
QModelIndex PlaylistModel::parent(const QModelIndex &child) const { return {}; }
int PlaylistModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) return 0;
return playlist->count();
}
int PlaylistModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid()) return 0;
return 1;
}
QVariant PlaylistModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return {};
switch (role) {
case Qt::DisplayRole:
return (*playlist)[index.row()];
default:
return {};
}
}
|