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 HIDDEN true
31 #define RESIZEABLE true
32 
33 ServerListColumn ServerListColumns::columns[] =
34 {
35  { IDPort, 24, !HIDDEN, !RESIZEABLE, Qt::AscendingOrder },
36  { IDPlayers, 60, !HIDDEN, RESIZEABLE, Qt::DescendingOrder },
37  { IDPing, 50, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
38  { IDServerName, 200, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
39  { IDAddress, 120, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
40  { IDIwad, 90, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
41  { IDMap, 70, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
42  { IDWads, 120, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
43  { IDGametype, 150, !HIDDEN, RESIZEABLE, Qt::AscendingOrder },
44  { IDHiddenGroup, 0, HIDDEN, !RESIZEABLE, Qt::DescendingOrder },
45  { IDHiddenServerPointer, 0, HIDDEN, !RESIZEABLE, Qt::AscendingOrder }
46 };
47 
48 QString ServerListColumns::columnLabel(int columnId)
49 {
50  // Column labels need to initialized after the translation is loaded
51  // or they won't get traslated. This piece of code was initialized
52  // statically before.
53  switch (columnId)
54  {
55  case IDPort:
56  return "";
57  case IDPlayers:
58  return tr("Players");
59  case IDPing:
60  return tr("Ping");
61  case IDServerName:
62  return tr("Server Name");
63  case IDAddress:
64  return tr("Address");
65  case IDIwad:
66  return tr("IWAD");
67  case IDMap:
68  return tr("Map");
69  case IDWads:
70  return tr("WADs");
71  case IDGametype:
72  return tr("Game Type");
73  case IDHiddenGroup:
74  return "SORT_GROUP";
75  case IDHiddenServerPointer:
76  return "SERVER_POINTER";
77  default:
78  return "UNKNOWN_COLUMN";
79  }
80 }
81 
82 QStringList ServerListColumns::generateColumnHeaderLabels()
83 {
84  QStringList labels;
85  for (int i = 0; i < NUM_SERVERLIST_COLUMNS; ++i)
86  {
87  labels << columnLabel(i);
88  }
89  return labels;
90 }
91 
92 QList<QStandardItem*> ServerListColumns::generateListOfCells()
93 {
94  QList<QStandardItem*> cells;
95  for (int x = 0; x < NUM_SERVERLIST_COLUMNS; ++x)
96  {
97  cells.append(new QStandardItem());
98  }
99  return cells;
100 }
101 
102 bool ServerListColumns::isColumnVital(int columnId)
103 {
104  // We assume that columnIndex == columnId.
105  return columns[columnId].bHidden || columnId == IDAddress || columnId == IDPort;
106 }