| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by The qGo Project * |
| 3 | * * |
| 4 | * This file is part of qGo. * |
| 5 | * * |
| 6 | * qGo is free software: you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 18 | * or write to the Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | #ifndef LISTVIEWS_H |
| 23 | #define LISTVIEWS_H |
| 24 | #include <QAbstractTableModel> |
| 25 | #include <QSortFilterProxyModel> |
| 26 | class GameListing; |
| 27 | class PlayerListing; |
| 28 | |
| 29 | enum ObserverListingColumn { OC_NAME=0, OC_RANK, O_TOTALCOLUMNS }; |
| 30 | |
| 31 | enum PlayerListingColumn { PC_STATUS=0, PC_NAME, PC_RANK, PC_PLAYING, |
| 32 | PC_OBSERVING, PC_WINS, PC_LOSSES, PC_IDLE, PC_COUNTRY, |
| 33 | PC_MATCHPREFS, P_TOTALCOLUMNS, PC_NOTIFY, PC_ONLINE}; |
| 34 | |
| 35 | enum SimplePlayerListingColumn { SPC_NAME=0, SPC_NOTIFY }; |
| 36 | |
| 37 | enum GameListingColumn { GC_ID=0, GC_WHITENAME, GC_WHITERANK, GC_BLACKNAME, |
| 38 | GC_BLACKRANK, |
| 39 | GC_MOVES, GC_SIZE, GC_HANDICAP, GC_KOMI, |
| 40 | GC_BYOMI, GC_FLAGS, |
| 41 | GC_OBSERVERS, G_TOTALCOLUMNS, GC_RUNNING }; |
| 42 | |
| 43 | #define LIST_SORT_ROLE Qt::UserRole |
| 44 | |
| 45 | class PlayerListSortFilterProxyModel : public QSortFilterProxyModel |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | public: |
| 49 | PlayerListSortFilterProxyModel(QObject * parent = NULL); |
| 50 | void setFilterOpen(bool state); |
| 51 | void setFilterFriends(bool state); |
| 52 | void setFilterFans(bool state); |
| 53 | void setFilterMinRank(int rank); |
| 54 | void setFilterMaxRank(int rank); |
| 55 | protected: |
| 56 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; |
| 57 | private: |
| 58 | int rankMin; |
| 59 | int rankMax; |
| 60 | bool open, friends, fans, noblock; |
| 61 | }; |
| 62 | |
| 63 | class GamesListSortFilterProxyModel : public QSortFilterProxyModel |
| 64 | { |
| 65 | Q_OBJECT |
| 66 | public: |
| 67 | GamesListSortFilterProxyModel(QObject * parent = NULL); |
| 68 | void setFilterWatch(bool state); |
| 69 | protected: |
| 70 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; |
| 71 | private: |
| 72 | bool watches; |
| 73 | }; |
| 74 | |
| 75 | class PlayerListModel : public QAbstractTableModel |
| 76 | { |
| 77 | Q_OBJECT |
| 78 | public: |
| 79 | PlayerListModel(); |
| 80 | ~PlayerListModel(); |
| 81 | |
| 82 | virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; |
| 83 | QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
| 84 | virtual QVariant data(const QModelIndex & index, int role) const; |
| 85 | Qt::ItemFlags flags(const QModelIndex & index) const; |
| 86 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 87 | virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; |
| 88 | |
| 89 | void insertListing(PlayerListing * item); |
| 90 | void removeListing(PlayerListing * const l); |
| 91 | void clearList(void); |
| 92 | PlayerListing * playerListingFromIndex(const QModelIndex &); |
| 93 | void setAccountName(const QString & name) { account_name = name; } |
| 94 | PlayerListing * getEntry(const QString & name); |
| 95 | PlayerListing * getEntry(unsigned int id); |
| 96 | PlayerListing * getPlayerFromNotNickName(const QString & notnickname); |
| 97 | PlayerListing * updateEntry(PlayerListing * listing); |
| 98 | protected: |
| 99 | friend class PlayerListSortFilterProxyModel; |
| 100 | friend class Room; |
| 101 | QList <PlayerListing *> items; |
| 102 | QString account_name; |
| 103 | }; |
| 104 | |
| 105 | class ObserverListModel : public PlayerListModel |
| 106 | { |
| 107 | public: |
| 108 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 109 | virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; |
| 110 | virtual QVariant data(const QModelIndex & index, int role) const; |
| 111 | }; |
| 112 | |
| 113 | class SimplePlayerListModel: public PlayerListModel |
| 114 | { |
| 115 | public: |
| 116 | SimplePlayerListModel(bool _notify_column); |
| 117 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 118 | virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; |
| 119 | virtual QVariant data(const QModelIndex & index, int role) const; |
| 120 | private: |
| 121 | bool notify_column; |
| 122 | }; |
| 123 | |
| 124 | class GamesListModel : public QAbstractTableModel |
| 125 | { |
| 126 | Q_OBJECT |
| 127 | public: |
| 128 | GamesListModel(); |
| 129 | ~GamesListModel(); |
| 130 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 131 | virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; |
| 132 | GameListing * getEntry(unsigned int id); |
| 133 | void updateListing(GameListing *listing); |
| 134 | void clearList(void); |
| 135 | virtual QVariant data(const QModelIndex & index, int role) const; |
| 136 | GameListing * gameListingFromIndex(const QModelIndex &); |
| 137 | void insertListing(GameListing *item); |
| 138 | virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; |
| 139 | QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const; |
| 140 | signals: |
| 141 | void countChanged(int); |
| 142 | protected: |
| 143 | friend class GamesListSortFilterProxyModel; |
| 144 | friend class Room; |
| 145 | QList <GameListing *> items; |
| 146 | }; |
| 147 | |
| 148 | #endif //!LISTVIEWS_H |