Skip to content

Commit

Permalink
Add copy button to duplicate display with same config
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Mar 14, 2016
1 parent 0d423d6 commit c3bc81f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/rviz/displays_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ DisplaysPanel::DisplaysPanel( QWidget* parent )
QPushButton* add_button = new QPushButton( "Add" );
add_button->setShortcut( QKeySequence( QString( "Ctrl+N" )));
add_button->setToolTip( "Add a new display, Ctrl+N" );
copy_button_ = new QPushButton( "Copy" );
copy_button_->setShortcut( QKeySequence( QString( "Ctrl+C" )));
copy_button_->setToolTip( "Copy a display, Ctrl+C" );
copy_button_->setEnabled( false );
remove_button_ = new QPushButton( "Remove" );
remove_button_->setShortcut( QKeySequence( QString( "Ctrl+X" )));
remove_button_->setToolTip( "Remove displays, Ctrl+X" );
Expand All @@ -69,6 +73,7 @@ DisplaysPanel::DisplaysPanel( QWidget* parent )

QHBoxLayout* button_layout = new QHBoxLayout;
button_layout->addWidget( add_button );
button_layout->addWidget( copy_button_ );
button_layout->addWidget( remove_button_ );
button_layout->addWidget( rename_button_ );
button_layout->setContentsMargins( 2, 0, 2, 2 );
Expand All @@ -81,6 +86,7 @@ DisplaysPanel::DisplaysPanel( QWidget* parent )
setLayout( layout );

connect( add_button, SIGNAL( clicked( bool )), this, SLOT( onNewDisplay() ));
connect( copy_button_, SIGNAL( clicked( bool )), this, SLOT( onCopyDisplay() ));
connect( remove_button_, SIGNAL( clicked( bool )), this, SLOT( onDeleteDisplay() ));
connect( rename_button_, SIGNAL( clicked( bool )), this, SLOT( onRenameDisplay() ));
connect( property_grid_, SIGNAL( selectionHasChanged() ), this, SLOT( onSelectionChanged() ));
Expand Down Expand Up @@ -127,6 +133,25 @@ void DisplaysPanel::onNewDisplay()
activateWindow(); // Force keyboard focus back on main window.
}

void DisplaysPanel::onCopyDisplay()
{
QList<Display*> displays_to_copy = property_grid_->getSelectedObjects<Display>();

for( int i = 0; i < displays_to_copy.size(); i++ )
{
// initialize display
QString lookup_name = displays_to_copy[ i ]->getClassId();
QString display_name = displays_to_copy[ i ]->getName();
Display *disp = vis_manager_->createDisplay( lookup_name, display_name, true );
// copy config
Config config;
displays_to_copy[ i ]->save(config);
disp->load(config);
}
vis_manager_->startUpdate();
activateWindow(); // Force keyboard focus back on main window.
}

void DisplaysPanel::onDeleteDisplay()
{
QList<Display*> displays_to_delete = property_grid_->getSelectedObjects<Display>();
Expand All @@ -148,6 +173,7 @@ void DisplaysPanel::onSelectionChanged()

int num_displays_selected = displays.size();

copy_button_->setEnabled( num_displays_selected > 0 );
remove_button_->setEnabled( num_displays_selected > 0 );
rename_button_->setEnabled( num_displays_selected == 1 );
}
Expand Down
3 changes: 3 additions & 0 deletions src/rviz/displays_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Q_OBJECT
protected Q_SLOTS:
/// Called when the "Add" button is pressed
void onNewDisplay();
/// Called when the "copy" button is pressed
void onCopyDisplay();
/// Called when the "Remove" button is pressed
void onDeleteDisplay();
/// Called when the "Rename" button is pressed
Expand All @@ -81,6 +83,7 @@ protected Q_SLOTS:
protected:
PropertyTreeWidget* property_grid_;

QPushButton* copy_button_;
QPushButton* remove_button_;
QPushButton* rename_button_;
PropertyTreeWithHelp* tree_with_help_;
Expand Down

0 comments on commit c3bc81f

Please sign in to comment.