Ref T77, tooltip for models (HTML Summary)

This commit is contained in:
Klaus Basan
2017-05-08 02:57:34 +02:00
parent afbb87298f
commit a4100d7efa
6 changed files with 63 additions and 21 deletions

View File

@@ -190,18 +190,30 @@ namespace BlackGui
QVariant CAircraftModelListModel::data(const QModelIndex &index, int role) const QVariant CAircraftModelListModel::data(const QModelIndex &index, int role) const
{ {
if (role != Qt::BackgroundRole) { return CListModelDbObjects::data(index, role); } if (role == Qt::BackgroundRole)
bool ms = highlightModelStrings() && !m_highlightStrings.isEmpty(); {
const bool ms = highlightModelStrings() && !m_highlightStrings.isEmpty();
if (!ms) { return CListModelDbObjects::data(index, role); } if (!ms) { return CListModelDbObjects::data(index, role); }
CAircraftModel model(this->at(index)); // the underlying model object
const CAircraftModel model(this->at(index));
// highlight stashed first // highlight stashed first
if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive)) if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive))
{ {
return this->m_highlightColor; return this->m_highlightColor;
} }
return QVariant(); return QVariant();
} }
else if (role == Qt::ToolTipRole)
{
// the underlying model object as summary
const CAircraftModel model(this->at(index));
return model.asHtmlSummary("<br>");
}
return CListModelDbObjects::data(index, role);
}
void CAircraftModelListModel::clearHighlighting() void CAircraftModelListModel::clearHighlighting()
{ {

View File

@@ -67,14 +67,22 @@ namespace BlackMisc
QString CLivery::getCombinedCodePlusInfo() const QString CLivery::getCombinedCodePlusInfo() const
{ {
QString s(getCombinedCode()); QString s = this->getCombinedCode();
if (!this->getDescription().isEmpty()) if (!this->getDescription().isEmpty())
{ {
s += QLatin1String(" (") % this->getDescription() % QLatin1String(")"); s += " ";
s += this->getDescription();
} }
return s; return s;
} }
QString CLivery::getCombinedCodePlusInfoAndId() const
{
QString s = this->getCombinedCodePlusInfo();
s += this->getDbKeyAsStringInParentheses(" ");
return s;
}
bool CLivery::isContainedInSimplifiedAirlineName(const QString &candidate) const bool CLivery::isContainedInSimplifiedAirlineName(const QString &candidate) const
{ {
return this->getAirlineIcaoCode().isContainedInSimplifiedName(candidate); return this->getAirlineIcaoCode().isContainedInSimplifiedName(candidate);
@@ -383,9 +391,13 @@ namespace BlackMisc
} }
} }
QString CLivery::asHtmlSummary() const QString CLivery::asHtmlSummary(const QString &separator) const
{ {
return this->getCombinedCodePlusInfo(); static const QString html = "%1%2Airline: %3";
return html.arg(
this->getCombinedCodePlusInfoAndId(), separator,
this->getAirlineIcaoCode().getDesignator().isEmpty() ? "No airline" : this->getAirlineIcaoCode().getCombinedStringWithKey()
).replace(" ", "&nbsp;");
} }
int CLivery::calculateScore(const CLivery &otherLivery, bool preferColorLiveries) const int CLivery::calculateScore(const CLivery &otherLivery, bool preferColorLiveries) const

View File

@@ -74,9 +74,12 @@ namespace BlackMisc
//! Combined code //! Combined code
const QString &getCombinedCode() const { return m_combinedCode; } const QString &getCombinedCode() const { return m_combinedCode; }
//! Combined code //! Combined code plus info
QString getCombinedCodePlusInfo() const; QString getCombinedCodePlusInfo() const;
//! Combined code, info, plus id
QString getCombinedCodePlusInfoAndId() const;
//! Get description. //! Get description.
const QString &getDescription() const { return m_description; } const QString &getDescription() const { return m_description; }
@@ -171,7 +174,7 @@ namespace BlackMisc
void updateMissingParts(const CLivery &otherLivery); void updateMissingParts(const CLivery &otherLivery);
//! As a brief HTML summary (e.g. used in tooltips) //! As a brief HTML summary (e.g. used in tooltips)
QString asHtmlSummary() const; QString asHtmlSummary(const QString &separator) const;
//! Score by comparison to another livery 0..100 //! Score by comparison to another livery 0..100
//! \remark normally used with liveries preselect by airline ICAO code //! \remark normally used with liveries preselect by airline ICAO code

View File

@@ -105,7 +105,7 @@ namespace BlackMisc
QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const
{ {
QJsonObject json; QJsonObject json;
auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>()); const auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
meta.forEachMember([ &, this ](auto member) meta.forEachMember([ &, this ](auto member)
{ {
auto &&maybeMemo = helper.maybeMemoize(member.in(*this)); auto &&maybeMemo = helper.maybeMemoize(member.in(*this));
@@ -116,7 +116,7 @@ namespace BlackMisc
void CAircraftModel::convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &helper) void CAircraftModel::convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &helper)
{ {
auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>()); const auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
meta.forEachMember([ &, this ](auto member) meta.forEachMember([ &, this ](auto member)
{ {
auto it = json.find(CExplicitLatin1String(member.latin1Name())); auto it = json.find(CExplicitLatin1String(member.latin1Name()));
@@ -126,10 +126,12 @@ namespace BlackMisc
QString CAircraftModel::asHtmlSummary(const QString &separator) const QString CAircraftModel::asHtmlSummary(const QString &separator) const
{ {
static const QString html = "Model: %1%2Aircraft ICAO: %3%4Livery: %5"; static const QString html = "Model: %1 changed: %2%3Simulator: %4 Mode: %5 Distributor: %6%7Aircraft ICAO: %8%9Livery: %10";
return html.arg(this->getModelStringAndDbKey(), separator, return html
this->getAircraftIcaoCode().asHtmlSummary(), separator, .arg(this->getModelStringAndDbKey(), this->getFormattedUtcTimestampYmdhms() , separator,
this->getLivery().asHtmlSummary()); this->getSimulator().toQString(true), this->getModelModeAsString(), this->getDistributor().getIdAndDescription(), separator,
this->getAircraftIcaoCode().asHtmlSummary(), separator)
.arg(this->getLivery().asHtmlSummary("&nbsp;")).replace(" ", "&nbsp;");
} }
bool CAircraftModel::canInitializeFromFsd() const bool CAircraftModel::canInitializeFromFsd() const

View File

@@ -33,6 +33,16 @@ namespace BlackMisc
this->setDbKey(id); this->setDbKey(id);
} }
const QString CDistributor::getIdAndDescription() const
{
if (!this->getDbKey().isEmpty() && !this->getDescription().isEmpty())
{
return this->getDbKey() + " " + this->getDescription();
}
if (!this->getDbKey().isEmpty()) { return this->getDbKey(); }
return "";
}
bool CDistributor::matchesKeyOrAlias(const QString &keyOrAlias) const bool CDistributor::matchesKeyOrAlias(const QString &keyOrAlias) const
{ {
QString s(keyOrAlias.trimmed().toUpper()); QString s(keyOrAlias.trimmed().toUpper());

View File

@@ -58,6 +58,9 @@ namespace BlackMisc
//! Get description //! Get description
const QString &getDescription() const { return this->m_description;} const QString &getDescription() const { return this->m_description;}
//! Get id and description
const QString getIdAndDescription() const;
//! Set description //! Set description
void setDescription(const QString &description) { this->m_description = description.trimmed(); } void setDescription(const QString &description) { this->m_description = description.trimmed(); }