File indexing completed on 2024-05-05 05:40:30

0001 /***************************************************************************
0002  *  Copyright (C) 2023 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/proxystatemodel.h"
0021 #include "model/characterstatemodel.h"
0022 
0023 ProxyStateModel::ProxyStateModel(QAbstractItemModel* source, QObject* parent)
0024     : QAbstractListModel(parent), m_source(source)
0025 {
0026 }
0027 
0028 QVariant ProxyStateModel::headerData(int, Qt::Orientation, int) const
0029 {
0030     return {};
0031 }
0032 
0033 int ProxyStateModel::rowCount(const QModelIndex& parent) const
0034 {
0035     if(parent.isValid())
0036         return 0;
0037 
0038     return m_source->rowCount() + 1;
0039 }
0040 
0041 QVariant ProxyStateModel::data(const QModelIndex& index, int role) const
0042 {
0043     if(!index.isValid())
0044         return QVariant();
0045 
0046     auto r= index.row();
0047 
0048     QVariant res;
0049     if(r == 0 && role == Qt::DisplayRole)
0050         res= tr("Any");
0051     else if(r == 0 && role == CharacterStateModel::ID)
0052         res= QString{};
0053     else if(r > 0)
0054         res= m_source->data(m_source->index(r - 1, index.column()), role);
0055 
0056     return res;
0057 }