File indexing completed on 2024-05-12 05:39:51

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 #ifndef PARTICIPANTSMODEL_H
0021 #define PARTICIPANTSMODEL_H
0022 
0023 #include <QAbstractProxyModel>
0024 #include <QObject>
0025 
0026 #include <QJsonObject>
0027 #include <core_global.h>
0028 class Player;
0029 class CORE_EXPORT ParticipantsModel : public QAbstractProxyModel
0030 {
0031     Q_OBJECT
0032 public:
0033     enum Permission
0034     {
0035         ReadWrite,
0036         ReadOnly,
0037         Hidden,
0038         Permission_count
0039     };
0040     ParticipantsModel();
0041     virtual int rowCount(const QModelIndex& parent) const override;
0042     virtual int columnCount(const QModelIndex& parent) const override;
0043     virtual QVariant data(const QModelIndex& index, int role) const override;
0044     virtual QModelIndex parent(const QModelIndex& child) const override;
0045     virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
0046     virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
0047 
0048     QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override;
0049     QModelIndex mapToSource(const QModelIndex& proxyIndex) const override;
0050 
0051     QString ownerId() const;
0052     void setOwnerId(const QString& id);
0053 
0054     void saveModel(QJsonObject& root);
0055     void loadModel(QJsonObject& root);
0056 
0057     ParticipantsModel::Permission getPermissionFor(Player* player);
0058 
0059 public slots:
0060     void promotePlayerToRead(const QModelIndex& index);
0061     void promotePlayerToReadWrite(const QModelIndex& index);
0062     void demotePlayerToRead(const QModelIndex& index);
0063     void demotePlayerToHidden(const QModelIndex& index);
0064 
0065     void promotePlayer(const QModelIndex& index);
0066     void demotePlayer(const QModelIndex& index);
0067 
0068 private:
0069     QStringList m_readOnly;
0070     QStringList m_readWrite;
0071     QStringList m_hidden;
0072 
0073     QStringList m_permissionGroup;
0074 
0075     QString m_ownerId;
0076 };
0077 
0078 #endif // PARTICIPANTSMODEL_H