QTfrontend/model/playerslistmodel.h
author unc0rr
Sun, 07 Oct 2012 00:12:46 +0400
changeset 7725 4ad05a478c6c
parent 7723 ca05b576ec74
child 7728 664738870325
permissions -rw-r--r--
Further work on moving to players list model
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
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    23
    explicit PlayersListModel(QObject *parent = 0);
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    24
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    25
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    26
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    27
    QVariant data(const QModelIndex &index, int role) const;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    28
    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
    29
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    30
    bool insertRow(int row, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    31
    bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    32
    bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    33
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    34
public slots:
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    35
    void addPlayer(const QString & nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    36
    void removePlayer(const QString & nickname);
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
    void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
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
private:
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    40
    QHash<quint32, QIcon> & m_icons();
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    41
    typedef QHash<int, QVariant> DataEntry;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    42
    QList<DataEntry> m_data;
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    43
    void updateIcon(const QModelIndex & index);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    44
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    45
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    46
#endif // PLAYERSLISTMODEL_H