refs #395, added isInRange to ATC stations

* use null as default values for some members to detect those are not yet set
* used simplified bool formatter for views
This commit is contained in:
Klaus Basan
2015-04-22 18:55:32 +02:00
committed by Mathew Sutcliffe
parent a3b147d59a
commit 3300b1ad9b
9 changed files with 72 additions and 51 deletions

View File

@@ -55,6 +55,7 @@ namespace BlackGui
col.setSortPropertyIndex({ CAtcStation::IndexCallsign, CCallsign::IndexSuffix });
this->m_columns.addColumn(col);
this->m_columns.addColumn(CColumn("distance", CAtcStation::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter()));
this->m_columns.addColumn(CColumn("r.", "in range", CAtcStation::IndexIsInRange, new CBoolIconFormatter("in range", "outside range")));
this->m_columns.addColumn(CColumn("frequency", CAtcStation::IndexFrequency, new CComFrequencyFormatter()));
this->m_columns.addColumn(CColumn::standardString("controllername", { CAtcStation::IndexController, CUser::IndexRealName }));
this->m_columns.addColumn(CColumn("from", "booked from", CAtcStation::IndexBookedFrom, new CDateTimeFormatter(CDateTimeFormatter::formatHm())));

View File

@@ -34,7 +34,7 @@ namespace BlackGui
this->m_columns.addColumn(CColumn::standardString("capabilities", CClient::IndexCapabilitiesString));
this->m_columns.addColumn(CColumn::standardString("model", {CClient::IndexModel, CAircraftModel::IndexModelString}));
this->m_columns.addColumn(CColumn("q.?", "queried", {CClient::IndexModel, CAircraftModel::IndexHasQueriedModelString},
new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "queried", "not queried")));
new CBoolIconFormatter("queried", "not queried")));
this->m_columns.addColumn(CColumn::standardString("server", CClient::IndexServer));
// force strings for translation in resource files

View File

@@ -316,7 +316,11 @@ namespace BlackGui
}
CBoolIconFormatter::CBoolIconFormatter(int alignment) :
CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconEmpty16, "on", "off", alignment)
CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "on", "off", alignment)
{ }
CBoolIconFormatter::CBoolIconFormatter(const QString &onName, const QString &offName, int alignment) :
CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, onName, offName, alignment)
{ }
CBoolIconFormatter::CBoolIconFormatter(CIcons::IconIndex onIcon, CIcons::IconIndex offIcon, const QString &onName, const QString &offName, int alignment) :

View File

@@ -205,6 +205,9 @@ namespace BlackGui
//! Constructor
CBoolIconFormatter(int alignment = alignDefault());
//! Constructor
CBoolIconFormatter(const QString &onName, const QString &offName, int alignment = alignDefault());
//! Constructor
CBoolIconFormatter(const BlackMisc::CIcon &onIcon, const BlackMisc::CIcon &offIcon, const QString &onName, const QString &offName, int alignment = alignDefault());

View File

@@ -69,16 +69,16 @@ namespace BlackGui
case ModelMode:
this->m_columns.addColumn(CColumn("e.", "enabled", CSimulatedAircraft::IndexEnabled,
new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "enabled", "disabled"), true));
new CBoolIconFormatter("enabled", "disabled"), true));
this->m_columns.addColumn(CColumn("r.", "rendered", CSimulatedAircraft::IndexRendered,
new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "rendered", "skipped"), true));
new CBoolIconFormatter("rendered", "skipped"), true));
this->m_columns.addColumn(CColumn::standardValueObject("cs.", "callsign", { CSimulatedAircraft::IndexCallsign, CCallsign::IndexCallsignString }));
this->m_columns.addColumn(CColumn::standardString("realname", "pilot's real name", { CSimulatedAircraft::IndexPilot, CUser::IndexRealName }));
this->m_columns.addColumn(CColumn("dist.", "distance", CSimulatedAircraft::IndexDistanceToOwnAircraft, new CAirspaceDistanceFormatter()));
this->m_columns.addColumn(CColumn("p.", "parts", CSimulatedAircraft::IndexPartsSynchronized,
new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "parts", "no parts"), true));
new CBoolIconFormatter("parts", "no parts"), true));
this->m_columns.addColumn(CColumn("fp.", "fast position updates", CSimulatedAircraft::IndexFastPositionUpdates,
new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "enabled", "disabled"), true));
new CBoolIconFormatter("enabled", "disabled"), true));
this->m_columns.addColumn(CColumn::standardString("icao", { CSimulatedAircraft::IndexIcao, CAircraftIcao::IndexAsString}));
this->m_columns.addColumn(CColumn::standardString("model", { CSimulatedAircraft::IndexModel, CAircraftModel::IndexModelString}));
this->m_columns.addColumn(CColumn::standardString("desc.", "description", { CSimulatedAircraft::IndexModel, CAircraftModel::IndexDescription}));

