QTfrontend/model/playerslistmodel.h
author Periklis Ntanasis <pntanasis@gmail.com>
Mon, 16 Sep 2013 04:04:15 +0300
branchspacecampaign
changeset 9629 1655c50d9c51
parent 8891 bf67b4d7d7b4
child 9503 8f9b04138456
permissions -rw-r--r--
hats
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     1
#ifndef PLAYERSLISTMODEL_H
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     2
#define PLAYERSLISTMODEL_H
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     3
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     4
#include <QAbstractListModel>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     5
#include <QHash>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     6
#include <QIcon>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     7
#include <QModelIndex>
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
     8
#include <QSet>
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     9
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    10
class PlayersListModel : public QAbstractListModel
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    11
{
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    12
    Q_OBJECT
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    13
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    14
public:
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    15
    enum StateFlag {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    16
        Ready       = Qt::UserRole,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    17
        ServerAdmin = Qt::UserRole + 1,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    18
        RoomAdmin   = Qt::UserRole + 2,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    19
        Registered  = Qt::UserRole + 3,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    20
        Friend      = Qt::UserRole + 4,
7765
1e162c1d6dc7 'In game' client flag, both server and frontend support
unc0rr
parents: 7737
diff changeset
    21
        Ignore      = Qt::UserRole + 5,
1e162c1d6dc7 'In game' client flag, both server and frontend support
unc0rr
parents: 7737
diff changeset
    22
        InGame      = Qt::UserRole + 6
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    23
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    24
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    25
    enum SpecialRoles {
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    26
        SortRole       = Qt::UserRole + 100,
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    27
        RoomFilterRole = Qt::UserRole + 101
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    28
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    29
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    30
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    31
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    33
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    34
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    35
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
7737
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    36
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    37
    bool isFlagSet(const QString & nickname, StateFlag flagType);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    38
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    39
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    42
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    43
public slots:
8891
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    44
    void addPlayer(const QString & nickname, bool notify);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    45
    void removePlayer(const QString & nickname, const QString & msg = QString());
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    46
    void playerJoinedRoom(const QString & nickname, bool notify);
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    47
    void playerLeftRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    48
    void resetRoomFlags();
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    49
    void setNickname(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    50
8891
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    51
signals:
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    52
    void nickAdded(const QString& nick, bool notifyNick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    53
    void nickRemoved(const QString& nick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    54
    void nickAddedLobby(const QString& nick, bool notifyNick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    55
    void nickRemovedLobby(const QString& nick);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    56
    void nickRemovedLobby(const QString& nick, const QString& message);
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    57
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    58
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    59
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    60
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    61
    QList<DataEntry> m_data;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    62
    QSet<QString> m_friendsSet, m_ignoredSet;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    63
    QString m_nickname;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    64
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    65
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    66
    void updateSortData(const QModelIndex & index);
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    67
    void loadSet(QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    68
    void saveSet(const QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    69
    void checkFriendIgnore(const QModelIndex & mi);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    70
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    71
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    72
#endif // PLAYERSLISTMODEL_H