Warning, file /network/ruqola/src/core/model/teamroomcompletermodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "teamroomcompletermodel.h" 0008 #include <QModelIndex> 0009 0010 TeamRoomCompleterModel::TeamRoomCompleterModel(QObject *parent) 0011 : QAbstractListModel(parent) 0012 { 0013 } 0014 0015 TeamRoomCompleterModel::~TeamRoomCompleterModel() = default; 0016 0017 void TeamRoomCompleterModel::clear() 0018 { 0019 if (!mRooms.isEmpty()) { 0020 beginResetModel(); 0021 mRooms.clear(); 0022 endResetModel(); 0023 } 0024 } 0025 0026 void TeamRoomCompleterModel::setRooms(const QVector<TeamRoomCompleter> &teams) 0027 { 0028 clear(); 0029 if (!teams.isEmpty()) { 0030 beginInsertRows(QModelIndex(), 0, teams.count() - 1); 0031 mRooms = teams; 0032 endInsertRows(); 0033 } 0034 } 0035 0036 int TeamRoomCompleterModel::rowCount(const QModelIndex &parent) const 0037 { 0038 Q_UNUSED(parent) 0039 return mRooms.count(); 0040 } 0041 0042 QVariant TeamRoomCompleterModel::data(const QModelIndex &index, int role) const 0043 { 0044 if (index.row() < 0 || index.row() >= mRooms.count()) { 0045 return {}; 0046 } 0047 const TeamRoomCompleter &room = mRooms.at(index.row()); 0048 switch (role) { 0049 case Qt::DisplayRole: 0050 case TeamName: 0051 return room.name(); 0052 case TeamId: 0053 return room.identifier(); 0054 case Qt::DecorationRole: 0055 case TeamIcon: 0056 return {}; 0057 } 0058 0059 return {}; 0060 } 0061 0062 #include "moc_teamroomcompletermodel.cpp"