Hide model string for ATC clients

This commit is contained in:
Klaus Basan
2014-12-20 18:13:47 +01:00
parent a03bd4d07f
commit 0b03ac1339
6 changed files with 71 additions and 19 deletions

View File

@@ -43,5 +43,23 @@ namespace BlackGui
(void)QT_TRANSLATE_NOOP("ViewClientList", "model");
(void)QT_TRANSLATE_NOOP("ViewClientList", "server");
}
}
}
QVariant CClientListModel::data(const QModelIndex &index, int role) const
{
static const CPropertyIndex ms( {CClient::IndexModel, CAircraftModel::IndexModelString});
if (role != Qt::DisplayRole) { return CListModelBase::data(index, role); }
CPropertyIndex pi = modelIndexToPropertyIndex(index);
if (pi == ms)
{
// no model string for ATC
CClient client = this->at(index);
bool atc = client.isAtc();
if (atc)
{
return QVariant("ATC");
}
}
return CListModelBase::data(index, role);
}
} // namespace
} // namespace

View File

@@ -20,9 +20,7 @@ namespace BlackGui
{
namespace Models
{
/*!
* Server list model
*/
//! Client list model
class CClientListModel : public CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>
{
@@ -32,7 +30,11 @@ namespace BlackGui
//! Destructor
virtual ~CClientListModel() {}
//! \copydoc QAbstractListModel::data()
virtual QVariant data(const QModelIndex &index, int role) const override;
};
}
}
} // namespace
} // namespace
#endif // guard

View File

@@ -116,9 +116,7 @@ namespace BlackGui
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
};
/*!
* List model
*/
//! List model
template <typename ObjectType, typename ContainerType> class CListModelBase :
public CListModelBaseNonTemplate
{

View File

@@ -58,6 +58,22 @@ namespace BlackMisc
}
}
/*
* ATC callsign?
*/
bool CCallsign::isAtcCallsign() const
{
if (this->m_callsignAsSet.contains('_'))
{
if (this->m_callsignAsSet.size() >= 3)
{
QString app = this->m_callsignAsSet.right(3);
return atcCallsignAppendixes().contains(app, Qt::CaseInsensitive);
}
}
return false;
}
/*
* Callsign as Observer
*/
@@ -136,5 +152,14 @@ namespace BlackMisc
return (regexp.match(callsign).hasMatch());
}
/*
* Appendixes
*/
const QStringList &CCallsign::atcCallsignAppendixes()
{
static const QStringList a( { "APP", "GND", "TWR", "DEL", "CTR", "SUP", "FSS" });
return a;
}
} // namespace
} // namespace

View File

@@ -48,6 +48,9 @@ namespace BlackMisc
//! Is empty?
bool isEmpty() const { return this->m_callsignAsSet.isEmpty(); }
//! ATC callsign
bool isAtcCallsign() const;
//! Get callsign.
const QString &asString() const { return this->m_callsign; }
@@ -78,6 +81,9 @@ namespace BlackMisc
//! Valid callsign?
static bool isValidCallsign(const QString &callsign);
//! List of ATC appendixes (e.g. TWR);
static const QStringList &atcCallsignAppendixes();
protected:
//! \copydoc CValueObject::convertToQString()
virtual QString convertToQString(bool i18n = false) const override;

View File

@@ -63,6 +63,9 @@ namespace BlackMisc
//! Callsign used with other client
const BlackMisc::Aviation::CCallsign &getCallsign() const { return this->m_user.getCallsign(); }
//! ATC client
bool isAtc() const { return getCallsign().isAtcCallsign(); }
//! Get capabilities
CPropertyIndexVariantMap getCapabilities() const { return this->m_capabilities; }
@@ -123,23 +126,23 @@ namespace BlackMisc
private:
BLACK_ENABLE_TUPLE_CONVERSION(CClient)
CUser m_user;
CUser m_user;
CAircraftModel m_model;
CPropertyIndexVariantMap m_capabilities;
QString m_server;
CVoiceCapabilities m_voiceCapabilities;
QString m_server;
CVoiceCapabilities m_voiceCapabilities;
};
} // namespace
} // namespace
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CClient, (
o.m_user,
o.m_model,
attr(o.m_capabilities, flags<DisabledForComparison>()),
o.m_server,
o.m_voiceCapabilities
))
o.m_user,
o.m_model,
attr(o.m_capabilities, flags<DisabledForComparison>()),
o.m_server,
o.m_voiceCapabilities
))
Q_DECLARE_METATYPE(BlackMisc::Network::CClient)
#endif // guard