9 #include "qwt_polar_renderer.h" 
   10 #include "qwt_polar_plot.h" 
   11 #include "qwt_polar_layout.h" 
   12 #include "qwt_legend.h" 
   13 #include "qwt_dyngrid_layout.h" 
   14 #include "qwt_text_label.h" 
   19 #include <qprintdialog.h> 
   20 #include <qfiledialog.h> 
   21 #include <qimagewriter.h> 
   22 #include <qfileinfo.h> 
   27 #define QWT_FORMAT_SVG 1 
   32 #define QWT_FORMAT_PDF 1 
   41 #if QT_VERSION >= 0x050300 
   43 #ifndef QWT_FORMAT_PDF 
   44 #define QWT_FORMAT_PDF 1 
   47 #define QWT_PDF_WRITER 1 
   54 #if QT_VERSION < 0x050000 
   55 #define QWT_FORMAT_POSTSCRIPT 1 
   60 #include <qsvggenerator.h> 
   64 #include <qpdfwriter.h> 
   67 static inline double qwtDistance(
 
   68     const QPointF& p1, 
const QPointF& p2 )
 
   70     double dx = p2.x() - p1.x();
 
   71     double dy = p2.y() - p1.y();
 
   72     return qSqrt( dx * dx + dy * dy );
 
   75 class QwtPolarRenderer::PrivateData
 
   93     m_data = 
new PrivateData;
 
  114     const QString& fileName, 
const QSizeF& sizeMM, 
int resolution )
 
  117         QFileInfo( fileName ).suffix(), sizeMM, resolution );
 
  139     const QString& fileName, 
const QString& format,
 
  140     const QSizeF& sizeMM, 
int resolution )
 
  142     if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
 
  146     if ( title.isEmpty() )
 
  147         title = 
"Plot Document";
 
  149     const double mmToInch = 1.0 / 25.4;
 
  150     const QSizeF size = sizeMM * mmToInch * resolution;
 
  152     const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );
 
  154     const QString fmt = format.toLower();
 
  155     if ( format == 
"pdf" )
 
  159         QPdfWriter pdfWriter( fileName );
 
  160         pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) );
 
  161         pdfWriter.setTitle( title );
 
  162         pdfWriter.setPageMargins( QMarginsF() );
 
  163         pdfWriter.setResolution( resolution );
 
  165         QPainter painter( &pdfWriter );
 
  166         render( plot, &painter, documentRect );
 
  170         printer.setOutputFormat( QPrinter::PdfFormat );
 
  171         printer.setColorMode( QPrinter::Color );
 
  172         printer.setFullPage( 
true );
 
  173         printer.setPaperSize( sizeMM, QPrinter::Millimeter );
 
  174         printer.setDocName( title );
 
  175         printer.setOutputFileName( fileName );
 
  176         printer.setResolution( resolution );
 
  178         QPainter painter( &printer );
 
  179         render( plot, &painter, documentRect );
 
  183     else if ( format == 
"ps" )
 
  185 #if QWT_FORMAT_POSTSCRIPT 
  187         printer.setColorMode( QPrinter::Color );
 
  188         printer.setFullPage( 
true );
 
  189         printer.setPaperSize( sizeMM, QPrinter::Millimeter );
 
  190         printer.setDocName( title );
 
  191         printer.setOutputFileName( fileName );
 
  192         printer.setOutputFormat( QPrinter::PostScriptFormat );
 
  193         printer.setResolution( resolution );
 
  195         QPainter painter( &printer );
 
  196         render( plot, &painter, documentRect );
 
  199     else if ( format == 
"svg" )
 
  201 #ifdef QWT_FORMAT_SVG 
  202         QSvgGenerator generator;
 
  203         generator.setTitle( title );
 
  204         generator.setFileName( fileName );
 
  205         generator.setResolution( resolution );
 
  206         generator.setViewBox( documentRect );
 
  208         QPainter painter( &generator );
 
  209         render( plot, &painter, documentRect );
 
  214         if ( QImageWriter::supportedImageFormats().indexOf(
 
  215             format.toLatin1() ) >= 0 )
 
  217             const QRect imageRect = documentRect.toRect();
 
  218             const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 );
 
  220             QImage image( imageRect.size(), QImage::Format_ARGB32 );
 
  221             image.setDotsPerMeterX( dotsPerMeter );
 
  222             image.setDotsPerMeterY( dotsPerMeter );
 
  223             image.fill( QColor( Qt::white ).rgb() );
 
  225             QPainter painter( &image );
 
  226             render( plot, &painter, imageRect );
 
  229             image.save( fileName, format.toLatin1() );
 
  250     int w = paintDevice.width();
 
  251     int h = paintDevice.height();
 
  253     QPainter p( &paintDevice );
 
  254     render( plot, &p, QRectF( 0, 0, w, h ) );
 
  271 #ifndef QT_NO_PRINTER 
  276     int w = printer.width();
 
  277     int h = printer.height();
 
  279     QRectF rect( 0, 0, w, h );
 
  280     double aspect = rect.width() / rect.height();
 
  281     if ( ( aspect < 1.0 ) )
 
  282         rect.setHeight( aspect * rect.width() );
 
  284     QPainter p( &printer );
 
  290 #ifdef QWT_FORMAT_SVG 
  306     QRectF rect = generator.viewBoxF();
 
  307     if ( rect.isEmpty() )
 
  308         rect.setRect( 0, 0, generator.width(), generator.height() );
 
  310     if ( rect.isEmpty() )
 
  311         rect.setRect( 0, 0, 800, 600 ); 
 
  313     QPainter p( &generator );
 
  327     QPainter* painter, 
