Commit 805df81c authored by Robert Lancaster's avatar Robert Lancaster Committed by Jasem Mutlaq

See if this improves things. I did a complete rewrite of the way the model...

See if this improves things.  I did a complete rewrite of the way the model manager works.  It is now much more efficient.  This also includes the other changes I already made as well as the additional download of comets and asteroids.  I also added the images to the qml file as you mentioned.
parent 49588f8d
......@@ -415,8 +415,8 @@ void KSWizard::slotExtractGSC()
void KSWizard::slotCheckDownloadProgress()
{
#ifdef Q_OS_OSX
if(QFileInfo(gscZipPath).exists());
data->downloadProgress->setValue(QFileInfo(gscZipPath).size()/1048576);
if(QFileInfo(gscZipPath).exists())
data->downloadProgress->setValue(QFileInfo(gscZipPath).size()/1048576);
#endif
}
......
......@@ -34,6 +34,7 @@
#include "skycomponents/skymapcomposite.h"
#include "skycomponents/flagcomponent.h"
#include "skymap.h"
#include "tools/whatsinteresting/wiview.h"
#include "observinglist.h"
......@@ -403,6 +404,8 @@ void KSPopupMenu::initPopupMenu( SkyObject * obj, QString name, QString type, QS
#endif
addSeparator();
addINDI();
addAction( i18n("View in What's Interesting"), this, SLOT( slotViewInWI() ) );
}
void KSPopupMenu::initFlagActions( SkyObject * obj )
......@@ -630,3 +633,10 @@ void KSPopupMenu::addFancyLabel(QString name, int deltaFontSize)
act->setDefaultWidget(label);
addAction( act );
}
void KSPopupMenu::slotViewInWI(){
if(!KStars::Instance()->map()->clickedObject())
return;
KStars::Instance()->slotShowWIView();
KStars::Instance()->wiView()->inspectSkyObject(KStars::Instance()->map()->clickedObject());
}
......@@ -125,6 +125,7 @@ class KSPopupMenu : public QMenu
void slotDeleteFlag();
void slotEditFlag( QAction * action );
void slotDeleteFlag( QAction * action );
void slotViewInWI();
private:
/** Initialize the popup menus. Adds name and type labels, and possibly
......
......@@ -21,6 +21,7 @@
#include <kxmlguiwindow.h>
#include <config-kstars.h>
#include <QDockWidget>
#include "oal/equipmentwriter.h"
#include "oal/observeradd.h"
......@@ -195,6 +196,8 @@ class KStars : public KXmlGuiWindow
void showWI(ObsConditions * obs);
WIEquipSettings * getWIEquipSettings() { return m_WIEquipmentSettings; }
public Q_SLOTS:
/** @defgroup DBusInterface DBus Interface
KStars provides powerful scripting functionality via DBus. The most common DBus functions can be constructed and executed within the ScriptBuilder tool.
......@@ -497,6 +500,28 @@ class KStars : public KXmlGuiWindow
void slotWizard();
void updateLocationFromWizard(GeoLocation geo);
WIView * wiView(){
return m_WIView;
}
bool isWIVisible(){
if(!m_WIView)
return false;
if(!m_wiDock)
return false;
return m_wiDock->isVisible();
}
//FIXME Port to QML2
//#if 0
/** action slot: open What's Interesting settings window */
void slotWISettings();
/** action slot: open What's Interesting window */
void slotShowWIView();
//#endif
private slots:
/** action slot: open a dialog for setting the time and date */
void slotSetTime();
......@@ -525,15 +550,6 @@ class KStars : public KXmlGuiWindow
/** action slot: open What's up tonight dialog */
void slotWUT();
//FIXME Port to QML2
//#if 0
/** action slot: open What's Interesting settings window */
void slotWISettings();
/** action slot: open What's Interesting window */
void slotShowWIView(int status);
//#endif
/** action slot: open Sky Calendar tool */
void slotCalendar();
......
......@@ -509,11 +509,10 @@ void KStars::slotWUT()
void KStars::slotWISettings()
{
#ifdef HAVE_KF5WIT
if (!m_WIView)
slotShowWIView();
if (m_WIView && !m_wiDock->isVisible())
{
slotShowWIView(1);
return;
}
slotShowWIView();
if (KConfigDialog::showDialog("wisettings"))
{
......@@ -524,52 +523,25 @@ void KStars::slotWISettings()
KConfigDialog * dialog = new KConfigDialog(this, "wisettings", Options::self());
connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SLOT(slotApplyWIConfigChanges()));
connect(dialog, SIGNAL(finished(int)), this, SLOT(slotShowWIView(int)));
m_WISettings = new WILPSettings(this);
m_WIEquipmentSettings = new WIEquipSettings();
dialog->addPage(m_WISettings, i18n("Light Pollution Settings"));
dialog->addPage(m_WIEquipmentSettings, i18n("Equipment Settings - Equipment Type and Parameters"));
dialog->show();
dialog->exec();
if(m_WIEquipmentSettings)
m_WIEquipmentSettings->setAperture(); //Something isn't working with this!
#endif
}
void KStars::slotShowWIView(int status)
void KStars::slotShowWIView()
{
#ifdef HAVE_KF5WIT
if (status == 0) return; //Cancelled
int bortle = Options::bortleClass();
m_WIEquipmentSettings->setAperture();
/* NOTE This part of the code dealing with equipment type is presently not required
* as WI does not differentiate between Telescope and Binoculars. It only needs the
* aperture of the equipment whichever available. However this is kept as a part of
* the code as support to be utilised in the future.
*/
ObsConditions::Equipment equip = ObsConditions::None;
if (Options::telescopeCheck() && Options::binocularsCheck())
equip = ObsConditions::Both;
else if (Options::telescopeCheck())
equip = ObsConditions::Telescope;
else if (Options::binocularsCheck())
equip = ObsConditions::Binoculars;
ObsConditions::TelescopeType telType = (equip == ObsConditions::Telescope) ? m_WIEquipmentSettings->getTelType() : ObsConditions::Invalid;
int aperture = m_WIEquipmentSettings->getAperture();
//Update observing conditions for What's Interesting
if (!m_ObsConditions)
m_ObsConditions = new ObsConditions(bortle, aperture, equip, telType);
else
m_ObsConditions->setObsConditions(bortle, aperture, equip, telType);
if (!m_WIView)
{
m_WIView = new WIView(0, m_ObsConditions);
m_WIView = new WIView(0);
m_wiDock = new QDockWidget(this);
m_wiDock->setObjectName("What's Interesting");
m_wiDock->setAllowedAreas(Qt::RightDockWidgetArea);
......@@ -581,10 +553,8 @@ void KStars::slotShowWIView(int status)
}
else
{
m_WIView->updateModels(m_ObsConditions);
m_wiDock->setVisible(true);
}
#endif
}
......@@ -902,6 +872,8 @@ void KStars::slotApplyWIConfigChanges()
{
Options::self()->save();
applyConfig();
m_WIView->updateObservingConditions();
m_WIView->onReloadIconClicked();
}
void KStars::slotSetTime()
......
......@@ -438,7 +438,7 @@ void KStars::initActions()
//FIXME Port to QML2
//#if 0
actionCollection()->addAction("whats_interesting", this, SLOT( slotWISettings() ) )
actionCollection()->addAction("whats_interesting", this, SLOT( slotShowWIView() ) )
<< i18n("What's Interesting...")
<< QKeySequence(Qt::CTRL+Qt::Key_W );
//#endif
......
......@@ -551,6 +551,9 @@ class SkyMap : public QGraphicsView
/** Emitted when a position is clicked */
void positionClicked(SkyPoint *);
/** Emitted when a position is clicked */
void objectClicked(SkyObject *);
protected:
/** Process keystrokes:
* @li arrow keys Slew the map
......
......@@ -653,9 +653,10 @@ void SkyMap::mousePressEvent( QMouseEvent * e )
case Qt::LeftButton:
{
QString name;
if( clickedObject() )
if( clickedObject() ){
name = clickedObject()->translatedLongName();
else
emit objectClicked(clickedObject());
}else
name = i18n( "Empty sky" );
//kstars->statusBar()->changeItem(name, 0 );
kstars->statusBar()->showMessage(name, 0 );
......
......@@ -20,48 +20,56 @@
#include "kstarsdatetime.h"
#include "skymapcomposite.h"
#include "skyobject.h"
#include <QtConcurrent>
ModelManager::ModelManager(ObsConditions * obs)
{
m_ObsConditions = obs;
m_PlanetsModel = new SkyObjListModel();
m_StarsModel = new SkyObjListModel();
m_GalModel = new SkyObjListModel();
m_ConModel = new SkyObjListModel();
m_ClustModel = new SkyObjListModel();
m_NebModel = new SkyObjListModel();
m_MessierModel = new SkyObjListModel();
m_SharplessModel = new SkyObjListModel();
m_InitObjects[Star_Model] = QList<SkyObject *>();
m_InitObjects[Galaxy_Model] = QList<SkyObject *>();
m_InitObjects[Constellation_Model] = QList<SkyObject *>();
m_InitObjects[Cluster_Model] = QList<SkyObject *>();
m_InitObjects[Nebula_Model] = QList<SkyObject *>();
m_InitObjects[Messier_Model] = QList<SkyObject *>();
m_InitObjects[Sharpless_Model] = QList<SkyObject *>();
updateModels(obs);
m_ModelList = QList < SkyObjListModel *>();
m_ObjectList = QList< QList <SkyObjItem *> >();
favoriteClusters = QList <SkyObjItem *>();
favoriteNebulas = QList <SkyObjItem *>();
favoriteGalaxies = QList <SkyObjItem *>();
for(int i=0;i<NumberOfLists;i++){
m_ModelList.append(new SkyObjListModel());
m_ObjectList.append(QList<SkyObjItem *>());
}
QtConcurrent::run(this, &ModelManager::loadLists);
}
ModelManager::~ModelManager()
{
delete m_PlanetsModel;
delete m_StarsModel;
delete m_GalModel;
delete m_ConModel;
delete m_ClustModel;
delete m_NebModel;
delete m_MessierModel;
delete m_SharplessModel;
qDeleteAll(m_ModelList);
foreach(QList<SkyObjItem *> list, m_ObjectList)
qDeleteAll(list);
}
void ModelManager::updateModels(ObsConditions * obs)
void ModelManager::loadLists()
{
m_ObsConditions = obs;
m_InitObjects.clear();
resetModels();
KStarsData * data = KStarsData::Instance();
QVector<QPair<QString, const SkyObject *>> listStars;
listStars.append(data->skyComposite()->objectLists(SkyObject::STAR));
for(int i = 0; i < listStars.size(); i++)
{
QPair<QString, const SkyObject *> pair = listStars.value(i);
const StarObject * star = dynamic_cast<const StarObject *>(pair.second);
if(star->hasLatinName())
m_ObjectList[Stars].append(new SkyObjItem(star->clone()));
}
QString prevName;
for(int i = 0; i < m_ObjectList[Stars].size(); i++)
{
SkyObjItem *star=m_ObjectList[Stars].at(i);
if(prevName==star->getName()){
m_ObjectList[Stars].removeAt(i);
i--;
}
prevName = star->getName();
}
KSFileReader fileReader;
if (!fileReader.open("Interesting.dat")) return;
......@@ -82,128 +90,140 @@ void ModelManager::updateModels(ObsConditions * obs)
case SkyObject::OPEN_CLUSTER:
case SkyObject::GLOBULAR_CLUSTER:
case SkyObject::GALAXY_CLUSTER:
m_InitObjects[Cluster_Model].append(o);
favoriteClusters.append(new SkyObjItem(o));
break;
case SkyObject::PLANETARY_NEBULA:
case SkyObject::DARK_NEBULA:
case SkyObject::GASEOUS_NEBULA:
m_InitObjects[Nebula_Model].append(o);
break;
case SkyObject::STAR:
m_InitObjects[Star_Model].append(o);
break;
case SkyObject::CONSTELLATION:
m_InitObjects[Constellation_Model].append(o);
favoriteNebulas.append(new SkyObjItem(o));
break;
case SkyObject::GALAXY:
m_InitObjects[Galaxy_Model].append(o);
favoriteGalaxies.append(new SkyObjItem(o));
break;
}
}
}
foreach (SkyObject * so, m_InitObjects.value(Star_Model))
{
//qDebug()<<so->longname()<<so->typeName();
if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
{
m_StarsModel->addSkyObject(new SkyObjItem(so));
}
}
loadObjectList(m_ObjectList[Asteroids], SkyObject::ASTEROID);
loadObjectList(m_ObjectList[Comets], SkyObject::COMET);
loadObjectList(m_ObjectList[Satellites], SkyObject::SATELLITE);
loadObjectList(m_ObjectList[Constellations], SkyObject::CONSTELLATION);
loadObjectList(m_ObjectList[Planets], SkyObject::PLANET);
loadObjectList(m_ObjectList[Galaxies], SkyObject::GALAXY);
loadObjectList(m_ObjectList[Clusters], SkyObject::OPEN_CLUSTER);
loadObjectList(m_ObjectList[Clusters], SkyObject::GLOBULAR_CLUSTER);
loadObjectList(m_ObjectList[Clusters], SkyObject::GALAXY_CLUSTER);
loadObjectList(m_ObjectList[Nebulas], SkyObject::PLANETARY_NEBULA);
loadObjectList(m_ObjectList[Nebulas], SkyObject::GASEOUS_NEBULA);
loadObjectList(m_ObjectList[Nebulas], SkyObject::DARK_NEBULA);
foreach (SkyObject * so, m_InitObjects.value(Galaxy_Model))
for(int i=1;i<=110;i++)
{
//qDebug()<<so->longname()<<so->typeName();
if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
{
m_GalModel->addSkyObject(new SkyObjItem(so));
}
SkyObject * o;
if ((o = data->skyComposite()->findByName("M " + QString::number(i))))
m_ObjectList[Messier].append(new SkyObjItem(o));
}
foreach (SkyObject * so, m_InitObjects.value(Constellation_Model))
/**
Note: The sharpless catalog did not have good wikipedia articles
for(int i=1;i<=350;i++)
{
if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
{
m_ConModel->addSkyObject(new SkyObjItem(so));
}
SkyObject * o;
if ((o = data->skyComposite()->findByName("Sh2 " + QString::number(i))))
m_SharplessModel->addSkyObject(new SkyObjItem(o));
}
**/
}
foreach (SkyObject * so, m_InitObjects.value(Cluster_Model))
{
if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
{
m_ClustModel->addSkyObject(new SkyObjItem(so));
}
void ModelManager::updateAllModels(ObsConditions * obs)
{
m_ObsConditions = obs;
resetAllModels();
for(int i=0;i<NumberOfLists;i++)
loadObjectsIntoModel(*m_ModelList[i], m_ObjectList[i]);
}
void ModelManager::updateModel(ObsConditions * obs, QString modelName){
m_ObsConditions = obs;
SkyObjListModel * model = returnModel(modelName);
if(model){
model->resetModel();
if(showOnlyFavorites && modelName=="galaxies")
loadObjectsIntoModel(*m_ModelList[getModelNumber(modelName)], favoriteGalaxies);
else if(showOnlyFavorites && modelName=="nebulas")
loadObjectsIntoModel(*m_ModelList[getModelNumber(modelName)], favoriteNebulas);
else if(showOnlyFavorites && modelName=="clusters")
loadObjectsIntoModel(*m_ModelList[getModelNumber(modelName)], favoriteClusters);
else
loadObjectsIntoModel(*m_ModelList[getModelNumber(modelName)], m_ObjectList[getModelNumber(modelName)]);
}
}
void ModelManager::loadObjectList(QList<SkyObjItem *> & skyObjectList, int type){
KStarsData * data = KStarsData::Instance();
QVector<QPair<QString, const SkyObject *>> objects = data->skyComposite()->objectLists( type );
foreach (SkyObject * so, m_InitObjects.value(Nebula_Model))
for(int i = 0; i < objects.size(); i++)
{
if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
{
m_NebModel->addSkyObject(new SkyObjItem(so));
}
QPair<QString, const SkyObject *> pair = objects.value(i);
const SkyObject * listObject = dynamic_cast<const SkyObject *>(pair.second);
if(listObject->name() != "Sun")
skyObjectList.append(new SkyObjItem(listObject->clone()));
}
}
foreach (const QString &name, data->skyComposite()->objectNames(SkyObject::PLANET))
void ModelManager::loadObjectsIntoModel(SkyObjListModel & model, QList<SkyObjItem *> &skyObjectList){
KStarsData * data = KStarsData::Instance();
foreach (SkyObjItem * soitem, skyObjectList)
{
SkyObject * so = data->skyComposite()->findByName(name);
//qDebug()<<so->name()<<so->mag();
if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
{
if (so->name() == "Sun") continue;
m_PlanetsModel->addSkyObject(new SkyObjItem(so));
}
bool isVisible = (showOnlyVisible) ? (m_ObsConditions->isVisible(data->geo(), data->lst(), soitem->getSkyObject())) : true;
if(isVisible)
model.addSkyObject(soitem);
}
for(int i=1;i<=110;i++)
{
SkyObject * o;
if ((o = data->skyComposite()->findByName("M " + QString::number(i))))
m_MessierModel->addSkyObject(new SkyObjItem(o));
}
/**
for(int i=1;i<=350;i++)
{
SkyObject * o;
if ((o = data->skyComposite()->findByName("Sh2 " + QString::number(i))))
m_SharplessModel->addSkyObject(new SkyObjItem(o));
}
**/
}
void ModelManager::resetModels()
void ModelManager::resetAllModels()
{
m_PlanetsModel->resetModel();
m_StarsModel->resetModel();
m_ConModel->resetModel();
m_GalModel->resetModel();
m_ClustModel->resetModel();
m_NebModel->resetModel();
m_MessierModel->resetModel();
m_SharplessModel->resetModel();
foreach(SkyObjListModel * model, m_ModelList)
model->resetModel();
}
SkyObjListModel * ModelManager::returnModel(int type)
int ModelManager::getModelNumber(QString modelName){
if(modelName=="planets")
return Planets;
if(modelName=="stars")
return Stars;
if(modelName=="constellations")
return Constellations;
if(modelName=="galaxies")
return Galaxies;
if(modelName=="clusters")
return Clusters;
if(modelName=="nebulas")
return Nebulas;
if(modelName=="asteroids")
return Asteroids;
if(modelName=="comets")
return Comets;
if(modelName=="satellites")
return Satellites;
if(modelName=="messier")
return Messier;
if(modelName=="sharpless")
return Sharpless;
else return -1;
}
SkyObjListModel * ModelManager::returnModel(QString modelName)
{
switch(type)
{
case 0: //Planet type
return m_PlanetsModel;
case 1: //Star type
return m_StarsModel;
case 2: //Constellation type
return m_ConModel;
case 3: //Galaxy Type
return m_GalModel;
case 4: //Cluster type
return m_ClustModel;
case 5: //Nebula type
return m_NebModel;
case 6: //Messier Objects
return m_MessierModel;
case 7: //Sharpless Objects
return m_SharplessModel;
default:
return 0;
}
int modelNumber = getModelNumber(modelName);
if(modelNumber > -1 && modelNumber < NumberOfLists)
return m_ModelList[modelNumber];
else
return new SkyObjListModel();
}
......@@ -21,6 +21,7 @@
#include "skyobjlistmodel.h"
#include "kstarsdata.h"
#include "obsconditions.h"
#include "starobject.h"
/**
* \class ModelManager
......@@ -34,7 +35,7 @@ class ModelManager
* \enum ModelType
* \brief Model type for different types of sky-objects.
*/
enum ModelType {Planet_Model, Star_Model, Constellation_Model, Galaxy_Model, Cluster_Model, Nebula_Model, Messier_Model, Sharpless_Model};
enum ObjectList {Planets, Stars, Constellations, Galaxies, Clusters, Nebulas, Satellites, Asteroids, Comets, Messier, Sharpless, NumberOfLists};
/**
* \brief Constructor - Creates models for different sky-object types.
......@@ -50,24 +51,55 @@ class ModelManager
/**
* \brief Updates sky-object list models.
*/
void updateModels(ObsConditions * obs);
void updateAllModels(ObsConditions *obs);
void updateModel(ObsConditions * obs, QString modelName);
/**
* \brief Clears all sky-objects list models.
*/
void resetModels();
void resetAllModels();
void setShowOnlyVisibleObjects(bool show){
showOnlyVisible=show;
}
bool showOnlyVisibleObjects(){
return showOnlyVisible;
}
void setShowOnlyFavoriteObjects(bool show){
showOnlyFavorites=show;
}
bool showOnlyFavoriteObjects(){
return showOnlyFavorites;
}
/**
* \brief Returns model of given type.
* \return Pointer to SkyObjListModel of given type.
* \param type Type of sky-object model to be returned.
*/
SkyObjListModel * returnModel(int type);
SkyObjListModel * returnModel(QString modelName);
int getModelNumber(QString modelName);
private:
ObsConditions * m_ObsConditions;
SkyObjListModel * m_PlanetsModel,