Pass dock widget to internalCaptureSnapshot from the call site

Take the view's dock widget as a parameter instead of discovering it by walking the widget parent chain, so the caller supplies it directly. Also forward declare QImage in RimViewWindow.h instead of including it, and drop now unused includes in RimViewWindow.cpp.
This commit is contained in:
Magne Sjaastad committed 2026-06-19 16:38:41 +02:00
1 parent 8369fad029
commit 21d3869e44
3 files changed
+17 -10

No files matched your search

@@ -650,7 +650,7 @@ QImage RimMultiPlot::captureSnapshot( int width, int height )
QSize orgViewSize = m_viewer->size(); QSize orgViewSize = m_viewer->size();
image = RimViewWindow::internalCaptureSnapshot( m_viewer->bookWidget(), width, height ); image = RimViewWindow::internalCaptureSnapshot( m_dockWidget, m_viewer->bookWidget(), width, height );
m_viewer->resize( orgViewSize ); m_viewer->resize( orgViewSize );
doUpdateLayout(); doUpdateLayout();
@@ -20,24 +20,21 @@
#include "RiaColorTables.h" #include "RiaColorTables.h"
#include "RiaColorTools.h" #include "RiaColorTools.h"
#include "RiaFieldHandleTools.h"
#include "RiaGuiApplication.h" #include "RiaGuiApplication.h"
#include "RiaPreferencesSystem.h" #include "RiaPreferencesSystem.h"
#include "RicfCommandObject.h" #include "RicfCommandObject.h"
#include "RimDockWindowController.h" #include "RimDockWindowController.h"
#include "RimProject.h"
#include "RiuDockWidgetTools.h" #include "RiuDockWidgetTools.h"
#include "cafPdmUiTreeAttributes.h" #include "cafPdmUiTreeAttributes.h"
#include "cafPdmUiTreeViewEditor.h"
#include "DockManager.h" #include "DockManager.h"
#include "DockWidget.h" #include "DockWidget.h"
#include <QDebug> #include <QApplication>
#include <QImage> #include <QImage>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
@@ -234,22 +231,33 @@ QImage RimViewWindow::snapshotWindowContent()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QImage RimViewWindow::captureSnapshot( int width, int height ) QImage RimViewWindow::captureSnapshot( int width, int height )
{ {
return internalCaptureSnapshot( viewWidget(), width, height ); return internalCaptureSnapshot( m_dockWidget, viewWidget(), width, height );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QImage RimViewWindow::internalCaptureSnapshot( QWidget* widget, int width, int height ) QImage RimViewWindow::internalCaptureSnapshot( ads::CDockWidget* dockWidget, QWidget* widget, int width, int height )
{ {
if ( !widget ) return QImage(); if ( !widget ) return QImage();
if ( dockWidget && !dockWidget->isCurrentTab() )
{
// Move the dock widget that is stacked behind others in the same dock area to the top to make sure the snapshot is rendered
dockWidget->setAsCurrentTab();
QApplication::processEvents();
}
bool shouldResize = width > 0 && height > 0 && ( widget->width() != width || widget->height() != height ); bool shouldResize = width > 0 && height > 0 && ( widget->width() != width || widget->height() != height );
QSize orgSize = widget->size(); QSize orgSize = widget->size();
if ( shouldResize ) if ( shouldResize )
{ {
widget->setFixedSize( width, height ); widget->setFixedSize( width, height );
// setFixedSize() only posts a deferred resize. If the pending resize is delivered from inside QWidget::render() below, a child
// QScrollArea may move its viewport mid-render and crash in Qt's backing-store blit (QWidgetRepaintManager::bltRect).
QApplication::processEvents();
} }
else else
{ {
@@ -25,8 +25,7 @@
#include "cafPdmField.h" #include "cafPdmField.h"
#include "cafPdmObject.h" #include "cafPdmObject.h"
#include <QImage> class QImage;
class RimDockWindowController; class RimDockWindowController;
namespace ads namespace ads
@@ -103,7 +102,7 @@ protected:
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
static QImage internalCaptureSnapshot( QWidget* widget, int width, int height ); static QImage internalCaptureSnapshot( ads::CDockWidget* dockWidget, QWidget* widget, int width, int height );
private: private:
friend class RimProject; friend class RimProject;