diff --git a/src/blackgui/models/atcstationlistmodel.cpp b/src/blackgui/models/atcstationlistmodel.cpp index 4a61f2324..9d2ca2173 100644 --- a/src/blackgui/models/atcstationlistmodel.cpp +++ b/src/blackgui/models/atcstationlistmodel.cpp @@ -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()))); diff --git a/src/blackgui/models/clientlistmodel.cpp b/src/blackgui/models/clientlistmodel.cpp index 463e603e2..45c791203 100644 --- a/src/blackgui/models/clientlistmodel.cpp +++ b/src/blackgui/models/clientlistmodel.cpp @@ -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 diff --git a/src/blackgui/models/columnformatters.cpp b/src/blackgui/models/columnformatters.cpp index 3d4afdcab..40a932e18 100644 --- a/src/blackgui/models/columnformatters.cpp +++ b/src/blackgui/models/columnformatters.cpp @@ -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) : diff --git a/src/blackgui/models/columnformatters.h b/src/blackgui/models/columnformatters.h index da649e522..5b2af7af4 100644 --- a/src/blackgui/models/columnformatters.h +++ b/src/blackgui/models/columnformatters.h @@ -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()); diff --git a/src/blackgui/models/simulatedaircraftlistmodel.cpp b/src/blackgui/models/simulatedaircraftlistmodel.cpp index 3f8b82e6e..c30e48918 100644 --- a/src/blackgui/models/simulatedaircraftlistmodel.cpp +++ b/src/blackgui/models/simulatedaircraftlistmodel.cpp @@ -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})); diff --git a/src/blackmisc/aviation/atcstation.cpp b/src/blackmisc/aviation/atcstation.cpp index 99c65c109..85ad38262 100644 --- a/src/blackmisc/aviation/atcstation.cpp +++ b/src/blackmisc/aviation/atcstation.cpp @@ -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: diff --git a/src/blackmisc/aviation/atcstation.h b/src/blackmisc/aviation/atcstation.h index 6b2c7ed8e..d2a0d99c4 100644 --- a/src/blackmisc/aviation/atcstation.h +++ b/src/blackmisc/aviation/atcstation.h @@ -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 @@ -282,7 +264,7 @@ BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAtcStation, ( o.m_voiceRoom, o.m_distanceToOwnAircraft, o.m_bearingToOwnAircraft - )) + )) Q_DECLARE_METATYPE(BlackMisc::Aviation::CAtcStation) #endif // guard diff --git a/src/blackmisc/geo/coordinategeodetic.cpp b/src/blackmisc/geo/coordinategeodetic.cpp index 84dc17d70..909ac07cd 100644 --- a/src/blackmisc/geo/coordinategeodetic.cpp +++ b/src/blackmisc/geo/coordinategeodetic.cpp @@ -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()); } diff --git a/src/blackmisc/geo/coordinategeodetic.h b/src/blackmisc/geo/coordinategeodetic.h index b1c61a476..2f5f1402b 100644 --- a/src/blackmisc/geo/coordinategeodetic.h +++ b/src/blackmisc/geo/coordinategeodetic.h @@ -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 };