Kstars

finddialoglite.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "finddialoglite.h"
8
9#include "catalogentrydata.h"
10#include "deepskyobject.h"
11#include "kstarsdata.h"
12#include "kstarslite.h"
13#include "skymaplite.h"
14#include "skyobjectlistmodel.h"
15#include "skycomponents/skymapcomposite.h"
16#include "skyobjects/skyobject.h"
17#include "tools/nameresolver.h"
18
19#include <QQmlContext>
20#include <QSortFilterProxyModel>
21#include <QTimer>
22
24{
25 m_filterModel.append(i18n("Any"));
26 m_filterModel.append(i18n("Stars"));
27 m_filterModel.append(i18n("Solar System"));
28 m_filterModel.append(i18n("Open Clusters"));
29 m_filterModel.append(i18n("Globular Clusters"));
30 m_filterModel.append(i18n("Gaseous Nebulae"));
31 m_filterModel.append(i18n("Planetary Nebulae"));
32 m_filterModel.append(i18n("Galaxies"));
33 m_filterModel.append(i18n("Comets"));
34 m_filterModel.append(i18n("Asteroids"));
35 m_filterModel.append(i18n("Constellations"));
36 m_filterModel.append(i18n("Supernovae"));
37 m_filterModel.append(i18n("Satellites"));
38 emit filterModelChanged();
39
40 fModel = new SkyObjectListModel(this);
41 m_sortModel = new QSortFilterProxyModel(this);
43 m_sortModel->setSourceModel(fModel);
44 m_sortModel->setSortRole(Qt::DisplayRole);
45 m_sortModel->setFilterRole(Qt::DisplayRole);
46 m_sortModel->setDynamicSortFilter(true);
47 KStarsLite::Instance()->qmlEngine()->rootContext()->setContextProperty("SortModel", m_sortModel);
48 m_sortModel->sort(0);
49}
50
51FindDialogLite::~FindDialogLite()
52{
53}
54
55void FindDialogLite::filterByType(uint typeIndex)
56{
57 KStarsData *data = KStarsData::Instance();
58 m_typeIndex = typeIndex;
59
60 switch (typeIndex)
61 {
62 case 0: // All object types
63 {
65 foreach (int type, data->skyComposite()->objectLists().keys())
66 {
67 allObjects.append(data->skyComposite()->objectLists(SkyObject::TYPE(type)));
68 }
69 fModel->setSkyObjectsList(allObjects);
70 break;
71 }
72 case 1: //Stars
73 {
75 starObjects.append(data->skyComposite()->objectLists(SkyObject::STAR));
76 starObjects.append(data->skyComposite()->objectLists(SkyObject::CATALOG_STAR));
77 fModel->setSkyObjectsList(starObjects);
78 break;
79 }
80 case 2: //Solar system
81 {
83 ssObjects.append(data->skyComposite()->objectLists(SkyObject::PLANET));
84 ssObjects.append(data->skyComposite()->objectLists(SkyObject::COMET));
85 ssObjects.append(data->skyComposite()->objectLists(SkyObject::ASTEROID));
86 ssObjects.append(data->skyComposite()->objectLists(SkyObject::MOON));
87
88 fModel->setSkyObjectsList(ssObjects);
89 break;
90 }
91 case 3: //Open Clusters
92 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::OPEN_CLUSTER));
93 break;
94 case 4: //Globular Clusters
95 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::GLOBULAR_CLUSTER));
96 break;
97 case 5: //Gaseous nebulae
98 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::GASEOUS_NEBULA));
99 break;
100 case 6: //Planetary nebula
101 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::PLANETARY_NEBULA));
102 break;
103 case 7: //Galaxies
104 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::GALAXY));
105 break;
106 case 8: //Comets
107 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::COMET));
108 break;
109 case 9: //Asteroids
110 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::ASTEROID));
111 break;
112 case 10: //Constellations
113 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::CONSTELLATION));
114 break;
115 case 11: //Supernovae
116 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::SUPERNOVA));
117 break;
118 case 12: //Satellites
119 fModel->setSkyObjectsList(data->skyComposite()->objectLists(SkyObject::SATELLITE));
120 break;
121 }
122}
123
125{
126 m_searchQuery = searchQuery;
127 setIsResolveEnabled(!isInList(searchQuery));
128 QString SearchText = processSearchText(searchQuery);
129 m_sortModel->setFilterFixedString(SearchText);
130 listFiltered = true;
131}
132
134{
135 QVariant sObj = m_sortModel->data(m_sortModel->index(index, 0), SkyObjectListModel::SkyObjectRole);
136 SkyObject *skyObj = (SkyObject *)sObj.value<void *>();
137 SkyMapLite::Instance()->slotSelectObject(skyObj);
138}
139
140// Process the search box text to replace equivalent names like "m93" with "m 93"
141QString FindDialogLite::processSearchText(QString text)
142{
144 QString searchtext = text;
145
146
148
149 // If it is an NGC/IC/M catalog number, as in "M 76" or "NGC 5139", check for absence of the space
150 re.setPattern("^(m|ngc|ic)\\s*\\d*$");
151 if (text.contains(re))
152 {
153 re.setPattern("\\s*(\\d+)");
154 searchtext.replace(re, " \\1");
155 re.setPattern("\\s*$");
156 searchtext.remove(re);
157 re.setPattern("^\\s*");
158 searchtext.remove(re);
159 }
160
161 // TODO after KDE 4.1 release:
162 // If it is a IAU standard three letter abbreviation for a constellation, then go to that constellation
163 // Check for genetive names of stars. Example: alp CMa must go to alpha Canis Majoris
164
165 return searchtext;
166}
167
169{
170 if (searchQuery.isEmpty())
171 return false;
172
173 int size = m_sortModel->rowCount(m_sortModel->index(0, 0));
174 QString stripped = searchQuery.remove(' ');
175
176 for (int i = 0; i < size; ++i)
177 {
178 QString s = m_sortModel->data(m_sortModel->index(i, 0), Qt::DisplayRole).toString();
179
180 if (s == searchQuery || s.remove(' ') == stripped)
181 return true;
182 }
183 return false;
184}
185
187{
188 emit notifyMessage(i18n("Not Implemented.", searchQuery));
189}
190
191void FindDialogLite::setIsResolveEnabled(bool isResolveEnabled)
192{
193 if (m_isResolveEnabled != isResolveEnabled)
194 {
195 m_isResolveEnabled = isResolveEnabled;
196 emit isResolveEnabledChanged(isResolveEnabled);
197 }
198}
Q_INVOKABLE void filterByType(uint typeIndex)
pre-filter the list of objects according to the selected object type.
Q_INVOKABLE bool isInList(QString searchQuery)
Q_INVOKABLE void selectObject(int index)
Open context menu for object with given index from m_sortModel.
Q_INVOKABLE void filterList(QString searchQuery)
When Text is entered in the QLineEdit, filter the List of objects so that only objects which start wi...
Q_INVOKABLE void resolveInInternet(QString searchQuery)
searches for the object in internet (adopted to KStars Lite version of FindDialog::finishProcessing()
FindDialogLite()
Constructor.
void setIsResolveEnabled(bool isResolveEnabled)
Setter for isResolveEnabled.
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
SkyMapComposite * skyComposite()
Definition kstarsdata.h:168
static KStarsLite * Instance()
Definition kstarslite.h:77
QQmlApplicationEngine * qmlEngine()
Definition kstarslite.h:92
void slotSelectObject(SkyObject *skyObj)
centres skyObj in SkyMap and opens context drawer with skyObj Used in FindDialogLite
A model used in Find Object Dialog in QML.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
TYPE
The type classification of the SkyObject.
Definition skyobject.h:112
QString i18n(const char *text, const TYPE &arg...)
QList< Key > keys() const const
void append(QList< T > &&value)
void setContextProperty(const QString &name, QObject *value)
QQmlContext * rootContext() const const
void setPattern(const QString &pattern)
void setPatternOptions(PatternOptions options)
virtual QVariant data(const QModelIndex &index, int role) const const override
void setDynamicSortFilter(bool enable)
void setFilterCaseSensitivity(Qt::CaseSensitivity cs)
void setFilterRole(int role)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
virtual int rowCount(const QModelIndex &parent) const const override
void setFilterFixedString(const QString &pattern)
virtual void setSourceModel(QAbstractItemModel *sourceModel) override
virtual void sort(int column, Qt::SortOrder order) override
void setSortRole(int role)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
CaseInsensitive
DisplayRole
QString toString() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:53:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.