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
This commit is contained in:
Klaus Basan
2014-05-28 01:27:52 +02:00
parent 6353edd50a
commit 0a4c47c800
9 changed files with 105 additions and 74 deletions

View File

@@ -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
*/

View File

@@ -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; }

View File

@@ -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

View File

@@ -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

View File

@@ -25,27 +25,19 @@ namespace BlackMisc
class CCallsignList : public CSequence<CCallsign>
{
public:
/*!
* \brief Default constructor.
*/
//! Default constructor.
CCallsignList();
/*!
* \brief Construct from a base class object.
*/
//! Construct from a base class object.
CCallsignList(const CSequence<CCallsign> &other);
/*!
* \copydoc CValueObject::toQVariant()
*/
//! CValueObject::toQVariant()
virtual QVariant toQVariant() const
{
return QVariant::fromValue(*this);
}
/*!
* \brief Register metadata
*/
//! Register metadata
static void registerMetadata();
};