MainWindow.cc 41.2 KB
Newer Older
1
2
3
4
/*=====================================================================

QGroundControl Open Source Ground Control Station

Lorenz Meier's avatar
Lorenz Meier committed
5
(c) 2009 - 2013 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Implementation of class MainWindow
 *   @author Lorenz Meier <mail@qgroundcontrol.org>
 */

#include <QSettings>
#include <QNetworkInterface>
#include <QDebug>
#include <QTimer>
#include <QHostInfo>
#include <QSplashScreen>
dogmaphobic's avatar
dogmaphobic committed
36
#ifndef __mobile__
37
38
39
#include <QGCHilLink.h>
#include <QGCHilConfiguration.h>
#include <QGCHilFlightGearConfiguration.h>
dogmaphobic's avatar
dogmaphobic committed
40
#endif
41
#include <QQuickView>
42
43
#include <QDesktopWidget>

44
#include "QGC.h"
dogmaphobic's avatar
dogmaphobic committed
45
#ifndef __ios__
46
#include "SerialLink.h"
dogmaphobic's avatar
dogmaphobic committed
47
#endif
48
49
50
#include "MAVLinkProtocol.h"
#include "QGCWaypointListMulti.h"
#include "MainWindow.h"
dogmaphobic's avatar
dogmaphobic committed
51
#ifndef __mobile__
52
#include "JoystickWidget.h"
dogmaphobic's avatar
dogmaphobic committed
53
#endif
54
55
#include "GAudioOutput.h"
#include "QGCMAVLinkLogPlayer.h"
Don Gagne's avatar
Don Gagne committed
56
#include "SettingsDialog.h"
57
#include "QGCMapTool.h"
58
#include "QGCMapDisplay.h"
59
60
61
#include "MAVLinkDecoder.h"
#include "QGCMAVLinkMessageSender.h"
#include "QGCRGBDView.h"
62
#include "UASQuickView.h"
63
64
#include "QGCDataPlot2D.h"
#include "Linecharts.h"
65
66
#include "QGCTabbedInfoView.h"
#include "UASRawStatusView.h"
67
#include "FlightDisplay.h"
68
#include "SetupView.h"
69
#include "QGCUASFileViewMulti.h"
Don Gagne's avatar
Don Gagne committed
70
#include "QGCApplication.h"
71
#include "QGCFileDialog.h"
Don Gagne's avatar
Don Gagne committed
72
#include "QGCMessageBox.h"
73
#include "QGCDockWidget.h"
Don Gagne's avatar
Don Gagne committed
74
#include "CustomCommandWidget.h"
75

76
77
78
79
#ifdef UNITTEST_BUILD
#include "QmlControls/QmlTestWidget.h"
#endif

80
81
82
83
84
85
#ifdef QGC_OSG_ENABLED
#include "Q3DWidgetFactory.h"
#endif

#include "LogCompressor.h"

86
87
88
/// The key under which the Main Window settings are saved
const char* MAIN_SETTINGS_GROUP = "QGC_MAINWINDOW";

89
90
91
92
93
const char* MainWindow::_uasControlDockWidgetName = "UNMANNED_SYSTEM_CONTROL_DOCKWIDGET";
const char* MainWindow::_uasListDockWidgetName = "UNMANNED_SYSTEM_LIST_DOCKWIDGET";
const char* MainWindow::_waypointsDockWidgetName = "WAYPOINT_LIST_DOCKWIDGET";
const char* MainWindow::_mavlinkDockWidgetName = "MAVLINK_INSPECTOR_DOCKWIDGET";
const char* MainWindow::_parametersDockWidgetName = "PARAMETER_INTERFACE_DOCKWIDGET";
Don Gagne's avatar
Don Gagne committed
94
const char* MainWindow::_customCommandWidgetName = "CUSTOM_COMMAND_DOCKWIDGET";
95
96
97
98
99
100
101
102
103
104
const char* MainWindow::_filesDockWidgetName = "FILE_VIEW_DOCKWIDGET";
const char* MainWindow::_uasStatusDetailsDockWidgetName = "UAS_STATUS_DETAILS_DOCKWIDGET";
const char* MainWindow::_mapViewDockWidgetName = "MAP_VIEW_DOCKWIDGET";
const char* MainWindow::_hsiDockWidgetName = "HORIZONTAL_SITUATION_INDICATOR_DOCKWIDGET";
const char* MainWindow::_hdd1DockWidgetName = "HEAD_DOWN_DISPLAY_1_DOCKWIDGET";
const char* MainWindow::_hdd2DockWidgetName = "HEAD_DOWN_DISPLAY_2_DOCKWIDGET";
const char* MainWindow::_pfdDockWidgetName = "PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET";
const char* MainWindow::_hudDockWidgetName = "HEAD_UP_DISPLAY_DOCKWIDGET";
const char* MainWindow::_uasInfoViewDockWidgetName = "UAS_INFO_INFOVIEW_DOCKWIDGET";

Don Gagne's avatar
Don Gagne committed
105
106
static MainWindow* _instance = NULL;   ///< @brief MainWindow singleton

107
MainWindow* MainWindow::_create(QSplashScreen* splashScreen)
108
{
Don Gagne's avatar
Don Gagne committed
109
    Q_ASSERT(_instance == NULL);
110
    new MainWindow(splashScreen);
Don Gagne's avatar
Don Gagne committed
111
112
    // _instance is set in constructor
    Q_ASSERT(_instance);
113
114
115
    return _instance;
}

Don Gagne's avatar
Don Gagne committed
116
MainWindow* MainWindow::instance(void)
117
{
Don Gagne's avatar
Don Gagne committed
118
    return _instance;
119
120
}

Don Gagne's avatar
Don Gagne committed
121
122
void MainWindow::deleteInstance(void)
{
Don Gagne's avatar
Don Gagne committed
123
    delete this;
Don Gagne's avatar
Don Gagne committed
124
125
}

Don Gagne's avatar
Don Gagne committed
126
127
128
/// @brief Private constructor for MainWindow. MainWindow singleton is only ever created
///         by MainWindow::_create method. Hence no other code should have access to
///         constructor.
dogmaphobic's avatar
dogmaphobic committed
129
130
131
MainWindow::MainWindow(QSplashScreen* splashScreen)
    : _autoReconnect(false)
    , _lowPowerMode(false)
