34 QStringList words = s.split(QChar(
' '));
35 QStringList changedWords;
36 Q_FOREACH(QString w, words) {
40 QString up = w.toUpper();
46 changedWords.append(
"Field");
51 changedWords.append(
"County");
55 if ((up ==
"MUNI") || (up ==
"MUN")) {
56 changedWords.append(
"Municipal");
61 changedWords.append(
"Memorial");
66 changedWords.append(
"Regional");
71 changedWords.append(
"Center");
76 changedWords.append(
"International");
82 changedWords.append(
"(New South Wales)");
86 if ((up ==
"VOR") || (up ==
"NDB")
87 || (up ==
"VOR-DME") || (up ==
"VORTAC")
89 || (up ==
"AFB") || (up ==
"RAF"))
91 changedWords.append(w);
95 if ((up ==
"[X]") || (up ==
"[H]") || (up ==
"[S]")) {
99 QChar firstChar = w.at(0).toUpper();
100 w = w.mid(1).toLower();
101 w.prepend(firstChar);
103 changedWords.append(w);
106 return changedWords.join(QChar(
' '));
144 bool ok = TypeFilter::pass(aPos);
145 const auto ty = aPos->
type();
149 if (!simgear::strutils::ends_with(aPos->
name(),
"TACAN")) {
163 m_searchActive =
false;
172 const size_t uIndex =
static_cast<size_t>(index);
173 if ((index < 0) || (uIndex >= m_ids.size()))
176 return m_ids.at(uIndex);
180 QAbstractListModel(parent)
192 std::string term(t.toUpper().toStdString());
197 m_ids.reserve(exactMatches.size());
198 m_items.reserve(exactMatches.size());
199 for (
auto match : exactMatches) {
200 m_ids.push_back(match->guid());
201 m_items.push_back(match);
208 QTimer::singleShot(100,
this, SLOT(onSearchResultsPoll()));
209 m_searchActive =
true;
216 return m_searchActive || (!m_items.empty());
221 if (m_maxResults > 0)
222 return std::min(
static_cast<int>(m_ids.size()), m_maxResults);
224 return static_cast<int>(m_ids.size());
229 if (!index.isValid())
234 case GuidRole:
return static_cast<qlonglong
>(pos->guid());
235 case IdentRole:
return QString::fromStdString(pos->ident());
239 case NavFrequencyRole: {
267 m_searchActive =
false;
271 for (
unsigned int i=0;
i < items.size(); ++
i) {
272 m_ids.push_back(m_items[
i]->guid());
282 QHash<int, QByteArray> result = QAbstractListModel::roleNames();
284 result[GeodRole] =
"geod";
285 result[GuidRole] =
"guid";
286 result[IdentRole] =
"ident";
287 result[NameRole] =
"name";
288 result[IconRole] =
"icon";
289 result[TypeRole] =
"type";
290 result[NavFrequencyRole] =
"frequency";
296 if (m_searchActive || (m_ids.size() != 1))
304 return static_cast<int>(m_ids.size());
307void NavaidSearchModel::onSearchResultsPoll()
309 if (m_search.isNull()) {
314 if (!newIds.empty()) {
316 for (
auto id : newIds) {
318 m_items.push_back({});
324 if (m_search->isComplete()) {
325 m_searchActive =
false;
331 QTimer::singleShot(100,
this, SLOT(onSearchResultsPoll()));
335void NavaidSearchModel::resort()
337 if (!m_airportsOnly) {
345 std::map<PositionedID, double> longestRunwayCache;
346 for (
auto a : m_ids) {
349 const auto rwy = apt->longestRunway();
351 longestRunwayCache[a] = rwy->lengthFt();
356 std::sort(m_ids.begin(), m_ids.end(),
359 return longestRunwayCache[a] > longestRunwayCache[b];
QString fixNavaidName(QString s)
SGSharedPtr< FGAirport > FGAirportRef
static QPixmap iconForPositioned(const FGPositionedRef &pos, const IconOptions &options=NoOptions)
virtual const std::string & name() const
Return the name of this positioned.
static SGSharedPtr< T > loadById(PositionedID id)
@ DME
important that DME & TACAN are adjacent to keep the TacanFilter efficient - DMEs are proxies for TACA...
bool pass(FGPositioned *aPos) const override
Over-rideable filter method.
IdentSearchFilter(LauncherController::AircraftType aircraft, bool airportsOnly)
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 haveExistingSearchChanged()
Q_INVOKABLE void setSearch(QString t, AircraftType aircraft=Unknown)
QHash< int, QByteArray > roleNames() const override
void searchActiveChanged()
Q_INVOKABLE qlonglong guidAtIndex(int index) const
FGPositionedList findAllWithIdent(const std::string &ident, FGPositioned::Filter *filter, bool exact)
FGPositionedRef loadById(PositionedID guid)
retrieve an FGPositioned from the cache.
static NavDataCache * instance()
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
SGSharedPtr< FGPositioned > FGPositionedRef
std::vector< PositionedID > PositionedIDVec
T * fgpositioned_cast(FGPositioned *p)
std::vector< FGPositionedRef > FGPositionedList