File indexing completed on 2025-03-16 03:33:49
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 #include <QStringList> 0011 0012 class QSortFilterProxyModel; 0013 class QStringListModel; 0014 class QTimer; 0015 0016 class SkyObjectListModel; 0017 0018 /** 0019 * @class FindDialogLite 0020 * @short Backend for "Find Object" dialog in QML 0021 * The way we are searching for the object is as follows: 0022 * Each SkyComponent in addition to QStringList of names holds QVector<QPair<QString, const SkyObject *>>. 0023 * SkyObjectListModel is a class that holds SkyObjects together with their names (name and longname). 0024 * Whenever user searches for an object we sort list of SkyObjects through QSortFilterProxyModel. The reason 0025 * for this way of searching is that we don't need to search for an object again, as it was done previously. 0026 * Instead of this, user directly selects the object in search results. 0027 * 0028 * @author Artem Fedoskin, Jason Harris 0029 * @version 1.0 0030 */ 0031 class FindDialogLite : public QObject 0032 { 0033 Q_OBJECT 0034 0035 Q_PROPERTY(QStringList filterModel READ getFilterModel NOTIFY filterModelChanged) 0036 //true if m_searchQuery is already in sorted list of object names 0037 Q_PROPERTY(bool isResolveEnabled READ getIsResolveEnabled WRITE setIsResolveEnabled NOTIFY isResolveEnabledChanged) 0038 public: 0039 /** 0040 * @short Constructor. Initialize m_filterModel with object types and 0041 * initialize m_sortModel with instance of SkyObjectListModel 0042 */ 0043 FindDialogLite(); 0044 virtual ~FindDialogLite(); 0045 0046 /** Open context menu for object with given index from m_sortModel */ 0047 Q_INVOKABLE void selectObject(int index); 0048 0049 /** 0050 * @return list of object types 0051 */ 0052 QStringList getFilterModel() { return m_filterModel; } 0053 0054 /** 0055 * @short pre-filter the list of objects according to the selected object type. 0056 */ 0057 Q_INVOKABLE void filterByType(uint typeIndex); 0058 0059 /** 0060 * @short searches for the object in internet (adopted to KStars Lite version of 0061 * FindDialog::finishProcessing() 0062 */ 0063 Q_INVOKABLE void resolveInInternet(QString searchQuery); 0064 0065 /** 0066 * @return true it at least one entry in fModel is an exact match with searchQuery 0067 */ 0068 Q_INVOKABLE bool isInList(QString searchQuery); 0069 0070 /** Getter for isResolveEnabled **/ 0071 bool getIsResolveEnabled() { return m_isResolveEnabled; } 0072 0073 /** Setter for isResolveEnabled **/ 0074 void setIsResolveEnabled(bool isResolveEnabled); 0075 signals: 0076 void filterModelChanged(); 0077 void notifyMessage(QString message); 0078 void isResolveEnabledChanged(bool); 0079 0080 public slots: 0081 /** 0082 * When Text is entered in the QLineEdit, filter the List of objects 0083 * so that only objects which start with the filter text are shown. 0084 */ 0085 Q_INVOKABLE void filterList(QString searchQuery); 0086 0087 private: 0088 /** 0089 * @short Do some post processing on the search text to interpret what the user meant 0090 * This could include replacing text like "m93" with "m 93" 0091 */ 0092 QString processSearchText(QString text); 0093 0094 QStringList m_filterModel; 0095 SkyObjectListModel *fModel { nullptr }; 0096 QSortFilterProxyModel *m_sortModel { nullptr }; 0097 QTimer *timer { nullptr }; 0098 bool listFiltered { false }; 0099 0100 /** Current query that is used to sort fModel **/ 0101 QString m_searchQuery; 0102 bool m_isResolveEnabled { false }; 0103 uint m_typeIndex { 0 }; 0104 };