From 0a4c47c8009711e9b81297b537dd5c793fe068ad Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 28 May 2014 01:27:52 +0200 Subject: [PATCH] refs #250, formatting, minor tweaks and fixes * changed return type for updateFromVatsimDataFileStation * improved resolution for own aircraft * convenience method findFirstByCallsign * automatically convert frequency to MHz for ATC station * improved output in toQString * GUI, flight plan formatting * corrected logging for network context * override keyword in listmodelbase --- src/blackcore/context_network_impl.h | 6 +-- src/blackgui/flightplancomponent.ui | 77 ++++++++++++++++++---------- src/blackgui/listmodelbase.cpp | 2 +- src/blackgui/listmodelbase.h | 12 ++--- src/blackmisc/avatcstation.cpp | 11 +++- src/blackmisc/avatcstation.h | 2 +- src/blackmisc/avatcstationlist.cpp | 48 ++++++++--------- src/blackmisc/avatcstationlist.h | 5 +- src/blackmisc/avcallsignlist.h | 16 ++---- 9 files changed, 105 insertions(+), 74 deletions(-) diff --git a/src/blackcore/context_network_impl.h b/src/blackcore/context_network_impl.h index 52c56ba65..ac29d2210 100644 --- a/src/blackcore/context_network_impl.h +++ b/src/blackcore/context_network_impl.h @@ -62,21 +62,21 @@ namespace BlackCore //! \copydoc IContextNetwork::getAtcStationsOnline() virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override { - // this->log(Q_FUNC_INFO); + if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); return m_atcStationsOnline; } //! \copydoc IContextNetwork::getAtcStationsBooked() virtual const BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override { - // this->log(Q_FUNC_INFO); + if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); return m_atcStationsBooked; } //! \copydoc IContextNetwork::getAircraftsInRange() virtual const BlackMisc::Aviation::CAircraftList getAircraftsInRange() const override { - // this->log(Q_FUNC_INFO); + if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); return m_aircraftsInRange; } diff --git a/src/blackgui/flightplancomponent.ui b/src/blackgui/flightplancomponent.ui index 748089346..88f71a695 100644 --- a/src/blackgui/flightplancomponent.ui +++ b/src/blackgui/flightplancomponent.ui @@ -236,32 +236,6 @@ - - - - 1. Type - - - - - - VFR - - - - - - - IFR - - - true - - - - - - @@ -396,6 +370,57 @@ + + + + + + + true + + + + 2 + + + 4 + + + 2 + + + 2 + + + 2 + + + + + VFR + + + + + + + IFR + + + true + + + + + + + + + + 1. Type + + + diff --git a/src/blackgui/listmodelbase.cpp b/src/blackgui/listmodelbase.cpp index fc58df6f6..05b283068 100644 --- a/src/blackgui/listmodelbase.cpp +++ b/src/blackgui/listmodelbase.cpp @@ -117,7 +117,7 @@ namespace BlackGui QModelIndex i1 = index.sibling(index.row(), 0); QModelIndex i2 = index.sibling(index.row(), this->columnCount(index) - 1); - emit this->dataChanged(i1, i2); + emit this->dataChanged(i1, i2); // which range has been changed } /* diff --git a/src/blackgui/listmodelbase.h b/src/blackgui/listmodelbase.h index 9827a7370..c119840dc 100644 --- a/src/blackgui/listmodelbase.h +++ b/src/blackgui/listmodelbase.h @@ -49,17 +49,17 @@ namespace BlackGui virtual ~CListModelBase() {} //! \copydoc QAbstractListModel::columnCount() - virtual int columnCount(const QModelIndex &modelIndex) const; + virtual int columnCount(const QModelIndex &modelIndex) const override; //! \copydoc QAbstractItemModel::headerData() - virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; //! Column to property index virtual int columnToPropertyIndex(int column) const; //! Index to property index virtual int indexToPropertyIndex(const QModelIndex &index) const - { + { return this->columnToPropertyIndex(index.column()); } @@ -103,10 +103,10 @@ namespace BlackGui } //! \copydoc QAbstractListModel::data() - virtual QVariant data(const QModelIndex &index, int role) const; + virtual QVariant data(const QModelIndex &index, int role) const override; //! \copydoc QAbstractListModel::rowCount() - virtual int rowCount(const QModelIndex &index = QModelIndex()) const; + virtual int rowCount(const QModelIndex &index = QModelIndex()) const override; //! \copydoc QAbstractTableModel::flags Qt::ItemFlags flags(const QModelIndex &index) const override; @@ -142,6 +142,6 @@ namespace BlackGui //! Clear the list virtual void clear(); - }; +}; } #endif // guard diff --git a/src/blackmisc/avatcstation.cpp b/src/blackmisc/avatcstation.cpp index 664344ab1..a76eea8e6 100644 --- a/src/blackmisc/avatcstation.cpp +++ b/src/blackmisc/avatcstation.cpp @@ -78,7 +78,7 @@ namespace BlackMisc // frequency s.append(' '); - s.append(this->m_frequency.toQString(i18n)); + s.append(this->m_frequency.valueRoundedWithUnit(3, i18n)); // ATIS if (this->hasAtis()) @@ -103,6 +103,7 @@ namespace BlackMisc // distance to plane if (this->m_distanceToPlane.isPositiveWithEpsilonConsidered()) { + s.append(' '); i18n ? s.append(QCoreApplication::translate("Aviation", "distance")) : s.append("distance"); s.append(' '); s.append(this->m_distanceToPlane.toQString(i18n)); @@ -232,6 +233,14 @@ namespace BlackMisc return !((*this) == other); } + /* + * Frequency + */ + void CAtcStation::setFrequency(const CFrequency &frequency) { + this->m_frequency = frequency; + this->m_frequency.setUnit(CFrequencyUnit::MHz()); + } + /* * SyncronizeControllerData */ diff --git a/src/blackmisc/avatcstation.h b/src/blackmisc/avatcstation.h index 76087af5e..7e01da4c9 100644 --- a/src/blackmisc/avatcstation.h +++ b/src/blackmisc/avatcstation.h @@ -143,7 +143,7 @@ namespace BlackMisc const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; } //! Set frequency - void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { this->m_frequency = frequency; } + void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency); //! Get the position of the center of the controller's area of visibility. const BlackMisc::Geo::CCoordinateGeodetic &getPosition() const { return m_position; } diff --git a/src/blackmisc/avatcstationlist.cpp b/src/blackmisc/avatcstationlist.cpp index 7accf9dbf..7208aa644 100644 --- a/src/blackmisc/avatcstationlist.cpp +++ b/src/blackmisc/avatcstationlist.cpp @@ -46,6 +46,16 @@ namespace BlackMisc return this->findBy(&CAtcStation::getCallsign, callsign); } + /* + * Find first by callsign + */ + CAtcStation CAtcStationList::findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound) const + { + CAtcStationList stations = findByCallsign(callsign); + if (!stations.isEmpty()) return stations[0]; + return ifNotFound; + } + /* * Stations within range */ @@ -178,35 +188,27 @@ namespace BlackMisc /* * Merge with VATSIM data file */ - int CAtcStationList::updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const + bool CAtcStationList::updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const { - if (this->isEmpty()) return 0; + if (this->isEmpty()) return false; if (stationToBeUpdated.hasValidRealName() && stationToBeUpdated.hasValidId() && stationToBeUpdated.hasValidFrequency()) return 0; - int c = 0; - for (auto i = this->begin(); i != this->end(); ++i) + CAtcStation dataFileStation = this->findFirstByCallsign(stationToBeUpdated.getCallsign()); + if (dataFileStation.getCallsign().isEmpty()) return false; // not found + + if (!stationToBeUpdated.hasValidRealName() || !stationToBeUpdated.hasValidId()) { - CAtcStation currentDataFileStation = *i; - if (currentDataFileStation.getCallsign() != stationToBeUpdated.getCallsign()) continue; - - if (!stationToBeUpdated.hasValidRealName() || !stationToBeUpdated.hasValidId()) - { - CUser user = stationToBeUpdated.getController(); - if (!stationToBeUpdated.hasValidRealName()) user.setRealName(currentDataFileStation.getControllerRealName()); - if (!stationToBeUpdated.hasValidId()) user.setId(currentDataFileStation.getControllerId()); - stationToBeUpdated.setController(user); - } - - if (!stationToBeUpdated.hasValidFrequency()) - { - stationToBeUpdated.setFrequency(currentDataFileStation.getFrequency()); - } - c++; + CUser user = stationToBeUpdated.getController(); + if (!stationToBeUpdated.hasValidRealName()) user.setRealName(dataFileStation.getControllerRealName()); + if (!stationToBeUpdated.hasValidId()) user.setId(dataFileStation.getControllerId()); + stationToBeUpdated.setController(user); } - // normally 1 expected, as I should find - // only one online station for this booking - return c; + if (!stationToBeUpdated.hasValidFrequency()) + { + stationToBeUpdated.setFrequency(dataFileStation.getFrequency()); + } + return true; } } // namespace } // namespace diff --git a/src/blackmisc/avatcstationlist.h b/src/blackmisc/avatcstationlist.h index a6b254980..e47a1282d 100644 --- a/src/blackmisc/avatcstationlist.h +++ b/src/blackmisc/avatcstationlist.h @@ -43,6 +43,9 @@ namespace BlackMisc //! Find 0..n stations by callsign CAtcStationList findByCallsign(const CCallsign &callsign) const; + //! Find first station by callsign, if not return given value / default + CAtcStation findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound = CAtcStation()) const; + //! Find 0..n stations within range of given coordinate CAtcStationList findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const; @@ -64,7 +67,7 @@ namespace BlackMisc //! Merge with the data from the VATSIM data file //! \remarks Can be used if the stored data in this list are VATSIM data file stations - int updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const; + bool updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const; }; } //namespace diff --git a/src/blackmisc/avcallsignlist.h b/src/blackmisc/avcallsignlist.h index 08bf38f7d..41d9ecb5e 100644 --- a/src/blackmisc/avcallsignlist.h +++ b/src/blackmisc/avcallsignlist.h @@ -25,27 +25,19 @@ namespace BlackMisc class CCallsignList : public CSequence { public: - /*! - * \brief Default constructor. - */ + //! Default constructor. CCallsignList(); - /*! - * \brief Construct from a base class object. - */ + //! Construct from a base class object. CCallsignList(const CSequence &other); - /*! - * \copydoc CValueObject::toQVariant() - */ + //! CValueObject::toQVariant() virtual QVariant toQVariant() const { return QVariant::fromValue(*this); } - /*! - * \brief Register metadata - */ + //! Register metadata static void registerMetadata(); };