Commit 7e056c47 authored by Samikshan Bairagya's avatar Samikshan Bairagya

Use instances of newly added SkyObjItem class instead of SkyObject to create the models.

Also return the category of the clicked item in the list of sky-objects.
parent e298a492
......@@ -128,6 +128,7 @@ set(libkstarstools_SRCS
tools/WhatsInteresting/skyobjlistmodel.cpp
tools/WhatsInteresting/WIView.cpp
tools/WhatsInteresting/modelmanager.cpp
tools/WhatsInteresting/skyobjitem.cpp
tools/flagmanager.cpp
tools/moonphasetool.cpp
tools/starhopper.cpp
......
......@@ -117,15 +117,18 @@ Rectangle {
objectName: "soListObj"
anchors.fill: parent
signal soListItemClicked( string name, string category)
signal soListItemClicked( string name, string type)
clip: true
visible: false
delegate: Item {
id: soListItem
objectName: dispName
objectName: type
x: 5
height: 40
Text {
id: dispText
objectName: dispName
text: dispName
color: "#ffffff"
anchors.verticalCenter: parent.verticalCenter
......@@ -134,7 +137,7 @@ Rectangle {
anchors.fill: parent
onClicked: {
soListView.currentIndex = index
soListView.catListItemClicked(soListView.currentItem.objectName)
soListView.soListItemClicked( dispText.objectName, soListItem.objectName)
}
}
}
......
......@@ -36,7 +36,8 @@ WIView::WIView ( QObject *parent) : QObject(parent)
catListObj = baseObj->findChild<QObject *>("listContainer")->findChild<QObject *>("catListObj");
connect(catListObj, SIGNAL(catListItemClicked(QString)), this, SLOT(onCatListItemClicked(QString)));
soListObj = baseObj->findChild<QObject *>("listContainer")->findChild<QObject *>("soListObj");
//connect(soListObj, SIGNAL(soListItemClicked()));
connect(soListObj, SIGNAL(soListItemClicked(QString, QString)),
this, SLOT(onSoListItemClicked(QString, QString)));
// planetaryListView->setSource(QUrl::fromLocalFile("WIPlanetaryListView.qml"));
......@@ -108,3 +109,9 @@ void WIView::onCatListItemClicked(QString category)
soListObj->setProperty("visible", true);
}
}
void WIView::onSoListItemClicked(QString name, QString type)
{
kDebug()<<"Working"<<name<<type;
}
......@@ -37,6 +37,7 @@ public slots:
// void loadModel ( int TYPE );
// void skyObjectItemClicked(QModelIndex index);
void onCatListItemClicked(QString);
void onSoListItemClicked(QString name, QString type);
private:
QObject *baseObj, *catListObj, *soListObj;
QDeclarativeContext *ctxt;
......
......@@ -20,6 +20,7 @@
#include "kstarsdata.h"
#include "skymapcomposite.h"
#include "skyobject.h"
#include "skyobjectitem.h"
ModelManager::ModelManager()
{
......@@ -95,31 +96,31 @@ void ModelManager::updateModels()
foreach(SkyObject *so, initobjects.value(SkyObject::STAR))
{
//kDebug()<<so->name()<<so->mag();
starsModel->addSkyObject(so);
starsModel->addSkyObject(new SkyObjItem(so->name(), so->typeName()));
}
foreach(SkyObject *so, initobjects.value(SkyObject::GALAXY))
{
//kDebug()<<so->name()<<so->mag();
galModel->addSkyObject(so);
galModel->addSkyObject(new SkyObjItem(so->name(), so->typeName()));
}
foreach(SkyObject *so, initobjects.value(SkyObject::CONSTELLATION))
{
//kDebug()<<so->name()<<so->mag();
conModel->addSkyObject(so);
conModel->addSkyObject(new SkyObjItem(so->name(), so->typeName()));
}
foreach(SkyObject *so, initobjects.value(SkyObject::OPEN_CLUSTER))
{
//kDebug()<<so->name()<<so->mag();
starClustModel->addSkyObject(so);
starClustModel->addSkyObject(new SkyObjItem(so->name(), so->typeName()));
}
foreach(SkyObject *so, initobjects.value(SkyObject::PLANETARY_NEBULA))
{
//kDebug()<<so->name()<<so->mag();
nebModel->addSkyObject(so);
nebModel->addSkyObject(new SkyObjItem(so->name(), so->typeName()));
}
foreach ( const QString &name, data->skyComposite()->objectNames( SkyObject::PLANET ) )
......@@ -130,7 +131,7 @@ void ModelManager::updateModels()
{
// SkyObjectItem *planetItem = new SkyObjectItem(o);
// planetItem->setText(o->name());
planetsModel->addSkyObject(so);
planetsModel->addSkyObject(new SkyObjItem(so->name(), so->typeName()));
}
}
//
......
/***************************************************************************
skyobjitem.cpp - K Desktop Planetarium
-------------------
begin : 2012/21/06
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 "skyobjitem.h"
SkyObjItem::SkyObjItem(QString soname, QString sotype, QObject* parent) : QObject(parent)
{
name = soname;
type = sotype;
}
QVariant SkyObjItem::data(int role)
{
switch(role)
{
case DispNameRole:
return getName();
case CategoryRole:
return getType();
default:
return QVariant();
}
}
QHash< int, QByteArray > SkyObjItem::roleNames() const
{
QHash<int, QByteArray > roles;
roles[DispNameRole]="dispName";
roles[CategoryRole] = "type";
return roles;
}
\ No newline at end of file
/***************************************************************************
skyobjitem.h - K Desktop Planetarium
-------------------
begin : 2012/21/06
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. *
* *
***************************************************************************/
#ifndef SKYOBJITEM_H
#define SKYOBJITEM_H
#include <QObject>
#include "skyobject.h"
class SkyObjItem : public QObject
{
Q_OBJECT
public:
enum SkyObjectRoles {DispNameRole = Qt::UserRole + 1 , CategoryRole };
explicit SkyObjItem(QString soname = QString(), QString sotype = QString(), QObject *parent = 0);
QVariant data(int role);
QHash<int, QByteArray> roleNames() const;
inline QString getName() { return name; }
inline QString getType() { return type; }
private:
QString name;
QString type;
};
#endif // SKYOBJITEM_H
......@@ -18,24 +18,21 @@
#include "skyobjlistmodel.h"
//#include "skyobjectitem.h"
SkyObjListModel::SkyObjListModel(QObject* parent): QAbstractListModel(parent)
SkyObjListModel::SkyObjListModel(SkyObjItem* soitem, QObject* parent): QAbstractListModel(parent)
{
QHash<int, QByteArray> roles;
roles[DispNameRole] = "dispName";
roles[CategoryRole] = "category";
setRoleNames(roles);
setRoleNames(soitem->roleNames());
}
void SkyObjListModel::addSkyObject(SkyObject* sobj)
void SkyObjListModel::addSkyObject(SkyObjItem* sobj)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
skyObjList.append(sobj);
soItemList.append(sobj);
endInsertRows();
}
int SkyObjListModel::rowCount(const QModelIndex& parent) const
{
return skyObjList.size();
return soItemList.size();
}
QVariant SkyObjListModel::data(const QModelIndex& index, int role) const
......@@ -43,16 +40,17 @@ QVariant SkyObjListModel::data(const QModelIndex& index, int role) const
if (index.row() < 0 || index.row() > rowCount())
return QVariant();
SkyObject *so = skyObjList[index.row()];
if (role == DispNameRole)
return so->name();
SkyObjItem *soitem = soItemList[index.row()];
/*if (role == DispNameRole)
return soitem->name();
else if (role == CategoryRole)
return so->type();
return QVariant();
return soitem->type();*/
//return QVariant();
return soitem->data(role);
}
QList< SkyObject* > SkyObjListModel::getSkyObjects()
QList< SkyObjItem* > SkyObjListModel::getSkyObjItems()
{
return skyObjList;
return soItemList;
}
......@@ -20,20 +20,21 @@
#include "qabstractitemmodel.h"
#include "skyobject.h"
#include "skyobjitem.h"
class SkyObjListModel : public QAbstractListModel
{
Q_OBJECT
public:
enum SkyObjectRoles {DispNameRole = Qt::UserRole + 1 , CategoryRole };
explicit SkyObjListModel(QObject* parent = 0);
void addSkyObject(SkyObject *sobj);
//enum SkyObjectRoles {DispNameRole = Qt::UserRole + 1 , CategoryRole };
explicit SkyObjListModel(SkyObjItem* soitem = 0, QObject* parent = 0);
void addSkyObject(SkyObjItem *sobj);
int rowCount( const QModelIndex& parent = QModelIndex()) const;
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole) const;
QList<SkyObject *> getSkyObjects();
QList<SkyObjItem *> getSkyObjItems();
private:
QList<SkyObject *> skyObjList;
QList<SkyObjItem *> soItemList;
};
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment