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

@@ -84,12 +84,7 @@ namespace BlackMisc
void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index)
{ {
if (ITimestampBased::canHandleIndex(index)) if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; }
{
ITimestampBased::setPropertyByIndex(variant, index);
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
@@ -152,7 +147,7 @@ namespace BlackMisc
CVariant IDatastoreObjectWithStringKey::propertyByIndex(const CPropertyIndex &index) const CVariant IDatastoreObjectWithStringKey::propertyByIndex(const CPropertyIndex &index) const
{ {
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbStringKey: return CVariant::from(this->m_dbKey); case IndexDbStringKey: return CVariant::from(this->m_dbKey);
@@ -165,13 +160,8 @@ namespace BlackMisc
void IDatastoreObjectWithStringKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) void IDatastoreObjectWithStringKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index)
{ {
if (ITimestampBased::canHandleIndex(index)) if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; }
{ const ColumnIndex i = index.frontCasted<ColumnIndex>();
ITimestampBased::setPropertyByIndex(variant, index);
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbStringKey: case IndexDbStringKey:
@@ -185,7 +175,7 @@ namespace BlackMisc
int IDatastoreObjectWithStringKey::comparePropertyByIndex(const IDatastoreObjectWithStringKey &compareValue, const CPropertyIndex &index) const int IDatastoreObjectWithStringKey::comparePropertyByIndex(const IDatastoreObjectWithStringKey &compareValue, const CPropertyIndex &index) const
{ {
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(compareValue, index); } if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(compareValue, index); }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey()); case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey());

View File

@@ -105,6 +105,8 @@ namespace BlackMisc
{ {
if (index.isMyself()) { return CVariant::from(*this); } if (index.isMyself()) { return CVariant::from(*this); }
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); } if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); }
if (IOrderable::canHandleIndex(index)) { return IOrderable::propertyByIndex(index);}
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
@@ -152,6 +154,9 @@ namespace BlackMisc
void CAircraftModel::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) void CAircraftModel::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{ {
if (index.isMyself()) { (*this) = variant.to<CAircraftModel>(); return; } 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>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
@@ -207,6 +212,7 @@ namespace BlackMisc
int CAircraftModel::comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const int CAircraftModel::comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const
{ {
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(compareValue, index);} 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); } if (index.isMyself()) { return this->m_modelString.compare(compareValue.getModelString(), Qt::CaseInsensitive); }
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
@@ -291,6 +297,31 @@ namespace BlackMisc
this->getLivery().isMilitary(); 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 bool CAircraftModel::hasDistributor() const
{ {
return this->m_distributor.hasValidDbKey(); return this->m_distributor.hasValidDbKey();

View File

@@ -30,7 +30,8 @@ namespace BlackMisc
//! \remarks Simulator independent class, supposed to be common denominator //! \remarks Simulator independent class, supposed to be common denominator
class BLACKMISC_EXPORT CAircraftModel : class BLACKMISC_EXPORT CAircraftModel :
public CValueObject<CAircraftModel>, public CValueObject<CAircraftModel>,
public BlackMisc::IDatastoreObjectWithIntegerKey public BlackMisc::IDatastoreObjectWithIntegerKey,
public BlackMisc::IOrderable
{ {
public: public:
//! Model type //! Model type
@@ -187,6 +188,9 @@ namespace BlackMisc
//! Set distributor //! Set distributor
void setDistributor(const CDistributor &distributor) { m_distributor = distributor; } void setDistributor(const CDistributor &distributor) { m_distributor = distributor; }
//! Update distributor`s order attribute
bool updateDistributorOrder(const CDistributorList &distributors);
//! Distributor //! Distributor
bool hasDistributor() const; 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 CAircraftModelList::toCompleterStrings(bool sorted) const
{ {
QStringList c; QStringList c;

View File

@@ -16,6 +16,7 @@
#include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/distributorlist.h"
#include "blackmisc/datastoreobjectlist.h" #include "blackmisc/datastoreobjectlist.h"
#include "blackmisc/orderablelist.h"
#include "blackmisc/collection.h" #include "blackmisc/collection.h"
#include "blackmisc/sequence.h" #include "blackmisc/sequence.h"
@@ -27,6 +28,7 @@ namespace BlackMisc
class BLACKMISC_EXPORT CAircraftModelList : class BLACKMISC_EXPORT CAircraftModelList :
public CSequence<CAircraftModel>, public CSequence<CAircraftModel>,
public IDatastoreObjectList<CAircraftModel, CAircraftModelList, int>, public IDatastoreObjectList<CAircraftModel, CAircraftModelList, int>,
public IOrderableList<CAircraftModel, CAircraftModelList>,
public BlackMisc::Mixin::MetaType<CAircraftModelList> public BlackMisc::Mixin::MetaType<CAircraftModelList>
{ {
public: public:
@@ -165,6 +167,9 @@ namespace BlackMisc
//! Update livery //! Update livery
void updateLivery(const BlackMisc::Aviation::CLivery &livery); void updateLivery(const BlackMisc::Aviation::CLivery &livery);
//! From given CDistributorList update the model`s distributor order
int updateDistributorOrder(const CDistributorList &distributors);
//! Completer strings //! Completer strings
QStringList toCompleterStrings(bool sorted = true) const; QStringList toCompleterStrings(bool sorted = true) const;