From 717cef3e2ca81a190f07ccc6634047a6efef3fe7 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 23 Nov 2014 20:40:39 -0800 Subject: [PATCH] Added saved file location, Flight Data logging Also renamed from QGCSettingsWidget to SettingsDialog to better reflect usage. --- src/ui/QGCSettingsWidget.cc | 172 ++++++++----- src/ui/QGCSettingsWidget.h | 54 ++-- src/ui/QGCSettingsWidget.ui | 483 ++++++++++++++++++++++-------------- 3 files changed, 444 insertions(+), 265 deletions(-) diff --git a/src/ui/QGCSettingsWidget.cc b/src/ui/QGCSettingsWidget.cc index 1ddef28ac..2cca08968 100644 --- a/src/ui/QGCSettingsWidget.cc +++ b/src/ui/QGCSettingsWidget.cc @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 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 . + + ======================================================================*/ + #include #include @@ -12,103 +35,138 @@ #include "GAudioOutput.h" #include "QGCCore.h" -QGCSettingsWidget::QGCSettingsWidget(JoystickInput *joystick, QWidget *parent, Qt::WindowFlags flags) : - QDialog(parent, flags), - mainWindow((MainWindow*)parent), - ui(new Ui::QGCSettingsWidget) +SettingsDialog::SettingsDialog(JoystickInput *joystick, QWidget *parent, Qt::WindowFlags flags) : +QDialog(parent, flags), +_mainWindow(MainWindow::instance()), +_ui(new Ui::SettingsDialog) { - ui->setupUi(this); - + _ui->setupUi(this); + // Center the window on the screen. QRect position = frameGeometry(); position.moveCenter(QApplication::desktop()->availableGeometry().center()); move(position.topLeft()); - + // Add the joystick settings pane - ui->tabWidget->addTab(new JoystickWidget(joystick, this), "Controllers"); - + _ui->tabWidget->addTab(new JoystickWidget(joystick, this), "Controllers"); + // Add all protocols QList protocols = LinkManager::instance()->getProtocols(); foreach (ProtocolInterface* protocol, protocols) { MAVLinkProtocol* mavlink = dynamic_cast(protocol); if (mavlink) { MAVLinkSettingsWidget* msettings = new MAVLinkSettingsWidget(mavlink, this); - ui->tabWidget->addTab(msettings, "MAVLink"); + _ui->tabWidget->addTab(msettings, "MAVLink"); } } - + this->window()->setWindowTitle(tr("QGroundControl Settings")); - + // Audio preferences - ui->audioMuteCheckBox->setChecked(GAudioOutput::instance()->isMuted()); - connect(ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool))); - connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), ui->audioMuteCheckBox, SLOT(setChecked(bool))); - + _ui->audioMuteCheckBox->setChecked(GAudioOutput::instance()->isMuted()); + connect(_ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool))); + connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), _ui->audioMuteCheckBox, SLOT(setChecked(bool))); + // Reconnect - ui->reconnectCheckBox->setChecked(mainWindow->autoReconnectEnabled()); - connect(ui->reconnectCheckBox, SIGNAL(clicked(bool)), mainWindow, SLOT(enableAutoReconnect(bool))); - + _ui->reconnectCheckBox->setChecked(_mainWindow->autoReconnectEnabled()); + connect(_ui->reconnectCheckBox, SIGNAL(clicked(bool)), _mainWindow, SLOT(enableAutoReconnect(bool))); + // Low power mode - ui->lowPowerCheckBox->setChecked(mainWindow->lowPowerModeEnabled()); - connect(ui->lowPowerCheckBox, SIGNAL(clicked(bool)), mainWindow, SLOT(enableLowPowerMode(bool))); - + _ui->lowPowerCheckBox->setChecked(_mainWindow->lowPowerModeEnabled()); + connect(_ui->lowPowerCheckBox, SIGNAL(clicked(bool)), _mainWindow, SLOT(enableLowPowerMode(bool))); + // Dock widget title bars - ui->titleBarCheckBox->setChecked(mainWindow->dockWidgetTitleBarsEnabled()); - connect(ui->titleBarCheckBox,SIGNAL(clicked(bool)),mainWindow,SLOT(enableDockWidgetTitleBars(bool))); + _ui->titleBarCheckBox->setChecked(_mainWindow->dockWidgetTitleBarsEnabled()); + connect(_ui->titleBarCheckBox,SIGNAL(clicked(bool)),_mainWindow,SLOT(enableDockWidgetTitleBars(bool))); + + connect(_ui->deleteSettings, &QAbstractButton::toggled, this, &SettingsDialog::_deleteSettingsToggled); - connect(ui->deleteSettings, &QAbstractButton::toggled, this, &QGCSettingsWidget::_deleteSettingsToggled); - // Custom mode - - ui->customModeComboBox->addItem(tr("Default: Generic MAVLink and serial links"), MainWindow::CUSTOM_MODE_NONE); - ui->customModeComboBox->addItem(tr("Wifi: Generic MAVLink, wifi or serial links"), MainWindow::CUSTOM_MODE_WIFI); - ui->customModeComboBox->addItem(tr("PX4: Optimized for PX4 Autopilot Users"), MainWindow::CUSTOM_MODE_PX4); - // XXX we need to polish the APM view mode before re-enabling this - //ui->customModeComboBox->addItem(tr("APM: Optimized for ArduPilot Users"), MainWindow::CUSTOM_MODE_APM); - - ui->customModeComboBox->setCurrentIndex(ui->customModeComboBox->findData(mainWindow->getCustomMode())); - connect(ui->customModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectCustomMode(int))); - - // Intialize the style UI to the proper values obtained from the MainWindow. - MainWindow::QGC_MAINWINDOW_STYLE style = mainWindow->getStyle(); - ui->styleChooser->setCurrentIndex(style); - - // And then connect all the signals for the UI for changing styles. - connect(ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int))); - - // Close / destroy - connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(deleteLater())); + + _ui->customModeComboBox->addItem(tr("Default: Generic MAVLink and serial links"), MainWindow::CUSTOM_MODE_NONE); + _ui->customModeComboBox->addItem(tr("Wifi: Generic MAVLink, wifi or serial links"), MainWindow::CUSTOM_MODE_WIFI); + _ui->customModeComboBox->addItem(tr("PX4: Optimized for PX4 Autopilot Users"), MainWindow::CUSTOM_MODE_PX4); + + _ui->customModeComboBox->setCurrentIndex(_ui->customModeComboBox->findData(_mainWindow->getCustomMode())); + connect(_ui->customModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectCustomMode(int))); + + // Application color style + MainWindow::QGC_MAINWINDOW_STYLE style = _mainWindow->getStyle(); + _ui->styleChooser->setCurrentIndex(style); + + _ui->savedFilesLocation->setText(qgcApp()->savedFilesLocation()); + _ui->promptFlightDataSave->setChecked(qgcApp()->promptFlightDataSave()); + + // Connect signals + connect(_ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int))); + connect(_ui->browseSavedFilesLocation, &QPushButton::clicked, this, &SettingsDialog::_selectSavedFilesDirectory); + connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::_validateBeforeClose); } -QGCSettingsWidget::~QGCSettingsWidget() +SettingsDialog::~SettingsDialog() { - delete ui; + delete _ui; } -void QGCSettingsWidget::styleChanged(int index) +void SettingsDialog::styleChanged(int index) { - mainWindow->loadStyle((index == 1) ? MainWindow::QGC_MAINWINDOW_STYLE_LIGHT : MainWindow::QGC_MAINWINDOW_STYLE_DARK); + _mainWindow->loadStyle((index == 1) ? MainWindow::QGC_MAINWINDOW_STYLE_LIGHT : MainWindow::QGC_MAINWINDOW_STYLE_DARK); } -void QGCSettingsWidget::selectCustomMode(int mode) +void SettingsDialog::selectCustomMode(int mode) { - MainWindow::instance()->setCustomMode(static_cast(ui->customModeComboBox->itemData(mode).toInt())); - MainWindow::instance()->showInfoMessage(tr("Please restart QGroundControl"), tr("The optimization selection was changed. The application needs to be closed and restarted to put all optimizations into effect.")); + _mainWindow->setCustomMode(static_cast(_ui->customModeComboBox->itemData(mode).toInt())); } -void QGCSettingsWidget::_deleteSettingsToggled(bool checked) +void SettingsDialog::_deleteSettingsToggled(bool checked) { if (checked){ QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Delete Settings"), - tr("All saved settgings will be deleted the next time you start QGroundControl. Is this really what you want?"), + 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) { - QSettings settings; - settings.setValue(QGCCore::deleteAllSettingsKey, 1); + qgcApp()->deleteAllSettingsNextBoot(); } else { - ui->deleteSettings->setChecked(false); + _ui->deleteSettings->setChecked(false); } + } else { + qgcApp()->clearDeleteAllSettingsNextBoot(); + } +} + +/// @brief Validates the settings before closing +void SettingsDialog::_validateBeforeClose(void) +{ + QGCApplication* app = qgcApp(); + + // Validate the saved file location + + 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.")); + return; + } + + // Locations is valid, save + app->setSavedFilesLocation(saveLocation); + + qgcApp()->setPromptFlightDataSave(_ui->promptFlightDataSave->checkState() == Qt::Checked); + + // Close dialog + accept(); +} + +/// @brief Displays a directory picker dialog to allow the user to select a saved file location +void SettingsDialog::_selectSavedFilesDirectory(void) +{ + QString newLocation = QFileDialog::getExistingDirectory(this, + tr("Select the directory where you want to save files to."), + _ui->savedFilesLocation->text()); + if (!newLocation.isEmpty()) { + _ui->savedFilesLocation->setText(newLocation); } } diff --git a/src/ui/QGCSettingsWidget.h b/src/ui/QGCSettingsWidget.h index 5c2f4675d..a8b2e117e 100644 --- a/src/ui/QGCSettingsWidget.h +++ b/src/ui/QGCSettingsWidget.h @@ -1,33 +1,57 @@ -#ifndef QGCSETTINGSWIDGET_H -#define QGCSETTINGSWIDGET_H +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 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 SETTINGSDIALOG_H +#define SETTINGSDIALOG_H #include #include "MainWindow.h" namespace Ui { -class QGCSettingsWidget; + class SettingsDialog; } -class QGCSettingsWidget : public QDialog +class SettingsDialog : public QDialog { Q_OBJECT - + public: - QGCSettingsWidget(JoystickInput *joystick, QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet); - ~QGCSettingsWidget(); - -public slots: + SettingsDialog(JoystickInput *joystick, QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet); + ~SettingsDialog(); + + public slots: void styleChanged(int index); void selectCustomMode(int mode); - -private slots: + + private slots: void _deleteSettingsToggled(bool checked); + void _selectSavedFilesDirectory(void); + void _validateBeforeClose(void); private: - MainWindow* mainWindow; - Ui::QGCSettingsWidget* ui; - bool updateStyle(QString style); + MainWindow* _mainWindow; + Ui::SettingsDialog* _ui; }; -#endif // QGCSETTINGSWIDGET_H +#endif diff --git a/src/ui/QGCSettingsWidget.ui b/src/ui/QGCSettingsWidget.ui index c3e13c2c8..1c55884d6 100644 --- a/src/ui/QGCSettingsWidget.ui +++ b/src/ui/QGCSettingsWidget.ui @@ -1,199 +1,296 @@ - QGCSettingsWidget - - - - 0 - 0 - 534 - 517 - - - - - 0 - 0 - - - - Dialog - - - - - - - General - - - General Settings - - - - - - Mute all audio output - - - - :/files/images/status/audio-volume-muted.svg:/files/images/status/audio-volume-muted.svg - - - - - - - Automatically reconnect last link on application startup - - - - :/files/images/devices/network-wireless.svg:/files/images/devices/network-wireless.svg - - - - - - - Lowers all update rates to save battery power - - - Enable low power mode - - - - - - - Show Docked Widget title bars when NOT in advanced Mode. - - - false - - - - - - - - - - Style - - - false - - - false - - - - - - QLayout::SetMinimumSize - + SettingsDialog + + + + 0 + 0 + 534 + 681 + + + + + 0 + 0 + + + + Dialog + + - - - - Dark (for indoor use) - - - - - Light (for outdoor use) - - - + + + + General + + + General Settings + + + + + + Mute all audio output + + + + :/files/images/status/audio-volume-muted.svg:/files/images/status/audio-volume-muted.svg + + + + + + + Automatically reconnect last link on application startup + + + + :/files/images/devices/network-wireless.svg:/files/images/devices/network-wireless.svg + + + + + + + Lowers all update rates to save battery power + + + Enable low power mode + + + + + + + Show Docked Widget title bars when NOT in advanced Mode. + + + false + + + + + + + Prompt to save Flight Data Log after each flight + + + + + + + + + + Style + + + false + + + false + + + + + + QLayout::SetMinimumSize + + + + + + Dark (for indoor use) + + + + + Light (for outdoor use) + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 200 + + + + File Locations + + + + + + + 11 + + + + Parameters will be saved here: + + + + + + + + 11 + + + + TextLabel + + + + + + + Browse + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Specify the location you would like to save files to: + + + true + + + + + + + + 0 + 21 + + + + + + + + + 11 + + + + Flight Data Logs will be saved here: + + + + + + + + 11 + + + + TextLabel + + + + + + + + + + Danger Zone + + + + + + Delete all saved settings on next boot + + + + + + + + 11 + + + + Note: You can also use --clear-settings as a command line option to accomplish this. + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + - - - - - - - - - Danger Zone - - - - - - Delete all saved settings on next boot - - - - - - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - false - + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + false + + + + - - - - - - - - - buttonBox - accepted() - QGCSettingsWidget - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - QGCSettingsWidget - reject() - - - 316 - 260 - - - 286 - 274 - - - - + + + + -- 2.22.0