From b1fb7990dc5be3cc39de4885de477d5175137673 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 28 Aug 2020 13:19:51 +0200 Subject: [PATCH] #6393 Snapshot : Make sure widgets are activated before taking snapshot If the active plot window is maximized in the MDI area, all plots will create the same snapshot size. --- .../CommandFileInterface/RicfExportSnapshots.cpp | 6 ++++++ .../RicSnapshotAllPlotsToFileFeature.cpp | 13 ++++++++++++- .../RicSnapshotAllPlotsToFileFeature.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp index 1d671f8e1f..a5b7248243 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp @@ -113,16 +113,22 @@ caf::PdmScriptResponse RicfExportSnapshots::execute() } if ( m_type == RicfExportSnapshots::SnapshotsType::PLOTS || m_type == RicfExportSnapshots::SnapshotsType::ALL ) { + bool activateWidget = false; if ( RiaRegressionTestRunner::instance()->isRunningRegressionTests() ) { RiaRegressionTestRunner::setDefaultSnapshotSizeForPlotWindows(); QApplication::processEvents(); } + else + { + activateWidget = true; + } QString fileSuffix = ".png"; if ( m_plotOutputFormat == PlotOutputFormat::PDF ) fileSuffix = ".pdf"; RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( absolutePathToSnapshotDir, + activateWidget, m_prefix, m_viewId(), fileSuffix ); diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp index 1fc3cd6103..b2e0463096 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.cpp @@ -57,7 +57,8 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots() // Save images in snapshot catalog relative to project directory QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath( "snapshots" ); - exportSnapshotOfPlotsIntoFolder( snapshotFolderName ); + bool activateWidget = true; + exportSnapshotOfPlotsIntoFolder( snapshotFolderName, activateWidget ); QString text = QString( "Exported snapshots to folder : \n%1" ).arg( snapshotFolderName ); RiaLogging::info( text ); @@ -67,6 +68,7 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots() /// //-------------------------------------------------------------------------------------------------- void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( const QString& snapshotFolderName, + bool activateWidget, const QString& prefix, int viewId, const QString& preferredFileSuffix /*=".png"*/ ) @@ -99,6 +101,15 @@ void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( const QS fileName.replace( " ", "_" ); + if ( activateWidget ) + { + // If the active MDI widget is maximized, all widgets will be maximized in the MDI area before taking + // snapshots + + RiuPlotMainWindowTools::selectAsCurrentItem( viewWindow ); + QApplication::processEvents(); + } + QString absoluteFileName = caf::Utils::constructFullFileName( absSnapshotPath, fileName, preferredFileSuffix ); RicSnapshotViewToFileFeature::saveSnapshotAs( absoluteFileName, viewWindow ); diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h index 2df7dbce22..158e8f7bc6 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllPlotsToFileFeature.h @@ -33,6 +33,7 @@ public: static void saveAllPlots(); static void exportSnapshotOfPlotsIntoFolder( const QString& snapshotFolderName, + bool activateWidget = false, const QString& prefix = "", int viewId = -1, const QString& preferredFileSuffix = ".png" );