Change from QPainter to QPaintDevice in the API for PDF rendering

* This is to be able to use QPagedPaintDevice::nextPage in the Multi plot rendering.
This commit is contained in:
Gaute Lindkvist 2019-12-19 10:34:23 +01:00
parent 65f4a5e089
commit 27788b1abd
13 changed files with 46 additions and 33 deletions

View File

@ -40,7 +40,6 @@
#include <QFileInfo> #include <QFileInfo>
#include <QMdiSubWindow> #include <QMdiSubWindow>
#include <QPageLayout> #include <QPageLayout>
#include <QPainter>
#include <QPdfWriter> #include <QPdfWriter>
CAF_CMD_SOURCE_INIT( RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature" ); CAF_CMD_SOURCE_INIT( RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature" );
@ -90,12 +89,11 @@ void RicSnapshotViewToFileFeature::savePlotPDFReportAs( const QString& fileName,
pdfPrinter.setPageLayout( plot->pageLayout() ); pdfPrinter.setPageLayout( plot->pageLayout() );
pdfPrinter.setCreator( QCoreApplication::applicationName() ); pdfPrinter.setCreator( QCoreApplication::applicationName() );
pdfPrinter.setResolution( resolution ); pdfPrinter.setResolution( resolution );
QPainter painter( &pdfPrinter ); QRect widgetRect = plot->viewWidget()->contentsRect();
QRect widgetRect = plot->viewWidget()->contentsRect(); QRect fullPageRect = pdfPrinter.pageLayout().fullRectPixels( resolution );
QRect fullPageRect = pdfPrinter.pageLayout().fullRectPixels( resolution ); QRect paintRect = pdfPrinter.pageLayout().paintRectPixels( resolution );
QRect paintRect = pdfPrinter.pageLayout().paintRectPixels( resolution );
plot->viewWidget()->resize( paintRect.size() ); plot->viewWidget()->resize( paintRect.size() );
plot->renderWindowContent( &painter ); plot->renderWindowContent( &pdfPrinter );
plot->viewWidget()->resize( widgetRect.size() ); plot->viewWidget()->resize( widgetRect.size() );
} }
else else

View File

@ -304,11 +304,11 @@ void RimMultiPlotWindow::doSetAutoScaleYEnabled( bool enabled )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimMultiPlotWindow::doRenderWindowContent( QPainter* painter ) void RimMultiPlotWindow::doRenderWindowContent( QPaintDevice* paintDevice )
{ {
if ( m_viewer ) if ( m_viewer )
{ {
m_viewer->renderTo( painter ); m_viewer->renderTo( paintDevice );
} }
} }
@ -439,9 +439,8 @@ QImage RimMultiPlotWindow::snapshotWindowContent()
if ( m_viewer ) if ( m_viewer )
{ {
QPixmap pix( m_viewer->size() ); QPixmap pix( m_viewer->size() );
QPainter painter( &pix ); m_viewer->renderTo( &pix );
m_viewer->renderTo( &painter );
image = pix.toImage(); image = pix.toImage();
} }

View File

@ -129,7 +129,7 @@ private:
virtual void updateSubPlotNames(); virtual void updateSubPlotNames();
virtual void updatePlotWindowTitle(); virtual void updatePlotWindowTitle();
virtual void doSetAutoScaleYEnabled( bool enabled ); virtual void doSetAutoScaleYEnabled( bool enabled );
void doRenderWindowContent( QPainter* painter ) override; void doRenderWindowContent( QPaintDevice* paintDevice ) override;
protected: protected:
caf::PdmField<bool> m_showPlotWindowTitle; caf::PdmField<bool> m_showPlotWindowTitle;

View File

@ -127,10 +127,10 @@ void RimPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const Q
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimPlot::doRenderWindowContent( QPainter* painter ) void RimPlot::doRenderWindowContent( QPaintDevice* paintDevice )
{ {
if ( viewer() ) if ( viewer() )
{ {
viewer()->renderTo( painter, viewer()->frameGeometry() ); viewer()->renderTo( paintDevice, viewer()->frameGeometry() );
} }
} }

