mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +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);
|
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>
|
template<class OBJ, class CONTAINER, typename KEYTYPE>
|
||||||
CONTAINER IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::findObjectsWithDbKey() const
|
CONTAINER IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::findObjectsWithDbKey() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ namespace BlackMisc
|
|||||||
//! Object with key, notFound otherwise
|
//! Object with key, notFound otherwise
|
||||||
OBJ findByKey(KEYTYPE key, const OBJ ¬Found = OBJ()) const;
|
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
|
//! Objects with DB key
|
||||||
CONTAINER findObjectsWithDbKey() const;
|
CONTAINER findObjectsWithDbKey() const;
|
||||||
|
|
||||||
|
|||||||
@@ -183,5 +183,41 @@ namespace BlackMisc
|
|||||||
distributor.setLoadedFromDb(true);
|
distributor.setLoadedFromDb(true);
|
||||||
return distributor;
|
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
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -125,6 +126,15 @@ namespace BlackMisc
|
|||||||
//! Object from JSON
|
//! Object from JSON
|
||||||
static CDistributor fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
|
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:
|
private:
|
||||||
QString m_description; //!< description
|
QString m_description; //!< description
|
||||||
QString m_alias1; //!< alias name
|
QString m_alias1; //!< alias name
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ namespace BlackMisc
|
|||||||
return CDistributor();
|
return CDistributor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDistributorList CDistributorList::findFsFamilyStandard() const
|
||||||
|
{
|
||||||
|
return this->findByKeys(CDistributor::standardAllFsFamily());
|
||||||
|
}
|
||||||
|
|
||||||
CDistributor CDistributorList::smartDistributorSelector(const CDistributor &distributor) const
|
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
|
// 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;
|
return sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDistributorList CDistributorList::matchesSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) const
|
CDistributorList CDistributorList::matchesSimulator(const CSimulatorInfo &simulator) const
|
||||||
{
|
{
|
||||||
if (this->isEmpty()) { return CDistributorList(); }
|
if (this->isEmpty()) { return CDistributorList(); }
|
||||||
CDistributorList distributors;
|
CDistributorList distributors;
|
||||||
@@ -114,6 +119,11 @@ namespace BlackMisc
|
|||||||
return distributors;
|
return distributors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDistributorList CDistributorList::matchesAnyFsFamily() const
|
||||||
|
{
|
||||||
|
return matchesSimulator(CSimulatorInfo::AllFsFamily);
|
||||||
|
}
|
||||||
|
|
||||||
bool CDistributorList::isCompletelyFromDb() const
|
bool CDistributorList::isCompletelyFromDb() const
|
||||||
{
|
{
|
||||||
return !this->contains(&CDistributor::isLoadedFromDb, false);
|
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
|
//! \remark model strings may have a pattern which makes it impossible to find the distributor
|
||||||
CDistributor findByModelData(const CAircraftModel &model) const;
|
CDistributor findByModelData(const CAircraftModel &model) const;
|
||||||
|
|
||||||
|
//! Find the FS family standard distributors
|
||||||
|
CDistributorList findFsFamilyStandard() const;
|
||||||
|
|
||||||
//! Best match by given pattern
|
//! Best match by given pattern
|
||||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern) const;
|
CDistributor smartDistributorSelector(const CDistributor &distributorPattern) const;
|
||||||
|
|
||||||
@@ -68,6 +71,9 @@ namespace BlackMisc
|
|||||||
//! Find for given simulator
|
//! Find for given simulator
|
||||||
CDistributorList matchesSimulator(const CSimulatorInfo &simulator) const;
|
CDistributorList matchesSimulator(const CSimulatorInfo &simulator) const;
|
||||||
|
|
||||||
|
//! Find all for all FS simulators
|
||||||
|
CDistributorList matchesAnyFsFamily() const;
|
||||||
|
|
||||||
//! All data from DB?
|
//! All data from DB?
|
||||||
bool isCompletelyFromDb() const;
|
bool isCompletelyFromDb() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user