swift
listmodelcallsignobjects.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <type_traits>
7 
8 #include <QBrush>
9 #include <QModelIndex>
10 
11 #include "gui/models/allmodelcontainers.h"
12 #include "misc/orderable.h"
13 
14 using namespace swift::misc;
15 using namespace swift::misc::aviation;
16 
17 namespace swift::gui::models
18 {
19  template <typename T, bool UseCompare>
21  QObject *parent)
22  : CListModelBase<ContainerType, UseCompare>(translationContext, parent)
23  {}
24 
25  template <typename T, bool UseCompare>
26  QVariant CListModelCallsignObjects<T, UseCompare>::data(const QModelIndex &index, int role) const
27  {
28  if (role != Qt::BackgroundRole) { return CListModelBase<ContainerType, UseCompare>::data(index, role); }
29  if (isHighlightedIndex(index)) { return QBrush(m_highlightColor); }
31  }
32 
33  template <typename T, bool UseCompare>
36  {
37  if (!index.isValid()) { return CCallsign(); }
38  return this->at(index).getCallsign();
39  }
40 
41  template <typename T, bool UseCompare>
43  {
44  if (!index.isValid()) { return false; }
45  if (m_highlightCallsigns.isEmpty()) { return false; }
46  return m_highlightCallsigns.contains(callsignForIndex(index));
47  }
48 
49  // see here for the reason of thess forward instantiations
50  // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl
54 } // namespace swift::gui::models
QVariant data(const QModelIndex &index, int role) const
List model for callsign based objects (callsign is unique key)
virtual QVariant data(const QModelIndex &index, int role) const
Get data for index and role.
bool isHighlightedIndex(const QModelIndex &index) const
Highlight index?
swift::misc::aviation::CCallsign callsignForIndex(const QModelIndex &index) const
Callsign for given index.
Value object encapsulating information of a callsign.
Definition: callsign.h:30
Models to be used with views, mainly QTableView.
Free functions in swift::misc.