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 // Backend methods
64 /**
65 * @short Do some post processing on the search text to interpret what the user meant
66 * This could include replacing text like "m93" with "m 93"
67 */
68 static QString processSearchText(QString searchText);
69
70 // FIXME: Move this method to a better place, maybe into the NameResolver
71 /**
72 * @short Resolves an object using the internet and adds it to the database
73 * @note Can only be called when KStars is fully initialized
74 * @return a pointer to the DeepSkyObject (instance managed by internetResolvedComponent) if successful, nullptr otherwise
75 */
76 static CatalogObject *resolveAndAdd(CatalogsDB::DBManager &db_manager, const QString &query);
77
78 public slots:
79 /**
80 * When Text is entered in the QLineEdit, filter the List of objects
81 * so that only objects which start with the filter text are shown.
82 */
83 void filterList();
84
85 // FIXME: Still valid for QDialog? i.e., does QDialog have a slotOk() ?
86 /**
87 * Overloading the Standard QDialogBase slotOk() to show a "sorry"
88 * message box if no object is selected and internet resolution was
89 * disabled/failed when the user presses Ok. The window is not
90 * closed in this case.
91 */
92 void slotOk();
93
94 /**
95 * @short This slot resolves the object on the internet, ignoring the selection on the list
96 */
97 void slotResolve();
98
99 private slots:
100 /** Init object list after opening dialog. */
101 void init();
102
103 /** Set the selected item to the first item in the list */
104 void initSelection();
105
106 void enqueueSearch();
107
108 void slotDetails();
109
110 /** Enable/disable the OK button, and set the default button */
111 void slotUpdateButtons();
112
113 protected:
114 /**
115 * Process Keystrokes. The Up and Down arrow keys are used to select the
116 * Previous/Next item in the listbox of named objects. The Esc key closes
117 * the window with no selection, using reject().
118 * @param e The QKeyEvent pointer
119 */
120 void keyPressEvent(QKeyEvent *e) override;
121
122 void showEvent(QShowEvent *e) override;
123
124 /** @return the currently-selected item from the listbox of named objects */
125 SkyObject *selectedObject() const;
126
127 private:
128 /**
129 * Constructor. Creates all widgets and packs them in QLayouts. Connects
130 * Signals and Slots. Runs initObjectList().
131 */
132 explicit FindDialog(QWidget *parent = nullptr);
133
134 static FindDialog *m_Instance;
135
136 /**
137 * @short processSearchText(QString) called on the text entered in the find dialog
138 */
139 inline QString processSearchText() { return processSearchText(ui->SearchBox->text()); }
140
141 /** @short Finishes the processing towards closing the dialog initiated by slotOk() or slotResolve() */
142 void finishProcessing(SkyObject *selObj = nullptr, bool resolve = true);
143
144 /** @short pre-filter the list of objects according to the selected object type. */
145 void filterByType();
146
147 FindDialogUI *ui { nullptr };
148 SkyObjectListModel *fModel { nullptr };
149 QSortFilterProxyModel *sortModel { nullptr };
150 QTimer *timer { nullptr };
151 bool listFiltered { false };
152 std::size_t m_currentSearchSequence { 0 };
153 QPushButton *okB { nullptr };
154 SkyObject *m_targetObject { nullptr };
155
156 // History
157 QComboBox *m_HistoryCombo { nullptr};
158 QList<SkyObject *> m_HistoryList;
159
160 // DSO Database
161 CatalogsDB::DBManager m_dbManager; // runs in this thread
162};
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 ...
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 Fri Oct 4 2024 12:01:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.