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_text.h"
18 #include "qwt_text_label.h"
19 #include "qwt_math.h"
20 #include <qpainter.h>
21 #include <qpaintengine.h>
22 #include <qtransform.h>
23 #include <qprinter.h>
24 #include <qprintdialog.h>
25 #include <qfiledialog.h>
26 #include <qfileinfo.h>
27 #include <qstyle.h>
28 #include <qstyleoption.h>
29 #include <qimagewriter.h>
30 
31 #ifndef QWT_NO_SVG
32 #ifdef QT_SVG_LIB
33 #if QT_VERSION >= 0x040500
34 #define QWT_FORMAT_SVG 1
35 #endif
36 #endif
37 #endif
38 
39 #ifndef QT_NO_PRINTER
40 #define QWT_FORMAT_PDF 1
41 #endif
42 
43 #ifndef QT_NO_PDF
44 
45 // QPdfWriter::setResolution() has been introduced with
46 // Qt 5.3. Guess it is o.k. to stay with QPrinter for older
47 // versions.
48 
49 #if QT_VERSION >= 0x050300
50 
51 #ifndef QWT_FORMAT_PDF
52 #define QWT_FORMAT_PDF 1
53 #endif
54 
55 #define QWT_PDF_WRITER 1
56 
57 #endif
58 #endif
59 
60 #ifndef QT_NO_PRINTER
61 // postscript support has been dropped in Qt5
62 #if QT_VERSION < 0x050000
63 #define QWT_FORMAT_POSTSCRIPT 1
64 #endif
65 #endif
66 
67 #if QWT_FORMAT_SVG
68 #include <qsvggenerator.h>
69 #endif
70 
71 #if QWT_PDF_WRITER
72 #include <qpdfwriter.h>
73 #endif
74 
75 static QPainterPath qwtCanvasClip(
76  const QWidget* canvas, const QRectF &canvasRect )
77 {
78  // The clip region is calculated in integers
79  // To avoid too much rounding errors better
80  // calculate it in target device resolution
81 
82  int x1 = qCeil( canvasRect.left() );
83  int x2 = qFloor( canvasRect.right() );
84  int y1 = qCeil( canvasRect.top() );
85  int y2 = qFloor( canvasRect.bottom() );
86 
87  const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 );
88 
89  QPainterPath clipPath;
90 
91  ( void ) QMetaObject::invokeMethod(
92  const_cast< QWidget *>( canvas ), "borderPath",
93  Qt::DirectConnection,
94  Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) );
95 
96  return clipPath;
97 }
98 
100 {
101 public:
105  {
106  }
107 
110 };
111 
117  QObject( parent )
118 {
119  d_data = new PrivateData;
120 }
121 
124 {
125  delete d_data;
126 }
127 
137 {
138  if ( on )
139  d_data->discardFlags |= flag;
140  else
141  d_data->discardFlags &= ~flag;
142 }
143 
150 {
151  return d_data->discardFlags & flag;
152 }
153 
161 {
162  d_data->discardFlags = flags;
163 }
164 
170 {
171  return d_data->discardFlags;
172 }
173 
183 {
184  if ( on )
185  d_data->layoutFlags |= flag;
186  else
187  d_data->layoutFlags &= ~flag;
188 }
189 
196 {
197  return d_data->layoutFlags & flag;
198 }
199 
207 {
208  d_data->layoutFlags = flags;
209 }
210 
216 {
217  return d_data->layoutFlags;
218 }
219 
232  const QString &fileName, const QSizeF &sizeMM, int resolution )
233 {
234  renderDocument( plot, fileName,
235  QFileInfo( fileName ).suffix(), sizeMM, resolution );
236 }
237 
264  const QString &fileName, const QString &format,
265  const QSizeF &sizeMM, int resolution )
266 {
267  if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
268  return;
269 
270  QString title = plot->title().text();
271  if ( title.isEmpty() )
272  title = "Plot Document";
273 
274  const double mmToInch = 1.0 / 25.4;
275  const QSizeF size = sizeMM * mmToInch * resolution;
276 
277  const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );
278 
279  const QString fmt = format.toLower();
280  if ( fmt == QLatin1String( "pdf" ) )
281  {
282 #if QWT_FORMAT_PDF
283 
284 #if QWT_PDF_WRITER
285  QPdfWriter pdfWriter( fileName );
286  pdfWriter.setPageSizeMM( sizeMM );
287  pdfWriter.setTitle( title );
288  pdfWriter.setPageMargins( QMarginsF() );
289  pdfWriter.setResolution( resolution );
290 
291  QPainter painter( &pdfWriter );
292  render( plot, &painter, documentRect );
293 #else
294  QPrinter printer;
295  printer.setOutputFormat( QPrinter::PdfFormat );
296  printer.setColorMode( QPrinter::Color );
297  printer.setFullPage( true );
298  printer.setPaperSize( sizeMM, QPrinter::Millimeter );
299  printer.setDocName( title );
300  printer.setOutputFileName( fileName );
301  printer.setResolution( resolution );
302 
303  QPainter painter( &printer );
304  render( plot, &painter, documentRect );
305 #endif
306 #endif
307  }
308  else if ( fmt == QLatin1String( "ps" ) )
309  {
310 #if QWT_FORMAT_POSTSCRIPT
311  QPrinter printer;
312  printer.setOutputFormat( QPrinter::PostScriptFormat );
313  printer.setColorMode( QPrinter::Color );
314  printer.setFullPage( true );
315  printer.setPaperSize( sizeMM, QPrinter::Millimeter );
316  printer.setDocName( title );
317  printer.setOutputFileName( fileName );
318  printer.setResolution( resolution );
319 
320  QPainter painter( &printer );
321  render( plot, &painter, documentRect );
322 #endif
323  }
324  else if ( fmt == QLatin1String( "svg" ) )
325  {
326 #if QWT_FORMAT_SVG
327  QSvgGenerator generator;
328  generator.setTitle( title );
329  generator.setFileName( fileName );
330  generator.setResolution( resolution );
331  generator.setViewBox( documentRect );
332 
333  QPainter painter( &generator );
334  render( plot, &painter, documentRect );
335 #endif
336  }
337  else
338  {
339  if ( QImageWriter::supportedImageFormats().indexOf(
340  format.toLatin1() ) >= 0 )
341  {
342  const QRect imageRect = documentRect.toRect();
343  const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 );
344 
345  QImage image( imageRect.size(), QImage::Format_ARGB32 );
346  image.setDotsPerMeterX( dotsPerMeter );
347  image.setDotsPerMeterY( dotsPerMeter );
348  image.fill( QColor( Qt::white ).rgb() );
349 
350  QPainter painter( &image );
351  render( plot, &painter, imageRect );
352  painter.end();
353 
354  image.save( fileName, format.toLatin1() );
355  }
356  }
357 }
358 
373  QwtPlot *plot, QPaintDevice &paintDevice ) const
374 {
375  int w = paintDevice.width();
376  int h = paintDevice.height();
377 
378  QPainter p( &paintDevice );
379  render( plot, &p, QRectF( 0, 0, w, h ) );
380 }
381 
395 #ifndef QT_NO_PRINTER
396 
398  QwtPlot *plot, QPrinter &printer ) const
399 {
400  int w = printer.width();
401  int h = printer.height();
402 
403  QRectF rect( 0, 0, w, h );
404  double aspect = rect.width() / rect.height();
405  if ( ( aspect < 1.0 ) )
406  rect.setHeight( aspect * rect.width() );
407 
408  QPainter p( &printer );
409  render( plot, &p, rect );
410 }
411 
412 #endif
413 
414 #if QWT_FORMAT_SVG
415 
428  QwtPlot *plot, QSvgGenerator &generator ) const
429 {
430  QRectF rect = generator.viewBoxF();
431  if ( rect.isEmpty() )
432  rect.setRect( 0, 0, generator.width(), generator.height() );
433 
434  if ( rect.isEmpty() )
435  rect.setRect( 0, 0, 800, 600 ); // something
436 
437  QPainter p( &generator );
438  render( plot, &p, rect );
439 }
440 
441 #endif
442 
453  QPainter *painter, const QRectF &plotRect ) const
454 {
455  if ( painter == 0 || !painter->isActive() ||
456  !plotRect.isValid() || plot->size().isNull() )
457  {
458  return;
459  }
460 
461  if ( !( d_data->discardFlags & DiscardBackground ) )
462  QwtPainter::drawBackgound( painter, plotRect, plot );
463 
464  /*
465  The layout engine uses the same methods as they are used
466  by the Qt layout system. Therefore we need to calculate the
467  layout in screen coordinates and paint with a scaled painter.
468  */
469  QTransform transform;
470  transform.scale(
471  double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(),
472  double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );
473 
474  QRectF layoutRect = transform.inverted().mapRect( plotRect );
475 
476  if ( !( d_data->discardFlags & DiscardBackground ) )
477  {
478  // subtract the contents margins
479 
480  int left, top, right, bottom;
481  plot->getContentsMargins( &left, &top, &right, &bottom );
482  layoutRect.adjust( left, top, -right, -bottom );
483  }
484 
485  QwtPlotLayout *layout = plot->plotLayout();
486 
487  int baseLineDists[QwtPlot::axisCnt];
488  int canvasMargins[QwtPlot::axisCnt];
489 
490  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
491  {
492  canvasMargins[ axisId ] = layout->canvasMargin( axisId );
493 
495  {
496  QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
497  if ( scaleWidget )
498  {
499  baseLineDists[axisId] = scaleWidget->margin();
500  scaleWidget->setMargin( 0 );
501  }
502 
503  if ( !plot->axisEnabled( axisId ) )
504  {
505  int left = 0;
506  int right = 0;
507  int top = 0;
508  int bottom = 0;
509 
510  // When we have a scale the frame is painted on
511  // the position of the backbone - otherwise we
512  // need to introduce a margin around the canvas
513 
514  switch( axisId )
515  {
516  case QwtPlot::yLeft:
517  layoutRect.adjust( 1, 0, 0, 0 );
518  break;
519  case QwtPlot::yRight:
520  layoutRect.adjust( 0, 0, -1, 0 );
521  break;
522  case QwtPlot::xTop:
523  layoutRect.adjust( 0, 1, 0, 0 );
524  break;
525  case QwtPlot::xBottom:
526  layoutRect.adjust( 0, 0, 0, -1 );
527  break;
528  default:
529  break;
530  }
531  layoutRect.adjust( left, top, right, bottom );
532  }
533  }
534  }
535 
536  // Calculate the layout for the document.
537 
539 
540  if ( ( d_data->layoutFlags & FrameWithScales ) ||
542  {
543  layoutOptions |= QwtPlotLayout::IgnoreFrames;
544  }
545 
546 
548  layoutOptions |= QwtPlotLayout::IgnoreLegend;
549 
551  layoutOptions |= QwtPlotLayout::IgnoreTitle;
552 
554  layoutOptions |= QwtPlotLayout::IgnoreFooter;
555 
556  layout->activate( plot, layoutRect, layoutOptions );
557 
558  // canvas
559 
561  buildCanvasMaps( plot, layout->canvasRect(), maps );
562  if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) )
563  {
564  // recalculate maps and layout, when the margins
565  // have been changed
566 
567  layout->activate( plot, layoutRect, layoutOptions );
568  buildCanvasMaps( plot, layout->canvasRect(), maps );
569  }
570 
571  // now start painting
572 
573  painter->save();
574  painter->setWorldTransform( transform, true );
575 
576  renderCanvas( plot, painter, layout->canvasRect(), maps );
577 
578  if ( !( d_data->discardFlags & DiscardTitle )
579  && ( !plot->titleLabel()->text().isEmpty() ) )
580  {
581  renderTitle( plot, painter, layout->titleRect() );
582  }
583 
584  if ( !( d_data->discardFlags & DiscardFooter )
585  && ( !plot->footerLabel()->text().isEmpty() ) )
586  {
587  renderFooter( plot, painter, layout->footerRect() );
588  }
589 
590  if ( !( d_data->discardFlags & DiscardLegend )
591  && plot->legend() && !plot->legend()->isEmpty() )
592  {
593  renderLegend( plot, painter, layout->legendRect() );
594  }
595 
596  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
597  {
598  QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
599  if ( scaleWidget )
600  {
601  int baseDist = scaleWidget->margin();
602 
603  int startDist, endDist;
604  scaleWidget->getBorderDistHint( startDist, endDist );
605 
606  renderScale( plot, painter, axisId, startDist, endDist,
607  baseDist, layout->scaleRect( axisId ) );
608  }
609  }
610 
611  painter->restore();
612 
613  // restore all setting to their original attributes.
614  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
615  {
617  {
618  QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
619  if ( scaleWidget )
620  scaleWidget->setMargin( baseLineDists[axisId] );
621  }
622 
623  layout->setCanvasMargin( canvasMargins[axisId] );
624  }
625 
626  layout->invalidate();
627 
628 }
629 
638  QPainter *painter, const QRectF &rect ) const
639 {
640  painter->setFont( plot->titleLabel()->font() );
641 
642  const QColor color = plot->titleLabel()->palette().color(
643  QPalette::Active, QPalette::Text );
644 
645  painter->setPen( color );
646  plot->titleLabel()->text().draw( painter, rect );
647 }
648 
657  QPainter *painter, const QRectF &rect ) const
658 {
659  painter->setFont( plot->footerLabel()->font() );
660 
661  const QColor color = plot->footerLabel()->palette().color(
662  QPalette::Active, QPalette::Text );
663 
664  painter->setPen( color );
665  plot->footerLabel()->text().draw( painter, rect );
666 }
667 
668 
677  QPainter *painter, const QRectF &rect ) const
678 {
679  if ( plot->legend() )
680  {
681  bool fillBackground = !( d_data->discardFlags & DiscardBackground );
682  plot->legend()->renderLegend( painter, rect, fillBackground );
683  }
684 }
685 
699  QPainter *painter,
700  int axisId, int startDist, int endDist, int baseDist,
701  const QRectF &rect ) const
702 {
703  if ( !plot->axisEnabled( axisId ) )
704  return;
705 
706  const QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
707  if ( scaleWidget->isColorBarEnabled()
708  && scaleWidget->colorBarWidth() > 0 )
709  {
710  scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) );
711  baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing();
712  }
713 
714  painter->save();
715 
717  double x, y, w;
718 
719  switch ( axisId )
720  {
721  case QwtPlot::yLeft:
722  {
723  x = rect.right() - 1.0 - baseDist;
724  y = rect.y() + startDist;
725  w = rect.height() - startDist - endDist;
726  align = QwtScaleDraw::LeftScale;
727  break;
728  }
729  case QwtPlot::yRight:
730  {
731  x = rect.left() + baseDist;
732  y = rect.y() + startDist;
733  w = rect.height() - startDist - endDist;
734  align = QwtScaleDraw::RightScale;
735  break;
736  }
737  case QwtPlot::xTop:
738  {
739  x = rect.left() + startDist;
740  y = rect.bottom() - 1.0 - baseDist;
741  w = rect.width() - startDist - endDist;
742  align = QwtScaleDraw::TopScale;
743  break;
744  }
745  case QwtPlot::xBottom:
746  {
747  x = rect.left() + startDist;
748  y = rect.top() + baseDist;
749  w = rect.width() - startDist - endDist;
751  break;
752  }
753  default:
754  return;
755  }
756 
757  scaleWidget->drawTitle( painter, align, rect );
758 
759  painter->setFont( scaleWidget->font() );
760 
761  QwtScaleDraw *sd = const_cast<QwtScaleDraw *>( scaleWidget->scaleDraw() );
762  const QPointF sdPos = sd->pos();
763  const double sdLength = sd->length();
764 
765  sd->move( x, y );
766  sd->setLength( w );
767 
768  QPalette palette = scaleWidget->palette();
769  palette.setCurrentColorGroup( QPalette::Active );
770  sd->draw( painter, palette );
771 
772  // reset previous values
773  sd->move( sdPos );
774  sd->setLength( sdLength );
775 
776  painter->restore();
777 }
778 
788  QPainter *painter, const QRectF &canvasRect,
789  const QwtScaleMap *map ) const
790 {
791  const QWidget *canvas = plot->canvas();
792 
793  QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
794 
796  {
797  painter->save();
798 
799  r.adjust( -1.0, -1.0, 1.0, 1.0 );
800  painter->setPen( QPen( Qt::black ) );
801 
803  {
804  const QBrush bgBrush =
805  canvas->palette().brush( plot->backgroundRole() );
806  painter->setBrush( bgBrush );
807  }
808 
809  QwtPainter::drawRect( painter, r );
810 
811  painter->restore();
812  painter->save();
813 
814  painter->setClipRect( canvasRect );
815  plot->drawItems( painter, canvasRect, map );
816 
817  painter->restore();
818  }
819  else if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
820  {
821  QPainterPath clipPath;
822 
823  painter->save();
824 
826  {
827  QwtPainter::drawBackgound( painter, r, canvas );
828  clipPath = qwtCanvasClip( canvas, canvasRect );
829  }
830 
831  painter->restore();
832  painter->save();
833 
834  if ( clipPath.isEmpty() )
835  painter->setClipRect( canvasRect );
836  else
837  painter->setClipPath( clipPath );
838 
839  plot->drawItems( painter, canvasRect, map );
840 
841  painter->restore();
842  }
843  else
844  {
845  QPainterPath clipPath;
846 
847  int frameWidth = 0;
848 
849  if ( !( d_data->discardFlags & DiscardCanvasFrame ) )
850  {
851  const QVariant fw = canvas->property( "frameWidth" );
852  if ( fw.type() == QVariant::Int )
853  frameWidth = fw.toInt();
854 
855  clipPath = qwtCanvasClip( canvas, canvasRect );
856  }
857 
858  QRectF innerRect = canvasRect.adjusted(
859  frameWidth, frameWidth, -frameWidth, -frameWidth );
860 
861  painter->save();
862 
863  if ( clipPath.isEmpty() )
864  {
865  painter->setClipRect( innerRect );
866  }
867  else
868  {
869  painter->setClipPath( clipPath );
870  }
871 
873  {
874  QwtPainter::drawBackgound( painter, innerRect, canvas );
875  }
876 
877  plot->drawItems( painter, innerRect, map );
878 
879  painter->restore();
880 
881  if ( frameWidth > 0 )
882  {
883  painter->save();
884 
885  const int frameStyle =
886  canvas->property( "frameShadow" ).toInt() |
887  canvas->property( "frameShape" ).toInt();
888 
889  const int frameWidth = canvas->property( "frameWidth" ).toInt();
890 
891 
892  const QVariant borderRadius = canvas->property( "borderRadius" );
893  if ( borderRadius.type() == QVariant::Double
894  && borderRadius.toDouble() > 0.0 )
895  {
896  const double r = borderRadius.toDouble();
897 
898  QwtPainter::drawRoundedFrame( painter, canvasRect,
899  r, r, canvas->palette(), frameWidth, frameStyle );
900  }
901  else
902  {
903  const int midLineWidth = canvas->property( "midLineWidth" ).toInt();
904 
905  QwtPainter::drawFrame( painter, canvasRect,
906  canvas->palette(), canvas->foregroundRole(),
907  frameWidth, midLineWidth, frameStyle );
908  }
909  painter->restore();
910  }
911  }
912 }
913 
922  const QRectF &canvasRect, QwtScaleMap maps[] ) const
923 {
924  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
925  {
926  maps[axisId].setTransformation(
927  plot->axisScaleEngine( axisId )->transformation() );
928 
929  const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
930  maps[axisId].setScaleInterval(
931  scaleDiv.lowerBound(), scaleDiv.upperBound() );
932 
933  double from, to;
934  if ( plot->axisEnabled( axisId ) )
935  {
936  const int sDist = plot->axisWidget( axisId )->startBorderDist();
937  const int eDist = plot->axisWidget( axisId )->endBorderDist();
938  const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
939 
940  if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom )
941  {
942  from = scaleRect.left() + sDist;
943  to = scaleRect.right() - eDist;
944  }
945  else
946  {
947  from = scaleRect.bottom() - eDist;
948  to = scaleRect.top() + sDist;
949  }
950  }
951  else
952  {
953  int margin = 0;
954  if ( !plot->plotLayout()->alignCanvasToScale( axisId ) )
955  margin = plot->plotLayout()->canvasMargin( axisId );
956 
957  if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight )
958  {
959  from = canvasRect.bottom() - margin;
960  to = canvasRect.top() + margin;
961  }
962  else
963  {
964  from = canvasRect.left() + margin;
965  to = canvasRect.right() - margin;
966  }
967  }
968  maps[axisId].setPaintInterval( from, to );
969  }
970 }
971 
973  const QRectF &canvasRect, const QwtScaleMap maps[] ) const
974 {
975  double margins[QwtPlot::axisCnt];
976  plot->getCanvasMarginsHint( maps, canvasRect,
977  margins[QwtPlot::yLeft], margins[QwtPlot::xTop],
978  margins[QwtPlot::yRight], margins[QwtPlot::xBottom] );
979 
980  bool marginsChanged = false;
981  for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
982  {
983  if ( margins[axisId] >= 0.0 )
984  {
985  const int m = qCeil( margins[axisId] );
986  plot->plotLayout()->setCanvasMargin( m, axisId);
987  marginsChanged = true;
988  }
989  }
990 
991  return marginsChanged;
992 }
993 
1005 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName,
1006  const QSizeF &sizeMM, int resolution )
1007 {
1008  if ( plot == NULL )
1009  return false;
1010 
1011  QString fileName = documentName;
1012 
1013  // What about translation
1014 
1015 #ifndef QT_NO_FILEDIALOG
1016  const QList<QByteArray> imageFormats =
1017  QImageWriter::supportedImageFormats();
1018 
1019  QStringList filter;
1020 #if QWT_FORMAT_PDF
1021  filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)";
1022 #endif
1023 #if QWT_FORMAT_SVG
1024  filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)";
1025 #endif
1026 #if QWT_FORMAT_POSTSCRIPT
1027  filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)";
1028 #endif
1029 
1030  if ( imageFormats.size() > 0 )
1031  {
1032  QString imageFilter( tr( "Images" ) );
1033  imageFilter += " (";
1034  for ( int i = 0; i < imageFormats.size(); i++ )
1035  {
1036  if ( i > 0 )
1037  imageFilter += " ";
1038  imageFilter += "*.";
1039  imageFilter += imageFormats[i];
1040  }
1041  imageFilter += ")";
1042 
1043  filter += imageFilter;
1044  }
1045 
1046  fileName = QFileDialog::getSaveFileName(
1047  NULL, tr( "Export File Name" ), fileName,
1048  filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
1049 #endif
1050  if ( fileName.isEmpty() )
1051  return false;
1052 
1053  renderDocument( plot, fileName, sizeMM, resolution );
1054 
1055  return true;
1056 }
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.
void drawColorBar(QPainter *painter, const QRectF &) const
bool updateCanvasMargins(QwtPlot *, const QRectF &, const QwtScaleMap maps[]) const
const QwtScaleDiv & axisScaleDiv(int axisId) const
Return the scale division of a specified axis.
void setLength(double length)
X axis above the canvas.
Definition: qwt_plot.h:105
Render all components of the plot.
QRectF legendRect() const
QwtTextLabel * titleLabel()
Definition: qwt_plot.cpp:361
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:667
Number of axes.
Definition: qwt_plot.h:108
virtual void drawItems(QPainter *, const QRectF &, const QwtScaleMap maps[axisCnt]) const
Definition: qwt_plot.cpp:757
int margin() const
The scale is above.
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:99
static void drawBackgound(QPainter *painter, const QRectF &rect, const QWidget *widget)
void draw(QPainter *painter, const QRectF &rect) const
Definition: qwt_text.cpp:560
const QwtText & text() const
Return the text.
A class representing a scale division.
Definition: qwt_scale_div.h:36
void setCanvasMargin(int margin, int axis=-1)
QwtTextLabel * footerLabel()
Definition: qwt_plot.cpp:405
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:74
QwtTransform * transformation() const
void setMargin(int)
Specify the margin to the colorBar/base line.
const QwtScaleDraw * scaleDraw() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
QPointF pos() const
Y axis left of the canvas.
Definition: qwt_plot.h:96
bool testLayoutFlag(LayoutFlag flag) const
Renderer for exporting a plot to a document, a printer or anything else, that is supported by QPainte...
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:449
LayoutFlags layoutFlags() const
virtual void renderCanvas(const QwtPlot *, QPainter *, const QRectF &canvasRect, const QwtScaleMap *maps) const
CONSTEXPR_F fields align(second_tag, fields f) noexcept
QRectF titleRect() const
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.
static void drawRoundedFrame(QPainter *, const QRectF &, double xRadius, double yRadius, const QPalette &, int lineWidth, int frameStyle)
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.
int canvasMargin(int axis) const
static void drawRect(QPainter *, double x, double y, double w, double h)
Wrapper for QPainter::drawRect()
virtual void activate(const QwtPlot *, const QRectF &rect, Options options=0x00)
Recalculate the geometry of all components.
A Widget which contains a scale.
QRectF colorBarRect(const QRectF &) const
size_t to
double lowerBound() const
void setTransformation(QwtTransform *)
bool isEmpty() const
Definition: qwt_text.h:213
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)
QString text() const
Definition: qwt_text.cpp:256
virtual void invalidate()
QFlags< DiscardFlag > DiscardFlags
Disard flags.
void drawTitle(QPainter *painter, QwtScaleDraw::Alignment, const QRectF &rect) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
QRectF canvasRect() const
A scale map.
Definition: qwt_scale_map.h:30
static QPainterPath qwtCanvasClip(const QWidget *canvas, const QRectF &canvasRect)
virtual void renderFooter(const QwtPlot *, QPainter *, const QRectF &) const
int endBorderDist() const
Don&#39;t render the title of the plot.
virtual void renderLegend(QPainter *painter, const QRectF &rect, bool fillBackground) const =0
Don&#39;t render the background of the plot.
uintptr_t size
void renderDocument(QwtPlot *, const QString &fileName, const QSizeF &sizeMM, int resolution=85)
virtual ~QwtPlotRenderer()
Destructor.
int spacing() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
int colorBarWidth() const
QwtText title() const
Definition: qwt_plot.cpp:355
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
QWidget * canvas()
Definition: qwt_plot.cpp:467
bool alignCanvasToScale(int axisId) const
virtual void renderTitle(const QwtPlot *, QPainter *, const QRectF &) const
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)
virtual void renderScale(const QwtPlot *, QPainter *, int axisId, int startDist, int endDist, int baseDist, const QRectF &) const
Paint a scale into a given rectangle. Paint the scale into a given rectangle.
A class for drawing scales.
Don&#39;t render the legend of the plot.
virtual void render(QwtPlot *, QPainter *, const QRectF &rect) const
QFlags< LayoutFlag > LayoutFlags
Layout flags.
int i
size_t from
The scale is below.
X axis below the canvas.
Definition: qwt_plot.h:102
QwtPlotLayout * plotLayout()
Definition: qwt_plot.cpp:434
QFlags< Option > Options
Layout options.
virtual void renderLegend(const QwtPlot *, QPainter *, const QRectF &) const
void move(double x, double y)
QwtPlotRenderer::LayoutFlags layoutFlags
QwtPlotRenderer(QObject *=NULL)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17