mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #828, added function to generate HTML file with matrix
* added utility functions * adjusted existing functions
This commit is contained in:
@@ -7,9 +7,12 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/aircraftmodelutils.h"
|
||||
#include "blackmisc/verify.h"
|
||||
|
||||
using namespace BlackConfig;
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
@@ -29,5 +32,111 @@ namespace BlackMisc
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString CAircraftModelUtilities::createIcaoAirlineAircraftHtmlMatrix(const CAircraftModelList &models)
|
||||
{
|
||||
if (models.isEmpty()) { return ""; }
|
||||
static const QString emptyDesignator = "----";
|
||||
static const QString colorLiveryDesignator = "-C-";
|
||||
|
||||
QMap<QString, QMap<QString, CAircraftModelList>> modelsByDesignator;
|
||||
|
||||
// create an empty map of all airlines
|
||||
const QMap<QString, CAircraftModelList> emptyAirlineDesignatorMap;
|
||||
CAircraftModelList sortedByAircraft(models);
|
||||
sortedByAircraft.sortBy(&CAircraftModel::getAircraftIcaoCodeDesignator);
|
||||
|
||||
for (const CAircraftModel &model : as_const(sortedByAircraft))
|
||||
{
|
||||
const QString aircraftIcao(model.hasAircraftDesignator() ? model.getAircraftIcaoCodeDesignator() : emptyDesignator);
|
||||
if (!modelsByDesignator.contains(aircraftIcao))
|
||||
{
|
||||
modelsByDesignator.insert(aircraftIcao, emptyAirlineDesignatorMap);
|
||||
}
|
||||
QMap<QString, CAircraftModelList> &airlineModels = modelsByDesignator[aircraftIcao];
|
||||
const QString airlineIcao(
|
||||
model.getLivery().isColorLivery() ? colorLiveryDesignator :
|
||||
model.hasAirlineDesignator() ? model.getAirlineIcaoCodeDesignator() : emptyDesignator);
|
||||
if (airlineModels.contains(airlineIcao))
|
||||
{
|
||||
airlineModels[airlineIcao].push_back(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
airlineModels.insert(airlineIcao, CAircraftModelList({model}));
|
||||
}
|
||||
}
|
||||
|
||||
// to HTML
|
||||
QString html("<table>\n");
|
||||
QStringList airlineIcaos = models.getAirlineVDesignators().toList();
|
||||
qSort(airlineIcaos);
|
||||
airlineIcaos.push_front(colorLiveryDesignator);
|
||||
airlineIcaos.push_back(emptyDesignator);
|
||||
QStringList aircraftIcaos = modelsByDesignator.keys();
|
||||
qSort(aircraftIcaos);
|
||||
|
||||
// header
|
||||
html += "<thead><tr>\n";
|
||||
html += "<th></th>";
|
||||
for (const QString &airline : as_const(airlineIcaos))
|
||||
{
|
||||
html += "<th>";
|
||||
html += airline;
|
||||
html += "</th>";
|
||||
}
|
||||
html += "\n</tr></thead>\n";
|
||||
|
||||
// fill data
|
||||
html += "<tbody>\n";
|
||||
for (const QString &aircraftIcao : as_const(aircraftIcaos))
|
||||
{
|
||||
html += "<tr>\n";
|
||||
html += " <th>";
|
||||
html += aircraftIcao;
|
||||
html += "</th>\n";
|
||||
|
||||
const QMap<QString, CAircraftModelList> &airlineModels = modelsByDesignator[aircraftIcao];
|
||||
for (const QString &airline : as_const(airlineIcaos))
|
||||
{
|
||||
if (airlineModels.contains(airline))
|
||||
{
|
||||
html += " <td>";
|
||||
const CAircraftModelList &models(airlineModels[airline]);
|
||||
html += "<a>";
|
||||
html += QString::number(models.size());
|
||||
html += "</a><div class=\"mouseoverdisplay\">";
|
||||
html += models.asHtmlSummary();
|
||||
html += "</div>";
|
||||
html += "</td>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
html += " <td></td>\n";
|
||||
}
|
||||
}
|
||||
html += "</tr>\n";
|
||||
}
|
||||
html += "</tbody>\n";
|
||||
html += "</table>\n";
|
||||
return html;
|
||||
}
|
||||
|
||||
QString CAircraftModelUtilities::createIcaoAirlineAircraftHtmlMatrixFile(const CAircraftModelList &models, const QString &tempDir)
|
||||
{
|
||||
Q_ASSERT_X(!tempDir.isEmpty(), Q_FUNC_INFO, "Need directory");
|
||||
if (models.isEmpty()) { return ""; }
|
||||
const QString html = createIcaoAirlineAircraftHtmlMatrix(models);
|
||||
if (html.isEmpty()) { return ""; }
|
||||
|
||||
QDir dir(tempDir);
|
||||
BLACK_VERIFY_X(dir.exists(), Q_FUNC_INFO, "Directory does not exist");
|
||||
if (!dir.exists()) { return ""; }
|
||||
|
||||
const QString htmlTemplate = CFileUtils::readFileToString(CBuildConfig::getHtmlTemplateFileName());
|
||||
const QString fn("airlineAircraftMatrix.html");
|
||||
const bool ok = CFileUtils::writeStringToFile(htmlTemplate.arg(html), dir.absoluteFilePath(fn));
|
||||
return ok ? dir.absoluteFilePath(fn) : "";
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user