displays_panel.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <QTimer>
00031 #include <QHBoxLayout>
00032 #include <QVBoxLayout>
00033 #include <QPushButton>
00034 #include <QInputDialog>
00035 #include <QApplication>
00036 
00037 #include <boost/bind.hpp>
00038 
00039 #include "rviz/display_factory.h"
00040 #include "rviz/display.h"
00041 #include "rviz/new_object_dialog.h"
00042 #include "rviz/properties/property.h"
00043 #include "rviz/properties/property_tree_widget.h"
00044 #include "rviz/properties/property_tree_with_help.h"
00045 #include "rviz/visualization_manager.h"
00046 
00047 #include "rviz/displays_panel.h"
00048 
00049 namespace rviz
00050 {
00051 
00052 DisplaysPanel::DisplaysPanel( QWidget* parent )
00053   : Panel( parent )
00054 {
00055   tree_with_help_ = new PropertyTreeWithHelp;
00056   property_grid_ = tree_with_help_->getTree();
00057 
00058   QPushButton* add_button = new QPushButton( "Add" );
00059   add_button->setShortcut( QKeySequence( QString( "Ctrl+N" )));
00060   add_button->setToolTip( "Add a new display, Ctrl+N" );
00061   remove_button_ = new QPushButton( "Remove" );
00062   remove_button_->setShortcut( QKeySequence( QString( "Ctrl+X" )));
00063   remove_button_->setToolTip( "Remove displays, Ctrl+X" );
00064   remove_button_->setEnabled( false );
00065   rename_button_ = new QPushButton( "Rename" );
00066   rename_button_->setShortcut( QKeySequence( QString( "Ctrl+R" )));
00067   rename_button_->setToolTip( "Rename a display, Ctrl+R" );
00068   rename_button_->setEnabled( false );
00069 
00070   QHBoxLayout* button_layout = new QHBoxLayout;
00071   button_layout->addWidget( add_button );
00072   button_layout->addWidget( remove_button_ );
00073   button_layout->addWidget( rename_button_ );
00074   button_layout->setContentsMargins( 2, 0, 2, 2 );
00075 
00076   QVBoxLayout* layout = new QVBoxLayout;
00077   layout->setContentsMargins( 0, 0, 0, 2 );
00078   layout->addWidget( tree_with_help_ );
00079   layout->addLayout( button_layout );
00080 
00081   setLayout( layout );
00082 
00083   connect( add_button, SIGNAL( clicked( bool )), this, SLOT( onNewDisplay() ));
00084   connect( remove_button_, SIGNAL( clicked( bool )), this, SLOT( onDeleteDisplay() ));
00085   connect( rename_button_, SIGNAL( clicked( bool )), this, SLOT( onRenameDisplay() ));
00086   connect( property_grid_, SIGNAL( selectionHasChanged() ), this, SLOT( onSelectionChanged() ));
00087 }
00088 
00089 DisplaysPanel::~DisplaysPanel()
00090 {
00091 }
00092 
00093 void DisplaysPanel::onInitialize()
00094 {
00095   property_grid_->setModel( vis_manager_->getDisplayTreeModel() );
00096 }
00097 
00098 void DisplaysPanel::onNewDisplay()
00099 {
00100   QString lookup_name;
00101   QString display_name;
00102 
00103   QStringList empty;
00104 
00105   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00106   NewObjectDialog* dialog = new NewObjectDialog( vis_manager_->getDisplayFactory(),
00107                                                  "Display",
00108                                                  empty, empty,
00109                                                  &lookup_name,
00110                                                  &display_name );
00111   QApplication::restoreOverrideCursor();
00112 
00113   vis_manager_->stopUpdate();
00114   if( dialog->exec() == QDialog::Accepted )
00115   {
00116     vis_manager_->createDisplay( lookup_name, display_name, true );
00117   }
00118   vis_manager_->startUpdate();
00119   activateWindow(); // Force keyboard focus back on main window.
00120 }
00121 
00122 void DisplaysPanel::onDeleteDisplay()
00123 {
00124   QList<Display*> displays_to_delete = property_grid_->getSelectedObjects<Display>();
00125 
00126   for( int i = 0; i < displays_to_delete.size(); i++ )
00127   {
00128     delete displays_to_delete[ i ];
00129   }
00130   vis_manager_->notifyConfigChanged();
00131 }
00132 
00133 void DisplaysPanel::onSelectionChanged()
00134 {
00135   QList<Display*> displays = property_grid_->getSelectedObjects<Display>();
00136 
00137   int num_displays_selected = displays.size();
00138 
00139   remove_button_->setEnabled( num_displays_selected > 0 );
00140   rename_button_->setEnabled( num_displays_selected == 1 );
00141 }
00142 
00143 void DisplaysPanel::onRenameDisplay()
00144 {
00145   QList<Display*> displays = property_grid_->getSelectedObjects<Display>();
00146   if( displays.size() == 0 )
00147   {
00148     return;
00149   }
00150   Display* display_to_rename = displays[ 0 ];
00151 
00152   if( !display_to_rename )
00153   {
00154     return;
00155   }
00156 
00157   QString old_name = display_to_rename->getName();
00158   QString new_name = QInputDialog::getText( this, "Rename Display", "New Name?", QLineEdit::Normal, old_name );
00159 
00160   if( new_name.isEmpty() || new_name == old_name )
00161   {
00162     return;
00163   }
00164 
00165   display_to_rename->setName( new_name );
00166 }
00167 
00168 void DisplaysPanel::save( Config config ) const
00169 {
00170   Panel::save( config );
00171   tree_with_help_->save( config );
00172 }
00173 
00174 void DisplaysPanel::load( const Config& config )
00175 {
00176   Panel::load( config );
00177   tree_with_help_->load( config );
00178 }
00179 
00180 } // namespace rviz


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:35