qwt_plot_rescaler.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_RESCALER_H
  10. #define QWT_PLOT_RESCALER_H 1
  11. #include "qwt_global.h"
  12. #include "qwt_interval.h"
  13. #include "qwt_plot.h"
  14. #include <qobject.h>
  15. class QwtPlot;
  16. class QResizeEvent;
  17. /*!
  18. \brief QwtPlotRescaler takes care of fixed aspect ratios for plot scales
  19. QwtPlotRescaler auto adjusts the axes of a QwtPlot according
  20. to fixed aspect ratios.
  21. */
  22. class QWT_EXPORT QwtPlotRescaler: public QObject
  23. {
  24. public:
  25. /*!
  26. The rescale policy defines how to rescale the reference axis and
  27. their depending axes.
  28. \sa ExpandingDirection, setIntervalHint()
  29. */
  30. enum RescalePolicy
  31. {
  32. /*!
  33. The interval of the reference axis remains unchanged, when the
  34. geometry of the canvas changes. All other axes
  35. will be adjusted according to their aspect ratio.
  36. */
  37. Fixed,
  38. /*!
  39. The interval of the reference axis will be shrunk/expanded,
  40. when the geometry of the canvas changes. All other axes
  41. will be adjusted according to their aspect ratio.
  42. The interval, that is represented by one pixel is fixed.
  43. */
  44. Expanding,
  45. /*!
  46. The intervals of the axes are calculated, so that all axes include
  47. their interval hint.
  48. */
  49. Fitting
  50. };
  51. /*!
  52. When rescalePolicy() is set to Expanding its direction depends
  53. on ExpandingDirection
  54. */
  55. enum ExpandingDirection
  56. {
  57. //! The upper limit of the scale is adjusted
  58. ExpandUp,
  59. //! The lower limit of the scale is adjusted
  60. ExpandDown,
  61. //! Both limits of the scale are adjusted
  62. ExpandBoth
  63. };
  64. explicit QwtPlotRescaler( QWidget *canvas,
  65. int referenceAxis = QwtPlot::xBottom,
  66. RescalePolicy = Expanding );
  67. virtual ~QwtPlotRescaler();
  68. void setEnabled( bool );
  69. bool isEnabled() const;
  70. void setRescalePolicy( RescalePolicy );
  71. RescalePolicy rescalePolicy() const;
  72. void setExpandingDirection( ExpandingDirection );
  73. void setExpandingDirection( int axis, ExpandingDirection );
  74. ExpandingDirection expandingDirection( int axis ) const;
  75. void setReferenceAxis( int axis );
  76. int referenceAxis() const;
  77. void setAspectRatio( double ratio );
  78. void setAspectRatio( int axis, double ratio );
  79. double aspectRatio( int axis ) const;
  80. void setIntervalHint( int axis, const QwtInterval& );
  81. QwtInterval intervalHint( int axis ) const;
  82. QWidget *canvas();
  83. const QWidget *canvas() const;
  84. QwtPlot *plot();
  85. const QwtPlot *plot() const;
  86. virtual bool eventFilter( QObject *, QEvent * );
  87. void rescale() const;
  88. protected:
  89. virtual void canvasResizeEvent( QResizeEvent * );
  90. virtual void rescale( const QSize &oldSize, const QSize &newSize ) const;
  91. virtual QwtInterval expandScale(
  92. int axis, const QSize &oldSize, const QSize &newSize ) const;
  93. virtual QwtInterval syncScale(
  94. int axis, const QwtInterval& reference,
  95. const QSize &size ) const;
  96. virtual void updateScales(
  97. QwtInterval intervals[QwtPlot::axisCnt] ) const;
  98. Qt::Orientation orientation( int axis ) const;
  99. QwtInterval interval( int axis ) const;
  100. QwtInterval expandInterval( const QwtInterval &,
  101. double width, ExpandingDirection ) const;
  102. private:
  103. double pixelDist( int axis, const QSize & ) const;
  104. class AxisData;
  105. class PrivateData;
  106. PrivateData *d_data;
  107. };
  108. #endif