serverlistcolumn.cpp
1 //------------------------------------------------------------------------------
2 // serverlistcolumn.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "serverlistcolumn.h"
24 
25 #include <QStandardItem>
26 #include <QStringList>
27 
28 using namespace ServerListColumnId;
29 
30 #define RESIZEABLE true
31 
32 const ServerListColumn ServerListColumns::columns[] =
33 {
34  { IDPort, 24, !RESIZEABLE, Qt::AscendingOrder },
35  { IDPlayers, 60, RESIZEABLE, Qt::DescendingOrder },
36  { IDPing, 50, RESIZEABLE, Qt::AscendingOrder },
37  { IDServerName, 200, RESIZEABLE, Qt::AscendingOrder },
38  { IDAddress, 120, RESIZEABLE, Qt::AscendingOrder },
39  { IDIwad, 90, RESIZEABLE, Qt::AscendingOrder },
40  { IDMap, 70, RESIZEABLE, Qt::AscendingOrder },
41  { IDWads, 120, RESIZEABLE, Qt::AscendingOrder },
42  { IDGametype, 150, RESIZEABLE, Qt::AscendingOrder },
43 };
44 
45 QString ServerListColumns::columnLabel(int columnId)
46 {
47  // Column labels need to initialized after the translation is loaded
48  // or they won't get traslated. This piece of code was initialized
49  // statically before.
50  switch (columnId)
51  {
52  case IDPort:
53  return "";
54  case IDPlayers:
55  return tr("Players");
56  case IDPing:
57  return tr("Ping");
58  case IDServerName:
59  return tr("Server Name");
60  case IDAddress:
61  return tr("Address");
62  case IDIwad:
63  return tr("IWAD");
64  case IDMap:
65  return tr("Map");
66  case IDWads:
67  return tr("WADs");
68  case IDGametype:
69  return tr("Game Type");
70  default:
71  return "UNKNOWN_COLUMN";
72  }
73 }
74 
75 QStringList ServerListColumns::generateColumnHeaderLabels()
76 {
77  QStringList labels;
78  for (int i = 0; i < NUM_SERVERLIST_COLUMNS; ++i)
79  labels << columnLabel(i);
80  return labels;
81 }
82 
83 QList<QStandardItem *> ServerListColumns::generateListOfCells()
84 {
85  QList<QStandardItem *> cells;
86  for (int x = 0; x < NUM_SERVERLIST_COLUMNS; ++x)
87  cells.append(new QStandardItem());
88  return cells;
89 }
90 
91 bool ServerListColumns::isColumnVital(int columnId)
92 {
93  // We assume that columnIndex == columnId.
94  return columnId == IDAddress || columnId == IDPort;
95 }