mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 10:57:01 +08:00
refs #787, utility functions for shared files
* entity to shared file, shared file for DB Info * CUrl path function * removed redundant code in CDbInfo::getEntity() and fixed CEntityFlags::singleEntityByName
This commit is contained in:
@@ -33,15 +33,27 @@ namespace BlackMisc
|
||||
CEntityFlags::Entity CDbInfo::getEntity() const
|
||||
{
|
||||
if (this->m_entity != CEntityFlags::NoEntity) { return this->m_entity; }
|
||||
if (this->m_tableName.isEmpty()) { return CEntityFlags::NoEntity; }
|
||||
if (this->m_tableName.contains("airport", Qt::CaseInsensitive)) { return CEntityFlags::AirportEntity; }
|
||||
if (this->m_tableName.contains("airlineicao", Qt::CaseInsensitive)) { return CEntityFlags::AirlineIcaoEntity; }
|
||||
if (this->m_tableName.contains("aircrafticao", Qt::CaseInsensitive)) { return CEntityFlags::AircraftIcaoEntity; }
|
||||
if (this->m_tableName.contains("livery", Qt::CaseInsensitive)) { return CEntityFlags::LiveryEntity; }
|
||||
if (this->m_tableName.contains("aircraftmodel", Qt::CaseInsensitive)) { return CEntityFlags::ModelEntity; }
|
||||
if (this->m_tableName.contains("country", Qt::CaseInsensitive)) { return CEntityFlags::CountryEntity; }
|
||||
if (this->m_tableName.contains("distributor", Qt::CaseInsensitive)) { return CEntityFlags::DistributorEntity; }
|
||||
return CEntityFlags::NoEntity;
|
||||
const QString tn(this->getTableName());
|
||||
return CEntityFlags::singleEntityByName(tn);
|
||||
}
|
||||
|
||||
const QString &CDbInfo::getSharedFileName() const
|
||||
{
|
||||
static const QString empty;
|
||||
CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
||||
switch (entity)
|
||||
{
|
||||
case CEntityFlags::AircraftIcaoEntity: { return sharedFileNames().at(0); }
|
||||
case CEntityFlags::AirlineIcaoEntity: { return sharedFileNames().at(1); }
|
||||
case CEntityFlags::AirportEntity: { return sharedFileNames().at(2); }
|
||||
case CEntityFlags::CountryEntity: { return sharedFileNames().at(3); }
|
||||
case CEntityFlags::DistributorEntity: { return sharedFileNames().at(4); }
|
||||
case CEntityFlags::LiveryEntity: { return sharedFileNames().at(5); }
|
||||
case CEntityFlags::ModelEntity: { return sharedFileNames().at(6); }
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
void CDbInfo::setEntity(CEntityFlags::Entity entity)
|
||||
@@ -142,6 +154,29 @@ namespace BlackMisc
|
||||
dbInfo.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||
return dbInfo;
|
||||
}
|
||||
|
||||
const QStringList &CDbInfo::sharedFileNames()
|
||||
{
|
||||
static const QStringList names({"aircrafticao.json", "airlineicao.json", "airports.json", "countries.json", "distributors.json", "liveries.json", "models.json" });
|
||||
return names;
|
||||
}
|
||||
|
||||
const QString &CDbInfo::entityToSharedFileName(CEntityFlags::Entity entity)
|
||||
{
|
||||
static const QString empty;
|
||||
switch (entity)
|
||||
{
|
||||
case CEntityFlags::AircraftIcaoEntity: return sharedFileNames().at(0);
|
||||
case CEntityFlags::AirlineIcaoEntity: return sharedFileNames().at(1);
|
||||
case CEntityFlags::AirportEntity: return sharedFileNames().at(2);
|
||||
case CEntityFlags::CountryEntity: return sharedFileNames().at(3);
|
||||
case CEntityFlags::DistributorEntity: return sharedFileNames().at(4);
|
||||
case CEntityFlags::LiveryEntity: return sharedFileNames().at(5);
|
||||
case CEntityFlags::ModelEntity: return sharedFileNames().at(6);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ namespace BlackMisc
|
||||
//! Get entity (based on table name
|
||||
Network::CEntityFlags::Entity getEntity() const;
|
||||
|
||||
//! The shared file name such as "airports.json"
|
||||
const QString &getSharedFileName() const;
|
||||
|
||||
//! Set entity, should be in sync with a corresponding table name
|
||||
void setEntity(Network::CEntityFlags::Entity entity);
|
||||
|
||||
@@ -83,6 +86,12 @@ namespace BlackMisc
|
||||
//! From our database JSON format
|
||||
static CDbInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
|
||||
|
||||
//! The shared file names
|
||||
static const QStringList &sharedFileNames();
|
||||
|
||||
//! Get shared file name
|
||||
static const QString &entityToSharedFileName(Network::CEntityFlags::Entity entity);
|
||||
|
||||
private:
|
||||
QString m_tableName; //!< table name
|
||||
int m_entries; //!< number of entries
|
||||
|
||||
@@ -144,12 +144,13 @@ namespace BlackMisc
|
||||
|
||||
CEntityFlags::Entity CEntityFlags::singleEntityByName(const QString &name)
|
||||
{
|
||||
// order here is crucial
|
||||
if (name.contains("model", Qt::CaseInsensitive)) { return ModelEntity; }
|
||||
if (name.contains("aircraft", Qt::CaseInsensitive)) { return AircraftIcaoEntity; }
|
||||
if (name.contains("airline", Qt::CaseInsensitive)) { return AirlineIcaoEntity; }
|
||||
if (name.contains("airport", Qt::CaseInsensitive)) { return AirportEntity; }
|
||||
if (name.contains("distributor", Qt::CaseInsensitive)) { return DistributorEntity; }
|
||||
if (name.contains("countr", Qt::CaseInsensitive)) { return CountryEntity; }
|
||||
if (name.contains("model", Qt::CaseInsensitive)) { return ModelEntity; }
|
||||
if (name.contains("liver", Qt::CaseInsensitive)) { return LiveryEntity; }
|
||||
return NoEntity;
|
||||
}
|
||||
|
||||
@@ -161,6 +161,11 @@ namespace BlackMisc
|
||||
return url;
|
||||
}
|
||||
|
||||
bool CUrl::pathEndsWith(const QString ending, Qt::CaseSensitivity cs) const
|
||||
{
|
||||
return m_path.endsWith(ending, cs);
|
||||
}
|
||||
|
||||
CUrl CUrl::withAppendedQuery(const QString &query) const
|
||||
{
|
||||
if (query.isEmpty()) { return *this; }
|
||||
|
||||
@@ -133,6 +133,9 @@ namespace BlackMisc
|
||||
//! Switch protocol
|
||||
CUrl withSwitchedScheme(const QString &protocol, int port) const;
|
||||
|
||||
//! Path ending with?
|
||||
bool pathEndsWith(const QString ending, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user