Formatting, QStringBuilder

This commit is contained in:
Klaus Basan
2017-01-31 19:46:37 +01:00
committed by Mathew Sutcliffe
parent a61abfcb8b
commit ec23863d53
6 changed files with 59 additions and 43 deletions

View File

@@ -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 += "&nbsp;&nbsp;&nbsp;&nbsp;"; QLatin1Literal("&nbsp;&nbsp;&nbsp;&nbsp;") %
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 += "&nbsp;&nbsp;&nbsp;&nbsp;"; QLatin1Literal("&nbsp;&nbsp;&nbsp;&nbsp;") %
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());
} }
} }

View File

@@ -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;

View File

@@ -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);
} }

View File

@@ -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");

View File

@@ -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()

View File

@@ -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 &timestampHtmlOutput();
//! 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();