FlightGear next
NavaidSearchModel.hxx
Go to the documentation of this file.
1// NavaidSearchModel.hxx - expose navaids via a QabstractListModel
2//
3// Written by James Turner, started July 2018.
4//
5// Copyright (C) 2018 James Turner <james@flightgear.org>
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21#ifndef NAVAIDSEARCHMODEL_HXX
22#define NAVAIDSEARCHMODEL_HXX
23
24#include <QAbstractListModel>
25
27
30
31class NavaidSearchModel : public QAbstractListModel
32{
33 Q_OBJECT
34
37 Q_PROPERTY(bool airportsOnly MEMBER m_airportsOnly NOTIFY airportsOnlyChanged)
38 Q_PROPERTY(int maxResults MEMBER m_maxResults NOTIFY maxResultsChanged)
39 Q_PROPERTY(int numResults READ numResults NOTIFY searchActiveChanged)
40
41 Q_PROPERTY(qlonglong exactMatch READ exactMatch NOTIFY searchActiveChanged)
42
43 enum Roles {
44 GeodRole = Qt::UserRole + 1,
45 GuidRole = Qt::UserRole + 2,
46 IdentRole = Qt::UserRole + 3,
47 NameRole = Qt::UserRole + 4,
48 IconRole = Qt::UserRole + 5,
49 TypeRole = Qt::UserRole + 6,
50 NavFrequencyRole = Qt::UserRole + 7
51 };
52
53public:
54 NavaidSearchModel(QObject* parent = nullptr);
55
64
65 Q_ENUMS(AircraftType)
66
67 Q_INVOKABLE void setSearch(QString t, AircraftType aircraft = Unknown);
68
69 Q_INVOKABLE void clear();
70
71 Q_INVOKABLE qlonglong guidAtIndex(int index) const;
72
73 bool isSearchActive() const
74 {
75 return m_searchActive;
76 }
77
78 bool haveExistingSearch() const;
79
80 int rowCount(const QModelIndex&) const override;
81
82 QVariant data(const QModelIndex& index, int role) const override;
83
84 FGPositionedRef itemAtRow(unsigned int row) const;
85
86 void setItems(const FGPositionedList& items);
87
88 QHash<int, QByteArray> roleNames() const override;
89
90 qlonglong exactMatch() const;
91
92 int numResults() const;
93Q_SIGNALS:
99
100private slots:
101 void onSearchResultsPoll();
102
103private:
104 void resort();
105
106 PositionedIDVec m_ids;
107 mutable FGPositionedList m_items;
108 bool m_searchActive = false;
109 bool m_airportsOnly = false;
110 int m_maxResults = 0;
111 QScopedPointer<flightgear::NavDataCache::ThreadedGUISearch> m_search;
112};
113
114
115#endif // NAVAIDSEARCHMODEL_HXX
SGSharedPtr< FGPositioned > FGPositionedRef
Definition airways.hxx:30
void setItems(const FGPositionedList &items)
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &) const override
NavaidSearchModel(QObject *parent=nullptr)
FGPositionedRef itemAtRow(unsigned int row) const
void airportsOnlyChanged()
void haveExistingSearchChanged()
Q_INVOKABLE void setSearch(QString t, AircraftType aircraft=Unknown)
bool isSearchActive() const
QHash< int, QByteArray > roleNames() const override
void searchActiveChanged()
Q_INVOKABLE void clear()
Q_INVOKABLE qlonglong guidAtIndex(int index) const
void maxResultsChanged()
std::vector< PositionedID > PositionedIDVec
std::vector< FGPositionedRef > FGPositionedList