QTfrontend/model/playerslistmodel.h
changeset 7725 4ad05a478c6c
parent 7723 ca05b576ec74
child 7728 664738870325
equal deleted inserted replaced
7724:36c539c9cfb1 7725:4ad05a478c6c
     1 #ifndef PLAYERSLISTMODEL_H
     1 #ifndef PLAYERSLISTMODEL_H
     2 #define PLAYERSLISTMODEL_H
     2 #define PLAYERSLISTMODEL_H
     3 
     3 
     4 #include <QStringListModel>
     4 #include <QAbstractListModel>
       
     5 #include <QHash>
       
     6 #include <QIcon>
       
     7 #include <QModelIndex>
     5 
     8 
     6 class PlayersListModel : public QStringListModel
     9 class PlayersListModel : public QAbstractListModel
     7 {
    10 {
     8     Q_OBJECT
    11     Q_OBJECT
       
    12 
     9 public:
    13 public:
       
    14     enum StateFlag {
       
    15         Ready       = Qt::UserRole,
       
    16         ServerAdmin = Qt::UserRole + 1,
       
    17         RoomAdmin   = Qt::UserRole + 2,
       
    18         Registered  = Qt::UserRole + 3,
       
    19         Friend      = Qt::UserRole + 4,
       
    20         Ignore      = Qt::UserRole + 5
       
    21     };
       
    22 
    10     explicit PlayersListModel(QObject *parent = 0);
    23     explicit PlayersListModel(QObject *parent = 0);
    11 
    24 
    12 signals:
    25     int rowCount(const QModelIndex &parent = QModelIndex()) const;
    13     
    26 
       
    27     QVariant data(const QModelIndex &index, int role) const;
       
    28     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole);
       
    29 
       
    30     bool insertRow(int row, const QModelIndex &parent = QModelIndex());
       
    31     bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
       
    32     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
       
    33 
    14 public slots:
    34 public slots:
    15     void addPlayer(const QString & nickname);
    35     void addPlayer(const QString & nickname);
    16     
    36     void removePlayer(const QString & nickname);
       
    37     void setFlag(const QString & nickname, StateFlag flagType, bool isSet);
       
    38 
       
    39 private:
       
    40     QHash<quint32, QIcon> & m_icons();
       
    41     typedef QHash<int, QVariant> DataEntry;
       
    42     QList<DataEntry> m_data;
       
    43     void updateIcon(const QModelIndex & index);
    17 };
    44 };
    18 
    45 
    19 #endif // PLAYERSLISTMODEL_H
    46 #endif // PLAYERSLISTMODEL_H