qwt_plot_rasteritem.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_RASTERITEM_H
  10. #define QWT_PLOT_RASTERITEM_H
  11. #include "qwt_global.h"
  12. #include "qwt_plot_item.h"
  13. #include "qwt_interval.h"
  14. #include <qglobal.h>
  15. #include <qstring.h>
  16. #include <qimage.h>
  17. /*!
  18. \brief A class, which displays raster data
  19. Raster data is a grid of pixel values, that can be represented
  20. as a QImage. It is used for many types of information like
  21. spectrograms, cartograms, geographical maps ...
  22. Often a plot has several types of raster data organized in layers.
  23. ( f.e a geographical map, with weather statistics ).
  24. Using setAlpha() raster items can be stacked easily.
  25. QwtPlotRasterItem is only implemented for images of the following formats:
  26. QImage::Format_Indexed8, QImage::Format_ARGB32.
  27. \sa QwtPlotSpectrogram
  28. */
  29. class QWT_EXPORT QwtPlotRasterItem: public QwtPlotItem
  30. {
  31. public:
  32. /*!
  33. \brief Cache policy
  34. The default policy is NoCache
  35. */
  36. enum CachePolicy
  37. {
  38. /*!
  39. renderImage() is called each time the item has to be repainted
  40. */
  41. NoCache,
  42. /*!
  43. renderImage() is called, whenever the image cache is not valid,
  44. or the scales, or the size of the canvas has changed.
  45. This type of cache is useful for improving the performance
  46. of hide/show operations or manipulations of the alpha value.
  47. All other situations are handled by the canvas backing store.
  48. */
  49. PaintCache
  50. };
  51. /*!
  52. Attributes to modify the drawing algorithm.
  53. \sa setPaintAttribute(), testPaintAttribute()
  54. */
  55. enum PaintAttribute
  56. {
  57. /*!
  58. When the image is rendered according to the data pixels
  59. ( QwtRasterData::pixelHint() ) it can be expanded to paint
  60. device resolution before it is passed to QPainter.
  61. The expansion algorithm rounds the pixel borders in the same
  62. way as the axis ticks, what is usually better than the
  63. scaling algorithm implemented in Qt.
  64. Disabling this flag might make sense, to reduce the size of a
  65. document/file. If this is possible for a document format
  66. depends on the implementation of the specific QPaintEngine.
  67. */
  68. PaintInDeviceResolution = 1
  69. };
  70. //! Paint attributes
  71. typedef QFlags<PaintAttribute> PaintAttributes;
  72. explicit QwtPlotRasterItem( const QString& title = QString() );
  73. explicit QwtPlotRasterItem( const QwtText& title );
  74. virtual ~QwtPlotRasterItem();
  75. void setPaintAttribute( PaintAttribute, bool on = true );
  76. bool testPaintAttribute( PaintAttribute ) const;
  77. void setAlpha( int alpha );
  78. int alpha() const;
  79. void setCachePolicy( CachePolicy );
  80. CachePolicy cachePolicy() const;
  81. void invalidateCache();
  82. virtual void draw( QPainter *,
  83. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  84. const QRectF &canvasRect ) const;
  85. virtual QRectF pixelHint( const QRectF & ) const;
  86. virtual QwtInterval interval(Qt::Axis) const;
  87. virtual QRectF boundingRect() const;
  88. protected:
  89. /*!
  90. \brief Render an image
  91. An implementation of render() might iterate over all
  92. pixels of imageRect. Each pixel has to be translated into
  93. the corresponding position in scale coordinates using the maps.
  94. This position can be used to look up a value in a implementation
  95. specific way and to map it into a color.
  96. \param xMap X-Scale Map
  97. \param yMap Y-Scale Map
  98. \param area Requested area for the image in scale coordinates
  99. \param imageSize Requested size of the image
  100. \return Rendered image
  101. */
  102. virtual QImage renderImage( const QwtScaleMap &xMap,
  103. const QwtScaleMap &yMap, const QRectF &area,
  104. const QSize &imageSize ) const = 0;
  105. virtual QwtScaleMap imageMap( Qt::Orientation,
  106. const QwtScaleMap &map, const QRectF &area,
  107. const QSize &imageSize, double pixelSize) const;
  108. private:
  109. QwtPlotRasterItem( const QwtPlotRasterItem & );
  110. QwtPlotRasterItem &operator=( const QwtPlotRasterItem & );
  111. void init();
  112. QImage compose( const QwtScaleMap &, const QwtScaleMap &,
  113. const QRectF &imageArea, const QRectF &paintRect,
  114. const QSize &imageSize, bool doCache) const;
  115. class PrivateData;
  116. PrivateData *d_data;
  117. };
  118. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotRasterItem::PaintAttributes )
  119. #endif