Commit 4dc1b91a authored by LM's avatar LM

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 ...@@ -64,7 +64,8 @@ This file is part of the QGROUNDCONTROL project
MainWindow* MainWindow::instance() MainWindow* MainWindow::instance()
{ {
static MainWindow* _instance = 0; static MainWindow* _instance = 0;
if(_instance == 0) { if(_instance == 0)
{
_instance = new MainWindow(); _instance = new MainWindow();
/* Set the application as parent to ensure that this object /* Set the application as parent to ensure that this object
...@@ -90,18 +91,25 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -90,18 +91,25 @@ MainWindow::MainWindow(QWidget *parent):
styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"), styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"),
autoReconnect(false), autoReconnect(false),
currentStyle(QGC_MAINWINDOW_STYLE_INDOOR), currentStyle(QGC_MAINWINDOW_STYLE_INDOOR),
lowPowerMode(false) lowPowerMode(false),
centerStackActionGroup(this)
{ {
hide();
loadSettings(); loadSettings();
if (!settings.contains("CURRENT_VIEW")) { if (!settings.contains("CURRENT_VIEW"))
{
// Set this view as default view // Set this view as default view
settings.setValue("CURRENT_VIEW", currentView); settings.setValue("CURRENT_VIEW", currentView);
} else { }
else
{
// LOAD THE LAST VIEW // LOAD THE LAST VIEW
VIEW_SECTIONS currentViewCandidate = (VIEW_SECTIONS) settings.value("CURRENT_VIEW", currentView).toInt(); VIEW_SECTIONS currentViewCandidate = (VIEW_SECTIONS) settings.value("CURRENT_VIEW", currentView).toInt();
if (currentViewCandidate != VIEW_ENGINEER && if (currentViewCandidate != VIEW_ENGINEER &&
currentViewCandidate != VIEW_OPERATOR && currentViewCandidate != VIEW_OPERATOR &&
currentViewCandidate != VIEW_PILOT) { currentViewCandidate != VIEW_PILOT &&
currentViewCandidate != VIEW_FULL)
{
currentView = currentViewCandidate; currentView = currentViewCandidate;
} }
} }
...@@ -110,10 +118,14 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -110,10 +118,14 @@ MainWindow::MainWindow(QWidget *parent):
settings.sync(); settings.sync();
// Setup UI state machines
centerStackActionGroup.setExclusive(true);
// Setup user interface // Setup user interface
ui.setupUi(this); ui.setupUi(this);
setVisible(false); centerStack = new QStackedWidget(this);
setCentralWidget(centerStack);
buildCommonWidgets(); buildCommonWidgets();
...@@ -136,18 +148,28 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -136,18 +148,28 @@ MainWindow::MainWindow(QWidget *parent):
statusBar()->setSizeGripEnabled(true); statusBar()->setSizeGripEnabled(true);
// Restore the window setup
if (settings.contains(getWindowStateKey()))
{
loadViewState();
}
// Restore the window position and size // Restore the window position and size
if (settings.contains(getWindowGeometryKey())) { if (settings.contains(getWindowGeometryKey()))
{
// Restore the window geometry // Restore the window geometry
restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray()); restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray());
} else { }
else
{
// Adjust the size // Adjust the size
adjustSize(); adjustSize();
} }
// Populate link menu // Populate link menu
QList<LinkInterface*> links = LinkManager::instance()->getLinks(); QList<LinkInterface*> links = LinkManager::instance()->getLinks();
foreach(LinkInterface* link, links) { foreach(LinkInterface* link, links)
{
this->addLink(link); this->addLink(link);
} }
...@@ -170,11 +192,9 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -170,11 +192,9 @@ MainWindow::MainWindow(QWidget *parent):
toolBar->addPerspectiveChangeAction(ui.actionEngineersView); toolBar->addPerspectiveChangeAction(ui.actionEngineersView);
toolBar->addPerspectiveChangeAction(ui.actionPilotsView); toolBar->addPerspectiveChangeAction(ui.actionPilotsView);
// Enable and update view
presentView();
// Connect link // Connect link
if (autoReconnect) { if (autoReconnect)
{
SerialLink* link = new SerialLink(); SerialLink* link = new SerialLink();
// Add to registry // Add to registry
LinkManager::instance()->add(link); LinkManager::instance()->add(link);
...@@ -187,6 +207,8 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -187,6 +207,8 @@ MainWindow::MainWindow(QWidget *parent):
// Initialize window state // Initialize window state
windowStateVal = windowState(); windowStateVal = windowState();
show();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
...@@ -203,9 +225,11 @@ MainWindow::~MainWindow() ...@@ -203,9 +225,11 @@ MainWindow::~MainWindow()
QObjectList::iterator i; QObjectList::iterator i;
QDockWidget* dockWidget; QDockWidget* dockWidget;
for (i = childList.begin(); i != childList.end(); ++i) { for (i = childList.begin(); i != childList.end(); ++i)
{
dockWidget = dynamic_cast<QDockWidget*>(*i); dockWidget = dynamic_cast<QDockWidget*>(*i);
if (dockWidget) { if (dockWidget)
{
// Remove dock widget from main window // Remove dock widget from main window
removeDockWidget(dockWidget); removeDockWidget(dockWidget);
delete dockWidget->widget(); delete dockWidget->widget();
...@@ -219,61 +243,67 @@ MainWindow::~MainWindow() ...@@ -219,61 +243,67 @@ MainWindow::~MainWindow()
*/ */
void MainWindow::setDefaultSettingsForAp() 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 // // Check if the settings exist, instantiate defaults if necessary
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_OPERATOR);
if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true);
// ENABLE UAS LIST // // UNCONNECTED VIEW DEFAULT
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST,VIEW_OPERATOR), true); //// QString centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_UNCONNECTED);
// ENABLE HUD TOOL WIDGET // if (!settings.contains(centralKey)) {
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_HUD,VIEW_OPERATOR), true); // settings.setValue(centralKey,true);
// ENABLE WAYPOINTS
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_WAYPOINTS,VIEW_OPERATOR), true);
}
// ENGINEER VIEW DEFAULT // // ENABLE UAS LIST
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_LINECHART, VIEW_ENGINEER); //// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST, VIEW_UNCONNECTED), true);
if (!settings.contains(centralKey)) { // // ENABLE COMMUNICATION CONSOLE
settings.setValue(centralKey,true); //// settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_DEBUG_CONSOLE, VIEW_UNCONNECTED), true);
// Enable Parameter widget // }
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_PARAMETERS,VIEW_ENGINEER), true);
}
// MAVLINK VIEW DEFAULT // // OPERATOR VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_PROTOCOL, VIEW_MAVLINK); //// centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_OPERATOR);
if (!settings.contains(centralKey)) { // if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true); //// 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 // // ENGINEER VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_HUD, VIEW_PILOT); // centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_LINECHART, VIEW_ENGINEER);
if (!settings.contains(centralKey)) { // if (!settings.contains(centralKey)) {
settings.setValue(centralKey,true); // settings.setValue(centralKey,true);
// Enable Flight display // // Enable Parameter widget
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_HDD_1,VIEW_PILOT), true); // 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) void MainWindow::resizeEvent(QResizeEvent * event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if (height() < 800) { if (height() < 800)
{
ui.statusBar->setVisible(false); ui.statusBar->setVisible(false);
} else { }
else
{
ui.statusBar->setVisible(true); ui.statusBar->setVisible(true);
ui.statusBar->setSizeGripEnabled(true); ui.statusBar->setSizeGripEnabled(true);
} }
...@@ -293,22 +323,26 @@ QString MainWindow::getWindowGeometryKey() ...@@ -293,22 +323,26 @@ QString MainWindow::getWindowGeometryKey()
void MainWindow::buildCustomWidget() void MainWindow::buildCustomWidget()
{ {
// Show custom widgets only if UAS is connected // Show custom widgets only if UAS is connected
if (UASManager::instance()->getActiveUAS() != NULL) { if (UASManager::instance()->getActiveUAS() != NULL)
{
// Enable custom widgets // Enable custom widgets
ui.actionNewCustomWidget->setEnabled(true); ui.actionNewCustomWidget->setEnabled(true);
// Create custom widgets // Create custom widgets
QList<QGCToolWidget*> widgets = QGCToolWidget::createWidgetsFromSettings(this); QList<QGCToolWidget*> widgets = QGCToolWidget::createWidgetsFromSettings(this);
if (widgets.size() > 0) { if (widgets.size() > 0)
{
ui.menuTools->addSeparator(); 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 // Check if this widget already has a parent, do not create it in this case
QGCToolWidget* tool = widgets.at(i); QGCToolWidget* tool = widgets.at(i);
QDockWidget* dock = dynamic_cast<QDockWidget*>(tool->parentWidget()); QDockWidget* dock = dynamic_cast<QDockWidget*>(tool->parentWidget());
if (!dock) { if (!dock)
{
QDockWidget* dock = new QDockWidget(tool->windowTitle(), this); QDockWidget* dock = new QDockWidget(tool->windowTitle(), this);
dock->setObjectName(tool->objectName()+"_DOCK"); dock->setObjectName(tool->objectName()+"_DOCK");
dock->setWidget(tool); dock->setWidget(tool);
...@@ -320,8 +354,8 @@ void MainWindow::buildCustomWidget() ...@@ -320,8 +354,8 @@ void MainWindow::buildCustomWidget()
widgets.at(i)->setMainMenuAction(showAction); widgets.at(i)->setMainMenuAction(showAction);
ui.menuTools->addAction(showAction); ui.menuTools->addAction(showAction);
// Load visibility for view (default is off) // // Load visibility for view (default is off)
dock->setVisible(tool->isVisible(currentView)); // dock->setVisible(tool->isVisible(currentView));
// Load dock widget location (default is bottom) // Load dock widget location (default is bottom)
Qt::DockWidgetArea location = static_cast <Qt::DockWidgetArea>(tool->getDockWidgetArea(currentView)); Qt::DockWidgetArea location = static_cast <Qt::DockWidgetArea>(tool->getDockWidgetArea(currentView));
...@@ -339,71 +373,73 @@ void MainWindow::buildCommonWidgets() ...@@ -339,71 +373,73 @@ void MainWindow::buildCommonWidgets()
connect(mavlink, SIGNAL(protocolStatusMessage(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection); connect(mavlink, SIGNAL(protocolStatusMessage(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection);
// Dock widgets // Dock widgets
if (!controlDockWidget) { if (!controlDockWidget)
{
controlDockWidget = new QDockWidget(tr("Control"), this); controlDockWidget = new QDockWidget(tr("Control"), this);
controlDockWidget->setObjectName("UNMANNED_SYSTEM_CONTROL_DOCKWIDGET"); controlDockWidget->setObjectName("UNMANNED_SYSTEM_CONTROL_DOCKWIDGET");
controlDockWidget->setWidget( new UASControlWidget(this) ); 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 = new QDockWidget(tr("Unmanned Systems"), this);
listDockWidget->setWidget( new UASListWidget(this) ); listDockWidget->setWidget( new UASListWidget(this) );
listDockWidget->setObjectName("UNMANNED_SYSTEMS_LIST_DOCKWIDGET"); 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 = new QDockWidget(tr("Mission Plan"), this);
waypointsDockWidget->setWidget( new QGCWaypointListMulti(this) ); waypointsDockWidget->setWidget( new QGCWaypointListMulti(this) );
waypointsDockWidget->setObjectName("WAYPOINT_LIST_DOCKWIDGET"); 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 = new QDockWidget(tr("Status Details"), this);
infoDockWidget->setWidget( new UASInfoWidget(this) ); infoDockWidget->setWidget( new UASInfoWidget(this) );
infoDockWidget->setObjectName("UAS_STATUS_DETAILS_DOCKWIDGET"); 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 = new QDockWidget(tr("Communication Console"), this);
debugConsoleDockWidget->setWidget( new DebugConsole(this) ); debugConsoleDockWidget->setWidget( new DebugConsole(this) );
debugConsoleDockWidget->setObjectName("COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET"); 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 = new QDockWidget(tr("MAVLink Log Player"), this);
logPlayerDockWidget->setWidget( new QGCMAVLinkLogPlayer(mavlink, this) ); logPlayerDockWidget->setWidget( new QGCMAVLinkLogPlayer(mavlink, this) );
logPlayerDockWidget->setObjectName("MAVLINK_LOG_PLAYER_DOCKWIDGET"); 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 // Center widgets
if (!mapWidget) if (!mapWidget)
{ {
mapWidget = new QGCMapTool(this); mapWidget = new QGCMapTool(this);
addToCentralWidgetsMenu (mapWidget, "Maps", SLOT(showCentralWidget()),CENTRAL_MAP); addCentralWidget(mapWidget, "Maps");
} }
if (!protocolWidget) { if (!protocolWidget)
{
protocolWidget = new XMLCommProtocolWidget(this); protocolWidget = new XMLCommProtocolWidget(this);
addToCentralWidgetsMenu (protocolWidget, "Mavlink Generator", SLOT(showCentralWidget()),CENTRAL_PROTOCOL); addCentralWidget(protocolWidget, "Mavlink Generator");
} }
if (!dataplotWidget) { if (!dataplotWidget)
{
dataplotWidget = new QGCDataPlot2D(this); 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 //FIXME: memory of acceptList will never be freed again
QStringList* acceptList = new QStringList(); QStringList* acceptList = new QStringList();
acceptList->append("-105,roll deg,deg,+105,s"); acceptList->append("-105,roll deg,deg,+105,s");
...@@ -433,41 +469,27 @@ void MainWindow::buildPxWidgets() ...@@ -433,41 +469,27 @@ void MainWindow::buildPxWidgets()
//acceptList2->append("-2048,accel. y,raw,2048,s"); //acceptList2->append("-2048,accel. y,raw,2048,s");
//acceptList2->append("-2048,accel. z,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) { if (!hudWidget) {
hudWidget = new HUD(320, 240, this); hudWidget = new HUD(320, 240, this);
addToCentralWidgetsMenu(hudWidget, tr("Head Up Display"), SLOT(showCentralWidget()), CENTRAL_HUD); addCentralWidget(hudWidget, tr("Head Up Display"));
} }
if (!dataplotWidget) { if (!dataplotWidget) {
dataplotWidget = new QGCDataPlot2D(this); dataplotWidget = new QGCDataPlot2D(this);
addToCentralWidgetsMenu(dataplotWidget, "Logfile Plot", SLOT(showCentralWidget()), CENTRAL_DATA_PLOT); addCentralWidget(dataplotWidget, tr("Logfile Plot"));
} }
#ifdef QGC_OSG_ENABLED #ifdef QGC_OSG_ENABLED
if (!_3DWidget) { if (!_3DWidget) {
_3DWidget = Q3DWidgetFactory::get("PIXHAWK"); _3DWidget = Q3DWidgetFactory::get("PIXHAWK");
addToCentralWidgetsMenu(_3DWidget, tr("Local 3D"), SLOT(showCentralWidget()), CENTRAL_3D_LOCAL); addCentralWidget(_3DWidget, tr("Local 3D"));
}
#endif
#ifdef QGC_OSGEARTH_ENABLED
if (!_3DMapWidget) {
_3DMapWidget = Q3DWidgetFactory::get("MAP3D");
addToCentralWidgetsMenu(_3DMapWidget, tr("OSG Earth 3D"), SLOT(showCentralWidget()), CENTRAL_OSGEARTH);
} }
#endif #endif
#if (defined _MSC_VER) | (defined Q_OS_MAC) #if (defined _MSC_VER) | (defined Q_OS_MAC)
if (!gEarthWidget) { if (!gEarthWidget) {
gEarthWidget = new QGCGoogleEarthView(this); gEarthWidget = new QGCGoogleEarthView(this);
addToCentralWidgetsMenu(gEarthWidget, tr("Google Earth"), SLOT(showCentralWidget()), CENTRAL_GOOGLE_EARTH); addCentralWidget(gEarthWidget, tr("Google Earth"));
} }
#endif #endif
...@@ -478,56 +500,56 @@ void MainWindow::buildPxWidgets() ...@@ -478,56 +500,56 @@ void MainWindow::buildPxWidgets()
detectionDockWidget = new QDockWidget(tr("Object Recognition"), this); detectionDockWidget = new QDockWidget(tr("Object Recognition"), this);
detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) ); detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) );
detectionDockWidget->setObjectName("OBJECT_DETECTION_DOCK_WIDGET"); 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) { if (!parametersDockWidget) {
parametersDockWidget = new QDockWidget(tr("Calibration and Onboard Parameters"), this); parametersDockWidget = new QDockWidget(tr("Calibration and Onboard Parameters"), this);
parametersDockWidget->setWidget( new ParameterInterface(this) ); parametersDockWidget->setWidget( new ParameterInterface(this) );
parametersDockWidget->setObjectName("PARAMETER_INTERFACE_DOCKWIDGET"); 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) { if (!watchdogControlDockWidget) {
watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this); watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this);
watchdogControlDockWidget->setWidget( new WatchdogControl(this) ); watchdogControlDockWidget->setWidget( new WatchdogControl(this) );
watchdogControlDockWidget->setObjectName("WATCHDOG_CONTROL_DOCKWIDGET"); 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) { if (!hsiDockWidget) {
hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this); hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this);
hsiDockWidget->setWidget( new HSIDisplay(this) ); hsiDockWidget->setWidget( new HSIDisplay(this) );
hsiDockWidget->setObjectName("HORIZONTAL_SITUATION_INDICATOR_DOCK_WIDGET"); 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) { if (!headDown1DockWidget) {
headDown1DockWidget = new QDockWidget(tr("Flight Display"), this); headDown1DockWidget = new QDockWidget(tr("Flight Display"), this);
headDown1DockWidget->setWidget( new HDDisplay(acceptList, "Flight Display", this) ); headDown1DockWidget->setWidget( new HDDisplay(acceptList, "Flight Display", this) );
headDown1DockWidget->setObjectName("HEAD_DOWN_DISPLAY_1_DOCK_WIDGET"); 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) { if (!headDown2DockWidget) {
headDown2DockWidget = new QDockWidget(tr("Actuator Status"), this); headDown2DockWidget = new QDockWidget(tr("Actuator Status"), this);
headDown2DockWidget->setWidget( new HDDisplay(acceptList2, "Actuator Status", this) ); headDown2DockWidget->setWidget( new HDDisplay(acceptList2, "Actuator Status", this) );
headDown2DockWidget->setObjectName("HEAD_DOWN_DISPLAY_2_DOCK_WIDGET"); 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) { if (!rcViewDockWidget) {
rcViewDockWidget = new QDockWidget(tr("Radio Control"), this); rcViewDockWidget = new QDockWidget(tr("Radio Control"), this);
rcViewDockWidget->setWidget( new QGCRemoteControlView(this) ); rcViewDockWidget->setWidget( new QGCRemoteControlView(this) );
rcViewDockWidget->setObjectName("RADIO_CONTROL_CHANNELS_DOCK_WIDGET"); 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) { if (!headUpDockWidget) {
headUpDockWidget = new QDockWidget(tr("HUD"), this); headUpDockWidget = new QDockWidget(tr("HUD"), this);
headUpDockWidget->setWidget( new HUD(320, 240, this)); headUpDockWidget->setWidget( new HUD(320, 240, this));
headUpDockWidget->setObjectName("HEAD_UP_DISPLAY_DOCK_WIDGET"); 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) { if (!video1DockWidget) {
...@@ -538,7 +560,7 @@ void MainWindow::buildPxWidgets() ...@@ -538,7 +560,7 @@ void MainWindow::buildPxWidgets()
// FIXME select video stream as well // FIXME select video stream as well
video1DockWidget->setWidget(video1); video1DockWidget->setWidget(video1);
video1DockWidget->setObjectName("VIDEO_STREAM_1_DOCK_WIDGET"); 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) { if (!video2DockWidget) {
...@@ -549,342 +571,58 @@ void MainWindow::buildPxWidgets() ...@@ -549,342 +571,58 @@ void MainWindow::buildPxWidgets()
// FIXME select video stream as well // FIXME select video stream as well
video2DockWidget->setWidget(video2); video2DockWidget->setWidget(video2);
video2DockWidget->setObjectName("VIDEO_STREAM_2_DOCK_WIDGET"); 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 // Dialogue widgets
//FIXME: free memory in destructor //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::addTool(QDockWidget* widget, const QString& title, Qt::DockWidgetArea area)
void MainWindow::addToCentralWidgetsMenu ( QWidget* widget,
const QString title,
const char * slotName,
TOOLS_WIDGET_NAMES centralWidget)
{ {
QAction* tempAction; QAction* tempAction = ui.menuTools->addAction(title);
// 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);
tempAction->setCheckable(true); tempAction->setCheckable(true);
tempAction->setData(centralWidget); QVariant var;
var.setValue((QWidget*)widget);
// populate the Hashes tempAction->setData(var);
toolsMenuActions[centralWidget] = tempAction; connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool)));
dockWidgets[centralWidget] = widget; addDockWidget(area, 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);
} }
void MainWindow::showCentralWidget() void MainWindow::showTool(bool show)
{ {
QAction* senderAction = qobject_cast<QAction *>(sender()); QAction* act = qobject_cast<QAction *>(sender());
QWidget* widget = qVariantValue<QWidget *>(act->data());
// Block sender action while manipulating state widget->setVisible(show);
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();
}
} }
/** void MainWindow::addCentralWidget(QWidget* widget, const QString& title)
* 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)
{ {
QAction* tempAction; // Check if this widget already has been added
QString posKey, chKey; if (centerStack->indexOf(widget) == -1)
{
centerStack->addWidget(widget);
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;
QAction* action = toolsMenuActions[tool]; QAction* tempAction = ui.menuMain->addAction(title);
action->blockSignals(true);
action->setChecked(visible);
action->blockSignals(false);
QHashIterator<int, QWidget*> i(dockWidgets); tempAction->setCheckable(true);
while (i.hasNext()) { QVariant var;
i.next(); var.setValue((QWidget*)widget);
if ((static_cast <QDockWidget *>(dockWidgets[i.key()])) == dockWidget) { tempAction->setData(var);
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView); centerStackActionGroup.addAction(tempAction);
settings.setValue(chKey,visible); connect(tempAction,SIGNAL(triggered()),this, SLOT(showCentralWidget()));
// qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible;
break;
}
}
}
} }
} }
void MainWindow::showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view) void MainWindow::showCentralWidget()
{
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)
{ {
// Key is built as follows: autopilot_type/section_menu/view/tool/section QAction* act = qobject_cast<QAction *>(sender());
int apType; QWidget* widget = qVariantValue<QWidget *>(act->data());
centerStack->setCurrentWidget(widget);
// 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) + "_" );
} }
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
...@@ -896,62 +634,6 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -896,62 +634,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(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 * Connect the signals and slots of the common window widgets
*/ */
...@@ -998,7 +680,8 @@ void MainWindow::loadCustomWidget() ...@@ -998,7 +680,8 @@ void MainWindow::loadCustomWidget()
QGCToolWidget* tool = new QGCToolWidget("", this); QGCToolWidget* tool = new QGCToolWidget("", this);
tool->loadSettings(fileName); tool->loadSettings(fileName);
if (QGCToolWidget::instances()->size() < 2) { if (QGCToolWidget::instances()->size() < 2)
{
// This is the first widget // This is the first widget
ui.menuTools->addSeparator(); ui.menuTools->addSeparator();
} }
...@@ -1019,85 +702,8 @@ void MainWindow::loadCustomWidget() ...@@ -1019,85 +702,8 @@ void MainWindow::loadCustomWidget()
dock->setVisible(true); 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() 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() ...@@ -1414,20 +1020,9 @@ void MainWindow::connectCommonActions()
connect(ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettings())); connect(ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
} }
void MainWindow::connectPxActions()
{
}
void MainWindow::connectSlugsActions()
{
}
void MainWindow::showHelp() void MainWindow::showHelp()
{ {
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/users/"))) { if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/users/start"))) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open help in browser"); msgBox.setText("Could not open help in browser");
...@@ -1440,7 +1035,7 @@ void MainWindow::showHelp() ...@@ -1440,7 +1035,7 @@ void MainWindow::showHelp()
void MainWindow::showCredits() void MainWindow::showCredits()
{ {
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/credits/"))) { if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/credits"))) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open credits in browser"); msgBox.setText("Could not open credits in browser");
...@@ -1453,7 +1048,7 @@ void MainWindow::showCredits() ...@@ -1453,7 +1048,7 @@ void MainWindow::showCredits()
void MainWindow::showRoadMap() void MainWindow::showRoadMap()
{ {
if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/roadmap/"))) { if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/dev/roadmap"))) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText("Could not open roadmap in browser"); msgBox.setText("Could not open roadmap in browser");
...@@ -1633,71 +1228,23 @@ void MainWindow::UASCreated(UASInterface* uas) ...@@ -1633,71 +1228,23 @@ void MainWindow::UASCreated(UASInterface* uas)
} }
} }
switch (uas->getAutopilotType()) { // Line chart
case (MAV_AUTOPILOT_SLUGS): { if (!linechartWidget)
// Build Slugs Widgets {
buildSlugsWidgets(); // Center widgets
linechartWidget = new Linecharts(this);
// Connect Slugs Widgets addCentralWidget(linechartWidget, tr("Realtime Plot"));
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;
} }
// Change the view only if this is the first UAS // Change the view only if this is the first UAS
// If this is the first connected UAS, it is both created as well as // If this is the first connected UAS, it is both created as well as
// the currently active UAS // the currently active UAS
if (UASManager::instance()->getUASList().size() == 1) { if (UASManager::instance()->getUASList().size() == 1)
{
// Load last view if setting is present // Load last view if setting is present
if (settings.contains("CURRENT_VIEW_WITH_UAS_CONNECTED")) { if (settings.contains("CURRENT_VIEW_WITH_UAS_CONNECTED"))
clearView(); {
int view = settings.value("CURRENT_VIEW_WITH_UAS_CONNECTED").toInt(); int view = settings.value("CURRENT_VIEW_WITH_UAS_CONNECTED").toInt();
switch (view) { switch (view) {
case VIEW_ENGINEER: case VIEW_ENGINEER:
...@@ -1717,7 +1264,9 @@ void MainWindow::UASCreated(UASInterface* uas) ...@@ -1717,7 +1264,9 @@ void MainWindow::UASCreated(UASInterface* uas)
loadOperatorView(); loadOperatorView();
break; break;
} }
} else { }
else
{
loadOperatorView(); loadOperatorView();
} }
} }
...@@ -1735,275 +1284,97 @@ void MainWindow::UASCreated(UASInterface* uas) ...@@ -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 // 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) // 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 // therefore this state is stored here and restored after applying the rest of the settings in the new
// perspective. // perspective.
windowStateVal = this->windowState(); windowStateVal = this->windowState();
settings.setValue(getWindowGeometryKey(), saveGeometry()); settings.setValue(getWindowGeometryKey(), saveGeometry());
}
QAction* temp; void MainWindow::loadViewState()
{
// Set tool widget visibility settings for this view // Restore center stack state
foreach (int key, toolsMenuActions.keys()) { int index = settings.value(getWindowStateKey()+"CENTER_WIDGET", centerStack->currentIndex()).toInt();
temp = toolsMenuActions[key]; centerStack->setCurrentIndex(index);
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() );
QObjectList::iterator i; // Restore the widget positions and size
QDockWidget* dockWidget; if (settings.contains(getWindowStateKey()))
for (i = childList.begin(); i != childList.end(); ++i) { {
dockWidget = dynamic_cast<QDockWidget*>(*i); restoreState(settings.value(getWindowStateKey()).toByteArray(), QGC::applicationVersion());
if (dockWidget) {
// Remove dock widget from main window
removeDockWidget(dockWidget);
dockWidget->hide();
//dockWidget->setVisible(false);
}
} }
changingViewsFlag = false;
} }
void MainWindow::loadEngineerView() void MainWindow::loadEngineerView()
{ {
if (currentView != VIEW_ENGINEER) { if (currentView != VIEW_ENGINEER) {
clearView(); storeViewState();
currentView = VIEW_ENGINEER; currentView = VIEW_ENGINEER;
ui.actionEngineersView->setChecked(true); ui.actionEngineersView->setChecked(true);
presentView(); loadViewState();
} }
} }
void MainWindow::loadOperatorView() void MainWindow::loadOperatorView()
{ {
if (currentView != VIEW_OPERATOR) { if (currentView != VIEW_OPERATOR) {
clearView(); storeViewState();
currentView = VIEW_OPERATOR; currentView = VIEW_OPERATOR;
ui.actionOperatorsView->setChecked(true); ui.actionOperatorsView->setChecked(true);
presentView(); loadViewState();
} }
} }
void MainWindow::loadUnconnectedView() void MainWindow::loadUnconnectedView()
{ {
if (currentView != VIEW_UNCONNECTED) { if (currentView != VIEW_UNCONNECTED)
clearView(); {
storeViewState();
currentView = VIEW_UNCONNECTED; currentView = VIEW_UNCONNECTED;
ui.actionUnconnectedView->setChecked(true); ui.actionUnconnectedView->setChecked(true);
presentView(); loadViewState();
} }
} }
void MainWindow::loadPilotView() void MainWindow::loadPilotView()
{ {
if (currentView != VIEW_PILOT) { if (currentView != VIEW_PILOT)
clearView(); {
storeViewState();
currentView = VIEW_PILOT; currentView = VIEW_PILOT;
ui.actionPilotsView->setChecked(true); ui.actionPilotsView->setChecked(true);
presentView(); loadViewState();
} }
} }
void MainWindow::loadMAVLinkView() void MainWindow::loadMAVLinkView()
{ {
if (currentView != VIEW_MAVLINK) { if (currentView != VIEW_MAVLINK)
clearView(); {
storeViewState();
currentView = VIEW_MAVLINK; currentView = VIEW_MAVLINK;
ui.actionMavlinkView->setChecked(true); ui.actionMavlinkView->setChecked(true);
presentView(); loadViewState();
}
}
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);
} }
} }
void MainWindow::loadDataView(QString fileName) 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 // 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); 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 ...@@ -49,7 +49,6 @@ This file is part of the QGROUNDCONTROL project
#include "UASListWidget.h" #include "UASListWidget.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "MAVLinkSimulationLink.h" #include "MAVLinkSimulationLink.h"
#include "AS4Protocol.h"
#include "ObjectDetectionView.h" #include "ObjectDetectionView.h"
#include "HUD.h" #include "HUD.h"
#include "JoystickWidget.h" #include "JoystickWidget.h"
...@@ -159,9 +158,6 @@ public slots: ...@@ -159,9 +158,6 @@ public slots:
/** @brief Show the project roadmap */ /** @brief Show the project roadmap */
void showRoadMap(); void showRoadMap();
/** @brief Shows the widgets based on configuration and current view and autopilot */
void presentView();
/** @brief Reload the CSS style sheet */ /** @brief Reload the CSS style sheet */
void reloadStylesheet(); void reloadStylesheet();
/** @brief Let the user select the CSS style sheet */ /** @brief Let the user select the CSS style sheet */
...@@ -193,29 +189,21 @@ public slots: ...@@ -193,29 +189,21 @@ public slots:
/** /**
* @brief Shows a Docked Widget based on the action sender * @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 * 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 * @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 * It shows the Widget based on the action sender
* *
*/ */
void showCentralWidget(); 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: protected:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
...@@ -223,65 +211,19 @@ protected: ...@@ -223,65 +211,19 @@ protected:
/** @brief Set default window settings for the current autopilot type */ /** @brief Set default window settings for the current autopilot type */
void setDefaultSettingsForAp(); 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 { typedef enum _VIEW_SECTIONS {
VIEW_ENGINEER, VIEW_ENGINEER,
VIEW_OPERATOR, VIEW_OPERATOR,
VIEW_PILOT, VIEW_PILOT,
VIEW_MAVLINK, VIEW_MAVLINK,
VIEW_UNCONNECTED, ///< View in unconnected mode, when no UAS is available VIEW_UNCONNECTED, ///< View in unconnected mode, when no UAS is available
VIEW_FULL ///< All widgets shown at once
} VIEW_SECTIONS; } VIEW_SECTIONS;
QHash<int, QAction*> toolsMenuActions; // Holds ptr to the Menu Actions QHash<int, QAction*> toolsMenuActions; // Holds ptr to the Menu Actions
QHash<int, QWidget*> dockWidgets; // Holds ptr to the Actual Dock widget 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 * @brief Adds an already instantiated QDockedWidget to the Tools Menu
...@@ -290,24 +232,22 @@ protected: ...@@ -290,24 +232,22 @@ protected:
* tools menu and connects the QMenuAction to a slot that shows the widget and * tools menu and connects the QMenuAction to a slot that shows the widget and
* checks/unchecks the tools menu item * 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 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 * @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); 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 // * @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 // * Based on the the autopilot and the current view it queries the settings and shows the
* widget if necessary // * widget if necessary
* // *
* @param widget The QDockWidget requested to be shown // * @param widget The QDockWidget requested to be shown
* @param view The view for which the QDockWidget is requested // * @param view The view for which the QDockWidget is requested
*/ // */
void showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view = VIEW_MAVLINK); // void showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view = VIEW_MAVLINK);
/** /**
* @brief Adds an already instantiated QWidget to the center stack * @brief Adds an already instantiated QWidget to the center stack
...@@ -319,21 +259,8 @@ protected: ...@@ -319,21 +259,8 @@ protected:
* *
* @param widget The QWidget being added * @param widget The QWidget being added
* @param title The entry that will appear in the Menu * @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 */ /** @brief Catch window resize events */
void resizeEvent(QResizeEvent * event); void resizeEvent(QResizeEvent * event);
...@@ -343,24 +270,25 @@ protected: ...@@ -343,24 +270,25 @@ protected:
bool aboutToCloseFlag; bool aboutToCloseFlag;
bool changingViewsFlag; bool changingViewsFlag;
void clearView(); void storeViewState();
void loadViewState();
void buildCustomWidget(); void buildCustomWidget();
void buildCommonWidgets(); void buildCommonWidgets();
void buildPxWidgets(); // void buildPxWidgets();
void buildSlugsWidgets(); // void buildSlugsWidgets();
void connectCommonWidgets(); void connectCommonWidgets();
void connectPxWidgets(); // void connectPxWidgets();
void connectSlugsWidgets(); // void connectSlugsWidgets();
void arrangeCommonCenterStack(); void arrangeCommonCenterStack();
void arrangePxCenterStack(); // void arrangePxCenterStack();
void arrangeSlugsCenterStack(); // void arrangeSlugsCenterStack();
void connectCommonActions(); void connectCommonActions();
void connectPxActions(); // void connectPxActions();
void connectSlugsActions(); // void connectSlugsActions();
void configureWindowName(); void configureWindowName();
...@@ -369,13 +297,13 @@ protected: ...@@ -369,13 +297,13 @@ protected:
// TODO Should be moved elsewhere, as the protocol does not belong to the UI // TODO Should be moved elsewhere, as the protocol does not belong to the UI
MAVLinkProtocol* mavlink; MAVLinkProtocol* mavlink;
AS4Protocol* as4link;
MAVLinkSimulationLink* simulationLink; MAVLinkSimulationLink* simulationLink;
LinkInterface* udpLink; LinkInterface* udpLink;
QSettings settings; QSettings settings;
QStackedWidget *centerStack; QStackedWidget *centerStack;
QActionGroup centerStackActionGroup;
// Center widgets // Center widgets
QPointer<Linecharts> linechartWidget; QPointer<Linecharts> linechartWidget;
...@@ -451,7 +379,7 @@ protected: ...@@ -451,7 +379,7 @@ protected:
private: private:
Ui::MainWindow ui; 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 getWindowStateKey();
QString getWindowGeometryKey(); QString getWindowGeometryKey();
......
...@@ -42,6 +42,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) : ...@@ -42,6 +42,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) :
} }
this->setWindowTitle(title); this->setWindowTitle(title);
setObjectName(title+"WIDGET");
QList<UASInterface*> systems = UASManager::instance()->getUASList(); QList<UASInterface*> systems = UASManager::instance()->getUASList();
foreach (UASInterface* uas, systems) { foreach (UASInterface* uas, systems) {
......
Markdown is supported
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