From a4100d7efa19ffbed5f4619fbb083df9fe7e5224 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 8 May 2017 02:57:34 +0200 Subject: [PATCH] Ref T77, tooltip for models (HTML Summary) --- .../models/aircraftmodellistmodel.cpp | 30 +++++++++++++------ src/blackmisc/aviation/livery.cpp | 20 ++++++++++--- src/blackmisc/aviation/livery.h | 7 +++-- src/blackmisc/simulation/aircraftmodel.cpp | 14 +++++---- src/blackmisc/simulation/distributor.cpp | 10 +++++++ src/blackmisc/simulation/distributor.h | 3 ++ 6 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/blackgui/models/aircraftmodellistmodel.cpp b/src/blackgui/models/aircraftmodellistmodel.cpp index 894536203..83dae0233 100644 --- a/src/blackgui/models/aircraftmodellistmodel.cpp +++ b/src/blackgui/models/aircraftmodellistmodel.cpp @@ -190,17 +190,29 @@ namespace BlackGui QVariant CAircraftModelListModel::data(const QModelIndex &index, int role) const { - if (role != Qt::BackgroundRole) { return CListModelDbObjects::data(index, role); } - bool ms = highlightModelStrings() && !m_highlightStrings.isEmpty(); - if (!ms) { return CListModelDbObjects::data(index, role); } - - CAircraftModel model(this->at(index)); - // highlight stashed first - if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive)) + if (role == Qt::BackgroundRole) { - return this->m_highlightColor; + const bool ms = highlightModelStrings() && !m_highlightStrings.isEmpty(); + if (!ms) { return CListModelDbObjects::data(index, role); } + + // the underlying model object + const CAircraftModel model(this->at(index)); + + // highlight stashed first + if (m_highlightStrings.contains(model.getModelString(), Qt::CaseInsensitive)) + { + 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("
"); + } + return CListModelDbObjects::data(index, role); } void CAircraftModelListModel::clearHighlighting() diff --git a/src/blackmisc/aviation/livery.cpp b/src/blackmisc/aviation/livery.cpp index ff1347d12..d70cf5655 100644 --- a/src/blackmisc/aviation/livery.cpp +++ b/src/blackmisc/aviation/livery.cpp @@ -67,14 +67,22 @@ namespace BlackMisc QString CLivery::getCombinedCodePlusInfo() const { - QString s(getCombinedCode()); + QString s = this->getCombinedCode(); if (!this->getDescription().isEmpty()) { - s += QLatin1String(" (") % this->getDescription() % QLatin1String(")"); + s += " "; + s += this->getDescription(); } return s; } + QString CLivery::getCombinedCodePlusInfoAndId() const + { + QString s = this->getCombinedCodePlusInfo(); + s += this->getDbKeyAsStringInParentheses(" "); + return s; + } + bool CLivery::isContainedInSimplifiedAirlineName(const QString &candidate) const { 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(" ", " "); } int CLivery::calculateScore(const CLivery &otherLivery, bool preferColorLiveries) const diff --git a/src/blackmisc/aviation/livery.h b/src/blackmisc/aviation/livery.h index 61f94613a..d43d0f9bf 100644 --- a/src/blackmisc/aviation/livery.h +++ b/src/blackmisc/aviation/livery.h @@ -74,9 +74,12 @@ namespace BlackMisc //! Combined code const QString &getCombinedCode() const { return m_combinedCode; } - //! Combined code + //! Combined code plus info QString getCombinedCodePlusInfo() const; + //! Combined code, info, plus id + QString getCombinedCodePlusInfoAndId() const; + //! Get description. const QString &getDescription() const { return m_description; } @@ -171,7 +174,7 @@ namespace BlackMisc void updateMissingParts(const CLivery &otherLivery); //! 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 //! \remark normally used with liveries preselect by airline ICAO code diff --git a/src/blackmisc/simulation/aircraftmodel.cpp b/src/blackmisc/simulation/aircraftmodel.cpp index 3c135eb2d..bf22669e8 100644 --- a/src/blackmisc/simulation/aircraftmodel.cpp +++ b/src/blackmisc/simulation/aircraftmodel.cpp @@ -105,7 +105,7 @@ namespace BlackMisc QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const { QJsonObject json; - auto meta = introspect().without(MetaFlags()); + const auto meta = introspect().without(MetaFlags()); meta.forEachMember([ &, this ](auto member) { auto &&maybeMemo = helper.maybeMemoize(member.in(*this)); @@ -116,7 +116,7 @@ namespace BlackMisc void CAircraftModel::convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &helper) { - auto meta = introspect().without(MetaFlags()); + const auto meta = introspect().without(MetaFlags()); meta.forEachMember([ &, this ](auto member) { auto it = json.find(CExplicitLatin1String(member.latin1Name())); @@ -126,10 +126,12 @@ namespace BlackMisc QString CAircraftModel::asHtmlSummary(const QString &separator) const { - static const QString html = "Model: %1%2Aircraft ICAO: %3%4Livery: %5"; - return html.arg(this->getModelStringAndDbKey(), separator, - this->getAircraftIcaoCode().asHtmlSummary(), separator, - this->getLivery().asHtmlSummary()); + static const QString html = "Model: %1 changed: %2%3Simulator: %4 Mode: %5 Distributor: %6%7Aircraft ICAO: %8%9Livery: %10"; + return html + .arg(this->getModelStringAndDbKey(), this->getFormattedUtcTimestampYmdhms() , separator, + this->getSimulator().toQString(true), this->getModelModeAsString(), this->getDistributor().getIdAndDescription(), separator, + this->getAircraftIcaoCode().asHtmlSummary(), separator) + .arg(this->getLivery().asHtmlSummary(" ")).replace(" ", " "); } bool CAircraftModel::canInitializeFromFsd() const diff --git a/src/blackmisc/simulation/distributor.cpp b/src/blackmisc/simulation/distributor.cpp index c983690f4..c08dd64b0 100644 --- a/src/blackmisc/simulation/distributor.cpp +++ b/src/blackmisc/simulation/distributor.cpp @@ -33,6 +33,16 @@ namespace BlackMisc 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 { QString s(keyOrAlias.trimmed().toUpper()); diff --git a/src/blackmisc/simulation/distributor.h b/src/blackmisc/simulation/distributor.h index 89e9ffb31..c02a7e2a7 100644 --- a/src/blackmisc/simulation/distributor.h +++ b/src/blackmisc/simulation/distributor.h @@ -58,6 +58,9 @@ namespace BlackMisc //! Get description const QString &getDescription() const { return this->m_description;} + //! Get id and description + const QString getIdAndDescription() const; + //! Set description void setDescription(const QString &description) { this->m_description = description.trimmed(); }