From 1bb6f98e56987a44a2c9a9c0b274c04fa6d5360f Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 23 Apr 2016 02:15:39 +0200 Subject: [PATCH] refs #641, using IOrderable and some formatting --- src/blackmisc/datastore.cpp | 20 +++--------- src/blackmisc/simulation/aircraftmodel.cpp | 31 +++++++++++++++++++ src/blackmisc/simulation/aircraftmodel.h | 6 +++- .../simulation/aircraftmodellist.cpp | 11 +++++++ src/blackmisc/simulation/aircraftmodellist.h | 5 +++ 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/blackmisc/datastore.cpp b/src/blackmisc/datastore.cpp index 62da269ab..49ed97175 100644 --- a/src/blackmisc/datastore.cpp +++ b/src/blackmisc/datastore.cpp @@ -84,12 +84,7 @@ namespace BlackMisc void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) { - if (ITimestampBased::canHandleIndex(index)) - { - ITimestampBased::setPropertyByIndex(variant, index); - return; - } - + if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; } ColumnIndex i = index.frontCasted(); switch (i) { @@ -152,7 +147,7 @@ namespace BlackMisc CVariant IDatastoreObjectWithStringKey::propertyByIndex(const CPropertyIndex &index) const { if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexDbStringKey: return CVariant::from(this->m_dbKey); @@ -165,13 +160,8 @@ namespace BlackMisc void IDatastoreObjectWithStringKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) { - if (ITimestampBased::canHandleIndex(index)) - { - ITimestampBased::setPropertyByIndex(variant, index); - return; - } - - ColumnIndex i = index.frontCasted(); + if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; } + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexDbStringKey: @@ -185,7 +175,7 @@ namespace BlackMisc int IDatastoreObjectWithStringKey::comparePropertyByIndex(const IDatastoreObjectWithStringKey &compareValue, const CPropertyIndex &index) const { if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(compareValue, index); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey()); diff --git a/src/blackmisc/simulation/aircraftmodel.cpp b/src/blackmisc/simulation/aircraftmodel.cpp index 9378b51ed..cbfaeacdf 100644 --- a/src/blackmisc/simulation/aircraftmodel.cpp +++ b/src/blackmisc/simulation/aircraftmodel.cpp @@ -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(); switch (i) { @@ -152,6 +154,9 @@ namespace BlackMisc void CAircraftModel::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) { if (index.isMyself()) { (*this) = variant.to(); return; } + if (IOrderable::canHandleIndex(index)) { IOrderable::setPropertyByIndex(variant, index); return; } + if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; } + ColumnIndex i = index.frontCasted(); 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(); 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(); diff --git a/src/blackmisc/simulation/aircraftmodel.h b/src/blackmisc/simulation/aircraftmodel.h index 8fe936c6c..e9ae4027f 100644 --- a/src/blackmisc/simulation/aircraftmodel.h +++ b/src/blackmisc/simulation/aircraftmodel.h @@ -30,7 +30,8 @@ namespace BlackMisc //! \remarks Simulator independent class, supposed to be common denominator class BLACKMISC_EXPORT CAircraftModel : public CValueObject, - 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; diff --git a/src/blackmisc/simulation/aircraftmodellist.cpp b/src/blackmisc/simulation/aircraftmodellist.cpp index 8389aed66..04f2a1f78 100644 --- a/src/blackmisc/simulation/aircraftmodellist.cpp +++ b/src/blackmisc/simulation/aircraftmodellist.cpp @@ -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; diff --git a/src/blackmisc/simulation/aircraftmodellist.h b/src/blackmisc/simulation/aircraftmodellist.h index 29b6fc5c9..db6efa280 100644 --- a/src/blackmisc/simulation/aircraftmodellist.h +++ b/src/blackmisc/simulation/aircraftmodellist.h @@ -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, public IDatastoreObjectList, + public IOrderableList, public BlackMisc::Mixin::MetaType { 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;