qmlfrontend/players_model.h
author S.D.
Tue, 27 Sep 2022 14:59:03 +0300
changeset 15878 fc3cb23fd26f
parent 15047 773beead236f
permissions -rw-r--r--
Allow to see rooms of incompatible versions in the lobby For the new clients the room version is shown in a separate column. There is also a hack for previous versions clients: the room vesion specifier is prepended to the room names for rooms of incompatible versions, and the server shows 'incompatible version' error if the client tries to join them.
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>
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
     5
#include <QFont>
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     6
#include <QHash>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     7
#include <QIcon>
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
     8
#include <QModelIndex>
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
     9
#include <QSet>
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    10
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    11
class PlayersListModel : public QAbstractListModel {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    12
  Q_OBJECT
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    13
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    14
 public:
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    15
  enum StateFlag {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    16
    Ready = Qt::UserRole,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    17
    ServerAdmin = Qt::UserRole + 1,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    18
    RoomAdmin = Qt::UserRole + 2,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    19
    Registered = Qt::UserRole + 3,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    20
    Friend = Qt::UserRole + 4,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    21
    Ignore = Qt::UserRole + 5,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    22
    InGame = Qt::UserRole + 6,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    23
    InRoom = Qt::UserRole + 7,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    24
    Contributor = Qt::UserRole + 8
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    25
    // if you add a role that will affect the player icon,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    26
    // then also add it to the flags Qlist in updateIcon()!
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    27
  };
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    28
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    29
  enum SpecialRoles {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    30
    SortRole = Qt::UserRole + 100,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    31
    RoomFilterRole = Qt::UserRole + 101
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    32
  };
7728
664738870325 Bring back sorting
unc0rr
parents: 7725
diff changeset
    33
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    34
  explicit PlayersListModel(QObject *parent = 0);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    35
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    36
  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    37
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    38
  QVariant data(const QModelIndex &index, int role) const override;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    39
  bool setData(const QModelIndex &index, const QVariant &value,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    40
               int role = Qt::DisplayRole) override;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    41
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    42
  void setFlag(const QString &nickname, StateFlag flagType, bool isSet);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    43
  bool isFlagSet(const QString &nickname, StateFlag flagType);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    44
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    45
  bool insertRows(int row, int count,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    46
                  const QModelIndex &parent = QModelIndex()) override;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    47
  bool removeRows(int row, int count,
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    48
                  const QModelIndex &parent = QModelIndex()) override;
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    49
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    50
  QModelIndex nicknameIndex(const QString &nickname);
9727
e89ed65f62da small cleanup etc
sheepluva
parents: 9725
diff changeset
    51
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    52
 public slots:
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    53
  void addPlayer(const QString &nickname, bool notify);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    54
  void removePlayer(const QString &nickname, const QString &msg = QString());
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    55
  void playerJoinedRoom(const QString &nickname, bool notify);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    56
  void playerLeftRoom(const QString &nickname);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    57
  void resetRoomFlags();
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    58
  void setNickname(const QString &nickname);
7725
4ad05a478c6c Further work on moving to players list model
unc0rr
parents: 7723
diff changeset
    59
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    60
 signals:
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    61
  void nickAdded(const QString &nick, bool notifyNick);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    62
  void nickRemoved(const QString &nick);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    63
  void nickAddedLobby(const QString &nick, bool notifyNick);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    64
  void nickRemovedLobby(const QString &nick, const QString &message);
8891
bf67b4d7d7b4 - Better fix to friends joins/quits highlighting problem
unc0rr
parents: 7765
diff changeset
    65
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    66
 private:
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    67
  QHash<quint32, QIcon> &m_icons();
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    68
  using DataEntry = QHash<int, QVariant>;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    69
  QList<DataEntry> m_data;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    70
  QSet<QString> m_friendsSet, m_ignoredSet;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    71
  QString m_nickname;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    72
  QFont m_fontInRoom;
7732
fad3408fdcc1 Load friends/ignored nicks from file
unc0rr
parents: 7731
diff changeset
    73
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    74
  void updateIcon(const QModelIndex &index);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    75
  void updateSortData(const QModelIndex &index);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    76
  void loadSet(QSet<QString> &set, const QString &fileName);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    77
  void saveSet(const QSet<QString> &set, const QString &fileName);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    78
  void checkFriendIgnore(const QModelIndex &mi);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    79
  bool isFriend(const QString &nickname);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    80
  bool isIgnored(const QString &nickname);
7723
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    81
};
ca05b576ec74 Start moving to players list model.
unc0rr
parents:
diff changeset
    82
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 10753
diff changeset
    83
#endif  // PLAYERSLISTMODEL_H