File indexing completed on 2024-05-05 04:50:48

0001 /*
0002  * SPDX-FileCopyrightText: 2023 George Florea Bănuș <georgefb899@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #include "chaptersmodel.h"
0008 
0009 ChaptersModel::ChaptersModel(QObject *parent)
0010     : QAbstractListModel(parent)
0011 {
0012 }
0013 
0014 int ChaptersModel::rowCount(const QModelIndex &parent) const
0015 {
0016     if (parent.isValid()) {
0017         return 0;
0018     }
0019 
0020     return m_chapters.count();
0021 }
0022 
0023 QVariant ChaptersModel::data(const QModelIndex &index, int role) const
0024 {
0025     if (!index.isValid()) {
0026         return QVariant();
0027     }
0028 
0029     auto chapter = m_chapters.at(index.row());
0030 
0031     switch (role) {
0032     case TitleRole:
0033         return QVariant(chapter.title);
0034 
0035     case StartTimeRole:
0036         return QVariant(chapter.startTime);
0037     }
0038 
0039     return QVariant();
0040 }
0041 
0042 QHash<int, QByteArray> ChaptersModel::roleNames() const
0043 {
0044     QHash<int, QByteArray> roles;
0045     roles[TitleRole] = "title";
0046     roles[StartTimeRole] = "startTime";
0047     return roles;
0048 }
0049 
0050 void ChaptersModel::setChapters(QList<Chapter> &_chapters)
0051 {
0052     beginResetModel();
0053     m_chapters = _chapters;
0054     endResetModel();
0055 }
0056 
0057 #include "moc_chaptersmodel.cpp"