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 <QLabel>
00031 #include <QListWidget>
00032 #include <QComboBox>
00033 #include <QPushButton>
00034 #include <QVBoxLayout>
00035 #include <QHBoxLayout>
00036 #include <QInputDialog>
00037
00038 #include "rviz/properties/property_tree_widget.h"
00039 #include "rviz/view_controller.h"
00040 #include "rviz/view_manager.h"
00041 #include "rviz/visualization_manager.h"
00042
00043 #include "views_panel.h"
00044
00045 namespace rviz
00046 {
00047
00048 ViewsPanel::ViewsPanel( QWidget* parent )
00049 : Panel( parent )
00050 , view_man_( NULL )
00051 {
00052 camera_type_selector_ = new QComboBox;
00053 properties_view_ = new PropertyTreeWidget();
00054
00055 save_button_ = new QPushButton( "Save" );
00056 QPushButton* remove_button = new QPushButton( "Remove" );
00057 QPushButton* rename_button = new QPushButton( "Rename" );
00058 QPushButton* zero_button = new QPushButton( "Zero" );
00059 zero_button->setToolTip( "Jump to 0,0,0 with the current view controller. Shortcut: Z" );
00060
00061 QHBoxLayout* top_layout = new QHBoxLayout;
00062 top_layout->addWidget( new QLabel( "Type:" ));
00063 top_layout->addWidget( camera_type_selector_ );
00064 top_layout->addStretch();
00065 top_layout->addWidget( zero_button );
00066 top_layout->setContentsMargins( 2, 6, 2, 2 );
00067
00068 QHBoxLayout* button_layout = new QHBoxLayout;
00069 button_layout->addWidget( save_button_ );
00070 button_layout->addWidget( remove_button );
00071 button_layout->addWidget( rename_button );
00072 button_layout->setContentsMargins( 2, 0, 2, 2 );
00073
00074 QVBoxLayout* main_layout = new QVBoxLayout;
00075 main_layout->setContentsMargins( 0,0,0,0 );
00076 main_layout->addLayout( top_layout );
00077 main_layout->addWidget( properties_view_ );
00078 main_layout->addLayout( button_layout );
00079 setLayout( main_layout );
00080
00081 connect( remove_button, SIGNAL( clicked() ), this, SLOT( onDeleteClicked() ));
00082 connect( rename_button, SIGNAL( clicked() ), this, SLOT( renameSelected() ));
00083 connect( zero_button, SIGNAL( clicked() ), this, SLOT( onZeroClicked() ));
00084 connect( properties_view_, SIGNAL( clicked( const QModelIndex& )), this, SLOT( setCurrentViewFromIndex( const QModelIndex& )));
00085 connect( properties_view_, SIGNAL( activated( const QModelIndex& )), this, SLOT( setCurrentViewFromIndex( const QModelIndex& )));
00086 }
00087
00088 void ViewsPanel::onInitialize()
00089 {
00090 setViewManager( vis_manager_->getViewManager() );
00091 }
00092
00093 void ViewsPanel::setViewManager( ViewManager* view_man )
00094 {
00095 if( view_man_ )
00096 {
00097 disconnect( save_button_, SIGNAL( clicked() ), view_man_, SLOT( copyCurrentToList() ));
00098 disconnect( camera_type_selector_, SIGNAL( activated( int )), this, SLOT( onTypeSelectorChanged( int )));
00099 disconnect( view_man_, SIGNAL( currentChanged() ), this, SLOT( onCurrentChanged() ));
00100 }
00101 view_man_ = view_man;
00102 camera_type_selector_->clear();
00103 if( view_man_ )
00104 {
00105 properties_view_->setModel( view_man_->getPropertyModel() );
00106
00107 QStringList ids = view_man_->getFactory()->getDeclaredClassIds();
00108 for( int i = 0; i < ids.size(); i++ )
00109 {
00110 const QString& id = ids[ i ];
00111 camera_type_selector_->addItem( ViewController::formatClassId( id ), id );
00112 }
00113
00114 connect( save_button_, SIGNAL( clicked() ), view_man_, SLOT( copyCurrentToList() ));
00115 connect( camera_type_selector_, SIGNAL( activated( int )), this, SLOT( onTypeSelectorChanged( int )));
00116 connect( view_man_, SIGNAL( currentChanged() ), this, SLOT( onCurrentChanged() ));
00117 }
00118 else
00119 {
00120 properties_view_->setModel( NULL );
00121 }
00122 onCurrentChanged();
00123 }
00124
00125 void ViewsPanel::onTypeSelectorChanged( int selected_index )
00126 {
00127 QString class_id = camera_type_selector_->itemData( selected_index ).toString();
00128 view_man_->setCurrentViewControllerType( class_id );
00129 }
00130
00131 void ViewsPanel::onZeroClicked()
00132 {
00133 if( view_man_->getCurrent() )
00134 {
00135 view_man_->getCurrent()->reset();
00136 }
00137 }
00138
00139 void ViewsPanel::setCurrentViewFromIndex( const QModelIndex& index )
00140 {
00141 Property* prop = view_man_->getPropertyModel()->getProp( index );
00142 if( ViewController* view = qobject_cast<ViewController*>( prop ))
00143 {
00144 view_man_->setCurrentFrom( view );
00145 }
00146 }
00147
00148 void ViewsPanel::onDeleteClicked()
00149 {
00150 QList<ViewController*> views_to_delete = properties_view_->getSelectedObjects<ViewController>();
00151
00152 for( int i = 0; i < views_to_delete.size(); i++ )
00153 {
00154
00155
00156
00157 if( views_to_delete[ i ] != view_man_->getCurrent() )
00158 {
00159 delete views_to_delete[ i ];
00160 }
00161 }
00162 }
00163
00164 void ViewsPanel::renameSelected()
00165 {
00166 QList<ViewController*> views_to_rename = properties_view_->getSelectedObjects<ViewController>();
00167 if( views_to_rename.size() == 1 )
00168 {
00169 ViewController* view = views_to_rename[ 0 ];
00170
00171
00172
00173
00174 if( view == view_man_->getCurrent() )
00175 {
00176 return;
00177 }
00178
00179 QString old_name = view->getName();
00180 QString new_name = QInputDialog::getText( this, "Rename View", "New Name?", QLineEdit::Normal, old_name );
00181
00182 if( new_name.isEmpty() || new_name == old_name )
00183 {
00184 return;
00185 }
00186
00187 view->setName( new_name );
00188 }
00189 }
00190
00191 void ViewsPanel::onCurrentChanged()
00192 {
00193 QString formatted_class_id = ViewController::formatClassId( view_man_->getCurrent()->getClassId() );
00194
00195
00196
00197
00198 camera_type_selector_->setCurrentIndex( camera_type_selector_->findText( formatted_class_id ));
00199
00200 properties_view_->setAnimated( false );
00201 view_man_->getCurrent()->expand();
00202 properties_view_->setAnimated( true );
00203 }
00204
00205 void ViewsPanel::save( Config config ) const
00206 {
00207 Panel::save( config );
00208 properties_view_->save( config );
00209 }
00210
00211 void ViewsPanel::load( const Config& config )
00212 {
00213 Panel::load( config );
00214 properties_view_->load( config );
00215 }
00216
00217 }
00218