Kstars

finddialog.h
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "ui_finddialog.h"
10#include "catalogsdb.h"
11
12#include <QDialog>
13#include <QKeyEvent>
14
15class QTimer;
16class QComboBox;
20class SkyObject;
21class DeepSkyObject;
22
23class FindDialogUI : public QFrame, public Ui::FindDialog
24{
26 public:
27 explicit FindDialogUI(QWidget *parent = nullptr);
28};
29
30/**
31 * @class FindDialog
32 * Dialog window for finding SkyObjects by name. The dialog contains
33 * a QListBox showing the list of named objects, a QLineEdit for filtering
34 * the list by name, and a QCombobox for filtering the list by object type.
35 *
36 * 2018-12 JM: The dialog is a singleton since we need a single instance in KStars.
37 * @short Find Object Dialog
38 * @author Jason Harris
39 * @author Jasem Mutlaq
40 * @version 1.1
41 */
42class FindDialog : public QDialog
43{
45 public:
46 static FindDialog *Instance();
47
48 /**
49 * @return the target object (need not be the same as currently selected object!)
50 *
51 * @note Avoid using selectedObject()
52 */
53 inline SkyObject *targetObject() { return m_targetObject; }
54
55
56 /**
57 * @brief exec overrides base's QDialog::exec() to provide a parent widget.
58 * @param parent is the widget to position the FindDialog instance againt.
59 * @return QDialog::exec() result.
60 */
61 int execWithParent(QWidget* parent = nullptr);
62
63 /**
64 * @brief removes the Details... button from this exec.
65 * @return QDialog::exec() result.
66 */
68
69 // Backend methods
70 /**
71 * @short Do some post processing on the search text to interpret what the user meant
72 * This could include replacing text like "m93" with "m 93"
73 */
74 static QString processSearchText(QString searchText);
75
76 // FIXME: Move this method to a better place, maybe into the NameResolver
77 /**
78 * @short Resolves an object using the internet and adds it to the database
79 * @note Can only be called when KStars is fully initialized
80 * @return a pointer to the DeepSkyObject (instance managed by internetResolvedComponent) if successful, nullptr otherwise
81 */
82 static CatalogObject *resolveAndAdd(CatalogsDB::DBManager &db_manager, const QString &query);
83
84 public slots:
85 /**
86 * When Text is entered in the QLineEdit, filter the List of objects
87 * so that only objects which start with the filter text are shown.
88 */
89 void filterList();
90
91 // FIXME: Still valid for QDialog? i.e., does QDialog have a slotOk() ?
92 /**
93 * Overloading the Standard QDialogBase slotOk() to show a "sorry"
94 * message box if no object is selected and internet resolution was
95 * disabled/failed when the user presses Ok. The window is not
96 * closed in this case.
97 */
98 void slotOk();
99
100 /**
101 * @short This slot resolves the object on the internet, ignoring the selection on the list
102 */
103 void slotResolve();
104
105 private slots:
106 /** Init object list after opening dialog. */
107 void init();
108
109 /** Set the selected item to the first item in the list */
110 void initSelection();
111
112 void enqueueSearch();
113
114 void slotDetails();
115
116 /** Enable/disable the OK button, and set the default button */
117 void slotUpdateButtons();
118
119 protected:
120 /**
121 * Process Keystrokes. The Up and Down arrow keys are used to select the
122 * Previous/Next item in the listbox of named objects. The Esc key closes
123 * the window with no selection, using reject().
124 * @param e The QKeyEvent pointer
125 */
126 void keyPressEvent(QKeyEvent *e) override;
127
128 void showEvent(QShowEvent *e) override;
129
130 /** @return the currently-selected item from the listbox of named objects */
131 SkyObject *selectedObject() const;
132
133 private:
134 /**
135 * Constructor. Creates all widgets and packs them in QLayouts. Connects
136 * Signals and Slots. Runs initObjectList().
137 */
138 explicit FindDialog(QWidget *parent = nullptr);
139
140 static FindDialog *m_Instance;
141
142 /**
143 * @short processSearchText(QString) called on the text entered in the find dialog
144 */
145 inline QString processSearchText() { return processSearchText(ui->SearchBox->text()); }
146
147 /** @short Finishes the processing towards closing the dialog initiated by slotOk() or slotResolve() */
148 void finishProcessing(SkyObject *selObj = nullptr, bool resolve = true);
149
150 /** @short pre-filter the list of objects according to the selected object type. */
151 void filterByType();
152
153 FindDialogUI *ui { nullptr };
154 SkyObjectListModel *fModel { nullptr };
155 QSortFilterProxyModel *sortModel { nullptr };
156 QTimer *timer { nullptr };
157 bool listFiltered { false };
158 std::size_t m_currentSearchSequence { 0 };
159 QPushButton *okB { nullptr };
160 SkyObject *m_targetObject { nullptr };
161 QPushButton *m_DetailsB { nullptr };
162
163 // History
164 QComboBox *m_HistoryCombo { nullptr};
165 QList<SkyObject *> m_HistoryList;
166
167 // DSO Database
168 CatalogsDB::DBManager m_dbManager; // runs in this thread
169};
A simple container object to hold the minimum information for a Deep Sky Object to be drawn on the sk...
Manages the catalog database and provides an interface to provide an interface to query and modify th...
Definition catalogsdb.h:183
Dialog window for finding SkyObjects by name.
Definition finddialog.h:43
static CatalogObject * resolveAndAdd(CatalogsDB::DBManager &db_manager, const QString &query)
Resolves an object using the internet and adds it to the database.
void filterList()
When Text is entered in the QLineEdit, filter the List of objects so that only objects which start wi...
void slotResolve()
This slot resolves the object on the internet, ignoring the selection on the list.
int execWithParent(QWidget *parent=nullptr)
exec overrides base's QDialog::exec() to provide a parent widget.
SkyObject * selectedObject() const
void slotOk()
Overloading the Standard QDialogBase slotOk() to show a "sorry" message box if no object is selected ...
int execWithoutDetails()
removes the Details... button from this exec.
void keyPressEvent(QKeyEvent *e) override
Process Keystrokes.
SkyObject * targetObject()
Definition finddialog.h:53
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
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.