Commit eecc521f authored by Artem Fedoskin's avatar Artem Fedoskin
Browse files

Added search to KStars Lite. In KStars Lite we don't need to call

findObject() after user selects object on "Find Object" page because
each object's name is associated with corresponding SkyObject and we
slew directly to this object. Started to work on controling sky map
using motion sensor.
parent 1ec33812
......@@ -610,6 +610,9 @@ if(BUILD_KSTARS_LITE)
kstarslite/skyobjectlite.cpp
#ImageProvider
kstarslite/imageprovider.cpp
#Dialogs
kstarslite/dialogs/finddialoglite.cpp
kstarslite/dialogs/skyobjectlistmodel.cpp
#RootNode
kstarslite/skyitems/rootnode.cpp
kstarslite/skyitems/skyopacitynode.cpp
......@@ -687,6 +690,9 @@ if(BUILD_KSTARS_LITE)
kstarslite/qml/modules/Splash.qml
kstarslite/qml/modules/ContextDrawerMenu.qml
kstarslite/qml/modules/TelescopeControlMenu.qml
#Dialogs
kstarslite/qml/dialogs/FindDialog.qml
#INDI
kstarslite/qml/indi/INDIControlPanel.qml
kstarslite/qml/indi/DevicePanel.qml
kstarslite/qml/indi/ImagePreview.qml
......@@ -920,9 +926,12 @@ ecm_add_app_icon(KSTARS_APP_SRCS ICONS
${CMAKE_CURRENT_SOURCE_DIR}/icons/128-apps-kstars.png
)
if(NOT BUILD_KSTARS_LITE)
qt5_add_resources(KSTARS_APP_SRCS data/kstars.qrc)
add_executable(kstars ${KSTARS_APP_SRCS})
target_link_libraries(kstars KStarsLib)
if(NOT BUILD_KSTARS_LITE)
install(TARGETS kstars ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
########### install files ###############
......@@ -930,6 +939,3 @@ install(PROGRAMS org.kde.kstars.desktop DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES kstars.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kstars.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
endif(NOT BUILD_KSTARS_LITE)
add_executable(kstars ${KSTARS_APP_SRCS})
target_link_libraries(kstars KStarsLib)
......@@ -23,9 +23,13 @@
#include <QSurfaceFormat>
#include "indi/clientmanagerlite.h"
#include "kstarslite/imageprovider.h"
#include "klocalizedcontext.h"
#include "kspaths.h"
//Dialog
#include "kstarslite/dialogs/finddialoglite.h"
#include "Options.h"
#include "ksutils.h"
......@@ -57,6 +61,11 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
m_Engine.rootContext()->setContextProperty("KStarsLite", this);
m_Engine.rootContext()->setContextProperty("KStarsData", m_KStarsData);
m_Engine.rootContext()->setContextProperty("Options", Options::self());
m_Engine.rootContext()->setContextObject(new KLocalizedContext(this));
//Dialogs
m_findDialogLite = new FindDialogLite;
m_Engine.rootContext()->setContextProperty("FindDialogLite", m_findDialogLite);
//Set Geographic Location from Options
m_KStarsData->setLocationFromOptions();
......@@ -68,7 +77,7 @@ KStarsLite::KStarsLite( bool doSplash, bool startClock, const QString &startDate
m_Engine.rootContext()->setContextProperty("SkyMapLite", m_SkyMapLite);
m_imgProvider = new ImageProvider;
m_Engine.addImageProvider(QLatin1String("images"), m_imgProvider);
//qmlRegisterType<SkyPoint>("skymaplite",1,0,"SkyMapLite");
//qmlRegisterType<SkyPoint>("skymaplite",1,0,"SkyMapLite");
#ifdef Q_OS_ANDROID
QString main = KSPaths::locate(QStandardPaths::AppDataLocation, "kstarslite/qml/main.qml");
......
......@@ -29,6 +29,8 @@ class SkyPoint;
class GeoLocation;
class ImageProvider;
class FindDialogLite;
#ifdef INDI_FOUND
class ClientManagerLite;
#endif
......@@ -140,6 +142,9 @@ private:
KStarsData *m_KStarsData;
ImageProvider *m_imgProvider;
//Dialogs
FindDialogLite *m_findDialogLite;
#ifdef INDI_FOUND
ClientManagerLite *m_clientManager;
#endif
......
/***************************************************************************
finddialoglite.cpp - K Desktop Planetarium
-------------------
begin : Wed Jul 29 2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@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 "finddialoglite.h"
#include "kstarsdata.h"
#include "Options.h"
#include "skyobjects/skyobject.h"
#include "skycomponents/starcomponent.h"
#include "skycomponents/skymapcomposite.h"
#include "skymaplite.h"
#include "solarsystemcomposite.h"
#include <QSortFilterProxyModel>
#include "skyobjectlistmodel.h"
#include <QTimer>
#include <QQmlContext>
FindDialogLite::FindDialogLite( ) :
timer(0)
{
m_filterModel.append( i18n ("Any") );
m_filterModel.append( i18n ("Stars") );
m_filterModel.append( i18n ("Solar System") );
m_filterModel.append( i18n ("Open Clusters") );
m_filterModel.append( i18n ("Globular Clusters") );
m_filterModel.append( i18n ("Gaseous Nebulae") );
m_filterModel.append( i18n ("Planetary Nebulae") );
m_filterModel.append( i18n ("Galaxies") );
m_filterModel.append( i18n ("Comets") );
m_filterModel.append( i18n ("Asteroids") );
m_filterModel.append( i18n ("Constellations") );
m_filterModel.append( i18n ("Supernovae") );
m_filterModel.append( i18n ("Satellites") );
emit filterModelChanged();
fModel = new SkyObjectListModel( this );
m_sortModel = new QSortFilterProxyModel(this);
m_sortModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
m_sortModel->setSourceModel( fModel );
m_sortModel->setSortRole(SkyObjectListModel::NameRole);
m_sortModel->setFilterRole(SkyObjectListModel::NameRole);
m_sortModel->setDynamicSortFilter(true);
KStarsLite::Instance()->qmlEngine()->rootContext()->setContextProperty("SortModel", m_sortModel);
m_sortModel->sort( 0 );
listFiltered = false;
}
FindDialogLite::~FindDialogLite() { }
/*void FindDialogLite::initSelection() {
if ( m_sortModel->rowCount() <= 0 )
{
return;
}
//if ( ui->SearchBox->text().isEmpty() ) {
//Pre-select the first item
QModelIndex selectItem = m_sortModel->index( 0, m_sortModel->filterKeyColumn(), QModelIndex() );
switch ( 0) {//ui->FilterType->currentIndex() ) {
case 0: //All objects, choose Andromeda galaxy
{
QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n("Andromeda Galaxy") ) );
selectItem = m_sortModel->mapFromSource( qmi );
break;
}
case 1: //Stars, choose Aldebaran
{
QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n("Aldebaran") ) );
selectItem = m_sortModel->mapFromSource( qmi );
break;
}
case 2: //Solar system or Asteroids, choose Aaltje
case 9:
{
QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n("Aaltje") ) );
selectItem = m_sortModel->mapFromSource( qmi );
break;
}
case 8: //Comets, choose 'Aarseth-Brewington (1989 W1)'
{
QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n("Aarseth-Brewington (1989 W1)") ) );
selectItem = m_sortModel->mapFromSource( qmi );
break;
}
}
//listFiltered = true;
}*/
void FindDialogLite::filterByType(uint typeIndex) {
KStarsData *data = KStarsData::Instance();
switch ( typeIndex ) {
case 0: // All object types
{
QVector<QPair<QString, const SkyObject *>> allObjects;
foreach( int type, data->skyComposite()->objectLists().keys() ) {
allObjects.append(data->skyComposite()->objectLists(SkyObject::TYPE(type)));
}
fModel->setSkyObjectsList( allObjects );
break;
}
case 1: //Stars
{
QVector<QPair<QString, const SkyObject *>> starObjects;
starObjects.append(data->skyComposite()->objectLists(SkyObject::STAR));
starObjects.append(data->skyComposite()->objectLists(SkyObject::CATALOG_STAR));
fModel->setSkyObjectsList( starObjects );
break;
}
case 2: //Solar system
{
QVector<QPair<QString, const SkyObject *>> ssObjects;
ssObjects.append(data->skyComposite()->objectLists(SkyObject::PLANET));
ssObjects.append(data->skyComposite()->objectLists(SkyObject::COMET));
ssObjects.append(data->skyComposite()->objectLists(SkyObject::ASTEROID));
ssObjects.append(data->skyComposite()->objectLists(SkyObject::MOON));
fModel->setSkyObjectsList(ssObjects);
break;
}
case 3: //Open Clusters
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::OPEN_CLUSTER ) );
break;
case 4: //Globular Clusters
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::GLOBULAR_CLUSTER ) );
break;
case 5: //Gaseous nebulae
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::GASEOUS_NEBULA ) );
break;
case 6: //Planetary nebula
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::PLANETARY_NEBULA ) );
break;
case 7: //Galaxies
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::GALAXY ) );
break;
case 8: //Comets
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::COMET ) );
break;
case 9: //Asteroids
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::ASTEROID ) );
break;
case 10: //Constellations
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::CONSTELLATION ) );
break;
case 11: //Supernovae
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::SUPERNOVA ) );
break;
case 12: //Satellites
fModel->setSkyObjectsList( data->skyComposite()->objectLists( SkyObject::SATELLITE ) );
break;
}
qDebug() << data->skyComposite()->objectLists( SkyObject::SUPERNOVA ) ;
}
void FindDialogLite::filterList(QString searchQuery) {
QString SearchText = processSearchText(searchQuery);
m_sortModel->setFilterFixedString( SearchText );
//filterByType();
//initSelection();
//Select the first item in the list that begins with the filter string
/*if ( !SearchText.isEmpty() ) {
QStringList mItems = fModel->stringList().filter( QRegExp( '^'+SearchText, Qt::CaseInsensitive ) );
mItems.sort();
if ( mItems.size() ) {
QModelIndex qmi = fModel->index( fModel->stringList().indexOf( mItems[0] ) );
QModelIndex selectItem = m_sortModel->mapFromSource( qmi );
}
}*/
listFiltered = true;
}
void FindDialogLite::selectObject(int index) {
QVariant sObj = m_sortModel->data(m_sortModel->index(index, 0), SkyObjectListModel::SkyObjectRole);
SkyObject *skyObj = (SkyObject *) sObj.value<void *>();
SkyMapLite::Instance()->slotOpenObject(skyObj);
}
void FindDialogLite::enqueueSearch() {
/*listFiltered = false;
if ( timer ) {
timer->stop();
} else {
timer = new QTimer( this );
timer->setSingleShot( true );
connect( timer, SIGNAL( timeout() ), this, SLOT( filterList() ) );
}
timer->start( 500 );*/
}
// Process the search box text to replace equivalent names like "m93" with "m 93"
QString FindDialogLite::processSearchText(QString text) {
QRegExp re;
QString searchtext = text;
re.setCaseSensitivity( Qt::CaseInsensitive );
// If it is an NGC/IC/M catalog number, as in "M 76" or "NGC 5139", check for absence of the space
re.setPattern("^(m|ngc|ic)\\s*\\d*$");
if(text.contains(re)) {
re.setPattern("\\s*(\\d+)");
searchtext.replace( re, " \\1" );
re.setPattern("\\s*$");
searchtext.remove( re );
re.setPattern("^\\s*");
searchtext.remove( re );
}
// TODO after KDE 4.1 release:
// If it is a IAU standard three letter abbreviation for a constellation, then go to that constellation
// Check for genetive names of stars. Example: alp CMa must go to alpha Canis Majoris
return searchtext;
}
void FindDialogLite::slotOk() {
/*//If no valid object selected, show a sorry-box. Otherwise, emit accept()
SkyObject *selObj;
if(!listFiltered) {
filterList();
}
selObj = selectedObject();
if ( selObj == 0 ) {
QString message = i18n( "No object named %1 found.", ui->SearchBox->text() );
//KMessageBox::sorry( 0, message, i18n( "Bad object name" ) );
} else {
accept();
}*/
}
/*void FindDialogLite::keyPressEvent( QKeyEvent *e ) {
switch( e->key() ) {
case Qt::Key_Escape :
reject();
break;
case Qt::Key_Up :
{
int currentRow = ui->SearchList->currentIndex().row();
if ( currentRow > 0 ) {
QModelIndex selectItem = m_sortModel->index( currentRow-1, m_sortModel->filterKeyColumn(), QModelIndex() );
ui->SearchList->selectionModel()->setCurrentIndex( selectItem, QItemSelectionModel::SelectCurrent );
}
break;
}
case Qt::Key_Down :
{
int currentRow = ui->SearchList->currentIndex().row();
if ( currentRow < m_sortModel->rowCount()-1 ) {
QModelIndex selectItem = m_sortModel->index( currentRow+1, m_sortModel->filterKeyColumn(), QModelIndex() );
ui->SearchList->selectionModel()->setCurrentIndex( selectItem, QItemSelectionModel::SelectCurrent );
}
break;
}
}
}*/
void FindDialogLite::slotDetails()
{
/*if ( selectedObject() ) {
QPointer<DetailDialog> dd = new DetailDialog( selectedObject(), KStarsData::Instance()->ut(), KStarsData::Instance()->geo(), KStars::Instance());
dd->exec();
delete dd;
}*/
}
/***************************************************************************
finddialoglite.h - K Desktop Planetarium
-------------------
begin : Wed Jul 29 2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@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 FINDDIALOGLITE_H_
#define FINDDIALOGLITE_H_
#include <QKeyEvent>
#include <QDialog>
#include "skyobjects/skyobject.h"
class QTimer;
class QStringListModel;
class QSortFilterProxyModel;
class SkyObjectListModel;
/** @class FindDialogLite
* A backend of dialog decleared in QML.
*
* @short Backend for Find Object Dialog in QML
* @author Artem Fedoskin, Jason Harris
* @version 1.0
*/
class FindDialogLite : public QObject {
Q_OBJECT
Q_PROPERTY(QStringList filterModel READ getFilterModel NOTIFY filterModelChanged)
public:
/**Constructor. Creates all widgets and packs them in QLayouts. Connects
* Signals and Slots. Runs initObjectList().
*/
explicit FindDialogLite();
/** Destructor */
virtual ~FindDialogLite();
Q_INVOKABLE void selectObject(int index);
QStringList getFilterModel() { return m_filterModel; }
/** @short pre-filter the list of objects according to the
* selected object type.
*/
Q_INVOKABLE void filterByType(uint typeIndex);
signals:
void filterModelChanged();
public slots:
/**When Text is entered in the QLineEdit, filter the List of objects
* so that only objects which start with the filter text are shown.
*/
Q_INVOKABLE void filterList(QString searchQuery);
//FIXME: Still valid for QDialog? i.e., does QDialog have a slotOk() ?
/**
*Overloading the Standard QDialogBase slotOk() to show a "sorry" message
*box if no object is selected when the user presses Ok. The window is
*not closed in this case.
*/
void slotOk();
private slots:
/** Set the selected item to the first item in the list */
//void initSelection();
void enqueueSearch();
void slotDetails();
private:
/** @short Do some post processing on the search text to interpret what the user meant
* This could include replacing text like "m93" with "m 93"
*/
QString processSearchText(QString text);
QStringList m_filterModel;
SkyObjectListModel *fModel;
QSortFilterProxyModel* m_sortModel;
QTimer* timer;
bool listFiltered;
};
#endif
/***************************************************************************
skyobjectlistmodel.cpp - K Desktop Planetarium
-------------------
begin : Wed Jul 29 2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@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 "skyobjectlistmodel.h"
#include "skyobject.h"
SkyObjectListModel::SkyObjectListModel(QObject *parent)
:QAbstractListModel(parent)
{
}
QHash<int, QByteArray> SkyObjectListModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[SkyObjectRole] = "skyobject";
return roles;
}
QVariant SkyObjectListModel::data(const QModelIndex &index, int role) const {
if(!index.isValid()) {
return QVariant();
}
if(role == NameRole) {
return QVariant(skyObjects[index.row()].first);
} else if(role == SkyObjectRole) {
return qVariantFromValue((void *) skyObjects[index.row()].second);
}
return QVariant();
}
void SkyObjectListModel::setSkyObjectsList(QVector<QPair<QString, const SkyObject *>> sObjects) {
emit beginResetModel();
skyObjects = sObjects;
/*foreach(SkyObject *s, sObjects) {
QString name = s->name();
if ( ! name.isEmpty() ) {
skyObjects.append(QPair<QString, SkyObject *>(name, s));
}
QString longname = s->longname();
if ( ! longname.isEmpty() && longname != name) {
skyObjects.append(QPair<QString, SkyObject *>(longname, s));
}
}*/
emit endResetModel();
}
/***************************************************************************
skyobjectlistmodel.h - K Desktop Planetarium
-------------------
begin : Wed Jul 29 2016
copyright : (C) 2016 by Artem Fedoskin
email : afedoskin3@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 SKYOBJECTLISTMODEL_H_
#define SKYOBJECTLISTMODEL_H_
#include <QAbstractListModel>
#include <QDebug>
class SkyObject;
/** @class FindDialogLite
* A backend of dialog decleared in QML.
*
* @short Backend for Find Object Dialog in QML
* @author Artem Fedoskin, Jason Harris
* @version 1.0
*/
class SkyObjectListModel : public QAbstractListModel {
Q_OBJECT
public:
enum DemoRoles {
NameRole = Qt::UserRole + 1,
SkyObjectRole
};
explicit SkyObjectListModel(QObject *parent = 0);
virtual int rowCount(const QModelIndex&) const { return skyObjects.size(); }
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QHash<int, QByteArray> roleNames() const;
/*virtual bool removeRows(int row, int count, const QModelIndex &parent) {
qDebug() << "TEST";
return false;
}*/
void setSkyObjectsList(QVector<QPair<QString, const SkyObject *>> sObjects);
private:
QVector<QPair<QString, const SkyObject *>> skyObjects;
};
#endif
......@@ -15,6 +15,9 @@ install( FILES modules/BottomMenu.qml
modules/TelescopeControlMenu.qml
DESTINATION ${KDE_INSTALL_DATADIR}/kstars/kstarslite/qml/modules )
install( FILES dialogs/FindDialog.qml
DESTINATION ${KDE_INSTALL_DATADIR}/kstars/kstarslite/qml/dialogs )
install( FILES modules/helpers/TopMenuButton.qml
DESTINATION ${KDE_INSTALL_DATADIR}/kstars/kstarslite/qml/modules/helpers )