refs #641, using IOrderable and some formatting

This commit is contained in:
Klaus Basan
2016-04-23 02:15:39 +02:00
parent a9c6fe2036
commit 1bb6f98e56
5 changed files with 57 additions and 16 deletions

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;