Commit 4dc1b91a authored by LM's avatar LM
Browse files

Cleaned up MainWindow init dramatically, relying now on Qts persistence...

Cleaned up MainWindow init dramatically, relying now on Qts persistence capabilities. Fixed a number of view persistence issues this way
parent 8bd61d71
......@@ -64,7 +64,8 @@ This file is part of the QGROUNDCONTROL project
MainWindow* MainWindow::instance()
{
static MainWindow* _instance = 0;
if(_instance == 0) {
if(_instance == 0)
{
_instance = new MainWindow();
/* Set the application as parent to ensure that this object
......@@ -90,18 +91,25 @@ MainWindow::MainWindow(QWidget *parent):
styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"),
autoReconnect(false),
currentStyle(QGC_MAINWINDOW_STYLE_INDOOR),
lowPowerMode(false)
lowPowerMode(false),
centerStackActionGroup(this)
{
hide();
loadSettings();
if (!settings.contains("CURRENT_VIEW")) {
if (!settings.contains("CURRENT_VIEW"))
{
// Set this view as default view
settings.setValue("CURRENT_VIEW", currentView);
} else {
}
else
{
// LOAD THE LAST VIEW
VIEW_SECTIONS currentViewCandidate = (VIEW_SECTIONS) settings.value("CURRENT_VIEW", currentView).toInt();
if (currentViewCandidate != VIEW_ENGINEER &&
currentViewCandidate != VIEW_OPERATOR &&
currentViewCandidate != VIEW_PILOT) {
currentViewCandidate != VIEW_PILOT &&
currentViewCandidate != VIEW_FULL)
{
currentView = currentViewCandidate;
}
}
......@@ -110,10 +118,14 @@ MainWindow::MainWindow(QWidget *parent):
settings.sync();
// Setup UI state machines
centerStackActionGroup.setExclusive(true);
// Setup user interface
ui.setupUi(this);
setVisible(false);
centerStack = new QStackedWidget(this);
setCentralWidget(centerStack);
buildCommonWidgets();
......@@ -136,18 +148,28 @@ MainWindow::MainWindow(QWidget *parent):
statusBar()->setSizeGripEnabled(true);
// Restore the window setup
if (settings.contains(getWindowStateKey()))
{
loadViewState();
}
// Restore the window position and size
if (settings.contains(getWindowGeometryKey())) {
if (settings.contains(getWindowGeometryKey()))
{
// Restore the window geometry
restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray());
} else {
}
else
{
// Adjust the size
adjustSize();
}
// Populate link menu
QList<LinkInterface*> links = LinkManager::instance()->getLinks();
foreach(LinkInterface* link, links) {
foreach(LinkInterface* link, links)
{
this->addLink(link);
}
......@@ -170,11 +192,9 @@ MainWindow::MainWindow(QWidget *parent):
toolBar->addPerspectiveChangeAction(ui.actionEngineersView);
toolBar->addPerspectiveChangeAction(ui.actionPilotsView);
// Enable and update view
presentView();
// Connect link
if (autoReconnect) {
if (autoReconnect)
{
SerialLink* link = new SerialLink();
// Add to registry
LinkManager::instance()->add(link);
......@@ -187,6 +207,8 @@ MainWindow::MainWindow(QWidget *parent):
// Initialize window state
windowStateVal = windowState();
show();
}
MainWindow::~MainWindow()
......@@ -203,9 +225,11 @@ MainWindow::~MainWindow()
QObjectList::iterator i;
QDockWidget* dockWidget;
for (i = childList.begin(); i != childList.end(); ++i) {
for (i = childList.begin(); i != childList.end(); ++i)
{
dockWidget = dynamic_cast<QDockWidget*>(*i);
if (dockWidget) {
if (dockWidget)
{
// Remove dock widget from main window
removeDockWidget(dockWidget);
delete dockWidget->widget();
......@@ -219,61 +243,67 @@ MainWindow::~MainWindow()
*/
void MainWindow::setDefaultSettingsForAp()
{
// Check if the settings exist, instantiate defaults if necessary
// UNCONNECTED VIEW DEFAULT
QString centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_UNCONNECTED);
if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true);
// ENABLE UAS LIST
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST, VIEW_UNCONNECTED), true);
// ENABLE COMMUNICATION CONSOLE
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_DEBUG_CONSOLE, VIEW_UNCONNECTED), true);
}
// OPERATOR VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_OPERATOR);
if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true);
// // Check if the settings exist, instantiate defaults if necessary
// ENABLE UAS LIST
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST,VIEW_OPERATOR), true);
// ENABLE HUD TOOL WIDGET
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_HUD,VIEW_OPERATOR), true);
// ENABLE WAYPOINTS
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_WAYPOINTS,VIEW_OPERATOR), true);
}
// // UNCONNECTED VIEW DEFAULT
//// QString centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_UNCONNECTED);
// if (!settings.contains(centralKey)) {
// settings.setValue(centralKey,true);
// ENGINEER VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_LINECHART, VIEW_ENGINEER);
if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true);
// Enable Parameter widget
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_PARAMETERS,VIEW_ENGINEER), true);
}
// // ENABLE UAS LIST
//// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST, VIEW_UNCONNECTED), true);
// // ENABLE COMMUNICATION CONSOLE
//// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_DEBUG_CONSOLE, VIEW_UNCONNECTED), true);
// }
// MAVLINK VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_PROTOCOL, VIEW_MAVLINK);
if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true);
}
// // OPERATOR VIEW DEFAULT
//// centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_OPERATOR);
// if (!settings.contains(centralKey)) {
//// settings.setValue(centralKey,true);
// // ENABLE UAS LIST
//// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST,VIEW_OPERATOR), true);
// // ENABLE HUD TOOL WIDGET
//// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_HUD,VIEW_OPERATOR), true);
// // ENABLE WAYPOINTS
//// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_WAYPOINTS,VIEW_OPERATOR), true);
// }
// PILOT VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_HUD, VIEW_PILOT);
if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true);
// Enable Flight display
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_HDD_1,VIEW_PILOT), true);
}
// // ENGINEER VIEW DEFAULT
// centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_LINECHART, VIEW_ENGINEER);
// if (!settings.contains(centralKey)) {
// settings.setValue(centralKey,true);
// // Enable Parameter widget
// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_PARAMETERS,VIEW_ENGINEER), true);
// }
// // MAVLINK VIEW DEFAULT
// centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_PROTOCOL, VIEW_MAVLINK);
// if (!settings.contains(centralKey)) {
// settings.setValue(centralKey,true);
// }
// // PILOT VIEW DEFAULT
// centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_HUD, VIEW_PILOT);
// if (!settings.contains(centralKey)) {
// settings.setValue(centralKey,true);
// // Enable Flight display
// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_HDD_1,VIEW_PILOT), true);
// }
}
void MainWindow::resizeEvent(QResizeEvent * event)
{
Q_UNUSED(event);
if (height() < 800) {
if (height() < 800)
{
ui.statusBar->setVisible(false);
} else {
}
else
{
ui.statusBar->setVisible(true);
ui.statusBar->setSizeGripEnabled(true);
}
......@@ -293,22 +323,26 @@ QString MainWindow::getWindowGeometryKey()
void MainWindow::buildCustomWidget()
{
// Show custom widgets only if UAS is connected
if (UASManager::instance()->getActiveUAS() != NULL) {
if (UASManager::instance()->getActiveUAS() != NULL)
{
// Enable custom widgets
ui.actionNewCustomWidget->setEnabled(true);
// Create custom widgets
QList<QGCToolWidget*> widgets = QGCToolWidget::createWidgetsFromSettings(this);
if (widgets.size() > 0) {
if (widgets.size() > 0)
{
ui.menuTools->addSeparator();
}
for(int i = 0; i < widgets.size(); ++i) {
for(int i = 0; i < widgets.size(); ++i)
{
// Check if this widget already has a parent, do not create it in this case
QGCToolWidget* tool = widgets.at(i);
QDockWidget* dock = dynamic_cast<QDockWidget*>(tool->parentWidget());
if (!dock) {
if (!dock)
{
QDockWidget* dock = new QDockWidget(tool->windowTitle(), this);
dock->setObjectName(tool->objectName()+"_DOCK");
dock->setWidget(tool);
......@@ -320,8 +354,8 @@ void MainWindow::buildCustomWidget()
widgets.at(i)->setMainMenuAction(showAction);
ui.menuTools->addAction(showAction);
// Load visibility for view (default is off)
dock->setVisible(tool->isVisible(currentView));
// // Load visibility for view (default is off)
// dock->setVisible(tool->isVisible(currentView));
// Load dock widget location (default is bottom)
Qt::DockWidgetArea location = static_cast <Qt::DockWidgetArea>(tool->getDockWidgetArea(currentView));
......@@ -339,71 +373,73 @@ void MainWindow::buildCommonWidgets()
connect(mavlink, SIGNAL(protocolStatusMessage(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection);
// Dock widgets
if (!controlDockWidget) {
if (!controlDockWidget)
{
controlDockWidget = new QDockWidget(tr("Control"), this);
controlDockWidget->setObjectName("UNMANNED_SYSTEM_CONTROL_DOCKWIDGET");
controlDockWidget->setWidget( new UASControlWidget(this) );
addToToolsMenu (controlDockWidget, tr("Control"), SLOT(showToolWidget(bool)), MENU_UAS_CONTROL, Qt::LeftDockWidgetArea);
addTool(controlDockWidget, tr("Control"), Qt::LeftDockWidgetArea);
}
if (!listDockWidget) {
if (!listDockWidget)
{
listDockWidget = new QDockWidget(tr("Unmanned Systems"), this);
listDockWidget->setWidget( new UASListWidget(this) );
listDockWidget->setObjectName("UNMANNED_SYSTEMS_LIST_DOCKWIDGET");
addToToolsMenu (listDockWidget, tr("Unmanned Systems"), SLOT(showToolWidget(bool)), MENU_UAS_LIST, Qt::RightDockWidgetArea);
addTool(listDockWidget, tr("Unmanned Systems"), Qt::RightDockWidgetArea);
}
if (!waypointsDockWidget) {
if (!waypointsDockWidget)
{
waypointsDockWidget = new QDockWidget(tr("Mission Plan"), this);
waypointsDockWidget->setWidget( new QGCWaypointListMulti(this) );
waypointsDockWidget->setObjectName("WAYPOINT_LIST_DOCKWIDGET");
addToToolsMenu (waypointsDockWidget, tr("Mission Plan"), SLOT(showToolWidget(bool)), MENU_WAYPOINTS, Qt::BottomDockWidgetArea);
addTool(waypointsDockWidget, tr("Mission Plan"), Qt::BottomDockWidgetArea);
}
if (!infoDockWidget) {
if (!infoDockWidget)
{
infoDockWidget = new QDockWidget(tr("Status Details"), this);
infoDockWidget->setWidget( new UASInfoWidget(this) );
infoDockWidget->setObjectName("UAS_STATUS_DETAILS_DOCKWIDGET");
addToToolsMenu (infoDockWidget, tr("Status Details"), SLOT(showToolWidget(bool)), MENU_STATUS, Qt::RightDockWidgetArea);
addTool(infoDockWidget, tr("Status Details"), Qt::RightDockWidgetArea);
}
if (!debugConsoleDockWidget) {
if (!debugConsoleDockWidget)
{
debugConsoleDockWidget = new QDockWidget(tr("Communication Console"), this);
debugConsoleDockWidget->setWidget( new DebugConsole(this) );
debugConsoleDockWidget->setObjectName("COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET");
addToToolsMenu (debugConsoleDockWidget, tr("Communication Console"), SLOT(showToolWidget(bool)), MENU_DEBUG_CONSOLE, Qt::BottomDockWidgetArea);
addTool(debugConsoleDockWidget, tr("Communication Console"), Qt::BottomDockWidgetArea);
}
if (!logPlayerDockWidget) {
if (!logPlayerDockWidget)
{
logPlayerDockWidget = new QDockWidget(tr("MAVLink Log Player"), this);
logPlayerDockWidget->setWidget( new QGCMAVLinkLogPlayer(mavlink, this) );
logPlayerDockWidget->setObjectName("MAVLINK_LOG_PLAYER_DOCKWIDGET");
addToToolsMenu(logPlayerDockWidget, tr("MAVLink Log Replay"), SLOT(showToolWidget(bool)), MENU_MAVLINK_LOG_PLAYER, Qt::RightDockWidgetArea);
addTool(logPlayerDockWidget, tr("MAVLink Log Replay"), Qt::RightDockWidgetArea);
}
// Center widgets
if (!mapWidget)
{
mapWidget = new QGCMapTool(this);
addToCentralWidgetsMenu (mapWidget, "Maps", SLOT(showCentralWidget()),CENTRAL_MAP);
addCentralWidget(mapWidget, "Maps");
}
if (!protocolWidget) {
if (!protocolWidget)
{
protocolWidget = new XMLCommProtocolWidget(this);
addToCentralWidgetsMenu (protocolWidget, "Mavlink Generator", SLOT(showCentralWidget()),CENTRAL_PROTOCOL);
addCentralWidget(protocolWidget, "Mavlink Generator");
}
if (!dataplotWidget) {
if (!dataplotWidget)
{
dataplotWidget = new QGCDataPlot2D(this);
addToCentralWidgetsMenu (dataplotWidget, "Logfile Plot", SLOT(showCentralWidget()),CENTRAL_DATA_PLOT);
addCentralWidget(dataplotWidget, "Logfile Plot");
}
}
void MainWindow::buildPxWidgets()
{
//FIXME: memory of acceptList will never be freed again
QStringList* acceptList = new QStringList();
acceptList->append("-105,roll deg,deg,+105,s");
......@@ -433,41 +469,27 @@ void MainWindow::buildPxWidgets()
//acceptList2->append("-2048,accel. y,raw,2048,s");
//acceptList2->append("-2048,accel. z,raw,2048,s");
if (!linechartWidget) {
// Center widgets
linechartWidget = new Linecharts(this);
addToCentralWidgetsMenu(linechartWidget, tr("Realtime Plot"), SLOT(showCentralWidget()), CENTRAL_LINECHART);
}
if (!hudWidget) {
hudWidget = new HUD(320, 240, this);
addToCentralWidgetsMenu(hudWidget, tr("Head Up Display"), SLOT(showCentralWidget()), CENTRAL_HUD);
addCentralWidget(hudWidget, tr("Head Up Display"));
}
if (!dataplotWidget) {
dataplotWidget = new QGCDataPlot2D(this);
addToCentralWidgetsMenu(dataplotWidget, "Logfile Plot", SLOT(showCentralWidget()), CENTRAL_DATA_PLOT);
addCentralWidget(dataplotWidget, tr("Logfile Plot"));
}
#ifdef QGC_OSG_ENABLED
if (!_3DWidget) {
_3DWidget = Q3DWidgetFactory::get("PIXHAWK");
addToCentralWidgetsMenu(_3DWidget, tr("Local 3D"), SLOT(showCentralWidget()), CENTRAL_3D_LOCAL);
}
#endif
#ifdef QGC_OSGEARTH_ENABLED
if (!_3DMapWidget) {
_3DMapWidget = Q3DWidgetFactory::get("MAP3D");
addToCentralWidgetsMenu(_3DMapWidget, tr("OSG Earth 3D"), SLOT(showCentralWidget()), CENTRAL_OSGEARTH);
addCentralWidget(_3DWidget, tr("Local 3D"));
}
#endif
#if (defined _MSC_VER) | (defined Q_OS_MAC)
if (!gEarthWidget) {
gEarthWidget = new QGCGoogleEarthView(this);
addToCentralWidgetsMenu(gEarthWidget, tr("Google Earth"), SLOT(showCentralWidget()), CENTRAL_GOOGLE_EARTH);
addCentralWidget(gEarthWidget, tr("Google Earth"));
}
#endif
......@@ -478,56 +500,56 @@ void MainWindow::buildPxWidgets()
detectionDockWidget = new QDockWidget(tr("Object Recognition"), this);
detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) );
detectionDockWidget->setObjectName("OBJECT_DETECTION_DOCK_WIDGET");
addToToolsMenu (detectionDockWidget, tr("Object Recognition"), SLOT(showToolWidget(bool)), MENU_DETECTION, Qt::RightDockWidgetArea);
addTool(detectionDockWidget, tr("Object Recognition"), Qt::RightDockWidgetArea);
}
if (!parametersDockWidget) {
parametersDockWidget = new QDockWidget(tr("Calibration and Onboard Parameters"), this);
parametersDockWidget->setWidget( new ParameterInterface(this) );
parametersDockWidget->setObjectName("PARAMETER_INTERFACE_DOCKWIDGET");
addToToolsMenu (parametersDockWidget, tr("Calibration and Parameters"), SLOT(showToolWidget(bool)), MENU_PARAMETERS, Qt::RightDockWidgetArea);
addTool(parametersDockWidget, tr("Calibration and Parameters"), Qt::RightDockWidgetArea);
}
if (!watchdogControlDockWidget) {
watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this);
watchdogControlDockWidget->setWidget( new WatchdogControl(this) );
watchdogControlDockWidget->setObjectName("WATCHDOG_CONTROL_DOCKWIDGET");
addToToolsMenu (watchdogControlDockWidget, tr("Process Control"), SLOT(showToolWidget(bool)), MENU_WATCHDOG, Qt::BottomDockWidgetArea);
addTool(watchdogControlDockWidget, tr("Process Control"), Qt::BottomDockWidgetArea);
}
if (!hsiDockWidget) {
hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this);
hsiDockWidget->setWidget( new HSIDisplay(this) );
hsiDockWidget->setObjectName("HORIZONTAL_SITUATION_INDICATOR_DOCK_WIDGET");
addToToolsMenu (hsiDockWidget, tr("Horizontal Situation"), SLOT(showToolWidget(bool)), MENU_HSI, Qt::BottomDockWidgetArea);
addTool(hsiDockWidget, tr("Horizontal Situation"), Qt::BottomDockWidgetArea);
}
if (!headDown1DockWidget) {
headDown1DockWidget = new QDockWidget(tr("Flight Display"), this);
headDown1DockWidget->setWidget( new HDDisplay(acceptList, "Flight Display", this) );
headDown1DockWidget->setObjectName("HEAD_DOWN_DISPLAY_1_DOCK_WIDGET");
addToToolsMenu (headDown1DockWidget, tr("Flight Display"), SLOT(showToolWidget(bool)), MENU_HDD_1, Qt::RightDockWidgetArea);
addTool(headDown1DockWidget, tr("Flight Display"), Qt::RightDockWidgetArea);
}
if (!headDown2DockWidget) {
headDown2DockWidget = new QDockWidget(tr("Actuator Status"), this);
headDown2DockWidget->setWidget( new HDDisplay(acceptList2, "Actuator Status", this) );
headDown2DockWidget->setObjectName("HEAD_DOWN_DISPLAY_2_DOCK_WIDGET");
addToToolsMenu (headDown2DockWidget, tr("Actuator Status"), SLOT(showToolWidget(bool)), MENU_HDD_2, Qt::RightDockWidgetArea);
addTool(headDown2DockWidget, tr("Actuator Status"), Qt::RightDockWidgetArea);
}
if (!rcViewDockWidget) {
rcViewDockWidget = new QDockWidget(tr("Radio Control"), this);
rcViewDockWidget->setWidget( new QGCRemoteControlView(this) );
rcViewDockWidget->setObjectName("RADIO_CONTROL_CHANNELS_DOCK_WIDGET");
addToToolsMenu (rcViewDockWidget, tr("Radio Control"), SLOT(showToolWidget(bool)), MENU_RC_VIEW, Qt::BottomDockWidgetArea);
addTool(rcViewDockWidget, tr("Radio Control"), Qt::BottomDockWidgetArea);
}
if (!headUpDockWidget) {
headUpDockWidget = new QDockWidget(tr("HUD"), this);
headUpDockWidget->setWidget( new HUD(320, 240, this));
headUpDockWidget->setObjectName("HEAD_UP_DISPLAY_DOCK_WIDGET");
addToToolsMenu (headUpDockWidget, tr("Head Up Display"), SLOT(showToolWidget(bool)), MENU_HUD, Qt::RightDockWidgetArea);
addTool(headUpDockWidget, tr("Head Up Display"), Qt::RightDockWidgetArea);
}
if (!video1DockWidget) {
......@@ -538,7 +560,7 @@ void MainWindow::buildPxWidgets()
// FIXME select video stream as well
video1DockWidget->setWidget(video1);
video1DockWidget->setObjectName("VIDEO_STREAM_1_DOCK_WIDGET");
addToToolsMenu (video1DockWidget, tr("Video Stream 1"), SLOT(showToolWidget(bool)), MENU_VIDEO_STREAM_1, Qt::LeftDockWidgetArea);
addTool(video1DockWidget, tr("Video Stream 1"), Qt::LeftDockWidgetArea);
}
if (!video2DockWidget) {
......@@ -549,342 +571,58 @@ void MainWindow::buildPxWidgets()
// FIXME select video stream as well
video2DockWidget->setWidget(video2);
video2DockWidget->setObjectName("VIDEO_STREAM_2_DOCK_WIDGET");
addToToolsMenu (video2DockWidget, tr("Video Stream 2"), SLOT(showToolWidget(bool)), MENU_VIDEO_STREAM_2, Qt::LeftDockWidgetArea);
addTool(video2DockWidget, tr("Video Stream 2"), Qt::LeftDockWidgetArea);
}
// Dialogue widgets
//FIXME: free memory in destructor
}
void MainWindow::buildSlugsWidgets()
{
if (!linechartWidget) {
// Center widgets
linechartWidget = new Linecharts(this);
addToCentralWidgetsMenu(linechartWidget, tr("Realtime Plot"), SLOT(showCentralWidget()), CENTRAL_LINECHART);
}
if (!headUpDockWidget) {
// Dock widgets
headUpDockWidget = new QDockWidget(tr("Control Indicator"), this);
headUpDockWidget->setWidget( new HUD(320, 240, this));
headUpDockWidget->setObjectName("HEAD_UP_DISPLAY_DOCK_WIDGET");
addToToolsMenu (headUpDockWidget, tr("Head Up Display"), SLOT(showToolWidget(bool)), MENU_HUD, Qt::LeftDockWidgetArea);
}
if (!rcViewDockWidget) {
rcViewDockWidget = new QDockWidget(tr("Radio Control"), this);
rcViewDockWidget->setWidget( new QGCRemoteControlView(this) );
rcViewDockWidget->setObjectName("RADIO_CONTROL_CHANNELS_DOCK_WIDGET");
addToToolsMenu (rcViewDockWidget, tr("Radio Control"), SLOT(showToolWidget(bool)), MENU_RC_VIEW, Qt::BottomDockWidgetArea);
}
#if (defined _MSC_VER) | (defined Q_OS_MAC)
if (!gEarthWidget) {
gEarthWidget = new QGCGoogleEarthView(this);
addToCentralWidgetsMenu(gEarthWidget, tr("Google Earth"), SLOT(showCentralWidget()), CENTRAL_GOOGLE_EARTH);
}
#endif
if (!slugsDataWidget) {
// Dialog widgets
slugsDataWidget = new QDockWidget(tr("Slugs Data"), this);
slugsDataWidget->setWidget( new SlugsDataSensorView(this));
slugsDataWidget->setObjectName("SLUGS_DATA_DOCK_WIDGET");
addToToolsMenu (slugsDataWidget, tr("Telemetry Data"), SLOT(showToolWidget(bool)), MENU_SLUGS_DATA, Qt::RightDockWidgetArea);
}
if (!slugsHilSimWidget) {
slugsHilSimWidget = new QDockWidget(tr("Slugs Hil Sim"), this);
slugsHilSimWidget->setWidget( new SlugsHilSim(this));
slugsHilSimWidget->setObjectName("SLUGS_HIL_SIM_DOCK_WIDGET");
addToToolsMenu (slugsHilSimWidget, tr("HIL Sim Configuration"), SLOT(showToolWidget(bool)), MENU_SLUGS_HIL, Qt::LeftDockWidgetArea);
}
if (!controlParameterWidget) {
controlParameterWidget = new QDockWidget(tr("Control Parameters"), this);
controlParameterWidget->setObjectName("UNMANNED_SYSTEM_CONTROL_PARAMETERWIDGET");
controlParameterWidget->setWidget( new UASControlParameters(this) );
addToToolsMenu (controlParameterWidget, tr("Control Parameters"), SLOT(showToolWidget(bool)), MENU_UAS_CONTROL_PARAM, Qt::LeftDockWidgetArea);
}
if (!parametersDockWidget) {
parametersDockWidget = new QDockWidget(tr("Calibration and Onboard Parameters"), this);
parametersDockWidget->setWidget( new ParameterInterface(this) );
parametersDockWidget->setObjectName("PARAMETER_INTERFACE_DOCKWIDGET");
addToToolsMenu (parametersDockWidget, tr("Calibration and Parameters"), SLOT(showToolWidget(bool)), MENU_PARAMETERS, Qt::RightDockWidgetArea);
}
if (!slugsCamControlWidget) {
slugsCamControlWidget = new QDockWidget(tr("Camera Control"), this);
slugsCamControlWidget->setWidget(new SlugsPadCameraControl(this));
slugsCamControlWidget->setObjectName("SLUGS_CAM_CONTROL_DOCK_WIDGET");
addToToolsMenu (slugsCamControlWidget, tr("Camera Control"), SLOT(showToolWidget(bool)), MENU_SLUGS_CAMERA, Qt::BottomDockWidgetArea);
}
}
void MainWindow::addToCentralWidgetsMenu ( QWidget* widget,
const QString title,
const char * slotName,
TOOLS_WIDGET_NAMES centralWidget)
void MainWindow::addTool(QDockWidget* widget, const QString& title, Qt::DockWidgetArea area)
{
QAction* tempAction;
// Not needed any more - separate menu now available
// // Add the separator that will separate tools from central Widgets
// if (!toolsMenuActions[CENTRAL_SEPARATOR])
// {
// tempAction = ui.menuTools->addSeparator();
// toolsMenuActions[CENTRAL_SEPARATOR] = tempAction;
// tempAction->setData(CENTRAL_SEPARATOR);
// }
tempAction = ui.menuMain->addAction(title);
QAction* tempAction = ui.menuTools->addAction(title);
tempAction->setCheckable(true);
tempAction->setData(centralWidget);
// populate the Hashes
toolsMenuActions[centralWidget] = tempAction;
dockWidgets[centralWidget] = widget;
QString chKey = buildMenuKey(SUB_SECTION_CHECKED, centralWidget, currentView);
if (!settings.contains(chKey)) {
settings.setValue(chKey,false);
tempAction->setChecked(false);
} else {
tempAction->setChecked(settings.value(chKey).toBool());
}
// connect the action
connect(tempAction,SIGNAL(triggered(bool)),this, slotName);
QVariant var;
var.setValue((QWidget*)widget);
tempAction->setData(var);
connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool)));
addDockWidget(area, widget);
}
void MainWindow::showCentralWidget()
void MainWindow::showTool(bool show)
{
QAction* senderAction = qobject_cast<QAction *>(sender());
// Block sender action while manipulating state
senderAction->blockSignals(true);
int tool = senderAction->data().toInt();
QString chKey;
// check the current action
if (senderAction && dockWidgets[tool]) {
// uncheck all central widget actions
QHashIterator<int, QAction*> i(toolsMenuActions);
while (i.hasNext()) {
i.next();
//qDebug() << "shCW" << i.key() << "read";
if (i.value() && i.value()->data().toInt() > 255) {
// Block signals and uncheck action
// firing would be unneccesary
i.value()->blockSignals(true);
i.value()->setChecked(false);
i.value()->blockSignals(false);
// update the settings
chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.value()->data().toInt()), currentView);
settings.setValue(chKey,false);
}
}
// check the current action
//qDebug() << senderAction->text();
senderAction->setChecked(true);
// update the central widget
centerStack->setCurrentWidget(dockWidgets[tool]);
// store the selected central widget
chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(tool), currentView);
settings.setValue(chKey,true);
// Unblock sender action
senderAction->blockSignals(false);
presentView();
}
QAction* act = qobject_cast<QAction *>(sender());
QWidget* widget = qVariantValue<QWidget *>(act->data());
widget->setVisible(show);
}
/**
* Adds a widget to the tools menu and sets it visible if it was
* enabled last time.
*/
void MainWindow::addToToolsMenu ( QWidget* widget,
const QString title,
const char * slotName,
TOOLS_WIDGET_NAMES tool,
Qt::DockWidgetArea location)
void MainWindow::addCentralWidget(QWidget* widget, const QString& title)
{
QAction* tempAction;
QString posKey, chKey;
if (toolsMenuActions[CENTRAL_SEPARATOR]) {
tempAction = new QAction(title, this);
ui.menuTools->insertAction(toolsMenuActions[CENTRAL_SEPARATOR],
tempAction);
} else {
tempAction = ui.menuTools->addAction(title);
}
tempAction->setCheckable(true);
tempAction->setData(tool);
// populate the Hashes
toolsMenuActions[tool] = tempAction;
dockWidgets[tool] = widget;
//qDebug() << widget;
posKey = buildMenuKey (SUB_SECTION_LOCATION,tool, currentView);
if (!settings.contains(posKey)) {
settings.setValue(posKey,location);
dockWidgetLocations[tool] = location;
} else {
dockWidgetLocations[tool] = static_cast <Qt::DockWidgetArea> (settings.value(posKey, Qt::RightDockWidgetArea).toInt());
}
chKey = buildMenuKey(SUB_SECTION_CHECKED,tool, currentView);
if (!settings.contains(chKey)) {
settings.setValue(chKey,false);
tempAction->setChecked(false);
widget->setVisible(false);
} else {
tempAction->setChecked(settings.value(chKey, false).toBool());
widget->setVisible(settings.value(chKey, false).toBool());
}
// connect the action
connect(tempAction,SIGNAL(toggled(bool)),this, slotName);
connect(qobject_cast <QDockWidget *>(dockWidgets[tool]),
SIGNAL(visibilityChanged(bool)), this, SLOT(showToolWidget(bool)));
// connect(qobject_cast <QDockWidget *>(dockWidgets[tool]),
// SIGNAL(visibilityChanged(bool)), this, SLOT(updateVisibilitySettings(bool)));
connect(qobject_cast <QDockWidget *>(dockWidgets[tool]),
SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(updateLocationSettings(Qt::DockWidgetArea)));
}
void MainWindow::showToolWidget(bool visible)
{
if (!aboutToCloseFlag && !changingViewsFlag) {
QAction* action = qobject_cast<QAction *>(sender());
// Prevent this to fire if undocked
if (action) {
int tool = action->data().toInt();
QDockWidget* dockWidget = qobject_cast<QDockWidget *> (dockWidgets[tool]);
if (dockWidget && dockWidget->isVisible() != visible) {
if (visible) {
addDockWidget(dockWidgetLocations[tool], dockWidget);
dockWidget->show();
} else {
removeDockWidget(dockWidget);
}
QHashIterator<int, QWidget*> i(dockWidgets);
while (i.hasNext()) {
i.next();
if ((static_cast <QDockWidget *>(dockWidgets[i.key()])) == dockWidget) {
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(chKey,visible);
//qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible;
break;
}
}
}
}
QDockWidget* dockWidget = qobject_cast<QDockWidget*>(QObject::sender());
//qDebug() << "Trying to cast dockwidget" << dockWidget << "isvisible" << visible;
if (dockWidget) {
// Get action
int tool = dockWidgets.key(dockWidget);
//qDebug() << "Updating widget setting" << tool << "to" << visible;
// Check if this widget already has been added
if (centerStack->indexOf(widget) == -1)
{
centerStack->addWidget(widget);
QAction* action = toolsMenuActions[tool];
action->blockSignals(true);
action->setChecked(visible);
action->blockSignals(false);
QAction* tempAction = ui.menuMain->addAction(title);
QHashIterator<int, QWidget*> i(dockWidgets);
while (i.hasNext()) {
i.next();
if ((static_cast <QDockWidget *>(dockWidgets[i.key()])) == dockWidget) {
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(chKey,visible);
// qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible;
break;
}
}
}
tempAction->setCheckable(true);
QVariant var;
var.setValue((QWidget*)widget);
tempAction->setData(var);
centerStackActionGroup.addAction(tempAction);
connect(tempAction,SIGNAL(triggered()),this, SLOT(showCentralWidget()));
}
}
void MainWindow::showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view)
{
bool tempVisible;
Qt::DockWidgetArea tempLocation;
QDockWidget* tempWidget = static_cast <QDockWidget *>(dockWidgets[widget]);
tempVisible = settings.value(buildMenuKey(SUB_SECTION_CHECKED,widget,view), false).toBool();
//qDebug() << "showTheWidget(): Set key" << buildMenuKey(SUB_SECTION_CHECKED,widget,view) << "to" << tempVisible;
if (tempWidget) {
toolsMenuActions[widget]->setChecked(tempVisible);
}
//qDebug() << buildMenuKey (SUB_SECTION_CHECKED,widget,view) << tempVisible;
tempLocation = static_cast <Qt::DockWidgetArea>(settings.value(buildMenuKey (SUB_SECTION_LOCATION,widget, view), QVariant(Qt::RightDockWidgetArea)).toInt());
if (tempWidget != NULL) {
if (tempVisible) {
addDockWidget(tempLocation, tempWidget);
tempWidget->show();
}
}
}
QString MainWindow::buildMenuKey(SETTINGS_SECTIONS section, TOOLS_WIDGET_NAMES tool, VIEW_SECTIONS view)
void MainWindow::showCentralWidget()
{
// Key is built as follows: autopilot_type/section_menu/view/tool/section
int apType;
// apType = (UASManager::instance() && UASManager::instance()->silentGetActiveUAS())?
// UASManager::instance()->getActiveUAS()->getAutopilotType():
// -1;
apType = 1;
return (QString::number(apType) + "_" +
QString::number(SECTION_MENU) + "_" +
QString::number(view) + "_" +
QString::number(tool) + "_" +
QString::number(section) + "_" );
QAction* act = qobject_cast<QAction *>(sender());
QWidget* widget = qVariantValue<QWidget *>(act->data());
centerStack->setCurrentWidget(widget);
}
void MainWindow::closeEvent(QCloseEvent *event)
......@@ -896,62 +634,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}
void MainWindow::showDockWidget (bool vis)
{
if (!aboutToCloseFlag && !changingViewsFlag) {
QDockWidget* temp = qobject_cast<QDockWidget *>(sender());
if (temp) {
QHashIterator<int, QWidget*> i(dockWidgets);
while (i.hasNext()) {
i.next();
if ((static_cast <QDockWidget *>(dockWidgets[i.key()])) == temp) {
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(chKey,vis);
toolsMenuActions[i.key()]->setChecked(vis);
break;
}
}
}
}
}
void MainWindow::updateVisibilitySettings (bool vis)
{
if (!aboutToCloseFlag && !changingViewsFlag) {
QDockWidget* temp = qobject_cast<QDockWidget *>(sender());
if (temp) {
QHashIterator<int, QWidget*> i(dockWidgets);
while (i.hasNext()) {
i.next();
if ((static_cast <QDockWidget *>(dockWidgets[i.key()])) == temp) {
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(chKey,vis);
toolsMenuActions[i.key()]->setChecked(vis);
break;
}
}
}
}
}
void MainWindow::updateLocationSettings (Qt::DockWidgetArea location)
{
QDockWidget* temp = qobject_cast<QDockWidget *>(sender());
QHashIterator<int, QWidget*> i(dockWidgets);
while (i.hasNext()) {
i.next();
if ((static_cast <QDockWidget *>(dockWidgets[i.key()])) == temp) {
QString posKey = buildMenuKey (SUB_SECTION_LOCATION,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(posKey,location);
break;
}
}
}
/**
* Connect the signals and slots of the common window widgets
*/
......@@ -998,7 +680,8 @@ void MainWindow::loadCustomWidget()
QGCToolWidget* tool = new QGCToolWidget("", this);
tool->loadSettings(fileName);
if (QGCToolWidget::instances()->size() < 2) {
if (QGCToolWidget::instances()->size() < 2)
{
// This is the first widget
ui.menuTools->addSeparator();
}
......@@ -1019,85 +702,8 @@ void MainWindow::loadCustomWidget()
dock->setVisible(true);
}
void MainWindow::connectPxWidgets()
{
// No special connections necessary at this point
}
void MainWindow::connectSlugsWidgets()
{
if (slugsHilSimWidget && slugsHilSimWidget->widget()) {
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
slugsHilSimWidget->widget(), SLOT(activeUasSet(UASInterface*)));
}
if (slugsDataWidget && slugsDataWidget->widget()) {
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
slugsDataWidget->widget(), SLOT(setActiveUAS(UASInterface*)));
}
if (controlParameterWidget && controlParameterWidget->widget()) {
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
controlParameterWidget->widget(), SLOT(activeUasSet(UASInterface*)));
}
if(controlDockWidget && controlParameterWidget) {
connect(controlDockWidget->widget(), SIGNAL(changedMode(int)), controlParameterWidget->widget(), SLOT(changedMode(int)));
}
}
void MainWindow::arrangeCommonCenterStack()
{
centerStack = new QStackedWidget(this);
centerStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if (!centerStack) return;
if (mapWidget && (centerStack->indexOf(mapWidget) == -1)) centerStack->addWidget(mapWidget);
if (dataplotWidget && (centerStack->indexOf(dataplotWidget) == -1)) centerStack->addWidget(dataplotWidget);
if (protocolWidget && (centerStack->indexOf(protocolWidget) == -1)) centerStack->addWidget(protocolWidget);
setCentralWidget(centerStack);
}
void MainWindow::arrangePxCenterStack()
{
if (!centerStack) {
qDebug() << "Center Stack not Created!";
return;
}
if (linechartWidget && (centerStack->indexOf(linechartWidget) == -1)) centerStack->addWidget(linechartWidget);
#ifdef QGC_OSG_ENABLED
if (_3DWidget && (centerStack->indexOf(_3DWidget) == -1)) centerStack->addWidget(_3DWidget);
#endif
#ifdef QGC_OSGEARTH_ENABLED
if (_3DMapWidget && (centerStack->indexOf(_3DMapWidget) == -1)) centerStack->addWidget(_3DMapWidget);
#endif
#if (defined _MSC_VER) | (defined Q_OS_MAC)
if (gEarthWidget && (centerStack->indexOf(gEarthWidget) == -1)) centerStack->addWidget(gEarthWidget);
#endif
if (hudWidget && (centerStack->indexOf(hudWidget) == -1)) centerStack->addWidget(hudWidget);
if (dataplotWidget && (centerStack->indexOf(dataplotWidget) == -1)) centerStack->addWidget(dataplotWidget);
}
void MainWindow::arrangeSlugsCenterStack()
{
if (!centerStack) {
qDebug() << "Center Stack not Created!";
return;
}
if (linechartWidget && (centerStack->indexOf(linechartWidget) == -1)) centerStack->addWidget(linechartWidget);
if (hudWidget && (centerStack->indexOf(hudWidget) == -1)) centerStack->addWidget(hudWidget);
#if (defined _MSC_VER) | (defined Q_OS_MAC)
if (gEarthWidget && (centerStack->indexOf(gEarthWidget) == -1)) centerStack->addWidget(gEarthWidget);
#endif
}
......@@ -1414,20 +1020,9 @@ void MainWindow::connectCommonActions()
connect(ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
}
void MainWindow::connectPxActions()
{
}
void MainWindow::connectSlugsActions()
{
}
void MainWindow::showHelp()
{
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/users/"))) {
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/users/start"))) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open help in browser");
......@@ -1440,7 +1035,7 @@ void MainWindow::showHelp()
void MainWindow::showCredits()
{
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/credits/"))) {
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/credits"))) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open credits in browser");
......@@ -1453,7 +1048,7 @@ void MainWindow::showCredits()
void MainWindow::showRoadMap()
{
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/roadmap/"))) {
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/dev/roadmap"))) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open roadmap in browser");
......@@ -1633,71 +1228,23 @@ void MainWindow::UASCreated(UASInterface* uas)
}
}
switch (uas->getAutopilotType()) {
case (MAV_AUTOPILOT_SLUGS): {
// Build Slugs Widgets
buildSlugsWidgets();
// Connect Slugs Widgets
connectSlugsWidgets();
// Arrange Slugs Centerstack
arrangeSlugsCenterStack();
// Connect Slugs Actions
connectSlugsActions();
// if(slugsDataWidget)
// {
// SlugsDataSensorView *mm = dynamic_cast<SlugsDataSensorView*>(slugsDataWidget->widget());
// if(mm)
// {
// mm->addUAS(uas);
// }
// }
// FIXME: This type checking might be redundant
// // if (slugsDataWidget) {
// // SlugsDataSensorView* dataWidget = dynamic_cast<SlugsDataSensorView*>(slugsDataWidget->widget());
// // if (dataWidget) {
// // SlugsMAV* mav2 = dynamic_cast<SlugsMAV*>(uas);
// // if (mav2) {
// (dynamic_cast<SlugsDataSensorView*>(slugsDataWidget->widget()))->addUAS(uas);
// // //loadSlugsView();
// // loadGlobalOperatorView();
// // }
// // }
// // }
}
break;
default:
case (MAV_AUTOPILOT_GENERIC):
case (MAV_AUTOPILOT_ARDUPILOTMEGA):
case (MAV_AUTOPILOT_PIXHAWK): {
// Build Pixhawk Widgets
buildPxWidgets();
// Connect Pixhawk Widgets
connectPxWidgets();
// Arrange Pixhawk Centerstack
arrangePxCenterStack();
// Connect Pixhawk Actions
connectPxActions();
}
break;
// Line chart
if (!linechartWidget)
{
// Center widgets
linechartWidget = new Linecharts(this);
addCentralWidget(linechartWidget, tr("Realtime Plot"));
}
// Change the view only if this is the first UAS
// If this is the first connected UAS, it is both created as well as
// the currently active UAS
if (UASManager::instance()->getUASList().size() == 1) {
if (UASManager::instance()->getUASList().size() == 1)
{
// Load last view if setting is present
if (settings.contains("CURRENT_VIEW_WITH_UAS_CONNECTED")) {
clearView();
if (settings.contains("CURRENT_VIEW_WITH_UAS_CONNECTED"))
{
int view = settings.value("CURRENT_VIEW_WITH_UAS_CONNECTED").toInt();
switch (view) {
case VIEW_ENGINEER:
......@@ -1717,7 +1264,9 @@ void MainWindow::UASCreated(UASInterface* uas)
loadOperatorView();
break;
}
} else {
}
else
{
loadOperatorView();
}
}
......@@ -1735,275 +1284,97 @@ void MainWindow::UASCreated(UASInterface* uas)
}
/**
* Clears the current view completely
* Stores the current view state
*/
void MainWindow::clearView()
void MainWindow::storeViewState()
{
// Save current state
if (UASManager::instance()->getUASList().count() > 0) settings.setValue(getWindowStateKey(), saveState(QGC::applicationVersion()));
settings.setValue(getWindowStateKey(), saveState(QGC::applicationVersion()));
settings.setValue(getWindowStateKey()+"CENTER_WIDGET", centerStack->currentIndex());
// Although we want save the state of the window, we do not want to change the top-leve state (minimized, maximized, etc)
// therefore this state is stored here and restored after applying the rest of the settings in the new
// perspective.
windowStateVal = this->windowState();
settings.setValue(getWindowGeometryKey(), saveGeometry());
}
QAction* temp;
// Set tool widget visibility settings for this view
foreach (int key, toolsMenuActions.keys()) {
temp = toolsMenuActions[key];
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(key), currentView);
if (temp) {
//qDebug() << "TOOL:" << chKey << "IS:" << temp->isChecked();
settings.setValue(chKey,temp->isChecked());
} else {
//qDebug() << "TOOL:" << chKey << "IS DEFAULT AND UNCHECKED";
settings.setValue(chKey,false);
}
}
changingViewsFlag = true;
// Remove all dock widgets from main window
QObjectList childList( this->children() );
void MainWindow::loadViewState()
{
// Restore center stack state
int index = settings.value(getWindowStateKey()+"CENTER_WIDGET", centerStack->currentIndex()).toInt();
centerStack->setCurrentIndex(index);
QObjectList::iterator i;
QDockWidget* dockWidget;
for (i = childList.begin(); i != childList.end(); ++i) {
dockWidget = dynamic_cast<QDockWidget*>(*i);
if (dockWidget) {
// Remove dock widget from main window
removeDockWidget(dockWidget);
dockWidget->hide();
//dockWidget->setVisible(false);
}
// Restore the widget positions and size
if (settings.contains(getWindowStateKey()))
{
restoreState(settings.value(getWindowStateKey()).toByteArray(), QGC::applicationVersion());
}
changingViewsFlag = false;
}
void MainWindow::loadEngineerView()
{
if (currentView != VIEW_ENGINEER) {
clearView();
storeViewState();
currentView = VIEW_ENGINEER;
ui.actionEngineersView->setChecked(true);
presentView();
loadViewState();
}
}
void MainWindow::loadOperatorView()
{
if (currentView != VIEW_OPERATOR) {
clearView();
storeViewState();
currentView = VIEW_OPERATOR;
ui.actionOperatorsView->setChecked(true);
presentView();
loadViewState();
}
}
void MainWindow::loadUnconnectedView()
{
if (currentView != VIEW_UNCONNECTED) {
clearView();
if (currentView != VIEW_UNCONNECTED)
{
storeViewState();
currentView = VIEW_UNCONNECTED;
ui.actionUnconnectedView->setChecked(true);
presentView();
loadViewState();
}
}
void MainWindow::loadPilotView()
{
if (currentView != VIEW_PILOT) {
clearView();
if (currentView != VIEW_PILOT)
{
storeViewState();
currentView = VIEW_PILOT;
ui.actionPilotsView->setChecked(true);
presentView();
loadViewState();
}
}
void MainWindow::loadMAVLinkView()
{
if (currentView != VIEW_MAVLINK) {
clearView();
if (currentView != VIEW_MAVLINK)
{
storeViewState();
currentView = VIEW_MAVLINK;
ui.actionMavlinkView->setChecked(true);
presentView();
}
}
void MainWindow::presentView()
{
// LINE CHART
showTheCentralWidget(CENTRAL_LINECHART, currentView);
// MAP
showTheCentralWidget(CENTRAL_MAP, currentView);
// PROTOCOL
showTheCentralWidget(CENTRAL_PROTOCOL, currentView);
// HEAD UP DISPLAY
showTheCentralWidget(CENTRAL_HUD, currentView);
// GOOGLE EARTH
showTheCentralWidget(CENTRAL_GOOGLE_EARTH, currentView);
// LOCAL 3D VIEW
showTheCentralWidget(CENTRAL_3D_LOCAL, currentView);
// GLOBAL 3D VIEW
showTheCentralWidget(CENTRAL_3D_MAP, currentView);
// DATA PLOT
showTheCentralWidget(CENTRAL_DATA_PLOT, currentView);
// Show docked widgets based on current view and autopilot type
// UAS CONTROL
showTheWidget(MENU_UAS_CONTROL, currentView);
showTheWidget(MENU_UAS_CONTROL_PARAM, currentView);
// UAS LIST
showTheWidget(MENU_UAS_LIST, currentView);
// WAYPOINT LIST
showTheWidget(MENU_WAYPOINTS, currentView);
// UAS STATUS
showTheWidget(MENU_STATUS, currentView);
// DETECTION
showTheWidget(MENU_DETECTION, currentView);
// DEBUG CONSOLE
showTheWidget(MENU_DEBUG_CONSOLE, currentView);
// ONBOARD PARAMETERS
showTheWidget(MENU_PARAMETERS, currentView);
// WATCHDOG
showTheWidget(MENU_WATCHDOG, currentView);
// HUD
showTheWidget(MENU_HUD, currentView);
if (headUpDockWidget) {
HUD* tmpHud = dynamic_cast<HUD*>( headUpDockWidget->widget() );
if (tmpHud) {
if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HUD,currentView)).toBool()) {
addDockWidget(static_cast <Qt::DockWidgetArea>(settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HUD, currentView)).toInt()),
headUpDockWidget);
headUpDockWidget->show();
} else {
headUpDockWidget->hide();
}
}
}
// RC View
showTheWidget(MENU_RC_VIEW, currentView);
// SLUGS DATA
showTheWidget(MENU_SLUGS_DATA, currentView);
// SLUGS PID
showTheWidget(MENU_SLUGS_PID, currentView);
// SLUGS HIL
showTheWidget(MENU_SLUGS_HIL, currentView);
// SLUGS CAMERA
showTheWidget(MENU_SLUGS_CAMERA, currentView);
// HORIZONTAL SITUATION INDICATOR
showTheWidget(MENU_HSI, currentView);
// HEAD DOWN 1
showTheWidget(MENU_HDD_1, currentView);
// HEAD DOWN 2
showTheWidget(MENU_HDD_2, currentView);
// MAVLINK LOG PLAYER
showTheWidget(MENU_MAVLINK_LOG_PLAYER, currentView);
// VIDEO 1
showTheWidget(MENU_VIDEO_STREAM_1, currentView);
// VIDEO 2
showTheWidget(MENU_VIDEO_STREAM_2, currentView);
// Restore window state
if (UASManager::instance()->getUASList().count() > 0) {
// // Restore the mainwindow size
// if (settings.contains(getWindowGeometryKey()))
// {
// restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray());
// }
// Restore the widget positions and size
if (settings.contains(getWindowStateKey())) {
restoreState(settings.value(getWindowStateKey()).toByteArray(), QGC::applicationVersion());
}
}
// ACTIVATE HUD WIDGET
if (headUpDockWidget) {
HUD* tmpHud = dynamic_cast<HUD*>( headUpDockWidget->widget() );
if (tmpHud) {
}
}
this->setWindowState(windowStateVal);
this->show();
}
void MainWindow::showTheCentralWidget (TOOLS_WIDGET_NAMES centralWidget, VIEW_SECTIONS view)
{
bool tempVisible;
QWidget* tempWidget = dockWidgets[centralWidget];
tempVisible = settings.value(buildMenuKey(SUB_SECTION_CHECKED,centralWidget,view), false).toBool();
//qDebug() << buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view) << tempVisible;
if (toolsMenuActions[centralWidget]) {
//qDebug() << "SETTING TO:" << tempVisible;
toolsMenuActions[centralWidget]->setChecked(tempVisible);
}
if (centerStack && tempWidget && tempVisible) {
//qDebug() << "ACTIVATING MAIN WIDGET";
centerStack->setCurrentWidget(tempWidget);
loadViewState();
}
}
void MainWindow::loadDataView(QString fileName)
{
clearView();
// Unload line chart
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(CENTRAL_LINECHART), currentView);
settings.setValue(chKey,false);
// Set data plot in settings as current widget and then run usual update procedure
chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(CENTRAL_DATA_PLOT), currentView);
settings.setValue(chKey,true);
presentView();
// Plot is now selected, now load data from file
if (dataplotWidget) {
if (dataplotWidget)
{
dataplotWidget->loadFile(fileName);
}
QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
if (centerStack)
{
centerStack->setCurrentWidget(dataplotWidget);
dataplotWidget->loadFile(fileName);
}
// QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
// if (centerStack)
// {
// centerStack->setCurrentWidget(dataplotWidget);
// dataplotWidget->loadFile(fileName);
// }
// }
}
......@@ -49,7 +49,6 @@ This file is part of the QGROUNDCONTROL project
#include "UASListWidget.h"
#include "MAVLinkProtocol.h"
#include "MAVLinkSimulationLink.h"
#include "AS4Protocol.h"
#include "ObjectDetectionView.h"
#include "HUD.h"
#include "JoystickWidget.h"
......@@ -159,9 +158,6 @@ public slots:
/** @brief Show the project roadmap */
void showRoadMap();
/** @brief Shows the widgets based on configuration and current view and autopilot */
void presentView();
/** @brief Reload the CSS style sheet */
void reloadStylesheet();
/** @brief Let the user select the CSS style sheet */
......@@ -193,29 +189,21 @@ public slots:
/**
* @brief Shows a Docked Widget based on the action sender
*
* This slot is written to be used in conjunction with the addToToolsMenu function
* This slot is written to be used in conjunction with the addTool() function
* It shows the QDockedWidget based on the action sender
*
*/
void showToolWidget(bool visible);
void showTool(bool visible);
/**
* @brief Shows a Widget from the center stack based on the action sender
*
* This slot is written to be used in conjunction with the addToCentralWidgetsMenu function
* This slot is written to be used in conjunction with the addCentralWidget() function
* It shows the Widget based on the action sender
*
*/
void showCentralWidget();
/** @brief Change actively a QDockWidgets visibility by an action */
void showDockWidget(bool vis);
/** @brief Updates a QDockWidget's checked status based on its visibility */
void updateVisibilitySettings(bool vis);
/** @brief Updates a QDockWidget's location */
void updateLocationSettings (Qt::DockWidgetArea location);
protected:
MainWindow(QWidget *parent = 0);
......@@ -223,65 +211,19 @@ protected:
/** @brief Set default window settings for the current autopilot type */
void setDefaultSettingsForAp();
// These defines are used to save the settings when selecting with
// which widgets populate the views
// FIXME: DO NOT PUT CUSTOM VALUES IN THIS ENUM since it is iterated over
// this will be fixed in a future release.
typedef enum _TOOLS_WIDGET_NAMES {
MENU_UAS_CONTROL_PARAM,
MENU_UAS_CONTROL,
MENU_UAS_INFO,
MENU_CAMERA,
MENU_UAS_LIST,
MENU_WAYPOINTS,
MENU_STATUS,
MENU_DETECTION,
MENU_DEBUG_CONSOLE,
MENU_PARAMETERS,
MENU_HDD_1,
MENU_HDD_2,
MENU_WATCHDOG,
MENU_HUD,
MENU_HSI,
MENU_RC_VIEW,
MENU_SLUGS_DATA,
MENU_SLUGS_PID,
MENU_SLUGS_HIL,
MENU_SLUGS_CAMERA,
MENU_MAVLINK_LOG_PLAYER,
MENU_VIDEO_STREAM_1,
MENU_VIDEO_STREAM_2,
CENTRAL_SEPARATOR= 255, // do not change
CENTRAL_LINECHART,
CENTRAL_PROTOCOL,
CENTRAL_MAP,
CENTRAL_3D_LOCAL,
CENTRAL_3D_MAP,
CENTRAL_OSGEARTH,
CENTRAL_GOOGLE_EARTH,
CENTRAL_HUD,
CENTRAL_DATA_PLOT,
} TOOLS_WIDGET_NAMES;
typedef enum _SETTINGS_SECTIONS {
SECTION_MENU,
SUB_SECTION_CHECKED,
SUB_SECTION_LOCATION,
} SETTINGS_SECTIONS;
typedef enum _VIEW_SECTIONS {
VIEW_ENGINEER,
VIEW_OPERATOR,
VIEW_PILOT,
VIEW_MAVLINK,
VIEW_UNCONNECTED, ///< View in unconnected mode, when no UAS is available
VIEW_FULL ///< All widgets shown at once
} VIEW_SECTIONS;
QHash<int, QAction*> toolsMenuActions; // Holds ptr to the Menu Actions
QHash<int, QWidget*> dockWidgets; // Holds ptr to the Actual Dock widget
QHash<int, Qt::DockWidgetArea> dockWidgetLocations; // Holds the location
// QHash<int, Qt::DockWidgetArea> dockWidgetLocations; // Holds the location
/**
* @brief Adds an already instantiated QDockedWidget to the Tools Menu
......@@ -290,24 +232,22 @@ protected:
* tools menu and connects the QMenuAction to a slot that shows the widget and
* checks/unchecks the tools menu item
*
* @param widget The QDockedWidget being added
* @param widget The QDockWidget being added
* @param title The entry that will appear in the Menu and in the QDockedWidget title bar
* @param slotName The slot to which the triggered() signal of the menu action will be connected.
* @param tool The ENUM defined in MainWindow.h that is associated to the widget
* @param location The default location for the QDockedWidget in case there is no previous key in the settings
*/
void addToToolsMenu (QWidget* widget, const QString title, const char * slotName, TOOLS_WIDGET_NAMES tool, Qt::DockWidgetArea location=Qt::RightDockWidgetArea);
/**
* @brief Determines if a QDockWidget needs to be show and if so, shows it
*
* Based on the the autopilot and the current view it queries the settings and shows the
* widget if necessary
*
* @param widget The QDockWidget requested to be shown
* @param view The view for which the QDockWidget is requested
*/
void showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view = VIEW_MAVLINK);
void addTool(QDockWidget* widget, const QString& title, Qt::DockWidgetArea location=Qt::RightDockWidgetArea);
// /**
// * @brief Determines if a QDockWidget needs to be show and if so, shows it
// *
// * Based on the the autopilot and the current view it queries the settings and shows the
// * widget if necessary
// *
// * @param widget The QDockWidget requested to be shown
// * @param view The view for which the QDockWidget is requested
// */
// void showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view = VIEW_MAVLINK);
/**
* @brief Adds an already instantiated QWidget to the center stack
......@@ -319,21 +259,8 @@ protected:
*
* @param widget The QWidget being added
* @param title The entry that will appear in the Menu
* @param slotName The slot to which the triggered() signal of the menu action will be connected.
* @param centralWidget The ENUM defined in MainWindow.h that is associated to the widget
*/
void addToCentralWidgetsMenu ( QWidget* widget, const QString title,const char * slotName, TOOLS_WIDGET_NAMES centralWidget);
/**
* @brief Determines if a QWidget needs to be show and if so, shows it
*
* Based on the the autopilot and the current view it queries the settings and shows the
* widget if necessary
*
* @param centralWidget The QWidget requested to be shown
* @param view The view for which the QWidget is requested
*/
void showTheCentralWidget (TOOLS_WIDGET_NAMES centralWidget, VIEW_SECTIONS view);
void addCentralWidget(QWidget* widget, const QString& title);
/** @brief Catch window resize events */
void resizeEvent(QResizeEvent * event);
......@@ -343,24 +270,25 @@ protected:
bool aboutToCloseFlag;
bool changingViewsFlag;
void clearView();
void storeViewState();
void loadViewState();
void buildCustomWidget();
void buildCommonWidgets();
void buildPxWidgets();
void buildSlugsWidgets();
// void buildPxWidgets();
// void buildSlugsWidgets();
void connectCommonWidgets();
void connectPxWidgets();
void connectSlugsWidgets();
// void connectPxWidgets();
// void connectSlugsWidgets();
void arrangeCommonCenterStack();
void arrangePxCenterStack();
void arrangeSlugsCenterStack();
// void arrangePxCenterStack();
// void arrangeSlugsCenterStack();
void connectCommonActions();
void connectPxActions();
void connectSlugsActions();
// void connectPxActions();
// void connectSlugsActions();
void configureWindowName();
......@@ -369,13 +297,13 @@ protected:
// TODO Should be moved elsewhere, as the protocol does not belong to the UI
MAVLinkProtocol* mavlink;
AS4Protocol* as4link;
MAVLinkSimulationLink* simulationLink;
LinkInterface* udpLink;
QSettings settings;
QStackedWidget *centerStack;
QActionGroup centerStackActionGroup;
// Center widgets
QPointer<Linecharts> linechartWidget;
......@@ -451,7 +379,7 @@ protected:
private:
Ui::MainWindow ui;
QString buildMenuKey (SETTINGS_SECTIONS section , TOOLS_WIDGET_NAMES tool, VIEW_SECTIONS view);
// QString buildMenuKey (SETTINGS_SECTIONS section , TOOLS_WIDGET_NAMES tool, VIEW_SECTIONS view);
QString getWindowStateKey();
QString getWindowGeometryKey();
......
......@@ -42,6 +42,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) :
}
this->setWindowTitle(title);
setObjectName(title+"WIDGET");
QList<UASInterface*> systems = UASManager::instance()->getUASList();
foreach (UASInterface* uas, systems) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment