From 169dca8d840553207f2bc0af29f22843ae025435 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 10 Jun 2018 02:11:39 +0200 Subject: [PATCH] Ref T275, aligned classes with new "comparePropertyByIndex" in base class --- src/blackmisc/aviation/aircrafticaocode.cpp | 153 ++++++-------------- src/blackmisc/aviation/aircrafticaocode.h | 2 +- src/blackmisc/aviation/aircraftsituation.h | 2 +- src/blackmisc/aviation/atcstation.cpp | 92 ++++-------- 4 files changed, 81 insertions(+), 168 deletions(-) diff --git a/src/blackmisc/aviation/aircrafticaocode.cpp b/src/blackmisc/aviation/aircrafticaocode.cpp index a227a3c69..d88ed0a70 100644 --- a/src/blackmisc/aviation/aircrafticaocode.cpp +++ b/src/blackmisc/aviation/aircrafticaocode.cpp @@ -579,40 +579,23 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexAircraftDesignator: - return CVariant::fromValue(m_designator); - case IndexIataCode: - return CVariant::fromValue(m_iataCode); - case IndexFamily: - return CVariant::fromValue(m_family); - case IndexCombinedAircraftType: - return CVariant::fromValue(m_combinedType); - case IndexModelDescription: - return CVariant::fromValue(m_modelDescription); - case IndexModelIataDescription: - return CVariant::fromValue(m_modelIataDescription); - case IndexModelSwiftDescription: - return CVariant::fromValue(m_modelSwiftDescription); - case IndexCombinedDescription: - return CVariant::fromValue(this->getCombinedModelDescription()); - case IndexManufacturer: - return CVariant::fromValue(m_manufacturer); - case IndexWtc: - return CVariant::fromValue(m_wtc); - case IndexIsVtol: - return CVariant::fromValue(this->isVtol()); - case IndexIsLegacy: - return CVariant::fromValue(m_legacy); - case IndexIsMilitary: - return CVariant::fromValue(m_military); - case IndexIsRealworld: - return CVariant::fromValue(m_realWorld); - case IndexRank: - return CVariant::fromValue(m_rank); - case IndexDesignatorManufacturer: - return CVariant::fromValue(this->getDesignatorManufacturer()); - default: - return CValueObject::propertyByIndex(index); + case IndexAircraftDesignator: return CVariant::fromValue(m_designator); + case IndexIataCode: return CVariant::fromValue(m_iataCode); + case IndexFamily: return CVariant::fromValue(m_family); + case IndexCombinedAircraftType: return CVariant::fromValue(m_combinedType); + case IndexModelDescription: return CVariant::fromValue(m_modelDescription); + case IndexModelIataDescription: return CVariant::fromValue(m_modelIataDescription); + case IndexModelSwiftDescription: return CVariant::fromValue(m_modelSwiftDescription); + case IndexCombinedDescription: return CVariant::fromValue(this->getCombinedModelDescription()); + case IndexManufacturer: return CVariant::fromValue(m_manufacturer); + case IndexWtc: return CVariant::fromValue(m_wtc); + case IndexIsVtol: return CVariant::fromValue(this->isVtol()); + case IndexIsLegacy: return CVariant::fromValue(m_legacy); + case IndexIsMilitary: return CVariant::fromValue(m_military); + case IndexIsRealworld: return CVariant::fromValue(m_realWorld); + case IndexRank: return CVariant::fromValue(m_rank); + case IndexDesignatorManufacturer: return CVariant::fromValue(this->getDesignatorManufacturer()); + default: return CValueObject::propertyByIndex(index); } } @@ -623,45 +606,19 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexAircraftDesignator: - this->setDesignator(variant.value()); - break; - case IndexIataCode: - this->setIataCode(variant.value()); - break; - case IndexFamily: - this->setFamily(variant.value()); - break; - case IndexCombinedAircraftType: - this->setCombinedType(variant.value()); - break; - case IndexModelDescription: - this->setModelDescription(variant.value()); - break; - case IndexModelIataDescription: - this->setModelIataDescription(variant.value()); - break; - case IndexModelSwiftDescription: - this->setModelSwiftDescription(variant.value()); - break; - case IndexManufacturer: - this->setManufacturer(variant.value()); - break; - case IndexWtc: - this->setWtc(variant.value()); - break; - case IndexIsLegacy: - m_legacy = variant.toBool(); - break; - case IndexIsMilitary: - m_military = variant.toBool(); - break; - case IndexRank: - m_rank = variant.toInt(); - break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; + case IndexAircraftDesignator: this->setDesignator(variant.value()); break; + case IndexIataCode: this->setIataCode(variant.value()); break; + case IndexFamily: this->setFamily(variant.value()); break; + case IndexCombinedAircraftType: this->setCombinedType(variant.value()); break; + case IndexModelDescription: this->setModelDescription(variant.value()); break; + case IndexModelIataDescription: this->setModelIataDescription(variant.value()); break; + case IndexModelSwiftDescription: this->setModelSwiftDescription(variant.value()); break; + case IndexManufacturer: this->setManufacturer(variant.value()); break; + case IndexWtc: this->setWtc(variant.value()); break; + case IndexIsLegacy: m_legacy = variant.toBool(); break; + case IndexIsMilitary: m_military = variant.toBool(); break; + case IndexRank: m_rank = variant.toInt(); break; + default: CValueObject::setPropertyByIndex(index, variant); break; } } @@ -669,23 +626,16 @@ namespace BlackMisc { if (index.isMyself()) { return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive); } if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(index, compareValue);} - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexAircraftDesignator: - return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive); - case IndexIataCode: - return m_iataCode.compare(compareValue.getIataCode(), Qt::CaseInsensitive); - case IndexFamily: - return m_family.compare(compareValue.getFamily(), Qt::CaseInsensitive); - case IndexCombinedAircraftType: - return m_combinedType.compare(compareValue.getCombinedType(), Qt::CaseInsensitive); - case IndexModelDescription: - return m_modelDescription.compare(compareValue.getModelDescription(), Qt::CaseInsensitive); - case IndexModelIataDescription: - return m_modelIataDescription.compare(compareValue.getModelIataDescription(), Qt::CaseInsensitive); - case IndexModelSwiftDescription: - return m_modelSwiftDescription.compare(compareValue.getModelSwiftDescription(), Qt::CaseInsensitive); + case IndexAircraftDesignator: return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive); + case IndexIataCode: return m_iataCode.compare(compareValue.getIataCode(), Qt::CaseInsensitive); + case IndexFamily: return m_family.compare(compareValue.getFamily(), Qt::CaseInsensitive); + case IndexCombinedAircraftType: return m_combinedType.compare(compareValue.getCombinedType(), Qt::CaseInsensitive); + case IndexModelDescription: return m_modelDescription.compare(compareValue.getModelDescription(), Qt::CaseInsensitive); + case IndexModelIataDescription: return m_modelIataDescription.compare(compareValue.getModelIataDescription(), Qt::CaseInsensitive); + case IndexModelSwiftDescription: return m_modelSwiftDescription.compare(compareValue.getModelSwiftDescription(), Qt::CaseInsensitive); case IndexCombinedDescription: { // compare without generating new strings @@ -700,24 +650,15 @@ namespace BlackMisc } return c; } - case IndexManufacturer: - return m_manufacturer.compare(compareValue.getManufacturer(), Qt::CaseInsensitive); - case IndexWtc: - return m_wtc.compare(compareValue.getWtc(), Qt::CaseInsensitive); - case IndexIsLegacy: - return Compare::compare(m_legacy, compareValue.isLegacyAircraft()); - case IndexIsMilitary: - return Compare::compare(m_military, compareValue.isMilitary()); - case IndexIsVtol: - return Compare::compare(isVtol(), compareValue.isVtol()); - case IndexIsRealworld: - return Compare::compare(m_realWorld, compareValue.isRealWorld()); - case IndexRank: - return Compare::compare(m_rank, compareValue.getRank()); - case IndexDesignatorManufacturer: - return getDesignatorManufacturer().compare(compareValue.getDesignatorManufacturer(), Qt::CaseInsensitive); - default: - break; + case IndexManufacturer: return m_manufacturer.compare(compareValue.getManufacturer(), Qt::CaseInsensitive); + case IndexWtc: return m_wtc.compare(compareValue.getWtc(), Qt::CaseInsensitive); + case IndexIsLegacy: return Compare::compare(m_legacy, compareValue.isLegacyAircraft()); + case IndexIsMilitary: return Compare::compare(m_military, compareValue.isMilitary()); + case IndexIsVtol: return Compare::compare(isVtol(), compareValue.isVtol()); + case IndexIsRealworld: return Compare::compare(m_realWorld, compareValue.isRealWorld()); + case IndexRank: return Compare::compare(m_rank, compareValue.getRank()); + case IndexDesignatorManufacturer: return getDesignatorManufacturer().compare(compareValue.getDesignatorManufacturer(), Qt::CaseInsensitive); + default: return CValueObject::comparePropertyByIndex(index, *this); } Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison"); return 0; diff --git a/src/blackmisc/aviation/aircrafticaocode.h b/src/blackmisc/aviation/aircrafticaocode.h index 6d5d4234e..3e1b71b52 100644 --- a/src/blackmisc/aviation/aircrafticaocode.h +++ b/src/blackmisc/aviation/aircrafticaocode.h @@ -276,7 +276,7 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); - //! Compare for index + //! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex int comparePropertyByIndex(const CPropertyIndex &index, const CAircraftIcaoCode &compareValue) const; //! \copydoc BlackMisc::Mixin::String::toQString diff --git a/src/blackmisc/aviation/aircraftsituation.h b/src/blackmisc/aviation/aircraftsituation.h index e08d3d855..e083e28be 100644 --- a/src/blackmisc/aviation/aircraftsituation.h +++ b/src/blackmisc/aviation/aircraftsituation.h @@ -154,7 +154,7 @@ namespace BlackMisc //! \copydoc Mixin::Index::setPropertyByIndex void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); - //! Compare by index + //! \copydoc Mixin::Index::comparePropertyByIndex int comparePropertyByIndex(const CPropertyIndex &index, const CAircraftSituation &compareValue) const; //! Get position diff --git a/src/blackmisc/aviation/atcstation.cpp b/src/blackmisc/aviation/atcstation.cpp index d08e671bf..f7f22d14b 100644 --- a/src/blackmisc/aviation/atcstation.cpp +++ b/src/blackmisc/aviation/atcstation.cpp @@ -314,37 +314,23 @@ namespace BlackMisc CVariant CAtcStation::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexBookedFrom: - return CVariant::from(m_bookedFromUtc); - case IndexBookedUntil: - return CVariant::from(m_bookedUntilUtc); - case IndexCallsign: - return m_callsign.propertyByIndex(index.copyFrontRemoved()); - case IndexController: - return m_controller.propertyByIndex(index.copyFrontRemoved()); - case IndexFrequency: - return m_frequency.propertyByIndex(index.copyFrontRemoved()); - case IndexIsOnline: - return CVariant::from(m_isOnline); - case IndexLatitude: - return this->latitude().propertyByIndex(index.copyFrontRemoved()); - case IndexLongitude: - return this->longitude().propertyByIndex(index.copyFrontRemoved()); - case IndexPosition: - return m_position.propertyByIndex(index.copyFrontRemoved()); - case IndexRange: - return m_range.propertyByIndex(index.copyFrontRemoved()); - case IndexIsInRange: - return CVariant::fromValue(isInRange()); - case IndexAtis: - return m_atis.propertyByIndex(index.copyFrontRemoved()); - case IndexMetar: - return m_metar.propertyByIndex(index.copyFrontRemoved()); - case IndexVoiceRoom: - return m_voiceRoom.propertyByIndex(index.copyFrontRemoved()); + case IndexBookedFrom: return CVariant::from(m_bookedFromUtc); + case IndexBookedUntil: return CVariant::from(m_bookedUntilUtc); + case IndexCallsign: return m_callsign.propertyByIndex(index.copyFrontRemoved()); + case IndexController: return m_controller.propertyByIndex(index.copyFrontRemoved()); + case IndexFrequency: return m_frequency.propertyByIndex(index.copyFrontRemoved()); + case IndexIsOnline: return CVariant::from(m_isOnline); + case IndexLatitude: return this->latitude().propertyByIndex(index.copyFrontRemoved()); + case IndexLongitude: return this->longitude().propertyByIndex(index.copyFrontRemoved()); + case IndexPosition: return m_position.propertyByIndex(index.copyFrontRemoved()); + case IndexRange: return m_range.propertyByIndex(index.copyFrontRemoved()); + case IndexIsInRange: return CVariant::fromValue(isInRange()); + case IndexAtis: return m_atis.propertyByIndex(index.copyFrontRemoved()); + case IndexMetar: return m_metar.propertyByIndex(index.copyFrontRemoved()); + case IndexVoiceRoom: return m_voiceRoom.propertyByIndex(index.copyFrontRemoved()); default: return (ICoordinateWithRelativePosition::canHandleIndex(index)) ? ICoordinateWithRelativePosition::propertyByIndex(index) : @@ -355,7 +341,7 @@ namespace BlackMisc void CAtcStation::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { case IndexBookedFrom: @@ -407,43 +393,29 @@ namespace BlackMisc int CAtcStation::comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const { if (index.isMyself()) { return this->getCallsign().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexBookedFrom: - return Compare::compare(this->getBookedFromUtc(), compareValue.getBookedFromUtc()); - case IndexBookedUntil: - return Compare::compare(this->getBookedUntilUtc(), compareValue.getBookedUntilUtc()); - case IndexCallsign: - return m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); - case IndexController: - return m_controller.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getController()); - case IndexFrequency: - return m_frequency.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getFrequency()); - case IndexIsOnline: - return Compare::compare(this->isOnline(), compareValue.isOnline()); - case IndexLatitude: - return this->latitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.latitude()); - case IndexLongitude: - return this->longitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.longitude()); - case IndexPosition: - return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); - case IndexRange: - return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange()); - case IndexIsInRange: - return Compare::compare(this->isInRange(), compareValue.isInRange()); - case IndexAtis: - return m_atis.getMessage().compare(compareValue.getAtis().getMessage()); - case IndexMetar: - return m_metar.getMessage().compare(compareValue.getMetar().getMessage()); - case IndexVoiceRoom: - return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl()); + case IndexBookedFrom: return Compare::compare(this->getBookedFromUtc(), compareValue.getBookedFromUtc()); + case IndexBookedUntil: return Compare::compare(this->getBookedUntilUtc(), compareValue.getBookedUntilUtc()); + case IndexCallsign: return m_callsign.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); + case IndexController: return m_controller.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getController()); + case IndexFrequency: return m_frequency.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getFrequency()); + case IndexIsOnline: return Compare::compare(this->isOnline(), compareValue.isOnline()); + case IndexLatitude: return this->latitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.latitude()); + case IndexLongitude: return this->longitude().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.longitude()); + case IndexPosition: return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); + case IndexRange: return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange()); + case IndexIsInRange: return Compare::compare(this->isInRange(), compareValue.isInRange()); + case IndexAtis: return m_atis.getMessage().compare(compareValue.getAtis().getMessage()); + case IndexMetar: return m_metar.getMessage().compare(compareValue.getMetar().getMessage()); + case IndexVoiceRoom: return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl()); default: if (ICoordinateWithRelativePosition::canHandleIndex(index)) { return ICoordinateWithRelativePosition::comparePropertyByIndex(index, compareValue); } - break; + return CValueObject::comparePropertyByIndex(index, *this); } Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed"); return 0;