Ref T215, some adjustments of user object

* remove "valid" from some functions, because no validity is checked
* homebase + real name string
This commit is contained in:
Klaus Basan
2018-01-03 20:13:47 +01:00
parent b2c0d726bc
commit 2fb7bde447
10 changed files with 45 additions and 37 deletions

View File

@@ -193,7 +193,7 @@ namespace BlackGui
if (m_flightPlan.wasSentOrLoaded()) { return; }
// only override with valid values
if (user.hasValidRealName())
if (user.hasRealName())
{
ui->le_PilotsName->setText(user.getRealName());
}
@@ -201,7 +201,7 @@ namespace BlackGui
{
ui->le_PilotsHomeBase->setText(user.getHomeBase().getIcaoCode());
}
if (user.hasValidCallsign())
if (user.hasCallsign())
{
ui->le_Callsign->setText(user.getCallsign().asString());
}

View File

@@ -351,7 +351,7 @@ namespace BlackGui
{
const CServer lastServer = m_lastVatsimServer.get();
const CUser lastUser = lastServer.getUser();
if (lastUser.hasValidCallsign())
if (lastUser.hasCallsign())
{
ui->le_Callsign->setText(lastUser.getCallsign().asString());
ui->le_VatsimId->setText(lastUser.getId());

View File

@@ -110,7 +110,7 @@ namespace BlackGui
aircraft.getAircraftIcaoCode().toQString(false) %
QLatin1String(")");
}
if (aircraft.hasValidRealName())
if (aircraft.hasRealName())
{
i += QLatin1String(" - ") % aircraft.getPilotRealName();
}

View File

@@ -49,7 +49,7 @@ namespace BlackMisc
{
// sync callsigns
m_callsign.setTypeHint(CCallsign::Atc);
if (!m_controller.hasValidCallsign() && !callsign.isEmpty())
if (!m_controller.hasCallsign() && !callsign.isEmpty())
{
m_controller.setCallsign(m_callsign);
}

View File

@@ -117,13 +117,13 @@ namespace BlackMisc
void setControllerId(const QString &controllerId) { m_controller.setId(controllerId); }
//! Has valid realname?
bool hasValidRealName() const { return m_controller.hasValidRealName(); }
bool hasRealName() const { return m_controller.hasRealName(); }
//! Has valid id?
bool hasValidId() const { return m_controller.hasValidId(); }
bool hasId() const { return m_controller.hasId(); }
//! Valid COM frequency
bool hasValidFrequency() const { return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->getFrequency()); }
bool hasValidFrequency() const { return CComSystem::isValidCivilAviationFrequency(this->getFrequency()); }
//! Get frequency.
const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }

View File

@@ -35,7 +35,7 @@ namespace BlackMisc
bool CClient::isValid() const
{
return m_user.hasValidCallsign();
return m_user.hasCallsign();
}
void CClient::setCapability(bool hasCapability, CClient::Capabilities capability)

View File

