mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
This commit is contained in:
@@ -95,6 +95,21 @@ namespace BlackMisc
|
||||
return delta;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
int IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::removeObjectsWithoutDbKey()
|
||||
{
|
||||
if (this->container().isEmpty()) { return 0; }
|
||||
CONTAINER newValues;
|
||||
for (const OBJ &obj : ITimestampObjectList<OBJ, CONTAINER>::container())
|
||||
{
|
||||
if (!obj.hasValidDbKey()) { continue; }
|
||||
newValues.push_back(obj);
|
||||
}
|
||||
int delta = this->container().size() - newValues.size();
|
||||
this->container() = newValues;
|
||||
return delta;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
int IDatastoreObjectList<OBJ, CONTAINER, KEYTYPE>::replaceOrAddObjectsByKey(const CONTAINER &container)
|
||||
{
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace BlackMisc
|
||||
//! Remove objects with key
|
||||
int removeObjectsWithKeys(const QList<KEYTYPE> &keys);
|
||||
|
||||
//! Remove objects without key
|
||||
int removeObjectsWithoutDbKey();
|
||||
|
||||
//! Update or insert data (based on DB key)
|
||||
int replaceOrAddObjectsByKey(const CONTAINER &container);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "aircraftmodel.h"
|
||||
#include "distributor.h"
|
||||
#include "distributorlist.h"
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include <QString>
|
||||
@@ -276,6 +276,25 @@ namespace BlackMisc
|
||||
return this->m_livery.hasValidAirlineDesignator();
|
||||
}
|
||||
|
||||
bool CAircraftModel::hasDistributor() const
|
||||
{
|
||||
return this->m_distributor.hasValidDbKey();
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesDistributor(const CDistributor &distributor) const
|
||||
{
|
||||
if (!distributor.hasValidDbKey()) { return false; }
|
||||
if (!this->hasDistributor()) { return false; }
|
||||
return this->m_distributor.getDbKey() == distributor.getDbKey();
|
||||
}
|
||||
|
||||
bool CAircraftModel::matchesAnyDistributor(const CDistributorList &distributors) const
|
||||
{
|
||||
if (distributors.isEmpty()) { return false; }
|
||||
if (!this->hasDistributor()) { return false; }
|
||||
return distributors.matchesAnyKeyOrAlias(this->m_distributor.getDbKey());
|
||||
}
|
||||
|
||||
const CIcon &CAircraftModel::getModelModeAsIcon() const
|
||||
{
|
||||
switch (this->getModelMode())
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/simulation/distributor.h"
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include "blackmisc/network/user.h"
|
||||
@@ -174,6 +174,15 @@ namespace BlackMisc
|
||||
//! Set distributor
|
||||
void setDistributor(const CDistributor &distributor) { m_distributor = distributor; }
|
||||
|
||||
//! Distributor
|
||||
bool hasDistributor() const;
|
||||
|
||||
//! By distributor
|
||||
bool matchesDistributor(const CDistributor &distributor) const;
|
||||
|
||||
//! By distributor
|
||||
bool matchesAnyDistributor(const CDistributorList &distributors) const;
|
||||
|
||||
//! Name
|
||||
const QString &getName() const { return this->m_name; }
|
||||
|
||||
@@ -273,13 +282,13 @@ namespace BlackMisc
|
||||
BlackMisc::Aviation::CAircraftIcaoCode m_aircraftIcao; //!< ICAO code if available
|
||||
BlackMisc::Aviation::CLivery m_livery; //!< livery information
|
||||
CSimulatorInfo m_simulator; //!< model for given simulator
|
||||
CDistributor m_distributor; //!< who designed or distributed the model
|
||||
QString m_modelString; //!< Simulator model key, unique
|
||||
QString m_name; //!< Model name
|
||||
QString m_description; //!< descriptive text
|
||||
QString m_fileName; //!< file name
|
||||
ModelType m_modelType = TypeUnknown; //!< model string is coming representing ...?
|
||||
ModelMode m_modelMode = Include; //!< model mode (include / exclude)
|
||||
CDistributor m_distributor; //!< who designed or distributed the model
|
||||
QString m_modelString; //!< Simulator model key, unique
|
||||
QString m_name; //!< Model name
|
||||
QString m_description; //!< descriptive text
|
||||
QString m_fileName; //!< file name
|
||||
ModelType m_modelType = TypeUnknown; //!< model string is coming representing ...?
|
||||
ModelMode m_modelMode = Include; //!< model mode (include / exclude)
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "blackmisc/datastoreobjectlist.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace BlackMisc
|
||||
CSequence<CDistributor>(other)
|
||||
{ }
|
||||
|
||||
CDistributor CDistributorList::findByKeyOrAlias(const QString &keyOrAlias)
|
||||
CDistributor CDistributorList::findByKeyOrAlias(const QString &keyOrAlias) const
|
||||
{
|
||||
if (keyOrAlias.isEmpty()) { return CDistributor(); }
|
||||
for (const CDistributor &distributor : (*this))
|
||||
@@ -44,6 +44,15 @@ namespace BlackMisc
|
||||
return CDistributor();
|
||||
}
|
||||
|
||||
bool CDistributorList::matchesAnyKeyOrAlias(const QString &keyOrAlias) const
|
||||
{
|
||||
for (const CDistributor &distributor : (*this))
|
||||
{
|
||||
if (distributor.matchesKeyOrAlias(keyOrAlias)) { return true; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList CDistributorList::getDbKeysAndAliases() const
|
||||
{
|
||||
if (this->isEmpty()) { return QStringList(); }
|
||||
|
||||
@@ -41,11 +41,14 @@ namespace BlackMisc
|
||||
CDistributorList(const CSequence<CDistributor> &other);
|
||||
|
||||
//! Find by id or alias
|
||||
CDistributor findByKeyOrAlias(const QString &keyOrAlias);
|
||||
CDistributor findByKeyOrAlias(const QString &keyOrAlias) const;
|
||||
|
||||
//! Best match by given pattern
|
||||
CDistributor smartDistributorSelector(const CDistributor &distributorPattern);
|
||||
|
||||
//! At least is matching key or alias
|
||||
bool matchesAnyKeyOrAlias(const QString &keyOrAlias) const;
|
||||
|
||||
//! All DB keys and aliases
|
||||
QStringList getDbKeysAndAliases() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user