From e833fe467d735b60d4e666089aa8df7a30a157b6 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 25 Nov 2014 12:03:14 -0800 Subject: [PATCH 1/2] Only reset if file is open --- src/ui/QGCMAVLinkLogPlayer.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/QGCMAVLinkLogPlayer.cc b/src/ui/QGCMAVLinkLogPlayer.cc index e4b39a5..46ff760 100644 --- a/src/ui/QGCMAVLinkLogPlayer.cc +++ b/src/ui/QGCMAVLinkLogPlayer.cc @@ -1,4 +1,3 @@ -#include #include #include @@ -136,7 +135,9 @@ void QGCMAVLinkLogPlayer::reset() { pause(); loopCounter = 0; - logFile.reset(); + if (logFile.isOpen()) { + logFile.reset(); + } // Now update the position slider to its default location updatePositionSliderUi(0.0); From db7b86fbbeb1059ca3665986198b3cfc638da2e1 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 25 Nov 2014 12:04:45 -0800 Subject: [PATCH 2/2] Use new QGCMessageBox apis Subclass of QMessageBox which re-implements the static public functions. There are two reasons for this: 1) The QMessageBox implementation on OSX does now show the title string. This leads to message boxes which don't make much sense. So on OSX we set title to text and text to informative text. 2) If parent is NULL, we set parent to MainWindow::instance. This prevents message boxes which can go behind MainWindow --- qgroundcontrol.pro | 3 +- src/QGCCore.cc | 18 ++---- src/QGCMessageBox.h | 79 ++++++++++++++++++++++++ src/comm/LinkManager.cc | 7 +-- src/comm/MAVLinkProtocol.cc | 1 - src/comm/OpalRT.cc | 6 +- src/comm/OpalRT.h | 1 - src/comm/QGCFlightGearLink.cc | 1 + src/input/Mouse6dofInput.cpp | 36 +++++------ src/uas/QGCUASParamManager.cc | 7 +-- src/uas/UAS.cc | 58 ++++++----------- src/uas/UASManager.cc | 5 +- src/ui/MAVLinkSettingsWidget.cc | 1 - src/ui/MainWindow.cc | 20 +++--- src/ui/QGCDataPlot2D.cc | 45 +++----------- src/ui/QGCPX4VehicleConfig.cc | 32 ---------- src/ui/QGCPX4VehicleConfig.h | 2 - src/ui/QGCParamWidget.cc | 1 - src/ui/QGCSettingsWidget.cc | 15 +++-- src/ui/QGCUASFileView.cc | 1 - src/ui/WaypointList.cc | 1 - src/ui/configuration/terminalconsole.cpp | 8 +-- src/ui/linechart/LinechartWidget.cc | 36 ++++------- src/ui/map/QGCMapWidget.cc | 16 ++--- src/ui/map3D/Pixhawk3DWidget.cc | 7 +-- src/ui/px4_configuration/PX4FirmwareUpgrade.cc | 4 +- src/ui/px4_configuration/PX4RCCalibration.cc | 8 +-- src/ui/px4_configuration/QGCPX4AirframeConfig.cc | 29 +++------ 28 files changed, 195 insertions(+), 253 deletions(-) create mode 100644 src/QGCMessageBox.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index a9e8a18..80e5ab7 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -487,7 +487,8 @@ HEADERS += \ src/uas/QGCUASWorker.h \ src/CmdLineOptParser.h \ src/uas/QGXPX4UAS.h \ - src/QGCFileDialog.h + src/QGCFileDialog.h \ + src/QGCMessageBox.h SOURCES += \ src/main.cc \ diff --git a/src/QGCCore.cc b/src/QGCCore.cc index 9a100c6..77a2022 100644 --- a/src/QGCCore.cc +++ b/src/QGCCore.cc @@ -47,6 +47,7 @@ #include "MainWindow.h" #include "GAudioOutput.h" #include "CmdLineOptParser.h" +#include "QGCMessageBox.h" #ifdef QGC_RTLAB_ENABLED #include "OpalLink.h" @@ -245,19 +246,12 @@ bool QGCApplication::init(void) // Check if link could be connected if (udpLink && !LinkManager::instance()->connectLink(udpLink)) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("Could not connect UDP port. Is an instance of " + qAppName() + "already running?"); - msgBox.setInformativeText("It is recommended to close the application and stop all instances. Click Yes to close."); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - int ret = msgBox.exec(); - - // Close the message box shortly after the click to prevent accidental clicks - QTimer::singleShot(15000, &msgBox, SLOT(reject())); - + QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Could not connect UDP port. Is an instance of %1 already running?").arg(qAppName()), + tr("It is recommended to close the application and stop all instances. Click Yes to close."), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); // Exit application - if (ret == QMessageBox::Yes) + if (button == QMessageBox::Yes) { //mainWindow->close(); QTimer::singleShot(200, _mainWindow, SLOT(close())); diff --git a/src/QGCMessageBox.h b/src/QGCMessageBox.h new file mode 100644 index 0000000..4c16a5d --- /dev/null +++ b/src/QGCMessageBox.h @@ -0,0 +1,79 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2014 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef QGCMESSAGEBOX_H +#define QGCMESSAGEBOX_H + +#include + +#include "MainWindow.h" + +/// @file +/// @brief Subclass of QMessageBox which re-implements the static public functions. There are two reasons for this: +/// 1) The QMessageBox implementation on OSX does now show the title string. This leads to message +/// boxes which don't make much sense. So on OSX we set title to text and text to informative text. +/// 2) If parent is NULL, we set parent to MainWindow::instance +/// @author Don Gagne + +class QGCMessageBox : public QMessageBox { + +public: + static StandardButton critical(const QString& title, const QString& text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, QWidget* parent = NULL) + { return _messageBox(QMessageBox::Critical, title, text, buttons, defaultButton, parent); } + + static StandardButton information(const QString & title, const QString& text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, QWidget* parent = NULL) + { return _messageBox(QMessageBox::Information, title, text, buttons, defaultButton, parent); } + + static StandardButton question(const QString& title, const QString& text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, QWidget* parent = NULL) + { return _messageBox(QMessageBox::Question, title, text, buttons, defaultButton, parent); } + + static StandardButton warning(const QString& title, const QString& text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, QWidget* parent = NULL) + { return _messageBox(QMessageBox::Warning, title, text, buttons, defaultButton, parent); } + +private: +#ifdef Q_OS_MAC + static StandardButton _messageBox(Icon icon, const QString& title, const QString& text, StandardButtons buttons, StandardButton defaultButton, QWidget* parent) + { + if (parent == NULL) { + parent = MainWindow::instance(); + } + QString emptyTitle; + QMessageBox box(icon, emptyTitle, title, buttons, parent); + box.setDefaultButton(defaultButton); + box.setInformativeText(text); + return static_cast(box.exec()); + } +#else + static StandardButton _messageBox(Icon icon, const QString& title, const QString& text, StandardButtons buttons, StandardButton defaultButton, QWidget* parent) + { + if (parent == NULL) { + parent = MainWindow::instance(); + } + QMessageBox box(icon, title, text, buttons, parent); + box.setDefaultButton(defaultButton); + return static_cast(box.exec()); + } +#endif +}; + +#endif diff --git a/src/comm/LinkManager.cc b/src/comm/LinkManager.cc index 129e40b..15aa623 100644 --- a/src/comm/LinkManager.cc +++ b/src/comm/LinkManager.cc @@ -31,11 +31,11 @@ This file is part of the QGROUNDCONTROL project #include #include -#include #include #include "LinkManager.h" #include "MainWindow.h" +#include "QGCMessageBox.h" LinkManager* LinkManager::instance() { @@ -284,9 +284,8 @@ const QList LinkManager::getSerialLinks() bool LinkManager::_connectionsSuspendedMsg(void) { if (_connectionsSuspended) { - QMessageBox::information(MainWindow::instance(), - tr("Connect not allowed"), - tr("Connect not allowed: %1").arg(_connectionsSuspendedReason)); + QGCMessageBox::information(tr("Connect not allowed"), + tr("Connect not allowed: %1").arg(_connectionsSuspendedReason)); return true; } else { return false; diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index d1300db..34f556a 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/src/comm/OpalRT.cc b/src/comm/OpalRT.cc index 1396872..16cdee5 100644 --- a/src/comm/OpalRT.cc +++ b/src/comm/OpalRT.cc @@ -1,4 +1,5 @@ #include "OpalRT.h" +#include "QGCMessageBox.h" namespace OpalRT { @@ -7,10 +8,7 @@ void OpalErrorMsg::displayLastErrorMsg() { static QString lastErrorMsg; setLastErrorMsg(); - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText(lastErrorMsg); - msgBox.exec(); + QGCMessageBox::critical(QString(), lastErrorMsg); } void OpalErrorMsg::setLastErrorMsg() diff --git a/src/comm/OpalRT.h b/src/comm/OpalRT.h index 0afc234..7920c01 100644 --- a/src/comm/OpalRT.h +++ b/src/comm/OpalRT.h @@ -31,7 +31,6 @@ This file is part of the QGROUNDCONTROL project #define OPALRT_H #include -#include #include "OpalApi.h" diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index b49ef8c..d12a9b5 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -35,6 +35,7 @@ This file is part of the QGROUNDCONTROL project #include #include #include +#include #include diff --git a/src/input/Mouse6dofInput.cpp b/src/input/Mouse6dofInput.cpp index 233be84..7ae8e3e 100644 --- a/src/input/Mouse6dofInput.cpp +++ b/src/input/Mouse6dofInput.cpp @@ -9,9 +9,9 @@ #include "Mouse6dofInput.h" #include "UAS.h" #include "UASManager.h" -#include "QMessageBox" +#include "QGCMessageBox.h" -#ifdef QGC_MOUSE_ENABLED_LINUX +#ifdef QGC_MOUSE_ENABLED_LINUX #include #include #ifdef Success @@ -21,9 +21,9 @@ extern "C" { #include "xdrvlib.h" } -#endif // QGC_MOUSE_ENABLED_LINUX +#endif // QGC_MOUSE_ENABLED_LINUX -#ifdef QGC_MOUSE_ENABLED_WIN +#ifdef QGC_MOUSE_ENABLED_WIN Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) : mouse3DMax(0.075), // TODO: check maximum value fot plugged device uas(NULL), @@ -45,9 +45,9 @@ Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) : //connect(mouseInput, SIGNAL(On3dmouseKeyUp(int)), this, SLOT(FUNCTION(int))); } -#endif //QGC_MOUSE_ENABLED_WIN +#endif //QGC_MOUSE_ENABLED_WIN -#ifdef QGC_MOUSE_ENABLED_LINUX +#ifdef QGC_MOUSE_ENABLED_LINUX Mouse6dofInput::Mouse6dofInput(QWidget* parent) : mouse3DMax(350.0), // TODO: check maximum value fot plugged device uas(NULL), @@ -86,14 +86,8 @@ Mouse6dofInput::Mouse6dofInput(QWidget* parent) : } if ( !MagellanInit( display, parent->winId() ) ) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Information); - msgBox.setText(tr("No 3DxWare driver is running.")); - msgBox.setInformativeText(tr("Enter in Terminal 'sudo /etc/3DxWare/daemon/3dxsrv -d usb' and then restart QGroundControl.")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); - + QGCMessageBox::critical(tr("No 3DxWare driver is running."), + tr("Enter in Terminal 'sudo /etc/3DxWare/daemon/3dxsrv -d usb' and then restart QGroundControl.")); qDebug() << "No 3DxWare driver is running!"; return; } @@ -109,7 +103,7 @@ Mouse6dofInput::Mouse6dofInput(QWidget* parent) : } } -#endif //QGC_MOUSE_ENABLED_LINUX +#endif //QGC_MOUSE_ENABLED_LINUX Mouse6dofInput::~Mouse6dofInput() @@ -191,7 +185,7 @@ void Mouse6dofInput::run() } } -#ifdef QGC_MOUSE_ENABLED_WIN +#ifdef QGC_MOUSE_ENABLED_WIN void Mouse6dofInput::motion3DMouse(std::vector &motionData) { if (motionData.size() < 6) return; @@ -220,9 +214,9 @@ void Mouse6dofInput::motion3DMouse(std::vector &motionData) //qDebug() << "NEW 3D MOUSE VALUES -- X" << xValue << " -- Y" << yValue << " -- Z" << zValue << " -- A" << aValue << " -- B" << bValue << " -- C" << cValue; } -#endif //QGC_MOUSE_ENABLED_WIN +#endif //QGC_MOUSE_ENABLED_WIN -#ifdef QGC_MOUSE_ENABLED_WIN +#ifdef QGC_MOUSE_ENABLED_WIN void Mouse6dofInput::button3DMouseDown(int button) { switch(button) @@ -245,9 +239,9 @@ void Mouse6dofInput::button3DMouseDown(int button) break; } } -#endif //QGC_MOUSE_ENABLED_WIN +#endif //QGC_MOUSE_ENABLED_WIN -#ifdef QGC_MOUSE_ENABLED_LINUX +#ifdef QGC_MOUSE_ENABLED_LINUX void Mouse6dofInput::handleX11Event(XEvent *event) { //qDebug("XEvent occured..."); @@ -327,4 +321,4 @@ void Mouse6dofInput::handleX11Event(XEvent *event) } } } -#endif //QGC_MOUSE_ENABLED_LINUX +#endif //QGC_MOUSE_ENABLED_LINUX diff --git a/src/uas/QGCUASParamManager.cc b/src/uas/QGCUASParamManager.cc index 3f19abc..d4a865d 100644 --- a/src/uas/QGCUASParamManager.cc +++ b/src/uas/QGCUASParamManager.cc @@ -2,9 +2,9 @@ #include #include -#include #include "UASInterface.h" +#include "QGCMessageBox.h" QGCUASParamManager::QGCUASParamManager(QObject *parent) : QGCUASParamManagerInterface(parent), @@ -193,9 +193,8 @@ void QGCUASParamManager::copyVolatileParamsToPersistent() int changedParamCount = paramDataModel.countPendingParams(); if (changedParamCount > 0) { - QMessageBox msgBox; - msgBox.setText(tr("There are locally changed parameters. Please transmit them first () or update them with the onboard values () before storing onboard from RAM to ROM.")); - msgBox.exec(); + QGCMessageBox::warning(tr("Warning"), + tr("There are locally changed parameters. Please transmit them first () or update them with the onboard values () before storing onboard from RAM to ROM.")); } else { paramCommsMgr.writeParamsToPersistentStorage(); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index aca75e9..0990af2 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -10,13 +10,14 @@ */ #include -#include #include #include #include #include + #include #include + #include "UAS.h" #include "LinkInterface.h" #include "UASManager.h" @@ -29,6 +30,7 @@ #include "UASParameterCommsMgr.h" #include #include "AutoPilotPlugin.h" +#include "QGCMessageBox.h" /** * Gets the settings from the previous UAS (name, airframe, autopilot, battery specs) @@ -1404,19 +1406,11 @@ void UAS::setHomePosition(double lat, double lon, double alt) tr("UAS") + QString::number(getUASID()) : getUASName(); - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Warning); - msgBox.setText(tr("Set a new home position for vehicle %1").arg(uasName)); - msgBox.setInformativeText("Do you want to set a new origin? Waypoints defined in the local frame will be shifted in their physical location"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - - // Close the message box shortly after the click to prevent accidental clicks - QTimer::singleShot(5000, &msgBox, SLOT(reject())); - - - if (ret == QMessageBox::Yes) + QMessageBox::StandardButton button = QGCMessageBox::question(tr("Set a new home position for vehicle %1").arg(uasName), + tr("Do you want to set a new origin? Waypoints defined in the local frame will be shifted in their physical location"), + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + if (button == QMessageBox::Yes) { mavlink_message_t msg; mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), 0, MAV_CMD_DO_SET_HOME, 1, 0, 0, 0, 0, lat, lon, alt); @@ -1442,19 +1436,11 @@ void UAS::setHomePosition(double lat, double lon, double alt) **/ void UAS::setLocalOriginAtCurrentGPSPosition() { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Warning); - msgBox.setText("Set the home position at the current GPS position?"); - msgBox.setInformativeText("Do you want to set a new origin? Waypoints defined in the local frame will be shifted in their physical location"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - - // Close the message box shortly after the click to prevent accidental clicks - QTimer::singleShot(5000, &msgBox, SLOT(reject())); - - - if (ret == QMessageBox::Yes) + QMessageBox::StandardButton button = QGCMessageBox::question(tr("Set the home position at the current GPS position?"), + tr("Do you want to set a new origin? Waypoints defined in the local frame will be shifted in their physical location"), + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + if (button == QMessageBox::Yes) { mavlink_message_t msg; mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), 0, MAV_CMD_DO_SET_HOME, 1, 1, 0, 0, 0, 0, 0, 0); @@ -3204,19 +3190,11 @@ void UAS::stopHil() void UAS::shutdown() { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("Shutting down the UAS"); - msgBox.setInformativeText("Do you want to shut down the onboard computer?"); - - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - - // Close the message box shortly after the click to prevent accidental clicks - QTimer::singleShot(5000, &msgBox, SLOT(reject())); - - if (ret == QMessageBox::Yes) + QMessageBox::StandardButton button = QGCMessageBox::question(tr("Shutting down the UAS"), + tr("Do you want to shut down the onboard computer?"), + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + if (button == QMessageBox::Yes) { // If the active UAS is set, execute command mavlink_message_t msg; diff --git a/src/uas/UASManager.cc b/src/uas/UASManager.cc index 79c8ac3..e2e71fb 100644 --- a/src/uas/UASManager.cc +++ b/src/uas/UASManager.cc @@ -10,13 +10,14 @@ #include #include -#include #include #include + #include "UAS.h" #include "UASInterface.h" #include "UASManager.h" #include "QGC.h" +#include "QGCMessageBox.h" #define PI 3.1415926535897932384626433832795 #define MEAN_EARTH_DIAMETER 12756274.0 @@ -308,7 +309,7 @@ void UASManager::addUAS(UASInterface* uas) setActiveUAS(uas); if (offlineUASWaypointManager->getWaypointEditableList().size() > 0) { - if (QMessageBox::question(0,"Question","Do you want to append the offline waypoints to the ones currently on the UAV?",QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) + if (QGCMessageBox::question(tr("Question"), tr("Do you want to append the offline waypoints to the ones currently on the UAV?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { //Need to transfer all waypoints from the offline mode WPManager to the online mode. for (int i=0;igetWaypointEditableList().size();i++) diff --git a/src/ui/MAVLinkSettingsWidget.cc b/src/ui/MAVLinkSettingsWidget.cc index bbadd89..6bffe32 100644 --- a/src/ui/MAVLinkSettingsWidget.cc +++ b/src/ui/MAVLinkSettingsWidget.cc @@ -28,7 +28,6 @@ This file is part of the QGROUNDCONTROL project */ #include -#include #include #include "MAVLinkSettingsWidget.h" diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index e5f87c5..0dbe028 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -30,7 +30,6 @@ This file is part of the QGROUNDCONTROL project #include #include #include -#include #include #include #include @@ -73,6 +72,7 @@ This file is part of the QGROUNDCONTROL project #include "QGCUASFileViewMulti.h" #include "QGCCore.h" #include "QGCFileDialog.h" +#include "QGCMessageBox.h" #ifdef QGC_OSG_ENABLED #include "Q3DWidgetFactory.h" @@ -1131,14 +1131,14 @@ void MainWindow::showCriticalMessage(const QString& title, const QString& messag { _hideSplashScreen(); qDebug() << "Critical" << title << message; - QMessageBox::critical(this, title, message); + QGCMessageBox::critical(title, message); } void MainWindow::showInfoMessage(const QString& title, const QString& message) { _hideSplashScreen(); qDebug() << "Information" << title << message; - QMessageBox::information(this, title, message); + QGCMessageBox::information(title, message); } /** @@ -1676,15 +1676,11 @@ void MainWindow::handleMisconfiguration(UASInterface* uas) _hideSplashScreen(); // Ask user if he wants to handle this now - QMessageBox msgBox(this); - msgBox.setIcon(QMessageBox::Information); - msgBox.setText(tr("Missing or Invalid Onboard Configuration")); - msgBox.setInformativeText(tr("The onboard system configuration is missing or incomplete. Do you want to resolve this now?")); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Ok); - int val = msgBox.exec(); - - if (val == QMessageBox::Ok) { + QMessageBox::StandardButton button = QGCMessageBox::question(tr("Missing or Invalid Onboard Configuration"), + tr("The onboard system configuration is missing or incomplete. Do you want to resolve this now?"), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Ok); + if (button == QMessageBox::Ok) { // He wants to handle it, make sure this system is selected UASManager::instance()->setActiveUAS(uas); diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 38a3995..8511420 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -29,7 +29,6 @@ This file is part of the QGROUNDCONTROL project */ #include -#include #include #include #include @@ -45,6 +44,7 @@ This file is part of the QGROUNDCONTROL project #include "MG.h" #include "MainWindow.h" #include "QGCFileDialog.h" +#include "QGCMessageBox.h" QGCDataPlot2D::QGCDataPlot2D(QWidget *parent) : QWidget(parent), @@ -130,14 +130,14 @@ void QGCDataPlot2D::savePlot() } while(!(fileName.endsWith(".svg") || fileName.endsWith(".pdf"))) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("Unsuitable file extension for PDF or SVG"); - msgBox.setInformativeText("Please choose .pdf or .svg as file extension. Click OK to change the file extension, cancel to not save the file."); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Ok); + QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for PDF or SVG"), + tr("Please choose .pdf or .svg as file extension. Click OK to change the file extension, cancel to not save the file."), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Ok); // Abort if cancelled - if(msgBox.exec() == QMessageBox::Cancel) return; + if (button == QMessageBox::Cancel) { + return; + } fileName = QGCFileDialog::getSaveFileName( this, "Export File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), "PDF Documents (*.pdf);;SVG Images (*.svg)"); @@ -279,13 +279,8 @@ void QGCDataPlot2D::selectFile() QFileInfo fileInfo(fileName); if (!fileInfo.isReadable()) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("Could not open file"); - msgBox.setInformativeText(tr("The file is owned by user %1. Is the file currently used by another program?").arg(fileInfo.owner())); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); + QGCMessageBox::critical(tr("Could not open file"), + tr("The file is owned by user %1. Is the file currently used by another program?").arg(fileInfo.owner())); ui->filenameLabel->setText(tr("Could not open %1").arg(fileInfo.baseName()+"."+fileInfo.completeSuffix())); } else @@ -705,26 +700,6 @@ void QGCDataPlot2D::saveCsvLog() fileName.append(".csv"); } - // QFileInfo fileInfo(fileName); - // - // // Check if we could create a new file in this directory - // QDir dir(fileInfo.absoluteDir()); - // QFileInfo dirInfo(dir); - // - // while(!(dirInfo.isWritable())) - // { - // QMessageBox msgBox; - // msgBox.setIcon(QMessageBox::Critical); - // msgBox.setText("File cannot be written, Operating System denies permission"); - // msgBox.setInformativeText("Please choose a different file name or directory. Click OK to change the file, cancel to not save the file."); - // msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - // msgBox.setDefaultButton(QMessageBox::Ok); - // if(msgBox.exec() == QMessageBox::Cancel) break; - // fileName = QGCFileDialog::getSaveFileName( - // this, "Export CSV File Name", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), - // "CSV file (*.csv);;Text file (*.txt)"); - // } - bool success = logFile->copy(fileName); qDebug() << "Saved CSV log. Success: " << success; diff --git a/src/ui/QGCPX4VehicleConfig.cc b/src/ui/QGCPX4VehicleConfig.cc index e57d61d..c90d9c2 100644 --- a/src/ui/QGCPX4VehicleConfig.cc +++ b/src/ui/QGCPX4VehicleConfig.cc @@ -10,7 +10,6 @@ #include #include #include -#include #include #include "QGCPX4VehicleConfig.h" @@ -152,37 +151,6 @@ void QGCPX4VehicleConfig::firmwareMenuButtonClicked() ui->tabTitleLabel->setText(tr("Firmware Upgrade")); } -#if 0 -void QGCPX4VehicleConfig::toggleSpektrumPairing(bool enabled) -{ - Q_UNUSED(enabled); - - if (!ui->dsm2RadioButton->isChecked() && !ui->dsmxRadioButton->isChecked() - && !ui->dsmx8RadioButton->isChecked()) { - // Reject - QMessageBox warnMsgBox; - warnMsgBox.setText(tr("Please select a Spektrum Protocol Version")); - warnMsgBox.setInformativeText(tr("Please select either DSM2 or DSM-X\ndirectly below the pair button,\nbased on the receiver type.")); - warnMsgBox.setStandardButtons(QMessageBox::Ok); - warnMsgBox.setDefaultButton(QMessageBox::Ok); - (void)warnMsgBox.exec(); - return; - } - - UASInterface* mav = UASManager::instance()->getActiveUAS(); - if (mav) { - int rxSubType; - if (ui->dsm2RadioButton->isChecked()) - rxSubType = 0; - else if (ui->dsmxRadioButton->isChecked()) - rxSubType = 1; - else // if (ui->dsmx8RadioButton->isChecked()) - rxSubType = 2; - mav->pairRX(0, rxSubType); - } -} -#endif - void QGCPX4VehicleConfig::menuButtonClicked() { QPushButton *button = qobject_cast(sender()); diff --git a/src/ui/QGCPX4VehicleConfig.h b/src/ui/QGCPX4VehicleConfig.h index 1ea9b17..1009cab 100644 --- a/src/ui/QGCPX4VehicleConfig.h +++ b/src/ui/QGCPX4VehicleConfig.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "QGCToolWidget.h" @@ -78,7 +77,6 @@ protected: QPixmap planeSide; QGCPX4SensorCalibration* px4SensorCalibration; PX4RCCalibration* px4RCCalibration; - QMessageBox msgBox; QGraphicsScene scene; QPushButton* skipActionButton; diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index f4f3ee4..a995726 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -33,7 +33,6 @@ This file is part of the QGROUNDCONTROL project #include #include -#include #include #include #include diff --git a/src/ui/QGCSettingsWidget.cc b/src/ui/QGCSettingsWidget.cc index d48a4f6..7c8e6c2 100644 --- a/src/ui/QGCSettingsWidget.cc +++ b/src/ui/QGCSettingsWidget.cc @@ -35,6 +35,7 @@ #include "GAudioOutput.h" #include "QGCCore.h" #include "QGCFileDialog.h" +#include "QGCMessageBox.h" SettingsDialog::SettingsDialog(JoystickInput *joystick, QWidget *parent, Qt::WindowFlags flags) : QDialog(parent, flags), @@ -122,11 +123,10 @@ void SettingsDialog::selectCustomMode(int mode) void SettingsDialog::_deleteSettingsToggled(bool checked) { if (checked){ - QMessageBox::StandardButton answer = QMessageBox::question(this, - tr("Delete Settings"), - tr("All saved settings will be deleted the next time you start QGroundControl. Is this really what you want?"), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No); + QGCMessageBox::StandardButton answer = QGCMessageBox::question(tr("Delete Settings"), + tr("All saved settings will be deleted the next time you start QGroundControl. Is this really what you want?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); if (answer == QMessageBox::Yes) { qgcApp()->deleteAllSettingsNextBoot(); } else { @@ -146,9 +146,8 @@ void SettingsDialog::_validateBeforeClose(void) QString saveLocation = _ui->savedFilesLocation->text(); if (!app->validatePossibleSavedFilesLocation(saveLocation)) { - QMessageBox::warning(_mainWindow, - tr("Bad save location"), - tr("The location to save files to is invalid, or cannot be written to. Please provide a valid directory.")); + QGCMessageBox::warning(tr("Bad save location"), + tr("The location to save files to is invalid, or cannot be written to. Please provide a valid directory.")); return; } diff --git a/src/ui/QGCUASFileView.cc b/src/ui/QGCUASFileView.cc index 536f1ca..08aed28 100644 --- a/src/ui/QGCUASFileView.cc +++ b/src/ui/QGCUASFileView.cc @@ -27,7 +27,6 @@ #include #include -#include QGCUASFileView::QGCUASFileView(QWidget *parent, QGCUASFileManager *manager) : QWidget(parent), diff --git a/src/ui/WaypointList.cc b/src/ui/WaypointList.cc index 741a571..7d634e4 100644 --- a/src/ui/WaypointList.cc +++ b/src/ui/WaypointList.cc @@ -39,7 +39,6 @@ This file is part of the PIXHAWK project #include #include #include -#include #include #include diff --git a/src/ui/configuration/terminalconsole.cpp b/src/ui/configuration/terminalconsole.cpp index 0ad03b6..34aefa5 100644 --- a/src/ui/configuration/terminalconsole.cpp +++ b/src/ui/configuration/terminalconsole.cpp @@ -38,11 +38,11 @@ This file is part of the APM_PLANNER project #include "ui_terminalconsole.h" #include "console.h" #include "QGCConfig.h" +#include "QGCMessageBox.h" #include #include #include -#include #include #include #include @@ -159,12 +159,12 @@ void TerminalConsole::openSerialPort(const SerialSettings &settings) } else { m_serial->close(); - QMessageBox::critical(this, tr("Error"), m_serial->errorString()); + QGCMessageBox::critical(tr("Error"), m_serial->errorString()); m_statusBar->showMessage(tr("Open error")); } } else { - QMessageBox::critical(this, tr("Error"), m_serial->errorString()); + QGCMessageBox::critical(tr("Error"), m_serial->errorString()); m_statusBar->showMessage(tr("Configure error")); } @@ -222,7 +222,7 @@ void TerminalConsole::readData() void TerminalConsole::handleError(QSerialPort::SerialPortError error) { if (error == QSerialPort::ResourceError) { - QMessageBox::critical(this, tr("Critical Error"), m_serial->errorString()); + QGCMessageBox::critical(tr("Critical Error"), m_serial->errorString()); closeSerialPort(); } } diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 2cdba35..39d3666 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -43,7 +43,6 @@ This file is part of the PIXHAWK project #include #include #include -#include #include #include "LinechartWidget.h" @@ -53,6 +52,7 @@ This file is part of the PIXHAWK project #include "QGC.h" #include "MG.h" #include "QGCFileDialog.h" +#include "QGCMessageBox.h" LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent), sysid(systemid), @@ -442,13 +442,7 @@ void LinechartWidget::startLogging() // Check if any curve is enabled if (!activePlot->anyCurveVisible()) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("No curves selected for logging."); - msgBox.setInformativeText("Please check all curves you want to log. Currently no data would be logged, aborting the logging."); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); + QGCMessageBox::critical(tr("No curves selected for logging."), tr("Please check all curves you want to log. Currently no data would be logged, aborting the logging.")); return; } @@ -458,14 +452,11 @@ void LinechartWidget::startLogging() QString fileName = QGCFileDialog::getSaveFileName(this, tr("Specify log file name"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), tr("Logfile (*.log);;")); while (!(fileName.endsWith(".log")) && !abort && fileName != "") { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("Unsuitable file extension for logfile"); - msgBox.setInformativeText("Please choose .log as file extension. Click OK to change the file extension, cancel to not start logging."); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Ok); - if(msgBox.exec() != QMessageBox::Ok) - { + QMessageBox::StandardButton button = QGCMessageBox::critical(tr("Unsuitable file extension for logfile"), + tr("Please choose .log as file extension. Click OK to change the file extension, cancel to not start logging."), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Ok); + if (button != QMessageBox::Ok) { abort = true; break; } @@ -501,15 +492,12 @@ void LinechartWidget::stopLogging() connect(compressor, SIGNAL(finishedFile(QString)), this, SIGNAL(logfileWritten(QString))); connect(compressor, SIGNAL(logProcessingStatusChanged(QString)), MainWindow::instance(), SLOT(showStatusMessage(QString))); - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Question); - msgBox.setText(tr("Starting Log Compression")); - msgBox.setInformativeText(tr("Should empty fields (e.g. due to packet drops) be filled with the previous value of the same variable (zero order hold)?")); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - int ret = msgBox.exec(); + QMessageBox::StandardButton button = QGCMessageBox::question(tr("Starting Log Compression"), + tr("Should empty fields (e.g. due to packet drops) be filled with the previous value of the same variable (zero order hold)?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); bool fill; - if (ret == QMessageBox::Yes) + if (button == QMessageBox::Yes) { fill = true; } diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 73f7b98..ccea9c4 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -6,6 +6,7 @@ #include "MAV2DIcon.h" #include "Waypoint2DIcon.h" #include "UASWaypointManager.h" +#include "QGCMessageBox.h" QGCMapWidget::QGCMapWidget(QWidget *parent) : mapcontrol::OPMapWidget(parent), @@ -65,7 +66,7 @@ void QGCMapWidget::guidedActionTriggered() { if (!uas) { - QMessageBox::information(0,"Error","Please connect first"); + QGCMessageBox::information(tr("Error"), tr("Please connect first")); return; } if (currWPManager) @@ -91,7 +92,7 @@ bool QGCMapWidget::guidedAltActionTriggered() { if (!uas) { - QMessageBox::information(0,"Error","Please connect first"); + QGCMessageBox::information(tr("Error"), tr("Please connect first")); return false; } bool ok = false; @@ -113,7 +114,7 @@ bool QGCMapWidget::setHomeActionTriggered() { if (!uas) { - QMessageBox::information(0,"Error","Please connect first"); + QGCMessageBox::information(tr("Error"), tr("Please connect first")); return false; } UASManagerInterface *uasManager = UASManager::instance(); @@ -597,13 +598,8 @@ void QGCMapWidget::cacheVisibleRegion() if (rect.IsEmpty()) { - QMessageBox msgBox(this); - msgBox.setIcon(QMessageBox::Information); - msgBox.setText("Cannot cache tiles for offline use"); - msgBox.setInformativeText("Please select an area first by holding down SHIFT or ALT and selecting the area with the left mouse button."); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); + QGCMessageBox::information(tr("Cannot cache tiles for offline use"), + tr("Please select an area first by holding down SHIFT or ALT and selecting the area with the left mouse button.")); } else { diff --git a/src/ui/map3D/Pixhawk3DWidget.cc b/src/ui/map3D/Pixhawk3DWidget.cc index 737f6bc..cb35f0b 100644 --- a/src/ui/map3D/Pixhawk3DWidget.cc +++ b/src/ui/map3D/Pixhawk3DWidget.cc @@ -45,6 +45,7 @@ #include "TerrainParamDialog.h" #include "UASManager.h" #include "QGCFileDialog.h" +#include "QGCMessageBox.h" #include "QGC.h" #include "gpl.h" @@ -618,10 +619,8 @@ Pixhawk3DWidget::loadTerrainModel(void) } else { - QMessageBox msgBox(QMessageBox::Warning, - "Error loading model", - QString("Error: Unable to load terrain model (%1).").arg(filename)); - msgBox.exec(); + QGCMessageBox::warning(tr("Error loading model"), + tr("Error: Unable to load terrain model (%1).").arg(filename)); } } diff --git a/src/ui/px4_configuration/PX4FirmwareUpgrade.cc b/src/ui/px4_configuration/PX4FirmwareUpgrade.cc index e3e879b..1db5191 100644 --- a/src/ui/px4_configuration/PX4FirmwareUpgrade.cc +++ b/src/ui/px4_configuration/PX4FirmwareUpgrade.cc @@ -34,9 +34,9 @@ #include #include #include -#include #include "QGCFileDialog.h" +#include "QGCMessageBox.h" /// @Brief Constructs a new PX4FirmwareUpgrade Widget. This widget is used within the PX4VehicleConfig set of screens. PX4FirmwareUpgrade::PX4FirmwareUpgrade(QWidget *parent) : @@ -294,7 +294,7 @@ void PX4FirmwareUpgrade::_foundBoard(bool firstTry, const QString portName, QStr { if (firstTry) { // Board is still plugged - QMessageBox::critical(this, tr("Firmware Upgrade"), tr("You must unplug you board before beginning the Firmware Upgrade process.")); + QGCMessageBox::critical(tr("Firmware Upgrade"), tr("You must unplug you board before beginning the Firmware Upgrade process.")); _cancel(); } else { _portName = portName; diff --git a/src/ui/px4_configuration/PX4RCCalibration.cc b/src/ui/px4_configuration/PX4RCCalibration.cc index 36220b5..e51fba0 100644 --- a/src/ui/px4_configuration/PX4RCCalibration.cc +++ b/src/ui/px4_configuration/PX4RCCalibration.cc @@ -25,11 +25,11 @@ /// @brief PX4 RC Calibration Widget /// @author Don Gagne #include #include "PX4RCCalibration.h" #include "UASManager.h" +#include "QGCMessageBox.h" const int PX4RCCalibration::_updateInterval = 150; ///< Interval for timer which updates radio channel widgets const int PX4RCCalibration::_rcCalPWMCenterPoint = ((PX4RCCalibration::_rcCalPWMValidMaxValue - PX4RCCalibration::_rcCalPWMValidMinValue) / 2.0f) + PX4RCCalibration::_rcCalPWMValidMinValue; @@ -297,7 +297,7 @@ void PX4RCCalibration::_nextButton(void) if (_unitTestMode) { emit nextButtonMessageBoxDisplayed(); } else { - QMessageBox::warning(this, tr("Receiver"), tr("Detected %1 radio channels. To operate PX4, you need at least %2 channels.").arg(_chanCount).arg(_chanMinimum)); + QGCMessageBox::warning(tr("Receiver"), tr("Detected %1 radio channels. To operate PX4, you need at least %2 channels.").arg(_chanCount).arg(_chanMinimum)); } return; } @@ -322,7 +322,7 @@ void PX4RCCalibration::_skipButton(void) void PX4RCCalibration::_trimNYI(void) { - QMessageBox::warning(this, tr("Set Trim"), tr("Setting individual trims is not yet implemented. You will need to go through full calibration to set trims.")); + QGCMessageBox::warning(tr("Set Trim"), tr("Setting individual trims is not yet implemented. You will need to go through full calibration to set trims.")); } void PX4RCCalibration::_saveAllTrims(void) @@ -559,7 +559,7 @@ void PX4RCCalibration::_saveFlapsDown(void) if (_unitTestMode) { emit nextButtonMessageBoxDisplayed(); } else { - QMessageBox::warning(this, tr("Flaps switch"), tr("Flaps switch has not yet been detected.")); + QGCMessageBox::warning(tr("Flaps switch"), tr("Flaps switch has not yet been detected.")); } return; } diff --git a/src/ui/px4_configuration/QGCPX4AirframeConfig.cc b/src/ui/px4_configuration/QGCPX4AirframeConfig.cc index a9d4104..5aec881 100644 --- a/src/ui/px4_configuration/QGCPX4AirframeConfig.cc +++ b/src/ui/px4_configuration/QGCPX4AirframeConfig.cc @@ -1,4 +1,3 @@ -#include #include #include #include @@ -10,6 +9,7 @@ #include "LinkManager.h" #include "UAS.h" #include "QGC.h" +#include "QGCMessageBox.h" QGCPX4AirframeConfig::QGCPX4AirframeConfig(QWidget *parent) : QWidget(parent), @@ -251,13 +251,8 @@ void QGCPX4AirframeConfig::applyAndReboot() // Guard against the case of an edit where we didn't receive all params yet if (selectedId <= 0) { - QMessageBox msgBox; - msgBox.setText(tr("No airframe selected")); - msgBox.setInformativeText(tr("Please select an airframe first.")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - (void)msgBox.exec(); - + QGCMessageBox::warning(tr("No airframe selected"), + tr("Please select an airframe first.")); return; } @@ -276,25 +271,15 @@ void QGCPX4AirframeConfig::applyAndReboot() // Guard against the case of an edit where we didn't receive all params yet if (paramMgr->countPendingParams() > 0 || components.count() == 0) { - QMessageBox msgBox; - msgBox.setText(tr("Parameter sync with UAS not yet complete")); - msgBox.setInformativeText(tr("Please wait a few moments and retry")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - (void)msgBox.exec(); - + QGCMessageBox::information(tr("Parameter sync with UAS not yet complete"), + tr("Please wait a few moments and retry")); return; } // Guard against multiple components responding - this will never show in practice if (components.count() != 1) { - QMessageBox msgBox; - msgBox.setText(tr("Invalid system setup detected")); - msgBox.setInformativeText(tr("None or more than one component advertised to provide the main system configuration option. This is an invalid system setup - please check your autopilot.")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - (void)msgBox.exec(); - + QGCMessageBox::warning(tr("Invalid system setup detected"), + tr("None or more than one component advertised to provide the main system configuration option. This is an invalid system setup - please check your autopilot.")); return; }