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/filterinstantmessagingmodel.h" 0021 0022 #include <QUuid> 0023 0024 #include "model/instantmessagingmodel.h" 0025 0026 namespace InstantMessaging 0027 { 0028 FilterInstantMessagingModel::FilterInstantMessagingModel(QObject* parent) 0029 : QSortFilterProxyModel(parent), m_uuid(QUuid::createUuid().toString(QUuid::WithoutBraces)) 0030 { 0031 } 0032 void FilterInstantMessagingModel::setFilterParameter(bool b, QStringList data) 0033 { 0034 if(m_allBut == b && m_filteredId == data) 0035 return; 0036 0037 m_allBut= b; 0038 m_filteredId= data; 0039 invalidateFilter(); 0040 } 0041 0042 QVariant FilterInstantMessagingModel::get(int idx) 0043 { 0044 auto modelIndex= index(idx, 0); 0045 return modelIndex.data(InstantMessagingModel::ChatRole); 0046 } 0047 0048 QString FilterInstantMessagingModel::uuid() const 0049 { 0050 return m_uuid; 0051 } 0052 0053 bool FilterInstantMessagingModel::all() const 0054 { 0055 return m_allBut; 0056 } 0057 0058 bool FilterInstantMessagingModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const 0059 { 0060 bool value= true; 0061 if(m_allBut && m_filteredId.isEmpty()) 0062 value= true; 0063 else if(m_allBut && m_filteredId.isEmpty()) 0064 value= false; 0065 else 0066 { 0067 auto index= sourceModel()->index(source_row, 0, source_parent); 0068 auto id= index.data(InstantMessagingModel::IdRole).toString(); 0069 value= m_filteredId.contains(id) ? !m_allBut : m_allBut; 0070 } 0071 return value; 0072 } 0073 } // namespace InstantMessaging