qwt_plot_renderer.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_plot_renderer.h"
11 #include "qwt_plot.h"
12 #include "qwt_painter.h"
13 #include "qwt_plot_layout.h"
14 #include "qwt_abstract_legend.h"
15 #include "qwt_scale_widget.h"
16 #include "qwt_scale_engine.h"
17 #include "qwt_scale_map.h"
18 #include "qwt_text.h"
19 #include "qwt_text_label.h"
20 #include "qwt_math.h"
21 
22 #include <qpainter.h>
23 #include <qpainterpath.h>
24 #include <qtransform.h>
25 #include <qprinter.h>
26 #include <qfiledialog.h>
27 #include <qfileinfo.h>
28 #include <qimagewriter.h>
29 #include <qvariant.h>
30 #include <qmargins.h>
31 
32 #ifndef QWT_NO_SVG
33 #ifdef QT_SVG_LIB
34 #define QWT_FORMAT_SVG 1
35 #endif
36 #endif
37 
38 #ifndef QT_NO_PRINTER
39 #define QWT_FORMAT_PDF 1
40 #endif
41 
42 #ifndef QT_NO_PDF
43 
44 // QPdfWriter::setResolution() has been introduced with
45 // Qt 5.3. Guess it is o.k. to stay with QPrinter for older
46 // versions.
47 
48 #if QT_VERSION >= 0x050300
49 
50 #ifndef QWT_FORMAT_PDF
51 #define QWT_FORMAT_PDF 1
52 #endif
53 
54 #define QWT_PDF_WRITER 1
55 
56 #endif
57 #endif
58 
59 #ifndef QT_NO_PRINTER
60 // postscript support has been dropped in Qt5
61 #if QT_VERSION < 0x050000
62 #define QWT_FORMAT_POSTSCRIPT 1
63 #endif
64 #endif
65 
66 #if QWT_FORMAT_SVG
67 #include <qsvggenerator.h>
68 #endif
69 
70 #if QWT_PDF_WRITER
71 #include <qpdfwriter.h>
72 #endif
73 
74 static qreal qwtScalePenWidth( const QwtPlot* plot )
75 {
76  qreal pw = 0.0;
77 
78  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
79  {
80  if ( plot->axisEnabled( axisId ) )
81  pw = qMax( pw, plot->axisScaleDraw( axisId )->penWidthF() );
82  }
83 
84  return pw;
85 }
86 
87 static QColor qwtScalePenColor( const QwtPlot* plot )
88 {
89  const QPalette pal = plot->axisWidget( QwtPlot::yLeft )->palette();
90  return pal.color( QPalette::WindowText );
91 }
92 
93 static QPainterPath qwtCanvasClip(
94  const QWidget* canvas, const QRectF &canvasRect )
95 {
96  // The clip region is calculated in integers
97  // To avoid too much rounding errors better
98  // calculate it in target device resolution
99 
100  int x1 = qwtCeil( canvasRect.left() );
101  int x2 = qwtFloor( canvasRect.right() );
102  int y1 = qwtCeil( canvasRect.top() );
103  int y2 = qwtFloor( canvasRect.bottom() );
104 
105  const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 );
106 
107  QPainterPath clipPath;
108 
109  ( void ) QMetaObject::invokeMethod(
110  const_cast< QWidget *>( canvas ), "borderPath",
111  Qt::DirectConnection,
112  Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) );
113 
114  return clipPath;
115 }
116 
117 static inline QFont qwtResolvedFont( const QWidget *widget )
118 {
119  QFont font = widget->font();
120  font.resolve( QFont::AllPropertiesResolved );
121 
122  return font;
123 }
124 
126 {
127 public:
131  {
132  }
133 
136 };
137 
143  QObject( parent )
144 {
145  d_data = new PrivateData;
146 }
147 
150 {
151  delete d_data;
152 }
153 
163 {
164  if ( on )
165  d_data->discardFlags |= flag;
166  else
167  d_data->discardFlags &= ~flag;
168 }
169 
176 {
177  return d_data->discardFlags & flag;
178 }
179 
187 {
188  d_data->discardFlags = flags;
189 }
190 
196 {
197  return d_data->discardFlags;
198 }
199 
209 {
210  if ( on )
211  d_data->layoutFlags |= flag;
212  else
213  d_data->layoutFlags &= ~flag;
214 }
215 
222 {
223  return d_data->layoutFlags & flag;
224 }
225 
233 {
234  d_data->layoutFlags = flags;
235 }
236 
242 {
243  return d_data->layoutFlags;
244 }
245 
258  const QString &fileName, const QSizeF &sizeMM, int resolution )
259 {
260  renderDocument( plot, fileName,
261  QFileInfo( fileName ).suffix(), sizeMM, resolution );
262 }
263 
290  const QString &fileName, const QString &format,
291  const QSizeF &sizeMM, int resolution )
292 {
293  if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
294  return;
295 
296  QString title = plot->title().text();
297  if ( title.isEmpty() )
298  title = "Plot Document";
299 
300  const double mmToInch = 1.0 / 25.4;
301  const QSizeF size = sizeMM * mmToInch * resolution;
302 
303  const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );
304 
305  const QString fmt = format.toLower();
306  if ( fmt == QLatin1String( "pdf" ) )
307  {
308 #if QWT_FORMAT_PDF
309 
310 #if QWT_PDF_WRITER
311  QPdfWriter pdfWriter( fileName );
312  pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) );
313  pdfWriter.setTitle( title );
314  pdfWriter.setPageMargins( QMarginsF() );
315  pdfWriter.setResolution( resolution );
316 
317  QPainter painter( &pdfWriter );
318  render( plot, &painter, documentRect );
319 #else
320  QPrinter printer;
321  printer.setOutputFormat( QPrinter::PdfFormat );
322  printer.setColorMode( QPrinter::Color );
323  printer.setFullPage( true );
324  printer.setPaperSize( sizeMM, QPrinter::Millimeter );
325  printer.setDocName( title );
326  printer.setOutputFileName( fileName );
327  printer.setResolution( resolution );
328 
329  QPainter painter( &printer );
330  render( plot, &painter, documentRect );
331 #endif
332 #endif
333  }
334  else if ( fmt == QLatin1String( "ps" ) )
335  {
336 #if QWT_FORMAT_POSTSCRIPT
337  QPrinter printer;
338  printer.setOutputFormat( QPrinter::PostScriptFormat );
339  printer.setColorMode( QPrinter::Color );
340  printer.setFullPage( true );
341  printer.setPaperSize( sizeMM, QPrinter::Millimeter );
342  printer.setDocName( title );
343  printer.setOutputFileName( fileName );
344  printer.setResolution( resolution );
345 
346  QPainter painter( &printer );
347  render( plot, &painter, documentRect );
348 #endif
349  }
350  else if ( fmt == QLatin1String( "svg" ) )
351  {
352 #if QWT_FORMAT_SVG
353  QSvgGenerator generator;
354  generator.setTitle( title );
355  generator.setFileName( fileName );
356  generator.setResolution( resolution );
357  generator.setViewBox( documentRect );
358 
359  QPainter painter( &generator );
360  render( plot, &painter, documentRect );
361 #endif
362  }
363  else
364  {
365  if ( QImageWriter::supportedImageFormats().indexOf(
366  format.toLatin1() ) >= 0 )
367  {
368  const QRect imageRect = documentRect.toRect();
369  const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 );
370 
371  QImage image( imageRect.size(), QImage::Format_ARGB32 );
372  image.setDotsPerMeterX( dotsPerMeter );
373  image.setDotsPerMeterY( dotsPerMeter );
374  image.fill( QColor( Qt::white ).rgb() );
375 
376  QPainter painter( &image );
377  render( plot, &painter, imageRect );
378  painter.end();
379 
380  image.save( fileName, format.toLatin1() );
381  }
382  }
383 }
384 
399  QwtPlot *plot, QPaintDevice &paintDevice ) const
400 {
401  int w = paintDevice.width();
402  int h = paintDevice.height();
403 
404  QPainter p( &paintDevice );
405  render( plot, &p, QRectF( 0, 0, w, h ) );
406 }
407 
421 #ifndef QT_NO_PRINTER
422 
424  QwtPlot *plot, QPrinter &printer ) const
425 {
426  int w = printer.width();
427  int h = printer.height();
428 
429  QRectF rect( 0, 0, w, h );
430  double aspect = rect.width() / rect.height();
431  if ( ( aspect < 1.0 ) )
432  rect.setHeight( aspect * rect.width() );
433 
434  QPainter p( &printer );
435  render( plot, &p, rect );
436 }
437 
438 #endif
439 
440 #if QWT_FORMAT_SVG
441 
454  QwtPlot *plot, QSvgGenerator &generator ) const
455 {
456  QRectF rect = generator.viewBoxF();
457  if ( rect.isEmpty() )
458  rect.setRect( 0, 0, generator.width(), generator.height() );
459 
460  if ( rect.isEmpty() )
461  rect.setRect( 0, 0, 800, 600 ); // something
462 
463  QPainter p( &generator );
464  render( plot, &p, rect );
465 }
466 
467 #endif
468 
479  QPainter *painter, const QRectF &plotRect ) const
480 {
481  if ( painter == 0 || !painter->isActive() ||
482  !plotRect.isValid() || plot->size().isNull() )
483  {
484  return;
485  }
486 
487  if ( !( d_data->discardFlags & DiscardBackground ) )
488  QwtPainter::drawBackgound( painter, plotRect, plot );
489 
490  /*
491  The layout engine uses the same methods as they are used
492  by the Qt layout system. Therefore we need to calculate the
493  layout in screen coordinates and paint with a scaled painter.
494  */
495  QTransform transform;
496  transform.scale(
497  double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
498  double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );
499 
500  QRectF layoutRect = transform.inverted().mapRect( plotRect );
501 
502  if ( !( d_data->discardFlags & DiscardBackground ) )
503  {
504  // subtract the contents margins
505 
506  const QMargins m = plot->contentsMargins();
507  layoutRect.adjust( m.left(), m.top(), -m.right(), -m.bottom() );
508  }
509 
510  QwtPlotLayout *layout = plot->plotLayout();
511 
512  int baseLineDists[QwtPlot::axisCnt];
513  int canvasMargins[QwtPlot::axisCnt];
514 
515  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
516  {
517  canvasMargins[ axisId ] = layout->canvasMargin( axisId );
518 
520  {
521  QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
522  if ( scaleWidget )
523  {
524  baseLineDists[axisId] = scaleWidget->margin();
525  scaleWidget->setMargin( 0 );
526  }
527 
528  if ( !plot->axisEnabled( axisId ) )
529  {
530  // When we have a scale the frame is painted on
531  // the position of the backbone - otherwise we
532  // need to introduce a margin around the canvas
533 
534  const qreal fw = qwtScalePenWidth( plot );
535 
536  switch( axisId )
537  {
538  case QwtPlot::yLeft:
539  layoutRect.adjust( fw, 0, 0, 0 );
540  break;
541  case QwtPlot::yRight:
542  layoutRect.adjust( 0, 0, -fw, 0 );
543  break;
544  case QwtPlot::xTop:
545  layoutRect.adjust( 0, fw, 0, 0 );
546  break;
547  case QwtPlot::xBottom:
548  layoutRect.adjust( 0, 0, 0, -fw );
549  break;
550  default:
551  break;
552  }
553  }
554  }
555  }
556 
557  // Calculate the layout for the document.
558 
560 
561  if ( ( d_data->layoutFlags & FrameWithScales ) ||
563  {
564  layoutOptions |= QwtPlotLayout::IgnoreFrames;
565  }
566 
568  layoutOptions |= QwtPlotLayout::IgnoreLegend;
569 
571  layoutOptions |= QwtPlotLayout::IgnoreTitle;
572 
574  layoutOptions |= QwtPlotLayout::IgnoreFooter;
575 
576  layout->activate( plot, layoutRect, layoutOptions );
577 
578  // canvas
579 
581  buildCanvasMaps( plot, layout->canvasRect(), maps );
582  if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) )
583  {
584  // recalculate maps and layout, when the margins
585  // have been changed
586 
587  layout->activate( plot, layoutRect, layoutOptions );
588  buildCanvasMaps( plot, layout->canvasRect(), maps );
589  }
590 
591  // now start painting
592 
593  painter->save();
594  painter->setWorldTransform( transform, true );
595 
596  renderCanvas( plot, painter, layout->canvasRect(), maps );
597 
598  if ( !( d_data->discardFlags & DiscardTitle )
599  && ( !plot->titleLabel()->text().isEmpty() ) )
600  {
601  renderTitle( plot, painter, layout->titleRect() );
602  }
603 
604  if ( !( d_data->discardFlags & DiscardFooter )
605  && ( !plot->footerLabel()->text().isEmpty() ) )
606  {
607  renderFooter( plot, painter, layout->footerRect() );
608  }
609 
610  if ( !( d_data->discardFlags & DiscardLegend )
611  && plot->legend() && !plot->legend()->isEmpty() )
612  {
613  renderLegend( plot, painter, layout->legendRect() );
614  }
615 
616  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
617  {
618  QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
619  if ( scaleWidget )
620  {
621  int baseDist = scaleWidget->margin();
622 
623  int startDist, endDist;
624  scaleWidget->getBorderDistHint( startDist, endDist );
625 
626  renderScale( plot, painter, axisId, startDist, endDist,
627  baseDist, layout->scaleRect( axisId ) );
628  }
629  }
630 
631  painter->restore();
632 
633  // restore all setting to their original attributes.
634  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
635  {
637  {
638  QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
639  if ( scaleWidget )
640  scaleWidget->setMargin( baseLineDists[axisId] );
641  }
642 
643  layout->setCanvasMargin( canvasMargins[axisId] );
644  }
645 
646  layout->invalidate();
647 
648 }
649 
658  QPainter *painter, const QRectF &titleRect ) const
659 {
660  painter->setFont( qwtResolvedFont( plot->titleLabel() ) );
661 
662  const QColor color = plot->titleLabel()->palette().color(
663  QPalette::Active, QPalette::Text );
664 
665  painter->setPen( color );
666  plot->titleLabel()->text().draw( painter, titleRect );
667 }
668 
677  QPainter *painter, const QRectF &footerRect ) const
678 {
679  painter->setFont( qwtResolvedFont( plot->footerLabel() ) );
680 
681  const QColor color = plot->footerLabel()->palette().color(
682  QPalette::Active, QPalette::Text );
683 
684  painter->setPen( color );
685  plot->footerLabel()->text().draw( painter, footerRect );
686 }
687 
696  QPainter *painter, const QRectF &legendRect ) const
697 {
698  if ( plot->legend() )
699  {
700  bool fillBackground = !( d_data->discardFlags & DiscardBackground );
701  plot->legend()->renderLegend( painter, legendRect, fillBackground );
702  }
703 }
704 
717 void QwtPlotRenderer::renderScale( const QwtPlot *plot, QPainter *painter,
718  int axisId, int startDist, int endDist, int baseDist,
719  const QRectF &scaleRect ) const
720 {
721  if ( !plot->axisEnabled( axisId ) )
722  return;
723 
724  const QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
725  if ( scaleWidget->isColorBarEnabled()
726  && scaleWidget->colorBarWidth() > 0 )
727  {
728  scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( scaleRect ) );
729  baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing();
730  }
731 
732  painter->save();
733 
735  double x, y, w;
736 
737  qreal off = 0.0;
739  off = qwtScalePenWidth( plot );
740 
741  switch ( axisId )
742  {
743  case QwtPlot::yLeft:
744  {
745  x = scaleRect.right() - 1.0 - baseDist - off;
746  y = scaleRect.y() + startDist;
747  w = scaleRect.height() - startDist - endDist;
748  align = QwtScaleDraw::LeftScale;
749  break;
750  }
751  case QwtPlot::yRight:
752  {
753  x = scaleRect.left() + baseDist + off;
754  y = scaleRect.y() + startDist;
755  w = scaleRect.height() - startDist - endDist;
756  align = QwtScaleDraw::RightScale;
757  break;
758  }
759  case QwtPlot::xTop:
760  {
761  x = scaleRect.left() + startDist;
762  y = scaleRect.bottom() - 1.0 - baseDist - off;
763  w = scaleRect.width() - startDist - endDist;
764  align = QwtScaleDraw::TopScale;
765  break;
766  }
767  case QwtPlot::xBottom:
768  {
769  x = scaleRect.left() + startDist;
770  y = scaleRect.top() + baseDist + off;
771  w = scaleRect.width() - startDist - endDist;
773  break;
774  }
775  default:
776  return;
777  }
778 
779  scaleWidget->drawTitle( painter, align, scaleRect );
780 
781  painter->setFont( qwtResolvedFont( scaleWidget ) );
782 
783  QwtScaleDraw *sd = const_cast<QwtScaleDraw *>( scaleWidget->scaleDraw() );
784  const QPointF sdPos = sd->pos();
785  const double sdLength = sd->length();
786 
787  const bool hasBackbone = sd->hasComponent( QwtAbstractScaleDraw::Backbone );
788 
791 
792  sd->move( x, y );
793  sd->setLength( w );
794 
795  QPalette palette = scaleWidget->palette();
796  palette.setCurrentColorGroup( QPalette::Active );
797  sd->draw( painter, palette );
798 
799  // reset previous values
800  sd->move( sdPos );
801  sd->setLength( sdLength );
803 
804  painter->restore();
805 }
806 
816  QPainter *painter, const QRectF &canvasRect,
817  const QwtScaleMap *maps ) const
818 {
819  const QWidget *canvas = plot->canvas();
820 
821  QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
822 
824  {
825  painter->save();
826 
827  QPen pen;
828  pen.setColor( qwtScalePenColor( plot ) );
829  pen.setWidth( qwtScalePenWidth( plot ) );
830  pen.setJoinStyle( Qt::MiterJoin );
831 
832  painter->setPen( pen );
833 
834  const qreal pw2 = 0.5 * pen.widthF();
835  r.adjust( -pw2, -pw2, pw2, pw2 );
836 
838  {
839  const QBrush bgBrush =
840  canvas->palette().brush( plot->backgroundRole() );
841  painter->setBrush( bgBrush );
842  }
843 
844  QwtPainter::drawRect( painter, r );
845 
846  painter->restore();
847  painter->save();
848 
849  painter->setClipRect( canvasRect );
850  plot->drawItems( painter, canvasRect, maps );
851 
852  painter->restore();
853  }
854  else if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
855  {
856  QPainterPath clipPath;
857 
858  painter->save();
859 
861  {
862  QwtPainter::drawBackgound( painter, r, canvas );
863  clipPath = qwtCanvasClip( canvas, canvasRect );
864  }
865 
866  painter->restore();
867  painter->save();
868 
869  if ( clipPath.isEmpty() )
870  painter->setClipRect( canvasRect );
871  else
872  painter->setClipPath( clipPath );
873 
874  plot->drawItems( painter, canvasRect, maps );
875 
876  painter->restore();
877  }
878  else
879  {
880  QPainterPath clipPath;
881 
882  int frameWidth = 0;
883 
884  if ( !( d_data->discardFlags & DiscardCanvasFrame ) )
885  {
886  const QVariant fw = canvas->property( "frameWidth" );
887  if ( fw.type() == QVariant::Int )
888  frameWidth = fw.toInt();
889 
890  clipPath = qwtCanvasClip( canvas, canvasRect );
891  }
892 
893  QRectF innerRect = canvasRect.adjusted(
894  frameWidth, frameWidth, -frameWidth, -frameWidth );
895 
896  painter->save();
897 
898  if ( clipPath.isEmpty() )
899  {
900  painter->setClipRect( innerRect );
901  }
902  else
903  {
904  painter->setClipPath( clipPath );
905  }
906 
908  {
909  QwtPainter::drawBackgound( painter, innerRect, canvas );
910  }
911 
912  plot->drawItems( painter, innerRect, maps );
913 
914  painter->restore();
915 
916  if ( frameWidth > 0 )
917  {
918  painter->save();
919 
920  const int frameStyle =
921  canvas->property( "frameShadow" ).toInt() |
922  canvas->property( "frameShape" ).toInt();
923 
924  const QVariant borderRadius = canvas->property( "borderRadius" );
925  if ( borderRadius.type() == QVariant::Double
926  && borderRadius.toDouble() > 0.0 )
927  {
928  const double radius = borderRadius.toDouble();
929 
930  QwtPainter::drawRoundedFrame( painter, canvasRect,
931  radius, radius, canvas->palette(), frameWidth, frameStyle );
932  }
933  else
934  {
935  const int midLineWidth = canvas->property( "midLineWidth" ).toInt();
936 
937  QwtPainter::drawFrame( painter, canvasRect,
938  canvas->palette(), canvas->foregroundRole(),
939  frameWidth, midLineWidth, frameStyle );
940  }
941  painter->restore();
942  }
943  }
944 }
945 
954  const QRectF &canvasRect, QwtScaleMap maps[] ) const
955 {
956  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
957  {
958  maps[axisId].setTransformation(
959  plot->axisScaleEngine( axisId )->transformation() );
960 
961  const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
962  maps[axisId].setScaleInterval(
963  scaleDiv.lowerBound(), scaleDiv.upperBound() );
964 
965  double from, to;
966  if ( plot->axisEnabled( axisId ) )
967  {
968  const int sDist = plot->axisWidget( axisId )->startBorderDist();
969  const int eDist = plot->axisWidget( axisId )->endBorderDist();
970  const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
971 
972  if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom )
973  {
974  from = scaleRect.left() + sDist;
975  to = scaleRect.right() - eDist;
976  }
977  else
978  {
979  from = scaleRect.bottom() - eDist;
980  to = scaleRect.top() + sDist;
981  }
982  }
983  else
984  {
985  int margin = 0;
986  if ( !plot->plotLayout()->alignCanvasToScale( axisId ) )
987  margin = plot->plotLayout()->canvasMargin( axisId );
988 
989  if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight )
990  {
991  from = canvasRect.bottom() - margin;
992  to = canvasRect.top() + margin;
993  }
994  else
995  {
996  from = canvasRect.left() + margin;
997  to = canvasRect.right() - margin;
998  }
999  }
1000  maps[axisId].setPaintInterval( from, to );
1001  }
1002 }
1003 
1005  const QRectF &canvasRect, const QwtScaleMap maps[] ) const
1006 {
1007  double margins[QwtPlot::axisCnt];
1008  plot->getCanvasMarginsHint( maps, canvasRect,
1009  margins[QwtPlot::yLeft], margins[QwtPlot::xTop],
1010  margins[QwtPlot::yRight], margins[QwtPlot::xBottom] );
1011 
1012  bool marginsChanged = false;
1013  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
1014  {
1015  if ( margins[axisId] >= 0.0 )
1016  {
1017  const int m = qwtCeil( margins[axisId] );
1018  plot->plotLayout()->setCanvasMargin( m, axisId);
1019  marginsChanged = true;
1020  }
1021  }
1022 
1023  return marginsChanged;
1024 }
1025 
1037 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName,
1038  const QSizeF &sizeMM, int resolution )
1039 {
1040  if ( plot == NULL )
1041  return false;
1042 
1043  QString fileName = documentName;
1044 
1045  // What about translation
1046 
1047 #ifndef QT_NO_FILEDIALOG
1048  const QList<QByteArray> imageFormats =
1049  QImageWriter::supportedImageFormats();
1050 
1051  QStringList filter;
1052 #if QWT_FORMAT_PDF
1053  filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)";
1054 #endif
1055 #if QWT_FORMAT_SVG
1056  filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)";
1057 #endif
1058 #if QWT_FORMAT_POSTSCRIPT
1059  filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)";
1060 #endif
1061 
1062  if ( imageFormats.size() > 0 )
1063  {
1064  QString imageFilter( tr( "Images" ) );
1065  imageFilter += " (";
1066  for ( int i = 0; i < imageFormats.size(); i++ )
1067  {
1068  if ( i > 0 )
1069  imageFilter += " ";
1070  imageFilter += "*.";
1071  imageFilter += imageFormats[i];
1072  }
1073  imageFilter += ")";
1074 
1075  filter += imageFilter;
1076  }
1077 
1078  fileName = QFileDialog::getSaveFileName(
1079  NULL, tr( "Export File Name" ), fileName,
1080  filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
1081 #endif
1082  if ( fileName.isEmpty() )
1083  return false;
1084 
1085  renderDocument( plot, fileName, sizeMM, resolution );
1086 
1087  return true;
1088 }
1089 
1090 #if QWT_MOC_INCLUDE
1091 #include "moc_qwt_plot_renderer.cpp"
1092 #endif
LayoutFlag
Layout flags.
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.
bool updateCanvasMargins(QwtPlot *, const QRectF &, const QwtScaleMap maps[]) const
const QwtScaleDiv & axisScaleDiv(int axisId) const
Return the scale division of a specified axis.
int canvasMargin(int axisId) const
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
void setLength(double length)
X axis above the canvas.
Definition: qwt_plot.h:106
virtual void activate(const QwtPlot *, const QRectF &plotRect, Options options=Options())
Recalculate the geometry of all components.
Render all components of the plot.
QRectF legendRect() const
QwtTextLabel * titleLabel()
Definition: qwt_plot.cpp:354
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:660
Number of axes.
Definition: qwt_plot.h:109
virtual void drawItems(QPainter *, const QRectF &, const QwtScaleMap maps[axisCnt]) const
Definition: qwt_plot.cpp:750
int margin() const
The scale is above.
virtual void renderScale(const QwtPlot *, QPainter *, int axisId, int startDist, int endDist, int baseDist, const QRectF &scaleRect) const
Paint a scale into a given rectangle. Paint the scale into a given rectangle.
QRectF footerRect() const
void setLayoutFlags(LayoutFlags flags)
void setDiscardFlag(DiscardFlag flag, bool on=true)
QwtPlotRenderer::DiscardFlags discardFlags
Y axis right of the canvas.
Definition: qwt_plot.h:100
void draw(QPainter *painter, const QRectF &rect) const
Definition: qwt_text.cpp:592
const QwtText & text() const
Return the text.
A class representing a scale division.
Definition: qwt_scale_div.h:33
void setCanvasMargin(int margin, int axis=-1)
QwtTextLabel * footerLabel()
Definition: qwt_plot.cpp:398
static qreal qwtScalePenWidth(const QwtPlot *plot)
Use the default layout as on screen.
bool axisEnabled(int axisId) const
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
A 2-D plotting widget.
Definition: qwt_plot.h:75
QwtTransform * transformation() const
void setMargin(int)
Specify the margin to the colorBar/base line.
const QwtScaleDraw * scaleDraw() const
virtual void renderTitle(const QwtPlot *, QPainter *, const QRectF &titleRect) const
QPointF pos() const
Y axis left of the canvas.
Definition: qwt_plot.h:97
static void drawRoundedFrame(QPainter *, const QRectF &, qreal xRadius, qreal yRadius, const QPalette &, int lineWidth, int frameStyle)
bool testLayoutFlag(LayoutFlag flag) const
Renderer for exporting a plot to a document, a printer or anything else, that is supported by QPainte...
int qwtFloor(qreal value)
Definition: qwt_math.h:271
void buildCanvasMaps(const QwtPlot *, const QRectF &, QwtScaleMap maps[]) const
double upperBound() const
const QwtScaleWidget * axisWidget(int axisId) const
bool testDiscardFlag(DiscardFlag flag) const
QwtAbstractLegend * legend()
Definition: qwt_plot.cpp:442
LayoutFlags layoutFlags() const
virtual void renderCanvas(const QwtPlot *, QPainter *, const QRectF &canvasRect, const QwtScaleMap *maps) const
QRectF titleRect() const
static QColor qwtScalePenColor(const QwtPlot *plot)
Don&#39;t render the background of the canvas.
virtual bool isEmpty() const =0
int startBorderDist() const
Don&#39;t render the footer of the plot.
void * align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space, std::size_t &required_space)
Definition: sol.hpp:9768
QRectF scaleRect(int axis) const
DiscardFlags discardFlags() const
DiscardFlag
Disard flags.
The scale is left.
void setLayoutFlag(LayoutFlag flag, bool on=true)
void renderTo(QwtPlot *, QPrinter &) const
Render the plot to a QPrinter.
A Widget which contains a scale.
QRectF colorBarRect(const QRectF &) const
void drawTitle(QPainter *, QwtScaleDraw::Alignment, const QRectF &rect) const
double lowerBound() const
void setTransformation(QwtTransform *)
bool isEmpty() const
Definition: qwt_text.cpp:716
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
void setDiscardFlags(DiscardFlags flags)
PrivateData * d_data
static void drawFrame(QPainter *, const QRectF &rect, const QPalette &palette, QPalette::ColorRole foregroundRole, int lineWidth, int midLineWidth, int frameStyle)
virtual void renderLegend(const QwtPlot *, QPainter *, const QRectF &legendRect) const
QString text() const
Definition: qwt_text.cpp:266
virtual void invalidate()
QFlags< DiscardFlag > DiscardFlags
Disard flags.
virtual void renderFooter(const QwtPlot *, QPainter *, const QRectF &footerRect) const
QRectF canvasRect() const
Backbone = the line where the ticks are located.
j template void())
Definition: json.hpp:3707
static void drawBackgound(QPainter *, const QRectF &, const QWidget *)
A scale map.
Definition: qwt_scale_map.h:26
static QFont qwtResolvedFont(const QWidget *widget)
static QPainterPath qwtCanvasClip(const QWidget *canvas, const QRectF &canvasRect)
int endBorderDist() const
Don&#39;t render the title of the plot.
void enableComponent(ScaleComponent, bool enable=true)
virtual void renderLegend(QPainter *painter, const QRectF &rect, bool fillBackground) const =0
Don&#39;t render the background of the plot.
void renderDocument(QwtPlot *, const QString &fileName, const QSizeF &sizeMM, int resolution=85)
virtual ~QwtPlotRenderer()
Destructor.
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
int spacing() const
int colorBarWidth() const
QwtText title() const
Definition: qwt_plot.cpp:348
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
QWidget * canvas()
Definition: qwt_plot.cpp:460
bool alignCanvasToScale(int axisId) const
const QwtScaleDraw * axisScaleDraw(int axisId) const
Return the scale draw of a specified axis.
bool isColorBarEnabled() const
Layout engine for QwtPlot.
The scale is right.
double length() const
void getBorderDistHint(int &start, int &end) const
Calculate a hint for the border distances.
QwtScaleEngine * axisScaleEngine(int axisId)
bool hasComponent(ScaleComponent) const
A class for drawing scales.
Don&#39;t render the legend of the plot.
QFlags< LayoutFlag > LayoutFlags
Layout flags.
virtual void render(QwtPlot *, QPainter *, const QRectF &plotRect) const
void drawColorBar(QPainter *, const QRectF &) const
int qwtCeil(qreal value)
Definition: qwt_math.h:262
The scale is below.
X axis below the canvas.
Definition: qwt_plot.h:103
QwtPlotLayout * plotLayout()
Definition: qwt_plot.cpp:427
QFlags< Option > Options
Layout options.
void move(double x, double y)
QwtPlotRenderer::LayoutFlags layoutFlags
QwtPlotRenderer(QObject *=NULL)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10