swift
clientlistmodel.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <Qt>
7 #include <QtGlobal>
8 
10 #include "gui/models/columns.h"
12 #include "misc/network/user.h"
13 #include "misc/propertyindex.h"
16 
17 using namespace swift::misc;
18 using namespace swift::misc::simulation;
19 using namespace swift::misc::network;
20 
21 namespace swift::gui::models
22 {
23  CClientListModel::CClientListModel(QObject *parent) : CListModelBase<CClientList>("ViewClientList", parent)
24  {
25  m_columns.addColumn(CColumn("client", CClient::IndexIcon));
26  m_columns.addColumn(CColumn::standardValueObject("callsign", CClient::IndexCallsign));
27  m_columns.addColumn(CColumn::standardString("realname", { CClient::IndexUser, CUser::IndexRealName }));
29  CColumn("vo.", "voice capabilities", CClient::IndexVoiceCapabilitiesIcon, new CPixmapFormatter()));
30  m_columns.addColumn(CColumn::standardString("capabilities", CClient::IndexCapabilitiesString));
31  m_columns.addColumn(CColumn::standardString("model", CClient::IndexModelString));
32  m_columns.addColumn(CColumn("q.?", "queried",
33  { CClient::IndexModelString, CAircraftModel::IndexHasQueriedModelString },
34  new CBoolIconFormatter("queried", "not queried")));
35  m_columns.addColumn(CColumn::standardString("server", CClient::IndexServer));
36 
37  // force strings for translation in resource files
38  (void)QT_TRANSLATE_NOOP("ViewClientList", "callsign");
39  (void)QT_TRANSLATE_NOOP("ViewClientList", "realname");
40  (void)QT_TRANSLATE_NOOP("ViewClientList", "userid");
41  (void)QT_TRANSLATE_NOOP("ViewClientList", "modelstring");
42  (void)QT_TRANSLATE_NOOP("ViewClientList", "server");
43  }
44 
45  QVariant CClientListModel::data(const QModelIndex &index, int role) const
46  {
47  static const CPropertyIndex ms({ CClient::IndexModelString, CAircraftModel::IndexModelString });
48  static const CPropertyIndex qf({ CClient::IndexModelString, CAircraftModel::IndexHasQueriedModelString });
49  if (role != Qt::DisplayRole && role != Qt::DecorationRole) { return CListModelBase::data(index, role); }
51  if (pi == ms && role == Qt::DisplayRole)
52  {
53  // no model string for ATC
54  const CClient client = this->at(index);
55  const bool atc = client.isAtc();
56  if (atc) { return QVariant("ATC"); }
57  }
58  else if (pi == qf && role == Qt::DecorationRole)
59  {
60  // no symbol for ATC
61  const CClient client = this->at(index);
62  const bool atc = client.isAtc();
63  if (atc) { return QVariant(); }
64  }
65  return CListModelBase::data(index, role);
66  }
67 } // namespace swift::gui::models
virtual QVariant data(const QModelIndex &index, int role) const
Single column.
Definition: columns.h:26
static CColumn standardValueObject(const QString &headerName, const swift::misc::CPropertyIndex &propertyIndex, int alignment=CDefaultFormatter::alignDefault())
Get a standard value object formatted column.
Definition: columns.cpp:46
static CColumn standardString(const QString &headerName, const swift::misc::CPropertyIndex &propertyIndex, int alignment=CDefaultFormatter::alignDefault())
Get a standard string object formatted column.
Definition: columns.cpp:57
void addColumn(const CColumn &column)
Add a column.
Definition: columns.cpp:100
virtual const ObjectType & at(const QModelIndex &index) const
Object at row position.
QVariant data(const QModelIndex &index, int role) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const final
virtual swift::misc::CPropertyIndex modelIndexToPropertyIndex(const QModelIndex &index) const
Index to property index.
Another client software.
Definition: client.h:27
bool isAtc() const
ATC client.
Definition: client.h:71
Value object encapsulating a list of voice rooms.
Definition: clientlist.h:27
Models to be used with views, mainly QTableView.
Free functions in swift::misc.