Kstars

catalogobjectlistmodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Valentin Boettcher <hiro at protagon.space; @hiro98:tchncs.de>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "catalogobjectlistmodel.h"
8 
9 CatalogObjectListModel::CatalogObjectListModel(QObject *parent,
10  std::vector<CatalogObject> objects)
11  : QAbstractTableModel{ parent }, m_objects{ std::move(objects) } {};
12 
13 QVariant CatalogObjectListModel::data(const QModelIndex &index, int role) const
14 {
15  if (role != Qt::DisplayRole)
16  return QVariant();
17 
18  const auto &obj = m_objects.at(index.row());
19 
20  switch (index.column())
21  {
22  case 0:
23  return obj.typeName();
24  case 1:
25  return obj.ra().toHMSString();
26  case 2:
27  return obj.dec().toDMSString();
28  case 3:
29  return obj.mag();
30  case 4:
31  return obj.name();
32  case 5:
33  return obj.longname();
34  case 6:
35  return obj.catalogIdentifier();
36  case 7:
37  return obj.a();
38  case 8:
39  return obj.b();
40  case 9:
41  return obj.pa();
42  case 10:
43  return obj.flux();
44  default:
45  return "";
46  }
47 };
48 
49 void CatalogObjectListModel::setObjects(std::vector<CatalogObject> objects)
50 {
51  beginResetModel();
52  m_objects = std::move(objects);
53  emit endResetModel();
54 }
55 
56 QVariant CatalogObjectListModel::headerData(int section, Qt::Orientation orientation,
57  int role) const
58 {
59  if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
60  return QVariant();
61 
62  switch (section)
63  {
64  case 0:
65  return i18n("Type");
66  case 1:
67  return i18n("RA");
68  case 2:
69  return i18n("Dec");
70  case 3:
71  return i18n("Mag");
72  case 4:
73  return i18n("Name");
74  case 5:
75  return i18n("Long Name");
76  case 6:
77  return i18n("Identifier");
78  case 7:
79  return i18n("Major Axis");
80  case 8:
81  return i18n("Minor Axis");
82  case 9:
83  return i18n("Position Angle");
84  case 10:
85  return i18n("Flux");
86  default:
87  return "";
88  }
89 };
Qt::Orientation orientation() const const
DisplayRole
int column() const const
QString i18n(const char *text, const TYPE &arg...)
Orientation
int row() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.