View File

@ -32,6 +32,8 @@ class RiuQwtPlotWidget;
class RimPlotCurve; class RimPlotCurve;
class QwtPlotCurve; class QwtPlotCurve;
class QPaintDevice;
//================================================================================================== //==================================================================================================
/// ///
/// ///
@ -93,7 +95,7 @@ protected:
private: private:
virtual void doRemoveFromCollection() = 0; virtual void doRemoveFromCollection() = 0;
virtual void doRenderWindowContent( QPainter* painter ); virtual void doRenderWindowContent( QPaintDevice* paintDevice );
protected: protected:
caf::PdmField<RowOrColSpanEnum> m_rowSpan; caf::PdmField<RowOrColSpanEnum> m_rowSpan;

View File

@ -159,9 +159,9 @@ void RimPlotWindow::updateParentLayout()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimPlotWindow::renderWindowContent( QPainter* painter ) void RimPlotWindow::renderWindowContent( QPaintDevice* paintDevice )
{ {
doRenderWindowContent( painter ); doRenderWindowContent( paintDevice );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -30,6 +30,7 @@ class RimProject;
class QwtPlotCurve; class QwtPlotCurve;
class QKeyEvent; class QKeyEvent;
class QPaintDevice;
//================================================================================================== //==================================================================================================
/// ///
@ -59,7 +60,7 @@ public:
void updateLayout(); void updateLayout();
void updateParentLayout(); void updateParentLayout();
void renderWindowContent( QPainter* painter ); void renderWindowContent( QPaintDevice* painter );
QPageLayout pageLayout() const; QPageLayout pageLayout() const;
protected: protected:
@ -75,7 +76,7 @@ protected:
private: private:
virtual void doUpdateLayout() {} virtual void doUpdateLayout() {}
virtual bool hasCustomPageLayout( QPageLayout* customPageLayout ) const; virtual bool hasCustomPageLayout( QPageLayout* customPageLayout ) const;
virtual void doRenderWindowContent( QPainter* painter ) = 0; virtual void doRenderWindowContent( QPaintDevice* paintDevice ) = 0;
private: private:
friend class RimProject; friend class RimProject;

View File

@ -284,9 +284,9 @@ void RiuMultiPlotWindow::scheduleReplotOfAllPlots()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuMultiPlotWindow::renderTo( QPainter* painter ) void RiuMultiPlotWindow::renderTo( QPaintDevice* paintDevice )
{ {
doRenderTo( painter ); doRenderTo( paintDevice );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -789,22 +789,23 @@ std::pair<int, int>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuMultiPlotWindow::doRenderTo( QPainter* painter ) void RiuMultiPlotWindow::doRenderTo( QPaintDevice* paintDevice )
{ {
QPainter painter( paintDevice );
setSelectionsVisible( false ); setSelectionsVisible( false );
m_plotTitle->render( painter ); m_plotTitle->render( &painter );
for ( auto subTitle : subTitlesForVisiblePlots() ) for ( auto subTitle : subTitlesForVisiblePlots() )
{ {
if ( subTitle->isVisible() ) if ( subTitle->isVisible() )
{ {
subTitle->render( painter, m_plotWidgetFrame->mapToParent( subTitle->frameGeometry().topLeft() ) ); subTitle->render( &painter, m_plotWidgetFrame->mapToParent( subTitle->frameGeometry().topLeft() ) );
} }
} }
for ( auto legend : legendsForVisiblePlots() ) for ( auto legend : legendsForVisiblePlots() )
{ {
legend->render( painter, m_plotWidgetFrame->mapToParent( legend->frameGeometry().topLeft() ) ); legend->render( &painter, m_plotWidgetFrame->mapToParent( legend->frameGeometry().topLeft() ) );
} }
for ( auto plotWidget : visiblePlotWidgets() ) for ( auto plotWidget : visiblePlotWidgets() )
@ -814,7 +815,7 @@ void RiuMultiPlotWindow::doRenderTo( QPainter* painter )
QPoint plotWidgetFrameTopLeft = m_plotWidgetFrame->frameGeometry().topLeft(); QPoint plotWidgetFrameTopLeft = m_plotWidgetFrame->frameGeometry().topLeft();
plotWidgetGeometry.moveTo( plotWidgetTopLeft + plotWidgetFrameTopLeft ); plotWidgetGeometry.moveTo( plotWidgetTopLeft + plotWidgetFrameTopLeft );
plotWidget->renderTo( painter, plotWidgetGeometry ); plotWidget->renderTo( &painter, plotWidgetGeometry );
} }
setSelectionsVisible( true ); setSelectionsVisible( true );

View File

@ -81,7 +81,7 @@ public:
void scheduleReplotOfAllPlots(); void scheduleReplotOfAllPlots();
virtual void updateVerticalScrollBar( double visibleMin, double visibleMax, double totalMin, double totalMax ) {} virtual void updateVerticalScrollBar( double visibleMin, double visibleMax, double totalMin, double totalMax ) {}
void renderTo( QPainter* painter ); void renderTo( QPaintDevice* paintDevice );
protected: protected:
void contextMenuEvent( QContextMenuEvent* ) override; void contextMenuEvent( QContextMenuEvent* ) override;
@ -114,7 +114,7 @@ protected:
std::pair<int, int> findAvailableRowAndColumn( int startRow, int startColumn, int columnSpan, int columnCount ) const; std::pair<int, int> findAvailableRowAndColumn( int startRow, int startColumn, int columnSpan, int columnCount ) const;
virtual void doRenderTo( QPainter* painter ); virtual void doRenderTo( QPaintDevice* paintDevice );
private slots: private slots:
virtual void performUpdate(); virtual void performUpdate();

View File

@ -606,7 +606,7 @@ bool RiuQwtPlotWidget::isZoomerActive() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::endZoomOperations() {} void RiuQwtPlotWidget::endZoomOperations() {}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect ) void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect )
@ -639,6 +639,15 @@ void RiuQwtPlotWidget::renderTo( QPainter* painter, const QRect& targetRect )
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::renderTo( QPaintDevice* paintDevice, const QRect& targetRect )
{
QPainter painter( paintDevice );
renderTo( &painter, targetRect );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -43,6 +43,8 @@ class QwtPlotPicker;
class QEvent; class QEvent;
class QLabel; class QLabel;
class QPainter;
class QPaintDevice;
//================================================================================================== //==================================================================================================
// //
@ -103,7 +105,8 @@ public:
void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget ); void removeOverlayFrame( RiuDraggableOverlayFrame* overlayWidget );
void updateLayout() override; void updateLayout() override;
void renderTo( QPainter* painter, const QRect& targetRect ); void renderTo( QPainter* painter, const QRect& targetRect );
void renderTo( QPaintDevice* painter, const QRect& targetRect );
int overlayMargins() const; int overlayMargins() const;
protected: protected:

View File

@ -40,10 +40,10 @@ RimWellLogPlot* RiuWellLogPlot::wellLogPlotDefinition()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::doRenderTo( QPainter* painter ) void RiuWellLogPlot::doRenderTo( QPaintDevice* paintDevice )
{ {
m_trackScrollBar->setVisible( false ); m_trackScrollBar->setVisible( false );
RiuMultiPlotWindow::doRenderTo( painter ); RiuMultiPlotWindow::doRenderTo( paintDevice );
m_trackScrollBar->setVisible( true ); m_trackScrollBar->setVisible( true );
} }

View File

@ -37,7 +37,7 @@ protected:
void reinsertScrollbar(); void reinsertScrollbar();
void alignScrollbar( int offset ); void alignScrollbar( int offset );
void doRenderTo( QPainter* painter ) override; void doRenderTo( QPaintDevice* paintDevice ) override;
private: private:
RimWellLogPlot* wellLogPlotDefinition(); RimWellLogPlot* wellLogPlotDefinition();