skyobjlistmodel.cpp 2.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/***************************************************************************
                          skyobjlistmodel.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : 2012/26/05
    copyright            : (C) 2012 by Samikshan Bairagya
    email                : samikshan@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "skyobjlistmodel.h"

20
SkyObjListModel::SkyObjListModel(SkyObjItem * soitem, QObject * parent): QAbstractListModel(parent)
21
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
22
    //FIXME Needs porting to KF5
23
    //Fixed in roleNames(). setRoleNames is not a member of QAbstractListModel anymore
Jasem Mutlaq's avatar
Jasem Mutlaq committed
24
    //setRoleNames(soitem->roleNames());
Marcos CARDINOT's avatar
Marcos CARDINOT committed
25
    Q_UNUSED(soitem);
26 27
}

28 29 30 31
QHash<int, QByteArray> SkyObjListModel::roleNames() const
{
    QHash<int, QByteArray> roles;
    roles[SkyObjItem::DispNameRole] = "dispName";
32 33
    roles[SkyObjItem::DispImageRole] = "imageSource";
    roles[SkyObjItem::DispSummaryRole] = "dispObjSummary";
34 35 36 37 38
    roles[SkyObjItem::CategoryRole] = "type";
    roles[SkyObjItem::CategoryNameRole] = "typeName";
    return roles;
}

39
void SkyObjListModel::addSkyObject(SkyObjItem * soitem)
40 41
{
    beginInsertRows(QModelIndex(), rowCount(), rowCount());
42
    m_SoItemList.append(soitem);
43 44 45
    endInsertRows();
}

46
int SkyObjListModel::rowCount(const QModelIndex &parent) const
47
{
Rafal Kulaga's avatar
Rafal Kulaga committed
48 49
    Q_UNUSED(parent)

50
    return m_SoItemList.size();
51 52
}

53
QVariant SkyObjListModel::data(const QModelIndex &index, int role) const
54 55 56 57
{
    if (index.row() < 0 || index.row() > rowCount())
        return QVariant();

58
    SkyObjItem * soitem = m_SoItemList[index.row()];
59

60
    return soitem->data(role);
61 62
}

63
QList< SkyObjItem *> SkyObjListModel::getSkyObjItems()
64
{
65
    return m_SoItemList;
66 67
}

68
SkyObjItem * SkyObjListModel::getSkyObjItem(int index)
69
{
70
    return m_SoItemList[index];
71
}
72 73 74

void SkyObjListModel::resetModel()
{
75
    m_SoItemList.clear();
76
}