mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Ref T77, tooltip for models (HTML Summary)
This commit is contained in:
@@ -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("<br>");
|
||||
}
|
||||
return CListModelDbObjects::data(index, role);
|
||||
}
|
||||
|
||||
void CAircraftModelListModel::clearHighlighting()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace BlackMisc
|
||||
QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const
|
||||
{
|
||||
QJsonObject json;
|
||||
auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
|
||||
const auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
|
||||
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<CAircraftModel>().without(MetaFlags<DisabledForJson>());
|
||||
const auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
|
||||
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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user