132
    , _showStatusBar(false)
dogmaphobic's avatar
dogmaphobic committed
133
134
135
136
137
    , _centerStackActionGroup(new QActionGroup(this))
    , _centralLayout(NULL)
    , _currentViewWidget(NULL)
    , _splashScreen(splashScreen)
    , _currentView(VIEW_SETUP)
138
{
Don Gagne's avatar
Don Gagne committed
139
140
    Q_ASSERT(_instance == NULL);
    _instance = this;
141

Don Gagne's avatar
Don Gagne committed
142
143
144
    if (splashScreen) {
        connect(this, &MainWindow::initStatusChanged, splashScreen, &QSplashScreen::showMessage);
    }
145

146
147
148
149
    // Qt 4/5 on Ubuntu does place the native menubar correctly so on Linux we revert back to in-window menu bar.
#ifdef Q_OS_LINUX
    menuBar()->setNativeMenuBar(false);
#endif
dogmaphobic's avatar
dogmaphobic committed
150
    // Setup user interface
151
    loadSettings();
152
    emit initStatusChanged(tr("Setting up user interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
dogmaphobic's avatar
dogmaphobic committed
153
154
    _ui.setupUi(this);
    // Make sure tool bar elements all fit before changing minimum width
dogmaphobic's avatar
dogmaphobic committed
155
    setMinimumWidth(1008);
dogmaphobic's avatar
dogmaphobic committed
156
    configureWindowName();
157

158
159
    // Setup central widget with a layout to hold the views
    _centralLayout = new QVBoxLayout();
160
    _centralLayout->setContentsMargins(0,0,0,0);
161
    centralWidget()->setLayout(_centralLayout);
162
163
164
    // Set dock options
    setDockOptions(AnimatedDocks | AllowTabbedDocks | AllowNestedDocks);
    // Setup corners
165
    setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
166

dogmaphobic's avatar
dogmaphobic committed
167
168
169
    // On Mobile devices, we don't want any main menus at all.
#ifdef __mobile__
    menuBar()->setNativeMenuBar(false);
dogmaphobic's avatar
dogmaphobic committed
170
#endif
dogmaphobic's avatar
dogmaphobic committed
171

172
173
174
#ifdef UNITTEST_BUILD
    QAction* qmlTestAction = new QAction("Test QML palette and controls", NULL);
    connect(qmlTestAction, &QAction::triggered, this, &MainWindow::_showQmlTestWidget);
dogmaphobic's avatar
dogmaphobic committed
175
    _ui.menuTools->addAction(qmlTestAction);
176
#endif
Lorenz Meier's avatar
Lorenz Meier committed
177

dogmaphobic's avatar
dogmaphobic committed
178
179
180
181
    // Load QML Toolbar
    QDockWidget* widget = new QDockWidget(this);
    widget->setObjectName("ToolBarDockWidget");
    qmlRegisterType<MainToolBar>("QGroundControl.MainToolBar", 1, 0, "MainToolBar");
Don Gagne's avatar
Don Gagne committed
182
    _mainToolBar = new MainToolBar(widget);
dogmaphobic's avatar
dogmaphobic committed
183
184
185
186
    widget->setWidget(_mainToolBar);
    widget->setFeatures(QDockWidget::NoDockWidgetFeatures);
    widget->setTitleBarWidget(new QWidget(this)); // Disables the title bar
    addDockWidget(Qt::TopDockWidgetArea, widget);
187

dogmaphobic's avatar
dogmaphobic committed
188
189
190
    // Setup UI state machines
    _centerStackActionGroup->setExclusive(true);
    // Status Bar
Don Gagne's avatar
Don Gagne committed
191
    setStatusBar(new QStatusBar(this));
192
    statusBar()->setSizeGripEnabled(true);
193

194
    emit initStatusChanged(tr("Building common widgets."), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
195
    _buildCommonWidgets();
196
    emit initStatusChanged(tr("Building common actions"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
197
198
199
    // Create actions
    connectCommonActions();
    // Connect user interface devices
200
    emit initStatusChanged(tr("Initializing joystick interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
dogmaphobic's avatar
dogmaphobic committed
201
#ifndef __mobile__
202
    joystick = new JoystickInput();
dogmaphobic's avatar
dogmaphobic committed
203
#endif
204
#ifdef QGC_MOUSE_ENABLED_WIN
205
    emit initStatusChanged(tr("Initializing 3D mouse interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
206
207
    mouseInput = new Mouse3DInput(this);
    mouse = new Mouse6dofInput(mouseInput);
208
#endif //QGC_MOUSE_ENABLED_WIN
209

210
#if QGC_MOUSE_ENABLED_LINUX
211
    emit initStatusChanged(tr("Initializing 3D mouse interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
212
213

    mouse = new Mouse6dofInput(this);
214
    connect(this, SIGNAL(x11EventOccured(XEvent*)), mouse, SLOT(handleX11Event(XEvent*)));
215
#endif //QGC_MOUSE_ENABLED_LINUX
216

217
218
219
220
    // These also cause the screen to redraw so we need to update any OpenGL canvases in QML controls
    connect(LinkManager::instance(), &LinkManager::linkConnected,    this, &MainWindow::_linkStateChange);
    connect(LinkManager::instance(), &LinkManager::linkDisconnected, this, &MainWindow::_linkStateChange);

221
    // Connect link
dogmaphobic's avatar
dogmaphobic committed
222
    if (_autoReconnect)
223
    {
224
        restoreLastUsedConnection();
225
226
227
    }

    // Set low power mode
dogmaphobic's avatar
dogmaphobic committed
228
    enableLowPowerMode(_lowPowerMode);
229
    emit initStatusChanged(tr("Restoring last view state"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
230
    // Restore the window setup
231
    _loadCurrentViewState();
dogmaphobic's avatar
dogmaphobic committed
232
#ifndef __mobile__
233

234
    // Restore the window position and size
dogmaphobic's avatar
dogmaphobic committed
235
236
    emit initStatusChanged(tr("Restoring last window size"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
    if (settings.contains(_getWindowGeometryKey()))
237
    {
dogmaphobic's avatar
dogmaphobic committed
238
        restoreGeometry(settings.value(_getWindowGeometryKey()).toByteArray());
239
240
241
242
    }
    else
    {
        // Adjust the size
dogmaphobic's avatar
dogmaphobic committed
243
244
245
        QScreen* scr = QApplication::primaryScreen();
        QSize scrSize = scr->availableSize();
        if (scrSize.width() <= 1280)
246
        {
dogmaphobic's avatar
dogmaphobic committed
247
            resize(scrSize.width(), scrSize.height());
248
249
250
        }
        else
        {
dogmaphobic's avatar
dogmaphobic committed
251
252
253
            int w = scrSize.width()  > 1600 ? 1600 : scrSize.width();
            int h = scrSize.height() >  800 ?  800 : scrSize.height();
            resize(w, h);
254
            move((scrSize.width() - w) / 2, (scrSize.height() - h) / 2);
255
256
257
        }
    }

258
259
260
    // Make sure the proper fullscreen/normal menu item is checked properly.
    if (isFullScreen())
    {
dogmaphobic's avatar
dogmaphobic committed
261
262
        _ui.actionFullscreen->setChecked(true);
        _ui.actionNormal->setChecked(false);
263
264
265
    }
    else
    {
dogmaphobic's avatar
dogmaphobic committed
266
267
        _ui.actionFullscreen->setChecked(false);
        _ui.actionNormal->setChecked(true);
268
269
270
    }

    // And that they will stay checked properly after user input
271
272
    connect(_ui.actionFullscreen, &QAction::triggered, this, &MainWindow::fullScreenActionItemCallback);
    connect(_ui.actionNormal,     &QAction::triggered, this, &MainWindow::normalActionItemCallback);
273
274
#endif

275
    connect(_ui.actionStatusBar,  &QAction::triggered, this, &MainWindow::showStatusBarCallback);
276

277
278
    // Set OS dependent keyboard shortcuts for the main window, non OS dependent shortcuts are set in MainWindow.ui
#ifdef Q_OS_MACX
dogmaphobic's avatar
dogmaphobic committed
279
    _ui.actionSetup->setShortcut(QApplication::translate("MainWindow", "Meta+1", 0));
280
281
282
    _ui.actionPlan->setShortcut(QApplication::translate("MainWindow", "Meta+2", 0));
    _ui.actionFlight->setShortcut(QApplication::translate("MainWindow", "Meta+3", 0));
    _ui.actionAnalyze->setShortcut(QApplication::translate("MainWindow", "Meta+4", 0));
Don Gagne's avatar
Don Gagne committed
283
    _ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Meta+5", 0));
dogmaphobic's avatar
dogmaphobic committed
284
    _ui.actionFullscreen->setShortcut(QApplication::translate("MainWindow", "Meta+Return", 0));
285
#else
dogmaphobic's avatar
dogmaphobic committed
286
    _ui.actionSetup->setShortcut(QApplication::translate("MainWindow", "Ctrl+1", 0));
Gus Grubba's avatar
Gus Grubba committed
287
    _ui.actionPlan->setShortcut(QApplication::translate("MainWindow", "Ctrl+2", 0));
288
    _ui.actionFlight->setShortcut(QApplication::translate("MainWindow", "Ctrl+3", 0));
Gus Grubba's avatar
Gus Grubba committed
289
    _ui.actionAnalyze->setShortcut(QApplication::translate("MainWindow", "Ctrl+4", 0));
Don Gagne's avatar
Don Gagne committed
290
    _ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Ctrl+5", 0));
dogmaphobic's avatar
dogmaphobic committed
291
    _ui.actionFullscreen->setShortcut(QApplication::translate("MainWindow", "Ctrl+Return", 0));
292
293
#endif

294
295
    connect(&windowNameUpdateTimer, SIGNAL(timeout()), this, SLOT(configureWindowName()));
    windowNameUpdateTimer.start(15000);
296
    emit initStatusChanged(tr("Done"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
297
298

    if (!qgcApp()->runningUnitTests()) {
299
300
        _ui.actionStatusBar->setChecked(_showStatusBar);
        showStatusBarCallback(_showStatusBar);
dogmaphobic's avatar
dogmaphobic committed
301
#ifdef __mobile__
302
303
        menuBar()->hide();
#endif
304
        show();
dogmaphobic's avatar
dogmaphobic committed
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#ifdef Q_OS_MAC
        // TODO HACK
        // This is a really ugly hack. For whatever reason, by having a QQuickWidget inside a
        // QDockWidget (MainToolBar above), the main menu is not shown when the app first
        // starts. I looked everywhere and I could not find a solution. What I did notice was
        // that if any other window gets focus, the menu comes up when you come back to QGC.
        // That is, if you were to click on another window and then back to QGC, the menus
        // would appear. This hack below creates a 0x0 dialog and immediately closes it.
        // That works around the issue and it will do until I find the root of the problem.
        QDialog qd(this);
        qd.show();
        qd.raise();
        qd.activateWindow();
        qd.close();
#endif
320
    }
321
322
323
324
}

MainWindow::~MainWindow()
{
dogmaphobic's avatar
dogmaphobic committed
325
#ifndef __mobile__
326
327
    if (joystick)
    {
328
329
        joystick->shutdown();
        joystick->wait(5000);
Lorenz Meier's avatar
Lorenz Meier committed
330
        joystick->deleteLater();
331
332
        joystick = NULL;
    }
dogmaphobic's avatar
dogmaphobic committed
333
#endif
334
    // Delete all UAS objects
dogmaphobic's avatar
dogmaphobic committed
335
    for (int i=0;i<_commsWidgetList.size();i++)
336
    {
dogmaphobic's avatar
dogmaphobic committed
337
        _commsWidgetList[i]->deleteLater();
338
    }
Don Gagne's avatar
Don Gagne committed
339
    _instance = NULL;
340
341
342
343
344
345
346
}

void MainWindow::resizeEvent(QResizeEvent * event)
{
    QMainWindow::resizeEvent(event);
}

dogmaphobic's avatar
dogmaphobic committed
347
QString MainWindow::_getWindowStateKey()
348
{
349
	return QString::number(_currentView)+"_windowstate_";
350
351
}

dogmaphobic's avatar
dogmaphobic committed
352
QString MainWindow::_getWindowGeometryKey()
353
354
355
356
{
    return "_geometry";
}

357
358
359
void MainWindow::_createDockWidget(const QString& title, const QString& name, Qt::DockWidgetArea area, QWidget* innerWidget)
{
    Q_ASSERT(!_mapName2DockWidget.contains(name));
360
	
361
362
363
364
365
    // Add to menu
    QAction* action = new QAction(title, NULL);
    action->setCheckable(true);
    action->setData(name);
    connect(action, &QAction::triggered, this, &MainWindow::_showDockWidgetAction);
dogmaphobic's avatar
dogmaphobic committed
366
    _ui.menuTools->addAction(action);
367
368
369
370
371
372
373
374
375
376
377
378
379
	
	// Create widget
	QGCDockWidget* dockWidget = new QGCDockWidget(title, action, this);
	Q_CHECK_PTR(dockWidget);
	dockWidget->setObjectName(name);
	dockWidget->setVisible (false);
	if (innerWidget) {
		// Put inner widget inside QDockWidget
		innerWidget->setParent(dockWidget);
		dockWidget->setWidget(innerWidget);
		innerWidget->setVisible(true);
	}
	
380
381
382
383
384
385
    _mapName2DockWidget[name] = dockWidget;
    _mapDockWidget2Action[dockWidget] = action;
    addDockWidget(area, dockWidget);
}

void MainWindow::_buildCommonWidgets(void)
386
387
{
    // Add generic MAVLink decoder
dogmaphobic's avatar
dogmaphobic committed
388
    // TODO: This is never deleted
389
    mavlinkDecoder = new MAVLinkDecoder(MAVLinkProtocol::instance(), this);
John Tapsell's avatar
John Tapsell committed
390
391
    connect(mavlinkDecoder, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),
                      this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)));
392

393
    // Log player
dogmaphobic's avatar
dogmaphobic committed
394
    // TODO: Make this optional with a preferences setting or under a "View" menu
Don Gagne's avatar
Don Gagne committed
395
    logPlayer = new QGCMAVLinkLogPlayer(statusBar());
Don Gagne's avatar
Don Gagne committed
396
    statusBar()->addPermanentWidget(logPlayer);
397

398
399
400
    // In order for Qt to save and restore state of widgets all widgets must be created ahead of time. We only create the QDockWidget
    // holders. We do not create the actual inner widget until it is needed. This saves memory and cpu from running widgets that are
    // never shown.
401

402
403
404
405
406
    struct DockWidgetInfo {
        const char* name;
        const char* title;
        Qt::DockWidgetArea area;
    };
407

408
409
410
411
412
    static const struct DockWidgetInfo rgDockWidgetInfo[] = {
        { _uasControlDockWidgetName,        "Control",                  Qt::LeftDockWidgetArea },
        { _uasListDockWidgetName,           "Unmanned Systems",         Qt::RightDockWidgetArea },
        { _waypointsDockWidgetName,         "Mission Plan",             Qt::BottomDockWidgetArea },
        { _mavlinkDockWidgetName,           "MAVLink Inspector",        Qt::RightDockWidgetArea },
413
        { _parametersDockWidgetName,        "Parameter Editor",			Qt::RightDockWidgetArea },
Don Gagne's avatar
Don Gagne committed
414
        { _customCommandWidgetName,         "Custom Command",			Qt::RightDockWidgetArea },
415
416
417
418
419
420
421
422
423
424
425
        { _filesDockWidgetName,             "Onboard Files",            Qt::RightDockWidgetArea },
        { _uasStatusDetailsDockWidgetName,  "Status Details",           Qt::RightDockWidgetArea },
        { _mapViewDockWidgetName,           "Map view",                 Qt::RightDockWidgetArea },
        { _hsiDockWidgetName,               "Horizontal Situation",     Qt::BottomDockWidgetArea },
        { _hdd1DockWidgetName,              "Flight Display",           Qt::RightDockWidgetArea },
        { _hdd2DockWidgetName,              "Actuator Status",          Qt::RightDockWidgetArea },
        { _pfdDockWidgetName,               "Primary Flight Display",   Qt::RightDockWidgetArea },
        { _hudDockWidgetName,               "Video Downlink",           Qt::RightDockWidgetArea },
        { _uasInfoViewDockWidgetName,       "Info View",                Qt::LeftDockWidgetArea },
    };
    static const size_t cDockWidgetInfo = sizeof(rgDockWidgetInfo) / sizeof(rgDockWidgetInfo[0]);
426

427
428
429
    for (size_t i=0; i<cDockWidgetInfo; i++) {
        const struct DockWidgetInfo* pDockInfo = &rgDockWidgetInfo[i];
        _createDockWidget(pDockInfo->title, pDockInfo->name, pDockInfo->area, NULL /* no inner widget yet */);
430
    }
431
}
432

433
void MainWindow::_buildPlanView(void)
434
{
435
436
437
    if (!_planView) {
        _planView = new QGCMapTool(this);
        _planView->setVisible(false);
438
    }
439
}
440

441
void MainWindow::_buildExperimentalPlanView(void)
442
{
443
444
445
446
447
448
449
450
451
    if (!_experimentalPlanView) {
        _experimentalPlanView = new QGCMapDisplay(this);
        _experimentalPlanView->setVisible(false);
    }
}

void MainWindow::_buildFlightView(void)
{
    if (!_flightView) {
452
        _flightView = new FlightDisplay(this);
453
        _flightView->setVisible(false);
454
    }
455
456
}

457
void MainWindow::_buildSetupView(void)
458
{
459
460
461
462
    if (!_setupView) {
        _setupView = new SetupView(this);
        _setupView->setVisible(false);
    }
463
464
}

465
void MainWindow::_buildAnalyzeView(void)
466
{
467
468
469
    if (!_analyzeView) {
        _analyzeView = new QGCDataPlot2D(this);
        _analyzeView->setVisible(false);
470
471
    }
}
Lorenz Meier's avatar
Lorenz Meier committed
472

473
474
475
476
477
478
void MainWindow::_buildSimView(void)
{
    if (!_simView) {
        _simView = new QGCMapTool(this);
        _simView->setVisible(false);
    }
479
}
480

481
482
/// Shows or hides the specified dock widget, creating if necessary
void MainWindow::_showDockWidget(const QString& name, bool show)
483
{
484
    if (!_mapName2DockWidget.contains(name)) {
Don Gagne's avatar
Don Gagne committed
485
486
        // Don't show any sort of warning here. Dock Widgets which have been remove could still be in settings.
        // Which would cause us to end up here.
487
488
        return;
    }
489

490
491
492
    // Create the inner widget if we need to
    if (!_mapName2DockWidget[name]->widget()) {
        _createInnerDockWidget(name);
493
    }
494
495
496
497

    Q_ASSERT(_mapName2DockWidget.contains(name));
    QDockWidget* dockWidget = _mapName2DockWidget[name];
    Q_ASSERT(dockWidget);
498

499
    dockWidget->setVisible(show);
500

501
502
503
504
505
506
507
508
509
    Q_ASSERT(_mapDockWidget2Action.contains(dockWidget));
    _mapDockWidget2Action[dockWidget]->setChecked(show);
}

/// Creates the specified inner dock widget and adds to the QDockWidget
void MainWindow::_createInnerDockWidget(const QString& widgetName)
{
    Q_ASSERT(_mapName2DockWidget.contains(widgetName)); // QDockWidget should already exist
    Q_ASSERT(!_mapName2DockWidget[widgetName]->widget());     // Inner widget should not
510

511
    QWidget* widget = NULL;
512

513
514
515
516
517
518
519
520
521
    if (widgetName == _uasControlDockWidgetName) {
        widget = new UASControlWidget(this);
    } else if (widgetName == _uasListDockWidgetName) {
        widget = new UASListWidget(this);
    } else if (widgetName == _waypointsDockWidgetName) {
        widget = new QGCWaypointListMulti(this);
    } else if (widgetName == _mavlinkDockWidgetName) {
        widget = new QGCMAVLinkInspector(MAVLinkProtocol::instance(),this);
    } else if (widgetName == _parametersDockWidgetName) {
522
        widget = new ParameterEditorWidget(this);
Don Gagne's avatar
Don Gagne committed
523
524
    } else if (widgetName == _customCommandWidgetName) {
        widget = new CustomCommandWidget(this);
525
526
527
528
529
530
531
532
533
    } else if (widgetName == _filesDockWidgetName) {
        widget = new QGCUASFileViewMulti(this);
    } else if (widgetName == _uasStatusDetailsDockWidgetName) {
        widget = new UASInfoWidget(this);
    } else if (widgetName == _mapViewDockWidgetName) {
        widget = new QGCMapTool(this);
    } else if (widgetName == _hsiDockWidgetName) {
        widget = new HSIDisplay(this);
    } else if (widgetName == _hdd1DockWidgetName) {
534
535
536
537
        QStringList acceptList;
        acceptList.append("-3.3,ATTITUDE.roll,rad,+3.3,s");
        acceptList.append("-3.3,ATTITUDE.pitch,deg,+3.3,s");
        acceptList.append("-3.3,ATTITUDE.yaw,deg,+3.3,s");
538
539
        HDDisplay *hddisplay = new HDDisplay(acceptList,"Flight Display",this);
        hddisplay->addSource(mavlinkDecoder);
540

541
542
        widget = hddisplay;
    } else if (widgetName == _hdd2DockWidgetName) {
543
544
545
        QStringList acceptList;
        acceptList.append("0,RAW_PRESSURE.pres_abs,hPa,65500");
        HDDisplay *hddisplay = new HDDisplay(acceptList,"Actuator Status",this);
546
        hddisplay->addSource(mavlinkDecoder);
547

548
549
        widget = hddisplay;
    } else if (widgetName == _pfdDockWidgetName) {
550
        widget = new FlightDisplay(this);
551
552
553
    } else if (widgetName == _hudDockWidgetName) {
        widget = new HUD(320,240,this);
    } else if (widgetName == _uasInfoViewDockWidgetName) {
554
555
556
        QGCTabbedInfoView* pInfoView = new QGCTabbedInfoView(this);
        pInfoView->addSource(mavlinkDecoder);
        widget = pInfoView;
557
558
    } else {
        qWarning() << "Attempt to create unknown Inner Dock Widget" << widgetName;
559
    }
560

561
562
563
564
565
    if (widget) {
        QDockWidget* dockWidget = _mapName2DockWidget[widgetName];
        Q_CHECK_PTR(dockWidget);
        widget->setParent(dockWidget);
        dockWidget->setWidget(widget);
566
567
    }
}
568

dogmaphobic's avatar
dogmaphobic committed
569
#ifndef __mobile__
570
void MainWindow::_showHILConfigurationWidgets(void)
571
{
572
    UASInterface* uas = UASManager::instance()->getActiveUAS();
573

574
575
576
    if (!uas) {
        return;
    }
577

578
579
    UAS* mav = dynamic_cast<UAS*>(uas);
    Q_ASSERT(mav);
580

581
    int uasId = mav->getUASID();
582

583
    if (!_mapUasId2HilDockWidget.contains(uasId)) {
584

585
        // Create QDockWidget
586
        QGCDockWidget* dockWidget = new QGCDockWidget(tr("HIL Config %1").arg(uasId), NULL, this);
587
588
589
        Q_CHECK_PTR(dockWidget);
        dockWidget->setObjectName(tr("HIL_CONFIG_%1").arg(uasId));
        dockWidget->setVisible (false);
590

591
592
        // Create inner widget and set it
        QWidget* widget = new QGCHilConfiguration(mav, dockWidget);
593

594
595
        widget->setParent(dockWidget);
        dockWidget->setWidget(widget);
596

597
        _mapUasId2HilDockWidget[uasId] = dockWidget;
598

599
600
        addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
    }
601

602
603
604
605
606
    if (_currentView == VIEW_SIMULATION) {
        // HIL dock widgets only show up on simulation view
        foreach (QDockWidget* dockWidget, _mapUasId2HilDockWidget) {
            dockWidget->setVisible(true);
        }
607
608
    }
}
dogmaphobic's avatar
dogmaphobic committed
609
#endif
610

611
void MainWindow::fullScreenActionItemCallback(bool)
612
{
dogmaphobic's avatar
dogmaphobic committed
613
    _ui.actionNormal->setChecked(false);
614
615
}

616
void MainWindow::normalActionItemCallback(bool)
617
{
dogmaphobic's avatar
dogmaphobic committed
618
    _ui.actionFullscreen->setChecked(false);
619
620
}

621
622
623
624
625
626
void MainWindow::showStatusBarCallback(bool checked)
{
    _showStatusBar = checked;
    checked ? statusBar()->show() : statusBar()->hide();
}

627
628
void MainWindow::closeEvent(QCloseEvent *event)
{
629
    // Disallow window close if there are active connections
630
    if (LinkManager::instance()->anyConnectedLinks()) {
dogmaphobic's avatar
dogmaphobic committed
631
632
633
634
635
636
        QGCMessageBox::StandardButton button =
            QGCMessageBox::warning(
                tr("QGroundControl close"),
                tr("There are still active connections to vehicles. Do you want to disconnect these before closing?"),
                QMessageBox::Yes | QMessageBox::Cancel,
                QMessageBox::Cancel);
637
638
639
640
641
642
643
644
645
646
		if (button == QMessageBox::Yes) {
			LinkManager::instance()->disconnectAll();
			// The above disconnect causes a flurry of activity as the vehicle components are removed. This in turn
			// causes the Windows Version of Qt to crash if you allow the close event to be accepted. In order to prevent
			// the crash, we ignore the close event and setup a delayed timer to close the window after things settle down.
			QTimer::singleShot(1500, this, &MainWindow::_closeWindow);
		}

        event->ignore();
        return;
647
648
    }

649
650
    // This will process any remaining flight log save dialogs
    qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
651
    
652
    // Should not be any active connections
653
654
    Q_ASSERT(!LinkManager::instance()->anyConnectedLinks());
    
655
    _storeCurrentViewState();
656
    storeSettings();
657
    UASManager::instance()->storeSettings();
658
    event->accept();
659
660
661
662
}

void MainWindow::loadSettings()
{
663
    // Why the screaming?
664
    QSettings settings;
665
    settings.beginGroup(MAIN_SETTINGS_GROUP);
666
667
668
    _autoReconnect  = settings.value("AUTO_RECONNECT",      _autoReconnect).toBool();
    _lowPowerMode   = settings.value("LOW_POWER_MODE",      _lowPowerMode).toBool();
    _showStatusBar  = settings.value("SHOW_STATUSBAR",      _showStatusBar).toBool();
669
670
671
672
673
674
    settings.endGroup();
}

void MainWindow::storeSettings()
{
    QSettings settings;
675
    settings.beginGroup(MAIN_SETTINGS_GROUP);
676
677
678
    settings.setValue("AUTO_RECONNECT",     _autoReconnect);
    settings.setValue("LOW_POWER_MODE",     _lowPowerMode);
    settings.setValue("SHOW_STATUSBAR",     _showStatusBar);
679
    settings.endGroup();
dogmaphobic's avatar
dogmaphobic committed
680
    settings.setValue(_getWindowGeometryKey(), saveGeometry());
681
	
682
    // Save the last current view in any case
683
    settings.setValue("CURRENT_VIEW", _currentView);
684
    settings.setValue(_getWindowStateKey(), saveState());
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
}

void MainWindow::configureWindowName()
{
    QList<QHostAddress> hostAddresses = QNetworkInterface::allAddresses();
    QString windowname = qApp->applicationName() + " " + qApp->applicationVersion();
    bool prevAddr = false;
    windowname.append(" (" + QHostInfo::localHostName() + ": ");
    for (int i = 0; i < hostAddresses.size(); i++)
    {
        // Exclude loopback IPv4 and all IPv6 addresses
        if (hostAddresses.at(i) != QHostAddress("127.0.0.1") && !hostAddresses.at(i).toString().contains(":"))
        {
            if(prevAddr) windowname.append("/");
            windowname.append(hostAddresses.at(i).toString());
            prevAddr = true;
        }
    }
    windowname.append(")");
    setWindowTitle(windowname);
}

void MainWindow::enableAutoReconnect(bool enabled)
{
dogmaphobic's avatar
dogmaphobic committed
709
    _autoReconnect = enabled;
710
711
712
713
714
715
716
717
718
}

/**
* @brief Create all actions associated to the main window
*
**/
void MainWindow::connectCommonActions()
{
    // Bind together the perspective actions
dogmaphobic's avatar
dogmaphobic committed
719
    QActionGroup* perspectives = new QActionGroup(_ui.menuPerspectives);
720
721
    perspectives->addAction(_ui.actionAnalyze);
    perspectives->addAction(_ui.actionFlight);
dogmaphobic's avatar
dogmaphobic committed
722
    perspectives->addAction(_ui.actionSimulationView);
723
    perspectives->addAction(_ui.actionPlan);
dogmaphobic's avatar
dogmaphobic committed
724
    perspectives->addAction(_ui.actionSetup);
725
    perspectives->addAction(_ui.actionExperimentalPlanView);
726
727
728
    perspectives->setExclusive(true);

    // Mark the right one as selected
729
    if (_currentView == VIEW_ANALYZE)
730
    {
731
732
        _ui.actionAnalyze->setChecked(true);
        _ui.actionAnalyze->activate(QAction::Trigger);
733
    }
734
    if (_currentView == VIEW_FLIGHT)
735
    {
736
737
        _ui.actionFlight->setChecked(true);
        _ui.actionFlight->activate(QAction::Trigger);
738
    }
739
    if (_currentView == VIEW_SIMULATION)
740
    {
dogmaphobic's avatar
dogmaphobic committed
741
742
        _ui.actionSimulationView->setChecked(true);
        _ui.actionSimulationView->activate(QAction::Trigger);
743
    }
744
    if (_currentView == VIEW_PLAN)
745
    {
746
747
748
749
750
751
752
        _ui.actionPlan->setChecked(true);
        _ui.actionPlan->activate(QAction::Trigger);
    }
    if (_currentView == VIEW_EXPERIMENTAL_PLAN)
    {
        _ui.actionExperimentalPlanView->setChecked(true);
        _ui.actionExperimentalPlanView->activate(QAction::Trigger);
753
    }
754
    if (_currentView == VIEW_SETUP)
755
    {
dogmaphobic's avatar
dogmaphobic committed
756
757
        _ui.actionSetup->setChecked(true);
        _ui.actionSetup->activate(QAction::Trigger);
758
    }
759
760

    // The UAS actions are not enabled without connection to system
dogmaphobic's avatar
dogmaphobic committed
761
762
763
764
765
    _ui.actionLiftoff->setEnabled(false);
    _ui.actionLand->setEnabled(false);
    _ui.actionEmergency_Kill->setEnabled(false);
    _ui.actionEmergency_Land->setEnabled(false);
    _ui.actionShutdownMAV->setEnabled(false);
766
767

    // Connect actions from ui
dogmaphobic's avatar
dogmaphobic committed
768
    connect(_ui.actionAdd_Link, SIGNAL(triggered()), this, SLOT(manageLinks()));
769
770
771

    // Connect internal actions
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(UASCreated(UASInterface*)));
772
    connect(UASManager::instance(), SIGNAL(UASDeleted(int)), this, SLOT(UASDeleted(int)));
773
774

    // Unmanned System controls
dogmaphobic's avatar
dogmaphobic committed
775
776
777
778
779
    connect(_ui.actionLiftoff, SIGNAL(triggered()), UASManager::instance(), SLOT(launchActiveUAS()));
    connect(_ui.actionLand, SIGNAL(triggered()), UASManager::instance(), SLOT(returnActiveUAS()));
    connect(_ui.actionEmergency_Land, SIGNAL(triggered()), UASManager::instance(), SLOT(stopActiveUAS()));
    connect(_ui.actionEmergency_Kill, SIGNAL(triggered()), UASManager::instance(), SLOT(killActiveUAS()));
    connect(_ui.actionShutdownMAV, SIGNAL(triggered()), UASManager::instance(), SLOT(shutdownActiveUAS()));
780
781

    // Views actions
782
    connect(_ui.actionFlight, SIGNAL(triggered()), this, SLOT(loadFlightView()));
dogmaphobic's avatar
dogmaphobic committed
783
    connect(_ui.actionSimulationView, SIGNAL(triggered()), this, SLOT(loadSimulationView()));
784
785
786
    connect(_ui.actionAnalyze, SIGNAL(triggered()), this, SLOT(loadAnalyzeView()));
    connect(_ui.actionPlan, SIGNAL(triggered()), this, SLOT(loadPlanView()));
    connect(_ui.actionExperimentalPlanView, SIGNAL(triggered()), this, SLOT(loadOldPlanView()));
787
788

    // Help Actions
dogmaphobic's avatar
dogmaphobic committed
789
790
791
    connect(_ui.actionOnline_Documentation, SIGNAL(triggered()), this, SLOT(showHelp()));
    connect(_ui.actionDeveloper_Credits, SIGNAL(triggered()), this, SLOT(showCredits()));
    connect(_ui.actionProject_Roadmap, SIGNAL(triggered()), this, SLOT(showRoadMap()));
792
793

    // Audio output
dogmaphobic's avatar
dogmaphobic committed
794
795
796
    _ui.actionMuteAudioOutput->setChecked(GAudioOutput::instance()->isMuted());
    connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), _ui.actionMuteAudioOutput, SLOT(setChecked(bool)));
    connect(_ui.actionMuteAudioOutput, SIGNAL(triggered(bool)), GAudioOutput::instance(), SLOT(mute(bool)));
797
798

    // Application Settings
dogmaphobic's avatar
dogmaphobic committed
799
    connect(_ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
800

dogmaphobic's avatar
dogmaphobic committed
801
    // Update Tool Bar
802
    _mainToolBar->setCurrentView(_currentView);
803
804
}

Don Gagne's avatar
Don Gagne committed
805
void MainWindow::_openUrl(const QString& url, const QString& errorMessage)
806
{
Don Gagne's avatar
Don Gagne committed
807
    if(!QDesktopServices::openUrl(QUrl(url))) {
dogmaphobic's avatar
dogmaphobic committed
808
809
810
811
        QMessageBox::critical(
            this,
            tr("Could not open information in browser"),
            errorMessage);
812
813
814
    }
}

Don Gagne's avatar
Don Gagne committed
815
816
void MainWindow::showHelp()
{
dogmaphobic's avatar
dogmaphobic committed
817
818
819
    _openUrl(
        "http://qgroundcontrol.org/users/start",
        tr("To get to the online help, please open http://qgroundcontrol.org/user_guide in a browser."));
Don Gagne's avatar
Don Gagne committed
820
821
}

822
823
void MainWindow::showCredits()
{
dogmaphobic's avatar
dogmaphobic committed
824
825
826
    _openUrl(
        "http://qgroundcontrol.org/credits",
        tr("To get to the credits, please open http://qgroundcontrol.org/credits in a browser."));
827
828
829
830
}

void MainWindow::showRoadMap()
{
dogmaphobic's avatar
dogmaphobic committed
831
832
833
    _openUrl(
        "http://qgroundcontrol.org/dev/roadmap",
        tr("To get to the online help, please open http://qgroundcontrol.org/roadmap in a browser."));
834
835
836
837
}

void MainWindow::showSettings()
{
dogmaphobic's avatar
dogmaphobic committed
838
#ifndef __mobile__
Don Gagne's avatar
Don Gagne committed
839
    SettingsDialog settings(joystick, this);
dogmaphobic's avatar
dogmaphobic committed
840
841
842
#else
    SettingsDialog settings(this);
#endif
Don Gagne's avatar
Don Gagne committed
843
    settings.exec();
844
845
}

846
847
void MainWindow::commsWidgetDestroyed(QObject *obj)
{
848
849
    // Do not dynamic cast or de-reference QObject, since object is either in destructor or may have already
    // been destroyed.
dogmaphobic's avatar
dogmaphobic committed
850
    if (_commsWidgetList.contains(obj))
851
    {
dogmaphobic's avatar
dogmaphobic committed
852
        _commsWidgetList.removeOne(obj);
853
854
    }
}
855
856
857

void MainWindow::UASCreated(UASInterface* uas)
{
858
    // The UAS actions are not enabled without connection to system
dogmaphobic's avatar
dogmaphobic committed
859
860
861
862
863
    _ui.actionLiftoff->setEnabled(true);
    _ui.actionLand->setEnabled(true);
    _ui.actionEmergency_Kill->setEnabled(true);
    _ui.actionEmergency_Land->setEnabled(true);
    _ui.actionShutdownMAV->setEnabled(true);
864

John Tapsell's avatar
John Tapsell committed
865
    connect(uas, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)));
866
    connect(uas, SIGNAL(misconfigurationDetected(UASInterface*)), this, SLOT(handleMisconfiguration(UASInterface*)));
867

868
    // HIL
dogmaphobic's avatar
dogmaphobic committed
869
#ifndef __mobile__
870
    _showHILConfigurationWidgets();
dogmaphobic's avatar
dogmaphobic committed
871
#endif
872

873
874
875
    if (!linechartWidget)
    {
        linechartWidget = new Linecharts(this);
876
        linechartWidget->setVisible(false);
877
    }
878

879
    linechartWidget->addSource(mavlinkDecoder);
880
    if (_analyzeView != linechartWidget)
881
    {
882
        _analyzeView = linechartWidget;
883
    }
884
885
}

886
887
888
889
890
891
892
893
void MainWindow::UASDeleted(int uasId)
{
    if (_mapUasId2HilDockWidget.contains(uasId)) {
        _mapUasId2HilDockWidget[uasId]->deleteLater();
        _mapUasId2HilDockWidget.remove(uasId);
    }
}

894
895
/// Stores the state of the toolbar, status bar and widgets associated with the current view
void MainWindow::_storeCurrentViewState(void)
896
{
897
898
899
900
901
902
903
904
905
906
907
908
909
    // HIL dock widgets are dynamic and are not part of the saved state
    _hideAllHilDockWidgets();
    // Save list of visible widgets
    bool firstWidget = true;
    QString widgetNames = "";
    foreach(QDockWidget* dockWidget, _mapName2DockWidget) {
        if (dockWidget->isVisible()) {
            if (!firstWidget) {
                widgetNames += ",";
            }
            widgetNames += dockWidget->objectName();
            firstWidget = false;
        }
910
    }
dogmaphobic's avatar
dogmaphobic committed
911
912
913
    settings.setValue(_getWindowStateKey() + "WIDGETS", widgetNames);
    settings.setValue(_getWindowStateKey(), saveState());
    settings.setValue(_getWindowGeometryKey(), saveGeometry());
914
915
}

916
917
/// Restores the state of the toolbar, status bar and widgets associated with the current view
void MainWindow::_loadCurrentViewState(void)
918
{
Don Gagne's avatar
Don Gagne committed
919
    QWidget* centerView = NULL;
920
    QString defaultWidgets;
921

922
    switch (_currentView) {
923
        case VIEW_SETUP:
924
925
            _buildSetupView();
            centerView = _setupView;
926
            break;
927

928
929
930
        case VIEW_ANALYZE:
            _buildAnalyzeView();
            centerView = _analyzeView;
931
            defaultWidgets = "PARAMETER_INTERFACE_DOCKWIDGET,FILE_VIEW_DOCKWIDGET";
932
            break;
933

934
        case VIEW_FLIGHT:
935
936
            _buildFlightView();
            centerView = _flightView;
Don Gagne's avatar
Don Gagne committed
937
            defaultWidgets = "COMMUNICATION_CONSOLE_DOCKWIDGET,UAS_INFO_INFOVIEW_DOCKWIDGET";
938
            break;
939

940
941
942
        case VIEW_PLAN:
            _buildPlanView();
            centerView = _planView;
943
            defaultWidgets = "WAYPOINT_LIST_DOCKWIDGET";
944
            break;
945

946
947
948
949
950
951
        case VIEW_EXPERIMENTAL_PLAN:
            _buildExperimentalPlanView();
            centerView = _experimentalPlanView;
            defaultWidgets.clear();
            break;

952
        case VIEW_SIMULATION:
953
954
955
            _buildSimView();
            centerView = _simView;
            defaultWidgets = "UNMANNED_SYSTEM_CONTROL_DOCKWIDGET,WAYPOINT_LIST_DOCKWIDGET,PARAMETER_INTERFACE_DOCKWIDGET,PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET";
956
            break;
957

958
959
        default:
            Q_ASSERT(false);
960
            break;
961
    }
962

963
964
965
966
967
968
969
970
    // Remove old view
    if (_currentViewWidget) {
        _currentViewWidget->setVisible(false);
        Q_ASSERT(_centralLayout->count() == 1);
        QLayoutItem *child = _centralLayout->takeAt(0);
        Q_ASSERT(child);
        delete child;
    }
971

972
973
974
975
976
    // Add the new one
    Q_ASSERT(centerView);
    Q_ASSERT(_centralLayout->count() == 0);
    _currentViewWidget = centerView;
    _centralLayout->addWidget(_currentViewWidget);
977
    _centralLayout->setContentsMargins(0, 0, 0, 0);
978
    _currentViewWidget->setVisible(true);
979

980
981
982
983
    // Hide all widgets from previous view
    _hideAllDockWidgets();

    // Restore the widgets for the new view
dogmaphobic's avatar
dogmaphobic committed
984
    QString widgetNames = settings.value(_getWindowStateKey() + "WIDGETS", defaultWidgets).toString();
Don Gagne's avatar
Don Gagne committed
985
    qDebug() << widgetNames;
986
987
988
989
990
    if (!widgetNames.isEmpty()) {
        QStringList split = widgetNames.split(",");
        foreach (QString widgetName, split) {
            Q_ASSERT(!widgetName.isEmpty());
            _showDockWidget(widgetName, true);
991
992
993
        }
    }

dogmaphobic's avatar
dogmaphobic committed
994
995
    if (settings.contains(_getWindowStateKey())) {
        restoreState(settings.value(_getWindowStateKey()).toByteArray());
996
    }
997

998
999
    // HIL dock widget are dynamic and don't take part in the saved window state, so this
    // need to happen after we restore state
dogmaphobic's avatar
dogmaphobic committed
1000
#ifndef __mobile__
For faster browsing, not all history is shown. View entire blame