From 55cdf5dbdcbd488d98b54b9b427365ac61c28cb4 Mon Sep 17 00:00:00 2001 From: lm Date: Tue, 21 Dec 2010 13:02:34 +0100 Subject: [PATCH] Improved and bugfixed window persistence --- src/uas/UASManager.cc | 14 +- src/ui/DebugConsole.cc | 48 +- src/ui/HDDisplay.cc | 4 +- src/ui/HUD.cc | 12 +- src/ui/MainWindow.cc | 1412 ++++++++++++++-------------------------- src/ui/MainWindow.h | 14 +- 6 files changed, 546 insertions(+), 958 deletions(-) diff --git a/src/uas/UASManager.cc b/src/uas/UASManager.cc index fabfec6ba..cb3183cb9 100644 --- a/src/uas/UASManager.cc +++ b/src/uas/UASManager.cc @@ -71,6 +71,18 @@ void UASManager::run() void UASManager::addUAS(UASInterface* uas) { + // WARNING: The active uas is set here + // and then announced below. This is necessary + // to make sure the getActiveUAS() function + // returns the UAS once the UASCreated() signal + // is emitted. The code is thus NOT redundant. + bool firstUAS = false; + if (activeUAS == NULL) + { + firstUAS = true; + activeUAS = uas; + } + // Only execute if there is no UAS at this index if (!systems.contains(uas->getUASID())) { @@ -79,7 +91,7 @@ void UASManager::addUAS(UASInterface* uas) } // If there is no active UAS yet, set the first one as the active UAS - if (activeUAS == NULL) + if (firstUAS) { setActiveUAS(uas); } diff --git a/src/ui/DebugConsole.cc b/src/ui/DebugConsole.cc index d91de4a9e..9853826dd 100644 --- a/src/ui/DebugConsole.cc +++ b/src/ui/DebugConsole.cc @@ -205,30 +205,30 @@ void DebugConsole::paintEvent(QPaintEvent *event) { Q_UNUSED(event); // Update bandwidth - if (holdOn) - { - //qDebug() << "Data rate:" << dataRate/1000.0f << "kB/s"; - QString rate("data rate: %1"); - rate.arg(dataRate); - QPainter painter(this); - painter.setRenderHint(QPainter::HighQualityAntialiasing); - painter.translate(width()/5.0f, height()/5.0f); - - - - //QFont font("Bitstream Vera Sans"); - QFont font = painter.font(); - font.setPixelSize((int)(60.0f)); - - QFontMetrics metrics = QFontMetrics(font); - int border = qMax(4, metrics.leading()); - QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125), - Qt::AlignLeft | Qt::TextWordWrap, rate); - painter.setPen(QColor(255, 50, 50)); - painter.setRenderHint(QPainter::TextAntialiasing); - painter.drawText(QRect(QPoint(static_cast(width()/5.0f), static_cast(height()/5.0f)), QPoint(static_cast(width() - width()/5.0f), static_cast(height() - height()/5.0f))), rate); - //Qt::AlignRight | Qt::TextWordWrap - } +// if (holdOn) +// { +// //qDebug() << "Data rate:" << dataRate/1000.0f << "kB/s"; +// QString rate("data rate: %1"); +// rate.arg(dataRate); +// QPainter painter(this); +// painter.setRenderHint(QPainter::HighQualityAntialiasing); +// painter.translate(width()/5.0f, height()/5.0f); + + + +// //QFont font("Bitstream Vera Sans"); +// QFont font = painter.font(); +// font.setPixelSize((int)(60.0f)); + +// QFontMetrics metrics = QFontMetrics(font); +// int border = qMax(4, metrics.leading()); +// QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125), +// Qt::AlignLeft | Qt::TextWordWrap, rate); +// painter.setPen(QColor(255, 50, 50)); +// painter.setRenderHint(QPainter::TextAntialiasing); +// painter.drawText(QRect(QPoint(static_cast(width()/5.0f), static_cast(height()/5.0f)), QPoint(static_cast(width() - width()/5.0f), static_cast(height() - height()/5.0f))), rate); +// //Qt::AlignRight | Qt::TextWordWrap +// } } void DebugConsole::receiveBytes(LinkInterface* link, QByteArray bytes) diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index 1f8f11208..1476ecee1 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -134,7 +134,7 @@ HDDisplay::HDDisplay(QStringList* plotList, QWidget *parent) : if(!QFile::exists(fontFileName)) qDebug() << "ERROR! font file: " << fontFileName << " DOES NOT EXIST!"; fontDatabase.addApplicationFont(fontFileName); - font = fontDatabase.font(fontFamilyName, "Roman", (int)(10*scalingFactor*1.2f+0.5f)); + font = fontDatabase.font(fontFamilyName, "Roman", qMax(5, (int)(10*scalingFactor*1.2f+0.5f))); if (font.family() != fontFamilyName) qDebug() << "ERROR! Font not loaded: " << fontFamilyName; // Connect with UAS @@ -151,7 +151,7 @@ HDDisplay::~HDDisplay() void HDDisplay::enableGLRendering(bool enable) { - + Q_UNUSED(enable) } void HDDisplay::triggerUpdate() diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index c95107ea1..def7a8ef8 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -150,8 +150,16 @@ HUD::HUD(int width, int height, QWidget* parent) if(!QFile::exists(fontFileName)) qDebug() << "ERROR! font file: " << fontFileName << " DOES NOT EXIST!"; fontDatabase.addApplicationFont(fontFileName); - font = fontDatabase.font(fontFamilyName, "Roman", (int)(10*scalingFactor*1.2f+0.5f)); - if (font.family() != fontFamilyName) qDebug() << "ERROR! Font not loaded: " << fontFamilyName; + font = fontDatabase.font(fontFamilyName, "Roman", qMax(5,(int)(10.0f*scalingFactor*1.2f+0.5f))); + QFont* fontPtr = &font; + if (!fontPtr) + { + qDebug() << "ERROR! FONT NOT LOADED!"; + } + else + { + if (font.family() != fontFamilyName) qDebug() << "ERROR! WRONG FONT LOADED: " << fontFamilyName; + } // Connect with UAS UASManager* manager = UASManager::instance(); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 055291cc3..be6980c35 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -48,11 +48,14 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), toolsMenuActions(), - currentView(VIEW_MAVLINK), + currentView(VIEW_OPERATOR), + aboutToCloseFlag(false), settings() { this->hide(); this->setVisible(false); + // Get current settings + settings.sync(); // Setup user interface ui.setupUi(this); @@ -86,27 +89,28 @@ MainWindow::MainWindow(QWidget *parent): // Load previous widget setup -// // FIXME WORK IN PROGRESS -// QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); - -// QList dockwidgets = qFindChildren(this); -// if (dockwidgets.size()) -// { -// settings.beginGroup("mainwindow/dockwidgets"); -// for (int i = 0; i < dockwidgets.size(); ++i) -// { -// QDockWidget *dockWidget = dockwidgets.at(i); -// if (dockWidget->parentWidget() == this) -// { -// if (settings.contains(dockWidget->windowTitle())) -// { -// dockWidget->setVisible(settings.value(dockWidget->windowTitle(), dockWidget->isVisible()).toBool()); -// } -// } -// } -// settings.endGroup(); -// } - + // // FIXME WORK IN PROGRESS + // QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); + + // QList dockwidgets = qFindChildren(this); + // if (dockwidgets.size()) + // { + // settings.beginGroup("mainwindow/dockwidgets"); + // for (int i = 0; i < dockwidgets.size(); ++i) + // { + // QDockWidget *dockWidget = dockwidgets.at(i); + // if (dockWidget->parentWidget() == this) + // { + // if (settings.contains(dockWidget->windowTitle())) + // { + // dockWidget->setVisible(settings.value(dockWidget->windowTitle(), dockWidget->isVisible()).toBool()); + // } + // } + // } + // settings.endGroup(); + // } + +// // Select the right perspective // Enable and update view this->show(); @@ -283,79 +287,80 @@ void MainWindow::addToCentralWidgetsMenu ( QWidget* widget, const QString title, const char * slotName, TOOLS_WIDGET_NAMES centralWidget){ - QAction* tempAction; + QAction* tempAction; - // 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); - } + // 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.menuTools->addAction(title); + tempAction = ui.menuTools->addAction(title); - tempAction->setCheckable(true); - tempAction->setData(centralWidget); + tempAction->setCheckable(true); + tempAction->setData(centralWidget); - // populate the Hashes - toolsMenuActions[centralWidget] = tempAction; - dockWidgets[centralWidget] = widget; + // populate the Hashes + toolsMenuActions[centralWidget] = tempAction; + dockWidgets[centralWidget] = widget; - QString chKey = buildMenuKey(SUB_SECTION_CHECKED, centralWidget, currentView); + 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()); -// } + 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()),this, slotName); + // connect the action + connect(tempAction,SIGNAL(triggered()),this, slotName); } void MainWindow::showCentralWidget() { - QAction* senderAction = qobject_cast(sender()); - int tool = senderAction->data().toInt(); - QString chKey; + QAction* senderAction = qobject_cast(sender()); + int tool = senderAction->data().toInt(); + QString chKey; - // check the current action - - if (senderAction && dockWidgets[tool]) - { + // check the current action - // uncheck all central widget actions - QHashIterator i(toolsMenuActions); - while (i.hasNext()) { - i.next(); - qDebug() << "shCW" << i.key() << "read"; - if (i.value() && i.value()->data().toInt() > 255){ - i.value()->setChecked(false); + if (senderAction && dockWidgets[tool]) + { - // update the settings - chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(i.value()->data().toInt()), currentView); - settings.setValue(chKey,false); - } - } + // uncheck all central widget actions + QHashIterator i(toolsMenuActions); + while (i.hasNext()) { + i.next(); + qDebug() << "shCW" << i.key() << "read"; + if (i.value() && i.value()->data().toInt() > 255){ + i.value()->setChecked(false); + + // update the settings + chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(i.value()->data().toInt()), currentView); + settings.setValue(chKey,false); + } + } - // check the current action - qDebug() << senderAction->text(); - senderAction->setChecked(true); + // check the current action + qDebug() << senderAction->text(); + senderAction->setChecked(true); - // update the central widget - centerStack->setCurrentWidget(dockWidgets[tool]); + // update the central widget + centerStack->setCurrentWidget(dockWidgets[tool]); - // store the selected central widget - chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(tool), currentView); - settings.setValue(chKey,true); + // store the selected central widget + chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(tool), currentView); + settings.setValue(chKey,true); + settings.sync(); - presentView(); - } + presentView(); + } } /** @@ -363,165 +368,195 @@ void MainWindow::showCentralWidget() * enabled last time. */ void MainWindow::addToToolsMenu ( QWidget* widget, - const QString title, - const char * slotName, - TOOLS_WIDGET_NAMES tool, - Qt::DockWidgetArea location) + const QString title, + const char * slotName, + TOOLS_WIDGET_NAMES tool, + Qt::DockWidgetArea location) { - QAction* tempAction; - QString posKey, chKey; + 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); - } + 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); + tempAction->setCheckable(true); + tempAction->setData(tool); - // populate the Hashes - toolsMenuActions[tool] = tempAction; - dockWidgets[tool] = widget; - qDebug() << widget; + // populate the Hashes + toolsMenuActions[tool] = tempAction; + dockWidgets[tool] = widget; + qDebug() << widget; - posKey = buildMenuKey (SUB_SECTION_LOCATION,tool, currentView); + posKey = buildMenuKey (SUB_SECTION_LOCATION,tool, currentView); - if (!settings.contains(posKey)){ - settings.setValue(posKey,location); - dockWidgetLocations[tool] = location; - } else { - dockWidgetLocations[tool] = static_cast (settings.value(posKey).toInt()); - } + if (!settings.contains(posKey)){ + settings.setValue(posKey,location); + dockWidgetLocations[tool] = location; + } else { + dockWidgetLocations[tool] = static_cast (settings.value(posKey).toInt()); + } - chKey = buildMenuKey(SUB_SECTION_CHECKED,tool, currentView); + chKey = buildMenuKey(SUB_SECTION_CHECKED,tool, currentView); - if (!settings.contains(chKey)) - { - settings.setValue(chKey,false); - tempAction->setChecked(false); - } - else - { - tempAction->setChecked(settings.value(chKey).toBool()); - widget->setVisible(settings.value(chKey).toBool()); - } + if (!settings.contains(chKey)) + { + settings.setValue(chKey,false); + tempAction->setChecked(false); + } + else + { + tempAction->setChecked(settings.value(chKey).toBool()); + widget->setVisible(settings.value(chKey).toBool()); + } - // connect the action - connect(tempAction,SIGNAL(triggered()),this, slotName); + // connect the action + connect(tempAction,SIGNAL(triggered()),this, slotName); - connect(qobject_cast (dockWidgets[tool]), - SIGNAL(visibilityChanged(bool)), this, SLOT(updateVisibilitySettings(bool))); + connect(qobject_cast (dockWidgets[tool]), + SIGNAL(visibilityChanged(bool)), this, SLOT(updateVisibilitySettings(bool))); - connect(qobject_cast (dockWidgets[tool]), - SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(updateLocationSettings(Qt::DockWidgetArea))); + connect(qobject_cast (dockWidgets[tool]), + SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(updateLocationSettings(Qt::DockWidgetArea))); } -void MainWindow::showToolWidget(){ - QAction* temp = qobject_cast(sender()); - int tool = temp->data().toInt(); +void MainWindow::showToolWidget() +{ + QAction* temp = qobject_cast(sender()); + int tool = temp->data().toInt(); - if (temp && dockWidgets[tool]){ - if (temp->isChecked()){ - addDockWidget(dockWidgetLocations[tool], qobject_cast (dockWidgets[tool])); - qobject_cast(dockWidgets[tool])->show(); - } else { - removeDockWidget(qobject_cast(dockWidgets[tool])); + if (temp && dockWidgets[tool]) + { + if (temp->isChecked()) + { + addDockWidget(dockWidgetLocations[tool], qobject_cast (dockWidgets[tool])); + qobject_cast(dockWidgets[tool])->show(); + } + else + { + removeDockWidget(qobject_cast(dockWidgets[tool])); + } + QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(tool), currentView); + settings.setValue(chKey,temp->isChecked()); + settings.sync(); } - QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(tool), currentView); - settings.setValue(chKey,temp->isChecked()); - } } -void MainWindow::showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view){ - bool tempVisible; - Qt::DockWidgetArea tempLocation; - QDockWidget* tempWidget = static_cast (dockWidgets[widget]); +void MainWindow::showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view) +{ + bool tempVisible; + Qt::DockWidgetArea tempLocation; + QDockWidget* tempWidget = static_cast (dockWidgets[widget]); - tempVisible = settings.value(buildMenuKey (SUB_SECTION_CHECKED,widget,view)).toBool(); + tempVisible = settings.value(buildMenuKey (SUB_SECTION_CHECKED,widget,view)).toBool(); + + if (tempWidget) + { + toolsMenuActions[widget]->setChecked(tempVisible); + } - if (tempWidget){ - toolsMenuActions[widget]->setChecked(tempVisible); - } + //qDebug() << buildMenuKey (SUB_SECTION_CHECKED,widget,view) << tempVisible; - //qDebug() << buildMenuKey (SUB_SECTION_CHECKED,widget,view) << tempVisible; + tempLocation = static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,widget, view)).toInt()); - tempLocation = static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,widget, view)).toInt()); + if (tempWidget && tempVisible) + { + addDockWidget(tempLocation, tempWidget); + tempWidget->show(); + } - if (tempWidget && 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 + int apType; + + apType = (UASManager::instance() && UASManager::instance()->silentGetActiveUAS())? + UASManager::instance()->getActiveUAS()->getAutopilotType(): + -1; + + return (QString::number(apType) + "/" + + QString::number(SECTION_MENU) + "/" + + QString::number(view) + "/" + + QString::number(tool) + "/" + + QString::number(section) + "/" ); } -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 - int apType; +void MainWindow::closeEvent(QCloseEvent *event) +{ + //settings.setValue("geometry", saveGeometry()); + //settings.setValue("windowState", saveState()); + aboutToCloseFlag = true; + settings.setValue("VIEW_ON_APPLICATION_CLOSE", currentView); + settings.sync(); + QMainWindow::closeEvent(event); +} - apType = (UASManager::instance() && UASManager::instance()->silentGetActiveUAS())? - UASManager::instance()->getActiveUAS()->getAutopilotType(): - -1; +void MainWindow::updateVisibilitySettings (bool vis) +{ + // This is commented since when the application closes + // sets the visibility to false. - return (QString::number(apType) + "/" + - QString::number(SECTION_MENU) + "/" + - QString::number(view) + "/" + - QString::number(tool) + "/" + - QString::number(section) + "/" ); -} + // TODO: A workaround is needed. The QApplication::aboutToQuit + // did not work -void MainWindow::updateVisibilitySettings (bool vis){ - Q_UNUSED(vis); - - // This is commented since when the application closes - // sets the visibility to false. - - // TODO: A workaround is needed. The QApplication::aboutToQuit - // did not work - - /* - QDockWidget* temp = qobject_cast(sender()); - - QHashIterator i(dockWidgets); - while (i.hasNext()) { - i.next(); - if ((static_cast (dockWidgets[i.key()])) == temp){ - QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(i.key())); - qDebug() << "Key in visibility changed" << chKey; - settings.setValue(chKey,vis); - toolsMenuActions[i.key()]->setChecked(vis); - break; - } - } -*/ + if (!aboutToCloseFlag) + { + + QDockWidget* temp = qobject_cast(sender()); + + if (temp) + { + QHashIterator i(dockWidgets); + while (i.hasNext()) + { + i.next(); + if ((static_cast (dockWidgets[i.key()])) == temp) + { +// QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast(i.key()), currentView); +// qDebug() << "Key in visibility changed" << chKey; +// settings.setValue(chKey,vis); +// settings.sync(); + toolsMenuActions[i.key()]->setChecked(vis); + break; + } + } + } + } } -void MainWindow::updateLocationSettings (Qt::DockWidgetArea location){ - QDockWidget* temp = qobject_cast(sender()); +void MainWindow::updateLocationSettings (Qt::DockWidgetArea location) +{ + QDockWidget* temp = qobject_cast(sender()); - QHashIterator i(dockWidgets); - while (i.hasNext()) { - i.next(); - if ((static_cast (dockWidgets[i.key()])) == temp){ - QString posKey = buildMenuKey (SUB_SECTION_LOCATION,static_cast(i.key()), currentView); - settings.setValue(posKey,location); - break; - } - } -//======= -// addDockWidget(Qt::BottomDockWidgetArea, slugsCamControlWidget); -// slugsCamControlWidget->hide(); - -// //FIXME: free memory in destructor -// joystick = new JoystickInput(); -//>>>>>>> master + QHashIterator i(dockWidgets); + while (i.hasNext()) + { + i.next(); + if ((static_cast (dockWidgets[i.key()])) == temp) + { + QString posKey = buildMenuKey (SUB_SECTION_LOCATION,static_cast(i.key()), currentView); + settings.setValue(posKey,location); + break; + } + } + //======= + // addDockWidget(Qt::BottomDockWidgetArea, slugsCamControlWidget); + // slugsCamControlWidget->hide(); + + // //FIXME: free memory in destructor + // joystick = new JoystickInput(); + //>>>>>>> master } /** @@ -571,13 +606,13 @@ void MainWindow::connectSlugsWidgets() } if (slugsHilSimWidget && slugsHilSimWidget->widget()){ - connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), - slugsHilSimWidget->widget(), SLOT(activeUasSet(UASInterface*))); + 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*))); + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), + slugsDataWidget->widget(), SLOT(setActiveUAS(UASInterface*))); } @@ -598,10 +633,10 @@ void MainWindow::arrangeCommonCenterStack() void MainWindow::arrangePxCenterStack() { - if (!centerStack) { - qDebug() << "Center Stack not Created!"; - return; - } + if (!centerStack) { + qDebug() << "Center Stack not Created!"; + return; + } if (linechartWidget) centerStack->addWidget(linechartWidget); @@ -622,15 +657,15 @@ void MainWindow::arrangePxCenterStack() void MainWindow::arrangeSlugsCenterStack() { - if (!centerStack) { - qDebug() << "Center Stack not Created!"; - return; - } + if (!centerStack) { + qDebug() << "Center Stack not Created!"; + return; + } - if (linechartWidget) centerStack->addWidget(linechartWidget); + if (linechartWidget) centerStack->addWidget(linechartWidget); - if (hudWidget) centerStack->addWidget(hudWidget); + if (hudWidget) centerStack->addWidget(hudWidget); } @@ -785,10 +820,10 @@ void MainWindow::connectCommonActions() void MainWindow::connectPxActions() { - ui.actionJoystickSettings->setVisible(true); + ui.actionJoystickSettings->setVisible(true); - // Joystick configuration - connect(ui.actionJoystickSettings, SIGNAL(triggered()), this, SLOT(configure())); + // Joystick configuration + connect(ui.actionJoystickSettings, SIGNAL(triggered()), this, SLOT(configure())); } @@ -948,58 +983,77 @@ void MainWindow::UASCreated(UASInterface* uas) // TODO Stylesheet reloading should in theory not be necessary reloadStylesheet(); - switch (uas->getAutopilotType()){ - 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(); - - // FIXME: This type checking might be redundant - // Check which type this UAS is of -// PxQuadMAV* mav = dynamic_cast(uas); -// if (mav) loadPixhawkEngineerView(); - } break; - - case (MAV_AUTOPILOT_SLUGS): - { - // Build Slugs Widgets - buildSlugsWidgets(); - - // Connect Slugs Widgets - connectSlugsWidgets(); - - // Arrange Slugs Centerstack - arrangeSlugsCenterStack(); - - // Connect Slugs Actions - connectSlugsActions(); - - // FIXME: This type checking might be redundant -// if (slugsDataWidget) { -// SlugsDataSensorView* dataWidget = dynamic_cast(slugsDataWidget->widget()); -// if (dataWidget) { -// SlugsMAV* mav2 = dynamic_cast(uas); -// if (mav2) { - (dynamic_cast(slugsDataWidget->widget()))->addUAS(uas); -// //loadSlugsView(); -// loadGlobalOperatorView(); -// } -// } -// } - } break; - - loadEngineerView(); + switch (uas->getAutopilotType()) + { + case (MAV_AUTOPILOT_SLUGS): + { + // Build Slugs Widgets + buildSlugsWidgets(); + + // Connect Slugs Widgets + connectSlugsWidgets(); + + // Arrange Slugs Centerstack + arrangeSlugsCenterStack(); + + // Connect Slugs Actions + connectSlugsActions(); + + // FIXME: This type checking might be redundant + // if (slugsDataWidget) { + // SlugsDataSensorView* dataWidget = dynamic_cast(slugsDataWidget->widget()); + // if (dataWidget) { + // SlugsMAV* mav2 = dynamic_cast(uas); + // if (mav2) { + (dynamic_cast(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 + + // If this is the first connected UAS, it is both created as well as + // the currently active UAS + if (UASManager::instance()->getActiveUAS() == uas) + { + qDebug() << "UPDATING THE VIEW SINCE THIS IS THE FIRST CONNECTED SYSTEM"; + + // Load last view if setting is present + if (settings.contains("VIEW_ON_APPLICATION_CLOSE")) + { + int view = settings.value("VIEW_ON_APPLICATION_CLOSE").toInt(); + currentView = (VIEW_SECTIONS) view; + presentView(); + } + else + { + loadEngineerView(); + } } } @@ -1065,11 +1119,11 @@ void MainWindow::clearView() void MainWindow::loadEngineerView() { - clearView(); + clearView(); - currentView = VIEW_ENGINEER; + currentView = VIEW_ENGINEER; - presentView(); + presentView(); } void MainWindow::loadOperatorView() @@ -1104,324 +1158,199 @@ void MainWindow::presentView() #ifdef QGC_OSG_ENABLED - // 3D map - if (_3DWidget) - { - if (centerStack) - { - //map3DWidget->setActive(true); - centerStack->setCurrentWidget(_3DWidget); - } - } + // 3D map + if (_3DWidget) + { + if (centerStack) + { + //map3DWidget->setActive(true); + centerStack->setCurrentWidget(_3DWidget); + } + } #endif - qDebug() << "LC"; - showTheCentralWidget(CENTRAL_LINECHART, currentView); - if (linechartWidget) - { - qDebug () << buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_LINECHART,currentView) << - settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_LINECHART,currentView)).toBool() ; - if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_LINECHART,currentView)).toBool()){ - if (centerStack) { - linechartWidget->setActive(true); - centerStack->setCurrentWidget(linechartWidget); - } - } else { - linechartWidget->setActive(false); + qDebug() << "LC"; + showTheCentralWidget(CENTRAL_LINECHART, currentView); + if (linechartWidget) + { + qDebug () << buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_LINECHART,currentView) << + settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_LINECHART,currentView)).toBool() ; + if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_LINECHART,currentView)).toBool()){ + if (centerStack) { + linechartWidget->setActive(true); + centerStack->setCurrentWidget(linechartWidget); + } + } else { + linechartWidget->setActive(false); + } } - } - // MAP - qDebug() << "MAP"; - showTheCentralWidget(CENTRAL_MAP, currentView); + // MAP + qDebug() << "MAP"; + showTheCentralWidget(CENTRAL_MAP, currentView); - // PROTOCOL - qDebug() << "CP"; - showTheCentralWidget(CENTRAL_PROTOCOL, currentView); + // PROTOCOL + qDebug() << "CP"; + showTheCentralWidget(CENTRAL_PROTOCOL, currentView); - // HEAD UP DISPLAY - showTheCentralWidget(CENTRAL_HUD, currentView); - qDebug() << "HUD"; - if (hudWidget){ - qDebug() << buildMenuKey(SUB_SECTION_CHECKED,CENTRAL_HUD,currentView) << - settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_HUD,currentView)).toBool(); - if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_HUD,currentView)).toBool()){ - if (centerStack) { - centerStack->setCurrentWidget(hudWidget); - hudWidget->start(); - } - } else { - hudWidget->stop(); + // HEAD UP DISPLAY + showTheCentralWidget(CENTRAL_HUD, currentView); + qDebug() << "HUD"; + if (hudWidget){ + qDebug() << buildMenuKey(SUB_SECTION_CHECKED,CENTRAL_HUD,currentView) << + settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_HUD,currentView)).toBool(); + if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,CENTRAL_HUD,currentView)).toBool()){ + if (centerStack) { + centerStack->setCurrentWidget(hudWidget); + hudWidget->start(); + } + } else { + hudWidget->stop(); + } } - } - // Show docked widgets based on current view and autopilot type + // Show docked widgets based on current view and autopilot type - // UAS CONTROL - showTheWidget(MENU_UAS_CONTROL, currentView); + // UAS CONTROL + showTheWidget(MENU_UAS_CONTROL, currentView); - // UAS LIST - showTheWidget(MENU_UAS_LIST, currentView); + // UAS LIST + showTheWidget(MENU_UAS_LIST, currentView); - // WAYPOINT LIST - showTheWidget(MENU_WAYPOINTS, currentView); + // WAYPOINT LIST + showTheWidget(MENU_WAYPOINTS, currentView); - // UAS STATUS - showTheWidget(MENU_STATUS, currentView); + // UAS STATUS + showTheWidget(MENU_STATUS, currentView); - // DETECTION - showTheWidget(MENU_DETECTION, currentView); + // DETECTION + showTheWidget(MENU_DETECTION, currentView); - // DEBUG CONSOLE - showTheWidget(MENU_DEBUG_CONSOLE, currentView); + // DEBUG CONSOLE + showTheWidget(MENU_DEBUG_CONSOLE, currentView); - // ONBOARD PARAMETERS - showTheWidget(MENU_PARAMETERS, currentView); + // ONBOARD PARAMETERS + showTheWidget(MENU_PARAMETERS, currentView); - // WATCHDOG - showTheWidget(MENU_WATCHDOG, currentView); + // WATCHDOG + showTheWidget(MENU_WATCHDOG, currentView); - // HUD - showTheWidget(MENU_HUD, currentView); - if (headUpDockWidget) - { - HUD* tmpHud = dynamic_cast( headUpDockWidget->widget() ); - if (tmpHud){ - if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HUD,currentView)).toBool()){ - tmpHud->start(); - addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HUD, currentView)).toInt()), - hsiDockWidget); - headUpDockWidget->show(); - } else { - tmpHud->stop(); - headUpDockWidget->hide(); + // HUD + showTheWidget(MENU_HUD, currentView); + if (headUpDockWidget) + { + HUD* tmpHud = dynamic_cast( headUpDockWidget->widget() ); + if (tmpHud){ + if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HUD,currentView)).toBool()){ + tmpHud->start(); + addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HUD, currentView)).toInt()), + hsiDockWidget); + headUpDockWidget->show(); + } else { + tmpHud->stop(); + headUpDockWidget->hide(); + } } - } - } + } - // RC View - showTheWidget(MENU_RC_VIEW, currentView); + // RC View + showTheWidget(MENU_RC_VIEW, currentView); - // SLUGS DATA - showTheWidget(MENU_SLUGS_DATA, currentView); + // SLUGS DATA + showTheWidget(MENU_SLUGS_DATA, currentView); - // SLUGS PID - showTheWidget(MENU_SLUGS_PID, currentView); + // SLUGS PID + showTheWidget(MENU_SLUGS_PID, currentView); - // SLUGS HIL - showTheWidget(MENU_SLUGS_HIL, currentView); + // SLUGS HIL + showTheWidget(MENU_SLUGS_HIL, currentView); - // SLUGS CAMERA - showTheWidget(MENU_SLUGS_CAMERA, currentView); + // SLUGS CAMERA + showTheWidget(MENU_SLUGS_CAMERA, currentView); - // HORIZONTAL SITUATION INDICATOR - showTheWidget(MENU_HSI, currentView); - if (hsiDockWidget) - { - HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); - if (hsi){ - if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HSI,currentView)).toBool()){ - hsi->start(); - addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HSI, currentView)).toInt()), - hsiDockWidget); - hsiDockWidget->show(); - } else { - hsi->stop(); - hsiDockWidget->hide(); - } - } - } - - // HEAD DOWN 1 - showTheWidget(MENU_HDD_1, currentView); - if (headDown1DockWidget) - { - HDDisplay *hdd = dynamic_cast(headDown1DockWidget->widget()); - if (hdd) { - if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HDD_1,currentView)).toBool()) { - addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HDD_1, currentView)).toInt()), - headDown1DockWidget); - headDown1DockWidget->show(); - hdd->start(); - } else { - headDown1DockWidget->hide();; - hdd->stop(); - } - } - } - - // HEAD DOWN 2 - showTheWidget(MENU_HDD_2, currentView); - if (headDown2DockWidget) - { - HDDisplay *hdd = dynamic_cast(headDown2DockWidget->widget()); - if (hdd){ - if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HDD_2,currentView)).toBool()){ - addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HDD_2, currentView)).toInt()), - headDown2DockWidget); - headDown2DockWidget->show(); - hdd->start(); - } else { - headDown2DockWidget->hide(); - hdd->stop(); + // HORIZONTAL SITUATION INDICATOR + showTheWidget(MENU_HSI, currentView); + if (hsiDockWidget) + { + HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); + if (hsi){ + if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HSI,currentView)).toBool()){ + hsi->start(); + addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HSI, currentView)).toInt()), + hsiDockWidget); + hsiDockWidget->show(); + } else { + hsi->stop(); + hsiDockWidget->hide(); + } } - } - } - - this->show(); - -} - -void MainWindow::showTheCentralWidget (TOOLS_WIDGET_NAMES centralWidget, VIEW_SECTIONS view){ - bool tempVisible; - QWidget* tempWidget = dockWidgets[centralWidget]; -//======= -// // ONBOARD PARAMETERS -// if (parametersDockWidget) -// { -// addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget); -// parametersDockWidget->show(); -// } -//} -//>>>>>>> master - - tempVisible = settings.value(buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view)).toBool(); - qDebug() << buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view) << tempVisible; - if (toolsMenuActions[centralWidget]){ - toolsMenuActions[centralWidget]->setChecked(tempVisible); - } - - if (centerStack && tempWidget && tempVisible){ - centerStack->setCurrentWidget(tempWidget); - } -} - - - -/* -========================================================== - Potentially Deprecated -========================================================== -*/ - -void MainWindow::loadPixhawkEngineerView() -{ - -} - - -void MainWindow::loadAllView() -{ - clearView(); + } + // HEAD DOWN 1 + showTheWidget(MENU_HDD_1, currentView); if (headDown1DockWidget) { HDDisplay *hdd = dynamic_cast(headDown1DockWidget->widget()); - if (hdd) - { - addDockWidget(Qt::RightDockWidgetArea, headDown1DockWidget); - headDown1DockWidget->show(); - hdd->start(); + if (hdd) { + if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HDD_1,currentView)).toBool()) { + addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HDD_1, currentView)).toInt()), + headDown1DockWidget); + headDown1DockWidget->show(); + hdd->start(); + } else { + headDown1DockWidget->hide();; + hdd->stop(); + } } - } + + // HEAD DOWN 2 + showTheWidget(MENU_HDD_2, currentView); if (headDown2DockWidget) { HDDisplay *hdd = dynamic_cast(headDown2DockWidget->widget()); - if (hdd) - { - addDockWidget(Qt::RightDockWidgetArea, headDown2DockWidget); - headDown2DockWidget->show(); - hdd->start(); + if (hdd){ + if (settings.value(buildMenuKey (SUB_SECTION_CHECKED,MENU_HDD_2,currentView)).toBool()){ + addDockWidget(static_cast (settings.value(buildMenuKey (SUB_SECTION_LOCATION,MENU_HDD_2, currentView)).toInt()), + headDown2DockWidget); + headDown2DockWidget->show(); + hdd->start(); + } else { + headDown2DockWidget->hide(); + hdd->stop(); + } } } -//<<<<<<< HEAD -//======= -//} - -//void MainWindow::loadOperatorView() -//{ -// clearView(); - -// // MAP -// if (mapWidget) -// { -// QStackedWidget *centerStack = dynamic_cast(centralWidget()); -// if (centerStack) -// { -// centerStack->setCurrentWidget(mapWidget); -// } -// } -//>>>>>>> master - // UAS CONTROL - if (controlDockWidget) - { - addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget); - controlDockWidget->show(); - } - - // UAS LIST - if (listDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, listDockWidget); - listDockWidget->show(); - } - - // UAS STATUS - if (infoDockWidget) - { - addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget); - infoDockWidget->show(); - } - - // WAYPOINT LIST - if (waypointsDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget); - waypointsDockWidget->show(); - } + this->show(); - // DEBUG CONSOLE - if (debugConsoleDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, debugConsoleDockWidget); - debugConsoleDockWidget->show(); - } +} - // OBJECT DETECTION - if (detectionDockWidget) - { - addDockWidget(Qt::RightDockWidgetArea, detectionDockWidget); - detectionDockWidget->show(); - } +void MainWindow::showTheCentralWidget (TOOLS_WIDGET_NAMES centralWidget, VIEW_SECTIONS view) +{ + bool tempVisible; + QWidget* tempWidget = dockWidgets[centralWidget]; - // LINE CHART - if (linechartWidget) + tempVisible = settings.value(buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view)).toBool(); + qDebug() << buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view) << tempVisible; + if (toolsMenuActions[centralWidget]) { - QStackedWidget *centerStack = dynamic_cast(centralWidget()); - if (centerStack) - { - linechartWidget->setActive(true); - centerStack->setCurrentWidget(linechartWidget); - } + toolsMenuActions[centralWidget]->setChecked(tempVisible); } - // ONBOARD PARAMETERS - if (parametersDockWidget) + if (centerStack && tempWidget && tempVisible) { - addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget); - parametersDockWidget->show(); + centerStack->setCurrentWidget(tempWidget); } } void MainWindow::loadWidgets() { - //loadOperatorView(); - loadMAVLinkView(); + loadOperatorView(); + //loadMAVLinkView(); //loadPilotView(); } @@ -1457,415 +1386,54 @@ void MainWindow::loadDataView(QString fileName) void MainWindow::load3DMapView() { #ifdef QGC_OSGEARTH_ENABLED - clearView(); - - // 3D map - if (_3DMapWidget) - { - QStackedWidget *centerStack = dynamic_cast(centralWidget()); - if (centerStack) - { - //map3DWidget->setActive(true); - centerStack->setCurrentWidget(_3DMapWidget); - } - } - - // UAS CONTROL - if (controlDockWidget) - { - addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget); - controlDockWidget->show(); - } - - // UAS LIST - if (listDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, listDockWidget); - listDockWidget->show(); - } - - // WAYPOINT LIST - if (waypointsDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget); - waypointsDockWidget->show(); - } + clearView(); - // HORIZONTAL SITUATION INDICATOR - if (hsiDockWidget) - { - HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); - if (hsi) - { - hsi->start(); - addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget); - hsiDockWidget->show(); - } - } + // 3D map + if (_3DMapWidget) + { + QStackedWidget *centerStack = dynamic_cast(centralWidget()); + if (centerStack) + { + //map3DWidget->setActive(true); + centerStack->setCurrentWidget(_3DMapWidget); + } + } #endif } void MainWindow::loadGoogleEarthView() { - #if (defined Q_OS_WIN) | (defined Q_OS_MAC) - clearView(); - - // 3D map - if (gEarthWidget) - { - QStackedWidget *centerStack = dynamic_cast(centralWidget()); - if (centerStack) - { - centerStack->setCurrentWidget(gEarthWidget); - } - } - - // UAS CONTROL - if (controlDockWidget) - { - addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget); - controlDockWidget->show(); - } - - // UAS LIST - if (listDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, listDockWidget); - listDockWidget->show(); - } - - // WAYPOINT LIST - if (waypointsDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget); - waypointsDockWidget->show(); - } - - // HORIZONTAL SITUATION INDICATOR - if (hsiDockWidget) - { - HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); - if (hsi) - { - hsi->start(); - addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget); - hsiDockWidget->show(); - } - } -#endif - -} - -void MainWindow::load3DView() -{ -#ifdef QGC_OSG_ENABLED - clearView(); - - // 3D map - if (_3DWidget) - { - QStackedWidget *centerStack = dynamic_cast(centralWidget()); - if (centerStack) - { - //map3DWidget->setActive(true); - centerStack->setCurrentWidget(_3DWidget); - } - } - - // UAS CONTROL - if (controlDockWidget) - { - addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget); - controlDockWidget->show(); - } - - // UAS LIST - if (listDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, listDockWidget); - listDockWidget->show(); - } - - // WAYPOINT LIST - if (waypointsDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget); - waypointsDockWidget->show(); - } - - // HORIZONTAL SITUATION INDICATOR - if (hsiDockWidget) - { - HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); - if (hsi) - { - hsi->start(); - addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget); - hsiDockWidget->show(); - } - } -#endif -} - -/* - ================================== - ========== ATTIC ================= - ================================== - -void MainWindow::buildCommonWidgets() -{ - //FIXME: memory of acceptList will never be freed again - QStringList* acceptList = new QStringList(); - acceptList->append("roll IMU"); - acceptList->append("pitch IMU"); - acceptList->append("yaw IMU"); - acceptList->append("rollspeed IMU"); - acceptList->append("pitchspeed IMU"); - acceptList->append("yawspeed IMU"); - - //FIXME: memory of acceptList2 will never be freed again - QStringList* acceptList2 = new QStringList(); - acceptList2->append("Battery"); - acceptList2->append("Pressure"); - - //TODO: move protocol outside UI - mavlink = new MAVLinkProtocol(); - - // Center widgets - linechartWidget = new Linecharts(this); - hudWidget = new HUD(320, 240, this); - mapWidget = new MapWidget(this); - protocolWidget = new XMLCommProtocolWidget(this); - dataplotWidget = new QGCDataPlot2D(this); -#ifdef QGC_OSG_ENABLED - _3DWidget = Q3DWidgetFactory::get("PIXHAWK"); -#endif - -#ifdef QGC_OSGEARTH_ENABLED - _3DMapWidget = Q3DWidgetFactory::get("MAP3D"); -#endif #if (defined Q_OS_WIN) | (defined Q_OS_MAC) - gEarthWidget = new QGCGoogleEarthView(this); -#endif - - // Dock widgets - controlDockWidget = new QDockWidget(tr("Control"), this); - controlDockWidget->setWidget( new UASControlWidget(this) ); - - listDockWidget = new QDockWidget(tr("Unmanned Systems"), this); - listDockWidget->setWidget( new UASListWidget(this) ); - -<<<<<<< HEAD - waypointsDockWidget = new QDockWidget(tr("Waypoint List"), this); - waypointsDockWidget->setWidget( new WaypointList(this, NULL) ); - - infoDockWidget = new QDockWidget(tr("Status Details"), this); - infoDockWidget->setWidget( new UASInfoWidget(this) ); -======= - // RADIO CONTROL VIEW - if (rcViewDockWidget) - { - addDockWidget(Qt::BottomDockWidgetArea, rcViewDockWidget); - rcViewDockWidget->show(); - } -} ->>>>>>> master - - detectionDockWidget = new QDockWidget(tr("Object Recognition"), this); - detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) ); - -<<<<<<< HEAD - debugConsoleDockWidget = new QDockWidget(tr("Communication Console"), this); - debugConsoleDockWidget->setWidget( new DebugConsole(this) ); - - parametersDockWidget = new QDockWidget(tr("Onboard Parameters"), this); - parametersDockWidget->setWidget( new ParameterInterface(this) ); - - watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this); - watchdogControlDockWidget->setWidget( new WatchdogControl(this) ); - - hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this); - hsiDockWidget->setWidget( new HSIDisplay(this) ); - - headDown1DockWidget = new QDockWidget(tr("Primary Flight Display"), this); - headDown1DockWidget->setWidget( new HDDisplay(acceptList, this) ); - - headDown2DockWidget = new QDockWidget(tr("Payload Status"), this); - headDown2DockWidget->setWidget( new HDDisplay(acceptList2, this) ); - - rcViewDockWidget = new QDockWidget(tr("Radio Control"), this); - rcViewDockWidget->setWidget( new QGCRemoteControlView(this) ); - - headUpDockWidget = new QDockWidget(tr("Control Indicator"), this); - headUpDockWidget->setWidget( new HUD(320, 240, this)); - - // Dialogue widgets - //FIXME: free memory in destructor - joystick = new JoystickInput(); - - slugsDataWidget = new QDockWidget(tr("Slugs Data"), this); - slugsDataWidget->setWidget( new SlugsDataSensorView(this)); - - slugsPIDControlWidget = new QDockWidget(tr("PID Control"), this); - slugsPIDControlWidget->setWidget(new SlugsPIDControl(this)); - - slugsHilSimWidget = new QDockWidget(tr("Slugs Hil Sim"), this); - slugsHilSimWidget->setWidget( new SlugsHilSim(this)); - - slugsCamControlWidget = new QDockWidget(tr("Video Camera Control"), this); - slugsCamControlWidget->setWidget(new SlugsVideoCamControl(this)); + clearView(); -======= - if (protocolWidget) + // 3D map + if (gEarthWidget) { QStackedWidget *centerStack = dynamic_cast(centralWidget()); if (centerStack) { - centerStack->setCurrentWidget(protocolWidget); + centerStack->setCurrentWidget(gEarthWidget); } } ->>>>>>> master -} - -void MainWindow::connectWidgets() -{ - if (linechartWidget) - { - connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), - linechartWidget, SLOT(addSystem(UASInterface*))); - connect(UASManager::instance(), SIGNAL(activeUASSet(int)), - linechartWidget, SLOT(selectSystem(int))); - connect(linechartWidget, SIGNAL(logfileWritten(QString)), - this, SLOT(loadDataView(QString))); - } - if (infoDockWidget && infoDockWidget->widget()) - { - connect(mavlink, SIGNAL(receiveLossChanged(int, float)), - infoDockWidget->widget(), SLOT(updateSendLoss(int, float))); - } - if (mapWidget && waypointsDockWidget->widget()) - { - // clear path create on the map - connect(waypointsDockWidget->widget(), SIGNAL(clearPathclicked()), mapWidget, SLOT(clearPath())); - // add Waypoint widget in the WaypointList widget when mouse clicked - connect(mapWidget, SIGNAL(captureMapCoordinateClick(QPointF)), waypointsDockWidget->widget(), SLOT(addWaypointMouse(QPointF))); - // it notifies that a waypoint global goes to do create - //connect(mapWidget, SIGNAL(createGlobalWP(bool, QPointF)), waypointsDockWidget->widget(), SLOT(setIsWPGlobal(bool, QPointF))); - //connect(mapWidget, SIGNAL(sendGeometryEndDrag(QPointF,int)), waypointsDockWidget->widget(), SLOT(waypointGlobalChanged(QPointF,int)) ); - - // it notifies that a waypoint global goes to do create and a map graphic too - connect(waypointsDockWidget->widget(), SIGNAL(createWaypointAtMap(QPointF)), mapWidget, SLOT(createWaypointGraphAtMap(QPointF))); - // it notifies that a waypoint global change it¥s position by spinBox on Widget WaypointView - //connect(waypointsDockWidget->widget(), SIGNAL(changePositionWPGlobalBySpinBox(int,float,float)), mapWidget, SLOT(changeGlobalWaypointPositionBySpinBox(int,float,float))); - // connect(waypointsDockWidget->widget(), SIGNAL(changePositionWPGlobalBySpinBox(int,float,float)), mapWidget, SLOT(changeGlobalWaypointPositionBySpinBox(int,float,float))); - - connect(slugsCamControlWidget->widget(),SIGNAL(viewCamBorderAtMap(bool)),mapWidget,SLOT(drawBorderCamAtMap(bool))); - connect(slugsCamControlWidget->widget(),SIGNAL(changeCamPosition(double,double,QString)),mapWidget,SLOT(updateCameraPosition(double,double, QString))); - } - - 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*))); - } - +#endif } -<<<<<<< HEAD -void MainWindow::arrangeCommonCenterStack() +void MainWindow::load3DView() { - - QStackedWidget *centerStack = new QStackedWidget(this); - if (!centerStack) return; - if (linechartWidget) centerStack->addWidget(linechartWidget); - if (protocolWidget) centerStack->addWidget(protocolWidget); - if (mapWidget) centerStack->addWidget(mapWidget); #ifdef QGC_OSG_ENABLED - if (_3DWidget) centerStack->addWidget(_3DWidget); -#endif -#ifdef QGC_OSGEARTH_ENABLED - if (_3DMapWidget) centerStack->addWidget(_3DMapWidget); -#endif -#if (defined Q_OS_WIN) | (defined Q_OS_MAC) - if (gEarthWidget) centerStack->addWidget(gEarthWidget); -#endif - if (hudWidget) centerStack->addWidget(hudWidget); - if (dataplotWidget) centerStack->addWidget(dataplotWidget); + clearView(); - setCentralWidget(centerStack); -======= - // ONBOARD PARAMETERS - if (parametersDockWidget) + // 3D map + if (_3DWidget) { - addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget); - parametersDockWidget->show(); + QStackedWidget *centerStack = dynamic_cast(centralWidget()); + if (centerStack) + { + //map3DWidget->setActive(true); + centerStack->setCurrentWidget(_3DWidget); + } } ->>>>>>> master -} - -void MainWindow::connectActions() -{ -<<<<<<< HEAD - // Connect actions from ui - connect(ui.actionAdd_Link, SIGNAL(triggered()), this, SLOT(addLink())); - - // Connect internal actions - connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(UASCreated(UASInterface*))); - - // Connect user interface controls - connect(ui.actionLiftoff, SIGNAL(triggered()), UASManager::instance(), SLOT(launchActiveUAS())); - connect(ui.actionLand, SIGNAL(triggered()), UASManager::instance(), SLOT(returnActiveUAS())); - connect(ui.actionEmergency_Land, SIGNAL(triggered()), UASManager::instance(), SLOT(stopActiveUAS())); - connect(ui.actionEmergency_Kill, SIGNAL(triggered()), UASManager::instance(), SLOT(killActiveUAS())); - - connect(ui.actionConfiguration, SIGNAL(triggered()), UASManager::instance(), SLOT(configureActiveUAS())); - - // User interface actions - connect(ui.actionPilotView, SIGNAL(triggered()), this, SLOT(loadPilotView())); - connect(ui.actionEngineerView, SIGNAL(triggered()), this, SLOT(loadEngineerView())); - connect(ui.actionOperatorView, SIGNAL(triggered()), this, SLOT(loadOperatorView())); -#ifdef QGC_OSG_ENABLED - connect(ui.action3DView, SIGNAL(triggered()), this, SLOT(load3DView())); -#else - ui.menuWindow->removeAction(ui.action3DView); #endif - -#ifdef QGC_OSGEARTH_ENABLED - connect(ui.action3DMapView, SIGNAL(triggered()), this, SLOT(load3DMapView())); -#else - ui.menuWindow->removeAction(ui.action3DMapView); -#endif - connect(ui.actionShow_full_view, SIGNAL(triggered()), this, SLOT(loadAllView())); - connect(ui.actionShow_MAVLink_view, SIGNAL(triggered()), this, SLOT(loadMAVLinkView())); - connect(ui.actionShow_data_analysis_view, SIGNAL(triggered()), this, SLOT(loadDataView())); - connect(ui.actionStyleConfig, SIGNAL(triggered()), this, SLOT(reloadStylesheet())); - connect(ui.actionGlobalOperatorView, SIGNAL(triggered()), this, SLOT(loadGlobalOperatorView())); - connect(ui.actionOnline_documentation, SIGNAL(triggered()), this, SLOT(showHelp())); - connect(ui.actionCredits_Developers, SIGNAL(triggered()), this, SLOT(showCredits())); - connect(ui.actionProject_Roadmap, SIGNAL(triggered()), this, SLOT(showRoadMap())); -#if (defined Q_OS_WIN) | (defined Q_OS_MAC) - connect(ui.actionGoogleEarthView, SIGNAL(triggered()), this, SLOT(loadGoogleEarthView())); -#else - ui.menuWindow->removeAction(ui.actionGoogleEarthView); -#endif - - // Joystick configuration - connect(ui.actionJoystickSettings, SIGNAL(triggered()), this, SLOT(configure())); - - // Slugs View - connect(ui.actionShow_Slugs_View, SIGNAL(triggered()), this, SLOT(loadSlugsView())); - - //GlobalOperatorView - // connect(ui.actionGlobalOperatorView,SIGNAL(triggered()),waypointsDockWidget->widget(),SLOT()) - -======= - //loadEngineerView(); ->>>>>>> master } -*/ diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index be8b3184f..4cc664427 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -138,17 +138,14 @@ public slots: /** @brief Reload the CSS style sheet */ void reloadStylesheet(); + void closeEvent(QCloseEvent* event); + /* ========================================================== Potentially Deprecated ========================================================== */ - void loadPixhawkEngineerView(); - - /** @brief Load view with all widgets */ - void loadAllView(); - void loadWidgets(); /** @brief Load data view, allowing to plot flight data */ @@ -228,13 +225,15 @@ protected: }TOOLS_WIDGET_NAMES; - typedef enum _SETTINGS_SECTIONS { + 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_OPERATOR, VIEW_PILOT, @@ -301,6 +300,7 @@ protected: /** @brief Keeps track of the current view */ VIEW_SECTIONS currentView; + bool aboutToCloseFlag; QStatusBar* statusBar; QStatusBar* createStatusBar(); -- 2.22.0