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
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{
143 QRegExp re;
144 QString searchtext = text;
145
146 re.setCaseSensitivity(Qt::CaseInsensitive);
147
148 // If it is an NGC/IC/M catalog number, as in "M 76" or "NGC 5139", check for absence of the space
149 re.setPattern("^(m|ngc|ic)\\s*\\d*$");
150 if (text.contains(re))
151 {
152 re.setPattern("\\s*(\\d+)");
153 searchtext.replace(re, " \\1");
154 re.setPattern("\\s*$");
155 searchtext.remove(re);
156 re.setPattern("^\\s*");
157 searchtext.remove(re);
158 }
159
160 // TODO after KDE 4.1 release:
161 // If it is a IAU standard three letter abbreviation for a constellation, then go to that constellation
162 // Check for genetive names of stars. Example: alp CMa must go to alpha Canis Majoris
163
164 return searchtext;
165}
166
168{
169 if (searchQuery.isEmpty())
170 return false;
171
172 int size = m_sortModel->rowCount(m_sortModel->index(0, 0));
173 QString stripped = searchQuery.remove(' ');
174
175 for (int i = 0; i < size; ++i)
176 {
177 QString s = m_sortModel->data(m_sortModel->index(i, 0), Qt::DisplayRole).toString();
178
179 if (s == searchQuery || s.remove(' ') == stripped)
180 return true;
181 }
182 return false;
183}
184
186{
187 emit notifyMessage(i18n("Not Implemented.", searchQuery));
188}
189
190void FindDialogLite::setIsResolveEnabled(bool isResolveEnabled)
191{
192 if (m_isResolveEnabled != isResolveEnabled)
193 {
194 m_isResolveEnabled = isResolveEnabled;
195 emit isResolveEnabledChanged(isResolveEnabled);
196 }
197}
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:72
SkyMapComposite * skyComposite()
Definition kstarsdata.h:166
static KStarsLite * Instance()
Definition kstarslite.h:77
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)
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)
CaseInsensitive
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:55:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.