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