qwt_plot_renderer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #ifndef QWT_PLOT_RENDERER_H
  10. #define QWT_PLOT_RENDERER_H
  11. #include "qwt_global.h"
  12. #include <qobject.h>
  13. #include <qsize.h>
  14. class QwtPlot;
  15. class QwtScaleMap;
  16. class QRectF;
  17. class QPainter;
  18. class QPaintDevice;
  19. #ifndef QT_NO_PRINTER
  20. class QPrinter;
  21. #endif
  22. #ifndef QWT_NO_SVG
  23. #ifdef QT_SVG_LIB
  24. class QSvgGenerator;
  25. #endif
  26. #endif
  27. /*!
  28. \brief Renderer for exporting a plot to a document, a printer
  29. or anything else, that is supported by QPainter/QPaintDevice
  30. */
  31. class QWT_EXPORT QwtPlotRenderer: public QObject
  32. {
  33. Q_OBJECT
  34. public:
  35. //! Disard flags
  36. enum DiscardFlag
  37. {
  38. //! Render all components of the plot
  39. DiscardNone = 0x00,
  40. //! Don't render the background of the plot
  41. DiscardBackground = 0x01,
  42. //! Don't render the title of the plot
  43. DiscardTitle = 0x02,
  44. //! Don't render the legend of the plot
  45. DiscardLegend = 0x04,
  46. //! Don't render the background of the canvas
  47. DiscardCanvasBackground = 0x08,
  48. //! Don't render the footer of the plot
  49. DiscardFooter = 0x10,
  50. /*!
  51. Don't render the frame of the canvas
  52. \note This flag has no effect when using
  53. style sheets, where the frame is part
  54. of the background
  55. */
  56. DiscardCanvasFrame = 0x20
  57. };
  58. //! Disard flags
  59. typedef QFlags<DiscardFlag> DiscardFlags;
  60. /*!
  61. \brief Layout flags
  62. \sa setLayoutFlag(), testLayoutFlag()
  63. */
  64. enum LayoutFlag
  65. {
  66. //! Use the default layout as on screen
  67. DefaultLayout = 0x00,
  68. /*!
  69. Instead of the scales a box is painted around the plot canvas,
  70. where the scale ticks are aligned to.
  71. */
  72. FrameWithScales = 0x01
  73. };
  74. //! Layout flags
  75. typedef QFlags<LayoutFlag> LayoutFlags;
  76. explicit QwtPlotRenderer( QObject * = NULL );
  77. virtual ~QwtPlotRenderer();
  78. void setDiscardFlag( DiscardFlag flag, bool on = true );
  79. bool testDiscardFlag( DiscardFlag flag ) const;
  80. void setDiscardFlags( DiscardFlags flags );
  81. DiscardFlags discardFlags() const;
  82. void setLayoutFlag( LayoutFlag flag, bool on = true );
  83. bool testLayoutFlag( LayoutFlag flag ) const;
  84. void setLayoutFlags( LayoutFlags flags );
  85. LayoutFlags layoutFlags() const;
  86. void renderDocument( QwtPlot *, const QString &fileName,
  87. const QSizeF &sizeMM, int resolution = 85 );
  88. void renderDocument( QwtPlot *,
  89. const QString &fileName, const QString &format,
  90. const QSizeF &sizeMM, int resolution = 85 );
  91. #ifndef QWT_NO_SVG
  92. #ifdef QT_SVG_LIB
  93. #if QT_VERSION >= 0x040500
  94. void renderTo( QwtPlot *, QSvgGenerator & ) const;
  95. #endif
  96. #endif
  97. #endif
  98. #ifndef QT_NO_PRINTER
  99. void renderTo( QwtPlot *, QPrinter & ) const;
  100. #endif
  101. void renderTo( QwtPlot *, QPaintDevice & ) const;
  102. virtual void render( QwtPlot *,
  103. QPainter *, const QRectF &plotRect ) const;
  104. virtual void renderTitle( const QwtPlot *,
  105. QPainter *, const QRectF &titleRect ) const;
  106. virtual void renderFooter( const QwtPlot *,
  107. QPainter *, const QRectF &footerRect ) const;
  108. virtual void renderScale( const QwtPlot *, QPainter *,
  109. int axisId, int startDist, int endDist,
  110. int baseDist, const QRectF &scaleRect ) const;
  111. virtual void renderCanvas( const QwtPlot *,
  112. QPainter *, const QRectF &canvasRect,
  113. const QwtScaleMap* maps ) const;
  114. virtual void renderLegend(
  115. const QwtPlot *, QPainter *, const QRectF &legendRect ) const;
  116. bool exportTo( QwtPlot *, const QString &documentName,
  117. const QSizeF &sizeMM = QSizeF( 300, 200 ), int resolution = 85 );
  118. private:
  119. void buildCanvasMaps( const QwtPlot *,
  120. const QRectF &, QwtScaleMap maps[] ) const;
  121. bool updateCanvasMargins( QwtPlot *,
  122. const QRectF &, const QwtScaleMap maps[] ) const;
  123. private:
  124. class PrivateData;
  125. PrivateData *d_data;
  126. };
  127. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotRenderer::DiscardFlags )
  128. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotRenderer::LayoutFlags )
  129. #endif