From 22a79625d15d6b1bb52a71eb43648bc155391ea0 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 25 Jan 2014 01:36:49 +0100 Subject: [PATCH] Added callsign to user object: * Changed user class * Updated ATC station / aircraft to keep callsigns in sync * Updated user list model for GUI --- src/blackgui/userlistmodel.cpp | 2 ++ src/blackmisc/avaircraft.h | 66 ++++++---------------------------- src/blackmisc/avatcstation.h | 41 ++++----------------- src/blackmisc/nwuser.cpp | 16 ++++++++- src/blackmisc/nwuser.h | 33 +++++++++++++---- 5 files changed, 60 insertions(+), 98 deletions(-) diff --git a/src/blackgui/userlistmodel.cpp b/src/blackgui/userlistmodel.cpp index df202a3bc..34337e73c 100644 --- a/src/blackgui/userlistmodel.cpp +++ b/src/blackgui/userlistmodel.cpp @@ -14,10 +14,12 @@ namespace BlackGui CListModelBase("ViewUserList", parent) { this->m_columns.addColumn(CUser::IndexRealName, "realname"); + this->m_columns.addColumn(CUser::IndexCallsign, "callsign"); this->m_columns.addColumn(CUser::IndexId, "userid"); this->m_columns.addColumn(CUser::IndexEmail, "email"); // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("ViewUserList", "callsign"); (void)QT_TRANSLATE_NOOP("ViewUserList", "realname"); (void)QT_TRANSLATE_NOOP("ViewUserList", "userid"); (void)QT_TRANSLATE_NOOP("ViewUserList", "email"); diff --git a/src/blackmisc/avaircraft.h b/src/blackmisc/avaircraft.h index df248cd36..2db7cb1f6 100644 --- a/src/blackmisc/avaircraft.h +++ b/src/blackmisc/avaircraft.h @@ -40,7 +40,6 @@ namespace BlackMisc /*! * \brief QVariant, required for DBus QVariant lists - * \return */ virtual QVariant toQVariant() const { @@ -49,80 +48,67 @@ namespace BlackMisc /*! * Get callsign. - * \return */ const CCallsign &getCallsign() const { return m_callsign; } /*! * Get callsign. - * \return */ QString getCallsignAsString() const { return m_callsign.asString(); } /*! * Set callsign - * \param callsign */ - void setCallsign(const CCallsign &callsign) { this->m_callsign = callsign; } + void setCallsign(const CCallsign &callsign) { this->m_callsign = callsign; this->m_pilot.setCallsign(callsign); } /*! * Get situation. - * \return */ const CAircraftSituation &getSituation() const { return m_situation; } /*! * Set situation. - * \param */ void setSituation(const CAircraftSituation &situation) { m_situation = situation; } /*! * Get user - * \return */ const BlackMisc::Network::CUser &getPilot() const { return m_pilot; } /*! * \brief Set user - * \param password */ - void setPilot(const BlackMisc::Network::CUser &user) { m_pilot = user; } + void setPilot(const BlackMisc::Network::CUser &user) { m_pilot = user; this->m_pilot.setCallsign(this->m_callsign);} /*! * Get ICAO info - * \return */ const CAircraftIcao &getIcaoInfo() const { return m_icao; } /*! * \brief Set ICAO info - * \param icao */ void setIcaoInfo(const CAircraftIcao &icao) { m_icao = icao; } /*! * Get the distance to own plane - * \return */ const BlackMisc::PhysicalQuantities::CLength &getDistanceToPlane() const { return m_distanceToPlane; } /*! * Set distance to own plane - * \param range */ void setDistanceToPlane(const BlackMisc::PhysicalQuantities::CLength &distance) { this->m_distanceToPlane = distance; } /*! * \brief Valid distance? - * \return */ bool hasValidDistance() const { return !this->m_distanceToPlane.isNegativeWithEpsilonConsidered();} /*! * \brief Calculcate distance to plane, set it, and also return it - * \param position - * \return + * \param position calculated from this postion to my own aircraft */ const BlackMisc::PhysicalQuantities::CLength &calculcateDistanceToPlane(const BlackMisc::Geo::CCoordinateGeodetic &position); @@ -134,73 +120,61 @@ namespace BlackMisc /*! * \brief Set position - * \param position */ void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_situation.setPosition(position); } /*! * \brief Get altitude - * \return */ const BlackMisc::Aviation::CAltitude &getAltitude() const { return this->m_situation.getAltitude(); } /*! * \brief Set altitude - * \param altitude */ void setAltitude(const BlackMisc::Aviation::CAltitude &altitude) { this->m_situation.setAltitude(altitude); } /*! * \brief Get groundspeed - * \return */ const BlackMisc::PhysicalQuantities::CSpeed &getGroundSpeed() const { return this->m_situation.getGroundSpeed(); } /*! * \brief Get latitude - * \return */ virtual const BlackMisc::Geo::CLatitude &latitude() const { return this->m_situation.latitude(); } /*! * \brief Get longitude - * \return */ virtual const BlackMisc::Geo::CLongitude &longitude() const { return this->m_situation.longitude(); } /*! - * \brief Get height - * \return + * \brief Get height (height of current position) */ const BlackMisc::PhysicalQuantities::CLength &getHeight() const { return this->m_situation.getHeight(); } /*! * \brief Get heading - * \return */ const BlackMisc::Aviation::CHeading &getHeading() const { return this->m_situation.getHeading(); } /*! * \brief Get pitch - * \return */ const BlackMisc::PhysicalQuantities::CAngle &getPitch() const { return this->m_situation.getPitch(); } /*! * \brief Get bank - * \return */ const BlackMisc::PhysicalQuantities::CAngle &getBank() const { return this->m_situation.getBank(); } /*! * \brief Get COM1 system - * \return */ const BlackMisc::Aviation::CComSystem &getCom1System() const { return this->m_com1system; } /*! * \brief Get COM2 system - * \return */ const BlackMisc::Aviation::CComSystem &getCom2System() const { return this->m_com2system; } @@ -216,7 +190,6 @@ namespace BlackMisc /*! * \brief Get transponder - * \return */ const BlackMisc::Aviation::CTransponder &getTransponder() const { return this->m_transponder; } @@ -227,25 +200,21 @@ namespace BlackMisc /*! * \brief Get transponder code - * \return */ QString getTransponderCodeFormatted() const { return this->m_transponder.getTransponderCodeFormatted(); } /*! * \brief Get transponder code - * \return */ qint32 getTransponderCode() const { return this->m_transponder.getTransponderCode(); } /*! * \brief Get transponder mode - * \return */ BlackMisc::Aviation::CTransponder::TransponderMode getTransponderMode() const { return this->m_transponder.getTransponderMode(); } /*! - * \brief Is valid for login - * \return + * \brief Is valid for login? */ bool isValidForLogin() const; @@ -261,8 +230,6 @@ namespace BlackMisc /*! * \brief Equal operator == - * \param other - * \return */ bool operator ==(const CAircraft &other) const; @@ -303,32 +270,23 @@ namespace BlackMisc }; /*! - * \brief Property by index - * \param index - * \return + * \copydoc CValueObject::propertyByIndex() */ virtual QVariant propertyByIndex(int index) const; /*! - * \brief Property by index as string - * \param index - * \param i18n - * \return + * \copydoc CValueObject::propertyByIndexAsString() */ virtual QString propertyByIndexAsString(int index, bool i18n) const; /*! - * \brief Property by index (setter) - * \param variant - * \param index + * \copydoc CValueObject::setPropertyByIndex() */ virtual void setPropertyByIndex(const QVariant &variant, int index); protected: /*! - * \brief Rounded value as string - * \param i18n - * \return + * \copydoc CValueObject::convertToQString() */ virtual QString convertToQString(bool i18n = false) const; @@ -348,14 +306,12 @@ namespace BlackMisc virtual int compareImpl(const CValueObject &other) const; /*! - * \brief Stream to DBus << - * \param argument + * \copydoc CValueObject::marshallToDbus() */ virtual void marshallToDbus(QDBusArgument &argument) const; /*! - * \brief Stream from DBus >> - * \param argument + * \copydoc CValueObject::marshallFromDbus() */ virtual void unmarshallFromDbus(const QDBusArgument &argument); diff --git a/src/blackmisc/avatcstation.h b/src/blackmisc/avatcstation.h index b87353790..dda2fa73b 100644 --- a/src/blackmisc/avatcstation.h +++ b/src/blackmisc/avatcstation.h @@ -63,27 +63,17 @@ namespace BlackMisc }; /*! - * Default constructor. + * \brief Default constructor. */ CAtcStation(); /*! * \brief Simplified constructor - * \param callsign */ CAtcStation(const QString &callsign); /*! - * \brief ATC station - * \param callsign - * \param controllerName - * \param freq - * \param pos - * \param range - * \param isOnline - * \param bookedFromUtc - * \param bookedUntilUtc - * \param atis + * \brief ATC station constructor */ CAtcStation(const CCallsign &callsign, const BlackMisc::Network::CUser &controller, const BlackMisc::PhysicalQuantities::CFrequency &frequency, @@ -92,8 +82,7 @@ namespace BlackMisc const CInformationMessage &atis = CInformationMessage(CInformationMessage::ATIS), const CInformationMessage &metar = CInformationMessage(CInformationMessage::METAR)); /*! - * \brief Virtual method to return QVariant, used with DBUS QVariant lists - * \return + * \copydoc CValueObject::toQVariant() */ virtual QVariant toQVariant() const { @@ -102,21 +91,16 @@ namespace BlackMisc /*! * \brief Equal operator == - * \param other - * @return */ bool operator ==(const CAtcStation &other) const; /*! * \brief Unequal operator == - * \param other - * @return */ bool operator !=(const CAtcStation &other) const; /*! * \brief Has booking times? - * \return */ bool hasBookingTimes() const { @@ -125,7 +109,6 @@ namespace BlackMisc /*! * \brief Has ATIS? - * \return */ bool hasAtis() const { @@ -134,7 +117,6 @@ namespace BlackMisc /*! * \brief Has Metar? - * \return */ bool hasMetar() const { @@ -148,16 +130,14 @@ namespace BlackMisc const CCallsign &getCallsign() const { return m_callsign; } /*! - * Get callsign. - * \return + * Get callsign as string. */ QString getCallsignAsString() const { return m_callsign.asString(); } /*! * Set callsign - * \param callsign */ - void setCallsign(const CCallsign &callsign) { this->m_callsign = callsign; } + void setCallsign(const CCallsign &callsign) { this->m_callsign = callsign; this->m_controller.setCallsign(callsign);} /*! * Get controller @@ -181,7 +161,7 @@ namespace BlackMisc * Set controller * \param controller */ - void setController(const BlackMisc::Network::CUser &controller) { this->m_controller = controller; } + void setController(const BlackMisc::Network::CUser &controller) { this->m_controller = controller; this->m_controller.setCallsign(this->m_callsign); } /*! * Set controller's name @@ -191,37 +171,31 @@ namespace BlackMisc /*! * Set controller's id - * \param controllerId */ void setControllerId(const QString &controllerId) { this->m_controller.setId(controllerId); } /*! * \brief Has valid realname? - * \return */ bool hasValidRealName() const { return this->m_controller.hasValidRealName(); } /*! * \brief Has valid id? - * \return */ bool hasValidId() const { return this->m_controller.hasValidId(); } /*! * Get frequency. - * \return */ const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; } /*! * Set frequency - * \param frequency */ void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { this->m_frequency = frequency; } /*! * Get the position of the center of the controller's area of visibility. - * \return */ const BlackMisc::Geo::CCoordinateGeodetic &getPosition() const { return m_position; } @@ -252,19 +226,16 @@ namespace BlackMisc /*! * Get the distance to own plane - * \return */ const BlackMisc::PhysicalQuantities::CLength &getDistanceToPlane() const { return m_distanceToPlane; } /*! * Set distance to own plane - * \param range */ void setDistanceToPlane(const BlackMisc::PhysicalQuantities::CLength &distance) { this->m_distanceToPlane = distance; } /*! * \brief Valid distance? - * \return */ bool hasValidDistance() const { return !this->m_distanceToPlane.isNegativeWithEpsilonConsidered();} diff --git a/src/blackmisc/nwuser.cpp b/src/blackmisc/nwuser.cpp index 69e9aa41b..8f33e70f7 100644 --- a/src/blackmisc/nwuser.cpp +++ b/src/blackmisc/nwuser.cpp @@ -62,6 +62,7 @@ namespace BlackMisc argument << this->m_realname; argument << this->m_email; argument << this->m_password; + argument << this->m_callsign; } /* @@ -73,6 +74,7 @@ namespace BlackMisc argument >> this->m_realname; argument >> this->m_email; argument >> this->m_password; + argument >> this->m_callsign; } /* @@ -83,7 +85,8 @@ namespace BlackMisc if (this == &other) return true; return (this->m_id == other.m_id && this->m_realname == other.m_realname && - this->m_email == other.m_email); + this->m_email == other.m_email && + this->m_callsign == other.m_callsign); } /* @@ -107,6 +110,11 @@ namespace BlackMisc otherUser.setEmail(this->getEmail()); else if (otherUser.hasValidEmail()) this->setEmail(otherUser.getEmail()); + + if (this->hasValidCallsign()) + otherUser.setCallsign(this->getCallsign()); + else if (otherUser.hasValidCallsign()) + this->setCallsign(otherUser.getCallsign()); } /* @@ -126,6 +134,7 @@ namespace BlackMisc hashs << qHash(this->m_id); hashs << qHash(this->m_realname); hashs << qHash(this->m_email); + hashs << qHash(this->m_callsign.getValueHash()); return BlackMisc::calculateHash(hashs, "CUser"); } @@ -153,6 +162,8 @@ namespace BlackMisc return QVariant(this->m_password); case IndexRealName: return QVariant(this->m_realname); + case IndexCallsign: + return this->m_callsign.toQVariant(); default: break; } @@ -181,6 +192,9 @@ namespace BlackMisc case IndexRealName: this->setRealName(variant.value()); break; + case IndexCallsign: + this->setCallsign(variant.value()); + break; default: Q_ASSERT_X(false, "CUser", "index unknown (setter)"); break; diff --git a/src/blackmisc/nwuser.h b/src/blackmisc/nwuser.h index cda370957..43d862a8e 100644 --- a/src/blackmisc/nwuser.h +++ b/src/blackmisc/nwuser.h @@ -9,7 +9,8 @@ #ifndef BLACKMISC_USER_H #define BLACKMISC_USER_H -#include "valueobject.h" + +#include "avcallsign.h" namespace BlackMisc { @@ -30,7 +31,8 @@ namespace BlackMisc IndexEmail, IndexId, IndexPassword, - IndexRealName + IndexRealName, + IndexCallsign }; /*! @@ -94,6 +96,11 @@ namespace BlackMisc */ bool hasValidId() const { return !this->m_id.isEmpty(); } + /*! + * Has associated callsign? + */ + bool hasValidCallsign() const { return !m_callsign.isEmpty(); } + /*! * Get email. */ @@ -104,21 +111,32 @@ namespace BlackMisc */ void setEmail(const QString &email) { m_email = email.trimmed(); } - /*! - * Get id. - */ - QString getId() const { return m_id; } - /*! * \brief Valid email? */ bool hasValidEmail() const { return !this->m_email.isEmpty(); } + /*! + * Get id. + */ + QString getId() const { return m_id; } + /*! * \brief Set id */ void setId(const QString &id) { m_id = id.trimmed(); } + /*! + * Get associated callsign. + */ + BlackMisc::Aviation::CCallsign getCallsign() const { return m_callsign; } + + /*! + * \brief Set associated callsign + * \param callsign + */ + void setCallsign(const BlackMisc::Aviation::CCallsign &callsign) { m_callsign = callsign; } + /*! * \brief Equal operator == */ @@ -196,6 +214,7 @@ namespace BlackMisc QString m_realname; QString m_email; QString m_password; + BlackMisc::Aviation::CCallsign m_callsign; }; } // namespace } // namespace