mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
refs #501, compareByPropertyIndex (performance for sort)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1e57ce7ecb
commit
0c94922bd6
@@ -13,6 +13,7 @@
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include <tuple>
|
||||
#include <QThreadStorage>
|
||||
#include <QRegularExpression>
|
||||
@@ -280,6 +281,36 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CAircraftIcaoCode::comparePropertyByIndex(const CAircraftIcaoCode &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(compareValue, index);}
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraftDesignator:
|
||||
return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive);
|
||||
case IndexCombinedAircraftType:
|
||||
return m_combinedType.compare(compareValue.getCombinedType(), Qt::CaseInsensitive);
|
||||
case IndexModelDescription:
|
||||
return m_modelDescription.compare(compareValue.getModelDescription(), Qt::CaseInsensitive);
|
||||
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 IndexRank:
|
||||
return Compare::compare(m_rank, compareValue.getRank());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CAircraftIcaoCode::isValidDesignator(const QString &designator)
|
||||
{
|
||||
if (designator.length() < 2 || designator.length() > 5) { return false; }
|
||||
|
||||
@@ -168,6 +168,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CAircraftIcaoCode &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
*/
|
||||
|
||||
#include "aircraftparts.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
QString CAircraftParts::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s;
|
||||
@@ -34,10 +36,7 @@ namespace BlackMisc
|
||||
CVariant CAircraftParts::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (ITimestampBased::canHandleIndex(index))
|
||||
{
|
||||
return ITimestampBased::propertyByIndex(index);
|
||||
}
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
@@ -60,11 +59,7 @@ namespace BlackMisc
|
||||
void CAircraftParts::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAircraftParts>(); return; }
|
||||
if (ITimestampBased::canHandleIndex(index))
|
||||
{
|
||||
ITimestampBased::setPropertyByIndex(variant, index);
|
||||
return;
|
||||
}
|
||||
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
@@ -90,6 +85,31 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CAircraftParts::comparePropertyByIndex(const CAircraftParts &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return ITimestampBased::comparePropertyByIndex(compareValue, CPropertyIndex()); }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::comparePropertyByIndex(compareValue, index); }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexEngines:
|
||||
return Compare::compare(this->getEnginesCount(), compareValue.getEnginesCount());
|
||||
case IndexFlapsPercentage:
|
||||
return Compare::compare(this->m_flapsPercentage, compareValue.getFlapsPercent());
|
||||
case IndexGearDown:
|
||||
return Compare::compare(this->m_gearDown, compareValue.isGearDown());
|
||||
case IndexLights:
|
||||
break;
|
||||
case IndexSpoilersOut:
|
||||
return Compare::compare(this->m_spoilersOut, compareValue.isSpoilersOut());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CAircraftParts::setAllLightsOn()
|
||||
{
|
||||
m_lights.setAllOn();
|
||||
|
||||
@@ -56,6 +56,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CAircraftParts &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! Get aircraft lights
|
||||
CAircraftLights getLights() const { return m_lights; }
|
||||
|
||||
@@ -92,6 +95,9 @@ namespace BlackMisc
|
||||
//! Engine with number
|
||||
CAircraftEngine getEngine(int number) const;
|
||||
|
||||
//! Number of engines
|
||||
int getEnginesCount() const { return m_engines.size(); }
|
||||
|
||||
//! Is engine with number 1..n on?
|
||||
bool isEngineOn(int number) const;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <QThreadStorage>
|
||||
@@ -154,6 +155,32 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CAirlineIcaoCode::comparePropertyByIndex(const CAirlineIcaoCode &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return m_designator.compare(compareValue.getDesignator(), Qt::CaseInsensitive); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(compareValue, index);}
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAirlineDesignator:
|
||||
return this->m_designator.compare(compareValue.getDesignator());
|
||||
case IndexAirlineCountry:
|
||||
return this->m_country.comparePropertyByIndex(compareValue.getCountry(), index.copyFrontRemoved());
|
||||
case IndexAirlineName:
|
||||
return this->m_name.compare(compareValue.getName(), Qt::CaseInsensitive);
|
||||
case IndexTelephonyDesignator:
|
||||
return this->m_telephonyDesignator.compare(compareValue.getTelephonyDesignator(), Qt::CaseInsensitive);
|
||||
case IndexIsVirtualAirline:
|
||||
return Compare::compare(this->isVirtualAirline(), compareValue.isVirtualAirline());
|
||||
case IndexIsOperating:
|
||||
return Compare::compare(this->isOperating(), compareValue.isOperating());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No compare function");
|
||||
return 0;
|
||||
}
|
||||
|
||||
CStatusMessageList CAirlineIcaoCode::validate() const
|
||||
{
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation() }));
|
||||
|
||||
@@ -133,6 +133,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CAirlineIcaoCode &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! Validate data
|
||||
BlackMisc::CStatusMessageList validate() const;
|
||||
|
||||
|
||||
@@ -100,5 +100,27 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CAirport::comparePropertyByIndex(const CAirport &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->m_icao.comparePropertyByIndex(compareValue.getIcao(), index.copyFrontRemoved()); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexIcao:
|
||||
return this->m_icao.comparePropertyByIndex(compareValue.getIcao(), index.copyFrontRemoved());
|
||||
case IndexDescriptiveName:
|
||||
return this->m_descriptiveName.compare(compareValue.getDescriptiveName(), Qt::CaseInsensitive);
|
||||
case IndexBearing:
|
||||
return this->m_bearingToOwnAircraft.comparePropertyByIndex(compareValue.getBearingToOwnAircraft(), index.copyFrontRemoved());
|
||||
case IndexPosition:
|
||||
case IndexDistanceToOwnAircraft:
|
||||
return this->m_distanceToOwnAircraft.comparePropertyByIndex(compareValue.getDistanceToOwnAircraft(), index.copyFrontRemoved());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -102,6 +102,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CAirport &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@ namespace BlackMisc
|
||||
return this->m_icaoCode;
|
||||
}
|
||||
|
||||
int CAirportIcaoCode::comparePropertyByIndex(const CAirportIcaoCode &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return this->m_icaoCode.compare(compareValue.getIcaoCode(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool CAirportIcaoCode::equalsString(const QString &icaoCode) const
|
||||
{
|
||||
CAirportIcaoCode other(icaoCode);
|
||||
|
||||
@@ -54,6 +54,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::convertToQString()
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CAirportIcaoCode &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CAirportIcaoCode)
|
||||
QString m_icaoCode;
|
||||
|
||||
@@ -168,6 +168,25 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CCallsign::comparePropertyByIndex(const CCallsign &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->m_callsign.compare(compareValue.m_callsign, Qt::CaseInsensitive); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCallsignString:
|
||||
return this->m_callsign.compare(compareValue.m_callsign, Qt::CaseInsensitive);
|
||||
case IndexCallsignStringAsSet:
|
||||
return this->m_callsignAsSet.compare(compareValue.m_callsignAsSet, Qt::CaseInsensitive);
|
||||
case IndexTelephonyDesignator:
|
||||
return this->m_telephonyDesignator.compare(compareValue.m_telephonyDesignator, Qt::CaseInsensitive);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CCallsign::isValidCallsign(const QString &callsign)
|
||||
{
|
||||
// We allow all number callsigns
|
||||
|
||||
@@ -117,6 +117,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CCallsign &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! Valid callsign?
|
||||
static bool isValidCallsign(const QString &callsign);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
@@ -228,6 +228,30 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CLivery::comparePropertyByIndex(const CLivery &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDescription:
|
||||
return this->m_description.compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
||||
case IndexAirlineIcaoCode:
|
||||
return this->m_airline.comparePropertyByIndex(compareValue.getAirlineIcaoCode(), index.copyFrontRemoved());
|
||||
case IndexColorFuselage:
|
||||
return this->m_colorFuselage.comparePropertyByIndex(compareValue.getColorFuselage(), index.copyFrontRemoved());
|
||||
case IndexColorTail:
|
||||
return this->m_colorTail.comparePropertyByIndex(compareValue.getColorTail(), index.copyFrontRemoved());
|
||||
case IndexCombinedCode:
|
||||
return this->getCombinedCode().compare(compareValue.getCombinedCode());
|
||||
case IndexIsMilitary:
|
||||
return Compare::compare(this->isMilitary(), compareValue.isMilitary());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No compare function");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CLivery::updateMissingParts(const CLivery &otherLivery)
|
||||
{
|
||||
if (!this->m_colorFuselage.isValid()) { this->setColorFuselage(otherLivery.getColorFuselage()); }
|
||||
|
||||
@@ -112,6 +112,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CLivery &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user