Skip to content

Commit

Permalink
Add "Duplicate" button to duplicate display with same config
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Mar 22, 2016
1 parent 0d423d6 commit 9b99fc2
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" );
duplicate_button_ = new QPushButton( "Duplicate" );
duplicate_button_->setShortcut( QKeySequence( QString( "Ctrl+D" )));
duplicate_button_->setToolTip( "Duplicate a display, Ctrl+D" );
duplicate_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( duplicate_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( duplicate_button_, SIGNAL( clicked( bool )), this, SLOT( onDuplicateDisplay() ));
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::onDuplicateDisplay()
{
QList<Display*> displays_to_duplicate = property_grid_->getSelectedObjects<Display>();

for( int i = 0; i < displays_to_duplicate.size(); i++ )
{
// initialize display
QString lookup_name = displays_to_duplicate[ i ]->getClassId();
QString display_name = displays_to_duplicate[ i ]->getName();
Display *disp = vis_manager_->createDisplay( lookup_name, display_name, true );
// duplicate config
Config config;
displays_to_duplicate[ 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();

duplicate_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 onDuplicateDisplay();
/// 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* duplicate_button_;
QPushButton* remove_button_;
QPushButton* rename_button_;
PropertyTreeWithHelp* tree_with_help_;
Expand Down

0 comments on commit 9b99fc2

Please sign in to comment.