QTfrontend/model/playerslistmodel.h
author unc0rr
Wed, 10 Oct 2012 00:21:18 +0400
changeset 7737 ff63da8a3202
parent 7732 fad3408fdcc1
child 7765 1e162c1d6dc7
permissions -rw-r--r--
- Enable chat context menu actions - Load/save friends/ignore list
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,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    21
        Ignore      = Qt::UserRole + 5
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    22
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    23
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    24
    enum SpecialRoles {
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    25
        SortRole       = Qt::UserRole + 100,
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    26
        RoomFilterRole = Qt::UserRole + 101
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    27
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    28
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    29
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    30
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    31
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    33
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    34
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
7737
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    35
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
ff63da8a3202 - Enable chat context menu actions
unc0rr
parents: 7732
diff changeset
    36
    bool isFlagSet(const QString & nickname, StateFlag flagType);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    38
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    39
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    42
public slots:
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    43
    void addPlayer(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
    void removePlayer(const QString & nickname);
7731
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    45
    void playerJoinedRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    46
    void playerLeftRoom(const QString & nickname);
262228c64f15 Room players list
unc0rr
parents: 7728
diff changeset
    47
    void resetRoomFlags();
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    48
    void setNickname(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    49
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    50
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    51
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    52
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    53
    QList<DataEntry> m_data;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    54
    QSet<QString> m_friendsSet, m_ignoredSet;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    55
    QString m_nickname;
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    56
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    57
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    58
    void updateSortData(const QModelIndex & index);
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    59
    void loadSet(QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    60
    void saveSet(const QSet<QString> & set, const QString & suffix);
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    61
    void checkFriendIgnore(const QModelIndex & mi);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    62
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    63
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    64
#endif // PLAYERSLISTMODEL_H