Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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/add_display_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 QString topic;
00103 QString datatype;
00104
00105 QStringList empty;
00106
00107 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00108 AddDisplayDialog* dialog = new AddDisplayDialog( vis_manager_->getDisplayFactory(),
00109 "Display",
00110 empty, empty,
00111 &lookup_name,
00112 &display_name,
00113 &topic,
00114 &datatype );
00115 QApplication::restoreOverrideCursor();
00116
00117 vis_manager_->stopUpdate();
00118 if( dialog->exec() == QDialog::Accepted )
00119 {
00120 Display *disp = vis_manager_->createDisplay( lookup_name, display_name, true );
00121 if ( !topic.isEmpty() && !datatype.isEmpty() )
00122 {
00123 disp->setTopic( topic, datatype );
00124 }
00125 }
00126 vis_manager_->startUpdate();
00127 activateWindow();
00128 }
00129
00130 void DisplaysPanel::onDeleteDisplay()
00131 {
00132 QList<Display*> displays_to_delete = property_grid_->getSelectedObjects<Display>();
00133
00134 for( int i = 0; i < displays_to_delete.size(); i++ )
00135 {
00136
00137
00138 displays_to_delete[ i ]->disconnect();
00139
00140 displays_to_delete[ i ]->deleteLater();
00141 }
00142 vis_manager_->notifyConfigChanged();
00143 }
00144
00145 void DisplaysPanel::onSelectionChanged()
00146 {
00147 QList<Display*> displays = property_grid_->getSelectedObjects<Display>();
00148
00149 int num_displays_selected = displays.size();
00150
00151 remove_button_->setEnabled( num_displays_selected > 0 );
00152 rename_button_->setEnabled( num_displays_selected == 1 );
00153 }
00154
00155 void DisplaysPanel::onRenameDisplay()
00156 {
00157 QList<Display*> displays = property_grid_->getSelectedObjects<Display>();
00158 if( displays.size() == 0 )
00159 {
00160 return;
00161 }
00162 Display* display_to_rename = displays[ 0 ];
00163
00164 if( !display_to_rename )
00165 {
00166 return;
00167 }
00168
00169 QString old_name = display_to_rename->getName();
00170 QString new_name = QInputDialog::getText( this, "Rename Display", "New Name?", QLineEdit::Normal, old_name );
00171
00172 if( new_name.isEmpty() || new_name == old_name )
00173 {
00174 return;
00175 }
00176
00177 display_to_rename->setName( new_name );
00178 }
00179
00180 void DisplaysPanel::save( Config config ) const
00181 {
00182 Panel::save( config );
00183 tree_with_help_->save( config );
00184 }
00185
00186 void DisplaysPanel::load( const Config& config )
00187 {
00188 Panel::load( config );
00189 tree_with_help_->load( config );
00190 }
00191
00192 }