#5528 Multi Plot : Add feature for export of PDF documents

This commit is contained in:
Magne Sjaastad 2020-02-17 11:11:11 +01:00
parent eacc8a852e
commit a3519a6e00
6 changed files with 152 additions and 11 deletions

View File

@ -18,6 +18,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicSnapshotAllViewsToFileFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotFilenameGenerator.h
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToClipboardFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToFileFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToPdfFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportSelectedWellPathsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportVisibleWellPathsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicExportWellPathsUi.h
@ -47,6 +48,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicSnapshotAllViewsToFileFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotFilenameGenerator.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToClipboardFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToFileFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSnapshotViewToPdfFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportSelectedWellPathsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportVisibleWellPathsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicExportWellPathsUi.cpp

View File

@ -53,7 +53,7 @@ void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, RimV
RimPlotWindow* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
if ( plotWindow && fileName.endsWith( ".pdf" ) )
{
savePlotPDFReportAs( fileName, plotWindow );
savePlotPdfReportAs( fileName, plotWindow );
}
else if ( viewWindow )
{
@ -83,7 +83,7 @@ void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, cons
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::savePlotPDFReportAs( const QString& fileName, RimPlotWindow* plot )
void RicSnapshotViewToFileFeature::savePlotPdfReportAs( const QString& fileName, RimPlotWindow* plot )
{
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdatesAndReplots();
QCoreApplication::processEvents();
@ -146,7 +146,7 @@ void RicSnapshotViewToFileFeature::saveViewWindowToFile( RimViewWindow* viewWind
{
if ( plotWindow && fileName.endsWith( "PDF", Qt::CaseInsensitive ) )
{
savePlotPDFReportAs( fileName, plotWindow );
savePlotPdfReportAs( fileName, plotWindow );
}
else
{
@ -170,8 +170,9 @@ void RicSnapshotViewToFileFeature::saveImageToFile( const QImage& image, const Q
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSnapshotViewToFileFeature::generateSaveFileName( const QString& defaultFileBaseName /*= "image"*/,
bool supportPDF /*= false */ )
QString RicSnapshotViewToFileFeature::generateSaveFileName( const QString& defaultFileBaseName,
bool supportPDF,
const QString& defaultExtension )
{
RiaApplication* app = RiaApplication::instance();
RimProject* proj = app->project();
@ -195,14 +196,25 @@ QString RicSnapshotViewToFileFeature::generateSaveFileName( const QString& defau
<< "*.pgm";
QString fileExtensionFilter = QString( "Images (%1)" ).arg( imageFileExtensions.join( " " ) );
QString pdfFilter = "PDF report( *.pdf )";
if ( supportPDF )
{
fileExtensionFilter += ";;PDF report( *.pdf )";
fileExtensionFilter += QString( ";;%1" ).arg( pdfFilter );
}
QString defaultAbsFileName = caf::Utils::constructFullFileName( startPath, defaultFileBaseName, ".png" );
QString fileName =
QFileDialog::getSaveFileName( nullptr, tr( "Export to File" ), defaultAbsFileName, fileExtensionFilter );
QString defaultAbsFileName =
caf::Utils::constructFullFileName( startPath, defaultFileBaseName, "." + defaultExtension );
QString selectedExtension;
if ( supportPDF )
{
selectedExtension = pdfFilter;
}
QString fileName = QFileDialog::getSaveFileName( nullptr,
tr( "Export to File" ),
defaultAbsFileName,
fileExtensionFilter,
&selectedExtension );
if ( !fileName.isEmpty() )
{
// Remember the directory to next time

View File

@ -34,11 +34,13 @@ class RicSnapshotViewToFileFeature : public caf::CmdFeature
public:
static void saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow );
static void saveSnapshotAs( const QString& fileName, const QImage& image );
static void savePlotPDFReportAs( const QString& fileName, RimPlotWindow* plotWindow );
static void savePlotPdfReportAs( const QString& fileName, RimPlotWindow* plotWindow );
static void saveViewWindowToFile( RimViewWindow* viewWindow, const QString& defaultFileBaseName = "image" );
static void saveImageToFile( const QImage& image, const QString& defaultFileBaseName = "image" );
static QString generateSaveFileName( const QString& defaultFileBaseName = "image", bool supportPDF = false );
static QString generateSaveFileName( const QString& defaultFileBaseName = "image",
bool supportPDF = false,
const QString& defaultExtension = "png" );
static QIcon icon();
static QString text();

View File

@ -0,0 +1,84 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicSnapshotViewToPdfFeature.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RicSnapshotFilenameGenerator.h"
#include "RicSnapshotViewToFileFeature.h"
#include "RimPlotWindow.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicSnapshotViewToPdfFeature, "RicSnapshotViewToPdfFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSnapshotViewToPdfFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToPdfFeature::onActionTriggered( bool isChecked )
{
// Get active view window before displaying the file selection dialog
// If this is done after the file save dialog is displayed (and closed)
// app->activeViewWindow() returns nullptr on Linux
RimViewWindow* viewWindow = RiaGuiApplication::activeViewWindow();
if ( !viewWindow )
{
RiaLogging::error( "No view window is available, nothing to do" );
return;
}
RimPlotWindow* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
if ( plotWindow )
{
QString fileExtension = "pdf";
QString defaultFileName = RicSnapshotFilenameGenerator::generateSnapshotFileName( viewWindow );
QString fileName = RicSnapshotViewToFileFeature::generateSaveFileName( defaultFileName, true, fileExtension );
if ( !fileName.isEmpty() )
{
if ( plotWindow && fileName.endsWith( "PDF", Qt::CaseInsensitive ) )
{
RicSnapshotViewToFileFeature::savePlotPdfReportAs( fileName, plotWindow );
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToPdfFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "PDF" );
// TODO : When icon is created, use the text below
// actionToSetup->setText( "Export View To PDF" );
// actionToSetup->setIcon( QIcon( ":/SnapShotSave.png" ) );
}

View File

@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
class RimPlotWindow;
class RimViewWindow;
class QImage;
//==================================================================================================
///
//==================================================================================================
class RicSnapshotViewToPdfFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -277,6 +277,7 @@ void RiuPlotMainWindow::createMenus()
QMenu* exportMenu = fileMenu->addMenu( "&Export" );
exportMenu->addAction( cmdFeatureMgr->action( "RicSnapshotViewToFileFeature" ) );
exportMenu->addAction( cmdFeatureMgr->action( "RicSnapshotViewToPdfFeature" ) );
exportMenu->addAction( cmdFeatureMgr->action( "RicSnapshotAllPlotsToFileFeature" ) );
exportMenu->addAction( cmdFeatureMgr->action( "RicSaveEclipseInputActiveVisibleCellsFeature" ) );
@ -299,6 +300,7 @@ void RiuPlotMainWindow::createMenus()
QMenu* editMenu = menuBar()->addMenu( "&Edit" );
editMenu->addAction( cmdFeatureMgr->action( "RicSnapshotViewToClipboardFeature" ) );
editMenu->addAction( cmdFeatureMgr->action( "RicSnapshotViewToFileFeature" ) );
editMenu->addAction( cmdFeatureMgr->action( "RicSnapshotViewToPdfFeature" ) );
editMenu->addSeparator();
editMenu->addAction( cmdFeatureMgr->action( "RicEditPreferencesFeature" ) );
@ -349,6 +351,7 @@ QStringList RiuPlotMainWindow::toolbarCommandIds( const QString& toolbarName )
{
commandIds << "RicSnapshotViewToClipboardFeature";
commandIds << "RicSnapshotViewToFileFeature";
commandIds << "RicSnapshotViewToPdfFeature";
commandIds << "RicSnapshotAllPlotsToFileFeature";
}