QTfrontend/model/playerslistmodel.h
author unc0rr
Sun, 07 Oct 2012 23:59:55 +0400
changeset 7728 664738870325
parent 7725 4ad05a478c6c
child 7731 262228c64f15
permissions -rw-r--r--
Bring back sorting
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>
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
     8
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     9
class PlayersListModel : public QAbstractListModel
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    10
{
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    11
    Q_OBJECT
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    12
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    13
public:
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    14
    enum StateFlag {
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    15
        Ready       = Qt::UserRole,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    16
        ServerAdmin = Qt::UserRole + 1,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    17
        RoomAdmin   = Qt::UserRole + 2,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    18
        Registered  = Qt::UserRole + 3,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    19
        Friend      = Qt::UserRole + 4,
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    20
        Ignore      = Qt::UserRole + 5
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    21
    };
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    22
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    23
    enum SpecialRoles {
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    24
        SortRole = Qt::UserRole + 100
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    25
    };
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    26
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    27
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    28
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    29
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    30
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    31
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
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
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    35
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    36
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    38
public slots:
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    39
    void addPlayer(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    void removePlayer(const QString & nickname);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    42
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    43
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    45
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    46
    QList<DataEntry> m_data;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    47
    void updateIcon(const QModelIndex & index);
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    48
    void updateSortData(const QModelIndex & index);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    49
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    50
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    51
#endif // PLAYERSLISTMODEL_H