File: IARURegions.cpp

package info (click to toggle)
js8call 2.2.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,416 kB
  • sloc: cpp: 563,285; f90: 9,265; ansic: 937; python: 132; sh: 93; makefile: 6
file content (100 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "IARURegions.hpp"

#include <algorithm>

#include <QString>
#include <QVariant>
#include <QModelIndex>
#include <QMetaType>

#include "moc_IARURegions.cpp"

namespace
{
  // human readable strings for each Region enumeration value
  char const * const region_names[] =
  {
    "All",
    "Region 1",
    "Region 2",
    "Region 3",
  };
  std::size_t constexpr region_names_size = sizeof (region_names) / sizeof (region_names[0]);
}

IARURegions::IARURegions (QObject * parent)
  : QAbstractListModel {parent}
{
  static_assert (region_names_size == SENTINAL,
                 "region_names array must match Region enumeration");
}

char const * IARURegions::name (Region r)
{
  return region_names[static_cast<int> (r)];
}

auto IARURegions::value (QString const& s) -> Region
{
  auto end = region_names + region_names_size;
  auto p = std::find_if (region_names, end
                         , [&s] (char const * const name) {
                           return name == s;
                         });
  return p != end ? static_cast<Region> (p - region_names) : ALL;
}

QVariant IARURegions::data (QModelIndex const& index, int role) const
{
  QVariant item;

  if (index.isValid ())
    {
      auto const& row = index.row ();
      switch (role)
        {
        case Qt::ToolTipRole:
        case Qt::AccessibleDescriptionRole:
          item = tr ("IARU Region");
          break;

        case Qt::EditRole:
          item = static_cast<Region> (row);
          break;

        case Qt::DisplayRole:
        case Qt::AccessibleTextRole:
          item = region_names[row];
          break;

        case Qt::TextAlignmentRole:
          item = Qt::AlignHCenter + Qt::AlignVCenter;
          break;
        }
    }

  return item;
}

QVariant IARURegions::headerData (int section, Qt::Orientation orientation, int role) const
{
  QVariant result;

  if (Qt::DisplayRole == role && Qt::Horizontal == orientation)
    {
      result = tr ("IARU Region");
    }
  else
    {
      result = QAbstractListModel::headerData (section, orientation, role);
    }

  return result;
}

#if !defined (QT_NO_DEBUG_STREAM)
ENUM_QDEBUG_OPS_IMPL (IARURegions, Region);
#endif

ENUM_QDATASTREAM_OPS_IMPL (IARURegions, Region);
ENUM_CONVERSION_OPS_IMPL (IARURegions, Region);