const QRectF& plotRect )
 const 
  329     if ( plot == NULL || painter == NULL || !painter->isActive() ||
 
  330         !plotRect.isValid() || plot->size().isNull() )
 
  342     QTransform transform;
 
  344         double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
 
  345         double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );
 
  347     const QRectF layoutRect = transform.inverted().mapRect( plotRect );
 
  357     layout->
activate( plot, layoutRect, layoutOptions );
 
  360     painter->setWorldTransform( transform, 
true );
 
  370     const QRectF canvasRect = layout->
canvasRect();
 
  373     painter->setClipRect( canvasRect );
 
  395     painter->setFont( title->font() );
 
  397     const QColor color = title->palette().color(
 
  398         QPalette::Active, QPalette::Text );
 
  400     painter->setPen( color );
 
  401     title->
text().
draw( painter, rect );
 
  412     QPainter* painter, 
const QRectF& rect )
 const 
  431     const QString& documentName, 
const QSizeF& sizeMM, 
int resolution )
 
  436     QString fileName = documentName;
 
  440 #ifndef QT_NO_FILEDIALOG 
  442         QImageWriter::supportedImageFormats();
 
  445 #ifndef QT_NO_PRINTER 
  446     filter += QString( 
"PDF " ) + tr( 
"Documents" ) + 
" (*.pdf)";
 
  449     filter += QString( 
"SVG " ) + tr( 
"Documents" ) + 
" (*.svg)";
 
  451 #ifndef QT_NO_PRINTER 
  452     filter += QString( 
"Postscript " ) + tr( 
"Documents" ) + 
" (*.ps)";
 
  455     if ( imageFormats.size() > 0 )
 
  457         QString imageFilter( tr( 
"Images" ) );
 
  459         for ( 
int i = 0; i < imageFormats.size(); i++ )
 
  464             imageFilter += imageFormats[i];
 
  468         filter += imageFilter;
 
  471     fileName = QFileDialog::getSaveFileName(
 
  472         NULL, tr( 
"Export File Name" ), fileName,
 
  473         filter.join( 
";;" ), NULL, QFileDialog::DontConfirmOverwrite );
 
  475     if ( fileName.isEmpty() )
 
  484 #include "moc_qwt_polar_renderer.cpp" 
virtual void renderLegend(QPainter *painter, const QRectF &rect, bool fillBackground) const =0
Layout class for QwtPolarPlot.
const QRectF & legendRect() const
virtual void invalidate()
virtual void activate(const QwtPolarPlot *, const QRectF &rect, Options options=Options())
Recalculate the geometry of all components.
const QRectF & titleRect() const
@ IgnoreScrollbars
Ignore the dimension of the scrollbars.
@ IgnoreFrames
Ignore all frames.
const QRectF & canvasRect() const
A plotting widget, displaying a polar coordinate system.
QwtPolarLayout * plotLayout()
virtual void drawCanvas(QPainter *, const QRectF &) const
QwtAbstractLegend * legend()
bool exportTo(QwtPolarPlot *, const QString &documentName, const QSizeF &sizeMM=QSizeF(200, 200), int resolution=85)
Execute a file dialog and render the plot to the selected file.
virtual void renderTitle(QPainter *, const QRectF &) const
QwtPolarRenderer(QObject *parent=NULL)
virtual void render(QwtPolarPlot *, QPainter *, const QRectF &rect) const
Render the plot to a given rectangle ( f.e QPrinter, QSvgRenderer )
void renderDocument(QwtPolarPlot *, const QString &format, const QSizeF &sizeMM, int resolution=85)
virtual ~QwtPolarRenderer()
Destructor.
virtual void renderLegend(const QwtPolarPlot *, QPainter *, const QRectF &) const
void renderTo(QwtPolarPlot *, QPrinter &) const
Render the plot to a QPrinter.
void draw(QPainter *painter, const QRectF &rect) const
A Widget which displays a QwtText.
const QwtText & text() const
Return the text.