mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
refs #501, compareByPropertyIndex (performance for sort)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
1e57ce7ecb
commit
0c94922bd6
@@ -10,10 +10,12 @@
|
||||
#include "aircraftmodel.h"
|
||||
#include "distributor.h"
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include <QString>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -140,6 +142,42 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CAircraftModel::comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::comparePropertyByIndex(compareValue, index);}
|
||||
if (index.isMyself()) { return this->m_modelString.compare(compareValue.getModelString(), Qt::CaseInsensitive); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexModelString:
|
||||
return this->m_modelString.compare(compareValue.getModelString(), Qt::CaseInsensitive);
|
||||
case IndexAircraftIcaoCode:
|
||||
return this->m_aircraftIcao.comparePropertyByIndex(compareValue.getAircraftIcaoCode(), index.copyFrontRemoved());
|
||||
case IndexLivery:
|
||||
return this->m_livery.comparePropertyByIndex(compareValue.getLivery(), index.copyFrontRemoved());
|
||||
case IndexDistributor:
|
||||
return this->m_distributor.comparePropertyByIndex(compareValue.getDistributor(), index.copyFrontRemoved());
|
||||
case IndexDescription:
|
||||
return this->m_description.compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
||||
case IndexSimulatorInfo:
|
||||
return this->m_simulator.comparePropertyByIndex(compareValue.getSimulatorInfo(), index.copyFrontRemoved());
|
||||
case IndexName:
|
||||
return this->m_modelName.compare(compareValue.getName(), Qt::CaseInsensitive);
|
||||
case IndexCallsign:
|
||||
break;
|
||||
case IndexFileName:
|
||||
return this->m_fileName.compare(compareValue.getFileName(), Qt::CaseInsensitive);
|
||||
case IndexModelType:
|
||||
return Compare::compare(this->m_modelType, compareValue.getModelType());
|
||||
case IndexModelMode:
|
||||
return Compare::compare(this->m_modelMode, compareValue.getModelMode());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CAircraftModel::setAircraftIcaoCode(const CAircraftIcaoCode &aircraftIcaoCode)
|
||||
{
|
||||
if (this->m_aircraftIcao == aircraftIcaoCode) { return false; }
|
||||
|
||||
@@ -94,6 +94,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CAircraftModel &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! Corresponding callsign if applicable
|
||||
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_callsign; }
|
||||
|
||||
|
||||
@@ -71,6 +71,25 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CDistributor::comparePropertyByIndex(const CDistributor &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (IDatastoreObjectWithStringKey::canHandleIndex(index)) { return IDatastoreObjectWithStringKey::comparePropertyByIndex(compareValue, index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAlias1:
|
||||
return this->m_alias1.compare(compareValue.m_alias1, Qt::CaseInsensitive);
|
||||
case IndexAlias2:
|
||||
return this->m_alias2.compare(compareValue.m_alias2, Qt::CaseInsensitive);
|
||||
case IndexDescription:
|
||||
return this->m_description.compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString CDistributor::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
|
||||
@@ -84,6 +84,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CDistributor &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
#include "simulatedaircraft.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
@@ -315,7 +317,8 @@ namespace BlackMisc
|
||||
this->m_transponder.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
case IndexAircraftIcaoCode:
|
||||
this->m_livery.setPropertyByIndex(variant, index); // intentionally not removing front, delegating
|
||||
// intentionally not removing front, delegating
|
||||
this->m_livery.setPropertyByIndex(variant, index);
|
||||
break;
|
||||
case IndexLivery:
|
||||
this->m_livery.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
@@ -348,6 +351,46 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
int CSimulatedAircraft::comparePropertyByIndex(const CSimulatedAircraft &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->m_callsign.comparePropertyByIndex(compareValue.getCallsign(), index.copyFrontRemoved()); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCallsign:
|
||||
return this->m_callsign.comparePropertyByIndex(compareValue.getCallsign(), index.copyFrontRemoved());
|
||||
case IndexPilot:
|
||||
return this->m_pilot.comparePropertyByIndex(compareValue.getPilot(), index.copyFrontRemoved());
|
||||
case IndexSituation:
|
||||
case IndexDistanceToOwnAircraft:
|
||||
return this->m_distanceToOwnAircraft.comparePropertyByIndex(compareValue.getDistanceToOwnAircraft(), index.copyFrontRemoved());
|
||||
case IndexCom1System:
|
||||
return m_com1system.getFrequencyActive().comparePropertyByIndex(compareValue.getCom1System().getFrequencyActive(), index.copyFrontRemoved());
|
||||
case IndexCom2System:
|
||||
return m_com2system.getFrequencyActive().comparePropertyByIndex(compareValue.getCom2System().getFrequencyActive(), index.copyFrontRemoved());
|
||||
case IndexTransponder:
|
||||
return Compare::compare(m_transponder.getTransponderCode(), compareValue.getTransponder().getTransponderCode());
|
||||
case IndexLivery:
|
||||
return this->m_livery.comparePropertyByIndex(compareValue.getLivery(), index.copyFrontRemoved());
|
||||
case IndexParts:
|
||||
return this->m_parts.comparePropertyByIndex(compareValue.getParts(), index.copyFrontRemoved());
|
||||
case IndexModel:
|
||||
return m_model.comparePropertyByIndex(compareValue.getModel(), index.copyFrontRemoved());
|
||||
case IndexEnabled:
|
||||
return Compare::compare(this->m_enabled, compareValue.isEnabled());
|
||||
case IndexRendered:
|
||||
return Compare::compare(this->m_rendered, compareValue.isRendered());
|
||||
case IndexPartsSynchronized:
|
||||
return Compare::compare(this->m_partsSynchronized, compareValue.isPartsSynchronized());
|
||||
case IndexFastPositionUpdates:
|
||||
return Compare::compare(this->m_fastPositionUpdates, compareValue.fastPositionUpdates());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Comapre failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSimulatedAircraft::setModel(const CAircraftModel &model)
|
||||
{
|
||||
// sync the callsigns
|
||||
|
||||
@@ -301,6 +301,9 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CSimulatedAircraft &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! Get model
|
||||
const BlackMisc::Simulation::CAircraftModel &getModel() const { return m_model; }
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "simulatorinfo.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/simulation/fscommon/fscommonutil.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -85,6 +86,12 @@ namespace BlackMisc
|
||||
return (this->m_simulator & otherInfo.m_simulator) > 0;
|
||||
}
|
||||
|
||||
int CSimulatorInfo::comparePropertyByIndex(const CSimulatorInfo &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return Compare::compare(this->m_simulator, compareValue.m_simulator);
|
||||
}
|
||||
|
||||
QString CSimulatorInfo::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
|
||||
@@ -101,6 +101,9 @@ namespace BlackMisc
|
||||
//! All simulators
|
||||
void setAllSimulators() { setSimulator(All); }
|
||||
|
||||
//! Compare for index
|
||||
int comparePropertyByIndex(const CSimulatorInfo &compareValue, const CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user