Ref T261, utility functions in value classes

* set offset values
* do not change PQs if PQ is null
* sorted by callsign
This commit is contained in:
Klaus Basan
2018-05-07 01:51:45 +02:00
committed by Roland Winklmeier
parent 3f4cb7529c
commit 8e3b55b4ca
9 changed files with 47 additions and 15 deletions

View File

@@ -349,13 +349,16 @@ namespace BlackMisc
return c;
}
void CAircraftSituationList::addAltitudeOffset(const CLength &offset)
int CAircraftSituationList::addAltitudeOffset(const CLength &offset)
{
if (offset.isNull() || this->isEmpty()) { return; }
if (offset.isNull() || this->isEmpty()) { return 0; }
int c = 0;
for (CAircraftSituation &s : *this)
{
s.addAltitudeOffset(offset);
c++;
}
return c;
}
bool CAircraftSituationList::isSortedAdjustedLatestFirstWithoutNullPositions() const

View File

@@ -132,7 +132,7 @@ namespace BlackMisc
int setOnGroundDetails(CAircraftSituation::OnGroundDetails details);
//! Add an offset to each altitude
void addAltitudeOffset(const PhysicalQuantities::CLength &offset);
int addAltitudeOffset(const PhysicalQuantities::CLength &offset);
//! Latest first and no null positions?
bool isSortedAdjustedLatestFirstWithoutNullPositions() const;

View File

@@ -30,30 +30,32 @@ namespace BlackMisc
CAltitude CAltitude::withOffset(const CLength &offset) const
{
if (this->isNull()) { return CAltitude(offset, CAltitude::MeanSeaLevel); }
CAltitude copy(*this);
if (!offset.isNull() && !offset.isZeroEpsilonConsidered()) { copy += offset; }
if (!offset.isNull() && !offset.isZeroEpsilonConsidered())
{
copy += offset;
}
return copy;
}
void CAltitude::addOffset(const CLength &offset)
{
*this = this->withOffset(offset);
}
QString CAltitude::convertToQString(bool i18n) const
{
if (this->m_datum == FlightLevel)
{
static const QString fls("FL%1");
const int fl = qRound(this->CLength::value(CLengthUnit::ft()) / 100.0);
return QString("FL%1").arg(fl);
return fls.arg(fl);
}
else
{
QString s;
if (this->getUnit() == CLengthUnit::m())
{
s = this->CLength::valueRoundedWithUnit(1, i18n);
}
else
{
s = this->CLength::valueRoundedWithUnit(CLengthUnit::ft(), 0, i18n);
}
return s.append(this->isMeanSeaLevel() ? QStringLiteral(" MSL") : QStringLiteral(" AGL"));
return this->CLength::valueRoundedWithUnit(1, i18n) %
(this->isMeanSeaLevel() ? QStringLiteral(" MSL") : QStringLiteral(" AGL"));
}
}

View File

@@ -105,6 +105,9 @@ namespace BlackMisc
//! \remark epsilon 0 (zero) values ignored
CAltitude withOffset(const CLength &offset) const;
//! Add offset value
void addOffset(const CLength &offset);
//! AGL Above ground level?
bool isAboveGroundLevel() const { return AboveGround == this->m_datum; }

View File

@@ -215,6 +215,14 @@ namespace BlackMisc
container().sortBy(&OBJ::getCallsign);
}
template<class OBJ, class CONTAINER>
CONTAINER ICallsignObjectList<OBJ, CONTAINER>::sortedByCallsign() const
{
CONTAINER copy(this->container());
copy.sortByCallsign();
return copy;
}
template <class OBJ, class CONTAINER>
int ICallsignObjectList<OBJ, CONTAINER>::incrementalUpdateOrAdd(const OBJ &objectBeforeChanges, const CPropertyIndexVariantMap &changedValues)
{

View File

@@ -104,6 +104,9 @@ namespace BlackMisc
//! Sort by callsign
void sortByCallsign();
//! Copy of list sorted by callsign
CONTAINER sortedByCallsign() const;
protected:
//! Constructor
ICallsignObjectList();

View File

@@ -38,6 +38,13 @@ namespace BlackMisc
CCoordinateGeodetic(coordinate), m_radius(radius)
{ }
void CElevationPlane::addAltitudeOffset(const CLength &offset)
{
if (offset.isNull() || offset.isZeroEpsilonConsidered()) { return; }
const CAltitude newAlt = this->getAltitude().withOffset(offset);
this->setGeodeticHeight(newAlt);
}
const CAltitude &CElevationPlane::getAltitudeIfWithinRadius(const ICoordinateGeodetic &coordinate) const
{
return (isWithinRange(coordinate)) ? geodeticHeight() : CAltitude::null();

View File

@@ -48,6 +48,9 @@ namespace BlackMisc
//! Radius
void setRadius(const PhysicalQuantities::CLength &radius) { m_radius = radius; }
//! Add offset to altitude
void addAltitudeOffset(const PhysicalQuantities::CLength &offset);
//! Altitude when within radius, else null
const Aviation::CAltitude &getAltitudeIfWithinRadius(const ICoordinateGeodetic &coordinate) const;

View File

@@ -143,6 +143,7 @@ namespace BlackMisc
template <class MU, class PQ>
const PQ &CPhysicalQuantity<MU, PQ>::makePositive()
{
if (this->isNull() || m_value == 0) { return *this->derived(); }
if (m_value < 0) { m_value *= -1.0; }
return *this->derived();
}
@@ -150,6 +151,7 @@ namespace BlackMisc
template <class MU, class PQ>
const PQ &CPhysicalQuantity<MU, PQ>::makeNegative()
{
if (this->isNull() || m_value == 0) { return *this->derived(); }
if (m_value > 0) { m_value *= -1.0; }
return *this->derived();
}
@@ -157,6 +159,7 @@ namespace BlackMisc
template<class MU, class PQ>
PQ CPhysicalQuantity<MU, PQ>::abs() const
{
if (this->isNull() || m_value == 0) { return *this->derived(); }
if (m_value >= 0) { return *this->derived(); }
PQ copy(*this->derived());
return copy.makePositive();