mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
refs #641, using IOrderable and some formatting
This commit is contained in:
@@ -105,6 +105,8 @@ namespace BlackMisc
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); }
|
||||
if (IOrderable::canHandleIndex(index)) { return IOrderable::propertyByIndex(index);}
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -152,6 +154,9 @@ namespace BlackMisc
|
||||
void CAircraftModel::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAircraftModel>(); return; }
|
||||
if (IOrderable::canHandleIndex(index)) { IOrderable::setPropertyByIndex(variant, index); return; }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -207,6 +212,7 @@ namespace BlackMisc
|
||||
int CAircraftModel::comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(compareValue, index);}
|
||||
if (IOrderable::canHandleIndex(index)) { return IOrderable::comparePropertyByIndex(compareValue, index);}
|
||||
if (index.isMyself()) { return this->m_modelString.compare(compareValue.getModelString(), Qt::CaseInsensitive); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
@@ -291,6 +297,31 @@ namespace BlackMisc
|
||||
this->getLivery().isMilitary();
|
||||
}
|
||||
|
||||
bool CAircraftModel::updateDistributorOrder(const CDistributorList &distributors)
|
||||
{
|
||||
if (distributors.isEmpty()) { return false; }
|
||||
bool found = false;
|
||||
const int noDistributorOrder = distributors.size();
|
||||
if (this->hasDistributor())
|
||||
{
|
||||
const CDistributor d = distributors.findByKeyOrAlias(this->m_distributor.getDbKey());
|
||||
if (d.hasValidDbKey())
|
||||
{
|
||||
this->m_distributor.setOrder(d.getOrder());
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_distributor.setOrder(noDistributorOrder);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_distributor.setOrder(noDistributorOrder);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
bool CAircraftModel::hasDistributor() const
|
||||
{
|
||||
return this->m_distributor.hasValidDbKey();
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace BlackMisc
|
||||
//! \remarks Simulator independent class, supposed to be common denominator
|
||||
class BLACKMISC_EXPORT CAircraftModel :
|
||||
public CValueObject<CAircraftModel>,
|
||||
public BlackMisc::IDatastoreObjectWithIntegerKey
|
||||
public BlackMisc::IDatastoreObjectWithIntegerKey,
|
||||
public BlackMisc::IOrderable
|
||||
{
|
||||
public:
|
||||
//! Model type
|
||||
@@ -187,6 +188,9 @@ namespace BlackMisc
|
||||
//! Set distributor
|
||||
void setDistributor(const CDistributor &distributor) { m_distributor = distributor; }
|
||||
|
||||
//! Update distributor`s order attribute
|
||||
bool updateDistributorOrder(const CDistributorList &distributors);
|
||||
|
||||
//! Distributor
|
||||
bool hasDistributor() const;
|
||||
|
||||
|
||||
@@ -469,6 +469,17 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CAircraftModelList::updateDistributorOrder(const CDistributorList &distributors)
|
||||
{
|
||||
if (distributors.isEmpty()) { return 0; }
|
||||
int found = 0;
|
||||
for (CAircraftModel &model : *this)
|
||||
{
|
||||
if (model.updateDistributorOrder(distributors)) { found ++; }
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
QStringList CAircraftModelList::toCompleterStrings(bool sorted) const
|
||||
{
|
||||
QStringList c;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "blackmisc/datastoreobjectlist.h"
|
||||
#include "blackmisc/orderablelist.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
|
||||
@@ -27,6 +28,7 @@ namespace BlackMisc
|
||||
class BLACKMISC_EXPORT CAircraftModelList :
|
||||
public CSequence<CAircraftModel>,
|
||||
public IDatastoreObjectList<CAircraftModel, CAircraftModelList, int>,
|
||||
public IOrderableList<CAircraftModel, CAircraftModelList>,
|
||||
public BlackMisc::Mixin::MetaType<CAircraftModelList>
|
||||
{
|
||||
public:
|
||||
@@ -165,6 +167,9 @@ namespace BlackMisc
|
||||
//! Update livery
|
||||
void updateLivery(const BlackMisc::Aviation::CLivery &livery);
|
||||
|
||||
//! From given CDistributorList update the model`s distributor order
|
||||
int updateDistributorOrder(const CDistributorList &distributors);
|
||||
|
||||
//! Completer strings
|
||||
QStringList toCompleterStrings(bool sorted = true) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user