Ref T219, added some utility functions in value classes

This commit is contained in:
Klaus Basan
2018-01-07 03:09:54 +01:00
parent b982b7aca6
commit 93d1dcfc1d
7 changed files with 29 additions and 7 deletions

View File

@@ -21,6 +21,11 @@ namespace BlackMisc
return this->m_icaoCode.compare(compareValue.getIcaoCode(), Qt::CaseInsensitive);
}
bool CAirportIcaoCode::hasValidIcaoCode() const
{
return CAirportIcaoCode::isValidIcaoDesignator(this->getIcaoCode());
}
bool CAirportIcaoCode::equalsString(const QString &icaoCode) const
{
CAirportIcaoCode other(icaoCode);

View File

@@ -41,6 +41,9 @@ namespace BlackMisc
//! Is empty?
bool isEmpty() const { return this->m_icaoCode.isEmpty(); }
//! Has valid code?
bool hasValidIcaoCode() const;
//! Get code.
const QString &asString() const { return this->m_icaoCode; }

View File

@@ -95,7 +95,7 @@ namespace BlackMisc
QLatin1String(" online: ") % boolToYesNo(m_isOnline) %
// controller
(!m_controller.isValid() ? QStringLiteral("") :
(m_controller.isNull() ? QStringLiteral("") :
QStringLiteral(" ") % m_controller.toQString(i18n)) %
// frequency

View File

@@ -106,7 +106,7 @@ namespace BlackMisc
bool CServer::isValidForLogin() const
{
return m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
return m_user.hasCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
}
bool CServer::hasAddressAndPort() const

View File

@@ -119,13 +119,18 @@ namespace BlackMisc
m_realname = beautifyRealName(rn);
}
bool CUser::hasValidHomeBase() const
{
return m_homebase.hasValidIcaoCode();
}
CStatusMessageList CUser::validate() const
{
CStatusMessageList msgs;
// callsign optional
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"));}
if (!this->hasCredentials()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Invalid credentials"));}
return msgs;
}

View File

@@ -73,10 +73,13 @@ namespace BlackMisc
void setPassword(const QString &pw) { m_password = pw.trimmed(); }
//! Valid user object?
bool isValid() const { return !m_realname.isEmpty() && !m_id.isEmpty(); }
bool isValid() const { return !isNull(); }
//! Null?
bool isNull() const { return m_realname.isEmpty() && m_id.isEmpty(); }
//! Valid credentials?
bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
bool hasCredentials() const { return this->isValid() && !m_password.isEmpty(); }
//! Valid real name?
bool hasRealName() const { return !m_realname.isEmpty(); }
@@ -84,12 +87,18 @@ namespace BlackMisc
//! Valid id?
bool hasId() const { return !m_id.isEmpty(); }
//! Has a valid VATSIM id?
bool hasValidVatsimId() const { return CUser::isValidVatsimId(this->getId()); }
//! Has associated callsign?
bool hasCallsign() const { return !m_callsign.isEmpty(); }
//! Has home base?
bool hasHomeBase() const { return !m_homebase.isEmpty(); }
//! Has valid home base?
bool hasValidHomeBase() const;
//! Real name + homebase
QString getRealNameAndHomeBase(const QString &separator = QString(" ")) const;

View File

@@ -88,8 +88,8 @@ namespace BlackMisc
bool CSimulatedAircraft::isValidForLogin() const
{
if (m_callsign.asString().isEmpty()) { return false; }
if (!m_pilot.isValid()) { return false; }
if (m_callsign.isEmpty()) { return false; }
if (m_pilot.isNull()) { return false; }
return true;
}