mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #720, improved distributor and airline/livery detection
* mark data read from DB (req. for string key where existing key value is not reliable indicator for DB data) * detect distributors by part of model string * use a simplified name (no spaces, no special characters) to find a match * allow to obtain model strings (=keys) as set and list
This commit is contained in:
committed by
Mathew Sutcliffe
parent
39dae7ed45
commit
f9922353c4
@@ -372,6 +372,7 @@ namespace BlackMisc
|
||||
|
||||
bool CAircraftModel::matchesMode(ModelModeFilter mode) const
|
||||
{
|
||||
if (mode == All) { return true; }
|
||||
return (mode & this->m_modelMode) > 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ namespace BlackMisc
|
||||
return addOrReplaceList.size();
|
||||
}
|
||||
CAircraftModelList newModels(*this);
|
||||
const QStringList keys(addOrReplaceList.getModelStrings(false));
|
||||
const QStringList keys(addOrReplaceList.getModelStringList(false));
|
||||
newModels.removeModelsWithString(keys, sensitivity);
|
||||
int removed = newModels.size(); // size after removing
|
||||
newModels.push_back(addOrReplaceList);
|
||||
@@ -398,7 +398,7 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
QStringList CAircraftModelList::getModelStrings(bool sort) const
|
||||
QStringList CAircraftModelList::getModelStringList(bool sort) const
|
||||
{
|
||||
QStringList ms;
|
||||
for (const CAircraftModel &model : (*this))
|
||||
@@ -410,6 +410,17 @@ namespace BlackMisc
|
||||
return ms;
|
||||
}
|
||||
|
||||
QSet<QString> CAircraftModelList::getModelStringSet() const
|
||||
{
|
||||
QSet<QString> ms;
|
||||
for (const CAircraftModel &model : (*this))
|
||||
{
|
||||
if (!model.hasModelString()) { continue; }
|
||||
ms.insert(model.getModelString());
|
||||
}
|
||||
return ms;
|
||||
}
|
||||
|
||||
CCountPerSimulator CAircraftModelList::countPerSimulator() const
|
||||
{
|
||||
CCountPerSimulator count;
|
||||
|
||||
@@ -166,7 +166,10 @@ namespace BlackMisc
|
||||
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity);
|
||||
|
||||
//! Model strings
|
||||
QStringList getModelStrings(bool sort = true) const;
|
||||
QStringList getModelStringList(bool sort = true) const;
|
||||
|
||||
//! Model strings as set
|
||||
QSet<QString> getModelStringSet() const;
|
||||
|
||||
//! Simulator counts
|
||||
CCountPerSimulator countPerSimulator() const;
|
||||
@@ -204,9 +207,8 @@ namespace BlackMisc
|
||||
//! To database JSON
|
||||
QString toDatabaseJsonString(QJsonDocument::JsonFormat format = QJsonDocument::Compact) const;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
} // namespace
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftModelList)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CAircraftModel>)
|
||||
|
||||
@@ -178,6 +178,7 @@ namespace BlackMisc
|
||||
Q_ASSERT_X(!description.isEmpty(), Q_FUNC_INFO, "Missing description");
|
||||
CDistributor distributor("", description, alias1, alias2, simulator);
|
||||
distributor.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||
distributor.setLoadedFromDb(true);
|
||||
return distributor;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -130,6 +130,7 @@ namespace BlackMisc
|
||||
BLACK_METACLASS(
|
||||
CDistributor,
|
||||
BLACK_METAMEMBER(dbKey, 0, CaseInsensitiveComparison),
|
||||
BLACK_METAMEMBER(loadedFromDb),
|
||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch),
|
||||
BLACK_METAMEMBER(order),
|
||||
BLACK_METAMEMBER(description),
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "distributorlist.h"
|
||||
#include "simulatorinfo.h"
|
||||
#include "aircraftmodel.h"
|
||||
#include "blackmisc/metaclassprivate.h"
|
||||
|
||||
#include <tuple>
|
||||
@@ -32,20 +34,40 @@ namespace BlackMisc
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
CDistributor CDistributorList::smartDistributorSelector(const CDistributor &distributorPattern) const
|
||||
CDistributor CDistributorList::findByModelData(const CAircraftModel &model) const
|
||||
{
|
||||
if (distributorPattern.hasValidDbKey())
|
||||
// some stuipd hardcoded resolutions
|
||||
if (model.getDistributor().hasValidDbKey()) { return model.getDistributor(); }
|
||||
if (model.getModelString().startsWith("WOA", Qt::CaseInsensitive)) { return this->findByKeyOrAlias("WOAI"); }
|
||||
if (model.getDescription().contains("WOA", Qt::CaseInsensitive)) { return this->findByKeyOrAlias("WOAI"); }
|
||||
if (model.getDescription().contains("IVAO", Qt::CaseInsensitive)) { return this->findByKeyOrAlias("IVAO"); }
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
CDistributor CDistributorList::smartDistributorSelector(const CDistributor &distributor) const
|
||||
{
|
||||
// key is not necessarily a DB key, so use complete data, happens when key is set from raw data
|
||||
if (distributor.isLoadedFromDb()) { return distributor; }
|
||||
if (distributor.hasValidDbKey())
|
||||
{
|
||||
QString k(distributorPattern.getDbKey());
|
||||
CDistributor d(this->findByKey(k));
|
||||
const QString key(distributor.getDbKey());
|
||||
CDistributor d(this->findByKey(key));
|
||||
if (d.hasCompleteData()) { return d; }
|
||||
|
||||
// more lenient search
|
||||
return this->findByKeyOrAlias(k);
|
||||
return this->findByKeyOrAlias(key);
|
||||
}
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
CDistributor CDistributorList::smartDistributorSelector(const CDistributor &distributorPattern, const CAircraftModel &model) const
|
||||
{
|
||||
const CDistributor d = this->smartDistributorSelector(distributorPattern);
|
||||
// key is not necessarily a DB key, so use complete data, happens when key is set from raw data
|
||||
if (d.hasCompleteData()) { return d; }
|
||||
return this->findByModelData(model);
|
||||
}
|
||||
|
||||
bool CDistributorList::matchesAnyKeyOrAlias(const QString &keyOrAlias) const
|
||||
{
|
||||
for (const CDistributor &distributor : (*this))
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "blackmisc/orderablelist.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/simulation/distributor.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMetaType>
|
||||
@@ -29,6 +28,8 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
class CSimulatorModel;
|
||||
|
||||
//! Value object encapsulating a list of distributors.
|
||||
class BLACKMISC_EXPORT CDistributorList :
|
||||
public BlackMisc::CSequence<CDistributor>,
|
||||
@@ -48,9 +49,16 @@ namespace BlackMisc
|
||||
//! Find by id or alias
|
||||
CDistributor findByKeyOrAlias(const QString &keyOrAlias) const;
|
||||
|
||||
//! Find by model string
|
||||
//! \remark model strings may have a pattern which makes it impossible to find the distributor
|
||||
CDistributor findByModelData(const CAircraftModel &model) const;
|
||||
|
||||
//! Best match by given pattern
|
||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern) const;
|
||||
|
||||
//! Best match by given pattern
|
||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern, const CAircraftModel &model) const;
|
||||
|
||||
//! At least is matching key or alias
|
||||
bool matchesAnyKeyOrAlias(const QString &keyOrAlias) const;
|
||||
|
||||
@@ -58,7 +66,7 @@ namespace BlackMisc
|
||||
QStringList getDbKeysAndAliases(bool sort) const;
|
||||
|
||||
//! Find for given simulator
|
||||
CDistributorList matchesSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
CDistributorList matchesSimulator(const CSimulatorInfo &simulator) const;
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user