Kstars

skyobjlistmodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Samikshan Bairagya <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "skyobjlistmodel.h"
8 
9 #include "skyobject.h"
10 #include "skyobjitem.h"
11 
13 {
14  //FIXME Needs porting to KF5
15  //Fixed in roleNames(). setRoleNames is not a member of QAbstractListModel anymore
16  //setRoleNames(soitem->roleNames());
17  Q_UNUSED(soitem);
18 }
19 
21 {
23  roles[SkyObjItem::DispNameRole] = "dispName";
24  roles[SkyObjItem::DispImageRole] = "imageSource";
25  roles[SkyObjItem::DispSummaryRole] = "dispObjSummary";
26  roles[SkyObjItem::CategoryRole] = "type";
27  roles[SkyObjItem::CategoryNameRole] = "typeName";
28  return roles;
29 }
30 
32 {
34  m_SoItemList.append(soitem);
35  endInsertRows();
36 }
37 
38 int SkyObjListModel::rowCount(const QModelIndex &parent) const
39 {
40  Q_UNUSED(parent)
41 
42  return m_SoItemList.size();
43 }
44 
45 QVariant SkyObjListModel::data(const QModelIndex &index, int role) const
46 {
47  if (index.row() < 0 || index.row() > rowCount())
48  return QVariant();
49 
50  SkyObjItem *soitem = m_SoItemList[index.row()];
51 
52  return soitem->data(role);
53 }
54 
56 {
57  return m_SoItemList;
58 }
59 
61 {
62  if (m_SoItemList.size() > index)
63  return m_SoItemList[index];
64  else
65  return nullptr;
66 }
67 
68 int SkyObjListModel::getSkyObjIndex(SkyObjItem *item)
69 {
70  for (int i = 0; i < m_SoItemList.size(); i++)
71  {
72  if (item->getName() == m_SoItemList[i]->getName())
73  return i;
74  }
75  return -1;
76 }
77 
79 {
80  m_SoItemList.clear();
81 }
void append(const T &value)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Overridden method from QAbstractItemModel.
void resetModel()
Erase all data in model.
QHash< int, QByteArray > roleNames() const override
Create and return a QHash<int, QByteArray> of rolenames for the SkyObjItem.
void beginInsertRows(const QModelIndex &parent, int first, int last)
SkyObjItem * getSkyObjItem(int index)
Get sky-object item referred to by index.
int size() const const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Overridden method from QAbstractItemModel.
int row() const const
QString getName() const
Get name of sky-object associated with the SkyObjItem.
Definition: skyobjitem.h:69
void clear()
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QList< SkyObjItem * > getSkyObjItems()
Get the list of sky-object items in the model.
SkyObjListModel(SkyObjItem *soitem=nullptr, QObject *parent=nullptr)
Constructor.
QObject * parent() const const
void addSkyObject(SkyObjItem *sobj)
Add a sky-object to the model.
QVariant data(int role)
Get data associated with a particular role for the SkyObjItem.
Definition: skyobjitem.cpp:55
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.