mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T226, completer improvements
* a location can home multiple airports * use a combined name for that reason in completers
This commit is contained in:
@@ -99,7 +99,7 @@ namespace BlackGui
|
||||
const CAirportList airports = sGui->getWebDataServices()->getAirports();
|
||||
ui->le_Icao->setCompleter(new QCompleter(airports.allIcaoCodes(true), ui->le_Icao));
|
||||
ui->le_Name->setCompleter(new QCompleter(airports.allDescriptivesNames(true), ui->le_Name));
|
||||
ui->le_Location->setCompleter(new QCompleter(airports.allLocations(true), ui->le_Location));
|
||||
ui->le_Location->setCompleter(new QCompleter(airports.allLocationsPlusOptionalDescription(true), ui->le_Location));
|
||||
|
||||
if (ui->le_Icao->completer()->popup())
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
@@ -40,6 +41,14 @@ namespace BlackMisc
|
||||
m_descriptiveName(descriptiveName), m_icao(icao), m_position(position)
|
||||
{ }
|
||||
|
||||
QString CAirport::getLocationPlusOptionalName() const
|
||||
{
|
||||
if (m_location.isEmpty()) { return this->getDescriptiveName(); }
|
||||
if (m_descriptiveName.isEmpty()) { return this->getLocation(); }
|
||||
if (this->getDescriptiveName() == this->getLocation()) { return this->getLocation(); }
|
||||
return this->getLocation() % QStringLiteral(" (") % this->getDescriptiveName() % QStringLiteral(")");
|
||||
}
|
||||
|
||||
bool CAirport::matchesLocation(const QString &location) const
|
||||
{
|
||||
if (location.isEmpty()) { return false; }
|
||||
@@ -54,8 +63,8 @@ namespace BlackMisc
|
||||
|
||||
void CAirport::updateMissingParts(const CAirport &airport)
|
||||
{
|
||||
if (!this->m_country.hasIsoCode() && airport.getCountry().hasIsoCode()) { this->m_country = airport.getCountry(); }
|
||||
if (this->m_descriptiveName.isEmpty()) { this->m_descriptiveName = airport.getDescriptiveName(); }
|
||||
if (!m_country.hasIsoCode() && airport.getCountry().hasIsoCode()) { m_country = airport.getCountry(); }
|
||||
if (m_descriptiveName.isEmpty()) { m_descriptiveName = airport.getDescriptiveName(); }
|
||||
}
|
||||
|
||||
bool CAirport::isNull() const
|
||||
@@ -66,10 +75,10 @@ namespace BlackMisc
|
||||
QString CAirport::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s = i18n ? QCoreApplication::translate("Aviation", "Airport") : "Airport";
|
||||
if (!this->m_icao.isEmpty()) { s.append(' ').append(this->m_icao.toQString(i18n)); }
|
||||
if (!m_icao.isEmpty()) { s.append(' ').append(m_icao.toQString(i18n)); }
|
||||
|
||||
// position
|
||||
s.append(' ').append(this->m_position.toQString(i18n));
|
||||
s.append(' ').append(m_position.toQString(i18n));
|
||||
return s;
|
||||
|
||||
// force strings for translation in resource files
|
||||
@@ -102,18 +111,12 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
return this->m_icao.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexLocation:
|
||||
return CVariant(this->m_location);
|
||||
case IndexDescriptiveName:
|
||||
return CVariant(this->m_descriptiveName);
|
||||
case IndexPosition:
|
||||
return this->m_position.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexElevation:
|
||||
return this->getElevation().propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexOperating:
|
||||
return CVariant::from(this->isOperating());
|
||||
case IndexIcao: return m_icao.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexLocation: return CVariant(m_location);
|
||||
case IndexDescriptiveName: return CVariant(m_descriptiveName);
|
||||
case IndexPosition: return m_position.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexElevation: return this->getElevation().propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexOperating: return CVariant::from(this->isOperating());
|
||||
default:
|
||||
return (ICoordinateWithRelativePosition::canHandleIndex(index)) ?
|
||||
ICoordinateWithRelativePosition::propertyByIndex(index) :
|
||||
@@ -128,7 +131,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
this->m_icao.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
m_icao.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexLocation:
|
||||
this->setLocation(variant.toQString());
|
||||
@@ -137,7 +140,7 @@ namespace BlackMisc
|
||||
this->setDescriptiveName(variant.toQString());
|
||||
break;
|
||||
case IndexPosition:
|
||||
this->m_position.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
m_position.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexOperating:
|
||||
this->setOperating(variant.toBool());
|
||||
@@ -157,16 +160,13 @@ namespace BlackMisc
|
||||
|
||||
int CAirport::comparePropertyByIndex(const CPropertyIndex &index, const CAirport &compareValue) const
|
||||
{
|
||||
if (index.isMyself()) { return this->m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao()); }
|
||||
if (index.isMyself()) { return m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao()); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
return this->m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao());
|
||||
case IndexLocation:
|
||||
return this->m_location.compare(compareValue.getLocation(), Qt::CaseInsensitive);
|
||||
case IndexDescriptiveName:
|
||||
return this->m_descriptiveName.compare(compareValue.getDescriptiveName(), Qt::CaseInsensitive);
|
||||
case IndexIcao: return m_icao.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getIcao());
|
||||
case IndexLocation: return m_location.compare(compareValue.getLocation(), Qt::CaseInsensitive);
|
||||
case IndexDescriptiveName: return m_descriptiveName.compare(compareValue.getDescriptiveName(), Qt::CaseInsensitive);
|
||||
default:
|
||||
if (ICoordinateWithRelativePosition::canHandleIndex(index))
|
||||
{
|
||||
|
||||
@@ -77,6 +77,9 @@ namespace BlackMisc
|
||||
//! Get location (e.g. "London")
|
||||
const QString &getLocation() const { return m_location; }
|
||||
|
||||
//! Location plus optional name (if available and different from location)
|
||||
QString getLocationPlusOptionalName() const;
|
||||
|
||||
//! Set location
|
||||
void setLocation(const QString &location) { this->m_location = location; }
|
||||
|
||||
|
||||
@@ -104,11 +104,26 @@ namespace BlackMisc
|
||||
|
||||
QStringList CAirportList::allLocations(bool sorted) const
|
||||
{
|
||||
QStringList locations;
|
||||
QSet<QString> locations;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getLocation().isEmpty()) { continue; }
|
||||
locations.push_back(airport.getLocation());
|
||||
locations.insert(airport.getLocation());
|
||||
}
|
||||
|
||||
QStringList locs = locations.toList();
|
||||
if (sorted) { locs.sort(); }
|
||||
return locs;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allLocationsPlusOptionalDescription(bool sorted) const
|
||||
{
|
||||
QStringList locations;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
const QString l = airport.getLocationPlusOptionalName();
|
||||
if (l.isEmpty()) { continue; }
|
||||
locations.push_back(l);
|
||||
}
|
||||
if (sorted) { locations.sort(); }
|
||||
return locations;
|
||||
|
||||
@@ -30,9 +30,9 @@ namespace BlackMisc
|
||||
//! Value object for a list of airports.
|
||||
class BLACKMISC_EXPORT CAirportList :
|
||||
public CSequence<CAirport>,
|
||||
public BlackMisc::Db::IDatastoreObjectList<CAirport, CAirportList, int>,
|
||||
public BlackMisc::Geo::IGeoObjectWithRelativePositionList<CAirport, CAirportList>,
|
||||
public BlackMisc::Mixin::MetaType<CAirportList>
|
||||
public Db::IDatastoreObjectList<CAirport, CAirportList, int>,
|
||||
public Geo::IGeoObjectWithRelativePositionList<CAirport, CAirportList>,
|
||||
public Mixin::MetaType<CAirportList>
|
||||
{
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CAirportList)
|
||||
@@ -67,9 +67,13 @@ namespace BlackMisc
|
||||
//! All names
|
||||
QStringList allDescriptivesNames(bool sorted) const;
|
||||
|
||||
//! All names
|
||||
//! All locations
|
||||
//! \remark less locations than airports, since a location (e.g. New Yorrk) homes multiple airports
|
||||
QStringList allLocations(bool sorted) const;
|
||||
|
||||
//! All locations plus optional description
|
||||
QStringList allLocationsPlusOptionalDescription(bool sorted) const;
|
||||
|
||||
//! From our DB JSON
|
||||
static CAirportList fromDatabaseJson(const QJsonArray &array, CAirportList *inconsistent = nullptr);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user