QTfrontend/model/roomslistmodel.h
author S.D.
Tue, 27 Sep 2022 14:59:03 +0300
changeset 15900 fc3cb23fd26f
parent 11046 47a8c19ecb60
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:
6966
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     1
/*
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10739
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
6966
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     4
 *
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     8
 *
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    12
 * GNU General Public License for more details.
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    13
 *
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    14
 * You should have received a copy of the GNU General Public License
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6966
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    17
 */
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    18
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    19
/**
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    20
 * @file
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    21
 * @brief RoomsListModel class definition
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    22
 */
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    23
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    24
#ifndef HEDGEWARS_ROOMSLISTMODEL_H
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    25
#define HEDGEWARS_ROOMSLISTMODEL_H
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    26
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    27
#include <QAbstractTableModel>
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    28
#include <QStringList>
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    29
6983
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6973
diff changeset
    30
#include "DataManager.h"
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6973
diff changeset
    31
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    32
class RoomsListModel : public QAbstractTableModel
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    33
{
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    34
    Q_OBJECT
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    35
public:
6993
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    36
    // if you add a column here, also incr. c_nColumns in constructor
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    37
    // also adjust header in constructor to changes
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    38
    enum Column {
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    39
        StateColumn,
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    40
        NameColumn,
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    41
        PlayerCountColumn,
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    42
        TeamCountColumn,
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    43
        OwnerColumn,
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    44
        MapColumn,
15900
fc3cb23fd26f Allow to see rooms of incompatible versions in the lobby
S.D.
parents: 11046
diff changeset
    45
        ScriptColumn,
6993
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    46
        SchemeColumn,
15900
fc3cb23fd26f Allow to see rooms of incompatible versions in the lobby
S.D.
parents: 11046
diff changeset
    47
        WeaponsColumn,
fc3cb23fd26f Allow to see rooms of incompatible versions in the lobby
S.D.
parents: 11046
diff changeset
    48
        VersionColumn,
6993
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    49
    };
47830cf50574 room list: replace magic table column indexes with enum. makes future changes to the room list format way easier.
sheepluva
parents: 6983
diff changeset
    50
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    51
    explicit RoomsListModel(QObject *parent = 0);
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    52
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    53
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    54
    int rowCount(const QModelIndex & parent) const;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    55
    int columnCount(const QModelIndex & parent) const;
15900
fc3cb23fd26f Allow to see rooms of incompatible versions in the lobby
S.D.
parents: 11046
diff changeset
    56
    int columnCountSupported() const { return c_nColumns; };
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    57
    QVariant data(const QModelIndex &index, int role) const;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    58
6733
5abbc345a82f Handle ROOM* commands in rooms list model
unc0rr
parents: 6732
diff changeset
    59
public slots:
5abbc345a82f Handle ROOM* commands in rooms list model
unc0rr
parents: 6732
diff changeset
    60
    void setRoomsList(const QStringList & rooms);
5abbc345a82f Handle ROOM* commands in rooms list model
unc0rr
parents: 6732
diff changeset
    61
    void addRoom(const QStringList & info);
5abbc345a82f Handle ROOM* commands in rooms list model
unc0rr
parents: 6732
diff changeset
    62
    void removeRoom(const QString & name);
5abbc345a82f Handle ROOM* commands in rooms list model
unc0rr
parents: 6732
diff changeset
    63
    void updateRoom(const QString & name, const QStringList & info);
6973
582ca7e8e338 RoomsListModel:
sheepluva
parents: 6966
diff changeset
    64
    int rowOfRoom(const QString & name);
6733
5abbc345a82f Handle ROOM* commands in rooms list model
unc0rr
parents: 6732
diff changeset
    65
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    66
private:
6973
582ca7e8e338 RoomsListModel:
sheepluva
parents: 6966
diff changeset
    67
    const int c_nColumns;
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    68
    QList<QStringList> m_data;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    69
    QStringList m_headerData;
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 6993
diff changeset
    70
    MapModel * m_staticMapModel;
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 6993
diff changeset
    71
    MapModel * m_missionMapModel;
15900
fc3cb23fd26f Allow to see rooms of incompatible versions in the lobby
S.D.
parents: 11046
diff changeset
    72
    static QString protoToVersion(const QString & proto);
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    73
};
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    74
6966
eda4f63bec41 add missing copyright headers to roomslistmodel
sheepluva
parents: 6733
diff changeset
    75
#endif // HEDGEWARS_ROOMSLISTMODEL_H