File indexing completed on 2024-04-14 12:01:16

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "teamcompletermodel.h"
0008 #include <QModelIndex>
0009 
0010 TeamCompleterModel::TeamCompleterModel(QObject *parent)
0011     : QAbstractListModel(parent)
0012 {
0013 }
0014 
0015 TeamCompleterModel::~TeamCompleterModel() = default;
0016 
0017 void TeamCompleterModel::clear()
0018 {
0019     if (!mTeams.isEmpty()) {
0020         beginResetModel();
0021         mTeams.clear();
0022         endResetModel();
0023     }
0024 }
0025 
0026 void TeamCompleterModel::insertTeams(const QVector<TeamCompleter> &teams)
0027 {
0028     clear();
0029     if (!teams.isEmpty()) {
0030         beginInsertRows(QModelIndex(), 0, teams.count() - 1);
0031         mTeams = teams;
0032         endInsertRows();
0033     }
0034 }
0035 
0036 int TeamCompleterModel::rowCount(const QModelIndex &parent) const
0037 {
0038     Q_UNUSED(parent)
0039     return mTeams.count();
0040 }
0041 
0042 QVariant TeamCompleterModel::data(const QModelIndex &index, int role) const
0043 {
0044     if (index.row() < 0 || index.row() >= mTeams.count()) {
0045         return {};
0046     }
0047     const TeamCompleter &team = mTeams.at(index.row());
0048     switch (role) {
0049     case Qt::DisplayRole:
0050     case TeamName:
0051         return team.fname();
0052     case TeamId:
0053         return team.teamId();
0054     case Qt::DecorationRole:
0055     case TeamIcon:
0056         return {};
0057     }
0058 
0059     return {};
0060 }
0061 
0062 #include "moc_teamcompletermodel.cpp"