#8348 Theme : Changing theme when maximized plot window causes crash

This commit is contained in:
Magne Sjaastad 2021-12-03 14:27:29 +01:00
parent 9edb0385d5
commit e4357a9ab3

View File

@ -87,9 +87,21 @@ void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, cons
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName, RimPlotWindow* plot )
{
auto currentTheme = RiuGuiTheme::currentGuiTheme();
if ( !plot || !plot->viewWidget() ) return;
auto viewWidget = plot->viewWidget();
// For some reason, the application crashes (seen on Windows 11) if the theme is changed when a plot window is
// maximized. Make sure the MDI windows are displayed as normal, and restore the maximized state
bool maximizedState = viewWidget->isMaximized();
if ( maximizedState ) viewWidget->showNormal();
auto currentTheme = RiuGuiTheme::currentGuiTheme();
if ( currentTheme != RiaDefines::ThemeEnum::LIGHT )
{
RiuGuiTheme::updateGuiTheme( RiaDefines::ThemeEnum::LIGHT );
}
RiuGuiTheme::updateGuiTheme( RiaDefines::ThemeEnum::LIGHT );
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdatesAndReplots();
QCoreApplication::processEvents();
QFile pdfFile( fileName );
@ -97,7 +109,7 @@ void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName,
{
int resolution = RiaGuiApplication::applicationResolution();
int pageWidth = plot->pageLayout().fullRectPixels( resolution ).width();
int widgetWidth = plot->viewWidget()->width();
int widgetWidth = viewWidget->width();
int deltaWidth = widgetWidth - pageWidth;
while ( std::abs( deltaWidth ) > 1 )
@ -114,29 +126,35 @@ void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName,
pdfPrinter.setPageLayout( plot->pageLayout() );
pdfPrinter.setCreator( QCoreApplication::applicationName() );
pdfPrinter.setResolution( resolution );
QRect widgetRect = plot->viewWidget()->contentsRect();
QRect widgetRect = viewWidget->contentsRect();
RimMultiPlot* multiPlot = dynamic_cast<RimMultiPlot*>( plot );
if ( multiPlot && multiPlot->previewModeEnabled() )
{
QRect pageRect = pdfPrinter.pageLayout().fullRectPixels( resolution );
plot->viewWidget()->resize( pageRect.size() );
viewWidget->resize( pageRect.size() );
plot->renderWindowContent( &pdfPrinter );
plot->viewWidget()->resize( widgetRect.size() );
viewWidget->resize( widgetRect.size() );
}
else
{
QRect pageRect = pdfPrinter.pageLayout().paintRectPixels( resolution );
plot->viewWidget()->resize( pageRect.size() );
viewWidget->resize( pageRect.size() );
plot->renderWindowContent( &pdfPrinter );
plot->viewWidget()->resize( widgetRect.size() );
viewWidget->resize( widgetRect.size() );
}
}
else
{
RiaLogging::error( QString( "Could not write PDF to %1" ).arg( fileName ) );
}
RiuGuiTheme::updateGuiTheme( currentTheme );
if ( currentTheme != RiaDefines::ThemeEnum::LIGHT )
{
RiuGuiTheme::updateGuiTheme( currentTheme );
}
if ( maximizedState ) viewWidget->showMaximized();
}
//--------------------------------------------------------------------------------------------------