View File

@@ -49,6 +49,11 @@ namespace BlackMisc
}
}
bool CAtcStation::hasBookingTimes() const
{
return !(this->m_bookedFromUtc.isNull() && this->m_bookedUntilUtc.isNull());
}
bool CAtcStation::hasMetar() const
{
return this->m_metar.hasMessage();
@@ -181,6 +186,24 @@ namespace BlackMisc
otherStation.setController(otherController);
}
bool CAtcStation::isInRange() const
{
if (m_range.isNull() || !hasValidDistance()) { return false; }
return (this->getDistanceToOwnAircraft() <= m_range);
}
bool CAtcStation::hasValidBookingTimes() const
{
return !this->m_bookedFromUtc.isNull() && this->m_bookedFromUtc.isValid() &&
!this->m_bookedUntilUtc.isNull() && this->m_bookedUntilUtc.isValid();
}
void CAtcStation::setBookedFromUntil(const CAtcStation &otherStation)
{
this->setBookedFromUtc(otherStation.getBookedFromUtc());
this->setBookedUntilUtc(otherStation.getBookedUntilUtc());
}
bool CAtcStation::isBookedNow() const
{
if (!this->hasValidBookingTimes()) return false;
@@ -190,9 +213,14 @@ namespace BlackMisc
return true;
}
bool CAtcStation::isComUnitTunedIn25KHz(const CComSystem &comUnit) const
{
return comUnit.isActiveFrequencyWithin25kHzChannel(this->getFrequency());
}
CTime CAtcStation::bookedWhen() const
{
if (!this->hasValidBookingTimes()) return CTime(-365.0, CTimeUnit::d());
if (!this->hasValidBookingTimes()) { return CTime(0, CTimeUnit::nullUnit()); }
QDateTime now = QDateTime::currentDateTimeUtc();
qint64 diffMs;
if (this->m_bookedFromUtc > now)
@@ -257,6 +285,8 @@ namespace BlackMisc
return this->m_position.propertyByIndex(index.copyFrontRemoved());
case IndexRange:
return this->m_range.propertyByIndex(index.copyFrontRemoved());
case IndexIsInRange:
return CVariant::fromValue(isInRange());
case IndexAtis:
return this->m_atis.propertyByIndex(index.copyFrontRemoved());
case IndexMetar:

View File

@@ -42,6 +42,7 @@ namespace BlackMisc
IndexFrequency,
IndexPosition,
IndexRange,
IndexIsInRange,
IndexDistanceToOwnAircraft,
IndexIsOnline,
IndexBookedFrom,
@@ -70,10 +71,7 @@ namespace BlackMisc
BlackMisc::CIcon toIcon() const { return this->m_callsign.toIcon(); }
//! Has booking times?
bool hasBookingTimes() const
{
return !(this->m_bookedFromUtc.isNull() && this->m_bookedUntilUtc.isNull());
}
bool hasBookingTimes() const;
//! Has ATIS?
bool hasAtis() const
@@ -135,10 +133,8 @@ namespace BlackMisc
//! Set position
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
/*!
* Syncronize controller data
* Updates two stations (namely a booked and online ATC station) with complementary data
*/
//! Syncronize controller data
//! Updates two stations (namely a booked and online ATC station) with complementary data
void syncronizeControllerData(CAtcStation &otherStation);
//! Get the radius of the controller's area of visibility.
@@ -147,6 +143,9 @@ namespace BlackMisc
//! Set range
void setRange(const BlackMisc::PhysicalQuantities::CLength &range) { this->m_range = range; }
//! In range? If range and distance to own aircraft are not available false
bool isInRange() const;
//! Is station online (or just booked)?
bool isOnline() const { return m_isOnline; }
@@ -165,50 +164,33 @@ namespace BlackMisc
//! Valid voice room?
bool hasValidVoiceRoom() const { return this->m_voiceRoom.isValid(); }
/*!
* Booked date/time if any.
* This represents the closest booking within a time frame as there can be multiple bookings.
*/
//! Booked date/time if any.
//! This represents the closest booking within a time frame as there can be multiple bookings.
const QDateTime &getBookedFromUtc() const { return m_bookedFromUtc; }
//! Booked date/time if any.
//! This represents the closest booking within a time frame as there can be multiple bookings.
const QDateTime &getBookedUntilUtc() const { return m_bookedUntilUtc; }
//! Has valid booking times?
bool hasValidBookingTimes() const;
//! Set booked from
void setBookedFromUtc(const QDateTime &from) { this->m_bookedFromUtc = from; }
/*!
* Booked date/time if any.
* This represents the closest booking within a time frame as there can be multiple bookings.
*/
const QDateTime &getBookedUntilUtc() const { return m_bookedUntilUtc; }
//! Has valid booking times?
bool hasValidBookingTimes() const
{
return !this->m_bookedFromUtc.isNull() && this->m_bookedFromUtc.isValid() &&
!this->m_bookedUntilUtc.isNull() && this->m_bookedUntilUtc.isValid();
}
//! Transfer booking times
void setBookedFromUntil(const CAtcStation &otherStation)
{
this->setBookedFromUtc(otherStation.getBookedFromUtc());
this->setBookedUntilUtc(otherStation.getBookedUntilUtc());
}
void setBookedFromUntil(const CAtcStation &otherStation);
//! Booked now?
bool isBookedNow() const;
//! Tuned in within 25KHz channel spacing
bool isComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const
{
return comUnit.isActiveFrequencyWithin25kHzChannel(this->getFrequency());
}
bool isComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const;
/*!
* When booked, 0 means now,
* negative values mean booking in past,
* positive values mean booking in future,
* no booking dates will result in - 1 year
*/
//! When booked, 0 means now,
//! negative values mean booking in past,
//! positive values mean booking in future,
//! no booking dates will result in null time
BlackMisc::PhysicalQuantities::CTime bookedWhen() const;
//! Get ATIS

View File

@@ -37,7 +37,7 @@ namespace BlackMisc
PhysicalQuantities::CLength calculateGreatCircleDistance(const ICoordinateGeodetic &coordinate1, const ICoordinateGeodetic &coordinate2)
{
// same coordinate results in 0 distance
// same coordinates results in 0 distance
if (coordinate1.latitude() == coordinate2.latitude() && coordinate1.longitude() == coordinate2.longitude())
{
return CLength(0, CLengthUnit::m());
@@ -58,6 +58,7 @@ namespace BlackMisc
double c = 2.0 * qAtan(qSqrt(a) / qSqrt(1.0 - a));
double distance = earthRadiusM * c;
Q_ASSERT_X(distance >= 0, Q_FUNC_INFO, "distance < 0");
return CLength(distance, CLengthUnit::m());
}

View File

@@ -121,8 +121,8 @@ namespace BlackMisc
//! Constructor
ICoordinateWithRelativePosition();
BlackMisc::PhysicalQuantities::CAngle m_bearingToOwnAircraft; //!< temporary stored value
BlackMisc::PhysicalQuantities::CLength m_distanceToOwnAircraft; //!< temporary stored value
BlackMisc::PhysicalQuantities::CAngle m_bearingToOwnAircraft {0.0, BlackMisc::PhysicalQuantities::CAngleUnit::nullUnit()}; //!< temporary stored value
BlackMisc::PhysicalQuantities::CLength m_distanceToOwnAircraft {0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< temporary stored value
};