mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
Formatting, QStringBuilder
This commit is contained in:
committed by
Mathew Sutcliffe
parent
a61abfcb8b
commit
ec23863d53
@@ -17,6 +17,7 @@
|
|||||||
#include "blackgui/guiapplication.h"
|
#include "blackgui/guiapplication.h"
|
||||||
#include "blackgui/uppercasevalidator.h"
|
#include "blackgui/uppercasevalidator.h"
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
@@ -106,7 +107,6 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (!this->hasContexts()) { return; }
|
if (!this->hasContexts()) { return; }
|
||||||
if (isBeingModified) { return; }
|
if (isBeingModified) { return; }
|
||||||
static const CPropertyIndexList properties({ CStatusMessage::IndexUtcTimestampFormattedHms, CStatusMessage::IndexMessage });
|
|
||||||
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
|
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
|
||||||
if (cs.isEmpty()) { return; }
|
if (cs.isEmpty()) { return; }
|
||||||
const auto currentAircraftParts = sGui->getIContextNetwork()->getRemoteAircraftParts(cs, -1).frontOrDefault();
|
const auto currentAircraftParts = sGui->getIContextNetwork()->getRemoteAircraftParts(cs, -1).frontOrDefault();
|
||||||
@@ -115,37 +115,37 @@ namespace BlackGui
|
|||||||
QString html;
|
QString html;
|
||||||
if (currentAircraftParts == CAircraftParts() && aircraftPartsHistory.isEmpty())
|
if (currentAircraftParts == CAircraftParts() && aircraftPartsHistory.isEmpty())
|
||||||
{
|
{
|
||||||
html = cs.toQString() + QString(" does not support aircraft parts or nothing received yet.");
|
html = cs.toQString() % QLatin1Literal(" does not support aircraft parts or nothing received yet.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString s;
|
const QString s =
|
||||||
s += "lights on:";
|
QLatin1Literal("lights on:") %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += " ";
|
QLatin1Literal(" ") %
|
||||||
s += currentAircraftParts.getLights().toQString();
|
currentAircraftParts.getLights().toQString() %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += "gear down: ";
|
QLatin1Literal("gear down: ") %
|
||||||
s += BlackMisc::boolToYesNo(currentAircraftParts.isGearDown());
|
BlackMisc::boolToYesNo(currentAircraftParts.isGearDown()) %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += "flaps pct: ";
|
QLatin1Literal("flaps pct: ") %
|
||||||
s += QString::number(currentAircraftParts.getFlapsPercent());
|
QString::number(currentAircraftParts.getFlapsPercent()) %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += "spoilers out: ";
|
QLatin1Literal("spoilers out: ") %
|
||||||
s += BlackMisc::boolToYesNo(currentAircraftParts.isSpoilersOut());
|
BlackMisc::boolToYesNo(currentAircraftParts.isSpoilersOut()) %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += "engines on: ";
|
QLatin1Literal("engines on: ") %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += " ";
|
QLatin1Literal(" ") %
|
||||||
s += currentAircraftParts.getEngines().toQString();
|
currentAircraftParts.getEngines().toQString() %
|
||||||
s += "<br>";
|
QLatin1Literal("<br>") %
|
||||||
s += " on ground: ";
|
QLatin1Literal(" on ground: ") %
|
||||||
s += BlackMisc::boolToYesNo(currentAircraftParts.isOnGround());
|
BlackMisc::boolToYesNo(currentAircraftParts.isOnGround());
|
||||||
html += s;
|
html += s;
|
||||||
if (ui->cb_PartsHistoryEnabled->isChecked())
|
if (ui->cb_PartsHistoryEnabled->isChecked())
|
||||||
{
|
{
|
||||||
html +="<hr>";
|
html += QLatin1Literal("<hr>") %
|
||||||
html += aircraftPartsHistory.toHtml(properties);
|
aircraftPartsHistory.toHtml(CStatusMessageList::timestampHtmlOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace BlackGui
|
|||||||
explicit CAircraftPartsHistory(QWidget *parent = nullptr);
|
explicit CAircraftPartsHistory(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~CAircraftPartsHistory();
|
virtual ~CAircraftPartsHistory();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CAircraftPartsHistory> ui;
|
QScopedPointer<Ui::CAircraftPartsHistory> ui;
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ namespace BlackGui
|
|||||||
void CModelMatcherLogComponent::ps_callsignEntered()
|
void CModelMatcherLogComponent::ps_callsignEntered()
|
||||||
{
|
{
|
||||||
if (!this->hasContexts()) { return; }
|
if (!this->hasContexts()) { return; }
|
||||||
static const CPropertyIndexList properties({ CPropertyIndex::GlobalIndexLineNumber, CStatusMessage::IndexMessage });
|
|
||||||
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
|
const CCallsign cs(ui->le_Callsign->text().trimmed().toUpper());
|
||||||
const CStatusMessageList reverseLookupMessages = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
|
const CStatusMessageList reverseLookupMessages = sGui->getIContextNetwork()->getReverseLookupMessages(cs);
|
||||||
const CStatusMessageList matchingMessages = sGui->getIContextSimulator()->getMatchingMessages(cs);
|
const CStatusMessageList matchingMessages = sGui->getIContextSimulator()->getMatchingMessages(cs);
|
||||||
@@ -113,7 +112,7 @@ namespace BlackGui
|
|||||||
CStatusMessageList allMessages(reverseLookupMessages);
|
CStatusMessageList allMessages(reverseLookupMessages);
|
||||||
allMessages.push_back(matchingMessages);
|
allMessages.push_back(matchingMessages);
|
||||||
|
|
||||||
const QString html = allMessages.toHtml(properties);
|
const QString html = allMessages.toHtml();
|
||||||
this->m_text.setHtml(html);
|
this->m_text.setHtml(html);
|
||||||
ui->te_Messages->setDocument(&this->m_text);
|
ui->te_Messages->setDocument(&this->m_text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ namespace BlackGui
|
|||||||
const QString path(QDir::toNativeSeparators(CSettingsCache::persistentStore()));
|
const QString path(QDir::toNativeSeparators(CSettingsCache::persistentStore()));
|
||||||
if (QDir(path).exists())
|
if (QDir(path).exists())
|
||||||
{
|
{
|
||||||
QDesktopServices::openUrl(QUrl("file:///" + path));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||||
@@ -353,7 +353,7 @@ namespace BlackGui
|
|||||||
const QString path(QDir::toNativeSeparators(CDataCache::persistentStore()));
|
const QString path(QDir::toNativeSeparators(CDataCache::persistentStore()));
|
||||||
if (QDir(path).exists())
|
if (QDir(path).exists())
|
||||||
{
|
{
|
||||||
QDesktopServices::openUrl(QUrl("file:///" + path));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
@@ -178,29 +179,39 @@ namespace BlackMisc
|
|||||||
QString rowHtml;
|
QString rowHtml;
|
||||||
if (withLineNumbers)
|
if (withLineNumbers)
|
||||||
{
|
{
|
||||||
rowHtml += "<td>" + QString::number(line++) + "</td>";
|
rowHtml = QLatin1Literal("<td>") % QString::number(line++) % QLatin1Literal("</td>");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const CPropertyIndex &index : usedIndexes)
|
for (const CPropertyIndex &index : usedIndexes)
|
||||||
{
|
{
|
||||||
rowHtml += "<td>" + statusMessage.propertyByIndex(index).toQString(true).toHtmlEscaped() + "</td>";
|
rowHtml += QLatin1Literal("<td>") % statusMessage.propertyByIndex(index).toQString(true).toHtmlEscaped() % QLatin1Literal("</td>");
|
||||||
}
|
}
|
||||||
|
|
||||||
rowHtml = "<tr class=\"%1\">" + rowHtml + "</tr>";
|
|
||||||
const QString severityClass = statusMessage.getSeverityAsString();
|
const QString severityClass = statusMessage.getSeverityAsString();
|
||||||
html += rowHtml.arg(severityClass);
|
html += QStringLiteral("<tr class=\"%1\">%2</tr>").arg(severityClass, rowHtml);
|
||||||
}
|
}
|
||||||
return "<table>" + html + "</table>";
|
return "<table>" % html % "</table>";
|
||||||
|
}
|
||||||
|
|
||||||
|
const CPropertyIndexList &CStatusMessageList::simpleHtmlOutput()
|
||||||
|
{
|
||||||
|
static const CPropertyIndexList properties({ CPropertyIndex::GlobalIndexLineNumber, CStatusMessage::IndexMessage });
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CPropertyIndexList &CStatusMessageList::timestampHtmlOutput()
|
||||||
|
{
|
||||||
|
static const CPropertyIndexList properties({ CStatusMessage::IndexUtcTimestampFormattedHms, CStatusMessage::IndexMessage });
|
||||||
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString htmlStyleSheetImpl()
|
const QString htmlStyleSheetImpl()
|
||||||
{
|
{
|
||||||
QString style;
|
const QString style = QLatin1Char('.') % CStatusMessage::severityToString(CStatusMessage::SeverityDebug) % QLatin1Literal(" { color: lightgreen; } ") %
|
||||||
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityDebug) + " { color: lightgreen; } ";
|
QLatin1Char('.') % CStatusMessage::severityToString(CStatusMessage::SeverityInfo) % QLatin1Literal(" { color: lightgreen; } ") %
|
||||||
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityInfo) + " { color: lightgreen; } ";
|
QLatin1Char('.') % CStatusMessage::severityToString(CStatusMessage::SeverityWarning) % QLatin1Literal(" { color: yellow; } ") %
|
||||||
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityWarning) + " { color: yellow; } ";
|
QLatin1Char('.') % CStatusMessage::severityToString(CStatusMessage::SeverityError) % QLatin1Literal(" { color: red; }");
|
||||||
style += "." + CStatusMessage::severityToString(CStatusMessage::SeverityError) + " { color: red; }";
|
return style;
|
||||||
return style; // "<style type=\"text/css\">" + style + "</style>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CStatusMessageList::htmlStyleSheet()
|
const QString &CStatusMessageList::htmlStyleSheet()
|
||||||
|
|||||||
@@ -101,7 +101,13 @@ namespace BlackMisc
|
|||||||
CStatusMessage toSingleMessage() const;
|
CStatusMessage toSingleMessage() const;
|
||||||
|
|
||||||
//! Specialized version to convert to HTML
|
//! Specialized version to convert to HTML
|
||||||
QString toHtml(const CPropertyIndexList &indexes) const;
|
QString toHtml(const CPropertyIndexList &indexes = simpleHtmlOutput()) const;
|
||||||
|
|
||||||
|
//! Properties for CStatusMessageList::toHtml
|
||||||
|
static const CPropertyIndexList &simpleHtmlOutput();
|
||||||
|
|
||||||
|
//! Properties for CStatusMessageList::toHtml
|
||||||
|
static const CPropertyIndexList ×tampHtmlOutput();
|
||||||
|
|
||||||
//! Default style sheet which can be used with CStatusMessageList::toHtml
|
//! Default style sheet which can be used with CStatusMessageList::toHtml
|
||||||
static const QString &htmlStyleSheet();
|
static const QString &htmlStyleSheet();
|
||||||
|
|||||||
Reference in New Issue
Block a user