File indexing completed on 2024-05-05 05:40:28
0001 /*************************************************************************** 0002 * Copyright (C) 2020 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #include "model/filteredplayermodel.h" 0021 #include "model/playermodel.h" 0022 0023 namespace InstantMessaging 0024 { 0025 FilteredPlayerModel::FilteredPlayerModel(const QStringList& list, QObject* parent) 0026 : QSortFilterProxyModel(parent), m_participants(list) 0027 { 0028 } 0029 0030 /*int FilteredPlayerModel::rowCount(const QModelIndex& parent) const 0031 { 0032 if(parent.isValid()) 0033 return 0; 0034 0035 return std::min<int>(m_participants.size(), sourceModel()->rowCount()); 0036 } 0037 0038 QModelIndex FilteredPlayerModel::index(int row, int col, const QModelIndex &parent) const 0039 { 0040 auto rowC = rowCount(); 0041 if(row < 0 || row >= rowC || col < 0 || col > 0 || parent.isValid()) 0042 return QModelIndex(); 0043 return createIndex(row, col, nullptr); 0044 }*/ 0045 0046 QStringList FilteredPlayerModel::recipiantIds() const 0047 { 0048 return m_participants; 0049 } 0050 0051 bool FilteredPlayerModel::hasRecipiant(const QString& uuid) 0052 { 0053 return m_participants.contains(uuid); 0054 } 0055 0056 QString FilteredPlayerModel::recipiantName(const QString& uuid) 0057 { 0058 auto source = sourceModel(); 0059 for(int i= 0; i < source->rowCount(); ++i) 0060 { 0061 auto indexModel= source->index(i, 0); 0062 auto id= indexModel.data(PlayerModel::IdentifierRole).toString(); 0063 if(uuid == id) 0064 return indexModel.data(PlayerModel::NameRole).toString(); 0065 } 0066 return {}; 0067 } 0068 0069 bool FilteredPlayerModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const 0070 { 0071 auto idx= sourceModel()->index(sourceRow, 0, sourceParent); 0072 auto uuid= sourceModel()->data(idx, PlayerModel::IdentifierRole).toString(); 0073 return m_participants.contains(uuid); 0074 } 0075 } // namespace InstantMessaging