diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index a9e8a18421da3e1e6e027dea4c5917f3c2b626f2..80e5ab79c81c73bfff12ea948924aba75fecb4a8 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 9a100c69fd567742c54ba2b53c1e50dfa76451e1..77a2022e9e1813b2229fe37d2e13016249bd2586 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 0000000000000000000000000000000000000000..4c16a5ddb18292eea44eb9db2a9d8a613ac49b86 --- /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 129e40babf315780fecf5782bbfec4e3b6690394..15aa623e93f65c06ae357bb4cdc56236c0028fa1 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 d1300db42c5b724f7206f611f0dd8469de3c9a04..34f556a04ecb3689f76a54ce472c51cd76c90581 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 13968725c6edab99540d750f8033efd413e51114..16cdee55db972381c7261d92f038ace4067d8d77 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 0afc2342a8f97aeff8d40c21c851d0d29813a9c0..7920c0118d15f5ae58161de5f5613bd9546f80f3 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 b49ef8c25efe13b869de037af18db5bce9f815f3..d12a9b5b1cabd84a275f446e36eabf0314fe879c 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 233be840a9c64c6bf81f2a93235b18b2bca27267..7ae8e3e655c2e1d5318eb8e637d0f479b3d93f7c 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 3f19abcd044831833539c25c1df57caf968b233b..d4a865d79cb2aaeb83ea6590b79f95131110323e 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 aca75e96567e4c17eeb27ded08811bfeb6a4adbc..0990af2b13bc9b5264debb200396011b85fec5f5 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 79c8ac323ac62e47b59b2d9441bcb25af6be045d..e2e71fb5bac480bf01c132064cbdce30a10c1e54 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 bbadd89348c9ba19b32958c1760c8fdf4e89360c..6bffe323a87fd97a3694e467dc65657905da1a49 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 e5f87c531107640231003be92bae2c08757769fa..0dbe0281171c39c23a8c20e5fcec57c40ddd3940 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 38a39954b30130040201dbe5c905613962004823..851142022080be8bd0a367eef5243bf20bf37ebf 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 e57d61d2b55096fdbdf309790bb4dc32dd49322b..c90d9c28a3cd4f4bfa93f863b33fc39fcfcd9e5b 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 1ea9b17df0b926fb0c5d1f63c51cce2ea882d1c4..1009cab0742ece3998e8d992dd009b5b5b67efa8 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 f4f3ee4153f8a0d2740ae9c76dc0baae92734c0b..a995726506457e9a095ee7d6c1f8510e84471f4d 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 d48a4f6f8d1daeca560b4bac49490a886c983a5a..7c8e6c2098f5a26bcdc9496eb0ea1e5f99bb8ac0 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 536f1ca6a37b24acde448533c10e3cbc91ad825c..08aed28f5edc932a92c531e3e7fce19976bec5f9 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 741a571a3e53410cf226bebad3aef934f2cbb72b..7d634e41449cf4c7f760c276dc183b806e12d31b 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 0ad03b62a838589814e3be6e485b56a16105eaeb..34aefa58cd7037235390667a330cfac30331b11d 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 2cdba3562c644021188cb69304e1d06e84602298..39d3666663998fb3218d8d89bb3ad6eadf0da8b0 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 73f7b98acab8e8239a675189ff2d2f4e0f04d51e..ccea9c46f7705ab3ab67a0eb3df4cb7e440af581 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 737f6bc24eb17a76668260210cce4e2a2496ecfd..cb35f0b8abf1c7a5c7895d1e8b0a0838ab7f721e 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 e3e879b2c6f9cda179882b98e25ed225527b4269..1db5191c4620ce5dac5972d2c53a20fbb642aed0 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 36220b5155a07b6ababa2a39027f988856b73e06..e51fba060683ad0fb39e5ae706d133888e9af8f3 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 a9d410434a0d07ef9c4a5b61b85d3f7402eb9249..5aec881fdb01d7d5601384fb6b1dd2c2129630d5 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; }