Kstars

skyobjlistmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
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());
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
37
38int SkyObjListModel::rowCount(const QModelIndex &parent) const
39{
41
42 return m_SoItemList.size();
43}
44
45QVariant 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
68int 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}
Represents an item in the list of interesting sky-objects.
Definition skyobjitem.h:21
QString getName() const
Get name of sky-object associated with the SkyObjItem.
Definition skyobjitem.h:69
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Overridden method from QAbstractItemModel.
SkyObjItem * getSkyObjItem(int index)
Get sky-object item referred to by index.
QHash< int, QByteArray > roleNames() const override
Create and return a QHash<int, QByteArray> of rolenames for the SkyObjItem.
void resetModel()
Erase all data in model.
SkyObjListModel(SkyObjItem *soitem=nullptr, QObject *parent=nullptr)
Constructor.
QList< SkyObjItem * > getSkyObjItems()
Get the list of sky-object items in the model.
void addSkyObject(SkyObjItem *sobj)
Add a sky-object to the model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Overridden method from QAbstractItemModel.
void beginInsertRows(const QModelIndex &parent, int first, int last)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void append(QList< T > &&value)
void clear()
qsizetype size() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:01:01 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.