Skip to content

Commit

Permalink
correctly show/close associated_widget_panels
Browse files Browse the repository at this point in the history
This resolves several open issues of displays with associated widgets (e.g. Camera and Image).
- when minimizing / unminimizing the main window, the enabled status of those displays changed
- tabbed DockWidgets were closed (and couldn't easily be reopened by enabling the display)
  • Loading branch information
rhaschke committed Aug 30, 2019
1 parent 0969fef commit aea864d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
6 changes: 1 addition & 5 deletions src/rviz/default_plugin/camera_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ CameraDisplay::~CameraDisplay()
unsubscribe();
caminfo_tf_filter_->clear();


//workaround. delete results in a later crash
render_panel_->hide();
//delete render_panel_;

delete render_panel_;
delete bg_screen_rect_;
delete fg_screen_rect_;

Expand Down
42 changes: 23 additions & 19 deletions src/rviz/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Display::Display()
, visibility_bits_( 0xFFFFFFFF )
, associated_widget_( NULL )
, associated_widget_panel_( NULL )
, associated_widget_visible_( false )
{
// Needed for timeSignal (see header) to work across threads
qRegisterMetaType<ros::Time>();
Expand Down Expand Up @@ -296,36 +297,42 @@ void Display::onEnableChanged()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
queueRender();
/* We get here, by two different routes:
* - First, we might have disabled the display.
* In this case we want to close/hide the associated widget.
* But there is an exception: tabbed DockWidgets shouldn't be hidden, because then we would loose the tab.
* - Second, the corresponding widget changed visibility and we got here via associatedPanelVisibilityChange().
* In this case, it's usually counterproductive to show/hide the widget here.
* Typical cases are: main window was minimized/unminimized, tab was switched.
*/
if( isEnabled() )
{
scene_node_->setVisible( true );

if( associated_widget_panel_ )
{
associated_widget_panel_->show();
if (!associated_widget_visible_)
associated_widget_panel_->show();
else
associated_widget_panel_->setFocus();
}
else if( associated_widget_ )
{
associated_widget_->show();
}

onEnable();
if( isEnabled() ) // status might have changed, e.g. if show() failed
onEnable();
}
else
{
onDisable();

if( associated_widget_panel_ )
{
if( associated_widget_panel_->isVisible() )
{
if( associated_widget_visible_ )
associated_widget_panel_->hide();
}
}
else if( associated_widget_ && associated_widget_->isVisible() )
{
else if( associated_widget_ )
associated_widget_->hide();
}

scene_node_->setVisible( false );
}
Expand Down Expand Up @@ -359,6 +366,7 @@ void Display::setAssociatedWidget( QWidget* widget )
if( wm )
{
associated_widget_panel_ = wm->addPane( getName(), associated_widget_ );
associated_widget_visible_ = true;
connect( associated_widget_panel_, SIGNAL( visibilityChanged( bool ) ), this, SLOT( associatedPanelVisibilityChange( bool ) ));
connect( associated_widget_panel_, SIGNAL( closed( ) ), this, SLOT( disable( )));
associated_widget_panel_->setIcon( getIcon() );
Expand All @@ -377,15 +385,11 @@ void Display::setAssociatedWidget( QWidget* widget )

void Display::associatedPanelVisibilityChange( bool visible )
{
// if something external makes the panel visible, make sure we're enabled
if ( visible )
{
setEnabled( true );
}
else
{
setEnabled( false );
}
associated_widget_visible_ = visible;
// If something external makes the panel visible/invisible, make sure to enable/disable the display
setEnabled(visible);
// Remark: vice versa, in Display::onEnableChanged(),
// the panel is made visible/invisible when the display is enabled/disabled
}

void Display::setIcon( const QIcon& icon )
Expand Down
1 change: 1 addition & 0 deletions src/rviz/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ private Q_SLOTS:
uint32_t visibility_bits_;
QWidget* associated_widget_;
PanelDockWidget* associated_widget_panel_;
bool associated_widget_visible_;
};

} // end namespace rviz
Expand Down

0 comments on commit aea864d

Please sign in to comment.