Skip to content

Commit

Permalink
Added closable and movable tabs to flight plan dock window.
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Aug 9, 2019
1 parent 236c968 commit 584f892
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/common/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const QLatin1Literal ROUTE_PRINT_DIALOG("Route/PrintWidget");
const QLatin1Literal ROUTE_STRING_DIALOG_SIZE("Route/StringDialogSize");
const QLatin1Literal ROUTE_STRING_DIALOG_SPLITTER("Route/StringDialogSplitter");
const QLatin1Literal ROUTE_STRING_DIALOG_OPTIONS("Route/StringDialogOptions");
const QLatin1Literal ROUTEWINDOW_WIDGET_TABS("Route/WidgetTabs");
const QLatin1Literal TRAFFIC_PATTERN_DIALOG("Route/TrafficPatternDialog");
const QLatin1Literal TRAFFIC_PATTERN_DIALOG_COLOR("Route/TrafficPatternDialogColor");
const QLatin1Literal HOLD_DIALOG("Route/HoldDialog");
Expand Down
4 changes: 3 additions & 1 deletion src/common/tabindexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

/* Flight plan dock window tabs */
namespace rc {
enum TabIndex
enum TabRouteId
{
ROUTE = 0,
AIRCRAFT = 1,
COLLECTION = 2
};

const QVector<int> TabRouteIds = {ROUTE, AIRCRAFT, COLLECTION};

}

namespace ic {
Expand Down
13 changes: 4 additions & 9 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "gui/dialog.h"
#include "gui/errorhandler.h"
#include "gui/helphandler.h"
#include "gui/tabwidgethandler.h"
#include "gui/itemviewzoomhandler.h"
#include "gui/translator.h"
#include "gui/widgetstate.h"
Expand Down Expand Up @@ -1577,7 +1578,7 @@ void MainWindow::actionShortcutFlightPlanTriggered()
ui->dockWidgetRoute->show();
ui->dockWidgetRoute->activateWindow();
ui->dockWidgetRoute->raise();
ui->tabWidgetRoute->setCurrentIndex(rc::ROUTE);
NavApp::getRouteTabHandler()->setCurrentTab(rc::ROUTE);
ui->tableViewRoute->setFocus();
}

Expand All @@ -1587,7 +1588,7 @@ void MainWindow::actionShortcutAircraftPerformanceTriggered()
ui->dockWidgetRoute->show();
ui->dockWidgetRoute->activateWindow();
ui->dockWidgetRoute->raise();
ui->tabWidgetRoute->setCurrentIndex(rc::AIRCRAFT);
NavApp::getRouteTabHandler()->setCurrentTab(rc::AIRCRAFT);
ui->textBrowserAircraftPerformanceReport->setFocus();
}

Expand Down Expand Up @@ -2109,13 +2110,7 @@ void MainWindow::updateWindowTitle()
newTitle += tr(" - *");

// Add a star to the flight plan tab if changed
if(routeController->hasChanged())
{
if(!ui->tabWidgetRoute->tabText(rc::ROUTE).endsWith(tr(" *")))
ui->tabWidgetRoute->setTabText(rc::ROUTE, ui->tabWidgetRoute->tabText(rc::ROUTE) + tr(" *"));
}
else
ui->tabWidgetRoute->setTabText(rc::ROUTE, ui->tabWidgetRoute->tabText(rc::ROUTE).replace(tr(" *"), QString()));
routeController->updateRouteTabChangedStatus();

setWindowTitle(newTitle);
}
Expand Down
6 changes: 6 additions & 0 deletions src/gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4159,6 +4159,12 @@
<property name="currentIndex">
<number>0</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<property name="movable">
<bool>true</bool>
</property>
<widget class="QWidget" name="tabRoutePlan">
<attribute name="title">
<string>Plan</string>
Expand Down
5 changes: 5 additions & 0 deletions src/navapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,11 @@ RouteController *NavApp::getRouteController()
return mainWindow->getRouteController();
}

atools::gui::TabWidgetHandler *NavApp::getRouteTabHandler()
{
return getRouteController()->getTabHandler();
}

