Skip to content

Commit

Permalink
Made MapQuery, AirwayTrackQuery and WaypointTrackQuery aggregates of …
Browse files Browse the repository at this point in the history
…MapPaintWidget since their caches are related to the map widget.

Renamed related getter methods to indicate GUI ownership.
Removed map query pointers from classes to have a late initialization.
#790
  • Loading branch information
albar965 committed Oct 12, 2021
1 parent ace3b71 commit 88dbf4e
Show file tree
Hide file tree
Showing 44 changed files with 343 additions and 260 deletions.
44 changes: 25 additions & 19 deletions src/common/htmlinfobuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "util/htmlbuilder.h"
#include "weather/windreporter.h"
#include "route/routealtitude.h"
#include "mapgui/mappaintwidget.h"

#include <QSize>
#include <QUrl>
Expand Down Expand Up @@ -95,11 +96,9 @@ const int WEATHER_MAX_AGE_HOURS = 6;
// Maximum distance for bearing display
const int MAX_DISTANCE_FOR_BEARING_METER = ageo::nmToMeter(500);

HtmlInfoBuilder::HtmlInfoBuilder(QWidget *parent, bool formatInfo, bool formatPrint)
: parentWidget(parent), info(formatInfo), print(formatPrint)
HtmlInfoBuilder::HtmlInfoBuilder(QWidget *parent, MapPaintWidget *mapWidgetParam, bool formatInfo, bool formatPrint)
: parentWidget(parent), mapWidget(mapWidgetParam), info(formatInfo), print(formatPrint)
{
mapQuery = NavApp::getMapQuery();
waypointQuery = NavApp::getWaypointTrackQuery();
infoQuery = NavApp::getInfoQuery();
airportQuerySim = NavApp::getAirportQuerySim();
airportQueryNav = NavApp::getAirportQueryNav();
Expand Down Expand Up @@ -162,6 +161,7 @@ void HtmlInfoBuilder::flightplanWaypointRemarks(HtmlBuilder& html, int index) co
void HtmlInfoBuilder::airportText(const MapAirport& airport, const map::WeatherContext& weatherContext,
HtmlBuilder& html, const Route *route) const
{
MapQuery *mapQuery = mapWidget->getMapQuery();
const SqlRecord *rec = infoQuery->getAirportInformation(airport.id);
int rating = -1;

Expand Down Expand Up @@ -223,7 +223,7 @@ void HtmlInfoBuilder::airportText(const MapAirport& airport, const map::WeatherC
if(info)
{
// Get transition altitude from nav database
map::MapAirport navAirport = NavApp::getMapQuery()->getAirportNav(airport);
map::MapAirport navAirport = mapQuery->getAirportNav(airport);
if(navAirport.isValid() && navAirport.transitionAltitude > 0)
html.row2(tr("Transition altitude:"), Unit::altFeet(navAirport.transitionAltitude));

Expand Down Expand Up @@ -524,10 +524,11 @@ void HtmlInfoBuilder::nearestText(const MapAirport& airport, HtmlBuilder& html)
arg(Unit::distNm(NEAREST_MAX_DISTANCE_AIRPORT_NM * 4.f))).pEnd();

// Get nearest VOR and NDB ====================================
MapResultIndex *nearestNavaids = mapQuery->getNearestNavaids(airport.position,
NEAREST_MAX_DISTANCE_NAVAID_NM,
map::VOR | map::NDB | map::ILS,
3 /* max ILS */, 4.f /* max ILS dist NM */);
MapResultIndex *nearestNavaids =
mapWidget->getMapQuery()->getNearestNavaids(airport.position, NEAREST_MAX_DISTANCE_NAVAID_NM,
map::VOR | map::NDB | map::ILS, 3 /* max ILS */,
4.f /* max ILS dist NM */);

if(!nearestMapObjectsText(airport, html, nearestNavaids, tr("Nearest Radio Navaids"), true, false,
NEAREST_MAX_NUM_NAVAID))
html.p().b(tr("No navaids within a radius of %1.").
Expand Down Expand Up @@ -615,7 +616,7 @@ bool HtmlInfoBuilder::nearestMapObjectsText(const MapAirport& airport, HtmlBuild
if(ap != nullptr)
{
// Convert navdatabase airport to simulator
map::MapAirport simAp = mapQuery->getAirportSim(*ap);
map::MapAirport simAp = mapWidget->getMapQuery()->getAirportSim(*ap);

// Omit center airport used as reference
if(simAp.isValid() && simAp.id != airport.id)
Expand Down Expand Up @@ -1061,7 +1062,8 @@ void HtmlInfoBuilder::runwayEndText(HtmlBuilder& html, const MapAirport& airport
html.tableEnd();

// Show none, one or more ILS
QVector<map::MapIls> ilsVector = mapQuery->getIlsByAirportAndRunway(airport.ident, rec->valueStr("name"));
QVector<map::MapIls> ilsVector =
mapWidget->getMapQuery()->getIlsByAirportAndRunway(airport.ident, rec->valueStr("name"));
for(const map::MapIls& ils : ilsVector)
ilsTextRunwayInfo(ils, html);
}
Expand Down Expand Up @@ -1307,6 +1309,7 @@ void HtmlInfoBuilder::procedureText(const MapAirport& airport, HtmlBuilder& html
{
if(info && infoQuery != nullptr && airport.isValid())
{
MapQuery *mapQuery = mapWidget->getMapQuery();
MapAirport navAirport = mapQuery->getAirportNav(airport);

if(!print)
Expand Down Expand Up @@ -1514,7 +1517,8 @@ void HtmlInfoBuilder::addRadionavFixType(HtmlBuilder& html, const SqlRecord& rec

map::MapResult result;

mapQuery->getMapObjectByIdent(result, map::VOR, recApp.valueStr("fix_ident"), recApp.valueStr("fix_region"));
mapWidget->getMapQuery()->getMapObjectByIdent(result, map::VOR, recApp.valueStr("fix_ident"),
recApp.valueStr("fix_region"));

if(result.hasVor())
{
Expand Down Expand Up @@ -1560,7 +1564,8 @@ void HtmlInfoBuilder::addRadionavFixType(HtmlBuilder& html, const SqlRecord& rec
html.row2(tr("Fix Type:"), tr("Terminal NDB"));

map::MapResult result;
mapQuery->getMapObjectByIdent(result, map::NDB, recApp.valueStr("fix_ident"), recApp.valueStr("fix_region"));
mapWidget->getMapQuery()->getMapObjectByIdent(result, map::NDB, recApp.valueStr("fix_ident"),
recApp.valueStr("fix_region"));

if(result.hasNdb())
{
Expand Down Expand Up @@ -1591,7 +1596,7 @@ void HtmlInfoBuilder::weatherText(const map::WeatherContext& context, const MapA
if(!print)
airportTitle(airport, html, -1);

map::MapAirport navAirport = NavApp::getMapQuery()->getAirportNav(airport);
map::MapAirport navAirport = mapWidget->getMapQuery()->getAirportNav(airport);
if(navAirport.isValid() && navAirport.transitionAltitude > 0)
html.br().br().b(tr("Transition altitude: ")).text(Unit::altFeet(navAirport.transitionAltitude));

Expand Down Expand Up @@ -2490,7 +2495,7 @@ void HtmlInfoBuilder::airportRow(const map::MapAirport& ap, HtmlBuilder& html) c
{
if(ap.isValid())
{
map::MapAirport apSim = mapQuery->getAirportSim(ap);
map::MapAirport apSim = mapWidget->getMapQuery()->getAirportSim(ap);
if(apSim.isValid())
{
HtmlBuilder apHtml = html.cleared();
Expand All @@ -2505,7 +2510,7 @@ void HtmlInfoBuilder::waypointText(const MapWaypoint& waypoint, HtmlBuilder& htm
const SqlRecord *rec = nullptr;

if(info && infoQuery != nullptr)
rec = waypointQuery->getWaypointInformation(waypoint.id);
rec = mapWidget->getWaypointTrackQuery()->getWaypointInformation(waypoint.id);

QIcon icon = SymbolPainter().createWaypointIcon(symbolSizeTitle.height());
html.img(icon, QString(), QString(), symbolSizeTitle);
Expand Down Expand Up @@ -2553,7 +2558,7 @@ void HtmlInfoBuilder::waypointText(const MapWaypoint& waypoint, HtmlBuilder& htm
html.tableEnd();

QList<MapAirway> airways;
NavApp::getAirwayTrackQuery()->getAirwaysForWaypoint(airways, waypoint.id);
NavApp::getAirwayTrackQueryGui()->getAirwaysForWaypoint(airways, waypoint.id);

if(!airways.isEmpty())
{
Expand Down Expand Up @@ -2830,6 +2835,7 @@ void HtmlInfoBuilder::airwayText(const MapAirway& airway, HtmlBuilder& html) con
else
html.row2If(tr("Track type:"), map::airwayTrackTypeToString(airway.type));

WaypointTrackQuery *waypointQuery = mapWidget->getWaypointTrackQuery();
map::MapWaypoint from = waypointQuery->getWaypointById(airway.fromWaypointId);
map::MapWaypoint to = waypointQuery->getWaypointById(airway.toWaypointId);

Expand Down Expand Up @@ -2909,7 +2915,7 @@ void HtmlInfoBuilder::airwayText(const MapAirway& airway, HtmlBuilder& html) con

// Show list of waypoints =================================================================
QList<map::MapAirwayWaypoint> waypointList;
NavApp::getAirwayTrackQuery()->getWaypointListForAirwayName(waypointList, airway.name, airway.fragment);
NavApp::getAirwayTrackQueryGui()->getWaypointListForAirwayName(waypointList, airway.name, airway.fragment);

if(!waypointList.isEmpty())
{
Expand Down Expand Up @@ -4259,7 +4265,7 @@ void HtmlInfoBuilder::addAirportSceneryAndLinks(const MapAirport& airport, HtmlB

// Check if airport is in navdata
QStringList links;
MapAirport airportNav = mapQuery->getAirportNav(airport);
MapAirport airportNav = mapWidget->getMapQuery()->getAirportNav(airport);

if(airportNav.isValid() && airportNav.navdata)
{
Expand Down
9 changes: 6 additions & 3 deletions src/common/htmlinfobuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class InfoQuery;
class WeatherReporter;
class Route;
class MainWindow;
class MapPaintWidget;

class QFileInfo;

Expand Down Expand Up @@ -102,6 +103,8 @@ struct MapProcedurePoint;

/*
* Builds HTML snippets (no <html> and no <body> tags) for QTextEdits or tooltips.
*
* This is indepent of the main GUI main map widget.
*/
class HtmlInfoBuilder
{
Expand All @@ -114,7 +117,7 @@ class HtmlInfoBuilder
* @param formatInfo true if this should generate HTML for QTextEdits or QWebBrowser
* (i.e. generate alternating background color for tables)
*/
HtmlInfoBuilder(QWidget *parent, bool formatInfo, bool formatPrint = false);
HtmlInfoBuilder(QWidget *parent, MapPaintWidget *mapWidgetParam, bool formatInfo, bool formatPrint = false);

virtual ~HtmlInfoBuilder();

Expand Down Expand Up @@ -414,8 +417,8 @@ class HtmlInfoBuilder
QSize symbolSizeVehicle = QSize(28, 28);

QWidget *parentWidget = nullptr;
MapQuery *mapQuery;
WaypointTrackQuery *waypointQuery;
MapPaintWidget *mapWidget = nullptr;

AirportQuery *airportQuerySim, *airportQueryNav;
InfoQuery *infoQuery;
atools::fs::util::MorseCode *morse;
Expand Down
15 changes: 10 additions & 5 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ MainWindow::MainWindow()
ui->dockWidgetMap->hide();
}

// Init a few late objects since these depend on the map widget instance
NavApp::initQueries();
NavApp::initElevationProvider();

// Create elevation profile widget and replace dummy widget in window
Expand Down Expand Up @@ -1508,6 +1510,8 @@ void MainWindow::connectAllSlots()
connect(trackController, &TrackController::postTrackLoad, this, &MainWindow::updateMapObjectsShown);
connect(trackController, &TrackController::postTrackLoad, routeController, &RouteController::tracksChanged);

connect(trackController, &TrackController::postTrackLoad, mapWidget, &MapPaintWidget::postTrackLoad);

connect(ui->actionRouteDownloadTracks, &QAction::toggled, trackController, &TrackController::downloadToggled);
connect(ui->actionRouteDownloadTracksNow, &QAction::triggered, trackController, &TrackController::startDownload);
connect(ui->actionRouteDeleteTracks, &QAction::triggered, trackController, &TrackController::deleteTracks);
Expand Down Expand Up @@ -3621,10 +3625,11 @@ void MainWindow::updateOnlineActionStates()
/* Enable or disable actions */
void MainWindow::updateMarkActionStates()
{
ui->actionMapHideRangeRings->setEnabled(!NavApp::getMapWidget()->getDistanceMarkers().isEmpty() ||
!NavApp::getMapWidget()->getRangeRings().isEmpty() ||
!NavApp::getMapWidget()->getTrafficPatterns().isEmpty() ||
!NavApp::getMapWidget()->getHolds().isEmpty());
MapWidget *mapWidget = NavApp::getMapWidgetGui();
ui->actionMapHideRangeRings->setEnabled(!mapWidget->getDistanceMarkers().isEmpty() ||
!mapWidget->getRangeRings().isEmpty() ||
!mapWidget->getTrafficPatterns().isEmpty() ||
!mapWidget->getHolds().isEmpty());
}

/* Enable or disable actions */
Expand Down Expand Up @@ -4299,10 +4304,10 @@ void MainWindow::postDatabaseLoad(atools::fs::FsPaths::SimulatorType type)
qDebug() << "MainWindow::postDatabaseLoad";
if(hasDatabaseLoadStatus)
{
mapWidget->postDatabaseLoad(); // Init map widget dependent queries first
NavApp::postDatabaseLoad();
searchController->postDatabaseLoad();
routeController->postDatabaseLoad();
mapWidget->postDatabaseLoad();
profileWidget->postDatabaseLoad();
infoController->postDatabaseLoad();
weatherReporter->postDatabaseLoad(type);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/timedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void TimeDialog::buttonBoxClicked(QAbstractButton *button)

// Select user option and update
NavApp::getMainUi()->actionMapShowSunShadingUserTime->setChecked(true);
MapWidget *mapWidget = NavApp::getMapWidget();
MapWidget *mapWidget = NavApp::getMapWidgetGui();
mapWidget->setSunShadingDateTime(getDateTime());
mapWidget->update();
mapWidget->updateSunShadingOption();
Expand Down
12 changes: 6 additions & 6 deletions src/info/infocontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ namespace ahtml = atools::util::html;
InfoController::InfoController(MainWindow *parent)
: QObject(parent), mainWindow(parent)
{
mapQuery = NavApp::getMapQuery();
mapQuery = NavApp::getMapQueryGui();
airportQuery = NavApp::getAirportQuerySim();

airspaceController = NavApp::getAirspaceController();

infoBuilder = new HtmlInfoBuilder(mainWindow, true);
infoBuilder = new HtmlInfoBuilder(mainWindow, parent->getMapWidget(), true);

// Get base font size for widgets
Ui::MainWindow *ui = NavApp::getMainUi();
Expand Down Expand Up @@ -236,7 +236,7 @@ void InfoController::anchorClicked(const QUrl& url)
{
// Internal link like "show on map"
QUrlQuery query(url);
MapWidget *mapWidget = NavApp::getMapWidget();
MapWidget *mapWidget = NavApp::getMapWidgetGui();
if(url.host() == "do")
{
if(query.hasQueryItem("hideairspaces"))
Expand Down Expand Up @@ -326,12 +326,12 @@ void InfoController::anchorClicked(const QUrl& url)
else if(type == map::AIRWAY)
{
// Show full airways by id ================================================
map::MapAirway airway = NavApp::getAirwayTrackQuery()->getAirwayById(id);
map::MapAirway airway = NavApp::getAirwayTrackQueryGui()->getAirwayById(id);

// Get all airway segments and the bounding rectangle
atools::geo::Rect bounding;
QList<map::MapAirway> airways;
NavApp::getAirwayTrackQuery()->getAirwayFull(airways, bounding, airway.name, airway.fragment);
NavApp::getAirwayTrackQueryGui()->getAirwayFull(airways, bounding, airway.name, airway.fragment);

QList<QList<map::MapAirway> > airwayHighlights = mapWidget->getAirwayHighlights();
airwayHighlights.append(airways);
Expand Down Expand Up @@ -1426,7 +1426,7 @@ QStringList InfoController::getAirportTextFull(const QString& ident) const
mainWindow->buildWeatherContext(weatherContext, airport);

atools::util::HtmlBuilder html(mapcolors::webTableBackgroundColor, mapcolors::webTableAltBackgroundColor);
HtmlInfoBuilder builder(mainWindow, true /*info*/, true /*print*/);
HtmlInfoBuilder builder(mainWindow, mainWindow->getMapWidget(), true /*info*/, true /*print*/);
builder.airportText(airport, weatherContext, html, nullptr);
retval.append(html.getHtml());

Expand Down
1 change: 0 additions & 1 deletion src/info/infocontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
class MainWindow;
class MapQuery;
class AirportQuery;
class AirspaceQuery;
class InfoQuery;
class HtmlInfoBuilder;
class QTextEdit;
Expand Down
4 changes: 2 additions & 2 deletions src/mapgui/mapcontextmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,8 @@ void MapContextMenu::procedureFlags(const map::MapBase *base, bool *departure, b
*roundtrip = NavApp::getRouteConst().isAirportRoundTrip(airport->ident);

if(arrivalProc != nullptr)
*arrivalProc = NavApp::getMapQuery()->hasArrivalProcedures(*airport);
*arrivalProc = NavApp::getMapQueryGui()->hasArrivalProcedures(*airport);
if(departureProc != nullptr)
*departureProc = NavApp::getMapQuery()->hasDepartureProcedures(*airport);
*departureProc = NavApp::getMapQueryGui()->hasDepartureProcedures(*airport);
}
}
Loading

0 comments on commit 88dbf4e

Please sign in to comment.