qwt_plot_renderer.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_renderer.h"
#include "qwt_plot.h"
#include "qwt_painter.h"
#include "qwt_plot_layout.h"
#include "qwt_abstract_legend.h"
#include "qwt_scale_widget.h"
#include "qwt_scale_engine.h"
#include "qwt_scale_map.h"
#include "qwt_text.h"
#include "qwt_text_label.h"
#include "qwt_math.h"
#include <qpainter.h>
#include <qpainterpath.h>
#include <qtransform.h>
#include <qprinter.h>
#include <qfiledialog.h>
#include <qfileinfo.h>
#include <qimagewriter.h>
#include <qvariant.h>
#include <qmargins.h>
#ifndef QWT_NO_SVG
#ifdef QT_SVG_LIB
#define QWT_FORMAT_SVG 1
#endif
#endif
#ifndef QT_NO_PRINTER
#define QWT_FORMAT_PDF 1
#endif
#ifndef QT_NO_PDF
// QPdfWriter::setResolution() has been introduced with
// Qt 5.3. Guess it is o.k. to stay with QPrinter for older
// versions.
#if QT_VERSION >= 0x050300
#ifndef QWT_FORMAT_PDF
#define QWT_FORMAT_PDF 1
#endif
#define QWT_PDF_WRITER 1
#endif
#endif
#ifndef QT_NO_PRINTER
// postscript support has been dropped in Qt5
#if QT_VERSION < 0x050000
#define QWT_FORMAT_POSTSCRIPT 1
#endif
#endif
#if QWT_FORMAT_SVG
#include <qsvggenerator.h>
#endif
#if QWT_PDF_WRITER
#include <qpdfwriter.h>
#endif
static qreal qwtScalePenWidth( const QwtPlot* plot )
{
qreal pw = 0.0;
for ( int axisId = 0; axisId < QwtAxis::AxisPositions; axisId++ )
{
if ( plot->isAxisVisible( axisId ) )
pw = qMax( pw, plot->axisScaleDraw( axisId )->penWidthF() );
}
return pw;
}
static QColor qwtScalePenColor( const QwtPlot* plot )
{
const QPalette pal = plot->axisWidget( QwtAxis::YLeft )->palette();
return pal.color( QPalette::WindowText );
}
static QPainterPath qwtCanvasClip(
const QWidget* canvas, const QRectF& canvasRect )
{
// The clip region is calculated in integers
// To avoid too much rounding errors better
// calculate it in target device resolution
int x1 = qwtCeil( canvasRect.left() );
int x2 = qwtFloor( canvasRect.right() );
int y1 = qwtCeil( canvasRect.top() );
int y2 = qwtFloor( canvasRect.bottom() );
const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 );
QPainterPath clipPath;
( void ) QMetaObject::invokeMethod(
const_cast< QWidget* >( canvas ), "borderPath",
Qt::DirectConnection,
Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) );
return clipPath;
}
static inline QFont qwtResolvedFont( const QWidget* widget )
{
QFont font = widget->font();
#if QT_VERSION >= 0x060000
font.setResolveMask( QFont::AllPropertiesResolved );
#else
font.resolve( QFont::AllPropertiesResolved );
#endif
return font;
}
class QwtPlotRenderer::PrivateData
{
public:
PrivateData()
: discardFlags( QwtPlotRenderer::DiscardNone )
, layoutFlags( QwtPlotRenderer::DefaultLayout )
{
}
QwtPlotRenderer::DiscardFlags discardFlags;
QwtPlotRenderer::LayoutFlags layoutFlags;
};
QwtPlotRenderer::QwtPlotRenderer( QObject* parent )
: QObject( parent )
{
m_data = new PrivateData;
}
QwtPlotRenderer::~QwtPlotRenderer()
{
delete m_data;
}
void QwtPlotRenderer::setDiscardFlag( DiscardFlag flag, bool on )
{
if ( on )
m_data->discardFlags |= flag;
else
m_data->discardFlags &= ~flag;
}
bool QwtPlotRenderer::testDiscardFlag( DiscardFlag flag ) const
{
return m_data->discardFlags & flag;
}
void QwtPlotRenderer::setDiscardFlags( DiscardFlags flags )
{
m_data->discardFlags = flags;
}
QwtPlotRenderer::DiscardFlags QwtPlotRenderer::discardFlags() const
{
return m_data->discardFlags;
}
void QwtPlotRenderer::setLayoutFlag( LayoutFlag flag, bool on )
{
if ( on )
m_data->layoutFlags |= flag;
else
m_data->layoutFlags &= ~flag;
}
bool QwtPlotRenderer::testLayoutFlag( LayoutFlag flag ) const
{
return m_data->layoutFlags & flag;
}
void QwtPlotRenderer::setLayoutFlags( LayoutFlags flags )
{
m_data->layoutFlags = flags;
}
QwtPlotRenderer::LayoutFlags QwtPlotRenderer::layoutFlags() const
{
return m_data->layoutFlags;
}
void QwtPlotRenderer::renderDocument( QwtPlot* plot,
const QString& fileName, const QSizeF& sizeMM, int resolution )
{
renderDocument( plot, fileName,
QFileInfo( fileName ).suffix(), sizeMM, resolution );
}
void QwtPlotRenderer::renderDocument( QwtPlot* plot,
const QString& fileName, const QString& format,
const QSizeF& sizeMM, int resolution )
{
if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
return;
QString title = plot->title().text();
if ( title.isEmpty() )
title = "Plot Document";
const double mmToInch = 1.0 / 25.4;
const QSizeF size = sizeMM * mmToInch * resolution;
const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );
const QString fmt = format.toLower();
if ( fmt == QLatin1String( "pdf" ) )
{
#if QWT_FORMAT_PDF
#if QWT_PDF_WRITER
QPdfWriter pdfWriter( fileName );
pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) );
pdfWriter.setTitle( title );
pdfWriter.setPageMargins( QMarginsF() );
pdfWriter.setResolution( resolution );
QPainter painter( &pdfWriter );
render( plot, &painter, documentRect );
#else
QPrinter printer;
printer.setOutputFormat( QPrinter::PdfFormat );
printer.setColorMode( QPrinter::Color );
printer.setFullPage( true );
printer.setPaperSize( sizeMM, QPrinter::Millimeter );
printer.setDocName( title );
printer.setOutputFileName( fileName );
printer.setResolution( resolution );
QPainter painter( &printer );
render( plot, &painter, documentRect );
#endif
#endif
}
else if ( fmt == QLatin1String( "ps" ) )
{
#if QWT_FORMAT_POSTSCRIPT
QPrinter printer;
printer.setOutputFormat( QPrinter::PostScriptFormat );
printer.setColorMode( QPrinter::Color );
printer.setFullPage( true );
printer.setPaperSize( sizeMM, QPrinter::Millimeter );
printer.setDocName( title );
printer.setOutputFileName( fileName );
printer.setResolution( resolution );
QPainter painter( &printer );
render( plot, &painter, documentRect );
#endif
}
else if ( fmt == QLatin1String( "svg" ) )
{
#if QWT_FORMAT_SVG
QSvgGenerator generator;
generator.setTitle( title );
generator.setFileName( fileName );
generator.setResolution( resolution );
generator.setViewBox( documentRect );
QPainter painter( &generator );
render( plot, &painter, documentRect );
#endif
}
else
{
if ( QImageWriter::supportedImageFormats().indexOf(
format.toLatin1() ) >= 0 )
{
const QRect imageRect = documentRect.toRect();
const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 );
QImage image( imageRect.size(), QImage::Format_ARGB32 );
image.setDotsPerMeterX( dotsPerMeter );
image.setDotsPerMeterY( dotsPerMeter );
image.fill( QColor( Qt::white ).rgb() );
QPainter painter( &image );
render( plot, &painter, imageRect );
painter.end();
image.save( fileName, format.toLatin1() );
}
}
}
void QwtPlotRenderer::renderTo(
QwtPlot* plot, QPaintDevice& paintDevice ) const
{
int w = paintDevice.width();
int h = paintDevice.height();
QPainter p( &paintDevice );
render( plot, &p, QRectF( 0, 0, w, h ) );
}
#ifndef QT_NO_PRINTER
void QwtPlotRenderer::renderTo(
QwtPlot* plot, QPrinter& printer ) const
{
int w = printer.width();
int h = printer.height();
QRectF rect( 0, 0, w, h );
double aspect = rect.width() / rect.height();
if ( ( aspect < 1.0 ) )
rect.setHeight( aspect * rect.width() );
QPainter p( &printer );
render( plot, &p, rect );
}
#endif
#if QWT_FORMAT_SVG
void QwtPlotRenderer::renderTo(
QwtPlot* plot, QSvgGenerator& generator ) const
{
QRectF rect = generator.viewBoxF();
if ( rect.isEmpty() )
rect.setRect( 0, 0, generator.width(), generator.height() );
if ( rect.isEmpty() )
rect.setRect( 0, 0, 800, 600 ); // something
QPainter p( &generator );
render( plot, &p, rect );
}
#endif
void QwtPlotRenderer::render( QwtPlot* plot,
QPainter* painter, const QRectF& plotRect ) const
{
if ( painter == 0 || !painter->isActive() ||
!plotRect.isValid() || plot->size().isNull() )
{
return;
}
if ( !( m_data->discardFlags & DiscardBackground ) )
QwtPainter::drawBackgound( painter, plotRect, plot );
/*
The layout engine uses the same methods as they are used
by the Qt layout system. Therefore we need to calculate the
layout in screen coordinates and paint with a scaled painter.
*/
QTransform transform;
transform.scale(
double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );
QRectF layoutRect = transform.inverted().mapRect( plotRect );
if ( !( m_data->discardFlags & DiscardBackground ) )
{
// subtract the contents margins
const QMargins m = plot->contentsMargins();
layoutRect.adjust( m.left(), m.top(), -m.right(), -m.bottom() );
}
QwtPlotLayout* layout = plot->plotLayout();
int baseLineDists[QwtAxis::AxisPositions];
int canvasMargins[QwtAxis::AxisPositions];
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
canvasMargins[axisPos] = layout->canvasMargin( axisPos );
if ( m_data->layoutFlags & FrameWithScales )
{
const QwtAxisId axisId( axisPos );
QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
if ( scaleWidget )
{
baseLineDists[axisPos] = scaleWidget->margin();
scaleWidget->setMargin( 0 );
}
if ( !plot->isAxisVisible( axisId ) )
{
// When we have a scale the frame is painted on
// the position of the backbone - otherwise we
// need to introduce a margin around the canvas
const qreal fw = qwtScalePenWidth( plot );
switch( axisPos )
{
case QwtAxis::YLeft:
layoutRect.adjust( fw, 0, 0, 0 );
break;
case QwtAxis::YRight:
layoutRect.adjust( 0, 0, -fw, 0 );
break;
case QwtAxis::XTop:
layoutRect.adjust( 0, fw, 0, 0 );
break;
case QwtAxis::XBottom:
layoutRect.adjust( 0, 0, 0, -fw );
break;
default:
;
}
}
}
}
// Calculate the layout for the document.
QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars;
if ( ( m_data->layoutFlags & FrameWithScales ) ||
( m_data->discardFlags & DiscardCanvasFrame ) )
{
layoutOptions |= QwtPlotLayout::IgnoreFrames;
}
if ( m_data->discardFlags & DiscardLegend )
layoutOptions |= QwtPlotLayout::IgnoreLegend;
if ( m_data->discardFlags & DiscardTitle )
layoutOptions |= QwtPlotLayout::IgnoreTitle;
if ( m_data->discardFlags & DiscardFooter )
layoutOptions |= QwtPlotLayout::IgnoreFooter;
layout->activate( plot, layoutRect, layoutOptions );
// canvas
QwtScaleMap maps[QwtAxis::AxisPositions];
buildCanvasMaps( plot, layout->canvasRect(), maps );
if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) )
{
// recalculate maps and layout, when the margins
// have been changed
layout->activate( plot, layoutRect, layoutOptions );
buildCanvasMaps( plot, layout->canvasRect(), maps );
}
// now start painting
painter->save();
painter->setWorldTransform( transform, true );
renderCanvas( plot, painter, layout->canvasRect(), maps );
if ( !( m_data->discardFlags & DiscardTitle )
&& ( !plot->titleLabel()->text().isEmpty() ) )
{
renderTitle( plot, painter, layout->titleRect() );
}
if ( !( m_data->discardFlags & DiscardFooter )
&& ( !plot->footerLabel()->text().isEmpty() ) )
{
renderFooter( plot, painter, layout->footerRect() );
}
if ( !( m_data->discardFlags & DiscardLegend )
&& plot->legend() && !plot->legend()->isEmpty() )
{
renderLegend( plot, painter, layout->legendRect() );
}
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
{
const QwtAxisId axisId( axisPos );
QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
if ( scaleWidget )
{
int baseDist = scaleWidget->margin();
int startDist, endDist;
scaleWidget->getBorderDistHint( startDist, endDist );
renderScale( plot, painter, axisId, startDist, endDist,
baseDist, layout->scaleRect( axisId ) );
}
}
}
painter->restore();
// restore all setting to their original attributes.
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
if ( m_data->layoutFlags & FrameWithScales )
{
const QwtAxisId axisId( axisPos );
QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
if ( scaleWidget )
scaleWidget->setMargin( baseLineDists[axisPos] );
}
layout->setCanvasMargin( canvasMargins[axisPos] );
}
layout->invalidate();
}
void QwtPlotRenderer::renderTitle( const QwtPlot* plot,
QPainter* painter, const QRectF& titleRect ) const
{
painter->setFont( qwtResolvedFont( plot->titleLabel() ) );
const QColor color = plot->titleLabel()->palette().color(
QPalette::Active, QPalette::Text );
painter->setPen( color );
plot->titleLabel()->text().draw( painter, titleRect );
}
void QwtPlotRenderer::renderFooter( const QwtPlot* plot,
QPainter* painter, const QRectF& footerRect ) const
{
painter->setFont( qwtResolvedFont( plot->footerLabel() ) );
const QColor color = plot->footerLabel()->palette().color(
QPalette::Active, QPalette::Text );
painter->setPen( color );
plot->footerLabel()->text().draw( painter, footerRect );
}
void QwtPlotRenderer::renderLegend( const QwtPlot* plot,
QPainter* painter, const QRectF& legendRect ) const
{
if ( plot->legend() )
{
bool fillBackground = !( m_data->discardFlags & DiscardBackground );
plot->legend()->renderLegend( painter, legendRect, fillBackground );
}
}
void QwtPlotRenderer::renderScale( const QwtPlot* plot, QPainter* painter,
QwtAxisId axisId, int startDist, int endDist, int baseDist,
const QRectF& scaleRect ) const
{
if ( !plot->isAxisVisible( axisId ) )
return;
const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
if ( scaleWidget->isColorBarEnabled()
&& scaleWidget->colorBarWidth() > 0 )
{
scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( scaleRect ) );
baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing();
}
painter->save();
QwtScaleDraw::Alignment align;
double x, y, w;
qreal off = 0.0;
if ( m_data->layoutFlags & FrameWithScales )
off = qwtScalePenWidth( plot );
switch ( axisId )
{
case QwtAxis::YLeft:
{
x = scaleRect.right() - 1.0 - baseDist - off;
y = scaleRect.y() + startDist;
w = scaleRect.height() - startDist - endDist;
align = QwtScaleDraw::LeftScale;
break;
}
case QwtAxis::YRight:
{
x = scaleRect.left() + baseDist + off;
y = scaleRect.y() + startDist;
w = scaleRect.height() - startDist - endDist;
align = QwtScaleDraw::RightScale;
break;
}
case QwtAxis::XTop:
{
x = scaleRect.left() + startDist;
y = scaleRect.bottom() - 1.0 - baseDist - off;
w = scaleRect.width() - startDist - endDist;
align = QwtScaleDraw::TopScale;
break;
}
case QwtAxis::XBottom:
{
x = scaleRect.left() + startDist;
y = scaleRect.top() + baseDist + off;
w = scaleRect.width() - startDist - endDist;
align = QwtScaleDraw::BottomScale;
break;
}
default:
return;
}
scaleWidget->drawTitle( painter, align, scaleRect );
painter->setFont( qwtResolvedFont( scaleWidget ) );
QwtScaleDraw* sd = const_cast< QwtScaleDraw* >( scaleWidget->scaleDraw() );
const QPointF sdPos = sd->pos();
const double sdLength = sd->length();
const bool hasBackbone = sd->hasComponent( QwtAbstractScaleDraw::Backbone );
if ( m_data->layoutFlags & FrameWithScales )
sd->enableComponent( QwtAbstractScaleDraw::Backbone, false );
sd->move( x, y );
sd->setLength( w );
QPalette palette = scaleWidget->palette();
palette.setCurrentColorGroup( QPalette::Active );
sd->draw( painter, palette );
// reset previous values
sd->move( sdPos );
sd->setLength( sdLength );
sd->enableComponent( QwtAbstractScaleDraw::Backbone, hasBackbone );
painter->restore();
}
void QwtPlotRenderer::renderCanvas( const QwtPlot* plot,
QPainter* painter, const QRectF& canvasRect,
const QwtScaleMap* maps ) const
{
const QWidget* canvas = plot->canvas();
QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
if ( m_data->layoutFlags & FrameWithScales )
{
painter->save();
QPen pen;
pen.setColor( qwtScalePenColor( plot ) );
pen.setWidth( qwtScalePenWidth( plot ) );
pen.setJoinStyle( Qt::MiterJoin );
painter->setPen( pen );
const qreal pw2 = 0.5 * pen.widthF();
r.adjust( -pw2, -pw2, pw2, pw2 );
if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
{
const QBrush bgBrush =
canvas->palette().brush( plot->backgroundRole() );
painter->setBrush( bgBrush );
}
QwtPainter::drawRect( painter, r );
painter->restore();
painter->save();
painter->setClipRect( canvasRect );
plot->drawItems( painter, canvasRect, maps );
painter->restore();
}
else if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
{
QPainterPath clipPath;
painter->save();
if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
{
QwtPainter::drawBackgound( painter, r, canvas );
clipPath = qwtCanvasClip( canvas, canvasRect );
}
painter->restore();
painter->save();
if ( clipPath.isEmpty() )
painter->setClipRect( canvasRect );
else
painter->setClipPath( clipPath );
plot->drawItems( painter, canvasRect, maps );
painter->restore();
}
else
{
QPainterPath clipPath;
double frameWidth = 0.0;
if ( !( m_data->discardFlags & DiscardCanvasFrame ) )
{
const QVariant fw = canvas->property( "frameWidth" );
if ( fw.canConvert< double >() )
frameWidth = fw.value< double >();
clipPath = qwtCanvasClip( canvas, canvasRect );
}
QRectF innerRect = canvasRect.adjusted(
frameWidth, frameWidth, -frameWidth, -frameWidth );
painter->save();
if ( clipPath.isEmpty() )
{
painter->setClipRect( innerRect );
}
else
{
painter->setClipPath( clipPath );
}
if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
{
QwtPainter::drawBackgound( painter, innerRect, canvas );
}
plot->drawItems( painter, innerRect, maps );
painter->restore();
if ( frameWidth > 0 )
{
painter->save();
const int frameStyle =
canvas->property( "frameShadow" ).toInt() |
canvas->property( "frameShape" ).toInt();
const QVariant borderRadius = canvas->property( "borderRadius" );
if ( borderRadius.canConvert< double >()
&& borderRadius.value< double >() > 0.0 )
{
const double radius = borderRadius.value< double >();
QwtPainter::drawRoundedFrame( painter, canvasRect,
radius, radius, canvas->palette(), frameWidth, frameStyle );
}
else
{
const int midLineWidth = canvas->property( "midLineWidth" ).toInt();
QwtPainter::drawFrame( painter, canvasRect,
canvas->palette(), canvas->foregroundRole(),
frameWidth, midLineWidth, frameStyle );
}
painter->restore();
}
}
}
void QwtPlotRenderer::buildCanvasMaps( const QwtPlot* plot,
const QRectF& canvasRect, QwtScaleMap maps[] ) const
{
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
{
{
const QwtAxisId axisId( axisPos );
QwtScaleMap& scaleMap = maps[axisId];
scaleMap.setTransformation(
plot->axisScaleEngine( axisId )->transformation() );
const QwtScaleDiv& scaleDiv = plot->axisScaleDiv( axisId );
scaleMap.setScaleInterval(
scaleDiv.lowerBound(), scaleDiv.upperBound() );
double from, to;
if ( plot->isAxisVisible( axisId ) )
{
const int sDist = plot->axisWidget( axisId )->startBorderDist();
const int eDist = plot->axisWidget( axisId )->endBorderDist();
const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
if ( QwtAxis::isXAxis( axisPos ) )
{
from = scaleRect.left() + sDist;
to = scaleRect.right() - eDist;
}
else
{
from = scaleRect.bottom() - eDist;
to = scaleRect.top() + sDist;
}
}
else
{
int margin = 0;
if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) )
margin = plot->plotLayout()->canvasMargin( axisPos );
if ( QwtAxis::isYAxis( axisPos ) )
{
from = canvasRect.bottom() - margin;
to = canvasRect.top() + margin;
}
else
{
from = canvasRect.left() + margin;
to = canvasRect.right() - margin;
}
}
scaleMap.setPaintInterval( from, to );
}
}
}
bool QwtPlotRenderer::updateCanvasMargins( QwtPlot* plot,
const QRectF& canvasRect, const QwtScaleMap maps[] ) const
{
using namespace QwtAxis;
double margins[AxisPositions];
plot->getCanvasMarginsHint( maps, canvasRect,
margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] );
bool marginsChanged = false;
for ( int axisId = 0; axisId < AxisPositions; axisId++ )
{
if ( margins[axisId] >= 0.0 )
{
const int m = qwtCeil( margins[axisId] );
plot->plotLayout()->setCanvasMargin( m, axisId);
marginsChanged = true;
}
}
return marginsChanged;
}
bool QwtPlotRenderer::exportTo( QwtPlot* plot, const QString& documentName,
const QSizeF& sizeMM, int resolution )
{
if ( plot == NULL )
return false;
QString fileName = documentName;
// What about translation
#ifndef QT_NO_FILEDIALOG
const QList< QByteArray > imageFormats =
QImageWriter::supportedImageFormats();
QStringList filter;
#if QWT_FORMAT_PDF
filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)";
#endif
#if QWT_FORMAT_SVG
filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)";
#endif
#if QWT_FORMAT_POSTSCRIPT
filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)";
#endif
if ( imageFormats.size() > 0 )
{
QString imageFilter( tr( "Images" ) );
imageFilter += " (";
for ( int i = 0; i < imageFormats.size(); i++ )
{
if ( i > 0 )
imageFilter += " ";
imageFilter += "*.";
imageFilter += imageFormats[i];
}
imageFilter += ")";
filter += imageFilter;
}
fileName = QFileDialog::getSaveFileName(
NULL, tr( "Export File Name" ), fileName,
filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
#endif
if ( fileName.isEmpty() )
return false;
renderDocument( plot, fileName, sizeMM, resolution );
return true;
}
#if QWT_MOC_INCLUDE
#include "moc_qwt_plot_renderer.cpp"
#endif
QList
Definition: qwt_abstract_legend.h:17
QwtAbstractLegend::renderLegend
virtual void renderLegend(QPainter *painter, const QRectF &rect, bool fillBackground) const =0
QwtAbstractLegend::isEmpty
virtual bool isEmpty() const =0
QwtAbstractScaleDraw::Backbone
@ Backbone
Backbone = the line where the ticks are located.
Definition: qwt_abstract_scale_draw.h:42
QwtAbstractScaleDraw::hasComponent
bool hasComponent(ScaleComponent) const
Definition: qwt_abstract_scale_draw.cpp:95
QwtAbstractScaleDraw::draw
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
Definition: qwt_abstract_scale_draw.cpp:169
QwtAbstractScaleDraw::penWidthF
qreal penWidthF() const
Definition: qwt_abstract_scale_draw.cpp:156
QwtAbstractScaleDraw::enableComponent
void enableComponent(ScaleComponent, bool enable=true)
Definition: qwt_abstract_scale_draw.cpp:79
QwtPainter::drawRoundedFrame
static void drawRoundedFrame(QPainter *, const QRectF &, qreal xRadius, qreal yRadius, const QPalette &, int lineWidth, int frameStyle)
Definition: qwt_painter.cpp:1065
QwtPainter::drawBackgound
static void drawBackgound(QPainter *, const QRectF &, const QWidget *)
Definition: qwt_painter.cpp:1351
QwtPainter::drawRect
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
Definition: qwt_painter.cpp:347
QwtPainter::drawFrame
static void drawFrame(QPainter *, const QRectF &rect, const QPalette &palette, QPalette::ColorRole foregroundRole, int lineWidth, int midLineWidth, int frameStyle)
Definition: qwt_painter.cpp:911
QwtPlot
A 2-D plotting widget.
Definition: qwt_plot.h:79
QwtPlot::getCanvasMarginsHint
virtual void getCanvasMarginsHint(const QwtScaleMap maps[], const QRectF &canvasRect, double &left, double &top, double &right, double &bottom) const
Calculate the canvas margins.
Definition: qwt_plot.cpp:670
QwtPlot::axisScaleEngine
QwtScaleEngine * axisScaleEngine(QwtAxisId)
Definition: qwt_plot_axis.cpp:190
QwtPlot::drawItems
virtual void drawItems(QPainter *, const QRectF &, const QwtScaleMap maps[QwtAxis::AxisPositions]) const
Definition: qwt_plot.cpp:764
QwtPlot::canvas
QWidget * canvas()
Definition: qwt_plot.cpp:463
QwtPlot::footerLabel
QwtTextLabel * footerLabel()
Definition: qwt_plot.cpp:401
QwtPlot::isAxisVisible
bool isAxisVisible(QwtAxisId) const
Definition: qwt_plot_axis.cpp:225
QwtPlot::plotLayout
QwtPlotLayout * plotLayout()
Definition: qwt_plot.cpp:430
QwtPlot::legend
QwtAbstractLegend * legend()
Definition: qwt_plot.cpp:445
QwtPlot::axisWidget
const QwtScaleWidget * axisWidget(QwtAxisId) const
Definition: qwt_plot_axis.cpp:141
QwtPlot::titleLabel
QwtTextLabel * titleLabel()
Definition: qwt_plot.cpp:357
QwtPlot::axisScaleDiv
const QwtScaleDiv & axisScaleDiv(QwtAxisId) const
Return the scale division of a specified axis.
Definition: qwt_plot_axis.cpp:283
QwtPlot::axisScaleDraw
const QwtScaleDraw * axisScaleDraw(QwtAxisId) const
Return the scale draw of a specified axis.
Definition: qwt_plot_axis.cpp:294
QwtPlot::title
QwtText title() const
Definition: qwt_plot.cpp:351
QwtPlotLayout
Layout engine for QwtPlot.
Definition: qwt_plot_layout.h:28
QwtPlotLayout::titleRect
QRectF titleRect() const
Definition: qwt_plot_layout.cpp:1282
QwtPlotLayout::setCanvasMargin
void setCanvasMargin(int margin, int axis=-1)
Definition: qwt_plot_layout.cpp:1066
QwtPlotLayout::footerRect
QRectF footerRect() const
Definition: qwt_plot_layout.cpp:1304
QwtPlotLayout::canvasMargin
int canvasMargin(int axisId) const
Definition: qwt_plot_layout.cpp:1089
QwtPlotLayout::legendRect
QRectF legendRect() const
Definition: qwt_plot_layout.cpp:1328
QwtPlotLayout::invalidate
virtual void invalidate()
Definition: qwt_plot_layout.cpp:1389
QwtPlotLayout::alignCanvasToScale
bool alignCanvasToScale(int axisId) const
Definition: qwt_plot_layout.cpp:1141
QwtPlotLayout::scaleRect
QRectF scaleRect(QwtAxisId) const
Definition: qwt_plot_layout.cpp:1355
QwtPlotLayout::Options
QFlags< Option > Options
Definition: qwt_plot_layout.h:58
QwtPlotLayout::canvasRect
QRectF canvasRect() const
Definition: qwt_plot_layout.cpp:1380
QwtPlotLayout::IgnoreTitle
@ IgnoreTitle
Ignore the title.
Definition: qwt_plot_layout.h:52
QwtPlotLayout::IgnoreFooter
@ IgnoreFooter
Ignore the footer.
Definition: qwt_plot_layout.h:55
QwtPlotLayout::IgnoreScrollbars
@ IgnoreScrollbars
Definition: qwt_plot_layout.h:43
QwtPlotLayout::IgnoreFrames
@ IgnoreFrames
Ignore all frames.
Definition: qwt_plot_layout.h:46
QwtPlotLayout::IgnoreLegend
@ IgnoreLegend
Ignore the legend.
Definition: qwt_plot_layout.h:49
QwtPlotLayout::activate
virtual void activate(const QwtPlot *, const QRectF &plotRect, Options options=Options())
Recalculate the geometry of all components.
Definition: qwt_plot_layout.cpp:1508
QwtPlotRenderer
Renderer for exporting a plot to a document, a printer or anything else, that is supported by QPainte...
Definition: qwt_plot_renderer.h:40
QwtPlotRenderer::renderTo
void renderTo(QwtPlot *, QPrinter &) const
Render the plot to a QPrinter.
Definition: qwt_plot_renderer.cpp:427
QwtPlotRenderer::LayoutFlag
LayoutFlag
Layout flags.
Definition: qwt_plot_renderer.h:83
QwtPlotRenderer::DefaultLayout
@ DefaultLayout
Use the default layout as on screen.
Definition: qwt_plot_renderer.h:85
QwtPlotRenderer::FrameWithScales
@ FrameWithScales
Definition: qwt_plot_renderer.h:91
QwtPlotRenderer::renderCanvas
virtual void renderCanvas(const QwtPlot *, QPainter *, const QRectF &canvasRect, const QwtScaleMap *maps) const
Definition: qwt_plot_renderer.cpp:831
QwtPlotRenderer::renderFooter
virtual void renderFooter(const QwtPlot *, QPainter *, const QRectF &footerRect) const
Definition: qwt_plot_renderer.cpp:692
QwtPlotRenderer::setDiscardFlag
void setDiscardFlag(DiscardFlag flag, bool on=true)
Definition: qwt_plot_renderer.cpp:166
QwtPlotRenderer::DiscardFlag
DiscardFlag
Discard flags.
Definition: qwt_plot_renderer.h:46
QwtPlotRenderer::DiscardCanvasFrame
@ DiscardCanvasFrame
Definition: qwt_plot_renderer.h:72
QwtPlotRenderer::DiscardFooter
@ DiscardFooter
Don't render the footer of the plot.
Definition: qwt_plot_renderer.h:63
QwtPlotRenderer::DiscardTitle
@ DiscardTitle
Don't render the title of the plot.
Definition: qwt_plot_renderer.h:54
QwtPlotRenderer::DiscardBackground
@ DiscardBackground
Don't render the background of the plot.
Definition: qwt_plot_renderer.h:51
QwtPlotRenderer::DiscardCanvasBackground
@ DiscardCanvasBackground
Don't render the background of the canvas.
Definition: qwt_plot_renderer.h:60
QwtPlotRenderer::DiscardLegend
@ DiscardLegend
Don't render the legend of the plot.
Definition: qwt_plot_renderer.h:57
QwtPlotRenderer::DiscardNone
@ DiscardNone
Render all components of the plot.
Definition: qwt_plot_renderer.h:48
QwtPlotRenderer::renderLegend
virtual void renderLegend(const QwtPlot *, QPainter *, const QRectF &legendRect) const
Definition: qwt_plot_renderer.cpp:711
QwtPlotRenderer::setLayoutFlags
void setLayoutFlags(LayoutFlags flags)
Definition: qwt_plot_renderer.cpp:236
QwtPlotRenderer::~QwtPlotRenderer
virtual ~QwtPlotRenderer()
Destructor.
Definition: qwt_plot_renderer.cpp:153
QwtPlotRenderer::renderScale
virtual void renderScale(const QwtPlot *, QPainter *, QwtAxisId, int startDist, int endDist, int baseDist, const QRectF &scaleRect) const
Paint a scale into a given rectangle. Paint the scale into a given rectangle.
Definition: qwt_plot_renderer.cpp:733
QwtPlotRenderer::renderTitle
virtual void renderTitle(const QwtPlot *, QPainter *, const QRectF &titleRect) const
Definition: qwt_plot_renderer.cpp:673
QwtPlotRenderer::testLayoutFlag
bool testLayoutFlag(LayoutFlag flag) const
Definition: qwt_plot_renderer.cpp:225
QwtPlotRenderer::renderDocument
void renderDocument(QwtPlot *, const QString &fileName, const QSizeF &sizeMM, int resolution=85)
Definition: qwt_plot_renderer.cpp:261
QwtPlotRenderer::QwtPlotRenderer
QwtPlotRenderer(QObject *=NULL)
Definition: qwt_plot_renderer.cpp:146
QwtPlotRenderer::LayoutFlags
QFlags< LayoutFlag > LayoutFlags
Definition: qwt_plot_renderer.h:94
QwtPlotRenderer::setLayoutFlag
void setLayoutFlag(LayoutFlag flag, bool on=true)
Definition: qwt_plot_renderer.cpp:212
QwtPlotRenderer::DiscardFlags
QFlags< DiscardFlag > DiscardFlags
Definition: qwt_plot_renderer.h:76
QwtPlotRenderer::discardFlags
DiscardFlags discardFlags() const
Definition: qwt_plot_renderer.cpp:199
QwtPlotRenderer::exportTo
bool exportTo(QwtPlot *, const QString &documentName, const QSizeF &sizeMM=QSizeF(300, 200), int resolution=85)
Execute a file dialog and render the plot to the selected file.
Definition: qwt_plot_renderer.cpp:1060
QwtPlotRenderer::setDiscardFlags
void setDiscardFlags(DiscardFlags flags)
Definition: qwt_plot_renderer.cpp:190
QwtPlotRenderer::testDiscardFlag
bool testDiscardFlag(DiscardFlag flag) const
Definition: qwt_plot_renderer.cpp:179
QwtPlotRenderer::render
virtual void render(QwtPlot *, QPainter *, const QRectF &plotRect) const
Definition: qwt_plot_renderer.cpp:482
QwtPlotRenderer::layoutFlags
LayoutFlags layoutFlags() const
Definition: qwt_plot_renderer.cpp:245
QwtScaleDiv
A class representing a scale division.
Definition: qwt_scale_div.h:34
QwtScaleDiv::lowerBound
double lowerBound() const
Definition: qwt_scale_div.cpp:131
QwtScaleDiv::upperBound
double upperBound() const
Definition: qwt_scale_div.cpp:151
QwtScaleDraw
A class for drawing scales.
Definition: qwt_scale_draw.h:36
QwtScaleDraw::setLength
void setLength(double length)
Definition: qwt_scale_draw.cpp:732
QwtScaleDraw::move
void move(double x, double y)
Definition: qwt_scale_draw.h:118
QwtScaleDraw::length
double length() const
Definition: qwt_scale_draw.cpp:753
QwtScaleDraw::pos
QPointF pos() const
Definition: qwt_scale_draw.cpp:717
QwtScaleDraw::Alignment
Alignment
Definition: qwt_scale_draw.h:43
QwtScaleDraw::BottomScale
@ BottomScale
The scale is below.
Definition: qwt_scale_draw.h:45
QwtScaleDraw::TopScale
@ TopScale
The scale is above.
Definition: qwt_scale_draw.h:48
QwtScaleDraw::RightScale
@ RightScale
The scale is right.
Definition: qwt_scale_draw.h:54
QwtScaleDraw::LeftScale
@ LeftScale
The scale is left.
Definition: qwt_scale_draw.h:51
QwtScaleEngine::transformation
QwtTransform * transformation() const
Definition: qwt_scale_engine.cpp:265
QwtScaleMap
A scale map.
Definition: qwt_scale_map.h:27
QwtScaleMap::setPaintInterval
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
Definition: qwt_scale_map.cpp:119
QwtScaleMap::setScaleInterval
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
Definition: qwt_scale_map.cpp:100
QwtScaleMap::setTransformation
void setTransformation(QwtTransform *)
Definition: qwt_scale_map.cpp:76
QwtScaleWidget
A Widget which contains a scale.
Definition: qwt_scale_widget.h:35
QwtScaleWidget::startBorderDist
int startBorderDist() const
Definition: qwt_scale_widget.cpp:380
QwtScaleWidget::drawColorBar
void drawColorBar(QPainter *, const QRectF &) const
Definition: qwt_scale_widget.cpp:624
QwtScaleWidget::scaleDraw
const QwtScaleDraw * scaleDraw() const
Definition: qwt_scale_widget.cpp:353
QwtScaleWidget::setMargin
void setMargin(int)
Specify the margin to the colorBar/base line.
Definition: qwt_scale_widget.cpp:265
QwtScaleWidget::isColorBarEnabled
bool isColorBarEnabled() const
Definition: qwt_scale_widget.cpp:907
QwtScaleWidget::drawTitle
void drawTitle(QPainter *, QwtScaleDraw::Alignment, const QRectF &rect) const
Definition: qwt_scale_widget.cpp:644
QwtScaleWidget::endBorderDist
int endBorderDist() const
Definition: qwt_scale_widget.cpp:389
QwtScaleWidget::spacing
int spacing() const
Definition: qwt_scale_widget.cpp:407
QwtScaleWidget::getBorderDistHint
void getBorderDistHint(int &start, int &end) const
Calculate a hint for the border distances.
Definition: qwt_scale_widget.cpp:814
QwtScaleWidget::colorBarRect
QRectF colorBarRect(const QRectF &) const
Definition: qwt_scale_widget.cpp:462
QwtScaleWidget::margin
int margin() const
Definition: qwt_scale_widget.cpp:398
QwtScaleWidget::colorBarWidth
int colorBarWidth() const
Definition: qwt_scale_widget.cpp:932
QwtText::isEmpty
bool isEmpty() const
Definition: qwt_text.cpp:739
QwtText::draw
void draw(QPainter *painter, const QRectF &rect) const
Definition: qwt_text.cpp:615
QwtText::text
QString text() const
Definition: qwt_text.cpp:289
QwtTextLabel::text
const QwtText & text() const
Return the text.
Definition: qwt_text_label.cpp:118
QwtAxis
Definition: qwt_axis.h:19
QwtAxis::isYAxis
bool isYAxis(int axisPos)
Definition: qwt_axis.h:57
QwtAxis::YRight
@ YRight
Y axis right of the canvas.
Definition: qwt_axis.h:27
QwtAxis::XTop
@ XTop
X axis above the canvas.
Definition: qwt_axis.h:33
QwtAxis::XBottom
@ XBottom
X axis below the canvas.
Definition: qwt_axis.h:30
QwtAxis::YLeft
@ YLeft
Y axis left of the canvas.
Definition: qwt_axis.h:24
QwtAxis::isXAxis
bool isXAxis(int axisPos)
Definition: qwt_axis.h:51