const InfoController *NavApp::getInfoController()
{
return mainWindow->getInfoController();
Expand Down
4 changes: 4 additions & 0 deletions src/navapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class WindReporter;
class MapMarkHandler;

namespace atools {
namespace gui {
class TabWidgetHandler;
}

namespace geo {
class Pos;
Expand Down Expand Up @@ -229,6 +232,7 @@ class NavApp :
static MapWidget *getMapWidget();
static MapPaintWidget *getMapPaintWidget();
static RouteController *getRouteController();
static atools::gui::TabWidgetHandler *getRouteTabHandler();
static const InfoController *getInfoController();

static DatabaseManager *getDatabaseManager();
Expand Down
13 changes: 9 additions & 4 deletions src/perf/aircraftperfcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "gui/widgetstate.h"
#include "fs/perf/aircraftperfhandler.h"
#include "fs/sc/simconnectdata.h"
#include "gui/tabwidgethandler.h"

#include <QDebug>
#include <QUrlQuery>
Expand Down Expand Up @@ -86,8 +87,7 @@ AircraftPerfController::AircraftPerfController(MainWindow *parent)
this, &AircraftPerfController::manualWindToggled);

// Widgets are only updated if visible - update on visbility changes of dock or tabs
connect(ui->tabWidgetRoute, &QTabWidget::currentChanged, this, &AircraftPerfController::visibilityChanged);
connect(ui->dockWidgetRoute, &QDockWidget::visibilityChanged, this, &AircraftPerfController::visibilityChanged);
connect(ui->dockWidgetRoute, &QDockWidget::visibilityChanged, this, &AircraftPerfController::tabVisibilityChanged);

// Create performance handler for background collection
perfHandler = new AircraftPerfHandler(this);
Expand Down Expand Up @@ -545,7 +545,7 @@ void AircraftPerfController::updateActionStates()
void AircraftPerfController::updateReport()
{
Ui::MainWindow *ui = NavApp::getMainUi();
if(ui->tabWidgetRoute->currentIndex() == rc::AIRCRAFT && ui->textBrowserAircraftPerformanceReport->isVisible())
if(NavApp::getRouteTabHandler()->getCurrentTabId() == rc::AIRCRAFT && ui->dockWidgetRoute->isVisible())
{
// Write HTML report ================================================================
HtmlBuilder html(true /* background color */);
Expand Down Expand Up @@ -996,6 +996,10 @@ void AircraftPerfController::restoreState()
{
atools::settings::Settings& settings = atools::settings::Settings::instance();

// Need to initialize this late since route controller is not valid when AircraftPerfController constructor is called
connect(NavApp::getRouteTabHandler(), &atools::gui::TabWidgetHandler::tabChanged,
this, &AircraftPerfController::tabVisibilityChanged);

fileHistory->restoreState();
loadFile(settings.valueStr(lnm::AIRCRAFT_PERF_FILENAME));

Expand Down Expand Up @@ -1087,8 +1091,9 @@ void AircraftPerfController::manualWindToggled()
emit aircraftPerformanceChanged(perf);
}

void AircraftPerfController::visibilityChanged()
void AircraftPerfController::tabVisibilityChanged()
{
qDebug() << Q_FUNC_INFO;
updateReport();
updateReportCurrent();
}
8 changes: 4 additions & 4 deletions src/perf/aircraftperfcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class MainWindow;
*
* Handles all menus, actions and buttons.
*/
class AircraftPerfController :
public QObject
class AircraftPerfController
: public QObject
{
Q_OBJECT

public:
explicit AircraftPerfController(MainWindow *parent);
virtual ~AircraftPerfController();
virtual ~AircraftPerfController() override;

/* Load a new performance file from file history after asking to save currently unchanged */
void loadFile(const QString& perfFile);
Expand Down Expand Up @@ -182,7 +182,7 @@ class AircraftPerfController :
void restartCollect();

/* Dock window or tab visibility changed */
void visibilityChanged();
void tabVisibilityChanged();

/* Cruise altitude either from flight plan or widget */
float cruiseAlt();
Expand Down
27 changes: 23 additions & 4 deletions src/route/routecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "common/unitstringtool.h"
#include "perf/aircraftperfcontroller.h"
#include "fs/sc/simconnectdata.h"
#include "gui/tabwidgethandler.h"

#include <QClipboard>
#include <QFile>
Expand Down Expand Up @@ -133,6 +134,11 @@ RouteController::RouteController(QMainWindow *parentWindow, QTableView *tableVie
flightplanIO = new atools::fs::pln::FlightplanIO();

Ui::MainWindow *ui = NavApp::getMainUi();
tabHandlerRoute = new atools::gui::TabWidgetHandler(ui->tabWidgetRoute,
QIcon(":/littlenavmap/resources/icons/tabbutton.svg"),
tr("Open or close tabs"));
tabHandlerRoute->init(rc::TabRouteIds, lnm::ROUTEWINDOW_WIDGET_TABS);

// Update units
units = new UnitStringTool();
units->init({
Expand Down Expand Up @@ -251,6 +257,7 @@ RouteController::RouteController(QMainWindow *parentWindow, QTableView *tableVie
RouteController::~RouteController()
{
routeAltDelayTimer.stop();
delete tabHandlerRoute;
delete units;
delete entryBuilder;
delete model;
Expand Down Expand Up @@ -644,10 +651,10 @@ void RouteController::saveState()

atools::gui::WidgetState(lnm::ROUTE_VIEW).save({view, ui->comboBoxRouteType,
ui->spinBoxRouteAlt,
ui->actionRouteFollowSelection,
ui->tabWidgetRoute});
ui->actionRouteFollowSelection});

atools::settings::Settings::instance().setValue(lnm::ROUTE_FILENAME, routeFilename);
tabHandlerRoute->saveState();
}

void RouteController::updateTableHeaders()
Expand All @@ -664,12 +671,12 @@ void RouteController::updateTableHeaders()

void RouteController::restoreState()
{
tabHandlerRoute->restoreState();
Ui::MainWindow *ui = NavApp::getMainUi();
updateTableHeaders();

atools::gui::WidgetState state(lnm::ROUTE_VIEW, true, true);
state.restore({view, ui->comboBoxRouteType, ui->spinBoxRouteAlt, ui->actionRouteFollowSelection,
ui->tabWidgetRoute});
state.restore({view, ui->comboBoxRouteType, ui->spinBoxRouteAlt, ui->actionRouteFollowSelection});

if(OptionData::instance().getFlags() & opts::STARTUP_LOAD_ROUTE)
{
Expand Down Expand Up @@ -2931,6 +2938,18 @@ void RouteController::showProceduresCustom(map::MapAirport airport)
}
}

void RouteController::updateRouteTabChangedStatus()
{
Ui::MainWindow *ui = NavApp::getMainUi();
if(hasChanged())
{
if(!ui->tabWidgetRoute->tabText(rc::ROUTE).endsWith(tr(" *")))
ui->tabWidgetRoute->setTabText(rc::ROUTE, ui->tabWidgetRoute->tabText(rc::ROUTE) + tr(" *"));
}
else
ui->tabWidgetRoute->setTabText(rc::ROUTE, ui->tabWidgetRoute->tabText(rc::ROUTE).replace(tr(" *"), QString()));
}

void RouteController::routeAttachProcedure(proc::MapProcedureLegs legs, const QString& sidStarRunway)
{
qDebug() << Q_FUNC_INFO
Expand Down
14 changes: 13 additions & 1 deletion src/route/routecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "route/routecommand.h"
#include "route/route.h"
#include "common/tabindexes.h"

#include <QIcon>
#include <QObject>
Expand All @@ -28,6 +29,7 @@
namespace atools {
namespace gui {
class ItemViewZoomHandler;
class TabWidgetHandler;
}
namespace util {
class HtmlBuilder;
Expand Down Expand Up @@ -71,7 +73,7 @@ class RouteController :

public:
RouteController(QMainWindow *parent, QTableView *tableView);
virtual ~RouteController();
virtual ~RouteController() override;

/* Creates a new plan and emits routeChanged */
void newFlightplan();
Expand Down Expand Up @@ -257,6 +259,14 @@ class RouteController :
return routeFilename;
}

/* Update the changed file indication in the flight plan tab header */
void updateRouteTabChangedStatus();

atools::gui::TabWidgetHandler *getTabHandler() const
{
return tabHandlerRoute;
}

signals:
/* Show airport on map */
void showRect(const atools::geo::Rect& rect, bool doubleClick);
Expand Down Expand Up @@ -444,6 +454,8 @@ class RouteController :

SymbolPainter *symbolPainter = nullptr;

atools::gui::TabWidgetHandler *tabHandlerRoute = nullptr;

QTimer routeAltDelayTimer;

// Route table colum headings
Expand Down

0 comments on commit 584f892

Please sign in to comment.