From ff5d88f5479409fa5acf13642c0baaa461f56baa Mon Sep 17 00:00:00 2001 From: dhood Date: Thu, 5 Apr 2018 16:52:15 -0700 Subject: [PATCH] Generalise preferences, hide impl Will allow us to add more preferences without breaking ABI --- src/rviz/preferences.h | 43 ++++++++++++++++++++++++++++++++ src/rviz/preferences_dialog.cpp | 9 ++++--- src/rviz/preferences_dialog.h | 6 +++-- src/rviz/visualization_frame.cpp | 15 +++++------ src/rviz/visualization_frame.h | 5 +++- 5 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 src/rviz/preferences.h diff --git a/src/rviz/preferences.h b/src/rviz/preferences.h new file mode 100644 index 0000000000..12f4c1c136 --- /dev/null +++ b/src/rviz/preferences.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018, Open Source Robotics Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Willow Garage, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RVIZ_PREFERENCES_H +#define RVIZ_PREFERENCES_H + +namespace rviz +{ + +struct Preferences +{ + bool prompt_save_on_exit = true; +}; + +} //namespace rviz + +#endif // RVIZ_PREFERENCES_H diff --git a/src/rviz/preferences_dialog.cpp b/src/rviz/preferences_dialog.cpp index 3bcfb79496..93ecc99e84 100644 --- a/src/rviz/preferences_dialog.cpp +++ b/src/rviz/preferences_dialog.cpp @@ -46,16 +46,17 @@ #include "preferences_dialog.h" #include "rviz/load_resource.h" +#include "rviz/preferences.h" namespace rviz { PreferencesDialog::PreferencesDialog( Factory* factory, - bool* prompt_save_on_exit_output, + Preferences *preferences, QWidget* parent) : QDialog( parent ) , factory_( factory ) -, prompt_save_on_exit_output_( prompt_save_on_exit_output ) +, preferences_( preferences) { //***** Layout @@ -65,7 +66,7 @@ PreferencesDialog::PreferencesDialog( Factory* factory, QVBoxLayout* preferences_layout = new QVBoxLayout; preferences_layout->setAlignment(Qt::AlignLeft | Qt::AlignTop); prompt_save_on_exit_checkbox_ = new QCheckBox; - prompt_save_on_exit_checkbox_->setChecked(*prompt_save_on_exit_output_); + prompt_save_on_exit_checkbox_->setChecked(preferences_->prompt_save_on_exit); prompt_save_on_exit_checkbox_->setText(QString( "Prompt Save on Exit?")); preferences_layout->addWidget( prompt_save_on_exit_checkbox_ ); preferences_box->setLayout( preferences_layout ); @@ -104,7 +105,7 @@ void PreferencesDialog::accept() { if( isValid() ) { - *prompt_save_on_exit_output_ = prompt_save_on_exit_checkbox_->isChecked(); + preferences_->prompt_save_on_exit = prompt_save_on_exit_checkbox_->isChecked(); QDialog::accept(); } } diff --git a/src/rviz/preferences_dialog.h b/src/rviz/preferences_dialog.h index c6e6b64ca3..8242b0d780 100644 --- a/src/rviz/preferences_dialog.h +++ b/src/rviz/preferences_dialog.h @@ -44,6 +44,8 @@ class QLabel; namespace rviz { +class Preferences; + class PreferencesDialog : public QDialog { Q_OBJECT @@ -64,7 +66,7 @@ Q_OBJECT * put the display name entered, or NULL (default) if display * name entry field should not be shown. */ PreferencesDialog( Factory* factory, - bool* prompt_save_on_exit_output, + Preferences* preferences, QWidget* parent = 0 ); virtual QSize sizeHint () const; @@ -84,7 +86,7 @@ public Q_SLOTS: Factory* factory_; QCheckBox* prompt_save_on_exit_checkbox_; - bool* prompt_save_on_exit_output_; + Preferences* preferences_; /** Widget with OK and CANCEL buttons. */ QDialogButtonBox* button_box_; diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index 164b1d7a39..0802511487 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -69,6 +69,7 @@ #include "rviz/help_panel.h" #include "rviz/loading_dialog.h" #include "rviz/new_object_dialog.h" +#include "rviz/preferences.h" #include "rviz/preferences_dialog.h" #include "rviz/panel_dock_widget.h" #include "rviz/panel_factory.h" @@ -126,7 +127,7 @@ VisualizationFrame::VisualizationFrame( QWidget* parent ) , loading_( false ) , post_load_timer_( new QTimer( this )) , frame_count_(0) - , prompt_save_on_exit_(true) + , preferences_( new Preferences() ) { panel_factory_ = new PanelFactory(); @@ -588,14 +589,14 @@ void VisualizationFrame::onDockPanelVisibilityChange( bool visible ) void VisualizationFrame::openPreferencesDialog() { - bool prompt_save_on_exit = prompt_save_on_exit_; + Preferences temp_preferences( *preferences_.get() ); PreferencesDialog* dialog = new PreferencesDialog( panel_factory_, - &prompt_save_on_exit, + &temp_preferences, this ); manager_->stopUpdate(); if( dialog->exec() == QDialog::Accepted ) { // Apply preferences. - prompt_save_on_exit_ = prompt_save_on_exit; + preferences_ = boost::make_shared( temp_preferences ); } manager_->startUpdate(); } @@ -927,12 +928,12 @@ void VisualizationFrame::savePanels( Config config ) void VisualizationFrame::loadPreferences( const Config& config ) { - config.mapGetBool( "PromptSaveOnExit", &prompt_save_on_exit_ ); + config.mapGetBool( "PromptSaveOnExit", &(preferences_->prompt_save_on_exit) ); } void VisualizationFrame::savePreferences( Config config ) { - config.mapSetValue( "PromptSaveOnExit", prompt_save_on_exit_ ); + config.mapSetValue( "PromptSaveOnExit", preferences_->prompt_save_on_exit ); } bool VisualizationFrame::prepareToExit() @@ -944,7 +945,7 @@ bool VisualizationFrame::prepareToExit() savePersistentSettings(); - if( isWindowModified() && prompt_save_on_exit_) + if( isWindowModified() && preferences_->prompt_save_on_exit) { QMessageBox box( this ); box.setText( "There are unsaved changes." ); diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index 228f60d6a0..a3fa91dc4b 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -30,6 +30,8 @@ #ifndef RVIZ_VISUALIZATION_FRAME_H #define RVIZ_VISUALIZATION_FRAME_H +#include + #include #include @@ -54,6 +56,7 @@ namespace rviz { class PanelFactory; +class Preferences; class RenderPanel; class VisualizationManager; class Tool; @@ -307,7 +310,7 @@ protected Q_SLOTS: std::string last_image_dir_; std::string home_dir_; - bool prompt_save_on_exit_; + boost::shared_ptr preferences_; QMenu* file_menu_; QMenu* recent_configs_menu_;