@@ -20,6 +20,7 @@
#include <QThreadStorage>
#include <Qt>
#include <QtGlobal>
#include <QStringBuilder>
using namespace BlackMisc::Aviation;
@@ -47,6 +48,13 @@ namespace BlackMisc
this->setRealName(realname); // extracts homebase
}
QString CUser::getRealNameAndHomeBase(const QString &separator) const
{
if (!this->hasHomeBase()) { return this->getRealName(); }
if (!this->hasRealName()) { return this->getHomeBase().asString(); }
return this->getRealName() % separator % this->getHomeBase().asString();
}
void CUser::setCallsign(const CCallsign &callsign)
{
m_callsign = callsign;
@@ -58,13 +66,13 @@ namespace BlackMisc
Q_UNUSED(i18n);
if (m_realname.isEmpty()) return "<no realname>";
QString s = m_realname;
if (this->hasValidId())
if (this->hasId())
{
s.append(" (").append(m_id).append(')');
s += QStringLiteral(" (") % m_id % QStringLiteral(")");
}
if (this->hasValidCallsign())
if (this->hasCallsign())
{
s.append(' ').append(this->getCallsign().getStringAsSet());
s += QStringLiteral(" ") % this->getCallsign().getStringAsSet();
}
return s;
}
@@ -86,11 +94,11 @@ namespace BlackMisc
QString rn(removeAccents(realname.trimmed().simplified()));
if (rn.isEmpty())
{
m_realname = "";
m_realname.clear();
return;
}
if (!this->hasValidHomebase())
if (!this->hasHomeBase())
{
// only apply stripping if home base is not explicitly given
// try to strip homebase: I understand the limitations, but we will have more correct hits as failures I assume
@@ -115,8 +123,8 @@ namespace BlackMisc
{
CStatusMessageList msgs;
// callsign optional
if (!this->hasValidId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
if (!this->hasValidRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
if (!this->hasId()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid id"));}
if (!this->hasRealName()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid real name"));}
if (!this->hasValidCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
return msgs;
}
@@ -124,10 +132,10 @@ namespace BlackMisc
void CUser::updateMissingParts(const CUser &otherUser)
{
if (this == &otherUser) { return; }
if (!this->hasValidRealName()) { this->setRealName(otherUser.getRealName()); }
if (!this->hasValidId()) { this->setId(otherUser.getId()); }
if (!this->hasRealName()) { this->setRealName(otherUser.getRealName()); }
if (!this->hasId()) { this->setId(otherUser.getId()); }
if (!this->hasValidEmail()) { this->setEmail(otherUser.getEmail()); }
if (!this->hasValidCallsign()) { this->setCallsign(otherUser.getCallsign()); }
if (!this->hasCallsign()) { this->setCallsign(otherUser.getCallsign()); }
}
void CUser::synchronizeData(CUser &otherUser)
@@ -141,7 +149,7 @@ namespace BlackMisc
{
if (id.isEmpty()) { return false; }
bool ok;
int i = id.toInt(&ok);
const int i = id.toInt(&ok);
if (!ok) { return false; }
return i >= 100000 && i <= 9999999;
}

View File

@@ -61,13 +61,13 @@ namespace BlackMisc
CUser(const QString &id, const QString &realname, const QString &email = "", const QString &password = "", const Aviation::CCallsign &callsign = {});
//! Get full name.
QString getRealName() const { return m_realname; }
const QString &getRealName() const { return m_realname; }
//! setRealName
//! Set real name
void setRealName(const QString &realname);
//! Get password
QString getPassword() const { return m_password; }
const QString &getPassword() const { return m_password; }
//! Set password
void setPassword(const QString &pw) { m_password = pw.trimmed(); }
@@ -79,22 +79,25 @@ namespace BlackMisc
bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
//! Valid real name?
bool hasValidRealName() const { return !m_realname.isEmpty(); }
bool hasRealName() const { return !m_realname.isEmpty(); }
//! Valid id?
bool hasValidId() const { return !m_id.isEmpty(); }
bool hasId() const { return !m_id.isEmpty(); }
//! Has associated callsign?
bool hasValidCallsign() const { return !m_callsign.isEmpty(); }
bool hasCallsign() const { return !m_callsign.isEmpty(); }
//! Valid homebase
bool hasValidHomebase() const { return !m_homebase.isEmpty(); }
//! Has home base?
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
//! Real name + homebase
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;
//! Validate, provide details about issues
CStatusMessageList validate() const;
//! Get email.
QString getEmail() const { return m_email; }
const QString &getEmail() const { return m_email; }
//! Set email.
void setEmail(const QString &email) { m_email = email.trimmed(); }
@@ -103,7 +106,7 @@ namespace BlackMisc
bool hasValidEmail() const { return !m_email.isEmpty(); }
//! Get id.
QString getId() const { return m_id; }
const QString &getId() const { return m_id; }
//! Set id
void setId(const QString &id) { m_id = id.trimmed(); }
@@ -114,9 +117,6 @@ namespace BlackMisc
//! Set homebase
void setHomeBase(const Aviation::CAirportIcaoCode &homebase) { m_homebase = homebase; }
//! Has home base?
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
//! Get associated callsign.
const Aviation::CCallsign &getCallsign() const { return m_callsign; }

View File

@@ -153,10 +153,10 @@ namespace BlackMisc
void setAircraftIcaoDesignator(const QString &designator);
//! Has valid realname?
bool hasValidRealName() const { return m_pilot.hasValidRealName(); }
bool hasRealName() const { return m_pilot.hasRealName(); }
//! Has valid id?
bool hasValidId() const { return m_pilot.hasValidId(); }
bool hasId() const { return m_pilot.hasId(); }
//! Valid designator?
bool hasAircraftDesignator() const;

View File

@@ -69,7 +69,7 @@ namespace BlackMisc
bool CSimulatedAircraftList::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUpdated) const
{
if (this->isEmpty()) return false;
if (aircraftToBeUpdated.hasValidRealName() && aircraftToBeUpdated.hasValidId() && aircraftToBeUpdated.hasAircraftAndAirlineDesignator()) { return false; }
if (aircraftToBeUpdated.hasRealName() && aircraftToBeUpdated.hasId() && aircraftToBeUpdated.hasAircraftAndAirlineDesignator()) { return false; }
CSimulatedAircraft currentDataFileAircraft = this->findFirstByCallsign(aircraftToBeUpdated.getCallsign());
if (currentDataFileAircraft.getCallsign().isEmpty()) return false;