mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Allow to find and select the default distributors
This commit is contained in:
@@ -47,6 +47,19 @@ namespace BlackMisc
|
||||
return this->container().findFirstByOrDefault(&OBJ::getDbKey, key, notFound);
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
CONTAINER IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::findByKeys(const QSet<KEYTYPE> &keys) const
|
||||
{
|
||||
CONTAINER objects;
|
||||
if (keys.isEmpty()) { return objects; }
|
||||
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||
{
|
||||
if (!keys.contains(obj.getDbKey())) { continue; }
|
||||
objects.push_back(obj);
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
CONTAINER IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::findObjectsWithDbKey() const
|
||||
{
|
||||
|
||||
@@ -30,6 +30,9 @@ namespace BlackMisc
|
||||
//! Object with key, notFound otherwise
|
||||
OBJ findByKey(KEYTYPE key, const OBJ ¬Found = OBJ()) const;
|
||||
|
||||
//! Object with key, notFound otherwise
|
||||
CONTAINER findByKeys(const QSet<KEYTYPE> &keys) const;
|
||||
|
||||
//! Objects with DB key
|
||||
CONTAINER findObjectsWithDbKey() const;
|
||||
|
||||
|
||||
@@ -183,5 +183,41 @@ namespace BlackMisc
|
||||
distributor.setLoadedFromDb(true);
|
||||
return distributor;
|
||||
}
|
||||
|
||||
const QString &CDistributor::standardFSX()
|
||||
{
|
||||
static const QString k("FSX");
|
||||
return k;
|
||||
}
|
||||
|
||||
const QString &CDistributor::standardP3D()
|
||||
{
|
||||
static const QString k("P3D");
|
||||
return k;
|
||||
}
|
||||
|
||||
const QString &CDistributor::standardFS9()
|
||||
{
|
||||
static const QString k("FS9");
|
||||
return k;
|
||||
}
|
||||
|
||||
const QString &CDistributor::standardXPlane()
|
||||
{
|
||||
static const QString k("XP");
|
||||
return k;
|
||||
}
|
||||
|
||||
const QString &CDistributor::standardFlightGear()
|
||||
{
|
||||
static const QString k("FG");
|
||||
return k;
|
||||
}
|
||||
|
||||
const QSet<QString> &CDistributor::standardAllFsFamily()
|
||||
{
|
||||
static const QSet<QString> fsFamily({standardFS9(), standardFSX(), standardP3D()});
|
||||
return fsFamily;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QMetaType>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -125,6 +126,15 @@ namespace BlackMisc
|
||||
//! Object from JSON
|
||||
static CDistributor fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
|
||||
|
||||
//! Hardcoded keys for standard models @{
|
||||
static const QString &standardFSX();
|
||||
static const QString &standardP3D();
|
||||
static const QString &standardFS9();
|
||||
static const QString &standardXPlane();
|
||||
static const QString &standardFlightGear();
|
||||
static const QSet<QString> &standardAllFsFamily();
|
||||
//! @}
|
||||
|
||||
private:
|
||||
QString m_description; //!< description
|
||||
QString m_alias1; //!< alias name
|
||||
|
||||
@@ -46,6 +46,11 @@ namespace BlackMisc
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
CDistributorList CDistributorList::findFsFamilyStandard() const
|
||||
{
|
||||
return this->findByKeys(CDistributor::standardAllFsFamily());
|
||||
}
|
||||
|
||||
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
|
||||
@@ -100,7 +105,7 @@ namespace BlackMisc
|
||||
return sl;
|
||||
}
|
||||
|
||||
CDistributorList CDistributorList::matchesSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) const
|
||||
CDistributorList CDistributorList::matchesSimulator(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
if (this->isEmpty()) { return CDistributorList(); }
|
||||
CDistributorList distributors;
|
||||
@@ -114,6 +119,11 @@ namespace BlackMisc
|
||||
return distributors;
|
||||
}
|
||||
|
||||
CDistributorList CDistributorList::matchesAnyFsFamily() const
|
||||
{
|
||||
return matchesSimulator(CSimulatorInfo::AllFsFamily);
|
||||
}
|
||||
|
||||
bool CDistributorList::isCompletelyFromDb() const
|
||||
{
|
||||
return !this->contains(&CDistributor::isLoadedFromDb, false);
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace BlackMisc
|
||||
//! \remark model strings may have a pattern which makes it impossible to find the distributor
|
||||
CDistributor findByModelData(const CAircraftModel &model) const;
|
||||
|
||||
//! Find the FS family standard distributors
|
||||
CDistributorList findFsFamilyStandard() const;
|
||||
|
||||
//! Best match by given pattern
|
||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern) const;
|
||||
|
||||
@@ -68,6 +71,9 @@ namespace BlackMisc
|
||||
//! Find for given simulator
|
||||
CDistributorList matchesSimulator(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Find all for all FS simulators
|
||||
CDistributorList matchesAnyFsFamily() const;
|
||||
|
||||
//! All data from DB?
|
||||
bool isCompletelyFromDb() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user