Changeset 11158 in ntrip for trunk/BNC/qwt
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (5 weeks ago)
- Location:
- trunk/BNC/qwt
- Files:
-
- 60 added
- 2 deleted
- 193 edited
-
qwt.cpp (added)
-
qwt.h (modified) (2 diffs)
-
qwt.pro (modified) (1 diff)
-
qwt_abstract_legend.cpp (modified) (4 diffs)
-
qwt_abstract_legend.h (modified) (5 diffs)
-
qwt_abstract_scale.cpp (modified) (16 diffs)
-
qwt_abstract_scale.h (modified) (5 diffs)
-
qwt_abstract_scale_draw.cpp (modified) (20 diffs)
-
qwt_abstract_scale_draw.h (modified) (7 diffs)
-
qwt_abstract_slider.cpp (modified) (36 diffs)
-
qwt_abstract_slider.h (modified) (5 diffs)
-
qwt_analog_clock.cpp (modified) (12 diffs)
-
qwt_analog_clock.h (modified) (3 diffs)
-
qwt_arrow_button.cpp (modified) (17 diffs)
-
qwt_arrow_button.h (modified) (3 diffs)
-
qwt_axis.h (added)
-
qwt_axis_id.h (added)
-
qwt_bezier.cpp (added)
-
qwt_bezier.h (added)
-
qwt_clipper.cpp (modified) (12 diffs)
-
qwt_clipper.h (modified) (2 diffs)
-
qwt_color_map.cpp (modified) (25 diffs)
-
qwt_color_map.h (modified) (8 diffs)
-
qwt_column_symbol.cpp (modified) (13 diffs)
-
qwt_column_symbol.h (modified) (8 diffs)
-
qwt_compass.cpp (modified) (10 diffs)
-
qwt_compass.h (modified) (2 diffs)
-
qwt_compass_rose.cpp (modified) (14 diffs)
-
qwt_compass_rose.h (modified) (5 diffs)
-
qwt_compat.h (deleted)
-
qwt_counter.cpp (modified) (32 diffs)
-
qwt_counter.h (modified) (9 diffs)
-
qwt_curve_fitter.cpp (modified) (3 diffs)
-
qwt_curve_fitter.h (modified) (3 diffs)
-
qwt_date.cpp (modified) (28 diffs)
-
qwt_date.h (modified) (6 diffs)
-
qwt_date_scale_draw.cpp (modified) (11 diffs)
-
qwt_date_scale_draw.h (modified) (4 diffs)
-
qwt_date_scale_engine.cpp (modified) (43 diffs)
-
qwt_date_scale_engine.h (modified) (3 diffs)
-
qwt_dial.cpp (modified) (42 diffs)
-
qwt_dial.h (modified) (7 diffs)
-
qwt_dial_needle.cpp (modified) (18 diffs)
-
qwt_dial_needle.h (modified) (6 diffs)
-
qwt_dyngrid_layout.cpp (modified) (32 diffs)
-
qwt_dyngrid_layout.h (modified) (3 diffs)
-
qwt_event_pattern.cpp (modified) (10 diffs)
-
qwt_event_pattern.h (modified) (9 diffs)
-
qwt_global.h (modified) (4 diffs)
-
qwt_graphic.cpp (modified) (44 diffs)
-
qwt_graphic.h (modified) (5 diffs)
-
qwt_interval.cpp (modified) (18 diffs)
-
qwt_interval.h (modified) (23 diffs)
-
qwt_interval_symbol.cpp (modified) (13 diffs)
-
qwt_interval_symbol.h (modified) (4 diffs)
-
qwt_knob.cpp (modified) (46 diffs)
-
qwt_knob.h (modified) (7 diffs)
-
qwt_legend.cpp (modified) (33 diffs)
-
qwt_legend.h (modified) (5 diffs)
-
qwt_legend_data.cpp (modified) (7 diffs)
-
qwt_legend_data.h (modified) (5 diffs)
-
qwt_legend_label.cpp (modified) (27 diffs)
-
qwt_legend_label.h (modified) (4 diffs)
-
qwt_magnifier.cpp (modified) (26 diffs)
-
qwt_magnifier.h (modified) (6 diffs)
-
qwt_math.cpp (modified) (4 diffs)
-
qwt_math.h (modified) (5 diffs)
-
qwt_matrix_raster_data.cpp (modified) (20 diffs)
-
qwt_matrix_raster_data.h (modified) (4 diffs)
-
qwt_null_paintdevice.cpp (modified) (40 diffs)
-
qwt_null_paintdevice.h (modified) (3 diffs)
-
qwt_painter.cpp (modified) (59 diffs)
-
qwt_painter.h (modified) (8 diffs)
-
qwt_painter_command.cpp (modified) (9 diffs)
-
qwt_painter_command.h (modified) (7 diffs)
-
qwt_panner.cpp (modified) (30 diffs)
-
qwt_panner.h (modified) (5 diffs)
-
qwt_picker.cpp (modified) (64 diffs)
-
qwt_picker.h (modified) (10 diffs)
-
qwt_picker_machine.cpp (modified) (26 diffs)
-
qwt_picker_machine.h (modified) (4 diffs)
-
qwt_pixel_matrix.cpp (modified) (4 diffs)
-
qwt_pixel_matrix.h (modified) (5 diffs)
-
qwt_plot.cpp (modified) (40 diffs)
-
qwt_plot.h (modified) (10 diffs)
-
qwt_plot_abstract_barchart.cpp (modified) (14 diffs)
-
qwt_plot_abstract_barchart.h (modified) (4 diffs)
-
qwt_plot_abstract_canvas.cpp (added)
-
qwt_plot_abstract_canvas.h (added)
-
qwt_plot_axis.cpp (modified) (28 diffs)
-
qwt_plot_barchart.cpp (modified) (20 diffs)
-
qwt_plot_barchart.h (modified) (2 diffs)
-
qwt_plot_canvas.cpp (modified) (20 diffs)
-
qwt_plot_canvas.h (modified) (3 diffs)
-
qwt_plot_curve.cpp (modified) (56 diffs)
-
qwt_plot_curve.h (modified) (13 diffs)
-
qwt_plot_dict.cpp (modified) (9 diffs)
-
qwt_plot_dict.h (modified) (4 diffs)
-
qwt_plot_directpainter.cpp (modified) (17 diffs)
-
qwt_plot_directpainter.h (modified) (3 diffs)
-
qwt_plot_glcanvas.cpp (modified) (4 diffs)
-
qwt_plot_glcanvas.h (modified) (3 diffs)
-
qwt_plot_graphicitem.cpp (added)
-
qwt_plot_graphicitem.h (added)
-
qwt_plot_grid.cpp (modified) (12 diffs)
-
qwt_plot_grid.h (modified) (4 diffs)
-
qwt_plot_histogram.cpp (modified) (30 diffs)
-
qwt_plot_histogram.h (modified) (6 diffs)
-
qwt_plot_intervalcurve.cpp (modified) (14 diffs)
-
qwt_plot_intervalcurve.h (modified) (4 diffs)
-
qwt_plot_item.cpp (modified) (41 diffs)
-
qwt_plot_item.h (modified) (13 diffs)
-
qwt_plot_layout.cpp (modified) (11 diffs)
-
qwt_plot_layout.h (modified) (6 diffs)
-
qwt_plot_legenditem.cpp (modified) (24 diffs)
-
qwt_plot_legenditem.h (modified) (5 diffs)
-
qwt_plot_magnifier.cpp (modified) (12 diffs)
-
qwt_plot_magnifier.h (modified) (3 diffs)
-
qwt_plot_marker.cpp (modified) (36 diffs)
-
qwt_plot_marker.h (modified) (6 diffs)
-
qwt_plot_multi_barchart.cpp (modified) (24 diffs)
-
qwt_plot_multi_barchart.h (modified) (4 diffs)
-
qwt_plot_opengl_canvas.cpp (added)
-
qwt_plot_opengl_canvas.h (added)
-
qwt_plot_panner.cpp (modified) (20 diffs)
-
qwt_plot_panner.h (modified) (2 diffs)
-
qwt_plot_picker.cpp (modified) (18 diffs)
-
qwt_plot_picker.h (modified) (2 diffs)
-
qwt_plot_rasteritem.cpp (modified) (45 diffs)
-
qwt_plot_rasteritem.h (modified) (5 diffs)
-
qwt_plot_renderer.cpp (modified) (42 diffs)
-
qwt_plot_renderer.h (modified) (6 diffs)
-
qwt_plot_rescaler.cpp (modified) (25 diffs)
-
qwt_plot_rescaler.h (modified) (6 diffs)
-
qwt_plot_scaleitem.cpp (modified) (31 diffs)
-
qwt_plot_scaleitem.h (modified) (6 diffs)
-
qwt_plot_seriesitem.cpp (modified) (6 diffs)
-
qwt_plot_seriesitem.h (modified) (3 diffs)
-
qwt_plot_shapeitem.cpp (modified) (25 diffs)
-
qwt_plot_shapeitem.h (modified) (6 diffs)
-
qwt_plot_spectrocurve.cpp (modified) (20 diffs)
-
qwt_plot_spectrocurve.h (modified) (4 diffs)
-
qwt_plot_spectrogram.cpp (modified) (35 diffs)
-
qwt_plot_spectrogram.h (modified) (5 diffs)
-
qwt_plot_svgitem.cpp (modified) (5 diffs)
-
qwt_plot_svgitem.h (modified) (2 diffs)
-
qwt_plot_textlabel.cpp (modified) (11 diffs)
-
qwt_plot_textlabel.h (modified) (4 diffs)
-
qwt_plot_tradingcurve.cpp (modified) (32 diffs)
-
qwt_plot_tradingcurve.h (modified) (7 diffs)
-
qwt_plot_vectorfield.cpp (added)
-
qwt_plot_vectorfield.h (added)
-
qwt_plot_xml.cpp (deleted)
-
qwt_plot_zoneitem.cpp (modified) (15 diffs)
-
qwt_plot_zoneitem.h (modified) (2 diffs)
-
qwt_plot_zoomer.cpp (modified) (27 diffs)
-
qwt_plot_zoomer.h (modified) (2 diffs)
-
qwt_point_3d.cpp (modified) (2 diffs)
-
qwt_point_3d.h (modified) (13 diffs)
-
qwt_point_data.cpp (modified) (9 diffs)
-
qwt_point_data.h (modified) (5 diffs)
-
qwt_point_mapper.cpp (modified) (28 diffs)
-
qwt_point_mapper.h (modified) (4 diffs)
-
qwt_point_polar.cpp (modified) (9 diffs)
-
qwt_point_polar.h (modified) (12 diffs)
-
qwt_polar.h (added)
-
qwt_polar_canvas.cpp (added)
-
qwt_polar_canvas.h (added)
-
qwt_polar_curve.cpp (added)
-
qwt_polar_curve.h (added)
-
qwt_polar_fitter.cpp (added)
-
qwt_polar_fitter.h (added)
-
qwt_polar_grid.cpp (added)
-
qwt_polar_grid.h (added)
-
qwt_polar_item.cpp (added)
-
qwt_polar_item.h (added)
-
qwt_polar_itemdict.cpp (added)
-
qwt_polar_itemdict.h (added)
-
qwt_polar_layout.cpp (added)
-
qwt_polar_layout.h (added)
-
qwt_polar_magnifier.cpp (added)
-
qwt_polar_magnifier.h (added)
-
qwt_polar_marker.cpp (added)
-
qwt_polar_marker.h (added)
-
qwt_polar_panner.cpp (added)
-
qwt_polar_panner.h (added)
-
qwt_polar_picker.cpp (added)
-
qwt_polar_picker.h (added)
-
qwt_polar_plot.cpp (added)
-
qwt_polar_plot.h (added)
-
qwt_polar_renderer.cpp (added)
-
qwt_polar_renderer.h (added)
-
qwt_polar_spectrogram.cpp (added)
-
qwt_polar_spectrogram.h (added)
-
qwt_raster_data.cpp (modified) (17 diffs)
-
qwt_raster_data.h (modified) (5 diffs)
-
qwt_round_scale_draw.cpp (modified) (18 diffs)
-
qwt_round_scale_draw.h (modified) (3 diffs)
-
qwt_samples.h (modified) (12 diffs)
-
qwt_sampling_thread.cpp (modified) (8 diffs)
-
qwt_sampling_thread.h (modified) (4 diffs)
-
qwt_scale_div.cpp (modified) (13 diffs)
-
qwt_scale_div.h (modified) (6 diffs)
-
qwt_scale_draw.cpp (modified) (32 diffs)
-
qwt_scale_draw.h (modified) (5 diffs)
-
qwt_scale_engine.cpp (modified) (49 diffs)
-
qwt_scale_engine.h (modified) (6 diffs)
-
qwt_scale_map.cpp (modified) (10 diffs)
-
qwt_scale_map.h (modified) (6 diffs)
-
qwt_scale_widget.cpp (modified) (52 diffs)
-
qwt_scale_widget.h (modified) (8 diffs)
-
qwt_series_data.cpp (modified) (6 diffs)
-
qwt_series_data.h (modified) (10 diffs)
-
qwt_series_store.h (modified) (5 diffs)
-
qwt_slider.cpp (modified) (52 diffs)
-
qwt_slider.h (modified) (8 diffs)
-
qwt_spline.cpp (modified) (3 diffs)
-
qwt_spline.h (modified) (2 diffs)
-
qwt_spline_basis.cpp (added)
-
qwt_spline_basis.h (added)
-
qwt_spline_cubic.cpp (added)
-
qwt_spline_cubic.h (added)
-
qwt_spline_curve_fitter.cpp (added)
-
qwt_spline_curve_fitter.h (added)
-
qwt_spline_local.cpp (added)
-
qwt_spline_local.h (added)
-
qwt_spline_parametrization.cpp (added)
-
qwt_spline_parametrization.h (added)
-
qwt_spline_pleasing.cpp (added)
-
qwt_spline_pleasing.h (added)
-
qwt_spline_polynomial.cpp (added)
-
qwt_spline_polynomial.h (added)
-
qwt_symbol.cpp (modified) (66 diffs)
-
qwt_symbol.h (modified) (10 diffs)
-
qwt_system_clock.cpp (modified) (2 diffs)
-
qwt_system_clock.h (modified) (3 diffs)
-
qwt_text.cpp (modified) (36 diffs)
-
qwt_text.h (modified) (8 diffs)
-
qwt_text_engine.cpp (modified) (20 diffs)
-
qwt_text_engine.h (modified) (4 diffs)
-
qwt_text_label.cpp (modified) (22 diffs)
-
qwt_text_label.h (modified) (5 diffs)
-
qwt_thermo.cpp (modified) (56 diffs)
-
qwt_thermo.h (modified) (8 diffs)
-
qwt_transform.cpp (modified) (11 diffs)
-
qwt_transform.h (modified) (6 diffs)
-
qwt_vectorfield_symbol.cpp (added)
-
qwt_vectorfield_symbol.h (added)
-
qwt_weeding_curve_fitter.cpp (added)
-
qwt_weeding_curve_fitter.h (added)
-
qwt_wheel.cpp (modified) (54 diffs)
-
qwt_wheel.h (modified) (6 diffs)
-
qwt_widget_overlay.cpp (modified) (25 diffs)
-
qwt_widget_overlay.h (modified) (6 diffs)
-
src.pri (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 15 class QSize; 16 15 17 /*! 16 Some constants for use within Qwt. 17 */ 18 Some constants for use within Qwt. 19 */ 18 20 namespace Qwt 19 21 { 20 22 } 21 23 24 QWT_EXPORT QSize qwtExpandedToGlobalStrut( const QSize& ); 25 22 26 #endif -
trunk/BNC/qwt/qwt.pro
r8127 r11158 7 7 CONFIG -= debug 8 8 CONFIG += release 9 QWT_CONFIG = QwtPlot QwtWidgets QwtSvg 9 QWT_CONFIG = QwtPlot QwtPolar QwtWidgets QwtSvg 10 10 11 11 OBJECTS_DIR = .obj -
trunk/BNC/qwt/qwt_abstract_legend.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_abstract_legend.h" 11 #include "qwt_legend_data.h" 11 12 12 13 /*! 13 Constructor 14 Constructor 14 15 15 \param parent Parent widget 16 */ 17 QwtAbstractLegend::QwtAbstractLegend( QWidget *parent ):18 QFrame( parent ) 16 \param parent Parent widget 17 */ 18 QwtAbstractLegend::QwtAbstractLegend( QWidget* parent ) 19 : QFrame( parent ) 19 20 { 20 21 } … … 31 32 \param orientation Orientation 32 33 \return Extent of the corresponding scroll element 33 */ 34 */ 34 35 int QwtAbstractLegend::scrollExtent( Qt::Orientation orientation ) const 35 36 { … … 37 38 return 0; 38 39 } 40 41 #include "moc_qwt_abstract_legend.cpp" -
trunk/BNC/qwt/qwt_abstract_legend.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_legend_data.h"15 14 #include <qframe.h> 16 #include <qlist.h>17 15 16 class QwtLegendData; 17 template< typename T > class QList; 18 18 class QVariant; 19 19 20 20 /*! 21 \brief Abstract base class for legend widgets 21 \brief Abstract base class for legend widgets 22 22 23 Legends, that need to be under control of the QwtPlot layout system 24 need to be derived from QwtAbstractLegend. 23 Legends, that need to be under control of the QwtPlot layout system 24 need to be derived from QwtAbstractLegend. 25 25 26 \note Other type of legends can be implemented by connecting to 26 \note Other type of legends can be implemented by connecting to 27 27 the QwtPlot::legendDataChanged() signal. But as these legends 28 28 are unknown to the plot layout system the layout code … … 30 30 in application code. 31 31 32 \sa QwtLegend 32 \sa QwtLegend 33 33 */ 34 34 class QWT_EXPORT QwtAbstractLegend : public QFrame … … 36 36 Q_OBJECT 37 37 38 public: 39 explicit QwtAbstractLegend( QWidget *parent = NULL );38 public: 39 explicit QwtAbstractLegend( QWidget* parent = NULL ); 40 40 virtual ~QwtAbstractLegend(); 41 41 42 42 /*! 43 Render the legend into a given rectangle. 43 Render the legend into a given rectangle. 44 44 45 \param painter Painter 46 \param rect Bounding rectangle 47 \param fillBackground When true, fill rect with the widget background 45 \param painter Painter 46 \param rect Bounding rectangle 47 \param fillBackground When true, fill rect with the widget background 48 48 49 \sa renderLegend() is used by QwtPlotRenderer 50 */ 51 virtual void renderLegend( QPainter *painter,52 const QRectF &rect, bool fillBackground ) const = 0;49 \sa renderLegend() is used by QwtPlotRenderer 50 */ 51 virtual void renderLegend( QPainter* painter, 52 const QRectF& rect, bool fillBackground ) const = 0; 53 53 54 54 //! \return True, when no plot item is inserted … … 57 57 virtual int scrollExtent( Qt::Orientation ) const; 58 58 59 public Q_SLOTS: 59 public Q_SLOTS: 60 60 61 61 /*! 62 \brief Update the entries for a plot item 62 \brief Update the entries for a plot item 63 63 64 \param itemInfo Info about an item 65 \param data List of legend entry attributes for the item 64 \param itemInfo Info about an item 65 \param data List of legend entry attributes for the item 66 66 */ 67 virtual void updateLegend( const QVariant &itemInfo,68 const QList<QwtLegendData > &data ) = 0;67 virtual void updateLegend( const QVariant& itemInfo, 68 const QList< QwtLegendData >& data ) = 0; 69 69 }; 70 70 -
trunk/BNC/qwt/qwt_abstract_scale.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 #include "qwt_interval.h" 16 16 17 #include <qcoreevent.h> 18 17 19 class QwtAbstractScale::PrivateData 18 20 { 19 public: 21 public: 20 22 PrivateData(): 21 23 maxMajor( 5 ), … … 33 35 } 34 36 35 QwtScaleEngine *scaleEngine;36 QwtAbstractScaleDraw *scaleDraw;37 QwtScaleEngine* scaleEngine; 38 QwtAbstractScaleDraw* scaleDraw; 37 39 38 40 int maxMajor; … … 42 44 43 45 /*! 44 Constructor 45 46 \param parent Parent widget 47 48 Creates a default QwtScaleDraw and a QwtLinearScaleEngine. 49 The initial scale boundaries are set to [ 0.0, 100.0 ] 50 51 The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5 52 and scaleMaxMajor to 3. 53 */ 54 55 QwtAbstractScale::QwtAbstractScale( QWidget *parent ):56 QWidget( parent ) 57 { 58 d_data = new PrivateData;59 rescale( 0.0, 100.0, d_data->stepSize );46 Constructor 47 48 \param parent Parent widget 49 50 Creates a default QwtScaleDraw and a QwtLinearScaleEngine. 51 The initial scale boundaries are set to [ 0.0, 100.0 ] 52 53 The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5 54 and scaleMaxMajor to 3. 55 */ 56 57 QwtAbstractScale::QwtAbstractScale( QWidget* parent ) 58 : QWidget( parent ) 59 { 60 m_data = new PrivateData; 61 rescale( 0.0, 100.0, m_data->stepSize ); 60 62 } 61 63 … … 63 65 QwtAbstractScale::~QwtAbstractScale() 64 66 { 65 delete d_data;66 } 67 68 /*! 69 Set the lower bound of the scale 70 71 \param value Lower bound 72 73 \sa lowerBound(), setScale(), setUpperBound() 74 \note For inverted scales the lower bound 67 delete m_data; 68 } 69 70 /*! 71 Set the lower bound of the scale 72 73 \param value Lower bound 74 75 \sa lowerBound(), setScale(), setUpperBound() 76 \note For inverted scales the lower bound 75 77 is greater than the upper bound 76 */ 78 */ 77 79 void QwtAbstractScale::setLowerBound( double value ) 78 80 { … … 81 83 82 84 /*! 83 \return Lower bound of the scale 84 \sa setLowerBound(), setScale(), upperBound() 85 */ 85 \return Lower bound of the scale 86 \sa setLowerBound(), setScale(), upperBound() 87 */ 86 88 double QwtAbstractScale::lowerBound() const 87 89 { 88 return d_data->scaleDraw->scaleDiv().lowerBound();89 } 90 91 /*! 92 Set the upper bound of the scale 93 94 \param value Upper bound 95 96 \sa upperBound(), setScale(), setLowerBound() 97 \note For inverted scales the lower bound 90 return m_data->scaleDraw->scaleDiv().lowerBound(); 91 } 92 93 /*! 94 Set the upper bound of the scale 95 96 \param value Upper bound 97 98 \sa upperBound(), setScale(), setLowerBound() 99 \note For inverted scales the lower bound 98 100 is greater than the upper bound 99 */ 101 */ 100 102 void QwtAbstractScale::setUpperBound( double value ) 101 103 { … … 104 106 105 107 /*! 106 \return Upper bound of the scale 107 \sa setUpperBound(), setScale(), lowerBound() 108 */ 108 \return Upper bound of the scale 109 \sa setUpperBound(), setScale(), lowerBound() 110 */ 109 111 double QwtAbstractScale::upperBound() const 110 112 { 111 return d_data->scaleDraw->scaleDiv().upperBound();112 } 113 114 /*! 115 \brief Specify a scale. 116 117 Define a scale by an interval 118 119 The ticks are calculated using scaleMaxMinor(), 120 scaleMaxMajor() and scaleStepSize(). 121 122 \param lowerBound lower limit of the scale interval 123 \param upperBound upper limit of the scale interval 124 125 \note For inverted scales the lower bound 113 return m_data->scaleDraw->scaleDiv().upperBound(); 114 } 115 116 /*! 117 \brief Specify a scale. 118 119 Define a scale by an interval 120 121 The ticks are calculated using scaleMaxMinor(), 122 scaleMaxMajor() and scaleStepSize(). 123 124 \param lowerBound lower limit of the scale interval 125 \param upperBound upper limit of the scale interval 126 127 \note For inverted scales the lower bound 126 128 is greater than the upper bound 127 */ 129 */ 128 130 void QwtAbstractScale::setScale( double lowerBound, double upperBound ) 129 131 { 130 rescale( lowerBound, upperBound, d_data->stepSize );131 } 132 133 /*! 134 \brief Specify a scale. 135 136 Define a scale by an interval 137 138 The ticks are calculated using scaleMaxMinor(), 139 scaleMaxMajor() and scaleStepSize(). 140 141 \param interval Interval 142 */ 143 void QwtAbstractScale::setScale( const QwtInterval &interval )132 rescale( lowerBound, upperBound, m_data->stepSize ); 133 } 134 135 /*! 136 \brief Specify a scale. 137 138 Define a scale by an interval 139 140 The ticks are calculated using scaleMaxMinor(), 141 scaleMaxMajor() and scaleStepSize(). 142 143 \param interval Interval 144 */ 145 void QwtAbstractScale::setScale( const QwtInterval& interval ) 144 146 { 145 147 setScale( interval.minValue(), interval.maxValue() ); … … 147 149 148 150 /*! 149 \brief Specify a scale. 150 151 scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect. 152 153 \param scaleDiv Scale division 154 \sa setAutoScale() 155 */ 156 void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv )157 { 158 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )151 \brief Specify a scale. 152 153 scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect. 154 155 \param scaleDiv Scale division 156 \sa setAutoScale() 157 */ 158 void QwtAbstractScale::setScale( const QwtScaleDiv& scaleDiv ) 159 { 160 if ( scaleDiv != m_data->scaleDraw->scaleDiv() ) 159 161 { 160 162 #if 1 161 if ( d_data->scaleEngine )163 if ( m_data->scaleEngine ) 162 164 { 163 d_data->scaleDraw->setTransformation(164 d_data->scaleEngine->transformation() );165 m_data->scaleDraw->setTransformation( 166 m_data->scaleEngine->transformation() ); 165 167 } 166 168 #endif 167 169 168 d_data->scaleDraw->setScaleDiv( scaleDiv );170 m_data->scaleDraw->setScaleDiv( scaleDiv ); 169 171 170 172 scaleChange(); … … 173 175 174 176 /*! 175 \brief Set the maximum number of major tick intervals. 176 177 The scale's major ticks are calculated automatically such that 178 the number of major intervals does not exceed ticks. 179 180 The default value is 5. 181 182 \param ticks Maximal number of major ticks. 183 184 \sa scaleMaxMajor(), setScaleMaxMinor(), 177 \brief Set the maximum number of major tick intervals. 178 179 The scale's major ticks are calculated automatically such that 180 the number of major intervals does not exceed ticks. 181 182 The default value is 5. 183 184 \param ticks Maximal number of major ticks. 185 186 \sa scaleMaxMajor(), setScaleMaxMinor(), 185 187 setScaleStepSize(), QwtScaleEngine::divideInterval() 186 */ 188 */ 187 189 void QwtAbstractScale::setScaleMaxMajor( int ticks ) 188 190 { 189 if ( ticks != d_data->maxMajor )190 { 191 d_data->maxMajor = ticks;191 if ( ticks != m_data->maxMajor ) 192 { 193 m_data->maxMajor = ticks; 192 194 updateScaleDraw(); 193 195 } … … 195 197 196 198 /*! 197 \return Maximal number of major tick intervals 198 \sa setScaleMaxMajor(), scaleMaxMinor() 199 */ 199 \return Maximal number of major tick intervals 200 \sa setScaleMaxMajor(), scaleMaxMinor() 201 */ 200 202 int QwtAbstractScale::scaleMaxMajor() const 201 203 { 202 return d_data->maxMajor;203 } 204 205 /*! 206 \brief Set the maximum number of minor tick intervals 207 208 The scale's minor ticks are calculated automatically such that 209 the number of minor intervals does not exceed ticks. 210 The default value is 3. 211 212 \param ticks Maximal number of minor ticks. 213 214 \sa scaleMaxMajor(), setScaleMaxMinor(), 204 return m_data->maxMajor; 205 } 206 207 /*! 208 \brief Set the maximum number of minor tick intervals 209 210 The scale's minor ticks are calculated automatically such that 211 the number of minor intervals does not exceed ticks. 212 The default value is 3. 213 214 \param ticks Maximal number of minor ticks. 215 216 \sa scaleMaxMajor(), setScaleMaxMinor(), 215 217 setScaleStepSize(), QwtScaleEngine::divideInterval() 216 */ 218 */ 217 219 void QwtAbstractScale::setScaleMaxMinor( int ticks ) 218 220 { 219 if ( ticks != d_data->maxMinor )220 { 221 d_data->maxMinor = ticks;221 if ( ticks != m_data->maxMinor ) 222 { 223 m_data->maxMinor = ticks; 222 224 updateScaleDraw(); 223 225 } … … 225 227 226 228 /*! 227 \return Maximal number of minor tick intervals 228 \sa setScaleMaxMinor(), scaleMaxMajor() 229 */ 229 \return Maximal number of minor tick intervals 230 \sa setScaleMaxMinor(), scaleMaxMajor() 231 */ 230 232 int QwtAbstractScale::scaleMaxMinor() const 231 233 { 232 return d_data->maxMinor;234 return m_data->maxMinor; 233 235 } 234 236 … … 246 248 \note Position and distance between the major ticks also 247 249 depends on scaleMaxMajor(). 248 */ 250 */ 249 251 void QwtAbstractScale::setScaleStepSize( double stepSize ) 250 252 { 251 if ( stepSize != d_data->stepSize )252 { 253 d_data->stepSize = stepSize;253 if ( stepSize != m_data->stepSize ) 254 { 255 m_data->stepSize = stepSize; 254 256 updateScaleDraw(); 255 257 } … … 257 259 258 260 /*! 259 \return Hint for the step size of the scale 260 \sa setScaleStepSize(), QwtScaleEngine::divideScale() 261 */ 261 \return Hint for the step size of the scale 262 \sa setScaleStepSize(), QwtScaleEngine::divideScale() 263 */ 262 264 double QwtAbstractScale::scaleStepSize() const 263 265 { 264 return d_data->stepSize;265 } 266 267 /*! 268 \brief Set a scale draw 269 270 scaleDraw has to be created with new and will be deleted in 271 the destructor or the next call of setAbstractScaleDraw(). 272 273 \sa abstractScaleDraw() 274 */ 275 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw *scaleDraw )276 { 277 if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )266 return m_data->stepSize; 267 } 268 269 /*! 270 \brief Set a scale draw 271 272 scaleDraw has to be created with new and will be deleted in 273 the destructor or the next call of setAbstractScaleDraw(). 274 275 \sa abstractScaleDraw() 276 */ 277 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw* scaleDraw ) 278 { 279 if ( scaleDraw == NULL || scaleDraw == m_data->scaleDraw ) 278 280 return; 279 281 280 if ( d_data->scaleDraw != NULL )281 scaleDraw->setScaleDiv( d_data->scaleDraw->scaleDiv() );282 283 delete d_data->scaleDraw;284 d_data->scaleDraw = scaleDraw;282 if ( m_data->scaleDraw != NULL ) 283 scaleDraw->setScaleDiv( m_data->scaleDraw->scaleDiv() ); 284 285 delete m_data->scaleDraw; 286 m_data->scaleDraw = scaleDraw; 285 287 } 286 288 … … 288 290 \return Scale draw 289 291 \sa setAbstractScaleDraw() 290 */ 291 QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()292 { 293 return d_data->scaleDraw;292 */ 293 QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() 294 { 295 return m_data->scaleDraw; 294 296 } 295 297 … … 297 299 \return Scale draw 298 300 \sa setAbstractScaleDraw() 299 */ 300 const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const301 { 302 return d_data->scaleDraw;303 } 304 305 /*! 306 \brief Set a scale engine 307 308 The scale engine is responsible for calculating the scale division 309 and provides a transformation between scale and widget coordinates. 310 311 scaleEngine has to be created with new and will be deleted in 312 the destructor or the next call of setScaleEngine. 313 */ 314 void QwtAbstractScale::setScaleEngine( QwtScaleEngine *scaleEngine )315 { 316 if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )317 { 318 delete d_data->scaleEngine;319 d_data->scaleEngine = scaleEngine;320 } 321 } 322 323 /*! 324 \return Scale engine 325 \sa setScaleEngine() 326 */ 327 const QwtScaleEngine *QwtAbstractScale::scaleEngine() const328 { 329 return d_data->scaleEngine;330 } 331 332 /*! 333 \return Scale engine 334 \sa setScaleEngine() 335 */ 336 QwtScaleEngine *QwtAbstractScale::scaleEngine()337 { 338 return d_data->scaleEngine;339 } 340 341 /*! 342 \return Scale boundaries and positions of the ticks 343 344 The scale division might have been assigned explicitly 345 or calculated implicitly by rescale(). 346 */ 347 const QwtScaleDiv &QwtAbstractScale::scaleDiv() const348 { 349 return d_data->scaleDraw->scaleDiv();350 } 351 352 /*! 353 \return Map to translate between scale and widget coordinates 354 */ 355 const QwtScaleMap &QwtAbstractScale::scaleMap() const356 { 357 return d_data->scaleDraw->scaleMap();358 } 359 360 /*! 361 Translate a scale value into a widget coordinate 362 363 \param value Scale value 364 \return Corresponding widget coordinate for value 365 \sa scaleMap(), invTransform() 301 */ 302 const QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() const 303 { 304 return m_data->scaleDraw; 305 } 306 307 /*! 308 \brief Set a scale engine 309 310 The scale engine is responsible for calculating the scale division 311 and provides a transformation between scale and widget coordinates. 312 313 scaleEngine has to be created with new and will be deleted in 314 the destructor or the next call of setScaleEngine. 315 */ 316 void QwtAbstractScale::setScaleEngine( QwtScaleEngine* scaleEngine ) 317 { 318 if ( scaleEngine != NULL && scaleEngine != m_data->scaleEngine ) 319 { 320 delete m_data->scaleEngine; 321 m_data->scaleEngine = scaleEngine; 322 } 323 } 324 325 /*! 326 \return Scale engine 327 \sa setScaleEngine() 328 */ 329 const QwtScaleEngine* QwtAbstractScale::scaleEngine() const 330 { 331 return m_data->scaleEngine; 332 } 333 334 /*! 335 \return Scale engine 336 \sa setScaleEngine() 337 */ 338 QwtScaleEngine* QwtAbstractScale::scaleEngine() 339 { 340 return m_data->scaleEngine; 341 } 342 343 /*! 344 \return Scale boundaries and positions of the ticks 345 346 The scale division might have been assigned explicitly 347 or calculated implicitly by rescale(). 348 */ 349 const QwtScaleDiv& QwtAbstractScale::scaleDiv() const 350 { 351 return m_data->scaleDraw->scaleDiv(); 352 } 353 354 /*! 355 \return Map to translate between scale and widget coordinates 356 */ 357 const QwtScaleMap& QwtAbstractScale::scaleMap() const 358 { 359 return m_data->scaleDraw->scaleMap(); 360 } 361 362 /*! 363 Translate a scale value into a widget coordinate 364 365 \param value Scale value 366 \return Corresponding widget coordinate for value 367 \sa scaleMap(), invTransform() 366 368 */ 367 369 int QwtAbstractScale::transform( double value ) const 368 370 { 369 return qRound( d_data->scaleDraw->scaleMap().transform( value ) );370 } 371 372 /*! 373 Translate a widget coordinate into a scale value 374 375 \param value Widget coordinate 376 \return Corresponding scale coordinate for value 377 \sa scaleMap(), transform() 371 return qRound( m_data->scaleDraw->scaleMap().transform( value ) ); 372 } 373 374 /*! 375 Translate a widget coordinate into a scale value 376 377 \param value Widget coordinate 378 \return Corresponding scale coordinate for value 379 \sa scaleMap(), transform() 378 380 */ 379 381 double QwtAbstractScale::invTransform( int value ) const 380 382 { 381 return d_data->scaleDraw->scaleMap().invTransform( value );382 } 383 384 /*! 385 \return True, when the scale is increasing in opposite direction 383 return m_data->scaleDraw->scaleMap().invTransform( value ); 384 } 385 386 /*! 387 \return True, when the scale is increasing in opposite direction 386 388 to the widget coordinates 387 389 */ 388 390 bool QwtAbstractScale::isInverted() const 389 391 { 390 return d_data->scaleDraw->scaleMap().isInverting();391 } 392 393 /*! 394 \return The boundary with the smaller value 395 \sa maximum(), lowerBound(), upperBound() 392 return m_data->scaleDraw->scaleMap().isInverting(); 393 } 394 395 /*! 396 \return The boundary with the smaller value 397 \sa maximum(), lowerBound(), upperBound() 396 398 */ 397 399 double QwtAbstractScale::minimum() const 398 400 { 399 return qMin( d_data->scaleDraw->scaleDiv().lowerBound(),400 d_data->scaleDraw->scaleDiv().upperBound() );401 } 402 403 /*! 404 \return The boundary with the larger value 405 \sa minimum(), lowerBound(), upperBound() 401 return qMin( m_data->scaleDraw->scaleDiv().lowerBound(), 402 m_data->scaleDraw->scaleDiv().upperBound() ); 403 } 404 405 /*! 406 \return The boundary with the larger value 407 \sa minimum(), lowerBound(), upperBound() 406 408 */ 407 409 double QwtAbstractScale::maximum() const 408 410 { 409 return qMax( d_data->scaleDraw->scaleDiv().lowerBound(),410 d_data->scaleDraw->scaleDiv().upperBound() );411 return qMax( m_data->scaleDraw->scaleDiv().lowerBound(), 412 m_data->scaleDraw->scaleDiv().upperBound() ); 411 413 } 412 414 … … 417 419 418 420 /*! 419 Recalculate the scale division and update the scale. 420 421 \param lowerBound Lower limit of the scale interval 422 \param upperBound Upper limit of the scale interval 423 \param stepSize Major step size 424 425 \sa scaleChange() 426 */ 421 Recalculate the scale division and update the scale. 422 423 \param lowerBound Lower limit of the scale interval 424 \param upperBound Upper limit of the scale interval 425 \param stepSize Major step size 426 427 \sa scaleChange() 428 */ 427 429 void QwtAbstractScale::rescale( 428 430 double lowerBound, double upperBound, double stepSize ) 429 431 { 430 const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(431 lowerBound, upperBound, d_data->maxMajor,d_data->maxMinor, stepSize );432 433 if ( scaleDiv != d_data->scaleDraw->scaleDiv() )432 const QwtScaleDiv scaleDiv = m_data->scaleEngine->divideScale( 433 lowerBound, upperBound, m_data->maxMajor, m_data->maxMinor, stepSize ); 434 435 if ( scaleDiv != m_data->scaleDraw->scaleDiv() ) 434 436 { 435 437 #if 1 436 d_data->scaleDraw->setTransformation(437 d_data->scaleEngine->transformation() );438 m_data->scaleDraw->setTransformation( 439 m_data->scaleEngine->transformation() ); 438 440 #endif 439 441 440 d_data->scaleDraw->setScaleDiv( scaleDiv );442 m_data->scaleDraw->setScaleDiv( scaleDiv ); 441 443 scaleChange(); 442 444 } 443 445 } 444 446 447 /*! 448 Change Event handler 449 \param event Change event 450 451 Invalidates internal caches if necessary 452 */ 453 void QwtAbstractScale::changeEvent( QEvent* event ) 454 { 455 if ( event->type() == QEvent::LocaleChange ) 456 { 457 m_data->scaleDraw->invalidateCache(); 458 } 459 460 QWidget::changeEvent( event ); 461 } 462 463 /*! 464 Recalculate ticks and scale boundaries. 465 */ 445 466 void QwtAbstractScale::updateScaleDraw() 446 467 { 447 rescale( d_data->scaleDraw->scaleDiv().lowerBound(), 448 d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize ); 449 } 468 rescale( m_data->scaleDraw->scaleDiv().lowerBound(), 469 m_data->scaleDraw->scaleDiv().upperBound(), m_data->stepSize ); 470 } 471 472 #include "moc_qwt_abstract_scale.cpp" -
trunk/BNC/qwt/qwt_abstract_scale.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 21 21 22 22 /*! 23 \brief An abstract base class for widgets having a scale 23 \brief An abstract base class for widgets having a scale 24 24 25 The scale of an QwtAbstractScale is determined by a QwtScaleDiv 26 definition, that contains the boundaries and the ticks of the scale. 27 The scale is painted using a QwtScaleDraw object. 25 The scale of an QwtAbstractScale is determined by a QwtScaleDiv 26 definition, that contains the boundaries and the ticks of the scale. 27 The scale is painted using a QwtScaleDraw object. 28 28 29 The scale division might be assigned explicitly - but usually 30 it is calculated from the boundaries using a QwtScaleEngine. 29 The scale division might be assigned explicitly - but usually 30 it is calculated from the boundaries using a QwtScaleEngine. 31 31 32 The scale engine also decides the type of transformation of the scale 33 ( linear, logarithmic ... ). 34 */ 32 The scale engine also decides the type of transformation of the scale 33 ( linear, logarithmic ... ). 34 */ 35 35 36 class QWT_EXPORT QwtAbstractScale: public QWidget 36 class QWT_EXPORT QwtAbstractScale : public QWidget 37 37 { 38 38 Q_OBJECT … … 46 46 Q_PROPERTY( double scaleStepSize READ scaleStepSize WRITE setScaleStepSize ) 47 47 48 public: 49 QwtAbstractScale( QWidget *parent = NULL );48 public: 49 explicit QwtAbstractScale( QWidget* parent = NULL ); 50 50 virtual ~QwtAbstractScale(); 51 51 52 52 void setScale( double lowerBound, double upperBound ); 53 void setScale( const QwtInterval & );54 void setScale( const QwtScaleDiv & );53 void setScale( const QwtInterval& ); 54 void setScale( const QwtScaleDiv& ); 55 55 56 56 const QwtScaleDiv& scaleDiv() const; … … 71 71 int scaleMaxMajor() const; 72 72 73 void setScaleEngine( QwtScaleEngine * );74 const QwtScaleEngine *scaleEngine() const;75 QwtScaleEngine *scaleEngine();73 void setScaleEngine( QwtScaleEngine* ); 74 const QwtScaleEngine* scaleEngine() const; 75 QwtScaleEngine* scaleEngine(); 76 76 77 77 int transform( double ) const; … … 83 83 double maximum() const; 84 84 85 const QwtScaleMap &scaleMap() const;85 const QwtScaleMap& scaleMap() const; 86 86 87 protected: 87 protected: 88 virtual void changeEvent( QEvent* ) QWT_OVERRIDE; 89 88 90 void rescale( double lowerBound, 89 91 double upperBound, double stepSize ); 90 92 91 void setAbstractScaleDraw( QwtAbstractScaleDraw * );93 void setAbstractScaleDraw( QwtAbstractScaleDraw* ); 92 94 93 const QwtAbstractScaleDraw *abstractScaleDraw() const;94 QwtAbstractScaleDraw *abstractScaleDraw();95 const QwtAbstractScaleDraw* abstractScaleDraw() const; 96 QwtAbstractScaleDraw* abstractScaleDraw(); 95 97 98 void updateScaleDraw(); 96 99 virtual void scaleChange(); 97 100 98 private: 99 void updateScaleDraw(); 100 101 private: 101 102 class PrivateData; 102 PrivateData *d_data;103 PrivateData* m_data; 103 104 }; 104 105 -
trunk/BNC/qwt/qwt_abstract_scale_draw.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_abstract_scale_draw.h" 11 #include "qwt_math.h"12 11 #include "qwt_text.h" 13 12 #include "qwt_painter.h" 14 13 #include "qwt_scale_map.h" 14 #include "qwt_math.h" 15 15 16 #include <qpainter.h> 16 17 #include <qpalette.h> 17 18 #include <qmap.h> 19 #include <qlist.h> 18 20 #include <qlocale.h> 19 21 20 22 class QwtAbstractScaleDraw::PrivateData 21 23 { 22 public: 24 public: 23 25 PrivateData(): 24 26 spacing( 4.0 ), 25 penWidth (0 ),27 penWidthF( 0.0 ), 26 28 minExtent( 0.0 ) 27 29 { … … 42 44 double spacing; 43 45 double tickLength[QwtScaleDiv::NTickTypes]; 44 intpenWidth;46 qreal penWidthF; 45 47 46 48 double minExtent; 47 49 48 QMap<double, QwtText> labelCache; 50 QMap< double, QwtText > labelCache; 49 51 }; 50 52 51 53 /*! 52 \brief Constructor 53 54 The range of the scale is initialized to [0, 100], 55 The spacing (distance between ticks and labels) is 56 set to 4, the tick lengths are set to 4,6 and 8 pixels 57 */ 54 \brief Constructor 55 56 The range of the scale is initialized to [0, 100], 57 The spacing (distance between ticks and labels) is 58 set to 4, the tick lengths are set to 4,6 and 8 pixels 59 */ 58 60 QwtAbstractScaleDraw::QwtAbstractScaleDraw() 59 61 { 60 d_data = new QwtAbstractScaleDraw::PrivateData;62 m_data = new QwtAbstractScaleDraw::PrivateData; 61 63 } 62 64 … … 64 66 QwtAbstractScaleDraw::~QwtAbstractScaleDraw() 65 67 { 66 delete d_data;67 } 68 69 /*! 70 En/Disable a component of the scale 71 72 \param component Scale component 73 \param enable On/Off 74 75 \sa hasComponent() 76 */ 68 delete m_data; 69 } 70 71 /*! 72 En/Disable a component of the scale 73 74 \param component Scale component 75 \param enable On/Off 76 77 \sa hasComponent() 78 */ 77 79 void QwtAbstractScaleDraw::enableComponent( 78 80 ScaleComponent component, bool enable ) 79 81 { 80 82 if ( enable ) 81 d_data->components |= component;83 m_data->components |= component; 82 84 else 83 d_data->components &= ~component;84 } 85 86 /*! 87 Check if a component is enabled 88 89 \param component Component type 90 \return true, when component is enabled 91 \sa enableComponent() 92 */ 85 m_data->components &= ~component; 86 } 87 88 /*! 89 Check if a component is enabled 90 91 \param component Component type 92 \return true, when component is enabled 93 \sa enableComponent() 94 */ 93 95 bool QwtAbstractScaleDraw::hasComponent( ScaleComponent component ) const 94 96 { 95 return ( d_data->components & component ); 96 } 97 98 /*! 99 Change the scale division 100 \param scaleDiv New scale division 101 */ 102 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &scaleDiv ) 103 { 104 d_data->scaleDiv = scaleDiv; 105 d_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() ); 106 d_data->labelCache.clear(); 107 } 108 109 /*! 110 Change the transformation of the scale 111 \param transformation New scale transformation 112 */ 113 void QwtAbstractScaleDraw::setTransformation( 114 QwtTransform *transformation ) 115 { 116 d_data->map.setTransformation( transformation ); 97 return ( m_data->components & component ); 98 } 99 100 /*! 101 Change the scale division 102 \param scaleDiv New scale division 103 */ 104 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv& scaleDiv ) 105 { 106 m_data->scaleDiv = scaleDiv; 107 m_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() ); 108 m_data->labelCache.clear(); 109 } 110 111 /*! 112 Change the transformation of the scale 113 \param transformation New scale transformation 114 */ 115 void QwtAbstractScaleDraw::setTransformation( QwtTransform* transformation ) 116 { 117 m_data->map.setTransformation( transformation ); 117 118 } 118 119 119 120 //! \return Map how to translate between scale and pixel values 120 const QwtScaleMap &QwtAbstractScaleDraw::scaleMap() const121 { 122 return d_data->map;121 const QwtScaleMap& QwtAbstractScaleDraw::scaleMap() const 122 { 123 return m_data->map; 123 124 } 124 125 125 126 //! \return Map how to translate between scale and pixel values 126 QwtScaleMap &QwtAbstractScaleDraw::scaleMap()127 { 128 return d_data->map;127 QwtScaleMap& QwtAbstractScaleDraw::scaleMap() 128 { 129 return m_data->map; 129 130 } 130 131 … … 132 133 const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const 133 134 { 134 return d_data->scaleDiv;135 } 136 137 /*! 138 \brief Specify the width of the scale pen 139 \param width Pen width 140 \sa penWidth() 141 */ 142 void QwtAbstractScaleDraw::setPenWidth( int width ) 143 { 144 if ( width < 0 ) 145 width= 0;146 147 if ( width != d_data->penWidth ) 148 d_data->penWidth = width;135 return m_data->scaleDiv; 136 } 137 138 /*! 139 \brief Specify the width of the scale pen 140 \param width Pen width 141 142 \sa penWidth() 143 */ 144 void QwtAbstractScaleDraw::setPenWidthF( qreal width ) 145 { 146 if ( width < 0.0 ) 147 width = 0.0; 148 149 m_data->penWidthF = width; 149 150 } 150 151 … … 152 153 \return Scale pen width 153 154 \sa setPenWidth() 154 */ 155 intQwtAbstractScaleDraw::penWidth() const156 { 157 return d_data->penWidth;158 } 159 160 /*! 161 \brief Draw the scale 162 163 \param painter The painter 164 165 \param palette Palette, text color is used for the labels, 155 */ 156 qreal QwtAbstractScaleDraw::penWidthF() const 157 { 158 return m_data->penWidthF; 159 } 160 161 /*! 162 \brief Draw the scale 163 164 \param painter The painter 165 166 \param palette Palette, text color is used for the labels, 166 167 foreground color for ticks and backbone 167 */ 168 void QwtAbstractScaleDraw::draw( QPainter *painter,168 */ 169 void QwtAbstractScaleDraw::draw( QPainter* painter, 169 170 const QPalette& palette ) const 170 171 { … … 172 173 173 174 QPen pen = painter->pen(); 174 pen.setWidth ( d_data->penWidth );175 pen.setCosmetic( false ); 175 pen.setWidthF( m_data->penWidthF ); 176 176 177 painter->setPen( pen ); 177 178 … … 181 182 painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style 182 183 183 const QList< double> &majorTicks =184 d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick );184 const QList< double >& majorTicks = 185 m_data->scaleDiv.ticks( QwtScaleDiv::MajorTick ); 185 186 186 187 for ( int i = 0; i < majorTicks.count(); i++ ) 187 188 { 188 189 const double v = majorTicks[i]; 189 if ( d_data->scaleDiv.contains( v ) )190 if ( m_data->scaleDiv.contains( v ) ) 190 191 drawLabel( painter, v ); 191 192 } … … 207 208 tickType < QwtScaleDiv::NTickTypes; tickType++ ) 208 209 { 209 const double tickLen = d_data->tickLength[tickType];210 const double tickLen = m_data->tickLength[tickType]; 210 211 if ( tickLen <= 0.0 ) 211 212 continue; 212 213 213 const QList< double> &ticks =d_data->scaleDiv.ticks( tickType );214 const QList< double >& ticks = m_data->scaleDiv.ticks( tickType ); 214 215 for ( int i = 0; i < ticks.count(); i++ ) 215 216 { 216 217 const double v = ticks[i]; 217 if ( d_data->scaleDiv.contains( v ) )218 if ( m_data->scaleDiv.contains( v ) ) 218 219 drawTick( painter, v, tickLen ); 219 220 } … … 242 243 243 244 /*! 244 \brief Set the spacing between tick and labels 245 246 The spacing is the distance between ticks and labels. 247 The default spacing is 4 pixels. 248 249 \param spacing Spacing 250 251 \sa spacing() 252 */ 245 \brief Set the spacing between tick and labels 246 247 The spacing is the distance between ticks and labels. 248 The default spacing is 4 pixels. 249 250 \param spacing Spacing 251 252 \sa spacing() 253 */ 253 254 void QwtAbstractScaleDraw::setSpacing( double spacing ) 254 255 { … … 256 257 spacing = 0; 257 258 258 d_data->spacing = spacing;259 } 260 261 /*! 262 \brief Get the spacing 263 264 The spacing is the distance between ticks and labels. 265 The default spacing is 4 pixels. 266 267 \return Spacing 268 \sa setSpacing() 269 */ 259 m_data->spacing = spacing; 260 } 261 262 /*! 263 \brief Get the spacing 264 265 The spacing is the distance between ticks and labels. 266 The default spacing is 4 pixels. 267 268 \return Spacing 269 \sa setSpacing() 270 */ 270 271 double QwtAbstractScaleDraw::spacing() const 271 272 { 272 return d_data->spacing;273 } 274 275 /*! 276 \brief Set a minimum for the extent 277 278 The extent is calculated from the components of the 279 scale draw. In situations, where the labels are 280 changing and the layout depends on the extent (f.e scrolling 281 a scale), setting an upper limit as minimum extent will 282 avoid jumps of the layout. 283 284 \param minExtent Minimum extent 285 286 \sa extent(), minimumExtent() 287 */ 273 return m_data->spacing; 274 } 275 276 /*! 277 \brief Set a minimum for the extent 278 279 The extent is calculated from the components of the 280 scale draw. In situations, where the labels are 281 changing and the layout depends on the extent (f.e scrolling 282 a scale), setting an upper limit as minimum extent will 283 avoid jumps of the layout. 284 285 \param minExtent Minimum extent 286 287 \sa extent(), minimumExtent() 288 */ 288 289 void QwtAbstractScaleDraw::setMinimumExtent( double minExtent ) 289 290 { … … 291 292 minExtent = 0.0; 292 293 293 d_data->minExtent = minExtent;294 } 295 296 /*! 297 Get the minimum extent 298 \return Minimum extent 299 \sa extent(), setMinimumExtent() 300 */ 294 m_data->minExtent = minExtent; 295 } 296 297 /*! 298 Get the minimum extent 299 \return Minimum extent 300 \sa extent(), setMinimumExtent() 301 */ 301 302 double QwtAbstractScaleDraw::minimumExtent() const 302 303 { 303 return d_data->minExtent;304 } 305 306 /*! 307 Set the length of the ticks 308 309 \param tickType Tick type 310 \param length New length 311 312 \warning the length is limited to [0..1000] 313 */ 304 return m_data->minExtent; 305 } 306 307 /*! 308 Set the length of the ticks 309 310 \param tickType Tick type 311 \param length New length 312 313 \warning the length is limited to [0..1000] 314 */ 314 315 void QwtAbstractScaleDraw::setTickLength( 315 316 QwtScaleDiv::TickType tickType, double length ) … … 328 329 length = maxTickLen; 329 330 330 d_data->tickLength[tickType] = length;331 m_data->tickLength[tickType] = length; 331 332 } 332 333 … … 334 335 \return Length of the ticks 335 336 \sa setTickLength(), maxTickLength() 336 */ 337 */ 337 338 double QwtAbstractScaleDraw::tickLength( QwtScaleDiv::TickType tickType ) const 338 339 { … … 343 344 } 344 345 345 return d_data->tickLength[tickType];346 return m_data->tickLength[tickType]; 346 347 } 347 348 … … 351 352 Useful for layout calculations 352 353 \sa tickLength(), setTickLength() 353 */ 354 */ 354 355 double QwtAbstractScaleDraw::maxTickLength() const 355 356 { 356 357 double length = 0.0; 357 358 for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ ) 358 length = q Max( length,d_data->tickLength[i] );359 length = qwtMaxF( length, m_data->tickLength[i] ); 359 360 360 361 return length; … … 362 363 363 364 /*! 364 \brief Convert a value into its representing label 365 366 The value is converted to a plain text using 367 QLocale().toString(value). 368 This method is often overloaded by applications to have individual 369 labels. 370 371 \param value Value 372 \return Label string. 373 */ 365 \brief Convert a value into its representing label 366 367 The value is converted to a plain text using 368 QLocale().toString(value). 369 This method is often overloaded by applications to have individual 370 labels. 371 372 \param value Value 373 \return Label string. 374 */ 374 375 QwtText QwtAbstractScaleDraw::label( double value ) const 375 376 { … … 389 390 390 391 \return Tick label 391 */ 392 const QwtText &QwtAbstractScaleDraw::tickLabel(393 const QFont &font, double value ) const394 { 395 QMap<double, QwtText>::const_iterator it1 = d_data->labelCache.constFind( value );396 if ( it1 != d_data->labelCache.constEnd() )392 */ 393 const QwtText& QwtAbstractScaleDraw::tickLabel( 394 const QFont& font, double value ) const 395 { 396 QMap< double, QwtText >::const_iterator it1 = m_data->labelCache.constFind( value ); 397 if ( it1 != m_data->labelCache.constEnd() ) 397 398 return *it1; 398 399 … … 403 404 ( void )lbl.textSize( font ); // initialize the internal cache 404 405 405 QMap<double, QwtText>::iterator it2 = d_data->labelCache.insert( value, lbl );406 QMap< double, QwtText >::iterator it2 = m_data->labelCache.insert( value, lbl ); 406 407 return *it2; 407 408 } … … 413 414 the labels need to be changed. while the same QwtScaleDiv is set, 414 415 invalidateCache() needs to be called manually. 415 */ 416 */ 416 417 void QwtAbstractScaleDraw::invalidateCache() 417 418 { 418 d_data->labelCache.clear();419 } 419 m_data->labelCache.clear(); 420 } -
trunk/BNC/qwt/qwt_abstract_scale_draw.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_scale_div.h" 15 #include "qwt_text.h"16 15 16 class QwtText; 17 17 class QPalette; 18 18 class QPainter; … … 22 22 23 23 /*! 24 \brief A abstract base class for drawing scales 24 \brief A abstract base class for drawing scales 25 25 26 QwtAbstractScaleDraw can be used to draw linear or logarithmic scales. 26 QwtAbstractScaleDraw can be used to draw linear or logarithmic scales. 27 27 28 After a scale division has been specified as a QwtScaleDiv object 29 using setScaleDiv(), the scale can be drawn with the draw() member. 30 */ 28 After a scale division has been specified as a QwtScaleDiv object 29 using setScaleDiv(), the scale can be drawn with the draw() member. 30 */ 31 31 class QWT_EXPORT QwtAbstractScaleDraw 32 32 { 33 public: 33 public: 34 34 35 35 /*! 36 36 Components of a scale 37 37 \sa enableComponent(), hasComponent 38 */ 38 */ 39 39 enum ScaleComponent 40 40 { … … 49 49 }; 50 50 51 //! Scale components 52 typedef QFlags<ScaleComponent> ScaleComponents; 51 Q_DECLARE_FLAGS( ScaleComponents, ScaleComponent ) 53 52 54 53 QwtAbstractScaleDraw(); 55 54 virtual ~QwtAbstractScaleDraw(); 56 55 57 void setScaleDiv( const QwtScaleDiv & );56 void setScaleDiv( const QwtScaleDiv& ); 58 57 const QwtScaleDiv& scaleDiv() const; 59 58 60 void setTransformation( QwtTransform * );61 const QwtScaleMap &scaleMap() const;62 QwtScaleMap &scaleMap();59 void setTransformation( QwtTransform* ); 60 const QwtScaleMap& scaleMap() const; 61 QwtScaleMap& scaleMap(); 63 62 64 63 void enableComponent( ScaleComponent, bool enable = true ); … … 72 71 double spacing() const; 73 72 74 void setPenWidth ( intwidth );75 intpenWidth() const;73 void setPenWidthF( qreal width ); 74 qreal penWidthF() const; 76 75 77 virtual void draw( QPainter *, const QPalette& ) const;76 virtual void draw( QPainter*, const QPalette& ) const; 78 77 79 78 virtual QwtText label( double ) const; 80 79 81 80 /*! 82 Calculate the extent 81 Calculate the extent 83 82 84 The extent is the distance from the baseline to the outermost 85 pixel of the scale draw in opposite to its orientation. 86 It is at least minimumExtent() pixels. 83 The extent is the distance from the baseline to the outermost 84 pixel of the scale draw in opposite to its orientation. 85 It is at least minimumExtent() pixels. 87 86 88 \param font Font used for drawing the tick labels 89 \return Number of pixels 87 \param font Font used for drawing the tick labels 88 \return Number of pixels 90 89 91 \sa setMinimumExtent(), minimumExtent() 92 */ 93 virtual double extent( const QFont &font ) const = 0;90 \sa setMinimumExtent(), minimumExtent() 91 */ 92 virtual double extent( const QFont& font ) const = 0; 94 93 95 94 void setMinimumExtent( double ); 96 95 double minimumExtent() const; 97 96 98 protected: 97 void invalidateCache(); 98 99 protected: 99 100 /*! 100 101 Draw a tick … … 105 106 106 107 \sa drawBackbone(), drawLabel() 107 */ 108 virtual void drawTick( QPainter *painter, double value, double len ) const = 0;108 */ 109 virtual void drawTick( QPainter* painter, double value, double len ) const = 0; 109 110 110 111 /*! 111 Draws the baseline of the scale 112 \param painter Painter 112 Draws the baseline of the scale 113 \param painter Painter 113 114 114 \sa drawTick(), drawLabel() 115 */ 116 virtual void drawBackbone( QPainter *painter ) const = 0;115 \sa drawTick(), drawLabel() 116 */ 117 virtual void drawBackbone( QPainter* painter ) const = 0; 117 118 118 119 /*! … … 123 124 124 125 \sa drawTick(), drawBackbone() 125 */ 126 virtual void drawLabel( QPainter *painter, double value ) const = 0;126 */ 127 virtual void drawLabel( QPainter* painter, double value ) const = 0; 127 128 128 void invalidateCache(); 129 const QwtText &tickLabel( const QFont &, double value ) const; 129 const QwtText& tickLabel( const QFont&, double value ) const; 130 130 131 private: 132 QwtAbstractScaleDraw( const QwtAbstractScaleDraw & ); 133 QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & ); 131 private: 132 Q_DISABLE_COPY(QwtAbstractScaleDraw) 134 133 135 134 class PrivateData; 136 PrivateData *d_data;135 PrivateData* m_data; 137 136 }; 138 137 -
trunk/BNC/qwt/qwt_abstract_slider.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_abstract_slider.h" 11 #include "qwt_abstract_scale_draw.h" 11 #include "qwt_scale_map.h" 12 #include "qwt_scale_div.h" 12 13 #include "qwt_math.h" 13 #include "qwt_scale_map.h" 14 14 15 #include <qevent.h> 15 16 16 #if QT_VERSION < 0x04060117 #define qFabs(x) ::fabs(x)18 #endif19 20 17 static double qwtAlignToScaleDiv( 21 const QwtAbstractSlider *slider, double value )22 { 23 const QwtScaleDiv &sd = slider->scaleDiv();18 const QwtAbstractSlider* slider, double value ) 19 { 20 const QwtScaleDiv& sd = slider->scaleDiv(); 24 21 25 22 const int tValue = slider->transform( value ); … … 33 30 for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ ) 34 31 { 35 const QList< double> ticks = sd.ticks( i );32 const QList< double > ticks = sd.ticks( i ); 36 33 for ( int j = 0; j < ticks.size(); j++ ) 37 34 { … … 46 43 class QwtAbstractSlider::PrivateData 47 44 { 48 public: 49 PrivateData() :50 isScrolling( false ) ,51 isTracking( true ) ,52 pendingValueChanged( false ) ,53 readOnly( false ) ,54 totalSteps( 100 ) ,55 singleSteps( 1 ) ,56 pageSteps( 10 ) ,57 stepAlignment( true ) ,58 isValid( false ) ,59 value( 0.0 ) ,60 wrapping( false ) ,61 invertedControls( false ) 45 public: 46 PrivateData() 47 : isScrolling( false ) 48 , isTracking( true ) 49 , pendingValueChanged( false ) 50 , readOnly( false ) 51 , totalSteps( 100 ) 52 , singleSteps( 1 ) 53 , pageSteps( 10 ) 54 , stepAlignment( true ) 55 , isValid( false ) 56 , value( 0.0 ) 57 , wrapping( false ) 58 , invertedControls( false ) 62 59 { 63 60 } … … 82 79 83 80 /*! 84 \brief Constructor 85 86 The scale is initialized to [0.0, 100.0], the 87 number of steps is set to 100 with 1 and 10 and single 88 an page step sizes. Step alignment is enabled. 89 90 The initial value is invalid. 91 92 \param parent Parent widget 93 */ 94 QwtAbstractSlider::QwtAbstractSlider( QWidget *parent ):95 QwtAbstractScale( parent ) 96 { 97 d_data = new QwtAbstractSlider::PrivateData;81 \brief Constructor 82 83 The scale is initialized to [0.0, 100.0], the 84 number of steps is set to 100 with 1 and 10 and single 85 an page step sizes. Step alignment is enabled. 86 87 The initial value is invalid. 88 89 \param parent Parent widget 90 */ 91 QwtAbstractSlider::QwtAbstractSlider( QWidget* parent ) 92 : QwtAbstractScale( parent ) 93 { 94 m_data = new QwtAbstractSlider::PrivateData; 98 95 99 96 setScale( 0.0, 100.0 ); … … 104 101 QwtAbstractSlider::~QwtAbstractSlider() 105 102 { 106 delete d_data;107 } 108 109 /*! 110 Set the value to be valid/invalid 111 112 \param on When true, the value is invalidated 113 114 \sa setValue() 115 */ 103 delete m_data; 104 } 105 106 /*! 107 Set the value to be valid/invalid 108 109 \param on When true, the value is invalidated 110 111 \sa setValue() 112 */ 116 113 void QwtAbstractSlider::setValid( bool on ) 117 114 { 118 if ( on != d_data->isValid )119 { 120 d_data->isValid = on;115 if ( on != m_data->isValid ) 116 { 117 m_data->isValid = on; 121 118 sliderChange(); 122 119 123 Q_EMIT valueChanged( d_data->value );120 Q_EMIT valueChanged( m_data->value ); 124 121 } 125 122 } … … 128 125 bool QwtAbstractSlider::isValid() const 129 126 { 130 return d_data->isValid;131 } 132 133 /*! 134 En/Disable read only mode 135 136 In read only mode the slider can't be controlled by mouse 137 or keyboard. 138 139 \param on Enables in case of true 140 \sa isReadOnly() 141 142 \warning The focus policy is set to Qt::StrongFocus or Qt::NoFocus 143 */ 127 return m_data->isValid; 128 } 129 130 /*! 131 En/Disable read only mode 132 133 In read only mode the slider can't be controlled by mouse 134 or keyboard. 135 136 \param on Enables in case of true 137 \sa isReadOnly() 138 139 \warning The focus policy is set to Qt::StrongFocus or Qt::NoFocus 140 */ 144 141 void QwtAbstractSlider::setReadOnly( bool on ) 145 142 { 146 if ( d_data->readOnly != on )147 { 148 d_data->readOnly = on;143 if ( m_data->readOnly != on ) 144 { 145 m_data->readOnly = on; 149 146 setFocusPolicy( on ? Qt::StrongFocus : Qt::NoFocus ); 150 147 … … 154 151 155 152 /*! 156 In read only mode the slider can't be controlled by mouse 157 or keyboard. 158 159 \return true if read only 160 \sa setReadOnly() 161 */ 153 In read only mode the slider can't be controlled by mouse 154 or keyboard. 155 156 \return true if read only 157 \sa setReadOnly() 158 */ 162 159 bool QwtAbstractSlider::isReadOnly() const 163 160 { 164 return d_data->readOnly;165 } 166 167 /*! 168 \brief Enables or disables tracking. 169 170 If tracking is enabled, the slider emits the valueChanged() 171 signal while the movable part of the slider is being dragged. 172 If tracking is disabled, the slider emits the valueChanged() signal 173 only when the user releases the slider. 174 175 Tracking is enabled by default. 176 \param on \c true (enable) or \c false (disable) tracking. 177 178 \sa isTracking(), sliderMoved() 179 */ 161 return m_data->readOnly; 162 } 163 164 /*! 165 \brief Enables or disables tracking. 166 167 If tracking is enabled, the slider emits the valueChanged() 168 signal while the movable part of the slider is being dragged. 169 If tracking is disabled, the slider emits the valueChanged() signal 170 only when the user releases the slider. 171 172 Tracking is enabled by default. 173 \param on \c true (enable) or \c false (disable) tracking. 174 175 \sa isTracking(), sliderMoved() 176 */ 180 177 void QwtAbstractSlider::setTracking( bool on ) 181 178 { 182 d_data->isTracking = on;183 } 184 185 /*! 186 \return True, when tracking has been enabled 187 \sa setTracking() 188 */ 179 m_data->isTracking = on; 180 } 181 182 /*! 183 \return True, when tracking has been enabled 184 \sa setTracking() 185 */ 189 186 bool QwtAbstractSlider::isTracking() const 190 187 { 191 return d_data->isTracking;188 return m_data->isTracking; 192 189 } 193 190 … … 195 192 Mouse press event handler 196 193 \param event Mouse event 197 */ 198 void QwtAbstractSlider::mousePressEvent( QMouseEvent *event )194 */ 195 void QwtAbstractSlider::mousePressEvent( QMouseEvent* event ) 199 196 { 200 197 if ( isReadOnly() ) … … 204 201 } 205 202 206 if ( ! d_data->isValid || lowerBound() == upperBound() )203 if ( !m_data->isValid || lowerBound() == upperBound() ) 207 204 return; 208 205 209 d_data->isScrolling = isScrollPosition( event->pos() );210 211 if ( d_data->isScrolling )212 { 213 d_data->pendingValueChanged = false;206 m_data->isScrolling = isScrollPosition( event->pos() ); 207 208 if ( m_data->isScrolling ) 209 { 210 m_data->pendingValueChanged = false; 214 211 215 212 Q_EMIT sliderPressed(); … … 220 217 Mouse Move Event handler 221 218 \param event Mouse event 222 */ 223 void QwtAbstractSlider::mouseMoveEvent( QMouseEvent *event )219 */ 220 void QwtAbstractSlider::mouseMoveEvent( QMouseEvent* event ) 224 221 { 225 222 if ( isReadOnly() ) … … 229 226 } 230 227 231 if ( d_data->isValid &&d_data->isScrolling )228 if ( m_data->isValid && m_data->isScrolling ) 232 229 { 233 230 double value = scrolledTo( event->pos() ); 234 if ( value != d_data->value )231 if ( value != m_data->value ) 235 232 { 236 233 value = boundedValue( value ); 237 234 238 if ( d_data->stepAlignment )235 if ( m_data->stepAlignment ) 239 236 { 240 237 value = alignedValue( value ); … … 245 242 } 246 243 247 if ( value != d_data->value )244 if ( value != m_data->value ) 248 245 { 249 d_data->value = value;246 m_data->value = value; 250 247 251 248 sliderChange(); 252 249 253 Q_EMIT sliderMoved( d_data->value );254 255 if ( d_data->isTracking )256 Q_EMIT valueChanged( d_data->value );250 Q_EMIT sliderMoved( m_data->value ); 251 252 if ( m_data->isTracking ) 253 Q_EMIT valueChanged( m_data->value ); 257 254 else 258 d_data->pendingValueChanged = true;255 m_data->pendingValueChanged = true; 259 256 } 260 257 } … … 265 262 Mouse Release Event handler 266 263 \param event Mouse event 267 */ 268 void QwtAbstractSlider::mouseReleaseEvent( QMouseEvent *event )264 */ 265 void QwtAbstractSlider::mouseReleaseEvent( QMouseEvent* event ) 269 266 { 270 267 if ( isReadOnly() ) … … 274 271 } 275 272 276 if ( d_data->isScrolling &&d_data->isValid )277 { 278 d_data->isScrolling = false;279 280 if ( d_data->pendingValueChanged )281 Q_EMIT valueChanged( d_data->value );273 if ( m_data->isScrolling && m_data->isValid ) 274 { 275 m_data->isScrolling = false; 276 277 if ( m_data->pendingValueChanged ) 278 Q_EMIT valueChanged( m_data->value ); 282 279 283 280 Q_EMIT sliderReleased(); … … 296 293 297 294 \param event Wheel event 298 */ 299 void QwtAbstractSlider::wheelEvent( QWheelEvent *event )295 */ 296 void QwtAbstractSlider::wheelEvent( QWheelEvent* event ) 300 297 { 301 298 if ( isReadOnly() ) … … 305 302 } 306 303 307 if ( ! d_data->isValid ||d_data->isScrolling )304 if ( !m_data->isValid || m_data->isScrolling ) 308 305 return; 309 306 307 #if QT_VERSION < 0x050000 308 const int wheelDelta = event->delta(); 309 #else 310 const QPoint delta = event->angleDelta(); 311 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) ) 312 ? delta.x() : delta.y(); 313 #endif 314 310 315 int numSteps = 0; 311 316 312 if ( ( event->modifiers() & Qt::ControlModifier) || 317 if ( ( event->modifiers() & Qt::ControlModifier ) || 313 318 ( event->modifiers() & Qt::ShiftModifier ) ) 314 319 { 315 320 // one page regardless of delta 316 numSteps = d_data->pageSteps;317 if ( event->delta()< 0 )321 numSteps = m_data->pageSteps; 322 if ( wheelDelta < 0 ) 318 323 numSteps = -numSteps; 319 324 } 320 325 else 321 326 { 322 const int numTurns = ( event->delta()/ 120 );323 numSteps = numTurns * d_data->singleSteps;324 } 325 326 if ( d_data->invertedControls )327 const int numTurns = ( wheelDelta / 120 ); 328 numSteps = numTurns * m_data->singleSteps; 329 } 330 331 if ( m_data->invertedControls ) 327 332 numSteps = -numSteps; 328 333 329 const double value = incrementedValue( d_data->value, numSteps );330 if ( value != d_data->value )331 { 332 d_data->value = value;334 const double value = incrementedValue( m_data->value, numSteps ); 335 if ( value != m_data->value ) 336 { 337 m_data->value = value; 333 338 sliderChange(); 334 339 335 Q_EMIT sliderMoved( d_data->value );336 Q_EMIT valueChanged( d_data->value );337 } 338 } 339 340 /*! 341 Handles key events 342 343 QwtAbstractSlider handles the following keys: 344 345 - Qt::Key_Left\n 340 Q_EMIT sliderMoved( m_data->value ); 341 Q_EMIT valueChanged( m_data->value ); 342 } 343 } 344 345 /*! 346 Handles key events 347 348 QwtAbstractSlider handles the following keys: 349 350 - Qt::Key_Left\n 346 351 Add/Subtract singleSteps() in direction to lowerBound(); 347 - Qt::Key_Right\n 352 - Qt::Key_Right\n 348 353 Add/Subtract singleSteps() in direction to upperBound(); 349 - Qt::Key_Down\n 354 - Qt::Key_Down\n 350 355 Subtract singleSteps(), when invertedControls() is false 351 - Qt::Key_Up\n 356 - Qt::Key_Up\n 352 357 Add singleSteps(), when invertedControls() is false 353 - Qt::Key_PageDown\n 358 - Qt::Key_PageDown\n 354 359 Subtract pageSteps(), when invertedControls() is false 355 - Qt::Key_PageUp\n 360 - Qt::Key_PageUp\n 356 361 Add pageSteps(), when invertedControls() is false 357 - Qt::Key_Home\n 362 - Qt::Key_Home\n 358 363 Set the value to the minimum() 359 - Qt::Key_End\n 364 - Qt::Key_End\n 360 365 Set the value to the maximum() 361 366 362 \param event Key event 363 \sa isReadOnly() 364 */ 365 void QwtAbstractSlider::keyPressEvent( QKeyEvent *event )367 \param event Key event 368 \sa isReadOnly() 369 */ 370 void QwtAbstractSlider::keyPressEvent( QKeyEvent* event ) 366 371 { 367 372 if ( isReadOnly() ) … … 371 376 } 372 377 373 if ( ! d_data->isValid ||d_data->isScrolling )378 if ( !m_data->isValid || m_data->isScrolling ) 374 379 return; 375 380 376 381 int numSteps = 0; 377 double value = d_data->value;382 double value = m_data->value; 378 383 379 384 switch ( event->key() ) … … 381 386 case Qt::Key_Left: 382 387 { 383 numSteps = -static_cast< int>( d_data->singleSteps );388 numSteps = -static_cast< int >( m_data->singleSteps ); 384 389 if ( isInverted() ) 385 390 numSteps = -numSteps; … … 389 394 case Qt::Key_Right: 390 395 { 391 numSteps = d_data->singleSteps;396 numSteps = m_data->singleSteps; 392 397 if ( isInverted() ) 393 398 numSteps = -numSteps; … … 397 402 case Qt::Key_Down: 398 403 { 399 numSteps = -static_cast< int>( d_data->singleSteps );400 if ( d_data->invertedControls )404 numSteps = -static_cast< int >( m_data->singleSteps ); 405 if ( m_data->invertedControls ) 401 406 numSteps = -numSteps; 402 407 break; … … 404 409 case Qt::Key_Up: 405 410 { 406 numSteps = d_data->singleSteps;407 if ( d_data->invertedControls )411 numSteps = m_data->singleSteps; 412 if ( m_data->invertedControls ) 408 413 numSteps = -numSteps; 409 414 … … 412 417 case Qt::Key_PageUp: 413 418 { 414 numSteps = d_data->pageSteps;415 if ( d_data->invertedControls )419 numSteps = m_data->pageSteps; 420 if ( m_data->invertedControls ) 416 421 numSteps = -numSteps; 417 422 break; … … 419 424 case Qt::Key_PageDown: 420 425 { 421 numSteps = -static_cast< int>( d_data->pageSteps );422 if ( d_data->invertedControls )426 numSteps = -static_cast< int >( m_data->pageSteps ); 427 if ( m_data->invertedControls ) 423 428 numSteps = -numSteps; 424 429 break; … … 434 439 break; 435 440 } 436 default: ;441 default: 437 442 { 438 443 event->ignore(); … … 442 447 if ( numSteps != 0 ) 443 448 { 444 value = incrementedValue( d_data->value, numSteps );445 } 446 447 if ( value != d_data->value )448 { 449 d_data->value = value;449 value = incrementedValue( m_data->value, numSteps ); 450 } 451 452 if ( value != m_data->value ) 453 { 454 m_data->value = value; 450 455 sliderChange(); 451 456 452 Q_EMIT sliderMoved( d_data->value );453 Q_EMIT valueChanged( d_data->value );454 } 455 } 456 457 /*! 458 \brief Set the number of steps 459 460 The range of the slider is divided into a number of steps from 461 which the value increments according to user inputs depend. 462 463 The default setting is 100. 464 465 \param stepCount Number of steps 466 467 \sa totalSteps(), setSingleSteps(), setPageSteps() 457 Q_EMIT sliderMoved( m_data->value ); 458 Q_EMIT valueChanged( m_data->value ); 459 } 460 } 461 462 /*! 463 \brief Set the number of steps 464 465 The range of the slider is divided into a number of steps from 466 which the value increments according to user inputs depend. 467 468 The default setting is 100. 469 470 \param stepCount Number of steps 471 472 \sa totalSteps(), setSingleSteps(), setPageSteps() 468 473 */ 469 474 void QwtAbstractSlider::setTotalSteps( uint stepCount ) 470 475 { 471 d_data->totalSteps = stepCount;472 } 473 474 /*! 475 \return Number of steps 476 \sa setTotalSteps(), singleSteps(), pageSteps() 476 m_data->totalSteps = stepCount; 477 } 478 479 /*! 480 \return Number of steps 481 \sa setTotalSteps(), singleSteps(), pageSteps() 477 482 */ 478 483 uint QwtAbstractSlider::totalSteps() const 479 484 { 480 return d_data->totalSteps;481 } 482 483 /*! 484 \brief Set the number of steps for a single increment 485 486 The range of the slider is divided into a number of steps from 487 which the value increments according to user inputs depend. 488 489 \param stepCount Number of steps 490 491 \sa singleSteps(), setTotalSteps(), setPageSteps() 485 return m_data->totalSteps; 486 } 487 488 /*! 489 \brief Set the number of steps for a single increment 490 491 The range of the slider is divided into a number of steps from 492 which the value increments according to user inputs depend. 493 494 \param stepCount Number of steps 495 496 \sa singleSteps(), setTotalSteps(), setPageSteps() 492 497 */ 493 498 494 499 void QwtAbstractSlider::setSingleSteps( uint stepCount ) 495 500 { 496 d_data->singleSteps = stepCount;497 } 498 499 /*! 500 \return Number of steps 501 \sa setSingleSteps(), totalSteps(), pageSteps() 501 m_data->singleSteps = stepCount; 502 } 503 504 /*! 505 \return Number of steps 506 \sa setSingleSteps(), totalSteps(), pageSteps() 502 507 */ 503 508 uint QwtAbstractSlider::singleSteps() const 504 509 { 505 return d_data->singleSteps;506 } 507 508 /*! 509 \brief Set the number of steps for a page increment 510 511 The range of the slider is divided into a number of steps from 512 which the value increments according to user inputs depend. 513 514 \param stepCount Number of steps 515 516 \sa pageSteps(), setTotalSteps(), setSingleSteps() 510 return m_data->singleSteps; 511 } 512 513 /*! 514 \brief Set the number of steps for a page increment 515 516 The range of the slider is divided into a number of steps from 517 which the value increments according to user inputs depend. 518 519 \param stepCount Number of steps 520 521 \sa pageSteps(), setTotalSteps(), setSingleSteps() 517 522 */ 518 523 519 524 void QwtAbstractSlider::setPageSteps( uint stepCount ) 520 525 { 521 d_data->pageSteps = stepCount;522 } 523 524 /*! 525 \return Number of steps 526 \sa setPageSteps(), totalSteps(), singleSteps() 526 m_data->pageSteps = stepCount; 527 } 528 529 /*! 530 \return Number of steps 531 \sa setPageSteps(), totalSteps(), singleSteps() 527 532 */ 528 533 uint QwtAbstractSlider::pageSteps() const 529 534 { 530 return d_data->pageSteps;531 } 532 533 /*! 534 \brief Enable step alignment 535 536 When step alignment is enabled values resulting from slider 537 movements are aligned to the step size. 538 539 \param on Enable step alignment when true 540 \sa stepAlignment() 541 */ 535 return m_data->pageSteps; 536 } 537 538 /*! 539 \brief Enable step alignment 540 541 When step alignment is enabled values resulting from slider 542 movements are aligned to the step size. 543 544 \param on Enable step alignment when true 545 \sa stepAlignment() 546 */ 542 547 void QwtAbstractSlider::setStepAlignment( bool on ) 543 548 { 544 if ( on != d_data->stepAlignment )545 { 546 d_data->stepAlignment = on;547 } 548 } 549 550 /*! 551 \return True, when step alignment is enabled 552 \sa setStepAlignment() 549 if ( on != m_data->stepAlignment ) 550 { 551 m_data->stepAlignment = on; 552 } 553 } 554 555 /*! 556 \return True, when step alignment is enabled 557 \sa setStepAlignment() 553 558 */ 554 559 bool QwtAbstractSlider::stepAlignment() const 555 560 { 556 return d_data->stepAlignment;557 } 558 559 /*! 560 Set the slider to the specified value 561 562 \param value New value 563 \sa setValid(), sliderChange(), valueChanged() 564 */ 561 return m_data->stepAlignment; 562 } 563 564 /*! 565 Set the slider to the specified value 566 567 \param value New value 568 \sa setValid(), sliderChange(), valueChanged() 569 */ 565 570 void QwtAbstractSlider::setValue( double value ) 566 571 { 567 572 value = qBound( minimum(), value, maximum() ); 568 573 569 const bool changed = ( d_data->value != value ) || !d_data->isValid;570 571 d_data->value = value;572 d_data->isValid = true;574 const bool changed = ( m_data->value != value ) || !m_data->isValid; 575 576 m_data->value = value; 577 m_data->isValid = true; 573 578 574 579 if ( changed ) 575 580 { 576 581 sliderChange(); 577 Q_EMIT valueChanged( d_data->value );582 Q_EMIT valueChanged( m_data->value ); 578 583 } 579 584 } … … 582 587 double QwtAbstractSlider::value() const 583 588 { 584 return d_data->value;585 } 586 587 /*! 588 If wrapping is true stepping up from upperBound() value will 589 take you to the minimum() value and vice versa. 590 591 \param on En/Disable wrapping 592 \sa wrapping() 593 */ 589 return m_data->value; 590 } 591 592 /*! 593 If wrapping is true stepping up from upperBound() value will 594 take you to the minimum() value and vice versa. 595 596 \param on En/Disable wrapping 597 \sa wrapping() 598 */ 594 599 void QwtAbstractSlider::setWrapping( bool on ) 595 600 { 596 d_data->wrapping = on;597 } 598 599 /*! 600 \return True, when wrapping is set 601 \sa setWrapping() 601 m_data->wrapping = on; 602 } 603 604 /*! 605 \return True, when wrapping is set 606 \sa setWrapping() 602 607 */ 603 608 bool QwtAbstractSlider::wrapping() const 604 609 { 605 return d_data->wrapping;606 } 607 608 /*! 609 Invert wheel and key events 610 611 Usually scrolling the mouse wheel "up" and using keys like page 612 up will increase the slider's value towards its maximum. 613 When invertedControls() is enabled the value is scrolled 614 towards its minimum. 615 616 Inverting the controls might be f.e. useful for a vertical slider 617 with an inverted scale ( decreasing from top to bottom ). 618 619 \param on Invert controls, when true 620 621 \sa invertedControls(), keyEvent(), wheelEvent() 610 return m_data->wrapping; 611 } 612 613 /*! 614 Invert wheel and key events 615 616 Usually scrolling the mouse wheel "up" and using keys like page 617 up will increase the slider's value towards its maximum. 618 When invertedControls() is enabled the value is scrolled 619 towards its minimum. 620 621 Inverting the controls might be f.e. useful for a vertical slider 622 with an inverted scale ( decreasing from top to bottom ). 623 624 \param on Invert controls, when true 625 626 \sa invertedControls(), keyEvent(), wheelEvent() 622 627 */ 623 628 void QwtAbstractSlider::setInvertedControls( bool on ) 624 629 { 625 d_data->invertedControls = on;626 } 627 628 /*! 629 \return True, when the controls are inverted 630 \sa setInvertedControls() 630 m_data->invertedControls = on; 631 } 632 633 /*! 634 \return True, when the controls are inverted 635 \sa setInvertedControls() 631 636 */ 632 637 bool QwtAbstractSlider::invertedControls() const 633 638 { 634 return d_data->invertedControls;635 } 636 637 /*! 638 Increment the slider 639 640 The step size depends on the number of totalSteps() 641 642 \param stepCount Number of steps 643 \sa setTotalSteps(), incrementedValue() 639 return m_data->invertedControls; 640 } 641 642 /*! 643 Increment the slider 644 645 The step size depends on the number of totalSteps() 646 647 \param stepCount Number of steps 648 \sa setTotalSteps(), incrementedValue() 644 649 */ 645 650 void QwtAbstractSlider::incrementValue( int stepCount ) 646 651 { 647 652 const double value = incrementedValue( 648 d_data->value, stepCount );649 650 if ( value != d_data->value )651 { 652 d_data->value = value;653 m_data->value, stepCount ); 654 655 if ( value != m_data->value ) 656 { 657 m_data->value = value; 653 658 sliderChange(); 654 659 } … … 656 661 657 662 /*! 658 Increment a value 659 660 \param value Value 661 \param stepCount Number of steps 662 663 \return Incremented value 663 Increment a value 664 665 \param value Value 666 \param stepCount Number of steps 667 668 \return Incremented value 664 669 */ 665 670 double QwtAbstractSlider::incrementedValue( 666 671 double value, int stepCount ) const 667 672 { 668 if ( d_data->totalSteps == 0 )673 if ( m_data->totalSteps == 0 ) 669 674 return value; 670 675 671 const QwtTransform *transformation =676 const QwtTransform* transformation = 672 677 scaleMap().transformation(); 673 678 … … 675 680 { 676 681 const double range = maximum() - minimum(); 677 value += stepCount * range / d_data->totalSteps;682 value += stepCount * range / m_data->totalSteps; 678 683 } 679 684 else 680 685 { 681 686 QwtScaleMap map = scaleMap(); 682 map.setPaintInterval( 0, d_data->totalSteps );683 684 // we need equidant steps according to 687 map.setPaintInterval( 0, m_data->totalSteps ); 688 689 // we need equidistant steps according to 685 690 // paint device coordinates 686 691 const double range = transformation->transform( maximum() ) 687 692 - transformation->transform( minimum() ); 688 693 689 const double stepSize = range / d_data->totalSteps;694 const double stepSize = range / m_data->totalSteps; 690 695 691 696 double v = transformation->transform( value ); 692 697 693 698 v = qRound( v / stepSize ) * stepSize; 694 v += stepCount * range / d_data->totalSteps;699 v += stepCount * range / m_data->totalSteps; 695 700 696 701 value = transformation->invTransform( v ); … … 699 704 value = boundedValue( value ); 700 705 701 if ( d_data->stepAlignment )706 if ( m_data->stepAlignment ) 702 707 value = alignedValue( value ); 703 708 … … 710 715 const double vmax = maximum(); 711 716 712 if ( d_data->wrapping && vmin != vmax ) 713 { 714 const int fullCircle = 360 * 16; 715 716 const double pd = scaleMap().pDist(); 717 if ( int( pd / fullCircle ) * fullCircle == pd ) 717 if ( m_data->wrapping && vmin != vmax ) 718 { 719 if ( qFuzzyCompare( scaleMap().pDist(), 360.0 ) ) 718 720 { 719 721 // full circle scales: min and max are the same 720 const double range = vmax - vmin; 721 722 if ( value < vmin ) 722 723 if ( qFuzzyCompare( value, vmax ) ) 723 724 { 724 value += ::ceil( ( vmin - value ) / range ) * range;725 value = vmin; 725 726 } 726 else if ( value > vmax )727 else 727 728 { 728 value -= ::ceil( ( value - vmax ) / range ) * range; 729 const double range = vmax - vmin; 730 731 if ( value < vmin ) 732 { 733 value += std::ceil( ( vmin - value ) / range ) * range; 734 } 735 else if ( value > vmax ) 736 { 737 value -= std::ceil( ( value - vmax ) / range ) * range; 738 } 729 739 } 730 740 } … … 747 757 double QwtAbstractSlider::alignedValue( double value ) const 748 758 { 749 if ( d_data->totalSteps == 0 )759 if ( m_data->totalSteps == 0 ) 750 760 return value; 751 761 … … 754 764 if ( scaleMap().transformation() == NULL ) 755 765 { 756 stepSize = ( maximum() - minimum() ) / d_data->totalSteps;766 stepSize = ( maximum() - minimum() ) / m_data->totalSteps; 757 767 if ( stepSize > 0.0 ) 758 768 { … … 763 773 else 764 774 { 765 stepSize = ( scaleMap().p2() - scaleMap().p1() ) / d_data->totalSteps;775 stepSize = ( scaleMap().p2() - scaleMap().p1() ) / m_data->totalSteps; 766 776 767 777 if ( stepSize > 0.0 ) … … 797 807 798 808 /*! 799 Update the slider according to modifications of the scale 809 Update the slider according to modifications of the scale 800 810 */ 801 811 void QwtAbstractSlider::scaleChange() 802 812 { 803 const double value = qBound( minimum(), d_data->value, maximum() );804 805 const bool changed = ( value != d_data->value );813 const double value = qBound( minimum(), m_data->value, maximum() ); 814 815 const bool changed = ( value != m_data->value ); 806 816 if ( changed ) 807 817 { 808 d_data->value = value;809 } 810 811 if ( d_data->isValid || changed )812 Q_EMIT valueChanged( d_data->value );818 m_data->value = value; 819 } 820 821 if ( m_data->isValid || changed ) 822 Q_EMIT valueChanged( m_data->value ); 813 823 814 824 updateGeometry(); … … 821 831 update(); 822 832 } 833 834 #include "moc_qwt_abstract_slider.cpp" -
trunk/BNC/qwt/qwt_abstract_slider.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 16 16 /*! 17 \brief An abstract base class for slider widgets with a scale 17 \brief An abstract base class for slider widgets with a scale 18 18 19 A slider widget displays a value according to a scale. 20 The class is designed as a common super class for widgets like 21 QwtKnob, QwtDial and QwtSlider. 19 A slider widget displays a value according to a scale. 20 The class is designed as a common super class for widgets like 21 QwtKnob, QwtDial and QwtSlider. 22 22 23 When the slider is nor readOnly() its value can be modified 24 by keyboard, mouse and wheel inputs. 23 When the slider is nor readOnly() its value can be modified 24 by keyboard, mouse and wheel inputs. 25 25 26 The range of the slider is divided into a number of steps from 27 which the value increments according to user inputs depend. 28 Only for linear scales the number of steps correspond with 29 a fixed step size. 30 */ 26 The range of the slider is divided into a number of steps from 27 which the value increments according to user inputs depend. 28 Only for linear scales the number of steps correspond with 29 a fixed step size. 30 */ 31 31 32 class QWT_EXPORT QwtAbstractSlider: public QwtAbstractScale 32 class QWT_EXPORT QwtAbstractSlider : public QwtAbstractScale 33 33 { 34 34 Q_OBJECT 35 35 36 Q_PROPERTY( double value READ value WRITE setValue ) 36 Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged USER true ) 37 37 38 38 Q_PROPERTY( uint totalSteps READ totalSteps WRITE setTotalSteps ) … … 47 47 Q_PROPERTY( bool invertedControls READ invertedControls WRITE setInvertedControls ) 48 48 49 public: 50 explicit QwtAbstractSlider( QWidget *parent = NULL );49 public: 50 explicit QwtAbstractSlider( QWidget* parent = NULL ); 51 51 virtual ~QwtAbstractSlider(); 52 52 … … 80 80 bool invertedControls() const; 81 81 82 public Q_SLOTS: 82 public Q_SLOTS: 83 83 void setValue( double value ); 84 84 85 Q_SIGNALS: 85 Q_SIGNALS: 86 86 87 87 /*! 88 \brief Notify a change of value. 88 \brief Notify a change of value. 89 89 90 When tracking is enabled (default setting), 91 this signal will be emitted every time the value changes. 90 When tracking is enabled (default setting), 91 this signal will be emitted every time the value changes. 92 92 93 \param value New value 93 \param value New value 94 94 95 \sa setTracking(), sliderMoved() 96 */ 95 \sa setTracking(), sliderMoved() 96 */ 97 97 void valueChanged( double value ); 98 98 99 99 /*! 100 This signal is emitted when the user presses the 101 movable part of the slider. 102 */ 100 This signal is emitted when the user presses the 101 movable part of the slider. 102 */ 103 103 void sliderPressed(); 104 104 105 105 /*! 106 This signal is emitted when the user releases the 107 movable part of the slider. 108 */ 106 This signal is emitted when the user releases the 107 movable part of the slider. 108 */ 109 109 void sliderReleased(); 110 110 111 111 /*! 112 This signal is emitted when the user moves the 113 slider with the mouse. 112 This signal is emitted when the user moves the 113 slider with the mouse. 114 114 115 \param value New value 115 \param value New value 116 116 117 \sa valueChanged() 118 */ 117 \sa valueChanged() 118 */ 119 119 void sliderMoved( double value ); 120 120 121 protected: 122 virtual void mousePressEvent( QMouseEvent * );123 virtual void mouseReleaseEvent( QMouseEvent * );124 virtual void mouseMoveEvent( QMouseEvent * );125 virtual void keyPressEvent( QKeyEvent * );126 virtual void wheelEvent( QWheelEvent * );121 protected: 122 virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE; 123 virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE; 124 virtual void mouseMoveEvent( QMouseEvent* ) QWT_OVERRIDE; 125 virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 126 virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE; 127 127 128 128 /*! 129 \brief Determine what to do when the user presses a mouse button. 129 \brief Determine what to do when the user presses a mouse button. 130 130 131 \param pos Mouse position 131 \param pos Mouse position 132 132 133 \retval True, when pos is a valid scroll position 134 \sa scrolledTo() 135 */ 136 virtual bool isScrollPosition( const QPoint &pos ) const = 0;133 \retval True, when pos is a valid scroll position 134 \sa scrolledTo() 135 */ 136 virtual bool isScrollPosition( const QPoint& pos ) const = 0; 137 137 138 138 /*! 139 \brief Determine the value for a new position of the 139 \brief Determine the value for a new position of the 140 140 movable part of the slider 141 141 142 \param pos Mouse position 142 \param pos Mouse position 143 143 144 \return Value for the mouse position 145 \sa isScrollPosition() 146 */ 147 virtual double scrolledTo( const QPoint &pos ) const = 0;144 \return Value for the mouse position 145 \sa isScrollPosition() 146 */ 147 virtual double scrolledTo( const QPoint& pos ) const = 0; 148 148 149 149 void incrementValue( int stepCount ); 150 150 151 virtual void scaleChange(); 151 virtual void scaleChange() QWT_OVERRIDE; 152 152 153 protected: 153 protected: 154 154 virtual void sliderChange(); 155 155 … … 157 157 double value, int stepCount ) const; 158 158 159 private: 159 private: 160 160 double alignedValue( double ) const; 161 161 double boundedValue( double ) const; 162 162 163 163 class PrivateData; 164 PrivateData *d_data;164 PrivateData* m_data; 165 165 }; 166 166 -
trunk/BNC/qwt/qwt_analog_clock.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_analog_clock.h" 11 #include "qwt_dial_needle.h" 11 12 #include "qwt_round_scale_draw.h" 12 #include <qmath.h> 13 #include "qwt_text.h" 14 #include "qwt_math.h" 15 13 16 #include <qlocale.h> 14 15 class QwtAnalogClockScaleDraw: public QwtRoundScaleDraw 16 { 17 public: 18 QwtAnalogClockScaleDraw() 19 { 20 setSpacing( 8 ); 21 22 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 23 24 setTickLength( QwtScaleDiv::MinorTick, 2 ); 25 setTickLength( QwtScaleDiv::MediumTick, 4 ); 26 setTickLength( QwtScaleDiv::MajorTick, 8 ); 27 28 setPenWidth( 1 ); 29 } 30 31 virtual QwtText label( double value ) const 32 { 33 if ( qFuzzyCompare( value + 1.0, 1.0 ) ) 34 value = 60.0 * 60.0 * 12.0; 35 36 return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) ); 37 } 38 }; 39 40 /*! 41 Constructor 42 \param parent Parent widget 43 */ 44 QwtAnalogClock::QwtAnalogClock( QWidget *parent ): 45 QwtDial( parent ) 17 #include <qdatetime.h> 18 19 namespace 20 { 21 class QwtAnalogClockScaleDraw QWT_FINAL : public QwtRoundScaleDraw 22 { 23 public: 24 QwtAnalogClockScaleDraw() 25 { 26 setSpacing( 8 ); 27 28 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 29 30 setTickLength( QwtScaleDiv::MinorTick, 2 ); 31 setTickLength( QwtScaleDiv::MediumTick, 4 ); 32 setTickLength( QwtScaleDiv::MajorTick, 8 ); 33 34 setPenWidthF( 1.0 ); 35 } 36 37 virtual QwtText label( double value ) const QWT_OVERRIDE 38 { 39 if ( qFuzzyCompare( value + 1.0, 1.0 ) ) 40 value = 60.0 * 60.0 * 12.0; 41 42 return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) ); 43 } 44 }; 45 } 46 47 /*! 48 Constructor 49 \param parent Parent widget 50 */ 51 QwtAnalogClock::QwtAnalogClock( QWidget* parent ) 52 : QwtDial( parent ) 46 53 { 47 54 setWrapping( true ); … … 55 62 const int secondsPerHour = 60.0 * 60.0; 56 63 57 QList< double> majorTicks;58 QList< double> minorTicks;64 QList< double > majorTicks; 65 QList< double > minorTicks; 59 66 60 67 for ( int i = 0; i < 12; i++ ) … … 91 98 } 92 99 93 QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(100 QwtDialSimpleNeedle* hand = new QwtDialSimpleNeedle( 94 101 QwtDialSimpleNeedle::Arrow, true, handColor, knobColor ); 95 102 hand->setWidth( width ); 96 103 97 d_hand[i] = NULL;98 setHand( static_cast< Hand>( i ), hand );104 m_hand[i] = NULL; 105 setHand( static_cast< Hand >( i ), hand ); 99 106 } 100 107 } … … 104 111 { 105 112 for ( int i = 0; i < NHands; i++ ) 106 delete d_hand[i];107 } 108 109 /*! 110 Nop method, use setHand() instead 111 \sa setHand() 112 */ 113 void QwtAnalogClock::setNeedle( QwtDialNeedle * )113 delete m_hand[i]; 114 } 115 116 /*! 117 Nop method, use setHand() instead 118 \sa setHand() 119 */ 120 void QwtAnalogClock::setNeedle( QwtDialNeedle* ) 114 121 { 115 122 // no op … … 122 129 \param needle Hand 123 130 \sa hand() 124 */ 125 void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle *needle )131 */ 132 void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle* needle ) 126 133 { 127 134 if ( hand >= 0 && hand < NHands ) 128 135 { 129 delete d_hand[hand];130 d_hand[hand] = needle;131 } 132 } 133 134 /*! 135 \return Clock hand 136 \param hd Specifies the type of hand 137 \sa setHand() 138 */ 139 QwtDialNeedle *QwtAnalogClock::hand( Hand hd )136 delete m_hand[hand]; 137 m_hand[hand] = needle; 138 } 139 } 140 141 /*! 142 \return Clock hand 143 \param hd Specifies the type of hand 144 \sa setHand() 145 */ 146 QwtDialNeedle* QwtAnalogClock::hand( Hand hd ) 140 147 { 141 148 if ( hd < 0 || hd >= NHands ) 142 149 return NULL; 143 150 144 return d_hand[hd];145 } 146 147 /*! 148 \return Clock hand 149 \param hd Specifies the type of hand 150 \sa setHand() 151 */ 152 const QwtDialNeedle *QwtAnalogClock::hand( Hand hd ) const153 { 154 return const_cast<QwtAnalogClock *>( this )->hand( hd );155 } 156 157 /*! 158 \brief Set the current time 159 */ 151 return m_hand[hd]; 152 } 153 154 /*! 155 \return Clock hand 156 \param hd Specifies the type of hand 157 \sa setHand() 158 */ 159 const QwtDialNeedle* QwtAnalogClock::hand( Hand hd ) const 160 { 161 return const_cast< QwtAnalogClock* >( this )->hand( hd ); 162 } 163 164 /*! 165 \brief Set the current time 166 */ 160 167 void QwtAnalogClock::setCurrentTime() 161 168 { … … 164 171 165 172 /*! 166 Set a time 167 \param time Time to display 168 */ 169 void QwtAnalogClock::setTime( const QTime &time )173 Set a time 174 \param time Time to display 175 */ 176 void QwtAnalogClock::setTime( const QTime& time ) 170 177 { 171 178 if ( time.isValid() ) … … 179 186 180 187 /*! 181 \brief Draw the needle 182 183 A clock has no single needle but three hands instead. drawNeedle() 184 translates value() into directions for the hands and calls 185 drawHand(). 186 187 \param painter Painter 188 \param center Center of the clock 189 \param radius Maximum length for the hands 190 \param dir Dummy, not used. 191 \param colorGroup ColorGroup 192 193 \sa drawHand() 194 */ 195 void QwtAnalogClock::drawNeedle( QPainter *painter, const QPointF¢er,196 double radius, double dir, QPalette::ColorGroup colorGroup ) const 197 { 198 Q_UNUSED( dir ); 188 \brief Draw the needle 189 190 A clock has no single needle but three hands instead. drawNeedle() 191 translates value() into directions for the hands and calls 192 drawHand(). 193 194 \param painter Painter 195 \param center Center of the clock 196 \param radius Maximum length for the hands 197 \param direction Dummy, not used. 198 \param colorGroup ColorGroup 199 200 \sa drawHand() 201 */ 202 void QwtAnalogClock::drawNeedle( QPainter* painter, const QPointF& center, 203 double radius, double direction, QPalette::ColorGroup colorGroup ) const 204 { 205 Q_UNUSED( direction ); 199 206 200 207 if ( isValid() ) … … 202 209 const double hours = value() / ( 60.0 * 60.0 ); 203 210 const double minutes = 204 ( value() - qFloor(hours) * 60.0 * 60.0 ) / 60.0;205 const double seconds = value() - qFloor(hours) * 60.0 * 60.0206 - qFloor(minutes) * 60.0;211 ( value() - std::floor(hours) * 60.0 * 60.0 ) / 60.0; 212 const double seconds = value() - std::floor(hours) * 60.0 * 60.0 213 - std::floor(minutes) * 60.0; 207 214 208 215 double angle[NHands]; … … 214 221 { 215 222 const double d = 360.0 - angle[hand] - origin(); 216 drawHand( painter, static_cast< Hand>( hand ),223 drawHand( painter, static_cast< Hand >( hand ), 217 224 center, radius, d, colorGroup ); 218 225 } … … 221 228 222 229 /*! 223 Draw a clock hand 224 225 \param painter Painter 226 \param hd Specify the type of hand 227 \param center Center of the clock 228 \param radius Maximum length for the hands 229 \param direction Direction of the hand in degrees, counter clockwise 230 \param cg ColorGroup 231 */ 232 void QwtAnalogClock::drawHand( QPainter *painter, Hand hd,233 const QPointF ¢er, double radius, double direction,230 Draw a clock hand 231 232 \param painter Painter 233 \param hd Specify the type of hand 234 \param center Center of the clock 235 \param radius Maximum length for the hands 236 \param direction Direction of the hand in degrees, counter clockwise 237 \param cg ColorGroup 238 */ 239 void QwtAnalogClock::drawHand( QPainter* painter, Hand hd, 240 const QPointF& center, double radius, double direction, 234 241 QPalette::ColorGroup cg ) const 235 242 { 236 const QwtDialNeedle *needle = hand( hd );243 const QwtDialNeedle* needle = hand( hd ); 237 244 if ( needle ) 238 245 { … … 243 250 } 244 251 } 252 253 #include "moc_qwt_analog_clock.cpp" -
trunk/BNC/qwt/qwt_analog_clock.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_dial.h" 15 #include "qwt_dial_needle.h" 16 #include <qdatetime.h> 15 16 class QwtDialNeedle; 17 17 18 18 /*! 19 \brief An analog clock 19 \brief An analog clock 20 20 21 \image html analogclock.png 21 \image html analogclock.png 22 22 23 \par Example 24 \code 25 #include <qwt_analog_clock.h>23 \par Example 24 \code 25 #include <qwt_analog_clock.h> 26 26 27 QwtAnalogClock *clock = new QwtAnalogClock(...); 28 clock->scaleDraw()->setPenWidth(3); 29 clock->setLineWidth(6); 30 clock->setFrameShadow(QwtDial::Sunken); 31 clock->setTime(); 27 QwtAnalogClock *clock = new QwtAnalogClock(...); 28 clock->scaleDraw()->setPenWidth(3); 29 clock->setLineWidth(6); 30 clock->setFrameShadow(QwtDial::Sunken); 31 clock->setTime(); 32 32 33 // update the clock every second 34 QTimer *timer = new QTimer(clock); 35 timer->connect(timer, SIGNAL(timeout()), clock, SLOT(setCurrentTime())); 36 timer->start(1000); 33 // update the clock every second 34 QTimer *timer = new QTimer(clock); 35 timer->connect(timer, SIGNAL(timeout()), clock, SLOT(setCurrentTime())); 36 timer->start(1000); 37 37 38 \endcode 38 \endcode 39 39 40 \note The examples/dials example shows how to use QwtAnalogClock. 41 */ 40 \note The examples/dials example shows how to use QwtAnalogClock. 41 */ 42 42 43 class QWT_EXPORT QwtAnalogClock: public QwtDial 43 class QWT_EXPORT QwtAnalogClock : public QwtDial 44 44 { 45 45 Q_OBJECT 46 46 47 public: 47 public: 48 48 /*! 49 49 Hand type 50 50 \sa setHand(), hand() 51 */ 51 */ 52 52 enum Hand 53 53 { … … 68 68 virtual ~QwtAnalogClock(); 69 69 70 void setHand( Hand, QwtDialNeedle * );70 void setHand( Hand, QwtDialNeedle* ); 71 71 72 const QwtDialNeedle *hand( Hand ) const;73 QwtDialNeedle *hand( Hand );72 const QwtDialNeedle* hand( Hand ) const; 73 QwtDialNeedle* hand( Hand ); 74 74 75 public Q_SLOTS: 75 public Q_SLOTS: 76 76 void setCurrentTime(); 77 void setTime( const QTime & );77 void setTime( const QTime& ); 78 78 79 protected: 80 virtual void drawNeedle( QPainter *, const QPointF &, 79 protected: 80 virtual void drawNeedle( QPainter*, const QPointF&, double radius, 81 double direction, QPalette::ColorGroup ) const QWT_OVERRIDE; 82 83 virtual void drawHand( QPainter*, Hand, const QPointF&, 81 84 double radius, double direction, QPalette::ColorGroup ) const; 82 85 83 virtual void drawHand( QPainter *, Hand, const QPointF &, 84 double radius, double direction, QPalette::ColorGroup ) const; 86 private: 87 // use setHand instead 88 void setNeedle( QwtDialNeedle* ); 85 89 86 private: 87 // use setHand instead 88 void setNeedle( QwtDialNeedle * ); 89 90 QwtDialNeedle *d_hand[NHands]; 90 QwtDialNeedle* m_hand[NHands]; 91 91 }; 92 92 -
trunk/BNC/qwt/qwt_arrow_button.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_arrow_button.h" 11 #include "qwt_math.h" 11 #include "qwt.h" 12 12 13 #include <qpainter.h> 13 14 #include <qstyle.h> 14 15 #include <qstyleoption.h> 15 16 #include <qevent.h> 16 #include <qapplication.h>17 17 18 18 static const int MaxNum = 3; … … 22 22 class QwtArrowButton::PrivateData 23 23 { 24 public: 24 public: 25 25 int num; 26 26 Qt::ArrowType arrowType; … … 30 30 { 31 31 QStyleOptionButton option; 32 option.init( btn ); 32 option.initFrom( btn ); 33 33 option.features = QStyleOptionButton::None; 34 34 if ( btn->isFlat() ) … … 49 49 50 50 /*! 51 \param num Number of arrows 52 \param arrowType see Qt::ArrowType in the Qt docs. 53 \param parent Parent widget 54 */ 55 QwtArrowButton::QwtArrowButton( int num, 56 Qt::ArrowType arrowType, QWidget *parent ): 57 QPushButton( parent ) 58 { 59 d_data = new PrivateData; 60 d_data->num = qBound( 1, num, MaxNum ); 61 d_data->arrowType = arrowType; 51 \param num Number of arrows 52 \param arrowType see Qt::ArrowType in the Qt docs. 53 \param parent Parent widget 54 */ 55 QwtArrowButton::QwtArrowButton( int num, Qt::ArrowType arrowType, QWidget* parent ) 56 : QPushButton( parent ) 57 { 58 m_data = new PrivateData; 59 m_data->num = qBound( 1, num, MaxNum ); 60 m_data->arrowType = arrowType; 62 61 63 62 setAutoRepeat( true ); 64 63 setAutoDefault( false ); 65 64 66 switch ( d_data->arrowType )65 switch ( m_data->arrowType ) 67 66 { 68 67 case Qt::LeftArrow: … … 80 79 QwtArrowButton::~QwtArrowButton() 81 80 { 82 delete d_data;83 d_data = NULL;84 } 85 86 /*! 87 \brief The direction of the arrows 88 */ 81 delete m_data; 82 m_data = NULL; 83 } 84 85 /*! 86 \brief The direction of the arrows 87 */ 89 88 Qt::ArrowType QwtArrowButton::arrowType() const 90 89 { 91 return d_data->arrowType;92 } 93 94 /*! 95 \brief The number of arrows 96 */ 90 return m_data->arrowType; 91 } 92 93 /*! 94 \brief The number of arrows 95 */ 97 96 int QwtArrowButton::num() const 98 97 { 99 return d_data->num;100 } 101 102 /*! 103 \return the bounding rectangle for the label 104 */ 98 return m_data->num; 99 } 100 101 /*! 102 \return the bounding rectangle for the label 103 */ 105 104 QRect QwtArrowButton::labelRect() const 106 105 { … … 128 127 Paint event handler 129 128 \param event Paint event 130 */ 131 void QwtArrowButton::paintEvent( QPaintEvent *event )129 */ 130 void QwtArrowButton::paintEvent( QPaintEvent* event ) 132 131 { 133 132 QPushButton::paintEvent( event ); … … 137 136 138 137 /*! 139 \brief Draw the button label 140 141 \param painter Painter 142 \sa The Qt Manual for QPushButton 143 */ 144 void QwtArrowButton::drawButtonLabel( QPainter *painter )145 { 146 const bool isVertical = d_data->arrowType == Qt::UpArrow ||147 d_data->arrowType == Qt::DownArrow;138 \brief Draw the button label 139 140 \param painter Painter 141 \sa The Qt Manual for QPushButton 142 */ 143 void QwtArrowButton::drawButtonLabel( QPainter* painter ) 144 { 145 const bool isVertical = m_data->arrowType == Qt::UpArrow || 146 m_data->arrowType == Qt::DownArrow; 148 147 149 148 const QRect r = labelRect(); … … 162 161 163 162 QRect contentsSize; // aligned rect where to paint all arrows 164 if ( d_data->arrowType == Qt::LeftArrow ||d_data->arrowType == Qt::RightArrow )165 { 166 contentsSize.setWidth( d_data->num * arrow.width()167 + ( d_data->num - 1 ) * Spacing );163 if ( m_data->arrowType == Qt::LeftArrow || m_data->arrowType == Qt::RightArrow ) 164 { 165 contentsSize.setWidth( m_data->num * arrow.width() 166 + ( m_data->num - 1 ) * Spacing ); 168 167 contentsSize.setHeight( arrow.height() ); 169 168 } … … 171 170 { 172 171 contentsSize.setWidth( arrow.width() ); 173 contentsSize.setHeight( d_data->num * arrow.height()174 + ( d_data->num - 1 ) * Spacing );172 contentsSize.setHeight( m_data->num * arrow.height() 173 + ( m_data->num - 1 ) * Spacing ); 175 174 } 176 175 … … 180 179 181 180 painter->save(); 182 for ( int i = 0; i < d_data->num; i++ )183 { 184 drawArrow( painter, arrowRect, d_data->arrowType );181 for ( int i = 0; i < m_data->num; i++ ) 182 { 183 drawArrow( painter, arrowRect, m_data->arrowType ); 185 184 186 185 int dx = 0; … … 199 198 { 200 199 QStyleOptionFocusRect option; 201 option.init( this ); 200 option.initFrom( this ); 202 201 option.backgroundColor = palette().color( QPalette::Window ); 203 202 … … 213 212 \param r Rectangle where to paint the arrow 214 213 \param arrowType Arrow type 215 */ 216 void QwtArrowButton::drawArrow( QPainter *painter,217 const QRect &r, Qt::ArrowType arrowType ) const214 */ 215 void QwtArrowButton::drawArrow( QPainter* painter, 216 const QRect& r, Qt::ArrowType arrowType ) const 218 217 { 219 218 QPolygon pa( 3 ); … … 256 255 257 256 /*! 258 \return a size hint 259 */ 257 \return a size hint 258 */ 260 259 QSize QwtArrowButton::sizeHint() const 261 260 { 262 261 const QSize hint = minimumSizeHint(); 263 return hint.expandedTo( QApplication::globalStrut());264 } 265 266 /*! 267 \brief Return a minimum size hint 268 */ 262 return qwtExpandedToGlobalStrut( hint ); 263 } 264 265 /*! 266 \brief Return a minimum size hint 267 */ 269 268 QSize QwtArrowButton::minimumSizeHint() const 270 269 { … … 274 273 2 * Margin + ( MaxNum - 1 ) * Spacing + MaxNum * asz.width(), 275 274 2 * Margin + asz.height() 276 ); 277 278 if ( d_data->arrowType == Qt::UpArrow ||d_data->arrowType == Qt::DownArrow )275 ); 276 277 if ( m_data->arrowType == Qt::UpArrow || m_data->arrowType == Qt::DownArrow ) 279 278 sz.transpose(); 280 279 281 280 QStyleOption styleOption; 282 styleOption.init( this ); 281 styleOption.initFrom( this ); 283 282 284 283 sz = style()->sizeFromContents( QStyle::CT_PushButton, … … 294 293 \param boundingSize Bounding size 295 294 \return Size of the arrow 296 */ 295 */ 297 296 QSize QwtArrowButton::arrowSize( Qt::ArrowType arrowType, 298 const QSize &boundingSize ) const297 const QSize& boundingSize ) const 299 298 { 300 299 QSize bs = boundingSize; … … 323 322 324 323 /*! 325 \brief autoRepeat for the space keys 326 */ 327 void QwtArrowButton::keyPressEvent( QKeyEvent *event )324 \brief autoRepeat for the space keys 325 */ 326 void QwtArrowButton::keyPressEvent( QKeyEvent* event ) 328 327 { 329 328 if ( event->isAutoRepeat() && event->key() == Qt::Key_Space ) -
trunk/BNC/qwt/qwt_arrow_button.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 16 16 /*! 17 \brief Arrow Button 17 \brief Arrow Button 18 18 19 A push button with one or more filled triangles on its front. 20 An Arrow button can have 1 to 3 arrows in a row, pointing 21 up, down, left or right. 22 */ 19 A push button with one or more filled triangles on its front. 20 An Arrow button can have 1 to 3 arrows in a row, pointing 21 up, down, left or right. 22 */ 23 23 class QWT_EXPORT QwtArrowButton : public QPushButton 24 24 { 25 public: 26 explicit QwtArrowButton ( int num, Qt::ArrowType, QWidget *parent = NULL );25 public: 26 explicit QwtArrowButton ( int num, Qt::ArrowType, QWidget* parent = NULL ); 27 27 virtual ~QwtArrowButton(); 28 28 … … 30 30 int num() const; 31 31 32 virtual QSize sizeHint() const; 33 virtual QSize minimumSizeHint() const; 32 virtual QSize sizeHint() const QWT_OVERRIDE; 33 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 34 34 35 protected: 36 virtual void paintEvent( QPaintEvent *event ); 35 protected: 36 virtual void paintEvent( QPaintEvent*) QWT_OVERRIDE; 37 virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 37 38 38 virtual void drawButtonLabel( QPainter * );39 virtual void drawArrow( QPainter *,40 const QRect &, Qt::ArrowType ) const;39 virtual void drawButtonLabel( QPainter* ); 40 virtual void drawArrow( QPainter*, 41 const QRect&, Qt::ArrowType ) const; 41 42 virtual QRect labelRect() const; 42 43 virtual QSize arrowSize( Qt::ArrowType, 43 const QSize &boundingSize ) const;44 const QSize& boundingSize ) const; 44 45 45 virtual void keyPressEvent( QKeyEvent * ); 46 47 private: 46 private: 48 47 class PrivateData; 49 PrivateData *d_data;48 PrivateData* m_data; 50 49 }; 51 50 -
trunk/BNC/qwt/qwt_clipper.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_clipper.h" 11 11 #include "qwt_point_polar.h" 12 #include "qwt_interval.h" 13 #include "qwt_math.h" 14 15 #include <qpolygon.h> 12 16 #include <qrect.h> 13 #include <string.h> 14 #include <stdlib.h> 15 16 #if QT_VERSION < 0x040601 17 #define qAtan(x) ::atan(x) 18 #endif 17 18 #include <algorithm> 19 19 20 20 namespace QwtClip 21 21 { 22 22 // some templates used for inlining 23 template <class Point, typename T> class LeftEdge; 24 template <class Point, typename T> class RightEdge; 25 template <class Point, typename T> class TopEdge; 26 template <class Point, typename T> class BottomEdge; 27 28 template <class Point> class PointBuffer; 29 } 30 31 template <class Point, typename Value> 23 template< class Point, typename T > class LeftEdge; 24 template< class Point, typename T > class RightEdge; 25 template< class Point, typename T > class TopEdge; 26 template< class Point, typename T > class BottomEdge; 27 } 28 29 template< class Point, typename Value > 32 30 class QwtClip::LeftEdge 33 31 { 34 public: 32 public: 35 33 inline LeftEdge( Value x1, Value, Value, Value ): 36 d_x1( x1 )37 { 38 } 39 40 inline bool isInside( const Point &p ) const41 { 42 return p.x() >= d_x1;43 } 44 45 inline Point intersection( const Point &p1, const Point&p2 ) const34 m_x1( x1 ) 35 { 36 } 37 38 inline bool isInside( const Point& p ) const 39 { 40 return p.x() >= m_x1; 41 } 42 43 inline Point intersection( const Point& p1, const Point& p2 ) const 46 44 { 47 45 double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() ); 48 return Point( d_x1, static_cast< Value >( p2.y() + (d_x1 - p2.x() ) * dy ) );49 } 50 private: 51 const Value d_x1;52 }; 53 54 template <class Point, typename Value>46 return Point( m_x1, static_cast< Value >( p2.y() + ( m_x1 - p2.x() ) * dy ) ); 47 } 48 private: 49 const Value m_x1; 50 }; 51 52 template< class Point, typename Value > 55 53 class QwtClip::RightEdge 56 54 { 57 public: 55 public: 58 56 inline RightEdge( Value, Value x2, Value, Value ): 59 d_x2( x2 )60 { 61 } 62 63 inline bool isInside( const Point &p ) const64 { 65 return p.x() <= d_x2;66 } 67 68 inline Point intersection( const Point &p1, const Point&p2 ) const57 m_x2( x2 ) 58 { 59 } 60 61 inline bool isInside( const Point& p ) const 62 { 63 return p.x() <= m_x2; 64 } 65 66 inline Point intersection( const Point& p1, const Point& p2 ) const 69 67 { 70 68 double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() ); 71 return Point( d_x2, static_cast<Value>( p2.y() + (d_x2 - p2.x() ) * dy ) );72 } 73 74 private: 75 const Value d_x2;76 }; 77 78 template <class Point, typename Value>69 return Point( m_x2, static_cast< Value >( p2.y() + ( m_x2 - p2.x() ) * dy ) ); 70 } 71 72 private: 73 const Value m_x2; 74 }; 75 76 template< class Point, typename Value > 79 77 class QwtClip::TopEdge 80 78 { 81 public: 79 public: 82 80 inline TopEdge( Value, Value, Value y1, Value ): 83 d_y1( y1 )84 { 85 } 86 87 inline bool isInside( const Point &p ) const88 { 89 return p.y() >= d_y1;90 } 91 92 inline Point intersection( const Point &p1, const Point&p2 ) const81 m_y1( y1 ) 82 { 83 } 84 85 inline bool isInside( const Point& p ) const 86 { 87 return p.y() >= m_y1; 88 } 89 90 inline Point intersection( const Point& p1, const Point& p2 ) const 93 91 { 94 92 double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() ); 95 return Point( static_cast< Value>( p2.x() + (d_y1 - p2.y() ) * dx ),d_y1 );96 } 97 98 private: 99 const Value d_y1;100 }; 101 102 template <class Point, typename Value>93 return Point( static_cast< Value >( p2.x() + ( m_y1 - p2.y() ) * dx ), m_y1 ); 94 } 95 96 private: 97 const Value m_y1; 98 }; 99 100 template< class Point, typename Value > 103 101 class QwtClip::BottomEdge 104 102 { 105 public: 103 public: 106 104 inline BottomEdge( Value, Value, Value, Value y2 ): 107 d_y2( y2 )108 { 109 } 110 111 inline bool isInside( const Point &p ) const112 { 113 return p.y() <= d_y2;114 } 115 116 inline Point intersection( const Point &p1, const Point&p2 ) const105 m_y2( y2 ) 106 { 107 } 108 109 inline bool isInside( const Point& p ) const 110 { 111 return p.y() <= m_y2; 112 } 113 114 inline Point intersection( const Point& p1, const Point& p2 ) const 117 115 { 118 116 double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() ); 119 return Point( static_cast<Value>( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 ); 120 } 121 122 private: 123 const Value d_y2; 124 }; 125 126 template<class Point> 127 class QwtClip::PointBuffer 128 { 129 public: 130 PointBuffer( int capacity = 0 ): 131 m_capacity( 0 ), 132 m_size( 0 ), 133 m_buffer( NULL ) 134 { 135 if ( capacity > 0 ) 136 reserve( capacity ); 137 } 138 139 ~PointBuffer() 140 { 141 if ( m_buffer ) 142 ::free( m_buffer ); 143 } 144 145 inline void setPoints( int numPoints, const Point *points ) 146 { 147 reserve( numPoints ); 148 149 m_size = numPoints; 150 ::memcpy( m_buffer, points, m_size * sizeof( Point ) ); 151 } 152 153 inline void reset() 154 { 155 m_size = 0; 156 } 157 158 inline int size() const 159 { 160 return m_size; 161 } 162 163 inline Point *data() const 164 { 165 return m_buffer; 166 } 167 168 inline Point &operator[]( int i ) 169 { 170 return m_buffer[i]; 171 } 172 173 inline const Point &operator[]( int i ) const 174 { 175 return m_buffer[i]; 176 } 177 178 inline void add( const Point &point ) 179 { 180 if ( m_capacity <= m_size ) 181 reserve( m_size + 1 ); 182 183 m_buffer[m_size++] = point; 184 } 185 186 private: 187 inline void reserve( int size ) 188 { 189 if ( m_capacity == 0 ) 190 m_capacity = 1; 191 192 while ( m_capacity < size ) 193 m_capacity *= 2; 194 195 m_buffer = static_cast<Point *>( 196 ::realloc( m_buffer, m_capacity * sizeof( Point ) ) ); 197 } 198 199 int m_capacity; 200 int m_size; 201 Point *m_buffer; 117 return Point( static_cast< Value >( p2.x() + ( m_y2 - p2.y() ) * dx ), m_y2 ); 118 } 119 120 private: 121 const Value m_y2; 202 122 }; 203 123 204 124 using namespace QwtClip; 205 125 206 template <class Polygon, class Rect,class Point,typename T>126 template< class Polygon, class Rect, typename T > 207 127 class QwtPolygonClipper 208 128 { 209 public: 210 QwtPolygonClipper( const Rect &clipRect ): 211 d_clipRect( clipRect ) 212 { 213 } 214 215 Polygon clipPolygon( const Polygon &polygon, bool closePolygon ) const 129 typedef typename Polygon::value_type Point; 130 public: 131 explicit QwtPolygonClipper( const Rect& clipRect ): 132 m_clipRect( clipRect ) 133 { 134 } 135 136 void clipPolygon( Polygon& points1, bool closePolygon ) const 216 137 { 217 138 #if 0 218 if ( d_clipRect.contains( polygon.boundingRect() ) )139 if ( m_clipRect.contains( points1.boundingRect() ) ) 219 140 return polygon; 220 141 #endif 221 142 222 PointBuffer<Point> points1; 223 PointBuffer<Point> points2( qMin( 256, polygon.size() ) ); 224 225 points1.setPoints( polygon.size(), polygon.data() ); 226 227 clipEdge< LeftEdge<Point, T> >( closePolygon, points1, points2 ); 228 clipEdge< RightEdge<Point, T> >( closePolygon, points2, points1 ); 229 clipEdge< TopEdge<Point, T> >( closePolygon, points1, points2 ); 230 clipEdge< BottomEdge<Point, T> >( closePolygon, points2, points1 ); 231 232 Polygon p; 233 p.resize( points1.size() ); 234 ::memcpy( p.data(), points1.data(), points1.size() * sizeof( Point ) ); 235 236 return p; 237 } 238 239 private: 240 template <class Edge> 143 Polygon points2; 144 points2.reserve( qMin( 256, points1.size() ) ); 145 146 clipEdge< LeftEdge< Point, T > >( closePolygon, points1, points2 ); 147 clipEdge< RightEdge< Point, T > >( closePolygon, points2, points1 ); 148 clipEdge< TopEdge< Point, T > >( closePolygon, points1, points2 ); 149 clipEdge< BottomEdge< Point, T > >( closePolygon, points2, points1 ); 150 } 151 152 private: 153 template< class Edge > 241 154 inline void clipEdge( bool closePolygon, 242 PointBuffer<Point> &points, PointBuffer<Point> &clippedPoints ) const243 { 244 clippedPoints. reset();155 const Polygon& points, Polygon& clippedPoints ) const 156 { 157 clippedPoints.clear(); 245 158 246 159 if ( points.size() < 2 ) 247 160 { 248 161 if ( points.size() == 1 ) 249 clippedPoints.add( points[0] ); 162 clippedPoints += points[0]; 163 250 164 return; 251 165 } 252 166 253 const Edge edge( d_clipRect.x(), d_clipRect.x() + d_clipRect.width(), 254 d_clipRect.y(), d_clipRect.y() + d_clipRect.height() ); 255 256 int lastPos, start; 257 if ( closePolygon ) 258 { 259 start = 0; 260 lastPos = points.size() - 1; 167 const Edge edge( m_clipRect.x(), m_clipRect.x() + m_clipRect.width(), 168 m_clipRect.y(), m_clipRect.y() + m_clipRect.height() ); 169 170 if ( !closePolygon ) 171 { 172 const Point& p1 = points.first(); 173 174 if ( edge.isInside( p1 ) ) 175 clippedPoints += p1; 261 176 } 262 177 else 263 178 { 264 start = 1; 265 lastPos = 0; 266 267 if ( edge.isInside( points[0] ) ) 268 clippedPoints.add( points[0] ); 269 } 270 271 const uint nPoints = points.size(); 272 for ( uint i = start; i < nPoints; i++ ) 273 { 274 const Point &p1 = points[i]; 275 const Point &p2 = points[lastPos]; 179 const Point& p1 = points.first(); 180 const Point& p2 = points.last(); 276 181 277 182 if ( edge.isInside( p1 ) ) 278 183 { 279 if ( edge.isInside( p2 ) ) 280 { 281 clippedPoints.add( p1 ); 282 } 283 else 284 { 285 clippedPoints.add( edge.intersection( p1, p2 ) ); 286 clippedPoints.add( p1 ); 287 } 184 if ( !edge.isInside( p2 ) ) 185 clippedPoints += edge.intersection( p1, p2 ); 186 187 clippedPoints += p1; 288 188 } 289 else 189 else if ( edge.isInside( p2 ) ) 290 190 { 291 if ( edge.isInside( p2 ) ) 292 { 293 clippedPoints.add( edge.intersection( p1, p2 ) ); 294 } 191 clippedPoints += edge.intersection( p1, p2 ); 295 192 } 296 lastPos = i; 297 } 298 } 299 300 const Rect d_clipRect; 193 } 194 195 const uint nPoints = points.size(); 196 const Point* p = points.constData(); 197 198 for ( uint i = 1; i < nPoints; i++ ) 199 { 200 const Point& p1 = p[i]; 201 const Point& p2 = p[i - 1]; 202 203 if ( edge.isInside( p1 ) ) 204 { 205 if ( !edge.isInside( p2 ) ) 206 clippedPoints += edge.intersection( p1, p2 ); 207 208 clippedPoints += p1; 209 } 210 else if ( edge.isInside( p2 ) ) 211 { 212 clippedPoints += edge.intersection( p1, p2 ); 213 } 214 } 215 } 216 217 const Rect m_clipRect; 301 218 }; 302 219 303 220 class QwtCircleClipper 304 221 { 305 public: 306 QwtCircleClipper( const QRectF &r );307 QVector<QwtInterval> clipCircle( const QPointF &, double radius ) const;308 309 private: 222 public: 223 explicit QwtCircleClipper( const QRectF& r ); 224 QVector< QwtInterval > clipCircle( const QPointF&, double radius ) const; 225 226 private: 310 227 enum Edge 311 228 { … … 318 235 }; 319 236 320 QList<QPointF> cuttingPoints( 321 Edge, const QPointF &pos, double radius ) const; 322 323 double toAngle( const QPointF &, const QPointF & ) const; 324 325 const QRectF d_rect; 326 }; 327 328 329 QwtCircleClipper::QwtCircleClipper( const QRectF &r ): 330 d_rect( r ) 331 { 332 } 333 334 QVector<QwtInterval> QwtCircleClipper::clipCircle( 335 const QPointF &pos, double radius ) const 336 { 337 QList<QPointF> points; 237 QVector< QPointF > cuttingPoints( 238 Edge, const QPointF& pos, double radius ) const; 239 240 double toAngle( const QPointF&, const QPointF& ) const; 241 242 const QRectF m_rect; 243 }; 244 245 246 QwtCircleClipper::QwtCircleClipper( const QRectF& r ) 247 : m_rect( r ) 248 { 249 } 250 251 QVector< QwtInterval > QwtCircleClipper::clipCircle( 252 const QPointF& pos, double radius ) const 253 { 254 // using QVarLengthArray TODO ... 255 256 QVector< QPointF > points; 338 257 for ( int edge = 0; edge < NEdges; edge++ ) 339 points += cuttingPoints( static_cast< Edge>(edge), pos, radius );340 341 QVector<QwtInterval> intv; 258 points += cuttingPoints( static_cast< Edge >( edge ), pos, radius ); 259 260 QVector< QwtInterval > intv; 342 261 if ( points.size() <= 0 ) 343 262 { 344 263 QRectF cRect( 0, 0, 2 * radius, 2 * radius ); 345 264 cRect.moveCenter( pos ); 346 if ( d_rect.contains( cRect ) )265 if ( m_rect.contains( cRect ) ) 347 266 intv += QwtInterval( 0.0, 2 * M_PI ); 348 267 } 349 268 else 350 269 { 351 QList<double> angles; 270 QVector< double > angles; 271 angles.reserve( points.size() ); 272 352 273 for ( int i = 0; i < points.size(); i++ ) 353 274 angles += toAngle( pos, points[i] ); 354 qSort( angles ); 355 356 const int in = d_rect.contains( qwtPolar2Pos( pos, radius, 275 276 std::sort( angles.begin(), angles.end() ); 277 278 const int in = m_rect.contains( qwtPolar2Pos( pos, radius, 357 279 angles[0] + ( angles[1] - angles[0] ) / 2 ) ); 358 280 281 intv.reserve( angles.size() / 2 ); 359 282 if ( in ) 360 283 { 361 284 for ( int i = 0; i < angles.size() - 1; i += 2 ) 362 intv += QwtInterval( angles[i], angles[i +1] );285 intv += QwtInterval( angles[i], angles[i + 1] ); 363 286 } 364 287 else 365 288 { 366 289 for ( int i = 1; i < angles.size() - 1; i += 2 ) 367 intv += QwtInterval( angles[i], angles[i+1] ); 290 intv += QwtInterval( angles[i], angles[i + 1] ); 291 368 292 intv += QwtInterval( angles.last(), angles.first() ); 369 293 } … … 374 298 375 299 double QwtCircleClipper::toAngle( 376 const QPointF &from, const QPointF&to ) const300 const QPointF& from, const QPointF& to ) const 377 301 { 378 302 if ( from.x() == to.x() ) … … 381 305 const double m = qAbs( ( to.y() - from.y() ) / ( to.x() - from.x() ) ); 382 306 383 double angle = qAtan( m );307 double angle = std::atan( m ); 384 308 if ( to.x() > from.x() ) 385 309 { … … 398 322 } 399 323 400 Q List<QPointF> QwtCircleClipper::cuttingPoints(401 Edge edge, const QPointF &pos, double radius ) const402 { 403 Q List<QPointF> points;324 QVector< QPointF > QwtCircleClipper::cuttingPoints( 325 Edge edge, const QPointF& pos, double radius ) const 326 { 327 QVector< QPointF > points; 404 328 405 329 if ( edge == Left || edge == Right ) 406 330 { 407 const double x = ( edge == Left ) ? d_rect.left() :d_rect.right();331 const double x = ( edge == Left ) ? m_rect.left() : m_rect.right(); 408 332 if ( qAbs( pos.x() - x ) < radius ) 409 333 { 410 const double off = qSqrt( qwtSqr( radius ) - qwtSqr( pos.x() - x ) );334 const double off = std::sqrt( qwtSqr( radius ) - qwtSqr( pos.x() - x ) ); 411 335 const double m_y1 = pos.y() + off; 412 if ( m_y1 >= d_rect.top() && m_y1 <=d_rect.bottom() )336 if ( m_y1 >= m_rect.top() && m_y1 <= m_rect.bottom() ) 413 337 points += QPointF( x, m_y1 ); 414 338 415 339 const double m_y2 = pos.y() - off; 416 if ( m_y2 >= d_rect.top() && m_y2 <=d_rect.bottom() )340 if ( m_y2 >= m_rect.top() && m_y2 <= m_rect.bottom() ) 417 341 points += QPointF( x, m_y2 ); 418 342 } … … 420 344 else 421 345 { 422 const double y = ( edge == Top ) ? d_rect.top() :d_rect.bottom();346 const double y = ( edge == Top ) ? m_rect.top() : m_rect.bottom(); 423 347 if ( qAbs( pos.y() - y ) < radius ) 424 348 { 425 const double off = qSqrt( qwtSqr( radius ) - qwtSqr( pos.y() - y ) );349 const double off = std::sqrt( qwtSqr( radius ) - qwtSqr( pos.y() - y ) ); 426 350 const double x1 = pos.x() + off; 427 if ( x1 >= d_rect.left() && x1 <=d_rect.right() )351 if ( x1 >= m_rect.left() && x1 <= m_rect.right() ) 428 352 points += QPointF( x1, y ); 429 353 430 354 const double m_x2 = pos.x() - off; 431 if ( m_x2 >= d_rect.left() && m_x2 <=d_rect.right() )355 if ( m_x2 >= m_rect.left() && m_x2 <= m_rect.right() ) 432 356 points += QPointF( m_x2, y ); 433 357 } … … 440 364 441 365 \param clipRect Clip rectangle 442 \param polygon Polygon 443 \param closePolygon True, when the polygon is closed 444 445 \return Clipped polygon 446 */ 447 QPolygon QwtClipper::clipPolygon( 448 const QRectF &clipRect, const QPolygon &polygon, bool closePolygon ) 366 \param polygon Polygon IN/OUT 367 \param closePolygon True, when the polygon is closed 368 */ 369 void QwtClipper::clipPolygon( 370 const QRectF& clipRect, QPolygon& polygon, bool closePolygon ) 449 371 { 450 372 const int minX = qCeil( clipRect.left() ); … … 455 377 const QRect r( minX, minY, maxX - minX, maxY - minY ); 456 378 457 QwtPolygonClipper<QPolygon, QRect, QPoint, int> clipper( r ); 458 return clipper.clipPolygon( polygon, closePolygon ); 459 } 379 QwtPolygonClipper< QPolygon, QRect, int > clipper( r ); 380 clipper.clipPolygon( polygon, closePolygon ); 381 } 382 383 /*! 384 Sutherland-Hodgman polygon clipping 385 386 \param clipRect Clip rectangle 387 \param polygon Polygon IN/OUT 388 \param closePolygon True, when the polygon is closed 389 */ 390 void QwtClipper::clipPolygon( 391 const QRect& clipRect, QPolygon& polygon, bool closePolygon ) 392 { 393 QwtPolygonClipper< QPolygon, QRect, int > clipper( clipRect ); 394 clipper.clipPolygon( polygon, closePolygon ); 395 } 396 397 /*! 398 Sutherland-Hodgman polygon clipping 399 400 \param clipRect Clip rectangle 401 \param polygon Polygon IN/OUT 402 \param closePolygon True, when the polygon is closed 403 */ 404 void QwtClipper::clipPolygonF( 405 const QRectF& clipRect, QPolygonF& polygon, bool closePolygon ) 406 { 407 QwtPolygonClipper< QPolygonF, QRectF, double > clipper( clipRect ); 408 clipper.clipPolygon( polygon, closePolygon ); 409 } 410 460 411 /*! 461 412 Sutherland-Hodgman polygon clipping … … 466 417 467 418 \return Clipped polygon 468 */ 469 QPolygon QwtClipper::clipPolygon( 470 const QRect &clipRect, const QPolygon &polygon, bool closePolygon ) 471 { 472 QwtPolygonClipper<QPolygon, QRect, QPoint, int> clipper( clipRect ); 473 return clipper.clipPolygon( polygon, closePolygon ); 474 } 475 419 */ 420 QPolygon QwtClipper::clippedPolygon( 421 const QRectF& clipRect, const QPolygon& polygon, bool closePolygon ) 422 { 423 QPolygon points( polygon ); 424 clipPolygon( clipRect, points, closePolygon ); 425 426 return points; 427 } 476 428 /*! 477 429 Sutherland-Hodgman polygon clipping … … 482 434 483 435 \return Clipped polygon 484 */ 485 QPolygonF QwtClipper::clipPolygonF( 486 const QRectF &clipRect, const QPolygonF &polygon, bool closePolygon ) 487 { 488 QwtPolygonClipper<QPolygonF, QRectF, QPointF, double> clipper( clipRect ); 489 return clipper.clipPolygon( polygon, closePolygon ); 436 */ 437 QPolygon QwtClipper::clippedPolygon( 438 const QRect& clipRect, const QPolygon& polygon, bool closePolygon ) 439 { 440 QPolygon points( polygon ); 441 clipPolygon( clipRect, points, closePolygon ); 442 443 return points; 444 } 445 446 /*! 447 Sutherland-Hodgman polygon clipping 448 449 \param clipRect Clip rectangle 450 \param polygon Polygon 451 \param closePolygon True, when the polygon is closed 452 453 \return Clipped polygon 454 */ 455 QPolygonF QwtClipper::clippedPolygonF( 456 const QRectF& clipRect, const QPolygonF& polygon, bool closePolygon ) 457 { 458 QPolygonF points( polygon ); 459 clipPolygonF( clipRect, points, closePolygon ); 460 461 return points; 490 462 } 491 463 … … 502 474 503 475 \return Arcs of the circle 504 */ 505 QVector<QwtInterval> QwtClipper::clipCircle( const QRectF &clipRect,506 const QPointF ¢er, double radius )476 */ 477 QVector< QwtInterval > QwtClipper::clipCircle( const QRectF& clipRect, 478 const QPointF& center, double radius ) 507 479 { 508 480 QwtCircleClipper clipper( clipRect ); -
trunk/BNC/qwt/qwt_clipper.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h"15 #include <qpolygon.h>16 #include <qvector.h>17 14 15 class QwtInterval; 16 class QPointF; 18 17 class QRect; 19 18 class QRectF; 19 class QPolygon; 20 class QPolygonF; 21 22 #if QT_VERSION < 0x060000 23 template< typename T > class QVector; 24 #endif 20 25 21 26 /*! 22 \brief Some clipping algorithms 23 */ 27 \brief Some clipping algorithms 28 */ 24 29 25 class QWT_EXPORTQwtClipper30 namespace QwtClipper 26 31 { 27 public: 28 static QPolygon clipPolygon( const QRect &, 29 const QPolygon &, bool closePolygon = false ); 30 static QPolygon clipPolygon( const QRectF &, 31 const QPolygon &, bool closePolygon = false ); 32 QWT_EXPORT void clipPolygon( const QRect&, 33 QPolygon&, bool closePolygon = false ); 32 34 33 static QPolygonFclipPolygonF( const QRectF&,34 const QPolygonF&, bool closePolygon = false );35 QWT_EXPORT void clipPolygon( const QRectF&, 36 QPolygon&, bool closePolygon = false ); 35 37 36 static QVector<QwtInterval> clipCircle( 37 const QRectF &, const QPointF &, double radius ); 38 QWT_EXPORT void clipPolygonF( const QRectF&, 39 QPolygonF&, bool closePolygon = false ); 40 41 QWT_EXPORT QPolygon clippedPolygon( const QRect&, 42 const QPolygon&, bool closePolygon = false ); 43 44 QWT_EXPORT QPolygon clippedPolygon( const QRectF&, 45 const QPolygon&, bool closePolygon = false ); 46 47 QWT_EXPORT QPolygonF clippedPolygonF( const QRectF&, 48 const QPolygonF&, bool closePolygon = false ); 49 50 QWT_EXPORT QVector< QwtInterval > clipCircle( 51 const QRectF&, const QPointF&, double radius ); 38 52 }; 39 53 -
trunk/BNC/qwt/qwt_color_map.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_color_map.h" 11 #include "qwt_math.h"12 11 #include "qwt_interval.h" 13 #include <qnumeric.h> 12 13 #include <qvector.h> 14 15 static inline QRgb qwtHsvToRgb( int h, int s, int v, int a ) 16 { 17 #if 0 18 return QColor::fromHsv( h, s, v, a ).rgb(); 19 #else 20 21 const double vs = v * s / 255.0; 22 const int p = v - qRound( vs ); 23 24 switch( h / 60 ) 25 { 26 case 0: 27 { 28 const double r = ( 60 - h ) / 60.0; 29 return qRgba( v, v - qRound( r * vs ), p, a ); 30 } 31 case 1: 32 { 33 const double r = ( h - 60 ) / 60.0; 34 return qRgba( v - qRound( r * vs ), v, p, a ); 35 } 36 case 2: 37 { 38 const double r = ( 180 - h ) / 60.0; 39 return qRgba( p, v, v - qRound( r * vs ), a ); 40 } 41 case 3: 42 { 43 const double r = ( h - 180 ) / 60.0; 44 return qRgba( p, v - qRound( r * vs ), v, a ); 45 } 46 case 4: 47 { 48 const double r = ( 300 - h ) / 60.0; 49 return qRgba( v - qRound( r * vs ), p, v, a ); 50 } 51 case 5: 52 default: 53 { 54 const double r = ( h - 300 ) / 60.0; 55 return qRgba( v, p, v - qRound( r * vs ), a ); 56 } 57 } 58 #endif 59 } 14 60 15 61 class QwtLinearColorMap::ColorStops 16 62 { 17 public: 63 public: 18 64 ColorStops(): 19 d_doAlpha( false )20 { 21 d_stops.reserve( 256 );22 } 23 24 void insert( double pos, const QColor &color );65 m_doAlpha( false ) 66 { 67 m_stops.reserve( 256 ); 68 } 69 70 void insert( double pos, const QColor& color ); 25 71 QRgb rgb( QwtLinearColorMap::Mode, double pos ) const; 26 72 27 QVector< double> stops() const;28 29 private: 73 QVector< double > stops() const; 74 75 private: 30 76 31 77 class ColorStop 32 78 { 33 public: 79 public: 34 80 ColorStop(): 35 81 pos( 0.0 ), … … 38 84 }; 39 85 40 ColorStop( double p, const QColor &c ):86 ColorStop( double p, const QColor& c ): 41 87 pos( p ), 42 88 rgb( c.rgba() ) … … 48 94 49 95 /* 50 when mapping a value to rgb we will have to calcu alate:96 when mapping a value to rgb we will have to calculate: 51 97 - const int v = int( ( s1.v0 + ratio * s1.vStep ) + 0.5 ); 52 98 … … 62 108 } 63 109 64 void updateSteps( const ColorStop &nextStop )110 void updateSteps( const ColorStop& nextStop ) 65 111 { 66 112 rStep = nextStop.r - r; … … 82 128 83 129 inline int findUpper( double pos ) const; 84 QVector<ColorStop > d_stops;85 bool d_doAlpha;130 QVector< ColorStop > m_stops; 131 bool m_doAlpha; 86 132 }; 87 133 88 void QwtLinearColorMap::ColorStops::insert( double pos, const QColor &color )134 void QwtLinearColorMap::ColorStops::insert( double pos, const QColor& color ) 89 135 { 90 136 // Lookups need to be very fast, insertions are not so important. … … 95 141 96 142 int index; 97 if ( d_stops.size() == 0 )143 if ( m_stops.size() == 0 ) 98 144 { 99 145 index = 0; 100 d_stops.resize( 1 );146 m_stops.resize( 1 ); 101 147 } 102 148 else 103 149 { 104 150 index = findUpper( pos ); 105 if ( index == d_stops.size() ||106 qAbs( d_stops[index].pos - pos ) >= 0.001 )107 { 108 d_stops.resize(d_stops.size() + 1 );109 for ( int i = d_stops.size() - 1; i > index; i-- )110 d_stops[i] =d_stops[i-1];111 } 112 } 113 114 d_stops[index] = ColorStop( pos, color );151 if ( index == m_stops.size() || 152 qAbs( m_stops[index].pos - pos ) >= 0.001 ) 153 { 154 m_stops.resize( m_stops.size() + 1 ); 155 for ( int i = m_stops.size() - 1; i > index; i-- ) 156 m_stops[i] = m_stops[i - 1]; 157 } 158 } 159 160 m_stops[index] = ColorStop( pos, color ); 115 161 if ( color.alpha() != 255 ) 116 d_doAlpha = true;162 m_doAlpha = true; 117 163 118 164 if ( index > 0 ) 119 d_stops[index-1].updateSteps(d_stops[index] );120 121 if ( index < d_stops.size() - 1 )122 d_stops[index].updateSteps(d_stops[index+1] );123 } 124 125 inline QVector< double> QwtLinearColorMap::ColorStops::stops() const126 { 127 QVector< double> positions(d_stops.size() );128 for ( int i = 0; i < d_stops.size(); i++ )129 positions[i] = d_stops[i].pos;165 m_stops[index - 1].updateSteps( m_stops[index] ); 166 167 if ( index < m_stops.size() - 1 ) 168 m_stops[index].updateSteps( m_stops[index + 1] ); 169 } 170 171 inline QVector< double > QwtLinearColorMap::ColorStops::stops() const 172 { 173 QVector< double > positions( m_stops.size() ); 174 for ( int i = 0; i < m_stops.size(); i++ ) 175 positions[i] = m_stops[i].pos; 130 176 return positions; 131 177 } … … 134 180 { 135 181 int index = 0; 136 int n = d_stops.size();137 138 const ColorStop *stops =d_stops.data();182 int n = m_stops.size(); 183 184 const ColorStop* stops = m_stops.data(); 139 185 140 186 while ( n > 0 ) … … 159 205 { 160 206 if ( pos <= 0.0 ) 161 return d_stops[0].rgb;207 return m_stops[0].rgb; 162 208 if ( pos >= 1.0 ) 163 return d_stops[d_stops.size() - 1 ].rgb;209 return m_stops[ m_stops.size() - 1 ].rgb; 164 210 165 211 const int index = findUpper( pos ); 166 212 if ( mode == FixedColors ) 167 213 { 168 return d_stops[index-1].rgb;214 return m_stops[index - 1].rgb; 169 215 } 170 216 else 171 217 { 172 const ColorStop &s1 = d_stops[index-1];218 const ColorStop& s1 = m_stops[index - 1]; 173 219 174 220 const double ratio = ( pos - s1.pos ) / ( s1.posStep ); … … 178 224 const int b = int( s1.b0 + ratio * s1.bStep ); 179 225 180 if ( d_doAlpha )226 if ( m_doAlpha ) 181 227 { 182 228 if ( s1.aStep ) … … 197 243 } 198 244 199 //! Constructor 200 QwtColorMap::QwtColorMap( Format format ): 201 d_format( format ) 245 /*! 246 Constructor 247 \param format Format of the color map 248 */ 249 QwtColorMap::QwtColorMap( Format format ) 250 : m_format( format ) 202 251 { 203 252 } … … 209 258 210 259 /*! 260 Set the format of the color map 261 262 \param format Format of the color map 263 */ 264 void QwtColorMap::setFormat( Format format ) 265 { 266 m_format = format; 267 } 268 269 /*! 270 \brief Map a value of a given interval into a color index 271 272 \param numColors Number of colors 273 \param interval Range for all values 274 \param value Value to map into a color index 275 276 \return Index, between 0 and numColors - 1, or -1 for an invalid value 277 */ 278 uint QwtColorMap::colorIndex( int numColors, 279 const QwtInterval& interval, double value ) const 280 { 281 const double width = interval.width(); 282 if ( width <= 0.0 ) 283 return 0; 284 285 if ( value <= interval.minValue() ) 286 return 0; 287 288 const int maxIndex = numColors - 1; 289 if ( value >= interval.maxValue() ) 290 return maxIndex; 291 292 const double v = maxIndex * ( ( value - interval.minValue() ) / width ); 293 return static_cast< unsigned int >( v + 0.5 ); 294 } 295 296 /*! 211 297 Build and return a color map of 256 colors 212 298 … … 214 300 with using colorIndex(). 215 301 216 \param interval Range for the values217 302 \return A color table, that can be used for a QImage 218 */ 219 QVector<QRgb> QwtColorMap::colorTable( const QwtInterval &interval ) const 220 { 221 QVector<QRgb> table( 256 ); 222 223 if ( interval.isValid() ) 224 { 225 const double step = interval.width() / ( table.size() - 1 ); 226 for ( int i = 0; i < table.size(); i++ ) 227 table[i] = rgb( interval, interval.minValue() + step * i ); 228 } 303 */ 304 QVector< QRgb > QwtColorMap::colorTable256() const 305 { 306 QVector< QRgb > table( 256 ); 307 308 const QwtInterval interval( 0, 256 ); 309 310 for ( int i = 0; i < 256; i++ ) 311 table[i] = rgb( interval, i ); 229 312 230 313 return table; 231 314 } 232 315 316 /*! 317 Build and return a color map of arbitrary number of colors 318 319 The color table is needed for rendering indexed images in combination 320 with using colorIndex(). 321 322 \param numColors Number of colors 323 \return A color table 324 */ 325 QVector< QRgb > QwtColorMap::colorTable( int numColors ) const 326 { 327 QVector< QRgb > table( numColors ); 328 329 const QwtInterval interval( 0.0, 1.0 ); 330 331 const double step = 1.0 / ( numColors - 1 ); 332 for ( int i = 0; i < numColors; i++ ) 333 table[i] = rgb( interval, step * i ); 334 335 return table; 336 } 337 233 338 class QwtLinearColorMap::PrivateData 234 339 { 235 public: 340 public: 236 341 ColorStops colorStops; 237 342 QwtLinearColorMap::Mode mode; … … 243 348 244 349 \param format Preferred format of the color map 245 */ 350 */ 246 351 QwtLinearColorMap::QwtLinearColorMap( QwtColorMap::Format format ): 247 352 QwtColorMap( format ) 248 353 { 249 d_data = new PrivateData;250 d_data->mode = ScaledColors;354 m_data = new PrivateData; 355 m_data->mode = ScaledColors; 251 356 252 357 setColorInterval( Qt::blue, Qt::yellow ); … … 259 364 \param color2 Color used for the maximum value of the value interval 260 365 \param format Preferred format for the color map 261 */ 262 QwtLinearColorMap::QwtLinearColorMap( const QColor &color1,263 const QColor &color2, QwtColorMap::Format format ):264 QwtColorMap( format ) 265 { 266 d_data = new PrivateData;267 d_data->mode = ScaledColors;366 */ 367 QwtLinearColorMap::QwtLinearColorMap( const QColor& color1, 368 const QColor& color2, QwtColorMap::Format format ) 369 : QwtColorMap( format ) 370 { 371 m_data = new PrivateData; 372 m_data->mode = ScaledColors; 268 373 setColorInterval( color1, color2 ); 269 374 } … … 272 377 QwtLinearColorMap::~QwtLinearColorMap() 273 378 { 274 delete d_data;379 delete m_data; 275 380 } 276 381 … … 283 388 284 389 \sa mode() 285 */ 390 */ 286 391 void QwtLinearColorMap::setMode( Mode mode ) 287 392 { 288 d_data->mode = mode;393 m_data->mode = mode; 289 394 } 290 395 … … 292 397 \return Mode of the color map 293 398 \sa setMode() 294 */ 399 */ 295 400 QwtLinearColorMap::Mode QwtLinearColorMap::mode() const 296 401 { 297 return d_data->mode;402 return m_data->mode; 298 403 } 299 404 … … 307 412 308 413 \sa color1(), color2() 309 */ 414 */ 310 415 void QwtLinearColorMap::setColorInterval( 311 const QColor &color1, const QColor&color2 )312 { 313 d_data->colorStops = ColorStops();314 d_data->colorStops.insert( 0.0, color1 );315 d_data->colorStops.insert( 1.0, color2 );416 const QColor& color1, const QColor& color2 ) 417 { 418 m_data->colorStops = ColorStops(); 419 m_data->colorStops.insert( 0.0, color1 ); 420 m_data->colorStops.insert( 1.0, color2 ); 316 421 } 317 422 … … 325 430 \param value Value between [0.0, 1.0] 326 431 \param color Color stop 327 */ 432 */ 328 433 void QwtLinearColorMap::addColorStop( double value, const QColor& color ) 329 434 { 330 435 if ( value >= 0.0 && value <= 1.0 ) 331 d_data->colorStops.insert( value, color );436 m_data->colorStops.insert( value, color ); 332 437 } 333 438 334 439 /*! 335 440 \return Positions of color stops in increasing order 336 */ 337 QVector< double> QwtLinearColorMap::colorStops() const338 { 339 return d_data->colorStops.stops();340 } 341 342 /*! 343 \return the first color of the color range 344 \sa setColorInterval() 345 */ 441 */ 442 QVector< double > QwtLinearColorMap::colorStops() const 443 { 444 return m_data->colorStops.stops(); 445 } 446 447 /*! 448 \return the first color of the color range 449 \sa setColorInterval() 450 */ 346 451 QColor QwtLinearColorMap::color1() const 347 452 { 348 return QColor::fromRgba( d_data->colorStops.rgb(d_data->mode, 0.0 ) );349 } 350 351 /*! 352 \return the second color of the color range 353 \sa setColorInterval() 354 */ 453 return QColor::fromRgba( m_data->colorStops.rgb( m_data->mode, 0.0 ) ); 454 } 455 456 /*! 457 \return the second color of the color range 458 \sa setColorInterval() 459 */ 355 460 QColor QwtLinearColorMap::color2() const 356 461 { 357 return QColor::fromRgba( d_data->colorStops.rgb(d_data->mode, 1.0 ) );358 } 359 360 /*! 361 Map a value of a given interval into a RGB value 362 363 \param interval Range for all values 364 \param value Value to map into a RGB value 365 366 \return RGB value for value 367 */ 462 return QColor::fromRgba( m_data->colorStops.rgb( m_data->mode, 1.0 ) ); 463 } 464 465 /*! 466 Map a value of a given interval into a RGB value 467 468 \param interval Range for all values 469 \param value Value to map into a RGB value 470 471 \return RGB value for value 472 */ 368 473 QRgb QwtLinearColorMap::rgb( 369 const QwtInterval &interval, double value ) const 370 { 371 if ( qIsNaN(value) ) 372 return 0u; 373 474 const QwtInterval& interval, double value ) const 475 { 374 476 const double width = interval.width(); 375 477 if ( width <= 0.0 ) … … 377 479 378 480 const double ratio = ( value - interval.minValue() ) / width; 379 return d_data->colorStops.rgb( d_data->mode, ratio ); 380 } 381 382 /*! 383 \brief Map a value of a given interval into a color index 384 385 \param interval Range for all values 386 \param value Value to map into a color index 387 388 \return Index, between 0 and 255 389 */ 390 unsigned char QwtLinearColorMap::colorIndex( 391 const QwtInterval &interval, double value ) const 481 return m_data->colorStops.rgb( m_data->mode, ratio ); 482 } 483 484 /*! 485 \brief Map a value of a given interval into a color index 486 487 \param numColors Size of the color table 488 \param interval Range for all values 489 \param value Value to map into a color index 490 491 \return Index, between 0 and 255 492 \note NaN values are mapped to 0 493 */ 494 uint QwtLinearColorMap::colorIndex( int numColors, 495 const QwtInterval& interval, double value ) const 392 496 { 393 497 const double width = interval.width(); 394 395 if ( qIsNaN(value) || width <= 0.0 || value <= interval.minValue() ) 498 if ( width <= 0.0 ) 396 499 return 0; 397 500 501 if ( value <= interval.minValue() ) 502 return 0; 503 398 504 if ( value >= interval.maxValue() ) 399 return 255; 400 401 const double ratio = ( value - interval.minValue() ) / width; 402 403 unsigned char index; 404 if ( d_data->mode == FixedColors ) 405 index = static_cast<unsigned char>( ratio * 255 ); // always floor 406 else 407 index = static_cast<unsigned char>( ratio * 255 + 0.5 ); 408 409 return index; 505 return numColors - 1; 506 507 const double v = ( numColors - 1 ) * ( value - interval.minValue() ) / width; 508 return static_cast< unsigned int >( ( m_data->mode == FixedColors ) ? v : v + 0.5 ); 410 509 } 411 510 412 511 class QwtAlphaColorMap::PrivateData 413 512 { 414 public: 513 public: 514 PrivateData() 515 : alpha1(0) 516 , alpha2(255) 517 { 518 } 519 520 int alpha1, alpha2; 521 415 522 QColor color; 416 523 QRgb rgb; 524 525 QRgb rgbMin; 417 526 QRgb rgbMax; 418 527 }; … … 420 529 421 530 /*! 422 Constructor 531 \brief Constructor 532 533 The alpha interval is initialized by 0 to 255. 534 423 535 \param color Color of the map 424 */ 425 QwtAlphaColorMap::QwtAlphaColorMap( const QColor &color ): 426 QwtColorMap( QwtColorMap::RGB ) 427 { 428 d_data = new PrivateData; 536 537 \sa setColor(), setAlphaInterval() 538 */ 539 QwtAlphaColorMap::QwtAlphaColorMap( const QColor& color ) 540 : QwtColorMap( QwtColorMap::RGB ) 541 { 542 m_data = new PrivateData; 429 543 setColor( color ); 430 544 } … … 433 547 QwtAlphaColorMap::~QwtAlphaColorMap() 434 548 { 435 delete d_data;549 delete m_data; 436 550 } 437 551 … … 441 555 \param color Color 442 556 \sa color() 443 */ 444 void QwtAlphaColorMap::setColor( const QColor &color ) 445 { 446 d_data->color = color; 447 d_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 ); 448 d_data->rgbMax = d_data->rgb | ( 255 << 24 ); 449 } 450 451 /*! 452 \return the color 453 \sa setColor() 454 */ 557 */ 558 void QwtAlphaColorMap::setColor( const QColor& color ) 559 { 560 m_data->color = color; 561 m_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 ); 562 563 m_data->rgbMin = m_data->rgb | ( m_data->alpha1 << 24 ); 564 m_data->rgbMax = m_data->rgb | ( m_data->alpha2 << 24 ); 565 } 566 567 /*! 568 \return the color 569 \sa setColor() 570 */ 455 571 QColor QwtAlphaColorMap::color() const 456 572 { 457 return d_data->color; 458 } 459 460 /*! 461 \brief Map a value of a given interval into a alpha value 462 463 alpha := (value - interval.minValue()) / interval.width(); 464 465 \param interval Range for all values 466 \param value Value to map into a RGB value 467 \return RGB value, with an alpha value 468 */ 469 QRgb QwtAlphaColorMap::rgb( const QwtInterval &interval, double value ) const 470 { 471 if ( qIsNaN(value) ) 472 return 0u; 473 573 return m_data->color; 574 } 575 576 /*! 577 Set the interval for the alpha coordinate 578 579 alpha1/alpha2 need to be in the range 0 to 255, 580 where 255 means opaque and 0 means transparent. 581 582 \param alpha1 First alpha coordinate 583 \param alpha2 Second alpha coordinate 584 585 \sa alpha1(), alpha2() 586 */ 587 void QwtAlphaColorMap::setAlphaInterval( int alpha1, int alpha2 ) 588 { 589 m_data->alpha1 = qBound( 0, alpha1, 255 ); 590 m_data->alpha2 = qBound( 0, alpha2, 255 ); 591 592 m_data->rgbMin = m_data->rgb | ( alpha1 << 24 ); 593 m_data->rgbMax = m_data->rgb | ( alpha2 << 24 ); 594 } 595 596 /*! 597 \return First alpha coordinate 598 \sa setAlphaInterval() 599 */ 600 int QwtAlphaColorMap::alpha1() const 601 { 602 return m_data->alpha1; 603 } 604 605 /*! 606 \return Second alpha coordinate 607 \sa setAlphaInterval() 608 */ 609 int QwtAlphaColorMap::alpha2() const 610 { 611 return m_data->alpha2; 612 } 613 614 /*! 615 \brief Map a value of a given interval into a alpha value 616 617 \param interval Range for all values 618 \param value Value to map into a RGB value 619 620 \return RGB value, with an alpha value 621 */ 622 QRgb QwtAlphaColorMap::rgb( const QwtInterval& interval, double value ) const 623 { 474 624 const double width = interval.width(); 475 625 if ( width <= 0.0 ) … … 477 627 478 628 if ( value <= interval.minValue() ) 479 return d_data->rgb;629 return m_data->rgb; 480 630 481 631 if ( value >= interval.maxValue() ) 482 return d_data->rgbMax;632 return m_data->rgbMax; 483 633 484 634 const double ratio = ( value - interval.minValue() ) / width; 485 return d_data->rgb | ( qRound( 255 * ratio ) << 24 ); 486 } 487 488 /*! 489 Dummy function, needed to be implemented as it is pure virtual 490 in QwtColorMap. Color indices make no sense in combination with 491 an alpha channel. 492 493 \return Always 0 494 */ 495 unsigned char QwtAlphaColorMap::colorIndex( 496 const QwtInterval &, double ) const 497 { 498 return 0; 499 } 635 const int alpha = m_data->alpha1 + qRound( ratio * ( m_data->alpha2 - m_data->alpha1 ) ); 636 637 return m_data->rgb | ( alpha << 24 ); 638 } 639 640 class QwtHueColorMap::PrivateData 641 { 642 public: 643 PrivateData(); 644 645 void updateTable(); 646 647 int hue1, hue2; 648 int saturation; 649 int value; 650 int alpha; 651 652 QRgb rgbMin; 653 QRgb rgbMax; 654 655 QRgb rgbTable[360]; 656 }; 657 658 QwtHueColorMap::PrivateData::PrivateData() 659 : hue1(0) 660 , hue2(359) 661 , saturation(255) 662 , value(255) 663 , alpha(255) 664 { 665 updateTable(); 666 } 667 668 void QwtHueColorMap::PrivateData::updateTable() 669 { 670 const int p = qRound( value * ( 255 - saturation ) / 255.0 ); 671 const double vs = value * saturation / 255.0; 672 673 for ( int i = 0; i < 60; i++ ) 674 { 675 const double r = ( 60 - i ) / 60.0; 676 rgbTable[i] = qRgba( value, qRound( value - r * vs ), p, alpha ); 677 } 678 679 for ( int i = 60; i < 120; i++ ) 680 { 681 const double r = ( i - 60 ) / 60.0; 682 rgbTable[i] = qRgba( qRound( value - r * vs ), value, p, alpha ); 683 } 684 685 for ( int i = 120; i < 180; i++ ) 686 { 687 const double r = ( 180 - i ) / 60.0; 688 rgbTable[i] = qRgba( p, value, qRound( value - r * vs ), alpha ); 689 } 690 691 for ( int i = 180; i < 240; i++ ) 692 { 693 const double r = ( i - 180 ) / 60.0; 694 rgbTable[i] = qRgba( p, qRound( value - r * vs ), value, alpha ); 695 } 696 697 for ( int i = 240; i < 300; i++ ) 698 { 699 const double r = ( 300 - i ) / 60.0; 700 rgbTable[i] = qRgba( qRound( value - r * vs ), p, value, alpha ); 701 } 702 703 for ( int i = 300; i < 360; i++ ) 704 { 705 const double r = ( i - 300 ) / 60.0; 706 rgbTable[i] = qRgba( value, p, qRound( value - r * vs ), alpha ); 707 } 708 709 rgbMin = rgbTable[ hue1 % 360 ]; 710 rgbMax = rgbTable[ hue2 % 360 ]; 711 } 712 713 /*! 714 \brief Constructor 715 716 The hue interval is initialized by 0 to 359. All other coordinates 717 are set to 255. 718 719 \param format Format of the color map 720 721 \sa setHueInterval(), setSaturation(), setValue(), setValue() 722 */ 723 QwtHueColorMap::QwtHueColorMap( QwtColorMap::Format format ) 724 : QwtColorMap( format ) 725 { 726 m_data = new PrivateData; 727 } 728 729 //! Destructor 730 QwtHueColorMap::~QwtHueColorMap() 731 { 732 delete m_data; 733 } 734 735 /*! 736 Set the interval for the hue coordinate 737 738 hue1/hue2 need to be positive number and can be > 360 to define cycles. 739 F.e. 420 to 240 defines a map yellow/red/magenta/blue. 740 741 \param hue1 First hue coordinate 742 \param hue2 Second hue coordinate 743 744 \sa hue1(), hue2() 745 */ 746 void QwtHueColorMap::setHueInterval( int hue1, int hue2 ) 747 { 748 m_data->hue1 = qMax( hue1, 0 ); 749 m_data->hue2 = qMax( hue2, 0 ); 750 751 m_data->rgbMin = m_data->rgbTable[ hue1 % 360 ]; 752 m_data->rgbMax = m_data->rgbTable[ hue2 % 360 ]; 753 } 754 755 /*! 756 \brief Set the the saturation coordinate 757 758 saturation needs to be in the range 0 to 255, 759 760 \param saturation Saturation coordinate 761 762 \sa saturation() 763 */ 764 void QwtHueColorMap::setSaturation( int saturation ) 765 { 766 saturation = qBound( 0, saturation, 255 ); 767 768 if ( saturation != m_data->saturation ) 769 { 770 m_data->saturation = saturation; 771 m_data->updateTable(); 772 } 773 } 774 775 /*! 776 \brief Set the the value coordinate 777 778 value needs to be in the range 0 to 255, 779 780 \param value Value coordinate 781 782 \sa value() 783 */ 784 void QwtHueColorMap::setValue( int value ) 785 { 786 value = qBound( 0, value, 255 ); 787 788 if ( value != m_data->value ) 789 { 790 m_data->value = value; 791 m_data->updateTable(); 792 } 793 } 794 795 /*! 796 \brief Set the the alpha coordinate 797 798 alpha needs to be in the range 0 to 255, 799 where 255 means opaque and 0 means transparent. 800 801 \param alpha Alpha coordinate 802 803 \sa alpha() 804 */ 805 void QwtHueColorMap::setAlpha( int alpha ) 806 { 807 alpha = qBound( 0, alpha, 255 ); 808 809 if ( alpha != m_data->alpha ) 810 { 811 m_data->alpha = alpha; 812 m_data->updateTable(); 813 } 814 } 815 816 /*! 817 \return First hue coordinate 818 \sa setHueInterval() 819 */ 820 int QwtHueColorMap::hue1() const 821 { 822 return m_data->hue1; 823 } 824 825 /*! 826 \return Second hue coordinate 827 \sa setHueInterval() 828 */ 829 int QwtHueColorMap::hue2() const 830 { 831 return m_data->hue2; 832 } 833 834 /*! 835 \return Saturation coordinate 836 \sa setSaturation() 837 */ 838 int QwtHueColorMap::saturation() const 839 { 840 return m_data->saturation; 841 } 842 843 /*! 844 \return Value coordinate 845 \sa setValue() 846 */ 847 int QwtHueColorMap::value() const 848 { 849 return m_data->value; 850 } 851 852 /*! 853 \return Alpha coordinate 854 \sa setAlpha() 855 */ 856 int QwtHueColorMap::alpha() const 857 { 858 return m_data->alpha; 859 } 860 861 /*! 862 Map a value of a given interval into a RGB value 863 864 \param interval Range for all values 865 \param value Value to map into a RGB value 866 867 \return RGB value for value 868 */ 869 QRgb QwtHueColorMap::rgb( const QwtInterval& interval, double value ) const 870 { 871 const double width = interval.width(); 872 if ( width <= 0 ) 873 return 0u; 874 875 if ( value <= interval.minValue() ) 876 return m_data->rgbMin; 877 878 if ( value >= interval.maxValue() ) 879 return m_data->rgbMax; 880 881 const double ratio = ( value - interval.minValue() ) / width; 882 883 int hue = m_data->hue1 + qRound( ratio * ( m_data->hue2 - m_data->hue1 ) ); 884 if ( hue >= 360 ) 885 { 886 hue -= 360; 887 888 if ( hue >= 360 ) 889 hue = hue % 360; 890 } 891 892 return m_data->rgbTable[hue]; 893 } 894 895 class QwtSaturationValueColorMap::PrivateData 896 { 897 public: 898 PrivateData() 899 : hue(0) 900 , sat1(255) 901 , sat2(255) 902 , value1(0) 903 , value2(255) 904 , alpha(255) 905 , tableType(Invalid) 906 { 907 updateTable(); 908 } 909 910 void updateTable() 911 { 912 tableType = Invalid; 913 914 if ( ( value1 == value2 ) && ( sat1 != sat2 ) ) 915 { 916 rgbTable.resize( 256 ); 917 918 for ( int i = 0; i < 256; i++ ) 919 rgbTable[i] = qwtHsvToRgb( hue, i, value1, alpha ); 920 921 tableType = Saturation; 922 } 923 else if ( ( value1 != value2 ) && ( sat1 == sat2 ) ) 924 { 925 rgbTable.resize( 256 ); 926 927 for ( int i = 0; i < 256; i++ ) 928 rgbTable[i] = qwtHsvToRgb( hue, sat1, i, alpha ); 929 930 tableType = Value; 931 } 932 else 933 { 934 rgbTable.resize( 256 * 256 ); 935 936 for ( int s = 0; s < 256; s++ ) 937 { 938 const int v0 = s * 256; 939 940 for ( int v = 0; v < 256; v++ ) 941 rgbTable[v0 + v] = qwtHsvToRgb( hue, s, v, alpha ); 942 } 943 } 944 } 945 946 int hue; 947 int sat1, sat2; 948 int value1, value2; 949 int alpha; 950 951 enum 952 { 953 Invalid, 954 Value, 955 Saturation 956 957 } tableType; 958 959 QVector< QRgb > rgbTable; 960 }; 961 962 /*! 963 \brief Constructor 964 965 The value interval is initialized by 0 to 255, 966 saturation by 255 to 255. Hue to 0 and alpha to 255. 967 968 So the default setting interpolates the value coordinate only. 969 970 \sa setHueInterval(), setSaturation(), setValue(), setValue() 971 */ 972 QwtSaturationValueColorMap::QwtSaturationValueColorMap() 973 { 974 m_data = new PrivateData; 975 } 976 977 //! Destructor 978 QwtSaturationValueColorMap::~QwtSaturationValueColorMap() 979 { 980 delete m_data; 981 } 982 983 /*! 984 \brief Set the the hue coordinate 985 986 Hue coordinates outside 0 to 359 will be interpreted as hue % 360.. 987 988 \param hue Hue coordinate 989 990 \sa hue() 991 */ 992 void QwtSaturationValueColorMap::setHue( int hue ) 993 { 994 hue = hue % 360; 995 996 if ( hue != m_data->hue ) 997 { 998 m_data->hue = hue; 999 m_data->updateTable(); 1000 } 1001 } 1002 1003 /*! 1004 \brief Set the interval for the saturation coordinate 1005 1006 When saturation1 == saturation2 the map interpolates between 1007 the value coordinates only 1008 1009 saturation1/saturation2 need to be in the range 0 to 255. 1010 1011 \param saturation1 First saturation 1012 \param saturation2 Second saturation 1013 1014 \sa saturation1(), saturation2(), setValueInterval() 1015 */ 1016 void QwtSaturationValueColorMap::setSaturationInterval( 1017 int saturation1, int saturation2 ) 1018 { 1019 saturation1 = qBound( 0, saturation1, 255 ); 1020 saturation2 = qBound( 0, saturation2, 255 ); 1021 1022 if ( ( saturation1 != m_data->sat1 ) || ( saturation2 != m_data->sat2 ) ) 1023 { 1024 m_data->sat1 = saturation1; 1025 m_data->sat2 = saturation2; 1026 1027 m_data->updateTable(); 1028 } 1029 } 1030 1031 /*! 1032 \brief Set the interval for the value coordinate 1033 1034 When value1 == value2 the map interpolates between the saturation coordinates only. 1035 1036 value1/value2 need to be in the range 0 to 255. 1037 1038 \param value1 First value 1039 \param value2 Second value 1040 1041 \sa value1(), value2(), setSaturationInterval() 1042 */ 1043 void QwtSaturationValueColorMap::setValueInterval( int value1, int value2 ) 1044 { 1045 value1 = qBound( 0, value1, 255 ); 1046 value2 = qBound( 0, value2, 255 ); 1047 1048 if ( ( value1 != m_data->value1 ) || ( value2 != m_data->value2 ) ) 1049 { 1050 m_data->value1 = value1; 1051 m_data->value2 = value2; 1052 1053 m_data->updateTable(); 1054 } 1055 } 1056 1057 /*! 1058 \brief Set the the alpha coordinate 1059 1060 alpha needs to be in the range 0 to 255, 1061 where 255 means opaque and 0 means transparent. 1062 1063 \param alpha Alpha coordinate 1064 1065 \sa alpha() 1066 */ 1067 void QwtSaturationValueColorMap::setAlpha( int alpha ) 1068 { 1069 alpha = qBound( 0, alpha, 255 ); 1070 1071 if ( alpha != m_data->alpha ) 1072 { 1073 m_data->alpha = alpha; 1074 m_data->updateTable(); 1075 } 1076 } 1077 1078 /*! 1079 \return Hue coordinate 1080 \sa setHue() 1081 */ 1082 int QwtSaturationValueColorMap::hue() const 1083 { 1084 return m_data->hue; 1085 } 1086 1087 /*! 1088 \return First saturation coordinate 1089 \sa setSaturationInterval() 1090 */ 1091 int QwtSaturationValueColorMap::saturation1() const 1092 { 1093 return m_data->sat1; 1094 } 1095 1096 /*! 1097 \return Second saturation coordinate 1098 \sa setSaturationInterval() 1099 */ 1100 int QwtSaturationValueColorMap::saturation2() const 1101 { 1102 return m_data->sat2; 1103 } 1104 1105 /*! 1106 \return First value coordinate 1107 \sa setValueInterval() 1108 */ 1109 int QwtSaturationValueColorMap::value1() const 1110 { 1111 return m_data->value1; 1112 } 1113 1114 /*! 1115 \return Second value coordinate 1116 \sa setValueInterval() 1117 */ 1118 int QwtSaturationValueColorMap::value2() const 1119 { 1120 return m_data->value2; 1121 } 1122 1123 /*! 1124 \return Alpha coordinate 1125 \sa setAlpha() 1126 */ 1127 int QwtSaturationValueColorMap::alpha() const 1128 { 1129 return m_data->alpha; 1130 } 1131 1132 /*! 1133 Map a value of a given interval into a RGB value 1134 1135 \param interval Range for all values 1136 \param value Value to map into a RGB value 1137 1138 \return RGB value for value 1139 */ 1140 QRgb QwtSaturationValueColorMap::rgb( 1141 const QwtInterval& interval, double value ) const 1142 { 1143 const double width = interval.width(); 1144 if ( width <= 0 ) 1145 return 0u; 1146 1147 const QRgb* rgbTable = m_data->rgbTable.constData(); 1148 1149 switch( m_data->tableType ) 1150 { 1151 case PrivateData::Saturation: 1152 { 1153 if ( value <= interval.minValue() ) 1154 return m_data->rgbTable[m_data->sat1]; 1155 1156 if ( value >= interval.maxValue() ) 1157 return m_data->rgbTable[m_data->sat2]; 1158 1159 const double ratio = ( value - interval.minValue() ) / width; 1160 const int sat = m_data->sat1 1161 + qRound( ratio * ( m_data->sat2 - m_data->sat1 ) ); 1162 1163 return rgbTable[sat]; 1164 } 1165 case PrivateData::Value: 1166 { 1167 if ( value <= interval.minValue() ) 1168 return m_data->rgbTable[m_data->value1]; 1169 1170 if ( value >= interval.maxValue() ) 1171 return m_data->rgbTable[m_data->value2]; 1172 1173 const double ratio = ( value - interval.minValue() ) / width; 1174 const int v = m_data->value1 + 1175 qRound( ratio * ( m_data->value2 - m_data->value1 ) ); 1176 1177 return rgbTable[ v ]; 1178 } 1179 default: 1180 { 1181 int s, v; 1182 if ( value <= interval.minValue() ) 1183 { 1184 s = m_data->sat1; 1185 v = m_data->value1; 1186 } 1187 else if ( value >= interval.maxValue() ) 1188 { 1189 s = m_data->sat2; 1190 v = m_data->value2; 1191 } 1192 else 1193 { 1194 const double ratio = ( value - interval.minValue() ) / width; 1195 1196 v = m_data->value1 + qRound( ratio * ( m_data->value2 - m_data->value1 ) ); 1197 s = m_data->sat1 + qRound( ratio * ( m_data->sat2 - m_data->sat1 ) ); 1198 } 1199 1200 return rgbTable[ 256 * s + v ]; 1201 } 1202 } 1203 } -
trunk/BNC/qwt/qwt_color_map.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h"15 14 #include <qcolor.h> 16 #include <qvector.h> 17 18 /*! 19 \brief QwtColorMap is used to map values into colors. 20 21 For displaying 3D data on a 2D plane the 3rd dimension is often 22 displayed using colors, like f.e in a spectrogram. 23 24 Each color map is optimized to return colors for only one of the 25 following image formats: 26 27 - QImage::Format_Indexed8\n 28 - QImage::Format_ARGB32\n 29 30 \sa QwtPlotSpectrogram, QwtScaleWidget 31 */ 15 16 class QwtInterval; 17 18 #if QT_VERSION < 0x060000 19 template< typename T > class QVector; 20 #endif 21 22 /*! 23 \brief QwtColorMap is used to map values into colors. 24 25 For displaying 3D data on a 2D plane the 3rd dimension is often 26 displayed using colors, like f.e in a spectrogram. 27 28 Each color map is optimized to return colors for only one of the 29 following image formats: 30 31 - QImage::Format_Indexed8\n 32 - QImage::Format_ARGB32\n 33 34 \sa QwtPlotSpectrogram, QwtScaleWidget 35 */ 32 36 33 37 class QWT_EXPORT QwtColorMap 34 38 { 35 public: 39 public: 36 40 /*! 37 41 Format for color mapping 38 42 \sa rgb(), colorIndex(), colorTable() 39 */ 43 */ 40 44 41 45 enum Format … … 45 49 46 50 /*! 47 The map is intended to map into 8 bit values, that 48 are indices into the color table. 51 Map values into 8 bit values, that 52 are used as indexes into the color table. 53 54 Indexed color maps are used to generate QImage::Format_Indexed8 55 images. The calculation of the color index is usually faster 56 and the resulting image has a lower memory footprint. 57 58 \sa colorIndex(), colorTable() 49 59 */ 50 60 Indexed 51 61 }; 52 62 53 QwtColorMap( Format = QwtColorMap::RGB ); 63 explicit QwtColorMap( Format = QwtColorMap::RGB ); 54 64 virtual ~QwtColorMap(); 55 65 66 void setFormat( Format ); 56 67 Format format() const; 57 68 … … 62 73 \param value Value 63 74 \return RGB value, corresponding to value 64 */65 virtual QRgb rgb( const QwtInterval &interval,66 double value ) const = 0;67 68 /*!69 Map a value of a given interval into a color index70 71 \param interval Range for the values72 \param value Value73 \return color index, corresponding to value74 75 */ 75 virtual unsigned char colorIndex( 76 const QwtInterval &interval, double value ) const = 0; 77 78 QColor color( const QwtInterval &, double value ) const; 79 virtual QVector<QRgb> colorTable( const QwtInterval & ) const; 80 81 private: 82 Format d_format; 83 }; 84 85 /*! 86 \brief QwtLinearColorMap builds a color map from color stops. 87 88 A color stop is a color at a specific position. The valid 89 range for the positions is [0.0, 1.0]. When mapping a value 90 into a color it is translated into this interval according to mode(). 91 */ 92 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap 93 { 94 public: 76 virtual QRgb rgb( const QwtInterval& interval, double value ) const = 0; 77 78 virtual uint colorIndex( int numColors, 79 const QwtInterval& interval, double value ) const; 80 81 QColor color( const QwtInterval&, double value ) const; 82 virtual QVector< QRgb > colorTable( int numColors ) const; 83 virtual QVector< QRgb > colorTable256() const; 84 85 private: 86 Q_DISABLE_COPY(QwtColorMap) 87 88 Format m_format; 89 }; 90 91 /*! 92 \brief QwtLinearColorMap builds a color map from color stops. 93 94 A color stop is a color at a specific position. The valid 95 range for the positions is [0.0, 1.0]. When mapping a value 96 into a color it is translated into this interval according to mode(). 97 */ 98 class QWT_EXPORT QwtLinearColorMap : public QwtColorMap 99 { 100 public: 95 101 /*! 96 102 Mode of color map 97 103 \sa setMode(), mode() 98 */ 104 */ 99 105 enum Mode 100 106 { … … 106 112 }; 107 113 108 QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB ); 109 QwtLinearColorMap( const QColor &color1, const QColor &color2, 114 explicit QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB ); 115 116 QwtLinearColorMap( const QColor& from, const QColor& to, 110 117 QwtColorMap::Format = QwtColorMap::RGB ); 111 118 … … 115 122 Mode mode() const; 116 123 117 void setColorInterval( const QColor &color1, const QColor&color2 );124 void setColorInterval( const QColor& color1, const QColor& color2 ); 118 125 void addColorStop( double value, const QColor& ); 119 QVector< double> colorStops() const;126 QVector< double > colorStops() const; 120 127 121 128 QColor color1() const; 122 129 QColor color2() const; 123 130 124 virtual QRgb rgb( const QwtInterval &, double value ) const; 125 virtual unsigned char colorIndex( 126 const QwtInterval &, double value ) const; 131 virtual QRgb rgb( const QwtInterval&, 132 double value ) const QWT_OVERRIDE; 133 134 virtual uint colorIndex( int numColors, 135 const QwtInterval&, double value ) const QWT_OVERRIDE; 127 136 128 137 class ColorStops; 129 138 130 private: 131 // Disabled copy constructor and operator= 132 QwtLinearColorMap( const QwtLinearColorMap & ); 133 QwtLinearColorMap &operator=( const QwtLinearColorMap & ); 134 135 class PrivateData; 136 PrivateData *d_data; 137 }; 138 139 /*! 140 \brief QwtAlphaColorMap varies the alpha value of a color 141 */ 142 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap 143 { 144 public: 145 QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) ); 139 private: 140 class PrivateData; 141 PrivateData* m_data; 142 }; 143 144 /*! 145 \brief QwtAlphaColorMap varies the alpha value of a color 146 */ 147 class QWT_EXPORT QwtAlphaColorMap : public QwtColorMap 148 { 149 public: 150 explicit QwtAlphaColorMap( const QColor& = QColor( Qt::gray ) ); 146 151 virtual ~QwtAlphaColorMap(); 147 152 148 void setColor( const QColor & ); 153 void setAlphaInterval( int alpha1, int alpha2 ); 154 155 int alpha1() const; 156 int alpha2() const; 157 158 void setColor( const QColor& ); 149 159 QColor color() const; 150 160 151 virtual QRgb rgb( const QwtInterval &, double value ) const; 152 153 private: 154 QwtAlphaColorMap( const QwtAlphaColorMap & ); 155 QwtAlphaColorMap &operator=( const QwtAlphaColorMap & ); 156 157 virtual unsigned char colorIndex( 158 const QwtInterval &, double value ) const; 159 160 class PrivateData; 161 PrivateData *d_data; 162 }; 163 161 virtual QRgb rgb( const QwtInterval&, 162 double value ) const QWT_OVERRIDE; 163 164 private: 165 class PrivateData; 166 PrivateData* m_data; 167 }; 168 169 /*! 170 \brief QwtHueColorMap varies the hue value of the HSV color model. 171 172 QwtHueColorMap can be used to set up a color map easily, that runs cyclic over 173 all colors. Each cycle has 360 different steps. 174 175 The values for value and saturation are in the range of 0 to 255 and doesn't 176 depend on the data value to be mapped. 177 178 \sa QwtSaturationValueColorMap 179 */ 180 class QWT_EXPORT QwtHueColorMap : public QwtColorMap 181 { 182 public: 183 explicit QwtHueColorMap( QwtColorMap::Format = QwtColorMap::RGB ); 184 virtual ~QwtHueColorMap(); 185 186 void setHueInterval( int hue1, int hue2 ); // direction ? 187 void setSaturation( int saturation ); 188 void setValue( int value ); 189 void setAlpha( int alpha ); 190 191 int hue1() const; 192 int hue2() const; 193 int saturation() const; 194 int value() const; 195 int alpha() const; 196 197 virtual QRgb rgb( const QwtInterval&, 198 double value ) const QWT_OVERRIDE; 199 200 private: 201 class PrivateData; 202 PrivateData* m_data; 203 }; 204 205 /*! 206 \brief QwtSaturationValueColorMap varies the saturation and/or value for a given 207 hue in the HSV color model. 208 209 Value and saturation are in the range of 0 to 255 while hue is in the range 210 of 0 to 259. 211 212 \sa QwtHueColorMap 213 */ 214 class QWT_EXPORT QwtSaturationValueColorMap : public QwtColorMap 215 { 216 public: 217 QwtSaturationValueColorMap(); 218 virtual ~QwtSaturationValueColorMap(); 219 220 void setHue( int hue ); 221 void setSaturationInterval( int sat1, int sat2 ); 222 void setValueInterval( int value1, int value2 ); 223 void setAlpha( int alpha ); 224 225 int hue() const; 226 int saturation1() const; 227 int saturation2() const; 228 int value1() const; 229 int value2() const; 230 int alpha() const; 231 232 virtual QRgb rgb( const QwtInterval&, 233 double value ) const QWT_OVERRIDE; 234 235 private: 236 class PrivateData; 237 PrivateData* m_data; 238 }; 164 239 165 240 /*! … … 170 245 171 246 \return Color corresponding to value 172 173 \warning This method is slow for Indexed color maps. If it is 174 necessary to map many values, its better to get the 175 color table once and find the color using colorIndex(). 176 */ 177 inline QColor QwtColorMap::color( 178 const QwtInterval &interval, double value ) const 179 { 180 if ( d_format == RGB ) 181 { 182 return QColor::fromRgba( rgb( interval, value ) ); 183 } 184 else 185 { 186 const unsigned int index = colorIndex( interval, value ); 187 188 const QVector<QRgb> rgbTable = colorTable( interval ); 189 return rgbTable[index]; // slow 190 } 247 */ 248 inline QColor QwtColorMap::color( const QwtInterval& interval, double value ) const 249 { 250 return QColor::fromRgba( rgb( interval, value ) ); 191 251 } 192 252 … … 194 254 \return Intended format of the color map 195 255 \sa Format 196 */ 256 */ 197 257 inline QwtColorMap::Format QwtColorMap::format() const 198 258 { 199 return d_format;259 return m_format; 200 260 } 201 261 -
trunk/BNC/qwt/qwt_column_symbol.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_column_symbol.h" 11 #include "qwt_painter.h" 11 12 #include "qwt_math.h" 12 #include "qwt_painter.h" 13 13 14 #include <qpainter.h> 14 15 #include <qpalette.h> 15 16 16 static void qwtDrawBox( QPainter *p, const QRectF&rect,17 const QPalette &pal, double lw )17 static void qwtDrawBox( QPainter* p, const QRectF& rect, 18 const QPalette& pal, double lw ) 18 19 { 19 20 if ( lw > 0.0 ) … … 33 34 } 34 35 35 lw = q Min( lw, rect.height() / 2.0 - 1.0 );36 lw = q Min( lw, rect.width() / 2.0 - 1.0 );36 lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 ); 37 lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 ); 37 38 38 39 const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 ); 39 40 QPolygonF polygon( outerRect ); 40 41 41 if ( outerRect.width() > 2 * lw && 42 outerRect.height() > 2 * lw ) 42 if ( outerRect.width() > 2 * lw && outerRect.height() > 2 * lw ) 43 43 { 44 44 const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw ); … … 57 57 } 58 58 59 static void qwtDrawPanel( QPainter *painter, const QRectF&rect,60 const QPalette &pal, double lw )59 static void qwtDrawPanel( QPainter* painter, const QRectF& rect, 60 const QPalette& pal, double lw ) 61 61 { 62 62 if ( lw > 0.0 ) … … 76 76 } 77 77 78 lw = q Min( lw, rect.height() / 2.0 - 1.0 );79 lw = q Min( lw, rect.width() / 2.0 - 1.0 );78 lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 ); 79 lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 ); 80 80 81 81 const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 ); … … 111 111 class QwtColumnSymbol::PrivateData 112 112 { 113 public: 114 PrivateData() :115 style( QwtColumnSymbol::Box ) ,116 frameStyle( QwtColumnSymbol::Raised ) ,117 palette( Qt::gray ) ,118 lineWidth( 2 ) 113 public: 114 PrivateData() 115 : style( QwtColumnSymbol::Box ) 116 , frameStyle( QwtColumnSymbol::Raised ) 117 , palette( Qt::gray ) 118 , lineWidth( 2 ) 119 119 { 120 120 } … … 128 128 129 129 /*! 130 Constructor 131 132 \param style Style of the symbol 133 \sa setStyle(), style(), Style 134 */ 130 Constructor 131 132 \param style Style of the symbol 133 \sa setStyle(), style(), Style 134 */ 135 135 QwtColumnSymbol::QwtColumnSymbol( Style style ) 136 136 { 137 d_data = new PrivateData();138 d_data->style = style;137 m_data = new PrivateData(); 138 m_data->style = style; 139 139 } 140 140 … … 142 142 QwtColumnSymbol::~QwtColumnSymbol() 143 143 { 144 delete d_data;145 } 146 147 /*! 148 Specify the symbol style 149 150 \param style Style 151 \sa style(), setPalette() 152 */ 144 delete m_data; 145 } 146 147 /*! 148 Specify the symbol style 149 150 \param style Style 151 \sa style(), setPalette() 152 */ 153 153 void QwtColumnSymbol::setStyle( Style style ) 154 154 { 155 d_data->style = style;156 } 157 158 /*! 159 \return Current symbol style 160 \sa setStyle() 161 */ 155 m_data->style = style; 156 } 157 158 /*! 159 \return Current symbol style 160 \sa setStyle() 161 */ 162 162 QwtColumnSymbol::Style QwtColumnSymbol::style() const 163 163 { 164 return d_data->style;165 } 166 167 /*! 168 Assign a palette for the symbol 169 170 \param palette Palette 171 \sa palette(), setStyle() 172 */ 173 void QwtColumnSymbol::setPalette( const QPalette &palette )174 { 175 d_data->palette = palette;176 } 177 178 /*! 179 \return Current palette 180 \sa setPalette() 181 */ 164 return m_data->style; 165 } 166 167 /*! 168 Assign a palette for the symbol 169 170 \param palette Palette 171 \sa palette(), setStyle() 172 */ 173 void QwtColumnSymbol::setPalette( const QPalette& palette ) 174 { 175 m_data->palette = palette; 176 } 177 178 /*! 179 \return Current palette 180 \sa setPalette() 181 */ 182 182 const QPalette& QwtColumnSymbol::palette() const 183 183 { 184 return d_data->palette;184 return m_data->palette; 185 185 } 186 186 … … 190 190 \param frameStyle Frame style 191 191 \sa frameStyle(), setLineWidth(), setStyle() 192 */ 192 */ 193 193 void QwtColumnSymbol::setFrameStyle( FrameStyle frameStyle ) 194 194 { 195 d_data->frameStyle = frameStyle;196 } 197 198 /*! 199 \return Current frame style, that is used for the Box style. 200 \sa setFrameStyle(), lineWidth(), setStyle() 201 */ 195 m_data->frameStyle = frameStyle; 196 } 197 198 /*! 199 \return Current frame style, that is used for the Box style. 200 \sa setFrameStyle(), lineWidth(), setStyle() 201 */ 202 202 QwtColumnSymbol::FrameStyle QwtColumnSymbol::frameStyle() const 203 203 { 204 return d_data->frameStyle;204 return m_data->frameStyle; 205 205 } 206 206 … … 210 210 \param width Width 211 211 \sa lineWidth(), setFrameStyle() 212 */ 212 */ 213 213 void QwtColumnSymbol::setLineWidth( int width ) 214 214 { … … 216 216 width = 0; 217 217 218 d_data->lineWidth = width;219 } 220 221 /*! 222 \return Line width of the frame, that is used for the Box style. 223 \sa setLineWidth(), frameStyle(), setStyle() 224 */ 218 m_data->lineWidth = width; 219 } 220 221 /*! 222 \return Line width of the frame, that is used for the Box style. 223 \sa setLineWidth(), frameStyle(), setStyle() 224 */ 225 225 int QwtColumnSymbol::lineWidth() const 226 226 { 227 return d_data->lineWidth;228 } 229 230 /*! 231 Draw the symbol depending on its style. 232 233 \param painter Painter 234 \param rect Directed rectangle 235 236 \sa drawBox() 237 */ 238 void QwtColumnSymbol::draw( QPainter *painter,239 const QwtColumnRect &rect ) const227 return m_data->lineWidth; 228 } 229 230 /*! 231 Draw the symbol depending on its style. 232 233 \param painter Painter 234 \param rect Directed rectangle 235 236 \sa drawBox() 237 */ 238 void QwtColumnSymbol::draw( QPainter* painter, 239 const QwtColumnRect& rect ) const 240 240 { 241 241 painter->save(); 242 242 243 switch ( d_data->style )243 switch ( m_data->style ) 244 244 { 245 245 case QwtColumnSymbol::Box: … … 255 255 256 256 /*! 257 Draw the symbol when it is in Box style. 258 259 \param painter Painter 260 \param rect Directed rectangle 261 262 \sa draw() 263 */ 264 void QwtColumnSymbol::drawBox( QPainter *painter,265 const QwtColumnRect &rect ) const257 Draw the symbol when it is in Box style. 258 259 \param painter Painter 260 \param rect Directed rectangle 261 262 \sa draw() 263 */ 264 void QwtColumnSymbol::drawBox( QPainter* painter, 265 const QwtColumnRect& rect ) const 266 266 { 267 267 QRectF r = rect.toRect(); … … 274 274 } 275 275 276 switch ( d_data->frameStyle )276 switch ( m_data->frameStyle ) 277 277 { 278 278 case QwtColumnSymbol::Raised: 279 279 { 280 qwtDrawPanel( painter, r, d_data->palette,d_data->lineWidth );280 qwtDrawPanel( painter, r, m_data->palette, m_data->lineWidth ); 281 281 break; 282 282 } 283 283 case QwtColumnSymbol::Plain: 284 284 { 285 qwtDrawBox( painter, r, d_data->palette,d_data->lineWidth );285 qwtDrawBox( painter, r, m_data->palette, m_data->lineWidth ); 286 286 break; 287 287 } 288 288 default: 289 289 { 290 painter->fillRect( r.adjusted( 0, 0, 1, 1 ), d_data->palette.window() ); 291 } 292 } 293 } 290 painter->fillRect( r.adjusted( 0, 0, 1, 1 ), m_data->palette.window() ); 291 } 292 } 293 } 294 295 //! \return A normalized QRect built from the intervals 296 QRectF QwtColumnRect::toRect() const 297 { 298 QRectF r( hInterval.minValue(), vInterval.minValue(), 299 hInterval.maxValue() - hInterval.minValue(), 300 vInterval.maxValue() - vInterval.minValue() ); 301 302 r = r.normalized(); 303 304 if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum ) 305 r.adjust( 1, 0, 0, 0 ); 306 307 if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum ) 308 r.adjust( 0, 0, -1, 0 ); 309 310 if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum ) 311 r.adjust( 0, 1, 0, 0 ); 312 313 if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum ) 314 r.adjust( 0, 0, 0, -1 ); 315 316 return r; 317 } 318 -
trunk/BNC/qwt/qwt_column_symbol.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_interval.h" 15 #include <qpen.h> 16 #include <qsize.h> 17 #include <qrect.h> 15 16 #include <qnamespace.h> 18 17 19 18 class QPainter; 20 19 class QPalette; 21 class QRect; 22 class QwtText; 20 class QRectF; 23 21 24 22 /*! 25 23 \brief Directed rectangle representing bounding rectangle and orientation 26 24 of a column. 27 */ 25 */ 28 26 class QWT_EXPORT QwtColumnRect 29 27 { 30 public: 28 public: 31 29 //! Direction of the column 32 30 enum Direction … … 46 44 47 45 //! Build an rectangle with invalid intervals directed BottomToTop. 48 QwtColumnRect() :49 direction( BottomToTop ) 46 QwtColumnRect() 47 : direction( BottomToTop ) 50 48 { 51 49 } 52 50 53 51 //! \return A normalized QRect built from the intervals 54 QRectF toRect() const 55 { 56 QRectF r( hInterval.minValue(), vInterval.minValue(), 57 hInterval.maxValue() - hInterval.minValue(), 58 vInterval.maxValue() - vInterval.minValue() ); 59 r = r.normalized(); 60 61 if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum ) 62 r.adjust( 1, 0, 0, 0 ); 63 if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum ) 64 r.adjust( 0, 0, -1, 0 ); 65 if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum ) 66 r.adjust( 0, 1, 0, 0 ); 67 if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum ) 68 r.adjust( 0, 0, 0, -1 ); 69 70 return r; 71 } 52 QRectF toRect() const; 72 53 73 54 //! \return Orientation … … 93 74 class QWT_EXPORT QwtColumnSymbol 94 75 { 95 public: 76 public: 96 77 /*! 97 Style 98 \sa setStyle(), style() 99 */ 78 Style 79 \sa setStyle(), style() 80 */ 100 81 enum Style 101 82 { … … 104 85 105 86 /*! 106 The column is painted with a frame depending on the frameStyle() 107 and lineWidth() using the palette(). 87 The column is painted with a frame depending on the frameStyle() 88 and lineWidth() using the palette(). 108 89 */ 109 90 Box, 110 91 111 92 /*! 112 Styles >= QwtColumnSymbol::UserStyle are reserved for derived 113 classes of QwtColumnSymbol that overload draw() with 114 additional application specific symbol types. 93 Styles >= QwtColumnSymbol::UserStyle are reserved for derived 94 classes of QwtColumnSymbol that overload draw() with 95 additional application specific symbol types. 115 96 */ 116 97 UserStyle = 1000 … … 118 99 119 100 /*! 120 Frame Style used in Box style(). 121 \sa Style, setFrameStyle(), frameStyle(), setStyle(), setPalette() 101 Frame Style used in Box style(). 102 \sa Style, setFrameStyle(), frameStyle(), setStyle(), setPalette() 122 103 */ 123 104 enum FrameStyle … … 133 114 }; 134 115 135 public: 136 QwtColumnSymbol( Style = NoStyle ); 116 public: 117 explicit QwtColumnSymbol( Style = NoStyle ); 137 118 virtual ~QwtColumnSymbol(); 138 119 … … 143 124 int lineWidth() const; 144 125 145 void setPalette( const QPalette & );146 const QPalette &palette() const;126 void setPalette( const QPalette& ); 127 const QPalette& palette() const; 147 128 148 129 void setStyle( Style ); 149 130 Style style() const; 150 131 151 virtual void draw( QPainter *, const QwtColumnRect& ) const;132 virtual void draw( QPainter*, const QwtColumnRect& ) const; 152 133 153 protected: 154 void drawBox( QPainter *, const QwtColumnRect& ) const;134 protected: 135 void drawBox( QPainter*, const QwtColumnRect& ) const; 155 136 156 private: 137 private: 138 Q_DISABLE_COPY(QwtColumnSymbol) 139 157 140 class PrivateData; 158 PrivateData* d_data;141 PrivateData* m_data; 159 142 }; 160 143 -
trunk/BNC/qwt/qwt_compass.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_compass.h" 11 11 #include "qwt_compass_rose.h" 12 #include "qwt_math.h" 13 #include "qwt_scale_draw.h" 14 #include "qwt_painter.h" 15 #include "qwt_dial_needle.h" 16 #include <qpainter.h> 17 #include <qpixmap.h> 12 #include "qwt_text.h" 13 18 14 #include <qevent.h> 19 20 /*! 21 \brief Constructor 22 23 Initializes a label map for multiples of 45 degrees 15 #include <qmap.h> 16 17 class QwtCompassScaleDraw::PrivateData 18 { 19 public: 20 QMap< double, QString > labelMap; 21 }; 22 23 /*! 24 \brief Constructor 25 26 Initializes a label map for multiples of 45 degrees 24 27 */ 25 28 QwtCompassScaleDraw::QwtCompassScaleDraw() 26 29 { 30 m_data = new PrivateData; 31 27 32 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 28 33 enableComponent( QwtAbstractScaleDraw::Ticks, false ); 29 34 30 d_labelMap.insert( 0.0, QString::fromLatin1( "N" ) ); 31 d_labelMap.insert( 45.0, QString::fromLatin1( "NE" ) ); 32 d_labelMap.insert( 90.0, QString::fromLatin1( "E" ) ); 33 d_labelMap.insert( 135.0, QString::fromLatin1( "SE" ) ); 34 d_labelMap.insert( 180.0, QString::fromLatin1( "S" ) ); 35 d_labelMap.insert( 225.0, QString::fromLatin1( "SW" ) ); 36 d_labelMap.insert( 270.0, QString::fromLatin1( "W" ) ); 37 d_labelMap.insert( 315.0, QString::fromLatin1( "NW" ) ); 35 QMap< double, QString >& map = m_data->labelMap; 36 37 map.insert( 0.0, QString::fromLatin1( "N" ) ); 38 map.insert( 45.0, QString::fromLatin1( "NE" ) ); 39 map.insert( 90.0, QString::fromLatin1( "E" ) ); 40 map.insert( 135.0, QString::fromLatin1( "SE" ) ); 41 map.insert( 180.0, QString::fromLatin1( "S" ) ); 42 map.insert( 225.0, QString::fromLatin1( "SW" ) ); 43 map.insert( 270.0, QString::fromLatin1( "W" ) ); 44 map.insert( 315.0, QString::fromLatin1( "NW" ) ); 38 45 39 46 #if 0 40 d_labelMap.insert( 22.5, QString::fromLatin1( "NNE" ) );41 d_labelMap.insert( 67.5, QString::fromLatin1( "NEE" ) );42 d_labelMap.insert( 112.5, QString::fromLatin1( "SEE" ) );43 d_labelMap.insert( 157.5, QString::fromLatin1( "SSE" ) );44 d_labelMap.insert( 202.5, QString::fromLatin1( "SSW" ) );45 d_labelMap.insert( 247.5, QString::fromLatin1( "SWW" ) );46 d_labelMap.insert( 292.5, QString::fromLatin1( "NWW" ) );47 d_labelMap.insert( 337.5, QString::fromLatin1( "NNW" ) );47 map.insert( 22.5, QString::fromLatin1( "NNE" ) ); 48 map.insert( 67.5, QString::fromLatin1( "NEE" ) ); 49 map.insert( 112.5, QString::fromLatin1( "SEE" ) ); 50 map.insert( 157.5, QString::fromLatin1( "SSE" ) ); 51 map.insert( 202.5, QString::fromLatin1( "SSW" ) ); 52 map.insert( 247.5, QString::fromLatin1( "SWW" ) ); 53 map.insert( 292.5, QString::fromLatin1( "NWW" ) ); 54 map.insert( 337.5, QString::fromLatin1( "NNW" ) ); 48 55 #endif 49 56 } 50 57 51 58 /*! 52 \brief Constructor 53 54 \param map Value to label map 55 */ 56 QwtCompassScaleDraw::QwtCompassScaleDraw( const QMap<double, QString> &map ): 57 d_labelMap( map ) 58 { 59 \brief Constructor 60 61 \param map Value to label map 62 */ 63 QwtCompassScaleDraw::QwtCompassScaleDraw( const QMap< double, QString >& map ) 64 { 65 m_data = new PrivateData; 66 m_data->labelMap = map; 67 59 68 enableComponent( QwtAbstractScaleDraw::Backbone, false ); 60 69 enableComponent( QwtAbstractScaleDraw::Ticks, false ); 61 70 } 62 71 63 /*! 64 \brief Set a map, mapping values to labels 65 \param map Value to label map 66 67 The values of the major ticks are found by looking into this 68 map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW. 69 70 \warning The map will have no effect for values that are no major 72 //! Destructor 73 QwtCompassScaleDraw::~QwtCompassScaleDraw() 74 { 75 delete m_data; 76 } 77 78 /*! 79 \brief Set a map, mapping values to labels 80 \param map Value to label map 81 82 The values of the major ticks are found by looking into this 83 map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW. 84 85 \warning The map will have no effect for values that are no major 71 86 tick values. Major ticks can be changed by QwtScaleDraw::setScale 72 87 73 \sa labelMap(), scaleDraw(), setScale() 74 */ 75 void QwtCompassScaleDraw::setLabelMap( const QMap<double, QString> &map ) 76 { 77 d_labelMap = map; 78 } 79 80 81 /*! 82 \return map, mapping values to labels 83 \sa setLabelMap() 84 */ 85 QMap<double, QString> QwtCompassScaleDraw::labelMap() const 86 { 87 return d_labelMap; 88 } 89 90 /*! 91 Map a value to a corresponding label 92 93 \param value Value that will be mapped 94 95 label() looks in the labelMap() for a corresponding label for value 96 or returns an null text. 97 98 \return Label 99 \sa labelMap(), setLabelMap() 100 */ 88 \sa labelMap(), scaleDraw(), setScale() 89 */ 90 void QwtCompassScaleDraw::setLabelMap( const QMap< double, QString >& map ) 91 { 92 m_data->labelMap = map; 93 } 94 95 /*! 96 \return map, mapping values to labels 97 \sa setLabelMap() 98 */ 99 QMap< double, QString > QwtCompassScaleDraw::labelMap() const 100 { 101 return m_data->labelMap; 102 } 103 104 /*! 105 Map a value to a corresponding label 106 107 \param value Value that will be mapped 108 109 label() looks in the labelMap() for a corresponding label for value 110 or returns an null text. 111 112 \return Label 113 \sa labelMap(), setLabelMap() 114 */ 101 115 102 116 QwtText QwtCompassScaleDraw::label( double value ) const … … 108 122 value += 360.0; 109 123 110 if ( d_labelMap.contains( value ) ) 111 return d_labelMap[value]; 124 QMap< double, QString >::const_iterator it = 125 m_data->labelMap.constFind( value ); 126 127 if ( it != m_data->labelMap.constEnd() ) 128 return *it; 112 129 113 130 return QwtText(); … … 116 133 class QwtCompass::PrivateData 117 134 { 118 public: 135 public: 119 136 PrivateData(): 120 137 rose( NULL ) … … 127 144 } 128 145 129 QwtCompassRose *rose;146 QwtCompassRose* rose; 130 147 }; 131 148 132 149 /*! 133 \brief Constructor 134 \param parent Parent widget 135 136 Create a compass widget with a scale, no needle and no rose. 137 The default origin is 270.0 with no valid value. It accepts 138 mouse and keyboard inputs and has no step size. The default mode 139 is QwtDial::RotateNeedle. 140 */ 141 QwtCompass::QwtCompass( QWidget* parent ) :142 QwtDial( parent ) 143 { 144 d_data = new PrivateData;150 \brief Constructor 151 \param parent Parent widget 152 153 Create a compass widget with a scale, no needle and no rose. 154 The default origin is 270.0 with no valid value. It accepts 155 mouse and keyboard inputs and has no step size. The default mode 156 is QwtDial::RotateNeedle. 157 */ 158 QwtCompass::QwtCompass( QWidget* parent ) 159 : QwtDial( parent ) 160 { 161 m_data = new PrivateData; 145 162 146 163 setScaleDraw( new QwtCompassScaleDraw() ); … … 159 176 QwtCompass::~QwtCompass() 160 177 { 161 delete d_data;178 delete m_data; 162 179 } 163 180 … … 169 186 \param center Center of the content circle 170 187 \param radius Radius of the content circle 171 */ 172 void QwtCompass::drawScaleContents( QPainter *painter,173 const QPointF ¢er, double radius ) const188 */ 189 void QwtCompass::drawScaleContents( QPainter* painter, 190 const QPointF& center, double radius ) const 174 191 { 175 192 QPalette::ColorGroup cg; … … 191 208 192 209 /*! 193 Draw the compass rose 194 195 \param painter Painter 196 \param center Center of the compass 197 \param radius of the circle, where to paint the rose 198 \param north Direction pointing north, in degrees counter clockwise 199 \param cg Color group 200 */ 201 void QwtCompass::drawRose( QPainter *painter, const QPointF¢er,210 Draw the compass rose 211 212 \param painter Painter 213 \param center Center of the compass 214 \param radius of the circle, where to paint the rose 215 \param north Direction pointing north, in degrees counter clockwise 216 \param cg Color group 217 */ 218 void QwtCompass::drawRose( QPainter* painter, const QPointF& center, 202 219 double radius, double north, QPalette::ColorGroup cg ) const 203 220 { 204 if ( d_data->rose )205 d_data->rose->draw( painter, center, radius, north, cg );206 } 207 208 /*! 209 Set a rose for the compass 210 \param rose Compass rose 211 \warning The rose will be deleted, when a different rose is 221 if ( m_data->rose ) 222 m_data->rose->draw( painter, center, radius, north, cg ); 223 } 224 225 /*! 226 Set a rose for the compass 227 \param rose Compass rose 228 \warning The rose will be deleted, when a different rose is 212 229 set or in ~QwtCompass 213 \sa rose() 214 */ 215 void QwtCompass::setRose( QwtCompassRose *rose )216 { 217 if ( rose != d_data->rose )218 { 219 if ( d_data->rose )220 delete d_data->rose;221 222 d_data->rose = rose;230 \sa rose() 231 */ 232 void QwtCompass::setRose( QwtCompassRose* rose ) 233 { 234 if ( rose != m_data->rose ) 235 { 236 if ( m_data->rose ) 237 delete m_data->rose; 238 239 m_data->rose = rose; 223 240 update(); 224 241 } … … 226 243 227 244 /*! 228 \return rose 229 \sa setRose() 230 */ 231 const QwtCompassRose *QwtCompass::rose() const232 { 233 return d_data->rose;234 } 235 236 /*! 237 \return rose 238 \sa setRose() 239 */ 240 QwtCompassRose *QwtCompass::rose()241 { 242 return d_data->rose;243 } 244 245 /*! 246 Handles key events 247 248 Beside the keys described in QwtDial::keyPressEvent numbers 249 from 1-9 (without 5) set the direction according to their 250 position on the num pad. 251 252 \sa isReadOnly() 253 */ 254 void QwtCompass::keyPressEvent( QKeyEvent *kev )245 \return rose 246 \sa setRose() 247 */ 248 const QwtCompassRose* QwtCompass::rose() const 249 { 250 return m_data->rose; 251 } 252 253 /*! 254 \return rose 255 \sa setRose() 256 */ 257 QwtCompassRose* QwtCompass::rose() 258 { 259 return m_data->rose; 260 } 261 262 /*! 263 Handles key events 264 265 Beside the keys described in QwtDial::keyPressEvent numbers 266 from 1-9 (without 5) set the direction according to their 267 position on the num pad. 268 269 \sa isReadOnly() 270 */ 271 void QwtCompass::keyPressEvent( QKeyEvent* kev ) 255 272 { 256 273 if ( isReadOnly() ) … … 307 324 } 308 325 } 326 327 #include "moc_qwt_compass.cpp" -
trunk/BNC/qwt/qwt_compass.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_COMPASS_H 11 #define QWT_COMPASS_H 111 #define QWT_COMPASS_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_dial.h" 15 15 #include "qwt_round_scale_draw.h" 16 #include <qstring.h>17 #include <qmap.h>18 16 19 17 class QwtCompassRose; 18 class QString; 19 template< class Key, class T > class QMap; 20 20 21 21 22 /*! 22 \brief A special scale draw made for QwtCompass 23 \brief A special scale draw made for QwtCompass 23 24 24 QwtCompassScaleDraw maps values to strings using 25 a special map, that can be modified by the application 25 QwtCompassScaleDraw maps values to strings using 26 a special map, that can be modified by the application 26 27 27 The default map consists of the labels N, NE, E, SE, S, SW, W, NW. 28 The default map consists of the labels N, NE, E, SE, S, SW, W, NW. 28 29 29 \sa QwtCompass 30 */ 31 class QWT_EXPORT QwtCompassScaleDraw: public QwtRoundScaleDraw 30 \sa QwtCompass 31 */ 32 class QWT_EXPORT QwtCompassScaleDraw : public QwtRoundScaleDraw 32 33 { 33 public: 34 public: 34 35 explicit QwtCompassScaleDraw(); 35 explicit QwtCompassScaleDraw( const QMap<double, QString > &map );36 explicit QwtCompassScaleDraw( const QMap< double, QString >& map ); 36 37 37 void setLabelMap( const QMap<double, QString> &map ); 38 QMap<double, QString> labelMap() const; 38 virtual ~QwtCompassScaleDraw(); 39 39 40 virtual QwtText label( double value ) const; 40 void setLabelMap( const QMap< double, QString >& map ); 41 QMap< double, QString > labelMap() const; 41 42 42 private: 43 QMap<double, QString> d_labelMap; 43 virtual QwtText label( double value ) const QWT_OVERRIDE; 44 45 private: 46 class PrivateData; 47 PrivateData* m_data; 44 48 }; 45 49 46 50 /*! 47 \brief A Compass Widget 51 \brief A Compass Widget 48 52 49 QwtCompass is a widget to display and enter directions. It consists 50 of a scale, an optional needle and rose. 53 QwtCompass is a widget to display and enter directions. It consists 54 of a scale, an optional needle and rose. 51 55 52 \image html dials1.png 56 \image html dials1.png 53 57 54 \note The examples/dials example shows how to use QwtCompass. 55 */ 58 \note The examples/dials example shows how to use QwtCompass. 59 */ 56 60 57 class QWT_EXPORT QwtCompass: public QwtDial 61 class QWT_EXPORT QwtCompass : public QwtDial 58 62 { 59 63 Q_OBJECT 60 64 61 public: 65 public: 62 66 explicit QwtCompass( QWidget* parent = NULL ); 63 67 virtual ~QwtCompass(); 64 68 65 void setRose( QwtCompassRose *rose );66 const QwtCompassRose *rose() const;67 QwtCompassRose *rose();69 void setRose( QwtCompassRose* rose ); 70 const QwtCompassRose* rose() const; 71 QwtCompassRose* rose(); 68 72 69 protected: 70 virtual void drawRose( QPainter *, const QPointF¢er,73 protected: 74 virtual void drawRose( QPainter*, const QPointF& center, 71 75 double radius, double north, QPalette::ColorGroup ) const; 72 76 73 virtual void drawScaleContents( QPainter *,74 const QPointF ¢er, double radius ) const;77 virtual void drawScaleContents( QPainter*, 78 const QPointF& center, double radius ) const QWT_OVERRIDE; 75 79 76 virtual void keyPressEvent( QKeyEvent * );80 virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 77 81 78 private: 82 private: 79 83 class PrivateData; 80 PrivateData *d_data;84 PrivateData* m_data; 81 85 }; 82 86 -
trunk/BNC/qwt/qwt_compass_rose.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_compass_rose.h" 11 11 #include "qwt_point_polar.h" 12 #include "qwt_painter.h" 12 13 13 #include <qpainter.h> 14 14 #include <qpainterpath.h> … … 21 21 22 22 QPointF pos; 23 #if QT_VERSION >= 0x050e00 24 if ( line1.intersects( line2, &pos ) == QLineF::NoIntersection ) 25 #else 23 26 if ( line1.intersect( line2, &pos ) == QLineF::NoIntersection ) 27 #endif 24 28 return QPointF(); 25 29 … … 27 31 } 28 32 33 //! Constructor 34 QwtCompassRose::QwtCompassRose() 35 { 36 } 37 38 //! Destructor 39 QwtCompassRose::~QwtCompassRose() 40 { 41 } 42 43 //! Assign a palette 44 void QwtCompassRose::setPalette( const QPalette& p ) 45 { 46 m_palette = p; 47 } 48 49 //! \return Current palette 50 const QPalette& QwtCompassRose::palette() const 51 { 52 return m_palette; 53 } 54 29 55 class QwtSimpleCompassRose::PrivateData 30 56 { 31 public: 32 PrivateData() :33 width( 0.2 ) ,34 numThorns( 8 ) ,35 numThornLevels( -1 ) ,36 shrinkFactor( 0.9 ) 57 public: 58 PrivateData() 59 : width( 0.2 ) 60 , numThorns( 8 ) 61 , numThornLevels( -1 ) 62 , shrinkFactor( 0.9 ) 37 63 { 38 64 } … … 49 75 \param numThorns Number of thorns 50 76 \param numThornLevels Number of thorn levels 51 */ 77 */ 52 78 QwtSimpleCompassRose::QwtSimpleCompassRose( 53 79 int numThorns, int numThornLevels ) 54 80 { 55 d_data = new PrivateData();56 d_data->numThorns = numThorns;57 d_data->numThornLevels = numThornLevels;81 m_data = new PrivateData(); 82 m_data->numThorns = numThorns; 83 m_data->numThornLevels = numThornLevels; 58 84 59 85 const QColor dark( 128, 128, 255 ); … … 70 96 QwtSimpleCompassRose::~QwtSimpleCompassRose() 71 97 { 72 delete d_data;73 } 74 75 /*! 76 Set the Factor how to shrink the thorns with each level 77 The default value is 0.9. 78 79 \param factor Shrink factor 80 \sa shrinkFactor() 81 */ 98 delete m_data; 99 } 100 101 /*! 102 Set the Factor how to shrink the thorns with each level 103 The default value is 0.9. 104 105 \param factor Shrink factor 106 \sa shrinkFactor() 107 */ 82 108 void QwtSimpleCompassRose::setShrinkFactor( double factor ) 83 109 { 84 d_data->shrinkFactor = factor;85 } 86 87 /*! 88 \return Factor how to shrink the thorns with each level 89 \sa setShrinkFactor() 90 */ 110 m_data->shrinkFactor = factor; 111 } 112 113 /*! 114 \return Factor how to shrink the thorns with each level 115 \sa setShrinkFactor() 116 */ 91 117 double QwtSimpleCompassRose::shrinkFactor() const 92 118 { 93 return d_data->shrinkFactor;119 return m_data->shrinkFactor; 94 120 } 95 121 … … 102 128 \param north Position 103 129 \param cg Color group 104 */ 105 void QwtSimpleCompassRose::draw( QPainter *painter, const QPointF¢er,130 */ 131 void QwtSimpleCompassRose::draw( QPainter* painter, const QPointF& center, 106 132 double radius, double north, QPalette::ColorGroup cg ) const 107 133 { … … 109 135 pal.setCurrentColorGroup( cg ); 110 136 111 drawRose( painter, pal, center, radius, north, d_data->width,112 d_data->numThorns,d_data->numThornLevels,d_data->shrinkFactor );137 drawRose( painter, pal, center, radius, north, m_data->width, 138 m_data->numThorns, m_data->numThornLevels, m_data->shrinkFactor ); 113 139 } 114 140 … … 125 151 \param numThornLevels Number of thorn levels 126 152 \param shrinkFactor Factor to shrink the thorns with each level 127 */ 153 */ 128 154 void QwtSimpleCompassRose::drawRose( 129 QPainter *painter,130 const QPalette &palette,131 const QPointF ¢er, double radius, double north, double width,155 QPainter* painter, 156 const QPalette& palette, 157 const QPointF& center, double radius, double north, double width, 132 158 int numThorns, int numThornLevels, double shrinkFactor ) 133 159 { … … 153 179 for ( int j = 1; j <= numThornLevels; j++ ) 154 180 { 155 double step = qPow( 2.0, j ) * M_PI / numThorns;181 double step = std::pow( 2.0, j ) * M_PI / numThorns; 156 182 if ( step > M_PI_2 ) 157 183 break; … … 203 229 204 230 \param width Width 205 */ 231 */ 206 232 void QwtSimpleCompassRose::setWidth( double width ) 207 233 { 208 d_data->width = width;209 if ( d_data->width < 0.03 )210 d_data->width = 0.03;211 212 if ( d_data->width > 0.4 )213 d_data->width = 0.4;214 } 215 216 /*! 217 \return Width of the rose 218 \sa setWidth() 234 m_data->width = width; 235 if ( m_data->width < 0.03 ) 236 m_data->width = 0.03; 237 238 if ( m_data->width > 0.4 ) 239 m_data->width = 0.4; 240 } 241 242 /*! 243 \return Width of the rose 244 \sa setWidth() 219 245 */ 220 246 double QwtSimpleCompassRose::width() const 221 247 { 222 return d_data->width;223 } 224 225 /*! 226 Set the number of thorns on one level 227 The number is aligned to a multiple of 4, with a minimum of 4 228 229 \param numThorns Number of thorns 230 \sa numThorns(), setNumThornLevels() 231 */ 248 return m_data->width; 249 } 250 251 /*! 252 Set the number of thorns on one level 253 The number is aligned to a multiple of 4, with a minimum of 4 254 255 \param numThorns Number of thorns 256 \sa numThorns(), setNumThornLevels() 257 */ 232 258 void QwtSimpleCompassRose::setNumThorns( int numThorns ) 233 259 { … … 238 264 numThorns += 4 - numThorns % 4; 239 265 240 d_data->numThorns = numThorns;266 m_data->numThorns = numThorns; 241 267 } 242 268 … … 244 270 \return Number of thorns 245 271 \sa setNumThorns(), setNumThornLevels() 246 */ 272 */ 247 273 int QwtSimpleCompassRose::numThorns() const 248 274 { 249 return d_data->numThorns;250 } 251 252 /*! 253 Set the of thorns levels 254 255 \param numThornLevels Number of thorns levels 256 \sa setNumThorns(), numThornLevels() 257 */ 275 return m_data->numThorns; 276 } 277 278 /*! 279 Set the of thorns levels 280 281 \param numThornLevels Number of thorns levels 282 \sa setNumThorns(), numThornLevels() 283 */ 258 284 void QwtSimpleCompassRose::setNumThornLevels( int numThornLevels ) 259 285 { 260 d_data->numThornLevels = numThornLevels;286 m_data->numThornLevels = numThornLevels; 261 287 } 262 288 … … 264 290 \return Number of thorn levels 265 291 \sa setNumThorns(), setNumThornLevels() 266 */ 292 */ 267 293 int QwtSimpleCompassRose::numThornLevels() const 268 294 { 269 return d_data->numThornLevels;270 } 295 return m_data->numThornLevels; 296 } -
trunk/BNC/qwt/qwt_compass_rose.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_COMPASS_ROSE_H 11 #define QWT_COMPASS_ROSE_H 111 #define QWT_COMPASS_ROSE_H 12 12 13 13 #include "qwt_global.h" … … 17 17 18 18 /*! 19 \brief Abstract base class for a compass rose 20 */ 19 \brief Abstract base class for a compass rose 20 */ 21 21 class QWT_EXPORT QwtCompassRose 22 22 { 23 public: 24 //! Destructor25 virtual ~QwtCompassRose() {};23 public: 24 QwtCompassRose(); 25 virtual ~QwtCompassRose(); 26 26 27 //! Assign a palette 28 virtual void setPalette( const QPalette &p ) 29 { 30 d_palette = p; 31 } 32 33 //! \return Current palette 34 const QPalette &palette() const 35 { 36 return d_palette; 37 } 27 virtual void setPalette( const QPalette& ); 28 const QPalette& palette() const; 38 29 39 30 /*! … … 46 37 \param colorGroup Color group 47 38 */ 48 virtual void draw( QPainter *painter,49 const QPointF ¢er, double radius, double north,39 virtual void draw( QPainter* painter, 40 const QPointF& center, double radius, double north, 50 41 QPalette::ColorGroup colorGroup = QPalette::Active ) const = 0; 51 42 52 private: 53 QPalette d_palette; 43 private: 44 Q_DISABLE_COPY(QwtCompassRose) 45 46 QPalette m_palette; 54 47 }; 55 48 56 49 /*! 57 \brief A simple rose for QwtCompass 58 */ 59 class QWT_EXPORT QwtSimpleCompassRose: public QwtCompassRose 50 \brief A simple rose for QwtCompass 51 */ 52 class QWT_EXPORT QwtSimpleCompassRose : public QwtCompassRose 60 53 { 61 public: 54 public: 62 55 QwtSimpleCompassRose( int numThorns = 8, int numThornLevels = -1 ); 63 56 virtual ~QwtSimpleCompassRose(); … … 75 68 double shrinkFactor() const; 76 69 77 virtual void draw( QPainter *, const QPointF ¢er, double radius, 78 double north, QPalette::ColorGroup = QPalette::Active ) const; 70 virtual void draw( QPainter*, 71 const QPointF& center, double radius, double north, 72 QPalette::ColorGroup = QPalette::Active ) const QWT_OVERRIDE; 79 73 80 static void drawRose( QPainter *, const QPalette&,81 const QPointF ¢er, double radius, double north, double width,74 static void drawRose( QPainter*, const QPalette&, 75 const QPointF& center, double radius, double north, double width, 82 76 int numThorns, int numThornLevels, double shrinkFactor ); 83 77 84 private: 78 private: 85 79 class PrivateData; 86 PrivateData *d_data;80 PrivateData* m_data; 87 81 }; 88 82 -
trunk/BNC/qwt/qwt_counter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_arrow_button.h" 11 #include "qwt_counter.h" 12 #include "qwt_painter.h" 11 13 #include "qwt_math.h" 12 #include "qwt_counter.h" 14 13 15 #include <qlayout.h> 14 16 #include <qlineedit.h> … … 19 21 class QwtCounter::PrivateData 20 22 { 21 public: 22 PrivateData() :23 minimum( 0.0 ) ,24 maximum( 0.0 ) ,25 singleStep( 1.0 ) ,26 isValid( false ) ,27 value( 0.0 ) ,28 wrapping( false ) 23 public: 24 PrivateData() 25 : minimum( 0.0 ) 26 , maximum( 0.0 ) 27 , singleStep( 1.0 ) 28 , isValid( false ) 29 , value( 0.0 ) 30 , wrapping( false ) 29 31 { 30 32 increment[Button1] = 1; … … 33 35 } 34 36 35 QwtArrowButton *buttonDown[ButtonCnt];36 QwtArrowButton *buttonUp[ButtonCnt];37 QLineEdit *valueEdit;37 QwtArrowButton* buttonDown[ButtonCnt]; 38 QwtArrowButton* buttonUp[ButtonCnt]; 39 QLineEdit* valueEdit; 38 40 39 41 int increment[ButtonCnt]; … … 51 53 52 54 /*! 53 The counter is initialized with a range is set to [0.0, 1.0] with 54 0.01 as single step size. The value is invalid. 55 56 The default number of buttons is set to 2. The default increments are: 57 \li Button 1: 1 step 58 \li Button 2: 10 steps 59 \li Button 3: 100 steps 60 61 \param parent 62 */ 63 QwtCounter::QwtCounter( QWidget *parent ):64 QWidget( parent ) 55 The counter is initialized with a range is set to [0.0, 1.0] with 56 0.01 as single step size. The value is invalid. 57 58 The default number of buttons is set to 2. The default increments are: 59 \li Button 1: 1 step 60 \li Button 2: 10 steps 61 \li Button 3: 100 steps 62 63 \param parent 64 */ 65 QwtCounter::QwtCounter( QWidget* parent ) 66 : QWidget( parent ) 65 67 { 66 68 initCounter(); … … 69 71 void QwtCounter::initCounter() 70 72 { 71 d_data = new PrivateData;72 73 QHBoxLayout *layout = new QHBoxLayout( this );73 m_data = new PrivateData; 74 75 QHBoxLayout* layout = new QHBoxLayout( this ); 74 76 layout->setSpacing( 0 ); 75 layout->set Margin( 0);77 layout->setContentsMargins( QMargins() ); 76 78 77 79 for ( int i = ButtonCnt - 1; i >= 0; i-- ) 78 80 { 79 QwtArrowButton *btn =81 QwtArrowButton* btn = 80 82 new QwtArrowButton( i + 1, Qt::DownArrow, this ); 81 83 btn->setFocusPolicy( Qt::NoFocus ); 82 btn->installEventFilter( this );83 84 layout->addWidget( btn ); 84 85 … … 86 87 connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) ); 87 88 88 d_data->buttonDown[i] = btn;89 } 90 91 d_data->valueEdit = new QLineEdit( this );92 d_data->valueEdit->setReadOnly( false );93 d_data->valueEdit->setValidator( new QDoubleValidator(d_data->valueEdit ) );94 layout->addWidget( d_data->valueEdit );95 96 connect( d_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );97 98 layout->setStretchFactor( d_data->valueEdit, 10 );89 m_data->buttonDown[i] = btn; 90 } 91 92 m_data->valueEdit = new QLineEdit( this ); 93 m_data->valueEdit->setReadOnly( false ); 94 m_data->valueEdit->setValidator( new QDoubleValidator( m_data->valueEdit ) ); 95 layout->addWidget( m_data->valueEdit ); 96 97 connect( m_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) ); 98 99 layout->setStretchFactor( m_data->valueEdit, 10 ); 99 100 100 101 for ( int i = 0; i < ButtonCnt; i++ ) 101 102 { 102 QwtArrowButton *btn =103 QwtArrowButton* btn = 103 104 new QwtArrowButton( i + 1, Qt::UpArrow, this ); 104 105 btn->setFocusPolicy( Qt::NoFocus ); 105 btn->installEventFilter( this );106 106 layout->addWidget( btn ); 107 107 … … 109 109 connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) ); 110 110 111 d_data->buttonUp[i] = btn;111 m_data->buttonUp[i] = btn; 112 112 } 113 113 … … 120 120 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); 121 121 122 setFocusProxy( d_data->valueEdit );122 setFocusProxy( m_data->valueEdit ); 123 123 setFocusPolicy( Qt::StrongFocus ); 124 124 } … … 127 127 QwtCounter::~QwtCounter() 128 128 { 129 delete d_data;130 } 131 132 /*! 133 Set the counter to be in valid/invalid state 134 135 When the counter is set to invalid, no numbers are displayed and 136 the buttons are disabled. 137 138 \param on If true the counter will be set as valid 139 140 \sa setValue(), isValid() 141 */ 129 delete m_data; 130 } 131 132 /*! 133 Set the counter to be in valid/invalid state 134 135 When the counter is set to invalid, no numbers are displayed and 136 the buttons are disabled. 137 138 \param on If true the counter will be set as valid 139 140 \sa setValue(), isValid() 141 */ 142 142 void QwtCounter::setValid( bool on ) 143 143 { 144 if ( on != d_data->isValid )145 { 146 d_data->isValid = on;144 if ( on != m_data->isValid ) 145 { 146 m_data->isValid = on; 147 147 148 148 updateButtons(); 149 149 150 if ( d_data->isValid )150 if ( m_data->isValid ) 151 151 { 152 152 showNumber( value() ); … … 155 155 else 156 156 { 157 d_data->valueEdit->setText( QString() );158 } 159 } 160 } 161 162 /*! 163 \return True, if the value is valid 164 \sa setValid(), setValue() 157 m_data->valueEdit->setText( QString() ); 158 } 159 } 160 } 161 162 /*! 163 \return True, if the value is valid 164 \sa setValid(), setValue() 165 165 */ 166 166 bool QwtCounter::isValid() const 167 167 { 168 return d_data->isValid;169 } 170 171 /*! 172 \brief Allow/disallow the user to manually edit the value 173 174 \param on True disable editing 175 \sa isReadOnly() 176 */ 168 return m_data->isValid; 169 } 170 171 /*! 172 \brief Allow/disallow the user to manually edit the value 173 174 \param on True disable editing 175 \sa isReadOnly() 176 */ 177 177 void QwtCounter::setReadOnly( bool on ) 178 178 { 179 d_data->valueEdit->setReadOnly( on );179 m_data->valueEdit->setReadOnly( on ); 180 180 } 181 181 182 182 /*! 183 183 \return True, when the line line edit is read only. (default is no) 184 \sa setReadOnly() 184 \sa setReadOnly() 185 185 */ 186 186 bool QwtCounter::isReadOnly() const 187 187 { 188 return d_data->valueEdit->isReadOnly();189 } 190 191 /*! 192 \brief Set a new value without adjusting to the step raster 193 194 The state of the counter is set to be valid. 195 196 \param value New value 197 198 \sa isValid(), value(), valueChanged() 199 \warning The value is clipped when it lies outside the range. 200 */ 188 return m_data->valueEdit->isReadOnly(); 189 } 190 191 /*! 192 \brief Set a new value without adjusting to the step raster 193 194 The state of the counter is set to be valid. 195 196 \param value New value 197 198 \sa isValid(), value(), valueChanged() 199 \warning The value is clipped when it lies outside the range. 200 */ 201 201 202 202 void QwtCounter::setValue( double value ) 203 203 { 204 const double vmin = q Min( d_data->minimum,d_data->maximum );205 const double vmax = q Max( d_data->minimum,d_data->maximum );204 const double vmin = qwtMinF( m_data->minimum, m_data->maximum ); 205 const double vmax = qwtMaxF( m_data->minimum, m_data->maximum ); 206 206 207 207 value = qBound( vmin, value, vmax ); 208 208 209 if ( ! d_data->isValid || value !=d_data->value )210 { 211 d_data->isValid = true;212 d_data->value = value;209 if ( !m_data->isValid || value != m_data->value ) 210 { 211 m_data->isValid = true; 212 m_data->value = value; 213 213 214 214 showNumber( value ); … … 220 220 221 221 /*! 222 \return Current value of the counter 223 \sa setValue(), valueChanged() 222 \return Current value of the counter 223 \sa setValue(), valueChanged() 224 224 */ 225 225 double QwtCounter::value() const 226 226 { 227 return d_data->value;228 } 229 230 /*! 231 \brief Set the minimum and maximum values 232 233 The maximum is adjusted if necessary to ensure that the range remains valid. 234 The value might be modified to be inside of the range. 235 236 \param min Minimum value 237 \param max Maximum value 238 239 \sa minimum(), maximum() 227 return m_data->value; 228 } 229 230 /*! 231 \brief Set the minimum and maximum values 232 233 The maximum is adjusted if necessary to ensure that the range remains valid. 234 The value might be modified to be inside of the range. 235 236 \param min Minimum value 237 \param max Maximum value 238 239 \sa minimum(), maximum() 240 240 */ 241 241 void QwtCounter::setRange( double min, double max ) 242 242 { 243 max = q Max( min, max );244 245 if ( d_data->maximum == max &&d_data->minimum == min )243 max = qwtMaxF( min, max ); 244 245 if ( m_data->maximum == max && m_data->minimum == min ) 246 246 return; 247 247 248 d_data->minimum = min;249 d_data->maximum = max;248 m_data->minimum = min; 249 m_data->maximum = max; 250 250 251 251 setSingleStep( singleStep() ); 252 252 253 const double value = qBound( min, d_data->value, max );254 255 if ( value != d_data->value )256 { 257 d_data->value = value;258 259 if ( d_data->isValid )253 const double value = qBound( min, m_data->value, max ); 254 255 if ( value != m_data->value ) 256 { 257 m_data->value = value; 258 259 if ( m_data->isValid ) 260 260 { 261 261 showNumber( value ); … … 268 268 269 269 /*! 270 Set the minimum value of the range 271 272 \param value Minimum value 273 \sa setRange(), setMaximum(), minimum() 274 275 \note The maximum is adjusted if necessary to ensure that the range remains valid. 276 */ 270 Set the minimum value of the range 271 272 \param value Minimum value 273 \sa setRange(), setMaximum(), minimum() 274 275 \note The maximum is adjusted if necessary to ensure that the range remains valid. 276 */ 277 277 void QwtCounter::setMinimum( double value ) 278 278 { … … 281 281 282 282 /*! 283 \return The minimum of the range 284 \sa setRange(), setMinimum(), maximum() 285 */ 283 \return The minimum of the range 284 \sa setRange(), setMinimum(), maximum() 285 */ 286 286 double QwtCounter::minimum() const 287 287 { 288 return d_data->minimum;289 } 290 291 /*! 292 Set the maximum value of the range 293 294 \param value Maximum value 295 \sa setRange(), setMinimum(), maximum() 296 */ 288 return m_data->minimum; 289 } 290 291 /*! 292 Set the maximum value of the range 293 294 \param value Maximum value 295 \sa setRange(), setMinimum(), maximum() 296 */ 297 297 void QwtCounter::setMaximum( double value ) 298 298 { … … 301 301 302 302 /*! 303 \return The maximum of the range 304 \sa setRange(), setMaximum(), minimum() 305 */ 303 \return The maximum of the range 304 \sa setRange(), setMaximum(), minimum() 305 */ 306 306 double QwtCounter::maximum() const 307 307 { 308 return d_data->maximum;309 } 310 311 /*! 312 \brief Set the step size of the counter 313 314 A value <= 0.0 disables stepping 315 316 \param stepSize Single step size 317 \sa singleStep() 318 */ 308 return m_data->maximum; 309 } 310 311 /*! 312 \brief Set the step size of the counter 313 314 A value <= 0.0 disables stepping 315 316 \param stepSize Single step size 317 \sa singleStep() 318 */ 319 319 void QwtCounter::setSingleStep( double stepSize ) 320 320 { 321 d_data->singleStep = qMax( stepSize, 0.0 );322 } 323 324 /*! 325 \return Single step size 326 \sa setSingleStep() 321 m_data->singleStep = qwtMaxF( stepSize, 0.0 ); 322 } 323 324 /*! 325 \return Single step size 326 \sa setSingleStep() 327 327 */ 328 328 double QwtCounter::singleStep() const 329 329 { 330 return d_data->singleStep;331 } 332 333 /*! 334 \brief En/Disable wrapping 335 336 If wrapping is true stepping up from maximum() value will take 337 you to the minimum() value and vice versa. 338 339 \param on En/Disable wrapping 340 \sa wrapping() 330 return m_data->singleStep; 331 } 332 333 /*! 334 \brief En/Disable wrapping 335 336 If wrapping is true stepping up from maximum() value will take 337 you to the minimum() value and vice versa. 338 339 \param on En/Disable wrapping 340 \sa wrapping() 341 341 */ 342 342 void QwtCounter::setWrapping( bool on ) 343 343 { 344 d_data->wrapping = on;345 } 346 347 /*! 348 \return True, when wrapping is set 349 \sa setWrapping() 344 m_data->wrapping = on; 345 } 346 347 /*! 348 \return True, when wrapping is set 349 \sa setWrapping() 350 350 */ 351 351 bool QwtCounter::wrapping() const 352 352 { 353 return d_data->wrapping;354 } 355 356 /*! 357 Specify the number of buttons on each side of the label 358 359 \param numButtons Number of buttons 360 \sa numButtons() 361 */ 353 return m_data->wrapping; 354 } 355 356 /*! 357 Specify the number of buttons on each side of the label 358 359 \param numButtons Number of buttons 360 \sa numButtons() 361 */ 362 362 void QwtCounter::setNumButtons( int numButtons ) 363 363 { … … 369 369 if ( i < numButtons ) 370 370 { 371 d_data->buttonDown[i]->show();372 d_data->buttonUp[i]->show();371 m_data->buttonDown[i]->show(); 372 m_data->buttonUp[i]->show(); 373 373 } 374 374 else 375 375 { 376 d_data->buttonDown[i]->hide();377 d_data->buttonUp[i]->hide();378 } 379 } 380 381 d_data->numButtons = numButtons;382 } 383 384 /*! 385 \return The number of buttons on each side of the widget. 386 \sa setNumButtons() 387 */ 376 m_data->buttonDown[i]->hide(); 377 m_data->buttonUp[i]->hide(); 378 } 379 } 380 381 m_data->numButtons = numButtons; 382 } 383 384 /*! 385 \return The number of buttons on each side of the widget. 386 \sa setNumButtons() 387 */ 388 388 int QwtCounter::numButtons() const 389 389 { 390 return d_data->numButtons;391 } 392 393 /*! 394 Specify the number of steps by which the value 395 is incremented or decremented when a specified button 396 is pushed. 397 398 \param button Button index 399 \param numSteps Number of steps 400 401 \sa incSteps() 402 */ 390 return m_data->numButtons; 391 } 392 393 /*! 394 Specify the number of steps by which the value 395 is incremented or decremented when a specified button 396 is pushed. 397 398 \param button Button index 399 \param numSteps Number of steps 400 401 \sa incSteps() 402 */ 403 403 void QwtCounter::setIncSteps( QwtCounter::Button button, int numSteps ) 404 404 { 405 405 if ( button >= 0 && button < QwtCounter::ButtonCnt ) 406 d_data->increment[ button ] = numSteps;407 } 408 409 /*! 410 \return The number of steps by which a specified button increments the value 406 m_data->increment[ button ] = numSteps; 407 } 408 409 /*! 410 \return The number of steps by which a specified button increments the value 411 411 or 0 if the button is invalid. 412 \param button Button index 413 414 \sa setIncSteps() 415 */ 412 \param button Button index 413 414 \sa setIncSteps() 415 */ 416 416 int QwtCounter::incSteps( QwtCounter::Button button ) const 417 417 { 418 418 if ( button >= 0 && button < QwtCounter::ButtonCnt ) 419 return d_data->increment[ button ];419 return m_data->increment[ button ]; 420 420 421 421 return 0; … … 424 424 425 425 /*! 426 Set the number of increment steps for button 1 427 \param nSteps Number of steps 428 */ 426 Set the number of increment steps for button 1 427 \param nSteps Number of steps 428 */ 429 429 void QwtCounter::setStepButton1( int nSteps ) 430 430 { … … 439 439 440 440 /*! 441 Set the number of increment steps for button 2 442 \param nSteps Number of steps 443 */ 441 Set the number of increment steps for button 2 442 \param nSteps Number of steps 443 */ 444 444 void QwtCounter::setStepButton2( int nSteps ) 445 445 { … … 454 454 455 455 /*! 456 Set the number of increment steps for button 3 457 \param nSteps Number of steps 458 */ 456 Set the number of increment steps for button 3 457 \param nSteps Number of steps 458 */ 459 459 void QwtCounter::setStepButton3( int nSteps ) 460 460 { … … 473 473 bool converted = false; 474 474 475 const double value = d_data->valueEdit->text().toDouble( &converted );475 const double value = m_data->valueEdit->text().toDouble( &converted ); 476 476 if ( converted ) 477 477 setValue( value ); … … 482 482 \param event Event 483 483 \return see QWidget::event() 484 */ 485 bool QwtCounter::event( QEvent *event )484 */ 485 bool QwtCounter::event( QEvent* event ) 486 486 { 487 487 if ( event->type() == QEvent::PolishRequest ) 488 488 { 489 const int w = d_data->valueEdit->fontMetrics().width( "W" ) + 8; 489 const QFontMetrics fm = m_data->valueEdit->fontMetrics(); 490 491 const int w = QwtPainter::horizontalAdvance( fm, "W" ) + 8; 490 492 for ( int i = 0; i < ButtonCnt; i++ ) 491 493 { 492 d_data->buttonDown[i]->setMinimumWidth( w );493 d_data->buttonUp[i]->setMinimumWidth( w );494 m_data->buttonDown[i]->setMinimumWidth( w ); 495 m_data->buttonUp[i]->setMinimumWidth( w ); 494 496 } 495 497 } … … 499 501 500 502 /*! 501 Handle key events 502 503 - Ctrl + Qt::Key_Home\n 503 Handle key events 504 505 - Ctrl + Qt::Key_Home\n 504 506 Step to minimum() 505 - Ctrl + Qt::Key_End\n 507 - Ctrl + Qt::Key_End\n 506 508 Step to maximum() 507 - Qt::Key_Up\n 509 - Qt::Key_Up\n 508 510 Increment by incSteps(QwtCounter::Button1) 509 - Qt::Key_Down\n 511 - Qt::Key_Down\n 510 512 Decrement by incSteps(QwtCounter::Button1) 511 - Qt::Key_PageUp\n 513 - Qt::Key_PageUp\n 512 514 Increment by incSteps(QwtCounter::Button2) 513 - Qt::Key_PageDown\n 515 - Qt::Key_PageDown\n 514 516 Decrement by incSteps(QwtCounter::Button2) 515 - Shift + Qt::Key_PageUp\n 517 - Shift + Qt::Key_PageUp\n 516 518 Increment by incSteps(QwtCounter::Button3) 517 - Shift + Qt::Key_PageDown\n 519 - Shift + Qt::Key_PageDown\n 518 520 Decrement by incSteps(QwtCounter::Button3) 519 521 520 \param event Key event 521 */ 522 void QwtCounter::keyPressEvent ( QKeyEvent *event )522 \param event Key event 523 */ 524 void QwtCounter::keyPressEvent ( QKeyEvent* event ) 523 525 { 524 526 bool accepted = true; … … 544 546 case Qt::Key_Up: 545 547 { 546 incrementValue( d_data->increment[0] );548 incrementValue( m_data->increment[0] ); 547 549 break; 548 550 } 549 551 case Qt::Key_Down: 550 552 { 551 incrementValue( - d_data->increment[0] );553 incrementValue( -m_data->increment[0] ); 552 554 break; 553 555 } … … 555 557 case Qt::Key_PageDown: 556 558 { 557 int increment = d_data->increment[0];558 if ( d_data->numButtons >= 2 )559 increment = d_data->increment[1];560 if ( d_data->numButtons >= 3 )559 int increment = m_data->increment[0]; 560 if ( m_data->numButtons >= 2 ) 561 increment = m_data->increment[1]; 562 if ( m_data->numButtons >= 3 ) 561 563 { 562 564 if ( event->modifiers() & Qt::ShiftModifier ) 563 increment = d_data->increment[2];565 increment = m_data->increment[2]; 564 566 } 565 567 if ( event->key() == Qt::Key_PageDown ) … … 584 586 585 587 /*! 586 Handle wheel events 587 \param event Wheel event 588 */ 589 void QwtCounter::wheelEvent( QWheelEvent *event )588 Handle wheel events 589 \param event Wheel event 590 */ 591 void QwtCounter::wheelEvent( QWheelEvent* event ) 590 592 { 591 593 event->accept(); 592 594 593 if ( d_data->numButtons <= 0 )595 if ( m_data->numButtons <= 0 ) 594 596 return; 595 597 596 int increment = d_data->increment[0];597 if ( d_data->numButtons >= 2 )598 int increment = m_data->increment[0]; 599 if ( m_data->numButtons >= 2 ) 598 600 { 599 601 if ( event->modifiers() & Qt::ControlModifier ) 600 increment = d_data->increment[1];601 } 602 if ( d_data->numButtons >= 3 )602 increment = m_data->increment[1]; 603 } 604 if ( m_data->numButtons >= 3 ) 603 605 { 604 606 if ( event->modifiers() & Qt::ShiftModifier ) 605 increment = d_data->increment[2]; 606 } 607 608 for ( int i = 0; i < d_data->numButtons; i++ ) 609 { 610 if ( d_data->buttonDown[i]->geometry().contains( event->pos() ) || 611 d_data->buttonUp[i]->geometry().contains( event->pos() ) ) 612 { 613 increment = d_data->increment[i]; 614 } 615 } 616 617 const int wheel_delta = 120; 607 increment = m_data->increment[2]; 608 } 609 610 #if QT_VERSION < 0x050e00 611 const QPoint wheelPos = event->pos(); 612 const int wheelDelta = event->delta(); 613 #else 614 const QPoint wheelPos = event->position().toPoint(); 615 616 const QPoint delta = event->angleDelta(); 617 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) ) 618 ? delta.x() : delta.y(); 619 #endif 620 621 for ( int i = 0; i < m_data->numButtons; i++ ) 622 { 623 if ( m_data->buttonDown[i]->geometry().contains( wheelPos ) || 624 m_data->buttonUp[i]->geometry().contains( wheelPos ) ) 625 { 626 increment = m_data->increment[i]; 627 } 628 } 629 630 incrementValue( wheelDelta / 120 * increment ); 631 } 632 633 void QwtCounter::incrementValue( int numSteps ) 634 { 635 const double min = m_data->minimum; 636 const double max = m_data->maximum; 637 double stepSize = m_data->singleStep; 638 639 if ( !m_data->isValid || min >= max || stepSize <= 0.0 ) 640 return; 641 618 642 619 643 #if 1 620 int delta = event->delta(); 621 if ( delta >= 2 * wheel_delta ) 622 delta /= 2; // Never saw an abs(delta) < 240 644 stepSize = qwtMaxF( stepSize, 1.0e-10 * ( max - min ) ); 623 645 #endif 624 646 625 incrementValue( delta / wheel_delta * increment ); 626 } 627 628 void QwtCounter::incrementValue( int numSteps ) 629 { 630 const double min = d_data->minimum; 631 const double max = d_data->maximum; 632 double stepSize = d_data->singleStep; 633 634 if ( !d_data->isValid || min >= max || stepSize <= 0.0 ) 635 return; 636 637 638 #if 1 639 stepSize = qMax( stepSize, 1.0e-10 * ( max - min ) ); 640 #endif 641 642 double value = d_data->value + numSteps * stepSize; 643 644 if ( d_data->wrapping ) 647 double value = m_data->value + numSteps * stepSize; 648 649 if ( m_data->wrapping ) 645 650 { 646 651 const double range = max - min; … … 648 653 if ( value < min ) 649 654 { 650 value += ::ceil( ( min - value ) / range ) * range; 655 value += std::ceil( ( min - value ) / range ) * range; 651 656 } 652 657 else if ( value > max ) 653 658 { 654 value -= ::ceil( ( value - max ) / range ) * range; 659 value -= std::ceil( ( value - max ) / range ) * range; 655 660 } 656 661 } … … 676 681 } 677 682 678 if ( value != d_data->value )679 { 680 d_data->value = value;681 showNumber( d_data->value );683 if ( value != m_data->value ) 684 { 685 m_data->value = value; 686 showNumber( m_data->value ); 682 687 updateButtons(); 683 688 684 Q_EMIT valueChanged( d_data->value );685 } 686 } 687 688 689 /*! 690 \brief Update buttons according to the current value 691 692 When the QwtCounter under- or over-flows, the focus is set to the smallest 693 up- or down-button and counting is disabled. 694 695 Counting is re-enabled on a button release event (mouse or space bar). 696 */ 689 Q_EMIT valueChanged( m_data->value ); 690 } 691 } 692 693 694 /*! 695 \brief Update buttons according to the current value 696 697 When the QwtCounter under- or over-flows, the focus is set to the smallest 698 up- or down-button and counting is disabled. 699 700 Counting is re-enabled on a button release event (mouse or space bar). 701 */ 697 702 void QwtCounter::updateButtons() 698 703 { 699 if ( d_data->isValid )704 if ( m_data->isValid ) 700 705 { 701 706 // 1. save enabled state of the smallest down- and up-button … … 704 709 for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) 705 710 { 706 d_data->buttonDown[i]->setEnabled( value() > minimum() );707 d_data->buttonUp[i]->setEnabled( value() < maximum() );711 m_data->buttonDown[i]->setEnabled( value() > minimum() ); 712 m_data->buttonUp[i]->setEnabled( value() < maximum() ); 708 713 } 709 714 } … … 712 717 for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) 713 718 { 714 d_data->buttonDown[i]->setEnabled( false );715 d_data->buttonUp[i]->setEnabled( false );716 } 717 } 718 } 719 /*! 720 Display number string 721 722 \param number Number 723 */ 719 m_data->buttonDown[i]->setEnabled( false ); 720 m_data->buttonUp[i]->setEnabled( false ); 721 } 722 } 723 } 724 /*! 725 Display number string 726 727 \param number Number 728 */ 724 729 void QwtCounter::showNumber( double number ) 725 730 { … … 727 732 text.setNum( number ); 728 733 729 const int cursorPos = d_data->valueEdit->cursorPosition();730 d_data->valueEdit->setText( text );731 d_data->valueEdit->setCursorPosition( cursorPos );734 const int cursorPos = m_data->valueEdit->cursorPosition(); 735 m_data->valueEdit->setText( text ); 736 m_data->valueEdit->setCursorPosition( cursorPos ); 732 737 } 733 738 … … 737 742 for ( int i = 0; i < ButtonCnt; i++ ) 738 743 { 739 if ( d_data->buttonUp[i] == sender() )740 incrementValue( d_data->increment[i] );741 742 if ( d_data->buttonDown[i] == sender() )743 incrementValue( - d_data->increment[i] );744 if ( m_data->buttonUp[i] == sender() ) 745 incrementValue( m_data->increment[i] ); 746 747 if ( m_data->buttonDown[i] == sender() ) 748 incrementValue( -m_data->increment[i] ); 744 749 } 745 750 } … … 769 774 tmp.fill( '9', w ); 770 775 771 QFontMetrics fm( d_data->valueEdit->font() );772 w = fm.width( tmp ) + 2; 773 if ( d_data->valueEdit->hasFrame() )776 w = QwtPainter::horizontalAdvance( m_data->valueEdit->fontMetrics(), tmp ) + 2; 777 778 if ( m_data->valueEdit->hasFrame() ) 774 779 w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); 775 780 776 // Now we replace default sizeHint contribution of d_data->valueEdit by781 // Now we replace default sizeHint contribution of m_data->valueEdit by 777 782 // what we really need. 778 783 779 w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width();784 w += QWidget::sizeHint().width() - m_data->valueEdit->sizeHint().width(); 780 785 781 786 const int h = qMin( QWidget::sizeHint().height(), 782 d_data->valueEdit->minimumSizeHint().height() ); 787 m_data->valueEdit->minimumSizeHint().height() ); 788 783 789 return QSize( w, h ); 784 790 } 791 792 #include "moc_qwt_counter.cpp" -
trunk/BNC/qwt/qwt_counter.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 16 16 /*! 17 \brief The Counter Widget 17 \brief The Counter Widget 18 18 19 A Counter consists of a label displaying a number and 20 one ore more (up to three) push buttons on each side 21 of the label which can be used to increment or decrement 22 the counter's value. 19 A Counter consists of a label displaying a number and 20 one ore more (up to three) push buttons on each side 21 of the label which can be used to increment or decrement 22 the counter's value. 23 23 24 A counter has a range from a minimum value to a maximum value 25 and a step size. When the wrapping property is set 26 the counter is circular. 24 A counter has a range from a minimum value to a maximum value 25 and a step size. When the wrapping property is set 26 the counter is circular. 27 27 28 The number of steps by which a button increments or decrements the value 29 can be specified using setIncSteps(). The number of buttons can be 30 changed with setNumButtons(). 28 The number of steps by which a button increments or decrements the value 29 can be specified using setIncSteps(). The number of buttons can be 30 changed with setNumButtons(). 31 31 32 Example: 33 \code 34 #include <qwt_counter.h> 32 Example: 33 \code 34 #include <qwt_counter.h> 35 35 36 QwtCounter *counter = new QwtCounter(parent); 36 QwtCounter *counter = new QwtCounter(parent); 37 37 38 counter->setRange(0.0, 100.0); // From 0.0 to 100 39 counter->setSingleStep( 1.0 ); // Step size 1.0 40 counter->setNumButtons(2); // Two buttons each side 41 counter->setIncSteps(QwtCounter::Button1, 1); // Button 1 increments 1 step 42 counter->setIncSteps(QwtCounter::Button2, 20); // Button 2 increments 20 steps 38 counter->setRange(0.0, 100.0); // From 0.0 to 100 39 counter->setSingleStep( 1.0 ); // Step size 1.0 40 counter->setNumButtons(2); // Two buttons each side 41 counter->setIncSteps(QwtCounter::Button1, 1); // Button 1 increments 1 step 42 counter->setIncSteps(QwtCounter::Button2, 20); // Button 2 increments 20 steps 43 43 44 connect(counter, SIGNAL(valueChanged(double)), myClass, SLOT(newValue(double))); 45 \endcode 44 connect(counter, SIGNAL(valueChanged(double)), myClass, SLOT(newValue(double))); 45 \endcode 46 46 */ 47 47 … … 50 50 Q_OBJECT 51 51 52 Q_PROPERTY( double value READ value WRITE setValue ) 52 Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged USER true ) 53 53 Q_PROPERTY( double minimum READ minimum WRITE setMinimum ) 54 54 Q_PROPERTY( double maximum READ maximum WRITE setMaximum ) … … 63 63 Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping ) 64 64 65 public: 65 public: 66 66 //! Button index 67 67 enum Button … … 80 80 }; 81 81 82 explicit QwtCounter( QWidget *parent = NULL );82 explicit QwtCounter( QWidget* parent = NULL ); 83 83 virtual ~QwtCounter(); 84 84 … … 98 98 int incSteps( QwtCounter::Button ) const; 99 99 100 virtual QSize sizeHint() const; 100 virtual QSize sizeHint() const QWT_OVERRIDE; 101 101 102 102 double singleStep() const; … … 122 122 double value() const; 123 123 124 public Q_SLOTS: 124 public Q_SLOTS: 125 125 void setValue( double ); 126 126 127 127 128 Q_SIGNALS: 128 Q_SIGNALS: 129 129 /*! 130 130 This signal is emitted when a button has been released 131 131 \param value The new value 132 */ 132 */ 133 133 void buttonReleased ( double value ); 134 134 … … 136 136 This signal is emitted when the counter's value has changed 137 137 \param value The new value 138 */ 138 */ 139 139 void valueChanged ( double value ); 140 140 141 protected: 142 virtual bool event( QEvent * );143 virtual void wheelEvent( QWheelEvent * );144 virtual void keyPressEvent( QKeyEvent * );141 protected: 142 virtual bool event( QEvent* ) QWT_OVERRIDE; 143 virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE; 144 virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 145 145 146 private Q_SLOTS: 146 private Q_SLOTS: 147 147 void btnReleased(); 148 148 void btnClicked(); 149 149 void textChanged(); 150 150 151 private: 151 private: 152 152 void incrementValue( int numSteps ); 153 153 void initCounter(); … … 156 156 157 157 class PrivateData; 158 PrivateData *d_data;158 PrivateData* m_data; 159 159 }; 160 160 -
trunk/BNC/qwt/qwt_curve_fitter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_curve_fitter.h" 11 #include "qwt_math.h"12 #include "qwt_spline.h"13 #include <qstack.h>14 #include <qvector.h>15 11 16 #if QT_VERSION < 0x040601 17 #define qFabs(x) ::fabs(x) 18 #endif 19 20 //! Constructor 21 QwtCurveFitter::QwtCurveFitter()12 /*! 13 Constructor 14 \param mode Preferred fitting mode 15 */ 16 QwtCurveFitter::QwtCurveFitter( Mode mode ) 17 : m_mode( mode ) 22 18 { 23 19 } … … 28 24 } 29 25 30 class QwtSplineCurveFitter::PrivateData 26 //! \return Preferred fitting mode 27 QwtCurveFitter::Mode QwtCurveFitter::mode() const 31 28 { 32 public: 33 PrivateData(): 34 fitMode( QwtSplineCurveFitter::Auto ), 35 splineSize( 250 ) 36 { 37 } 38 39 QwtSpline spline; 40 QwtSplineCurveFitter::FitMode fitMode; 41 int splineSize; 42 }; 43 44 //! Constructor 45 QwtSplineCurveFitter::QwtSplineCurveFitter() 46 { 47 d_data = new PrivateData; 29 return m_mode; 48 30 } 49 50 //! Destructor51 QwtSplineCurveFitter::~QwtSplineCurveFitter()52 {53 delete d_data;54 }55 56 /*!57 Select the algorithm used for building the spline58 59 \param mode Mode representing a spline algorithm60 \sa fitMode()61 */62 void QwtSplineCurveFitter::setFitMode( FitMode mode )63 {64 d_data->fitMode = mode;65 }66 67 /*!68 \return Mode representing a spline algorithm69 \sa setFitMode()70 */71 QwtSplineCurveFitter::FitMode QwtSplineCurveFitter::fitMode() const72 {73 return d_data->fitMode;74 }75 76 /*!77 Assign a spline78 79 \param spline Spline80 \sa spline()81 */82 void QwtSplineCurveFitter::setSpline( const QwtSpline &spline )83 {84 d_data->spline = spline;85 d_data->spline.reset();86 }87 88 /*!89 \return Spline90 \sa setSpline()91 */92 const QwtSpline &QwtSplineCurveFitter::spline() const93 {94 return d_data->spline;95 }96 97 /*!98 \return Spline99 \sa setSpline()100 */101 QwtSpline &QwtSplineCurveFitter::spline()102 {103 return d_data->spline;104 }105 106 /*!107 Assign a spline size ( has to be at least 10 points )108 109 \param splineSize Spline size110 \sa splineSize()111 */112 void QwtSplineCurveFitter::setSplineSize( int splineSize )113 {114 d_data->splineSize = qMax( splineSize, 10 );115 }116 117 /*!118 \return Spline size119 \sa setSplineSize()120 */121 int QwtSplineCurveFitter::splineSize() const122 {123 return d_data->splineSize;124 }125 126 /*!127 Find a curve which has the best fit to a series of data points128 129 \param points Series of data points130 \return Curve points131 */132 QPolygonF QwtSplineCurveFitter::fitCurve( const QPolygonF &points ) const133 {134 const int size = points.size();135 if ( size <= 2 )136 return points;137 138 FitMode fitMode = d_data->fitMode;139 if ( fitMode == Auto )140 {141 fitMode = Spline;142 143 const QPointF *p = points.data();144 for ( int i = 1; i < size; i++ )145 {146 if ( p[i].x() <= p[i-1].x() )147 {148 fitMode = ParametricSpline;149 break;150 }151 };152 }153 154 if ( fitMode == ParametricSpline )155 return fitParametric( points );156 else157 return fitSpline( points );158 }159 160 QPolygonF QwtSplineCurveFitter::fitSpline( const QPolygonF &points ) const161 {162 d_data->spline.setPoints( points );163 if ( !d_data->spline.isValid() )164 return points;165 166 QPolygonF fittedPoints( d_data->splineSize );167 168 const double x1 = points[0].x();169 const double x2 = points[int( points.size() - 1 )].x();170 const double dx = x2 - x1;171 const double delta = dx / ( d_data->splineSize - 1 );172 173 for ( int i = 0; i < d_data->splineSize; i++ )174 {175 QPointF &p = fittedPoints[i];176 177 const double v = x1 + i * delta;178 const double sv = d_data->spline.value( v );179 180 p.setX( v );181 p.setY( sv );182 }183 d_data->spline.reset();184 185 return fittedPoints;186 }187 188 QPolygonF QwtSplineCurveFitter::fitParametric( const QPolygonF &points ) const189 {190 int i;191 const int size = points.size();192 193 QPolygonF fittedPoints( d_data->splineSize );194 QPolygonF splinePointsX( size );195 QPolygonF splinePointsY( size );196 197 const QPointF *p = points.data();198 QPointF *spX = splinePointsX.data();199 QPointF *spY = splinePointsY.data();200 201 double param = 0.0;202 for ( i = 0; i < size; i++ )203 {204 const double x = p[i].x();205 const double y = p[i].y();206 if ( i > 0 )207 {208 const double delta = qSqrt( qwtSqr( x - spX[i-1].y() )209 + qwtSqr( y - spY[i-1].y() ) );210 param += qMax( delta, 1.0 );211 }212 spX[i].setX( param );213 spX[i].setY( x );214 spY[i].setX( param );215 spY[i].setY( y );216 }217 218 d_data->spline.setPoints( splinePointsX );219 if ( !d_data->spline.isValid() )220 return points;221 222 const double deltaX =223 splinePointsX[size - 1].x() / ( d_data->splineSize - 1 );224 for ( i = 0; i < d_data->splineSize; i++ )225 {226 const double dtmp = i * deltaX;227 fittedPoints[i].setX( d_data->spline.value( dtmp ) );228 }229 230 d_data->spline.setPoints( splinePointsY );231 if ( !d_data->spline.isValid() )232 return points;233 234 const double deltaY =235 splinePointsY[size - 1].x() / ( d_data->splineSize - 1 );236 for ( i = 0; i < d_data->splineSize; i++ )237 {238 const double dtmp = i * deltaY;239 fittedPoints[i].setY( d_data->spline.value( dtmp ) );240 }241 242 return fittedPoints;243 }244 245 class QwtWeedingCurveFitter::PrivateData246 {247 public:248 PrivateData():249 tolerance( 1.0 ),250 chunkSize( 0 )251 {252 }253 254 double tolerance;255 uint chunkSize;256 };257 258 class QwtWeedingCurveFitter::Line259 {260 public:261 Line( int i1 = 0, int i2 = 0 ):262 from( i1 ),263 to( i2 )264 {265 }266 267 int from;268 int to;269 };270 271 /*!272 Constructor273 274 \param tolerance Tolerance275 \sa setTolerance(), tolerance()276 */277 QwtWeedingCurveFitter::QwtWeedingCurveFitter( double tolerance )278 {279 d_data = new PrivateData;280 setTolerance( tolerance );281 }282 283 //! Destructor284 QwtWeedingCurveFitter::~QwtWeedingCurveFitter()285 {286 delete d_data;287 }288 289 /*!290 Assign the tolerance291 292 The tolerance is the maximum distance, that is acceptable293 between the original curve and the smoothed curve.294 295 Increasing the tolerance will reduce the number of the296 resulting points.297 298 \param tolerance Tolerance299 300 \sa tolerance()301 */302 void QwtWeedingCurveFitter::setTolerance( double tolerance )303 {304 d_data->tolerance = qMax( tolerance, 0.0 );305 }306 307 /*!308 \return Tolerance309 \sa setTolerance()310 */311 double QwtWeedingCurveFitter::tolerance() const312 {313 return d_data->tolerance;314 }315 316 /*!317 Limit the number of points passed to a run of the algorithm318 319 The runtime of the Douglas Peucker algorithm increases non linear320 with the number of points. For a chunk size > 0 the polygon321 is split into pieces passed to the algorithm one by one.322 323 \param numPoints Maximum for the number of points passed to the algorithm324 325 \sa chunkSize()326 */327 void QwtWeedingCurveFitter::setChunkSize( uint numPoints )328 {329 if ( numPoints > 0 )330 numPoints = qMax( numPoints, 3U );331 332 d_data->chunkSize = numPoints;333 }334 335 /*!336 \return Maximum for the number of points passed to a run337 of the algorithm - or 0, when unlimited338 \sa setChunkSize()339 */340 uint QwtWeedingCurveFitter::chunkSize() const341 {342 return d_data->chunkSize;343 }344 345 /*!346 \param points Series of data points347 \return Curve points348 */349 QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const350 {351 if ( points.isEmpty() )352 return points;353 354 QPolygonF fittedPoints;355 if ( d_data->chunkSize == 0 )356 {357 fittedPoints = simplify( points );358 }359 else360 {361 for ( int i = 0; i < points.size(); i += d_data->chunkSize )362 {363 const QPolygonF p = points.mid( i, d_data->chunkSize );364 fittedPoints += simplify( p );365 }366 }367 368 return fittedPoints;369 }370 371 QPolygonF QwtWeedingCurveFitter::simplify( const QPolygonF &points ) const372 {373 const double toleranceSqr = d_data->tolerance * d_data->tolerance;374 375 QStack<Line> stack;376 stack.reserve( 500 );377 378 const QPointF *p = points.data();379 const int nPoints = points.size();380 381 QVector<bool> usePoint( nPoints, false );382 383 stack.push( Line( 0, nPoints - 1 ) );384 385 while ( !stack.isEmpty() )386 {387 const Line r = stack.pop();388 389 // initialize line segment390 const double vecX = p[r.to].x() - p[r.from].x();391 const double vecY = p[r.to].y() - p[r.from].y();392 393 const double vecLength = qSqrt( vecX * vecX + vecY * vecY );394 395 const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0;396 const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;397 398 double maxDistSqr = 0.0;399 int nVertexIndexMaxDistance = r.from + 1;400 for ( int i = r.from + 1; i < r.to; i++ )401 {402 //compare to anchor403 const double fromVecX = p[i].x() - p[r.from].x();404 const double fromVecY = p[i].y() - p[r.from].y();405 406 double distToSegmentSqr;407 if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )408 {409 distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY;410 }411 else412 {413 const double toVecX = p[i].x() - p[r.to].x();414 const double toVecY = p[i].y() - p[r.to].y();415 const double toVecLength = toVecX * toVecX + toVecY * toVecY;416 417 const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );418 if ( s < 0.0 )419 {420 distToSegmentSqr = toVecLength;421 }422 else423 {424 distToSegmentSqr = qFabs( toVecLength - s * s );425 }426 }427 428 if ( maxDistSqr < distToSegmentSqr )429 {430 maxDistSqr = distToSegmentSqr;431 nVertexIndexMaxDistance = i;432 }433 }434 if ( maxDistSqr <= toleranceSqr )435 {436 usePoint[r.from] = true;437 usePoint[r.to] = true;438 }439 else440 {441 stack.push( Line( r.from, nVertexIndexMaxDistance ) );442 stack.push( Line( nVertexIndexMaxDistance, r.to ) );443 }444 }445 446 QPolygonF stripped;447 for ( int i = 0; i < nPoints; i++ )448 {449 if ( usePoint[i] )450 stripped += p[i];451 }452 453 return stripped;454 } -
trunk/BNC/qwt/qwt_curve_fitter.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include <qpolygon.h>15 #include <qrect.h>16 14 17 class QwtSpline; 15 class QPainterPath; 16 class QPolygonF; 18 17 19 18 /*! 20 \brief Abstract base class for a curve fitter 21 */ 19 \brief Abstract base class for a curve fitter 20 */ 22 21 class QWT_EXPORT QwtCurveFitter 23 22 { 24 public: 23 public: 24 /*! 25 \brief Preferred mode of the fitting algorithm 26 27 Even if a QPainterPath can always be created from a QPolygonF 28 the overhead of the conversion can be avoided by indicating 29 the preference of the implementation to the application 30 code. 31 */ 32 enum Mode 33 { 34 /*! 35 The fitting algorithm creates a polygon - the implementation 36 of fitCurvePath() simply wraps the polygon into a path. 37 38 \sa QwtWeedingCurveFitter 39 */ 40 Polygon, 41 42 /*! 43 The fitting algorithm creates a painter path - the implementation 44 of fitCurve() extracts a polygon from the path. 45 46 \sa QwtSplineCurveFitter 47 */ 48 Path 49 }; 50 25 51 virtual ~QwtCurveFitter(); 52 53 Mode mode() const; 26 54 27 55 /*! … … 30 58 \param polygon Series of data points 31 59 \return Curve points 60 61 \sa fitCurvePath() 32 62 */ 33 virtual QPolygonF fitCurve( const QPolygonF &polygon ) const = 0;63 virtual QPolygonF fitCurve( const QPolygonF& polygon ) const = 0; 34 64 35 protected: 36 QwtCurveFitter();65 /*! 66 Find a curve path which has the best fit to a series of data points 37 67 38 private: 39 QwtCurveFitter( const QwtCurveFitter & ); 40 QwtCurveFitter &operator=( const QwtCurveFitter & ); 41 }; 68 \param polygon Series of data points 69 \return Curve path 42 70 43 /*! 44 \brief A curve fitter using cubic splines 45 */ 46 class QWT_EXPORT QwtSplineCurveFitter: public QwtCurveFitter 47 { 48 public: 49 /*! 50 Spline type 51 The default setting is Auto 52 \sa setFitMode(), FitMode() 71 \sa fitCurve() 53 72 */ 54 enum FitMode 55 { 56 /*! 57 Use the default spline algorithm for polygons with 58 increasing x values ( p[i-1] < p[i] ), otherwise use 59 a parametric spline algorithm. 60 */ 61 Auto, 73 virtual QPainterPath fitCurvePath( const QPolygonF& polygon ) const = 0; 62 74 63 //! Use a default spline algorithm64 Spline,75 protected: 76 explicit QwtCurveFitter( Mode mode ); 65 77 66 //! Use a parametric spline algorithm 67 ParametricSpline 68 }; 78 private: 79 Q_DISABLE_COPY(QwtCurveFitter) 69 80 70 QwtSplineCurveFitter(); 71 virtual ~QwtSplineCurveFitter(); 72 73 void setFitMode( FitMode ); 74 FitMode fitMode() const; 75 76 void setSpline( const QwtSpline& ); 77 const QwtSpline &spline() const; 78 QwtSpline &spline(); 79 80 void setSplineSize( int ); 81 int splineSize() const; 82 83 virtual QPolygonF fitCurve( const QPolygonF & ) const; 84 85 private: 86 QPolygonF fitSpline( const QPolygonF & ) const; 87 QPolygonF fitParametric( const QPolygonF & ) const; 88 89 class PrivateData; 90 PrivateData *d_data; 91 }; 92 93 /*! 94 \brief A curve fitter implementing Douglas and Peucker algorithm 95 96 The purpose of the Douglas and Peucker algorithm is that given a 'curve' 97 composed of line segments to find a curve not too dissimilar but that 98 has fewer points. The algorithm defines 'too dissimilar' based on the 99 maximum distance (tolerance) between the original curve and the 100 smoothed curve. 101 102 The runtime of the algorithm increases non linear ( worst case O( n*n ) ) 103 and might be very slow for huge polygons. To avoid performance issues 104 it might be useful to split the polygon ( setChunkSize() ) and to run the algorithm 105 for these smaller parts. The disadvantage of having no interpolation 106 at the borders is for most use cases irrelevant. 107 108 The smoothed curve consists of a subset of the points that defined the 109 original curve. 110 111 In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces 112 the number of points. By adjusting the tolerance parameter according to the 113 axis scales QwtSplineCurveFitter can be used to implement different 114 level of details to speed up painting of curves of many points. 115 */ 116 class QWT_EXPORT QwtWeedingCurveFitter: public QwtCurveFitter 117 { 118 public: 119 QwtWeedingCurveFitter( double tolerance = 1.0 ); 120 virtual ~QwtWeedingCurveFitter(); 121 122 void setTolerance( double ); 123 double tolerance() const; 124 125 void setChunkSize( uint ); 126 uint chunkSize() const; 127 128 virtual QPolygonF fitCurve( const QPolygonF & ) const; 129 130 private: 131 virtual QPolygonF simplify( const QPolygonF & ) const; 132 133 class Line; 134 135 class PrivateData; 136 PrivateData *d_data; 81 const Mode m_mode; 137 82 }; 138 83 -
trunk/BNC/qwt/qwt_date.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_date.h" 11 #include "qwt_math.h" 12 11 13 #include <qdebug.h> 12 14 #include <qlocale.h> 13 #include <math.h> 15 14 16 #include <limits> 15 #include <limits.h>16 17 17 18 #if QT_VERSION >= 0x050000 … … 24 25 25 26 // QDate stores the Julian day as unsigned int, but 26 // but itis QDate::fromJulianDay( int ). That's why27 // there is QDate::fromJulianDay( int ). That's why 27 28 // we have the range [ 1, INT_MAX ] 29 28 30 typedef int QwtJulianDay; 29 31 static const QwtJulianDay minJulianDayD = 1; 30 static const QwtJulianDay maxJulianDayD = std::numeric_limits< int>::max();32 static const QwtJulianDay maxJulianDayD = std::numeric_limits< int >::max(); 31 33 32 34 #endif 33 35 34 static QString qwtExpandedFormat( const QString & format,35 const QDateTime &dateTime, QwtDate::Week0Type week0Type )36 static QString qwtExpandedFormat( const QString& format, 37 const QDateTime& dateTime, QwtDate::Week0Type week0Type ) 36 38 { 37 39 const int week = QwtDate::weekNumber( dateTime.date(), week0Type ); … … 42 44 QString weekNoWW; 43 45 if ( weekNo.length() == 1 ) 44 weekNoWW += "0";46 weekNoWW += QLatin1Char( '0' ); 45 47 46 48 weekNoWW += weekNo; 47 49 48 50 QString fmt = format; 49 fmt.replace( "ww", weekNoWW );50 fmt.replace( "w", weekNo );51 fmt.replace( QLatin1String( "ww" ), weekNoWW ); 52 fmt.replace( QLatin1Char( 'w' ), weekNo ); 51 53 52 54 if ( week == 1 && dateTime.date().month() != 1 ) … … 54 56 // in case of week 1, we might need to increment the year 55 57 56 static QString s_yyyy="yyyy";57 static QString s_yy= "yy";58 QLatin1String s_yyyy( "yyyy" ); 59 QLatin1String s_yy( "yy" ); 58 60 59 61 // week 1 might start in the previous year … … 100 102 { 101 103 const QDate dt( dateTime.date().year() + 1, 1, 1 ); 104 const QString dtString = QLocale().toString( dt, s_yyyy ); 102 105 103 106 if ( fmt.contains( s_yyyy ) ) 104 107 { 105 fmt.replace( s_yyyy, dt .toString( s_yyyy ));108 fmt.replace( s_yyyy, dtString ); 106 109 } 107 110 else 108 111 { 109 fmt.replace( s_yy, dt .toString( s_yyyy ));112 fmt.replace( s_yy, dtString ); 110 113 } 111 114 } … … 117 120 static inline Qt::DayOfWeek qwtFirstDayOfWeek() 118 121 { 119 #if QT_VERSION >= 0x040800120 122 return QLocale().firstDayOfWeek(); 121 #else122 123 switch( QLocale().country() )124 {125 case QLocale::Maldives:126 return Qt::Friday;127 128 case QLocale::Afghanistan:129 case QLocale::Algeria:130 case QLocale::Bahrain:131 case QLocale::Djibouti:132 case QLocale::Egypt:133 case QLocale::Eritrea:134 case QLocale::Ethiopia:135 case QLocale::Iran:136 case QLocale::Iraq:137 case QLocale::Jordan:138 case QLocale::Kenya:139 case QLocale::Kuwait:140 case QLocale::LibyanArabJamahiriya:141 case QLocale::Morocco:142 case QLocale::Oman:143 case QLocale::Qatar:144 case QLocale::SaudiArabia:145 case QLocale::Somalia:146 case QLocale::Sudan:147 case QLocale::Tunisia:148 case QLocale::Yemen:149 return Qt::Saturday;150 151 case QLocale::AmericanSamoa:152 case QLocale::Argentina:153 case QLocale::Azerbaijan:154 case QLocale::Botswana:155 case QLocale::Canada:156 case QLocale::China:157 case QLocale::FaroeIslands:158 case QLocale::Georgia:159 case QLocale::Greenland:160 case QLocale::Guam:161 case QLocale::HongKong:162 case QLocale::Iceland:163 case QLocale::India:164 case QLocale::Ireland:165 case QLocale::Israel:166 case QLocale::Jamaica:167 case QLocale::Japan:168 case QLocale::Kyrgyzstan:169 case QLocale::Lao:170 case QLocale::Malta:171 case QLocale::MarshallIslands:172 case QLocale::Macau:173 case QLocale::Mongolia:174 case QLocale::NewZealand:175 case QLocale::NorthernMarianaIslands:176 case QLocale::Pakistan:177 case QLocale::Philippines:178 case QLocale::RepublicOfKorea:179 case QLocale::Singapore:180 case QLocale::SyrianArabRepublic:181 case QLocale::Taiwan:182 case QLocale::Thailand:183 case QLocale::TrinidadAndTobago:184 case QLocale::UnitedStates:185 case QLocale::UnitedStatesMinorOutlyingIslands:186 case QLocale::USVirginIslands:187 case QLocale::Uzbekistan:188 case QLocale::Zimbabwe:189 return Qt::Sunday;190 191 default:192 return Qt::Monday;193 }194 #endif195 123 } 196 124 197 125 static inline void qwtFloorTime( 198 QwtDate::IntervalType intervalType, QDateTime &dt )126 QwtDate::IntervalType intervalType, QDateTime& dt ) 199 127 { 200 128 // when dt is inside the special hour where DST is ending … … 234 162 235 163 static inline QDateTime qwtToTimeSpec( 236 const QDateTime &dt, Qt::TimeSpec spec )164 const QDateTime& dt, Qt::TimeSpec spec ) 237 165 { 238 166 if ( dt.timeSpec() == spec ) … … 240 168 241 169 const qint64 jd = dt.date().toJulianDay(); 242 if ( jd < 0 || jd >= INT_MAX)170 if ( jd < 0 || jd >= std::numeric_limits< int >::max() ) 243 171 { 244 172 // the conversion between local time and UTC … … 264 192 const int m1 = ( month - 14 ) / 12; 265 193 const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12; 266 const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 ); 267 268 return ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2 269 -::floor( ( 3 * y1 ) / 4 ) + day - 32075;194 const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 ); 195 196 return std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2 197 - std::floor( ( 3 * y1 ) / 4 ) + day - 32075; 270 198 } 271 199 … … 300 228 const int m1 = ( month - 14 ) / 12; 301 229 const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12; 302 const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 ); 303 304 const double jd = ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2 305 - ::floor( ( 3 * y1 ) / 4 ) + day - 32075; 230 const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 ); 231 232 const double jd = std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2 233 - std::floor( ( 3 * y1 ) / 4 ) + day - 32075; 306 234 307 235 if ( jd > maxJulianDayD ) … … 311 239 } 312 240 313 return QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) ); 241 return QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) ); 314 242 } 315 243 else … … 321 249 322 250 /*! 323 Translate from double to QDateTime 324 325 \param value Number of milliseconds since the epoch, 251 Translate from double to QDateTime 252 253 \param value Number of milliseconds since the epoch, 326 254 1970-01-01T00:00:00 UTC 327 \param timeSpec Time specification 328 \return Datetime value 329 330 \sa toDouble(), QDateTime::setMSecsSinceEpoch() 331 \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC 255 \param timeSpec Time specification 256 \return Datetime value 257 258 \sa toDouble(), QDateTime::setMSecsSinceEpoch() 259 \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC 332 260 */ 333 261 QDateTime QwtDate::toDateTime( double value, Qt::TimeSpec timeSpec ) … … 335 263 const int msecsPerDay = 86400000; 336 264 337 const double days = static_cast< qint64>(::floor( value / msecsPerDay ) );265 const double days = static_cast< qint64 >( std::floor( value / msecsPerDay ) ); 338 266 339 267 const double jd = QwtDate::JulianDayForEpoch + days; … … 344 272 } 345 273 346 const QDate d = QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) ); 347 348 const int msecs = static_cast< int>( value - days * msecsPerDay );274 const QDate d = QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) ); 275 276 const int msecs = static_cast< int >( value - days * msecsPerDay ); 349 277 350 278 static const QTime timeNull( 0, 0, 0, 0 ); … … 359 287 360 288 /*! 361 Translate from QDateTime to double 362 363 \param dateTime Datetime value 364 \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed. 365 366 \sa toDateTime(), QDateTime::toMSecsSinceEpoch() 367 \warning For values very far below or above 1970-01-01 UTC rounding errors 289 Translate from QDateTime to double 290 291 \param dateTime Datetime value 292 \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed. 293 294 \sa toDateTime(), QDateTime::toMSecsSinceEpoch() 295 \warning For values very far below or above 1970-01-01 UTC rounding errors 368 296 will happen due to the limited significance of a double. 369 297 */ 370 double QwtDate::toDouble( const QDateTime &dateTime )298 double QwtDate::toDouble( const QDateTime& dateTime ) 371 299 { 372 300 const int msecsPerDay = 86400000; … … 384 312 385 313 /*! 386 Ceil a datetime according the interval type 387 388 \param dateTime Datetime value 389 \param intervalType Interval type, how to ceil. 314 Ceil a datetime according the interval type 315 316 \param dateTime Datetime value 317 \param intervalType Interval type, how to ceil. 390 318 F.e. when intervalType = QwtDate::Months, the result 391 319 will be ceiled to the next beginning of a month 392 \return Ceiled datetime 393 \sa floor() 394 */ 395 QDateTime QwtDate::ceil( const QDateTime &dateTime, IntervalType intervalType )320 \return Ceiled datetime 321 \sa floor() 322 */ 323 QDateTime QwtDate::ceil( const QDateTime& dateTime, IntervalType intervalType ) 396 324 { 397 325 if ( dateTime.date() >= QwtDate::maxDate() ) … … 485 413 486 414 /*! 487 Floor a datetime according the interval type 488 489 \param dateTime Datetime value 490 \param intervalType Interval type, how to ceil. 415 Floor a datetime according the interval type 416 417 \param dateTime Datetime value 418 \param intervalType Interval type, how to ceil. 491 419 F.e. when intervalType = QwtDate::Months, 492 420 the result will be ceiled to the next 493 421 beginning of a month 494 \return Floored datetime 495 \sa floor() 496 */ 497 QDateTime QwtDate::floor( const QDateTime &dateTime,422 \return Floored datetime 423 \sa floor() 424 */ 425 QDateTime QwtDate::floor( const QDateTime& dateTime, 498 426 IntervalType intervalType ) 499 427 { … … 558 486 559 487 /*! 560 Minimum for the supported date range 561 562 The range of valid dates depends on how QDate stores the 563 Julian day internally. 564 565 - For Qt4 it is "Tue Jan 2 -4713" 566 - For Qt5 it is "Thu Jan 1 -2147483648" 567 568 \return minimum of the date range 569 \sa maxDate() 488 Minimum for the supported date range 489 490 The range of valid dates depends on how QDate stores the 491 Julian day internally. 492 493 - For Qt4 it is "Tue Jan 2 -4713" 494 - For Qt5 it is "Thu Jan 1 -2147483648" 495 496 \return minimum of the date range 497 \sa maxDate() 570 498 */ 571 499 QDate QwtDate::minDate() … … 579 507 580 508 /*! 581 Maximum for the supported date range 582 583 The range of valid dates depends on how QDate stores the 584 Julian day internally. 585 586 - For Qt4 it is "Tue Jun 3 5874898" 587 - For Qt5 it is "Tue Dec 31 2147483647" 588 589 \return maximum of the date range 590 \sa minDate() 591 \note The maximum differs between Qt4 and Qt5 509 Maximum for the supported date range 510 511 The range of valid dates depends on how QDate stores the 512 Julian day internally. 513 514 - For Qt4 it is "Tue Jun 3 5874898" 515 - For Qt5 it is "Tue Dec 31 2147483647" 516 517 \return maximum of the date range 518 \sa minDate() 519 \note The maximum differs between Qt4 and Qt5 592 520 */ 593 521 QDate QwtDate::maxDate() … … 601 529 602 530 /*! 603 \brief Date of the first day of the first week for a year 604 605 The first day of a week depends on the current locale 606 ( QLocale::firstDayOfWeek() ). 607 608 \param year Year 609 \param type Option how to identify the first week 610 \return First day of week 0 611 612 \sa QLocale::firstDayOfWeek(), weekNumber() 531 \brief Date of the first day of the first week for a year 532 533 The first day of a week depends on the current locale 534 ( QLocale::firstDayOfWeek() ). 535 536 \param year Year 537 \param type Option how to identify the first week 538 \return First day of week 0 539 540 \sa QLocale::firstDayOfWeek(), weekNumber() 613 541 */ 614 542 QDate QwtDate::dateOfWeek0( int year, Week0Type type ) … … 628 556 { 629 557 // according to ISO 8601 the first week is defined 630 // by the first thursday.558 // by the first Thursday. 631 559 632 560 int d = Qt::Thursday - firstDayOfWeek; … … 642 570 643 571 /*! 644 Find the week number of a date 645 646 - QwtDate::FirstThursday\n 572 Find the week number of a date 573 574 - QwtDate::FirstThursday\n 647 575 Corresponding to ISO 8601 ( see QDate::weekNumber() ). 648 576 649 - QwtDate::FirstDay\n 577 - QwtDate::FirstDay\n 650 578 Number of weeks that have begun since dateOfWeek0(). 651 579 652 \param date Date 653 \param type Option how to identify the first week 654 655 \return Week number, starting with 1 656 */ 657 int QwtDate::weekNumber( const QDate &date, Week0Type type )580 \param date Date 581 \param type Option how to identify the first week 582 583 \return Week number, starting with 1 584 */ 585 int QwtDate::weekNumber( const QDate& date, Week0Type type ) 658 586 { 659 587 int weekNo; … … 695 623 0, dateTime has no offset 696 624 - Qt::OffsetFromUTC 697 returns dateTime. utcOffset()625 returns dateTime.offsetFromUtc() 698 626 - Qt::LocalTime: 699 627 number of seconds from the UTC … … 705 633 \return Offset in seconds 706 634 */ 707 int QwtDate::utcOffset( const QDateTime &dateTime )635 int QwtDate::utcOffset( const QDateTime& dateTime ) 708 636 { 709 637 int seconds = 0; … … 717 645 case Qt::OffsetFromUTC: 718 646 { 647 #if QT_VERSION >= 0x050200 648 seconds = dateTime.offsetFromUtc(); 649 #else 719 650 seconds = dateTime.utcOffset(); 651 #endif 720 652 break; 721 653 } … … 731 663 732 664 /*! 733 Translate a datetime into a string 734 735 Beside the format expressions documented in QDateTime::toString() 736 the following expressions are supported: 737 738 - w\n 665 Translate a datetime into a string 666 667 Beside the format expressions documented in QDateTime::toString() 668 the following expressions are supported: 669 670 - w\n 739 671 week number: ( 1 - 53 ) 740 - ww\n 672 - ww\n 741 673 week number with a leading zero ( 01 - 53 ) 742 674 743 As week 1 usually starts in the previous year a special rule 744 is applied for formats, where the year is expected to match the 745 week number - even if the date belongs to the previous year. 746 747 \param dateTime Datetime value 748 \param format Format string 749 \param week0Type Specification of week 0 750 751 \return Datetime string 752 \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw 753 */ 754 QString QwtDate::toString( const QDateTime &dateTime,755 const QString & format, Week0Type week0Type )675 As week 1 usually starts in the previous year a special rule 676 is applied for formats, where the year is expected to match the 677 week number - even if the date belongs to the previous year. 678 679 \param dateTime Datetime value 680 \param format Format string 681 \param week0Type Specification of week 0 682 683 \return Datetime string 684 \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw 685 */ 686 QString QwtDate::toString( const QDateTime& dateTime, 687 const QString& format, Week0Type week0Type ) 756 688 { 757 689 QString fmt = format; … … 761 693 } 762 694 763 return dateTime.toString( fmt );764 } 695 return QLocale().toString( dateTime, fmt ); 696 } -
trunk/BNC/qwt/qwt_date.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 8 8 *****************************************************************************/ 9 9 10 #ifndef _QWT_DATE_H_11 #define _QWT_DATE_H_10 #ifndef QWT_DATE_H 11 #define QWT_DATE_H 12 12 13 13 #include "qwt_global.h" … … 15 15 16 16 /*! 17 \brief A collection of methods around date/time values 17 \brief A collection of methods around date/time values 18 18 19 Qt offers convenient classes for dealing with date/time values, 20 but Qwt uses coordinate systems that are based on doubles. 21 QwtDate offers methods to translate from QDateTime to double and v.v. 19 Qt offers convenient classes for dealing with date/time values, 20 but Qwt uses coordinate systems that are based on doubles. 21 QwtDate offers methods to translate from QDateTime to double and v.v. 22 22 23 A double is interpreted as the number of milliseconds since 24 1970-01-01T00:00:00 Universal Coordinated Time - also known 25 as "The Epoch". 23 A double is interpreted as the number of milliseconds since 24 1970-01-01T00:00:00 Universal Coordinated Time - also known 25 as "The Epoch". 26 26 27 While the range of the Julian day in Qt4 is limited to [0, MAX_INT], 28 Qt5 stores it as qint64 offering a huge range of valid dates. 29 As the significance of a double is below this ( assuming a 30 fraction of 52 bits ) the translation is not 31 bijective with rounding errors for dates very far from Epoch. 32 For a resolution of 1 ms those start to happen for dates above the 33 year 144683. 27 While the range of the Julian day in Qt4 is limited to [0, MAX_INT], 28 Qt5 stores it as qint64 offering a huge range of valid dates. 29 As the significance of a double is below this ( assuming a 30 fraction of 52 bits ) the translation is not 31 bijective with rounding errors for dates very far from Epoch. 32 For a resolution of 1 ms those start to happen for dates above the 33 year 144683. 34 34 35 An axis for a date/time interval is expected to be aligned 36 and divided in time/date units like seconds, minutes, ... 37 QwtDate offers several algorithms that are needed to 38 calculate these axes. 35 An axis for a date/time interval is expected to be aligned 36 and divided in time/date units like seconds, minutes, ... 37 QwtDate offers several algorithms that are needed to 38 calculate these axes. 39 39 40 \sa QwtDateScaleEngine, QwtDateScaleDraw, QDate, QTime 41 */ 40 \sa QwtDateScaleEngine, QwtDateScaleDraw, QDate, QTime 41 */ 42 42 class QWT_EXPORT QwtDate 43 43 { 44 public: 44 public: 45 45 /*! 46 46 How to identify the first week of year differs between … … 55 55 FirstThursday corresponds to the numbering that is 56 56 implemented in QDate::weekNumber(). 57 */ 57 */ 58 58 FirstThursday, 59 59 … … 63 63 In the U.S. this definition is more common than 64 64 FirstThursday. 65 */ 65 */ 66 66 FirstDay 67 67 }; 68 68 69 69 /*! 70 Classification of an time interval 70 Classification of an time interval 71 71 72 Time intervals needs to be classified to decide how to 73 align and divide it. 72 Time intervals needs to be classified to decide how to 73 align and divide it. 74 74 */ 75 75 enum IntervalType … … 112 112 Qt::TimeSpec = Qt::UTC ); 113 113 114 static double toDouble( const QDateTime & );114 static double toDouble( const QDateTime& ); 115 115 116 static QDateTime ceil( const QDateTime &, IntervalType );117 static QDateTime floor( const QDateTime &, IntervalType );116 static QDateTime ceil( const QDateTime&, IntervalType ); 117 static QDateTime floor( const QDateTime&, IntervalType ); 118 118 119 119 static QDate dateOfWeek0( int year, Week0Type ); 120 static int weekNumber( const QDate &, Week0Type );120 static int weekNumber( const QDate&, Week0Type ); 121 121 122 static int utcOffset( const QDateTime & );122 static int utcOffset( const QDateTime& ); 123 123 124 static QString toString( const QDateTime &,125 const QString & format, Week0Type );124 static QString toString( const QDateTime&, 125 const QString& format, Week0Type ); 126 126 }; 127 127 -
trunk/BNC/qwt/qwt_date_scale_draw.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_date_scale_draw.h" 11 #include "qwt_text.h" 11 12 12 13 class QwtDateScaleDraw::PrivateData 13 14 { 14 public: 15 PrivateData( Qt::TimeSpec spec ) :16 timeSpec( spec ) ,17 utcOffset( 0 ) ,18 week0Type( QwtDate::FirstThursday ) 15 public: 16 explicit PrivateData( Qt::TimeSpec spec ) 17 : timeSpec( spec ) 18 , utcOffset( 0 ) 19 , week0Type( QwtDate::FirstThursday ) 19 20 { 20 21 dateFormats[ QwtDate::Millisecond ] = "hh:mm:ss:zzz\nddd dd MMM yyyy"; … … 35 36 36 37 /*! 37 \brief Constructor 38 39 The default setting is to display tick labels for the 40 given time specification. The first week of a year is defined like 41 for QwtDate::FirstThursday. 42 43 \param timeSpec Time specification 44 45 \sa setTimeSpec(), setWeek0Type() 38 \brief Constructor 39 40 The default setting is to display tick labels for the 41 given time specification. The first week of a year is defined like 42 for QwtDate::FirstThursday. 43 44 \param timeSpec Time specification 45 46 \sa setTimeSpec(), setWeek0Type() 46 47 */ 47 48 QwtDateScaleDraw::QwtDateScaleDraw( Qt::TimeSpec timeSpec ) 48 49 { 49 d_data = new PrivateData( timeSpec );50 m_data = new PrivateData( timeSpec ); 50 51 } 51 52 … … 53 54 QwtDateScaleDraw::~QwtDateScaleDraw() 54 55 { 55 delete d_data;56 } 57 58 /*! 59 Set the time specification used for the tick labels 60 61 \param timeSpec Time specification 62 \sa timeSpec(), setUtcOffset(), toDateTime() 56 delete m_data; 57 } 58 59 /*! 60 Set the time specification used for the tick labels 61 62 \param timeSpec Time specification 63 \sa timeSpec(), setUtcOffset(), toDateTime() 63 64 */ 64 65 void QwtDateScaleDraw::setTimeSpec( Qt::TimeSpec timeSpec ) 65 66 { 66 d_data->timeSpec = timeSpec;67 } 68 69 /*! 70 \return Time specification used for the tick labels 71 \sa setTimeSpec(), utcOffset(), toDateTime() 67 m_data->timeSpec = timeSpec; 68 } 69 70 /*! 71 \return Time specification used for the tick labels 72 \sa setTimeSpec(), utcOffset(), toDateTime() 72 73 */ 73 74 Qt::TimeSpec QwtDateScaleDraw::timeSpec() const 74 75 { 75 return d_data->timeSpec;76 } 77 78 /*! 79 Set the offset in seconds from Coordinated Universal Time 80 81 \param seconds Offset in seconds 82 83 \note The offset has no effect beside for the time specification 76 return m_data->timeSpec; 77 } 78 79 /*! 80 Set the offset in seconds from Coordinated Universal Time 81 82 \param seconds Offset in seconds 83 84 \note The offset has no effect beside for the time specification 84 85 Qt::OffsetFromUTC. 85 86 86 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 87 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 87 88 */ 88 89 void QwtDateScaleDraw::setUtcOffset( int seconds ) 89 90 { 90 d_data->utcOffset = seconds;91 } 92 93 /*! 94 \return Offset in seconds from Coordinated Universal Time 95 \note The offset has no effect beside for the time specification 91 m_data->utcOffset = seconds; 92 } 93 94 /*! 95 \return Offset in seconds from Coordinated Universal Time 96 \note The offset has no effect beside for the time specification 96 97 Qt::OffsetFromUTC. 97 98 98 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 99 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 99 100 */ 100 101 int QwtDateScaleDraw::utcOffset() const 101 102 { 102 return d_data->utcOffset;103 } 104 105 /*! 106 Sets how to identify the first week of a year. 107 108 \param week0Type Mode how to identify the first week of a year 109 110 \sa week0Type(). 111 \note week0Type has no effect beside for intervals classified as 103 return m_data->utcOffset; 104 } 105 106 /*! 107 Sets how to identify the first week of a year. 108 109 \param week0Type Mode how to identify the first week of a year 110 111 \sa week0Type(). 112 \note week0Type has no effect beside for intervals classified as 112 113 QwtDate::Week. 113 114 */ 114 115 void QwtDateScaleDraw::setWeek0Type( QwtDate::Week0Type week0Type ) 115 116 { 116 d_data->week0Type = week0Type;117 } 118 119 /*! 120 \return Setting how to identify the first week of a year. 121 \sa setWeek0Type() 117 m_data->week0Type = week0Type; 118 } 119 120 /*! 121 \return Setting how to identify the first week of a year. 122 \sa setWeek0Type() 122 123 */ 123 124 QwtDate::Week0Type QwtDateScaleDraw::week0Type() const 124 125 { 125 return d_data->week0Type;126 } 127 128 /*! 129 Set the default format string for an datetime interval type 130 131 \param intervalType Interval type 132 \param format Default format string 133 134 \sa dateFormat(), dateFormatOfDate(), QwtDate::toString() 126 return m_data->week0Type; 127 } 128 129 /*! 130 Set the default format string for an datetime interval type 131 132 \param intervalType Interval type 133 \param format Default format string 134 135 \sa dateFormat(), dateFormatOfDate(), QwtDate::toString() 135 136 */ 136 137 void QwtDateScaleDraw::setDateFormat( 137 QwtDate::IntervalType intervalType, const QString &format )138 QwtDate::IntervalType intervalType, const QString& format ) 138 139 { 139 140 if ( intervalType >= QwtDate::Millisecond && 140 141 intervalType <= QwtDate::Year ) 141 142 { 142 d_data->dateFormats[ intervalType ] = format;143 } 144 } 145 146 /*! 147 \param intervalType Interval type 148 \return Default format string for an datetime interval type 149 \sa setDateFormat(), dateFormatOfDate() 143 m_data->dateFormats[ intervalType ] = format; 144 } 145 } 146 147 /*! 148 \param intervalType Interval type 149 \return Default format string for an datetime interval type 150 \sa setDateFormat(), dateFormatOfDate() 150 151 */ 151 152 QString QwtDateScaleDraw::dateFormat( … … 155 156 intervalType <= QwtDate::Year ) 156 157 { 157 return d_data->dateFormats[ intervalType ];158 return m_data->dateFormats[ intervalType ]; 158 159 } 159 160 … … 162 163 163 164 /*! 164 Format string for the representation of a datetime 165 166 dateFormatOfDate() is intended to be overloaded for 167 situations, where formats are individual for specific 168 datetime values. 169 170 The default setting ignores dateTime and return 171 the default format for the interval type. 172 173 \param dateTime Datetime value 174 \param intervalType Interval type 175 \return Format string 176 177 \sa setDateFormat(), QwtDate::toString() 178 */ 179 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime &dateTime,165 Format string for the representation of a datetime 166 167 dateFormatOfDate() is intended to be overloaded for 168 situations, where formats are individual for specific 169 datetime values. 170 171 The default setting ignores dateTime and return 172 the default format for the interval type. 173 174 \param dateTime Datetime value 175 \param intervalType Interval type 176 \return Format string 177 178 \sa setDateFormat(), QwtDate::toString() 179 */ 180 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime& dateTime, 180 181 QwtDate::IntervalType intervalType ) const 181 182 { … … 185 186 intervalType <= QwtDate::Year ) 186 187 { 187 return d_data->dateFormats[ intervalType ];188 } 189 190 return d_data->dateFormats[ QwtDate::Second ];191 } 192 193 /*! 194 \brief Convert a value into its representing label 195 196 The value is converted to a datetime value using toDateTime() 197 and converted to a plain text using QwtDate::toString(). 198 199 \param value Value 200 \return Label string. 201 202 \sa dateFormatOfDate() 203 */ 188 return m_data->dateFormats[ intervalType ]; 189 } 190 191 return m_data->dateFormats[ QwtDate::Second ]; 192 } 193 194 /*! 195 \brief Convert a value into its representing label 196 197 The value is converted to a datetime value using toDateTime() 198 and converted to a plain text using QwtDate::toString(). 199 200 \param value Value 201 \return Label string. 202 203 \sa dateFormatOfDate() 204 */ 204 205 QwtText QwtDateScaleDraw::label( double value ) const 205 206 { … … 208 209 dt, intervalType( scaleDiv() ) ); 209 210 210 return QwtDate::toString( dt, fmt, d_data->week0Type );211 } 212 213 /*! 214 Find the less detailed datetime unit, where no rounding 215 errors happen. 216 217 \param scaleDiv Scale division 218 \return Interval type 219 220 \sa dateFormatOfDate() 211 return QwtDate::toString( dt, fmt, m_data->week0Type ); 212 } 213 214 /*! 215 Find the less detailed datetime unit, where no rounding 216 errors happen. 217 218 \param scaleDiv Scale division 219 \return Interval type 220 221 \sa dateFormatOfDate() 221 222 */ 222 223 QwtDate::IntervalType QwtDateScaleDraw::intervalType( 223 const QwtScaleDiv &scaleDiv ) const224 const QwtScaleDiv& scaleDiv ) const 224 225 { 225 226 int intvType = QwtDate::Year; … … 227 228 bool alignedToWeeks = true; 228 229 229 const QList< double> ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick );230 const QList< double > ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick ); 230 231 for ( int i = 0; i < ticks.size(); i++ ) 231 232 { … … 234 235 { 235 236 const QDateTime dt0 = QwtDate::floor( dt, 236 static_cast<QwtDate::IntervalType>( j ) ); 237 static_cast< QwtDate::IntervalType >( j ) ); 237 238 238 239 if ( dt0 != dt ) … … 257 258 intvType = QwtDate::Day; 258 259 259 return static_cast<QwtDate::IntervalType>( intvType ); 260 } 261 262 /*! 263 Translate a double value into a QDateTime object. 264 265 \return QDateTime object initialized with timeSpec() and utcOffset(). 266 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 260 return static_cast< QwtDate::IntervalType >( intvType ); 261 } 262 263 /*! 264 Translate a double value into a QDateTime object. 265 266 \return QDateTime object initialized with timeSpec() and utcOffset(). 267 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 267 268 */ 268 269 QDateTime QwtDateScaleDraw::toDateTime( double value ) const 269 270 { 270 QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec ); 271 if ( d_data->timeSpec == Qt::OffsetFromUTC ) 272 { 273 dt = dt.addSecs( d_data->utcOffset ); 274 dt.setUtcOffset( d_data->utcOffset ); 271 QDateTime dt = QwtDate::toDateTime( value, m_data->timeSpec ); 272 if ( m_data->timeSpec == Qt::OffsetFromUTC ) 273 { 274 dt = dt.addSecs( m_data->utcOffset ); 275 #if QT_VERSION >= 0x050200 276 dt.setOffsetFromUtc( m_data->utcOffset ); 277 #else 278 dt.setUtcOffset( m_data->utcOffset ); 279 #endif 275 280 } 276 281 -
trunk/BNC/qwt/qwt_date_scale_draw.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 8 8 *****************************************************************************/ 9 9 10 #ifndef _QWT_DATE_SCALE_DRAW_H_11 #define _QWT_DATE_SCALE_DRAW_H_ 110 #ifndef QWT_DATE_SCALE_DRAW_H 11 #define QWT_DATE_SCALE_DRAW_H 12 12 13 13 #include "qwt_global.h" … … 16 16 17 17 /*! 18 \brief A class for drawing datetime scales 18 \brief A class for drawing datetime scales 19 19 20 QwtDateScaleDraw displays values as datetime labels. 21 The format of the labels depends on the alignment of 22 the major tick labels. 20 QwtDateScaleDraw displays values as datetime labels. 21 The format of the labels depends on the alignment of 22 the major tick labels. 23 23 24 The default format strings are: 24 The default format strings are: 25 25 26 - Millisecond\n 26 - Millisecond\n 27 27 "hh:mm:ss:zzz\nddd dd MMM yyyy" 28 - Second\n 28 - Second\n 29 29 "hh:mm:ss\nddd dd MMM yyyy" 30 - Minute\n 30 - Minute\n 31 31 "hh:mm\nddd dd MMM yyyy" 32 - Hour\n 32 - Hour\n 33 33 "hh:mm\nddd dd MMM yyyy" 34 - Day\n 34 - Day\n 35 35 "ddd dd MMM yyyy" 36 - Week\n 36 - Week\n 37 37 "Www yyyy" 38 - Month\n 38 - Month\n 39 39 "MMM yyyy" 40 - Year\n 40 - Year\n 41 41 "yyyy" 42 42 43 The format strings can be modified using setDateFormat() 44 or individually for each tick label by overloading dateFormatOfDate(), 43 The format strings can be modified using setDateFormat() 44 or individually for each tick label by overloading dateFormatOfDate(), 45 45 46 Usually QwtDateScaleDraw is used in combination with 47 QwtDateScaleEngine, that calculates scales for datetime 48 intervals. 46 Usually QwtDateScaleDraw is used in combination with 47 QwtDateScaleEngine, that calculates scales for datetime 48 intervals. 49 49 50 \sa QwtDateScaleEngine, QwtPlot::setAxisScaleDraw() 51 */ 52 class QWT_EXPORT QwtDateScaleDraw: public QwtScaleDraw 50 \sa QwtDateScaleEngine, QwtPlot::setAxisScaleDraw() 51 */ 52 class QWT_EXPORT QwtDateScaleDraw : public QwtScaleDraw 53 53 { 54 public: 55 QwtDateScaleDraw( Qt::TimeSpec = Qt::LocalTime ); 54 public: 55 explicit QwtDateScaleDraw( Qt::TimeSpec = Qt::LocalTime ); 56 56 virtual ~QwtDateScaleDraw(); 57 57 58 void setDateFormat( QwtDate::IntervalType, const QString & );58 void setDateFormat( QwtDate::IntervalType, const QString& ); 59 59 QString dateFormat( QwtDate::IntervalType ) const; 60 60 … … 68 68 QwtDate::Week0Type week0Type() const; 69 69 70 virtual QwtText label( double ) const; 70 virtual QwtText label( double ) const QWT_OVERRIDE; 71 71 72 72 QDateTime toDateTime( double ) const; 73 73 74 protected: 74 protected: 75 75 virtual QwtDate::IntervalType 76 intervalType( const QwtScaleDiv& ) const;76 intervalType( const QwtScaleDiv& ) const; 77 77 78 virtual QString dateFormatOfDate( const QDateTime &,78 virtual QString dateFormatOfDate( const QDateTime&, 79 79 QwtDate::IntervalType ) const; 80 80 81 private: 81 private: 82 82 class PrivateData; 83 PrivateData *d_data;83 PrivateData* m_data; 84 84 }; 85 85 -
trunk/BNC/qwt/qwt_date_scale_engine.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_date_scale_engine.h" 11 11 #include "qwt_math.h" 12 #include "qwt_transform.h" 12 #include "qwt_interval.h" 13 13 14 #include <qdatetime.h> 14 #include <limits.h> 15 16 #include <limits> 15 17 16 18 static inline double qwtMsecsForType( int type ) … … 28 30 }; 29 31 30 if ( type < 0 || type >= static_cast< int>( sizeof( msecs ) / sizeof( msecs[0] ) ) )32 if ( type < 0 || type >= static_cast< int >( sizeof( msecs ) / sizeof( msecs[0] ) ) ) 31 33 return 1.0; 32 34 … … 38 40 { 39 41 double d = value / stepSize; 40 d = up ? ::ceil( d ) : ::floor( d ); 41 42 return static_cast< int>( d * stepSize );43 } 44 45 static double qwtIntervalWidth( const QDateTime &minDate,46 const QDateTime &maxDate, QwtDate::IntervalType intervalType )42 d = up ? std::ceil( d ) : std::floor( d ); 43 44 return static_cast< int >( d * stepSize ); 45 } 46 47 static double qwtIntervalWidth( const QDateTime& minDate, 48 const QDateTime& maxDate, QwtDate::IntervalType intervalType ) 47 49 { 48 50 switch( intervalType ) … … 50 52 case QwtDate::Millisecond: 51 53 { 54 return minDate.msecsTo( maxDate ); 55 } 56 case QwtDate::Second: 57 { 58 return minDate.secsTo( maxDate ); 59 } 60 case QwtDate::Minute: 61 { 52 62 const double secsTo = minDate.secsTo( maxDate ); 53 const double msecs = maxDate.time().msec() - 54 minDate.time().msec(); 55 56 return secsTo * 1000 + msecs; 57 } 58 case QwtDate::Second: 59 { 60 return minDate.secsTo( maxDate ); 61 } 62 case QwtDate::Minute: 63 return std::floor( secsTo / 60 ); 64 } 65 case QwtDate::Hour: 63 66 { 64 67 const double secsTo = minDate.secsTo( maxDate ); 65 return ::floor( secsTo / 60 ); 66 } 67 case QwtDate::Hour: 68 { 69 const double secsTo = minDate.secsTo( maxDate ); 70 return ::floor( secsTo / 3600 ); 68 return std::floor( secsTo / 3600 ); 71 69 } 72 70 case QwtDate::Day: … … 76 74 case QwtDate::Week: 77 75 { 78 return ::floor( minDate.daysTo( maxDate ) / 7.0 ); 76 return std::floor( minDate.daysTo( maxDate ) / 7.0 ); 79 77 } 80 78 case QwtDate::Month: … … 105 103 106 104 static double qwtRoundedIntervalWidth( 107 const QDateTime &minDate, const QDateTime&maxDate,105 const QDateTime& minDate, const QDateTime& maxDate, 108 106 QwtDate::IntervalType intervalType ) 109 107 { … … 142 140 const double stepSize = double( intervalSize ) / numSteps; 143 141 144 const double p = ::floor( ::log( stepSize ) / ::log( double( base ) ) ); 145 const double fraction = qPow( base, p );142 const double p = std::floor( std::log( stepSize ) / std::log( double( base ) ) ); 143 const double fraction = std::pow( base, p ); 146 144 147 145 for ( uint n = base; n >= 1; n /= 2 ) … … 165 163 const int limits[], size_t numLimits ) 166 164 { 167 const int v = qCeil( intervalSize / double( numSteps ) ); 165 const int v = qwtCeil( intervalSize / double( numSteps ) ); 168 166 169 167 for ( uint i = 0; i < numLimits - 1; i++ ) … … 215 213 const double v = intervalSize / double( numSteps ); 216 214 if ( v <= 5.0 ) 217 stepSize = qCeil( v );215 stepSize = std::ceil( v ); 218 216 else 219 stepSize = qCeil( v / 7 ) * 7;217 stepSize = std::ceil( v / 7 ) * 7; 220 218 221 219 break; … … 285 283 286 284 if ( numSteps > 0 ) 287 minStepSize = double( stepSize )/ numSteps;285 minStepSize = stepSize / numSteps; 288 286 289 287 break; … … 309 307 310 308 if ( numSteps > 0 ) 311 minStepSize = double( stepSize )/ numSteps;309 minStepSize = stepSize / numSteps; 312 310 313 311 break; … … 333 331 334 332 if ( numSteps > 0 ) 335 minStepSize = double( stepSize )/ numSteps;333 minStepSize = stepSize / numSteps; 336 334 337 335 break; … … 370 368 371 369 if ( stepSize < maxMinSteps ) 372 maxMinSteps = static_cast< int>( stepSize );370 maxMinSteps = static_cast< int >( stepSize ); 373 371 374 372 static int limits[] = { 1, 2, 3, 4, 6, 12 }; … … 378 376 379 377 if ( numSteps > 0 ) 380 minStepSize = double( stepSize )/ numSteps;378 minStepSize = stepSize / numSteps; 381 379 382 380 break; … … 399 397 400 398 if ( numSteps > 0 ) 401 minStepSize = double( stepSize )/ numSteps;399 minStepSize = stepSize / numSteps; 402 400 } 403 401 … … 417 415 } 418 416 419 static QList< double> qwtDstTicks( const QDateTime&dateTime,417 static QList< double > qwtDstTicks( const QDateTime& dateTime, 420 418 int secondsMajor, int secondsMinor ) 421 419 { 422 420 if ( secondsMinor <= 0 ) 423 QList<double>();421 return QList< double >(); 424 422 425 423 QDateTime minDate = dateTime.addSecs( -secondsMajor ); … … 438 436 } 439 437 440 QList<double> ticks; 438 QList< double > ticks; 439 ticks.reserve( 3600 / secondsMinor); 440 441 441 for ( int i = 0; i < 3600; i += secondsMinor ) 442 442 ticks += dstMin + i * 1000.0; … … 446 446 447 447 static QwtScaleDiv qwtDivideToSeconds( 448 const QDateTime &minDate, const QDateTime&maxDate,448 const QDateTime& minDate, const QDateTime& maxDate, 449 449 double stepSize, int maxMinSteps, 450 450 QwtDate::IntervalType intervalType ) … … 470 470 471 471 const double s = qwtMsecsForType( intervalType ) / 1000; 472 const int secondsMajor = static_cast< int>( stepSize * s );472 const int secondsMajor = static_cast< int >( stepSize * s ); 473 473 const double secondsMinor = minStepSize * s; 474 474 … … 480 480 double dstOff = 0; 481 481 482 QList< double> majorTicks;483 QList< double> mediumTicks;484 QList< double> minorTicks;482 QList< double > majorTicks; 483 QList< double > mediumTicks; 484 QList< double > minorTicks; 485 485 486 486 for ( QDateTime dt = minDate; dt <= maxDate; … … 513 513 if ( secondsMinor > 0.0 ) 514 514 { 515 const int numMinorSteps = qFloor( secondsMajor / secondsMinor ); 515 const int numMinorSteps = qwtFloor( secondsMajor / secondsMinor ); 516 516 517 517 for ( int i = 1; i < numMinorSteps; i++ ) … … 554 554 555 555 static QwtScaleDiv qwtDivideToMonths( 556 QDateTime &minDate, const QDateTime&maxDate,556 QDateTime& minDate, const QDateTime& maxDate, 557 557 double stepSize, int maxMinSteps ) 558 558 { … … 584 584 } 585 585 586 QList< double> majorTicks;587 QList< double> mediumTicks;588 QList< double> minorTicks;586 QList< double > majorTicks; 587 QList< double > mediumTicks; 588 QList< double > minorTicks; 589 589 590 590 for ( QDateTime dt = minDate; … … 638 638 639 639 static QwtScaleDiv qwtDivideToYears( 640 const QDateTime &minDate, const QDateTime&maxDate,640 const QDateTime& minDate, const QDateTime& maxDate, 641 641 double stepSize, int maxMinSteps ) 642 642 { 643 QList< double> majorTicks;644 QList< double> mediumTicks;645 QList< double> minorTicks;643 QList< double > majorTicks; 644 QList< double > mediumTicks; 645 QList< double > minorTicks; 646 646 647 647 double minStepSize = 0.0; … … 655 655 int numMinorSteps = 0; 656 656 if ( minStepSize > 0.0 ) 657 numMinorSteps = qFloor( stepSize / minStepSize ); 657 numMinorSteps = qwtFloor( stepSize / minStepSize ); 658 658 659 659 bool dateBC = minDate.date().year() < -1; … … 679 679 680 680 const double years = qRound( i * minStepSize ); 681 if ( years >= INT_MAX/ 12 )681 if ( years >= std::numeric_limits< int >::max() / 12 ) 682 682 { 683 683 tickDate = dt.addYears( years ); … … 717 717 class QwtDateScaleEngine::PrivateData 718 718 { 719 public: 720 PrivateData( Qt::TimeSpec spec ) :721 timeSpec( spec ) ,722 utcOffset( 0 ) ,723 week0Type( QwtDate::FirstThursday ) ,724 maxWeeks( 4 ) 719 public: 720 explicit PrivateData( Qt::TimeSpec spec ) 721 : timeSpec( spec ) 722 , utcOffset( 0 ) 723 , week0Type( QwtDate::FirstThursday ) 724 , maxWeeks( 4 ) 725 725 { 726 726 } … … 734 734 735 735 /*! 736 \brief Constructor 737 738 The engine is initialized to build scales for the 739 given time specification. It classifies intervals > 4 weeks 740 as >= Qt::Month. The first week of a year is defined like 741 for QwtDate::FirstThursday. 742 743 \param timeSpec Time specification 744 745 \sa setTimeSpec(), setMaxWeeks(), setWeek0Type() 736 \brief Constructor 737 738 The engine is initialized to build scales for the 739 given time specification. It classifies intervals > 4 weeks 740 as >= Qt::Month. The first week of a year is defined like 741 for QwtDate::FirstThursday. 742 743 \param timeSpec Time specification 744 745 \sa setTimeSpec(), setMaxWeeks(), setWeek0Type() 746 746 */ 747 QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec ) :748 QwtLinearScaleEngine( 10 ) 749 { 750 d_data = new PrivateData( timeSpec );747 QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec ) 748 : QwtLinearScaleEngine( 10 ) 749 { 750 m_data = new PrivateData( timeSpec ); 751 751 } 752 752 … … 754 754 QwtDateScaleEngine::~QwtDateScaleEngine() 755 755 { 756 delete d_data;756 delete m_data; 757 757 } 758 758 759 759 /*! 760 Set the time specification used by the engine 761 762 \param timeSpec Time specification 763 \sa timeSpec(), setUtcOffset(), toDateTime() 760 Set the time specification used by the engine 761 762 \param timeSpec Time specification 763 \sa timeSpec(), setUtcOffset(), toDateTime() 764 764 */ 765 765 void QwtDateScaleEngine::setTimeSpec( Qt::TimeSpec timeSpec ) 766 766 { 767 d_data->timeSpec = timeSpec;767 m_data->timeSpec = timeSpec; 768 768 } 769 769 770 770 /*! 771 \return Time specification used by the engine 772 \sa setTimeSpec(), utcOffset(), toDateTime() 771 \return Time specification used by the engine 772 \sa setTimeSpec(), utcOffset(), toDateTime() 773 773 */ 774 774 Qt::TimeSpec QwtDateScaleEngine::timeSpec() const 775 775 { 776 return d_data->timeSpec;776 return m_data->timeSpec; 777 777 } 778 778 779 779 /*! 780 Set the offset in seconds from Coordinated Universal Time 781 782 \param seconds Offset in seconds 783 784 \note The offset has no effect beside for the time specification 780 Set the offset in seconds from Coordinated Universal Time 781 782 \param seconds Offset in seconds 783 784 \note The offset has no effect beside for the time specification 785 785 Qt::OffsetFromUTC. 786 786 787 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 787 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 788 788 */ 789 789 void QwtDateScaleEngine::setUtcOffset( int seconds ) 790 790 { 791 d_data->utcOffset = seconds;791 m_data->utcOffset = seconds; 792 792 } 793 793 794 794 /*! 795 \return Offset in seconds from Coordinated Universal Time 796 \note The offset has no effect beside for the time specification 795 \return Offset in seconds from Coordinated Universal Time 796 \note The offset has no effect beside for the time specification 797 797 Qt::OffsetFromUTC. 798 798 799 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 799 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 800 800 */ 801 801 int QwtDateScaleEngine::utcOffset() const 802 802 { 803 return d_data->utcOffset;803 return m_data->utcOffset; 804 804 } 805 805 806 806 /*! 807 Sets how to identify the first week of a year. 808 809 \param week0Type Mode how to identify the first week of a year 810 811 \sa week0Type(), setMaxWeeks() 812 \note week0Type has no effect beside for intervals classified as 807 Sets how to identify the first week of a year. 808 809 \param week0Type Mode how to identify the first week of a year 810 811 \sa week0Type(), setMaxWeeks() 812 \note week0Type has no effect beside for intervals classified as 813 813 QwtDate::Week. 814 814 */ 815 815 void QwtDateScaleEngine::setWeek0Type( QwtDate::Week0Type week0Type ) 816 816 { 817 d_data->week0Type = week0Type;817 m_data->week0Type = week0Type; 818 818 } 819 819 820 820 /*! 821 \return Setting how to identify the first week of a year. 822 \sa setWeek0Type(), maxWeeks() 821 \return Setting how to identify the first week of a year. 822 \sa setWeek0Type(), maxWeeks() 823 823 */ 824 824 QwtDate::Week0Type QwtDateScaleEngine::week0Type() const 825 825 { 826 return d_data->week0Type;826 return m_data->week0Type; 827 827 } 828 828 829 829 /*! 830 Set a upper limit for the number of weeks, when an interval 831 can be classified as Qt::Week. 832 833 The default setting is 4 weeks. 834 835 \param weeks Upper limit for the number of weeks 836 837 \note In business charts a year is often divided 830 Set a upper limit for the number of weeks, when an interval 831 can be classified as Qt::Week. 832 833 The default setting is 4 weeks. 834 835 \param weeks Upper limit for the number of weeks 836 837 \note In business charts a year is often divided 838 838 into weeks [1-52] 839 \sa maxWeeks(), setWeek0Type() 839 \sa maxWeeks(), setWeek0Type() 840 840 */ 841 841 void QwtDateScaleEngine::setMaxWeeks( int weeks ) 842 842 { 843 d_data->maxWeeks = qMax( weeks, 0 );843 m_data->maxWeeks = qMax( weeks, 0 ); 844 844 } 845 845 846 846 /*! 847 \return Upper limit for the number of weeks, when an interval 847 \return Upper limit for the number of weeks, when an interval 848 848 can be classified as Qt::Week. 849 \sa setMaxWeeks(), week0Type() 849 \sa setMaxWeeks(), week0Type() 850 850 */ 851 851 int QwtDateScaleEngine::maxWeeks() const 852 852 { 853 return d_data->maxWeeks;853 return m_data->maxWeeks; 854 854 } 855 855 856 856 /*! 857 Classification of a date/time interval division 858 859 \param minDate Minimum ( = earlier ) of the interval 860 \param maxDate Maximum ( = later ) of the interval 861 \param maxSteps Maximum for the number of steps 862 863 \return Interval classification 857 Classification of a date/time interval division 858 859 \param minDate Minimum ( = earlier ) of the interval 860 \param maxDate Maximum ( = later ) of the interval 861 \param maxSteps Maximum for the number of steps 862 863 \return Interval classification 864 864 */ 865 865 QwtDate::IntervalType QwtDateScaleEngine::intervalType( 866 const QDateTime &minDate, const QDateTime&maxDate,866 const QDateTime& minDate, const QDateTime& maxDate, 867 867 int maxSteps ) const 868 868 { … … 880 880 const int weeks = qwtRoundedIntervalWidth( minDate, maxDate, QwtDate::Week ); 881 881 882 if ( weeks > d_data->maxWeeks )882 if ( weeks > m_data->maxWeeks ) 883 883 { 884 884 if ( days > 4 * maxSteps * 7 ) … … 908 908 909 909 /*! 910 Align and divide an interval 911 912 The algorithm aligns and divides the interval into steps. 913 914 Datetime interval divisions are usually not equidistant and the 915 calculated stepSize can only be used as an approximation 916 for the steps calculated by divideScale(). 917 918 \param maxNumSteps Max. number of steps 919 \param x1 First limit of the interval (In/Out) 920 \param x2 Second limit of the interval (In/Out) 921 \param stepSize Step size (Out) 922 923 \sa QwtScaleEngine::setAttribute() 924 */ 910 Align and divide an interval 911 912 The algorithm aligns and divides the interval into steps. 913 914 Datetime interval divisions are usually not equidistant and the 915 calculated stepSize can only be used as an approximation 916 for the steps calculated by divideScale(). 917 918 \param maxNumSteps Max. number of steps 919 \param x1 First limit of the interval (In/Out) 920 \param x2 Second limit of the interval (In/Out) 921 \param stepSize Step size (Out) 922 923 \sa QwtScaleEngine::setAttribute() 924 */ 925 925 void QwtDateScaleEngine::autoScale( int maxNumSteps, 926 double &x1, double&x2, double&stepSize ) const926 double& x1, double& x2, double& stepSize ) const 927 927 { 928 928 stepSize = 0.0; … … 989 989 calculates one. 990 990 \return Calculated scale division 991 */ 991 */ 992 992 QwtScaleDiv QwtDateScaleEngine::divideScale( double x1, double x2, 993 993 int maxMajorSteps, int maxMinorSteps, double stepSize ) const … … 996 996 maxMajorSteps = 1; 997 997 998 const double min = q Min( x1, x2 );999 const double max = q Max( x1, x2 );998 const double min = qwtMinF( x1, x2 ); 999 const double max = qwtMaxF( x1, x2 ); 1000 1000 1001 1001 const QDateTime from = toDateTime( min ); … … 1012 1012 // the stepSize is used as a hint only 1013 1013 1014 maxMajorSteps = qCeil( ( max - min ) / stepSize ); 1014 maxMajorSteps = qwtCeil( ( max - min ) / stepSize ); 1015 1015 } 1016 1016 … … 1047 1047 1048 1048 QwtScaleDiv QwtDateScaleEngine::buildScaleDiv( 1049 const QDateTime &minDate, const QDateTime&maxDate,1049 const QDateTime& minDate, const QDateTime& maxDate, 1050 1050 int maxMajorSteps, int maxMinorSteps, 1051 1051 QwtDate::IntervalType intervalType ) const … … 1091 1091 1092 1092 /*! 1093 Align a date/time value for a step size 1094 1095 For Qt::Day alignments there is no "natural day 0" - 1096 instead the first day of the year is used to avoid jumping 1097 major ticks positions when panning a scale. For other alignments 1098 ( f.e according to the first day of the month ) alignDate() 1099 has to be overloaded. 1100 1101 \param dateTime Date/time value 1102 \param stepSize Step size 1103 \param intervalType Interval type 1104 \param up When true dateTime is ceiled - otherwise it is floored 1105 1106 \return Aligned date/time value 1093 Align a date/time value for a step size 1094 1095 For Qt::Day alignments there is no "natural day 0" - 1096 instead the first day of the year is used to avoid jumping 1097 major ticks positions when panning a scale. For other alignments 1098 ( f.e according to the first day of the month ) alignDate() 1099 has to be overloaded. 1100 1101 \param dateTime Date/time value 1102 \param stepSize Step size 1103 \param intervalType Interval type 1104 \param up When true dateTime is ceiled - otherwise it is floored 1105 1106 \return Aligned date/time value 1107 1107 */ 1108 1108 QDateTime QwtDateScaleEngine::alignDate( 1109 const QDateTime &dateTime, double stepSize,1109 const QDateTime& dateTime, double stepSize, 1110 1110 QwtDate::IntervalType intervalType, bool up ) const 1111 1111 { … … 1116 1116 if ( dateTime.timeSpec() == Qt::OffsetFromUTC ) 1117 1117 { 1118 #if QT_VERSION >= 0x050200 1119 dt.setOffsetFromUtc( 0 ); 1120 #else 1118 1121 dt.setUtcOffset( 0 ); 1122 #endif 1119 1123 } 1120 1124 … … 1124 1128 { 1125 1129 const int ms = qwtAlignValue( 1126 dt.time().msec(), stepSize, up ) ;1130 dt.time().msec(), stepSize, up ); 1127 1131 1128 1132 dt = QwtDate::floor( dateTime, QwtDate::Second ); … … 1204 1208 { 1205 1209 const QDate date = QwtDate::dateOfWeek0( 1206 dt.date().year(), d_data->week0Type );1210 dt.date().year(), m_data->week0Type ); 1207 1211 1208 1212 int numWeeks = date.daysTo( dt.date() ) / 7; … … 1274 1278 if ( dateTime.timeSpec() == Qt::OffsetFromUTC ) 1275 1279 { 1280 #if QT_VERSION >= 0x050200 1281 dt.setOffsetFromUtc( dateTime.offsetFromUtc() ); 1282 #else 1276 1283 dt.setUtcOffset( dateTime.utcOffset() ); 1284 #endif 1277 1285 } 1278 1286 … … 1281 1289 1282 1290 /*! 1283 Translate a double value into a QDateTime object. 1284 1285 For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate() 1286 1287 \return QDateTime object initialized with timeSpec() and utcOffset(). 1288 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 1291 Translate a double value into a QDateTime object. 1292 1293 For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate() 1294 1295 \return QDateTime object initialized with timeSpec() and utcOffset(). 1296 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 1289 1297 */ 1290 1298 QDateTime QwtDateScaleEngine::toDateTime( double value ) const 1291 1299 { 1292 QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );1300 QDateTime dt = QwtDate::toDateTime( value, m_data->timeSpec ); 1293 1301 if ( !dt.isValid() ) 1294 1302 { … … 1296 1304 ? QwtDate::minDate() : QwtDate::maxDate(); 1297 1305 1298 dt = QDateTime( date, QTime( 0, 0 ), d_data->timeSpec ); 1299 } 1300 1301 if ( d_data->timeSpec == Qt::OffsetFromUTC ) 1302 { 1303 dt = dt.addSecs( d_data->utcOffset ); 1304 dt.setUtcOffset( d_data->utcOffset ); 1306 dt = QDateTime( date, QTime( 0, 0 ), m_data->timeSpec ); 1307 } 1308 1309 if ( m_data->timeSpec == Qt::OffsetFromUTC ) 1310 { 1311 dt = dt.addSecs( m_data->utcOffset ); 1312 #if QT_VERSION >= 0x050200 1313 dt.setOffsetFromUtc( m_data->utcOffset ); 1314 #else 1315 dt.setUtcOffset( m_data->utcOffset ); 1316 #endif 1305 1317 } 1306 1318 -
trunk/BNC/qwt/qwt_date_scale_engine.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 8 8 *****************************************************************************/ 9 9 10 #ifndef _QWT_DATE_SCALE_ENGINE_H_11 #define _QWT_DATE_SCALE_ENGINE_H_ 110 #ifndef QWT_DATE_SCALE_ENGINE_H 11 #define QWT_DATE_SCALE_ENGINE_H 12 12 13 #include "qwt_global.h" 13 14 #include "qwt_date.h" 14 15 #include "qwt_scale_engine.h" 15 16 16 17 /*! 17 \brief A scale engine for date/time values 18 \brief A scale engine for date/time values 18 19 19 QwtDateScaleEngine builds scales from a time intervals. 20 Together with QwtDateScaleDraw it can be used for 21 axes according to date/time values. 20 QwtDateScaleEngine builds scales from a time intervals. 21 Together with QwtDateScaleDraw it can be used for 22 axes according to date/time values. 22 23 23 Years, months, weeks, days, hours and minutes are organized 24 in steps with non constant intervals. QwtDateScaleEngine 25 classifies intervals and aligns the boundaries and tick positions 26 according to this classification. 24 Years, months, weeks, days, hours and minutes are organized 25 in steps with non constant intervals. QwtDateScaleEngine 26 classifies intervals and aligns the boundaries and tick positions 27 according to this classification. 27 28 28 QwtDateScaleEngine supports representations depending 29 on Qt::TimeSpec specifications. The valid range for scales 30 is limited by the range of QDateTime, that differs 31 between Qt4 and Qt5. 29 QwtDateScaleEngine supports representations depending 30 on Qt::TimeSpec specifications. The valid range for scales 31 is limited by the range of QDateTime, that differs 32 between Qt4 and Qt5. 32 33 33 Datetime values are expected as the number of milliseconds since 34 1970-01-01T00:00:00 Universal Coordinated Time - also known 35 as "The Epoch", that can be converted to QDateTime using 36 QwtDate::toDateTime(). 34 Datetime values are expected as the number of milliseconds since 35 1970-01-01T00:00:00 Universal Coordinated Time - also known 36 as "The Epoch", that can be converted to QDateTime using 37 QwtDate::toDateTime(). 37 38 38 \sa QwtDate, QwtPlot::setAxisScaleEngine(), 39 \sa QwtDate, QwtPlot::setAxisScaleEngine(), 39 40 QwtAbstractScale::setScaleEngine() 40 */ 41 class QWT_EXPORT QwtDateScaleEngine: public QwtLinearScaleEngine 41 */ 42 class QWT_EXPORT QwtDateScaleEngine : public QwtLinearScaleEngine 42 43 { 43 public: 44 QwtDateScaleEngine( Qt::TimeSpec = Qt::LocalTime ); 44 public: 45 explicit QwtDateScaleEngine( Qt::TimeSpec = Qt::LocalTime ); 45 46 virtual ~QwtDateScaleEngine(); 46 47 … … 57 58 int maxWeeks() const; 58 59 59 virtual void autoScale( int maxNumSteps, 60 double &x1, double &x2, double &stepSize ) const; 60 virtual void autoScale( 61 int maxNumSteps, double& x1, double& x2, 62 double& stepSize ) const QWT_OVERRIDE; 61 63 62 64 virtual QwtScaleDiv divideScale( 63 65 double x1, double x2, 64 66 int maxMajorSteps, int maxMinorSteps, 65 double stepSize = 0.0 ) const; 67 double stepSize = 0.0 ) const QWT_OVERRIDE; 66 68 67 69 virtual QwtDate::IntervalType intervalType( 68 const QDateTime &, const QDateTime&, int maxSteps ) const;70 const QDateTime&, const QDateTime&, int maxSteps ) const; 69 71 70 72 QDateTime toDateTime( double ) const; 71 73 72 protected: 73 virtual QDateTime alignDate( const QDateTime &, double stepSize,74 protected: 75 virtual QDateTime alignDate( const QDateTime&, double stepSize, 74 76 QwtDate::IntervalType, bool up ) const; 75 77 76 private: 77 QwtScaleDiv buildScaleDiv( const QDateTime &, const QDateTime&,78 private: 79 QwtScaleDiv buildScaleDiv( const QDateTime&, const QDateTime&, 78 80 int maxMajorSteps, int maxMinorSteps, 79 81 QwtDate::IntervalType ) const; 80 82 81 private: 83 private: 82 84 class PrivateData; 83 PrivateData *d_data;85 PrivateData* m_data; 84 86 }; 85 87 -
trunk/BNC/qwt/qwt_dial.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_dial_needle.h" 12 12 #include "qwt_math.h" 13 #include "qwt_scale_engine.h"14 13 #include "qwt_scale_map.h" 15 14 #include "qwt_round_scale_draw.h" 16 15 #include "qwt_painter.h" 16 #include "qwt.h" 17 17 18 #include <qpainter.h> 18 19 #include <qpalette.h> 19 20 #include <qpixmap.h> 20 21 #include <qevent.h> 21 #include <qalgorithms.h>22 #include <qmath.h>23 22 #include <qstyle.h> 24 23 #include <qstyleoption.h> 25 #include <qapplication.h>26 24 27 25 static inline double qwtAngleDist( double a1, double a2 ) … … 77 75 class QwtDial::PrivateData 78 76 { 79 public: 80 PrivateData() :81 frameShadow( Sunken ) ,82 lineWidth( 0 ) ,83 mode( RotateNeedle ) ,84 origin( 90.0 ) ,85 minScaleArc( 0.0 ) ,86 maxScaleArc( 0.0 ) ,87 needle( NULL ) ,88 arcOffset( 0.0 ) ,89 mouseOffset( 0.0 ) 77 public: 78 PrivateData() 79 : frameShadow( Sunken ) 80 , lineWidth( 0 ) 81 , mode( RotateNeedle ) 82 , origin( 90.0 ) 83 , minScaleArc( 0.0 ) 84 , maxScaleArc( 0.0 ) 85 , needle( NULL ) 86 , arcOffset( 0.0 ) 87 , mouseOffset( 0.0 ) 90 88 { 91 89 } … … 104 102 double maxScaleArc; 105 103 106 QwtDialNeedle *needle;104 QwtDialNeedle* needle; 107 105 108 106 double arcOffset; … … 113 111 114 112 /*! 115 \brief Constructor 116 \param parent Parent widget 117 118 Create a dial widget with no needle. The scale is initialized 119 to [ 0.0, 360.0 ] and 360 steps ( QwtAbstractSlider::setTotalSteps() ). 120 The origin of the scale is at 90°, 121 122 The value is set to 0.0. 123 124 The default mode is QwtDial::RotateNeedle. 125 */ 126 QwtDial::QwtDial( QWidget* parent ) :127 QwtAbstractSlider( parent ) 128 { 129 d_data = new PrivateData;113 \brief Constructor 114 \param parent Parent widget 115 116 Create a dial widget with no needle. The scale is initialized 117 to [ 0.0, 360.0 ] and 360 steps ( QwtAbstractSlider::setTotalSteps() ). 118 The origin of the scale is at 90°, 119 120 The value is set to 0.0. 121 122 The default mode is QwtDial::RotateNeedle. 123 */ 124 QwtDial::QwtDial( QWidget* parent ) 125 : QwtAbstractSlider( parent ) 126 { 127 m_data = new PrivateData; 130 128 131 129 setFocusPolicy( Qt::TabFocus ); … … 135 133 { 136 134 const QPalette::ColorGroup colorGroup = 137 static_cast<QPalette::ColorGroup>( i ); 135 static_cast< QPalette::ColorGroup >( i ); 138 136 139 137 // Base: background color of the circle inside the frame. … … 161 159 QwtDial::~QwtDial() 162 160 { 163 delete d_data;164 } 165 166 /*! 167 Sets the frame shadow value from the frame style. 168 169 \param shadow Frame shadow 170 \sa setLineWidth(), QFrame::setFrameShadow() 171 */ 161 delete m_data; 162 } 163 164 /*! 165 Sets the frame shadow value from the frame style. 166 167 \param shadow Frame shadow 168 \sa setLineWidth(), QFrame::setFrameShadow() 169 */ 172 170 void QwtDial::setFrameShadow( Shadow shadow ) 173 171 { 174 if ( shadow != d_data->frameShadow )172 if ( shadow != m_data->frameShadow ) 175 173 { 176 174 invalidateCache(); 177 175 178 d_data->frameShadow = shadow;176 m_data->frameShadow = shadow; 179 177 if ( lineWidth() > 0 ) 180 178 update(); … … 183 181 184 182 /*! 185 \return Frame shadow 186 /sa setFrameShadow(), lineWidth(), QFrame::frameShadow() 187 */ 183 \return Frame shadow 184 /sa setFrameShadow(), lineWidth(), QFrame::frameShadow() 185 */ 188 186 QwtDial::Shadow QwtDial::frameShadow() const 189 187 { 190 return d_data->frameShadow;191 } 192 193 /*! 194 Sets the line width of the frame 195 196 \param lineWidth Line width 197 \sa setFrameShadow() 198 */ 188 return m_data->frameShadow; 189 } 190 191 /*! 192 Sets the line width of the frame 193 194 \param lineWidth Line width 195 \sa setFrameShadow() 196 */ 199 197 void QwtDial::setLineWidth( int lineWidth ) 200 198 { … … 202 200 lineWidth = 0; 203 201 204 if ( d_data->lineWidth != lineWidth )202 if ( m_data->lineWidth != lineWidth ) 205 203 { 206 204 invalidateCache(); 207 205 208 d_data->lineWidth = lineWidth;206 m_data->lineWidth = lineWidth; 209 207 update(); 210 208 } … … 212 210 213 211 /*! 214 \return Line width of the frame 215 \sa setLineWidth(), frameShadow(), lineWidth() 216 */ 212 \return Line width of the frame 213 \sa setLineWidth(), frameShadow(), lineWidth() 214 */ 217 215 int QwtDial::lineWidth() const 218 216 { 219 return d_data->lineWidth;220 } 221 222 /*! 223 \return bounding rectangle of the circle inside the frame 224 \sa setLineWidth(), scaleInnerRect(), boundingRect() 225 */ 217 return m_data->lineWidth; 218 } 219 220 /*! 221 \return bounding rectangle of the circle inside the frame 222 \sa setLineWidth(), scaleInnerRect(), boundingRect() 223 */ 226 224 QRect QwtDial::innerRect() const 227 225 { … … 231 229 232 230 /*! 233 \return bounding rectangle of the dial including the frame 234 \sa setLineWidth(), scaleInnerRect(), innerRect() 235 */ 231 \return bounding rectangle of the dial including the frame 232 \sa setLineWidth(), scaleInnerRect(), innerRect() 233 */ 236 234 QRect QwtDial::boundingRect() const 237 235 { … … 247 245 248 246 /*! 249 \return rectangle inside the scale 250 \sa setLineWidth(), boundingRect(), innerRect() 251 */ 247 \return rectangle inside the scale 248 \sa setLineWidth(), boundingRect(), innerRect() 249 */ 252 250 QRect QwtDial::scaleInnerRect() const 253 251 { 254 252 QRect rect = innerRect(); 255 253 256 const QwtAbstractScaleDraw *sd = scaleDraw();254 const QwtAbstractScaleDraw* sd = scaleDraw(); 257 255 if ( sd ) 258 256 { 259 int scaleDist = qCeil( sd->extent( font() ) ); 257 int scaleDist = qwtCeil( sd->extent( font() ) ); 260 258 scaleDist++; // margin 261 259 … … 267 265 268 266 /*! 269 \brief Change the mode of the dial. 270 \param mode New mode 271 272 In case of QwtDial::RotateNeedle the needle is rotating, in case of 273 QwtDial::RotateScale, the needle points to origin() 274 and the scale is rotating. 275 276 The default mode is QwtDial::RotateNeedle. 277 278 \sa mode(), setValue(), setOrigin() 279 */ 267 \brief Change the mode of the dial. 268 \param mode New mode 269 270 In case of QwtDial::RotateNeedle the needle is rotating, in case of 271 QwtDial::RotateScale, the needle points to origin() 272 and the scale is rotating. 273 274 The default mode is QwtDial::RotateNeedle. 275 276 \sa mode(), setValue(), setOrigin() 277 */ 280 278 void QwtDial::setMode( Mode mode ) 281 279 { 282 if ( mode != d_data->mode )280 if ( mode != m_data->mode ) 283 281 { 284 282 invalidateCache(); 285 283 286 d_data->mode = mode;284 m_data->mode = mode; 287 285 sliderChange(); 288 286 } … … 290 288 291 289 /*! 292 \return Mode of the dial. 293 \sa setMode(), origin(), setScaleArc(), value() 294 */ 290 \return Mode of the dial. 291 \sa setMode(), origin(), setScaleArc(), value() 292 */ 295 293 QwtDial::Mode QwtDial::mode() const 296 294 { 297 return d_data->mode;298 } 299 300 /*! 301 Invalidate the internal caches used to speed up repainting 295 return m_data->mode; 296 } 297 298 /*! 299 Invalidate the internal caches used to speed up repainting 302 300 */ 303 301 void QwtDial::invalidateCache() 304 302 { 305 d_data->pixmapCache = QPixmap();303 m_data->pixmapCache = QPixmap(); 306 304 } 307 305 … … 309 307 Paint the dial 310 308 \param event Paint event 311 */ 312 void QwtDial::paintEvent( QPaintEvent *event )309 */ 310 void QwtDial::paintEvent( QPaintEvent* event ) 313 311 { 314 312 QPainter painter( this ); … … 316 314 317 315 QStyleOption opt; 318 opt.init(this); 316 opt.initFrom(this); 319 317 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 320 318 321 if ( d_data->mode == QwtDial::RotateScale )319 if ( m_data->mode == QwtDial::RotateScale ) 322 320 { 323 321 painter.save(); … … 330 328 331 329 const QRect r = contentsRect(); 332 if ( r.size() != d_data->pixmapCache.size() )333 { 334 d_data->pixmapCache = QwtPainter::backingStore( this, r.size() );335 d_data->pixmapCache.fill( Qt::transparent );336 337 QPainter p( & d_data->pixmapCache );330 if ( r.size() != m_data->pixmapCache.size() ) 331 { 332 m_data->pixmapCache = QwtPainter::backingStore( this, r.size() ); 333 m_data->pixmapCache.fill( Qt::transparent ); 334 335 QPainter p( &m_data->pixmapCache ); 338 336 p.setRenderHint( QPainter::Antialiasing, true ); 339 337 p.translate( -r.topLeft() ); 340 338 341 if ( d_data->mode != QwtDial::RotateScale )339 if ( m_data->mode != QwtDial::RotateScale ) 342 340 drawContents( &p ); 343 341 … … 345 343 drawFrame( &p ); 346 344 347 if ( d_data->mode != QwtDial::RotateNeedle )345 if ( m_data->mode != QwtDial::RotateNeedle ) 348 346 drawNeedle( &p ); 349 347 } 350 348 351 painter.drawPixmap( r.topLeft(), d_data->pixmapCache );352 353 if ( d_data->mode == QwtDial::RotateNeedle )349 painter.drawPixmap( r.topLeft(), m_data->pixmapCache ); 350 351 if ( m_data->mode == QwtDial::RotateNeedle ) 354 352 drawNeedle( &painter ); 355 353 … … 359 357 360 358 /*! 361 Draw the focus indicator 362 \param painter Painter 363 */ 364 void QwtDial::drawFocusIndicator( QPainter *painter ) const359 Draw the focus indicator 360 \param painter Painter 361 */ 362 void QwtDial::drawFocusIndicator( QPainter* painter ) const 365 363 { 366 364 QwtPainter::drawFocusRect( painter, this, boundingRect() ); … … 368 366 369 367 /*! 370 Draw the frame around the dial 371 372 \param painter Painter 373 \sa lineWidth(), frameShadow() 374 */ 375 void QwtDial::drawFrame( QPainter *painter )368 Draw the frame around the dial 369 370 \param painter Painter 371 \sa lineWidth(), frameShadow() 372 */ 373 void QwtDial::drawFrame( QPainter* painter ) 376 374 { 377 375 QwtPainter::drawRoundFrame( painter, boundingRect(), 378 palette(), lineWidth(), d_data->frameShadow );379 } 380 381 /*! 382 \brief Draw the contents inside the frame 383 384 QPalette::Window is the background color outside of the frame. 385 QPalette::Base is the background color inside the frame. 386 QPalette::WindowText is the background color inside the scale. 387 388 \param painter Painter 389 390 \sa boundingRect(), innerRect(), 376 palette(), lineWidth(), m_data->frameShadow ); 377 } 378 379 /*! 380 \brief Draw the contents inside the frame 381 382 QPalette::Window is the background color outside of the frame. 383 QPalette::Base is the background color inside the frame. 384 QPalette::WindowText is the background color inside the scale. 385 386 \param painter Painter 387 388 \sa boundingRect(), innerRect(), 391 389 scaleInnerRect(), QWidget::setPalette() 392 */ 393 void QwtDial::drawContents( QPainter *painter ) const390 */ 391 void QwtDial::drawContents( QPainter* painter ) const 394 392 { 395 393 if ( testAttribute( Qt::WA_NoSystemBackground ) || 396 394 palette().brush( QPalette::Base ) != 397 palette().brush( QPalette::Window ) )395 palette().brush( QPalette::Window ) ) 398 396 { 399 397 const QRectF br = boundingRect(); … … 408 406 const QRectF insideScaleRect = scaleInnerRect(); 409 407 if ( palette().brush( QPalette::WindowText ) != 410 palette().brush( QPalette::Base ) )408 palette().brush( QPalette::Base ) ) 411 409 { 412 410 painter->save(); … … 430 428 431 429 /*! 432 Draw the needle 433 434 \param painter Painter 435 \param center Center of the dial 436 \param radius Length for the needle 437 \param direction Direction of the needle in degrees, counter clockwise 438 \param colorGroup ColorGroup 439 */ 440 void QwtDial::drawNeedle( QPainter *painter, const QPointF¢er,430 Draw the needle 431 432 \param painter Painter 433 \param center Center of the dial 434 \param radius Length for the needle 435 \param direction Direction of the needle in degrees, counter clockwise 436 \param colorGroup ColorGroup 437 */ 438 void QwtDial::drawNeedle( QPainter* painter, const QPointF& center, 441 439 double radius, double direction, QPalette::ColorGroup colorGroup ) const 442 440 { 443 if ( d_data->needle )441 if ( m_data->needle ) 444 442 { 445 443 direction = 360.0 - direction; // counter clockwise 446 d_data->needle->draw( painter, center, radius, direction, colorGroup );447 } 448 } 449 450 void QwtDial::drawNeedle( QPainter *painter ) const444 m_data->needle->draw( painter, center, radius, direction, colorGroup ); 445 } 446 } 447 448 void QwtDial::drawNeedle( QPainter* painter ) const 451 449 { 452 450 if ( !isValid() ) … … 469 467 470 468 /*! 471 Draw the scale 472 473 \param painter Painter 474 \param center Center of the dial 475 \param radius Radius of the scale 476 */ 477 void QwtDial::drawScale( QPainter *painter,478 const QPointF ¢er, double radius ) const479 { 480 QwtRoundScaleDraw *sd = const_cast<QwtRoundScaleDraw*>( scaleDraw() );469 Draw the scale 470 471 \param painter Painter 472 \param center Center of the dial 473 \param radius Radius of the scale 474 */ 475 void QwtDial::drawScale( QPainter* painter, 476 const QPointF& center, double radius ) const 477 { 478 QwtRoundScaleDraw* sd = const_cast< QwtRoundScaleDraw* >( scaleDraw() ); 481 479 if ( sd == NULL ) 482 480 return; … … 491 489 492 490 painter->setFont( font() ); 493 painter->setPen( QPen( textColor, sd->penWidth() ) ); 491 painter->setPen( QPen( textColor, sd->penWidthF() ) ); 494 492 495 493 painter->setBrush( Qt::red ); … … 498 496 499 497 /*! 500 Draw the contents inside the scale 501 502 Paints nothing. 503 504 \param painter Painter 505 \param center Center of the contents circle 506 \param radius Radius of the contents circle 507 */ 508 void QwtDial::drawScaleContents( QPainter *painter,509 const QPointF ¢er, double radius ) const498 Draw the contents inside the scale 499 500 Paints nothing. 501 502 \param painter Painter 503 \param center Center of the contents circle 504 \param radius Radius of the contents circle 505 */ 506 void QwtDial::drawScaleContents( QPainter* painter, 507 const QPointF& center, double radius ) const 510 508 { 511 509 Q_UNUSED(painter); … … 515 513 516 514 /*! 517 Set a needle for the dial 518 519 \param needle Needle 520 521 \warning The needle will be deleted, when a different needle is 515 Set a needle for the dial 516 517 \param needle Needle 518 519 \warning The needle will be deleted, when a different needle is 522 520 set or in ~QwtDial() 523 */ 524 void QwtDial::setNeedle( QwtDialNeedle *needle )525 { 526 if ( needle != d_data->needle )527 { 528 if ( d_data->needle )529 delete d_data->needle;530 531 d_data->needle = needle;521 */ 522 void QwtDial::setNeedle( QwtDialNeedle* needle ) 523 { 524 if ( needle != m_data->needle ) 525 { 526 if ( m_data->needle ) 527 delete m_data->needle; 528 529 m_data->needle = needle; 532 530 update(); 533 531 } … … 535 533 536 534 /*! 537 \return needle 538 \sa setNeedle() 539 */ 540 const QwtDialNeedle *QwtDial::needle() const541 { 542 return d_data->needle;543 } 544 545 /*! 546 \return needle 547 \sa setNeedle() 548 */ 549 QwtDialNeedle *QwtDial::needle()550 { 551 return d_data->needle;535 \return needle 536 \sa setNeedle() 537 */ 538 const QwtDialNeedle* QwtDial::needle() const 539 { 540 return m_data->needle; 541 } 542 543 /*! 544 \return needle 545 \sa setNeedle() 546 */ 547 QwtDialNeedle* QwtDial::needle() 548 { 549 return m_data->needle; 552 550 } 553 551 554 552 //! \return the scale draw 555 QwtRoundScaleDraw *QwtDial::scaleDraw()556 { 557 return static_cast<QwtRoundScaleDraw *>( abstractScaleDraw() );553 QwtRoundScaleDraw* QwtDial::scaleDraw() 554 { 555 return static_cast< QwtRoundScaleDraw* >( abstractScaleDraw() ); 558 556 } 559 557 560 558 //! \return the scale draw 561 const QwtRoundScaleDraw *QwtDial::scaleDraw() const562 { 563 return static_cast<const QwtRoundScaleDraw *>( abstractScaleDraw() );564 } 565 566 /*! 567 Set an individual scale draw 568 569 The motivation for setting a scale draw is often 570 to overload QwtRoundScaleDraw::label() to return 571 individual tick labels. 572 573 \param scaleDraw Scale draw 574 \warning The previous scale draw is deleted 575 */ 576 void QwtDial::setScaleDraw( QwtRoundScaleDraw *scaleDraw )559 const QwtRoundScaleDraw* QwtDial::scaleDraw() const 560 { 561 return static_cast< const QwtRoundScaleDraw* >( abstractScaleDraw() ); 562 } 563 564 /*! 565 Set an individual scale draw 566 567 The motivation for setting a scale draw is often 568 to overload QwtRoundScaleDraw::label() to return 569 individual tick labels. 570 571 \param scaleDraw Scale draw 572 \warning The previous scale draw is deleted 573 */ 574 void QwtDial::setScaleDraw( QwtRoundScaleDraw* scaleDraw ) 577 575 { 578 576 setAbstractScaleDraw( scaleDraw ); … … 581 579 582 580 /*! 583 Change the arc of the scale 584 585 \param minArc Lower limit 586 \param maxArc Upper limit 587 588 \sa minScaleArc(), maxScaleArc() 589 */ 581 Change the arc of the scale 582 583 \param minArc Lower limit 584 \param maxArc Upper limit 585 586 \sa minScaleArc(), maxScaleArc() 587 */ 590 588 void QwtDial::setScaleArc( double minArc, double maxArc ) 591 589 { 592 590 if ( minArc != 360.0 && minArc != -360.0 ) 593 minArc = ::fmod( minArc, 360.0 ); 591 minArc = std::fmod( minArc, 360.0 ); 594 592 if ( maxArc != 360.0 && maxArc != -360.0 ) 595 maxArc = ::fmod( maxArc, 360.0 ); 596 597 double minScaleArc = q Min( minArc, maxArc );598 double maxScaleArc = q Max( minArc, maxArc );593 maxArc = std::fmod( maxArc, 360.0 ); 594 595 double minScaleArc = qwtMinF( minArc, maxArc ); 596 double maxScaleArc = qwtMaxF( minArc, maxArc ); 599 597 600 598 if ( maxScaleArc - minScaleArc > 360.0 ) 601 599 maxScaleArc = minScaleArc + 360.0; 602 600 603 if ( ( minScaleArc != d_data->minScaleArc ) ||604 ( maxScaleArc != d_data->maxScaleArc ) )605 { 606 d_data->minScaleArc = minScaleArc;607 d_data->maxScaleArc = maxScaleArc;601 if ( ( minScaleArc != m_data->minScaleArc ) || 602 ( maxScaleArc != m_data->maxScaleArc ) ) 603 { 604 m_data->minScaleArc = minScaleArc; 605 m_data->maxScaleArc = maxScaleArc; 608 606 609 607 invalidateCache(); … … 613 611 614 612 /*! 615 Set the lower limit for the scale arc 616 617 \param min Lower limit of the scale arc 618 \sa setScaleArc(), setMaxScaleArc() 613 Set the lower limit for the scale arc 614 615 \param min Lower limit of the scale arc 616 \sa setScaleArc(), setMaxScaleArc() 619 617 */ 620 618 void QwtDial::setMinScaleArc( double min ) 621 619 { 622 setScaleArc( min, d_data->maxScaleArc );623 } 624 625 /*! 626 \return Lower limit of the scale arc 627 \sa setScaleArc() 628 */ 620 setScaleArc( min, m_data->maxScaleArc ); 621 } 622 623 /*! 624 \return Lower limit of the scale arc 625 \sa setScaleArc() 626 */ 629 627 double QwtDial::minScaleArc() const 630 628 { 631 return d_data->minScaleArc;632 } 633 634 /*! 635 Set the upper limit for the scale arc 636 637 \param max Upper limit of the scale arc 638 \sa setScaleArc(), setMinScaleArc() 629 return m_data->minScaleArc; 630 } 631 632 /*! 633 Set the upper limit for the scale arc 634 635 \param max Upper limit of the scale arc 636 \sa setScaleArc(), setMinScaleArc() 639 637 */ 640 638 void QwtDial::setMaxScaleArc( double max ) 641 639 { 642 setScaleArc( d_data->minScaleArc, max );643 } 644 645 /*! 646 \return Upper limit of the scale arc 647 \sa setScaleArc() 648 */ 640 setScaleArc( m_data->minScaleArc, max ); 641 } 642 643 /*! 644 \return Upper limit of the scale arc 645 \sa setScaleArc() 646 */ 649 647 double QwtDial::maxScaleArc() const 650 648 { 651 return d_data->maxScaleArc;652 } 653 654 /*! 655 \brief Change the origin 656 657 The origin is the angle where scale and needle is relative to. 658 659 \param origin New origin 660 \sa origin() 661 */ 649 return m_data->maxScaleArc; 650 } 651 652 /*! 653 \brief Change the origin 654 655 The origin is the angle where scale and needle is relative to. 656 657 \param origin New origin 658 \sa origin() 659 */ 662 660 void QwtDial::setOrigin( double origin ) 663 661 { 664 662 invalidateCache(); 665 663 666 d_data->origin = origin;664 m_data->origin = origin; 667 665 sliderChange(); 668 666 } 669 667 670 668 /*! 671 The origin is the angle where scale and needle is relative to. 672 673 \return Origin of the dial 674 \sa setOrigin() 675 */ 669 The origin is the angle where scale and needle is relative to. 670 671 \return Origin of the dial 672 \sa setOrigin() 673 */ 676 674 double QwtDial::origin() const 677 675 { 678 return d_data->origin;679 } 680 681 /*! 682 \return Size hint 683 \sa minimumSizeHint() 684 */ 676 return m_data->origin; 677 } 678 679 /*! 680 \return Size hint 681 \sa minimumSizeHint() 682 */ 685 683 QSize QwtDial::sizeHint() const 686 684 { 687 685 int sh = 0; 688 686 if ( scaleDraw() ) 689 sh = qCeil( scaleDraw()->extent( font() ) ); 687 sh = qwtCeil( scaleDraw()->extent( font() ) ); 690 688 691 689 const int d = 6 * sh + 2 * lineWidth(); … … 693 691 QSize hint( d, d ); 694 692 if ( !isReadOnly() ) 695 hint = hint.expandedTo( QApplication::globalStrut());693 hint = qwtExpandedToGlobalStrut( hint ); 696 694 697 695 return hint; … … 699 697 700 698 /*! 701 \return Minimum size hint 702 \sa sizeHint() 703 */ 699 \return Minimum size hint 700 \sa sizeHint() 701 */ 704 702 QSize QwtDial::minimumSizeHint() const 705 703 { 706 704 int sh = 0; 707 705 if ( scaleDraw() ) 708 sh = qCeil( scaleDraw()->extent( font() ) ); 706 sh = qwtCeil( scaleDraw()->extent( font() ) ); 709 707 710 708 const int d = 3 * sh + 2 * lineWidth(); … … 714 712 715 713 /*! 716 \brief Determine what to do when the user presses a mouse button. 717 718 \param pos Mouse position 719 720 \retval True, when the inner circle contains pos 721 \sa scrolledTo() 722 */ 723 bool QwtDial::isScrollPosition( const QPoint &pos ) const714 \brief Determine what to do when the user presses a mouse button. 715 716 \param pos Mouse position 717 718 \retval True, when the inner circle contains pos 719 \sa scrolledTo() 720 */ 721 bool QwtDial::isScrollPosition( const QPoint& pos ) const 724 722 { 725 723 const QRegion region( innerRect(), QRegion::Ellipse ); … … 727 725 { 728 726 double angle = QLineF( rect().center(), pos ).angle(); 729 if ( d_data->mode == QwtDial::RotateScale )727 if ( m_data->mode == QwtDial::RotateScale ) 730 728 angle = 360.0 - angle; 731 729 … … 733 731 qwtNormalizeDegrees( 90.0 - scaleMap().transform( value() ) ); 734 732 735 d_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );736 d_data->arcOffset = scaleMap().p1();733 m_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle ); 734 m_data->arcOffset = scaleMap().p1(); 737 735 738 736 return true; … … 743 741 744 742 /*! 745 \brief Determine the value for a new position of the 743 \brief Determine the value for a new position of the 746 744 slider handle. 747 745 748 \param pos Mouse position 749 750 \return Value for the mouse position 751 \sa isScrollPosition() 752 */ 753 double QwtDial::scrolledTo( const QPoint &pos ) const746 \param pos Mouse position 747 748 \return Value for the mouse position 749 \sa isScrollPosition() 750 */ 751 double QwtDial::scrolledTo( const QPoint& pos ) const 754 752 { 755 753 double angle = QLineF( rect().center(), pos ).angle(); 756 if ( d_data->mode == QwtDial::RotateScale )757 { 758 angle += scaleMap().p1() - d_data->arcOffset;754 if ( m_data->mode == QwtDial::RotateScale ) 755 { 756 angle += scaleMap().p1() - m_data->arcOffset; 759 757 angle = 360.0 - angle; 760 758 } 761 759 762 angle = qwtNormalizeDegrees( angle - d_data->mouseOffset );760 angle = qwtNormalizeDegrees( angle - m_data->mouseOffset ); 763 761 angle = qwtNormalizeDegrees( 90.0 - angle ); 764 762 … … 779 777 } 780 778 781 d_data->mouseOffset += ( boundedAngle - angle );779 m_data->mouseOffset += ( boundedAngle - angle ); 782 780 783 781 angle = boundedAngle; … … 790 788 791 789 if ( !wrapping() ) 792 d_data->mouseOffset += ( boundedAngle - angle );790 m_data->mouseOffset += ( boundedAngle - angle ); 793 791 794 792 angle = boundedAngle; … … 799 797 800 798 /*! 801 Change Event handler 802 \param event Change event 803 804 Invalidates internal paint caches if necessary 805 */ 806 void QwtDial::changeEvent( QEvent *event )799 Change Event handler 800 \param event Change event 801 802 Invalidates internal paint caches if necessary 803 */ 804 void QwtDial::changeEvent( QEvent* event ) 807 805 { 808 806 switch( event->type() ) … … 826 824 827 825 /*! 828 Wheel Event handler 829 \param event Wheel event 830 */ 831 void QwtDial::wheelEvent( QWheelEvent *event ) 832 { 826 Wheel Event handler 827 \param event Wheel event 828 */ 829 void QwtDial::wheelEvent( QWheelEvent* event ) 830 { 831 #if QT_VERSION < 0x050e00 832 const QPoint wheelPos = event->pos(); 833 #else 834 const QPoint wheelPos = event->position().toPoint(); 835 #endif 836 833 837 const QRegion region( innerRect(), QRegion::Ellipse ); 834 if ( region.contains( event->pos()) )838 if ( region.contains( wheelPos ) ) 835 839 QwtAbstractSlider::wheelEvent( event ); 836 840 } … … 838 842 void QwtDial::setAngleRange( double angle, double span ) 839 843 { 840 QwtRoundScaleDraw *sd = const_cast<QwtRoundScaleDraw *>( scaleDraw() ); 841 if ( sd ) 844 if ( QwtRoundScaleDraw* sd = scaleDraw() ) 842 845 { 843 846 angle = qwtNormalizeDegrees( angle - 270.0 ); … … 847 850 848 851 /*! 849 Invalidate the internal caches and call 850 QwtAbstractSlider::scaleChange() 852 Invalidate the internal caches and call 853 QwtAbstractSlider::scaleChange() 851 854 */ 852 855 void QwtDial::scaleChange() … … 858 861 void QwtDial::sliderChange() 859 862 { 860 setAngleRange( d_data->origin +d_data->minScaleArc,861 d_data->maxScaleArc -d_data->minScaleArc );863 setAngleRange( m_data->origin + m_data->minScaleArc, 864 m_data->maxScaleArc - m_data->minScaleArc ); 862 865 863 866 if ( mode() == RotateScale ) 864 867 { 865 868 const double arc = scaleMap().transform( value() ) - scaleMap().p1(); 866 setAngleRange( d_data->origin - arc,867 d_data->maxScaleArc -d_data->minScaleArc );869 setAngleRange( m_data->origin - arc, 870 m_data->maxScaleArc - m_data->minScaleArc ); 868 871 } 869 872 870 873 QwtAbstractSlider::sliderChange(); 871 874 } 875 876 #include "moc_qwt_dial.cpp" -
trunk/BNC/qwt/qwt_dial.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_DIAL_H 11 #define QWT_DIAL_H 111 #define QWT_DIAL_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_abstract_slider.h" 15 #include "qwt_abstract_scale_draw.h" 15 16 16 #include <qframe.h> 17 17 #include <qpalette.h> … … 19 19 class QwtDialNeedle; 20 20 class QwtRoundScaleDraw; 21 class QwtAbstractScaleDraw; 21 22 22 23 /*! 23 \brief QwtDial class provides a rounded range control. 24 \brief QwtDial class provides a rounded range control. 24 25 25 QwtDial is intended as base class for dial widgets like 26 speedometers, compass widgets, clocks ... 26 QwtDial is intended as base class for dial widgets like 27 speedometers, compass widgets, clocks ... 27 28 28 \image html dials2.png 29 \image html dials2.png 29 30 30 A dial contains a scale and a needle indicating the current value 31 of the dial. Depending on Mode one of them is fixed and the 32 other is rotating. If not isReadOnly() the 33 dial can be rotated by dragging the mouse or using keyboard inputs 34 (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means 35 a rotation below/above one limit continues on the other limit (f.e compass). 36 The scale might cover any arc of the dial, its values are related to 37 the origin() of the dial. 31 A dial contains a scale and a needle indicating the current value 32 of the dial. Depending on Mode one of them is fixed and the 33 other is rotating. If not isReadOnly() the 34 dial can be rotated by dragging the mouse or using keyboard inputs 35 (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means 36 a rotation below/above one limit continues on the other limit (f.e compass). 37 The scale might cover any arc of the dial, its values are related to 38 the origin() of the dial. 38 39 39 Often dials have to be updated very often according to values from external 40 devices. For these high refresh rates QwtDial caches as much as possible. 41 For derived classes it might be necessary to clear these caches manually 42 according to attribute changes using invalidateCache(). 40 Often dials have to be updated very often according to values from external 41 devices. For these high refresh rates QwtDial caches as much as possible. 42 For derived classes it might be necessary to clear these caches manually 43 according to attribute changes using invalidateCache(). 43 44 44 \sa QwtCompass, QwtAnalogClock, QwtDialNeedle 45 \note The controls and dials examples shows different types of dials. 46 \note QDial is more similar to QwtKnob than to QwtDial 47 */ 45 \sa QwtCompass, QwtAnalogClock, QwtDialNeedle 46 \note The controls and dials examples shows different types of dials. 47 \note QDial is more similar to QwtKnob than to QwtDial 48 */ 48 49 49 class QWT_EXPORT QwtDial: public QwtAbstractSlider 50 class QWT_EXPORT QwtDial : public QwtAbstractSlider 50 51 { 51 52 Q_OBJECT … … 60 61 Q_PROPERTY( double maxScaleArc READ maxScaleArc WRITE setMaxScaleArc ) 61 62 62 public: 63 public: 63 64 64 65 /*! … … 92 93 }; 93 94 94 explicit QwtDial( QWidget *parent = NULL );95 explicit QwtDial( QWidget* parent = NULL ); 95 96 virtual ~QwtDial(); 96 97 … … 115 116 double origin() const; 116 117 117 void setNeedle( QwtDialNeedle * );118 const QwtDialNeedle *needle() const;119 QwtDialNeedle *needle();118 void setNeedle( QwtDialNeedle* ); 119 const QwtDialNeedle* needle() const; 120 QwtDialNeedle* needle(); 120 121 121 122 QRect boundingRect() const; … … 124 125 virtual QRect scaleInnerRect() const; 125 126 126 virtual QSize sizeHint() const; 127 virtual QSize minimumSizeHint() const; 127 virtual QSize sizeHint() const QWT_OVERRIDE; 128 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 128 129 129 void setScaleDraw( QwtRoundScaleDraw * );130 void setScaleDraw( QwtRoundScaleDraw* ); 130 131 131 QwtRoundScaleDraw *scaleDraw();132 const QwtRoundScaleDraw *scaleDraw() const;132 QwtRoundScaleDraw* scaleDraw(); 133 const QwtRoundScaleDraw* scaleDraw() const; 133 134 134 protected: 135 virtual void wheelEvent( QWheelEvent * );136 virtual void paintEvent( QPaintEvent * );137 virtual void changeEvent( QEvent * );135 protected: 136 virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE; 137 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 138 virtual void changeEvent( QEvent* ) QWT_OVERRIDE; 138 139 139 virtual void drawFrame( QPainter * );140 virtual void drawContents( QPainter * ) const;141 virtual void drawFocusIndicator( QPainter * ) const;140 virtual void drawFrame( QPainter* ); 141 virtual void drawContents( QPainter* ) const; 142 virtual void drawFocusIndicator( QPainter* ) const; 142 143 143 144 void invalidateCache(); 144 145 145 virtual void drawScale( QPainter *,146 const QPointF ¢er, double radius ) const;146 virtual void drawScale( QPainter*, 147 const QPointF& center, double radius ) const; 147 148 148 virtual void drawScaleContents( QPainter *painter,149 const QPointF ¢er, double radius ) const;149 virtual void drawScaleContents( QPainter* painter, 150 const QPointF& center, double radius ) const; 150 151 151 virtual void drawNeedle( QPainter *, const QPointF&,152 virtual void drawNeedle( QPainter*, const QPointF&, 152 153 double radius, double direction, QPalette::ColorGroup ) const; 153 154 154 virtual double scrolledTo( const QPoint & ) const;155 virtual bool isScrollPosition( const QPoint & ) const;155 virtual double scrolledTo( const QPoint& ) const QWT_OVERRIDE; 156 virtual bool isScrollPosition( const QPoint& ) const QWT_OVERRIDE; 156 157 157 virtual void sliderChange(); 158 virtual void scaleChange(); 158 virtual void sliderChange() QWT_OVERRIDE; 159 virtual void scaleChange() QWT_OVERRIDE; 159 160 160 private: 161 private: 161 162 void setAngleRange( double angle, double span ); 162 void drawNeedle( QPainter * ) const;163 void drawNeedle( QPainter* ) const; 163 164 164 165 class PrivateData; 165 PrivateData *d_data;166 PrivateData* m_data; 166 167 }; 167 168 -
trunk/BNC/qwt/qwt_dial_needle.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_dial_needle.h" 11 #include "qwt_global.h"12 11 #include "qwt_math.h" 13 #include "qwt_painter.h" 12 14 13 #include <qapplication.h> 15 14 #include <qpainter.h> 16 15 #include <qpainterpath.h> 17 18 #if QT_VERSION < 0x040601 19 #define qFastSin(x) qSin(x) 20 #define qFastCos(x) qCos(x) 21 #endif 22 23 static void qwtDrawStyle1Needle( QPainter *painter, 24 const QPalette &palette, QPalette::ColorGroup colorGroup, 25 double length ) 26 { 27 const double r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 }; 28 const double a[] = { -45, -20, -15, 0, 15, 20, 45 }; 16 #include <qmath.h> 17 18 static void qwtDrawStyle1Needle( QPainter* painter, 19 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length ) 20 { 21 const qreal r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 }; 22 const qreal a[] = { -45, -20, -15, 0, 15, 20, 45 }; 29 23 30 24 QPainterPath path; 31 25 for ( int i = 0; i < 7; i++ ) 32 26 { 33 const doubleangle = a[i] / 180.0 * M_PI;34 const doubleradius = r[i] * length;35 36 const doublex = radius * qFastCos( angle );37 const doubley = radius * qFastSin( angle );27 const qreal angle = a[i] / 180.0 * M_PI; 28 const qreal radius = r[i] * length; 29 30 const qreal x = radius * qFastCos( angle ); 31 const qreal y = radius * qFastSin( angle ); 38 32 39 33 path.lineTo( x, -y ); … … 45 39 } 46 40 47 static void qwtDrawStyle2Needle( QPainter *painter,48 const QPalette &palette, QPalette::ColorGroup colorGroup,doublelength )49 { 50 const doubleratioX = 0.7;51 const doubleratioY = 0.3;41 static void qwtDrawStyle2Needle( QPainter* painter, 42 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length ) 43 { 44 const qreal ratioX = 0.7; 45 const qreal ratioY = 0.3; 52 46 53 47 QPainterPath path1; … … 68 62 } 69 63 70 static void qwtDrawShadedPointer( QPainter *painter,71 const QColor &lightColor, const QColor&darkColor,72 doublelength,doublewidth )73 { 74 const doublepeak = qMax( length / 10.0, 5.0 );75 76 const doubleknobWidth = width + 8;64 static void qwtDrawShadedPointer( QPainter* painter, 65 const QColor& lightColor, const QColor& darkColor, 66 qreal length, qreal width ) 67 { 68 const qreal peak = qwtMaxF( length / 10.0, 5.0 ); 69 70 const qreal knobWidth = width + 8; 77 71 QRectF knobRect( 0, 0, knobWidth, knobWidth ); 78 72 knobRect.moveCenter( QPointF(0, 0) ); … … 109 103 } 110 104 111 static void qwtDrawArrowNeedle( QPainter *painter,112 const QPalette &palette, QPalette::ColorGroup colorGroup,113 doublelength,doublewidth )105 static void qwtDrawArrowNeedle( QPainter* painter, 106 const QPalette& palette, QPalette::ColorGroup colorGroup, 107 qreal length, qreal width ) 114 108 { 115 109 if ( width <= 0 ) 116 width = q Max( length * 0.06, 9.0 );117 118 const doublepeak = qMax( 2.0, 0.4 * width );110 width = qwtMaxF( length * 0.06, 9.0 ); 111 112 const qreal peak = qwtMaxF( 2.0, 0.4 * width ); 119 113 120 114 QPainterPath path; … … 146 140 } 147 141 148 static void qwtDrawTriangleNeedle( QPainter *painter, 149 const QPalette &palette, QPalette::ColorGroup colorGroup, 150 double length ) 151 { 152 const double width = qRound( length / 3.0 ); 142 static void qwtDrawTriangleNeedle( QPainter* painter, 143 const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length ) 144 { 145 const qreal width = qRound( length / 3.0 ); 153 146 154 147 QPainterPath path[4]; … … 167 160 168 161 169 const int colorOffset = 10;162 const int colorOffset = 10; 170 163 const QColor darkColor = palette.color( colorGroup, QPalette::Dark ); 171 164 const QColor lightColor = palette.color( colorGroup, QPalette::Light ); … … 187 180 188 181 //! Constructor 189 QwtDialNeedle::QwtDialNeedle() :190 d_palette( QApplication::palette() )182 QwtDialNeedle::QwtDialNeedle() 183 : m_palette( QApplication::palette() ) 191 184 { 192 185 } … … 201 194 202 195 \param palette New Palette 203 */ 204 void QwtDialNeedle::setPalette( const QPalette &palette )205 { 206 d_palette = palette;207 } 208 209 /*! 210 \return the palette of the needle. 211 */ 212 const QPalette &QwtDialNeedle::palette() const213 { 214 return d_palette;215 } 216 217 /*! 218 Draw the needle 219 220 \param painter Painter 221 \param center Center of the dial, start position for the needle 222 \param length Length of the needle 223 \param direction Direction of the needle, in degrees counter clockwise 224 \param colorGroup Color group, used for painting 225 */ 226 void QwtDialNeedle::draw( QPainter *painter,227 const QPointF ¢er, double length, double direction,196 */ 197 void QwtDialNeedle::setPalette( const QPalette& palette ) 198 { 199 m_palette = palette; 200 } 201 202 /*! 203 \return the palette of the needle. 204 */ 205 const QPalette& QwtDialNeedle::palette() const 206 { 207 return m_palette; 208 } 209 210 /*! 211 Draw the needle 212 213 \param painter Painter 214 \param center Center of the dial, start position for the needle 215 \param length Length of the needle 216 \param direction Direction of the needle, in degrees counter clockwise 217 \param colorGroup Color group, used for painting 218 */ 219 void QwtDialNeedle::draw( QPainter* painter, 220 const QPointF& center, double length, double direction, 228 221 QPalette::ColorGroup colorGroup ) const 229 222 { … … 239 232 240 233 //! Draw the knob 241 void QwtDialNeedle::drawKnob( QPainter *painter,242 double width, const QBrush &brush, bool sunken ) const234 void QwtDialNeedle::drawKnob( QPainter* painter, 235 double width, const QBrush& brush, bool sunken ) const 243 236 { 244 237 QPalette palette( brush.color() ); … … 251 244 252 245 QRectF rect( 0.0, 0.0, width, width ); 253 rect.moveCenter( painter-> combinedTransform().map( QPointF() ) );246 rect.moveCenter( painter->transform().map( QPointF() ) ); 254 247 255 248 QLinearGradient gradient( rect.topLeft(), rect.bottomRight() ); … … 271 264 272 265 /*! 273 Constructor 274 275 \param style Style 276 \param hasKnob With/Without knob 277 \param mid Middle color 278 \param base Base color 279 */ 266 Constructor 267 268 \param style Style 269 \param hasKnob With/Without knob 270 \param mid Middle color 271 \param base Base color 272 */ 280 273 QwtDialSimpleNeedle::QwtDialSimpleNeedle( Style style, bool hasKnob, 281 const QColor&mid, const QColor&base ):282 d_style( style ),283 d_hasKnob( hasKnob ),284 d_width( -1 )274 const QColor& mid, const QColor& base ): 275 m_style( style ), 276 m_hasKnob( hasKnob ), 277 m_width( -1 ) 285 278 { 286 279 QPalette palette; … … 292 285 293 286 /*! 294 Set the width of the needle 295 \param width Width 296 \sa width() 297 */ 287 Set the width of the needle 288 \param width Width 289 \sa width() 290 */ 298 291 void QwtDialSimpleNeedle::setWidth( double width ) 299 292 { 300 d_width = width;301 } 302 303 /*! 304 \return the width of the needle 305 \sa setWidth() 306 */ 293 m_width = width; 294 } 295 296 /*! 297 \return the width of the needle 298 \sa setWidth() 299 */ 307 300 double QwtDialSimpleNeedle::width() const 308 301 { 309 return d_width;310 } 311 312 /*! 313 Draw the needle 314 315 \param painter Painter 316 \param length Length of the needle 317 \param colorGroup Color group, used for painting 318 */ 319 void QwtDialSimpleNeedle::drawNeedle( QPainter *painter,302 return m_width; 303 } 304 305 /*! 306 Draw the needle 307 308 \param painter Painter 309 \param length Length of the needle 310 \param colorGroup Color group, used for painting 311 */ 312 void QwtDialSimpleNeedle::drawNeedle( QPainter* painter, 320 313 double length, QPalette::ColorGroup colorGroup ) const 321 314 { 322 doubleknobWidth = 0.0;323 doublewidth =d_width;324 325 if ( d_style == Arrow )315 qreal knobWidth = 0.0; 316 qreal width = m_width; 317 318 if ( m_style == Arrow ) 326 319 { 327 320 if ( width <= 0.0 ) 328 width = q Max(length * 0.06, 6.0);321 width = qwtMaxF( length * 0.06, 6.0 ); 329 322 330 323 qwtDrawArrowNeedle( painter, 331 324 palette(), colorGroup, length, width ); 332 325 333 knobWidth = q Min( width * 2.0, 0.2 * length );326 knobWidth = qwtMinF( width * 2.0, 0.2 * length ); 334 327 } 335 328 else … … 344 337 painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) ); 345 338 346 knobWidth = q Max( width * 3.0, 5.0 );347 } 348 349 if ( d_hasKnob && knobWidth > 0.0 )339 knobWidth = qwtMaxF( width * 3.0, 5.0 ); 340 } 341 342 if ( m_hasKnob && knobWidth > 0.0 ) 350 343 { 351 344 drawKnob( painter, knobWidth, … … 356 349 //! Constructor 357 350 QwtCompassMagnetNeedle::QwtCompassMagnetNeedle( Style style, 358 const QColor&light, const QColor&dark ):359 d_style( style )351 const QColor& light, const QColor& dark ): 352 m_style( style ) 360 353 { 361 354 QPalette palette; … … 373 366 \param length Length of the needle 374 367 \param colorGroup Color group, used for painting 375 */ 376 void QwtCompassMagnetNeedle::drawNeedle( QPainter *painter,368 */ 369 void QwtCompassMagnetNeedle::drawNeedle( QPainter* painter, 377 370 double length, QPalette::ColorGroup colorGroup ) const 378 371 { 379 if ( d_style == ThinStyle )380 { 381 const doublewidth = qMax( length / 6.0, 3.0 );372 if ( m_style == ThinStyle ) 373 { 374 const qreal width = qwtMaxF( length / 6.0, 3.0 ); 382 375 383 376 const int colorOffset = 10; … … 413 406 \param light Light color 414 407 \param dark Dark color 415 */ 408 */ 416 409 QwtCompassWindArrow::QwtCompassWindArrow( Style style, 417 const QColor&light, const QColor&dark ):418 d_style( style )410 const QColor& light, const QColor& dark ): 411 m_style( style ) 419 412 { 420 413 QPalette palette; … … 426 419 427 420 /*! 428 Draw the needle 429 430 \param painter Painter 431 \param length Length of the needle 432 \param colorGroup Color group, used for painting 433 */ 434 void QwtCompassWindArrow::drawNeedle( QPainter *painter,421 Draw the needle 422 423 \param painter Painter 424 \param length Length of the needle 425 \param colorGroup Color group, used for painting 426 */ 427 void QwtCompassWindArrow::drawNeedle( QPainter* painter, 435 428 double length, QPalette::ColorGroup colorGroup ) const 436 429 { 437 if ( d_style == Style1 )430 if ( m_style == Style1 ) 438 431 qwtDrawStyle1Needle( painter, palette(), colorGroup, length ); 439 432 else -
trunk/BNC/qwt/qwt_dial_needle.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_DIAL_NEEDLE_H 11 #define QWT_DIAL_NEEDLE_H 111 #define QWT_DIAL_NEEDLE_H 12 12 13 13 #include "qwt_global.h" … … 15 15 16 16 class QPainter; 17 class QPoint;18 17 19 18 /*! 20 \brief Base class for needles that can be used in a QwtDial. 19 \brief Base class for needles that can be used in a QwtDial. 21 20 22 QwtDialNeedle is a pointer that indicates a value by pointing 23 to a specific direction. 21 QwtDialNeedle is a pointer that indicates a value by pointing 22 to a specific direction. 24 23 25 \sa QwtDial, QwtCompass 26 */ 24 \sa QwtDial, QwtCompass 25 */ 27 26 28 27 class QWT_EXPORT QwtDialNeedle 29 28 { 30 public: 29 public: 31 30 QwtDialNeedle(); 32 31 virtual ~QwtDialNeedle(); 33 32 34 virtual void setPalette( const QPalette & );35 const QPalette &palette() const;33 virtual void setPalette( const QPalette& ); 34 const QPalette& palette() const; 36 35 37 virtual void draw( QPainter *painter, const QPointF¢er,36 virtual void draw( QPainter*, const QPointF& center, 38 37 double length, double direction, 39 38 QPalette::ColorGroup = QPalette::Active ) const; 40 39 41 protected: 40 protected: 42 41 /*! 43 \brief Draw the needle 42 \brief Draw the needle 44 43 45 The origin of the needle is at position (0.0, 0.0 ) 46 pointing in direction 0.0 ( = east ). 44 The origin of the needle is at position (0.0, 0.0 ) 45 pointing in direction 0.0 ( = east ). 47 46 48 The painter is already initialized with translation and 49 rotation. 47 The painter is already initialized with translation and 48 rotation. 50 49 51 \param painter Painter 52 \param length Length of the needle 53 \param colorGroup Color group, used for painting 50 \param painter Painter 51 \param length Length of the needle 52 \param colorGroup Color group, used for painting 54 53 55 \sa setPalette(), palette() 56 */ 57 virtual void drawNeedle( QPainter *painter,54 \sa setPalette(), palette() 55 */ 56 virtual void drawNeedle( QPainter* painter, 58 57 double length, QPalette::ColorGroup colorGroup ) const = 0; 59 58 60 virtual void drawKnob( QPainter *, double width,61 const QBrush &, bool sunken ) const;59 virtual void drawKnob( QPainter*, double width, 60 const QBrush&, bool sunken ) const; 62 61 63 private: 64 QPalette d_palette; 62 private: 63 Q_DISABLE_COPY(QwtDialNeedle) 64 65 QPalette m_palette; 65 66 }; 66 67 67 68 /*! 68 \brief A needle for dial widgets 69 \brief A needle for dial widgets 69 70 70 The following colors are used: 71 The following colors are used: 71 72 72 - QPalette::Mid\n 73 - QPalette::Mid\n 73 74 Pointer 74 - QPalette::Base\n 75 - QPalette::Base\n 75 76 Knob 76 77 77 \sa QwtDial, QwtCompass 78 */ 78 \sa QwtDial, QwtCompass 79 */ 79 80 80 class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle 81 class QWT_EXPORT QwtDialSimpleNeedle : public QwtDialNeedle 81 82 { 82 public: 83 public: 83 84 //! Style of the needle 84 85 enum Style … … 92 93 93 94 QwtDialSimpleNeedle( Style, bool hasKnob = true, 94 const QColor &mid = Qt::gray, const QColor&base = Qt::darkGray );95 const QColor& mid = Qt::gray, const QColor& base = Qt::darkGray ); 95 96 96 97 void setWidth( double width ); 97 98 double width() const; 98 99 99 protected: 100 virtual void drawNeedle( QPainter *, double length,101 QPalette::ColorGroup ) const; 100 protected: 101 virtual void drawNeedle( QPainter*, double length, 102 QPalette::ColorGroup ) const QWT_OVERRIDE; 102 103 103 private: 104 Style d_style;105 bool d_hasKnob;106 double d_width;104 private: 105 Style m_style; 106 bool m_hasKnob; 107 double m_width; 107 108 }; 108 109 109 110 /*! 110 \brief A magnet needle for compass widgets 111 \brief A magnet needle for compass widgets 111 112 112 A magnet needle points to two opposite directions indicating 113 north and south. 113 A magnet needle points to two opposite directions indicating 114 north and south. 114 115 115 The following colors are used: 116 - QPalette::Light\n 116 The following colors are used: 117 - QPalette::Light\n 117 118 Used for pointing south 118 - QPalette::Dark\n 119 - QPalette::Dark\n 119 120 Used for pointing north 120 - QPalette::Base\n 121 - QPalette::Base\n 121 122 Knob (ThinStyle only) 122 123 123 \sa QwtDial, QwtCompass 124 */ 124 \sa QwtDial, QwtCompass 125 */ 125 126 126 class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle 127 class QWT_EXPORT QwtCompassMagnetNeedle : public QwtDialNeedle 127 128 { 128 public: 129 public: 129 130 //! Style of the needle 130 131 enum Style … … 138 139 139 140 QwtCompassMagnetNeedle( Style = TriangleStyle, 140 const QColor &light = Qt::white, const QColor&dark = Qt::red );141 const QColor& light = Qt::white, const QColor& dark = Qt::red ); 141 142 142 protected: 143 virtual void drawNeedle( QPainter *,144 double length, QPalette::ColorGroup ) const; 143 protected: 144 virtual void drawNeedle( QPainter*, 145 double length, QPalette::ColorGroup ) const QWT_OVERRIDE; 145 146 146 private: 147 Style d_style;147 private: 148 Style m_style; 148 149 }; 149 150 150 151 /*! 151 \brief An indicator for the wind direction 152 \brief An indicator for the wind direction 152 153 153 QwtCompassWindArrow shows the direction where the wind comes from. 154 QwtCompassWindArrow shows the direction where the wind comes from. 154 155 155 - QPalette::Light\n 156 - QPalette::Light\n 156 157 Used for Style1, or the light half of Style2 157 - QPalette::Dark\n 158 - QPalette::Dark\n 158 159 Used for the dark half of Style2 159 160 160 \sa QwtDial, QwtCompass 161 */ 161 \sa QwtDial, QwtCompass 162 */ 162 163 163 class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle 164 class QWT_EXPORT QwtCompassWindArrow : public QwtDialNeedle 164 165 { 165 public: 166 public: 166 167 //! Style of the arrow 167 168 enum Style … … 174 175 }; 175 176 176 QwtCompassWindArrow( Style, const QColor &light = Qt::white,177 const QColor &dark = Qt::gray );177 QwtCompassWindArrow( Style, const QColor& light = Qt::white, 178 const QColor& dark = Qt::gray ); 178 179 179 protected: 180 virtual void drawNeedle( QPainter *,181 double length, QPalette::ColorGroup ) const; 180 protected: 181 virtual void drawNeedle( QPainter*, 182 double length, QPalette::ColorGroup ) const QWT_OVERRIDE; 182 183 183 private: 184 Style d_style;184 private: 185 Style m_style; 185 186 }; 186 187 -
trunk/BNC/qwt/qwt_dyngrid_layout.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_dyngrid_layout.h" 11 #include "qwt_math.h" 11 12 12 #include <qvector.h> 13 13 #include <qlist.h> … … 15 15 class QwtDynGridLayout::PrivateData 16 16 { 17 public: 18 PrivateData() :19 isDirty( true ) 17 public: 18 PrivateData() 19 : isDirty( true ) 20 20 { 21 21 } … … 23 23 void updateLayoutCache(); 24 24 25 mutable QList<QLayoutItem*> itemList; 25 mutable QList< QLayoutItem* > itemList; 26 26 27 27 uint maxColumns; … … 32 32 33 33 bool isDirty; 34 QVector< QSize> itemSizeHints;34 QVector< QSize > itemSizeHints; 35 35 }; 36 36 … … 41 41 int index = 0; 42 42 43 for ( QList<QLayoutItem* >::iterator it = itemList.begin();44 it != itemList. end(); ++it, index++ )43 for ( QList< QLayoutItem* >::const_iterator it = itemList.constBegin(); 44 it != itemList.constEnd(); ++it, index++ ) 45 45 { 46 46 itemSizeHints[ index ] = ( *it )->sizeHint(); … … 51 51 52 52 /*! 53 \param parent Parent widget 54 \param margin Margin 55 \param spacing Spacing 56 */ 57 58 QwtDynGridLayout::QwtDynGridLayout( QWidget *parent, 59 int margin, int spacing ): 60 QLayout( parent ) 53 \param parent Parent widget 54 \param margin Margin 55 \param spacing Spacing 56 */ 57 58 QwtDynGridLayout::QwtDynGridLayout( QWidget* parent, int margin, int spacing ) 59 : QLayout( parent ) 61 60 { 62 61 init(); 63 62 64 63 setSpacing( spacing ); 65 set Margin(margin );66 } 67 68 /*! 69 \param spacing Spacing 70 */ 64 setContentsMargins( margin, margin, margin, margin ); 65 } 66 67 /*! 68 \param spacing Spacing 69 */ 71 70 72 71 QwtDynGridLayout::QwtDynGridLayout( int spacing ) … … 77 76 78 77 /*! 79 Initialize the layout with default values. 80 */ 78 Initialize the layout with default values. 79 */ 81 80 void QwtDynGridLayout::init() 82 81 { 83 d_data = new QwtDynGridLayout::PrivateData; 84 d_data->maxColumns = d_data->numRows = d_data->numColumns = 0; 85 d_data->expanding = 0; 82 m_data = new QwtDynGridLayout::PrivateData; 83 m_data->maxColumns = m_data->numRows = m_data->numColumns = 0; 86 84 } 87 85 … … 90 88 QwtDynGridLayout::~QwtDynGridLayout() 91 89 { 92 for ( int i = 0; i < d_data->itemList.size(); i++ ) 93 delete d_data->itemList[i]; 94 95 delete d_data; 90 qDeleteAll( m_data->itemList ); 91 delete m_data; 96 92 } 97 93 … … 99 95 void QwtDynGridLayout::invalidate() 100 96 { 101 d_data->isDirty = true;97 m_data->isDirty = true; 102 98 QLayout::invalidate(); 103 99 } 104 100 105 101 /*! 106 Limit the number of columns. 107 \param maxColumns upper limit, 0 means unlimited 108 \sa maxColumns() 109 */ 102 Limit the number of columns. 103 \param maxColumns upper limit, 0 means unlimited 104 \sa maxColumns() 105 */ 110 106 void QwtDynGridLayout::setMaxColumns( uint maxColumns ) 111 107 { 112 d_data->maxColumns = maxColumns;113 } 114 115 /*! 116 \brief Return the upper limit for the number of columns. 117 118 0 means unlimited, what is the default. 119 120 \return Upper limit for the number of columns 121 \sa setMaxColumns() 122 */ 108 m_data->maxColumns = maxColumns; 109 } 110 111 /*! 112 \brief Return the upper limit for the number of columns. 113 114 0 means unlimited, what is the default. 115 116 \return Upper limit for the number of columns 117 \sa setMaxColumns() 118 */ 123 119 uint QwtDynGridLayout::maxColumns() const 124 120 { 125 return d_data->maxColumns;126 } 127 128 /*! 129 \brief Add an item to the next free position. 130 \param item Layout item 131 */ 132 void QwtDynGridLayout::addItem( QLayoutItem *item )133 { 134 d_data->itemList.append( item );121 return m_data->maxColumns; 122 } 123 124 /*! 125 \brief Add an item to the next free position. 126 \param item Layout item 127 */ 128 void QwtDynGridLayout::addItem( QLayoutItem* item ) 129 { 130 m_data->itemList.append( item ); 135 131 invalidate(); 136 132 } 137 133 138 134 /*! 139 \return true if this layout is empty. 140 */ 135 \return true if this layout is empty. 136 */ 141 137 bool QwtDynGridLayout::isEmpty() const 142 138 { 143 return d_data->itemList.isEmpty();144 } 145 146 /*! 147 \return number of layout items 148 */ 139 return m_data->itemList.isEmpty(); 140 } 141 142 /*! 143 \return number of layout items 144 */ 149 145 uint QwtDynGridLayout::itemCount() const 150 146 { 151 return d_data->itemList.count();152 } 153 154 /*! 155 Find the item at a specific index 156 157 \param index Index 158 \return Item at a specific index 159 \sa takeAt() 160 */ 161 QLayoutItem *QwtDynGridLayout::itemAt( int index ) const162 { 163 if ( index < 0 || index >= d_data->itemList.count() )147 return m_data->itemList.count(); 148 } 149 150 /*! 151 Find the item at a specific index 152 153 \param index Index 154 \return Item at a specific index 155 \sa takeAt() 156 */ 157 QLayoutItem* QwtDynGridLayout::itemAt( int index ) const 158 { 159 if ( index < 0 || index >= m_data->itemList.count() ) 164 160 return NULL; 165 161 166 return d_data->itemList.at( index );167 } 168 169 /*! 170 Find the item at a specific index and remove it from the layout 171 172 \param index Index 173 \return Layout item, removed from the layout 174 \sa itemAt() 175 */ 176 QLayoutItem *QwtDynGridLayout::takeAt( int index )177 { 178 if ( index < 0 || index >= d_data->itemList.count() )162 return m_data->itemList.at( index ); 163 } 164 165 /*! 166 Find the item at a specific index and remove it from the layout 167 168 \param index Index 169 \return Layout item, removed from the layout 170 \sa itemAt() 171 */ 172 QLayoutItem* QwtDynGridLayout::takeAt( int index ) 173 { 174 if ( index < 0 || index >= m_data->itemList.count() ) 179 175 return NULL; 180 176 181 d_data->isDirty = true;182 return d_data->itemList.takeAt( index );177 m_data->isDirty = true; 178 return m_data->itemList.takeAt( index ); 183 179 } 184 180 … … 186 182 int QwtDynGridLayout::count() const 187 183 { 188 return d_data->itemList.count();189 } 190 191 /*! 192 Set whether this layout can make use of more space than sizeHint(). 193 A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only 194 one dimension, while Qt::Vertical | Qt::Horizontal means that it wants 195 to grow in both dimensions. The default value is 0. 196 197 \param expanding Or'd orientations 198 \sa expandingDirections() 199 */ 184 return m_data->itemList.count(); 185 } 186 187 /*! 188 Set whether this layout can make use of more space than sizeHint(). 189 A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only 190 one dimension, while Qt::Vertical | Qt::Horizontal means that it wants 191 to grow in both dimensions. The default value is 0. 192 193 \param expanding Or'd orientations 194 \sa expandingDirections() 195 */ 200 196 void QwtDynGridLayout::setExpandingDirections( Qt::Orientations expanding ) 201 197 { 202 d_data->expanding = expanding;203 } 204 205 /*! 206 \brief Returns whether this layout can make use of more space than sizeHint(). 207 208 A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only 209 one dimension, while Qt::Vertical | Qt::Horizontal means that it wants 210 to grow in both dimensions. 211 212 \return Orientations, where the layout expands 213 \sa setExpandingDirections() 214 */ 198 m_data->expanding = expanding; 199 } 200 201 /*! 202 \brief Returns whether this layout can make use of more space than sizeHint(). 203 204 A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only 205 one dimension, while Qt::Vertical | Qt::Horizontal means that it wants 206 to grow in both dimensions. 207 208 \return Orientations, where the layout expands 209 \sa setExpandingDirections() 210 */ 215 211 Qt::Orientations QwtDynGridLayout::expandingDirections() const 216 212 { 217 return d_data->expanding;218 } 219 220 /*! 221 Reorganizes columns and rows and resizes managed items within 222 a rectangle. 223 224 \param rect Layout geometry 225 */ 226 void QwtDynGridLayout::setGeometry( const QRect &rect )213 return m_data->expanding; 214 } 215 216 /*! 217 Reorganizes columns and rows and resizes managed items within 218 a rectangle. 219 220 \param rect Layout geometry 221 */ 222 void QwtDynGridLayout::setGeometry( const QRect& rect ) 227 223 { 228 224 QLayout::setGeometry( rect ); … … 231 227 return; 232 228 233 d_data->numColumns = columnsForWidth( rect.width() );234 d_data->numRows = itemCount() /d_data->numColumns;235 if ( itemCount() % d_data->numColumns )236 d_data->numRows++;237 238 QList<QRect> itemGeometries = layoutItems( rect,d_data->numColumns );229 m_data->numColumns = columnsForWidth( rect.width() ); 230 m_data->numRows = itemCount() / m_data->numColumns; 231 if ( itemCount() % m_data->numColumns ) 232 m_data->numRows++; 233 234 const QList< QRect > itemGeometries = layoutItems( rect, m_data->numColumns ); 239 235 240 236 int index = 0; 241 for ( QList<QLayoutItem* >::iterator it =d_data->itemList.begin();242 it != d_data->itemList.end(); ++it )237 for ( QList< QLayoutItem* >::const_iterator it = m_data->itemList.constBegin(); 238 it != m_data->itemList.constEnd(); ++it ) 243 239 { 244 240 ( *it )->setGeometry( itemGeometries[index] ); … … 248 244 249 245 /*! 250 \brief Calculate the number of columns for a given width. 251 252 The calculation tries to use as many columns as possible 253 ( limited by maxColumns() ) 254 255 \param width Available width for all columns 256 \return Number of columns for a given width 257 258 \sa maxColumns(), setMaxColumns() 259 */ 246 \brief Calculate the number of columns for a given width. 247 248 The calculation tries to use as many columns as possible 249 ( limited by maxColumns() ) 250 251 \param width Available width for all columns 252 \return Number of columns for a given width 253 254 \sa maxColumns(), setMaxColumns() 255 */ 260 256 uint QwtDynGridLayout::columnsForWidth( int width ) const 261 257 { … … 264 260 265 261 uint maxColumns = itemCount(); 266 if ( d_data->maxColumns > 0 )267 maxColumns = qMin( d_data->maxColumns, maxColumns );262 if ( m_data->maxColumns > 0 ) 263 maxColumns = qMin( m_data->maxColumns, maxColumns ); 268 264 269 265 if ( maxRowWidth( maxColumns ) <= width ) … … 281 277 282 278 /*! 283 Calculate the width of a layout for a given number of 284 columns. 285 286 \param numColumns Given number of columns 287 \param itemWidth Array of the width hints for all items 288 */ 279 Calculate the width of a layout for a given number of 280 columns. 281 282 \param numColumns Given number of columns 283 \param itemWidth Array of the width hints for all items 284 */ 289 285 int QwtDynGridLayout::maxRowWidth( int numColumns ) const 290 286 { 291 287 int col; 292 288 293 QVector< int> colWidth( numColumns );289 QVector< int > colWidth( numColumns ); 294 290 for ( col = 0; col < numColumns; col++ ) 295 291 colWidth[col] = 0; 296 292 297 if ( d_data->isDirty )298 d_data->updateLayoutCache();293 if ( m_data->isDirty ) 294 m_data->updateLayoutCache(); 299 295 300 296 for ( int index = 0; 301 index < d_data->itemSizeHints.count(); index++ )297 index < m_data->itemSizeHints.count(); index++ ) 302 298 { 303 299 col = index % numColumns; 304 300 colWidth[col] = qMax( colWidth[col], 305 d_data->itemSizeHints[int( index )].width() ); 306 } 307 308 int rowWidth = 2 * margin() + ( numColumns - 1 ) * spacing(); 301 m_data->itemSizeHints[index].width() ); 302 } 303 304 const QMargins m = contentsMargins(); 305 306 int rowWidth = m.left() + m.right() + ( numColumns - 1 ) * spacing(); 309 307 for ( col = 0; col < numColumns; col++ ) 310 308 rowWidth += colWidth[col]; … … 314 312 315 313 /*! 316 \return the maximum width of all layout items 317 */ 314 \return the maximum width of all layout items 315 */ 318 316 int QwtDynGridLayout::maxItemWidth() const 319 317 { … … 321 319 return 0; 322 320 323 if ( d_data->isDirty )324 d_data->updateLayoutCache();321 if ( m_data->isDirty ) 322 m_data->updateLayoutCache(); 325 323 326 324 int w = 0; 327 for ( int i = 0; i < d_data->itemSizeHints.count(); i++ )328 { 329 const int itemW = d_data->itemSizeHints[i].width();325 for ( int i = 0; i < m_data->itemSizeHints.count(); i++ ) 326 { 327 const int itemW = m_data->itemSizeHints[i].width(); 330 328 if ( itemW > w ) 331 329 w = itemW; … … 336 334 337 335 /*! 338 Calculate the geometries of the layout items for a layout 339 with numColumns columns and a given rectangle. 340 341 \param rect Rect where to place the items 342 \param numColumns Number of columns 343 \return item geometries 344 */ 345 346 QList< QRect> QwtDynGridLayout::layoutItems( const QRect&rect,336 Calculate the geometries of the layout items for a layout 337 with numColumns columns and a given rectangle. 338 339 \param rect Rect where to place the items 340 \param numColumns Number of columns 341 \return item geometries 342 */ 343 344 QList< QRect > QwtDynGridLayout::layoutItems( const QRect& rect, 347 345 uint numColumns ) const 348 346 { 349 QList< QRect> itemGeometries;347 QList< QRect > itemGeometries; 350 348 if ( numColumns == 0 || isEmpty() ) 351 349 return itemGeometries; … … 358 356 return itemGeometries; 359 357 360 QVector< int> rowHeight( numRows );361 QVector< int> colWidth( numColumns );358 QVector< int > rowHeight( numRows ); 359 QVector< int > colWidth( numColumns ); 362 360 363 361 layoutGrid( numColumns, rowHeight, colWidth ); … … 370 368 stretchGrid( rect, numColumns, rowHeight, colWidth ); 371 369 372 const int maxColumns = d_data->maxColumns;373 d_data->maxColumns = numColumns;370 const int maxColumns = m_data->maxColumns; 371 m_data->maxColumns = numColumns; 374 372 const QRect alignedRect = alignmentRect( rect ); 375 d_data->maxColumns = maxColumns;373 m_data->maxColumns = maxColumns; 376 374 377 375 const int xOffset = expandH ? 0 : alignedRect.x(); 378 376 const int yOffset = expandV ? 0 : alignedRect.y(); 379 377 380 QVector< int> colX( numColumns );381 QVector< int> rowY( numRows );378 QVector< int > colX( numColumns ); 379 QVector< int > rowY( numRows ); 382 380 383 381 const int xySpace = spacing(); 384 382 385 rowY[0] = yOffset + margin(); 383 const QMargins m = contentsMargins(); 384 385 rowY[0] = yOffset + m.top(); 386 386 for ( uint r = 1; r < numRows; r++ ) 387 rowY[r] = rowY[r -1] + rowHeight[r-1] + xySpace;388 389 colX[0] = xOffset + m argin();387 rowY[r] = rowY[r - 1] + rowHeight[r - 1] + xySpace; 388 389 colX[0] = xOffset + m.left(); 390 390 for ( uint c = 1; c < numColumns; c++ ) 391 colX[c] = colX[c-1] + colWidth[c-1] + xySpace; 392 393 const int itemCount = d_data->itemList.size(); 391 colX[c] = colX[c - 1] + colWidth[c - 1] + xySpace; 392 393 const int itemCount = m_data->itemList.size(); 394 itemGeometries.reserve( itemCount ); 395 394 396 for ( int i = 0; i < itemCount; i++ ) 395 397 { … … 397 399 const int col = i % numColumns; 398 400 399 QRect itemGeometry( colX[col], rowY[row], 401 const QRect itemGeometry( colX[col], rowY[row], 400 402 colWidth[col], rowHeight[row] ); 401 403 itemGeometries.append( itemGeometry ); … … 407 409 408 410 /*! 409 Calculate the dimensions for the columns and rows for a grid 410 of numColumns columns. 411 412 \param numColumns Number of columns. 413 \param rowHeight Array where to fill in the calculated row heights. 414 \param colWidth Array where to fill in the calculated column widths. 415 */ 411 Calculate the dimensions for the columns and rows for a grid 412 of numColumns columns. 413 414 \param numColumns Number of columns. 415 \param rowHeight Array where to fill in the calculated row heights. 416 \param colWidth Array where to fill in the calculated column widths. 417 */ 416 418 417 419 void QwtDynGridLayout::layoutGrid( uint numColumns, 418 QVector< int>& rowHeight, QVector<int>& colWidth ) const420 QVector< int >& rowHeight, QVector< int >& colWidth ) const 419 421 { 420 422 if ( numColumns <= 0 ) 421 423 return; 422 424 423 if ( d_data->isDirty )424 d_data->updateLayoutCache();425 426 for ( int index = 0; index < d_data->itemSizeHints.count(); index++ )425 if ( m_data->isDirty ) 426 m_data->updateLayoutCache(); 427 428 for ( int index = 0; index < m_data->itemSizeHints.count(); index++ ) 427 429 { 428 430 const int row = index / numColumns; 429 431 const int col = index % numColumns; 430 432 431 const QSize &size =d_data->itemSizeHints[int( index )];433 const QSize& size = m_data->itemSizeHints[index]; 432 434 433 435 rowHeight[row] = ( col == 0 ) … … 439 441 440 442 /*! 441 \return true: QwtDynGridLayout implements heightForWidth(). 442 \sa heightForWidth() 443 */ 443 \return true: QwtDynGridLayout implements heightForWidth(). 444 \sa heightForWidth() 445 */ 444 446 bool QwtDynGridLayout::hasHeightForWidth() const 445 447 { … … 448 450 449 451 /*! 450 \return The preferred height for this layout, given a width. 451 \sa hasHeightForWidth() 452 */ 452 \return The preferred height for this layout, given a width. 453 \sa hasHeightForWidth() 454 */ 453 455 int QwtDynGridLayout::heightForWidth( int width ) const 454 456 { … … 461 463 numRows++; 462 464 463 QVector< int> rowHeight( numRows );464 QVector< int> colWidth( numColumns );465 QVector< int > rowHeight( numRows ); 466 QVector< int > colWidth( numColumns ); 465 467 466 468 layoutGrid( numColumns, rowHeight, colWidth ); 467 469 468 int h = 2 * margin() + ( numRows - 1 ) * spacing(); 470 const QMargins m = contentsMargins(); 471 472 int h = m.top() + m.bottom() + ( numRows - 1 ) * spacing(); 469 473 for ( uint row = 0; row < numRows; row++ ) 470 474 h += rowHeight[row]; … … 474 478 475 479 /*! 476 Stretch columns in case of expanding() & QSizePolicy::Horizontal and 477 rows in case of expanding() & QSizePolicy::Vertical to fill the entire 478 rect. Rows and columns are stretched with the same factor. 479 480 \param rect Bounding rectangle 481 \param numColumns Number of columns 482 \param rowHeight Array to be filled with the calculated row heights 483 \param colWidth Array to be filled with the calculated column widths 484 485 \sa setExpanding(), expanding() 486 */ 487 void QwtDynGridLayout::stretchGrid( const QRect &rect,488 uint numColumns, QVector< int>& rowHeight, QVector<int>& colWidth ) const480 Stretch columns in case of expanding() & QSizePolicy::Horizontal and 481 rows in case of expanding() & QSizePolicy::Vertical to fill the entire 482 rect. Rows and columns are stretched with the same factor. 483 484 \param rect Bounding rectangle 485 \param numColumns Number of columns 486 \param rowHeight Array to be filled with the calculated row heights 487 \param colWidth Array to be filled with the calculated column widths 488 489 \sa setExpanding(), expanding() 490 */ 491 void QwtDynGridLayout::stretchGrid( const QRect& rect, 492 uint numColumns, QVector< int >& rowHeight, QVector< int >& colWidth ) const 489 493 { 490 494 if ( numColumns == 0 || isEmpty() ) … … 495 499 expandV = expandingDirections() & Qt::Vertical; 496 500 501 const QMargins m = contentsMargins(); 502 497 503 if ( expandH ) 498 504 { 499 int xDelta = rect.width() - 2 * margin() - ( numColumns - 1 ) * spacing();505 int xDelta = rect.width() - m.left() - m.right() - ( numColumns - 1 ) * spacing(); 500 506 for ( uint col = 0; col < numColumns; col++ ) 501 507 xDelta -= colWidth[col]; … … 518 524 numRows++; 519 525 520 int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing();526 int yDelta = rect.height() - m.top() - m.bottom() - ( numRows - 1 ) * spacing(); 521 527 for ( uint row = 0; row < numRows; row++ ) 522 528 yDelta -= rowHeight[row]; … … 541 547 \return Size hint 542 548 \sa maxColumns(), setMaxColumns() 543 */ 549 */ 544 550 QSize QwtDynGridLayout::sizeHint() const 545 551 { … … 548 554 549 555 uint numColumns = itemCount(); 550 if ( d_data->maxColumns > 0 )551 numColumns = qMin( d_data->maxColumns, numColumns );556 if ( m_data->maxColumns > 0 ) 557 numColumns = qMin( m_data->maxColumns, numColumns ); 552 558 553 559 uint numRows = itemCount() / numColumns; … … 555 561 numRows++; 556 562 557 QVector< int> rowHeight( numRows );558 QVector< int> colWidth( numColumns );563 QVector< int > rowHeight( numRows ); 564 QVector< int > colWidth( numColumns ); 559 565 560 566 layoutGrid( numColumns, rowHeight, colWidth ); 561 567 562 int h = 2 * margin() + ( numRows - 1 ) * spacing(); 568 const QMargins m = contentsMargins(); 569 570 int h = m.top() + m.bottom() + ( numRows - 1 ) * spacing(); 563 571 for ( uint row = 0; row < numRows; row++ ) 564 572 h += rowHeight[row]; 565 573 566 int w = 2 * margin() + ( numColumns - 1 ) * spacing();574 int w = m.left() + m.right() + ( numColumns - 1 ) * spacing(); 567 575 for ( uint col = 0; col < numColumns; col++ ) 568 576 w += colWidth[col]; … … 572 580 573 581 /*! 574 \return Number of rows of the current layout. 575 \sa numColumns() 576 \warning The number of rows might change whenever the geometry changes 577 */ 582 \return Number of rows of the current layout. 583 \sa numColumns() 584 \warning The number of rows might change whenever the geometry changes 585 */ 578 586 uint QwtDynGridLayout::numRows() const 579 587 { 580 return d_data->numRows;581 } 582 583 /*! 584 \return Number of columns of the current layout. 585 \sa numRows() 586 \warning The number of columns might change whenever the geometry changes 587 */ 588 return m_data->numRows; 589 } 590 591 /*! 592 \return Number of columns of the current layout. 593 \sa numRows() 594 \warning The number of columns might change whenever the geometry changes 595 */ 588 596 uint QwtDynGridLayout::numColumns() const 589 597 { 590 return d_data->numColumns; 591 } 598 return m_data->numColumns; 599 } 600 601 #include "moc_qwt_dyngrid_layout.cpp" -
trunk/BNC/qwt/qwt_dyngrid_layout.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include <qlayout.h> 15 #include <qsize.h> 16 #include <qlist.h> 15 16 template< typename T > class QList; 17 17 18 18 /*! 19 \brief The QwtDynGridLayout class lays out widgets in a grid, 19 \brief The QwtDynGridLayout class lays out widgets in a grid, 20 20 adjusting the number of columns and rows to the current size. 21 21 22 QwtDynGridLayout takes the space it gets, divides it up into rows and 23 columns, and puts each of the widgets it manages into the correct cell(s). 24 It lays out as many number of columns as possible (limited by maxColumns()). 25 */ 22 QwtDynGridLayout takes the space it gets, divides it up into rows and 23 columns, and puts each of the widgets it manages into the correct cell(s). 24 It lays out as many number of columns as possible (limited by maxColumns()). 25 */ 26 26 27 27 class QWT_EXPORT QwtDynGridLayout : public QLayout 28 28 { 29 29 Q_OBJECT 30 public: 31 explicit QwtDynGridLayout( QWidget *, int margin = 0, int spacing = -1 );30 public: 31 explicit QwtDynGridLayout( QWidget*, int margin = 0, int spacing = -1 ); 32 32 explicit QwtDynGridLayout( int spacing = -1 ); 33 33 34 34 virtual ~QwtDynGridLayout(); 35 35 36 virtual void invalidate(); 36 virtual void invalidate() QWT_OVERRIDE; 37 37 38 38 void setMaxColumns( uint maxColumns ); … … 42 42 uint numColumns () const; 43 43 44 virtual void addItem( QLayoutItem * );44 virtual void addItem( QLayoutItem* ) QWT_OVERRIDE; 45 45 46 virtual QLayoutItem *itemAt( int index ) const;47 virtual QLayoutItem *takeAt( int index );48 virtual int count() const; 46 virtual QLayoutItem* itemAt( int index ) const QWT_OVERRIDE; 47 virtual QLayoutItem* takeAt( int index ) QWT_OVERRIDE; 48 virtual int count() const QWT_OVERRIDE; 49 49 50 50 void setExpandingDirections( Qt::Orientations ); 51 virtual Qt::Orientations expandingDirections() const; 52 QList< QRect> layoutItems( const QRect&, uint numColumns ) const;51 virtual Qt::Orientations expandingDirections() const QWT_OVERRIDE; 52 QList< QRect > layoutItems( const QRect&, uint numColumns ) const; 53 53 54 54 virtual int maxItemWidth() const; 55 55 56 virtual void setGeometry( const QRect &rect );56 virtual void setGeometry( const QRect& ) QWT_OVERRIDE; 57 57 58 virtual bool hasHeightForWidth() const; 59 virtual int heightForWidth( int ) const; 58 virtual bool hasHeightForWidth() const QWT_OVERRIDE; 59 virtual int heightForWidth( int ) const QWT_OVERRIDE; 60 60 61 virtual QSize sizeHint() const; 61 virtual QSize sizeHint() const QWT_OVERRIDE; 62 62 63 virtual bool isEmpty() const; 63 virtual bool isEmpty() const QWT_OVERRIDE; 64 64 uint itemCount() const; 65 65 66 66 virtual uint columnsForWidth( int width ) const; 67 67 68 protected: 68 protected: 69 69 70 70 void layoutGrid( uint numColumns, 71 QVector<int>& rowHeight, QVector<int>& colWidth ) const; 72 void stretchGrid( const QRect &rect, uint numColumns, 73 QVector<int>& rowHeight, QVector<int>& colWidth ) const; 71 QVector< int >& rowHeight, QVector< int >& colWidth ) const; 74 72 75 private: 73 void stretchGrid( const QRect& rect, uint numColumns, 74 QVector< int >& rowHeight, QVector< int >& colWidth ) const; 75 76 private: 76 77 void init(); 77 78 int maxRowWidth( int numColumns ) const; 78 79 79 80 class PrivateData; 80 PrivateData *d_data;81 PrivateData* m_data; 81 82 }; 82 83 -
trunk/BNC/qwt/qwt_event_pattern.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 /*! 14 Constructor 15 16 \sa MousePatternCode, KeyPatternCode 17 */ 18 19 QwtEventPattern::QwtEventPattern() :20 d_mousePattern( MousePatternCount ),21 d_keyPattern( KeyPatternCount )14 Constructor 15 16 \sa MousePatternCode, KeyPatternCode 17 */ 18 19 QwtEventPattern::QwtEventPattern() 20 : m_mousePattern( MousePatternCount ) 21 , m_keyPattern( KeyPatternCount ) 22 22 { 23 23 initKeyPattern(); … … 31 31 32 32 /*! 33 Set default mouse patterns, depending on the number of mouse buttons 34 35 \param numButtons Number of mouse buttons ( <= 3 ) 36 \sa MousePatternCode 37 */ 33 Set default mouse patterns, depending on the number of mouse buttons 34 35 \param numButtons Number of mouse buttons ( <= 3 ) 36 \sa MousePatternCode 37 */ 38 38 void QwtEventPattern::initMousePattern( int numButtons ) 39 39 { 40 d_mousePattern.resize( MousePatternCount );40 m_mousePattern.resize( MousePatternCount ); 41 41 42 42 switch ( numButtons ) … … 60 60 setMousePattern( MouseSelect1, Qt::LeftButton ); 61 61 setMousePattern( MouseSelect2, Qt::RightButton ); 62 setMousePattern( MouseSelect3, Qt::MidButton ); 62 setMousePattern( MouseSelect3, Qt::MiddleButton ); 63 63 } 64 64 } 65 65 66 setMousePattern( MouseSelect4, d_mousePattern[MouseSelect1].button,67 d_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );68 69 setMousePattern( MouseSelect5, d_mousePattern[MouseSelect2].button,70 d_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );71 72 setMousePattern( MouseSelect6, d_mousePattern[MouseSelect3].button,73 d_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );74 } 75 76 /*! 77 Set default mouse patterns. 78 79 \sa KeyPatternCode 80 */ 66 setMousePattern( MouseSelect4, m_mousePattern[MouseSelect1].button, 67 m_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier ); 68 69 setMousePattern( MouseSelect5, m_mousePattern[MouseSelect2].button, 70 m_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier ); 71 72 setMousePattern( MouseSelect6, m_mousePattern[MouseSelect3].button, 73 m_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier ); 74 } 75 76 /*! 77 Set default mouse patterns. 78 79 \sa KeyPatternCode 80 */ 81 81 void QwtEventPattern::initKeyPattern() 82 82 { 83 d_keyPattern.resize( KeyPatternCount );83 m_keyPattern.resize( KeyPatternCount ); 84 84 85 85 setKeyPattern( KeySelect1, Qt::Key_Return ); … … 98 98 99 99 /*! 100 Change one mouse pattern 101 102 \param pattern Index of the pattern 103 \param button Button 104 \param modifiers Keyboard modifiers 105 106 \sa QMouseEvent 107 */ 100 Change one mouse pattern 101 102 \param pattern Index of the pattern 103 \param button Button 104 \param modifiers Keyboard modifiers 105 106 \sa QMouseEvent 107 */ 108 108 void QwtEventPattern::setMousePattern( MousePatternCode pattern, 109 109 Qt::MouseButton button, Qt::KeyboardModifiers modifiers ) … … 111 111 if ( pattern >= 0 && pattern < MousePatternCount ) 112 112 { 113 d_mousePattern[ pattern ].button = button;114 d_mousePattern[ pattern ].modifiers = modifiers;113 m_mousePattern[ pattern ].button = button; 114 m_mousePattern[ pattern ].modifiers = modifiers; 115 115 } 116 116 } 117 117 118 118 /*! 119 Change one key pattern 120 121 \param pattern Index of the pattern 122 \param key Key 123 \param modifiers Keyboard modifiers 124 125 \sa QKeyEvent 126 */ 119 Change one key pattern 120 121 \param pattern Index of the pattern 122 \param key Key 123 \param modifiers Keyboard modifiers 124 125 \sa QKeyEvent 126 */ 127 127 void QwtEventPattern::setKeyPattern( KeyPatternCode pattern, 128 128 int key, Qt::KeyboardModifiers modifiers ) … … 130 130 if ( pattern >= 0 && pattern < KeyPatternCount ) 131 131 { 132 d_keyPattern[ pattern ].key = key;133 d_keyPattern[ pattern ].modifiers = modifiers;132 m_keyPattern[ pattern ].key = key; 133 m_keyPattern[ pattern ].modifiers = modifiers; 134 134 } 135 135 } 136 136 137 137 //! Change the mouse event patterns 138 void QwtEventPattern::setMousePattern( const QVector<MousePattern > &pattern )139 { 140 d_mousePattern = pattern;138 void QwtEventPattern::setMousePattern( const QVector< MousePattern >& pattern ) 139 { 140 m_mousePattern = pattern; 141 141 } 142 142 143 143 //! Change the key event patterns 144 void QwtEventPattern::setKeyPattern( const QVector<KeyPattern > &pattern )145 { 146 d_keyPattern = pattern;144 void QwtEventPattern::setKeyPattern( const QVector< KeyPattern >& pattern ) 145 { 146 m_keyPattern = pattern; 147 147 } 148 148 149 149 //! \return Mouse pattern 150 const QVector<QwtEventPattern::MousePattern >&150 const QVector< QwtEventPattern::MousePattern >& 151 151 QwtEventPattern::mousePattern() const 152 152 { 153 return d_mousePattern;153 return m_mousePattern; 154 154 } 155 155 156 156 //! \return Key pattern 157 const QVector<QwtEventPattern::KeyPattern >&157 const QVector< QwtEventPattern::KeyPattern >& 158 158 QwtEventPattern::keyPattern() const 159 159 { 160 return d_keyPattern;160 return m_keyPattern; 161 161 } 162 162 163 163 //! \return Mouse pattern 164 QVector<QwtEventPattern::MousePattern > &QwtEventPattern::mousePattern()165 { 166 return d_mousePattern;164 QVector< QwtEventPattern::MousePattern >& QwtEventPattern::mousePattern() 165 { 166 return m_mousePattern; 167 167 } 168 168 169 169 //! \return Key pattern 170 QVector<QwtEventPattern::KeyPattern > &QwtEventPattern::keyPattern()171 { 172 return d_keyPattern;173 } 174 175 /*! 176 \brief Compare a mouse event with an event pattern. 177 178 A mouse event matches the pattern when both have the same button 179 value and in the state value the same key flags(Qt::KeyButtonMask) 180 are set. 181 182 \param code Index of the event pattern 183 \param event Mouse event 184 \return true if matches 185 186 \sa keyMatch() 187 */ 170 QVector< QwtEventPattern::KeyPattern >& QwtEventPattern::keyPattern() 171 { 172 return m_keyPattern; 173 } 174 175 /*! 176 \brief Compare a mouse event with an event pattern. 177 178 A mouse event matches the pattern when both have the same button 179 value and in the state value the same key flags(Qt::KeyButtonMask) 180 are set. 181 182 \param code Index of the event pattern 183 \param event Mouse event 184 \return true if matches 185 186 \sa keyMatch() 187 */ 188 188 bool QwtEventPattern::mouseMatch( MousePatternCode code, 189 const QMouseEvent *event ) const189 const QMouseEvent* event ) const 190 190 { 191 191 if ( code >= 0 && code < MousePatternCount ) 192 return mouseMatch( d_mousePattern[ code ], event );192 return mouseMatch( m_mousePattern[ code ], event ); 193 193 194 194 return false; … … 196 196 197 197 /*! 198 \brief Compare a mouse event with an event pattern. 199 200 A mouse event matches the pattern when both have the same button 201 value and in the state value the same key flags(Qt::KeyButtonMask) 202 are set. 203 204 \param pattern Mouse event pattern 205 \param event Mouse event 206 \return true if matches 207 208 \sa keyMatch() 209 */ 210 211 bool QwtEventPattern::mouseMatch( const MousePattern &pattern,212 const QMouseEvent *event ) const198 \brief Compare a mouse event with an event pattern. 199 200 A mouse event matches the pattern when both have the same button 201 value and in the state value the same key flags(Qt::KeyButtonMask) 202 are set. 203 204 \param pattern Mouse event pattern 205 \param event Mouse event 206 \return true if matches 207 208 \sa keyMatch() 209 */ 210 211 bool QwtEventPattern::mouseMatch( const MousePattern& pattern, 212 const QMouseEvent* event ) const 213 213 { 214 214 if ( event == NULL ) … … 220 220 221 221 /*! 222 \brief Compare a key event with an event pattern. 223 224 A key event matches the pattern when both have the same key 225 value and in the state value the same key flags (Qt::KeyButtonMask) 226 are set. 227 228 \param code Index of the event pattern 229 \param event Key event 230 \return true if matches 231 232 \sa mouseMatch() 233 */ 222 \brief Compare a key event with an event pattern. 223 224 A key event matches the pattern when both have the same key 225 value and in the state value the same key flags (Qt::KeyButtonMask) 226 are set. 227 228 \param code Index of the event pattern 229 \param event Key event 230 \return true if matches 231 232 \sa mouseMatch() 233 */ 234 234 bool QwtEventPattern::keyMatch( KeyPatternCode code, 235 const QKeyEvent *event ) const235 const QKeyEvent* event ) const 236 236 { 237 237 if ( code >= 0 && code < KeyPatternCount ) 238 return keyMatch( d_keyPattern[ code ], event );238 return keyMatch( m_keyPattern[ code ], event ); 239 239 240 240 return false; … … 242 242 243 243 /*! 244 \brief Compare a key event with an event pattern. 245 246 A key event matches the pattern when both have the same key 247 value and in the state value the same key flags (Qt::KeyButtonMask) 248 are set. 249 250 \param pattern Key event pattern 251 \param event Key event 252 \return true if matches 253 254 \sa mouseMatch() 255 */ 244 \brief Compare a key event with an event pattern. 245 246 A key event matches the pattern when both have the same key 247 value and in the state value the same key flags (Qt::KeyButtonMask) 248 are set. 249 250 \param pattern Key event pattern 251 \param event Key event 252 \return true if matches 253 254 \sa mouseMatch() 255 */ 256 256 257 257 bool QwtEventPattern::keyMatch( 258 const KeyPattern &pattern, const QKeyEvent*event ) const258 const KeyPattern& pattern, const QKeyEvent* event ) const 259 259 { 260 260 if ( event == NULL ) -
trunk/BNC/qwt/qwt_event_pattern.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_EVENT_PATTERN 11 #define QWT_EVENT_PATTERN 111 #define QWT_EVENT_PATTERN 12 12 13 13 #include "qwt_global.h" 14 14 15 #include <qnamespace.h> 15 16 #include <qvector.h> … … 19 20 20 21 /*! 21 \brief A collection of event patterns 22 23 QwtEventPattern introduces an level of indirection for mouse and 24 keyboard inputs. Those are represented by symbolic names, so 25 the application code can be configured by individual mappings. 26 27 \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer 28 */ 22 \brief A collection of event patterns 23 24 QwtEventPattern introduces an level of indirection for mouse and 25 keyboard inputs. Those are represented by symbolic names, so 26 the application code can be configured by individual mappings. 27 28 \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer 29 */ 29 30 class QWT_EXPORT QwtEventPattern 30 31 { 31 public: 32 public: 32 33 /*! 33 \brief Symbolic mouse input codes 34 35 QwtEventPattern implements 3 different settings for 36 mice with 1, 2, or 3 buttons that can be activated 37 using initMousePattern(). The default setting is for 38 3 button mice. 39 40 Individual settings can be configured using setMousePattern(). 41 42 \sa initMousePattern(), setMousePattern(), setKeyPattern() 43 */ 34 \brief Symbolic mouse input codes 35 36 QwtEventPattern implements 3 different settings for 37 mice with 1, 2, or 3 buttons that can be activated 38 using initMousePattern(). The default setting is for 39 3 button mice. 40 41 Individual settings can be configured using setMousePattern(). 42 43 \sa initMousePattern(), setMousePattern(), setKeyPattern() 44 */ 44 45 enum MousePatternCode 45 46 { 46 47 /*! 47 The default setting for 1, 2 and 3 button mice is: 48 49 - Qt::LeftButton 50 - Qt::LeftButton 51 - Qt::LeftButton 48 The default setting for 1, 2 and 3 button mice is: 49 50 - Qt::LeftButton 51 - Qt::LeftButton 52 - Qt::LeftButton 52 53 */ 53 54 MouseSelect1, 54 55 55 56 /*! 56 The default setting for 1, 2 and 3 button mice is: 57 58 - Qt::LeftButton + Qt::ControlModifier 59 - Qt::RightButton 60 - Qt::RightButton 57 The default setting for 1, 2 and 3 button mice is: 58 59 - Qt::LeftButton + Qt::ControlModifier 60 - Qt::RightButton 61 - Qt::RightButton 61 62 */ 62 63 MouseSelect2, 63 64 64 65 /*! 65 The default setting for 1, 2 and 3 button mice is: 66 67 - Qt::LeftButton + Qt::AltModifier 68 - Qt::LeftButton + Qt::AltModifier 69 - Qt::MidButton 66 The default setting for 1, 2 and 3 button mice is: 67 68 - Qt::LeftButton + Qt::AltModifier 69 - Qt::LeftButton + Qt::AltModifier 70 - Qt::MidButton 70 71 */ 71 72 MouseSelect3, 72 73 73 74 /*! 74 The default setting for 1, 2 and 3 button mice is: 75 76 - Qt::LeftButton + Qt::ShiftModifier 77 - Qt::LeftButton + Qt::ShiftModifier 78 - Qt::LeftButton + Qt::ShiftModifier 75 The default setting for 1, 2 and 3 button mice is: 76 77 - Qt::LeftButton + Qt::ShiftModifier 78 - Qt::LeftButton + Qt::ShiftModifier 79 - Qt::LeftButton + Qt::ShiftModifier 79 80 */ 80 81 MouseSelect4, 81 82 82 83 /*! 83 The default setting for 1, 2 and 3 button mice is: 84 85 - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier 86 - Qt::RightButton + Qt::ShiftModifier 87 - Qt::RightButton + Qt::ShiftModifier 84 The default setting for 1, 2 and 3 button mice is: 85 86 - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier 87 - Qt::RightButton + Qt::ShiftModifier 88 - Qt::RightButton + Qt::ShiftModifier 88 89 */ 89 90 MouseSelect5, 90 91 91 92 /*! 92 The default setting for 1, 2 and 3 button mice is: 93 94 - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier 95 - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier 96 - Qt::MidButton + Qt::ShiftModifier 93 The default setting for 1, 2 and 3 button mice is: 94 95 - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier 96 - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier 97 - Qt::MidButton + Qt::ShiftModifier 97 98 */ 98 99 MouseSelect6, … … 103 104 104 105 /*! 105 \brief Symbolic keyboard input codes 106 107 Individual settings can be configured using setKeyPattern() 108 109 \sa setKeyPattern(), setMousePattern() 110 */ 106 \brief Symbolic keyboard input codes 107 108 Individual settings can be configured using setKeyPattern() 109 110 \sa setKeyPattern(), setMousePattern() 111 */ 111 112 enum KeyPatternCode 112 113 { … … 148 149 class MousePattern 149 150 { 150 public: 151 public: 151 152 //! Constructor 152 153 MousePattern( Qt::MouseButton btn = Qt::NoButton, 153 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):154 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ): 154 155 button( btn ), 155 156 modifiers( modifierCodes ) … … 167 168 class KeyPattern 168 169 { 169 public: 170 public: 170 171 //! Constructor 171 172 KeyPattern( int keyCode = Qt::Key_unknown, 172 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):173 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ): 173 174 key( keyCode ), 174 175 modifiers( modifierCodes ) … … 195 196 Qt::KeyboardModifiers modifiers = Qt::NoModifier ); 196 197 197 void setMousePattern( const QVector<MousePattern >& );198 void setKeyPattern( const QVector<KeyPattern >& );199 200 const QVector<MousePattern > &mousePattern() const;201 const QVector<KeyPattern > &keyPattern() const;202 203 QVector<MousePattern > &mousePattern();204 QVector<KeyPattern > &keyPattern();205 206 bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;207 bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;208 209 protected: 210 virtual bool mouseMatch( const MousePattern &, const QMouseEvent* ) const;211 virtual bool keyMatch( const KeyPattern &, const QKeyEvent* ) const;212 213 private: 214 215 #if defined( _MSC_VER)198 void setMousePattern( const QVector< MousePattern >& ); 199 void setKeyPattern( const QVector< KeyPattern >& ); 200 201 const QVector< MousePattern >& mousePattern() const; 202 const QVector< KeyPattern >& keyPattern() const; 203 204 QVector< MousePattern >& mousePattern(); 205 QVector< KeyPattern >& keyPattern(); 206 207 bool mouseMatch( MousePatternCode, const QMouseEvent* ) const; 208 bool keyMatch( KeyPatternCode, const QKeyEvent* ) const; 209 210 protected: 211 virtual bool mouseMatch( const MousePattern&, const QMouseEvent* ) const; 212 virtual bool keyMatch( const KeyPattern&, const QKeyEvent* ) const; 213 214 private: 215 216 #if defined( _MSC_VER ) 216 217 #pragma warning(push) 217 218 #pragma warning(disable: 4251) 218 219 #endif 219 QVector<MousePattern > d_mousePattern;220 QVector<KeyPattern > d_keyPattern;221 #if defined( _MSC_VER)220 QVector< MousePattern > m_mousePattern; 221 QVector< KeyPattern > m_keyPattern; 222 #if defined( _MSC_VER ) 222 223 #pragma warning(pop) 223 224 #endif … … 226 227 //! Compare operator 227 228 inline bool operator==( QwtEventPattern::MousePattern b1, 228 QwtEventPattern::MousePattern b2 )229 QwtEventPattern::MousePattern b2 ) 229 230 { 230 231 return b1.button == b2.button && b1.modifiers == b2.modifiers; … … 233 234 //! Compare operator 234 235 inline bool operator==( QwtEventPattern::KeyPattern b1, 235 QwtEventPattern::KeyPattern b2 )236 QwtEventPattern::KeyPattern b2 ) 236 237 { 237 238 return b1.key == b2.key && b1.modifiers == b2.modifiers; -
trunk/BNC/qwt/qwt_global.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 // QWT_VERSION is (major << 16) + (minor << 8) + patch. 16 16 17 #define QWT_VERSION 0x060 10618 #define QWT_VERSION_STR "6. 1.6"17 #define QWT_VERSION 0x060300 18 #define QWT_VERSION_STR "6.3.0" 19 19 20 #if defined( _MSC_VER) /* MSVC Compiler */20 #if defined( _MSC_VER ) /* MSVC Compiler */ 21 21 /* template-class specialization 'identifier' is already instantiated */ 22 22 #pragma warning(disable: 4660) … … 27 27 #ifdef QWT_DLL 28 28 29 #if defined(QWT_MAKEDLL) // create a Qwt DLL library 29 #if defined( QWT_MAKEDLL ) // create a Qwt DLL library 30 30 #define QWT_EXPORT Q_DECL_EXPORT 31 31 #else // use a Qwt DLL library … … 39 39 #endif 40 40 41 #define QWT_CONSTEXPR Q_DECL_CONSTEXPR 42 43 #if QT_VERSION >= 0x050000 44 #define QWT_OVERRIDE Q_DECL_OVERRIDE 45 #define QWT_FINAL Q_DECL_FINAL 41 46 #endif 47 48 #ifndef QWT_CONSTEXPR 49 #define QWT_CONSTEXPR 50 #endif 51 52 #ifndef QWT_OVERRIDE 53 #define QWT_OVERRIDE 54 #endif 55 56 #ifndef QWT_FINAL 57 #define QWT_FINAL 58 #endif 59 60 #endif -
trunk/BNC/qwt/qwt_graphic.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_graphic.h" 11 11 #include "qwt_painter_command.h" 12 #include "qwt_math.h" 13 12 14 #include <qvector.h> 13 15 #include <qpainter.h> … … 16 18 #include <qpixmap.h> 17 19 #include <qpainterpath.h> 18 #include <qmath.h> 19 20 static bool qwtHasScalablePen( const QPainter *painter ) 20 21 #if QT_VERSION >= 0x050000 22 23 #include <qguiapplication.h> 24 25 static inline qreal qwtDevicePixelRatio() 26 { 27 return qGuiApp ? qGuiApp->devicePixelRatio() : 1.0; 28 } 29 30 #endif 31 32 static bool qwtHasScalablePen( const QPainter* painter ) 21 33 { 22 34 const QPen pen = painter->pen(); … … 27 39 { 28 40 scalablePen = !pen.isCosmetic(); 41 #if QT_VERSION < 0x050000 29 42 if ( !scalablePen && pen.widthF() == 0.0 ) 30 43 { … … 33 46 scalablePen = true; 34 47 } 48 #endif 35 49 } 36 50 … … 39 53 40 54 static QRectF qwtStrokedPathRect( 41 const QPainter *painter, const QPainterPath&path )55 const QPainter* painter, const QPainterPath& path ) 42 56 { 43 57 QPainterPathStroker stroker; … … 50 64 if ( qwtHasScalablePen( painter ) ) 51 65 { 52 QPainterPath stroke = stroker.createStroke( path);53 rect = painter->transform().map( stroke).boundingRect();66 QPainterPath stroke = stroker.createStroke( path ); 67 rect = painter->transform().map( stroke ).boundingRect(); 54 68 } 55 69 else 56 70 { 57 QPainterPath mappedPath = painter->transform().map( path);71 QPainterPath mappedPath = painter->transform().map( path ); 58 72 mappedPath = stroker.createStroke( mappedPath ); 59 73 … … 65 79 66 80 static inline void qwtExecCommand( 67 QPainter *painter, const QwtPainterCommand&cmd,81 QPainter* painter, const QwtPainterCommand& cmd, 68 82 QwtGraphic::RenderHints renderHints, 69 const QTransform &transform,70 const QTransform *initialTransform )83 const QTransform& transform, 84 const QTransform* initialTransform ) 71 85 { 72 86 switch( cmd.type() ) … … 76 90 bool doMap = false; 77 91 78 if ( renderHints.testFlag( QwtGraphic::RenderPensUnscaled ) 79 && painter->transform().isScaling() ) 92 if ( painter->transform().isScaling() ) 80 93 { 81 94 bool isCosmetic = painter->pen().isCosmetic(); 95 #if QT_VERSION < 0x050000 82 96 if ( isCosmetic && painter->pen().widthF() == 0.0 ) 83 97 { … … 86 100 isCosmetic = false; 87 101 } 88 89 doMap = !isCosmetic; 102 #endif 103 104 if ( isCosmetic ) 105 { 106 // OpenGL2 seems to be buggy for cosmetic pens. 107 // It interpolates curves in too rough steps then 108 109 doMap = painter->paintEngine()->type() == QPaintEngine::OpenGL2; 110 } 111 else 112 { 113 doMap = renderHints.testFlag( QwtGraphic::RenderPensUnscaled ); 114 } 90 115 } 91 116 … … 115 140 case QwtPainterCommand::Pixmap: 116 141 { 117 const QwtPainterCommand::PixmapData *data = cmd.pixmapData();142 const QwtPainterCommand::PixmapData* data = cmd.pixmapData(); 118 143 painter->drawPixmap( data->rect, data->pixmap, data->subRect ); 119 144 break; … … 121 146 case QwtPainterCommand::Image: 122 147 { 123 const QwtPainterCommand::ImageData *data = cmd.imageData();148 const QwtPainterCommand::ImageData* data = cmd.imageData(); 124 149 painter->drawImage( data->rect, data->image, 125 150 data->subRect, data->flags ); … … 128 153 case QwtPainterCommand::State: 129 154 { 130 const QwtPainterCommand::StateData *data = cmd.stateData();155 const QwtPainterCommand::StateData* data = cmd.stateData(); 131 156 132 157 if ( data->flags & QPaintEngine::DirtyPen ) … … 156 181 painter->setClipping( data->isClipEnabled ); 157 182 158 if ( data->flags & QPaintEngine::DirtyClipRegion) 183 if ( data->flags & QPaintEngine::DirtyClipRegion ) 159 184 { 160 185 painter->setClipRegion( data->clipRegion, … … 167 192 } 168 193 169 if ( data->flags & QPaintEngine::DirtyHints) 194 if ( data->flags & QPaintEngine::DirtyHints ) 170 195 { 171 const QPainter::RenderHints hints = data->renderHints; 172 173 painter->setRenderHint( QPainter::Antialiasing, 174 hints.testFlag( QPainter::Antialiasing ) ); 175 176 painter->setRenderHint( QPainter::TextAntialiasing, 177 hints.testFlag( QPainter::TextAntialiasing ) ); 178 179 painter->setRenderHint( QPainter::SmoothPixmapTransform, 180 hints.testFlag( QPainter::SmoothPixmapTransform ) ); 181 182 painter->setRenderHint( QPainter::HighQualityAntialiasing, 183 hints.testFlag( QPainter::HighQualityAntialiasing ) ); 184 185 painter->setRenderHint( QPainter::NonCosmeticDefaultPen, 186 hints.testFlag( QPainter::NonCosmeticDefaultPen ) ); 196 for ( int i = 0; i < 8; i++ ) 197 { 198 const QPainter::RenderHint hint = static_cast< QPainter::RenderHint >( 1 << i ); 199 painter->setRenderHint( hint, data->renderHints.testFlag( hint ) ); 200 } 187 201 } 188 202 189 if ( data->flags & QPaintEngine::DirtyCompositionMode) 203 if ( data->flags & QPaintEngine::DirtyCompositionMode ) 190 204 painter->setCompositionMode( data->compositionMode ); 191 205 192 if ( data->flags & QPaintEngine::DirtyOpacity) 206 if ( data->flags & QPaintEngine::DirtyOpacity ) 193 207 painter->setOpacity( data->opacity ); 194 208 … … 198 212 break; 199 213 } 200 201 214 } 202 215 203 216 class QwtGraphic::PathInfo 204 217 { 205 public: 206 PathInfo() :207 d_scalablePen( false )218 public: 219 PathInfo() 220 : m_scalablePen( false ) 208 221 { 209 222 // QVector needs a default constructor 210 223 } 211 224 212 PathInfo( const QRectF &pointRect, 213 const QRectF &boundingRect, bool scalablePen ): 214 d_pointRect( pointRect ), 215 d_boundingRect( boundingRect ), 216 d_scalablePen( scalablePen ) 217 { 218 } 219 220 inline QRectF scaledBoundingRect( double sx, double sy, 221 bool scalePens ) const 225 PathInfo( const QRectF& pointRect, 226 const QRectF& boundingRect, bool scalablePen ) 227 : m_pointRect( pointRect ) 228 , m_boundingRect( boundingRect ) 229 , m_scalablePen( scalablePen ) 230 { 231 } 232 233 inline QRectF scaledBoundingRect( qreal sx, qreal sy, bool scalePens ) const 222 234 { 223 235 if ( sx == 1.0 && sy == 1.0 ) 224 return d_boundingRect;236 return m_boundingRect; 225 237 226 238 QTransform transform; … … 228 240 229 241 QRectF rect; 230 if ( scalePens && d_scalablePen )231 { 232 rect = transform.mapRect( d_boundingRect );242 if ( scalePens && m_scalablePen ) 243 { 244 rect = transform.mapRect( m_boundingRect ); 233 245 } 234 246 else 235 247 { 236 rect = transform.mapRect( d_pointRect );237 238 const doublel = qAbs(d_pointRect.left() -d_boundingRect.left() );239 const doubler = qAbs(d_pointRect.right() -d_boundingRect.right() );240 const doublet = qAbs(d_pointRect.top() -d_boundingRect.top() );241 const doubleb = qAbs(d_pointRect.bottom() -d_boundingRect.bottom() );248 rect = transform.mapRect( m_pointRect ); 249 250 const qreal l = qAbs( m_pointRect.left() - m_boundingRect.left() ); 251 const qreal r = qAbs( m_pointRect.right() - m_boundingRect.right() ); 252 const qreal t = qAbs( m_pointRect.top() - m_boundingRect.top() ); 253 const qreal b = qAbs( m_pointRect.bottom() - m_boundingRect.bottom() ); 242 254 243 255 rect.adjust( -l, -t, r, b ); … … 248 260 249 261 inline double scaleFactorX( const QRectF& pathRect, 250 const QRectF &targetRect, bool scalePens ) const262 const QRectF& targetRect, bool scalePens ) const 251 263 { 252 264 if ( pathRect.width() <= 0.0 ) 253 265 return 0.0; 254 266 255 const QPointF p0 = d_pointRect.center();256 257 const doublel = qAbs( pathRect.left() - p0.x() );258 const doubler = qAbs( pathRect.right() - p0.x() );259 260 const double w = 2.0 * q Min( l, r )267 const QPointF p0 = m_pointRect.center(); 268 269 const qreal l = qAbs( pathRect.left() - p0.x() ); 270 const qreal r = qAbs( pathRect.right() - p0.x() ); 271 272 const double w = 2.0 * qwtMinF( l, r ) 261 273 * targetRect.width() / pathRect.width(); 262 274 263 275 double sx; 264 if ( scalePens && d_scalablePen )265 { 266 sx = w / d_boundingRect.width();276 if ( scalePens && m_scalablePen ) 277 { 278 sx = w / m_boundingRect.width(); 267 279 } 268 280 else 269 281 { 270 const doublepw = qMax(271 qAbs( d_boundingRect.left() -d_pointRect.left() ),272 qAbs( d_boundingRect.right() -d_pointRect.right() ) );273 274 sx = ( w - 2 * pw ) / d_pointRect.width();282 const qreal pw = qwtMaxF( 283 qAbs( m_boundingRect.left() - m_pointRect.left() ), 284 qAbs( m_boundingRect.right() - m_pointRect.right() ) ); 285 286 sx = ( w - 2 * pw ) / m_pointRect.width(); 275 287 } 276 288 … … 279 291 280 292 inline double scaleFactorY( const QRectF& pathRect, 281 const QRectF &targetRect, bool scalePens ) const293 const QRectF& targetRect, bool scalePens ) const 282 294 { 283 295 if ( pathRect.height() <= 0.0 ) 284 296 return 0.0; 285 297 286 const QPointF p0 = d_pointRect.center();287 288 const doublet = qAbs( pathRect.top() - p0.y() );289 const doubleb = qAbs( pathRect.bottom() - p0.y() );290 291 const doubleh = 2.0 * qMin( t, b )298 const QPointF p0 = m_pointRect.center(); 299 300 const qreal t = qAbs( pathRect.top() - p0.y() ); 301 const qreal b = qAbs( pathRect.bottom() - p0.y() ); 302 303 const qreal h = 2.0 * qwtMinF( t, b ) 292 304 * targetRect.height() / pathRect.height(); 293 305 294 306 double sy; 295 if ( scalePens && d_scalablePen )296 { 297 sy = h / d_boundingRect.height();307 if ( scalePens && m_scalablePen ) 308 { 309 sy = h / m_boundingRect.height(); 298 310 } 299 311 else 300 312 { 301 const double pw =302 q Max( qAbs( d_boundingRect.top() -d_pointRect.top() ),303 qAbs( d_boundingRect.bottom() -d_pointRect.bottom() ) );304 305 sy = ( h - 2 * pw ) / d_pointRect.height();313 const qreal pw = qwtMaxF( 314 qAbs( m_boundingRect.top() - m_pointRect.top() ), 315 qAbs( m_boundingRect.bottom() - m_pointRect.bottom() ) ); 316 317 sy = ( h - 2 * pw ) / m_pointRect.height(); 306 318 } 307 319 … … 309 321 } 310 322 311 private: 312 QRectF d_pointRect;313 QRectF d_boundingRect;314 bool d_scalablePen;323 private: 324 QRectF m_pointRect; 325 QRectF m_boundingRect; 326 bool m_scalablePen; 315 327 }; 316 328 317 329 class QwtGraphic::PrivateData 318 330 { 319 public: 320 PrivateData(): 321 boundingRect( 0.0, 0.0, -1.0, -1.0 ), 322 pointRect( 0.0, 0.0, -1.0, -1.0 ), 323 initialTransform( NULL ) 331 public: 332 PrivateData() 333 : boundingRect( 0.0, 0.0, -1.0, -1.0 ) 334 , pointRect( 0.0, 0.0, -1.0, -1.0 ) 324 335 { 325 336 } 326 337 327 338 QSizeF defaultSize; 328 QVector<QwtPainterCommand> commands; 329 QVector<QwtGraphic::PathInfo> pathInfos; 339 QVector< QwtPainterCommand > commands; 340 QVector< QwtGraphic::PathInfo > pathInfos; 330 341 331 342 QRectF boundingRect; 332 343 QRectF pointRect; 333 344 345 QwtGraphic::CommandTypes commandTypes; 334 346 QwtGraphic::RenderHints renderHints; 335 QTransform *initialTransform;336 347 }; 337 348 338 349 /*! 339 \brief Constructor 340 341 Initializes a null graphic 342 \sa isNull() 343 */ 344 QwtGraphic::QwtGraphic(): 345 QwtNullPaintDevice() 350 \brief Constructor 351 352 Initializes a null graphic 353 \sa isNull() 354 */ 355 QwtGraphic::QwtGraphic() 346 356 { 347 357 setMode( QwtNullPaintDevice::PathMode ); 348 d_data = new PrivateData; 349 } 350 351 /*! 352 \brief Copy constructor 353 354 \param other Source 355 \sa operator=() 356 */ 357 QwtGraphic::QwtGraphic( const QwtGraphic &other ): 358 QwtNullPaintDevice() 358 m_data = new PrivateData; 359 } 360 361 /*! 362 \brief Copy constructor 363 364 \param other Source 365 \sa operator=() 366 */ 367 QwtGraphic::QwtGraphic( const QwtGraphic& other ) 359 368 { 360 369 setMode( other.mode() ); 361 d_data = new PrivateData( *other.d_data );370 m_data = new PrivateData( *other.m_data ); 362 371 } 363 372 … … 365 374 QwtGraphic::~QwtGraphic() 366 375 { 367 delete d_data;368 } 369 370 /*! 371 \brief Assignment operator 372 373 \param other Source 374 \return A reference of this object 375 */ 376 QwtGraphic& QwtGraphic::operator=(const QwtGraphic &other)376 delete m_data; 377 } 378 379 /*! 380 \brief Assignment operator 381 382 \param other Source 383 \return A reference of this object 384 */ 385 QwtGraphic& QwtGraphic::operator=( const QwtGraphic& other ) 377 386 { 378 387 setMode( other.mode() ); 379 * d_data = *other.d_data;388 *m_data = *other.m_data; 380 389 381 390 return *this; … … 383 392 384 393 /*! 385 \brief Clear all stored commands 386 \sa isNull() 394 \brief Clear all stored commands 395 \sa isNull() 387 396 */ 388 397 void QwtGraphic::reset() 389 398 { 390 d_data->commands.clear(); 391 d_data->pathInfos.clear(); 392 393 d_data->boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 ); 394 d_data->pointRect = QRectF( 0.0, 0.0, -1.0, -1.0 ); 395 d_data->defaultSize = QSizeF(); 396 397 } 398 399 /*! 400 \return True, when no painter commands have been stored 401 \sa isEmpty(), commands() 402 */ 399 m_data->commands.clear(); 400 m_data->pathInfos.clear(); 401 402 m_data->commandTypes = CommandTypes(); 403 404 m_data->boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 ); 405 m_data->pointRect = QRectF( 0.0, 0.0, -1.0, -1.0 ); 406 m_data->defaultSize = QSizeF(); 407 } 408 409 /*! 410 \return True, when no painter commands have been stored 411 \sa isEmpty(), commands() 412 */ 403 413 bool QwtGraphic::isNull() const 404 414 { 405 return d_data->commands.isEmpty();406 } 407 408 /*! 409 \return True, when the bounding rectangle is empty 410 \sa boundingRect(), isNull() 411 */ 415 return m_data->commands.isEmpty(); 416 } 417 418 /*! 419 \return True, when the bounding rectangle is empty 420 \sa boundingRect(), isNull() 421 */ 412 422 bool QwtGraphic::isEmpty() const 413 423 { 414 return d_data->boundingRect.isEmpty(); 415 } 416 417 /*! 418 Toggle an render hint 419 420 \param hint Render hint 421 \param on true/false 422 423 \sa testRenderHint(), RenderHint 424 */ 424 return m_data->boundingRect.isEmpty(); 425 } 426 427 /*! 428 \return Types of painter commands being used 429 */ 430 QwtGraphic::CommandTypes QwtGraphic::commandTypes() const 431 { 432 return m_data->commandTypes; 433 } 434 435 /*! 436 Toggle an render hint 437 438 \param hint Render hint 439 \param on true/false 440 441 \sa testRenderHint(), RenderHint 442 */ 425 443 void QwtGraphic::setRenderHint( RenderHint hint, bool on ) 426 444 { 427 445 if ( on ) 428 d_data->renderHints |= hint;446 m_data->renderHints |= hint; 429 447 else 430 d_data->renderHints &= ~hint;431 } 432 433 /*! 434 Test a render hint 435 436 \param hint Render hint 437 \return true/false 438 \sa setRenderHint(), RenderHint 439 */ 448 m_data->renderHints &= ~hint; 449 } 450 451 /*! 452 Test a render hint 453 454 \param hint Render hint 455 \return true/false 456 \sa setRenderHint(), RenderHint 457 */ 440 458 bool QwtGraphic::testRenderHint( RenderHint hint ) const 441 459 { 442 return d_data->renderHints.testFlag( hint ); 443 } 444 445 /*! 446 The bounding rectangle is the controlPointRect() 447 extended by the areas needed for rendering the outlines 448 with unscaled pens. 449 450 \return Bounding rectangle of the graphic 451 \sa controlPointRect(), scaledBoundingRect() 460 return m_data->renderHints.testFlag( hint ); 461 } 462 463 //! \return Render hints 464 QwtGraphic::RenderHints QwtGraphic::renderHints() const 465 { 466 return m_data->renderHints; 467 } 468 469 /*! 470 The bounding rectangle is the controlPointRect() 471 extended by the areas needed for rendering the outlines 472 with unscaled pens. 473 474 \return Bounding rectangle of the graphic 475 \sa controlPointRect(), scaledBoundingRect() 452 476 */ 453 477 QRectF QwtGraphic::boundingRect() const 454 478 { 455 if ( d_data->boundingRect.width() < 0 )479 if ( m_data->boundingRect.width() < 0 ) 456 480 return QRectF(); 457 481 458 return d_data->boundingRect;459 } 460 461 /*! 462 The control point rectangle is the bounding rectangle 463 of all control points of the paths and the target 464 rectangles of the images/pixmaps. 465 466 \return Control point rectangle 467 \sa boundingRect(), scaledBoundingRect() 482 return m_data->boundingRect; 483 } 484 485 /*! 486 The control point rectangle is the bounding rectangle 487 of all control points of the paths and the target 488 rectangles of the images/pixmaps. 489 490 \return Control point rectangle 491 \sa boundingRect(), scaledBoundingRect() 468 492 */ 469 493 QRectF QwtGraphic::controlPointRect() const 470 494 { 471 if ( d_data->pointRect.width() < 0 )495 if ( m_data->pointRect.width() < 0 ) 472 496 return QRectF(); 473 497 474 return d_data->pointRect;475 } 476 477 /*! 478 \brief Calculate the target rectangle for scaling the graphic 479 480 \param sx Horizontal scaling factor 481 \param sy Vertical scaling factor 482 483 \note In case of paths that are painted with a cosmetic pen 498 return m_data->pointRect; 499 } 500 501 /*! 502 \brief Calculate the target rectangle for scaling the graphic 503 504 \param sx Horizontal scaling factor 505 \param sy Vertical scaling factor 506 507 \note In case of paths that are painted with a cosmetic pen 484 508 ( see QPen::isCosmetic() ) the target rectangle is different to 485 509 multiplying the bounding rectangle. 486 510 487 \return Scaled bounding rectangle 488 \sa boundingRect(), controlPointRect() 489 */ 490 QRectF QwtGraphic::scaledBoundingRect( double sx, doublesy ) const511 \return Scaled bounding rectangle 512 \sa boundingRect(), controlPointRect() 513 */ 514 QRectF QwtGraphic::scaledBoundingRect( qreal sx, qreal sy ) const 491 515 { 492 516 if ( sx == 1.0 && sy == 1.0 ) 493 return d_data->boundingRect; 517 return m_data->boundingRect; 518 519 const bool scalePens = !( m_data->renderHints & RenderPensUnscaled ); 494 520 495 521 QTransform transform; 496 522 transform.scale( sx, sy ); 497 523 498 QRectF rect = transform.mapRect( d_data->pointRect ); 499 500 for ( int i = 0; i < d_data->pathInfos.size(); i++ ) 501 { 502 rect |= d_data->pathInfos[i].scaledBoundingRect( sx, sy, 503 !d_data->renderHints.testFlag( RenderPensUnscaled ) ); 504 } 524 QRectF rect = transform.mapRect( m_data->pointRect ); 525 526 for ( int i = 0; i < m_data->pathInfos.size(); i++ ) 527 rect |= m_data->pathInfos[i].scaledBoundingRect( sx, sy, scalePens ); 505 528 506 529 return rect; … … 511 534 { 512 535 const QSizeF sz = defaultSize(); 513 return QSize( qCeil( sz.width() ), qCeil( sz.height() ) ); 514 } 515 516 /*! 517 \brief Set a default size 518 519 The default size is used in all methods rendering the graphic, 520 where no size is explicitly specified. Assigning an empty size 521 means, that the default size will be calculated from the bounding 522 rectangle. 523 524 The default setting is an empty size. 525 526 \param size Default size 527 528 \sa defaultSize(), boundingRect() 529 */ 530 void QwtGraphic::setDefaultSize( const QSizeF &size )531 { 532 const double w = q Max( qreal( 0.0 ), size.width() );533 const double h = q Max( qreal( 0.0 ), size.height() );534 535 d_data->defaultSize = QSizeF( w, h );536 } 537 538 /*! 539 \brief Default size 540 541 When a non empty size has been assigned by setDefaultSize() this 542 size will be returned. Otherwise the default size is the size 543 of the bounding rectangle. 544 545 The default size is used in all methods rendering the graphic, 546 where no size is explicitly specified. 547 548 \return Default size 549 \sa setDefaultSize(), boundingRect() 536 return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) ); 537 } 538 539 /*! 540 \brief Set a default size 541 542 The default size is used in all methods rendering the graphic, 543 where no size is explicitly specified. Assigning an empty size 544 means, that the default size will be calculated from the bounding 545 rectangle. 546 547 The default setting is an empty size. 548 549 \param size Default size 550 551 \sa defaultSize(), boundingRect() 552 */ 553 void QwtGraphic::setDefaultSize( const QSizeF& size ) 554 { 555 const double w = qwtMaxF( 0.0, size.width() ); 556 const double h = qwtMaxF( 0.0, size.height() ); 557 558 m_data->defaultSize = QSizeF( w, h ); 559 } 560 561 /*! 562 \brief Default size 563 564 When a non empty size has been assigned by setDefaultSize() this 565 size will be returned. Otherwise the default size is the size 566 of the bounding rectangle. 567 568 The default size is used in all methods rendering the graphic, 569 where no size is explicitly specified. 570 571 \return Default size 572 \sa setDefaultSize(), boundingRect() 550 573 */ 551 574 QSizeF QwtGraphic::defaultSize() const 552 575 { 553 if ( ! d_data->defaultSize.isEmpty() )554 return d_data->defaultSize;576 if ( !m_data->defaultSize.isEmpty() ) 577 return m_data->defaultSize; 555 578 556 579 return boundingRect().size(); … … 558 581 559 582 /*! 560 \brief Replay all recorded painter commands 561 \param painter Qt painter 562 */ 563 void QwtGraphic::render( QPainter *painter ) const 583 Find the height for a given width 584 585 The height is calculated using the aspect ratio of defaultSize(). 586 587 \param width Width 588 589 \return Calculated height 590 \sa defaultSize() 591 */ 592 qreal QwtGraphic::heightForWidth( qreal width ) const 593 { 594 const QSizeF sz = defaultSize(); 595 if ( sz.isEmpty() ) 596 return 0.0; 597 598 return sz.height() * width / sz.width(); 599 } 600 601 /*! 602 Find the width for a given height 603 604 The width is calculated using the aspect ratio of defaultSize(). 605 606 \param height Height 607 608 \return Calculated width 609 \sa defaultSize() 610 */ 611 qreal QwtGraphic::widthForHeight( qreal height ) const 612 { 613 const QSizeF sz = defaultSize(); 614 if ( sz.isEmpty() ) 615 return 0.0; 616 617 return sz.width() * height / sz.height(); 618 } 619 620 /*! 621 \brief Replay all recorded painter commands 622 \param painter Qt painter 623 */ 624 void QwtGraphic::render( QPainter* painter ) const 625 { 626 renderGraphic( painter, NULL ); 627 } 628 629 void QwtGraphic::renderGraphic( QPainter* painter, QTransform* initialTransform ) const 564 630 { 565 631 if ( isNull() ) 566 632 return; 567 633 568 const int numCommands = d_data->commands.size();569 const QwtPainterCommand *commands =d_data->commands.constData();634 const int numCommands = m_data->commands.size(); 635 const QwtPainterCommand* commands = m_data->commands.constData(); 570 636 571 637 const QTransform transform = painter->transform(); … … 576 642 { 577 643 qwtExecCommand( painter, commands[i], 578 d_data->renderHints, transform,d_data->initialTransform );644 m_data->renderHints, transform, initialTransform ); 579 645 } 580 646 … … 583 649 584 650 /*! 585 \brief Replay all recorded painter commands 586 587 The graphic is scaled to fit into the rectangle 588 of the given size starting at ( 0, 0 ). 589 590 \param painter Qt painter 591 \param size Size for the scaled graphic 592 \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode 593 */ 594 void QwtGraphic::render( QPainter *painter, const QSizeF&size,651 \brief Replay all recorded painter commands 652 653 The graphic is scaled to fit into the rectangle 654 of the given size starting at ( 0, 0 ). 655 656 \param painter Qt painter 657 \param size Size for the scaled graphic 658 \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode 659 */ 660 void QwtGraphic::render( QPainter* painter, const QSizeF& size, 595 661 Qt::AspectRatioMode aspectRatioMode ) const 596 662 { … … 600 666 601 667 /*! 602 \brief Replay all recorded painter commands 603 604 The graphic is scaled to fit into the given rectangle 605 606 \param painter Qt painter 607 \param rect Rectangle for the scaled graphic 608 \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode 609 */ 610 void QwtGraphic::render( QPainter *painter, const QRectF&rect,668 \brief Replay all recorded painter commands 669 670 The graphic is scaled to fit into the given rectangle 671 672 \param painter Qt painter 673 \param rect Rectangle for the scaled graphic 674 \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode 675 */ 676 void QwtGraphic::render( QPainter* painter, const QRectF& rect, 611 677 Qt::AspectRatioMode aspectRatioMode ) const 612 678 { … … 617 683 double sy = 1.0; 618 684 619 if ( d_data->pointRect.width() > 0.0 ) 620 sx = rect.width() / d_data->pointRect.width(); 621 622 if ( d_data->pointRect.height() > 0.0 ) 623 sy = rect.height() / d_data->pointRect.height(); 624 625 const bool scalePens = 626 !d_data->renderHints.testFlag( RenderPensUnscaled ); 627 628 for ( int i = 0; i < d_data->pathInfos.size(); i++ ) 629 { 630 const PathInfo info = d_data->pathInfos[i]; 685 if ( m_data->pointRect.width() > 0.0 ) 686 sx = rect.width() / m_data->pointRect.width(); 687 688 if ( m_data->pointRect.height() > 0.0 ) 689 sy = rect.height() / m_data->pointRect.height(); 690 691 const bool scalePens = !m_data->renderHints.testFlag( RenderPensUnscaled ); 692 693 for ( int i = 0; i < m_data->pathInfos.size(); i++ ) 694 { 695 const PathInfo& info = m_data->pathInfos[i]; 631 696 632 697 const double ssx = info.scaleFactorX( 633 d_data->pointRect, rect, scalePens );698 m_data->pointRect, rect, scalePens ); 634 699 635 700 if ( ssx > 0.0 ) 636 sx = q Min( sx, ssx );701 sx = qwtMinF( sx, ssx ); 637 702 638 703 const double ssy = info.scaleFactorY( 639 d_data->pointRect, rect, scalePens );704 m_data->pointRect, rect, scalePens ); 640 705 641 706 if ( ssy > 0.0 ) 642 sy = q Min( sy, ssy );707 sy = qwtMinF( sy, ssy ); 643 708 } 644 709 645 710 if ( aspectRatioMode == Qt::KeepAspectRatio ) 646 711 { 647 const double s = qMin( sx, sy );712 const qreal s = qwtMinF( sx, sy ); 648 713 sx = s; 649 714 sy = s; … … 651 716 else if ( aspectRatioMode == Qt::KeepAspectRatioByExpanding ) 652 717 { 653 const double s = qMax( sx, sy );718 const qreal s = qwtMaxF( sx, sy ); 654 719 sx = s; 655 720 sy = s; … … 657 722 658 723 QTransform tr; 659 tr.translate( rect.center().x() - 0.5 * sx * d_data->pointRect.width(),660 rect.center().y() - 0.5 * sy * d_data->pointRect.height() );724 tr.translate( rect.center().x() - 0.5 * sx * m_data->pointRect.width(), 725 rect.center().y() - 0.5 * sy * m_data->pointRect.height() ); 661 726 tr.scale( sx, sy ); 662 tr.translate( - d_data->pointRect.x(), -d_data->pointRect.y() );727 tr.translate( -m_data->pointRect.x(), -m_data->pointRect.y() ); 663 728 664 729 const QTransform transform = painter->transform(); 730 731 painter->setTransform( tr, true ); 732 665 733 if ( !scalePens && transform.isScaling() ) 666 734 { … … 669 737 // painter transformation later 670 738 671 d_data->initialTransform = new QTransform(); 672 d_data->initialTransform->scale( transform.m11(), transform.m22() ); 673 } 674 675 painter->setTransform( tr, true ); 676 render( painter ); 739 QTransform initialTransform; 740 initialTransform.scale( transform.m11(), transform.m22() ); 741 742 renderGraphic( painter, &initialTransform ); 743 } 744 else 745 { 746 renderGraphic( painter, NULL ); 747 } 677 748 678 749 painter->setTransform( transform ); 679 680 delete d_data->initialTransform; 681 d_data->initialTransform = NULL; 682 } 683 684 /*! 685 \brief Replay all recorded painter commands 686 687 The graphic is scaled to the defaultSize() and aligned 688 to a position. 689 690 \param painter Qt painter 691 \param pos Reference point, where to render 692 \param alignment Flags how to align the target rectangle 693 to pos. 694 */ 695 void QwtGraphic::render( QPainter *painter, 696 const QPointF &pos, Qt::Alignment alignment ) const 750 } 751 752 /*! 753 \brief Replay all recorded painter commands 754 755 The graphic is scaled to the defaultSize() and aligned 756 to a position. 757 758 \param painter Qt painter 759 \param pos Reference point, where to render 760 \param alignment Flags how to align the target rectangle to pos. 761 */ 762 void QwtGraphic::render( QPainter* painter, 763 const QPointF& pos, Qt::Alignment alignment ) const 697 764 { 698 765 QRectF r( pos, defaultSize() ); … … 728 795 729 796 /*! 730 \brief Convert the graphic to a QPixmap 731 732 All pixels of the pixmap get initialized by Qt::transparent 733 before the graphic is scaled and rendered on it. 734 735 The size of the pixmap is the default size ( ceiled to integers ) 736 of the graphic. 737 738 \return The graphic as pixmap in default size 739 \sa defaultSize(), toImage(), render() 740 */ 741 QPixmap QwtGraphic::toPixmap() const 797 \brief Convert the graphic to a QPixmap 798 799 All pixels of the pixmap get initialized by Qt::transparent 800 before the graphic is scaled and rendered on it. 801 802 The size of the pixmap is the default size ( ceiled to integers ) 803 of the graphic. 804 805 \param devicePixelRatio Device pixel ratio for the pixmap. 806 If devicePixelRatio <= 0.0 the pixmap 807 is initialized with the system default. 808 809 \return The graphic as pixmap in default size 810 \sa defaultSize(), toImage(), render() 811 */ 812 QPixmap QwtGraphic::toPixmap( qreal devicePixelRatio ) const 742 813 { 743 814 if ( isNull() ) … … 746 817 const QSizeF sz = defaultSize(); 747 818 748 const int w = qCeil( sz.width() ); 749 const int h = qCeil( sz.height() ); 819 #if QT_VERSION >= 0x050000 820 if ( devicePixelRatio <= 0.0 ) 821 devicePixelRatio = qwtDevicePixelRatio(); 822 823 const int w = qwtCeil( sz.width() * devicePixelRatio ); 824 const int h = qwtCeil( sz.height() * devicePixelRatio ); 750 825 751 826 QPixmap pixmap( w, h ); 827 pixmap.setDevicePixelRatio( devicePixelRatio ); 828 #else 829 Q_UNUSED( devicePixelRatio ) 830 831 const int w = qwtCeil( sz.width() ); 832 const int h = qwtCeil( sz.height() ); 833 834 QPixmap pixmap( w, h ); 835 #endif 836 752 837 pixmap.fill( Qt::transparent ); 753 838 … … 762 847 763 848 /*! 764 \brief Convert the graphic to a QPixmap 765 766 All pixels of the pixmap get initialized by Qt::transparent 767 before the graphic is scaled and rendered on it. 768 769 \param size Size of the image 770 \param aspectRatioMode Aspect ratio how to scale the graphic 771 772 \return The graphic as pixmap 773 \sa toImage(), render() 774 */ 775 QPixmap QwtGraphic::toPixmap( const QSize &size, 776 Qt::AspectRatioMode aspectRatioMode ) const 777 { 849 \brief Convert the graphic to a QPixmap 850 851 All pixels of the pixmap get initialized by Qt::transparent 852 before the graphic is scaled and rendered on it. 853 854 \param size Size of the image 855 \param aspectRatioMode Aspect ratio how to scale the graphic 856 \param devicePixelRatio Device pixel ratio for the pixmap. 857 If devicePixelRatio <= 0.0 the pixmap 858 is initialized with the system default. 859 860 \return The graphic as pixmap 861 \sa toImage(), render() 862 */ 863 QPixmap QwtGraphic::toPixmap( const QSize& size, 864 Qt::AspectRatioMode aspectRatioMode, qreal devicePixelRatio ) const 865 { 866 #if QT_VERSION >= 0x050000 867 if ( devicePixelRatio <= 0.0 ) 868 devicePixelRatio = qwtDevicePixelRatio(); 869 870 const int w = qwtCeil( size.width() * devicePixelRatio ); 871 const int h = qwtCeil( size.height() * devicePixelRatio ); 872 873 QPixmap pixmap( w, h ); 874 pixmap.setDevicePixelRatio( devicePixelRatio ); 875 #else 876 Q_UNUSED( devicePixelRatio ) 778 877 QPixmap pixmap( size ); 878 #endif 779 879 pixmap.fill( Qt::transparent ); 780 880 … … 789 889 790 890 /*! 791 \brief Convert the graphic to a QImage 792 793 All pixels of the image get initialized by 0 ( transparent ) 794 before the graphic is scaled and rendered on it. 795 796 The format of the image is QImage::Format_ARGB32_Premultiplied. 797 798 \param size Size of the image 799 \param aspectRatioMode Aspect ratio how to scale the graphic 800 801 \return The graphic as image 802 \sa toPixmap(), render() 803 */ 804 QImage QwtGraphic::toImage( const QSize &size, 805 Qt::AspectRatioMode aspectRatioMode ) const 806 { 891 \brief Convert the graphic to a QImage 892 893 All pixels of the image get initialized by 0 ( transparent ) 894 before the graphic is scaled and rendered on it. 895 896 The format of the image is QImage::Format_ARGB32_Premultiplied. 897 898 \param size Size of the image ( will be multiplied by the devicePixelRatio ) 899 \param aspectRatioMode Aspect ratio how to scale the graphic 900 \param devicePixelRatio Device pixel ratio for the image. 901 If devicePixelRatio <= 0.0 the pixmap 902 is initialized with the system default. 903 904 \return The graphic as image 905 \sa toPixmap(), render() 906 */ 907 QImage QwtGraphic::toImage( const QSize& size, 908 Qt::AspectRatioMode aspectRatioMode, qreal devicePixelRatio ) const 909 { 910 #if QT_VERSION >= 0x050000 911 if ( devicePixelRatio <= 0.0 ) 912 devicePixelRatio = qwtDevicePixelRatio(); 913 914 const int w = qwtCeil( size.width() * devicePixelRatio ); 915 const int h = qwtCeil( size.height() * devicePixelRatio ); 916 917 QImage image( w, h, QImage::Format_ARGB32_Premultiplied ); 918 image.setDevicePixelRatio( devicePixelRatio ); 919 #else 920 Q_UNUSED( devicePixelRatio ) 807 921 QImage image( size, QImage::Format_ARGB32_Premultiplied ); 922 #endif 923 808 924 image.fill( 0 ); 809 925 … … 818 934 819 935 /*! 820 \brief Convert the graphic to a QImage 821 822 All pixels of the image get initialized by 0 ( transparent ) 823 before the graphic is scaled and rendered on it. 824 825 The format of the image is QImage::Format_ARGB32_Premultiplied. 826 827 The size of the image is the default size ( ceiled to integers ) 828 of the graphic. 829 830 \return The graphic as image in default size 831 \sa defaultSize(), toPixmap(), render() 832 */ 833 QImage QwtGraphic::toImage() const 936 \brief Convert the graphic to a QImage 937 938 All pixels of the image get initialized by 0 ( transparent ) 939 before the graphic is scaled and rendered on it. 940 941 The format of the image is QImage::Format_ARGB32_Premultiplied. 942 943 The size of the image is the default size ( ceiled to integers ) 944 of the graphic multiplied by the devicePixelRatio. 945 946 \param devicePixelRatio Device pixel ratio for the image. 947 If devicePixelRatio <= 0.0 the pixmap 948 is initialized with the system default. 949 950 \return The graphic as image in default size 951 \sa defaultSize(), toPixmap(), render() 952 */ 953 QImage QwtGraphic::toImage( qreal devicePixelRatio ) const 834 954 { 835 955 if ( isNull() ) … … 838 958 const QSizeF sz = defaultSize(); 839 959 840 const int w = qCeil( sz.width() ); 841 const int h = qCeil( sz.height() ); 960 #if QT_VERSION >= 0x050000 961 if ( devicePixelRatio <= 0.0 ) 962 devicePixelRatio = qwtDevicePixelRatio(); 963 964 const int w = qwtCeil( sz.width() * devicePixelRatio ); 965 const int h = qwtCeil( sz.height() * devicePixelRatio ); 842 966 843 967 QImage image( w, h, QImage::Format_ARGB32 ); 968 image.setDevicePixelRatio( devicePixelRatio ); 969 #else 970 Q_UNUSED( devicePixelRatio ) 971 972 const int w = qwtCeil( sz.width() ); 973 const int h = qwtCeil( sz.height() ); 974 975 QImage image( w, h, QImage::Format_ARGB32 ); 976 #endif 977 844 978 image.fill( 0 ); 845 979 … … 854 988 855 989 /*! 856 Store a path command in the command list 857 858 \param path Painter path 859 \sa QPaintEngine::drawPath() 860 */ 861 void QwtGraphic::drawPath( const QPainterPath &path )862 { 863 const QPainter *painter = paintEngine()->painter();990 Store a path command in the command list 991 992 \param path Painter path 993 \sa QPaintEngine::drawPath() 994 */ 995 void QwtGraphic::drawPath( const QPainterPath& path ) 996 { 997 const QPainter* painter = paintEngine()->painter(); 864 998 if ( painter == NULL ) 865 999 return; 866 1000 867 d_data->commands += QwtPainterCommand( path ); 1001 m_data->commands += QwtPainterCommand( path ); 1002 m_data->commandTypes |= QwtGraphic::VectorData; 868 1003 869 1004 if ( !path.isEmpty() ) … … 883 1018 updateBoundingRect( boundingRect ); 884 1019 885 d_data->pathInfos += PathInfo( pointRect,1020 m_data->pathInfos += PathInfo( pointRect, 886 1021 boundingRect, qwtHasScalablePen( painter ) ); 887 1022 } … … 889 1024 890 1025 /*! 891 \brief Store a pixmap command in the command list 892 893 \param rect target rectangle 894 \param pixmap Pixmap to be painted 895 \param subRect Reactangle of the pixmap to be painted 896 897 \sa QPaintEngine::drawPixmap() 898 */ 899 void QwtGraphic::drawPixmap( const QRectF &rect,900 const QPixmap &pixmap, const QRectF&subRect )901 { 902 const QPainter *painter = paintEngine()->painter();1026 \brief Store a pixmap command in the command list 1027 1028 \param rect target rectangle 1029 \param pixmap Pixmap to be painted 1030 \param subRect Reactangle of the pixmap to be painted 1031 1032 \sa QPaintEngine::drawPixmap() 1033 */ 1034 void QwtGraphic::drawPixmap( const QRectF& rect, 1035 const QPixmap& pixmap, const QRectF& subRect ) 1036 { 1037 const QPainter* painter = paintEngine()->painter(); 903 1038 if ( painter == NULL ) 904 1039 return; 905 1040 906 d_data->commands += QwtPainterCommand( rect, pixmap, subRect ); 1041 m_data->commands += QwtPainterCommand( rect, pixmap, subRect ); 1042 m_data->commandTypes |= QwtGraphic::RasterData; 907 1043 908 1044 const QRectF r = painter->transform().mapRect( rect ); … … 912 1048 913 1049 /*! 914 \brief Store a image command in the command list 915 916 \param rect t raget rectangle917 \param image Image to be painted 918 \param subRect Reactangle of the pixmap to be painted 919 \param flags Image conversion flags 920 921 \sa QPaintEngine::drawImage() 922 */ 923 void QwtGraphic::drawImage( const QRectF &rect, const QImage&image,924 const QRectF &subRect, Qt::ImageConversionFlags flags)925 { 926 const QPainter *painter = paintEngine()->painter();1050 \brief Store a image command in the command list 1051 1052 \param rect target rectangle 1053 \param image Image to be painted 1054 \param subRect Reactangle of the pixmap to be painted 1055 \param flags Image conversion flags 1056 1057 \sa QPaintEngine::drawImage() 1058 */ 1059 void QwtGraphic::drawImage( const QRectF& rect, const QImage& image, 1060 const QRectF& subRect, Qt::ImageConversionFlags flags ) 1061 { 1062 const QPainter* painter = paintEngine()->painter(); 927 1063 if ( painter == NULL ) 928 1064 return; 929 1065 930 d_data->commands += QwtPainterCommand( rect, image, subRect, flags ); 1066 m_data->commands += QwtPainterCommand( rect, image, subRect, flags ); 1067 m_data->commandTypes |= QwtGraphic::RasterData; 931 1068 932 1069 const QRectF r = painter->transform().mapRect( rect ); … … 937 1074 938 1075 /*! 939 \brief Store a state command in the command list 940 941 \param state State to be stored 942 \sa QPaintEngine::updateState() 943 */ 944 void QwtGraphic::updateState( const QPaintEngineState &state) 945 { 946 d_data->commands += QwtPainterCommand( state ); 947 } 948 949 void QwtGraphic::updateBoundingRect( const QRectF &rect ) 1076 \brief Store a state command in the command list 1077 1078 \param state State to be stored 1079 \sa QPaintEngine::updateState() 1080 */ 1081 void QwtGraphic::updateState( const QPaintEngineState& state ) 1082 { 1083 m_data->commands += QwtPainterCommand( state ); 1084 1085 if ( state.state() & QPaintEngine::DirtyTransform ) 1086 { 1087 if ( !( m_data->commandTypes & QwtGraphic::Transformation ) ) 1088 { 1089 /* 1090 QTransform::isScaling() returns true for all type 1091 of transformations beside simple translations 1092 even if it is f.e a rotation 1093 */ 1094 if ( state.transform().isScaling() ) 1095 m_data->commandTypes |= QwtGraphic::Transformation; 1096 } 1097 } 1098 } 1099 1100 void QwtGraphic::updateBoundingRect( const QRectF& rect ) 950 1101 { 951 1102 QRectF br = rect; 952 1103 953 const QPainter *painter = paintEngine()->painter();1104 const QPainter* painter = paintEngine()->painter(); 954 1105 if ( painter && painter->hasClipping() ) 955 1106 { … … 960 1111 } 961 1112 962 if ( d_data->boundingRect.width() < 0 )963 d_data->boundingRect = br;1113 if ( m_data->boundingRect.width() < 0 ) 1114 m_data->boundingRect = br; 964 1115 else 965 d_data->boundingRect |= br;966 } 967 968 void QwtGraphic::updateControlPointRect( const QRectF &rect )969 { 970 if ( d_data->pointRect.width() < 0.0 )971 d_data->pointRect = rect;1116 m_data->boundingRect |= br; 1117 } 1118 1119 void QwtGraphic::updateControlPointRect( const QRectF& rect ) 1120 { 1121 if ( m_data->pointRect.width() < 0.0 ) 1122 m_data->pointRect = rect; 972 1123 else 973 d_data->pointRect |= rect;974 } 975 976 /*! 977 \return List of recorded paint commands 978 \sa setCommands() 979 */ 980 const QVector< QwtPainterCommand > &QwtGraphic::commands() const981 { 982 return d_data->commands;983 } 984 985 /*! 986 \brief Append paint commands 987 988 \param commands Paint commands 989 \sa commands() 990 */ 991 void QwtGraphic::setCommands( QVector< QwtPainterCommand > &commands )1124 m_data->pointRect |= rect; 1125 } 1126 1127 /*! 1128 \return List of recorded paint commands 1129 \sa setCommands() 1130 */ 1131 const QVector< QwtPainterCommand >& QwtGraphic::commands() const 1132 { 1133 return m_data->commands; 1134 } 1135 1136 /*! 1137 \brief Append paint commands 1138 1139 \param commands Paint commands 1140 \sa commands() 1141 */ 1142 void QwtGraphic::setCommands( const QVector< QwtPainterCommand >& commands ) 992 1143 { 993 1144 reset(); … … 1000 1151 // the commands. 1001 1152 1002 const QwtPainterCommand *cmds = commands.constData(); 1153 const QwtPainterCommand* cmds = commands.constData(); 1154 1155 const QTransform noTransform; 1156 const RenderHints noRenderHints; 1003 1157 1004 1158 QPainter painter( this ); 1005 1159 for ( int i = 0; i < numCommands; i++ ) 1006 qwtExecCommand( &painter, cmds[i], RenderHints (), QTransform(), NULL );1160 qwtExecCommand( &painter, cmds[i], noRenderHints, noTransform, NULL ); 1007 1161 1008 1162 painter.end(); -
trunk/BNC/qwt/qwt_graphic.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_null_paintdevice.h" 15 15 16 #include <qmetatype.h> 16 #include <qimage.h>17 #include <qpixmap.h>18 17 19 18 class QwtPainterCommand; 19 class QPixmap; 20 class QImage; 20 21 21 22 /*! … … 72 73 \sa QwtPainterCommand 73 74 */ 74 class QWT_EXPORT QwtGraphic: public QwtNullPaintDevice 75 class QWT_EXPORT QwtGraphic : public QwtNullPaintDevice 75 76 { 76 public: 77 public: 77 78 /*! 78 79 Hint how to render a graphic … … 96 97 }; 97 98 99 Q_DECLARE_FLAGS( RenderHints, RenderHint ) 100 98 101 /*! 99 \brief Render hints 100 101 The default setting is to disable all hints 102 Indicator if the graphic contains a specific type of painter command 103 \sa CommandTypes, commandTypes(); 102 104 */ 103 typedef QFlags<RenderHint> RenderHints; 105 enum CommandType 106 { 107 //! The graphic contains scalable vector data 108 VectorData = 1 << 0, 109 110 //! The graphic contains raster data ( QPixmap or QImage ) 111 RasterData = 1 << 1, 112 113 //! The graphic contains transformations beyond simple translations 114 Transformation = 1 << 2 115 }; 116 117 Q_DECLARE_FLAGS( CommandTypes, CommandType ) 104 118 105 119 QwtGraphic(); 106 QwtGraphic( const QwtGraphic & );120 QwtGraphic( const QwtGraphic& ); 107 121 108 122 virtual ~QwtGraphic(); 109 123 110 QwtGraphic& operator=( const QwtGraphic & );124 QwtGraphic& operator=( const QwtGraphic& ); 111 125 112 126 void reset(); … … 115 129 bool isEmpty() const; 116 130 117 void render( QPainter * ) const; 118 119 void render( QPainter *, const QSizeF &, 120 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const; 121 122 void render( QPainter *, const QRectF &, 123 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const; 124 125 void render( QPainter *, const QPointF &, 131 CommandTypes commandTypes() const; 132 133 void render( QPainter* ) const; 134 135 void render( QPainter*, const QSizeF&, 136 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const; 137 138 void render( QPainter*, const QPointF&, 126 139 Qt::Alignment = Qt::AlignTop | Qt::AlignLeft ) const; 127 140 128 QPixmap toPixmap() const; 129 QPixmap toPixmap( const QSize &, 130 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const; 131 132 QImage toImage() const; 133 QImage toImage( const QSize &, 134 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const; 135 136 QRectF scaledBoundingRect( double sx, double sy ) const; 141 void render( QPainter*, const QRectF&, 142 Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const; 143 144 QPixmap toPixmap( qreal devicePixelRatio = 0.0 ) const; 145 146 QPixmap toPixmap( const QSize&, 147 Qt::AspectRatioMode = Qt::IgnoreAspectRatio, 148 qreal devicePixelRatio = 0.0 ) const; 149 150 QImage toImage( qreal devicePixelRatio = 0.0 ) const; 151 152 QImage toImage( const QSize&, 153 Qt::AspectRatioMode = Qt::IgnoreAspectRatio, 154 qreal devicePixelRatio = 0.0 ) const; 155 156 QRectF scaledBoundingRect( qreal sx, qreal sy ) const; 137 157 138 158 QRectF boundingRect() const; 139 159 QRectF controlPointRect() const; 140 160 141 const QVector< QwtPainterCommand > &commands() const;142 void setCommands( QVector< QwtPainterCommand > & );143 144 void setDefaultSize( const QSizeF & );161 const QVector< QwtPainterCommand >& commands() const; 162 void setCommands( const QVector< QwtPainterCommand >& ); 163 164 void setDefaultSize( const QSizeF& ); 145 165 QSizeF defaultSize() const; 166 167 qreal heightForWidth( qreal width ) const; 168 qreal widthForHeight( qreal height ) const; 146 169 147 170 void setRenderHint( RenderHint, bool on = true ); 148 171 bool testRenderHint( RenderHint ) const; 149 172 150 protected: 151 virtual QSize sizeMetrics() const; 152 153 virtual void drawPath( const QPainterPath & ); 154 155 virtual void drawPixmap( const QRectF &, 156 const QPixmap &, const QRectF & ); 157 158 virtual void drawImage( const QRectF &, 159 const QImage &, const QRectF &, Qt::ImageConversionFlags ); 160 161 virtual void updateState( const QPaintEngineState &state ); 162 163 private: 164 void updateBoundingRect( const QRectF & ); 165 void updateControlPointRect( const QRectF & ); 173 RenderHints renderHints() const; 174 175 protected: 176 virtual QSize sizeMetrics() const QWT_OVERRIDE; 177 178 virtual void drawPath( const QPainterPath& ) QWT_OVERRIDE; 179 180 virtual void drawPixmap( const QRectF&, 181 const QPixmap&, const QRectF& ) QWT_OVERRIDE; 182 183 virtual void drawImage( const QRectF&, const QImage&, 184 const QRectF&, Qt::ImageConversionFlags ) QWT_OVERRIDE; 185 186 virtual void updateState( const QPaintEngineState& ) QWT_OVERRIDE; 187 188 private: 189 void renderGraphic( QPainter*, QTransform* ) const; 190 191 void updateBoundingRect( const QRectF& ); 192 void updateControlPointRect( const QRectF& ); 166 193 167 194 class PathInfo; 168 195 169 196 class PrivateData; 170 PrivateData *d_data;197 PrivateData* m_data; 171 198 }; 172 199 173 200 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtGraphic::RenderHints ) 201 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtGraphic::CommandTypes ) 174 202 Q_DECLARE_METATYPE( QwtGraphic ) 175 203 -
trunk/BNC/qwt/qwt_interval.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_interval.h" 11 #include "qwt_math.h" 12 #include <qalgorithms.h> 13 14 /*! 15 \brief Normalize the limits of the interval 16 17 If maxValue() < minValue() the limits will be inverted. 18 \return Normalized interval 19 20 \sa isValid(), inverted() 21 */ 11 12 namespace 13 { 14 static const struct RegisterQwtInterval 15 { 16 inline RegisterQwtInterval() { qRegisterMetaType< QwtInterval >(); } 17 18 } qwtRegisterQwtInterval; 19 } 20 21 /*! 22 \brief Normalize the limits of the interval 23 24 If maxValue() < minValue() the limits will be inverted. 25 \return Normalized interval 26 27 \sa isValid(), inverted() 28 */ 22 29 QwtInterval QwtInterval::normalized() const 23 30 { 24 if ( d_minValue >d_maxValue )31 if ( m_minValue > m_maxValue ) 25 32 { 26 33 return inverted(); 27 34 } 28 if ( d_minValue ==d_maxValue &&d_borderFlags == ExcludeMinimum )35 if ( m_minValue == m_maxValue && m_borderFlags == ExcludeMinimum ) 29 36 { 30 37 return inverted(); … … 35 42 36 43 /*! 37 Invert the limits of the interval 38 \return Inverted interval 39 \sa normalized() 40 */ 44 Invert the limits of the interval 45 \return Inverted interval 46 \sa normalized() 47 */ 41 48 QwtInterval QwtInterval::inverted() const 42 49 { 43 50 BorderFlags borderFlags = IncludeBorders; 44 if ( d_borderFlags & ExcludeMinimum ) 51 52 if ( m_borderFlags & ExcludeMinimum ) 45 53 borderFlags |= ExcludeMaximum; 46 if ( d_borderFlags & ExcludeMaximum ) 54 55 if ( m_borderFlags & ExcludeMaximum ) 47 56 borderFlags |= ExcludeMinimum; 48 57 49 return QwtInterval( d_maxValue,d_minValue, borderFlags );50 } 51 52 /*! 53 Test if a value is inside an interval 54 55 \param value Value 56 \return true, if value >= minValue() && value <= maxValue()57 */ 58 return QwtInterval( m_maxValue, m_minValue, borderFlags ); 59 } 60 61 /*! 62 Test if a value is inside an interval 63 64 \param value Value 65 \return true, if value lies inside the boundaries 66 */ 58 67 bool QwtInterval::contains( double value ) const 59 68 { … … 61 70 return false; 62 71 63 if ( value < d_minValue||value >d_maxValue )64 return false; 65 66 if ( value == d_minValue&& d_borderFlags & ExcludeMinimum )67 return false; 68 69 if ( value == d_maxValue&& d_borderFlags & ExcludeMaximum )72 if ( ( value < m_minValue ) || ( value > m_maxValue ) ) 73 return false; 74 75 if ( ( value == m_minValue ) && ( m_borderFlags & ExcludeMinimum ) ) 76 return false; 77 78 if ( ( value == m_maxValue ) && ( m_borderFlags & ExcludeMaximum ) ) 70 79 return false; 71 80 … … 73 82 } 74 83 84 /*! 85 Test if an interval is inside an interval 86 87 \param interval Interval 88 \return true, if interval lies inside the boundaries 89 */ 90 bool QwtInterval::contains( const QwtInterval& interval ) const 91 { 92 if ( !isValid() || !interval.isValid() ) 93 return false; 94 95 if ( ( interval.m_minValue < m_minValue ) || ( interval.m_maxValue > m_maxValue ) ) 96 return false; 97 98 if ( m_borderFlags ) 99 { 100 if ( interval.m_minValue == m_minValue ) 101 { 102 if ( ( m_borderFlags & ExcludeMinimum ) 103 && !( interval.m_borderFlags & ExcludeMinimum ) ) 104 { 105 return false; 106 } 107 } 108 109 if ( interval.m_maxValue == m_maxValue ) 110 { 111 if ( ( m_borderFlags & ExcludeMaximum ) 112 && !( interval.m_borderFlags & ExcludeMaximum ) ) 113 { 114 return false; 115 } 116 } 117 } 118 119 return true; 120 } 121 75 122 //! Unite 2 intervals 76 QwtInterval QwtInterval::unite( const QwtInterval &other ) const123 QwtInterval QwtInterval::unite( const QwtInterval& other ) const 77 124 { 78 125 /* 79 If one of the intervals is invalid return the other one. 80 If both are invalid return an invalid default interval 126 If one of the intervals is invalid return the other one. 127 If both are invalid return an invalid default interval 81 128 */ 82 129 if ( !isValid() ) … … 94 141 95 142 // minimum 96 if ( d_minValue < other.minValue() )97 { 98 united.setMinValue( d_minValue );99 flags &= d_borderFlags & ExcludeMinimum;100 } 101 else if ( other.minValue() < d_minValue )143 if ( m_minValue < other.minValue() ) 144 { 145 united.setMinValue( m_minValue ); 146 flags &= m_borderFlags & ExcludeMinimum; 147 } 148 else if ( other.minValue() < m_minValue ) 102 149 { 103 150 united.setMinValue( other.minValue() ); 104 151 flags &= other.borderFlags() & ExcludeMinimum; 105 152 } 106 else // d_minValue == other.minValue()107 { 108 united.setMinValue( d_minValue );109 flags &= ( d_borderFlags & other.borderFlags() ) & ExcludeMinimum;153 else // m_minValue == other.minValue() 154 { 155 united.setMinValue( m_minValue ); 156 flags &= ( m_borderFlags & other.borderFlags() ) & ExcludeMinimum; 110 157 } 111 158 112 159 // maximum 113 if ( d_maxValue > other.maxValue() )114 { 115 united.setMaxValue( d_maxValue );116 flags &= d_borderFlags & ExcludeMaximum;117 } 118 else if ( other.maxValue() > d_maxValue )160 if ( m_maxValue > other.maxValue() ) 161 { 162 united.setMaxValue( m_maxValue ); 163 flags &= m_borderFlags & ExcludeMaximum; 164 } 165 else if ( other.maxValue() > m_maxValue ) 119 166 { 120 167 united.setMaxValue( other.maxValue() ); 121 168 flags &= other.borderFlags() & ExcludeMaximum; 122 169 } 123 else // d_maxValue == other.maxValue() )124 { 125 united.setMaxValue( d_maxValue );126 flags &= d_borderFlags & other.borderFlags() & ExcludeMaximum;170 else // m_maxValue == other.maxValue() ) 171 { 172 united.setMaxValue( m_maxValue ); 173 flags &= m_borderFlags & other.borderFlags() & ExcludeMaximum; 127 174 } 128 175 … … 132 179 133 180 /*! 134 \brief Intersect 2 intervals 135 136 \param other Interval to be intersect with 137 \return Intersection 138 */ 139 QwtInterval QwtInterval::intersect( const QwtInterval &other ) const181 \brief Intersect 2 intervals 182 183 \param other Interval to be intersect with 184 \return Intersection 185 */ 186 QwtInterval QwtInterval::intersect( const QwtInterval& other ) const 140 187 { 141 188 if ( !other.isValid() || !isValid() ) … … 199 246 200 247 /*! 201 \brief Unite this interval with the given interval. 202 203 \param other Interval to be united with 204 \return This interval 205 */ 206 QwtInterval& QwtInterval::operator|=( const QwtInterval &other )248 \brief Unite this interval with the given interval. 249 250 \param other Interval to be united with 251 \return This interval 252 */ 253 QwtInterval& QwtInterval::operator|=( const QwtInterval& other ) 207 254 { 208 255 *this = *this | other; … … 211 258 212 259 /*! 213 \brief Intersect this interval with the given interval. 214 215 \param other Interval to be intersected with 216 \return This interval 217 */ 218 QwtInterval& QwtInterval::operator&=( const QwtInterval &other )260 \brief Intersect this interval with the given interval. 261 262 \param other Interval to be intersected with 263 \return This interval 264 */ 265 QwtInterval& QwtInterval::operator&=( const QwtInterval& other ) 219 266 { 220 267 *this = *this & other; … … 223 270 224 271 /*! 225 \brief Test if two intervals overlap 226 227 \param other Interval 228 \return True, when the intervals are intersecting 229 */ 230 bool QwtInterval::intersects( const QwtInterval &other ) const272 \brief Test if two intervals overlap 273 274 \param other Interval 275 \return True, when the intervals are intersecting 276 */ 277 bool QwtInterval::intersects( const QwtInterval& other ) const 231 278 { 232 279 if ( !isValid() || !other.isValid() ) … … 244 291 } 245 292 else if ( i1.minValue() == i2.minValue() && 246 i1.borderFlags() & ExcludeMinimum )293 i1.borderFlags() & ExcludeMinimum ) 247 294 { 248 295 qSwap( i1, i2 ); … … 256 303 { 257 304 return !( ( i1.borderFlags() & ExcludeMaximum ) || 258 ( i2.borderFlags() & ExcludeMinimum ) ); 305 ( i2.borderFlags() & ExcludeMinimum ) ); 259 306 } 260 307 return false; … … 262 309 263 310 /*! 264 Adjust the limit that is closer to value, so that value becomes 265 the center of the interval. 266 267 \param value Center 268 \return Interval with value as center 269 */ 311 Adjust the limit that is closer to value, so that value becomes 312 the center of the interval. 313 314 \param value Center 315 \return Interval with value as center 316 */ 270 317 QwtInterval QwtInterval::symmetrize( double value ) const 271 318 { … … 274 321 275 322 const double delta = 276 qMax( qAbs( value - d_maxValue ), qAbs( value -d_minValue ) );323 qMax( qAbs( value - m_maxValue ), qAbs( value - m_minValue ) ); 277 324 278 325 return QwtInterval( value - delta, value + delta ); … … 280 327 281 328 /*! 282 Limit the interval, keeping the border modes 283 284 \param lowerBound Lower limit 285 \param upperBound Upper limit 286 287 \return Limited interval 288 */ 329 Limit the interval, keeping the border modes 330 331 \param lowerBound Lower limit 332 \param upperBound Upper limit 333 334 \return Limited interval 335 */ 289 336 QwtInterval QwtInterval::limited( double lowerBound, double upperBound ) const 290 337 { … … 292 339 return QwtInterval(); 293 340 294 double minValue = qMax( d_minValue, lowerBound );341 double minValue = qMax( m_minValue, lowerBound ); 295 342 minValue = qMin( minValue, upperBound ); 296 343 297 double maxValue = qMax( d_maxValue, lowerBound );344 double maxValue = qMax( m_maxValue, lowerBound ); 298 345 maxValue = qMin( maxValue, upperBound ); 299 346 300 return QwtInterval( minValue, maxValue, d_borderFlags );301 } 302 303 /*! 304 \brief Extend the interval 305 306 If value is below minValue(), value becomes the lower limit. 307 If value is above maxValue(), value becomes the upper limit. 308 309 extend() has no effect for invalid intervals 310 311 \param value Value 312 \return extended interval 313 314 \sa isValid() 315 */ 347 return QwtInterval( minValue, maxValue, m_borderFlags ); 348 } 349 350 /*! 351 \brief Extend the interval 352 353 If value is below minValue(), value becomes the lower limit. 354 If value is above maxValue(), value becomes the upper limit. 355 356 extend() has no effect for invalid intervals 357 358 \param value Value 359 \return extended interval 360 361 \sa isValid() 362 */ 316 363 QwtInterval QwtInterval::extend( double value ) const 317 364 { … … 319 366 return *this; 320 367 321 return QwtInterval( qMin( value, d_minValue ),322 qMax( value, d_maxValue ),d_borderFlags );323 } 324 325 /*! 326 Extend an interval 327 328 \param value Value 329 \return Reference of the extended interval 330 331 \sa extend() 332 */ 368 return QwtInterval( qMin( value, m_minValue ), 369 qMax( value, m_maxValue ), m_borderFlags ); 370 } 371 372 /*! 373 Extend an interval 374 375 \param value Value 376 \return Reference of the extended interval 377 378 \sa extend() 379 */ 333 380 QwtInterval& QwtInterval::operator|=( double value ) 334 381 { … … 339 386 #ifndef QT_NO_DEBUG_STREAM 340 387 341 QDebug operator<<( QDebug debug, const QwtInterval &interval ) 388 #include <qdebug.h> 389 390 QDebug operator<<( QDebug debug, const QwtInterval& interval ) 342 391 { 343 392 const int flags = interval.borderFlags(); 344 393 345 394 debug.nospace() << "QwtInterval(" 346 << ( ( flags & QwtInterval::ExcludeMinimum ) ? "]" : "[" )347 << interval.minValue() << "," << interval.maxValue() 348 << ( ( flags & QwtInterval::ExcludeMaximum ) ? "[" : "]" )349 << ")"; 395 << ( ( flags& QwtInterval::ExcludeMinimum ) ? "]" : "[" ) 396 << interval.minValue() << "," << interval.maxValue() 397 << ( ( flags& QwtInterval::ExcludeMaximum ) ? "[" : "]" ) 398 << ")"; 350 399 351 400 return debug.space(); -
trunk/BNC/qwt/qwt_interval.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 14 14 #include <qmetatype.h> 15 15 16 #ifndef QT_NO_DEBUG_STREAM 17 #include <qdebug.h> 18 #endif 19 20 /*! 21 \brief A class representing an interval 22 23 The interval is represented by 2 doubles, the lower and the upper limit. 24 */ 16 /*! 17 \brief A class representing an interval 18 19 The interval is represented by 2 doubles, the lower and the upper limit. 20 */ 25 21 26 22 class QWT_EXPORT QwtInterval 27 23 { 28 public: 24 public: 29 25 /*! 30 Flag indicating if a border is included or excluded 31 \sa setBorderFlags(), borderFlags() 32 */ 26 Flag indicating if a border is included or excluded 27 \sa setBorderFlags(), borderFlags() 28 */ 33 29 enum BorderFlag 34 30 { … … 47 43 48 44 //! Border flags 49 typedef QFlags<BorderFlag>BorderFlags;45 Q_DECLARE_FLAGS( BorderFlags, BorderFlag ) 50 46 51 47 QwtInterval(); … … 60 56 QwtInterval limited( double lowerBound, double upperBound ) const; 61 57 62 bool operator==( const QwtInterval & ) const;63 bool operator!=( const QwtInterval & ) const;58 bool operator==( const QwtInterval& ) const; 59 bool operator!=( const QwtInterval& ) const; 64 60 65 61 void setBorderFlags( BorderFlags ); … … 70 66 71 67 double width() const; 68 long double widthL() const; 72 69 73 70 void setMinValue( double ); … … 75 72 76 73 bool contains( double value ) const; 77 78 bool intersects( const QwtInterval & ) const; 79 QwtInterval intersect( const QwtInterval & ) const; 80 QwtInterval unite( const QwtInterval & ) const; 81 82 QwtInterval operator|( const QwtInterval & ) const; 83 QwtInterval operator&( const QwtInterval & ) const; 84 85 QwtInterval &operator|=( const QwtInterval & ); 86 QwtInterval &operator&=( const QwtInterval & ); 74 bool contains( const QwtInterval& ) const; 75 76 bool intersects( const QwtInterval& ) const; 77 QwtInterval intersect( const QwtInterval& ) const; 78 QwtInterval unite( const QwtInterval& ) const; 79 80 QwtInterval operator|( const QwtInterval& ) const; 81 QwtInterval operator&( const QwtInterval& ) const; 82 83 QwtInterval& operator|=( const QwtInterval& ); 84 QwtInterval& operator&=( const QwtInterval& ); 87 85 88 86 QwtInterval extend( double value ) const; 89 87 QwtInterval operator|( double ) const; 90 QwtInterval &operator|=( double );88 QwtInterval& operator|=( double ); 91 89 92 90 bool isValid() const; … … 96 94 QwtInterval symmetrize( double value ) const; 97 95 98 private: 99 double d_minValue;100 double d_maxValue;101 BorderFlags d_borderFlags;96 private: 97 double m_minValue; 98 double m_maxValue; 99 BorderFlags m_borderFlags; 102 100 }; 103 101 104 Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE); 105 106 /*! 107 \brief Default Constructor 108 109 Creates an invalid interval [0.0, -1.0] 110 \sa setInterval(), isValid() 111 */ 112 inline QwtInterval::QwtInterval(): 113 d_minValue( 0.0 ), 114 d_maxValue( -1.0 ), 115 d_borderFlags( IncludeBorders ) 102 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags ) 103 Q_DECLARE_METATYPE( QwtInterval ) 104 Q_DECLARE_TYPEINFO( QwtInterval, Q_MOVABLE_TYPE ); 105 106 /*! 107 \brief Default Constructor 108 109 Creates an invalid interval [0.0, -1.0] 110 \sa setInterval(), isValid() 111 */ 112 inline QwtInterval::QwtInterval() 113 : m_minValue( 0.0 ) 114 , m_maxValue( -1.0 ) 115 , m_borderFlags( IncludeBorders ) 116 116 { 117 117 } … … 125 125 \param maxValue Maximum value 126 126 \param borderFlags Include/Exclude borders 127 */ 127 */ 128 128 inline QwtInterval::QwtInterval( 129 double minValue, double maxValue, BorderFlags borderFlags ) :130 d_minValue( minValue ),131 d_maxValue( maxValue ),132 d_borderFlags( borderFlags )129 double minValue, double maxValue, BorderFlags borderFlags ) 130 : m_minValue( minValue ) 131 , m_maxValue( maxValue ) 132 , m_borderFlags( borderFlags ) 133 133 { 134 134 } … … 140 140 \param maxValue Maximum value 141 141 \param borderFlags Include/Exclude borders 142 */ 142 */ 143 143 inline void QwtInterval::setInterval( 144 144 double minValue, double maxValue, BorderFlags borderFlags ) 145 145 { 146 d_minValue = minValue;147 d_maxValue = maxValue;148 d_borderFlags = borderFlags;146 m_minValue = minValue; 147 m_maxValue = maxValue; 148 m_borderFlags = borderFlags; 149 149 } 150 150 … … 154 154 \param borderFlags Or'd BorderMode flags 155 155 \sa borderFlags() 156 */ 156 */ 157 157 inline void QwtInterval::setBorderFlags( BorderFlags borderFlags ) 158 158 { 159 d_borderFlags = borderFlags;159 m_borderFlags = borderFlags; 160 160 } 161 161 … … 163 163 \return Border flags 164 164 \sa setBorderFlags() 165 */ 165 */ 166 166 inline QwtInterval::BorderFlags QwtInterval::borderFlags() const 167 167 { 168 return d_borderFlags;168 return m_borderFlags; 169 169 } 170 170 … … 173 173 174 174 \param minValue Minimum value 175 */ 175 */ 176 176 inline void QwtInterval::setMinValue( double minValue ) 177 177 { 178 d_minValue = minValue;178 m_minValue = minValue; 179 179 } 180 180 … … 183 183 184 184 \param maxValue Maximum value 185 */ 185 */ 186 186 inline void QwtInterval::setMaxValue( double maxValue ) 187 187 { 188 d_maxValue = maxValue;188 m_maxValue = maxValue; 189 189 } 190 190 … … 192 192 inline double QwtInterval::minValue() const 193 193 { 194 return d_minValue;194 return m_minValue; 195 195 } 196 196 … … 198 198 inline double QwtInterval::maxValue() const 199 199 { 200 return d_maxValue;200 return m_maxValue; 201 201 } 202 202 … … 207 207 208 208 \return True, when the interval is valid 209 */ 209 */ 210 210 inline bool QwtInterval::isValid() const 211 211 { 212 if ( ( d_borderFlags & ExcludeBorders ) == 0 )213 return d_minValue <=d_maxValue;212 if ( ( m_borderFlags & ExcludeBorders ) == 0 ) 213 return m_minValue <= m_maxValue; 214 214 else 215 return d_minValue <d_maxValue;215 return m_minValue < m_maxValue; 216 216 } 217 217 … … 224 224 \return Interval width 225 225 \sa isValid() 226 */ 226 */ 227 227 inline double QwtInterval::width() const 228 228 { 229 return isValid() ? ( d_maxValue - d_minValue ) : 0.0; 229 return isValid() ? ( m_maxValue - m_minValue ) : 0.0; 230 } 231 232 /*! 233 \brief Return the width of an interval as long double 234 235 The width of invalid intervals is 0.0, otherwise the result is 236 maxValue() - minValue(). 237 238 \return Interval width 239 \sa isValid() 240 */ 241 inline long double QwtInterval::widthL() const 242 { 243 if ( !isValid() ) 244 return 0.0; 245 246 return static_cast< long double >( m_maxValue ) 247 - static_cast< long double >( m_minValue ); 230 248 } 231 249 … … 237 255 238 256 \sa intersect() 239 */ 257 */ 240 258 inline QwtInterval QwtInterval::operator&( 241 const QwtInterval &other ) const259 const QwtInterval& other ) const 242 260 { 243 261 return intersect( other ); … … 251 269 252 270 \sa unite() 253 */ 271 */ 254 272 inline QwtInterval QwtInterval::operator|( 255 const QwtInterval &other ) const273 const QwtInterval& other ) const 256 274 { 257 275 return unite( other ); … … 263 281 \param other Interval to compare with 264 282 \return True, when this and other are equal 265 */ 266 inline bool QwtInterval::operator==( const QwtInterval &other ) const267 { 268 return ( d_minValue == other.d_minValue ) &&269 ( d_maxValue == other.d_maxValue ) &&270 ( d_borderFlags == other.d_borderFlags );283 */ 284 inline bool QwtInterval::operator==( const QwtInterval& other ) const 285 { 286 return ( m_minValue == other.m_minValue ) && 287 ( m_maxValue == other.m_maxValue ) && 288 ( m_borderFlags == other.m_borderFlags ); 271 289 } 272 290 /*! … … 275 293 \param other Interval to compare with 276 294 \return True, when this and other are not equal 277 */ 278 inline bool QwtInterval::operator!=( const QwtInterval &other ) const295 */ 296 inline bool QwtInterval::operator!=( const QwtInterval& other ) const 279 297 { 280 298 return ( !( *this == other ) ); … … 287 305 \return Extended interval 288 306 \sa extend() 289 */ 307 */ 290 308 inline QwtInterval QwtInterval::operator|( double value ) const 291 309 { … … 296 314 inline bool QwtInterval::isNull() const 297 315 { 298 return isValid() && d_minValue >=d_maxValue;299 } 300 301 /*! 302 Invalidate the interval 303 304 The limits are set to interval [0.0, -1.0] 305 \sa isValid() 306 */ 316 return isValid() && m_minValue >= m_maxValue; 317 } 318 319 /*! 320 Invalidate the interval 321 322 The limits are set to interval [0.0, -1.0] 323 \sa isValid() 324 */ 307 325 inline void QwtInterval::invalidate() 308 326 { 309 d_minValue = 0.0; 310 d_maxValue = -1.0; 311 } 312 313 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags ) 314 Q_DECLARE_METATYPE( QwtInterval ) 327 m_minValue = 0.0; 328 m_maxValue = -1.0; 329 } 315 330 316 331 #ifndef QT_NO_DEBUG_STREAM 317 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );332 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval& ); 318 333 #endif 319 334 -
trunk/BNC/qwt/qwt_interval_symbol.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_painter.h" 12 12 #include "qwt_math.h" 13 13 14 #include <qpainter.h> 14 15 #if QT_VERSION < 0x040601 16 #define qAtan2(y, x) ::atan2(y, x) 17 #define qFastSin(x) qSin(x) 18 #define qFastCos(x) qCos(x) 19 #endif 15 #include <qmath.h> 20 16 21 17 class QwtIntervalSymbol::PrivateData 22 18 { 23 public: 24 PrivateData() :25 style( QwtIntervalSymbol::NoSymbol ) ,26 width( 6 ) 19 public: 20 PrivateData() 21 : style( QwtIntervalSymbol::NoSymbol ) 22 , width( 6 ) 27 23 { 28 24 } 29 25 30 bool operator==( const PrivateData &other ) const26 bool operator==( const PrivateData& other ) const 31 27 { 32 28 return ( style == other.style ) 33 && ( width == other.width ) 34 && ( brush == other.brush ) 35 && ( pen == other.pen ); 29 && ( width == other.width ) 30 && ( brush == other.brush ) 31 && ( pen == other.pen ); 36 32 } 37 33 … … 44 40 45 41 /*! 46 Constructor 47 48 \param style Style of the symbol 49 \sa setStyle(), style(), Style 50 */ 42 Constructor 43 44 \param style Style of the symbol 45 \sa setStyle(), style(), Style 46 */ 51 47 QwtIntervalSymbol::QwtIntervalSymbol( Style style ) 52 48 { 53 d_data = new PrivateData();54 d_data->style = style;49 m_data = new PrivateData(); 50 m_data->style = style; 55 51 } 56 52 57 53 //! Copy constructor 58 QwtIntervalSymbol::QwtIntervalSymbol( const QwtIntervalSymbol &other )59 { 60 d_data = new PrivateData();61 * d_data = *other.d_data;54 QwtIntervalSymbol::QwtIntervalSymbol( const QwtIntervalSymbol& other ) 55 { 56 m_data = new PrivateData(); 57 *m_data = *other.m_data; 62 58 } 63 59 … … 65 61 QwtIntervalSymbol::~QwtIntervalSymbol() 66 62 { 67 delete d_data;63 delete m_data; 68 64 } 69 65 70 66 //! \brief Assignment operator 71 QwtIntervalSymbol &QwtIntervalSymbol::operator=(72 const QwtIntervalSymbol &other )73 { 74 * d_data = *other.d_data;67 QwtIntervalSymbol& QwtIntervalSymbol::operator=( 68 const QwtIntervalSymbol& other ) 69 { 70 *m_data = *other.m_data; 75 71 return *this; 76 72 } … … 78 74 //! \brief Compare two symbols 79 75 bool QwtIntervalSymbol::operator==( 80 const QwtIntervalSymbol &other ) const81 { 82 return * d_data == *other.d_data;76 const QwtIntervalSymbol& other ) const 77 { 78 return *m_data == *other.m_data; 83 79 } 84 80 85 81 //! \brief Compare two symbols 86 82 bool QwtIntervalSymbol::operator!=( 87 const QwtIntervalSymbol &other ) const88 { 89 return !( * d_data == *other.d_data );90 } 91 92 /*! 93 Specify the symbol style 94 95 \param style Style 96 \sa style(), Style 97 */ 83 const QwtIntervalSymbol& other ) const 84 { 85 return !( *m_data == *other.m_data ); 86 } 87 88 /*! 89 Specify the symbol style 90 91 \param style Style 92 \sa style(), Style 93 */ 98 94 void QwtIntervalSymbol::setStyle( Style style ) 99 95 { 100 d_data->style = style;101 } 102 103 /*! 104 \return Current symbol style 105 \sa setStyle() 106 */ 96 m_data->style = style; 97 } 98 99 /*! 100 \return Current symbol style 101 \sa setStyle() 102 */ 107 103 QwtIntervalSymbol::Style QwtIntervalSymbol::style() const 108 104 { 109 return d_data->style;110 } 111 112 /*! 113 Specify the width of the symbol 114 It is used depending on the style. 115 116 \param width Width 117 \sa width(), setStyle() 118 */ 105 return m_data->style; 106 } 107 108 /*! 109 Specify the width of the symbol 110 It is used depending on the style. 111 112 \param width Width 113 \sa width(), setStyle() 114 */ 119 115 void QwtIntervalSymbol::setWidth( int width ) 120 116 { 121 d_data->width = width;122 } 123 124 /*! 125 \return Width of the symbol. 126 \sa setWidth(), setStyle() 127 */ 117 m_data->width = width; 118 } 119 120 /*! 121 \return Width of the symbol. 122 \sa setWidth(), setStyle() 123 */ 128 124 int QwtIntervalSymbol::width() const 129 125 { 130 return d_data->width;131 } 132 133 /*! 134 \brief Assign a brush 135 136 The brush is used for the Box style. 137 138 \param brush Brush 139 \sa brush() 140 */ 141 void QwtIntervalSymbol::setBrush( const QBrush &brush )142 { 143 d_data->brush = brush;144 } 145 146 /*! 147 \return Brush 148 \sa setBrush() 149 */ 126 return m_data->width; 127 } 128 129 /*! 130 \brief Assign a brush 131 132 The brush is used for the Box style. 133 134 \param brush Brush 135 \sa brush() 136 */ 137 void QwtIntervalSymbol::setBrush( const QBrush& brush ) 138 { 139 m_data->brush = brush; 140 } 141 142 /*! 143 \return Brush 144 \sa setBrush() 145 */ 150 146 const QBrush& QwtIntervalSymbol::brush() const 151 147 { 152 return d_data->brush;153 } 154 155 /*! 156 Build and assign a pen 157 158 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 159 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 160 to hide this incompatibility. 161 162 \param color Pen color 163 \param width Pen width 164 \param style Pen style 165 166 \sa pen(), brush() 167 */ 168 void QwtIntervalSymbol::setPen( const QColor &color,148 return m_data->brush; 149 } 150 151 /*! 152 Build and assign a pen 153 154 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 155 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 156 to hide this incompatibility. 157 158 \param color Pen color 159 \param width Pen width 160 \param style Pen style 161 162 \sa pen(), brush() 163 */ 164 void QwtIntervalSymbol::setPen( const QColor& color, 169 165 qreal width, Qt::PenStyle style ) 170 166 { … … 173 169 174 170 /*! 175 Assign a pen 176 177 \param pen Pen 178 \sa pen(), setBrush() 179 */ 180 void QwtIntervalSymbol::setPen( const QPen &pen )181 { 182 d_data->pen = pen;183 } 184 185 /*! 186 \return Pen 187 \sa setPen(), brush() 188 */ 171 Assign a pen 172 173 \param pen Pen 174 \sa pen(), setBrush() 175 */ 176 void QwtIntervalSymbol::setPen( const QPen& pen ) 177 { 178 m_data->pen = pen; 179 } 180 181 /*! 182 \return Pen 183 \sa setPen(), brush() 184 */ 189 185 const QPen& QwtIntervalSymbol::pen() const 190 186 { 191 return d_data->pen;192 } 193 194 /*! 195 Draw a symbol depending on its style 196 197 \param painter Painter 198 \param orientation Orientation 199 \param from Start point of the interval in target device coordinates 200 \param to End point of the interval in target device coordinates 201 202 \sa setStyle() 203 */ 204 void QwtIntervalSymbol::draw( QPainter *painter, Qt::Orientation orientation,205 const QPointF &from, const QPointF&to ) const206 { 207 const qreal pw = qMax( painter->pen().widthF(), qreal( 1.0) );187 return m_data->pen; 188 } 189 190 /*! 191 Draw a symbol depending on its style 192 193 \param painter Painter 194 \param orientation Orientation 195 \param from Start point of the interval in target device coordinates 196 \param to End point of the interval in target device coordinates 197 198 \sa setStyle() 199 */ 200 void QwtIntervalSymbol::draw( QPainter* painter, Qt::Orientation orientation, 201 const QPointF& from, const QPointF& to ) const 202 { 203 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); 208 204 209 205 QPointF p1 = from; … … 215 211 } 216 212 217 switch ( d_data->style )213 switch ( m_data->style ) 218 214 { 219 215 case QwtIntervalSymbol::Bar: 220 216 { 221 217 QwtPainter::drawLine( painter, p1, p2 ); 222 if ( d_data->width > pw )218 if ( m_data->width > pw ) 223 219 { 224 220 if ( ( orientation == Qt::Horizontal ) 225 221 && ( p1.y() == p2.y() ) ) 226 222 { 227 const double sw = d_data->width;223 const double sw = m_data->width; 228 224 229 225 const double y = p1.y() - sw / 2; … … 236 232 && ( p1.x() == p2.x() ) ) 237 233 { 238 const double sw = d_data->width;234 const double sw = m_data->width; 239 235 240 236 const double x = p1.x() - sw / 2; … … 246 242 else 247 243 { 248 const double sw = d_data->width;244 const double sw = m_data->width; 249 245 250 246 const double dx = p2.x() - p1.x(); 251 247 const double dy = p2.y() - p1.y(); 252 const double angle = qAtan2( dy, dx ) + M_PI_2;248 const double angle = std::atan2( dy, dx ) + M_PI_2; 253 249 double dw2 = sw / 2.0; 254 250 … … 268 264 case QwtIntervalSymbol::Box: 269 265 { 270 if ( d_data->width <= pw )266 if ( m_data->width <= pw ) 271 267 { 272 268 QwtPainter::drawLine( painter, p1, p2 ); … … 277 273 && ( p1.y() == p2.y() ) ) 278 274 { 279 const double sw = d_data->width;280 281 const double y = p1.y() - d_data->width / 2;275 const double sw = m_data->width; 276 277 const double y = p1.y() - m_data->width / 2; 282 278 QwtPainter::drawRect( painter, 283 279 p1.x(), y, p2.x() - p1.x(), sw ); … … 286 282 && ( p1.x() == p2.x() ) ) 287 283 { 288 const double sw = d_data->width;289 290 const double x = p1.x() - d_data->width / 2;284 const double sw = m_data->width; 285 286 const double x = p1.x() - m_data->width / 2; 291 287 QwtPainter::drawRect( painter, 292 288 x, p1.y(), sw, p2.y() - p1.y() ); … … 294 290 else 295 291 { 296 const double sw = d_data->width;292 const double sw = m_data->width; 297 293 298 294 const double dx = p2.x() - p1.x(); 299 295 const double dy = p2.y() - p1.y(); 300 const double angle = qAtan2( dy, dx ) + M_PI_2;296 const double angle = std::atan2( dy, dx ) + M_PI_2; 301 297 double dw2 = sw / 2.0; 302 298 -
trunk/BNC/qwt/qwt_interval_symbol.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include <qpen.h> 15 #include <qsize.h> 14 #include <qnamespace.h> 16 15 17 16 class QPainter; 18 class QRect; 17 class QPen; 18 class QBrush; 19 19 class QPointF; 20 class QColor; 20 21 21 22 /*! 22 \brief A drawing primitive for displaying an interval like an error bar 23 \brief A drawing primitive for displaying an interval like an error bar 23 24 24 \sa QwtPlotIntervalCurve 25 */ 25 \sa QwtPlotIntervalCurve 26 */ 26 27 class QWT_EXPORT QwtIntervalSymbol 27 28 { 28 public: 29 public: 29 30 //! Symbol style 30 31 enum Style … … 34 35 35 36 /*! 36 The symbol displays a line with caps at the beginning/end. 37 The size of the caps depends on the symbol width(). 37 The symbol displays a line with caps at the beginning/end. 38 The size of the caps depends on the symbol width(). 38 39 */ 39 40 Bar, 40 41 41 42 /*! 42 The symbol displays a plain rectangle using pen() and brush(). 43 The size of the rectangle depends on the translated interval and 44 the width(), 43 The symbol displays a plain rectangle using pen() and brush(). 44 The size of the rectangle depends on the translated interval and 45 the width(), 45 46 */ 46 47 Box, 47 48 48 49 /*! 49 Styles >= UserSymbol are reserved for derived 50 classes of QwtIntervalSymbol that overload draw() with 51 additional application specific symbol types. 50 Styles >= UserSymbol are reserved for derived 51 classes of QwtIntervalSymbol that overload draw() with 52 additional application specific symbol types. 52 53 */ 53 54 UserSymbol = 1000 54 55 }; 55 56 56 public: 57 QwtIntervalSymbol( Style = NoSymbol ); 58 QwtIntervalSymbol( const QwtIntervalSymbol & ); 57 public: 58 explicit QwtIntervalSymbol( Style = NoSymbol ); 59 QwtIntervalSymbol( const QwtIntervalSymbol& ); 60 59 61 virtual ~QwtIntervalSymbol(); 60 62 61 QwtIntervalSymbol &operator=( const QwtIntervalSymbol& );62 bool operator==( const QwtIntervalSymbol & ) const;63 bool operator!=( const QwtIntervalSymbol & ) const;63 QwtIntervalSymbol& operator=( const QwtIntervalSymbol& ); 64 bool operator==( const QwtIntervalSymbol& ) const; 65 bool operator!=( const QwtIntervalSymbol& ) const; 64 66 65 67 void setWidth( int ); 66 68 int width() const; 67 69 68 void setBrush( const QBrush & );70 void setBrush( const QBrush& ); 69 71 const QBrush& brush() const; 70 72 71 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );72 void setPen( const QPen & );73 void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 74 void setPen( const QPen& ); 73 75 const QPen& pen() const; 74 76 … … 76 78 Style style() const; 77 79 78 virtual void draw( QPainter *, Qt::Orientation,80 virtual void draw( QPainter*, Qt::Orientation, 79 81 const QPointF& from, const QPointF& to ) const; 80 82 81 private: 83 private: 82 84 class PrivateData; 83 PrivateData* d_data;85 PrivateData* m_data; 84 86 }; 85 87 -
trunk/BNC/qwt/qwt_knob.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_knob.h" 11 11 #include "qwt_round_scale_draw.h" 12 #include "qwt_math.h"13 12 #include "qwt_painter.h" 14 13 #include "qwt_scale_map.h" 14 #include "qwt_math.h" 15 #include "qwt.h" 16 15 17 #include <qpainter.h> 16 18 #include <qpalette.h> … … 18 20 #include <qstyleoption.h> 19 21 #include <qevent.h> 22 #include <qmargins.h> 20 23 #include <qmath.h> 21 #include <qapplication.h> 22 23 #if QT_VERSION < 0x040601 24 #define qAtan2(y, x) ::atan2(y, x) 25 #define qFabs(x) ::fabs(x) 26 #define qFastCos(x) qCos(x) 27 #define qFastSin(x) qSin(x) 28 #endif 29 30 static QSize qwtKnobSizeHint( const QwtKnob *knob, int min ) 24 25 static QSize qwtKnobSizeHint( const QwtKnob* knob, int min ) 31 26 { 32 27 int knobWidth = knob->knobWidth(); … … 35 30 36 31 // Add the scale radial thickness to the knobWidth 37 const int extent = qCeil( knob->scaleDraw()->extent( knob->font() ) ); 32 const int extent = qwtCeil( knob->scaleDraw()->extent( knob->font() ) ); 38 33 const int d = 2 * ( extent + 4 ) + knobWidth; 39 34 40 int left, right, top, bottom; 41 knob->getContentsMargins( &left, &top, &right, &bottom ); 42 43 return QSize( d + left + right, d + top + bottom ); 35 const QMargins m = knob->contentsMargins(); 36 return QSize( d + m.left() + m.right(), d + m.top() + m.bottom() ); 44 37 } 45 38 … … 65 58 class QwtKnob::PrivateData 66 59 { 67 public: 68 PrivateData() :69 knobStyle( QwtKnob::Raised ) ,70 markerStyle( QwtKnob::Notch ) ,71 borderWidth( 2 ) ,72 borderDist( 4 ) ,73 scaleDist( 4 ) ,74 maxScaleTicks( 11 ) ,75 knobWidth( 0 ) ,76 alignment( Qt::AlignCenter ) ,77 markerSize( 8 ) ,78 totalAngle( 270.0 ) ,79 mouseOffset( 0.0 ) 60 public: 61 PrivateData() 62 : knobStyle( QwtKnob::Raised ) 63 , markerStyle( QwtKnob::Notch ) 64 , borderWidth( 2 ) 65 , borderDist( 4 ) 66 , scaleDist( 4 ) 67 , maxScaleTicks( 11 ) 68 , knobWidth( 0 ) 69 , alignment( Qt::AlignCenter ) 70 , markerSize( 8 ) 71 , totalAngle( 270.0 ) 72 , mouseOffset( 0.0 ) 80 73 { 81 74 } … … 98 91 99 92 /*! 100 \brief Constructor 101 102 Construct a knob with an angle of 270°. The style is 103 QwtKnob::Raised and the marker style is QwtKnob::Notch. 104 The width of the knob is set to 50 pixels. 105 106 \param parent Parent widget 107 108 \sa setTotalAngle() 109 */ 110 QwtKnob::QwtKnob( QWidget* parent ) :111 QwtAbstractSlider( parent ) 112 { 113 d_data = new PrivateData;93 \brief Constructor 94 95 Construct a knob with an angle of 270°. The style is 96 QwtKnob::Raised and the marker style is QwtKnob::Notch. 97 The width of the knob is set to 50 pixels. 98 99 \param parent Parent widget 100 101 \sa setTotalAngle() 102 */ 103 QwtKnob::QwtKnob( QWidget* parent ) 104 : QwtAbstractSlider( parent ) 105 { 106 m_data = new PrivateData; 114 107 115 108 setScaleDraw( new QwtRoundScaleDraw() ); … … 127 120 QwtKnob::~QwtKnob() 128 121 { 129 delete d_data;130 } 131 132 /*! 133 \brief Set the knob type 134 135 \param knobStyle Knob type 136 \sa knobStyle(), setBorderWidth() 137 */ 122 delete m_data; 123 } 124 125 /*! 126 \brief Set the knob type 127 128 \param knobStyle Knob type 129 \sa knobStyle(), setBorderWidth() 130 */ 138 131 void QwtKnob::setKnobStyle( KnobStyle knobStyle ) 139 132 { 140 if ( d_data->knobStyle != knobStyle )141 { 142 d_data->knobStyle = knobStyle;133 if ( m_data->knobStyle != knobStyle ) 134 { 135 m_data->knobStyle = knobStyle; 143 136 update(); 144 137 } … … 148 141 \return Marker type of the knob 149 142 \sa setKnobStyle(), setBorderWidth() 150 */ 143 */ 151 144 QwtKnob::KnobStyle QwtKnob::knobStyle() const 152 145 { 153 return d_data->knobStyle;154 } 155 156 /*! 157 \brief Set the marker type of the knob 158 159 \param markerStyle Marker type 160 \sa markerStyle(), setMarkerSize() 161 */ 146 return m_data->knobStyle; 147 } 148 149 /*! 150 \brief Set the marker type of the knob 151 152 \param markerStyle Marker type 153 \sa markerStyle(), setMarkerSize() 154 */ 162 155 void QwtKnob::setMarkerStyle( MarkerStyle markerStyle ) 163 156 { 164 if ( d_data->markerStyle != markerStyle )165 { 166 d_data->markerStyle = markerStyle;157 if ( m_data->markerStyle != markerStyle ) 158 { 159 m_data->markerStyle = markerStyle; 167 160 update(); 168 161 } … … 170 163 171 164 /*! 172 \return Marker type of the knob 173 \sa setMarkerStyle(), setMarkerSize() 174 */ 165 \return Marker type of the knob 166 \sa setMarkerStyle(), setMarkerSize() 167 */ 175 168 QwtKnob::MarkerStyle QwtKnob::markerStyle() const 176 169 { 177 return d_data->markerStyle;178 } 179 180 /*! 181 \brief Set the total angle by which the knob can be turned 182 \param angle Angle in degrees. 183 184 The angle has to be between [10, 360] degrees. Angles above 185 360 ( so that the knob can be turned several times around its axis ) 186 have to be set using setNumTurns(). 187 188 The default angle is 270 degrees. 189 190 \sa totalAngle(), setNumTurns() 191 */ 170 return m_data->markerStyle; 171 } 172 173 /*! 174 \brief Set the total angle by which the knob can be turned 175 \param angle Angle in degrees. 176 177 The angle has to be between [10, 360] degrees. Angles above 178 360 ( so that the knob can be turned several times around its axis ) 179 have to be set using setNumTurns(). 180 181 The default angle is 270 degrees. 182 183 \sa totalAngle(), setNumTurns() 184 */ 192 185 void QwtKnob::setTotalAngle ( double angle ) 193 186 { 194 187 angle = qBound( 10.0, angle, 360.0 ); 195 188 196 if ( angle != d_data->totalAngle )197 { 198 d_data->totalAngle = angle;199 200 scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle,201 0.5 * d_data->totalAngle );189 if ( angle != m_data->totalAngle ) 190 { 191 m_data->totalAngle = angle; 192 193 scaleDraw()->setAngleRange( -0.5 * m_data->totalAngle, 194 0.5 * m_data->totalAngle ); 202 195 203 196 updateGeometry(); … … 207 200 208 201 /*! 209 \return the total angle 210 \sa setTotalAngle(), setNumTurns(), numTurns() 202 \return the total angle 203 \sa setTotalAngle(), setNumTurns(), numTurns() 211 204 */ 212 205 double QwtKnob::totalAngle() const 213 206 { 214 return d_data->totalAngle;215 } 216 217 /*! 218 \brief Set the number of turns 219 220 When numTurns > 1 the knob can be turned several times around its axis 221 - otherwise the total angle is floored to 360°. 222 223 \sa numTurns(), totalAngle(), setTotalAngle() 224 */ 207 return m_data->totalAngle; 208 } 209 210 /*! 211 \brief Set the number of turns 212 213 When numTurns > 1 the knob can be turned several times around its axis 214 - otherwise the total angle is floored to 360°. 215 216 \sa numTurns(), totalAngle(), setTotalAngle() 217 */ 225 218 226 219 void QwtKnob::setNumTurns( int numTurns ) … … 228 221 numTurns = qMax( numTurns, 1 ); 229 222 230 if ( numTurns == 1 && d_data->totalAngle <= 360.0 )223 if ( numTurns == 1 && m_data->totalAngle <= 360.0 ) 231 224 return; 232 225 233 226 const double angle = numTurns * 360.0; 234 if ( angle != d_data->totalAngle )235 { 236 d_data->totalAngle = angle;237 238 scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle,239 0.5 * d_data->totalAngle );227 if ( angle != m_data->totalAngle ) 228 { 229 m_data->totalAngle = angle; 230 231 scaleDraw()->setAngleRange( -0.5 * m_data->totalAngle, 232 0.5 * m_data->totalAngle ); 240 233 241 234 updateGeometry(); … … 245 238 246 239 /*! 247 \return Number of turns. 248 249 When the total angle is below 360° numTurns() is ceiled to 1. 250 \sa setNumTurns(), setTotalAngle(), totalAngle() 240 \return Number of turns. 241 242 When the total angle is below 360° numTurns() is ceiled to 1. 243 \sa setNumTurns(), setTotalAngle(), totalAngle() 251 244 */ 252 245 int QwtKnob::numTurns() const 253 246 { 254 return q Ceil( d_data->totalAngle / 360.0 );247 return qwtCeil( m_data->totalAngle / 360.0 ); 255 248 } 256 249 … … 263 256 264 257 \sa scaleDraw() 265 */ 266 void QwtKnob::setScaleDraw( QwtRoundScaleDraw *scaleDraw )258 */ 259 void QwtKnob::setScaleDraw( QwtRoundScaleDraw* scaleDraw ) 267 260 { 268 261 setAbstractScaleDraw( scaleDraw ); 269 setTotalAngle( d_data->totalAngle );262 setTotalAngle( m_data->totalAngle ); 270 263 271 264 updateGeometry(); … … 276 269 \return the scale draw of the knob 277 270 \sa setScaleDraw() 278 */ 279 const QwtRoundScaleDraw *QwtKnob::scaleDraw() const280 { 281 return static_cast<const QwtRoundScaleDraw *>( abstractScaleDraw() );271 */ 272 const QwtRoundScaleDraw* QwtKnob::scaleDraw() const 273 { 274 return static_cast< const QwtRoundScaleDraw* >( abstractScaleDraw() ); 282 275 } 283 276 … … 285 278 \return the scale draw of the knob 286 279 \sa setScaleDraw() 287 */ 288 QwtRoundScaleDraw *QwtKnob::scaleDraw()289 { 290 return static_cast<QwtRoundScaleDraw *>( abstractScaleDraw() );291 } 292 293 /*! 294 Calculate the bounding rectangle of the knob without the scale 295 296 \return Bounding rectangle of the knob 297 \sa knobWidth(), alignment(), QWidget::contentsRect() 280 */ 281 QwtRoundScaleDraw* QwtKnob::scaleDraw() 282 { 283 return static_cast< QwtRoundScaleDraw* >( abstractScaleDraw() ); 284 } 285 286 /*! 287 Calculate the bounding rectangle of the knob without the scale 288 289 \return Bounding rectangle of the knob 290 \sa knobWidth(), alignment(), QWidget::contentsRect() 298 291 */ 299 292 QRect QwtKnob::knobRect() const … … 301 294 const QRect cr = contentsRect(); 302 295 303 const int extent = qCeil( scaleDraw()->extent( font() ) ); 304 const int d = extent + d_data->scaleDist;305 306 int w = d_data->knobWidth;296 const int extent = qwtCeil( scaleDraw()->extent( font() ) ); 297 const int d = extent + m_data->scaleDist; 298 299 int w = m_data->knobWidth; 307 300 if ( w <= 0 ) 308 301 { … … 315 308 QRect r( 0, 0, w, w ); 316 309 317 if ( d_data->alignment & Qt::AlignLeft )310 if ( m_data->alignment & Qt::AlignLeft ) 318 311 { 319 312 r.moveLeft( cr.left() + d ); 320 313 } 321 else if ( d_data->alignment & Qt::AlignRight )314 else if ( m_data->alignment & Qt::AlignRight ) 322 315 { 323 316 r.moveRight( cr.right() - d ); … … 328 321 } 329 322 330 if ( d_data->alignment & Qt::AlignTop )323 if ( m_data->alignment & Qt::AlignTop ) 331 324 { 332 325 r.moveTop( cr.top() + d ); 333 326 } 334 else if ( d_data->alignment & Qt::AlignBottom )327 else if ( m_data->alignment & Qt::AlignBottom ) 335 328 { 336 329 r.moveBottom( cr.bottom() - d ); … … 345 338 346 339 /*! 347 \brief Determine what to do when the user presses a mouse button. 348 349 \param pos Mouse position 350 351 \retval True, when pos is inside the circle of the knob. 352 \sa scrolledTo() 353 */ 354 bool QwtKnob::isScrollPosition( const QPoint &pos ) const340 \brief Determine what to do when the user presses a mouse button. 341 342 \param pos Mouse position 343 344 \retval True, when pos is inside the circle of the knob. 345 \sa scrolledTo() 346 */ 347 bool QwtKnob::isScrollPosition( const QPoint& pos ) const 355 348 { 356 349 const QRect kr = knobRect(); … … 362 355 const double valueAngle = qwtToDegrees( scaleMap().transform( value() ) ); 363 356 364 d_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );357 m_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle ); 365 358 366 359 return true; … … 371 364 372 365 /*! 373 \brief Determine the value for a new position of the mouse 374 375 \param pos Mouse position 376 377 \return Value for the mouse position 378 \sa isScrollPosition() 379 */ 380 double QwtKnob::scrolledTo( const QPoint &pos ) const366 \brief Determine the value for a new position of the mouse 367 368 \param pos Mouse position 369 370 \return Value for the mouse position 371 \sa isScrollPosition() 372 */ 373 double QwtKnob::scrolledTo( const QPoint& pos ) const 381 374 { 382 375 double angle = QLineF( rect().center(), pos ).angle(); 383 angle = qwtNormalizeDegrees( angle - d_data->mouseOffset );376 angle = qwtNormalizeDegrees( angle - m_data->mouseOffset ); 384 377 385 378 if ( scaleMap().pDist() > 360.0 ) … … 389 382 const double v = scaleMap().transform( value() ); 390 383 391 int numTurns = qFloor( ( v - scaleMap().p1() ) / 360.0 ); 384 int numTurns = qwtFloor( ( v - scaleMap().p1() ) / 360.0 ); 392 385 393 386 double valueAngle = qwtNormalizeDegrees( v ); … … 404 397 qBound( scaleMap().p1(), angle, scaleMap().p2() ); 405 398 406 d_data->mouseOffset += ( boundedAngle - angle );399 m_data->mouseOffset += ( boundedAngle - angle ); 407 400 angle = boundedAngle; 408 401 } … … 423 416 boundedAngle = scaleMap().p1(); 424 417 425 d_data->mouseOffset += ( boundedAngle - angle );418 m_data->mouseOffset += ( boundedAngle - angle ); 426 419 } 427 420 … … 433 426 434 427 /*! 435 Handle QEvent::StyleChange and QEvent::FontChange; 436 \param event Change event 437 */ 438 void QwtKnob::changeEvent( QEvent *event )428 Handle QEvent::StyleChange and QEvent::FontChange; 429 \param event Change event 430 */ 431 void QwtKnob::changeEvent( QEvent* event ) 439 432 { 440 433 switch( event->type() ) … … 453 446 454 447 /*! 455 Repaint the knob 456 \param event Paint event 457 */ 458 void QwtKnob::paintEvent( QPaintEvent *event )448 Repaint the knob 449 \param event Paint event 450 */ 451 void QwtKnob::paintEvent( QPaintEvent* event ) 459 452 { 460 453 const QRectF knobRect = this->knobRect(); … … 464 457 465 458 QStyleOption opt; 466 opt.init(this); 459 opt.initFrom(this); 467 460 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 468 461 … … 471 464 if ( !knobRect.contains( event->region().boundingRect() ) ) 472 465 { 473 scaleDraw()->setRadius( 0.5 * knobRect.width() + d_data->scaleDist );466 scaleDraw()->setRadius( 0.5 * knobRect.width() + m_data->scaleDist ); 474 467 scaleDraw()->moveCenter( knobRect.center() ); 475 468 … … 489 482 490 483 /*! 491 \brief Draw the knob 492 493 \param painter painter 494 \param knobRect Bounding rectangle of the knob (without scale) 495 */ 496 void QwtKnob::drawKnob( QPainter *painter, const QRectF&knobRect ) const484 \brief Draw the knob 485 486 \param painter painter 487 \param knobRect Bounding rectangle of the knob (without scale) 488 */ 489 void QwtKnob::drawKnob( QPainter* painter, const QRectF& knobRect ) const 497 490 { 498 491 double dim = qMin( knobRect.width(), knobRect.height() ); 499 dim -= d_data->borderWidth * 0.5;492 dim -= m_data->borderWidth * 0.5; 500 493 501 494 QRectF aRect( 0, 0, dim, dim ); … … 503 496 504 497 QPen pen( Qt::NoPen ); 505 if ( d_data->borderWidth > 0 )498 if ( m_data->borderWidth > 0 ) 506 499 { 507 500 QColor c1 = palette().color( QPalette::Light ); … … 514 507 gradient.setColorAt( 1.0, c2 ); 515 508 516 pen = QPen( gradient, d_data->borderWidth );509 pen = QPen( gradient, m_data->borderWidth ); 517 510 } 518 511 519 512 QBrush brush; 520 switch( d_data->knobStyle )513 switch( m_data->knobStyle ) 521 514 { 522 515 case QwtKnob::Raised: … … 542 535 543 536 const QColor c = palette().color( QPalette::Button ); 544 gradient.setColorAt(0, c.lighter(110)); 545 gradient.setColorAt( qreal(0.5), c);546 gradient.setColorAt( qreal(0.501), c.darker(102));547 gradient.setColorAt(1, c.darker(115)); 537 gradient.setColorAt(0, c.lighter(110) ); 538 gradient.setColorAt( 0.5, c); 539 gradient.setColorAt( 0.501, c.darker(102) ); 540 gradient.setColorAt(1, c.darker(115) ); 548 541 549 542 brush = QBrush( gradient ); … … 574 567 575 568 /*! 576 \brief Draw the marker at the knob's front 577 578 \param painter Painter 579 \param rect Bounding rectangle of the knob without scale 580 \param angle Angle of the marker in degrees 569 \brief Draw the marker at the knob's front 570 571 \param painter Painter 572 \param rect Bounding rectangle of the knob without scale 573 \param angle Angle of the marker in degrees 581 574 ( clockwise, 0 at the 12 o'clock position ) 582 */ 583 void QwtKnob::drawMarker( QPainter *painter,584 const QRectF &rect, double angle ) const585 { 586 if ( d_data->markerStyle == NoMarker || !isValid() )575 */ 576 void QwtKnob::drawMarker( QPainter* painter, 577 const QRectF& rect, double angle ) const 578 { 579 if ( m_data->markerStyle == NoMarker || !isValid() ) 587 580 return; 588 581 … … 595 588 const double margin = 4.0; 596 589 597 double radius = 0.5 * ( rect.width() - d_data->borderWidth ) - margin;590 double radius = 0.5 * ( rect.width() - m_data->borderWidth ) - margin; 598 591 if ( radius < 1.0 ) 599 592 radius = 1.0; 600 593 601 intmarkerSize =d_data->markerSize;594 double markerSize = m_data->markerSize; 602 595 if ( markerSize <= 0 ) 603 596 markerSize = qRound( 0.4 * radius ); 604 597 605 switch ( d_data->markerStyle )598 switch ( m_data->markerStyle ) 606 599 { 607 600 case Notch: 608 601 case Nub: 609 602 { 610 const double dotWidth = 611 qMin( double( markerSize ), radius); 603 const double dotWidth = qwtMinF( markerSize, radius ); 612 604 613 605 const double dotCenterDist = radius - 0.5 * dotWidth; … … 623 615 QColor c2 = palette().color( QPalette::Mid ); 624 616 625 if ( d_data->markerStyle == Notch )617 if ( m_data->markerStyle == Notch ) 626 618 qSwap( c1, c2 ); 627 619 … … 640 632 case Dot: 641 633 { 642 const double dotWidth = 643 qMin( double( markerSize ), radius); 634 const double dotWidth = qwtMinF( markerSize, radius); 644 635 645 636 const double dotCenterDist = radius - 0.5 * dotWidth; … … 661 652 case Tick: 662 653 { 663 const double rb = q Max( radius - markerSize, 1.0 );654 const double rb = qwtMaxF( radius - markerSize, 1.0 ); 664 655 const double re = radius; 665 656 … … 676 667 case Triangle: 677 668 { 678 const double rb = q Max( radius - markerSize, 1.0 );669 const double rb = qwtMaxF( radius - markerSize, 1.0 ); 679 670 const double re = radius; 680 671 … … 701 692 702 693 /*! 703 Draw the focus indicator 704 \param painter Painter 705 */ 706 void QwtKnob::drawFocusIndicator( QPainter *painter ) const694 Draw the focus indicator 695 \param painter Painter 696 */ 697 void QwtKnob::drawFocusIndicator( QPainter* painter ) const 707 698 { 708 699 const QRect cr = contentsRect(); 709 700 710 int w = d_data->knobWidth;701 int w = m_data->knobWidth; 711 702 if ( w <= 0 ) 712 703 { … … 716 707 { 717 708 const int extent = qCeil( scaleDraw()->extent( font() ) ); 718 w += 2 * ( extent + d_data->scaleDist );709 w += 2 * ( extent + m_data->scaleDist ); 719 710 } 720 711 … … 726 717 727 718 /*! 728 \brief Set the alignment of the knob 729 730 Similar to a QLabel::alignment() the flags decide how 731 to align the knob inside of contentsRect(). 732 733 The default setting is Qt::AlignCenter 734 735 \param alignment Or'd alignment flags 736 737 \sa alignment(), setKnobWidth(), knobRect() 719 \brief Set the alignment of the knob 720 721 Similar to a QLabel::alignment() the flags decide how 722 to align the knob inside of contentsRect(). 723 724 The default setting is Qt::AlignCenter 725 726 \param alignment Or'd alignment flags 727 728 \sa alignment(), setKnobWidth(), knobRect() 738 729 */ 739 730 void QwtKnob::setAlignment( Qt::Alignment alignment ) 740 731 { 741 if ( d_data->alignment != alignment )742 { 743 d_data->alignment = alignment;732 if ( m_data->alignment != alignment ) 733 { 734 m_data->alignment = alignment; 744 735 update(); 745 736 } … … 747 738 748 739 /*! 749 \return Alignment of the knob inside of contentsRect() 750 \sa setAlignment(), knobWidth(), knobRect() 740 \return Alignment of the knob inside of contentsRect() 741 \sa setAlignment(), knobWidth(), knobRect() 751 742 */ 752 743 Qt::Alignment QwtKnob::alignment() const 753 744 { 754 return d_data->alignment;755 } 756 757 /*! 758 \brief Change the knob's width. 759 760 Setting a fixed value for the diameter of the knob 761 is helpful for aligning several knobs in a row. 762 763 \param width New width 764 765 \sa knobWidth(), setAlignment() 766 \note Modifies the sizePolicy() 767 */ 745 return m_data->alignment; 746 } 747 748 /*! 749 \brief Change the knob's width. 750 751 Setting a fixed value for the diameter of the knob 752 is helpful for aligning several knobs in a row. 753 754 \param width New width 755 756 \sa knobWidth(), setAlignment() 757 \note Modifies the sizePolicy() 758 */ 768 759 void QwtKnob::setKnobWidth( int width ) 769 760 { 770 761 width = qMax( width, 0 ); 771 762 772 if ( width != d_data->knobWidth )763 if ( width != m_data->knobWidth ) 773 764 { 774 765 QSizePolicy::Policy policy; … … 780 771 setSizePolicy( policy, policy ); 781 772 782 d_data->knobWidth = width;773 m_data->knobWidth = width; 783 774 784 775 updateGeometry(); … … 790 781 int QwtKnob::knobWidth() const 791 782 { 792 return d_data->knobWidth;793 } 794 795 /*! 796 \brief Set the knob's border width 797 \param borderWidth new border width 798 */ 783 return m_data->knobWidth; 784 } 785 786 /*! 787 \brief Set the knob's border width 788 \param borderWidth new border width 789 */ 799 790 void QwtKnob::setBorderWidth( int borderWidth ) 800 791 { 801 d_data->borderWidth = qMax( borderWidth, 0 );792 m_data->borderWidth = qMax( borderWidth, 0 ); 802 793 803 794 updateGeometry(); … … 808 799 int QwtKnob::borderWidth() const 809 800 { 810 return d_data->borderWidth;811 } 812 813 /*! 814 \brief Set the size of the marker 815 816 When setting a size <= 0 the marker will 817 automatically scaled to 40% of the radius of the knob. 818 819 \sa markerSize(), markerStyle() 820 */ 801 return m_data->borderWidth; 802 } 803 804 /*! 805 \brief Set the size of the marker 806 807 When setting a size <= 0 the marker will 808 automatically scaled to 40% of the radius of the knob. 809 810 \sa markerSize(), markerStyle() 811 */ 821 812 void QwtKnob::setMarkerSize( int size ) 822 813 { 823 if ( d_data->markerSize != size )824 { 825 d_data->markerSize = size;814 if ( m_data->markerSize != size ) 815 { 816 m_data->markerSize = size; 826 817 update(); 827 818 } … … 829 820 830 821 /*! 831 \return Marker size 832 \sa setMarkerSize() 822 \return Marker size 823 \sa setMarkerSize() 833 824 */ 834 825 int QwtKnob::markerSize() const 835 826 { 836 return d_data->markerSize;837 } 838 839 /*! 840 \return sizeHint() 841 */ 827 return m_data->markerSize; 828 } 829 830 /*! 831 \return sizeHint() 832 */ 842 833 QSize QwtKnob::sizeHint() const 843 834 { 844 835 const QSize hint = qwtKnobSizeHint( this, 50 ); 845 return hint.expandedTo( QApplication::globalStrut());846 } 847 848 /*! 849 \return Minimum size hint 850 \sa sizeHint() 851 */ 836 return qwtExpandedToGlobalStrut( hint ); 837 } 838 839 /*! 840 \return Minimum size hint 841 \sa sizeHint() 842 */ 852 843 QSize QwtKnob::minimumSizeHint() const 853 844 { 854 845 return qwtKnobSizeHint( this, 20 ); 855 846 } 847 848 #include "moc_qwt_knob.cpp" -
trunk/BNC/qwt/qwt_knob.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 17 17 18 18 /*! 19 \brief The Knob Widget 19 \brief The Knob Widget 20 20 21 The QwtKnob widget imitates look and behavior of a volume knob on a radio. 22 It looks similar to QDial - not to QwtDial. 21 The QwtKnob widget imitates look and behavior of a volume knob on a radio. 22 It looks similar to QDial - not to QwtDial. 23 23 24 The value range of a knob might be divided into several turns. 24 The value range of a knob might be divided into several turns. 25 25 26 The layout of the knob depends on the knobWidth(). 26 The layout of the knob depends on the knobWidth(). 27 27 28 - width > 0 28 - width > 0 29 29 The diameter of the knob is fixed and the knob is aligned 30 30 according to the alignment() flags inside of the contentsRect(). 31 31 32 - width <= 0 32 - width <= 0 33 33 The knob is extended to the minimum of width/height of the contentsRect() 34 34 and aligned in the other direction according to alignment(). 35 35 36 Setting a fixed knobWidth() is helpful to align several knobs with different 37 scale labels. 36 Setting a fixed knobWidth() is helpful to align several knobs with different 37 scale labels. 38 38 39 \image html knob.png 40 */ 39 \image html knob.png 40 */ 41 41 42 class QWT_EXPORT QwtKnob: public QwtAbstractSlider 42 class QWT_EXPORT QwtKnob : public QwtAbstractSlider 43 43 { 44 44 Q_OBJECT … … 55 55 Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth ) 56 56 57 public: 57 public: 58 58 /*! 59 59 \brief Style of the knob surface … … 73 73 74 74 /*! 75 Build a gradient from QPalette::Midlight, QPalette::Button 76 and QPalette::Midlight 75 Build a gradient from QPalette::Midlight, QPalette::Button 76 and QPalette::Midlight 77 77 */ 78 78 Sunken, 79 79 80 80 /*! 81 Build a radial gradient from QPalette::Button 82 like it is used for QDial in various Qt styles. 81 Build a radial gradient from QPalette::Button 82 like it is used for QDial in various Qt styles. 83 83 */ 84 84 Styled … … 92 92 93 93 \sa setMarkerStyle(), setMarkerSize() 94 */ 94 */ 95 95 enum MarkerStyle 96 96 { … … 108 108 109 109 /*! 110 Draw a raised ellipse with a gradient build from 111 QPalette::Light and QPalette::Mid 110 Draw a raised ellipse with a gradient build from 111 QPalette::Light and QPalette::Mid 112 112 */ 113 113 Nub, 114 114 115 115 /*! 116 Draw a sunken ellipse with a gradient build from 117 QPalette::Light and QPalette::Mid 116 Draw a sunken ellipse with a gradient build from 117 QPalette::Light and QPalette::Mid 118 118 */ 119 119 Notch … … 147 147 int markerSize() const; 148 148 149 virtual QSize sizeHint() const; 150 virtual QSize minimumSizeHint() const; 149 virtual QSize sizeHint() const QWT_OVERRIDE; 150 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 151 151 152 void setScaleDraw( QwtRoundScaleDraw * );152 void setScaleDraw( QwtRoundScaleDraw* ); 153 153 154 const QwtRoundScaleDraw *scaleDraw() const;155 QwtRoundScaleDraw *scaleDraw();154 const QwtRoundScaleDraw* scaleDraw() const; 155 QwtRoundScaleDraw* scaleDraw(); 156 156 157 157 QRect knobRect() const; 158 158 159 protected: 160 virtual void paintEvent( QPaintEvent * );161 virtual void changeEvent( QEvent * );159 protected: 160 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 161 virtual void changeEvent( QEvent* ) QWT_OVERRIDE; 162 162 163 virtual void drawKnob( QPainter *, const QRectF& ) const;163 virtual void drawKnob( QPainter*, const QRectF& ) const; 164 164 165 virtual void drawFocusIndicator( QPainter * ) const;165 virtual void drawFocusIndicator( QPainter* ) const; 166 166 167 virtual void drawMarker( QPainter *,168 const QRectF &, double angle ) const;167 virtual void drawMarker( QPainter*, 168 const QRectF&, double angle ) const; 169 169 170 virtual double scrolledTo( const QPoint & ) const;171 virtual bool isScrollPosition( const QPoint & ) const;170 virtual double scrolledTo( const QPoint& ) const QWT_OVERRIDE; 171 virtual bool isScrollPosition( const QPoint& ) const QWT_OVERRIDE; 172 172 173 private: 173 private: 174 174 class PrivateData; 175 PrivateData *d_data;175 PrivateData* m_data; 176 176 }; 177 177 -
trunk/BNC/qwt/qwt_legend.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_dyngrid_layout.h" 13 13 #include "qwt_math.h" 14 #include "qwt_plot_item.h"15 14 #include "qwt_painter.h" 15 #include "qwt_graphic.h" 16 16 17 #include <qapplication.h> 17 18 #include <qscrollbar.h> 18 19 #include <qscrollarea.h> 19 20 #include <qpainter.h> 20 #include <qstyle.h> 21 #include <qstyleoption.h> 22 23 class QwtLegendMap 24 { 25 public: 26 inline bool isEmpty() const { return d_entries.isEmpty(); } 27 28 void insert( const QVariant &, const QList<QWidget *> & ); 29 void remove( const QVariant & ); 30 31 void removeWidget( const QWidget * ); 32 33 QList<QWidget *> legendWidgets( const QVariant & ) const; 34 QVariant itemInfo( const QWidget * ) const; 35 36 private: 37 // we don't know anything about itemInfo and therefore don't have 38 // any key that can be used for a map or hashtab. 39 // But a simple linear list is o.k. here, as we will never have 40 // more than a few entries. 41 42 class Entry 43 { 44 public: 45 QVariant itemInfo; 46 QList<QWidget *> widgets; 21 #include <qmargins.h> 22 23 namespace 24 { 25 class LegendMap 26 { 27 public: 28 inline bool isEmpty() const { return m_entries.isEmpty(); } 29 30 void insert( const QVariant&, const QList< QWidget* >& ); 31 void remove( const QVariant& ); 32 33 void removeWidget( const QWidget* ); 34 35 QList< QWidget* > legendWidgets( const QVariant& ) const; 36 QVariant itemInfo( const QWidget* ) const; 37 38 private: 39 // we don't know anything about itemInfo and therefore don't have 40 // any key that can be used for a map or hashtab. 41 // But a simple linear list is o.k. here, as we will never have 42 // more than a few entries. 43 44 class Entry 45 { 46 public: 47 QVariant itemInfo; 48 QList< QWidget* > widgets; 49 }; 50 51 QList< Entry > m_entries; 47 52 }; 48 53 49 QList< Entry > d_entries; 54 void LegendMap::insert( const QVariant& itemInfo, 55 const QList< QWidget* >& widgets ) 56 { 57 for ( int i = 0; i < m_entries.size(); i++ ) 58 { 59 Entry& entry = m_entries[i]; 60 if ( entry.itemInfo == itemInfo ) 61 { 62 entry.widgets = widgets; 63 return; 64 } 65 } 66 67 Entry newEntry; 68 newEntry.itemInfo = itemInfo; 69 newEntry.widgets = widgets; 70 71 m_entries += newEntry; 72 } 73 74 void LegendMap::remove( const QVariant& itemInfo ) 75 { 76 for ( int i = 0; i < m_entries.size(); i++ ) 77 { 78 Entry& entry = m_entries[i]; 79 if ( entry.itemInfo == itemInfo ) 80 { 81 m_entries.removeAt( i ); 82 return; 83 } 84 } 85 } 86 87 void LegendMap::removeWidget( const QWidget* widget ) 88 { 89 QWidget* w = const_cast< QWidget* >( widget ); 90 91 for ( int i = 0; i < m_entries.size(); i++ ) 92 m_entries[ i ].widgets.removeAll( w ); 93 } 94 95 QVariant LegendMap::itemInfo( const QWidget* widget ) const 96 { 97 if ( widget != NULL ) 98 { 99 QWidget* w = const_cast< QWidget* >( widget ); 100 101 for ( int i = 0; i < m_entries.size(); i++ ) 102 { 103 const Entry& entry = m_entries[i]; 104 if ( entry.widgets.indexOf( w ) >= 0 ) 105 return entry.itemInfo; 106 } 107 } 108 109 return QVariant(); 110 } 111 112 QList< QWidget* > LegendMap::legendWidgets( const QVariant& itemInfo ) const 113 { 114 if ( itemInfo.isValid() ) 115 { 116 for ( int i = 0; i < m_entries.size(); i++ ) 117 { 118 const Entry& entry = m_entries[i]; 119 if ( entry.itemInfo == itemInfo ) 120 return entry.widgets; 121 } 122 } 123 124 return QList< QWidget* >(); 125 } 126 } 127 128 class QwtLegend::PrivateData 129 { 130 public: 131 PrivateData() 132 : itemMode( QwtLegendData::ReadOnly ) 133 , view( NULL ) 134 { 135 } 136 137 QwtLegendData::Mode itemMode; 138 LegendMap itemMap; 139 140 class LegendView; 141 LegendView* view; 50 142 }; 51 143 52 void QwtLegendMap::insert( const QVariant &itemInfo, 53 const QList<QWidget *> &widgets ) 54 { 55 for ( int i = 0; i < d_entries.size(); i++ ) 56 { 57 Entry &entry = d_entries[i]; 58 if ( entry.itemInfo == itemInfo ) 59 { 60 entry.widgets = widgets; 61 return; 62 } 63 } 64 65 Entry newEntry; 66 newEntry.itemInfo = itemInfo; 67 newEntry.widgets = widgets; 68 69 d_entries += newEntry; 70 } 71 72 void QwtLegendMap::remove( const QVariant &itemInfo ) 73 { 74 for ( int i = 0; i < d_entries.size(); i++ ) 75 { 76 Entry &entry = d_entries[i]; 77 if ( entry.itemInfo == itemInfo ) 78 { 79 d_entries.removeAt( i ); 80 return; 81 } 82 } 83 } 84 85 void QwtLegendMap::removeWidget( const QWidget *widget ) 86 { 87 QWidget *w = const_cast<QWidget *>( widget ); 88 89 for ( int i = 0; i < d_entries.size(); i++ ) 90 d_entries[ i ].widgets.removeAll( w ); 91 } 92 93 QVariant QwtLegendMap::itemInfo( const QWidget *widget ) const 94 { 95 if ( widget != NULL ) 96 { 97 QWidget *w = const_cast<QWidget *>( widget ); 98 99 for ( int i = 0; i < d_entries.size(); i++ ) 100 { 101 const Entry &entry = d_entries[i]; 102 if ( entry.widgets.indexOf( w ) >= 0 ) 103 return entry.itemInfo; 104 } 105 } 106 107 return QVariant(); 108 } 109 110 QList<QWidget *> QwtLegendMap::legendWidgets( const QVariant &itemInfo ) const 111 { 112 if ( itemInfo.isValid() ) 113 { 114 for ( int i = 0; i < d_entries.size(); i++ ) 115 { 116 const Entry &entry = d_entries[i]; 117 if ( entry.itemInfo == itemInfo ) 118 return entry.widgets; 119 } 120 } 121 122 return QList<QWidget *>(); 123 } 124 125 class QwtLegend::PrivateData 126 { 127 public: 128 PrivateData(): 129 itemMode( QwtLegendData::ReadOnly ), 130 view( NULL ) 131 { 132 } 133 134 QwtLegendData::Mode itemMode; 135 QwtLegendMap itemMap; 136 137 class LegendView; 138 LegendView *view; 139 }; 140 141 class QwtLegend::PrivateData::LegendView: public QScrollArea 142 { 143 public: 144 explicit LegendView( QWidget *parent ): 144 class QwtLegend::PrivateData::LegendView QWT_FINAL : public QScrollArea 145 { 146 public: 147 explicit LegendView( QWidget * parent ) : 145 148 QScrollArea( parent ) 146 149 { … … 159 162 } 160 163 161 virtual bool event( QEvent *event )164 virtual bool event( QEvent* event ) QWT_OVERRIDE 162 165 { 163 166 if ( event->type() == QEvent::PolishRequest ) … … 187 190 } 188 191 189 virtual bool viewportEvent( QEvent *event )192 virtual bool viewportEvent( QEvent* event ) QWT_OVERRIDE 190 193 { 191 194 bool ok = QScrollArea::viewportEvent( event ); … … 223 226 void layoutContents() 224 227 { 225 const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout*>(228 const QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >( 226 229 contentsWidget->layout() ); 227 230 if ( tl == NULL ) … … 230 233 const QSize visibleSize = viewport()->contentsRect().size(); 231 234 232 const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin(); 235 const QMargins m = tl->contentsMargins(); 236 const int minW = tl->maxItemWidth() + m.left() + m.right(); 233 237 234 238 int w = qMax( visibleSize.width(), minW ); … … 245 249 } 246 250 247 QWidget *contentsWidget;251 QWidget* contentsWidget; 248 252 }; 249 253 250 254 /*! 251 Constructor 252 \param parent Parent widget 253 */ 254 QwtLegend::QwtLegend( QWidget *parent ):255 QwtAbstractLegend( parent ) 255 Constructor 256 \param parent Parent widget 257 */ 258 QwtLegend::QwtLegend( QWidget* parent ) 259 : QwtAbstractLegend( parent ) 256 260 { 257 261 setFrameStyle( NoFrame ); 258 262 259 d_data = new QwtLegend::PrivateData;260 261 d_data->view = new QwtLegend::PrivateData::LegendView( this );262 d_data->view->setObjectName( "QwtLegendView" );263 d_data->view->setFrameStyle( NoFrame );264 265 QwtDynGridLayout *gridLayout = new QwtDynGridLayout(266 d_data->view->contentsWidget );263 m_data = new QwtLegend::PrivateData; 264 265 m_data->view = new QwtLegend::PrivateData::LegendView( this ); 266 m_data->view->setObjectName( "QwtLegendView" ); 267 m_data->view->setFrameStyle( NoFrame ); 268 269 QwtDynGridLayout* gridLayout = new QwtDynGridLayout( 270 m_data->view->contentsWidget ); 267 271 gridLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop ); 268 272 269 d_data->view->contentsWidget->installEventFilter( this );270 271 QVBoxLayout *layout = new QVBoxLayout( this );273 m_data->view->contentsWidget->installEventFilter( this ); 274 275 QVBoxLayout* layout = new QVBoxLayout( this ); 272 276 layout->setContentsMargins( 0, 0, 0, 0 ); 273 layout->addWidget( d_data->view );277 layout->addWidget( m_data->view ); 274 278 } 275 279 … … 277 281 QwtLegend::~QwtLegend() 278 282 { 279 delete d_data;280 } 281 282 /*! 283 \brief Set the maximum number of entries in a row 284 285 F.e when the maximum is set to 1 all items are aligned 286 vertically. 0 means unlimited 287 288 \param numColums Maximum number of entries in a row 289 290 \sa maxColumns(), QwtDynGridLayout::setMaxColumns() 283 delete m_data; 284 } 285 286 /*! 287 \brief Set the maximum number of entries in a row 288 289 F.e when the maximum is set to 1 all items are aligned 290 vertically. 0 means unlimited 291 292 \param numColums Maximum number of entries in a row 293 294 \sa maxColumns(), QwtDynGridLayout::setMaxColumns() 291 295 */ 292 296 void QwtLegend::setMaxColumns( uint numColums ) 293 297 { 294 QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout*>(295 d_data->view->contentsWidget->layout() );298 QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >( 299 m_data->view->contentsWidget->layout() ); 296 300 if ( tl ) 297 301 tl->setMaxColumns( numColums ); … … 301 305 302 306 /*! 303 \return Maximum number of entries in a row 304 \sa setMaxColumns(), QwtDynGridLayout::maxColumns() 307 \return Maximum number of entries in a row 308 \sa setMaxColumns(), QwtDynGridLayout::maxColumns() 305 309 */ 306 310 uint QwtLegend::maxColumns() const … … 308 312 uint maxCols = 0; 309 313 310 const QwtDynGridLayout *tl = qobject_cast<const QwtDynGridLayout*>(311 d_data->view->contentsWidget->layout() );314 const QwtDynGridLayout* tl = qobject_cast< const QwtDynGridLayout* >( 315 m_data->view->contentsWidget->layout() ); 312 316 if ( tl ) 313 317 maxCols = tl->maxColumns(); … … 317 321 318 322 /*! 319 \brief Set the default mode for legend labels 320 321 Legend labels will be constructed according to the 322 attributes in a QwtLegendData object. When it doesn't 323 contain a value for the QwtLegendData::ModeRole the 324 label will be initialized with the default mode of the legend. 325 326 \param mode Default item mode 327 328 \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData() 329 \note Changing the mode doesn't have any effect on existing labels. 323 \brief Set the default mode for legend labels 324 325 Legend labels will be constructed according to the 326 attributes in a QwtLegendData object. When it doesn't 327 contain a value for the QwtLegendData::ModeRole the 328 label will be initialized with the default mode of the legend. 329 330 \param mode Default item mode 331 332 \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData() 333 \note Changing the mode doesn't have any effect on existing labels. 330 334 */ 331 335 void QwtLegend::setDefaultItemMode( QwtLegendData::Mode mode ) 332 336 { 333 d_data->itemMode = mode;334 } 335 336 /*! 337 \return Default item mode 338 \sa setDefaultItemMode() 339 */ 337 m_data->itemMode = mode; 338 } 339 340 /*! 341 \return Default item mode 342 \sa setDefaultItemMode() 343 */ 340 344 QwtLegendData::Mode QwtLegend::defaultItemMode() const 341 345 { 342 return d_data->itemMode;343 } 344 345 /*! 346 The contents widget is the only child of the viewport of 347 the internal QScrollArea and the parent widget of all legend items. 348 349 \return Container widget of the legend items 350 */ 351 QWidget *QwtLegend::contentsWidget()352 { 353 return d_data->view->contentsWidget;354 } 355 356 /*! 357 \return Horizontal scrollbar 358 \sa verticalScrollBar() 359 */ 360 QScrollBar *QwtLegend::horizontalScrollBar() const361 { 362 return d_data->view->horizontalScrollBar();363 } 364 365 /*! 366 \return Vertical scrollbar 367 \sa horizontalScrollBar() 368 */ 369 QScrollBar *QwtLegend::verticalScrollBar() const370 { 371 return d_data->view->verticalScrollBar();372 } 373 374 /*! 375 The contents widget is the only child of the viewport of 376 the internal QScrollArea and the parent widget of all legend items. 377 378 \return Container widget of the legend items 379 380 */ 381 const QWidget *QwtLegend::contentsWidget() const382 { 383 return d_data->view->contentsWidget;384 } 385 386 /*! 387 \brief Update the entries for an item 388 389 \param itemInfo Info for an item 390 \param legendData List of legend entry attributes for the item 391 */ 392 void QwtLegend::updateLegend( const QVariant &itemInfo,393 const QList<QwtLegendData > &legendData )394 { 395 QList<QWidget *> widgetList = legendWidgets( itemInfo );346 return m_data->itemMode; 347 } 348 349 /*! 350 The contents widget is the only child of the viewport of 351 the internal QScrollArea and the parent widget of all legend items. 352 353 \return Container widget of the legend items 354 */ 355 QWidget* QwtLegend::contentsWidget() 356 { 357 return m_data->view->contentsWidget; 358 } 359 360 /*! 361 \return Horizontal scrollbar 362 \sa verticalScrollBar() 363 */ 364 QScrollBar* QwtLegend::horizontalScrollBar() const 365 { 366 return m_data->view->horizontalScrollBar(); 367 } 368 369 /*! 370 \return Vertical scrollbar 371 \sa horizontalScrollBar() 372 */ 373 QScrollBar* QwtLegend::verticalScrollBar() const 374 { 375 return m_data->view->verticalScrollBar(); 376 } 377 378 /*! 379 The contents widget is the only child of the viewport of 380 the internal QScrollArea and the parent widget of all legend items. 381 382 \return Container widget of the legend items 383 384 */ 385 const QWidget* QwtLegend::contentsWidget() const 386 { 387 return m_data->view->contentsWidget; 388 } 389 390 /*! 391 \brief Update the entries for an item 392 393 \param itemInfo Info for an item 394 \param legendData List of legend entry attributes for the item 395 */ 396 void QwtLegend::updateLegend( const QVariant& itemInfo, 397 const QList< QwtLegendData >& legendData ) 398 { 399 QList< QWidget* > widgetList = legendWidgets( itemInfo ); 396 400 397 401 if ( widgetList.size() != legendData.size() ) 398 402 { 399 QLayout *contentsLayout =d_data->view->contentsWidget->layout();403 QLayout* contentsLayout = m_data->view->contentsWidget->layout(); 400 404 401 405 while ( widgetList.size() > legendData.size() ) 402 406 { 403 QWidget *w = widgetList.takeLast();407 QWidget* w = widgetList.takeLast(); 404 408 405 409 contentsLayout->removeWidget( w ); … … 412 416 } 413 417 414 #if QT_VERSION >= 0x040700415 418 widgetList.reserve( legendData.size() ); 416 #endif417 419 418 420 for ( int i = widgetList.size(); i < legendData.size(); i++ ) 419 421 { 420 QWidget *widget = createWidget( legendData[i] );422 QWidget* widget = createWidget( legendData[i] ); 421 423 422 424 if ( contentsLayout ) … … 438 440 if ( widgetList.isEmpty() ) 439 441 { 440 d_data->itemMap.remove( itemInfo );442 m_data->itemMap.remove( itemInfo ); 441 443 } 442 444 else 443 445 { 444 d_data->itemMap.insert( itemInfo, widgetList );446 m_data->itemMap.insert( itemInfo, widgetList ); 445 447 } 446 448 … … 453 455 454 456 /*! 455 \brief Create a widget to be inserted into the legend 456 457 The default implementation returns a QwtLegendLabel. 458 459 \param legendData Attributes of the legend entry 460 \return Widget representing data on the legend 461 462 \note updateWidget() will called soon after createWidget() 457 \brief Create a widget to be inserted into the legend 458 459 The default implementation returns a QwtLegendLabel. 460 461 \param legendData Attributes of the legend entry 462 \return Widget representing data on the legend 463 464 \note updateWidget() will called soon after createWidget() 463 465 with the same attributes. 464 466 */ 465 QWidget *QwtLegend::createWidget( const QwtLegendData&legendData ) const467 QWidget* QwtLegend::createWidget( const QwtLegendData& legendData ) const 466 468 { 467 469 Q_UNUSED( legendData ); 468 470 469 QwtLegendLabel *label = new QwtLegendLabel();471 QwtLegendLabel* label = new QwtLegendLabel(); 470 472 label->setItemMode( defaultItemMode() ); 471 473 … … 477 479 478 480 /*! 479 \brief Update the widget 480 481 \param widget Usually a QwtLegendLabel 482 \param legendData Attributes to be displayed 483 484 \sa createWidget() 485 \note When widget is no QwtLegendLabel updateWidget() does nothing. 486 */ 487 void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData&legendData )488 { 489 QwtLegendLabel *label = qobject_cast<QwtLegendLabel*>( widget );481 \brief Update the widget 482 483 \param widget Usually a QwtLegendLabel 484 \param legendData Attributes to be displayed 485 486 \sa createWidget() 487 \note When widget is no QwtLegendLabel updateWidget() does nothing. 488 */ 489 void QwtLegend::updateWidget( QWidget* widget, const QwtLegendData& legendData ) 490 { 491 QwtLegendLabel* label = qobject_cast< QwtLegendLabel* >( widget ); 490 492 if ( label ) 491 493 { … … 503 505 void QwtLegend::updateTabOrder() 504 506 { 505 QLayout *contentsLayout =d_data->view->contentsWidget->layout();507 QLayout* contentsLayout = m_data->view->contentsWidget->layout(); 506 508 if ( contentsLayout ) 507 509 { 508 510 // set tab focus chain 509 511 510 QWidget *w = NULL;512 QWidget* w = NULL; 511 513 512 514 for ( int i = 0; i < contentsLayout->count(); i++ ) 513 515 { 514 QLayoutItem *item = contentsLayout->itemAt( i );516 QLayoutItem* item = contentsLayout->itemAt( i ); 515 517 if ( w && item->widget() ) 516 518 QWidget::setTabOrder( w, item->widget() ); … … 524 526 QSize QwtLegend::sizeHint() const 525 527 { 526 QSize hint = d_data->view->contentsWidget->sizeHint();528 QSize hint = m_data->view->contentsWidget->sizeHint(); 527 529 hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); 528 530 … … 531 533 532 534 /*! 533 \return The preferred height, for a width. 534 \param width Width 535 */ 535 \return The preferred height, for a width. 536 \param width Width 537 */ 536 538 int QwtLegend::heightForWidth( int width ) const 537 539 { 538 540 width -= 2 * frameWidth(); 539 541 540 int h = d_data->view->contentsWidget->heightForWidth( width );542 int h = m_data->view->contentsWidget->heightForWidth( width ); 541 543 if ( h >= 0 ) 542 544 h += 2 * frameWidth(); … … 547 549 548 550 /*! 549 Handle QEvent::ChildRemoved andQEvent::LayoutRequest events 550 for the contentsWidget(). 551 552 \param object Object to be filtered 553 \param event Event 554 555 \return Forwarded to QwtAbstractLegend::eventFilter() 556 */ 557 bool QwtLegend::eventFilter( QObject *object, QEvent*event )558 { 559 if ( object == d_data->view->contentsWidget )551 Handle QEvent::ChildRemoved and QEvent::LayoutRequest events 552 for the contentsWidget(). 553 554 \param object Object to be filtered 555 \param event Event 556 557 \return Forwarded to QwtAbstractLegend::eventFilter() 558 */ 559 bool QwtLegend::eventFilter( QObject* object, QEvent* event ) 560 { 561 if ( object == m_data->view->contentsWidget ) 560 562 { 561 563 switch ( event->type() ) … … 563 565 case QEvent::ChildRemoved: 564 566 { 565 const QChildEvent *ce =566 static_cast<const QChildEvent *>(event);567 const QChildEvent* ce = 568 static_cast< const QChildEvent* >( event ); 567 569 568 570 if ( ce->child()->isWidgetType() ) … … 573 575 to remove it from the map. 574 576 */ 575 QWidget *w = reinterpret_cast< QWidget* >( ce->child() );576 d_data->itemMap.removeWidget( w );577 QWidget* w = reinterpret_cast< QWidget* >( ce->child() ); 578 m_data->itemMap.removeWidget( w ); 577 579 } 578 580 break; … … 580 582 case QEvent::LayoutRequest: 581 583 { 582 d_data->view->layoutContents();584 m_data->view->layoutContents(); 583 585 584 586 if ( parentWidget() && parentWidget()->layout() == NULL ) … … 609 611 610 612 /*! 611 Called internally when the legend has been clicked on. 612 Emits a clicked() signal. 613 */ 613 Called internally when the legend has been clicked on. 614 Emits a clicked() signal. 615 */ 614 616 void QwtLegend::itemClicked() 615 617 { 616 QWidget *w = qobject_cast<QWidget*>( sender() );618 QWidget* w = qobject_cast< QWidget* >( sender() ); 617 619 if ( w ) 618 620 { 619 const QVariant itemInfo = d_data->itemMap.itemInfo( w );621 const QVariant itemInfo = m_data->itemMap.itemInfo( w ); 620 622 if ( itemInfo.isValid() ) 621 623 { 622 const QList<QWidget *> widgetList =623 d_data->itemMap.legendWidgets( itemInfo );624 const QList< QWidget* > widgetList = 625 m_data->itemMap.legendWidgets( itemInfo ); 624 626 625 627 const int index = widgetList.indexOf( w ); … … 631 633 632 634 /*! 633 Called internally when the legend has been checked 634 Emits a checked() signal. 635 */ 635 Called internally when the legend has been checked 636 Emits a checked() signal. 637 */ 636 638 void QwtLegend::itemChecked( bool on ) 637 639 { 638 QWidget *w = qobject_cast<QWidget*>( sender() );640 QWidget* w = qobject_cast< QWidget* >( sender() ); 639 641 if ( w ) 640 642 { 641 const QVariant itemInfo = d_data->itemMap.itemInfo( w );643 const QVariant itemInfo = m_data->itemMap.itemInfo( w ); 642 644 if ( itemInfo.isValid() ) 643 645 { 644 const QList<QWidget *> widgetList =645 d_data->itemMap.legendWidgets( itemInfo );646 const QList< QWidget* > widgetList = 647 m_data->itemMap.legendWidgets( itemInfo ); 646 648 647 649 const int index = widgetList.indexOf( w ); … … 653 655 654 656 /*! 655 Render the legend into a given rectangle. 656 657 \param painter Painter 658 \param rect Bounding rectangle 659 \param fillBackground When true, fill rect with the widget background 660 661 \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself 662 */ 663 void QwtLegend::renderLegend( QPainter *painter,664 const QRectF &rect, bool fillBackground ) const665 { 666 if ( d_data->itemMap.isEmpty() )657 Render the legend into a given rectangle. 658 659 \param painter Painter 660 \param rect Bounding rectangle 661 \param fillBackground When true, fill rect with the widget background 662 663 \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself 664 */ 665 void QwtLegend::renderLegend( QPainter* painter, 666 const QRectF& rect, bool fillBackground ) const 667 { 668 if ( m_data->itemMap.isEmpty() ) 667 669 return; 668 670 … … 676 678 } 677 679 678 const QwtDynGridLayout *legendLayout =679 qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );680 const QwtDynGridLayout* legendLayout = 681 qobject_cast< QwtDynGridLayout* >( contentsWidget()->layout() ); 680 682 if ( legendLayout == NULL ) 681 683 return; 682 684 683 int left, right, top, bottom; 684 getContentsMargins( &left, &top, &right, &bottom ); 685 const QMargins m = contentsMargins(); 685 686 686 687 QRect layoutRect; 687 layoutRect.setLeft( qCeil( rect.left() ) + left);688 layoutRect.setTop( qCeil( rect.top() ) + top);689 layoutRect.setRight( qFloor( rect.right() ) - right);690 layoutRect.setBottom( qFloor( rect.bottom() ) - bottom);688 layoutRect.setLeft( qwtCeil( rect.left() ) + m.left() ); 689 layoutRect.setTop( qwtCeil( rect.top() ) + m.top() ); 690 layoutRect.setRight( qwtFloor( rect.right() ) - m.right() ); 691 layoutRect.setBottom( qwtFloor( rect.bottom() ) - m.bottom() ); 691 692 692 693 uint numCols = legendLayout->columnsForWidth( layoutRect.width() ); 693 const QList< QRect> itemRects =694 const QList< QRect > itemRects = 694 695 legendLayout->layoutItems( layoutRect, numCols ); 695 696 … … 698 699 for ( int i = 0; i < legendLayout->count(); i++ ) 699 700 { 700 QLayoutItem *item = legendLayout->itemAt( i );701 QWidget *w = item->widget();701 QLayoutItem* item = legendLayout->itemAt( i ); 702 QWidget* w = item->widget(); 702 703 if ( w ) 703 704 { … … 714 715 715 716 /*! 716 Render a legend entry into a given rectangle. 717 718 \param painter Painter 719 \param widget Widget representing a legend entry 720 \param rect Bounding rectangle 721 \param fillBackground When true, fill rect with the widget background 722 723 \note When widget is not derived from QwtLegendLabel renderItem 717 Render a legend entry into a given rectangle. 718 719 \param painter Painter 720 \param widget Widget representing a legend entry 721 \param rect Bounding rectangle 722 \param fillBackground When true, fill rect with the widget background 723 724 \note When widget is not derived from QwtLegendLabel renderItem 724 725 does nothing beside the background 725 */ 726 void QwtLegend::renderItem( QPainter *painter,727 const QWidget *widget, const QRectF&rect, bool fillBackground ) const726 */ 727 void QwtLegend::renderItem( QPainter* painter, 728 const QWidget* widget, const QRectF& rect, bool fillBackground ) const 728 729 { 729 730 if ( fillBackground ) … … 736 737 } 737 738 738 const QwtLegendLabel *label = qobject_cast<const QwtLegendLabel*>( widget );739 const QwtLegendLabel* label = qobject_cast< const QwtLegendLabel* >( widget ); 739 740 if ( label ) 740 741 { 741 742 // icon 742 743 743 const QwtGraphic &icon = label->data().icon();744 const QwtGraphic& icon = label->data().icon(); 744 745 const QSizeF sz = icon.defaultSize(); 745 746 … … 756 757 757 758 QFont labelFont = label->font(); 759 #if QT_VERSION >= 0x060000 760 labelFont.setResolveMask( QFont::AllPropertiesResolved ); 761 #else 758 762 labelFont.resolve( QFont::AllPropertiesResolved ); 763 #endif 759 764 760 765 painter->setFont( labelFont ); 761 766 painter->setPen( label->palette().color( QPalette::Text ) ); 762 767 763 const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect );764 } 765 } 766 767 /*! 768 \return List of widgets associated to a item 769 \param itemInfo Info about an item 770 \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo() 771 */ 772 QList<QWidget *> QwtLegend::legendWidgets( const QVariant&itemInfo ) const773 { 774 return d_data->itemMap.legendWidgets( itemInfo );775 } 776 777 /*! 778 \return First widget in the list of widgets associated to an item 779 \param itemInfo Info about an item 780 \sa itemInfo(), QwtPlot::itemToInfo() 781 \note Almost all types of items have only one widget 782 */ 783 QWidget *QwtLegend::legendWidget( const QVariant&itemInfo ) const784 { 785 const QList<QWidget *> list =d_data->itemMap.legendWidgets( itemInfo );768 const_cast< QwtLegendLabel* >( label )->drawText( painter, titleRect ); 769 } 770 } 771 772 /*! 773 \return List of widgets associated to a item 774 \param itemInfo Info about an item 775 \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo() 776 */ 777 QList< QWidget* > QwtLegend::legendWidgets( const QVariant& itemInfo ) const 778 { 779 return m_data->itemMap.legendWidgets( itemInfo ); 780 } 781 782 /*! 783 \return First widget in the list of widgets associated to an item 784 \param itemInfo Info about an item 785 \sa itemInfo(), QwtPlot::itemToInfo() 786 \note Almost all types of items have only one widget 787 */ 788 QWidget* QwtLegend::legendWidget( const QVariant& itemInfo ) const 789 { 790 const QList< QWidget* > list = m_data->itemMap.legendWidgets( itemInfo ); 786 791 if ( list.isEmpty() ) 787 792 return NULL; … … 791 796 792 797 /*! 793 Find the item that is associated to a widget 794 795 \param widget Widget on the legend 796 \return Associated item info 797 \sa legendWidget() 798 */ 799 QVariant QwtLegend::itemInfo( const QWidget *widget ) const800 { 801 return d_data->itemMap.itemInfo( widget );798 Find the item that is associated to a widget 799 800 \param widget Widget on the legend 801 \return Associated item info 802 \sa legendWidget() 803 */ 804 QVariant QwtLegend::itemInfo( const QWidget* widget ) const 805 { 806 return m_data->itemMap.itemInfo( widget ); 802 807 } 803 808 … … 805 810 bool QwtLegend::isEmpty() const 806 811 { 807 return d_data->itemMap.isEmpty();812 return m_data->itemMap.isEmpty(); 808 813 } 809 814 … … 826 831 } 827 832 833 #include "moc_qwt_legend.cpp" -
trunk/BNC/qwt/qwt_legend.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_abstract_legend.h" 15 #include "qwt_legend_data.h" 16 15 17 #include <qvariant.h> 16 18 … … 18 20 19 21 /*! 20 \brief The legend widget 22 \brief The legend widget 21 23 22 The QwtLegend widget is a tabular arrangement of legend items. Legend 23 items might be any type of widget, but in general they will be 24 a QwtLegendLabel. 24 The QwtLegend widget is a tabular arrangement of legend items. Legend 25 items might be any type of widget, but in general they will be 26 a QwtLegendLabel. 25 27 26 \sa QwtLegendLabel, QwtPlotItem, QwtPlot 27 */ 28 \sa QwtLegendLabel, QwtPlotItem, QwtPlot 29 */ 28 30 29 31 class QWT_EXPORT QwtLegend : public QwtAbstractLegend … … 31 33 Q_OBJECT 32 34 33 public: 34 explicit QwtLegend( QWidget *parent = NULL );35 public: 36 explicit QwtLegend( QWidget* parent = NULL ); 35 37 virtual ~QwtLegend(); 36 38 … … 41 43 QwtLegendData::Mode defaultItemMode() const; 42 44 43 QWidget *contentsWidget();44 const QWidget *contentsWidget() const;45 QWidget* contentsWidget(); 46 const QWidget* contentsWidget() const; 45 47 46 QWidget *legendWidget( const QVariant& ) const;47 QList<QWidget *> legendWidgets( const QVariant& ) const;48 QWidget* legendWidget( const QVariant& ) const; 49 QList< QWidget* > legendWidgets( const QVariant& ) const; 48 50 49 QVariant itemInfo( const QWidget * ) const;51 QVariant itemInfo( const QWidget* ) const; 50 52 51 virtual bool eventFilter( QObject *, QEvent* );53 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 52 54 53 virtual QSize sizeHint() const; 54 virtual int heightForWidth( int w idth) const;55 virtual QSize sizeHint() const QWT_OVERRIDE; 56 virtual int heightForWidth( int w ) const QWT_OVERRIDE; 55 57 56 QScrollBar *horizontalScrollBar() const;57 QScrollBar *verticalScrollBar() const;58 QScrollBar* horizontalScrollBar() const; 59 QScrollBar* verticalScrollBar() const; 58 60 59 virtual void renderLegend( QPainter *,60 const QRectF &, bool fillBackground ) const;61 virtual void renderLegend( QPainter*, 62 const QRectF&, bool fillBackground ) const QWT_OVERRIDE; 61 63 62 virtual void renderItem( QPainter *,63 const QWidget *, const QRectF&, bool fillBackground ) const;64 virtual void renderItem( QPainter*, 65 const QWidget*, const QRectF&, bool fillBackground ) const; 64 66 65 virtual bool isEmpty() const; 66 virtual int scrollExtent( Qt::Orientation ) const; 67 virtual bool isEmpty() const QWT_OVERRIDE; 68 virtual int scrollExtent( Qt::Orientation ) const QWT_OVERRIDE; 67 69 68 Q_SIGNALS: 70 Q_SIGNALS: 69 71 /*! 70 A signal which is emitted when the user has clicked on 71 a legend label, which is in QwtLegendData::Clickable mode. 72 A signal which is emitted when the user has clicked on 73 a legend label, which is in QwtLegendData::Clickable mode. 72 74 73 \param itemInfo Info for the item item of the 75 \param itemInfo Info for the item item of the 74 76 selected legend item 75 \param index Index of the legend label in the list of widgets 77 \param index Index of the legend label in the list of widgets 76 78 that are associated with the plot item 77 79 78 \note clicks are disabled as default 79 \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo() 80 \note clicks are disabled as default 81 \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo() 80 82 */ 81 void clicked( const QVariant &itemInfo, int index );83 void clicked( const QVariant& itemInfo, int index ); 82 84 83 85 /*! 84 A signal which is emitted when the user has clicked on 85 a legend label, which is in QwtLegendData::Checkable mode 86 A signal which is emitted when the user has clicked on 87 a legend label, which is in QwtLegendData::Checkable mode 86 88 87 \param itemInfo Info for the item of the 89 \param itemInfo Info for the item of the 88 90 selected legend label 89 \param index Index of the legend label in the list of widgets 91 \param index Index of the legend label in the list of widgets 90 92 that are associated with the plot item 91 \param on True when the legend label is checked 93 \param on True when the legend label is checked 92 94 93 \note clicks are disabled as default 94 \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo() 95 \note clicks are disabled as default 96 \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo() 95 97 */ 96 void checked( const QVariant &itemInfo, bool on, int index );98 void checked( const QVariant& itemInfo, bool on, int index ); 97 99 98 public Q_SLOTS: 99 virtual void updateLegend( const QVariant &,100 const QList<QwtLegendData > & );100 public Q_SLOTS: 101 virtual void updateLegend( const QVariant&, 102 const QList< QwtLegendData >& ) QWT_OVERRIDE; 101 103 102 protected Q_SLOTS: 104 protected Q_SLOTS: 103 105 void itemClicked(); 104 106 void itemChecked( bool ); 105 107 106 protected: 107 virtual QWidget *createWidget( const QwtLegendData& ) const;108 virtual void updateWidget( QWidget *widget, const QwtLegendData& );108 protected: 109 virtual QWidget* createWidget( const QwtLegendData& ) const; 110 virtual void updateWidget( QWidget*, const QwtLegendData& ); 109 111 110 private: 112 private: 111 113 void updateTabOrder(); 112 114 113 115 class PrivateData; 114 PrivateData *d_data;116 PrivateData* m_data; 115 117 }; 116 118 -
trunk/BNC/qwt/qwt_legend_data.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_legend_data.h" 11 #include "qwt_text.h" 12 #include "qwt_graphic.h" 11 13 12 14 //! Constructor … … 21 23 22 24 /*! 23 Set the legend attributes 25 Set the legend attributes 24 26 25 QwtLegendData actually is a QMap<int, QVariant> with some 26 convenience interfaces 27 QwtLegendData actually is a QMap<int, QVariant> with some 28 convenience interfaces 27 29 28 \param map Values 29 \sa values() 30 \param map Values 31 \sa values() 30 32 */ 31 void QwtLegendData::setValues( const QMap<int, QVariant > &map )33 void QwtLegendData::setValues( const QMap< int, QVariant >& map ) 32 34 { 33 d_map = map;35 m_map = map; 34 36 } 35 37 36 38 /*! 37 \return Legend attributes 38 \sa setValues() 39 \return Legend attributes 40 \sa setValues() 39 41 */ 40 const QMap<int, QVariant > &QwtLegendData::values() const42 const QMap< int, QVariant >& QwtLegendData::values() const 41 43 { 42 return d_map;44 return m_map; 43 45 } 44 46 45 47 /*! 46 \param role Attribute role 47 \return True, when the internal map has an entry for role 48 \param role Attribute role 49 \return True, when the internal map has an entry for role 48 50 */ 49 51 bool QwtLegendData::hasRole( int role ) const 50 52 { 51 return d_map.contains( role );53 return m_map.contains( role ); 52 54 } 53 55 54 56 /*! 55 Set an attribute value 57 Set an attribute value 56 58 57 \param role Attribute role 58 \param data Attribute value 59 \param role Attribute role 60 \param data Attribute value 59 61 60 \sa value() 62 \sa value() 61 63 */ 62 void QwtLegendData::setValue( int role, const QVariant &data )64 void QwtLegendData::setValue( int role, const QVariant& data ) 63 65 { 64 d_map[role] = data;66 m_map[role] = data; 65 67 } 66 68 67 69 /*! 68 \param role Attribute role 69 \return Attribute value for a specific role 70 \param role Attribute role 71 \return Attribute value for a specific role 70 72 */ 71 73 QVariant QwtLegendData::value( int role ) const 72 74 { 73 if ( ! d_map.contains( role ) )75 if ( !m_map.contains( role ) ) 74 76 return QVariant(); 75 77 76 return d_map[role];78 return m_map[role]; 77 79 } 78 80 … … 80 82 bool QwtLegendData::isValid() const 81 83 { 82 return ! d_map.isEmpty();84 return !m_map.isEmpty(); 83 85 } 84 86 … … 89 91 90 92 const QVariant titleValue = value( QwtLegendData::TitleRole ); 91 if ( titleValue.canConvert< QwtText>() )93 if ( titleValue.canConvert< QwtText >() ) 92 94 { 93 text = qvariant_cast< QwtText>( titleValue );95 text = qvariant_cast< QwtText >( titleValue ); 94 96 } 95 else if ( titleValue.canConvert< QString>() )97 else if ( titleValue.canConvert< QString >() ) 96 98 { 97 text.setText( qvariant_cast< QString>( titleValue ) );99 text.setText( qvariant_cast< QString >( titleValue ) ); 98 100 } 99 101 … … 107 109 108 110 QwtGraphic graphic; 109 if ( iconValue.canConvert<QwtGraphic>() ) 111 if ( iconValue.canConvert< QwtGraphic >() ) 110 112 { 111 graphic = qvariant_cast<QwtGraphic>( iconValue ); 113 graphic = qvariant_cast< QwtGraphic >( iconValue ); 112 114 } 113 115 … … 119 121 { 120 122 const QVariant modeValue = value( QwtLegendData::ModeRole ); 121 if ( modeValue.canConvert< int>() )123 if ( modeValue.canConvert< int >() ) 122 124 { 123 const int mode = qvariant_cast< int>( modeValue );124 return static_cast<QwtLegendData::Mode>( mode ); 125 const int mode = qvariant_cast< int >( modeValue ); 126 return static_cast< QwtLegendData::Mode >( mode ); 125 127 } 126 128 -
trunk/BNC/qwt/qwt_legend_data.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_text.h" 15 #include "qwt_graphic.h" 14 16 15 #include <qvariant.h> 17 #include <qpixmap.h>18 16 #include <qmap.h> 19 17 18 class QwtText; 19 class QwtGraphic; 20 20 21 /*! 21 \brief Attributes of an entry on a legend 22 \brief Attributes of an entry on a legend 22 23 23 QwtLegendData is an abstract container ( like QAbstractModel ) 24 to exchange attributes, that are only known between to 25 the plot item and the legend. 24 QwtLegendData is an abstract container ( like QAbstractModel ) 25 to exchange attributes, that are only known between to 26 the plot item and the legend. 26 27 27 By overloading QwtPlotItem::legendData() any other set of attributes 28 could be used, that can be handled by a modified ( or completely 29 different ) implementation of a legend. 28 By overloading QwtPlotItem::legendData() any other set of attributes 29 could be used, that can be handled by a modified ( or completely 30 different ) implementation of a legend. 30 31 31 \sa QwtLegend, QwtPlotLegendItem 32 \note The stockchart example implements a legend as a tree 32 \sa QwtLegend, QwtPlotLegendItem 33 \note The stockchart example implements a legend as a tree 33 34 with checkable items 34 35 */ 35 36 class QWT_EXPORT QwtLegendData 36 37 { 37 public: 38 public: 38 39 //! Mode defining how a legend entry interacts 39 40 enum Mode … … 49 50 }; 50 51 51 //! Identifier how to interpret ea QVariant52 //! Identifier how to interpret a QVariant 52 53 enum Role 53 54 { … … 68 69 ~QwtLegendData(); 69 70 70 void setValues( const QMap<int, QVariant >& );71 const QMap<int, QVariant > &values() const;71 void setValues( const QMap< int, QVariant >& ); 72 const QMap< int, QVariant >& values() const; 72 73 73 void setValue( int role, const QVariant & );74 void setValue( int role, const QVariant& ); 74 75 QVariant value( int role ) const; 75 76 … … 81 82 Mode mode() const; 82 83 83 private: 84 QMap<int, QVariant > d_map;84 private: 85 QMap< int, QVariant > m_map; 85 86 }; 86 87 -
trunk/BNC/qwt/qwt_legend_label.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_legend_label.h" 11 11 #include "qwt_legend_data.h" 12 #include "qwt_ math.h"12 #include "qwt_graphic.h" 13 13 #include "qwt_painter.h" 14 #include "qwt _symbol.h"15 #include "qwt_graphic.h" 14 #include "qwt.h" 15 16 16 #include <qpainter.h> 17 17 #include <qdrawutil.h> 18 18 #include <qstyle.h> 19 #include <qpen.h>20 19 #include <qevent.h> 21 20 #include <qstyleoption.h> 22 #include <qapplication.h>23 21 24 22 static const int ButtonFrame = 2; 25 23 static const int Margin = 2; 26 24 27 static QSize buttonShift( const QwtLegendLabel *w )25 static QSize buttonShift( const QwtLegendLabel* w ) 28 26 { 29 27 QStyleOption option; 30 option.init( w ); 28 option.initFrom( w ); 31 29 32 30 const int ph = w->style()->pixelMetric( … … 39 37 class QwtLegendLabel::PrivateData 40 38 { 41 public: 42 PrivateData() :43 itemMode( QwtLegendData::ReadOnly ) ,44 isDown( false ) ,45 spacing( Margin ) 39 public: 40 PrivateData() 41 : itemMode( QwtLegendData::ReadOnly ) 42 , isDown( false ) 43 , spacing( Margin ) 46 44 { 47 45 } … … 57 55 58 56 /*! 59 Set the attributes of the legend label 60 61 \param legendData Attributes of the label 62 \sa data() 63 */ 64 void QwtLegendLabel::setData( const QwtLegendData &legendData )65 { 66 d_data->legendData = legendData;57 Set the attributes of the legend label 58 59 \param legendData Attributes of the label 60 \sa data() 61 */ 62 void QwtLegendLabel::setData( const QwtLegendData& legendData ) 63 { 64 m_data->legendData = legendData; 67 65 68 66 const bool doUpdate = updatesEnabled(); 69 setUpdatesEnabled( false ); 67 if ( doUpdate ) 68 setUpdatesEnabled( false ); 70 69 71 70 setText( legendData.title() ); … … 76 75 77 76 if ( doUpdate ) 78 {79 77 setUpdatesEnabled( true ); 80 update(); 81 } 82 } 83 84 /*! 85 \return Attributes of the label 86 \sa setData(), QwtPlotItem::legendData() 87 */ 88 const QwtLegendData &QwtLegendLabel::data() const 89 { 90 return d_data->legendData; 91 } 92 93 /*! 94 \param parent Parent widget 95 */ 96 QwtLegendLabel::QwtLegendLabel( QWidget *parent ): 97 QwtTextLabel( parent ) 98 { 99 d_data = new PrivateData; 78 } 79 80 /*! 81 \return Attributes of the label 82 \sa setData(), QwtPlotItem::legendData() 83 */ 84 const QwtLegendData& QwtLegendLabel::data() const 85 { 86 return m_data->legendData; 87 } 88 89 /*! 90 \param parent Parent widget 91 */ 92 QwtLegendLabel::QwtLegendLabel( QWidget* parent ) 93 : QwtTextLabel( parent ) 94 { 95 m_data = new PrivateData; 100 96 setMargin( Margin ); 101 97 setIndent( Margin ); … … 105 101 QwtLegendLabel::~QwtLegendLabel() 106 102 { 107 delete d_data;108 d_data = NULL;103 delete m_data; 104 m_data = NULL; 109 105 } 110 106 … … 114 110 \param text Text label 115 111 \sa QwtTextLabel::text() 116 */ 117 void QwtLegendLabel::setText( const QwtText &text )112 */ 113 void QwtLegendLabel::setText( const QwtText& text ) 118 114 { 119 115 const int flags = Qt::AlignLeft | Qt::AlignVCenter … … 132 128 \param mode Item mode 133 129 \sa itemMode() 134 */ 130 */ 135 131 void QwtLegendLabel::setItemMode( QwtLegendData::Mode mode ) 136 132 { 137 if ( mode != d_data->itemMode )138 { 139 d_data->itemMode = mode;140 d_data->isDown = false;133 if ( mode != m_data->itemMode ) 134 { 135 m_data->itemMode = mode; 136 m_data->isDown = false; 141 137 142 138 setFocusPolicy( ( mode != QwtLegendData::ReadOnly ) … … 151 147 \return Item mode 152 148 \sa setItemMode() 153 */ 149 */ 154 150 QwtLegendData::Mode QwtLegendLabel::itemMode() const 155 151 { 156 return d_data->itemMode;157 } 158 159 /*! 160 Assign the icon 161 162 \param icon Pixmap representing a plot item 163 164 \sa icon(), QwtPlotItem::legendIcon() 165 */ 166 void QwtLegendLabel::setIcon( const QPixmap &icon )167 { 168 d_data->icon = icon;169 170 int indent = margin() + d_data->spacing;152 return m_data->itemMode; 153 } 154 155 /*! 156 Assign the icon 157 158 \param icon Pixmap representing a plot item 159 160 \sa icon(), QwtPlotItem::legendIcon() 161 */ 162 void QwtLegendLabel::setIcon( const QPixmap& icon ) 163 { 164 m_data->icon = icon; 165 166 int indent = margin() + m_data->spacing; 171 167 if ( icon.width() > 0 ) 172 indent += icon.width() + d_data->spacing; 168 { 169 const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &icon ); 170 indent += icon.width() / devicePixelRatio + m_data->spacing; 171 } 173 172 174 173 setIndent( indent ); … … 176 175 177 176 /*! 178 \return Pixmap representing a plot item 179 \sa setIcon() 180 */ 177 \return Pixmap representing a plot item 178 \sa setIcon() 179 */ 181 180 QPixmap QwtLegendLabel::icon() const 182 181 { 183 return d_data->icon;182 return m_data->icon; 184 183 } 185 184 … … 189 188 \param spacing Spacing 190 189 \sa spacing(), QwtTextLabel::margin() 191 */ 190 */ 192 191 void QwtLegendLabel::setSpacing( int spacing ) 193 192 { 194 193 spacing = qMax( spacing, 0 ); 195 if ( spacing != d_data->spacing )196 { 197 d_data->spacing = spacing;198 199 int indent = margin() + d_data->spacing;200 if ( d_data->icon.width() > 0 )201 indent += d_data->icon.width() +d_data->spacing;194 if ( spacing != m_data->spacing ) 195 { 196 m_data->spacing = spacing; 197 198 int indent = margin() + m_data->spacing; 199 if ( m_data->icon.width() > 0 ) 200 indent += m_data->icon.width() + m_data->spacing; 202 201 203 202 setIndent( indent ); … … 208 207 \return Spacing between icon and text 209 208 \sa setSpacing(), QwtTextLabel::margin() 210 */ 209 */ 211 210 int QwtLegendLabel::spacing() const 212 211 { 213 return d_data->spacing;212 return m_data->spacing; 214 213 } 215 214 … … 219 218 \param on check/uncheck 220 219 \sa setItemMode() 221 */ 220 */ 222 221 void QwtLegendLabel::setChecked( bool on ) 223 222 { 224 if ( d_data->itemMode == QwtLegendData::Checkable )223 if ( m_data->itemMode == QwtLegendData::Checkable ) 225 224 { 226 225 const bool isBlocked = signalsBlocked(); … … 236 235 bool QwtLegendLabel::isChecked() const 237 236 { 238 return d_data->itemMode == QwtLegendData::Checkable && isDown();237 return m_data->itemMode == QwtLegendData::Checkable && isDown(); 239 238 } 240 239 … … 242 241 void QwtLegendLabel::setDown( bool down ) 243 242 { 244 if ( down == d_data->isDown )243 if ( down == m_data->isDown ) 245 244 return; 246 245 247 d_data->isDown = down;246 m_data->isDown = down; 248 247 update(); 249 248 250 if ( d_data->itemMode == QwtLegendData::Clickable )251 { 252 if ( d_data->isDown )249 if ( m_data->itemMode == QwtLegendData::Clickable ) 250 { 251 if ( m_data->isDown ) 253 252 Q_EMIT pressed(); 254 253 else … … 259 258 } 260 259 261 if ( d_data->itemMode == QwtLegendData::Checkable )262 Q_EMIT checked( d_data->isDown );260 if ( m_data->itemMode == QwtLegendData::Checkable ) 261 Q_EMIT checked( m_data->isDown ); 263 262 } 264 263 … … 266 265 bool QwtLegendLabel::isDown() const 267 266 { 268 return d_data->isDown;267 return m_data->isDown; 269 268 } 270 269 … … 273 272 { 274 273 QSize sz = QwtTextLabel::sizeHint(); 275 sz.setHeight( qMax( sz.height(), d_data->icon.height() + 4 ) );276 277 if ( d_data->itemMode != QwtLegendData::ReadOnly )274 sz.setHeight( qMax( sz.height(), m_data->icon.height() + 4 ) ); 275 276 if ( m_data->itemMode != QwtLegendData::ReadOnly ) 278 277 { 279 278 sz += buttonShift( this ); 280 sz = sz.expandedTo( QApplication::globalStrut());279 sz = qwtExpandedToGlobalStrut( sz ); 281 280 } 282 281 … … 285 284 286 285 //! Paint event 287 void QwtLegendLabel::paintEvent( QPaintEvent *e )286 void QwtLegendLabel::paintEvent( QPaintEvent* e ) 288 287 { 289 288 const QRect cr = contentsRect(); … … 292 291 painter.setClipRegion( e->region() ); 293 292 294 if ( d_data->isDown )293 if ( m_data->isDown ) 295 294 { 296 295 qDrawWinButton( &painter, 0, 0, width(), height(), … … 300 299 painter.save(); 301 300 302 if ( d_data->isDown )301 if ( m_data->isDown ) 303 302 { 304 303 const QSize shiftSize = buttonShift( this ); … … 310 309 drawContents( &painter ); 311 310 312 if ( ! d_data->icon.isNull() )311 if ( !m_data->icon.isNull() ) 313 312 { 314 313 QRect iconRect = cr; 315 314 iconRect.setX( iconRect.x() + margin() ); 316 if ( d_data->itemMode != QwtLegendData::ReadOnly )315 if ( m_data->itemMode != QwtLegendData::ReadOnly ) 317 316 iconRect.setX( iconRect.x() + ButtonFrame ); 318 317 319 iconRect.setSize( d_data->icon.size() ); 318 const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &m_data->icon ); 319 iconRect.setSize( m_data->icon.size() / devicePixelRatio ); 320 320 iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) ); 321 321 322 painter.drawPixmap( iconRect, d_data->icon );322 painter.drawPixmap( iconRect, m_data->icon ); 323 323 } 324 324 … … 327 327 328 328 //! Handle mouse press events 329 void QwtLegendLabel::mousePressEvent( QMouseEvent *e )329 void QwtLegendLabel::mousePressEvent( QMouseEvent* e ) 330 330 { 331 331 if ( e->button() == Qt::LeftButton ) 332 332 { 333 switch ( d_data->itemMode )333 switch ( m_data->itemMode ) 334 334 { 335 335 case QwtLegendData::Clickable: … … 350 350 351 351 //! Handle mouse release events 352 void QwtLegendLabel::mouseReleaseEvent( QMouseEvent *e )352 void QwtLegendLabel::mouseReleaseEvent( QMouseEvent* e ) 353 353 { 354 354 if ( e->button() == Qt::LeftButton ) 355 355 { 356 switch ( d_data->itemMode )356 switch ( m_data->itemMode ) 357 357 { 358 358 case QwtLegendData::Clickable: … … 372 372 373 373 //! Handle key press events 374 void QwtLegendLabel::keyPressEvent( QKeyEvent *e )374 void QwtLegendLabel::keyPressEvent( QKeyEvent* e ) 375 375 { 376 376 if ( e->key() == Qt::Key_Space ) 377 377 { 378 switch ( d_data->itemMode )378 switch ( m_data->itemMode ) 379 379 { 380 380 case QwtLegendData::Clickable: … … 398 398 399 399 //! Handle key release events 400 void QwtLegendLabel::keyReleaseEvent( QKeyEvent *e )400 void QwtLegendLabel::keyReleaseEvent( QKeyEvent* e ) 401 401 { 402 402 if ( e->key() == Qt::Key_Space ) 403 403 { 404 switch ( d_data->itemMode )404 switch ( m_data->itemMode ) 405 405 { 406 406 case QwtLegendData::Clickable: … … 420 420 QwtTextLabel::keyReleaseEvent( e ); 421 421 } 422 423 #include "moc_qwt_legend_label.cpp" -
trunk/BNC/qwt/qwt_legend_label.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_text_label.h" 14 15 #include "qwt_legend_data.h" 15 #include "qwt_text.h"16 #include "qwt_text_label.h"17 #include <qpixmap.h>18 16 19 class Qwt LegendData;17 class QwtText; 20 18 21 19 /*! 22 \brief A widget representing something on a QwtLegend. 23 */ 24 class QWT_EXPORT QwtLegendLabel: public QwtTextLabel 20 \brief A widget representing something on a QwtLegend. 21 */ 22 class QWT_EXPORT QwtLegendLabel : public QwtTextLabel 25 23 { 26 24 Q_OBJECT 27 public: 28 explicit QwtLegendLabel( QWidget *parent = 0 );25 public: 26 explicit QwtLegendLabel( QWidget* parent = 0 ); 29 27 virtual ~QwtLegendLabel(); 30 28 31 void setData( const QwtLegendData & );32 const QwtLegendData &data() const;29 void setData( const QwtLegendData& ); 30 const QwtLegendData& data() const; 33 31 34 32 void setItemMode( QwtLegendData::Mode ); … … 38 36 int spacing() const; 39 37 40 virtual void setText( const QwtText & );38 virtual void setText( const QwtText& ) QWT_OVERRIDE; 41 39 42 void setIcon( const QPixmap & );40 void setIcon( const QPixmap& ); 43 41 QPixmap icon() const; 44 42 45 virtual QSize sizeHint() const; 43 virtual QSize sizeHint() const QWT_OVERRIDE; 46 44 47 45 bool isChecked() const; 48 46 49 public Q_SLOTS: 47 public Q_SLOTS: 50 48 void setChecked( bool on ); 51 49 52 Q_SIGNALS: 50 Q_SIGNALS: 53 51 //! Signal, when the legend item has been clicked 54 52 void clicked(); … … 63 61 void checked( bool ); 64 62 65 protected: 63 protected: 66 64 void setDown( bool ); 67 65 bool isDown() const; 68 66 69 virtual void paintEvent( QPaintEvent * );70 virtual void mousePressEvent( QMouseEvent * );71 virtual void mouseReleaseEvent( QMouseEvent * );72 virtual void keyPressEvent( QKeyEvent * );73 virtual void keyReleaseEvent( QKeyEvent * );67 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 68 virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE; 69 virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE; 70 virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 71 virtual void keyReleaseEvent( QKeyEvent* ) QWT_OVERRIDE; 74 72 75 private: 73 private: 76 74 class PrivateData; 77 PrivateData *d_data;75 PrivateData* m_data; 78 76 }; 79 77 -
trunk/BNC/qwt/qwt_magnifier.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_magnifier.h" 11 11 #include "qwt_math.h" 12 12 13 #include <qevent.h> 13 14 #include <qwidget.h> … … 15 16 class QwtMagnifier::PrivateData 16 17 { 17 public: 18 PrivateData(): 19 isEnabled( false ), 20 wheelFactor( 0.9 ), 21 wheelModifiers( Qt::NoModifier ), 22 mouseFactor( 0.95 ), 23 mouseButton( Qt::RightButton ), 24 mouseButtonModifiers( Qt::NoModifier ), 25 keyFactor( 0.9 ), 26 zoomInKey( Qt::Key_Plus ), 27 zoomInKeyModifiers( Qt::NoModifier ), 28 zoomOutKey( Qt::Key_Minus ), 29 zoomOutKeyModifiers( Qt::NoModifier ), 30 mousePressed( false ) 18 public: 19 PrivateData() 20 : isEnabled( false ) 21 , wheelFactor( 0.9 ) 22 , wheelModifiers( Qt::NoModifier ) 23 , mouseFactor( 0.95 ) 24 , mouseButton( Qt::RightButton ) 25 , mouseButtonModifiers( Qt::NoModifier ) 26 , keyFactor( 0.9 ) 27 , zoomInKey( Qt::Key_Plus ) 28 , zoomInKeyModifiers( Qt::NoModifier ) 29 , zoomOutKey( Qt::Key_Minus ) 30 , zoomOutKeyModifiers( Qt::NoModifier ) 31 , mousePressed( false ) 32 , hasMouseTracking( false ) 31 33 { 32 34 } … … 48 50 49 51 int zoomOutKey; 50 Qt::KeyboardModifiers zoomOutKeyModifiers;52 Qt::KeyboardModifiers zoomOutKeyModifiers; 51 53 52 54 bool mousePressed; … … 58 60 Constructor 59 61 \param parent Widget to be magnified 60 */ 61 QwtMagnifier::QwtMagnifier( QWidget *parent ): 62 QObject( parent ) 63 { 64 d_data = new PrivateData(); 62 */ 63 QwtMagnifier::QwtMagnifier( QWidget* parent ) 64 : QObject( parent ) 65 { 66 m_data = new PrivateData(); 67 68 if ( parent ) 69 { 70 if ( parent->focusPolicy() == Qt::NoFocus ) 71 parent->setFocusPolicy( Qt::WheelFocus ); 72 } 73 65 74 setEnabled( true ); 66 75 } … … 69 78 QwtMagnifier::~QwtMagnifier() 70 79 { 71 delete d_data;72 } 73 74 /*! 75 \brief En/disable the magnifier 76 77 When enabled is true an event filter is installed for 78 the observed widget, otherwise the event filter is removed. 79 80 \param on true or false 81 \sa isEnabled(), eventFilter() 82 */ 80 delete m_data; 81 } 82 83 /*! 84 \brief En/disable the magnifier 85 86 When enabled is true an event filter is installed for 87 the observed widget, otherwise the event filter is removed. 88 89 \param on true or false 90 \sa isEnabled(), eventFilter() 91 */ 83 92 void QwtMagnifier::setEnabled( bool on ) 84 93 { 85 if ( d_data->isEnabled != on )86 { 87 d_data->isEnabled = on;88 89 QObject *o = parent();94 if ( m_data->isEnabled != on ) 95 { 96 m_data->isEnabled = on; 97 98 QObject* o = parent(); 90 99 if ( o ) 91 100 { 92 if ( d_data->isEnabled )101 if ( m_data->isEnabled ) 93 102 o->installEventFilter( this ); 94 103 else … … 99 108 100 109 /*! 101 \return true when enabled, false otherwise 102 \sa setEnabled(), eventFilter() 103 */ 110 \return true when enabled, false otherwise 111 \sa setEnabled(), eventFilter() 112 */ 104 113 bool QwtMagnifier::isEnabled() const 105 114 { 106 return d_data->isEnabled;115 return m_data->isEnabled; 107 116 } 108 117 … … 122 131 \sa wheelFactor(), setWheelButtonState(), 123 132 setMouseFactor(), setKeyFactor() 124 */ 133 */ 125 134 void QwtMagnifier::setWheelFactor( double factor ) 126 135 { 127 d_data->wheelFactor = factor;136 m_data->wheelFactor = factor; 128 137 } 129 138 … … 131 140 \return Wheel factor 132 141 \sa setWheelFactor() 133 */ 142 */ 134 143 double QwtMagnifier::wheelFactor() const 135 144 { 136 return d_data->wheelFactor;145 return m_data->wheelFactor; 137 146 } 138 147 … … 143 152 \param modifiers Keyboard modifiers 144 153 \sa wheelModifiers() 145 */ 154 */ 146 155 void QwtMagnifier::setWheelModifiers( Qt::KeyboardModifiers modifiers ) 147 156 { 148 d_data->wheelModifiers = modifiers;157 m_data->wheelModifiers = modifiers; 149 158 } 150 159 … … 152 161 \return Wheel modifiers 153 162 \sa setWheelModifiers() 154 */ 163 */ 155 164 Qt::KeyboardModifiers QwtMagnifier::wheelModifiers() const 156 165 { 157 return d_data->wheelModifiers;166 return m_data->wheelModifiers; 158 167 } 159 168 … … 167 176 \param factor Wheel factor 168 177 \sa mouseFactor(), setMouseButton(), setWheelFactor(), setKeyFactor() 169 */ 178 */ 170 179 void QwtMagnifier::setMouseFactor( double factor ) 171 180 { 172 d_data->mouseFactor = factor;181 m_data->mouseFactor = factor; 173 182 } 174 183 … … 176 185 \return Mouse factor 177 186 \sa setMouseFactor() 178 */ 187 */ 179 188 double QwtMagnifier::mouseFactor() const 180 189 { 181 return d_data->mouseFactor;190 return m_data->mouseFactor; 182 191 } 183 192 … … 190 199 191 200 \sa getMouseButton() 192 */ 201 */ 193 202 void QwtMagnifier::setMouseButton( 194 203 Qt::MouseButton button, Qt::KeyboardModifiers modifiers ) 195 204 { 196 d_data->mouseButton = button;197 d_data->mouseButtonModifiers = modifiers;205 m_data->mouseButton = button; 206 m_data->mouseButtonModifiers = modifiers; 198 207 } 199 208 200 209 //! \sa setMouseButton() 201 210 void QwtMagnifier::getMouseButton( 202 Qt::MouseButton &button, Qt::KeyboardModifiers&modifiers ) const203 { 204 button = d_data->mouseButton;205 modifiers = d_data->mouseButtonModifiers;211 Qt::MouseButton& button, Qt::KeyboardModifiers& modifiers ) const 212 { 213 button = m_data->mouseButton; 214 modifiers = m_data->mouseButtonModifiers; 206 215 } 207 216 … … 216 225 \sa keyFactor(), setZoomInKey(), setZoomOutKey(), 217 226 setWheelFactor, setMouseFactor() 218 */ 227 */ 219 228 void QwtMagnifier::setKeyFactor( double factor ) 220 229 { 221 d_data->keyFactor = factor;230 m_data->keyFactor = factor; 222 231 } 223 232 … … 225 234 \return Key factor 226 235 \sa setKeyFactor() 227 */ 236 */ 228 237 double QwtMagnifier::keyFactor() const 229 238 { 230 return d_data->keyFactor;239 return m_data->keyFactor; 231 240 } 232 241 … … 238 247 \param modifiers 239 248 \sa getZoomInKey(), setZoomOutKey() 240 */ 249 */ 241 250 void QwtMagnifier::setZoomInKey( int key, 242 251 Qt::KeyboardModifiers modifiers ) 243 252 { 244 d_data->zoomInKey = key;245 d_data->zoomInKeyModifiers = modifiers;253 m_data->zoomInKey = key; 254 m_data->zoomInKeyModifiers = modifiers; 246 255 } 247 256 … … 253 262 254 263 \sa setZoomInKey() 255 */ 256 void QwtMagnifier::getZoomInKey( int &key,257 Qt::KeyboardModifiers &modifiers ) const258 { 259 key = d_data->zoomInKey;260 modifiers = d_data->zoomInKeyModifiers;264 */ 265 void QwtMagnifier::getZoomInKey( int& key, 266 Qt::KeyboardModifiers& modifiers ) const 267 { 268 key = m_data->zoomInKey; 269 modifiers = m_data->zoomInKeyModifiers; 261 270 } 262 271 … … 268 277 \param modifiers 269 278 \sa getZoomOutKey(), setZoomOutKey() 270 */ 279 */ 271 280 void QwtMagnifier::setZoomOutKey( int key, 272 281 Qt::KeyboardModifiers modifiers ) 273 282 { 274 d_data->zoomOutKey = key;275 d_data->zoomOutKeyModifiers = modifiers;283 m_data->zoomOutKey = key; 284 m_data->zoomOutKeyModifiers = modifiers; 276 285 } 277 286 … … 283 292 284 293 \sa setZoomOutKey() 285 */ 286 void QwtMagnifier::getZoomOutKey( int &key,287 Qt::KeyboardModifiers &modifiers ) const288 { 289 key = d_data->zoomOutKey;290 modifiers = d_data->zoomOutKeyModifiers;291 } 292 293 /*! 294 \brief Event filter 295 296 When isEnabled() is true, the mouse events of the 297 observed widget are filtered. 298 299 \param object Object to be filtered 300 \param event Event 301 302 \return Forwarded to QObject::eventFilter() 303 304 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 294 */ 295 void QwtMagnifier::getZoomOutKey( int& key, 296 Qt::KeyboardModifiers& modifiers ) const 297 { 298 key = m_data->zoomOutKey; 299 modifiers = m_data->zoomOutKeyModifiers; 300 } 301 302 /*! 303 \brief Event filter 304 305 When isEnabled() is true, the mouse events of the 306 observed widget are filtered. 307 308 \param object Object to be filtered 309 \param event Event 310 311 \return Forwarded to QObject::eventFilter() 312 313 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 305 314 widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent() 306 315 widgetKeyReleaseEvent() 307 */ 308 bool QwtMagnifier::eventFilter( QObject *object, QEvent*event )316 */ 317 bool QwtMagnifier::eventFilter( QObject* object, QEvent* event ) 309 318 { 310 319 if ( object && object == parent() ) … … 314 323 case QEvent::MouseButtonPress: 315 324 { 316 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );325 widgetMousePressEvent( static_cast< QMouseEvent* >( event ) ); 317 326 break; 318 327 } 319 328 case QEvent::MouseMove: 320 329 { 321 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );330 widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) ); 322 331 break; 323 332 } 324 333 case QEvent::MouseButtonRelease: 325 334 { 326 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );335 widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) ); 327 336 break; 328 337 } 329 338 case QEvent::Wheel: 330 339 { 331 widgetWheelEvent( static_cast<QWheelEvent *>( event ) );340 widgetWheelEvent( static_cast< QWheelEvent* >( event ) ); 332 341 break; 333 342 } 334 343 case QEvent::KeyPress: 335 344 { 336 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );345 widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) ); 337 346 break; 338 347 } 339 348 case QEvent::KeyRelease: 340 349 { 341 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );350 widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) ); 342 351 break; 343 352 } … … 349 358 350 359 /*! 351 Handle a mouse press event for the observed widget. 352 353 \param mouseEvent Mouse event 354 \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent() 355 */ 356 void QwtMagnifier::widgetMousePressEvent( QMouseEvent *mouseEvent )360 Handle a mouse press event for the observed widget. 361 362 \param mouseEvent Mouse event 363 \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent() 364 */ 365 void QwtMagnifier::widgetMousePressEvent( QMouseEvent* mouseEvent ) 357 366 { 358 367 if ( parentWidget() == NULL ) 359 368 return; 360 369 361 if ( ( mouseEvent->button() != d_data->mouseButton ) ||362 ( mouseEvent->modifiers() != d_data->mouseButtonModifiers ) )370 if ( ( mouseEvent->button() != m_data->mouseButton ) || 371 ( mouseEvent->modifiers() != m_data->mouseButtonModifiers ) ) 363 372 { 364 373 return; 365 374 } 366 375 367 d_data->hasMouseTracking = parentWidget()->hasMouseTracking();376 m_data->hasMouseTracking = parentWidget()->hasMouseTracking(); 368 377 369 378 parentWidget()->setMouseTracking( true ); 370 d_data->mousePos = mouseEvent->pos();371 d_data->mousePressed = true;372 } 373 374 /*! 375 Handle a mouse release event for the observed widget. 376 377 \param mouseEvent Mouse event 378 379 \sa eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(), 380 */ 381 void QwtMagnifier::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )379 m_data->mousePos = mouseEvent->pos(); 380 m_data->mousePressed = true; 381 } 382 383 /*! 384 Handle a mouse release event for the observed widget. 385 386 \param mouseEvent Mouse event 387 388 \sa eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(), 389 */ 390 void QwtMagnifier::widgetMouseReleaseEvent( QMouseEvent* mouseEvent ) 382 391 { 383 392 Q_UNUSED( mouseEvent ); 384 393 385 if ( d_data->mousePressed && parentWidget() )386 { 387 d_data->mousePressed = false;388 parentWidget()->setMouseTracking( d_data->hasMouseTracking );389 } 390 } 391 392 /*! 393 Handle a mouse move event for the observed widget. 394 395 \param mouseEvent Mouse event 396 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 397 */ 398 void QwtMagnifier::widgetMouseMoveEvent( QMouseEvent *mouseEvent )399 { 400 if ( ! d_data->mousePressed )394 if ( m_data->mousePressed && parentWidget() ) 395 { 396 m_data->mousePressed = false; 397 parentWidget()->setMouseTracking( m_data->hasMouseTracking ); 398 } 399 } 400 401 /*! 402 Handle a mouse move event for the observed widget. 403 404 \param mouseEvent Mouse event 405 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 406 */ 407 void QwtMagnifier::widgetMouseMoveEvent( QMouseEvent* mouseEvent ) 408 { 409 if ( !m_data->mousePressed ) 401 410 return; 402 411 403 const int dy = mouseEvent->pos().y() - d_data->mousePos.y();412 const int dy = mouseEvent->pos().y() - m_data->mousePos.y(); 404 413 if ( dy != 0 ) 405 414 { 406 double f = d_data->mouseFactor;415 double f = m_data->mouseFactor; 407 416 if ( dy < 0 ) 408 417 f = 1 / f; … … 411 420 } 412 421 413 d_data->mousePos = mouseEvent->pos();414 } 415 416 /*! 417 Handle a wheel event for the observed widget. 418 419 \param wheelEvent Wheel event 420 \sa eventFilter() 421 */ 422 void QwtMagnifier::widgetWheelEvent( QWheelEvent *wheelEvent )423 { 424 if ( wheelEvent->modifiers() != d_data->wheelModifiers )422 m_data->mousePos = mouseEvent->pos(); 423 } 424 425 /*! 426 Handle a wheel event for the observed widget. 427 428 \param wheelEvent Wheel event 429 \sa eventFilter() 430 */ 431 void QwtMagnifier::widgetWheelEvent( QWheelEvent* wheelEvent ) 432 { 433 if ( wheelEvent->modifiers() != m_data->wheelModifiers ) 425 434 { 426 435 return; 427 436 } 428 437 429 if ( d_data->wheelFactor != 0.0 ) 430 { 438 if ( m_data->wheelFactor != 0.0 ) 439 { 440 #if QT_VERSION < 0x050000 441 const int wheelDelta = wheelEvent->delta(); 442 #else 443 const QPoint delta = wheelEvent->angleDelta(); 444 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) ) 445 ? delta.x() : delta.y(); 446 #endif 447 431 448 /* 432 449 A positive delta indicates that the wheel was … … 438 455 of 120 (== 15 * 8). 439 456 */ 440 double f = qPow( d_data->wheelFactor,441 qAbs( wheel Event->delta()/ 120.0 ) );442 443 if ( wheel Event->delta()> 0 )457 double f = std::pow( m_data->wheelFactor, 458 qAbs( wheelDelta / 120.0 ) ); 459 460 if ( wheelDelta > 0 ) 444 461 f = 1 / f; 445 462 … … 449 466 450 467 /*! 451 Handle a key press event for the observed widget. 452 453 \param keyEvent Key event 454 \sa eventFilter(), widgetKeyReleaseEvent() 455 */ 456 void QwtMagnifier::widgetKeyPressEvent( QKeyEvent *keyEvent )457 { 458 if ( keyEvent->key() == d_data->zoomInKey &&459 keyEvent->modifiers() == d_data->zoomInKeyModifiers )460 { 461 rescale( d_data->keyFactor );462 } 463 else if ( keyEvent->key() == d_data->zoomOutKey &&464 keyEvent->modifiers() == d_data->zoomOutKeyModifiers )465 { 466 rescale( 1.0 / d_data->keyFactor );467 } 468 } 469 470 /*! 471 Handle a key release event for the observed widget. 472 473 \param keyEvent Key event 474 \sa eventFilter(), widgetKeyReleaseEvent() 475 */ 476 void QwtMagnifier::widgetKeyReleaseEvent( QKeyEvent *keyEvent )468 Handle a key press event for the observed widget. 469 470 \param keyEvent Key event 471 \sa eventFilter(), widgetKeyReleaseEvent() 472 */ 473 void QwtMagnifier::widgetKeyPressEvent( QKeyEvent* keyEvent ) 474 { 475 if ( keyEvent->key() == m_data->zoomInKey && 476 keyEvent->modifiers() == m_data->zoomInKeyModifiers ) 477 { 478 rescale( m_data->keyFactor ); 479 } 480 else if ( keyEvent->key() == m_data->zoomOutKey && 481 keyEvent->modifiers() == m_data->zoomOutKeyModifiers ) 482 { 483 rescale( 1.0 / m_data->keyFactor ); 484 } 485 } 486 487 /*! 488 Handle a key release event for the observed widget. 489 490 \param keyEvent Key event 491 \sa eventFilter(), widgetKeyReleaseEvent() 492 */ 493 void QwtMagnifier::widgetKeyReleaseEvent( QKeyEvent* keyEvent ) 477 494 { 478 495 Q_UNUSED( keyEvent ); … … 480 497 481 498 //! \return Parent widget, where the rescaling happens 482 QWidget *QwtMagnifier::parentWidget()483 { 484 return qobject_cast<QWidget *>( parent() );499 QWidget* QwtMagnifier::parentWidget() 500 { 501 return qobject_cast< QWidget* >( parent() ); 485 502 } 486 503 487 504 //! \return Parent widget, where the rescaling happens 488 const QWidget *QwtMagnifier::parentWidget() const 489 { 490 return qobject_cast<const QWidget *>( parent() ); 491 } 492 505 const QWidget* QwtMagnifier::parentWidget() const 506 { 507 return qobject_cast< const QWidget* >( parent() ); 508 } 509 510 #include "moc_qwt_magnifier.cpp" -
trunk/BNC/qwt/qwt_magnifier.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_MAGNIFIER_H 11 #define QWT_MAGNIFIER_H 111 #define QWT_MAGNIFIER_H 12 12 13 13 #include "qwt_global.h" … … 20 20 21 21 /*! 22 \brief QwtMagnifier provides zooming, by magnifying in steps. 22 \brief QwtMagnifier provides zooming, by magnifying in steps. 23 23 24 Using QwtMagnifier a plot can be zoomed in/out in steps using 25 keys, the mouse wheel or moving a mouse button in vertical direction. 26 */ 27 class QWT_EXPORT QwtMagnifier: public QObject 24 Using QwtMagnifier a plot can be zoomed in/out in steps using 25 keys, the mouse wheel or moving a mouse button in vertical direction. 26 */ 27 class QWT_EXPORT QwtMagnifier : public QObject 28 28 { 29 29 Q_OBJECT 30 30 31 public: 32 explicit QwtMagnifier( QWidget * );31 public: 32 explicit QwtMagnifier( QWidget* ); 33 33 virtual ~QwtMagnifier(); 34 34 35 QWidget *parentWidget();36 const QWidget *parentWidget() const;35 QWidget* parentWidget(); 36 const QWidget* parentWidget() const; 37 37 38 38 void setEnabled( bool ); … … 44 44 45 45 void setMouseButton( Qt::MouseButton, Qt::KeyboardModifiers = Qt::NoModifier ); 46 void getMouseButton( Qt::MouseButton &, Qt::KeyboardModifiers& ) const;46 void getMouseButton( Qt::MouseButton&, Qt::KeyboardModifiers& ) const; 47 47 48 48 // mouse wheel … … 58 58 59 59 void setZoomInKey( int key, Qt::KeyboardModifiers = Qt::NoModifier ); 60 void getZoomInKey( int &key, Qt::KeyboardModifiers& ) const;60 void getZoomInKey( int& key, Qt::KeyboardModifiers& ) const; 61 61 62 62 void setZoomOutKey( int key, Qt::KeyboardModifiers = Qt::NoModifier ); 63 void getZoomOutKey( int &key, Qt::KeyboardModifiers& ) const;63 void getZoomOutKey( int& key, Qt::KeyboardModifiers& ) const; 64 64 65 virtual bool eventFilter( QObject *, QEvent* );65 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 66 66 67 protected: 67 protected: 68 68 /*! 69 69 Rescale the parent widget … … 72 72 virtual void rescale( double factor ) = 0; 73 73 74 virtual void widgetMousePressEvent( QMouseEvent * );75 virtual void widgetMouseReleaseEvent( QMouseEvent * );76 virtual void widgetMouseMoveEvent( QMouseEvent * );77 virtual void widgetWheelEvent( QWheelEvent * );78 virtual void widgetKeyPressEvent( QKeyEvent * );79 virtual void widgetKeyReleaseEvent( QKeyEvent * );74 virtual void widgetMousePressEvent( QMouseEvent* ); 75 virtual void widgetMouseReleaseEvent( QMouseEvent* ); 76 virtual void widgetMouseMoveEvent( QMouseEvent* ); 77 virtual void widgetWheelEvent( QWheelEvent* ); 78 virtual void widgetKeyPressEvent( QKeyEvent* ); 79 virtual void widgetKeyReleaseEvent( QKeyEvent* ); 80 80 81 private: 81 private: 82 82 class PrivateData; 83 PrivateData *d_data;83 PrivateData* m_data; 84 84 }; 85 85 -
trunk/BNC/qwt/qwt_math.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_math.h" 11 #if QT_VERSION >= 0x050a00 12 #include <qrandom.h> 13 #endif 11 14 12 15 /*! 13 \brief Find the smallest value in an array 14 \param array Pointer to an array 15 \param size Array size 16 */ 17 double qwtGetMin( const double *array, int size ) 18 { 19 if ( size <= 0 ) 20 return 0.0; 21 22 double rv = array[0]; 23 for ( int i = 1; i < size; i++ ) 24 rv = qMin( rv, array[i] ); 25 26 return rv; 27 } 28 29 30 /*! 31 \brief Find the largest value in an array 32 \param array Pointer to an array 33 \param size Array size 34 */ 35 double qwtGetMax( const double *array, int size ) 36 { 37 if ( size <= 0 ) 38 return 0.0; 39 40 double rv = array[0]; 41 for ( int i = 1; i < size; i++ ) 42 rv = qMax( rv, array[i] ); 43 44 return rv; 45 } 46 47 /*! 48 \brief Normalize an angle to be int the range [0.0, 2 * PI[ 49 \param radians Angle in radians 50 \return Normalized angle in radians 51 */ 16 \brief Normalize an angle to be int the range [0.0, 2 * PI[ 17 \param radians Angle in radians 18 \return Normalized angle in radians 19 */ 52 20 double qwtNormalizeRadians( double radians ) 53 21 { 54 double a = ::fmod( radians, 2.0 * M_PI ); 22 double a = std::fmod( radians, 2.0 * M_PI ); 55 23 if ( a < 0.0 ) 56 24 a += 2.0 * M_PI; … … 61 29 62 30 /*! 63 \brief Normalize an angle to be int the range [0.0, 360.0[ 64 \param radians Angle in degrees 65 \return Normalized angle in degrees 66 */ 31 \brief Normalize an angle to be int the range [0.0, 360.0[ 32 \param radians Angle in degrees 33 \return Normalized angle in degrees 34 */ 67 35 double qwtNormalizeDegrees( double degrees ) 68 36 { 69 double a = ::fmod( degrees, 360.0 ); 37 double a = std::fmod( degrees, 360.0 ); 70 38 if ( a < 0.0 ) 71 39 a += 360.0; … … 73 41 return a; 74 42 } 43 44 /*! 45 \brief Uses QRandomGenerator for Qt >= 5.10 and qRand() otherwise 46 \return A 32-bit random quantity 47 */ 48 quint32 qwtRand() 49 { 50 #if QT_VERSION >= 0x050a00 51 return QRandomGenerator::global()->generate(); 52 #else 53 return static_cast< quint32 >( qrand() ); // [0, RAND_MAX ] 54 #endif 55 } -
trunk/BNC/qwt/qwt_math.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 15 #if defined(_MSC_VER)16 15 /* 17 Microsoft says: 18 19 Define _USE_MATH_DEFINES before including math.h to expose these macro 20 definitions for common math constants. These are placed under an #ifdef 21 since these commonly-defined names are not part of the C/C++ standards. 22 */ 23 #define _USE_MATH_DEFINES 1 24 #endif 25 26 #include <qmath.h> 27 #include "qwt_global.h" 16 Microsoft says: 17 18 Define _USE_MATH_DEFINES before including math.h to expose these macro 19 definitions for common math constants. These are placed under an #ifdef 20 since these commonly-defined names are not part of the C/C++ standards. 21 */ 22 23 #ifndef _USE_MATH_DEFINES 24 #define _USE_MATH_DEFINES 25 #define undef_USE_MATH_DEFINES 26 #endif 27 28 #include <cmath> 29 30 #ifdef undef_USE_MATH_DEFINES 31 #undef _USE_MATH_DEFINES 32 #undef undef_USE_MATH_DEFINES 33 #endif 34 35 #ifndef M_E 36 #define M_E ( 2.7182818284590452354 ) 37 #endif 38 39 #ifndef M_LOG2E 40 #define M_LOG2E ( 1.4426950408889634074 ) 41 #endif 42 43 #ifndef M_LOG10E 44 #define M_LOG10E ( 0.43429448190325182765 ) 45 #endif 46 47 #ifndef M_LN2 48 #define M_LN2 ( 0.69314718055994530942 ) 49 #endif 50 51 #ifndef M_LN10 52 #define M_LN10 ( 2.30258509299404568402 ) 53 #endif 54 55 #ifndef M_PI 56 #define M_PI ( 3.14159265358979323846 ) 57 #endif 28 58 29 59 #ifndef M_PI_2 30 // For Qt <= 4.8.4 M_PI_2 is not known by MinGW-w64 31 // when compiling with -std=c++11 32 #define M_PI_2 (1.57079632679489661923) 33 #endif 34 35 #ifndef LOG_MIN 36 //! Minimum value for logarithmic scales 37 #define LOG_MIN 1.0e-100 38 #endif 39 40 #ifndef LOG_MAX 41 //! Maximum value for logarithmic scales 42 #define LOG_MAX 1.0e100 43 #endif 44 45 QWT_EXPORT double qwtGetMin( const double *array, int size ); 46 QWT_EXPORT double qwtGetMax( const double *array, int size ); 60 #define M_PI_2 ( 1.57079632679489661923 ) 61 #endif 62 63 #ifndef M_PI_4 64 #define M_PI_4 ( 0.78539816339744830962 ) 65 #endif 66 67 #ifndef M_1_PI 68 #define M_1_PI ( 0.31830988618379067154 ) 69 #endif 70 71 #ifndef M_2_PI 72 #define M_2_PI ( 0.63661977236758134308 ) 73 #endif 74 75 #ifndef M_2_SQRTPI 76 #define M_2_SQRTPI ( 1.12837916709551257390 ) 77 #endif 78 79 #ifndef M_SQRT2 80 #define M_SQRT2 ( 1.41421356237309504880 ) 81 #endif 82 83 #ifndef M_SQRT1_2 84 #define M_SQRT1_2 ( 0.70710678118654752440 ) 85 #endif 86 87 #if defined( QT_WARNING_PUSH ) 88 /* 89 early Qt versions not having QT_WARNING_PUSH is full of warnings 90 so that we do not care of suppressing those from below 91 */ 92 QT_WARNING_PUSH 93 QT_WARNING_DISABLE_CLANG("-Wdouble-promotion") 94 QT_WARNING_DISABLE_GCC("-Wdouble-promotion") 95 #endif 96 97 /* 98 On systems, where qreal is a float you often run into 99 compiler issues with qMin/qMax. 100 */ 101 102 //! \return Minimum of a and b. 103 QWT_CONSTEXPR inline float qwtMinF( float a, float b ) 104 { 105 return ( a < b ) ? a : b; 106 } 107 108 //! \return Minimum of a and b. 109 QWT_CONSTEXPR inline double qwtMinF( double a, double b ) 110 { 111 return ( a < b ) ? a : b; 112 } 113 114 //! \return Minimum of a and b. 115 QWT_CONSTEXPR inline qreal qwtMinF( float a, double b ) 116 { 117 return ( a < b ) ? a : b; 118 } 119 120 //! \return Minimum of a and b. 121 QWT_CONSTEXPR inline qreal qwtMinF( double a, float b ) 122 { 123 return ( a < b ) ? a : b; 124 } 125 126 //! \return Maximum of a and b. 127 QWT_CONSTEXPR inline float qwtMaxF( float a, float b ) 128 { 129 return ( a < b ) ? b : a; 130 } 131 132 //! \return Maximum of a and b. 133 QWT_CONSTEXPR inline double qwtMaxF( double a, double b ) 134 { 135 return ( a < b ) ? b : a; 136 } 137 138 //! \return Maximum of a and b. 139 QWT_CONSTEXPR inline qreal qwtMaxF( float a, double b ) 140 { 141 return ( a < b ) ? b : a; 142 } 143 144 //! \return Maximum of a and b. 145 QWT_CONSTEXPR inline qreal qwtMaxF( double a, float b ) 146 { 147 return ( a < b ) ? b : a; 148 } 149 150 #if defined( QT_WARNING_POP ) 151 QT_WARNING_POP 152 #endif 47 153 48 154 QWT_EXPORT double qwtNormalizeRadians( double radians ); 49 155 QWT_EXPORT double qwtNormalizeDegrees( double degrees ); 156 QWT_EXPORT quint32 qwtRand(); 50 157 51 158 /*! 52 \brief Compare 2 values, relative to an interval 53 54 Values are "equal", when : 55 \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$ 56 57 \param value1 First value to compare 58 \param value2 Second value to compare 59 \param intervalSize interval size 60 61 \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2 62 */ 159 \brief Compare 2 values, relative to an interval 160 161 Values are "equal", when : 162 \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$ 163 164 \param value1 First value to compare 165 \param value2 Second value to compare 166 \param intervalSize interval size 167 168 \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2 169 */ 63 170 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize ) 64 171 { … … 72 179 73 180 return 0; 74 }75 76 77 inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )78 {79 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );80 }81 82 inline bool qwtFuzzyLessOrEqual( double d1, double d2 )83 {84 return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );85 181 } 86 182 … … 135 231 } 136 232 233 /* ! 234 \brief Calculate a value of a cubic polynomial 235 236 \param x Value 237 \param a Cubic coefficient 238 \param b Quadratic coefficient 239 \param c Linear coefficient 240 \param d Constant offset 241 242 \return Value of the polyonom for x 243 */ 244 inline double qwtCubicPolynomial( double x, 245 double a, double b, double c, double d ) 246 { 247 return ( ( ( a * x ) + b ) * x + c ) * x + d; 248 } 249 137 250 //! Translate degrees into radians 138 251 inline double qwtRadians( double degrees ) … … 147 260 } 148 261 149 #endif 262 /*! 263 The same as qCeil, but avoids including qmath.h 264 \return Ceiling of value. 265 */ 266 inline int qwtCeil( qreal value ) 267 { 268 using std::ceil; 269 return int( ceil( value ) ); 270 } 271 /*! 272 The same as qFloor, but avoids including qmath.h 273 \return Floor of value. 274 */ 275 inline int qwtFloor( qreal value ) 276 { 277 using std::floor; 278 return int( floor( value ) ); 279 } 280 281 #endif -
trunk/BNC/qwt/qwt_matrix_raster_data.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_matrix_raster_data.h" 11 #include "qwt_interval.h" 12 13 #include <qvector.h> 11 14 #include <qnumeric.h> 12 #include <qmath.h> 15 #include <qrect.h> 16 17 static inline double qwtHermiteInterpolate( 18 double A, double B, double C, double D, double t ) 19 { 20 const double t2 = t * t; 21 const double t3 = t2 * t; 22 23 const double a = -A / 2.0 + ( 3.0 * B ) / 2.0 - ( 3.0 * C ) / 2.0 + D / 2.0; 24 const double b = A - ( 5.0 * B ) / 2.0 + 2.0 * C - D / 2.0; 25 const double c = -A / 2.0 + C / 2.0; 26 const double d = B; 27 28 return a * t3 + b * t2 + c * t + d; 29 } 30 31 static inline double qwtBicubicInterpolate( 32 double v00, double v10, double v20, double v30, 33 double v01, double v11, double v21, double v31, 34 double v02, double v12, double v22, double v32, 35 double v03, double v13, double v23, double v33, 36 double dx, double dy ) 37 { 38 const double v0 = qwtHermiteInterpolate( v00, v10, v20, v30, dx ); 39 const double v1 = qwtHermiteInterpolate( v01, v11, v21, v31, dx ); 40 const double v2 = qwtHermiteInterpolate( v02, v12, v22, v32, dx ); 41 const double v3 = qwtHermiteInterpolate( v03, v13, v23, v33, dx ); 42 43 return qwtHermiteInterpolate( v0, v1, v2, v3, dy ); 44 } 13 45 14 46 class QwtMatrixRasterData::PrivateData 15 47 { 16 public: 17 PrivateData() :18 resampleMode(QwtMatrixRasterData::NearestNeighbour ),19 numColumns(0) 48 public: 49 PrivateData() 50 : resampleMode( QwtMatrixRasterData::NearestNeighbour ) 51 , numColumns(0) 20 52 { 21 53 } … … 26 58 } 27 59 60 QwtInterval intervals[3]; 28 61 QwtMatrixRasterData::ResampleMode resampleMode; 29 62 30 QVector< double> values;63 QVector< double > values; 31 64 int numColumns; 32 65 int numRows; … … 39 72 QwtMatrixRasterData::QwtMatrixRasterData() 40 73 { 41 d_data = new PrivateData();74 m_data = new PrivateData(); 42 75 update(); 43 76 } … … 46 79 QwtMatrixRasterData::~QwtMatrixRasterData() 47 80 { 48 delete d_data;81 delete m_data; 49 82 } 50 83 … … 54 87 \param mode Resampling mode 55 88 \sa resampleMode(), value() 56 */ 89 */ 57 90 void QwtMatrixRasterData::setResampleMode( ResampleMode mode ) 58 91 { 59 d_data->resampleMode = mode;92 m_data->resampleMode = mode; 60 93 } 61 94 … … 63 96 \return resampling algorithm 64 97 \sa setResampleMode(), value() 65 */ 98 */ 66 99 QwtMatrixRasterData::ResampleMode QwtMatrixRasterData::resampleMode() const 67 100 { 68 return d_data->resampleMode;101 return m_data->resampleMode; 69 102 } 70 103 … … 84 117 85 118 \sa QwtRasterData::interval(), setValueMatrix() 86 */ 119 */ 87 120 void QwtMatrixRasterData::setInterval( 88 Qt::Axis axis, const QwtInterval &interval ) 89 { 90 QwtRasterData::setInterval( axis, interval ); 91 update(); 121 Qt::Axis axis, const QwtInterval& interval ) 122 { 123 if ( axis >= 0 && axis <= 2 ) 124 { 125 m_data->intervals[axis] = interval; 126 update(); 127 } 128 } 129 130 /*! 131 \return Bounding interval for an axis 132 \sa setInterval 133 */ 134 QwtInterval QwtMatrixRasterData::interval( Qt::Axis axis ) const 135 { 136 if ( axis >= 0 && axis <= 2 ) 137 return m_data->intervals[ axis ]; 138 139 return QwtInterval(); 92 140 } 93 141 … … 104 152 105 153 \sa valueMatrix(), numColumns(), numRows(), setInterval()() 106 */ 154 */ 107 155 void QwtMatrixRasterData::setValueMatrix( 108 const QVector< double> &values, int numColumns )109 { 110 d_data->values = values;111 d_data->numColumns = qMax( numColumns, 0 );156 const QVector< double >& values, int numColumns ) 157 { 158 m_data->values = values; 159 m_data->numColumns = qMax( numColumns, 0 ); 112 160 update(); 113 161 } … … 116 164 \return Value matrix 117 165 \sa setValueMatrix(), numColumns(), numRows(), setInterval() 118 */ 119 const QVector< double> QwtMatrixRasterData::valueMatrix() const120 { 121 return d_data->values;122 } 123 124 /*! 125 \brief Change a single value in the matrix 126 127 \param row Row index 128 \param col Column index 129 \param value New value 130 131 \sa value(), setValueMatrix() 132 */ 166 */ 167 const QVector< double > QwtMatrixRasterData::valueMatrix() const 168 { 169 return m_data->values; 170 } 171 172 /*! 173 \brief Change a single value in the matrix 174 175 \param row Row index 176 \param col Column index 177 \param value New value 178 179 \sa value(), setValueMatrix() 180 */ 133 181 void QwtMatrixRasterData::setValue( int row, int col, double value ) 134 182 { 135 if ( row >= 0 && row < d_data->numRows &&136 col >= 0 && col < d_data->numColumns )137 { 138 const int index = row * d_data->numColumns + col;139 d_data->values.data()[ index ] = value;183 if ( row >= 0 && row < m_data->numRows && 184 col >= 0 && col < m_data->numColumns ) 185 { 186 const int index = row * m_data->numColumns + col; 187 m_data->values.data()[ index ] = value; 140 188 } 141 189 } … … 144 192 \return Number of columns of the value matrix 145 193 \sa valueMatrix(), numRows(), setValueMatrix() 146 */ 194 */ 147 195 int QwtMatrixRasterData::numColumns() const 148 196 { 149 return d_data->numColumns;197 return m_data->numColumns; 150 198 } 151 199 … … 153 201 \return Number of rows of the value matrix 154 202 \sa valueMatrix(), numColumns(), setValueMatrix() 155 */ 203 */ 156 204 int QwtMatrixRasterData::numRows() const 157 205 { 158 return d_data->numRows;206 return m_data->numRows; 159 207 } 160 208 … … 178 226 179 227 \sa ResampleMode, setMatrix(), setInterval() 180 */ 181 QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const228 */ 229 QRectF QwtMatrixRasterData::pixelHint( const QRectF& area ) const 182 230 { 183 231 Q_UNUSED( area ) 184 232 185 233 QRectF rect; 186 if ( d_data->resampleMode == NearestNeighbour )234 if ( m_data->resampleMode == NearestNeighbour ) 187 235 { 188 236 const QwtInterval intervalX = interval( Qt::XAxis ); … … 191 239 { 192 240 rect = QRectF( intervalX.minValue(), intervalY.minValue(), 193 d_data->dx,d_data->dy );241 m_data->dx, m_data->dy ); 194 242 } 195 243 } … … 205 253 206 254 \sa ResampleMode 207 */ 255 */ 208 256 double QwtMatrixRasterData::value( double x, double y ) const 209 257 { … … 216 264 double value; 217 265 218 switch( d_data->resampleMode ) 219 { 266 switch( m_data->resampleMode ) 267 { 268 case BicubicInterpolation: 269 { 270 const double colF = ( x - xInterval.minValue() ) / m_data->dx; 271 const double rowF = ( y - yInterval.minValue() ) / m_data->dy; 272 273 const int col = qRound( colF ); 274 const int row = qRound( rowF ); 275 276 int col0 = col - 2; 277 int col1 = col - 1; 278 int col2 = col; 279 int col3 = col + 1; 280 281 if ( col1 < 0 ) 282 col1 = col2; 283 284 if ( col0 < 0 ) 285 col0 = col1; 286 287 if ( col2 >= m_data->numColumns ) 288 col2 = col1; 289 290 if ( col3 >= m_data->numColumns ) 291 col3 = col2; 292 293 int row0 = row - 2; 294 int row1 = row - 1; 295 int row2 = row; 296 int row3 = row + 1; 297 298 if ( row1 < 0 ) 299 row1 = row2; 300 301 if ( row0 < 0 ) 302 row0 = row1; 303 304 if ( row2 >= m_data->numRows ) 305 row2 = row1; 306 307 if ( row3 >= m_data->numRows ) 308 row3 = row2; 309 310 // First row 311 const double v00 = m_data->value( row0, col0 ); 312 const double v10 = m_data->value( row0, col1 ); 313 const double v20 = m_data->value( row0, col2 ); 314 const double v30 = m_data->value( row0, col3 ); 315 316 // Second row 317 const double v01 = m_data->value( row1, col0 ); 318 const double v11 = m_data->value( row1, col1 ); 319 const double v21 = m_data->value( row1, col2 ); 320 const double v31 = m_data->value( row1, col3 ); 321 322 // Third row 323 const double v02 = m_data->value( row2, col0 ); 324 const double v12 = m_data->value( row2, col1 ); 325 const double v22 = m_data->value( row2, col2 ); 326 const double v32 = m_data->value( row2, col3 ); 327 328 // Fourth row 329 const double v03 = m_data->value( row3, col0 ); 330 const double v13 = m_data->value( row3, col1 ); 331 const double v23 = m_data->value( row3, col2 ); 332 const double v33 = m_data->value( row3, col3 ); 333 334 value = qwtBicubicInterpolate( 335 v00, v10, v20, v30, v01, v11, v21, v31, 336 v02, v12, v22, v32, v03, v13, v23, v33, 337 colF - col + 0.5, rowF - row + 0.5 ); 338 339 break; 340 } 220 341 case BilinearInterpolation: 221 342 { 222 int col1 = qRound( (x - xInterval.minValue() ) / d_data->dx ) - 1;223 int row1 = qRound( (y - yInterval.minValue() ) / d_data->dy ) - 1;343 int col1 = qRound( ( x - xInterval.minValue() ) / m_data->dx ) - 1; 344 int row1 = qRound( ( y - yInterval.minValue() ) / m_data->dy ) - 1; 224 345 int col2 = col1 + 1; 225 346 int row2 = row1 + 1; … … 227 348 if ( col1 < 0 ) 228 349 col1 = col2; 229 else if ( col2 >= static_cast<int>( d_data->numColumns))350 else if ( col2 >= m_data->numColumns ) 230 351 col2 = col1; 231 352 232 353 if ( row1 < 0 ) 233 354 row1 = row2; 234 else if ( row2 >= static_cast<int>( d_data->numRows))355 else if ( row2 >= m_data->numRows ) 235 356 row2 = row1; 236 357 237 const double v11 = d_data->value( row1, col1 ); 238 const double v21 = d_data->value( row1, col2 ); 239 const double v12 = d_data->value( row2, col1 ); 240 const double v22 = d_data->value( row2, col2 ); 241 242 const double x2 = xInterval.minValue() + 243 ( col2 + 0.5 ) * d_data->dx; 244 const double y2 = yInterval.minValue() + 245 ( row2 + 0.5 ) * d_data->dy; 246 247 const double rx = ( x2 - x ) / d_data->dx; 248 const double ry = ( y2 - y ) / d_data->dy; 358 const double v11 = m_data->value( row1, col1 ); 359 const double v21 = m_data->value( row1, col2 ); 360 const double v12 = m_data->value( row2, col1 ); 361 const double v22 = m_data->value( row2, col2 ); 362 363 const double x2 = xInterval.minValue() + ( col2 + 0.5 ) * m_data->dx; 364 const double y2 = yInterval.minValue() + ( row2 + 0.5 ) * m_data->dy; 365 366 const double rx = ( x2 - x ) / m_data->dx; 367 const double ry = ( y2 - y ) / m_data->dy; 249 368 250 369 const double vr1 = rx * v11 + ( 1.0 - rx ) * v21; … … 258 377 default: 259 378 { 260 int row = int( (y - yInterval.minValue() ) / d_data->dy );261 int col = int( (x - xInterval.minValue() ) / d_data->dx );379 int row = int( ( y - yInterval.minValue() ) / m_data->dy ); 380 int col = int( ( x - xInterval.minValue() ) / m_data->dx ); 262 381 263 382 // In case of intervals, where the maximum is included … … 266 385 // from the last row/col 267 386 268 if ( row >= d_data->numRows )269 row = d_data->numRows - 1;270 271 if ( col >= d_data->numColumns )272 col = d_data->numColumns - 1;273 274 value = d_data->value( row, col );387 if ( row >= m_data->numRows ) 388 row = m_data->numRows - 1; 389 390 if ( col >= m_data->numColumns ) 391 col = m_data->numColumns - 1; 392 393 value = m_data->value( row, col ); 275 394 } 276 395 } … … 281 400 void QwtMatrixRasterData::update() 282 401 { 283 d_data->numRows = 0;284 d_data->dx = 0.0;285 d_data->dy = 0.0;286 287 if ( d_data->numColumns > 0 )288 { 289 d_data->numRows =d_data->values.size() /d_data->numColumns;402 m_data->numRows = 0; 403 m_data->dx = 0.0; 404 m_data->dy = 0.0; 405 406 if ( m_data->numColumns > 0 ) 407 { 408 m_data->numRows = m_data->values.size() / m_data->numColumns; 290 409 291 410 const QwtInterval xInterval = interval( Qt::XAxis ); 292 411 const QwtInterval yInterval = interval( Qt::YAxis ); 293 412 if ( xInterval.isValid() ) 294 d_data->dx = xInterval.width() /d_data->numColumns;413 m_data->dx = xInterval.width() / m_data->numColumns; 295 414 if ( yInterval.isValid() ) 296 d_data->dy = yInterval.width() /d_data->numRows;297 } 298 } 415 m_data->dy = yInterval.width() / m_data->numRows; 416 } 417 } -
trunk/BNC/qwt/qwt_matrix_raster_data.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_MATRIX_RASTER_DATA_H 11 #define QWT_MATRIX_RASTER_DATA_H 111 #define QWT_MATRIX_RASTER_DATA_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_raster_data.h" 15 #include <qvector.h> 15 16 #if QT_VERSION < 0x060000 17 template< typename T > class QVector; 18 #endif 16 19 17 20 /*! 18 \brief A class representing a matrix of values as raster data 21 \brief A class representing a matrix of values as raster data 19 22 20 QwtMatrixRasterData implements an interface for a matrix of 21 equidistant values, that can be used by a QwtPlotRasterItem. 22 It implements a couple of resampling algorithms, to provide 23 values for positions, that or not on the value matrix. 24 */ 25 class QWT_EXPORT QwtMatrixRasterData: public QwtRasterData 23 QwtMatrixRasterData implements an interface for a matrix of 24 equidistant values, that can be used by a QwtPlotRasterItem. 25 It implements a couple of resampling algorithms, to provide 26 values for positions, that or not on the value matrix. 27 */ 28 class QWT_EXPORT QwtMatrixRasterData : public QwtRasterData 26 29 { 27 public: 30 public: 28 31 /*! 29 \brief Resampling algorithm 30 The default setting is NearestNeighbour; 31 */ 32 \brief Resampling algorithm 33 The default setting is NearestNeighbour; 34 */ 32 35 enum ResampleMode 33 36 { 34 37 /*! 35 Return the value from the matrix, that is nearest to the 36 the requested position. 38 Return the value from the matrix, that is nearest to the 39 the requested position. 37 40 */ 38 41 NearestNeighbour, 39 42 40 43 /*! 41 Interpolate the value from the distances and values of the 42 4 surrounding values in the matrix, 44 Interpolate the value from the distances and values of the 45 4 surrounding values in the matrix, 43 46 */ 44 BilinearInterpolation 47 BilinearInterpolation, 48 49 /*! 50 Interpolate the value from the 16 surrounding values in the 51 matrix using hermite bicubic interpolation 52 */ 53 BicubicInterpolation 45 54 }; 46 55 … … 51 60 ResampleMode resampleMode() const; 52 61 53 virtual void setInterval( Qt::Axis, const QwtInterval & ); 62 void setInterval( Qt::Axis, const QwtInterval& ); 63 virtual QwtInterval interval( Qt::Axis axis) const QWT_OVERRIDE QWT_FINAL; 54 64 55 void setValueMatrix( const QVector< double> &values, int numColumns );56 const QVector< double> valueMatrix() const;65 void setValueMatrix( const QVector< double >& values, int numColumns ); 66 const QVector< double > valueMatrix() const; 57 67 58 68 void setValue( int row, int col, double value ); … … 61 71 int numRows() const; 62 72 63 virtual QRectF pixelHint( const QRectF & ) const;73 virtual QRectF pixelHint( const QRectF& ) const QWT_OVERRIDE; 64 74 65 virtual double value( double x, double y ) const; 75 virtual double value( double x, double y ) const QWT_OVERRIDE; 66 76 67 private: 77 private: 68 78 void update(); 69 79 70 80 class PrivateData; 71 PrivateData *d_data;81 PrivateData* m_data; 72 82 }; 73 83 -
trunk/BNC/qwt/qwt_null_paintdevice.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include <qpaintengine.h> 12 12 #include <qpainterpath.h> 13 #include <qpixmap.h>14 13 15 14 class QwtNullPaintDevice::PrivateData 16 15 { 17 public: 16 public: 18 17 PrivateData(): 19 18 mode( QwtNullPaintDevice::NormalMode ) … … 24 23 }; 25 24 26 class QwtNullPaintDevice::PaintEngine: public QPaintEngine 27 { 28 public: 25 class QwtNullPaintDevice::PaintEngine QWT_FINAL : public QPaintEngine 26 { 27 public: 29 28 PaintEngine(); 30 29 31 virtual bool begin( QPaintDevice * ); 32 virtual bool end(); 33 34 virtual Type type () const; 35 virtual void updateState(const QPaintEngineState &); 36 37 virtual void drawRects(const QRect *, int ); 38 virtual void drawRects(const QRectF *, int ); 39 40 virtual void drawLines(const QLine *, int ); 41 virtual void drawLines(const QLineF *, int ); 42 43 virtual void drawEllipse(const QRectF &); 44 virtual void drawEllipse(const QRect &); 45 46 virtual void drawPath(const QPainterPath &); 47 48 virtual void drawPoints(const QPointF *, int ); 49 virtual void drawPoints(const QPoint *, int ); 50 51 virtual void drawPolygon(const QPointF *, int , PolygonDrawMode ); 52 virtual void drawPolygon(const QPoint *, int , PolygonDrawMode ); 53 54 virtual void drawPixmap(const QRectF &, 55 const QPixmap &, const QRectF &); 56 57 virtual void drawTextItem(const QPointF &, const QTextItem &); 58 59 virtual void drawTiledPixmap(const QRectF &, 60 const QPixmap &, const QPointF &s); 61 62 virtual void drawImage(const QRectF &, 63 const QImage &, const QRectF &, Qt::ImageConversionFlags ); 64 65 private: 66 QwtNullPaintDevice *nullDevice(); 30 virtual bool begin( QPaintDevice* ) QWT_OVERRIDE; 31 virtual bool end() QWT_OVERRIDE; 32 33 virtual Type type () const QWT_OVERRIDE; 34 virtual void updateState(const QPaintEngineState&) QWT_OVERRIDE; 35 36 virtual void drawRects(const QRect*, int ) QWT_OVERRIDE; 37 virtual void drawRects(const QRectF*, int ) QWT_OVERRIDE; 38 39 virtual void drawLines(const QLine*, int ) QWT_OVERRIDE; 40 virtual void drawLines(const QLineF*, int ) QWT_OVERRIDE; 41 42 virtual void drawEllipse(const QRectF&) QWT_OVERRIDE; 43 virtual void drawEllipse(const QRect&) QWT_OVERRIDE; 44 45 virtual void drawPath(const QPainterPath&) QWT_OVERRIDE; 46 47 virtual void drawPoints(const QPointF*, int ) QWT_OVERRIDE; 48 virtual void drawPoints(const QPoint*, int ) QWT_OVERRIDE; 49 50 virtual void drawPolygon( 51 const QPointF*, int, PolygonDrawMode ) QWT_OVERRIDE; 52 53 virtual void drawPolygon( 54 const QPoint*, int, PolygonDrawMode ) QWT_OVERRIDE; 55 56 virtual void drawPixmap(const QRectF&, 57 const QPixmap&, const QRectF&) QWT_OVERRIDE; 58 59 virtual void drawTextItem( 60 const QPointF&, const QTextItem&) QWT_OVERRIDE; 61 62 virtual void drawTiledPixmap(const QRectF&, 63 const QPixmap&, const QPointF& s) QWT_OVERRIDE; 64 65 virtual void drawImage(const QRectF&, const QImage&, 66 const QRectF&, Qt::ImageConversionFlags ) QWT_OVERRIDE; 67 68 private: 69 QwtNullPaintDevice* nullDevice(); 67 70 }; 68 71 69 QwtNullPaintDevice::PaintEngine::PaintEngine() :70 QPaintEngine( QPaintEngine::AllFeatures ) 71 { 72 } 73 74 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )72 QwtNullPaintDevice::PaintEngine::PaintEngine() 73 : QPaintEngine( QPaintEngine::AllFeatures ) 74 { 75 } 76 77 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice* ) 75 78 { 76 79 setActive( true ); … … 86 89 QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const 87 90 { 88 return QPaintEngine::User; 91 /* 92 How to avoid conflicts with other 3rd party pain engines ? 93 At least we don't use QPaintEngine::User what is known to 94 be the value of some print engines 95 */ 96 return static_cast< QPaintEngine::Type >( QPaintEngine::MaxUser - 2 ); 89 97 } 90 98 91 99 void QwtNullPaintDevice::PaintEngine::drawRects( 92 const QRect *rects, int rectCount)93 { 94 QwtNullPaintDevice *device = nullDevice();100 const QRect* rects, int rectCount) 101 { 102 QwtNullPaintDevice* device = nullDevice(); 95 103 if ( device == NULL ) 96 104 return; … … 106 114 107 115 void QwtNullPaintDevice::PaintEngine::drawRects( 108 const QRectF *rects, int rectCount)109 { 110 QwtNullPaintDevice *device = nullDevice();116 const QRectF* rects, int rectCount) 117 { 118 QwtNullPaintDevice* device = nullDevice(); 111 119 if ( device == NULL ) 112 120 return; … … 122 130 123 131 void QwtNullPaintDevice::PaintEngine::drawLines( 124 const QLine *lines, int lineCount)125 { 126 QwtNullPaintDevice *device = nullDevice();132 const QLine* lines, int lineCount) 133 { 134 QwtNullPaintDevice* device = nullDevice(); 127 135 if ( device == NULL ) 128 136 return; … … 138 146 139 147 void QwtNullPaintDevice::PaintEngine::drawLines( 140 const QLineF *lines, int lineCount)141 { 142 QwtNullPaintDevice *device = nullDevice();148 const QLineF* lines, int lineCount) 149 { 150 QwtNullPaintDevice* device = nullDevice(); 143 151 if ( device == NULL ) 144 152 return; … … 154 162 155 163 void QwtNullPaintDevice::PaintEngine::drawEllipse( 156 const QRectF &rect)157 { 158 QwtNullPaintDevice *device = nullDevice();164 const QRectF& rect) 165 { 166 QwtNullPaintDevice* device = nullDevice(); 159 167 if ( device == NULL ) 160 168 return; … … 170 178 171 179 void QwtNullPaintDevice::PaintEngine::drawEllipse( 172 const QRect &rect)173 { 174 QwtNullPaintDevice *device = nullDevice();180 const QRect& rect) 181 { 182 QwtNullPaintDevice* device = nullDevice(); 175 183 if ( device == NULL ) 176 184 return; … … 187 195 188 196 void QwtNullPaintDevice::PaintEngine::drawPath( 189 const QPainterPath &path)190 { 191 QwtNullPaintDevice *device = nullDevice();197 const QPainterPath& path) 198 { 199 QwtNullPaintDevice* device = nullDevice(); 192 200 if ( device == NULL ) 193 201 return; … … 197 205 198 206 void QwtNullPaintDevice::PaintEngine::drawPoints( 199 const QPointF *points, int pointCount)200 { 201 QwtNullPaintDevice *device = nullDevice();207 const QPointF* points, int pointCount) 208 { 209 QwtNullPaintDevice* device = nullDevice(); 202 210 if ( device == NULL ) 203 211 return; … … 213 221 214 222 void QwtNullPaintDevice::PaintEngine::drawPoints( 215 const QPoint *points, int pointCount)216 { 217 QwtNullPaintDevice *device = nullDevice();223 const QPoint* points, int pointCount) 224 { 225 QwtNullPaintDevice* device = nullDevice(); 218 226 if ( device == NULL ) 219 227 return; … … 229 237 230 238 void QwtNullPaintDevice::PaintEngine::drawPolygon( 231 const QPointF *points, int pointCount, PolygonDrawMode mode)232 { 233 QwtNullPaintDevice *device = nullDevice();239 const QPointF* points, int pointCount, PolygonDrawMode mode) 240 { 241 QwtNullPaintDevice* device = nullDevice(); 234 242 if ( device == NULL ) 235 243 return; … … 257 265 258 266 void QwtNullPaintDevice::PaintEngine::drawPolygon( 259 const QPoint *points, int pointCount, PolygonDrawMode mode)260 { 261 QwtNullPaintDevice *device = nullDevice();267 const QPoint* points, int pointCount, PolygonDrawMode mode) 268 { 269 QwtNullPaintDevice* device = nullDevice(); 262 270 if ( device == NULL ) 263 271 return; … … 285 293 286 294 void QwtNullPaintDevice::PaintEngine::drawPixmap( 287 const QRectF &rect, const QPixmap&pm, const QRectF&subRect )288 { 289 QwtNullPaintDevice *device = nullDevice();295 const QRectF& rect, const QPixmap& pm, const QRectF& subRect ) 296 { 297 QwtNullPaintDevice* device = nullDevice(); 290 298 if ( device == NULL ) 291 299 return; … … 295 303 296 304 void QwtNullPaintDevice::PaintEngine::drawTextItem( 297 const QPointF &pos, const QTextItem&textItem)298 { 299 QwtNullPaintDevice *device = nullDevice();305 const QPointF& pos, const QTextItem& textItem) 306 { 307 QwtNullPaintDevice* device = nullDevice(); 300 308 if ( device == NULL ) 301 309 return; … … 311 319 312 320 void QwtNullPaintDevice::PaintEngine::drawTiledPixmap( 313 const QRectF &rect, const QPixmap&pixmap,314 const QPointF &subRect)315 { 316 QwtNullPaintDevice *device = nullDevice();321 const QRectF& rect, const QPixmap& pixmap, 322 const QPointF& subRect) 323 { 324 QwtNullPaintDevice* device = nullDevice(); 317 325 if ( device == NULL ) 318 326 return; … … 328 336 329 337 void QwtNullPaintDevice::PaintEngine::drawImage( 330 const QRectF &rect, const QImage&image,331 const QRectF &subRect, Qt::ImageConversionFlags flags)332 { 333 QwtNullPaintDevice *device = nullDevice();338 const QRectF& rect, const QImage& image, 339 const QRectF& subRect, Qt::ImageConversionFlags flags) 340 { 341 QwtNullPaintDevice* device = nullDevice(); 334 342 if ( device == NULL ) 335 343 return; … … 339 347 340 348 void QwtNullPaintDevice::PaintEngine::updateState( 341 const QPaintEngineState &engineState)342 { 343 QwtNullPaintDevice *device = nullDevice();349 const QPaintEngineState& engineState) 350 { 351 QwtNullPaintDevice* device = nullDevice(); 344 352 if ( device == NULL ) 345 353 return; … … 348 356 } 349 357 350 inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()358 inline QwtNullPaintDevice* QwtNullPaintDevice::PaintEngine::nullDevice() 351 359 { 352 360 if ( !isActive() ) 353 361 return NULL; 354 362 355 return static_cast<QwtNullPaintDevice *>( paintDevice() );363 return static_cast< QwtNullPaintDevice* >( paintDevice() ); 356 364 } 357 365 358 366 //! Constructor 359 367 QwtNullPaintDevice::QwtNullPaintDevice(): 360 d_engine( NULL )361 { 362 d_data = new PrivateData;368 m_engine( NULL ) 369 { 370 m_data = new PrivateData; 363 371 } 364 372 … … 366 374 QwtNullPaintDevice::~QwtNullPaintDevice() 367 375 { 368 delete d_engine;369 delete d_data;376 delete m_engine; 377 delete m_data; 370 378 } 371 379 … … 378 386 void QwtNullPaintDevice::setMode( Mode mode ) 379 387 { 380 d_data->mode = mode;388 m_data->mode = mode; 381 389 } 382 390 … … 384 392 \return Render mode 385 393 \sa setMode() 386 */ 394 */ 387 395 QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const 388 396 { 389 return d_data->mode;397 return m_data->mode; 390 398 } 391 399 392 400 //! See QPaintDevice::paintEngine() 393 QPaintEngine *QwtNullPaintDevice::paintEngine() const394 { 395 if ( d_engine == NULL )396 { 397 QwtNullPaintDevice *that =398 const_cast< QwtNullPaintDevice * >( this );399 400 that-> d_engine = new PaintEngine();401 } 402 403 return d_engine;401 QPaintEngine* QwtNullPaintDevice::paintEngine() const 402 { 403 if ( m_engine == NULL ) 404 { 405 QwtNullPaintDevice* that = 406 const_cast< QwtNullPaintDevice* >( this ); 407 408 that->m_engine = new PaintEngine(); 409 } 410 411 return m_engine; 404 412 } 405 413 … … 411 419 412 420 \sa sizeMetrics() 413 */ 421 */ 414 422 int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const 415 423 { … … 456 464 break; 457 465 } 466 #if QT_VERSION >= 0x050100 467 case PdmDevicePixelRatio: 468 { 469 value = 1.0; 470 break; 471 } 472 #endif 458 473 default: 459 value = 0; 460 } 474 { 475 value = QPaintDevice::metric( deviceMetric ); 476 } 477 } 478 461 479 return value; 462 463 480 } 464 481 465 482 //! See QPaintEngine::drawRects() 466 483 void QwtNullPaintDevice::drawRects( 467 const QRect *rects, int rectCount)484 const QRect* rects, int rectCount) 468 485 { 469 486 Q_UNUSED(rects); … … 473 490 //! See QPaintEngine::drawRects() 474 491 void QwtNullPaintDevice::drawRects( 475 const QRectF *rects, int rectCount)492 const QRectF* rects, int rectCount) 476 493 { 477 494 Q_UNUSED(rects); … … 481 498 //! See QPaintEngine::drawLines() 482 499 void QwtNullPaintDevice::drawLines( 483 const QLine *lines, int lineCount)500 const QLine* lines, int lineCount) 484 501 { 485 502 Q_UNUSED(lines); … … 489 506 //! See QPaintEngine::drawLines() 490 507 void QwtNullPaintDevice::drawLines( 491 const QLineF *lines, int lineCount)508 const QLineF* lines, int lineCount) 492 509 { 493 510 Q_UNUSED(lines); … … 496 513 497 514 //! See QPaintEngine::drawEllipse() 498 void QwtNullPaintDevice::drawEllipse( const QRectF &rect )515 void QwtNullPaintDevice::drawEllipse( const QRectF& rect ) 499 516 { 500 517 Q_UNUSED(rect); … … 502 519 503 520 //! See QPaintEngine::drawEllipse() 504 void QwtNullPaintDevice::drawEllipse( const QRect &rect )521 void QwtNullPaintDevice::drawEllipse( const QRect& rect ) 505 522 { 506 523 Q_UNUSED(rect); … … 508 525 509 526 //! See QPaintEngine::drawPath() 510 void QwtNullPaintDevice::drawPath( const QPainterPath &path )527 void QwtNullPaintDevice::drawPath( const QPainterPath& path ) 511 528 { 512 529 Q_UNUSED(path); … … 515 532 //! See QPaintEngine::drawPoints() 516 533 void QwtNullPaintDevice::drawPoints( 517 const QPointF *points, int pointCount)534 const QPointF* points, int pointCount) 518 535 { 519 536 Q_UNUSED(points); … … 523 540 //! See QPaintEngine::drawPoints() 524 541 void QwtNullPaintDevice::drawPoints( 525 const QPoint *points, int pointCount)542 const QPoint* points, int pointCount) 526 543 { 527 544 Q_UNUSED(points); … … 531 548 //! See QPaintEngine::drawPolygon() 532 549 void QwtNullPaintDevice::drawPolygon( 533 const QPointF *points, int pointCount,550 const QPointF* points, int pointCount, 534 551 QPaintEngine::PolygonDrawMode mode) 535 552 { … … 541 558 //! See QPaintEngine::drawPolygon() 542 559 void QwtNullPaintDevice::drawPolygon( 543 const QPoint *points, int pointCount,560 const QPoint* points, int pointCount, 544 561 QPaintEngine::PolygonDrawMode mode) 545 562 { … … 550 567 551 568 //! See QPaintEngine::drawPixmap() 552 void QwtNullPaintDevice::drawPixmap( const QRectF &rect,553 const QPixmap &pm, const QRectF&subRect )569 void QwtNullPaintDevice::drawPixmap( const QRectF& rect, 570 const QPixmap& pm, const QRectF& subRect ) 554 571 { 555 572 Q_UNUSED(rect); … … 560 577 //! See QPaintEngine::drawTextItem() 561 578 void QwtNullPaintDevice::drawTextItem( 562 const QPointF &pos, const QTextItem&textItem)579 const QPointF& pos, const QTextItem& textItem) 563 580 { 564 581 Q_UNUSED(pos); … … 568 585 //! See QPaintEngine::drawTiledPixmap() 569 586 void QwtNullPaintDevice::drawTiledPixmap( 570 const QRectF &rect, const QPixmap&pixmap,571 const QPointF &subRect)587 const QRectF& rect, const QPixmap& pixmap, 588 const QPointF& subRect) 572 589 { 573 590 Q_UNUSED(rect); … … 578 595 //! See QPaintEngine::drawImage() 579 596 void QwtNullPaintDevice::drawImage( 580 const QRectF &rect, const QImage&image,581 const QRectF &subRect, Qt::ImageConversionFlags flags)597 const QRectF& rect, const QImage& image, 598 const QRectF& subRect, Qt::ImageConversionFlags flags) 582 599 { 583 600 Q_UNUSED(rect); … … 589 606 //! See QPaintEngine::updateState() 590 607 void QwtNullPaintDevice::updateState( 591 const QPaintEngineState &state )608 const QPaintEngineState& state ) 592 609 { 593 610 Q_UNUSED(state); -
trunk/BNC/qwt/qwt_null_paintdevice.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_NULL_PAINT_DEVICE_H 11 #define QWT_NULL_PAINT_DEVICE_H 111 #define QWT_NULL_PAINT_DEVICE_H 12 12 13 13 #include "qwt_global.h" 14 14 15 #include <qpaintdevice.h> 15 16 #include <qpaintengine.h> 16 17 17 18 /*! 18 \brief A null paint device doing nothing 19 \brief A null paint device doing nothing 19 20 20 Sometimes important layout/rendering geometries are not 21 available or changeable from the public Qt class interface. 22 ( f.e hidden in the style implementation ). 21 Sometimes important layout/rendering geometries are not 22 available or changeable from the public Qt class interface. 23 ( f.e hidden in the style implementation ). 23 24 24 QwtNullPaintDevice can be used to manipulate or filter out 25 this information by analyzing the stream of paint primitives. 25 QwtNullPaintDevice can be used to manipulate or filter out 26 this information by analyzing the stream of paint primitives. 26 27 27 F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify 28 styled backgrounds with rounded corners. 29 */ 28 F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify 29 styled backgrounds with rounded corners. 30 */ 30 31 31 class QWT_EXPORT QwtNullPaintDevice: public QPaintDevice 32 class QWT_EXPORT QwtNullPaintDevice : public QPaintDevice 32 33 { 33 public: 34 public: 34 35 /*! 35 \brief Render mode 36 \brief Render mode 36 37 37 \sa setMode(), mode() 38 \sa setMode(), mode() 38 39 */ 39 40 enum Mode … … 75 76 Mode mode() const; 76 77 77 virtual QPaintEngine *paintEngine() const;78 virtual QPaintEngine* paintEngine() const QWT_OVERRIDE; 78 79 79 virtual int metric( PaintDeviceMetric ) const; 80 virtual int metric( PaintDeviceMetric ) const QWT_OVERRIDE; 80 81 81 virtual void drawRects(const QRect *, int );82 virtual void drawRects(const QRectF *, int );82 virtual void drawRects(const QRect*, int ); 83 virtual void drawRects(const QRectF*, int ); 83 84 84 virtual void drawLines(const QLine *, int );85 virtual void drawLines(const QLineF *, int );85 virtual void drawLines(const QLine*, int ); 86 virtual void drawLines(const QLineF*, int ); 86 87 87 virtual void drawEllipse(const QRectF &);88 virtual void drawEllipse(const QRect &);88 virtual void drawEllipse(const QRectF&); 89 virtual void drawEllipse(const QRect&); 89 90 90 virtual void drawPath(const QPainterPath &);91 virtual void drawPath(const QPainterPath&); 91 92 92 virtual void drawPoints(const QPointF *, int );93 virtual void drawPoints(const QPoint *, int );93 virtual void drawPoints(const QPointF*, int ); 94 virtual void drawPoints(const QPoint*, int ); 94 95 95 virtual void drawPolygon( 96 const QPointF *, int ,QPaintEngine::PolygonDrawMode );96 virtual void drawPolygon( const QPointF*, int, 97 QPaintEngine::PolygonDrawMode ); 97 98 98 virtual void drawPolygon( 99 const QPoint *, int ,QPaintEngine::PolygonDrawMode );99 virtual void drawPolygon( const QPoint*, int, 100 QPaintEngine::PolygonDrawMode ); 100 101 101 virtual void drawPixmap(const QRectF &,102 const QPixmap &, const QRectF&);102 virtual void drawPixmap(const QRectF&, 103 const QPixmap&, const QRectF&); 103 104 104 virtual void drawTextItem(const QPointF &, const QTextItem&);105 virtual void drawTextItem(const QPointF&, const QTextItem&); 105 106 106 virtual void drawTiledPixmap(const QRectF &,107 const QPixmap &, const QPointF& );107 virtual void drawTiledPixmap(const QRectF&, 108 const QPixmap&, const QPointF& ); 108 109 109 virtual void drawImage(const QRectF &,110 const Q Image &, const QRectF&, Qt::ImageConversionFlags );110 virtual void drawImage(const QRectF&, const QImage&, 111 const QRectF&, Qt::ImageConversionFlags ); 111 112 112 virtual void updateState( const QPaintEngineState & );113 virtual void updateState( const QPaintEngineState& ); 113 114 114 protected: 115 protected: 115 116 //! \return Size needed to implement metric() 116 117 virtual QSize sizeMetrics() const = 0; 117 118 118 private: 119 private: 119 120 class PaintEngine; 120 PaintEngine *d_engine;121 PaintEngine* m_engine; 121 122 122 123 class PrivateData; 123 PrivateData *d_data;124 PrivateData* m_data; 124 125 }; 125 126 -
trunk/BNC/qwt/qwt_painter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_color_map.h" 14 14 #include "qwt_scale_map.h" 15 #include <qwindowdefs.h> 15 16 16 #include <qwidget.h> 17 17 #include <qframe.h> … … 28 28 #include <qpaintengine.h> 29 29 #include <qapplication.h> 30 31 #if QT_VERSION >= 0x060000 32 #include <qscreen.h> 33 #else 30 34 #include <qdesktopwidget.h> 31 32 #if QT_VERSION >= 0x05000033 #include <qwindow.h>34 35 #endif 35 36 … … 42 43 #endif 43 44 44 bool QwtPainter::d_polylineSplitting = true; 45 bool QwtPainter::d_roundingAlignment = true; 45 #include <cstring> 46 47 bool QwtPainter::m_polylineSplitting = true; 48 bool QwtPainter::m_roundingAlignment = true; 49 50 static inline bool qwtIsRasterPaintEngineBuggy() 51 { 52 #if 0 53 static int isBuggy = -1; 54 if ( isBuggy < 0 ) 55 { 56 // auto detect bug of the raster paint engine, 57 // fixed with: https://codereview.qt-project.org/#/c/99456/ 58 59 QImage image( 2, 3, QImage::Format_ARGB32 ); 60 image.fill( 0u ); 61 62 QPolygonF p; 63 p += QPointF(0, 1); 64 p += QPointF(0, 0); 65 p += QPointF(1, 0 ); 66 p += QPointF(1, 2 ); 67 68 QPainter painter( &image ); 69 painter.drawPolyline( p ); 70 painter.end(); 71 72 isBuggy = ( image.pixel( 1, 1 ) == 0 ) ? 1 : 0; 73 } 74 75 return isBuggy == 1; 76 #endif 77 78 #if QT_VERSION < 0x050000 79 return true; 80 #elif QT_VERSION < 0x050100 81 return false; 82 #elif QT_VERSION < 0x050400 83 return true; 84 #else 85 return false; 86 #endif 87 } 46 88 47 89 static inline bool qwtIsClippingNeeded( 48 const QPainter *painter, QRectF&clipRect )90 const QPainter* painter, QRectF& clipRect ) 49 91 { 50 92 bool doClipping = false; 51 const QPaintEngine *pe = painter->paintEngine();93 const QPaintEngine* pe = painter->paintEngine(); 52 94 if ( pe && pe->type() == QPaintEngine::SVG ) 53 95 { … … 64 106 } 65 107 66 template <class T>67 static inline void qwtDrawPolyline( QPainter *painter,68 const T *points, int pointCount, bool polylineSplitting )108 template< class T > 109 static inline void qwtDrawPolyline( QPainter* painter, 110 const T* points, int pointCount, bool polylineSplitting ) 69 111 { 70 112 bool doSplit = false; 71 113 if ( polylineSplitting ) 72 114 { 73 const QPaintEngine *pe = painter->paintEngine();115 const QPaintEngine* pe = painter->paintEngine(); 74 116 if ( pe && pe->type() == QPaintEngine::Raster ) 75 117 { 76 118 /* 77 The raster paint engine seems to use some algo with O(n*n). 78 ( Qt 4.3 is better than Qt 4.2, but remains unacceptable) 79 To work around this problem, we have to split the polygon into 80 smaller pieces. 119 Raster paint engine is much faster when splitting 120 the polygon, but of course we might see some issues where 121 the pieces are joining 81 122 */ 82 123 doSplit = true; … … 86 127 if ( doSplit ) 87 128 { 129 QPen pen = painter->pen(); 130 88 131 const int splitSize = 6; 89 132 90 for ( int i = 0; i < pointCount; i += splitSize ) 91 { 92 const int n = qMin( splitSize + 1, pointCount - i ); 93 painter->drawPolyline( points + i, n ); 133 if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy() 134 && !( painter->renderHints() & QPainter::Antialiasing ) ) 135 { 136 int k = 0; 137 138 for ( int i = k + 1; i < pointCount; i++ ) 139 { 140 const QPointF& p1 = points[i - 1]; 141 const QPointF& p2 = points[i]; 142 143 const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 ) 144 && qAbs( p2.x() - p1.x() ) <= 1; 145 146 if ( isBad || ( i - k >= splitSize ) ) 147 { 148 painter->drawPolyline( points + k, i - k + 1 ); 149 k = i; 150 } 151 } 152 153 painter->drawPolyline( points + k, pointCount - k ); 154 } 155 else 156 { 157 for ( int i = 0; i < pointCount; i += splitSize ) 158 { 159 const int n = qMin( splitSize + 1, pointCount - i ); 160 painter->drawPolyline( points + i, n ); 161 } 94 162 } 95 163 } … … 105 173 if ( !screenResolution.isValid() ) 106 174 { 107 QDesktopWidget *desktop = QApplication::desktop(); 175 /* 176 We might have screens with different resolutions. TODO ... 177 */ 178 #if QT_VERSION >= 0x060000 179 QScreen* screen = QGuiApplication::primaryScreen(); 180 if ( screen ) 181 { 182 screenResolution.setWidth( screen->logicalDotsPerInchX() ); 183 screenResolution.setHeight( screen->logicalDotsPerInchY() ); 184 } 185 #else 186 QDesktopWidget* desktop = QApplication::desktop(); 108 187 if ( desktop ) 109 188 { … … 111 190 screenResolution.setHeight( desktop->logicalDpiY() ); 112 191 } 192 #endif 113 193 } 114 194 … … 116 196 } 117 197 118 static inline void qwtUnscaleFont( QPainter *painter )198 static inline void qwtUnscaleFont( QPainter* painter ) 119 199 { 120 200 if ( painter->font().pixelSize() >= 0 ) … … 123 203 const QSize screenResolution = qwtScreenResolution(); 124 204 125 const QPaintDevice *pd = painter->device();205 const QPaintDevice* pd = painter->device(); 126 206 if ( pd->logicalDpiX() != screenResolution.width() || 127 207 pd->logicalDpiY() != screenResolution.height() ) 128 208 { 129 QFont pixelFont( painter->font (), QApplication::desktop() );209 QFont pixelFont = QwtPainter::scaledFont( painter->font() ); 130 210 pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() ); 131 211 … … 135 215 136 216 /*! 137 Check is the application is running with the X11 graphics system 138 that has some special capabilities that can be used for incremental 139 painting to a widget. 140 141 \return True, when the graphics system is X11 142 */ 217 Check is the application is running with the X11 graphics system 218 that has some special capabilities that can be used for incremental 219 painting to a widget. 220 221 \return True, when the graphics system is X11 222 */ 143 223 bool QwtPainter::isX11GraphicsSystem() 144 224 { … … 162 242 163 243 /*! 164 Check if the painter is using a paint engine, that aligns 165 coordinates to integers. Today these are all paint engines 166 beside QPaintEngine::Pdf and QPaintEngine::SVG. 167 168 If we have an integer based paint engine it is also 169 checked if the painter has a transformation matrix, 170 that rotates or scales. 171 172 \param painter Painter 173 \return true, when the painter is aligning 174 175 \sa setRoundingAlignment() 176 */ 177 bool QwtPainter::isAligning( QPainter *painter )244 Check if the painter is using a paint engine, that aligns 245 coordinates to integers. Today these are all paint engines 246 beside QPaintEngine::Pdf and QPaintEngine::SVG. 247 248 If we have an integer based paint engine it is also 249 checked if the painter has a transformation matrix, 250 that rotates or scales. 251 252 \param painter Painter 253 \return true, when the painter is aligning 254 255 \sa setRoundingAlignment() 256 */ 257 bool QwtPainter::isAligning( const QPainter* painter ) 178 258 { 179 259 if ( painter && painter->isActive() ) 180 260 { 181 switch ( painter->paintEngine()->type() ) 261 const QPaintEngine::Type type = 262 painter->paintEngine()->type(); 263 264 if ( type >= QPaintEngine::User ) 265 { 266 // we have no idea - better don't align 267 return false; 268 } 269 270 switch ( type ) 182 271 { 183 272 case QPaintEngine::Pdf: 184 273 case QPaintEngine::SVG: 274 #if 0 275 case QPaintEngine::MacPrinter: 276 #endif 185 277 return false; 186 278 187 default:; 188 } 189 190 const QTransform &tr = painter->transform(); 279 default: 280 break; 281 } 282 283 const QTransform& tr = painter->transform(); 191 284 if ( tr.isRotating() || tr.isScaling() ) 192 285 { … … 200 293 201 294 /*! 202 Enable whether coordinates should be rounded, before they are painted 203 to a paint engine that floors to integer values. For other paint engines 204 ( PDF, SVG ) this flag has no effect. 205 QwtPainter stores this flag only, the rounding itself is done in 206 the painting code ( f.e the plot items ). 207 208 The default setting is true. 209 210 \sa roundingAlignment(), isAligning() 211 */ 295 Enable whether coordinates should be rounded, before they are painted 296 to a paint engine that floors to integer values. For other paint engines 297 ( PDF, SVG ) this flag has no effect. 298 QwtPainter stores this flag only, the rounding itself is done in 299 the painting code ( f.e the plot items ). 300 301 The default setting is true. 302 303 \sa roundingAlignment(), isAligning() 304 */ 212 305 void QwtPainter::setRoundingAlignment( bool enable ) 213 306 { 214 d_roundingAlignment = enable;215 } 216 217 /*! 218 \brief En/Disable line splitting for the raster paint engine 219 220 In some Qt versions the raster paint engine paints polylines of many points 221 much faster when they are split in smaller chunks: f.e all supported Qt versions 222 >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2. 223 224 Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... ) 225 for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked 226 around in this mode. 227 228 The default setting is true. 229 230 \sa polylineSplitting() 231 */ 307 m_roundingAlignment = enable; 308 } 309 310 /*! 311 \brief En/Disable line splitting for the raster paint engine 312 313 In some Qt versions the raster paint engine paints polylines of many points 314 much faster when they are split in smaller chunks: f.e all supported Qt versions 315 >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2. 316 317 Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... ) 318 for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked 319 around in this mode. 320 321 The default setting is true. 322 323 \sa polylineSplitting() 324 */ 232 325 void QwtPainter::setPolylineSplitting( bool enable ) 233 326 { 234 d_polylineSplitting = enable;327 m_polylineSplitting = enable; 235 328 } 236 329 237 330 //! Wrapper for QPainter::drawPath() 238 void QwtPainter::drawPath( QPainter *painter, const QPainterPath&path )331 void QwtPainter::drawPath( QPainter* painter, const QPainterPath& path ) 239 332 { 240 333 painter->drawPath( path ); … … 242 335 243 336 //! Wrapper for QPainter::drawRect() 244 void QwtPainter::drawRect( QPainter *painter,double x, double y, double w, doubleh )337 void QwtPainter::drawRect( QPainter* painter, qreal x, qreal y, qreal w, qreal h ) 245 338 { 246 339 drawRect( painter, QRectF( x, y, w, h ) ); … … 248 341 249 342 //! Wrapper for QPainter::drawRect() 250 void QwtPainter::drawRect( QPainter *painter, const QRectF&rect )343 void QwtPainter::drawRect( QPainter* painter, const QRectF& rect ) 251 344 { 252 345 const QRectF r = rect; … … 277 370 278 371 //! Wrapper for QPainter::fillRect() 279 void QwtPainter::fillRect( QPainter *painter,280 const QRectF &rect, const QBrush&brush )372 void QwtPainter::fillRect( QPainter* painter, 373 const QRectF& rect, const QBrush& brush ) 281 374 { 282 375 if ( !rect.isValid() ) … … 287 380 288 381 /* 289 Performance of Qt4 is horrible for a non trivial brush. Without 290 clipping expect minutes or hours for repainting large rectangles 291 (might result from zooming) 292 */ 382 Performance of Qt4 is horrible for a non trivial brush. Without 383 clipping expect minutes or hours for repainting large rectangles 384 (might result from zooming) 385 */ 293 386 294 387 if ( deviceClipping ) … … 309 402 310 403 //! Wrapper for QPainter::drawPie() 311 void QwtPainter::drawPie( QPainter *painter, const QRectF&rect,404 void QwtPainter::drawPie( QPainter* painter, const QRectF& rect, 312 405 int a, int alen ) 313 406 { … … 321 414 322 415 //! Wrapper for QPainter::drawEllipse() 323 void QwtPainter::drawEllipse( QPainter *painter, const QRectF&rect )416 void QwtPainter::drawEllipse( QPainter* painter, const QRectF& rect ) 324 417 { 325 418 QRectF clipRect; … … 333 426 334 427 //! Wrapper for QPainter::drawText() 335 void QwtPainter::drawText( QPainter *painter, double x, double y,336 const QString&text )428 void QwtPainter::drawText( QPainter* painter, 429 qreal x, qreal y, const QString& text ) 337 430 { 338 431 drawText( painter, QPointF( x, y ), text ); … … 340 433 341 434 //! Wrapper for QPainter::drawText() 342 void QwtPainter::drawText( QPainter *painter, const QPointF&pos,343 const QString&text )435 void QwtPainter::drawText( QPainter* painter, const QPointF& pos, 436 const QString& text ) 344 437 { 345 438 QRectF clipRect; … … 357 450 358 451 //! Wrapper for QPainter::drawText() 359 void QwtPainter::drawText( QPainter *painter,360 double x, double y, double w, doubleh,361 int flags, const QString &text )452 void QwtPainter::drawText( QPainter* painter, 453 qreal x, qreal y, qreal w, qreal h, 454 int flags, const QString& text ) 362 455 { 363 456 drawText( painter, QRectF( x, y, w, h ), flags, text ); … … 365 458 366 459 //! Wrapper for QPainter::drawText() 367 void QwtPainter::drawText( QPainter *painter, const QRectF&rect,368 int flags, const QString&text )460 void QwtPainter::drawText( QPainter* painter, const QRectF& rect, 461 int flags, const QString& text ) 369 462 { 370 463 painter->save(); … … 377 470 378 471 /*! 379 Draw a text document into a rectangle 380 381 \param painter Painter 382 \param rect T raget rectangle383 \param flags Alignments/Text flags, see QPainter::drawText() 384 \param text Text document 385 */ 386 void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF&rect,387 int flags, const QTextDocument &text )388 { 389 QTextDocument *txt = text.clone();472 Draw a text document into a rectangle 473 474 \param painter Painter 475 \param rect Target rectangle 476 \param flags Alignments/Text flags, see QPainter::drawText() 477 \param text Text document 478 */ 479 void QwtPainter::drawSimpleRichText( QPainter* painter, const QRectF& rect, 480 int flags, const QTextDocument& text ) 481 { 482 QTextDocument* txt = text.clone(); 390 483 391 484 painter->save(); … … 397 490 const QSize res = qwtScreenResolution(); 398 491 399 const QPaintDevice *pd = painter->device();492 const QPaintDevice* pd = painter->device(); 400 493 if ( pd->logicalDpiX() != res.width() || 401 494 pd->logicalDpiY() != res.height() ) 402 495 { 403 496 QTransform transform; 404 transform.scale( res.width() / double( pd->logicalDpiX() ),405 res.height() / double( pd->logicalDpiY() ));497 transform.scale( res.width() / qreal( pd->logicalDpiX() ), 498 res.height() / qreal( pd->logicalDpiY() ) ); 406 499 407 500 painter->setWorldTransform( transform, true ); … … 415 508 QAbstractTextDocumentLayout* layout = txt->documentLayout(); 416 509 417 const doubleheight = layout->documentSize().height();418 doubley = unscaledRect.y();510 const qreal height = layout->documentSize().height(); 511 qreal y = unscaledRect.y(); 419 512 if ( flags & Qt::AlignBottom ) 420 513 y += ( unscaledRect.height() - height ); … … 436 529 437 530 //! Wrapper for QPainter::drawLine() 438 void QwtPainter::drawLine( QPainter *painter,439 const QPointF &p1, const QPointF&p2 )531 void QwtPainter::drawLine( QPainter* painter, 532 const QPointF& p1, const QPointF& p2 ) 440 533 { 441 534 QRectF clipRect; … … 456 549 457 550 //! Wrapper for QPainter::drawPolygon() 458 void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF&polygon )551 void QwtPainter::drawPolygon( QPainter* painter, const QPolygonF& polygon ) 459 552 { 460 553 QRectF clipRect; 461 554 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 462 555 463 QPolygonF cpa = polygon;464 556 if ( deviceClipping ) 465 cpa = QwtClipper::clipPolygonF( clipRect, polygon, true ); 466 467 painter->drawPolygon( cpa ); 557 { 558 painter->drawPolygon( 559 QwtClipper::clippedPolygonF( clipRect, polygon, true ) ); 560 } 561 else 562 { 563 painter->drawPolygon( polygon ); 564 } 468 565 } 469 566 470 567 //! Wrapper for QPainter::drawPolyline() 471 void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF&polygon )568 void QwtPainter::drawPolyline( QPainter* painter, const QPolygonF& polygon ) 472 569 { 473 570 QRectF clipRect; 474 571 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 475 572 476 QPolygonF cpa = polygon;477 573 if ( deviceClipping ) 478 cpa = QwtClipper::clipPolygonF( clipRect, cpa ); 479 480 qwtDrawPolyline<QPointF>( painter, 481 cpa.constData(), cpa.size(), d_polylineSplitting ); 574 { 575 const QPolygonF cpa = QwtClipper::clippedPolygonF( clipRect, polygon ); 576 577 qwtDrawPolyline< QPointF >( painter, 578 cpa.constData(), cpa.size(), m_polylineSplitting ); 579 } 580 else 581 { 582 qwtDrawPolyline< QPointF >( painter, 583 polygon.constData(), polygon.size(), m_polylineSplitting ); 584 } 482 585 } 483 586 484 587 //! Wrapper for QPainter::drawPolyline() 485 void QwtPainter::drawPolyline( QPainter *painter,486 const QPointF *points, int pointCount )588 void QwtPainter::drawPolyline( QPainter* painter, 589 const QPointF* points, int pointCount ) 487 590 { 488 591 QRectF clipRect; … … 492 595 { 493 596 QPolygonF polygon( pointCount ); 494 ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) ); 495 496 polygon =QwtClipper::clipPolygonF( clipRect, polygon );497 qwtDrawPolyline< QPointF>( painter,498 polygon.constData(), polygon.size(), d_polylineSplitting );597 std::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) ); 598 599 QwtClipper::clipPolygonF( clipRect, polygon ); 600 qwtDrawPolyline< QPointF >( painter, 601 polygon.constData(), polygon.size(), m_polylineSplitting ); 499 602 } 500 603 else 501 604 { 502 qwtDrawPolyline< QPointF>( painter, points, pointCount,d_polylineSplitting );605 qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting ); 503 606 } 504 607 } 505 608 506 609 //! Wrapper for QPainter::drawPolygon() 507 void QwtPainter::drawPolygon( QPainter *painter, const QPolygon&polygon )610 void QwtPainter::drawPolygon( QPainter* painter, const QPolygon& polygon ) 508 611 { 509 612 QRectF clipRect; 510 613 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 511 614 512 QPolygon cpa = polygon;513 615 if ( deviceClipping ) 514 cpa = QwtClipper::clipPolygon( clipRect, polygon, true ); 515 516 painter->drawPolygon( cpa ); 616 { 617 painter->drawPolygon( 618 QwtClipper::clippedPolygon( clipRect, polygon, true ) ); 619 } 620 else 621 { 622 painter->drawPolygon( polygon ); 623 } 517 624 } 518 625 519 626 //! Wrapper for QPainter::drawPolyline() 520 void QwtPainter::drawPolyline( QPainter *painter, const QPolygon&polygon )627 void QwtPainter::drawPolyline( QPainter* painter, const QPolygon& polygon ) 521 628 { 522 629 QRectF clipRect; 523 630 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 524 631 525 QPolygon cpa = polygon;526 632 if ( deviceClipping ) 527 cpa = QwtClipper::clipPolygon( clipRect, cpa ); 528 529 qwtDrawPolyline<QPoint>( painter, 530 cpa.constData(), cpa.size(), d_polylineSplitting ); 633 { 634 const QPolygon cpa = QwtClipper::clippedPolygon( clipRect, polygon ); 635 636 qwtDrawPolyline< QPoint >( painter, 637 cpa.constData(), cpa.size(), m_polylineSplitting ); 638 } 639 else 640 { 641 qwtDrawPolyline< QPoint >( painter, 642 polygon.constData(), polygon.size(), m_polylineSplitting ); 643 } 531 644 } 532 645 533 646 //! Wrapper for QPainter::drawPolyline() 534 void QwtPainter::drawPolyline( QPainter *painter,535 const QPoint *points, int pointCount )647 void QwtPainter::drawPolyline( QPainter* painter, 648 const QPoint* points, int pointCount ) 536 649 { 537 650 QRectF clipRect; … … 541 654 { 542 655 QPolygon polygon( pointCount ); 543 ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) ); 544 545 polygon =QwtClipper::clipPolygon( clipRect, polygon );546 qwtDrawPolyline< QPoint>( painter,547 polygon.constData(), polygon.size(), d_polylineSplitting );656 std::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) ); 657 658 QwtClipper::clipPolygon( clipRect, polygon ); 659 qwtDrawPolyline< QPoint >( painter, 660 polygon.constData(), polygon.size(), m_polylineSplitting ); 548 661 } 549 662 else 550 663 { 551 qwtDrawPolyline< QPoint>( painter, points, pointCount,d_polylineSplitting );664 qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting ); 552 665 } 553 666 } 554 667 555 668 //! Wrapper for QPainter::drawPoint() 556 void QwtPainter::drawPoint( QPainter *painter, const QPointF&pos )669 void QwtPainter::drawPoint( QPainter* painter, const QPointF& pos ) 557 670 { 558 671 QRectF clipRect; … … 566 679 567 680 //! Wrapper for QPainter::drawPoint() 568 void QwtPainter::drawPoint( QPainter *painter, const QPoint&pos )681 void QwtPainter::drawPoint( QPainter* painter, const QPoint& pos ) 569 682 { 570 683 QRectF clipRect; … … 573 686 if ( deviceClipping ) 574 687 { 575 const int minX = qCeil( clipRect.left() ); 576 const int maxX = qFloor( clipRect.right() ); 577 const int minY = qCeil( clipRect.top() ); 578 const int maxY = qFloor( clipRect.bottom() ); 688 const int minX = qwtCeil( clipRect.left() ); 689 const int maxX = qwtFloor( clipRect.right() ); 690 const int minY = qwtCeil( clipRect.top() ); 691 const int maxY = qwtFloor( clipRect.bottom() ); 579 692 580 693 if ( pos.x() < minX || pos.x() > maxX … … 589 702 590 703 //! Wrapper for QPainter::drawPoints() 591 void QwtPainter::drawPoints( QPainter *painter,592 const QPoint *points, int pointCount )704 void QwtPainter::drawPoints( QPainter* painter, 705 const QPoint* points, int pointCount ) 593 706 { 594 707 QRectF clipRect; … … 597 710 if ( deviceClipping ) 598 711 { 599 const int minX = qCeil( clipRect.left() ); 600 const int maxX = qFloor( clipRect.right() ); 601 const int minY = qCeil( clipRect.top() ); 602 const int maxY = qFloor( clipRect.bottom() ); 712 const int minX = qwtCeil( clipRect.left() ); 713 const int maxX = qwtFloor( clipRect.right() ); 714 const int minY = qwtCeil( clipRect.top() ); 715 const int maxY = qwtFloor( clipRect.bottom() ); 603 716 604 717 const QRect r( minX, minY, maxX - minX, maxY - minY ); 605 718 606 719 QPolygon clippedPolygon( pointCount ); 607 QPoint *clippedData = clippedPolygon.data();720 QPoint* clippedData = clippedPolygon.data(); 608 721 609 722 int numClippedPoints = 0; … … 622 735 623 736 //! Wrapper for QPainter::drawPoints() 624 void QwtPainter::drawPoints( QPainter *painter,625 const QPointF *points, int pointCount )737 void QwtPainter::drawPoints( QPainter* painter, 738 const QPointF* points, int pointCount ) 626 739 { 627 740 QRectF clipRect; … … 631 744 { 632 745 QPolygonF clippedPolygon( pointCount ); 633 QPointF *clippedData = clippedPolygon.data();746 QPointF* clippedData = clippedPolygon.data(); 634 747 635 748 int numClippedPoints = 0; … … 648 761 649 762 //! Wrapper for QPainter::drawImage() 650 void QwtPainter::drawImage( QPainter *painter,651 const QRectF &rect, const QImage&image )763 void QwtPainter::drawImage( QPainter* painter, 764 const QRectF& rect, const QImage& image ) 652 765 { 653 766 const QRect alignedRect = rect.toAlignedRect(); … … 669 782 670 783 //! Wrapper for QPainter::drawPixmap() 671 void QwtPainter::drawPixmap( QPainter *painter,672 const QRectF &rect, const QPixmap&pixmap )784 void QwtPainter::drawPixmap( QPainter* painter, 785 const QRectF& rect, const QPixmap& pixmap ) 673 786 { 674 787 const QRect alignedRect = rect.toAlignedRect(); … … 690 803 691 804 //! Draw a focus rectangle on a widget using its style. 692 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget*widget )805 void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget ) 693 806 { 694 807 drawFocusRect( painter, widget, widget->rect() ); … … 696 809 697 810 //! Draw a focus rectangle on a widget using its style. 698 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget*widget,699 const QRect &rect )811 void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget, 812 const QRect& rect ) 700 813 { 701 814 QStyleOptionFocusRect opt; 702 opt.init( widget ); 815 opt.initFrom( widget ); 703 816 opt.rect = rect; 704 817 opt.state |= QStyle::State_HasFocus; … … 710 823 711 824 /*! 712 Draw a round frame 713 714 \param painter Painter 715 \param rect Frame rectangle 716 \param palette QPalette::WindowText is used for plain borders 825 Draw a round frame 826 827 \param painter Painter 828 \param rect Frame rectangle 829 \param palette QPalette::WindowText is used for plain borders 717 830 QPalette::Dark and QPalette::Light for raised 718 831 or sunken borders 719 \param lineWidth Line width 720 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 721 */ 722 void QwtPainter::drawRoundFrame( QPainter *painter,723 const QRectF &rect, const QPalette&palette,832 \param lineWidth Line width 833 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 834 */ 835 void QwtPainter::drawRoundFrame( QPainter* painter, 836 const QRectF& rect, const QPalette& palette, 724 837 int lineWidth, int frameStyle ) 725 838 { … … 732 845 733 846 Style style = Plain; 734 if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )847 if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken ) 735 848 style = Sunken; 736 else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )849 else if ( (frameStyle& QFrame::Raised) == QFrame::Raised ) 737 850 style = Raised; 738 851 739 const doublelw2 = 0.5 * lineWidth;852 const qreal lw2 = 0.5 * lineWidth; 740 853 QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 ); 741 854 … … 776 889 777 890 /*! 778 Draw a rectangular frame 779 780 \param painter Painter 781 \param rect Frame rectangle 782 \param palette Palette 783 \param foregroundRole Foreground role used for QFrame::Plain 784 \param frameWidth Frame width 785 \param midLineWidth Used for QFrame::Box 786 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 787 */ 788 void QwtPainter::drawFrame( QPainter *painter, const QRectF&rect,789 const QPalette &palette, QPalette::ColorRole foregroundRole,891 Draw a rectangular frame 892 893 \param painter Painter 894 \param rect Frame rectangle 895 \param palette Palette 896 \param foregroundRole Foreground role used for QFrame::Plain 897 \param frameWidth Frame width 898 \param midLineWidth Used for QFrame::Box 899 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 900 */ 901 void QwtPainter::drawFrame( QPainter* painter, const QRectF& rect, 902 const QPalette& palette, QPalette::ColorRole foregroundRole, 790 903 int frameWidth, int midLineWidth, int frameStyle ) 791 904 { … … 882 995 painter->drawPath( path5 ); 883 996 } 884 #if 0885 // qDrawWinPanel doesn't result in something nice886 // on a scalable document like PDF. Better draw a887 // Panel.888 889 else if ( shape == QFrame::WinPanel )890 {891 painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );892 qDrawWinPanel ( painter, rect.toRect(), palette,893 frameStyle & QFrame::Sunken );894 }895 else if ( shape == QFrame::StyledPanel )896 {897 }898 #endif899 997 else 900 998 { … … 942 1040 943 1041 /*! 944 Draw a rectangular frame with rounded borders 945 946 \param painter Painter 947 \param rect Frame rectangle 948 \param xRadius x-radius of the ellipses defining the corners 949 \param yRadius y-radius of the ellipses defining the corners 950 \param palette QPalette::WindowText is used for plain borders 1042 Draw a rectangular frame with rounded borders 1043 1044 \param painter Painter 1045 \param rect Frame rectangle 1046 \param xRadius x-radius of the ellipses defining the corners 1047 \param yRadius y-radius of the ellipses defining the corners 1048 \param palette QPalette::WindowText is used for plain borders 951 1049 QPalette::Dark and QPalette::Light for raised 952 1050 or sunken borders 953 \param lineWidth Line width 954 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 955 */ 956 957 void QwtPainter::drawRoundedFrame( QPainter *painter,958 const QRectF &rect, doublexRadius,doubleyRadius,959 const QPalette &palette, int lineWidth, int frameStyle )1051 \param lineWidth Line width 1052 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 1053 */ 1054 1055 void QwtPainter::drawRoundedFrame( QPainter* painter, 1056 const QRectF& rect, qreal xRadius, qreal yRadius, 1057 const QPalette& palette, int lineWidth, int frameStyle ) 960 1058 { 961 1059 painter->save(); … … 963 1061 painter->setBrush( Qt::NoBrush ); 964 1062 965 doublelw2 = lineWidth * 0.5;1063 qreal lw2 = lineWidth * 0.5; 966 1064 QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 ); 967 1065 … … 977 1075 978 1076 Style style = Plain; 979 if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )1077 if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken ) 980 1078 style = Sunken; 981 else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )1079 else if ( (frameStyle& QFrame::Raised) == QFrame::Raised ) 982 1080 style = Raised; 983 1081 … … 993 1091 pathList[ 2 * i ].moveTo( 994 1092 path.elementAt(j - 1).x, path.elementAt( j - 1 ).y 995 ); 1093 ); 996 1094 997 1095 pathList[ 2 * i ].cubicTo( … … 1002 1100 pathList[ 2 * i + 1 ].moveTo( 1003 1101 path.elementAt(j + 2).x, path.elementAt(j + 2).y 1004 ); 1102 ); 1005 1103 pathList[ 2 * i + 1 ].lineTo( 1006 1104 path.elementAt(j + 3).x, path.elementAt(j + 3).y 1007 ); 1105 ); 1008 1106 } 1009 1107 … … 1086 1184 1087 1185 /*! 1088 Draw a color bar into a rectangle 1089 1090 \param painter Painter 1091 \param colorMap Color map 1092 \param interval Value range 1093 \param scaleMap Scale map 1094 \param orientation Orientation 1095 \param rect T raget rectangle1096 */ 1097 void QwtPainter::drawColorBar( QPainter *painter,1098 const QwtColorMap&colorMap, const QwtInterval&interval,1099 const QwtScaleMap&scaleMap, Qt::Orientation orientation,1100 const QRectF&rect )1101 { 1102 QVector< QRgb> colorTable;1186 Draw a color bar into a rectangle 1187 1188 \param painter Painter 1189 \param colorMap Color map 1190 \param interval Value range 1191 \param scaleMap Scale map 1192 \param orientation Orientation 1193 \param rect Target rectangle 1194 */ 1195 void QwtPainter::drawColorBar( QPainter* painter, 1196 const QwtColorMap& colorMap, const QwtInterval& interval, 1197 const QwtScaleMap& scaleMap, Qt::Orientation orientation, 1198 const QRectF& rect ) 1199 { 1200 QVector< QRgb > colorTable; 1103 1201 if ( colorMap.format() == QwtColorMap::Indexed ) 1104 colorTable = colorMap.colorTable ( interval);1202 colorTable = colorMap.colorTable256(); 1105 1203 1106 1204 QColor c; … … 1109 1207 1110 1208 /* 1111 We paint to a pixmap first to have something scalable for printing 1112 ( f.e. in a Pdf document ) 1209 We paint to a pixmap first to have something scalable for printing 1210 ( f.e. in a Pdf document ) 1113 1211 */ 1114 1212 … … 1131 1229 c.setRgba( colorMap.rgb( interval, value ) ); 1132 1230 else 1133 c = colorTable[colorMap.colorIndex( interval, value )]; 1231 c = colorTable[colorMap.colorIndex( 256, interval, value )]; 1134 1232 1135 1233 pmPainter.setPen( c ); … … 1149 1247 c.setRgba( colorMap.rgb( interval, value ) ); 1150 1248 else 1151 c = colorTable[colorMap.colorIndex( interval, value )]; 1249 c = colorTable[colorMap.colorIndex( 256, interval, value )]; 1152 1250 1153 1251 pmPainter.setPen( c ); … … 1160 1258 } 1161 1259 1162 static inline void qwtFillRect( const QWidget *widget, QPainter*painter,1163 const QRect &rect, const QBrush&brush)1260 static inline void qwtFillRect( const QWidget* widget, QPainter* painter, 1261 const QRect& rect, const QBrush& brush) 1164 1262 { 1165 1263 if ( brush.style() == Qt::TexturePattern ) … … 1168 1266 1169 1267 painter->setClipRect( rect ); 1170 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); 1268 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() ); 1171 1269 1172 1270 painter->restore(); … … 1189 1287 1190 1288 /*! 1191 Fill a pixmap with the content of a widget 1192 1193 In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy 1194 for backgrounds with gradients. Thus fillPixmap() offers 1195 an alternative implementation. 1196 1197 \param widget Widget 1198 \param pixmap Pixmap to be filled 1199 \param offset Offset 1200 1201 \sa QPixmap::fill() 1202 */ 1203 void QwtPainter::fillPixmap( const QWidget *widget,1204 QPixmap &pixmap, const QPoint&offset )1289 Fill a pixmap with the content of a widget 1290 1291 In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy 1292 for backgrounds with gradients. Thus fillPixmap() offers 1293 an alternative implementation. 1294 1295 \param widget Widget 1296 \param pixmap Pixmap to be filled 1297 \param offset Offset 1298 1299 \sa QPixmap::fill() 1300 */ 1301 void QwtPainter::fillPixmap( const QWidget* widget, 1302 QPixmap& pixmap, const QPoint& offset ) 1205 1303 { 1206 1304 const QRect rect( offset, pixmap.size() ); … … 1233 1331 1234 1332 /*! 1235 Fill rect with the background of a widget 1236 1237 \param painter Painter 1238 \param rect Rectangle to be filled 1239 \param widget Widget 1240 1241 \sa QStyle::PE_Widget, QWidget::backgroundRole() 1242 */ 1243 void QwtPainter::drawBackgound( QPainter *painter,1244 const QRectF &rect, const QWidget*widget )1333 Fill rect with the background of a widget 1334 1335 \param painter Painter 1336 \param rect Rectangle to be filled 1337 \param widget Widget 1338 1339 \sa QStyle::PE_Widget, QWidget::backgroundRole() 1340 */ 1341 void QwtPainter::drawBackgound( QPainter* painter, 1342 const QRectF& rect, const QWidget* widget ) 1245 1343 { 1246 1344 if ( widget->testAttribute( Qt::WA_StyledBackground ) ) … … 1263 1361 1264 1362 /*! 1265 \return A pixmap that can be used as backing store 1266 1267 \param widget Widget, for which the backingstore is intended 1268 \param size Size of the pixmap 1269 */ 1270 QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size ) 1363 Distance appropriate for drawing a subsequent character after text. 1364 1365 \param fontMetrics Font metrics 1366 \param text Text 1367 \return horizontal advance in pixels 1368 */ 1369 int QwtPainter::horizontalAdvance( 1370 const QFontMetrics& fontMetrics, const QString& text ) 1371 { 1372 #if QT_VERSION >= 0x050b00 1373 return fontMetrics.horizontalAdvance( text ); 1374 #else 1375 return fontMetrics.width( text ); 1376 #endif 1377 1378 } 1379 1380 /*! 1381 Distance appropriate for drawing a subsequent character after text. 1382 1383 \param fontMetrics Font metrics 1384 \param text Text 1385 \return horizontal advance in pixels 1386 */ 1387 qreal QwtPainter::horizontalAdvance( 1388 const QFontMetricsF& fontMetrics, const QString& text ) 1389 { 1390 #if QT_VERSION >= 0x050b00 1391 return fontMetrics.horizontalAdvance( text ); 1392 #else 1393 return fontMetrics.width( text ); 1394 #endif 1395 } 1396 1397 /*! 1398 Distance appropriate for drawing a subsequent character after ch. 1399 1400 \param fontMetrics Font metrics 1401 \param ch Character 1402 \return horizontal advance in pixels 1403 */ 1404 int QwtPainter::horizontalAdvance( 1405 const QFontMetrics& fontMetrics, QChar ch ) 1406 { 1407 #if QT_VERSION >= 0x050b00 1408 return fontMetrics.horizontalAdvance( ch ); 1409 #else 1410 return fontMetrics.width( ch ); 1411 #endif 1412 } 1413 1414 /*! 1415 Distance appropriate for drawing a subsequent character after ch. 1416 1417 \param fontMetrics Font metrics 1418 \param ch Character 1419 \return horizontal advance in pixels 1420 */ 1421 qreal QwtPainter::horizontalAdvance( 1422 const QFontMetricsF& fontMetrics, QChar ch ) 1423 { 1424 #if QT_VERSION >= 0x050b00 1425 return fontMetrics.horizontalAdvance( ch ); 1426 #else 1427 return fontMetrics.width( ch ); 1428 #endif 1429 } 1430 1431 /*! 1432 Adjust the DPI value of font according to the DPI value of the paint device 1433 1434 \param font Unscaled font 1435 \param paintDevice Paint device providing a DPI value. If paintDevice == null 1436 the DPI value of the primary screen will be used 1437 1438 \return Font being adjusted to the DPI value of the paint device 1439 */ 1440 QFont QwtPainter::scaledFont( const QFont& font, const QPaintDevice* paintDevice ) 1441 { 1442 if ( paintDevice == NULL ) 1443 { 1444 #if QT_VERSION < 0x060000 1445 paintDevice = QApplication::desktop(); 1446 #else 1447 class PaintDevice : public QPaintDevice 1448 { 1449 virtual QPaintEngine* paintEngine() const QWT_OVERRIDE 1450 { 1451 return NULL; 1452 } 1453 1454 virtual int metric( PaintDeviceMetric metric ) const QWT_OVERRIDE 1455 { 1456 if ( metric == PdmDpiY ) 1457 { 1458 QScreen* screen = QGuiApplication::primaryScreen(); 1459 if ( screen ) 1460 { 1461 return screen->logicalDotsPerInchY(); 1462 } 1463 } 1464 1465 return QPaintDevice::metric( metric ); 1466 } 1467 }; 1468 1469 static PaintDevice dummyPaintDevice; 1470 paintDevice = &dummyPaintDevice; 1471 #endif 1472 } 1473 1474 return QFont( font, const_cast< QPaintDevice* >( paintDevice ) ); 1475 } 1476 1477 /*! 1478 \return Pixel ratio for a paint device 1479 \param paintDevice Paint device 1480 */ 1481 qreal QwtPainter::devicePixelRatio( const QPaintDevice* paintDevice ) 1482 { 1483 qreal pixelRatio = 0.0; 1484 1485 #if QT_VERSION >= 0x050100 1486 if ( paintDevice ) 1487 { 1488 #if QT_VERSION >= 0x050600 1489 pixelRatio = paintDevice->devicePixelRatioF(); 1490 #else 1491 pixelRatio = paintDevice->devicePixelRatio(); 1492 #endif 1493 } 1494 #else 1495 Q_UNUSED( paintDevice ) 1496 #endif 1497 1498 #if QT_VERSION >= 0x050000 1499 if ( pixelRatio == 0.0 && qApp ) 1500 pixelRatio = qApp->devicePixelRatio(); 1501 #endif 1502 1503 if ( pixelRatio == 0.0 ) 1504 pixelRatio = 1.0; 1505 1506 return pixelRatio; 1507 } 1508 1509 /*! 1510 \return A pixmap that can be used as backing store 1511 1512 \param widget Widget, for which the backingstore is intended 1513 \param size Size of the pixmap 1514 */ 1515 QPixmap QwtPainter::backingStore( QWidget* widget, const QSize& size ) 1271 1516 { 1272 1517 QPixmap pm; 1273 1518 1274 #define QWT_HIGH_DPI 1 1275 1276 #if QT_VERSION >= 0x050000 && QWT_HIGH_DPI 1277 qreal pixelRatio = 1.0; 1278 1279 if ( widget && widget->windowHandle() ) 1280 { 1281 #if QT_VERSION < 0x050100 1282 pixelRatio = widget->windowHandle()->devicePixelRatio(); 1283 #else 1284 pixelRatio = widget->devicePixelRatio(); 1285 #endif 1286 } 1287 else 1288 { 1289 if ( qApp ) 1290 pixelRatio = qApp->devicePixelRatio(); 1291 } 1519 #if QT_VERSION >= 0x050000 1520 const qreal pixelRatio = QwtPainter::devicePixelRatio( widget ); 1292 1521 1293 1522 pm = QPixmap( size * pixelRatio ); 1294 1523 pm.setDevicePixelRatio( pixelRatio ); 1295 1524 #else 1296 Q_UNUSED( widget )1297 1525 pm = QPixmap( size ); 1298 1526 #endif 1299 1527 1300 #if QT_VERSION < 0x0500001301 1528 #ifdef Q_WS_X11 1302 1529 if ( widget && isX11GraphicsSystem() ) … … 1305 1532 pm.x11SetScreen( widget->x11Info().screen() ); 1306 1533 } 1307 #endif 1534 #else 1535 Q_UNUSED( widget ) 1308 1536 #endif 1309 1537 1310 1538 return pm; 1311 1539 } 1312 -
trunk/BNC/qwt/qwt_painter.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 15 #include <qp oint.h>16 #include <q rect.h>15 #include <qpalette.h> 16 #include <qpolygon.h> 17 17 #include <qpen.h> 18 #include <qline.h> 19 #include <qpalette.h> 20 21 class QPainter; 22 class QBrush; 23 class QColor; 24 class QWidget; 25 class QPolygonF; 26 class QRectF; 27 class QImage; 28 class QPixmap; 18 29 19 class QwtScaleMap; 30 20 class QwtColorMap; 31 21 class QwtInterval; 32 22 23 class QPainter; 24 class QBrush; 25 class QWidget; 26 class QImage; 27 class QPixmap; 28 class QFontMetrics; 29 class QFontMetricsF; 33 30 class QTextDocument; 34 31 class QPainterPath; 35 32 36 33 /*! 37 \brief A collection of QPainter workarounds 38 */ 34 \brief A collection of QPainter workarounds 35 */ 39 36 class QWT_EXPORT QwtPainter 40 37 { 41 public: 38 public: 42 39 static void setPolylineSplitting( bool ); 43 40 static bool polylineSplitting(); … … 45 42 static void setRoundingAlignment( bool ); 46 43 static bool roundingAlignment(); 47 static bool roundingAlignment(QPainter *);48 49 static void drawText( QPainter *, double x, doubley, const QString& );50 static void drawText( QPainter *, const QPointF&, const QString& );51 static void drawText( QPainter *, double x, double y, double w, doubleh,52 int flags, const QString & );53 static void drawText( QPainter *, const QRectF&,54 int flags, const QString & );44 static bool roundingAlignment( const QPainter* ); 45 46 static void drawText( QPainter*, qreal x, qreal y, const QString& ); 47 static void drawText( QPainter*, const QPointF&, const QString& ); 48 static void drawText( QPainter*, qreal x, qreal y, qreal w, qreal h, 49 int flags, const QString& ); 50 static void drawText( QPainter*, const QRectF&, 51 int flags, const QString& ); 55 52 56 53 #ifndef QT_NO_RICHTEXT 57 static void drawSimpleRichText( QPainter *, const QRectF&,58 int flags, const QTextDocument & );54 static void drawSimpleRichText( QPainter*, const QRectF&, 55 int flags, const QTextDocument& ); 59 56 #endif 60 57 61 static void drawRect( QPainter *, double x, double y, double w, doubleh );62 static void drawRect( QPainter *, const QRectF&rect );63 static void fillRect( QPainter *, const QRectF&, const QBrush& );64 65 static void drawEllipse( QPainter *, const QRectF& );66 static void drawPie( QPainter *, const QRectF&, int a, int alen );67 68 static void drawLine( QPainter *, double x1, double y1, double x2, doubley2 );69 static void drawLine( QPainter *, const QPointF&p1, const QPointF&p2 );70 static void drawLine( QPainter *, const QLineF& );71 72 static void drawPolygon( QPainter *, const QPolygonF& );73 static void drawPolyline( QPainter *, const QPolygonF& );74 static void drawPolyline( QPainter *, const QPointF*, int pointCount );75 76 static void drawPolygon( QPainter *, const QPolygon& );77 static void drawPolyline( QPainter *, const QPolygon& );78 static void drawPolyline( QPainter *, const QPoint*, int pointCount );79 80 static void drawPoint( QPainter *, const QPoint& );81 static void drawPoints( QPainter *, const QPolygon& );82 static void drawPoints( QPainter *, const QPoint*, int pointCount );83 84 static void drawPoint( QPainter *, double x, doubley );85 static void drawPoint( QPainter *, const QPointF& );86 static void drawPoints( QPainter *, const QPolygonF& );87 static void drawPoints( QPainter *, const QPointF*, int pointCount );88 89 static void drawPath( QPainter *, const QPainterPath& );90 static void drawImage( QPainter *, const QRectF&, const QImage& );91 static void drawPixmap( QPainter *, const QRectF&, const QPixmap& );92 93 static void drawRoundFrame( QPainter *,94 const QRectF &, const QPalette&, int lineWidth, int frameStyle );95 96 static void drawRoundedFrame( QPainter *,97 const QRectF &, doublexRadius,doubleyRadius,98 const QPalette &, int lineWidth, int frameStyle );99 100 static void drawFrame( QPainter *, const QRectF&rect,101 const QPalette &palette, QPalette::ColorRole foregroundRole,102 int frameWidth, int midLineWidth, int frameStyle );103 104 static void drawFocusRect( QPainter *, const QWidget* );105 static void drawFocusRect( QPainter *, const QWidget*, const QRect& );106 107 static void drawColorBar( QPainter *painter,108 const QwtColorMap &, const QwtInterval&,109 const QwtScaleMap &, Qt::Orientation, const QRectF& );110 111 static bool isAligning( QPainter *painter);58 static void drawRect( QPainter*, qreal x, qreal y, qreal w, qreal h ); 59 static void drawRect( QPainter*, const QRectF& rect ); 60 static void fillRect( QPainter*, const QRectF&, const QBrush& ); 61 62 static void drawEllipse( QPainter*, const QRectF& ); 63 static void drawPie( QPainter*, const QRectF& r, int a, int alen ); 64 65 static void drawLine( QPainter*, qreal x1, qreal y1, qreal x2, qreal y2 ); 66 static void drawLine( QPainter*, const QPointF& p1, const QPointF& p2 ); 67 static void drawLine( QPainter*, const QLineF& ); 68 69 static void drawPolygon( QPainter*, const QPolygonF& ); 70 static void drawPolyline( QPainter*, const QPolygonF& ); 71 static void drawPolyline( QPainter*, const QPointF*, int pointCount ); 72 73 static void drawPolygon( QPainter*, const QPolygon& ); 74 static void drawPolyline( QPainter*, const QPolygon& ); 75 static void drawPolyline( QPainter*, const QPoint*, int pointCount ); 76 77 static void drawPoint( QPainter*, const QPoint& ); 78 static void drawPoints( QPainter*, const QPolygon& ); 79 static void drawPoints( QPainter*, const QPoint*, int pointCount ); 80 81 static void drawPoint( QPainter*, qreal x, qreal y ); 82 static void drawPoint( QPainter*, const QPointF& ); 83 static void drawPoints( QPainter*, const QPolygonF& ); 84 static void drawPoints( QPainter*, const QPointF*, int pointCount ); 85 86 static void drawPath( QPainter*, const QPainterPath& ); 87 static void drawImage( QPainter*, const QRectF&, const QImage& ); 88 static void drawPixmap( QPainter*, const QRectF&, const QPixmap& ); 89 90 static void drawRoundFrame( QPainter*, 91 const QRectF&, const QPalette&, int lineWidth, int frameStyle ); 92 93 static void drawRoundedFrame( QPainter*, 94 const QRectF&, qreal xRadius, qreal yRadius, 95 const QPalette&, int lineWidth, int frameStyle ); 96 97 static void drawFrame( QPainter*, const QRectF& rect, 98 const QPalette& palette, QPalette::ColorRole foregroundRole, 99 int lineWidth, int midLineWidth, int frameStyle ); 100 101 static void drawFocusRect( QPainter*, const QWidget* ); 102 static void drawFocusRect( QPainter*, const QWidget*, const QRect& ); 103 104 static void drawColorBar( QPainter*, 105 const QwtColorMap&, const QwtInterval&, 106 const QwtScaleMap&, Qt::Orientation, const QRectF& ); 107 108 static bool isAligning( const QPainter*); 112 109 static bool isX11GraphicsSystem(); 113 110 114 static void fillPixmap( const QWidget *, 115 QPixmap &, const QPoint &offset = QPoint() ); 116 117 static void drawBackgound( QPainter *painter, 118 const QRectF &rect, const QWidget *widget ); 119 120 static QPixmap backingStore( QWidget *, const QSize & ); 121 122 private: 123 static bool d_polylineSplitting; 124 static bool d_roundingAlignment; 111 static void fillPixmap( const QWidget*, 112 QPixmap&, const QPoint& offset = QPoint() ); 113 114 static void drawBackgound( QPainter*, 115 const QRectF&, const QWidget* ); 116 117 static QPixmap backingStore( QWidget*, const QSize& ); 118 static qreal devicePixelRatio( const QPaintDevice* ); 119 120 static qreal effectivePenWidth( const QPen& ); 121 122 static int horizontalAdvance( const QFontMetrics&, const QString& ); 123 static qreal horizontalAdvance( const QFontMetricsF&, const QString& ); 124 125 static int horizontalAdvance( const QFontMetrics&, QChar ); 126 static qreal horizontalAdvance( const QFontMetricsF&, QChar ); 127 128 static QFont scaledFont( const QFont&, const QPaintDevice* = NULL ); 129 130 private: 131 static bool m_polylineSplitting; 132 static bool m_roundingAlignment; 125 133 }; 126 134 127 135 //! Wrapper for QPainter::drawPoint() 128 inline void QwtPainter::drawPoint( QPainter *painter,double x, doubley )136 inline void QwtPainter::drawPoint( QPainter* painter, qreal x, qreal y ) 129 137 { 130 138 QwtPainter::drawPoint( painter, QPointF( x, y ) ); … … 132 140 133 141 //! Wrapper for QPainter::drawPoints() 134 inline void QwtPainter::drawPoints( QPainter *painter, const QPolygon&polygon )142 inline void QwtPainter::drawPoints( QPainter* painter, const QPolygon& polygon ) 135 143 { 136 144 drawPoints( painter, polygon.data(), polygon.size() ); … … 138 146 139 147 //! Wrapper for QPainter::drawPoints() 140 inline void QwtPainter::drawPoints( QPainter *painter, const QPolygonF&polygon )148 inline void QwtPainter::drawPoints( QPainter* painter, const QPolygonF& polygon ) 141 149 { 142 150 drawPoints( painter, polygon.data(), polygon.size() ); … … 144 152 145 153 //! Wrapper for QPainter::drawLine() 146 inline void QwtPainter::drawLine( QPainter *painter,147 double x1, double y1, double x2, doubley2 )154 inline void QwtPainter::drawLine( QPainter* painter, 155 qreal x1, qreal y1, qreal x2, qreal y2 ) 148 156 { 149 157 QwtPainter::drawLine( painter, QPointF( x1, y1 ), QPointF( x2, y2 ) ); … … 151 159 152 160 //! Wrapper for QPainter::drawLine() 153 inline void QwtPainter::drawLine( QPainter *painter, const QLineF&line )161 inline void QwtPainter::drawLine( QPainter* painter, const QLineF& line ) 154 162 { 155 163 QwtPainter::drawLine( painter, line.p1(), line.p2() ); … … 157 165 158 166 /*! 159 \return True, when line splitting for the raster paint engine is enabled. 160 \sa setPolylineSplitting() 161 */ 167 \return True, when line splitting for the raster paint engine is enabled. 168 \sa setPolylineSplitting() 169 */ 162 170 inline bool QwtPainter::polylineSplitting() 163 171 { 164 return d_polylineSplitting;165 } 166 167 /*! 168 Check whether coordinates should be rounded, before they are painted 169 to a paint engine that rounds to integer values. For other paint engines 170 ( PDF, SVG ), this flag has no effect. 171 172 \return True, when rounding is enabled 173 \sa setRoundingAlignment(), isAligning() 174 */ 172 return m_polylineSplitting; 173 } 174 175 /*! 176 Check whether coordinates should be rounded, before they are painted 177 to a paint engine that rounds to integer values. For other paint engines 178 ( PDF, SVG ), this flag has no effect. 179 180 \return True, when rounding is enabled 181 \sa setRoundingAlignment(), isAligning() 182 */ 175 183 inline bool QwtPainter::roundingAlignment() 176 184 { 177 return d_roundingAlignment; 178 } 179 180 /*! 181 \return roundingAlignment() && isAligning(painter); 182 \param painter Painter 183 */ 184 inline bool QwtPainter::roundingAlignment(QPainter *painter) 185 { 186 return d_roundingAlignment && isAligning(painter); 187 } 185 return m_roundingAlignment; 186 } 187 188 /*! 189 \return roundingAlignment() && isAligning(painter); 190 \param painter Painter 191 */ 192 inline bool QwtPainter::roundingAlignment( const QPainter* painter ) 193 { 194 return m_roundingAlignment && isAligning(painter); 195 } 196 197 /*! 198 \return pen.widthF() expanded to at least 1.0 199 \param pen Pen 200 */ 201 inline qreal QwtPainter::effectivePenWidth( const QPen& pen ) 202 { 203 const qreal width = pen.widthF(); 204 return ( width < 1.0 ) ? 1.0 : width; 205 } 206 188 207 #endif -
trunk/BNC/qwt/qwt_painter_command.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 12 12 //! Construct an invalid command 13 QwtPainterCommand::QwtPainterCommand() :14 d_type( Invalid )13 QwtPainterCommand::QwtPainterCommand() 14 : m_type( Invalid ) 15 15 { 16 16 } 17 17 18 18 //! Copy constructor 19 QwtPainterCommand::QwtPainterCommand( const QPainterPath &path ):20 d_type( Path )21 { 22 d_path = new QPainterPath( path );23 } 24 25 /*! 26 Constructor for Pixmap paint operation 27 28 \param rect Target rectangle 29 \param pixmap Pixmap 30 \param subRect Rectangle inside the pixmap 31 32 \sa QPainter::drawPixmap() 33 */ 34 QwtPainterCommand::QwtPainterCommand( const QRectF &rect,35 const QPixmap &pixmap, const QRectF& subRect ):36 d_type( Pixmap )37 { 38 d_pixmapData = new PixmapData();39 d_pixmapData->rect = rect;40 d_pixmapData->pixmap = pixmap;41 d_pixmapData->subRect = subRect;42 } 43 44 /*! 45 Constructor for Image paint operation 46 47 \param rect Target rectangle 48 \param image Image 49 \param subRect Rectangle inside the image 50 \param flags Conversion flags 51 52 \sa QPainter::drawImage() 53 */ 54 QwtPainterCommand::QwtPainterCommand( const QRectF &rect,55 const QImage &image, const QRectF& subRect,56 Qt::ImageConversionFlags flags ) :57 d_type( Image )58 { 59 d_imageData = new ImageData();60 d_imageData->rect = rect;61 d_imageData->image = image;62 d_imageData->subRect = subRect;63 d_imageData->flags = flags;64 } 65 66 /*! 67 Constructor for State paint operation 68 \param state Paint engine state 69 */ 70 QwtPainterCommand::QwtPainterCommand( const QPaintEngineState &state ):71 d_type( State )72 { 73 d_stateData = new StateData();74 75 d_stateData->flags = state.state();76 77 if ( d_stateData->flags & QPaintEngine::DirtyPen )78 d_stateData->pen = state.pen();79 80 if ( d_stateData->flags & QPaintEngine::DirtyBrush )81 d_stateData->brush = state.brush();82 83 if ( d_stateData->flags & QPaintEngine::DirtyBrushOrigin )84 d_stateData->brushOrigin = state.brushOrigin();85 86 if ( d_stateData->flags & QPaintEngine::DirtyFont )87 d_stateData->font = state.font();88 89 if ( d_stateData->flags & QPaintEngine::DirtyBackground )90 { 91 d_stateData->backgroundMode = state.backgroundMode();92 d_stateData->backgroundBrush = state.backgroundBrush();93 } 94 95 if ( d_stateData->flags & QPaintEngine::DirtyTransform )96 d_stateData->transform = state.transform();97 98 if ( d_stateData->flags & QPaintEngine::DirtyClipEnabled )99 d_stateData->isClipEnabled = state.isClipEnabled();100 101 if ( d_stateData->flags & QPaintEngine::DirtyClipRegion )102 { 103 d_stateData->clipRegion = state.clipRegion();104 d_stateData->clipOperation = state.clipOperation();105 } 106 107 if ( d_stateData->flags & QPaintEngine::DirtyClipPath )108 { 109 d_stateData->clipPath = state.clipPath();110 d_stateData->clipOperation = state.clipOperation();111 } 112 113 if ( d_stateData->flags & QPaintEngine::DirtyHints )114 d_stateData->renderHints = state.renderHints();115 116 if ( d_stateData->flags & QPaintEngine::DirtyCompositionMode )117 d_stateData->compositionMode = state.compositionMode();118 119 if ( d_stateData->flags & QPaintEngine::DirtyOpacity )120 d_stateData->opacity = state.opacity();121 } 122 123 /*! 124 Copy constructor 125 \param other Command to be copied 126 127 */ 128 QwtPainterCommand::QwtPainterCommand(const QwtPainterCommand &other)19 QwtPainterCommand::QwtPainterCommand( const QPainterPath& path ) 20 : m_type( Path ) 21 { 22 m_path = new QPainterPath( path ); 23 } 24 25 /*! 26 Constructor for Pixmap paint operation 27 28 \param rect Target rectangle 29 \param pixmap Pixmap 30 \param subRect Rectangle inside the pixmap 31 32 \sa QPainter::drawPixmap() 33 */ 34 QwtPainterCommand::QwtPainterCommand( const QRectF& rect, 35 const QPixmap& pixmap, const QRectF& subRect ) 36 : m_type( Pixmap ) 37 { 38 m_pixmapData = new PixmapData(); 39 m_pixmapData->rect = rect; 40 m_pixmapData->pixmap = pixmap; 41 m_pixmapData->subRect = subRect; 42 } 43 44 /*! 45 Constructor for Image paint operation 46 47 \param rect Target rectangle 48 \param image Image 49 \param subRect Rectangle inside the image 50 \param flags Conversion flags 51 52 \sa QPainter::drawImage() 53 */ 54 QwtPainterCommand::QwtPainterCommand( const QRectF& rect, 55 const QImage& image, const QRectF& subRect, 56 Qt::ImageConversionFlags flags ) 57 : m_type( Image ) 58 { 59 m_imageData = new ImageData(); 60 m_imageData->rect = rect; 61 m_imageData->image = image; 62 m_imageData->subRect = subRect; 63 m_imageData->flags = flags; 64 } 65 66 /*! 67 Constructor for State paint operation 68 \param state Paint engine state 69 */ 70 QwtPainterCommand::QwtPainterCommand( const QPaintEngineState& state ) 71 : m_type( State ) 72 { 73 m_stateData = new StateData(); 74 75 m_stateData->flags = state.state(); 76 77 if ( m_stateData->flags & QPaintEngine::DirtyPen ) 78 m_stateData->pen = state.pen(); 79 80 if ( m_stateData->flags & QPaintEngine::DirtyBrush ) 81 m_stateData->brush = state.brush(); 82 83 if ( m_stateData->flags & QPaintEngine::DirtyBrushOrigin ) 84 m_stateData->brushOrigin = state.brushOrigin(); 85 86 if ( m_stateData->flags & QPaintEngine::DirtyFont ) 87 m_stateData->font = state.font(); 88 89 if ( m_stateData->flags & QPaintEngine::DirtyBackground ) 90 { 91 m_stateData->backgroundMode = state.backgroundMode(); 92 m_stateData->backgroundBrush = state.backgroundBrush(); 93 } 94 95 if ( m_stateData->flags & QPaintEngine::DirtyTransform ) 96 m_stateData->transform = state.transform(); 97 98 if ( m_stateData->flags & QPaintEngine::DirtyClipEnabled ) 99 m_stateData->isClipEnabled = state.isClipEnabled(); 100 101 if ( m_stateData->flags & QPaintEngine::DirtyClipRegion ) 102 { 103 m_stateData->clipRegion = state.clipRegion(); 104 m_stateData->clipOperation = state.clipOperation(); 105 } 106 107 if ( m_stateData->flags & QPaintEngine::DirtyClipPath ) 108 { 109 m_stateData->clipPath = state.clipPath(); 110 m_stateData->clipOperation = state.clipOperation(); 111 } 112 113 if ( m_stateData->flags & QPaintEngine::DirtyHints ) 114 m_stateData->renderHints = state.renderHints(); 115 116 if ( m_stateData->flags & QPaintEngine::DirtyCompositionMode ) 117 m_stateData->compositionMode = state.compositionMode(); 118 119 if ( m_stateData->flags & QPaintEngine::DirtyOpacity ) 120 m_stateData->opacity = state.opacity(); 121 } 122 123 /*! 124 Copy constructor 125 \param other Command to be copied 126 127 */ 128 QwtPainterCommand::QwtPainterCommand( const QwtPainterCommand& other ) 129 129 { 130 130 copy( other ); … … 138 138 139 139 /*! 140 Assignment operator 141 142 \param other Command to be copied 143 \return Modified command 144 */ 145 QwtPainterCommand &QwtPainterCommand::operator=(const QwtPainterCommand&other)140 Assignment operator 141 142 \param other Command to be copied 143 \return Modified command 144 */ 145 QwtPainterCommand& QwtPainterCommand::operator=( const QwtPainterCommand& other ) 146 146 { 147 147 reset(); … … 151 151 } 152 152 153 void QwtPainterCommand::copy( const QwtPainterCommand &other )154 { 155 d_type = other.d_type;156 157 switch( other. d_type )153 void QwtPainterCommand::copy( const QwtPainterCommand& other ) 154 { 155 m_type = other.m_type; 156 157 switch( other.m_type ) 158 158 { 159 159 case Path: 160 160 { 161 d_path = new QPainterPath( *other.d_path );161 m_path = new QPainterPath( *other.m_path ); 162 162 break; 163 163 } 164 164 case Pixmap: 165 165 { 166 d_pixmapData = new PixmapData( *other.d_pixmapData );166 m_pixmapData = new PixmapData( *other.m_pixmapData ); 167 167 break; 168 168 } 169 169 case Image: 170 170 { 171 d_imageData = new ImageData( *other.d_imageData );171 m_imageData = new ImageData( *other.m_imageData ); 172 172 break; 173 173 } 174 174 case State: 175 175 { 176 d_stateData = new StateData( *other.d_stateData );176 m_stateData = new StateData( *other.m_stateData ); 177 177 break; 178 178 } … … 184 184 void QwtPainterCommand::reset() 185 185 { 186 switch( d_type )186 switch( m_type ) 187 187 { 188 188 case Path: 189 189 { 190 delete d_path;190 delete m_path; 191 191 break; 192 192 } 193 193 case Pixmap: 194 194 { 195 delete d_pixmapData;195 delete m_pixmapData; 196 196 break; 197 197 } 198 198 case Image: 199 199 { 200 delete d_imageData;200 delete m_imageData; 201 201 break; 202 202 } 203 203 case State: 204 204 { 205 delete d_stateData;205 delete m_stateData; 206 206 break; 207 207 } … … 210 210 } 211 211 212 d_type = Invalid;212 m_type = Invalid; 213 213 } 214 214 215 215 //! \return Painter path to be painted 216 QPainterPath *QwtPainterCommand::path()217 { 218 return d_path;216 QPainterPath* QwtPainterCommand::path() 217 { 218 return m_path; 219 219 } 220 220 … … 222 222 QwtPainterCommand::PixmapData* QwtPainterCommand::pixmapData() 223 223 { 224 return d_pixmapData;224 return m_pixmapData; 225 225 } 226 226 … … 228 228 QwtPainterCommand::ImageData* QwtPainterCommand::imageData() 229 229 { 230 return d_imageData;230 return m_imageData; 231 231 } 232 232 … … 234 234 QwtPainterCommand::StateData* QwtPainterCommand::stateData() 235 235 { 236 return d_stateData;237 } 236 return m_stateData; 237 } -
trunk/BNC/qwt/qwt_painter_command.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 14 15 #include <qpaintengine.h> 15 16 #include <qpixmap.h> … … 21 22 22 23 /*! 23 QwtPainterCommand represents the attributes of a paint operation 24 how it is used between QPainter and QPaintDevice 24 QwtPainterCommand represents the attributes of a paint operation 25 how it is used between QPainter and QPaintDevice 25 26 26 It is used by QwtGraphic to record and replay paint operations 27 It is used by QwtGraphic to record and replay paint operations 27 28 28 \sa QwtGraphic::commands() 29 \sa QwtGraphic::commands() 29 30 */ 30 31 31 32 class QWT_EXPORT QwtPainterCommand 32 33 { 33 public: 34 public: 34 35 //! Type of the paint command 35 36 enum Type … … 79 80 Qt::BGMode backgroundMode; 80 81 QFont font; 81 QMatrix matrix;82 82 QTransform transform; 83 83 … … 93 93 94 94 QwtPainterCommand(); 95 QwtPainterCommand(const QwtPainterCommand &);95 QwtPainterCommand(const QwtPainterCommand&); 96 96 97 QwtPainterCommand( const QPainterPath & );97 explicit QwtPainterCommand( const QPainterPath& ); 98 98 99 QwtPainterCommand( const QRectF &rect,100 const QPixmap&, const QRectF& subRect );99 QwtPainterCommand( const QRectF& rect, 100 const QPixmap&, const QRectF& subRect ); 101 101 102 QwtPainterCommand( const QRectF &rect,103 const QImage&, const QRectF& subRect,104 Qt::ImageConversionFlags );102 QwtPainterCommand( const QRectF& rect, 103 const QImage&, const QRectF& subRect, 104 Qt::ImageConversionFlags ); 105 105 106 QwtPainterCommand( const QPaintEngineState & );106 explicit QwtPainterCommand( const QPaintEngineState& ); 107 107 108 108 ~QwtPainterCommand(); 109 109 110 QwtPainterCommand &operator=(const QwtPainterCommand& );110 QwtPainterCommand& operator=(const QwtPainterCommand& ); 111 111 112 112 Type type() const; 113 113 114 QPainterPath *path();115 const QPainterPath *path() const;114 QPainterPath* path(); 115 const QPainterPath* path() const; 116 116 117 117 PixmapData* pixmapData(); … … 124 124 const StateData* stateData() const; 125 125 126 private: 127 void copy( const QwtPainterCommand & );126 private: 127 void copy( const QwtPainterCommand& ); 128 128 void reset(); 129 129 130 Type d_type;130 Type m_type; 131 131 132 132 union 133 133 { 134 QPainterPath *d_path;135 PixmapData *d_pixmapData;136 ImageData *d_imageData;137 StateData *d_stateData;134 QPainterPath* m_path; 135 PixmapData* m_pixmapData; 136 ImageData* m_imageData; 137 StateData* m_stateData; 138 138 }; 139 139 }; … … 142 142 inline QwtPainterCommand::Type QwtPainterCommand::type() const 143 143 { 144 return d_type;144 return m_type; 145 145 } 146 146 147 147 //! \return Painter path to be painted 148 inline const QPainterPath *QwtPainterCommand::path() const148 inline const QPainterPath* QwtPainterCommand::path() const 149 149 { 150 return d_path;150 return m_path; 151 151 } 152 152 153 153 //! \return Attributes how to paint a QPixmap 154 inline const QwtPainterCommand::PixmapData *154 inline const QwtPainterCommand::PixmapData* 155 155 QwtPainterCommand::pixmapData() const 156 156 { 157 return d_pixmapData;157 return m_pixmapData; 158 158 } 159 159 160 160 //! \return Attributes how to paint a QImage 161 inline const QwtPainterCommand::ImageData *161 inline const QwtPainterCommand::ImageData* 162 162 QwtPainterCommand::imageData() const 163 163 { 164 return d_imageData;164 return m_imageData; 165 165 } 166 166 167 167 //! \return Attributes of a state change 168 inline const QwtPainterCommand::StateData *168 inline const QwtPainterCommand::StateData* 169 169 QwtPainterCommand::stateData() const 170 170 { 171 return d_stateData;171 return m_stateData; 172 172 } 173 173 -
trunk/BNC/qwt/qwt_panner.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_picker.h" 12 12 #include "qwt_painter.h" 13 13 14 #include <qpainter.h> 14 15 #include <qpixmap.h> … … 17 18 #include <qbitmap.h> 18 19 19 static QVector<QwtPicker *> qwtActivePickers( QWidget*w )20 { 21 QVector<QwtPicker *> pickers;20 static QVector< QwtPicker* > qwtActivePickers( QWidget* w ) 21 { 22 QVector< QwtPicker* > pickers; 22 23 23 24 QObjectList children = w->children(); 24 25 for ( int i = 0; i < children.size(); i++ ) 25 26 { 26 QwtPicker *picker = qobject_cast<QwtPicker*>( children[i] );27 QwtPicker* picker = qobject_cast< QwtPicker* >( children[i] ); 27 28 if ( picker && picker->isEnabled() ) 28 29 pickers += picker; … … 34 35 class QwtPanner::PrivateData 35 36 { 36 public: 37 PrivateData() :38 button( Qt::LeftButton ) ,39 buttonModifiers( Qt::NoModifier ) ,40 abortKey( Qt::Key_Escape ) ,41 abortKeyModifiers( Qt::NoModifier ) ,42 #ifndef QT_NO_CURSOR 43 cursor( NULL ) ,44 restoreCursor( NULL ) ,45 hasCursor( false ) ,46 #endif 47 isEnabled( false ) 48 {49 orientations = Qt::Vertical | Qt::Horizontal;37 public: 38 PrivateData() 39 : button( Qt::LeftButton ) 40 , buttonModifiers( Qt::NoModifier ) 41 , abortKey( Qt::Key_Escape ) 42 , abortKeyModifiers( Qt::NoModifier ) 43 #ifndef QT_NO_CURSOR 44 , cursor( NULL ) 45 , restoreCursor( NULL ) 46 , hasCursor( false ) 47 #endif 48 , isEnabled( false ) 49 , orientations( Qt::Vertical | Qt::Horizontal ) 50 { 50 51 } 51 52 … … 59 60 60 61 Qt::MouseButton button; 61 Qt::KeyboardModifiers buttonModifiers;62 Qt::KeyboardModifiers buttonModifiers; 62 63 63 64 int abortKey; … … 71 72 72 73 #ifndef QT_NO_CURSOR 73 QCursor *cursor;74 QCursor *restoreCursor;74 QCursor* cursor; 75 QCursor* restoreCursor; 75 76 bool hasCursor; 76 77 #endif … … 80 81 81 82 /*! 82 Creates an panner that is enabled for the left mouse button. 83 84 \param parent Parent widget to be panned 85 */ 86 QwtPanner::QwtPanner( QWidget *parent ):87 QWidget( parent ) 88 { 89 d_data = new PrivateData();83 Creates an panner that is enabled for the left mouse button. 84 85 \param parent Parent widget to be panned 86 */ 87 QwtPanner::QwtPanner( QWidget* parent ) 88 : QWidget( parent ) 89 { 90 m_data = new PrivateData(); 90 91 91 92 setAttribute( Qt::WA_TransparentForMouseEvents ); … … 100 101 QwtPanner::~QwtPanner() 101 102 { 102 delete d_data;103 delete m_data; 103 104 } 104 105 … … 106 107 Change the mouse button and modifiers used for panning 107 108 The defaults are Qt::LeftButton and Qt::NoModifier 108 */ 109 */ 109 110 void QwtPanner::setMouseButton( Qt::MouseButton button, 110 111 Qt::KeyboardModifiers modifiers ) 111 112 { 112 d_data->button = button;113 d_data->buttonModifiers = modifiers;113 m_data->button = button; 114 m_data->buttonModifiers = modifiers; 114 115 } 115 116 116 117 //! Get mouse button and modifiers used for panning 117 void QwtPanner::getMouseButton( Qt::MouseButton &button,118 Qt::KeyboardModifiers &modifiers ) const119 { 120 button = d_data->button;121 modifiers = d_data->buttonModifiers;118 void QwtPanner::getMouseButton( Qt::MouseButton& button, 119 Qt::KeyboardModifiers& modifiers ) const 120 { 121 button = m_data->button; 122 modifiers = m_data->buttonModifiers; 122 123 } 123 124 … … 128 129 \param key Key ( See Qt::Keycode ) 129 130 \param modifiers Keyboard modifiers 130 */ 131 */ 131 132 void QwtPanner::setAbortKey( int key, 132 133 Qt::KeyboardModifiers modifiers ) 133 134 { 134 d_data->abortKey = key;135 d_data->abortKeyModifiers = modifiers;135 m_data->abortKey = key; 136 m_data->abortKeyModifiers = modifiers; 136 137 } 137 138 138 139 //! Get the abort key and modifiers 139 void QwtPanner::getAbortKey( int &key,140 Qt::KeyboardModifiers &modifiers ) const141 { 142 key = d_data->abortKey;143 modifiers = d_data->abortKeyModifiers;140 void QwtPanner::getAbortKey( int& key, 141 Qt::KeyboardModifiers& modifiers ) const 142 { 143 key = m_data->abortKey; 144 modifiers = m_data->abortKeyModifiers; 144 145 } 145 146 … … 151 152 152 153 \sa setCursor() 153 */ 154 #ifndef QT_NO_CURSOR 155 void QwtPanner::setCursor( const QCursor &cursor )156 { 157 d_data->cursor = new QCursor( cursor );154 */ 155 #ifndef QT_NO_CURSOR 156 void QwtPanner::setCursor( const QCursor& cursor ) 157 { 158 m_data->cursor = new QCursor( cursor ); 158 159 } 159 160 #endif … … 162 163 \return Cursor that is active while panning 163 164 \sa setCursor() 164 */ 165 */ 165 166 #ifndef QT_NO_CURSOR 166 167 const QCursor QwtPanner::cursor() const 167 168 { 168 if ( d_data->cursor )169 return * d_data->cursor;169 if ( m_data->cursor ) 170 return *m_data->cursor; 170 171 171 172 if ( parentWidget() ) … … 177 178 178 179 /*! 179 \brief En/disable the panner 180 181 When enabled is true an event filter is installed for 182 the observed widget, otherwise the event filter is removed. 183 184 \param on true or false 185 \sa isEnabled(), eventFilter() 186 */ 180 \brief En/disable the panner 181 182 When enabled is true an event filter is installed for 183 the observed widget, otherwise the event filter is removed. 184 185 \param on true or false 186 \sa isEnabled(), eventFilter() 187 */ 187 188 void QwtPanner::setEnabled( bool on ) 188 189 { 189 if ( d_data->isEnabled != on )190 { 191 d_data->isEnabled = on;192 193 QWidget *w = parentWidget();190 if ( m_data->isEnabled != on ) 191 { 192 m_data->isEnabled = on; 193 194 QWidget* w = parentWidget(); 194 195 if ( w ) 195 196 { 196 if ( d_data->isEnabled )197 if ( m_data->isEnabled ) 197 198 { 198 199 w->installEventFilter( this ); … … 212 213 213 214 /param o Orientation 214 */ 215 */ 215 216 void QwtPanner::setOrientations( Qt::Orientations o ) 216 217 { 217 d_data->orientations = o;218 } 219 220 //! Return the orientation, where paning is enabled 218 m_data->orientations = o; 219 } 220 221 //! Return the orientation, where panning is enabled 221 222 Qt::Orientations QwtPanner::orientations() const 222 223 { 223 return d_data->orientations;224 return m_data->orientations; 224 225 } 225 226 … … 227 228 \return True if an orientation is enabled 228 229 \sa orientations(), setOrientations() 229 */ 230 */ 230 231 bool QwtPanner::isOrientationEnabled( Qt::Orientation o ) const 231 232 { 232 return d_data->orientations & o;233 } 234 235 /*! 236 \return true when enabled, false otherwise 237 \sa setEnabled, eventFilter() 238 */ 233 return m_data->orientations & o; 234 } 235 236 /*! 237 \return true when enabled, false otherwise 238 \sa setEnabled, eventFilter() 239 */ 239 240 bool QwtPanner::isEnabled() const 240 241 { 241 return d_data->isEnabled;242 return m_data->isEnabled; 242 243 } 243 244 … … 249 250 250 251 \param event Paint event 251 */ 252 void QwtPanner::paintEvent( QPaintEvent *event )253 { 254 int dx = d_data->pos.x() -d_data->initialPos.x();255 int dy = d_data->pos.y() -d_data->initialPos.y();252 */ 253 void QwtPanner::paintEvent( QPaintEvent* event ) 254 { 255 int dx = m_data->pos.x() - m_data->initialPos.x(); 256 int dy = m_data->pos.y() - m_data->initialPos.y(); 256 257 257 258 QRectF r; 258 r.setSize( d_data->pixmap.size() ); 259 #if QT_VERSION >= 0x050000 260 r.setSize( r.size() / d_data->pixmap.devicePixelRatio() ); 261 #endif 259 r.setSize( m_data->pixmap.size() / QwtPainter::devicePixelRatio( &m_data->pixmap ) ); 262 260 r.moveCenter( QPointF( r.center().x() + dx, r.center().y() + dy ) ); 263 261 … … 267 265 QPainter painter( &pm ); 268 266 269 if ( ! d_data->contentsMask.isNull() )270 { 271 QPixmap masked = d_data->pixmap;272 masked.setMask( d_data->contentsMask );267 if ( !m_data->contentsMask.isNull() ) 268 { 269 QPixmap masked = m_data->pixmap; 270 masked.setMask( m_data->contentsMask ); 273 271 painter.drawPixmap( r.toRect(), masked ); 274 272 } 275 273 else 276 274 { 277 painter.drawPixmap( r.toRect(), d_data->pixmap );275 painter.drawPixmap( r.toRect(), m_data->pixmap ); 278 276 } 279 277 280 278 painter.end(); 281 279 282 if ( ! d_data->contentsMask.isNull() )283 pm.setMask( d_data->contentsMask );280 if ( !m_data->contentsMask.isNull() ) 281 pm.setMask( m_data->contentsMask ); 284 282 285 283 painter.begin( this ); … … 289 287 290 288 /*! 291 \brief Calculate a mask for the contents of the panned widget 292 293 Sometimes only parts of the contents of a widget should be 294 panned. F.e. for a widget with a styled background with rounded borders 295 only the area inside of the border should be panned. 296 297 \return An empty bitmap, indicating no mask 298 */ 289 \brief Calculate a mask for the contents of the panned widget 290 291 Sometimes only parts of the contents of a widget should be 292 panned. F.e. for a widget with a styled background with rounded borders 293 only the area inside of the border should be panned. 294 295 \return An empty bitmap, indicating no mask 296 */ 299 297 QBitmap QwtPanner::contentsMask() const 300 298 { … … 303 301 304 302 /*! 305 Grab the widget into a pixmap. 306 \return Grabbed pixmap 307 */ 303 Grab the widget into a pixmap. 304 \return Grabbed pixmap 305 */ 308 306 QPixmap QwtPanner::grab() const 309 307 { … … 316 314 317 315 /*! 318 \brief Event filter 319 320 When isEnabled() is true mouse events of the 321 observed widget are filtered. 322 323 \param object Object to be filtered 324 \param event Event 325 326 \return Always false, beside for paint events for the 316 \brief Event filter 317 318 When isEnabled() is true mouse events of the 319 observed widget are filtered. 320 321 \param object Object to be filtered 322 \param event Event 323 324 \return Always false, beside for paint events for the 327 325 parent widget. 328 326 329 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 327 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 330 328 widgetMouseMoveEvent() 331 */ 332 bool QwtPanner::eventFilter( QObject *object, QEvent*event )329 */ 330 bool QwtPanner::eventFilter( QObject* object, QEvent* event ) 333 331 { 334 332 if ( object == NULL || object != parentWidget() ) … … 339 337 case QEvent::MouseButtonPress: 340 338 { 341 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );339 widgetMousePressEvent( static_cast< QMouseEvent* >( event ) ); 342 340 break; 343 341 } 344 342 case QEvent::MouseMove: 345 343 { 346 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );344 widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) ); 347 345 break; 348 346 } 349 347 case QEvent::MouseButtonRelease: 350 348 { 351 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );349 widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) ); 352 350 break; 353 351 } 354 352 case QEvent::KeyPress: 355 353 { 356 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );354 widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) ); 357 355 break; 358 356 } 359 357 case QEvent::KeyRelease: 360 358 { 361 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );359 widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) ); 362 360 break; 363 361 } … … 375 373 376 374 /*! 377 Handle a mouse press event for the observed widget. 378 379 \param mouseEvent Mouse event 380 \sa eventFilter(), widgetMouseReleaseEvent(), 375 Handle a mouse press event for the observed widget. 376 377 \param mouseEvent Mouse event 378 \sa eventFilter(), widgetMouseReleaseEvent(), 381 379 widgetMouseMoveEvent(), 382 */ 383 void QwtPanner::widgetMousePressEvent( QMouseEvent *mouseEvent )384 { 385 if ( ( mouseEvent->button() != d_data->button )386 || ( mouseEvent->modifiers() != d_data->buttonModifiers ) )380 */ 381 void QwtPanner::widgetMousePressEvent( QMouseEvent* mouseEvent ) 382 { 383 if ( ( mouseEvent->button() != m_data->button ) 384 || ( mouseEvent->modifiers() != m_data->buttonModifiers ) ) 387 385 { 388 386 return; 389 387 } 390 388 391 QWidget *w = parentWidget();389 QWidget* w = parentWidget(); 392 390 if ( w == NULL ) 393 391 return; … … 397 395 #endif 398 396 399 d_data->initialPos =d_data->pos = mouseEvent->pos();397 m_data->initialPos = m_data->pos = mouseEvent->pos(); 400 398 401 399 setGeometry( parentWidget()->rect() ); 402 400 403 401 // We don't want to grab the picker ! 404 QVector<QwtPicker *> pickers = qwtActivePickers( parentWidget() );402 QVector< QwtPicker* > pickers = qwtActivePickers( parentWidget() ); 405 403 for ( int i = 0; i < pickers.size(); i++ ) 406 404 pickers[i]->setEnabled( false ); 407 405 408 d_data->pixmap = grab();409 d_data->contentsMask = contentsMask();406 m_data->pixmap = grab(); 407 m_data->contentsMask = contentsMask(); 410 408 411 409 for ( int i = 0; i < pickers.size(); i++ ) … … 416 414 417 415 /*! 418 Handle a mouse move event for the observed widget. 419 420 \param mouseEvent Mouse event 421 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent() 422 */ 423 void QwtPanner::widgetMouseMoveEvent( QMouseEvent *mouseEvent )416 Handle a mouse move event for the observed widget. 417 418 \param mouseEvent Mouse event 419 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent() 420 */ 421 void QwtPanner::widgetMouseMoveEvent( QMouseEvent* mouseEvent ) 424 422 { 425 423 if ( !isVisible() ) … … 428 426 QPoint pos = mouseEvent->pos(); 429 427 if ( !isOrientationEnabled( Qt::Horizontal ) ) 430 pos.setX( d_data->initialPos.x() );428 pos.setX( m_data->initialPos.x() ); 431 429 if ( !isOrientationEnabled( Qt::Vertical ) ) 432 pos.setY( d_data->initialPos.y() );433 434 if ( pos != d_data->pos && rect().contains( pos ) )435 { 436 d_data->pos = pos;430 pos.setY( m_data->initialPos.y() ); 431 432 if ( pos != m_data->pos && rect().contains( pos ) ) 433 { 434 m_data->pos = pos; 437 435 update(); 438 436 439 Q_EMIT moved( d_data->pos.x() -d_data->initialPos.x(),440 d_data->pos.y() -d_data->initialPos.y() );441 } 442 } 443 444 /*! 445 Handle a mouse release event for the observed widget. 446 447 \param mouseEvent Mouse event 448 \sa eventFilter(), widgetMousePressEvent(), 437 Q_EMIT moved( m_data->pos.x() - m_data->initialPos.x(), 438 m_data->pos.y() - m_data->initialPos.y() ); 439 } 440 } 441 442 /*! 443 Handle a mouse release event for the observed widget. 444 445 \param mouseEvent Mouse event 446 \sa eventFilter(), widgetMousePressEvent(), 449 447 widgetMouseMoveEvent(), 450 */ 451 void QwtPanner::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )448 */ 449 void QwtPanner::widgetMouseReleaseEvent( QMouseEvent* mouseEvent ) 452 450 { 453 451 if ( isVisible() ) … … 460 458 QPoint pos = mouseEvent->pos(); 461 459 if ( !isOrientationEnabled( Qt::Horizontal ) ) 462 pos.setX( d_data->initialPos.x() );460 pos.setX( m_data->initialPos.x() ); 463 461 if ( !isOrientationEnabled( Qt::Vertical ) ) 464 pos.setY( d_data->initialPos.y() );465 466 d_data->pixmap = QPixmap();467 d_data->contentsMask = QBitmap();468 d_data->pos = pos;469 470 if ( d_data->pos !=d_data->initialPos )471 { 472 Q_EMIT panned( d_data->pos.x() -d_data->initialPos.x(),473 d_data->pos.y() -d_data->initialPos.y() );474 } 475 } 476 } 477 478 /*! 479 Handle a key press event for the observed widget. 480 481 \param keyEvent Key event 482 \sa eventFilter(), widgetKeyReleaseEvent() 483 */ 484 void QwtPanner::widgetKeyPressEvent( QKeyEvent *keyEvent )485 { 486 if ( ( keyEvent->key() == d_data->abortKey )487 && ( keyEvent->modifiers() == d_data->abortKeyModifiers ) )462 pos.setY( m_data->initialPos.y() ); 463 464 m_data->pixmap = QPixmap(); 465 m_data->contentsMask = QBitmap(); 466 m_data->pos = pos; 467 468 if ( m_data->pos != m_data->initialPos ) 469 { 470 Q_EMIT panned( m_data->pos.x() - m_data->initialPos.x(), 471 m_data->pos.y() - m_data->initialPos.y() ); 472 } 473 } 474 } 475 476 /*! 477 Handle a key press event for the observed widget. 478 479 \param keyEvent Key event 480 \sa eventFilter(), widgetKeyReleaseEvent() 481 */ 482 void QwtPanner::widgetKeyPressEvent( QKeyEvent* keyEvent ) 483 { 484 if ( ( keyEvent->key() == m_data->abortKey ) 485 && ( keyEvent->modifiers() == m_data->abortKeyModifiers ) ) 488 486 { 489 487 hide(); … … 492 490 showCursor( false ); 493 491 #endif 494 d_data->pixmap = QPixmap();495 } 496 } 497 498 /*! 499 Handle a key release event for the observed widget. 500 501 \param keyEvent Key event 502 \sa eventFilter(), widgetKeyReleaseEvent() 503 */ 504 void QwtPanner::widgetKeyReleaseEvent( QKeyEvent *keyEvent )492 m_data->pixmap = QPixmap(); 493 } 494 } 495 496 /*! 497 Handle a key release event for the observed widget. 498 499 \param keyEvent Key event 500 \sa eventFilter(), widgetKeyReleaseEvent() 501 */ 502 void QwtPanner::widgetKeyReleaseEvent( QKeyEvent* keyEvent ) 505 503 { 506 504 Q_UNUSED( keyEvent ); … … 510 508 void QwtPanner::showCursor( bool on ) 511 509 { 512 if ( on == d_data->hasCursor )510 if ( on == m_data->hasCursor ) 513 511 return; 514 512 515 QWidget *w = parentWidget();516 if ( w == NULL || d_data->cursor == NULL )513 QWidget* w = parentWidget(); 514 if ( w == NULL || m_data->cursor == NULL ) 517 515 return; 518 516 519 d_data->hasCursor = on;517 m_data->hasCursor = on; 520 518 521 519 if ( on ) … … 523 521 if ( w->testAttribute( Qt::WA_SetCursor ) ) 524 522 { 525 delete d_data->restoreCursor;526 d_data->restoreCursor = new QCursor( w->cursor() );527 } 528 w->setCursor( * d_data->cursor );523 delete m_data->restoreCursor; 524 m_data->restoreCursor = new QCursor( w->cursor() ); 525 } 526 w->setCursor( *m_data->cursor ); 529 527 } 530 528 else 531 529 { 532 if ( d_data->restoreCursor )533 { 534 w->setCursor( * d_data->restoreCursor );535 delete d_data->restoreCursor;536 d_data->restoreCursor = NULL;530 if ( m_data->restoreCursor ) 531 { 532 w->setCursor( *m_data->restoreCursor ); 533 delete m_data->restoreCursor; 534 m_data->restoreCursor = NULL; 537 535 } 538 536 else … … 541 539 } 542 540 #endif 541 542 #include "moc_qwt_panner.cpp" -
trunk/BNC/qwt/qwt_panner.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PANNER_H 11 #define QWT_PANNER_H 111 #define QWT_PANNER_H 12 12 13 13 #include "qwt_global.h" 14 14 #include <qwidget.h> 15 #include <qpixmap.h>16 15 17 16 class QCursor; 17 class QPixmap; 18 18 19 19 /*! 20 \brief QwtPanner provides panning of a widget 20 \brief QwtPanner provides panning of a widget 21 21 22 QwtPanner grabs the contents of a widget, that can be dragged 23 in all directions. The offset between the start and the end position 24 is emitted by the panned signal. 22 QwtPanner grabs the contents of a widget, that can be dragged 23 in all directions. The offset between the start and the end position 24 is emitted by the panned signal. 25 25 26 QwtPanner grabs the content of the widget into a pixmap and moves 27 the pixmap around, without initiating any repaint events for the widget. 28 Areas, that are not part of content are not painted while panning. 29 This makes panning fast enough for widgets, where 30 repaints are too slow for mouse movements. 26 QwtPanner grabs the content of the widget into a pixmap and moves 27 the pixmap around, without initiating any repaint events for the widget. 28 Areas, that are not part of content are not painted while panning. 29 This makes panning fast enough for widgets, where 30 repaints are too slow for mouse movements. 31 31 32 For widgets, where repaints are very fast it might be better to 33 implement panning manually by mapping mouse events into paint events. 34 */ 35 class QWT_EXPORT QwtPanner: public QWidget 32 For widgets, where repaints are very fast it might be better to 33 implement panning manually by mapping mouse events into paint events. 34 */ 35 class QWT_EXPORT QwtPanner : public QWidget 36 36 { 37 37 Q_OBJECT 38 38 39 public: 40 QwtPanner( QWidget* parent ); 39 public: 40 explicit QwtPanner( QWidget* parent ); 41 41 virtual ~QwtPanner(); 42 42 … … 46 46 void setMouseButton( Qt::MouseButton, 47 47 Qt::KeyboardModifiers = Qt::NoModifier ); 48 void getMouseButton( Qt::MouseButton &button,49 Qt::KeyboardModifiers & ) const;48 void getMouseButton( Qt::MouseButton& button, 49 Qt::KeyboardModifiers& ) const; 50 50 51 51 void setAbortKey( int key, Qt::KeyboardModifiers = Qt::NoModifier ); 52 void getAbortKey( int &key, Qt::KeyboardModifiers& ) const;52 void getAbortKey( int& key, Qt::KeyboardModifiers& ) const; 53 53 54 void setCursor( const QCursor & );54 void setCursor( const QCursor& ); 55 55 const QCursor cursor() const; 56 56 … … 60 60 bool isOrientationEnabled( Qt::Orientation ) const; 61 61 62 virtual bool eventFilter( QObject *, QEvent* );62 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 63 63 64 Q_SIGNALS: 64 Q_SIGNALS: 65 65 /*! 66 Signal emitted, when panning is done 66 Signal emitted, when panning is done 67 67 68 \param dx Offset in horizontal direction 69 \param dy Offset in vertical direction 70 */ 68 \param dx Offset in horizontal direction 69 \param dy Offset in vertical direction 70 */ 71 71 void panned( int dx, int dy ); 72 72 73 73 /*! 74 Signal emitted, while the widget moved, but panning 75 is not finished. 74 Signal emitted, while the widget moved, but panning 75 is not finished. 76 76 77 \param dx Offset in horizontal direction 78 \param dy Offset in vertical direction 79 */ 77 \param dx Offset in horizontal direction 78 \param dy Offset in vertical direction 79 */ 80 80 void moved( int dx, int dy ); 81 81 82 protected: 83 virtual void widgetMousePressEvent( QMouseEvent * );84 virtual void widgetMouseReleaseEvent( QMouseEvent * );85 virtual void widgetMouseMoveEvent( QMouseEvent * );86 virtual void widgetKeyPressEvent( QKeyEvent * );87 virtual void widgetKeyReleaseEvent( QKeyEvent * );82 protected: 83 virtual void widgetMousePressEvent( QMouseEvent* ); 84 virtual void widgetMouseReleaseEvent( QMouseEvent* ); 85 virtual void widgetMouseMoveEvent( QMouseEvent* ); 86 virtual void widgetKeyPressEvent( QKeyEvent* ); 87 virtual void widgetKeyReleaseEvent( QKeyEvent* ); 88 88 89 virtual void paintEvent( QPaintEvent * );89 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 90 90 91 91 virtual QBitmap contentsMask() const; 92 92 virtual QPixmap grab() const; 93 93 94 private: 94 private: 95 95 #ifndef QT_NO_CURSOR 96 96 void showCursor( bool ); … … 98 98 99 99 class PrivateData; 100 PrivateData *d_data;100 PrivateData* m_data; 101 101 }; 102 102 -
trunk/BNC/qwt/qwt_picker.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_math.h" 14 14 #include "qwt_widget_overlay.h" 15 #include <qapplication.h> 15 #include "qwt_text.h" 16 16 17 #include <qevent.h> 17 18 #include <qpainter.h> 18 #include <q frame.h>19 #include <qpainterpath.h> 19 20 #include <qcursor.h> 20 #include <qbitmap.h>21 21 #include <qpointer.h> 22 #include <qpaintengine.h>23 22 #include <qmath.h> 24 23 25 static inline QRegion qwtMaskRegion( const QRect &r, int penWidth )24 static inline QRegion qwtMaskRegion( const QRect& r, int penWidth ) 26 25 { 27 26 const int pw = qMax( penWidth, 1 ); … … 44 43 } 45 44 46 static inline QRegion qwtMaskRegion( const QLine &l, int penWidth )45 static inline QRegion qwtMaskRegion( const QLine& l, int penWidth ) 47 46 { 48 47 const int pw = qMax( penWidth, 1 ); … … 65 64 } 66 65 67 class QwtPickerRubberband: public QwtWidgetOverlay 68 { 69 public: 70 QwtPickerRubberband( QwtPicker *, QWidget * ); 71 72 protected: 73 virtual void drawOverlay( QPainter * ) const; 74 virtual QRegion maskHint() const; 75 76 QwtPicker *d_picker; 77 }; 78 79 class QwtPickerTracker: public QwtWidgetOverlay 80 { 81 public: 82 QwtPickerTracker( QwtPicker *, QWidget * ); 83 84 protected: 85 virtual void drawOverlay( QPainter * ) const; 86 virtual QRegion maskHint() const; 87 88 QwtPicker *d_picker; 89 }; 90 66 namespace 67 { 68 class Rubberband QWT_FINAL : public QwtWidgetOverlay 69 { 70 public: 71 Rubberband( QwtPicker* picker, QWidget* parent ) 72 : QwtWidgetOverlay( parent ) 73 , m_picker( picker ) 74 { 75 setMaskMode( QwtWidgetOverlay::MaskHint ); 76 } 77 78 protected: 79 virtual void drawOverlay( QPainter* painter ) const QWT_OVERRIDE 80 { 81 painter->setPen( m_picker->rubberBandPen() ); 82 m_picker->drawRubberBand( painter ); 83 } 84 85 virtual QRegion maskHint() const QWT_OVERRIDE 86 { 87 return m_picker->rubberBandMask(); 88 } 89 90 QwtPicker* m_picker; 91 }; 92 93 class Tracker QWT_FINAL : public QwtWidgetOverlay 94 { 95 public: 96 Tracker( QwtPicker* picker, QWidget* parent ) 97 : QwtWidgetOverlay( parent ) 98 , m_picker( picker ) 99 { 100 setMaskMode( QwtWidgetOverlay::MaskHint ); 101 } 102 103 protected: 104 virtual void drawOverlay( QPainter* painter ) const QWT_OVERRIDE 105 { 106 painter->setPen( m_picker->trackerPen() ); 107 m_picker->drawTracker( painter ); 108 } 109 110 virtual QRegion maskHint() const QWT_OVERRIDE 111 { 112 return m_picker->trackerMask(); 113 } 114 115 QwtPicker* m_picker; 116 }; 117 } 91 118 92 119 class QwtPicker::PrivateData 93 120 { 94 public: 121 public: 95 122 PrivateData(): 96 123 enabled( false ), … … 108 135 bool enabled; 109 136 110 QwtPickerMachine *stateMachine;137 QwtPickerMachine* stateMachine; 111 138 112 139 QwtPicker::ResizeMode resizeMode; … … 125 152 bool mouseTracking; // used to save previous value 126 153 127 QPointer< QwtPickerRubberband > rubberBandOverlay;128 QPointer< QwtPickerTracker> trackerOverlay;154 QPointer< Rubberband > rubberBandOverlay; 155 QPointer< Tracker > trackerOverlay; 129 156 130 157 bool openGL; 131 158 }; 132 159 133 QwtPickerRubberband::QwtPickerRubberband( 134 QwtPicker *picker, QWidget *parent ): 135 QwtWidgetOverlay( parent ), 136 d_picker( picker ) 137 { 138 setMaskMode( QwtWidgetOverlay::MaskHint ); 139 } 140 141 QRegion QwtPickerRubberband::maskHint() const 142 { 143 return d_picker->rubberBandMask(); 144 } 145 146 void QwtPickerRubberband::drawOverlay( QPainter *painter ) const 147 { 148 painter->setPen( d_picker->rubberBandPen() ); 149 d_picker->drawRubberBand( painter ); 150 } 151 152 QwtPickerTracker::QwtPickerTracker( 153 QwtPicker *picker, QWidget *parent ): 154 QwtWidgetOverlay( parent ), 155 d_picker( picker ) 156 { 157 setMaskMode( QwtWidgetOverlay::MaskHint ); 158 } 159 160 QRegion QwtPickerTracker::maskHint() const 161 { 162 return d_picker->trackerRect( font() ); 163 } 164 165 void QwtPickerTracker::drawOverlay( QPainter *painter ) const 166 { 167 painter->setPen( d_picker->trackerPen() ); 168 d_picker->drawTracker( painter ); 169 } 170 171 /*! 172 Constructor 173 174 Creates an picker that is enabled, but without a state machine. 175 rubber band and tracker are disabled. 176 177 \param parent Parent widget, that will be observed 178 */ 179 180 QwtPicker::QwtPicker( QWidget *parent ): 160 /*! 161 Constructor 162 163 Creates an picker that is enabled, but without a state machine. 164 rubber band and tracker are disabled. 165 166 \param parent Parent widget, that will be observed 167 */ 168 169 QwtPicker::QwtPicker( QWidget* parent ): 181 170 QObject( parent ) 182 171 { … … 185 174 186 175 /*! 187 Constructor 188 189 \param rubberBand Rubber band style 190 \param trackerMode Tracker mode 191 \param parent Parent widget, that will be observed 176 Constructor 177 178 \param rubberBand Rubber band style 179 \param trackerMode Tracker mode 180 \param parent Parent widget, that will be observed 192 181 */ 193 182 QwtPicker::QwtPicker( RubberBand rubberBand, 194 DisplayMode trackerMode, QWidget*parent ):183 DisplayMode trackerMode, QWidget* parent ): 195 184 QObject( parent ) 196 185 { … … 203 192 setMouseTracking( false ); 204 193 205 delete d_data->stateMachine;206 delete d_data->rubberBandOverlay;207 delete d_data->trackerOverlay;208 209 delete d_data;194 delete m_data->stateMachine; 195 delete m_data->rubberBandOverlay; 196 delete m_data->trackerOverlay; 197 198 delete m_data; 210 199 } 211 200 212 201 //! Initialize the picker - used by the constructors 213 void QwtPicker::init( QWidget *parent,202 void QwtPicker::init( QWidget* parent, 214 203 RubberBand rubberBand, DisplayMode trackerMode ) 215 204 { 216 d_data = new PrivateData;217 218 d_data->rubberBand = rubberBand;205 m_data = new PrivateData; 206 207 m_data->rubberBand = rubberBand; 219 208 220 209 if ( parent ) … … 223 212 parent->setFocusPolicy( Qt::WheelFocus ); 224 213 225 d_data->openGL = parent->inherits( "QGLWidget" );226 d_data->trackerFont = parent->font();227 d_data->mouseTracking = parent->hasMouseTracking();214 m_data->openGL = parent->inherits( "QGLWidget" ); 215 m_data->trackerFont = parent->font(); 216 m_data->mouseTracking = parent->hasMouseTracking(); 228 217 229 218 setEnabled( true ); … … 234 223 235 224 /*! 236 Set a state machine and delete the previous one 237 238 \param stateMachine State machine 239 \sa stateMachine() 240 */ 241 void QwtPicker::setStateMachine( QwtPickerMachine *stateMachine )242 { 243 if ( d_data->stateMachine != stateMachine )225 Set a state machine and delete the previous one 226 227 \param stateMachine State machine 228 \sa stateMachine() 229 */ 230 void QwtPicker::setStateMachine( QwtPickerMachine* stateMachine ) 231 { 232 if ( m_data->stateMachine != stateMachine ) 244 233 { 245 234 reset(); 246 235 247 delete d_data->stateMachine;248 d_data->stateMachine = stateMachine;249 250 if ( d_data->stateMachine )251 d_data->stateMachine->reset();252 } 253 } 254 255 /*! 256 \return Assigned state machine 257 \sa setStateMachine() 258 */ 259 QwtPickerMachine *QwtPicker::stateMachine()260 { 261 return d_data->stateMachine;262 } 263 264 /*! 265 \return Assigned state machine 266 \sa setStateMachine() 267 */ 268 const QwtPickerMachine *QwtPicker::stateMachine() const269 { 270 return d_data->stateMachine;236 delete m_data->stateMachine; 237 m_data->stateMachine = stateMachine; 238 239 if ( m_data->stateMachine ) 240 m_data->stateMachine->reset(); 241 } 242 } 243 244 /*! 245 \return Assigned state machine 246 \sa setStateMachine() 247 */ 248 QwtPickerMachine* QwtPicker::stateMachine() 249 { 250 return m_data->stateMachine; 251 } 252 253 /*! 254 \return Assigned state machine 255 \sa setStateMachine() 256 */ 257 const QwtPickerMachine* QwtPicker::stateMachine() const 258 { 259 return m_data->stateMachine; 271 260 } 272 261 273 262 //! Return the parent widget, where the selection happens 274 QWidget *QwtPicker::parentWidget()275 { 276 QObject *obj = parent();263 QWidget* QwtPicker::parentWidget() 264 { 265 QObject* obj = parent(); 277 266 if ( obj && obj->isWidgetType() ) 278 return static_cast<QWidget *>( obj );267 return static_cast< QWidget* >( obj ); 279 268 280 269 return NULL; … … 282 271 283 272 //! Return the parent widget, where the selection happens 284 const QWidget *QwtPicker::parentWidget() const285 { 286 QObject *obj = parent();273 const QWidget* QwtPicker::parentWidget() const 274 { 275 QObject* obj = parent(); 287 276 if ( obj && obj->isWidgetType() ) 288 return static_cast< const QWidget *>( obj );277 return static_cast< const QWidget* >( obj ); 289 278 290 279 return NULL; … … 292 281 293 282 /*! 294 Set the rubber band style 295 296 \param rubberBand Rubber band style 283 Set the rubber band style 284 285 \param rubberBand Rubber band style 297 286 The default value is NoRubberBand. 298 287 299 \sa rubberBand(), RubberBand, setRubberBandPen() 300 */ 288 \sa rubberBand(), RubberBand, setRubberBandPen() 289 */ 301 290 void QwtPicker::setRubberBand( RubberBand rubberBand ) 302 291 { 303 d_data->rubberBand = rubberBand;304 } 305 306 /*! 307 \return Rubber band style 308 \sa setRubberBand(), RubberBand, rubberBandPen() 309 */ 292 m_data->rubberBand = rubberBand; 293 } 294 295 /*! 296 \return Rubber band style 297 \sa setRubberBand(), RubberBand, rubberBandPen() 298 */ 310 299 QwtPicker::RubberBand QwtPicker::rubberBand() const 311 300 { 312 return d_data->rubberBand;313 } 314 315 /*! 316 \brief Set the display mode of the tracker. 317 318 A tracker displays information about current position of 319 the cursor as a string. The display mode controls 320 if the tracker has to be displayed whenever the observed 321 widget has focus and cursor (AlwaysOn), never (AlwaysOff), or 322 only when the selection is active (ActiveOnly). 323 324 \param mode Tracker display mode 325 326 \warning In case of AlwaysOn, mouseTracking will be enabled 301 return m_data->rubberBand; 302 } 303 304 /*! 305 \brief Set the display mode of the tracker. 306 307 A tracker displays information about current position of 308 the cursor as a string. The display mode controls 309 if the tracker has to be displayed whenever the observed 310 widget has focus and cursor (AlwaysOn), never (AlwaysOff), or 311 only when the selection is active (ActiveOnly). 312 313 \param mode Tracker display mode 314 315 \warning In case of AlwaysOn, mouseTracking will be enabled 327 316 for the observed widget. 328 \sa trackerMode(), DisplayMode 329 */ 317 \sa trackerMode(), DisplayMode 318 */ 330 319 331 320 void QwtPicker::setTrackerMode( DisplayMode mode ) 332 321 { 333 if ( d_data->trackerMode != mode )334 { 335 d_data->trackerMode = mode;336 setMouseTracking( d_data->trackerMode == AlwaysOn );337 } 338 } 339 340 /*! 341 \return Tracker display mode 342 \sa setTrackerMode(), DisplayMode 343 */ 322 if ( m_data->trackerMode != mode ) 323 { 324 m_data->trackerMode = mode; 325 setMouseTracking( m_data->trackerMode == AlwaysOn ); 326 } 327 } 328 329 /*! 330 \return Tracker display mode 331 \sa setTrackerMode(), DisplayMode 332 */ 344 333 QwtPicker::DisplayMode QwtPicker::trackerMode() const 345 334 { 346 return d_data->trackerMode;347 } 348 349 /*! 350 \brief Set the resize mode. 351 352 The resize mode controls what to do with the selected points of an active 353 selection when the observed widget is resized. 354 355 Stretch means the points are scaled according to the new 356 size, KeepSize means the points remain unchanged. 357 358 The default mode is Stretch. 359 360 \param mode Resize mode 361 \sa resizeMode(), ResizeMode 362 */ 335 return m_data->trackerMode; 336 } 337 338 /*! 339 \brief Set the resize mode. 340 341 The resize mode controls what to do with the selected points of an active 342 selection when the observed widget is resized. 343 344 Stretch means the points are scaled according to the new 345 size, KeepSize means the points remain unchanged. 346 347 The default mode is Stretch. 348 349 \param mode Resize mode 350 \sa resizeMode(), ResizeMode 351 */ 363 352 void QwtPicker::setResizeMode( ResizeMode mode ) 364 353 { 365 d_data->resizeMode = mode;366 } 367 368 /*! 369 \return Resize mode 370 \sa setResizeMode(), ResizeMode 371 */ 354 m_data->resizeMode = mode; 355 } 356 357 /*! 358 \return Resize mode 359 \sa setResizeMode(), ResizeMode 360 */ 372 361 373 362 QwtPicker::ResizeMode QwtPicker::resizeMode() const 374 363 { 375 return d_data->resizeMode;376 } 377 378 /*! 379 \brief En/disable the picker 380 381 When enabled is true an event filter is installed for 382 the observed widget, otherwise the event filter is removed. 383 384 \param enabled true or false 385 \sa isEnabled(), eventFilter() 386 */ 364 return m_data->resizeMode; 365 } 366 367 /*! 368 \brief En/disable the picker 369 370 When enabled is true an event filter is installed for 371 the observed widget, otherwise the event filter is removed. 372 373 \param enabled true or false 374 \sa isEnabled(), eventFilter() 375 */ 387 376 void QwtPicker::setEnabled( bool enabled ) 388 377 { 389 if ( d_data->enabled != enabled )390 { 391 d_data->enabled = enabled;392 393 QWidget *w = parentWidget();378 if ( m_data->enabled != enabled ) 379 { 380 m_data->enabled = enabled; 381 382 QWidget* w = parentWidget(); 394 383 if ( w ) 395 384 { … … 405 394 406 395 /*! 407 \return true when enabled, false otherwise 408 \sa setEnabled(), eventFilter() 409 */ 396 \return true when enabled, false otherwise 397 \sa setEnabled(), eventFilter() 398 */ 410 399 411 400 bool QwtPicker::isEnabled() const 412 401 { 413 return d_data->enabled;414 } 415 416 /*! 417 Set the font for the tracker 418 419 \param font Tracker font 420 \sa trackerFont(), setTrackerMode(), setTrackerPen() 421 */ 422 void QwtPicker::setTrackerFont( const QFont &font )423 { 424 if ( font != d_data->trackerFont )425 { 426 d_data->trackerFont = font;402 return m_data->enabled; 403 } 404 405 /*! 406 Set the font for the tracker 407 408 \param font Tracker font 409 \sa trackerFont(), setTrackerMode(), setTrackerPen() 410 */ 411 void QwtPicker::setTrackerFont( const QFont& font ) 412 { 413 if ( font != m_data->trackerFont ) 414 { 415 m_data->trackerFont = font; 427 416 updateDisplay(); 428 417 } … … 430 419 431 420 /*! 432 \return Tracker font 433 \sa setTrackerFont(), trackerMode(), trackerPen() 434 */ 421 \return Tracker font 422 \sa setTrackerFont(), trackerMode(), trackerPen() 423 */ 435 424 436 425 QFont QwtPicker::trackerFont() const 437 426 { 438 return d_data->trackerFont;439 } 440 441 /*! 442 Set the pen for the tracker 443 444 \param pen Tracker pen 445 \sa trackerPen(), setTrackerMode(), setTrackerFont() 446 */ 447 void QwtPicker::setTrackerPen( const QPen &pen )448 { 449 if ( pen != d_data->trackerPen )450 { 451 d_data->trackerPen = pen;427 return m_data->trackerFont; 428 } 429 430 /*! 431 Set the pen for the tracker 432 433 \param pen Tracker pen 434 \sa trackerPen(), setTrackerMode(), setTrackerFont() 435 */ 436 void QwtPicker::setTrackerPen( const QPen& pen ) 437 { 438 if ( pen != m_data->trackerPen ) 439 { 440 m_data->trackerPen = pen; 452 441 updateDisplay(); 453 442 } … … 455 444 456 445 /*! 457 \return Tracker pen 458 \sa setTrackerPen(), trackerMode(), trackerFont() 459 */ 446 \return Tracker pen 447 \sa setTrackerPen(), trackerMode(), trackerFont() 448 */ 460 449 QPen QwtPicker::trackerPen() const 461 450 { 462 return d_data->trackerPen;463 } 464 465 /*! 466 Set the pen for the rubberband 467 468 \param pen Rubber band pen 469 \sa rubberBandPen(), setRubberBand() 470 */ 471 void QwtPicker::setRubberBandPen( const QPen &pen )472 { 473 if ( pen != d_data->rubberBandPen )474 { 475 d_data->rubberBandPen = pen;451 return m_data->trackerPen; 452 } 453 454 /*! 455 Set the pen for the rubberband 456 457 \param pen Rubber band pen 458 \sa rubberBandPen(), setRubberBand() 459 */ 460 void QwtPicker::setRubberBandPen( const QPen& pen ) 461 { 462 if ( pen != m_data->rubberBandPen ) 463 { 464 m_data->rubberBandPen = pen; 476 465 updateDisplay(); 477 466 } … … 479 468 480 469 /*! 481 \return Rubber band pen 482 \sa setRubberBandPen(), rubberBand() 483 */ 470 \return Rubber band pen 471 \sa setRubberBandPen(), rubberBand() 472 */ 484 473 QPen QwtPicker::rubberBandPen() const 485 474 { 486 return d_data->rubberBandPen;475 return m_data->rubberBandPen; 487 476 } 488 477 … … 498 487 \param pos Position 499 488 \return Converted position as string 500 */ 501 502 QwtText QwtPicker::trackerText( const QPoint &pos ) const489 */ 490 491 QwtText QwtPicker::trackerText( const QPoint& pos ) const 503 492 { 504 493 QString label; … … 507 496 { 508 497 case HLineRubberBand: 509 label .sprintf( "%d",pos.y() );498 label = QString::number( pos.y() ); 510 499 break; 511 500 case VLineRubberBand: 512 label .sprintf( "%d",pos.x() );501 label = QString::number( pos.x() ); 513 502 break; 514 503 default: 515 label .sprintf( "%d, %d",pos.x(),pos.y() );504 label = QString::number( pos.x() ) + ", " + QString::number( pos.y() ); 516 505 } 517 506 return label; … … 519 508 520 509 /*! 521 Calculate the mask for the rubber band overlay 522 523 \return Region for the mask 524 \sa QWidget::setMask() 510 Calculate the mask for the tracker overlay 511 512 \return Region with one rectangle: trackerRect( trackerFont() ); 513 \sa QWidget::setMask(), trackerRect() 514 */ 515 QRegion QwtPicker::trackerMask() const 516 { 517 return trackerRect( m_data->trackerFont ); 518 } 519 520 /*! 521 Calculate the mask for the rubber band overlay 522 523 \return Region for the mask 524 \sa QWidget::setMask() 525 525 */ 526 526 QRegion QwtPicker::rubberBandMask() const … … 534 534 } 535 535 536 const QPolygon pa = adjustedPoints( d_data->pickedPoints );536 const QPolygon pa = adjustedPoints( m_data->pickedPoints ); 537 537 538 538 QwtPickerMachine::SelectionType selectionType = 539 539 QwtPickerMachine::NoSelection; 540 540 541 if ( d_data->stateMachine ) 542 selectionType = d_data->stateMachine->selectionType(); 541 if ( m_data->stateMachine ) 542 selectionType = m_data->stateMachine->selectionType(); 543 544 const int pw = qCeil( rubberBandPen().widthF() 545 * QwtPainter::devicePixelRatio( parentWidget() ) ); 543 546 544 547 switch ( selectionType ) … … 551 554 552 555 const QPoint pos = pa[0]; 553 const int pw = rubberBandPen().width();554 556 555 557 const QRect pRect = pickArea().boundingRect().toRect(); … … 586 588 return mask; 587 589 588 const int pw = rubberBandPen().width();589 590 590 switch ( rubberBand() ) 591 591 { … … 609 609 case QwtPickerMachine::PolygonSelection: 610 610 { 611 const int pw = rubberBandPen().width();612 611 if ( pw <= 1 ) 613 612 { … … 634 633 635 634 \sa rubberBand(), RubberBand 636 */ 637 638 void QwtPicker::drawRubberBand( QPainter *painter ) const635 */ 636 637 void QwtPicker::drawRubberBand( QPainter* painter ) const 639 638 { 640 639 if ( !isActive() || rubberBand() == NoRubberBand || … … 644 643 } 645 644 646 const QPolygon pa = adjustedPoints( d_data->pickedPoints );645 const QPolygon pa = adjustedPoints( m_data->pickedPoints ); 647 646 648 647 QwtPickerMachine::SelectionType selectionType = 649 648 QwtPickerMachine::NoSelection; 650 649 651 if ( d_data->stateMachine )652 selectionType = d_data->stateMachine->selectionType();650 if ( m_data->stateMachine ) 651 selectionType = m_data->stateMachine->selectionType(); 653 652 654 653 switch ( selectionType ) … … 729 728 \param painter Painter 730 729 \sa trackerRect(), trackerText() 731 */ 732 733 void QwtPicker::drawTracker( QPainter *painter ) const730 */ 731 732 void QwtPicker::drawTracker( QPainter* painter ) const 734 733 { 735 734 const QRect textRect = trackerRect( painter->font() ); 736 735 if ( !textRect.isEmpty() ) 737 736 { 738 const QwtText label = trackerText( d_data->trackerPosition );737 const QwtText label = trackerText( m_data->trackerPosition ); 739 738 if ( !label.isEmpty() ) 740 739 label.draw( painter, textRect ); … … 759 758 point is the center of the selected rectangle. 760 759 761 \par Example 762 \code 760 \par Example 761 \code 763 762 QPolygon MyPicker::adjustedPoints( const QPolygon &points ) const 764 763 { … … 777 776 return adjusted; 778 777 } 779 \endcode 780 \endpar 781 782 \param points Selected points 783 \return Selected points unmodified 784 */ 785 QPolygon QwtPicker::adjustedPoints( const QPolygon &points ) const 778 \endcode 779 780 \param points Selected points 781 \return Selected points unmodified 782 */ 783 QPolygon QwtPicker::adjustedPoints( const QPolygon& points ) const 786 784 { 787 785 return points; … … 789 787 790 788 /*! 791 \return Selected points 792 \sa pickedPoints(), adjustedPoints() 793 */ 789 \return Selected points 790 \sa pickedPoints(), adjustedPoints() 791 */ 794 792 QPolygon QwtPicker::selection() const 795 793 { 796 return adjustedPoints( d_data->pickedPoints );794 return adjustedPoints( m_data->pickedPoints ); 797 795 } 798 796 … … 800 798 QPoint QwtPicker::trackerPosition() const 801 799 { 802 return d_data->trackerPosition;800 return m_data->trackerPosition; 803 801 } 804 802 … … 811 809 812 810 \sa trackerPosition() 813 */ 814 QRect QwtPicker::trackerRect( const QFont &font ) const811 */ 812 QRect QwtPicker::trackerRect( const QFont& font ) const 815 813 { 816 814 if ( trackerMode() == AlwaysOff || … … 820 818 } 821 819 822 if ( d_data->trackerPosition.x() < 0 ||d_data->trackerPosition.y() < 0 )820 if ( m_data->trackerPosition.x() < 0 || m_data->trackerPosition.y() < 0 ) 823 821 return QRect(); 824 822 825 QwtText text = trackerText( d_data->trackerPosition );823 QwtText text = trackerText( m_data->trackerPosition ); 826 824 if ( text.isEmpty() ) 827 825 return QRect(); 828 826 829 827 const QSizeF textSize = text.textSize( font ); 830 QRect textRect( 0, 0, qCeil( textSize.width() ), qCeil( textSize.height() ) ); 831 832 const QPoint &pos = d_data->trackerPosition; 828 829 const int w = qwtCeil( textSize.width() ); 830 const int h = qwtCeil( textSize.height() ); 831 832 return trackerRect( QSize( w, h ) ); 833 } 834 835 /*! 836 Calculate the geometry of the tracker that is needed to display 837 information of a specific size at the tracker position 838 839 \param size Size 840 \return Bounding rectangle of the tracker 841 842 \sa trackerPosition() 843 */ 844 QRect QwtPicker::trackerRect( const QSize& size ) const 845 { 846 const QPoint& pos = m_data->trackerPosition; 847 QRect infoRect( 0, 0, size.width(), size.height() ); 833 848 834 849 int alignment = 0; 835 if ( isActive() && d_data->pickedPoints.count() > 1850 if ( isActive() && m_data->pickedPoints.count() > 1 836 851 && rubberBand() != NoRubberBand ) 837 852 { 838 853 const QPoint last = 839 d_data->pickedPoints[d_data->pickedPoints.count() - 2 ];854 m_data->pickedPoints[ m_data->pickedPoints.count() - 2 ]; 840 855 841 856 alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft; … … 843 858 } 844 859 else 860 { 845 861 alignment = Qt::AlignTop | Qt::AlignRight; 862 } 846 863 847 864 const int margin = 5; … … 849 866 int x = pos.x(); 850 867 if ( alignment & Qt::AlignLeft ) 851 x -= textRect.width() + margin;868 x -= infoRect.width() + margin; 852 869 else if ( alignment & Qt::AlignRight ) 853 870 x += margin; … … 857 874 y += margin; 858 875 else if ( alignment & Qt::AlignTop ) 859 y -= textRect.height() + margin;860 861 textRect.moveTopLeft( QPoint( x, y ) );876 y -= infoRect.height() + margin; 877 878 infoRect.moveTopLeft( QPoint( x, y ) ); 862 879 863 880 const QRect pickRect = pickArea().boundingRect().toRect(); 864 881 865 int right = qMin( textRect.right(), pickRect.right() - margin );866 int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin );867 textRect.moveBottomRight( QPoint( right, bottom ) );868 869 int left = qMax( textRect.left(), pickRect.left() + margin );870 int top = qMax( textRect.top(), pickRect.top() + margin );871 textRect.moveTopLeft( QPoint( left, top ) );872 873 return textRect;874 } 875 876 /*! 877 \brief Event filter 878 879 When isEnabled() is true all events of the observed widget are filtered. 880 Mouse and keyboard events are translated into widgetMouse- and widgetKey- 881 and widgetWheel-events. Paint and Resize events are handled to keep 882 rubber band and tracker up to date. 883 884 \param object Object to be filtered 885 \param event Event 886 887 \return Always false. 888 889 \sa widgetEnterEvent(), widgetLeaveEvent(), 882 int right = qMin( infoRect.right(), pickRect.right() - margin ); 883 int bottom = qMin( infoRect.bottom(), pickRect.bottom() - margin ); 884 infoRect.moveBottomRight( QPoint( right, bottom ) ); 885 886 int left = qMax( infoRect.left(), pickRect.left() + margin ); 887 int top = qMax( infoRect.top(), pickRect.top() + margin ); 888 infoRect.moveTopLeft( QPoint( left, top ) ); 889 890 return infoRect; 891 } 892 893 /*! 894 \brief Event filter 895 896 When isEnabled() is true all events of the observed widget are filtered. 897 Mouse and keyboard events are translated into widgetMouse- and widgetKey- 898 and widgetWheel-events. Paint and Resize events are handled to keep 899 rubber band and tracker up to date. 900 901 \param object Object to be filtered 902 \param event Event 903 904 \return Always false. 905 906 \sa widgetEnterEvent(), widgetLeaveEvent(), 890 907 widgetMousePressEvent(), widgetMouseReleaseEvent(), 891 908 widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), 892 909 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent(), 893 910 QObject::installEventFilter(), QObject::event() 894 */ 895 bool QwtPicker::eventFilter( QObject *object, QEvent*event )911 */ 912 bool QwtPicker::eventFilter( QObject* object, QEvent* event ) 896 913 { 897 914 if ( object && object == parentWidget() ) … … 901 918 case QEvent::Resize: 902 919 { 903 const QResizeEvent *re = static_cast<QResizeEvent*>( event );920 const QResizeEvent* re = static_cast< QResizeEvent* >( event ); 904 921 905 922 /* 906 923 Adding/deleting additional event filters inside of an event filter 907 is not safe dues to the implementation in Qt ( changing alist while iterating ). 924 is not safe dues to the implementation in Qt ( changing a list while iterating ). 908 925 So we create the overlays in a way, that they don't install en event filter 909 926 ( parent set to NULL ) and do the resizing here. 910 927 */ 911 if ( d_data->trackerOverlay )912 d_data->trackerOverlay->resize( re->size() );913 914 if ( d_data->rubberBandOverlay )915 d_data->rubberBandOverlay->resize( re->size() );916 917 if ( d_data->resizeMode == Stretch )928 if ( m_data->trackerOverlay ) 929 m_data->trackerOverlay->resize( re->size() ); 930 931 if ( m_data->rubberBandOverlay ) 932 m_data->rubberBandOverlay->resize( re->size() ); 933 934 if ( m_data->resizeMode == Stretch ) 918 935 stretchSelection( re->oldSize(), re->size() ); 919 936 … … 933 950 case QEvent::MouseButtonPress: 934 951 { 935 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );952 widgetMousePressEvent( static_cast< QMouseEvent* >( event ) ); 936 953 break; 937 954 } 938 955 case QEvent::MouseButtonRelease: 939 956 { 940 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );957 widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) ); 941 958 break; 942 959 } 943 960 case QEvent::MouseButtonDblClick: 944 961 { 945 widgetMouseDoubleClickEvent( static_cast<QMouseEvent *>( event ) );962 widgetMouseDoubleClickEvent( static_cast< QMouseEvent* >( event ) ); 946 963 break; 947 964 } 948 965 case QEvent::MouseMove: 949 966 { 950 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );967 widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) ); 951 968 break; 952 969 } 953 970 case QEvent::KeyPress: 954 971 { 955 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );972 widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) ); 956 973 break; 957 974 } 958 975 case QEvent::KeyRelease: 959 976 { 960 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );977 widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) ); 961 978 break; 962 979 } 963 980 case QEvent::Wheel: 964 981 { 965 widgetWheelEvent( static_cast<QWheelEvent *>( event ) );982 widgetWheelEvent( static_cast< QWheelEvent* >( event ) ); 966 983 break; 967 984 } … … 974 991 975 992 /*! 976 Handle a mouse press event for the observed widget. 977 978 \param mouseEvent Mouse event 979 980 \sa eventFilter(), widgetMouseReleaseEvent(), 993 Handle a mouse press event for the observed widget. 994 995 \param mouseEvent Mouse event 996 997 \sa eventFilter(), widgetMouseReleaseEvent(), 981 998 widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), 982 999 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() 983 */ 984 void QwtPicker::widgetMousePressEvent( QMouseEvent *mouseEvent )1000 */ 1001 void QwtPicker::widgetMousePressEvent( QMouseEvent* mouseEvent ) 985 1002 { 986 1003 transition( mouseEvent ); … … 988 1005 989 1006 /*! 990 Handle a mouse move event for the observed widget. 991 992 \param mouseEvent Mouse event 993 994 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1007 Handle a mouse move event for the observed widget. 1008 1009 \param mouseEvent Mouse event 1010 1011 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 995 1012 widgetMouseDoubleClickEvent(), 996 1013 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() 997 */ 998 void QwtPicker::widgetMouseMoveEvent( QMouseEvent *mouseEvent )1014 */ 1015 void QwtPicker::widgetMouseMoveEvent( QMouseEvent* mouseEvent ) 999 1016 { 1000 1017 if ( pickArea().contains( mouseEvent->pos() ) ) 1001 d_data->trackerPosition = mouseEvent->pos();1018 m_data->trackerPosition = mouseEvent->pos(); 1002 1019 else 1003 d_data->trackerPosition = QPoint( -1, -1 );1020 m_data->trackerPosition = QPoint( -1, -1 ); 1004 1021 1005 1022 if ( !isActive() ) … … 1010 1027 1011 1028 /*! 1012 Handle a enter event for the observed widget. 1013 1014 \param event Qt event 1015 1016 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1029 Handle a enter event for the observed widget. 1030 1031 \param event Qt event 1032 1033 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1017 1034 widgetMouseDoubleClickEvent(), 1018 1035 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() 1019 */ 1020 void QwtPicker::widgetEnterEvent( QEvent *event )1036 */ 1037 void QwtPicker::widgetEnterEvent( QEvent* event ) 1021 1038 { 1022 1039 transition( event ); … … 1024 1041 1025 1042 /*! 1026 Handle a leave event for the observed widget. 1027 1028 \param event Qt event 1029 1030 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1043 Handle a leave event for the observed widget. 1044 1045 \param event Qt event 1046 1047 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1031 1048 widgetMouseDoubleClickEvent(), 1032 1049 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() 1033 */ 1034 void QwtPicker::widgetLeaveEvent( QEvent *event )1050 */ 1051 void QwtPicker::widgetLeaveEvent( QEvent* event ) 1035 1052 { 1036 1053 transition( event ); 1037 1054 1038 d_data->trackerPosition = QPoint( -1, -1 );1055 m_data->trackerPosition = QPoint( -1, -1 ); 1039 1056 if ( !isActive() ) 1040 1057 updateDisplay(); … … 1042 1059 1043 1060 /*! 1044 Handle a mouse release event for the observed widget. 1045 1046 \param mouseEvent Mouse event 1047 1048 \sa eventFilter(), widgetMousePressEvent(), 1061 Handle a mouse release event for the observed widget. 1062 1063 \param mouseEvent Mouse event 1064 1065 \sa eventFilter(), widgetMousePressEvent(), 1049 1066 widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), 1050 1067 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() 1051 */ 1052 void QwtPicker::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )1068 */ 1069 void QwtPicker::widgetMouseReleaseEvent( QMouseEvent* mouseEvent ) 1053 1070 { 1054 1071 transition( mouseEvent ); … … 1056 1073 1057 1074 /*! 1058 Handle mouse double click event for the observed widget. 1059 1060 \param mouseEvent Mouse event 1061 1062 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1075 Handle mouse double click event for the observed widget. 1076 1077 \param mouseEvent Mouse event 1078 1079 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1063 1080 widgetMouseMoveEvent(), 1064 1081 widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() 1065 */ 1066 void QwtPicker::widgetMouseDoubleClickEvent( QMouseEvent *mouseEvent )1082 */ 1083 void QwtPicker::widgetMouseDoubleClickEvent( QMouseEvent* mouseEvent ) 1067 1084 { 1068 1085 transition( mouseEvent ); … … 1071 1088 1072 1089 /*! 1073 Handle a wheel event for the observed widget. 1074 1075 Move the last point of the selection in case of isActive() == true 1076 1077 \param wheelEvent Wheel event 1078 1079 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1090 Handle a wheel event for the observed widget. 1091 1092 Move the last point of the selection in case of isActive() == true 1093 1094 \param wheelEvent Wheel event 1095 1096 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1080 1097 widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), 1081 1098 widgetKeyPressEvent(), widgetKeyReleaseEvent() 1082 */ 1083 void QwtPicker::widgetWheelEvent( QWheelEvent *wheelEvent ) 1084 { 1085 if ( pickArea().contains( wheelEvent->pos() ) ) 1086 d_data->trackerPosition = wheelEvent->pos(); 1099 */ 1100 void QwtPicker::widgetWheelEvent( QWheelEvent* wheelEvent ) 1101 { 1102 #if QT_VERSION < 0x050e00 1103 const QPoint wheelPos = wheelEvent->pos(); 1104 #else 1105 const QPoint wheelPos = wheelEvent->position().toPoint(); 1106 #endif 1107 if ( pickArea().contains( wheelPos ) ) 1108 m_data->trackerPosition = wheelPos; 1087 1109 else 1088 d_data->trackerPosition = QPoint( -1, -1 );1110 m_data->trackerPosition = QPoint( -1, -1 ); 1089 1111 1090 1112 updateDisplay(); … … 1094 1116 1095 1117 /*! 1096 Handle a key press event for the observed widget. 1097 1098 Selections can be completely done by the keyboard. The arrow keys 1099 move the cursor, the abort key aborts a selection. All other keys 1100 are handled by the current state machine. 1101 1102 \param keyEvent Key event 1103 1104 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1118 Handle a key press event for the observed widget. 1119 1120 Selections can be completely done by the keyboard. The arrow keys 1121 move the cursor, the abort key aborts a selection. All other keys 1122 are handled by the current state machine. 1123 1124 \param keyEvent Key event 1125 1126 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1105 1127 widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), 1106 1128 widgetWheelEvent(), widgetKeyReleaseEvent(), stateMachine(), 1107 1129 QwtEventPattern::KeyPatternCode 1108 */ 1109 void QwtPicker::widgetKeyPressEvent( QKeyEvent *keyEvent )1130 */ 1131 void QwtPicker::widgetKeyPressEvent( QKeyEvent* keyEvent ) 1110 1132 { 1111 1133 int dx = 0; … … 1149 1171 1150 1172 /*! 1151 Handle a key release event for the observed widget. 1152 1153 Passes the event to the state machine. 1154 1155 \param keyEvent Key event 1156 1157 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1173 Handle a key release event for the observed widget. 1174 1175 Passes the event to the state machine. 1176 1177 \param keyEvent Key event 1178 1179 \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), 1158 1180 widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), 1159 1181 widgetWheelEvent(), widgetKeyPressEvent(), stateMachine() 1160 */ 1161 void QwtPicker::widgetKeyReleaseEvent( QKeyEvent *keyEvent )1182 */ 1183 void QwtPicker::widgetKeyReleaseEvent( QKeyEvent* keyEvent ) 1162 1184 { 1163 1185 transition( keyEvent ); … … 1165 1187 1166 1188 /*! 1167 Passes an event to the state machine and executes the resulting 1168 commands. Append and Move commands use the current position 1169 of the cursor ( QCursor::pos() ). 1170 1171 \param event Event 1172 */ 1173 void QwtPicker::transition( const QEvent *event )1174 { 1175 if ( ! d_data->stateMachine )1189 Passes an event to the state machine and executes the resulting 1190 commands. Append and Move commands use the current position 1191 of the cursor ( QCursor::pos() ). 1192 1193 \param event Event 1194 */ 1195 void QwtPicker::transition( const QEvent* event ) 1196 { 1197 if ( !m_data->stateMachine ) 1176 1198 return; 1177 1199 1178 const QList<QwtPickerMachine::Command> commandList = 1179 d_data->stateMachine->transition( *this, event );1200 const QList< QwtPickerMachine::Command > commandList = 1201 m_data->stateMachine->transition( *this, event ); 1180 1202 1181 1203 QPoint pos; … … 1187 1209 case QEvent::MouseMove: 1188 1210 { 1189 const QMouseEvent *me =1190 static_cast< const QMouseEvent * >( event );1211 const QMouseEvent* me = 1212 static_cast< const QMouseEvent* >( event ); 1191 1213 pos = me->pos(); 1192 1214 break; … … 1230 1252 1231 1253 /*! 1232 Open a selection setting the state to active 1233 1234 \sa isActive(), end(), append(), move() 1235 */ 1254 Open a selection setting the state to active 1255 1256 \sa isActive(), end(), append(), move() 1257 */ 1236 1258 void QwtPicker::begin() 1237 1259 { 1238 if ( d_data->isActive )1260 if ( m_data->isActive ) 1239 1261 return; 1240 1262 1241 d_data->pickedPoints.clear();1242 d_data->isActive = true;1263 m_data->pickedPoints.clear(); 1264 m_data->isActive = true; 1243 1265 Q_EMIT activated( true ); 1244 1266 1245 1267 if ( trackerMode() != AlwaysOff ) 1246 1268 { 1247 if ( d_data->trackerPosition.x() < 0 ||d_data->trackerPosition.y() < 0 )1248 { 1249 QWidget *w = parentWidget();1269 if ( m_data->trackerPosition.x() < 0 || m_data->trackerPosition.y() < 0 ) 1270 { 1271 QWidget* w = parentWidget(); 1250 1272 if ( w ) 1251 d_data->trackerPosition = w->mapFromGlobal( QCursor::pos() );1273 m_data->trackerPosition = w->mapFromGlobal( QCursor::pos() ); 1252 1274 } 1253 1275 } … … 1258 1280 1259 1281 /*! 1260 \brief Close a selection setting the state to inactive. 1261 1262 The selection is validated and maybe fixed by accept(). 1263 1264 \param ok If true, complete the selection and emit a selected signal 1282 \brief Close a selection setting the state to inactive. 1283 1284 The selection is validated and maybe fixed by accept(). 1285 1286 \param ok If true, complete the selection and emit a selected signal 1265 1287 otherwise discard the selection. 1266 \return true if the selection is accepted, false otherwise 1267 \sa isActive(), begin(), append(), move(), selected(), accept() 1268 */ 1288 \return true if the selection is accepted, false otherwise 1289 \sa isActive(), begin(), append(), move(), selected(), accept() 1290 */ 1269 1291 bool QwtPicker::end( bool ok ) 1270 1292 { 1271 if ( d_data->isActive )1293 if ( m_data->isActive ) 1272 1294 { 1273 1295 setMouseTracking( false ); 1274 1296 1275 d_data->isActive = false;1297 m_data->isActive = false; 1276 1298 Q_EMIT activated( false ); 1277 1299 1278 1300 if ( trackerMode() == ActiveOnly ) 1279 d_data->trackerPosition = QPoint( -1, -1 );1301 m_data->trackerPosition = QPoint( -1, -1 ); 1280 1302 1281 1303 if ( ok ) 1282 ok = accept( d_data->pickedPoints );1304 ok = accept( m_data->pickedPoints ); 1283 1305 1284 1306 if ( ok ) 1285 Q_EMIT selected( d_data->pickedPoints );1307 Q_EMIT selected( m_data->pickedPoints ); 1286 1308 else 1287 d_data->pickedPoints.clear();1309 m_data->pickedPoints.clear(); 1288 1310 1289 1311 updateDisplay(); … … 1297 1319 /*! 1298 1320 Reset the state machine and terminate ( end(false) ) the selection 1299 */ 1321 */ 1300 1322 void QwtPicker::reset() 1301 1323 { 1302 if ( d_data->stateMachine )1303 d_data->stateMachine->reset();1324 if ( m_data->stateMachine ) 1325 m_data->stateMachine->reset(); 1304 1326 1305 1327 if ( isActive() ) … … 1308 1330 1309 1331 /*! 1310 Append a point to the selection and update rubber band and tracker. 1311 The appended() signal is emitted. 1312 1313 \param pos Additional point 1314 1315 \sa isActive(), begin(), end(), move(), appended() 1316 */ 1317 void QwtPicker::append( const QPoint &pos )1318 { 1319 if ( d_data->isActive )1320 { 1321 d_data->pickedPoints += pos;1332 Append a point to the selection and update rubber band and tracker. 1333 The appended() signal is emitted. 1334 1335 \param pos Additional point 1336 1337 \sa isActive(), begin(), end(), move(), appended() 1338 */ 1339 void QwtPicker::append( const QPoint& pos ) 1340 { 1341 if ( m_data->isActive ) 1342 { 1343 m_data->pickedPoints += pos; 1322 1344 1323 1345 updateDisplay(); … … 1327 1349 1328 1350 /*! 1329 Move the last point of the selection 1330 The moved() signal is emitted. 1331 1332 \param pos New position 1333 \sa isActive(), begin(), end(), append() 1334 */ 1335 void QwtPicker::move( const QPoint &pos )1336 { 1337 if ( d_data->isActive && !d_data->pickedPoints.isEmpty() )1338 { 1339 QPoint &point =d_data->pickedPoints.last();1351 Move the last point of the selection 1352 The moved() signal is emitted. 1353 1354 \param pos New position 1355 \sa isActive(), begin(), end(), append() 1356 */ 1357 void QwtPicker::move( const QPoint& pos ) 1358 { 1359 if ( m_data->isActive && !m_data->pickedPoints.isEmpty() ) 1360 { 1361 QPoint& point = m_data->pickedPoints.last(); 1340 1362 if ( point != pos ) 1341 1363 { … … 1349 1371 1350 1372 /*! 1351 Remove the last point of the selection 1352 The removed() signal is emitted. 1353 1354 \sa isActive(), begin(), end(), append(), move() 1355 */ 1373 Remove the last point of the selection 1374 The removed() signal is emitted. 1375 1376 \sa isActive(), begin(), end(), append(), move() 1377 */ 1356 1378 void QwtPicker::remove() 1357 1379 { 1358 if ( d_data->isActive && !d_data->pickedPoints.isEmpty() )1380 if ( m_data->isActive && !m_data->pickedPoints.isEmpty() ) 1359 1381 { 1360 1382 #if QT_VERSION >= 0x050100 1361 const QPoint pos = d_data->pickedPoints.takeLast();1383 const QPoint pos = m_data->pickedPoints.takeLast(); 1362 1384 #else 1363 const QPoint pos = d_data->pickedPoints.last();1364 d_data->pickedPoints.resize(d_data->pickedPoints.count() - 1 );1385 const QPoint pos = m_data->pickedPoints.last(); 1386 m_data->pickedPoints.resize( m_data->pickedPoints.count() - 1 ); 1365 1387 #endif 1366 1388 … … 1371 1393 1372 1394 /*! 1373 \brief Validate and fix up the selection 1374 1375 Accepts all selections unmodified 1376 1377 \param selection Selection to validate and fix up 1378 \return true, when accepted, false otherwise 1379 */ 1380 bool QwtPicker::accept( QPolygon &selection ) const1395 \brief Validate and fix up the selection 1396 1397 Accepts all selections unmodified 1398 1399 \param selection Selection to validate and fix up 1400 \return true, when accepted, false otherwise 1401 */ 1402 bool QwtPicker::accept( QPolygon& selection ) const 1381 1403 { 1382 1404 Q_UNUSED( selection ); … … 1385 1407 1386 1408 /*! 1387 A picker is active between begin() and end(). 1388 \return true if the selection is active. 1389 */ 1409 A picker is active between begin() and end(). 1410 \return true if the selection is active. 1411 */ 1390 1412 bool QwtPicker::isActive() const 1391 1413 { 1392 return d_data->isActive;1393 } 1394 1395 /*! 1396 Return the points, that have been collected so far. The selection() 1397 is calculated from the pickedPoints() in adjustedPoints(). 1398 \return Picked points 1399 */ 1400 const QPolygon &QwtPicker::pickedPoints() const1401 { 1402 return d_data->pickedPoints;1403 } 1404 1405 /*! 1406 Scale the selection by the ratios of oldSize and newSize 1407 The changed() signal is emitted. 1408 1409 \param oldSize Previous size 1410 \param newSize Current size 1411 1412 \sa ResizeMode, setResizeMode(), resizeMode() 1413 */ 1414 void QwtPicker::stretchSelection( const QSize &oldSize, const QSize&newSize )1414 return m_data->isActive; 1415 } 1416 1417 /*! 1418 Return the points, that have been collected so far. The selection() 1419 is calculated from the pickedPoints() in adjustedPoints(). 1420 \return Picked points 1421 */ 1422 const QPolygon& QwtPicker::pickedPoints() const 1423 { 1424 return m_data->pickedPoints; 1425 } 1426 1427 /*! 1428 Scale the selection by the ratios of oldSize and newSize 1429 The changed() signal is emitted. 1430 1431 \param oldSize Previous size 1432 \param newSize Current size 1433 1434 \sa ResizeMode, setResizeMode(), resizeMode() 1435 */ 1436 void QwtPicker::stretchSelection( const QSize& oldSize, const QSize& newSize ) 1415 1437 { 1416 1438 if ( oldSize.isEmpty() ) … … 1424 1446 const double yRatio = double( newSize.height() ) / double( oldSize.height() ); 1425 1447 1426 for ( int i = 0; i < d_data->pickedPoints.count(); i++ )1427 { 1428 QPoint &p = d_data->pickedPoints[i];1448 for ( int i = 0; i < m_data->pickedPoints.count(); i++ ) 1449 { 1450 QPoint& p = m_data->pickedPoints[i]; 1429 1451 p.setX( qRound( p.x() * xRatio ) ); 1430 1452 p.setY( qRound( p.y() * yRatio ) ); 1431 1453 1432 Q_EMIT changed( d_data->pickedPoints );1433 } 1434 } 1435 1436 /*! 1437 Set mouse tracking for the observed widget. 1438 1439 In case of enable is true, the previous value 1440 is saved, that is restored when enable is false. 1441 1442 \warning Even when enable is false, mouse tracking might be restored 1454 Q_EMIT changed( m_data->pickedPoints ); 1455 } 1456 } 1457 1458 /*! 1459 Set mouse tracking for the observed widget. 1460 1461 In case of enable is true, the previous value 1462 is saved, that is restored when enable is false. 1463 1464 \warning Even when enable is false, mouse tracking might be restored 1443 1465 to true. When mouseTracking for the observed widget 1444 1466 has been changed directly by QWidget::setMouseTracking 1445 1467 while mouse tracking has been set to true, this value can't 1446 1468 be restored. 1447 */ 1469 */ 1448 1470 1449 1471 void QwtPicker::setMouseTracking( bool enable ) 1450 1472 { 1451 QWidget *widget = parentWidget();1473 QWidget* widget = parentWidget(); 1452 1474 if ( !widget ) 1453 1475 return; … … 1455 1477 if ( enable ) 1456 1478 { 1457 d_data->mouseTracking = widget->hasMouseTracking();1479 m_data->mouseTracking = widget->hasMouseTracking(); 1458 1480 widget->setMouseTracking( true ); 1459 1481 } 1460 1482 else 1461 1483 { 1462 widget->setMouseTracking( d_data->mouseTracking );1463 } 1464 } 1465 1466 /*! 1467 Find the area of the observed widget, where selection might happen. 1468 1469 \return parentWidget()->contentsRect() 1470 */ 1484 widget->setMouseTracking( m_data->mouseTracking ); 1485 } 1486 } 1487 1488 /*! 1489 Find the area of the observed widget, where selection might happen. 1490 1491 \return parentWidget()->contentsRect() 1492 */ 1471 1493 QPainterPath QwtPicker::pickArea() const 1472 1494 { 1473 1495 QPainterPath path; 1474 1496 1475 const QWidget *widget = parentWidget();1497 const QWidget* widget = parentWidget(); 1476 1498 if ( widget ) 1477 1499 path.addRect( widget->contentsRect() ); … … 1483 1505 void QwtPicker::updateDisplay() 1484 1506 { 1485 QWidget *w = parentWidget();1507 QWidget* w = parentWidget(); 1486 1508 1487 1509 bool showRubberband = false; 1488 1510 bool showTracker = false; 1489 1511 1490 if ( w && w->isVisible() && d_data->enabled )1512 if ( w && w->isVisible() && m_data->enabled ) 1491 1513 { 1492 1514 if ( rubberBand() != NoRubberBand && isActive() && … … 1507 1529 } 1508 1530 1509 QPointer< QwtPickerRubberband >&rw = d_data->rubberBandOverlay;1531 QPointer< Rubberband >& rw = m_data->rubberBandOverlay; 1510 1532 if ( showRubberband ) 1511 1533 { 1512 1534 if ( rw.isNull() ) 1513 1535 { 1514 rw = new QwtPickerRubberband( this, NULL ); // NULL -> no extra event filter1536 rw = new Rubberband( this, NULL ); // NULL -> no extra event filter 1515 1537 rw->setObjectName( "PickerRubberBand" ); 1516 1538 rw->setParent( w ); … … 1518 1540 } 1519 1541 1520 if ( d_data->rubberBand <= RectRubberBand )1542 if ( m_data->rubberBand <= RectRubberBand ) 1521 1543 rw->setMaskMode( QwtWidgetOverlay::MaskHint ); 1522 1544 else … … 1527 1549 else 1528 1550 { 1529 if ( d_data->openGL )1551 if ( m_data->openGL ) 1530 1552 { 1531 1553 // Qt 4.8 crashes for a delete … … 1543 1565 } 1544 1566 1545 QPointer< QwtPickerTracker >&tw = d_data->trackerOverlay;1567 QPointer< Tracker >& tw = m_data->trackerOverlay; 1546 1568 if ( showTracker ) 1547 1569 { 1548 1570 if ( tw.isNull() ) 1549 1571 { 1550 tw = new QwtPickerTracker( this, NULL ); // NULL -> no extra event filter1572 tw = new Tracker( this, NULL ); // NULL -> no extra event filter 1551 1573 tw->setObjectName( "PickerTracker" ); 1552 1574 tw->setParent( w ); 1553 1575 tw->resize( w->size() ); 1554 1576 } 1555 tw->setFont( d_data->trackerFont );1577 tw->setFont( m_data->trackerFont ); 1556 1578 tw->updateOverlay(); 1557 1579 } 1558 1580 else 1559 1581 { 1560 if ( d_data->openGL )1582 if ( m_data->openGL ) 1561 1583 { 1562 1584 // Qt 4.8 crashes for a delete … … 1576 1598 1577 1599 //! \return Overlay displaying the rubber band 1578 const QwtWidgetOverlay *QwtPicker::rubberBandOverlay() const1579 { 1580 return d_data->rubberBandOverlay;1600 const QwtWidgetOverlay* QwtPicker::rubberBandOverlay() const 1601 { 1602 return m_data->rubberBandOverlay; 1581 1603 } 1582 1604 1583 1605 //! \return Overlay displaying the tracker text 1584 const QwtWidgetOverlay *QwtPicker::trackerOverlay() const 1585 { 1586 return d_data->trackerOverlay; 1587 } 1588 1606 const QwtWidgetOverlay* QwtPicker::trackerOverlay() const 1607 { 1608 return m_data->trackerOverlay; 1609 } 1610 1611 #include "moc_qwt_picker.cpp" -
trunk/BNC/qwt/qwt_picker.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PICKER 11 #define QWT_PICKER 111 #define QWT_PICKER 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_text.h"15 14 #include "qwt_event_pattern.h" 15 16 16 #include <qobject.h> 17 #include <qpen.h> 18 #include <qfont.h> 19 #include <qrect.h> 20 #include <qpainterpath.h> 21 17 18 class QwtPickerMachine; 19 class QwtWidgetOverlay; 20 class QwtText; 22 21 class QWidget; 23 22 class QMouseEvent; 24 23 class QWheelEvent; 25 24 class QKeyEvent; 26 class QwtPickerMachine; 27 class QwtWidgetOverlay; 25 class QPainter; 26 class QPen; 27 class QFont; 28 class QRegion; 29 class QPainterPath; 30 class QPoint; 31 class QRect; 32 class QSize; 33 class QPolygon; 28 34 29 35 /*! 30 \brief QwtPicker provides selections on a widget 31 32 QwtPicker filters all enter, leave, mouse and keyboard events of a widget 33 and translates them into an array of selected points. 34 35 The way how the points are collected depends on type of state machine 36 that is connected to the picker. Qwt offers a couple of predefined 37 state machines for selecting: 38 39 - Nothing\n 36 \brief QwtPicker provides selections on a widget 37 38 QwtPicker filters all enter, leave, mouse and keyboard events of a widget 39 and translates them into an array of selected points. 40 41 The way how the points are collected depends on type of state machine 42 that is connected to the picker. Qwt offers a couple of predefined 43 state machines for selecting: 44 45 - Nothing\n 40 46 QwtPickerTrackerMachine 41 - Single points\n 47 - Single points\n 42 48 QwtPickerClickPointMachine, QwtPickerDragPointMachine 43 - Rectangles\n 49 - Rectangles\n 44 50 QwtPickerClickRectMachine, QwtPickerDragRectMachine 45 - Polygons\n 51 - Polygons\n 46 52 QwtPickerPolygonMachine 47 53 48 While these state machines cover the most common ways to collect points 49 it is also possible to implement individual machines as well. 50 51 QwtPicker translates the picked points into a selection using the 52 adjustedPoints() method. adjustedPoints() is intended to be reimplemented 53 to fix up the selection according to application specific requirements. 54 (F.e. when an application accepts rectangles of a fixed aspect ratio only.) 55 56 Optionally QwtPicker support the process of collecting points by a 57 rubber band and tracker displaying a text for the current mouse 58 position. 59 60 \par Example 61 \code 62 #include <qwt_picker.h>63 #include <qwt_picker_machine.h>54 While these state machines cover the most common ways to collect points 55 it is also possible to implement individual machines as well. 56 57 QwtPicker translates the picked points into a selection using the 58 adjustedPoints() method. adjustedPoints() is intended to be reimplemented 59 to fix up the selection according to application specific requirements. 60 (F.e. when an application accepts rectangles of a fixed aspect ratio only.) 61 62 Optionally QwtPicker support the process of collecting points by a 63 rubber band and tracker displaying a text for the current mouse 64 position. 65 66 \par Example 67 \code 68 #include <qwt_picker.h> 69 #include <qwt_picker_machine.h> 64 70 65 71 QwtPicker *picker = new QwtPicker(widget); … … 67 73 picker->setTrackerMode(QwtPicker::ActiveOnly); 68 74 picker->setRubberBand(QwtPicker::RectRubberBand); 69 \endcode 70 \endpar 71 72 The state machine triggers the following commands: 73 74 - begin()\n 75 \endcode 76 77 The state machine triggers the following commands: 78 79 - begin()\n 75 80 Activate/Initialize the selection. 76 - append()\n 81 - append()\n 77 82 Add a new point 78 - move() \n 83 - move() \n 79 84 Change the position of the last point. 80 - remove()\n 85 - remove()\n 81 86 Remove the last point. 82 - end()\n 87 - end()\n 83 88 Terminate the selection and call accept to validate the picked points. 84 89 85 The picker is active (isActive()), between begin() and end(). 86 In active state the rubber band is displayed, and the tracker is visible 87 in case of trackerMode is ActiveOnly or AlwaysOn. 88 89 The cursor can be moved using the arrow keys. All selections can be aborted 90 using the abort key. (QwtEventPattern::KeyPatternCode) 91 92 \warning In case of QWidget::NoFocus the focus policy of the observed 90 The picker is active (isActive()), between begin() and end(). 91 In active state the rubber band is displayed, and the tracker is visible 92 in case of trackerMode is ActiveOnly or AlwaysOn. 93 94 The cursor can be moved using the arrow keys. All selections can be aborted 95 using the abort key. (QwtEventPattern::KeyPatternCode) 96 97 \warning In case of QWidget::NoFocus the focus policy of the observed 93 98 widget is set to QWidget::WheelFocus and mouse tracking 94 99 will be manipulated while the picker is active, 95 100 or if trackerMode() is AlwayOn. 96 */ 97 98 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern 101 */ 102 103 class QWT_EXPORT QwtPicker : public QObject, public QwtEventPattern 99 104 { 100 105 Q_OBJECT … … 112 117 Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen ) 113 118 114 public: 115 /*! 116 Rubber band style 117 118 The default value is QwtPicker::NoRubberBand. 119 \sa setRubberBand(), rubberBand() 120 */ 119 public: 120 /*! 121 Rubber band style 122 123 The default value is QwtPicker::NoRubberBand. 124 \sa setRubberBand(), rubberBand() 125 */ 121 126 122 127 enum RubberBand … … 144 149 145 150 /*! 146 Values >= UserRubberBand can be used to define additional 147 rubber bands. 151 Values >= UserRubberBand can be used to define additional 152 rubber bands. 148 153 */ 149 154 UserRubberBand = 100 … … 151 156 152 157 /*! 153 \brief Display mode 154 \sa setTrackerMode(), trackerMode(), isActive() 155 */ 158 \brief Display mode 159 \sa setTrackerMode(), trackerMode(), isActive() 160 */ 156 161 enum DisplayMode 157 162 { … … 167 172 168 173 /*! 169 Controls what to do with the selected points of an active 174 Controls what to do with the selected points of an active 170 175 selection when the observed widget is resized. 171 176 172 The default value is QwtPicker::Stretch. 173 \sa setResizeMode() 174 */ 177 The default value is QwtPicker::Stretch. 178 \sa setResizeMode() 179 */ 175 180 176 181 enum ResizeMode … … 183 188 }; 184 189 185 explicit QwtPicker( QWidget *parent );190 explicit QwtPicker( QWidget* parent ); 186 191 explicit QwtPicker( RubberBand rubberBand, 187 DisplayMode trackerMode, QWidget* );192 DisplayMode trackerMode, QWidget* ); 188 193 189 194 virtual ~QwtPicker(); 190 195 191 void setStateMachine( QwtPickerMachine * );192 const QwtPickerMachine *stateMachine() const;193 QwtPickerMachine *stateMachine();196 void setStateMachine( QwtPickerMachine* ); 197 const QwtPickerMachine* stateMachine() const; 198 QwtPickerMachine* stateMachine(); 194 199 195 200 void setRubberBand( RubberBand ); … … 202 207 ResizeMode resizeMode() const; 203 208 204 void setRubberBandPen( const QPen & );209 void setRubberBandPen( const QPen& ); 205 210 QPen rubberBandPen() const; 206 211 207 void setTrackerPen( const QPen & );212 void setTrackerPen( const QPen& ); 208 213 QPen trackerPen() const; 209 214 210 void setTrackerFont( const QFont & );215 void setTrackerFont( const QFont& ); 211 216 QFont trackerFont() const; 212 217 … … 214 219 bool isActive() const; 215 220 216 virtual bool eventFilter( QObject *, QEvent* );217 218 QWidget *parentWidget();219 const QWidget *parentWidget() const;221 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 222 223 QWidget* parentWidget(); 224 const QWidget* parentWidget() const; 220 225 221 226 virtual QPainterPath pickArea() const; 222 227 223 virtual void drawRubberBand( QPainter * ) const; 224 virtual void drawTracker( QPainter * ) const; 225 228 virtual void drawRubberBand( QPainter* ) const; 229 virtual void drawTracker( QPainter* ) const; 230 231 virtual QRegion trackerMask() const; 226 232 virtual QRegion rubberBandMask() const; 227 233 228 virtual QwtText trackerText( const QPoint &pos ) const;234 virtual QwtText trackerText( const QPoint& pos ) const; 229 235 QPoint trackerPosition() const; 230 virtual QRect trackerRect( const QFont & ) const;236 virtual QRect trackerRect( const QFont& ) const; 231 237 232 238 QPolygon selection() const; 233 239 234 public Q_SLOTS: 240 public Q_SLOTS: 235 241 void setEnabled( bool ); 236 242 237 Q_SIGNALS: 238 /*! 239 A signal indicating, when the picker has been activated. 240 Together with setEnabled() it can be used to implement 241 selections with more than one picker. 242 243 \param on True, when the picker has been activated 244 */ 243 Q_SIGNALS: 244 /*! 245 A signal indicating, when the picker has been activated. 246 Together with setEnabled() it can be used to implement 247 selections with more than one picker. 248 249 \param on True, when the picker has been activated 250 */ 245 251 void activated( bool on ); 246 252 247 253 /*! 248 A signal emitting the selected points, 249 at the end of a selection. 250 251 \param polygon Selected points 252 */ 253 void selected( const QPolygon &polygon );254 255 /*! 256 A signal emitted when a point has been appended to the selection 257 258 \param pos Position of the appended point. 259 \sa append(). moved() 260 */ 261 void appended( const QPoint &pos );262 263 /*! 264 A signal emitted whenever the last appended point of the 265 selection has been moved. 266 267 \param pos Position of the moved last point of the selection. 268 \sa move(), appended() 269 */ 270 void moved( const QPoint &pos );271 272 /*! 273 A signal emitted whenever the last appended point of the 274 selection has been removed. 275 276 \param pos Position of the point, that has been removed 277 \sa remove(), appended() 278 */ 279 void removed( const QPoint &pos );280 /*! 281 A signal emitted when the active selection has been changed. 282 This might happen when the observed widget is resized. 283 284 \param selection Changed selection 285 \sa stretchSelection() 286 */ 287 void changed( const QPolygon &selection );288 289 protected: 290 virtual QPolygon adjustedPoints( const QPolygon & ) const;291 292 virtual void transition( const QEvent * );254 A signal emitting the selected points, 255 at the end of a selection. 256 257 \param polygon Selected points 258 */ 259 void selected( const QPolygon& polygon ); 260 261 /*! 262 A signal emitted when a point has been appended to the selection 263 264 \param pos Position of the appended point. 265 \sa append(). moved() 266 */ 267 void appended( const QPoint& pos ); 268 269 /*! 270 A signal emitted whenever the last appended point of the 271 selection has been moved. 272 273 \param pos Position of the moved last point of the selection. 274 \sa move(), appended() 275 */ 276 void moved( const QPoint& pos ); 277 278 /*! 279 A signal emitted whenever the last appended point of the 280 selection has been removed. 281 282 \param pos Position of the point, that has been removed 283 \sa remove(), appended() 284 */ 285 void removed( const QPoint& pos ); 286 /*! 287 A signal emitted when the active selection has been changed. 288 This might happen when the observed widget is resized. 289 290 \param selection Changed selection 291 \sa stretchSelection() 292 */ 293 void changed( const QPolygon& selection ); 294 295 protected: 296 virtual QPolygon adjustedPoints( const QPolygon& ) const; 297 298 virtual void transition( const QEvent* ); 293 299 294 300 virtual void begin(); 295 virtual void append( const QPoint & );296 virtual void move( const QPoint & );301 virtual void append( const QPoint& ); 302 virtual void move( const QPoint& ); 297 303 virtual void remove(); 298 304 virtual bool end( bool ok = true ); 299 305 300 virtual bool accept( QPolygon & ) const;306 virtual bool accept( QPolygon& ) const; 301 307 virtual void reset(); 302 308 303 virtual void widgetMousePressEvent( QMouseEvent * );304 virtual void widgetMouseReleaseEvent( QMouseEvent * );305 virtual void widgetMouseDoubleClickEvent( QMouseEvent * );306 virtual void widgetMouseMoveEvent( QMouseEvent * );307 virtual void widgetWheelEvent( QWheelEvent * );308 virtual void widgetKeyPressEvent( QKeyEvent * );309 virtual void widgetKeyReleaseEvent( QKeyEvent * );310 virtual void widgetEnterEvent( QEvent * );311 virtual void widgetLeaveEvent( QEvent * );309 virtual void widgetMousePressEvent( QMouseEvent* ); 310 virtual void widgetMouseReleaseEvent( QMouseEvent* ); 311 virtual void widgetMouseDoubleClickEvent( QMouseEvent* ); 312 virtual void widgetMouseMoveEvent( QMouseEvent* ); 313 virtual void widgetWheelEvent( QWheelEvent* ); 314 virtual void widgetKeyPressEvent( QKeyEvent* ); 315 virtual void widgetKeyReleaseEvent( QKeyEvent* ); 316 virtual void widgetEnterEvent( QEvent* ); 317 virtual void widgetLeaveEvent( QEvent* ); 312 318 313 319 virtual void stretchSelection( 314 const QSize &oldSize, const QSize&newSize );320 const QSize& oldSize, const QSize& newSize ); 315 321 316 322 virtual void updateDisplay(); 317 323 318 const QwtWidgetOverlay *rubberBandOverlay() const; 319 const QwtWidgetOverlay *trackerOverlay() const; 320 321 const QPolygon &pickedPoints() const; 322 323 private: 324 void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode ); 324 const QwtWidgetOverlay* rubberBandOverlay() const; 325 const QwtWidgetOverlay* trackerOverlay() const; 326 327 const QPolygon& pickedPoints() const; 328 QRect trackerRect( const QSize& ) const; 329 330 private: 331 void init( QWidget*, RubberBand rubberBand, DisplayMode trackerMode ); 325 332 326 333 void setMouseTracking( bool ); 327 334 328 335 class PrivateData; 329 PrivateData *d_data;336 PrivateData* m_data; 330 337 }; 331 338 -
trunk/BNC/qwt/qwt_picker_machine.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_picker_machine.h" 11 11 #include "qwt_event_pattern.h" 12 12 13 #include <qevent.h> 13 14 14 15 //! Constructor 15 QwtPickerMachine::QwtPickerMachine( SelectionType type ) :16 d_selectionType( type ),17 d_state( 0 )16 QwtPickerMachine::QwtPickerMachine( SelectionType type ) 17 : m_selectionType( type ) 18 , m_state( 0 ) 18 19 { 19 20 } … … 27 28 QwtPickerMachine::SelectionType QwtPickerMachine::selectionType() const 28 29 { 29 return d_selectionType;30 return m_selectionType; 30 31 } 31 32 … … 33 34 int QwtPickerMachine::state() const 34 35 { 35 return d_state;36 return m_state; 36 37 } 37 38 … … 39 40 void QwtPickerMachine::setState( int state ) 40 41 { 41 d_state = state;42 m_state = state; 42 43 } 43 44 … … 55 56 56 57 //! Transition 57 QList<QwtPickerMachine::Command> QwtPickerTrackerMachine::transition( 58 const QwtEventPattern &, const QEvent*e )59 { 60 QList<QwtPickerMachine::Command> cmdList; 58 QList< QwtPickerMachine::Command > QwtPickerTrackerMachine::transition( 59 const QwtEventPattern&, const QEvent* e ) 60 { 61 QList< QwtPickerMachine::Command > cmdList; 61 62 62 63 switch ( e->type() ) … … 97 98 98 99 //! Transition 99 QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition( 100 const QwtEventPattern &eventPattern, const QEvent*event )101 { 102 QList<QwtPickerMachine::Command> cmdList; 100 QList< QwtPickerMachine::Command > QwtPickerClickPointMachine::transition( 101 const QwtEventPattern& eventPattern, const QEvent* event ) 102 { 103 QList< QwtPickerMachine::Command > cmdList; 103 104 104 105 switch ( event->type() ) … … 107 108 { 108 109 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 109 static_cast<const QMouseEvent *>( event ) ) )110 static_cast< const QMouseEvent* >( event ) ) ) 110 111 { 111 112 cmdList += Begin; … … 117 118 case QEvent::KeyPress: 118 119 { 119 const QKeyEvent *keyEvent = static_cast<const QKeyEvent*> ( event );120 const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event ); 120 121 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 121 122 { … … 143 144 144 145 //! Transition 145 QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition( 146 const QwtEventPattern &eventPattern, const QEvent*event )147 { 148 QList<QwtPickerMachine::Command> cmdList; 146 QList< QwtPickerMachine::Command > QwtPickerDragPointMachine::transition( 147 const QwtEventPattern& eventPattern, const QEvent* event ) 148 { 149 QList< QwtPickerMachine::Command > cmdList; 149 150 150 151 switch ( event->type() ) … … 153 154 { 154 155 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 155 static_cast<const QMouseEvent *>( event ) ) )156 static_cast< const QMouseEvent* >( event ) ) ) 156 157 { 157 158 if ( state() == 0 ) … … 182 183 case QEvent::KeyPress: 183 184 { 184 const QKeyEvent *keyEvent = static_cast<const QKeyEvent*> ( event );185 const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event ); 185 186 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 186 187 { … … 216 217 217 218 //! Transition 218 QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition( 219 const QwtEventPattern &eventPattern, const QEvent*event )220 { 221 QList<QwtPickerMachine::Command> cmdList; 219 QList< QwtPickerMachine::Command > QwtPickerClickRectMachine::transition( 220 const QwtEventPattern& eventPattern, const QEvent* event ) 221 { 222 QList< QwtPickerMachine::Command > cmdList; 222 223 223 224 switch ( event->type() ) … … 226 227 { 227 228 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 228 static_cast<const QMouseEvent *>( event ) ) )229 static_cast< const QMouseEvent* >( event ) ) ) 229 230 { 230 231 switch ( state() ) … … 261 262 { 262 263 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 263 static_cast<const QMouseEvent *>( event ) ) )264 static_cast< const QMouseEvent* >( event ) ) ) 264 265 { 265 266 if ( state() == 1 ) … … 273 274 case QEvent::KeyPress: 274 275 { 275 const QKeyEvent *keyEvent = static_cast<const QKeyEvent*> ( event );276 const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event ); 276 277 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 277 278 { … … 315 316 316 317 //! Transition 317 QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition( 318 const QwtEventPattern &eventPattern, const QEvent*event )319 { 320 QList<QwtPickerMachine::Command> cmdList; 318 QList< QwtPickerMachine::Command > QwtPickerDragRectMachine::transition( 319 const QwtEventPattern& eventPattern, const QEvent* event ) 320 { 321 QList< QwtPickerMachine::Command > cmdList; 321 322 322 323 switch ( event->type() ) … … 325 326 { 326 327 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 327 static_cast<const QMouseEvent *>( event ) ) )328 static_cast< const QMouseEvent* >( event ) ) ) 328 329 { 329 330 if ( state() == 0 ) … … 356 357 { 357 358 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, 358 static_cast<const QKeyEvent *> ( event ) ) )359 static_cast< const QKeyEvent* > ( event ) ) ) 359 360 { 360 361 if ( state() == 0 ) … … 387 388 388 389 //! Transition 389 QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition( 390 const QwtEventPattern &eventPattern, const QEvent*event )391 { 392 QList<QwtPickerMachine::Command> cmdList; 390 QList< QwtPickerMachine::Command > QwtPickerPolygonMachine::transition( 391 const QwtEventPattern& eventPattern, const QEvent* event ) 392 { 393 QList< QwtPickerMachine::Command > cmdList; 393 394 394 395 switch ( event->type() ) … … 397 398 { 398 399 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 399 static_cast<const QMouseEvent *>( event ) ) )400 static_cast< const QMouseEvent* >( event ) ) ) 400 401 { 401 402 if ( state() == 0 ) … … 412 413 } 413 414 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2, 414 static_cast<const QMouseEvent *>( event ) ) )415 static_cast< const QMouseEvent* >( event ) ) ) 415 416 { 416 417 if ( state() == 1 ) … … 431 432 case QEvent::KeyPress: 432 433 { 433 const QKeyEvent *keyEvent = static_cast<const QKeyEvent*> ( event );434 const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event ); 434 435 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 435 436 { … … 476 477 477 478 //! Transition 478 QList<QwtPickerMachine::Command> QwtPickerDragLineMachine::transition( 479 const QwtEventPattern &eventPattern, const QEvent*event )480 { 481 QList<QwtPickerMachine::Command> cmdList; 479 QList< QwtPickerMachine::Command > QwtPickerDragLineMachine::transition( 480 const QwtEventPattern& eventPattern, const QEvent* event ) 481 { 482 QList< QwtPickerMachine::Command > cmdList; 482 483 483 484 switch( event->type() ) … … 486 487 { 487 488 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 488 static_cast<const QMouseEvent *>( event ) ) )489 static_cast< const QMouseEvent* >( event ) ) ) 489 490 { 490 491 if ( state() == 0 ) … … 501 502 { 502 503 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, 503 static_cast<const QKeyEvent *> ( event ) ) )504 static_cast< const QKeyEvent* > ( event ) ) ) 504 505 { 505 506 if ( state() == 0 ) -
trunk/BNC/qwt/qwt_picker_machine.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PICKER_MACHINE 11 #define QWT_PICKER_MACHINE 111 #define QWT_PICKER_MACHINE 12 12 13 13 #include "qwt_global.h" 14 #include <qlist.h> 15 14 15 class QwtEventPattern; 16 16 class QEvent; 17 class Q wtEventPattern;18 19 /*! 20 \brief A state machine for QwtPicker selections 21 22 QwtPickerMachine accepts key and mouse events and translates them 23 into selection commands. 24 25 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 26 */ 17 template< typename T > class QList; 18 19 /*! 20 \brief A state machine for QwtPicker selections 21 22 QwtPickerMachine accepts key and mouse events and translates them 23 into selection commands. 24 25 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 26 */ 27 27 28 28 class QWT_EXPORT QwtPickerMachine 29 29 { 30 public: 30 public: 31 31 /*! 32 Type of a selection. 33 \sa selectionType() 34 */ 32 Type of a selection. 33 \sa selectionType() 34 */ 35 35 enum SelectionType 36 36 { … … 58 58 }; 59 59 60 QwtPickerMachine( SelectionType ); 60 explicit QwtPickerMachine( SelectionType ); 61 61 virtual ~QwtPickerMachine(); 62 62 63 63 //! Transition 64 virtual QList< Command> transition(65 const QwtEventPattern &, const QEvent* ) = 0;64 virtual QList< Command > transition( 65 const QwtEventPattern&, const QEvent* ) = 0; 66 66 void reset(); 67 67 … … 71 71 SelectionType selectionType() const; 72 72 73 private: 74 const SelectionType d_selectionType;75 int d_state;76 }; 77 78 /*! 79 \brief A state machine for indicating mouse movements 80 81 QwtPickerTrackerMachine supports displaying information 82 corresponding to mouse movements, but is not intended for 83 selecting anything. Begin/End are related to Enter/Leave events. 84 */ 85 class QWT_EXPORT QwtPickerTrackerMachine: public QwtPickerMachine 86 { 87 public: 73 private: 74 const SelectionType m_selectionType; 75 int m_state; 76 }; 77 78 /*! 79 \brief A state machine for indicating mouse movements 80 81 QwtPickerTrackerMachine supports displaying information 82 corresponding to mouse movements, but is not intended for 83 selecting anything. Begin/End are related to Enter/Leave events. 84 */ 85 class QWT_EXPORT QwtPickerTrackerMachine : public QwtPickerMachine 86 { 87 public: 88 88 QwtPickerTrackerMachine(); 89 89 90 virtual QList< Command> transition(91 const QwtEventPattern &, const QEvent* );92 }; 93 94 /*! 95 \brief A state machine for point selections 96 97 Pressing QwtEventPattern::MouseSelect1 or 98 QwtEventPattern::KeySelect1 selects a point. 99 100 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 101 */ 102 class QWT_EXPORT QwtPickerClickPointMachine: public QwtPickerMachine 103 { 104 public: 90 virtual QList< Command > transition( 91 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 92 }; 93 94 /*! 95 \brief A state machine for point selections 96 97 Pressing QwtEventPattern::MouseSelect1 or 98 QwtEventPattern::KeySelect1 selects a point. 99 100 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 101 */ 102 class QWT_EXPORT QwtPickerClickPointMachine : public QwtPickerMachine 103 { 104 public: 105 105 QwtPickerClickPointMachine(); 106 106 107 virtual QList< Command> transition(108 const QwtEventPattern &, const QEvent* );109 }; 110 111 /*! 112 \brief A state machine for point selections 113 114 Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 115 starts the selection, releasing QwtEventPattern::MouseSelect1 or 116 a second press of QwtEventPattern::KeySelect1 terminates it. 117 */ 118 class QWT_EXPORT QwtPickerDragPointMachine: public QwtPickerMachine 119 { 120 public: 107 virtual QList< Command > transition( 108 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 109 }; 110 111 /*! 112 \brief A state machine for point selections 113 114 Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 115 starts the selection, releasing QwtEventPattern::MouseSelect1 or 116 a second press of QwtEventPattern::KeySelect1 terminates it. 117 */ 118 class QWT_EXPORT QwtPickerDragPointMachine : public QwtPickerMachine 119 { 120 public: 121 121 QwtPickerDragPointMachine(); 122 122 123 virtual QList< Command> transition(124 const QwtEventPattern &, const QEvent* );125 }; 126 127 /*! 128 \brief A state machine for rectangle selections 129 130 Pressing QwtEventPattern::MouseSelect1 starts 131 the selection, releasing it selects the first point. Pressing it 132 again selects the second point and terminates the selection. 133 Pressing QwtEventPattern::KeySelect1 also starts the 134 selection, a second press selects the first point. A third one selects 135 the second point and terminates the selection. 136 137 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 138 */ 139 140 class QWT_EXPORT QwtPickerClickRectMachine: public QwtPickerMachine 141 { 142 public: 123 virtual QList< Command > transition( 124 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 125 }; 126 127 /*! 128 \brief A state machine for rectangle selections 129 130 Pressing QwtEventPattern::MouseSelect1 starts 131 the selection, releasing it selects the first point. Pressing it 132 again selects the second point and terminates the selection. 133 Pressing QwtEventPattern::KeySelect1 also starts the 134 selection, a second press selects the first point. A third one selects 135 the second point and terminates the selection. 136 137 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 138 */ 139 140 class QWT_EXPORT QwtPickerClickRectMachine : public QwtPickerMachine 141 { 142 public: 143 143 QwtPickerClickRectMachine(); 144 144 145 virtual QList< Command> transition(146 const QwtEventPattern &, const QEvent* );147 }; 148 149 /*! 150 \brief A state machine for rectangle selections 151 152 Pressing QwtEventPattern::MouseSelect1 selects 153 the first point, releasing it the second point. 154 Pressing QwtEventPattern::KeySelect1 also selects the 155 first point, a second press selects the second point and terminates 156 the selection. 157 158 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 159 */ 160 161 class QWT_EXPORT QwtPickerDragRectMachine: public QwtPickerMachine 162 { 163 public: 145 virtual QList< Command > transition( 146 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 147 }; 148 149 /*! 150 \brief A state machine for rectangle selections 151 152 Pressing QwtEventPattern::MouseSelect1 selects 153 the first point, releasing it the second point. 154 Pressing QwtEventPattern::KeySelect1 also selects the 155 first point, a second press selects the second point and terminates 156 the selection. 157 158 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 159 */ 160 161 class QWT_EXPORT QwtPickerDragRectMachine : public QwtPickerMachine 162 { 163 public: 164 164 QwtPickerDragRectMachine(); 165 165 166 virtual QList< Command> transition(167 const QwtEventPattern &, const QEvent* );168 }; 169 170 /*! 171 \brief A state machine for line selections 172 173 Pressing QwtEventPattern::MouseSelect1 selects 174 the first point, releasing it the second point. 175 Pressing QwtEventPattern::KeySelect1 also selects the 176 first point, a second press selects the second point and terminates 177 the selection. 178 179 A common use case of QwtPickerDragLineMachine are pickers for 180 distance measurements. 181 182 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 183 */ 184 185 class QWT_EXPORT QwtPickerDragLineMachine: public QwtPickerMachine 186 { 187 public: 166 virtual QList< Command > transition( 167 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 168 }; 169 170 /*! 171 \brief A state machine for line selections 172 173 Pressing QwtEventPattern::MouseSelect1 selects 174 the first point, releasing it the second point. 175 Pressing QwtEventPattern::KeySelect1 also selects the 176 first point, a second press selects the second point and terminates 177 the selection. 178 179 A common use case of QwtPickerDragLineMachine are pickers for 180 distance measurements. 181 182 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 183 */ 184 185 class QWT_EXPORT QwtPickerDragLineMachine : public QwtPickerMachine 186 { 187 public: 188 188 QwtPickerDragLineMachine(); 189 189 190 virtual QList< Command> transition(191 const QwtEventPattern &, const QEvent* );192 }; 193 194 /*! 195 \brief A state machine for polygon selections 196 197 Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 198 starts the selection and selects the first point, or appends a point. 199 Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2 200 appends the last point and terminates the selection. 201 202 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 203 */ 204 205 class QWT_EXPORT QwtPickerPolygonMachine: public QwtPickerMachine 206 { 207 public: 190 virtual QList< Command > transition( 191 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 192 }; 193 194 /*! 195 \brief A state machine for polygon selections 196 197 Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 198 starts the selection and selects the first point, or appends a point. 199 Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2 200 appends the last point and terminates the selection. 201 202 \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode 203 */ 204 205 class QWT_EXPORT QwtPickerPolygonMachine : public QwtPickerMachine 206 { 207 public: 208 208 QwtPickerPolygonMachine(); 209 209 210 virtual QList< Command> transition(211 const QwtEventPattern &, const QEvent* );210 virtual QList< Command > transition( 211 const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE; 212 212 }; 213 213 -
trunk/BNC/qwt/qwt_pixel_matrix.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 12 12 /*! 13 \brief Constructor 13 \brief Constructor 14 14 15 \param rect Bounding rectangle for the matrix 16 */ 17 QwtPixelMatrix::QwtPixelMatrix( const QRect& rect ) :18 QBitArray( qMax( rect.width() * rect.height(), 0 ) ) ,19 d_rect( rect )15 \param rect Bounding rectangle for the matrix 16 */ 17 QwtPixelMatrix::QwtPixelMatrix( const QRect& rect ) 18 : QBitArray( qMax( rect.width() * rect.height(), 0 ) ) 19 , m_rect( rect ) 20 20 { 21 21 } … … 35 35 void QwtPixelMatrix::setRect( const QRect& rect ) 36 36 { 37 if ( rect != d_rect )37 if ( rect != m_rect ) 38 38 { 39 d_rect = rect;39 m_rect = rect; 40 40 const int sz = qMax( rect.width() * rect.height(), 0 ); 41 41 resize( sz ); … … 48 48 QRect QwtPixelMatrix::rect() const 49 49 { 50 return d_rect;50 return m_rect; 51 51 } -
trunk/BNC/qwt/qwt_pixel_matrix.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 14 15 #include <qbitarray.h> 15 16 #include <qrect.h> 16 17 17 18 /*! 18 \brief A bit field corresponding to the pixels of a rectangle 19 \brief A bit field corresponding to the pixels of a rectangle 19 20 20 QwtPixelMatrix is intended to filter out duplicates in an 21 unsorted array of points. 22 */ 23 class QWT_EXPORT QwtPixelMatrix: public QBitArray 21 QwtPixelMatrix is intended to filter out duplicates in an 22 unsorted array of points. 23 */ 24 class QWT_EXPORT QwtPixelMatrix : public QBitArray 24 25 { 25 public: 26 QwtPixelMatrix( const QRect& rect ); 26 public: 27 explicit QwtPixelMatrix( const QRect& rect ); 27 28 ~QwtPixelMatrix(); 28 29 … … 35 36 int index( int x, int y ) const; 36 37 37 private: 38 QRect d_rect;38 private: 39 QRect m_rect; 39 40 }; 40 41 41 42 /*! 42 \brief Test if a pixel has been set 43 \brief Test if a pixel has been set 43 44 44 \param x X-coordinate 45 \param y Y-coordinate 45 \param x X-coordinate 46 \param y Y-coordinate 46 47 47 \return true, when pos is outside of rect(), or when the pixel 48 \return true, when pos is outside of rect(), or when the pixel 48 49 has already been set. 49 50 */ … … 55 56 56 57 /*! 57 \brief Set a pixel and test if a pixel has been set before 58 \brief Set a pixel and test if a pixel has been set before 58 59 59 \param x X-coordinate 60 \param y Y-coordinate 61 \param on Set/Clear the pixel 60 \param x X-coordinate 61 \param y Y-coordinate 62 \param on Set/Clear the pixel 62 63 63 \return true, when pos is outside of rect(), or when the pixel 64 \return true, when pos is outside of rect(), or when the pixel 64 65 was set before. 65 66 */ … … 77 78 78 79 /*! 79 \brief Calculate the index in the bit field corresponding to a position 80 \brief Calculate the index in the bit field corresponding to a position 80 81 81 \param x X-coordinate 82 \param y Y-coordinate 83 \return Index, when rect() contains pos - otherwise -1. 82 \param x X-coordinate 83 \param y Y-coordinate 84 \return Index, when rect() contains pos - otherwise -1. 84 85 */ 85 86 inline int QwtPixelMatrix::index( int x, int y ) const 86 87 { 87 const int dx = x - d_rect.x();88 if ( dx < 0 || dx >= d_rect.width() )88 const int dx = x - m_rect.x(); 89 if ( dx < 0 || dx >= m_rect.width() ) 89 90 return -1; 90 91 91 const int dy = y - d_rect.y();92 if ( dy < 0 || dy >= d_rect.height() )92 const int dy = y - m_rect.y(); 93 if ( dy < 0 || dy >= m_rect.height() ) 93 94 return -1; 94 95 95 return dy * d_rect.width() + dx;96 return dy * m_rect.width() + dx; 96 97 } 97 98 -
trunk/BNC/qwt/qwt_plot.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_scale_widget.h" 14 14 #include "qwt_scale_engine.h" 15 #include "qwt_scale_map.h" 15 16 #include "qwt_text_label.h" 16 17 #include "qwt_legend.h" 17 18 #include "qwt_legend_data.h" 18 19 #include "qwt_plot_canvas.h" 19 #include <qmath.h> 20 #include "qwt_math.h" 21 20 22 #include <qpainter.h> 21 23 #include <qpointer.h> 22 #include <qpaintengine.h>23 24 #include <qapplication.h> 24 #include <qevent.h> 25 26 static inline void qwtEnableLegendItems( QwtPlot *plot, bool on ) 27 { 25 #include <qcoreevent.h> 26 27 static inline void qwtEnableLegendItems( QwtPlot* plot, bool on ) 28 { 29 // gcc seems to have problems with const char sig[] in combination with certain options 30 const char* sig = SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)); 31 const char* slot = SLOT(updateLegendItems(QVariant,QList<QwtLegendData>)); 32 28 33 if ( on ) 29 { 30 QObject::connect( 31 plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)), 32 plot, SLOT(updateLegendItems(QVariant,QList<QwtLegendData>)) 33 ); 34 } 34 QObject::connect( plot, sig, plot, slot ); 35 35 else 36 { 37 QObject::disconnect( 38 plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>) ), 39 plot, SLOT( updateLegendItems(QVariant,QList<QwtLegendData>)) 40 ); 41 } 36 QObject::disconnect( plot, sig, plot, slot ); 42 37 } 43 38 44 39 static void qwtSetTabOrder( 45 QWidget *first, QWidget*second, bool withChildren )46 { 47 QList<QWidget *> tabChain;40 QWidget* first, QWidget* second, bool withChildren ) 41 { 42 QList< QWidget* > tabChain; 48 43 tabChain += first; 49 44 tabChain += second; … … 51 46 if ( withChildren ) 52 47 { 53 QList<QWidget *> children = second->findChildren<QWidget*>();54 55 QWidget *w = second->nextInFocusChain();48 QList< QWidget* > children = second->findChildren< QWidget* >(); 49 50 QWidget* w = second->nextInFocusChain(); 56 51 while ( children.contains( w ) ) 57 52 { … … 65 60 for ( int i = 0; i < tabChain.size() - 1; i++ ) 66 61 { 67 QWidget *from = tabChain[i];68 QWidget *to = tabChain[i+1];62 QWidget* from = tabChain[i]; 63 QWidget* to = tabChain[i + 1]; 69 64 70 65 const Qt::FocusPolicy policy1 = from->focusPolicy(); 71 66 const Qt::FocusPolicy policy2 = to->focusPolicy(); 72 67 73 QWidget *proxy1 = from->focusProxy();74 QWidget *proxy2 = to->focusProxy();68 QWidget* proxy1 = from->focusProxy(); 69 QWidget* proxy2 = to->focusProxy(); 75 70 76 71 from->setFocusPolicy( Qt::TabFocus ); … … 92 87 class QwtPlot::PrivateData 93 88 { 94 public: 95 QPointer<QwtTextLabel> titleLabel; 96 QPointer<QwtTextLabel> footerLabel; 97 QPointer< QWidget> canvas;98 QPointer<QwtAbstractLegend> legend; 99 QwtPlotLayout *layout;89 public: 90 QPointer< QwtTextLabel > titleLabel; 91 QPointer< QwtTextLabel > footerLabel; 92 QPointer< QWidget > canvas; 93 QPointer< QwtAbstractLegend > legend; 94 QwtPlotLayout* layout; 100 95 101 96 bool autoReplot; … … 103 98 104 99 /*! 105 \brief Constructor 106 \param parent Parent widget 107 */ 108 QwtPlot::QwtPlot( QWidget *parent ):109 QFrame( parent ) 100 \brief Constructor 101 \param parent Parent widget 102 */ 103 QwtPlot::QwtPlot( QWidget* parent ) 104 : QFrame( parent ) 110 105 { 111 106 initPlot( QwtText() ); … … 113 108 114 109 /*! 115 \brief Constructor 116 \param title Title text 117 \param parent Parent widget 118 */ 119 QwtPlot::QwtPlot( const QwtText &title, QWidget*parent ):120 QFrame( parent ) 110 \brief Constructor 111 \param title Title text 112 \param parent Parent widget 113 */ 114 QwtPlot::QwtPlot( const QwtText& title, QWidget* parent ) 115 : QFrame( parent ) 121 116 { 122 117 initPlot( title ); … … 129 124 detachItems( QwtPlotItem::Rtti_PlotItem, autoDelete() ); 130 125 131 delete d_data->layout;126 delete m_data->layout; 132 127 deleteAxesData(); 133 delete d_data;134 } 135 136 /*! 137 \brief Initializes a QwtPlot instance 138 \param title Title text 139 */ 140 void QwtPlot::initPlot( const QwtText &title )141 { 142 d_data = new PrivateData;143 144 d_data->layout = new QwtPlotLayout;145 d_data->autoReplot = false;128 delete m_data; 129 } 130 131 /*! 132 \brief Initializes a QwtPlot instance 133 \param title Title text 134 */ 135 void QwtPlot::initPlot( const QwtText& title ) 136 { 137 m_data = new PrivateData; 138 139 m_data->layout = new QwtPlotLayout; 140 m_data->autoReplot = false; 146 141 147 142 // title 148 d_data->titleLabel = new QwtTextLabel( this );149 d_data->titleLabel->setObjectName( "QwtPlotTitle" );150 d_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );143 m_data->titleLabel = new QwtTextLabel( this ); 144 m_data->titleLabel->setObjectName( "QwtPlotTitle" ); 145 m_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) ); 151 146 152 147 QwtText text( title ); 153 148 text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); 154 d_data->titleLabel->setText( text );149 m_data->titleLabel->setText( text ); 155 150 156 151 // footer 157 d_data->footerLabel = new QwtTextLabel( this );158 d_data->footerLabel->setObjectName( "QwtPlotFooter" );152 m_data->footerLabel = new QwtTextLabel( this ); 153 m_data->footerLabel->setObjectName( "QwtPlotFooter" ); 159 154 160 155 QwtText footer; 161 156 footer.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); 162 d_data->footerLabel->setText( footer );157 m_data->footerLabel->setText( footer ); 163 158 164 159 // legend 165 d_data->legend = NULL;166 167 // ax is160 m_data->legend = NULL; 161 162 // axes 168 163 initAxesData(); 169 164 170 165 // canvas 171 d_data->canvas = new QwtPlotCanvas( this );172 d_data->canvas->setObjectName( "QwtPlotCanvas" );173 d_data->canvas->installEventFilter( this );166 m_data->canvas = new QwtPlotCanvas( this ); 167 m_data->canvas->setObjectName( "QwtPlotCanvas" ); 168 m_data->canvas->installEventFilter( this ); 174 169 175 170 setSizePolicy( QSizePolicy::MinimumExpanding, … … 178 173 resize( 200, 200 ); 179 174 180 QList<QWidget *> focusChain; 181 focusChain << this << d_data->titleLabel << axisWidget( xTop ) 182 << axisWidget( yLeft ) << d_data->canvas << axisWidget( yRight ) 183 << axisWidget( xBottom ) << d_data->footerLabel; 175 using namespace QwtAxis; 176 177 QList< QWidget* > focusChain; 178 focusChain << this << m_data->titleLabel << axisWidget( XTop ) 179 << axisWidget( YLeft ) << m_data->canvas 180 << axisWidget( YRight ) << axisWidget( XBottom ) 181 << m_data->footerLabel; 184 182 185 183 for ( int i = 0; i < focusChain.size() - 1; i++ ) 186 qwtSetTabOrder( focusChain[i], focusChain[i +1], false );184 qwtSetTabOrder( focusChain[i], focusChain[i + 1], false ); 187 185 188 186 qwtEnableLegendItems( this, true ); … … 190 188 191 189 /*! 192 \brief Set the drawing canvas of the plot widget 193 194 QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ). 195 In opposite to using conventional C++ techniques like virtual methods 196 they allow to use canvas implementations that are derived from 197 QWidget or QGLWidget. 198 199 The following meta methods could be implemented: 200 201 - replot() 190 \brief Set the drawing canvas of the plot widget 191 192 QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ). 193 In opposite to using conventional C++ techniques like virtual methods 194 they allow to use canvas implementations that are derived from 195 QWidget or QGLWidget. 196 197 The following meta methods could be implemented: 198 199 - replot() 202 200 When the canvas doesn't offer a replot method, QwtPlot calls 203 201 update() instead. 204 202 205 - borderPath() 203 - borderPath() 206 204 The border path is necessary to clip the content of the canvas 207 205 When the canvas doesn't have any special border ( f.e rounded corners ) 208 206 it is o.k. not to implement this method. 209 207 210 The default canvas is a QwtPlotCanvas 211 212 \param canvas Canvas Widget 213 \sa canvas() 214 */ 215 void QwtPlot::setCanvas( QWidget *canvas )216 { 217 if ( canvas == d_data->canvas )208 The default canvas is a QwtPlotCanvas 209 210 \param canvas Canvas Widget 211 \sa canvas() 212 */ 213 void QwtPlot::setCanvas( QWidget* canvas ) 214 { 215 if ( canvas == m_data->canvas ) 218 216 return; 219 217 220 delete d_data->canvas;221 d_data->canvas = canvas;218 delete m_data->canvas; 219 m_data->canvas = canvas; 222 220 223 221 if ( canvas ) … … 232 230 233 231 /*! 234 \brief Adds handling of layout requests 235 \param event Event 236 237 \return See QFrame::event() 238 */ 239 bool QwtPlot::event( QEvent *event )232 \brief Adds handling of layout requests 233 \param event Event 234 235 \return See QFrame::event() 236 */ 237 bool QwtPlot::event( QEvent* event ) 240 238 { 241 239 bool ok = QFrame::event( event ); … … 254 252 255 253 /*! 256 \brief Event filter 257 258 The plot handles the following events for the canvas: 259 260 - QEvent::Resize 254 \brief Event filter 255 256 The plot handles the following events for the canvas: 257 258 - QEvent::Resize 261 259 The canvas margins might depend on its size 262 260 263 - QEvent::ContentsRectChange 261 - QEvent::ContentsRectChange 264 262 The layout needs to be recalculated 265 263 266 \param object Object to be filtered 267 \param event Event 268 269 \return See QFrame::eventFilter() 270 271 \sa updateCanvasMargins(), updateLayout() 272 */ 273 bool QwtPlot::eventFilter( QObject *object, QEvent*event )274 { 275 if ( object == d_data->canvas )264 \param object Object to be filtered 265 \param event Event 266 267 \return See QFrame::eventFilter() 268 269 \sa updateCanvasMargins(), updateLayout() 270 */ 271 bool QwtPlot::eventFilter( QObject* object, QEvent* event ) 272 { 273 if ( object == m_data->canvas ) 276 274 { 277 275 if ( event->type() == QEvent::Resize ) … … 291 289 void QwtPlot::autoRefresh() 292 290 { 293 if ( d_data->autoReplot )291 if ( m_data->autoReplot ) 294 292 replot(); 295 293 } 296 294 297 295 /*! 298 \brief Set or reset the autoReplot option 299 300 If the autoReplot option is set, the plot will be 301 updated implicitly by manipulating member functions. 302 Since this may be time-consuming, it is recommended 303 to leave this option switched off and call replot() 304 explicitly if necessary. 305 306 The autoReplot option is set to false by default, which 307 means that the user has to call replot() in order to make 308 changes visible. 309 \param tf \c true or \c false. Defaults to \c true. 310 \sa replot() 311 */ 296 \brief Set or reset the autoReplot option 297 298 If the autoReplot option is set, the plot will be 299 updated implicitly by manipulating member functions. 300 Since this may be time-consuming, it is recommended 301 to leave this option switched off and call replot() 302 explicitly if necessary. 303 304 The autoReplot option is set to false by default, which 305 means that the user has to call replot() in order to make 306 changes visible. 307 \param tf \c true or \c false. Defaults to \c true. 308 \sa replot() 309 */ 312 310 void QwtPlot::setAutoReplot( bool tf ) 313 311 { 314 d_data->autoReplot = tf;315 } 316 317 /*! 318 \return true if the autoReplot option is set. 319 \sa setAutoReplot() 320 */ 312 m_data->autoReplot = tf; 313 } 314 315 /*! 316 \return true if the autoReplot option is set. 317 \sa setAutoReplot() 318 */ 321 319 bool QwtPlot::autoReplot() const 322 320 { 323 return d_data->autoReplot;324 } 325 326 /*! 327 Change the plot's title 328 \param title New title 329 */ 330 void QwtPlot::setTitle( const QString &title )331 { 332 if ( title != d_data->titleLabel->text().text() )333 { 334 d_data->titleLabel->setText( title );321 return m_data->autoReplot; 322 } 323 324 /*! 325 Change the plot's title 326 \param title New title 327 */ 328 void QwtPlot::setTitle( const QString& title ) 329 { 330 if ( title != m_data->titleLabel->text().text() ) 331 { 332 m_data->titleLabel->setText( title ); 335 333 updateLayout(); 336 334 } … … 338 336 339 337 /*! 340 Change the plot's title 341 \param title New title 342 */ 343 void QwtPlot::setTitle( const QwtText &title )344 { 345 if ( title != d_data->titleLabel->text() )346 { 347 d_data->titleLabel->setText( title );338 Change the plot's title 339 \param title New title 340 */ 341 void QwtPlot::setTitle( const QwtText& title ) 342 { 343 if ( title != m_data->titleLabel->text() ) 344 { 345 m_data->titleLabel->setText( title ); 348 346 updateLayout(); 349 347 } … … 353 351 QwtText QwtPlot::title() const 354 352 { 355 return d_data->titleLabel->text();353 return m_data->titleLabel->text(); 356 354 } 357 355 358 356 //! \return Title label widget. 359 QwtTextLabel *QwtPlot::titleLabel()360 { 361 return d_data->titleLabel;357 QwtTextLabel* QwtPlot::titleLabel() 358 { 359 return m_data->titleLabel; 362 360 } 363 361 364 362 //! \return Title label widget. 365 const QwtTextLabel *QwtPlot::titleLabel() const366 { 367 return d_data->titleLabel;368 } 369 370 /*! 371 Change the text the footer 372 \param text New text of the footer 373 */ 374 void QwtPlot::setFooter( const QString &text )375 { 376 if ( text != d_data->footerLabel->text().text() )377 { 378 d_data->footerLabel->setText( text );363 const QwtTextLabel* QwtPlot::titleLabel() const 364 { 365 return m_data->titleLabel; 366 } 367 368 /*! 369 Change the text the footer 370 \param text New text of the footer 371 */ 372 void QwtPlot::setFooter( const QString& text ) 373 { 374 if ( text != m_data->footerLabel->text().text() ) 375 { 376 m_data->footerLabel->setText( text ); 379 377 updateLayout(); 380 378 } … … 382 380 383 381 /*! 384 Change the text the footer 385 \param text New text of the footer 386 */ 387 void QwtPlot::setFooter( const QwtText &text )388 { 389 if ( text != d_data->footerLabel->text() )390 { 391 d_data->footerLabel->setText( text );382 Change the text the footer 383 \param text New text of the footer 384 */ 385 void QwtPlot::setFooter( const QwtText& text ) 386 { 387 if ( text != m_data->footerLabel->text() ) 388 { 389 m_data->footerLabel->setText( text ); 392 390 updateLayout(); 393 391 } … … 397 395 QwtText QwtPlot::footer() const 398 396 { 399 return d_data->footerLabel->text();397 return m_data->footerLabel->text(); 400 398 } 401 399 402 400 //! \return Footer label widget. 403 QwtTextLabel *QwtPlot::footerLabel()404 { 405 return d_data->footerLabel;401 QwtTextLabel* QwtPlot::footerLabel() 402 { 403 return m_data->footerLabel; 406 404 } 407 405 408 406 //! \return Footer label widget. 409 const QwtTextLabel *QwtPlot::footerLabel() const410 { 411 return d_data->footerLabel;407 const QwtTextLabel* QwtPlot::footerLabel() const 408 { 409 return m_data->footerLabel; 412 410 } 413 411 … … 418 416 \sa plotLayout() 419 417 */ 420 void QwtPlot::setPlotLayout( QwtPlotLayout *layout )421 { 422 if ( layout != d_data->layout )423 { 424 delete d_data->layout;425 d_data->layout = layout;418 void QwtPlot::setPlotLayout( QwtPlotLayout* layout ) 419 { 420 if ( layout != m_data->layout ) 421 { 422 delete m_data->layout; 423 m_data->layout = layout; 426 424 427 425 updateLayout(); … … 430 428 431 429 //! \return the plot's layout 432 QwtPlotLayout *QwtPlot::plotLayout()433 { 434 return d_data->layout;430 QwtPlotLayout* QwtPlot::plotLayout() 431 { 432 return m_data->layout; 435 433 } 436 434 437 435 //! \return the plot's layout 438 const QwtPlotLayout *QwtPlot::plotLayout() const439 { 440 return d_data->layout;441 } 442 443 /*! 444 \return the plot's legend 445 \sa insertLegend() 446 */ 447 QwtAbstractLegend *QwtPlot::legend()448 { 449 return d_data->legend;450 } 451 452 /*! 453 \return the plot's legend 454 \sa insertLegend() 455 */ 456 const QwtAbstractLegend *QwtPlot::legend() const457 { 458 return d_data->legend;459 } 460 461 462 /*! 463 \return the plot's canvas 464 */ 465 QWidget *QwtPlot::canvas()466 { 467 return d_data->canvas;468 } 469 470 /*! 471 \return the plot's canvas 472 */ 473 const QWidget *QwtPlot::canvas() const474 { 475 return d_data->canvas;476 } 477 478 /*! 479 \return Size hint for the plot widget 480 \sa minimumSizeHint() 481 */ 436 const QwtPlotLayout* QwtPlot::plotLayout() const 437 { 438 return m_data->layout; 439 } 440 441 /*! 442 \return the plot's legend 443 \sa insertLegend() 444 */ 445 QwtAbstractLegend* QwtPlot::legend() 446 { 447 return m_data->legend; 448 } 449 450 /*! 451 \return the plot's legend 452 \sa insertLegend() 453 */ 454 const QwtAbstractLegend* QwtPlot::legend() const 455 { 456 return m_data->legend; 457 } 458 459 460 /*! 461 \return the plot's canvas 462 */ 463 QWidget* QwtPlot::canvas() 464 { 465 return m_data->canvas; 466 } 467 468 /*! 469 \return the plot's canvas 470 */ 471 const QWidget* QwtPlot::canvas() const 472 { 473 return m_data->canvas; 474 } 475 476 /*! 477 \return Size hint for the plot widget 478 \sa minimumSizeHint() 479 */ 482 480 QSize QwtPlot::sizeHint() const 483 481 { 484 482 int dw = 0; 485 483 int dh = 0; 486 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 487 { 488 if ( axisEnabled( axisId ) ) 489 { 490 const int niceDist = 40; 491 const QwtScaleWidget *scaleWidget = axisWidget( axisId ); 492 const QwtScaleDiv &scaleDiv = scaleWidget->scaleDraw()->scaleDiv(); 493 const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count(); 494 495 if ( axisId == yLeft || axisId == yRight ) 484 485 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 486 { 487 { 488 const QwtAxisId axisId( axisPos ); 489 490 if ( isAxisVisible( axisId ) ) 496 491 { 497 int hDiff = ( majCnt - 1 ) * niceDist 498 - scaleWidget->minimumSizeHint().height(); 499 if ( hDiff > dh ) 500 dh = hDiff; 492 const int niceDist = 40; 493 const QwtScaleWidget* scaleWidget = axisWidget( axisId ); 494 const QwtScaleDiv& scaleDiv = scaleWidget->scaleDraw()->scaleDiv(); 495 const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count(); 496 497 const QSize hint = scaleWidget->minimumSizeHint(); 498 499 if ( QwtAxis::isYAxis( axisPos ) ) 500 { 501 const int hDiff = ( majCnt - 1 ) * niceDist - hint.height(); 502 dh = qMax( dh, hDiff ); 503 } 504 else 505 { 506 const int wDiff = ( majCnt - 1 ) * niceDist - hint.width(); 507 dw = qMax( dw, wDiff ); 508 } 509 } 510 } 511 } 512 return minimumSizeHint() + QSize( dw, dh ); 513 } 514 515 /*! 516 \brief Return a minimum size hint 517 */ 518 QSize QwtPlot::minimumSizeHint() const 519 { 520 QSize hint = m_data->layout->minimumSizeHint( this ); 521 hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); 522 523 return hint; 524 } 525 526 /*! 527 Resize and update internal layout 528 \param e Resize event 529 */ 530 void QwtPlot::resizeEvent( QResizeEvent* e ) 531 { 532 QFrame::resizeEvent( e ); 533 updateLayout(); 534 } 535 536 /*! 537 \brief Redraw the plot 538 539 If the autoReplot option is not set (which is the default) 540 or if any curves are attached to raw data, the plot has to 541 be refreshed explicitly in order to make changes visible. 542 543 \sa updateAxes(), setAutoReplot() 544 */ 545 void QwtPlot::replot() 546 { 547 bool doAutoReplot = autoReplot(); 548 setAutoReplot( false ); 549 550 updateAxes(); 551 552 /* 553 Maybe the layout needs to be updated, because of changed 554 axes labels. We need to process them here before painting 555 to avoid that scales and canvas get out of sync. 556 */ 557 QApplication::sendPostedEvents( this, QEvent::LayoutRequest ); 558 559 if ( m_data->canvas ) 560 { 561 const bool ok = QMetaObject::invokeMethod( 562 m_data->canvas, "replot", Qt::DirectConnection ); 563 if ( !ok ) 564 { 565 // fallback, when canvas has no a replot method 566 m_data->canvas->update( m_data->canvas->contentsRect() ); 567 } 568 } 569 570 setAutoReplot( doAutoReplot ); 571 } 572 573 /*! 574 \brief Adjust plot content to its current size. 575 \sa resizeEvent() 576 */ 577 void QwtPlot::updateLayout() 578 { 579 QwtPlotLayout* layout = m_data->layout; 580 layout->activate( this, contentsRect() ); 581 582 const QRect titleRect = layout->titleRect().toRect(); 583 const QRect footerRect = layout->footerRect().toRect(); 584 const QRect legendRect = layout->legendRect().toRect(); 585 const QRect canvasRect = layout->canvasRect().toRect(); 586 587 // resize and show the visible widgets 588 589 if ( !m_data->titleLabel->text().isEmpty() ) 590 { 591 m_data->titleLabel->setGeometry( titleRect ); 592 if ( !m_data->titleLabel->isVisibleTo( this ) ) 593 m_data->titleLabel->show(); 594 } 595 else 596 m_data->titleLabel->hide(); 597 598 if ( !m_data->footerLabel->text().isEmpty() ) 599 { 600 m_data->footerLabel->setGeometry( footerRect ); 601 if ( !m_data->footerLabel->isVisibleTo( this ) ) 602 m_data->footerLabel->show(); 603 } 604 else 605 { 606 m_data->footerLabel->hide(); 607 } 608 609 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 610 { 611 { 612 const QwtAxisId axisId( axisPos ); 613 614 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 615 616 if ( isAxisVisible( axisId ) ) 617 { 618 const QRect scaleRect = layout->scaleRect( axisId ).toRect(); 619 620 if ( scaleRect != scaleWidget->geometry() ) 621 { 622 scaleWidget->setGeometry( scaleRect ); 623 624 int startDist, endDist; 625 scaleWidget->getBorderDistHint( startDist, endDist ); 626 scaleWidget->setBorderDist( startDist, endDist ); 627 } 628 629 if ( !scaleWidget->isVisibleTo( this ) ) 630 scaleWidget->show(); 501 631 } 502 632 else 503 633 { 504 int wDiff = ( majCnt - 1 ) * niceDist 505 - scaleWidget->minimumSizeHint().width(); 506 if ( wDiff > dw ) 507 dw = wDiff; 634 scaleWidget->hide(); 508 635 } 509 636 } 510 637 } 511 return minimumSizeHint() + QSize( dw, dh ); 512 } 513 514 /*! 515 \brief Return a minimum size hint 516 */ 517 QSize QwtPlot::minimumSizeHint() const 518 { 519 QSize hint = d_data->layout->minimumSizeHint( this ); 520 hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); 521 522 return hint; 523 } 524 525 /*! 526 Resize and update internal layout 527 \param e Resize event 528 */ 529 void QwtPlot::resizeEvent( QResizeEvent *e ) 530 { 531 QFrame::resizeEvent( e ); 532 updateLayout(); 533 } 534 535 /*! 536 \brief Redraw the plot 537 538 If the autoReplot option is not set (which is the default) 539 or if any curves are attached to raw data, the plot has to 540 be refreshed explicitly in order to make changes visible. 541 542 \sa updateAxes(), setAutoReplot() 543 */ 544 void QwtPlot::replot() 545 { 546 bool doAutoReplot = autoReplot(); 547 setAutoReplot( false ); 548 549 updateAxes(); 550 551 /* 552 Maybe the layout needs to be updated, because of changed 553 axes labels. We need to process them here before painting 554 to avoid that scales and canvas get out of sync. 555 */ 556 QApplication::sendPostedEvents( this, QEvent::LayoutRequest ); 557 558 if ( d_data->canvas ) 559 { 560 const bool ok = QMetaObject::invokeMethod( 561 d_data->canvas, "replot", Qt::DirectConnection ); 562 if ( !ok ) 563 { 564 // fallback, when canvas has no a replot method 565 d_data->canvas->update( d_data->canvas->contentsRect() ); 566 } 567 } 568 569 setAutoReplot( doAutoReplot ); 570 } 571 572 /*! 573 \brief Adjust plot content to its current size. 574 \sa resizeEvent() 575 */ 576 void QwtPlot::updateLayout() 577 { 578 d_data->layout->activate( this, contentsRect() ); 579 580 QRect titleRect = d_data->layout->titleRect().toRect(); 581 QRect footerRect = d_data->layout->footerRect().toRect(); 582 QRect scaleRect[QwtPlot::axisCnt]; 583 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 584 scaleRect[axisId] = d_data->layout->scaleRect( axisId ).toRect(); 585 QRect legendRect = d_data->layout->legendRect().toRect(); 586 QRect canvasRect = d_data->layout->canvasRect().toRect(); 587 588 // resize and show the visible widgets 589 590 if ( !d_data->titleLabel->text().isEmpty() ) 591 { 592 d_data->titleLabel->setGeometry( titleRect ); 593 if ( !d_data->titleLabel->isVisibleTo( this ) ) 594 d_data->titleLabel->show(); 595 } 596 else 597 d_data->titleLabel->hide(); 598 599 if ( !d_data->footerLabel->text().isEmpty() ) 600 { 601 d_data->footerLabel->setGeometry( footerRect ); 602 if ( !d_data->footerLabel->isVisibleTo( this ) ) 603 d_data->footerLabel->show(); 604 } 605 else 606 { 607 d_data->footerLabel->hide(); 608 } 609 610 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 611 { 612 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 613 614 if ( axisEnabled( axisId ) ) 615 { 616 if ( scaleRect[axisId] != scaleWidget->geometry() ) 617 { 618 scaleWidget->setGeometry( scaleRect[axisId] ); 619 620 int startDist, endDist; 621 scaleWidget->getBorderDistHint( startDist, endDist ); 622 scaleWidget->setBorderDist( startDist, endDist ); 623 } 624 625 #if 1 626 if ( axisId == xBottom || axisId == xTop ) 627 { 628 // do we need this code any longer ??? 629 630 QRegion r( scaleRect[axisId] ); 631 if ( axisEnabled( yLeft ) ) 632 r = r.subtracted( QRegion( scaleRect[yLeft] ) ); 633 if ( axisEnabled( yRight ) ) 634 r = r.subtracted( QRegion( scaleRect[yRight] ) ); 635 r.translate( -scaleRect[ axisId ].x(), 636 -scaleRect[axisId].y() ); 637 638 scaleWidget->setMask( r ); 639 } 640 #endif 641 if ( !scaleWidget->isVisibleTo( this ) ) 642 scaleWidget->show(); 638 639 if ( m_data->legend ) 640 { 641 if ( m_data->legend->isEmpty() ) 642 { 643 m_data->legend->hide(); 643 644 } 644 645 else 645 646 { 646 scaleWidget->hide(); 647 } 648 } 649 650 if ( d_data->legend ) 651 { 652 if ( d_data->legend->isEmpty() ) 653 { 654 d_data->legend->hide(); 655 } 656 else 657 { 658 d_data->legend->setGeometry( legendRect ); 659 d_data->legend->show(); 660 } 661 } 662 663 d_data->canvas->setGeometry( canvasRect ); 664 } 665 666 /*! 667 \brief Calculate the canvas margins 668 669 \param maps QwtPlot::axisCnt maps, mapping between plot and paint device coordinates 670 \param canvasRect Bounding rectangle where to paint 671 \param left Return parameter for the left margin 672 \param top Return parameter for the top margin 673 \param right Return parameter for the right margin 674 \param bottom Return parameter for the bottom margin 675 676 Plot items might indicate, that they need some extra space 677 at the borders of the canvas by the QwtPlotItem::Margins flag. 678 679 updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint() 647 m_data->legend->setGeometry( legendRect ); 648 m_data->legend->show(); 649 } 650 } 651 652 m_data->canvas->setGeometry( canvasRect ); 653 } 654 655 /*! 656 \brief Calculate the canvas margins 657 658 \param maps QwtAxis::AxisCount maps, mapping between plot and paint device coordinates 659 \param canvasRect Bounding rectangle where to paint 660 \param left Return parameter for the left margin 661 \param top Return parameter for the top margin 662 \param right Return parameter for the right margin 663 \param bottom Return parameter for the bottom margin 664 665 Plot items might indicate, that they need some extra space 666 at the borders of the canvas by the QwtPlotItem::Margins flag. 667 668 updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint() 680 669 */ 681 670 void QwtPlot::getCanvasMarginsHint( 682 const QwtScaleMap maps[], const QRectF &canvasRect,683 double &left, double&top, double&right, double&bottom) const671 const QwtScaleMap maps[], const QRectF& canvasRect, 672 double& left, double& top, double& right, double& bottom) const 684 673 { 685 674 left = top = right = bottom = -1.0; … … 689 678 it != itmList.end(); ++it ) 690 679 { 691 const QwtPlotItem *item = *it;680 const QwtPlotItem* item = *it; 692 681 if ( item->testItemAttribute( QwtPlotItem::Margins ) ) 693 682 { 694 double m[ QwtPlot::axisCnt ]; 683 using namespace QwtAxis; 684 685 double m[ AxisPositions ]; 695 686 item->getCanvasMarginHint( 696 687 maps[ item->xAxis() ], maps[ item->yAxis() ], 697 canvasRect, m[ yLeft], m[xTop], m[yRight], m[xBottom] );698 699 left = q Max( left, m[yLeft] );700 top = q Max( top, m[xTop] );701 right = q Max( right, m[yRight] );702 bottom = q Max( bottom, m[xBottom] );703 } 704 } 705 } 706 707 /*! 708 \brief Update the canvas margins 709 710 Plot items might indicate, that they need some extra space 711 at the borders of the canvas by the QwtPlotItem::Margins flag. 712 713 getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint() 688 canvasRect, m[YLeft], m[XTop], m[YRight], m[XBottom] ); 689 690 left = qwtMaxF( left, m[YLeft] ); 691 top = qwtMaxF( top, m[XTop] ); 692 right = qwtMaxF( right, m[YRight] ); 693 bottom = qwtMaxF( bottom, m[XBottom] ); 694 } 695 } 696 } 697 698 /*! 699 \brief Update the canvas margins 700 701 Plot items might indicate, that they need some extra space 702 at the borders of the canvas by the QwtPlotItem::Margins flag. 703 704 getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint() 714 705 */ 715 706 void QwtPlot::updateCanvasMargins() 716 707 { 717 QwtScaleMap maps[axisCnt]; 718 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 708 using namespace QwtAxis; 709 710 QwtScaleMap maps[ AxisPositions ]; 711 for ( int axisId = 0; axisId < AxisPositions; axisId++ ) 719 712 maps[axisId] = canvasMap( axisId ); 720 713 721 double margins[ axisCnt];714 double margins[AxisPositions]; 722 715 getCanvasMarginsHint( maps, canvas()->contentsRect(), 723 margins[ yLeft], margins[xTop], margins[yRight], margins[xBottom] );716 margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] ); 724 717 725 718 bool doUpdate = false; 726 for ( int axis Id= 0; axisId < axisCnt; axisId++ )727 { 728 if ( margins[axis Id] >= 0.0 )729 { 730 const int m = qCeil( margins[axis Id] );731 plotLayout()->setCanvasMargin( m, axis Id);719 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 720 { 721 if ( margins[axisPos] >= 0.0 ) 722 { 723 const int m = qwtCeil( margins[axisPos] ); 724 plotLayout()->setCanvasMargin( m, axisPos); 732 725 doUpdate = true; 733 726 } … … 739 732 740 733 /*! 741 Redraw the canvas. 742 \param painter Painter used for drawing 743 744 \warning drawCanvas calls drawItems what is also used 734 Redraw the canvas. 735 \param painter Painter used for drawing 736 737 \warning drawCanvas calls drawItems what is also used 745 738 for printing. Applications that like to add individual 746 739 plot items better overload drawItems() 747 \sa drawItems() 748 */ 749 void QwtPlot::drawCanvas( QPainter *painter )750 { 751 QwtScaleMap maps[ axisCnt];752 for ( int axis Id= 0; axisId < axisCnt; axisId++ )753 maps[axis Id] = canvasMap( axisId);754 755 drawItems( painter, d_data->canvas->contentsRect(), maps );756 } 757 758 /*! 759 Redraw the canvas items. 760 761 \param painter Painter used for drawing 762 \param canvasRect Bounding rectangle where to paint 763 \param maps Qwt Plot::axisCnt maps, mapping between plot and paint device coordinates764 765 \note Usually canvasRect is contentsRect() of the plot canvas. 740 \sa drawItems() 741 */ 742 void QwtPlot::drawCanvas( QPainter* painter ) 743 { 744 QwtScaleMap maps[ QwtAxis::AxisPositions ]; 745 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 746 maps[axisPos] = canvasMap( axisPos ); 747 748 drawItems( painter, m_data->canvas->contentsRect(), maps ); 749 } 750 751 /*! 752 Redraw the canvas items. 753 754 \param painter Painter used for drawing 755 \param canvasRect Bounding rectangle where to paint 756 \param maps QwtAxis::AxisCount maps, mapping between plot and paint device coordinates 757 758 \note Usually canvasRect is contentsRect() of the plot canvas. 766 759 Due to a bug in Qt this rectangle might be wrong for certain 767 760 frame styles ( f.e QFrame::Box ) and it might be necessary to 768 761 fix the margins manually using QWidget::setContentsMargins() 769 */ 770 771 void QwtPlot::drawItems( QPainter *painter, const QRectF&canvasRect,772 const QwtScaleMap maps[axisCnt] ) const762 */ 763 764 void QwtPlot::drawItems( QPainter* painter, const QRectF& canvasRect, 765 const QwtScaleMap maps[ QwtAxis::AxisPositions ] ) const 773 766 { 774 767 const QwtPlotItemList& itmList = itemList(); … … 776 769 it != itmList.end(); ++it ) 777 770 { 778 QwtPlotItem *item = *it;771 QwtPlotItem* item = *it; 779 772 if ( item && item->isVisible() ) 780 773 { 774 const QwtAxisId xAxis = item->xAxis(); 775 const QwtAxisId yAxis = item->yAxis(); 776 781 777 painter->save(); 782 778 783 779 painter->setRenderHint( QPainter::Antialiasing, 784 780 item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 781 782 #if QT_VERSION < 0x050100 785 783 painter->setRenderHint( QPainter::HighQualityAntialiasing, 786 784 item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 787 788 item->draw( painter, 789 maps[item->xAxis()], maps[item->yAxis()], 790 canvasRect ); 785 #endif 786 787 item->draw( painter, maps[xAxis], maps[yAxis], canvasRect ); 791 788 792 789 painter->restore(); … … 796 793 797 794 /*! 798 \param axisId Axis 799 \return Map for the axis on the canvas. With this map pixel coordinates can 795 \param axisId Axis 796 \return Map for the axis on the canvas. With this map pixel coordinates can 800 797 translated to plot coordinates and vice versa. 801 \sa QwtScaleMap, transform(), invTransform() 802 803 */ 804 QwtScaleMap QwtPlot::canvasMap( int axisId ) const 798 \sa QwtScaleMap, transform(), invTransform() 799 */ 800 QwtScaleMap QwtPlot::canvasMap( QwtAxisId axisId ) const 805 801 { 806 802 QwtScaleMap map; 807 if ( ! d_data->canvas )803 if ( !m_data->canvas ) 808 804 return map; 809 805 810 806 map.setTransformation( axisScaleEngine( axisId )->transformation() ); 811 807 812 const QwtScaleDiv &sd = axisScaleDiv( axisId );808 const QwtScaleDiv& sd = axisScaleDiv( axisId ); 813 809 map.setScaleInterval( sd.lowerBound(), sd.upperBound() ); 814 810 815 if ( axisEnabled( axisId ) )816 { 817 const QwtScaleWidget *s = axisWidget( axisId );818 if ( axisId == yLeft ||axisId== yRight)819 { 820 double y = s->y() + s->startBorderDist() - d_data->canvas->y();811 if ( isAxisVisible( axisId ) ) 812 { 813 const QwtScaleWidget* s = axisWidget( axisId ); 814 if ( QwtAxis::isYAxis( axisId ) ) 815 { 816 double y = s->y() + s->startBorderDist() - m_data->canvas->y(); 821 817 double h = s->height() - s->startBorderDist() - s->endBorderDist(); 822 818 map.setPaintInterval( y + h, y ); … … 824 820 else 825 821 { 826 double x = s->x() + s->startBorderDist() - d_data->canvas->x();822 double x = s->x() + s->startBorderDist() - m_data->canvas->x(); 827 823 double w = s->width() - s->startBorderDist() - s->endBorderDist(); 828 824 map.setPaintInterval( x, x + w ); … … 831 827 else 832 828 { 833 const QRect &canvasRect = d_data->canvas->contentsRect(); 834 if ( axisId == yLeft || axisId == yRight ) 829 using namespace QwtAxis; 830 831 const QRect& canvasRect = m_data->canvas->contentsRect(); 832 if ( isYAxis( axisId ) ) 835 833 { 836 834 int top = 0; 837 if ( !plotLayout()->alignCanvasToScale( xTop ) )838 top = plotLayout()->canvasMargin( xTop );835 if ( !plotLayout()->alignCanvasToScale( XTop ) ) 836 top = plotLayout()->canvasMargin( XTop ); 839 837 840 838 int bottom = 0; 841 if ( !plotLayout()->alignCanvasToScale( xBottom ) )842 bottom = plotLayout()->canvasMargin( xBottom );839 if ( !plotLayout()->alignCanvasToScale( XBottom ) ) 840 bottom = plotLayout()->canvasMargin( XBottom ); 843 841 844 842 map.setPaintInterval( canvasRect.bottom() - bottom, … … 848 846 { 849 847 int left = 0; 850 if ( !plotLayout()->alignCanvasToScale( yLeft ) )851 left = plotLayout()->canvasMargin( yLeft );848 if ( !plotLayout()->alignCanvasToScale( YLeft ) ) 849 left = plotLayout()->canvasMargin( YLeft ); 852 850 853 851 int right = 0; 854 if ( !plotLayout()->alignCanvasToScale( yRight ) )855 right = plotLayout()->canvasMargin( yRight );852 if ( !plotLayout()->alignCanvasToScale( YRight ) ) 853 right = plotLayout()->canvasMargin( YRight ); 856 854 857 855 map.setPaintInterval( canvasRect.left() + left, … … 864 862 865 863 /*! 866 \brief Change the background of the plotting area 867 868 Sets brush to QPalette::Window of all color groups of 869 the palette of the canvas. Using canvas()->setPalette() 870 is a more powerful way to set these colors. 871 872 \param brush New background brush 873 \sa canvasBackground() 874 */ 875 void QwtPlot::setCanvasBackground( const QBrush &brush )876 { 877 QPalette pal = d_data->canvas->palette();864 \brief Change the background of the plotting area 865 866 Sets brush to QPalette::Window of all color groups of 867 the palette of the canvas. Using canvas()->setPalette() 868 is a more powerful way to set these colors. 869 870 \param brush New background brush 871 \sa canvasBackground() 872 */ 873 void QwtPlot::setCanvasBackground( const QBrush& brush ) 874 { 875 QPalette pal = m_data->canvas->palette(); 878 876 pal.setBrush( QPalette::Window, brush ); 879 877 … … 882 880 883 881 /*! 884 Nothing else than: canvas()->palette().brush( 882 Nothing else than: canvas()->palette().brush( 885 883 QPalette::Normal, QPalette::Window); 886 884 887 \return Background brush of the plotting area. 888 \sa setCanvasBackground() 889 */ 885 \return Background brush of the plotting area. 886 \sa setCanvasBackground() 887 */ 890 888 QBrush QwtPlot::canvasBackground() const 891 889 { … … 895 893 896 894 /*! 897 \return \c true if the specified axis exists, otherwise \c false 898 \param axisId axis index 899 */ 900 bool QwtPlot::axisValid( int axisId ) 901 { 902 return ( ( axisId >= QwtPlot::yLeft ) && ( axisId < QwtPlot::axisCnt ) ); 903 } 904 905 /*! 906 \brief Insert a legend 907 908 If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend 909 the legend will be organized in one column from top to down. 910 Otherwise the legend items will be placed in a table 911 with a best fit number of columns from left to right. 912 913 insertLegend() will set the plot widget as parent for the legend. 914 The legend will be deleted in the destructor of the plot or when 915 another legend is inserted. 916 917 Legends, that are not inserted into the layout of the plot widget 918 need to connect to the legendDataChanged() signal. Calling updateLegend() 919 initiates this signal for an initial update. When the application code 920 wants to implement its own layout this also needs to be done for 921 rendering plots to a document ( see QwtPlotRenderer ). 922 923 \param legend Legend 924 \param pos The legend's position. For top/left position the number 895 \brief Insert a legend 896 897 If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend 898 the legend will be organized in one column from top to down. 899 Otherwise the legend items will be placed in a table 900 with a best fit number of columns from left to right. 901 902 insertLegend() will set the plot widget as parent for the legend. 903 The legend will be deleted in the destructor of the plot or when 904 another legend is inserted. 905 906 Legends, that are not inserted into the layout of the plot widget 907 need to connect to the legendDataChanged() signal. Calling updateLegend() 908 initiates this signal for an initial update. When the application code 909 wants to implement its own layout this also needs to be done for 910 rendering plots to a document ( see QwtPlotRenderer ). 911 912 \param legend Legend 913 \param pos The legend's position. For top/left position the number 925 914 of columns will be limited to 1, otherwise it will be set to 926 915 unlimited. 927 916 928 \param ratio Ratio between legend and the bounding rectangle 917 \param ratio Ratio between legend and the bounding rectangle 929 918 of title, canvas and axes. The legend will be shrunk 930 919 if it would need more space than the given ratio. … … 933 922 The default vertical/horizontal ratio is 0.33/0.5. 934 923 935 \sa legend(), QwtPlotLayout::legendPosition(), 924 \sa legend(), QwtPlotLayout::legendPosition(), 936 925 QwtPlotLayout::setLegendPosition() 937 */ 938 void QwtPlot::insertLegend( QwtAbstractLegend *legend,926 */ 927 void QwtPlot::insertLegend( QwtAbstractLegend* legend, 939 928 QwtPlot::LegendPosition pos, double ratio ) 940 929 { 941 d_data->layout->setLegendPosition( pos, ratio );942 943 if ( legend != d_data->legend )944 { 945 if ( d_data->legend &&d_data->legend->parent() == this )946 delete d_data->legend;947 948 d_data->legend = legend;949 950 if ( d_data->legend )930 m_data->layout->setLegendPosition( pos, ratio ); 931 932 if ( legend != m_data->legend ) 933 { 934 if ( m_data->legend && m_data->legend->parent() == this ) 935 delete m_data->legend; 936 937 m_data->legend = legend; 938 939 if ( m_data->legend ) 951 940 { 952 941 connect( 953 942 this, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)), 954 d_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>))955 ); 956 957 if ( d_data->legend->parent() != this )958 d_data->legend->setParent( this );943 m_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>)) 944 ); 945 946 if ( m_data->legend->parent() != this ) 947 m_data->legend->setParent( this ); 959 948 960 949 qwtEnableLegendItems( this, false ); … … 962 951 qwtEnableLegendItems( this, true ); 963 952 964 QwtLegend *lgd = qobject_cast<QwtLegend*>( legend );953 QwtLegend* lgd = qobject_cast< QwtLegend* >( legend ); 965 954 if ( lgd ) 966 955 { 967 switch ( d_data->layout->legendPosition() )956 switch ( m_data->layout->legendPosition() ) 968 957 { 969 958 case LeftLegend: … … 985 974 } 986 975 987 QWidget *previousInChain = NULL;988 switch ( d_data->layout->legendPosition() )976 QWidget* previousInChain = NULL; 977 switch ( m_data->layout->legendPosition() ) 989 978 { 990 979 case LeftLegend: 991 980 { 992 previousInChain = axisWidget( QwtPlot::xTop ); 981 const QwtAxisId axisId( QwtAxis::XTop ); 982 previousInChain = axisWidget( axisId ); 993 983 break; 994 984 } … … 1000 990 case RightLegend: 1001 991 { 1002 previousInChain = axisWidget( QwtPlot::yRight ); 992 const QwtAxisId axisId( QwtAxis::YRight ); 993 previousInChain = axisWidget( axisId ); 1003 994 break; 1004 995 } … … 1019 1010 1020 1011 /*! 1021 Emit legendDataChanged() for all plot item 1022 1023 \sa QwtPlotItem::legendData(), legendDataChanged() 1012 Emit legendDataChanged() for all plot item 1013 1014 \sa QwtPlotItem::legendData(), legendDataChanged() 1024 1015 */ 1025 1016 void QwtPlot::updateLegend() … … 1034 1025 1035 1026 /*! 1036 Emit legendDataChanged() for a plot item 1037 1038 \param plotItem Plot item 1039 \sa QwtPlotItem::legendData(), legendDataChanged() 1040 */ 1041 void QwtPlot::updateLegend( const QwtPlotItem *plotItem )1027 Emit legendDataChanged() for a plot item 1028 1029 \param plotItem Plot item 1030 \sa QwtPlotItem::legendData(), legendDataChanged() 1031 */ 1032 void QwtPlot::updateLegend( const QwtPlotItem* plotItem ) 1042 1033 { 1043 1034 if ( plotItem == NULL ) 1044 1035 return; 1045 1036 1046 QList<QwtLegendData> legendData; 1037 QList< QwtLegendData > legendData; 1047 1038 1048 1039 if ( plotItem->testItemAttribute( QwtPlotItem::Legend ) ) 1049 1040 legendData = plotItem->legendData(); 1050 1041 1051 const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem *>( plotItem) );1042 const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem* >( plotItem ) ); 1052 1043 Q_EMIT legendDataChanged( itemInfo, legendData ); 1053 1044 } 1054 1045 1055 1046 /*! 1056 \brief Update all plot items interested in legend attributes 1057 1058 Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest 1059 flag is set. 1060 1061 \param itemInfo Info about the plot item 1062 \param legendData Entries to be displayed for the plot item ( usually 1 ) 1063 1064 \sa QwtPlotItem::LegendInterest, 1047 \brief Update all plot items interested in legend attributes 1048 1049 Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest 1050 flag is set. 1051 1052 \param itemInfo Info about the plot item 1053 \param legendData Entries to be displayed for the plot item ( usually 1 ) 1054 1055 \sa QwtPlotItem::LegendInterest, 1065 1056 QwtPlotLegendItem, QwtPlotItem::updateLegend() 1066 1057 */ 1067 void QwtPlot::updateLegendItems( const QVariant &itemInfo,1068 const QList<QwtLegendData > &legendData )1069 { 1070 QwtPlotItem *plotItem = infoToItem( itemInfo );1058 void QwtPlot::updateLegendItems( const QVariant& itemInfo, 1059 const QList< QwtLegendData >& legendData ) 1060 { 1061 QwtPlotItem* plotItem = infoToItem( itemInfo ); 1071 1062 if ( plotItem ) 1072 1063 { … … 1075 1066 it != itmList.end(); ++it ) 1076 1067 { 1077 QwtPlotItem *item = *it;1068 QwtPlotItem* item = *it; 1078 1069 if ( item->testItemInterest( QwtPlotItem::LegendInterest ) ) 1079 1070 item->updateLegend( plotItem, legendData ); … … 1083 1074 1084 1075 /*! 1085 \brief Attach/Detach a plot item 1086 1087 \param plotItem Plot item 1088 \param on When true attach the item, otherwise detach it 1089 */ 1090 void QwtPlot::attachItem( QwtPlotItem *plotItem, bool on )1076 \brief Attach/Detach a plot item 1077 1078 \param plotItem Plot item 1079 \param on When true attach the item, otherwise detach it 1080 */ 1081 void QwtPlot::attachItem( QwtPlotItem* plotItem, bool on ) 1091 1082 { 1092 1083 if ( plotItem->testItemInterest( QwtPlotItem::LegendInterest ) ) … … 1098 1089 it != itmList.end(); ++it ) 1099 1090 { 1100 QwtPlotItem *item = *it;1101 1102 QList<QwtLegendData> legendData; 1091 QwtPlotItem* item = *it; 1092 1093 QList< QwtLegendData > legendData; 1103 1094 if ( on && item->testItemAttribute( QwtPlotItem::Legend ) ) 1104 1095 { … … 1127 1118 { 1128 1119 const QVariant itemInfo = itemToInfo( plotItem ); 1129 Q_EMIT legendDataChanged( itemInfo, QList<QwtLegendData>() ); 1120 Q_EMIT legendDataChanged( itemInfo, QList< QwtLegendData >() ); 1130 1121 } 1131 1122 } … … 1135 1126 1136 1127 /*! 1137 \brief Build an information, that can be used to identify 1128 \brief Build an information, that can be used to identify 1138 1129 a plot item on the legend. 1139 1130 1140 The default implementation simply wraps the plot item 1141 into a QVariant object. When overloading itemToInfo() 1142 usually infoToItem() needs to reimplemeted too. 1143 1144 \code 1145 QVariant itemInfo; 1146 qVariantSetValue( itemInfo, plotItem ); 1147 \endcode 1148 1149 \param plotItem Plot item 1150 \return Plot item embedded in a QVariant 1151 \sa infoToItem() 1152 */ 1153 QVariant QwtPlot::itemToInfo( QwtPlotItem *plotItem ) const 1154 { 1155 QVariant itemInfo; 1156 qVariantSetValue( itemInfo, plotItem ); 1157 1158 return itemInfo; 1159 } 1160 1161 /*! 1162 \brief Identify the plot item according to an item info object, 1131 The default implementation simply wraps the plot item 1132 into a QVariant object. When overloading itemToInfo() 1133 usually infoToItem() needs to reimplemeted too. 1134 1135 \param plotItem Plot item 1136 \return Plot item embedded in a QVariant 1137 \sa infoToItem() 1138 */ 1139 QVariant QwtPlot::itemToInfo( QwtPlotItem* plotItem ) const 1140 { 1141 return QVariant::fromValue( plotItem ); 1142 } 1143 1144 /*! 1145 \brief Identify the plot item according to an item info object, 1163 1146 that has bee generated from itemToInfo(). 1164 1147 1165 The default implementation simply tries to unwrap a QwtPlotItem 1166 pointer: 1167 1168 \code 1148 The default implementation simply tries to unwrap a QwtPlotItem 1149 pointer: 1150 1151 \code 1169 1152 if ( itemInfo.canConvert<QwtPlotItem *>() ) 1170 1153 return qvariant_cast<QwtPlotItem *>( itemInfo ); 1171 \endcode 1172 \param itemInfo Plot item 1173 \return A plot item, when successful, otherwise a NULL pointer. 1174 \sa itemToInfo() 1175 */ 1176 QwtPlotItem *QwtPlot::infoToItem( const QVariant&itemInfo ) const1177 { 1178 if ( itemInfo.canConvert<QwtPlotItem *>() )1179 return qvariant_cast<QwtPlotItem *>( itemInfo );1154 \endcode 1155 \param itemInfo Plot item 1156 \return A plot item, when successful, otherwise a NULL pointer. 1157 \sa itemToInfo() 1158 */ 1159 QwtPlotItem* QwtPlot::infoToItem( const QVariant& itemInfo ) const 1160 { 1161 if ( itemInfo.canConvert< QwtPlotItem* >() ) 1162 return qvariant_cast< QwtPlotItem* >( itemInfo ); 1180 1163 1181 1164 return NULL; 1182 1165 } 1183 1166 1184 1167 #include "moc_qwt_plot.cpp" -
trunk/BNC/qwt/qwt_plot.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_ text.h"14 #include "qwt_axis_id.h" 15 15 #include "qwt_plot_dict.h" 16 #include "qwt_scale_map.h" 17 #include "qwt_interval.h" 16 18 17 #include <qframe.h> 19 #include <qlist.h>20 #include <qvariant.h>21 18 22 19 class QwtPlotLayout; … … 25 22 class QwtScaleEngine; 26 23 class QwtScaleDiv; 24 class QwtScaleMap; 27 25 class QwtScaleDraw; 28 26 class QwtTextLabel; 27 class QwtInterval; 28 class QwtText; 29 template< typename T > class QList; 30 31 // 6.1 compatibility definitions 32 #define QWT_AXIS_COMPAT 1 29 33 30 34 /*! 31 \brief A 2-D plotting widget 32 33 QwtPlot is a widget for plotting two-dimensional graphs. 34 An unlimited number of plot items can be displayed on 35 its canvas. Plot items might be curves (QwtPlotCurve), markers 36 (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived 37 from QwtPlotItem. 38 A plot can have up to four axes, with each plot item attached to an x- and 39 a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or 40 are calculated from the plot items, using algorithms (QwtScaleEngine) which 41 can be configured separately for each axis. 42 43 The simpleplot example is a good starting point to see how to set up a 44 plot widget. 45 46 \image html plot.png 47 48 \par Example 35 \brief A 2-D plotting widget 36 37 QwtPlot is a widget for plotting two-dimensional graphs. 38 An unlimited number of plot items can be displayed on 39 its canvas. Plot items might be curves (QwtPlotCurve), markers 40 (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived 41 from QwtPlotItem. 42 A plot can have up to four axes, with each plot item attached to an x- and 43 a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or 44 are calculated from the plot items, using algorithms (QwtScaleEngine) which 45 can be configured separately for each axis. 46 47 The simpleplot example is a good starting point to see how to set up a 48 plot widget. 49 50 \image html plot.png 51 52 \par Example 49 53 The following example shows (schematically) the most simple 50 54 way to use QwtPlot. By default, only the left and bottom axes are 51 55 visible and their scales are computed automatically. 52 56 \code 53 #include <qwt_plot.h>54 #include <qwt_plot_curve.h>57 #include <qwt_plot.h> 58 #include <qwt_plot_curve.h> 55 59 56 60 QwtPlot *myPlot = new QwtPlot( "Two Curves", parent ); … … 70 74 myPlot->replot(); 71 75 \endcode 72 \endpar 73 */ 74 75 class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict 76 */ 77 78 class QWT_EXPORT QwtPlot : public QFrame, public QwtPlotDict 76 79 { 77 80 Q_OBJECT … … 79 82 Q_PROPERTY( QBrush canvasBackground 80 83 READ canvasBackground WRITE setCanvasBackground ) 84 81 85 Q_PROPERTY( bool autoReplot READ autoReplot WRITE setAutoReplot ) 82 86 83 #if 0 84 // This property is intended to configure the plot 85 // widget from a special dialog in the deigner plugin. 86 // Disabled until such a dialog has been implemented. 87 88 Q_PROPERTY( QString propertiesDocument 89 READ grabProperties WRITE applyProperties ) 90 #endif 91 92 public: 93 //! \brief Axis index 94 enum Axis 95 { 96 //! Y axis left of the canvas 97 yLeft, 98 99 //! Y axis right of the canvas 100 yRight, 101 102 //! X axis below the canvas 103 xBottom, 104 105 //! X axis above the canvas 106 xTop, 107 108 //! Number of axes 109 axisCnt 110 }; 111 87 public: 112 88 /*! 113 89 Position of the legend, relative to the canvas. … … 117 93 enum LegendPosition 118 94 { 119 //! The legend will be left from the Qwt Plot::yLeft axis.95 //! The legend will be left from the QwtAxis::YLeft axis. 120 96 LeftLegend, 121 97 122 //! The legend will be right from the Qwt Plot::yRight axis.98 //! The legend will be right from the QwtAxis::YRight axis. 123 99 RightLegend, 124 100 … … 130 106 }; 131 107 132 explicit QwtPlot( QWidget * = NULL );133 explicit QwtPlot( const QwtText &title, QWidget* = NULL );108 explicit QwtPlot( QWidget* = NULL ); 109 explicit QwtPlot( const QwtText& title, QWidget* = NULL ); 134 110 135 111 virtual ~QwtPlot(); 136 137 void applyProperties( const QString & );138 QString grabProperties() const;139 112 140 113 void setAutoReplot( bool = true ); … … 143 116 // Layout 144 117 145 void setPlotLayout( QwtPlotLayout * );146 147 QwtPlotLayout *plotLayout();148 const QwtPlotLayout *plotLayout() const;118 void setPlotLayout( QwtPlotLayout* ); 119 120 QwtPlotLayout* plotLayout(); 121 const QwtPlotLayout* plotLayout() const; 149 122 150 123 // Title 151 124 152 void setTitle( const QString & );153 void setTitle( const QwtText & );125 void setTitle( const QString& ); 126 void setTitle( const QwtText& ); 154 127 QwtText title() const; 155 128 156 QwtTextLabel *titleLabel();157 const QwtTextLabel *titleLabel() const;129 QwtTextLabel* titleLabel(); 130 const QwtTextLabel* titleLabel() const; 158 131 159 132 // Footer 160 133 161 void setFooter( const QString & );162 void setFooter( const QwtText & );134 void setFooter( const QString& ); 135 void setFooter( const QwtText& ); 163 136 QwtText footer() const; 164 137 165 QwtTextLabel *footerLabel();166 const QwtTextLabel *footerLabel() const;138 QwtTextLabel* footerLabel(); 139 const QwtTextLabel* footerLabel() const; 167 140 168 141 // Canvas 169 142 170 void setCanvas( QWidget * );171 172 QWidget *canvas();173 const QWidget *canvas() const;174 175 void setCanvasBackground( const QBrush & );143 void setCanvas( QWidget* ); 144 145 QWidget* canvas(); 146 const QWidget* canvas() const; 147 148 void setCanvasBackground( const QBrush& ); 176 149 QBrush canvasBackground() const; 177 150 178 virtual QwtScaleMap canvasMap( int axisId ) const;179 180 double invTransform( int axisId,intpos ) const;181 double transform( int axisId, double value ) const;151 virtual QwtScaleMap canvasMap( QwtAxisId ) const; 152 153 double invTransform( QwtAxisId, double pos ) const; 154 double transform( QwtAxisId, double value ) const; 182 155 183 156 // Axes 184 157 185 QwtScaleEngine *axisScaleEngine( int axisId ); 186 const QwtScaleEngine *axisScaleEngine( int axisId ) const; 187 void setAxisScaleEngine( int axisId, QwtScaleEngine * ); 188 189 void setAxisAutoScale( int axisId, bool on = true ); 190 bool axisAutoScale( int axisId ) const; 191 192 void enableAxis( int axisId, bool tf = true ); 193 bool axisEnabled( int axisId ) const; 194 195 void setAxisFont( int axisId, const QFont & ); 196 QFont axisFont( int axisId ) const; 197 198 void setAxisScale( int axisId, double min, double max, double stepSize = 0 ); 199 void setAxisScaleDiv( int axisId, const QwtScaleDiv & ); 200 void setAxisScaleDraw( int axisId, QwtScaleDraw * ); 201 202 double axisStepSize( int axisId ) const; 203 QwtInterval axisInterval( int axisId ) const; 204 205 const QwtScaleDiv &axisScaleDiv( int axisId ) const; 206 207 const QwtScaleDraw *axisScaleDraw( int axisId ) const; 208 QwtScaleDraw *axisScaleDraw( int axisId ); 209 210 const QwtScaleWidget *axisWidget( int axisId ) const; 211 QwtScaleWidget *axisWidget( int axisId ); 212 213 void setAxisLabelAlignment( int axisId, Qt::Alignment ); 214 void setAxisLabelRotation( int axisId, double rotation ); 215 216 void setAxisTitle( int axisId, const QString & ); 217 void setAxisTitle( int axisId, const QwtText & ); 218 QwtText axisTitle( int axisId ) const; 219 220 void setAxisMaxMinor( int axisId, int maxMinor ); 221 int axisMaxMinor( int axisId ) const; 222 223 void setAxisMaxMajor( int axisId, int maxMajor ); 224 int axisMaxMajor( int axisId ) const; 158 bool isAxisValid( QwtAxisId ) const; 159 160 void setAxisVisible( QwtAxisId, bool on = true ); 161 bool isAxisVisible( QwtAxisId ) const; 162 163 // Axes data 164 165 QwtScaleEngine* axisScaleEngine( QwtAxisId ); 166 const QwtScaleEngine* axisScaleEngine( QwtAxisId ) const; 167 void setAxisScaleEngine( QwtAxisId, QwtScaleEngine* ); 168 169 void setAxisAutoScale( QwtAxisId, bool on = true ); 170 bool axisAutoScale( QwtAxisId ) const; 171 172 void setAxisFont( QwtAxisId, const QFont& ); 173 QFont axisFont( QwtAxisId ) const; 174 175 void setAxisScale( QwtAxisId, double min, double max, double stepSize = 0 ); 176 void setAxisScaleDiv( QwtAxisId, const QwtScaleDiv& ); 177 void setAxisScaleDraw( QwtAxisId, QwtScaleDraw* ); 178 179 double axisStepSize( QwtAxisId ) const; 180 QwtInterval axisInterval( QwtAxisId ) const; 181 const QwtScaleDiv& axisScaleDiv( QwtAxisId ) const; 182 183 const QwtScaleDraw* axisScaleDraw( QwtAxisId ) const; 184 QwtScaleDraw* axisScaleDraw( QwtAxisId ); 185 186 const QwtScaleWidget* axisWidget( QwtAxisId ) const; 187 QwtScaleWidget* axisWidget( QwtAxisId ); 188 189 void setAxisLabelAlignment( QwtAxisId, Qt::Alignment ); 190 void setAxisLabelRotation( QwtAxisId, double rotation ); 191 192 void setAxisTitle( QwtAxisId, const QString& ); 193 void setAxisTitle( QwtAxisId, const QwtText& ); 194 QwtText axisTitle( QwtAxisId ) const; 195 196 void setAxisMaxMinor( QwtAxisId, int maxMinor ); 197 int axisMaxMinor( QwtAxisId ) const; 198 199 void setAxisMaxMajor( QwtAxisId, int maxMajor ); 200 int axisMaxMajor( QwtAxisId ) const; 225 201 226 202 // Legend 227 203 228 void insertLegend( QwtAbstractLegend *,204 void insertLegend( QwtAbstractLegend*, 229 205 LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 ); 230 206 231 QwtAbstractLegend *legend();232 const QwtAbstractLegend *legend() const;207 QwtAbstractLegend* legend(); 208 const QwtAbstractLegend* legend() const; 233 209 234 210 void updateLegend(); 235 void updateLegend( const QwtPlotItem * );211 void updateLegend( const QwtPlotItem* ); 236 212 237 213 // Misc 238 214 239 virtual QSize sizeHint() const; 240 virtual QSize minimumSizeHint() const; 215 virtual QSize sizeHint() const QWT_OVERRIDE; 216 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 241 217 242 218 virtual void updateLayout(); 243 virtual void drawCanvas( QPainter * );219 virtual void drawCanvas( QPainter* ); 244 220 245 221 void updateAxes(); … … 247 223 248 224 virtual void getCanvasMarginsHint( 249 const QwtScaleMap maps[], const QRectF &canvasRect, 250 double &left, double &top, double &right, double &bottom) const; 251 252 virtual bool event( QEvent * ); 253 virtual bool eventFilter( QObject *, QEvent * ); 254 255 virtual void drawItems( QPainter *, const QRectF &, 256 const QwtScaleMap maps[axisCnt] ) const; 257 258 virtual QVariant itemToInfo( QwtPlotItem * ) const; 259 virtual QwtPlotItem *infoToItem( const QVariant & ) const; 260 261 Q_SIGNALS: 225 const QwtScaleMap maps[], const QRectF& canvasRect, 226 double& left, double& top, double& right, double& bottom) const; 227 228 virtual bool event( QEvent* ) QWT_OVERRIDE; 229 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 230 231 virtual void drawItems( QPainter*, const QRectF&, 232 const QwtScaleMap maps[ QwtAxis::AxisPositions ] ) const; 233 234 virtual QVariant itemToInfo( QwtPlotItem* ) const; 235 virtual QwtPlotItem* infoToItem( const QVariant& ) const; 236 237 #if QWT_AXIS_COMPAT 238 enum Axis 239 { 240 yLeft = QwtAxis::YLeft, 241 yRight = QwtAxis::YRight, 242 xBottom = QwtAxis::XBottom, 243 xTop = QwtAxis::XTop, 244 245 axisCnt = QwtAxis::AxisPositions 246 }; 247 248 void enableAxis( int axisId, bool on = true ) 249 { 250 setAxisVisible( axisId, on ); 251 } 252 253 bool axisEnabled( int axisId ) const 254 { 255 return isAxisVisible( axisId ); 256 } 257 #endif 258 259 Q_SIGNALS: 262 260 /*! 263 A signal indicating, that an item has been attached/detached 264 265 \param plotItem Plot item 266 \param on Attached/Detached 261 A signal indicating, that an item has been attached/detached 262 263 \param plotItem Plot item 264 \param on Attached/Detached 267 265 */ 268 void itemAttached( QwtPlotItem *plotItem, bool on );266 void itemAttached( QwtPlotItem* plotItem, bool on ); 269 267 270 268 /*! 271 A signal with the attributes how to update 272 the legend entries for a plot item. 273 274 \param itemInfo Info about a plot item, build from itemToInfo() 275 \param data Attributes of the entries ( usually <= 1 ) for 269 A signal with the attributes how to update 270 the legend entries for a plot item. 271 272 \param itemInfo Info about a plot item, build from itemToInfo() 273 \param data Attributes of the entries ( usually <= 1 ) for 276 274 the plot item. 277 275 278 \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend() 276 \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend() 279 277 */ 280 void legendDataChanged( const QVariant &itemInfo,281 const QList<QwtLegendData > &data );282 283 public Q_SLOTS: 278 void legendDataChanged( const QVariant& itemInfo, 279 const QList< QwtLegendData >& data ); 280 281 public Q_SLOTS: 284 282 virtual void replot(); 285 283 void autoRefresh(); 286 284 287 protected: 288 static bool axisValid( int axisId ); 289 290 virtual void resizeEvent( QResizeEvent *e ); 291 292 private Q_SLOTS: 293 void updateLegendItems( const QVariant &itemInfo, 294 const QList<QwtLegendData> &legendData ); 295 296 private: 285 protected: 286 287 virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE; 288 289 private Q_SLOTS: 290 void updateLegendItems( const QVariant& itemInfo, 291 const QList< QwtLegendData >& legendData ); 292 293 private: 297 294 friend class QwtPlotItem; 298 void attachItem( QwtPlotItem *, bool );295 void attachItem( QwtPlotItem*, bool ); 299 296 300 297 void initAxesData(); … … 302 299 void updateScaleDiv(); 303 300 304 void initPlot( const QwtText &title );305 306 class AxisData;307 AxisData *d_axisData[axisCnt];301 void initPlot( const QwtText& title ); 302 303 class ScaleData; 304 ScaleData* m_scaleData; 308 305 309 306 class PrivateData; 310 PrivateData *d_data;307 PrivateData* m_data; 311 308 }; 312 309 -
trunk/BNC/qwt/qwt_plot_abstract_barchart.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_abstract_barchart.h" 11 11 #include "qwt_scale_map.h" 12 #include "qwt_math.h" 12 13 13 14 static inline double qwtTransformWidth( 14 const QwtScaleMap &map, double value, double width )15 const QwtScaleMap& map, double value, double width ) 15 16 { 16 17 const double w2 = 0.5 * width; … … 24 25 class QwtPlotAbstractBarChart::PrivateData 25 26 { 26 public: 27 PrivateData() :28 layoutPolicy( QwtPlotAbstractBarChart::AutoAdjustSamples ) ,29 layoutHint( 0.5 ) ,30 spacing( 10 ) ,31 margin( 5 ) ,32 baseline( 0.0 ) 27 public: 28 PrivateData() 29 : layoutPolicy( QwtPlotAbstractBarChart::AutoAdjustSamples ) 30 , layoutHint( 0.5 ) 31 , spacing( 10 ) 32 , margin( 5 ) 33 , baseline( 0.0 ) 33 34 { 34 35 } … … 42 43 43 44 /*! 44 Constructor 45 \param title Title of the chart 46 */ 47 QwtPlotAbstractBarChart::QwtPlotAbstractBarChart( const QwtText &title ):48 QwtPlotSeriesItem( title ) 49 { 50 d_data = new PrivateData;45 Constructor 46 \param title Title of the chart 47 */ 48 QwtPlotAbstractBarChart::QwtPlotAbstractBarChart( const QwtText& title ) 49 : QwtPlotSeriesItem( title ) 50 { 51 m_data = new PrivateData; 51 52 52 53 setItemAttribute( QwtPlotItem::Legend, true ); … … 59 60 QwtPlotAbstractBarChart::~QwtPlotAbstractBarChart() 60 61 { 61 delete d_data;62 } 63 64 /*! 65 The combination of layoutPolicy() and layoutHint() define how the width 66 of the bars is calculated 67 68 \param policy Layout policy 69 70 \sa layoutPolicy(), layoutHint() 62 delete m_data; 63 } 64 65 /*! 66 The combination of layoutPolicy() and layoutHint() define how the width 67 of the bars is calculated 68 69 \param policy Layout policy 70 71 \sa layoutPolicy(), layoutHint() 71 72 */ 72 73 void QwtPlotAbstractBarChart::setLayoutPolicy( LayoutPolicy policy ) 73 74 { 74 if ( policy != d_data->layoutPolicy )75 { 76 d_data->layoutPolicy = policy;77 itemChanged(); 78 } 79 } 80 81 /*! 82 The combination of layoutPolicy() and layoutHint() define how the width 83 of the bars is calculated 84 85 \return Layout policy of the chart item 86 \sa setLayoutPolicy(), layoutHint() 75 if ( policy != m_data->layoutPolicy ) 76 { 77 m_data->layoutPolicy = policy; 78 itemChanged(); 79 } 80 } 81 82 /*! 83 The combination of layoutPolicy() and layoutHint() define how the width 84 of the bars is calculated 85 86 \return Layout policy of the chart item 87 \sa setLayoutPolicy(), layoutHint() 87 88 */ 88 89 QwtPlotAbstractBarChart::LayoutPolicy QwtPlotAbstractBarChart::layoutPolicy() const 89 90 { 90 return d_data->layoutPolicy;91 } 92 93 /*! 94 The combination of layoutPolicy() and layoutHint() define how the width 95 of the bars is calculated 96 97 \param hint Layout hint 98 99 \sa LayoutPolicy, layoutPolicy(), layoutHint() 91 return m_data->layoutPolicy; 92 } 93 94 /*! 95 The combination of layoutPolicy() and layoutHint() define how the width 96 of the bars is calculated 97 98 \param hint Layout hint 99 100 \sa LayoutPolicy, layoutPolicy(), layoutHint() 100 101 */ 101 102 void QwtPlotAbstractBarChart::setLayoutHint( double hint ) 102 103 { 103 hint = q Max( 0.0, hint );104 if ( hint != d_data->layoutHint )105 { 106 d_data->layoutHint = hint;107 itemChanged(); 108 } 109 } 110 111 /*! 112 The combination of layoutPolicy() and layoutHint() define how the width 113 of the bars is calculated 114 115 \return Layout policy of the chart item 116 \sa LayoutPolicy, setLayoutHint(), layoutPolicy() 117 */ 104 hint = qwtMaxF( 0.0, hint ); 105 if ( hint != m_data->layoutHint ) 106 { 107 m_data->layoutHint = hint; 108 itemChanged(); 109 } 110 } 111 112 /*! 113 The combination of layoutPolicy() and layoutHint() define how the width 114 of the bars is calculated 115 116 \return Layout policy of the chart item 117 \sa LayoutPolicy, setLayoutHint(), layoutPolicy() 118 */ 118 119 double QwtPlotAbstractBarChart::layoutHint() const 119 120 { 120 return d_data->layoutHint;121 } 122 123 /*! 124 \brief Set the spacing 125 126 The spacing is the distance between 2 samples ( bars for QwtPlotBarChart or 127 a group of bars for QwtPlotMultiBarChart ) in paint device coordinates. 128 129 \sa spacing() 121 return m_data->layoutHint; 122 } 123 124 /*! 125 \brief Set the spacing 126 127 The spacing is the distance between 2 samples ( bars for QwtPlotBarChart or 128 a group of bars for QwtPlotMultiBarChart ) in paint device coordinates. 129 130 \sa spacing() 130 131 */ 131 132 void QwtPlotAbstractBarChart::setSpacing( int spacing ) 132 133 { 133 134 spacing = qMax( spacing, 0 ); 134 if ( spacing != d_data->spacing )135 { 136 d_data->spacing = spacing;137 itemChanged(); 138 } 139 } 140 141 /*! 142 \return Spacing between 2 samples ( bars or groups of bars ) 143 \sa setSpacing(), margin() 135 if ( spacing != m_data->spacing ) 136 { 137 m_data->spacing = spacing; 138 itemChanged(); 139 } 140 } 141 142 /*! 143 \return Spacing between 2 samples ( bars or groups of bars ) 144 \sa setSpacing(), margin() 144 145 */ 145 146 int QwtPlotAbstractBarChart::spacing() const 146 147 { 147 return d_data->spacing;148 } 149 /*! 150 \brief Set the margin 151 152 The margin is the distance between the outmost bars and the contentsRect() 153 of the canvas. The default setting is 5 pixels. 154 155 \param margin Margin 156 157 \sa spacing(), margin() 148 return m_data->spacing; 149 } 150 /*! 151 \brief Set the margin 152 153 The margin is the distance between the outmost bars and the contentsRect() 154 of the canvas. The default setting is 5 pixels. 155 156 \param margin Margin 157 158 \sa spacing(), margin() 158 159 */ 159 160 void QwtPlotAbstractBarChart::setMargin( int margin ) 160 161 { 161 162 margin = qMax( margin, 0 ); 162 if ( margin != d_data->margin )163 { 164 d_data->margin = margin;165 itemChanged(); 166 } 167 } 168 169 /*! 170 \return Margin between the outmost bars and the contentsRect() 171 of the canvas. 172 173 \sa setMargin(), spacing() 163 if ( margin != m_data->margin ) 164 { 165 m_data->margin = margin; 166 itemChanged(); 167 } 168 } 169 170 /*! 171 \return Margin between the outmost bars and the contentsRect() 172 of the canvas. 173 174 \sa setMargin(), spacing() 174 175 */ 175 176 int QwtPlotAbstractBarChart::margin() const 176 177 { 177 return d_data->margin;178 return m_data->margin; 178 179 } 179 180 … … 191 192 192 193 \sa baseline(), QwtPlotSeriesItem::orientation() 193 */ 194 */ 194 195 void QwtPlotAbstractBarChart::setBaseline( double value ) 195 196 { 196 if ( value != d_data->baseline )197 { 198 d_data->baseline = value;197 if ( value != m_data->baseline ) 198 { 199 m_data->baseline = value; 199 200 itemChanged(); 200 201 } … … 207 208 double QwtPlotAbstractBarChart::baseline() const 208 209 { 209 return d_data->baseline;210 return m_data->baseline; 210 211 } 211 212 … … 221 222 \return Sample width 222 223 \sa layoutPolicy(), layoutHint() 223 */ 224 double QwtPlotAbstractBarChart::sampleWidth( const QwtScaleMap &map,224 */ 225 double QwtPlotAbstractBarChart::sampleWidth( const QwtScaleMap& map, 225 226 double canvasSize, double boundingSize, double value ) const 226 227 { 227 228 double width; 228 229 229 switch( d_data->layoutPolicy )230 switch( m_data->layoutPolicy ) 230 231 { 231 232 case ScaleSamplesToAxes: 232 233 { 233 width = qwtTransformWidth( map, value, d_data->layoutHint );234 width = qwtTransformWidth( map, value, m_data->layoutHint ); 234 235 break; 235 236 } 236 237 case ScaleSampleToCanvas: 237 238 { 238 width = canvasSize * d_data->layoutHint;239 width = canvasSize * m_data->layoutHint; 239 240 break; 240 241 } 241 242 case FixedSampleSize: 242 243 { 243 width = d_data->layoutHint;244 width = m_data->layoutHint; 244 245 break; 245 246 } … … 256 257 257 258 width = qwtTransformWidth( map, value, w ); 258 width -= d_data->spacing;259 width = q Max( width,d_data->layoutHint );259 width -= m_data->spacing; 260 width = qwtMaxF( width, m_data->layoutHint ); 260 261 } 261 262 } … … 281 282 \param bottom Returns the bottom margin 282 283 283 \return Margin284 285 284 \sa layoutPolicy(), layoutHint(), QwtPlotItem::Margins 286 285 QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins() 287 286 */ 288 void QwtPlotAbstractBarChart::getCanvasMarginHint( const QwtScaleMap &xMap,289 const QwtScaleMap &yMap, const QRectF&canvasRect,290 double &left, double&top, double&right, double&bottom ) const287 void QwtPlotAbstractBarChart::getCanvasMarginHint( const QwtScaleMap& xMap, 288 const QwtScaleMap& yMap, const QRectF& canvasRect, 289 double& left, double& top, double& right, double& bottom ) const 291 290 { 292 291 double hint = -1.0; … … 297 296 { 298 297 if ( orientation() == Qt::Vertical ) 299 hint = 0.5 * canvasRect.width() * d_data->layoutHint;298 hint = 0.5 * canvasRect.width() * m_data->layoutHint; 300 299 else 301 hint = 0.5 * canvasRect.height() * d_data->layoutHint;300 hint = 0.5 * canvasRect.height() * m_data->layoutHint; 302 301 303 302 break; … … 305 304 case FixedSampleSize: 306 305 { 307 hint = 0.5 * d_data->layoutHint;306 hint = 0.5 * m_data->layoutHint; 308 307 break; 309 308 } … … 324 323 if ( layoutPolicy() == ScaleSamplesToAxes ) 325 324 { 326 sampleWidthS = q Max( d_data->layoutHint, 0.0 );325 sampleWidthS = qwtMaxF( m_data->layoutHint, 0.0 ); 327 326 } 328 327 else 329 328 { 330 spacing = d_data->spacing;329 spacing = m_data->spacing; 331 330 332 331 if ( numSamples > 1 ) … … 352 351 353 352 hint = 0.5 * sampleWidthP; 354 hint += qMax( d_data->margin, 0 );353 hint += qMax( m_data->margin, 0 ); 355 354 } 356 355 } -
trunk/BNC/qwt/qwt_plot_abstract_barchart.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_seriesitem.h" 15 #include "qwt_series_data.h"16 15 17 16 /*! 18 \brief Abstract base class for bar chart items 17 \brief Abstract base class for bar chart items 19 18 20 In opposite to almost all other plot items bar charts can't be 21 displayed inside of their bounding rectangle and need a special 22 API how to calculate the width of the bars and how they affect 23 the layout of the attached plot. 19 In opposite to almost all other plot items bar charts can't be 20 displayed inside of their bounding rectangle and need a special 21 API how to calculate the width of the bars and how they affect 22 the layout of the attached plot. 24 23 */ 25 class QWT_EXPORT QwtPlotAbstractBarChart: public QwtPlotSeriesItem 24 class QWT_EXPORT QwtPlotAbstractBarChart : public QwtPlotSeriesItem 26 25 { 27 public: 26 public: 28 27 /*! 29 28 \brief Mode how to calculate the bar width … … 34 33 { 35 34 /*! 36 The sample width is calculated by dividing the bounding rectangle 37 by the number of samples. The layoutHint() is used as a minimum width 38 in paint device coordinates. 35 The sample width is calculated by dividing the bounding rectangle 36 by the number of samples. The layoutHint() is used as a minimum width 37 in paint device coordinates. 39 38 40 \sa boundingRectangle() 39 \sa boundingRectangle() 41 40 */ 42 41 AutoAdjustSamples, 43 42 44 43 /*! 45 layoutHint() defines an interval in axis coordinates 44 layoutHint() defines an interval in axis coordinates 46 45 */ 47 46 ScaleSamplesToAxes, 48 47 49 48 /*! 50 The bar width is calculated by multiplying layoutHint() 51 with the height or width of the canvas. 49 The bar width is calculated by multiplying layoutHint() 50 with the height or width of the canvas. 52 51 53 \sa boundingRectangle() 52 \sa boundingRectangle() 54 53 */ 55 54 ScaleSampleToCanvas, 56 55 57 56 /*! 58 layoutHint() defines a fixed width in paint device coordinates. 57 layoutHint() defines a fixed width in paint device coordinates. 59 58 */ 60 59 FixedSampleSize 61 60 }; 62 61 63 explicit QwtPlotAbstractBarChart( const QwtText &title );62 explicit QwtPlotAbstractBarChart( const QwtText& title ); 64 63 virtual ~QwtPlotAbstractBarChart(); 65 64 … … 80 79 81 80 virtual void getCanvasMarginHint( 82 const QwtScaleMap &xMap, const QwtScaleMap&yMap,83 const QRectF &canvasRect,84 double &left, double &top, double &right, double&bottom) const;81 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 82 const QRectF& canvasRect, double& left, double& top, 83 double& right, double& bottom) const QWT_OVERRIDE; 85 84 86 85 87 protected: 88 double sampleWidth( const QwtScaleMap &map,86 protected: 87 double sampleWidth( const QwtScaleMap& map, 89 88 double canvasSize, double boundingSize, 90 89 double value ) const; 91 90 92 private: 91 private: 93 92 class PrivateData; 94 PrivateData *d_data;93 PrivateData* m_data; 95 94 }; 96 95 -
trunk/BNC/qwt/qwt_plot_axis.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot.h" 11 #include "qwt_math.h"12 11 #include "qwt_scale_widget.h" 12 #include "qwt_scale_map.h" 13 13 #include "qwt_scale_div.h" 14 14 #include "qwt_scale_engine.h" 15 16 class QwtPlot::AxisData 17 { 18 public: 19 bool isEnabled; 20 bool doAutoScale; 21 22 double minValue; 23 double maxValue; 24 double stepSize; 25 26 int maxMajor; 27 int maxMinor; 28 29 bool isValid; 30 31 QwtScaleDiv scaleDiv; 32 QwtScaleEngine *scaleEngine; 33 QwtScaleWidget *scaleWidget; 15 #include "qwt_interval.h" 16 17 namespace 18 { 19 class AxisData 20 { 21 public: 22 AxisData() 23 : isVisible( true ) 24 , doAutoScale( true ) 25 , minValue( 0.0 ) 26 , maxValue( 1000.0 ) 27 , stepSize( 0.0 ) 28 , maxMajor( 8 ) 29 , maxMinor( 5 ) 30 , isValid( false ) 31 , scaleEngine( new QwtLinearScaleEngine() ) 32 , scaleWidget( NULL ) 33 { 34 } 35 36 ~AxisData() 37 { 38 delete scaleEngine; 39 } 40 41 void initWidget( QwtScaleDraw::Alignment align, const QString& name, QwtPlot* plot ) 42 { 43 scaleWidget = new QwtScaleWidget( align, plot ); 44 scaleWidget->setObjectName( name ); 45 46 #if 1 47 // better find the font sizes from the application font 48 const QFont fscl( plot->fontInfo().family(), 10 ); 49 const QFont fttl( plot->fontInfo().family(), 12, QFont::Bold ); 50 #endif 51 52 scaleWidget->setTransformation( scaleEngine->transformation() ); 53 54 scaleWidget->setFont( fscl ); 55 scaleWidget->setMargin( 2 ); 56 57 QwtText text = scaleWidget->title(); 58 text.setFont( fttl ); 59 scaleWidget->setTitle( text ); 60 } 61 62 bool isVisible; 63 bool doAutoScale; 64 65 double minValue; 66 double maxValue; 67 double stepSize; 68 69 int maxMajor; 70 int maxMinor; 71 72 bool isValid; 73 74 QwtScaleDiv scaleDiv; 75 QwtScaleEngine* scaleEngine; 76 QwtScaleWidget* scaleWidget; 77 }; 78 } 79 80 class QwtPlot::ScaleData 81 { 82 public: 83 ScaleData( QwtPlot* plot ) 84 { 85 using namespace QwtAxis; 86 87 m_axisData[YLeft].initWidget( QwtScaleDraw::LeftScale, "QwtPlotAxisYLeft", plot ); 88 m_axisData[YRight].initWidget( QwtScaleDraw::RightScale, "QwtPlotAxisYRight", plot ); 89 m_axisData[XTop].initWidget( QwtScaleDraw::TopScale, "QwtPlotAxisXTop", plot ); 90 m_axisData[XBottom].initWidget( QwtScaleDraw::BottomScale, "QwtPlotAxisXBottom", plot ); 91 } 92 93 inline AxisData& axisData( QwtAxisId axisId ) 94 { 95 return m_axisData[ axisId ]; 96 } 97 98 inline const AxisData& axisData( QwtAxisId axisId ) const 99 { 100 return m_axisData[ axisId ]; 101 } 102 103 private: 104 AxisData m_axisData[ QwtAxis::AxisPositions ]; 34 105 }; 35 106 36 //! Initialize axes37 107 void QwtPlot::initAxesData() 38 108 { 39 int axisId; 40 41 for ( axisId = 0; axisId < axisCnt; axisId++ ) 42 d_axisData[axisId] = new AxisData; 43 44 d_axisData[yLeft]->scaleWidget = 45 new QwtScaleWidget( QwtScaleDraw::LeftScale, this ); 46 d_axisData[yRight]->scaleWidget = 47 new QwtScaleWidget( QwtScaleDraw::RightScale, this ); 48 d_axisData[xTop]->scaleWidget = 49 new QwtScaleWidget( QwtScaleDraw::TopScale, this ); 50 d_axisData[xBottom]->scaleWidget = 51 new QwtScaleWidget( QwtScaleDraw::BottomScale, this ); 52 53 d_axisData[yLeft]->scaleWidget->setObjectName( "QwtPlotAxisYLeft" ); 54 d_axisData[yRight]->scaleWidget->setObjectName( "QwtPlotAxisYRight" ); 55 d_axisData[xTop]->scaleWidget->setObjectName( "QwtPlotAxisXTop" ); 56 d_axisData[xBottom]->scaleWidget->setObjectName( "QwtPlotAxisXBottom" ); 57 58 #if 1 59 // better find the font sizes from the application font 60 QFont fscl( fontInfo().family(), 10 ); 61 QFont fttl( fontInfo().family(), 12, QFont::Bold ); 62 #endif 63 64 for ( axisId = 0; axisId < axisCnt; axisId++ ) 65 { 66 AxisData &d = *d_axisData[axisId]; 67 68 d.scaleEngine = new QwtLinearScaleEngine; 69 70 d.scaleWidget->setTransformation( 71 d.scaleEngine->transformation() ); 72 73 d.scaleWidget->setFont( fscl ); 74 d.scaleWidget->setMargin( 2 ); 75 76 QwtText text = d.scaleWidget->title(); 77 text.setFont( fttl ); 78 d.scaleWidget->setTitle( text ); 79 80 d.doAutoScale = true; 81 82 d.minValue = 0.0; 83 d.maxValue = 1000.0; 84 d.stepSize = 0.0; 85 86 d.maxMinor = 5; 87 d.maxMajor = 8; 88 89 90 d.isValid = false; 91 } 92 93 d_axisData[yLeft]->isEnabled = true; 94 d_axisData[yRight]->isEnabled = false; 95 d_axisData[xBottom]->isEnabled = true; 96 d_axisData[xTop]->isEnabled = false; 109 m_scaleData = new ScaleData( this ); 110 111 m_scaleData->axisData( QwtAxis::YRight ).isVisible = false; 112 m_scaleData->axisData( QwtAxis::XTop ).isVisible = false; 97 113 } 98 114 99 115 void QwtPlot::deleteAxesData() 100 116 { 101 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 102 { 103 delete d_axisData[axisId]->scaleEngine; 104 delete d_axisData[axisId]; 105 d_axisData[axisId] = NULL; 106 } 107 } 108 109 /*! 110 \return Scale widget of the specified axis, or NULL if axisId is invalid. 111 \param axisId Axis index 112 */ 113 const QwtScaleWidget *QwtPlot::axisWidget( int axisId ) const 114 { 115 if ( axisValid( axisId ) ) 116 return d_axisData[axisId]->scaleWidget; 117 delete m_scaleData; 118 m_scaleData = NULL; 119 } 120 121 /*! 122 Checks if an axis is valid 123 124 \param axisId axis 125 \return \c true if the specified axis exists, otherwise \c false 126 127 \note This method is equivalent to QwtAxis::isValid( axisId ) and simply checks 128 if axisId is one of the values of QwtAxis::Position. It is a placeholder 129 for future releases, where it will be possible to have a customizable number 130 of axes ( multiaxes branch ) at each side. 131 */ 132 bool QwtPlot::isAxisValid( QwtAxisId axisId ) const 133 { 134 return QwtAxis::isValid( axisId ); 135 } 136 137 /*! 138 \return Scale widget of the specified axis, or NULL if axisId is invalid. 139 \param axisId Axis 140 */ 141 const QwtScaleWidget* QwtPlot::axisWidget( QwtAxisId axisId ) const 142 { 143 if ( isAxisValid( axisId ) ) 144 return m_scaleData->axisData( axisId ).scaleWidget; 117 145 118 146 return NULL; … … 120 148 121 149 /*! 122 \return Scale widget of the specified axis, or NULL if axisId is invalid. 123 \param axisId Axis index124 */ 125 QwtScaleWidget *QwtPlot::axisWidget(intaxisId )126 { 127 if ( axisValid( axisId ) )128 return d_axisData[axisId]->scaleWidget;150 \return Scale widget of the specified axis, or NULL if axisId is invalid. 151 \param axisId Axis 152 */ 153 QwtScaleWidget* QwtPlot::axisWidget( QwtAxisId axisId ) 154 { 155 if ( isAxisValid( axisId ) ) 156 return m_scaleData->axisData( axisId ).scaleWidget; 129 157 130 158 return NULL; … … 132 160 133 161 /*! 134 Change the scale engine for an axis 135 136 \param axisId Axis index137 \param scaleEngine Scale engine 138 139 \sa axisScaleEngine() 140 */ 141 void QwtPlot::setAxisScaleEngine( intaxisId, QwtScaleEngine*scaleEngine )142 { 143 if ( axisValid( axisId ) && scaleEngine != NULL )144 { 145 AxisData &d = *d_axisData[axisId];162 Change the scale engine for an axis 163 164 \param axisId Axis 165 \param scaleEngine Scale engine 166 167 \sa axisScaleEngine() 168 */ 169 void QwtPlot::setAxisScaleEngine( QwtAxisId axisId, QwtScaleEngine* scaleEngine ) 170 { 171 if ( isAxisValid( axisId ) && scaleEngine != NULL ) 172 { 173 AxisData& d = m_scaleData->axisData( axisId ); 146 174 147 175 delete d.scaleEngine; 148 176 d.scaleEngine = scaleEngine; 149 177 150 d_axisData[axisId]->scaleWidget->setTransformation( 151 scaleEngine->transformation() ); 178 d.scaleWidget->setTransformation( scaleEngine->transformation() ); 152 179 153 180 d.isValid = false; … … 158 185 159 186 /*! 160 \param axisId Axis index161 \return Scale engine for a specific axis 162 */ 163 QwtScaleEngine *QwtPlot::axisScaleEngine(intaxisId )164 { 165 if ( axisValid( axisId ) )166 return d_axisData[axisId]->scaleEngine;187 \param axisId Axis 188 \return Scale engine for a specific axis 189 */ 190 QwtScaleEngine* QwtPlot::axisScaleEngine( QwtAxisId axisId ) 191 { 192 if ( isAxisValid( axisId ) ) 193 return m_scaleData->axisData( axisId ).scaleEngine; 167 194 else 168 195 return NULL; … … 170 197 171 198 /*! 172 \param axisId Axis index173 \return Scale engine for a specific axis 174 */ 175 const QwtScaleEngine *QwtPlot::axisScaleEngine(intaxisId ) const176 { 177 if ( axisValid( axisId ) )178 return d_axisData[axisId]->scaleEngine;199 \param axisId Axis 200 \return Scale engine for a specific axis 201 */ 202 const QwtScaleEngine* QwtPlot::axisScaleEngine( QwtAxisId axisId ) const 203 { 204 if ( isAxisValid( axisId ) ) 205 return m_scaleData->axisData( axisId ).scaleEngine; 179 206 else 180 207 return NULL; 181 208 } 182 209 /*! 183 \return \c True, if autoscaling is enabled 184 \param axisId Axis index185 */ 186 bool QwtPlot::axisAutoScale( intaxisId ) const187 { 188 if ( axisValid( axisId ) )189 return d_axisData[axisId]->doAutoScale;210 \return \c True, if autoscaling is enabled 211 \param axisId Axis 212 */ 213 bool QwtPlot::axisAutoScale( QwtAxisId axisId ) const 214 { 215 if ( isAxisValid( axisId ) ) 216 return m_scaleData->axisData( axisId ).doAutoScale; 190 217 else 191 218 return false; … … 193 220 194 221 /*! 195 \return \c True, if a specified axis is enabled196 \param axisId Axis index197 */ 198 bool QwtPlot:: axisEnabled( intaxisId ) const199 { 200 if ( axisValid( axisId ) )201 return d_axisData[axisId]->isEnabled;222 \return \c True, if a specified axis is visible 223 \param axisId Axis 224 */ 225 bool QwtPlot::isAxisVisible( QwtAxisId axisId ) const 226 { 227 if ( isAxisValid( axisId ) ) 228 return m_scaleData->axisData( axisId ).isVisible; 202 229 else 203 230 return false; … … 205 232 206 233 /*! 207 \return The font of the scale labels for a specified axis 208 \param axisId Axis index209 */ 210 QFont QwtPlot::axisFont( intaxisId ) const211 { 212 if ( axisValid( axisId ) )234 \return The font of the scale labels for a specified axis 235 \param axisId Axis 236 */ 237 QFont QwtPlot::axisFont( QwtAxisId axisId ) const 238 { 239 if ( isAxisValid( axisId ) ) 213 240 return axisWidget( axisId )->font(); 214 241 else … … 218 245 219 246 /*! 220 \return The maximum number of major ticks for a specified axis 221 \param axisId Axis index222 \sa setAxisMaxMajor(), QwtScaleEngine::divideScale() 223 */ 224 int QwtPlot::axisMaxMajor( intaxisId ) const225 { 226 if ( axisValid( axisId ) )227 return d_axisData[axisId]->maxMajor;247 \return The maximum number of major ticks for a specified axis 248 \param axisId Axis 249 \sa setAxisMaxMajor(), QwtScaleEngine::divideScale() 250 */ 251 int QwtPlot::axisMaxMajor( QwtAxisId axisId ) const 252 { 253 if ( isAxisValid( axisId ) ) 254 return m_scaleData->axisData( axisId ).maxMajor; 228 255 else 229 256 return 0; … … 231 258 232 259 /*! 233 \return the maximum number of minor ticks for a specified axis 234 \param axisId Axis index235 \sa setAxisMaxMinor(), QwtScaleEngine::divideScale() 236 */ 237 int QwtPlot::axisMaxMinor( intaxisId ) const238 { 239 if ( axisValid( axisId ) )240 return d_axisData[axisId]->maxMinor;260 \return the maximum number of minor ticks for a specified axis 261 \param axisId Axis 262 \sa setAxisMaxMinor(), QwtScaleEngine::divideScale() 263 */ 264 int QwtPlot::axisMaxMinor( QwtAxisId axisId ) const 265 { 266 if ( isAxisValid( axisId ) ) 267 return m_scaleData->axisData( axisId ).maxMinor; 241 268 else 242 269 return 0; … … 244 271 245 272 /*! 246 \brief Return the scale division of a specified axis 247 248 axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound() 249 are the current limits of the axis scale. 250 251 \param axisId Axis index 252 \return Scale division 253 254 \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale() 255 */ 256 const QwtScaleDiv &QwtPlot::axisScaleDiv( int axisId ) const 257 { 258 return d_axisData[axisId]->scaleDiv; 259 } 260 261 /*! 262 \brief Return the scale draw of a specified axis 263 264 \param axisId Axis index 265 \return Specified scaleDraw for axis, or NULL if axis is invalid. 266 */ 267 const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const 268 { 269 if ( !axisValid( axisId ) ) 273 \brief Return the scale division of a specified axis 274 275 axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound() 276 are the current limits of the axis scale. 277 278 \param axisId Axis 279 \return Scale division 280 281 \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale() 282 */ 283 const QwtScaleDiv& QwtPlot::axisScaleDiv( QwtAxisId axisId ) const 284 { 285 if ( isAxisValid( axisId ) ) 286 return m_scaleData->axisData( axisId ).scaleDiv; 287 288 static QwtScaleDiv dummyScaleDiv; 289 return dummyScaleDiv; 290 } 291 292 /*! 293 \brief Return the scale draw of a specified axis 294 295 \param axisId Axis 296 \return Specified scaleDraw for axis, or NULL if axis is invalid. 297 */ 298 const QwtScaleDraw* QwtPlot::axisScaleDraw( QwtAxisId axisId ) const 299 { 300 if ( !isAxisValid( axisId ) ) 270 301 return NULL; 271 302 … … 274 305 275 306 /*! 276 \brief Return the scale draw of a specified axis 277 278 \param axisId Axis index279 \return Specified scaleDraw for axis, or NULL if axis is invalid. 280 */ 281 QwtScaleDraw *QwtPlot::axisScaleDraw(intaxisId )282 { 283 if ( ! axisValid( axisId ) )307 \brief Return the scale draw of a specified axis 308 309 \param axisId Axis 310 \return Specified scaleDraw for axis, or NULL if axis is invalid. 311 */ 312 QwtScaleDraw* QwtPlot::axisScaleDraw( QwtAxisId axisId ) 313 { 314 if ( !isAxisValid( axisId ) ) 284 315 return NULL; 285 316 … … 288 319 289 320 /*! 290 \brief Return the step size parameter that has been set in setAxisScale. 291 292 This doesn't need to be the step size of the current scale. 293 294 \param axisId Axis index295 \return step size parameter value 321 \brief Return the step size parameter that has been set in setAxisScale. 322 323 This doesn't need to be the step size of the current scale. 324 325 \param axisId Axis 326 \return step size parameter value 296 327 297 328 \sa setAxisScale(), QwtScaleEngine::divideScale() 298 */ 299 double QwtPlot::axisStepSize( intaxisId ) const300 { 301 if ( ! axisValid( axisId ) )329 */ 330 double QwtPlot::axisStepSize( QwtAxisId axisId ) const 331 { 332 if ( !isAxisValid( axisId ) ) 302 333 return 0; 303 334 304 return d_axisData[axisId]->stepSize;305 } 306 307 /*! 308 \brief Return the current interval of the specified axis 309 310 This is only a convenience function for axisScaleDiv( axisId )->interval(); 311 312 \param axisId Axis index313 \return Scale interval 314 315 \sa QwtScaleDiv, axisScaleDiv() 316 */ 317 QwtInterval QwtPlot::axisInterval( intaxisId ) const318 { 319 if ( ! axisValid( axisId ) )335 return m_scaleData->axisData( axisId ).stepSize; 336 } 337 338 /*! 339 \brief Return the current interval of the specified axis 340 341 This is only a convenience function for axisScaleDiv( axisId )->interval(); 342 343 \param axisId Axis 344 \return Scale interval 345 346 \sa QwtScaleDiv, axisScaleDiv() 347 */ 348 QwtInterval QwtPlot::axisInterval( QwtAxisId axisId ) const 349 { 350 if ( !isAxisValid( axisId ) ) 320 351 return QwtInterval(); 321 352 322 return d_axisData[axisId]->scaleDiv.interval();323 } 324 325 /*! 326 \return Title of a specified axis 327 \param axisId Axis index328 */ 329 QwtText QwtPlot::axisTitle( intaxisId ) const330 { 331 if ( axisValid( axisId ) )353 return m_scaleData->axisData( axisId ).scaleDiv.interval(); 354 } 355 356 /*! 357 \return Title of a specified axis 358 \param axisId Axis 359 */ 360 QwtText QwtPlot::axisTitle( QwtAxisId axisId ) const 361 { 362 if ( isAxisValid( axisId ) ) 332 363 return axisWidget( axisId )->title(); 333 364 else … … 336 367 337 368 /*! 338 \brief Enable or disable a specified axis 339 340 When an axis is disabled, this only means that it is not 341 visible on the screen. Curves, markers and can be attached 342 to disabled axes, and transformation of screen coordinates 343 into values works as normal. 344 345 Only xBottom and yLeft are enabled by default. 346 347 \param axisId Axis index 348 \param tf \c true (enabled) or \c false (disabled) 349 */ 350 void QwtPlot::enableAxis( int axisId, bool tf ) 351 { 352 if ( axisValid( axisId ) && tf != d_axisData[axisId]->isEnabled ) 353 { 354 d_axisData[axisId]->isEnabled = tf; 369 \brief Hide or show a specified axis 370 371 Curves, markers and other items can be attached 372 to hidden axes, and transformation of screen coordinates 373 into values works as normal. 374 375 Only QwtAxis::XBottom and QwtAxis::YLeft are enabled by default. 376 377 \param axisId Axis 378 \param on \c true (visible) or \c false (hidden) 379 */ 380 void QwtPlot::setAxisVisible( QwtAxisId axisId, bool on ) 381 { 382 if ( isAxisValid( axisId ) && on != m_scaleData->axisData( axisId ).isVisible ) 383 { 384 m_scaleData->axisData( axisId ).isVisible = on; 355 385 updateLayout(); 356 386 } … … 358 388 359 389 /*! 360 Transform the x or y coordinate of a position in the 361 drawing region into a value. 362 363 \param axisId Axis index364 \param pos position 365 366 \return Position as axis coordinate 367 368 \warning The position can be an x or a y coordinate, 390 Transform the x or y coordinate of a position in the 391 drawing region into a value. 392 393 \param axisId Axis 394 \param pos position 395 396 \return Position as axis coordinate 397 398 \warning The position can be an x or a y coordinate, 369 399 depending on the specified axis. 370 */ 371 double QwtPlot::invTransform( intaxisId,intpos ) const372 { 373 if ( axisValid( axisId ) )400 */ 401 double QwtPlot::invTransform( QwtAxisId axisId, double pos ) const 402 { 403 if ( isAxisValid( axisId ) ) 374 404 return( canvasMap( axisId ).invTransform( pos ) ); 375 405 else … … 379 409 380 410 /*! 381 \brief Transform a value into a coordinate in the plotting region 382 383 \param axisId Axis index384 \param value value 385 \return X or Y coordinate in the plotting region corresponding 411 \brief Transform a value into a coordinate in the plotting region 412 413 \param axisId Axis 414 \param value value 415 \return X or Y coordinate in the plotting region corresponding 386 416 to the value. 387 */ 388 double QwtPlot::transform( intaxisId, double value ) const389 { 390 if ( axisValid( axisId ) )417 */ 418 double QwtPlot::transform( QwtAxisId axisId, double value ) const 419 { 420 if ( isAxisValid( axisId ) ) 391 421 return( canvasMap( axisId ).transform( value ) ); 392 422 else … … 395 425 396 426 /*! 397 \brief Change the font of an axis 398 399 \param axisId Axis index400 \param font Font 401 \warning This function changes the font of the tick labels, 427 \brief Change the font of an axis 428 429 \param axisId Axis 430 \param font Font 431 \warning This function changes the font of the tick labels, 402 432 not of the axis title. 403 */ 404 void QwtPlot::setAxisFont( intaxisId, const QFont&font )405 { 406 if ( axisValid( axisId ) )433 */ 434 void QwtPlot::setAxisFont( QwtAxisId axisId, const QFont& font ) 435 { 436 if ( isAxisValid( axisId ) ) 407 437 axisWidget( axisId )->setFont( font ); 408 438 } 409 439 410 440 /*! 411 \brief Enable autoscaling for a specified axis 412 413 This member function is used to switch back to autoscaling mode 414 after a fixed scale has been set. Autoscaling is enabled by default. 415 416 \param axisId Axis index417 \param on On/Off 418 \sa setAxisScale(), setAxisScaleDiv(), updateAxes() 419 420 \note The autoscaling flag has no effect until updateAxes() is executed 441 \brief Enable autoscaling for a specified axis 442 443 This member function is used to switch back to autoscaling mode 444 after a fixed scale has been set. Autoscaling is enabled by default. 445 446 \param axisId Axis 447 \param on On/Off 448 \sa setAxisScale(), setAxisScaleDiv(), updateAxes() 449 450 \note The autoscaling flag has no effect until updateAxes() is executed 421 451 ( called by replot() ). 422 */ 423 void QwtPlot::setAxisAutoScale( intaxisId, bool on )424 { 425 if ( axisValid( axisId ) && (d_axisData[axisId]->doAutoScale != on ) )426 { 427 d_axisData[axisId]->doAutoScale = on;452 */ 453 void QwtPlot::setAxisAutoScale( QwtAxisId axisId, bool on ) 454 { 455 if ( isAxisValid( axisId ) && ( m_scaleData->axisData( axisId ).doAutoScale != on ) ) 456 { 457 m_scaleData->axisData( axisId ).doAutoScale = on; 428 458 autoRefresh(); 429 459 } … … 431 461 432 462 /*! 433 \brief Disable autoscaling and specify a fixed scale for a selected axis. 434 435 In updateAxes() the scale engine calculates a scale division from the 436 specified parameters, that will be assigned to the scale widget. So 437 updates of the scale widget usually happen delayed with the next replot. 438 439 \param axisId Axis index440 \param min Minimum of the scale 441 \param max Maximum of the scale 442 \param stepSize Major step size. If <code>step == 0</code>, the step size is 463 \brief Disable autoscaling and specify a fixed scale for a selected axis. 464 465 In updateAxes() the scale engine calculates a scale division from the 466 specified parameters, that will be assigned to the scale widget. So 467 updates of the scale widget usually happen delayed with the next replot. 468 469 \param axisId Axis 470 \param min Minimum of the scale 471 \param max Maximum of the scale 472 \param stepSize Major step size. If <code>step == 0</code>, the step size is 443 473 calculated automatically using the maxMajor setting. 444 474 445 \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale() 446 */ 447 void QwtPlot::setAxisScale( intaxisId, double min, double max, double stepSize )448 { 449 if ( axisValid( axisId ) )450 { 451 AxisData &d = *d_axisData[axisId];475 \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale() 476 */ 477 void QwtPlot::setAxisScale( QwtAxisId axisId, double min, double max, double stepSize ) 478 { 479 if ( isAxisValid( axisId ) ) 480 { 481 AxisData& d = m_scaleData->axisData( axisId ); 452 482 453 483 d.doAutoScale = false; … … 463 493 464 494 /*! 465 \brief Disable autoscaling and specify a fixed scale for a selected axis. 466 467 The scale division will be stored locally only until the next call 468 of updateAxes(). So updates of the scale widget usually happen delayed with 469 the next replot. 470 471 \param axisId Axis index472 \param scaleDiv Scale division 473 474 \sa setAxisScale(), setAxisAutoScale() 475 */ 476 void QwtPlot::setAxisScaleDiv( intaxisId, const QwtScaleDiv&scaleDiv )477 { 478 if ( axisValid( axisId ) )479 { 480 AxisData &d = *d_axisData[axisId];495 \brief Disable autoscaling and specify a fixed scale for a selected axis. 496 497 The scale division will be stored locally only until the next call 498 of updateAxes(). So updates of the scale widget usually happen delayed with 499 the next replot. 500 501 \param axisId Axis 502 \param scaleDiv Scale division 503 504 \sa setAxisScale(), setAxisAutoScale() 505 */ 506 void QwtPlot::setAxisScaleDiv( QwtAxisId axisId, const QwtScaleDiv& scaleDiv ) 507 { 508 if ( isAxisValid( axisId ) ) 509 { 510 AxisData& d = m_scaleData->axisData( axisId ); 481 511 482 512 d.doAutoScale = false; … … 489 519 490 520 /*! 491 \brief Set a scale draw 492 493 \param axisId Axis index494 \param scaleDraw Object responsible for drawing scales. 495 496 By passing scaleDraw it is possible to extend QwtScaleDraw 497 functionality and let it take place in QwtPlot. Please note 498 that scaleDraw has to be created with new and will be deleted 499 by the corresponding QwtScale member ( like a child object ). 500 501 \sa QwtScaleDraw, QwtScaleWidget 502 \warning The attributes of scaleDraw will be overwritten by those of the 521 \brief Set a scale draw 522 523 \param axisId Axis 524 \param scaleDraw Object responsible for drawing scales. 525 526 By passing scaleDraw it is possible to extend QwtScaleDraw 527 functionality and let it take place in QwtPlot. Please note 528 that scaleDraw has to be created with new and will be deleted 529 by the corresponding QwtScale member ( like a child object ). 530 531 \sa QwtScaleDraw, QwtScaleWidget 532 \warning The attributes of scaleDraw will be overwritten by those of the 503 533 previous QwtScaleDraw. 504 */ 505 506 void QwtPlot::setAxisScaleDraw( intaxisId, QwtScaleDraw*scaleDraw )507 { 508 if ( axisValid( axisId ) )534 */ 535 536 void QwtPlot::setAxisScaleDraw( QwtAxisId axisId, QwtScaleDraw* scaleDraw ) 537 { 538 if ( isAxisValid( axisId ) ) 509 539 { 510 540 axisWidget( axisId )->setScaleDraw( scaleDraw ); … … 514 544 515 545 /*! 516 Change the alignment of the tick labels 517 518 \param axisId Axis index519 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 520 521 \sa QwtScaleDraw::setLabelAlignment() 522 */ 523 void QwtPlot::setAxisLabelAlignment( intaxisId, Qt::Alignment alignment )524 { 525 if ( axisValid( axisId ) )546 Change the alignment of the tick labels 547 548 \param axisId Axis 549 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 550 551 \sa QwtScaleDraw::setLabelAlignment() 552 */ 553 void QwtPlot::setAxisLabelAlignment( QwtAxisId axisId, Qt::Alignment alignment ) 554 { 555 if ( isAxisValid( axisId ) ) 526 556 axisWidget( axisId )->setLabelAlignment( alignment ); 527 557 } 528 558 529 559 /*! 530 Rotate all tick labels 531 532 \param axisId Axis index533 \param rotation Angle in degrees. When changing the label rotation, 560 Rotate all tick labels 561 562 \param axisId Axis 563 \param rotation Angle in degrees. When changing the label rotation, 534 564 the label alignment might be adjusted too. 535 565 536 \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment() 537 */ 538 void QwtPlot::setAxisLabelRotation( intaxisId, double rotation )539 { 540 if ( axisValid( axisId ) )566 \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment() 567 */ 568 void QwtPlot::setAxisLabelRotation( QwtAxisId axisId, double rotation ) 569 { 570 if ( isAxisValid( axisId ) ) 541 571 axisWidget( axisId )->setLabelRotation( rotation ); 542 572 } 543 573 544 574 /*! 545 Set the maximum number of minor scale intervals for a specified axis 546 547 \param axisId Axis index548 \param maxMinor Maximum number of minor steps 549 550 \sa axisMaxMinor() 551 */ 552 void QwtPlot::setAxisMaxMinor( intaxisId, int maxMinor )553 { 554 if ( axisValid( axisId ) )575 Set the maximum number of minor scale intervals for a specified axis 576 577 \param axisId Axis 578 \param maxMinor Maximum number of minor steps 579 580 \sa axisMaxMinor() 581 */ 582 void QwtPlot::setAxisMaxMinor( QwtAxisId axisId, int maxMinor ) 583 { 584 if ( isAxisValid( axisId ) ) 555 585 { 556 586 maxMinor = qBound( 0, maxMinor, 100 ); 557 587 558 AxisData &d = *d_axisData[axisId];588 AxisData& d = m_scaleData->axisData( axisId ); 559 589 if ( maxMinor != d.maxMinor ) 560 590 { … … 567 597 568 598 /*! 569 Set the maximum number of major scale intervals for a specified axis 570 571 \param axisId Axis index572 \param maxMajor Maximum number of major steps 573 574 \sa axisMaxMajor() 575 */ 576 void QwtPlot::setAxisMaxMajor( intaxisId, int maxMajor )577 { 578 if ( axisValid( axisId ) )599 Set the maximum number of major scale intervals for a specified axis 600 601 \param axisId Axis 602 \param maxMajor Maximum number of major steps 603 604 \sa axisMaxMajor() 605 */ 606 void QwtPlot::setAxisMaxMajor( QwtAxisId axisId, int maxMajor ) 607 { 608 if ( isAxisValid( axisId ) ) 579 609 { 580 610 maxMajor = qBound( 1, maxMajor, 10000 ); 581 611 582 AxisData &d = *d_axisData[axisId];612 AxisData& d = m_scaleData->axisData( axisId ); 583 613 if ( maxMajor != d.maxMajor ) 584 614 { … … 591 621 592 622 /*! 593 \brief Change the title of a specified axis 594 595 \param axisId Axis index596 \param title axis title 597 */ 598 void QwtPlot::setAxisTitle( intaxisId, const QString&title )599 { 600 if ( axisValid( axisId ) )623 \brief Change the title of a specified axis 624 625 \param axisId Axis 626 \param title axis title 627 */ 628 void QwtPlot::setAxisTitle( QwtAxisId axisId, const QString& title ) 629 { 630 if ( isAxisValid( axisId ) ) 601 631 axisWidget( axisId )->setTitle( title ); 602 632 } 603 633 604 634 /*! 605 \brief Change the title of a specified axis 606 607 \param axisId Axis index608 \param title Axis title 609 */ 610 void QwtPlot::setAxisTitle( intaxisId, const QwtText&title )611 { 612 if ( axisValid( axisId ) )635 \brief Change the title of a specified axis 636 637 \param axisId Axis 638 \param title Axis title 639 */ 640 void QwtPlot::setAxisTitle( QwtAxisId axisId, const QwtText& title ) 641 { 642 if ( isAxisValid( axisId ) ) 613 643 axisWidget( axisId )->setTitle( title ); 614 644 } 615 645 616 646 /*! 617 \brief Rebuild the axes scales 618 619 In case of autoscaling the boundaries of a scale are calculated 620 from the bounding rectangles of all plot items, having the 621 QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ). 622 Then a scale division is calculated ( QwtScaleEngine::didvideScale() ) 623 and assigned to scale widget. 624 625 When the scale boundaries have been assigned with setAxisScale() a 626 scale division is calculated ( QwtScaleEngine::didvideScale() ) 627 for this interval and assigned to the scale widget. 628 629 When the scale has been set explicitly by setAxisScaleDiv() the 630 locally stored scale division gets assigned to the scale widget. 631 632 The scale widget indicates modifications by emitting a 633 QwtScaleWidget::scaleDivChanged() signal. 634 635 updateAxes() is usually called by replot(). 636 637 \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot() 647 \brief Rebuild the axes scales 648 649 In case of autoscaling the boundaries of a scale are calculated 650 from the bounding rectangles of all plot items, having the 651 QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ). 652 Then a scale division is calculated ( QwtScaleEngine::didvideScale() ) 653 and assigned to scale widget. 654 655 When the scale boundaries have been assigned with setAxisScale() a 656 scale division is calculated ( QwtScaleEngine::didvideScale() ) 657 for this interval and assigned to the scale widget. 658 659 When the scale has been set explicitly by setAxisScaleDiv() the 660 locally stored scale division gets assigned to the scale widget. 661 662 The scale widget indicates modifications by emitting a 663 QwtScaleWidget::scaleDivChanged() signal. 664 665 updateAxes() is usually called by replot(). 666 667 \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot() 638 668 QwtPlotItem::boundingRect() 639 669 */ … … 643 673 // for all axes, where autoscaling is enabled 644 674 645 QwtInterval intv[axisCnt];675 QwtInterval boundingIntervals[QwtAxis::AxisPositions]; 646 676 647 677 const QwtPlotItemList& itmList = itemList(); … … 650 680 for ( it = itmList.begin(); it != itmList.end(); ++it ) 651 681 { 652 const QwtPlotItem *item = *it;682 const QwtPlotItem* item = *it; 653 683 654 684 if ( !item->testItemAttribute( QwtPlotItem::AutoScale ) ) … … 658 688 continue; 659 689 660 if ( axisAutoScale( item->xAxis() ) || axisAutoScale( item->yAxis() ) ) 690 const QwtAxisId xAxis = item->xAxis(); 691 const QwtAxisId yAxis = item->yAxis(); 692 693 if ( axisAutoScale( xAxis ) || axisAutoScale( yAxis ) ) 661 694 { 662 695 const QRectF rect = item->boundingRect(); 663 696 664 if ( rect.width() >= 0.0 ) 665 intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );666 667 if ( rect.height() >= 0.0 ) 668 intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() );697 if ( axisAutoScale( xAxis ) && rect.width() >= 0.0 ) 698 boundingIntervals[xAxis] |= QwtInterval( rect.left(), rect.right() ); 699 700 if ( axisAutoScale( yAxis ) && rect.height() >= 0.0 ) 701 boundingIntervals[yAxis] |= QwtInterval( rect.top(), rect.bottom() ); 669 702 } 670 703 } … … 672 705 // Adjust scales 673 706 674 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 675 { 676 AxisData &d = *d_axisData[axisId]; 677 678 double minValue = d.minValue; 679 double maxValue = d.maxValue; 680 double stepSize = d.stepSize; 681 682 if ( d.doAutoScale && intv[axisId].isValid() ) 707 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 708 { 683 709 { 684 d.isValid = false; 685 686 minValue = intv[axisId].minValue(); 687 maxValue = intv[axisId].maxValue(); 688 689 d.scaleEngine->autoScale( d.maxMajor, 690 minValue, maxValue, stepSize ); 710 const QwtAxisId axisId( axisPos ); 711 712 AxisData& d = m_scaleData->axisData( axisId ); 713 714 double minValue = d.minValue; 715 double maxValue = d.maxValue; 716 double stepSize = d.stepSize; 717 718 const QwtInterval& interval = boundingIntervals[axisId]; 719 720 if ( d.doAutoScale && interval.isValid() ) 721 { 722 d.isValid = false; 723 724 minValue = interval.minValue(); 725 maxValue = interval.maxValue(); 726 727 d.scaleEngine->autoScale( d.maxMajor, 728 minValue, maxValue, stepSize ); 729 } 730 if ( !d.isValid ) 731 { 732 d.scaleDiv = d.scaleEngine->divideScale( 733 minValue, maxValue, d.maxMajor, d.maxMinor, stepSize ); 734 d.isValid = true; 735 } 736 737 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 738 scaleWidget->setScaleDiv( d.scaleDiv ); 739 740 int startDist, endDist; 741 scaleWidget->getBorderDistHint( startDist, endDist ); 742 scaleWidget->setBorderDist( startDist, endDist ); 691 743 } 692 if ( !d.isValid )693 {694 d.scaleDiv = d.scaleEngine->divideScale(695 minValue, maxValue,696 d.maxMajor, d.maxMinor, stepSize );697 d.isValid = true;698 }699 700 QwtScaleWidget *scaleWidget = axisWidget( axisId );701 scaleWidget->setScaleDiv( d.scaleDiv );702 703 int startDist, endDist;704 scaleWidget->getBorderDistHint( startDist, endDist );705 scaleWidget->setBorderDist( startDist, endDist );706 744 } 707 745 708 746 for ( it = itmList.begin(); it != itmList.end(); ++it ) 709 747 { 710 QwtPlotItem *item = *it;748 QwtPlotItem* item = *it; 711 749 if ( item->testItemInterest( QwtPlotItem::ScaleInterest ) ) 712 750 { … … 716 754 } 717 755 } 718 -
trunk/BNC/qwt/qwt_plot_barchart.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_map.h" 12 12 #include "qwt_column_symbol.h" 13 #include "qwt_painter.h" 13 #include "qwt_text.h" 14 #include "qwt_graphic.h" 15 #include "qwt_legend_data.h" 16 14 17 #include <qpainter.h> 15 18 16 19 class QwtPlotBarChart::PrivateData 17 20 { 18 public: 19 PrivateData() :20 symbol( NULL ) ,21 legendMode( QwtPlotBarChart::LegendChartTitle ) 21 public: 22 PrivateData() 23 : symbol( NULL ) 24 , legendMode( QwtPlotBarChart::LegendChartTitle ) 22 25 { 23 26 } … … 28 31 } 29 32 30 QwtColumnSymbol *symbol;33 QwtColumnSymbol* symbol; 31 34 QwtPlotBarChart::LegendMode legendMode; 32 35 }; 33 36 34 37 /*! 35 Constructor 36 \param title Title of the curve 37 */ 38 QwtPlotBarChart::QwtPlotBarChart( const QwtText &title ):39 QwtPlotAbstractBarChart( title ) 38 Constructor 39 \param title Title of the curve 40 */ 41 QwtPlotBarChart::QwtPlotBarChart( const QwtText& title ) 42 : QwtPlotAbstractBarChart( title ) 40 43 { 41 44 init(); … … 43 46 44 47 /*! 45 Constructor 46 \param title Title of the curve 47 */ 48 QwtPlotBarChart::QwtPlotBarChart( const QString &title ):49 QwtPlotAbstractBarChart( QwtText( title ) ) 48 Constructor 49 \param title Title of the curve 50 */ 51 QwtPlotBarChart::QwtPlotBarChart( const QString& title ) 52 : QwtPlotAbstractBarChart( QwtText( title ) ) 50 53 { 51 54 init(); … … 55 58 QwtPlotBarChart::~QwtPlotBarChart() 56 59 { 57 delete d_data;60 delete m_data; 58 61 } 59 62 60 63 void QwtPlotBarChart::init() 61 64 { 62 d_data = new PrivateData;65 m_data = new PrivateData; 63 66 setData( new QwtPointSeriesData() ); 64 67 } … … 71 74 72 75 /*! 73 Initialize data with an array of points 74 75 \param samples Vector of points 76 \note QVector is implicitly shared 77 \note QPolygonF is derived from QVector<QPointF> 78 */ 76 Initialize data with an array of points 77 78 \param samples Vector of points 79 \note QVector is implicitly shared 80 \note QPolygonF is derived from QVector<QPointF> 81 */ 79 82 void QwtPlotBarChart::setSamples( 80 const QVector<QPointF > &samples )83 const QVector< QPointF >& samples ) 81 84 { 82 85 setData( new QwtPointSeriesData( samples ) ); … … 84 87 85 88 /*! 86 Initialize data with an array of doubles 87 88 The indices in the array are taken as x coordinate, 89 while the doubles are interpreted as y values. 90 91 \param samples Vector of y coordinates 92 \note QVector is implicitly shared 93 */ 89 Initialize data with an array of doubles 90 91 The indices in the array are taken as x coordinate, 92 while the doubles are interpreted as y values. 93 94 \param samples Vector of y coordinates 95 \note QVector is implicitly shared 96 */ 94 97 void QwtPlotBarChart::setSamples( 95 const QVector<double> &samples ) 96 { 97 QVector<QPointF> points; 98 const QVector< double >& samples ) 99 { 100 QVector< QPointF > points; 101 points.reserve( samples.size() ); 102 98 103 for ( int i = 0; i < samples.size(); i++ ) 99 104 points += QPointF( i, samples[ i ] ); … … 103 108 104 109 /*! 105 Assign a series of samples 106 107 setSamples() is just a wrapper for setData() without any additional 108 value - beside that it is easier to find for the developer. 109 110 \param data Data 111 \warning The item takes ownership of the data object, deleting 110 Assign a series of samples 111 112 setSamples() is just a wrapper for setData() without any additional 113 value - beside that it is easier to find for the developer. 114 115 \param data Data 116 \warning The item takes ownership of the data object, deleting 112 117 it when its not used anymore. 113 */ 114 void QwtPlotBarChart::setSamples( QwtSeriesData<QPointF > *data )118 */ 119 void QwtPlotBarChart::setSamples( QwtSeriesData< QPointF >* data ) 115 120 { 116 121 setData( data ); … … 118 123 119 124 /*! 120 \brief Assign a symbol 121 122 The bar chart will take the ownership of the symbol, hence the previously 123 set symbol will be delete by setting a new one. If \p symbol is 124 \c NULL no symbol will be drawn. 125 126 \param symbol Symbol 127 \sa symbol() 128 */ 129 void QwtPlotBarChart::setSymbol( QwtColumnSymbol *symbol )130 { 131 if ( symbol != d_data->symbol )132 { 133 delete d_data->symbol;134 d_data->symbol = symbol;125 \brief Assign a symbol 126 127 The bar chart will take the ownership of the symbol, hence the previously 128 set symbol will be delete by setting a new one. If \p symbol is 129 \c NULL no symbol will be drawn. 130 131 \param symbol Symbol 132 \sa symbol() 133 */ 134 void QwtPlotBarChart::setSymbol( QwtColumnSymbol* symbol ) 135 { 136 if ( symbol != m_data->symbol ) 137 { 138 delete m_data->symbol; 139 m_data->symbol = symbol; 135 140 136 141 legendChanged(); … … 140 145 141 146 /*! 142 \return Current symbol or NULL, when no symbol has been assigned 143 \sa setSymbol() 144 */ 145 const QwtColumnSymbol *QwtPlotBarChart::symbol() const146 { 147 return d_data->symbol;148 } 149 150 /*! 151 Set the mode that decides what to display on the legend 152 153 In case of LegendBarTitles barTitle() needs to be overloaded 154 to return individual titles for each bar. 155 156 \param mode New mode 157 \sa legendMode(), legendData(), barTitle(), QwtPlotItem::ItemAttribute 147 \return Current symbol or NULL, when no symbol has been assigned 148 \sa setSymbol() 149 */ 150 const QwtColumnSymbol* QwtPlotBarChart::symbol() const 151 { 152 return m_data->symbol; 153 } 154 155 /*! 156 Set the mode that decides what to display on the legend 157 158 In case of LegendBarTitles barTitle() needs to be overloaded 159 to return individual titles for each bar. 160 161 \param mode New mode 162 \sa legendMode(), legendData(), barTitle(), QwtPlotItem::ItemAttribute 158 163 */ 159 164 void QwtPlotBarChart::setLegendMode( LegendMode mode ) 160 165 { 161 if ( mode != d_data->legendMode )162 { 163 d_data->legendMode = mode;166 if ( mode != m_data->legendMode ) 167 { 168 m_data->legendMode = mode; 164 169 legendChanged(); 165 170 } … … 167 172 168 173 /*! 169 \return Legend mode 170 \sa setLegendMode() 174 \return Legend mode 175 \sa setLegendMode() 171 176 */ 172 177 QwtPlotBarChart::LegendMode QwtPlotBarChart::legendMode() const 173 178 { 174 return d_data->legendMode;175 } 176 177 /*! 178 \return Bounding rectangle of all samples. 179 For an empty series the rectangle is invalid. 180 */ 179 return m_data->legendMode; 180 } 181 182 /*! 183 \return Bounding rectangle of all samples. 184 For an empty series the rectangle is invalid. 185 */ 181 186 QRectF QwtPlotBarChart::boundingRect() const 182 187 { … … 204 209 205 210 /*! 206 Draw an interval of the bar chart 207 208 \param painter Painter 209 \param xMap Maps x-values into pixel coordinates. 210 \param yMap Maps y-values into pixel coordinates. 211 \param canvasRect Contents rect of the canvas 212 \param from Index of the first point to be painted 213 \param to Index of the last point to be painted. If to < 0 the 211 Draw an interval of the bar chart 212 213 \param painter Painter 214 \param xMap Maps x-values into pixel coordinates. 215 \param yMap Maps y-values into pixel coordinates. 216 \param canvasRect Contents rect of the canvas 217 \param from Index of the first point to be painted 218 \param to Index of the last point to be painted. If to < 0 the 214 219 curve will be painted to its last point. 215 220 216 \sa drawSymbols() 217 */ 218 void QwtPlotBarChart::drawSeries( QPainter *painter,219 const QwtScaleMap &xMap, const QwtScaleMap&yMap,220 const QRectF &canvasRect, int from, int to ) const221 \sa drawSymbols() 222 */ 223 void QwtPlotBarChart::drawSeries( QPainter* painter, 224 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 225 const QRectF& canvasRect, int from, int to ) const 221 226 { 222 227 if ( to < 0 ) … … 238 243 { 239 244 drawSample( painter, xMap, yMap, 240 canvasRect, interval, i, sample( i ) );245 canvasRect, interval, i, sample( i ) ); 241 246 } 242 247 … … 245 250 246 251 /*! 247 Draw a sample 248 249 \param painter Painter 250 \param xMap x map 251 \param yMap y map 252 \param canvasRect Contents rect of the canvas 253 \param boundingInterval Bounding interval of sample values 254 \param index Index of the sample 255 \param sample Value of the sample 256 257 \sa drawSeries() 258 */ 259 void QwtPlotBarChart::drawSample( QPainter *painter, 260 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 261 const QRectF &canvasRect, const QwtInterval &boundingInterval, 262 int index, const QPointF &sample ) const 252 Calculate the geometry of a bar in widget coordinates 253 254 \param xMap x map 255 \param yMap y map 256 \param canvasRect Contents rect of the canvas 257 \param boundingInterval Bounding interval of sample values 258 \param sample Value of the sample 259 260 \return Geometry of the column 261 */ 262 QwtColumnRect QwtPlotBarChart::columnRect( 263 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 264 const QRectF& canvasRect, const QwtInterval& boundingInterval, 265 const QPointF& sample ) const 263 266 { 264 267 QwtColumnRect barRect; … … 301 304 } 302 305 306 return barRect; 307 } 308 309 /*! 310 Draw a sample 311 312 \param painter Painter 313 \param xMap x map 314 \param yMap y map 315 \param canvasRect Contents rect of the canvas 316 \param boundingInterval Bounding interval of sample values 317 \param index Index of the sample 318 \param sample Value of the sample 319 320 \sa drawSeries() 321 */ 322 void QwtPlotBarChart::drawSample( QPainter* painter, 323 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 324 const QRectF& canvasRect, const QwtInterval& boundingInterval, 325 int index, const QPointF& sample ) const 326 { 327 const QwtColumnRect barRect = columnRect( xMap, yMap, 328 canvasRect, boundingInterval, sample ); 329 303 330 drawBar( painter, index, sample, barRect ); 304 331 } 305 332 306 333 /*! 307 Draw a bar 308 309 \param painter Painter 310 \param sampleIndex Index of the sample represented by the bar 311 \param sample Value of the sample 312 \param rect Bounding rectangle of the bar 313 */ 314 void QwtPlotBarChart::drawBar( QPainter *painter,315 int sampleIndex, const QPointF &sample,316 const QwtColumnRect &rect ) const317 { 318 const QwtColumnSymbol *specialSym =334 Draw a bar 335 336 \param painter Painter 337 \param sampleIndex Index of the sample represented by the bar 338 \param sample Value of the sample 339 \param rect Bounding rectangle of the bar 340 */ 341 void QwtPlotBarChart::drawBar( QPainter* painter, 342 int sampleIndex, const QPointF& sample, 343 const QwtColumnRect& rect ) const 344 { 345 const QwtColumnSymbol* specialSym = 319 346 specialSymbol( sampleIndex, sample ); 320 347 321 const QwtColumnSymbol *sym = specialSym;348 const QwtColumnSymbol* sym = specialSym; 322 349 if ( sym == NULL ) 323 sym = d_data->symbol;350 sym = m_data->symbol; 324 351 325 352 if ( sym ) … … 340 367 341 368 /*! 342 Needs to be overloaded to return a 343 non default symbol for a specific sample 344 345 \param sampleIndex Index of the sample represented by the bar 346 \param sample Value of the sample 347 348 \return NULL, indicating to use the default symbol 349 */ 350 QwtColumnSymbol *QwtPlotBarChart::specialSymbol(351 int sampleIndex, const QPointF &sample ) const369 Needs to be overloaded to return a 370 non default symbol for a specific sample 371 372 \param sampleIndex Index of the sample represented by the bar 373 \param sample Value of the sample 374 375 \return NULL, indicating to use the default symbol 376 */ 377 QwtColumnSymbol* QwtPlotBarChart::specialSymbol( 378 int sampleIndex, const QPointF& sample ) const 352 379 { 353 380 Q_UNUSED( sampleIndex ); … … 358 385 359 386 /*! 360 \brief Return the title of a bar 361 362 In LegendBarTitles mode the title is displayed on 363 the legend entry corresponding to a bar. 364 365 The default implementation is a dummy, that is intended 366 to be overloaded. 367 368 \param sampleIndex Index of the bar 369 \return An empty text 370 \sa LegendBarTitles 387 \brief Return the title of a bar 388 389 In LegendBarTitles mode the title is displayed on 390 the legend entry corresponding to a bar. 391 392 The default implementation is a dummy, that is intended 393 to be overloaded. 394 395 \param sampleIndex Index of the bar 396 \return An empty text 397 \sa LegendBarTitles 371 398 */ 372 399 QwtText QwtPlotBarChart::barTitle( int sampleIndex ) const … … 387 414 \sa title(), setLegendMode(), barTitle(), QwtLegend, QwtPlotLegendItem 388 415 */ 389 QList<QwtLegendData> QwtPlotBarChart::legendData() const 390 { 391 QList<QwtLegendData> list; 392 393 if ( d_data->legendMode == LegendBarTitles )416 QList< QwtLegendData > QwtPlotBarChart::legendData() const 417 { 418 QList< QwtLegendData > list; 419 420 if ( m_data->legendMode == LegendBarTitles ) 394 421 { 395 422 const size_t numSamples = dataSize(); 423 list.reserve( numSamples ); 424 396 425 for ( size_t i = 0; i < numSamples; i++ ) 397 426 { 398 427 QwtLegendData data; 399 428 400 QVariant titleValue; 401 qVariantSetValue( titleValue, barTitle( i ) ); 402 data.setValue( QwtLegendData::TitleRole, titleValue ); 429 data.setValue( QwtLegendData::TitleRole, 430 QVariant::fromValue( barTitle( i ) ) ); 403 431 404 432 if ( !legendIconSize().isEmpty() ) 405 433 { 406 QVariant iconValue; 407 qVariantSetValue( iconValue, 408 legendIcon( i, legendIconSize() ) ); 409 410 data.setValue( QwtLegendData::IconRole, iconValue ); 434 data.setValue( QwtLegendData::IconRole, 435 QVariant::fromValue( legendIcon( i, legendIconSize() ) ) ); 411 436 } 412 437 … … 436 461 */ 437 462 QwtGraphic QwtPlotBarChart::legendIcon( 438 int index, const QSizeF &size ) const463 int index, const QSizeF& size ) const 439 464 { 440 465 QwtColumnRect column; … … 451 476 452 477 int barIndex = -1; 453 if ( d_data->legendMode == QwtPlotBarChart::LegendBarTitles )478 if ( m_data->legendMode == QwtPlotBarChart::LegendBarTitles ) 454 479 barIndex = index; 455 480 -
trunk/BNC/qwt/qwt_plot_barchart.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_abstract_barchart.h" 15 #include "qwt_series_data.h"16 15 17 16 class QwtColumnRect; 18 17 class QwtColumnSymbol; 18 template< typename T > class QwtSeriesData; 19 19 20 20 /*! 21 \brief QwtPlotBarChart displays a series of a values as bars. 21 \brief QwtPlotBarChart displays a series of a values as bars. 22 22 23 Each bar might be customized individually by implementing 24 a specialSymbol(). Otherwise it is rendered using a default symbol. 23 Each bar might be customized individually by implementing 24 a specialSymbol(). Otherwise it is rendered using a default symbol. 25 25 26 Depending on its orientation() the bars are displayed horizontally 27 or vertically. The bars cover the interval between the baseline() 28 and the value. 26 Depending on its orientation() the bars are displayed horizontally 27 or vertically. The bars cover the interval between the baseline() 28 and the value. 29 29 30 By activating the LegendBarTitles mode each sample will have 31 its own entry on the legend. 30 By activating the LegendBarTitles mode each sample will have 31 its own entry on the legend. 32 32 33 The most common use case of a bar chart is to display a 34 list of y coordinates, where the x coordinate is simply the index 35 in the list. But for other situations ( f.e. when values are related 36 to dates ) it is also possible to set x coordinates explicitly. 33 The most common use case of a bar chart is to display a 34 list of y coordinates, where the x coordinate is simply the index 35 in the list. But for other situations ( f.e. when values are related 36 to dates ) it is also possible to set x coordinates explicitly. 37 37 38 \sa QwtPlotMultiBarChart, QwtPlotHistogram, QwtPlotCurve::Sticks, 38 \sa QwtPlotMultiBarChart, QwtPlotHistogram, QwtPlotCurve::Sticks, 39 39 QwtPlotSeriesItem::orientation(), QwtPlotAbstractBarChart::baseline() 40 40 */ 41 class QWT_EXPORT QwtPlotBarChart: 42 public QwtPlotAbstractBarChart, public QwtSeriesStore<QPointF> 41 class QWT_EXPORT QwtPlotBarChart 42 : public QwtPlotAbstractBarChart 43 , public QwtSeriesStore< QPointF > 43 44 { 44 public: 45 public: 45 46 /*! 46 \brief Legend modes. 47 \brief Legend modes. 47 48 48 The default setting is QwtPlotBarChart::LegendChartTitle. 49 \sa setLegendMode(), legendMode() 50 */ 49 The default setting is QwtPlotBarChart::LegendChartTitle. 50 \sa setLegendMode(), legendMode() 51 */ 51 52 enum LegendMode 52 53 { 53 54 /*! 54 One entry on the legend showing the default symbol 55 and the title() of the chart 55 One entry on the legend showing the default symbol 56 and the title() of the chart 56 57 57 \sa QwtPlotItem::title() 58 \sa QwtPlotItem::title() 58 59 */ 59 60 LegendChartTitle, 60 61 61 62 /*! 62 One entry for each value showing the individual symbol 63 of the corresponding bar and the bar title. 63 One entry for each value showing the individual symbol 64 of the corresponding bar and the bar title. 64 65 65 \sa specialSymbol(), barTitle() 66 \sa specialSymbol(), barTitle() 66 67 */ 67 68 LegendBarTitles 68 69 }; 69 70 70 explicit QwtPlotBarChart( const QString &title = QString() );71 explicit QwtPlotBarChart( const QwtText &title );71 explicit QwtPlotBarChart( const QString& title = QString() ); 72 explicit QwtPlotBarChart( const QwtText& title ); 72 73 73 74 virtual ~QwtPlotBarChart(); 74 75 75 virtual int rtti() const; 76 virtual int rtti() const QWT_OVERRIDE; 76 77 77 void setSamples( const QVector<QPointF >& );78 void setSamples( const QVector< double>& );79 void setSamples( QwtSeriesData<QPointF >* );78 void setSamples( const QVector< QPointF >& ); 79 void setSamples( const QVector< double >& ); 80 void setSamples( QwtSeriesData< QPointF >* ); 80 81 81 void setSymbol( QwtColumnSymbol * );82 const QwtColumnSymbol *symbol() const;82 void setSymbol( QwtColumnSymbol* ); 83 const QwtColumnSymbol* symbol() const; 83 84 84 85 void setLegendMode( LegendMode ); 85 86 LegendMode legendMode() const; 86 87 87 virtual void drawSeries( QPainter *painter,88 const QwtScaleMap &xMap, const QwtScaleMap&yMap,89 const QRectF &canvasRect, int from, int to ) const;88 virtual void drawSeries( QPainter*, 89 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 90 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 90 91 91 virtual QRectF boundingRect() const; 92 virtual QRectF boundingRect() const QWT_OVERRIDE; 92 93 93 virtual QwtColumnSymbol *specialSymbol(94 virtual QwtColumnSymbol* specialSymbol( 94 95 int sampleIndex, const QPointF& ) const; 95 96 96 97 virtual QwtText barTitle( int sampleIndex ) const; 97 98 98 protected: 99 virtual void drawSample( QPainter *painter,100 const QwtScaleMap &xMap, const QwtScaleMap&yMap,101 const QRectF &canvasRect, const QwtInterval&boundingInterval,99 protected: 100 virtual void drawSample( QPainter* painter, 101 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 102 const QRectF& canvasRect, const QwtInterval& boundingInterval, 102 103 int index, const QPointF& sample ) const; 103 104 104 virtual void drawBar( QPainter *,105 virtual void drawBar( QPainter*, 105 106 int sampleIndex, const QPointF& sample, 106 const QwtColumnRect & ) const;107 const QwtColumnRect& ) const; 107 108 108 QList<QwtLegendData> legendData() const; 109 QwtGraphic legendIcon( int index, const QSizeF & ) const; 109 QwtColumnRect columnRect( 110 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 111 const QRectF& canvasRect, const QwtInterval& boundingInterval, 112 const QPointF& sample ) const; 110 113 111 private: 114 QList< QwtLegendData > legendData() const QWT_OVERRIDE; 115 QwtGraphic legendIcon( int index, const QSizeF& ) const QWT_OVERRIDE; 116 117 private: 112 118 void init(); 113 119 114 120 class PrivateData; 115 PrivateData *d_data;121 PrivateData* m_data; 116 122 }; 117 123 -
trunk/BNC/qwt/qwt_plot_canvas.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_canvas.h" 11 11 #include "qwt_painter.h" 12 #include "qwt_null_paintdevice.h"13 #include "qwt_math.h"14 12 #include "qwt_plot.h" 13 15 14 #include <qpainter.h> 16 #include <qstyle.h> 17 #include <qstyleoption.h> 18 #include <qpaintengine.h> 15 #include <qpainterpath.h> 19 16 #include <qevent.h> 20 17 21 class QwtStyleSheetRecorder: public QwtNullPaintDevice 22 { 23 public: 24 QwtStyleSheetRecorder( const QSize &size ): 25 d_size( size ) 26 { 27 } 28 29 virtual void updateState( const QPaintEngineState &state ) 30 { 31 if ( state.state() & QPaintEngine::DirtyPen ) 32 { 33 d_pen = state.pen(); 34 } 35 if ( state.state() & QPaintEngine::DirtyBrush ) 36 { 37 d_brush = state.brush(); 38 } 39 if ( state.state() & QPaintEngine::DirtyBrushOrigin ) 40 { 41 d_origin = state.brushOrigin(); 42 } 43 } 44 45 virtual void drawRects(const QRectF *rects, int count ) 46 { 47 for ( int i = 0; i < count; i++ ) 48 border.rectList += rects[i]; 49 } 50 51 virtual void drawRects(const QRect *rects, int count ) 52 { 53 // to silence -Woverloaded-virtual 54 QwtNullPaintDevice::drawRects( rects, count ); 55 } 56 57 virtual void drawPath( const QPainterPath &path ) 58 { 59 const QRectF rect( QPointF( 0.0, 0.0 ), d_size ); 60 if ( path.controlPointRect().contains( rect.center() ) ) 61 { 62 setCornerRects( path ); 63 alignCornerRects( rect ); 64 65 background.path = path; 66 background.brush = d_brush; 67 background.origin = d_origin; 68 } 69 else 70 { 71 border.pathList += path; 72 } 73 } 74 75 void setCornerRects( const QPainterPath &path ) 76 { 77 QPointF pos( 0.0, 0.0 ); 78 79 for ( int i = 0; i < path.elementCount(); i++ ) 80 { 81 QPainterPath::Element el = path.elementAt(i); 82 switch( el.type ) 83 { 84 case QPainterPath::MoveToElement: 85 case QPainterPath::LineToElement: 86 { 87 pos.setX( el.x ); 88 pos.setY( el.y ); 89 break; 90 } 91 case QPainterPath::CurveToElement: 92 { 93 QRectF r( pos, QPointF( el.x, el.y ) ); 94 clipRects += r.normalized(); 95 96 pos.setX( el.x ); 97 pos.setY( el.y ); 98 99 break; 100 } 101 case QPainterPath::CurveToDataElement: 102 { 103 if ( clipRects.size() > 0 ) 104 { 105 QRectF r = clipRects.last(); 106 r.setCoords( 107 qMin( r.left(), el.x ), 108 qMin( r.top(), el.y ), 109 qMax( r.right(), el.x ), 110 qMax( r.bottom(), el.y ) 111 ); 112 clipRects.last() = r.normalized(); 113 } 114 break; 115 } 116 } 117 } 118 } 119 120 protected: 121 virtual QSize sizeMetrics() const 122 { 123 return d_size; 124 } 125 126 private: 127 void alignCornerRects( const QRectF &rect ) 128 { 129 for ( int i = 0; i < clipRects.size(); i++ ) 130 { 131 QRectF &r = clipRects[i]; 132 if ( r.center().x() < rect.center().x() ) 133 r.setLeft( rect.left() ); 134 else 135 r.setRight( rect.right() ); 136 137 if ( r.center().y() < rect.center().y() ) 138 r.setTop( rect.top() ); 139 else 140 r.setBottom( rect.bottom() ); 141 } 142 } 143 144 145 public: 146 QVector<QRectF> clipRects; 147 148 struct Border 149 { 150 QList<QPainterPath> pathList; 151 QList<QRectF> rectList; 152 QRegion clipRegion; 153 } border; 154 155 struct Background 156 { 157 QPainterPath path; 158 QBrush brush; 159 QPointF origin; 160 } background; 161 162 private: 163 const QSize d_size; 164 165 QPen d_pen; 166 QBrush d_brush; 167 QPointF d_origin; 18 class QwtPlotCanvas::PrivateData 19 { 20 public: 21 PrivateData() 22 : backingStore( NULL ) 23 { 24 } 25 26 ~PrivateData() 27 { 28 delete backingStore; 29 } 30 31 QwtPlotCanvas::PaintAttributes paintAttributes; 32 QPixmap* backingStore; 168 33 }; 169 34 170 static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas ) 171 { 172 painter->save(); 173 174 const QPainterPath borderClip = canvas->borderPath( canvas->rect() ); 175 if ( !borderClip.isEmpty() ) 176 painter->setClipPath( borderClip, Qt::IntersectClip ); 177 178 const QBrush &brush = 179 canvas->palette().brush( canvas->backgroundRole() ); 180 181 if ( brush.style() == Qt::TexturePattern ) 182 { 183 QPixmap pm( canvas->size() ); 184 QwtPainter::fillPixmap( canvas, pm ); 185 painter->drawPixmap( 0, 0, pm ); 186 } 187 else if ( brush.gradient() ) 188 { 189 QVector<QRect> rects; 190 191 if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode ) 192 { 193 rects += canvas->rect(); 194 } 195 else 196 { 197 rects = painter->clipRegion().rects(); 198 } 199 200 #if 1 201 bool useRaster = false; 202 203 if ( painter->paintEngine()->type() == QPaintEngine::X11 ) 204 { 205 // Qt 4.7.1: gradients on X11 are broken ( subrects + 206 // QGradient::StretchToDeviceMode ) and horrible slow. 207 // As workaround we have to use the raster paintengine. 208 // Even if the QImage -> QPixmap translation is slow 209 // it is three times faster, than using X11 directly 210 211 useRaster = true; 212 } 213 #endif 214 if ( useRaster ) 215 { 216 QImage::Format format = QImage::Format_RGB32; 217 218 const QGradientStops stops = brush.gradient()->stops(); 219 for ( int i = 0; i < stops.size(); i++ ) 220 { 221 if ( stops[i].second.alpha() != 255 ) 222 { 223 // don't use Format_ARGB32_Premultiplied. It's 224 // recommended by the Qt docs, but QPainter::drawImage() 225 // is horrible slow on X11. 226 227 format = QImage::Format_ARGB32; 228 break; 229 } 230 } 231 232 QImage image( canvas->size(), format ); 233 234 QPainter p( &image ); 235 p.setPen( Qt::NoPen ); 236 p.setBrush( brush ); 237 238 p.drawRects( rects ); 239 240 p.end(); 241 242 painter->drawImage( 0, 0, image ); 243 } 244 else 245 { 246 painter->setPen( Qt::NoPen ); 247 painter->setBrush( brush ); 248 249 painter->drawRects( rects ); 250 } 251 } 252 else 253 { 254 painter->setPen( Qt::NoPen ); 255 painter->setBrush( brush ); 256 257 painter->drawRects( painter->clipRegion().rects() ); 258 259 } 260 261 painter->restore(); 262 } 263 264 static inline void qwtRevertPath( QPainterPath &path ) 265 { 266 if ( path.elementCount() == 4 ) 267 { 268 QPainterPath::Element el0 = path.elementAt(0); 269 QPainterPath::Element el3 = path.elementAt(3); 270 271 path.setElementPositionAt( 0, el3.x, el3.y ); 272 path.setElementPositionAt( 3, el0.x, el0.y ); 273 } 274 } 275 276 static QPainterPath qwtCombinePathList( const QRectF &rect, 277 const QList<QPainterPath> &pathList ) 278 { 279 if ( pathList.isEmpty() ) 280 return QPainterPath(); 281 282 QPainterPath ordered[8]; // starting top left 283 284 for ( int i = 0; i < pathList.size(); i++ ) 285 { 286 int index = -1; 287 QPainterPath subPath = pathList[i]; 288 289 const QRectF br = pathList[i].controlPointRect(); 290 if ( br.center().x() < rect.center().x() ) 291 { 292 if ( br.center().y() < rect.center().y() ) 293 { 294 if ( qAbs( br.top() - rect.top() ) < 295 qAbs( br.left() - rect.left() ) ) 296 { 297 index = 1; 298 } 299 else 300 { 301 index = 0; 302 } 303 } 304 else 305 { 306 if ( qAbs( br.bottom() - rect.bottom() ) < 307 qAbs( br.left() - rect.left() ) ) 308 { 309 index = 6; 310 } 311 else 312 { 313 index = 7; 314 } 315 } 316 317 if ( subPath.currentPosition().y() > br.center().y() ) 318 qwtRevertPath( subPath ); 319 } 320 else 321 { 322 if ( br.center().y() < rect.center().y() ) 323 { 324 if ( qAbs( br.top() - rect.top() ) < 325 qAbs( br.right() - rect.right() ) ) 326 { 327 index = 2; 328 } 329 else 330 { 331 index = 3; 332 } 333 } 334 else 335 { 336 if ( qAbs( br.bottom() - rect.bottom() ) < 337 qAbs( br.right() - rect.right() ) ) 338 { 339 index = 5; 340 } 341 else 342 { 343 index = 4; 344 } 345 } 346 if ( subPath.currentPosition().y() < br.center().y() ) 347 qwtRevertPath( subPath ); 348 } 349 ordered[index] = subPath; 350 } 351 352 for ( int i = 0; i < 4; i++ ) 353 { 354 if ( ordered[ 2 * i].isEmpty() != ordered[2 * i + 1].isEmpty() ) 355 { 356 // we don't accept incomplete rounded borders 357 return QPainterPath(); 358 } 359 } 360 361 362 const QPolygonF corners( rect ); 363 364 QPainterPath path; 365 //path.moveTo( rect.topLeft() ); 366 367 for ( int i = 0; i < 4; i++ ) 368 { 369 if ( ordered[2 * i].isEmpty() ) 370 { 371 path.lineTo( corners[i] ); 372 } 373 else 374 { 375 path.connectPath( ordered[2 * i] ); 376 path.connectPath( ordered[2 * i + 1] ); 377 } 378 } 379 380 path.closeSubpath(); 381 382 #if 0 383 return path.simplified(); 384 #else 385 return path; 386 #endif 387 } 388 389 static inline void qwtDrawStyledBackground( 390 QWidget *w, QPainter *painter ) 391 { 392 QStyleOption opt; 393 opt.initFrom(w); 394 w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w); 395 } 396 397 static QWidget *qwtBackgroundWidget( QWidget *w ) 398 { 399 if ( w->parentWidget() == NULL ) 400 return w; 401 402 if ( w->autoFillBackground() ) 403 { 404 const QBrush brush = w->palette().brush( w->backgroundRole() ); 405 if ( brush.color().alpha() > 0 ) 406 return w; 407 } 408 409 if ( w->testAttribute( Qt::WA_StyledBackground ) ) 410 { 411 QImage image( 1, 1, QImage::Format_ARGB32 ); 412 image.fill( Qt::transparent ); 413 414 QPainter painter( &image ); 415 painter.translate( -w->rect().center() ); 416 qwtDrawStyledBackground( w, &painter ); 417 painter.end(); 418 419 if ( qAlpha( image.pixel( 0, 0 ) ) != 0 ) 420 return w; 421 } 422 423 return qwtBackgroundWidget( w->parentWidget() ); 424 } 425 426 static void qwtFillBackground( QPainter *painter, 427 QWidget *widget, const QVector<QRectF> &fillRects ) 428 { 429 if ( fillRects.isEmpty() ) 430 return; 431 432 QRegion clipRegion; 433 if ( painter->hasClipping() ) 434 clipRegion = painter->transform().map( painter->clipRegion() ); 435 else 436 clipRegion = widget->contentsRect(); 437 438 // Try to find out which widget fills 439 // the unfilled areas of the styled background 440 441 QWidget *bgWidget = qwtBackgroundWidget( widget->parentWidget() ); 442 443 for ( int i = 0; i < fillRects.size(); i++ ) 444 { 445 const QRect rect = fillRects[i].toAlignedRect(); 446 if ( clipRegion.intersects( rect ) ) 447 { 448 QPixmap pm( rect.size() ); 449 QwtPainter::fillPixmap( bgWidget, pm, widget->mapTo( bgWidget, rect.topLeft() ) ); 450 painter->drawPixmap( rect, pm ); 451 } 452 } 453 } 454 455 static void qwtFillBackground( QPainter *painter, QwtPlotCanvas *canvas ) 456 { 457 QVector<QRectF> rects; 458 459 if ( canvas->testAttribute( Qt::WA_StyledBackground ) ) 460 { 461 QwtStyleSheetRecorder recorder( canvas->size() ); 462 463 QPainter p( &recorder ); 464 qwtDrawStyledBackground( canvas, &p ); 465 p.end(); 466 467 if ( recorder.background.brush.isOpaque() ) 468 rects = recorder.clipRects; 469 else 470 rects += canvas->rect(); 471 } 472 else 473 { 474 const QRectF r = canvas->rect(); 475 const double radius = canvas->borderRadius(); 476 if ( radius > 0.0 ) 477 { 478 QSizeF sz( radius, radius ); 479 480 rects += QRectF( r.topLeft(), sz ); 481 rects += QRectF( r.topRight() - QPointF( radius, 0 ), sz ); 482 rects += QRectF( r.bottomRight() - QPointF( radius, radius ), sz ); 483 rects += QRectF( r.bottomLeft() - QPointF( 0, radius ), sz ); 484 } 485 } 486 487 qwtFillBackground( painter, canvas, rects); 488 } 489 490 491 class QwtPlotCanvas::PrivateData 492 { 493 public: 494 PrivateData(): 495 focusIndicator( NoFocusIndicator ), 496 borderRadius( 0 ), 497 paintAttributes( 0 ), 498 backingStore( NULL ) 499 { 500 styleSheet.hasBorder = false; 501 } 502 503 ~PrivateData() 504 { 505 delete backingStore; 506 } 507 508 FocusIndicator focusIndicator; 509 double borderRadius; 510 QwtPlotCanvas::PaintAttributes paintAttributes; 511 QPixmap *backingStore; 512 513 struct StyleSheet 514 { 515 bool hasBorder; 516 QPainterPath borderPath; 517 QVector<QRectF> cornerRects; 518 519 struct StyleSheetBackground 520 { 521 QBrush brush; 522 QPointF origin; 523 } background; 524 525 } styleSheet; 526 527 }; 528 529 /*! 530 \brief Constructor 531 532 \param plot Parent plot widget 533 \sa QwtPlot::setCanvas() 534 */ 535 QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ): 536 QFrame( plot ) 537 { 538 setFrameStyle( QFrame::Panel | QFrame::Sunken ); 539 setLineWidth( 2 ); 540 541 d_data = new PrivateData; 542 543 #ifndef QT_NO_CURSOR 544 setCursor( Qt::CrossCursor ); 545 #endif 546 547 setAutoFillBackground( true ); 35 /*! 36 \brief Constructor 37 38 \param plot Parent plot widget 39 \sa QwtPlot::setCanvas() 40 */ 41 QwtPlotCanvas::QwtPlotCanvas( QwtPlot* plot ) 42 : QFrame( plot ) 43 , QwtPlotAbstractCanvas( this ) 44 { 45 m_data = new PrivateData; 46 548 47 setPaintAttribute( QwtPlotCanvas::BackingStore, true ); 549 48 setPaintAttribute( QwtPlotCanvas::Opaque, true ); 550 49 setPaintAttribute( QwtPlotCanvas::HackStyledBackground, true ); 50 51 setLineWidth( 2 ); 52 setFrameShadow( QFrame::Sunken ); 53 setFrameShape( QFrame::Panel ); 551 54 } 552 55 … … 554 57 QwtPlotCanvas::~QwtPlotCanvas() 555 58 { 556 delete d_data; 557 } 558 559 //! Return parent plot widget 560 QwtPlot *QwtPlotCanvas::plot() 561 { 562 return qobject_cast<QwtPlot *>( parent() ); 563 } 564 565 //! Return parent plot widget 566 const QwtPlot *QwtPlotCanvas::plot() const 567 { 568 return qobject_cast<const QwtPlot *>( parent() ); 569 } 570 571 /*! 572 \brief Changing the paint attributes 573 574 \param attribute Paint attribute 575 \param on On/Off 576 577 \sa testPaintAttribute(), backingStore() 578 */ 59 delete m_data; 60 } 61 62 /*! 63 \brief Changing the paint attributes 64 65 \param attribute Paint attribute 66 \param on On/Off 67 68 \sa testPaintAttribute(), backingStore() 69 */ 579 70 void QwtPlotCanvas::setPaintAttribute( PaintAttribute attribute, bool on ) 580 71 { 581 if ( bool( d_data->paintAttributes & attribute ) == on )72 if ( bool( m_data->paintAttributes & attribute ) == on ) 582 73 return; 583 74 584 75 if ( on ) 585 d_data->paintAttributes |= attribute;76 m_data->paintAttributes |= attribute; 586 77 else 587 d_data->paintAttributes &= ~attribute;78 m_data->paintAttributes &= ~attribute; 588 79 589 80 switch ( attribute ) … … 593 84 if ( on ) 594 85 { 595 if ( d_data->backingStore == NULL )596 d_data->backingStore = new QPixmap();86 if ( m_data->backingStore == NULL ) 87 m_data->backingStore = new QPixmap(); 597 88 598 89 if ( isVisible() ) 599 90 { 600 91 #if QT_VERSION >= 0x050000 601 * d_data->backingStore = grab( rect() );92 *m_data->backingStore = grab( rect() ); 602 93 #else 603 * d_data->backingStore =94 *m_data->backingStore = 604 95 QPixmap::grabWidget( this, rect() ); 605 96 #endif … … 608 99 else 609 100 { 610 delete d_data->backingStore;611 d_data->backingStore = NULL;101 delete m_data->backingStore; 102 m_data->backingStore = NULL; 612 103 } 613 104 break; … … 620 111 break; 621 112 } 622 case HackStyledBackground: 623 case ImmediatePaint: 113 default: 624 114 { 625 115 break; … … 629 119 630 120 /*! 631 Test whether a paint attribute is enabled 632 633 \param attribute Paint attribute 634 \return true, when attribute is enabled 635 \sa setPaintAttribute() 636 */ 121 Test whether a paint attribute is enabled 122 123 \param attribute Paint attribute 124 \return true, when attribute is enabled 125 \sa setPaintAttribute() 126 */ 637 127 bool QwtPlotCanvas::testPaintAttribute( PaintAttribute attribute ) const 638 128 { 639 return d_data->paintAttributes & attribute;129 return m_data->paintAttributes & attribute; 640 130 } 641 131 642 132 //! \return Backing store, might be null 643 const QPixmap *QwtPlotCanvas::backingStore() const644 { 645 return d_data->backingStore;133 const QPixmap* QwtPlotCanvas::backingStore() const 134 { 135 return m_data->backingStore; 646 136 } 647 137 … … 649 139 void QwtPlotCanvas::invalidateBackingStore() 650 140 { 651 if ( d_data->backingStore ) 652 *d_data->backingStore = QPixmap(); 653 } 654 655 /*! 656 Set the focus indicator 657 658 \sa FocusIndicator, focusIndicator() 659 */ 660 void QwtPlotCanvas::setFocusIndicator( FocusIndicator focusIndicator ) 661 { 662 d_data->focusIndicator = focusIndicator; 663 } 664 665 /*! 666 \return Focus indicator 667 668 \sa FocusIndicator, setFocusIndicator() 669 */ 670 QwtPlotCanvas::FocusIndicator QwtPlotCanvas::focusIndicator() const 671 { 672 return d_data->focusIndicator; 673 } 674 675 /*! 676 Set the radius for the corners of the border frame 677 678 \param radius Radius of a rounded corner 679 \sa borderRadius() 680 */ 681 void QwtPlotCanvas::setBorderRadius( double radius ) 682 { 683 d_data->borderRadius = qMax( 0.0, radius ); 684 } 685 686 /*! 687 \return Radius for the corners of the border frame 688 \sa setBorderRadius() 689 */ 690 double QwtPlotCanvas::borderRadius() const 691 { 692 return d_data->borderRadius; 693 } 694 695 /*! 696 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 697 698 \param event Qt Event 699 \return See QFrame::event() 700 */ 701 bool QwtPlotCanvas::event( QEvent *event ) 141 if ( m_data->backingStore ) 142 *m_data->backingStore = QPixmap(); 143 } 144 145 /*! 146 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 147 148 \param event Qt Event 149 \return See QFrame::event() 150 */ 151 bool QwtPlotCanvas::event( QEvent* event ) 702 152 { 703 153 if ( event->type() == QEvent::PolishRequest ) … … 723 173 724 174 /*! 725 Paint event 726 \param event Paint event 727 */ 728 void QwtPlotCanvas::paintEvent( QPaintEvent *event )175 Paint event 176 \param event Paint event 177 */ 178 void QwtPlotCanvas::paintEvent( QPaintEvent* event ) 729 179 { 730 180 QPainter painter( this ); … … 732 182 733 183 if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) && 734 d_data->backingStore != NULL ) 735 { 736 QPixmap &bs = *d_data->backingStore; 737 738 qreal pixelRatio = 1.0; 739 740 #if QT_VERSION >= 0x050000 741 pixelRatio = bs.devicePixelRatio(); 742 #endif 743 744 if ( bs.size() != size() * pixelRatio ) 184 m_data->backingStore != NULL ) 185 { 186 QPixmap& bs = *m_data->backingStore; 187 if ( bs.size() != size() * QwtPainter::devicePixelRatio( &bs ) ) 745 188 { 746 189 bs = QwtPainter::backingStore( this, size() ); … … 749 192 { 750 193 QPainter p( &bs ); 751 qwtFillBackground( &p, this ); 752 drawCanvas( &p, true ); 194 drawStyled( &p, testPaintAttribute( HackStyledBackground ) ); 753 195 } 754 196 else 755 197 { 756 198 QPainter p; 757 if ( d_data->borderRadius <= 0.0 )199 if ( borderRadius() <= 0.0 ) 758 200 { 759 201 QwtPainter::fillPixmap( this, bs ); 760 202 p.begin( &bs ); 761 drawCanvas( &p , false);203 drawCanvas( &p ); 762 204 } 763 205 else 764 206 { 765 207 p.begin( &bs ); 766 qwtFillBackground( &p, this ); 767 drawCanvas( &p, true ); 208 drawUnstyled( &p ); 768 209 } 769 210 … … 773 214 } 774 215 775 painter.drawPixmap( 0, 0, * d_data->backingStore );216 painter.drawPixmap( 0, 0, *m_data->backingStore ); 776 217 } 777 218 else … … 781 222 if ( testAttribute( Qt::WA_OpaquePaintEvent ) ) 782 223 { 783 qwtFillBackground( &painter, this ); 784 drawCanvas( &painter, true ); 224 drawStyled( &painter, testPaintAttribute( HackStyledBackground ) ); 785 225 } 786 226 else 787 227 { 788 drawCanvas( &painter , false);228 drawCanvas( &painter ); 789 229 } 790 230 } … … 795 235 if ( autoFillBackground() ) 796 236 { 797 qwtFillBackground( &painter, this);798 qwtDrawBackground( &painter, this);237 fillBackground( &painter ); 238 drawBackground( &painter ); 799 239 } 800 240 } … … 810 250 811 251 painter.setClipPath( clipPath, Qt::IntersectClip ); 812 qwtFillBackground( &painter, this);813 qwtDrawBackground( &painter, this);252 fillBackground( &painter ); 253 drawBackground( &painter ); 814 254 815 255 painter.restore(); … … 817 257 } 818 258 819 drawCanvas( &painter , false);259 drawCanvas( &painter ); 820 260 821 261 if ( frameWidth() > 0 ) … … 828 268 } 829 269 830 void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground ) 831 { 832 bool hackStyledBackground = false; 833 834 if ( withBackground && testAttribute( Qt::WA_StyledBackground ) 835 && testPaintAttribute( HackStyledBackground ) ) 836 { 837 // Antialiasing rounded borders is done by 838 // inserting pixels with colors between the 839 // border color and the color on the canvas, 840 // When the border is painted before the plot items 841 // these colors are interpolated for the canvas 842 // and the plot items need to be clipped excluding 843 // the anialiased pixels. In situations, where 844 // the plot items fill the area at the rounded 845 // borders this is noticeable. 846 // The only way to avoid these annoying "artefacts" 847 // is to paint the border on top of the plot items. 848 849 if ( d_data->styleSheet.hasBorder && 850 !d_data->styleSheet.borderPath.isEmpty() ) 851 { 852 // We have a border with at least one rounded corner 853 hackStyledBackground = true; 854 } 855 } 856 857 if ( withBackground ) 858 { 859 painter->save(); 860 861 if ( testAttribute( Qt::WA_StyledBackground ) ) 862 { 863 if ( hackStyledBackground ) 864 { 865 // paint background without border 866 867 painter->setPen( Qt::NoPen ); 868 painter->setBrush( d_data->styleSheet.background.brush ); 869 painter->setBrushOrigin( d_data->styleSheet.background.origin ); 870 painter->setClipPath( d_data->styleSheet.borderPath ); 871 painter->drawRect( contentsRect() ); 872 } 873 else 874 { 875 qwtDrawStyledBackground( this, painter ); 876 } 877 } 878 else if ( autoFillBackground() ) 879 { 880 painter->setPen( Qt::NoPen ); 881 painter->setBrush( palette().brush( backgroundRole() ) ); 882 883 if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) ) 884 { 885 if ( frameWidth() > 0 ) 886 { 887 painter->setClipPath( borderPath( rect() ) ); 888 painter->drawRect( rect() ); 889 } 890 else 891 { 892 painter->setRenderHint( QPainter::Antialiasing, true ); 893 painter->drawPath( borderPath( rect() ) ); 894 } 895 } 896 else 897 { 898 painter->drawRect( rect() ); 899 } 900 } 901 902 painter->restore(); 903 } 904 905 painter->save(); 906 907 if ( !d_data->styleSheet.borderPath.isEmpty() ) 908 { 909 painter->setClipPath( 910 d_data->styleSheet.borderPath, Qt::IntersectClip ); 911 } 912 else 913 { 914 if ( d_data->borderRadius > 0.0 ) 915 painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip ); 916 else 917 painter->setClipRect( contentsRect(), Qt::IntersectClip ); 918 } 919 920 plot()->drawCanvas( painter ); 921 922 painter->restore(); 923 924 if ( withBackground && hackStyledBackground ) 925 { 926 // Now paint the border on top 927 QStyleOptionFrame opt; 928 opt.initFrom(this); 929 style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, this); 930 } 931 } 932 933 /*! 934 Draw the border of the plot canvas 935 936 \param painter Painter 937 \sa setBorderRadius() 938 */ 939 void QwtPlotCanvas::drawBorder( QPainter *painter ) 940 { 941 if ( d_data->borderRadius > 0 ) 942 { 943 if ( frameWidth() > 0 ) 944 { 945 QwtPainter::drawRoundedFrame( painter, QRectF( frameRect() ), 946 d_data->borderRadius, d_data->borderRadius, 947 palette(), frameWidth(), frameStyle() ); 948 } 949 } 950 else 951 { 952 #if QT_VERSION >= 0x040500 953 #if QT_VERSION < 0x050000 954 QStyleOptionFrameV3 opt; 955 #else 956 QStyleOptionFrame opt; 957 #endif 958 opt.init(this); 959 960 int frameShape = frameStyle() & QFrame::Shape_Mask; 961 int frameShadow = frameStyle() & QFrame::Shadow_Mask; 962 963 opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape ); 964 #if 0 965 opt.rect = frameRect(); 966 #endif 967 968 switch (frameShape) 969 { 970 case QFrame::Box: 971 case QFrame::HLine: 972 case QFrame::VLine: 973 case QFrame::StyledPanel: 974 case QFrame::Panel: 975 { 976 opt.lineWidth = lineWidth(); 977 opt.midLineWidth = midLineWidth(); 978 break; 979 } 980 default: 981 { 982 opt.lineWidth = frameWidth(); 983 break; 984 } 985 } 986 987 if ( frameShadow == Sunken ) 988 opt.state |= QStyle::State_Sunken; 989 else if ( frameShadow == Raised ) 990 opt.state |= QStyle::State_Raised; 991 992 style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, this); 993 #else 270 /*! 271 Draw the border of the plot canvas 272 273 \param painter Painter 274 \sa setBorderRadius() 275 */ 276 void QwtPlotCanvas::drawBorder( QPainter* painter ) 277 { 278 if ( borderRadius() <= 0 ) 279 { 994 280 drawFrame( painter ); 995 #endif 996 } 997 } 998 999 /*! 1000 Resize event 1001 \param event Resize event 1002 */ 1003 void QwtPlotCanvas::resizeEvent( QResizeEvent *event ) 281 return; 282 } 283 284 QwtPlotAbstractCanvas::drawBorder( painter ); 285 } 286 287 /*! 288 Resize event 289 \param event Resize event 290 */ 291 void QwtPlotCanvas::resizeEvent( QResizeEvent* event ) 1004 292 { 1005 293 QFrame::resizeEvent( event ); … … 1008 296 1009 297 /*! 1010 Draw the focus indication1011 \param painter Painter1012 */1013 void QwtPlotCanvas::drawFocusIndicator( QPainter *painter )1014 {1015 const int margin = 1;1016 1017 QRect focusRect = contentsRect();1018 focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin,1019 focusRect.width() - 2 * margin, focusRect.height() - 2 * margin );1020 1021 QwtPainter::drawFocusRect( painter, this, focusRect );1022 }1023 1024 /*!1025 298 Invalidate the paint cache and repaint the canvas 1026 299 \sa invalidatePaintCache() 1027 */ 300 */ 1028 301 void QwtPlotCanvas::replot() 1029 302 { … … 1036 309 } 1037 310 1038 //! Update the cached information about the current style sheet1039 void QwtPlotCanvas::updateStyleSheetInfo()1040 {1041 if ( !testAttribute(Qt::WA_StyledBackground ) )1042 return;1043 1044 QwtStyleSheetRecorder recorder( size() );1045 1046 QPainter painter( &recorder );1047 1048 QStyleOption opt;1049 opt.initFrom(this);1050 style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this);1051 1052 painter.end();1053 1054 d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty();1055 d_data->styleSheet.cornerRects = recorder.clipRects;1056 1057 if ( recorder.background.path.isEmpty() )1058 {1059 if ( !recorder.border.rectList.isEmpty() )1060 {1061 d_data->styleSheet.borderPath =1062 qwtCombinePathList( rect(), recorder.border.pathList );1063 }1064 }1065 else1066 {1067 d_data->styleSheet.borderPath = recorder.background.path;1068 d_data->styleSheet.background.brush = recorder.background.brush;1069 d_data->styleSheet.background.origin = recorder.background.origin;1070 }1071 }1072 1073 311 /*! 1074 312 Calculate the painter path for a styled or rounded border … … 1079 317 \param rect Bounding rectangle of the canvas 1080 318 \return Painter path, that can be used for clipping 1081 */ 1082 QPainterPath QwtPlotCanvas::borderPath( const QRect &rect ) const 1083 { 1084 if ( testAttribute(Qt::WA_StyledBackground ) ) 1085 { 1086 QwtStyleSheetRecorder recorder( rect.size() ); 1087 1088 QPainter painter( &recorder ); 1089 1090 QStyleOption opt; 1091 opt.initFrom(this); 1092 opt.rect = rect; 1093 style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this); 1094 1095 painter.end(); 1096 1097 if ( !recorder.background.path.isEmpty() ) 1098 return recorder.background.path; 1099 1100 if ( !recorder.border.rectList.isEmpty() ) 1101 return qwtCombinePathList( rect, recorder.border.pathList ); 1102 } 1103 else if ( d_data->borderRadius > 0.0 ) 1104 { 1105 double fw2 = frameWidth() * 0.5; 1106 QRectF r = QRectF(rect).adjusted( fw2, fw2, -fw2, -fw2 ); 1107 1108 QPainterPath path; 1109 path.addRoundedRect( r, d_data->borderRadius, d_data->borderRadius ); 1110 return path; 1111 } 1112 1113 return QPainterPath(); 1114 } 319 */ 320 QPainterPath QwtPlotCanvas::borderPath( const QRect& rect ) const 321 { 322 return canvasBorderPath( rect ); 323 } 324 325 #include "moc_qwt_plot_canvas.cpp" -
trunk/BNC/qwt/qwt_plot_canvas.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_plot_abstract_canvas.h" 15 14 16 #include <qframe.h> 15 #include <qpainterpath.h>16 17 17 18 class QwtPlot; 18 19 class QPixmap; 20 class QPainterPath; 19 21 20 22 /*! 21 \brief Canvas of a QwtPlot. 23 \brief Canvas of a QwtPlot. 22 24 23 25 Canvas is the widget where all plot items are displayed 24 26 25 \sa QwtPlot::setCanvas(), QwtPlotGLCanvas 26 */ 27 class QWT_EXPORT QwtPlotCanvas : public QFrame 27 \sa QwtPlot::setCanvas(), QwtPlotGLCanvas, QwtPlotOpenGLCanvas 28 */ 29 class QWT_EXPORT QwtPlotCanvas : public QFrame, public QwtPlotAbstractCanvas 28 30 { 29 31 Q_OBJECT … … 31 33 Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius ) 32 34 33 public: 35 public: 34 36 35 37 /*! 36 \brief Paint attributes 38 \brief Paint attributes 37 39 38 The default setting enables BackingStore and Opaque. 40 The default setting enables BackingStore and Opaque. 39 41 40 \sa setPaintAttribute(), testPaintAttribute() 42 \sa setPaintAttribute(), testPaintAttribute() 41 43 */ 42 44 enum PaintAttribute 43 45 { 44 46 /*! 45 \brief Paint double buffered reusing the content 47 \brief Paint double buffered reusing the content 46 48 of the pixmap buffer when possible. 47 49 48 Using a backing store might improve the performance 49 significantly, when working with widget overlays ( like rubber bands ). 50 Disabling the cache might improve the performance for 51 incremental paints (using QwtPlotDirectPainter ). 50 Using a backing store might improve the performance 51 significantly, when working with widget overlays ( like rubber bands ). 52 Disabling the cache might improve the performance for 53 incremental paints (using QwtPlotDirectPainter ). 52 54 53 \sa backingStore(), invalidateBackingStore() 55 \sa backingStore(), invalidateBackingStore() 54 56 */ 55 57 BackingStore = 1, 56 58 57 59 /*! 58 \brief Try to fill the complete contents rectangle 60 \brief Try to fill the complete contents rectangle 59 61 of the plot canvas 60 62 61 When using styled backgrounds Qt assumes, that the 62 canvas doesn't fill its area completely 63 ( f.e because of rounded borders ) and fills the area 64 below the canvas. When this is done with gradients it might 65 result in a serious performance bottleneck - depending on the size. 63 When using styled backgrounds Qt assumes, that the 64 canvas doesn't fill its area completely 65 ( f.e because of rounded borders ) and fills the area 66 below the canvas. When this is done with gradients it might 67 result in a serious performance bottleneck - depending on the size. 66 68 67 When the Opaque attribute is enabled the canvas tries to 68 identify the gaps with some heuristics and to fill those only. 69 When the Opaque attribute is enabled the canvas tries to 70 identify the gaps with some heuristics and to fill those only. 69 71 70 \warning Will not work for semitransparent backgrounds 72 \warning Will not work for semitransparent backgrounds 71 73 */ 72 74 Opaque = 2, 73 75 74 76 /*! 75 \brief Try to improve painting of styled backgrounds 77 \brief Try to improve painting of styled backgrounds 76 78 77 QwtPlotCanvas supports the box model attributes for 78 customizing the layout with style sheets. Unfortunately 79 the design of Qt style sheets has no concept how to 80 handle backgrounds with rounded corners - beside of padding. 79 QwtPlotCanvas supports the box model attributes for 80 customizing the layout with style sheets. Unfortunately 81 the design of Qt style sheets has no concept how to 82 handle backgrounds with rounded corners - beside of padding. 81 83 82 When HackStyledBackground is enabled the plot canvas tries 83 to separate the background from the background border 84 by reverse engineering to paint the background before and 85 the border after the plot items. In this order the border 86 gets perfectly antialiased and you can avoid some pixel 87 artifacts in the corners. 84 When HackStyledBackground is enabled the plot canvas tries 85 to separate the background from the background border 86 by reverse engineering to paint the background before and 87 the border after the plot items. In this order the border 88 gets perfectly antialiased and you can avoid some pixel 89 artifacts in the corners. 88 90 */ 89 91 HackStyledBackground = 4, 90 92 91 93 /*! 92 When ImmediatePaint is set replot() calls repaint() 93 instead of update(). 94 When ImmediatePaint is set replot() calls repaint() 95 instead of update(). 94 96 95 \sa replot(), QWidget::repaint(), QWidget::update() 97 \sa replot(), QWidget::repaint(), QWidget::update() 96 98 */ 97 99 ImmediatePaint = 8 98 100 }; 99 101 100 //! Paint attributes 101 typedef QFlags<PaintAttribute> PaintAttributes; 102 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 102 103 103 /*! 104 \brief Focus indicator 105 The default setting is NoFocusIndicator 106 \sa setFocusIndicator(), focusIndicator(), drawFocusIndicator() 107 */ 108 109 enum FocusIndicator 110 { 111 //! Don't paint a focus indicator 112 NoFocusIndicator, 113 114 /*! 115 The focus is related to the complete canvas. 116 Paint the focus indicator using drawFocusIndicator() 117 */ 118 CanvasFocusIndicator, 119 120 /*! 121 The focus is related to an item (curve, point, ...) on 122 the canvas. It is up to the application to display a 123 focus indication using f.e. highlighting. 124 */ 125 ItemFocusIndicator 126 }; 127 128 explicit QwtPlotCanvas( QwtPlot * = NULL ); 104 explicit QwtPlotCanvas( QwtPlot* = NULL ); 129 105 virtual ~QwtPlotCanvas(); 130 131 QwtPlot *plot();132 const QwtPlot *plot() const;133 134 void setFocusIndicator( FocusIndicator );135 FocusIndicator focusIndicator() const;136 137 void setBorderRadius( double );138 double borderRadius() const;139 106 140 107 void setPaintAttribute( PaintAttribute, bool on = true ); 141 108 bool testPaintAttribute( PaintAttribute ) const; 142 109 143 const QPixmap *backingStore() const;144 void invalidateBackingStore(); 110 const QPixmap* backingStore() const; 111 Q_INVOKABLE void invalidateBackingStore(); 145 112 146 virtual bool event( QEvent * );113 virtual bool event( QEvent* ) QWT_OVERRIDE; 147 114 148 Q_INVOKABLE QPainterPath borderPath( const QRect & ) const;115 Q_INVOKABLE QPainterPath borderPath( const QRect& ) const; 149 116 150 public Q_SLOTS: 117 public Q_SLOTS: 151 118 void replot(); 152 119 153 protected: 154 virtual void paintEvent( QPaintEvent * );155 virtual void resizeEvent( QResizeEvent * );120 protected: 121 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 122 virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE; 156 123 157 virtual void drawFocusIndicator( QPainter * ); 158 virtual void drawBorder( QPainter * ); 124 virtual void drawBorder( QPainter* ) QWT_OVERRIDE; 159 125 160 void updateStyleSheetInfo(); 161 162 private: 163 void drawCanvas( QPainter *, bool withBackground ); 164 126 private: 165 127 class PrivateData; 166 PrivateData *d_data;128 PrivateData* m_data; 167 129 }; 168 130 -
trunk/BNC/qwt/qwt_plot_curve.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 #include "qwt_scale_map.h" 16 16 #include "qwt_plot.h" 17 #include "qwt_curve_fitter.h" 17 #include "qwt_spline_curve_fitter.h" 18 18 #include "qwt_symbol.h" 19 19 #include "qwt_point_mapper.h" 20 #include "qwt_text.h" 21 #include "qwt_graphic.h" 22 20 23 #include <qpainter.h> 21 #include <qpixmap.h> 22 #include <qalgorithms.h> 23 #include <qmath.h> 24 25 static void qwtUpdateLegendIconSize( QwtPlotCurve *curve ) 24 #include <qpainterpath.h> 25 #include <qnumeric.h> 26 27 #include <climits> 28 29 static inline QRectF qwtIntersectedClipRect( const QRectF& rect, QPainter* painter ) 30 { 31 QRectF clipRect = rect; 32 if ( painter->hasClipping() ) 33 clipRect &= painter->clipBoundingRect(); 34 35 return clipRect; 36 } 37 38 static void qwtUpdateLegendIconSize( QwtPlotCurve* curve ) 26 39 { 27 40 if ( curve->symbol() && … … 35 48 // Avoid, that the line is completely covered by the symbol 36 49 37 int w = qCeil( 1.5 * sz.width() ); 50 int w = qwtCeil( 1.5 * sz.width() ); 38 51 if ( w % 2 ) 39 52 w++; … … 46 59 } 47 60 48 static int qwtVerifyRange( int size, int &i1, int&i2 )61 static int qwtVerifyRange( int size, int& i1, int& i2 ) 49 62 { 50 63 if ( size < 1 ) … … 62 75 class QwtPlotCurve::PrivateData 63 76 { 64 public: 65 PrivateData(): 66 style( QwtPlotCurve::Lines ), 67 baseline( 0.0 ), 68 symbol( NULL ), 69 attributes( 0 ), 70 paintAttributes( 71 QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints ), 72 legendAttributes( 0 ) 73 { 74 pen = QPen( Qt::black ); 77 public: 78 PrivateData() 79 : style( QwtPlotCurve::Lines ) 80 , baseline( 0.0 ) 81 , symbol( NULL ) 82 , pen( Qt::black ) 83 , paintAttributes( QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints ) 84 { 75 85 curveFitter = new QwtSplineCurveFitter; 76 86 } … … 85 95 double baseline; 86 96 87 const QwtSymbol *symbol;88 QwtCurveFitter *curveFitter;97 const QwtSymbol* symbol; 98 QwtCurveFitter* curveFitter; 89 99 90 100 QPen pen; … … 98 108 99 109 /*! 100 Constructor 101 \param title Title of the curve 102 */ 103 QwtPlotCurve::QwtPlotCurve( const QwtText &title ):104 QwtPlotSeriesItem( title ) 110 Constructor 111 \param title Title of the curve 112 */ 113 QwtPlotCurve::QwtPlotCurve( const QwtText& title ) 114 : QwtPlotSeriesItem( title ) 105 115 { 106 116 init(); … … 108 118 109 119 /*! 110 Constructor 111 \param title Title of the curve 112 */ 113 QwtPlotCurve::QwtPlotCurve( const QString &title ):114 QwtPlotSeriesItem( QwtText( title ) ) 120 Constructor 121 \param title Title of the curve 122 */ 123 QwtPlotCurve::QwtPlotCurve( const QString& title ) 124 : QwtPlotSeriesItem( QwtText( title ) ) 115 125 { 116 126 init(); … … 120 130 QwtPlotCurve::~QwtPlotCurve() 121 131 { 122 delete d_data;132 delete m_data; 123 133 } 124 134 … … 129 139 setItemAttribute( QwtPlotItem::AutoScale ); 130 140 131 d_data = new PrivateData;141 m_data = new PrivateData; 132 142 setData( new QwtPointSeriesData() ); 133 143 … … 142 152 143 153 /*! 144 Specify an attribute how to draw the curve 145 146 \param attribute Paint attribute 147 \param on On/Off 148 \sa testPaintAttribute() 149 */ 154 Specify an attribute how to draw the curve 155 156 \param attribute Paint attribute 157 \param on On/Off 158 \sa testPaintAttribute() 159 */ 150 160 void QwtPlotCurve::setPaintAttribute( PaintAttribute attribute, bool on ) 151 161 { 152 162 if ( on ) 153 d_data->paintAttributes |= attribute;163 m_data->paintAttributes |= attribute; 154 164 else 155 d_data->paintAttributes &= ~attribute;165 m_data->paintAttributes &= ~attribute; 156 166 } 157 167 … … 159 169 \return True, when attribute is enabled 160 170 \sa setPaintAttribute() 161 */ 171 */ 162 172 bool QwtPlotCurve::testPaintAttribute( PaintAttribute attribute ) const 163 173 { 164 return ( d_data->paintAttributes & attribute );165 } 166 167 /*! 168 Specify an attribute how to draw the legend icon 169 170 \param attribute Attribute 171 \param on On/Off 172 /sa testLegendAttribute(). legendIcon() 173 */ 174 return ( m_data->paintAttributes & attribute ); 175 } 176 177 /*! 178 Specify an attribute how to draw the legend icon 179 180 \param attribute Attribute 181 \param on On/Off 182 /sa testLegendAttribute(). legendIcon() 183 */ 174 184 void QwtPlotCurve::setLegendAttribute( LegendAttribute attribute, bool on ) 175 185 { … … 177 187 { 178 188 if ( on ) 179 d_data->legendAttributes |= attribute;189 m_data->legendAttributes |= attribute; 180 190 else 181 d_data->legendAttributes &= ~attribute;191 m_data->legendAttributes &= ~attribute; 182 192 183 193 qwtUpdateLegendIconSize( this ); … … 187 197 188 198 /*! 189 \return True, when attribute is enabled 190 \sa setLegendAttribute() 191 */ 199 \return True, when attribute is enabled 200 \sa setLegendAttribute() 201 */ 192 202 bool QwtPlotCurve::testLegendAttribute( LegendAttribute attribute ) const 193 203 { 194 return ( d_data->legendAttributes & attribute ); 195 } 196 197 /*! 198 Set the curve's drawing style 199 200 \param style Curve style 201 \sa style() 202 */ 204 return ( m_data->legendAttributes & attribute ); 205 } 206 207 /*! 208 Specify the attributes how to draw the legend icon 209 210 \param attributes Attributes 211 /sa setLegendAttribute(). legendIcon() 212 */ 213 void QwtPlotCurve::setLegendAttributes( LegendAttributes attributes ) 214 { 215 if ( attributes != m_data->legendAttributes ) 216 { 217 m_data->legendAttributes = attributes; 218 219 qwtUpdateLegendIconSize( this ); 220 legendChanged(); 221 } 222 } 223 224 /*! 225 \return Attributes how to draw the legend icon 226 \sa setLegendAttributes(), testLegendAttribute() 227 */ 228 QwtPlotCurve::LegendAttributes QwtPlotCurve::legendAttributes() const 229 { 230 return m_data->legendAttributes; 231 } 232 233 /*! 234 Set the curve's drawing style 235 236 \param style Curve style 237 \sa style() 238 */ 203 239 void QwtPlotCurve::setStyle( CurveStyle style ) 204 240 { 205 if ( style != d_data->style )206 { 207 d_data->style = style;241 if ( style != m_data->style ) 242 { 243 m_data->style = style; 208 244 209 245 legendChanged(); … … 213 249 214 250 /*! 215 \return Style of the curve 216 \sa setStyle() 217 */ 251 \return Style of the curve 252 \sa setStyle() 253 */ 218 254 QwtPlotCurve::CurveStyle QwtPlotCurve::style() const 219 255 { 220 return d_data->style;221 } 222 223 /*! 224 \brief Assign a symbol 225 226 The curve will take the ownership of the symbol, hence the previously 227 set symbol will be delete by setting a new one. If \p symbol is 228 \c NULL no symbol will be drawn. 229 230 \param symbol Symbol 231 \sa symbol() 232 */ 233 void QwtPlotCurve::setSymbol( QwtSymbol *symbol )234 { 235 if ( symbol != d_data->symbol )236 { 237 delete d_data->symbol;238 d_data->symbol = symbol;256 return m_data->style; 257 } 258 259 /*! 260 \brief Assign a symbol 261 262 The curve will take the ownership of the symbol, hence the previously 263 set symbol will be delete by setting a new one. If \p symbol is 264 \c NULL no symbol will be drawn. 265 266 \param symbol Symbol 267 \sa symbol() 268 */ 269 void QwtPlotCurve::setSymbol( QwtSymbol* symbol ) 270 { 271 if ( symbol != m_data->symbol ) 272 { 273 delete m_data->symbol; 274 m_data->symbol = symbol; 239 275 240 276 qwtUpdateLegendIconSize( this ); … … 246 282 247 283 /*! 248 \return Current symbol or NULL, when no symbol has been assigned 249 \sa setSymbol() 250 */ 251 const QwtSymbol *QwtPlotCurve::symbol() const252 { 253 return d_data->symbol;254 } 255 256 /*! 257 Build and assign a pen 258 259 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 260 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 261 to hide this incompatibility. 262 263 \param color Pen color 264 \param width Pen width 265 \param style Pen style 266 267 \sa pen(), brush() 268 */ 269 void QwtPlotCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style )284 \return Current symbol or NULL, when no symbol has been assigned 285 \sa setSymbol() 286 */ 287 const QwtSymbol* QwtPlotCurve::symbol() const 288 { 289 return m_data->symbol; 290 } 291 292 /*! 293 Build and assign a pen 294 295 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 296 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 297 to hide this incompatibility. 298 299 \param color Pen color 300 \param width Pen width 301 \param style Pen style 302 303 \sa pen(), brush() 304 */ 305 void QwtPlotCurve::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 270 306 { 271 307 setPen( QPen( color, width, style ) ); … … 273 309 274 310 /*! 275 Assign a pen 276 277 \param pen New pen 278 \sa pen(), brush() 279 */ 280 void QwtPlotCurve::setPen( const QPen &pen )281 { 282 if ( pen != d_data->pen )283 { 284 d_data->pen = pen;311 Assign a pen 312 313 \param pen New pen 314 \sa pen(), brush() 315 */ 316 void QwtPlotCurve::setPen( const QPen& pen ) 317 { 318 if ( pen != m_data->pen ) 319 { 320 m_data->pen = pen; 285 321 286 322 legendChanged(); … … 290 326 291 327 /*! 292 \return Pen used to draw the lines 293 \sa setPen(), brush() 294 */ 328 \return Pen used to draw the lines 329 \sa setPen(), brush() 330 */ 295 331 const QPen& QwtPlotCurve::pen() const 296 332 { 297 return d_data->pen;298 } 299 300 /*! 301 \brief Assign a brush. 333 return m_data->pen; 334 } 335 336 /*! 337 \brief Assign a brush. 302 338 303 339 In case of brush.style() != QBrush::NoBrush … … 310 346 (ascending or descending). 311 347 312 \param brush New brush 313 \sa brush(), setBaseline(), baseline() 314 */ 315 void QwtPlotCurve::setBrush( const QBrush &brush )316 { 317 if ( brush != d_data->brush )318 { 319 d_data->brush = brush;348 \param brush New brush 349 \sa brush(), setBaseline(), baseline() 350 */ 351 void QwtPlotCurve::setBrush( const QBrush& brush ) 352 { 353 if ( brush != m_data->brush ) 354 { 355 m_data->brush = brush; 320 356 321 357 legendChanged(); … … 325 361 326 362 /*! 327 \return Brush used to fill the area between lines and the baseline 328 \sa setBrush(), setBaseline(), baseline() 329 */ 363 \return Brush used to fill the area between lines and the baseline 364 \sa setBrush(), setBaseline(), baseline() 365 */ 330 366 const QBrush& QwtPlotCurve::brush() const 331 367 { 332 return d_data->brush;333 } 334 335 /*! 336 Draw an interval of the curve 337 338 \param painter Painter 339 \param xMap Maps x-values into pixel coordinates. 340 \param yMap Maps y-values into pixel coordinates. 341 \param canvasRect Contents rectangle of the canvas 342 \param from Index of the first point to be painted 343 \param to Index of the last point to be painted. If to < 0 the 368 return m_data->brush; 369 } 370 371 /*! 372 Draw an interval of the curve 373 374 \param painter Painter 375 \param xMap Maps x-values into pixel coordinates. 376 \param yMap Maps y-values into pixel coordinates. 377 \param canvasRect Contents rectangle of the canvas 378 \param from Index of the first point to be painted 379 \param to Index of the last point to be painted. If to < 0 the 344 380 curve will be painted to its last point. 345 381 346 \sa drawCurve(), drawSymbols(), 347 */ 348 void QwtPlotCurve::drawSeries( QPainter *painter,349 const QwtScaleMap &xMap, const QwtScaleMap&yMap,350 const QRectF &canvasRect, int from, int to ) const382 \sa drawCurve(), drawSymbols(), 383 */ 384 void QwtPlotCurve::drawSeries( QPainter* painter, 385 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 386 const QRectF& canvasRect, int from, int to ) const 351 387 { 352 388 const size_t numSamples = dataSize(); … … 361 397 { 362 398 painter->save(); 363 painter->setPen( d_data->pen );399 painter->setPen( m_data->pen ); 364 400 365 401 /* 366 Qt 4.0.0 is slow when drawing lines, but it's even 367 slower when the painter has a brush. So we don't 368 set the brush before we really need it. 402 Qt 4.0.0 is slow when drawing lines, but it's even 403 slower when the painter has a brush. So we don't 404 set the brush before we really need it. 369 405 */ 370 406 371 drawCurve( painter, d_data->style, xMap, yMap, canvasRect, from, to );407 drawCurve( painter, m_data->style, xMap, yMap, canvasRect, from, to ); 372 408 painter->restore(); 373 409 374 if ( d_data->symbol &&375 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )410 if ( m_data->symbol && 411 ( m_data->symbol->style() != QwtSymbol::NoSymbol ) ) 376 412 { 377 413 painter->save(); 378 drawSymbols( painter, * d_data->symbol,414 drawSymbols( painter, *m_data->symbol, 379 415 xMap, yMap, canvasRect, from, to ); 380 416 painter->restore(); … … 384 420 385 421 /*! 386 \brief Draw the line part (without symbols) of a curve interval. 387 \param painter Painter 388 \param style curve style, see QwtPlotCurve::CurveStyle 389 \param xMap x map 390 \param yMap y map 391 \param canvasRect Contents rectangle of the canvas 392 \param from index of the first point to be painted 393 \param to index of the last point to be painted 394 \sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks() 395 */ 396 void QwtPlotCurve::drawCurve( QPainter *painter, int style,397 const QwtScaleMap &xMap, const QwtScaleMap&yMap,398 const QRectF &canvasRect, int from, int to ) const422 \brief Draw the line part (without symbols) of a curve interval. 423 \param painter Painter 424 \param style curve style, see QwtPlotCurve::CurveStyle 425 \param xMap x map 426 \param yMap y map 427 \param canvasRect Contents rectangle of the canvas 428 \param from index of the first point to be painted 429 \param to index of the last point to be painted 430 \sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks() 431 */ 432 void QwtPlotCurve::drawCurve( QPainter* painter, int style, 433 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 434 const QRectF& canvasRect, int from, int to ) const 399 435 { 400 436 switch ( style ) … … 426 462 427 463 /*! 428 \brief Draw lines 429 430 If the CurveAttribute Fitted is enabled a QwtCurveFitter tries 431 to interpolate/smooth the curve, before it is painted. 432 433 \param painter Painter 434 \param xMap x map 435 \param yMap y map 436 \param canvasRect Contents rectangle of the canvas 437 \param from index of the first point to be painted 438 \param to index of the last point to be painted 439 440 \sa setCurveAttribute(), setCurveFitter(), draw(), 464 \brief Draw lines 465 466 If the CurveAttribute Fitted is enabled a QwtCurveFitter tries 467 to interpolate/smooth the curve, before it is painted. 468 469 \param painter Painter 470 \param xMap x map 471 \param yMap y map 472 \param canvasRect Contents rectangle of the canvas 473 \param from index of the first point to be painted 474 \param to index of the last point to be painted 475 476 \sa setCurveAttribute(), setCurveFitter(), draw(), 441 477 drawLines(), drawDots(), drawSteps(), drawSticks() 442 */ 443 void QwtPlotCurve::drawLines( QPainter *painter,444 const QwtScaleMap &xMap, const QwtScaleMap&yMap,445 const QRectF &canvasRect, int from, int to ) const478 */ 479 void QwtPlotCurve::drawLines( QPainter* painter, 480 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 481 const QRectF& canvasRect, int from, int to ) const 446 482 { 447 483 if ( from > to ) 448 484 return; 449 485 450 const bool do Align = QwtPainter::roundingAlignment( painter );451 const bool do Fit = ( d_data->attributes & Fitted ) && d_data->curveFitter;452 const bool doFill = ( d_data->brush.style() != Qt::NoBrush )453 && ( d_data->brush.color().alpha() > 0 );486 const bool doFit = ( m_data->attributes & Fitted ) && m_data->curveFitter; 487 const bool doAlign = !doFit && QwtPainter::roundingAlignment( painter ); 488 const bool doFill = ( m_data->brush.style() != Qt::NoBrush ) 489 && ( m_data->brush.color().alpha() > 0 ); 454 490 455 491 QRectF clipRect; 456 if ( d_data->paintAttributes & ClipPolygons ) 457 { 458 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); 459 clipRect = canvasRect.adjusted(-pw, -pw, pw, pw); 460 } 461 462 bool doIntegers = false; 463 464 #if QT_VERSION < 0x040800 465 466 // For Qt <= 4.7 the raster paint engine is significantly faster 467 // for rendering QPolygon than for QPolygonF. So let's 468 // see if we can use it. 469 470 if ( painter->paintEngine()->type() == QPaintEngine::Raster ) 471 { 472 // In case of filling or fitting performance doesn't count 473 // because both operations are much more expensive 474 // then drawing the polyline itself 475 476 if ( !doFit && !doFill ) 477 doIntegers = true; 478 } 479 #endif 480 481 const bool noDuplicates = d_data->paintAttributes & FilterPoints; 492 if ( m_data->paintAttributes & ClipPolygons ) 493 { 494 clipRect = qwtIntersectedClipRect( canvasRect, painter ); 495 496 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); 497 clipRect = clipRect.adjusted(-pw, -pw, pw, pw); 498 } 482 499 483 500 QwtPointMapper mapper; 484 mapper.setFlag( QwtPointMapper::RoundPoints, doAlign ); 485 mapper.setFlag( QwtPointMapper::WeedOutPoints, noDuplicates ); 501 502 if ( doAlign ) 503 { 504 mapper.setFlag( QwtPointMapper::RoundPoints, true ); 505 mapper.setFlag( QwtPointMapper::WeedOutIntermediatePoints, 506 testPaintAttribute( FilterPointsAggressive ) ); 507 } 508 509 mapper.setFlag( QwtPointMapper::WeedOutPoints, 510 testPaintAttribute( FilterPoints ) || 511 testPaintAttribute( FilterPointsAggressive ) ); 512 486 513 mapper.setBoundingRect( canvasRect ); 487 514 488 if ( doIntegers ) 489 { 490 QPolygon polyline = mapper.toPolygon( 491 xMap, yMap, data(), from, to ); 492 493 if ( d_data->paintAttributes & ClipPolygons ) 494 { 495 polyline = QwtClipper::clipPolygon( 496 clipRect.toAlignedRect(), polyline, false ); 497 } 498 499 QwtPainter::drawPolyline( painter, polyline ); 515 QPolygonF polyline = mapper.toPolygonF( xMap, yMap, data(), from, to ); 516 517 if ( doFill ) 518 { 519 if ( doFit ) 520 { 521 // it might be better to extend and draw the curvePath, but for 522 // the moment we keep an implementation, where we translate the 523 // path back to a polyline. 524 525 polyline = m_data->curveFitter->fitCurve( polyline ); 526 } 527 528 if ( painter->pen().style() != Qt::NoPen ) 529 { 530 // here we are wasting memory for the filled copy, 531 // do polygon clipping twice etc .. TODO 532 533 QPolygonF filled = polyline; 534 fillCurve( painter, xMap, yMap, canvasRect, filled ); 535 filled.clear(); 536 537 if ( m_data->paintAttributes & ClipPolygons ) 538 QwtClipper::clipPolygonF( clipRect, polyline, false ); 539 540 QwtPainter::drawPolyline( painter, polyline ); 541 } 542 else 543 { 544 fillCurve( painter, xMap, yMap, canvasRect, polyline ); 545 } 500 546 } 501 547 else 502 548 { 503 QPolygonF polyline = mapper.toPolygonF( xMap, yMap, data(), from, to ); 549 if ( testPaintAttribute( ClipPolygons ) ) 550 { 551 QwtClipper::clipPolygonF( clipRect, polyline, false ); 552 } 504 553 505 554 if ( doFit ) 506 polyline = d_data->curveFitter->fitCurve( polyline ); 507 508 if ( doFill ) 509 { 510 if ( painter->pen().style() != Qt::NoPen ) 555 { 556 if ( m_data->curveFitter->mode() == QwtCurveFitter::Path ) 511 557 { 512 // here we are wasting memory for the filled copy, 513 // do polygon clipping twice etc .. TODO 514 515 QPolygonF filled = polyline; 516 fillCurve( painter, xMap, yMap, canvasRect, filled ); 517 filled.clear(); 518 519 if ( d_data->paintAttributes & ClipPolygons ) 520 { 521 polyline = QwtClipper::clipPolygonF( 522 clipRect, polyline, false ); 523 } 524 525 QwtPainter::drawPolyline( painter, polyline ); 558 const QPainterPath curvePath = 559 m_data->curveFitter->fitCurvePath( polyline ); 560 561 painter->drawPath( curvePath ); 526 562 } 527 563 else 528 564 { 529 fillCurve( painter, xMap, yMap, canvasRect, polyline ); 565 polyline = m_data->curveFitter->fitCurve( polyline ); 566 QwtPainter::drawPolyline( painter, polyline ); 530 567 } 531 568 } 532 569 else 533 570 { 534 if ( d_data->paintAttributes & ClipPolygons )535 {536 polyline = QwtClipper::clipPolygonF(537 clipRect, polyline, false );538 }539 540 571 QwtPainter::drawPolyline( painter, polyline ); 541 572 } … … 544 575 545 576 /*! 546 Draw sticks 547 548 \param painter Painter 549 \param xMap x map 550 \param yMap y map 551 \param canvasRect Contents rectangle of the canvas 552 \param from index of the first point to be painted 553 \param to index of the last point to be painted 554 555 \sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps() 556 */ 557 void QwtPlotCurve::drawSticks( QPainter *painter,558 const QwtScaleMap &xMap, const QwtScaleMap&yMap,559 const QRectF &canvasRect, int from, int to ) const577 Draw sticks 578 579 \param painter Painter 580 \param xMap x map 581 \param yMap y map 582 \param canvasRect Contents rectangle of the canvas 583 \param from index of the first point to be painted 584 \param to index of the last point to be painted 585 586 \sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps() 587 */ 588 void QwtPlotCurve::drawSticks( QPainter* painter, 589 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 590 const QRectF& canvasRect, int from, int to ) const 560 591 { 561 592 Q_UNUSED( canvasRect ) … … 566 597 const bool doAlign = QwtPainter::roundingAlignment( painter ); 567 598 568 double x0 = xMap.transform( d_data->baseline );569 double y0 = yMap.transform( d_data->baseline );599 double x0 = xMap.transform( m_data->baseline ); 600 double y0 = yMap.transform( m_data->baseline ); 570 601 if ( doAlign ) 571 602 { … … 576 607 const Qt::Orientation o = orientation(); 577 608 578 const QwtSeriesData<QPointF > *series = data();609 const QwtSeriesData< QPointF >* series = data(); 579 610 580 611 for ( int i = from; i <= to; i++ ) … … 599 630 600 631 /*! 601 Draw dots 602 603 \param painter Painter 604 \param xMap x map 605 \param yMap y map 606 \param canvasRect Contents rectangle of the canvas 607 \param from index of the first point to be painted 608 \param to index of the last point to be painted 609 610 \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps() 611 */ 612 void QwtPlotCurve::drawDots( QPainter *painter,613 const QwtScaleMap &xMap, const QwtScaleMap&yMap,614 const QRectF &canvasRect, int from, int to ) const632 Draw dots 633 634 \param painter Painter 635 \param xMap x map 636 \param yMap y map 637 \param canvasRect Contents rectangle of the canvas 638 \param from index of the first point to be painted 639 \param to index of the last point to be painted 640 641 \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps() 642 */ 643 void QwtPlotCurve::drawDots( QPainter* painter, 644 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 645 const QRectF& canvasRect, int from, int to ) const 615 646 { 616 647 const QColor color = painter->pen().color(); … … 621 652 } 622 653 623 const bool doFill = ( d_data->brush.style() != Qt::NoBrush )624 && ( d_data->brush.color().alpha() > 0 );654 const bool doFill = ( m_data->brush.style() != Qt::NoBrush ) 655 && ( m_data->brush.color().alpha() > 0 ); 625 656 const bool doAlign = QwtPainter::roundingAlignment( painter ); 626 657 … … 629 660 mapper.setFlag( QwtPointMapper::RoundPoints, doAlign ); 630 661 631 if ( d_data->paintAttributes & FilterPoints )662 if ( m_data->paintAttributes & FilterPoints ) 632 663 { 633 664 if ( ( color.alpha() == 255 ) … … 642 673 mapper.setFlag( QwtPointMapper::WeedOutPoints, false ); 643 674 644 QPolygonF points = mapper.toPo intsF(675 QPolygonF points = mapper.toPolygonF( 645 676 xMap, yMap, data(), from, to ); 646 677 … … 648 679 fillCurve( painter, xMap, yMap, canvasRect, points ); 649 680 } 650 else if ( d_data->paintAttributes & ImageBuffer )681 else if ( m_data->paintAttributes & ImageBuffer ) 651 682 { 652 683 const QImage image = mapper.toImage( xMap, yMap, 653 data(), from, to, d_data->pen,684 data(), from, to, m_data->pen, 654 685 painter->testRenderHint( QPainter::Antialiasing ), 655 686 renderThreadCount() ); … … 657 688 painter->drawImage( canvasRect.toAlignedRect(), image ); 658 689 } 659 else if ( d_data->paintAttributes & MinimizeMemory )660 { 661 const QwtSeriesData<QPointF > *series = data();690 else if ( m_data->paintAttributes & MinimizeMemory ) 691 { 692 const QwtSeriesData< QPointF >* series = data(); 662 693 663 694 for ( int i = from; i <= to; i++ ) … … 697 728 698 729 /*! 699 Draw step function 700 701 The direction of the steps depends on Inverted attribute. 702 703 \param painter Painter 704 \param xMap x map 705 \param yMap y map 706 \param canvasRect Contents rectangle of the canvas 707 \param from index of the first point to be painted 708 \param to index of the last point to be painted 709 710 \sa CurveAttribute, setCurveAttribute(), 730 Draw step function 731 732 The direction of the steps depends on Inverted attribute. 733 734 \param painter Painter 735 \param xMap x map 736 \param yMap y map 737 \param canvasRect Contents rectangle of the canvas 738 \param from index of the first point to be painted 739 \param to index of the last point to be painted 740 741 \sa CurveAttribute, setCurveAttribute(), 711 742 draw(), drawCurve(), drawDots(), drawLines(), drawSticks() 712 */ 713 void QwtPlotCurve::drawSteps( QPainter *painter,714 const QwtScaleMap &xMap, const QwtScaleMap&yMap,715 const QRectF &canvasRect, int from, int to ) const743 */ 744 void QwtPlotCurve::drawSteps( QPainter* painter, 745 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 746 const QRectF& canvasRect, int from, int to ) const 716 747 { 717 748 const bool doAlign = QwtPainter::roundingAlignment( painter ); 718 749 719 750 QPolygonF polygon( 2 * ( to - from ) + 1 ); 720 QPointF *points = polygon.data();751 QPointF* points = polygon.data(); 721 752 722 753 bool inverted = orientation() == Qt::Vertical; 723 if ( d_data->attributes & Inverted )754 if ( m_data->attributes & Inverted ) 724 755 inverted = !inverted; 725 756 726 const QwtSeriesData<QPointF > *series = data();757 const QwtSeriesData< QPointF >* series = data(); 727 758 728 759 int i, ip; … … 740 771 if ( ip > 0 ) 741 772 { 742 const QPointF &p0 = points[ip - 2];743 QPointF &p = points[ip - 1];773 const QPointF& p0 = points[ip - 2]; 774 QPointF& p = points[ip - 1]; 744 775 745 776 if ( inverted ) … … 759 790 } 760 791 761 if ( d_data->paintAttributes & ClipPolygons ) 762 { 763 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); 764 const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw); 765 766 const QPolygonF clipped = QwtClipper::clipPolygonF( 792 if ( m_data->paintAttributes & ClipPolygons ) 793 { 794 QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter ); 795 796 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); 797 clipRect = clipRect.adjusted(-pw, -pw, pw, pw); 798 799 const QPolygonF clipped = QwtClipper::clippedPolygonF( 767 800 clipRect, polygon, false ); 768 801 … … 774 807 } 775 808 776 if ( d_data->brush.style() != Qt::NoBrush )809 if ( m_data->brush.style() != Qt::NoBrush ) 777 810 fillCurve( painter, xMap, yMap, canvasRect, polygon ); 778 811 } … … 780 813 781 814 /*! 782 Specify an attribute for drawing the curve 783 784 \param attribute Curve attribute 785 \param on On/Off 786 787 /sa testCurveAttribute(), setCurveFitter() 788 */ 815 Specify an attribute for drawing the curve 816 817 \param attribute Curve attribute 818 \param on On/Off 819 820 /sa testCurveAttribute(), setCurveFitter() 821 */ 789 822 void QwtPlotCurve::setCurveAttribute( CurveAttribute attribute, bool on ) 790 823 { 791 if ( bool( d_data->attributes & attribute ) == on )824 if ( bool( m_data->attributes & attribute ) == on ) 792 825 return; 793 826 794 827 if ( on ) 795 d_data->attributes |= attribute;828 m_data->attributes |= attribute; 796 829 else 797 d_data->attributes &= ~attribute;830 m_data->attributes &= ~attribute; 798 831 799 832 itemChanged(); … … 803 836 \return true, if attribute is enabled 804 837 \sa setCurveAttribute() 805 */ 838 */ 806 839 bool QwtPlotCurve::testCurveAttribute( CurveAttribute attribute ) const 807 840 { 808 return d_data->attributes & attribute;809 } 810 811 /*! 812 Assign a curve fitter 813 814 The curve fitter "smooths" the curve points, when the Fitted 815 CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting. 816 817 The curve fitter operates on the translated points ( = widget coordinates) 818 to be functional for logarithmic scales. Obviously this is less performant 819 for fitting algorithms, that reduce the number of points. 820 821 For situations, where curve fitting is used to improve the performance 822 of painting huge series of points it might be better to execute the fitter 823 on the curve points once and to cache the result in the QwtSeriesData object. 824 825 \param curveFitter() Curve fitter 826 \sa Fitted 827 */ 828 void QwtPlotCurve::setCurveFitter( QwtCurveFitter *curveFitter )829 { 830 delete d_data->curveFitter;831 d_data->curveFitter = curveFitter;841 return m_data->attributes & attribute; 842 } 843 844 /*! 845 Assign a curve fitter 846 847 The curve fitter "smooths" the curve points, when the Fitted 848 CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting. 849 850 The curve fitter operates on the translated points ( = widget coordinates) 851 to be functional for logarithmic scales. Obviously this is less performant 852 for fitting algorithms, that reduce the number of points. 853 854 For situations, where curve fitting is used to improve the performance 855 of painting huge series of points it might be better to execute the fitter 856 on the curve points once and to cache the result in the QwtSeriesData object. 857 858 \param curveFitter() Curve fitter 859 \sa Fitted 860 */ 861 void QwtPlotCurve::setCurveFitter( QwtCurveFitter* curveFitter ) 862 { 863 delete m_data->curveFitter; 864 m_data->curveFitter = curveFitter; 832 865 833 866 itemChanged(); … … 835 868 836 869 /*! 837 Get the curve fitter. If curve fitting is disabled NULL is returned. 838 839 \return Curve fitter 840 \sa setCurveFitter(), Fitted 841 */ 842 QwtCurveFitter *QwtPlotCurve::curveFitter() const843 { 844 return d_data->curveFitter;845 } 846 847 /*! 848 Fill the area between the curve and the baseline with 849 the curve brush 850 851 \param painter Painter 852 \param xMap x map 853 \param yMap y map 854 \param canvasRect Contents rectangle of the canvas 855 \param polygon Polygon - will be modified ! 856 857 \sa setBrush(), setBaseline(), setStyle() 858 */ 859 void QwtPlotCurve::fillCurve( QPainter *painter,860 const QwtScaleMap &xMap, const QwtScaleMap&yMap,861 const QRectF &canvasRect, QPolygonF&polygon ) const862 { 863 if ( d_data->brush.style() == Qt::NoBrush )870 Get the curve fitter. If curve fitting is disabled NULL is returned. 871 872 \return Curve fitter 873 \sa setCurveFitter(), Fitted 874 */ 875 QwtCurveFitter* QwtPlotCurve::curveFitter() const 876 { 877 return m_data->curveFitter; 878 } 879 880 /*! 881 Fill the area between the curve and the baseline with 882 the curve brush 883 884 \param painter Painter 885 \param xMap x map 886 \param yMap y map 887 \param canvasRect Contents rectangle of the canvas 888 \param polygon Polygon - will be modified ! 889 890 \sa setBrush(), setBaseline(), setStyle() 891 */ 892 void QwtPlotCurve::fillCurve( QPainter* painter, 893 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 894 const QRectF& canvasRect, QPolygonF& polygon ) const 895 { 896 if ( m_data->brush.style() == Qt::NoBrush ) 864 897 return; 865 898 … … 868 901 return; 869 902 870 QBrush brush = d_data->brush;903 QBrush brush = m_data->brush; 871 904 if ( !brush.color().isValid() ) 872 brush.setColor( d_data->pen.color() ); 873 874 if ( d_data->paintAttributes & ClipPolygons ) 875 polygon = QwtClipper::clipPolygonF( canvasRect, polygon, true ); 905 brush.setColor( m_data->pen.color() ); 906 907 if ( m_data->paintAttributes & ClipPolygons ) 908 { 909 const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter ); 910 QwtClipper::clipPolygonF( clipRect, polygon, true ); 911 } 876 912 877 913 painter->save(); … … 886 922 887 923 /*! 888 \brief Complete a polygon to be a closed polygon including the 924 \brief Complete a polygon to be a closed polygon including the 889 925 area between the original polygon and the baseline. 890 926 891 \param painter Painter 892 \param xMap X map 893 \param yMap Y map 894 \param polygon Polygon to be completed 895 */ 896 void QwtPlotCurve::closePolyline( QPainter *painter,897 const QwtScaleMap &xMap, const QwtScaleMap&yMap,898 QPolygonF &polygon ) const927 \param painter Painter 928 \param xMap X map 929 \param yMap Y map 930 \param polygon Polygon to be completed 931 */ 932 void QwtPlotCurve::closePolyline( QPainter* painter, 933 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 934 QPolygonF& polygon ) const 899 935 { 900 936 if ( polygon.size() < 2 ) … … 903 939 const bool doAlign = QwtPainter::roundingAlignment( painter ); 904 940 905 double baseline = d_data->baseline;941 double baseline = m_data->baseline; 906 942 907 943 if ( orientation() == Qt::Vertical ) … … 911 947 912 948 double refY = yMap.transform( baseline ); 913 if ( doAlign ) 949 if ( doAlign && qAbs( refY ) < std::numeric_limits< int >::max() ) 914 950 refY = qRound( refY ); 915 951 … … 923 959 924 960 double refX = xMap.transform( baseline ); 925 if ( doAlign ) 961 if ( doAlign && qAbs( refX ) < std::numeric_limits< int >::max() ) 926 962 refX = qRound( refX ); 927 963 … … 932 968 933 969 /*! 934 Draw symbols 935 936 \param painter Painter 937 \param symbol Curve symbol 938 \param xMap x map 939 \param yMap y map 940 \param canvasRect Contents rectangle of the canvas 941 \param from Index of the first point to be painted 942 \param to Index of the last point to be painted 943 944 \sa setSymbol(), drawSeries(), drawCurve() 945 */ 946 void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol&symbol,947 const QwtScaleMap &xMap, const QwtScaleMap&yMap,948 const QRectF &canvasRect, int from, int to ) const970 Draw symbols 971 972 \param painter Painter 973 \param symbol Curve symbol 974 \param xMap x map 975 \param yMap y map 976 \param canvasRect Contents rectangle of the canvas 977 \param from Index of the first point to be painted 978 \param to Index of the last point to be painted 979 980 \sa setSymbol(), drawSeries(), drawCurve() 981 */ 982 void QwtPlotCurve::drawSymbols( QPainter* painter, const QwtSymbol& symbol, 983 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 984 const QRectF& canvasRect, int from, int to ) const 949 985 { 950 986 QwtPointMapper mapper; … … 953 989 mapper.setFlag( QwtPointMapper::WeedOutPoints, 954 990 testPaintAttribute( QwtPlotCurve::FilterPoints ) ); 955 mapper.setBoundingRect( canvasRect ); 991 992 const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter ); 993 mapper.setBoundingRect( clipRect ); 956 994 957 995 const int chunkSize = 500; … … 970 1008 971 1009 /*! 972 \brief Set the value of the baseline 973 974 The baseline is needed for filling the curve with a brush or 975 the Sticks drawing style. 976 977 The interpretation of the baseline depends on the orientation(). 978 With Qt::Vertical, the baseline is interpreted as a horizontal line 979 at y = baseline(), with Qt::Horizontal, it is interpreted as a vertical 980 line at x = baseline(). 981 982 The default value is 0.0. 983 984 \param value Value of the baseline 985 \sa baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation() 986 */ 1010 \brief Set the value of the baseline 1011 1012 The baseline is needed for filling the curve with a brush or 1013 the Sticks drawing style. 1014 1015 The interpretation of the baseline depends on the orientation(). 1016 With Qt::Vertical, the baseline is interpreted as a horizontal line 1017 at y = baseline(), with Qt::Horizontal, it is interpreted as a vertical 1018 line at x = baseline(). 1019 1020 The default value is 0.0. 1021 1022 \param value Value of the baseline 1023 \sa baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation() 1024 */ 987 1025 void QwtPlotCurve::setBaseline( double value ) 988 1026 { 989 if ( d_data->baseline != value )990 { 991 d_data->baseline = value;1027 if ( m_data->baseline != value ) 1028 { 1029 m_data->baseline = value; 992 1030 itemChanged(); 993 1031 } … … 995 1033 996 1034 /*! 997 \return Value of the baseline 998 \sa setBaseline() 999 */ 1035 \return Value of the baseline 1036 \sa setBaseline() 1037 */ 1000 1038 double QwtPlotCurve::baseline() const 1001 1039 { 1002 return d_data->baseline;1003 } 1004 1005 /*! 1006 Find the closest curve point for a specific position 1007 1008 \param pos Position, where to look for the closest curve point 1009 \param dist If dist != NULL, closestPoint() returns the distance between 1010 the position and the closest curve point 1011 \return Index of the closest curve point, or -1 if none can be found 1040 return m_data->baseline; 1041 } 1042 1043 /*! 1044 Find the closest curve point for a specific position 1045 1046 \param pos Position, where to look for the closest curve point 1047 \param dist If dist != NULL, closestPoint() returns the distance between 1048 the position and the closest curve point in paint device coordinates 1049 \return Index of the closest curve point, or -1 if none can be found 1012 1050 ( f.e when the curve has no points ) 1013 \note closestPoint() implements a dumb algorithm, that iterates 1051 \note closestPoint() implements a dumb algorithm, that iterates 1014 1052 over all points 1015 */ 1016 int QwtPlotCurve::closestPoint( const QPoint &pos, double *dist ) const 1017 { 1053 */ 1054 int QwtPlotCurve::closestPoint( const QPointF& pos, double* dist ) const 1055 { 1056 const QwtPlot* plot = this->plot(); 1057 1058 if ( ( plot == NULL ) || !plot->isAxisValid( xAxis() ) || !plot->isAxisValid( yAxis() ) ) 1059 return -1; 1060 1018 1061 const size_t numSamples = dataSize(); 1019 1020 if ( plot() == NULL || numSamples <= 0 ) 1062 if ( numSamples <= 0 ) 1021 1063 return -1; 1022 1064 1023 const QwtSeriesData<QPointF > *series = data();1024 1025 const QwtScaleMap xMap = plot ()->canvasMap( xAxis() );1026 const QwtScaleMap yMap = plot ()->canvasMap( yAxis() );1065 const QwtSeriesData< QPointF >* series = data(); 1066 1067 const QwtScaleMap xMap = plot->canvasMap( xAxis() ); 1068 const QwtScaleMap yMap = plot->canvasMap( yAxis() ); 1027 1069 1028 1070 int index = -1; … … 1044 1086 } 1045 1087 if ( dist ) 1046 *dist = qSqrt( dmin );1088 *dist = std::sqrt( dmin ); 1047 1089 1048 1090 return index; 1091 } 1092 1093 /*! 1094 Find the curve point with the smallest coordinate larger than a specific value 1095 The coordinates have to be monotonic in direction of the orientation. 1096 1097 \param orientation Qt::Horizontal corresponds to x, Qt::Vertical to y coordinates 1098 \param value x or y coordinate, depending on the orientation 1099 1100 \return Index of the curve point with the smalles coordinate above value 1101 or -1 if there is none. 1102 1103 \note The implementation uses a binary search algorithm and requires the 1104 points being ordered in direction of the orientation. 1105 1106 \sa qwtUpperSampleIndex() 1107 */ 1108 int QwtPlotCurve::adjacentPoint( Qt::Orientation orientation, qreal value ) const 1109 { 1110 const QwtSeriesData< QPointF >* data = this->data(); 1111 if ( data == NULL ) 1112 return -1; 1113 1114 if ( orientation == Qt::Horizontal ) 1115 { 1116 struct compareX 1117 { 1118 inline bool operator()( const double x, const QPointF& pos ) const 1119 { 1120 return ( x < pos.x() ); 1121 } 1122 }; 1123 1124 return qwtUpperSampleIndex< QPointF >( *data, value, compareX() ); 1125 } 1126 else 1127 { 1128 struct compareY 1129 { 1130 inline bool operator()( const double y, const QPointF& pos ) const 1131 { 1132 return ( y < pos.y() ); 1133 } 1134 }; 1135 1136 return qwtUpperSampleIndex< QPointF >( *data, value, compareY() ); 1137 } 1138 1139 return -1; 1140 } 1141 1142 /*! 1143 Calculate a fictive curve point by interpolating between the adjacent 1144 points. The curve points have to be monotonic in direction of the orientation. 1145 1146 \param orientation For Qt::Horizontal value is a x coordinate and a y coordinate 1147 is returned. For Qt::Vertical value is a x coordinate 1148 \param value x or y coordinate, depending on the orientation 1149 1150 \return Interpolated coordinate or qQNaN() if value is outside the bounding 1151 rectangle of the curve 1152 1153 \note The implementation uses a binary search algorithm and requires the 1154 points being ordered in direction of the orientation. 1155 1156 \sa adjacentPoint() 1157 */ 1158 qreal QwtPlotCurve::interpolatedValueAt( Qt::Orientation orientation, double value ) const 1159 { 1160 const QRectF br = boundingRect(); 1161 if ( br.width() <= 0.0 ) 1162 return qQNaN(); 1163 1164 double v; 1165 1166 if ( orientation == Qt::Horizontal ) 1167 { 1168 if ( value < br.left() || value > br.right() ) 1169 return qQNaN(); 1170 1171 const int index = adjacentPoint( orientation, value ); 1172 1173 if ( index == -1 ) 1174 { 1175 const QPointF last = sample( dataSize() - 1 ); 1176 1177 if ( value != last.x() ) 1178 return qQNaN(); 1179 1180 v = last.y(); 1181 } 1182 else 1183 { 1184 const QLineF line( sample( index - 1 ), sample( index ) ); 1185 v = line.pointAt( ( value - line.p1().x() ) / line.dx() ).y(); 1186 } 1187 } 1188 else 1189 { 1190 if ( value < br.top() || value > br.bottom() ) 1191 return qQNaN(); 1192 1193 const int index = adjacentPoint( orientation, value ); 1194 1195 if ( index == -1 ) 1196 { 1197 const QPointF last = sample( dataSize() - 1 ); 1198 1199 if ( value != last.y() ) 1200 return qQNaN(); 1201 1202 v = last.x(); 1203 } 1204 else 1205 { 1206 const QLineF line( sample( index - 1 ), sample( index ) ); 1207 v = line.pointAt( ( value - line.p1().y() ) / line.dy() ).x(); 1208 } 1209 } 1210 1211 return v; 1049 1212 } 1050 1213 … … 1058 1221 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 1059 1222 */ 1060 QwtGraphic QwtPlotCurve::legendIcon( int index, 1061 const QSizeF &size ) const 1223 QwtGraphic QwtPlotCurve::legendIcon( int index, const QSizeF& size ) const 1062 1224 { 1063 1225 Q_UNUSED( index ); … … 1074 1236 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 1075 1237 1076 if ( d_data->legendAttributes == 0 ||1077 d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )1078 { 1079 QBrush brush = d_data->brush;1238 if ( m_data->legendAttributes == 0 || 1239 m_data->legendAttributes & QwtPlotCurve::LegendShowBrush ) 1240 { 1241 QBrush brush = m_data->brush; 1080 1242 1081 1243 if ( brush.style() == Qt::NoBrush && 1082 d_data->legendAttributes == 0 )1244 m_data->legendAttributes == 0 ) 1083 1245 { 1084 1246 if ( style() != QwtPlotCurve::NoCurve ) … … 1086 1248 brush = QBrush( pen().color() ); 1087 1249 } 1088 else if ( d_data->symbol &&1089 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )1250 else if ( m_data->symbol && 1251 ( m_data->symbol->style() != QwtSymbol::NoSymbol ) ) 1090 1252 { 1091 brush = QBrush( d_data->symbol->pen().color() );1253 brush = QBrush( m_data->symbol->pen().color() ); 1092 1254 } 1093 1255 } … … 1100 1262 } 1101 1263 1102 if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )1264 if ( m_data->legendAttributes & QwtPlotCurve::LegendShowLine ) 1103 1265 { 1104 1266 if ( pen() != Qt::NoPen ) … … 1114 1276 } 1115 1277 1116 if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )1117 { 1118 if ( d_data->symbol )1278 if ( m_data->legendAttributes & QwtPlotCurve::LegendShowSymbol ) 1279 { 1280 if ( m_data->symbol ) 1119 1281 { 1120 1282 QRectF r( 0, 0, size.width(), size.height() ); 1121 d_data->symbol->drawSymbol( &painter, r );1283 m_data->symbol->drawSymbol( &painter, r ); 1122 1284 } 1123 1285 } … … 1127 1289 1128 1290 /*! 1129 Initialize data with an array of points. 1130 1131 \param samples Vector of points 1132 \note QVector is implicitly shared 1133 \note QPolygonF is derived from QVector<QPointF> 1134 */ 1135 void QwtPlotCurve::setSamples( const QVector<QPointF> &samples ) 1291 Assign a series of points 1292 1293 setSamples() is just a wrapper for setData() without any additional 1294 value - beside that it is easier to find for the developer. 1295 1296 \param data Data 1297 \warning The item takes ownership of the data object, deleting 1298 it when its not used anymore. 1299 */ 1300 void QwtPlotCurve::setSamples( QwtSeriesData< QPointF >* data ) 1301 { 1302 setData( data ); 1303 } 1304 1305 /*! 1306 Initialize data with an array of points. 1307 1308 \param samples Vector of points 1309 \note QVector is implicitly shared 1310 \note QPolygonF is derived from QVector<QPointF> 1311 */ 1312 void QwtPlotCurve::setSamples( const QVector< QPointF >& samples ) 1136 1313 { 1137 1314 setData( new QwtPointSeriesData( samples ) ); … … 1139 1316 1140 1317 /*! 1141 Assign a series of points 1142 1143 setSamples() is just a wrapper for setData() without any additional 1144 value - beside that it is easier to find for the developer. 1145 1146 \param data Data 1147 \warning The item takes ownership of the data object, deleting 1148 it when its not used anymore. 1149 */ 1150 void QwtPlotCurve::setSamples( QwtSeriesData<QPointF> *data ) 1151 { 1152 setData( data ); 1153 } 1154 1155 #ifndef QWT_NO_COMPAT 1156 1157 /*! 1158 \brief Initialize the data by pointing to memory blocks which 1318 \brief Initialize the data by pointing to memory blocks which 1159 1319 are not managed by QwtPlotCurve. 1160 1320 1161 setRawSamples is provided for efficiency. 1162 It is important to keep the pointers 1163 during the lifetime of the underlying QwtCPointerData class. 1164 1165 \param xData pointer to x data 1166 \param yData pointer to y data 1167 \param size size of x and y 1168 1169 \sa QwtCPointerData 1170 */ 1321 setRawSamples is provided for efficiency. 1322 It is important to keep the pointers 1323 during the lifetime of the underlying QwtCPointerData class. 1324 1325 \param xData pointer to x data 1326 \param yData pointer to y data 1327 \param size size of x and y 1328 1329 \sa QwtCPointerData 1330 */ 1171 1331 void QwtPlotCurve::setRawSamples( 1172 const double *xData, const double *yData, int size ) 1173 { 1174 setData( new QwtCPointerData( xData, yData, size ) ); 1175 } 1176 1177 /*! 1178 Set data by copying x- and y-values from specified memory blocks. 1179 Contrary to setRawSamples(), this function makes a 'deep copy' of 1180 the data. 1181 1182 \param xData pointer to x values 1183 \param yData pointer to y values 1184 \param size size of xData and yData 1185 1186 \sa QwtPointArrayData 1187 */ 1332 const double* xData, const double* yData, int size ) 1333 { 1334 setData( new QwtCPointerData< double >( xData, yData, size ) ); 1335 } 1336 1337 /*! 1338 \brief Initialize the data by pointing to memory blocks which 1339 are not managed by QwtPlotCurve. 1340 1341 setRawSamples is provided for efficiency. 1342 It is important to keep the pointers 1343 during the lifetime of the underlying QwtCPointerData class. 1344 1345 \param xData pointer to x data 1346 \param yData pointer to y data 1347 \param size size of x and y 1348 1349 \sa QwtCPointerData 1350 */ 1351 void QwtPlotCurve::setRawSamples( 1352 const float* xData, const float* yData, int size ) 1353 { 1354 setData( new QwtCPointerData< float >( xData, yData, size ) ); 1355 } 1356 1357 /*! 1358 \brief Initialize the data by pointing to a memory block which 1359 is not managed by QwtPlotCurve. 1360 1361 The memory contains the y coordinates, while the index is 1362 interpreted as x coordinate. 1363 1364 setRawSamples() is provided for efficiency. It is important to 1365 keep the pointers during the lifetime of the underlying 1366 QwtCPointerValueData class. 1367 1368 \param yData pointer to y data 1369 \param size size of x and y 1370 1371 \sa QwtCPointerData 1372 */ 1373 void QwtPlotCurve::setRawSamples( const double* yData, int size ) 1374 { 1375 setData( new QwtCPointerValueData< double >( yData, size ) ); 1376 } 1377 1378 /*! 1379 \brief Initialize the data by pointing to memory blocks which 1380 are not managed by QwtPlotCurve. 1381 1382 The memory contains the y coordinates, while the index is 1383 interpreted as x coordinate. 1384 1385 setRawSamples() is provided for efficiency. It is important to 1386 keep the pointers during the lifetime of the underlying 1387 QwtCPointerValueData class. 1388 1389 \param yData pointer to y data 1390 \param size size of x and y 1391 1392 \sa QwtCPointerData 1393 */ 1394 void QwtPlotCurve::setRawSamples( const float* yData, int size ) 1395 { 1396 setData( new QwtCPointerValueData< float >( yData, size ) ); 1397 } 1398 1399 /*! 1400 Set data by copying x- and y-values from specified memory blocks. 1401 Contrary to setRawSamples(), this function makes a 'deep copy' of 1402 the data. 1403 1404 \param xData pointer to x values 1405 \param yData pointer to y values 1406 \param size size of xData and yData 1407 1408 \sa QwtPointArrayData 1409 */ 1188 1410 void QwtPlotCurve::setSamples( 1189 const double *xData, const double *yData, int size ) 1190 { 1191 setData( new QwtPointArrayData( xData, yData, size ) ); 1192 } 1193 1194 /*! 1195 \brief Initialize data with x- and y-arrays (explicitly shared) 1196 1197 \param xData x data 1198 \param yData y data 1199 1200 \sa QwtPointArrayData 1201 */ 1202 void QwtPlotCurve::setSamples( const QVector<double> &xData, 1203 const QVector<double> &yData ) 1204 { 1205 setData( new QwtPointArrayData( xData, yData ) ); 1206 } 1207 1208 #endif // !QWT_NO_COMPAT 1209 1411 const double* xData, const double* yData, int size ) 1412 { 1413 setData( new QwtPointArrayData< double >( xData, yData, size ) ); 1414 } 1415 1416 /*! 1417 Set data by copying x- and y-values from specified memory blocks. 1418 Contrary to setRawSamples(), this function makes a 'deep copy' of 1419 the data. 1420 1421 \param xData pointer to x values 1422 \param yData pointer to y values 1423 \param size size of xData and yData 1424 1425 \sa QwtPointArrayData 1426 */ 1427 void QwtPlotCurve::setSamples( 1428 const float* xData, const float* yData, int size ) 1429 { 1430 setData( new QwtPointArrayData< float >( xData, yData, size ) ); 1431 } 1432 1433 /*! 1434 \brief Initialize data with x- and y-arrays (explicitly shared) 1435 1436 \param xData x data 1437 \param yData y data 1438 1439 \sa QwtPointArrayData 1440 */ 1441 void QwtPlotCurve::setSamples( const QVector< double >& xData, 1442 const QVector< double >& yData ) 1443 { 1444 setData( new QwtPointArrayData< double >( xData, yData ) ); 1445 } 1446 1447 /*! 1448 \brief Initialize data with x- and y-arrays (explicitly shared) 1449 1450 \param xData x data 1451 \param yData y data 1452 1453 \sa QwtPointArrayData 1454 */ 1455 void QwtPlotCurve::setSamples( const QVector< float >& xData, 1456 const QVector< float >& yData ) 1457 { 1458 setData( new QwtPointArrayData< float >( xData, yData ) ); 1459 } 1460 1461 /*! 1462 Set data by copying y-values from a specified memory block. 1463 1464 The memory contains the y coordinates, while the index is 1465 interpreted as x coordinate. 1466 1467 \param yData y data 1468 \param size size of yData 1469 1470 \sa QwtValuePointData 1471 */ 1472 void QwtPlotCurve::setSamples( const double* yData, int size ) 1473 { 1474 setData( new QwtValuePointData< double >( yData, size ) ); 1475 } 1476 1477 /*! 1478 Set data by copying y-values from a specified memory block. 1479 1480 The vector contains the y coordinates, while the index is 1481 interpreted as x coordinate. 1482 1483 \param yData y data 1484 \param size size of yData 1485 1486 \sa QwtValuePointData 1487 */ 1488 void QwtPlotCurve::setSamples( const float* yData, int size ) 1489 { 1490 setData( new QwtValuePointData< float >( yData, size ) ); 1491 } 1492 1493 /*! 1494 Initialize data with an array of y values (explicitly shared) 1495 1496 The vector contains the y coordinates, while the index is 1497 the x coordinate. 1498 1499 \param yData y data 1500 1501 \sa QwtValuePointData 1502 */ 1503 void QwtPlotCurve::setSamples( const QVector< double >& yData ) 1504 { 1505 setData( new QwtValuePointData< double >( yData ) ); 1506 } 1507 1508 /*! 1509 Initialize data with an array of y values (explicitly shared) 1510 1511 The vector contains the y coordinates, while the index is 1512 the x coordinate. 1513 1514 \param yData y data 1515 1516 \sa QwtValuePointData 1517 */ 1518 void QwtPlotCurve::setSamples( const QVector< float >& yData ) 1519 { 1520 setData( new QwtValuePointData< float >( yData ) ); 1521 } -
trunk/BNC/qwt/qwt_plot_curve.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_seriesitem.h" 15 #include "qwt_series_data.h" 16 #include "qwt_text.h" 17 #include <qpen.h> 15 18 16 #include <qstring.h> 19 17 20 class QPainter;21 class QPolygonF;22 18 class QwtScaleMap; 23 19 class QwtSymbol; 24 20 class QwtCurveFitter; 21 template< typename T > class QwtSeriesData; 22 class QwtText; 23 class QPainter; 24 class QPolygonF; 25 class QPen; 25 26 26 27 /*! 27 \brief A plot item, that represents a series of points 28 29 A curve is the representation of a series of points in the x-y plane. 30 It supports different display styles, interpolation ( f.e. spline ) 31 and symbols. 32 33 \par Usage 34 <dl><dt>a) Assign curve properties</dt> 35 <dd>When a curve is created, it is configured to draw black solid lines 36 with in QwtPlotCurve::Lines style and no symbols. 37 You can change this by calling 38 setPen(), setStyle() and setSymbol().</dd> 39 <dt>b) Connect/Assign data.</dt> 40 <dd>QwtPlotCurve gets its points using a QwtSeriesData object offering 41 a bridge to the real storage of the points ( like QAbstractItemModel ). 42 There are several convenience classes derived from QwtSeriesData, that also store 43 the points inside ( like QStandardItemModel ). QwtPlotCurve also offers 44 a couple of variations of setSamples(), that build QwtSeriesData objects from 45 arrays internally.</dd> 46 <dt>c) Attach the curve to a plot</dt> 47 <dd>See QwtPlotItem::attach() 48 </dd></dl> 49 50 \par Example: 51 see examples/bode 52 53 \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap 54 */ 55 class QWT_EXPORT QwtPlotCurve: 56 public QwtPlotSeriesItem, public QwtSeriesStore<QPointF> 57 { 58 public: 28 \brief A plot item, that represents a series of points 29 30 A curve is the representation of a series of points in the x-y plane. 31 It supports different display styles, interpolation ( f.e. spline ) 32 and symbols. 33 34 \par Usage 35 <dl><dt>a) Assign curve properties</dt> 36 <dd>When a curve is created, it is configured to draw black solid lines 37 with in QwtPlotCurve::Lines style and no symbols. 38 You can change this by calling 39 setPen(), setStyle() and setSymbol().</dd> 40 <dt>b) Connect/Assign data.</dt> 41 <dd>QwtPlotCurve gets its points using a QwtSeriesData object offering 42 a bridge to the real storage of the points ( like QAbstractItemModel ). 43 There are several convenience classes derived from QwtSeriesData, that also store 44 the points inside ( like QStandardItemModel ). QwtPlotCurve also offers 45 a couple of variations of setSamples(), that build QwtSeriesData objects from 46 arrays internally.</dd> 47 <dt>c) Attach the curve to a plot</dt> 48 <dd>See QwtPlotItem::attach() 49 </dd></dl> 50 51 \par Example: 52 see examples/bode 53 54 \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap 55 */ 56 class QWT_EXPORT QwtPlotCurve 57 : public QwtPlotSeriesItem 58 , public QwtSeriesStore< QPointF > 59 { 60 public: 59 61 /*! 60 62 Curve styles. 61 63 \sa setStyle(), style() 62 */ 64 */ 63 65 enum CurveStyle 64 66 { 65 67 /*! 66 68 Don't draw a curve. Note: This doesn't affect the symbols. 67 */ 69 */ 68 70 NoCurve = -1, 69 71 … … 72 74 be interpolated depending on the 'Fitted' attribute. Curve 73 75 fitting can be configured using setCurveFitter(). 74 */ 76 */ 75 77 Lines, 76 78 … … 78 80 Draw vertical or horizontal sticks ( depending on the 79 81 orientation() ) from a baseline which is defined by setBaseline(). 80 */ 82 */ 81 83 Sticks, 82 84 … … 85 87 is drawn from the left to the right or vice versa, 86 88 depending on the QwtPlotCurve::Inverted attribute. 87 */ 89 */ 88 90 Steps, 89 91 … … 93 95 as a curve in QwtPlotCurve::NoStyle style and a symbol 94 96 painting a point. 95 */ 97 */ 96 98 Dots, 97 99 … … 100 102 classes of QwtPlotCurve that overload drawCurve() with 101 103 additional application specific curve types. 102 */ 104 */ 103 105 UserCurve = 100 104 106 }; 105 107 106 108 /*! 107 Attribute for drawing the curve 108 \sa setCurveAttribute(), testCurveAttribute(), curveFitter() 109 */ 109 Attribute for drawing the curve 110 \sa setCurveAttribute(), testCurveAttribute(), curveFitter() 111 */ 110 112 enum CurveAttribute 111 113 { … … 117 119 118 120 /*! 119 Only in combination with QwtPlotCurve::Lines 120 A QwtCurveFitter tries to 121 interpolate/smooth the curve, before it is painted. 122 123 \note Curve fitting requires temporary memory 124 for calculating coefficients and additional points. 125 If painting in QwtPlotCurve::Fitted mode is slow it might be better 126 to fit the points, before they are passed to QwtPlotCurve. 121 Only in combination with QwtPlotCurve::Lines 122 A QwtCurveFitter tries to 123 interpolate/smooth the curve, before it is painted. 124 125 \note Curve fitting requires temporary memory 126 for calculating coefficients and additional points. 127 If painting in QwtPlotCurve::Fitted mode is slow it might be better 128 to fit the points, before they are passed to QwtPlotCurve. 127 129 */ 128 130 Fitted = 0x02 129 131 }; 130 132 131 //! Curve attributes 132 typedef QFlags<CurveAttribute> CurveAttributes; 133 Q_DECLARE_FLAGS( CurveAttributes, CurveAttribute ) 133 134 134 135 /*! … … 142 143 { 143 144 /*! 144 QwtPlotCurve tries to find a color representing the curve 145 and paints a rectangle with it. 145 QwtPlotCurve tries to find a color representing the curve 146 and paints a rectangle with it. 146 147 */ 147 148 LegendNoAttribute = 0x00, 148 149 149 150 /*! 150 If the style() is not QwtPlotCurve::NoCurve a line 151 is painted with the curve pen(). 151 If the style() is not QwtPlotCurve::NoCurve a line 152 is painted with the curve pen(). 152 153 */ 153 154 LegendShowLine = 0x01, 154 155 155 156 /*! 156 If the curve has a valid symbol it is painted. 157 If the curve has a valid symbol it is painted. 157 158 */ 158 159 LegendShowSymbol = 0x02, 159 160 160 161 /*! 161 If the curve has a brush a rectangle filled with the 162 curve brush() is painted. 162 If the curve has a brush a rectangle filled with the 163 curve brush() is painted. 163 164 */ 164 165 LegendShowBrush = 0x04 165 166 }; 166 167 167 //! Legend attributes 168 typedef QFlags<LegendAttribute> LegendAttributes; 168 Q_DECLARE_FLAGS( LegendAttributes, LegendAttribute ) 169 169 170 170 /*! … … 173 173 174 174 \sa setPaintAttribute(), testPaintAttribute() 175 */ 175 */ 176 176 enum PaintAttribute 177 177 { 178 178 /*! 179 Clip polygons before painting them. In situations, where points 180 are far outside the visible area (f.e when zooming deep) this 181 might be a substantial improvement for the painting performance 179 Clip polygons before painting them. In situations, where points 180 are far outside the visible area (f.e when zooming deep) this 181 might be a substantial improvement for the painting performance 182 182 */ 183 183 ClipPolygons = 0x01, 184 184 185 185 /*! 186 Tries to reduce the data that has to be painted, by sorting out 187 duplicates, or paintings outside the visible area. Might have a 188 notable impact on curves with many close points. 189 Only a couple of very basic filtering algorithms are implemented. 186 Tries to reduce the data that has to be painted, by sorting out 187 duplicates, or paintings outside the visible area. Might have a 188 notable impact on curves with many close points. 189 Only a couple of very basic filtering algorithms are implemented. 190 190 */ 191 191 FilterPoints = 0x02, 192 192 193 193 /*! 194 Minimize memory usage that is temporarily needed for the 195 translated points, before they get painted. 196 This might slow down the performance of painting 194 Minimize memory usage that is temporarily needed for the 195 translated points, before they get painted. 196 This might slow down the performance of painting 197 197 */ 198 198 MinimizeMemory = 0x04, 199 199 200 200 /*! 201 Render the points to a temporary image and paint the image. 202 This is a very special optimization for Dots style, when 203 having a huge amount of points. 204 With a reasonable number of points QPainter::drawPoints() 205 will be faster. 206 */ 207 ImageBuffer = 0x08 201 Render the points to a temporary image and paint the image. 202 This is a very special optimization for Dots style, when 203 having a huge amount of points. 204 With a reasonable number of points QPainter::drawPoints() 205 will be faster. 206 */ 207 ImageBuffer = 0x08, 208 209 /*! 210 More aggressive point filtering trying to filter out 211 intermediate points, accepting minor visual differences. 212 213 Has only an effect, when drawing the curve to a paint device 214 in integer coordinates ( f.e. all widgets on screen ) using the fact, 215 that consecutive points are often mapped to the same x or y coordinate. 216 Each chunk of samples mapped to the same coordinate can be reduced to 217 4 points ( first, min, max last ). 218 219 In the worst case the polygon to be rendered will be 4 times the width 220 of the plot canvas. 221 222 The algorithm is very fast and effective for huge datasets, and can be used 223 inside a replot cycle. 224 225 \note Implemented for QwtPlotCurve::Lines only 226 \note As this algo replaces many small lines by a long one 227 a nasty bug of the raster paint engine ( Qt 4.8, Qt 5.1 - 5.3 ) 228 becomes more dominant. For these versions the bug can be 229 worked around by enabling the QwtPainter::polylineSplitting() mode. 230 */ 231 FilterPointsAggressive = 0x10, 208 232 }; 209 233 210 //! Paint attributes 211 typedef QFlags<PaintAttribute> PaintAttributes; 212 213 explicit QwtPlotCurve( const QString &title = QString() ); 214 explicit QwtPlotCurve( const QwtText &title ); 234 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 235 236 explicit QwtPlotCurve( const QString& title = QString() ); 237 explicit QwtPlotCurve( const QwtText& title ); 215 238 216 239 virtual ~QwtPlotCurve(); 217 240 218 virtual int rtti() const; 241 virtual int rtti() const QWT_OVERRIDE; 219 242 220 243 void setPaintAttribute( PaintAttribute, bool on = true ); … … 224 247 bool testLegendAttribute( LegendAttribute ) const; 225 248 226 #ifndef QWT_NO_COMPAT 227 void setRawSamples( const double *xData, const double *yData, int size ); 228 void setSamples( const double *xData, const double *yData, int size ); 229 void setSamples( const QVector<double> &xData, const QVector<double> &yData ); 230 #endif 231 void setSamples( const QVector<QPointF> & ); 232 void setSamples( QwtSeriesData<QPointF> * ); 233 234 int closestPoint( const QPoint &pos, double *dist = NULL ) const; 249 void setLegendAttributes( LegendAttributes ); 250 LegendAttributes legendAttributes() const; 251 252 void setRawSamples( const double* xData, const double* yData, int size ); 253 void setRawSamples( const float* xData, const float* yData, int size ); 254 255 void setRawSamples( const double* yData, int size ); 256 void setRawSamples( const float* yData, int size ); 257 258 void setSamples( const double* xData, const double* yData, int size ); 259 void setSamples( const float* xData, const float* yData, int size ); 260 261 void setSamples( const double* yData, int size ); 262 void setSamples( const float* yData, int size ); 263 264 void setSamples( const QVector< double >& yData ); 265 void setSamples( const QVector< float >& yData ); 266 267 void setSamples( const QVector< double >& xData, const QVector< double >& yData ); 268 void setSamples( const QVector< float >& xData, const QVector< float >& yData ); 269 270 void setSamples( const QVector< QPointF >& ); 271 void setSamples( QwtSeriesData< QPointF >* ); 272 273 virtual int closestPoint( const QPointF& pos, double* dist = NULL ) const; 274 virtual int adjacentPoint( Qt::Orientation orientation, qreal value ) const; 275 276 qreal interpolatedValueAt( Qt::Orientation, double ) const; 235 277 236 278 double minXValue() const; … … 242 284 bool testCurveAttribute( CurveAttribute ) const; 243 285 244 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );245 void setPen( const QPen & );246 const QPen &pen() const;247 248 void setBrush( const QBrush & );249 const QBrush &brush() const;286 void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 287 void setPen( const QPen& ); 288 const QPen& pen() const; 289 290 void setBrush( const QBrush& ); 291 const QBrush& brush() const; 250 292 251 293 void setBaseline( double ); … … 255 297 CurveStyle style() const; 256 298 257 void setSymbol( QwtSymbol * );258 const QwtSymbol *symbol() const;259 260 void setCurveFitter( QwtCurveFitter * );261 QwtCurveFitter *curveFitter() const;262 263 virtual void drawSeries( QPainter *,264 const QwtScaleMap &xMap, const QwtScaleMap&yMap,265 const QRectF &canvasRect, int from, int to ) const;266 267 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;268 269 protected: 299 void setSymbol( QwtSymbol* ); 300 const QwtSymbol* symbol() const; 301 302 void setCurveFitter( QwtCurveFitter* ); 303 QwtCurveFitter* curveFitter() const; 304 305 virtual void drawSeries( QPainter*, 306 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 307 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 308 309 virtual QwtGraphic legendIcon( int index, const QSizeF& ) const QWT_OVERRIDE; 310 311 protected: 270 312 271 313 void init(); 272 314 273 virtual void drawCurve( QPainter *, int style,274 const QwtScaleMap &xMap, const QwtScaleMap&yMap,275 const QRectF &canvasRect, int from, int to ) const;276 277 virtual void drawSymbols( QPainter *, const QwtSymbol&,278 const QwtScaleMap &xMap, const QwtScaleMap&yMap,279 const QRectF &canvasRect, int from, int to ) const;280 281 virtual void drawLines( QPainter *,282 const QwtScaleMap &xMap, const QwtScaleMap&yMap,283 const QRectF &canvasRect, int from, int to ) const;284 285 virtual void drawSticks( QPainter *,286 const QwtScaleMap &xMap, const QwtScaleMap&yMap,287 const QRectF &canvasRect, int from, int to ) const;288 289 virtual void drawDots( QPainter *,290 const QwtScaleMap &xMap, const QwtScaleMap&yMap,291 const QRectF &canvasRect, int from, int to ) const;292 293 virtual void drawSteps( QPainter *,294 const QwtScaleMap &xMap, const QwtScaleMap&yMap,295 const QRectF &canvasRect, int from, int to ) const;296 297 virtual void fillCurve( QPainter *,298 const QwtScaleMap &, const QwtScaleMap&,299 const QRectF &canvasRect, QPolygonF& ) const;300 301 void closePolyline( QPainter *,302 const QwtScaleMap &, const QwtScaleMap&, QPolygonF& ) const;303 304 private: 315 virtual void drawCurve( QPainter*, int style, 316 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 317 const QRectF& canvasRect, int from, int to ) const; 318 319 virtual void drawSymbols( QPainter*, const QwtSymbol&, 320 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 321 const QRectF& canvasRect, int from, int to ) const; 322 323 virtual void drawLines( QPainter*, 324 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 325 const QRectF& canvasRect, int from, int to ) const; 326 327 virtual void drawSticks( QPainter*, 328 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 329 const QRectF& canvasRect, int from, int to ) const; 330 331 virtual void drawDots( QPainter*, 332 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 333 const QRectF& canvasRect, int from, int to ) const; 334 335 virtual void drawSteps( QPainter*, 336 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 337 const QRectF& canvasRect, int from, int to ) const; 338 339 virtual void fillCurve( QPainter*, 340 const QwtScaleMap&, const QwtScaleMap&, 341 const QRectF& canvasRect, QPolygonF& ) const; 342 343 void closePolyline( QPainter*, 344 const QwtScaleMap&, const QwtScaleMap&, QPolygonF& ) const; 345 346 private: 305 347 class PrivateData; 306 PrivateData *d_data;348 PrivateData* m_data; 307 349 }; 308 350 -
trunk/BNC/qwt/qwt_plot_dict.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot_dict.h" 11 #include <algorithm> 11 12 12 13 class QwtPlotDict::PrivateData 13 14 { 14 public: 15 public: 15 16 16 class ItemList: public QList<QwtPlotItem *>17 class ItemList : public QList< QwtPlotItem* > 17 18 { 18 public: 19 void insertItem( QwtPlotItem *item )19 public: 20 void insertItem( QwtPlotItem* item ) 20 21 { 21 22 if ( item == NULL ) 22 23 return; 23 24 24 QList<QwtPlotItem *>::iterator it =25 qUpperBound( begin(), end(), item, LessZThan() );25 QList< QwtPlotItem* >::iterator it = 26 std::upper_bound( begin(), end(), item, LessZThan() ); 26 27 insert( it, item ); 27 28 } 28 29 29 void removeItem( QwtPlotItem *item )30 void removeItem( QwtPlotItem* item ) 30 31 { 31 32 if ( item == NULL ) 32 33 return; 33 34 34 QList<QwtPlotItem *>::iterator it =35 qLowerBound( begin(), end(), item, LessZThan() );35 QList< QwtPlotItem* >::iterator it = 36 std::lower_bound( begin(), end(), item, LessZThan() ); 36 37 37 38 for ( ; it != end(); ++it ) … … 44 45 } 45 46 } 46 private: 47 private: 47 48 class LessZThan 48 49 { 49 public: 50 inline bool operator()( const QwtPlotItem *item1,51 const QwtPlotItem *item2 ) const50 public: 51 inline bool operator()( const QwtPlotItem* item1, 52 const QwtPlotItem* item2 ) const 52 53 { 53 54 return item1->z() < item2->z(); … … 65 66 Auto deletion is enabled. 66 67 \sa setAutoDelete(), QwtPlotItem::attach() 67 */ 68 */ 68 69 QwtPlotDict::QwtPlotDict() 69 70 { 70 d_data = new QwtPlotDict::PrivateData;71 d_data->autoDelete = true;71 m_data = new QwtPlotDict::PrivateData; 72 m_data->autoDelete = true; 72 73 } 73 74 … … 77 78 If autoDelete() is on, all attached items will be deleted 78 79 \sa setAutoDelete(), autoDelete(), QwtPlotItem::attach() 79 */ 80 */ 80 81 QwtPlotDict::~QwtPlotDict() 81 82 { 82 detachItems( QwtPlotItem::Rtti_PlotItem, d_data->autoDelete );83 delete d_data;83 detachItems( QwtPlotItem::Rtti_PlotItem, m_data->autoDelete ); 84 delete m_data; 84 85 } 85 86 … … 91 92 92 93 \sa autoDelete(), insertItem() 93 */ 94 */ 94 95 void QwtPlotDict::setAutoDelete( bool autoDelete ) 95 96 { 96 d_data->autoDelete = autoDelete;97 m_data->autoDelete = autoDelete; 97 98 } 98 99 … … 100 101 \return true if auto deletion is enabled 101 102 \sa setAutoDelete(), insertItem() 102 */ 103 */ 103 104 bool QwtPlotDict::autoDelete() const 104 105 { 105 return d_data->autoDelete;106 return m_data->autoDelete; 106 107 } 107 108 108 109 /*! 109 Insert a plot item 110 Insert a plot item 110 111 111 \param item PlotItem 112 \sa removeItem() 112 \param item PlotItem 113 \sa removeItem() 113 114 */ 114 void QwtPlotDict::insertItem( QwtPlotItem *item )115 void QwtPlotDict::insertItem( QwtPlotItem* item ) 115 116 { 116 d_data->itemList.insertItem( item );117 m_data->itemList.insertItem( item ); 117 118 } 118 119 119 120 /*! 120 Remove a plot item 121 Remove a plot item 121 122 122 \param item PlotItem 123 \sa insertItem() 123 \param item PlotItem 124 \sa insertItem() 124 125 */ 125 void QwtPlotDict::removeItem( QwtPlotItem *item )126 void QwtPlotDict::removeItem( QwtPlotItem* item ) 126 127 { 127 d_data->itemList.removeItem( item );128 m_data->itemList.removeItem( item ); 128 129 } 129 130 … … 134 135 otherwise only those items of the type rtti. 135 136 \param autoDelete If true, delete all detached items 136 */ 137 */ 137 138 void QwtPlotDict::detachItems( int rtti, bool autoDelete ) 138 139 { 139 PrivateData::ItemList list = d_data->itemList;140 PrivateData::ItemList list = m_data->itemList; 140 141 QwtPlotItemIterator it = list.constBegin(); 141 142 while ( it != list.constEnd() ) 142 143 { 143 QwtPlotItem *item = *it;144 QwtPlotItem* item = *it; 144 145 145 146 ++it; // increment before removing item from the list … … 155 156 156 157 /*! 157 \brief A QwtPlotItemList of all attached plot items. 158 \brief A QwtPlotItemList of all attached plot items. 158 159 159 Use caution when iterating these lists, as removing/detaching an item will 160 invalidate the iterator. Instead you can place pointers to objects to be 161 removed in a removal list, and traverse that list later. 160 Use caution when iterating these lists, as removing/detaching an item will 161 invalidate the iterator. Instead you can place pointers to objects to be 162 removed in a removal list, and traverse that list later. 162 163 163 \return List of all attached plot items. 164 */ 165 const QwtPlotItemList &QwtPlotDict::itemList() const164 \return List of all attached plot items. 165 */ 166 const QwtPlotItemList& QwtPlotDict::itemList() const 166 167 { 167 return d_data->itemList;168 return m_data->itemList; 168 169 } 169 170 170 171 /*! 171 \return List of all attached plot items of a specific type. 172 \param rtti See QwtPlotItem::RttiValues 173 \sa QwtPlotItem::rtti() 174 */ 172 \return List of all attached plot items of a specific type. 173 \param rtti See QwtPlotItem::RttiValues 174 \sa QwtPlotItem::rtti() 175 */ 175 176 QwtPlotItemList QwtPlotDict::itemList( int rtti ) const 176 177 { 177 178 if ( rtti == QwtPlotItem::Rtti_PlotItem ) 178 return d_data->itemList;179 return m_data->itemList; 179 180 180 181 QwtPlotItemList items; 181 182 182 PrivateData::ItemList list = d_data->itemList;183 PrivateData::ItemList list = m_data->itemList; 183 184 for ( QwtPlotItemIterator it = list.constBegin(); it != list.constEnd(); ++it ) 184 185 { 185 QwtPlotItem *item = *it;186 QwtPlotItem* item = *it; 186 187 if ( item->rtti() == rtti ) 187 188 items += item; -
trunk/BNC/qwt/qwt_plot_dict.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 8 8 *****************************************************************************/ 9 9 10 /*! \file !*/11 10 #ifndef QWT_PLOT_DICT 12 11 #define QWT_PLOT_DICT … … 14 13 #include "qwt_global.h" 15 14 #include "qwt_plot_item.h" 15 16 16 #include <qlist.h> 17 17 18 /// \var typedef QList< QwtPlotItem *> QwtPlotItemList 19 /// \brief See QT 4.x assistant documentation for QList 20 typedef QList<QwtPlotItem *> QwtPlotItemList; 21 typedef QList<QwtPlotItem *>::ConstIterator QwtPlotItemIterator; 18 typedef QList< QwtPlotItem* > QwtPlotItemList; 19 typedef QList< QwtPlotItem* >::ConstIterator QwtPlotItemIterator; 22 20 23 21 /*! 24 \brief A dictionary for plot items 22 \brief A dictionary for plot items 25 23 26 QwtPlotDict organizes plot items in increasing z-order. 27 If autoDelete() is enabled, all attached items will be deleted 28 in the destructor of the dictionary. 29 QwtPlotDict can be used to get access to all QwtPlotItem items - or all 30 items of a specific type - that are currently on the plot. 24 QwtPlotDict organizes plot items in increasing z-order. 25 If autoDelete() is enabled, all attached items will be deleted 26 in the destructor of the dictionary. 27 QwtPlotDict can be used to get access to all QwtPlotItem items - or all 28 items of a specific type - that are currently on the plot. 31 29 32 \sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z() 33 */ 30 \sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z() 31 */ 34 32 class QWT_EXPORT QwtPlotDict 35 33 { 36 public: 34 public: 37 35 explicit QwtPlotDict(); 38 36 virtual ~QwtPlotDict(); … … 47 45 bool autoDelete = true ); 48 46 49 protected: 50 void insertItem( QwtPlotItem * );51 void removeItem( QwtPlotItem * );47 protected: 48 void insertItem( QwtPlotItem* ); 49 void removeItem( QwtPlotItem* ); 52 50 53 private: 51 private: 54 52 class PrivateData; 55 PrivateData *d_data;53 PrivateData* m_data; 56 54 }; 57 55 -
trunk/BNC/qwt/qwt_plot_directpainter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_plot_canvas.h" 14 14 #include "qwt_plot_seriesitem.h" 15 15 16 #include <qpainter.h> 16 17 #include <qevent.h> 17 #include <qapplication.h>18 18 #include <qpixmap.h> 19 19 20 20 static inline void qwtRenderItem( 21 QPainter *painter, const QRect&canvasRect,22 QwtPlotSeriesItem *seriesItem, int from, int to )21 QPainter* painter, const QRect& canvasRect, 22 QwtPlotSeriesItem* seriesItem, int from, int to ) 23 23 { 24 24 // A minor performance improvement is possible 25 25 // with caching the maps. TODO ... 26 26 27 QwtPlot *plot = seriesItem->plot();27 QwtPlot* plot = seriesItem->plot(); 28 28 const QwtScaleMap xMap = plot->canvasMap( seriesItem->xAxis() ); 29 29 const QwtScaleMap yMap = plot->canvasMap( seriesItem->yAxis() ); … … 34 34 } 35 35 36 static inline bool qwtHasBackingStore( const QwtPlotCanvas *canvas )36 static inline bool qwtHasBackingStore( const QwtPlotCanvas* canvas ) 37 37 { 38 38 return canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) 39 && canvas->backingStore() && !canvas->backingStore()->isNull(); 39 && canvas->backingStore() && !canvas->backingStore()->isNull(); 40 40 } 41 41 42 42 class QwtPlotDirectPainter::PrivateData 43 43 { 44 public: 45 PrivateData(): 46 attributes( 0 ), 47 hasClipping(false), 48 seriesItem( NULL ), 49 from( 0 ), 50 to( 0 ) 44 public: 45 PrivateData() 46 : hasClipping( false ) 47 , seriesItem( NULL ) 48 , from( 0 ) 49 , to( 0 ) 51 50 { 52 51 } … … 59 58 QPainter painter; 60 59 61 QwtPlotSeriesItem *seriesItem;60 QwtPlotSeriesItem* seriesItem; 62 61 int from; 63 62 int to; … … 65 64 66 65 //! Constructor 67 QwtPlotDirectPainter::QwtPlotDirectPainter( QObject *parent ):68 QObject( parent ) 69 { 70 d_data = new PrivateData;66 QwtPlotDirectPainter::QwtPlotDirectPainter( QObject* parent ) 67 : QObject( parent ) 68 { 69 m_data = new PrivateData; 71 70 } 72 71 … … 74 73 QwtPlotDirectPainter::~QwtPlotDirectPainter() 75 74 { 76 delete d_data;77 } 78 79 /*! 80 Change an attribute 81 82 \param attribute Attribute to change 83 \param on On/Off 84 85 \sa Attribute, testAttribute() 86 */ 75 delete m_data; 76 } 77 78 /*! 79 Change an attribute 80 81 \param attribute Attribute to change 82 \param on On/Off 83 84 \sa Attribute, testAttribute() 85 */ 87 86 void QwtPlotDirectPainter::setAttribute( Attribute attribute, bool on ) 88 87 { 89 if ( bool( d_data->attributes & attribute ) != on )88 if ( bool( m_data->attributes & attribute ) != on ) 90 89 { 91 90 if ( on ) 92 d_data->attributes |= attribute;91 m_data->attributes |= attribute; 93 92 else 94 d_data->attributes &= ~attribute;93 m_data->attributes &= ~attribute; 95 94 96 95 if ( ( attribute == AtomicPainter ) && on ) … … 100 99 101 100 /*! 102 \return True, when attribute is enabled 103 \param attribute Attribute to be tested 104 \sa Attribute, setAttribute() 105 */ 101 \return True, when attribute is enabled 102 \param attribute Attribute to be tested 103 \sa Attribute, setAttribute() 104 */ 106 105 bool QwtPlotDirectPainter::testAttribute( Attribute attribute ) const 107 106 { 108 return d_data->attributes & attribute;109 } 110 111 /*! 112 En/Disables clipping 113 114 \param enable Enables clipping is true, disable it otherwise 115 \sa hasClipping(), clipRegion(), setClipRegion() 116 */ 107 return m_data->attributes & attribute; 108 } 109 110 /*! 111 En/Disables clipping 112 113 \param enable Enables clipping is true, disable it otherwise 114 \sa hasClipping(), clipRegion(), setClipRegion() 115 */ 117 116 void QwtPlotDirectPainter::setClipping( bool enable ) 118 117 { 119 d_data->hasClipping = enable;120 } 121 122 /*! 123 \return true, when clipping is enabled 124 \sa setClipping(), clipRegion(), setClipRegion() 125 */ 118 m_data->hasClipping = enable; 119 } 120 121 /*! 122 \return true, when clipping is enabled 123 \sa setClipping(), clipRegion(), setClipRegion() 124 */ 126 125 bool QwtPlotDirectPainter::hasClipping() const 127 126 { 128 return d_data->hasClipping;127 return m_data->hasClipping; 129 128 } 130 129 … … 139 138 \param region Clip region 140 139 \sa clipRegion(), hasClipping(), setClipping() 141 */ 142 void QwtPlotDirectPainter::setClipRegion( const QRegion ®ion )143 { 144 d_data->clipRegion = region;145 d_data->hasClipping = true;140 */ 141 void QwtPlotDirectPainter::setClipRegion( const QRegion& region ) 142 { 143 m_data->clipRegion = region; 144 m_data->hasClipping = true; 146 145 } 147 146 … … 149 148 \return Currently set clip region. 150 149 \sa setClipRegion(), setClipping(), hasClipping() 151 */ 150 */ 152 151 QRegion QwtPlotDirectPainter::clipRegion() const 153 152 { 154 return d_data->clipRegion;155 } 156 157 /*! 158 \brief Draw a set of points of a seriesItem. 159 160 When observing an measurement while it is running, new points have to be 161 added to an existing seriesItem. drawSeries() can be used to display them avoiding 162 a complete redraw of the canvas. 163 164 Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 165 will result in faster painting, if the paint engine of the canvas widget 166 supports this feature. 167 168 \param seriesItem Item to be painted 169 \param from Index of the first point to be painted 170 \param to Index of the last point to be painted. If to < 0 the 153 return m_data->clipRegion; 154 } 155 156 /*! 157 \brief Draw a set of points of a seriesItem. 158 159 When observing an measurement while it is running, new points have to be 160 added to an existing seriesItem. drawSeries() can be used to display them avoiding 161 a complete redraw of the canvas. 162 163 Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 164 will result in faster painting, if the paint engine of the canvas widget 165 supports this feature. 166 167 \param seriesItem Item to be painted 168 \param from Index of the first point to be painted 169 \param to Index of the last point to be painted. If to < 0 the 171 170 series will be painted to its last point. 172 */ 171 */ 173 172 void QwtPlotDirectPainter::drawSeries( 174 QwtPlotSeriesItem *seriesItem, int from, int to )173 QwtPlotSeriesItem* seriesItem, int from, int to ) 175 174 { 176 175 if ( seriesItem == NULL || seriesItem->plot() == NULL ) 177 176 return; 178 177 179 QWidget *canvas = seriesItem->plot()->canvas();178 QWidget* canvas = seriesItem->plot()->canvas(); 180 179 const QRect canvasRect = canvas->contentsRect(); 181 180 182 QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas*>( canvas );181 QwtPlotCanvas* plotCanvas = qobject_cast< QwtPlotCanvas* >( canvas ); 183 182 184 183 if ( plotCanvas && qwtHasBackingStore( plotCanvas ) ) 185 184 { 186 QPainter painter( const_cast<QPixmap *>( plotCanvas->backingStore() ) );187 188 if ( d_data->hasClipping )189 painter.setClipRegion( d_data->clipRegion );185 QPainter painter( const_cast< QPixmap* >( plotCanvas->backingStore() ) ); 186 187 if ( m_data->hasClipping ) 188 painter.setClipRegion( m_data->clipRegion ); 190 189 191 190 qwtRenderItem( &painter, canvasRect, seriesItem, from, to ); … … 206 205 if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) ) 207 206 #endif 208 immediatePaint = false;207 immediatePaint = false; 209 208 } 210 209 211 210 if ( immediatePaint ) 212 211 { 213 if ( ! d_data->painter.isActive() )212 if ( !m_data->painter.isActive() ) 214 213 { 215 214 reset(); 216 215 217 d_data->painter.begin( canvas );216 m_data->painter.begin( canvas ); 218 217 canvas->installEventFilter( this ); 219 218 } 220 219 221 if ( d_data->hasClipping )222 { 223 d_data->painter.setClipRegion(224 QRegion( canvasRect ) & d_data->clipRegion );220 if ( m_data->hasClipping ) 221 { 222 m_data->painter.setClipRegion( 223 QRegion( canvasRect ) & m_data->clipRegion ); 225 224 } 226 225 else 227 226 { 228 if ( ! d_data->painter.hasClipping() )229 d_data->painter.setClipRect( canvasRect );230 } 231 232 qwtRenderItem( & d_data->painter, canvasRect, seriesItem, from, to );233 234 if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter )227 if ( !m_data->painter.hasClipping() ) 228 m_data->painter.setClipRect( canvasRect ); 229 } 230 231 qwtRenderItem( &m_data->painter, canvasRect, seriesItem, from, to ); 232 233 if ( m_data->attributes & QwtPlotDirectPainter::AtomicPainter ) 235 234 { 236 235 reset(); … … 238 237 else 239 238 { 240 if ( d_data->hasClipping )241 d_data->painter.setClipping( false );239 if ( m_data->hasClipping ) 240 m_data->painter.setClipping( false ); 242 241 } 243 242 } … … 246 245 reset(); 247 246 248 d_data->seriesItem = seriesItem;249 d_data->from = from;250 d_data->to = to;247 m_data->seriesItem = seriesItem; 248 m_data->from = from; 249 m_data->to = to; 251 250 252 251 QRegion clipRegion = canvasRect; 253 if ( d_data->hasClipping )254 clipRegion &= d_data->clipRegion;252 if ( m_data->hasClipping ) 253 clipRegion &= m_data->clipRegion; 255 254 256 255 canvas->installEventFilter( this ); … … 258 257 canvas->removeEventFilter( this ); 259 258 260 d_data->seriesItem = NULL;259 m_data->seriesItem = NULL; 261 260 } 262 261 } … … 265 264 void QwtPlotDirectPainter::reset() 266 265 { 267 if ( d_data->painter.isActive() )268 { 269 QWidget *w = static_cast<QWidget*>( d_data->painter.device() );266 if ( m_data->painter.isActive() ) 267 { 268 QWidget* w = static_cast< QWidget* >( m_data->painter.device() ); 270 269 if ( w ) 271 270 w->removeEventFilter( this ); 272 271 273 d_data->painter.end();272 m_data->painter.end(); 274 273 } 275 274 } 276 275 277 276 //! Event filter 278 bool QwtPlotDirectPainter::eventFilter( QObject *, QEvent*event )277 bool QwtPlotDirectPainter::eventFilter( QObject*, QEvent* event ) 279 278 { 280 279 if ( event->type() == QEvent::Paint ) … … 282 281 reset(); 283 282 284 if ( d_data->seriesItem )285 { 286 const QPaintEvent *pe = static_cast< QPaintEvent*>( event );287 288 QWidget *canvas =d_data->seriesItem->plot()->canvas();283 if ( m_data->seriesItem ) 284 { 285 const QPaintEvent* pe = static_cast< QPaintEvent* >( event ); 286 287 QWidget* canvas = m_data->seriesItem->plot()->canvas(); 289 288 290 289 QPainter painter( canvas ); … … 295 294 if ( doCopyCache ) 296 295 { 297 QwtPlotCanvas *plotCanvas =298 qobject_cast<QwtPlotCanvas *>( canvas );296 QwtPlotCanvas* plotCanvas = 297 qobject_cast< QwtPlotCanvas* >( canvas ); 299 298 if ( plotCanvas ) 300 299 { … … 311 310 { 312 311 qwtRenderItem( &painter, canvas->contentsRect(), 313 d_data->seriesItem,d_data->from,d_data->to );312 m_data->seriesItem, m_data->from, m_data->to ); 314 313 } 315 314 -
trunk/BNC/qwt/qwt_plot_directpainter.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 36 36 by another operation ( like changing scales ) and nothing needs 37 37 to be erased. 38 */ 39 class QWT_EXPORT QwtPlotDirectPainter: public QObject 38 */ 39 class QWT_EXPORT QwtPlotDirectPainter : public QObject 40 40 { 41 public: 41 public: 42 42 /*! 43 \brief Paint attributes 44 \sa setAttribute(), testAttribute(), drawSeries() 45 */ 43 \brief Paint attributes 44 \sa setAttribute(), testAttribute(), drawSeries() 45 */ 46 46 enum Attribute 47 47 { 48 48 /*! 49 Initializing a QPainter is an expensive operation. 50 When AtomicPainter is set each call of drawSeries() opens/closes 51 a temporary QPainter. Otherwise QwtPlotDirectPainter tries to 52 use the same QPainter as long as possible. 49 Initializing a QPainter is an expensive operation. 50 When AtomicPainter is set each call of drawSeries() opens/closes 51 a temporary QPainter. Otherwise QwtPlotDirectPainter tries to 52 use the same QPainter as long as possible. 53 53 */ 54 54 AtomicPainter = 0x01, 55 55 56 56 /*! 57 When FullRepaint is set the plot canvas is explicitly repainted 58 after the samples have been rendered. 57 When FullRepaint is set the plot canvas is explicitly repainted 58 after the samples have been rendered. 59 59 */ 60 60 FullRepaint = 0x02, 61 61 62 62 /*! 63 When QwtPlotCanvas::BackingStore is enabled the painter 64 has to paint to the backing store and the widget. In certain 65 situations/environments it might be faster to paint to 66 the backing store only and then copy the backing store to the canvas. 67 This flag can also be useful for settings, where Qt fills the 68 the clip region with the widget background. 63 When QwtPlotCanvas::BackingStore is enabled the painter 64 has to paint to the backing store and the widget. In certain 65 situations/environments it might be faster to paint to 66 the backing store only and then copy the backing store to the canvas. 67 This flag can also be useful for settings, where Qt fills the 68 the clip region with the widget background. 69 69 */ 70 70 CopyBackingStore = 0x04 71 71 }; 72 72 73 //! Paint attributes 74 typedef QFlags<Attribute> Attributes; 73 Q_DECLARE_FLAGS( Attributes, Attribute ) 75 74 76 QwtPlotDirectPainter( QObject *parent = NULL );75 explicit QwtPlotDirectPainter( QObject* parent = NULL ); 77 76 virtual ~QwtPlotDirectPainter(); 78 77 … … 83 82 bool hasClipping() const; 84 83 85 void setClipRegion( const QRegion & );84 void setClipRegion( const QRegion& ); 86 85 QRegion clipRegion() const; 87 86 88 void drawSeries( QwtPlotSeriesItem *, int from, int to );87 void drawSeries( QwtPlotSeriesItem*, int from, int to ); 89 88 void reset(); 90 89 91 virtual bool eventFilter( QObject *, QEvent* );90 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 92 91 93 private: 92 private: 94 93 class PrivateData; 95 PrivateData *d_data;94 PrivateData* m_data; 96 95 }; 97 96 -
trunk/BNC/qwt/qwt_plot_glcanvas.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_plot.h" 12 12 #include "qwt_painter.h" 13 #include <qevent.h> 13 14 #include <qcoreevent.h> 14 15 #include <qpainter.h> 15 #include <qdrawutil.h> 16 #include <qstyle.h> 17 #include <qstyleoption.h> 18 19 #define FIX_GL_TRANSLATION 0 20 21 static QWidget *qwtBGWidget( QWidget *widget ) 22 { 23 QWidget *w = widget; 24 25 for ( ; w->parentWidget() != NULL; w = w->parentWidget() ) 26 { 27 if ( w->autoFillBackground() || 28 w->testAttribute( Qt::WA_StyledBackground ) ) 29 { 30 return w; 31 } 32 } 33 34 return w; 35 } 36 37 static void qwtUpdateContentsRect( QwtPlotGLCanvas *canvas ) 38 { 39 const int fw = canvas->frameWidth(); 40 canvas->setContentsMargins( fw, fw, fw, fw ); 16 #include <qpainterpath.h> 17 #include <qglframebufferobject.h> 18 19 namespace 20 { 21 class QwtPlotGLCanvasFormat : public QGLFormat 22 { 23 public: 24 QwtPlotGLCanvasFormat() 25 : QGLFormat( QGLFormat::defaultFormat() ) 26 { 27 setSampleBuffers( true ); 28 } 29 }; 41 30 } 42 31 43 32 class QwtPlotGLCanvas::PrivateData 44 33 { 45 public: 46 PrivateData(): 47 frameStyle( QFrame::Panel | QFrame::Sunken), 48 lineWidth( 2 ), 49 midLineWidth( 0 ) 50 { 51 } 52 53 int frameStyle; 54 int lineWidth; 55 int midLineWidth; 34 public: 35 PrivateData() 36 : fboDirty( true ) 37 , fbo( NULL ) 38 { 39 } 40 41 ~PrivateData() 42 { 43 delete fbo; 44 } 45 46 bool fboDirty; 47 QGLFramebufferObject* fbo; 56 48 }; 57 49 58 class QwtPlotGLCanvasFormat: public QGLFormat 59 { 60 public: 61 QwtPlotGLCanvasFormat(): 62 QGLFormat( QGLFormat::defaultFormat() ) 63 { 64 setSampleBuffers( true ); 65 } 66 }; 67 68 /*! 69 \brief Constructor 70 71 \param plot Parent plot widget 72 \sa QwtPlot::setCanvas() 73 */ 74 QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot *plot ): 75 QGLWidget( QwtPlotGLCanvasFormat(), plot ) 76 { 77 d_data = new PrivateData; 78 79 #ifndef QT_NO_CURSOR 80 setCursor( Qt::CrossCursor ); 81 #endif 82 83 setAutoFillBackground( true ); 84 qwtUpdateContentsRect( this ); 50 /*! 51 \brief Constructor 52 53 \param plot Parent plot widget 54 \sa QwtPlot::setCanvas() 55 */ 56 QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot* plot ) 57 : QGLWidget( QwtPlotGLCanvasFormat(), plot ) 58 , QwtPlotAbstractGLCanvas( this ) 59 { 60 init(); 61 } 62 /*! 63 \brief Constructor 64 65 \param format OpenGL rendering options 66 \param plot Parent plot widget 67 \sa QwtPlot::setCanvas() 68 */ 69 QwtPlotGLCanvas::QwtPlotGLCanvas( const QGLFormat& format, QwtPlot* plot ) 70 : QGLWidget( format, plot ) 71 , QwtPlotAbstractGLCanvas( this ) 72 { 73 init(); 85 74 } 86 75 … … 88 77 QwtPlotGLCanvas::~QwtPlotGLCanvas() 89 78 { 90 delete d_data; 91 } 92 93 /*! 94 Set the frame style 95 96 \param style The bitwise OR between a shape and a shadow. 97 98 \sa frameStyle(), QFrame::setFrameStyle(), 99 setFrameShadow(), setFrameShape() 100 */ 101 void QwtPlotGLCanvas::setFrameStyle( int style ) 102 { 103 if ( style != d_data->frameStyle ) 104 { 105 d_data->frameStyle = style; 106 qwtUpdateContentsRect( this ); 107 108 update(); 109 } 110 } 111 112 /*! 113 \return The bitwise OR between a frameShape() and a frameShadow() 114 \sa setFrameStyle(), QFrame::frameStyle() 115 */ 116 int QwtPlotGLCanvas::frameStyle() const 117 { 118 return d_data->frameStyle; 119 } 120 121 /*! 122 Set the frame shadow 123 124 \param shadow Frame shadow 125 \sa frameShadow(), setFrameShape(), QFrame::setFrameShadow() 126 */ 127 void QwtPlotGLCanvas::setFrameShadow( Shadow shadow ) 128 { 129 setFrameStyle(( d_data->frameStyle & QFrame::Shape_Mask ) | shadow ); 130 } 131 132 /*! 133 \return Frame shadow 134 \sa setFrameShadow(), QFrame::setFrameShadow() 135 */ 136 QwtPlotGLCanvas::Shadow QwtPlotGLCanvas::frameShadow() const 137 { 138 return (Shadow) ( d_data->frameStyle & QFrame::Shadow_Mask ); 139 } 140 141 /*! 142 Set the frame shape 143 144 \param shape Frame shape 145 \sa frameShape(), setFrameShadow(), QFrame::frameShape() 146 */ 147 void QwtPlotGLCanvas::setFrameShape( Shape shape ) 148 { 149 setFrameStyle( ( d_data->frameStyle & QFrame::Shadow_Mask ) | shape ); 150 } 151 152 /*! 153 \return Frame shape 154 \sa setFrameShape(), QFrame::frameShape() 155 */ 156 QwtPlotGLCanvas::Shape QwtPlotGLCanvas::frameShape() const 157 { 158 return (Shape) ( d_data->frameStyle & QFrame::Shape_Mask ); 159 } 160 161 /*! 162 Set the frame line width 163 164 The default line width is 2 pixels. 165 166 \param width Line width of the frame 167 \sa lineWidth(), setMidLineWidth() 168 */ 169 void QwtPlotGLCanvas::setLineWidth( int width ) 170 { 171 width = qMax( width, 0 ); 172 if ( width != d_data->lineWidth ) 173 { 174 d_data->lineWidth = qMax( width, 0 ); 175 qwtUpdateContentsRect( this ); 176 update(); 177 } 178 } 179 180 /*! 181 \return Line width of the frame 182 \sa setLineWidth(), midLineWidth() 183 */ 184 int QwtPlotGLCanvas::lineWidth() const 185 { 186 return d_data->lineWidth; 187 } 188 189 /*! 190 Set the frame mid line width 191 192 The default midline width is 0 pixels. 193 194 \param width Midline width of the frame 195 \sa midLineWidth(), setLineWidth() 196 */ 197 void QwtPlotGLCanvas::setMidLineWidth( int width ) 198 { 199 width = qMax( width, 0 ); 200 if ( width != d_data->midLineWidth ) 201 { 202 d_data->midLineWidth = width; 203 qwtUpdateContentsRect( this ); 204 update(); 205 } 206 } 207 208 /*! 209 \return Midline width of the frame 210 \sa setMidLineWidth(), lineWidth() 211 */ 212 int QwtPlotGLCanvas::midLineWidth() const 213 { 214 return d_data->midLineWidth; 215 } 216 217 /*! 218 \return Frame width depending on the style, line width and midline width. 219 */ 220 int QwtPlotGLCanvas::frameWidth() const 221 { 222 return ( frameStyle() != NoFrame ) ? d_data->lineWidth : 0; 223 } 224 225 /*! 226 Paint event 227 228 \param event Paint event 229 \sa QwtPlot::drawCanvas() 230 */ 231 void QwtPlotGLCanvas::paintEvent( QPaintEvent *event ) 232 { 233 Q_UNUSED( event ); 234 235 QPainter painter( this ); 236 237 #if FIX_GL_TRANSLATION 238 if ( painter.paintEngine()->type() == QPaintEngine::OpenGL2 ) 239 { 240 // work around a translation bug of QPaintEngine::OpenGL2 241 painter.translate( 1, 1 ); 242 } 79 delete m_data; 80 } 81 82 void QwtPlotGLCanvas::init() 83 { 84 m_data = new PrivateData; 85 86 #if 1 87 setAttribute( Qt::WA_OpaquePaintEvent, true ); 243 88 #endif 244 245 drawBackground( &painter ); 246 drawItems( &painter ); 247 248 if ( !testAttribute( Qt::WA_StyledBackground ) ) 249 { 250 if ( frameWidth() > 0 ) 251 drawBorder( &painter ); 252 } 253 } 254 /*! 255 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 256 \param event Qt Event 257 \return See QGLWidget::event() 258 */ 259 bool QwtPlotGLCanvas::event( QEvent *event ) 89 setLineWidth( 2 ); 90 setFrameShadow( QFrame::Sunken ); 91 setFrameShape( QFrame::Panel ); 92 } 93 94 /*! 95 Paint event 96 97 \param event Paint event 98 \sa QwtPlot::drawCanvas() 99 */ 100 void QwtPlotGLCanvas::paintEvent( QPaintEvent* event ) 101 { 102 QGLWidget::paintEvent( event ); 103 } 104 105 /*! 106 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 107 \param event Qt Event 108 \return See QGLWidget::event() 109 */ 110 bool QwtPlotGLCanvas::event( QEvent* event ) 260 111 { 261 112 const bool ok = QGLWidget::event( event ); … … 275 126 276 127 /*! 277 Draw the plot items 278 \param painter Painter 279 280 \sa QwtPlot::drawCanvas() 281 */ 282 void QwtPlotGLCanvas::drawItems( QPainter *painter ) 283 { 284 painter->save(); 285 286 painter->setClipRect( contentsRect(), Qt::IntersectClip ); 287 288 QwtPlot *plot = qobject_cast< QwtPlot *>( parent() ); 289 if ( plot ) 290 plot->drawCanvas( painter ); 291 292 painter->restore(); 293 } 294 295 /*! 296 Draw the background of the canvas 297 \param painter Painter 298 */ 299 void QwtPlotGLCanvas::drawBackground( QPainter *painter ) 300 { 301 painter->save(); 302 303 QWidget *w = qwtBGWidget( this ); 304 305 const QPoint off = mapTo( w, QPoint() ); 306 painter->translate( -off ); 307 308 const QRect fillRect = rect().translated( off ); 309 310 if ( w->testAttribute( Qt::WA_StyledBackground ) ) 311 { 312 painter->setClipRect( fillRect ); 313 314 QStyleOption opt; 315 opt.initFrom( w ); 316 w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w); 128 Invalidate the paint cache and repaint the canvas 129 \sa invalidatePaintCache() 130 */ 131 void QwtPlotGLCanvas::replot() 132 { 133 QwtPlotAbstractGLCanvas::replot(); 134 } 135 136 //! Invalidate the internal backing store 137 void QwtPlotGLCanvas::invalidateBackingStore() 138 { 139 m_data->fboDirty = true; 140 } 141 142 void QwtPlotGLCanvas::clearBackingStore() 143 { 144 delete m_data->fbo; 145 m_data->fbo = NULL; 146 } 147 148 /*! 149 Calculate the painter path for a styled or rounded border 150 151 When the canvas has no styled background or rounded borders 152 the painter path is empty. 153 154 \param rect Bounding rectangle of the canvas 155 \return Painter path, that can be used for clipping 156 */ 157 QPainterPath QwtPlotGLCanvas::borderPath( const QRect& rect ) const 158 { 159 return canvasBorderPath( rect ); 160 } 161 162 //! No operation - reserved for some potential use in the future 163 void QwtPlotGLCanvas::initializeGL() 164 { 165 } 166 167 //! Paint the plot 168 void QwtPlotGLCanvas::paintGL() 169 { 170 const bool hasFocusIndicator = 171 hasFocus() && focusIndicator() == CanvasFocusIndicator; 172 173 QPainter painter; 174 175 if ( testPaintAttribute( QwtPlotGLCanvas::BackingStore ) ) 176 { 177 const qreal pixelRatio = QwtPainter::devicePixelRatio( this ); 178 const QRect rect( 0, 0, width() * pixelRatio, height() * pixelRatio ); 179 180 if ( hasFocusIndicator ) 181 painter.begin( this ); 182 183 if ( m_data->fbo ) 184 { 185 if ( m_data->fbo->size() != rect.size() ) 186 { 187 delete m_data->fbo; 188 m_data->fbo = NULL; 189 } 190 } 191 192 if ( m_data->fbo == NULL ) 193 { 194 QGLFramebufferObjectFormat format; 195 format.setSamples( 4 ); 196 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); 197 198 m_data->fbo = new QGLFramebufferObject( rect.size(), format ); 199 m_data->fboDirty = true; 200 } 201 202 if ( m_data->fboDirty ) 203 { 204 QPainter fboPainter( m_data->fbo ); 205 fboPainter.scale( pixelRatio, pixelRatio ); 206 draw( &fboPainter ); 207 fboPainter.end(); 208 209 m_data->fboDirty = false; 210 } 211 212 /* 213 Why do we have this strange translation - but, anyway 214 QwtPlotGLCanvas in combination with scaling factor 215 is not very likely to happen as using QwtPlotOpenGLCanvas 216 usually makes more sense then. 217 */ 218 219 QGLFramebufferObject::blitFramebuffer( NULL, 220 rect.translated( 0, height() - rect.height() ), m_data->fbo, rect ); 317 221 } 318 222 else 319 223 { 320 painter->fillRect( fillRect, 321 w->palette().brush( w->backgroundRole() ) ); 322 } 323 324 painter->restore(); 325 } 326 327 /*! 328 Draw the border of the canvas 329 \param painter Painter 330 */ 331 void QwtPlotGLCanvas::drawBorder( QPainter *painter ) 332 { 333 const int fw = frameWidth(); 334 if ( fw <= 0 ) 335 return; 336 337 if ( frameShadow() == QwtPlotGLCanvas::Plain ) 338 { 339 qDrawPlainRect( painter, frameRect(), 340 palette().shadow().color(), lineWidth() ); 341 } 342 else 343 { 344 if ( frameShape() == QwtPlotGLCanvas::Box ) 345 { 346 qDrawShadeRect( painter, frameRect(), palette(), 347 frameShadow() == Sunken, lineWidth(), midLineWidth() ); 348 } 349 else 350 { 351 qDrawShadePanel( painter, frameRect(), palette(), 352 frameShadow() == Sunken, lineWidth() ); 353 } 354 } 355 } 356 357 //! Calls repaint() 358 void QwtPlotGLCanvas::replot() 359 { 360 repaint(); 361 } 362 363 /*! 364 \return Empty path 365 */ 366 QPainterPath QwtPlotGLCanvas::borderPath( const QRect &rect ) const 367 { 368 Q_UNUSED( rect ); 369 return QPainterPath(); 370 } 371 372 //! \return The rectangle where the frame is drawn in. 373 QRect QwtPlotGLCanvas::frameRect() const 374 { 375 const int fw = frameWidth(); 376 return contentsRect().adjusted( -fw, -fw, fw, fw ); 377 } 224 painter.begin( this ); 225 draw( &painter ); 226 } 227 228 if ( hasFocusIndicator ) 229 drawFocusIndicator( &painter ); 230 } 231 232 //! No operation - reserved for some potential use in the future 233 void QwtPlotGLCanvas::resizeGL( int, int ) 234 { 235 // nothing to do 236 } 237 238 #include "moc_qwt_plot_glcanvas.cpp" -
trunk/BNC/qwt/qwt_plot_glcanvas.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include <qframe.h> 14 #include "qwt_plot_abstract_canvas.h" 15 15 16 #include <qgl.h> 16 #include <qpainterpath.h>17 17 18 18 class QwtPlot; 19 19 20 20 /*! 21 \brief An alternative canvas for a QwtPlot derived from QGLWidget 21 \brief An alternative canvas for a QwtPlot derived from QGLWidget 22 22 23 QwtPlotGLCanvas implements the very basics to act as canvas 24 inside of a QwtPlot widget. It might be extended to a full 25 featured alternative to QwtPlotCanvas in a future version of Qwt. 23 QwtPlotGLCanvas implements the very basics to act as canvas 24 inside of a QwtPlot widget. It might be extended to a full 25 featured alternative to QwtPlotCanvas in a future version of Qwt. 26 26 27 Even if QwtPlotGLCanvas is not derived from QFrame it imitates 28 its API. When using style sheets it supports the box model - beside 29 backgrounds with rounded borders. 27 Even if QwtPlotGLCanvas is not derived from QFrame it imitates 28 its API. When using style sheets it supports the box model - beside 29 backgrounds with rounded borders. 30 30 31 \saQwtPlot::setCanvas(), QwtPlotCanvas31 Since Qt 5.4 QOpenGLWidget is available, that is used by QwtPlotOpenGLCanvas. 32 32 33 \note With Qt4 you might want to use the QPaintEngine::OpenGL paint engine 33 \sa QwtPlot::setCanvas(), QwtPlotCanvas, QwtPlotOpenGLCanvas 34 35 \note With Qt4 you might want to use the QPaintEngine::OpenGL paint engine 34 36 ( see QGL::setPreferredPaintEngine() ). On a Linux test system 35 37 QPaintEngine::OpenGL2 shows very basic problems like translated 36 38 geometries. 37 */ 38 class QWT_EXPORT QwtPlotGLCanvas: public QGLWidget 39 40 \note Another way for getting hardware accelerated graphics is using 41 an OpenGL offscreen buffer ( QwtPlotCanvas::OpenGLBuffer ) with QwtPlotCanvas. 42 Performance is worse, than rendering straight to a QGLWidget, but is usually 43 better integrated into a desktop application. 44 */ 45 class QWT_EXPORT QwtPlotGLCanvas : public QGLWidget, public QwtPlotAbstractGLCanvas 39 46 { 40 47 Q_OBJECT 41 48 42 Q_ENUMS( Shape Shadow ) 43 44 Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow ) 45 Q_PROPERTY( Shape frameShape READ frameShape WRITE setFrameShape ) 49 Q_PROPERTY( QFrame::Shadow frameShadow READ frameShadow WRITE setFrameShadow ) 50 Q_PROPERTY( QFrame::Shape frameShape READ frameShape WRITE setFrameShape ) 46 51 Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth ) 47 52 Q_PROPERTY( int midLineWidth READ midLineWidth WRITE setMidLineWidth ) … … 49 54 Q_PROPERTY( QRect frameRect READ frameRect DESIGNABLE false ) 50 55 51 public: 52 /*! 53 \brief Frame shadow 56 Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius ) 54 57 55 Unfortunately it is not possible to use QFrame::Shadow 56 as a property of a widget that is not derived from QFrame. 57 The following enum is made for the designer only. It is safe 58 to use QFrame::Shadow instead. 59 */ 60 enum Shadow 61 { 62 //! QFrame::Plain 63 Plain = QFrame::Plain, 64 65 //! QFrame::Raised 66 Raised = QFrame::Raised, 67 68 //! QFrame::Sunken 69 Sunken = QFrame::Sunken 70 }; 71 72 /*! 73 \brief Frame shape 74 75 Unfortunately it is not possible to use QFrame::Shape 76 as a property of a widget that is not derived from QFrame. 77 The following enum is made for the designer only. It is safe 78 to use QFrame::Shadow instead. 79 80 \note QFrame::StyledPanel and QFrame::WinPanel are unsupported 81 and will be displayed as QFrame::Panel. 82 */ 83 enum Shape 84 { 85 NoFrame = QFrame::NoFrame, 86 87 Box = QFrame::Box, 88 Panel = QFrame::Panel 89 }; 90 91 explicit QwtPlotGLCanvas( QwtPlot * = NULL ); 58 public: 59 explicit QwtPlotGLCanvas( QwtPlot* = NULL ); 60 explicit QwtPlotGLCanvas( const QGLFormat&, QwtPlot* = NULL ); 92 61 virtual ~QwtPlotGLCanvas(); 93 62 94 void setFrameStyle( int style );95 int frameStyle() const;63 Q_INVOKABLE virtual void invalidateBackingStore() QWT_OVERRIDE; 64 Q_INVOKABLE QPainterPath borderPath( const QRect& ) const; 96 65 97 void setFrameShadow( Shadow ); 98 Shadow frameShadow() const; 66 virtual bool event( QEvent* ) QWT_OVERRIDE; 99 67 100 void setFrameShape( Shape ); 101 Shape frameShape() const; 102 103 void setLineWidth( int ); 104 int lineWidth() const; 105 106 void setMidLineWidth( int ); 107 int midLineWidth() const; 108 109 int frameWidth() const; 110 QRect frameRect() const; 111 112 Q_INVOKABLE QPainterPath borderPath( const QRect & ) const; 113 114 virtual bool event( QEvent * ); 115 116 public Q_SLOTS: 68 public Q_SLOTS: 117 69 void replot(); 118 70 119 protected: 120 virtual void paintEvent( QPaintEvent * );71 protected: 72 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 121 73 122 virtual void drawBackground( QPainter * );123 virtual void drawBorder( QPainter * );124 virtual void drawItems( QPainter * );74 virtual void initializeGL() QWT_OVERRIDE; 75 virtual void paintGL() QWT_OVERRIDE; 76 virtual void resizeGL( int width, int height ) QWT_OVERRIDE; 125 77 126 private: 78 private: 79 void init(); 80 virtual void clearBackingStore() QWT_OVERRIDE; 81 127 82 class PrivateData; 128 PrivateData *d_data;83 PrivateData* m_data; 129 84 }; 130 85 -
trunk/BNC/qwt/qwt_plot_grid.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_scale_map.h" 14 14 #include "qwt_scale_div.h" 15 #include "qwt_math.h" 15 16 16 #include <qpainter.h> 17 17 #include <qpen.h> 18 18 19 static inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 ) 20 { 21 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 ); 22 } 23 19 24 class QwtPlotGrid::PrivateData 20 25 { 21 public: 22 PrivateData() :23 xEnabled( true ) ,24 yEnabled( true ) ,25 xMinEnabled( false ) ,26 yMinEnabled( false ) 26 public: 27 PrivateData() 28 : xEnabled( true ) 29 , yEnabled( true ) 30 , xMinEnabled( false ) 31 , yMinEnabled( false ) 27 32 { 28 33 } … … 41 46 42 47 //! Enables major grid, disables minor grid 43 QwtPlotGrid::QwtPlotGrid() :44 QwtPlotItem( QwtText( "Grid" ) ) 45 { 46 d_data = new PrivateData;48 QwtPlotGrid::QwtPlotGrid() 49 : QwtPlotItem( QwtText( "Grid" ) ) 50 { 51 m_data = new PrivateData; 47 52 48 53 setItemInterest( QwtPlotItem::ScaleInterest, true ); … … 53 58 QwtPlotGrid::~QwtPlotGrid() 54 59 { 55 delete d_data;60 delete m_data; 56 61 } 57 62 … … 63 68 64 69 /*! 65 \brief Enable or disable vertical grid lines 66 \param on Enable (true) or disable 67 68 \sa Minor grid lines can be enabled or disabled with 70 \brief Enable or disable vertical grid lines 71 \param on Enable (true) or disable 72 73 \sa Minor grid lines can be enabled or disabled with 69 74 enableXMin() 70 */ 75 */ 71 76 void QwtPlotGrid::enableX( bool on ) 72 77 { 73 if ( d_data->xEnabled != on )74 { 75 d_data->xEnabled = on;76 77 legendChanged(); 78 itemChanged(); 79 } 80 } 81 82 /*! 83 \brief Enable or disable horizontal grid lines 84 \param on Enable (true) or disable 85 \sa Minor grid lines can be enabled or disabled with enableYMin() 86 */ 78 if ( m_data->xEnabled != on ) 79 { 80 m_data->xEnabled = on; 81 82 legendChanged(); 83 itemChanged(); 84 } 85 } 86 87 /*! 88 \brief Enable or disable horizontal grid lines 89 \param on Enable (true) or disable 90 \sa Minor grid lines can be enabled or disabled with enableYMin() 91 */ 87 92 void QwtPlotGrid::enableY( bool on ) 88 93 { 89 if ( d_data->yEnabled != on )90 { 91 d_data->yEnabled = on;92 93 legendChanged(); 94 itemChanged(); 95 } 96 } 97 98 /*! 99 \brief Enable or disable minor vertical grid lines. 100 \param on Enable (true) or disable 101 \sa enableX() 102 */ 94 if ( m_data->yEnabled != on ) 95 { 96 m_data->yEnabled = on; 97 98 legendChanged(); 99 itemChanged(); 100 } 101 } 102 103 /*! 104 \brief Enable or disable minor vertical grid lines. 105 \param on Enable (true) or disable 106 \sa enableX() 107 */ 103 108 void QwtPlotGrid::enableXMin( bool on ) 104 109 { 105 if ( d_data->xMinEnabled != on )106 { 107 d_data->xMinEnabled = on;108 109 legendChanged(); 110 itemChanged(); 111 } 112 } 113 114 /*! 115 \brief Enable or disable minor horizontal grid lines 116 \param on Enable (true) or disable 117 \sa enableY() 118 */ 110 if ( m_data->xMinEnabled != on ) 111 { 112 m_data->xMinEnabled = on; 113 114 legendChanged(); 115 itemChanged(); 116 } 117 } 118 119 /*! 120 \brief Enable or disable minor horizontal grid lines 121 \param on Enable (true) or disable 122 \sa enableY() 123 */ 119 124 void QwtPlotGrid::enableYMin( bool on ) 120 125 { 121 if ( d_data->yMinEnabled != on )122 { 123 d_data->yMinEnabled = on;124 125 legendChanged(); 126 itemChanged(); 127 } 128 } 129 130 /*! 131 Assign an x axis scale division 132 133 \param scaleDiv Scale division 134 */ 135 void QwtPlotGrid::setXDiv( const QwtScaleDiv &scaleDiv )136 { 137 if ( d_data->xScaleDiv != scaleDiv )138 { 139 d_data->xScaleDiv = scaleDiv;140 itemChanged(); 141 } 142 } 143 144 /*! 145 Assign a y axis division 146 147 \param scaleDiv Scale division 148 */ 149 void QwtPlotGrid::setYDiv( const QwtScaleDiv &scaleDiv )150 { 151 if ( d_data->yScaleDiv != scaleDiv )152 { 153 d_data->yScaleDiv = scaleDiv;154 itemChanged(); 155 } 156 } 157 158 /*! 159 Build and assign a pen for both major and minor grid lines 160 161 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 162 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 163 to hide this incompatibility. 164 165 \param color Pen color 166 \param width Pen width 167 \param style Pen style 168 169 \sa pen(), brush() 170 */ 171 void QwtPlotGrid::setPen( const QColor &color, qreal width, Qt::PenStyle style )126 if ( m_data->yMinEnabled != on ) 127 { 128 m_data->yMinEnabled = on; 129 130 legendChanged(); 131 itemChanged(); 132 } 133 } 134 135 /*! 136 Assign an x axis scale division 137 138 \param scaleDiv Scale division 139 */ 140 void QwtPlotGrid::setXDiv( const QwtScaleDiv& scaleDiv ) 141 { 142 if ( m_data->xScaleDiv != scaleDiv ) 143 { 144 m_data->xScaleDiv = scaleDiv; 145 itemChanged(); 146 } 147 } 148 149 /*! 150 Assign a y axis division 151 152 \param scaleDiv Scale division 153 */ 154 void QwtPlotGrid::setYDiv( const QwtScaleDiv& scaleDiv ) 155 { 156 if ( m_data->yScaleDiv != scaleDiv ) 157 { 158 m_data->yScaleDiv = scaleDiv; 159 itemChanged(); 160 } 161 } 162 163 /*! 164 Build and assign a pen for both major and minor grid lines 165 166 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 167 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 168 to hide this incompatibility. 169 170 \param color Pen color 171 \param width Pen width 172 \param style Pen style 173 174 \sa pen(), brush() 175 */ 176 void QwtPlotGrid::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 172 177 { 173 178 setPen( QPen( color, width, style ) ); … … 175 180 176 181 /*! 177 Assign a pen for both major and minor grid lines 178 179 \param pen Pen 180 \sa setMajorPen(), setMinorPen() 181 */ 182 void QwtPlotGrid::setPen( const QPen &pen )183 { 184 if ( d_data->majorPen != pen ||d_data->minorPen != pen )185 { 186 d_data->majorPen = pen;187 d_data->minorPen = pen;188 189 legendChanged(); 190 itemChanged(); 191 } 192 } 193 194 /*! 195 Build and assign a pen for both major grid lines 196 197 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 198 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 199 to hide this incompatibility. 200 201 \param color Pen color 202 \param width Pen width 203 \param style Pen style 204 205 \sa pen(), brush() 206 */ 207 void QwtPlotGrid::setMajorPen( const QColor &color, qreal width, Qt::PenStyle style )182 Assign a pen for both major and minor grid lines 183 184 \param pen Pen 185 \sa setMajorPen(), setMinorPen() 186 */ 187 void QwtPlotGrid::setPen( const QPen& pen ) 188 { 189 if ( m_data->majorPen != pen || m_data->minorPen != pen ) 190 { 191 m_data->majorPen = pen; 192 m_data->minorPen = pen; 193 194 legendChanged(); 195 itemChanged(); 196 } 197 } 198 199 /*! 200 Build and assign a pen for both major grid lines 201 202 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 203 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 204 to hide this incompatibility. 205 206 \param color Pen color 207 \param width Pen width 208 \param style Pen style 209 210 \sa pen(), brush() 211 */ 212 void QwtPlotGrid::setMajorPen( const QColor& color, qreal width, Qt::PenStyle style ) 208 213 { 209 214 setMajorPen( QPen( color, width, style ) ); … … 211 216 212 217 /*! 213 Assign a pen for the major grid lines 214 215 \param pen Pen 216 \sa majorPen(), setMinorPen(), setPen() 217 */ 218 void QwtPlotGrid::setMajorPen( const QPen &pen )219 { 220 if ( d_data->majorPen != pen )221 { 222 d_data->majorPen = pen;223 224 legendChanged(); 225 itemChanged(); 226 } 227 } 228 229 /*! 230 Build and assign a pen for the minor grid lines 231 232 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 233 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 234 to hide this incompatibility. 235 236 \param color Pen color 237 \param width Pen width 238 \param style Pen style 239 240 \sa pen(), brush() 241 */ 242 void QwtPlotGrid::setMinorPen( const QColor &color, qreal width, Qt::PenStyle style )218 Assign a pen for the major grid lines 219 220 \param pen Pen 221 \sa majorPen(), setMinorPen(), setPen() 222 */ 223 void QwtPlotGrid::setMajorPen( const QPen& pen ) 224 { 225 if ( m_data->majorPen != pen ) 226 { 227 m_data->majorPen = pen; 228 229 legendChanged(); 230 itemChanged(); 231 } 232 } 233 234 /*! 235 Build and assign a pen for the minor grid lines 236 237 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 238 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 239 to hide this incompatibility. 240 241 \param color Pen color 242 \param width Pen width 243 \param style Pen style 244 245 \sa pen(), brush() 246 */ 247 void QwtPlotGrid::setMinorPen( const QColor& color, qreal width, Qt::PenStyle style ) 243 248 { 244 249 setMinorPen( QPen( color, width, style ) ); … … 246 251 247 252 /*! 248 Assign a pen for the minor grid lines 249 250 \param pen Pen 251 \sa minorPen(), setMajorPen(), setPen() 252 */ 253 void QwtPlotGrid::setMinorPen( const QPen &pen )254 { 255 if ( d_data->minorPen != pen )256 { 257 d_data->minorPen = pen;258 259 legendChanged(); 260 itemChanged(); 261 } 262 } 263 264 /*! 265 \brief Draw the grid 266 267 The grid is drawn into the bounding rectangle such that 268 grid lines begin and end at the rectangle's borders. The X and Y 269 maps are used to map the scale divisions into the drawing region 270 screen. 271 272 \param painter Painter 273 \param xMap X axis map 274 \param yMap Y axis 275 \param canvasRect Contents rectangle of the plot canvas 276 */ 277 void QwtPlotGrid::draw( QPainter *painter,278 const QwtScaleMap &xMap, const QwtScaleMap&yMap,279 const QRectF &canvasRect ) const253 Assign a pen for the minor grid lines 254 255 \param pen Pen 256 \sa minorPen(), setMajorPen(), setPen() 257 */ 258 void QwtPlotGrid::setMinorPen( const QPen& pen ) 259 { 260 if ( m_data->minorPen != pen ) 261 { 262 m_data->minorPen = pen; 263 264 legendChanged(); 265 itemChanged(); 266 } 267 } 268 269 /*! 270 \brief Draw the grid 271 272 The grid is drawn into the bounding rectangle such that 273 grid lines begin and end at the rectangle's borders. The X and Y 274 maps are used to map the scale divisions into the drawing region 275 screen. 276 277 \param painter Painter 278 \param xMap X axis map 279 \param yMap Y axis 280 \param canvasRect Contents rectangle of the plot canvas 281 */ 282 void QwtPlotGrid::draw( QPainter* painter, 283 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 284 const QRectF& canvasRect ) const 280 285 { 281 286 // draw minor grid lines 282 QPen minorPen = d_data->minorPen;287 QPen minorPen = m_data->minorPen; 283 288 minorPen.setCapStyle( Qt::FlatCap ); 284 289 285 290 painter->setPen( minorPen ); 286 291 287 if ( d_data->xEnabled &&d_data->xMinEnabled )292 if ( m_data->xEnabled && m_data->xMinEnabled ) 288 293 { 289 294 drawLines( painter, canvasRect, Qt::Vertical, xMap, 290 d_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) );295 m_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) ); 291 296 drawLines( painter, canvasRect, Qt::Vertical, xMap, 292 d_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) );293 } 294 295 if ( d_data->yEnabled &&d_data->yMinEnabled )297 m_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) ); 298 } 299 300 if ( m_data->yEnabled && m_data->yMinEnabled ) 296 301 { 297 302 drawLines( painter, canvasRect, Qt::Horizontal, yMap, 298 d_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) );303 m_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) ); 299 304 drawLines( painter, canvasRect, Qt::Horizontal, yMap, 300 d_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) );305 m_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) ); 301 306 } 302 307 303 308 // draw major grid lines 304 QPen majorPen = d_data->majorPen;309 QPen majorPen = m_data->majorPen; 305 310 majorPen.setCapStyle( Qt::FlatCap ); 306 311 307 312 painter->setPen( majorPen ); 308 313 309 if ( d_data->xEnabled )314 if ( m_data->xEnabled ) 310 315 { 311 316 drawLines( painter, canvasRect, Qt::Vertical, xMap, 312 d_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) );313 } 314 315 if ( d_data->yEnabled )317 m_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) ); 318 } 319 320 if ( m_data->yEnabled ) 316 321 { 317 322 drawLines( painter, canvasRect, Qt::Horizontal, yMap, 318 d_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) );319 } 320 } 321 322 void QwtPlotGrid::drawLines( QPainter *painter, const QRectF&canvasRect,323 Qt::Orientation orientation, const QwtScaleMap &scaleMap,324 const QList< double> &values ) const323 m_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) ); 324 } 325 } 326 327 void QwtPlotGrid::drawLines( QPainter* painter, const QRectF& canvasRect, 328 Qt::Orientation orientation, const QwtScaleMap& scaleMap, 329 const QList< double >& values ) const 325 330 { 326 331 const double x1 = canvasRect.left(); … … 340 345 { 341 346 if ( qwtFuzzyGreaterOrEqual( value, y1 ) && 342 qwtFuzzy LessOrEqual(value, y2) )347 qwtFuzzyGreaterOrEqual( y2, value ) ) 343 348 { 344 349 QwtPainter::drawLine( painter, x1, value, x2, value ); … … 348 353 { 349 354 if ( qwtFuzzyGreaterOrEqual( value, x1 ) && 350 qwtFuzzy LessOrEqual(value, x2) )355 qwtFuzzyGreaterOrEqual( x2, value ) ) 351 356 { 352 357 QwtPainter::drawLine( painter, value, y1, value, y2 ); … … 357 362 358 363 /*! 359 \return the pen for the major grid lines 360 \sa setMajorPen(), setMinorPen(), setPen() 361 */ 362 const QPen &QwtPlotGrid::majorPen() const363 { 364 return d_data->majorPen;365 } 366 367 /*! 368 \return the pen for the minor grid lines 369 \sa setMinorPen(), setMajorPen(), setPen() 370 */ 371 const QPen &QwtPlotGrid::minorPen() const372 { 373 return d_data->minorPen;374 } 375 376 /*! 377 \return true if vertical grid lines are enabled 378 \sa enableX() 379 */ 364 \return the pen for the major grid lines 365 \sa setMajorPen(), setMinorPen(), setPen() 366 */ 367 const QPen& QwtPlotGrid::majorPen() const 368 { 369 return m_data->majorPen; 370 } 371 372 /*! 373 \return the pen for the minor grid lines 374 \sa setMinorPen(), setMajorPen(), setPen() 375 */ 376 const QPen& QwtPlotGrid::minorPen() const 377 { 378 return m_data->minorPen; 379 } 380 381 /*! 382 \return true if vertical grid lines are enabled 383 \sa enableX() 384 */ 380 385 bool QwtPlotGrid::xEnabled() const 381 386 { 382 return d_data->xEnabled;383 } 384 385 /*! 386 \return true if minor vertical grid lines are enabled 387 \sa enableXMin() 388 */ 387 return m_data->xEnabled; 388 } 389 390 /*! 391 \return true if minor vertical grid lines are enabled 392 \sa enableXMin() 393 */ 389 394 bool QwtPlotGrid::xMinEnabled() const 390 395 { 391 return d_data->xMinEnabled;392 } 393 394 /*! 395 \return true if horizontal grid lines are enabled 396 \sa enableY() 397 */ 396 return m_data->xMinEnabled; 397 } 398 399 /*! 400 \return true if horizontal grid lines are enabled 401 \sa enableY() 402 */ 398 403 bool QwtPlotGrid::yEnabled() const 399 404 { 400 return d_data->yEnabled;401 } 402 403 /*! 404 \return true if minor horizontal grid lines are enabled 405 \sa enableYMin() 406 */ 405 return m_data->yEnabled; 406 } 407 408 /*! 409 \return true if minor horizontal grid lines are enabled 410 \sa enableYMin() 411 */ 407 412 bool QwtPlotGrid::yMinEnabled() const 408 413 { 409 return d_data->yMinEnabled;414 return m_data->yMinEnabled; 410 415 } 411 416 412 417 413 418 /*! \return the scale division of the x axis */ 414 const QwtScaleDiv &QwtPlotGrid::xScaleDiv() const415 { 416 return d_data->xScaleDiv;419 const QwtScaleDiv& QwtPlotGrid::xScaleDiv() const 420 { 421 return m_data->xScaleDiv; 417 422 } 418 423 419 424 /*! \return the scale division of the y axis */ 420 const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const421 { 422 return d_data->yScaleDiv;425 const QwtScaleDiv& QwtPlotGrid::yScaleDiv() const 426 { 427 return m_data->yScaleDiv; 423 428 } 424 429 … … 430 435 431 436 \sa QwtPlot::updateAxes() 432 */ 437 */ 433 438 void QwtPlotGrid::updateScaleDiv( const QwtScaleDiv& xScaleDiv, 434 439 const QwtScaleDiv& yScaleDiv ) -
trunk/BNC/qwt/qwt_plot_grid.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include "qwt_scale_div.h"16 15 17 16 class QPainter; … … 21 20 22 21 /*! 23 \brief A class which draws a coordinate grid 22 \brief A class which draws a coordinate grid 24 23 25 The QwtPlotGrid class can be used to draw a coordinate grid. 26 A coordinate grid consists of major and minor vertical 27 and horizontal grid lines. The locations of the grid lines 28 are determined by the X and Y scale divisions which can 29 be assigned with setXDiv() and setYDiv(). 30 The draw() member draws the grid within a bounding 31 rectangle. 32 */ 24 The QwtPlotGrid class can be used to draw a coordinate grid. 25 A coordinate grid consists of major and minor vertical 26 and horizontal grid lines. The locations of the grid lines 27 are determined by the X and Y scale divisions which can 28 be assigned with setXDiv() and setYDiv(). 29 The draw() member draws the grid within a bounding 30 rectangle. 31 */ 33 32 34 class QWT_EXPORT QwtPlotGrid: public QwtPlotItem 33 class QWT_EXPORT QwtPlotGrid : public QwtPlotItem 35 34 { 36 public: 35 public: 37 36 explicit QwtPlotGrid(); 38 37 virtual ~QwtPlotGrid(); 39 38 40 virtual int rtti() const; 39 virtual int rtti() const QWT_OVERRIDE; 41 40 42 41 void enableX( bool ); … … 52 51 bool yMinEnabled() const; 53 52 54 void setXDiv( const QwtScaleDiv & );55 const QwtScaleDiv &xScaleDiv() const;53 void setXDiv( const QwtScaleDiv& ); 54 const QwtScaleDiv& xScaleDiv() const; 56 55 57 void setYDiv( const QwtScaleDiv & );58 const QwtScaleDiv &yScaleDiv() const;56 void setYDiv( const QwtScaleDiv& ); 57 const QwtScaleDiv& yScaleDiv() const; 59 58 60 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );61 void setPen( const QPen &);59 void setPen( const QColor&, 60 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 62 61 63 void setMajorPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 64 void setMajorPen( const QPen & ); 62 void setPen( const QPen& ); 63 64 void setMajorPen( const QColor&, 65 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 66 67 void setMajorPen( const QPen& ); 65 68 const QPen& majorPen() const; 66 69 67 void setMinorPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );68 void setMinorPen( const QPen & );70 void setMinorPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 71 void setMinorPen( const QPen& ); 69 72 const QPen& minorPen() const; 70 73 71 virtual void draw( QPainter *,72 const QwtScaleMap &xMap, const QwtScaleMap&yMap,73 const QRectF &canvasRect ) const;74 virtual void draw( QPainter*, 75 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 76 const QRectF& canvasRect ) const QWT_OVERRIDE; 74 77 75 78 virtual void updateScaleDiv( 76 const QwtScaleDiv &xScaleDiv, const QwtScaleDiv&yScaleDiv );79 const QwtScaleDiv& xScaleDiv, const QwtScaleDiv& yScaleDiv ) QWT_OVERRIDE; 77 80 78 private: 79 void drawLines( QPainter *, const QRectF&,80 Qt::Orientation, const QwtScaleMap &,81 const QList< double>& ) const;81 private: 82 void drawLines( QPainter*, const QRectF&, 83 Qt::Orientation, const QwtScaleMap&, 84 const QList< double >& ) const; 82 85 83 86 class PrivateData; 84 PrivateData *d_data;87 PrivateData* m_data; 85 88 }; 86 89 -
trunk/BNC/qwt/qwt_plot_histogram.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot_histogram.h" 11 #include "qwt_plot.h"12 11 #include "qwt_painter.h" 13 12 #include "qwt_column_symbol.h" 14 13 #include "qwt_scale_map.h" 14 #include "qwt_graphic.h" 15 15 16 #include <qstring.h> 16 17 #include <qpainter.h> 17 18 18 static inline bool qwtIsCombinable( const QwtInterval &d1,19 const QwtInterval &d2 )19 static inline bool qwtIsCombinable( const QwtInterval& d1, 20 const QwtInterval& d2 ) 20 21 { 21 22 if ( d1.isValid() && d2.isValid() ) … … 36 37 class QwtPlotHistogram::PrivateData 37 38 { 38 public: 39 PrivateData() :40 baseline( 0.0 ) ,41 style( Columns ) ,42 symbol( NULL ) 39 public: 40 PrivateData() 41 : baseline( 0.0 ) 42 , style( Columns ) 43 , symbol( NULL ) 43 44 { 44 45 } … … 54 55 QBrush brush; 55 56 QwtPlotHistogram::HistogramStyle style; 56 const QwtColumnSymbol *symbol;57 const QwtColumnSymbol* symbol; 57 58 }; 58 59 59 60 /*! 60 Constructor 61 \param title Title of the histogram. 62 */ 63 QwtPlotHistogram::QwtPlotHistogram( const QwtText &title ):64 QwtPlotSeriesItem( title ) 61 Constructor 62 \param title Title of the histogram. 63 */ 64 QwtPlotHistogram::QwtPlotHistogram( const QwtText& title ) 65 : QwtPlotSeriesItem( title ) 65 66 { 66 67 init(); … … 68 69 69 70 /*! 70 Constructor 71 \param title Title of the histogram. 72 */ 73 QwtPlotHistogram::QwtPlotHistogram( const QString &title ):74 QwtPlotSeriesItem( title ) 71 Constructor 72 \param title Title of the histogram. 73 */ 74 QwtPlotHistogram::QwtPlotHistogram( const QString& title ) 75 : QwtPlotSeriesItem( title ) 75 76 { 76 77 init(); … … 80 81 QwtPlotHistogram::~QwtPlotHistogram() 81 82 { 82 delete d_data;83 delete m_data; 83 84 } 84 85 … … 86 87 void QwtPlotHistogram::init() 87 88 { 88 d_data = new PrivateData();89 m_data = new PrivateData(); 89 90 setData( new QwtIntervalSeriesData() ); 90 91 … … 96 97 97 98 /*! 98 Set the histogram's drawing style 99 100 \param style Histogram style 101 \sa HistogramStyle, style() 102 */ 99 Set the histogram's drawing style 100 101 \param style Histogram style 102 \sa HistogramStyle, style() 103 */ 103 104 void QwtPlotHistogram::setStyle( HistogramStyle style ) 104 105 { 105 if ( style != d_data->style )106 { 107 d_data->style = style;106 if ( style != m_data->style ) 107 { 108 m_data->style = style; 108 109 109 110 legendChanged(); … … 115 116 \return Style of the histogram 116 117 \sa HistogramStyle, setStyle() 117 */ 118 */ 118 119 QwtPlotHistogram::HistogramStyle QwtPlotHistogram::style() const 119 120 { 120 return d_data->style;121 } 122 123 /*! 124 Build and assign a pen 125 126 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 127 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 128 to hide this incompatibility. 129 130 \param color Pen color 131 \param width Pen width 132 \param style Pen style 133 134 \sa pen(), brush() 135 */ 136 void QwtPlotHistogram::setPen( const QColor &color, qreal width, Qt::PenStyle style )121 return m_data->style; 122 } 123 124 /*! 125 Build and assign a pen 126 127 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 128 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 129 to hide this incompatibility. 130 131 \param color Pen color 132 \param width Pen width 133 \param style Pen style 134 135 \sa pen(), brush() 136 */ 137 void QwtPlotHistogram::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 137 138 { 138 139 setPen( QPen( color, width, style ) ); … … 140 141 141 142 /*! 142 Assign a pen, that is used in a style() depending way. 143 144 \param pen New pen 145 \sa pen(), brush() 146 */ 147 void QwtPlotHistogram::setPen( const QPen &pen )148 { 149 if ( pen != d_data->pen )150 { 151 d_data->pen = pen;143 Assign a pen, that is used in a style() depending way. 144 145 \param pen New pen 146 \sa pen(), brush() 147 */ 148 void QwtPlotHistogram::setPen( const QPen& pen ) 149 { 150 if ( pen != m_data->pen ) 151 { 152 m_data->pen = pen; 152 153 153 154 legendChanged(); … … 157 158 158 159 /*! 159 \return Pen used in a style() depending way. 160 \sa setPen(), brush() 161 */ 162 const QPen &QwtPlotHistogram::pen() const163 { 164 return d_data->pen;165 } 166 167 /*! 168 Assign a brush, that is used in a style() depending way. 169 170 \param brush New brush 171 \sa pen(), brush() 172 */ 173 void QwtPlotHistogram::setBrush( const QBrush &brush )174 { 175 if ( brush != d_data->brush )176 { 177 d_data->brush = brush;160 \return Pen used in a style() depending way. 161 \sa setPen(), brush() 162 */ 163 const QPen& QwtPlotHistogram::pen() const 164 { 165 return m_data->pen; 166 } 167 168 /*! 169 Assign a brush, that is used in a style() depending way. 170 171 \param brush New brush 172 \sa pen(), brush() 173 */ 174 void QwtPlotHistogram::setBrush( const QBrush& brush ) 175 { 176 if ( brush != m_data->brush ) 177 { 178 m_data->brush = brush; 178 179 179 180 legendChanged(); … … 183 184 184 185 /*! 185 \return Brush used in a style() depending way. 186 \sa setPen(), brush() 187 */ 188 const QBrush &QwtPlotHistogram::brush() const189 { 190 return d_data->brush;191 } 192 193 /*! 194 \brief Assign a symbol 195 196 In Column style an optional symbol can be assigned, that is responsible 197 for displaying the rectangle that is defined by the interval and 198 the distance between baseline() and value. When no symbol has been 199 defined the area is displayed as plain rectangle using pen() and brush(). 200 201 \sa style(), symbol(), drawColumn(), pen(), brush() 202 203 \note In applications, where different intervals need to be displayed 186 \return Brush used in a style() depending way. 187 \sa setPen(), brush() 188 */ 189 const QBrush& QwtPlotHistogram::brush() const 190 { 191 return m_data->brush; 192 } 193 194 /*! 195 \brief Assign a symbol 196 197 In Column style an optional symbol can be assigned, that is responsible 198 for displaying the rectangle that is defined by the interval and 199 the distance between baseline() and value. When no symbol has been 200 defined the area is displayed as plain rectangle using pen() and brush(). 201 202 \sa style(), symbol(), drawColumn(), pen(), brush() 203 204 \note In applications, where different intervals need to be displayed 204 205 in a different way ( f.e different colors or even using different symbols) 205 206 it is recommended to overload drawColumn(). 206 */ 207 void QwtPlotHistogram::setSymbol( const QwtColumnSymbol *symbol )208 { 209 if ( symbol != d_data->symbol )210 { 211 delete d_data->symbol;212 d_data->symbol = symbol;207 */ 208 void QwtPlotHistogram::setSymbol( const QwtColumnSymbol* symbol ) 209 { 210 if ( symbol != m_data->symbol ) 211 { 212 delete m_data->symbol; 213 m_data->symbol = symbol; 213 214 214 215 legendChanged(); … … 218 219 219 220 /*! 220 \return Current symbol or NULL, when no symbol has been assigned 221 \sa setSymbol() 222 */ 223 const QwtColumnSymbol *QwtPlotHistogram::symbol() const224 { 225 return d_data->symbol;226 } 227 228 /*! 229 \brief Set the value of the baseline 230 231 Each column representing an QwtIntervalSample is defined by its 232 interval and the interval between baseline and the value of the sample. 233 234 The default value of the baseline is 0.0. 235 236 \param value Value of the baseline 237 \sa baseline() 238 */ 221 \return Current symbol or NULL, when no symbol has been assigned 222 \sa setSymbol() 223 */ 224 const QwtColumnSymbol* QwtPlotHistogram::symbol() const 225 { 226 return m_data->symbol; 227 } 228 229 /*! 230 \brief Set the value of the baseline 231 232 Each column representing an QwtIntervalSample is defined by its 233 interval and the interval between baseline and the value of the sample. 234 235 The default value of the baseline is 0.0. 236 237 \param value Value of the baseline 238 \sa baseline() 239 */ 239 240 void QwtPlotHistogram::setBaseline( double value ) 240 241 { 241 if ( d_data->baseline != value )242 { 243 d_data->baseline = value;242 if ( m_data->baseline != value ) 243 { 244 m_data->baseline = value; 244 245 itemChanged(); 245 246 } … … 247 248 248 249 /*! 249 \return Value of the baseline 250 \sa setBaseline() 251 */ 250 \return Value of the baseline 251 \sa setBaseline() 252 */ 252 253 double QwtPlotHistogram::baseline() const 253 254 { 254 return d_data->baseline;255 } 256 257 /*! 258 \return Bounding rectangle of all samples. 259 For an empty series the rectangle is invalid. 260 */ 255 return m_data->baseline; 256 } 257 258 /*! 259 \return Bounding rectangle of all samples. 260 For an empty series the rectangle is invalid. 261 */ 261 262 QRectF QwtPlotHistogram::boundingRect() const 262 263 { … … 270 271 rect.height(), rect.width() ); 271 272 272 if ( rect.left() > d_data->baseline )273 rect.setLeft( d_data->baseline );274 else if ( rect.right() < d_data->baseline )275 rect.setRight( d_data->baseline );273 if ( rect.left() > m_data->baseline ) 274 rect.setLeft( m_data->baseline ); 275 else if ( rect.right() < m_data->baseline ) 276 rect.setRight( m_data->baseline ); 276 277 } 277 278 else 278 279 { 279 if ( rect.bottom() < d_data->baseline )280 rect.setBottom( d_data->baseline );281 else if ( rect.top() > d_data->baseline )282 rect.setTop( d_data->baseline );280 if ( rect.bottom() < m_data->baseline ) 281 rect.setBottom( m_data->baseline ); 282 else if ( rect.top() > m_data->baseline ) 283 rect.setTop( m_data->baseline ); 283 284 } 284 285 … … 293 294 294 295 /*! 295 Initialize data with an array of samples. 296 \param samples Vector of points 297 */ 296 Initialize data with an array of samples. 297 \param samples Vector of points 298 */ 298 299 void QwtPlotHistogram::setSamples( 299 const QVector<QwtIntervalSample > &samples )300 const QVector< QwtIntervalSample >& samples ) 300 301 { 301 302 setData( new QwtIntervalSeriesData( samples ) ); … … 303 304 304 305 /*! 305 Assign a series of samples 306 307 setSamples() is just a wrapper for setData() without any additional 308 value - beside that it is easier to find for the developer. 309 310 \param data Data 311 \warning The item takes ownership of the data object, deleting 306 Assign a series of samples 307 308 setSamples() is just a wrapper for setData() without any additional 309 value - beside that it is easier to find for the developer. 310 311 \param data Data 312 \warning The item takes ownership of the data object, deleting 312 313 it when its not used anymore. 313 */ 314 */ 314 315 void QwtPlotHistogram::setSamples( 315 QwtSeriesData<QwtIntervalSample > *data )316 QwtSeriesData< QwtIntervalSample >* data ) 316 317 { 317 318 setData( data ); … … 319 320 320 321 /*! 321 Draw a subset of the histogram samples 322 323 \param painter Painter 324 \param xMap Maps x-values into pixel coordinates. 325 \param yMap Maps y-values into pixel coordinates. 326 \param canvasRect Contents rectangle of the canvas 327 \param from Index of the first sample to be painted 328 \param to Index of the last sample to be painted. If to < 0 the 322 Draw a subset of the histogram samples 323 324 \param painter Painter 325 \param xMap Maps x-values into pixel coordinates. 326 \param yMap Maps y-values into pixel coordinates. 327 \param canvasRect Contents rectangle of the canvas 328 \param from Index of the first sample to be painted 329 \param to Index of the last sample to be painted. If to < 0 the 329 330 series will be painted to its last sample. 330 331 331 \sa drawOutline(), drawLines(), drawColumns 332 */ 333 void QwtPlotHistogram::drawSeries( QPainter *painter,334 const QwtScaleMap &xMap, const QwtScaleMap&yMap,335 const QRectF &canvasRect, int from, int to ) const332 \sa drawOutline(), drawLines(), drawColumns 333 */ 334 void QwtPlotHistogram::drawSeries( QPainter* painter, 335 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 336 const QRectF& canvasRect, int from, int to ) const 336 337 { 337 338 Q_UNUSED( canvasRect ) … … 343 344 to = dataSize() - 1; 344 345 345 switch ( d_data->style )346 switch ( m_data->style ) 346 347 { 347 348 case Outline: … … 360 361 361 362 /*! 362 Draw a histogram in Outline style() 363 364 \param painter Painter 365 \param xMap Maps x-values into pixel coordinates. 366 \param yMap Maps y-values into pixel coordinates. 367 \param from Index of the first sample to be painted 368 \param to Index of the last sample to be painted. If to < 0 the 363 Draw a histogram in Outline style() 364 365 \param painter Painter 366 \param xMap Maps x-values into pixel coordinates. 367 \param yMap Maps y-values into pixel coordinates. 368 \param from Index of the first sample to be painted 369 \param to Index of the last sample to be painted. If to < 0 the 369 370 histogram will be painted to its last point. 370 371 371 \sa setStyle(), style() 372 \warning The outline style requires, that the intervals are in increasing 372 \sa setStyle(), style() 373 \warning The outline style requires, that the intervals are in increasing 373 374 order and not overlapping. 374 */ 375 void QwtPlotHistogram::drawOutline( QPainter *painter,376 const QwtScaleMap &xMap, const QwtScaleMap&yMap,375 */ 376 void QwtPlotHistogram::drawOutline( QPainter* painter, 377 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 377 378 int from, int to ) const 378 379 { … … 447 448 448 449 /*! 449 Draw a histogram in Columns style() 450 451 \param painter Painter 452 \param xMap Maps x-values into pixel coordinates. 453 \param yMap Maps y-values into pixel coordinates. 454 \param from Index of the first sample to be painted 455 \param to Index of the last sample to be painted. If to < 0 the 450 Draw a histogram in Columns style() 451 452 \param painter Painter 453 \param xMap Maps x-values into pixel coordinates. 454 \param yMap Maps y-values into pixel coordinates. 455 \param from Index of the first sample to be painted 456 \param to Index of the last sample to be painted. If to < 0 the 456 457 histogram will be painted to its last point. 457 458 458 \sa setStyle(), style(), setSymbol(), drawColumn() 459 */ 460 void QwtPlotHistogram::drawColumns( QPainter *painter,461 const QwtScaleMap &xMap, const QwtScaleMap&yMap,459 \sa setStyle(), style(), setSymbol(), drawColumn() 460 */ 461 void QwtPlotHistogram::drawColumns( QPainter* painter, 462 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 462 463 int from, int to ) const 463 464 { 464 painter->setPen( d_data->pen );465 painter->setBrush( d_data->brush );466 467 const QwtSeriesData<QwtIntervalSample > *series = data();465 painter->setPen( m_data->pen ); 466 painter->setBrush( m_data->brush ); 467 468 const QwtSeriesData< QwtIntervalSample >* series = data(); 468 469 469 470 for ( int i = from; i <= to; i++ ) … … 479 480 480 481 /*! 481 Draw a histogram in Lines style() 482 483 \param painter Painter 484 \param xMap Maps x-values into pixel coordinates. 485 \param yMap Maps y-values into pixel coordinates. 486 \param from Index of the first sample to be painted 487 \param to Index of the last sample to be painted. If to < 0 the 482 Draw a histogram in Lines style() 483 484 \param painter Painter 485 \param xMap Maps x-values into pixel coordinates. 486 \param yMap Maps y-values into pixel coordinates. 487 \param from Index of the first sample to be painted 488 \param to Index of the last sample to be painted. If to < 0 the 488 489 histogram will be painted to its last point. 489 490 490 \sa setStyle(), style(), setPen() 491 */ 492 void QwtPlotHistogram::drawLines( QPainter *painter,493 const QwtScaleMap &xMap, const QwtScaleMap&yMap,491 \sa setStyle(), style(), setPen() 492 */ 493 void QwtPlotHistogram::drawLines( QPainter* painter, 494 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 494 495 int from, int to ) const 495 496 { 496 497 const bool doAlign = QwtPainter::roundingAlignment( painter ); 497 498 498 painter->setPen( d_data->pen );499 painter->setPen( m_data->pen ); 499 500 painter->setBrush( Qt::NoBrush ); 500 501 501 const QwtSeriesData<QwtIntervalSample > *series = data();502 const QwtSeriesData< QwtIntervalSample >* series = data(); 502 503 503 504 for ( int i = from; i <= to; i++ ) … … 549 550 550 551 //! Internal, used by the Outline style. 551 void QwtPlotHistogram::flushPolygon( QPainter *painter,552 double baseLine, QPolygonF &polygon ) const552 void QwtPlotHistogram::flushPolygon( QPainter* painter, 553 double baseLine, QPolygonF& polygon ) const 553 554 { 554 555 if ( polygon.size() == 0 ) … … 560 561 polygon += QPointF( polygon.last().x(), baseLine ); 561 562 562 if ( d_data->brush.style() != Qt::NoBrush )563 if ( m_data->brush.style() != Qt::NoBrush ) 563 564 { 564 565 painter->setPen( Qt::NoPen ); 565 painter->setBrush( d_data->brush );566 painter->setBrush( m_data->brush ); 566 567 567 568 if ( orientation() == Qt::Horizontal ) … … 581 582 polygon.pop_back(); 582 583 } 583 if ( d_data->pen.style() != Qt::NoPen )584 if ( m_data->pen.style() != Qt::NoPen ) 584 585 { 585 586 painter->setBrush( Qt::NoBrush ); 586 painter->setPen( d_data->pen );587 painter->setPen( m_data->pen ); 587 588 QwtPainter::drawPolyline( painter, polygon ); 588 589 } … … 591 592 592 593 /*! 593 Calculate the area that is covered by a sample 594 595 \param sample Sample 596 \param xMap Maps x-values into pixel coordinates. 597 \param yMap Maps y-values into pixel coordinates. 598 599 \return Rectangle, that is covered by a sample 600 */ 601 QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample &sample,602 const QwtScaleMap &xMap, const QwtScaleMap&yMap ) const594 Calculate the area that is covered by a sample 595 596 \param sample Sample 597 \param xMap Maps x-values into pixel coordinates. 598 \param yMap Maps y-values into pixel coordinates. 599 600 \return Rectangle, that is covered by a sample 601 */ 602 QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample& sample, 603 const QwtScaleMap& xMap, const QwtScaleMap& yMap ) const 603 604 { 604 605 QwtColumnRect rect; 605 606 606 const QwtInterval &iv = sample.interval;607 const QwtInterval& iv = sample.interval; 607 608 if ( !iv.isValid() ) 608 609 return rect; … … 611 612 { 612 613 const double x0 = xMap.transform( baseline() ); 613 const double x = xMap.transform( sample.value );614 const double x = xMap.transform( sample.value ); 614 615 const double y1 = yMap.transform( iv.minValue() ); 615 616 const double y2 = yMap.transform( iv.maxValue() ); … … 618 619 rect.vInterval.setInterval( y1, y2, iv.borderFlags() ); 619 620 rect.direction = ( x < x0 ) ? QwtColumnRect::RightToLeft : 620 QwtColumnRect::LeftToRight;621 QwtColumnRect::LeftToRight; 621 622 } 622 623 else … … 637 638 638 639 /*! 639 Draw a column for a sample in Columns style(). 640 641 When a symbol() has been set the symbol is used otherwise the 642 column is displayed as plain rectangle using pen() and brush(). 643 644 \param painter Painter 645 \param rect Rectangle where to paint the column in paint device coordinates 646 \param sample Sample to be displayed 647 648 \note In applications, where different intervals need to be displayed 640 Draw a column for a sample in Columns style(). 641 642 When a symbol() has been set the symbol is used otherwise the 643 column is displayed as plain rectangle using pen() and brush(). 644 645 \param painter Painter 646 \param rect Rectangle where to paint the column in paint device coordinates 647 \param sample Sample to be displayed 648 649 \note In applications, where different intervals need to be displayed 649 650 in a different way ( f.e different colors or even using different symbols) 650 651 it is recommended to overload drawColumn(). 651 */ 652 void QwtPlotHistogram::drawColumn( QPainter *painter,653 const QwtColumnRect &rect, const QwtIntervalSample&sample ) const652 */ 653 void QwtPlotHistogram::drawColumn( QPainter* painter, 654 const QwtColumnRect& rect, const QwtIntervalSample& sample ) const 654 655 { 655 656 Q_UNUSED( sample ); 656 657 657 if ( d_data->symbol &&658 ( d_data->symbol->style() != QwtColumnSymbol::NoStyle ) )659 { 660 d_data->symbol->draw( painter, rect );658 if ( m_data->symbol && 659 ( m_data->symbol->style() != QwtColumnSymbol::NoStyle ) ) 660 { 661 m_data->symbol->draw( painter, rect ); 661 662 } 662 663 else … … 676 677 677 678 /*! 678 A plain rectangle without pen using the brush() 679 680 \param index Index of the legend entry 679 A plain rectangle without pen using the brush() 680 681 \param index Index of the legend entry 681 682 ( ignored as there is only one ) 682 \param size Icon size 683 \return A graphic displaying the icon 684 685 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 686 */ 687 QwtGraphic QwtPlotHistogram::legendIcon( int index, 688 const QSizeF &size ) const 683 \param size Icon size 684 \return A graphic displaying the icon 685 686 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 687 */ 688 QwtGraphic QwtPlotHistogram::legendIcon( int index, const QSizeF& size ) const 689 689 { 690 690 Q_UNUSED( index ); 691 return defaultIcon( d_data->brush, size );692 } 691 return defaultIcon( m_data->brush, size ); 692 } -
trunk/BNC/qwt/qwt_plot_histogram.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_seriesitem.h" 15 #include "qwt_column_symbol.h"16 #include <qcolor.h>17 #include <qvector.h>18 15 19 class QwtIntervalData; 20 class QString; 16 class QwtColumnSymbol; 17 class QwtColumnRect; 18 class QColor; 21 19 class QPolygonF; 22 20 21 #if QT_VERSION < 0x060000 22 template< typename T > class QVector; 23 #endif 24 23 25 /*! 24 \brief QwtPlotHistogram represents a series of samples, where an interval 26 \brief QwtPlotHistogram represents a series of samples, where an interval 25 27 is associated with a value ( \f$y = f([x1,x2])\f$ ). 26 28 27 The representation depends on the style() and an optional symbol() 28 that is displayed for each interval. 29 The representation depends on the style() and an optional symbol() 30 that is displayed for each interval. 29 31 30 \note The term "histogram" is used in a different way in the areas of 32 \note The term "histogram" is used in a different way in the areas of 31 33 digital image processing and statistics. Wikipedia introduces the 32 34 terms "image histogram" and "color histogram" to avoid confusions. … … 34 36 is no applicable plot item for a "color histogram" yet. 35 37 36 \sa QwtPlotBarChart, QwtPlotMultiBarChart 37 */ 38 \sa QwtPlotBarChart, QwtPlotMultiBarChart 39 */ 38 40 39 class QWT_EXPORT QwtPlotHistogram: 40 public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample> 41 class QWT_EXPORT QwtPlotHistogram 42 : public QwtPlotSeriesItem 43 , public QwtSeriesStore< QwtIntervalSample > 41 44 { 42 public: 45 public: 43 46 /*! 44 47 Histogram styles. … … 46 49 47 50 \sa setStyle(), style(), setSymbol(), symbol(), setBaseline() 48 */ 51 */ 49 52 enum HistogramStyle 50 53 { … … 77 80 }; 78 81 79 explicit QwtPlotHistogram( const QString &title = QString() );80 explicit QwtPlotHistogram( const QwtText &title );82 explicit QwtPlotHistogram( const QString& title = QString() ); 83 explicit QwtPlotHistogram( const QwtText& title ); 81 84 virtual ~QwtPlotHistogram(); 82 85 83 virtual int rtti() const; 86 virtual int rtti() const QWT_OVERRIDE; 84 87 85 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 86 void setPen( const QPen & ); 87 const QPen &pen() const; 88 void setPen( const QColor&, 89 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 88 90 89 void set Brush( const QBrush& );90 const Q Brush &brush() const;91 void setPen( const QPen& ); 92 const QPen& pen() const; 91 93 92 void setSamples( const QVector<QwtIntervalSample> & ); 93 void setSamples( QwtSeriesData<QwtIntervalSample> * ); 94 void setBrush( const QBrush& ); 95 const QBrush& brush() const; 96 97 void setSamples( const QVector< QwtIntervalSample >& ); 98 void setSamples( QwtSeriesData< QwtIntervalSample >* ); 94 99 95 100 void setBaseline( double ); … … 99 104 HistogramStyle style() const; 100 105 101 void setSymbol( const QwtColumnSymbol * );102 const QwtColumnSymbol *symbol() const;106 void setSymbol( const QwtColumnSymbol* ); 107 const QwtColumnSymbol* symbol() const; 103 108 104 virtual void drawSeries( QPainter *,105 const QwtScaleMap &xMap, const QwtScaleMap&yMap,106 const QRectF &canvasRect, int from, int to ) const;109 virtual void drawSeries( QPainter*, 110 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 111 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 107 112 108 virtual QRectF boundingRect() const; 113 virtual QRectF boundingRect() const QWT_OVERRIDE; 109 114 110 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 115 virtual QwtGraphic legendIcon( 116 int index, const QSizeF& ) const QWT_OVERRIDE; 111 117 112 protected: 113 virtual QwtColumnRect columnRect( const QwtIntervalSample &,114 const QwtScaleMap &, const QwtScaleMap& ) const;118 protected: 119 virtual QwtColumnRect columnRect( const QwtIntervalSample&, 120 const QwtScaleMap&, const QwtScaleMap& ) const; 115 121 116 virtual void drawColumn( QPainter *, const QwtColumnRect&,117 const QwtIntervalSample & ) const;122 virtual void drawColumn( QPainter*, const QwtColumnRect&, 123 const QwtIntervalSample& ) const; 118 124 119 void drawColumns( QPainter *,120 const QwtScaleMap &xMap, const QwtScaleMap&yMap,125 void drawColumns( QPainter*, 126 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 121 127 int from, int to ) const; 122 128 123 void drawOutline( QPainter *,124 const QwtScaleMap &xMap, const QwtScaleMap&yMap,129 void drawOutline( QPainter*, 130 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 125 131 int from, int to ) const; 126 132 127 void drawLines( QPainter *,128 const QwtScaleMap&xMap, const QwtScaleMap&yMap,129 int from, int to ) const;133 void drawLines( QPainter*, 134 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 135 int from, int to ) const; 130 136 131 private: 137 private: 132 138 void init(); 133 void flushPolygon( QPainter *, double baseLine, QPolygonF& ) const;139 void flushPolygon( QPainter*, double baseLine, QPolygonF& ) const; 134 140 135 141 class PrivateData; 136 PrivateData *d_data;142 PrivateData* m_data; 137 143 }; 138 144 -
trunk/BNC/qwt/qwt_plot_intervalcurve.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_clipper.h" 14 14 #include "qwt_painter.h" 15 #include <string.h> 15 #include "qwt_graphic.h" 16 #include "qwt_text.h" 16 17 17 18 #include <qpainter.h> 18 19 static inline bool qwtIsHSampleInside( const QwtIntervalSample &sample, 19 #include <qmath.h> 20 #include <cstring> 21 22 static inline bool qwtIsHSampleInside( const QwtIntervalSample& sample, 20 23 double xMin, double xMax, double yMin, double yMax ) 21 24 { … … 30 33 } 31 34 32 static inline bool qwtIsVSampleInside( const QwtIntervalSample &sample,35 static inline bool qwtIsVSampleInside( const QwtIntervalSample& sample, 33 36 double xMin, double xMax, double yMin, double yMax ) 34 37 { … … 43 46 } 44 47 45 class QwtPlotIntervalCurve::PrivateData 46 { 47 public: 48 PrivateData(): 49 style( QwtPlotIntervalCurve::Tube ), 50 symbol( NULL ), 51 pen( Qt::black ), 52 brush( Qt::white ) 53 { 54 paintAttributes = QwtPlotIntervalCurve::ClipPolygons; 55 paintAttributes |= QwtPlotIntervalCurve::ClipSymbol; 56 57 pen.setCapStyle( Qt::FlatCap ); 58 } 59 60 ~PrivateData() 61 { 62 delete symbol; 63 } 64 65 QwtPlotIntervalCurve::CurveStyle style; 66 const QwtIntervalSymbol *symbol; 67 68 QPen pen; 69 QBrush brush; 70 71 QwtPlotIntervalCurve::PaintAttributes paintAttributes; 72 }; 73 74 /*! 75 Constructor 76 \param title Title of the curve 77 */ 78 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ): 79 QwtPlotSeriesItem( title ) 80 { 81 init(); 82 } 83 84 /*! 85 Constructor 86 \param title Title of the curve 87 */ 88 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ): 89 QwtPlotSeriesItem( QwtText( title ) ) 90 { 91 init(); 92 } 93 94 //! Destructor 95 QwtPlotIntervalCurve::~QwtPlotIntervalCurve() 96 { 97 delete d_data; 98 } 99 100 //! Initialize internal members 101 void QwtPlotIntervalCurve::init() 102 { 103 setItemAttribute( QwtPlotItem::Legend, true ); 104 setItemAttribute( QwtPlotItem::AutoScale, true ); 105 106 d_data = new PrivateData; 107 setData( new QwtIntervalSeriesData() ); 108 109 setZ( 19.0 ); 110 } 111 112 //! \return QwtPlotItem::Rtti_PlotIntervalCurve 113 int QwtPlotIntervalCurve::rtti() const 114 { 115 return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve; 116 } 117 118 /*! 119 Specify an attribute how to draw the curve 120 121 \param attribute Paint attribute 122 \param on On/Off 123 \sa testPaintAttribute() 124 */ 125 void QwtPlotIntervalCurve::setPaintAttribute( 126 PaintAttribute attribute, bool on ) 127 { 128 if ( on ) 129 d_data->paintAttributes |= attribute; 48 static inline int qwtInterpolated( int from, int to, double ratio ) 49 { 50 return qRound( from + ratio * ( to - from ) ); 51 } 52 53 static int qwtStartIndex( int from, double min, double max, 54 const QwtSeriesData< QwtIntervalSample >* samples ) 55 { 56 /* 57 As we know, that the value coordinates are montonically 58 increasing/decreasing we can find the first sample before 59 entering the interval using a binary search algo. 60 */ 61 62 struct lessThan 63 { 64 inline bool operator()( const double value, 65 const QwtIntervalSample& sample ) const 66 { 67 return value < sample.value; 68 } 69 }; 70 71 struct greaterThan 72 { 73 inline bool operator()( const double value, 74 const QwtIntervalSample& sample ) const 75 { 76 return value > sample.value; 77 } 78 }; 79 80 int idx; 81 82 if ( samples->firstSample().value < samples->lastSample().value ) 83 { 84 idx = qwtUpperSampleIndex< QwtIntervalSample >( 85 *samples, min, lessThan() ); 86 } 130 87 else 131 d_data->paintAttributes &= ~attribute; 132 } 133 134 /*! 135 \return True, when attribute is enabled 136 \sa PaintAttribute, setPaintAttribute() 137 */ 138 bool QwtPlotIntervalCurve::testPaintAttribute( 139 PaintAttribute attribute ) const 140 { 141 return ( d_data->paintAttributes & attribute ); 142 } 143 144 /*! 145 Initialize data with an array of samples. 146 \param samples Vector of samples 147 */ 148 void QwtPlotIntervalCurve::setSamples( 149 const QVector<QwtIntervalSample> &samples ) 150 { 151 setData( new QwtIntervalSeriesData( samples ) ); 152 } 153 154 /*! 155 Assign a series of samples 156 157 setSamples() is just a wrapper for setData() without any additional 158 value - beside that it is easier to find for the developer. 159 160 \param data Data 161 \warning The item takes ownership of the data object, deleting 162 it when its not used anymore. 163 */ 164 void QwtPlotIntervalCurve::setSamples( 165 QwtSeriesData<QwtIntervalSample> *data ) 166 { 167 setData( data ); 168 } 169 170 /*! 171 Set the curve's drawing style 172 173 \param style Curve style 174 \sa CurveStyle, style() 175 */ 176 void QwtPlotIntervalCurve::setStyle( CurveStyle style ) 177 { 178 if ( style != d_data->style ) 179 { 180 d_data->style = style; 181 182 legendChanged(); 183 itemChanged(); 184 } 185 } 186 187 /*! 188 \return Style of the curve 189 \sa setStyle() 190 */ 191 QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const 192 { 193 return d_data->style; 194 } 195 196 /*! 197 Assign a symbol. 198 199 \param symbol Symbol 200 \sa symbol() 201 */ 202 void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol *symbol ) 203 { 204 if ( symbol != d_data->symbol ) 205 { 206 delete d_data->symbol; 207 d_data->symbol = symbol; 208 209 legendChanged(); 210 itemChanged(); 211 } 212 } 213 214 /*! 215 \return Current symbol or NULL, when no symbol has been assigned 216 \sa setSymbol() 217 */ 218 const QwtIntervalSymbol *QwtPlotIntervalCurve::symbol() const 219 { 220 return d_data->symbol; 221 } 222 223 /*! 224 Build and assign a pen 225 226 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 227 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 228 to hide this incompatibility. 229 230 \param color Pen color 231 \param width Pen width 232 \param style Pen style 233 234 \sa pen(), brush() 235 */ 236 void QwtPlotIntervalCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style ) 237 { 238 setPen( QPen( color, width, style ) ); 239 } 240 241 /*! 242 \brief Assign a pen 243 \param pen New pen 244 \sa pen(), brush() 245 */ 246 void QwtPlotIntervalCurve::setPen( const QPen &pen ) 247 { 248 if ( pen != d_data->pen ) 249 { 250 d_data->pen = pen; 251 252 legendChanged(); 253 itemChanged(); 254 } 255 } 256 257 /*! 258 \return Pen used to draw the lines 259 \sa setPen(), brush() 260 */ 261 const QPen& QwtPlotIntervalCurve::pen() const 262 { 263 return d_data->pen; 264 } 265 266 /*! 267 Assign a brush. 268 269 The brush is used to fill the area in Tube style(). 270 271 \param brush Brush 272 \sa brush(), pen(), setStyle(), CurveStyle 273 */ 274 void QwtPlotIntervalCurve::setBrush( const QBrush &brush ) 275 { 276 if ( brush != d_data->brush ) 277 { 278 d_data->brush = brush; 279 280 legendChanged(); 281 itemChanged(); 282 } 283 } 284 285 /*! 286 \return Brush used to fill the area in Tube style() 287 \sa setBrush(), setStyle(), CurveStyle 288 */ 289 const QBrush& QwtPlotIntervalCurve::brush() const 290 { 291 return d_data->brush; 292 } 293 294 /*! 295 \return Bounding rectangle of all samples. 296 For an empty series the rectangle is invalid. 297 */ 298 QRectF QwtPlotIntervalCurve::boundingRect() const 299 { 300 QRectF rect = QwtPlotSeriesItem::boundingRect(); 301 if ( orientation() == Qt::Vertical ) 302 rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() ); 303 304 return rect; 305 } 306 307 /*! 308 Draw a subset of the samples 309 310 \param painter Painter 311 \param xMap Maps x-values into pixel coordinates. 312 \param yMap Maps y-values into pixel coordinates. 313 \param canvasRect Contents rectangle of the canvas 314 \param from Index of the first sample to be painted 315 \param to Index of the last sample to be painted. If to < 0 the 316 series will be painted to its last sample. 317 318 \sa drawTube(), drawSymbols() 319 */ 320 void QwtPlotIntervalCurve::drawSeries( QPainter *painter, 321 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 322 const QRectF &canvasRect, int from, int to ) const 323 { 324 if ( to < 0 ) 325 to = dataSize() - 1; 326 327 if ( from < 0 ) 328 from = 0; 329 330 if ( from > to ) 331 return; 332 333 switch ( d_data->style ) 334 { 335 case Tube: 336 drawTube( painter, xMap, yMap, canvasRect, from, to ); 337 break; 338 339 case NoCurve: 340 default: 341 break; 342 } 343 344 if ( d_data->symbol && 345 ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) 346 { 347 drawSymbols( painter, *d_data->symbol, 348 xMap, yMap, canvasRect, from, to ); 349 } 350 } 351 352 /*! 353 Draw a tube 354 355 Builds 2 curves from the upper and lower limits of the intervals 356 and draws them with the pen(). The area between the curves is 357 filled with the brush(). 358 359 \param painter Painter 360 \param xMap Maps x-values into pixel coordinates. 361 \param yMap Maps y-values into pixel coordinates. 362 \param canvasRect Contents rectangle of the canvas 363 \param from Index of the first sample to be painted 364 \param to Index of the last sample to be painted. If to < 0 the 365 series will be painted to its last sample. 366 367 \sa drawSeries(), drawSymbols() 368 */ 369 void QwtPlotIntervalCurve::drawTube( QPainter *painter, 370 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 371 const QRectF &canvasRect, int from, int to ) const 88 { 89 idx = qwtUpperSampleIndex< QwtIntervalSample >( 90 *samples, max, greaterThan() ); 91 } 92 93 if ( idx >= 0 ) 94 { 95 idx = qMax( from, idx ); 96 if ( idx > 0 ) 97 { 98 // we need to fill the area before the first sample 99 idx--; 100 } 101 } 102 103 return idx; 104 } 105 106 namespace 107 { 108 class LinesRenderer 109 { 110 public: 111 LinesRenderer( Qt::Orientation, 112 const QwtScaleMap&, const QwtScaleMap&, const QRectF& ); 113 114 void addSamples( const QwtSeriesData< QwtIntervalSample >*, int from, int to ); 115 116 QVector< QLine > fillLines; 117 QVector< QLine > borderLines; 118 119 private: 120 bool addSample( const QwtIntervalSample& ); 121 void flush(); 122 123 bool append( int value, int min, int max ); 124 125 void addFillLineAt( int value, int min, int max ); 126 void addFillLines( int value, int min, int max ); 127 128 void addBorderLineAt( int value, int min, int max ); 129 void addBorderLine( int, int, int, int ); 130 131 const bool m_vertical; 132 133 const QwtScaleMap& m_valueMap; 134 const QwtScaleMap& m_intervalMap; 135 136 const bool m_inverting; 137 bool m_pending; 138 139 // all ints are in paint device coordinates 140 141 int m_intvMin, m_intvMax; // interval boundaries of the canvas 142 int m_valueMin, m_valueMax; // value boundaries of the canvas 143 144 int m_value; // value of the last sample being processed 145 146 struct 147 { 148 inline void reset( int value ) 149 { 150 min = max = last = value; 151 } 152 153 inline void extend( int value ) 154 { 155 if ( value < min ) 156 min = value; 157 else if ( value > max ) 158 max = value; 159 160 last = value; 161 } 162 163 int min, max, last; 164 165 } m_lower, m_upper; 166 }; 167 168 LinesRenderer::LinesRenderer( Qt::Orientation orientation, 169 const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& rect ) 170 : m_vertical( orientation == Qt::Vertical ) 171 , m_valueMap( m_vertical ? xMap : yMap ) 172 , m_intervalMap( m_vertical ? yMap : xMap ) 173 , m_inverting( m_intervalMap.isInverting() ) 174 , m_pending( false ) 175 , m_value( 0 ) 176 { 177 QRectF r = rect; 178 if ( !m_vertical ) 179 r.setSize( QSizeF( r.height(), r.width() ) ); 180 181 m_intvMin = qFloor( r.top() ); 182 m_intvMax = qCeil( r.bottom() ); 183 184 m_valueMin = qFloor( r.left() ); 185 m_valueMax = qCeil( r.right() ); 186 187 const int steps = m_valueMax - m_valueMin + 1; 188 189 // one line for each pixel 190 fillLines.reserve( steps ); 191 192 /* 193 for both border lines: 194 one line ( min/max ) of the samples lying on the same pixel 195 one line connecting the pixels 196 */ 197 borderLines.reserve( 4 * steps ); 198 } 199 200 void LinesRenderer::addSamples( 201 const QwtSeriesData< QwtIntervalSample >* samples, int from, int to ) 202 { 203 const double v1 = m_valueMap.invTransform( m_valueMin ); 204 const double v2 = m_valueMap.invTransform( m_valueMax ); 205 206 from = qwtStartIndex( from, qMin( v1, v2 ), qMax( v1, v2 ), samples ); 207 208 if ( from >= 0 ) 209 { 210 for ( int i = from; i <= to; i++ ) 211 { 212 if ( addSample( samples->sample( i ) ) ) 213 break; 214 } 215 } 216 217 flush(); 218 } 219 220 inline bool LinesRenderer::addSample( const QwtIntervalSample& sample ) 221 { 222 const double value = qRound( m_valueMap.transform( sample.value ) ); 223 224 const int min = qRound( m_intervalMap.transform( sample.interval.minValue() ) ); 225 const int max = qRound( m_intervalMap.transform( sample.interval.maxValue() ) ); 226 227 return m_inverting ? append( value, max, min ) : append( value, max, min ); 228 } 229 230 inline bool LinesRenderer::append( 231 const int value, const int lower, const int upper ) 232 { 233 if ( !m_pending ) 234 { 235 m_value = value; 236 m_lower.reset( lower ); 237 m_upper.reset( upper ); 238 239 m_pending = true; 240 241 return false; 242 } 243 244 if ( value != m_value ) 245 { 246 addFillLines( value, lower, upper ); 247 addBorderLineAt( m_value, m_lower.min, m_lower.max ); 248 addBorderLineAt( m_value, m_upper.min, m_upper.max ); 249 250 addBorderLine( m_value, m_lower.last, value, lower ); 251 addBorderLine( m_value, m_upper.last, value, upper ); 252 253 if ( ( value > m_value ) ? ( value > m_valueMax ) : ( value < m_valueMin ) ) 254 { 255 m_pending = false; 256 return true; 257 } 258 259 m_value = value; 260 261 m_lower.reset( lower ); 262 m_upper.reset( upper ); 263 } 264 else 265 { 266 m_lower.extend( lower ); 267 m_upper.extend( upper ); 268 } 269 270 return false; 271 } 272 273 inline void LinesRenderer::flush() 274 { 275 if ( m_pending ) 276 { 277 addFillLineAt( m_value, m_lower.min, m_upper.max ); 278 addBorderLineAt( m_value, m_lower.min, m_lower.max ); 279 addBorderLineAt( m_value, m_upper.min, m_upper.max ); 280 } 281 } 282 283 inline void LinesRenderer::addFillLines( 284 const int value, const int lower, const int upper ) 285 { 286 addFillLineAt( m_value, m_lower.min, m_upper.max ); 287 288 const double delta = value - m_value; 289 290 if ( value > m_value ) 291 { 292 for ( int v = m_value + 1; v < value; v++ ) 293 { 294 const double ratio = ( v - m_value ) / delta; 295 296 addFillLineAt( v, 297 qwtInterpolated( m_lower.last, lower, ratio ), 298 qwtInterpolated( m_upper.last, upper, ratio ) ); 299 } 300 } 301 else 302 { 303 for ( int v = m_value - 1; v > value; v-- ) 304 { 305 const double ratio = ( v - m_value ) / delta; 306 307 addFillLineAt( v, 308 qwtInterpolated( m_lower.last, lower, ratio ), 309 qwtInterpolated( m_upper.last, upper, ratio ) ); 310 } 311 } 312 } 313 314 inline void LinesRenderer::addFillLineAt( int value, int min, int max ) 315 { 316 if ( ( min != max ) && ( max > m_intvMin ) && ( min < m_intvMax ) ) 317 { 318 min = qMax( min, m_intvMin ); 319 max = qMin( max, m_intvMax ); 320 321 if( m_vertical ) 322 fillLines += QLine( value, min, value, max ); 323 else 324 fillLines += QLine( min, value, max, value ); 325 } 326 } 327 328 inline void LinesRenderer::addBorderLineAt( int value, int min, int max ) 329 { 330 if ( min != max ) 331 addBorderLine( value, min, value, max ); 332 } 333 334 inline void LinesRenderer::addBorderLine( int x1, int y1, int x2, int y2 ) 335 { 336 if( m_vertical ) 337 borderLines += QLine( x1, y1, x2, y2 ); 338 else 339 borderLines += QLine( y1, x1, y2, x2 ); 340 } 341 } 342 343 static void qwtDrawTubeLines( 344 const QwtPlotIntervalCurve* curve, QPainter* painter, 345 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 346 const QRectF& canvasRect, int from, int to) 347 { 348 LinesRenderer renderer( curve->orientation(), xMap, yMap, canvasRect ); 349 renderer.addSamples( curve->data(), from, to ); 350 351 if ( curve->brush().style() != Qt::NoBrush ) 352 { 353 painter->save(); 354 355 painter->setPen( curve->brush().color() ); 356 painter->setRenderHint( QPainter::Antialiasing, false ); 357 painter->drawLines( renderer.fillLines ); 358 359 painter->restore(); 360 } 361 362 if ( curve->pen().style() != Qt::NoPen ) 363 { 364 painter->save(); 365 366 painter->setPen( curve->pen() ); 367 painter->drawLines( renderer.borderLines ); 368 369 painter->restore(); 370 } 371 } 372 373 static void qwtDrawTube( 374 const QwtPlotIntervalCurve* curve, QPainter* painter, 375 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 376 const QRectF& canvasRect, int from, int to ) 372 377 { 373 378 const bool doAlign = QwtPainter::roundingAlignment( painter ); … … 377 382 const size_t size = to - from + 1; 378 383 QPolygonF polygon( 2 * size ); 379 QPointF *points = polygon.data();384 QPointF* points = polygon.data(); 380 385 381 386 for ( uint i = 0; i < size; i++ ) 382 387 { 383 QPointF &minValue = points[i];384 QPointF &maxValue = points[2 * size - 1 - i];385 386 const QwtIntervalSample intervalSample = sample( from + i ); 387 if ( orientation() == Qt::Vertical ) 388 QPointF& minValue = points[i]; 389 QPointF& maxValue = points[2 * size - 1 - i]; 390 391 const QwtIntervalSample intervalSample = curve->sample( from + i ); 392 if ( curve->orientation() == Qt::Vertical ) 388 393 { 389 394 double x = xMap.transform( intervalSample.value ); 390 395 double y1 = yMap.transform( intervalSample.interval.minValue() ); 391 396 double y2 = yMap.transform( intervalSample.interval.maxValue() ); 397 392 398 if ( doAlign ) 393 399 { … … 407 413 double x1 = xMap.transform( intervalSample.interval.minValue() ); 408 414 double x2 = xMap.transform( intervalSample.interval.maxValue() ); 415 409 416 if ( doAlign ) 410 417 { … … 421 428 } 422 429 423 if ( d_data->brush.style() != Qt::NoBrush ) 430 const bool doClip = curve->testPaintAttribute( QwtPlotIntervalCurve::ClipPolygons ); 431 432 if ( curve->brush().style() != Qt::NoBrush ) 424 433 { 425 434 painter->setPen( QPen( Qt::NoPen ) ); 426 painter->setBrush( d_data->brush );427 428 if ( d _data->paintAttributes & ClipPolygons)435 painter->setBrush( curve->brush() ); 436 437 if ( doClip ) 429 438 { 430 439 const qreal m = 1.0; 431 const QPolygonF p = QwtClipper::clipPolygonF( 432 canvasRect.adjusted( -m, -m, m, m ), polygon, true ); 440 const QPolygonF p = QwtClipper::clippedPolygonF( 441 canvasRect.adjusted( -m, -m, m, m ), polygon, true ); 433 442 434 443 QwtPainter::drawPolygon( painter, p ); … … 440 449 } 441 450 442 if ( d_data->pen.style() != Qt::NoPen )443 { 444 painter->setPen( d_data->pen);451 if ( curve->pen().style() != Qt::NoPen ) 452 { 453 painter->setPen( curve->pen() ); 445 454 painter->setBrush( Qt::NoBrush ); 446 455 447 if ( d _data->paintAttributes & ClipPolygons)448 { 449 qreal pw = qMax( qreal( 1.0 ),painter->pen().widthF() );456 if ( doClip ) 457 { 458 qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); 450 459 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 451 460 452 QPolygonF p; 453 454 p.resize( size ); 455 ::memcpy( p.data(), points, size * sizeof( QPointF ) ); 456 p = QwtClipper::clipPolygonF( clipRect, p ); 457 QwtPainter::drawPolyline( painter, p ); 458 459 p.resize( size ); 460 ::memcpy( p.data(), points + size, size * sizeof( QPointF ) ); 461 p = QwtClipper::clipPolygonF( clipRect, p ); 462 QwtPainter::drawPolyline( painter, p ); 461 QPolygonF p( size ); 462 463 std::memcpy( p.data(), points, size * sizeof( QPointF ) ); 464 QwtPainter::drawPolyline( painter, 465 QwtClipper::clippedPolygonF( clipRect, p ) ); 466 467 std::memcpy( p.data(), points + size, size * sizeof( QPointF ) ); 468 QwtPainter::drawPolyline( painter, 469 QwtClipper::clippedPolygonF( clipRect, p ) ); 463 470 } 464 471 else … … 472 479 } 473 480 474 /*! 475 Draw symbols for a subset of the samples 476 477 \param painter Painter 478 \param symbol Interval symbol 479 \param xMap x map 480 \param yMap y map 481 \param canvasRect Contents rectangle of the canvas 482 \param from Index of the first sample to be painted 483 \param to Index of the last sample to be painted 484 485 \sa setSymbol(), drawSeries(), drawTube() 486 */ 481 class QwtPlotIntervalCurve::PrivateData 482 { 483 public: 484 PrivateData(): 485 style( QwtPlotIntervalCurve::Tube ), 486 symbol( NULL ), 487 pen( Qt::black ), 488 brush( Qt::white ) 489 { 490 paintAttributes = QwtPlotIntervalCurve::ClipPolygons; 491 paintAttributes |= QwtPlotIntervalCurve::ClipSymbol; 492 493 pen.setCapStyle( Qt::FlatCap ); 494 } 495 496 ~PrivateData() 497 { 498 delete symbol; 499 } 500 501 QwtPlotIntervalCurve::CurveStyle style; 502 const QwtIntervalSymbol* symbol; 503 504 QPen pen; 505 QBrush brush; 506 507 QwtPlotIntervalCurve::PaintAttributes paintAttributes; 508 }; 509 510 /*! 511 Constructor 512 \param title Title of the curve 513 */ 514 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText& title ) 515 : QwtPlotSeriesItem( title ) 516 { 517 init(); 518 } 519 520 /*! 521 Constructor 522 \param title Title of the curve 523 */ 524 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString& title ) 525 : QwtPlotSeriesItem( QwtText( title ) ) 526 { 527 init(); 528 } 529 530 //! Destructor 531 QwtPlotIntervalCurve::~QwtPlotIntervalCurve() 532 { 533 delete m_data; 534 } 535 536 //! Initialize internal members 537 void QwtPlotIntervalCurve::init() 538 { 539 setItemAttribute( QwtPlotItem::Legend, true ); 540 setItemAttribute( QwtPlotItem::AutoScale, true ); 541 542 m_data = new PrivateData; 543 setData( new QwtIntervalSeriesData() ); 544 545 setZ( 19.0 ); 546 } 547 548 //! \return QwtPlotItem::Rtti_PlotIntervalCurve 549 int QwtPlotIntervalCurve::rtti() const 550 { 551 return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve; 552 } 553 554 /*! 555 Specify an attribute how to draw the curve 556 557 \param attribute Paint attribute 558 \param on On/Off 559 \sa testPaintAttribute() 560 */ 561 void QwtPlotIntervalCurve::setPaintAttribute( 562 PaintAttribute attribute, bool on ) 563 { 564 if ( on ) 565 m_data->paintAttributes |= attribute; 566 else 567 m_data->paintAttributes &= ~attribute; 568 } 569 570 /*! 571 \return True, when attribute is enabled 572 \sa PaintAttribute, setPaintAttribute() 573 */ 574 bool QwtPlotIntervalCurve::testPaintAttribute( 575 PaintAttribute attribute ) const 576 { 577 return ( m_data->paintAttributes & attribute ); 578 } 579 580 /*! 581 Initialize data with an array of samples. 582 \param samples Vector of samples 583 */ 584 void QwtPlotIntervalCurve::setSamples( 585 const QVector< QwtIntervalSample >& samples ) 586 { 587 setData( new QwtIntervalSeriesData( samples ) ); 588 } 589 590 /*! 591 Assign a series of samples 592 593 setSamples() is just a wrapper for setData() without any additional 594 value - beside that it is easier to find for the developer. 595 596 \param data Data 597 \warning The item takes ownership of the data object, deleting 598 it when its not used anymore. 599 */ 600 void QwtPlotIntervalCurve::setSamples( 601 QwtSeriesData< QwtIntervalSample >* data ) 602 { 603 setData( data ); 604 } 605 606 /*! 607 Set the curve's drawing style 608 609 \param style Curve style 610 \sa CurveStyle, style() 611 */ 612 void QwtPlotIntervalCurve::setStyle( CurveStyle style ) 613 { 614 if ( style != m_data->style ) 615 { 616 m_data->style = style; 617 618 legendChanged(); 619 itemChanged(); 620 } 621 } 622 623 /*! 624 \return Style of the curve 625 \sa setStyle() 626 */ 627 QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const 628 { 629 return m_data->style; 630 } 631 632 /*! 633 Assign a symbol. 634 635 \param symbol Symbol 636 \sa symbol() 637 */ 638 void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol* symbol ) 639 { 640 if ( symbol != m_data->symbol ) 641 { 642 delete m_data->symbol; 643 m_data->symbol = symbol; 644 645 legendChanged(); 646 itemChanged(); 647 } 648 } 649 650 /*! 651 \return Current symbol or NULL, when no symbol has been assigned 652 \sa setSymbol() 653 */ 654 const QwtIntervalSymbol* QwtPlotIntervalCurve::symbol() const 655 { 656 return m_data->symbol; 657 } 658 659 /*! 660 Build and assign a pen 661 662 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 663 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 664 to hide this incompatibility. 665 666 \param color Pen color 667 \param width Pen width 668 \param style Pen style 669 670 \sa pen(), brush() 671 */ 672 void QwtPlotIntervalCurve::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 673 { 674 setPen( QPen( color, width, style ) ); 675 } 676 677 /*! 678 \brief Assign a pen 679 \param pen New pen 680 \sa pen(), brush() 681 */ 682 void QwtPlotIntervalCurve::setPen( const QPen& pen ) 683 { 684 if ( pen != m_data->pen ) 685 { 686 m_data->pen = pen; 687 688 legendChanged(); 689 itemChanged(); 690 } 691 } 692 693 /*! 694 \return Pen used to draw the lines 695 \sa setPen(), brush() 696 */ 697 const QPen& QwtPlotIntervalCurve::pen() const 698 { 699 return m_data->pen; 700 } 701 702 /*! 703 Assign a brush. 704 705 The brush is used to fill the area in Tube style(). 706 707 \param brush Brush 708 \sa brush(), pen(), setStyle(), CurveStyle 709 */ 710 void QwtPlotIntervalCurve::setBrush( const QBrush& brush ) 711 { 712 if ( brush != m_data->brush ) 713 { 714 m_data->brush = brush; 715 716 legendChanged(); 717 itemChanged(); 718 } 719 } 720 721 /*! 722 \return Brush used to fill the area in Tube style() 723 \sa setBrush(), setStyle(), CurveStyle 724 */ 725 const QBrush& QwtPlotIntervalCurve::brush() const 726 { 727 return m_data->brush; 728 } 729 730 /*! 731 \return Bounding rectangle of all samples. 732 For an empty series the rectangle is invalid. 733 */ 734 QRectF QwtPlotIntervalCurve::boundingRect() const 735 { 736 QRectF rect = QwtPlotSeriesItem::boundingRect(); 737 if ( orientation() == Qt::Vertical ) 738 rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() ); 739 740 return rect; 741 } 742 743 /*! 744 Draw a subset of the samples 745 746 \param painter Painter 747 \param xMap Maps x-values into pixel coordinates. 748 \param yMap Maps y-values into pixel coordinates. 749 \param canvasRect Contents rectangle of the canvas 750 \param from Index of the first sample to be painted 751 \param to Index of the last sample to be painted. If to < 0 the 752 series will be painted to its last sample. 753 754 \sa drawTube(), drawSymbols() 755 */ 756 void QwtPlotIntervalCurve::drawSeries( QPainter* painter, 757 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 758 const QRectF& canvasRect, int from, int to ) const 759 { 760 if ( to < 0 ) 761 to = dataSize() - 1; 762 763 if ( from < 0 ) 764 from = 0; 765 766 if ( from > to ) 767 return; 768 769 if ( m_data->style == Tube ) 770 drawTube( painter, xMap, yMap, canvasRect, from, to ); 771 772 if ( m_data->symbol && 773 ( m_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) 774 { 775 drawSymbols( painter, *m_data->symbol, 776 xMap, yMap, canvasRect, from, to ); 777 } 778 } 779 780 /*! 781 Draw a tube 782 783 Builds 2 curves from the upper and lower limits of the intervals 784 and draws them with the pen(). The area between the curves is 785 filled with the brush(). 786 787 \param painter Painter 788 \param xMap Maps x-values into pixel coordinates. 789 \param yMap Maps y-values into pixel coordinates. 790 \param canvasRect Contents rectangle of the canvas 791 \param from Index of the first sample to be painted 792 \param to Index of the last sample to be painted. If to < 0 the 793 series will be painted to its last sample. 794 795 \sa drawSeries(), drawSymbols() 796 */ 797 void QwtPlotIntervalCurve::drawTube( 798 QPainter* painter, const QwtScaleMap& xMap, 799 const QwtScaleMap& yMap, const QRectF& canvasRect, int from, int to) const 800 { 801 if ( ( m_data->pen.style() == Qt::NoPen ) && 802 ( m_data->brush.style() == Qt::NoBrush ) ) 803 { 804 return; 805 } 806 807 const bool useLines = testPaintAttribute( TubeAsLines ) 808 && QwtPainter::roundingAlignment( painter ); 809 810 if ( useLines ) 811 qwtDrawTubeLines( this, painter, xMap, yMap, canvasRect, from, to ); 812 else 813 qwtDrawTube( this, painter, xMap, yMap, canvasRect, from, to ); 814 } 815 816 /*! 817 Draw symbols for a subset of the samples 818 819 \param painter Painter 820 \param symbol Interval symbol 821 \param xMap x map 822 \param yMap y map 823 \param canvasRect Contents rectangle of the canvas 824 \param from Index of the first sample to be painted 825 \param to Index of the last sample to be painted 826 827 \sa setSymbol(), drawSeries(), drawTube() 828 */ 487 829 void QwtPlotIntervalCurve::drawSymbols( 488 QPainter *painter, const QwtIntervalSymbol&symbol,489 const QwtScaleMap &xMap, const QwtScaleMap&yMap,490 const QRectF &canvasRect, int from, int to ) const830 QPainter* painter, const QwtIntervalSymbol& symbol, 831 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 832 const QRectF& canvasRect, int from, int to ) const 491 833 { 492 834 painter->save(); … … 505 847 const double yMax = tr.bottom(); 506 848 507 const bool doClip = d_data->paintAttributes & ClipSymbol;849 const bool doClip = m_data->paintAttributes & ClipSymbol; 508 850 509 851 for ( int i = from; i <= to; i++ ) … … 541 883 542 884 /*! 543 \return Icon for the legend 544 545 In case of Tube style() the icon is a plain rectangle filled with the brush(). 546 If a symbol is assigned it is scaled to size. 547 548 \param index Index of the legend entry 885 \return Icon for the legend 886 887 In case of Tube style() the icon is a plain rectangle filled with the brush(). 888 If a symbol is assigned it is scaled to size. 889 890 \param index Index of the legend entry 549 891 ( ignored as there is only one ) 550 \param size Icon size 551 552 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 553 */ 892 \param size Icon size 893 894 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 895 */ 554 896 QwtGraphic QwtPlotIntervalCurve::legendIcon( 555 int index, const QSizeF &size ) const897 int index, const QSizeF& size ) const 556 898 { 557 899 Q_UNUSED( index ); … … 568 910 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 569 911 570 if ( d_data->style == Tube )912 if ( m_data->style == Tube ) 571 913 { 572 914 QRectF r( 0, 0, size.width(), size.height() ); 573 painter.fillRect( r, d_data->brush );574 } 575 576 if ( d_data->symbol &&577 ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )578 { 579 QPen pen = d_data->symbol->pen();915 painter.fillRect( r, m_data->brush ); 916 } 917 918 if ( m_data->symbol && 919 ( m_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) 920 { 921 QPen pen = m_data->symbol->pen(); 580 922 pen.setWidthF( pen.widthF() ); 581 923 pen.setCapStyle( Qt::FlatCap ); 582 924 583 925 painter.setPen( pen ); 584 painter.setBrush( d_data->symbol->brush() );926 painter.setBrush( m_data->symbol->brush() ); 585 927 586 928 if ( orientation() == Qt::Vertical ) … … 588 930 const double x = 0.5 * size.width(); 589 931 590 d_data->symbol->draw( &painter, orientation(),932 m_data->symbol->draw( &painter, orientation(), 591 933 QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) ); 592 934 } … … 595 937 const double y = 0.5 * size.height(); 596 938 597 d_data->symbol->draw( &painter, orientation(),939 m_data->symbol->draw( &painter, orientation(), 598 940 QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) ); 599 941 } -
trunk/BNC/qwt/qwt_plot_intervalcurve.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_seriesitem.h" 15 #include "qwt_series_data.h"16 15 17 16 class QwtIntervalSymbol; 17 template< typename T > class QwtSeriesData; 18 18 19 19 /*! 20 \brief QwtPlotIntervalCurve represents a series of samples, where each value 20 \brief QwtPlotIntervalCurve represents a series of samples, where each value 21 21 is associated with an interval ( \f$[y1,y2] = f(x)\f$ ). 22 22 23 The representation depends on the style() and an optional symbol() 24 that is displayed for each interval. QwtPlotIntervalCurve might be used 25 to display error bars or the area between 2 curves. 26 */ 27 class QWT_EXPORT QwtPlotIntervalCurve: 28 public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample> 23 The representation depends on the style() and an optional symbol() 24 that is displayed for each interval. QwtPlotIntervalCurve might be used 25 to display error bars or the area between 2 curves. 26 */ 27 class QWT_EXPORT QwtPlotIntervalCurve 28 : public QwtPlotSeriesItem 29 , public QwtSeriesStore< QwtIntervalSample > 29 30 { 30 public: 31 public: 31 32 /*! 32 33 \brief Curve styles. … … 34 35 35 36 \sa setStyle(), style() 36 */ 37 */ 37 38 enum CurveStyle 38 39 { … … 60 61 Attributes to modify the drawing algorithm. 61 62 \sa setPaintAttribute(), testPaintAttribute() 62 */ 63 */ 63 64 enum PaintAttribute 64 65 { 65 66 /*! 66 Clip polygons before painting them. In situations, where points 67 are far outside the visible area (f.e when zooming deep) this 68 might be a substantial improvement for the painting performance. 67 Clip polygons before painting them. In situations, where points 68 are far outside the visible area (f.e when zooming deep) this 69 might be a substantial improvement for the painting performance. 69 70 */ 70 71 ClipPolygons = 0x01, 71 72 72 73 //! Check if a symbol is on the plot canvas before painting it. 73 ClipSymbol = 0x02 74 ClipSymbol = 0x02, 75 76 /*! 77 Fill the tube with horizontal or vertical lines and unite 78 overlapping border lines. This attribute is useful for large 79 data sets, where consecutive samples are often mapped to the same 80 coordinate. 81 82 Beside other minor visual differences the filling is always 83 monochrome - using brush().color(). 84 85 This algorithm is very fast and effective and can be used inside 86 a replot cycle. In the worst case the number of lines to be rendered 87 will be 5 times the ( width/height - depending on the orientation() ) 88 of the plot canvas. 89 90 \note Has only an effect, when drawing to a paint device 91 in integer coordinates ( f.e. all widgets on screen ). 92 93 \sa QwtPlotCurve::FilterPointsAggressive 94 */ 95 TubeAsLines = 0x10 74 96 }; 75 97 76 //! Paint attributes 77 typedef QFlags<PaintAttribute> PaintAttributes; 98 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 78 99 79 explicit QwtPlotIntervalCurve( const QString &title = QString() );80 explicit QwtPlotIntervalCurve( const QwtText &title );100 explicit QwtPlotIntervalCurve( const QString& title = QString() ); 101 explicit QwtPlotIntervalCurve( const QwtText& title ); 81 102 82 103 virtual ~QwtPlotIntervalCurve(); 83 104 84 virtual int rtti() const; 105 virtual int rtti() const QWT_OVERRIDE; 85 106 86 107 void setPaintAttribute( PaintAttribute, bool on = true ); 87 108 bool testPaintAttribute( PaintAttribute ) const; 88 109 89 void setSamples( const QVector<QwtIntervalSample >& );90 void setSamples( QwtSeriesData<QwtIntervalSample >* );110 void setSamples( const QVector< QwtIntervalSample >& ); 111 void setSamples( QwtSeriesData< QwtIntervalSample >* ); 91 112 92 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 93 void setPen( const QPen & ); 94 const QPen &pen() const; 113 void setPen( const QColor&, 114 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 95 115 96 void setBrush( const QBrush & ); 97 const QBrush &brush() const; 116 void setPen( const QPen& ); 117 const QPen& pen() const; 118 119 void setBrush( const QBrush& ); 120 const QBrush& brush() const; 98 121 99 122 void setStyle( CurveStyle style ); 100 123 CurveStyle style() const; 101 124 102 void setSymbol( const QwtIntervalSymbol * );103 const QwtIntervalSymbol *symbol() const;125 void setSymbol( const QwtIntervalSymbol* ); 126 const QwtIntervalSymbol* symbol() const; 104 127 105 virtual void drawSeries( QPainter *,106 const QwtScaleMap &xMap, const QwtScaleMap&yMap,107 const QRectF &canvasRect, int from, int to ) const;128 virtual void drawSeries( QPainter*, 129 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 130 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 108 131 109 virtual QRectF boundingRect() const; 132 virtual QRectF boundingRect() const QWT_OVERRIDE; 110 133 111 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 134 virtual QwtGraphic legendIcon( 135 int index, const QSizeF& ) const QWT_OVERRIDE; 112 136 113 protected: 137 protected: 114 138 115 139 void init(); 116 140 117 virtual void drawTube( QPainter *,118 const QwtScaleMap &xMap, const QwtScaleMap&yMap,119 const QRectF &canvasRect, int from, int to ) const;141 virtual void drawTube( QPainter*, 142 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 143 const QRectF& canvasRect, int from, int to ) const; 120 144 121 virtual void drawSymbols( QPainter *, const QwtIntervalSymbol&,122 const QwtScaleMap &xMap, const QwtScaleMap&yMap,123 const QRectF &canvasRect, int from, int to ) const;145 virtual void drawSymbols( QPainter*, const QwtIntervalSymbol&, 146 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 147 const QRectF& canvasRect, int from, int to ) const; 124 148 125 private: 149 private: 126 150 class PrivateData; 127 PrivateData *d_data;151 PrivateData* m_data; 128 152 }; 129 153 -
trunk/BNC/qwt/qwt_plot_item.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_plot.h" 13 13 #include "qwt_legend_data.h" 14 #include "qwt_scale_ div.h"14 #include "qwt_scale_map.h" 15 15 #include "qwt_graphic.h" 16 16 17 #include <qpainter.h> 17 18 18 19 class QwtPlotItem::PrivateData 19 20 { 20 public: 21 PrivateData(): 22 plot( NULL ), 23 isVisible( true ), 24 attributes( 0 ), 25 interests( 0 ), 26 renderHints( 0 ), 27 renderThreadCount( 1 ), 28 z( 0.0 ), 29 xAxis( QwtPlot::xBottom ), 30 yAxis( QwtPlot::yLeft ), 31 legendIconSize( 8, 8 ) 32 { 33 } 34 35 mutable QwtPlot *plot; 21 public: 22 PrivateData() 23 : plot( NULL ) 24 , isVisible( true ) 25 , renderThreadCount( 1 ) 26 , z( 0.0 ) 27 , xAxisId( QwtAxis::XBottom ) 28 , yAxisId( QwtAxis::YLeft ) 29 , legendIconSize( 8, 8 ) 30 { 31 } 32 33 mutable QwtPlot* plot; 36 34 37 35 bool isVisible; … … 45 43 double z; 46 44 47 int xAxis;48 int yAxis;45 QwtAxisId xAxisId; 46 QwtAxisId yAxisId; 49 47 50 48 QwtText title; … … 54 52 /*! 55 53 Constructor 54 */ 55 QwtPlotItem::QwtPlotItem() 56 { 57 m_data = new PrivateData; 58 } 59 60 /*! 61 Constructor 56 62 \param title Title of the item 57 */ 58 QwtPlotItem::QwtPlotItem( const QwtText &title ) 59 { 60 d_data = new PrivateData; 61 d_data->title = title; 63 */ 64 QwtPlotItem::QwtPlotItem( const QString& title ) 65 { 66 m_data = new PrivateData; 67 m_data->title = title; 68 } 69 70 /*! 71 Constructor 72 \param title Title of the item 73 */ 74 QwtPlotItem::QwtPlotItem( const QwtText& title ) 75 { 76 m_data = new PrivateData; 77 m_data->title = title; 62 78 } 63 79 … … 66 82 { 67 83 attach( NULL ); 68 delete d_data;69 } 70 71 /*! 72 \brief Attach the item to a plot. 73 74 This method will attach a QwtPlotItem to the QwtPlot argument. It will first 75 detach the QwtPlotItem from any plot from a previous call to attach (if 76 necessary). If a NULL argument is passed, it will detach from any QwtPlot it 77 was attached to. 78 79 \param plot Plot widget 80 \sa detach() 81 */ 82 void QwtPlotItem::attach( QwtPlot *plot )83 { 84 if ( plot == d_data->plot )84 delete m_data; 85 } 86 87 /*! 88 \brief Attach the item to a plot. 89 90 This method will attach a QwtPlotItem to the QwtPlot argument. It will first 91 detach the QwtPlotItem from any plot from a previous call to attach (if 92 necessary). If a NULL argument is passed, it will detach from any QwtPlot it 93 was attached to. 94 95 \param plot Plot widget 96 \sa detach() 97 */ 98 void QwtPlotItem::attach( QwtPlot* plot ) 99 { 100 if ( plot == m_data->plot ) 85 101 return; 86 102 87 if ( d_data->plot )88 d_data->plot->attachItem( this, false );89 90 d_data->plot = plot;91 92 if ( d_data->plot )93 d_data->plot->attachItem( this, true );103 if ( m_data->plot ) 104 m_data->plot->attachItem( this, false ); 105 106 m_data->plot = plot; 107 108 if ( m_data->plot ) 109 m_data->plot->attachItem( this, true ); 94 110 } 95 111 … … 100 116 detach() is equivalent to calling attach( NULL ) 101 117 \sa attach() 102 */ 118 */ 103 119 void QwtPlotItem::detach() 104 120 { … … 117 133 \return rtti value 118 134 \sa RttiValues 119 */ 135 */ 120 136 int QwtPlotItem::rtti() const 121 137 { … … 124 140 125 141 //! Return attached plot 126 QwtPlot *QwtPlotItem::plot() const127 { 128 return d_data->plot;142 QwtPlot* QwtPlotItem::plot() const 143 { 144 return m_data->plot; 129 145 } 130 146 … … 133 149 134 150 \return setZ(), QwtPlotDict::itemList() 135 */ 151 */ 136 152 double QwtPlotItem::z() const 137 153 { 138 return d_data->z;154 return m_data->z; 139 155 } 140 156 … … 146 162 \param z Z-value 147 163 \sa z(), QwtPlotDict::itemList() 148 */ 164 */ 149 165 void QwtPlotItem::setZ( double z ) 150 166 { 151 if ( d_data->z != z )152 { 153 if ( d_data->plot ) // update the z order154 d_data->plot->attachItem( this, false );155 156 d_data->z = z;157 158 if ( d_data->plot )159 d_data->plot->attachItem( this, true );167 if ( m_data->z != z ) 168 { 169 if ( m_data->plot ) // update the z order 170 m_data->plot->attachItem( this, false ); 171 172 m_data->z = z; 173 174 if ( m_data->plot ) 175 m_data->plot->attachItem( this, true ); 160 176 161 177 itemChanged(); … … 168 184 \param title Title 169 185 \sa title() 170 */ 171 void QwtPlotItem::setTitle( const QString &title )186 */ 187 void QwtPlotItem::setTitle( const QString& title ) 172 188 { 173 189 setTitle( QwtText( title ) ); … … 179 195 \param title Title 180 196 \sa title() 181 */ 182 void QwtPlotItem::setTitle( const QwtText &title )183 { 184 if ( d_data->title != title )185 { 186 d_data->title = title;197 */ 198 void QwtPlotItem::setTitle( const QwtText& title ) 199 { 200 if ( m_data->title != title ) 201 { 202 m_data->title = title; 187 203 188 204 legendChanged(); … … 196 212 \return Title of the item 197 213 \sa setTitle() 198 */ 199 const QwtText &QwtPlotItem::title() const200 { 201 return d_data->title;214 */ 215 const QwtText& QwtPlotItem::title() const 216 { 217 return m_data->title; 202 218 } 203 219 … … 209 225 210 226 \sa testItemAttribute(), ItemInterest 211 */ 227 */ 212 228 void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on ) 213 229 { 214 if ( d_data->attributes.testFlag( attribute ) != on )230 if ( m_data->attributes.testFlag( attribute ) != on ) 215 231 { 216 232 if ( on ) 217 d_data->attributes |= attribute;233 m_data->attributes |= attribute; 218 234 else 219 d_data->attributes &= ~attribute;235 m_data->attributes &= ~attribute; 220 236 221 237 if ( attribute == QwtPlotItem::Legend ) 222 legendChanged(); 238 { 239 if ( on ) 240 { 241 legendChanged(); 242 } 243 else 244 { 245 /* 246 In the special case of taking an item from 247 the legend we can't use legendChanged() as 248 it depends on QwtPlotItem::Legend being enabled 249 */ 250 if ( m_data->plot ) 251 m_data->plot->updateLegend( this ); 252 } 253 } 223 254 224 255 itemChanged(); … … 232 263 \return true/false 233 264 \sa setItemAttribute(), ItemInterest 234 */ 265 */ 235 266 bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const 236 267 { 237 return d_data->attributes.testFlag( attribute );268 return m_data->attributes.testFlag( attribute ); 238 269 } 239 270 … … 245 276 246 277 \sa testItemInterest(), ItemAttribute 247 */ 278 */ 248 279 void QwtPlotItem::setItemInterest( ItemInterest interest, bool on ) 249 280 { 250 if ( d_data->interests.testFlag( interest ) != on )281 if ( m_data->interests.testFlag( interest ) != on ) 251 282 { 252 283 if ( on ) 253 d_data->interests |= interest;284 m_data->interests |= interest; 254 285 else 255 d_data->interests &= ~interest;286 m_data->interests &= ~interest; 256 287 257 288 itemChanged(); … … 265 296 \return true/false 266 297 \sa setItemInterest(), ItemAttribute 267 */ 298 */ 268 299 bool QwtPlotItem::testItemInterest( ItemInterest interest ) const 269 300 { 270 return d_data->interests.testFlag( interest );301 return m_data->interests.testFlag( interest ); 271 302 } 272 303 … … 278 309 279 310 \sa testRenderHint(), RenderHint 280 */ 311 */ 281 312 void QwtPlotItem::setRenderHint( RenderHint hint, bool on ) 282 313 { 283 if ( d_data->renderHints.testFlag( hint ) != on )314 if ( m_data->renderHints.testFlag( hint ) != on ) 284 315 { 285 316 if ( on ) 286 d_data->renderHints |= hint;317 m_data->renderHints |= hint; 287 318 else 288 d_data->renderHints &= ~hint;319 m_data->renderHints &= ~hint; 289 320 290 321 itemChanged(); … … 298 329 \return true/false 299 330 \sa setRenderHint(), RenderHint 300 */ 331 */ 301 332 bool QwtPlotItem::testRenderHint( RenderHint hint ) const 302 333 { 303 return d_data->renderHints.testFlag( hint );334 return m_data->renderHints.testFlag( hint ); 304 335 } 305 336 … … 316 347 317 348 The default thread count is 1 ( = no additional threads ) 318 */ 349 */ 319 350 void QwtPlotItem::setRenderThreadCount( uint numThreads ) 320 351 { 321 d_data->renderThreadCount = numThreads;352 m_data->renderThreadCount = numThreads; 322 353 } 323 354 … … 326 357 If numThreads() is set to 0, the system specific 327 358 ideal thread count is used. 328 */ 359 */ 329 360 uint QwtPlotItem::renderThreadCount() const 330 361 { 331 return d_data->renderThreadCount;362 return m_data->renderThreadCount; 332 363 } 333 364 … … 339 370 \param size Size 340 371 \sa legendIconSize(), legendIcon() 341 */ 342 void QwtPlotItem::setLegendIconSize( const QSize &size )343 { 344 if ( d_data->legendIconSize != size )345 { 346 d_data->legendIconSize = size;372 */ 373 void QwtPlotItem::setLegendIconSize( const QSize& size ) 374 { 375 if ( m_data->legendIconSize != size ) 376 { 377 m_data->legendIconSize = size; 347 378 legendChanged(); 348 379 } … … 352 383 \return Legend icon size 353 384 \sa setLegendIconSize(), legendIcon() 354 */ 385 */ 355 386 QSize QwtPlotItem::legendIconSize() const 356 387 { 357 return d_data->legendIconSize;388 return m_data->legendIconSize; 358 389 } 359 390 … … 370 401 */ 371 402 QwtGraphic QwtPlotItem::legendIcon( 372 int index, const QSizeF &size ) const403 int index, const QSizeF& size ) const 373 404 { 374 405 Q_UNUSED( index ) … … 390 421 */ 391 422 QwtGraphic QwtPlotItem::defaultIcon( 392 const QBrush &brush, const QSizeF&size ) const423 const QBrush& brush, const QSizeF& size ) const 393 424 { 394 425 QwtGraphic icon; … … 423 454 \param on Show if true, otherwise hide 424 455 \sa isVisible(), show(), hide() 425 */ 456 */ 426 457 void QwtPlotItem::setVisible( bool on ) 427 458 { 428 if ( on != d_data->isVisible )429 { 430 d_data->isVisible = on;459 if ( on != m_data->isVisible ) 460 { 461 m_data->isVisible = on; 431 462 itemChanged(); 432 463 } … … 436 467 \return true if visible 437 468 \sa setVisible(), show(), hide() 438 */ 469 */ 439 470 bool QwtPlotItem::isVisible() const 440 471 { 441 return d_data->isVisible;472 return m_data->isVisible; 442 473 } 443 474 … … 447 478 448 479 \sa QwtPlot::legendChanged(), QwtPlot::autoRefresh() 449 */ 480 */ 450 481 void QwtPlotItem::itemChanged() 451 482 { 452 if ( d_data->plot )453 d_data->plot->autoRefresh();483 if ( m_data->plot ) 484 m_data->plot->autoRefresh(); 454 485 } 455 486 … … 457 488 Update the legend of the parent plot. 458 489 \sa QwtPlot::updateLegend(), itemChanged() 459 */ 490 */ 460 491 void QwtPlotItem::legendChanged() 461 492 { 462 if ( testItemAttribute( QwtPlotItem::Legend ) && d_data->plot )463 d_data->plot->updateLegend( this );493 if ( testItemAttribute( QwtPlotItem::Legend ) && m_data->plot ) 494 m_data->plot->updateLegend( this ); 464 495 } 465 496 … … 469 500 The item will painted according to the coordinates of its Axes. 470 501 471 \param xAxis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )472 \param yAxis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )473 474 \sa setXAxis(), setYAxis(), xAxis(), yAxis() , QwtPlot::Axis475 */ 476 void QwtPlotItem::setAxes( int xAxis, int yAxis)477 { 478 if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop)479 d_data->xAxis= xAxis;480 481 if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight)482 d_data->yAxis= yAxis;502 \param xAxisId X Axis 503 \param yAxisId Y Axis 504 505 \sa setXAxis(), setYAxis(), xAxis(), yAxis() 506 */ 507 void QwtPlotItem::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId ) 508 { 509 if ( QwtAxis::isXAxis( xAxisId ) ) 510 m_data->xAxisId = xAxisId; 511 512 if ( QwtAxis::isYAxis( yAxisId ) ) 513 m_data->yAxisId = yAxisId; 483 514 484 515 itemChanged(); … … 490 521 The item will painted according to the coordinates its Axes. 491 522 492 \param axis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )493 \sa setAxes(), setYAxis(), xAxis() , QwtPlot::Axis494 */ 495 void QwtPlotItem::setXAxis( int axis)496 { 497 if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop)498 { 499 d_data->xAxis= axis;523 \param axisId X Axis 524 \sa setAxes(), setYAxis(), xAxis() 525 */ 526 void QwtPlotItem::setXAxis( QwtAxisId axisId ) 527 { 528 if ( QwtAxis::isXAxis( axisId ) ) 529 { 530 m_data->xAxisId = axisId; 500 531 itemChanged(); 501 532 } … … 507 538 The item will painted according to the coordinates its Axes. 508 539 509 \param axis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )510 \sa setAxes(), setXAxis(), yAxis() , QwtPlot::Axis511 */ 512 void QwtPlotItem::setYAxis( int axis)513 { 514 if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight)515 { 516 d_data->yAxis= axis;540 \param axisId Y Axis 541 \sa setAxes(), setXAxis(), yAxis() 542 */ 543 void QwtPlotItem::setYAxis( QwtAxisId axisId ) 544 { 545 if ( QwtAxis::isYAxis( axisId ) ) 546 { 547 m_data->yAxisId = axisId; 517 548 itemChanged(); 518 549 } … … 520 551 521 552 //! Return xAxis 522 intQwtPlotItem::xAxis() const523 { 524 return d_data->xAxis;553 QwtAxisId QwtPlotItem::xAxis() const 554 { 555 return m_data->xAxisId; 525 556 } 526 557 527 558 //! Return yAxis 528 intQwtPlotItem::yAxis() const529 { 530 return d_data->yAxis;559 QwtAxisId QwtPlotItem::yAxis() const 560 { 561 return m_data->yAxisId; 531 562 } 532 563 … … 534 565 \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0) 535 566 \note A width or height < 0.0 is ignored by the autoscaler 536 */ 567 */ 537 568 QRectF QwtPlotItem::boundingRect() const 538 569 { … … 562 593 \sa QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins() 563 594 */ 564 void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap &xMap,565 const QwtScaleMap &yMap, const QRectF&canvasRect,566 double &left, double&top, double&right, double&bottom ) const595 void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap& xMap, 596 const QwtScaleMap& yMap, const QRectF& canvasRect, 597 double& left, double& top, double& right, double& bottom ) const 567 598 { 568 599 Q_UNUSED( xMap ); … … 593 624 \sa title(), legendIcon(), QwtLegend, QwtPlotLegendItem 594 625 */ 595 QList<QwtLegendData> QwtPlotItem::legendData() const 626 QList< QwtLegendData > QwtPlotItem::legendData() const 596 627 { 597 628 QwtLegendData data; … … 600 631 label.setRenderFlags( label.renderFlags() & Qt::AlignLeft ); 601 632 602 QVariant titleValue; 603 qVariantSetValue( titleValue, label ); 604 data.setValue( QwtLegendData::TitleRole, titleValue ); 633 data.setValue( QwtLegendData::TitleRole, 634 QVariant::fromValue( label ) ); 605 635 606 636 const QwtGraphic graphic = legendIcon( 0, legendIconSize() ); 607 637 if ( !graphic.isNull() ) 608 638 { 609 QVariant iconValue; 610 qVariantSetValue( iconValue, graphic ); 611 data.setValue( QwtLegendData::IconRole, iconValue ); 612 } 613 614 QList<QwtLegendData> list; 639 data.setValue( QwtLegendData::IconRole, 640 QVariant::fromValue( graphic ) ); 641 } 642 643 QList< QwtLegendData > list; 615 644 list += data; 616 645 … … 633 662 634 663 \sa QwtPlot::updateAxes(), ScaleInterest 635 */ 636 void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv,637 const QwtScaleDiv &yScaleDiv )664 */ 665 void QwtPlotItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv, 666 const QwtScaleDiv& yScaleDiv ) 638 667 { 639 668 Q_UNUSED( xScaleDiv ); … … 659 688 legendData() and legendIcon() 660 689 */ 661 void QwtPlotItem::updateLegend( const QwtPlotItem *item,662 const QList<QwtLegendData > &data )690 void QwtPlotItem::updateLegend( const QwtPlotItem* item, 691 const QList< QwtLegendData >& data ) 663 692 { 664 693 Q_UNUSED( item ); … … 673 702 674 703 \return Bounding scale rect of the scale maps, not normalized 675 */ 676 QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap,677 const QwtScaleMap &yMap ) const704 */ 705 QRectF QwtPlotItem::scaleRect( const QwtScaleMap& xMap, 706 const QwtScaleMap& yMap ) const 678 707 { 679 708 return QRectF( xMap.s1(), yMap.s1(), … … 688 717 689 718 \return Bounding paint rectangle of the scale maps, not normalized 690 */ 691 QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap,692 const QwtScaleMap &yMap ) const719 */ 720 QRectF QwtPlotItem::paintRect( const QwtScaleMap& xMap, 721 const QwtScaleMap& yMap ) const 693 722 { 694 723 const QRectF rect( xMap.p1(), yMap.p1(), -
trunk/BNC/qwt/qwt_plot_item.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_text.h" 15 #include "qwt_legend_data.h" 16 #include "qwt_graphic.h" 17 #include <qrect.h> 18 #include <qlist.h> 14 #include "qwt_axis_id.h" 19 15 #include <qmetatype.h> 20 16 21 class QPainter;22 17 class QwtScaleMap; 23 18 class QwtScaleDiv; 24 19 class QwtPlot; 20 class QwtText; 21 class QwtGraphic; 22 class QwtLegendData; 23 class QRectF; 24 class QPainter; 25 class QString; 26 template< typename T > class QList; 25 27 26 28 /*! 27 \brief Base class for items on the plot canvas 28 29 A plot item is "something", that can be painted on the plot canvas, 30 or only affects the scales of the plot widget. They can be categorized as: 31 32 - Representator\n 29 \brief Base class for items on the plot canvas 30 31 A plot item is "something", that can be painted on the plot canvas, 32 or only affects the scales of the plot widget. They can be categorized as: 33 34 - Representator\n 33 35 A "Representator" is an item that represents some sort of data 34 36 on the plot canvas. The different representator classes are organized … … 42 44 - ... 43 45 44 - Decorators\n 46 - Decorators\n 45 47 A "Decorator" is an item, that displays additional information, that 46 48 is not related to any data: … … 50 52 - ... 51 53 52 Depending on the QwtPlotItem::ItemAttribute flags, an item is included 53 into autoscaling or has an entry on the legend. 54 55 Before misusing the existing item classes it might be better to 56 implement a new type of plot item 57 ( don't implement a watermark as spectrogram ). 58 Deriving a new type of QwtPlotItem primarily means to implement 59 the YourPlotItem::draw() method. 60 61 \sa The cpuplot example shows the implementation of additional plot items. 62 */ 54 Depending on the QwtPlotItem::ItemAttribute flags, an item is included 55 into autoscaling or has an entry on the legend. 56 57 Before misusing the existing item classes it might be better to 58 implement a new type of plot item 59 ( don't implement a watermark as spectrogram ). 60 Deriving a new type of QwtPlotItem primarily means to implement 61 the YourPlotItem::draw() method. 62 63 \sa The cpuplot example shows the implementation of additional plot items. 64 */ 63 65 64 66 class QWT_EXPORT QwtPlotItem 65 67 { 66 public: 68 public: 67 69 /*! 68 70 \brief Runtime type information … … 103 105 Rtti_PlotSpectrogram, 104 106 105 //! For QwtPlotSvgItem 106 Rtti_Plot SVG,107 //! For QwtPlotGraphicItem, QwtPlotSvgItem 108 Rtti_PlotGraphic, 107 109 108 110 //! For QwtPlotTradingCurve … … 123 125 //! For QwtPlotZoneItem 124 126 Rtti_PlotZone, 127 128 //! For QwtPlotVectorField 129 Rtti_PlotVectorField, 125 130 126 131 /*! … … 160 165 }; 161 166 162 //! Plot Item Attributes 163 typedef QFlags<ItemAttribute> ItemAttributes; 167 Q_DECLARE_FLAGS( ItemAttributes, ItemAttribute ) 164 168 165 169 /*! … … 194 198 }; 195 199 196 //! Plot Item Interests 197 typedef QFlags<ItemInterest> ItemInterests; 200 Q_DECLARE_FLAGS( ItemInterests, ItemInterest ) 198 201 199 202 //! Render hints … … 204 207 }; 205 208 206 //! Render hints 207 typedef QFlags<RenderHint> RenderHints; 208 209 explicit QwtPlotItem( const QwtText &title = QwtText() ); 209 Q_DECLARE_FLAGS( RenderHints, RenderHint ) 210 211 explicit QwtPlotItem(); 212 explicit QwtPlotItem( const QString& title ); 213 explicit QwtPlotItem( const QwtText& title ); 214 210 215 virtual ~QwtPlotItem(); 211 216 212 void attach( QwtPlot *plot );217 void attach( QwtPlot* plot ); 213 218 void detach(); 214 219 215 QwtPlot *plot() const;216 217 void setTitle( const QString &title );218 void setTitle( const QwtText &title );219 const QwtText &title() const;220 QwtPlot* plot() const; 221 222 void setTitle( const QString& title ); 223 void setTitle( const QwtText& title ); 224 const QwtText& title() const; 220 225 221 226 virtual int rtti() const; … … 233 238 uint renderThreadCount() const; 234 239 235 void setLegendIconSize( const QSize & );240 void setLegendIconSize( const QSize& ); 236 241 QSize legendIconSize() const; 237 242 … … 244 249 bool isVisible () const; 245 250 246 void setAxes( intxAxis,intyAxis );247 248 void setXAxis( int axis);249 intxAxis() const;250 251 void setYAxis( int axis);252 intyAxis() const;251 void setAxes( QwtAxisId xAxis, QwtAxisId yAxis ); 252 253 void setXAxis( QwtAxisId ); 254 QwtAxisId xAxis() const; 255 256 void setYAxis( QwtAxisId ); 257 QwtAxisId yAxis() const; 253 258 254 259 virtual void itemChanged(); … … 256 261 257 262 /*! 258 \brief Draw the item 259 260 \param painter Painter 261 \param xMap Maps x-values into pixel coordinates. 262 \param yMap Maps y-values into pixel coordinates. 263 \param canvasRect Contents rect of the canvas in painter coordinates 264 */ 265 virtual void draw( QPainter *painter,266 const QwtScaleMap &xMap, const QwtScaleMap&yMap,267 const QRectF &canvasRect ) const = 0;263 \brief Draw the item 264 265 \param painter Painter 266 \param xMap Maps x-values into pixel coordinates. 267 \param yMap Maps y-values into pixel coordinates. 268 \param canvasRect Contents rect of the canvas in painter coordinates 269 */ 270 virtual void draw( QPainter* painter, 271 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 272 const QRectF& canvasRect ) const = 0; 268 273 269 274 virtual QRectF boundingRect() const; 270 275 271 276 virtual void getCanvasMarginHint( 272 const QwtScaleMap &xMap, const QwtScaleMap&yMap,273 const QRectF &canvasRect,274 double &left, double&top, double&right, double&bottom) const;277 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 278 const QRectF& canvasRect, 279 double& left, double& top, double& right, double& bottom) const; 275 280 276 281 virtual void updateScaleDiv( 277 282 const QwtScaleDiv&, const QwtScaleDiv& ); 278 283 279 virtual void updateLegend( const QwtPlotItem *, 280 const QList<QwtLegendData> & ); 281 282 QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const; 283 QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const; 284 285 virtual QList<QwtLegendData> legendData() const; 286 287 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 288 289 protected: 290 QwtGraphic defaultIcon( const QBrush &, const QSizeF & ) const; 291 292 private: 293 // Disabled copy constructor and operator= 294 QwtPlotItem( const QwtPlotItem & ); 295 QwtPlotItem &operator=( const QwtPlotItem & ); 284 virtual void updateLegend( const QwtPlotItem*, 285 const QList< QwtLegendData >& ); 286 287 QRectF scaleRect( const QwtScaleMap&, const QwtScaleMap& ) const; 288 QRectF paintRect( const QwtScaleMap&, const QwtScaleMap& ) const; 289 290 virtual QList< QwtLegendData > legendData() const; 291 292 virtual QwtGraphic legendIcon( int index, const QSizeF& ) const; 293 294 protected: 295 QwtGraphic defaultIcon( const QBrush&, const QSizeF& ) const; 296 297 private: 298 Q_DISABLE_COPY(QwtPlotItem) 296 299 297 300 class PrivateData; 298 PrivateData *d_data;301 PrivateData* m_data; 299 302 }; 300 303 … … 303 306 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::RenderHints ) 304 307 305 Q_DECLARE_METATYPE( QwtPlotItem * )308 Q_DECLARE_METATYPE( QwtPlotItem* ) 306 309 307 310 #endif -
trunk/BNC/qwt/qwt_plot_layout.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_scale_widget.h" 14 14 #include "qwt_abstract_legend.h" 15 #include <qscrollbar.h> 16 #include <qmath.h> 17 18 class QwtPlotLayout::LayoutData 19 { 20 public: 21 void init( const QwtPlot *, const QRectF &rect ); 22 23 struct t_legendData 24 { 25 int frameWidth; 26 int hScrollExtent; 27 int vScrollExtent; 28 QSize hint; 29 } legend; 30 31 struct t_titleData 32 { 33 QwtText text; 34 int frameWidth; 35 } title; 36 37 struct t_footerData 38 { 39 QwtText text; 40 int frameWidth; 41 } footer; 42 43 struct t_scaleData 44 { 45 bool isEnabled; 46 const QwtScaleWidget *scaleWidget; 47 QFont scaleFont; 48 int start; 49 int end; 50 int baseLineOffset; 51 double tickOffset; 52 int dimWithoutTitle; 53 } scale[QwtPlot::axisCnt]; 54 55 struct t_canvasData 56 { 57 int contentsMargins[ QwtPlot::axisCnt ]; 58 59 } canvas; 60 }; 61 62 /* 63 Extract all layout relevant data from the plot components 64 */ 65 void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect ) 66 { 67 // legend 68 69 if ( plot->legend() ) 70 { 71 legend.frameWidth = plot->legend()->frameWidth(); 72 legend.hScrollExtent = 73 plot->legend()->scrollExtent( Qt::Horizontal ); 74 legend.vScrollExtent = 75 plot->legend()->scrollExtent( Qt::Vertical ); 76 77 const QSize hint = plot->legend()->sizeHint(); 78 79 const int w = qMin( hint.width(), qFloor( rect.width() ) ); 80 81 int h = plot->legend()->heightForWidth( w ); 82 if ( h <= 0 ) 83 h = hint.height(); 84 85 legend.hint = QSize( w, h ); 86 } 87 88 // title 89 90 title.frameWidth = 0; 91 title.text = QwtText(); 92 93 if ( plot->titleLabel() ) 94 { 95 const QwtTextLabel *label = plot->titleLabel(); 96 title.text = label->text(); 97 if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) 98 title.text.setFont( label->font() ); 99 100 title.frameWidth = plot->titleLabel()->frameWidth(); 101 } 102 103 // footer 104 105 footer.frameWidth = 0; 106 footer.text = QwtText(); 107 108 if ( plot->footerLabel() ) 109 { 110 const QwtTextLabel *label = plot->footerLabel(); 111 footer.text = label->text(); 112 if ( !( footer.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) 113 footer.text.setFont( label->font() ); 114 115 footer.frameWidth = plot->footerLabel()->frameWidth(); 116 } 117 118 // scales 119 120 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 121 { 122 if ( plot->axisEnabled( axis ) ) 123 { 124 const QwtScaleWidget *scaleWidget = plot->axisWidget( axis ); 125 126 scale[axis].isEnabled = true; 127 128 scale[axis].scaleWidget = scaleWidget; 129 130 scale[axis].scaleFont = scaleWidget->font(); 131 132 scale[axis].start = scaleWidget->startBorderDist(); 133 scale[axis].end = scaleWidget->endBorderDist(); 134 135 scale[axis].baseLineOffset = scaleWidget->margin(); 136 scale[axis].tickOffset = scaleWidget->margin(); 137 if ( scaleWidget->scaleDraw()->hasComponent( 138 QwtAbstractScaleDraw::Ticks ) ) 139 { 140 scale[axis].tickOffset += 141 scaleWidget->scaleDraw()->maxTickLength(); 142 } 143 144 scale[axis].dimWithoutTitle = scaleWidget->dimForLength( 145 QWIDGETSIZE_MAX, scale[axis].scaleFont ); 146 147 if ( !scaleWidget->title().isEmpty() ) 148 { 149 scale[axis].dimWithoutTitle -= 150 scaleWidget->titleHeightForWidth( QWIDGETSIZE_MAX ); 151 } 152 } 153 else 154 { 155 scale[axis].isEnabled = false; 156 scale[axis].start = 0; 157 scale[axis].end = 0; 158 scale[axis].baseLineOffset = 0; 159 scale[axis].tickOffset = 0.0; 160 scale[axis].dimWithoutTitle = 0; 161 } 162 } 163 164 // canvas 165 166 plot->canvas()->getContentsMargins( 167 &canvas.contentsMargins[ QwtPlot::yLeft ], 168 &canvas.contentsMargins[ QwtPlot::xTop ], 169 &canvas.contentsMargins[ QwtPlot::yRight ], 170 &canvas.contentsMargins[ QwtPlot::xBottom ] ); 171 } 172 173 class QwtPlotLayout::PrivateData 174 { 175 public: 176 PrivateData(): 177 spacing( 5 ) 178 { 179 } 180 181 QRectF titleRect; 182 QRectF footerRect; 183 QRectF legendRect; 184 QRectF scaleRect[QwtPlot::axisCnt]; 185 QRectF canvasRect; 186 187 QwtPlotLayout::LayoutData layoutData; 188 189 QwtPlot::LegendPosition legendPos; 190 double legendRatio; 191 unsigned int spacing; 192 unsigned int canvasMargin[QwtPlot::axisCnt]; 193 bool alignCanvasToScales[QwtPlot::axisCnt]; 194 }; 195 196 /*! 197 \brief Constructor 198 */ 199 200 QwtPlotLayout::QwtPlotLayout() 201 { 202 d_data = new PrivateData; 203 204 setLegendPosition( QwtPlot::BottomLegend ); 205 setCanvasMargin( 4 ); 206 setAlignCanvasToScales( false ); 207 208 invalidate(); 209 } 210 211 //! Destructor 212 QwtPlotLayout::~QwtPlotLayout() 213 { 214 delete d_data; 215 } 216 217 /*! 218 Change a margin of the canvas. The margin is the space 219 above/below the scale ticks. A negative margin will 220 be set to -1, excluding the borders of the scales. 221 222 \param margin New margin 223 \param axis One of QwtPlot::Axis. Specifies where the position of the margin. 224 -1 means margin at all borders. 225 \sa canvasMargin() 226 227 \warning The margin will have no effect when alignCanvasToScale() is true 228 */ 229 230 void QwtPlotLayout::setCanvasMargin( int margin, int axis ) 231 { 232 if ( margin < -1 ) 233 margin = -1; 234 235 if ( axis == -1 ) 236 { 237 for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) 238 d_data->canvasMargin[axis] = margin; 239 } 240 else if ( axis >= 0 && axis < QwtPlot::axisCnt ) 241 d_data->canvasMargin[axis] = margin; 242 } 243 244 /*! 245 \param axisId Axis index 246 \return Margin around the scale tick borders 247 \sa setCanvasMargin() 248 */ 249 int QwtPlotLayout::canvasMargin( int axisId ) const 250 { 251 if ( axisId < 0 || axisId >= QwtPlot::axisCnt ) 15 #include "qwt_math.h" 16 17 #include <qmargins.h> 18 19 namespace 20 { 21 class LayoutData 22 { 23 public: 24 struct LegendData 25 { 26 void init( const QwtAbstractLegend* legend ) 27 { 28 if ( legend ) 29 { 30 frameWidth = legend->frameWidth(); 31 hScrollExtent = legend->scrollExtent( Qt::Horizontal ); 32 vScrollExtent = legend->scrollExtent( Qt::Vertical ); 33 34 hint = legend->sizeHint(); 35 } 36 } 37 38 QSize legendHint( const QwtAbstractLegend* legend, const QRectF& rect ) const 39 { 40 const int w = qMin( hint.width(), qwtFloor( rect.width() ) ); 41 42 int h = legend->heightForWidth( w ); 43 if ( h <= 0 ) 44 h = hint.height(); 45 46 return QSize( w, h ); 47 } 48 49 int frameWidth; 50 int hScrollExtent; 51 int vScrollExtent; 52 QSize hint; 53 }; 54 55 struct LabelData 56 { 57 void init( const QwtTextLabel* label ) 58 { 59 frameWidth = 0; 60 text = QwtText(); 61 62 if ( label ) 63 { 64 text = label->text(); 65 if ( !( text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) 66 text.setFont( label->font() ); 67 68 frameWidth = label->frameWidth(); 69 } 70 } 71 72 QwtText text; 73 int frameWidth; 74 }; 75 76 struct ScaleData 77 { 78 void init( const QwtScaleWidget* axisWidget ) 79 { 80 isVisible = true; 81 82 scaleWidget = axisWidget; 83 scaleFont = axisWidget->font(); 84 85 start = axisWidget->startBorderDist(); 86 end = axisWidget->endBorderDist(); 87 88 baseLineOffset = axisWidget->margin(); 89 90 tickOffset = axisWidget->margin(); 91 if ( axisWidget->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) 92 tickOffset += axisWidget->scaleDraw()->maxTickLength(); 93 94 dimWithoutTitle = axisWidget->dimForLength( QWIDGETSIZE_MAX, scaleFont ); 95 if ( !axisWidget->title().isEmpty() ) 96 dimWithoutTitle -= axisWidget->titleHeightForWidth( QWIDGETSIZE_MAX ); 97 } 98 99 void reset() 100 { 101 isVisible = false; 102 start = 0; 103 end = 0; 104 baseLineOffset = 0; 105 tickOffset = 0.0; 106 dimWithoutTitle = 0; 107 } 108 109 bool isVisible; 110 const QwtScaleWidget* scaleWidget; 111 QFont scaleFont; 112 int start; 113 int end; 114 int baseLineOffset; 115 double tickOffset; 116 int dimWithoutTitle; 117 }; 118 119 struct CanvasData 120 { 121 void init( const QWidget* canvas ) 122 { 123 const QMargins m = canvas->contentsMargins(); 124 125 contentsMargins[ QwtAxis::YLeft ] = m.left(); 126 contentsMargins[ QwtAxis::XTop ] = m.top(); 127 contentsMargins[ QwtAxis::YRight ] = m.right(); 128 contentsMargins[ QwtAxis::XBottom ] = m.bottom(); 129 } 130 131 int contentsMargins[ QwtAxis::AxisPositions ]; 132 }; 133 134 public: 135 enum Label 136 { 137 Title, 138 Footer, 139 140 NumLabels 141 }; 142 143 LayoutData( const QwtPlot* ); 144 bool hasSymmetricYAxes() const; 145 146 inline ScaleData& axisData( QwtAxisId axisId ) 147 { 148 return m_scaleData[ axisId ]; 149 } 150 151 inline const ScaleData& axisData( QwtAxisId axisId ) const 152 { 153 return m_scaleData[ axisId ]; 154 } 155 156 inline double tickOffset( int axisPos ) const 157 { 158 return axisData( axisPos ).tickOffset; 159 } 160 161 LegendData legendData; 162 LabelData labelData[ NumLabels ]; 163 CanvasData canvasData; 164 165 private: 166 ScaleData m_scaleData[ QwtAxis::AxisPositions ]; 167 }; 168 169 /* 170 Extract all layout relevant data from the plot components 171 */ 172 LayoutData::LayoutData( const QwtPlot* plot ) 173 { 174 legendData.init( plot->legend() ); 175 labelData[ Title ].init( plot->titleLabel() ); 176 labelData[ Footer ].init( plot->footerLabel() ); 177 178 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 179 { 180 { 181 const QwtAxisId axisId( axisPos ); 182 183 ScaleData& scaleData = axisData( axisId ); 184 185 if ( plot->isAxisVisible( axisId ) ) 186 { 187 const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 188 scaleData.init( scaleWidget ); 189 } 190 else 191 { 192 scaleData.reset(); 193 } 194 } 195 } 196 197 canvasData.init( plot->canvas() ); 198 } 199 200 bool LayoutData::hasSymmetricYAxes() const 201 { 202 using namespace QwtAxis; 203 return m_scaleData[ YLeft ].isVisible == m_scaleData[ YRight ].isVisible; 204 } 205 } 206 207 namespace 208 { 209 class LayoutHintData 210 { 211 public: 212 LayoutHintData( const QwtPlot* plot ); 213 214 int alignedSize( const QwtAxisId ) const; 215 216 inline int yAxesWidth() const 217 { 218 using namespace QwtAxis; 219 return axesWidth( YLeft ) + axesWidth( YRight ); 220 } 221 222 inline int yAxesHeight() const 223 { 224 using namespace QwtAxis; 225 return qMax( axesHeight( YLeft ), axesHeight( YRight ) ); 226 } 227 228 inline int xAxesHeight() const 229 { 230 using namespace QwtAxis; 231 return axesHeight( XTop ) + axesHeight( XBottom ); 232 } 233 234 inline int xAxesWidth() const 235 { 236 using namespace QwtAxis; 237 return qMax( axesWidth( XTop ), axesWidth( XBottom ) ); 238 } 239 240 private: 241 242 struct ScaleData 243 { 244 ScaleData() 245 { 246 w = h = minLeft = minRight = tickOffset = 0; 247 } 248 249 int w; 250 int h; 251 int minLeft; 252 int minRight; 253 int tickOffset; 254 255 }; 256 257 const ScaleData& axisData( QwtAxisId axisId ) const 258 { 259 return m_scaleData[ axisId ]; 260 } 261 262 ScaleData& axisData( QwtAxisId axisId ) 263 { 264 return m_scaleData[ axisId ]; 265 } 266 267 inline int axesWidth( int axisPos ) const 268 { 269 return m_scaleData[axisPos].w; 270 } 271 272 inline int axesHeight( int axisPos ) const 273 { 274 return m_scaleData[axisPos].h; 275 } 276 277 int m_canvasBorder[QwtAxis::AxisPositions]; 278 ScaleData m_scaleData[QwtAxis::AxisPositions]; 279 }; 280 281 LayoutHintData::LayoutHintData( const QwtPlot* plot ) 282 { 283 using namespace QwtAxis; 284 285 const QMargins m = plot->canvas()->contentsMargins(); 286 287 int contentsMargins[ 4 ]; 288 contentsMargins[ YLeft ] = m.left(); 289 contentsMargins[ XTop ] = m.top(); 290 contentsMargins[ YRight ] = m.right(); 291 contentsMargins[ XBottom ] = m.bottom(); 292 293 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 294 { 295 m_canvasBorder[axisPos] = contentsMargins[axisPos] + 296 plot->plotLayout()->canvasMargin( axisPos ) + 1; 297 { 298 const QwtAxisId axisId( axisPos ); 299 300 if ( plot->isAxisVisible( axisId ) ) 301 { 302 const QwtScaleWidget* scl = plot->axisWidget( axisId ); 303 304 const QSize hint = scl->minimumSizeHint(); 305 306 ScaleData& sd = axisData( axisId ); 307 sd.w = hint.width(); 308 sd.h = hint.height(); 309 scl->getBorderDistHint( sd.minLeft, sd.minRight ); 310 311 { 312 sd.tickOffset = scl->margin(); 313 if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) 314 sd.tickOffset += qwtCeil( scl->scaleDraw()->maxTickLength() ); 315 } 316 } 317 } 318 } 319 320 for ( int axis = 0; axis < AxisPositions; axis++ ) 321 { 322 const int sz = alignedSize( axis ); 323 324 ScaleData& sd = axisData( axis ); 325 if ( isXAxis( axis ) ) 326 sd.w = sz; 327 else 328 sd.h = sz; 329 } 330 } 331 332 int LayoutHintData::alignedSize( const QwtAxisId axisId ) const 333 { 334 using namespace QwtAxis; 335 336 const ScaleData& sd = axisData( axisId ); 337 338 if ( sd.w && isXAxis( axisId ) ) 339 { 340 int w = sd.w; 341 342 if ( const int leftW = axesWidth( YLeft ) ) 343 { 344 const int shiftLeft = sd.minLeft - m_canvasBorder[YLeft]; 345 if ( shiftLeft > 0 ) 346 w -= qMin( shiftLeft, leftW ); 347 } 348 349 if ( const int rightW = axesWidth( YRight ) ) 350 { 351 const int shiftRight = sd.minRight - m_canvasBorder[YRight]; 352 if ( shiftRight > 0 ) 353 w -= qMin( shiftRight, rightW ); 354 } 355 356 return w; 357 } 358 359 if ( sd.h && isYAxis( axisId ) ) 360 { 361 int h = sd.h; 362 363 if ( axesHeight( XBottom ) ) 364 { 365 const int shiftBottom = sd.minLeft - m_canvasBorder[XBottom]; 366 if ( shiftBottom > 0 ) 367 h -= qMin( shiftBottom, axisData( XBottom ).tickOffset ); 368 } 369 370 if ( axesHeight( XTop ) ) 371 { 372 const int shiftTop = sd.minRight - m_canvasBorder[XTop]; 373 if ( shiftTop > 0 ) 374 h -= qMin( shiftTop, axisData( XTop ).tickOffset ); 375 } 376 377 return h; 378 } 379 252 380 return 0; 253 254 return d_data->canvasMargin[axisId]; 255 } 256 257 /*! 258 \brief Set the align-canvas-to-axis-scales flag for all axes 259 260 \param on True/False 261 \sa setAlignCanvasToScale(), alignCanvasToScale() 262 */ 263 void QwtPlotLayout::setAlignCanvasToScales( bool on ) 264 { 265 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 266 d_data->alignCanvasToScales[axis] = on; 267 } 268 269 /*! 270 Change the align-canvas-to-axis-scales setting. The canvas may: 271 272 - extend beyond the axis scale ends to maximize its size, 273 - align with the axis scale ends to control its size. 274 275 The axisId parameter is somehow confusing as it identifies a border 276 of the plot and not the axes, that are aligned. F.e when QwtPlot::yLeft 277 is set, the left end of the the x-axes ( QwtPlot::xTop, QwtPlot::xBottom ) 278 is aligned. 279 280 \param axisId Axis index 281 \param on New align-canvas-to-axis-scales setting 282 283 \sa setCanvasMargin(), alignCanvasToScale(), setAlignCanvasToScales() 284 \warning In case of on == true canvasMargin() will have no effect 285 */ 286 void QwtPlotLayout::setAlignCanvasToScale( int axisId, bool on ) 287 { 288 if ( axisId >= 0 && axisId < QwtPlot::axisCnt ) 289 d_data->alignCanvasToScales[axisId] = on; 290 } 291 292 /*! 293 Return the align-canvas-to-axis-scales setting. The canvas may: 294 - extend beyond the axis scale ends to maximize its size 295 - align with the axis scale ends to control its size. 296 297 \param axisId Axis index 298 \return align-canvas-to-axis-scales setting 299 \sa setAlignCanvasToScale(), setAlignCanvasToScale(), setCanvasMargin() 300 */ 301 bool QwtPlotLayout::alignCanvasToScale( int axisId ) const 302 { 303 if ( axisId < 0 || axisId >= QwtPlot::axisCnt ) 304 return false; 305 306 return d_data->alignCanvasToScales[ axisId ]; 307 } 308 309 /*! 310 Change the spacing of the plot. The spacing is the distance 311 between the plot components. 312 313 \param spacing New spacing 314 \sa setCanvasMargin(), spacing() 315 */ 316 void QwtPlotLayout::setSpacing( int spacing ) 317 { 318 d_data->spacing = qMax( 0, spacing ); 319 } 320 321 /*! 322 \return Spacing 323 \sa margin(), setSpacing() 324 */ 325 int QwtPlotLayout::spacing() const 326 { 327 return d_data->spacing; 328 } 329 330 /*! 331 \brief Specify the position of the legend 332 \param pos The legend's position. 333 \param ratio Ratio between legend and the bounding rectangle 334 of title, footer, canvas and axes. The legend will be shrunk 335 if it would need more space than the given ratio. 336 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 337 it will be reset to the default ratio. 338 The default vertical/horizontal ratio is 0.33/0.5. 339 340 \sa QwtPlot::setLegendPosition() 341 */ 342 343 void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos, double ratio ) 344 { 345 if ( ratio > 1.0 ) 346 ratio = 1.0; 347 348 switch ( pos ) 349 { 350 case QwtPlot::TopLegend: 351 case QwtPlot::BottomLegend: 352 if ( ratio <= 0.0 ) 353 ratio = 0.33; 354 d_data->legendRatio = ratio; 355 d_data->legendPos = pos; 356 break; 357 case QwtPlot::LeftLegend: 358 case QwtPlot::RightLegend: 359 if ( ratio <= 0.0 ) 360 ratio = 0.5; 361 d_data->legendRatio = ratio; 362 d_data->legendPos = pos; 363 break; 364 default: 365 break; 366 } 367 } 368 369 /*! 370 \brief Specify the position of the legend 371 \param pos The legend's position. Valid values are 372 \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend, 373 \c QwtPlot::TopLegend, \c QwtPlot::BottomLegend. 374 375 \sa QwtPlot::setLegendPosition() 376 */ 377 void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos ) 378 { 379 setLegendPosition( pos, 0.0 ); 380 } 381 382 /*! 383 \return Position of the legend 384 \sa setLegendPosition(), QwtPlot::setLegendPosition(), 385 QwtPlot::legendPosition() 386 */ 387 QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const 388 { 389 return d_data->legendPos; 390 } 391 392 /*! 393 Specify the relative size of the legend in the plot 394 \param ratio Ratio between legend and the bounding rectangle 395 of title, footer, canvas and axes. The legend will be shrunk 396 if it would need more space than the given ratio. 397 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 398 it will be reset to the default ratio. 399 The default vertical/horizontal ratio is 0.33/0.5. 400 */ 401 void QwtPlotLayout::setLegendRatio( double ratio ) 402 { 403 setLegendPosition( legendPosition(), ratio ); 404 } 405 406 /*! 407 \return The relative size of the legend in the plot. 408 \sa setLegendPosition() 409 */ 410 double QwtPlotLayout::legendRatio() const 411 { 412 return d_data->legendRatio; 413 } 414 415 /*! 416 \brief Set the geometry for the title 417 418 This method is intended to be used from derived layouts 419 overloading activate() 420 421 \sa titleRect(), activate() 422 */ 423 void QwtPlotLayout::setTitleRect( const QRectF &rect ) 424 { 425 d_data->titleRect = rect; 426 } 427 428 /*! 429 \return Geometry for the title 430 \sa activate(), invalidate() 431 */ 432 QRectF QwtPlotLayout::titleRect() const 433 { 434 return d_data->titleRect; 435 } 436 437 /*! 438 \brief Set the geometry for the footer 439 440 This method is intended to be used from derived layouts 441 overloading activate() 442 443 \sa footerRect(), activate() 444 */ 445 void QwtPlotLayout::setFooterRect( const QRectF &rect ) 446 { 447 d_data->footerRect = rect; 448 } 449 450 /*! 451 \return Geometry for the footer 452 \sa activate(), invalidate() 453 */ 454 QRectF QwtPlotLayout::footerRect() const 455 { 456 return d_data->footerRect; 457 } 458 459 /*! 460 \brief Set the geometry for the legend 461 462 This method is intended to be used from derived layouts 463 overloading activate() 464 465 \param rect Rectangle for the legend 466 467 \sa legendRect(), activate() 468 */ 469 void QwtPlotLayout::setLegendRect( const QRectF &rect ) 470 { 471 d_data->legendRect = rect; 472 } 473 474 /*! 475 \return Geometry for the legend 476 \sa activate(), invalidate() 477 */ 478 QRectF QwtPlotLayout::legendRect() const 479 { 480 return d_data->legendRect; 481 } 482 483 /*! 484 \brief Set the geometry for an axis 485 486 This method is intended to be used from derived layouts 487 overloading activate() 488 489 \param axis Axis index 490 \param rect Rectangle for the scale 491 492 \sa scaleRect(), activate() 493 */ 494 void QwtPlotLayout::setScaleRect( int axis, const QRectF &rect ) 495 { 496 if ( axis >= 0 && axis < QwtPlot::axisCnt ) 497 d_data->scaleRect[axis] = rect; 498 } 499 500 /*! 501 \param axis Axis index 502 \return Geometry for the scale 503 \sa activate(), invalidate() 504 */ 505 QRectF QwtPlotLayout::scaleRect( int axis ) const 506 { 507 if ( axis < 0 || axis >= QwtPlot::axisCnt ) 508 { 509 static QRectF dummyRect; 510 return dummyRect; 511 } 512 return d_data->scaleRect[axis]; 513 } 514 515 /*! 516 \brief Set the geometry for the canvas 517 518 This method is intended to be used from derived layouts 519 overloading activate() 520 521 \sa canvasRect(), activate() 522 */ 523 void QwtPlotLayout::setCanvasRect( const QRectF &rect ) 524 { 525 d_data->canvasRect = rect; 526 } 527 528 /*! 529 \return Geometry for the canvas 530 \sa activate(), invalidate() 531 */ 532 QRectF QwtPlotLayout::canvasRect() const 533 { 534 return d_data->canvasRect; 535 } 536 537 /*! 538 Invalidate the geometry of all components. 539 \sa activate() 540 */ 541 void QwtPlotLayout::invalidate() 542 { 543 d_data->titleRect = d_data->footerRect 544 = d_data->legendRect = d_data->canvasRect = QRect(); 545 546 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 547 d_data->scaleRect[axis] = QRect(); 548 } 549 550 /*! 551 \return Minimum size hint 552 \param plot Plot widget 553 554 \sa QwtPlot::minimumSizeHint() 555 */ 556 557 QSize QwtPlotLayout::minimumSizeHint( const QwtPlot *plot ) const 558 { 559 class ScaleData 560 { 561 public: 562 ScaleData() 563 { 564 w = h = minLeft = minRight = tickOffset = 0; 565 } 566 567 int w; 568 int h; 569 int minLeft; 570 int minRight; 571 int tickOffset; 572 } scaleData[QwtPlot::axisCnt]; 573 574 int canvasBorder[QwtPlot::axisCnt]; 575 576 int fw; 577 plot->canvas()->getContentsMargins( &fw, NULL, NULL, NULL ); 578 579 int axis; 580 for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) 581 { 582 if ( plot->axisEnabled( axis ) ) 583 { 584 const QwtScaleWidget *scl = plot->axisWidget( axis ); 585 ScaleData &sd = scaleData[axis]; 586 587 const QSize hint = scl->minimumSizeHint(); 588 sd.w = hint.width(); 589 sd.h = hint.height(); 590 scl->getBorderDistHint( sd.minLeft, sd.minRight ); 591 sd.tickOffset = scl->margin(); 592 if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) 593 sd.tickOffset += qCeil( scl->scaleDraw()->maxTickLength() ); 594 } 595 596 canvasBorder[axis] = fw + d_data->canvasMargin[axis] + 1; 597 } 598 599 600 for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) 601 { 602 ScaleData &sd = scaleData[axis]; 603 if ( sd.w && ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) ) 604 { 605 if ( ( sd.minLeft > canvasBorder[QwtPlot::yLeft] ) 606 && scaleData[QwtPlot::yLeft].w ) 607 { 608 int shiftLeft = sd.minLeft - canvasBorder[QwtPlot::yLeft]; 609 if ( shiftLeft > scaleData[QwtPlot::yLeft].w ) 610 shiftLeft = scaleData[QwtPlot::yLeft].w; 611 612 sd.w -= shiftLeft; 613 } 614 if ( ( sd.minRight > canvasBorder[QwtPlot::yRight] ) 615 && scaleData[QwtPlot::yRight].w ) 616 { 617 int shiftRight = sd.minRight - canvasBorder[QwtPlot::yRight]; 618 if ( shiftRight > scaleData[QwtPlot::yRight].w ) 619 shiftRight = scaleData[QwtPlot::yRight].w; 620 621 sd.w -= shiftRight; 622 } 623 } 624 625 if ( sd.h && ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) ) 626 { 627 if ( ( sd.minLeft > canvasBorder[QwtPlot::xBottom] ) && 628 scaleData[QwtPlot::xBottom].h ) 629 { 630 int shiftBottom = sd.minLeft - canvasBorder[QwtPlot::xBottom]; 631 if ( shiftBottom > scaleData[QwtPlot::xBottom].tickOffset ) 632 shiftBottom = scaleData[QwtPlot::xBottom].tickOffset; 633 634 sd.h -= shiftBottom; 635 } 636 if ( ( sd.minLeft > canvasBorder[QwtPlot::xTop] ) && 637 scaleData[QwtPlot::xTop].h ) 638 { 639 int shiftTop = sd.minRight - canvasBorder[QwtPlot::xTop]; 640 if ( shiftTop > scaleData[QwtPlot::xTop].tickOffset ) 641 shiftTop = scaleData[QwtPlot::xTop].tickOffset; 642 643 sd.h -= shiftTop; 644 } 645 } 646 } 647 648 const QWidget *canvas = plot->canvas(); 649 650 int left, top, right, bottom; 651 canvas->getContentsMargins( &left, &top, &right, &bottom ); 652 653 const QSize minCanvasSize = canvas->minimumSize(); 654 655 int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; 656 int cw = qMax( scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w ) 657 + left + 1 + right + 1; 658 w += qMax( cw, minCanvasSize.width() ); 659 660 int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h; 661 int ch = qMax( scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h ) 662 + top + 1 + bottom + 1; 663 h += qMax( ch, minCanvasSize.height() ); 664 665 const QwtTextLabel *labels[2]; 666 labels[0] = plot->titleLabel(); 667 labels[1] = plot->footerLabel(); 668 669 for ( int i = 0; i < 2; i++ ) 670 { 671 const QwtTextLabel *label = labels[i]; 672 if ( label && !label->text().isEmpty() ) 673 { 674 // If only QwtPlot::yLeft or QwtPlot::yRight is showing, 675 // we center on the plot canvas. 676 const bool centerOnCanvas = !( plot->axisEnabled( QwtPlot::yLeft ) 677 && plot->axisEnabled( QwtPlot::yRight ) ); 678 679 int labelW = w; 680 if ( centerOnCanvas ) 681 { 682 labelW -= scaleData[QwtPlot::yLeft].w 683 + scaleData[QwtPlot::yRight].w; 684 } 685 686 int labelH = label->heightForWidth( labelW ); 687 if ( labelH > labelW ) // Compensate for a long title 688 { 689 w = labelW = labelH; 690 if ( centerOnCanvas ) 691 { 692 w += scaleData[QwtPlot::yLeft].w 693 + scaleData[QwtPlot::yRight].w; 694 } 695 696 labelH = label->heightForWidth( labelW ); 697 } 698 h += labelH + d_data->spacing; 699 } 700 } 701 702 // Compute the legend contribution 703 704 const QwtAbstractLegend *legend = plot->legend(); 705 if ( legend && !legend->isEmpty() ) 706 { 707 if ( d_data->legendPos == QwtPlot::LeftLegend 708 || d_data->legendPos == QwtPlot::RightLegend ) 709 { 710 int legendW = legend->sizeHint().width(); 711 int legendH = legend->heightForWidth( legendW ); 712 713 if ( legend->frameWidth() > 0 ) 714 w += d_data->spacing; 715 716 if ( legendH > h ) 717 legendW += legend->scrollExtent( Qt::Horizontal ); 718 719 if ( d_data->legendRatio < 1.0 ) 720 legendW = qMin( legendW, int( w / ( 1.0 - d_data->legendRatio ) ) ); 721 722 w += legendW + d_data->spacing; 723 } 724 else // QwtPlot::Top, QwtPlot::Bottom 725 { 726 int legendW = qMin( legend->sizeHint().width(), w ); 727 int legendH = legend->heightForWidth( legendW ); 728 729 if ( legend->frameWidth() > 0 ) 730 h += d_data->spacing; 731 732 if ( d_data->legendRatio < 1.0 ) 733 legendH = qMin( legendH, int( h / ( 1.0 - d_data->legendRatio ) ) ); 734 735 h += legendH + d_data->spacing; 736 } 737 } 738 739 return QSize( w, h ); 740 } 741 742 /*! 743 Find the geometry for the legend 744 745 \param options Options how to layout the legend 746 \param rect Rectangle where to place the legend 747 748 \return Geometry for the legend 749 \sa Options 750 */ 751 752 QRectF QwtPlotLayout::layoutLegend( Options options, 753 const QRectF &rect ) const 754 { 755 const QSize hint( d_data->layoutData.legend.hint ); 756 381 } 382 } 383 384 namespace 385 { 386 class LayoutEngine 387 { 388 public: 389 struct Dimensions 390 { 391 Dimensions() 392 { 393 dimTitle = dimFooter = 0; 394 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 395 m_dimAxes[axisPos] = 0; 396 } 397 398 inline int dimAxis( QwtAxisId axisId ) const 399 { 400 return m_dimAxes[ axisId ]; 401 } 402 403 void setDimAxis( QwtAxisId axisId, int dim ) 404 { 405 m_dimAxes[ axisId ] = dim; 406 } 407 408 inline int dimAxes( int axisPos ) const 409 { 410 return m_dimAxes[ axisPos ]; 411 } 412 413 inline int dimYAxes() const 414 { 415 return dimAxes( QwtAxis::YLeft ) + dimAxes( QwtAxis::YRight ); 416 } 417 418 inline int dimXAxes() const 419 { 420 return dimAxes( QwtAxis::XTop ) + dimAxes( QwtAxis::XBottom ); 421 } 422 423 inline QRectF centered( const QRectF& rect, const QRectF& labelRect ) const 424 { 425 QRectF r = labelRect; 426 r.setX( rect.left() + dimAxes( QwtAxis::YLeft ) ); 427 r.setWidth( rect.width() - dimYAxes() ); 428 429 return r; 430 } 431 432 inline QRectF innerRect( const QRectF& rect ) const 433 { 434 QRectF r( 435 rect.x() + dimAxes( QwtAxis::YLeft ), 436 rect.y() + dimAxes( QwtAxis::XTop ), 437 rect.width() - dimYAxes(), 438 rect.height() - dimXAxes() ); 439 440 if ( r.width() < 0 ) 441 { 442 r.setX( rect.center().x() ); 443 r.setWidth( 0 ); 444 } 445 if ( r.height() < 0 ) 446 { 447 r.setY( rect.center().y() ); 448 r.setHeight( 0 ); 449 } 450 451 return r; 452 } 453 454 int dimTitle; 455 int dimFooter; 456 457 private: 458 int m_dimAxes[QwtAxis::AxisPositions]; 459 }; 460 461 LayoutEngine() 462 : m_legendPos( QwtPlot::BottomLegend ) 463 , m_legendRatio( 1.0 ) 464 , m_spacing( 5 ) 465 { 466 } 467 468 QRectF layoutLegend( QwtPlotLayout::Options, 469 const LayoutData::LegendData&, const QRectF&, const QSize& ) const; 470 471 QRectF alignLegend( const QSize& legendHint, 472 const QRectF& canvasRect, const QRectF& legendRect ) const; 473 474 void alignScales( QwtPlotLayout::Options, 475 const LayoutData&, QRectF& canvasRect, 476 QRectF scaleRect[QwtAxis::AxisPositions] ) const; 477 478 Dimensions layoutDimensions( QwtPlotLayout::Options, 479 const LayoutData&, const QRectF& ) const; 480 481 inline void setSpacing( unsigned int spacing ) { m_spacing = spacing; } 482 inline unsigned int spacing() const { return m_spacing; } 483 484 inline void setAlignCanvas( int axisPos, bool on ) { m_alignCanvas[ axisPos ] = on; } 485 inline bool alignCanvas( int axisPos ) const { return m_alignCanvas[ axisPos ]; } 486 487 inline void setCanvasMargin( int axisPos, int margin ) { m_canvasMargin[ axisPos ] = margin; } 488 inline int canvasMargin( int axisPos ) const { return m_canvasMargin[ axisPos ]; } 489 490 inline void setLegendPos( QwtPlot::LegendPosition pos ) { m_legendPos = pos; } 491 inline QwtPlot::LegendPosition legendPos() const { return m_legendPos; } 492 493 inline void setLegendRatio( double ratio ) { m_legendRatio = ratio; } 494 inline double legendRatio() const { return m_legendRatio; } 495 496 private: 497 int heightForWidth( LayoutData::Label, const LayoutData&, 498 QwtPlotLayout::Options, double width, int axesWidth ) const; 499 500 QwtPlot::LegendPosition m_legendPos; 501 double m_legendRatio; 502 503 unsigned int m_canvasMargin[QwtAxis::AxisPositions]; 504 bool m_alignCanvas[QwtAxis::AxisPositions]; 505 506 unsigned int m_spacing; 507 }; 508 } 509 510 QRectF LayoutEngine::layoutLegend( QwtPlotLayout::Options options, 511 const LayoutData::LegendData& legendData, 512 const QRectF& rect, const QSize& legendHint ) const 513 { 757 514 int dim; 758 if ( d_data->legendPos == QwtPlot::LeftLegend759 || d_data->legendPos == QwtPlot::RightLegend )515 if ( m_legendPos == QwtPlot::LeftLegend 516 || m_legendPos == QwtPlot::RightLegend ) 760 517 { 761 518 // We don't allow vertical legends to take more than 762 519 // half of the available space. 763 520 764 dim = qMin( hint.width(), int( rect.width() *d_data->legendRatio ) );765 766 if ( !( options & IgnoreScrollbars ) ) 767 { 768 if ( hint.height() > rect.height() )521 dim = qMin( legendHint.width(), int( rect.width() * m_legendRatio ) ); 522 523 if ( !( options & QwtPlotLayout::IgnoreScrollbars ) ) 524 { 525 if ( legendHint.height() > rect.height() ) 769 526 { 770 527 // The legend will need additional 771 528 // space for the vertical scrollbar. 772 529 773 dim += d_data->layoutData.legend.hScrollExtent;530 dim += legendData.hScrollExtent; 774 531 } 775 532 } … … 777 534 else 778 535 { 779 dim = qMin( hint.height(), int( rect.height() *d_data->legendRatio ) );780 dim = qMax( dim, d_data->layoutData.legend.vScrollExtent );536 dim = qMin( legendHint.height(), int( rect.height() * m_legendRatio ) ); 537 dim = qMax( dim, legendData.vScrollExtent ); 781 538 } 782 539 783 540 QRectF legendRect = rect; 784 switch ( d_data->legendPos )541 switch ( m_legendPos ) 785 542 { 786 543 case QwtPlot::LeftLegend: 544 { 787 545 legendRect.setWidth( dim ); 788 546 break; 547 } 789 548 case QwtPlot::RightLegend: 549 { 790 550 legendRect.setX( rect.right() - dim ); 791 551 legendRect.setWidth( dim ); 792 552 break; 553 } 793 554 case QwtPlot::TopLegend: 555 { 794 556 legendRect.setHeight( dim ); 795 557 break; 558 } 796 559 case QwtPlot::BottomLegend: 560 { 797 561 legendRect.setY( rect.bottom() - dim ); 798 562 legendRect.setHeight( dim ); 799 563 break; 564 } 800 565 } 801 566 … … 803 568 } 804 569 805 /*! 806 Align the legend to the canvas 807 808 \param canvasRect Geometry of the canvas 809 \param legendRect Maximum geometry for the legend 810 811 \return Geometry for the aligned legend 812 */ 813 QRectF QwtPlotLayout::alignLegend( const QRectF &canvasRect, 814 const QRectF &legendRect ) const 570 QRectF LayoutEngine::alignLegend( const QSize& legendHint, 571 const QRectF& canvasRect, const QRectF& legendRect ) const 815 572 { 816 573 QRectF alignedRect = legendRect; 817 574 818 if ( d_data->legendPos == QwtPlot::BottomLegend819 || d_data->legendPos == QwtPlot::TopLegend )820 { 821 if ( d_data->layoutData.legend.hint.width() < canvasRect.width() )575 if ( m_legendPos == QwtPlot::BottomLegend 576 || m_legendPos == QwtPlot::TopLegend ) 577 { 578 if ( legendHint.width() < canvasRect.width() ) 822 579 { 823 580 alignedRect.setX( canvasRect.x() ); … … 827 584 else 828 585 { 829 if ( d_data->layoutData.legend.hint.height() < canvasRect.height() )586 if ( legendHint.height() < canvasRect.height() ) 830 587 { 831 588 alignedRect.setY( canvasRect.y() ); … … 837 594 } 838 595 839 /*! 840 Expand all line breaks in text labels, and calculate the height 841 of their widgets in orientation of the text. 842 843 \param options Options how to layout the legend 844 \param rect Bounding rectangle for title, footer, axes and canvas. 845 \param dimTitle Expanded height of the title widget 846 \param dimFooter Expanded height of the footer widget 847 \param dimAxes Expanded heights of the axis in axis orientation. 848 849 \sa Options 850 */ 851 void QwtPlotLayout::expandLineBreaks( Options options, const QRectF &rect, 852 int &dimTitle, int &dimFooter, int dimAxes[QwtPlot::axisCnt] ) const 853 { 854 dimTitle = dimFooter = 0; 855 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 856 dimAxes[axis] = 0; 857 858 int backboneOffset[QwtPlot::axisCnt]; 859 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 860 { 861 backboneOffset[axis] = 0; 862 if ( !( options & IgnoreFrames ) ) 863 backboneOffset[axis] += d_data->layoutData.canvas.contentsMargins[ axis ]; 864 865 if ( !d_data->alignCanvasToScales[axis] ) 866 backboneOffset[axis] += d_data->canvasMargin[axis]; 596 int LayoutEngine::heightForWidth( 597 LayoutData::Label labelType, const LayoutData& layoutData, 598 QwtPlotLayout::Options options, 599 double width, int axesWidth ) const 600 { 601 const LayoutData::LabelData& labelData = layoutData.labelData[ labelType ]; 602 603 if ( labelData.text.isEmpty() ) 604 return 0; 605 606 double w = width; 607 608 if ( !layoutData.hasSymmetricYAxes() ) 609 { 610 // center to the canvas 611 w -= axesWidth; 612 } 613 614 int d = qwtCeil( labelData.text.heightForWidth( w ) ); 615 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 616 d += 2 * labelData.frameWidth; 617 618 return d; 619 } 620 621 LayoutEngine::Dimensions LayoutEngine::layoutDimensions( QwtPlotLayout::Options options, 622 const LayoutData& layoutData, const QRectF& rect ) const 623 { 624 using namespace QwtAxis; 625 626 Dimensions dimensions; 627 628 int backboneOffset[AxisPositions]; 629 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 630 { 631 backboneOffset[axisPos] = 0; 632 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 633 backboneOffset[axisPos] += layoutData.canvasData.contentsMargins[axisPos]; 634 635 if ( !m_alignCanvas[axisPos] ) 636 backboneOffset[axisPos] += m_canvasMargin[axisPos]; 867 637 } 868 638 … … 880 650 // axis ... . So we loop as long until no size changes. 881 651 882 if ( !( ( options & IgnoreTitle ) || 883 d_data->layoutData.title.text.isEmpty() ) ) 884 { 885 double w = rect.width(); 886 887 if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled 888 != d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) 889 { 890 // center to the canvas 891 w -= dimAxes[QwtPlot::yLeft] + dimAxes[QwtPlot::yRight]; 892 } 893 894 int d = qCeil( d_data->layoutData.title.text.heightForWidth( w ) ); 895 if ( !( options & IgnoreFrames ) ) 896 d += 2 * d_data->layoutData.title.frameWidth; 897 898 if ( d > dimTitle ) 899 { 900 dimTitle = d; 652 if ( !( options & QwtPlotLayout::IgnoreTitle ) ) 653 { 654 const int d = heightForWidth( 655 LayoutData::Title, layoutData, options, 656 rect.width(), dimensions.dimYAxes() ); 657 658 if ( d > dimensions.dimTitle ) 659 { 660 dimensions.dimTitle = d; 901 661 done = false; 902 662 } 903 663 } 904 664 905 if ( !( ( options & IgnoreFooter ) || 906 d_data->layoutData.footer.text.isEmpty() ) ) 907 { 908 double w = rect.width(); 909 910 if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled 911 != d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) 912 { 913 // center to the canvas 914 w -= dimAxes[QwtPlot::yLeft] + dimAxes[QwtPlot::yRight]; 915 } 916 917 int d = qCeil( d_data->layoutData.footer.text.heightForWidth( w ) ); 918 if ( !( options & IgnoreFrames ) ) 919 d += 2 * d_data->layoutData.footer.frameWidth; 920 921 if ( d > dimFooter ) 922 { 923 dimFooter = d; 665 if ( !( options & QwtPlotLayout::IgnoreFooter ) ) 666 { 667 const int d = heightForWidth( 668 LayoutData::Footer, layoutData, options, 669 rect.width(), dimensions.dimYAxes() ); 670 671 if ( d > dimensions.dimFooter ) 672 { 673 dimensions.dimFooter = d; 924 674 done = false; 925 675 } 926 676 } 927 677 928 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 929 { 930 const struct LayoutData::t_scaleData &scaleData = 931 d_data->layoutData.scale[axis]; 932 933 if ( scaleData.isEnabled ) 934 { 935 double length; 936 if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) 937 { 938 length = rect.width() - dimAxes[QwtPlot::yLeft] 939 - dimAxes[QwtPlot::yRight]; 940 length -= scaleData.start + scaleData.end; 941 942 if ( dimAxes[QwtPlot::yRight] > 0 ) 678 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 679 { 680 { 681 const QwtAxisId axisId( axisPos ); 682 683 const LayoutData::ScaleData& scaleData = layoutData.axisData( axisId ); 684 685 if ( scaleData.isVisible ) 686 { 687 double length; 688 if ( isXAxis( axisPos ) ) 689 { 690 length = rect.width() - dimensions.dimYAxes(); 691 length -= scaleData.start + scaleData.end; 692 693 if ( dimensions.dimAxes( YRight ) > 0 ) 694 length -= 1; 695 696 length += qMin( dimensions.dimAxes( YLeft ), 697 scaleData.start - backboneOffset[YLeft] ); 698 699 length += qMin( dimensions.dimAxes( YRight ), 700 scaleData.end - backboneOffset[YRight] ); 701 } 702 else // y axis 703 { 704 length = rect.height() - dimensions.dimXAxes(); 705 length -= scaleData.start + scaleData.end; 943 706 length -= 1; 944 707 945 length += qMin( dimAxes[QwtPlot::yLeft], 946 scaleData.start - backboneOffset[QwtPlot::yLeft] ); 947 length += qMin( dimAxes[QwtPlot::yRight], 948 scaleData.end - backboneOffset[QwtPlot::yRight] ); 949 } 950 else // QwtPlot::yLeft, QwtPlot::yRight 951 { 952 length = rect.height() - dimAxes[QwtPlot::xTop] 953 - dimAxes[QwtPlot::xBottom]; 954 length -= scaleData.start + scaleData.end; 955 length -= 1; 956 957 if ( dimAxes[QwtPlot::xBottom] <= 0 ) 958 length -= 1; 959 if ( dimAxes[QwtPlot::xTop] <= 0 ) 960 length -= 1; 961 962 if ( dimAxes[QwtPlot::xBottom] > 0 ) 963 { 964 length += qMin( 965 d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, 966 double( scaleData.start - backboneOffset[QwtPlot::xBottom] ) ); 967 } 968 if ( dimAxes[QwtPlot::xTop] > 0 ) 969 { 970 length += qMin( 971 d_data->layoutData.scale[QwtPlot::xTop].tickOffset, 972 double( scaleData.end - backboneOffset[QwtPlot::xTop] ) ); 973 } 974 975 if ( dimTitle > 0 ) 976 length -= dimTitle + d_data->spacing; 977 } 978 979 int d = scaleData.dimWithoutTitle; 980 if ( !scaleData.scaleWidget->title().isEmpty() ) 981 { 982 d += scaleData.scaleWidget->titleHeightForWidth( qFloor( length ) ); 983 } 984 985 986 if ( d > dimAxes[axis] ) 987 { 988 dimAxes[axis] = d; 989 done = false; 990 } 991 } 992 } 993 } 994 } 995 996 /*! 997 Align the ticks of the axis to the canvas borders using 998 the empty corners. 999 1000 \param options Layout options 1001 \param canvasRect Geometry of the canvas ( IN/OUT ) 1002 \param scaleRect Geometries of the scales ( IN/OUT ) 1003 1004 \sa Options 1005 */ 1006 1007 void QwtPlotLayout::alignScales( Options options, 1008 QRectF &canvasRect, QRectF scaleRect[QwtPlot::axisCnt] ) const 1009 { 1010 int backboneOffset[QwtPlot::axisCnt]; 1011 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 1012 { 1013 backboneOffset[axis] = 0; 1014 1015 if ( !d_data->alignCanvasToScales[axis] ) 1016 { 1017 backboneOffset[axis] += d_data->canvasMargin[axis]; 1018 } 1019 1020 if ( !( options & IgnoreFrames ) ) 1021 { 1022 backboneOffset[axis] += 1023 d_data->layoutData.canvas.contentsMargins[axis]; 1024 } 1025 } 1026 1027 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 1028 { 1029 if ( !scaleRect[axis].isValid() ) 1030 continue; 1031 1032 const int startDist = d_data->layoutData.scale[axis].start; 1033 const int endDist = d_data->layoutData.scale[axis].end; 1034 1035 QRectF &axisRect = scaleRect[axis]; 1036 1037 if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) 1038 { 1039 const QRectF &leftScaleRect = scaleRect[QwtPlot::yLeft]; 1040 const int leftOffset = 1041 backboneOffset[QwtPlot::yLeft] - startDist; 1042 1043 if ( leftScaleRect.isValid() ) 1044 { 1045 const double dx = leftOffset + leftScaleRect.width(); 1046 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && dx < 0.0 ) 1047 { 1048 /* 1049 The axis needs more space than the width 1050 of the left scale. 1051 */ 1052 const double cLeft = canvasRect.left(); // qreal -> double 1053 canvasRect.setLeft( qMax( cLeft, axisRect.left() - dx ) ); 708 if ( dimensions.dimAxes( XBottom ) <= 0 ) 709 length -= 1; 710 711 if ( dimensions.dimAxes( XTop ) <= 0 ) 712 length -= 1; 713 714 /* 715 The tick labels of the y axes are always left/right from the 716 backbone/ticks of the x axes - but we have to take care, 717 that the labels don't overlap. 718 */ 719 if ( dimensions.dimAxes( XBottom ) > 0 ) 720 { 721 length += qMin( 722 layoutData.tickOffset( XBottom ), 723 double( scaleData.start - backboneOffset[XBottom] ) ); 724 } 725 726 if ( dimensions.dimAxes( XTop ) > 0 ) 727 { 728 length += qMin( 729 layoutData.tickOffset( XTop ), 730 double( scaleData.end - backboneOffset[XTop] ) ); 731 } 732 733 if ( dimensions.dimTitle > 0 ) 734 length -= dimensions.dimTitle + m_spacing; 735 } 736 737 int d = scaleData.dimWithoutTitle; 738 if ( !scaleData.scaleWidget->title().isEmpty() ) 739 { 740 d += scaleData.scaleWidget->titleHeightForWidth( qwtFloor( length ) ); 741 } 742 743 744 if ( d > dimensions.dimAxis( axisId ) ) 745 { 746 dimensions.setDimAxis( axisId, d ); 747 done = false; 748 } 749 } 750 } 751 } 752 } 753 754 return dimensions; 755 } 756 757 void LayoutEngine::alignScales( QwtPlotLayout::Options options, 758 const LayoutData& layoutData, QRectF& canvasRect, 759 QRectF scaleRect[QwtAxis::AxisPositions] ) const 760 { 761 using namespace QwtAxis; 762 763 int backboneOffset[AxisPositions]; 764 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 765 { 766 backboneOffset[axisPos] = 0; 767 768 if ( !m_alignCanvas[axisPos] ) 769 { 770 backboneOffset[axisPos] += m_canvasMargin[axisPos]; 771 } 772 773 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 774 { 775 backboneOffset[axisPos] += 776 layoutData.canvasData.contentsMargins[axisPos]; 777 } 778 } 779 780 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 781 { 782 { 783 QRectF& axisRect = scaleRect[axisPos]; 784 if ( !axisRect.isValid() ) 785 continue; 786 787 const QwtAxisId axisId( axisPos ); 788 789 const int startDist = layoutData.axisData( axisId ).start; 790 const int endDist = layoutData.axisData( axisId ).end; 791 792 if ( isXAxis( axisPos ) ) 793 { 794 const QRectF& leftScaleRect = scaleRect[YLeft]; 795 const int leftOffset = backboneOffset[YLeft] - startDist; 796 797 if ( leftScaleRect.isValid() ) 798 { 799 const double dx = leftOffset + leftScaleRect.width(); 800 if ( m_alignCanvas[YLeft] && dx < 0.0 ) 801 { 802 /* 803 The axis needs more space than the width 804 of the left scale. 805 */ 806 const double cLeft = canvasRect.left(); // qreal -> double 807 canvasRect.setLeft( qwtMaxF( cLeft, axisRect.left() - dx ) ); 808 } 809 else 810 { 811 const double minLeft = leftScaleRect.left(); 812 const double left = axisRect.left() + leftOffset; 813 axisRect.setLeft( qwtMaxF( left, minLeft ) ); 814 } 1054 815 } 1055 816 else 1056 817 { 1057 const double minLeft = leftScaleRect.left(); 1058 const double left = axisRect.left() + leftOffset; 1059 axisRect.setLeft( qMax( left, minLeft ) ); 818 if ( m_alignCanvas[YLeft] && leftOffset < 0 ) 819 { 820 canvasRect.setLeft( qwtMaxF( canvasRect.left(), 821 axisRect.left() - leftOffset ) ); 822 } 823 else 824 { 825 if ( leftOffset > 0 ) 826 axisRect.setLeft( axisRect.left() + leftOffset ); 827 } 828 } 829 830 const QRectF& rightScaleRect = scaleRect[YRight]; 831 const int rightOffset = backboneOffset[YRight] - endDist + 1; 832 833 if ( rightScaleRect.isValid() ) 834 { 835 const double dx = rightOffset + rightScaleRect.width(); 836 if ( m_alignCanvas[YRight] && dx < 0 ) 837 { 838 /* 839 The axis needs more space than the width 840 of the right scale. 841 */ 842 const double cRight = canvasRect.right(); // qreal -> double 843 canvasRect.setRight( qwtMinF( cRight, axisRect.right() + dx ) ); 844 } 845 846 const double maxRight = rightScaleRect.right(); 847 const double right = axisRect.right() - rightOffset; 848 axisRect.setRight( qwtMinF( right, maxRight ) ); 849 } 850 else 851 { 852 if ( m_alignCanvas[YRight] && rightOffset < 0 ) 853 { 854 canvasRect.setRight( qwtMinF( canvasRect.right(), 855 axisRect.right() + rightOffset ) ); 856 } 857 else 858 { 859 if ( rightOffset > 0 ) 860 axisRect.setRight( axisRect.right() - rightOffset ); 861 } 862 } 863 } 864 else // y axes 865 { 866 const QRectF& bottomScaleRect = scaleRect[XBottom]; 867 const int bottomOffset = backboneOffset[XBottom] - endDist + 1; 868 869 if ( bottomScaleRect.isValid() ) 870 { 871 const double dy = bottomOffset + bottomScaleRect.height(); 872 if ( m_alignCanvas[XBottom] && dy < 0 ) 873 { 874 /* 875 The axis needs more space than the height 876 of the bottom scale. 877 */ 878 const double cBottom = canvasRect.bottom(); // qreal -> double 879 canvasRect.setBottom( qwtMinF( cBottom, axisRect.bottom() + dy ) ); 880 } 881 else 882 { 883 const double maxBottom = bottomScaleRect.top() + 884 layoutData.tickOffset( XBottom ); 885 const double bottom = axisRect.bottom() - bottomOffset; 886 axisRect.setBottom( qwtMinF( bottom, maxBottom ) ); 887 } 888 } 889 else 890 { 891 if ( m_alignCanvas[XBottom] && bottomOffset < 0 ) 892 { 893 canvasRect.setBottom( qwtMinF( canvasRect.bottom(), 894 axisRect.bottom() + bottomOffset ) ); 895 } 896 else 897 { 898 if ( bottomOffset > 0 ) 899 axisRect.setBottom( axisRect.bottom() - bottomOffset ); 900 } 901 } 902 903 const QRectF& topScaleRect = scaleRect[XTop]; 904 const int topOffset = backboneOffset[XTop] - startDist; 905 906 if ( topScaleRect.isValid() ) 907 { 908 const double dy = topOffset + topScaleRect.height(); 909 if ( m_alignCanvas[XTop] && dy < 0 ) 910 { 911 /* 912 The axis needs more space than the height 913 of the top scale. 914 */ 915 const double cTop = canvasRect.top(); // qreal -> double 916 canvasRect.setTop( qwtMaxF( cTop, axisRect.top() - dy ) ); 917 } 918 else 919 { 920 const double minTop = topScaleRect.bottom() - 921 layoutData.tickOffset( XTop ); 922 923 const double top = axisRect.top() + topOffset; 924 axisRect.setTop( qwtMaxF( top, minTop ) ); 925 } 926 } 927 else 928 { 929 if ( m_alignCanvas[XTop] && topOffset < 0 ) 930 { 931 canvasRect.setTop( qwtMaxF( canvasRect.top(), 932 axisRect.top() - topOffset ) ); 933 } 934 else 935 { 936 if ( topOffset > 0 ) 937 axisRect.setTop( axisRect.top() + topOffset ); 938 } 939 } 940 } 941 } 942 } 943 944 /* 945 The canvas has been aligned to the scale with largest 946 border distances. Now we have to realign the other scale. 947 */ 948 949 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 950 { 951 { 952 const QwtAxisId axisId( axisPos ); 953 954 QRectF& sRect = scaleRect[axisPos]; 955 const LayoutData::ScaleData& axisData = layoutData.axisData( axisId ); 956 957 if ( !sRect.isValid() ) 958 continue; 959 960 if ( isXAxis( axisPos ) ) 961 { 962 if ( m_alignCanvas[YLeft] ) 963 { 964 double y = canvasRect.left() - axisData.start; 965 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 966 y += layoutData.canvasData.contentsMargins[YLeft]; 967 968 sRect.setLeft( y ); 969 } 970 971 if ( m_alignCanvas[YRight] ) 972 { 973 double y = canvasRect.right() - 1 + axisData.end; 974 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 975 y -= layoutData.canvasData.contentsMargins[YRight]; 976 977 sRect.setRight( y ); 978 } 979 980 if ( m_alignCanvas[axisPos] ) 981 { 982 if ( axisPos == XTop ) 983 sRect.setBottom( canvasRect.top() ); 984 else 985 sRect.setTop( canvasRect.bottom() ); 1060 986 } 1061 987 } 1062 988 else 1063 989 { 1064 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && leftOffset < 0 ) 1065 { 1066 canvasRect.setLeft( qMax( canvasRect.left(), 1067 axisRect.left() - leftOffset ) ); 1068 } 1069 else 1070 { 1071 if ( leftOffset > 0 ) 1072 axisRect.setLeft( axisRect.left() + leftOffset ); 1073 } 1074 } 1075 1076 const QRectF &rightScaleRect = scaleRect[QwtPlot::yRight]; 1077 const int rightOffset = 1078 backboneOffset[QwtPlot::yRight] - endDist + 1; 1079 1080 if ( rightScaleRect.isValid() ) 1081 { 1082 const double dx = rightOffset + rightScaleRect.width(); 1083 if ( d_data->alignCanvasToScales[QwtPlot::yRight] && dx < 0 ) 1084 { 1085 /* 1086 The axis needs more space than the width 1087 of the right scale. 1088 */ 1089 const double cRight = canvasRect.right(); // qreal -> double 1090 canvasRect.setRight( qMin( cRight, axisRect.right() + dx ) ); 1091 } 1092 1093 const double maxRight = rightScaleRect.right(); 1094 const double right = axisRect.right() - rightOffset; 1095 axisRect.setRight( qMin( right, maxRight ) ); 1096 } 1097 else 1098 { 1099 if ( d_data->alignCanvasToScales[QwtPlot::yRight] && rightOffset < 0 ) 1100 { 1101 canvasRect.setRight( qMin( canvasRect.right(), 1102 axisRect.right() + rightOffset ) ); 1103 } 1104 else 1105 { 1106 if ( rightOffset > 0 ) 1107 axisRect.setRight( axisRect.right() - rightOffset ); 1108 } 1109 } 1110 } 1111 else // QwtPlot::yLeft, QwtPlot::yRight 1112 { 1113 const QRectF &bottomScaleRect = scaleRect[QwtPlot::xBottom]; 1114 const int bottomOffset = 1115 backboneOffset[QwtPlot::xBottom] - endDist + 1; 1116 1117 if ( bottomScaleRect.isValid() ) 1118 { 1119 const double dy = bottomOffset + bottomScaleRect.height(); 1120 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && dy < 0 ) 1121 { 1122 /* 1123 The axis needs more space than the height 1124 of the bottom scale. 1125 */ 1126 const double cBottom = canvasRect.bottom(); // qreal -> double 1127 canvasRect.setBottom( qMin( cBottom, axisRect.bottom() + dy ) ); 1128 } 1129 else 1130 { 1131 const double maxBottom = bottomScaleRect.top() + 1132 d_data->layoutData.scale[QwtPlot::xBottom].tickOffset; 1133 const double bottom = axisRect.bottom() - bottomOffset; 1134 axisRect.setBottom( qMin( bottom, maxBottom ) ); 1135 } 1136 } 1137 else 1138 { 1139 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && bottomOffset < 0 ) 1140 { 1141 canvasRect.setBottom( qMin( canvasRect.bottom(), 1142 axisRect.bottom() + bottomOffset ) ); 1143 } 1144 else 1145 { 1146 if ( bottomOffset > 0 ) 1147 axisRect.setBottom( axisRect.bottom() - bottomOffset ); 1148 } 1149 } 1150 1151 const QRectF &topScaleRect = scaleRect[QwtPlot::xTop]; 1152 const int topOffset = backboneOffset[QwtPlot::xTop] - startDist; 1153 1154 if ( topScaleRect.isValid() ) 1155 { 1156 const double dy = topOffset + topScaleRect.height(); 1157 if ( d_data->alignCanvasToScales[QwtPlot::xTop] && dy < 0 ) 1158 { 1159 /* 1160 The axis needs more space than the height 1161 of the top scale. 1162 */ 1163 const double cTop = canvasRect.top(); // qreal -> double 1164 canvasRect.setTop( qMax( cTop, axisRect.top() - dy ) ); 1165 } 1166 else 1167 { 1168 const double minTop = topScaleRect.bottom() - 1169 d_data->layoutData.scale[QwtPlot::xTop].tickOffset; 1170 const double top = axisRect.top() + topOffset; 1171 axisRect.setTop( qMax( top, minTop ) ); 1172 } 1173 } 1174 else 1175 { 1176 if ( d_data->alignCanvasToScales[QwtPlot::xTop] && topOffset < 0 ) 1177 { 1178 canvasRect.setTop( qMax( canvasRect.top(), 1179 axisRect.top() - topOffset ) ); 1180 } 1181 else 1182 { 1183 if ( topOffset > 0 ) 1184 axisRect.setTop( axisRect.top() + topOffset ); 1185 } 1186 } 1187 } 1188 } 1189 1190 /* 1191 The canvas has been aligned to the scale with largest 1192 border distances. Now we have to realign the other scale. 1193 */ 1194 1195 1196 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 1197 { 1198 QRectF &sRect = scaleRect[axis]; 1199 1200 if ( !sRect.isValid() ) 1201 continue; 1202 1203 if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) 1204 { 1205 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] ) 1206 { 1207 double y = canvasRect.left() - d_data->layoutData.scale[axis].start; 1208 if ( !( options & IgnoreFrames ) ) 1209 y += d_data->layoutData.canvas.contentsMargins[ QwtPlot::yLeft ]; 1210 1211 sRect.setLeft( y ); 1212 } 1213 if ( d_data->alignCanvasToScales[QwtPlot::yRight] ) 1214 { 1215 double y = canvasRect.right() - 1 + d_data->layoutData.scale[axis].end; 1216 if ( !( options & IgnoreFrames ) ) 1217 y -= d_data->layoutData.canvas.contentsMargins[ QwtPlot::yRight ]; 1218 1219 sRect.setRight( y ); 1220 } 1221 1222 if ( d_data->alignCanvasToScales[ axis ] ) 1223 { 1224 if ( axis == QwtPlot::xTop ) 1225 sRect.setBottom( canvasRect.top() ); 1226 else 1227 sRect.setTop( canvasRect.bottom() ); 1228 } 990 if ( m_alignCanvas[XTop] ) 991 { 992 double x = canvasRect.top() - axisData.start; 993 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 994 x += layoutData.canvasData.contentsMargins[XTop]; 995 996 sRect.setTop( x ); 997 } 998 999 if ( m_alignCanvas[XBottom] ) 1000 { 1001 double x = canvasRect.bottom() - 1 + axisData.end; 1002 if ( !( options & QwtPlotLayout::IgnoreFrames ) ) 1003 x -= layoutData.canvasData.contentsMargins[XBottom]; 1004 1005 sRect.setBottom( x ); 1006 } 1007 1008 if ( m_alignCanvas[axisPos] ) 1009 { 1010 if ( axisPos == YLeft ) 1011 sRect.setRight( canvasRect.left() ); 1012 else 1013 sRect.setLeft( canvasRect.right() ); 1014 } 1015 } 1016 } 1017 } 1018 } 1019 1020 class QwtPlotLayout::PrivateData 1021 { 1022 public: 1023 QRectF titleRect; 1024 QRectF footerRect; 1025 QRectF legendRect; 1026 QRectF scaleRects[QwtAxis::AxisPositions]; 1027 QRectF canvasRect; 1028 1029 LayoutEngine engine; 1030 }; 1031 1032 /*! 1033 \brief Constructor 1034 */ 1035 1036 QwtPlotLayout::QwtPlotLayout() 1037 { 1038 m_data = new PrivateData; 1039 1040 setLegendPosition( QwtPlot::BottomLegend ); 1041 setCanvasMargin( 4 ); 1042 setAlignCanvasToScales( false ); 1043 1044 invalidate(); 1045 } 1046 1047 //! Destructor 1048 QwtPlotLayout::~QwtPlotLayout() 1049 { 1050 delete m_data; 1051 } 1052 1053 /*! 1054 Change a margin of the canvas. The margin is the space 1055 above/below the scale ticks. A negative margin will 1056 be set to -1, excluding the borders of the scales. 1057 1058 \param margin New margin 1059 \param axisPos One of QwtAxis::Position. Specifies where the position of the margin. 1060 -1 means margin at all borders. 1061 \sa canvasMargin() 1062 1063 \warning The margin will have no effect when alignCanvasToScale() is true 1064 */ 1065 1066 void QwtPlotLayout::setCanvasMargin( int margin, int axisPos ) 1067 { 1068 if ( margin < -1 ) 1069 margin = -1; 1070 1071 LayoutEngine& engine = m_data->engine; 1072 1073 if ( axisPos == -1 ) 1074 { 1075 for ( axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 1076 engine.setCanvasMargin( axisPos, margin ); 1077 } 1078 else if ( QwtAxis::isValid( axisPos ) ) 1079 { 1080 engine.setCanvasMargin( axisPos, margin ); 1081 } 1082 } 1083 1084 /*! 1085 \param axisPos Axis position 1086 \return Margin around the scale tick borders 1087 \sa setCanvasMargin() 1088 */ 1089 int QwtPlotLayout::canvasMargin( int axisPos ) const 1090 { 1091 if ( !QwtAxis::isValid( axisPos ) ) 1092 return 0; 1093 1094 return m_data->engine.canvasMargin( axisPos ); 1095 } 1096 1097 /*! 1098 \brief Set the align-canvas-to-axis-scales flag for all axes 1099 1100 \param on True/False 1101 \sa setAlignCanvasToScale(), alignCanvasToScale() 1102 */ 1103 void QwtPlotLayout::setAlignCanvasToScales( bool on ) 1104 { 1105 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 1106 m_data->engine.setAlignCanvas( axisPos, on ); 1107 } 1108 1109 /*! 1110 Change the align-canvas-to-axis-scales setting. The canvas may: 1111 1112 - extend beyond the axis scale ends to maximize its size, 1113 - align with the axis scale ends to control its size. 1114 1115 The axisId parameter is somehow confusing as it identifies a border 1116 of the plot and not the axes, that are aligned. F.e when QwtAxis::YLeft 1117 is set, the left end of the the x-axes ( QwtAxis::XTop, QwtAxis::XBottom ) 1118 is aligned. 1119 1120 \param axisPos Axis position 1121 \param on New align-canvas-to-axis-scales setting 1122 1123 \sa setCanvasMargin(), alignCanvasToScale(), setAlignCanvasToScales() 1124 \warning In case of on == true canvasMargin() will have no effect 1125 */ 1126 void QwtPlotLayout::setAlignCanvasToScale( int axisPos, bool on ) 1127 { 1128 if ( QwtAxis::isValid( axisPos ) ) 1129 m_data->engine.setAlignCanvas( axisPos, on ); 1130 } 1131 1132 /*! 1133 Return the align-canvas-to-axis-scales setting. The canvas may: 1134 - extend beyond the axis scale ends to maximize its size 1135 - align with the axis scale ends to control its size. 1136 1137 \param axisPos Axis position 1138 \return align-canvas-to-axis-scales setting 1139 \sa setAlignCanvasToScale(), setAlignCanvasToScale(), setCanvasMargin() 1140 */ 1141 bool QwtPlotLayout::alignCanvasToScale( int axisPos ) const 1142 { 1143 if ( !QwtAxis::isValid( axisPos ) ) 1144 return false; 1145 1146 return m_data->engine.alignCanvas( axisPos ); 1147 } 1148 1149 /*! 1150 Change the spacing of the plot. The spacing is the distance 1151 between the plot components. 1152 1153 \param spacing New spacing 1154 \sa setCanvasMargin(), spacing() 1155 */ 1156 void QwtPlotLayout::setSpacing( int spacing ) 1157 { 1158 m_data->engine.setSpacing( qMax( 0, spacing ) ); 1159 } 1160 1161 /*! 1162 \return Spacing 1163 \sa margin(), setSpacing() 1164 */ 1165 int QwtPlotLayout::spacing() const 1166 { 1167 return m_data->engine.spacing(); 1168 } 1169 1170 /*! 1171 \brief Specify the position of the legend 1172 \param pos The legend's position. 1173 \param ratio Ratio between legend and the bounding rectangle 1174 of title, footer, canvas and axes. The legend will be shrunk 1175 if it would need more space than the given ratio. 1176 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 1177 it will be reset to the default ratio. 1178 The default vertical/horizontal ratio is 0.33/0.5. 1179 1180 \sa QwtPlot::setLegendPosition() 1181 */ 1182 1183 void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos, double ratio ) 1184 { 1185 if ( ratio > 1.0 ) 1186 ratio = 1.0; 1187 1188 LayoutEngine& engine = m_data->engine; 1189 1190 switch ( pos ) 1191 { 1192 case QwtPlot::TopLegend: 1193 case QwtPlot::BottomLegend: 1194 { 1195 if ( ratio <= 0.0 ) 1196 ratio = 0.33; 1197 1198 engine.setLegendRatio( ratio ); 1199 engine.setLegendPos( pos ); 1200 1201 break; 1202 } 1203 case QwtPlot::LeftLegend: 1204 case QwtPlot::RightLegend: 1205 { 1206 if ( ratio <= 0.0 ) 1207 ratio = 0.5; 1208 1209 engine.setLegendRatio( ratio ); 1210 engine.setLegendPos( pos ); 1211 1212 break; 1213 } 1214 default: 1215 break; 1216 } 1217 } 1218 1219 /*! 1220 \brief Specify the position of the legend 1221 \param pos The legend's position. Valid values are 1222 \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend, 1223 \c QwtPlot::TopLegend, \c QwtPlot::BottomLegend. 1224 1225 \sa QwtPlot::setLegendPosition() 1226 */ 1227 void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos ) 1228 { 1229 setLegendPosition( pos, 0.0 ); 1230 } 1231 1232 /*! 1233 \return Position of the legend 1234 \sa setLegendPosition(), QwtPlot::setLegendPosition(), 1235 QwtPlot::legendPosition() 1236 */ 1237 QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const 1238 { 1239 return m_data->engine.legendPos(); 1240 } 1241 1242 /*! 1243 Specify the relative size of the legend in the plot 1244 \param ratio Ratio between legend and the bounding rectangle 1245 of title, footer, canvas and axes. The legend will be shrunk 1246 if it would need more space than the given ratio. 1247 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 1248 it will be reset to the default ratio. 1249 The default vertical/horizontal ratio is 0.33/0.5. 1250 */ 1251 void QwtPlotLayout::setLegendRatio( double ratio ) 1252 { 1253 setLegendPosition( legendPosition(), ratio ); 1254 } 1255 1256 /*! 1257 \return The relative size of the legend in the plot. 1258 \sa setLegendPosition() 1259 */ 1260 double QwtPlotLayout::legendRatio() const 1261 { 1262 return m_data->engine.legendRatio(); 1263 } 1264 1265 /*! 1266 \brief Set the geometry for the title 1267 1268 This method is intended to be used from derived layouts 1269 overloading activate() 1270 1271 \sa titleRect(), activate() 1272 */ 1273 void QwtPlotLayout::setTitleRect( const QRectF& rect ) 1274 { 1275 m_data->titleRect = rect; 1276 } 1277 1278 /*! 1279 \return Geometry for the title 1280 \sa activate(), invalidate() 1281 */ 1282 QRectF QwtPlotLayout::titleRect() const 1283 { 1284 return m_data->titleRect; 1285 } 1286 1287 /*! 1288 \brief Set the geometry for the footer 1289 1290 This method is intended to be used from derived layouts 1291 overloading activate() 1292 1293 \sa footerRect(), activate() 1294 */ 1295 void QwtPlotLayout::setFooterRect( const QRectF& rect ) 1296 { 1297 m_data->footerRect = rect; 1298 } 1299 1300 /*! 1301 \return Geometry for the footer 1302 \sa activate(), invalidate() 1303 */ 1304 QRectF QwtPlotLayout::footerRect() const 1305 { 1306 return m_data->footerRect; 1307 } 1308 1309 /*! 1310 \brief Set the geometry for the legend 1311 1312 This method is intended to be used from derived layouts 1313 overloading activate() 1314 1315 \param rect Rectangle for the legend 1316 1317 \sa legendRect(), activate() 1318 */ 1319 void QwtPlotLayout::setLegendRect( const QRectF& rect ) 1320 { 1321 m_data->legendRect = rect; 1322 } 1323 1324 /*! 1325 \return Geometry for the legend 1326 \sa activate(), invalidate() 1327 */ 1328 QRectF QwtPlotLayout::legendRect() const 1329 { 1330 return m_data->legendRect; 1331 } 1332 1333 /*! 1334 \brief Set the geometry for an axis 1335 1336 This method is intended to be used from derived layouts 1337 overloading activate() 1338 1339 \param axisId Axis 1340 \param rect Rectangle for the scale 1341 1342 \sa scaleRect(), activate() 1343 */ 1344 void QwtPlotLayout::setScaleRect( QwtAxisId axisId, const QRectF& rect ) 1345 { 1346 if ( QwtAxis::isValid( axisId ) ) 1347 m_data->scaleRects[axisId] = rect; 1348 } 1349 1350 /*! 1351 \param axisId Axis 1352 \return Geometry for the scale 1353 \sa activate(), invalidate() 1354 */ 1355 QRectF QwtPlotLayout::scaleRect( QwtAxisId axisId ) const 1356 { 1357 if ( QwtAxis::isValid( axisId ) ) 1358 return m_data->scaleRects[axisId]; 1359 1360 return QRectF(); 1361 } 1362 1363 /*! 1364 \brief Set the geometry for the canvas 1365 1366 This method is intended to be used from derived layouts 1367 overloading activate() 1368 1369 \sa canvasRect(), activate() 1370 */ 1371 void QwtPlotLayout::setCanvasRect( const QRectF& rect ) 1372 { 1373 m_data->canvasRect = rect; 1374 } 1375 1376 /*! 1377 \return Geometry for the canvas 1378 \sa activate(), invalidate() 1379 */ 1380 QRectF QwtPlotLayout::canvasRect() const 1381 { 1382 return m_data->canvasRect; 1383 } 1384 1385 /*! 1386 Invalidate the geometry of all components. 1387 \sa activate() 1388 */ 1389 void QwtPlotLayout::invalidate() 1390 { 1391 m_data->titleRect = m_data->footerRect = 1392 m_data->legendRect = m_data->canvasRect = QRectF(); 1393 1394 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 1395 m_data->scaleRects[axisPos] = QRect(); 1396 } 1397 1398 /*! 1399 \return Minimum size hint 1400 \param plot Plot widget 1401 1402 \sa QwtPlot::minimumSizeHint() 1403 */ 1404 QSize QwtPlotLayout::minimumSizeHint( const QwtPlot* plot ) const 1405 { 1406 LayoutHintData hintData( plot ); 1407 1408 const int xAxesWidth = hintData.xAxesWidth(); 1409 const int yAxesHeight = hintData.yAxesHeight(); 1410 1411 const QWidget* canvas = plot->canvas(); 1412 1413 const QMargins m = canvas->contentsMargins(); 1414 const QSize minCanvasSize = canvas->minimumSize(); 1415 1416 int w = hintData.yAxesWidth(); 1417 int cw = xAxesWidth + m.left() + 1 + m.right() + 1; 1418 w += qMax( cw, minCanvasSize.width() ); 1419 1420 int h = hintData.xAxesHeight(); 1421 int ch = yAxesHeight + m.top() + 1 + m.bottom() + 1; 1422 h += qMax( ch, minCanvasSize.height() ); 1423 1424 const QwtTextLabel* labels[2]; 1425 labels[0] = plot->titleLabel(); 1426 labels[1] = plot->footerLabel(); 1427 1428 for ( int i = 0; i < 2; i++ ) 1429 { 1430 const QwtTextLabel* label = labels[i]; 1431 if ( label && !label->text().isEmpty() ) 1432 { 1433 // we center on the plot canvas. 1434 const bool centerOnCanvas = !( plot->isAxisVisible( QwtAxis::YLeft ) 1435 && plot->isAxisVisible( QwtAxis::YRight ) ); 1436 1437 int labelW = w; 1438 if ( centerOnCanvas ) 1439 { 1440 labelW -= hintData.yAxesWidth(); 1441 } 1442 1443 int labelH = label->heightForWidth( labelW ); 1444 if ( labelH > labelW ) // Compensate for a long title 1445 { 1446 w = labelW = labelH; 1447 if ( centerOnCanvas ) 1448 w += hintData.yAxesWidth(); 1449 1450 labelH = label->heightForWidth( labelW ); 1451 } 1452 h += labelH + spacing(); 1453 } 1454 } 1455 1456 // Compute the legend contribution 1457 1458 const QwtAbstractLegend* legend = plot->legend(); 1459 if ( legend && !legend->isEmpty() ) 1460 { 1461 const LayoutEngine& engine = m_data->engine; 1462 1463 if ( engine.legendPos() == QwtPlot::LeftLegend 1464 || engine.legendPos() == QwtPlot::RightLegend ) 1465 { 1466 int legendW = legend->sizeHint().width(); 1467 int legendH = legend->heightForWidth( legendW ); 1468 1469 if ( legend->frameWidth() > 0 ) 1470 w += spacing(); 1471 1472 if ( legendH > h ) 1473 legendW += legend->scrollExtent( Qt::Horizontal ); 1474 1475 if ( engine.legendRatio() < 1.0 ) 1476 legendW = qMin( legendW, int( w / ( 1.0 - engine.legendRatio() ) ) ); 1477 1478 w += legendW + spacing(); 1229 1479 } 1230 1480 else 1231 1481 { 1232 if ( d_data->alignCanvasToScales[QwtPlot::xTop] ) 1233 { 1234 double x = canvasRect.top() - d_data->layoutData.scale[axis].start; 1235 if ( !( options & IgnoreFrames ) ) 1236 x += d_data->layoutData.canvas.contentsMargins[ QwtPlot::xTop ]; 1237 1238 sRect.setTop( x ); 1239 } 1240 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] ) 1241 { 1242 double x = canvasRect.bottom() - 1 + d_data->layoutData.scale[axis].end; 1243 if ( !( options & IgnoreFrames ) ) 1244 x -= d_data->layoutData.canvas.contentsMargins[ QwtPlot::xBottom ]; 1245 1246 sRect.setBottom( x ); 1247 } 1248 1249 if ( d_data->alignCanvasToScales[ axis ] ) 1250 { 1251 if ( axis == QwtPlot::yLeft ) 1252 sRect.setRight( canvasRect.left() ); 1253 else 1254 sRect.setLeft( canvasRect.right() ); 1255 } 1256 } 1257 } 1258 } 1259 1260 /*! 1261 \brief Recalculate the geometry of all components. 1262 1263 \param plot Plot to be layout 1264 \param plotRect Rectangle where to place the components 1265 \param options Layout options 1266 1267 \sa invalidate(), titleRect(), footerRect() 1482 int legendW = qMin( legend->sizeHint().width(), w ); 1483 int legendH = legend->heightForWidth( legendW ); 1484 1485 if ( legend->frameWidth() > 0 ) 1486 h += spacing(); 1487 1488 if ( engine.legendRatio() < 1.0 ) 1489 legendH = qMin( legendH, int( h / ( 1.0 - engine.legendRatio() ) ) ); 1490 1491 h += legendH + spacing(); 1492 } 1493 } 1494 1495 return QSize( w, h ); 1496 } 1497 1498 /*! 1499 \brief Recalculate the geometry of all components. 1500 1501 \param plot Plot to be layout 1502 \param plotRect Rectangle where to place the components 1503 \param options Layout options 1504 1505 \sa invalidate(), titleRect(), footerRect() 1268 1506 legendRect(), scaleRect(), canvasRect() 1269 */ 1270 void QwtPlotLayout::activate( const QwtPlot *plot,1271 const QRectF &plotRect, Options options )1507 */ 1508 void QwtPlotLayout::activate( const QwtPlot* plot, 1509 const QRectF& plotRect, Options options ) 1272 1510 { 1273 1511 invalidate(); … … 1276 1514 1277 1515 // We extract all layout relevant parameters from the widgets, 1278 // and save them to d_data->layoutData. 1279 1280 d_data->layoutData.init( plot, rect ); 1516 // and save them to m_data->layoutData. 1517 1518 LayoutData layoutData( plot ); 1519 1520 QSize legendHint; 1281 1521 1282 1522 if ( !( options & IgnoreLegend ) 1283 1523 && plot->legend() && !plot->legend()->isEmpty() ) 1284 1524 { 1285 d_data->legendRect = layoutLegend( options, rect ); 1286 1287 // subtract d_data->legendRect from rect 1525 legendHint = layoutData.legendData.legendHint( plot->legend(), rect ); 1526 1527 m_data->legendRect = m_data->engine.layoutLegend( 1528 options, layoutData.legendData, rect, legendHint ); 1529 1530 // subtract m_data->legendRect from rect 1288 1531 1289 1532 const QRegion region( rect.toRect() ); 1290 rect = region.subtracted( d_data->legendRect.toRect() ).boundingRect();1291 1292 switch ( d_data->legendPos )1533 rect = region.subtracted( m_data->legendRect.toRect() ).boundingRect(); 1534 1535 switch ( m_data->engine.legendPos() ) 1293 1536 { 1294 1537 case QwtPlot::LeftLegend: 1295 rect.setLeft( rect.left() + d_data->spacing ); 1538 { 1539 rect.setLeft( rect.left() + spacing() ); 1296 1540 break; 1541 } 1297 1542 case QwtPlot::RightLegend: 1298 rect.setRight( rect.right() - d_data->spacing ); 1543 { 1544 rect.setRight( rect.right() - spacing() ); 1299 1545 break; 1546 } 1300 1547 case QwtPlot::TopLegend: 1301 rect.setTop( rect.top() + d_data->spacing ); 1548 { 1549 rect.setTop( rect.top() + spacing() ); 1302 1550 break; 1551 } 1303 1552 case QwtPlot::BottomLegend: 1304 rect.setBottom( rect.bottom() - d_data->spacing ); 1553 { 1554 rect.setBottom( rect.bottom() - spacing() ); 1305 1555 break; 1556 } 1306 1557 } 1307 1558 } … … 1322 1573 | Footer | 1323 1574 +---+-----------+---+ 1324 */ 1575 */ 1325 1576 1326 1577 // title, footer and axes include text labels. The height of each … … 1328 1579 // for the label. A line break in a horizontal text will reduce 1329 1580 // the available width for vertical texts and vice versa. 1330 // expandLineBreaks finds the height/width for title, footer and axes1581 // layoutDimensions finds the height/width for title, footer and axes 1331 1582 // including all line breaks. 1332 1583 1333 int dimTitle, dimFooter, dimAxes[QwtPlot::axisCnt]; 1334 expandLineBreaks( options, rect, dimTitle, dimFooter, dimAxes ); 1335 1336 if ( dimTitle > 0 ) 1337 { 1338 d_data->titleRect.setRect( 1339 rect.left(), rect.top(), rect.width(), dimTitle ); 1340 1341 rect.setTop( d_data->titleRect.bottom() + d_data->spacing ); 1342 1343 if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != 1344 d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) 1584 using namespace QwtAxis; 1585 1586 const LayoutEngine::Dimensions dimensions = 1587 m_data->engine.layoutDimensions( options, layoutData, rect ); 1588 1589 if ( dimensions.dimTitle > 0 ) 1590 { 1591 QRectF& labelRect = m_data->titleRect; 1592 1593 labelRect.setRect( rect.left(), rect.top(), rect.width(), dimensions.dimTitle ); 1594 1595 rect.setTop( labelRect.bottom() + spacing() ); 1596 1597 if ( !layoutData.hasSymmetricYAxes() ) 1345 1598 { 1346 1599 // if only one of the y axes is missing we align 1347 1600 // the title centered to the canvas 1348 1601 1349 d_data->titleRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] ); 1350 d_data->titleRect.setWidth( rect.width() 1351 - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] ); 1352 } 1353 } 1354 1355 if ( dimFooter > 0 ) 1356 { 1357 d_data->footerRect.setRect( 1358 rect.left(), rect.bottom() - dimFooter, rect.width(), dimFooter ); 1359 1360 rect.setBottom( d_data->footerRect.top() - d_data->spacing ); 1361 1362 if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != 1363 d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) 1602 labelRect = dimensions.centered( rect, labelRect ); 1603 } 1604 } 1605 1606 if ( dimensions.dimFooter > 0 ) 1607 { 1608 QRectF& labelRect = m_data->footerRect; 1609 1610 labelRect.setRect( rect.left(), rect.bottom() - dimensions.dimFooter, 1611 rect.width(), dimensions.dimFooter ); 1612 1613 rect.setBottom( labelRect.top() - spacing() ); 1614 1615 if ( !layoutData.hasSymmetricYAxes() ) 1364 1616 { 1365 1617 // if only one of the y axes is missing we align 1366 1618 // the footer centered to the canvas 1367 1619 1368 d_data->footerRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] ); 1369 d_data->footerRect.setWidth( rect.width() 1370 - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] ); 1371 } 1372 } 1373 1374 d_data->canvasRect.setRect( 1375 rect.x() + dimAxes[QwtPlot::yLeft], 1376 rect.y() + dimAxes[QwtPlot::xTop], 1377 rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft], 1378 rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop] ); 1379 1380 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 1620 labelRect = dimensions.centered( rect, labelRect ); 1621 } 1622 } 1623 1624 m_data->canvasRect = dimensions.innerRect( rect ); 1625 1626 for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ ) 1381 1627 { 1382 1628 // set the rects for the axes 1383 1629 1384 if ( dimAxes[axis] ) 1385 { 1386 int dim = dimAxes[axis]; 1387 QRectF &scaleRect = d_data->scaleRect[axis]; 1388 1389 scaleRect = d_data->canvasRect; 1390 switch ( axis ) 1391 { 1392 case QwtPlot::yLeft: 1393 scaleRect.setX( d_data->canvasRect.left() - dim ); 1394 scaleRect.setWidth( dim ); 1395 break; 1396 case QwtPlot::yRight: 1397 scaleRect.setX( d_data->canvasRect.right() ); 1398 scaleRect.setWidth( dim ); 1399 break; 1400 case QwtPlot::xBottom: 1401 scaleRect.setY( d_data->canvasRect.bottom() ); 1402 scaleRect.setHeight( dim ); 1403 break; 1404 case QwtPlot::xTop: 1405 scaleRect.setY( d_data->canvasRect.top() - dim ); 1406 scaleRect.setHeight( dim ); 1407 break; 1408 } 1409 scaleRect = scaleRect.normalized(); 1630 const int pos = 0; 1631 { 1632 const QwtAxisId axisId( axisPos ); 1633 1634 if ( dimensions.dimAxis( axisId ) ) 1635 { 1636 const int dim = dimensions.dimAxis( axisId ); 1637 1638 const QRectF& canvasRect = m_data->canvasRect; 1639 1640 QRectF& scaleRect = m_data->scaleRects[axisId]; 1641 scaleRect = canvasRect; 1642 1643 switch ( axisPos ) 1644 { 1645 case YLeft: 1646 { 1647 scaleRect.setX( canvasRect.left() - pos - dim ); 1648 scaleRect.setWidth( dim ); 1649 break; 1650 } 1651 case YRight: 1652 { 1653 scaleRect.setX( canvasRect.right() + pos ); 1654 scaleRect.setWidth( dim ); 1655 break; 1656 } 1657 case XBottom: 1658 { 1659 scaleRect.setY( canvasRect.bottom() + pos ); 1660 scaleRect.setHeight( dim ); 1661 break; 1662 } 1663 case XTop: 1664 { 1665 scaleRect.setY( canvasRect.top() - pos - dim ); 1666 scaleRect.setHeight( dim ); 1667 break; 1668 } 1669 } 1670 scaleRect = scaleRect.normalized(); 1671 } 1410 1672 } 1411 1673 } … … 1431 1693 // left/right of the min/max ticks are moved into them. 1432 1694 1433 alignScales( options, d_data->canvasRect, d_data->scaleRect ); 1434 1435 if ( !d_data->legendRect.isEmpty() ) 1695 m_data->engine.alignScales( options, layoutData, 1696 m_data->canvasRect, m_data->scaleRects ); 1697 1698 if ( !m_data->legendRect.isEmpty() ) 1436 1699 { 1437 1700 // We prefer to align the legend to the canvas - not to 1438 1701 // the complete plot - if possible. 1439 1702 1440 d_data->legendRect = alignLegend( d_data->canvasRect, d_data->legendRect ); 1441 } 1442 } 1703 m_data->legendRect = m_data->engine.alignLegend( 1704 legendHint, m_data->canvasRect, m_data->legendRect ); 1705 } 1706 } -
trunk/BNC/qwt/qwt_plot_layout.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot.h" 15 #include "qwt_axis_id.h" 15 16 16 17 /*! 17 \brief Layout engine for QwtPlot. 18 \brief Layout engine for QwtPlot. 18 19 19 It is used by the QwtPlot widget to organize its internal widgets 20 or by QwtPlot::print() to render its content to a QPaintDevice like 21 a QPrinter, QPixmap/QImage or QSvgRenderer. 20 It is used by the QwtPlot widget to organize its internal widgets 21 or by QwtPlot::print() to render its content to a QPaintDevice like 22 a QPrinter, QPixmap/QImage or QSvgRenderer. 22 23 23 \sa QwtPlot::setPlotLayout() 24 */ 24 \sa QwtPlot::setPlotLayout() 25 */ 25 26 26 27 class QWT_EXPORT QwtPlotLayout 27 28 { 28 public: 29 public: 29 30 /*! 30 Options to configure the plot layout engine 31 \sa activate(), QwtPlotRenderer 31 Options to configure the plot layout engine 32 \sa activate(), QwtPlotRenderer 32 33 */ 33 34 enum Option … … 37 38 38 39 /*! 39 Ignore the dimension of the scrollbars. There are no 40 scrollbars, when the plot is not rendered to widgets. 40 Ignore the dimension of the scrollbars. There are no 41 scrollbars, when the plot is not rendered to widgets. 41 42 */ 42 43 IgnoreScrollbars = 0x02, … … 55 56 }; 56 57 57 //! Layout options 58 typedef QFlags<Option> Options; 58 Q_DECLARE_FLAGS( Options, Option ) 59 59 60 60 explicit QwtPlotLayout(); … … 79 79 double legendRatio() const; 80 80 81 virtual QSize minimumSizeHint( const QwtPlot * ) const;81 virtual QSize minimumSizeHint( const QwtPlot* ) const; 82 82 83 virtual void activate( const QwtPlot *,84 const QRectF &plotRect, Options options = Options() );83 virtual void activate( const QwtPlot*, 84 const QRectF& plotRect, Options options = Options() ); 85 85 86 86 virtual void invalidate(); … … 89 89 QRectF footerRect() const; 90 90 QRectF legendRect() const; 91 QRectF scaleRect( int axis) const;91 QRectF scaleRect( QwtAxisId ) const; 92 92 QRectF canvasRect() const; 93 93 94 class LayoutData;94 protected: 95 95 96 protected: 96 void setTitleRect( const QRectF& ); 97 void setFooterRect( const QRectF& ); 98 void setLegendRect( const QRectF& ); 99 void setScaleRect( QwtAxisId, const QRectF& ); 100 void setCanvasRect( const QRectF& ); 97 101 98 void setTitleRect( const QRectF & ); 99 void setFooterRect( const QRectF & ); 100 void setLegendRect( const QRectF & ); 101 void setScaleRect( int axis, const QRectF & ); 102 void setCanvasRect( const QRectF & ); 102 private: 103 Q_DISABLE_COPY(QwtPlotLayout) 103 104 104 QRectF layoutLegend( Options options, const QRectF & ) const;105 QRectF alignLegend( const QRectF &canvasRect,106 const QRectF &legendRect ) const;107 108 void expandLineBreaks( Options options, const QRectF &rect,109 int &dimTitle, int &dimFooter, int dimAxes[QwtPlot::axisCnt] ) const;110 111 void alignScales( Options options, QRectF &canvasRect,112 QRectF scaleRect[QwtPlot::axisCnt] ) const;113 114 private:115 105 class PrivateData; 116 117 PrivateData *d_data; 106 PrivateData* m_data; 118 107 }; 119 108 -
trunk/BNC/qwt/qwt_plot_legenditem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_legenditem.h" 11 11 #include "qwt_dyngrid_layout.h" 12 #include "qwt_scale_map.h" 13 #include "qwt_painter.h" 12 #include "qwt_text.h" 13 #include "qwt_graphic.h" 14 #include "qwt_legend_data.h" 15 #include "qwt_math.h" 16 14 17 #include <qlayoutitem.h> 15 18 #include <qpen.h> 16 19 #include <qbrush.h> 17 20 #include <qpainter.h> 18 #include <qmath.h> 19 20 class QwtLegendLayoutItem: public QLayoutItem 21 { 22 public: 23 QwtLegendLayoutItem( const QwtPlotLegendItem *, const QwtPlotItem * ); 24 virtual ~QwtLegendLayoutItem(); 25 26 const QwtPlotItem *plotItem() const; 27 28 void setData( const QwtLegendData & ); 29 const QwtLegendData &data() const; 30 31 virtual Qt::Orientations expandingDirections() const; 32 virtual QRect geometry() const; 33 virtual bool hasHeightForWidth() const; 34 virtual int heightForWidth( int w ) const; 35 virtual bool isEmpty() const; 36 virtual QSize maximumSize() const; 37 virtual int minimumHeightForWidth( int w ) const; 38 virtual QSize minimumSize() const; 39 virtual void setGeometry( const QRect & r ); 40 virtual QSize sizeHint() const; 41 42 private: 43 44 const QwtPlotLegendItem *d_legendItem; 45 const QwtPlotItem *d_plotItem; 46 QwtLegendData d_data; 47 48 QRect d_rect; 49 }; 50 51 QwtLegendLayoutItem::QwtLegendLayoutItem( 52 const QwtPlotLegendItem *legendItem, const QwtPlotItem *plotItem ): 53 d_legendItem( legendItem ), 54 d_plotItem( plotItem) 55 { 56 } 57 58 QwtLegendLayoutItem::~QwtLegendLayoutItem() 59 { 60 } 61 62 const QwtPlotItem *QwtLegendLayoutItem::plotItem() const 63 { 64 return d_plotItem; 65 } 66 67 void QwtLegendLayoutItem::setData( const QwtLegendData &data ) 68 { 69 d_data = data; 70 } 71 72 const QwtLegendData &QwtLegendLayoutItem::data() const 73 { 74 return d_data; 75 } 76 77 Qt::Orientations QwtLegendLayoutItem::expandingDirections() const 78 { 79 return Qt::Horizontal; 80 } 81 82 bool QwtLegendLayoutItem::hasHeightForWidth() const 83 { 84 return !d_data.title().isEmpty(); 85 } 86 87 int QwtLegendLayoutItem::minimumHeightForWidth( int w ) const 88 { 89 return d_legendItem->heightForWidth( d_data, w ); 90 } 91 92 int QwtLegendLayoutItem::heightForWidth( int w ) const 93 { 94 return d_legendItem->heightForWidth( d_data, w ); 95 } 96 97 bool QwtLegendLayoutItem::isEmpty() const 98 { 99 return false; 100 } 101 102 QSize QwtLegendLayoutItem::maximumSize() const 103 { 104 return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX ); 105 } 106 107 QSize QwtLegendLayoutItem::minimumSize() const 108 { 109 return d_legendItem->minimumSize( d_data ); 110 } 111 112 QSize QwtLegendLayoutItem::sizeHint() const 113 { 114 return minimumSize(); 115 } 116 117 void QwtLegendLayoutItem::setGeometry( const QRect &rect ) 118 { 119 d_rect = rect; 120 } 121 122 QRect QwtLegendLayoutItem::geometry() const 123 { 124 return d_rect; 21 22 namespace 23 { 24 class LayoutItem QWT_FINAL : public QLayoutItem 25 { 26 public: 27 LayoutItem( const QwtPlotLegendItem*, const QwtPlotItem* ); 28 virtual ~LayoutItem(); 29 30 const QwtPlotItem* plotItem() const; 31 32 void setData( const QwtLegendData& ); 33 const QwtLegendData& data() const; 34 35 virtual Qt::Orientations expandingDirections() const QWT_OVERRIDE; 36 virtual QRect geometry() const QWT_OVERRIDE; 37 virtual bool hasHeightForWidth() const QWT_OVERRIDE; 38 virtual int heightForWidth( int ) const QWT_OVERRIDE; 39 virtual bool isEmpty() const QWT_OVERRIDE; 40 virtual QSize maximumSize() const QWT_OVERRIDE; 41 virtual int minimumHeightForWidth( int ) const QWT_OVERRIDE; 42 virtual QSize minimumSize() const QWT_OVERRIDE; 43 virtual void setGeometry( const QRect& ) QWT_OVERRIDE; 44 virtual QSize sizeHint() const QWT_OVERRIDE; 45 46 private: 47 48 const QwtPlotLegendItem* m_legendItem; 49 const QwtPlotItem* m_plotItem; 50 QwtLegendData m_data; 51 52 QRect m_rect; 53 }; 54 55 LayoutItem::LayoutItem( 56 const QwtPlotLegendItem* legendItem, const QwtPlotItem* plotItem ) 57 : m_legendItem( legendItem ) 58 , m_plotItem( plotItem) 59 { 60 } 61 62 LayoutItem::~LayoutItem() 63 { 64 } 65 66 const QwtPlotItem* LayoutItem::plotItem() const 67 { 68 return m_plotItem; 69 } 70 71 void LayoutItem::setData( const QwtLegendData& data ) 72 { 73 m_data = data; 74 } 75 76 const QwtLegendData& LayoutItem::data() const 77 { 78 return m_data; 79 } 80 81 Qt::Orientations LayoutItem::expandingDirections() const 82 { 83 return Qt::Horizontal; 84 } 85 86 bool LayoutItem::hasHeightForWidth() const 87 { 88 return !m_data.title().isEmpty(); 89 } 90 91 int LayoutItem::minimumHeightForWidth( int w ) const 92 { 93 return m_legendItem->heightForWidth( m_data, w ); 94 } 95 96 int LayoutItem::heightForWidth( int w ) const 97 { 98 return m_legendItem->heightForWidth( m_data, w ); 99 } 100 101 bool LayoutItem::isEmpty() const 102 { 103 return false; 104 } 105 106 QSize LayoutItem::maximumSize() const 107 { 108 return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX ); 109 } 110 111 QSize LayoutItem::minimumSize() const 112 { 113 return m_legendItem->minimumSize( m_data ); 114 } 115 116 QSize LayoutItem::sizeHint() const 117 { 118 return minimumSize(); 119 } 120 121 void LayoutItem::setGeometry( const QRect& rect ) 122 { 123 m_rect = rect; 124 } 125 126 QRect LayoutItem::geometry() const 127 { 128 return m_rect; 129 } 125 130 } 126 131 127 132 class QwtPlotLegendItem::PrivateData 128 133 { 129 public: 130 PrivateData() :131 itemMargin( 4 ) ,132 itemSpacing( 4 ) ,133 borderRadius( 0.0 ) ,134 borderPen( Qt::NoPen ) ,135 backgroundBrush( Qt::NoBrush ) ,136 backgroundMode( QwtPlotLegendItem::LegendBackground ) ,137 borderDistance( 10 ),138 alignment( Qt::AlignRight | Qt::AlignBottom )139 {134 public: 135 PrivateData() 136 : itemMargin( 4 ) 137 , itemSpacing( 4 ) 138 , borderRadius( 0.0 ) 139 , borderPen( Qt::NoPen ) 140 , backgroundBrush( Qt::NoBrush ) 141 , backgroundMode( QwtPlotLegendItem::LegendBackground ) 142 , canvasAlignment( Qt::AlignRight | Qt::AlignBottom ) 143 { 144 canvasOffset[ 0 ] = canvasOffset[1] = 10; 140 145 layout = new QwtDynGridLayout(); 141 146 layout->setMaxColumns( 2 ); … … 160 165 QwtPlotLegendItem::BackgroundMode backgroundMode; 161 166 162 int borderDistance;163 Qt::Alignment alignment;164 165 QMap< const QwtPlotItem *, QList<QwtLegendLayoutItem*> > map;166 QwtDynGridLayout *layout;167 int canvasOffset[2]; 168 Qt::Alignment canvasAlignment; 169 170 QMap< const QwtPlotItem*, QList< LayoutItem* > > map; 171 QwtDynGridLayout* layout; 167 172 }; 168 173 169 174 //! Constructor 170 QwtPlotLegendItem::QwtPlotLegendItem() :171 QwtPlotItem( QwtText( "Legend" ) ) 172 { 173 d_data = new PrivateData;175 QwtPlotLegendItem::QwtPlotLegendItem() 176 : QwtPlotItem( QwtText( "Legend" ) ) 177 { 178 m_data = new PrivateData; 174 179 175 180 setItemInterest( QwtPlotItem::LegendInterest, true ); … … 181 186 { 182 187 clearLegend(); 183 delete d_data;188 delete m_data; 184 189 } 185 190 … … 191 196 192 197 /*! 193 \brief Set the alignmnet 194 195 Alignment means the position of the legend relative 196 to the geometry of the plot canvas. 197 198 \param alignment Alignment flags 199 200 \sa alignment(), setMaxColumns() 201 202 \note To align a legend with many items horizontally 198 \brief Set the alignmnet 199 200 Alignment means the position of the legend relative 201 to the geometry of the plot canvas. 202 203 \param alignment Alignment flags 204 205 \sa alignmentInCanvas(), setMaxColumns() 206 207 \note To align a legend with many items horizontally 203 208 the number of columns need to be limited 204 209 */ 205 void QwtPlotLegendItem::setAlignment( Qt::Alignment alignment ) 206 { 207 if ( d_data->alignment != alignment )208 { 209 d_data->alignment = alignment;210 itemChanged(); 211 } 212 } 213 214 /*! 215 \return Alignment flags 216 \sa setAlignment() 217 */ 218 Qt::Alignment QwtPlotLegendItem::alignment() const 219 { 220 return d_data->alignment;221 } 222 223 /*! 224 \brief Limit the number of columns 225 226 When aligning the legend horizontally ( Qt::AlignLeft, Qt::AlignRight ) 227 the number of columns needs to be limited to avoid, that 228 the width of the legend grows with an increasing number of entries. 229 230 \param maxColumns Maximum number of columns. 0 means unlimited. 231 \sa maxColumns(), QwtDynGridLayout::setMaxColumns() 210 void QwtPlotLegendItem::setAlignmentInCanvas( Qt::Alignment alignment ) 211 { 212 if ( m_data->canvasAlignment != alignment ) 213 { 214 m_data->canvasAlignment = alignment; 215 itemChanged(); 216 } 217 } 218 219 /*! 220 \return Alignment flags 221 \sa setAlignmentInCanvas() 222 */ 223 Qt::Alignment QwtPlotLegendItem::alignmentInCanvas() const 224 { 225 return m_data->canvasAlignment; 226 } 227 228 /*! 229 \brief Limit the number of columns 230 231 When aligning the legend horizontally ( Qt::AlignLeft, Qt::AlignRight ) 232 the number of columns needs to be limited to avoid, that 233 the width of the legend grows with an increasing number of entries. 234 235 \param maxColumns Maximum number of columns. 0 means unlimited. 236 \sa maxColumns(), QwtDynGridLayout::setMaxColumns() 232 237 */ 233 238 void QwtPlotLegendItem::setMaxColumns( uint maxColumns ) 234 239 { 235 if ( maxColumns != d_data->layout->maxColumns() )236 { 237 d_data->layout->setMaxColumns( maxColumns );238 itemChanged(); 239 } 240 } 241 242 /*! 243 \return Maximum number of columns 244 \sa maxColumns(), QwtDynGridLayout::maxColumns() 240 if ( maxColumns != m_data->layout->maxColumns() ) 241 { 242 m_data->layout->setMaxColumns( maxColumns ); 243 itemChanged(); 244 } 245 } 246 247 /*! 248 \return Maximum number of columns 249 \sa maxColumns(), QwtDynGridLayout::maxColumns() 245 250 */ 246 251 uint QwtPlotLegendItem::maxColumns() const 247 252 { 248 return d_data->layout->maxColumns();249 } 250 251 /*! 252 \brief Set the margin around legend items 253 254 The default setting for the margin is 0. 255 256 \param margin Margin in pixels 257 \sa margin(), setSpacing(), setItemMargin(), setItemSpacing 253 return m_data->layout->maxColumns(); 254 } 255 256 /*! 257 \brief Set the margin around legend items 258 259 The default setting for the margin is 0. 260 261 \param margin Margin in pixels 262 \sa margin(), setSpacing(), setItemMargin(), setItemSpacing 258 263 */ 259 264 void QwtPlotLegendItem::setMargin( int margin ) … … 262 267 if ( margin != this->margin() ) 263 268 { 264 d_data->layout->setContentsMargins(269 m_data->layout->setContentsMargins( 265 270 margin, margin, margin, margin ); 266 271 … … 270 275 271 276 /*! 272 \return Margin around the legend items 273 \sa setMargin(), spacing(), itemMargin(), itemSpacing() 277 \return Margin around the legend items 278 \sa setMargin(), spacing(), itemMargin(), itemSpacing() 274 279 */ 275 280 int QwtPlotLegendItem::margin() const 276 281 { 277 282 int left; 278 d_data->layout->getContentsMargins( &left, NULL, NULL, NULL );283 m_data->layout->getContentsMargins( &left, NULL, NULL, NULL ); 279 284 280 285 return left; … … 282 287 283 288 /*! 284 \brief Set the spacing between the legend items 285 286 \param spacing Spacing in pixels 287 \sa spacing(), setMargin() 288 */ 289 \brief Set the spacing between the legend items 290 291 \param spacing Spacing in pixels 292 \sa spacing(), setMargin() 293 */ 289 294 void QwtPlotLegendItem::setSpacing( int spacing ) 290 295 { 291 296 spacing = qMax( spacing, 0 ); 292 if ( spacing != d_data->layout->spacing() )293 { 294 d_data->layout->setSpacing( spacing );295 itemChanged(); 296 } 297 } 298 299 /*! 300 \return Spacing between the legend items 301 \sa setSpacing(), margin(), itemSpacing(), itemMargin() 297 if ( spacing != m_data->layout->spacing() ) 298 { 299 m_data->layout->setSpacing( spacing ); 300 itemChanged(); 301 } 302 } 303 304 /*! 305 \return Spacing between the legend items 306 \sa setSpacing(), margin(), itemSpacing(), itemMargin() 302 307 */ 303 308 int QwtPlotLegendItem::spacing() const 304 309 { 305 return d_data->layout->spacing();306 } 307 308 /*! 309 Set the margin around each item 310 311 \param margin Margin 312 \sa itemMargin(), setItemSpacing(), setMargin(), setSpacing() 310 return m_data->layout->spacing(); 311 } 312 313 /*! 314 Set the margin around each item 315 316 \param margin Margin 317 \sa itemMargin(), setItemSpacing(), setMargin(), setSpacing() 313 318 */ 314 319 void QwtPlotLegendItem::setItemMargin( int margin ) 315 320 { 316 321 margin = qMax( margin, 0 ); 317 if ( margin != d_data->itemMargin )318 { 319 d_data->itemMargin = margin;320 321 d_data->layout->invalidate();322 itemChanged(); 323 } 324 } 325 326 /*! 327 \return Margin around each item 328 \sa setItemMargin(), itemSpacing(), margin(), spacing() 329 */ 322 if ( margin != m_data->itemMargin ) 323 { 324 m_data->itemMargin = margin; 325 326 m_data->layout->invalidate(); 327 itemChanged(); 328 } 329 } 330 331 /*! 332 \return Margin around each item 333 \sa setItemMargin(), itemSpacing(), margin(), spacing() 334 */ 330 335 int QwtPlotLegendItem::itemMargin() const 331 336 { 332 return d_data->itemMargin;333 } 334 335 /*! 336 Set the spacing inside of each item 337 338 \param spacing Spacing 339 \sa itemSpacing(), setItemMargin(), setMargin(), setSpacing() 337 return m_data->itemMargin; 338 } 339 340 /*! 341 Set the spacing inside of each item 342 343 \param spacing Spacing 344 \sa itemSpacing(), setItemMargin(), setMargin(), setSpacing() 340 345 */ 341 346 void QwtPlotLegendItem::setItemSpacing( int spacing ) 342 347 { 343 348 spacing = qMax( spacing, 0 ); 344 if ( spacing != d_data->itemSpacing )345 { 346 d_data->itemSpacing = spacing;347 348 d_data->layout->invalidate();349 itemChanged(); 350 } 351 352 } 353 354 /*! 355 \return Spacing inside of each item 356 \sa setItemSpacing(), itemMargin(), margin(), spacing() 357 */ 349 if ( spacing != m_data->itemSpacing ) 350 { 351 m_data->itemSpacing = spacing; 352 353 m_data->layout->invalidate(); 354 itemChanged(); 355 } 356 357 } 358 359 /*! 360 \return Spacing inside of each item 361 \sa setItemSpacing(), itemMargin(), margin(), spacing() 362 */ 358 363 int QwtPlotLegendItem::itemSpacing() const 359 364 { 360 return d_data->itemSpacing;365 return m_data->itemSpacing; 361 366 } 362 367 … … 366 371 \param font Legend font 367 372 \sa font() 368 */ 369 void QwtPlotLegendItem::setFont( const QFont &font )370 { 371 if ( font != d_data->font )372 { 373 d_data->font = font;374 375 d_data->layout->invalidate();373 */ 374 void QwtPlotLegendItem::setFont( const QFont& font ) 375 { 376 if ( font != m_data->font ) 377 { 378 m_data->font = font; 379 380 m_data->layout->invalidate(); 376 381 itemChanged(); 377 382 } … … 381 386 \return Font used for drawing the text label 382 387 \sa setFont() 383 */ 388 */ 384 389 QFont QwtPlotLegendItem::font() const 385 390 { 386 return d_data->font; 387 } 388 389 /*! 390 \brief Set the margin between the legend and the canvas border 391 392 The default setting for the margin is 10 pixels. 393 394 \param distance Margin in pixels 395 \sa setMargin() 396 */ 397 void QwtPlotLegendItem::setBorderDistance( int distance ) 398 { 399 if ( distance < 0 ) 400 distance = -1; 401 402 if ( distance != d_data->borderDistance ) 403 { 404 d_data->borderDistance = distance; 405 itemChanged(); 406 } 407 } 408 409 /*! 410 \return Margin between the legend and the canvas border 411 \sa margin() 412 */ 413 int QwtPlotLegendItem::borderDistance() const 414 { 415 return d_data->borderDistance; 416 } 417 418 /*! 419 Set the radius for the border 420 421 \param radius A value <= 0 defines a rectangular border 422 \sa borderRadius(), setBorderPen() 391 return m_data->font; 392 } 393 394 /*! 395 \brief Set the distance between the legend and the canvas border 396 397 The default setting is 10 pixels. 398 399 \param orientations Qt::Horizontal is for the left/right, 400 Qt::Vertical for the top/bottom offset. 401 402 \param numPixels Distance in pixels 403 \sa setMargin() 404 */ 405 void QwtPlotLegendItem::setOffsetInCanvas( 406 Qt::Orientations orientations, int numPixels ) 407 { 408 if ( numPixels < 0 ) 409 numPixels = -1; 410 411 bool isChanged = false; 412 413 int* offset = m_data->canvasOffset; 414 415 if ( orientations & Qt::Horizontal ) 416 { 417 if ( numPixels != offset[0] ) 418 { 419 offset[0] = numPixels; 420 isChanged = true; 421 } 422 } 423 424 if ( orientations & Qt::Vertical ) 425 { 426 if ( numPixels != offset[1] ) 427 { 428 offset[1] = numPixels; 429 isChanged = true; 430 } 431 } 432 433 if ( isChanged ) 434 itemChanged(); 435 } 436 437 /*! 438 \param orientation Qt::Horizontal is for the left/right, 439 Qt::Vertical for the top/bottom padding. 440 441 \return Distance between the legend and the canvas border 442 \sa setOffsetInCanvas() 443 */ 444 int QwtPlotLegendItem::offsetInCanvas( 445 Qt::Orientation orientation ) const 446 { 447 const int index = ( orientation == Qt::Vertical ) ? 1 : 0; 448 return m_data->canvasOffset[index]; 449 } 450 451 /*! 452 Set the radius for the border 453 454 \param radius A value <= 0 defines a rectangular border 455 \sa borderRadius(), setBorderPen() 423 456 */ 424 457 void QwtPlotLegendItem::setBorderRadius( double radius ) 425 458 { 426 radius = q Max( 0.0, radius );427 428 if ( radius != d_data->borderRadius )429 { 430 d_data->borderRadius = radius;431 itemChanged(); 432 } 433 } 434 435 /*! 436 \return Radius of the border 437 \sa setBorderRadius(), setBorderPen() 459 radius = qwtMaxF( 0.0, radius ); 460 461 if ( radius != m_data->borderRadius ) 462 { 463 m_data->borderRadius = radius; 464 itemChanged(); 465 } 466 } 467 468 /*! 469 \return Radius of the border 470 \sa setBorderRadius(), setBorderPen() 438 471 */ 439 472 double QwtPlotLegendItem::borderRadius() const 440 473 { 441 return d_data->borderRadius;442 } 443 444 /*! 445 Set the pen for drawing the border 446 447 \param pen Border pen 448 \sa borderPen(), setBackgroundBrush() 449 */ 450 void QwtPlotLegendItem::setBorderPen( const QPen &pen )451 { 452 if ( d_data->borderPen != pen )453 { 454 d_data->borderPen = pen;455 itemChanged(); 456 } 457 } 458 459 /*! 460 \return Pen for drawing the border 461 \sa setBorderPen(), backgroundBrush() 474 return m_data->borderRadius; 475 } 476 477 /*! 478 Set the pen for drawing the border 479 480 \param pen Border pen 481 \sa borderPen(), setBackgroundBrush() 482 */ 483 void QwtPlotLegendItem::setBorderPen( const QPen& pen ) 484 { 485 if ( m_data->borderPen != pen ) 486 { 487 m_data->borderPen = pen; 488 itemChanged(); 489 } 490 } 491 492 /*! 493 \return Pen for drawing the border 494 \sa setBorderPen(), backgroundBrush() 462 495 */ 463 496 QPen QwtPlotLegendItem::borderPen() const 464 497 { 465 return d_data->borderPen;466 } 467 468 /*! 469 \brief Set the background brush 470 471 The brush is used to fill the background 472 473 \param brush Brush 474 \sa backgroundBrush(), setBackgroundMode(), drawBackground() 475 */ 476 void QwtPlotLegendItem::setBackgroundBrush( const QBrush &brush )477 { 478 if ( d_data->backgroundBrush != brush )479 { 480 d_data->backgroundBrush = brush;481 itemChanged(); 482 } 483 } 484 485 /*! 486 \return Brush is used to fill the background 487 \sa setBackgroundBrush(), backgroundMode(), drawBackground() 498 return m_data->borderPen; 499 } 500 501 /*! 502 \brief Set the background brush 503 504 The brush is used to fill the background 505 506 \param brush Brush 507 \sa backgroundBrush(), setBackgroundMode(), drawBackground() 508 */ 509 void QwtPlotLegendItem::setBackgroundBrush( const QBrush& brush ) 510 { 511 if ( m_data->backgroundBrush != brush ) 512 { 513 m_data->backgroundBrush = brush; 514 itemChanged(); 515 } 516 } 517 518 /*! 519 \return Brush is used to fill the background 520 \sa setBackgroundBrush(), backgroundMode(), drawBackground() 488 521 */ 489 522 QBrush QwtPlotLegendItem::backgroundBrush() const 490 523 { 491 return d_data->backgroundBrush;492 } 493 494 /*! 495 \brief Set the background mode 496 497 Depending on the mode the complete legend or each item 498 might have an background. 499 500 The default setting is LegendBackground. 524 return m_data->backgroundBrush; 525 } 526 527 /*! 528 \brief Set the background mode 529 530 Depending on the mode the complete legend or each item 531 might have an background. 532 533 The default setting is LegendBackground. 501 534 502 535 \sa backgroundMode(), setBackgroundBrush(), drawBackground() … … 504 537 void QwtPlotLegendItem::setBackgroundMode( BackgroundMode mode ) 505 538 { 506 if ( mode != d_data->backgroundMode )507 { 508 d_data->backgroundMode = mode;509 itemChanged(); 510 } 511 } 512 513 /*! 514 \return backgroundMode 515 \sa setBackgroundMode(), backgroundBrush(), drawBackground() 539 if ( mode != m_data->backgroundMode ) 540 { 541 m_data->backgroundMode = mode; 542 itemChanged(); 543 } 544 } 545 546 /*! 547 \return backgroundMode 548 \sa setBackgroundMode(), backgroundBrush(), drawBackground() 516 549 */ 517 550 QwtPlotLegendItem::BackgroundMode QwtPlotLegendItem::backgroundMode() const 518 551 { 519 return d_data->backgroundMode;520 } 521 522 /*! 523 \brief Set the pen for drawing text labels 524 525 \param pen Text pen 526 \sa textPen(), setFont() 527 */ 528 void QwtPlotLegendItem::setTextPen( const QPen &pen )529 { 530 if ( d_data->textPen != pen )531 { 532 d_data->textPen = pen;533 itemChanged(); 534 } 535 } 536 537 /*! 538 \return Pen for drawing text labels 539 \sa setTextPen(), font() 552 return m_data->backgroundMode; 553 } 554 555 /*! 556 \brief Set the pen for drawing text labels 557 558 \param pen Text pen 559 \sa textPen(), setFont() 560 */ 561 void QwtPlotLegendItem::setTextPen( const QPen& pen ) 562 { 563 if ( m_data->textPen != pen ) 564 { 565 m_data->textPen = pen; 566 itemChanged(); 567 } 568 } 569 570 /*! 571 \return Pen for drawing text labels 572 \sa setTextPen(), font() 540 573 */ 541 574 QPen QwtPlotLegendItem::textPen() const 542 575 { 543 return d_data->textPen;544 } 545 546 /*! 547 Draw the legend 548 549 \param painter Painter 550 \param xMap x Scale Map 551 \param yMap y Scale Map 552 \param canvasRect Contents rectangle of the canvas in painter coordinates 553 */ 554 void QwtPlotLegendItem::draw( QPainter *painter,555 const QwtScaleMap &xMap, const QwtScaleMap&yMap,556 const QRectF &canvasRect ) const576 return m_data->textPen; 577 } 578 579 /*! 580 Draw the legend 581 582 \param painter Painter 583 \param xMap x Scale Map 584 \param yMap y Scale Map 585 \param canvasRect Contents rectangle of the canvas in painter coordinates 586 */ 587 void QwtPlotLegendItem::draw( QPainter* painter, 588 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 589 const QRectF& canvasRect ) const 557 590 { 558 591 Q_UNUSED( xMap ); 559 592 Q_UNUSED( yMap ); 560 593 561 d_data->layout->setGeometry( geometry( canvasRect ) );562 if ( d_data->layout->geometry().isEmpty() )594 m_data->layout->setGeometry( geometry( canvasRect ) ); 595 if ( m_data->layout->geometry().isEmpty() ) 563 596 { 564 597 // don't draw a legend when having no content … … 566 599 } 567 600 568 if ( d_data->backgroundMode == QwtPlotLegendItem::LegendBackground )569 drawBackground( painter, d_data->layout->geometry() );570 571 for ( int i = 0; i < d_data->layout->count(); i++ )572 { 573 const QwtLegendLayoutItem*layoutItem =574 static_cast< QwtLegendLayoutItem*>( d_data->layout->itemAt( i ) );575 576 if ( d_data->backgroundMode == QwtPlotLegendItem::ItemBackground )601 if ( m_data->backgroundMode == QwtPlotLegendItem::LegendBackground ) 602 drawBackground( painter, m_data->layout->geometry() ); 603 604 for ( int i = 0; i < m_data->layout->count(); i++ ) 605 { 606 const LayoutItem* layoutItem = 607 static_cast< LayoutItem* >( m_data->layout->itemAt( i ) ); 608 609 if ( m_data->backgroundMode == QwtPlotLegendItem::ItemBackground ) 577 610 drawBackground( painter, layoutItem->geometry() ); 578 611 … … 587 620 588 621 /*! 589 Draw a rounded rect 590 591 \param painter Painter 592 \param rect Bounding rectangle 593 594 \sa setBorderRadius(), setBorderPen(), 622 Draw a rounded rect 623 624 \param painter Painter 625 \param rect Bounding rectangle 626 627 \sa setBorderRadius(), setBorderPen(), 595 628 setBackgroundBrush(), setBackgroundMode() 596 629 */ 597 630 void QwtPlotLegendItem::drawBackground( 598 QPainter *painter, const QRectF&rect ) const631 QPainter* painter, const QRectF& rect ) const 599 632 { 600 633 painter->save(); 601 634 602 painter->setPen( d_data->borderPen );603 painter->setBrush( d_data->backgroundBrush );604 605 const double radius = d_data->borderRadius;635 painter->setPen( m_data->borderPen ); 636 painter->setBrush( m_data->backgroundBrush ); 637 638 const double radius = m_data->borderRadius; 606 639 painter->drawRoundedRect( rect, radius, radius ); 607 640 … … 610 643 611 644 /*! 612 Calculate the geometry of the legend on the canvas 613 614 \param canvasRect Geometry of the canvas 615 \return Geometry of the legend 616 */ 617 QRect QwtPlotLegendItem::geometry( const QRectF &canvasRect ) const645 Calculate the geometry of the legend on the canvas 646 647 \param canvasRect Geometry of the canvas 648 \return Geometry of the legend 649 */ 650 QRect QwtPlotLegendItem::geometry( const QRectF& canvasRect ) const 618 651 { 619 652 QRect rect; 620 rect.setSize( d_data->layout->sizeHint() ); 621 622 int margin = d_data->borderDistance; 623 if ( d_data->alignment & Qt::AlignHCenter ) 653 rect.setSize( m_data->layout->sizeHint() ); 654 655 if ( m_data->canvasAlignment & Qt::AlignHCenter ) 624 656 { 625 657 int x = qRound( canvasRect.center().x() ); 626 658 rect.moveCenter( QPoint( x, rect.center().y() ) ); 627 659 } 628 else if ( d_data->alignment & Qt::AlignRight ) 629 { 630 rect.moveRight( qFloor( canvasRect.right() - margin ) ); 660 else if ( m_data->canvasAlignment & Qt::AlignRight ) 661 { 662 const int offset = offsetInCanvas( Qt::Horizontal ); 663 rect.moveRight( qwtFloor( canvasRect.right() - offset ) ); 631 664 } 632 665 else 633 666 { 634 rect.moveLeft( qCeil( canvasRect.left() + margin ) ); 635 } 636 637 if ( d_data->alignment & Qt::AlignVCenter ) 667 const int offset = offsetInCanvas( Qt::Horizontal ); 668 rect.moveLeft( qwtCeil( canvasRect.left() + offset ) ); 669 } 670 671 if ( m_data->canvasAlignment & Qt::AlignVCenter ) 638 672 { 639 673 int y = qRound( canvasRect.center().y() ); 640 674 rect.moveCenter( QPoint( rect.center().x(), y ) ); 641 675 } 642 else if ( d_data->alignment & Qt::AlignBottom ) 643 { 644 rect.moveBottom( qFloor( canvasRect.bottom() - margin ) ); 676 else if ( m_data->canvasAlignment & Qt::AlignBottom ) 677 { 678 const int offset = offsetInCanvas( Qt::Vertical ); 679 rect.moveBottom( qwtFloor( canvasRect.bottom() - offset ) ); 645 680 } 646 681 else 647 682 { 648 rect.moveTop( qCeil( canvasRect.top() + margin ) ); 683 const int offset = offsetInCanvas( Qt::Vertical ); 684 rect.moveTop( qwtCeil( canvasRect.top() + offset ) ); 649 685 } 650 686 … … 653 689 654 690 /*! 655 Update the legend items according to modifications of a 656 plot item 657 658 \param plotItem Plot item 659 \param data Attributes of the legend entries 660 */ 661 void QwtPlotLegendItem::updateLegend( const QwtPlotItem *plotItem,662 const QList<QwtLegendData> &data )691 Update the legend items according to modifications of a 692 plot item 693 694 \param plotItem Plot item 695 \param data Attributes of the legend entries 696 */ 697 void QwtPlotLegendItem::updateLegend( const QwtPlotItem* plotItem, 698 const QList< QwtLegendData >& data ) 663 699 { 664 700 if ( plotItem == NULL ) 665 701 return; 666 702 667 QList< QwtLegendLayoutItem*> layoutItems;668 669 QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem*> >::iterator it =670 d_data->map.find( plotItem );671 if ( it != d_data->map.end() )703 QList< LayoutItem* > layoutItems; 704 705 QMap< const QwtPlotItem*, QList< LayoutItem* > >::const_iterator it = 706 m_data->map.constFind( plotItem ); 707 if ( it != m_data->map.constEnd() ) 672 708 layoutItems = it.value(); 673 709 … … 680 716 for ( int i = 0; i < layoutItems.size(); i++ ) 681 717 { 682 d_data->layout->removeItem( layoutItems[i] );718 m_data->layout->removeItem( layoutItems[i] ); 683 719 delete layoutItems[i]; 684 720 } 685 721 layoutItems.clear(); 686 722 687 if ( it != d_data->map.end() )688 d_data->map.remove( plotItem );723 if ( it != m_data->map.constEnd() ) 724 m_data->map.remove( plotItem ); 689 725 690 726 if ( !data.isEmpty() ) 691 727 { 728 layoutItems.reserve( data.size() ); 729 692 730 for ( int i = 0; i < data.size(); i++ ) 693 731 { 694 QwtLegendLayoutItem*layoutItem =695 new QwtLegendLayoutItem( this, plotItem );696 d_data->layout->addItem( layoutItem );732 LayoutItem* layoutItem = 733 new LayoutItem( this, plotItem ); 734 m_data->layout->addItem( layoutItem ); 697 735 layoutItems += layoutItem; 698 736 } 699 737 700 d_data->map.insert( plotItem, layoutItems );738 m_data->map.insert( plotItem, layoutItems ); 701 739 } 702 740 } … … 713 751 if ( changed ) 714 752 { 715 d_data->layout->invalidate();753 m_data->layout->invalidate(); 716 754 itemChanged(); 717 755 } … … 721 759 void QwtPlotLegendItem::clearLegend() 722 760 { 723 if ( ! d_data->map.isEmpty() )724 { 725 d_data->map.clear();726 727 for ( int i = d_data->layout->count() - 1; i >= 0; i-- )728 delete d_data->layout->takeAt( i );729 730 itemChanged(); 731 } 732 } 733 734 /*! 735 Draw an entry on the legend 736 737 \param painter Qt Painter 738 \param plotItem Plot item, represented by the entry 739 \param data Attributes of the legend entry 740 \param rect Bounding rectangle for the entry 741 */ 742 void QwtPlotLegendItem::drawLegendData( QPainter *painter,743 const QwtPlotItem *plotItem, const QwtLegendData&data,744 const QRectF &rect ) const761 if ( !m_data->map.isEmpty() ) 762 { 763 m_data->map.clear(); 764 765 for ( int i = m_data->layout->count() - 1; i >= 0; i-- ) 766 delete m_data->layout->takeAt( i ); 767 768 itemChanged(); 769 } 770 } 771 772 /*! 773 Draw an entry on the legend 774 775 \param painter Qt Painter 776 \param plotItem Plot item, represented by the entry 777 \param data Attributes of the legend entry 778 \param rect Bounding rectangle for the entry 779 */ 780 void QwtPlotLegendItem::drawLegendData( QPainter* painter, 781 const QwtPlotItem* plotItem, const QwtLegendData& data, 782 const QRectF& rect ) const 745 783 { 746 784 Q_UNUSED( plotItem ); 747 785 748 const int m = d_data->itemMargin;786 const int m = m_data->itemMargin; 749 787 const QRectF r = rect.toRect().adjusted( m, m, -m, -m ); 750 788 … … 763 801 graphic.render( painter, iconRect, Qt::KeepAspectRatio ); 764 802 765 titleOff += iconRect.width() + d_data->itemSpacing;803 titleOff += iconRect.width() + m_data->itemSpacing; 766 804 } 767 805 … … 778 816 779 817 /*! 780 Minimum size hint needed to display an entry 781 782 \param data Attributes of the legend entry 783 \return Minimum size 784 */ 785 QSize QwtPlotLegendItem::minimumSize( const QwtLegendData &data ) const786 { 787 QSize size( 2 * d_data->itemMargin, 2 *d_data->itemMargin );818 Minimum size hint needed to display an entry 819 820 \param data Attributes of the legend entry 821 \return Minimum size 822 */ 823 QSize QwtPlotLegendItem::minimumSize( const QwtLegendData& data ) const 824 { 825 QSize size( 2 * m_data->itemMargin, 2 * m_data->itemMargin ); 788 826 789 827 if ( !data.isValid() ) … … 806 844 const QSizeF sz = text.textSize( font() ); 807 845 808 w += qCeil( sz.width() ); 809 h = qMax( h, qCeil( sz.height() ) ); 846 w += qwtCeil( sz.width() ); 847 h = qMax( h, qwtCeil( sz.height() ) ); 810 848 } 811 849 812 850 if ( graphic.width() > 0 && !text.isEmpty() ) 813 w += d_data->itemSpacing;851 w += m_data->itemSpacing; 814 852 815 853 size += QSize( w, h ); … … 818 856 819 857 /*! 820 \return The preferred height, for a width. 821 \param data Attributes of the legend entry 822 \param width Width 823 */ 858 \return The preferred height, for a width. 859 \param data Attributes of the legend entry 860 \param width Width 861 */ 824 862 int QwtPlotLegendItem::heightForWidth( 825 const QwtLegendData &data, int width ) const826 { 827 width -= 2 * d_data->itemMargin;863 const QwtLegendData& data, int width ) const 864 { 865 width -= 2 * m_data->itemMargin; 828 866 829 867 const QwtGraphic graphic = data.icon(); … … 834 872 835 873 if ( graphic.width() > 0 ) 836 width -= graphic.width() + d_data->itemSpacing;874 width -= graphic.width() + m_data->itemSpacing; 837 875 838 876 int h = text.heightForWidth( width, font() ); 839 h += 2 * d_data->itemMargin;877 h += 2 * m_data->itemMargin; 840 878 841 879 return qMax( graphic.height(), h ); … … 843 881 844 882 /*! 845 \return All plot items with an entry on the legend 846 \note A plot item might have more than one entry on the legend 847 */ 848 QList< const QwtPlotItem * > QwtPlotLegendItem::plotItems() const849 { 850 return d_data->map.keys();851 } 852 853 /*! 854 \return Geometries of the items of a plot item 855 \note Usually a plot item has only one entry on the legend 856 */ 883 \return All plot items with an entry on the legend 884 \note A plot item might have more than one entry on the legend 885 */ 886 QList< const QwtPlotItem* > QwtPlotLegendItem::plotItems() const 887 { 888 return m_data->map.keys(); 889 } 890 891 /*! 892 \return Geometries of the items of a plot item 893 \note Usually a plot item has only one entry on the legend 894 */ 857 895 QList< QRect > QwtPlotLegendItem::legendGeometries( 858 const QwtPlotItem *plotItem ) const859 { 860 QList< QwtLegendLayoutItem*> layoutItems;861 862 QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem*> >::iterator it =863 d_data->map.find( plotItem );864 if ( it != d_data->map.end() )896 const QwtPlotItem* plotItem ) const 897 { 898 QList< LayoutItem* > layoutItems; 899 900 QMap< const QwtPlotItem*, QList< LayoutItem* > >::const_iterator it = 901 m_data->map.constFind( plotItem ); 902 if ( it != m_data->map.constEnd() ) 865 903 layoutItems = it.value(); 866 904 867 QList<QRect> geometries; 905 QList< QRect > geometries; 906 geometries.reserve(layoutItems.size() ); 907 868 908 for ( int i = 0; i < layoutItems.size(); i++ ) 869 909 geometries += layoutItems[i]->geometry(); -
trunk/BNC/qwt/qwt_plot_legenditem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include "qwt_legend_data.h"16 15 17 16 class QFont; 18 17 19 18 /*! 20 \brief A class which draws a legend inside the plot canvas 19 \brief A class which draws a legend inside the plot canvas 21 20 22 QwtPlotLegendItem can be used to draw a inside the plot canvas. 23 It can be used together with a QwtLegend or instead of it 24 to have more space for the plot canvas. 21 QwtPlotLegendItem can be used to draw a inside the plot canvas. 22 It can be used together with a QwtLegend or instead of it 23 to have more space for the plot canvas. 25 24 26 In opposite to QwtLegend the legend item is not interactive. 27 To identify mouse clicks on a legend item an event filter 28 needs to be installed catching mouse events ob the plot canvas. 29 The geometries of the legend items are available using 30 legendGeometries(). 25 In opposite to QwtLegend the legend item is not interactive. 26 To identify mouse clicks on a legend item an event filter 27 needs to be installed catching mouse events ob the plot canvas. 28 The geometries of the legend items are available using 29 legendGeometries(). 31 30 32 The legend item is aligned to plot canvas according to 33 its alignment() flags. It might have a background for the 34 complete legend ( usually semi transparent ) or for 35 each legend item. 31 The legend item is aligned to plot canvas according to 32 its alignment() flags. It might have a background for the 33 complete legend ( usually semi transparent ) or for 34 each legend item. 36 35 37 \note An external QwtLegend with a transparent background 36 \note An external QwtLegend with a transparent background 38 37 on top the plot canvas might be another option 39 38 with a similar effect. 40 */ 39 */ 41 40 42 class QWT_EXPORT QwtPlotLegendItem: public QwtPlotItem 41 class QWT_EXPORT QwtPlotLegendItem : public QwtPlotItem 43 42 { 44 public: 43 public: 45 44 /*! 46 \brief Background mode 45 \brief Background mode 47 46 48 Depending on the mode the complete legend or each item 49 might have an background. 47 Depending on the mode the complete legend or each item 48 might have an background. 50 49 51 The default setting is LegendBackground. 50 The default setting is LegendBackground. 52 51 53 52 \sa setBackgroundMode(), setBackgroundBrush(), drawBackground() … … 65 64 virtual ~QwtPlotLegendItem(); 66 65 67 virtual int rtti() const; 66 virtual int rtti() const QWT_OVERRIDE; 68 67 69 void setAlignment( Qt::Alignment ); 70 Qt::Alignment alignment() const; 68 void setAlignmentInCanvas( Qt::Alignment ); 69 Qt::Alignment alignmentInCanvas() const; 70 71 void setOffsetInCanvas( Qt::Orientations, int numPixels ); 72 int offsetInCanvas( Qt::Orientation ) const; 71 73 72 74 void setMaxColumns( uint ); … … 88 90 QFont font() const; 89 91 90 void setBorderDistance( int );91 int borderDistance() const;92 93 92 void setBorderRadius( double ); 94 93 double borderRadius() const; 95 94 96 void setBorderPen( const QPen & );95 void setBorderPen( const QPen& ); 97 96 QPen borderPen() const; 98 97 99 void setBackgroundBrush( const QBrush & );98 void setBackgroundBrush( const QBrush& ); 100 99 QBrush backgroundBrush() const; 101 100 … … 103 102 BackgroundMode backgroundMode() const; 104 103 105 void setTextPen( const QPen & );104 void setTextPen( const QPen& ); 106 105 QPen textPen() const; 107 106 108 virtual void draw( QPainter *,109 const QwtScaleMap &xMap, const QwtScaleMap&yMap,110 const QRectF &canvasRect ) const;107 virtual void draw( QPainter*, 108 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 109 const QRectF& canvasRect ) const QWT_OVERRIDE; 111 110 112 111 void clearLegend(); 113 112 114 virtual void updateLegend( const QwtPlotItem *,115 const QList<QwtLegendData > & );113 virtual void updateLegend( const QwtPlotItem*, 114 const QList< QwtLegendData >& ) QWT_OVERRIDE; 116 115 117 virtual QRect geometry( const QRectF &canvasRect ) const;116 virtual QRect geometry( const QRectF& canvasRect ) const; 118 117 119 virtual QSize minimumSize( const QwtLegendData & ) const;120 virtual int heightForWidth( const QwtLegendData &, int width ) const;118 virtual QSize minimumSize( const QwtLegendData& ) const; 119 virtual int heightForWidth( const QwtLegendData&, int width ) const; 121 120 122 QList< const QwtPlotItem * > plotItems() const;123 QList< QRect > legendGeometries( const QwtPlotItem * ) const;121 QList< const QwtPlotItem* > plotItems() const; 122 QList< QRect > legendGeometries( const QwtPlotItem* ) const; 124 123 125 protected: 126 virtual void drawLegendData( QPainter *painter,127 const QwtPlotItem *, const QwtLegendData&, const QRectF& ) const;124 protected: 125 virtual void drawLegendData( QPainter*, 126 const QwtPlotItem*, const QwtLegendData&, const QRectF& ) const; 128 127 129 virtual void drawBackground( QPainter *, const QRectF&rect ) const;128 virtual void drawBackground( QPainter*, const QRectF& rect ) const; 130 129 131 private: 130 private: 132 131 class PrivateData; 133 PrivateData *d_data;132 PrivateData* m_data; 134 133 }; 135 134 -
trunk/BNC/qwt/qwt_plot_magnifier.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot.h" 11 #include "qwt_scale_ div.h"11 #include "qwt_scale_map.h" 12 12 #include "qwt_plot_magnifier.h" 13 #include <qevent.h>14 13 15 14 class QwtPlotMagnifier::PrivateData 16 15 { 17 public: 16 public: 18 17 PrivateData() 19 18 { 20 for ( int axis = 0; axis < Qwt Plot::axisCnt; axis++ )19 for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ ) 21 20 isAxisEnabled[axis] = true; 22 21 } 23 22 24 bool isAxisEnabled[Qwt Plot::axisCnt];23 bool isAxisEnabled[QwtAxis::AxisPositions]; 25 24 }; 26 25 … … 28 27 Constructor 29 28 \param canvas Plot canvas to be magnified 30 */ 31 QwtPlotMagnifier::QwtPlotMagnifier( QWidget *canvas ):32 QwtMagnifier( canvas ) 29 */ 30 QwtPlotMagnifier::QwtPlotMagnifier( QWidget* canvas ) 31 : QwtMagnifier( canvas ) 33 32 { 34 d_data = new PrivateData();33 m_data = new PrivateData(); 35 34 } 36 35 … … 38 37 QwtPlotMagnifier::~QwtPlotMagnifier() 39 38 { 40 delete d_data;39 delete m_data; 41 40 } 42 41 … … 47 46 All other axes will remain unchanged. 48 47 49 \param axis Axis, see QwtPlot::Axis48 \param axisId Axis 50 49 \param on On/Off 51 50 52 51 \sa isAxisEnabled() 53 */ 54 void QwtPlotMagnifier::setAxisEnabled( int axis, bool on )52 */ 53 void QwtPlotMagnifier::setAxisEnabled( QwtAxisId axisId, bool on ) 55 54 { 56 if ( axis >= 0 && axis < QwtPlot::axisCnt)57 d_data->isAxisEnabled[axis] = on;55 if ( QwtAxis::isValid( axisId ) ) 56 m_data->isAxisEnabled[axisId] = on; 58 57 } 59 58 … … 61 60 Test if an axis is enabled 62 61 63 \param axis Axis, see QwtPlot::Axis62 \param axisId Axis 64 63 \return True, if the axis is enabled 65 64 66 65 \sa setAxisEnabled() 67 */ 68 bool QwtPlotMagnifier::isAxisEnabled( int axis) const66 */ 67 bool QwtPlotMagnifier::isAxisEnabled( QwtAxisId axisId ) const 69 68 { 70 if ( axis >= 0 && axis < QwtPlot::axisCnt)71 return d_data->isAxisEnabled[axis];69 if ( QwtAxis::isValid( axisId ) ) 70 return m_data->isAxisEnabled[axisId]; 72 71 73 72 return true; … … 75 74 76 75 //! Return observed plot canvas 77 QWidget *QwtPlotMagnifier::canvas()76 QWidget* QwtPlotMagnifier::canvas() 78 77 { 79 78 return parentWidget(); … … 81 80 82 81 //! Return Observed plot canvas 83 const QWidget *QwtPlotMagnifier::canvas() const82 const QWidget* QwtPlotMagnifier::canvas() const 84 83 { 85 84 return parentWidget(); … … 87 86 88 87 //! Return plot widget, containing the observed plot canvas 89 QwtPlot *QwtPlotMagnifier::plot()88 QwtPlot* QwtPlotMagnifier::plot() 90 89 { 91 QWidget *w = canvas();90 QWidget* w = canvas(); 92 91 if ( w ) 93 92 w = w->parentWidget(); 94 93 95 return qobject_cast<QwtPlot *>( w );94 return qobject_cast< QwtPlot* >( w ); 96 95 } 97 96 98 97 //! Return plot widget, containing the observed plot canvas 99 const QwtPlot *QwtPlotMagnifier::plot() const98 const QwtPlot* QwtPlotMagnifier::plot() const 100 99 { 101 const QWidget *w = canvas();100 const QWidget* w = canvas(); 102 101 if ( w ) 103 102 w = w->parentWidget(); 104 103 105 return qobject_cast<const QwtPlot *>( w );104 return qobject_cast< const QwtPlot* >( w ); 106 105 } 107 106 … … 109 108 Zoom in/out the axes scales 110 109 \param factor A value < 1.0 zooms in, a value > 1.0 zooms out. 111 */ 110 */ 112 111 void QwtPlotMagnifier::rescale( double factor ) 113 112 { … … 125 124 plt->setAutoReplot( false ); 126 125 127 for ( int axis Id= 0; axisId < QwtPlot::axisCnt; axisId++ )126 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 128 127 { 129 if ( isAxisEnabled( axisId ) )130 128 { 131 const Qwt ScaleMap scaleMap = plt->canvasMap(axisId );129 const QwtAxisId axisId( axisPos ); 132 130 133 double v1 = scaleMap.s1(); 134 double v2 = scaleMap.s2(); 131 if ( isAxisEnabled( axisId ) ) 132 { 133 const QwtScaleMap scaleMap = plt->canvasMap( axisId ); 135 134 136 if ( scaleMap.transformation() ) 137 { 138 // the coordinate system of the paint device is always linear 135 double v1 = scaleMap.s1(); 136 double v2 = scaleMap.s2(); 139 137 140 v1 = scaleMap.transform( v1 ); // scaleMap.p1() 141 v2 = scaleMap.transform( v2 ); // scaleMap.p2() 138 if ( scaleMap.transformation() ) 139 { 140 // the coordinate system of the paint device is always linear 141 142 v1 = scaleMap.transform( v1 ); // scaleMap.p1() 143 v2 = scaleMap.transform( v2 ); // scaleMap.p2() 144 } 145 146 const double center = 0.5 * ( v1 + v2 ); 147 const double width_2 = 0.5 * ( v2 - v1 ) * factor; 148 149 v1 = center - width_2; 150 v2 = center + width_2; 151 152 if ( scaleMap.transformation() ) 153 { 154 v1 = scaleMap.invTransform( v1 ); 155 v2 = scaleMap.invTransform( v2 ); 156 } 157 158 plt->setAxisScale( axisId, v1, v2 ); 159 doReplot = true; 142 160 } 143 144 const double center = 0.5 * ( v1 + v2 );145 const double width_2 = 0.5 * ( v2 - v1 ) * factor;146 147 v1 = center - width_2;148 v2 = center + width_2;149 150 if ( scaleMap.transformation() )151 {152 v1 = scaleMap.invTransform( v1 );153 v2 = scaleMap.invTransform( v2 );154 }155 156 plt->setAxisScale( axisId, v1, v2 );157 doReplot = true;158 161 } 159 162 } … … 164 167 plt->replot(); 165 168 } 169 170 #include "moc_qwt_plot_magnifier.cpp" -
trunk/BNC/qwt/qwt_plot_magnifier.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PLOT_MAGNIFIER_H 11 #define QWT_PLOT_MAGNIFIER_H 111 #define QWT_PLOT_MAGNIFIER_H 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_axis_id.h" 14 15 #include "qwt_magnifier.h" 15 16 … … 17 18 18 19 /*! 19 \brief QwtPlotMagnifier provides zooming, by magnifying in steps. 20 \brief QwtPlotMagnifier provides zooming, by magnifying in steps. 20 21 21 Using QwtPlotMagnifier a plot can be zoomed in/out in steps using 22 keys, the mouse wheel or moving a mouse button in vertical direction. 22 Using QwtPlotMagnifier a plot can be zoomed in/out in steps using 23 keys, the mouse wheel or moving a mouse button in vertical direction. 23 24 24 Together with QwtPlotZoomer and QwtPlotPanner it is possible to implement 25 individual and powerful navigation of the plot canvas. 25 Together with QwtPlotZoomer and QwtPlotPanner it is possible to implement 26 individual and powerful navigation of the plot canvas. 26 27 27 \sa QwtPlotZoomer, QwtPlotPanner, QwtPlot 28 */ 29 class QWT_EXPORT QwtPlotMagnifier: public QwtMagnifier 28 \sa QwtPlotZoomer, QwtPlotPanner, QwtPlot 29 */ 30 class QWT_EXPORT QwtPlotMagnifier : public QwtMagnifier 30 31 { 31 32 Q_OBJECT 32 33 33 public: 34 explicit QwtPlotMagnifier( QWidget * );34 public: 35 explicit QwtPlotMagnifier( QWidget* ); 35 36 virtual ~QwtPlotMagnifier(); 36 37 37 void setAxisEnabled( int axis, bool on );38 bool isAxisEnabled( int axis) const;38 void setAxisEnabled( QwtAxisId, bool on ); 39 bool isAxisEnabled( QwtAxisId ) const; 39 40 40 QWidget *canvas();41 const QWidget *canvas() const;41 QWidget* canvas(); 42 const QWidget* canvas() const; 42 43 43 QwtPlot *plot();44 const QwtPlot *plot() const;44 QwtPlot* plot(); 45 const QwtPlot* plot() const; 45 46 46 protected:47 virtual void rescale( double factor ); 47 public Q_SLOTS: 48 virtual void rescale( double factor ) QWT_OVERRIDE; 48 49 49 private: 50 private: 50 51 class PrivateData; 51 PrivateData *d_data;52 PrivateData* m_data; 52 53 }; 53 54 -
trunk/BNC/qwt/qwt_plot_marker.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_symbol.h" 14 14 #include "qwt_text.h" 15 #include "qwt_graphic.h" 15 16 #include "qwt_math.h" 17 16 18 #include <qpainter.h> 17 19 18 20 class QwtPlotMarker::PrivateData 19 21 { 20 public: 21 PrivateData() :22 labelAlignment( Qt::AlignCenter ) ,23 labelOrientation( Qt::Horizontal ) ,24 spacing( 2 ) ,25 symbol( NULL ) ,26 style( QwtPlotMarker::NoLine ) ,27 xValue( 0.0 ) ,28 yValue( 0.0 ) 22 public: 23 PrivateData() 24 : labelAlignment( Qt::AlignCenter ) 25 , labelOrientation( Qt::Horizontal ) 26 , spacing( 2 ) 27 , symbol( NULL ) 28 , style( QwtPlotMarker::NoLine ) 29 , xValue( 0.0 ) 30 , yValue( 0.0 ) 29 31 { 30 32 } … … 41 43 42 44 QPen pen; 43 const QwtSymbol *symbol;45 const QwtSymbol* symbol; 44 46 LineStyle style; 45 47 … … 49 51 50 52 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 51 QwtPlotMarker::QwtPlotMarker( const QString &title ): 52 QwtPlotItem( QwtText( title ) ) 53 { 54 d_data = new PrivateData; 53 QwtPlotMarker::QwtPlotMarker() 54 { 55 m_data = new PrivateData; 55 56 setZ( 30.0 ); 56 57 } 57 58 58 59 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 59 QwtPlotMarker::QwtPlotMarker( const QwtText &title ): 60 QwtPlotItem( title ) 61 { 62 d_data = new PrivateData; 60 QwtPlotMarker::QwtPlotMarker( const QString& title ) 61 : QwtPlotItem( QwtText( title ) ) 62 { 63 m_data = new PrivateData; 64 setZ( 30.0 ); 65 } 66 67 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 68 QwtPlotMarker::QwtPlotMarker( const QwtText& title ) 69 : QwtPlotItem( title ) 70 { 71 m_data = new PrivateData; 63 72 setZ( 30.0 ); 64 73 } … … 67 76 QwtPlotMarker::~QwtPlotMarker() 68 77 { 69 delete d_data;78 delete m_data; 70 79 } 71 80 … … 79 88 QPointF QwtPlotMarker::value() const 80 89 { 81 return QPointF( d_data->xValue,d_data->yValue );90 return QPointF( m_data->xValue, m_data->yValue ); 82 91 } 83 92 … … 85 94 double QwtPlotMarker::xValue() const 86 95 { 87 return d_data->xValue;96 return m_data->xValue; 88 97 } 89 98 … … 91 100 double QwtPlotMarker::yValue() const 92 101 { 93 return d_data->yValue;102 return m_data->yValue; 94 103 } 95 104 … … 103 112 void QwtPlotMarker::setValue( double x, double y ) 104 113 { 105 if ( x != d_data->xValue || y !=d_data->yValue )106 { 107 d_data->xValue = x;108 d_data->yValue = y;114 if ( x != m_data->xValue || y != m_data->yValue ) 115 { 116 m_data->xValue = x; 117 m_data->yValue = y; 109 118 itemChanged(); 110 119 } … … 114 123 void QwtPlotMarker::setXValue( double x ) 115 124 { 116 setValue( x, d_data->yValue );125 setValue( x, m_data->yValue ); 117 126 } 118 127 … … 120 129 void QwtPlotMarker::setYValue( double y ) 121 130 { 122 setValue( d_data->xValue, y ); 123 } 124 125 /*! 126 Draw the marker 127 128 \param painter Painter 129 \param xMap x Scale Map 130 \param yMap y Scale Map 131 \param canvasRect Contents rectangle of the canvas in painter coordinates 132 */ 133 void QwtPlotMarker::draw( QPainter *painter, 134 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 135 const QRectF &canvasRect ) const 136 { 137 const QPointF pos( xMap.transform( d_data->xValue ), 138 yMap.transform( d_data->yValue ) ); 139 140 // draw lines 131 setValue( m_data->xValue, y ); 132 } 133 134 /*! 135 Draw the marker 136 137 \param painter Painter 138 \param xMap x Scale Map 139 \param yMap y Scale Map 140 \param canvasRect Contents rectangle of the canvas in painter coordinates 141 */ 142 void QwtPlotMarker::draw( QPainter* painter, 143 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 144 const QRectF& canvasRect ) const 145 { 146 const QPointF pos( xMap.transform( m_data->xValue ), 147 yMap.transform( m_data->yValue ) ); 141 148 142 149 drawLines( painter, canvasRect, pos ); 143 144 // draw symbol 145 if ( d_data->symbol && 146 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) 147 { 148 const QSizeF sz = d_data->symbol->size(); 149 150 const QRectF clipRect = canvasRect.adjusted( 151 -sz.width(), -sz.height(), sz.width(), sz.height() ); 152 153 if ( clipRect.contains( pos ) ) 154 d_data->symbol->drawSymbol( painter, pos ); 155 } 156 150 drawSymbol( painter, canvasRect, pos ); 157 151 drawLabel( painter, canvasRect, pos ); 158 152 } 159 153 160 154 /*! 161 Draw the lines marker 162 163 \param painter Painter 164 \param canvasRect Contents rectangle of the canvas in painter coordinates 165 \param pos Position of the marker, translated into widget coordinates 166 167 \sa drawLabel(), QwtSymbol::drawSymbol()168 */ 169 void QwtPlotMarker::drawLines( QPainter *painter,170 const QRectF &canvasRect, const QPointF&pos ) const171 { 172 if ( d_data->style == NoLine )155 Draw the lines marker 156 157 \param painter Painter 158 \param canvasRect Contents rectangle of the canvas in painter coordinates 159 \param pos Position of the marker, translated into widget coordinates 160 161 \sa drawLabel(), drawSymbol() 162 */ 163 void QwtPlotMarker::drawLines( QPainter* painter, 164 const QRectF& canvasRect, const QPointF& pos ) const 165 { 166 if ( m_data->style == NoLine ) 173 167 return; 174 168 175 169 const bool doAlign = QwtPainter::roundingAlignment( painter ); 176 170 177 painter->setPen( d_data->pen );178 if ( d_data->style == QwtPlotMarker::HLine ||179 d_data->style == QwtPlotMarker::Cross )171 painter->setPen( m_data->pen ); 172 if ( m_data->style == QwtPlotMarker::HLine || 173 m_data->style == QwtPlotMarker::Cross ) 180 174 { 181 175 double y = pos.y(); … … 186 180 y, canvasRect.right() - 1.0, y ); 187 181 } 188 if ( d_data->style == QwtPlotMarker::VLine ||189 d_data->style == QwtPlotMarker::Cross )182 if ( m_data->style == QwtPlotMarker::VLine || 183 m_data->style == QwtPlotMarker::Cross ) 190 184 { 191 185 double x = pos.x(); … … 199 193 200 194 /*! 201 Align and draw thetext label of the marker202 203 \param painter Painter 204 \param canvasRect Contents rectangle of the canvas in painter coordinates 205 \param pos Position of the marker, translated into widget coordinates 206 207 \sa drawLabel(), QwtSymbol::drawSymbol() 208 */ 209 void QwtPlotMarker::draw Label( QPainter*painter,210 const QRectF &canvasRect, const QPointF&pos ) const211 { 212 if ( d_data->label.isEmpty())195 Draw the symbol of the marker 196 197 \param painter Painter 198 \param canvasRect Contents rectangle of the canvas in painter coordinates 199 \param pos Position of the marker, translated into widget coordinates 200 201 \sa drawLabel(), QwtSymbol::drawSymbol() 202 */ 203 void QwtPlotMarker::drawSymbol( QPainter* painter, 204 const QRectF& canvasRect, const QPointF& pos ) const 205 { 206 if ( m_data->symbol == NULL ) 213 207 return; 214 208 215 Qt::Alignment align = d_data->labelAlignment; 209 const QwtSymbol& symbol = *m_data->symbol; 210 211 if ( symbol.style() != QwtSymbol::NoSymbol ) 212 { 213 const QSizeF sz = symbol.size(); 214 215 const QRectF clipRect = canvasRect.adjusted( 216 -sz.width(), -sz.height(), sz.width(), sz.height() ); 217 218 if ( clipRect.contains( pos ) ) 219 symbol.drawSymbol( painter, pos ); 220 } 221 } 222 223 /*! 224 Align and draw the text label of the marker 225 226 \param painter Painter 227 \param canvasRect Contents rectangle of the canvas in painter coordinates 228 \param pos Position of the marker, translated into widget coordinates 229 230 \sa drawLabel(), drawSymbol() 231 */ 232 void QwtPlotMarker::drawLabel( QPainter* painter, 233 const QRectF& canvasRect, const QPointF& pos ) const 234 { 235 if ( m_data->label.isEmpty() ) 236 return; 237 238 Qt::Alignment align = m_data->labelAlignment; 216 239 QPointF alignPos = pos; 217 240 218 241 QSizeF symbolOff( 0, 0 ); 219 242 220 switch ( d_data->style )243 switch ( m_data->style ) 221 244 { 222 245 case QwtPlotMarker::VLine: … … 225 248 // the alignment flags are relative to the canvas 226 249 227 if ( d_data->labelAlignment & Qt::AlignTop )250 if ( m_data->labelAlignment & Qt::AlignTop ) 228 251 { 229 252 alignPos.setY( canvasRect.top() ); … … 231 254 align |= Qt::AlignBottom; 232 255 } 233 else if ( d_data->labelAlignment & Qt::AlignBottom )256 else if ( m_data->labelAlignment & Qt::AlignBottom ) 234 257 { 235 258 // In HLine-style the x-position is pointless and … … 248 271 case QwtPlotMarker::HLine: 249 272 { 250 if ( d_data->labelAlignment & Qt::AlignLeft )273 if ( m_data->labelAlignment & Qt::AlignLeft ) 251 274 { 252 275 alignPos.setX( canvasRect.left() ); … … 254 277 align |= Qt::AlignRight; 255 278 } 256 else if ( d_data->labelAlignment & Qt::AlignRight )279 else if ( m_data->labelAlignment & Qt::AlignRight ) 257 280 { 258 281 alignPos.setX( canvasRect.right() - 1 ); … … 268 291 default: 269 292 { 270 if ( d_data->symbol &&271 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )293 if ( m_data->symbol && 294 ( m_data->symbol->style() != QwtSymbol::NoSymbol ) ) 272 295 { 273 symbolOff = d_data->symbol->size() + QSizeF( 1, 1 );296 symbolOff = m_data->symbol->size() + QSizeF( 1, 1 ); 274 297 symbolOff /= 2; 275 298 } … … 277 300 } 278 301 279 qreal pw2 = d_data->pen.widthF() / 2.0;302 qreal pw2 = m_data->pen.widthF() / 2.0; 280 303 if ( pw2 == 0.0 ) 281 304 pw2 = 0.5; 282 305 283 const int spacing = d_data->spacing;284 285 const qreal xOff = q Max( pw2, symbolOff.width() );286 const qreal yOff = q Max( pw2, symbolOff.height() );287 288 const QSizeF textSize = d_data->label.textSize( painter->font() );306 const int spacing = m_data->spacing; 307 308 const qreal xOff = qwtMaxF( pw2, symbolOff.width() ); 309 const qreal yOff = qwtMaxF( pw2, symbolOff.height() ); 310 311 const QSizeF textSize = m_data->label.textSize( painter->font() ); 289 312 290 313 if ( align & Qt::AlignLeft ) 291 314 { 292 315 alignPos.rx() -= xOff + spacing; 293 if ( d_data->labelOrientation == Qt::Vertical )316 if ( m_data->labelOrientation == Qt::Vertical ) 294 317 alignPos.rx() -= textSize.height(); 295 318 else … … 302 325 else 303 326 { 304 if ( d_data->labelOrientation == Qt::Vertical )327 if ( m_data->labelOrientation == Qt::Vertical ) 305 328 alignPos.rx() -= textSize.height() / 2; 306 329 else … … 311 334 { 312 335 alignPos.ry() -= yOff + spacing; 313 if ( d_data->labelOrientation != Qt::Vertical )336 if ( m_data->labelOrientation != Qt::Vertical ) 314 337 alignPos.ry() -= textSize.height(); 315 338 } … … 317 340 { 318 341 alignPos.ry() += yOff + spacing; 319 if ( d_data->labelOrientation == Qt::Vertical )342 if ( m_data->labelOrientation == Qt::Vertical ) 320 343 alignPos.ry() += textSize.width(); 321 344 } 322 345 else 323 346 { 324 if ( d_data->labelOrientation == Qt::Vertical )347 if ( m_data->labelOrientation == Qt::Vertical ) 325 348 alignPos.ry() += textSize.width() / 2; 326 349 else … … 329 352 330 353 painter->translate( alignPos.x(), alignPos.y() ); 331 if ( d_data->labelOrientation == Qt::Vertical )354 if ( m_data->labelOrientation == Qt::Vertical ) 332 355 painter->rotate( -90.0 ); 333 356 334 357 const QRectF textRect( 0, 0, textSize.width(), textSize.height() ); 335 d_data->label.draw( painter, textRect );336 } 337 338 /*! 339 \brief Set the line style 340 \param style Line style. 341 \sa lineStyle() 342 */ 358 m_data->label.draw( painter, textRect ); 359 } 360 361 /*! 362 \brief Set the line style 363 \param style Line style. 364 \sa lineStyle() 365 */ 343 366 void QwtPlotMarker::setLineStyle( LineStyle style ) 344 367 { 345 if ( style != d_data->style )346 { 347 d_data->style = style;368 if ( style != m_data->style ) 369 { 370 m_data->style = style; 348 371 349 372 legendChanged(); … … 353 376 354 377 /*! 355 \return the line style 356 \sa setLineStyle() 357 */ 378 \return the line style 379 \sa setLineStyle() 380 */ 358 381 QwtPlotMarker::LineStyle QwtPlotMarker::lineStyle() const 359 382 { 360 return d_data->style;361 } 362 363 /*! 364 \brief Assign a symbol 365 \param symbol New symbol 366 \sa symbol() 367 */ 368 void QwtPlotMarker::setSymbol( const QwtSymbol *symbol )369 { 370 if ( symbol != d_data->symbol )371 { 372 delete d_data->symbol;373 d_data->symbol = symbol;383 return m_data->style; 384 } 385 386 /*! 387 \brief Assign a symbol 388 \param symbol New symbol 389 \sa symbol() 390 */ 391 void QwtPlotMarker::setSymbol( const QwtSymbol* symbol ) 392 { 393 if ( symbol != m_data->symbol ) 394 { 395 delete m_data->symbol; 396 m_data->symbol = symbol; 374 397 375 398 if ( symbol ) … … 382 405 383 406 /*! 384 \return the symbol 385 \sa setSymbol(), QwtSymbol 386 */ 387 const QwtSymbol *QwtPlotMarker::symbol() const388 { 389 return d_data->symbol;390 } 391 392 /*! 393 \brief Set the label 394 \param label Label text 395 \sa label() 396 */ 407 \return the symbol 408 \sa setSymbol(), QwtSymbol 409 */ 410 const QwtSymbol* QwtPlotMarker::symbol() const 411 { 412 return m_data->symbol; 413 } 414 415 /*! 416 \brief Set the label 417 \param label Label text 418 \sa label() 419 */ 397 420 void QwtPlotMarker::setLabel( const QwtText& label ) 398 421 { 399 if ( label != d_data->label )400 { 401 d_data->label = label;422 if ( label != m_data->label ) 423 { 424 m_data->label = label; 402 425 itemChanged(); 403 426 } … … 405 428 406 429 /*! 407 \return the label 408 \sa setLabel() 409 */ 430 \return the label 431 \sa setLabel() 432 */ 410 433 QwtText QwtPlotMarker::label() const 411 434 { 412 return d_data->label;413 } 414 415 /*! 416 \brief Set the alignment of the label 417 418 In case of QwtPlotMarker::HLine the alignment is relative to the 419 y position of the marker, but the horizontal flags correspond to the 420 canvas rectangle. In case of QwtPlotMarker::VLine the alignment is 421 relative to the x position of the marker, but the vertical flags 422 correspond to the canvas rectangle. 423 424 In all other styles the alignment is relative to the marker's position. 425 426 \param align Alignment. 427 \sa labelAlignment(), labelOrientation() 428 */ 435 return m_data->label; 436 } 437 438 /*! 439 \brief Set the alignment of the label 440 441 In case of QwtPlotMarker::HLine the alignment is relative to the 442 y position of the marker, but the horizontal flags correspond to the 443 canvas rectangle. In case of QwtPlotMarker::VLine the alignment is 444 relative to the x position of the marker, but the vertical flags 445 correspond to the canvas rectangle. 446 447 In all other styles the alignment is relative to the marker's position. 448 449 \param align Alignment. 450 \sa labelAlignment(), labelOrientation() 451 */ 429 452 void QwtPlotMarker::setLabelAlignment( Qt::Alignment align ) 430 453 { 431 if ( align != d_data->labelAlignment )432 { 433 d_data->labelAlignment = align;454 if ( align != m_data->labelAlignment ) 455 { 456 m_data->labelAlignment = align; 434 457 itemChanged(); 435 458 } … … 437 460 438 461 /*! 439 \return the label alignment 440 \sa setLabelAlignment(), setLabelOrientation() 441 */ 462 \return the label alignment 463 \sa setLabelAlignment(), setLabelOrientation() 464 */ 442 465 Qt::Alignment QwtPlotMarker::labelAlignment() const 443 466 { 444 return d_data->labelAlignment;445 } 446 447 /*! 448 \brief Set the orientation of the label 449 450 When orientation is Qt::Vertical the label is rotated by 90.0 degrees 451 ( from bottom to top ). 452 453 \param orientation Orientation of the label 454 455 \sa labelOrientation(), setLabelAlignment() 456 */ 467 return m_data->labelAlignment; 468 } 469 470 /*! 471 \brief Set the orientation of the label 472 473 When orientation is Qt::Vertical the label is rotated by 90.0 degrees 474 ( from bottom to top ). 475 476 \param orientation Orientation of the label 477 478 \sa labelOrientation(), setLabelAlignment() 479 */ 457 480 void QwtPlotMarker::setLabelOrientation( Qt::Orientation orientation ) 458 481 { 459 if ( orientation != d_data->labelOrientation )460 { 461 d_data->labelOrientation = orientation;482 if ( orientation != m_data->labelOrientation ) 483 { 484 m_data->labelOrientation = orientation; 462 485 itemChanged(); 463 486 } … … 465 488 466 489 /*! 467 \return the label orientation 468 \sa setLabelOrientation(), labelAlignment() 469 */ 490 \return the label orientation 491 \sa setLabelOrientation(), labelAlignment() 492 */ 470 493 Qt::Orientation QwtPlotMarker::labelOrientation() const 471 494 { 472 return d_data->labelOrientation;473 } 474 475 /*! 476 \brief Set the spacing 477 478 When the label is not centered on the marker position, the spacing 479 is the distance between the position and the label. 480 481 \param spacing Spacing 482 \sa spacing(), setLabelAlignment() 483 */ 495 return m_data->labelOrientation; 496 } 497 498 /*! 499 \brief Set the spacing 500 501 When the label is not centered on the marker position, the spacing 502 is the distance between the position and the label. 503 504 \param spacing Spacing 505 \sa spacing(), setLabelAlignment() 506 */ 484 507 void QwtPlotMarker::setSpacing( int spacing ) 485 508 { … … 487 510 spacing = 0; 488 511 489 if ( spacing == d_data->spacing )512 if ( spacing == m_data->spacing ) 490 513 return; 491 514 492 d_data->spacing = spacing;515 m_data->spacing = spacing; 493 516 itemChanged(); 494 517 } 495 518 496 519 /*! 497 \return the spacing 498 \sa setSpacing() 499 */ 520 \return the spacing 521 \sa setSpacing() 522 */ 500 523 int QwtPlotMarker::spacing() const 501 524 { 502 return d_data->spacing;503 } 504 505 /*! 506 Build and assign a line pen 507 508 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 509 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 510 to hide this incompatibility. 511 512 \param color Pen color 513 \param width Pen width 514 \param style Pen style 515 516 \sa pen(), brush() 517 */ 518 void QwtPlotMarker::setLinePen( const QColor &color, qreal width, Qt::PenStyle style )525 return m_data->spacing; 526 } 527 528 /*! 529 Build and assign a line pen 530 531 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 532 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 533 to hide this incompatibility. 534 535 \param color Pen color 536 \param width Pen width 537 \param style Pen style 538 539 \sa pen(), brush() 540 */ 541 void QwtPlotMarker::setLinePen( const QColor& color, qreal width, Qt::PenStyle style ) 519 542 { 520 543 setLinePen( QPen( color, width, style ) ); … … 522 545 523 546 /*! 524 Specify a pen for the line. 525 526 \param pen New pen 527 \sa linePen() 528 */ 529 void QwtPlotMarker::setLinePen( const QPen &pen )530 { 531 if ( pen != d_data->pen )532 { 533 d_data->pen = pen;547 Specify a pen for the line. 548 549 \param pen New pen 550 \sa linePen() 551 */ 552 void QwtPlotMarker::setLinePen( const QPen& pen ) 553 { 554 if ( pen != m_data->pen ) 555 { 556 m_data->pen = pen; 534 557 535 558 legendChanged(); … … 539 562 540 563 /*! 541 \return the line pen 542 \sa setLinePen() 543 */ 544 const QPen &QwtPlotMarker::linePen() const545 { 546 return d_data->pen;564 \return the line pen 565 \sa setLinePen() 566 */ 567 const QPen& QwtPlotMarker::linePen() const 568 { 569 return m_data->pen; 547 570 } 548 571 … … 551 574 // width/height of -1 does not affect the autoscale calculation 552 575 553 switch ( d_data->style)576 switch (m_data->style) 554 577 { 555 578 case QwtPlotMarker::HLine: 556 return QRectF( d_data->xValue,d_data->yValue, -1.0, 0.0 );579 return QRectF( m_data->xValue, m_data->yValue, -1.0, 0.0 ); 557 580 558 581 case QwtPlotMarker::VLine: 559 return QRectF( d_data->xValue,d_data->yValue, 0.0, -1.0 );560 561 default :562 return QRectF( d_data->xValue,d_data->yValue, 0.0, 0.0 );582 return QRectF( m_data->xValue, m_data->yValue, 0.0, -1.0 ); 583 584 default: 585 return QRectF( m_data->xValue, m_data->yValue, 0.0, 0.0 ); 563 586 } 564 587 } … … 572 595 573 596 \sa setLegendIconSize(), legendData() 574 */ 575 QwtGraphic QwtPlotMarker::legendIcon( int index, 576 const QSizeF &size ) const 597 */ 598 QwtGraphic QwtPlotMarker::legendIcon( int index, const QSizeF& size ) const 577 599 { 578 600 Q_UNUSED( index ); … … 589 611 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 590 612 591 if ( d_data->style != QwtPlotMarker::NoLine )592 { 593 painter.setPen( d_data->pen );594 595 if ( d_data->style == QwtPlotMarker::HLine ||596 d_data->style == QwtPlotMarker::Cross )613 if ( m_data->style != QwtPlotMarker::NoLine ) 614 { 615 painter.setPen( m_data->pen ); 616 617 if ( m_data->style == QwtPlotMarker::HLine || 618 m_data->style == QwtPlotMarker::Cross ) 597 619 { 598 620 const double y = 0.5 * size.height(); … … 602 624 } 603 625 604 if ( d_data->style == QwtPlotMarker::VLine ||605 d_data->style == QwtPlotMarker::Cross )626 if ( m_data->style == QwtPlotMarker::VLine || 627 m_data->style == QwtPlotMarker::Cross ) 606 628 { 607 629 const double x = 0.5 * size.width(); … … 612 634 } 613 635 614 if ( d_data->symbol )636 if ( m_data->symbol ) 615 637 { 616 638 const QRect r( 0.0, 0.0, size.width(), size.height() ); 617 d_data->symbol->drawSymbol( &painter, r );639 m_data->symbol->drawSymbol( &painter, r ); 618 640 } 619 641 -
trunk/BNC/qwt/qwt_plot_marker.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #define QWT_PLOT_MARKER_H 12 12 13 #include <qpen.h>14 #include <qfont.h>15 #include <qstring.h>16 #include <qbrush.h>17 13 #include "qwt_global.h" 18 14 #include "qwt_plot_item.h" 19 15 16 class QString; 20 17 class QRectF; 21 18 class QwtText; … … 23 20 24 21 /*! 25 \brief A class for drawing markers 22 \brief A class for drawing markers 26 23 27 A marker can be a horizontal line, a vertical line, 28 a symbol, a label or any combination of them, which can 29 be drawn around a center point inside a bounding rectangle. 24 A marker can be a horizontal line, a vertical line, 25 a symbol, a label or any combination of them, which can 26 be drawn around a center point inside a bounding rectangle. 30 27 31 The setSymbol() member assigns a symbol to the marker. 32 The symbol is drawn at the specified point. 28 The setSymbol() member assigns a symbol to the marker. 29 The symbol is drawn at the specified point. 33 30 34 With setLabel(), a label can be assigned to the marker. 35 The setLabelAlignment() member specifies where the label is 36 drawn. All the Align*-constants in Qt::AlignmentFlags (see Qt documentation) 37 are valid. The interpretation of the alignment depends on the marker's 38 line style. The alignment refers to the center point of 39 the marker, which means, for example, that the label would be printed 40 left above the center point if the alignment was set to 41 Qt::AlignLeft | Qt::AlignTop. 31 With setLabel(), a label can be assigned to the marker. 32 The setLabelAlignment() member specifies where the label is 33 drawn. All the Align*-constants in Qt::AlignmentFlags (see Qt documentation) 34 are valid. The interpretation of the alignment depends on the marker's 35 line style. The alignment refers to the center point of 36 the marker, which means, for example, that the label would be printed 37 left above the center point if the alignment was set to 38 Qt::AlignLeft | Qt::AlignTop. 42 39 43 \note QwtPlotTextLabel is intended to align a text label 40 \note QwtPlotTextLabel is intended to align a text label 44 41 according to the geometry of canvas 45 42 ( unrelated to plot coordinates ) 46 */ 43 */ 47 44 48 class QWT_EXPORT QwtPlotMarker: public QwtPlotItem 45 class QWT_EXPORT QwtPlotMarker : public QwtPlotItem 49 46 { 50 public: 47 public: 51 48 52 49 /*! 53 50 Line styles. 54 51 \sa setLineStyle(), lineStyle() 55 */ 52 */ 56 53 enum LineStyle 57 54 { … … 69 66 }; 70 67 71 explicit QwtPlotMarker( const QString &title = QString() ); 72 explicit QwtPlotMarker( const QwtText &title ); 68 explicit QwtPlotMarker(); 69 explicit QwtPlotMarker( const QString& title ); 70 explicit QwtPlotMarker( const QwtText& title ); 73 71 74 72 virtual ~QwtPlotMarker(); 75 73 76 virtual int rtti() const; 74 virtual int rtti() const QWT_OVERRIDE; 77 75 78 76 double xValue() const; … … 83 81 void setYValue( double ); 84 82 void setValue( double, double ); 85 void setValue( const QPointF & );83 void setValue( const QPointF& ); 86 84 87 85 void setLineStyle( LineStyle ); 88 86 LineStyle lineStyle() const; 89 87 90 void setLinePen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );91 void setLinePen( const QPen & );92 const QPen &linePen() const;88 void setLinePen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 89 void setLinePen( const QPen& ); 90 const QPen& linePen() const; 93 91 94 void setSymbol( const QwtSymbol * );95 const QwtSymbol *symbol() const;92 void setSymbol( const QwtSymbol* ); 93 const QwtSymbol* symbol() const; 96 94 97 95 void setLabel( const QwtText& ); … … 107 105 int spacing() const; 108 106 109 virtual void draw( QPainter *,110 const QwtScaleMap &xMap, const QwtScaleMap&yMap,111 const QRectF & ) const;107 virtual void draw( QPainter*, 108 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 109 const QRectF& ) const QWT_OVERRIDE; 112 110 113 virtual QRectF boundingRect() const; 111 virtual QRectF boundingRect() const QWT_OVERRIDE; 114 112 115 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 113 virtual QwtGraphic legendIcon( 114 int index, const QSizeF& ) const QWT_OVERRIDE; 116 115 117 protected: 118 virtual void drawLines( QPainter *,119 const QRectF &, const QPointF& ) const;116 protected: 117 virtual void drawLines( QPainter*, 118 const QRectF&, const QPointF& ) const; 120 119 121 virtual void draw Label( QPainter*,122 const QRectF &, const QPointF& ) const;120 virtual void drawSymbol( QPainter*, 121 const QRectF&, const QPointF& ) const; 123 122 124 private: 123 virtual void drawLabel( QPainter*, 124 const QRectF&, const QPointF& ) const; 125 126 private: 125 127 126 128 class PrivateData; 127 PrivateData *d_data;129 PrivateData* m_data; 128 130 }; 129 131 -
trunk/BNC/qwt/qwt_plot_multi_barchart.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_map.h" 12 12 #include "qwt_column_symbol.h" 13 #include "qwt_painter.h" 14 #include <qpainter.h> 15 #include <qpalette.h> 13 #include "qwt_text.h" 14 #include "qwt_graphic.h" 15 #include "qwt_legend_data.h" 16 #include "qwt_math.h" 17 16 18 #include <qmap.h> 17 19 18 20 inline static bool qwtIsIncreasing( 19 const QwtScaleMap &map, const QVector<double> &values )21 const QwtScaleMap& map, const QVector< double >& values ) 20 22 { 21 23 bool isInverting = map.isInverting(); … … 33 35 class QwtPlotMultiBarChart::PrivateData 34 36 { 35 public: 36 PrivateData() :37 style( QwtPlotMultiBarChart::Grouped ) 37 public: 38 PrivateData() 39 : style( QwtPlotMultiBarChart::Grouped ) 38 40 { 39 41 } 40 42 41 43 QwtPlotMultiBarChart::ChartStyle style; 42 QList< QwtText> barTitles;43 QMap<int, QwtColumnSymbol *> symbolMap;44 QList< QwtText > barTitles; 45 QMap< int, QwtColumnSymbol* > symbolMap; 44 46 }; 45 47 46 48 /*! 47 Constructor 48 \param title Title of the chart 49 */ 50 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QwtText &title ):51 QwtPlotAbstractBarChart( title ) 49 Constructor 50 \param title Title of the chart 51 */ 52 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QwtText& title ) 53 : QwtPlotAbstractBarChart( title ) 52 54 { 53 55 init(); … … 55 57 56 58 /*! 57 Constructor 58 \param title Title of the chart 59 */ 60 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QString &title ):61 QwtPlotAbstractBarChart( QwtText( title ) ) 59 Constructor 60 \param title Title of the chart 61 */ 62 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QString& title ) 63 : QwtPlotAbstractBarChart( QwtText( title ) ) 62 64 { 63 65 init(); … … 68 70 { 69 71 resetSymbolMap(); 70 delete d_data;72 delete m_data; 71 73 } 72 74 73 75 void QwtPlotMultiBarChart::init() 74 76 { 75 d_data = new PrivateData;77 m_data = new PrivateData; 76 78 setData( new QwtSetSeriesData() ); 77 79 } … … 84 86 85 87 /*! 86 Initialize data with an array of samples. 87 \param samples Vector of points 88 */ 88 Initialize data with an array of samples. 89 \param samples Vector of points 90 */ 89 91 void QwtPlotMultiBarChart::setSamples( 90 const QVector<QwtSetSample > &samples )92 const QVector< QwtSetSample >& samples ) 91 93 { 92 94 setData( new QwtSetSeriesData( samples ) ); … … 94 96 95 97 /*! 96 Initialize data with an array of samples. 97 \param samples Vector of points 98 */ 98 Initialize data with an array of samples. 99 \param samples Vector of points 100 */ 99 101 void QwtPlotMultiBarChart::setSamples( 100 const QVector< QVector<double> > &samples ) 101 { 102 QVector<QwtSetSample> s; 102 const QVector< QVector< double > >& samples ) 103 { 104 QVector< QwtSetSample > s; 105 s.reserve( samples.size() ); 106 103 107 for ( int i = 0; i < samples.size(); i++ ) 104 108 s += QwtSetSample( i, samples[ i ] ); … … 108 112 109 113 /*! 110 Assign a series of samples 111 112 setSamples() is just a wrapper for setData() without any additional 113 value - beside that it is easier to find for the developer. 114 115 \param data Data 116 \warning The item takes ownership of the data object, deleting 114 Assign a series of samples 115 116 setSamples() is just a wrapper for setData() without any additional 117 value - beside that it is easier to find for the developer. 118 119 \param data Data 120 \warning The item takes ownership of the data object, deleting 117 121 it when its not used anymore. 118 */ 122 */ 119 123 void QwtPlotMultiBarChart::setSamples( 120 QwtSeriesData<QwtSetSample > *data )124 QwtSeriesData< QwtSetSample >* data ) 121 125 { 122 126 setData( data ); … … 124 128 125 129 /*! 126 \brief Set the titles for the bars 127 128 The titles are used for the legend. 129 130 \param titles Bar titles 131 132 \sa barTitles(), legendData() 133 */ 134 void QwtPlotMultiBarChart::setBarTitles( const QList<QwtText > &titles )135 { 136 d_data->barTitles = titles;130 \brief Set the titles for the bars 131 132 The titles are used for the legend. 133 134 \param titles Bar titles 135 136 \sa barTitles(), legendData() 137 */ 138 void QwtPlotMultiBarChart::setBarTitles( const QList< QwtText >& titles ) 139 { 140 m_data->barTitles = titles; 137 141 itemChanged(); 138 142 } 139 143 140 144 /*! 141 \return Bar titles 142 \sa setBarTitles(), legendData() 143 */ 144 QList< QwtText> QwtPlotMultiBarChart::barTitles() const145 { 146 return d_data->barTitles;147 } 148 149 /*! 150 \brief Add a symbol to the symbol map 151 152 Assign a default symbol for drawing the bar representing all values 153 with the same index in a set. 154 155 \param valueIndex Index of a value in a set 156 \param symbol Symbol used for drawing a bar 157 158 \sa symbol(), resetSymbolMap(), specialSymbol() 159 */ 160 void QwtPlotMultiBarChart::setSymbol( int valueIndex, QwtColumnSymbol *symbol )145 \return Bar titles 146 \sa setBarTitles(), legendData() 147 */ 148 QList< QwtText > QwtPlotMultiBarChart::barTitles() const 149 { 150 return m_data->barTitles; 151 } 152 153 /*! 154 \brief Add a symbol to the symbol map 155 156 Assign a default symbol for drawing the bar representing all values 157 with the same index in a set. 158 159 \param valueIndex Index of a value in a set 160 \param symbol Symbol used for drawing a bar 161 162 \sa symbol(), resetSymbolMap(), specialSymbol() 163 */ 164 void QwtPlotMultiBarChart::setSymbol( int valueIndex, QwtColumnSymbol* symbol ) 161 165 { 162 166 if ( valueIndex < 0 ) 163 167 return; 164 168 165 QMap<int, QwtColumnSymbol *>::iterator it =166 d_data->symbolMap.find(valueIndex);167 if ( it == d_data->symbolMap.end() )169 QMap< int, QwtColumnSymbol* >::iterator it = 170 m_data->symbolMap.find(valueIndex); 171 if ( it == m_data->symbolMap.end() ) 168 172 { 169 173 if ( symbol != NULL ) 170 174 { 171 d_data->symbolMap.insert( valueIndex, symbol );175 m_data->symbolMap.insert( valueIndex, symbol ); 172 176 173 177 legendChanged(); … … 183 187 if ( symbol == NULL ) 184 188 { 185 d_data->symbolMap.remove( valueIndex );189 m_data->symbolMap.remove( valueIndex ); 186 190 } 187 191 else … … 197 201 198 202 /*! 199 Find a symbol in the symbol map 200 201 \param valueIndex Index of a value in a set 202 \return The symbol, that had been set by setSymbol() or NULL. 203 204 \sa setSymbol(), specialSymbol(), drawBar() 205 */ 206 const QwtColumnSymbol *QwtPlotMultiBarChart::symbol( int valueIndex ) const207 { 208 QMap<int, QwtColumnSymbol *>::const_iterator it =209 d_data->symbolMap.constFind( valueIndex );210 211 return ( it == d_data->symbolMap.constEnd() ) ? NULL : it.value();212 } 213 214 /*! 215 Find a symbol in the symbol map 216 217 \param valueIndex Index of a value in a set 218 \return The symbol, that had been set by setSymbol() or NULL. 219 220 \sa setSymbol(), specialSymbol(), drawBar() 221 */ 222 QwtColumnSymbol *QwtPlotMultiBarChart::symbol( int valueIndex )223 { 224 QMap<int, QwtColumnSymbol *>::const_iterator it =225 d_data->symbolMap.constFind( valueIndex );226 227 return ( it == d_data->symbolMap.constEnd() ) ? NULL : it.value();228 } 229 230 /*! 231 Remove all symbols from the symbol map 203 Find a symbol in the symbol map 204 205 \param valueIndex Index of a value in a set 206 \return The symbol, that had been set by setSymbol() or NULL. 207 208 \sa setSymbol(), specialSymbol(), drawBar() 209 */ 210 const QwtColumnSymbol* QwtPlotMultiBarChart::symbol( int valueIndex ) const 211 { 212 QMap< int, QwtColumnSymbol* >::const_iterator it = 213 m_data->symbolMap.constFind( valueIndex ); 214 215 return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value(); 216 } 217 218 /*! 219 Find a symbol in the symbol map 220 221 \param valueIndex Index of a value in a set 222 \return The symbol, that had been set by setSymbol() or NULL. 223 224 \sa setSymbol(), specialSymbol(), drawBar() 225 */ 226 QwtColumnSymbol* QwtPlotMultiBarChart::symbol( int valueIndex ) 227 { 228 QMap< int, QwtColumnSymbol* >::const_iterator it = 229 m_data->symbolMap.constFind( valueIndex ); 230 231 return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value(); 232 } 233 234 /*! 235 Remove all symbols from the symbol map 232 236 */ 233 237 void QwtPlotMultiBarChart::resetSymbolMap() 234 238 { 235 qDeleteAll( d_data->symbolMap );236 d_data->symbolMap.clear();237 } 238 239 /*! 240 \brief Create a symbol for special values 241 242 Usually the symbols for displaying a bar are set by setSymbols() and 243 common for all sets. By overloading specialSymbol() it is possible to 244 create a temporary symbol() for displaying a special value. 245 246 The symbol has to be created by new each time specialSymbol() is 247 called. As soon as the symbol is painted this symbol gets deleted. 248 249 When no symbol ( NULL ) is returned, the value will be displayed 250 with the standard symbol that is used for all symbols with the same 251 valueIndex. 252 253 \param sampleIndex Index of the sample 254 \param valueIndex Index of the value in the set 255 256 \return NULL, meaning that the value is not special 257 258 */ 259 QwtColumnSymbol *QwtPlotMultiBarChart::specialSymbol(239 qDeleteAll( m_data->symbolMap ); 240 m_data->symbolMap.clear(); 241 } 242 243 /*! 244 \brief Create a symbol for special values 245 246 Usually the symbols for displaying a bar are set by setSymbols() and 247 common for all sets. By overloading specialSymbol() it is possible to 248 create a temporary symbol() for displaying a special value. 249 250 The symbol has to be created by new each time specialSymbol() is 251 called. As soon as the symbol is painted this symbol gets deleted. 252 253 When no symbol ( NULL ) is returned, the value will be displayed 254 with the standard symbol that is used for all symbols with the same 255 valueIndex. 256 257 \param sampleIndex Index of the sample 258 \param valueIndex Index of the value in the set 259 260 \return NULL, meaning that the value is not special 261 262 */ 263 QwtColumnSymbol* QwtPlotMultiBarChart::specialSymbol( 260 264 int sampleIndex, int valueIndex ) const 261 265 { … … 267 271 268 272 /*! 269 Set the style of the chart 270 271 \param style Chart style 272 \sa style() 273 Set the style of the chart 274 275 \param style Chart style 276 \sa style() 273 277 */ 274 278 void QwtPlotMultiBarChart::setStyle( ChartStyle style ) 275 279 { 276 if ( style != d_data->style )277 { 278 d_data->style = style;280 if ( style != m_data->style ) 281 { 282 m_data->style = style; 279 283 280 284 legendChanged(); … … 284 288 285 289 /*! 286 \return Style of the chart 287 \sa setStyle() 290 \return Style of the chart 291 \sa setStyle() 288 292 */ 289 293 QwtPlotMultiBarChart::ChartStyle QwtPlotMultiBarChart::style() const 290 294 { 291 return d_data->style;292 } 293 294 /*! 295 \return Bounding rectangle of all samples. 296 For an empty series the rectangle is invalid. 297 */ 295 return m_data->style; 296 } 297 298 /*! 299 \return Bounding rectangle of all samples. 300 For an empty series the rectangle is invalid. 301 */ 298 302 QRectF QwtPlotMultiBarChart::boundingRect() const 299 303 { … … 307 311 QRectF rect; 308 312 309 if ( d_data->style != QwtPlotMultiBarChart::Stacked )313 if ( m_data->style != QwtPlotMultiBarChart::Stacked ) 310 314 { 311 315 rect = QwtPlotSeriesItem::boundingRect(); … … 326 330 yMin = yMax = baseLine; 327 331 328 const QwtSeriesData<QwtSetSample > *series = data();332 const QwtSeriesData< QwtSetSample >* series = data(); 329 333 330 334 for ( size_t i = 0; i < numSamples; i++ ) … … 337 341 else 338 342 { 339 xMin = q Min( xMin, sample.value );340 xMax = q Max( xMax, sample.value );343 xMin = qwtMinF( xMin, sample.value ); 344 xMax = qwtMaxF( xMax, sample.value ); 341 345 } 342 346 343 347 const double y = baseLine + sample.added(); 344 348 345 yMin = q Min( yMin, y );346 yMax = q Max( yMax, y );349 yMin = qwtMinF( yMin, y ); 350 yMax = qwtMaxF( yMax, y ); 347 351 } 348 352 rect.setRect( xMin, yMin, xMax - xMin, yMax - yMin ); … … 356 360 357 361 /*! 358 Draw an interval of the bar chart 359 360 \param painter Painter 361 \param xMap Maps x-values into pixel coordinates. 362 \param yMap Maps y-values into pixel coordinates. 363 \param canvasRect Contents rectangle of the canvas 364 \param from Index of the first point to be painted 365 \param to Index of the last point to be painted. If to < 0 the 362 Draw an interval of the bar chart 363 364 \param painter Painter 365 \param xMap Maps x-values into pixel coordinates. 366 \param yMap Maps y-values into pixel coordinates. 367 \param canvasRect Contents rectangle of the canvas 368 \param from Index of the first point to be painted 369 \param to Index of the last point to be painted. If to < 0 the 366 370 curve will be painted to its last point. 367 371 368 \sa drawSymbols() 369 */ 370 void QwtPlotMultiBarChart::drawSeries( QPainter *painter,371 const QwtScaleMap &xMap, const QwtScaleMap&yMap,372 const QRectF &canvasRect, int from, int to ) const372 \sa drawSymbols() 373 */ 374 void QwtPlotMultiBarChart::drawSeries( QPainter* painter, 375 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 376 const QRectF& canvasRect, int from, int to ) const 373 377 { 374 378 if ( to < 0 ) … … 397 401 398 402 /*! 399 Draw a sample 400 401 \param painter Painter 402 \param xMap x map 403 \param yMap y map 404 \param canvasRect Contents rectangle of the canvas 405 \param boundingInterval Bounding interval of sample values 406 \param index Index of the sample to be painted 407 \param sample Sample value 408 409 \sa drawSeries() 410 */ 411 void QwtPlotMultiBarChart::drawSample( QPainter *painter,412 const QwtScaleMap &xMap, const QwtScaleMap&yMap,413 const QRectF &canvasRect, const QwtInterval&boundingInterval,403 Draw a sample 404 405 \param painter Painter 406 \param xMap x map 407 \param yMap y map 408 \param canvasRect Contents rectangle of the canvas 409 \param boundingInterval Bounding interval of sample values 410 \param index Index of the sample to be painted 411 \param sample Sample value 412 413 \sa drawSeries() 414 */ 415 void QwtPlotMultiBarChart::drawSample( QPainter* painter, 416 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 417 const QRectF& canvasRect, const QwtInterval& boundingInterval, 414 418 int index, const QwtSetSample& sample ) const 415 419 { … … 430 434 } 431 435 432 if ( d_data->style == Stacked )436 if ( m_data->style == Stacked ) 433 437 { 434 438 drawStackedBars( painter, xMap, yMap, … … 443 447 444 448 /*! 445 Draw a grouped sample 446 447 \param painter Painter 448 \param xMap x map 449 \param yMap y map 450 \param canvasRect Contents rectangle of the canvas 451 \param index Index of the sample to be painted 452 \param sampleWidth Boundng width for all bars of the s maple453 \param sample Sample 454 455 \sa drawSeries(), sampleWidth() 456 */ 457 void QwtPlotMultiBarChart::drawGroupedBars( QPainter *painter,458 const QwtScaleMap &xMap, const QwtScaleMap&yMap,459 const QRectF &canvasRect, int index, double sampleWidth,449 Draw a grouped sample 450 451 \param painter Painter 452 \param xMap x map 453 \param yMap y map 454 \param canvasRect Contents rectangle of the canvas 455 \param index Index of the sample to be painted 456 \param sampleWidth Bounding width for all bars of the sample 457 \param sample Sample 458 459 \sa drawSeries(), sampleWidth() 460 */ 461 void QwtPlotMultiBarChart::drawGroupedBars( QPainter* painter, 462 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 463 const QRectF& canvasRect, int index, double sampleWidth, 460 464 const QwtSetSample& sample ) const 461 465 { … … 523 527 524 528 /*! 525 Draw a stacked sample 526 527 \param painter Painter 528 \param xMap x map 529 \param yMap y map 530 \param canvasRect Contents rectangle of the canvas 531 \param index Index of the sample to be painted 532 \param sampleWidth Width of the bars 533 \param sample Sample 534 535 \sa drawSeries(), sampleWidth() 536 */ 537 void QwtPlotMultiBarChart::drawStackedBars( QPainter *painter,538 const QwtScaleMap &xMap, const QwtScaleMap&yMap,539 const QRectF &canvasRect, int index,529 Draw a stacked sample 530 531 \param painter Painter 532 \param xMap x map 533 \param yMap y map 534 \param canvasRect Contents rectangle of the canvas 535 \param index Index of the sample to be painted 536 \param sampleWidth Width of the bars 537 \param sample Sample 538 539 \sa drawSeries(), sampleWidth() 540 */ 541 void QwtPlotMultiBarChart::drawStackedBars( QPainter* painter, 542 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 543 const QRectF& canvasRect, int index, 540 544 double sampleWidth, const QwtSetSample& sample ) const 541 545 { … … 636 640 637 641 /*! 638 Draw a bar 639 640 \param painter Painter 641 \param sampleIndex Index of the sample - might be -1 when the 642 Draw a bar 643 644 \param painter Painter 645 \param sampleIndex Index of the sample - might be -1 when the 642 646 bar is painted for the legend 643 \param valueIndex Index of a value in a set 644 \param rect Directed target rectangle for the bar 645 646 \sa drawSeries() 647 */ 648 void QwtPlotMultiBarChart::drawBar( QPainter *painter,649 int sampleIndex, int valueIndex, const QwtColumnRect &rect ) const650 { 651 const QwtColumnSymbol *specialSym = NULL;647 \param valueIndex Index of a value in a set 648 \param rect Directed target rectangle for the bar 649 650 \sa drawSeries() 651 */ 652 void QwtPlotMultiBarChart::drawBar( QPainter* painter, 653 int sampleIndex, int valueIndex, const QwtColumnRect& rect ) const 654 { 655 const QwtColumnSymbol* specialSym = NULL; 652 656 if ( sampleIndex >= 0 ) 653 657 specialSym = specialSymbol( sampleIndex, valueIndex ); 654 658 655 const QwtColumnSymbol *sym = specialSym;659 const QwtColumnSymbol* sym = specialSym; 656 660 if ( sym == NULL ) 657 661 sym = symbol( valueIndex ); … … 674 678 675 679 /*! 676 \return Information to be displayed on the legend 677 678 The chart is represented by a list of entries - one for each bar title. 679 Each element contains a bar title and an icon showing its corresponding bar. 680 681 \sa barTitles(), legendIcon(), legendIconSize() 682 */ 683 QList<QwtLegendData> QwtPlotMultiBarChart::legendData() const 684 { 685 QList<QwtLegendData> list; 686 687 for ( int i = 0; i < d_data->barTitles.size(); i++ ) 680 \return Information to be displayed on the legend 681 682 The chart is represented by a list of entries - one for each bar title. 683 Each element contains a bar title and an icon showing its corresponding bar. 684 685 \sa barTitles(), legendIcon(), legendIconSize() 686 */ 687 QList< QwtLegendData > QwtPlotMultiBarChart::legendData() const 688 { 689 QList< QwtLegendData > list; 690 list.reserve( m_data->barTitles.size() ); 691 692 for ( int i = 0; i < m_data->barTitles.size(); i++ ) 688 693 { 689 694 QwtLegendData data; 690 695 691 QVariant titleValue; 692 qVariantSetValue( titleValue, d_data->barTitles[i] ); 693 data.setValue( QwtLegendData::TitleRole, titleValue ); 696 data.setValue( QwtLegendData::TitleRole, 697 QVariant::fromValue( m_data->barTitles[i] ) ); 694 698 695 699 if ( !legendIconSize().isEmpty() ) 696 700 { 697 QVariant iconValue; 698 qVariantSetValue( iconValue, 699 legendIcon( i, legendIconSize() ) ); 700 701 data.setValue( QwtLegendData::IconRole, iconValue ); 701 data.setValue( QwtLegendData::IconRole, 702 QVariant::fromValue( legendIcon( i, legendIconSize() ) ) ); 702 703 } 703 704 … … 709 710 710 711 /*! 711 \return Icon for representing a bar on the legend 712 713 \param index Index of the bar 714 \param size Icon size 715 716 \return An icon showing a bar 717 \sa drawBar(), legendData() 712 \return Icon for representing a bar on the legend 713 714 \param index Index of the bar 715 \param size Icon size 716 717 \return An icon showing a bar 718 \sa drawBar(), legendData() 718 719 */ 719 720 QwtGraphic QwtPlotMultiBarChart::legendIcon( int index, 720 const QSizeF &size ) const721 const QSizeF& size ) const 721 722 { 722 723 QwtColumnRect column; -
trunk/BNC/qwt/qwt_plot_multi_barchart.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_abstract_barchart.h" 15 #include "qwt_series_data.h"16 15 17 16 class QwtColumnRect; 18 17 class QwtColumnSymbol; 18 template< typename T > class QwtSeriesData; 19 19 20 20 /*! 21 \brief QwtPlotMultiBarChart displays a series of a samples that consist 21 \brief QwtPlotMultiBarChart displays a series of a samples that consist 22 22 each of a set of values. 23 23 24 Each value is displayed as a bar, the bars of each set can be organized 25 side by side or accumulated. 24 Each value is displayed as a bar, the bars of each set can be organized 25 side by side or accumulated. 26 26 27 Each bar of a set is rendered by a QwtColumnSymbol, that is set by setSymbol(). 28 The bars of different sets use the same symbols. Exceptions are possible 29 by overloading specialSymbol() or overloading drawBar(). 27 Each bar of a set is rendered by a QwtColumnSymbol, that is set by setSymbol(). 28 The bars of different sets use the same symbols. Exceptions are possible 29 by overloading specialSymbol() or overloading drawBar(). 30 30 31 Depending on its orientation() the bars are displayed horizontally 32 or vertically. The bars cover the interval between the baseline() 33 and the value. 31 Depending on its orientation() the bars are displayed horizontally 32 or vertically. The bars cover the interval between the baseline() 33 and the value. 34 34 35 In opposite to most other plot items, QwtPlotMultiBarChart returns more 36 than one entry for the legend - one for each symbol. 35 In opposite to most other plot items, QwtPlotMultiBarChart returns more 36 than one entry for the legend - one for each symbol. 37 37 38 \sa QwtPlotBarChart, QwtPlotHistogram 38 \sa QwtPlotBarChart, QwtPlotHistogram 39 39 QwtPlotSeriesItem::orientation(), QwtPlotAbstractBarChart::baseline() 40 40 */ 41 class QWT_EXPORT QwtPlotMultiBarChart: 42 public QwtPlotAbstractBarChart, public QwtSeriesStore<QwtSetSample> 41 class QWT_EXPORT QwtPlotMultiBarChart 42 : public QwtPlotAbstractBarChart 43 , public QwtSeriesStore< QwtSetSample > 43 44 { 44 public: 45 public: 45 46 /*! 46 47 \brief Chart styles. … … 48 49 The default setting is QwtPlotMultiBarChart::Grouped. 49 50 \sa setStyle(), style() 50 */ 51 */ 51 52 enum ChartStyle 52 53 { … … 62 63 }; 63 64 64 explicit QwtPlotMultiBarChart( const QString &title = QString() );65 explicit QwtPlotMultiBarChart( const QwtText &title );65 explicit QwtPlotMultiBarChart( const QString& title = QString() ); 66 explicit QwtPlotMultiBarChart( const QwtText& title ); 66 67 67 68 virtual ~QwtPlotMultiBarChart(); 68 69 69 virtual int rtti() const; 70 virtual int rtti() const QWT_OVERRIDE; 70 71 71 void setBarTitles( const QList<QwtText >& );72 QList< QwtText> barTitles() const;72 void setBarTitles( const QList< QwtText >& ); 73 QList< QwtText > barTitles() const; 73 74 74 void setSamples( const QVector<QwtSetSample >& );75 void setSamples( const QVector< QVector< double> >& );76 void setSamples( QwtSeriesData<QwtSetSample >* );75 void setSamples( const QVector< QwtSetSample >& ); 76 void setSamples( const QVector< QVector< double > >& ); 77 void setSamples( QwtSeriesData< QwtSetSample >* ); 77 78 78 79 void setStyle( ChartStyle style ); 79 80 ChartStyle style() const; 80 81 81 void setSymbol( int valueIndex, QwtColumnSymbol * );82 const QwtColumnSymbol *symbol( int valueIndex ) const;82 void setSymbol( int valueIndex, QwtColumnSymbol* ); 83 const QwtColumnSymbol* symbol( int valueIndex ) const; 83 84 84 85 void resetSymbolMap(); 85 86 86 virtual void drawSeries( QPainter *painter,87 const QwtScaleMap &xMap, const QwtScaleMap&yMap,88 const QRectF &canvasRect, int from, int to ) const;87 virtual void drawSeries( QPainter*, 88 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 89 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 89 90 90 virtual QRectF boundingRect() const; 91 virtual QRectF boundingRect() const QWT_OVERRIDE; 91 92 92 virtual QList<QwtLegendData> legendData() const; 93 virtual QList< QwtLegendData > legendData() const QWT_OVERRIDE; 93 94 94 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 95 virtual QwtGraphic legendIcon( 96 int index, const QSizeF& ) const QWT_OVERRIDE; 95 97 96 protected: 97 QwtColumnSymbol *symbol( int valueIndex );98 protected: 99 QwtColumnSymbol* symbol( int valueIndex ); 98 100 99 virtual QwtColumnSymbol *specialSymbol(101 virtual QwtColumnSymbol* specialSymbol( 100 102 int sampleIndex, int valueIndex ) const; 101 103 102 virtual void drawSample( QPainter *painter,103 const QwtScaleMap &xMap, const QwtScaleMap&yMap,104 const QRectF &canvasRect, const QwtInterval&boundingInterval,105 int index, const QwtSetSample& sample) const;104 virtual void drawSample( QPainter*, 105 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 106 const QRectF& canvasRect, const QwtInterval& boundingInterval, 107 int index, const QwtSetSample& ) const; 106 108 107 virtual void drawBar( QPainter *, int sampleIndex,108 int valueIndex, const QwtColumnRect & ) const;109 virtual void drawBar( QPainter*, int sampleIndex, 110 int valueIndex, const QwtColumnRect& ) const; 109 111 110 void drawStackedBars( QPainter *painter,111 const QwtScaleMap &xMap, const QwtScaleMap&yMap,112 const QRectF &canvasRect, int index,113 double sampleWidth, const QwtSetSample& sample) const;112 void drawStackedBars( QPainter*, 113 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 114 const QRectF& canvasRect, int index, 115 double sampleWidth, const QwtSetSample& ) const; 114 116 115 void drawGroupedBars( QPainter *painter,116 const QwtScaleMap &xMap, const QwtScaleMap&yMap,117 const QRectF &canvasRect, int index,118 double sampleWidth, const QwtSetSample& sample) const;117 void drawGroupedBars( QPainter*, 118 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 119 const QRectF& canvasRect, int index, 120 double sampleWidth, const QwtSetSample& ) const; 119 121 120 private: 122 private: 121 123 void init(); 122 124 123 125 class PrivateData; 124 PrivateData *d_data;126 PrivateData* m_data; 125 127 }; 126 128 -
trunk/BNC/qwt/qwt_plot_panner.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_div.h" 12 12 #include "qwt_plot.h" 13 #include "qwt_scale_map.h" 13 14 #include "qwt_painter.h" 15 14 16 #include <qbitmap.h> 15 17 #include <qstyle.h> 16 18 #include <qstyleoption.h> 19 #include <qpainter.h> 17 20 #include <qpainterpath.h> 18 21 22 static QBitmap qwtBorderMask( const QWidget* canvas, const QSize& size ) 23 { 19 24 #if QT_VERSION >= 0x050000 20 #if QT_VERSION < 0x050100 21 #define QWT_USE_WINDOW_HANDLE 1 25 const qreal pixelRatio = QwtPainter::devicePixelRatio( canvas ); 22 26 #endif 23 #endif24 25 #ifdef QWT_USE_WINDOW_HANDLE26 #include <qwindow.h>27 #endif28 29 static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size )30 {31 #if QT_VERSION >= 0x05000032 qreal pixelRatio = 1.0;33 34 #ifdef QWT_USE_WINDOW_HANDLE35 pixelRatio = canvas->windowHandle()->devicePixelRatio();36 #else37 pixelRatio = canvas->devicePixelRatio();38 #endif39 #endif40 27 41 28 const QRect r( 0, 0, size.width(), size.height() ); … … 44 31 45 32 ( void )QMetaObject::invokeMethod( 46 const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection,33 const_cast< QWidget* >( canvas ), "borderPath", Qt::DirectConnection, 47 34 Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) ); 48 35 … … 53 40 54 41 #if QT_VERSION >= 0x050000 55 QBitmap mask( size * pixelRatio );42 QBitmap mask( size* pixelRatio ); 56 43 mask.setDevicePixelRatio( pixelRatio ); 57 44 #else … … 67 54 68 55 #if QT_VERSION >= 0x050000 69 QImage image( size * pixelRatio, QImage::Format_ARGB32_Premultiplied );56 QImage image( size* pixelRatio, QImage::Format_ARGB32_Premultiplied ); 70 57 image.setDevicePixelRatio( pixelRatio ); 71 58 #else … … 94 81 const QVariant frameWidth = canvas->property( "frameWidth" ); 95 82 96 if ( borderRadius.type() == QVariant::Double 97 && frameWidth.type() == QVariant::Int ) 83 if ( borderRadius.canConvert< double >() && frameWidth.canConvert< int >() ) 98 84 { 99 const double br = borderRadius. toDouble();100 const int fw = frameWidth. toInt();85 const double br = borderRadius.value< double >(); 86 const int fw = frameWidth.value< int >(); 101 87 102 88 if ( br > 0.0 && fw > 0 ) … … 121 107 class QwtPlotPanner::PrivateData 122 108 { 123 public: 109 public: 124 110 PrivateData() 125 111 { 126 for ( int axis = 0; axis < Qwt Plot::axisCnt; axis++ )112 for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ ) 127 113 isAxisEnabled[axis] = true; 128 114 } 129 115 130 bool isAxisEnabled[Qwt Plot::axisCnt];116 bool isAxisEnabled[QwtAxis::AxisPositions]; 131 117 }; 132 118 133 119 /*! 134 \brief A panner for the canvas of a QwtPlot 135 136 The panner is enabled for all axes 137 138 \param canvas Plot canvas to pan, also the parent object 139 140 \sa setAxisEnabled() 141 */ 142 QwtPlotPanner::QwtPlotPanner( QWidget *canvas ):143 QwtPanner( canvas ) 144 { 145 d_data = new PrivateData();120 \brief A panner for the canvas of a QwtPlot 121 122 The panner is enabled for all axes 123 124 \param canvas Plot canvas to pan, also the parent object 125 126 \sa setAxisEnabled() 127 */ 128 QwtPlotPanner::QwtPlotPanner( QWidget* canvas ) 129 : QwtPanner( canvas ) 130 { 131 m_data = new PrivateData(); 146 132 147 133 connect( this, SIGNAL(panned(int,int)), … … 152 138 QwtPlotPanner::~QwtPlotPanner() 153 139 { 154 delete d_data;140 delete m_data; 155 141 } 156 142 … … 161 147 result of panning. All other axes will remain unchanged. 162 148 163 \param axis Axis, see QwtPlot::Axis149 \param axisId Axis id 164 150 \param on On/Off 165 151 166 152 \sa isAxisEnabled(), moveCanvas() 167 */ 168 void QwtPlotPanner::setAxisEnabled( int axis, bool on )169 { 170 if ( axis >= 0 && axis < QwtPlot::axisCnt)171 d_data->isAxisEnabled[axis] = on;153 */ 154 void QwtPlotPanner::setAxisEnabled( QwtAxisId axisId, bool on ) 155 { 156 if ( QwtAxis::isValid( axisId ) ) 157 m_data->isAxisEnabled[axisId] = on; 172 158 } 173 159 … … 175 161 Test if an axis is enabled 176 162 177 \param axis Axis, see QwtPlot::Axis163 \param axisId Axis 178 164 \return True, if the axis is enabled 179 165 180 166 \sa setAxisEnabled(), moveCanvas() 181 */ 182 bool QwtPlotPanner::isAxisEnabled( int axis) const183 { 184 if ( axis >= 0 && axis < QwtPlot::axisCnt)185 return d_data->isAxisEnabled[axis];167 */ 168 bool QwtPlotPanner::isAxisEnabled( QwtAxisId axisId ) const 169 { 170 if ( QwtAxis::isValid( axisId ) ) 171 return m_data->isAxisEnabled[axisId]; 186 172 187 173 return true; … … 189 175 190 176 //! Return observed plot canvas 191 QWidget *QwtPlotPanner::canvas()177 QWidget* QwtPlotPanner::canvas() 192 178 { 193 179 return parentWidget(); … … 195 181 196 182 //! Return Observed plot canvas 197 const QWidget *QwtPlotPanner::canvas() const183 const QWidget* QwtPlotPanner::canvas() const 198 184 { 199 185 return parentWidget(); … … 201 187 202 188 //! Return plot widget, containing the observed plot canvas 203 QwtPlot *QwtPlotPanner::plot()204 { 205 QWidget *w = canvas();189 QwtPlot* QwtPlotPanner::plot() 190 { 191 QWidget* w = canvas(); 206 192 if ( w ) 207 193 w = w->parentWidget(); 208 194 209 return qobject_cast<QwtPlot *>( w );195 return qobject_cast< QwtPlot* >( w ); 210 196 } 211 197 212 198 //! Return plot widget, containing the observed plot canvas 213 const QwtPlot *QwtPlotPanner::plot() const214 { 215 const QWidget *w = canvas();199 const QwtPlot* QwtPlotPanner::plot() const 200 { 201 const QWidget* w = canvas(); 216 202 if ( w ) 217 203 w = w->parentWidget(); 218 204 219 return qobject_cast<const QwtPlot *>( w );205 return qobject_cast< const QwtPlot* >( w ); 220 206 } 221 207 … … 227 213 228 214 \sa QwtPanner::panned() 229 */ 215 */ 230 216 void QwtPlotPanner::moveCanvas( int dx, int dy ) 231 217 { … … 233 219 return; 234 220 235 QwtPlot *plot = this->plot();221 QwtPlot* plot = this->plot(); 236 222 if ( plot == NULL ) 237 223 return; … … 240 226 plot->setAutoReplot( false ); 241 227 242 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 243 { 244 if ( !d_data->isAxisEnabled[axis] ) 245 continue; 246 247 const QwtScaleMap map = plot->canvasMap( axis ); 248 249 const double p1 = map.transform( plot->axisScaleDiv( axis ).lowerBound() ); 250 const double p2 = map.transform( plot->axisScaleDiv( axis ).upperBound() ); 251 252 double d1, d2; 253 if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) 228 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 229 { 254 230 { 255 d1 = map.invTransform( p1 - dx ); 256 d2 = map.invTransform( p2 - dx ); 231 const QwtAxisId axisId( axisPos ); 232 233 if ( !m_data->isAxisEnabled[axisId] ) 234 continue; 235 236 const QwtScaleMap map = plot->canvasMap( axisId ); 237 238 const double p1 = map.transform( plot->axisScaleDiv( axisId ).lowerBound() ); 239 const double p2 = map.transform( plot->axisScaleDiv( axisId ).upperBound() ); 240 241 double d1, d2; 242 if ( QwtAxis::isXAxis( axisPos ) ) 243 { 244 d1 = map.invTransform( p1 - dx ); 245 d2 = map.invTransform( p2 - dx ); 246 } 247 else 248 { 249 d1 = map.invTransform( p1 - dy ); 250 d2 = map.invTransform( p2 - dy ); 251 } 252 253 plot->setAxisScale( axisId, d1, d2 ); 257 254 } 258 else259 {260 d1 = map.invTransform( p1 - dy );261 d2 = map.invTransform( p2 - dy );262 }263 264 plot->setAxisScale( axis, d1, d2 );265 255 } 266 256 … … 274 264 \return Mask as bitmap 275 265 \sa QwtPlotCanvas::borderPath() 276 */ 266 */ 277 267 QBitmap QwtPlotPanner::contentsMask() const 278 268 { … … 288 278 QPixmap QwtPlotPanner::grab() const 289 279 { 290 const QWidget *cv = canvas();280 const QWidget* cv = canvas(); 291 281 if ( cv && cv->inherits( "QGLWidget" ) ) 292 282 { … … 297 287 298 288 QPainter painter( &pm ); 299 const_cast<QwtPlot *>( plot() )->drawCanvas( &painter );289 const_cast< QwtPlot* >( plot() )->drawCanvas( &painter ); 300 290 301 291 return pm; … … 305 295 } 306 296 297 #include "moc_qwt_plot_panner.cpp" -
trunk/BNC/qwt/qwt_plot_panner.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PLOT_PANNER_H 11 #define QWT_PLOT_PANNER_H 111 #define QWT_PLOT_PANNER_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_panner.h" 15 #include "qwt_axis_id.h" 15 16 16 17 class QwtPlot; 17 18 18 19 /*! 19 \brief QwtPlotPanner provides panning of a plot canvas 20 \brief QwtPlotPanner provides panning of a plot canvas 20 21 21 QwtPlotPanner is a panner for a plot canvas, that 22 adjusts the scales of the axes after dropping 23 the canvas on its new position. 22 QwtPlotPanner is a panner for a plot canvas, that 23 adjusts the scales of the axes after dropping 24 the canvas on its new position. 24 25 25 Together with QwtPlotZoomer and QwtPlotMagnifier powerful ways 26 of navigating on a QwtPlot widget can be implemented easily. 26 Together with QwtPlotZoomer and QwtPlotMagnifier powerful ways 27 of navigating on a QwtPlot widget can be implemented easily. 27 28 28 \note The axes are not updated, while dragging the canvas 29 \sa QwtPlotZoomer, QwtPlotMagnifier 30 */ 31 class QWT_EXPORT QwtPlotPanner: public QwtPanner 29 \note The axes are not updated, while dragging the canvas 30 \sa QwtPlotZoomer, QwtPlotMagnifier 31 */ 32 class QWT_EXPORT QwtPlotPanner : public QwtPanner 32 33 { 33 34 Q_OBJECT 34 35 35 public: 36 explicit QwtPlotPanner( QWidget * );36 public: 37 explicit QwtPlotPanner( QWidget* ); 37 38 virtual ~QwtPlotPanner(); 38 39 39 QWidget *canvas();40 const QWidget *canvas() const;40 QWidget* canvas(); 41 const QWidget* canvas() const; 41 42 42 QwtPlot *plot();43 const QwtPlot *plot() const;43 QwtPlot* plot(); 44 const QwtPlot* plot() const; 44 45 45 void setAxisEnabled( int axis, bool on );46 bool isAxisEnabled( int axis) const;46 void setAxisEnabled( QwtAxisId axisId, bool on ); 47 bool isAxisEnabled( QwtAxisId ) const; 47 48 48 protectedQ_SLOTS:49 public Q_SLOTS: 49 50 virtual void moveCanvas( int dx, int dy ); 50 51 51 protected: 52 virtual QBitmap contentsMask() const; 53 virtual QPixmap grab() const; 52 protected: 53 virtual QBitmap contentsMask() const QWT_OVERRIDE; 54 virtual QPixmap grab() const QWT_OVERRIDE; 54 55 55 private: 56 private: 56 57 class PrivateData; 57 PrivateData *d_data;58 PrivateData* m_data; 58 59 }; 59 60 -
trunk/BNC/qwt/qwt_plot_picker.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_picker.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_text.h" 12 13 #include "qwt_scale_div.h" 13 #include "qwt_painter.h"14 14 #include "qwt_scale_map.h" 15 15 #include "qwt_picker_machine.h" 16 16 17 /*! 18 \brief Create a plot picker 19 20 The picker is set to those x- and y-axis of the plot 21 that are enabled. If both or no x-axis are enabled, the picker 22 is set to QwtPlot::xBottom. If both or no y-axis are 23 enabled, it is set to QwtPlot::yLeft. 24 25 \param canvas Plot canvas to observe, also the parent object 26 27 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 28 */ 29 30 QwtPlotPicker::QwtPlotPicker( QWidget *canvas ): 31 QwtPicker( canvas ), 32 d_xAxis( -1 ), 33 d_yAxis( -1 ) 34 { 17 class QwtPlotPicker::PrivateData 18 { 19 public: 20 PrivateData(): 21 xAxisId( -1 ), 22 yAxisId( -1 ) 23 { 24 } 25 26 QwtAxisId xAxisId; 27 QwtAxisId yAxisId; 28 }; 29 30 /*! 31 \brief Create a plot picker 32 33 The picker is set to those x- and y-axis of the plot 34 that are enabled. If both or no x-axis are enabled, the picker 35 is set to QwtAxis::XBottom. If both or no y-axis are 36 enabled, it is set to QwtAxis::YLeft. 37 38 \param canvas Plot canvas to observe, also the parent object 39 40 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 41 */ 42 43 QwtPlotPicker::QwtPlotPicker( QWidget* canvas ) 44 : QwtPicker( canvas ) 45 { 46 m_data = new PrivateData; 47 35 48 if ( !canvas ) 36 49 return; 37 50 51 const QwtPlot* plot = QwtPlotPicker::plot(); 38 52 // attach axes 39 53 40 int xAxis = QwtPlot::xBottom; 41 42 const QwtPlot *plot = QwtPlotPicker::plot(); 43 if ( !plot->axisEnabled( QwtPlot::xBottom ) && 44 plot->axisEnabled( QwtPlot::xTop ) ) 45 { 46 xAxis = QwtPlot::xTop; 47 } 48 49 int yAxis = QwtPlot::yLeft; 50 if ( !plot->axisEnabled( QwtPlot::yLeft ) && 51 plot->axisEnabled( QwtPlot::yRight ) ) 52 { 53 yAxis = QwtPlot::yRight; 54 } 55 56 setAxis( xAxis, yAxis ); 57 } 58 59 /*! 60 Create a plot picker 61 62 \param xAxis Set the x axis of the picker 63 \param yAxis Set the y axis of the picker 64 \param canvas Plot canvas to observe, also the parent object 65 66 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 67 */ 68 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, QWidget *canvas ): 69 QwtPicker( canvas ), 70 d_xAxis( xAxis ), 71 d_yAxis( yAxis ) 72 { 73 } 74 75 /*! 76 Create a plot picker 77 78 \param xAxis X axis of the picker 79 \param yAxis Y axis of the picker 80 \param rubberBand Rubber band style 81 \param trackerMode Tracker mode 82 \param canvas Plot canvas to observe, also the parent object 83 84 \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(), 54 using namespace QwtAxis; 55 56 int xAxis = XBottom; 57 if ( !plot->isAxisVisible( XBottom ) && plot->isAxisVisible( XTop ) ) 58 xAxis = XTop; 59 60 int yAxis = YLeft; 61 if ( !plot->isAxisVisible( YLeft ) && plot->isAxisVisible( YRight ) ) 62 yAxis = YRight; 63 64 setAxes( xAxis, yAxis ); 65 } 66 67 /*! 68 Create a plot picker 69 70 \param xAxisId X axis of the picker 71 \param yAxisId Y axis of the picker 72 \param canvas Plot canvas to observe, also the parent object 73 74 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 75 */ 76 QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, QWidget* canvas ) 77 : QwtPicker( canvas ) 78 { 79 m_data = new PrivateData; 80 m_data->xAxisId = xAxisId; 81 m_data->yAxisId = yAxisId; 82 } 83 84 /*! 85 Create a plot picker 86 87 \param xAxisId X axis of the picker 88 \param yAxisId Y axis of the picker 89 \param rubberBand Rubber band style 90 \param trackerMode Tracker mode 91 \param canvas Plot canvas to observe, also the parent object 92 93 \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(), 85 94 QwtPicker::setTrackerMode 86 95 87 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 88 */ 89 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis,90 RubberBand rubberBand, DisplayMode trackerMode, 91 QWidget *canvas ):92 QwtPicker( rubberBand, trackerMode, canvas ), 93 d_xAxis( xAxis ),94 d_yAxis( yAxis )95 { 96 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 97 */ 98 QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, 99 RubberBand rubberBand, DisplayMode trackerMode, QWidget* canvas ) 100 : QwtPicker( rubberBand, trackerMode, canvas ) 101 { 102 m_data = new PrivateData; 103 m_data->xAxisId = xAxisId; 104 m_data->yAxisId = yAxisId; 96 105 } 97 106 … … 99 108 QwtPlotPicker::~QwtPlotPicker() 100 109 { 110 delete m_data; 101 111 } 102 112 103 113 //! \return Observed plot canvas 104 QWidget *QwtPlotPicker::canvas()114 QWidget* QwtPlotPicker::canvas() 105 115 { 106 116 return parentWidget(); … … 108 118 109 119 //! \return Observed plot canvas 110 const QWidget *QwtPlotPicker::canvas() const120 const QWidget* QwtPlotPicker::canvas() const 111 121 { 112 122 return parentWidget(); … … 114 124 115 125 //! \return Plot widget, containing the observed plot canvas 116 QwtPlot *QwtPlotPicker::plot()117 { 118 QWidget *w = canvas();126 QwtPlot* QwtPlotPicker::plot() 127 { 128 QWidget* w = canvas(); 119 129 if ( w ) 120 130 w = w->parentWidget(); 121 131 122 return qobject_cast<QwtPlot *>( w );132 return qobject_cast< QwtPlot* >( w ); 123 133 } 124 134 125 135 //! \return Plot widget, containing the observed plot canvas 126 const QwtPlot *QwtPlotPicker::plot() const127 { 128 const QWidget *w = canvas();136 const QwtPlot* QwtPlotPicker::plot() const 137 { 138 const QWidget* w = canvas(); 129 139 if ( w ) 130 140 w = w->parentWidget(); 131 141 132 return qobject_cast<const QwtPlot *>( w );133 } 134 135 /*! 136 \return Normalized bounding rectangle of the axes 137 \sa QwtPlot::autoReplot(), QwtPlot::replot(). 138 */ 142 return qobject_cast< const QwtPlot* >( w ); 143 } 144 145 /*! 146 \return Normalized bounding rectangle of the axes 147 \sa QwtPlot::autoReplot(), QwtPlot::replot(). 148 */ 139 149 QRectF QwtPlotPicker::scaleRect() const 140 150 { … … 143 153 if ( plot() ) 144 154 { 145 const QwtScaleDiv &xs = plot()->axisScaleDiv( xAxis() );146 const QwtScaleDiv &ys = plot()->axisScaleDiv( yAxis() );155 const QwtScaleDiv& xs = plot()->axisScaleDiv( xAxis() ); 156 const QwtScaleDiv& ys = plot()->axisScaleDiv( yAxis() ); 147 157 148 158 rect = QRectF( xs.lowerBound(), ys.lowerBound(), … … 155 165 156 166 /*! 157 Set the x and y axes of the picker 158 159 \param xAxis X axis 160 \param yAxis Y axis 161 */ 162 void QwtPlotPicker::setAx is( int xAxis, int yAxis)163 { 164 const QwtPlot *plt = plot();167 Set the x and y axes of the picker 168 169 \param xAxisId X axis 170 \param yAxisId Y axis 171 */ 172 void QwtPlotPicker::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId ) 173 { 174 const QwtPlot* plt = plot(); 165 175 if ( !plt ) 166 176 return; 167 177 168 if ( xAxis != d_xAxis|| yAxis!= d_yAxis)169 { 170 d_xAxis= xAxis;171 d_yAxis= yAxis;178 if ( xAxisId != m_data->xAxisId || yAxisId != m_data->yAxisId ) 179 { 180 m_data->xAxisId = xAxisId; 181 m_data->yAxisId = yAxisId; 172 182 } 173 183 } 174 184 175 185 //! Return x axis 176 intQwtPlotPicker::xAxis() const177 { 178 return d_xAxis;186 QwtAxisId QwtPlotPicker::xAxis() const 187 { 188 return m_data->xAxisId; 179 189 } 180 190 181 191 //! Return y axis 182 intQwtPlotPicker::yAxis() const183 { 184 return d_yAxis;185 } 186 187 /*! 188 Translate a pixel position into a position string 189 190 \param pos Position in pixel coordinates 191 \return Position string 192 */ 193 QwtText QwtPlotPicker::trackerText( const QPoint &pos ) const192 QwtAxisId QwtPlotPicker::yAxis() const 193 { 194 return m_data->yAxisId; 195 } 196 197 /*! 198 Translate a pixel position into a position string 199 200 \param pos Position in pixel coordinates 201 \return Position string 202 */ 203 QwtText QwtPlotPicker::trackerText( const QPoint& pos ) const 194 204 { 195 205 if ( plot() == NULL ) … … 200 210 201 211 /*! 202 \brief Translate a position into a position string 203 204 In case of HLineRubberBand the label is the value of the 205 y position, in case of VLineRubberBand the value of the x position. 206 Otherwise the label contains x and y position separated by a ',' . 207 208 The format for the double to string conversion is "%.4f". 209 210 \param pos Position 211 \return Position string 212 */ 213 QwtText QwtPlotPicker::trackerTextF( const QPointF &pos ) const212 \brief Translate a position into a position string 213 214 In case of HLineRubberBand the label is the value of the 215 y position, in case of VLineRubberBand the value of the x position. 216 Otherwise the label contains x and y position separated by a ',' . 217 218 The format for the double to string conversion is "%.4f". 219 220 \param pos Position 221 \return Position string 222 */ 223 QwtText QwtPlotPicker::trackerTextF( const QPointF& pos ) const 214 224 { 215 225 QString text; … … 218 228 { 219 229 case HLineRubberBand: 220 text .sprintf( "%.4f",pos.y() );230 text = QString::number( pos.y(), 'f', 4 ); 221 231 break; 222 232 case VLineRubberBand: 223 text .sprintf( "%.4f",pos.x() );233 text = QString::number( pos.x(), 'f', 4 ); 224 234 break; 225 235 default: 226 text.sprintf( "%.4f, %.4f", pos.x(), pos.y() ); 236 text = QString::number( pos.x(), 'f', 4 ) 237 + ", " + QString::number( pos.y(), 'f', 4 ); 227 238 } 228 239 return QwtText( text ); … … 230 241 231 242 /*! 232 Append a point to the selection and update rubber band and tracker. 233 234 \param pos Additional point 235 \sa isActive, begin(), end(), move(), appended() 236 237 \note The appended(const QPoint &), appended(const QDoublePoint &) 243 Append a point to the selection and update rubber band and tracker. 244 245 \param pos Additional point 246 \sa isActive, begin(), end(), move(), appended() 247 248 \note The appended(const QPoint &), appended(const QDoublePoint &) 238 249 signals are emitted. 239 */ 240 void QwtPlotPicker::append( const QPoint &pos )250 */ 251 void QwtPlotPicker::append( const QPoint& pos ) 241 252 { 242 253 QwtPicker::append( pos ); … … 245 256 246 257 /*! 247 Move the last point of the selection 248 249 \param pos New position 250 \sa isActive, begin(), end(), append() 251 252 \note The moved(const QPoint &), moved(const QDoublePoint &) 258 Move the last point of the selection 259 260 \param pos New position 261 \sa isActive, begin(), end(), append() 262 263 \note The moved(const QPoint &), moved(const QDoublePoint &) 253 264 signals are emitted. 254 */ 255 void QwtPlotPicker::move( const QPoint &pos )265 */ 266 void QwtPlotPicker::move( const QPoint& pos ) 256 267 { 257 268 QwtPicker::move( pos ); … … 260 271 261 272 /*! 262 Close a selection setting the state to inactive. 263 264 \param ok If true, complete the selection and emit selected signals 273 Close a selection setting the state to inactive. 274 275 \param ok If true, complete the selection and emit selected signals 265 276 otherwise discard the selection. 266 \return True if the selection has been accepted, false otherwise 267 */ 277 \return True if the selection has been accepted, false otherwise 278 */ 268 279 269 280 bool QwtPlotPicker::end( bool ok ) … … 273 284 return false; 274 285 275 QwtPlot *plot = QwtPlotPicker::plot();286 QwtPlot* plot = QwtPlotPicker::plot(); 276 287 if ( !plot ) 277 288 return false; … … 309 320 case QwtPickerMachine::PolygonSelection: 310 321 { 311 QVector< QPointF> dpa( points.count() );322 QVector< QPointF > dpa( points.count() ); 312 323 for ( int i = 0; i < points.count(); i++ ) 313 324 dpa[i] = invTransform( points[i] ); … … 327 338 \return Rectangle in plot coordinates 328 339 \sa transform() 329 */ 330 QRectF QwtPlotPicker::invTransform( const QRect &rect ) const331 { 332 const QwtScaleMap xMap = plot()->canvasMap( d_xAxis);333 const QwtScaleMap yMap = plot()->canvasMap( d_yAxis);340 */ 341 QRectF QwtPlotPicker::invTransform( const QRect& rect ) const 342 { 343 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 344 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 334 345 335 346 return QwtScaleMap::invTransform( xMap, yMap, rect ); … … 340 351 \return Rectangle in pixel coordinates 341 352 \sa invTransform() 342 */ 343 QRect QwtPlotPicker::transform( const QRectF &rect ) const344 { 345 const QwtScaleMap xMap = plot()->canvasMap( d_xAxis);346 const QwtScaleMap yMap = plot()->canvasMap( d_yAxis);353 */ 354 QRect QwtPlotPicker::transform( const QRectF& rect ) const 355 { 356 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 357 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 347 358 348 359 return QwtScaleMap::transform( xMap, yMap, rect ).toRect(); … … 353 364 \return Point in plot coordinates 354 365 \sa transform() 355 */ 356 QPointF QwtPlotPicker::invTransform( const QPoint &pos ) const357 { 358 QwtScaleMap xMap = plot()->canvasMap( d_xAxis);359 QwtScaleMap yMap = plot()->canvasMap( d_yAxis);366 */ 367 QPointF QwtPlotPicker::invTransform( const QPoint& pos ) const 368 { 369 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 370 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 360 371 361 372 return QPointF( 362 373 xMap.invTransform( pos.x() ), 363 374 yMap.invTransform( pos.y() ) 364 ); 375 ); 365 376 } 366 377 … … 369 380 \return Point in pixel coordinates 370 381 \sa invTransform() 371 */ 372 QPoint QwtPlotPicker::transform( const QPointF &pos ) const 373 { 374 QwtScaleMap xMap = plot()->canvasMap( d_xAxis ); 375 QwtScaleMap yMap = plot()->canvasMap( d_yAxis ); 376 377 const QPointF p( xMap.transform( pos.x() ), 378 yMap.transform( pos.y() ) ); 382 */ 383 QPoint QwtPlotPicker::transform( const QPointF& pos ) const 384 { 385 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); 386 const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); 387 388 const QPointF p( xMap.transform( pos.x() ), yMap.transform( pos.y() ) ); 379 389 380 390 return p.toPoint(); 381 391 } 392 393 #include "moc_qwt_plot_picker.cpp" -
trunk/BNC/qwt/qwt_plot_picker.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_picker.h" 15 #include <qvector.h>15 #include "qwt_axis_id.h" 16 16 17 17 class QwtPlot; 18 class QPointF; 19 class QRectF; 20 21 #if QT_VERSION < 0x060000 22 template< typename T > class QVector; 23 #endif 18 24 19 25 /*! 20 \brief QwtPlotPicker provides selections on a plot canvas 26 \brief QwtPlotPicker provides selections on a plot canvas 21 27 22 QwtPlotPicker is a QwtPicker tailored for selections on 23 a plot canvas. It is set to a x-Axis and y-Axis and 24 translates all pixel coordinates into this coordinate system. 25 */ 28 QwtPlotPicker is a QwtPicker tailored for selections on 29 a plot canvas. It is set to a x-Axis and y-Axis and 30 translates all pixel coordinates into this coordinate system. 31 */ 26 32 27 class QWT_EXPORT QwtPlotPicker: public QwtPicker 33 class QWT_EXPORT QwtPlotPicker : public QwtPicker 28 34 { 29 35 Q_OBJECT 30 36 31 public: 32 explicit QwtPlotPicker( QWidget *canvas );37 public: 38 explicit QwtPlotPicker( QWidget* canvas ); 33 39 virtual ~QwtPlotPicker(); 34 40 35 explicit QwtPlotPicker( int xAxis, int yAxis, QWidget* );41 explicit QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, QWidget* ); 36 42 37 explicit QwtPlotPicker( int xAxis, int yAxis,38 RubberBand rubberBand, DisplayMode trackerMode, QWidget * );43 explicit QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, 44 RubberBand rubberBand, DisplayMode trackerMode, QWidget* ); 39 45 40 virtual void setAx is( int xAxis, int yAxis);46 virtual void setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId ); 41 47 42 intxAxis() const;43 intyAxis() const;48 QwtAxisId xAxis() const; 49 QwtAxisId yAxis() const; 44 50 45 QwtPlot *plot();46 const QwtPlot *plot() const;51 QwtPlot* plot(); 52 const QwtPlot* plot() const; 47 53 48 QWidget *canvas();49 const QWidget *canvas() const;54 QWidget* canvas(); 55 const QWidget* canvas() const; 50 56 51 Q_SIGNALS: 57 Q_SIGNALS: 52 58 53 59 /*! 54 A signal emitted in case of QwtPickerMachine::PointSelection. 55 \param pos Selected point 56 */ 57 void selected( const QPointF &pos );60 A signal emitted in case of QwtPickerMachine::PointSelection. 61 \param pos Selected point 62 */ 63 void selected( const QPointF& pos ); 58 64 59 65 /*! 60 A signal emitted in case of QwtPickerMachine::RectSelection. 61 \param rect Selected rectangle 62 */ 63 void selected( const QRectF &rect );66 A signal emitted in case of QwtPickerMachine::RectSelection. 67 \param rect Selected rectangle 68 */ 69 void selected( const QRectF& rect ); 64 70 65 71 /*! 66 A signal emitting the selected points, 67 at the end of a selection. 72 A signal emitting the selected points, 73 at the end of a selection. 68 74 69 \param pa Selected points 70 */ 71 void selected( const QVector<QPointF > &pa );75 \param pa Selected points 76 */ 77 void selected( const QVector< QPointF >& pa ); 72 78 73 79 /*! 74 A signal emitted when a point has been appended to the selection 80 A signal emitted when a point has been appended to the selection 75 81 76 \param pos Position of the appended point. 77 \sa append(). moved() 78 */ 79 void appended( const QPointF &pos );82 \param pos Position of the appended point. 83 \sa append(). moved() 84 */ 85 void appended( const QPointF& pos ); 80 86 81 87 /*! 82 A signal emitted whenever the last appended point of the 83 selection has been moved. 88 A signal emitted whenever the last appended point of the 89 selection has been moved. 84 90 85 \param pos Position of the moved last point of the selection. 86 \sa move(), appended() 87 */ 88 void moved( const QPointF &pos );91 \param pos Position of the moved last point of the selection. 92 \sa move(), appended() 93 */ 94 void moved( const QPointF& pos ); 89 95 90 protected: 96 protected: 91 97 QRectF scaleRect() const; 92 98 93 QRectF invTransform( const QRect & ) const;94 QRect transform( const QRectF & ) const;99 QRectF invTransform( const QRect& ) const; 100 QRect transform( const QRectF& ) const; 95 101 96 QPointF invTransform( const QPoint & ) const;97 QPoint transform( const QPointF & ) const;102 QPointF invTransform( const QPoint& ) const; 103 QPoint transform( const QPointF& ) const; 98 104 99 virtual QwtText trackerText( const QPoint & ) const;100 virtual QwtText trackerTextF( const QPointF & ) const;105 virtual QwtText trackerText( const QPoint& ) const QWT_OVERRIDE; 106 virtual QwtText trackerTextF( const QPointF& ) const; 101 107 102 virtual void move( const QPoint & );103 virtual void append( const QPoint & );104 virtual bool end( bool ok = true ); 108 virtual void move( const QPoint& ) QWT_OVERRIDE; 109 virtual void append( const QPoint& ) QWT_OVERRIDE; 110 virtual bool end( bool ok = true ) QWT_OVERRIDE; 105 111 106 private: 107 int d_xAxis;108 int d_yAxis;112 private: 113 class PrivateData; 114 PrivateData* m_data; 109 115 }; 110 116 -
trunk/BNC/qwt/qwt_plot_rasteritem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_map.h" 12 12 #include "qwt_painter.h" 13 #include <qapplication.h> 14 #include <qdesktopwidget.h> 13 #include "qwt_text.h" 14 #include "qwt_interval.h" 15 #include "qwt_math.h" 16 15 17 #include <qpainter.h> 16 18 #include <qpaintengine.h> 17 #include <qmath.h>18 #if QT_VERSION >= 0x04040019 19 #include <qthread.h> 20 20 #include <qfuture.h> 21 21 #include <qtconcurrentrun.h> 22 #endif 23 #include < float.h>22 23 #include <limits> 24 24 25 25 class QwtPlotRasterItem::PrivateData 26 26 { 27 public: 28 PrivateData() :29 alpha( -1 ) ,30 paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution ) 27 public: 28 PrivateData() 29 : alpha( -1 ) 30 , paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution ) 31 31 { 32 32 cache.policy = QwtPlotRasterItem::NoCache; … … 47 47 48 48 49 static QRectF qwtAlignRect(const QRectF &rect)49 static QRectF qwtAlignRect(const QRectF& rect) 50 50 { 51 51 QRectF r; … … 58 58 } 59 59 60 static QRectF qwtStripRect(const QRectF &rect, const QRectF&area,61 const QwtScaleMap &xMap, const QwtScaleMap&yMap,62 const QwtInterval &xInterval, const QwtInterval&yInterval)60 static QRectF qwtStripRect(const QRectF& rect, const QRectF& area, 61 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 62 const QwtInterval& xInterval, const QwtInterval& yInterval) 63 63 { 64 64 QRectF r = rect; … … 110 110 } 111 111 112 static QImage qwtExpandImage(const QImage &image,113 const QwtScaleMap &xMap, const QwtScaleMap&yMap,114 const QRectF &area, const QRectF&area2, const QRectF&paintRect,115 const QwtInterval &xInterval, const QwtInterval&yInterval )112 static QImage qwtExpandImage(const QImage& image, 113 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 114 const QRectF& area, const QRectF& area2, const QRectF& paintRect, 115 const QwtInterval& xInterval, const QwtInterval& yInterval ) 116 116 { 117 117 const QRectF strippedRect = qwtStripRect(paintRect, area2, … … 123 123 124 124 const QRectF r = QwtScaleMap::transform(xMap, yMap, area).normalized(); 125 const double pw = ( r.width() - 1) / w; 126 const double ph = ( r.height() - 1) / h; 125 const double pw = ( r.width() - 1 ) / w; 126 const double ph = ( r.height() - 1 ) / h; 127 127 128 128 double px0, py0; … … 193 193 } 194 194 195 const quint32 *line1 =196 reinterpret_cast<const quint32 *>( image.scanLine( y1 ) );195 const quint32* line1 = 196 reinterpret_cast< const quint32* >( image.scanLine( y1 ) ); 197 197 198 198 for ( int x1 = 0; x1 < w; x1++ ) … … 225 225 for ( int y2 = yy1; y2 < yy2; y2++ ) 226 226 { 227 quint32 *line2 = reinterpret_cast<quint32*>(227 quint32* line2 = reinterpret_cast< quint32* >( 228 228 expanded.scanLine( y2 ) ); 229 229 … … 263 263 } 264 264 265 const uchar *line1 = image.scanLine( y1 );265 const uchar* line1 = image.scanLine( y1 ); 266 266 267 267 for ( int x1 = 0; x1 < w; x1++ ) … … 293 293 for ( int y2 = yy1; y2 < yy2; y2++ ) 294 294 { 295 uchar *line2 = expanded.scanLine( y2 );295 uchar* line2 = expanded.scanLine( y2 ); 296 296 memset( line2 + xx1, line1[x1], xx2 - xx1 ); 297 297 } … … 307 307 } 308 308 309 static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF&pixelRect)309 static QRectF qwtExpandToPixels(const QRectF& rect, const QRectF& pixelRect) 310 310 { 311 311 const double pw = pixelRect.width(); … … 318 318 319 319 QRectF r; 320 r.setLeft( pixelRect.left() - qCeil( dx1 / pw ) * pw ); 321 r.setTop( pixelRect.top() - qCeil( dy1 / ph ) * ph ); 322 r.setRight( pixelRect.right() - qFloor( dx2 / pw ) * pw ); 323 r.setBottom( pixelRect.bottom() - qFloor( dy2 / ph ) * ph ); 320 r.setLeft( pixelRect.left() - qwtCeil( dx1 / pw ) * pw ); 321 r.setTop( pixelRect.top() - qwtCeil( dy1 / ph ) * ph ); 322 r.setRight( pixelRect.right() - qwtFloor( dx2 / pw ) * pw ); 323 r.setBottom( pixelRect.bottom() - qwtFloor( dy2 / ph ) * ph ); 324 324 325 325 return r; 326 326 } 327 327 328 static void qwtTransformMaps( const QTransform &tr,329 const QwtScaleMap &xMap, const QwtScaleMap&yMap,330 QwtScaleMap &xxMap, QwtScaleMap&yyMap )328 static void qwtTransformMaps( const QTransform& tr, 329 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 330 QwtScaleMap& xxMap, QwtScaleMap& yyMap ) 331 331 { 332 332 const QPointF p1 = tr.map( QPointF( xMap.p1(), yMap.p1() ) ); … … 340 340 } 341 341 342 static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap&yMap,343 const QRectF &area, const QRectF&paintRect)342 static void qwtAdjustMaps( QwtScaleMap& xMap, QwtScaleMap& yMap, 343 const QRectF& area, const QRectF& paintRect) 344 344 { 345 345 double sx1 = area.left(); … … 354 354 qSwap(sy1, sy2); 355 355 356 xMap.setPaintInterval(paintRect.left(), paintRect.right()); 356 xMap.setPaintInterval(paintRect.left(), paintRect.right() ); 357 357 xMap.setScaleInterval(sx1, sx2); 358 358 359 yMap.setPaintInterval(paintRect.top(), paintRect.bottom()); 359 yMap.setPaintInterval(paintRect.top(), paintRect.bottom() ); 360 360 yMap.setScaleInterval(sy1, sy2); 361 361 } 362 362 363 363 static bool qwtUseCache( QwtPlotRasterItem::CachePolicy policy, 364 const QPainter *painter )364 const QPainter* painter ) 365 365 { 366 366 bool doCache = false; … … 375 375 case QPaintEngine::SVG: 376 376 case QPaintEngine::Pdf: 377 #if QT_VERSION < 0x060000 377 378 case QPaintEngine::PostScript: 379 #endif 378 380 case QPaintEngine::MacPrinter: 379 381 case QPaintEngine::Picture: … … 403 405 for ( int y = y0; y <= y1; y++ ) 404 406 { 405 QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );406 const unsigned char *line = from->scanLine( y );407 QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) ); 408 const unsigned char* line = from->scanLine( y ); 407 409 408 410 for ( int x = x0; x <= x1; x++ ) … … 414 416 for ( int y = y0; y <= y1; y++ ) 415 417 { 416 QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );417 const QRgb *line = reinterpret_cast<const QRgb*>( from->scanLine( y ) );418 QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) ); 419 const QRgb* line = reinterpret_cast< const QRgb* >( from->scanLine( y ) ); 418 420 419 421 for ( int x = x0; x <= x1; x++ ) … … 430 432 431 433 //! Constructor 432 QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ) :433 QwtPlotItem( QwtText( title ) ) 434 QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ) 435 : QwtPlotItem( QwtText( title ) ) 434 436 { 435 437 init(); … … 437 439 438 440 //! Constructor 439 QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ) :440 QwtPlotItem( title ) 441 QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ) 442 : QwtPlotItem( title ) 441 443 { 442 444 init(); … … 446 448 QwtPlotRasterItem::~QwtPlotRasterItem() 447 449 { 448 delete d_data;450 delete m_data; 449 451 } 450 452 451 453 void QwtPlotRasterItem::init() 452 454 { 453 d_data = new PrivateData();455 m_data = new PrivateData(); 454 456 455 457 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 460 462 461 463 /*! 462 Specify an attribute how to draw the raster item 463 464 \param attribute Paint attribute 465 \param on On/Off 466 /sa PaintAttribute, testPaintAttribute() 467 */ 464 Specify an attribute how to draw the raster item 465 466 \param attribute Paint attribute 467 \param on On/Off 468 /sa PaintAttribute, testPaintAttribute() 469 */ 468 470 void QwtPlotRasterItem::setPaintAttribute( PaintAttribute attribute, bool on ) 469 471 { 470 472 if ( on ) 471 d_data->paintAttributes |= attribute;473 m_data->paintAttributes |= attribute; 472 474 else 473 d_data->paintAttributes &= ~attribute;475 m_data->paintAttributes &= ~attribute; 474 476 } 475 477 … … 477 479 \return True, when attribute is enabled 478 480 \sa PaintAttribute, setPaintAttribute() 479 */ 481 */ 480 482 bool QwtPlotRasterItem::testPaintAttribute( PaintAttribute attribute ) const 481 483 { 482 return ( d_data->paintAttributes & attribute );484 return ( m_data->paintAttributes & attribute ); 483 485 } 484 486 … … 505 507 506 508 \sa alpha() 507 */ 509 */ 508 510 void QwtPlotRasterItem::setAlpha( int alpha ) 509 511 { … … 514 516 alpha = 255; 515 517 516 if ( alpha != d_data->alpha )517 { 518 d_data->alpha = alpha;518 if ( alpha != m_data->alpha ) 519 { 520 m_data->alpha = alpha; 519 521 520 522 itemChanged(); … … 523 525 524 526 /*! 525 \return Alpha value of the raster item 526 \sa setAlpha() 527 */ 527 \return Alpha value of the raster item 528 \sa setAlpha() 529 */ 528 530 int QwtPlotRasterItem::alpha() const 529 531 { 530 return d_data->alpha;531 } 532 533 /*! 534 Change the cache policy 535 536 The default policy is NoCache 537 538 \param policy Cache policy 539 \sa CachePolicy, cachePolicy() 540 */ 532 return m_data->alpha; 533 } 534 535 /*! 536 Change the cache policy 537 538 The default policy is NoCache 539 540 \param policy Cache policy 541 \sa CachePolicy, cachePolicy() 542 */ 541 543 void QwtPlotRasterItem::setCachePolicy( 542 544 QwtPlotRasterItem::CachePolicy policy ) 543 545 { 544 if ( d_data->cache.policy != policy )545 { 546 d_data->cache.policy = policy;546 if ( m_data->cache.policy != policy ) 547 { 548 m_data->cache.policy = policy; 547 549 548 550 invalidateCache(); … … 552 554 553 555 /*! 554 \return Cache policy 555 \sa CachePolicy, setCachePolicy() 556 */ 556 \return Cache policy 557 \sa CachePolicy, setCachePolicy() 558 */ 557 559 QwtPlotRasterItem::CachePolicy QwtPlotRasterItem::cachePolicy() const 558 560 { 559 return d_data->cache.policy;561 return m_data->cache.policy; 560 562 } 561 563 … … 563 565 Invalidate the paint cache 564 566 \sa setCachePolicy() 565 */ 567 */ 566 568 void QwtPlotRasterItem::invalidateCache() 567 569 { 568 d_data->cache.image = QImage();569 d_data->cache.area = QRect();570 d_data->cache.size = QSize();570 m_data->cache.image = QImage(); 571 m_data->cache.area = QRect(); 572 m_data->cache.size = QSize(); 571 573 } 572 574 … … 596 598 597 599 \sa render(), renderImage() 598 */ 599 QRectF QwtPlotRasterItem::pixelHint( const QRectF &area ) const600 */ 601 QRectF QwtPlotRasterItem::pixelHint( const QRectF& area ) const 600 602 { 601 603 Q_UNUSED( area ); … … 604 606 605 607 /*! 606 \brief Draw the raster data 607 \param painter Painter 608 \param xMap X-Scale Map 609 \param yMap Y-Scale Map 610 \param canvasRect Contents rectangle of the plot canvas 611 */ 612 void QwtPlotRasterItem::draw( QPainter *painter,613 const QwtScaleMap &xMap, const QwtScaleMap&yMap,614 const QRectF &canvasRect ) const615 { 616 if ( canvasRect.isEmpty() || d_data->alpha == 0 )608 \brief Draw the raster data 609 \param painter Painter 610 \param xMap X-Scale Map 611 \param yMap Y-Scale Map 612 \param canvasRect Contents rectangle of the plot canvas 613 */ 614 void QwtPlotRasterItem::draw( QPainter* painter, 615 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 616 const QRectF& canvasRect ) const 617 { 618 if ( canvasRect.isEmpty() || m_data->alpha == 0 ) 617 619 return; 618 620 619 const bool doCache = qwtUseCache( d_data->cache.policy, painter );621 const bool doCache = qwtUseCache( m_data->cache.policy, painter ); 620 622 621 623 const QwtInterval xInterval = interval( Qt::XAxis ); … … 626 628 precision/quality. So we always render the image in 627 629 paint device resolution. 628 */ 630 */ 629 631 630 632 QwtScaleMap xxMap, yyMap; … … 657 659 { 658 660 /* 659 When the resolution of the data pixels is higher than 660 the resolution of the target device we render in 661 target device resolution. 661 When the resolution of the data pixels is higher than 662 the resolution of the target device we render in 663 target device resolution. 662 664 */ 663 665 pixelRect = QRectF(); … … 666 668 { 667 669 /* 668 If only one dimension is of the data pixel is higher 669 we expand the pixel rect to the resolution of the target device. 670 If only one dimension is of the data pixel is higher 671 we expand the pixel rect to the resolution of the target device. 670 672 */ 671 673 … … 692 694 // data pixels we render in resolution of the paint device. 693 695 696 auto imageSize = paintRect.size(); 697 698 #if QT_VERSION >= 0x050000 699 const auto pixelRatio = QwtPainter::devicePixelRatio( painter->device() ); 700 imageSize *= pixelRatio; 701 #endif 702 694 703 image = compose(xxMap, yyMap, 695 area, paintRect, paintRect.size().toSize(), doCache); 704 area, paintRect, imageSize.toSize(), doCache); 705 696 706 if ( image.isNull() ) 697 707 return; 698 708 709 #if QT_VERSION >= 0x050000 710 image.setDevicePixelRatio( pixelRatio ); 711 #endif 712 699 713 // Remove pixels at the boundaries, when explicitly 700 714 // excluded in the intervals … … 706 720 { 707 721 const QRect r( 708 qRound( imageRect.x() - paintRect.x()), 722 qRound( imageRect.x() - paintRect.x() ), 709 723 qRound( imageRect.y() - paintRect.y() ), 710 724 qRound( imageRect.width() ), … … 773 787 774 788 \param axis X, Y, or Z axis 775 */ 789 */ 776 790 QwtInterval QwtPlotRasterItem::interval(Qt::Axis axis) const 777 791 { … … 783 797 \return Bounding rectangle of the data 784 798 \sa QwtPlotRasterItem::interval() 785 */ 799 */ 786 800 QRectF QwtPlotRasterItem::boundingRect() const 787 801 { … … 801 815 else 802 816 { 803 r.setLeft(-0.5 * FLT_MAX); 804 r.setWidth(FLT_MAX); 817 const qreal max = std::numeric_limits< float >::max(); 818 819 r.setLeft( -0.5 * max ); 820 r.setWidth( max ); 805 821 } 806 822 … … 812 828 else 813 829 { 814 r.setTop(-0.5 * FLT_MAX); 815 r.setHeight(FLT_MAX); 830 const qreal max = std::numeric_limits< float >::max(); 831 832 r.setTop( -0.5 * max ); 833 r.setHeight( max ); 816 834 } 817 835 … … 820 838 821 839 QImage QwtPlotRasterItem::compose( 822 const QwtScaleMap &xMap, const QwtScaleMap&yMap,823 const QRectF &imageArea, const QRectF&paintRect,824 const QSize &imageSize, bool doCache) const840 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 841 const QRectF& imageArea, const QRectF& paintRect, 842 const QSize& imageSize, bool doCache) const 825 843 { 826 844 QImage image; … … 830 848 if ( doCache ) 831 849 { 832 if ( ! d_data->cache.image.isNull()833 && d_data->cache.area == imageArea834 && d_data->cache.size == paintRect.size() )835 { 836 image = d_data->cache.image;850 if ( !m_data->cache.image.isNull() 851 && m_data->cache.area == imageArea 852 && m_data->cache.size == paintRect.size() ) 853 { 854 image = m_data->cache.image; 837 855 } 838 856 } … … 858 876 if ( doCache ) 859 877 { 860 d_data->cache.area = imageArea;861 d_data->cache.size = paintRect.size();862 d_data->cache.image = image;863 } 864 } 865 866 if ( d_data->alpha >= 0 &&d_data->alpha < 255 )878 m_data->cache.area = imageArea; 879 m_data->cache.size = paintRect.size(); 880 m_data->cache.image = image; 881 } 882 } 883 884 if ( m_data->alpha >= 0 && m_data->alpha < 255 ) 867 885 { 868 886 QImage alphaImage( image.size(), QImage::Format_ARGB32 ); 869 887 870 #if QT_VERSION >= 0x040400 &&!defined(QT_NO_QFUTURE)888 #if !defined( QT_NO_QFUTURE ) 871 889 uint numThreads = renderThreadCount(); 872 890 … … 879 897 const int numRows = image.height() / numThreads; 880 898 881 QList< QFuture<void> > futures; 899 QVector< QFuture< void > > futures; 900 futures.reserve( numThreads - 1 ); 901 882 902 for ( uint i = 0; i < numThreads; i++ ) 883 903 { … … 886 906 { 887 907 tile.setHeight( image.height() - i * numRows ); 888 qwtToRgba( &image, &alphaImage, tile, d_data->alpha );908 qwtToRgba( &image, &alphaImage, tile, m_data->alpha ); 889 909 } 890 910 else 891 911 { 892 912 futures += QtConcurrent::run( 893 &qwtToRgba, &image, &alphaImage, tile, d_data->alpha );913 &qwtToRgba, &image, &alphaImage, tile, m_data->alpha ); 894 914 } 895 915 } … … 898 918 #else 899 919 const QRect tile( 0, 0, image.width(), image.height() ); 900 qwtToRgba( &image, &alphaImage, tile, d_data->alpha );920 qwtToRgba( &image, &alphaImage, tile, m_data->alpha ); 901 921 #endif 902 922 image = alphaImage; … … 916 936 917 937 \return Calculated scale map 918 */ 938 */ 919 939 QwtScaleMap QwtPlotRasterItem::imageMap( 920 940 Qt::Orientation orientation, 921 const QwtScaleMap &map, const QRectF&area,922 const QSize &imageSize, double pixelSize) const941 const QwtScaleMap& map, const QRectF& area, 942 const QSize& imageSize, double pixelSize) const 923 943 { 924 944 double p1, p2, s1, s2; -
trunk/BNC/qwt/qwt_plot_rasteritem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include "qwt_interval.h" 16 #include <qglobal.h> 15 17 16 #include <qstring.h> 18 #include <qimage.h> 17 18 class QwtInterval; 19 19 20 20 /*! 21 \brief A class, which displays raster data 21 \brief A class, which displays raster data 22 22 23 Raster data is a grid of pixel values, that can be represented 24 as a QImage. It is used for many types of information like 25 spectrograms, cartograms, geographical maps ... 23 Raster data is a grid of pixel values, that can be represented 24 as a QImage. It is used for many types of information like 25 spectrograms, cartograms, geographical maps ... 26 26 27 Often a plot has several types of raster data organized in layers. 28 ( f.e a geographical map, with weather statistics ). 29 Using setAlpha() raster items can be stacked easily. 27 Often a plot has several types of raster data organized in layers. 28 ( f.e a geographical map, with weather statistics ). 29 Using setAlpha() raster items can be stacked easily. 30 30 31 QwtPlotRasterItem is only implemented for images of the following formats: 32 QImage::Format_Indexed8, QImage::Format_ARGB32. 31 QwtPlotRasterItem is only implemented for images of the following formats: 32 QImage::Format_Indexed8, QImage::Format_ARGB32. 33 33 34 \sa QwtPlotSpectrogram 35 */ 34 \sa QwtPlotSpectrogram 35 */ 36 36 37 class QWT_EXPORT QwtPlotRasterItem: public QwtPlotItem 37 class QWT_EXPORT QwtPlotRasterItem : public QwtPlotItem 38 38 { 39 public: 39 public: 40 40 /*! 41 \brief Cache policy 42 The default policy is NoCache 41 \brief Cache policy 42 The default policy is NoCache 43 43 */ 44 44 enum CachePolicy 45 45 { 46 46 /*! 47 renderImage() is called each time the item has to be repainted 47 renderImage() is called each time the item has to be repainted 48 48 */ 49 49 NoCache, 50 50 51 51 /*! 52 renderImage() is called, whenever the image cache is not valid, 53 or the scales, or the size of the canvas has changed. 52 renderImage() is called, whenever the image cache is not valid, 53 or the scales, or the size of the canvas has changed. 54 54 55 This type of cache is useful for improving the performance 56 of hide/show operations or manipulations of the alpha value. 57 All other situations are handled by the canvas backing store. 55 This type of cache is useful for improving the performance 56 of hide/show operations or manipulations of the alpha value. 57 All other situations are handled by the canvas backing store. 58 58 */ 59 59 PaintCache … … 63 63 Attributes to modify the drawing algorithm. 64 64 \sa setPaintAttribute(), testPaintAttribute() 65 */ 65 */ 66 66 enum PaintAttribute 67 67 { 68 68 /*! 69 When the image is rendered according to the data pixels 70 ( QwtRasterData::pixelHint() ) it can be expanded to paint 71 device resolution before it is passed to QPainter. 72 The expansion algorithm rounds the pixel borders in the same 73 way as the axis ticks, what is usually better than the 74 scaling algorithm implemented in Qt. 75 Disabling this flag might make sense, to reduce the size of a 76 document/file. If this is possible for a document format 77 depends on the implementation of the specific QPaintEngine. 69 When the image is rendered according to the data pixels 70 ( QwtRasterData::pixelHint() ) it can be expanded to paint 71 device resolution before it is passed to QPainter. 72 The expansion algorithm rounds the pixel borders in the same 73 way as the axis ticks, what is usually better than the 74 scaling algorithm implemented in Qt. 75 Disabling this flag might make sense, to reduce the size of a 76 document/file. If this is possible for a document format 77 depends on the implementation of the specific QPaintEngine. 78 78 */ 79 79 … … 81 81 }; 82 82 83 //! Paint attributes 84 typedef QFlags<PaintAttribute> PaintAttributes; 83 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 85 84 86 85 explicit QwtPlotRasterItem( const QString& title = QString() ); … … 99 98 void invalidateCache(); 100 99 101 virtual void draw( QPainter *,102 const QwtScaleMap &xMap, const QwtScaleMap&yMap,103 const QRectF &canvasRect ) const;100 virtual void draw( QPainter*, 101 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 102 const QRectF& canvasRect ) const QWT_OVERRIDE; 104 103 105 virtual QRectF pixelHint( const QRectF & ) const;104 virtual QRectF pixelHint( const QRectF& ) const; 106 105 107 106 virtual QwtInterval interval(Qt::Axis) const; 108 virtual QRectF boundingRect() const; 107 virtual QRectF boundingRect() const QWT_OVERRIDE; 109 108 110 protected: 109 protected: 111 110 /*! 112 \brief Render an image 111 \brief Render an image 113 112 114 An implementation of render() might iterate over all 115 pixels of imageRect. Each pixel has to be translated into 116 the corresponding position in scale coordinates using the maps. 117 This position can be used to look up a value in a implementation 118 specific way and to map it into a color. 113 An implementation of render() might iterate over all 114 pixels of imageRect. Each pixel has to be translated into 115 the corresponding position in scale coordinates using the maps. 116 This position can be used to look up a value in a implementation 117 specific way and to map it into a color. 119 118 120 \param xMap X-Scale Map 121 \param yMap Y-Scale Map 122 \param area Requested area for the image in scale coordinates 123 \param imageSize Requested size of the image 119 \param xMap X-Scale Map 120 \param yMap Y-Scale Map 121 \param area Requested area for the image in scale coordinates 122 \param imageSize Requested size of the image 124 123 125 \return Rendered image 124 \return Rendered image 126 125 */ 127 virtual QImage renderImage( const QwtScaleMap &xMap,128 const QwtScaleMap &yMap, const QRectF&area,129 const QSize &imageSize ) const = 0;126 virtual QImage renderImage( const QwtScaleMap& xMap, 127 const QwtScaleMap& yMap, const QRectF& area, 128 const QSize& imageSize ) const = 0; 130 129 131 130 virtual QwtScaleMap imageMap( Qt::Orientation, 132 const QwtScaleMap &map, const QRectF&area,133 const QSize &imageSize, double pixelSize) const;131 const QwtScaleMap& map, const QRectF& area, 132 const QSize& imageSize, double pixelSize) const; 134 133 135 private: 136 QwtPlotRasterItem( const QwtPlotRasterItem & );137 QwtPlotRasterItem &operator=( const QwtPlotRasterItem& );134 private: 135 explicit QwtPlotRasterItem( const QwtPlotRasterItem& ); 136 QwtPlotRasterItem& operator=( const QwtPlotRasterItem& ); 138 137 139 138 void init(); 140 139 141 QImage compose( const QwtScaleMap &, const QwtScaleMap&,142 const QRectF &imageArea, const QRectF&paintRect,143 const QSize &imageSize, bool doCache) const;140 QImage compose( const QwtScaleMap&, const QwtScaleMap&, 141 const QRectF& imageArea, const QRectF& paintRect, 142 const QSize& imageSize, bool doCache) const; 144 143 145 144 146 145 class PrivateData; 147 PrivateData *d_data;146 PrivateData* m_data; 148 147 }; 149 148 -
trunk/BNC/qwt/qwt_plot_renderer.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 28 28 #include <qimagewriter.h> 29 29 #include <qvariant.h> 30 #include <qmargins.h> 30 31 31 32 #ifndef QWT_NO_SVG 32 33 #ifdef QT_SVG_LIB 33 #if QT_VERSION >= 0x04050034 34 #define QWT_FORMAT_SVG 1 35 #endif36 35 #endif 37 36 #endif … … 73 72 #endif 74 73 74 static qreal qwtScalePenWidth( const QwtPlot* plot ) 75 { 76 qreal pw = 0.0; 77 78 for ( int axisId = 0; axisId < QwtAxis::AxisPositions; axisId++ ) 79 { 80 if ( plot->isAxisVisible( 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( QwtAxis::YLeft )->palette(); 90 return pal.color( QPalette::WindowText ); 91 } 92 75 93 static QPainterPath qwtCanvasClip( 76 const QWidget* canvas, const QRectF &canvasRect )94 const QWidget* canvas, const QRectF& canvasRect ) 77 95 { 78 96 // The clip region is calculated in integers … … 80 98 // calculate it in target device resolution 81 99 82 int x1 = qCeil( canvasRect.left() ); 83 int x2 = qFloor( canvasRect.right() ); 84 int y1 = qCeil( canvasRect.top() ); 85 int y2 = qFloor( canvasRect.bottom() ); 100 int x1 = qwtCeil( canvasRect.left() ); 101 int x2 = qwtFloor( canvasRect.right() ); 102 int y1 = qwtCeil( canvasRect.top() ); 103 int y2 = qwtFloor( canvasRect.bottom() ); 86 104 87 105 const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 ); … … 90 108 91 109 ( void ) QMetaObject::invokeMethod( 92 const_cast< QWidget *>( canvas ), "borderPath",110 const_cast< QWidget* >( canvas ), "borderPath", 93 111 Qt::DirectConnection, 94 112 Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) ); … … 97 115 } 98 116 99 static inline QFont qwtResolvedFont( const QWidget *widget )117 static inline QFont qwtResolvedFont( const QWidget* widget ) 100 118 { 101 119 QFont font = widget->font(); 120 #if QT_VERSION >= 0x060000 121 font.setResolveMask( QFont::AllPropertiesResolved ); 122 #else 102 123 font.resolve( QFont::AllPropertiesResolved ); 124 #endif 103 125 104 126 return font; … … 107 129 class QwtPlotRenderer::PrivateData 108 130 { 109 public: 110 PrivateData() :111 discardFlags( QwtPlotRenderer::DiscardNone ) ,112 layoutFlags( QwtPlotRenderer::DefaultLayout ) 131 public: 132 PrivateData() 133 : discardFlags( QwtPlotRenderer::DiscardNone ) 134 , layoutFlags( QwtPlotRenderer::DefaultLayout ) 113 135 { 114 136 } … … 121 143 Constructor 122 144 \param parent Parent object 123 */ 124 QwtPlotRenderer::QwtPlotRenderer( QObject *parent ):125 QObject( parent ) 126 { 127 d_data = new PrivateData;145 */ 146 QwtPlotRenderer::QwtPlotRenderer( QObject* parent ) 147 : QObject( parent ) 148 { 149 m_data = new PrivateData; 128 150 } 129 151 … … 131 153 QwtPlotRenderer::~QwtPlotRenderer() 132 154 { 133 delete d_data;134 } 135 136 /*! 137 Change a flag, indicating what to discard from rendering 138 139 \param flag Flag to change 140 \param on On/Off 141 142 \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags() 143 */ 155 delete m_data; 156 } 157 158 /*! 159 Change a flag, indicating what to discard from rendering 160 161 \param flag Flag to change 162 \param on On/Off 163 164 \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags() 165 */ 144 166 void QwtPlotRenderer::setDiscardFlag( DiscardFlag flag, bool on ) 145 167 { 146 168 if ( on ) 147 d_data->discardFlags |= flag;169 m_data->discardFlags |= flag; 148 170 else 149 d_data->discardFlags &= ~flag;150 } 151 152 /*! 153 \return True, if flag is enabled. 154 \param flag Flag to be tested 155 \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags() 156 */ 171 m_data->discardFlags &= ~flag; 172 } 173 174 /*! 175 \return True, if flag is enabled. 176 \param flag Flag to be tested 177 \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags() 178 */ 157 179 bool QwtPlotRenderer::testDiscardFlag( DiscardFlag flag ) const 158 180 { 159 return d_data->discardFlags & flag;160 } 161 162 /*! 163 Set the flags, indicating what to discard from rendering 164 165 \param flags Flags 166 \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags() 167 */ 181 return m_data->discardFlags & flag; 182 } 183 184 /*! 185 Set the flags, indicating what to discard from rendering 186 187 \param flags Flags 188 \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags() 189 */ 168 190 void QwtPlotRenderer::setDiscardFlags( DiscardFlags flags ) 169 191 { 170 d_data->discardFlags = flags;171 } 172 173 /*! 174 \return Flags, indicating what to discard from rendering 175 \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag() 176 */ 192 m_data->discardFlags = flags; 193 } 194 195 /*! 196 \return Flags, indicating what to discard from rendering 197 \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag() 198 */ 177 199 QwtPlotRenderer::DiscardFlags QwtPlotRenderer::discardFlags() const 178 200 { 179 return d_data->discardFlags;180 } 181 182 /*! 183 Change a layout flag 184 185 \param flag Flag to change 186 \param on On/Off 187 188 \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags() 189 */ 201 return m_data->discardFlags; 202 } 203 204 /*! 205 Change a layout flag 206 207 \param flag Flag to change 208 \param on On/Off 209 210 \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags() 211 */ 190 212 void QwtPlotRenderer::setLayoutFlag( LayoutFlag flag, bool on ) 191 213 { 192 214 if ( on ) 193 d_data->layoutFlags |= flag;215 m_data->layoutFlags |= flag; 194 216 else 195 d_data->layoutFlags &= ~flag;196 } 197 198 /*! 199 \return True, if flag is enabled. 200 \param flag Flag to be tested 201 \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags() 202 */ 217 m_data->layoutFlags &= ~flag; 218 } 219 220 /*! 221 \return True, if flag is enabled. 222 \param flag Flag to be tested 223 \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags() 224 */ 203 225 bool QwtPlotRenderer::testLayoutFlag( LayoutFlag flag ) const 204 226 { 205 return d_data->layoutFlags & flag;206 } 207 208 /*! 209 Set the layout flags 210 211 \param flags Flags 212 \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags() 213 */ 227 return m_data->layoutFlags & flag; 228 } 229 230 /*! 231 Set the layout flags 232 233 \param flags Flags 234 \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags() 235 */ 214 236 void QwtPlotRenderer::setLayoutFlags( LayoutFlags flags ) 215 237 { 216 d_data->layoutFlags = flags;217 } 218 219 /*! 220 \return Layout flags 221 \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag() 222 */ 238 m_data->layoutFlags = flags; 239 } 240 241 /*! 242 \return Layout flags 243 \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag() 244 */ 223 245 QwtPlotRenderer::LayoutFlags QwtPlotRenderer::layoutFlags() const 224 246 { 225 return d_data->layoutFlags;226 } 227 228 /*! 229 Render a plot to a file 230 231 The format of the document will be auto-detected from the 232 suffix of the file name. 233 234 \param plot Plot widget 235 \param fileName Path of the file, where the document will be stored 236 \param sizeMM Size for the document in millimeters. 237 \param resolution Resolution in dots per Inch (dpi) 238 */ 239 void QwtPlotRenderer::renderDocument( QwtPlot *plot,240 const QString &fileName, const QSizeF&sizeMM, int resolution )247 return m_data->layoutFlags; 248 } 249 250 /*! 251 Render a plot to a file 252 253 The format of the document will be auto-detected from the 254 suffix of the file name. 255 256 \param plot Plot widget 257 \param fileName Path of the file, where the document will be stored 258 \param sizeMM Size for the document in millimeters. 259 \param resolution Resolution in dots per Inch (dpi) 260 */ 261 void QwtPlotRenderer::renderDocument( QwtPlot* plot, 262 const QString& fileName, const QSizeF& sizeMM, int resolution ) 241 263 { 242 264 renderDocument( plot, fileName, … … 245 267 246 268 /*! 247 Render a plot to a file 248 249 Supported formats are: 250 251 - pdf\n 269 Render a plot to a file 270 271 Supported formats are: 272 273 - pdf\n 252 274 Portable Document Format PDF 253 - ps\n 275 - ps\n 254 276 Postcript 255 - svg\n 277 - svg\n 256 278 Scalable Vector Graphics SVG 257 - all image formats supported by Qt\n 279 - all image formats supported by Qt\n 258 280 see QImageWriter::supportedImageFormats() 259 281 260 Scalable vector graphic formats like PDF or SVG are superior to 261 raster graphics formats. 262 263 \param plot Plot widget 264 \param fileName Path of the file, where the document will be stored 265 \param format Format for the document 266 \param sizeMM Size for the document in millimeters. 267 \param resolution Resolution in dots per Inch (dpi) 268 269 \sa renderTo(), render(), QwtPainter::setRoundingAlignment() 270 */ 271 void QwtPlotRenderer::renderDocument( QwtPlot *plot,272 const QString &fileName, const QString&format,273 const QSizeF &sizeMM, int resolution )282 Scalable vector graphic formats like PDF or SVG are superior to 283 raster graphics formats. 284 285 \param plot Plot widget 286 \param fileName Path of the file, where the document will be stored 287 \param format Format for the document 288 \param sizeMM Size for the document in millimeters. 289 \param resolution Resolution in dots per Inch (dpi) 290 291 \sa renderTo(), render(), QwtPainter::setRoundingAlignment() 292 */ 293 void QwtPlotRenderer::renderDocument( QwtPlot* plot, 294 const QString& fileName, const QString& format, 295 const QSizeF& sizeMM, int resolution ) 274 296 { 275 297 if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 ) … … 292 314 #if QWT_PDF_WRITER 293 315 QPdfWriter pdfWriter( fileName ); 294 pdfWriter.setPageSize MM( sizeMM );316 pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) ); 295 317 pdfWriter.setTitle( title ); 296 318 pdfWriter.setPageMargins( QMarginsF() ); … … 366 388 367 389 /*! 368 \brief Render the plot to a \c QPaintDevice 369 370 This function renders the contents of a QwtPlot instance to 371 \c QPaintDevice object. The target rectangle is derived from 372 its device metrics. 373 374 \param plot Plot to be rendered 375 \param paintDevice device to paint on, f.e a QImage 376 377 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 378 */ 390 \brief Render the plot to a \c QPaintDevice 391 392 This function renders the contents of a QwtPlot instance to 393 \c QPaintDevice object. The target rectangle is derived from 394 its device metrics. 395 396 \param plot Plot to be rendered 397 \param paintDevice device to paint on, f.e a QImage 398 399 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 400 */ 379 401 380 402 void QwtPlotRenderer::renderTo( 381 QwtPlot *plot, QPaintDevice&paintDevice ) const403 QwtPlot* plot, QPaintDevice& paintDevice ) const 382 404 { 383 405 int w = paintDevice.width(); … … 389 411 390 412 /*! 391 \brief Render the plot to a QPrinter 392 393 This function renders the contents of a QwtPlot instance to 394 \c QPaintDevice object. The size is derived from the printer 395 metrics. 396 397 \param plot Plot to be rendered 398 \param printer Printer to paint on 399 400 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 401 */ 413 \brief Render the plot to a QPrinter 414 415 This function renders the contents of a QwtPlot instance to 416 \c QPaintDevice object. The size is derived from the printer 417 metrics. 418 419 \param plot Plot to be rendered 420 \param printer Printer to paint on 421 422 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 423 */ 402 424 403 425 #ifndef QT_NO_PRINTER 404 426 405 427 void QwtPlotRenderer::renderTo( 406 QwtPlot *plot, QPrinter&printer ) const428 QwtPlot* plot, QPrinter& printer ) const 407 429 { 408 430 int w = printer.width(); … … 423 445 424 446 /*! 425 \brief Render the plot to a QSvgGenerator 426 427 If the generator has a view box, the plot will be rendered into it. 428 If it has no viewBox but a valid size the target coordinates 429 will be (0, 0, generator.width(), generator.height()). Otherwise 430 the target rectangle will be QRectF(0, 0, 800, 600); 431 432 \param plot Plot to be rendered 433 \param generator SVG generator 434 */ 447 \brief Render the plot to a QSvgGenerator 448 449 If the generator has a view box, the plot will be rendered into it. 450 If it has no viewBox but a valid size the target coordinates 451 will be (0, 0, generator.width(), generator.height()). Otherwise 452 the target rectangle will be QRectF(0, 0, 800, 600); 453 454 \param plot Plot to be rendered 455 \param generator SVG generator 456 */ 435 457 void QwtPlotRenderer::renderTo( 436 QwtPlot *plot, QSvgGenerator&generator ) const458 QwtPlot* plot, QSvgGenerator& generator ) const 437 459 { 438 460 QRectF rect = generator.viewBoxF(); … … 450 472 451 473 /*! 452 Paint the contents of a QwtPlot instance into a given rectangle. 453 454 \param plot Plot to be rendered 455 \param painter Painter 456 \param plotRect Bounding rectangle 457 458 \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment() 459 */ 460 void QwtPlotRenderer::render( QwtPlot *plot,461 QPainter *painter, const QRectF&plotRect ) const474 Paint the contents of a QwtPlot instance into a given rectangle. 475 476 \param plot Plot to be rendered 477 \param painter Painter 478 \param plotRect Bounding rectangle 479 480 \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment() 481 */ 482 void QwtPlotRenderer::render( QwtPlot* plot, 483 QPainter* painter, const QRectF& plotRect ) const 462 484 { 463 485 if ( painter == 0 || !painter->isActive() || 464 !plotRect.isValid() || plot->size().isNull() )486 !plotRect.isValid() || plot->size().isNull() ) 465 487 { 466 488 return; 467 489 } 468 490 469 if ( !( d_data->discardFlags & DiscardBackground ) )491 if ( !( m_data->discardFlags & DiscardBackground ) ) 470 492 QwtPainter::drawBackgound( painter, plotRect, plot ); 471 493 472 494 /* 473 The layout engine uses the same methods as they are used 474 by the Qt layout system. Therefore we need to calculate the 475 layout in screen coordinates and paint with a scaled painter. 495 The layout engine uses the same methods as they are used 496 by the Qt layout system. Therefore we need to calculate the 497 layout in screen coordinates and paint with a scaled painter. 476 498 */ 477 499 QTransform transform; … … 482 504 QRectF layoutRect = transform.inverted().mapRect( plotRect ); 483 505 484 if ( !( d_data->discardFlags & DiscardBackground ) )506 if ( !( m_data->discardFlags & DiscardBackground ) ) 485 507 { 486 508 // subtract the contents margins 487 509 488 int left, top, right, bottom; 489 plot->getContentsMargins( &left, &top, &right, &bottom ); 490 layoutRect.adjust( left, top, -right, -bottom ); 491 } 492 493 QwtPlotLayout *layout = plot->plotLayout(); 494 495 int baseLineDists[QwtPlot::axisCnt]; 496 int canvasMargins[QwtPlot::axisCnt]; 497 498 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 499 { 500 canvasMargins[ axisId ] = layout->canvasMargin( axisId ); 501 502 if ( d_data->layoutFlags & FrameWithScales ) 503 { 504 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); 510 const QMargins m = plot->contentsMargins(); 511 layoutRect.adjust( m.left(), m.top(), -m.right(), -m.bottom() ); 512 } 513 514 QwtPlotLayout* layout = plot->plotLayout(); 515 516 int baseLineDists[QwtAxis::AxisPositions]; 517 int canvasMargins[QwtAxis::AxisPositions]; 518 519 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 520 { 521 canvasMargins[axisPos] = layout->canvasMargin( axisPos ); 522 523 if ( m_data->layoutFlags & FrameWithScales ) 524 { 525 const QwtAxisId axisId( axisPos ); 526 527 QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 505 528 if ( scaleWidget ) 506 529 { 507 baseLineDists[axis Id] = scaleWidget->margin();530 baseLineDists[axisPos] = scaleWidget->margin(); 508 531 scaleWidget->setMargin( 0 ); 509 532 } 510 533 511 if ( !plot-> axisEnabled( axisId ) )534 if ( !plot->isAxisVisible( axisId ) ) 512 535 { 513 536 // When we have a scale the frame is painted on … … 515 538 // need to introduce a margin around the canvas 516 539 517 switch( axisId ) 540 const qreal fw = qwtScalePenWidth( plot ); 541 542 switch( axisPos ) 518 543 { 519 case Qwt Plot::yLeft:520 layoutRect.adjust( 1, 0, 0, 0 );544 case QwtAxis::YLeft: 545 layoutRect.adjust( fw, 0, 0, 0 ); 521 546 break; 522 case QwtPlot::yRight: 523 layoutRect.adjust( 0, 0, -1, 0 ); 547 548 case QwtAxis::YRight: 549 layoutRect.adjust( 0, 0, -fw, 0 ); 524 550 break; 525 case QwtPlot::xTop: 526 layoutRect.adjust( 0, 1, 0, 0 ); 551 552 case QwtAxis::XTop: 553 layoutRect.adjust( 0, fw, 0, 0 ); 527 554 break; 528 case QwtPlot::xBottom: 529 layoutRect.adjust( 0, 0, 0, -1 ); 555 556 case QwtAxis::XBottom: 557 layoutRect.adjust( 0, 0, 0, -fw ); 530 558 break; 559 531 560 default: 532 break;561 ; 533 562 } 534 563 } … … 540 569 QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars; 541 570 542 if ( ( d_data->layoutFlags & FrameWithScales ) ||543 ( d_data->discardFlags & DiscardCanvasFrame ) )571 if ( ( m_data->layoutFlags & FrameWithScales ) || 572 ( m_data->discardFlags & DiscardCanvasFrame ) ) 544 573 { 545 574 layoutOptions |= QwtPlotLayout::IgnoreFrames; 546 575 } 547 576 548 if ( d_data->discardFlags & DiscardLegend )577 if ( m_data->discardFlags & DiscardLegend ) 549 578 layoutOptions |= QwtPlotLayout::IgnoreLegend; 550 579 551 if ( d_data->discardFlags & DiscardTitle )580 if ( m_data->discardFlags & DiscardTitle ) 552 581 layoutOptions |= QwtPlotLayout::IgnoreTitle; 553 582 554 if ( d_data->discardFlags & DiscardFooter )583 if ( m_data->discardFlags & DiscardFooter ) 555 584 layoutOptions |= QwtPlotLayout::IgnoreFooter; 556 585 … … 559 588 // canvas 560 589 561 QwtScaleMap maps[Qwt Plot::axisCnt];590 QwtScaleMap maps[QwtAxis::AxisPositions]; 562 591 buildCanvasMaps( plot, layout->canvasRect(), maps ); 563 592 if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) ) … … 577 606 renderCanvas( plot, painter, layout->canvasRect(), maps ); 578 607 579 if ( !( d_data->discardFlags & DiscardTitle )608 if ( !( m_data->discardFlags & DiscardTitle ) 580 609 && ( !plot->titleLabel()->text().isEmpty() ) ) 581 610 { … … 583 612 } 584 613 585 if ( !( d_data->discardFlags & DiscardFooter )614 if ( !( m_data->discardFlags & DiscardFooter ) 586 615 && ( !plot->footerLabel()->text().isEmpty() ) ) 587 616 { … … 589 618 } 590 619 591 if ( !( d_data->discardFlags & DiscardLegend )620 if ( !( m_data->discardFlags & DiscardLegend ) 592 621 && plot->legend() && !plot->legend()->isEmpty() ) 593 622 { … … 595 624 } 596 625 597 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 598 { 599 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); 600 if ( scaleWidget ) 601 { 602 int baseDist = scaleWidget->margin(); 603 604 int startDist, endDist; 605 scaleWidget->getBorderDistHint( startDist, endDist ); 606 607 renderScale( plot, painter, axisId, startDist, endDist, 608 baseDist, layout->scaleRect( axisId ) ); 626 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 627 { 628 { 629 const QwtAxisId axisId( axisPos ); 630 631 QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 632 if ( scaleWidget ) 633 { 634 int baseDist = scaleWidget->margin(); 635 636 int startDist, endDist; 637 scaleWidget->getBorderDistHint( startDist, endDist ); 638 639 renderScale( plot, painter, axisId, startDist, endDist, 640 baseDist, layout->scaleRect( axisId ) ); 641 } 609 642 } 610 643 } … … 613 646 614 647 // restore all setting to their original attributes. 615 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 616 { 617 if ( d_data->layoutFlags & FrameWithScales ) 618 { 619 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); 648 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 649 { 650 if ( m_data->layoutFlags & FrameWithScales ) 651 { 652 const QwtAxisId axisId( axisPos ); 653 654 QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 620 655 if ( scaleWidget ) 621 scaleWidget->setMargin( baseLineDists[axis Id] );622 } 623 624 layout->setCanvasMargin( canvasMargins[axis Id] );656 scaleWidget->setMargin( baseLineDists[axisPos] ); 657 } 658 659 layout->setCanvasMargin( canvasMargins[axisPos] ); 625 660 } 626 661 … … 630 665 631 666 /*! 632 Render the title into a given rectangle. 633 634 \param plot Plot widget 635 \param painter Painter 636 \param titleRect Bounding rectangle for the title 637 */ 638 void QwtPlotRenderer::renderTitle( const QwtPlot *plot,639 QPainter *painter, const QRectF&titleRect ) const667 Render the title into a given rectangle. 668 669 \param plot Plot widget 670 \param painter Painter 671 \param titleRect Bounding rectangle for the title 672 */ 673 void QwtPlotRenderer::renderTitle( const QwtPlot* plot, 674 QPainter* painter, const QRectF& titleRect ) const 640 675 { 641 676 painter->setFont( qwtResolvedFont( plot->titleLabel() ) ); 642 677 643 678 const QColor color = plot->titleLabel()->palette().color( 644 QPalette::Active, QPalette::Text );679 QPalette::Active, QPalette::Text ); 645 680 646 681 painter->setPen( color ); … … 649 684 650 685 /*! 651 Render the footer into a given rectangle. 652 653 \param plot Plot widget 654 \param painter Painter 655 \param footerRect Bounding rectangle for the footer 656 */ 657 void QwtPlotRenderer::renderFooter( const QwtPlot *plot,658 QPainter *painter, const QRectF&footerRect ) const686 Render the footer into a given rectangle. 687 688 \param plot Plot widget 689 \param painter Painter 690 \param footerRect Bounding rectangle for the footer 691 */ 692 void QwtPlotRenderer::renderFooter( const QwtPlot* plot, 693 QPainter* painter, const QRectF& footerRect ) const 659 694 { 660 695 painter->setFont( qwtResolvedFont( plot->footerLabel() ) ); 661 696 662 697 const QColor color = plot->footerLabel()->palette().color( 663 QPalette::Active, QPalette::Text );698 QPalette::Active, QPalette::Text ); 664 699 665 700 painter->setPen( color ); … … 668 703 669 704 /*! 670 Render the legend into a given rectangle. 671 672 \param plot Plot widget 673 \param painter Painter 674 \param legendRect Bounding rectangle for the legend 675 */ 676 void QwtPlotRenderer::renderLegend( const QwtPlot *plot,677 QPainter *painter, const QRectF&legendRect ) const705 Render the legend into a given rectangle. 706 707 \param plot Plot widget 708 \param painter Painter 709 \param legendRect Bounding rectangle for the legend 710 */ 711 void QwtPlotRenderer::renderLegend( const QwtPlot* plot, 712 QPainter* painter, const QRectF& legendRect ) const 678 713 { 679 714 if ( plot->legend() ) 680 715 { 681 bool fillBackground = !( d_data->discardFlags & DiscardBackground );716 bool fillBackground = !( m_data->discardFlags & DiscardBackground ); 682 717 plot->legend()->renderLegend( painter, legendRect, fillBackground ); 683 718 } … … 685 720 686 721 /*! 687 \brief Paint a scale into a given rectangle. 688 Paint the scale into a given rectangle. 689 690 \param plot Plot widget 691 \param painter Painter 692 \param axisId Axis 693 \param startDist Start border distance 694 \param endDist End border distance 695 \param baseDist Base distance 696 \param scaleRect Bounding rectangle for the scale 697 */ 698 void QwtPlotRenderer::renderScale( const QwtPlot *plot, 699 QPainter *painter, 700 int axisId, int startDist, int endDist, int baseDist, 701 const QRectF &scaleRect ) const 702 { 703 if ( !plot->axisEnabled( axisId ) ) 722 \brief Paint a scale into a given rectangle. 723 Paint the scale into a given rectangle. 724 725 \param plot Plot widget 726 \param painter Painter 727 \param axisId Axis 728 \param startDist Start border distance 729 \param endDist End border distance 730 \param baseDist Base distance 731 \param scaleRect Bounding rectangle for the scale 732 */ 733 void QwtPlotRenderer::renderScale( const QwtPlot* plot, QPainter* painter, 734 QwtAxisId axisId, int startDist, int endDist, int baseDist, 735 const QRectF& scaleRect ) const 736 { 737 if ( !plot->isAxisVisible( axisId ) ) 704 738 return; 705 739 706 const QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );740 const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 707 741 if ( scaleWidget->isColorBarEnabled() 708 742 && scaleWidget->colorBarWidth() > 0 ) … … 717 751 double x, y, w; 718 752 753 qreal off = 0.0; 754 if ( m_data->layoutFlags & FrameWithScales ) 755 off = qwtScalePenWidth( plot ); 756 719 757 switch ( axisId ) 720 758 { 721 case Qwt Plot::yLeft:722 { 723 x = scaleRect.right() - 1.0 - baseDist; 759 case QwtAxis::YLeft: 760 { 761 x = scaleRect.right() - 1.0 - baseDist - off; 724 762 y = scaleRect.y() + startDist; 725 763 w = scaleRect.height() - startDist - endDist; … … 727 765 break; 728 766 } 729 case Qwt Plot::yRight:730 { 731 x = scaleRect.left() + baseDist; 767 case QwtAxis::YRight: 768 { 769 x = scaleRect.left() + baseDist + off; 732 770 y = scaleRect.y() + startDist; 733 771 w = scaleRect.height() - startDist - endDist; … … 735 773 break; 736 774 } 737 case Qwt Plot::xTop:775 case QwtAxis::XTop: 738 776 { 739 777 x = scaleRect.left() + startDist; 740 y = scaleRect.bottom() - 1.0 - baseDist; 778 y = scaleRect.bottom() - 1.0 - baseDist - off; 741 779 w = scaleRect.width() - startDist - endDist; 742 780 align = QwtScaleDraw::TopScale; 743 781 break; 744 782 } 745 case Qwt Plot::xBottom:783 case QwtAxis::XBottom: 746 784 { 747 785 x = scaleRect.left() + startDist; 748 y = scaleRect.top() + baseDist; 786 y = scaleRect.top() + baseDist + off; 749 787 w = scaleRect.width() - startDist - endDist; 750 788 align = QwtScaleDraw::BottomScale; … … 759 797 painter->setFont( qwtResolvedFont( scaleWidget ) ); 760 798 761 QwtScaleDraw *sd = const_cast<QwtScaleDraw*>( scaleWidget->scaleDraw() );799 QwtScaleDraw* sd = const_cast< QwtScaleDraw* >( scaleWidget->scaleDraw() ); 762 800 const QPointF sdPos = sd->pos(); 763 801 const double sdLength = sd->length(); 802 803 const bool hasBackbone = sd->hasComponent( QwtAbstractScaleDraw::Backbone ); 804 805 if ( m_data->layoutFlags & FrameWithScales ) 806 sd->enableComponent( QwtAbstractScaleDraw::Backbone, false ); 764 807 765 808 sd->move( x, y ); … … 773 816 sd->move( sdPos ); 774 817 sd->setLength( sdLength ); 818 sd->enableComponent( QwtAbstractScaleDraw::Backbone, hasBackbone ); 775 819 776 820 painter->restore(); … … 778 822 779 823 /*! 780 Render the canvas into a given rectangle. 781 782 \param plot Plot widget 783 \param painter Painter 784 \param maps Maps mapping between plot and paint device coordinates 785 \param canvasRect Canvas rectangle 786 */ 787 void QwtPlotRenderer::renderCanvas( const QwtPlot *plot,788 QPainter *painter, const QRectF&canvasRect,789 const QwtScaleMap *maps ) const790 { 791 const QWidget *canvas = plot->canvas();824 Render the canvas into a given rectangle. 825 826 \param plot Plot widget 827 \param painter Painter 828 \param maps Maps mapping between plot and paint device coordinates 829 \param canvasRect Canvas rectangle 830 */ 831 void QwtPlotRenderer::renderCanvas( const QwtPlot* plot, 832 QPainter* painter, const QRectF& canvasRect, 833 const QwtScaleMap* maps ) const 834 { 835 const QWidget* canvas = plot->canvas(); 792 836 793 837 QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 ); 794 838 795 if ( d_data->layoutFlags & FrameWithScales )839 if ( m_data->layoutFlags & FrameWithScales ) 796 840 { 797 841 painter->save(); 798 842 799 r.adjust( -1.0, -1.0, 1.0, 1.0 ); 800 painter->setPen( QPen( Qt::black ) ); 801 802 if ( !( d_data->discardFlags & DiscardCanvasBackground ) ) 843 QPen pen; 844 pen.setColor( qwtScalePenColor( plot ) ); 845 pen.setWidth( qwtScalePenWidth( plot ) ); 846 pen.setJoinStyle( Qt::MiterJoin ); 847 848 painter->setPen( pen ); 849 850 const qreal pw2 = 0.5 * pen.widthF(); 851 r.adjust( -pw2, -pw2, pw2, pw2 ); 852 853 if ( !( m_data->discardFlags & DiscardCanvasBackground ) ) 803 854 { 804 855 const QBrush bgBrush = … … 823 874 painter->save(); 824 875 825 if ( !( d_data->discardFlags & DiscardCanvasBackground ) )876 if ( !( m_data->discardFlags & DiscardCanvasBackground ) ) 826 877 { 827 878 QwtPainter::drawBackgound( painter, r, canvas ); … … 845 896 QPainterPath clipPath; 846 897 847 intframeWidth = 0;848 849 if ( !( d_data->discardFlags & DiscardCanvasFrame ) )898 double frameWidth = 0.0; 899 900 if ( !( m_data->discardFlags & DiscardCanvasFrame ) ) 850 901 { 851 902 const QVariant fw = canvas->property( "frameWidth" ); 852 if ( fw. type() == QVariant::Int)853 frameWidth = fw. toInt();903 if ( fw.canConvert< double >() ) 904 frameWidth = fw.value< double >(); 854 905 855 906 clipPath = qwtCanvasClip( canvas, canvasRect ); … … 870 921 } 871 922 872 if ( !( d_data->discardFlags & DiscardCanvasBackground ) )923 if ( !( m_data->discardFlags & DiscardCanvasBackground ) ) 873 924 { 874 925 QwtPainter::drawBackgound( painter, innerRect, canvas ); … … 888 939 889 940 const QVariant borderRadius = canvas->property( "borderRadius" ); 890 if ( borderRadius. type() == QVariant::Double891 && borderRadius. toDouble() > 0.0 )941 if ( borderRadius.canConvert< double >() 942 && borderRadius.value< double >() > 0.0 ) 892 943 { 893 const double radius = borderRadius. toDouble();944 const double radius = borderRadius.value< double >(); 894 945 895 946 QwtPainter::drawRoundedFrame( painter, canvasRect, … … 915 966 \param canvasRect Target rectangle 916 967 \param maps Scale maps to be calculated 917 */ 918 void QwtPlotRenderer::buildCanvasMaps( const QwtPlot *plot, 919 const QRectF &canvasRect, QwtScaleMap maps[] ) const 920 { 921 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 922 { 923 maps[axisId].setTransformation( 924 plot->axisScaleEngine( axisId )->transformation() ); 925 926 const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId ); 927 maps[axisId].setScaleInterval( 928 scaleDiv.lowerBound(), scaleDiv.upperBound() ); 929 930 double from, to; 931 if ( plot->axisEnabled( axisId ) ) 932 { 933 const int sDist = plot->axisWidget( axisId )->startBorderDist(); 934 const int eDist = plot->axisWidget( axisId )->endBorderDist(); 935 const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId ); 936 937 if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom ) 968 */ 969 void QwtPlotRenderer::buildCanvasMaps( const QwtPlot* plot, 970 const QRectF& canvasRect, QwtScaleMap maps[] ) const 971 { 972 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 973 { 974 { 975 const QwtAxisId axisId( axisPos ); 976 977 QwtScaleMap& scaleMap = maps[axisId]; 978 979 scaleMap.setTransformation( 980 plot->axisScaleEngine( axisId )->transformation() ); 981 982 const QwtScaleDiv& scaleDiv = plot->axisScaleDiv( axisId ); 983 scaleMap.setScaleInterval( 984 scaleDiv.lowerBound(), scaleDiv.upperBound() ); 985 986 double from, to; 987 if ( plot->isAxisVisible( axisId ) ) 938 988 { 939 from = scaleRect.left() + sDist; 940 to = scaleRect.right() - eDist; 989 const int sDist = plot->axisWidget( axisId )->startBorderDist(); 990 const int eDist = plot->axisWidget( axisId )->endBorderDist(); 991 const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId ); 992 993 if ( QwtAxis::isXAxis( axisPos ) ) 994 { 995 from = scaleRect.left() + sDist; 996 to = scaleRect.right() - eDist; 997 } 998 else 999 { 1000 from = scaleRect.bottom() - eDist; 1001 to = scaleRect.top() + sDist; 1002 } 941 1003 } 942 1004 else 943 1005 { 944 from = scaleRect.bottom() - eDist; 945 to = scaleRect.top() + sDist; 1006 int margin = 0; 1007 if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) ) 1008 margin = plot->plotLayout()->canvasMargin( axisPos ); 1009 1010 if ( QwtAxis::isYAxis( axisPos ) ) 1011 { 1012 from = canvasRect.bottom() - margin; 1013 to = canvasRect.top() + margin; 1014 } 1015 else 1016 { 1017 from = canvasRect.left() + margin; 1018 to = canvasRect.right() - margin; 1019 } 946 1020 } 947 } 948 else 949 { 950 int margin = 0; 951 if ( !plot->plotLayout()->alignCanvasToScale( axisId ) ) 952 margin = plot->plotLayout()->canvasMargin( axisId ); 953 954 if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight ) 955 { 956 from = canvasRect.bottom() - margin; 957 to = canvasRect.top() + margin; 958 } 959 else 960 { 961 from = canvasRect.left() + margin; 962 to = canvasRect.right() - margin; 963 } 964 } 965 maps[axisId].setPaintInterval( from, to ); 966 } 967 } 968 969 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot *plot, 970 const QRectF &canvasRect, const QwtScaleMap maps[] ) const 971 { 972 double margins[QwtPlot::axisCnt]; 1021 scaleMap.setPaintInterval( from, to ); 1022 } 1023 } 1024 } 1025 1026 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot* plot, 1027 const QRectF& canvasRect, const QwtScaleMap maps[] ) const 1028 { 1029 using namespace QwtAxis; 1030 1031 double margins[AxisPositions]; 973 1032 plot->getCanvasMarginsHint( maps, canvasRect, 974 margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 975 margins[QwtPlot::yRight], margins[QwtPlot::xBottom] ); 1033 margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] ); 976 1034 977 1035 bool marginsChanged = false; 978 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )1036 for ( int axisId = 0; axisId < AxisPositions; axisId++ ) 979 1037 { 980 1038 if ( margins[axisId] >= 0.0 ) 981 1039 { 982 const int m = qCeil( margins[axisId] ); 1040 const int m = qwtCeil( margins[axisId] ); 983 1041 plot->plotLayout()->setCanvasMargin( m, axisId); 984 1042 marginsChanged = true; … … 999 1057 \return True, when exporting was successful 1000 1058 \sa renderDocument() 1001 */ 1002 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString&documentName,1003 const QSizeF&sizeMM, int resolution )1059 */ 1060 bool QwtPlotRenderer::exportTo( QwtPlot* plot, const QString& documentName, 1061 const QSizeF& sizeMM, int resolution ) 1004 1062 { 1005 1063 if ( plot == NULL ) … … 1011 1069 1012 1070 #ifndef QT_NO_FILEDIALOG 1013 const QList<QByteArray> imageFormats = 1071 const QList< QByteArray > imageFormats = 1014 1072 QImageWriter::supportedImageFormats(); 1015 1073 … … 1052 1110 return true; 1053 1111 } 1112 1113 #include "moc_qwt_plot_renderer.cpp" -
trunk/BNC/qwt/qwt_plot_renderer.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_axis_id.h" 15 14 16 #include <qobject.h> 15 17 #include <qsize.h> … … 34 36 \brief Renderer for exporting a plot to a document, a printer 35 37 or anything else, that is supported by QPainter/QPaintDevice 36 */ 37 class QWT_EXPORT QwtPlotRenderer: public QObject 38 */ 39 class QWT_EXPORT QwtPlotRenderer : public QObject 38 40 { 39 41 Q_OBJECT 40 42 41 public: 42 //! Disard flags 43 public: 44 //! Discard flags 43 45 enum DiscardFlag 44 46 { … … 72 74 }; 73 75 74 //! Disard flags 75 typedef QFlags<DiscardFlag> DiscardFlags; 76 Q_DECLARE_FLAGS( DiscardFlags, DiscardFlag ) 76 77 77 78 /*! … … 85 86 86 87 /*! 87 Instead of the scales a box is painted around the plot canvas, 88 where the scale ticks are aligned to. 88 Instead of the scales a box is painted around the plot canvas, 89 where the scale ticks are aligned to. 89 90 */ 90 91 FrameWithScales = 0x01 91 92 }; 92 93 93 //! Layout flags 94 typedef QFlags<LayoutFlag> LayoutFlags; 94 Q_DECLARE_FLAGS( LayoutFlags, LayoutFlag ) 95 95 96 explicit QwtPlotRenderer( QObject * = NULL );96 explicit QwtPlotRenderer( QObject* = NULL ); 97 97 virtual ~QwtPlotRenderer(); 98 98 … … 109 109 LayoutFlags layoutFlags() const; 110 110 111 void renderDocument( QwtPlot *, const QString&fileName,112 const QSizeF &sizeMM, int resolution = 85 );111 void renderDocument( QwtPlot*, const QString& fileName, 112 const QSizeF& sizeMM, int resolution = 85 ); 113 113 114 void renderDocument( QwtPlot *,115 const QString &fileName, const QString&format,116 const QSizeF &sizeMM, int resolution = 85 );114 void renderDocument( QwtPlot*, 115 const QString& fileName, const QString& format, 116 const QSizeF& sizeMM, int resolution = 85 ); 117 117 118 118 #ifndef QWT_NO_SVG 119 119 #ifdef QT_SVG_LIB 120 #if QT_VERSION >= 0x040500 121 void renderTo( QwtPlot *, QSvgGenerator & ) const; 122 #endif 120 void renderTo( QwtPlot*, QSvgGenerator& ) const; 123 121 #endif 124 122 #endif 125 123 126 124 #ifndef QT_NO_PRINTER 127 void renderTo( QwtPlot *, QPrinter& ) const;125 void renderTo( QwtPlot*, QPrinter& ) const; 128 126 #endif 129 127 130 void renderTo( QwtPlot *, QPaintDevice& ) const;128 void renderTo( QwtPlot*, QPaintDevice& ) const; 131 129 132 virtual void render( QwtPlot *,133 QPainter *, const QRectF&plotRect ) const;130 virtual void render( QwtPlot*, 131 QPainter*, const QRectF& plotRect ) const; 134 132 135 virtual void renderTitle( const QwtPlot *,136 QPainter *, const QRectF&titleRect ) const;133 virtual void renderTitle( const QwtPlot*, 134 QPainter*, const QRectF& titleRect ) const; 137 135 138 virtual void renderFooter( const QwtPlot *,139 QPainter *, const QRectF&footerRect ) const;136 virtual void renderFooter( const QwtPlot*, 137 QPainter*, const QRectF& footerRect ) const; 140 138 141 virtual void renderScale( const QwtPlot *, QPainter*,142 int axisId, int startDist, int endDist,143 int baseDist, const QRectF &scaleRect ) const;139 virtual void renderScale( const QwtPlot*, QPainter*, 140 QwtAxisId, int startDist, int endDist, 141 int baseDist, const QRectF& scaleRect ) const; 144 142 145 virtual void renderCanvas( const QwtPlot *,146 QPainter *, const QRectF&canvasRect,143 virtual void renderCanvas( const QwtPlot*, 144 QPainter*, const QRectF& canvasRect, 147 145 const QwtScaleMap* maps ) const; 148 146 149 147 virtual void renderLegend( 150 const QwtPlot *, QPainter*, const QRectF&legendRect ) const;148 const QwtPlot*, QPainter*, const QRectF& legendRect ) const; 151 149 152 bool exportTo( QwtPlot *, const QString&documentName,153 const QSizeF &sizeMM = QSizeF( 300, 200 ), int resolution = 85 );150 bool exportTo( QwtPlot*, const QString& documentName, 151 const QSizeF& sizeMM = QSizeF( 300, 200 ), int resolution = 85 ); 154 152 155 private: 156 void buildCanvasMaps( const QwtPlot *,157 const QRectF &, QwtScaleMap maps[] ) const;153 private: 154 void buildCanvasMaps( const QwtPlot*, 155 const QRectF&, QwtScaleMap maps[] ) const; 158 156 159 bool updateCanvasMargins( QwtPlot *,160 const QRectF &, const QwtScaleMap maps[] ) const;157 bool updateCanvasMargins( QwtPlot*, 158 const QRectF&, const QwtScaleMap maps[] ) const; 161 159 162 private: 160 private: 163 161 class PrivateData; 164 PrivateData *d_data;162 PrivateData* m_data; 165 163 }; 166 164 -
trunk/BNC/qwt/qwt_plot_rescaler.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_interval.h" 14 14 #include "qwt_plot_canvas.h" 15 15 16 #include <qevent.h> 16 #include <qalgorithms.h>17 17 18 18 class QwtPlotRescaler::AxisData 19 19 { 20 public: 21 AxisData() :22 aspectRatio( 1.0 ) ,23 expandingDirection( QwtPlotRescaler::ExpandUp ) 20 public: 21 AxisData() 22 : aspectRatio( 1.0 ) 23 , expandingDirection( QwtPlotRescaler::ExpandUp ) 24 24 { 25 25 } … … 33 33 class QwtPlotRescaler::PrivateData 34 34 { 35 public: 36 PrivateData(): 37 referenceAxis( QwtPlot::xBottom ), 38 rescalePolicy( QwtPlotRescaler::Expanding ), 39 isEnabled( false ), 40 inReplot( 0 ) 41 { 42 } 43 44 int referenceAxis; 35 public: 36 PrivateData() 37 : referenceAxis( QwtAxis::XBottom ) 38 , rescalePolicy( QwtPlotRescaler::Expanding ) 39 , isEnabled( false ) 40 , inReplot( 0 ) 41 { 42 } 43 44 QwtPlotRescaler::AxisData* axisData( QwtAxisId axisId ) 45 { 46 if ( !QwtAxis::isValid( axisId ) ) 47 return NULL; 48 49 return &m_axisData[ axisId]; 50 } 51 52 QwtAxisId referenceAxis; 45 53 RescalePolicy rescalePolicy; 46 QwtPlotRescaler::AxisData axisData[QwtPlot::axisCnt];47 54 bool isEnabled; 48 55 49 56 mutable int inReplot; 57 58 private: 59 QwtPlotRescaler::AxisData m_axisData[QwtAxis::AxisPositions]; 50 60 }; 51 61 … … 58 68 59 69 \sa setRescalePolicy(), setReferenceAxis() 60 */ 61 QwtPlotRescaler::QwtPlotRescaler( QWidget *canvas,62 intreferenceAxis, RescalePolicy policy ):63 QObject( canvas ) 64 { 65 d_data = new PrivateData;66 d_data->referenceAxis = referenceAxis;67 d_data->rescalePolicy = policy;70 */ 71 QwtPlotRescaler::QwtPlotRescaler( QWidget* canvas, 72 QwtAxisId referenceAxis, RescalePolicy policy ) 73 : QObject( canvas ) 74 { 75 m_data = new PrivateData; 76 m_data->referenceAxis = referenceAxis; 77 m_data->rescalePolicy = policy; 68 78 69 79 setEnabled( true ); … … 73 83 QwtPlotRescaler::~QwtPlotRescaler() 74 84 { 75 delete d_data;76 } 77 78 /*! 79 \brief En/disable the rescaler 80 81 When enabled is true an event filter is installed for 82 the canvas, otherwise the event filter is removed. 83 84 \param on true or false 85 \sa isEnabled(), eventFilter() 86 */ 85 delete m_data; 86 } 87 88 /*! 89 \brief En/disable the rescaler 90 91 When enabled is true an event filter is installed for 92 the canvas, otherwise the event filter is removed. 93 94 \param on true or false 95 \sa isEnabled(), eventFilter() 96 */ 87 97 void QwtPlotRescaler::setEnabled( bool on ) 88 98 { 89 if ( d_data->isEnabled != on )90 { 91 d_data->isEnabled = on;92 93 QWidget *w = canvas();99 if ( m_data->isEnabled != on ) 100 { 101 m_data->isEnabled = on; 102 103 QWidget* w = canvas(); 94 104 if ( w ) 95 105 { 96 if ( d_data->isEnabled )106 if ( m_data->isEnabled ) 97 107 w->installEventFilter( this ); 98 108 else … … 103 113 104 114 /*! 105 \return true when enabled, false otherwise 106 \sa setEnabled, eventFilter() 107 */ 115 \return true when enabled, false otherwise 116 \sa setEnabled, eventFilter() 117 */ 108 118 bool QwtPlotRescaler::isEnabled() const 109 119 { 110 return d_data->isEnabled;111 } 112 113 /*! 114 Change the rescale policy 115 116 \param policy Rescale policy 117 \sa rescalePolicy() 118 */ 120 return m_data->isEnabled; 121 } 122 123 /*! 124 Change the rescale policy 125 126 \param policy Rescale policy 127 \sa rescalePolicy() 128 */ 119 129 void QwtPlotRescaler::setRescalePolicy( RescalePolicy policy ) 120 130 { 121 d_data->rescalePolicy = policy;122 } 123 124 /*! 125 \return Rescale policy 126 \sa setRescalePolicy() 127 */ 131 m_data->rescalePolicy = policy; 132 } 133 134 /*! 135 \return Rescale policy 136 \sa setRescalePolicy() 137 */ 128 138 QwtPlotRescaler::RescalePolicy QwtPlotRescaler::rescalePolicy() const 129 139 { 130 return d_data->rescalePolicy;131 } 132 133 /*! 134 Set the reference axis ( see RescalePolicy ) 135 136 \param axis Axis index ( QwtPlot::Axis )137 \sa referenceAxis() 138 */ 139 void QwtPlotRescaler::setReferenceAxis( int axis)140 { 141 d_data->referenceAxis = axis;142 } 143 144 /*! 145 \return Reference axis ( see RescalePolicy ) 146 \sa setReferenceAxis() 147 */ 148 intQwtPlotRescaler::referenceAxis() const149 { 150 return d_data->referenceAxis;151 } 152 153 /*! 154 Set the direction in which all axis should be expanded 155 156 \param direction Direction 157 \sa expandingDirection() 158 */ 140 return m_data->rescalePolicy; 141 } 142 143 /*! 144 Set the reference axis ( see RescalePolicy ) 145 146 \param axisId Axis 147 \sa referenceAxis() 148 */ 149 void QwtPlotRescaler::setReferenceAxis( QwtAxisId axisId ) 150 { 151 m_data->referenceAxis = axisId; 152 } 153 154 /*! 155 \return Reference axis ( see RescalePolicy ) 156 \sa setReferenceAxis() 157 */ 158 QwtAxisId QwtPlotRescaler::referenceAxis() const 159 { 160 return m_data->referenceAxis; 161 } 162 163 /*! 164 Set the direction in which all axis should be expanded 165 166 \param direction Direction 167 \sa expandingDirection() 168 */ 159 169 void QwtPlotRescaler::setExpandingDirection( 160 170 ExpandingDirection direction ) 161 171 { 162 for ( int axis = 0; axis < Qwt Plot::axisCnt; axis++ )172 for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ ) 163 173 setExpandingDirection( axis, direction ); 164 174 } 165 175 166 176 /*! 167 Set the direction in which an axis should be expanded 168 169 \param axis Axis index ( see QwtPlot::AxisId )170 \param direction Direction 171 \sa expandingDirection() 172 */ 177 Set the direction in which an axis should be expanded 178 179 \param axisId Axis 180 \param direction Direction 181 \sa expandingDirection() 182 */ 173 183 void QwtPlotRescaler::setExpandingDirection( 174 int axis, ExpandingDirection direction )175 { 176 if ( axis >= 0 && axis < QwtPlot::axisCnt)177 d_data->axisData[axis].expandingDirection = direction;178 } 179 180 /*! 181 \return Direction in which an axis should be expanded 182 183 \param axis Axis index ( see QwtPlot::AxisId )184 \sa setExpandingDirection() 185 */ 184 QwtAxisId axisId, ExpandingDirection direction ) 185 { 186 if ( AxisData* axisData = m_data->axisData( axisId ) ) 187 axisData->expandingDirection = direction; 188 } 189 190 /*! 191 \return Direction in which an axis should be expanded 192 193 \param axisId Axis 194 \sa setExpandingDirection() 195 */ 186 196 QwtPlotRescaler::ExpandingDirection 187 QwtPlotRescaler::expandingDirection( int axis) const188 { 189 if ( axis >= 0 && axis < QwtPlot::axisCnt)190 return d_data->axisData[axis].expandingDirection;197 QwtPlotRescaler::expandingDirection( QwtAxisId axisId ) const 198 { 199 if ( const AxisData* axisData = m_data->axisData( axisId ) ) 200 return axisData->expandingDirection; 191 201 192 202 return ExpandBoth; … … 194 204 195 205 /*! 196 Set the aspect ratio between the scale of the reference axis 197 and the other scales. The default ratio is 1.0 198 199 \param ratio Aspect ratio 200 \sa aspectRatio() 201 */ 206 Set the aspect ratio between the scale of the reference axis 207 and the other scales. The default ratio is 1.0 208 209 \param ratio Aspect ratio 210 \sa aspectRatio() 211 */ 202 212 void QwtPlotRescaler::setAspectRatio( double ratio ) 203 213 { 204 for ( int axis = 0; axis < Qwt Plot::axisCnt; axis++ )214 for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ ) 205 215 setAspectRatio( axis, ratio ); 206 216 } 207 217 208 218 /*! 209 Set the aspect ratio between the scale of the reference axis 210 and another scale. The default ratio is 1.0 211 212 \param axis Axis index ( see QwtPlot::AxisId ) 213 \param ratio Aspect ratio 214 \sa aspectRatio() 215 */ 216 void QwtPlotRescaler::setAspectRatio( int axis, double ratio ) 217 { 218 if ( ratio < 0.0 ) 219 ratio = 0.0; 220 221 if ( axis >= 0 && axis < QwtPlot::axisCnt ) 222 d_data->axisData[axis].aspectRatio = ratio; 223 } 224 225 /*! 226 \return Aspect ratio between an axis and the reference axis. 227 228 \param axis Axis index ( see QwtPlot::AxisId ) 229 \sa setAspectRatio() 230 */ 231 double QwtPlotRescaler::aspectRatio( int axis ) const 232 { 233 if ( axis >= 0 && axis < QwtPlot::axisCnt ) 234 return d_data->axisData[axis].aspectRatio; 219 Set the aspect ratio between the scale of the reference axis 220 and another scale. The default ratio is 1.0 221 222 \param axisId Axis 223 \param ratio Aspect ratio 224 \sa aspectRatio() 225 */ 226 void QwtPlotRescaler::setAspectRatio( QwtAxisId axisId, double ratio ) 227 { 228 if ( AxisData* axisData = m_data->axisData( axisId ) ) 229 { 230 if ( ratio < 0.0 ) 231 ratio = 0.0; 232 233 axisData->aspectRatio = ratio; 234 } 235 } 236 237 /*! 238 \return Aspect ratio between an axis and the reference axis. 239 240 \param axisId Axis 241 \sa setAspectRatio() 242 */ 243 double QwtPlotRescaler::aspectRatio( QwtAxisId axisId ) const 244 { 245 if ( AxisData* axisData = m_data->axisData( axisId ) ) 246 return axisData->aspectRatio; 235 247 236 248 return 0.0; … … 238 250 239 251 /*! 240 Set an interval hint for an axis 241 242 In Fitting mode, the hint is used as minimal interval 243 that always needs to be displayed. 244 245 \param axis Axis, see QwtPlot::Axis246 \param interval Axis 247 \sa intervalHint(), RescalePolicy 248 */ 249 void QwtPlotRescaler::setIntervalHint( int axis,250 const QwtInterval &interval )251 { 252 if ( axis >= 0 && axis < QwtPlot::axisCnt)253 d_data->axisData[axis].intervalHint = interval;254 } 255 256 /*! 257 \param axis Axis, see QwtPlot::Axis258 \return Interval hint 259 \sa setIntervalHint(), RescalePolicy 260 */ 261 QwtInterval QwtPlotRescaler::intervalHint( int axis) const262 { 263 if ( axis >= 0 && axis < QwtPlot::axisCnt)264 return d_data->axisData[axis].intervalHint;252 Set an interval hint for an axis 253 254 In Fitting mode, the hint is used as minimal interval 255 that always needs to be displayed. 256 257 \param axisId Axis 258 \param interval Axis 259 \sa intervalHint(), RescalePolicy 260 */ 261 void QwtPlotRescaler::setIntervalHint( QwtAxisId axisId, 262 const QwtInterval& interval ) 263 { 264 if ( AxisData* axisData = m_data->axisData( axisId ) ) 265 axisData->intervalHint = interval; 266 } 267 268 /*! 269 \param axisId Axis 270 \return Interval hint 271 \sa setIntervalHint(), RescalePolicy 272 */ 273 QwtInterval QwtPlotRescaler::intervalHint( QwtAxisId axisId ) const 274 { 275 if ( AxisData* axisData = m_data->axisData( axisId ) ) 276 return axisData->intervalHint; 265 277 266 278 return QwtInterval(); … … 268 280 269 281 //! \return plot canvas 270 QWidget *QwtPlotRescaler::canvas()271 { 272 return qobject_cast<QWidget *>( parent() );282 QWidget* QwtPlotRescaler::canvas() 283 { 284 return qobject_cast< QWidget* >( parent() ); 273 285 } 274 286 275 287 //! \return plot canvas 276 const QWidget *QwtPlotRescaler::canvas() const277 { 278 return qobject_cast<const QWidget *>( parent() );288 const QWidget* QwtPlotRescaler::canvas() const 289 { 290 return qobject_cast< const QWidget* >( parent() ); 279 291 } 280 292 281 293 //! \return plot widget 282 QwtPlot *QwtPlotRescaler::plot()283 { 284 QWidget *w = canvas();294 QwtPlot* QwtPlotRescaler::plot() 295 { 296 QWidget* w = canvas(); 285 297 if ( w ) 286 298 w = w->parentWidget(); 287 299 288 return qobject_cast<QwtPlot *>( w );300 return qobject_cast< QwtPlot* >( w ); 289 301 } 290 302 291 303 //! \return plot widget 292 const QwtPlot *QwtPlotRescaler::plot() const293 { 294 const QWidget *w = canvas();304 const QwtPlot* QwtPlotRescaler::plot() const 305 { 306 const QWidget* w = canvas(); 295 307 if ( w ) 296 308 w = w->parentWidget(); 297 309 298 return qobject_cast<const QwtPlot *>( w );310 return qobject_cast< const QwtPlot* >( w ); 299 311 } 300 312 301 313 //! Event filter for the plot canvas 302 bool QwtPlotRescaler::eventFilter( QObject *object, QEvent*event )314 bool QwtPlotRescaler::eventFilter( QObject* object, QEvent* event ) 303 315 { 304 316 if ( object && object == canvas() ) … … 308 320 case QEvent::Resize: 309 321 { 310 canvasResizeEvent( static_cast<QResizeEvent *>( event ) );322 canvasResizeEvent( static_cast< QResizeEvent* >( event ) ); 311 323 break; 312 324 } … … 324 336 325 337 /*! 326 Event handler for resize events of the plot canvas 327 328 \param event Resize event 329 \sa rescale() 330 */ 338 Event handler for resize events of the plot canvas 339 340 \param event Resize event 341 \sa rescale() 342 */ 331 343 void QwtPlotRescaler::canvasResizeEvent( QResizeEvent* event ) 332 344 { 333 int left, top, right, bottom; 334 canvas()->getContentsMargins( &left, &top, &right, &bottom ); 335 336 const QSize marginSize( left + right, top + bottom ); 345 const QMargins m = canvas()->contentsMargins(); 346 const QSize marginSize( m.left() + m.right(), m.top() + m.bottom() ); 337 347 338 348 const QSize newSize = event->size() - marginSize; … … 354 364 \param oldSize Previous size of the canvas 355 365 \param newSize New size of the canvas 356 */ 366 */ 357 367 void QwtPlotRescaler::rescale( 358 const QSize &oldSize, const QSize&newSize ) const368 const QSize& oldSize, const QSize& newSize ) const 359 369 { 360 370 if ( newSize.isEmpty() ) 361 371 return; 362 372 363 QwtInterval intervals[QwtPlot::axisCnt]; 364 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 365 intervals[axis] = interval( axis ); 366 367 const int refAxis = referenceAxis(); 373 QwtInterval intervals[QwtAxis::AxisPositions]; 374 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 375 { 376 const QwtAxisId axisId( axisPos ); 377 intervals[axisPos] = interval( axisId ); 378 } 379 380 const QwtAxisId refAxis = referenceAxis(); 368 381 intervals[refAxis] = expandScale( refAxis, oldSize, newSize ); 369 382 370 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 371 { 372 if ( aspectRatio( axis ) > 0.0 && axis != refAxis ) 373 intervals[axis] = syncScale( axis, intervals[refAxis], newSize ); 383 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 384 { 385 const QwtAxisId axisId( axisPos ); 386 if ( aspectRatio( axisId ) > 0.0 && axisId != refAxis ) 387 { 388 intervals[axisPos] = syncScale( 389 axisId, intervals[refAxis], newSize ); 390 } 374 391 } 375 392 … … 378 395 379 396 /*! 380 Calculate the new scale interval of a plot axis 381 382 \param axis Axis index ( see QwtPlot::AxisId )383 \param oldSize Previous size of the canvas 384 \param newSize New size of the canvas 385 386 \return Calculated new interval for the axis 387 */ 388 QwtInterval QwtPlotRescaler::expandScale( int axis,389 const QSize&oldSize, const QSize&newSize ) const390 { 391 const QwtInterval oldInterval = interval( axis ); 397 Calculate the new scale interval of a plot axis 398 399 \param axisId Axis 400 \param oldSize Previous size of the canvas 401 \param newSize New size of the canvas 402 403 \return Calculated new interval for the axis 404 */ 405 QwtInterval QwtPlotRescaler::expandScale( QwtAxisId axisId, 406 const QSize& oldSize, const QSize& newSize ) const 407 { 408 const QwtInterval oldInterval = interval( axisId ); 392 409 393 410 QwtInterval expanded = oldInterval; … … 403 420 { 404 421 double width = oldInterval.width(); 405 if ( orientation( axis ) == Qt::Horizontal ) 422 if ( orientation( axisId ) == Qt::Horizontal ) 406 423 width *= double( newSize.width() ) / oldSize.width(); 407 424 else … … 409 426 410 427 expanded = expandInterval( oldInterval, 411 width, expandingDirection( axis ) ); 428 width, expandingDirection( axisId ) ); 412 429 } 413 430 break; … … 416 433 { 417 434 double dist = 0.0; 418 for ( int ax = 0; ax < QwtPlot::axisCnt; ax++ )435 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 419 436 { 420 const double d = pixelDist( ax, newSize ); 437 const QwtAxisId axisId( axisPos ); 438 const double d = pixelDist( axisId, newSize ); 421 439 if ( d > dist ) 422 440 dist = d; … … 425 443 { 426 444 double width; 427 if ( orientation( axis ) == Qt::Horizontal ) 445 if ( orientation( axisId ) == Qt::Horizontal ) 428 446 width = newSize.width() * dist; 429 447 else 430 448 width = newSize.height() * dist; 431 449 432 expanded = expandInterval( intervalHint( axis ), 433 width, expandingDirection( axis ) ); 450 expanded = expandInterval( intervalHint( axisId ), 451 width, expandingDirection( axisId ) ); 434 452 } 435 453 break; … … 441 459 442 460 /*! 443 Synchronize an axis scale according to the scale of the reference axis 444 445 \param axis Axis index ( see QwtPlot::AxisId )446 \param reference Interval of the reference axis 447 \param size Size of the canvas 448 449 \return New interval for axis 450 */ 451 QwtInterval QwtPlotRescaler::syncScale( int axis,452 const QwtInterval& reference, const QSize &size ) const461 Synchronize an axis scale according to the scale of the reference axis 462 463 \param axisId Axis 464 \param reference Interval of the reference axis 465 \param size Size of the canvas 466 467 \return New interval for axis 468 */ 469 QwtInterval QwtPlotRescaler::syncScale( QwtAxisId axisId, 470 const QwtInterval& reference, const QSize& size ) const 453 471 { 454 472 double dist; … … 458 476 dist = reference.width() / size.height(); 459 477 460 if ( orientation( axis ) == Qt::Horizontal ) 478 if ( orientation( axisId ) == Qt::Horizontal ) 461 479 dist *= size.width(); 462 480 else 463 481 dist *= size.height(); 464 482 465 dist /= aspectRatio( axis ); 483 dist /= aspectRatio( axisId ); 466 484 467 485 QwtInterval intv; 468 486 if ( rescalePolicy() == Fitting ) 469 intv = intervalHint( axis ); 487 intv = intervalHint( axisId ); 470 488 else 471 intv = interval( axis ); 472 473 intv = expandInterval( intv, dist, expandingDirection( axis ) ); 489 intv = interval( axisId ); 490 491 intv = expandInterval( intv, dist, expandingDirection( axisId ) ); 474 492 475 493 return intv; … … 477 495 478 496 /*! 479 \return Orientation of an axis 480 \param axis Axis index ( see QwtPlot::AxisId ) 481 */ 482 Qt::Orientation QwtPlotRescaler::orientation( int axis ) const 483 { 484 if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) 485 return Qt::Vertical; 486 487 return Qt::Horizontal; 488 } 489 490 /*! 491 \param axis Axis index ( see QwtPlot::AxisId ) 492 \return Normalized interval of an axis 493 */ 494 QwtInterval QwtPlotRescaler::interval( int axis ) const 495 { 496 if ( axis < 0 || axis >= QwtPlot::axisCnt ) 497 \return Orientation of an axis 498 \param axisId Axis 499 */ 500 Qt::Orientation QwtPlotRescaler::orientation( QwtAxisId axisId ) const 501 { 502 return QwtAxis::isYAxis( axisId ) ? Qt::Vertical : Qt::Horizontal; 503 } 504 505 /*! 506 \param axisId Axis 507 \return Normalized interval of an axis 508 */ 509 QwtInterval QwtPlotRescaler::interval( QwtAxisId axisId ) const 510 { 511 if ( !plot()->isAxisValid( axisId ) ) 497 512 return QwtInterval(); 498 513 499 return plot()->axisScaleDiv( axis ).interval().normalized(); 500 } 501 502 /*! 503 Expand the interval 504 505 \param interval Interval to be expanded 506 \param width Distance to be added to the interval 507 \param direction Direction of the expand operation 508 509 \return Expanded interval 510 */ 514 return plot()->axisScaleDiv( axisId ).interval().normalized(); 515 } 516 517 /*! 518 Expand the interval 519 520 \param interval Interval to be expanded 521 \param width Distance to be added to the interval 522 \param direction Direction of the expand operation 523 524 \return Expanded interval 525 */ 511 526 QwtInterval QwtPlotRescaler::expandInterval( 512 const QwtInterval &interval, double width,527 const QwtInterval& interval, double width, 513 528 ExpandingDirection direction ) const 514 529 { … … 536 551 } 537 552 538 double QwtPlotRescaler::pixelDist( int axis, const QSize&size ) const539 { 540 const QwtInterval intv = intervalHint( axis ); 553 double QwtPlotRescaler::pixelDist( QwtAxisId axisId, const QSize& size ) const 554 { 555 const QwtInterval intv = intervalHint( axisId ); 541 556 542 557 double dist = 0.0; 543 558 if ( !intv.isNull() ) 544 559 { 545 if ( axis == referenceAxis() ) 560 if ( axisId == referenceAxis() ) 561 { 546 562 dist = intv.width(); 563 } 547 564 else 548 565 { 549 const double r = aspectRatio( axis ); 566 const double r = aspectRatio( axisId ); 550 567 if ( r > 0.0 ) 551 568 dist = intv.width() * r; … … 555 572 if ( dist > 0.0 ) 556 573 { 557 if ( orientation( axis ) == Qt::Horizontal ) 574 if ( orientation( axisId ) == Qt::Horizontal ) 558 575 dist /= size.width(); 559 576 else … … 568 585 569 586 \param intervals Scale intervals 570 */ 587 */ 571 588 void QwtPlotRescaler::updateScales( 572 QwtInterval intervals[Qwt Plot::axisCnt] ) const573 { 574 if ( d_data->inReplot >= 5 )589 QwtInterval intervals[QwtAxis::AxisPositions] ) const 590 { 591 if ( m_data->inReplot >= 5 ) 575 592 { 576 593 return; 577 594 } 578 595 579 QwtPlot *plt = const_cast<QwtPlot*>( plot() );596 QwtPlot* plt = const_cast< QwtPlot* >( plot() ); 580 597 581 598 const bool doReplot = plt->autoReplot(); 582 599 plt->setAutoReplot( false ); 583 600 584 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 585 { 586 if ( axis == referenceAxis() || aspectRatio( axis ) > 0.0 ) 587 { 588 double v1 = intervals[axis].minValue(); 589 double v2 = intervals[axis].maxValue(); 590 591 if ( !plt->axisScaleDiv( axis ).isIncreasing() ) 592 qSwap( v1, v2 ); 593 594 if ( d_data->inReplot >= 1 ) 595 d_data->axisData[axis].scaleDiv = plt->axisScaleDiv( axis ); 596 597 if ( d_data->inReplot >= 2 ) 601 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 602 { 603 { 604 const QwtAxisId axisId( axisPos ); 605 606 if ( axisId == referenceAxis() || aspectRatio( axisId ) > 0.0 ) 598 607 { 599 QList<double> ticks[QwtScaleDiv::NTickTypes]; 600 for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ ) 601 ticks[i] = d_data->axisData[axis].scaleDiv.ticks( i ); 602 603 plt->setAxisScaleDiv( axis, QwtScaleDiv( v1, v2, ticks ) ); 608 double v1 = intervals[axisPos].minValue(); 609 double v2 = intervals[axisPos].maxValue(); 610 611 if ( !plt->axisScaleDiv( axisId ).isIncreasing() ) 612 qSwap( v1, v2 ); 613 614 if ( m_data->inReplot >= 1 ) 615 m_data->axisData( axisId )->scaleDiv = plt->axisScaleDiv( axisId ); 616 617 if ( m_data->inReplot >= 2 ) 618 { 619 QList< double > ticks[QwtScaleDiv::NTickTypes]; 620 for ( int t = 0; t < QwtScaleDiv::NTickTypes; t++ ) 621 ticks[t] = m_data->axisData( axisId )->scaleDiv.ticks( t ); 622 623 plt->setAxisScaleDiv( axisId, QwtScaleDiv( v1, v2, ticks ) ); 624 } 625 else 626 { 627 plt->setAxisScale( axisId, v1, v2 ); 628 } 604 629 } 605 else 606 { 607 plt->setAxisScale( axis, v1, v2 ); 608 } 609 } 610 } 611 612 QwtPlotCanvas *canvas = qobject_cast<QwtPlotCanvas *>( plt->canvas() ); 630 } 631 } 632 633 QwtPlotCanvas* canvas = qobject_cast< QwtPlotCanvas* >( plt->canvas() ); 613 634 614 635 bool immediatePaint = false; … … 621 642 plt->setAutoReplot( doReplot ); 622 643 623 d_data->inReplot++;644 m_data->inReplot++; 624 645 plt->replot(); 625 d_data->inReplot--;646 m_data->inReplot--; 626 647 627 648 if ( canvas && immediatePaint ) … … 630 651 } 631 652 } 653 654 #include "moc_qwt_plot_rescaler.cpp" -
trunk/BNC/qwt/qwt_plot_rescaler.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PLOT_RESCALER_H 11 #define QWT_PLOT_RESCALER_H 111 #define QWT_PLOT_RESCALER_H 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h"15 14 #include "qwt_plot.h" 15 16 16 #include <qobject.h> 17 17 18 18 class QwtPlot; 19 class QwtInterval; 19 20 class QResizeEvent; 20 21 … … 24 25 QwtPlotRescaler auto adjusts the axes of a QwtPlot according 25 26 to fixed aspect ratios. 26 */ 27 */ 27 28 28 class QWT_EXPORT QwtPlotRescaler: public QObject 29 class QWT_EXPORT QwtPlotRescaler : public QObject 29 30 { 30 public: 31 Q_OBJECT 32 33 public: 31 34 /*! 32 The rescale policy defines how to rescale the reference axis and 33 their depending axes. 35 The rescale policy defines how to rescale the reference axis and 36 their depending axes. 34 37 35 \sa ExpandingDirection, setIntervalHint() 36 */ 38 \sa ExpandingDirection, setIntervalHint() 39 */ 37 40 enum RescalePolicy 38 41 { 39 42 /*! 40 The interval of the reference axis remains unchanged, when the 41 geometry of the canvas changes. All other axes 42 will be adjusted according to their aspect ratio. 43 The interval of the reference axis remains unchanged, when the 44 geometry of the canvas changes. All other axes 45 will be adjusted according to their aspect ratio. 43 46 */ 44 47 Fixed, 45 48 46 49 /*! 47 The interval of the reference axis will be shrunk/expanded, 48 when the geometry of the canvas changes. All other axes 49 will be adjusted according to their aspect ratio. 50 The interval of the reference axis will be shrunk/expanded, 51 when the geometry of the canvas changes. All other axes 52 will be adjusted according to their aspect ratio. 50 53 51 The interval, that is represented by one pixel is fixed. 54 The interval, that is represented by one pixel is fixed. 52 55 53 56 */ … … 55 58 56 59 /*! 57 The intervals of the axes are calculated, so that all axes include 58 their interval hint. 60 The intervals of the axes are calculated, so that all axes include 61 their interval hint. 59 62 */ 60 63 Fitting … … 77 80 }; 78 81 79 explicit QwtPlotRescaler( QWidget *canvas,80 intreferenceAxis = QwtPlot::xBottom,82 explicit QwtPlotRescaler( QWidget* canvas, 83 QwtAxisId referenceAxis = QwtAxis::XBottom, 81 84 RescalePolicy = Expanding ); 82 85 … … 90 93 91 94 void setExpandingDirection( ExpandingDirection ); 92 void setExpandingDirection( int axis, ExpandingDirection );93 ExpandingDirection expandingDirection( int axis) const;95 void setExpandingDirection( QwtAxisId, ExpandingDirection ); 96 ExpandingDirection expandingDirection( QwtAxisId ) const; 94 97 95 void setReferenceAxis( int axis);96 intreferenceAxis() const;98 void setReferenceAxis( QwtAxisId ); 99 QwtAxisId referenceAxis() const; 97 100 98 101 void setAspectRatio( double ratio ); 99 void setAspectRatio( int axis, double ratio );100 double aspectRatio( int axis) const;102 void setAspectRatio( QwtAxisId, double ratio ); 103 double aspectRatio( QwtAxisId ) const; 101 104 102 void setIntervalHint( int axis, const QwtInterval& );103 QwtInterval intervalHint( int axis) const;105 void setIntervalHint( QwtAxisId, const QwtInterval& ); 106 QwtInterval intervalHint( QwtAxisId ) const; 104 107 105 QWidget *canvas();106 const QWidget *canvas() const;108 QWidget* canvas(); 109 const QWidget* canvas() const; 107 110 108 QwtPlot *plot();109 const QwtPlot *plot() const;111 QwtPlot* plot(); 112 const QwtPlot* plot() const; 110 113 111 virtual bool eventFilter( QObject *, QEvent* );114 virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE; 112 115 113 116 void rescale() const; 114 117 115 protected: 116 virtual void canvasResizeEvent( QResizeEvent * );118 protected: 119 virtual void canvasResizeEvent( QResizeEvent* ); 117 120 118 virtual void rescale( const QSize &oldSize, const QSize&newSize ) const;121 virtual void rescale( const QSize& oldSize, const QSize& newSize ) const; 119 122 virtual QwtInterval expandScale( 120 int axis, const QSize&oldSize, const QSize&newSize ) const;123 QwtAxisId, const QSize& oldSize, const QSize& newSize ) const; 121 124 122 125 virtual QwtInterval syncScale( 123 int axis, const QwtInterval& reference, 124 const QSize &size ) const; 126 QwtAxisId, const QwtInterval& reference, const QSize& size ) const; 125 127 126 128 virtual void updateScales( 127 QwtInterval intervals[Qwt Plot::axisCnt] ) const;129 QwtInterval intervals[QwtAxis::AxisPositions] ) const; 128 130 129 Qt::Orientation orientation( int axis) const;130 QwtInterval interval( int axis) const;131 QwtInterval expandInterval( const QwtInterval &,131 Qt::Orientation orientation( QwtAxisId ) const; 132 QwtInterval interval( QwtAxisId ) const; 133 QwtInterval expandInterval( const QwtInterval&, 132 134 double width, ExpandingDirection ) const; 133 135 134 private: 135 double pixelDist( int axis, const QSize& ) const;136 private: 137 double pixelDist( QwtAxisId, const QSize& ) const; 136 138 137 139 class AxisData; 138 140 class PrivateData; 139 PrivateData *d_data;141 PrivateData* m_data; 140 142 }; 141 143 -
trunk/BNC/qwt/qwt_plot_scaleitem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_scale_map.h" 13 13 #include "qwt_interval.h" 14 #include "qwt_text.h" 15 14 16 #include <qpalette.h> 15 17 #include <qpainter.h> … … 17 19 class QwtPlotScaleItem::PrivateData 18 20 { 19 public: 20 PrivateData() :21 position( 0.0 ) ,22 borderDistance( -1 ) ,23 scaleDivFromAxis( true ) ,24 scaleDraw( new QwtScaleDraw() ) 21 public: 22 PrivateData() 23 : position( 0.0 ) 24 , borderDistance( -1 ) 25 , scaleDivFromAxis( true ) 26 , scaleDraw( new QwtScaleDraw() ) 25 27 { 26 28 } … … 31 33 } 32 34 33 QwtInterval scaleInterval( const QRectF &,34 const QwtScaleMap &, const QwtScaleMap& ) const;35 QwtInterval scaleInterval( const QRectF&, 36 const QwtScaleMap&, const QwtScaleMap& ) const; 35 37 36 38 QPalette palette; … … 39 41 int borderDistance; 40 42 bool scaleDivFromAxis; 41 QwtScaleDraw *scaleDraw;43 QwtScaleDraw* scaleDraw; 42 44 }; 43 45 44 QwtInterval QwtPlotScaleItem::PrivateData::scaleInterval( const QRectF &canvasRect,45 const QwtScaleMap &xMap, const QwtScaleMap&yMap ) const46 QwtInterval QwtPlotScaleItem::PrivateData::scaleInterval( const QRectF& canvasRect, 47 const QwtScaleMap& xMap, const QwtScaleMap& yMap ) const 46 48 { 47 49 QwtInterval interval; … … 70 72 71 73 \sa setPosition(), setAlignment() 72 */ 74 */ 73 75 QwtPlotScaleItem::QwtPlotScaleItem( 74 QwtScaleDraw::Alignment alignment, const double pos ) :75 QwtPlotItem( QwtText( "Scale" ) ) 76 { 77 d_data = new PrivateData;78 d_data->position = pos;79 d_data->scaleDraw->setAlignment( alignment );76 QwtScaleDraw::Alignment alignment, const double pos ) 77 : QwtPlotItem( QwtText( "Scale" ) ) 78 { 79 m_data = new PrivateData; 80 m_data->position = pos; 81 m_data->scaleDraw->setAlignment( alignment ); 80 82 81 83 setItemInterest( QwtPlotItem::ScaleInterest, true ); … … 86 88 QwtPlotScaleItem::~QwtPlotScaleItem() 87 89 { 88 delete d_data;90 delete m_data; 89 91 } 90 92 … … 103 105 \param scaleDiv Scale division 104 106 \sa scaleDiv(), setScaleDivFromAxis(), isScaleDivFromAxis() 105 */ 107 */ 106 108 void QwtPlotScaleItem::setScaleDiv( const QwtScaleDiv& scaleDiv ) 107 109 { 108 d_data->scaleDivFromAxis = false;109 d_data->scaleDraw->setScaleDiv( scaleDiv );110 m_data->scaleDivFromAxis = false; 111 m_data->scaleDraw->setScaleDiv( scaleDiv ); 110 112 } 111 113 … … 113 115 const QwtScaleDiv& QwtPlotScaleItem::scaleDiv() const 114 116 { 115 return d_data->scaleDraw->scaleDiv();117 return m_data->scaleDraw->scaleDiv(); 116 118 } 117 119 … … 122 124 \param on true/false 123 125 \sa isScaleDivFromAxis() 124 */ 126 */ 125 127 void QwtPlotScaleItem::setScaleDivFromAxis( bool on ) 126 128 { 127 if ( on != d_data->scaleDivFromAxis )128 { 129 d_data->scaleDivFromAxis = on;129 if ( on != m_data->scaleDivFromAxis ) 130 { 131 m_data->scaleDivFromAxis = on; 130 132 if ( on ) 131 133 { 132 const QwtPlot *plt = plot();134 const QwtPlot* plt = plot(); 133 135 if ( plt ) 134 136 { … … 145 147 the corresponding axis is enabled. 146 148 \sa setScaleDiv(), setScaleDivFromAxis() 147 */ 149 */ 148 150 bool QwtPlotScaleItem::isScaleDivFromAxis() const 149 151 { 150 return d_data->scaleDivFromAxis;152 return m_data->scaleDivFromAxis; 151 153 } 152 154 … … 154 156 Set the palette 155 157 \sa QwtAbstractScaleDraw::draw(), palette() 156 */ 157 void QwtPlotScaleItem::setPalette( const QPalette &palette )158 { 159 if ( palette != d_data->palette )160 { 161 d_data->palette = palette;158 */ 159 void QwtPlotScaleItem::setPalette( const QPalette& palette ) 160 { 161 if ( palette != m_data->palette ) 162 { 163 m_data->palette = palette; 162 164 163 165 legendChanged(); … … 169 171 \return palette 170 172 \sa setPalette() 171 */ 173 */ 172 174 QPalette QwtPlotScaleItem::palette() const 173 175 { 174 return d_data->palette;176 return m_data->palette; 175 177 } 176 178 … … 178 180 Change the tick label font 179 181 \sa font() 180 */ 181 void QwtPlotScaleItem::setFont( const QFont &font )182 { 183 if ( font != d_data->font )184 { 185 d_data->font = font;182 */ 183 void QwtPlotScaleItem::setFont( const QFont& font ) 184 { 185 if ( font != m_data->font ) 186 { 187 m_data->font = font; 186 188 itemChanged(); 187 189 } … … 191 193 \return tick label font 192 194 \sa setFont() 193 */ 195 */ 194 196 QFont QwtPlotScaleItem::font() const 195 197 { 196 return d_data->font;197 } 198 199 /*! 200 \brief Set a scale draw 201 202 \param scaleDraw object responsible for drawing scales. 203 204 The main use case for replacing the default QwtScaleDraw is 205 to overload QwtAbstractScaleDraw::label, to replace or swallow 206 tick labels. 207 208 \sa scaleDraw() 209 */ 210 void QwtPlotScaleItem::setScaleDraw( QwtScaleDraw *scaleDraw )198 return m_data->font; 199 } 200 201 /*! 202 \brief Set a scale draw 203 204 \param scaleDraw object responsible for drawing scales. 205 206 The main use case for replacing the default QwtScaleDraw is 207 to overload QwtAbstractScaleDraw::label, to replace or swallow 208 tick labels. 209 210 \sa scaleDraw() 211 */ 212 void QwtPlotScaleItem::setScaleDraw( QwtScaleDraw* scaleDraw ) 211 213 { 212 214 if ( scaleDraw == NULL ) 213 215 return; 214 216 215 if ( scaleDraw != d_data->scaleDraw )216 delete d_data->scaleDraw;217 218 d_data->scaleDraw = scaleDraw;219 220 const QwtPlot *plt = plot();217 if ( scaleDraw != m_data->scaleDraw ) 218 delete m_data->scaleDraw; 219 220 m_data->scaleDraw = scaleDraw; 221 222 const QwtPlot* plt = plot(); 221 223 if ( plt ) 222 224 { … … 231 233 \return Scale draw 232 234 \sa setScaleDraw() 233 */ 234 const QwtScaleDraw *QwtPlotScaleItem::scaleDraw() const235 { 236 return d_data->scaleDraw;235 */ 236 const QwtScaleDraw* QwtPlotScaleItem::scaleDraw() const 237 { 238 return m_data->scaleDraw; 237 239 } 238 240 … … 240 242 \return Scale draw 241 243 \sa setScaleDraw() 242 */ 243 QwtScaleDraw *QwtPlotScaleItem::scaleDraw()244 { 245 return d_data->scaleDraw;244 */ 245 QwtScaleDraw* QwtPlotScaleItem::scaleDraw() 246 { 247 return m_data->scaleDraw; 246 248 } 247 249 … … 256 258 \param pos New position 257 259 \sa position(), setAlignment() 258 */ 260 */ 259 261 void QwtPlotScaleItem::setPosition( double pos ) 260 262 { 261 if ( d_data->position != pos )262 { 263 d_data->position = pos;264 d_data->borderDistance = -1;263 if ( m_data->position != pos ) 264 { 265 m_data->position = pos; 266 m_data->borderDistance = -1; 265 267 itemChanged(); 266 268 } … … 270 272 \return Position of the scale 271 273 \sa setPosition(), setAlignment() 272 */ 274 */ 273 275 double QwtPlotScaleItem::position() const 274 276 { 275 return d_data->position;277 return m_data->position; 276 278 } 277 279 … … 291 293 292 294 \sa setPosition(), borderDistance() 293 */ 295 */ 294 296 void QwtPlotScaleItem::setBorderDistance( int distance ) 295 297 { … … 297 299 distance = -1; 298 300 299 if ( distance != d_data->borderDistance )300 { 301 d_data->borderDistance = distance;301 if ( distance != m_data->borderDistance ) 302 { 303 m_data->borderDistance = distance; 302 304 itemChanged(); 303 305 } … … 307 309 \return Distance from a canvas border 308 310 \sa setBorderDistance(), setPosition() 309 */ 311 */ 310 312 int QwtPlotScaleItem::borderDistance() const 311 313 { 312 return d_data->borderDistance;314 return m_data->borderDistance; 313 315 } 314 316 … … 328 330 329 331 \sa scaleDraw(), QwtScaleDraw::alignment(), setPosition() 330 */ 332 */ 331 333 void QwtPlotScaleItem::setAlignment( QwtScaleDraw::Alignment alignment ) 332 334 { 333 QwtScaleDraw *sd = d_data->scaleDraw;335 QwtScaleDraw* sd = m_data->scaleDraw; 334 336 if ( sd->alignment() != alignment ) 335 337 { … … 340 342 341 343 /*! 342 \brief Draw the scale 343 */ 344 void QwtPlotScaleItem::draw( QPainter *painter,345 const QwtScaleMap &xMap, const QwtScaleMap&yMap,346 const QRectF &canvasRect ) const347 { 348 QwtScaleDraw *sd = d_data->scaleDraw;349 350 if ( d_data->scaleDivFromAxis )344 \brief Draw the scale 345 */ 346 void QwtPlotScaleItem::draw( QPainter* painter, 347 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 348 const QRectF& canvasRect ) const 349 { 350 QwtScaleDraw* sd = m_data->scaleDraw; 351 352 if ( m_data->scaleDivFromAxis ) 351 353 { 352 354 const QwtInterval interval = 353 d_data->scaleInterval( canvasRect, xMap, yMap );355 m_data->scaleInterval( canvasRect, xMap, yMap ); 354 356 355 357 if ( interval != sd->scaleDiv().interval() ) … … 368 370 { 369 371 double y; 370 if ( d_data->borderDistance >= 0 )372 if ( m_data->borderDistance >= 0 ) 371 373 { 372 374 if ( sd->alignment() == QwtScaleDraw::BottomScale ) 373 y = canvasRect.top() + d_data->borderDistance;375 y = canvasRect.top() + m_data->borderDistance; 374 376 else 375 377 { 376 y = canvasRect.bottom() - d_data->borderDistance;378 y = canvasRect.bottom() - m_data->borderDistance; 377 379 } 378 380 … … 380 382 else 381 383 { 382 y = yMap.transform( d_data->position );384 y = yMap.transform( m_data->position ); 383 385 } 384 386 … … 389 391 sd->setLength( canvasRect.width() - 1 ); 390 392 391 QwtTransform *transform = NULL;393 QwtTransform* transform = NULL; 392 394 if ( xMap.transformation() ) 393 395 transform = xMap.transformation()->copy(); … … 398 400 { 399 401 double x; 400 if ( d_data->borderDistance >= 0 )402 if ( m_data->borderDistance >= 0 ) 401 403 { 402 404 if ( sd->alignment() == QwtScaleDraw::RightScale ) 403 x = canvasRect.left() + d_data->borderDistance;405 x = canvasRect.left() + m_data->borderDistance; 404 406 else 405 407 { 406 x = canvasRect.right() - d_data->borderDistance;408 x = canvasRect.right() - m_data->borderDistance; 407 409 } 408 410 } 409 411 else 410 412 { 411 x = xMap.transform( d_data->position );413 x = xMap.transform( m_data->position ); 412 414 } 413 415 if ( x < canvasRect.left() || x > canvasRect.right() ) … … 417 419 sd->setLength( canvasRect.height() - 1 ); 418 420 419 QwtTransform *transform = NULL;421 QwtTransform* transform = NULL; 420 422 if ( yMap.transformation() ) 421 423 transform = yMap.transformation()->copy(); … … 424 426 } 425 427 426 painter->setFont( d_data->font );427 428 sd->draw( painter, d_data->palette );428 painter->setFont( m_data->font ); 429 430 sd->draw( painter, m_data->palette ); 429 431 } 430 432 … … 439 441 440 442 \sa QwtPlot::updateAxes() 441 */ 443 */ 442 444 443 445 void QwtPlotScaleItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv, 444 446 const QwtScaleDiv& yScaleDiv ) 445 447 { 446 QwtScaleDraw *scaleDraw =d_data->scaleDraw;447 448 if ( d_data->scaleDivFromAxis && scaleDraw )449 { 450 const QwtScaleDiv &scaleDiv =448 QwtScaleDraw* scaleDraw = m_data->scaleDraw; 449 450 if ( m_data->scaleDivFromAxis && scaleDraw ) 451 { 452 const QwtScaleDiv& scaleDiv = 451 453 scaleDraw->orientation() == Qt::Horizontal ? xScaleDiv : yScaleDiv; 452 454 453 const QwtPlot *plt = plot();455 const QwtPlot* plt = plot(); 454 456 if ( plt != NULL ) 455 457 { 456 458 const QRectF canvasRect = plt->canvas()->contentsRect(); 457 459 458 const QwtInterval interval = d_data->scaleInterval(460 const QwtInterval interval = m_data->scaleInterval( 459 461 canvasRect, plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) ); 460 462 -
trunk/BNC/qwt/qwt_plot_scaleitem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 18 18 19 19 /*! 20 \brief A class which draws a scale inside the plot canvas 20 \brief A class which draws a scale inside the plot canvas 21 21 22 QwtPlotScaleItem can be used to draw an axis inside the plot canvas. 23 It might by synchronized to one of the axis of the plot, but can 24 also display its own ticks and labels. 22 QwtPlotScaleItem can be used to draw an axis inside the plot canvas. 23 It might by synchronized to one of the axis of the plot, but can 24 also display its own ticks and labels. 25 25 26 It is allowed to synchronize the scale item with a disabled axis. 27 In plots with vertical and horizontal scale items, it might be 28 necessary to remove ticks at the intersections, by overloading 29 updateScaleDiv(). 26 It is allowed to synchronize the scale item with a disabled axis. 27 In plots with vertical and horizontal scale items, it might be 28 necessary to remove ticks at the intersections, by overloading 29 updateScaleDiv(). 30 30 31 The scale might be at a specific position (f.e 0.0) or it might be 32 aligned to a canvas border. 31 The scale might be at a specific position (f.e 0.0) or it might be 32 aligned to a canvas border. 33 33 34 \par Example 34 \par Example 35 35 The following example shows how to replace the left axis, by a scale item 36 36 at the x position 0.0. 37 37 \code 38 38 QwtPlotScaleItem *scaleItem = new QwtPlotScaleItem( QwtScaleDraw::RightScale, 0.0 ); 39 scaleItem->setFont( plot->axisWidget( Qwt Plot::yLeft )->font() );39 scaleItem->setFont( plot->axisWidget( QwtAxis::YLeft )->font() ); 40 40 scaleItem->attach(plot); 41 41 42 plot-> enableAxis( QwtPlot::yLeft, false );42 plot->setAxisVisible( QwtAxis::YLeft, false ); 43 43 \endcode 44 \endpar 45 */ 44 */ 46 45 47 class QWT_EXPORT QwtPlotScaleItem: public QwtPlotItem 46 class QWT_EXPORT QwtPlotScaleItem : public QwtPlotItem 48 47 { 49 public: 48 public: 50 49 explicit QwtPlotScaleItem( 51 50 QwtScaleDraw::Alignment = QwtScaleDraw::BottomScale, … … 54 53 virtual ~QwtPlotScaleItem(); 55 54 56 virtual int rtti() const; 55 virtual int rtti() const QWT_OVERRIDE; 57 56 58 57 void setScaleDiv( const QwtScaleDiv& ); … … 62 61 bool isScaleDivFromAxis() const; 63 62 64 void setPalette( const QPalette & );63 void setPalette( const QPalette& ); 65 64 QPalette palette() const; 66 65 … … 68 67 QFont font() const; 69 68 70 void setScaleDraw( QwtScaleDraw * );69 void setScaleDraw( QwtScaleDraw* ); 71 70 72 const QwtScaleDraw *scaleDraw() const;73 QwtScaleDraw *scaleDraw();71 const QwtScaleDraw* scaleDraw() const; 72 QwtScaleDraw* scaleDraw(); 74 73 75 74 void setPosition( double pos ); … … 81 80 void setAlignment( QwtScaleDraw::Alignment ); 82 81 83 virtual void draw( QPainter *,84 const QwtScaleMap &xMap, const QwtScaleMap&yMap,85 const QRectF &canvasRect ) const;82 virtual void draw( QPainter*, 83 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 84 const QRectF& canvasRect ) const QWT_OVERRIDE; 86 85 87 virtual void updateScaleDiv( const QwtScaleDiv &, const QwtScaleDiv & ); 86 virtual void updateScaleDiv( 87 const QwtScaleDiv&, const QwtScaleDiv& ) QWT_OVERRIDE; 88 88 89 private: 89 private: 90 90 class PrivateData; 91 PrivateData *d_data;91 PrivateData* m_data; 92 92 }; 93 93 -
trunk/BNC/qwt/qwt_plot_seriesitem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot_seriesitem.h" 11 #include "qwt_scale_div.h" 12 #include "qwt_text.h" 11 13 12 14 class QwtPlotSeriesItem::PrivateData 13 15 { 14 public: 15 PrivateData() :16 orientation( Qt::Vertical ) 16 public: 17 PrivateData() 18 : orientation( Qt::Vertical ) 17 19 { 18 20 } … … 22 24 23 25 /*! 24 Constructor 25 \param title Title of the curve 26 */ 27 QwtPlotSeriesItem::QwtPlotSeriesItem( const QwtText &title ):28 QwtPlotItem( title ) 26 Constructor 27 \param title Title of the curve 28 */ 29 QwtPlotSeriesItem::QwtPlotSeriesItem( const QwtText& title ) 30 : QwtPlotItem( title ) 29 31 { 30 d_data = new PrivateData();32 m_data = new PrivateData(); 31 33 setItemInterest( QwtPlotItem::ScaleInterest, true ); 32 34 } 33 35 34 36 /*! 35 Constructor 36 \param title Title of the curve 37 */ 38 QwtPlotSeriesItem::QwtPlotSeriesItem( const QString &title ):39 QwtPlotItem( QwtText( title ) ) 37 Constructor 38 \param title Title of the curve 39 */ 40 QwtPlotSeriesItem::QwtPlotSeriesItem( const QString& title ) 41 : QwtPlotItem( QwtText( title ) ) 40 42 { 41 d_data = new PrivateData();43 m_data = new PrivateData(); 42 44 setItemInterest( QwtPlotItem::ScaleInterest, true ); 43 45 } … … 46 48 QwtPlotSeriesItem::~QwtPlotSeriesItem() 47 49 { 48 delete d_data;50 delete m_data; 49 51 } 50 52 51 53 /*! 52 Set the orientation of the item. 54 Set the orientation of the item. 53 55 54 The orientation() might be used in specific way by a plot item. 55 F.e. a QwtPlotCurve uses it to identify how to display the curve 56 int QwtPlotCurve::Steps or QwtPlotCurve::Sticks style. 56 The orientation() might be used in specific way by a plot item. 57 F.e. a QwtPlotCurve uses it to identify how to display the curve 58 int QwtPlotCurve::Steps or QwtPlotCurve::Sticks style. 57 59 58 \sa orientation() 59 */ 60 \sa orientation() 61 */ 60 62 void QwtPlotSeriesItem::setOrientation( Qt::Orientation orientation ) 61 63 { 62 if ( d_data->orientation != orientation )64 if ( m_data->orientation != orientation ) 63 65 { 64 d_data->orientation = orientation;66 m_data->orientation = orientation; 65 67 66 68 legendChanged(); … … 70 72 71 73 /*! 72 \return Orientation of the plot item 73 \sa setOrientation() 74 */ 74 \return Orientation of the plot item 75 \sa setOrientation() 76 */ 75 77 Qt::Orientation QwtPlotSeriesItem::orientation() const 76 78 { 77 return d_data->orientation;79 return m_data->orientation; 78 80 } 79 81 80 82 /*! 81 \brief Draw the complete series 83 \brief Draw the complete series 82 84 83 \param painter Painter 84 \param xMap Maps x-values into pixel coordinates. 85 \param yMap Maps y-values into pixel coordinates. 86 \param canvasRect Contents rectangle of the canvas 87 */ 88 void QwtPlotSeriesItem::draw( QPainter *painter,89 const QwtScaleMap&xMap, const QwtScaleMap&yMap,90 const QRectF&canvasRect ) const85 \param painter Painter 86 \param xMap Maps x-values into pixel coordinates. 87 \param yMap Maps y-values into pixel coordinates. 88 \param canvasRect Contents rectangle of the canvas 89 */ 90 void QwtPlotSeriesItem::draw( QPainter* painter, 91 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 92 const QRectF& canvasRect ) const 91 93 { 92 94 drawSeries( painter, xMap, yMap, canvasRect, 0, -1 ); … … 99 101 100 102 void QwtPlotSeriesItem::updateScaleDiv( 101 const QwtScaleDiv &xScaleDiv, const QwtScaleDiv&yScaleDiv )103 const QwtScaleDiv& xScaleDiv, const QwtScaleDiv& yScaleDiv ) 102 104 { 103 105 const QRectF rect = QRectF( -
trunk/BNC/qwt/qwt_plot_seriesitem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include "qwt_scale_div.h"16 #include "qwt_series_data.h"17 15 #include "qwt_series_store.h" 18 16 17 #include <qstring.h> 18 19 class QwtScaleDiv; 20 19 21 /*! 20 \brief Base class for plot items representing a series of samples 21 */ 22 class QWT_EXPORT QwtPlotSeriesItem: public QwtPlotItem, 22 \brief Base class for plot items representing a series of samples 23 */ 24 class QWT_EXPORT QwtPlotSeriesItem : public QwtPlotItem, 23 25 public virtual QwtAbstractSeriesStore 24 26 { 25 public: 26 explicit QwtPlotSeriesItem( const QString &title = QString() );27 explicit QwtPlotSeriesItem( const QwtText &title );27 public: 28 explicit QwtPlotSeriesItem( const QString& title = QString() ); 29 explicit QwtPlotSeriesItem( const QwtText& title ); 28 30 29 31 virtual ~QwtPlotSeriesItem(); … … 32 34 Qt::Orientation orientation() const; 33 35 34 virtual void draw( QPainter *,35 const QwtScaleMap &xMap, const QwtScaleMap&yMap,36 const QRectF &) const;36 virtual void draw( QPainter*, 37 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 38 const QRectF& canvasRect ) const QWT_OVERRIDE; 37 39 38 40 /*! 39 Draw a subset of the samples 41 Draw a subset of the samples 40 42 41 \param painter Painter 42 \param xMap Maps x-values into pixel coordinates. 43 \param yMap Maps y-values into pixel coordinates. 44 \param canvasRect Contents rectangle of the canvas 45 \param from Index of the first point to be painted 46 \param to Index of the last point to be painted. If to < 0 the 43 \param painter Painter 44 \param xMap Maps x-values into pixel coordinates. 45 \param yMap Maps y-values into pixel coordinates. 46 \param canvasRect Contents rectangle of the canvas 47 \param from Index of the first point to be painted 48 \param to Index of the last point to be painted. If to < 0 the 47 49 curve will be painted to its last point. 48 */ 49 virtual void drawSeries( QPainter *painter,50 const QwtScaleMap &xMap, const QwtScaleMap&yMap,51 const QRectF &canvasRect, int from, int to ) const = 0;50 */ 51 virtual void drawSeries( QPainter* painter, 52 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 53 const QRectF& canvasRect, int from, int to ) const = 0; 52 54 53 virtual QRectF boundingRect() const; 55 virtual QRectF boundingRect() const QWT_OVERRIDE; 54 56 55 57 virtual void updateScaleDiv( 56 const QwtScaleDiv &, const QwtScaleDiv& );58 const QwtScaleDiv&, const QwtScaleDiv& ) QWT_OVERRIDE; 57 59 58 protected: 59 virtual void dataChanged(); 60 protected: 61 virtual void dataChanged() QWT_OVERRIDE; 60 62 61 private: 63 private: 62 64 class PrivateData; 63 PrivateData *d_data;65 PrivateData* m_data; 64 66 }; 65 67 -
trunk/BNC/qwt/qwt_plot_shapeitem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_shapeitem.h" 11 11 #include "qwt_scale_map.h" 12 #include "qwt_text.h" 13 #include "qwt_graphic.h" 12 14 #include "qwt_painter.h" 13 #include "qwt_curve_fitter.h" 15 #include "qwt_weeding_curve_fitter.h" 14 16 #include "qwt_clipper.h" 15 16 static QPainterPath qwtTransformPath( const QwtScaleMap &xMap, 17 const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign ) 17 #include "qwt_math.h" 18 19 #include <qpainter.h> 20 #include <qpainterpath.h> 21 22 static QPainterPath qwtTransformPath( const QwtScaleMap& xMap, 23 const QwtScaleMap& yMap, const QPainterPath& path, bool doAlign ) 18 24 { 19 25 QPainterPath shape; … … 22 28 for ( int i = 0; i < path.elementCount(); i++ ) 23 29 { 24 const QPainterPath::Element &element = path.elementAt( i );30 const QPainterPath::Element element = path.elementAt( i ); 25 31 26 32 double x = xMap.transform( element.x ); … … 53 59 case QPainterPath::CurveToElement: 54 60 { 55 const QPainterPath::Element &element1 = path.elementAt( ++i );61 const QPainterPath::Element element1 = path.elementAt( ++i ); 56 62 const double x1 = xMap.transform( element1.x ); 57 63 const double y1 = yMap.transform( element1.y ); 58 64 59 const QPainterPath::Element &element2 = path.elementAt( ++i );65 const QPainterPath::Element element2 = path.elementAt( ++i ); 60 66 const double x2 = xMap.transform( element2.x ); 61 67 const double y2 = yMap.transform( element2.y ); … … 77 83 class QwtPlotShapeItem::PrivateData 78 84 { 79 public: 80 PrivateData() :81 legendMode( QwtPlotShapeItem::LegendColor ) ,82 renderTolerance( 0.0 ) 85 public: 86 PrivateData() 87 : legendMode( QwtPlotShapeItem::LegendColor ) 88 , renderTolerance( 0.0 ) 83 89 { 84 90 } … … 103 109 104 110 \param title Title 105 */ 106 QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ) :107 QwtPlotItem( QwtText( title ) ) 111 */ 112 QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ) 113 : QwtPlotItem( QwtText( title ) ) 108 114 { 109 115 init(); … … 118 124 119 125 \param title Title 120 */ 121 QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ) :122 QwtPlotItem( title ) 126 */ 127 QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ) 128 : QwtPlotItem( title ) 123 129 { 124 130 init(); … … 128 134 QwtPlotShapeItem::~QwtPlotShapeItem() 129 135 { 130 delete d_data;136 delete m_data; 131 137 } 132 138 133 139 void QwtPlotShapeItem::init() 134 140 { 135 d_data = new PrivateData();136 d_data->boundingRect = QwtPlotItem::boundingRect();141 m_data = new PrivateData(); 142 m_data->boundingRect = QwtPlotItem::boundingRect(); 137 143 138 144 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 149 155 150 156 /*! 151 Specify an attribute how to draw the shape 152 153 \param attribute Paint attribute 154 \param on On/Off 155 \sa testPaintAttribute() 156 */ 157 Specify an attribute how to draw the shape 158 159 \param attribute Paint attribute 160 \param on On/Off 161 \sa testPaintAttribute() 162 */ 157 163 void QwtPlotShapeItem::setPaintAttribute( PaintAttribute attribute, bool on ) 158 164 { 159 165 if ( on ) 160 d_data->paintAttributes |= attribute;166 m_data->paintAttributes |= attribute; 161 167 else 162 d_data->paintAttributes &= ~attribute;163 } 164 165 /*! 166 \return True, when attribute is enabled 167 \sa setPaintAttribute() 168 */ 168 m_data->paintAttributes &= ~attribute; 169 } 170 171 /*! 172 \return True, when attribute is enabled 173 \sa setPaintAttribute() 174 */ 169 175 bool QwtPlotShapeItem::testPaintAttribute( PaintAttribute attribute ) const 170 176 { 171 return ( d_data->paintAttributes & attribute );172 } 173 174 /*! 175 Set the mode how to represent the item on the legend 176 177 \param mode Mode 178 \sa legendMode() 177 return ( m_data->paintAttributes & attribute ); 178 } 179 180 /*! 181 Set the mode how to represent the item on the legend 182 183 \param mode Mode 184 \sa legendMode() 179 185 */ 180 186 void QwtPlotShapeItem::setLegendMode( LegendMode mode ) 181 187 { 182 if ( mode != d_data->legendMode )183 { 184 d_data->legendMode = mode;188 if ( mode != m_data->legendMode ) 189 { 190 m_data->legendMode = mode; 185 191 legendChanged(); 186 192 } … … 188 194 189 195 /*! 190 \return Mode how to represent the item on the legend 191 \sa legendMode() 196 \return Mode how to represent the item on the legend 197 \sa legendMode() 192 198 */ 193 199 QwtPlotShapeItem::LegendMode QwtPlotShapeItem::legendMode() const 194 200 { 195 return d_data->legendMode;201 return m_data->legendMode; 196 202 } 197 203 … … 199 205 QRectF QwtPlotShapeItem::boundingRect() const 200 206 { 201 return d_data->boundingRect;202 } 203 204 /*! 205 \brief Set a path built from a rectangle 206 207 \param rect Rectangle 208 \sa setShape(), setPolygon(), shape() 209 */ 210 void QwtPlotShapeItem::setRect( const QRectF &rect )207 return m_data->boundingRect; 208 } 209 210 /*! 211 \brief Set a path built from a rectangle 212 213 \param rect Rectangle 214 \sa setShape(), setPolygon(), shape() 215 */ 216 void QwtPlotShapeItem::setRect( const QRectF& rect ) 211 217 { 212 218 QPainterPath path; … … 217 223 218 224 /*! 219 \brief Set a path built from a polygon 220 221 \param polygon Polygon 222 \sa setShape(), setRect(), shape() 223 */ 224 void QwtPlotShapeItem::setPolygon( const QPolygonF &polygon )225 \brief Set a path built from a polygon 226 227 \param polygon Polygon 228 \sa setShape(), setRect(), shape() 229 */ 230 void QwtPlotShapeItem::setPolygon( const QPolygonF& polygon ) 225 231 { 226 232 QPainterPath shape; … … 231 237 232 238 /*! 233 \brief Set the shape to be displayed 234 235 \param shape Shape 236 \sa setShape(), shape() 237 */ 238 void QwtPlotShapeItem::setShape( const QPainterPath &shape )239 { 240 if ( shape != d_data->shape )241 { 242 d_data->shape = shape;239 \brief Set the shape to be displayed 240 241 \param shape Shape 242 \sa setShape(), shape() 243 */ 244 void QwtPlotShapeItem::setShape( const QPainterPath& shape ) 245 { 246 if ( shape != m_data->shape ) 247 { 248 m_data->shape = shape; 243 249 if ( shape.isEmpty() ) 244 250 { 245 d_data->boundingRect = QwtPlotItem::boundingRect();251 m_data->boundingRect = QwtPlotItem::boundingRect(); 246 252 } 247 253 else 248 254 { 249 d_data->boundingRect = shape.boundingRect();255 m_data->boundingRect = shape.boundingRect(); 250 256 } 251 257 … … 255 261 256 262 /*! 257 \return Shape to be displayed 258 \sa setShape() 263 \return Shape to be displayed 264 \sa setShape() 259 265 */ 260 266 QPainterPath QwtPlotShapeItem::shape() const 261 267 { 262 return d_data->shape;263 } 264 265 /*! 266 Build and assign a pen 267 268 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 269 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 270 to hide this incompatibility. 271 272 \param color Pen color 273 \param width Pen width 274 \param style Pen style 275 276 \sa pen(), brush() 277 */ 278 void QwtPlotShapeItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )268 return m_data->shape; 269 } 270 271 /*! 272 Build and assign a pen 273 274 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 275 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 276 to hide this incompatibility. 277 278 \param color Pen color 279 \param width Pen width 280 \param style Pen style 281 282 \sa pen(), brush() 283 */ 284 void QwtPlotShapeItem::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 279 285 { 280 286 setPen( QPen( color, width, style ) ); … … 282 288 283 289 /*! 284 \brief Assign a pen 285 286 The pen is used to draw the outline of the shape 287 288 \param pen Pen 289 \sa pen(), brush() 290 */ 291 void QwtPlotShapeItem::setPen( const QPen &pen )292 { 293 if ( pen != d_data->pen )294 { 295 d_data->pen = pen;290 \brief Assign a pen 291 292 The pen is used to draw the outline of the shape 293 294 \param pen Pen 295 \sa pen(), brush() 296 */ 297 void QwtPlotShapeItem::setPen( const QPen& pen ) 298 { 299 if ( pen != m_data->pen ) 300 { 301 m_data->pen = pen; 296 302 itemChanged(); 297 303 } … … 301 307 \return Pen used to draw the outline of the shape 302 308 \sa setPen(), brush() 303 */ 309 */ 304 310 QPen QwtPlotShapeItem::pen() const 305 311 { 306 return d_data->pen;307 } 308 309 /*! 310 Assign a brush. 311 312 The brush is used to fill the path 313 314 \param brush Brush 315 \sa brush(), pen() 316 */ 317 void QwtPlotShapeItem::setBrush( const QBrush &brush )318 { 319 if ( brush != d_data->brush )320 { 321 d_data->brush = brush;312 return m_data->pen; 313 } 314 315 /*! 316 Assign a brush. 317 318 The brush is used to fill the path 319 320 \param brush Brush 321 \sa brush(), pen() 322 */ 323 void QwtPlotShapeItem::setBrush( const QBrush& brush ) 324 { 325 if ( brush != m_data->brush ) 326 { 327 m_data->brush = brush; 322 328 itemChanged(); 323 329 } … … 325 331 326 332 /*! 327 \return Brush used to fill the shape 328 \sa setBrush(), pen() 329 */ 333 \return Brush used to fill the shape 334 \sa setBrush(), pen() 335 */ 330 336 QBrush QwtPlotShapeItem::brush() const 331 337 { 332 return d_data->brush;333 } 334 335 /*! 336 \brief Set the tolerance for the weeding optimization 337 338 After translating the shape into target device coordinate 339 ( usually widget geometries ) the painter path can be simplified 340 by a point weeding algorithm ( Douglas-Peucker ). 341 342 For shapes built from curves and ellipses weeding might 343 have the opposite effect because they have to be expanded 344 to polygons. 345 346 \param tolerance Accepted error when reducing the number of points 338 return m_data->brush; 339 } 340 341 /*! 342 \brief Set the tolerance for the weeding optimization 343 344 After translating the shape into target device coordinate 345 ( usually widget geometries ) the painter path can be simplified 346 by a point weeding algorithm ( Douglas-Peucker ). 347 348 For shapes built from curves and ellipses weeding might 349 have the opposite effect because they have to be expanded 350 to polygons. 351 352 \param tolerance Accepted error when reducing the number of points 347 353 A value <= 0.0 disables weeding. 348 354 349 \sa renderTolerance(), QwtWeedingCurveFitter 355 \sa renderTolerance(), QwtWeedingCurveFitter 350 356 */ 351 357 void QwtPlotShapeItem::setRenderTolerance( double tolerance ) 352 358 { 353 tolerance = q Max( tolerance, 0.0 );354 355 if ( tolerance != d_data->renderTolerance )356 { 357 d_data->renderTolerance = tolerance;359 tolerance = qwtMaxF( tolerance, 0.0 ); 360 361 if ( tolerance != m_data->renderTolerance ) 362 { 363 m_data->renderTolerance = tolerance; 358 364 itemChanged(); 359 365 } … … 361 367 362 368 /*! 363 \return Tolerance for the weeding optimization 364 \sa setRenderTolerance() 369 \return Tolerance for the weeding optimization 370 \sa setRenderTolerance() 365 371 */ 366 372 double QwtPlotShapeItem::renderTolerance() const 367 373 { 368 return d_data->renderTolerance;369 } 370 371 /*! 372 Draw the shape item 373 374 \param painter Painter 375 \param xMap X-Scale Map 376 \param yMap Y-Scale Map 377 \param canvasRect Contents rect of the plot canvas 378 */ 379 void QwtPlotShapeItem::draw( QPainter *painter,380 const QwtScaleMap &xMap, const QwtScaleMap&yMap,381 const QRectF &canvasRect ) const382 { 383 if ( d_data->shape.isEmpty() )374 return m_data->renderTolerance; 375 } 376 377 /*! 378 Draw the shape item 379 380 \param painter Painter 381 \param xMap X-Scale Map 382 \param yMap Y-Scale Map 383 \param canvasRect Contents rect of the plot canvas 384 */ 385 void QwtPlotShapeItem::draw( QPainter* painter, 386 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 387 const QRectF& canvasRect ) const 388 { 389 if ( m_data->shape.isEmpty() ) 384 390 return; 385 391 386 if ( d_data->pen.style() == Qt::NoPen387 && d_data->brush.style() == Qt::NoBrush )392 if ( m_data->pen.style() == Qt::NoPen 393 && m_data->brush.style() == Qt::NoBrush ) 388 394 { 389 395 return; … … 393 399 xMap, yMap, canvasRect.toRect() ); 394 400 395 const QRectF &br = d_data->boundingRect;401 const QRectF& br = m_data->boundingRect; 396 402 397 403 if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() ) 398 404 || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) ) 399 405 { 400 // outside the visi sble area406 // outside the visible area 401 407 return; 402 408 } … … 405 411 406 412 QPainterPath path = qwtTransformPath( xMap, yMap, 407 d_data->shape, doAlign );413 m_data->shape, doAlign ); 408 414 409 415 if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) ) 410 416 { 411 qreal pw = qMax( qreal( 1.0 ),painter->pen().widthF());412 QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 417 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); 418 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 413 419 414 420 QPainterPath clippedPath; 415 421 clippedPath.setFillRule( path.fillRule() ); 416 422 417 const QList<QPolygonF> polygons = path.toSubpathPolygons();423 QList< QPolygonF > polygons = path.toSubpathPolygons(); 418 424 for ( int i = 0; i < polygons.size(); i++ ) 419 425 { 420 const QPolygonF p = QwtClipper::clipPolygonF( 421 clipRect, polygons[i], true ); 422 423 clippedPath.addPolygon( p ); 426 QwtClipper::clipPolygonF( clipRect, polygons[i], true ); 427 clippedPath.addPolygon( polygons[i] ); 424 428 425 429 } … … 428 432 } 429 433 430 if ( d_data->renderTolerance > 0.0 )431 { 432 QwtWeedingCurveFitter fitter( d_data->renderTolerance );434 if ( m_data->renderTolerance > 0.0 ) 435 { 436 QwtWeedingCurveFitter fitter( m_data->renderTolerance ); 433 437 434 438 QPainterPath fittedPath; 435 439 fittedPath.setFillRule( path.fillRule() ); 436 440 437 const QList<QPolygonF> polygons = path.toSubpathPolygons(); 441 const QList< QPolygonF > polygons = path.toSubpathPolygons(); 438 442 for ( int i = 0; i < polygons.size(); i++ ) 439 443 fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) ); … … 442 446 } 443 447 444 painter->setPen( d_data->pen );445 painter->setBrush( d_data->brush );448 painter->setPen( m_data->pen ); 449 painter->setBrush( m_data->brush ); 446 450 447 451 painter->drawPath( path ); … … 449 453 450 454 /*! 451 \return A rectangle filled with the color of the brush ( or the pen ) 452 453 \param index Index of the legend entry 455 \return A rectangle filled with the color of the brush ( or the pen ) 456 457 \param index Index of the legend entry 454 458 ( usually there is only one ) 455 \param size Icon size 456 457 \sa setLegendIconSize(), legendData() 458 */ 459 \param size Icon size 460 461 \sa setLegendIconSize(), legendData() 462 */ 459 463 QwtGraphic QwtPlotShapeItem::legendIcon( int index, 460 const QSizeF &size ) const464 const QSizeF& size ) const 461 465 { 462 466 Q_UNUSED( index ); … … 468 472 return icon; 469 473 470 if ( d_data->legendMode == QwtPlotShapeItem::LegendShape )471 { 472 const QRectF &br = d_data->boundingRect;474 if ( m_data->legendMode == QwtPlotShapeItem::LegendShape ) 475 { 476 const QRectF& br = m_data->boundingRect; 473 477 474 478 QPainter painter( &icon ); … … 478 482 painter.translate( -br.topLeft() ); 479 483 480 painter.setPen( d_data->pen );481 painter.setBrush( d_data->brush );482 painter.drawPath( d_data->shape );484 painter.setPen( m_data->pen ); 485 painter.setBrush( m_data->brush ); 486 painter.drawPath( m_data->shape ); 483 487 } 484 488 else 485 489 { 486 490 QColor iconColor; 487 if ( d_data->brush.style() != Qt::NoBrush )488 iconColor = d_data->brush.color();491 if ( m_data->brush.style() != Qt::NoBrush ) 492 iconColor = m_data->brush.color(); 489 493 else 490 iconColor = d_data->pen.color();494 iconColor = m_data->pen.color(); 491 495 492 496 icon = defaultIcon( iconColor, size ); -
trunk/BNC/qwt/qwt_plot_shapeitem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include <qpainterpath.h> 15 16 #include <qstring.h> 17 18 class QPainterPath; 19 class QPolygonF; 16 20 17 21 /*! 18 \brief A plot item, which displays any graphical shape, 22 \brief A plot item, which displays any graphical shape, 19 23 that can be defined by a QPainterPath 20 24 21 A QPainterPath is a shape composed from intersecting and uniting 22 regions, rectangles, ellipses or irregular areas defined by lines, and curves. 23 QwtPlotShapeItem displays a shape with a pen and brush. 25 A QPainterPath is a shape composed from intersecting and uniting 26 regions, rectangles, ellipses or irregular areas defined by lines, and curves. 27 QwtPlotShapeItem displays a shape with a pen and brush. 24 28 25 QwtPlotShapeItem offers a couple of optimizations like clipping or weeding. 26 These algorithms need to convert the painter path into polygons that might be 27 less performant for paths built from curves and ellipses. 29 QwtPlotShapeItem offers a couple of optimizations like clipping or weeding. 30 These algorithms need to convert the painter path into polygons that might be 31 less performant for paths built from curves and ellipses. 28 32 29 \sa QwtPlotZone 30 */ 31 class QWT_EXPORT QwtPlotShapeItem: public QwtPlotItem 33 More complex shapes, that can't be expressed by a QPainterPath can be displayed 34 using QwtPlotGraphicItem. 35 36 \sa QwtPlotZone, QwtPlotGraphicItem 37 */ 38 class QWT_EXPORT QwtPlotShapeItem : public QwtPlotItem 32 39 { 33 public: 40 public: 34 41 /*! 35 42 Attributes to modify the drawing algorithm. … … 37 44 38 45 \sa setPaintAttribute(), testPaintAttribute() 39 */ 46 */ 40 47 enum PaintAttribute 41 48 { 42 49 /*! 43 Clip polygons before painting them. In situations, where points 44 are far outside the visible area (f.e when zooming deep) this 45 might be a substantial improvement for the painting performance 50 Clip polygons before painting them. In situations, where points 51 are far outside the visible area (f.e when zooming deep) this 52 might be a substantial improvement for the painting performance 46 53 47 But polygon clipping will convert the painter path into 48 polygons what might introduce a negative impact on the 49 performance of paths composed from curves or ellipses. 54 But polygon clipping will convert the painter path into 55 polygons what might introduce a negative impact on the 56 performance of paths composed from curves or ellipses. 50 57 */ 51 58 ClipPolygons = 0x01, 52 59 }; 53 60 54 //! Paint attributes 55 typedef QFlags<PaintAttribute> PaintAttributes; 61 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 56 62 57 63 //! Mode how to display the item on the legend … … 65 71 }; 66 72 67 explicit QwtPlotShapeItem( const QString &title = QString() );68 explicit QwtPlotShapeItem( const QwtText &title );73 explicit QwtPlotShapeItem( const QString& title = QString() ); 74 explicit QwtPlotShapeItem( const QwtText& title ); 69 75 70 76 virtual ~QwtPlotShapeItem(); … … 76 82 LegendMode legendMode() const; 77 83 78 void setRect( const QRectF & );79 void setPolygon( const QPolygonF & );84 void setRect( const QRectF& ); 85 void setPolygon( const QPolygonF& ); 80 86 81 void setShape( const QPainterPath & );87 void setShape( const QPainterPath& ); 82 88 QPainterPath shape() const; 83 89 84 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );85 void setPen( const QPen & );90 void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 91 void setPen( const QPen& ); 86 92 QPen pen() const; 87 93 88 void setBrush( const QBrush & );94 void setBrush( const QBrush& ); 89 95 QBrush brush() const; 90 96 … … 92 98 double renderTolerance() const; 93 99 94 virtual QRectF boundingRect() const; 100 virtual QRectF boundingRect() const QWT_OVERRIDE; 95 101 96 virtual void draw( QPainter *,97 const QwtScaleMap &xMap, const QwtScaleMap&yMap,98 const QRectF &canvasRect ) const;102 virtual void draw( QPainter*, 103 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 104 const QRectF& canvasRect ) const QWT_OVERRIDE; 99 105 100 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 106 virtual QwtGraphic legendIcon( 107 int index, const QSizeF& ) const QWT_OVERRIDE; 101 108 102 virtual int rtti() const; 109 virtual int rtti() const QWT_OVERRIDE; 103 110 104 private: 111 private: 105 112 void init(); 106 113 107 114 class PrivateData; 108 PrivateData *d_data;115 PrivateData* m_data; 109 116 }; 110 117 -
trunk/BNC/qwt/qwt_plot_spectrocurve.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_scale_map.h" 13 13 #include "qwt_painter.h" 14 #include "qwt_text.h" 15 14 16 #include <qpainter.h> 15 17 16 18 class QwtPlotSpectroCurve::PrivateData 17 19 { 18 public: 19 PrivateData() :20 colorRange( 0.0, 1000.0 ) ,21 penWidth( 0.0),22 paintAttributes( QwtPlotSpectroCurve::ClipPoints ) 20 public: 21 PrivateData() 22 : colorRange( 0.0, 1000.0 ) 23 , penWidth( 0.0 ) 24 , paintAttributes( QwtPlotSpectroCurve::ClipPoints ) 23 25 { 24 26 colorMap = new QwtLinearColorMap(); … … 30 32 } 31 33 32 QwtColorMap *colorMap;34 QwtColorMap* colorMap; 33 35 QwtInterval colorRange; 34 QVector< QRgb> colorTable;36 QVector< QRgb > colorTable; 35 37 double penWidth; 36 38 QwtPlotSpectroCurve::PaintAttributes paintAttributes; … … 38 40 39 41 /*! 40 Constructor 41 \param title Title of the curve 42 */ 43 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QwtText &title ):44 QwtPlotSeriesItem( title ) 42 Constructor 43 \param title Title of the curve 44 */ 45 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QwtText& title ) 46 : QwtPlotSeriesItem( title ) 45 47 { 46 48 init(); … … 48 50 49 51 /*! 50 Constructor 51 \param title Title of the curve 52 */ 53 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString &title ):54 QwtPlotSeriesItem( QwtText( title ) ) 52 Constructor 53 \param title Title of the curve 54 */ 55 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString& title ) 56 : QwtPlotSeriesItem( QwtText( title ) ) 55 57 { 56 58 init(); … … 60 62 QwtPlotSpectroCurve::~QwtPlotSpectroCurve() 61 63 { 62 delete d_data;63 } 64 65 /*! 66 \brief Initialize data members 67 */ 64 delete m_data; 65 } 66 67 /*! 68 \brief Initialize data members 69 */ 68 70 void QwtPlotSpectroCurve::init() 69 71 { … … 71 73 setItemAttribute( QwtPlotItem::AutoScale ); 72 74 73 d_data = new PrivateData;75 m_data = new PrivateData; 74 76 setData( new QwtPoint3DSeriesData() ); 75 77 … … 84 86 85 87 /*! 86 Specify an attribute how to draw the curve 87 88 \param attribute Paint attribute 89 \param on On/Off 90 /sa PaintAttribute, testPaintAttribute() 91 */ 88 Specify an attribute how to draw the curve 89 90 \param attribute Paint attribute 91 \param on On/Off 92 /sa PaintAttribute, testPaintAttribute() 93 */ 92 94 void QwtPlotSpectroCurve::setPaintAttribute( PaintAttribute attribute, bool on ) 93 95 { 94 96 if ( on ) 95 d_data->paintAttributes |= attribute;97 m_data->paintAttributes |= attribute; 96 98 else 97 d_data->paintAttributes &= ~attribute;99 m_data->paintAttributes &= ~attribute; 98 100 } 99 101 … … 101 103 \return True, when attribute is enabled 102 104 \sa PaintAttribute, setPaintAttribute() 103 */ 105 */ 104 106 bool QwtPlotSpectroCurve::testPaintAttribute( PaintAttribute attribute ) const 105 107 { 106 return ( d_data->paintAttributes & attribute );107 } 108 109 /*! 110 Initialize data with an array of samples. 111 \param samples Vector of points 112 */ 113 void QwtPlotSpectroCurve::setSamples( const QVector<QwtPoint3D > &samples )108 return ( m_data->paintAttributes & attribute ); 109 } 110 111 /*! 112 Initialize data with an array of samples. 113 \param samples Vector of points 114 */ 115 void QwtPlotSpectroCurve::setSamples( const QVector< QwtPoint3D >& samples ) 114 116 { 115 117 setData( new QwtPoint3DSeriesData( samples ) ); … … 117 119 118 120 /*! 119 Assign a series of samples 120 121 setSamples() is just a wrapper for setData() without any additional 122 value - beside that it is easier to find for the developer. 123 124 \param data Data 125 \warning The item takes ownership of the data object, deleting 121 Assign a series of samples 122 123 setSamples() is just a wrapper for setData() without any additional 124 value - beside that it is easier to find for the developer. 125 126 \param data Data 127 \warning The item takes ownership of the data object, deleting 126 128 it when its not used anymore. 127 */ 129 */ 128 130 void QwtPlotSpectroCurve::setSamples( 129 QwtSeriesData<QwtPoint3D > *data )131 QwtSeriesData< QwtPoint3D >* data ) 130 132 { 131 133 setData( data ); … … 133 135 134 136 /*! 135 Change the color map 136 137 Often it is useful to display the mapping between intensities and 138 colors as an additional plot axis, showing a color bar. 139 140 \param colorMap Color Map 141 142 \sa colorMap(), setColorRange(), QwtColorMap::color(), 137 Change the color map 138 139 Often it is useful to display the mapping between intensities and 140 colors as an additional plot axis, showing a color bar. 141 142 \param colorMap Color Map 143 144 \sa colorMap(), setColorRange(), QwtColorMap::color(), 143 145 QwtScaleWidget::setColorBarEnabled(), QwtScaleWidget::setColorMap() 144 */ 145 void QwtPlotSpectroCurve::setColorMap( QwtColorMap *colorMap )146 { 147 if ( colorMap != d_data->colorMap )148 { 149 delete d_data->colorMap;150 d_data->colorMap = colorMap;146 */ 147 void QwtPlotSpectroCurve::setColorMap( QwtColorMap* colorMap ) 148 { 149 if ( colorMap != m_data->colorMap ) 150 { 151 delete m_data->colorMap; 152 m_data->colorMap = colorMap; 151 153 } 152 154 … … 158 160 \return Color Map used for mapping the intensity values to colors 159 161 \sa setColorMap(), setColorRange(), QwtColorMap::color() 160 */ 161 const QwtColorMap *QwtPlotSpectroCurve::colorMap() const162 { 163 return d_data->colorMap;162 */ 163 const QwtColorMap* QwtPlotSpectroCurve::colorMap() const 164 { 165 return m_data->colorMap; 164 166 } 165 167 … … 171 173 172 174 \sa colorRange(), setColorMap(), QwtColorMap::color() 173 */ 174 void QwtPlotSpectroCurve::setColorRange( const QwtInterval &interval )175 { 176 if ( interval != d_data->colorRange )177 { 178 d_data->colorRange = interval;175 */ 176 void QwtPlotSpectroCurve::setColorRange( const QwtInterval& interval ) 177 { 178 if ( interval != m_data->colorRange ) 179 { 180 m_data->colorRange = interval; 179 181 180 182 legendChanged(); … … 184 186 185 187 /*! 186 \return Value interval, that corresponds to the color map 187 \sa setColorRange(), setColorMap(), QwtColorMap::color() 188 */ 189 QwtInterval &QwtPlotSpectroCurve::colorRange() const190 { 191 return d_data->colorRange;192 } 193 194 /*! 195 Assign a pen width 196 197 \param penWidth New pen width 198 \sa penWidth() 199 */ 188 \return Value interval, that corresponds to the color map 189 \sa setColorRange(), setColorMap(), QwtColorMap::color() 190 */ 191 QwtInterval& QwtPlotSpectroCurve::colorRange() const 192 { 193 return m_data->colorRange; 194 } 195 196 /*! 197 Assign a pen width 198 199 \param penWidth New pen width 200 \sa penWidth() 201 */ 200 202 void QwtPlotSpectroCurve::setPenWidth(double penWidth) 201 203 { … … 203 205 penWidth = 0.0; 204 206 205 if ( d_data->penWidth != penWidth )206 { 207 d_data->penWidth = penWidth;207 if ( m_data->penWidth != penWidth ) 208 { 209 m_data->penWidth = penWidth; 208 210 209 211 legendChanged(); … … 213 215 214 216 /*! 215 \return Pen width used to draw a dot 216 \sa setPenWidth() 217 */ 217 \return Pen width used to draw a dot 218 \sa setPenWidth() 219 */ 218 220 double QwtPlotSpectroCurve::penWidth() const 219 221 { 220 return d_data->penWidth;221 } 222 223 /*! 224 Draw a subset of the points 225 226 \param painter Painter 227 \param xMap Maps x-values into pixel coordinates. 228 \param yMap Maps y-values into pixel coordinates. 229 \param canvasRect Contents rectangle of the canvas 230 \param from Index of the first sample to be painted 231 \param to Index of the last sample to be painted. If to < 0 the 222 return m_data->penWidth; 223 } 224 225 /*! 226 Draw a subset of the points 227 228 \param painter Painter 229 \param xMap Maps x-values into pixel coordinates. 230 \param yMap Maps y-values into pixel coordinates. 231 \param canvasRect Contents rectangle of the canvas 232 \param from Index of the first sample to be painted 233 \param to Index of the last sample to be painted. If to < 0 the 232 234 series will be painted to its last sample. 233 235 234 \sa drawDots() 235 */ 236 void QwtPlotSpectroCurve::drawSeries( QPainter *painter,237 const QwtScaleMap &xMap, const QwtScaleMap&yMap,238 const QRectF &canvasRect, int from, int to ) const236 \sa drawDots() 237 */ 238 void QwtPlotSpectroCurve::drawSeries( QPainter* painter, 239 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 240 const QRectF& canvasRect, int from, int to ) const 239 241 { 240 242 if ( !painter || dataSize() <= 0 ) … … 254 256 255 257 /*! 256 Draw a subset of the points 257 258 \param painter Painter 259 \param xMap Maps x-values into pixel coordinates. 260 \param yMap Maps y-values into pixel coordinates. 261 \param canvasRect Contents rectangle of the canvas 262 \param from Index of the first sample to be painted 263 \param to Index of the last sample to be painted. If to < 0 the 258 Draw a subset of the points 259 260 \param painter Painter 261 \param xMap Maps x-values into pixel coordinates. 262 \param yMap Maps y-values into pixel coordinates. 263 \param canvasRect Contents rectangle of the canvas 264 \param from Index of the first sample to be painted 265 \param to Index of the last sample to be painted. If to < 0 the 264 266 series will be painted to its last sample. 265 267 266 \sa drawSeries() 267 */ 268 void QwtPlotSpectroCurve::drawDots( QPainter *painter,269 const QwtScaleMap &xMap, const QwtScaleMap&yMap,270 const QRectF &canvasRect, int from, int to ) const271 { 272 if ( ! d_data->colorRange.isValid() )268 \sa drawSeries() 269 */ 270 void QwtPlotSpectroCurve::drawDots( QPainter* painter, 271 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 272 const QRectF& canvasRect, int from, int to ) const 273 { 274 if ( !m_data->colorRange.isValid() ) 273 275 return; 274 276 275 277 const bool doAlign = QwtPainter::roundingAlignment( painter ); 276 278 277 const QwtColorMap::Format format = d_data->colorMap->format();279 const QwtColorMap::Format format = m_data->colorMap->format(); 278 280 if ( format == QwtColorMap::Indexed ) 279 d_data->colorTable =d_data->colorMap->colorTable( d_data->colorRange);280 281 const QwtSeriesData<QwtPoint3D > *series = data();281 m_data->colorTable = m_data->colorMap->colorTable256(); 282 283 const QwtSeriesData< QwtPoint3D >* series = data(); 282 284 283 285 for ( int i = from; i <= to; i++ ) … … 293 295 } 294 296 295 if ( d_data->paintAttributes & QwtPlotSpectroCurve::ClipPoints )297 if ( m_data->paintAttributes & QwtPlotSpectroCurve::ClipPoints ) 296 298 { 297 299 if ( !canvasRect.contains( xi, yi ) ) … … 301 303 if ( format == QwtColorMap::RGB ) 302 304 { 303 const QRgb rgb = d_data->colorMap->rgb(304 d_data->colorRange, sample.z() );305 306 painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) );305 const QRgb rgb = m_data->colorMap->rgb( 306 m_data->colorRange, sample.z() ); 307 308 painter->setPen( QPen( QColor::fromRgba( rgb ), m_data->penWidth ) ); 307 309 } 308 310 else 309 311 { 310 const unsigned char index = d_data->colorMap->colorIndex(311 d_data->colorRange, sample.z() );312 313 painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ),314 d_data->penWidth ) );312 const unsigned char index = m_data->colorMap->colorIndex( 313 256, m_data->colorRange, sample.z() ); 314 315 painter->setPen( QPen( QColor::fromRgba( m_data->colorTable[index] ), 316 m_data->penWidth ) ); 315 317 } 316 318 … … 318 320 } 319 321 320 d_data->colorTable.clear();321 } 322 m_data->colorTable.clear(); 323 } -
trunk/BNC/qwt/qwt_plot_spectrocurve.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_seriesitem.h" 15 #include "qwt_series_data.h"16 15 17 class QwtSymbol;18 16 class QwtColorMap; 19 17 … … 21 19 \brief Curve that displays 3D points as dots, where the z coordinate is 22 20 mapped to a color. 23 */ 24 class QWT_EXPORT QwtPlotSpectroCurve: 25 public QwtPlotSeriesItem, public QwtSeriesStore<QwtPoint3D> 21 */ 22 class QWT_EXPORT QwtPlotSpectroCurve 23 : public QwtPlotSeriesItem 24 , public QwtSeriesStore< QwtPoint3D > 26 25 { 27 public: 26 public: 28 27 //! Paint attributes 29 28 enum PaintAttribute … … 33 32 }; 34 33 35 //! Paint attributes 36 typedef QFlags<PaintAttribute> PaintAttributes; 34 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 37 35 38 explicit QwtPlotSpectroCurve( const QString &title = QString() );39 explicit QwtPlotSpectroCurve( const QwtText &title );36 explicit QwtPlotSpectroCurve( const QString& title = QString() ); 37 explicit QwtPlotSpectroCurve( const QwtText& title ); 40 38 41 39 virtual ~QwtPlotSpectroCurve(); 42 40 43 virtual int rtti() const; 41 virtual int rtti() const QWT_OVERRIDE; 44 42 45 43 void setPaintAttribute( PaintAttribute, bool on = true ); 46 44 bool testPaintAttribute( PaintAttribute ) const; 47 45 48 void setSamples( const QVector<QwtPoint3D >& );49 void setSamples( QwtSeriesData<QwtPoint3D >* );46 void setSamples( const QVector< QwtPoint3D >& ); 47 void setSamples( QwtSeriesData< QwtPoint3D >* ); 50 48 51 49 52 void setColorMap( QwtColorMap * );53 const QwtColorMap *colorMap() const;50 void setColorMap( QwtColorMap* ); 51 const QwtColorMap* colorMap() const; 54 52 55 void setColorRange( const QwtInterval & );56 QwtInterval & colorRange() const;53 void setColorRange( const QwtInterval& ); 54 QwtInterval& colorRange() const; 57 55 58 virtual void drawSeries( QPainter *,59 const QwtScaleMap &xMap, const QwtScaleMap&yMap,60 const QRectF &canvasRect, int from, int to ) const;56 virtual void drawSeries( QPainter*, 57 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 58 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 61 59 62 60 void setPenWidth( double ); 63 61 double penWidth() const; 64 62 65 protected: 66 virtual void drawDots( QPainter *,67 const QwtScaleMap &xMap, const QwtScaleMap&yMap,68 const QRectF &canvasRect, int from, int to ) const;63 protected: 64 virtual void drawDots( QPainter*, 65 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 66 const QRectF& canvasRect, int from, int to ) const; 69 67 70 private: 68 private: 71 69 void init(); 72 70 73 71 class PrivateData; 74 PrivateData *d_data;72 PrivateData* m_data; 75 73 }; 76 74 -
trunk/BNC/qwt/qwt_plot_spectrogram.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_scale_map.h" 14 14 #include "qwt_color_map.h" 15 #include "qwt_math.h" 16 15 17 #include <qimage.h> 16 18 #include <qpen.h> 17 19 #include <qpainter.h> 18 #include <qmath.h>19 #include <qalgorithms.h>20 #if QT_VERSION >= 0x04040021 20 #include <qthread.h> 22 21 #include <qfuture.h> 23 22 #include <qtconcurrentrun.h> 23 24 #define DEBUG_RENDER 0 25 26 #if DEBUG_RENDER 27 #include <qelapsedtimer.h> 24 28 #endif 25 29 26 #define DEBUG_RENDER 0 27 28 #if DEBUG_RENDER 29 #include <QElapsedTimer> 30 #endif 30 #include <algorithm> 31 32 static inline bool qwtIsNaN( double d ) 33 { 34 // qt_is_nan is private header and qIsNaN is not inlined 35 // so we need these code here too 36 37 const uchar* ch = (const uchar*)&d; 38 if ( QSysInfo::ByteOrder == QSysInfo::BigEndian ) 39 { 40 return ( ch[0] & 0x7f ) == 0x7f && ch[1] > 0xf0; 41 } 42 else 43 { 44 return ( ch[7] & 0x7f ) == 0x7f && ch[6] > 0xf0; 45 } 46 } 31 47 32 48 class QwtPlotSpectrogram::PrivateData 33 49 { 34 public: 35 PrivateData(): 36 data( NULL ) 50 public: 51 PrivateData() 52 : data( NULL ) 53 , colorTableSize( 0 ) 37 54 { 38 55 colorMap = new QwtLinearColorMap(); … … 44 61 #endif 45 62 } 63 46 64 ~PrivateData() 47 65 { … … 50 68 } 51 69 52 QwtRasterData *data; 53 QwtColorMap *colorMap; 70 void updateColorTable() 71 { 72 if ( colorMap->format() == QwtColorMap::Indexed ) 73 { 74 colorTable = colorMap->colorTable256(); 75 } 76 else 77 { 78 if ( colorTableSize == 0 ) 79 colorTable.clear(); 80 else 81 colorTable = colorMap->colorTable( colorTableSize ); 82 } 83 } 84 85 QwtRasterData* data; 86 QwtColorMap* colorMap; 54 87 DisplayModes displayMode; 55 88 56 QList< double> contourLevels;89 QList< double > contourLevels; 57 90 QPen defaultContourPen; 58 91 QwtRasterData::ConrecFlags conrecFlags; 92 93 int colorTableSize; 94 QVector< QRgb > colorTable; 59 95 }; 60 96 … … 69 105 70 106 \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ() 71 */ 72 QwtPlotSpectrogram::QwtPlotSpectrogram( const QString &title ):73 QwtPlotRasterItem( title ) 74 { 75 d_data = new PrivateData();107 */ 108 QwtPlotSpectrogram::QwtPlotSpectrogram( const QString& title ) 109 : QwtPlotRasterItem( title ) 110 { 111 m_data = new PrivateData(); 76 112 77 113 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 84 120 QwtPlotSpectrogram::~QwtPlotSpectrogram() 85 121 { 86 delete d_data;122 delete m_data; 87 123 } 88 124 … … 102 138 103 139 \sa DisplayMode, displayMode() 104 */ 140 */ 105 141 void QwtPlotSpectrogram::setDisplayMode( DisplayMode mode, bool on ) 106 142 { 107 if ( on != bool( mode & d_data->displayMode ) )143 if ( on != bool( mode & m_data->displayMode ) ) 108 144 { 109 145 if ( on ) 110 d_data->displayMode |= mode;146 m_data->displayMode |= mode; 111 147 else 112 d_data->displayMode &= ~mode;148 m_data->displayMode &= ~mode; 113 149 } 114 150 … … 122 158 \param mode Display mode 123 159 \return true if mode is enabled 124 */ 160 */ 125 161 bool QwtPlotSpectrogram::testDisplayMode( DisplayMode mode ) const 126 162 { 127 return ( d_data->displayMode & mode );128 } 129 130 /*! 131 Change the color map 132 133 Often it is useful to display the mapping between intensities and 134 colors as an additional plot axis, showing a color bar. 135 136 \param colorMap Color Map 137 138 \sa colorMap(), QwtScaleWidget::setColorBarEnabled(), 163 return ( m_data->displayMode & mode ); 164 } 165 166 /*! 167 Change the color map 168 169 Often it is useful to display the mapping between intensities and 170 colors as an additional plot axis, showing a color bar. 171 172 \param colorMap Color Map 173 174 \sa colorMap(), QwtScaleWidget::setColorBarEnabled(), 139 175 QwtScaleWidget::setColorMap() 140 */ 141 void QwtPlotSpectrogram::setColorMap( QwtColorMap *colorMap ) 142 { 143 if ( d_data->colorMap != colorMap ) 144 { 145 delete d_data->colorMap; 146 d_data->colorMap = colorMap; 147 } 176 */ 177 void QwtPlotSpectrogram::setColorMap( QwtColorMap* colorMap ) 178 { 179 if ( colorMap == NULL ) 180 return; 181 182 if ( colorMap != m_data->colorMap ) 183 { 184 delete m_data->colorMap; 185 m_data->colorMap = colorMap; 186 } 187 188 m_data->updateColorTable(); 148 189 149 190 invalidateCache(); … … 156 197 \return Color Map used for mapping the intensity values to colors 157 198 \sa setColorMap() 158 */ 159 const QwtColorMap *QwtPlotSpectrogram::colorMap() const 160 { 161 return d_data->colorMap; 162 } 163 164 /*! 165 Build and assign the default pen for the contour lines 166 167 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 168 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 169 to hide this incompatibility. 170 171 \param color Pen color 172 \param width Pen width 173 \param style Pen style 174 175 \sa pen(), brush() 199 */ 200 const QwtColorMap* QwtPlotSpectrogram::colorMap() const 201 { 202 return m_data->colorMap; 203 } 204 205 /*! 206 Limit the number of colors being used by the color map 207 208 When using a color table the mapping from the value into a color 209 is usually faster as it can be done by simple lookups into a 210 precalculated color table. 211 212 Setting a table size > 0 enables using a color table, while setting 213 the size to 0 disables it. 214 215 The default size = 0, and no color table is used. 216 217 \param numColors Number of colors. 0 means not using a color table 218 \note The colorTableSize has no effect when using a color table 219 of QwtColorMap::Indexed, where the size is always 256. 220 221 222 \sa QwtColorMap::colorTable(), colorTableSize() 223 */ 224 void QwtPlotSpectrogram::setColorTableSize( int numColors ) 225 { 226 numColors = qMax( numColors, 0 ); 227 if ( numColors != m_data->colorTableSize ) 228 { 229 m_data->colorTableSize = numColors; 230 m_data->updateColorTable(); 231 invalidateCache(); 232 } 233 } 234 /*! 235 \return Size of the color table, 0 means not using a color table 236 \sa QwtColorMap::colorTable(), setColorTableSize() 237 */ 238 int QwtPlotSpectrogram::colorTableSize() const 239 { 240 return m_data->colorTableSize; 241 } 242 243 /*! 244 Build and assign the default pen for the contour lines 245 246 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 247 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 248 to hide this incompatibility. 249 250 \param color Pen color 251 \param width Pen width 252 \param style Pen style 253 254 \sa pen(), brush() 176 255 */ 177 256 void QwtPlotSpectrogram::setDefaultContourPen( 178 const QColor &color, qreal width, Qt::PenStyle style )257 const QColor& color, qreal width, Qt::PenStyle style ) 179 258 { 180 259 setDefaultContourPen( QPen( color, width, style ) ); … … 190 269 191 270 \sa defaultContourPen(), contourPen() 192 */ 193 void QwtPlotSpectrogram::setDefaultContourPen( const QPen &pen )194 { 195 if ( pen != d_data->defaultContourPen )196 { 197 d_data->defaultContourPen = pen;271 */ 272 void QwtPlotSpectrogram::setDefaultContourPen( const QPen& pen ) 273 { 274 if ( pen != m_data->defaultContourPen ) 275 { 276 m_data->defaultContourPen = pen; 198 277 199 278 legendChanged(); … … 205 284 \return Default contour pen 206 285 \sa setDefaultContourPen() 207 */ 286 */ 208 287 QPen QwtPlotSpectrogram::defaultContourPen() const 209 288 { 210 return d_data->defaultContourPen;289 return m_data->defaultContourPen; 211 290 } 212 291 … … 221 300 222 301 \sa setDefaultContourPen(), setColorMap(), setContourLevels() 223 */ 302 */ 224 303 QPen QwtPlotSpectrogram::contourPen( double level ) const 225 304 { 226 if ( d_data->data == NULL ||d_data->colorMap == NULL )305 if ( m_data->data == NULL || m_data->colorMap == NULL ) 227 306 return QPen(); 228 307 229 const QwtInterval intensityRange = d_data->data->interval(Qt::ZAxis);230 const QColor c( d_data->colorMap->rgb( intensityRange, level ) );308 const QwtInterval intensityRange = m_data->data->interval(Qt::ZAxis); 309 const QColor c( m_data->colorMap->rgb( intensityRange, level ) ); 231 310 232 311 return QPen( c ); … … 242 321 \sa testConrecFlag(), renderContourLines(), 243 322 QwtRasterData::contourLines() 244 */ 323 */ 245 324 void QwtPlotSpectrogram::setConrecFlag( 246 325 QwtRasterData::ConrecFlag flag, bool on ) 247 326 { 248 if ( bool( d_data->conrecFlags & flag ) == on )327 if ( bool( m_data->conrecFlags & flag ) == on ) 249 328 return; 250 329 251 330 if ( on ) 252 d_data->conrecFlags |= flag;331 m_data->conrecFlags |= flag; 253 332 else 254 d_data->conrecFlags &= ~flag;333 m_data->conrecFlags &= ~flag; 255 334 256 335 itemChanged(); … … 268 347 \sa setConrecClag(), renderContourLines(), 269 348 QwtRasterData::contourLines() 270 */ 349 */ 271 350 bool QwtPlotSpectrogram::testConrecFlag( 272 351 QwtRasterData::ConrecFlag flag ) const 273 352 { 274 return d_data->conrecFlags & flag;353 return m_data->conrecFlags & flag; 275 354 } 276 355 … … 283 362 284 363 \note contourLevels returns the same levels but sorted. 285 */ 286 void QwtPlotSpectrogram::setContourLevels( const QList< double> &levels )287 { 288 d_data->contourLevels = levels;289 qSort( d_data->contourLevels );364 */ 365 void QwtPlotSpectrogram::setContourLevels( const QList< double >& levels ) 366 { 367 m_data->contourLevels = levels; 368 std::sort( m_data->contourLevels.begin(), m_data->contourLevels.end() ); 290 369 291 370 legendChanged(); … … 300 379 \sa contourLevels(), renderContourLines(), 301 380 QwtRasterData::contourLines() 302 */ 303 QList< double> QwtPlotSpectrogram::contourLevels() const304 { 305 return d_data->contourLevels;306 } 307 308 /*! 309 Set the data to be displayed 310 311 \param data Spectrogram Data 312 \sa data() 313 */ 314 void QwtPlotSpectrogram::setData( QwtRasterData *data )315 { 316 if ( data != d_data->data )317 { 318 delete d_data->data;319 d_data->data = data;381 */ 382 QList< double > QwtPlotSpectrogram::contourLevels() const 383 { 384 return m_data->contourLevels; 385 } 386 387 /*! 388 Set the data to be displayed 389 390 \param data Spectrogram Data 391 \sa data() 392 */ 393 void QwtPlotSpectrogram::setData( QwtRasterData* data ) 394 { 395 if ( data != m_data->data ) 396 { 397 delete m_data->data; 398 m_data->data = data; 320 399 321 400 invalidateCache(); … … 325 404 326 405 /*! 327 \return Spectrogram data 328 \sa setData() 329 */ 330 const QwtRasterData *QwtPlotSpectrogram::data() const331 { 332 return d_data->data;333 } 334 335 /*! 336 \return Spectrogram data 337 \sa setData() 338 */ 339 QwtRasterData *QwtPlotSpectrogram::data()340 { 341 return d_data->data;406 \return Spectrogram data 407 \sa setData() 408 */ 409 const QwtRasterData* QwtPlotSpectrogram::data() const 410 { 411 return m_data->data; 412 } 413 414 /*! 415 \return Spectrogram data 416 \sa setData() 417 */ 418 QwtRasterData* QwtPlotSpectrogram::data() 419 { 420 return m_data->data; 342 421 } 343 422 … … 350 429 \param axis X, Y, or Z axis 351 430 \sa QwtRasterData::interval() 352 */ 431 */ 353 432 QwtInterval QwtPlotSpectrogram::interval(Qt::Axis axis) const 354 433 { 355 if ( d_data->data == NULL )434 if ( m_data->data == NULL ) 356 435 return QwtInterval(); 357 436 358 return d_data->data->interval( axis );437 return m_data->data->interval( axis ); 359 438 } 360 439 … … 374 453 \sa QwtPlotRasterItem::pixelHint(), QwtRasterData::pixelHint(), 375 454 render(), renderImage() 376 */ 377 QRectF QwtPlotSpectrogram::pixelHint( const QRectF &area ) const378 { 379 if ( d_data->data == NULL )455 */ 456 QRectF QwtPlotSpectrogram::pixelHint( const QRectF& area ) const 457 { 458 if ( m_data->data == NULL ) 380 459 return QRectF(); 381 460 382 return d_data->data->pixelHint( area );461 return m_data->data->pixelHint( area ); 383 462 } 384 463 … … 388 467 For each pixel of area the value is mapped into a color. 389 468 390 \param xMap X-Scale Map 391 \param yMap Y-Scale Map 392 \param area Requested area for the image in scale coordinates 393 \param imageSize Size of the requested image 469 \param xMap X-Scale Map 470 \param yMap Y-Scale Map 471 \param area Requested area for the image in scale coordinates 472 \param imageSize Size of the requested image 394 473 395 474 \return A QImage::Format_Indexed8 or QImage::Format_ARGB32 depending … … 398 477 \sa QwtRasterData::value(), QwtColorMap::rgb(), 399 478 QwtColorMap::colorIndex() 400 */ 479 */ 401 480 QImage QwtPlotSpectrogram::renderImage( 402 const QwtScaleMap &xMap, const QwtScaleMap&yMap,403 const QRectF &area, const QSize&imageSize ) const404 { 405 if ( imageSize.isEmpty() || d_data->data == NULL406 || d_data->colorMap == NULL )481 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 482 const QRectF& area, const QSize& imageSize ) const 483 { 484 if ( imageSize.isEmpty() || m_data->data == NULL 485 || m_data->colorMap == NULL ) 407 486 { 408 487 return QImage(); 409 488 } 410 489 411 const QwtInterval intensityRange = d_data->data->interval( Qt::ZAxis );490 const QwtInterval intensityRange = m_data->data->interval( Qt::ZAxis ); 412 491 if ( !intensityRange.isValid() ) 413 492 return QImage(); 414 493 415 QImage::Format format = ( d_data->colorMap->format() == QwtColorMap::RGB )494 const QImage::Format format = ( m_data->colorMap->format() == QwtColorMap::RGB ) 416 495 ? QImage::Format_ARGB32 : QImage::Format_Indexed8; 417 496 418 497 QImage image( imageSize, format ); 419 498 420 if ( d_data->colorMap->format() == QwtColorMap::Indexed )421 image.setColorTable( d_data->colorMap->colorTable( intensityRange) );422 423 d_data->data->initRaster( area, image.size() );499 if ( m_data->colorMap->format() == QwtColorMap::Indexed ) 500 image.setColorTable( m_data->colorMap->colorTable256() ); 501 502 m_data->data->initRaster( area, image.size() ); 424 503 425 504 #if DEBUG_RENDER … … 428 507 #endif 429 508 430 #if QT_VERSION >= 0x040400 &&!defined(QT_NO_QFUTURE)509 #if !defined( QT_NO_QFUTURE ) 431 510 uint numThreads = renderThreadCount(); 432 511 … … 439 518 const int numRows = imageSize.height() / numThreads; 440 519 441 QList< QFuture<void> > futures; 520 QVector< QFuture< void > > futures; 521 futures.reserve( numThreads - 1 ); 522 442 523 for ( uint i = 0; i < numThreads; i++ ) 443 524 { … … 451 532 { 452 533 futures += QtConcurrent::run( 534 #if QT_VERSION >= 0x060000 535 &QwtPlotSpectrogram::renderTile, this, 536 #else 453 537 this, &QwtPlotSpectrogram::renderTile, 538 #endif 454 539 xMap, yMap, tile, &image ); 455 540 } 456 541 } 542 457 543 for ( int i = 0; i < futures.size(); i++ ) 458 544 futures[i].waitForFinished(); 459 545 460 #else // QT_VERSION < 0x040400546 #else 461 547 const QRect tile( 0, 0, image.width(), image.height() ); 462 548 renderTile( xMap, yMap, tile, &image ); … … 468 554 #endif 469 555 470 d_data->data->discardRaster();556 m_data->data->discardRaster(); 471 557 472 558 return image; … … 483 569 \param tile Geometry of the tile in image coordinates 484 570 \param image Image to be rendered 485 */ 571 */ 486 572 void QwtPlotSpectrogram::renderTile( 487 const QwtScaleMap &xMap, const QwtScaleMap&yMap,488 const QRect &tile, QImage*image ) const489 { 490 const QwtInterval range = d_data->data->interval( Qt::ZAxis );491 if ( !range.isValid())573 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 574 const QRect& tile, QImage* image ) const 575 { 576 const QwtInterval range = m_data->data->interval( Qt::ZAxis ); 577 if ( range.width() <= 0.0 ) 492 578 return; 493 579 494 if ( d_data->colorMap->format() == QwtColorMap::RGB ) 495 { 580 const bool hasGaps = !m_data->data->testAttribute( QwtRasterData::WithoutGaps ); 581 582 if ( m_data->colorMap->format() == QwtColorMap::RGB ) 583 { 584 const int numColors = m_data->colorTable.size(); 585 const QRgb* rgbTable = m_data->colorTable.constData(); 586 const QwtColorMap* colorMap = m_data->colorMap; 587 496 588 for ( int y = tile.top(); y <= tile.bottom(); y++ ) 497 589 { 498 590 const double ty = yMap.invTransform( y ); 499 591 500 QRgb *line = reinterpret_cast<QRgb *>( image->scanLine( y ) );592 QRgb* line = reinterpret_cast< QRgb* >( image->scanLine( y ) ); 501 593 line += tile.left(); 502 594 … … 505 597 const double tx = xMap.invTransform( x ); 506 598 507 *line++ = d_data->colorMap->rgb( range, 508 d_data->data->value( tx, ty ) ); 599 const double value = m_data->data->value( tx, ty ); 600 601 if ( hasGaps && qwtIsNaN( value ) ) 602 { 603 *line++ = 0u; 604 } 605 else if ( numColors == 0 ) 606 { 607 *line++ = colorMap->rgb( range, value ); 608 } 609 else 610 { 611 const uint index = colorMap->colorIndex( numColors, range, value ); 612 *line++ = rgbTable[index]; 613 } 509 614 } 510 615 } 511 616 } 512 else if ( d_data->colorMap->format() == QwtColorMap::Indexed )617 else if ( m_data->colorMap->format() == QwtColorMap::Indexed ) 513 618 { 514 619 for ( int y = tile.top(); y <= tile.bottom(); y++ ) … … 516 621 const double ty = yMap.invTransform( y ); 517 622 518 unsigned char *line = image->scanLine( y );623 unsigned char* line = image->scanLine( y ); 519 624 line += tile.left(); 520 625 … … 523 628 const double tx = xMap.invTransform( x ); 524 629 525 *line++ = d_data->colorMap->colorIndex( range, 526 d_data->data->value( tx, ty ) ); 630 const double value = m_data->data->value( tx, ty ); 631 632 if ( hasGaps && qwtIsNaN( value ) ) 633 { 634 *line++ = 0; 635 } 636 else 637 { 638 const uint index = m_data->colorMap->colorIndex( 256, range, value ); 639 *line++ = static_cast< unsigned char >( index ); 640 } 527 641 } 528 642 } … … 546 660 547 661 \sa drawContourLines(), QwtRasterData::contourLines() 548 */ 662 */ 549 663 QSize QwtPlotSpectrogram::contourRasterSize( 550 const QRectF &area, const QRect&rect ) const664 const QRectF& area, const QRect& rect ) const 551 665 { 552 666 QSize raster = rect.size() / 2; … … 555 669 if ( !pixelRect.isEmpty() ) 556 670 { 557 const QSize res( qCeil( rect.width() / pixelRect.width() ), 558 qCeil( rect.height() / pixelRect.height() ) ); 671 const QSize res( qwtCeil( rect.width() / pixelRect.width() ), 672 qwtCeil( rect.height() / pixelRect.height() ) ); 559 673 raster = raster.boundedTo( res ); 560 674 } … … 572 686 \sa contourLevels(), setConrecFlag(), 573 687 QwtRasterData::contourLines() 574 */ 688 */ 575 689 QwtRasterData::ContourLines QwtPlotSpectrogram::renderContourLines( 576 const QRectF &rect, const QSize&raster ) const577 { 578 if ( d_data->data == NULL )690 const QRectF& rect, const QSize& raster ) const 691 { 692 if ( m_data->data == NULL ) 579 693 return QwtRasterData::ContourLines(); 580 694 581 return d_data->data->contourLines( rect, raster,582 d_data->contourLevels,d_data->conrecFlags );695 return m_data->data->contourLines( rect, raster, 696 m_data->contourLevels, m_data->conrecFlags ); 583 697 } 584 698 … … 592 706 593 707 \sa renderContourLines(), defaultContourPen(), contourPen() 594 */ 595 void QwtPlotSpectrogram::drawContourLines( QPainter *painter,596 const QwtScaleMap&xMap, const QwtScaleMap&yMap,597 const QwtRasterData::ContourLines&contourLines ) const598 { 599 if ( d_data->data == NULL )708 */ 709 void QwtPlotSpectrogram::drawContourLines( QPainter* painter, 710 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 711 const QwtRasterData::ContourLines& contourLines ) const 712 { 713 if ( m_data->data == NULL ) 600 714 return; 601 715 602 const int numLevels = d_data->contourLevels.size();716 const int numLevels = m_data->contourLevels.size(); 603 717 for ( int l = 0; l < numLevels; l++ ) 604 718 { 605 const double level = d_data->contourLevels[l];719 const double level = m_data->contourLevels[l]; 606 720 607 721 QPen pen = defaultContourPen(); … … 614 728 painter->setPen( pen ); 615 729 616 const QPolygonF &lines = contourLines[level];730 const QPolygonF& lines = contourLines[level]; 617 731 for ( int i = 0; i < lines.size(); i += 2 ) 618 732 { 619 733 const QPointF p1( xMap.transform( lines[i].x() ), 620 734 yMap.transform( lines[i].y() ) ); 621 const QPointF p2( xMap.transform( lines[i +1].x() ),622 yMap.transform( lines[i +1].y() ) );735 const QPointF p2( xMap.transform( lines[i + 1].x() ), 736 yMap.transform( lines[i + 1].y() ) ); 623 737 624 738 QwtPainter::drawLine( painter, p1, p2 ); … … 628 742 629 743 /*! 630 \brief Draw the spectrogram 631 632 \param painter Painter 633 \param xMap Maps x-values into pixel coordinates. 634 \param yMap Maps y-values into pixel coordinates. 635 \param canvasRect Contents rectangle of the canvas in painter coordinates 636 637 \sa setDisplayMode(), renderImage(), 744 \brief Draw the spectrogram 745 746 \param painter Painter 747 \param xMap Maps x-values into pixel coordinates. 748 \param yMap Maps y-values into pixel coordinates. 749 \param canvasRect Contents rectangle of the canvas in painter coordinates 750 751 \sa setDisplayMode(), renderImage(), 638 752 QwtPlotRasterItem::draw(), drawContourLines() 639 */ 640 void QwtPlotSpectrogram::draw( QPainter *painter,641 const QwtScaleMap &xMap, const QwtScaleMap&yMap,642 const QRectF &canvasRect ) const643 { 644 if ( d_data->displayMode & ImageMode )753 */ 754 void QwtPlotSpectrogram::draw( QPainter* painter, 755 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 756 const QRectF& canvasRect ) const 757 { 758 if ( m_data->displayMode & ImageMode ) 645 759 QwtPlotRasterItem::draw( painter, xMap, yMap, canvasRect ); 646 760 647 if ( d_data->displayMode & ContourMode )761 if ( m_data->displayMode & ContourMode ) 648 762 { 649 763 // Add some pixels at the borders -
trunk/BNC/qwt/qwt_plot_spectrogram.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 14 14 #include "qwt_raster_data.h" 15 15 #include "qwt_plot_rasteritem.h" 16 #include <qlist.h>17 16 18 17 class QwtColorMap; 18 template< typename T > class QList; 19 19 20 20 /*! 21 \brief A plot item, which displays a spectrogram 21 \brief A plot item, which displays a spectrogram 22 22 23 A spectrogram displays 3-dimensional data, where the 3rd dimension 24 ( the intensity ) is displayed using colors. The colors are calculated 25 from the values using a color map. 23 A spectrogram displays 3-dimensional data, where the 3rd dimension 24 ( the intensity ) is displayed using colors. The colors are calculated 25 from the values using a color map. 26 26 27 On multi-core systems the performance of the image composition 28 can often be improved by dividing the area into tiles - each of them 29 rendered in a different thread ( see QwtPlotItem::setRenderThreadCount() ). 27 On multi-core systems the performance of the image composition 28 can often be improved by dividing the area into tiles - each of them 29 rendered in a different thread ( see QwtPlotItem::setRenderThreadCount() ). 30 30 31 In ContourMode contour lines are painted for the contour levels. 31 In ContourMode contour lines are painted for the contour levels. 32 32 33 \image html spectrogram3.png 33 \sa QwtRasterData, QwtColorMap, QwtPlotItem::setRenderThreadCount() 34 */ 34 35 35 \sa QwtRasterData, QwtColorMap, QwtPlotItem::setRenderThreadCount() 36 */ 37 38 class QWT_EXPORT QwtPlotSpectrogram: public QwtPlotRasterItem 36 class QWT_EXPORT QwtPlotSpectrogram : public QwtPlotRasterItem 39 37 { 40 public: 38 public: 41 39 /*! 42 The display mode controls how the raster data will be represented. 43 \sa setDisplayMode(), testDisplayMode() 44 */ 40 The display mode controls how the raster data will be represented. 41 \sa setDisplayMode(), testDisplayMode() 42 */ 45 43 46 44 enum DisplayMode … … 53 51 }; 54 52 55 //! Display modes 56 typedef QFlags<DisplayMode> DisplayModes; 53 Q_DECLARE_FLAGS( DisplayModes, DisplayMode ) 57 54 58 explicit QwtPlotSpectrogram( const QString &title = QString() );55 explicit QwtPlotSpectrogram( const QString& title = QString() ); 59 56 virtual ~QwtPlotSpectrogram(); 60 57 … … 62 59 bool testDisplayMode( DisplayMode ) const; 63 60 64 void setData( QwtRasterData *data );65 const QwtRasterData *data() const;66 QwtRasterData *data();61 void setData( QwtRasterData* data ); 62 const QwtRasterData* data() const; 63 QwtRasterData* data(); 67 64 68 void setColorMap( QwtColorMap * );69 const QwtColorMap *colorMap() const;65 void setColorMap( QwtColorMap* ); 66 const QwtColorMap* colorMap() const; 70 67 71 v irtual QwtInterval interval(Qt::Axis) const;72 virtual QRectF pixelHint( const QRectF &) const;68 void setColorTableSize( int numColors ); 69 int colorTableSize() const; 73 70 74 void setDefaultContourPen( const QColor &, 71 virtual QwtInterval interval( Qt::Axis ) const QWT_OVERRIDE; 72 virtual QRectF pixelHint( const QRectF& ) const QWT_OVERRIDE; 73 74 void setDefaultContourPen( const QColor&, 75 75 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 76 void setDefaultContourPen( const QPen & );76 void setDefaultContourPen( const QPen& ); 77 77 QPen defaultContourPen() const; 78 78 … … 82 82 bool testConrecFlag( QwtRasterData::ConrecFlag ) const; 83 83 84 void setContourLevels( const QList< double>& );85 QList< double> contourLevels() const;84 void setContourLevels( const QList< double >& ); 85 QList< double > contourLevels() const; 86 86 87 virtual int rtti() const; 87 virtual int rtti() const QWT_OVERRIDE; 88 88 89 virtual void draw( QPainter *,90 const QwtScaleMap &xMap, const QwtScaleMap&yMap,91 const QRectF &canvasRect ) const;89 virtual void draw( QPainter*, 90 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 91 const QRectF& canvasRect ) const QWT_OVERRIDE; 92 92 93 protected: 93 protected: 94 94 virtual QImage renderImage( 95 const QwtScaleMap &xMap, const QwtScaleMap&yMap,96 const QRectF &area, const QSize&imageSize ) const;95 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 96 const QRectF& area, const QSize& imageSize ) const QWT_OVERRIDE; 97 97 98 98 virtual QSize contourRasterSize( 99 const QRectF &, const QRect& ) const;99 const QRectF&, const QRect& ) const; 100 100 101 101 virtual QwtRasterData::ContourLines renderContourLines( 102 const QRectF &rect, const QSize&raster ) const;102 const QRectF& rect, const QSize& raster ) const; 103 103 104 virtual void drawContourLines( QPainter *,105 const QwtScaleMap &xMap, const QwtScaleMap&yMap,104 virtual void drawContourLines( QPainter*, 105 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 106 106 const QwtRasterData::ContourLines& ) const; 107 107 108 void renderTile( const QwtScaleMap &xMap, const QwtScaleMap&yMap,109 const QRect &tile, QImage* ) const;108 void renderTile( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 109 const QRect& tile, QImage* ) const; 110 110 111 private: 111 private: 112 112 class PrivateData; 113 PrivateData *d_data;113 PrivateData* m_data; 114 114 }; 115 115 -
trunk/BNC/qwt/qwt_plot_svgitem.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_plot_svgitem.h" 11 #include "qwt_ scale_map.h"12 #include "qwt_ painter.h"13 #include <qpainter.h> 11 #include "qwt_text.h" 12 #include "qwt_graphic.h" 13 14 14 #include <qsvgrenderer.h> 15 16 class QwtPlotSvgItem::PrivateData17 {18 public:19 PrivateData()20 {21 }22 23 QRectF boundingRect;24 QSvgRenderer renderer;25 };26 15 27 16 /*! 28 17 \brief Constructor 29 30 Sets the following item attributes:31 - QwtPlotItem::AutoScale: true32 - QwtPlotItem::Legend: false33 34 18 \param title Title 35 */ 36 QwtPlotSvgItem::QwtPlotSvgItem( const QString& title ) :37 QwtPlotItem( QwtText( title ) )19 */ 20 QwtPlotSvgItem::QwtPlotSvgItem( const QString& title ) 21 : QwtPlotGraphicItem( QwtText( title ) ) 38 22 { 39 init();40 23 } 41 24 42 25 /*! 43 26 \brief Constructor 44 45 Sets the following item attributes:46 - QwtPlotItem::AutoScale: true47 - QwtPlotItem::Legend: false48 49 27 \param title Title 50 */ 51 QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title ) :52 QwtPlotItem( title )28 */ 29 QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title ) 30 : QwtPlotGraphicItem( title ) 53 31 { 54 init();55 32 } 56 33 … … 58 35 QwtPlotSvgItem::~QwtPlotSvgItem() 59 36 { 60 delete d_data;61 }62 63 void QwtPlotSvgItem::init()64 {65 d_data = new PrivateData();66 d_data->boundingRect = QwtPlotItem::boundingRect();67 68 setItemAttribute( QwtPlotItem::AutoScale, true );69 setItemAttribute( QwtPlotItem::Legend, false );70 71 setZ( 8.0 );72 }73 74 //! \return QwtPlotItem::Rtti_PlotSVG75 int QwtPlotSvgItem::rtti() const76 {77 return QwtPlotItem::Rtti_PlotSVG;78 37 } 79 38 … … 85 44 86 45 \return true, if the SVG file could be loaded 87 */ 88 bool QwtPlotSvgItem::loadFile( const QRectF &rect,89 const QString &fileName )46 */ 47 bool QwtPlotSvgItem::loadFile( const QRectF& rect, 48 const QString& fileName ) 90 49 { 91 d_data->boundingRect = rect; 92 const bool ok = d_data->renderer.load( fileName ); 50 QwtGraphic graphic; 93 51 94 legendChanged(); 95 itemChanged(); 52 QSvgRenderer renderer; 53 54 const bool ok = renderer.load( fileName ); 55 if ( ok ) 56 { 57 QPainter p( &graphic ); 58 renderer.render( &p ); 59 } 60 61 setGraphic( rect, graphic ); 96 62 97 63 return ok; … … 105 71 106 72 \return true, if the SVG data could be loaded 107 */ 108 bool QwtPlotSvgItem::loadData( const QRectF &rect,109 const QByteArray &data )73 */ 74 bool QwtPlotSvgItem::loadData( const QRectF& rect, 75 const QByteArray& data ) 110 76 { 111 d_data->boundingRect = rect; 112 const bool ok = d_data->renderer.load( data ); 77 QwtGraphic graphic; 113 78 114 legendChanged(); 115 itemChanged(); 79 QSvgRenderer renderer; 80 81 const bool ok = renderer.load( data ); 82 if ( ok ) 83 { 84 QPainter p( &graphic ); 85 renderer.render( &p ); 86 } 87 88 setGraphic( rect, graphic ); 116 89 117 90 return ok; 118 91 } 119 120 //! Bounding rectangle of the item121 QRectF QwtPlotSvgItem::boundingRect() const122 {123 return d_data->boundingRect;124 }125 126 //! \return Renderer used to render the SVG data127 const QSvgRenderer &QwtPlotSvgItem::renderer() const128 {129 return d_data->renderer;130 }131 132 //! \return Renderer used to render the SVG data133 QSvgRenderer &QwtPlotSvgItem::renderer()134 {135 return d_data->renderer;136 }137 138 /*!139 Draw the SVG item140 141 \param painter Painter142 \param xMap X-Scale Map143 \param yMap Y-Scale Map144 \param canvasRect Contents rect of the plot canvas145 */146 void QwtPlotSvgItem::draw( QPainter *painter,147 const QwtScaleMap &xMap, const QwtScaleMap &yMap,148 const QRectF &canvasRect ) const149 {150 const QRectF cRect = QwtScaleMap::invTransform(151 xMap, yMap, canvasRect.toRect() );152 const QRectF bRect = boundingRect();153 if ( bRect.isValid() && cRect.isValid() )154 {155 QRectF rect = bRect;156 if ( bRect.contains( cRect ) )157 rect = cRect;158 159 const QRectF r = QwtScaleMap::transform( xMap, yMap, rect );160 render( painter, viewBox( rect ), r );161 }162 }163 164 /*!165 Render the SVG data166 167 \param painter Painter168 \param viewBox View Box, see QSvgRenderer::viewBox()169 \param rect Target rectangle on the paint device170 */171 void QwtPlotSvgItem::render( QPainter *painter,172 const QRectF &viewBox, const QRectF &rect ) const173 {174 if ( !viewBox.isValid() )175 return;176 177 QRectF r = rect;178 179 if ( QwtPainter::roundingAlignment( painter ) )180 {181 r.setLeft ( qRound( r.left() ) );182 r.setRight ( qRound( r.right() ) );183 r.setTop ( qRound( r.top() ) );184 r.setBottom ( qRound( r.bottom() ) );185 }186 187 d_data->renderer.setViewBox( viewBox );188 d_data->renderer.render( painter, r );189 }190 191 /*!192 Calculate the view box from rect and boundingRect().193 194 \param rect Rectangle in scale coordinates195 \return View box, see QSvgRenderer::viewBox()196 */197 QRectF QwtPlotSvgItem::viewBox( const QRectF &rect ) const198 {199 const QSize sz = d_data->renderer.defaultSize();200 const QRectF br = boundingRect();201 202 if ( !rect.isValid() || !br.isValid() || sz.isNull() )203 return QRectF();204 205 QwtScaleMap xMap;206 xMap.setScaleInterval( br.left(), br.right() );207 xMap.setPaintInterval( 0, sz.width() );208 209 QwtScaleMap yMap;210 yMap.setScaleInterval( br.top(), br.bottom() );211 yMap.setPaintInterval( sz.height(), 0 );212 213 const double x1 = xMap.transform( rect.left() );214 const double x2 = xMap.transform( rect.right() );215 const double y1 = yMap.transform( rect.bottom() );216 const double y2 = yMap.transform( rect.top() );217 218 return QRectF( x1, y1, x2 - x1, y2 - y1 );219 } -
trunk/BNC/qwt/qwt_plot_svgitem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 8 8 *****************************************************************************/ 9 9 10 #ifndef QWT_PLOT_SVGITEM_H 11 #define QWT_PLOT_SVGITEM_H 10 #ifndef QWT_PLOT_SVG_ITEM_H 11 #define QWT_PLOT_SVG_ITEM_H 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_plot_item.h" 15 #include <qstring.h> 14 #include "qwt_plot_graphicitem.h" 16 15 17 class QSvgRenderer;18 16 class QByteArray; 19 17 20 18 /*! 21 \brief A plot item, which displays 19 \brief A plot item, which displays 22 20 data in Scalable Vector Graphics (SVG) format. 23 21 24 SVG images are often used to display maps 25 */ 22 SVG images are often used to display maps 26 23 27 class QWT_EXPORT QwtPlotSvgItem: public QwtPlotItem 24 QwtPlotSvgItem is only a small convenience wrapper class for 25 QwtPlotGraphicItem, that creates a QwtGraphic from SVG data. 26 */ 27 28 class QWT_EXPORT QwtPlotSvgItem : public QwtPlotGraphicItem 28 29 { 29 public: 30 public: 30 31 explicit QwtPlotSvgItem( const QString& title = QString() ); 31 32 explicit QwtPlotSvgItem( const QwtText& title ); 32 33 virtual ~QwtPlotSvgItem(); 33 34 34 bool loadFile( const QRectF&, const QString &fileName ); 35 bool loadData( const QRectF&, const QByteArray & ); 36 37 virtual QRectF boundingRect() const; 38 39 virtual void draw( QPainter *, 40 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 41 const QRectF &canvasRect ) const; 42 43 virtual int rtti() const; 44 45 protected: 46 const QSvgRenderer &renderer() const; 47 QSvgRenderer &renderer(); 48 49 void render( QPainter *, 50 const QRectF &viewBox, const QRectF &rect ) const; 51 52 QRectF viewBox( const QRectF &rect ) const; 53 54 private: 55 void init(); 56 57 class PrivateData; 58 PrivateData *d_data; 35 bool loadFile( const QRectF&, const QString& fileName ); 36 bool loadData( const QRectF&, const QByteArray& ); 59 37 }; 60 38 -
trunk/BNC/qwt/qwt_plot_textlabel.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_textlabel.h" 11 11 #include "qwt_painter.h" 12 #include "qwt_scale_map.h" 12 #include "qwt_text.h" 13 #include "qwt_math.h" 14 13 15 #include <qpainter.h> 16 #include <qpaintengine.h> 14 17 #include <qpixmap.h> 15 #include <qmath.h>16 18 17 19 static QRect qwtItemRect( int renderFlags, 18 const QRectF &rect, const QSizeF&itemSize )20 const QRectF& rect, const QSizeF& itemSize ) 19 21 { 20 22 int x; … … 51 53 class QwtPlotTextLabel::PrivateData 52 54 { 53 public: 54 PrivateData() :55 margin( 5 ) 55 public: 56 PrivateData() 57 : margin( 5 ) 56 58 { 57 59 } … … 76 78 77 79 \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ() 78 */ 79 80 QwtPlotTextLabel::QwtPlotTextLabel() :81 QwtPlotItem( QwtText( "Label" ) ) 82 { 83 d_data = new PrivateData;80 */ 81 82 QwtPlotTextLabel::QwtPlotTextLabel() 83 : QwtPlotItem( QwtText( "Label" ) ) 84 { 85 m_data = new PrivateData; 84 86 85 87 setItemAttribute( QwtPlotItem::AutoScale, false ); … … 92 94 QwtPlotTextLabel::~QwtPlotTextLabel() 93 95 { 94 delete d_data;96 delete m_data; 95 97 } 96 98 … … 102 104 103 105 /*! 104 Set the text 105 106 The label will be aligned to the plot canvas according to 107 the alignment flags of text. 108 109 \param text Text to be displayed 110 111 \sa text(), QwtText::renderFlags() 112 */ 113 void QwtPlotTextLabel::setText( const QwtText &text )114 { 115 if ( d_data->text != text )116 { 117 d_data->text = text;106 Set the text 107 108 The label will be aligned to the plot canvas according to 109 the alignment flags of text. 110 111 \param text Text to be displayed 112 113 \sa text(), QwtText::renderFlags() 114 */ 115 void QwtPlotTextLabel::setText( const QwtText& text ) 116 { 117 if ( m_data->text != text ) 118 { 119 m_data->text = text; 118 120 119 121 invalidateCache(); … … 123 125 124 126 /*! 125 \return Text to be displayed 126 \sa setText() 127 */ 127 \return Text to be displayed 128 \sa setText() 129 */ 128 130 QwtText QwtPlotTextLabel::text() const 129 131 { 130 return d_data->text;131 } 132 133 /*! 134 Set the margin 135 136 The margin is the distance between the contentsRect() 137 of the plot canvas and the rectangle where the label can 138 be displayed. 139 140 \param margin Margin 141 142 \sa margin(), textRect() 132 return m_data->text; 133 } 134 135 /*! 136 Set the margin 137 138 The margin is the distance between the contentsRect() 139 of the plot canvas and the rectangle where the label can 140 be displayed. 141 142 \param margin Margin 143 144 \sa margin(), textRect() 143 145 */ 144 146 void QwtPlotTextLabel::setMargin( int margin ) 145 147 { 146 148 margin = qMax( margin, 0 ); 147 if ( d_data->margin != margin )148 { 149 d_data->margin = margin;149 if ( m_data->margin != margin ) 150 { 151 m_data->margin = margin; 150 152 itemChanged(); 151 153 } … … 153 155 154 156 /*! 155 \return Margin added to the contentsMargins() of the canvas 156 \sa setMargin() 157 */ 157 \return Margin added to the contentsMargins() of the canvas 158 \sa setMargin() 159 */ 158 160 int QwtPlotTextLabel::margin() const 159 161 { 160 return d_data->margin;161 } 162 163 /*! 164 Draw the text label 165 166 \param painter Painter 167 \param xMap x Scale Map 168 \param yMap y Scale Map 169 \param canvasRect Contents rectangle of the canvas in painter coordinates 170 171 \sa textRect() 172 */ 173 174 void QwtPlotTextLabel::draw( QPainter *painter,175 const QwtScaleMap &xMap, const QwtScaleMap&yMap,176 const QRectF &canvasRect ) const162 return m_data->margin; 163 } 164 165 /*! 166 Draw the text label 167 168 \param painter Painter 169 \param xMap x Scale Map 170 \param yMap y Scale Map 171 \param canvasRect Contents rectangle of the canvas in painter coordinates 172 173 \sa textRect() 174 */ 175 176 void QwtPlotTextLabel::draw( QPainter* painter, 177 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 178 const QRectF& canvasRect ) const 177 179 { 178 180 Q_UNUSED( xMap ); 179 181 Q_UNUSED( yMap ); 180 182 181 const int m = d_data->margin;183 const int m = m_data->margin; 182 184 183 185 const QRectF rect = textRect( canvasRect.adjusted( m, m, -m, -m ), 184 d_data->text.textSize( painter->font() ) );186 m_data->text.textSize( painter->font() ) ); 185 187 186 188 bool doCache = QwtPainter::roundingAlignment( painter ); … … 208 210 209 211 int pw = 0; 210 if ( d_data->text.borderPen().style() != Qt::NoPen )211 pw = qMax( d_data->text.borderPen().width(), 1 );212 if ( m_data->text.borderPen().style() != Qt::NoPen ) 213 pw = qMax( m_data->text.borderPen().width(), 1 ); 212 214 213 215 QRect pixmapRect; 214 pixmapRect.setLeft( qFloor( rect.left() ) - pw ); 215 pixmapRect.setTop( qFloor( rect.top() ) - pw ); 216 pixmapRect.setRight( qCeil( rect.right() ) + pw ); 217 pixmapRect.setBottom( qCeil( rect.bottom() ) + pw ); 218 219 #define QWT_HIGH_DPI 1 220 221 #if QT_VERSION >= 0x050100 && QWT_HIGH_DPI 222 const qreal pixelRatio = painter->device()->devicePixelRatio(); 216 pixmapRect.setLeft( qwtFloor( rect.left() ) - pw ); 217 pixmapRect.setTop( qwtFloor( rect.top() ) - pw ); 218 pixmapRect.setRight( qwtCeil( rect.right() ) + pw ); 219 pixmapRect.setBottom( qwtCeil( rect.bottom() ) + pw ); 220 221 #if QT_VERSION >= 0x050000 222 const qreal pixelRatio = QwtPainter::devicePixelRatio( painter->device() ); 223 223 const QSize scaledSize = pixmapRect.size() * pixelRatio; 224 224 #else 225 225 const QSize scaledSize = pixmapRect.size(); 226 226 #endif 227 if ( d_data->pixmap.isNull() || 228 ( scaledSize != d_data->pixmap.size() ) ) 227 228 if ( m_data->pixmap.isNull() || 229 ( scaledSize != m_data->pixmap.size() ) ) 229 230 { 230 d_data->pixmap = QPixmap( scaledSize );231 #if QT_VERSION >= 0x050 100 && QWT_HIGH_DPI232 d_data->pixmap.setDevicePixelRatio( pixelRatio );231 m_data->pixmap = QPixmap( scaledSize ); 232 #if QT_VERSION >= 0x050000 233 m_data->pixmap.setDevicePixelRatio( pixelRatio ); 233 234 #endif 234 d_data->pixmap.fill( Qt::transparent );235 m_data->pixmap.fill( Qt::transparent ); 235 236 236 237 const QRect r( pw, pw, 237 238 pixmapRect.width() - 2 * pw, pixmapRect.height() - 2 * pw ); 238 239 239 QPainter pmPainter( & d_data->pixmap );240 d_data->text.draw( &pmPainter, r );240 QPainter pmPainter( &m_data->pixmap ); 241 m_data->text.draw( &pmPainter, r ); 241 242 } 242 243 243 painter->drawPixmap( pixmapRect, d_data->pixmap );244 painter->drawPixmap( pixmapRect, m_data->pixmap ); 244 245 } 245 246 else 246 247 { 247 d_data->text.draw( painter, rect );248 m_data->text.draw( painter, rect ); 248 249 } 249 250 } … … 261 262 */ 262 263 QRectF QwtPlotTextLabel::textRect( 263 const QRectF &rect, const QSizeF&textSize ) const264 { 265 return qwtItemRect( d_data->text.renderFlags(), rect, textSize );264 const QRectF& rect, const QSizeF& textSize ) const 265 { 266 return qwtItemRect( m_data->text.renderFlags(), rect, textSize ); 266 267 } 267 268 … … 269 270 void QwtPlotTextLabel::invalidateCache() 270 271 { 271 d_data->pixmap = QPixmap();272 } 272 m_data->pixmap = QPixmap(); 273 } -
trunk/BNC/qwt/qwt_plot_textlabel.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_PLOT_TEXT_LABEL_H 11 #define QWT_PLOT_TEXT_LABEL_H 111 #define QWT_PLOT_TEXT_LABEL_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include "qwt_text.h" 15 16 class QwtText; 16 17 17 18 /*! 18 \brief A plot item, which displays a text label 19 \brief A plot item, which displays a text label 19 20 20 QwtPlotTextLabel displays a text label aligned to the plot canvas. 21 QwtPlotTextLabel displays a text label aligned to the plot canvas. 21 22 22 In opposite to QwtPlotMarker the position of the label is unrelated to 23 plot coordinates. 23 In opposite to QwtPlotMarker the position of the label is unrelated to 24 plot coordinates. 24 25 25 As drawing a text is an expensive operation the label is cached 26 in a pixmap to speed up replots. 26 As drawing a text is an expensive operation the label is cached 27 in a pixmap to speed up replots. 27 28 28 \par Example 29 \par Example 29 30 The following code shows how to add a title. 30 31 \code … … 40 41 titleItem->attach( plot ); 41 42 \endcode 42 \endpar43 43 44 \sa QwtPlotMarker 45 */ 44 \sa QwtPlotMarker 45 */ 46 46 47 class QWT_EXPORT QwtPlotTextLabel: public QwtPlotItem 47 class QWT_EXPORT QwtPlotTextLabel : public QwtPlotItem 48 48 { 49 public: 49 public: 50 50 QwtPlotTextLabel(); 51 51 virtual ~QwtPlotTextLabel(); 52 52 53 virtual int rtti() const; 53 virtual int rtti() const QWT_OVERRIDE; 54 54 55 void setText( const QwtText & );55 void setText( const QwtText& ); 56 56 QwtText text() const; 57 57 … … 59 59 int margin() const; 60 60 61 virtual QRectF textRect( const QRectF &, const QSizeF& ) const;61 virtual QRectF textRect( const QRectF&, const QSizeF& ) const; 62 62 63 protected: 64 virtual void draw( QPainter *,65 const QwtScaleMap &, const QwtScaleMap&,66 const QRectF &) const;63 protected: 64 virtual void draw( QPainter*, 65 const QwtScaleMap&, const QwtScaleMap&, 66 const QRectF&) const QWT_OVERRIDE; 67 67 68 68 void invalidateCache(); 69 69 70 private: 70 private: 71 71 class PrivateData; 72 PrivateData *d_data;72 PrivateData* m_data; 73 73 }; 74 74 -
trunk/BNC/qwt/qwt_plot_tradingcurve.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_tradingcurve.h" 11 11 #include "qwt_scale_map.h" 12 #include "qwt_clipper.h"13 12 #include "qwt_painter.h" 13 #include "qwt_text.h" 14 #include "qwt_graphic.h" 15 #include "qwt_math.h" 16 14 17 #include <qpainter.h> 15 18 16 static inline bool qwtIsSampleInside( const QwtOHLCSample &sample,19 static inline bool qwtIsSampleInside( const QwtOHLCSample& sample, 17 20 double tMin, double tMax, double vMin, double vMax ) 18 21 { … … 28 31 class QwtPlotTradingCurve::PrivateData 29 32 { 30 public: 31 PrivateData() :32 symbolStyle( QwtPlotTradingCurve::CandleStick ) ,33 symbolExtent( 0.6 ) ,34 minSymbolWidth( 2.0 ) ,35 maxSymbolWidth( -1.0 ) ,36 paintAttributes( QwtPlotTradingCurve::ClipSymbols ) 33 public: 34 PrivateData() 35 : symbolStyle( QwtPlotTradingCurve::CandleStick ) 36 , symbolExtent( 0.6 ) 37 , minSymbolWidth( 2.0 ) 38 , maxSymbolWidth( -1.0 ) 39 , paintAttributes( QwtPlotTradingCurve::ClipSymbols ) 37 40 { 38 41 symbolBrush[0] = QBrush( Qt::white ); … … 52 55 53 56 /*! 54 Constructor 55 \param title Title of the curve 56 */ 57 QwtPlotTradingCurve::QwtPlotTradingCurve( const QwtText &title ):58 QwtPlotSeriesItem( title ) 57 Constructor 58 \param title Title of the curve 59 */ 60 QwtPlotTradingCurve::QwtPlotTradingCurve( const QwtText& title ) 61 : QwtPlotSeriesItem( title ) 59 62 { 60 63 init(); … … 62 65 63 66 /*! 64 Constructor 65 \param title Title of the curve 66 */ 67 QwtPlotTradingCurve::QwtPlotTradingCurve( const QString &title ):68 QwtPlotSeriesItem( QwtText( title ) ) 67 Constructor 68 \param title Title of the curve 69 */ 70 QwtPlotTradingCurve::QwtPlotTradingCurve( const QString& title ) 71 : QwtPlotSeriesItem( QwtText( title ) ) 69 72 { 70 73 init(); … … 74 77 QwtPlotTradingCurve::~QwtPlotTradingCurve() 75 78 { 76 delete d_data;79 delete m_data; 77 80 } 78 81 … … 83 86 setItemAttribute( QwtPlotItem::AutoScale, true ); 84 87 85 d_data = new PrivateData;88 m_data = new PrivateData; 86 89 setData( new QwtTradingChartData() ); 87 90 … … 96 99 97 100 /*! 98 Specify an attribute how to draw the curve 99 100 \param attribute Paint attribute 101 \param on On/Off 102 \sa testPaintAttribute() 103 */ 101 Specify an attribute how to draw the curve 102 103 \param attribute Paint attribute 104 \param on On/Off 105 \sa testPaintAttribute() 106 */ 104 107 void QwtPlotTradingCurve::setPaintAttribute( 105 108 PaintAttribute attribute, bool on ) 106 109 { 107 110 if ( on ) 108 d_data->paintAttributes |= attribute;111 m_data->paintAttributes |= attribute; 109 112 else 110 d_data->paintAttributes &= ~attribute;113 m_data->paintAttributes &= ~attribute; 111 114 } 112 115 … … 114 117 \return True, when attribute is enabled 115 118 \sa PaintAttribute, setPaintAttribute() 116 */ 119 */ 117 120 bool QwtPlotTradingCurve::testPaintAttribute( 118 121 PaintAttribute attribute ) const 119 122 { 120 return ( d_data->paintAttributes & attribute );121 } 122 123 /*! 124 Initialize data with an array of samples. 125 \param samples Vector of samples 126 127 \sa QwtPlotSeriesItem::setData() 128 */ 123 return ( m_data->paintAttributes & attribute ); 124 } 125 126 /*! 127 Initialize data with an array of samples. 128 \param samples Vector of samples 129 130 \sa QwtPlotSeriesItem::setData() 131 */ 129 132 void QwtPlotTradingCurve::setSamples( 130 const QVector<QwtOHLCSample > &samples )133 const QVector< QwtOHLCSample >& samples ) 131 134 { 132 135 setData( new QwtTradingChartData( samples ) ); … … 134 137 135 138 /*! 136 Assign a series of samples 137 138 setSamples() is just a wrapper for setData() without any additional 139 value - beside that it is easier to find for the developer. 140 141 \param data Data 142 \warning The item takes ownership of the data object, deleting 139 Assign a series of samples 140 141 setSamples() is just a wrapper for setData() without any additional 142 value - beside that it is easier to find for the developer. 143 144 \param data Data 145 \warning The item takes ownership of the data object, deleting 143 146 it when its not used anymore. 144 */ 147 */ 145 148 void QwtPlotTradingCurve::setSamples( 146 QwtSeriesData<QwtOHLCSample > *data )149 QwtSeriesData< QwtOHLCSample >* data ) 147 150 { 148 151 setData( data ); … … 150 153 151 154 /*! 152 Set the symbol style 153 154 \param style Symbol style 155 156 \sa symbolStyle(), setSymbolExtent(), 155 Set the symbol style 156 157 \param style Symbol style 158 159 \sa symbolStyle(), setSymbolExtent(), 157 160 setSymbolPen(), setSymbolBrush() 158 */ 161 */ 159 162 void QwtPlotTradingCurve::setSymbolStyle( SymbolStyle style ) 160 163 { 161 if ( style != d_data->symbolStyle )162 { 163 d_data->symbolStyle = style;164 if ( style != m_data->symbolStyle ) 165 { 166 m_data->symbolStyle = style; 164 167 165 168 legendChanged(); … … 169 172 170 173 /*! 171 \return Symbol style 172 \sa setSymbolStyle(), symbolExtent(), symbolPen(), symbolBrush() 173 */ 174 \return Symbol style 175 \sa setSymbolStyle(), symbolExtent(), symbolPen(), symbolBrush() 176 */ 174 177 QwtPlotTradingCurve::SymbolStyle QwtPlotTradingCurve::symbolStyle() const 175 178 { 176 return d_data->symbolStyle;177 } 178 179 /*! 180 Build and assign the symbol pen 181 182 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 183 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 184 to hide this incompatibility. 185 186 \param color Pen color 187 \param width Pen width 188 \param style Pen style 189 190 \sa pen(), brush() 179 return m_data->symbolStyle; 180 } 181 182 /*! 183 Build and assign the symbol pen 184 185 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 186 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 187 to hide this incompatibility. 188 189 \param color Pen color 190 \param width Pen width 191 \param style Pen style 192 193 \sa pen(), brush() 191 194 */ 192 195 void QwtPlotTradingCurve::setSymbolPen( 193 const QColor &color, qreal width, Qt::PenStyle style )196 const QColor& color, qreal width, Qt::PenStyle style ) 194 197 { 195 198 setSymbolPen( QPen( color, width, style ) ); … … 197 200 198 201 /*! 199 \brief Set the symbol pen 200 201 The symbol pen is used for rendering the lines of the 202 bar or candlestick symbols 203 204 \sa symbolPen(), setSymbolBrush() 205 */ 206 void QwtPlotTradingCurve::setSymbolPen( const QPen &pen )207 { 208 if ( pen != d_data->symbolPen )209 { 210 d_data->symbolPen = pen;202 \brief Set the symbol pen 203 204 The symbol pen is used for rendering the lines of the 205 bar or candlestick symbols 206 207 \sa symbolPen(), setSymbolBrush() 208 */ 209 void QwtPlotTradingCurve::setSymbolPen( const QPen& pen ) 210 { 211 if ( pen != m_data->symbolPen ) 212 { 213 m_data->symbolPen = pen; 211 214 212 215 legendChanged(); … … 216 219 217 220 /*! 218 \return Symbol pen 219 \sa setSymbolPen(), symbolBrush() 220 */ 221 \return Symbol pen 222 \sa setSymbolPen(), symbolBrush() 223 */ 221 224 QPen QwtPlotTradingCurve::symbolPen() const 222 225 { 223 return d_data->symbolPen;224 } 225 226 /*! 227 Set the symbol brush 228 229 \param direction Direction type 230 \param brush Brush used to fill the body of all candlestick 226 return m_data->symbolPen; 227 } 228 229 /*! 230 Set the symbol brush 231 232 \param direction Direction type 233 \param brush Brush used to fill the body of all candlestick 231 234 symbols with the direction 232 235 233 \sa symbolBrush(), setSymbolPen() 234 */ 236 \sa symbolBrush(), setSymbolPen() 237 */ 235 238 void QwtPlotTradingCurve::setSymbolBrush( 236 Direction direction, const QBrush &brush )239 Direction direction, const QBrush& brush ) 237 240 { 238 241 // silencing -Wtautological-constant-out-of-range-compare … … 241 244 return; 242 245 243 if ( brush != d_data->symbolBrush[ index ] )244 { 245 d_data->symbolBrush[ index ] = brush;246 if ( brush != m_data->symbolBrush[ index ] ) 247 { 248 m_data->symbolBrush[ index ] = brush; 246 249 247 250 legendChanged(); … … 251 254 252 255 /*! 253 \param direction 254 \return Brush used to fill the body of all candlestick 256 \param direction 257 \return Brush used to fill the body of all candlestick 255 258 symbols with the direction 256 259 257 \sa setSymbolPen(), symbolBrush() 258 */ 260 \sa setSymbolPen(), symbolBrush() 261 */ 259 262 QBrush QwtPlotTradingCurve::symbolBrush( Direction direction ) const 260 263 { … … 263 266 return QBrush(); 264 267 265 return d_data->symbolBrush[ index ];266 } 267 268 /*! 269 \brief Set the extent of the symbol 270 271 The width of the symbol is given in scale coordinates. When painting 272 a symbol the width is scaled into paint device coordinates 273 by scaledSymbolWidth(). The scaled width is bounded by 274 minSymbolWidth(), maxSymbolWidth() 275 276 \param extent Symbol width in scale coordinates 277 278 \sa symbolExtent(), scaledSymbolWidth(), 268 return m_data->symbolBrush[ index ]; 269 } 270 271 /*! 272 \brief Set the extent of the symbol 273 274 The width of the symbol is given in scale coordinates. When painting 275 a symbol the width is scaled into paint device coordinates 276 by scaledSymbolWidth(). The scaled width is bounded by 277 minSymbolWidth(), maxSymbolWidth() 278 279 \param extent Symbol width in scale coordinates 280 281 \sa symbolExtent(), scaledSymbolWidth(), 279 282 setMinSymbolWidth(), setMaxSymbolWidth() 280 */ 283 */ 281 284 void QwtPlotTradingCurve::setSymbolExtent( double extent ) 282 285 { 283 extent = q Max( 0.0, extent );284 if ( extent != d_data->symbolExtent )285 { 286 d_data->symbolExtent = extent;286 extent = qwtMaxF( 0.0, extent ); 287 if ( extent != m_data->symbolExtent ) 288 { 289 m_data->symbolExtent = extent; 287 290 288 291 legendChanged(); … … 292 295 293 296 /*! 294 \return Extent of a symbol in scale coordinates 295 \sa setSymbolExtent(), scaledSymbolWidth(), 297 \return Extent of a symbol in scale coordinates 298 \sa setSymbolExtent(), scaledSymbolWidth(), 296 299 minSymbolWidth(), maxSymbolWidth() 297 */ 300 */ 298 301 double QwtPlotTradingCurve::symbolExtent() const 299 302 { 300 return d_data->symbolExtent;301 } 302 303 /*! 304 Set a minimum for the symbol width 305 306 \param width Width in paint device coordinates 307 \sa minSymbolWidth(), setMaxSymbolWidth(), setSymbolExtent() 303 return m_data->symbolExtent; 304 } 305 306 /*! 307 Set a minimum for the symbol width 308 309 \param width Width in paint device coordinates 310 \sa minSymbolWidth(), setMaxSymbolWidth(), setSymbolExtent() 308 311 */ 309 312 void QwtPlotTradingCurve::setMinSymbolWidth( double width ) 310 313 { 311 width = q Max( width, 0.0 );312 if ( width != d_data->minSymbolWidth )313 { 314 d_data->minSymbolWidth = width;314 width = qwtMaxF( width, 0.0 ); 315 if ( width != m_data->minSymbolWidth ) 316 { 317 m_data->minSymbolWidth = width; 315 318 316 319 legendChanged(); … … 320 323 321 324 /*! 322 \return Minmum for the symbol width 323 \sa setMinSymbolWidth(), maxSymbolWidth(), symbolExtent() 325 \return Minmum for the symbol width 326 \sa setMinSymbolWidth(), maxSymbolWidth(), symbolExtent() 324 327 */ 325 328 double QwtPlotTradingCurve::minSymbolWidth() const 326 329 { 327 return d_data->minSymbolWidth;328 } 329 330 /*! 331 Set a maximum for the symbol width 332 333 A value <= 0.0 means an unlimited width 334 335 \param width Width in paint device coordinates 336 \sa maxSymbolWidth(), setMinSymbolWidth(), setSymbolExtent() 330 return m_data->minSymbolWidth; 331 } 332 333 /*! 334 Set a maximum for the symbol width 335 336 A value <= 0.0 means an unlimited width 337 338 \param width Width in paint device coordinates 339 \sa maxSymbolWidth(), setMinSymbolWidth(), setSymbolExtent() 337 340 */ 338 341 void QwtPlotTradingCurve::setMaxSymbolWidth( double width ) 339 342 { 340 if ( width != d_data->maxSymbolWidth )341 { 342 d_data->maxSymbolWidth = width;343 if ( width != m_data->maxSymbolWidth ) 344 { 345 m_data->maxSymbolWidth = width; 343 346 344 347 legendChanged(); … … 348 351 349 352 /*! 350 \return Maximum for the symbol width 351 \sa setMaxSymbolWidth(), minSymbolWidth(), symbolExtent() 353 \return Maximum for the symbol width 354 \sa setMaxSymbolWidth(), minSymbolWidth(), symbolExtent() 352 355 */ 353 356 double QwtPlotTradingCurve::maxSymbolWidth() const 354 357 { 355 return d_data->maxSymbolWidth;356 } 357 358 /*! 359 \return Bounding rectangle of all samples. 360 For an empty series the rectangle is invalid. 361 */ 358 return m_data->maxSymbolWidth; 359 } 360 361 /*! 362 \return Bounding rectangle of all samples. 363 For an empty series the rectangle is invalid. 364 */ 362 365 QRectF QwtPlotTradingCurve::boundingRect() const 363 366 { … … 370 373 371 374 /*! 372 Draw an interval of the curve 373 374 \param painter Painter 375 \param xMap Maps x-values into pixel coordinates. 376 \param yMap Maps y-values into pixel coordinates. 377 \param canvasRect Contents rectangle of the canvas 378 \param from Index of the first point to be painted 379 \param to Index of the last point to be painted. If to < 0 the 375 Draw an interval of the curve 376 377 \param painter Painter 378 \param xMap Maps x-values into pixel coordinates. 379 \param yMap Maps y-values into pixel coordinates. 380 \param canvasRect Contents rectangle of the canvas 381 \param from Index of the first point to be painted 382 \param to Index of the last point to be painted. If to < 0 the 380 383 curve will be painted to its last point. 381 384 382 \sa drawSymbols() 383 */ 384 void QwtPlotTradingCurve::drawSeries( QPainter *painter,385 const QwtScaleMap &xMap, const QwtScaleMap&yMap,386 const QRectF &canvasRect, int from, int to ) const385 \sa drawSymbols() 386 */ 387 void QwtPlotTradingCurve::drawSeries( QPainter* painter, 388 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 389 const QRectF& canvasRect, int from, int to ) const 387 390 { 388 391 if ( to < 0 ) … … 397 400 painter->save(); 398 401 399 if ( d_data->symbolStyle != QwtPlotTradingCurve::NoSymbol )402 if ( m_data->symbolStyle != QwtPlotTradingCurve::NoSymbol ) 400 403 drawSymbols( painter, xMap, yMap, canvasRect, from, to ); 401 404 … … 404 407 405 408 /*! 406 Draw symbols 407 408 \param painter Painter 409 \param xMap x map 410 \param yMap y map 411 \param canvasRect Contents rectangle of the canvas 412 \param from Index of the first point to be painted 413 \param to Index of the last point to be painted 414 415 \sa drawSeries() 416 */ 417 void QwtPlotTradingCurve::drawSymbols( QPainter *painter,418 const QwtScaleMap &xMap, const QwtScaleMap&yMap,419 const QRectF &canvasRect, int from, int to ) const409 Draw symbols 410 411 \param painter Painter 412 \param xMap x map 413 \param yMap y map 414 \param canvasRect Contents rectangle of the canvas 415 \param from Index of the first point to be painted 416 \param to Index of the last point to be painted 417 418 \sa drawSeries() 419 */ 420 void QwtPlotTradingCurve::drawSymbols( QPainter* painter, 421 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 422 const QRectF& canvasRect, int from, int to ) const 420 423 { 421 424 const QRectF tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect ); 422 425 423 const QwtScaleMap *timeMap, *valueMap;426 const QwtScaleMap* timeMap, * valueMap; 424 427 double tMin, tMax, vMin, vMax; 425 428 … … 447 450 448 451 const bool inverted = timeMap->isInverting(); 449 const bool doClip = d_data->paintAttributes & ClipSymbols;452 const bool doClip = m_data->paintAttributes & ClipSymbols; 450 453 const bool doAlign = QwtPainter::roundingAlignment( painter ); 451 454 452 455 double symbolWidth = scaledSymbolWidth( xMap, yMap, canvasRect ); 453 456 if ( doAlign ) 454 symbolWidth = qFloor( 0.5 * symbolWidth ) * 2.0;455 456 QPen pen = d_data->symbolPen;457 symbolWidth = std::floor( 0.5 * symbolWidth ) * 2.0; 458 459 QPen pen = m_data->symbolPen; 457 460 pen.setCapStyle( Qt::FlatCap ); 458 461 … … 486 489 } 487 490 488 switch( d_data->symbolStyle )491 switch( m_data->symbolStyle ) 489 492 { 490 493 case Bar: … … 496 499 case CandleStick: 497 500 { 498 painter->setBrush( d_data->symbolBrush[ brushIndex ] );501 painter->setBrush( m_data->symbolBrush[ brushIndex ] ); 499 502 drawCandleStick( painter, translatedSample, 500 503 orient, symbolWidth ); … … 503 506 default: 504 507 { 505 if ( d_data->symbolStyle >= UserSymbol )508 if ( m_data->symbolStyle >= UserSymbol ) 506 509 { 507 painter->setBrush( d_data->symbolBrush[ brushIndex ] );508 drawUserSymbol( painter, d_data->symbolStyle,510 painter->setBrush( m_data->symbolBrush[ brushIndex ] ); 511 drawUserSymbol( painter, m_data->symbolStyle, 509 512 translatedSample, orient, inverted, symbolWidth ); 510 513 } … … 516 519 517 520 /*! 518 \brief Draw a symbol for a symbol style >= UserSymbol 519 520 The implementation does nothing and is intended to be overloaded 521 522 \param painter Qt painter, initialized with pen/brush 523 \param symbolStyle Symbol style 524 \param sample Samples already translated into paint device coordinates 525 \param orientation Vertical or horizontal 526 \param inverted True, when the opposite scale 521 \brief Draw a symbol for a symbol style >= UserSymbol 522 523 The implementation does nothing and is intended to be overloaded 524 525 \param painter Qt painter, initialized with pen/brush 526 \param symbolStyle Symbol style 527 \param sample Samples already translated into paint device coordinates 528 \param orientation Vertical or horizontal 529 \param inverted True, when the opposite scale 527 530 ( Qt::Vertical: x, Qt::Horizontal: y ) is increasing 528 531 in the opposite direction as QPainter coordinates. 529 \param symbolWidth Width of the symbol in paint device coordinates 530 */ 531 void QwtPlotTradingCurve::drawUserSymbol( QPainter *painter,532 SymbolStyle symbolStyle, const QwtOHLCSample &sample,532 \param symbolWidth Width of the symbol in paint device coordinates 533 */ 534 void QwtPlotTradingCurve::drawUserSymbol( QPainter* painter, 535 SymbolStyle symbolStyle, const QwtOHLCSample& sample, 533 536 Qt::Orientation orientation, bool inverted, double symbolWidth ) const 534 537 { … … 542 545 543 546 /*! 544 \brief Draw a bar 545 546 \param painter Qt painter, initialized with pen/brush 547 \param sample Sample, already translated into paint device coordinates 548 \param orientation Vertical or horizontal 549 \param inverted When inverted is false the open tick is painted 547 \brief Draw a bar 548 549 \param painter Qt painter, initialized with pen/brush 550 \param sample Sample, already translated into paint device coordinates 551 \param orientation Vertical or horizontal 552 \param inverted When inverted is false the open tick is painted 550 553 to the left/top, otherwise it is painted right/bottom. 551 554 The close tick is painted in the opposite direction … … 553 556 painted in the opposite d 554 557 opposite direction. 555 \param width Width or height of the candle, depending on the orientation 556 557 \sa Bar 558 */ 559 void QwtPlotTradingCurve::drawBar( QPainter *painter,560 const QwtOHLCSample &sample, Qt::Orientation orientation,558 \param width Width or height of the candle, depending on the orientation 559 560 \sa Bar 561 */ 562 void QwtPlotTradingCurve::drawBar( QPainter* painter, 563 const QwtOHLCSample& sample, Qt::Orientation orientation, 561 564 bool inverted, double width ) const 562 565 { … … 587 590 588 591 /*! 589 \brief Draw a candle stick 590 591 \param painter Qt painter, initialized with pen/brush 592 \param sample Samples already translated into paint device coordinates 593 \param orientation Vertical or horizontal 594 \param width Width or height of the candle, depending on the orientation 595 596 \sa CandleStick 597 */ 598 void QwtPlotTradingCurve::drawCandleStick( QPainter *painter,599 const QwtOHLCSample &sample, Qt::Orientation orientation,592 \brief Draw a candle stick 593 594 \param painter Qt painter, initialized with pen/brush 595 \param sample Samples already translated into paint device coordinates 596 \param orientation Vertical or horizontal 597 \param width Width or height of the candle, depending on the orientation 598 599 \sa CandleStick 600 */ 601 void QwtPlotTradingCurve::drawCandleStick( QPainter* painter, 602 const QwtOHLCSample& sample, Qt::Orientation orientation, 600 603 double width ) const 601 604 { 602 605 const double t = sample.time; 603 const double v1 = q Min( sample.low, sample.high );604 const double v2 = q Min( sample.open, sample.close );605 const double v3 = q Max( sample.low, sample.high );606 const double v4 = q Max( sample.open, sample.close );606 const double v1 = qwtMinF( sample.low, sample.high ); 607 const double v2 = qwtMinF( sample.open, sample.close ); 608 const double v3 = qwtMaxF( sample.low, sample.high ); 609 const double v4 = qwtMaxF( sample.open, sample.close ); 607 610 608 611 if ( orientation == Qt::Vertical ) … … 629 632 630 633 /*! 631 \return A rectangle filled with the color of the symbol pen 632 633 \param index Index of the legend entry 634 \return A rectangle filled with the color of the symbol pen 635 636 \param index Index of the legend entry 634 637 ( usually there is only one ) 635 \param size Icon size 636 637 \sa setLegendIconSize(), legendData() 638 */ 638 \param size Icon size 639 640 \sa setLegendIconSize(), legendData() 641 */ 639 642 QwtGraphic QwtPlotTradingCurve::legendIcon( int index, 640 const QSizeF &size ) const643 const QSizeF& size ) const 641 644 { 642 645 Q_UNUSED( index ); 643 return defaultIcon( d_data->symbolPen.color(), size );644 } 645 646 /*! 647 Calculate the symbol width in paint coordinates 648 649 The width is calculated by scaling the symbol extent into 650 paint device coordinates bounded by the minimum/maximum 651 symbol width. 652 653 \param xMap Maps x-values into pixel coordinates. 654 \param yMap Maps y-values into pixel coordinates. 655 \param canvasRect Contents rectangle of the canvas 656 657 \return Symbol width in paint coordinates 658 659 \sa symbolExtent(), minSymbolWidth(), maxSymbolWidth() 660 */ 646 return defaultIcon( m_data->symbolPen.color(), size ); 647 } 648 649 /*! 650 Calculate the symbol width in paint coordinates 651 652 The width is calculated by scaling the symbol extent into 653 paint device coordinates bounded by the minimum/maximum 654 symbol width. 655 656 \param xMap Maps x-values into pixel coordinates. 657 \param yMap Maps y-values into pixel coordinates. 658 \param canvasRect Contents rectangle of the canvas 659 660 \return Symbol width in paint coordinates 661 662 \sa symbolExtent(), minSymbolWidth(), maxSymbolWidth() 663 */ 661 664 double QwtPlotTradingCurve::scaledSymbolWidth( 662 const QwtScaleMap &xMap, const QwtScaleMap&yMap,663 const QRectF &canvasRect ) const665 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 666 const QRectF& canvasRect ) const 664 667 { 665 668 Q_UNUSED( canvasRect ); 666 669 667 if ( d_data->maxSymbolWidth > 0.0 &&668 d_data->minSymbolWidth >=d_data->maxSymbolWidth )669 { 670 return d_data->minSymbolWidth;671 } 672 673 const QwtScaleMap *map =670 if ( m_data->maxSymbolWidth > 0.0 && 671 m_data->minSymbolWidth >= m_data->maxSymbolWidth ) 672 { 673 return m_data->minSymbolWidth; 674 } 675 676 const QwtScaleMap* map = 674 677 ( orientation() == Qt::Vertical ) ? &xMap : &yMap; 675 678 676 const double pos = map->transform( map->s1() + d_data->symbolExtent );679 const double pos = map->transform( map->s1() + m_data->symbolExtent ); 677 680 678 681 double width = qAbs( pos - map->p1() ); 679 682 680 width = q Max( width,d_data->minSymbolWidth );681 if ( d_data->maxSymbolWidth > 0.0 )682 width = q Min( width,d_data->maxSymbolWidth );683 width = qwtMaxF( width, m_data->minSymbolWidth ); 684 if ( m_data->maxSymbolWidth > 0.0 ) 685 width = qwtMinF( width, m_data->maxSymbolWidth ); 683 686 684 687 return width; -
trunk/BNC/qwt/qwt_plot_tradingcurve.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_seriesitem.h" 15 #include "qwt_series_data.h"16 15 17 16 /*! 18 \brief QwtPlotTradingCurve illustrates movements in the price of a 17 \brief QwtPlotTradingCurve illustrates movements in the price of a 19 18 financial instrument over time. 20 19 21 QwtPlotTradingCurve supports candlestick or bar ( OHLC ) charts 22 that are used in the domain of technical analysis. 20 QwtPlotTradingCurve supports candlestick or bar ( OHLC ) charts 21 that are used in the domain of technical analysis. 23 22 24 While the length ( height or width depending on orientation() ) 25 of each symbol depends on the corresponding OHLC sample the size 26 of the other dimension can be controlled using: 23 While the length ( height or width depending on orientation() ) 24 of each symbol depends on the corresponding OHLC sample the size 25 of the other dimension can be controlled using: 27 26 28 - setSymbolExtent() 29 - setSymbolMinWidth() 30 - setSymbolMaxWidth() 27 - setSymbolExtent() 28 - setSymbolMinWidth() 29 - setSymbolMaxWidth() 31 30 32 The extent is a size in scale coordinates, so that the symbol width 33 is increasing when the plot is zoomed in. Minimum/Maximum width 34 is in widget coordinates independent from the zoom level. 35 When setting the minimum and maximum to the same value, the width of 36 the symbol is fixed. 37 */ 38 class QWT_EXPORT QwtPlotTradingCurve: 39 public QwtPlotSeriesItem, public QwtSeriesStore<QwtOHLCSample> 31 The extent is a size in scale coordinates, so that the symbol width 32 is increasing when the plot is zoomed in. Minimum/Maximum width 33 is in widget coordinates independent from the zoom level. 34 When setting the minimum and maximum to the same value, the width of 35 the symbol is fixed. 36 */ 37 class QWT_EXPORT QwtPlotTradingCurve 38 : public QwtPlotSeriesItem 39 , public QwtSeriesStore< QwtOHLCSample > 40 40 { 41 public: 41 public: 42 42 /*! 43 43 \brief Symbol styles. … … 45 45 The default setting is QwtPlotSeriesItem::CandleStick. 46 46 \sa setSymbolStyle(), symbolStyle() 47 */ 47 */ 48 48 enum SymbolStyle 49 49 { … … 52 52 53 53 /*! 54 A line on the chart shows the price range (the highest and lowest 55 prices) over one unit of time, e.g. one day or one hour. 56 Tick marks project from each side of the line indicating the 57 opening and closing price. 54 A line on the chart shows the price range (the highest and lowest 55 prices) over one unit of time, e.g. one day or one hour. 56 Tick marks project from each side of the line indicating the 57 opening and closing price. 58 58 */ 59 59 Bar, 60 60 61 61 /*! 62 The range between opening/closing price are displayed as 63 a filled box. The fill brush depends on the direction of the 64 price movement. The box is connected to the highest/lowest 65 values by lines. 66 */ 62 The range between opening/closing price are displayed as 63 a filled box. The fill brush depends on the direction of the 64 price movement. The box is connected to the highest/lowest 65 values by lines. 66 */ 67 67 CandleStick, 68 68 69 69 /*! 70 SymbolTypes >= UserSymbol are displayed by drawUserSymbol(), 71 that needs to be overloaded and implemented in derived 72 curve classes. 70 SymbolTypes >= UserSymbol are displayed by drawUserSymbol(), 71 that needs to be overloaded and implemented in derived 72 curve classes. 73 73 74 \sa drawUserSymbol() 75 */ 74 \sa drawUserSymbol() 75 */ 76 76 UserSymbol = 100 77 77 }; … … 92 92 Attributes to modify the drawing algorithm. 93 93 \sa setPaintAttribute(), testPaintAttribute() 94 */ 94 */ 95 95 enum PaintAttribute 96 96 { … … 99 99 }; 100 100 101 //! Paint attributes 102 typedef QFlags<PaintAttribute> PaintAttributes; 101 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 103 102 104 explicit QwtPlotTradingCurve( const QString &title = QString() );105 explicit QwtPlotTradingCurve( const QwtText &title );103 explicit QwtPlotTradingCurve( const QString& title = QString() ); 104 explicit QwtPlotTradingCurve( const QwtText& title ); 106 105 107 106 virtual ~QwtPlotTradingCurve(); 108 107 109 virtual int rtti() const; 108 virtual int rtti() const QWT_OVERRIDE; 110 109 111 110 void setPaintAttribute( PaintAttribute, bool on = true ); 112 111 bool testPaintAttribute( PaintAttribute ) const; 113 112 114 void setSamples( const QVector<QwtOHLCSample >& );115 void setSamples( QwtSeriesData<QwtOHLCSample >* );113 void setSamples( const QVector< QwtOHLCSample >& ); 114 void setSamples( QwtSeriesData< QwtOHLCSample >* ); 116 115 117 116 void setSymbolStyle( SymbolStyle style ); 118 117 SymbolStyle symbolStyle() const; 119 118 120 void setSymbolPen( const QColor &,119 void setSymbolPen( const QColor&, 121 120 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 122 void setSymbolPen( const QPen & );121 void setSymbolPen( const QPen& ); 123 122 QPen symbolPen() const; 124 123 125 void setSymbolBrush( Direction, const QBrush & );124 void setSymbolBrush( Direction, const QBrush& ); 126 125 QBrush symbolBrush( Direction ) const; 127 126 … … 135 134 double maxSymbolWidth() const; 136 135 137 virtual void drawSeries( QPainter *painter,138 const QwtScaleMap &xMap, const QwtScaleMap&yMap,139 const QRectF &canvasRect, int from, int to ) const;136 virtual void drawSeries( QPainter*, 137 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 138 const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE; 140 139 141 virtual QRectF boundingRect() const; 140 virtual QRectF boundingRect() const QWT_OVERRIDE; 142 141 143 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;142 virtual QwtGraphic legendIcon( int index, const QSizeF& ) const QWT_OVERRIDE; 144 143 145 protected: 144 protected: 146 145 147 146 void init(); 148 147 149 virtual void drawSymbols( QPainter *,150 const QwtScaleMap &xMap, const QwtScaleMap&yMap,151 const QRectF &canvasRect, int from, int to ) const;148 virtual void drawSymbols( QPainter*, 149 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 150 const QRectF& canvasRect, int from, int to ) const; 152 151 153 virtual void drawUserSymbol( QPainter *,154 SymbolStyle, const QwtOHLCSample &,152 virtual void drawUserSymbol( QPainter*, 153 SymbolStyle, const QwtOHLCSample&, 155 154 Qt::Orientation, bool inverted, double symbolWidth ) const; 156 155 157 void drawBar( QPainter *painter, const QwtOHLCSample&,156 void drawBar( QPainter*, const QwtOHLCSample&, 158 157 Qt::Orientation, bool inverted, double width ) const; 159 158 160 void drawCandleStick( QPainter *, const QwtOHLCSample&,159 void drawCandleStick( QPainter*, const QwtOHLCSample&, 161 160 Qt::Orientation, double width ) const; 162 161 163 162 virtual double scaledSymbolWidth( 164 const QwtScaleMap &xMap, const QwtScaleMap&yMap,165 const QRectF &canvasRect ) const;163 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 164 const QRectF& canvasRect ) const; 166 165 167 private: 166 private: 168 167 class PrivateData; 169 PrivateData *d_data;168 PrivateData* m_data; 170 169 }; 171 170 -
trunk/BNC/qwt/qwt_plot_zoneitem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_painter.h" 12 12 #include "qwt_scale_map.h" 13 #include "qwt_text.h" 14 #include "qwt_interval.h" 15 13 16 #include <qpainter.h> 14 17 15 18 class QwtPlotZoneItem::PrivateData 16 19 { 17 public: 18 PrivateData() :19 orientation( Qt::Vertical ) ,20 pen( Qt::NoPen ) 20 public: 21 PrivateData() 22 : orientation( Qt::Vertical ) 23 , pen( Qt::NoPen ) 21 24 { 22 25 QColor c( Qt::darkGray ); … … 44 47 45 48 \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ() 46 */ 47 QwtPlotZoneItem::QwtPlotZoneItem() :48 QwtPlotItem( QwtText( "Zone" ) ) 49 { 50 d_data = new PrivateData;49 */ 50 QwtPlotZoneItem::QwtPlotZoneItem() 51 : QwtPlotItem( QwtText( "Zone" ) ) 52 { 53 m_data = new PrivateData; 51 54 52 55 setItemAttribute( QwtPlotItem::AutoScale, false ); … … 59 62 QwtPlotZoneItem::~QwtPlotZoneItem() 60 63 { 61 delete d_data;64 delete m_data; 62 65 } 63 66 … … 69 72 70 73 /*! 71 Build and assign a pen 72 73 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 74 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 75 to hide this incompatibility. 76 77 \param color Pen color 78 \param width Pen width 79 \param style Pen style 80 81 \sa pen(), brush() 82 */ 83 void QwtPlotZoneItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )74 Build and assign a pen 75 76 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 77 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 78 to hide this incompatibility. 79 80 \param color Pen color 81 \param width Pen width 82 \param style Pen style 83 84 \sa pen(), brush() 85 */ 86 void QwtPlotZoneItem::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 84 87 { 85 88 setPen( QPen( color, width, style ) ); … … 87 90 88 91 /*! 89 \brief Assign a pen 90 91 The pen is used to draw the border lines of the zone 92 93 \param pen Pen 94 \sa pen(), setBrush() 95 */ 96 void QwtPlotZoneItem::setPen( const QPen &pen )97 { 98 if ( d_data->pen != pen )99 { 100 d_data->pen = pen;92 \brief Assign a pen 93 94 The pen is used to draw the border lines of the zone 95 96 \param pen Pen 97 \sa pen(), setBrush() 98 */ 99 void QwtPlotZoneItem::setPen( const QPen& pen ) 100 { 101 if ( m_data->pen != pen ) 102 { 103 m_data->pen = pen; 101 104 itemChanged(); 102 105 } … … 104 107 105 108 /*! 106 \return Pen used to draw the border lines 107 \sa setPen(), brush() 108 */ 109 const QPen &QwtPlotZoneItem::pen() const110 { 111 return d_data->pen;112 } 113 114 /*! 115 \brief Assign a brush 116 117 The brush is used to fill the zone 118 119 \param brush Brush 120 \sa pen(), setBrush() 121 */ 122 void QwtPlotZoneItem::setBrush( const QBrush &brush )123 { 124 if ( d_data->brush != brush )125 { 126 d_data->brush = brush;109 \return Pen used to draw the border lines 110 \sa setPen(), brush() 111 */ 112 const QPen& QwtPlotZoneItem::pen() const 113 { 114 return m_data->pen; 115 } 116 117 /*! 118 \brief Assign a brush 119 120 The brush is used to fill the zone 121 122 \param brush Brush 123 \sa pen(), setBrush() 124 */ 125 void QwtPlotZoneItem::setBrush( const QBrush& brush ) 126 { 127 if ( m_data->brush != brush ) 128 { 129 m_data->brush = brush; 127 130 itemChanged(); 128 131 } … … 130 133 131 134 /*! 132 \return Brush used to fill the zone 133 \sa setPen(), brush() 134 */ 135 const QBrush &QwtPlotZoneItem::brush() const136 { 137 return d_data->brush;138 } 139 140 /*! 141 \brief Set the orientation of the zone 142 143 A horizontal zone highlights an interval of the y axis, 144 a vertical zone of the x axis. It is unbounded in the 145 opposite direction. 146 147 \sa orientation(), QwtPlotItem::setAxes() 148 */ 135 \return Brush used to fill the zone 136 \sa setPen(), brush() 137 */ 138 const QBrush& QwtPlotZoneItem::brush() const 139 { 140 return m_data->brush; 141 } 142 143 /*! 144 \brief Set the orientation of the zone 145 146 A horizontal zone highlights an interval of the y axis, 147 a vertical zone of the x axis. It is unbounded in the 148 opposite direction. 149 150 \sa orientation(), QwtPlotItem::setAxes() 151 */ 149 152 void QwtPlotZoneItem::setOrientation( Qt::Orientation orientation ) 150 153 { 151 if ( d_data->orientation != orientation )152 { 153 d_data->orientation = orientation;154 if ( m_data->orientation != orientation ) 155 { 156 m_data->orientation = orientation; 154 157 itemChanged(); 155 158 } … … 157 160 158 161 /*! 159 \return Orientation of the zone 160 \sa setOrientation() 161 */ 162 Qt::Orientation QwtPlotZoneItem::orientation() 163 { 164 return d_data->orientation;165 } 166 167 /*! 168 Set the interval of the zone 169 170 For a horizontal zone the interval is related to the y axis, 171 for a vertical zone it is related to the x axis. 172 173 \param min Minimum of the interval 174 \param max Maximum of the interval 175 176 \sa interval(), setOrientation() 162 \return Orientation of the zone 163 \sa setOrientation() 164 */ 165 Qt::Orientation QwtPlotZoneItem::orientation() const 166 { 167 return m_data->orientation; 168 } 169 170 /*! 171 Set the interval of the zone 172 173 For a horizontal zone the interval is related to the y axis, 174 for a vertical zone it is related to the x axis. 175 176 \param min Minimum of the interval 177 \param max Maximum of the interval 178 179 \sa interval(), setOrientation() 177 180 */ 178 181 void QwtPlotZoneItem::setInterval( double min, double max ) … … 182 185 183 186 /*! 184 Set the interval of the zone 185 186 For a horizontal zone the interval is related to the y axis, 187 for a vertical zone it is related to the x axis. 188 189 \param interval Zone interval 190 191 \sa interval(), setOrientation() 192 */ 193 void QwtPlotZoneItem::setInterval( const QwtInterval &interval )194 { 195 if ( d_data->interval != interval )196 { 197 d_data->interval = interval;187 Set the interval of the zone 188 189 For a horizontal zone the interval is related to the y axis, 190 for a vertical zone it is related to the x axis. 191 192 \param interval Zone interval 193 194 \sa interval(), setOrientation() 195 */ 196 void QwtPlotZoneItem::setInterval( const QwtInterval& interval ) 197 { 198 if ( m_data->interval != interval ) 199 { 200 m_data->interval = interval; 198 201 itemChanged(); 199 202 } … … 201 204 202 205 /*! 203 \return Zone interval 204 \sa setInterval(), orientation() 206 \return Zone interval 207 \sa setInterval(), orientation() 205 208 */ 206 209 QwtInterval QwtPlotZoneItem::interval() const 207 210 { 208 return d_data->interval;209 } 210 211 /*! 212 Draw the zone 213 214 \param painter Painter 215 \param xMap x Scale Map 216 \param yMap y Scale Map 217 \param canvasRect Contents rectangle of the canvas in painter coordinates 218 */ 219 220 void QwtPlotZoneItem::draw( QPainter *painter,221 const QwtScaleMap &xMap, const QwtScaleMap&yMap,222 const QRectF &canvasRect ) const223 { 224 if ( ! d_data->interval.isValid() )211 return m_data->interval; 212 } 213 214 /*! 215 Draw the zone 216 217 \param painter Painter 218 \param xMap x Scale Map 219 \param yMap y Scale Map 220 \param canvasRect Contents rectangle of the canvas in painter coordinates 221 */ 222 223 void QwtPlotZoneItem::draw( QPainter* painter, 224 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 225 const QRectF& canvasRect ) const 226 { 227 if ( !m_data->interval.isValid() ) 225 228 return; 226 229 227 QPen pen = d_data->pen;230 QPen pen = m_data->pen; 228 231 pen.setCapStyle( Qt::FlatCap ); 229 232 230 233 const bool doAlign = QwtPainter::roundingAlignment( painter ); 231 234 232 if ( d_data->orientation == Qt::Horizontal )233 { 234 double y1 = yMap.transform( d_data->interval.minValue() );235 double y2 = yMap.transform( d_data->interval.maxValue() );235 if ( m_data->orientation == Qt::Horizontal ) 236 { 237 double y1 = yMap.transform( m_data->interval.minValue() ); 238 double y2 = yMap.transform( m_data->interval.maxValue() ); 236 239 237 240 if ( doAlign ) … … 244 247 r = r.normalized(); 245 248 246 if ( ( d_data->brush.style() != Qt::NoBrush ) && ( y1 != y2 ) )247 { 248 QwtPainter::fillRect( painter, r, d_data->brush );249 } 250 251 if ( d_data->pen.style() != Qt::NoPen )252 { 253 painter->setPen( d_data->pen );249 if ( ( m_data->brush.style() != Qt::NoBrush ) && ( y1 != y2 ) ) 250 { 251 QwtPainter::fillRect( painter, r, m_data->brush ); 252 } 253 254 if ( m_data->pen.style() != Qt::NoPen ) 255 { 256 painter->setPen( m_data->pen ); 254 257 255 258 QwtPainter::drawLine( painter, r.left(), r.top(), r.right(), r.top() ); … … 259 262 else 260 263 { 261 double x1 = xMap.transform( d_data->interval.minValue() );262 double x2 = xMap.transform( d_data->interval.maxValue() );264 double x1 = xMap.transform( m_data->interval.minValue() ); 265 double x2 = xMap.transform( m_data->interval.maxValue() ); 263 266 264 267 if ( doAlign ) … … 271 274 r = r.normalized(); 272 275 273 if ( ( d_data->brush.style() != Qt::NoBrush ) && ( x1 != x2 ) )274 { 275 QwtPainter::fillRect( painter, r, d_data->brush );276 } 277 278 if ( d_data->pen.style() != Qt::NoPen )279 { 280 painter->setPen( d_data->pen );276 if ( ( m_data->brush.style() != Qt::NoBrush ) && ( x1 != x2 ) ) 277 { 278 QwtPainter::fillRect( painter, r, m_data->brush ); 279 } 280 281 if ( m_data->pen.style() != Qt::NoPen ) 282 { 283 painter->setPen( m_data->pen ); 281 284 282 285 QwtPainter::drawLine( painter, r.left(), r.top(), r.left(), r.bottom() ); … … 287 290 288 291 /*! 289 The bounding rectangle is build from the interval in one direction 290 and something invalid for the opposite direction. 291 292 \return An invalid rectangle with valid boundaries in one direction 293 */ 292 The bounding rectangle is build from the interval in one direction 293 and something invalid for the opposite direction. 294 295 \return An invalid rectangle with valid boundaries in one direction 296 */ 294 297 QRectF QwtPlotZoneItem::boundingRect() const 295 298 { 296 299 QRectF br = QwtPlotItem::boundingRect(); 297 300 298 const QwtInterval &intv =d_data->interval;301 const QwtInterval& intv = m_data->interval; 299 302 300 303 if ( intv.isValid() ) 301 304 { 302 if ( d_data->orientation == Qt::Horizontal )305 if ( m_data->orientation == Qt::Horizontal ) 303 306 { 304 307 br.setTop( intv.minValue() ); -
trunk/BNC/qwt/qwt_plot_zoneitem.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_item.h" 15 #include "qwt_interval.h"16 15 16 #include <qnamespace.h> 17 18 class QwtInterval; 17 19 class QPen; 18 20 class QBrush; 19 21 20 22 /*! 21 \brief A plot item, which displays a zone 23 \brief A plot item, which displays a zone 22 24 23 A horizontal zone highlights an interval of the y axis - a vertical 24 zone an interval of the x axis - and is unbounded in the opposite direction. 25 It is filled with a brush and its border lines are optionally displayed with a pen. 25 A horizontal zone highlights an interval of the y axis - a vertical 26 zone an interval of the x axis - and is unbounded in the opposite direction. 27 It is filled with a brush and its border lines are optionally displayed with a pen. 26 28 27 \note For displaying an area that is bounded for x and y coordinates 29 \note For displaying an area that is bounded for x and y coordinates 28 30 use QwtPlotShapeItem 29 */ 31 */ 30 32 31 class QWT_EXPORT QwtPlotZoneItem: 33 class QWT_EXPORT QwtPlotZoneItem : 32 34 public QwtPlotItem 33 35 { 34 public: 36 public: 35 37 explicit QwtPlotZoneItem(); 36 38 virtual ~QwtPlotZoneItem(); 37 39 38 virtual int rtti() const; 40 virtual int rtti() const QWT_OVERRIDE; 39 41 40 42 void setOrientation( Qt::Orientation ); 41 Qt::Orientation orientation(); 43 Qt::Orientation orientation() const; 42 44 43 45 void setInterval( double min, double max ); 44 void setInterval( const QwtInterval & );46 void setInterval( const QwtInterval& ); 45 47 QwtInterval interval() const; 46 48 47 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );48 void setPen( const QPen & );49 const QPen &pen() const;49 void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 50 void setPen( const QPen& ); 51 const QPen& pen() const; 50 52 51 void setBrush( const QBrush & );52 const QBrush &brush() const;53 void setBrush( const QBrush& ); 54 const QBrush& brush() const; 53 55 54 virtual void draw( QPainter *,55 const QwtScaleMap &, const QwtScaleMap&,56 const QRectF &) const;56 virtual void draw( QPainter*, 57 const QwtScaleMap&, const QwtScaleMap&, 58 const QRectF& canvasRect ) const QWT_OVERRIDE; 57 59 58 virtual QRectF boundingRect() const; 60 virtual QRectF boundingRect() const QWT_OVERRIDE; 59 61 60 private: 62 private: 61 63 class PrivateData; 62 PrivateData *d_data;64 PrivateData* m_data; 63 65 }; 64 66 -
trunk/BNC/qwt/qwt_plot_zoomer.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_plot.h" 12 12 #include "qwt_scale_div.h" 13 #include "qwt_scale_map.h" 14 #include "qwt_interval.h" 13 15 #include "qwt_picker_machine.h" 14 #include <qalgorithms.h> 16 17 #include <qstack.h> 15 18 16 19 static QwtInterval qwtExpandedZoomInterval( double v1, double v2, … … 50 53 } 51 54 52 static QRectF qwtExpandedZoomRect( const QRectF &zoomRect, const QSizeF&minSize,55 static QRectF qwtExpandedZoomRect( const QRectF& zoomRect, const QSizeF& minSize, 53 56 const QwtTransform* transformX, const QwtTransform* transformY ) 54 57 { … … 78 81 class QwtPlotZoomer::PrivateData 79 82 { 80 public: 83 public: 81 84 uint zoomRectIndex; 82 QStack< QRectF> zoomStack;85 QStack< QRectF > zoomStack; 83 86 84 87 int maxStackDepth; … … 86 89 87 90 /*! 88 \brief Create a zoomer for a plot canvas. 89 90 The zoomer is set to those x- and y-axis of the parent plot of the 91 canvas that are enabled. If both or no x-axis are enabled, the picker 92 is set to Qwt Plot::xBottom. If both or no y-axis are93 enabled, it is set to Qwt Plot::yLeft.94 95 The zoomer is initialized with a QwtPickerDragRectMachine, 96 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 97 is set to QwtPicker::RectRubberBand 98 99 \param canvas Plot canvas to observe, also the parent object 100 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 91 \brief Create a zoomer for a plot canvas. 92 93 The zoomer is set to those x- and y-axis of the parent plot of the 94 canvas that are enabled. If both or no x-axis are enabled, the picker 95 is set to QwtAxis::XBottom. If both or no y-axis are 96 enabled, it is set to QwtAxis::YLeft. 97 98 The zoomer is initialized with a QwtPickerDragRectMachine, 99 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 100 is set to QwtPicker::RectRubberBand 101 102 \param canvas Plot canvas to observe, also the parent object 103 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 101 104 the zoomer with its scales. This might be necessary, 102 105 when the plot is in a state with pending scale changes. 103 106 104 \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase() 105 */ 106 QwtPlotZoomer::QwtPlotZoomer( QWidget *canvas, bool doReplot ):107 QwtPlotPicker( canvas ) 107 \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase() 108 */ 109 QwtPlotZoomer::QwtPlotZoomer( QWidget* canvas, bool doReplot ) 110 : QwtPlotPicker( canvas ) 108 111 { 109 112 if ( canvas ) … … 112 115 113 116 /*! 114 \brief Create a zoomer for a plot canvas. 115 116 The zoomer is initialized with a QwtPickerDragRectMachine, 117 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 118 is set to QwtPicker ;;RectRubberBand119 120 \param xAxis X axis of the zoomer 121 \param yAxis Y axis of the zoomer 122 \param canvas Plot canvas to observe, also the parent object 123 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 117 \brief Create a zoomer for a plot canvas. 118 119 The zoomer is initialized with a QwtPickerDragRectMachine, 120 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 121 is set to QwtPicker::RectRubberBand 122 123 \param xAxisId X axis of the zoomer 124 \param yAxisId Y axis of the zoomer 125 \param canvas Plot canvas to observe, also the parent object 126 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 124 127 the zoomer with its scales. This might be necessary, 125 128 when the plot is in a state with pending scale changes. 126 129 127 \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase() 128 */ 129 130 QwtPlotZoomer::QwtPlotZoomer( int xAxis, int yAxis,131 QWidget *canvas, bool doReplot ):132 QwtPlotPicker( xAxis , yAxis, canvas )130 \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase() 131 */ 132 133 QwtPlotZoomer::QwtPlotZoomer( QwtAxisId xAxisId, QwtAxisId yAxisId, 134 QWidget* canvas, bool doReplot ) 135 : QwtPlotPicker( xAxisId, yAxisId, canvas ) 133 136 { 134 137 if ( canvas ) … … 139 142 void QwtPlotZoomer::init( bool doReplot ) 140 143 { 141 d_data = new PrivateData;142 143 d_data->maxStackDepth = -1;144 m_data = new PrivateData; 145 146 m_data->maxStackDepth = -1; 144 147 145 148 setTrackerMode( ActiveOnly ); … … 155 158 QwtPlotZoomer::~QwtPlotZoomer() 156 159 { 157 delete d_data;158 } 159 160 /*! 161 \brief Limit the number of recursive zoom operations to depth. 162 163 A value of -1 set the depth to unlimited, 0 disables zooming. 164 If the current zoom rectangle is below depth, the plot is unzoomed. 165 166 \param depth Maximum for the stack depth 167 \sa maxStackDepth() 168 \note depth doesn't include the zoom base, so zoomStack().count() might be 160 delete m_data; 161 } 162 163 /*! 164 \brief Limit the number of recursive zoom operations to depth. 165 166 A value of -1 set the depth to unlimited, 0 disables zooming. 167 If the current zoom rectangle is below depth, the plot is unzoomed. 168 169 \param depth Maximum for the stack depth 170 \sa maxStackDepth() 171 \note depth doesn't include the zoom base, so zoomStack().count() might be 169 172 maxStackDepth() + 1. 170 */ 173 */ 171 174 void QwtPlotZoomer::setMaxStackDepth( int depth ) 172 175 { 173 d_data->maxStackDepth = depth;176 m_data->maxStackDepth = depth; 174 177 175 178 if ( depth >= 0 ) 176 179 { 177 // unzoom if the current depth is below d_data->maxStackDepth180 // unzoom if the current depth is below m_data->maxStackDepth 178 181 179 182 const int zoomOut = 180 int( d_data->zoomStack.count()) - 1 - depth; // -1 for the zoom base183 m_data->zoomStack.count() - 1 - depth; // -1 for the zoom base 181 184 182 185 if ( zoomOut > 0 ) 183 186 { 184 187 zoom( -zoomOut ); 185 for ( int i = int( d_data->zoomStack.count()) - 1;186 i > int( d_data->zoomRectIndex ); i-- )188 for ( int i = m_data->zoomStack.count() - 1; 189 i > int( m_data->zoomRectIndex ); i-- ) 187 190 { 188 ( void ) d_data->zoomStack.pop(); // remove trailing rects191 ( void )m_data->zoomStack.pop(); // remove trailing rects 189 192 } 190 193 } … … 193 196 194 197 /*! 195 \return Maximal depth of the zoom stack. 196 \sa setMaxStackDepth() 197 */ 198 \return Maximal depth of the zoom stack. 199 \sa setMaxStackDepth() 200 */ 198 201 int QwtPlotZoomer::maxStackDepth() const 199 202 { 200 return d_data->maxStackDepth;201 } 202 203 /*! 204 \return The zoom stack. zoomStack()[0] is the zoom base, 203 return m_data->maxStackDepth; 204 } 205 206 /*! 207 \return The zoom stack. zoomStack()[0] is the zoom base, 205 208 zoomStack()[1] the first zoomed rectangle. 206 209 207 \sa setZoomStack(), zoomRectIndex() 208 */ 209 const QStack< QRectF> &QwtPlotZoomer::zoomStack() const210 { 211 return d_data->zoomStack;212 } 213 214 /*! 215 \return Initial rectangle of the zoomer 216 \sa setZoomBase(), zoomRect() 217 */ 210 \sa setZoomStack(), zoomRectIndex() 211 */ 212 const QStack< QRectF >& QwtPlotZoomer::zoomStack() const 213 { 214 return m_data->zoomStack; 215 } 216 217 /*! 218 \return Initial rectangle of the zoomer 219 \sa setZoomBase(), zoomRect() 220 */ 218 221 QRectF QwtPlotZoomer::zoomBase() const 219 222 { 220 return d_data->zoomStack[0];221 } 222 223 /*! 224 Reinitialized the zoom stack with scaleRect() as base. 225 226 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 223 return m_data->zoomStack[0]; 224 } 225 226 /*! 227 Reinitialized the zoom stack with scaleRect() as base. 228 229 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 227 230 the zoomer with its scales. This might be necessary, 228 231 when the plot is in a state with pending scale changes. 229 232 230 \sa zoomBase(), scaleRect() QwtPlot::autoReplot(), QwtPlot::replot(). 231 */ 233 \sa zoomBase(), scaleRect() QwtPlot::autoReplot(), QwtPlot::replot(). 234 */ 232 235 void QwtPlotZoomer::setZoomBase( bool doReplot ) 233 236 { 234 QwtPlot *plt = plot();237 QwtPlot* plt = plot(); 235 238 if ( plt == NULL ) 236 239 return; … … 239 242 plt->replot(); 240 243 241 d_data->zoomStack.clear();242 d_data->zoomStack.push( scaleRect() );243 d_data->zoomRectIndex = 0;244 m_data->zoomStack.clear(); 245 m_data->zoomStack.push( scaleRect() ); 246 m_data->zoomRectIndex = 0; 244 247 245 248 rescale(); … … 247 250 248 251 /*! 249 \brief Set the initial size of the zoomer. 250 251 base is united with the current scaleRect() and the zoom stack is 252 reinitialized with it as zoom base. plot is zoomed to scaleRect(). 253 254 \param base Zoom base 255 256 \sa zoomBase(), scaleRect() 257 */ 258 void QwtPlotZoomer::setZoomBase( const QRectF &base )259 { 260 const QwtPlot *plt = plot();252 \brief Set the initial size of the zoomer. 253 254 base is united with the current scaleRect() and the zoom stack is 255 reinitialized with it as zoom base. plot is zoomed to scaleRect(). 256 257 \param base Zoom base 258 259 \sa zoomBase(), scaleRect() 260 */ 261 void QwtPlotZoomer::setZoomBase( const QRectF& base ) 262 { 263 const QwtPlot* plt = plot(); 261 264 if ( !plt ) 262 265 return; … … 265 268 const QRectF bRect = base | sRect; 266 269 267 d_data->zoomStack.clear();268 d_data->zoomStack.push( bRect );269 d_data->zoomRectIndex = 0;270 m_data->zoomStack.clear(); 271 m_data->zoomStack.push( bRect ); 272 m_data->zoomRectIndex = 0; 270 273 271 274 if ( base != sRect ) 272 275 { 273 d_data->zoomStack.push( sRect );274 d_data->zoomRectIndex++;276 m_data->zoomStack.push( sRect ); 277 m_data->zoomRectIndex++; 275 278 } 276 279 … … 279 282 280 283 /*! 281 \return Rectangle at the current position on the zoom stack. 282 \sa zoomRectIndex(), scaleRect(). 283 */ 284 \return Rectangle at the current position on the zoom stack. 285 \sa zoomRectIndex(), scaleRect(). 286 */ 284 287 QRectF QwtPlotZoomer::zoomRect() const 285 288 { 286 return d_data->zoomStack[d_data->zoomRectIndex];287 } 288 289 /*! 290 \return Index of current position of zoom stack. 291 */ 289 return m_data->zoomStack[m_data->zoomRectIndex]; 290 } 291 292 /*! 293 \return Index of current position of zoom stack. 294 */ 292 295 uint QwtPlotZoomer::zoomRectIndex() const 293 296 { 294 return d_data->zoomRectIndex;295 } 296 297 /*! 298 \brief Zoom in 299 300 Clears all rectangles above the current position of the 301 zoom stack and pushes the normalized rectangle on it. 302 303 \note If the maximal stack depth is reached, zoom is ignored. 304 \note The zoomed signal is emitted. 305 */ 306 307 void QwtPlotZoomer::zoom( const QRectF &rect )308 { 309 if ( d_data->maxStackDepth >= 0 &&310 int( d_data->zoomRectIndex ) >=d_data->maxStackDepth )297 return m_data->zoomRectIndex; 298 } 299 300 /*! 301 \brief Zoom in 302 303 Clears all rectangles above the current position of the 304 zoom stack and pushes the normalized rectangle on it. 305 306 \note If the maximal stack depth is reached, zoom is ignored. 307 \note The zoomed signal is emitted. 308 */ 309 310 void QwtPlotZoomer::zoom( const QRectF& rect ) 311 { 312 if ( m_data->maxStackDepth >= 0 && 313 int( m_data->zoomRectIndex ) >= m_data->maxStackDepth ) 311 314 { 312 315 return; … … 314 317 315 318 const QRectF zoomRect = rect.normalized(); 316 if ( zoomRect != d_data->zoomStack[d_data->zoomRectIndex] )317 { 318 for ( uint i = int( d_data->zoomStack.count()) - 1;319 i > d_data->zoomRectIndex; i-- )319 if ( zoomRect != m_data->zoomStack[m_data->zoomRectIndex] ) 320 { 321 for ( uint i = m_data->zoomStack.count() - 1; 322 i > m_data->zoomRectIndex; i-- ) 320 323 { 321 ( void ) d_data->zoomStack.pop();324 ( void )m_data->zoomStack.pop(); 322 325 } 323 326 324 d_data->zoomStack.push( zoomRect );325 d_data->zoomRectIndex++;327 m_data->zoomStack.push( zoomRect ); 328 m_data->zoomRectIndex++; 326 329 327 330 rescale(); … … 332 335 333 336 /*! 334 \brief Zoom in or out 335 336 Activate a rectangle on the zoom stack with an offset relative 337 to the current position. Negative values of offset will zoom out, 338 positive zoom in. A value of 0 zooms out to the zoom base. 339 340 \param offset Offset relative to the current position of the zoom stack. 341 \note The zoomed signal is emitted. 342 \sa zoomRectIndex() 343 */ 337 \brief Zoom in or out 338 339 Activate a rectangle on the zoom stack with an offset relative 340 to the current position. Negative values of offset will zoom out, 341 positive zoom in. A value of 0 zooms out to the zoom base. 342 343 \param offset Offset relative to the current position of the zoom stack. 344 \note The zoomed signal is emitted. 345 \sa zoomRectIndex() 346 */ 344 347 void QwtPlotZoomer::zoom( int offset ) 345 348 { 349 int newIndex; 350 346 351 if ( offset == 0 ) 347 d_data->zoomRectIndex = 0; 352 { 353 newIndex = 0; 354 } 348 355 else 349 356 { 350 intnewIndex =d_data->zoomRectIndex + offset;351 newIndex = q Max( 0, newIndex );352 newIndex = qMin( int( d_data->zoomStack.count() ) - 1, newIndex );353 354 d_data->zoomRectIndex= uint( newIndex );355 }356 357 rescale(); 358 359 Q_EMIT zoomed( zoomRect() );360 } 361 362 /*! 363 \brief Assign a zoom stack 364 365 In combination with other types of navigation it might be useful to 366 modify to manipulate the complete zoom stack. 367 368 \param zoomStack New zoom stack 369 \param zoomRectIndex Index of the current position of zoom stack. 357 newIndex = m_data->zoomRectIndex + offset; 358 newIndex = qBound( 0, newIndex, m_data->zoomStack.count() - 1 ); 359 } 360 361 if ( newIndex != static_cast< int >( m_data->zoomRectIndex ) ) 362 { 363 m_data->zoomRectIndex = newIndex; 364 rescale(); 365 Q_EMIT zoomed( zoomRect() ); 366 } 367 } 368 369 /*! 370 \brief Assign a zoom stack 371 372 In combination with other types of navigation it might be useful to 373 modify to manipulate the complete zoom stack. 374 375 \param zoomStack New zoom stack 376 \param zoomRectIndex Index of the current position of zoom stack. 370 377 In case of -1 the current position is at the top 371 378 of the stack. 372 379 373 \note The zoomed signal might be emitted. 374 \sa zoomStack(), zoomRectIndex() 375 */ 380 \note The zoomed signal might be emitted. 381 \sa zoomStack(), zoomRectIndex() 382 */ 376 383 void QwtPlotZoomer::setZoomStack( 377 const QStack< QRectF> &zoomStack, int zoomRectIndex )384 const QStack< QRectF >& zoomStack, int zoomRectIndex ) 378 385 { 379 386 if ( zoomStack.isEmpty() ) 380 387 return; 381 388 382 if ( d_data->maxStackDepth >= 0 &&383 int(zoomStack.count()) > d_data->maxStackDepth )389 if ( m_data->maxStackDepth >= 0 && 390 zoomStack.count() > m_data->maxStackDepth ) 384 391 { 385 392 return; 386 393 } 387 394 388 if ( zoomRectIndex < 0 || zoomRectIndex > int(zoomStack.count()) )395 if ( zoomRectIndex < 0 || zoomRectIndex > zoomStack.count() ) 389 396 zoomRectIndex = zoomStack.count() - 1; 390 397 391 398 const bool doRescale = zoomStack[zoomRectIndex] != zoomRect(); 392 399 393 d_data->zoomStack = zoomStack;394 d_data->zoomRectIndex = uint( zoomRectIndex );400 m_data->zoomStack = zoomStack; 401 m_data->zoomRectIndex = uint( zoomRectIndex ); 395 402 396 403 if ( doRescale ) … … 402 409 403 410 /*! 404 Adjust the observed plot to zoomRect() 405 406 \note Initiates QwtPlot::replot() 407 */ 411 Adjust the observed plot to zoomRect() 412 413 \note Initiates QwtPlot::replot() 414 */ 408 415 409 416 void QwtPlotZoomer::rescale() 410 417 { 411 QwtPlot *plt = plot();418 QwtPlot* plt = plot(); 412 419 if ( !plt ) 413 420 return; 414 421 415 const QRectF &rect =d_data->zoomStack[d_data->zoomRectIndex];422 const QRectF& rect = m_data->zoomStack[m_data->zoomRectIndex]; 416 423 if ( rect != scaleRect() ) 417 424 { … … 440 447 441 448 /*! 442 Reinitialize the axes, and set the zoom base to their scales. 443 444 \param xAxis X axis 445 \param yAxis Y axis 446 */ 447 448 void QwtPlotZoomer::setAx is( int xAxis, int yAxis)449 { 450 if ( xAxis != QwtPlotPicker::xAxis() || yAxis != QwtPlotPicker::yAxis() ) 451 { 452 QwtPlotPicker::setAx is( xAxis, yAxis);449 Reinitialize the axes, and set the zoom base to their scales. 450 451 \param xAxisId X axis 452 \param yAxisId Y axis 453 */ 454 455 void QwtPlotZoomer::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId ) 456 { 457 if ( xAxisId != QwtPlotPicker::xAxis() || yAxisId != QwtPlotPicker::yAxis() ) 458 { 459 QwtPlotPicker::setAxes( xAxisId, yAxisId ); 453 460 setZoomBase( scaleRect() ); 454 461 } … … 464 471 \note The mouse events can be changed, using 465 472 QwtEventPattern::setMousePattern: 2, 1 466 */ 467 void QwtPlotZoomer::widgetMouseReleaseEvent( QMouseEvent *me )473 */ 474 void QwtPlotZoomer::widgetMouseReleaseEvent( QMouseEvent* me ) 468 475 { 469 476 if ( mouseMatch( MouseSelect2, me ) ) … … 486 493 \note The keys codes can be changed, using 487 494 QwtEventPattern::setKeyPattern: 3, 4, 5 488 */ 489 490 void QwtPlotZoomer::widgetKeyPressEvent( QKeyEvent *ke )495 */ 496 497 void QwtPlotZoomer::widgetKeyPressEvent( QKeyEvent* ke ) 491 498 { 492 499 if ( !isActive() ) … … 504 511 505 512 /*! 506 Move the current zoom rectangle. 507 508 \param dx X offset 509 \param dy Y offset 510 511 \note The changed rectangle is limited by the zoom base 512 */ 513 Move the current zoom rectangle. 514 515 \param dx X offset 516 \param dy Y offset 517 518 \note The changed rectangle is limited by the zoom base 519 */ 513 520 void QwtPlotZoomer::moveBy( double dx, double dy ) 514 521 { 515 const QRectF &rect =d_data->zoomStack[d_data->zoomRectIndex];522 const QRectF& rect = m_data->zoomStack[m_data->zoomRectIndex]; 516 523 moveTo( QPointF( rect.left() + dx, rect.top() + dy ) ); 517 524 } 518 525 519 526 /*! 520 Move the the current zoom rectangle. 521 522 \param pos New position 523 524 \sa QRectF::moveTo() 525 \note The changed rectangle is limited by the zoom base 526 */ 527 void QwtPlotZoomer::moveTo( const QPointF &pos )527 Move the the current zoom rectangle. 528 529 \param pos New position 530 531 \sa QRectF::moveTo() 532 \note The changed rectangle is limited by the zoom base 533 */ 534 void QwtPlotZoomer::moveTo( const QPointF& pos ) 528 535 { 529 536 double x = pos.x(); … … 542 549 if ( x != zoomRect().left() || y != zoomRect().top() ) 543 550 { 544 d_data->zoomStack[d_data->zoomRectIndex].moveTo( x, y );551 m_data->zoomStack[m_data->zoomRectIndex].moveTo( x, y ); 545 552 rescale(); 546 553 } … … 548 555 549 556 /*! 550 \brief Check and correct a selected rectangle 551 552 Reject rectangles with a height or width < 2, otherwise 553 expand the selected rectangle to a minimum size of 11x11 554 and accept it. 555 556 \return true If the rectangle is accepted, or has been changed 557 \brief Check and correct a selected rectangle 558 559 Reject rectangles with a height or width < 2, otherwise 560 expand the selected rectangle to a minimum size of 11x11 561 and accept it. 562 563 \return true If the rectangle is accepted, or has been changed 557 564 to an accepted one. 558 */ 559 560 bool QwtPlotZoomer::accept( QPolygon &pa ) const565 */ 566 567 bool QwtPlotZoomer::accept( QPolygon& pa ) const 561 568 { 562 569 if ( pa.count() < 2 ) 563 570 return false; 564 571 565 QRect rect = QRect( pa [0], pa[int( pa.count() ) - 1]);572 QRect rect = QRect( pa.first(), pa.last() ); 566 573 rect = rect.normalized(); 567 574 … … 584 591 585 592 /*! 586 \brief Limit zooming by a minimum rectangle 587 588 \return zoomBase().width() / 10e4, zoomBase().height() / 10e4 589 */ 593 \brief Limit zooming by a minimum rectangle 594 595 \return zoomBase().width() / 10e4, zoomBase().height() / 10e4 596 */ 590 597 QSizeF QwtPlotZoomer::minZoomSize() const 591 598 { 592 return QSizeF( d_data->zoomStack[0].width() / 10e4,593 d_data->zoomStack[0].height() / 10e4 );594 } 595 596 /*! 597 Rejects selections, when the stack depth is too deep, or 598 the zoomed rectangle is minZoomSize(). 599 600 \sa minZoomSize(), maxStackDepth() 601 */ 599 return QSizeF( m_data->zoomStack[0].width() / 10e4, 600 m_data->zoomStack[0].height() / 10e4 ); 601 } 602 603 /*! 604 Rejects selections, when the stack depth is too deep, or 605 the zoomed rectangle is minZoomSize(). 606 607 \sa minZoomSize(), maxStackDepth() 608 */ 602 609 void QwtPlotZoomer::begin() 603 610 { 604 if ( d_data->maxStackDepth >= 0 )605 { 606 if ( d_data->zoomRectIndex >= uint(d_data->maxStackDepth ) )611 if ( m_data->maxStackDepth >= 0 ) 612 { 613 if ( m_data->zoomRectIndex >= uint( m_data->maxStackDepth ) ) 607 614 return; 608 615 } … … 612 619 { 613 620 const QSizeF sz = 614 d_data->zoomStack[d_data->zoomRectIndex].size() * 0.9999;621 m_data->zoomStack[m_data->zoomRectIndex].size() * 0.9999; 615 622 616 623 if ( minSize.width() >= sz.width() && … … 625 632 626 633 /*! 627 Expand the selected rectangle to minZoomSize() and zoom in 628 if accepted. 629 630 \param ok If true, complete the selection and emit selected signals 634 Expand the selected rectangle to minZoomSize() and zoom in 635 if accepted. 636 637 \param ok If true, complete the selection and emit selected signals 631 638 otherwise discard the selection. 632 639 633 \sa accept(), minZoomSize() 634 \return True if the selection has been accepted, false otherwise 635 */ 640 \sa accept(), minZoomSize() 641 \return True if the selection has been accepted, false otherwise 642 */ 636 643 bool QwtPlotZoomer::end( bool ok ) 637 644 { … … 640 647 return false; 641 648 642 QwtPlot *plot = QwtPlotZoomer::plot();649 QwtPlot* plot = QwtPlotZoomer::plot(); 643 650 if ( !plot ) 644 651 return false; 645 652 646 const QPolygon &pa = selection();653 const QPolygon& pa = selection(); 647 654 if ( pa.count() < 2 ) 648 655 return false; 649 656 650 QRect rect = QRect( pa [0], pa[int( pa.count() - 1 )]);657 QRect rect = QRect( pa.first(), pa.last() ); 651 658 rect = rect.normalized(); 652 659 … … 663 670 return true; 664 671 } 672 673 #include "moc_qwt_plot_zoomer.cpp" -
trunk/BNC/qwt/qwt_plot_zoomer.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_plot_picker.h" 15 #include <qstack.h> 15 16 class QSizeF; 17 template< typename T > class QStack; 16 18 17 19 /*! 18 \brief QwtPlotZoomer provides stacked zooming for a plot widget 20 \brief QwtPlotZoomer provides stacked zooming for a plot widget 19 21 20 QwtPlotZoomer selects rectangles from user inputs ( mouse or keyboard ) 21 translates them into plot coordinates and adjusts the axes to them. 22 The selection is supported by a rubber band and optionally by displaying 23 the coordinates of the current mouse position. 22 QwtPlotZoomer selects rectangles from user inputs ( mouse or keyboard ) 23 translates them into plot coordinates and adjusts the axes to them. 24 The selection is supported by a rubber band and optionally by displaying 25 the coordinates of the current mouse position. 24 26 25 Zooming can be repeated as often as possible, limited only by 26 maxStackDepth() or minZoomSize(). Each rectangle is pushed on a stack. 27 Zooming can be repeated as often as possible, limited only by 28 maxStackDepth() or minZoomSize(). Each rectangle is pushed on a stack. 27 29 28 The default setting how to select rectangles is 29 a QwtPickerDragRectMachine with the following bindings: 30 The default setting how to select rectangles is 31 a QwtPickerDragRectMachine with the following bindings: 30 32 31 - QwtEventPattern::MouseSelect1\n 33 - QwtEventPattern::MouseSelect1\n 32 34 The first point of the zoom rectangle is selected by a mouse press, 33 35 the second point from the position, where the mouse is released. 34 36 35 - QwtEventPattern::KeySelect1\n 37 - QwtEventPattern::KeySelect1\n 36 38 The first key press selects the first, the second key press 37 39 selects the second point. 38 40 39 - QwtEventPattern::KeyAbort\n 41 - QwtEventPattern::KeyAbort\n 40 42 Discard the selection in the state, where the first point 41 43 is selected. 42 44 43 To traverse the zoom stack the following bindings are used: 45 To traverse the zoom stack the following bindings are used: 44 46 45 - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n 47 - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n 46 48 Zoom out one position on the zoom stack 47 49 48 - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n 50 - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n 49 51 Zoom in one position on the zoom stack 50 52 51 - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n 53 - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n 52 54 Zoom to the zoom base 53 55 54 The setKeyPattern() and setMousePattern() functions can be used 55 to configure the zoomer actions. The following example 56 shows, how to configure the 'I' and 'O' keys for zooming in and out 57 one position on the zoom stack. The "Home" key is used to 58 "unzoom" the plot. 56 The setKeyPattern() and setMousePattern() functions can be used 57 to configure the zoomer actions. The following example 58 shows, how to configure the 'I' and 'O' keys for zooming in and out 59 one position on the zoom stack. The "Home" key is used to 60 "unzoom" the plot. 59 61 60 \code 62 \code 61 63 zoomer = new QwtPlotZoomer( plot ); 62 64 zoomer->setKeyPattern( QwtEventPattern::KeyRedo, Qt::Key_I, Qt::ShiftModifier ); 63 65 zoomer->setKeyPattern( QwtEventPattern::KeyUndo, Qt::Key_O, Qt::ShiftModifier ); 64 66 zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home ); 65 \endcode 67 \endcode 66 68 67 QwtPlotZoomer is tailored for plots with one x and y axis, but it is 68 allowed to attach a second QwtPlotZoomer ( without rubber band and tracker ) 69 for the other axes. 69 QwtPlotZoomer is tailored for plots with one x and y axis, but it is 70 allowed to attach a second QwtPlotZoomer ( without rubber band and tracker ) 71 for the other axes. 70 72 71 \note The realtime example includes an derived zoomer class that adds 73 \note The realtime example includes an derived zoomer class that adds 72 74 scrollbars to the plot canvas. 73 75 74 \sa QwtPlotPanner, QwtPlotMagnifier 75 */ 76 \sa QwtPlotPanner, QwtPlotMagnifier 77 */ 76 78 77 class QWT_EXPORT QwtPlotZoomer: public QwtPlotPicker 79 class QWT_EXPORT QwtPlotZoomer : public QwtPlotPicker 78 80 { 79 81 Q_OBJECT 80 public: 81 explicit QwtPlotZoomer( QWidget *, bool doReplot = true );82 explicit QwtPlotZoomer( intxAxis,intyAxis,83 QWidget*, bool doReplot = true );82 public: 83 explicit QwtPlotZoomer( QWidget*, bool doReplot = true ); 84 explicit QwtPlotZoomer( QwtAxisId xAxis, QwtAxisId yAxis, 85 QWidget*, bool doReplot = true ); 84 86 85 87 virtual ~QwtPlotZoomer(); 86 88 87 89 virtual void setZoomBase( bool doReplot = true ); 88 virtual void setZoomBase( const QRectF & );90 virtual void setZoomBase( const QRectF& ); 89 91 90 92 QRectF zoomBase() const; 91 93 QRectF zoomRect() const; 92 94 93 virtual void setAx is( intxAxis,intyAxis );95 virtual void setAxes( QwtAxisId xAxis, QwtAxisId yAxis ) QWT_OVERRIDE; 94 96 95 97 void setMaxStackDepth( int ); 96 98 int maxStackDepth() const; 97 99 98 const QStack< QRectF> &zoomStack() const;99 void setZoomStack( const QStack< QRectF>&,100 const QStack< QRectF >& zoomStack() const; 101 void setZoomStack( const QStack< QRectF >&, 100 102 int zoomRectIndex = -1 ); 101 103 102 104 uint zoomRectIndex() const; 103 105 104 public Q_SLOTS: 106 public Q_SLOTS: 105 107 void moveBy( double dx, double dy ); 106 virtual void moveTo( const QPointF & );108 virtual void moveTo( const QPointF& ); 107 109 108 virtual void zoom( const QRectF & );110 virtual void zoom( const QRectF& ); 109 111 virtual void zoom( int offset ); 110 112 111 Q_SIGNALS: 113 Q_SIGNALS: 112 114 /*! 113 A signal emitting the zoomRect(), when the plot has been 114 zoomed in or out. 115 A signal emitting the zoomRect(), when the plot has been 116 zoomed in or out. 115 117 116 \param rect Current zoom rectangle. 117 */ 118 \param rect Current zoom rectangle. 119 */ 118 120 119 void zoomed( const QRectF &rect );121 void zoomed( const QRectF& rect ); 120 122 121 protected: 123 protected: 122 124 virtual void rescale(); 123 125 124 126 virtual QSizeF minZoomSize() const; 125 127 126 virtual void widgetMouseReleaseEvent( QMouseEvent * );127 virtual void widgetKeyPressEvent( QKeyEvent * );128 virtual void widgetMouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE; 129 virtual void widgetKeyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 128 130 129 virtual void begin(); 130 virtual bool end( bool ok = true ); 131 virtual bool accept( QPolygon & ) const;131 virtual void begin() QWT_OVERRIDE; 132 virtual bool end( bool ok = true ) QWT_OVERRIDE; 133 virtual bool accept( QPolygon& ) const QWT_OVERRIDE; 132 134 133 private: 135 private: 134 136 void init( bool doReplot ); 135 137 136 138 class PrivateData; 137 PrivateData *d_data;139 PrivateData* m_data; 138 140 }; 139 141 -
trunk/BNC/qwt/qwt_point_3d.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_point_3d.h" 11 11 12 #if QT_VERSION >= 0x050200 13 14 static QwtPoint3D qwtPointToPoint3D( const QPointF& point ) 15 { 16 return QwtPoint3D( point ); 17 } 18 19 #endif 20 21 namespace 22 { 23 static const struct RegisterQwtPoint3D 24 { 25 inline RegisterQwtPoint3D() 26 { 27 qRegisterMetaType< QwtPoint3D >(); 28 29 #if QT_VERSION >= 0x050200 30 QMetaType::registerConverter< QPointF, QwtPoint3D >( qwtPointToPoint3D ); 31 #endif 32 } 33 } qwtRegisterQwtPoint3D; 34 } 35 12 36 #ifndef QT_NO_DEBUG_STREAM 13 37 14 QDebug operator<<( QDebug debug, const QwtPoint3D &point ) 38 #include <qdebug.h> 39 40 QDebug operator<<( QDebug debug, const QwtPoint3D& point ) 15 41 { 16 42 debug.nospace() << "QwtPoint3D(" << point.x() 17 << "," << point.y() << "," << point.z() << ")"; 43 << "," << point.y() << "," << point.z() << ")"; 18 44 return debug.space(); 19 45 } -
trunk/BNC/qwt/qwt_point_3d.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 /*! \file */ 11 11 #ifndef QWT_POINT_3D_H 12 #define QWT_POINT_3D_H 112 #define QWT_POINT_3D_H 13 13 14 14 #include "qwt_global.h" 15 15 #include <qpoint.h> 16 #ifndef QT_NO_DEBUG_STREAM 17 #include <qdebug.h> 18 #endif 16 #include <qmetatype.h> 19 17 20 18 /*! 21 \brief QwtPoint3D class defines a 3D point in double coordinates 22 */ 19 \brief QwtPoint3D class defines a 3D point in double coordinates 20 */ 23 21 24 22 class QWT_EXPORT QwtPoint3D 25 23 { 26 public: 24 public: 27 25 QwtPoint3D(); 28 26 QwtPoint3D( double x, double y, double z ); 29 QwtPoint3D( const QwtPoint3D & ); 30 QwtPoint3D( const QPointF & ); 27 QwtPoint3D( const QPointF& ); 31 28 32 29 bool isNull() const; … … 36 33 double z() const; 37 34 38 double &rx();39 double &ry();40 double &rz();35 double& rx(); 36 double& ry(); 37 double& rz(); 41 38 42 39 void setX( double x ); … … 46 43 QPointF toPoint() const; 47 44 48 bool operator==( const QwtPoint3D & ) const;49 bool operator!=( const QwtPoint3D & ) const;45 bool operator==( const QwtPoint3D& ) const; 46 bool operator!=( const QwtPoint3D& ) const; 50 47 51 private: 52 double d_x;53 double d_y;54 double d_z;48 private: 49 double m_x; 50 double m_y; 51 double m_z; 55 52 }; 56 53 57 Q_DECLARE_TYPEINFO(QwtPoint3D, Q_MOVABLE_TYPE); 54 Q_DECLARE_TYPEINFO( QwtPoint3D, Q_MOVABLE_TYPE ); 55 Q_DECLARE_METATYPE( QwtPoint3D ) 58 56 59 57 #ifndef QT_NO_DEBUG_STREAM 60 QWT_EXPORT QDebug operator<<( QDebug, const QwtPoint3D & );58 QWT_EXPORT QDebug operator<<( QDebug, const QwtPoint3D& ); 61 59 #endif 62 60 … … 64 62 Constructs a null point. 65 63 \sa isNull() 66 */ 67 inline QwtPoint3D::QwtPoint3D() :68 d_x( 0.0 ),69 d_y( 0.0 ),70 d_z( 0.0 )64 */ 65 inline QwtPoint3D::QwtPoint3D() 66 : m_x( 0.0 ) 67 , m_y( 0.0 ) 68 , m_z( 0.0 ) 71 69 { 72 70 } 73 71 74 72 //! Constructs a point with coordinates specified by x, y and z. 75 inline QwtPoint3D::QwtPoint3D( double x, double y, double z = 0.0 ): 76 d_x( x ), 77 d_y( y ), 78 d_z( z ) 79 { 80 } 81 82 /*! 83 Copy constructor. 84 Constructs a point using the values of the point specified. 85 */ 86 inline QwtPoint3D::QwtPoint3D( const QwtPoint3D &other ): 87 d_x( other.d_x ), 88 d_y( other.d_y ), 89 d_z( other.d_z ) 73 inline QwtPoint3D::QwtPoint3D( double x, double y, double z = 0.0 ) 74 : m_x( x ) 75 , m_y( y ) 76 , m_z( z ) 90 77 { 91 78 } … … 94 81 Constructs a point with x and y coordinates from a 2D point, 95 82 and a z coordinate of 0. 96 */ 97 inline QwtPoint3D::QwtPoint3D( const QPointF &other ):98 d_x( other.x() ),99 d_y( other.y() ),100 d_z( 0.0 )83 */ 84 inline QwtPoint3D::QwtPoint3D( const QPointF& other ) 85 : m_x( other.x() ) 86 , m_y( other.y() ) 87 , m_z( 0.0 ) 101 88 { 102 89 } … … 107 94 A point is considered to be null if x, y and z-coordinates 108 95 are equal to zero. 109 */ 96 */ 110 97 inline bool QwtPoint3D::isNull() const 111 98 { 112 return d_x == 0.0 &&d_y == 0.0 &&d_z == 0.0;99 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0; 113 100 } 114 101 … … 116 103 inline double QwtPoint3D::x() const 117 104 { 118 return d_x;105 return m_x; 119 106 } 120 107 … … 122 109 inline double QwtPoint3D::y() const 123 110 { 124 return d_y;111 return m_y; 125 112 } 126 113 … … 128 115 inline double QwtPoint3D::z() const 129 116 { 130 return d_z;117 return m_z; 131 118 } 132 119 133 120 //! \return A reference to the x-coordinate of the point. 134 inline double &QwtPoint3D::rx()121 inline double& QwtPoint3D::rx() 135 122 { 136 return d_x;123 return m_x; 137 124 } 138 125 139 126 //! \return A reference to the y-coordinate of the point. 140 inline double &QwtPoint3D::ry()127 inline double& QwtPoint3D::ry() 141 128 { 142 return d_y;129 return m_y; 143 130 } 144 131 145 132 //! \return A reference to the z-coordinate of the point. 146 inline double &QwtPoint3D::rz()133 inline double& QwtPoint3D::rz() 147 134 { 148 return d_z;135 return m_z; 149 136 } 150 137 … … 152 139 inline void QwtPoint3D::setX( double x ) 153 140 { 154 d_x = x;141 m_x = x; 155 142 } 156 143 … … 158 145 inline void QwtPoint3D::setY( double y ) 159 146 { 160 d_y = y;147 m_y = y; 161 148 } 162 149 … … 164 151 inline void QwtPoint3D::setZ( double z ) 165 152 { 166 d_z = z;153 m_z = z; 167 154 } 168 155 169 156 /*! 170 157 \return 2D point, where the z coordinate is dropped. 171 */ 158 */ 172 159 inline QPointF QwtPoint3D::toPoint() const 173 160 { 174 return QPointF( d_x, d_y );161 return QPointF( m_x, m_y ); 175 162 } 176 163 177 164 //! \return True, if this point and other are equal; otherwise returns false. 178 inline bool QwtPoint3D::operator==( const QwtPoint3D &other ) const165 inline bool QwtPoint3D::operator==( const QwtPoint3D& other ) const 179 166 { 180 return ( d_x == other.d_x ) && (d_y == other.d_y ) && (d_z == other.d_z );167 return ( m_x == other.m_x ) && ( m_y == other.m_y ) && ( m_z == other.m_z ); 181 168 } 182 169 183 170 //! \return True if this rect and other are different; otherwise returns false. 184 inline bool QwtPoint3D::operator!=( const QwtPoint3D &other ) const171 inline bool QwtPoint3D::operator!=( const QwtPoint3D& other ) const 185 172 { 186 173 return !operator==( other ); -
trunk/BNC/qwt/qwt_point_data.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_point_data.h" 11 #include "qwt_math.h"12 #include <string.h>13 14 /*!15 Constructor16 17 \param x Array of x values18 \param y Array of y values19 20 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()21 */22 QwtPointArrayData::QwtPointArrayData(23 const QVector<double> &x, const QVector<double> &y ):24 d_x( x ),25 d_y( y )26 {27 }28 29 /*!30 Constructor31 32 \param x Array of x values33 \param y Array of y values34 \param size Size of the x and y arrays35 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()36 */37 QwtPointArrayData::QwtPointArrayData( const double *x,38 const double *y, size_t size )39 {40 d_x.resize( size );41 ::memcpy( d_x.data(), x, size * sizeof( double ) );42 43 d_y.resize( size );44 ::memcpy( d_y.data(), y, size * sizeof( double ) );45 }46 47 /*!48 \brief Calculate the bounding rectangle49 50 The bounding rectangle is calculated once by iterating over all51 points and is stored for all following requests.52 53 \return Bounding rectangle54 */55 QRectF QwtPointArrayData::boundingRect() const56 {57 if ( d_boundingRect.width() < 0 )58 d_boundingRect = qwtBoundingRect( *this );59 60 return d_boundingRect;61 }62 63 //! \return Size of the data set64 size_t QwtPointArrayData::size() const65 {66 return qMin( d_x.size(), d_y.size() );67 }68 69 /*!70 Return the sample at position i71 72 \param index Index73 \return Sample at position i74 */75 QPointF QwtPointArrayData::sample( size_t index ) const76 {77 return QPointF( d_x[int( index )], d_y[int( index )] );78 }79 80 //! \return Array of the x-values81 const QVector<double> &QwtPointArrayData::xData() const82 {83 return d_x;84 }85 86 //! \return Array of the y-values87 const QVector<double> &QwtPointArrayData::yData() const88 {89 return d_y;90 }91 92 /*!93 Constructor94 95 \param x Array of x values96 \param y Array of y values97 \param size Size of the x and y arrays98 99 \warning The programmer must assure that the memory blocks referenced100 by the pointers remain valid during the lifetime of the101 QwtPlotCPointer object.102 103 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples()104 */105 QwtCPointerData::QwtCPointerData(106 const double *x, const double *y, size_t size ):107 d_x( x ),108 d_y( y ),109 d_size( size )110 {111 }112 113 /*!114 \brief Calculate the bounding rectangle115 116 The bounding rectangle is calculated once by iterating over all117 points and is stored for all following requests.118 119 \return Bounding rectangle120 */121 QRectF QwtCPointerData::boundingRect() const122 {123 if ( d_boundingRect.width() < 0 )124 d_boundingRect = qwtBoundingRect( *this );125 126 return d_boundingRect;127 }128 129 //! \return Size of the data set130 size_t QwtCPointerData::size() const131 {132 return d_size;133 }134 135 /*!136 Return the sample at position i137 138 \param index Index139 \return Sample at position i140 */141 QPointF QwtCPointerData::sample( size_t index ) const142 {143 return QPointF( d_x[int( index )], d_y[int( index )] );144 }145 146 //! \return Array of the x-values147 const double *QwtCPointerData::xData() const148 {149 return d_x;150 }151 152 //! \return Array of the y-values153 const double *QwtCPointerData::yData() const154 {155 return d_y;156 }157 11 158 12 /*! … … 163 17 164 18 \sa setInterval(), setSize() 165 */ 19 */ 166 20 QwtSyntheticPointData::QwtSyntheticPointData( 167 size_t size, const QwtInterval &interval ):168 d_size( size ),169 d_interval( interval )21 size_t size, const QwtInterval& interval ) 22 : m_size( size ) 23 , m_interval( interval ) 170 24 { 171 25 } 172 26 173 27 /*! 174 Change the number of points 28 Change the number of points 175 29 176 \param size Number of points 177 \sa size(), setInterval() 178 */ 30 \param size Number of points 31 \sa size(), setInterval() 32 */ 179 33 void QwtSyntheticPointData::setSize( size_t size ) 180 34 { 181 d_size = size;35 m_size = size; 182 36 } 183 37 184 38 /*! 185 \return Number of points 186 \sa setSize(), interval() 187 */ 39 \return Number of points 40 \sa setSize(), interval() 41 */ 188 42 size_t QwtSyntheticPointData::size() const 189 43 { 190 return d_size;44 return m_size; 191 45 } 192 46 … … 196 50 \param interval Interval 197 51 \sa interval(), setSize() 198 */ 199 void QwtSyntheticPointData::setInterval( const QwtInterval &interval )52 */ 53 void QwtSyntheticPointData::setInterval( const QwtInterval& interval ) 200 54 { 201 d_interval = interval.normalized();55 m_interval = interval.normalized(); 202 56 } 203 57 … … 205 59 \return Bounding interval 206 60 \sa setInterval(), size() 207 */ 61 */ 208 62 QwtInterval QwtSyntheticPointData::interval() const 209 63 { 210 return d_interval;64 return m_interval; 211 65 } 212 66 … … 221 75 222 76 \sa rectOfInterest() 223 */ 224 void QwtSyntheticPointData::setRectOfInterest( const QRectF &rect )77 */ 78 void QwtSyntheticPointData::setRectOfInterest( const QRectF& rect ) 225 79 { 226 d_rectOfInterest = rect;227 d_intervalOfInterest = QwtInterval(80 m_rectOfInterest = rect; 81 m_intervalOfInterest = QwtInterval( 228 82 rect.left(), rect.right() ).normalized(); 229 83 } … … 232 86 \return "rectangle of interest" 233 87 \sa setRectOfInterest() 234 */ 88 */ 235 89 QRectF QwtSyntheticPointData::rectOfInterest() const 236 90 { 237 return d_rectOfInterest;91 return m_rectOfInterest; 238 92 } 239 93 240 94 /*! 241 \brief Calculate the bounding rectangle 95 \brief Calculate the bounding rectangle 242 96 243 This implementation iterates over all points, what could often 244 be implemented much faster using the characteristics of the series. 245 When there are many points it is recommended to overload and 246 reimplement this method using the characteristics of the series 247 ( if possible ). 97 This implementation iterates over all points, what could often 98 be implemented much faster using the characteristics of the series. 99 When there are many points it is recommended to overload and 100 reimplement this method using the characteristics of the series 101 ( if possible ). 248 102 249 \return Bounding rectangle 250 */ 103 \return Bounding rectangle 104 */ 251 105 QRectF QwtSyntheticPointData::boundingRect() const 252 106 { 253 if ( d_size == 0 ||254 !( d_interval.isValid() ||d_intervalOfInterest.isValid() ) )107 if ( m_size == 0 || 108 !( m_interval.isValid() || m_intervalOfInterest.isValid() ) ) 255 109 { 256 110 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // something invalid … … 268 122 \warning For invalid indices ( index < 0 || index >= size() ) 269 123 (0, 0) is returned. 270 */ 124 */ 271 125 QPointF QwtSyntheticPointData::sample( size_t index ) const 272 126 { 273 if ( index >= d_size )127 if ( index >= m_size ) 274 128 return QPointF( 0, 0 ); 275 129 … … 291 145 292 146 \sa interval(), rectOfInterest(), y() 293 */ 147 */ 294 148 double QwtSyntheticPointData::x( uint index ) const 295 149 { 296 const QwtInterval &interval =d_interval.isValid() ?297 d_interval :d_intervalOfInterest;150 const QwtInterval& interval = m_interval.isValid() ? 151 m_interval : m_intervalOfInterest; 298 152 299 153 if ( !interval.isValid() ) 300 154 return 0.0; 301 155 302 if ( d_size <= 1 )156 if ( m_size <= 1 ) 303 157 return interval.minValue(); 304 158 305 const double dx = interval.width() / ( d_size - 1 );159 const double dx = interval.width() / ( m_size - 1 ); 306 160 return interval.minValue() + index * dx; 307 161 } -
trunk/BNC/qwt/qwt_point_data.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_POINT_DATA_H 11 #define QWT_POINT_DATA_H 111 #define QWT_POINT_DATA_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_series_data.h" 15 15 16 /*! 17 \brief Interface for iterating over two QVector<double> objects. 18 */ 19 class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF> 20 { 21 public: 22 QwtPointArrayData( const QVector<double> &x, const QVector<double> &y ); 23 QwtPointArrayData( const double *x, const double *y, size_t size ); 24 25 virtual QRectF boundingRect() const; 26 27 virtual size_t size() const; 28 virtual QPointF sample( size_t index ) const; 29 30 const QVector<double> &xData() const; 31 const QVector<double> &yData() const; 32 33 private: 34 QVector<double> d_x; 35 QVector<double> d_y; 16 #include <cstring> 17 18 /*! 19 \brief Interface for iterating over two QVector<T> objects. 20 */ 21 template< typename T > 22 class QwtPointArrayData : public QwtSeriesData< QPointF > 23 { 24 public: 25 QwtPointArrayData( const QVector< T >& x, const QVector< T >& y ); 26 QwtPointArrayData( const T* x, const T* y, size_t size ); 27 28 virtual size_t size() const QWT_OVERRIDE; 29 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 30 31 const QVector< T >& xData() const; 32 const QVector< T >& yData() const; 33 34 private: 35 QVector< T > m_x; 36 QVector< T > m_y; 36 37 }; 37 38 38 39 /*! 39 \brief Data class containing two pointers to memory blocks of doubles.40 */ 41 class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF>42 { 43 public: 44 QwtCPointerData( const double *x, const double *y, size_t size );45 46 virtual QRectF boundingRect() const; 47 virtual size_t size() const; 48 virtual QPointF sample( size_t index ) const; 49 50 const double *xData() const;51 const double *yData() const;52 53 private: 54 const double *d_x;55 const double *d_y;56 size_t d_size;40 \brief Data class containing two pointers to memory blocks of T. 41 */ 42 template< typename T > 43 class QwtCPointerData : public QwtSeriesData< QPointF > 44 { 45 public: 46 QwtCPointerData( const T* x, const T* y, size_t size ); 47 48 virtual size_t size() const QWT_OVERRIDE; 49 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 50 51 const T* xData() const; 52 const T* yData() const; 53 54 private: 55 const T* m_x; 56 const T* m_y; 57 size_t m_size; 57 58 }; 58 59 59 60 /*! 60 \brief Synthetic point data 61 62 QwtSyntheticPointData provides a fixed number of points for an interval. 63 The points are calculated in equidistant steps in x-direction. 64 65 If the interval is invalid, the points are calculated for 66 the "rectangle of interest", what normally is the displayed area on the 67 plot canvas. In this mode you get different levels of detail, when 68 zooming in/out. 69 70 \par Example 71 72 The following example shows how to implement a sinus curve. 73 74 \code 75 #include <cmath> 76 #include <qwt_series_data.h> 77 #include <qwt_plot_curve.h> 78 #include <qwt_plot.h> 79 #include <qapplication.h> 80 81 class SinusData: public QwtSyntheticPointData 82 { 83 public: 61 \brief Interface for iterating over a QVector<T>. 62 63 The memory contains the y coordinates, while the index is 64 interpreted as x coordinate. 65 */ 66 template< typename T > 67 class QwtValuePointData : public QwtSeriesData< QPointF > 68 { 69 public: 70 QwtValuePointData( const QVector< T >& y ); 71 QwtValuePointData( const T* y, size_t size ); 72 73 virtual size_t size() const QWT_OVERRIDE; 74 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 75 76 const QVector< T >& yData() const; 77 78 private: 79 QVector< T > m_y; 80 }; 81 82 /*! 83 \brief Data class containing a pointer to memory of y coordinates 84 85 The memory contains the y coordinates, while the index is 86 interpreted as x coordinate. 87 */ 88 template< typename T > 89 class QwtCPointerValueData : public QwtSeriesData< QPointF > 90 { 91 public: 92 QwtCPointerValueData( const T* y, size_t size ); 93 94 virtual size_t size() const QWT_OVERRIDE; 95 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 96 97 const T* yData() const; 98 99 private: 100 const T* m_y; 101 size_t m_size; 102 }; 103 104 /*! 105 \brief Synthetic point data 106 107 QwtSyntheticPointData provides a fixed number of points for an interval. 108 The points are calculated in equidistant steps in x-direction. 109 110 If the interval is invalid, the points are calculated for 111 the "rectangle of interest", what normally is the displayed area on the 112 plot canvas. In this mode you get different levels of detail, when 113 zooming in/out. 114 115 \par Example 116 117 The following example shows how to implement a sinus curve. 118 119 \code 120 #include <cmath> 121 #include <qwt_series_data.h> 122 #include <qwt_plot_curve.h> 123 #include <qwt_plot.h> 124 #include <qapplication.h> 125 126 class SinusData: public QwtSyntheticPointData 127 { 128 public: 84 129 SinusData(): 85 130 QwtSyntheticPointData( 100 ) … … 91 136 return qSin( x ); 92 137 } 93 }; 94 95 int main(int argc, char **argv) 96 { 138 }; 139 140 int main(int argc, char **argv) 141 { 97 142 QApplication a( argc, argv ); 98 143 99 144 QwtPlot plot; 100 plot.setAxisScale( Qwt Plot::xBottom, 0.0, 10.0 );101 plot.setAxisScale( Qwt Plot::yLeft, -1.0, 1.0 );145 plot.setAxisScale( QwtAxis::XBottom, 0.0, 10.0 ); 146 plot.setAxisScale( QwtAxis::YLeft, -1.0, 1.0 ); 102 147 103 148 QwtPlotCurve *curve = new QwtPlotCurve( "y = sin(x)" ); … … 107 152 plot.show(); 108 153 return a.exec(); 109 } 154 } 110 155 \endcode 111 */ 112 class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData< QPointF>113 { 114 public: 156 */ 157 class QWT_EXPORT QwtSyntheticPointData : public QwtSeriesData< QPointF > 158 { 159 public: 115 160 QwtSyntheticPointData( size_t size, 116 const QwtInterval & = QwtInterval() );161 const QwtInterval& = QwtInterval() ); 117 162 118 163 void setSize( size_t size ); 119 virtual size_t size() const; 164 virtual size_t size() const QWT_OVERRIDE; 120 165 121 166 void setInterval( const QwtInterval& ); 122 167 QwtInterval interval() const; 123 168 124 virtual QRectF boundingRect() const; 125 virtual QPointF sample( size_t index ) const; 169 virtual QRectF boundingRect() const QWT_OVERRIDE; 170 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 126 171 127 172 /*! … … 134 179 virtual double x( uint index ) const; 135 180 136 virtual void setRectOfInterest( const QRectF & );181 virtual void setRectOfInterest( const QRectF& ) QWT_OVERRIDE; 137 182 QRectF rectOfInterest() const; 138 183 139 private: 140 size_t d_size;141 QwtInterval d_interval;142 QRectF d_rectOfInterest;143 QwtInterval d_intervalOfInterest;184 private: 185 size_t m_size; 186 QwtInterval m_interval; 187 QRectF m_rectOfInterest; 188 QwtInterval m_intervalOfInterest; 144 189 }; 145 190 191 /*! 192 Constructor 193 194 \param x Array of x values 195 \param y Array of y values 196 197 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 198 */ 199 template< typename T > 200 QwtPointArrayData< T >::QwtPointArrayData( 201 const QVector< T >& x, const QVector< T >& y ) 202 : m_x( x ) 203 , m_y( y ) 204 { 205 } 206 207 /*! 208 Constructor 209 210 \param x Array of x values 211 \param y Array of y values 212 \param size Size of the x and y arrays 213 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 214 */ 215 template< typename T > 216 QwtPointArrayData< T >::QwtPointArrayData( const T* x, const T* y, size_t size ) 217 { 218 m_x.resize( size ); 219 std::memcpy( m_x.data(), x, size * sizeof( T ) ); 220 221 m_y.resize( size ); 222 std::memcpy( m_y.data(), y, size * sizeof( T ) ); 223 } 224 225 //! \return Size of the data set 226 template< typename T > 227 size_t QwtPointArrayData< T >::size() const 228 { 229 return qMin( m_x.size(), m_y.size() ); 230 } 231 232 /*! 233 Return the sample at position i 234 235 \param index Index 236 \return Sample at position i 237 */ 238 template< typename T > 239 QPointF QwtPointArrayData< T >::sample( size_t index ) const 240 { 241 return QPointF( m_x[int( index )], m_y[int( index )] ); 242 } 243 244 //! \return Array of the x-values 245 template< typename T > 246 const QVector< T >& QwtPointArrayData< T >::xData() const 247 { 248 return m_x; 249 } 250 251 //! \return Array of the y-values 252 template< typename T > 253 const QVector< T >& QwtPointArrayData< T >::yData() const 254 { 255 return m_y; 256 } 257 258 /*! 259 Constructor 260 261 \param y Array of y values 262 263 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 264 */ 265 template< typename T > 266 QwtValuePointData< T >::QwtValuePointData( const QVector< T >& y ) 267 : m_y( y ) 268 { 269 } 270 271 /*! 272 Constructor 273 274 \param y Array of y values 275 \param size Size of the x and y arrays 276 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 277 */ 278 template< typename T > 279 QwtValuePointData< T >::QwtValuePointData( const T* y, size_t size ) 280 { 281 m_y.resize( size ); 282 std::memcpy( m_y.data(), y, size * sizeof( T ) ); 283 } 284 285 //! \return Size of the data set 286 template< typename T > 287 size_t QwtValuePointData< T >::size() const 288 { 289 return m_y.size(); 290 } 291 292 /*! 293 Return the sample at position i 294 295 \param index Index 296 \return Sample at position i 297 */ 298 template< typename T > 299 QPointF QwtValuePointData< T >::sample( size_t index ) const 300 { 301 return QPointF( index, m_y[int( index )] ); 302 } 303 304 //! \return Array of the y-values 305 template< typename T > 306 const QVector< T >& QwtValuePointData< T >::yData() const 307 { 308 return m_y; 309 } 310 311 /*! 312 Constructor 313 314 \param x Array of x values 315 \param y Array of y values 316 \param size Size of the x and y arrays 317 318 \warning The programmer must assure that the memory blocks referenced 319 by the pointers remain valid during the lifetime of the 320 QwtPlotCPointer object. 321 322 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples() 323 */ 324 325 template< typename T > 326 QwtCPointerData< T >::QwtCPointerData( const T* x, const T* y, size_t size ) 327 : m_x( x ) 328 , m_y( y ) 329 , m_size( size ) 330 { 331 } 332 333 //! \return Size of the data set 334 template< typename T > 335 size_t QwtCPointerData< T >::size() const 336 { 337 return m_size; 338 } 339 340 /*! 341 Return the sample at position i 342 343 \param index Index 344 \return Sample at position i 345 */ 346 template< typename T > 347 QPointF QwtCPointerData< T >::sample( size_t index ) const 348 { 349 return QPointF( m_x[int( index )], m_y[int( index )] ); 350 } 351 352 //! \return Array of the x-values 353 template< typename T > 354 const T* QwtCPointerData< T >::xData() const 355 { 356 return m_x; 357 } 358 359 //! \return Array of the y-values 360 template< typename T > 361 const T* QwtCPointerData< T >::yData() const 362 { 363 return m_y; 364 } 365 366 /*! 367 Constructor 368 369 \param y Array of y values 370 \param size Size of the x and y arrays 371 372 \warning The programmer must assure that the memory blocks referenced 373 by the pointers remain valid during the lifetime of the 374 QwtCPointerValueData object. 375 376 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples() 377 */ 378 379 template< typename T > 380 QwtCPointerValueData< T >::QwtCPointerValueData( const T* y, size_t size ) 381 : m_y( y ) 382 , m_size( size ) 383 { 384 } 385 386 //! \return Size of the data set 387 template< typename T > 388 size_t QwtCPointerValueData< T >::size() const 389 { 390 return m_size; 391 } 392 393 /*! 394 Return the sample at position i 395 396 \param index Index 397 \return Sample at position i 398 */ 399 template< typename T > 400 QPointF QwtCPointerValueData< T >::sample( size_t index ) const 401 { 402 return QPointF( index, m_y[ int( index ) ] ); 403 } 404 405 //! \return Array of the y-values 406 template< typename T > 407 const T* QwtCPointerValueData< T >::yData() const 408 { 409 return m_y; 410 } 411 146 412 #endif -
trunk/BNC/qwt/qwt_point_mapper.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_map.h" 12 12 #include "qwt_pixel_matrix.h" 13 #include "qwt_series_data.h" 14 #include "qwt_math.h" 15 13 16 #include <qpolygon.h> 14 17 #include <qimage.h> … … 16 19 #include <qpainter.h> 17 20 18 #if QT_VERSION >= 0x04040019 20 21 #include <qthread.h> 21 22 #include <qfuture.h> 22 23 #include <qtconcurrentrun.h> 23 24 24 #if !defined(QT_NO_QFUTURE) 25 #if !defined( QT_NO_QFUTURE ) 25 26 #define QWT_USE_THREADS 1 26 27 #endif 27 28 29 static QRectF qwtInvalidRect( 0.0, 0.0, -1.0, -1.0 ); 30 31 static inline int qwtRoundValue( double value ) 32 { 33 return qRound( value ); 34 } 35 36 static inline double qwtRoundValueF( double value ) 37 { 38 #if 1 39 // MS Windows and at least IRIX does not have C99's nearbyint() function 40 return ( value >= 0.0 ) ? std::floor( value + 0.5 ) : std::ceil( value - 0.5 ); 41 #else 42 return nearbyint( value ); 28 43 #endif 29 30 static QRectF qwtInvalidRect( 0.0, 0.0, -1.0, -1.0 ); 44 } 45 46 static Qt::Orientation qwtProbeOrientation( 47 const QwtSeriesData< QPointF >* series, int from, int to ) 48 { 49 if ( to - from < 20 ) 50 { 51 // not enough points to "have an orientation" 52 return Qt::Horizontal; 53 } 54 55 const double x0 = series->sample( from ).x(); 56 const double xn = series->sample( to ).x(); 57 58 if ( x0 == xn ) 59 return Qt::Vertical; 60 61 const int step = ( to - from ) / 10; 62 const bool isIncreasing = xn > x0; 63 64 double x1 = x0; 65 for ( int i = from + step; i < to; i += step ) 66 { 67 const double x2 = series->sample( i ).x(); 68 if ( x2 != x1 ) 69 { 70 if ( ( x2 > x1 ) != isIncreasing ) 71 return Qt::Vertical; 72 } 73 74 x1 = x2; 75 } 76 77 return Qt::Horizontal; 78 } 79 80 namespace 81 { 82 template< class Polygon, class Point > 83 class QwtPolygonQuadrupelX 84 { 85 public: 86 inline void start( int x, int y ) 87 { 88 m_x0 = x; 89 m_y1 = m_yMin = m_yMax = m_y2 = y; 90 } 91 92 inline bool append( int x, int y ) 93 { 94 if ( m_x0 != x ) 95 return false; 96 97 if ( y < m_yMin ) 98 m_yMin = y; 99 else if ( y > m_yMax ) 100 m_yMax = y; 101 102 m_y2 = y; 103 104 return true; 105 } 106 107 inline void flush( Polygon& polyline ) 108 { 109 appendTo( m_y1, polyline ); 110 111 if ( m_y2 > m_y1 ) 112 qSwap( m_yMin, m_yMax ); 113 114 if ( m_yMax != m_y1 ) 115 appendTo( m_yMax, polyline ); 116 117 if ( m_yMin != m_yMax ) 118 appendTo( m_yMin, polyline ); 119 120 if ( m_y2 != m_yMin ) 121 appendTo( m_y2, polyline ); 122 } 123 124 private: 125 inline void appendTo( int y, Polygon& polyline ) 126 { 127 polyline += Point( m_x0, y ); 128 } 129 130 private: 131 int m_x0, m_y1, m_yMin, m_yMax, m_y2; 132 }; 133 134 template< class Polygon, class Point > 135 class QwtPolygonQuadrupelY 136 { 137 public: 138 inline void start( int x, int y ) 139 { 140 m_y0 = y; 141 m_x1 = m_xMin = m_xMax = m_x2 = x; 142 } 143 144 inline bool append( int x, int y ) 145 { 146 if ( m_y0 != y ) 147 return false; 148 149 if ( x < m_xMin ) 150 m_xMin = x; 151 else if ( x > m_xMax ) 152 m_xMax = x; 153 154 m_x2 = x; 155 156 return true; 157 } 158 159 inline void flush( Polygon& polyline ) 160 { 161 appendTo( m_x1, polyline ); 162 163 if ( m_x2 > m_x1 ) 164 qSwap( m_xMin, m_xMax ); 165 166 if ( m_xMax != m_x1 ) 167 appendTo( m_xMax, polyline ); 168 169 if ( m_xMin != m_xMax ) 170 appendTo( m_xMin, polyline ); 171 172 if ( m_x2 != m_xMin ) 173 appendTo( m_x2, polyline ); 174 } 175 176 private: 177 inline void appendTo( int x, Polygon& polyline ) 178 { 179 polyline += Point( x, m_y0 ); 180 } 181 182 int m_y0, m_x1, m_xMin, m_xMax, m_x2; 183 }; 184 } 185 186 template< class Polygon, class Point, class PolygonQuadrupel > 187 static Polygon qwtMapPointsQuad( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 188 const QwtSeriesData< QPointF >* series, int from, int to ) 189 { 190 const QPointF sample0 = series->sample( from ); 191 192 PolygonQuadrupel q; 193 q.start( qwtRoundValue( xMap.transform( sample0.x() ) ), 194 qwtRoundValue( yMap.transform( sample0.y() ) ) ); 195 196 Polygon polyline; 197 for ( int i = from; i <= to; i++ ) 198 { 199 const QPointF sample = series->sample( i ); 200 201 const int x = qwtRoundValue( xMap.transform( sample.x() ) ); 202 const int y = qwtRoundValue( yMap.transform( sample.y() ) ); 203 204 if ( !q.append( x, y ) ) 205 { 206 q.flush( polyline ); 207 q.start( x, y ); 208 } 209 } 210 q.flush( polyline ); 211 212 return polyline; 213 } 214 215 template< class Polygon, class Point, class PolygonQuadrupel > 216 static Polygon qwtMapPointsQuad( const Polygon& polyline ) 217 { 218 const int numPoints = polyline.size(); 219 220 if ( numPoints < 3 ) 221 return polyline; 222 223 const Point* points = polyline.constData(); 224 225 Polygon polylineXY; 226 227 PolygonQuadrupel q; 228 q.start( points[0].x(), points[0].y() ); 229 230 for ( int i = 0; i < numPoints; i++ ) 231 { 232 const int x = points[i].x(); 233 const int y = points[i].y(); 234 235 if ( !q.append( x, y ) ) 236 { 237 q.flush( polylineXY ); 238 q.start( x, y ); 239 } 240 } 241 q.flush( polylineXY ); 242 243 return polylineXY; 244 } 245 246 247 template< class Polygon, class Point > 248 static Polygon qwtMapPointsQuad( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 249 const QwtSeriesData< QPointF >* series, int from, int to ) 250 { 251 Polygon polyline; 252 if ( from > to ) 253 return polyline; 254 255 /* 256 probing some values, to decide if it is better 257 to start with x or y coordinates 258 */ 259 const Qt::Orientation orientation = qwtProbeOrientation( series, from, to ); 260 261 if ( orientation == Qt::Horizontal ) 262 { 263 polyline = qwtMapPointsQuad< Polygon, Point, 264 QwtPolygonQuadrupelY< Polygon, Point > >( xMap, yMap, series, from, to ); 265 266 polyline = qwtMapPointsQuad< Polygon, Point, 267 QwtPolygonQuadrupelX< Polygon, Point > >( polyline ); 268 } 269 else 270 { 271 polyline = qwtMapPointsQuad< Polygon, Point, 272 QwtPolygonQuadrupelX< Polygon, Point > >( xMap, yMap, series, from, to ); 273 274 polyline = qwtMapPointsQuad< Polygon, Point, 275 QwtPolygonQuadrupelY< Polygon, Point > >( polyline ); 276 } 277 278 return polyline; 279 } 31 280 32 281 // Helper class to work around the 5 parameters … … 34 283 class QwtDotsCommand 35 284 { 36 public: 37 const QwtSeriesData<QPointF > *series;285 public: 286 const QwtSeriesData< QPointF >* series; 38 287 int from; 39 288 int to; … … 42 291 43 292 static void qwtRenderDots( 44 const QwtScaleMap &xMap, const QwtScaleMap&yMap,45 const QwtDotsCommand command, const QPoint &pos, QImage*image )293 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 294 const QwtDotsCommand& command, const QPoint& pos, QImage* image ) 46 295 { 47 296 const QRgb rgb = command.rgb; 48 QRgb *bits = reinterpret_cast<QRgb *>( image->bits() );297 QRgb* bits = reinterpret_cast< QRgb* >( image->bits() ); 49 298 50 299 const int w = image->width(); … … 58 307 const QPointF sample = command.series->sample( i ); 59 308 60 const int x = static_cast< int>( xMap.transform( sample.x() ) + 0.5 ) - x0;61 const int y = static_cast< int>( yMap.transform( sample.y() ) + 0.5 ) - y0;309 const int x = static_cast< int >( xMap.transform( sample.x() ) + 0.5 ) - x0; 310 const int y = static_cast< int >( yMap.transform( sample.y() ) + 0.5 ) - y0; 62 311 63 312 if ( x >= 0 && x < w && y >= 0 && y < h ) … … 66 315 } 67 316 68 static inline int qwtRoundValue( double value )69 {70 return qRound( value );71 }72 73 317 // some functors, so that the compile can inline 74 318 struct QwtRoundI 75 319 { 76 inline int operator()( double value ) 320 inline int operator()( double value ) const 77 321 { 78 322 return qwtRoundValue( value ); … … 82 326 struct QwtRoundF 83 327 { 84 inline double operator()( double value ) 85 { 86 #if 1 87 // MS Windows and at least IRIX does not have C99's nearbyint() function 88 return ( value >= 0.0 ) ? ::floor( value + 0.5 ) : ::ceil( value - 0.5 ); 89 #else 90 // slightly faster than the code above 91 return nearbyint( value ); 92 #endif 328 inline double operator()( double value ) const 329 { 330 return qwtRoundValueF( value ); 93 331 } 94 332 }; … … 96 334 struct QwtNoRoundF 97 335 { 98 inline double operator()( double value ) 336 inline double operator()( double value ) const 99 337 { 100 338 return value; … … 105 343 // the bounding rectangle 106 344 107 template<class Polygon, class Point, class Round> 345 template< class Polygon, class Point, class Round > 108 346 static inline Polygon qwtToPoints( 109 const QRectF &boundingRect,110 const QwtScaleMap &xMap, const QwtScaleMap&yMap,111 const QwtSeriesData<QPointF > *series,347 const QRectF& boundingRect, 348 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 349 const QwtSeriesData< QPointF >* series, 112 350 int from, int to, Round round ) 113 351 { 114 352 Polygon polyline( to - from + 1 ); 115 Point *points = polyline.data();353 Point* points = polyline.data(); 116 354 117 355 int numPoints = 0; … … 164 402 165 403 static inline QPolygon qwtToPointsI( 166 const QRectF &boundingRect,167 const QwtScaleMap &xMap, const QwtScaleMap&yMap,168 const QwtSeriesData<QPointF > *series,404 const QRectF& boundingRect, 405 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 406 const QwtSeriesData< QPointF >* series, 169 407 int from, int to ) 170 408 { 171 return qwtToPoints<QPolygon, QPoint>( 409 return qwtToPoints< QPolygon, QPoint >( 172 410 boundingRect, xMap, yMap, series, from, to, QwtRoundI() ); 173 411 } 174 412 175 template<class Round> 413 template< class Round > 176 414 static inline QPolygonF qwtToPointsF( 177 const QRectF &boundingRect,178 const QwtScaleMap &xMap, const QwtScaleMap&yMap,179 const QwtSeriesData<QPointF > *series,415 const QRectF& boundingRect, 416 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 417 const QwtSeriesData< QPointF >* series, 180 418 int from, int to, Round round ) 181 419 { 182 return qwtToPoints<QPolygonF, QPointF>( 420 return qwtToPoints< QPolygonF, QPointF >( 183 421 boundingRect, xMap, yMap, series, from, to, round ); 184 422 } … … 187 425 // points mapped to the same position 188 426 189 template<class Polygon, class Point, class Round> 427 template< class Polygon, class Point, class Round > 190 428 static inline Polygon qwtToPolylineFiltered( 191 const QwtScaleMap &xMap, const QwtScaleMap&yMap,192 const QwtSeriesData<QPointF > *series,429 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 430 const QwtSeriesData< QPointF >* series, 193 431 int from, int to, Round round ) 194 432 { … … 199 437 200 438 Polygon polyline( to - from + 1 ); 201 Point *points = polyline.data();439 Point* points = polyline.data(); 202 440 203 441 const QPointF sample0 = series->sample( from ); … … 223 461 224 462 static inline QPolygon qwtToPolylineFilteredI( 225 const QwtScaleMap &xMap, const QwtScaleMap&yMap,226 const QwtSeriesData<QPointF > *series,463 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 464 const QwtSeriesData< QPointF >* series, 227 465 int from, int to ) 228 466 { 229 return qwtToPolylineFiltered<QPolygon, QPoint>( 467 return qwtToPolylineFiltered< QPolygon, QPoint >( 230 468 xMap, yMap, series, from, to, QwtRoundI() ); 231 469 } 232 470 233 template<class Round> 471 template< class Round > 234 472 static inline QPolygonF qwtToPolylineFilteredF( 235 const QwtScaleMap &xMap, const QwtScaleMap&yMap,236 const QwtSeriesData<QPointF > *series,473 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 474 const QwtSeriesData< QPointF >* series, 237 475 int from, int to, Round round ) 238 476 { 239 return qwtToPolylineFiltered<QPolygonF, QPointF>( 477 return qwtToPolylineFiltered< QPolygonF, QPointF >( 240 478 xMap, yMap, series, from, to, round ); 241 479 } 242 480 243 template<class Polygon, class Point> 481 template< class Polygon, class Point > 244 482 static inline Polygon qwtToPointsFiltered( 245 const QRectF &boundingRect,246 const QwtScaleMap &xMap, const QwtScaleMap&yMap,247 const QwtSeriesData<QPointF > *series, int from, int to )483 const QRectF& boundingRect, 484 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 485 const QwtSeriesData< QPointF >* series, int from, int to ) 248 486 { 249 487 // F.e. in scatter plots ( no connecting lines ) we … … 251 489 252 490 Polygon polygon( to - from + 1 ); 253 Point *points = polygon.data();491 Point* points = polygon.data(); 254 492 255 493 QwtPixelMatrix pixelMatrix( boundingRect.toAlignedRect() ); … … 277 515 278 516 static inline QPolygon qwtToPointsFilteredI( 279 const QRectF &boundingRect,280 const QwtScaleMap &xMap, const QwtScaleMap&yMap,281 const QwtSeriesData<QPointF > *series, int from, int to )282 { 283 return qwtToPointsFiltered<QPolygon, QPoint>( 517 const QRectF& boundingRect, 518 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 519 const QwtSeriesData< QPointF >* series, int from, int to ) 520 { 521 return qwtToPointsFiltered< QPolygon, QPoint >( 284 522 boundingRect, xMap, yMap, series, from, to ); 285 523 } 286 524 287 525 static inline QPolygonF qwtToPointsFilteredF( 288 const QRectF &boundingRect,289 const QwtScaleMap &xMap, const QwtScaleMap&yMap,290 const QwtSeriesData<QPointF > *series, int from, int to )291 { 292 return qwtToPointsFiltered<QPolygonF, QPointF>( 526 const QRectF& boundingRect, 527 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 528 const QwtSeriesData< QPointF >* series, int from, int to ) 529 { 530 return qwtToPointsFiltered< QPolygonF, QPointF >( 293 531 boundingRect, xMap, yMap, series, from, to ); 294 532 } … … 296 534 class QwtPointMapper::PrivateData 297 535 { 298 public: 299 PrivateData() :300 boundingRect( qwtInvalidRect ) 536 public: 537 PrivateData() 538 : boundingRect( qwtInvalidRect ) 301 539 { 302 540 } … … 309 547 QwtPointMapper::QwtPointMapper() 310 548 { 311 d_data = new PrivateData();549 m_data = new PrivateData(); 312 550 } 313 551 … … 315 553 QwtPointMapper::~QwtPointMapper() 316 554 { 317 delete d_data;318 } 319 320 /*! 321 Set the flags affecting the transformation process 322 323 \param flags Flags 324 \sa flags(), setFlag() 555 delete m_data; 556 } 557 558 /*! 559 Set the flags affecting the transformation process 560 561 \param flags Flags 562 \sa flags(), setFlag() 325 563 */ 326 564 void QwtPointMapper::setFlags( TransformationFlags flags ) 327 565 { 328 d_data->flags = flags;329 } 330 331 /*! 332 \return Flags affecting the transformation process 333 \sa setFlags(), setFlag() 566 m_data->flags = flags; 567 } 568 569 /*! 570 \return Flags affecting the transformation process 571 \sa setFlags(), setFlag() 334 572 */ 335 573 QwtPointMapper::TransformationFlags QwtPointMapper::flags() const 336 574 { 337 return d_data->flags;338 } 339 340 /*! 341 Modify a flag affecting the transformation process 342 343 \param flag Flag type 344 \param on Value 345 346 \sa flag(), setFlags() 575 return m_data->flags; 576 } 577 578 /*! 579 Modify a flag affecting the transformation process 580 581 \param flag Flag type 582 \param on Value 583 584 \sa flag(), setFlags() 347 585 */ 348 586 void QwtPointMapper::setFlag( TransformationFlag flag, bool on ) 349 587 { 350 588 if ( on ) 351 d_data->flags |= flag;589 m_data->flags |= flag; 352 590 else 353 d_data->flags &= ~flag;354 } 355 356 /*! 357 \return True, when the flag is set 358 \param flag Flag type 359 \sa setFlag(), setFlags() 591 m_data->flags &= ~flag; 592 } 593 594 /*! 595 \return True, when the flag is set 596 \param flag Flag type 597 \sa setFlag(), setFlags() 360 598 */ 361 599 bool QwtPointMapper::testFlag( TransformationFlag flag ) const 362 600 { 363 return d_data->flags & flag;364 } 365 366 /*! 367 Set a bounding rectangle for the point mapping algorithm 368 369 A valid bounding rectangle can be used for optimizations 370 371 \param rect Bounding rectangle 372 \sa boundingRect() 373 */ 374 void QwtPointMapper::setBoundingRect( const QRectF &rect )375 { 376 d_data->boundingRect = rect;377 } 378 379 /*! 380 \return Bounding rectangle 381 \sa setBoundingRect() 601 return m_data->flags & flag; 602 } 603 604 /*! 605 Set a bounding rectangle for the point mapping algorithm 606 607 A valid bounding rectangle can be used for optimizations 608 609 \param rect Bounding rectangle 610 \sa boundingRect() 611 */ 612 void QwtPointMapper::setBoundingRect( const QRectF& rect ) 613 { 614 m_data->boundingRect = rect; 615 } 616 617 /*! 618 \return Bounding rectangle 619 \sa setBoundingRect() 382 620 */ 383 621 QRectF QwtPointMapper::boundingRect() const 384 622 { 385 return d_data->boundingRect; 386 } 387 388 /*! 389 \brief Translate a series of points into a QPolygonF 390 391 When the WeedOutPoints flag is enabled consecutive points, 392 that are mapped to the same position will be one point. 393 394 When RoundPoints is set all points are rounded to integers 395 but returned as PolygonF - what only makes sense 396 when the further processing of the values need a QPolygonF. 397 398 \param xMap x map 399 \param yMap y map 400 \param series Series of points to be mapped 401 \param from Index of the first point to be painted 402 \param to Index of the last point to be painted 403 404 \return Translated polygon 405 */ 623 return m_data->boundingRect; 624 } 625 626 /*! 627 \brief Translate a series of points into a QPolygonF 628 629 When the WeedOutPoints flag is enabled consecutive points, 630 that are mapped to the same position will be one point. 631 632 When RoundPoints is set all points are rounded to integers 633 but returned as PolygonF - what only makes sense 634 when the further processing of the values need a QPolygonF. 635 636 When RoundPoints & WeedOutIntermediatePoints is enabled an even more 637 aggressive weeding algorithm is enabled. 638 639 \param xMap x map 640 \param yMap y map 641 \param series Series of points to be mapped 642 \param from Index of the first point to be painted 643 \param to Index of the last point to be painted 644 645 \return Translated polygon 646 */ 406 647 QPolygonF QwtPointMapper::toPolygonF( 407 const QwtScaleMap &xMap, const QwtScaleMap&yMap,408 const QwtSeriesData<QPointF > *series, int from, int to ) const648 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 649 const QwtSeriesData< QPointF >* series, int from, int to ) const 409 650 { 410 651 QPolygonF polyline; 411 652 412 if ( d_data->flags & WeedOutPoints ) 413 { 414 if ( d_data->flags & RoundPoints ) 653 if ( m_data->flags & RoundPoints ) 654 { 655 if ( m_data->flags & WeedOutIntermediatePoints ) 656 { 657 polyline = qwtMapPointsQuad< QPolygonF, QPointF >( 658 xMap, yMap, series, from, to ); 659 } 660 else if ( m_data->flags & WeedOutPoints ) 415 661 { 416 662 polyline = qwtToPolylineFilteredF( … … 419 665 else 420 666 { 667 polyline = qwtToPointsF( qwtInvalidRect, 668 xMap, yMap, series, from, to, QwtRoundF() ); 669 } 670 } 671 else 672 { 673 if ( m_data->flags & WeedOutPoints ) 674 { 421 675 polyline = qwtToPolylineFilteredF( 422 676 xMap, yMap, series, from, to, QwtNoRoundF() ); 423 677 } 424 }425 else426 {427 if ( d_data->flags & RoundPoints )428 {429 polyline = qwtToPointsF( qwtInvalidRect,430 xMap, yMap, series, from, to, QwtRoundF() );431 }432 678 else 433 679 { … … 441 687 442 688 /*! 443 \brief Translate a series of points into a QPolygon 444 445 When the WeedOutPoints flag is enabled consecutive points, 446 that are mapped to the same position will be one point. 447 448 \param xMap x map 449 \param yMap y map 450 \param series Series of points to be mapped 451 \param from Index of the first point to be painted 452 \param to Index of the last point to be painted 453 454 \return Translated polygon 455 */ 689 \brief Translate a series of points into a QPolygon 690 691 When the WeedOutPoints flag is enabled consecutive points, 692 that are mapped to the same position will be one point. 693 694 \param xMap x map 695 \param yMap y map 696 \param series Series of points to be mapped 697 \param from Index of the first point to be painted 698 \param to Index of the last point to be painted 699 700 \return Translated polygon 701 */ 456 702 QPolygon QwtPointMapper::toPolygon( 457 const QwtScaleMap &xMap, const QwtScaleMap&yMap,458 const QwtSeriesData<QPointF > *series, int from, int to ) const703 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 704 const QwtSeriesData< QPointF >* series, int from, int to ) const 459 705 { 460 706 QPolygon polyline; 461 707 462 if ( d_data->flags & WeedOutPoints ) 708 if ( m_data->flags & WeedOutIntermediatePoints ) 709 { 710 // TODO WeedOutIntermediatePointsY ... 711 polyline = qwtMapPointsQuad< QPolygon, QPoint >( 712 xMap, yMap, series, from, to ); 713 } 714 else if ( m_data->flags & WeedOutPoints ) 463 715 { 464 716 polyline = qwtToPolylineFilteredI( … … 475 727 476 728 /*! 477 \brief Translate a series into a QPolygonF 478 479 - WeedOutPoints & RoundPoints & boundingRect().isValid() 729 \brief Translate a series into a QPolygonF 730 731 - WeedOutPoints & RoundPoints & boundingRect().isValid() 480 732 All points that are mapped to the same position 481 733 will be one point. Points outside of the bounding 482 734 rectangle are ignored. 483 735 484 - WeedOutPoints & RoundPoints & !boundingRect().isValid() 736 - WeedOutPoints & RoundPoints & !boundingRect().isValid() 485 737 All consecutive points that are mapped to the same position 486 738 will one point 487 739 488 - WeedOutPoints & !RoundPoints 740 - WeedOutPoints & !RoundPoints 489 741 All consecutive points that are mapped to the same position 490 742 will one point 491 743 492 - !WeedOutPoints & boundingRect().isValid() 744 - !WeedOutPoints & boundingRect().isValid() 493 745 Points outside of the bounding rectangle are ignored. 494 746 495 When RoundPoints is set all points are rounded to integers 496 but returned as PolygonF - what only makes sense 497 when the further processing of the values need a QPolygonF. 498 499 \param xMap x map 500 \param yMap y map 501 \param series Series of points to be mapped 502 \param from Index of the first point to be painted 503 \param to Index of the last point to be painted 504 505 \return Translated polygon 506 */ 747 When RoundPoints is set all points are rounded to integers 748 but returned as PolygonF - what only makes sense 749 when the further processing of the values need a QPolygonF. 750 751 \param xMap x map 752 \param yMap y map 753 \param series Series of points to be mapped 754 \param from Index of the first point to be painted 755 \param to Index of the last point to be painted 756 757 \return Translated polygon 758 */ 507 759 QPolygonF QwtPointMapper::toPointsF( 508 const QwtScaleMap &xMap, const QwtScaleMap&yMap,509 const QwtSeriesData<QPointF > *series, int from, int to ) const760 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 761 const QwtSeriesData< QPointF >* series, int from, int to ) const 510 762 { 511 763 QPolygonF points; 512 764 513 if ( d_data->flags & WeedOutPoints )514 { 515 if ( d_data->flags & RoundPoints )516 { 517 if ( d_data->boundingRect.isValid() )765 if ( m_data->flags & WeedOutPoints ) 766 { 767 if ( m_data->flags & RoundPoints ) 768 { 769 if ( m_data->boundingRect.isValid() ) 518 770 { 519 points = qwtToPointsFilteredF( d_data->boundingRect,771 points = qwtToPointsFilteredF( m_data->boundingRect, 520 772 xMap, yMap, series, from, to ); 521 773 } … … 541 793 else 542 794 { 543 if ( d_data->flags & RoundPoints )544 { 545 points = qwtToPointsF( d_data->boundingRect,795 if ( m_data->flags & RoundPoints ) 796 { 797 points = qwtToPointsF( m_data->boundingRect, 546 798 xMap, yMap, series, from, to, QwtRoundF() ); 547 799 } 548 800 else 549 801 { 550 points = qwtToPointsF( d_data->boundingRect,802 points = qwtToPointsF( m_data->boundingRect, 551 803 xMap, yMap, series, from, to, QwtNoRoundF() ); 552 804 } … … 557 809 558 810 /*! 559 \brief Translate a series of points into a QPolygon 560 561 - WeedOutPoints & boundingRect().isValid() 811 \brief Translate a series of points into a QPolygon 812 813 - WeedOutPoints & boundingRect().isValid() 562 814 All points that are mapped to the same position 563 815 will be one point. Points outside of the bounding 564 816 rectangle are ignored. 565 817 566 - WeedOutPoints & !boundingRect().isValid() 818 - WeedOutPoints & !boundingRect().isValid() 567 819 All consecutive points that are mapped to the same position 568 820 will one point 569 821 570 - !WeedOutPoints & boundingRect().isValid() 822 - !WeedOutPoints & boundingRect().isValid() 571 823 Points outside of the bounding rectangle are ignored. 572 824 573 \param xMap x map 574 \param yMap y map 575 \param series Series of points to be mapped 576 \param from Index of the first point to be painted 577 \param to Index of the last point to be painted 578 579 \return Translated polygon 580 */ 825 \param xMap x map 826 \param yMap y map 827 \param series Series of points to be mapped 828 \param from Index of the first point to be painted 829 \param to Index of the last point to be painted 830 831 \return Translated polygon 832 */ 581 833 QPolygon QwtPointMapper::toPoints( 582 const QwtScaleMap &xMap, const QwtScaleMap&yMap,583 const QwtSeriesData<QPointF > *series, int from, int to ) const834 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 835 const QwtSeriesData< QPointF >* series, int from, int to ) const 584 836 { 585 837 QPolygon points; 586 838 587 if ( d_data->flags & WeedOutPoints )588 { 589 if ( d_data->boundingRect.isValid() )590 { 591 points = qwtToPointsFilteredI( d_data->boundingRect,839 if ( m_data->flags & WeedOutPoints ) 840 { 841 if ( m_data->boundingRect.isValid() ) 842 { 843 points = qwtToPointsFilteredI( m_data->boundingRect, 592 844 xMap, yMap, series, from, to ); 593 845 } … … 604 856 { 605 857 points = qwtToPointsI( 606 d_data->boundingRect, xMap, yMap, series, from, to );858 m_data->boundingRect, xMap, yMap, series, from, to ); 607 859 } 608 860 … … 612 864 613 865 /*! 614 \brief Translate a series into a QImage 615 616 \param xMap x map 617 \param yMap y map 618 \param series Series of points to be mapped 619 \param from Index of the first point to be painted 620 \param to Index of the last point to be painted 621 \param pen Pen used for drawing a point 866 \brief Translate a series into a QImage 867 868 \param xMap x map 869 \param yMap y map 870 \param series Series of points to be mapped 871 \param from Index of the first point to be painted 872 \param to Index of the last point to be painted 873 \param pen Pen used for drawing a point 622 874 of the image, where a point is mapped to 623 \param antialiased True, when the dots should be displayed 875 \param antialiased True, when the dots should be displayed 624 876 antialiased 625 \param numThreads Number of threads to be used for rendering. 877 \param numThreads Number of threads to be used for rendering. 626 878 If numThreads is set to 0, the system specific 627 879 ideal thread count is used. 628 880 629 \return Image displaying the series 630 */ 881 \return Image displaying the series 882 */ 631 883 QImage QwtPointMapper::toImage( 632 const QwtScaleMap &xMap, const QwtScaleMap&yMap,633 const QwtSeriesData<QPointF > *series, int from, int to,634 const QPen &pen, bool antialiased, uint numThreads ) const884 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 885 const QwtSeriesData< QPointF >* series, int from, int to, 886 const QPen& pen, bool antialiased, uint numThreads ) const 635 887 { 636 888 Q_UNUSED( antialiased ) … … 649 901 // where every sample is mapped to one pixel only. 650 902 651 const QRect rect = d_data->boundingRect.toAlignedRect();903 const QRect rect = m_data->boundingRect.toAlignedRect(); 652 904 653 905 QImage image( rect.size(), QImage::Format_ARGB32 ); … … 663 915 const int numPoints = ( to - from + 1 ) / numThreads; 664 916 665 QList< QFuture< void> > futures;917 QList< QFuture< void > > futures; 666 918 for ( uint i = 0; i < numThreads; i++ ) 667 919 { -
trunk/BNC/qwt/qwt_point_mapper.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_series_data.h"15 #include <qimage.h>16 14 17 15 class QwtScaleMap; 16 template< typename T > class QwtSeriesData; 18 17 class QPolygonF; 18 class QPointF; 19 class QRectF; 19 20 class QPolygon; 21 class QPen; 22 class QImage; 20 23 21 24 /*! 22 \brief A helper class for translating a series of points 25 \brief A helper class for translating a series of points 23 26 24 QwtPointMapper is a collection of methods and optimizations 25 for translating a series of points into paint device coordinates. 26 It is used by QwtPlotCurve but might also be useful for 27 similar plot items displaying a QwtSeriesData<QPointF>. 27 QwtPointMapper is a collection of methods and optimizations 28 for translating a series of points into paint device coordinates. 29 It is used by QwtPlotCurve but might also be useful for 30 similar plot items displaying a QwtSeriesData<QPointF>. 28 31 */ 29 32 class QWT_EXPORT QwtPointMapper 30 33 { 31 public: 34 public: 32 35 /*! 33 \brief Flags affecting the transformation process 34 \sa setFlag(), setFlags() 36 \brief Flags affecting the transformation process 37 \sa setFlag(), setFlags() 35 38 */ 36 39 enum TransformationFlag … … 40 43 41 44 /*! 42 Try to remove points, that are translated to the 43 same position. 45 Try to remove points, that are translated to the 46 same position. 44 47 */ 45 WeedOutPoints = 0x02 48 WeedOutPoints = 0x02, 49 50 /*! 51 An even more aggressive weeding algorithm, that 52 can be used in toPolygon(). 53 54 A consecutive chunk of points being mapped to the 55 same x coordinate is reduced to 4 points: 56 57 - first point 58 - point with the minimum y coordinate 59 - point with the maximum y coordinate 60 - last point 61 62 In the worst case ( first and last points are never one of the extremes ) 63 the number of points will be 4 times the width. 64 65 As the algorithm is fast it can be used inside of 66 a polyline render cycle. 67 */ 68 WeedOutIntermediatePoints = 0x04 46 69 }; 47 70 48 /*! 49 \brief Flags affecting the transformation process 50 \sa setFlag(), setFlags() 51 */ 52 typedef QFlags<TransformationFlag> TransformationFlags; 71 Q_DECLARE_FLAGS( TransformationFlags, TransformationFlag ) 53 72 54 73 QwtPointMapper(); … … 61 80 bool testFlag( TransformationFlag ) const; 62 81 63 void setBoundingRect( const QRectF & );82 void setBoundingRect( const QRectF& ); 64 83 QRectF boundingRect() const; 65 84 66 QPolygonF toPolygonF( const QwtScaleMap &xMap, const QwtScaleMap&yMap,67 const QwtSeriesData<QPointF > *series, int from, int to ) const;85 QPolygonF toPolygonF( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 86 const QwtSeriesData< QPointF >* series, int from, int to ) const; 68 87 69 QPolygon toPolygon( const QwtScaleMap &xMap, const QwtScaleMap&yMap,70 const QwtSeriesData<QPointF > *series, int from, int to ) const;88 QPolygon toPolygon( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 89 const QwtSeriesData< QPointF >* series, int from, int to ) const; 71 90 72 QPolygon toPoints( const QwtScaleMap &xMap, const QwtScaleMap&yMap,73 const QwtSeriesData<QPointF > *series, int from, int to ) const;91 QPolygon toPoints( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 92 const QwtSeriesData< QPointF >* series, int from, int to ) const; 74 93 75 QPolygonF toPointsF( const QwtScaleMap &xMap, const QwtScaleMap&yMap,76 const QwtSeriesData<QPointF > *series, int from, int to ) const;94 QPolygonF toPointsF( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 95 const QwtSeriesData< QPointF >* series, int from, int to ) const; 77 96 78 QImage toImage( const QwtScaleMap &xMap, const QwtScaleMap&yMap,79 const QwtSeriesData<QPointF > *series, int from, int to,80 const QPen &, bool antialiased, uint numThreads ) const;97 QImage toImage( const QwtScaleMap& xMap, const QwtScaleMap& yMap, 98 const QwtSeriesData< QPointF >* series, int from, int to, 99 const QPen&, bool antialiased, uint numThreads ) const; 81 100 82 private: 101 private: 102 Q_DISABLE_COPY(QwtPointMapper) 103 83 104 class PrivateData; 84 PrivateData *d_data;105 PrivateData* m_data; 85 106 }; 86 107 -
trunk/BNC/qwt/qwt_point_polar.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * QwtPolar Widget Library 3 3 * Copyright (C) 2008 Uwe Rathmann … … 10 10 #include "qwt_math.h" 11 11 12 #if QT_VERSION < 0x040601 13 #define qAtan2(y, x) ::atan2(y, x) 12 #if QT_VERSION >= 0x050200 13 14 static QwtPointPolar qwtPointToPolar( const QPointF& point ) 15 { 16 return QwtPointPolar( point ); 17 } 18 14 19 #endif 20 21 namespace 22 { 23 static const struct RegisterQwtPointPolar 24 { 25 inline RegisterQwtPointPolar() 26 { 27 qRegisterMetaType< QwtPointPolar >(); 28 29 #if QT_VERSION >= 0x050200 30 QMetaType::registerConverter< QPointF, QwtPointPolar >( qwtPointToPolar ); 31 QMetaType::registerConverter< QwtPointPolar, QPointF >( &QwtPointPolar::toPoint ); 32 #endif 33 } 34 35 } qwtRegisterQwtPointPolar; 36 } 15 37 16 38 /*! … … 19 41 \param p Point in Cartesian coordinates 20 42 \sa setPoint(), toPoint() 21 */ 22 QwtPointPolar::QwtPointPolar( const QPointF &p )43 */ 44 QwtPointPolar::QwtPointPolar( const QPointF& p ) 23 45 { 24 d_radius =qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );25 d_azimuth =qAtan2( p.y(), p.x() );46 m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) ); 47 m_azimuth = std::atan2( p.y(), p.x() ); 26 48 } 27 49 … … 29 51 Convert and assign values from a point in Cartesian coordinates 30 52 \param p Point in Cartesian coordinates 31 */ 32 void QwtPointPolar::setPoint( const QPointF &p )53 */ 54 void QwtPointPolar::setPoint( const QPointF& p ) 33 55 { 34 d_radius =qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );35 d_azimuth =qAtan2( p.y(), p.x() );56 m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) ); 57 m_azimuth = std::atan2( p.y(), p.x() ); 36 58 } 37 59 … … 43 65 \note Invalid or null points will be returned as QPointF(0.0, 0.0) 44 66 \sa isValid(), isNull() 45 */ 67 */ 46 68 QPointF QwtPointPolar::toPoint() const 47 69 { 48 if ( d_radius <= 0.0 )70 if ( m_radius <= 0.0 ) 49 71 return QPointF( 0.0, 0.0 ); 50 72 51 const double x = d_radius *qCos( d_azimuth );52 const double y = d_radius *qSin( d_azimuth );73 const double x = m_radius * std::cos( m_azimuth ); 74 const double y = m_radius * std::sin( m_azimuth ); 53 75 54 76 return QPointF( x, y ); … … 65 87 66 88 \sa normalized() 67 */ 68 bool QwtPointPolar::operator==( const QwtPointPolar &other ) const89 */ 90 bool QwtPointPolar::operator==( const QwtPointPolar& other ) const 69 91 { 70 return d_radius == other.d_radius &&d_azimuth == other.d_azimuth;92 return m_radius == other.m_radius && m_azimuth == other.m_azimuth; 71 93 } 72 94 … … 80 102 \return True if the point is not equal to other; otherwise return false. 81 103 \sa normalized() 82 */ 83 bool QwtPointPolar::operator!=( const QwtPointPolar &other ) const104 */ 105 bool QwtPointPolar::operator!=( const QwtPointPolar& other ) const 84 106 { 85 return d_radius != other.d_radius ||d_azimuth != other.d_azimuth;107 return m_radius != other.m_radius || m_azimuth != other.m_azimuth; 86 108 } 87 109 … … 93 115 94 116 \return Normalized point 95 */ 117 */ 96 118 QwtPointPolar QwtPointPolar::normalized() const 97 119 { 98 const double radius = q Max( d_radius, 0.0 );120 const double radius = qwtMaxF( m_radius, 0.0 ); 99 121 100 double azimuth = d_azimuth;122 double azimuth = m_azimuth; 101 123 if ( azimuth < -2.0 * M_PI || azimuth >= 2 * M_PI ) 102 azimuth = ::fmod( d_azimuth, 2 * M_PI );124 azimuth = std::fmod( m_azimuth, 2 * M_PI ); 103 125 104 126 if ( azimuth < 0.0 ) … … 110 132 #ifndef QT_NO_DEBUG_STREAM 111 133 112 QDebug operator<<( QDebug debug, const QwtPointPolar &point ) 134 #include <qdebug.h> 135 136 QDebug operator<<( QDebug debug, const QwtPointPolar& point ) 113 137 { 114 138 debug.nospace() << "QwtPointPolar(" 115 << point.azimuth() << "," << point.radius() << ")"; 139 << point.azimuth() << "," << point.radius() << ")"; 116 140 117 141 return debug.space(); -
trunk/BNC/qwt/qwt_point_polar.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 /*! \file */ 11 #ifndef _QWT_POINT_POLAR_H_12 #define _QWT_POINT_POLAR_H_ 111 #ifndef QWT_POINT_POLAR_H 12 #define QWT_POINT_POLAR_H 13 13 14 14 #include "qwt_global.h" 15 15 #include "qwt_math.h" 16 16 17 #include <qpoint.h> 17 #ifndef QT_NO_DEBUG_STREAM 18 #include <qdebug.h> 19 #endif 18 #include <qmetatype.h> 19 #include <qmath.h> 20 20 21 21 /*! 22 \brief A point in polar coordinates 22 \brief A point in polar coordinates 23 23 24 In polar coordinates a point is determined by an angle and a distance. 25 See http://en.wikipedia.org/wiki/Polar_coordinate_system 26 */ 24 In polar coordinates a point is determined by an angle and a distance. 25 See http://en.wikipedia.org/wiki/Polar_coordinate_system 26 */ 27 27 28 28 class QWT_EXPORT QwtPointPolar 29 29 { 30 public: 30 public: 31 31 QwtPointPolar(); 32 32 QwtPointPolar( double azimuth, double radius ); 33 QwtPointPolar( const QPointF & );33 QwtPointPolar( const QPointF& ); 34 34 35 void setPoint( const QPointF & );35 void setPoint( const QPointF& ); 36 36 QPointF toPoint() const; 37 37 … … 42 42 double azimuth() const; 43 43 44 double &rRadius();45 double &rAzimuth();44 double& rRadius(); 45 double& rAzimuth(); 46 46 47 47 void setRadius( double ); 48 48 void setAzimuth( double ); 49 49 50 bool operator==( const QwtPointPolar & ) const;51 bool operator!=( const QwtPointPolar & ) const;50 bool operator==( const QwtPointPolar& ) const; 51 bool operator!=( const QwtPointPolar& ) const; 52 52 53 53 QwtPointPolar normalized() const; 54 54 55 double _value; // Change by LM 55 private: 56 double m_azimuth; 57 double m_radius; 58 }; 56 59 57 private: 58 double d_azimuth; 59 double d_radius; 60 }; 60 Q_DECLARE_TYPEINFO( QwtPointPolar, Q_MOVABLE_TYPE ); 61 Q_DECLARE_METATYPE( QwtPointPolar ) 62 63 #ifndef QT_NO_DEBUG_STREAM 64 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar& ); 65 #endif 61 66 62 67 /*! 63 68 Constructs a null point, with a radius and azimuth set to 0.0. 64 69 \sa QPointF::isNull() 65 */ 66 inline QwtPointPolar::QwtPointPolar() :67 d_azimuth( 0.0 ),68 d_radius( 0.0 )70 */ 71 inline QwtPointPolar::QwtPointPolar() 72 : m_azimuth( 0.0 ) 73 , m_radius( 0.0 ) 69 74 { 70 75 } … … 75 80 \param azimuth Azimuth 76 81 \param radius Radius 77 */ 78 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ) :79 d_azimuth( azimuth ),80 d_radius( radius )82 */ 83 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ) 84 : m_azimuth( azimuth ) 85 , m_radius( radius ) 81 86 { 82 87 } … … 85 90 inline bool QwtPointPolar::isValid() const 86 91 { 87 return d_radius >= 0.0;92 return m_radius >= 0.0; 88 93 } 89 94 … … 91 96 inline bool QwtPointPolar::isNull() const 92 97 { 93 return d_radius == 0.0;98 return m_radius == 0.0; 94 99 } 95 100 … … 97 102 inline double QwtPointPolar::radius() const 98 103 { 99 return d_radius;104 return m_radius; 100 105 } 101 106 … … 103 108 inline double QwtPointPolar::azimuth() const 104 109 { 105 return d_azimuth;110 return m_azimuth; 106 111 } 107 112 108 113 //! Returns the radius. 109 inline double &QwtPointPolar::rRadius()114 inline double& QwtPointPolar::rRadius() 110 115 { 111 return d_radius;116 return m_radius; 112 117 } 113 118 114 119 //! Returns the azimuth. 115 inline double &QwtPointPolar::rAzimuth()120 inline double& QwtPointPolar::rAzimuth() 116 121 { 117 return d_azimuth;122 return m_azimuth; 118 123 } 119 124 … … 121 126 inline void QwtPointPolar::setRadius( double radius ) 122 127 { 123 d_radius = radius;128 m_radius = radius; 124 129 } 125 130 126 //! Sets the a timuth to atimuth.131 //! Sets the azimuth to azimuth. 127 132 inline void QwtPointPolar::setAzimuth( double azimuth ) 128 133 { 129 d_azimuth = azimuth;134 m_azimuth = azimuth; 130 135 } 131 136 132 #ifndef QT_NO_DEBUG_STREAM 133 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & ); 134 #endif 135 136 inline QPoint qwtPolar2Pos( const QPoint &pole, 137 inline QPoint qwtPolar2Pos( const QPoint& pole, 137 138 double radius, double angle ) 138 139 { 139 const double x = pole.x() + radius * qCos( angle );140 const double y = pole.y() - radius * qSin( angle );140 const double x = pole.x() + radius * std::cos( angle ); 141 const double y = pole.y() - radius * std::sin( angle ); 141 142 142 143 return QPoint( qRound( x ), qRound( y ) ); 143 144 } 144 145 145 inline QPoint qwtDegree2Pos( const QPoint &pole,146 inline QPoint qwtDegree2Pos( const QPoint& pole, 146 147 double radius, double angle ) 147 148 { … … 149 150 } 150 151 151 inline QPointF qwtPolar2Pos( const QPointF &pole,152 inline QPointF qwtPolar2Pos( const QPointF& pole, 152 153 double radius, double angle ) 153 154 { 154 const double x = pole.x() + radius * qCos( angle );155 const double y = pole.y() - radius * qSin( angle );155 const double x = pole.x() + radius * std::cos( angle ); 156 const double y = pole.y() - radius * std::sin( angle ); 156 157 157 158 return QPointF( x, y); 158 159 } 159 160 160 inline QPointF qwtDegree2Pos( const QPointF &pole,161 inline QPointF qwtDegree2Pos( const QPointF& pole, 161 162 double radius, double angle ) 162 163 { … … 164 165 } 165 166 166 inline QPointF qwtFastPolar2Pos( const QPointF &pole,167 inline QPointF qwtFastPolar2Pos( const QPointF& pole, 167 168 double radius, double angle ) 168 169 { 169 #if QT_VERSION < 0x040601170 const double x = pole.x() + radius * ::cos( angle );171 const double y = pole.y() - radius * ::sin( angle );172 #else173 170 const double x = pole.x() + radius * qFastCos( angle ); 174 171 const double y = pole.y() - radius * qFastSin( angle ); 175 #endif176 172 177 173 return QPointF( x, y); 178 174 } 179 175 180 inline QPointF qwtFastDegree2Pos( const QPointF &pole,176 inline QPointF qwtFastDegree2Pos( const QPointF& pole, 181 177 double radius, double angle ) 182 178 { … … 184 180 } 185 181 186 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )182 inline QwtPointPolar qwtFastPos2Polar( const QPointF& pos ) 187 183 { 188 184 return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ), -
trunk/BNC/qwt/qwt_raster_data.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_raster_data.h" 11 11 #include "qwt_point_3d.h" 12 #include "qwt_interval.h" 13 14 #include <qrect.h> 15 #include <qpolygon.h> 12 16 #include <qnumeric.h> 17 #include <qlist.h> 18 #include <qmap.h> 13 19 14 20 class QwtRasterData::ContourPlane 15 21 { 16 public: 17 inline ContourPlane( double z ): 18 d_z( z )22 public: 23 explicit inline ContourPlane( double z ): 24 m_z( z ) 19 25 { 20 26 } … … 23 29 QPointF line[2], bool ignoreOnPlane ) const; 24 30 25 inline double z() const { return d_z; }26 27 private: 31 inline double z() const { return m_z; } 32 33 private: 28 34 inline int compare( double z ) const; 29 35 inline QPointF intersection( 30 const QwtPoint3D& p1, const QwtPoint3D &p2 ) const;31 32 double d_z;36 const QwtPoint3D& p1, const QwtPoint3D& p2 ) const; 37 38 double m_z; 33 39 }; 34 40 … … 65 71 }; 66 72 67 const int edgeType = tab[eq1 +1][eq2+1][eq3+1];73 const int edgeType = tab[eq1 + 1][eq2 + 1][eq3 + 1]; 68 74 switch ( edgeType ) 69 75 { … … 135 141 inline int QwtRasterData::ContourPlane::compare( double z ) const 136 142 { 137 if ( z > d_z )143 if ( z > m_z ) 138 144 return 1; 139 145 140 if ( z < d_z )146 if ( z < m_z ) 141 147 return -1; 142 148 … … 145 151 146 152 inline QPointF QwtRasterData::ContourPlane::intersection( 147 const QwtPoint3D& p1, const QwtPoint3D &p2 ) const148 { 149 const double h1 = p1.z() - d_z;150 const double h2 = p2.z() - d_z;153 const QwtPoint3D& p1, const QwtPoint3D& p2 ) const 154 { 155 const double h1 = p1.z() - m_z; 156 const double h2 = p2.z() - m_z; 151 157 152 158 const double x = ( h2 * p1.x() - h1 * p2.x() ) / ( h2 - h1 ); … … 156 162 } 157 163 164 class QwtRasterData::PrivateData 165 { 166 public: 167 QwtRasterData::Attributes attributes; 168 }; 169 158 170 //! Constructor 159 171 QwtRasterData::QwtRasterData() 160 172 { 173 m_data = new PrivateData(); 161 174 } 162 175 … … 164 177 QwtRasterData::~QwtRasterData() 165 178 { 166 } 167 168 /*! 169 Set the bounding interval for the x, y or z coordinates. 170 171 \param axis Axis 172 \param interval Bounding interval 173 174 \sa interval() 175 */ 176 void QwtRasterData::setInterval( Qt::Axis axis, const QwtInterval &interval ) 177 { 178 d_intervals[axis] = interval; 179 } 180 181 /*! 182 \brief Initialize a raster 183 184 Before the composition of an image QwtPlotSpectrogram calls initRaster(), 185 announcing the area and its resolution that will be requested. 186 187 The default implementation does nothing, but for data sets that 188 are stored in files, it might be good idea to reimplement initRaster(), 189 where the data is resampled and loaded into memory. 190 191 \param area Area of the raster 192 \param raster Number of horizontal and vertical pixels 193 194 \sa initRaster(), value() 195 */ 196 void QwtRasterData::initRaster( const QRectF &area, const QSize &raster ) 179 delete m_data; 180 } 181 182 /*! 183 Specify an attribute of the data 184 185 \param attribute Attribute 186 \param on On/Off 187 /sa Attribute, testAttribute() 188 */ 189 void QwtRasterData::setAttribute( Attribute attribute, bool on ) 190 { 191 if ( on ) 192 m_data->attributes |= attribute; 193 else 194 m_data->attributes &= ~attribute; 195 } 196 197 /*! 198 \return True, when attribute is enabled 199 \sa Attribute, setAttribute() 200 */ 201 bool QwtRasterData::testAttribute( Attribute attribute ) const 202 { 203 return m_data->attributes & attribute; 204 } 205 206 /*! 207 \brief Initialize a raster 208 209 Before the composition of an image QwtPlotSpectrogram calls initRaster(), 210 announcing the area and its resolution that will be requested. 211 212 The default implementation does nothing, but for data sets that 213 are stored in files, it might be good idea to reimplement initRaster(), 214 where the data is resampled and loaded into memory. 215 216 \param area Area of the raster 217 \param raster Number of horizontal and vertical pixels 218 219 \sa initRaster(), value() 220 */ 221 void QwtRasterData::initRaster( const QRectF& area, const QSize& raster ) 197 222 { 198 223 Q_UNUSED( area ); … … 201 226 202 227 /*! 203 \brief Discard a raster 204 205 After the composition of an image QwtPlotSpectrogram calls discardRaster(). 206 207 The default implementation does nothing, but if data has been loaded 208 in initRaster(), it could deleted now. 209 210 \sa initRaster(), value() 211 */ 228 \brief Discard a raster 229 230 After the composition of an image QwtPlotSpectrogram calls discardRaster(). 231 232 The default implementation does nothing, but if data has been loaded 233 in initRaster(), it could deleted now. 234 235 \sa initRaster(), value() 236 */ 212 237 void QwtRasterData::discardRaster() 213 238 { … … 239 264 240 265 \return Bounding rectangle of a pixel 241 */ 242 QRectF QwtRasterData::pixelHint( const QRectF &area ) const266 */ 267 QRectF QwtRasterData::pixelHint( const QRectF& area ) const 243 268 { 244 269 Q_UNUSED( area ); … … 258 283 An adaption of CONREC, a simple contouring algorithm. 259 284 http://local.wasp.uwa.edu.au/~pbourke/papers/conrec/ 260 */ 285 */ 261 286 QwtRasterData::ContourLines QwtRasterData::contourLines( 262 const QRectF &rect, const QSize&raster,263 const QList< double> &levels, ConrecFlags flags ) const287 const QRectF& rect, const QSize& raster, 288 const QList< double >& levels, ConrecFlags flags ) const 264 289 { 265 290 ContourLines contourLines; … … 279 304 ignoreOutOfRange = flags & IgnoreOutOfRange; 280 305 281 QwtRasterData *that = const_cast<QwtRasterData*>( this );306 QwtRasterData* that = const_cast< QwtRasterData* >( this ); 282 307 that->initRaster( rect, raster ); 283 284 #if __GNUC__ >= 9285 #pragma GCC diagnostic push286 #pragma GCC diagnostic ignored "-Wdeprecated-copy"287 #endif288 308 289 309 for ( int y = 0; y < raster.height() - 1; y++ ) … … 313 333 xy[TopRight].setZ( 314 334 value( xy[TopRight].x(), xy[TopRight].y() ) 315 ); 335 ); 316 336 317 337 xy[BottomRight].setX( pos.x() ); … … 319 339 xy[BottomRight].setZ( 320 340 value( xy[BottomRight].x(), xy[BottomRight].y() ) 321 ); 341 ); 322 342 } 323 343 … … 332 352 xy[TopRight].setZ( 333 353 value( xy[TopRight].x(), xy[TopRight].y() ) 334 ); 354 ); 335 355 xy[BottomRight].setZ( 336 356 value( xy[BottomRight].x(), xy[BottomRight].y() ) 337 ); 357 ); 338 358 339 359 double zMin = xy[TopLeft].z(); … … 380 400 if ( level < zMin || level > zMax ) 381 401 continue; 382 QPolygonF &lines = contourLines[level];402 QPolygonF& lines = contourLines[level]; 383 403 const ContourPlane plane( level ); 384 404 … … 404 424 } 405 425 406 #if __GNUC__ >= 9407 #pragma GCC diagnostic pop408 #endif409 410 426 that->discardRaster(); 411 427 -
trunk/BNC/qwt/qwt_raster_data.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_RASTER_DATA_H 11 #define QWT_RASTER_DATA_H 111 #define QWT_RASTER_DATA_H 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h" 15 #include <qmap.h> 16 #include <qlist.h> 17 #include <qpolygon.h> 14 #include <qnamespace.h> 18 15 19 class QwtScaleMap; 16 class QwtInterval; 17 class QPolygonF; 18 class QRectF; 19 class QSize; 20 template< typename T > class QList; 21 template< class Key, class T > class QMap; 20 22 21 23 /*! 22 \brief QwtRasterData defines an interface to any type of raster data. 24 \brief QwtRasterData defines an interface to any type of raster data. 23 25 24 QwtRasterData is an abstract interface, that is used by 25 QwtPlotRasterItem to find the values at the pixels of its raster. 26 QwtRasterData is an abstract interface, that is used by 27 QwtPlotRasterItem to find the values at the pixels of its raster. 26 28 27 Often a raster item is used to display values from a matrix. Then the 28 derived raster data class needs to implement some sort of resampling, 29 that maps the raster of the matrix into the requested raster of 30 the raster item ( depending on resolution and scales of the canvas ). 31 */ 29 Gaps inside the bounding rectangle of the data can be indicated by NaN 30 values ( when WithoutGaps is disabled ). 31 32 Often a raster item is used to display values from a matrix. Then the 33 derived raster data class needs to implement some sort of resampling, 34 that maps the raster of the matrix into the requested raster of 35 the raster item ( depending on resolution and scales of the canvas ). 36 37 QwtMatrixRasterData implements raster data, that returns values from 38 a given 2D matrix. 39 40 \sa QwtMatrixRasterData 41 */ 32 42 class QWT_EXPORT QwtRasterData 33 43 { 34 public: 44 public: 35 45 //! Contour lines 36 typedef QMap<double, QPolygonF> ContourLines; 46 typedef QMap< double, QPolygonF > ContourLines; 47 48 /*! 49 \brief Raster data attributes 50 51 Additional information that is used to improve processing 52 of the data. 53 */ 54 enum Attribute 55 { 56 /*! 57 The bounding rectangle of the data is spanned by 58 the interval(Qt::XAxis) and interval(Qt::YAxis). 59 60 WithoutGaps indicates, that the data has no gaps 61 ( unknown values ) in this area and the result of 62 value() does not need to be checked for NaN values. 63 64 Enabling this flag will have an positive effect on 65 the performance of rendering a QwtPlotSpectrogram. 66 67 The default setting is false. 68 69 \note NaN values indicate an undefined value 70 */ 71 WithoutGaps = 0x01 72 }; 73 74 Q_DECLARE_FLAGS( Attributes, Attribute ) 37 75 38 76 //! Flags to modify the contour algorithm … … 46 84 }; 47 85 48 //! Flags to modify the contour algorithm 49 typedef QFlags<ConrecFlag> ConrecFlags; 86 Q_DECLARE_FLAGS( ConrecFlags, ConrecFlag ) 50 87 51 88 QwtRasterData(); 52 89 virtual ~QwtRasterData(); 53 90 54 v irtual void setInterval( Qt::Axis, const QwtInterval &);55 const QwtInterval &interval(Qt::Axis) const;91 void setAttribute( Attribute, bool on = true ); 92 bool testAttribute( Attribute ) const; 56 93 57 virtual QRectF pixelHint( const QRectF & ) const; 94 /*! 95 \return Bounding interval for an axis 96 \sa setInterval 97 */ 98 virtual QwtInterval interval( Qt::Axis ) const = 0; 58 99 59 virtual void initRaster( const QRectF &, const QSize& raster ); 100 virtual QRectF pixelHint( const QRectF& ) const; 101 102 virtual void initRaster( const QRectF&, const QSize& raster ); 60 103 virtual void discardRaster(); 61 104 … … 64 107 \param x X value in plot coordinates 65 108 \param y Y value in plot coordinates 66 */ 109 */ 67 110 virtual double value( double x, double y ) const = 0; 68 111 69 virtual ContourLines contourLines( const QRectF &rect,70 const QSize &raster, const QList<double> &levels,112 virtual ContourLines contourLines( const QRectF& rect, 113 const QSize& raster, const QList< double >& levels, 71 114 ConrecFlags ) const; 72 115 … … 74 117 class ContourPlane; 75 118 76 private: 77 // Disabled copy constructor and operator= 78 QwtRasterData( const QwtRasterData & ); 79 QwtRasterData &operator=( const QwtRasterData & ); 119 private: 120 Q_DISABLE_COPY(QwtRasterData) 80 121 81 QwtInterval d_intervals[3]; 122 class PrivateData; 123 PrivateData* m_data; 82 124 }; 83 125 84 /*!85 \return Bounding interval for a axis86 \sa setInterval87 */88 inline const QwtInterval &QwtRasterData::interval( Qt::Axis axis) const89 {90 return d_intervals[axis];91 }92 93 126 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtRasterData::ConrecFlags ) 127 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtRasterData::Attributes ) 94 128 95 129 #endif -
trunk/BNC/qwt/qwt_round_scale_draw.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_scale_div.h" 13 13 #include "qwt_scale_map.h" 14 #include "qwt_text.h" 14 15 #include "qwt_math.h" 15 #include <qpen.h> 16 16 17 #include <qpainter.h> 17 #include <qfontmetrics.h>18 #include <qmath.h>19 18 20 19 class QwtRoundScaleDraw::PrivateData 21 20 { 22 public: 23 PrivateData() :24 center( 50.0, 50.0 ) ,25 radius( 50.0 ) ,26 startAngle( -135.0 ) ,27 endAngle( 135.0 ) 21 public: 22 PrivateData() 23 : center( 50.0, 50.0 ) 24 , radius( 50.0 ) 25 , startAngle( -135.0 ) 26 , endAngle( 135.0 ) 28 27 { 29 28 } … … 37 36 38 37 /*! 39 \brief Constructor 40 41 The range of the scale is initialized to [0, 100], 42 The center is set to (50, 50) with a radius of 50. 43 The angle range is set to [-135, 135]. 44 */ 38 \brief Constructor 39 40 The range of the scale is initialized to [0, 100], 41 The center is set to (50, 50) with a radius of 50. 42 The angle range is set to [-135, 135]. 43 */ 45 44 QwtRoundScaleDraw::QwtRoundScaleDraw() 46 45 { 47 d_data = new QwtRoundScaleDraw::PrivateData;46 m_data = new QwtRoundScaleDraw::PrivateData; 48 47 49 48 setRadius( 50 ); 50 scaleMap().setPaintInterval( d_data->startAngle,d_data->endAngle );49 scaleMap().setPaintInterval( m_data->startAngle, m_data->endAngle ); 51 50 } 52 51 … … 54 53 QwtRoundScaleDraw::~QwtRoundScaleDraw() 55 54 { 56 delete d_data;57 } 58 59 /*! 60 Change of radius the scale 61 62 Radius is the radius of the backbone without ticks and labels. 63 64 \param radius New Radius 65 \sa moveCenter() 66 */ 55 delete m_data; 56 } 57 58 /*! 59 Change of radius the scale 60 61 Radius is the radius of the backbone without ticks and labels. 62 63 \param radius New Radius 64 \sa moveCenter() 65 */ 67 66 void QwtRoundScaleDraw::setRadius( double radius ) 68 67 { 69 d_data->radius = radius;70 } 71 72 /*! 73 Get the radius 74 75 Radius is the radius of the backbone without ticks and labels. 76 77 \return Radius of the scale 78 \sa setRadius(), extent() 79 */ 68 m_data->radius = radius; 69 } 70 71 /*! 72 Get the radius 73 74 Radius is the radius of the backbone without ticks and labels. 75 76 \return Radius of the scale 77 \sa setRadius(), extent() 78 */ 80 79 double QwtRoundScaleDraw::radius() const 81 80 { 82 return d_data->radius;81 return m_data->radius; 83 82 } 84 83 … … 88 87 \param center New center 89 88 \sa setRadius() 90 */ 91 void QwtRoundScaleDraw::moveCenter( const QPointF ¢er )92 { 93 d_data->center = center;89 */ 90 void QwtRoundScaleDraw::moveCenter( const QPointF& center ) 91 { 92 m_data->center = center; 94 93 } 95 94 … … 97 96 QPointF QwtRoundScaleDraw::center() const 98 97 { 99 return d_data->center;100 } 101 102 /*! 103 \brief Adjust the baseline circle segment for round scales. 104 105 The baseline will be drawn from min(angle1,angle2) to max(angle1, angle2). 106 The default setting is [ -135, 135 ]. 107 An angle of 0 degrees corresponds to the 12 o'clock position, 108 and positive angles count in a clockwise direction. 109 \param angle1 110 \param angle2 boundaries of the angle interval in degrees. 111 \warning <ul> 112 <li>The angle range is limited to [-360, 360] degrees. Angles exceeding 98 return m_data->center; 99 } 100 101 /*! 102 \brief Adjust the baseline circle segment for round scales. 103 104 The baseline will be drawn from min(angle1,angle2) to max(angle1, angle2). 105 The default setting is [ -135, 135 ]. 106 An angle of 0 degrees corresponds to the 12 o'clock position, 107 and positive angles count in a clockwise direction. 108 \param angle1 109 \param angle2 boundaries of the angle interval in degrees. 110 \warning <ul> 111 <li>The angle range is limited to [-360, 360] degrees. Angles exceeding 113 112 this range will be clipped. 114 <li>For angles more or equal than 360 degrees above or below min(angle1, angle2), 113 <li>For angles more or equal than 360 degrees above or below min(angle1, angle2), 115 114 scale marks will not be drawn. 116 <li>If you need a counterclockwise scale, use QwtScaleDiv::setInterval() 117 </ul> 118 */ 115 <li>If you need a counterclockwise scale, use QwtScaleDiv::setInterval() 116 </ul> 117 */ 119 118 void QwtRoundScaleDraw::setAngleRange( double angle1, double angle2 ) 120 119 { … … 124 123 #endif 125 124 126 d_data->startAngle = angle1;127 d_data->endAngle = angle2;128 129 if ( d_data->startAngle ==d_data->endAngle )130 { 131 d_data->startAngle -= 1;132 d_data->endAngle += 1;133 } 134 135 scaleMap().setPaintInterval( d_data->startAngle,d_data->endAngle );125 m_data->startAngle = angle1; 126 m_data->endAngle = angle2; 127 128 if ( m_data->startAngle == m_data->endAngle ) 129 { 130 m_data->startAngle -= 1; 131 m_data->endAngle += 1; 132 } 133 134 scaleMap().setPaintInterval( m_data->startAngle, m_data->endAngle ); 136 135 } 137 136 … … 143 142 144 143 \sa drawTick(), drawBackbone() 145 */ 146 void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const144 */ 145 void QwtRoundScaleDraw::drawLabel( QPainter* painter, double value ) const 147 146 { 148 147 const double tval = scaleMap().transform( value ); 149 if ( ( tval >= d_data->startAngle + 360.0 )150 || ( tval <= d_data->startAngle - 360.0 ) )148 if ( ( tval >= m_data->startAngle + 360.0 ) 149 || ( tval <= m_data->startAngle - 360.0 ) ) 151 150 { 152 151 return; … … 157 156 return; 158 157 159 double radius = d_data->radius;158 double radius = m_data->radius; 160 159 if ( hasComponent( QwtAbstractScaleDraw::Ticks ) || 161 160 hasComponent( QwtAbstractScaleDraw::Backbone ) ) … … 170 169 const double arc = qwtRadians( tval ); 171 170 172 const double x = d_data->center.x() +173 ( radius + sz.width() / 2.0 ) * qSin( arc );174 const double y = d_data->center.y() -175 ( radius + sz.height() / 2.0 ) * qCos( arc );171 const double x = m_data->center.x() + 172 ( radius + sz.width() / 2.0 ) * std::sin( arc ); 173 const double y = m_data->center.y() - 174 ( radius + sz.height() / 2.0 ) * std::cos( arc ); 176 175 177 176 const QRectF r( x - sz.width() / 2, y - sz.height() / 2, … … 188 187 189 188 \sa drawBackbone(), drawLabel() 190 */ 191 void QwtRoundScaleDraw::drawTick( QPainter *painter, double value, double len ) const189 */ 190 void QwtRoundScaleDraw::drawTick( QPainter* painter, double value, double len ) const 192 191 { 193 192 if ( len <= 0 ) … … 196 195 const double tval = scaleMap().transform( value ); 197 196 198 const double cx = d_data->center.x();199 const double cy = d_data->center.y();200 const double radius = d_data->radius;201 202 if ( ( tval < d_data->startAngle + 360.0 )203 && ( tval > d_data->startAngle - 360.0 ) )197 const double cx = m_data->center.x(); 198 const double cy = m_data->center.y(); 199 const double radius = m_data->radius; 200 201 if ( ( tval < m_data->startAngle + 360.0 ) 202 && ( tval > m_data->startAngle - 360.0 ) ) 204 203 { 205 204 const double arc = qwtRadians( tval ); 206 205 207 const double sinArc = qSin( arc );208 const double cosArc = qCos( arc );206 const double sinArc = std::sin( arc ); 207 const double cosArc = std::cos( arc ); 209 208 210 209 const double x1 = cx + radius * sinArc; … … 222 221 223 222 \sa drawTick(), drawLabel() 224 */ 225 void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const223 */ 224 void QwtRoundScaleDraw::drawBackbone( QPainter* painter ) const 226 225 { 227 226 const double deg1 = scaleMap().p1(); 228 227 const double deg2 = scaleMap().p2(); 229 228 230 const int a1 = qRound( q Min( deg1, deg2 ) - 90 );231 const int a2 = qRound( q Max( deg1, deg2 ) - 90 );232 233 const double radius = d_data->radius;234 const double x = d_data->center.x() - radius;235 const double y = d_data->center.y() - radius;229 const int a1 = qRound( qwtMinF( deg1, deg2 ) - 90 ); 230 const int a2 = qRound( qwtMaxF( deg1, deg2 ) - 90 ); 231 232 const double radius = m_data->radius; 233 const double x = m_data->center.x() - radius; 234 const double y = m_data->center.y() - radius; 236 235 237 236 painter->drawArc( QRectF( x, y, 2 * radius, 2 * radius ), … … 253 252 calculates only an upper limit, that might be a 254 253 few pixels too large 255 */ 256 double QwtRoundScaleDraw::extent( const QFont &font ) const254 */ 255 double QwtRoundScaleDraw::extent( const QFont& font ) const 257 256 { 258 257 double d = 0.0; … … 260 259 if ( hasComponent( QwtAbstractScaleDraw::Labels ) ) 261 260 { 262 const QwtScaleDiv &sd = scaleDiv();263 const QList< double> &ticks = sd.ticks( QwtScaleDiv::MajorTick );261 const QwtScaleDiv& sd = scaleDiv(); 262 const QList< double >& ticks = sd.ticks( QwtScaleDiv::MajorTick ); 264 263 for ( int i = 0; i < ticks.count(); i++ ) 265 264 { … … 269 268 270 269 const double tval = scaleMap().transform( value ); 271 if ( ( tval < d_data->startAngle + 360 )272 && ( tval > d_data->startAngle - 360 ) )270 if ( ( tval < m_data->startAngle + 360 ) 271 && ( tval > m_data->startAngle - 360 ) ) 273 272 { 274 273 const QwtText label = tickLabel( font, value ); … … 281 280 const double off = qMax( sz.width(), sz.height() ); 282 281 283 double x = off * qSin( arc );284 double y = off * qCos( arc );285 286 const double dist = qSqrt( x * x + y * y );282 double x = off * std::sin( arc ); 283 double y = off * std::cos( arc ); 284 285 const double dist = std::sqrt( x * x + y * y ); 287 286 if ( dist > d ) 288 287 d = dist; … … 298 297 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 299 298 { 300 const double pw = qMax( 1, penWidth() ); // pen width can be zero 301 d += pw; 299 d += qwtMaxF( penWidthF(), 1.0 ); 302 300 } 303 301 304 302 if ( hasComponent( QwtAbstractScaleDraw::Labels ) && 305 303 ( hasComponent( QwtAbstractScaleDraw::Ticks ) || 306 hasComponent( QwtAbstractScaleDraw::Backbone ) ) )304 hasComponent( QwtAbstractScaleDraw::Backbone ) ) ) 307 305 { 308 306 d += spacing(); 309 307 } 310 308 311 d = q Max( d, minimumExtent() );309 d = qwtMaxF( d, minimumExtent() ); 312 310 313 311 return d; -
trunk/BNC/qwt/qwt_round_scale_draw.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_abstract_scale_draw.h" 15 15 16 #include <qpoint.h> 16 17 17 18 /*! 18 \brief A class for drawing round scales 19 \brief A class for drawing round scales 19 20 20 QwtRoundScaleDraw can be used to draw round scales. 21 The circle segment can be adjusted by setAngleRange(). 22 The geometry of the scale can be specified with 23 moveCenter() and setRadius(). 21 QwtRoundScaleDraw can be used to draw round scales. 22 The circle segment can be adjusted by setAngleRange(). 23 The geometry of the scale can be specified with 24 moveCenter() and setRadius(). 24 25 25 After a scale division has been specified as a QwtScaleDiv object 26 using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), 27 the scale can be drawn with the QwtAbstractScaleDraw::draw() member. 28 */ 26 After a scale division has been specified as a QwtScaleDiv object 27 using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), 28 the scale can be drawn with the QwtAbstractScaleDraw::draw() member. 29 */ 29 30 30 class QWT_EXPORT QwtRoundScaleDraw: public QwtAbstractScaleDraw 31 class QWT_EXPORT QwtRoundScaleDraw : public QwtAbstractScaleDraw 31 32 { 32 public: 33 public: 33 34 QwtRoundScaleDraw(); 34 35 virtual ~QwtRoundScaleDraw(); … … 38 39 39 40 void moveCenter( double x, double y ); 40 void moveCenter( const QPointF & );41 void moveCenter( const QPointF& ); 41 42 QPointF center() const; 42 43 43 44 void setAngleRange( double angle1, double angle2 ); 44 45 45 virtual double extent( const QFont & ) const;46 virtual double extent( const QFont& ) const QWT_OVERRIDE; 46 47 47 protected: 48 virtual void drawTick( QPainter *, double value, double len ) const; 49 virtual void drawBackbone( QPainter * ) const; 50 virtual void drawLabel( QPainter *, double val ) const; 48 protected: 49 virtual void drawTick( QPainter*, 50 double value, double len ) const QWT_OVERRIDE; 51 51 52 private: 53 QwtRoundScaleDraw( const QwtRoundScaleDraw & ); 54 QwtRoundScaleDraw &operator=( const QwtRoundScaleDraw &other ); 52 virtual void drawBackbone( 53 QPainter* ) const QWT_OVERRIDE; 55 54 55 virtual void drawLabel( 56 QPainter*, double value ) const QWT_OVERRIDE; 57 58 private: 56 59 class PrivateData; 57 PrivateData *d_data;60 PrivateData* m_data; 58 61 }; 59 62 -
trunk/BNC/qwt/qwt_samples.h
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_SAMPLES_H 11 #define QWT_SAMPLES_H 111 #define QWT_SAMPLES_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_interval.h" 15 15 16 #include <qvector.h> 16 17 #include <qrect.h> … … 19 20 class QWT_EXPORT QwtIntervalSample 20 21 { 21 public: 22 public: 22 23 QwtIntervalSample(); 23 QwtIntervalSample( double, const QwtInterval & );24 QwtIntervalSample( double, const QwtInterval& ); 24 25 QwtIntervalSample( double value, double min, double max ); 25 26 26 bool operator==( const QwtIntervalSample & ) const;27 bool operator!=( const QwtIntervalSample & ) const;27 bool operator==( const QwtIntervalSample& ) const; 28 bool operator!=( const QwtIntervalSample& ) const; 28 29 29 30 //! Value … … 35 36 36 37 /*! 37 Constructor 38 The value is set to 0.0, the interval is invalid 39 */ 40 inline QwtIntervalSample::QwtIntervalSample() :41 value( 0.0 ) 38 Constructor 39 The value is set to 0.0, the interval is invalid 40 */ 41 inline QwtIntervalSample::QwtIntervalSample() 42 : value( 0.0 ) 42 43 { 43 44 } 44 45 45 46 //! Constructor 46 inline QwtIntervalSample::QwtIntervalSample( 47 double v, const QwtInterval &intv ): 48 value( v ), 49 interval( intv ) 47 inline QwtIntervalSample::QwtIntervalSample( double v, const QwtInterval& intv ) 48 : value( v ) 49 , interval( intv ) 50 50 { 51 51 } 52 52 53 53 //! Constructor 54 inline QwtIntervalSample::QwtIntervalSample( 55 double v, double min, double max ): 56 value( v ), 57 interval( min, max ) 54 inline QwtIntervalSample::QwtIntervalSample( double v, double min, double max ) 55 : value( v ) 56 , interval( min, max ) 58 57 { 59 58 } 60 59 61 60 //! Compare operator 62 inline bool QwtIntervalSample::operator==( 63 const QwtIntervalSample &other ) const 61 inline bool QwtIntervalSample::operator==( const QwtIntervalSample& other ) const 64 62 { 65 63 return value == other.value && interval == other.interval; … … 67 65 68 66 //! Compare operator 69 inline bool QwtIntervalSample::operator!=( 70 const QwtIntervalSample &other ) const 67 inline bool QwtIntervalSample::operator!=( const QwtIntervalSample& other ) const 71 68 { 72 69 return !( *this == other ); … … 76 73 class QWT_EXPORT QwtSetSample 77 74 { 78 public: 75 public: 79 76 QwtSetSample(); 80 QwtSetSample( double, const QVector< double>& = QVector<double>() );81 82 bool operator==( const QwtSetSample &other ) const;83 bool operator!=( const QwtSetSample &other ) const;77 explicit QwtSetSample( double, const QVector< double >& = QVector< double >( ) ); 78 79 bool operator==( const QwtSetSample& other ) const; 80 bool operator!=( const QwtSetSample& other ) const; 84 81 85 82 double added() const; … … 89 86 90 87 //! Vector of values associated to value 91 QVector< double> set;88 QVector< double > set; 92 89 }; 93 90 94 91 /*! 95 Constructor 96 The value is set to 0.0 97 */ 98 inline QwtSetSample::QwtSetSample() :99 value( 0.0 ) 100 { 101 } 102 103 /*! 104 Constructor 105 106 \param v Value 107 \param s Set of values 108 */ 109 inline QwtSetSample::QwtSetSample( double v, const QVector< double > &s ):110 value( v ) ,111 set( s ) 92 Constructor 93 The value is set to 0.0 94 */ 95 inline QwtSetSample::QwtSetSample() 96 : value( 0.0 ) 97 { 98 } 99 100 /*! 101 Constructor 102 103 \param v Value 104 \param s Set of values 105 */ 106 inline QwtSetSample::QwtSetSample( double v, const QVector< double >& s ) 107 : value( v ) 108 , set( s ) 112 109 { 113 110 } 114 111 115 112 //! Compare operator 116 inline bool QwtSetSample::operator==( const QwtSetSample &other ) const113 inline bool QwtSetSample::operator==( const QwtSetSample& other ) const 117 114 { 118 115 return value == other.value && set == other.set; … … 120 117 121 118 //! Compare operator 122 inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const119 inline bool QwtSetSample::operator!=( const QwtSetSample& other ) const 123 120 { 124 121 return !( *this == other ); … … 143 140 144 141 \sa QwtTradingChartData 145 */ 142 */ 146 143 class QWT_EXPORT QwtOHLCSample 147 144 { 148 public: 145 public: 149 146 QwtOHLCSample( double time = 0.0, 150 147 double open = 0.0, double high = 0.0, … … 156 153 157 154 /*! 158 Time of the sample, usually a number representing 159 a specific interval - like a day. 160 */ 155 Time of the sample, usually a number representing 156 a specific interval - like a day. 157 */ 161 158 double time; 162 159 … … 174 171 }; 175 172 176 177 /*! 178 Constructor 179 180 \param t Time value 181 \param o Open value 182 \param h High value 183 \param l Low value 184 \param c Close value 185 */ 186 inline QwtOHLCSample::QwtOHLCSample( double t, 187 double o, double h, double l, double c ): 188 time( t ), 189 open( o ), 190 high( h ), 191 low( l ), 192 close( c ) 193 { 194 } 195 196 /*! 197 \brief Check if a sample is valid 198 199 A sample is valid, when all of the following checks are true: 200 201 - low <= high 202 - low <= open <= high 203 - low <= close <= high 204 205 \return True, when the sample is valid 173 /*! 174 Constructor 175 176 \param t Time value 177 \param o Open value 178 \param h High value 179 \param l Low value 180 \param c Close value 181 */ 182 inline QwtOHLCSample::QwtOHLCSample( 183 double t, double o, double h, double l, double c ) 184 : time( t ) 185 , open( o ) 186 , high( h ) 187 , low( l ) 188 , close( c ) 189 { 190 } 191 192 /*! 193 \brief Check if a sample is valid 194 195 A sample is valid, when all of the following checks are true: 196 197 - low <= high 198 - low <= open <= high 199 - low <= close <= high 200 201 \return True, when the sample is valid 206 202 */ 207 203 inline bool QwtOHLCSample::isValid() const 208 204 { 209 205 return ( low <= high ) 210 && ( open >= low ) 211 && ( open <= high ) 212 && ( close >= low ) 213 && ( close <= high ); 206 && ( open >= low ) 207 && ( open <= high ) 208 && ( close >= low ) 209 && ( close <= high ); 214 210 } 215 211 … … 237 233 } 238 234 235 /*! 236 \brief Sample used in vector fields 237 238 A vector field sample is a position and a vector - usually 239 representing some direction and magnitude - attached to this position. 240 241 \sa QwtVectorFieldData 242 */ 243 class QWT_EXPORT QwtVectorFieldSample 244 { 245 public: 246 QwtVectorFieldSample( double x = 0.0, double y = 0.0, 247 double vx = 0.0, double vy = 0.0 ); 248 249 QwtVectorFieldSample( const QPointF& pos, 250 double vx = 0.0, double vy = 0.0 ); 251 252 QPointF pos() const; 253 254 bool isNull() const; 255 256 //! x coordinate of the position 257 double x; 258 259 //! y coordinate of the position 260 double y; 261 262 //! x coordinate of the vector 263 double vx; 264 265 //! y coordinate of the vector 266 double vy; 267 }; 268 269 /*! 270 \brief Constructor 271 272 \param posX x coordinate of the position 273 \param posY y coordinate of the position 274 \param vectorX x coordinate of the vector 275 \param vectorY y coordinate of the vector 276 */ 277 inline QwtVectorFieldSample::QwtVectorFieldSample( 278 double posX, double posY, double vectorX, double vectorY ) 279 : x( posX ) 280 , y( posY ) 281 , vx( vectorX ) 282 , vy( vectorY ) 283 { 284 } 285 286 /*! 287 \brief Constructor 288 289 \param pos Position 290 \param vectorX x coordinate of the vector 291 \param vectorY y coordinate of the vector 292 */ 293 inline QwtVectorFieldSample::QwtVectorFieldSample( 294 const QPointF& pos, double vectorX, double vectorY ) 295 : x( pos.x() ) 296 , y( pos.y() ) 297 , vx( vectorX ) 298 , vy( vectorY ) 299 { 300 } 301 302 //! \return x/y coordinates as QPointF 303 inline QPointF QwtVectorFieldSample::pos() const 304 { 305 return QPointF( x, y ); 306 } 307 308 //! \return true, if vx and vy are 0 309 inline bool QwtVectorFieldSample::isNull() const 310 { 311 return ( vx == 0.0 ) && ( vy == 0.0 ); 312 } 313 239 314 #endif -
trunk/BNC/qwt/qwt_sampling_thread.cpp
r4271 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_sampling_thread.h" 11 #include "qwt_system_clock.h"11 #include <qelapsedtimer.h> 12 12 13 13 class QwtSamplingThread::PrivateData 14 14 { 15 public: 16 QwtSystemClock clock; 17 18 double interval; 19 bool isStopped; 15 public: 16 QElapsedTimer timer; 17 double msecsInterval; 20 18 }; 21 19 22 23 20 //! Constructor 24 QwtSamplingThread::QwtSamplingThread( QObject *parent ):25 QThread( parent ) 21 QwtSamplingThread::QwtSamplingThread( QObject* parent ) 22 : QThread( parent ) 26 23 { 27 d_data = new PrivateData; 28 d_data->interval = 1000; // 1 second 29 d_data->isStopped = true; 24 m_data = new PrivateData; 25 m_data->msecsInterval = 1e3; // 1 second 30 26 } 31 27 … … 33 29 QwtSamplingThread::~QwtSamplingThread() 34 30 { 35 delete d_data;31 delete m_data; 36 32 } 37 33 … … 40 36 The default interval is 1000.0 ( = 1s ) 41 37 42 \param intervalInterval38 \param msecs Interval 43 39 \sa interval() 44 */ 45 void QwtSamplingThread::setInterval( double interval)40 */ 41 void QwtSamplingThread::setInterval( double msecs ) 46 42 { 47 if ( interval< 0.0 )48 interval= 0.0;43 if ( msecs < 0.0 ) 44 msecs = 0.0; 49 45 50 d_data->interval =interval;46 m_data->msecsInterval = msecs; 51 47 } 52 48 … … 54 50 \return Interval (in ms), between 2 calls of sample() 55 51 \sa setInterval() 56 */ 52 */ 57 53 double QwtSamplingThread::interval() const 58 54 { 59 return d_data->interval;55 return m_data->msecsInterval; 60 56 } 61 57 … … 63 59 \return Time (in ms) since the thread was started 64 60 \sa QThread::start(), run() 65 */ 61 */ 66 62 double QwtSamplingThread::elapsed() const 67 63 { 68 if ( d_data->isStopped)69 return 0.0;64 if ( m_data->timer.isValid() ) 65 return m_data->timer.nsecsElapsed() / 1e6; 70 66 71 return d_data->clock.elapsed();67 return 0.0; 72 68 } 73 69 … … 75 71 Terminate the collecting thread 76 72 \sa QThread::start(), run() 77 */ 73 */ 78 74 void QwtSamplingThread::stop() 79 75 { 80 d_data->isStopped = true;76 m_data->timer.invalidate(); 81 77 } 82 78 … … 84 80 Loop collecting samples started from QThread::start() 85 81 \sa stop() 86 */ 82 */ 87 83 void QwtSamplingThread::run() 88 84 { 89 d_data->clock.start(); 90 d_data->isStopped = false; 85 m_data->timer.start(); 91 86 92 while ( !d_data->isStopped ) 87 /* 88 We should have all values in nsecs/qint64, but 89 this would break existing code. TODO ... 90 Anyway - for QThread::usleep we even need microseconds( usecs ) 91 */ 92 while ( m_data->timer.isValid() ) 93 93 { 94 const double elapsed = d_data->clock.elapsed();95 sample( elapsed / 1000.0 );94 const qint64 timestamp = m_data->timer.nsecsElapsed(); 95 sample( timestamp / 1e9 ); // seconds 96 96 97 if ( d_data->interval > 0.0 )97 if ( m_data->msecsInterval > 0.0 ) 98 98 { 99 const double msecs =100 d_data->interval - ( d_data->clock.elapsed() -elapsed );99 const double interval = m_data->msecsInterval * 1e3; 100 const double elapsed = ( m_data->timer.nsecsElapsed() - timestamp ) / 1e3; 101 101 102 if ( msecs > 0.0 ) 103 usleep( qRound( 1000.0 * msecs ) ); 102 const double usecs = interval - elapsed; 103 104 if ( usecs > 0.0 ) 105 QThread::usleep( qRound( usecs ) ); 104 106 } 105 107 } 106 108 } 109 110 #include "moc_qwt_sampling_thread.cpp" -
trunk/BNC/qwt/qwt_sampling_thread.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 8 8 *****************************************************************************/ 9 9 10 #ifndef _QWT_SAMPLING_THREAD_H_11 #define _QWT_SAMPLING_THREAD_H_10 #ifndef QWT_SAMPLING_THREAD_H 11 #define QWT_SAMPLING_THREAD_H 12 12 13 13 #include "qwt_global.h" … … 15 15 16 16 /*! 17 \brief A thread collecting samples at regular intervals. 17 \brief A thread collecting samples at regular intervals. 18 18 19 Continuous signals are converted into a discrete signal by 20 collecting samples at regular intervals. A discrete signal 21 can be displayed by a QwtPlotSeriesItem on a QwtPlot widget. 19 Continuous signals are converted into a discrete signal by 20 collecting samples at regular intervals. A discrete signal 21 can be displayed by a QwtPlotSeriesItem on a QwtPlot widget. 22 22 23 QwtSamplingThread starts a thread calling periodically sample(), 24 to collect and store ( or emit ) a single sample. 23 QwtSamplingThread starts a thread calling periodically sample(), 24 to collect and store ( or emit ) a single sample. 25 25 26 \sa QwtPlotCurve, QwtPlotSeriesItem 27 */ 28 class QWT_EXPORT QwtSamplingThread: public QThread 26 \sa QwtPlotCurve, QwtPlotSeriesItem 27 */ 28 class QWT_EXPORT QwtSamplingThread : public QThread 29 29 { 30 30 Q_OBJECT 31 31 32 public: 32 public: 33 33 virtual ~QwtSamplingThread(); 34 34 … … 36 36 double elapsed() const; 37 37 38 public Q_SLOTS: 38 public Q_SLOTS: 39 39 void setInterval( double interval ); 40 40 void stop(); 41 41 42 protected: 43 explicit QwtSamplingThread( QObject *parent = NULL );42 protected: 43 explicit QwtSamplingThread( QObject* parent = NULL ); 44 44 45 virtual void run(); 45 virtual void run() QWT_OVERRIDE; 46 46 47 47 /*! 48 48 Collect a sample 49 49 50 \param elapsed Time since the thread was started in milliseconds 50 \param elapsed Time since the thread was started in seconds 51 \note Due to a bug in previous version elapsed was passed as 52 seconds instead of miliseconds. To avoid breaking existing 53 code we stay with seconds for now. 51 54 */ 52 55 virtual void sample( double elapsed ) = 0; 53 56 54 private: 57 private: 55 58 class PrivateData; 56 PrivateData *d_data;59 PrivateData* m_data; 57 60 }; 58 61 -
trunk/BNC/qwt/qwt_scale_div.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_scale_div.h" 11 #include "qwt_math.h" 12 #include <qalgorithms.h> 13 14 /*! 15 Construct a division without ticks 16 17 \param lowerBound First boundary 18 \param upperBound Second boundary 19 20 \note lowerBound might be greater than upperBound for inverted scales 21 */ 22 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ): 23 d_lowerBound( lowerBound ), 24 d_upperBound( upperBound ) 25 { 26 } 27 28 /*! 29 Construct a scale division 30 31 \param interval Interval 32 \param ticks List of major, medium and minor ticks 33 */ 34 QwtScaleDiv::QwtScaleDiv( const QwtInterval &interval, 35 QList<double> ticks[NTickTypes] ): 36 d_lowerBound( interval.minValue() ), 37 d_upperBound( interval.maxValue() ) 11 #include "qwt_interval.h" 12 13 /*! 14 Construct a division without ticks 15 16 \param lowerBound First boundary 17 \param upperBound Second boundary 18 19 \note lowerBound might be greater than upperBound for inverted scales 20 */ 21 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ) 22 : m_lowerBound( lowerBound ) 23 , m_upperBound( upperBound ) 24 { 25 } 26 27 /*! 28 Construct a scale division 29 30 \param interval Interval 31 \param ticks List of major, medium and minor ticks 32 */ 33 QwtScaleDiv::QwtScaleDiv( const QwtInterval& interval, 34 QList< double > ticks[NTickTypes] ) 35 : m_lowerBound( interval.minValue() ) 36 , m_upperBound( interval.maxValue() ) 38 37 { 39 38 for ( int i = 0; i < NTickTypes; i++ ) 40 d_ticks[i] = ticks[i];41 } 42 43 /*! 44 Construct a scale division 45 46 \param lowerBound First boundary 47 \param upperBound Second boundary 48 \param ticks List of major, medium and minor ticks 49 50 \note lowerBound might be greater than upperBound for inverted scales 51 */ 39 m_ticks[i] = ticks[i]; 40 } 41 42 /*! 43 Construct a scale division 44 45 \param lowerBound First boundary 46 \param upperBound Second boundary 47 \param ticks List of major, medium and minor ticks 48 49 \note lowerBound might be greater than upperBound for inverted scales 50 */ 52 51 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound, 53 QList< double> ticks[NTickTypes] ):54 d_lowerBound( lowerBound ),55 d_upperBound( upperBound )52 QList< double > ticks[NTickTypes] ) 53 : m_lowerBound( lowerBound ) 54 , m_upperBound( upperBound ) 56 55 { 57 56 for ( int i = 0; i < NTickTypes; i++ ) 58 d_ticks[i] = ticks[i];59 } 60 61 /*! 62 Construct a scale division 63 64 \param lowerBound First boundary 65 \param upperBound Second boundary 66 \param minorTicks List of minor ticks 67 \param mediumTicks List medium ticks 68 \param majorTicks List of major ticks 69 70 \note lowerBound might be greater than upperBound for inverted scales 71 */ 57 m_ticks[i] = ticks[i]; 58 } 59 60 /*! 61 Construct a scale division 62 63 \param lowerBound First boundary 64 \param upperBound Second boundary 65 \param minorTicks List of minor ticks 66 \param mediumTicks List medium ticks 67 \param majorTicks List of major ticks 68 69 \note lowerBound might be greater than upperBound for inverted scales 70 */ 72 71 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound, 73 const QList< double> &minorTicks,74 const QList< double> &mediumTicks,75 const QList< double> &majorTicks ):76 d_lowerBound( lowerBound ),77 d_upperBound( upperBound )78 { 79 d_ticks[ MinorTick ] = minorTicks;80 d_ticks[ MediumTick ] = mediumTicks;81 d_ticks[ MajorTick ] = majorTicks;82 } 83 84 /*! 85 Change the interval 86 87 \param lowerBound First boundary 88 \param upperBound Second boundary 89 90 \note lowerBound might be greater than upperBound for inverted scales 91 */ 72 const QList< double >& minorTicks, 73 const QList< double >& mediumTicks, 74 const QList< double >& majorTicks ) 75 : m_lowerBound( lowerBound ) 76 , m_upperBound( upperBound ) 77 { 78 m_ticks[ MinorTick ] = minorTicks; 79 m_ticks[ MediumTick ] = mediumTicks; 80 m_ticks[ MajorTick ] = majorTicks; 81 } 82 83 /*! 84 Change the interval 85 86 \param lowerBound First boundary 87 \param upperBound Second boundary 88 89 \note lowerBound might be greater than upperBound for inverted scales 90 */ 92 91 void QwtScaleDiv::setInterval( double lowerBound, double upperBound ) 93 92 { 94 d_lowerBound = lowerBound;95 d_upperBound = upperBound;93 m_lowerBound = lowerBound; 94 m_upperBound = upperBound; 96 95 } 97 96 … … 100 99 101 100 \param interval Interval 102 */ 103 void QwtScaleDiv::setInterval( const QwtInterval &interval )104 { 105 d_lowerBound = interval.minValue();106 d_upperBound = interval.maxValue();107 } 108 109 /*! 110 \return lowerBound -> upperBound 111 */ 101 */ 102 void QwtScaleDiv::setInterval( const QwtInterval& interval ) 103 { 104 m_lowerBound = interval.minValue(); 105 m_upperBound = interval.maxValue(); 106 } 107 108 /*! 109 \return lowerBound -> upperBound 110 */ 112 111 QwtInterval QwtScaleDiv::interval() const 113 112 { 114 return QwtInterval( d_lowerBound,d_upperBound );115 } 116 117 /*! 118 Set the first boundary 119 120 \param lowerBound First boundary 121 \sa lowerB iound(), setUpperBound()113 return QwtInterval( m_lowerBound, m_upperBound ); 114 } 115 116 /*! 117 Set the first boundary 118 119 \param lowerBound First boundary 120 \sa lowerBound(), setUpperBound() 122 121 */ 123 122 void QwtScaleDiv::setLowerBound( double lowerBound ) 124 123 { 125 d_lowerBound = lowerBound;126 } 127 128 /*! 129 \return First boundary 130 \sa upperBound() 131 */ 124 m_lowerBound = lowerBound; 125 } 126 127 /*! 128 \return First boundary 129 \sa upperBound() 130 */ 132 131 double QwtScaleDiv::lowerBound() const 133 132 { 134 return d_lowerBound;135 } 136 137 /*! 138 Set the second boundary 139 140 \param upperBound Second boundary 141 \sa upperBound(), setLowerBound() 133 return m_lowerBound; 134 } 135 136 /*! 137 Set the second boundary 138 139 \param upperBound Second boundary 140 \sa upperBound(), setLowerBound() 142 141 */ 143 142 void QwtScaleDiv::setUpperBound( double upperBound ) 144 143 { 145 d_upperBound = upperBound;146 } 147 148 /*! 149 \return upper bound 150 \sa lowerBound() 151 */ 144 m_upperBound = upperBound; 145 } 146 147 /*! 148 \return upper bound 149 \sa lowerBound() 150 */ 152 151 double QwtScaleDiv::upperBound() const 153 152 { 154 return d_upperBound;155 } 156 157 /*! 158 \return upperBound() - lowerBound() 159 */ 153 return m_upperBound; 154 } 155 156 /*! 157 \return upperBound() - lowerBound() 158 */ 160 159 double QwtScaleDiv::range() const 161 160 { 162 return d_upperBound -d_lowerBound;163 } 164 165 /*! 166 \brief Equality operator 167 \return true if this instance is equal to other 168 */ 169 bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const170 { 171 if ( d_lowerBound != other.d_lowerBound ||172 d_upperBound != other.d_upperBound )161 return m_upperBound - m_lowerBound; 162 } 163 164 /*! 165 \brief Equality operator 166 \return true if this instance is equal to other 167 */ 168 bool QwtScaleDiv::operator==( const QwtScaleDiv& other ) const 169 { 170 if ( m_lowerBound != other.m_lowerBound || 171 m_upperBound != other.m_upperBound ) 173 172 { 174 173 return false; … … 177 176 for ( int i = 0; i < NTickTypes; i++ ) 178 177 { 179 if ( d_ticks[i] != other.d_ticks[i] )178 if ( m_ticks[i] != other.m_ticks[i] ) 180 179 return false; 181 180 } … … 185 184 186 185 /*! 187 \brief Inequality 188 \return true if this instance is not equal to other 189 */ 190 bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const186 \brief Inequality 187 \return true if this instance is not equal to other 188 */ 189 bool QwtScaleDiv::operator!=( const QwtScaleDiv& other ) const 191 190 { 192 191 return ( !( *this == other ) ); … … 196 195 bool QwtScaleDiv::isEmpty() const 197 196 { 198 return ( d_lowerBound ==d_upperBound );197 return ( m_lowerBound == m_upperBound ); 199 198 } 200 199 … … 202 201 bool QwtScaleDiv::isIncreasing() const 203 202 { 204 return d_lowerBound <=d_upperBound;205 } 206 207 /*! 208 Return if a value is between lowerBound() and upperBound() 209 210 \param value Value 211 \return true/false 212 */ 203 return m_lowerBound <= m_upperBound; 204 } 205 206 /*! 207 Return if a value is between lowerBound() and upperBound() 208 209 \param value Value 210 \return true/false 211 */ 213 212 bool QwtScaleDiv::contains( double value ) const 214 213 { 215 const double min = qMin( d_lowerBound,d_upperBound );216 const double max = qMax( d_lowerBound,d_upperBound );214 const double min = qMin( m_lowerBound, m_upperBound ); 215 const double max = qMax( m_lowerBound, m_upperBound ); 217 216 218 217 return value >= min && value <= max; … … 225 224 void QwtScaleDiv::invert() 226 225 { 227 qSwap( d_lowerBound,d_upperBound );226 qSwap( m_lowerBound, m_upperBound ); 228 227 229 228 for ( int i = 0; i < NTickTypes; i++ ) 230 229 { 231 QList< double>& ticks =d_ticks[i];230 QList< double >& ticks = m_ticks[i]; 232 231 233 232 const int size = ticks.count(); … … 240 239 241 240 /*! 242 \return A scale division with inverted boundaries and ticks 243 \sa invert() 241 \return A scale division with inverted boundaries and ticks 242 \sa invert() 244 243 */ 245 244 QwtScaleDiv QwtScaleDiv::inverted() const … … 261 260 262 261 \note lowerBound might be greater than upperBound for inverted scales 263 */ 262 */ 264 263 QwtScaleDiv QwtScaleDiv::bounded( 265 264 double lowerBound, double upperBound ) const … … 273 272 for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ ) 274 273 { 275 const QList< double> &ticks =d_ticks[ tickType ];276 277 QList< double> boundedTicks;274 const QList< double >& ticks = m_ticks[ tickType ]; 275 276 QList< double > boundedTicks; 278 277 for ( int i = 0; i < ticks.size(); i++ ) 279 278 { … … 293 292 Assign ticks 294 293 295 \param type MinorTick, MediumTick or MajorTick 294 \param tickType MinorTick, MediumTick or MajorTick 296 295 \param ticks Values of the tick positions 297 */ 298 void QwtScaleDiv::setTicks( int type, const QList< double> &ticks )299 { 300 if ( type >= 0 && type < NTickTypes ) 301 d_ticks[type] = ticks;296 */ 297 void QwtScaleDiv::setTicks( int tickType, const QList< double >& ticks ) 298 { 299 if ( tickType >= 0 && tickType < NTickTypes ) 300 m_ticks[tickType] = ticks; 302 301 } 303 302 … … 305 304 Return a list of ticks 306 305 307 \param type MinorTick, MediumTick or MajorTick 306 \param tickType MinorTick, MediumTick or MajorTick 308 307 \return Tick list 309 */ 310 QList< double> QwtScaleDiv::ticks( int type ) const311 { 312 if ( type >= 0 && type < NTickTypes ) 313 return d_ticks[type];314 315 return QList< double>();308 */ 309 QList< double > QwtScaleDiv::ticks( int tickType ) const 310 { 311 if ( tickType >= 0 && tickType < NTickTypes ) 312 return m_ticks[tickType]; 313 314 return QList< double >(); 316 315 } 317 316 318 317 #ifndef QT_NO_DEBUG_STREAM 319 318 320 QDebug operator<<( QDebug debug, const QwtScaleDiv &scaleDiv ) 319 #include <qdebug.h> 320 321 QDebug operator<<( QDebug debug, const QwtScaleDiv& scaleDiv ) 321 322 { 322 323 debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound(); -
trunk/BNC/qwt/qwt_scale_div.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h"15 14 #include <qlist.h> 16 15 17 #ifndef QT_NO_DEBUG_STREAM 18 #include <qdebug.h> 19 #endif 16 class QwtInterval; 20 17 21 18 /*! 22 \brief A class representing a scale division 19 \brief A class representing a scale division 23 20 24 A Qwt scale is defined by its boundaries and 3 list 25 for the positions of the major, medium and minor ticks. 21 A Qwt scale is defined by its boundaries and 3 list 22 for the positions of the major, medium and minor ticks. 26 23 27 The upperBound() might be smaller than the lowerBound() 28 to indicate inverted scales. 24 The upperBound() might be smaller than the lowerBound() 25 to indicate inverted scales. 29 26 30 Scale divisions can be calculated from a QwtScaleEngine. 27 Scale divisions can be calculated from a QwtScaleEngine. 31 28 32 \sa QwtScaleEngine::divideScale(), QwtPlot::setAxisScaleDiv(), 29 \sa QwtScaleEngine::divideScale(), QwtPlot::setAxisScaleDiv(), 33 30 QwtAbstractSlider::setScaleDiv() 34 */ 31 */ 35 32 36 33 class QWT_EXPORT QwtScaleDiv 37 34 { 38 public: 35 public: 39 36 //! Scale tick types 40 37 enum TickType … … 59 56 double upperBound = 0.0 ); 60 57 61 explicit QwtScaleDiv( const QwtInterval &, QList<double>[NTickTypes] );58 explicit QwtScaleDiv( const QwtInterval&, QList< double >[NTickTypes] ); 62 59 63 60 explicit QwtScaleDiv( double lowerBound, double upperBound, 64 QList< double>[NTickTypes] );61 QList< double >[NTickTypes] ); 65 62 66 63 explicit QwtScaleDiv( double lowerBound, double upperBound, 67 const QList< double> &minorTicks, const QList<double> &mediumTicks,68 const QList< double> &majorTicks );64 const QList< double >& minorTicks, const QList< double >& mediumTicks, 65 const QList< double >& majorTicks ); 69 66 70 bool operator==( const QwtScaleDiv & ) const;71 bool operator!=( const QwtScaleDiv & ) const;67 bool operator==( const QwtScaleDiv& ) const; 68 bool operator!=( const QwtScaleDiv& ) const; 72 69 73 70 void setInterval( double lowerBound, double upperBound ); 74 void setInterval( const QwtInterval & );71 void setInterval( const QwtInterval& ); 75 72 QwtInterval interval() const; 76 73 … … 85 82 bool contains( double value ) const; 86 83 87 void setTicks( int tickType, const QList< double>& );88 QList< double> ticks( int tickType ) const;84 void setTicks( int tickType, const QList< double >& ); 85 QList< double > ticks( int tickType ) const; 89 86 90 87 bool isEmpty() const; … … 96 93 QwtScaleDiv bounded( double lowerBound, double upperBound ) const; 97 94 98 private: 99 double d_lowerBound;100 double d_upperBound;101 QList< double> d_ticks[NTickTypes];95 private: 96 double m_lowerBound; 97 double m_upperBound; 98 QList< double > m_ticks[NTickTypes]; 102 99 }; 103 100 … … 105 102 106 103 #ifndef QT_NO_DEBUG_STREAM 107 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleDiv & );104 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleDiv& ); 108 105 #endif 109 106 -
trunk/BNC/qwt/qwt_scale_draw.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_math.h" 14 14 #include "qwt_painter.h" 15 #include <qpen.h> 15 #include "qwt_text.h" 16 16 17 #include <qpainter.h> 18 #include <qpaintengine.h> 17 19 #include <qmath.h> 18 20 19 #if QT_VERSION < 0x040601 20 #define qFastSin(x) qSin(x) 21 #define qFastCos(x) qCos(x) 21 static inline double qwtEffectivePenWidth( const QwtAbstractScaleDraw* scaleDraw ) 22 { 23 return qwtMaxF( scaleDraw->penWidthF(), 1.0 ); 24 } 25 26 namespace QwtScaleRendererReal 27 { 28 inline qreal penWidth( const QPainter* painter, const QwtScaleDraw* scaleDraw ) 29 { 30 qreal width = scaleDraw->penWidthF(); 31 #if 1 32 if ( width <= 0.0 ) 33 width = 1.0; 22 34 #endif 23 35 36 if ( painter->pen().isCosmetic() ) 37 { 38 const QTransform& transform = painter->transform(); 39 40 switch ( scaleDraw->alignment() ) 41 { 42 case QwtScaleDraw::LeftScale: 43 case QwtScaleDraw::RightScale: 44 { 45 width /= transform.m11(); 46 break; 47 } 48 case QwtScaleDraw::TopScale: 49 case QwtScaleDraw::BottomScale: 50 { 51 width /= transform.m22(); 52 break; 53 } 54 } 55 } 56 57 return width; 58 } 59 60 inline void drawBackbone( QPainter* painter, const QwtScaleDraw* scaleDraw ) 61 { 62 const qreal pw2 = 0.5 * penWidth( painter, scaleDraw ); 63 64 const QPointF pos = scaleDraw->pos(); 65 const qreal length = scaleDraw->length(); 66 67 switch ( scaleDraw->alignment() ) 68 { 69 case QwtScaleDraw::LeftScale: 70 { 71 const qreal x = pos.x() + 1.0 - pw2; 72 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 73 74 break; 75 } 76 case QwtScaleDraw::RightScale: 77 { 78 const qreal x = pos.x() - 1.0 + pw2; 79 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 80 81 break; 82 } 83 case QwtScaleDraw::TopScale: 84 { 85 const qreal y = pos.y() + 1.0 - pw2; 86 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 87 88 break; 89 } 90 case QwtScaleDraw::BottomScale: 91 { 92 const qreal y = pos.y() - 1.0 + pw2; 93 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 94 95 break; 96 } 97 } 98 } 99 100 inline void drawTick( QPainter* painter, 101 const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength ) 102 { 103 const QPointF pos = scaleDraw->pos(); 104 105 qreal pw = 0.0; 106 107 if ( scaleDraw->hasComponent( QwtScaleDraw::Backbone ) ) 108 pw = penWidth( painter, scaleDraw ); 109 110 const qreal length = tickLength + pw; 111 112 /* 113 Those correction offsets have been found by try and error. 114 They need to be understood and replaced by a calculation, 115 that makes sense. TODO ... 116 */ 117 const qreal off1 = 1.0; 118 const qreal off2 = ( scaleDraw->penWidthF() <= 0.0 ) ? 0.5 : 0.0; 119 120 switch ( scaleDraw->alignment() ) 121 { 122 case QwtScaleDraw::LeftScale: 123 { 124 const qreal x = pos.x() + off1 - off2; 125 QwtPainter::drawLine( painter, x, tickPos, x - length, tickPos ); 126 127 break; 128 } 129 case QwtScaleDraw::RightScale: 130 { 131 const qreal x = pos.x() - off1 + off2; 132 QwtPainter::drawLine( painter, x, tickPos, x + length, tickPos ); 133 break; 134 } 135 case QwtScaleDraw::TopScale: 136 { 137 const qreal y = pos.y() + off1 - 2 * off2; 138 QwtPainter::drawLine( painter, tickPos, y, tickPos, y - length ); 139 140 break; 141 } 142 case QwtScaleDraw::BottomScale: 143 { 144 const qreal y = pos.y() - off1 + off2; 145 QwtPainter::drawLine( painter, tickPos, y, tickPos, y + length ); 146 147 break; 148 } 149 } 150 } 151 } 152 153 namespace QwtScaleRendererInt 154 { 155 inline void drawBackbone( QPainter* painter, const QwtScaleDraw* scaleDraw ) 156 { 157 const int pw = qMax( qRound( scaleDraw->penWidthF() ), 1 ); 158 159 const qreal length = scaleDraw->length(); 160 const QPointF pos = scaleDraw->pos(); 161 162 switch ( scaleDraw->alignment() ) 163 { 164 case QwtScaleDraw::LeftScale: 165 { 166 const qreal x = qRound( pos.x() - ( pw - 1 ) / 2 ); 167 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 168 169 break; 170 } 171 case QwtScaleDraw::RightScale: 172 { 173 const qreal x = qRound( pos.x() + pw / 2 ); 174 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length ); 175 176 break; 177 } 178 case QwtScaleDraw::TopScale: 179 { 180 const qreal y = qRound( pos.y() - ( pw - 1 ) / 2 ); 181 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 182 183 break; 184 } 185 case QwtScaleDraw::BottomScale: 186 { 187 const qreal y = qRound( pos.y() + pw / 2 ); 188 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y ); 189 190 break; 191 } 192 } 193 } 194 195 inline void drawTick( QPainter* painter, 196 const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength ) 197 { 198 const QPointF pos = scaleDraw->pos(); 199 tickPos = qRound( tickPos ); 200 201 int pw = 0; 202 if ( scaleDraw->hasComponent( QwtScaleDraw::Backbone ) ) 203 pw = qMax( qRound( scaleDraw->penWidthF() ), 1 ); 204 205 int len = qMax( qRound( tickLength ), 1 ); 206 207 // the width of ticks at the borders might extent the backbone 208 len += pw; 209 210 if ( painter->pen().capStyle() == Qt::FlatCap ) 211 len++; // the end point is not rendered 212 213 qreal off = 0.0; 214 215 if ( painter->paintEngine()->type() == QPaintEngine::X11 ) 216 { 217 if ( pw == 1 ) 218 { 219 // In opposite to raster, X11 paints the end point 220 off = 1.0; 221 } 222 } 223 224 switch ( scaleDraw->alignment() ) 225 { 226 case QwtScaleDraw::LeftScale: 227 { 228 const qreal x1 = qRound( pos.x() ) + 1; 229 const qreal x2 = x1 - len + 1; 230 231 QwtPainter::drawLine( painter, x2, tickPos, x1 - off, tickPos ); 232 233 break; 234 } 235 case QwtScaleDraw::RightScale: 236 { 237 const qreal x1 = qRound( pos.x() ); 238 const qreal x2 = x1 + len - 1; 239 240 QwtPainter::drawLine( painter, x1, tickPos, x2 - off, tickPos ); 241 242 break; 243 } 244 case QwtScaleDraw::BottomScale: 245 { 246 const qreal y1 = qRound( pos.y() ); 247 const qreal y2 = y1 + len - 1; 248 249 QwtPainter::drawLine( painter, tickPos, y1, tickPos, y2 - off ); 250 251 break; 252 } 253 case QwtScaleDraw::TopScale: 254 { 255 const qreal y1 = qRound( pos.y() ); 256 const qreal y2 = y1 - len + 1; 257 258 QwtPainter::drawLine( painter, tickPos, y2 + 1, tickPos, y1 + 1 - off ); 259 260 break; 261 } 262 } 263 } 264 } 265 24 266 class QwtScaleDraw::PrivateData 25 267 { 26 public: 27 PrivateData(): 28 len( 0 ), 29 alignment( QwtScaleDraw::BottomScale ), 30 labelAlignment( 0 ), 31 labelRotation( 0.0 ) 268 public: 269 PrivateData() 270 : len( 0 ) 271 , alignment( QwtScaleDraw::BottomScale ) 272 , labelRotation( 0.0 ) 32 273 { 33 274 } … … 43 284 44 285 /*! 45 \brief Constructor 46 47 The range of the scale is initialized to [0, 100], 48 The position is at (0, 0) with a length of 100. 49 The orientation is QwtAbstractScaleDraw::Bottom. 50 */ 286 \brief Constructor 287 288 The range of the scale is initialized to [0, 100], 289 The position is at (0, 0) with a length of 100. 290 The orientation is QwtAbstractScaleDraw::Bottom. 291 */ 51 292 QwtScaleDraw::QwtScaleDraw() 52 293 { 53 d_data = new QwtScaleDraw::PrivateData;294 m_data = new QwtScaleDraw::PrivateData; 54 295 setLength( 100 ); 55 296 } … … 58 299 QwtScaleDraw::~QwtScaleDraw() 59 300 { 60 delete d_data;301 delete m_data; 61 302 } 62 303 … … 65 306 \sa setAlignment() 66 307 \return Alignment of the scale 67 */ 308 */ 68 309 QwtScaleDraw::Alignment QwtScaleDraw::alignment() const 69 310 { 70 return d_data->alignment;311 return m_data->alignment; 71 312 } 72 313 … … 78 319 The default alignment is QwtScaleDraw::BottomScale 79 320 \sa alignment() 80 */ 321 */ 81 322 void QwtScaleDraw::setAlignment( Alignment align ) 82 323 { 83 d_data->alignment = align;84 } 85 86 /*! 87 Return the orientation 88 89 TopScale, BottomScale are horizontal (Qt::Horizontal) scales, 90 LeftScale, RightScale are vertical (Qt::Vertical) scales. 91 92 \return Orientation of the scale 93 94 \sa alignment() 95 */ 324 m_data->alignment = align; 325 } 326 327 /*! 328 Return the orientation 329 330 TopScale, BottomScale are horizontal (Qt::Horizontal) scales, 331 LeftScale, RightScale are vertical (Qt::Vertical) scales. 332 333 \return Orientation of the scale 334 335 \sa alignment() 336 */ 96 337 Qt::Orientation QwtScaleDraw::orientation() const 97 338 { 98 switch ( d_data->alignment )339 switch ( m_data->alignment ) 99 340 { 100 341 case TopScale: … … 109 350 110 351 /*! 111 \brief Determine the minimum border distance 112 113 This member function returns the minimum space 114 needed to draw the mark labels at the scale's endpoints. 115 116 \param font Font 117 \param start Start border distance 118 \param end End border distance 119 */ 352 \brief Determine the minimum border distance 353 354 This member function returns the minimum space 355 needed to draw the mark labels at the scale's endpoints. 356 357 \param font Font 358 \param start Start border distance 359 \param end End border distance 360 */ 120 361 void QwtScaleDraw::getBorderDistHint( 121 const QFont &font, int&start, int&end ) const362 const QFont& font, int& start, int& end ) const 122 363 { 123 364 start = 0; … … 127 368 return; 128 369 129 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );370 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 130 371 if ( ticks.count() == 0 ) 131 372 return; … … 179 420 e = 0.0; 180 421 181 start = qCeil( s ); 182 end = qCeil( e ); 183 } 184 185 /*! 186 Determine the minimum distance between two labels, that is necessary 187 that the texts don't overlap. 188 189 \param font Font 190 \return The maximum width of a label 191 192 \sa getBorderDistHint() 193 */ 194 195 int QwtScaleDraw::minLabelDist( const QFont &font ) const422 start = qwtCeil( s ); 423 end = qwtCeil( e ); 424 } 425 426 /*! 427 Determine the minimum distance between two labels, that is necessary 428 that the texts don't overlap. 429 430 \param font Font 431 \return The maximum width of a label 432 433 \sa getBorderDistHint() 434 */ 435 436 int QwtScaleDraw::minLabelDist( const QFont& font ) const 196 437 { 197 438 if ( !hasComponent( QwtAbstractScaleDraw::Labels ) ) 198 439 return 0; 199 440 200 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );441 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 201 442 if ( ticks.isEmpty() ) 202 443 return 0; … … 279 520 280 521 \sa minLength() 281 */ 282 double QwtScaleDraw::extent( const QFont &font ) const522 */ 523 double QwtScaleDraw::extent( const QFont& font ) const 283 524 { 284 525 double d = 0; … … 302 543 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 303 544 { 304 const double pw = qMax( 1, penWidth() ); // pen width can be zero 305 d += pw; 306 } 307 308 d = qMax( d, minimumExtent() ); 545 d += qwtEffectivePenWidth( this ); 546 } 547 548 d = qwtMaxF( d, minimumExtent() ); 309 549 return d; 310 550 } … … 317 557 318 558 \sa extent() 319 */ 320 int QwtScaleDraw::minLength( const QFont &font ) const559 */ 560 int QwtScaleDraw::minLength( const QFont& font ) const 321 561 { 322 562 int startDist, endDist; 323 563 getBorderDistHint( font, startDist, endDist ); 324 564 325 const QwtScaleDiv &sd = scaleDiv();565 const QwtScaleDiv& sd = scaleDiv(); 326 566 327 567 const uint minorCount = … … 338 578 if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) 339 579 { 340 const double pw = q Max( 1, penWidth() ); // penwidth can be zero580 const double pw = qwtEffectivePenWidth( this ); 341 581 lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) ); 342 582 } … … 353 593 \param value Value 354 594 \return Position, where to paint a label 355 */ 595 */ 356 596 QPointF QwtScaleDraw::labelPosition( double value ) const 357 597 { … … 359 599 double dist = spacing(); 360 600 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 361 dist += q Max( 1, penWidth());601 dist += qwtEffectivePenWidth( this ); 362 602 363 603 if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) … … 371 611 case RightScale: 372 612 { 373 px = d_data->pos.x() + dist;613 px = m_data->pos.x() + dist; 374 614 py = tval; 375 615 break; … … 377 617 case LeftScale: 378 618 { 379 px = d_data->pos.x() - dist;619 px = m_data->pos.x() - dist; 380 620 py = tval; 381 621 break; … … 384 624 { 385 625 px = tval; 386 py = d_data->pos.y() + dist;626 py = m_data->pos.y() + dist; 387 627 break; 388 628 } … … 390 630 { 391 631 px = tval; 392 py = d_data->pos.y() - dist;632 py = m_data->pos.y() - dist; 393 633 break; 394 634 } … … 406 646 407 647 \sa drawBackbone(), drawLabel() 408 */ 409 void QwtScaleDraw::drawTick( QPainter *painter, double value, double len ) const648 */ 649 void QwtScaleDraw::drawTick( QPainter* painter, double value, double len ) const 410 650 { 411 651 if ( len <= 0 ) 412 652 return; 413 653 414 const bool roundingAlignment = QwtPainter::roundingAlignment( painter ); 415 416 QPointF pos = d_data->pos; 417 418 double tval = scaleMap().transform( value ); 419 if ( roundingAlignment ) 420 tval = qRound( tval ); 421 422 const int pw = penWidth(); 423 int a = 0; 424 if ( pw > 1 && roundingAlignment ) 425 a = 1; 426 427 switch ( alignment() ) 428 { 429 case LeftScale: 430 { 431 double x1 = pos.x() + a; 432 double x2 = pos.x() + a - pw - len; 433 if ( roundingAlignment ) 434 { 435 x1 = qRound( x1 ); 436 x2 = qRound( x2 ); 437 } 438 439 QwtPainter::drawLine( painter, x1, tval, x2, tval ); 440 break; 441 } 442 443 case RightScale: 444 { 445 double x1 = pos.x(); 446 double x2 = pos.x() + pw + len; 447 if ( roundingAlignment ) 448 { 449 x1 = qRound( x1 ); 450 x2 = qRound( x2 ); 451 } 452 453 QwtPainter::drawLine( painter, x1, tval, x2, tval ); 454 break; 455 } 456 457 case BottomScale: 458 { 459 double y1 = pos.y(); 460 double y2 = pos.y() + pw + len; 461 if ( roundingAlignment ) 462 { 463 y1 = qRound( y1 ); 464 y2 = qRound( y2 ); 465 } 466 467 QwtPainter::drawLine( painter, tval, y1, tval, y2 ); 468 break; 469 } 470 471 case TopScale: 472 { 473 double y1 = pos.y() + a; 474 double y2 = pos.y() - pw - len + a; 475 if ( roundingAlignment ) 476 { 477 y1 = qRound( y1 ); 478 y2 = qRound( y2 ); 479 } 480 481 QwtPainter::drawLine( painter, tval, y1, tval, y2 ); 482 break; 483 } 484 } 654 const double tval = scaleMap().transform( value ); 655 656 if ( QwtPainter::roundingAlignment( painter ) ) 657 QwtScaleRendererInt::drawTick( painter, this, tval, len ); 658 else 659 QwtScaleRendererReal::drawTick( painter, this, tval, len ); 485 660 } 486 661 … … 490 665 491 666 \sa drawTick(), drawLabel() 492 */ 493 void QwtScaleDraw::drawBackbone( QPainter *painter ) const 494 { 495 const bool doAlign = QwtPainter::roundingAlignment( painter ); 496 497 const QPointF &pos = d_data->pos; 498 const double len = d_data->len; 499 const int pw = qMax( penWidth(), 1 ); 500 501 // pos indicates a border not the center of the backbone line 502 // so we need to shift its position depending on the pen width 503 // and the alignment of the scale 504 505 double off; 506 if ( doAlign ) 507 { 508 if ( alignment() == LeftScale || alignment() == TopScale ) 509 off = ( pw - 1 ) / 2; 510 else 511 off = pw / 2; 512 } 667 */ 668 void QwtScaleDraw::drawBackbone( QPainter* painter ) const 669 { 670 if ( QwtPainter::roundingAlignment( painter ) ) 671 QwtScaleRendererInt::drawBackbone( painter, this ); 513 672 else 514 { 515 off = 0.5 * penWidth(); 516 } 517 518 switch ( alignment() ) 519 { 520 case LeftScale: 521 { 522 double x = pos.x() - off; 523 if ( doAlign ) 524 x = qRound( x ); 525 526 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + len ); 527 break; 528 } 529 case RightScale: 530 { 531 double x = pos.x() + off; 532 if ( doAlign ) 533 x = qRound( x ); 534 535 QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + len ); 536 break; 537 } 538 case TopScale: 539 { 540 double y = pos.y() - off; 541 if ( doAlign ) 542 y = qRound( y ); 543 544 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + len, y ); 545 break; 546 } 547 case BottomScale: 548 { 549 double y = pos.y() + off; 550 if ( doAlign ) 551 y = qRound( y ); 552 553 QwtPainter::drawLine( painter, pos.x(), y, pos.x() + len, y ); 554 break; 555 } 556 } 557 } 558 559 /*! 560 \brief Move the position of the scale 561 562 The meaning of the parameter pos depends on the alignment: 563 <dl> 564 <dt>QwtScaleDraw::LeftScale 565 <dd>The origin is the topmost point of the 673 QwtScaleRendererReal::drawBackbone( painter, this ); 674 } 675 676 /*! 677 \brief Move the position of the scale 678 679 The meaning of the parameter pos depends on the alignment: 680 <dl> 681 <dt>QwtScaleDraw::LeftScale 682 <dd>The origin is the topmost point of the 566 683 backbone. The backbone is a vertical line. 567 684 Scale marks and labels are drawn 568 685 at the left of the backbone. 569 <dt>QwtScaleDraw::RightScale 570 <dd>The origin is the topmost point of the 686 <dt>QwtScaleDraw::RightScale 687 <dd>The origin is the topmost point of the 571 688 backbone. The backbone is a vertical line. 572 689 Scale marks and labels are drawn 573 690 at the right of the backbone. 574 <dt>QwtScaleDraw::TopScale 575 <dd>The origin is the leftmost point of the 691 <dt>QwtScaleDraw::TopScale 692 <dd>The origin is the leftmost point of the 576 693 backbone. The backbone is a horizontal line. 577 694 Scale marks and labels are drawn 578 695 above the backbone. 579 <dt>QwtScaleDraw::BottomScale 580 <dd>The origin is the leftmost point of the 696 <dt>QwtScaleDraw::BottomScale 697 <dd>The origin is the leftmost point of the 581 698 backbone. The backbone is a horizontal line 582 699 Scale marks and labels are drawn 583 700 below the backbone. 584 </dl> 585 586 \param pos Origin of the scale 587 588 \sa pos(), setLength() 589 */ 590 void QwtScaleDraw::move( const QPointF &pos )591 { 592 d_data->pos = pos;701 </dl> 702 703 \param pos Origin of the scale 704 705 \sa pos(), setLength() 706 */ 707 void QwtScaleDraw::move( const QPointF& pos ) 708 { 709 m_data->pos = pos; 593 710 updateMap(); 594 711 } … … 597 714 \return Origin of the scale 598 715 \sa move(), length() 599 */ 716 */ 600 717 QPointF QwtScaleDraw::pos() const 601 718 { 602 return d_data->pos;603 } 604 605 /*! 606 Set the length of the backbone. 607 608 The length doesn't include the space needed for 609 overlapping labels. 610 611 \param length Length of the backbone 612 613 \sa move(), minLabelDist() 614 */ 719 return m_data->pos; 720 } 721 722 /*! 723 Set the length of the backbone. 724 725 The length doesn't include the space needed for 726 overlapping labels. 727 728 \param length Length of the backbone 729 730 \sa move(), minLabelDist() 731 */ 615 732 void QwtScaleDraw::setLength( double length ) 616 733 { 617 #if 1618 734 if ( length >= 0 && length < 10 ) 619 735 length = 10; 620 736 621 // why should we accept negative lengths ???737 // f.e the left/bottom scales of a polar plot 622 738 if ( length < 0 && length > -10 ) 623 739 length = -10; 624 #else 625 length = qMax( length, 10 ); 626 #endif 627 628 d_data->len = length; 740 741 m_data->len = length; 629 742 updateMap(); 630 743 } … … 633 746 \return the length of the backbone 634 747 \sa setLength(), pos() 635 */ 748 */ 636 749 double QwtScaleDraw::length() const 637 750 { 638 return d_data->len;751 return m_data->len; 639 752 } 640 753 … … 646 759 647 760 \sa drawTick(), drawBackbone(), boundingLabelRect() 648 */ 649 void QwtScaleDraw::drawLabel( QPainter *painter, double value ) const761 */ 762 void QwtScaleDraw::drawLabel( QPainter* painter, double value ) const 650 763 { 651 764 QwtText lbl = tickLabel( painter->font(), value ); … … 668 781 669 782 /*! 670 \brief Find the bounding rectangle for the label. 671 672 The coordinates of the rectangle are absolute ( calculated from pos() ). 673 in direction of the tick. 674 675 \param font Font used for painting 676 \param value Value 677 678 \return Bounding rectangle 679 \sa labelRect() 680 */ 681 QRect QwtScaleDraw::boundingLabelRect( const QFont &font, double value ) const783 \brief Find the bounding rectangle for the label. 784 785 The coordinates of the rectangle are absolute ( calculated from pos() ). 786 in direction of the tick. 787 788 \param font Font used for painting 789 \param value Value 790 791 \return Bounding rectangle 792 \sa labelRect() 793 */ 794 QRect QwtScaleDraw::boundingLabelRect( const QFont& font, double value ) const 682 795 { 683 796 QwtText lbl = tickLabel( font, value ); … … 701 814 \return Transformation matrix 702 815 \sa setLabelAlignment(), setLabelRotation() 703 */ 816 */ 704 817 QTransform QwtScaleDraw::labelTransformation( 705 const QPointF &pos, const QSizeF&size ) const818 const QPointF& pos, const QSizeF& size ) const 706 819 { 707 820 QTransform transform; … … 763 876 764 877 /*! 765 Find the bounding rectangle for the label. The coordinates of 766 the rectangle are relative to spacing + tick length from the backbone 767 in direction of the tick. 768 769 \param font Font used for painting 770 \param value Value 878 Find the bounding rectangle for the label. The coordinates of 879 the rectangle are relative to spacing + tick length from the backbone 880 in direction of the tick. 881 882 \param font Font used for painting 883 \param value Value 771 884 772 885 \return Bounding rectangle that is needed to draw a label 773 */ 774 QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const886 */ 887 QRectF QwtScaleDraw::labelRect( const QFont& font, double value ) const 775 888 { 776 889 QwtText lbl = tickLabel( font, value ); … … 796 909 797 910 \return Size that is needed to draw a label 798 */ 799 QSizeF QwtScaleDraw::labelSize( const QFont &font, double value ) const911 */ 912 QSizeF QwtScaleDraw::labelSize( const QFont& font, double value ) const 800 913 { 801 914 return labelRect( font, value ).size(); … … 803 916 804 917 /*! 805 Rotate all labels. 806 807 When changing the rotation, it might be necessary to 808 adjust the label flags too. Finding a useful combination is 809 often the result of try and error. 810 811 \param rotation Angle in degrees. When changing the label rotation, 918 Rotate all labels. 919 920 When changing the rotation, it might be necessary to 921 adjust the label flags too. Finding a useful combination is 922 often the result of try and error. 923 924 \param rotation Angle in degrees. When changing the label rotation, 812 925 the label flags often needs to be adjusted too. 813 926 814 \sa setLabelAlignment(), labelRotation(), labelAlignment(). 815 816 */ 927 \sa setLabelAlignment(), labelRotation(), labelAlignment(). 928 929 */ 817 930 void QwtScaleDraw::setLabelRotation( double rotation ) 818 931 { 819 d_data->labelRotation = rotation;820 } 821 822 /*! 823 \return the label rotation 824 \sa setLabelRotation(), labelAlignment() 825 */ 932 m_data->labelRotation = rotation; 933 } 934 935 /*! 936 \return the label rotation 937 \sa setLabelRotation(), labelAlignment() 938 */ 826 939 double QwtScaleDraw::labelRotation() const 827 940 { 828 return d_data->labelRotation;829 } 830 831 /*! 832 \brief Change the label flags 833 834 Labels are aligned to the point tick length + spacing away from the backbone. 835 836 The alignment is relative to the orientation of the label text. 837 In case of an flags of 0 the label will be aligned 838 depending on the orientation of the scale: 941 return m_data->labelRotation; 942 } 943 944 /*! 945 \brief Change the label flags 946 947 Labels are aligned to the point tick length + spacing away from the backbone. 948 949 The alignment is relative to the orientation of the label text. 950 In case of an flags of 0 the label will be aligned 951 depending on the orientation of the scale: 839 952 840 953 QwtScaleDraw::TopScale: Qt::AlignHCenter | Qt::AlignTop\n … … 843 956 QwtScaleDraw::RightScale: Qt::AlignRight | Qt::AlignVCenter\n 844 957 845 Changing the alignment is often necessary for rotated labels. 846 847 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 848 849 \sa setLabelRotation(), labelRotation(), labelAlignment() 850 \warning The various alignments might be confusing. 958 Changing the alignment is often necessary for rotated labels. 959 960 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 961 962 \sa setLabelRotation(), labelRotation(), labelAlignment() 963 \warning The various alignments might be confusing. 851 964 The alignment of the label is not the alignment 852 965 of the scale and is not the alignment of the flags 853 966 ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label(). 854 */ 967 */ 855 968 856 969 void QwtScaleDraw::setLabelAlignment( Qt::Alignment alignment ) 857 970 { 858 d_data->labelAlignment = alignment;859 } 860 861 /*! 862 \return the label flags 863 \sa setLabelAlignment(), labelRotation() 864 */ 971 m_data->labelAlignment = alignment; 972 } 973 974 /*! 975 \return the label flags 976 \sa setLabelAlignment(), labelRotation() 977 */ 865 978 Qt::Alignment QwtScaleDraw::labelAlignment() const 866 979 { 867 return d_data->labelAlignment;868 } 869 870 /*! 871 \param font Font 872 \return the maximum width of a label 873 */ 874 int QwtScaleDraw::maxLabelWidth( const QFont &font ) const980 return m_data->labelAlignment; 981 } 982 983 /*! 984 \param font Font 985 \return the maximum width of a label 986 */ 987 int QwtScaleDraw::maxLabelWidth( const QFont& font ) const 875 988 { 876 989 double maxWidth = 0.0; 877 990 878 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );991 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 879 992 for ( int i = 0; i < ticks.count(); i++ ) 880 993 { … … 892 1005 893 1006 /*! 894 \param font Font 895 \return the maximum height of a label 896 */ 897 int QwtScaleDraw::maxLabelHeight( const QFont &font ) const1007 \param font Font 1008 \return the maximum height of a label 1009 */ 1010 int QwtScaleDraw::maxLabelHeight( const QFont& font ) const 898 1011 { 899 1012 double maxHeight = 0.0; 900 1013 901 const QList< double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );1014 const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 902 1015 for ( int i = 0; i < ticks.count(); i++ ) 903 1016 { … … 916 1029 void QwtScaleDraw::updateMap() 917 1030 { 918 const QPointF pos = d_data->pos;919 double len = d_data->len;920 921 QwtScaleMap &sm = scaleMap();1031 const QPointF pos = m_data->pos; 1032 double len = m_data->len; 1033 1034 QwtScaleMap& sm = scaleMap(); 922 1035 if ( orientation() == Qt::Vertical ) 923 1036 sm.setPaintInterval( pos.y() + len, pos.y() ); -
trunk/BNC/qwt/qwt_scale_draw.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_abstract_scale_draw.h" 15 15 16 #include <qpoint.h> 16 #include <qrect.h> 17 #include <qtransform.h> 17 18 class QTransform; 19 class QSizeF; 20 class QRectF; 21 class QRect; 18 22 19 23 /*! 20 \brief A class for drawing scales 24 \brief A class for drawing scales 21 25 22 QwtScaleDraw can be used to draw linear or logarithmic scales. 23 A scale has a position, an alignment and a length, which can be specified . 24 The labels can be rotated and aligned 25 to the ticks using setLabelRotation() and setLabelAlignment(). 26 QwtScaleDraw can be used to draw linear or logarithmic scales. 27 A scale has a position, an alignment and a length, which can be specified . 28 The labels can be rotated and aligned 29 to the ticks using setLabelRotation() and setLabelAlignment(). 26 30 27 After a scale division has been specified as a QwtScaleDiv object 28 using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), 29 the scale can be drawn with the QwtAbstractScaleDraw::draw() member. 30 */ 31 class QWT_EXPORT QwtScaleDraw: public QwtAbstractScaleDraw 31 After a scale division has been specified as a QwtScaleDiv object 32 using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), 33 the scale can be drawn with the QwtAbstractScaleDraw::draw() member. 34 */ 35 class QWT_EXPORT QwtScaleDraw : public QwtAbstractScaleDraw 32 36 { 33 public: 37 public: 34 38 /*! 35 39 Alignment of the scale draw … … 54 58 virtual ~QwtScaleDraw(); 55 59 56 void getBorderDistHint( const QFont &, int &start, int&end ) const;57 int minLabelDist( const QFont & ) const;60 void getBorderDistHint( const QFont&, int& start, int& end ) const; 61 int minLabelDist( const QFont& ) const; 58 62 59 int minLength( const QFont & ) const;60 virtual double extent( const QFont & ) const;63 int minLength( const QFont& ) const; 64 virtual double extent( const QFont& ) const QWT_OVERRIDE; 61 65 62 66 void move( double x, double y ); 63 void move( const QPointF & );67 void move( const QPointF& ); 64 68 void setLength( double length ); 65 69 … … 78 82 double labelRotation() const; 79 83 80 int maxLabelHeight( const QFont & ) const;81 int maxLabelWidth( const QFont & ) const;84 int maxLabelHeight( const QFont& ) const; 85 int maxLabelWidth( const QFont& ) const; 82 86 83 87 QPointF labelPosition( double value ) const; 84 88 85 QRectF labelRect( const QFont &, double value ) const;86 QSizeF labelSize( const QFont &, double value ) const;89 QRectF labelRect( const QFont&, double value ) const; 90 QSizeF labelSize( const QFont&, double value ) const; 87 91 88 QRect boundingLabelRect( const QFont &, double value ) const;92 QRect boundingLabelRect( const QFont&, double value ) const; 89 93 90 protected: 91 QTransform labelTransformation( const QPointF &, const QSizeF& ) const;94 protected: 95 QTransform labelTransformation( const QPointF&, const QSizeF& ) const; 92 96 93 virtual void drawTick( QPainter *, double value, double len ) const; 94 virtual void drawBackbone( QPainter * ) const; 95 virtual void drawLabel( QPainter *, double value ) const; 97 virtual void drawTick( QPainter*, 98 double value, double len ) const QWT_OVERRIDE; 96 99 97 private: 98 QwtScaleDraw( const QwtScaleDraw & ); 99 QwtScaleDraw &operator=( const QwtScaleDraw &other ); 100 virtual void drawBackbone( QPainter* ) const QWT_OVERRIDE; 101 virtual void drawLabel( QPainter*, double value ) const QWT_OVERRIDE; 100 102 103 private: 101 104 void updateMap(); 102 105 103 106 class PrivateData; 104 PrivateData *d_data;107 PrivateData* m_data; 105 108 }; 106 109 … … 112 115 113 116 \sa move(const QPointF &) 114 */ 117 */ 115 118 inline void QwtScaleDraw::move( double x, double y ) 116 119 { -
trunk/BNC/qwt/qwt_scale_engine.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_scale_engine.h" 11 11 #include "qwt_math.h" 12 #include "qwt_scale_map.h" 13 #include <qalgorithms.h> 14 #include <qmath.h> 15 #include <float.h> 12 #include "qwt_interval.h" 13 #include "qwt_transform.h" 14 15 #include <qdebug.h> 16 16 17 #include <limits> 17 18 18 #if QT_VERSION < 0x04060119 #define qFabs(x) ::fabs(x)20 #define qExp(x) ::exp(x)21 #endif22 23 19 static inline double qwtLog( double base, double value ) 24 20 { 25 return log( value ) / log( base ); 26 } 27 28 static inline QwtInterval qwtLogInterval( double base, const QwtInterval &interval )21 return std::log( value ) / std::log( base ); 22 } 23 24 static inline QwtInterval qwtLogInterval( double base, const QwtInterval& interval ) 29 25 { 30 26 return QwtInterval( qwtLog( base, interval.minValue() ), 31 qwtLog( base, interval.maxValue() ) ); 32 } 33 34 static inline QwtInterval qwtPowInterval( double base, const QwtInterval &interval ) 35 { 36 return QwtInterval( qPow( base, interval.minValue() ), 37 qPow( base, interval.maxValue() ) ); 38 } 39 40 static inline long double qwtIntervalWidthL( const QwtInterval &interval ) 41 { 42 if ( !interval.isValid() ) 43 return 0.0; 44 45 return static_cast<long double>( interval.maxValue() ) 46 - static_cast<long double>( interval.minValue() ); 27 qwtLog( base, interval.maxValue() ) ); 28 } 29 30 static inline QwtInterval qwtPowInterval( double base, const QwtInterval& interval ) 31 { 32 return QwtInterval( std::pow( base, interval.minValue() ), 33 std::pow( base, interval.maxValue() ) ); 47 34 } 48 35 … … 58 45 { 59 46 // # ticks per interval 60 const int numTicks = qCeil( qAbs( intervalSize / minStep ) ) - 1; 47 const int numTicks = qwtCeil( qAbs( intervalSize / minStep ) ) - 1; 61 48 62 49 // Do the minor steps fit into the interval? 63 if ( qwtFuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ),50 if ( qwtFuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ), 64 51 qAbs( intervalSize ), intervalSize ) > 0 ) 65 52 { … … 85 72 const double stepSize = intervalSize / numSteps; 86 73 87 const double p = ::floor( ::log( stepSize ) / ::log( base ) ); 88 const double fraction = qPow( base, p );74 const double p = std::floor( std::log( stepSize ) / std::log( base ) ); 75 const double fraction = std::pow( base, p ); 89 76 90 77 for ( uint n = base; n > 1; n /= 2 ) … … 110 97 111 98 /*! 112 Ceil a value, relative to an interval 113 114 \param value Value to be ceiled 115 \param intervalSize Interval size 116 117 \return Rounded value 118 119 \sa floorEps() 120 */ 99 Ceil a value, relative to an interval 100 101 \param value Value to be ceiled 102 \param intervalSize Interval size 103 104 \return Rounded value 105 106 \sa floorEps() 107 */ 121 108 double QwtScaleArithmetic::ceilEps( double value, 122 109 double intervalSize ) … … 125 112 126 113 value = ( value - eps ) / intervalSize; 127 return ::ceil( value ) * intervalSize; 128 } 129 130 /*! 131 Floor a value, relative to an interval 132 133 \param value Value to be floored 134 \param intervalSize Interval size 135 136 \return Rounded value 137 \sa floorEps() 138 */ 114 return std::ceil( value ) * intervalSize; 115 } 116 117 /*! 118 Floor a value, relative to an interval 119 120 \param value Value to be floored 121 \param intervalSize Interval size 122 123 \return Rounded value 124 \sa floorEps() 125 */ 139 126 double QwtScaleArithmetic::floorEps( double value, double intervalSize ) 140 127 { … … 142 129 143 130 value = ( value + eps ) / intervalSize; 144 return ::floor( value ) * intervalSize; 145 } 146 147 /*! 148 \brief Divide an interval into steps 149 150 \f$stepSize = (intervalSize - intervalSize * 10e^{-6}) / numSteps\f$ 151 152 \param intervalSize Interval size 153 \param numSteps Number of steps 154 \return Step size 155 */ 131 return std::floor( value ) * intervalSize; 132 } 133 134 /*! 135 \brief Divide an interval into steps 136 137 \f$stepSize = (intervalSize - intervalSize * 10e^{-6}) / numSteps\f$ 138 139 \param intervalSize Interval size 140 \param numSteps Number of steps 141 \return Step size 142 */ 156 143 double QwtScaleArithmetic::divideEps( double intervalSize, double numSteps ) 157 144 { … … 163 150 164 151 /*! 165 Calculate a step size for a given interval 166 167 \param intervalSize Interval size 168 \param numSteps Number of steps 169 \param base Base for the division ( usually 10 ) 170 171 \return Calculated step size 152 Calculate a step size for a given interval 153 154 \param intervalSize Interval size 155 \param numSteps Number of steps 156 \param base Base for the division ( usually 10 ) 157 158 \return Calculated step size 172 159 */ 173 160 double QwtScaleArithmetic::divideInterval( … … 181 168 return 0.0; 182 169 183 const double lx = qwtLog( base, qFabs( v ) );184 const double p = ::floor( lx ); 185 186 const double fraction = qPow( base, lx - p );170 const double lx = qwtLog( base, std::fabs( v ) ); 171 const double p = std::floor( lx ); 172 173 const double fraction = std::pow( base, lx - p ); 187 174 188 175 uint n = base; … … 190 177 n /= 2; 191 178 192 double stepSize = n * qPow( base, p );179 double stepSize = n * std::pow( base, p ); 193 180 if ( v < 0 ) 194 181 stepSize = -stepSize; … … 199 186 class QwtScaleEngine::PrivateData 200 187 { 201 public: 188 public: 202 189 PrivateData(): 203 190 attributes( QwtScaleEngine::NoAttribute ), … … 228 215 229 216 /*! 230 Constructor 231 232 \param base Base of the scale engine 233 \sa setBase() 217 Constructor 218 219 \param base Base of the scale engine 220 \sa setBase() 234 221 */ 235 222 QwtScaleEngine::QwtScaleEngine( uint base ) 236 223 { 237 d_data = new PrivateData;224 m_data = new PrivateData; 238 225 setBase( base ); 239 226 } … … 243 230 QwtScaleEngine::~QwtScaleEngine () 244 231 { 245 delete d_data;232 delete m_data; 246 233 } 247 234 … … 259 246 260 247 */ 261 void QwtScaleEngine::setTransformation( QwtTransform *transform )262 { 263 if ( transform != d_data->transform )264 { 265 delete d_data->transform;266 d_data->transform = transform;248 void QwtScaleEngine::setTransformation( QwtTransform* transform ) 249 { 250 if ( transform != m_data->transform ) 251 { 252 delete m_data->transform; 253 m_data->transform = transform; 267 254 } 268 255 } … … 273 260 NULL is returned, indicating no transformation. 274 261 275 \return A clone of the transfomation 262 \return A clone of the transformation 276 263 \sa setTransformation() 277 264 */ 278 QwtTransform *QwtScaleEngine::transformation() const279 { 280 QwtTransform *transform = NULL;281 if ( d_data->transform )282 transform = d_data->transform->copy();265 QwtTransform* QwtScaleEngine::transformation() const 266 { 267 QwtTransform* transform = NULL; 268 if ( m_data->transform ) 269 transform = m_data->transform->copy(); 283 270 284 271 return transform; … … 290 277 291 278 \sa setMargins() 292 */ 279 */ 293 280 double QwtScaleEngine::lowerMargin() const 294 281 { 295 return d_data->lowerMargin;282 return m_data->lowerMargin; 296 283 } 297 284 … … 301 288 302 289 \sa setMargins() 303 */ 290 */ 304 291 double QwtScaleEngine::upperMargin() const 305 292 { 306 return d_data->upperMargin;307 } 308 309 /*! 310 \brief Specify margins at the scale's endpoints 311 \param lower minimum distance between the scale's lower boundary and the 293 return m_data->upperMargin; 294 } 295 296 /*! 297 \brief Specify margins at the scale's endpoints 298 \param lower minimum distance between the scale's lower boundary and the 312 299 smallest enclosed value 313 \param upper minimum distance between the scale's upper boundary and the 300 \param upper minimum distance between the scale's upper boundary and the 314 301 greatest enclosed value 315 302 316 Margins can be used to leave a minimum amount of space between 317 the enclosed intervals and the boundaries of the scale. 318 319 \warning 320 \li QwtLogScaleEngine measures the margins in decades. 321 322 \sa upperMargin(), lowerMargin() 323 */ 303 Margins can be used to leave a minimum amount of space between 304 the enclosed intervals and the boundaries of the scale. 305 306 \warning 307 \li QwtLogScaleEngine measures the margins in decades. 308 309 \sa upperMargin(), lowerMargin() 310 */ 324 311 325 312 void QwtScaleEngine::setMargins( double lower, double upper ) 326 313 { 327 d_data->lowerMargin = qMax( lower, 0.0 );328 d_data->upperMargin = qMax( upper, 0.0 );329 } 330 331 /*! 332 Calculate a step size for an interval size 333 334 \param intervalSize Interval size 335 \param numSteps Number of steps 336 337 \return Step size 338 */ 314 m_data->lowerMargin = qwtMaxF( lower, 0.0 ); 315 m_data->upperMargin = qwtMaxF( upper, 0.0 ); 316 } 317 318 /*! 319 Calculate a step size for an interval size 320 321 \param intervalSize Interval size 322 \param numSteps Number of steps 323 324 \return Step size 325 */ 339 326 double QwtScaleEngine::divideInterval( 340 327 double intervalSize, int numSteps ) const 341 328 { 342 329 return QwtScaleArithmetic::divideInterval( 343 intervalSize, numSteps, d_data->base );344 } 345 346 /*! 347 Check if an interval "contains" a value 348 349 \param interval Interval 350 \param value Value 351 352 \return True, when the value is inside the interval 353 */ 330 intervalSize, numSteps, m_data->base ); 331 } 332 333 /*! 334 Check if an interval "contains" a value 335 336 \param interval Interval 337 \param value Value 338 339 \return True, when the value is inside the interval 340 */ 354 341 bool QwtScaleEngine::contains( 355 const QwtInterval &interval, double value ) const342 const QwtInterval& interval, double value ) const 356 343 { 357 344 if ( !interval.isValid() ) … … 368 355 369 356 /*! 370 Remove ticks from a list, that are not inside an interval 371 372 \param ticks Tick list 373 \param interval Interval 374 375 \return Stripped tick list 376 */ 377 QList< double> QwtScaleEngine::strip( const QList<double>& ticks,378 const QwtInterval &interval ) const357 Remove ticks from a list, that are not inside an interval 358 359 \param ticks Tick list 360 \param interval Interval 361 362 \return Stripped tick list 363 */ 364 QList< double > QwtScaleEngine::strip( const QList< double >& ticks, 365 const QwtInterval& interval ) const 379 366 { 380 367 if ( !interval.isValid() || ticks.count() == 0 ) 381 return QList< double>();368 return QList< double >(); 382 369 383 370 if ( contains( interval, ticks.first() ) … … 387 374 } 388 375 389 QList< double> strippedTicks;376 QList< double > strippedTicks; 390 377 for ( int i = 0; i < ticks.count(); i++ ) 391 378 { … … 397 384 398 385 /*! 399 \brief Build an interval around a value 400 401 In case of v == 0.0 the interval is [-0.5, 0.5], 402 otherwide it is [0.5 * v, 1.5 * v]403 404 \param value Initial value 405 \return Calculated interval 406 */ 386 \brief Build an interval around a value 387 388 In case of v == 0.0 the interval is [-0.5, 0.5], 389 otherwise it is [0.5 * v, 1.5 * v] 390 391 \param value Initial value 392 \return Calculated interval 393 */ 407 394 408 395 QwtInterval QwtScaleEngine::buildInterval( double value ) const 409 396 { 410 397 const double delta = ( value == 0.0 ) ? 0.5 : qAbs( 0.5 * value ); 411 412 if ( DBL_MAX - delta < value ) 413 return QwtInterval( DBL_MAX - delta, DBL_MAX ); 414 415 if ( -DBL_MAX + delta > value ) 416 return QwtInterval( -DBL_MAX, -DBL_MAX + delta ); 398 const double max = std::numeric_limits< double >::max(); 399 400 if ( max - delta < value ) 401 return QwtInterval( max - delta, max ); 402 403 if ( -max + delta > value ) 404 return QwtInterval( -max, -max + delta ); 417 405 418 406 return QwtInterval( value - delta, value + delta ); … … 420 408 421 409 /*! 422 Change a scale attribute 423 424 \param attribute Attribute to change 425 \param on On/Off 426 427 \sa Attribute, testAttribute() 428 */ 410 Change a scale attribute 411 412 \param attribute Attribute to change 413 \param on On/Off 414 415 \sa Attribute, testAttribute() 416 */ 429 417 void QwtScaleEngine::setAttribute( Attribute attribute, bool on ) 430 418 { 431 419 if ( on ) 432 d_data->attributes |= attribute;420 m_data->attributes |= attribute; 433 421 else 434 d_data->attributes &= ~attribute;435 } 436 437 /*! 438 \return True, if attribute is enabled. 439 440 \param attribute Attribute to be tested 441 \sa Attribute, setAttribute() 442 */ 422 m_data->attributes &= ~attribute; 423 } 424 425 /*! 426 \return True, if attribute is enabled. 427 428 \param attribute Attribute to be tested 429 \sa Attribute, setAttribute() 430 */ 443 431 bool QwtScaleEngine::testAttribute( Attribute attribute ) const 444 432 { 445 return ( d_data->attributes & attribute );446 } 447 448 /*! 449 Change the scale attribute 450 451 \param attributes Set scale attributes 452 \sa Attribute, attributes() 453 */ 433 return ( m_data->attributes & attribute ); 434 } 435 436 /*! 437 Change the scale attribute 438 439 \param attributes Set scale attributes 440 \sa Attribute, attributes() 441 */ 454 442 void QwtScaleEngine::setAttributes( Attributes attributes ) 455 443 { 456 d_data->attributes = attributes;457 } 458 459 /*! 460 \return Scale attributes 461 \sa Attribute, setAttributes(), testAttribute() 462 */ 444 m_data->attributes = attributes; 445 } 446 447 /*! 448 \return Scale attributes 449 \sa Attribute, setAttributes(), testAttribute() 450 */ 463 451 QwtScaleEngine::Attributes QwtScaleEngine::attributes() const 464 452 { 465 return d_data->attributes;466 } 467 468 /*! 469 \brief Specify a reference point 470 \param reference New reference value 471 472 The reference point is needed if options IncludeReference or 473 Symmetric are active. Its default value is 0.0. 474 475 \sa Attribute 476 */ 453 return m_data->attributes; 454 } 455 456 /*! 457 \brief Specify a reference point 458 \param reference New reference value 459 460 The reference point is needed if options IncludeReference or 461 Symmetric are active. Its default value is 0.0. 462 463 \sa Attribute 464 */ 477 465 void QwtScaleEngine::setReference( double reference ) 478 466 { 479 d_data->referenceValue = reference;480 } 481 482 /*! 483 \return the reference value 484 \sa setReference(), setAttribute() 485 */ 467 m_data->referenceValue = reference; 468 } 469 470 /*! 471 \return the reference value 472 \sa setReference(), setAttribute() 473 */ 486 474 double QwtScaleEngine::reference() const 487 475 { 488 return d_data->referenceValue;489 } 490 491 /*! 492 Set the base of the scale engine 493 494 While a base of 10 is what 99.9% of all applications need 495 certain scales might need a different base: f.e 2 496 497 The default setting is 10 498 499 \param base Base of the engine 500 501 \sa base() 476 return m_data->referenceValue; 477 } 478 479 /*! 480 Set the base of the scale engine 481 482 While a base of 10 is what 99.9% of all applications need 483 certain scales might need a different base: f.e 2 484 485 The default setting is 10 486 487 \param base Base of the engine 488 489 \sa base() 502 490 */ 503 491 void QwtScaleEngine::setBase( uint base ) 504 492 { 505 d_data->base = qMax( base, 2U );506 } 507 508 /*! 509 \return base Base of the scale engine 510 \sa setBase() 493 m_data->base = qMax( base, 2U ); 494 } 495 496 /*! 497 \return base Base of the scale engine 498 \sa setBase() 511 499 */ 512 500 uint QwtScaleEngine::base() const 513 501 { 514 return d_data->base;515 } 516 517 /*! 518 Constructor 519 520 \param base Base of the scale engine 521 \sa setBase() 502 return m_data->base; 503 } 504 505 /*! 506 Constructor 507 508 \param base Base of the scale engine 509 \sa setBase() 522 510 */ 523 511 QwtLinearScaleEngine::QwtLinearScaleEngine( uint base ): … … 532 520 533 521 /*! 534 Align and divide an interval 535 536 \param maxNumSteps Max. number of steps 537 \param x1 First limit of the interval (In/Out) 538 \param x2 Second limit of the interval (In/Out) 539 \param stepSize Step size (Out) 540 541 \sa setAttribute() 542 */ 522 Align and divide an interval 523 524 \param maxNumSteps Max. number of steps 525 \param x1 First limit of the interval (In/Out) 526 \param x2 Second limit of the interval (In/Out) 527 \param stepSize Step size (Out) 528 529 \sa setAttribute() 530 */ 543 531 void QwtLinearScaleEngine::autoScale( int maxNumSteps, 544 double &x1, double&x2, double&stepSize ) const532 double& x1, double& x2, double& stepSize ) const 545 533 { 546 534 QwtInterval interval( x1, x2 ); … … 586 574 587 575 \return Calculated scale division 588 */ 576 */ 589 577 QwtScaleDiv QwtLinearScaleEngine::divideScale( double x1, double x2, 590 578 int maxMajorSteps, int maxMinorSteps, double stepSize ) const … … 592 580 QwtInterval interval = QwtInterval( x1, x2 ).normalized(); 593 581 594 if ( qwtIntervalWidthL(interval) > std::numeric_limits<double>::max() )582 if ( interval.widthL() > std::numeric_limits< double >::max() ) 595 583 { 596 584 qWarning() << "QwtLinearScaleEngine::divideScale: overflow"; … … 615 603 if ( stepSize != 0.0 ) 616 604 { 617 QList< double> ticks[QwtScaleDiv::NTickTypes];605 QList< double > ticks[QwtScaleDiv::NTickTypes]; 618 606 buildTicks( interval, stepSize, maxMinorSteps, ticks ); 619 607 … … 636 624 637 625 \sa buildMajorTicks(), buildMinorTicks 638 */ 626 */ 639 627 void QwtLinearScaleEngine::buildTicks( 640 628 const QwtInterval& interval, double stepSize, int maxMinorSteps, 641 QList< double> ticks[QwtScaleDiv::NTickTypes] ) const629 QList< double > ticks[QwtScaleDiv::NTickTypes] ) const 642 630 { 643 631 const QwtInterval boundingInterval = align( interval, stepSize ); … … 656 644 ticks[i] = strip( ticks[i], interval ); 657 645 658 // ticks very close to 0.0 are 659 // explicitely set to 0.0 646 // ticks very close to 0.0 are explicitly set to 0.0 660 647 661 648 for ( int j = 0; j < ticks[i].count(); j++ ) … … 674 661 675 662 \return Calculated ticks 676 */ 677 QList< double> QwtLinearScaleEngine::buildMajorTicks(678 const QwtInterval &interval, double stepSize ) const663 */ 664 QList< double > QwtLinearScaleEngine::buildMajorTicks( 665 const QwtInterval& interval, double stepSize ) const 679 666 { 680 667 int numTicks = qRound( interval.width() / stepSize ) + 1; … … 682 669 numTicks = 10000; 683 670 684 QList<double> ticks; 671 QList< double > ticks; 672 ticks.reserve( numTicks ); 685 673 686 674 ticks += interval.minValue(); … … 701 689 \param mediumTicks Array to be filled with the calculated medium ticks 702 690 703 */ 691 */ 704 692 void QwtLinearScaleEngine::buildMinorTicks( 705 const QList< double>& majorTicks,693 const QList< double >& majorTicks, 706 694 int maxMinorSteps, double stepSize, 707 QList< double> &minorTicks,708 QList< double> &mediumTicks ) const695 QList< double >& minorTicks, 696 QList< double >& mediumTicks ) const 709 697 { 710 698 double minStep = qwtStepSize( stepSize, maxMinorSteps, base() ); … … 713 701 714 702 // # ticks per interval 715 const int numTicks = qCeil( qAbs( stepSize / minStep ) ) - 1; 703 const int numTicks = qwtCeil( qAbs( stepSize / minStep ) ) - 1; 716 704 717 705 int medIndex = -1; … … 741 729 742 730 /*! 743 \brief Align an interval to a step size 744 745 The limits of an interval are aligned that both are integer 746 multiples of the step size. 747 748 \param interval Interval 749 \param stepSize Step size 750 751 \return Aligned interval 752 */ 731 \brief Align an interval to a step size 732 733 The limits of an interval are aligned that both are integer 734 multiples of the step size. 735 736 \param interval Interval 737 \param stepSize Step size 738 739 \return Aligned interval 740 */ 753 741 QwtInterval QwtLinearScaleEngine::align( 754 const QwtInterval &interval, double stepSize ) const742 const QwtInterval& interval, double stepSize ) const 755 743 { 756 744 double x1 = interval.minValue(); … … 761 749 762 750 const double eps = 0.000000000001; // since Qt 4.8: qFuzzyIsNull 763 if ( -DBL_MAX + stepSize <= x1 ) 751 const double max = std::numeric_limits< double >::max(); 752 753 if ( -max + stepSize <= x1 ) 764 754 { 765 755 const double x = QwtScaleArithmetic::floorEps( x1, stepSize ); … … 768 758 } 769 759 770 if ( DBL_MAX- stepSize >= x2 )760 if ( max - stepSize >= x2 ) 771 761 { 772 762 const double x = QwtScaleArithmetic::ceilEps( x2, stepSize ); … … 779 769 780 770 /*! 781 Constructor 782 783 \param base Base of the scale engine 784 \sa setBase() 771 Constructor 772 773 \param base Base of the scale engine 774 \sa setBase() 785 775 */ 786 776 QwtLogScaleEngine::QwtLogScaleEngine( uint base ): … … 804 794 805 795 \sa QwtScaleEngine::setAttribute() 806 */ 796 */ 807 797 void QwtLogScaleEngine::autoScale( int maxNumSteps, 808 double &x1, double&x2, double&stepSize ) const798 double& x1, double& x2, double& stepSize ) const 809 799 { 810 800 if ( x1 > x2 ) … … 813 803 const double logBase = base(); 814 804 815 QwtInterval interval( x1 / qPow( logBase, lowerMargin() ),816 x2 * qPow( logBase, upperMargin() ) );805 QwtInterval interval( x1 / std::pow( logBase, lowerMargin() ), 806 x2 * std::pow( logBase, upperMargin() ) ); 817 807 818 808 if ( interval.maxValue() / interval.minValue() < logBase ) … … 828 818 829 819 QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized(); 830 linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX ); 820 linearInterval = linearInterval.limited( 821 QwtLogTransform::LogMin, QwtLogTransform::LogMax ); 831 822 832 823 if ( linearInterval.maxValue() / linearInterval.minValue() < logBase ) 833 824 { 834 // the aligned scale is still less than one step 835 836 #if 1 837 // this code doesn't make any sense, but for compatibility 838 // reasons we keep it until 6.2. But it will be ignored 839 // in divideScale 840 841 if ( stepSize < 0.0 ) 842 stepSize = -qwtLog( logBase, qAbs( stepSize ) ); 843 else 844 stepSize = qwtLog( logBase, stepSize ); 845 #endif 846 825 stepSize = 0.0; 847 826 return; 848 827 } … … 850 829 851 830 double logRef = 1.0; 852 if ( reference() > LOG_MIN/ 2 )853 logRef = q Min( reference(),LOG_MAX/ 2 );831 if ( reference() > QwtLogTransform::LogMin / 2 ) 832 logRef = qwtMinF( reference(), QwtLogTransform::LogMax / 2 ); 854 833 855 834 if ( testAttribute( QwtScaleEngine::Symmetric ) ) 856 835 { 857 const double delta = q Max( interval.maxValue() / logRef,836 const double delta = qwtMaxF( interval.maxValue() / logRef, 858 837 logRef / interval.minValue() ); 859 838 interval.setInterval( logRef / delta, logRef * delta ); … … 863 842 interval = interval.extend( logRef ); 864 843 865 interval = interval.limited( LOG_MIN, LOG_MAX);844 interval = interval.limited( QwtLogTransform::LogMin, QwtLogTransform::LogMax ); 866 845 867 846 if ( interval.width() == 0.0 ) … … 897 876 898 877 \return Calculated scale division 899 */ 878 */ 900 879 QwtScaleDiv QwtLogScaleEngine::divideScale( double x1, double x2, 901 880 int maxMajorSteps, int maxMinorSteps, double stepSize ) const 902 881 { 903 882 QwtInterval interval = QwtInterval( x1, x2 ).normalized(); 904 interval = interval.limited( LOG_MIN, LOG_MAX);883 interval = interval.limited( QwtLogTransform::LogMin, QwtLogTransform::LogMax ); 905 884 906 885 if ( interval.width() <= 0 ) … … 937 916 if ( stepSize != 0.0 ) 938 917 { 939 QList< double> ticks[QwtScaleDiv::NTickTypes];918 QList< double > ticks[QwtScaleDiv::NTickTypes]; 940 919 buildTicks( interval, stepSize, maxMinorSteps, ticks ); 941 920 … … 958 937 959 938 \sa buildMajorTicks(), buildMinorTicks 960 */ 939 */ 961 940 void QwtLogScaleEngine::buildTicks( 962 941 const QwtInterval& interval, double stepSize, int maxMinorSteps, 963 QList< double> ticks[QwtScaleDiv::NTickTypes] ) const942 QList< double > ticks[QwtScaleDiv::NTickTypes] ) const 964 943 { 965 944 const QwtInterval boundingInterval = align( interval, stepSize ); … … 985 964 986 965 \return Calculated ticks 987 */ 988 QList< double> QwtLogScaleEngine::buildMajorTicks(989 const QwtInterval &interval, double stepSize ) const966 */ 967 QList< double > QwtLogScaleEngine::buildMajorTicks( 968 const QwtInterval& interval, double stepSize ) const 990 969 { 991 970 double width = qwtLogInterval( base(), interval ).width(); … … 995 974 numTicks = 10000; 996 975 997 const double lxmin = ::log( interval.minValue() ); 998 const double lxmax = ::log( interval.maxValue() ); 976 const double lxmin = std::log( interval.minValue() ); 977 const double lxmax = std::log( interval.maxValue() ); 999 978 const double lstep = ( lxmax - lxmin ) / double( numTicks - 1 ); 1000 979 1001 QList<double> ticks; 980 QList< double > ticks; 981 ticks.reserve( numTicks ); 1002 982 1003 983 ticks += interval.minValue(); 1004 984 1005 985 for ( int i = 1; i < numTicks - 1; i++ ) 1006 ticks += qExp( lxmin + double( i ) * lstep );986 ticks += std::exp( lxmin + double( i ) * lstep ); 1007 987 1008 988 ticks += interval.maxValue(); … … 1019 999 \param minorTicks Array to be filled with the calculated minor ticks 1020 1000 \param mediumTicks Array to be filled with the calculated medium ticks 1021 */ 1001 */ 1022 1002 void QwtLogScaleEngine::buildMinorTicks( 1023 const QList< double> &majorTicks,1003 const QList< double >& majorTicks, 1024 1004 int maxMinorSteps, double stepSize, 1025 QList< double> &minorTicks,1026 QList< double> &mediumTicks ) const1005 QList< double >& minorTicks, 1006 QList< double >& mediumTicks ) const 1027 1007 { 1028 1008 const double logBase = base(); … … 1081 1061 1082 1062 // Do the minor steps fit into the interval? 1083 if ( qwtFuzzyCompare( ( numTicks + 1 ) * minStep,1063 if ( qwtFuzzyCompare( ( numTicks + 1 ) * minStep, 1084 1064 stepSize, stepSize ) > 0 ) 1085 1065 { … … 1095 1075 1096 1076 // substep factor = base^substeps 1097 const qreal minFactor = q Max( qPow( logBase, minStep ),qreal( logBase ));1077 const qreal minFactor = qwtMaxF( std::pow( logBase, minStep ), logBase ); 1098 1078 1099 1079 for ( int i = 0; i < majorTicks.count(); i++ ) … … 1114 1094 1115 1095 /*! 1116 \brief Align an interval to a step size 1117 1118 The limits of an interval are aligned that both are integer 1119 multiples of the step size. 1120 1121 \param interval Interval 1122 \param stepSize Step size 1123 1124 \return Aligned interval 1125 */ 1096 \brief Align an interval to a step size 1097 1098 The limits of an interval are aligned that both are integer 1099 multiples of the step size. 1100 1101 \param interval Interval 1102 \param stepSize Step size 1103 1104 \return Aligned interval 1105 */ 1126 1106 QwtInterval QwtLogScaleEngine::align( 1127 const QwtInterval &interval, double stepSize ) const1107 const QwtInterval& interval, double stepSize ) const 1128 1108 { 1129 1109 const QwtInterval intv = qwtLogInterval( base(), interval ); -
trunk/BNC/qwt/qwt_scale_engine.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_scale_div.h" 15 #include "qwt_interval.h" 16 15 16 class QwtInterval; 17 17 class QwtTransform; 18 18 19 19 /*! 20 \brief Arithmetic including a tolerance 21 */ 20 \brief Arithmetic including a tolerance 21 */ 22 22 class QWT_EXPORT QwtScaleArithmetic 23 23 { 24 public: 24 public: 25 25 static double ceilEps( double value, double intervalSize ); 26 26 static double floorEps( double value, double intervalSize ); … … 33 33 34 34 /*! 35 \brief Base class for scale engines. 36 37 A scale engine tries to find "reasonable" ranges and step sizes 38 for scales. 39 40 The layout of the scale can be varied with setAttribute(). 41 42 Qwt offers implementations for logarithmic and linear scales. 43 */ 35 \brief Base class for scale engines. 36 37 A scale engine tries to find "reasonable" ranges and step sizes 38 for scales. 39 40 The layout of the scale can be varied with setAttribute(). 41 42 Qwt offers implementations for logarithmic and linear scales. 43 */ 44 44 45 45 class QWT_EXPORT QwtScaleEngine 46 46 { 47 public: 47 public: 48 48 /*! 49 49 Layout attributes … … 76 76 }; 77 77 78 //! Layout attributes 79 typedef QFlags<Attribute> Attributes; 78 Q_DECLARE_FLAGS( Attributes, Attribute ) 80 79 81 80 explicit QwtScaleEngine( uint base = 10 ); … … 99 98 100 99 /*! 101 Align and divide an interval 102 103 \param maxNumSteps Max. number of steps 104 \param x1 First limit of the interval (In/Out) 105 \param x2 Second limit of the interval (In/Out) 106 \param stepSize Step size (Return value) 107 */ 100 Align and divide an interval 101 102 \param maxNumSteps Max. number of steps 103 \param x1 First limit of the interval (In/Out) 104 \param x2 Second limit of the interval (In/Out) 105 \param stepSize Step size (Return value) 106 */ 108 107 virtual void autoScale( int maxNumSteps, 109 double &x1, double&x2, double&stepSize ) const = 0;108 double& x1, double& x2, double& stepSize ) const = 0; 110 109 111 110 /*! 112 \brief Calculate a scale division 113 114 \param x1 First interval limit 115 \param x2 Second interval limit 116 \param maxMajorSteps Maximum for the number of major steps 117 \param maxMinorSteps Maximum number of minor steps 118 \param stepSize Step size. If stepSize == 0.0, the scaleEngine 111 \brief Calculate a scale division 112 113 \param x1 First interval limit 114 \param x2 Second interval limit 115 \param maxMajorSteps Maximum for the number of major steps 116 \param maxMinorSteps Maximum number of minor steps 117 \param stepSize Step size. If stepSize == 0.0, the scaleEngine 119 118 calculates one. 120 119 121 \return Calculated scale division 122 */ 120 \return Calculated scale division 121 */ 123 122 virtual QwtScaleDiv divideScale( double x1, double x2, 124 123 int maxMajorSteps, int maxMinorSteps, 125 124 double stepSize = 0.0 ) const = 0; 126 125 127 void setTransformation( QwtTransform * );128 QwtTransform *transformation() const;129 130 protected: 131 bool contains( const QwtInterval &, double value ) const;132 QList< double> strip( const QList<double>&, const QwtInterval& ) const;126 void setTransformation( QwtTransform* ); 127 QwtTransform* transformation() const; 128 129 protected: 130 bool contains( const QwtInterval&, double value ) const; 131 QList< double > strip( const QList< double >&, const QwtInterval& ) const; 133 132 134 133 double divideInterval( double intervalSize, int numSteps ) const; … … 136 135 QwtInterval buildInterval( double value ) const; 137 136 138 private: 137 private: 138 Q_DISABLE_COPY(QwtScaleEngine) 139 139 140 class PrivateData; 140 PrivateData *d_data;141 }; 142 143 /*! 144 \brief A scale engine for linear scales 145 146 The step size will fit into the pattern 147 \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer. 148 */ 149 150 class QWT_EXPORT QwtLinearScaleEngine: public QwtScaleEngine 151 { 152 public: 153 QwtLinearScaleEngine( uint base = 10 ); 141 PrivateData* m_data; 142 }; 143 144 /*! 145 \brief A scale engine for linear scales 146 147 The step size will fit into the pattern 148 \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer. 149 */ 150 151 class QWT_EXPORT QwtLinearScaleEngine : public QwtScaleEngine 152 { 153 public: 154 explicit QwtLinearScaleEngine( uint base = 10 ); 154 155 virtual ~QwtLinearScaleEngine(); 155 156 156 157 virtual void autoScale( int maxNumSteps, 157 double &x1, double&x2, double&stepSize ) const;158 double& x1, double& x2, double& stepSize ) const QWT_OVERRIDE; 158 159 159 160 virtual QwtScaleDiv divideScale( double x1, double x2, 160 161 int maxMajorSteps, int maxMinorSteps, 161 double stepSize = 0.0 ) const; 162 163 164 protected: 162 double stepSize = 0.0 ) const QWT_OVERRIDE; 163 164 165 protected: 165 166 QwtInterval align( const QwtInterval&, double stepSize ) const; 166 167 167 168 void buildTicks( 168 const QwtInterval &, double stepSize, int maxMinorSteps,169 QList< double> ticks[QwtScaleDiv::NTickTypes] ) const;170 171 QList< double> buildMajorTicks(172 const QwtInterval &interval, double stepSize ) const;173 174 void buildMinorTicks( const QList< double>& majorTicks,169 const QwtInterval&, double stepSize, int maxMinorSteps, 170 QList< double > ticks[QwtScaleDiv::NTickTypes] ) const; 171 172 QList< double > buildMajorTicks( 173 const QwtInterval& interval, double stepSize ) const; 174 175 void buildMinorTicks( const QList< double >& majorTicks, 175 176 int maxMinorSteps, double stepSize, 176 QList< double> &minorTicks, QList<double> &mediumTicks ) const;177 }; 178 179 /*! 180 \brief A scale engine for logarithmic scales 181 182 The step size is measured in *decades* 183 and the major step size will be adjusted to fit the pattern 184 \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number 185 including zero. 186 187 \warning the step size as well as the margins are measured in *decades*. 188 */ 189 190 class QWT_EXPORT QwtLogScaleEngine: public QwtScaleEngine 191 { 192 public: 193 QwtLogScaleEngine( uint base = 10 ); 177 QList< double >& minorTicks, QList< double >& mediumTicks ) const; 178 }; 179 180 /*! 181 \brief A scale engine for logarithmic scales 182 183 The step size is measured in *decades* 184 and the major step size will be adjusted to fit the pattern 185 \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number 186 including zero. 187 188 \warning the step size as well as the margins are measured in *decades*. 189 */ 190 191 class QWT_EXPORT QwtLogScaleEngine : public QwtScaleEngine 192 { 193 public: 194 explicit QwtLogScaleEngine( uint base = 10 ); 194 195 virtual ~QwtLogScaleEngine(); 195 196 196 197 virtual void autoScale( int maxNumSteps, 197 double &x1, double&x2, double&stepSize ) const;198 double& x1, double& x2, double& stepSize ) const QWT_OVERRIDE; 198 199 199 200 virtual QwtScaleDiv divideScale( double x1, double x2, 200 201 int maxMajorSteps, int maxMinorSteps, 201 double stepSize = 0.0 ) const; 202 203 protected: 202 double stepSize = 0.0 ) const QWT_OVERRIDE; 203 204 protected: 204 205 QwtInterval align( const QwtInterval&, double stepSize ) const; 205 206 206 207 void buildTicks( 207 const QwtInterval &, double stepSize, int maxMinorSteps,208 QList< double> ticks[QwtScaleDiv::NTickTypes] ) const;209 210 QList< double> buildMajorTicks(211 const QwtInterval &interval, double stepSize ) const;212 213 void buildMinorTicks( const QList< double>& majorTicks,208 const QwtInterval&, double stepSize, int maxMinorSteps, 209 QList< double > ticks[QwtScaleDiv::NTickTypes] ) const; 210 211 QList< double > buildMajorTicks( 212 const QwtInterval& interval, double stepSize ) const; 213 214 void buildMinorTicks( const QList< double >& majorTicks, 214 215 int maxMinorSteps, double stepSize, 215 QList< double> &minorTicks, QList<double> &mediumTicks ) const;216 QList< double >& minorTicks, QList< double >& mediumTicks ) const; 216 217 }; 217 218 -
trunk/BNC/qwt/qwt_scale_map.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_scale_map.h" 11 11 #include "qwt_math.h" 12 12 13 #include <qrect.h> 13 14 #include <qdebug.h> 14 15 15 16 /*! 16 \brief Constructor 17 18 The scale and paint device intervals are both set to [0,1]. 19 */ 20 QwtScaleMap::QwtScaleMap() :21 d_s1( 0.0 ),22 d_s2( 1.0 ),23 d_p1( 0.0 ),24 d_p2( 1.0 ),25 d_cnv( 1.0 ),26 d_ts1( 0.0 ),27 d_transform( NULL )17 \brief Constructor 18 19 The scale and paint device intervals are both set to [0,1]. 20 */ 21 QwtScaleMap::QwtScaleMap() 22 : m_s1( 0.0 ) 23 , m_s2( 1.0 ) 24 , m_p1( 0.0 ) 25 , m_p2( 1.0 ) 26 , m_cnv( 1.0 ) 27 , m_ts1( 0.0 ) 28 , m_transform( NULL ) 28 29 { 29 30 } 30 31 31 32 //! Copy constructor 32 QwtScaleMap::QwtScaleMap( const QwtScaleMap& other ) :33 d_s1( other.d_s1 ),34 d_s2( other.d_s2 ),35 d_p1( other.d_p1 ),36 d_p2( other.d_p2 ),37 d_cnv( other.d_cnv ),38 d_ts1( other.d_ts1 ),39 d_transform( NULL )40 { 41 if ( other. d_transform )42 d_transform = other.d_transform->copy();43 } 44 45 /*! 46 Destructor 47 */ 33 QwtScaleMap::QwtScaleMap( const QwtScaleMap& other ) 34 : m_s1( other.m_s1 ) 35 , m_s2( other.m_s2 ) 36 , m_p1( other.m_p1 ) 37 , m_p2( other.m_p2 ) 38 , m_cnv( other.m_cnv ) 39 , m_ts1( other.m_ts1 ) 40 , m_transform( NULL ) 41 { 42 if ( other.m_transform ) 43 m_transform = other.m_transform->copy(); 44 } 45 46 /*! 47 Destructor 48 */ 48 49 QwtScaleMap::~QwtScaleMap() 49 50 { 50 delete d_transform;51 delete m_transform; 51 52 } 52 53 53 54 //! Assignment operator 54 QwtScaleMap &QwtScaleMap::operator=( const QwtScaleMap& other )55 { 56 d_s1 = other.d_s1;57 d_s2 = other.d_s2;58 d_p1 = other.d_p1;59 d_p2 = other.d_p2;60 d_cnv = other.d_cnv;61 d_ts1 = other.d_ts1;62 63 delete d_transform;64 d_transform = NULL;65 66 if ( other. d_transform )67 d_transform = other.d_transform->copy();55 QwtScaleMap& QwtScaleMap::operator=( const QwtScaleMap& other ) 56 { 57 m_s1 = other.m_s1; 58 m_s2 = other.m_s2; 59 m_p1 = other.m_p1; 60 m_p2 = other.m_p2; 61 m_cnv = other.m_cnv; 62 m_ts1 = other.m_ts1; 63 64 delete m_transform; 65 m_transform = NULL; 66 67 if ( other.m_transform ) 68 m_transform = other.m_transform->copy(); 68 69 69 70 return *this; … … 72 73 /*! 73 74 Initialize the map with a transformation 74 */ 75 void QwtScaleMap::setTransformation( QwtTransform *transform )76 { 77 if ( transform != d_transform )75 */ 76 void QwtScaleMap::setTransformation( QwtTransform* transform ) 77 { 78 if ( transform != m_transform ) 78 79 { 79 delete d_transform;80 d_transform = transform;80 delete m_transform; 81 m_transform = transform; 81 82 } 82 83 83 setScaleInterval( d_s1, d_s2 );84 setScaleInterval( m_s1, m_s2 ); 84 85 } 85 86 86 87 //! Get the transformation 87 const QwtTransform *QwtScaleMap::transformation() const88 { 89 return d_transform;90 } 91 92 /*! 93 \brief Specify the borders of the scale interval 94 \param s1 first border 95 \param s2 second border 96 \warning scales might be aligned to 88 const QwtTransform* QwtScaleMap::transformation() const 89 { 90 return m_transform; 91 } 92 93 /*! 94 \brief Specify the borders of the scale interval 95 \param s1 first border 96 \param s2 second border 97 \warning scales might be aligned to 97 98 transformation depending boundaries 98 */ 99 */ 99 100 void QwtScaleMap::setScaleInterval( double s1, double s2 ) 100 101 { 101 d_s1 = s1;102 d_s2 = s2;103 104 if ( d_transform )102 m_s1 = s1; 103 m_s2 = s2; 104 105 if ( m_transform ) 105 106 { 106 d_s1 = d_transform->bounded(d_s1 );107 d_s2 = d_transform->bounded(d_s2 );107 m_s1 = m_transform->bounded( m_s1 ); 108 m_s2 = m_transform->bounded( m_s2 ); 108 109 } 109 110 … … 112 113 113 114 /*! 114 \brief Specify the borders of the paint device interval 115 \param p1 first border 116 \param p2 second border 117 */ 115 \brief Specify the borders of the paint device interval 116 \param p1 first border 117 \param p2 second border 118 */ 118 119 void QwtScaleMap::setPaintInterval( double p1, double p2 ) 119 120 { 120 d_p1 = p1;121 d_p2 = p2;121 m_p1 = p1; 122 m_p2 = p2; 122 123 123 124 updateFactor(); … … 126 127 void QwtScaleMap::updateFactor() 127 128 { 128 d_ts1 =d_s1;129 double ts2 = d_s2;130 131 if ( d_transform )129 m_ts1 = m_s1; 130 double ts2 = m_s2; 131 132 if ( m_transform ) 132 133 { 133 d_ts1 =d_transform->transform(d_ts1 );134 ts2 = d_transform->transform( ts2 );134 m_ts1 = m_transform->transform( m_ts1 ); 135 ts2 = m_transform->transform( ts2 ); 135 136 } 136 137 137 d_cnv = 1.0;138 if ( d_ts1 != ts2 )139 d_cnv = (d_p2 - d_p1 ) / ( ts2 -d_ts1 );138 m_cnv = 1.0; 139 if ( m_ts1 != ts2 ) 140 m_cnv = ( m_p2 - m_p1 ) / ( ts2 - m_ts1 ); 140 141 } 141 142 … … 149 150 150 151 \sa invTransform() 151 */ 152 QRectF QwtScaleMap::transform( const QwtScaleMap &xMap,153 const QwtScaleMap &yMap, const QRectF&rect )152 */ 153 QRectF QwtScaleMap::transform( const QwtScaleMap& xMap, 154 const QwtScaleMap& yMap, const QRectF& rect ) 154 155 { 155 156 double x1 = xMap.transform( rect.left() ); … … 183 184 \return Position in scale coordinates 184 185 \sa transform() 185 */ 186 QPointF QwtScaleMap::invTransform( const QwtScaleMap &xMap,187 const QwtScaleMap &yMap, const QPointF&pos )186 */ 187 QPointF QwtScaleMap::invTransform( const QwtScaleMap& xMap, 188 const QwtScaleMap& yMap, const QPointF& pos ) 188 189 { 189 190 return QPointF( 190 191 xMap.invTransform( pos.x() ), 191 192 yMap.invTransform( pos.y() ) 192 ); 193 ); 193 194 } 194 195 … … 202 203 203 204 \sa invTransform() 204 */ 205 QPointF QwtScaleMap::transform( const QwtScaleMap &xMap,206 const QwtScaleMap &yMap, const QPointF&pos )205 */ 206 QPointF QwtScaleMap::transform( const QwtScaleMap& xMap, 207 const QwtScaleMap& yMap, const QPointF& pos ) 207 208 { 208 209 return QPointF( 209 210 xMap.transform( pos.x() ), 210 211 yMap.transform( pos.y() ) 211 ); 212 ); 212 213 } 213 214 … … 220 221 \return Rectangle in scale coordinates 221 222 \sa transform() 222 */ 223 QRectF QwtScaleMap::invTransform( const QwtScaleMap &xMap,224 const QwtScaleMap &yMap, const QRectF&rect )223 */ 224 QRectF QwtScaleMap::invTransform( const QwtScaleMap& xMap, 225 const QwtScaleMap& yMap, const QRectF& rect ) 225 226 { 226 227 const double x1 = xMap.invTransform( rect.left() ); … … 235 236 #ifndef QT_NO_DEBUG_STREAM 236 237 237 QDebug operator<<( QDebug debug, const QwtScaleMap &map )238 QDebug operator<<( QDebug debug, const QwtScaleMap& map ) 238 239 { 239 240 debug.nospace() << "QwtScaleMap(" 240 << map.transformation() 241 << ", s:" << map.s1() << "->" << map.s2() 242 << ", p:" << map.p1() << "->" << map.p2() 243 << ")"; 241 << map.transformation() 242 << ", s:" << map.s1() << "->" << map.s2() 243 << ", p:" << map.p1() << "->" << map.p2() 244 << ")"; 244 245 245 246 return debug.space(); -
trunk/BNC/qwt/qwt_scale_map.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_transform.h" 15 #include <qrect.h>16 15 17 #ifndef QT_NO_DEBUG_STREAM 18 #include <qdebug.h> 19 #endif 20 16 class QPointF; 21 17 class QRectF; 22 18 … … 27 23 of a scale into the linear coordinate system of a paint device 28 24 and vice versa. 29 */ 25 */ 30 26 class QWT_EXPORT QwtScaleMap 31 27 { 32 public: 28 public: 33 29 QwtScaleMap(); 34 30 QwtScaleMap( const QwtScaleMap& ); … … 36 32 ~QwtScaleMap(); 37 33 38 QwtScaleMap &operator=( const QwtScaleMap& );34 QwtScaleMap& operator=( const QwtScaleMap& ); 39 35 40 void setTransformation( QwtTransform * );41 const QwtTransform *transformation() const;36 void setTransformation( QwtTransform* ); 37 const QwtTransform* transformation() const; 42 38 43 39 void setPaintInterval( double p1, double p2 ); … … 56 52 double sDist() const; 57 53 58 static QRectF transform( const QwtScaleMap &, 59 const QwtScaleMap &, const QRectF & ); 60 static QRectF invTransform( const QwtScaleMap &, 61 const QwtScaleMap &, const QRectF & ); 54 static QRectF transform( const QwtScaleMap&, 55 const QwtScaleMap&, const QRectF& ); 62 56 63 static QPointF transform( const QwtScaleMap &, 64 const QwtScaleMap &, const QPointF & ); 65 static QPointF invTransform( const QwtScaleMap &, 66 const QwtScaleMap &, const QPointF & ); 57 static QRectF invTransform( const QwtScaleMap&, 58 const QwtScaleMap&, const QRectF& ); 59 60 static QPointF transform( const QwtScaleMap&, 61 const QwtScaleMap&, const QPointF& ); 62 63 static QPointF invTransform( const QwtScaleMap&, 64 const QwtScaleMap&, const QPointF& ); 67 65 68 66 bool isInverting() const; 69 67 70 private: 68 private: 71 69 void updateFactor(); 72 70 73 double d_s1, d_s2; // scale interval boundaries74 double d_p1, d_p2; // paint device interval boundaries71 double m_s1, m_s2; // scale interval boundaries 72 double m_p1, m_p2; // paint device interval boundaries 75 73 76 double d_cnv; // conversion factor77 double d_ts1;74 double m_cnv; // conversion factor 75 double m_ts1; 78 76 79 QwtTransform *d_transform;77 QwtTransform* m_transform; 80 78 }; 81 79 82 80 /*! 83 81 \return First border of the scale interval 84 */ 82 */ 85 83 inline double QwtScaleMap::s1() const 86 84 { 87 return d_s1;85 return m_s1; 88 86 } 89 87 90 88 /*! 91 89 \return Second border of the scale interval 92 */ 90 */ 93 91 inline double QwtScaleMap::s2() const 94 92 { 95 return d_s2;93 return m_s2; 96 94 } 97 95 98 96 /*! 99 97 \return First border of the paint interval 100 */ 98 */ 101 99 inline double QwtScaleMap::p1() const 102 100 { 103 return d_p1;101 return m_p1; 104 102 } 105 103 106 104 /*! 107 105 \return Second border of the paint interval 108 */ 106 */ 109 107 inline double QwtScaleMap::p2() const 110 108 { 111 return d_p2;109 return m_p2; 112 110 } 113 111 114 112 /*! 115 113 \return qwtAbs(p2() - p1()) 116 */ 114 */ 117 115 inline double QwtScaleMap::pDist() const 118 116 { 119 return qAbs( d_p2 - d_p1 );117 return qAbs( m_p2 - m_p1 ); 120 118 } 121 119 122 120 /*! 123 121 \return qwtAbs(s2() - s1()) 124 */ 122 */ 125 123 inline double QwtScaleMap::sDist() const 126 124 { 127 return qAbs( d_s2 - d_s1 );125 return qAbs( m_s2 - m_s1 ); 128 126 } 129 127 130 128 /*! 131 Transform a point related to the scale interval into an point 132 related to the interval of the paint device 129 Transform a point related to the scale interval into an point 130 related to the interval of the paint device 133 131 134 \param s Value relative to the coordinates of the scale 135 \return Transformed value 132 \param s Value relative to the coordinates of the scale 133 \return Transformed value 136 134 137 \sa invTransform() 138 */ 135 \sa invTransform() 136 */ 139 137 inline double QwtScaleMap::transform( double s ) const 140 138 { 141 if ( d_transform )142 s = d_transform->transform( s );139 if ( m_transform ) 140 s = m_transform->transform( s ); 143 141 144 return d_p1 + ( s -d_ts1 ) *d_cnv;142 return m_p1 + ( s - m_ts1 ) * m_cnv; 145 143 } 146 144 147 145 /*! 148 Transform an paint device value into a value in the 149 interval of the scale. 146 Transform an paint device value into a value in the 147 interval of the scale. 150 148 151 \param p Value relative to the coordinates of the paint device 152 \return Transformed value 149 \param p Value relative to the coordinates of the paint device 150 \return Transformed value 153 151 154 \sa transform() 155 */ 152 \sa transform() 153 */ 156 154 inline double QwtScaleMap::invTransform( double p ) const 157 155 { 158 double s = d_ts1 + ( p -d_p1 ) /d_cnv;159 if ( d_transform )160 s = d_transform->invTransform( s );156 double s = m_ts1 + ( p - m_p1 ) / m_cnv; 157 if ( m_transform ) 158 s = m_transform->invTransform( s ); 161 159 162 160 return s; … … 166 164 inline bool QwtScaleMap::isInverting() const 167 165 { 168 return ( ( d_p1 < d_p2 ) != (d_s1 < d_s2 ) );166 return ( ( m_p1 < m_p2 ) != ( m_s1 < m_s2 ) ); 169 167 } 170 168 171 169 #ifndef QT_NO_DEBUG_STREAM 172 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );170 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap& ); 173 171 #endif 174 172 -
trunk/BNC/qwt/qwt_scale_widget.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 #include "qwt_scale_div.h" 16 16 #include "qwt_text.h" 17 #include "qwt_interval.h" 17 18 #include "qwt_scale_engine.h" 19 18 20 #include <qpainter.h> 19 21 #include <qevent.h> 20 #include <qmath.h>21 22 #include <qstyle.h> 22 23 #include <qstyleoption.h> 23 24 #include <qapplication.h> 25 #include <qmargins.h> 24 26 25 27 class QwtScaleWidget::PrivateData 26 28 { 27 public: 28 PrivateData() :29 scaleDraw( NULL ) 29 public: 30 PrivateData() 31 : scaleDraw( NULL ) 30 32 { 31 33 colorBar.colorMap = NULL; … … 38 40 } 39 41 40 QwtScaleDraw *scaleDraw;42 QwtScaleDraw* scaleDraw; 41 43 42 44 int borderDist[2]; … … 56 58 int width; 57 59 QwtInterval interval; 58 QwtColorMap *colorMap;60 QwtColorMap* colorMap; 59 61 } colorBar; 60 62 }; 61 63 62 64 /*! 63 \brief Create a scale with the position QwtScaleWidget::Left 64 \param parent Parent widget 65 */ 66 QwtScaleWidget::QwtScaleWidget( QWidget *parent ):67 QWidget( parent ) 65 \brief Create a scale with the position QwtScaleWidget::Left 66 \param parent Parent widget 67 */ 68 QwtScaleWidget::QwtScaleWidget( QWidget* parent ) 69 : QWidget( parent ) 68 70 { 69 71 initScale( QwtScaleDraw::LeftScale ); … … 71 73 72 74 /*! 73 \brief Constructor 74 \param align Alignment. 75 \param parent Parent widget 76 */ 77 QwtScaleWidget::QwtScaleWidget( 78 QwtScaleDraw::Alignment align, QWidget *parent ): 79 QWidget( parent ) 75 \brief Constructor 76 \param align Alignment. 77 \param parent Parent widget 78 */ 79 QwtScaleWidget::QwtScaleWidget( QwtScaleDraw::Alignment align, QWidget* parent ) 80 : QWidget( parent ) 80 81 { 81 82 initScale( align ); … … 85 86 QwtScaleWidget::~QwtScaleWidget() 86 87 { 87 delete d_data;88 delete m_data; 88 89 } 89 90 … … 91 92 void QwtScaleWidget::initScale( QwtScaleDraw::Alignment align ) 92 93 { 93 d_data = new PrivateData; 94 95 d_data->layoutFlags = 0; 94 m_data = new PrivateData; 95 96 96 if ( align == QwtScaleDraw::RightScale ) 97 d_data->layoutFlags |= TitleInverted;98 99 d_data->borderDist[0] = 0;100 d_data->borderDist[1] = 0;101 d_data->minBorderDist[0] = 0;102 d_data->minBorderDist[1] = 0;103 d_data->margin = 4;104 d_data->titleOffset = 0;105 d_data->spacing = 2;106 107 d_data->scaleDraw = new QwtScaleDraw;108 d_data->scaleDraw->setAlignment( align );109 d_data->scaleDraw->setLength( 10 );110 111 d_data->scaleDraw->setScaleDiv(97 m_data->layoutFlags |= TitleInverted; 98 99 m_data->borderDist[0] = 0; 100 m_data->borderDist[1] = 0; 101 m_data->minBorderDist[0] = 0; 102 m_data->minBorderDist[1] = 0; 103 m_data->margin = 4; 104 m_data->titleOffset = 0; 105 m_data->spacing = 2; 106 107 m_data->scaleDraw = new QwtScaleDraw; 108 m_data->scaleDraw->setAlignment( align ); 109 m_data->scaleDraw->setLength( 10 ); 110 111 m_data->scaleDraw->setScaleDiv( 112 112 QwtLinearScaleEngine().divideScale( 0.0, 100.0, 10, 5 ) ); 113 113 114 d_data->colorBar.colorMap = new QwtLinearColorMap();115 d_data->colorBar.isEnabled = false;116 d_data->colorBar.width = 10;114 m_data->colorBar.colorMap = new QwtLinearColorMap(); 115 m_data->colorBar.isEnabled = false; 116 m_data->colorBar.width = 10; 117 117 118 118 const int flags = Qt::AlignHCenter 119 119 | Qt::TextExpandTabs | Qt::TextWordWrap; 120 d_data->title.setRenderFlags( flags );121 d_data->title.setFont( font() );120 m_data->title.setRenderFlags( flags ); 121 m_data->title.setFont( font() ); 122 122 123 123 QSizePolicy policy( QSizePolicy::MinimumExpanding, 124 124 QSizePolicy::Fixed ); 125 if ( d_data->scaleDraw->orientation() == Qt::Vertical )125 if ( m_data->scaleDraw->orientation() == Qt::Vertical ) 126 126 policy.transpose(); 127 127 … … 138 138 139 139 \sa testLayoutFlag(), LayoutFlag 140 */ 140 */ 141 141 void QwtScaleWidget::setLayoutFlag( LayoutFlag flag, bool on ) 142 142 { 143 if ( ( ( d_data->layoutFlags & flag ) != 0 ) != on )143 if ( ( ( m_data->layoutFlags & flag ) != 0 ) != on ) 144 144 { 145 145 if ( on ) 146 d_data->layoutFlags |= flag;146 m_data->layoutFlags |= flag; 147 147 else 148 d_data->layoutFlags &= ~flag;148 m_data->layoutFlags &= ~flag; 149 149 150 150 update(); … … 158 158 \return true/false 159 159 \sa setLayoutFlag(), LayoutFlag 160 */ 160 */ 161 161 bool QwtScaleWidget::testLayoutFlag( LayoutFlag flag ) const 162 162 { 163 return ( d_data->layoutFlags & flag );164 } 165 166 /*! 167 Give title new text contents 168 169 \param title New title 170 \sa title(), setTitle(const QwtText &); 171 */ 172 void QwtScaleWidget::setTitle( const QString &title )173 { 174 if ( d_data->title.text() != title )175 { 176 d_data->title.setText( title );163 return ( m_data->layoutFlags & flag ); 164 } 165 166 /*! 167 Give title new text contents 168 169 \param title New title 170 \sa title(), setTitle(const QwtText &); 171 */ 172 void QwtScaleWidget::setTitle( const QString& title ) 173 { 174 if ( m_data->title.text() != title ) 175 { 176 m_data->title.setText( title ); 177 177 layoutScale(); 178 178 } … … 180 180 181 181 /*! 182 Give title new text contents 183 184 \param title New title 185 \sa title() 186 \warning The title flags are interpreted in 182 Give title new text contents 183 184 \param title New title 185 \sa title() 186 \warning The title flags are interpreted in 187 187 direction of the label, AlignTop, AlignBottom can't be set 188 188 as the title will always be aligned to the scale. 189 */ 190 void QwtScaleWidget::setTitle( const QwtText &title )189 */ 190 void QwtScaleWidget::setTitle( const QwtText& title ) 191 191 { 192 192 QwtText t = title; … … 194 194 t.setRenderFlags( flags ); 195 195 196 if ( t != d_data->title )197 { 198 d_data->title = t;196 if ( t != m_data->title ) 197 { 198 m_data->title = t; 199 199 layoutScale(); 200 200 } … … 202 202 203 203 /*! 204 Change the alignment 205 206 \param alignment New alignment 207 \sa alignment() 208 */ 204 Change the alignment 205 206 \param alignment New alignment 207 \sa alignment() 208 */ 209 209 void QwtScaleWidget::setAlignment( QwtScaleDraw::Alignment alignment ) 210 210 { 211 if ( d_data->scaleDraw ) 212 d_data->scaleDraw->setAlignment( alignment ); 211 if ( m_data->scaleDraw == NULL ) 212 return; 213 214 m_data->scaleDraw->setAlignment( alignment ); 213 215 214 216 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) 215 217 { 216 QSizePolicy policy( QSizePolicy::MinimumExpanding, 217 QSizePolicy::Fixed ); 218 if ( d_data->scaleDraw->orientation() == Qt::Vertical ) 218 QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); 219 if ( m_data->scaleDraw->orientation() == Qt::Vertical ) 219 220 policy.transpose(); 220 221 … … 231 232 \return position 232 233 \sa setPosition() 233 */ 234 */ 234 235 QwtScaleDraw::Alignment QwtScaleWidget::alignment() const 235 236 { … … 241 242 242 243 /*! 243 Specify distances of the scale's endpoints from the 244 widget's borders. The actual borders will never be less 245 than minimum border distance. 246 \param dist1 Left or top Distance 247 \param dist2 Right or bottom distance 248 \sa borderDist() 249 */ 244 Specify distances of the scale's endpoints from the 245 widget's borders. The actual borders will never be less 246 than minimum border distance. 247 \param dist1 Left or top Distance 248 \param dist2 Right or bottom distance 249 \sa borderDist() 250 */ 250 251 void QwtScaleWidget::setBorderDist( int dist1, int dist2 ) 251 252 { 252 if ( dist1 != d_data->borderDist[0] || dist2 !=d_data->borderDist[1] )253 { 254 d_data->borderDist[0] = dist1;255 d_data->borderDist[1] = dist2;253 if ( dist1 != m_data->borderDist[0] || dist2 != m_data->borderDist[1] ) 254 { 255 m_data->borderDist[0] = dist1; 256 m_data->borderDist[1] = dist2; 256 257 layoutScale(); 257 258 } … … 259 260 260 261 /*! 261 \brief Specify the margin to the colorBar/base line. 262 \param margin Margin 263 \sa margin() 264 */ 262 \brief Specify the margin to the colorBar/base line. 263 \param margin Margin 264 \sa margin() 265 */ 265 266 void QwtScaleWidget::setMargin( int margin ) 266 267 { 267 268 margin = qMax( 0, margin ); 268 if ( margin != d_data->margin )269 { 270 d_data->margin = margin;269 if ( margin != m_data->margin ) 270 { 271 m_data->margin = margin; 271 272 layoutScale(); 272 273 } … … 274 275 275 276 /*! 276 \brief Specify the distance between color bar, scale and title 277 \param spacing Spacing 278 \sa spacing() 279 */ 277 \brief Specify the distance between color bar, scale and title 278 \param spacing Spacing 279 \sa spacing() 280 */ 280 281 void QwtScaleWidget::setSpacing( int spacing ) 281 282 { 282 283 spacing = qMax( 0, spacing ); 283 if ( spacing != d_data->spacing )284 { 285 d_data->spacing = spacing;284 if ( spacing != m_data->spacing ) 285 { 286 m_data->spacing = spacing; 286 287 layoutScale(); 287 288 } … … 289 290 290 291 /*! 291 \brief Change the alignment for the labels. 292 293 \sa QwtScaleDraw::setLabelAlignment(), setLabelRotation() 294 */ 292 \brief Change the alignment for the labels. 293 294 \sa QwtScaleDraw::setLabelAlignment(), setLabelRotation() 295 */ 295 296 void QwtScaleWidget::setLabelAlignment( Qt::Alignment alignment ) 296 297 { 297 d_data->scaleDraw->setLabelAlignment( alignment );298 m_data->scaleDraw->setLabelAlignment( alignment ); 298 299 layoutScale(); 299 300 } 300 301 301 302 /*! 302 \brief Change the rotation for the labels. 303 See QwtScaleDraw::setLabelRotation(). 304 305 \param rotation Rotation 306 \sa QwtScaleDraw::setLabelRotation(), setLabelFlags() 307 */ 303 \brief Change the rotation for the labels. 304 See QwtScaleDraw::setLabelRotation(). 305 306 \param rotation Rotation 307 \sa QwtScaleDraw::setLabelRotation(), setLabelFlags() 308 */ 308 309 void QwtScaleWidget::setLabelRotation( double rotation ) 309 310 { 310 d_data->scaleDraw->setLabelRotation( rotation );311 m_data->scaleDraw->setLabelRotation( rotation ); 311 312 layoutScale(); 312 313 } 313 314 314 315 /*! 315 Set a scale draw 316 317 scaleDraw has to be created with new and will be deleted in 318 ~QwtScaleWidget() or the next call of setScaleDraw(). 319 scaleDraw will be initialized with the attributes of 320 the previous scaleDraw object. 321 322 \param scaleDraw ScaleDraw object 323 \sa scaleDraw() 324 */ 325 void QwtScaleWidget::setScaleDraw( QwtScaleDraw *scaleDraw )326 { 327 if ( ( scaleDraw == NULL ) || ( scaleDraw == d_data->scaleDraw ) )316 Set a scale draw 317 318 scaleDraw has to be created with new and will be deleted in 319 ~QwtScaleWidget() or the next call of setScaleDraw(). 320 scaleDraw will be initialized with the attributes of 321 the previous scaleDraw object. 322 323 \param scaleDraw ScaleDraw object 324 \sa scaleDraw() 325 */ 326 void QwtScaleWidget::setScaleDraw( QwtScaleDraw* scaleDraw ) 327 { 328 if ( ( scaleDraw == NULL ) || ( scaleDraw == m_data->scaleDraw ) ) 328 329 return; 329 330 330 const QwtScaleDraw* sd = d_data->scaleDraw;331 const QwtScaleDraw* sd = m_data->scaleDraw; 331 332 if ( sd ) 332 333 { … … 334 335 scaleDraw->setScaleDiv( sd->scaleDiv() ); 335 336 336 QwtTransform *transform = NULL;337 QwtTransform* transform = NULL; 337 338 if ( sd->scaleMap().transformation() ) 338 339 transform = sd->scaleMap().transformation()->copy(); … … 341 342 } 342 343 343 delete d_data->scaleDraw;344 d_data->scaleDraw = scaleDraw;344 delete m_data->scaleDraw; 345 m_data->scaleDraw = scaleDraw; 345 346 346 347 layoutScale(); … … 350 351 \return scaleDraw of this scale 351 352 \sa setScaleDraw(), QwtScaleDraw::setScaleDraw() 352 */ 353 const QwtScaleDraw *QwtScaleWidget::scaleDraw() const354 { 355 return d_data->scaleDraw;353 */ 354 const QwtScaleDraw* QwtScaleWidget::scaleDraw() const 355 { 356 return m_data->scaleDraw; 356 357 } 357 358 … … 359 360 \return scaleDraw of this scale 360 361 \sa QwtScaleDraw::setScaleDraw() 361 */ 362 QwtScaleDraw *QwtScaleWidget::scaleDraw()363 { 364 return d_data->scaleDraw;362 */ 363 QwtScaleDraw* QwtScaleWidget::scaleDraw() 364 { 365 return m_data->scaleDraw; 365 366 } 366 367 … … 368 369 \return title 369 370 \sa setTitle() 370 */ 371 */ 371 372 QwtText QwtScaleWidget::title() const 372 373 { 373 return d_data->title;374 return m_data->title; 374 375 } 375 376 … … 377 378 \return start border distance 378 379 \sa setBorderDist() 379 */ 380 */ 380 381 int QwtScaleWidget::startBorderDist() const 381 382 { 382 return d_data->borderDist[0];383 return m_data->borderDist[0]; 383 384 } 384 385 … … 386 387 \return end border distance 387 388 \sa setBorderDist() 388 */ 389 */ 389 390 int QwtScaleWidget::endBorderDist() const 390 391 { 391 return d_data->borderDist[1];392 return m_data->borderDist[1]; 392 393 } 393 394 … … 395 396 \return margin 396 397 \sa setMargin() 397 */ 398 */ 398 399 int QwtScaleWidget::margin() const 399 400 { 400 return d_data->margin;401 return m_data->margin; 401 402 } 402 403 … … 404 405 \return distance between scale and title 405 406 \sa setMargin() 406 */ 407 */ 407 408 int QwtScaleWidget::spacing() const 408 409 { 409 return d_data->spacing;410 } 411 412 /*! 413 \brief paintEvent 414 */ 415 void QwtScaleWidget::paintEvent( QPaintEvent *event )410 return m_data->spacing; 411 } 412 413 /*! 414 \brief paintEvent 415 */ 416 void QwtScaleWidget::paintEvent( QPaintEvent* event ) 416 417 { 417 418 QPainter painter( this ); … … 419 420 420 421 QStyleOption opt; 421 opt.init(this); 422 opt.initFrom(this); 422 423 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 423 424 … … 426 427 427 428 /*! 428 \brief draw the scale 429 */ 430 void QwtScaleWidget::draw( QPainter *painter ) const431 { 432 d_data->scaleDraw->draw( painter, palette() );433 434 if ( d_data->colorBar.isEnabled &&d_data->colorBar.width > 0 &&435 d_data->colorBar.interval.isValid() )429 \brief draw the scale 430 */ 431 void QwtScaleWidget::draw( QPainter* painter ) const 432 { 433 m_data->scaleDraw->draw( painter, palette() ); 434 435 if ( m_data->colorBar.isEnabled && m_data->colorBar.width > 0 && 436 m_data->colorBar.interval.isValid() ) 436 437 { 437 438 drawColorBar( painter, colorBarRect( contentsRect() ) ); … … 439 440 440 441 QRect r = contentsRect(); 441 if ( d_data->scaleDraw->orientation() == Qt::Horizontal )442 { 443 r.setLeft( r.left() + d_data->borderDist[0] );444 r.setWidth( r.width() - d_data->borderDist[1] );442 if ( m_data->scaleDraw->orientation() == Qt::Horizontal ) 443 { 444 r.setLeft( r.left() + m_data->borderDist[0] ); 445 r.setWidth( r.width() - m_data->borderDist[1] ); 445 446 } 446 447 else 447 448 { 448 r.setTop( r.top() + d_data->borderDist[0] );449 r.setHeight( r.height() - d_data->borderDist[1] );450 } 451 452 if ( ! d_data->title.isEmpty() )453 drawTitle( painter, d_data->scaleDraw->alignment(), r );454 } 455 456 /*! 457 Calculate the the rectangle for the color bar 458 459 \param rect Bounding rectangle for all components of the scale 460 \return Rectangle for the color bar 461 */ 449 r.setTop( r.top() + m_data->borderDist[0] ); 450 r.setHeight( r.height() - m_data->borderDist[1] ); 451 } 452 453 if ( !m_data->title.isEmpty() ) 454 drawTitle( painter, m_data->scaleDraw->alignment(), r ); 455 } 456 457 /*! 458 Calculate the the rectangle for the color bar 459 460 \param rect Bounding rectangle for all components of the scale 461 \return Rectangle for the color bar 462 */ 462 463 QRectF QwtScaleWidget::colorBarRect( const QRectF& rect ) const 463 464 { 464 465 QRectF cr = rect; 465 466 466 if ( d_data->scaleDraw->orientation() == Qt::Horizontal )467 { 468 cr.setLeft( cr.left() + d_data->borderDist[0] );469 cr.setWidth( cr.width() - d_data->borderDist[1] + 1 );467 if ( m_data->scaleDraw->orientation() == Qt::Horizontal ) 468 { 469 cr.setLeft( cr.left() + m_data->borderDist[0] ); 470 cr.setWidth( cr.width() - m_data->borderDist[1] + 1 ); 470 471 } 471 472 else 472 473 { 473 cr.setTop( cr.top() + d_data->borderDist[0] );474 cr.setHeight( cr.height() - d_data->borderDist[1] + 1 );475 } 476 477 switch ( d_data->scaleDraw->alignment() )474 cr.setTop( cr.top() + m_data->borderDist[0] ); 475 cr.setHeight( cr.height() - m_data->borderDist[1] + 1 ); 476 } 477 478 switch ( m_data->scaleDraw->alignment() ) 478 479 { 479 480 case QwtScaleDraw::LeftScale: 480 481 { 481 cr.setLeft( cr.right() - d_data->margin482 - d_data->colorBar.width );483 cr.setWidth( d_data->colorBar.width );482 cr.setLeft( cr.right() - m_data->margin 483 - m_data->colorBar.width ); 484 cr.setWidth( m_data->colorBar.width ); 484 485 break; 485 486 } … … 487 488 case QwtScaleDraw::RightScale: 488 489 { 489 cr.setLeft( cr.left() + d_data->margin );490 cr.setWidth( d_data->colorBar.width );490 cr.setLeft( cr.left() + m_data->margin ); 491 cr.setWidth( m_data->colorBar.width ); 491 492 break; 492 493 } … … 494 495 case QwtScaleDraw::BottomScale: 495 496 { 496 cr.setTop( cr.top() + d_data->margin );497 cr.setHeight( d_data->colorBar.width );497 cr.setTop( cr.top() + m_data->margin ); 498 cr.setHeight( m_data->colorBar.width ); 498 499 break; 499 500 } … … 501 502 case QwtScaleDraw::TopScale: 502 503 { 503 cr.setTop( cr.bottom() - d_data->margin504 - d_data->colorBar.width );505 cr.setHeight( d_data->colorBar.width );504 cr.setTop( cr.bottom() - m_data->margin 505 - m_data->colorBar.width ); 506 cr.setHeight( m_data->colorBar.width ); 506 507 break; 507 508 } … … 512 513 513 514 /*! 514 Event handler for resize events 515 \param event Resize event 516 */ 517 void QwtScaleWidget::resizeEvent( QResizeEvent *event ) 515 Change Event handler 516 \param event Change event 517 518 Invalidates internal caches if necessary 519 */ 520 void QwtScaleWidget::changeEvent( QEvent* event ) 521 { 522 if ( event->type() == QEvent::LocaleChange ) 523 { 524 m_data->scaleDraw->invalidateCache(); 525 } 526 527 QWidget::changeEvent( event ); 528 } 529 530 /*! 531 Event handler for resize events 532 \param event Resize event 533 */ 534 void QwtScaleWidget::resizeEvent( QResizeEvent* event ) 518 535 { 519 536 Q_UNUSED( event ); … … 522 539 523 540 /*! 524 Recalculate the scale's geometry and layout based on 525 the current geometry and fonts. 526 527 \param update_geometry Notify the layout system and call update 541 Recalculate the scale's geometry and layout based on 542 the current geometry and fonts. 543 544 \param update_geometry Notify the layout system and call update 528 545 to redraw the scale 529 */ 546 */ 530 547 531 548 void QwtScaleWidget::layoutScale( bool update_geometry ) … … 533 550 int bd0, bd1; 534 551 getBorderDistHint( bd0, bd1 ); 535 if ( d_data->borderDist[0] > bd0 )536 bd0 = d_data->borderDist[0];537 if ( d_data->borderDist[1] > bd1 )538 bd1 = d_data->borderDist[1];552 if ( m_data->borderDist[0] > bd0 ) 553 bd0 = m_data->borderDist[0]; 554 if ( m_data->borderDist[1] > bd1 ) 555 bd1 = m_data->borderDist[1]; 539 556 540 557 int colorBarWidth = 0; 541 if ( d_data->colorBar.isEnabled &&d_data->colorBar.interval.isValid() )542 colorBarWidth = d_data->colorBar.width +d_data->spacing;558 if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.isValid() ) 559 colorBarWidth = m_data->colorBar.width + m_data->spacing; 543 560 544 561 const QRectF r = contentsRect(); 545 562 double x, y, length; 546 563 547 if ( d_data->scaleDraw->orientation() == Qt::Vertical )564 if ( m_data->scaleDraw->orientation() == Qt::Vertical ) 548 565 { 549 566 y = r.top() + bd0; 550 567 length = r.height() - ( bd0 + bd1 ); 551 568 552 if ( d_data->scaleDraw->alignment() == QwtScaleDraw::LeftScale )553 x = r.right() - 1.0 - d_data->margin - colorBarWidth;569 if ( m_data->scaleDraw->alignment() == QwtScaleDraw::LeftScale ) 570 x = r.right() - 1.0 - m_data->margin - colorBarWidth; 554 571 else 555 x = r.left() + d_data->margin + colorBarWidth;572 x = r.left() + m_data->margin + colorBarWidth; 556 573 } 557 574 else … … 560 577 length = r.width() - ( bd0 + bd1 ); 561 578 562 if ( d_data->scaleDraw->alignment() == QwtScaleDraw::BottomScale )563 y = r.top() + d_data->margin + colorBarWidth;579 if ( m_data->scaleDraw->alignment() == QwtScaleDraw::BottomScale ) 580 y = r.top() + m_data->margin + colorBarWidth; 564 581 else 565 y = r.bottom() - 1.0 - d_data->margin - colorBarWidth;566 } 567 568 d_data->scaleDraw->move( x, y );569 d_data->scaleDraw->setLength( length );570 571 const int extent = q Ceil( d_data->scaleDraw->extent( font() ) );572 573 d_data->titleOffset =574 d_data->margin +d_data->spacing + colorBarWidth + extent;582 y = r.bottom() - 1.0 - m_data->margin - colorBarWidth; 583 } 584 585 m_data->scaleDraw->move( x, y ); 586 m_data->scaleDraw->setLength( length ); 587 588 const int extent = qwtCeil( m_data->scaleDraw->extent( font() ) ); 589 590 m_data->titleOffset = 591 m_data->margin + m_data->spacing + colorBarWidth + extent; 575 592 576 593 if ( update_geometry ) … … 599 616 600 617 /*! 601 Draw the color bar of the scale widget 602 603 \param painter Painter 604 \param rect Bounding rectangle for the color bar 605 606 \sa setColorBarEnabled() 607 */ 608 void QwtScaleWidget::drawColorBar( QPainter *painter, const QRectF& rect ) const609 { 610 if ( ! d_data->colorBar.interval.isValid() )618 Draw the color bar of the scale widget 619 620 \param painter Painter 621 \param rect Bounding rectangle for the color bar 622 623 \sa setColorBarEnabled() 624 */ 625 void QwtScaleWidget::drawColorBar( QPainter* painter, const QRectF& rect ) const 626 { 627 if ( !m_data->colorBar.interval.isValid() ) 611 628 return; 612 629 613 const QwtScaleDraw* sd = d_data->scaleDraw;614 615 QwtPainter::drawColorBar( painter, * d_data->colorBar.colorMap,616 d_data->colorBar.interval.normalized(), sd->scaleMap(),630 const QwtScaleDraw* sd = m_data->scaleDraw; 631 632 QwtPainter::drawColorBar( painter, *m_data->colorBar.colorMap, 633 m_data->colorBar.interval.normalized(), sd->scaleMap(), 617 634 sd->orientation(), rect ); 618 635 } 619 636 620 637 /*! 621 Rotate and paint a title according to its position into a given rectangle. 622 623 \param painter Painter 624 \param align Alignment 625 \param rect Bounding rectangle 626 */ 627 628 void QwtScaleWidget::drawTitle( QPainter *painter,629 QwtScaleDraw::Alignment align, const QRectF &rect ) const638 Rotate and paint a title according to its position into a given rectangle. 639 640 \param painter Painter 641 \param align Alignment 642 \param rect Bounding rectangle 643 */ 644 645 void QwtScaleWidget::drawTitle( QPainter* painter, 646 QwtScaleDraw::Alignment align, const QRectF& rect ) const 630 647 { 631 648 QRectF r = rect; 632 649 double angle; 633 int flags = d_data->title.renderFlags() &650 int flags = m_data->title.renderFlags() & 634 651 ~( Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter ); 635 652 … … 640 657 flags |= Qt::AlignTop; 641 658 r.setRect( r.left(), r.bottom(), 642 r.height(), r.width() - d_data->titleOffset );659 r.height(), r.width() - m_data->titleOffset ); 643 660 break; 644 661 … … 646 663 angle = -90.0; 647 664 flags |= Qt::AlignTop; 648 r.setRect( r.left() + d_data->titleOffset, r.bottom(),649 r.height(), r.width() - d_data->titleOffset );665 r.setRect( r.left() + m_data->titleOffset, r.bottom(), 666 r.height(), r.width() - m_data->titleOffset ); 650 667 break; 651 668 … … 653 670 angle = 0.0; 654 671 flags |= Qt::AlignBottom; 655 r.setTop( r.top() + d_data->titleOffset );672 r.setTop( r.top() + m_data->titleOffset ); 656 673 break; 657 674 … … 660 677 angle = 0.0; 661 678 flags |= Qt::AlignTop; 662 r.setBottom( r.bottom() - d_data->titleOffset );679 r.setBottom( r.bottom() - m_data->titleOffset ); 663 680 break; 664 681 } 665 682 666 if ( d_data->layoutFlags & TitleInverted )683 if ( m_data->layoutFlags & TitleInverted ) 667 684 { 668 685 if ( align == QwtScaleDraw::LeftScale … … 683 700 painter->rotate( angle ); 684 701 685 QwtText title = d_data->title;702 QwtText title = m_data->title; 686 703 title.setRenderFlags( flags ); 687 704 title.draw( painter, QRectF( 0.0, 0.0, r.width(), r.height() ) ); … … 691 708 692 709 /*! 693 \brief Notify a change of the scale 694 695 This virtual function can be overloaded by derived 696 classes. The default implementation updates the geometry 697 and repaints the widget. 698 */ 710 \brief Notify a change of the scale 711 712 This virtual function can be overloaded by derived 713 classes. The default implementation updates the geometry 714 and repaints the widget. 715 */ 699 716 700 717 void QwtScaleWidget::scaleChange() … … 704 721 705 722 /*! 706 \return a size hint 707 */ 723 \return a size hint 724 */ 708 725 QSize QwtScaleWidget::sizeHint() const 709 726 { … … 712 729 713 730 /*! 714 \return a minimum size hint 715 */ 731 \return a minimum size hint 732 */ 716 733 QSize QwtScaleWidget::minimumSizeHint() const 717 734 { 718 const Qt::Orientation o = d_data->scaleDraw->orientation();735 const Qt::Orientation o = m_data->scaleDraw->orientation(); 719 736 720 737 // Border Distance cannot be less than the scale borderDistHint … … 723 740 int mbd1, mbd2; 724 741 getBorderDistHint( mbd1, mbd2 ); 725 length += qMax( 0, d_data->borderDist[0] - mbd1 );726 length += qMax( 0, d_data->borderDist[1] - mbd2 );727 length += d_data->scaleDraw->minLength( font() );742 length += qMax( 0, m_data->borderDist[0] - mbd1 ); 743 length += qMax( 0, m_data->borderDist[1] - mbd2 ); 744 length += m_data->scaleDraw->minLength( font() ); 728 745 729 746 int dim = dimForLength( length, font() ); … … 739 756 size.transpose(); 740 757 741 int left, right, top, bottom; 742 getContentsMargins( &left, &top, &right, &bottom ); 743 return size + QSize( left + right, top + bottom ); 744 } 745 746 /*! 747 \brief Find the height of the title for a given width. 748 \param width Width 749 \return height Height 758 const QMargins m = contentsMargins(); 759 return size + QSize( m.left() + m.right(), m.top() + m.bottom() ); 760 } 761 762 /*! 763 \brief Find the height of the title for a given width. 764 \param width Width 765 \return height Height 750 766 */ 751 767 752 768 int QwtScaleWidget::titleHeightForWidth( int width ) const 753 769 { 754 return q Ceil( d_data->title.heightForWidth( width, font() ) );755 } 756 757 /*! 758 \brief Find the minimum dimension for a given length. 770 return qwtCeil( m_data->title.heightForWidth( width, font() ) ); 771 } 772 773 /*! 774 \brief Find the minimum dimension for a given length. 759 775 dim is the height, length the width seen in 760 776 direction of the title. 761 \param length width for horizontal, height for vertical scales 762 \param scaleFont Font of the scale 763 \return height for horizontal, width for vertical scales 764 */ 765 766 int QwtScaleWidget::dimForLength( int length, const QFont &scaleFont ) const767 { 768 const int extent = q Ceil( d_data->scaleDraw->extent( scaleFont ) );769 770 int dim = d_data->margin + extent + 1;771 772 if ( ! d_data->title.isEmpty() )773 dim += titleHeightForWidth( length ) + d_data->spacing;774 775 if ( d_data->colorBar.isEnabled &&d_data->colorBar.interval.isValid() )776 dim += d_data->colorBar.width +d_data->spacing;777 \param length width for horizontal, height for vertical scales 778 \param scaleFont Font of the scale 779 \return height for horizontal, width for vertical scales 780 */ 781 782 int QwtScaleWidget::dimForLength( int length, const QFont& scaleFont ) const 783 { 784 const int extent = qwtCeil( m_data->scaleDraw->extent( scaleFont ) ); 785 786 int dim = m_data->margin + extent + 1; 787 788 if ( !m_data->title.isEmpty() ) 789 dim += titleHeightForWidth( length ) + m_data->spacing; 790 791 if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.isValid() ) 792 dim += m_data->colorBar.width + m_data->spacing; 777 793 778 794 return dim; … … 780 796 781 797 /*! 782 \brief Calculate a hint for the border distances. 783 784 This member function calculates the distance 785 of the scale's endpoints from the widget borders which 786 is required for the mark labels to fit into the widget. 787 The maximum of this distance an the minimum border distance 788 is returned. 789 790 \param start Return parameter for the border width at 798 \brief Calculate a hint for the border distances. 799 800 This member function calculates the distance 801 of the scale's endpoints from the widget borders which 802 is required for the mark labels to fit into the widget. 803 The maximum of this distance an the minimum border distance 804 is returned. 805 806 \param start Return parameter for the border width at 791 807 the beginning of the scale 792 \param end Return parameter for the border width at the 808 \param end Return parameter for the border width at the 793 809 end of the scale 794 810 795 \warning 796 <ul> <li>The minimum border distance depends on the font.</ul> 797 \sa setMinBorderDist(), getMinBorderDist(), setBorderDist() 798 */ 799 void QwtScaleWidget::getBorderDistHint( int &start, int&end ) const800 { 801 d_data->scaleDraw->getBorderDistHint( font(), start, end );802 803 if ( start < d_data->minBorderDist[0] )804 start = d_data->minBorderDist[0];805 806 if ( end < d_data->minBorderDist[1] )807 end = d_data->minBorderDist[1];808 } 809 810 /*! 811 Set a minimum value for the distances of the scale's endpoints from 812 the widget borders. This is useful to avoid that the scales 813 are "jumping", when the tick labels or their positions change 814 often. 815 816 \param start Minimum for the start border 817 \param end Minimum for the end border 818 \sa getMinBorderDist(), getBorderDistHint() 819 */ 811 \warning 812 <ul> <li>The minimum border distance depends on the font.</ul> 813 \sa setMinBorderDist(), getMinBorderDist(), setBorderDist() 814 */ 815 void QwtScaleWidget::getBorderDistHint( int& start, int& end ) const 816 { 817 m_data->scaleDraw->getBorderDistHint( font(), start, end ); 818 819 if ( start < m_data->minBorderDist[0] ) 820 start = m_data->minBorderDist[0]; 821 822 if ( end < m_data->minBorderDist[1] ) 823 end = m_data->minBorderDist[1]; 824 } 825 826 /*! 827 Set a minimum value for the distances of the scale's endpoints from 828 the widget borders. This is useful to avoid that the scales 829 are "jumping", when the tick labels or their positions change 830 often. 831 832 \param start Minimum for the start border 833 \param end Minimum for the end border 834 \sa getMinBorderDist(), getBorderDistHint() 835 */ 820 836 void QwtScaleWidget::setMinBorderDist( int start, int end ) 821 837 { 822 d_data->minBorderDist[0] = start;823 d_data->minBorderDist[1] = end;824 } 825 826 /*! 827 Get the minimum value for the distances of the scale's endpoints from 828 the widget borders. 829 830 \param start Return parameter for the border width at 838 m_data->minBorderDist[0] = start; 839 m_data->minBorderDist[1] = end; 840 } 841 842 /*! 843 Get the minimum value for the distances of the scale's endpoints from 844 the widget borders. 845 846 \param start Return parameter for the border width at 831 847 the beginning of the scale 832 \param end Return parameter for the border width at the 848 \param end Return parameter for the border width at the 833 849 end of the scale 834 850 835 \sa setMinBorderDist(), getBorderDistHint() 836 */ 837 void QwtScaleWidget::getMinBorderDist( int &start, int&end ) const838 { 839 start = d_data->minBorderDist[0];840 end = d_data->minBorderDist[1];841 } 842 843 /*! 844 \brief Assign a scale division 845 846 The scale division determines where to set the tick marks. 847 848 \param scaleDiv Scale Division 849 \sa For more information about scale divisions, see QwtScaleDiv. 850 */ 851 void QwtScaleWidget::setScaleDiv( const QwtScaleDiv &scaleDiv )852 { 853 QwtScaleDraw *sd = d_data->scaleDraw;851 \sa setMinBorderDist(), getBorderDistHint() 852 */ 853 void QwtScaleWidget::getMinBorderDist( int& start, int& end ) const 854 { 855 start = m_data->minBorderDist[0]; 856 end = m_data->minBorderDist[1]; 857 } 858 859 /*! 860 \brief Assign a scale division 861 862 The scale division determines where to set the tick marks. 863 864 \param scaleDiv Scale Division 865 \sa For more information about scale divisions, see QwtScaleDiv. 866 */ 867 void QwtScaleWidget::setScaleDiv( const QwtScaleDiv& scaleDiv ) 868 { 869 QwtScaleDraw* sd = m_data->scaleDraw; 854 870 if ( sd->scaleDiv() != scaleDiv ) 855 871 { … … 862 878 863 879 /*! 864 Set the transformation 865 866 \param transformation Transformation 867 \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap 868 */ 869 void QwtScaleWidget::setTransformation( QwtTransform *transformation )870 { 871 d_data->scaleDraw->setTransformation( transformation );880 Set the transformation 881 882 \param transformation Transformation 883 \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap 884 */ 885 void QwtScaleWidget::setTransformation( QwtTransform* transformation ) 886 { 887 m_data->scaleDraw->setTransformation( transformation ); 872 888 layoutScale(); 873 889 } 874 890 875 891 /*! 876 En/disable a color bar associated to the scale 877 \sa isColorBarEnabled(), setColorBarWidth() 878 */ 892 En/disable a color bar associated to the scale 893 \sa isColorBarEnabled(), setColorBarWidth() 894 */ 879 895 void QwtScaleWidget::setColorBarEnabled( bool on ) 880 896 { 881 if ( on != d_data->colorBar.isEnabled )882 { 883 d_data->colorBar.isEnabled = on;897 if ( on != m_data->colorBar.isEnabled ) 898 { 899 m_data->colorBar.isEnabled = on; 884 900 layoutScale(); 885 901 } … … 887 903 888 904 /*! 889 \return true, when the color bar is enabled 890 \sa setColorBarEnabled(), setColorBarWidth() 891 */ 905 \return true, when the color bar is enabled 906 \sa setColorBarEnabled(), setColorBarWidth() 907 */ 892 908 bool QwtScaleWidget::isColorBarEnabled() const 893 909 { 894 return d_data->colorBar.isEnabled;895 } 896 897 /*! 898 Set the width of the color bar 899 900 \param width Width 901 \sa colorBarWidth(), setColorBarEnabled() 902 */ 910 return m_data->colorBar.isEnabled; 911 } 912 913 /*! 914 Set the width of the color bar 915 916 \param width Width 917 \sa colorBarWidth(), setColorBarEnabled() 918 */ 903 919 void QwtScaleWidget::setColorBarWidth( int width ) 904 920 { 905 if ( width != d_data->colorBar.width )906 { 907 d_data->colorBar.width = width;921 if ( width != m_data->colorBar.width ) 922 { 923 m_data->colorBar.width = width; 908 924 if ( isColorBarEnabled() ) 909 925 layoutScale(); … … 912 928 913 929 /*! 914 \return Width of the color bar 915 \sa setColorBarEnabled(), setColorBarEnabled() 916 */ 930 \return Width of the color bar 931 \sa setColorBarEnabled(), setColorBarEnabled() 932 */ 917 933 int QwtScaleWidget::colorBarWidth() const 918 934 { 919 return d_data->colorBar.width;920 } 921 922 /*! 923 \return Value interval for the color bar 924 \sa setColorMap(), colorMap() 925 */ 935 return m_data->colorBar.width; 936 } 937 938 /*! 939 \return Value interval for the color bar 940 \sa setColorMap(), colorMap() 941 */ 926 942 QwtInterval QwtScaleWidget::colorBarInterval() const 927 943 { 928 return d_data->colorBar.interval;929 } 930 931 /*! 932 Set the color map and value interval, that are used for displaying 933 the color bar. 934 935 \param interval Value interval 936 \param colorMap Color map 937 938 \sa colorMap(), colorBarInterval() 939 */ 944 return m_data->colorBar.interval; 945 } 946 947 /*! 948 Set the color map and value interval, that are used for displaying 949 the color bar. 950 951 \param interval Value interval 952 \param colorMap Color map 953 954 \sa colorMap(), colorBarInterval() 955 */ 940 956 void QwtScaleWidget::setColorMap( 941 const QwtInterval &interval, QwtColorMap*colorMap )942 { 943 d_data->colorBar.interval = interval;944 945 if ( colorMap != d_data->colorBar.colorMap )946 { 947 delete d_data->colorBar.colorMap;948 d_data->colorBar.colorMap = colorMap;957 const QwtInterval& interval, QwtColorMap* colorMap ) 958 { 959 m_data->colorBar.interval = interval; 960 961 if ( colorMap != m_data->colorBar.colorMap ) 962 { 963 delete m_data->colorBar.colorMap; 964 m_data->colorBar.colorMap = colorMap; 949 965 } 950 966 … … 954 970 955 971 /*! 956 \return Color map 957 \sa setColorMap(), colorBarInterval() 958 */ 959 const QwtColorMap *QwtScaleWidget::colorMap() const 960 { 961 return d_data->colorBar.colorMap; 962 } 972 \return Color map 973 \sa setColorMap(), colorBarInterval() 974 */ 975 const QwtColorMap* QwtScaleWidget::colorMap() const 976 { 977 return m_data->colorBar.colorMap; 978 } 979 980 #include "moc_qwt_scale_widget.cpp" -
trunk/BNC/qwt/qwt_scale_widget.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 14 14 #include "qwt_text.h" 15 15 #include "qwt_scale_draw.h" 16 16 17 #include <qwidget.h> 17 18 #include <qfont.h> … … 25 26 26 27 /*! 27 \brief A Widget which contains a scale 28 \brief A Widget which contains a scale 28 29 29 This Widget can be used to decorate composite widgets with 30 a scale. 31 */ 30 This Widget can be used to decorate composite widgets with 31 a scale. 32 */ 32 33 33 34 class QWT_EXPORT QwtScaleWidget : public QWidget … … 35 36 Q_OBJECT 36 37 37 public: 38 public: 38 39 //! Layout flags of the title 39 40 enum LayoutFlag 40 41 { 41 42 /*! 42 The title of vertical scales is painted from top to bottom. 43 Otherwise it is painted from bottom to top. 43 The title of vertical scales is painted from top to bottom. 44 Otherwise it is painted from bottom to top. 44 45 */ 45 46 TitleInverted = 1 46 47 }; 47 48 48 //! Layout flags of the title 49 typedef QFlags<LayoutFlag> LayoutFlags; 49 Q_DECLARE_FLAGS( LayoutFlags, LayoutFlag ) 50 50 51 explicit QwtScaleWidget( QWidget *parent = NULL );52 explicit QwtScaleWidget( QwtScaleDraw::Alignment, QWidget *parent = NULL );51 explicit QwtScaleWidget( QWidget* parent = NULL ); 52 explicit QwtScaleWidget( QwtScaleDraw::Alignment, QWidget* parent = NULL ); 53 53 virtual ~QwtScaleWidget(); 54 54 55 Q_SIGNALS: 55 Q_SIGNALS: 56 56 //! Signal emitted, whenever the scale division changes 57 57 void scaleDivChanged(); 58 58 59 public: 60 void setTitle( const QString &title );61 void setTitle( const QwtText &title );59 public: 60 void setTitle( const QString& title ); 61 void setTitle( const QwtText& title ); 62 62 QwtText title() const; 63 63 … … 69 69 int endBorderDist() const; 70 70 71 void getBorderDistHint( int &start, int&end ) const;71 void getBorderDistHint( int& start, int& end ) const; 72 72 73 void getMinBorderDist( int &start, int&end ) const;73 void getMinBorderDist( int& start, int& end ) const; 74 74 void setMinBorderDist( int start, int end ); 75 75 … … 80 80 int spacing() const; 81 81 82 void setScaleDiv( const QwtScaleDiv & );83 void setTransformation( QwtTransform * );82 void setScaleDiv( const QwtScaleDiv& ); 83 void setTransformation( QwtTransform* ); 84 84 85 void setScaleDraw( QwtScaleDraw * );86 const QwtScaleDraw *scaleDraw() const;87 QwtScaleDraw *scaleDraw();85 void setScaleDraw( QwtScaleDraw* ); 86 const QwtScaleDraw* scaleDraw() const; 87 QwtScaleDraw* scaleDraw(); 88 88 89 89 void setLabelAlignment( Qt::Alignment ); … … 96 96 int colorBarWidth() const; 97 97 98 void setColorMap( const QwtInterval &, QwtColorMap* );98 void setColorMap( const QwtInterval&, QwtColorMap* ); 99 99 100 100 QwtInterval colorBarInterval() const; 101 const QwtColorMap *colorMap() const;101 const QwtColorMap* colorMap() const; 102 102 103 virtual QSize sizeHint() const; 104 virtual QSize minimumSizeHint() const; 103 virtual QSize sizeHint() const QWT_OVERRIDE; 104 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 105 105 106 106 int titleHeightForWidth( int width ) const; 107 int dimForLength( int length, const QFont &scaleFont ) const;107 int dimForLength( int length, const QFont& scaleFont ) const; 108 108 109 void drawColorBar( QPainter *painter, const QRectF& ) const;110 void drawTitle( QPainter *painter, QwtScaleDraw::Alignment,111 const QRectF &rect ) const;109 void drawColorBar( QPainter*, const QRectF& ) const; 110 void drawTitle( QPainter*, QwtScaleDraw::Alignment, 111 const QRectF& rect ) const; 112 112 113 113 void setAlignment( QwtScaleDraw::Alignment ); … … 116 116 QRectF colorBarRect( const QRectF& ) const; 117 117 118 protected: 119 virtual void paintEvent( QPaintEvent * ); 120 virtual void resizeEvent( QResizeEvent * ); 118 protected: 119 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 120 virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE; 121 virtual void changeEvent( QEvent* ) QWT_OVERRIDE; 121 122 122 void draw( QPainter * ) const;123 void draw( QPainter* ) const; 123 124 124 125 void scaleChange(); 125 126 void layoutScale( bool update_geometry = true ); 126 127 127 private: 128 private: 128 129 void initScale( QwtScaleDraw::Alignment ); 129 130 130 131 class PrivateData; 131 PrivateData *d_data;132 PrivateData* m_data; 132 133 }; 133 134 -
trunk/BNC/qwt/qwt_series_data.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_series_data.h" 11 #include "qwt_ math.h"12 13 static inline QRectF qwtBoundingRect( const QPointF &sample )11 #include "qwt_point_polar.h" 12 13 static inline QRectF qwtBoundingRect( const QPointF& sample ) 14 14 { 15 15 return QRectF( sample.x(), sample.y(), 0.0, 0.0 ); 16 16 } 17 17 18 static inline QRectF qwtBoundingRect( const QwtPoint3D &sample )18 static inline QRectF qwtBoundingRect( const QwtPoint3D& sample ) 19 19 { 20 20 return QRectF( sample.x(), sample.y(), 0.0, 0.0 ); 21 21 } 22 22 23 static inline QRectF qwtBoundingRect( const QwtPointPolar &sample )23 static inline QRectF qwtBoundingRect( const QwtPointPolar& sample ) 24 24 { 25 25 return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 ); 26 26 } 27 27 28 static inline QRectF qwtBoundingRect( const QwtIntervalSample &sample )28 static inline QRectF qwtBoundingRect( const QwtIntervalSample& sample ) 29 29 { 30 30 return QRectF( sample.interval.minValue(), sample.value, … … 32 32 } 33 33 34 static inline QRectF qwtBoundingRect( const QwtSetSample &sample )34 static inline QRectF qwtBoundingRect( const QwtSetSample& sample ) 35 35 { 36 36 if ( sample.set.empty() ) … … 52 52 } 53 53 54 static inline QRectF qwtBoundingRect( const QwtOHLCSample &sample )54 static inline QRectF qwtBoundingRect( const QwtOHLCSample& sample ) 55 55 { 56 56 const QwtInterval interval = sample.boundingInterval(); … … 58 58 } 59 59 60 /*! 61 \brief Calculate the bounding rectangle of a series subset 62 63 Slow implementation, that iterates over the series. 64 65 \param series Series 66 \param from Index of the first sample, <= 0 means from the beginning 67 \param to Index of the last sample, < 0 means to the end 68 69 \return Bounding rectangle 70 */ 71 72 template <class T> 73 QRectF qwtBoundingRectT( 74 const QwtSeriesData<T>& series, int from, int to ) 60 static inline QRectF qwtBoundingRect( const QwtVectorFieldSample& sample ) 61 { 62 /* 63 When displaying a sample as an arrow its length will be 64 proportional to the magnitude - but not the same. 65 As the factor between length and magnitude is not known 66 we can't include vx/vy into the bounding rectangle. 67 */ 68 69 return QRectF( sample.x, sample.y, 0, 0 ); 70 } 71 72 /*! 73 \brief Calculate the bounding rectangle of a series subset 74 75 Slow implementation, that iterates over the series. 76 77 \param series Series 78 \param from Index of the first sample, <= 0 means from the beginning 79 \param to Index of the last sample, < 0 means to the end 80 81 \return Bounding rectangle 82 */ 83 84 template< class T > 85 QRectF qwtBoundingRectT( const QwtSeriesData< T >& series, int from, int to ) 75 86 { 76 87 QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid; … … 113 124 114 125 /*! 115 \brief Calculate the bounding rectangle of a series subset 116 117 Slow implementation, that iterates over the series. 118 119 \param series Series 120 \param from Index of the first sample, <= 0 means from the beginning 121 \param to Index of the last sample, < 0 means to the end 122 123 \return Bounding rectangle 124 */ 125 QRectF qwtBoundingRect( 126 const QwtSeriesData<QPointF> &series, int from, int to ) 127 { 128 return qwtBoundingRectT<QPointF>( series, from, to ); 129 } 130 131 /*! 132 \brief Calculate the bounding rectangle of a series subset 133 134 Slow implementation, that iterates over the series. 135 136 \param series Series 137 \param from Index of the first sample, <= 0 means from the beginning 138 \param to Index of the last sample, < 0 means to the end 139 140 \return Bounding rectangle 141 */ 142 QRectF qwtBoundingRect( 143 const QwtSeriesData<QwtPoint3D> &series, int from, int to ) 144 { 145 return qwtBoundingRectT<QwtPoint3D>( series, from, to ); 146 } 147 148 /*! 149 \brief Calculate the bounding rectangle of a series subset 150 151 The horizontal coordinates represent the azimuth, the 152 vertical coordinates the radius. 153 154 Slow implementation, that iterates over the series. 155 156 \param series Series 157 \param from Index of the first sample, <= 0 means from the beginning 158 \param to Index of the last sample, < 0 means to the end 159 160 \return Bounding rectangle 161 */ 162 QRectF qwtBoundingRect( 163 const QwtSeriesData<QwtPointPolar> &series, int from, int to ) 164 { 165 return qwtBoundingRectT<QwtPointPolar>( series, from, to ); 166 } 167 168 /*! 169 \brief Calculate the bounding rectangle of a series subset 170 171 Slow implementation, that iterates over the series. 172 173 \param series Series 174 \param from Index of the first sample, <= 0 means from the beginning 175 \param to Index of the last sample, < 0 means to the end 176 177 \return Bounding rectangle 178 */ 179 QRectF qwtBoundingRect( 180 const QwtSeriesData<QwtIntervalSample>& series, int from, int to ) 181 { 182 return qwtBoundingRectT<QwtIntervalSample>( series, from, to ); 183 } 184 185 /*! 186 \brief Calculate the bounding rectangle of a series subset 187 188 Slow implementation, that iterates over the series. 189 190 \param series Series 191 \param from Index of the first sample, <= 0 means from the beginning 192 \param to Index of the last sample, < 0 means to the end 193 194 \return Bounding rectangle 195 */ 196 QRectF qwtBoundingRect( 197 const QwtSeriesData<QwtOHLCSample>& series, int from, int to ) 198 { 199 return qwtBoundingRectT<QwtOHLCSample>( series, from, to ); 200 } 201 202 /*! 203 \brief Calculate the bounding rectangle of a series subset 204 205 Slow implementation, that iterates over the series. 206 207 \param series Series 208 \param from Index of the first sample, <= 0 means from the beginning 209 \param to Index of the last sample, < 0 means to the end 210 211 \return Bounding rectangle 212 */ 213 QRectF qwtBoundingRect( 214 const QwtSeriesData<QwtSetSample>& series, int from, int to ) 215 { 216 return qwtBoundingRectT<QwtSetSample>( series, from, to ); 217 } 218 219 /*! 220 Constructor 221 \param samples Samples 222 */ 223 QwtPointSeriesData::QwtPointSeriesData( 224 const QVector<QPointF> &samples ): 225 QwtArraySeriesData<QPointF>( samples ) 226 { 227 } 228 229 /*! 230 \brief Calculate the bounding rectangle 231 232 The bounding rectangle is calculated once by iterating over all 233 points and is stored for all following requests. 234 235 \return Bounding rectangle 236 */ 237 QRectF QwtPointSeriesData::boundingRect() const 238 { 239 if ( d_boundingRect.width() < 0.0 ) 240 d_boundingRect = qwtBoundingRect( *this ); 241 242 return d_boundingRect; 243 } 244 245 /*! 246 Constructor 247 \param samples Samples 248 */ 249 QwtPoint3DSeriesData::QwtPoint3DSeriesData( 250 const QVector<QwtPoint3D> &samples ): 251 QwtArraySeriesData<QwtPoint3D>( samples ) 252 { 253 } 254 255 /*! 256 \brief Calculate the bounding rectangle 257 258 The bounding rectangle is calculated once by iterating over all 259 points and is stored for all following requests. 260 261 \return Bounding rectangle 262 */ 263 QRectF QwtPoint3DSeriesData::boundingRect() const 264 { 265 if ( d_boundingRect.width() < 0.0 ) 266 d_boundingRect = qwtBoundingRect( *this ); 267 268 return d_boundingRect; 269 } 270 271 /*! 272 Constructor 273 \param samples Samples 274 */ 275 QwtIntervalSeriesData::QwtIntervalSeriesData( 276 const QVector<QwtIntervalSample> &samples ): 277 QwtArraySeriesData<QwtIntervalSample>( samples ) 278 { 279 } 280 281 /*! 282 \brief Calculate the bounding rectangle 283 284 The bounding rectangle is calculated once by iterating over all 285 points and is stored for all following requests. 286 287 \return Bounding rectangle 288 */ 289 QRectF QwtIntervalSeriesData::boundingRect() const 290 { 291 if ( d_boundingRect.width() < 0.0 ) 292 d_boundingRect = qwtBoundingRect( *this ); 293 294 return d_boundingRect; 295 } 296 297 /*! 298 Constructor 299 \param samples Samples 300 */ 301 QwtSetSeriesData::QwtSetSeriesData( 302 const QVector<QwtSetSample> &samples ): 303 QwtArraySeriesData<QwtSetSample>( samples ) 304 { 305 } 306 307 /*! 308 \brief Calculate the bounding rectangle 309 310 The bounding rectangle is calculated once by iterating over all 311 points and is stored for all following requests. 312 313 \return Bounding rectangle 314 */ 315 QRectF QwtSetSeriesData::boundingRect() const 316 { 317 if ( d_boundingRect.width() < 0.0 ) 318 d_boundingRect = qwtBoundingRect( *this ); 319 320 return d_boundingRect; 321 } 322 323 /*! 324 Constructor 325 \param samples Samples 326 */ 327 QwtTradingChartData::QwtTradingChartData( 328 const QVector<QwtOHLCSample> &samples ): 329 QwtArraySeriesData<QwtOHLCSample>( samples ) 330 { 331 } 332 333 /*! 334 \brief Calculate the bounding rectangle 335 336 The bounding rectangle is calculated once by iterating over all 337 points and is stored for all following requests. 338 339 \return Bounding rectangle 340 */ 341 QRectF QwtTradingChartData::boundingRect() const 342 { 343 if ( d_boundingRect.width() < 0.0 ) 344 d_boundingRect = qwtBoundingRect( *this ); 345 346 return d_boundingRect; 347 } 126 \brief Calculate the bounding rectangle of a series subset 127 128 Slow implementation, that iterates over the series. 129 130 \param series Series 131 \param from Index of the first sample, <= 0 means from the beginning 132 \param to Index of the last sample, < 0 means to the end 133 134 \return Bounding rectangle 135 */ 136 QRectF qwtBoundingRect( const QwtSeriesData< QPointF >& series, int from, int to ) 137 { 138 return qwtBoundingRectT< QPointF >( series, from, to ); 139 } 140 141 /*! 142 \brief Calculate the bounding rectangle of a series subset 143 144 Slow implementation, that iterates over the series. 145 146 \param series Series 147 \param from Index of the first sample, <= 0 means from the beginning 148 \param to Index of the last sample, < 0 means to the end 149 150 \return Bounding rectangle 151 */ 152 QRectF qwtBoundingRect( 153 const QwtSeriesData< QwtPoint3D >& series, int from, int to ) 154 { 155 return qwtBoundingRectT< QwtPoint3D >( series, from, to ); 156 } 157 158 /*! 159 \brief Calculate the bounding rectangle of a series subset 160 161 The horizontal coordinates represent the azimuth, the 162 vertical coordinates the radius. 163 164 Slow implementation, that iterates over the series. 165 166 \param series Series 167 \param from Index of the first sample, <= 0 means from the beginning 168 \param to Index of the last sample, < 0 means to the end 169 170 \return Bounding rectangle 171 */ 172 QRectF qwtBoundingRect( 173 const QwtSeriesData< QwtPointPolar >& series, int from, int to ) 174 { 175 return qwtBoundingRectT< QwtPointPolar >( series, from, to ); 176 } 177 178 /*! 179 \brief Calculate the bounding rectangle of a series subset 180 181 Slow implementation, that iterates over the series. 182 183 \param series Series 184 \param from Index of the first sample, <= 0 means from the beginning 185 \param to Index of the last sample, < 0 means to the end 186 187 \return Bounding rectangle 188 */ 189 QRectF qwtBoundingRect( 190 const QwtSeriesData< QwtIntervalSample >& series, int from, int to ) 191 { 192 return qwtBoundingRectT< QwtIntervalSample >( series, from, to ); 193 } 194 195 /*! 196 \brief Calculate the bounding rectangle of a series subset 197 198 Slow implementation, that iterates over the series. 199 200 \param series Series 201 \param from Index of the first sample, <= 0 means from the beginning 202 \param to Index of the last sample, < 0 means to the end 203 204 \return Bounding rectangle 205 */ 206 QRectF qwtBoundingRect( 207 const QwtSeriesData< QwtOHLCSample >& series, int from, int to ) 208 { 209 return qwtBoundingRectT< QwtOHLCSample >( series, from, to ); 210 } 211 212 /*! 213 \brief Calculate the bounding rectangle of a series subset 214 215 Slow implementation, that iterates over the series. 216 217 \param series Series 218 \param from Index of the first sample, <= 0 means from the beginning 219 \param to Index of the last sample, < 0 means to the end 220 221 \return Bounding rectangle 222 */ 223 QRectF qwtBoundingRect( 224 const QwtSeriesData< QwtSetSample >& series, int from, int to ) 225 { 226 return qwtBoundingRectT< QwtSetSample >( series, from, to ); 227 } 228 229 /*! 230 \brief Calculate the bounding rectangle of a series subset 231 232 Slow implementation, that iterates over the series. 233 234 \param series Series 235 \param from Index of the first sample, <= 0 means from the beginning 236 \param to Index of the last sample, < 0 means to the end 237 238 \return Bounding rectangle 239 */ 240 QRectF qwtBoundingRect( 241 const QwtSeriesData< QwtVectorFieldSample >& series, int from, int to ) 242 { 243 return qwtBoundingRectT< QwtVectorFieldSample >( series, from, to ); 244 } -
trunk/BNC/qwt/qwt_series_data.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_SERIES_DATA_H 11 #define QWT_SERIES_DATA_H 111 #define QWT_SERIES_DATA_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_samples.h" 15 15 #include "qwt_point_3d.h" 16 #include "qwt_point_polar.h" 16 17 17 #include <qvector.h> 18 18 #include <qrect.h> 19 20 class QwtPointPolar; 19 21 20 22 /*! … … 41 43 but often it is possible to implement a more efficient algorithm 42 44 depending on the characteristics of the series. 43 The member d_boundingRect is intended for caching the calculated rectangle.44 45 */ 46 template <typename T>45 The member cachedBoundingRect is intended for caching the calculated rectangle. 46 47 */ 48 template< typename T > 47 49 class QwtSeriesData 48 50 { 49 public: 51 public: 50 52 //! Constructor 51 53 QwtSeriesData(); … … 60 62 61 63 /*! 62 Return a sample 63 \param i Index 64 \return Sample at position i 64 Return a sample 65 \param i Index 66 \return Sample at position i 65 67 */ 66 68 virtual T sample( size_t i ) const = 0; 67 68 /*!69 Calculate the bounding rect of all samples70 71 The bounding rect is necessary for autoscaling and can be used72 for a couple of painting optimizations.73 74 qwtBoundingRect(...) offers slow implementations iterating75 over the samples. For large sets it is recommended to implement76 something faster f.e. by caching the bounding rectangle.77 78 \return Bounding rectangle79 */80 virtual QRectF boundingRect() const = 0;81 69 82 70 #else … … 84 72 virtual size_t size() const { return 0; } 85 73 virtual T sample( size_t i ) const { return T(); } 86 virtual QRectF boundingRect() const { return d_boundingRect; }87 74 #endif 75 76 /*! 77 Returns the first sample in the list. 78 \warning This function assumes that the list isn't empty. 79 */ 80 inline T firstSample() const { return sample( 0 ); } 81 82 /*! 83 Returns the first sample in the list. 84 \warning This function assumes that the list isn't empty. 85 */ 86 inline T lastSample() const { return sample( size() - 1 ); } 87 88 /*! 89 Calculate the bounding rect of all samples 90 91 The bounding rect is necessary for autoscaling and can be used 92 for a couple of painting optimizations. 93 94 qwtBoundingRect(...) offers slow implementations iterating 95 over the samples. For large sets it is recommended to implement 96 something faster. 97 98 \return Bounding rectangle 99 */ 100 virtual QRectF boundingRect() const 101 { 102 if ( cachedBoundingRect.width() < 0.0 ) 103 cachedBoundingRect = qwtBoundingRect( *this ); 104 105 return cachedBoundingRect; 106 } 88 107 89 108 /*! … … 97 116 98 117 \param rect Rectangle of interest 99 */ 100 virtual void setRectOfInterest( const QRectF &rect );101 102 protected: 118 */ 119 virtual void setRectOfInterest( const QRectF& rect ); 120 121 protected: 103 122 //! Can be used to cache a calculated bounding rectangle 104 mutable QRectF d_boundingRect;105 106 private: 107 QwtSeriesData< T> &operator=( const QwtSeriesData<T>& );123 mutable QRectF cachedBoundingRect; 124 125 private: 126 QwtSeriesData< T >& operator=( const QwtSeriesData< T >& ); 108 127 }; 109 128 110 template <typename T>111 QwtSeriesData< T>::QwtSeriesData():112 d_boundingRect( 0.0, 0.0, -1.0, -1.0 )113 { 114 } 115 116 template <typename T>117 QwtSeriesData< T>::~QwtSeriesData()118 { 119 } 120 121 template <typename T>122 void QwtSeriesData< T>::setRectOfInterest( const QRectF& )129 template< typename T > 130 QwtSeriesData< T >::QwtSeriesData() 131 : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 ) 132 { 133 } 134 135 template< typename T > 136 QwtSeriesData< T >::~QwtSeriesData() 137 { 138 } 139 140 template< typename T > 141 void QwtSeriesData< T >::setRectOfInterest( const QRectF& ) 123 142 { 124 143 } 125 144 126 145 /*! 127 \brief Template class for data, that is organized as QVector 128 129 QVector uses implicit data sharing and can be 130 passed around as argument efficiently. 131 */ 132 template <typename T>133 class QwtArraySeriesData: public QwtSeriesData< T>134 { 135 public: 146 \brief Template class for data, that is organized as QVector 147 148 QVector uses implicit data sharing and can be 149 passed around as argument efficiently. 150 */ 151 template< typename T > 152 class QwtArraySeriesData : public QwtSeriesData< T > 153 { 154 public: 136 155 //! Constructor 137 156 QwtArraySeriesData(); … … 140 159 Constructor 141 160 \param samples Array of samples 142 */ 143 QwtArraySeriesData( const QVector< T> &samples );144 145 /*! 146 Assign an array of samples 147 \param samples Array of samples 148 */ 149 void setSamples( const QVector< T> &samples );161 */ 162 explicit QwtArraySeriesData( const QVector< T >& samples ); 163 164 /*! 165 Assign an array of samples 166 \param samples Array of samples 167 */ 168 void setSamples( const QVector< T >& samples ); 150 169 151 170 //! \return Array of samples 152 const QVector< T> samples() const;171 const QVector< T > samples() const; 153 172 154 173 //! \return Number of samples 155 virtual size_t size() const; 156 157 /*! 158 \return Sample at a specific position 159 160 \param index Index 161 \return Sample at position index 162 */ 163 virtual T sample( size_t index ) const; 164 165 protected: 174 virtual size_t size() const QWT_OVERRIDE; 175 176 /*! 177 \return Sample at a specific position 178 179 \param index Index 180 \return Sample at position index 181 */ 182 virtual T sample( size_t index ) const QWT_OVERRIDE; 183 184 protected: 166 185 //! Vector of samples 167 QVector< T> d_samples;186 QVector< T > m_samples; 168 187 }; 169 188 170 template <typename T>171 QwtArraySeriesData< T>::QwtArraySeriesData()172 { 173 } 174 175 template <typename T>176 QwtArraySeriesData< T>::QwtArraySeriesData( const QVector<T> &samples ):177 d_samples( samples )178 { 179 } 180 181 template <typename T>182 void QwtArraySeriesData< T>::setSamples( const QVector<T> &samples )183 { 184 QwtSeriesData< T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );185 d_samples = samples;186 } 187 188 template <typename T>189 const QVector< T> QwtArraySeriesData<T>::samples() const190 { 191 return d_samples;192 } 193 194 template <typename T>195 size_t QwtArraySeriesData< T>::size() const196 { 197 return d_samples.size();198 } 199 200 template <typename T>201 T QwtArraySeriesData< T>::sample( size_t i ) const202 { 203 return d_samples[ static_cast<int>( i ) ];189 template< typename T > 190 QwtArraySeriesData< T >::QwtArraySeriesData() 191 { 192 } 193 194 template< typename T > 195 QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples ) 196 : m_samples( samples ) 197 { 198 } 199 200 template< typename T > 201 void QwtArraySeriesData< T >::setSamples( const QVector< T >& samples ) 202 { 203 QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 ); 204 m_samples = samples; 205 } 206 207 template< typename T > 208 const QVector< T > QwtArraySeriesData< T >::samples() const 209 { 210 return m_samples; 211 } 212 213 template< typename T > 214 size_t QwtArraySeriesData< T >::size() const 215 { 216 return m_samples.size(); 217 } 218 219 template< typename T > 220 T QwtArraySeriesData< T >::sample( size_t i ) const 221 { 222 return m_samples[ static_cast< int >( i ) ]; 204 223 } 205 224 206 225 //! Interface for iterating over an array of points 207 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF> 208 { 209 public: 210 QwtPointSeriesData( 211 const QVector<QPointF> & = QVector<QPointF>() ); 212 213 virtual QRectF boundingRect() const; 214 }; 226 typedef QwtArraySeriesData< QPointF > QwtPointSeriesData; 215 227 216 228 //! Interface for iterating over an array of 3D points 217 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D> 218 { 219 public: 220 QwtPoint3DSeriesData( 221 const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() ); 222 virtual QRectF boundingRect() const; 223 }; 229 typedef QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData; 224 230 225 231 //! Interface for iterating over an array of intervals 226 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample> 227 { 228 public: 229 QwtIntervalSeriesData( 230 const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() ); 231 232 virtual QRectF boundingRect() const; 233 }; 232 typedef QwtArraySeriesData< QwtIntervalSample > QwtIntervalSeriesData; 234 233 235 234 //! Interface for iterating over an array of samples 236 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample> 237 { 238 public: 239 QwtSetSeriesData( 240 const QVector<QwtSetSample> & = QVector<QwtSetSample>() ); 241 242 virtual QRectF boundingRect() const; 243 }; 244 245 /*! 246 Interface for iterating over an array of OHLC samples 247 */ 248 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample> 249 { 250 public: 251 QwtTradingChartData( 252 const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() ); 253 254 virtual QRectF boundingRect() const; 255 }; 256 257 QWT_EXPORT QRectF qwtBoundingRect( 258 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 ); 259 260 QWT_EXPORT QRectF qwtBoundingRect( 261 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 ); 262 263 QWT_EXPORT QRectF qwtBoundingRect( 264 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 ); 265 266 QWT_EXPORT QRectF qwtBoundingRect( 267 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 ); 268 269 QWT_EXPORT QRectF qwtBoundingRect( 270 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 ); 271 272 QWT_EXPORT QRectF qwtBoundingRect( 273 const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 ); 235 typedef QwtArraySeriesData< QwtSetSample > QwtSetSeriesData; 236 237 //! Interface for iterating over an array of vector field samples 238 typedef QwtArraySeriesData< QwtVectorFieldSample > QwtVectorFieldData; 239 240 //! Interface for iterating over an array of OHLC samples 241 typedef QwtArraySeriesData< QwtOHLCSample > QwtTradingChartData; 242 243 QWT_EXPORT QRectF qwtBoundingRect( 244 const QwtSeriesData< QPointF >&, int from = 0, int to = -1 ); 245 246 QWT_EXPORT QRectF qwtBoundingRect( 247 const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 ); 248 249 QWT_EXPORT QRectF qwtBoundingRect( 250 const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 ); 251 252 QWT_EXPORT QRectF qwtBoundingRect( 253 const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 ); 254 255 QWT_EXPORT QRectF qwtBoundingRect( 256 const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 ); 257 258 QWT_EXPORT QRectF qwtBoundingRect( 259 const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 ); 260 261 QWT_EXPORT QRectF qwtBoundingRect( 262 const QwtSeriesData< QwtVectorFieldSample >&, int from = 0, int to = -1 ); 274 263 275 264 /*! … … 281 270 value the return value will be -1. 282 271 283 \par Example 272 \par Example 284 273 The following example shows finds a point of curve from an x 285 274 coordinate 286 275 \code 287 #include <qwt_series_data.h>288 #include <qwt_plot_curve.h>276 #include <qwt_series_data.h> 277 #include <qwt_plot_curve.h> 289 278 290 279 struct compareX … … 299 288 { 300 289 int index = qwtUpperSampleIndex<QPointF>( 301 *curve->data(), x, compareX() );290 * curve->data(), x, compareX() ); 302 291 303 292 if ( index == -1 && … … 319 308 320 309 \endcode 321 \endpar 322 323 \param series Series of samples 324 \param value Value 325 \param lessThan Compare operation 326 327 \note The samples must be sorted according to the order specified 310 \endpar 311 312 \param series Series of samples 313 \param value Value 314 \param lessThan Compare operation 315 316 \note The samples must be sorted according to the order specified 328 317 by the lessThan object 329 318 */ 330 template <typename T, typename LessThan>331 inline int qwtUpperSampleIndex( const QwtSeriesData< T> &series,319 template< typename T, typename LessThan > 320 inline int qwtUpperSampleIndex( const QwtSeriesData< T >& series, 332 321 double value, LessThan lessThan ) 333 322 { 334 323 const int indexMax = series.size() - 1; 335 324 336 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )325 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) ) 337 326 return -1; 338 327 -
trunk/BNC/qwt/qwt_series_store.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 16 16 /*! 17 \brief Bridge between QwtSeriesStore and QwtPlotSeriesItem 18 19 QwtAbstractSeriesStore is an abstract interface only 20 to make it possible to isolate the template based methods ( QwtSeriesStore ) 21 from the regular methods ( QwtPlotSeriesItem ) to make it possible 22 to derive from QwtPlotSeriesItem without any hassle with templates. 23 */ 17 \brief Bridge between QwtSeriesStore and QwtPlotSeriesItem 18 19 QwtAbstractSeriesStore is an abstract interface only 20 to make it possible to isolate the template based methods ( QwtSeriesStore ) 21 from the regular methods ( QwtPlotSeriesItem ) to make it possible 22 to derive from QwtPlotSeriesItem without any hassle with templates. 23 */ 24 24 class QwtAbstractSeriesStore 25 25 { 26 protected:26 public: 27 27 //! Destructor 28 28 virtual ~QwtAbstractSeriesStore() {} 29 29 30 protected: 30 31 #ifndef QWT_PYTHON_WRAPPER 31 32 //! dataChanged() indicates, that the series has been changed. … … 33 34 34 35 /*! 35 Set a the "rectangle of interest" for the stored series 36 \sa QwtSeriesData<T>::setRectOfInterest() 37 */ 38 virtual void setRectOfInterest( const QRectF & ) = 0;36 Set a the "rectangle of interest" for the stored series 37 \sa QwtSeriesData<T>::setRectOfInterest() 38 */ 39 virtual void setRectOfInterest( const QRectF& ) = 0; 39 40 40 41 //! \return Bounding rectangle of the stored series … … 46 47 // Needed for generating the python bindings, but not for using them ! 47 48 virtual void dataChanged() {} 48 virtual void setRectOfInterest( const QRectF & ) {}49 virtual QRectF dataRect() const { return QRectF( 0.0, 0.0, -1.0, -1.0 ); }49 virtual void setRectOfInterest( const QRectF& ) {} 50 virtual QRectF dataRect() const { return QRectF( 0.0, 0.0, -1.0, -1.0 ); } 50 51 virtual size_t dataSize() const { return 0; } 51 52 #endif … … 53 54 54 55 /*! 55 \brief Class storing a QwtSeriesData object 56 57 QwtSeriesStore and QwtPlotSeriesItem are intended as base classes for all 58 plot items iterating over a series of samples. Both classes share 59 a virtual base class ( QwtAbstractSeriesStore ) to bridge between them. 60 61 QwtSeriesStore offers the template based part for the plot item API, so 62 that QwtPlotSeriesItem can be derived without any hassle with templates. 56 \brief Class storing a QwtSeriesData object 57 58 QwtSeriesStore and QwtPlotSeriesItem are intended as base classes for all 59 plot items iterating over a series of samples. Both classes share 60 a virtual base class ( QwtAbstractSeriesStore ) to bridge between them. 61 62 QwtSeriesStore offers the template based part for the plot item API, so 63 that QwtPlotSeriesItem can be derived without any hassle with templates. 63 64 */ 64 template <typename T>65 class QwtSeriesStore: public virtual QwtAbstractSeriesStore 66 { 67 public: 68 /*! 69 \brief Constructor 70 The store contains no series 71 */ 72 explicit QwtSeriesStore <T>();65 template< typename T > 66 class QwtSeriesStore : public virtual QwtAbstractSeriesStore 67 { 68 public: 69 /*! 70 \brief Constructor 71 The store contains no series 72 */ 73 explicit QwtSeriesStore(); 73 74 74 75 //! Destructor 75 ~QwtSeriesStore <T>();76 77 /*! 78 Assign a series of samples 79 80 \param series Data 81 \warning The item takes ownership of the data object, deleting 76 ~QwtSeriesStore(); 77 78 /*! 79 Assign a series of samples 80 81 \param series Data 82 \warning The item takes ownership of the data object, deleting 82 83 it when its not used anymore. 83 */ 84 void setData( QwtSeriesData< T> *series );84 */ 85 void setData( QwtSeriesData< T >* series ); 85 86 86 87 //! \return the the series data 87 QwtSeriesData< T> *data();88 QwtSeriesData< T >* data(); 88 89 89 90 //! \return the the series data 90 const QwtSeriesData< T> *data() const;91 const QwtSeriesData< T >* data() const; 91 92 92 93 /*! 93 94 \param index Index 94 95 \return Sample at position index 95 */ 96 */ 96 97 T sample( int index ) const; 97 98 98 99 /*! 99 \return Number of samples of the series 100 \sa setData(), QwtSeriesData<T>::size() 101 */ 102 virtual size_t dataSize() const; 103 104 /*! 105 \return Bounding rectangle of the series 100 \return Number of samples of the series 101 \sa setData(), QwtSeriesData<T>::size() 102 */ 103 virtual size_t dataSize() const QWT_OVERRIDE; 104 105 /*! 106 \return Bounding rectangle of the series 106 107 or an invalid rectangle, when no series is stored 107 108 108 \sa QwtSeriesData<T>::boundingRect() 109 */ 110 virtual QRectF dataRect() const; 111 112 /*! 113 Set a the "rect of interest" for the series 114 115 \param rect Rectangle of interest 116 \sa QwtSeriesData<T>::setRectOfInterest() 117 */ 118 virtual void setRectOfInterest( const QRectF &rect );119 120 /*! 121 Replace a series without deleting the previous one 122 123 \param series New series 124 \return Previously assigned series 125 */ 126 QwtSeriesData< T> *swapData( QwtSeriesData<T> *series );127 128 private: 129 QwtSeriesData< T> *d_series;109 \sa QwtSeriesData<T>::boundingRect() 110 */ 111 virtual QRectF dataRect() const QWT_OVERRIDE; 112 113 /*! 114 Set a the "rect of interest" for the series 115 116 \param rect Rectangle of interest 117 \sa QwtSeriesData<T>::setRectOfInterest() 118 */ 119 virtual void setRectOfInterest( const QRectF& rect ) QWT_OVERRIDE; 120 121 /*! 122 Replace a series without deleting the previous one 123 124 \param series New series 125 \return Previously assigned series 126 */ 127 QwtSeriesData< T >* swapData( QwtSeriesData< T >* series ); 128 129 private: 130 QwtSeriesData< T >* m_series; 130 131 }; 131 132 132 template <typename T>133 QwtSeriesStore< T>::QwtSeriesStore():134 d_series( NULL )135 { 136 } 137 138 template <typename T>139 QwtSeriesStore< T>::~QwtSeriesStore()140 { 141 delete d_series;142 } 143 144 template <typename T>145 inline QwtSeriesData< T> *QwtSeriesStore<T>::data()146 { 147 return d_series;148 } 149 150 template <typename T>151 inline const QwtSeriesData< T> *QwtSeriesStore<T>::data() const152 { 153 return d_series;154 } 155 156 template <typename T>157 inline T QwtSeriesStore< T>::sample( int index ) const158 { 159 return d_series ?d_series->sample( index ) : T();160 } 161 162 template <typename T>163 void QwtSeriesStore< T>::setData( QwtSeriesData<T> *series )164 { 165 if ( d_series != series )133 template< typename T > 134 QwtSeriesStore< T >::QwtSeriesStore() 135 : m_series( NULL ) 136 { 137 } 138 139 template< typename T > 140 QwtSeriesStore< T >::~QwtSeriesStore() 141 { 142 delete m_series; 143 } 144 145 template< typename T > 146 inline QwtSeriesData< T >* QwtSeriesStore< T >::data() 147 { 148 return m_series; 149 } 150 151 template< typename T > 152 inline const QwtSeriesData< T >* QwtSeriesStore< T >::data() const 153 { 154 return m_series; 155 } 156 157 template< typename T > 158 inline T QwtSeriesStore< T >::sample( int index ) const 159 { 160 return m_series ? m_series->sample( index ) : T(); 161 } 162 163 template< typename T > 164 void QwtSeriesStore< T >::setData( QwtSeriesData< T >* series ) 165 { 166 if ( m_series != series ) 166 167 { 167 delete d_series;168 d_series = series;168 delete m_series; 169 m_series = series; 169 170 dataChanged(); 170 171 } 171 172 } 172 173 173 template <typename T>174 size_t QwtSeriesStore< T>::dataSize() const175 { 176 if ( d_series == NULL )174 template< typename T > 175 size_t QwtSeriesStore< T >::dataSize() const 176 { 177 if ( m_series == NULL ) 177 178 return 0; 178 179 179 return d_series->size();180 } 181 182 template <typename T>183 QRectF QwtSeriesStore< T>::dataRect() const184 { 185 if ( d_series == NULL )180 return m_series->size(); 181 } 182 183 template< typename T > 184 QRectF QwtSeriesStore< T >::dataRect() const 185 { 186 if ( m_series == NULL ) 186 187 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid 187 188 188 return d_series->boundingRect();189 } 190 191 template <typename T>192 void QwtSeriesStore< T>::setRectOfInterest( const QRectF&rect )193 { 194 if ( d_series )195 d_series->setRectOfInterest( rect );196 } 197 198 template <typename T>199 QwtSeriesData< T>* QwtSeriesStore<T>::swapData( QwtSeriesData<T> *series )200 { 201 QwtSeriesData< T>* swappedSeries =d_series;202 d_series = series;189 return m_series->boundingRect(); 190 } 191 192 template< typename T > 193 void QwtSeriesStore< T >::setRectOfInterest( const QRectF& rect ) 194 { 195 if ( m_series ) 196 m_series->setRectOfInterest( rect ); 197 } 198 199 template< typename T > 200 QwtSeriesData< T >* QwtSeriesStore< T >::swapData( QwtSeriesData< T >* series ) 201 { 202 QwtSeriesData< T >* swappedSeries = m_series; 203 m_series = series; 203 204 204 205 return swappedSeries; -
trunk/BNC/qwt/qwt_slider.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_scale_draw.h" 13 13 #include "qwt_scale_map.h" 14 #include "qwt_math.h" 15 #include "qwt.h" 16 14 17 #include <qevent.h> 15 18 #include <qdrawutil.h> 16 19 #include <qpainter.h> 17 #include <qalgorithms.h>18 #include <qmath.h>19 20 #include <qstyle.h> 20 21 #include <qstyleoption.h> 21 #include <q application.h>22 23 static QSize qwtHandleSize( const QSize &size,22 #include <qmargins.h> 23 24 static QSize qwtHandleSize( const QSize& size, 24 25 Qt::Orientation orientation, bool hasTrough ) 25 26 { … … 69 70 class QwtSlider::PrivateData 70 71 { 71 public: 72 PrivateData() :73 repeatTimerId( 0 ) ,74 updateInterval( 150 ) ,75 stepsIncrement( 0 ) ,76 pendingValueChange( false ) ,77 borderWidth( 2 ) ,78 spacing( 4 ) ,79 scalePosition( QwtSlider::TrailingScale ) ,80 hasTrough( true ) ,81 hasGroove( false ) ,82 mouseOffset( 0 ) 72 public: 73 PrivateData() 74 : repeatTimerId( 0 ) 75 , updateInterval( 150 ) 76 , stepsIncrement( 0 ) 77 , pendingValueChange( false ) 78 , borderWidth( 2 ) 79 , spacing( 4 ) 80 , scalePosition( QwtSlider::TrailingScale ) 81 , hasTrough( true ) 82 , hasGroove( false ) 83 , mouseOffset( 0 ) 83 84 { 84 85 } … … 107 108 }; 108 109 /*! 109 Construct vertical slider in QwtSlider::Trough style 110 with a scale to the left. 111 112 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 113 114 \param parent Parent widget 115 116 \sa setOrientation(), setScalePosition(), setBackgroundStyle() 117 */ 118 QwtSlider::QwtSlider( QWidget *parent ):119 QwtAbstractSlider( parent ) 110 Construct vertical slider in QwtSlider::Trough style 111 with a scale to the left. 112 113 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 114 115 \param parent Parent widget 116 117 \sa setOrientation(), setScalePosition(), setBackgroundStyle() 118 */ 119 QwtSlider::QwtSlider( QWidget* parent ) 120 : QwtAbstractSlider( parent ) 120 121 { 121 122 initSlider( Qt::Vertical ); … … 123 124 124 125 /*! 125 Construct a slider in QwtSlider::Trough style 126 127 When orientation is Qt::Vertical the scale will be aligned to 128 the left - otherwise at the the top of the slider. 129 130 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 131 132 \param parent Parent widget 133 \param orientation Orientation of the slider. 134 */ 135 QwtSlider::QwtSlider( Qt::Orientation orientation, QWidget *parent ):136 QwtAbstractSlider( parent ) 126 Construct a slider in QwtSlider::Trough style 127 128 When orientation is Qt::Vertical the scale will be aligned to 129 the left - otherwise at the the top of the slider. 130 131 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 132 133 \param parent Parent widget 134 \param orientation Orientation of the slider. 135 */ 136 QwtSlider::QwtSlider( Qt::Orientation orientation, QWidget* parent ) 137 : QwtAbstractSlider( parent ) 137 138 { 138 139 initSlider( orientation ); … … 142 143 QwtSlider::~QwtSlider() 143 144 { 144 delete d_data;145 delete m_data; 145 146 } 146 147 … … 154 155 setAttribute( Qt::WA_WState_OwnSizePolicy, false ); 155 156 156 d_data = new QwtSlider::PrivateData;157 158 d_data->orientation = orientation;157 m_data = new QwtSlider::PrivateData; 158 159 m_data->orientation = orientation; 159 160 160 161 scaleDraw()->setAlignment( 161 qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );162 qwtScaleDrawAlignment( orientation, m_data->scalePosition ) ); 162 163 scaleDraw()->setLength( 100 ); 163 164 … … 167 168 168 169 /*! 169 \brief Set the orientation. 170 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 171 172 \sa orientation(), scalePosition() 173 */ 170 \brief Set the orientation. 171 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 172 173 \sa orientation(), scalePosition() 174 */ 174 175 void QwtSlider::setOrientation( Qt::Orientation orientation ) 175 176 { 176 if ( orientation == d_data->orientation )177 if ( orientation == m_data->orientation ) 177 178 return; 178 179 179 d_data->orientation = orientation;180 m_data->orientation = orientation; 180 181 181 182 scaleDraw()->setAlignment( 182 qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );183 qwtScaleDrawAlignment( orientation, m_data->scalePosition ) ); 183 184 184 185 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) … … 196 197 197 198 /*! 198 \return Orientation 199 \sa setOrientation() 200 */ 199 \return Orientation 200 \sa setOrientation() 201 */ 201 202 Qt::Orientation QwtSlider::orientation() const 202 203 { 203 return d_data->orientation;204 } 205 206 /*! 207 \brief Change the position of the scale 208 \param scalePosition Position of the scale. 209 210 \sa ScalePosition, scalePosition() 211 */ 204 return m_data->orientation; 205 } 206 207 /*! 208 \brief Change the position of the scale 209 \param scalePosition Position of the scale. 210 211 \sa ScalePosition, scalePosition() 212 */ 212 213 void QwtSlider::setScalePosition( ScalePosition scalePosition ) 213 214 { 214 if ( d_data->scalePosition == scalePosition )215 if ( m_data->scalePosition == scalePosition ) 215 216 return; 216 217 217 d_data->scalePosition = scalePosition;218 m_data->scalePosition = scalePosition; 218 219 scaleDraw()->setAlignment( 219 qwtScaleDrawAlignment( d_data->orientation, scalePosition ) );220 qwtScaleDrawAlignment( m_data->orientation, scalePosition ) ); 220 221 221 222 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 224 225 225 226 /*! 226 \return Position of the scale 227 \sa setScalePosition() 227 \return Position of the scale 228 \sa setScalePosition() 228 229 */ 229 230 QwtSlider::ScalePosition QwtSlider::scalePosition() const 230 231 { 231 return d_data->scalePosition;232 } 233 234 /*! 235 \brief Change the slider's border width 236 237 The border width is used for drawing the slider handle and the 238 trough. 239 240 \param width Border width 241 \sa borderWidth() 242 */ 232 return m_data->scalePosition; 233 } 234 235 /*! 236 \brief Change the slider's border width 237 238 The border width is used for drawing the slider handle and the 239 trough. 240 241 \param width Border width 242 \sa borderWidth() 243 */ 243 244 void QwtSlider::setBorderWidth( int width ) 244 245 { … … 246 247 width = 0; 247 248 248 if ( width != d_data->borderWidth )249 { 250 d_data->borderWidth = width;249 if ( width != m_data->borderWidth ) 250 { 251 m_data->borderWidth = width; 251 252 252 253 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 256 257 257 258 /*! 258 \return the border width. 259 \sa setBorderWidth() 260 */ 259 \return the border width. 260 \sa setBorderWidth() 261 */ 261 262 int QwtSlider::borderWidth() const 262 263 { 263 return d_data->borderWidth;264 } 265 266 /*! 267 \brief Change the spacing between trough and scale 268 269 A spacing of 0 means, that the backbone of the scale is covered 270 by the trough. 271 272 The default setting is 4 pixels. 273 274 \param spacing Number of pixels 275 \sa spacing(); 276 */ 264 return m_data->borderWidth; 265 } 266 267 /*! 268 \brief Change the spacing between trough and scale 269 270 A spacing of 0 means, that the backbone of the scale is covered 271 by the trough. 272 273 The default setting is 4 pixels. 274 275 \param spacing Number of pixels 276 \sa spacing(); 277 */ 277 278 void QwtSlider::setSpacing( int spacing ) 278 279 { … … 280 281 spacing = 0; 281 282 282 if ( spacing != d_data->spacing )283 { 284 d_data->spacing = spacing;283 if ( spacing != m_data->spacing ) 284 { 285 m_data->spacing = spacing; 285 286 286 287 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 290 291 291 292 /*! 292 \return Number of pixels between slider and scale 293 \sa setSpacing() 294 */ 293 \return Number of pixels between slider and scale 294 \sa setSpacing() 295 */ 295 296 int QwtSlider::spacing() const 296 297 { 297 return d_data->spacing;298 } 299 300 /*! 301 \brief Set the slider's handle size 302 303 When the size is empty the slider handle will be painted with a 304 default size depending on its orientation() and backgroundStyle(). 305 306 \param size New size 307 308 \sa handleSize() 309 */ 310 void QwtSlider::setHandleSize( const QSize &size )311 { 312 if ( size != d_data->handleSize )313 { 314 d_data->handleSize = size;298 return m_data->spacing; 299 } 300 301 /*! 302 \brief Set the slider's handle size 303 304 When the size is empty the slider handle will be painted with a 305 default size depending on its orientation() and backgroundStyle(). 306 307 \param size New size 308 309 \sa handleSize() 310 */ 311 void QwtSlider::setHandleSize( const QSize& size ) 312 { 313 if ( size != m_data->handleSize ) 314 { 315 m_data->handleSize = size; 315 316 316 317 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 320 321 321 322 /*! 322 \return Size of the handle. 323 \sa setHandleSize() 324 */ 323 \return Size of the handle. 324 \sa setHandleSize() 325 */ 325 326 QSize QwtSlider::handleSize() const 326 327 { 327 return d_data->handleSize;328 } 329 330 /*! 331 \brief Set a scale draw 332 333 For changing the labels of the scales, it 334 is necessary to derive from QwtScaleDraw and 335 overload QwtScaleDraw::label(). 336 337 \param scaleDraw ScaleDraw object, that has to be created with 328 return m_data->handleSize; 329 } 330 331 /*! 332 \brief Set a scale draw 333 334 For changing the labels of the scales, it 335 is necessary to derive from QwtScaleDraw and 336 overload QwtScaleDraw::label(). 337 338 \param scaleDraw ScaleDraw object, that has to be created with 338 339 new and will be deleted in ~QwtSlider() or the next 339 340 call of setScaleDraw(). 340 341 341 \sa scaleDraw() 342 */ 343 void QwtSlider::setScaleDraw( QwtScaleDraw *scaleDraw )344 { 345 const QwtScaleDraw *previousScaleDraw = this->scaleDraw();342 \sa scaleDraw() 343 */ 344 void QwtSlider::setScaleDraw( QwtScaleDraw* scaleDraw ) 345 { 346 const QwtScaleDraw* previousScaleDraw = this->scaleDraw(); 346 347 if ( scaleDraw == NULL || scaleDraw == previousScaleDraw ) 347 348 return; … … 357 358 358 359 /*! 359 \return the scale draw of the slider 360 \sa setScaleDraw() 361 */ 362 const QwtScaleDraw *QwtSlider::scaleDraw() const363 { 364 return static_cast<const QwtScaleDraw *>( abstractScaleDraw() );365 } 366 367 /*! 368 \return the scale draw of the slider 369 \sa setScaleDraw() 370 */ 371 QwtScaleDraw *QwtSlider::scaleDraw()372 { 373 return static_cast<QwtScaleDraw *>( abstractScaleDraw() );360 \return the scale draw of the slider 361 \sa setScaleDraw() 362 */ 363 const QwtScaleDraw* QwtSlider::scaleDraw() const 364 { 365 return static_cast< const QwtScaleDraw* >( abstractScaleDraw() ); 366 } 367 368 /*! 369 \return the scale draw of the slider 370 \sa setScaleDraw() 371 */ 372 QwtScaleDraw* QwtSlider::scaleDraw() 373 { 374 return static_cast< QwtScaleDraw* >( abstractScaleDraw() ); 374 375 } 375 376 … … 384 385 385 386 /*! 386 \brief Specify the update interval for automatic scrolling 387 388 The minimal accepted value is 50 ms. 389 390 \param interval Update interval in milliseconds 391 392 \sa setUpdateInterval() 393 */ 387 \brief Specify the update interval for automatic scrolling 388 389 The minimal accepted value is 50 ms. 390 391 \param interval Update interval in milliseconds 392 393 \sa setUpdateInterval() 394 */ 394 395 void QwtSlider::setUpdateInterval( int interval ) 395 396 { 396 d_data->updateInterval = qMax( interval, 50 );397 } 398 399 /*! 400 \return Update interval in milliseconds for automatic scrolling 401 \sa setUpdateInterval() 397 m_data->updateInterval = qMax( interval, 50 ); 398 } 399 400 /*! 401 \return Update interval in milliseconds for automatic scrolling 402 \sa setUpdateInterval() 402 403 */ 403 404 int QwtSlider::updateInterval() const 404 405 { 405 return d_data->updateInterval;406 return m_data->updateInterval; 406 407 } 407 408 … … 411 412 \param painter Painter 412 413 \param sliderRect Bounding rectangle of the slider 413 */ 414 */ 414 415 void QwtSlider::drawSlider( 415 QPainter *painter, const QRect&sliderRect ) const416 QPainter* painter, const QRect& sliderRect ) const 416 417 { 417 418 QRect innerRect( sliderRect ); 418 419 419 if ( d_data->hasTrough )420 { 421 const int bw = d_data->borderWidth;420 if ( m_data->hasTrough ) 421 { 422 const int bw = m_data->borderWidth; 422 423 innerRect = sliderRect.adjusted( bw, bw, -bw, -bw ); 423 424 … … 426 427 } 427 428 428 const QSize handleSize = qwtHandleSize( d_data->handleSize,429 d_data->orientation, d_data->hasTrough );430 431 if ( d_data->hasGroove )432 { 429 if ( m_data->hasGroove ) 430 { 431 const QSize handleSize = qwtHandleSize( m_data->handleSize, 432 m_data->orientation, m_data->hasTrough ); 433 433 434 const int slotExtent = 4; 434 435 const int slotMargin = 4; … … 456 457 457 458 QBrush brush = palette().brush( QPalette::Dark ); 458 qDrawShadePanel( painter, slotRect, palette(), true, 1 , &brush );459 qDrawShadePanel( painter, slotRect, palette(), true, 1, &brush ); 459 460 } 460 461 … … 464 465 465 466 /*! 466 Draw the thumb at a position 467 468 \param painter Painter 469 \param handleRect Bounding rectangle of the handle 470 \param pos Position of the handle marker in widget coordinates 471 */ 472 void QwtSlider::drawHandle( QPainter *painter,473 const QRect &handleRect, int pos ) const474 { 475 const int bw = d_data->borderWidth;467 Draw the thumb at a position 468 469 \param painter Painter 470 \param handleRect Bounding rectangle of the handle 471 \param pos Position of the handle marker in widget coordinates 472 */ 473 void QwtSlider::drawHandle( QPainter* painter, 474 const QRect& handleRect, int pos ) const 475 { 476 const int bw = m_data->borderWidth; 476 477 477 478 qDrawShadePanel( painter, … … 493 494 494 495 /*! 495 \brief Determine what to do when the user presses a mouse button. 496 497 \param pos Mouse position 498 499 \retval True, when handleRect() contains pos 500 \sa scrolledTo() 501 */ 502 bool QwtSlider::isScrollPosition( const QPoint &pos ) const496 \brief Determine what to do when the user presses a mouse button. 497 498 \param pos Mouse position 499 500 \retval True, when handleRect() contains pos 501 \sa scrolledTo() 502 */ 503 bool QwtSlider::isScrollPosition( const QPoint& pos ) const 503 504 { 504 505 if ( handleRect().contains( pos ) ) … … 507 508 ? pos.x() : pos.y(); 508 509 509 d_data->mouseOffset = v - transform( value() );510 m_data->mouseOffset = v - transform( value() ); 510 511 return true; 511 512 } … … 515 516 516 517 /*! 517 \brief Determine the value for a new position of the 518 \brief Determine the value for a new position of the 518 519 slider handle. 519 520 520 \param pos Mouse position 521 522 \return Value for the mouse position 523 \sa isScrollPosition() 524 */ 525 double QwtSlider::scrolledTo( const QPoint &pos ) const521 \param pos Mouse position 522 523 \return Value for the mouse position 524 \sa isScrollPosition() 525 */ 526 double QwtSlider::scrolledTo( const QPoint& pos ) const 526 527 { 527 528 int p = ( orientation() == Qt::Horizontal ) 528 529 ? pos.x() : pos.y(); 529 530 530 p -= d_data->mouseOffset;531 p -= m_data->mouseOffset; 531 532 532 533 int min = transform( lowerBound() ); … … 543 544 Mouse press event handler 544 545 \param event Mouse event 545 */ 546 void QwtSlider::mousePressEvent( QMouseEvent *event )546 */ 547 void QwtSlider::mousePressEvent( QMouseEvent* event ) 547 548 { 548 549 if ( isReadOnly() ) … … 554 555 const QPoint pos = event->pos(); 555 556 556 if ( isValid() && d_data->sliderRect.contains( pos ) )557 if ( isValid() && m_data->sliderRect.contains( pos ) ) 557 558 { 558 559 if ( !handleRect().contains( pos ) ) … … 560 561 const int markerPos = transform( value() ); 561 562 562 d_data->stepsIncrement = pageSteps();563 564 if ( d_data->orientation == Qt::Horizontal )563 m_data->stepsIncrement = pageSteps(); 564 565 if ( m_data->orientation == Qt::Horizontal ) 565 566 { 566 567 if ( pos.x() < markerPos ) 567 d_data->stepsIncrement = -d_data->stepsIncrement;568 m_data->stepsIncrement = -m_data->stepsIncrement; 568 569 } 569 570 else 570 571 { 571 572 if ( pos.y() < markerPos ) 572 d_data->stepsIncrement = -d_data->stepsIncrement;573 m_data->stepsIncrement = -m_data->stepsIncrement; 573 574 } 574 575 575 576 if ( isInverted() ) 576 d_data->stepsIncrement = -d_data->stepsIncrement;577 m_data->stepsIncrement = -m_data->stepsIncrement; 577 578 578 579 const double v = value(); 579 incrementValue( d_data->stepsIncrement );580 incrementValue( m_data->stepsIncrement ); 580 581 581 582 if ( v != value() ) … … 584 585 Q_EMIT valueChanged( value() ); 585 586 else 586 d_data->pendingValueChange = true;587 m_data->pendingValueChange = true; 587 588 588 589 Q_EMIT sliderMoved( value() ); 589 590 } 590 591 591 d_data->timerTick = false;592 d_data->repeatTimerId = startTimer( qMax( 250, 2 * updateInterval() ) );592 m_data->timerTick = false; 593 m_data->repeatTimerId = startTimer( qMax( 250, 2 * updateInterval() ) ); 593 594 594 595 return; … … 602 603 Mouse release event handler 603 604 \param event Mouse event 604 */ 605 void QwtSlider::mouseReleaseEvent( QMouseEvent *event )606 { 607 if ( d_data->repeatTimerId > 0 )608 { 609 killTimer( d_data->repeatTimerId );610 d_data->repeatTimerId = 0;611 d_data->timerTick = false;612 d_data->stepsIncrement = 0;613 } 614 615 if ( d_data->pendingValueChange )616 { 617 d_data->pendingValueChange = false;605 */ 606 void QwtSlider::mouseReleaseEvent( QMouseEvent* event ) 607 { 608 if ( m_data->repeatTimerId > 0 ) 609 { 610 killTimer( m_data->repeatTimerId ); 611 m_data->repeatTimerId = 0; 612 m_data->timerTick = false; 613 m_data->stepsIncrement = 0; 614 } 615 616 if ( m_data->pendingValueChange ) 617 { 618 m_data->pendingValueChange = false; 618 619 Q_EMIT valueChanged( value() ); 619 620 } … … 629 630 630 631 \param event Mouse event 631 */ 632 void QwtSlider::timerEvent( QTimerEvent *event )633 { 634 if ( event->timerId() != d_data->repeatTimerId )632 */ 633 void QwtSlider::timerEvent( QTimerEvent* event ) 634 { 635 if ( event->timerId() != m_data->repeatTimerId ) 635 636 { 636 637 QwtAbstractSlider::timerEvent( event ); … … 640 641 if ( !isValid() ) 641 642 { 642 killTimer( d_data->repeatTimerId );643 d_data->repeatTimerId = 0;643 killTimer( m_data->repeatTimerId ); 644 m_data->repeatTimerId = 0; 644 645 return; 645 646 } 646 647 647 648 const double v = value(); 648 incrementValue( d_data->stepsIncrement );649 incrementValue( m_data->stepsIncrement ); 649 650 650 651 if ( v != value() ) … … 653 654 Q_EMIT valueChanged( value() ); 654 655 else 655 d_data->pendingValueChange = true;656 m_data->pendingValueChange = true; 656 657 657 658 Q_EMIT sliderMoved( value() ); 658 659 } 659 660 660 if ( ! d_data->timerTick )661 if ( !m_data->timerTick ) 661 662 { 662 663 // restart the timer with a shorter interval 663 killTimer( d_data->repeatTimerId );664 d_data->repeatTimerId = startTimer( updateInterval() );665 666 d_data->timerTick = true;664 killTimer( m_data->repeatTimerId ); 665 m_data->repeatTimerId = startTimer( updateInterval() ); 666 667 m_data->timerTick = true; 667 668 } 668 669 } … … 671 672 Qt paint event handler 672 673 \param event Paint event 673 */ 674 void QwtSlider::paintEvent( QPaintEvent *event )674 */ 675 void QwtSlider::paintEvent( QPaintEvent* event ) 675 676 { 676 677 QPainter painter( this ); … … 678 679 679 680 QStyleOption opt; 680 opt.init(this); 681 opt.initFrom(this); 681 682 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 682 683 683 if ( d_data->scalePosition != QwtSlider::NoScale )684 { 685 if ( ! d_data->sliderRect.contains( event->rect() ) )684 if ( m_data->scalePosition != QwtSlider::NoScale ) 685 { 686 if ( !m_data->sliderRect.contains( event->rect() ) ) 686 687 scaleDraw()->draw( &painter, palette() ); 687 688 } 688 689 689 drawSlider( &painter, d_data->sliderRect );690 drawSlider( &painter, m_data->sliderRect ); 690 691 691 692 if ( hasFocus() ) 692 QwtPainter::drawFocusRect( &painter, this, d_data->sliderRect );693 QwtPainter::drawFocusRect( &painter, this, m_data->sliderRect ); 693 694 } 694 695 … … 696 697 Qt resize event handler 697 698 \param event Resize event 698 */ 699 void QwtSlider::resizeEvent( QResizeEvent *event ) 700 { 701 Q_UNUSED( event ); 702 699 */ 700 void QwtSlider::resizeEvent( QResizeEvent* event ) 701 { 703 702 layoutSlider( false ); 703 QwtAbstractSlider::resizeEvent( event ); 704 } 705 706 /*! 707 Qt event handler 708 \param event Event 709 710 \return true, if event was recognized and processed 711 */ 712 bool QwtSlider::event( QEvent* event ) 713 { 714 if ( event->type() == QEvent::PolishRequest ) 715 layoutSlider( false ); 716 717 return QwtAbstractSlider::event( event ); 704 718 } 705 719 … … 707 721 Handles QEvent::StyleChange and QEvent::FontChange events 708 722 \param event Change event 709 */ 710 void QwtSlider::changeEvent( QEvent *event )723 */ 724 void QwtSlider::changeEvent( QEvent* event ) 711 725 { 712 726 if ( event->type() == QEvent::StyleChange || … … 721 735 722 736 /*! 723 Recalculate the slider's geometry and layout based on 724 the current geometry and fonts. 725 726 \param update_geometry notify the layout system and call update 737 Recalculate the slider's geometry and layout based on 738 the current geometry and fonts. 739 740 \param update_geometry notify the layout system and call update 727 741 to redraw the scale 728 */ 742 */ 729 743 void QwtSlider::layoutSlider( bool update_geometry ) 730 744 { 731 745 int bw = 0; 732 if ( d_data->hasTrough )733 bw = d_data->borderWidth;734 735 const QSize handleSize = qwtHandleSize( d_data->handleSize,736 d_data->orientation,d_data->hasTrough );746 if ( m_data->hasTrough ) 747 bw = m_data->borderWidth; 748 749 const QSize handleSize = qwtHandleSize( m_data->handleSize, 750 m_data->orientation, m_data->hasTrough ); 737 751 738 752 QRect sliderRect = contentsRect(); … … 752 766 753 767 int scaleMargin = 0; 754 if ( d_data->scalePosition != QwtSlider::NoScale )768 if ( m_data->scalePosition != QwtSlider::NoScale ) 755 769 { 756 770 int d1, d2; … … 762 776 int scaleX, scaleY, scaleLength; 763 777 764 if ( d_data->orientation == Qt::Horizontal )778 if ( m_data->orientation == Qt::Horizontal ) 765 779 { 766 780 const int handleMargin = handleSize.width() / 2 - 1; … … 791 805 // now align slider and scale according to the ScalePosition 792 806 793 if ( d_data->orientation == Qt::Horizontal )807 if ( m_data->orientation == Qt::Horizontal ) 794 808 { 795 809 const int h = handleSize.height() + 2 * bw; 796 810 797 if ( d_data->scalePosition == QwtSlider::TrailingScale )811 if ( m_data->scalePosition == QwtSlider::TrailingScale ) 798 812 { 799 813 sliderRect.setTop( sliderRect.bottom() + 1 - h ); 800 scaleY = sliderRect.top() - d_data->spacing;814 scaleY = sliderRect.top() - m_data->spacing; 801 815 } 802 816 else 803 817 { 804 818 sliderRect.setHeight( h ); 805 scaleY = sliderRect.bottom() + 1 + d_data->spacing;819 scaleY = sliderRect.bottom() + 1 + m_data->spacing; 806 820 } 807 821 } … … 810 824 const int w = handleSize.width() + 2 * bw; 811 825 812 if ( d_data->scalePosition == QwtSlider::LeadingScale )826 if ( m_data->scalePosition == QwtSlider::LeadingScale ) 813 827 { 814 828 sliderRect.setWidth( w ); 815 scaleX = sliderRect.right() + 1 + d_data->spacing;829 scaleX = sliderRect.right() + 1 + m_data->spacing; 816 830 } 817 831 else 818 832 { 819 833 sliderRect.setLeft( sliderRect.right() + 1 - w ); 820 scaleX = sliderRect.left() - d_data->spacing;834 scaleX = sliderRect.left() - m_data->spacing; 821 835 } 822 836 } 823 837 824 d_data->sliderRect = sliderRect;838 m_data->sliderRect = sliderRect; 825 839 826 840 scaleDraw()->move( scaleX, scaleY ); … … 829 843 if ( update_geometry ) 830 844 { 831 d_data->sizeHintCache = QSize(); // invalidate845 m_data->sizeHintCache = QSize(); // invalidate 832 846 updateGeometry(); 833 847 update(); … … 836 850 837 851 /*! 838 En/Disable the trough 839 840 The slider can be cutomized by showing a trough for the 841 handle. 842 843 \param on When true, the groove is visible 844 \sa hasTrough(), setGroove() 852 En/Disable the trough 853 854 The slider can be customized by showing a trough for the 855 handle. 856 857 \param on When true, the groove is visible 858 \sa hasTrough(), setGroove() 845 859 */ 846 860 void QwtSlider::setTrough( bool on ) 847 861 { 848 if ( d_data->hasTrough != on )849 { 850 d_data->hasTrough = on;862 if ( m_data->hasTrough != on ) 863 { 864 m_data->hasTrough = on; 851 865 852 866 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 856 870 857 871 /*! 858 \return True, when the trough is visi sble859 \sa setTrough(), hasGroove() 872 \return True, when the trough is visible 873 \sa setTrough(), hasGroove() 860 874 */ 861 875 bool QwtSlider::hasTrough() const 862 876 { 863 return d_data->hasTrough;864 } 865 866 /*! 867 En/Disable the groove 868 869 The slider can be cutomized by showing a groove for the 870 handle. 871 872 \param on When true, the groove is visible 873 \sa hasGroove(), setThrough() 877 return m_data->hasTrough; 878 } 879 880 /*! 881 En/Disable the groove 882 883 The slider can be customized by showing a groove for the 884 handle. 885 886 \param on When true, the groove is visible 887 \sa hasGroove(), setThrough() 874 888 */ 875 889 void QwtSlider::setGroove( bool on ) 876 890 { 877 if ( d_data->hasGroove != on )878 { 879 d_data->hasGroove = on;891 if ( m_data->hasGroove != on ) 892 { 893 m_data->hasGroove = on; 880 894 881 895 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 885 899 886 900 /*! 887 \return True, when the groove is visi sble888 \sa setGroove(), hasTrough() 901 \return True, when the groove is visible 902 \sa setGroove(), hasTrough() 889 903 */ 890 904 bool QwtSlider::hasGroove() const 891 905 { 892 return d_data->hasGroove;893 } 894 895 /*! 896 \return minimumSizeHint() 897 */ 906 return m_data->hasGroove; 907 } 908 909 /*! 910 \return minimumSizeHint() 911 */ 898 912 QSize QwtSlider::sizeHint() const 899 913 { 900 914 const QSize hint = minimumSizeHint(); 901 return hint.expandedTo( QApplication::globalStrut());902 } 903 904 /*! 905 \return Minimum size hint 906 \sa sizeHint() 907 */ 915 return qwtExpandedToGlobalStrut( hint ); 916 } 917 918 /*! 919 \return Minimum size hint 920 \sa sizeHint() 921 */ 908 922 QSize QwtSlider::minimumSizeHint() const 909 923 { 910 if ( ! d_data->sizeHintCache.isEmpty() )911 return d_data->sizeHintCache;912 913 const QSize handleSize = qwtHandleSize( d_data->handleSize,914 d_data->orientation,d_data->hasTrough );924 if ( !m_data->sizeHintCache.isEmpty() ) 925 return m_data->sizeHintCache; 926 927 const QSize handleSize = qwtHandleSize( m_data->handleSize, 928 m_data->orientation, m_data->hasTrough ); 915 929 916 930 int bw = 0; 917 if ( d_data->hasTrough )918 bw = d_data->borderWidth;931 if ( m_data->hasTrough ) 932 bw = m_data->borderWidth; 919 933 920 934 int sliderLength = 0; 921 935 int scaleExtent = 0; 922 936 923 if ( d_data->scalePosition != QwtSlider::NoScale )937 if ( m_data->scalePosition != QwtSlider::NoScale ) 924 938 { 925 939 int d1, d2; … … 929 943 930 944 int handleBorderDist; 931 if ( d_data->orientation == Qt::Horizontal )945 if ( m_data->orientation == Qt::Horizontal ) 932 946 handleBorderDist = handleSize.width(); 933 947 else … … 941 955 } 942 956 943 scaleExtent += d_data->spacing;944 scaleExtent += qCeil( scaleDraw()->extent( font() ) ); 957 scaleExtent += m_data->spacing; 958 scaleExtent += qwtCeil( scaleDraw()->extent( font() ) ); 945 959 } 946 960 … … 950 964 int h = 0; 951 965 952 if ( d_data->orientation == Qt::Horizontal )966 if ( m_data->orientation == Qt::Horizontal ) 953 967 { 954 968 w = sliderLength; … … 962 976 963 977 // finally add margins 964 int left, right, top, bottom; 965 getContentsMargins( &left, &top, &right, &bottom ); 966 967 w += left + right; 968 h += top + bottom; 969 970 d_data->sizeHintCache = QSize( w, h ); 971 return d_data->sizeHintCache; 978 const QMargins m = contentsMargins(); 979 980 w += m.left() + m.right(); 981 h += m.top() + m.bottom(); 982 983 m_data->sizeHintCache = QSize( w, h ); 984 return m_data->sizeHintCache; 972 985 } 973 986 … … 982 995 const int markerPos = transform( value() ); 983 996 984 QPoint center = d_data->sliderRect.center();985 if ( d_data->orientation == Qt::Horizontal )997 QPoint center = m_data->sliderRect.center(); 998 if ( m_data->orientation == Qt::Horizontal ) 986 999 center.setX( markerPos ); 987 1000 else … … 989 1002 990 1003 QRect rect; 991 rect.setSize( qwtHandleSize( d_data->handleSize,992 d_data->orientation,d_data->hasTrough ) );1004 rect.setSize( qwtHandleSize( m_data->handleSize, 1005 m_data->orientation, m_data->hasTrough ) ); 993 1006 rect.moveCenter( center ); 994 1007 … … 997 1010 998 1011 /*! 999 \return Bounding rectangle of the slider - without the scale 1012 \return Bounding rectangle of the slider - without the scale 1000 1013 */ 1001 1014 QRect QwtSlider::sliderRect() const 1002 1015 { 1003 return d_data->sliderRect; 1004 } 1016 return m_data->sliderRect; 1017 } 1018 1019 #include "moc_qwt_slider.cpp" -
trunk/BNC/qwt/qwt_slider.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 17 17 18 18 /*! 19 \brief The Slider Widget 19 \brief The Slider Widget 20 20 21 QwtSlider is a slider widget which operates on an interval 22 of type double. Its position is related to a scale showing 23 the current value. 21 QwtSlider is a slider widget which operates on an interval 22 of type double. Its position is related to a scale showing 23 the current value. 24 24 25 The slider can be customized by having a through, a groove - or both. 25 The slider can be customized by having a through, a groove - or both. 26 26 27 \image html sliders.png 28 */ 27 \image html sliders.png 28 */ 29 29 30 class QWT_EXPORT QwtSlider: public QwtAbstractSlider 30 class QWT_EXPORT QwtSlider : public QwtAbstractSlider 31 31 { 32 32 Q_OBJECT … … 35 35 36 36 Q_PROPERTY( Qt::Orientation orientation 37 READ orientation WRITE setOrientation )37 READ orientation WRITE setOrientation ) 38 38 Q_PROPERTY( ScalePosition scalePosition READ scalePosition 39 39 WRITE setScalePosition ) … … 46 46 Q_PROPERTY( int spacing READ spacing WRITE setSpacing ) 47 47 48 public: 48 public: 49 49 50 50 /*! 51 Position of the scale 52 \sa QwtSlider(), setScalePosition(), setOrientation() 51 Position of the scale 52 \sa QwtSlider(), setScalePosition(), setOrientation() 53 53 */ 54 54 enum ScalePosition … … 64 64 }; 65 65 66 explicit QwtSlider( QWidget *parent = NULL );67 explicit QwtSlider( Qt::Orientation, QWidget *parent = NULL );66 explicit QwtSlider( QWidget* parent = NULL ); 67 explicit QwtSlider( Qt::Orientation, QWidget* parent = NULL ); 68 68 69 69 virtual ~QwtSlider(); … … 81 81 bool hasGroove() const; 82 82 83 void setHandleSize( const QSize & );83 void setHandleSize( const QSize& ); 84 84 QSize handleSize() const; 85 85 … … 90 90 int spacing() const; 91 91 92 virtual QSize sizeHint() const; 93 virtual QSize minimumSizeHint() const; 92 virtual QSize sizeHint() const QWT_OVERRIDE; 93 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 94 94 95 void setScaleDraw( QwtScaleDraw * );96 const QwtScaleDraw *scaleDraw() const;95 void setScaleDraw( QwtScaleDraw* ); 96 const QwtScaleDraw* scaleDraw() const; 97 97 98 98 void setUpdateInterval( int ); 99 99 int updateInterval() const; 100 100 101 protected: 102 virtual double scrolledTo( const QPoint & ) const;103 virtual bool isScrollPosition( const QPoint & ) const;101 protected: 102 virtual double scrolledTo( const QPoint& ) const QWT_OVERRIDE; 103 virtual bool isScrollPosition( const QPoint& ) const QWT_OVERRIDE; 104 104 105 virtual void drawSlider ( QPainter *, const QRect& ) const;106 virtual void drawHandle( QPainter *, const QRect&, int pos ) const;105 virtual void drawSlider ( QPainter*, const QRect& ) const; 106 virtual void drawHandle( QPainter*, const QRect&, int pos ) const; 107 107 108 virtual void mousePressEvent( QMouseEvent * );109 virtual void mouseReleaseEvent( QMouseEvent * );110 virtual void resizeEvent( QResizeEvent * );111 virtual void paintEvent ( QPaintEvent * );112 virtual void changeEvent( QEvent * );113 virtual void timerEvent( QTimerEvent * );108 virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE; 109 virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE; 110 virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE; 111 virtual void paintEvent ( QPaintEvent* ) QWT_OVERRIDE; 112 virtual void changeEvent( QEvent* ) QWT_OVERRIDE; 113 virtual void timerEvent( QTimerEvent* ) QWT_OVERRIDE; 114 114 115 virtual void scaleChange(); 115 virtual bool event( QEvent* ) QWT_OVERRIDE; 116 117 virtual void scaleChange() QWT_OVERRIDE; 116 118 117 119 QRect sliderRect() const; 118 120 QRect handleRect() const; 119 121 120 private: 121 QwtScaleDraw *scaleDraw();122 private: 123 QwtScaleDraw* scaleDraw(); 122 124 123 125 void layoutSlider( bool ); … … 125 127 126 128 class PrivateData; 127 PrivateData *d_data;129 PrivateData* m_data; 128 130 }; 129 131 -
trunk/BNC/qwt/qwt_spline.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_spline.h" 11 #include "qwt_math.h" 11 #include "qwt_spline_parametrization.h" 12 #include "qwt_spline_polynomial.h" 13 #include "qwt_bezier.h" 14 15 #include <qpainterpath.h> 16 17 namespace QwtSplineC1P 18 { 19 struct param 20 { 21 param( const QwtSplineParametrization* p ): 22 parameter( p ) 23 { 24 } 25 26 inline double operator()( const QPointF& p1, const QPointF& p2 ) const 27 { 28 return parameter->valueIncrement( p1, p2 ); 29 } 30 31 const QwtSplineParametrization* parameter; 32 }; 33 34 struct paramY 35 { 36 inline double operator()( const QPointF& p1, const QPointF& p2 ) const 37 { 38 return QwtSplineParametrization::valueIncrementY( p1, p2 ); 39 } 40 }; 41 42 struct paramUniform 43 { 44 inline double operator()( const QPointF& p1, const QPointF& p2 ) const 45 { 46 return QwtSplineParametrization::valueIncrementUniform( p1, p2 ); 47 } 48 }; 49 50 struct paramCentripetal 51 { 52 inline double operator()( const QPointF& p1, const QPointF& p2 ) const 53 { 54 return QwtSplineParametrization::valueIncrementCentripetal( p1, p2 ); 55 } 56 }; 57 58 struct paramChordal 59 { 60 inline double operator()( const QPointF& p1, const QPointF& p2 ) const 61 { 62 return QwtSplineParametrization::valueIncrementChordal( p1, p2 ); 63 } 64 }; 65 66 struct paramManhattan 67 { 68 inline double operator()( const QPointF& p1, const QPointF& p2 ) const 69 { 70 return QwtSplineParametrization::valueIncrementManhattan( p1, p2 ); 71 } 72 }; 73 74 class PathStore 75 { 76 public: 77 inline void init( int size ) 78 { 79 Q_UNUSED(size); 80 } 81 82 inline void start( double x1, double y1 ) 83 { 84 path.moveTo( x1, y1 ); 85 } 86 87 inline void addCubic( double cx1, double cy1, 88 double cx2, double cy2, double x2, double y2 ) 89 { 90 path.cubicTo( cx1, cy1, cx2, cy2, x2, y2 ); 91 } 92 93 inline void end() 94 { 95 path.closeSubpath(); 96 } 97 98 QPainterPath path; 99 }; 100 101 class ControlPointsStore 102 { 103 public: 104 inline ControlPointsStore(): 105 m_cp( NULL ) 106 { 107 } 108 109 inline void init( int size ) 110 { 111 controlPoints.resize( size ); 112 m_cp = controlPoints.data(); 113 } 114 115 inline void start( double x1, double y1 ) 116 { 117 Q_UNUSED( x1 ); 118 Q_UNUSED( y1 ); 119 } 120 121 inline void addCubic( double cx1, double cy1, 122 double cx2, double cy2, double x2, double y2 ) 123 { 124 Q_UNUSED( x2 ); 125 Q_UNUSED( y2 ); 126 127 QLineF& l = *m_cp++; 128 l.setLine( cx1, cy1, cx2, cy2 ); 129 } 130 131 inline void end() 132 { 133 } 134 135 QVector< QLineF > controlPoints; 136 137 private: 138 QLineF* m_cp; 139 }; 140 141 double slopeBoundary( int boundaryCondition, double boundaryValue, 142 const QPointF& p1, const QPointF& p2, double slope1 ) 143 { 144 const double dx = p2.x() - p1.x(); 145 const double dy = p2.y() - p1.y(); 146 147 double m = 0.0; 148 149 switch( boundaryCondition ) 150 { 151 case QwtSpline::Clamped1: 152 { 153 m = boundaryValue; 154 break; 155 } 156 case QwtSpline::Clamped2: 157 { 158 const double c2 = 0.5 * boundaryValue; 159 const double c1 = slope1; 160 161 m = 0.5 * ( 3.0 * dy / dx - c1 - c2 * dx ); 162 break; 163 } 164 case QwtSpline::Clamped3: 165 { 166 const double c3 = boundaryValue / 6.0; 167 m = c3 * dx * dx + 2 * dy / dx - slope1; 168 break; 169 } 170 case QwtSpline::LinearRunout: 171 { 172 const double s = dy / dx; 173 const double r = qBound( 0.0, boundaryValue, 1.0 ); 174 175 m = s - r * ( s - slope1 ); 176 break; 177 } 178 default: 179 { 180 m = dy / dx; // something 181 } 182 } 183 184 return m; 185 } 186 } 187 188 template< class SplineStore > 189 static inline SplineStore qwtSplineC1PathParamX( 190 const QwtSplineC1* spline, const QPolygonF& points ) 191 { 192 const int n = points.size(); 193 194 const QVector< double > m = spline->slopes( points ); 195 if ( m.size() != n ) 196 return SplineStore(); 197 198 const QPointF* pd = points.constData(); 199 const double* md = m.constData(); 200 201 SplineStore store; 202 store.init( m.size() - 1 ); 203 store.start( pd[0].x(), pd[0].y() ); 204 205 for ( int i = 0; i < n - 1; i++ ) 206 { 207 const double dx3 = ( pd[i + 1].x() - pd[i].x() ) / 3.0; 208 209 store.addCubic( pd[i].x() + dx3, pd[i].y() + md[i] * dx3, 210 pd[i + 1].x() - dx3, pd[i + 1].y() - md[i + 1] * dx3, 211 pd[i + 1].x(), pd[i + 1].y() ); 212 } 213 214 return store; 215 } 216 217 template< class SplineStore > 218 static inline SplineStore qwtSplineC1PathParamY( 219 const QwtSplineC1* spline, const QPolygonF& points ) 220 { 221 const int n = points.size(); 222 223 QPolygonF pointsFlipped( n ); 224 for ( int i = 0; i < n; i++ ) 225 { 226 pointsFlipped[i].setX( points[i].y() ); 227 pointsFlipped[i].setY( points[i].x() ); 228 } 229 230 const QVector< double > m = spline->slopes( pointsFlipped ); 231 if ( m.size() != n ) 232 return SplineStore(); 233 234 const QPointF* pd = pointsFlipped.constData(); 235 const double* md = m.constData(); 236 237 SplineStore store; 238 store.init( m.size() - 1 ); 239 store.start( pd[0].y(), pd[0].x() ); 240 241 QVector< QLineF > lines( n ); 242 for ( int i = 0; i < n - 1; i++ ) 243 { 244 const double dx3 = ( pd[i + 1].x() - pd[i].x() ) / 3.0; 245 246 store.addCubic( pd[i].y() + md[i] * dx3, pd[i].x() + dx3, 247 pd[i + 1].y() - md[i + 1] * dx3, pd[i + 1].x() - dx3, 248 pd[i + 1].y(), pd[i + 1].x() ); 249 } 250 251 return store; 252 } 253 254 template< class SplineStore, class Param > 255 static inline SplineStore qwtSplineC1PathParametric( 256 const QwtSplineC1* spline, const QPolygonF& points, Param param ) 257 { 258 const bool isClosing = ( spline->boundaryType() == QwtSpline::ClosedPolygon ); 259 const int n = points.size(); 260 261 QPolygonF pointsX, pointsY; 262 pointsX.resize( isClosing ? n + 1 : n ); 263 pointsY.resize( isClosing ? n + 1 : n ); 264 265 QPointF* px = pointsX.data(); 266 QPointF* py = pointsY.data(); 267 const QPointF* p = points.constData(); 268 269 double t = 0.0; 270 271 px[0].rx() = py[0].rx() = t; 272 px[0].ry() = p[0].x(); 273 py[0].ry() = p[0].y(); 274 275 int numParamPoints = 1; 276 for ( int i = 1; i < n; i++ ) 277 { 278 const double td = param( points[i - 1], points[i] ); 279 if ( td > 0.0 ) 280 { 281 t += td; 282 283 px[numParamPoints].rx() = py[numParamPoints].rx() = t; 284 285 px[numParamPoints].ry() = p[i].x(); 286 py[numParamPoints].ry() = p[i].y(); 287 288 numParamPoints++; 289 } 290 } 291 292 if ( isClosing ) 293 { 294 const double td = param( points[n - 1], points[0] ); 295 296 if ( td > 0.0 ) 297 { 298 t += td; 299 300 px[numParamPoints].rx() = py[numParamPoints].rx() = t; 301 302 px[numParamPoints].ry() = p[0].x(); 303 py[numParamPoints].ry() = p[0].y(); 304 305 numParamPoints++; 306 } 307 } 308 309 if ( pointsX.size() != numParamPoints ) 310 { 311 pointsX.resize( numParamPoints ); 312 pointsY.resize( numParamPoints ); 313 } 314 315 const QVector< double > slopesX = spline->slopes( pointsX ); 316 const QVector< double > slopesY = spline->slopes( pointsY ); 317 318 const double* mx = slopesX.constData(); 319 const double* my = slopesY.constData(); 320 321 // we don't need it anymore 322 pointsX.clear(); 323 pointsY.clear(); 324 325 SplineStore store; 326 store.init( isClosing ? n : n - 1 ); 327 store.start( points[0].x(), points[0].y() ); 328 329 int j = 0; 330 331 for ( int i = 0; i < n - 1; i++ ) 332 { 333 const QPointF& p1 = p[i]; 334 const QPointF& p2 = p[i + 1]; 335 336 const double td = param( p1, p2 ); 337 338 if ( td != 0.0 ) 339 { 340 const double t3 = td / 3.0; 341 342 const double cx1 = p1.x() + mx[j] * t3; 343 const double cy1 = p1.y() + my[j] * t3; 344 345 const double cx2 = p2.x() - mx[j + 1] * t3; 346 const double cy2 = p2.y() - my[j + 1] * t3; 347 348 store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() ); 349 350 j++; 351 } 352 else 353 { 354 // setting control points to the ends 355 store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() ); 356 } 357 } 358 359 if ( isClosing ) 360 { 361 const QPointF& p1 = p[n - 1]; 362 const QPointF& p2 = p[0]; 363 364 const double td = param( p1, p2 ); 365 366 if ( td != 0.0 ) 367 { 368 const double t3 = td / 3.0; 369 370 const double cx1 = p1.x() + mx[j] * t3; 371 const double cy1 = p1.y() + my[j] * t3; 372 373 const double cx2 = p2.x() - mx[0] * t3; 374 const double cy2 = p2.y() - my[0] * t3; 375 376 store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() ); 377 } 378 else 379 { 380 store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() ); 381 } 382 383 store.end(); 384 } 385 386 return store; 387 } 388 389 template< QwtSplinePolynomial toPolynomial( const QPointF&, double, const QPointF&, double ) > 390 static QPolygonF qwtPolygonParametric( double distance, 391 const QPolygonF& points, const QVector< double >& values, bool withNodes ) 392 { 393 QPolygonF fittedPoints; 394 395 const QPointF* p = points.constData(); 396 const double* v = values.constData(); 397 398 fittedPoints += p[0]; 399 double t = distance; 400 401 const int n = points.size(); 402 403 for ( int i = 0; i < n - 1; i++ ) 404 { 405 const QPointF& p1 = p[i]; 406 const QPointF& p2 = p[i + 1]; 407 408 const QwtSplinePolynomial polynomial = toPolynomial( p1, v[i], p2, v[i + 1] ); 409 410 const double l = p2.x() - p1.x(); 411 412 while ( t < l ) 413 { 414 fittedPoints += QPointF( p1.x() + t, p1.y() + polynomial.valueAt( t ) ); 415 t += distance; 416 } 417 418 if ( withNodes ) 419 { 420 if ( qFuzzyCompare( fittedPoints.last().x(), p2.x() ) ) 421 fittedPoints.last() = p2; 422 else 423 fittedPoints += p2; 424 } 425 else 426 { 427 t -= l; 428 } 429 } 430 431 return fittedPoints; 432 } 12 433 13 434 class QwtSpline::PrivateData 14 435 { 15 public: 16 PrivateData(): 17 splineType( QwtSpline::Natural ) 18 { 19 } 20 21 QwtSpline::SplineType splineType; 22 23 // coefficient vectors 24 QVector<double> a; 25 QVector<double> b; 26 QVector<double> c; 27 28 // control points 29 QPolygonF points; 436 public: 437 PrivateData() 438 : boundaryType( QwtSpline::ConditionalBoundaries ) 439 { 440 parametrization = new QwtSplineParametrization( 441 QwtSplineParametrization::ParameterChordal ); 442 443 // parabolic runout at both ends 444 445 boundaryConditions[0].type = QwtSpline::Clamped3; 446 boundaryConditions[0].value = 0.0; 447 448 boundaryConditions[1].type = QwtSpline::Clamped3; 449 boundaryConditions[1].value = 0.0; 450 } 451 452 ~PrivateData() 453 { 454 delete parametrization; 455 } 456 457 QwtSplineParametrization* parametrization; 458 QwtSpline::BoundaryType boundaryType; 459 460 struct 461 { 462 int type; 463 double value; 464 465 } boundaryConditions[2]; 30 466 }; 31 467 32 static int lookup( double x, const QPolygonF &values ) 33 { 34 #if 0 35 //qLowerBound/qHigherBound ??? 36 #endif 37 int i1; 38 const int size = values.size(); 39 40 if ( x <= values[0].x() ) 41 i1 = 0; 42 else if ( x >= values[size - 2].x() ) 43 i1 = size - 2; 44 else 45 { 46 i1 = 0; 47 int i2 = size - 2; 48 int i3 = 0; 49 50 while ( i2 - i1 > 1 ) 51 { 52 i3 = i1 + ( ( i2 - i1 ) >> 1 ); 53 54 if ( values[i3].x() > x ) 55 i2 = i3; 56 else 57 i1 = i3; 58 } 59 } 60 return i1; 61 } 62 63 //! Constructor 468 /*! 469 \fn QPainterPath QwtSpline::painterPath( const QPolygonF &points ) const 470 471 Approximates a polygon piecewise with cubic Bezier curves 472 and returns them as QPainterPath. 473 474 \param points Control points 475 \return Painter path, that can be rendered by QPainter 476 477 \sa polygon(), QwtBezier 478 */ 479 480 /*! 481 \brief Interpolate a curve by a polygon 482 483 Interpolates a polygon piecewise with Bezier curves 484 interpolating them in a 2nd pass by polygons. 485 486 The interpolation is based on "Piecewise Linear Approximation of Bézier Curves" 487 by Roger Willcocks ( http://www.rops.org ) 488 489 \param points Control points 490 \param tolerance Maximum for the accepted error of the approximation 491 492 \return polygon approximating the interpolating polynomials 493 494 \sa bezierControlLines(), QwtBezier 495 */ 496 QPolygonF QwtSpline::polygon( const QPolygonF& points, double tolerance ) const 497 { 498 if ( tolerance <= 0.0 ) 499 return QPolygonF(); 500 501 const QPainterPath path = painterPath( points ); 502 const int n = path.elementCount(); 503 if ( n == 0 ) 504 return QPolygonF(); 505 506 const QPainterPath::Element el = path.elementAt( 0 ); 507 if ( el.type != QPainterPath::MoveToElement ) 508 return QPolygonF(); 509 510 QPointF p1( el.x, el.y ); 511 512 QPolygonF polygon; 513 QwtBezier bezier( tolerance ); 514 515 for ( int i = 1; i < n; i += 3 ) 516 { 517 const QPainterPath::Element el1 = path.elementAt( i ); 518 const QPainterPath::Element el2 = path.elementAt( i + 1 ); 519 const QPainterPath::Element el3 = path.elementAt( i + 2 ); 520 521 const QPointF cp1( el1.x, el1.y ); 522 const QPointF cp2( el2.x, el2.y ); 523 const QPointF p2( el3.x, el3.y ); 524 525 bezier.appendToPolygon( p1, cp1, cp2, p2, polygon ); 526 527 p1 = p2; 528 } 529 530 return polygon; 531 } 532 533 /*! 534 \brief Constructor 535 536 The default setting is a non closing spline with chordal parametrization 537 538 \sa setParametrization(), setBoundaryType() 539 */ 64 540 QwtSpline::QwtSpline() 65 541 { 66 d_data = new PrivateData; 67 } 68 69 /*! 70 Copy constructor 71 \param other Spline used for initialization 72 */ 73 QwtSpline::QwtSpline( const QwtSpline& other ) 74 { 75 d_data = new PrivateData( *other.d_data ); 76 } 77 78 /*! 79 Assignment operator 80 \param other Spline used for initialization 81 \return *this 82 */ 83 QwtSpline &QwtSpline::operator=( const QwtSpline & other ) 84 { 85 *d_data = *other.d_data; 86 return *this; 542 m_data = new PrivateData; 87 543 } 88 544 … … 90 546 QwtSpline::~QwtSpline() 91 547 { 92 delete d_data; 93 } 94 95 /*! 96 Select the algorithm used for calculating the spline 97 98 \param splineType Spline type 99 \sa splineType() 100 */ 101 void QwtSpline::setSplineType( SplineType splineType ) 102 { 103 d_data->splineType = splineType; 104 } 105 106 /*! 107 \return the spline type 108 \sa setSplineType() 109 */ 110 QwtSpline::SplineType QwtSpline::splineType() const 111 { 112 return d_data->splineType; 113 } 114 115 /*! 116 \brief Calculate the spline coefficients 117 118 Depending on the value of \a periodic, this function 119 will determine the coefficients for a natural or a periodic 120 spline and store them internally. 121 122 \param points Points 123 \return true if successful 124 \warning The sequence of x (but not y) values has to be strictly monotone 125 increasing, which means <code>points[i].x() < points[i+1].x()</code>. 126 If this is not the case, the function will return false 127 */ 128 bool QwtSpline::setPoints( const QPolygonF& points ) 129 { 130 const int size = points.size(); 131 if ( size <= 2 ) 132 { 133 reset(); 134 return false; 135 } 136 137 d_data->points = points; 138 139 d_data->a.resize( size - 1 ); 140 d_data->b.resize( size - 1 ); 141 d_data->c.resize( size - 1 ); 142 143 bool ok; 144 if ( d_data->splineType == Periodic ) 145 ok = buildPeriodicSpline( points ); 146 else 147 ok = buildNaturalSpline( points ); 148 149 if ( !ok ) 150 reset(); 151 152 return ok; 153 } 154 155 /*! 156 \return Points, that have been by setPoints() 157 */ 158 QPolygonF QwtSpline::points() const 159 { 160 return d_data->points; 161 } 162 163 //! \return A coefficients 164 const QVector<double> &QwtSpline::coefficientsA() const 165 { 166 return d_data->a; 167 } 168 169 //! \return B coefficients 170 const QVector<double> &QwtSpline::coefficientsB() const 171 { 172 return d_data->b; 173 } 174 175 //! \return C coefficients 176 const QVector<double> &QwtSpline::coefficientsC() const 177 { 178 return d_data->c; 179 } 180 181 182 //! Free allocated memory and set size to 0 183 void QwtSpline::reset() 184 { 185 d_data->a.resize( 0 ); 186 d_data->b.resize( 0 ); 187 d_data->c.resize( 0 ); 188 d_data->points.resize( 0 ); 189 } 190 191 //! True if valid 192 bool QwtSpline::isValid() const 193 { 194 return d_data->a.size() > 0; 195 } 196 197 /*! 198 Calculate the interpolated function value corresponding 199 to a given argument x. 200 201 \param x Coordinate 202 \return Interpolated coordinate 203 */ 204 double QwtSpline::value( double x ) const 205 { 206 if ( d_data->a.size() == 0 ) 548 delete m_data; 549 } 550 551 /*! 552 The locality of an spline interpolation identifies how many adjacent 553 polynomials are affected, when changing the position of one point. 554 555 A locality of 'n' means, that changing the coordinates of a point 556 has an effect on 'n' leading and 'n' following polynomials. 557 Those polynomials can be calculated from a local subpolygon. 558 559 A value of 0 means, that the interpolation is not local and any modification 560 of the polygon requires to recalculate all polynomials ( f.e cubic splines ). 561 562 \return Order of locality 563 */ 564 uint QwtSpline::locality() const 565 { 566 return 0; 567 } 568 569 /*! 570 Define the parametrization for a parametric spline approximation 571 The default setting is a chordal parametrization. 572 573 \param type Type of parametrization, usually one of QwtSplineParametrization::Type 574 \sa parametrization() 575 */ 576 void QwtSpline::setParametrization( int type ) 577 { 578 if ( m_data->parametrization->type() != type ) 579 { 580 delete m_data->parametrization; 581 m_data->parametrization = new QwtSplineParametrization( type ); 582 } 583 } 584 585 /*! 586 Define the parametrization for a parametric spline approximation 587 The default setting is a chordal parametrization. 588 589 \param parametrization Parametrization 590 \sa parametrization() 591 */ 592 void QwtSpline::setParametrization( QwtSplineParametrization* parametrization ) 593 { 594 if ( ( parametrization != NULL ) && ( m_data->parametrization != parametrization ) ) 595 { 596 delete m_data->parametrization; 597 m_data->parametrization = parametrization; 598 } 599 } 600 601 /*! 602 \return parametrization 603 \sa setParametrization() 604 */ 605 const QwtSplineParametrization* QwtSpline::parametrization() const 606 { 607 return m_data->parametrization; 608 } 609 610 /*! 611 Define the boundary type for the endpoints of the approximating 612 spline. 613 614 \param boundaryType Boundary type 615 \sa boundaryType() 616 */ 617 void QwtSpline::setBoundaryType( BoundaryType boundaryType ) 618 { 619 m_data->boundaryType = boundaryType; 620 } 621 622 /*! 623 \return Boundary type 624 \sa setBoundaryType() 625 */ 626 QwtSpline::BoundaryType QwtSpline::boundaryType() const 627 { 628 return m_data->boundaryType; 629 } 630 631 /*! 632 \brief Define the condition for an endpoint of the spline 633 634 \param position At the beginning or the end of the spline 635 \param condition Condition 636 637 \sa BoundaryCondition, QwtSplineC2::BoundaryCondition, boundaryCondition() 638 */ 639 void QwtSpline::setBoundaryCondition( BoundaryPosition position, int condition ) 640 { 641 if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) ) 642 m_data->boundaryConditions[position].type = condition; 643 } 644 645 /*! 646 \return Condition for an endpoint of the spline 647 \param position At the beginning or the end of the spline 648 649 \sa setBoundaryCondition(), boundaryValue(), setBoundaryConditions() 650 */ 651 int QwtSpline::boundaryCondition( BoundaryPosition position ) const 652 { 653 if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) ) 654 return m_data->boundaryConditions[position].type; 655 656 return m_data->boundaryConditions[0].type; // should never happen 657 } 658 659 /*! 660 \brief Define the boundary value 661 662 The boundary value is an parameter used in combination with 663 the boundary condition. Its meaning depends on the condition. 664 665 \param position At the beginning or the end of the spline 666 \param value Value used for the condition at the end point 667 668 \sa boundaryValue(), setBoundaryCondition() 669 */ 670 void QwtSpline::setBoundaryValue( BoundaryPosition position, double value ) 671 { 672 if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) ) 673 m_data->boundaryConditions[position].value = value; 674 } 675 676 /*! 677 \return Boundary value 678 \param position At the beginning or the end of the spline 679 680 \sa setBoundaryValue(), boundaryCondition() 681 */ 682 double QwtSpline::boundaryValue( BoundaryPosition position ) const 683 { 684 if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) ) 685 return m_data->boundaryConditions[position].value; 686 687 return m_data->boundaryConditions[0].value; // should never happen 688 } 689 690 /*! 691 \brief Define the condition at the endpoints of a spline 692 693 \param condition Condition 694 \param valueBegin Used for the condition at the beginning of te spline 695 \param valueEnd Used for the condition at the end of te spline 696 697 \sa BoundaryCondition, QwtSplineC2::BoundaryCondition, 698 testBoundaryCondition(), setBoundaryValue() 699 */ 700 void QwtSpline::setBoundaryConditions( 701 int condition, double valueBegin, double valueEnd ) 702 { 703 setBoundaryCondition( QwtSpline::AtBeginning, condition ); 704 setBoundaryValue( QwtSpline::AtBeginning, valueBegin ); 705 706 setBoundaryCondition( QwtSpline::AtEnd, condition ); 707 setBoundaryValue( QwtSpline::AtEnd, valueEnd ); 708 } 709 710 //! \brief Constructor 711 QwtSplineInterpolating::QwtSplineInterpolating() 712 { 713 } 714 715 //! Destructor 716 QwtSplineInterpolating::~QwtSplineInterpolating() 717 { 718 } 719 720 /*! \fn QVector<QLineF> QwtSplineInterpolating::bezierControlLines( const QPolygonF &points ) const 721 722 \brief Interpolate a curve with Bezier curves 723 724 Interpolates a polygon piecewise with cubic Bezier curves 725 and returns the 2 control points of each curve as QLineF. 726 727 \param points Control points 728 \return Control points of the interpolating Bezier curves 729 */ 730 731 /*! 732 \brief Interpolate a curve with Bezier curves 733 734 Interpolates a polygon piecewise with cubic Bezier curves 735 and returns them as QPainterPath. 736 737 The implementation calculates the Bezier control lines first 738 and converts them into painter path elements in an additional loop. 739 740 \param points Control points 741 \return Painter path, that can be rendered by QPainter 742 743 \note Derived spline classes might overload painterPath() to avoid 744 the extra loops for converting results into a QPainterPath 745 746 \sa bezierControlLines() 747 */ 748 QPainterPath QwtSplineInterpolating::painterPath( const QPolygonF& points ) const 749 { 750 const int n = points.size(); 751 752 QPainterPath path; 753 if ( n == 0 ) 754 return path; 755 756 if ( n == 1 ) 757 { 758 path.moveTo( points[0] ); 759 return path; 760 } 761 762 if ( n == 2 ) 763 { 764 path.addPolygon( points ); 765 return path; 766 } 767 768 const QVector< QLineF > controlLines = bezierControlLines( points ); 769 if ( controlLines.size() < n - 1 ) 770 return path; 771 772 const QPointF* p = points.constData(); 773 const QLineF* l = controlLines.constData(); 774 775 path.moveTo( p[0] ); 776 for ( int i = 0; i < n - 1; i++ ) 777 path.cubicTo( l[i].p1(), l[i].p2(), p[i + 1] ); 778 779 if ( ( boundaryType() == QwtSpline::ClosedPolygon ) 780 && ( controlLines.size() >= n ) ) 781 { 782 path.cubicTo( l[n - 1].p1(), l[n - 1].p2(), p[0] ); 783 path.closeSubpath(); 784 } 785 786 return path; 787 } 788 789 /*! 790 \brief Interpolate a curve by a polygon 791 792 Interpolates a polygon piecewise with Bezier curves 793 approximating them by polygons. 794 795 The approximation is based on "Piecewise Linear Approximation of Bézier Curves" 796 by Roger Willcocks ( http://www.rops.org ) 797 798 \param points Control points 799 \param tolerance Maximum for the accepted error of the approximation 800 801 \return polygon approximating the interpolating polynomials 802 803 \sa bezierControlLines(), QwtSplineBezier::toPolygon() 804 */ 805 QPolygonF QwtSplineInterpolating::polygon( 806 const QPolygonF& points, double tolerance ) const 807 { 808 if ( tolerance <= 0.0 ) 809 return QPolygonF(); 810 811 const QVector< QLineF > controlLines = bezierControlLines( points ); 812 if ( controlLines.isEmpty() ) 813 return QPolygonF(); 814 815 const bool isClosed = boundaryType() == QwtSpline::ClosedPolygon; 816 817 QwtBezier bezier( tolerance ); 818 819 const QPointF* p = points.constData(); 820 const QLineF* cl = controlLines.constData(); 821 822 const int n = controlLines.size(); 823 824 QPolygonF polygon; 825 826 for ( int i = 0; i < n - 1; i++ ) 827 { 828 const QLineF& l = cl[i]; 829 bezier.appendToPolygon( p[i], l.p1(), l.p2(), p[i + 1], polygon ); 830 } 831 832 const QPointF& pn = isClosed ? p[0] : p[n]; 833 const QLineF& l = cl[n - 1]; 834 835 bezier.appendToPolygon( p[n - 1], l.p1(), l.p2(), pn, polygon ); 836 837 return polygon; 838 } 839 840 /*! 841 \brief Find an interpolated polygon with "equidistant" points 842 843 When withNodes is disabled all points of the resulting polygon 844 will be equidistant according to the parametrization. 845 846 When withNodes is enabled the resulting polygon will also include 847 the control points and the interpolated points are always aligned to 848 the control point before ( points[i] + i * distance ). 849 850 The implementation calculates bezier curves first and calculates 851 the interpolated points in a second run. 852 853 \param points Control nodes of the spline 854 \param distance Distance between 2 points according 855 to the parametrization 856 \param withNodes When true, also add the control 857 nodes ( even if not being equidistant ) 858 859 \return Interpolating polygon 860 861 \sa bezierControlLines() 862 */ 863 QPolygonF QwtSplineInterpolating::equidistantPolygon( const QPolygonF& points, 864 double distance, bool withNodes ) const 865 { 866 if ( distance <= 0.0 ) 867 return QPolygonF(); 868 869 const int n = points.size(); 870 if ( n <= 1 ) 871 return points; 872 873 if ( n == 2 ) 874 { 875 // TODO 876 return points; 877 } 878 879 QPolygonF path; 880 881 const QVector< QLineF > controlLines = bezierControlLines( points ); 882 883 if ( controlLines.size() < n - 1 ) 884 return path; 885 886 path += points.first(); 887 double t = distance; 888 889 const QPointF* p = points.constData(); 890 const QLineF* cl = controlLines.constData(); 891 892 const QwtSplineParametrization* param = parametrization(); 893 894 for ( int i = 0; i < n - 1; i++ ) 895 { 896 const double l = param->valueIncrement( p[i], p[i + 1] ); 897 898 while ( t < l ) 899 { 900 path += QwtBezier::pointAt( p[i], cl[i].p1(), 901 cl[i].p2(), p[i + 1], t / l ); 902 903 t += distance; 904 } 905 906 if ( withNodes ) 907 { 908 if ( qFuzzyCompare( path.last().x(), p[i + 1].x() ) ) 909 path.last() = p[i + 1]; 910 else 911 path += p[i + 1]; 912 913 t = distance; 914 } 915 else 916 { 917 t -= l; 918 } 919 } 920 921 if ( ( boundaryType() == QwtSpline::ClosedPolygon ) 922 && ( controlLines.size() >= n ) ) 923 { 924 const double l = param->valueIncrement( p[n - 1], p[0] ); 925 926 while ( t < l ) 927 { 928 path += QwtBezier::pointAt( p[n - 1], cl[n - 1].p1(), 929 cl[n - 1].p2(), p[0], t / l ); 930 931 t += distance; 932 } 933 934 if ( qFuzzyCompare( path.last().x(), p[0].x() ) ) 935 path.last() = p[0]; 936 else 937 path += p[0]; 938 } 939 940 return path; 941 } 942 943 //! Constructor 944 QwtSplineG1::QwtSplineG1() 945 { 946 } 947 948 //! Destructor 949 QwtSplineG1::~QwtSplineG1() 950 { 951 } 952 953 /*! 954 \brief Constructor 955 956 The default setting is a non closing spline with no parametrization 957 ( QwtSplineParametrization::ParameterX ). 958 959 \sa QwtSpline::setParametrization(), 960 QwtSpline::setBoundaryType() 961 */ 962 QwtSplineC1::QwtSplineC1() 963 { 964 setParametrization( QwtSplineParametrization::ParameterX ); 965 } 966 967 //! Destructor 968 QwtSplineC1::~QwtSplineC1() 969 { 970 } 971 972 /*! 973 \param points Control points 974 \param slopeNext Value of the first derivative at the second point 975 976 \return value of the first derivative at the first point 977 \sa slopeAtEnd(), QwtSpline::boundaryCondition(), QwtSpline::boundaryValue() 978 */ 979 double QwtSplineC1::slopeAtBeginning( const QPolygonF& points, double slopeNext ) const 980 { 981 if ( points.size() < 2 ) 207 982 return 0.0; 208 983 209 const int i = lookup( x, d_data->points ); 210 211 const double delta = x - d_data->points[i].x(); 212 return( ( ( ( d_data->a[i] * delta ) + d_data->b[i] ) 213 * delta + d_data->c[i] ) * delta + d_data->points[i].y() ); 214 } 215 216 /*! 217 \brief Determines the coefficients for a natural spline 218 \return true if successful 219 */ 220 bool QwtSpline::buildNaturalSpline( const QPolygonF &points ) 221 { 222 int i; 223 224 const QPointF *p = points.data(); 225 const int size = points.size(); 226 227 double *a = d_data->a.data(); 228 double *b = d_data->b.data(); 229 double *c = d_data->c.data(); 230 231 // set up tridiagonal equation system; use coefficient 232 // vectors as temporary buffers 233 QVector<double> h( size - 1 ); 234 for ( i = 0; i < size - 1; i++ ) 235 { 236 h[i] = p[i+1].x() - p[i].x(); 237 if ( h[i] <= 0 ) 238 return false; 239 } 240 241 QVector<double> d( size - 1 ); 242 double dy1 = ( p[1].y() - p[0].y() ) / h[0]; 243 for ( i = 1; i < size - 1; i++ ) 244 { 245 b[i] = c[i] = h[i]; 246 a[i] = 2.0 * ( h[i-1] + h[i] ); 247 248 const double dy2 = ( p[i+1].y() - p[i].y() ) / h[i]; 249 d[i] = 6.0 * ( dy1 - dy2 ); 250 dy1 = dy2; 251 } 252 253 // 254 // solve it 255 // 256 257 // L-U Factorization 258 for ( i = 1; i < size - 2; i++ ) 259 { 260 c[i] /= a[i]; 261 a[i+1] -= b[i] * c[i]; 262 } 263 264 // forward elimination 265 QVector<double> s( size ); 266 s[1] = d[1]; 267 for ( i = 2; i < size - 1; i++ ) 268 s[i] = d[i] - c[i-1] * s[i-1]; 269 270 // backward elimination 271 s[size - 2] = - s[size - 2] / a[size - 2]; 272 for ( i = size - 3; i > 0; i-- ) 273 s[i] = - ( s[i] + b[i] * s[i+1] ) / a[i]; 274 s[size - 1] = s[0] = 0.0; 275 276 // 277 // Finally, determine the spline coefficients 278 // 279 for ( i = 0; i < size - 1; i++ ) 280 { 281 a[i] = ( s[i+1] - s[i] ) / ( 6.0 * h[i] ); 282 b[i] = 0.5 * s[i]; 283 c[i] = ( p[i+1].y() - p[i].y() ) / h[i] 284 - ( s[i+1] + 2.0 * s[i] ) * h[i] / 6.0; 285 } 286 287 return true; 288 } 289 290 /*! 291 \brief Determines the coefficients for a periodic spline 292 \return true if successful 293 */ 294 bool QwtSpline::buildPeriodicSpline( const QPolygonF &points ) 295 { 296 int i; 297 298 const QPointF *p = points.data(); 299 const int size = points.size(); 300 301 double *a = d_data->a.data(); 302 double *b = d_data->b.data(); 303 double *c = d_data->c.data(); 304 305 QVector<double> d( size - 1 ); 306 QVector<double> h( size - 1 ); 307 QVector<double> s( size ); 308 309 // 310 // setup equation system; use coefficient 311 // vectors as temporary buffers 312 // 313 for ( i = 0; i < size - 1; i++ ) 314 { 315 h[i] = p[i+1].x() - p[i].x(); 316 if ( h[i] <= 0.0 ) 317 return false; 318 } 319 320 const int imax = size - 2; 321 double htmp = h[imax]; 322 double dy1 = ( p[0].y() - p[imax].y() ) / htmp; 323 for ( i = 0; i <= imax; i++ ) 324 { 325 b[i] = c[i] = h[i]; 326 a[i] = 2.0 * ( htmp + h[i] ); 327 const double dy2 = ( p[i+1].y() - p[i].y() ) / h[i]; 328 d[i] = 6.0 * ( dy1 - dy2 ); 329 dy1 = dy2; 330 htmp = h[i]; 331 } 332 333 // 334 // solve it 335 // 336 337 // L-U Factorization 338 a[0] = qSqrt( a[0] ); 339 c[0] = h[imax] / a[0]; 340 double sum = 0; 341 342 for ( i = 0; i < imax - 1; i++ ) 343 { 344 b[i] /= a[i]; 345 if ( i > 0 ) 346 c[i] = - c[i-1] * b[i-1] / a[i]; 347 a[i+1] = qSqrt( a[i+1] - qwtSqr( b[i] ) ); 348 sum += qwtSqr( c[i] ); 349 } 350 b[imax-1] = ( b[imax-1] - c[imax-2] * b[imax-2] ) / a[imax-1]; 351 a[imax] = qSqrt( a[imax] - qwtSqr( b[imax-1] ) - sum ); 352 353 354 // forward elimination 355 s[0] = d[0] / a[0]; 356 sum = 0; 357 for ( i = 1; i < imax; i++ ) 358 { 359 s[i] = ( d[i] - b[i-1] * s[i-1] ) / a[i]; 360 sum += c[i-1] * s[i-1]; 361 } 362 s[imax] = ( d[imax] - b[imax-1] * s[imax-1] - sum ) / a[imax]; 363 364 365 // backward elimination 366 s[imax] = - s[imax] / a[imax]; 367 s[imax-1] = -( s[imax-1] + b[imax-1] * s[imax] ) / a[imax-1]; 368 for ( i = imax - 2; i >= 0; i-- ) 369 s[i] = - ( s[i] + b[i] * s[i+1] + c[i] * s[imax] ) / a[i]; 370 371 // 372 // Finally, determine the spline coefficients 373 // 374 s[size-1] = s[0]; 375 for ( i = 0; i < size - 1; i++ ) 376 { 377 a[i] = ( s[i+1] - s[i] ) / ( 6.0 * h[i] ); 378 b[i] = 0.5 * s[i]; 379 c[i] = ( p[i+1].y() - p[i].y() ) 380 / h[i] - ( s[i+1] + 2.0 * s[i] ) * h[i] / 6.0; 381 } 382 383 return true; 384 } 984 return QwtSplineC1P::slopeBoundary( 985 boundaryCondition( QwtSpline::AtBeginning ), 986 boundaryValue( QwtSpline::AtBeginning ), 987 points[0], points[1], slopeNext ); 988 } 989 990 /*! 991 \param points Control points 992 \param slopeBefore Value of the first derivative at the point before the last one 993 994 \return value of the first derivative at the last point 995 \sa slopeAtBeginning(), QwtSpline::boundaryCondition(), QwtSpline::boundaryValue() 996 */ 997 double QwtSplineC1::slopeAtEnd( const QPolygonF& points, double slopeBefore ) const 998 { 999 const int n = points.size(); 1000 1001 const QPointF p1( points[n - 1].x(), -points[n - 1].y() ); 1002 const QPointF p2( points[n - 2].x(), -points[n - 2].y() ); 1003 1004 const int condition = boundaryCondition( QwtSpline::AtEnd ); 1005 1006 double value = boundaryValue( QwtSpline::AtEnd ); 1007 if ( condition != QwtSpline::LinearRunout ) 1008 { 1009 // beside LinearRunout the boundaryValue is a slope or curvature 1010 // and needs to be inverted too 1011 value = -value; 1012 } 1013 1014 const double slope = QwtSplineC1P::slopeBoundary( condition, value, p1, p2, -slopeBefore ); 1015 return -slope; 1016 } 1017 1018 /*! \fn QVector<double> QwtSplineC1::slopes( const QPolygonF &points ) const 1019 1020 \brief Find the first derivative at the control points 1021 1022 \param points Control nodes of the spline 1023 \return Vector with the values of the 2nd derivate at the control points 1024 1025 \note The x coordinates need to be increasing or decreasing 1026 */ 1027 1028 /*! 1029 \brief Calculate an interpolated painter path 1030 1031 Interpolates a polygon piecewise into cubic Bezier curves 1032 and returns them as QPainterPath. 1033 1034 The implementation calculates the slopes at the control points 1035 and converts them into painter path elements in an additional loop. 1036 1037 \param points Control points 1038 \return QPainterPath Painter path, that can be rendered by QPainter 1039 1040 \note Derived spline classes might overload painterPath() to avoid 1041 the extra loops for converting results into a QPainterPath 1042 */ 1043 QPainterPath QwtSplineC1::painterPath( const QPolygonF& points ) const 1044 { 1045 const int n = points.size(); 1046 if ( n <= 2 ) 1047 return QwtSplineInterpolating::painterPath( points ); 1048 1049 using namespace QwtSplineC1P; 1050 1051 PathStore store; 1052 switch( parametrization()->type() ) 1053 { 1054 case QwtSplineParametrization::ParameterX: 1055 { 1056 store = qwtSplineC1PathParamX< PathStore >( this, points ); 1057 break; 1058 } 1059 case QwtSplineParametrization::ParameterY: 1060 { 1061 store = qwtSplineC1PathParamY< PathStore >( this, points ); 1062 break; 1063 } 1064 case QwtSplineParametrization::ParameterUniform: 1065 { 1066 store = qwtSplineC1PathParametric< PathStore >( 1067 this, points, paramUniform() ); 1068 break; 1069 } 1070 case QwtSplineParametrization::ParameterCentripetal: 1071 { 1072 store = qwtSplineC1PathParametric< PathStore >( 1073 this, points, paramCentripetal() ); 1074 break; 1075 } 1076 case QwtSplineParametrization::ParameterChordal: 1077 { 1078 store = qwtSplineC1PathParametric< PathStore >( 1079 this, points, paramChordal() ); 1080 break; 1081 } 1082 default: 1083 { 1084 store = qwtSplineC1PathParametric< PathStore >( 1085 this, points, param( parametrization() ) ); 1086 } 1087 } 1088 1089 return store.path; 1090 } 1091 1092 /*! 1093 \brief Interpolate a curve with Bezier curves 1094 1095 Interpolates a polygon piecewise with cubic Bezier curves 1096 and returns the 2 control points of each curve as QLineF. 1097 1098 \param points Control points 1099 \return Control points of the interpolating Bezier curves 1100 */ 1101 QVector< QLineF > QwtSplineC1::bezierControlLines( const QPolygonF& points ) const 1102 { 1103 using namespace QwtSplineC1P; 1104 1105 const int n = points.size(); 1106 if ( n <= 2 ) 1107 return QVector< QLineF >(); 1108 1109 ControlPointsStore store; 1110 switch( parametrization()->type() ) 1111 { 1112 case QwtSplineParametrization::ParameterX: 1113 { 1114 store = qwtSplineC1PathParamX< ControlPointsStore >( this, points ); 1115 break; 1116 } 1117 case QwtSplineParametrization::ParameterY: 1118 { 1119 store = qwtSplineC1PathParamY< ControlPointsStore >( this, points ); 1120 break; 1121 } 1122 case QwtSplineParametrization::ParameterUniform: 1123 { 1124 store = qwtSplineC1PathParametric< ControlPointsStore >( 1125 this, points, paramUniform() ); 1126 break; 1127 } 1128 case QwtSplineParametrization::ParameterCentripetal: 1129 { 1130 store = qwtSplineC1PathParametric< ControlPointsStore >( 1131 this, points, paramCentripetal() ); 1132 break; 1133 } 1134 case QwtSplineParametrization::ParameterChordal: 1135 { 1136 store = qwtSplineC1PathParametric< ControlPointsStore >( 1137 this, points, paramChordal() ); 1138 break; 1139 } 1140 default: 1141 { 1142 store = qwtSplineC1PathParametric< ControlPointsStore >( 1143 this, points, param( parametrization() ) ); 1144 } 1145 } 1146 1147 return store.controlPoints; 1148 } 1149 1150 /*! 1151 \brief Find an interpolated polygon with "equidistant" points 1152 1153 The implementation is optimzed for non parametric curves 1154 ( QwtSplineParametrization::ParameterX ) and falls back to 1155 QwtSpline::equidistantPolygon() otherwise. 1156 1157 \param points Control nodes of the spline 1158 \param distance Distance between 2 points according 1159 to the parametrization 1160 \param withNodes When true, also add the control 1161 nodes ( even if not being equidistant ) 1162 1163 \return Interpolating polygon 1164 1165 \sa QwtSpline::equidistantPolygon() 1166 */ 1167 QPolygonF QwtSplineC1::equidistantPolygon( const QPolygonF& points, 1168 double distance, bool withNodes ) const 1169 { 1170 if ( parametrization()->type() == QwtSplineParametrization::ParameterX ) 1171 { 1172 if ( points.size() > 2 ) 1173 { 1174 const QVector< double > m = slopes( points ); 1175 if ( m.size() != points.size() ) 1176 return QPolygonF(); 1177 1178 return qwtPolygonParametric< QwtSplinePolynomial::fromSlopes >( 1179 distance, points, m, withNodes ); 1180 } 1181 } 1182 1183 return QwtSplineInterpolating::equidistantPolygon( points, distance, withNodes ); 1184 } 1185 1186 /*! 1187 \brief Calculate the interpolating polynomials for a non parametric spline 1188 1189 C1 spline interpolations are based on finding values for the first 1190 derivates at the control points. The interpolating polynomials can 1191 be calculated from the the first derivates using QwtSplinePolynomial::fromSlopes(). 1192 1193 The default implementation is a two pass calculation. In derived classes it 1194 might be overloaded by a one pass implementation. 1195 1196 \param points Control points 1197 \return Interpolating polynomials 1198 1199 \note The x coordinates need to be increasing or decreasing 1200 */ 1201 QVector< QwtSplinePolynomial > QwtSplineC1::polynomials( 1202 const QPolygonF& points ) const 1203 { 1204 QVector< QwtSplinePolynomial > polynomials; 1205 1206 const QVector< double > m = slopes( points ); 1207 if ( m.size() < 2 ) 1208 return polynomials; 1209 1210 polynomials.reserve( m.size() - 1 ); 1211 for ( int i = 1; i < m.size(); i++ ) 1212 { 1213 polynomials += QwtSplinePolynomial::fromSlopes( 1214 points[i - 1], m[i - 1], points[i], m[i] ); 1215 } 1216 1217 return polynomials; 1218 } 1219 1220 /*! 1221 \brief Constructor 1222 1223 The default setting is a non closing spline with no parametrization 1224 ( QwtSplineParametrization::ParameterX ). 1225 1226 \sa QwtSpline::setParametrization(), QwtSpline::setBoundaryType() 1227 */ 1228 QwtSplineC2::QwtSplineC2() 1229 { 1230 } 1231 1232 //! Destructor 1233 QwtSplineC2::~QwtSplineC2() 1234 { 1235 } 1236 1237 /*! 1238 \brief Interpolate a curve with Bezier curves 1239 1240 Interpolates a polygon piecewise with cubic Bezier curves 1241 and returns them as QPainterPath. 1242 1243 \param points Control points 1244 \return Painter path, that can be rendered by QPainter 1245 1246 \note The implementation simply calls QwtSplineC1::painterPath(), but is 1247 intended to be replaced by a one pass calculation some day. 1248 */ 1249 QPainterPath QwtSplineC2::painterPath( const QPolygonF& points ) const 1250 { 1251 // could be implemented from curvatures without the extra 1252 // loop for calculating the slopes vector. TODO ... 1253 1254 return QwtSplineC1::painterPath( points ); 1255 } 1256 1257 /*! 1258 \brief Interpolate a curve with Bezier curves 1259 1260 Interpolates a polygon piecewise with cubic Bezier curves 1261 and returns the 2 control points of each curve as QLineF. 1262 1263 \param points Control points 1264 \return Control points of the interpolating Bezier curves 1265 1266 \note The implementation simply calls QwtSplineC1::bezierControlLines(), 1267 but is intended to be replaced by a more efficient implementation 1268 that builds the polynomials by the curvatures some day. 1269 */ 1270 QVector< QLineF > QwtSplineC2::bezierControlLines( const QPolygonF& points ) const 1271 { 1272 // could be implemented from curvatures without the extra 1273 // loop for calculating the slopes vector. TODO ... 1274 1275 return QwtSplineC1::bezierControlLines( points ); 1276 } 1277 1278 /*! 1279 \brief Find an interpolated polygon with "equidistant" points 1280 1281 The implementation is optimzed for non parametric curves 1282 ( QwtSplineParametrization::ParameterX ) and falls back to 1283 QwtSpline::equidistantPolygon() otherwise. 1284 1285 \param points Control nodes of the spline 1286 \param distance Distance between 2 points according 1287 to the parametrization 1288 \param withNodes When true, also add the control 1289 nodes ( even if not being equidistant ) 1290 1291 \return Interpolating polygon 1292 1293 \sa QwtSpline::equidistantPolygon() 1294 */ 1295 QPolygonF QwtSplineC2::equidistantPolygon( const QPolygonF& points, 1296 double distance, bool withNodes ) const 1297 { 1298 if ( parametrization()->type() == QwtSplineParametrization::ParameterX ) 1299 { 1300 if ( points.size() > 2 ) 1301 { 1302 const QVector< double > cv = curvatures( points ); 1303 if ( cv.size() != points.size() ) 1304 return QPolygonF(); 1305 1306 return qwtPolygonParametric< QwtSplinePolynomial::fromCurvatures >( 1307 distance, points, cv, withNodes ); 1308 } 1309 } 1310 1311 return QwtSplineInterpolating::equidistantPolygon( points, distance, withNodes ); 1312 } 1313 1314 /*! \fn QVector<double> QwtSplineC2::curvatures( const QPolygonF &points ) const 1315 1316 \brief Find the second derivative at the control points 1317 1318 \param points Control nodes of the spline 1319 \return Vector with the values of the 2nd derivate at the control points 1320 1321 \sa slopes() 1322 \note The x coordinates need to be increasing or decreasing 1323 */ 1324 1325 /*! 1326 \brief Find the first derivative at the control points 1327 1328 An implementation calculating the 2nd derivatives and then building 1329 the slopes in a 2nd loop. QwtSplineCubic overloads it with a more 1330 performant implementation doing it in one loop. 1331 1332 \param points Control nodes of the spline 1333 \return Vector with the values of the 1nd derivate at the control points 1334 1335 \sa curvatures() 1336 1337 \note The x coordinates need to be increasing or decreasing 1338 */ 1339 QVector< double > QwtSplineC2::slopes( const QPolygonF& points ) const 1340 { 1341 const QVector< double > curvatures = this->curvatures( points ); 1342 if ( curvatures.size() < 2 ) 1343 return QVector< double >(); 1344 1345 QVector< double > slopes( curvatures.size() ); 1346 1347 const double* cv = curvatures.constData(); 1348 double* m = slopes.data(); 1349 1350 const int n = points.size(); 1351 const QPointF* p = points.constData(); 1352 1353 QwtSplinePolynomial polynomial; 1354 1355 for ( int i = 0; i < n - 1; i++ ) 1356 { 1357 polynomial = QwtSplinePolynomial::fromCurvatures( p[i], cv[i], p[i + 1], cv[i + 1] ); 1358 m[i] = polynomial.c1; 1359 } 1360 1361 m[n - 1] = polynomial.slopeAt( p[n - 1].x() - p[n - 2].x() ); 1362 1363 return slopes; 1364 } 1365 1366 /*! 1367 \brief Calculate the interpolating polynomials for a non parametric spline 1368 1369 C2 spline interpolations are based on finding values for the second 1370 derivates of f at the control points. The interpolating polynomials can 1371 be calculated from the the second derivates using QwtSplinePolynomial::fromCurvatures. 1372 1373 The default implementation is a 2 pass calculation. In derived classes it 1374 might be overloaded by a one pass implementation. 1375 1376 \param points Control points 1377 \return Interpolating polynomials 1378 1379 \note The x coordinates need to be increasing or decreasing 1380 */ 1381 QVector< QwtSplinePolynomial > QwtSplineC2::polynomials( const QPolygonF& points ) const 1382 { 1383 QVector< QwtSplinePolynomial > polynomials; 1384 1385 const QVector< double > curvatures = this->curvatures( points ); 1386 if ( curvatures.size() < 2 ) 1387 return polynomials; 1388 1389 const QPointF* p = points.constData(); 1390 const double* cv = curvatures.constData(); 1391 const int n = curvatures.size(); 1392 polynomials.reserve( n - 1 ); 1393 1394 for ( int i = 1; i < n; i++ ) 1395 { 1396 polynomials += QwtSplinePolynomial::fromCurvatures( 1397 p[i - 1], cv[i - 1], p[i], cv[i] ); 1398 } 1399 1400 return polynomials; 1401 } -
trunk/BNC/qwt/qwt_spline.h
r4271 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include <qpolygon.h> 15 #include <qvector.h> 16 17 /*! 18 \brief A class for spline interpolation 19 20 The QwtSpline class is used for cubical spline interpolation. 21 Two types of splines, natural and periodic, are supported. 22 23 \par Usage: 24 <ol> 25 <li>First call setPoints() to determine the spline coefficients 26 for a tabulated function y(x). 27 <li>After the coefficients have been set up, the interpolated 28 function value for an argument x can be determined by calling 29 QwtSpline::value(). 30 </ol> 31 32 \par Example: 33 \code 34 #include <qwt_spline.h> 35 36 QPolygonF interpolate(const QPolygonF& points, int numValues) 37 { 38 QwtSpline spline; 39 if ( !spline.setPoints(points) ) 40 return points; 41 42 QPolygonF interpolatedPoints(numValues); 43 44 const double delta = 45 (points[numPoints - 1].x() - points[0].x()) / (points.size() - 1); 46 for(i = 0; i < points.size(); i++) / interpolate 14 #include "qwt_spline.h" 15 16 class QwtSplineParametrization; 17 class QwtSplinePolynomial; 18 class QPainterPath; 19 class QLineF; 20 class QPolygonF; 21 22 #if QT_VERSION < 0x060000 23 template< typename T > class QVector; 24 #endif 25 26 /*! 27 \brief Base class for all splines 28 29 A spline is a curve represented by a sequence of polynomials. Spline approximation 30 is the process of finding polynomials for a given set of points. 31 When the algorithm preserves the initial points it is called interpolating. 32 33 Splines can be classified according to conditions of the polynomials that 34 are met at the start/endpoints of the pieces: 35 36 - Geometric Continuity 37 38 - G0: polynomials are joined 39 - G1: first derivatives are proportional at the join point 40 The curve tangents thus have the same direction, but not necessarily the 41 same magnitude. i.e., C1'(1) = (a,b,c) and C2'(0) = (k*a, k*b, k*c). 42 - G2: first and second derivatives are proportional at join point 43 44 - Parametric Continuity 45 46 - C0: curves are joined 47 - C1: first derivatives equal 48 - C2: first and second derivatives are equal 49 50 Geometric continuity requires the geometry to be continuous, while parametric 51 continuity requires that the underlying parameterization be continuous as well. 52 Parametric continuity of order n implies geometric continuity of order n, 53 but not vice-versa. 54 55 QwtSpline is the base class for spline approximations of any continuity. 56 */ 57 class QWT_EXPORT QwtSpline 58 { 59 public: 60 /*! 61 Boundary type specifying the spline at its endpoints 62 63 \sa setBoundaryType(), boundaryType() 64 */ 65 enum BoundaryType 47 66 { 48 const double x = points[0].x() + i * delta; 49 interpolatedPoints[i].setX(x); 50 interpolatedPoints[i].setY(spline.value(x)); 51 } 52 return interpolatedPoints; 53 } 54 \endcode 55 */ 56 57 class QWT_EXPORT QwtSpline 58 { 59 public: 60 //! Spline type 61 enum SplineType 67 /*! 68 The polynomials at the start/endpoint depend on specific conditions 69 70 \sa QwtSpline::BoundaryCondition 71 */ 72 ConditionalBoundaries, 73 74 /*! 75 The polynomials at the start/endpoint are found by using 76 imaginary additional points. Additional points at the end 77 are found by translating points from the beginning or v.v. 78 */ 79 PeriodicPolygon, 80 81 /*! 82 ClosedPolygon is similar to PeriodicPolygon beside, that 83 the interpolation includes the connection between the last 84 and the first control point. 85 86 \note Only works for parametrizations, where the parameter increment 87 for the the final closing line is positive. 88 This excludes QwtSplineParametrization::ParameterX and 89 QwtSplineParametrization::ParameterY 90 */ 91 92 ClosedPolygon 93 }; 94 95 /*! 96 position of a boundary condition 97 \sa boundaryCondition(), boundaryValue() 98 */ 99 enum BoundaryPosition 62 100 { 63 //! A natural spline64 Natural,65 66 //! A periodic spline67 Periodic101 //! the condition is at the beginning of the polynomial 102 AtBeginning, 103 104 //! the condition is at the end of the polynomial 105 AtEnd 68 106 }; 69 107 108 /*! 109 \brief Boundary condition 110 111 A spline algorithm calculates polynomials by looking 112 a couple of points back/ahead ( locality() ). At the ends 113 additional rules are necessary to compensate the missing 114 points. 115 116 \sa boundaryCondition(), boundaryValue() 117 \sa QwtSplineC2::BoundaryConditionC2 118 */ 119 enum BoundaryCondition 120 { 121 /*! 122 The first derivative at the end point is given 123 \sa boundaryValue() 124 */ 125 Clamped1, 126 127 /*! 128 The second derivative at the end point is given 129 130 \sa boundaryValue() 131 \note a condition having a second derivative of 0 132 is also called "natural". 133 */ 134 Clamped2, 135 136 /*! 137 The third derivative at the end point is given 138 139 \sa boundaryValue() 140 \note a condition having a third derivative of 0 141 is also called "parabolic runout". 142 */ 143 Clamped3, 144 145 /*! 146 The first derivate at the endpoint is related to the first derivative 147 at its neighbour by the boundary value. F,e when the boundary 148 value at the end is 1.0 then the slope at the last 2 points is 149 the same. 150 151 \sa boundaryValue(). 152 */ 153 LinearRunout 154 }; 155 70 156 QwtSpline(); 71 QwtSpline( const QwtSpline &);72 73 ~QwtSpline();74 75 QwtSpline &operator=(const QwtSpline& );76 77 void set SplineType( SplineType );78 SplineType splineType() const;79 80 bool setPoints( const QPolygonF& points);81 QPolygonF points() const;82 83 void reset();84 85 bool isValid() const; 86 double value( double x ) const;87 88 const QVector<double> &coefficientsA() const; 89 const Q Vector<double> &coefficientsB() const;90 const Q Vector<double> &coefficientsC() const;91 92 protected: 93 bool buildNaturalSpline( const QPolygonF & ); 94 bool buildPeriodicSpline( const QPolygonF & );95 96 private: 157 virtual ~QwtSpline(); 158 159 void setParametrization( int type ); 160 void setParametrization( QwtSplineParametrization* ); 161 const QwtSplineParametrization* parametrization() const; 162 163 void setBoundaryType( BoundaryType ); 164 BoundaryType boundaryType() const; 165 166 void setBoundaryValue( BoundaryPosition, double value ); 167 double boundaryValue( BoundaryPosition ) const; 168 169 void setBoundaryCondition( BoundaryPosition, int condition ); 170 int boundaryCondition( BoundaryPosition ) const; 171 172 void setBoundaryConditions( int condition, 173 double valueBegin = 0.0, double valueEnd = 0.0 ); 174 175 virtual QPolygonF polygon( const QPolygonF&, double tolerance ) const; 176 virtual QPainterPath painterPath( const QPolygonF& ) const = 0; 177 178 virtual uint locality() const; 179 180 private: 181 Q_DISABLE_COPY(QwtSpline) 182 97 183 class PrivateData; 98 PrivateData *d_data; 184 PrivateData* m_data; 185 }; 186 187 /*! 188 \brief Base class for a spline interpolation 189 190 Spline interpolation is the process of interpolating a set of points 191 piecewise with polynomials. The initial set of points is preserved. 192 */ 193 class QWT_EXPORT QwtSplineInterpolating : public QwtSpline 194 { 195 public: 196 QwtSplineInterpolating(); 197 virtual ~QwtSplineInterpolating(); 198 199 virtual QPolygonF equidistantPolygon( const QPolygonF&, 200 double distance, bool withNodes ) const; 201 202 virtual QPolygonF polygon( 203 const QPolygonF&, double tolerance ) const QWT_OVERRIDE; 204 205 virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE; 206 virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const = 0; 207 208 private: 209 Q_DISABLE_COPY(QwtSplineInterpolating) 210 }; 211 212 /*! 213 \brief Base class for spline interpolations providing a 214 first order geometric continuity ( G1 ) between adjoining curves 215 */ 216 class QWT_EXPORT QwtSplineG1 : public QwtSplineInterpolating 217 { 218 public: 219 QwtSplineG1(); 220 virtual ~QwtSplineG1(); 221 }; 222 223 /*! 224 \brief Base class for spline interpolations providing a 225 first order parametric continuity ( C1 ) between adjoining curves 226 227 All interpolations with C1 continuity are based on rules for finding 228 the 1. derivate at some control points. 229 230 In case of non parametric splines those points are the curve points, while 231 for parametric splines the calculation is done twice using a parameter value t. 232 233 \sa QwtSplineParametrization 234 */ 235 class QWT_EXPORT QwtSplineC1 : public QwtSplineG1 236 { 237 public: 238 QwtSplineC1(); 239 virtual ~QwtSplineC1(); 240 241 virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE; 242 virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const QWT_OVERRIDE; 243 244 virtual QPolygonF equidistantPolygon( const QPolygonF&, 245 double distance, bool withNodes ) const QWT_OVERRIDE; 246 247 // these methods are the non parametric part 248 virtual QVector< QwtSplinePolynomial > polynomials( const QPolygonF& ) const; 249 virtual QVector< double > slopes( const QPolygonF& ) const = 0; 250 251 virtual double slopeAtBeginning( const QPolygonF&, double slopeNext ) const; 252 virtual double slopeAtEnd( const QPolygonF&, double slopeBefore ) const; 253 }; 254 255 /*! 256 \brief Base class for spline interpolations providing a 257 second order parametric continuity ( C2 ) between adjoining curves 258 259 All interpolations with C2 continuity are based on rules for finding 260 the 2. derivate at some control points. 261 262 In case of non parametric splines those points are the curve points, while 263 for parametric splines the calculation is done twice using a parameter value t. 264 265 \sa QwtSplineParametrization 266 */ 267 class QWT_EXPORT QwtSplineC2 : public QwtSplineC1 268 { 269 public: 270 /*! 271 Boundary condition that requires C2 continuity 272 273 \sa QwtSpline::boundaryCondition, QwtSpline::BoundaryCondition 274 */ 275 enum BoundaryConditionC2 276 { 277 /*! 278 The second derivate at the endpoint is related to the second derivatives 279 at the 2 neighbours: cv[0] := 2.0 * cv[1] - cv[2]. 280 281 \note boundaryValue() is ignored 282 */ 283 CubicRunout = LinearRunout + 1, 284 285 /*! 286 The 3rd derivate at the endpoint matches the 3rd derivate at its neighbours. 287 Or in other words: the first/last curve segment extents the polynomial of its 288 neighboured polynomial 289 290 \note boundaryValue() is ignored 291 */ 292 NotAKnot 293 }; 294 295 QwtSplineC2(); 296 virtual ~QwtSplineC2(); 297 298 virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE; 299 virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const QWT_OVERRIDE; 300 301 virtual QPolygonF equidistantPolygon( const QPolygonF&, 302 double distance, bool withNodes ) const QWT_OVERRIDE; 303 304 // calculating the parametric equations 305 virtual QVector< QwtSplinePolynomial > polynomials( const QPolygonF& ) const QWT_OVERRIDE; 306 virtual QVector< double > slopes( const QPolygonF& ) const QWT_OVERRIDE; 307 virtual QVector< double > curvatures( const QPolygonF& ) const = 0; 99 308 }; 100 309 -
trunk/BNC/qwt/qwt_symbol.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_painter.h" 12 12 #include "qwt_graphic.h" 13 #include <qapplication.h> 13 #include "qwt_math.h" 14 14 15 #include <qpainter.h> 15 16 #include <qpainterpath.h> 16 17 #include <qpixmap.h> 17 18 #include <qpaintengine.h> 18 #include <qmath.h>19 19 #ifndef QWT_NO_SVG 20 20 #include <qsvgrenderer.h> … … 32 32 } 33 33 34 static QwtGraphic qwtPathGraphic( const QPainterPath &path,35 const QPen &pen, const QBrush& brush )34 static QwtGraphic qwtPathGraphic( const QPainterPath& path, 35 const QPen& pen, const QBrush& brush ) 36 36 { 37 37 QwtGraphic graphic; … … 48 48 49 49 static inline QRectF qwtScaledBoundingRect( 50 const QwtGraphic &graphic, const QSizeF size )50 const QwtGraphic& graphic, const QSizeF size ) 51 51 { 52 52 QSizeF scaledSize = size; … … 67 67 } 68 68 69 static inline void qwtDrawPixmapSymbols( QPainter *painter,70 const QPointF *points, int numPoints, const QwtSymbol&symbol )69 static inline void qwtDrawPixmapSymbols( QPainter* painter, 70 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 71 71 { 72 72 QSize size = symbol.size(); … … 102 102 #ifndef QWT_NO_SVG 103 103 104 static inline void qwtDrawSvgSymbols( QPainter *painter,105 const QPointF *points, int numPoints,106 QSvgRenderer *renderer, const QwtSymbol&symbol )104 static inline void qwtDrawSvgSymbols( QPainter* painter, 105 const QPointF* points, int numPoints, 106 QSvgRenderer* renderer, const QwtSymbol& symbol ) 107 107 { 108 108 if ( renderer == NULL || !renderer->isValid() ) … … 139 139 #endif 140 140 141 static inline void qwtDrawGraphicSymbols( QPainter *painter,142 const QPointF *points, int numPoints, const QwtGraphic&graphic,143 const QwtSymbol &symbol )141 static inline void qwtDrawGraphicSymbols( QPainter* painter, 142 const QPointF* points, int numPoints, const QwtGraphic& graphic, 143 const QwtSymbol& symbol ) 144 144 { 145 145 const QRectF pointRect = graphic.controlPointRect(); … … 178 178 } 179 179 180 static inline void qwtDrawEllipseSymbols( QPainter *painter,181 const QPointF *points, int numPoints, const QwtSymbol&symbol )180 static inline void qwtDrawEllipseSymbols( QPainter* painter, 181 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 182 182 { 183 183 painter->setBrush( symbol.brush() ); … … 220 220 } 221 221 222 static inline void qwtDrawRectSymbols( QPainter *painter,223 const QPointF *points, int numPoints, const QwtSymbol&symbol )222 static inline void qwtDrawRectSymbols( QPainter* painter, 223 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 224 224 { 225 225 const QSize size = symbol.size(); … … 265 265 } 266 266 267 static inline void qwtDrawDiamondSymbols( QPainter *painter,268 const QPointF *points, int numPoints, const QwtSymbol&symbol )267 static inline void qwtDrawDiamondSymbols( QPainter* painter, 268 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 269 269 { 270 270 const QSize size = symbol.size(); … … 300 300 for ( int i = 0; i < numPoints; i++ ) 301 301 { 302 const QPointF &pos = points[i];302 const QPointF& pos = points[i]; 303 303 304 304 const double x1 = pos.x() - 0.5 * size.width(); … … 319 319 320 320 static inline void qwtDrawTriangleSymbols( 321 QPainter *painter, QwtTriangle::Type type,322 const QPointF *points, int numPoints,323 const QwtSymbol &symbol )321 QPainter* painter, QwtTriangle::Type type, 322 const QPointF* points, int numPoints, 323 const QwtSymbol& symbol ) 324 324 { 325 325 const QSize size = symbol.size(); … … 338 338 if ( doAlign ) 339 339 { 340 sw2 = qFloor( sw2 );341 sh2 = qFloor( sh2 );340 sw2 = std::floor( sw2 ); 341 sh2 = std::floor( sh2 ); 342 342 } 343 343 344 344 QPolygonF triangle( 3 ); 345 QPointF *trianglePoints = triangle.data();345 QPointF* trianglePoints = triangle.data(); 346 346 347 347 for ( int i = 0; i < numPoints; i++ ) 348 348 { 349 const QPointF &pos = points[i];349 const QPointF& pos = points[i]; 350 350 351 351 double x = pos.x(); … … 423 423 424 424 static inline void qwtDrawLineSymbols( 425 QPainter *painter, int orientations,426 const QPointF *points, int numPoints, const QwtSymbol&symbol )425 QPainter* painter, int orientations, 426 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 427 427 { 428 428 const QSize size = symbol.size(); … … 442 442 if ( QwtPainter::roundingAlignment( painter ) ) 443 443 { 444 const int sw = qFloor( size.width() ); 445 const int sh = qFloor( size.height() ); 444 const int sw = qwtFloor( size.width() ); 445 const int sh = qwtFloor( size.height() ); 446 446 const int sw2 = size.width() / 2; 447 447 const int sh2 = size.height() / 2; … … 492 492 } 493 493 494 static inline void qwtDrawXCrossSymbols( QPainter *painter,495 const QPointF *points, int numPoints, const QwtSymbol&symbol )494 static inline void qwtDrawXCrossSymbols( QPainter* painter, 495 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 496 496 { 497 497 const QSize size = symbol.size(); … … 516 516 for ( int i = 0; i < numPoints; i++ ) 517 517 { 518 const QPointF &pos = points[i];518 const QPointF& pos = points[i]; 519 519 520 520 const int x = qRound( pos.x() ); … … 539 539 for ( int i = 0; i < numPoints; i++ ) 540 540 { 541 const QPointF &pos = points[i];541 const QPointF& pos = points[i]; 542 542 543 543 const double x1 = pos.x() - sw2; … … 552 552 } 553 553 554 static inline void qwtDrawStar1Symbols( QPainter *painter,555 const QPointF *points, int numPoints, const QwtSymbol&symbol )554 static inline void qwtDrawStar1Symbols( QPainter* painter, 555 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 556 556 { 557 557 const QSize size = symbol.size(); … … 575 575 QwtPainter::drawLine( painter, 576 576 qRound( r.left() + d1 ), qRound( r.bottom() - d1 ), 577 qRound( r .right() - d1), qRound( r.top() + d1 ) );577 qRound( r.right() - d1), qRound( r.top() + d1 ) ); 578 578 579 579 const QPoint c = r.center(); … … 596 596 597 597 const QPointF c = r.center(); 598 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );598 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 ); 599 599 600 600 QwtPainter::drawLine( painter, … … 614 614 } 615 615 616 static inline void qwtDrawStar2Symbols( QPainter *painter,617 const QPointF *points, int numPoints, const QwtSymbol&symbol )616 static inline void qwtDrawStar2Symbols( QPainter* painter, 617 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 618 618 { 619 619 QPen pen = symbol.pen(); … … 631 631 632 632 QPolygonF star( 12 ); 633 QPointF *starPoints = star.data();633 QPointF* starPoints = star.data(); 634 634 635 635 const bool doAlign = QwtPainter::roundingAlignment( painter ); … … 705 705 } 706 706 707 static inline void qwtDrawHexagonSymbols( QPainter *painter,708 const QPointF *points, int numPoints, const QwtSymbol&symbol )707 static inline void qwtDrawHexagonSymbols( QPainter* painter, 708 const QPointF* points, int numPoints, const QwtSymbol& symbol ) 709 709 { 710 710 painter->setBrush( symbol.brush() ); … … 717 717 718 718 QPolygonF hexaPolygon( 6 ); 719 QPointF *hexaPoints = hexaPolygon.data();719 QPointF* hexaPoints = hexaPolygon.data(); 720 720 721 721 const bool doAlign = QwtPainter::roundingAlignment( painter ); … … 735 735 if ( doAlign ) 736 736 { 737 x1 = qCeil( x1 );738 y1 = qCeil( y1 );737 x1 = std::ceil( x1 ); 738 y1 = std::ceil( y1 ); 739 739 } 740 740 … … 770 770 class QwtSymbol::PrivateData 771 771 { 772 public: 773 PrivateData( QwtSymbol::Style st, const QBrush &br,774 const QPen &pn, const QSize&sz ):775 style( st ) ,776 size( sz ) ,777 brush( br ) ,778 pen( pn ) ,779 isPinPointEnabled( false ) 772 public: 773 PrivateData( QwtSymbol::Style st, const QBrush& br, 774 const QPen& pn, const QSize& sz ) 775 : style( st ) 776 , size( sz ) 777 , brush( br ) 778 , pen( pn ) 779 , isPinPointEnabled( false ) 780 780 { 781 781 cache.policy = QwtSymbol::AutoCache; … … 822 822 struct SVG 823 823 { 824 QSvgRenderer *renderer;824 QSvgRenderer* renderer; 825 825 } svg; 826 826 #endif … … 835 835 836 836 /*! 837 Default Constructor 838 \param style Symbol Style 839 840 The symbol is constructed with gray interior, 841 black outline with zero width, no size and style 'NoSymbol'. 842 */ 837 Default Constructor 838 \param style Symbol Style 839 840 The symbol is constructed with gray interior, 841 black outline with zero width, no size and style 'NoSymbol'. 842 */ 843 843 QwtSymbol::QwtSymbol( Style style ) 844 844 { 845 d_data = new PrivateData( style, QBrush( Qt::gray ),845 m_data = new PrivateData( style, QBrush( Qt::gray ), 846 846 QPen( Qt::black, 0 ), QSize() ); 847 847 } 848 848 849 849 /*! 850 \brief Constructor 851 \param style Symbol Style 852 \param brush brush to fill the interior 853 \param pen outline pen 854 \param size size 855 856 \sa setStyle(), setBrush(), setPen(), setSize() 857 */ 858 QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush &brush,859 const QPen &pen, const QSize&size )860 { 861 d_data = new PrivateData( style, brush, pen, size );862 } 863 864 /*! 865 \brief Constructor 866 867 The symbol gets initialized by a painter path. The style is 868 set to QwtSymbol::Path, the size is set to empty ( the path 869 is displayed unscaled ). 870 871 \param path painter path 872 \param brush brush to fill the interior 873 \param pen outline pen 874 875 \sa setPath(), setBrush(), setPen(), setSize() 876 */ 877 878 QwtSymbol::QwtSymbol( const QPainterPath &path,879 const QBrush &brush, const QPen&pen )880 { 881 d_data = new PrivateData( QwtSymbol::Path, brush, pen, QSize() );850 \brief Constructor 851 \param style Symbol Style 852 \param brush brush to fill the interior 853 \param pen outline pen 854 \param size size 855 856 \sa setStyle(), setBrush(), setPen(), setSize() 857 */ 858 QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush& brush, 859 const QPen& pen, const QSize& size ) 860 { 861 m_data = new PrivateData( style, brush, pen, size ); 862 } 863 864 /*! 865 \brief Constructor 866 867 The symbol gets initialized by a painter path. The style is 868 set to QwtSymbol::Path, the size is set to empty ( the path 869 is displayed unscaled ). 870 871 \param path painter path 872 \param brush brush to fill the interior 873 \param pen outline pen 874 875 \sa setPath(), setBrush(), setPen(), setSize() 876 */ 877 878 QwtSymbol::QwtSymbol( const QPainterPath& path, 879 const QBrush& brush, const QPen& pen ) 880 { 881 m_data = new PrivateData( QwtSymbol::Path, brush, pen, QSize() ); 882 882 setPath( path ); 883 883 } … … 886 886 QwtSymbol::~QwtSymbol() 887 887 { 888 delete d_data;889 } 890 891 /*! 892 Change the cache policy 893 894 The default policy is AutoCache 895 896 \param policy Cache policy 897 \sa CachePolicy, cachePolicy() 898 */ 888 delete m_data; 889 } 890 891 /*! 892 Change the cache policy 893 894 The default policy is AutoCache 895 896 \param policy Cache policy 897 \sa CachePolicy, cachePolicy() 898 */ 899 899 void QwtSymbol::setCachePolicy( 900 900 QwtSymbol::CachePolicy policy ) 901 901 { 902 if ( d_data->cache.policy != policy )903 { 904 d_data->cache.policy = policy;902 if ( m_data->cache.policy != policy ) 903 { 904 m_data->cache.policy = policy; 905 905 invalidateCache(); 906 906 } … … 908 908 909 909 /*! 910 \return Cache policy 911 \sa CachePolicy, setCachePolicy() 912 */ 910 \return Cache policy 911 \sa CachePolicy, setCachePolicy() 912 */ 913 913 QwtSymbol::CachePolicy QwtSymbol::cachePolicy() const 914 914 { 915 return d_data->cache.policy;916 } 917 918 /*! 919 \brief Set a painter path as symbol 920 921 The symbol is represented by a painter path, where the 922 origin ( 0, 0 ) of the path coordinate system is mapped to 923 the position of the symbol. 924 925 When the symbol has valid size the painter path gets scaled 926 to fit into the size. Otherwise the symbol size depends on 927 the bounding rectangle of the path. 928 929 \par Example 915 return m_data->cache.policy; 916 } 917 918 /*! 919 \brief Set a painter path as symbol 920 921 The symbol is represented by a painter path, where the 922 origin ( 0, 0 ) of the path coordinate system is mapped to 923 the position of the symbol. 924 925 When the symbol has valid size the painter path gets scaled 926 to fit into the size. Otherwise the symbol size depends on 927 the bounding rectangle of the path. 928 929 \par Example 930 930 The following code defines a symbol drawing an arrow: 931 931 932 932 \code 933 #include <qwt_symbol.h>933 #include <qwt_symbol.h> 934 934 935 935 QwtSymbol *symbol = new QwtSymbol(); … … 958 958 setSize( 10, 14 ); 959 959 \endcode 960 \endpar 961 962 \param path Painter path 963 964 \note The style is implicitely set to QwtSymbol::Path. 965 \sa path(), setSize() 966 */ 967 void QwtSymbol::setPath( const QPainterPath &path ) 968 { 969 d_data->style = QwtSymbol::Path; 970 d_data->path.path = path; 971 d_data->path.graphic.reset(); 960 961 \param path Painter path 962 963 \note The style is implicitly set to QwtSymbol::Path. 964 \sa path(), setSize() 965 */ 966 void QwtSymbol::setPath( const QPainterPath& path ) 967 { 968 m_data->style = QwtSymbol::Path; 969 m_data->path.path = path; 970 m_data->path.graphic.reset(); 972 971 } 973 972 … … 975 974 \return Painter path for displaying the symbol 976 975 \sa setPath() 977 */ 978 const QPainterPath &QwtSymbol::path() const979 { 980 return d_data->path.path;981 } 982 983 /*! 984 Set a pixmap as symbol 985 986 \param pixmap Pixmap 987 988 \sa pixmap(), setGraphic() 989 990 \note the style() is set to QwtSymbol::Pixmap 991 \note brush() and pen() have no effect 992 */ 993 void QwtSymbol::setPixmap( const QPixmap &pixmap )994 { 995 d_data->style = QwtSymbol::Pixmap;996 d_data->pixmap.pixmap = pixmap;997 } 998 999 /*! 1000 \return Assigned pixmap 1001 \sa setPixmap() 1002 */ 1003 const QPixmap &QwtSymbol::pixmap() const1004 { 1005 return d_data->pixmap.pixmap;1006 } 1007 1008 /*! 1009 Set a graphic as symbol 1010 1011 \param graphic Graphic 1012 1013 \sa graphic(), setPixmap() 1014 1015 \note the style() is set to QwtSymbol::Graphic 1016 \note brush() and pen() have no effect 1017 */ 1018 void QwtSymbol::setGraphic( const QwtGraphic &graphic )1019 { 1020 d_data->style = QwtSymbol::Graphic;1021 d_data->graphic.graphic = graphic;1022 } 1023 1024 /*! 1025 \return Assigned graphic 1026 \sa setGraphic() 1027 */ 1028 const QwtGraphic &QwtSymbol::graphic() const1029 { 1030 return d_data->graphic.graphic;976 */ 977 const QPainterPath& QwtSymbol::path() const 978 { 979 return m_data->path.path; 980 } 981 982 /*! 983 Set a pixmap as symbol 984 985 \param pixmap Pixmap 986 987 \sa pixmap(), setGraphic() 988 989 \note the style() is set to QwtSymbol::Pixmap 990 \note brush() and pen() have no effect 991 */ 992 void QwtSymbol::setPixmap( const QPixmap& pixmap ) 993 { 994 m_data->style = QwtSymbol::Pixmap; 995 m_data->pixmap.pixmap = pixmap; 996 } 997 998 /*! 999 \return Assigned pixmap 1000 \sa setPixmap() 1001 */ 1002 const QPixmap& QwtSymbol::pixmap() const 1003 { 1004 return m_data->pixmap.pixmap; 1005 } 1006 1007 /*! 1008 Set a graphic as symbol 1009 1010 \param graphic Graphic 1011 1012 \sa graphic(), setPixmap() 1013 1014 \note the style() is set to QwtSymbol::Graphic 1015 \note brush() and pen() have no effect 1016 */ 1017 void QwtSymbol::setGraphic( const QwtGraphic& graphic ) 1018 { 1019 m_data->style = QwtSymbol::Graphic; 1020 m_data->graphic.graphic = graphic; 1021 } 1022 1023 /*! 1024 \return Assigned graphic 1025 \sa setGraphic() 1026 */ 1027 const QwtGraphic& QwtSymbol::graphic() const 1028 { 1029 return m_data->graphic.graphic; 1031 1030 } 1032 1031 … … 1034 1033 1035 1034 /*! 1036 Set a SVG icon as symbol 1037 1038 \param svgDocument SVG icon 1039 1040 \sa setGraphic(), setPixmap() 1041 1042 \note the style() is set to QwtSymbol::SvgDocument 1043 \note brush() and pen() have no effect 1044 */ 1045 void QwtSymbol::setSvgDocument( const QByteArray &svgDocument )1046 { 1047 d_data->style = QwtSymbol::SvgDocument;1048 if ( d_data->svg.renderer == NULL )1049 d_data->svg.renderer = new QSvgRenderer();1050 1051 d_data->svg.renderer->load( svgDocument );1035 Set a SVG icon as symbol 1036 1037 \param svgDocument SVG icon 1038 1039 \sa setGraphic(), setPixmap() 1040 1041 \note the style() is set to QwtSymbol::SvgDocument 1042 \note brush() and pen() have no effect 1043 */ 1044 void QwtSymbol::setSvgDocument( const QByteArray& svgDocument ) 1045 { 1046 m_data->style = QwtSymbol::SvgDocument; 1047 if ( m_data->svg.renderer == NULL ) 1048 m_data->svg.renderer = new QSvgRenderer(); 1049 1050 m_data->svg.renderer->load( svgDocument ); 1052 1051 } 1053 1052 … … 1055 1054 1056 1055 /*! 1057 \brief Specify the symbol's size 1058 1059 If the 'h' parameter is left out or less than 0, 1060 and the 'w' parameter is greater than or equal to 0, 1061 the symbol size will be set to (w,w). 1062 1063 \param width Width 1064 \param height Height (defaults to -1) 1065 1066 \sa size() 1067 */ 1056 \brief Specify the symbol's size 1057 1058 If the 'h' parameter is left out or less than 0, 1059 and the 'w' parameter is greater than or equal to 0, 1060 the symbol size will be set to (w,w). 1061 1062 \param width Width 1063 \param height Height (defaults to -1) 1064 1065 \sa size() 1066 */ 1068 1067 void QwtSymbol::setSize( int width, int height ) 1069 1068 { … … 1079 1078 1080 1079 \sa size() 1081 */ 1082 void QwtSymbol::setSize( const QSize &size )1083 { 1084 if ( size.isValid() && size != d_data->size )1085 { 1086 d_data->size = size;1080 */ 1081 void QwtSymbol::setSize( const QSize& size ) 1082 { 1083 if ( size.isValid() && size != m_data->size ) 1084 { 1085 m_data->size = size; 1087 1086 invalidateCache(); 1088 1087 } … … 1092 1091 \return Size 1093 1092 \sa setSize() 1094 */ 1093 */ 1095 1094 const QSize& QwtSymbol::size() const 1096 1095 { 1097 return d_data->size;1098 } 1099 1100 /*! 1101 \brief Assign a brush 1102 1103 The brush is used to draw the interior of the symbol. 1104 \param brush Brush 1105 1106 \sa brush() 1107 */ 1108 void QwtSymbol::setBrush( const QBrush &brush )1109 { 1110 if ( brush != d_data->brush )1111 { 1112 d_data->brush = brush;1096 return m_data->size; 1097 } 1098 1099 /*! 1100 \brief Assign a brush 1101 1102 The brush is used to draw the interior of the symbol. 1103 \param brush Brush 1104 1105 \sa brush() 1106 */ 1107 void QwtSymbol::setBrush( const QBrush& brush ) 1108 { 1109 if ( brush != m_data->brush ) 1110 { 1111 m_data->brush = brush; 1113 1112 invalidateCache(); 1114 1113 1115 if ( d_data->style == QwtSymbol::Path )1116 d_data->path.graphic.reset();1117 } 1118 } 1119 1120 /*! 1121 \return Brush 1122 \sa setBrush() 1123 */ 1114 if ( m_data->style == QwtSymbol::Path ) 1115 m_data->path.graphic.reset(); 1116 } 1117 } 1118 1119 /*! 1120 \return Brush 1121 \sa setBrush() 1122 */ 1124 1123 const QBrush& QwtSymbol::brush() const 1125 1124 { 1126 return d_data->brush;1127 } 1128 1129 /*! 1130 Build and assign a pen 1131 1132 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) 1133 what makes it non cosmetic ( see QPen::isCosmetic() ). 1134 This method has been introduced to hide this incompatibility. 1135 1136 \param color Pen color 1137 \param width Pen width 1138 \param style Pen style 1139 1140 \sa pen(), brush() 1141 */ 1142 void QwtSymbol::setPen( const QColor &color,1125 return m_data->brush; 1126 } 1127 1128 /*! 1129 Build and assign a pen 1130 1131 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) 1132 what makes it non cosmetic ( see QPen::isCosmetic() ). 1133 This method has been introduced to hide this incompatibility. 1134 1135 \param color Pen color 1136 \param width Pen width 1137 \param style Pen style 1138 1139 \sa pen(), brush() 1140 */ 1141 void QwtSymbol::setPen( const QColor& color, 1143 1142 qreal width, Qt::PenStyle style ) 1144 1143 { … … 1147 1146 1148 1147 /*! 1149 Assign a pen 1150 1151 The pen is used to draw the symbol's outline. 1152 1153 \param pen Pen 1154 \sa pen(), setBrush() 1155 */ 1156 void QwtSymbol::setPen( const QPen &pen )1157 { 1158 if ( pen != d_data->pen )1159 { 1160 d_data->pen = pen;1148 Assign a pen 1149 1150 The pen is used to draw the symbol's outline. 1151 1152 \param pen Pen 1153 \sa pen(), setBrush() 1154 */ 1155 void QwtSymbol::setPen( const QPen& pen ) 1156 { 1157 if ( pen != m_data->pen ) 1158 { 1159 m_data->pen = pen; 1161 1160 invalidateCache(); 1162 1161 1163 if ( d_data->style == QwtSymbol::Path )1164 d_data->path.graphic.reset();1165 } 1166 } 1167 1168 /*! 1169 \return Pen 1170 \sa setPen(), brush() 1171 */ 1162 if ( m_data->style == QwtSymbol::Path ) 1163 m_data->path.graphic.reset(); 1164 } 1165 } 1166 1167 /*! 1168 \return Pen 1169 \sa setPen(), brush() 1170 */ 1172 1171 const QPen& QwtSymbol::pen() const 1173 1172 { 1174 return d_data->pen;1175 } 1176 1177 /*! 1178 \brief Set the color of the symbol 1179 1180 Change the color of the brush for symbol types with a filled area. 1181 For all other symbol types the color will be assigned to the pen. 1182 1183 \param color Color 1184 1185 \sa setBrush(), setPen(), brush(), pen() 1186 */ 1187 void QwtSymbol::setColor( const QColor &color )1188 { 1189 switch ( d_data->style )1173 return m_data->pen; 1174 } 1175 1176 /*! 1177 \brief Set the color of the symbol 1178 1179 Change the color of the brush for symbol types with a filled area. 1180 For all other symbol types the color will be assigned to the pen. 1181 1182 \param color Color 1183 1184 \sa setBrush(), setPen(), brush(), pen() 1185 */ 1186 void QwtSymbol::setColor( const QColor& color ) 1187 { 1188 switch ( m_data->style ) 1190 1189 { 1191 1190 case QwtSymbol::Ellipse: … … 1200 1199 case QwtSymbol::Hexagon: 1201 1200 { 1202 if ( d_data->brush.color() != color )1201 if ( m_data->brush.color() != color ) 1203 1202 { 1204 d_data->brush.setColor( color );1203 m_data->brush.setColor( color ); 1205 1204 invalidateCache(); 1206 1205 } … … 1213 1212 case QwtSymbol::Star1: 1214 1213 { 1215 if ( d_data->pen.color() != color )1214 if ( m_data->pen.color() != color ) 1216 1215 { 1217 d_data->pen.setColor( color );1216 m_data->pen.setColor( color ); 1218 1217 invalidateCache(); 1219 1218 } … … 1222 1221 default: 1223 1222 { 1224 if ( d_data->brush.color() != color ||1225 d_data->pen.color() != color )1223 if ( m_data->brush.color() != color || 1224 m_data->pen.color() != color ) 1226 1225 { 1227 1226 invalidateCache(); 1228 1227 } 1229 1228 1230 d_data->brush.setColor( color );1231 d_data->pen.setColor( color );1232 } 1233 } 1234 } 1235 1236 /*! 1237 \brief Set and enable a pin point 1238 1239 The position of a complex symbol is not always aligned to its center 1240 ( f.e an arrow, where the peak points to a position ). The pin point 1241 defines the position inside of a Pixmap, Graphic, SvgDocument 1242 or PainterPath symbol where the represented point has to 1243 be aligned to. 1244 1245 \param pos Position 1246 \param enable En/Disable the pin point alignment 1247 1248 \sa pinPoint(), setPinPointEnabled() 1249 */ 1250 void QwtSymbol::setPinPoint( const QPointF &pos, bool enable )1251 { 1252 if ( d_data->pinPoint != pos )1253 { 1254 d_data->pinPoint = pos;1255 if ( d_data->isPinPointEnabled )1229 m_data->brush.setColor( color ); 1230 m_data->pen.setColor( color ); 1231 } 1232 } 1233 } 1234 1235 /*! 1236 \brief Set and enable a pin point 1237 1238 The position of a complex symbol is not always aligned to its center 1239 ( f.e an arrow, where the peak points to a position ). The pin point 1240 defines the position inside of a Pixmap, Graphic, SvgDocument 1241 or PainterPath symbol where the represented point has to 1242 be aligned to. 1243 1244 \param pos Position 1245 \param enable En/Disable the pin point alignment 1246 1247 \sa pinPoint(), setPinPointEnabled() 1248 */ 1249 void QwtSymbol::setPinPoint( const QPointF& pos, bool enable ) 1250 { 1251 if ( m_data->pinPoint != pos ) 1252 { 1253 m_data->pinPoint = pos; 1254 if ( m_data->isPinPointEnabled ) 1256 1255 { 1257 1256 invalidateCache(); … … 1263 1262 1264 1263 /*! 1265 \return Pin point 1266 \sa setPinPoint(), setPinPointEnabled() 1264 \return Pin point 1265 \sa setPinPoint(), setPinPointEnabled() 1267 1266 */ 1268 1267 QPointF QwtSymbol::pinPoint() const 1269 1268 { 1270 return d_data->pinPoint;1271 } 1272 1273 /*! 1274 En/Disable the pin point alignment 1275 1276 \param on Enabled, when on is true 1277 \sa setPinPoint(), isPinPointEnabled() 1269 return m_data->pinPoint; 1270 } 1271 1272 /*! 1273 En/Disable the pin point alignment 1274 1275 \param on Enabled, when on is true 1276 \sa setPinPoint(), isPinPointEnabled() 1278 1277 */ 1279 1278 void QwtSymbol::setPinPointEnabled( bool on ) 1280 1279 { 1281 if ( d_data->isPinPointEnabled != on )1282 { 1283 d_data->isPinPointEnabled = on;1280 if ( m_data->isPinPointEnabled != on ) 1281 { 1282 m_data->isPinPointEnabled = on; 1284 1283 invalidateCache(); 1285 1284 } … … 1287 1286 1288 1287 /*! 1289 \return True, when the pin point translation is enabled 1290 \sa setPinPoint(), setPinPointEnabled() 1288 \return True, when the pin point translation is enabled 1289 \sa setPinPoint(), setPinPointEnabled() 1291 1290 */ 1292 1291 bool QwtSymbol::isPinPointEnabled() const 1293 1292 { 1294 return d_data->isPinPointEnabled;1295 } 1296 1297 /*! 1298 Render an array of symbols 1299 1300 Painting several symbols is more effective than drawing symbols 1301 one by one, as a couple of layout calculations and setting of pen/brush 1302 can be done once for the complete array. 1303 1304 \param painter Painter 1305 \param points Array of points 1306 \param numPoints Number of points 1307 */ 1308 void QwtSymbol::drawSymbols( QPainter *painter,1309 const QPointF *points, int numPoints ) const1293 return m_data->isPinPointEnabled; 1294 } 1295 1296 /*! 1297 Render an array of symbols 1298 1299 Painting several symbols is more effective than drawing symbols 1300 one by one, as a couple of layout calculations and setting of pen/brush 1301 can be done once for the complete array. 1302 1303 \param painter Painter 1304 \param points Array of points 1305 \param numPoints Number of points 1306 */ 1307 void QwtSymbol::drawSymbols( QPainter* painter, 1308 const QPointF* points, int numPoints ) const 1310 1309 { 1311 1310 if ( numPoints <= 0 ) … … 1320 1319 !painter->transform().isScaling() ) 1321 1320 { 1322 if ( d_data->cache.policy == QwtSymbol::Cache )1321 if ( m_data->cache.policy == QwtSymbol::Cache ) 1323 1322 { 1324 1323 useCache = true; 1325 1324 } 1326 else if ( d_data->cache.policy == QwtSymbol::AutoCache )1327 { 1328 if( painter->paintEngine()->type()== QPaintEngine::Raster)1325 else if ( m_data->cache.policy == QwtSymbol::AutoCache ) 1326 { 1327 switch( painter->paintEngine()->type() ) 1329 1328 { 1330 useCache = true; 1331 } 1332 else 1333 { 1334 switch( d_data->style ) 1329 case QPaintEngine::OpenGL: 1330 case QPaintEngine::OpenGL2: 1335 1331 { 1336 case QwtSymbol::XCross: 1337 case QwtSymbol::HLine: 1338 case QwtSymbol::VLine: 1339 case QwtSymbol::Cross: 1340 break; 1341 1342 case QwtSymbol::Pixmap: 1332 // using a FBO as cache ? 1333 useCache = false; 1334 break; 1335 } 1336 case QPaintEngine::OpenVG: 1337 case QPaintEngine::SVG: 1338 case QPaintEngine::Pdf: 1339 case QPaintEngine::Picture: 1340 { 1341 // vector graphics 1342 useCache = false; 1343 break; 1344 } 1345 case QPaintEngine::X11: 1346 { 1347 switch( m_data->style ) 1343 1348 { 1344 if ( !d_data->size.isEmpty() && 1345 d_data->size != d_data->pixmap.pixmap.size() ) 1349 case QwtSymbol::XCross: 1350 case QwtSymbol::HLine: 1351 case QwtSymbol::VLine: 1352 case QwtSymbol::Cross: 1346 1353 { 1347 useCache = true; 1354 // for the very simple shapes using vector graphics is 1355 // usually faster. 1356 1357 useCache = false; 1358 break; 1348 1359 } 1349 break; 1360 1361 case QwtSymbol::Pixmap: 1362 { 1363 if ( m_data->size.isEmpty() || 1364 m_data->size == m_data->pixmap.pixmap.size() ) 1365 { 1366 // no need to have a pixmap cache for a pixmap 1367 // of the same size 1368 1369 useCache = false; 1370 } 1371 break; 1372 } 1373 default: 1374 break; 1350 1375 } 1351 default: 1352 useCache = true; 1376 break; 1377 } 1378 default: 1379 { 1380 useCache = true; 1353 1381 } 1354 1382 } … … 1360 1388 const QRect br = boundingRect(); 1361 1389 1362 if ( d_data->cache.pixmap.isNull() )1363 { 1364 d_data->cache.pixmap = QwtPainter::backingStore( NULL, br.size() );1365 d_data->cache.pixmap.fill( Qt::transparent );1366 1367 QPainter p( & d_data->cache.pixmap );1390 if ( m_data->cache.pixmap.isNull() ) 1391 { 1392 m_data->cache.pixmap = QwtPainter::backingStore( NULL, br.size() ); 1393 m_data->cache.pixmap.fill( Qt::transparent ); 1394 1395 QPainter p( &m_data->cache.pixmap ); 1368 1396 p.setRenderHints( painter->renderHints() ); 1369 1397 p.translate( -br.topLeft() ); 1370 1398 1371 const QPointF pos; 1399 const QPointF pos( 0.0, 0.0 ); 1372 1400 renderSymbols( &p, &pos, 1 ); 1373 1401 } … … 1381 1409 const int top = qRound( points[i].y() ) + dy; 1382 1410 1383 painter->drawPixmap( left, top, d_data->cache.pixmap );1411 painter->drawPixmap( left, top, m_data->cache.pixmap ); 1384 1412 } 1385 1413 } … … 1393 1421 1394 1422 /*! 1395 \brief Draw the symbol into a rectangle 1396 1397 The symbol is painted centered and scaled into the target rectangle. 1398 It is always painted uncached and the pin point is ignored. 1399 1400 This method is primarily intended for drawing a symbol to 1401 the legend. 1402 1403 \param painter Painter 1404 \param rect Target rectangle for the symbol 1405 */ 1406 void QwtSymbol::drawSymbol( QPainter *painter, const QRectF&rect ) const1407 { 1408 if ( d_data->style == QwtSymbol::NoSymbol )1423 \brief Draw the symbol into a rectangle 1424 1425 The symbol is painted centered and scaled into the target rectangle. 1426 It is always painted uncached and the pin point is ignored. 1427 1428 This method is primarily intended for drawing a symbol to 1429 the legend. 1430 1431 \param painter Painter 1432 \param rect Target rectangle for the symbol 1433 */ 1434 void QwtSymbol::drawSymbol( QPainter* painter, const QRectF& rect ) const 1435 { 1436 if ( m_data->style == QwtSymbol::NoSymbol ) 1409 1437 return; 1410 1438 1411 if ( d_data->style == QwtSymbol::Graphic )1412 { 1413 d_data->graphic.graphic.render(1439 if ( m_data->style == QwtSymbol::Graphic ) 1440 { 1441 m_data->graphic.graphic.render( 1414 1442 painter, rect, Qt::KeepAspectRatio ); 1415 1443 } 1416 else if ( d_data->style == QwtSymbol::Path )1417 { 1418 if ( d_data->path.graphic.isNull() )1419 { 1420 d_data->path.graphic = qwtPathGraphic(1421 d_data->path.path,d_data->pen,d_data->brush );1422 } 1423 1424 d_data->path.graphic.render(1444 else if ( m_data->style == QwtSymbol::Path ) 1445 { 1446 if ( m_data->path.graphic.isNull() ) 1447 { 1448 m_data->path.graphic = qwtPathGraphic( 1449 m_data->path.path, m_data->pen, m_data->brush ); 1450 } 1451 1452 m_data->path.graphic.render( 1425 1453 painter, rect, Qt::KeepAspectRatio ); 1426 1454 return; 1427 1455 } 1428 else if ( d_data->style == QwtSymbol::SvgDocument )1456 else if ( m_data->style == QwtSymbol::SvgDocument ) 1429 1457 { 1430 1458 #ifndef QWT_NO_SVG 1431 if ( d_data->svg.renderer )1459 if ( m_data->svg.renderer ) 1432 1460 { 1433 1461 QRectF scaledRect; 1434 1462 1435 QSizeF sz = d_data->svg.renderer->viewBoxF().size();1463 QSizeF sz = m_data->svg.renderer->viewBoxF().size(); 1436 1464 if ( !sz.isEmpty() ) 1437 1465 { … … 1445 1473 } 1446 1474 1447 d_data->svg.renderer->render(1475 m_data->svg.renderer->render( 1448 1476 painter, scaledRect ); 1449 1477 } … … 1464 1492 painter->scale( ratio, ratio ); 1465 1493 1466 const bool isPinPointEnabled = d_data->isPinPointEnabled;1467 d_data->isPinPointEnabled = false;1494 const bool isPinPointEnabled = m_data->isPinPointEnabled; 1495 m_data->isPinPointEnabled = false; 1468 1496 1469 1497 const QPointF pos; 1470 1498 renderSymbols( painter, &pos, 1 ); 1471 1499 1472 d_data->isPinPointEnabled = isPinPointEnabled;1500 m_data->isPinPointEnabled = isPinPointEnabled; 1473 1501 1474 1502 painter->restore(); … … 1477 1505 1478 1506 /*! 1479 Render the symbol to series of points 1480 1481 \param painter Qt painter 1482 \param points Positions of the symbols 1483 \param numPoints Number of points 1484 */ 1485 void QwtSymbol::renderSymbols( QPainter *painter,1486 const QPointF *points, int numPoints ) const1487 { 1488 switch ( d_data->style )1507 Render the symbol to series of points 1508 1509 \param painter Qt painter 1510 \param points Positions of the symbols 1511 \param numPoints Number of points 1512 */ 1513 void QwtSymbol::renderSymbols( QPainter* painter, 1514 const QPointF* points, int numPoints ) const 1515 { 1516 switch ( m_data->style ) 1489 1517 { 1490 1518 case QwtSymbol::Ellipse: … … 1568 1596 case QwtSymbol::Path: 1569 1597 { 1570 if ( d_data->path.graphic.isNull() )1598 if ( m_data->path.graphic.isNull() ) 1571 1599 { 1572 d_data->path.graphic = qwtPathGraphic(d_data->path.path,1573 d_data->pen,d_data->brush );1600 m_data->path.graphic = qwtPathGraphic( m_data->path.path, 1601 m_data->pen, m_data->brush ); 1574 1602 } 1575 1603 1576 1604 qwtDrawGraphicSymbols( painter, points, numPoints, 1577 d_data->path.graphic, *this );1605 m_data->path.graphic, *this ); 1578 1606 break; 1579 1607 } … … 1586 1614 { 1587 1615 qwtDrawGraphicSymbols( painter, points, numPoints, 1588 d_data->graphic.graphic, *this );1616 m_data->graphic.graphic, *this ); 1589 1617 break; 1590 1618 } … … 1593 1621 #ifndef QWT_NO_SVG 1594 1622 qwtDrawSvgSymbols( painter, points, numPoints, 1595 d_data->svg.renderer, *this );1623 m_data->svg.renderer, *this ); 1596 1624 #endif 1597 1625 break; … … 1602 1630 1603 1631 /*! 1604 Calculate the bounding rectangle for a symbol 1605 at position (0,0). 1606 1607 \return Bounding rectangle 1632 Calculate the bounding rectangle for a symbol 1633 at position (0,0). 1634 1635 \return Bounding rectangle 1608 1636 */ 1609 1637 QRect QwtSymbol::boundingRect() const … … 1613 1641 bool pinPointTranslation = false; 1614 1642 1615 switch ( d_data->style )1643 switch ( m_data->style ) 1616 1644 { 1617 1645 case QwtSymbol::Ellipse: … … 1620 1648 { 1621 1649 qreal pw = 0.0; 1622 if ( d_data->pen.style() != Qt::NoPen )1623 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ));1624 1625 rect.setSize( d_data->size + QSizeF( pw, pw ) );1650 if ( m_data->pen.style() != Qt::NoPen ) 1651 pw = QwtPainter::effectivePenWidth( m_data->pen ); 1652 1653 rect.setSize( m_data->size + QSizeF( pw, pw ) ); 1626 1654 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1627 1655 … … 1639 1667 { 1640 1668 qreal pw = 0.0; 1641 if ( d_data->pen.style() != Qt::NoPen )1642 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ));1643 1644 rect.setSize( d_data->size + QSizeF( 2 * pw, 2 * pw ) );1669 if ( m_data->pen.style() != Qt::NoPen ) 1670 pw = QwtPainter::effectivePenWidth( m_data->pen ); 1671 1672 rect.setSize( m_data->size + QSizeF( 2 * pw, 2 * pw ) ); 1645 1673 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1646 1674 break; … … 1648 1676 case QwtSymbol::Path: 1649 1677 { 1650 if ( d_data->path.graphic.isNull() )1678 if ( m_data->path.graphic.isNull() ) 1651 1679 { 1652 d_data->path.graphic = qwtPathGraphic(1653 d_data->path.path,d_data->pen,d_data->brush );1680 m_data->path.graphic = qwtPathGraphic( 1681 m_data->path.path, m_data->pen, m_data->brush ); 1654 1682 } 1655 1683 1656 1684 rect = qwtScaledBoundingRect( 1657 d_data->path.graphic,d_data->size );1685 m_data->path.graphic, m_data->size ); 1658 1686 pinPointTranslation = true; 1659 1687 … … 1662 1690 case QwtSymbol::Pixmap: 1663 1691 { 1664 if ( d_data->size.isEmpty() )1665 rect.setSize( d_data->pixmap.pixmap.size() );1692 if ( m_data->size.isEmpty() ) 1693 rect.setSize( m_data->pixmap.pixmap.size() ); 1666 1694 else 1667 rect.setSize( d_data->size );1695 rect.setSize( m_data->size ); 1668 1696 1669 1697 pinPointTranslation = true; … … 1674 1702 { 1675 1703 rect = qwtScaledBoundingRect( 1676 d_data->graphic.graphic,d_data->size );1704 m_data->graphic.graphic, m_data->size ); 1677 1705 pinPointTranslation = true; 1678 1706 … … 1682 1710 case QwtSymbol::SvgDocument: 1683 1711 { 1684 if ( d_data->svg.renderer )1685 rect = d_data->svg.renderer->viewBoxF();1686 1687 if ( d_data->size.isValid() && !rect.isEmpty() )1712 if ( m_data->svg.renderer ) 1713 rect = m_data->svg.renderer->viewBoxF(); 1714 1715 if ( m_data->size.isValid() && !rect.isEmpty() ) 1688 1716 { 1689 1717 QSizeF sz = rect.size(); 1690 1718 1691 const double sx = d_data->size.width() / sz.width();1692 const double sy = d_data->size.height() / sz.height();1719 const double sx = m_data->size.width() / sz.width(); 1720 const double sy = m_data->size.height() / sz.height(); 1693 1721 1694 1722 QTransform transform; … … 1703 1731 default: 1704 1732 { 1705 rect.setSize( d_data->size );1733 rect.setSize( m_data->size ); 1706 1734 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1707 1735 } … … 1711 1739 { 1712 1740 QPointF pinPoint( 0.0, 0.0 ); 1713 if ( d_data->isPinPointEnabled )1714 pinPoint = rect.center() - d_data->pinPoint;1741 if ( m_data->isPinPointEnabled ) 1742 pinPoint = rect.center() - m_data->pinPoint; 1715 1743 1716 1744 rect.moveCenter( pinPoint ); … … 1718 1746 1719 1747 QRect r; 1720 r.setLeft( qFloor( rect.left() ) ); 1721 r.setTop( qFloor( rect.top() ) ); 1722 r.setRight( qCeil( rect.right() ) ); 1723 r.setBottom( qCeil( rect.bottom() ) ); 1724 1725 if ( d_data->style != QwtSymbol::Pixmap )1748 r.setLeft( qwtFloor( rect.left() ) ); 1749 r.setTop( qwtFloor( rect.top() ) ); 1750 r.setRight( qwtCeil( rect.right() ) ); 1751 r.setBottom( qwtCeil( rect.bottom() ) ); 1752 1753 if ( m_data->style != QwtSymbol::Pixmap ) 1726 1754 r.adjust( -1, -1, 1, 1 ); // for antialiasing 1727 1755 … … 1730 1758 1731 1759 /*! 1732 Invalidate the cached symbol pixmap 1733 1734 The symbol invalidates its cache, whenever an attribute is changed 1735 that has an effect ob how to display a symbol. In case of derived 1736 classes with individual styles ( >= QwtSymbol::UserStyle ) it 1737 might be necessary to call invalidateCache() for attributes 1738 that are relevant for this style. 1739 1740 \sa CachePolicy, setCachePolicy(), drawSymbols() 1760 Invalidate the cached symbol pixmap 1761 1762 The symbol invalidates its cache, whenever an attribute is changed 1763 that has an effect ob how to display a symbol. In case of derived 1764 classes with individual styles ( >= QwtSymbol::UserStyle ) it 1765 might be necessary to call invalidateCache() for attributes 1766 that are relevant for this style. 1767 1768 \sa CachePolicy, setCachePolicy(), drawSymbols() 1741 1769 */ 1742 1770 void QwtSymbol::invalidateCache() 1743 1771 { 1744 if ( ! d_data->cache.pixmap.isNull() )1745 d_data->cache.pixmap = QPixmap();1746 } 1747 1748 /*! 1749 Specify the symbol style 1750 1751 \param style Style 1752 \sa style() 1753 */ 1772 if ( !m_data->cache.pixmap.isNull() ) 1773 m_data->cache.pixmap = QPixmap(); 1774 } 1775 1776 /*! 1777 Specify the symbol style 1778 1779 \param style Style 1780 \sa style() 1781 */ 1754 1782 void QwtSymbol::setStyle( QwtSymbol::Style style ) 1755 1783 { 1756 if ( d_data->style != style )1757 { 1758 d_data->style = style;1784 if ( m_data->style != style ) 1785 { 1786 m_data->style = style; 1759 1787 invalidateCache(); 1760 1788 } … … 1762 1790 1763 1791 /*! 1764 \return Current symbol style 1765 \sa setStyle() 1766 */ 1792 \return Current symbol style 1793 \sa setStyle() 1794 */ 1767 1795 QwtSymbol::Style QwtSymbol::style() const 1768 1796 { 1769 return d_data->style;1770 } 1797 return m_data->style; 1798 } -
trunk/BNC/qwt/qwt_symbol.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 14 15 #include <qpolygon.h> 16 #include <qpen.h> 17 #include <qbrush.h> 15 18 16 19 class QPainter; 17 class QRect;18 20 class QSize; 19 21 class QBrush; … … 21 23 class QColor; 22 24 class QPointF; 23 class QPolygonF;24 25 class QPainterPath; 25 26 class QPixmap; … … 30 31 class QWT_EXPORT QwtSymbol 31 32 { 32 public: 33 public: 33 34 /*! 34 Symbol Style 35 \sa setStyle(), style() 35 Symbol Style 36 \sa setStyle(), style() 36 37 */ 37 38 enum Style … … 86 87 87 88 /*! 88 The symbol is represented by a painter path, where the 89 origin ( 0, 0 ) of the path coordinate system is mapped to 90 the position of the symbol. 91 92 \sa setPath(), path() 89 The symbol is represented by a painter path, where the 90 origin ( 0, 0 ) of the path coordinate system is mapped to 91 the position of the symbol. 92 93 \sa setPath(), path() 93 94 */ 94 95 Path, 95 96 96 97 /*! 97 The symbol is represented by a pixmap. The pixmap is centered 98 or aligned to its pin point. 99 100 \sa setPinPoint() 98 The symbol is represented by a pixmap. The pixmap is centered 99 or aligned to its pin point. 100 101 \sa setPinPoint() 101 102 */ 102 103 Pixmap, 103 104 104 105 /*! 105 The symbol is represented by a graphic. The graphic is centered 106 or aligned to its pin point. 107 108 \sa setPinPoint() 106 The symbol is represented by a graphic. The graphic is centered 107 or aligned to its pin point. 108 109 \sa setPinPoint() 109 110 */ 110 111 Graphic, 111 112 112 113 /*! 113 The symbol is represented by a SVG graphic. The graphic is centered 114 or aligned to its pin point. 115 116 \sa setPinPoint() 114 The symbol is represented by a SVG graphic. The graphic is centered 115 or aligned to its pin point. 116 117 \sa setPinPoint() 117 118 */ 118 119 SvgDocument, 119 120 120 121 /*! 121 Styles >= QwtSymbol::UserSymbol are reserved for derived 122 classes of QwtSymbol that overload drawSymbols() with 123 additional application specific symbol types. 122 Styles >= QwtSymbol::UserSymbol are reserved for derived 123 classes of QwtSymbol that overload drawSymbols() with 124 additional application specific symbol types. 124 125 */ 125 126 UserStyle = 1000 … … 127 128 128 129 /*! 129 Depending on the render engine and the complexity of the 130 symbol shape it might be faster to render the symbol 131 to a pixmap and to paint this pixmap. 132 133 F.e. the raster paint engine is a pure software renderer 134 where in cache mode a draw operation usually ends in 135 raster operation with the the backing store, that are usually 136 faster, than the algorithms for rendering polygons. 137 But the opposite can be expected for graphic pipelines 138 that can make use of hardware acceleration. 139 140 The default setting is AutoCache 141 142 \sa setCachePolicy(), cachePolicy() 143 144 \note The policy has no effect, when the symbol is painted 130 Depending on the render engine and the complexity of the 131 symbol shape it might be faster to render the symbol 132 to a pixmap and to paint this pixmap. 133 134 F.e. the raster paint engine is a pure software renderer 135 where in cache mode a draw operation usually ends in 136 raster operation with the the backing store, that are usually 137 faster, than the algorithms for rendering polygons. 138 But the opposite can be expected for graphic pipelines 139 that can make use of hardware acceleration. 140 141 The default setting is AutoCache 142 143 \sa setCachePolicy(), cachePolicy() 144 145 \note The policy has no effect, when the symbol is painted 145 146 to a vector graphics format ( PDF, SVG ). 146 \warning Since Qt 4.8 raster is the default backend on X11 147 \warning Since Qt 4.8 raster is the default backend on X11 147 148 */ 148 149 … … 164 165 }; 165 166 166 public: 167 QwtSymbol( Style = NoSymbol ); 168 QwtSymbol( Style, const QBrush &, const QPen&, const QSize& );169 QwtSymbol( const QPainterPath &, const QBrush&, const QPen& );167 public: 168 explicit QwtSymbol( Style = NoSymbol ); 169 QwtSymbol( Style, const QBrush&, const QPen&, const QSize& ); 170 QwtSymbol( const QPainterPath&, const QBrush&, const QPen& ); 170 171 171 172 virtual ~QwtSymbol(); … … 174 175 CachePolicy cachePolicy() const; 175 176 176 void setSize( const QSize & );177 void setSize( const QSize& ); 177 178 void setSize( int width, int height = -1 ); 178 const QSize &size() const;179 180 void setPinPoint( const QPointF &pos, bool enable = true );179 const QSize& size() const; 180 181 void setPinPoint( const QPointF& pos, bool enable = true ); 181 182 QPointF pinPoint() const; 182 183 … … 184 185 bool isPinPointEnabled() const; 185 186 186 virtual void setColor( const QColor & );187 188 void setBrush( const QBrush & );189 const QBrush &brush() const;190 191 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );192 void setPen( const QPen & );193 const QPen &pen() const;187 virtual void setColor( const QColor& ); 188 189 void setBrush( const QBrush& ); 190 const QBrush& brush() const; 191 192 void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 193 void setPen( const QPen& ); 194 const QPen& pen() const; 194 195 195 196 void setStyle( Style ); 196 197 Style style() const; 197 198 198 void setPath( const QPainterPath & );199 const QPainterPath &path() const;200 201 void setPixmap( const QPixmap & );202 const QPixmap &pixmap() const;203 204 void setGraphic( const QwtGraphic & );205 const QwtGraphic &graphic() const;199 void setPath( const QPainterPath& ); 200 const QPainterPath& path() const; 201 202 void setPixmap( const QPixmap& ); 203 const QPixmap& pixmap() const; 204 205 void setGraphic( const QwtGraphic& ); 206 const QwtGraphic& graphic() const; 206 207 207 208 #ifndef QWT_NO_SVG 208 void setSvgDocument( const QByteArray & );209 void setSvgDocument( const QByteArray& ); 209 210 #endif 210 211 211 void drawSymbol( QPainter *, const QRectF& ) const;212 void drawSymbol( QPainter *, const QPointF& ) const;213 void drawSymbols( QPainter *, const QPolygonF& ) const;214 void drawSymbols( QPainter *,215 const QPointF *, int numPoints ) const;212 void drawSymbol( QPainter*, const QRectF& ) const; 213 void drawSymbol( QPainter*, const QPointF& ) const; 214 void drawSymbols( QPainter*, const QPolygonF& ) const; 215 void drawSymbols( QPainter*, 216 const QPointF*, int numPoints ) const; 216 217 217 218 virtual QRect boundingRect() const; 218 219 void invalidateCache(); 219 220 220 protected: 221 virtual void renderSymbols( QPainter *, 222 const QPointF *, int numPoints ) const; 223 224 private: 225 // Disabled copy constructor and operator= 226 QwtSymbol( const QwtSymbol & ); 227 QwtSymbol &operator=( const QwtSymbol & ); 221 protected: 222 virtual void renderSymbols( QPainter*, 223 const QPointF*, int numPoints ) const; 224 225 private: 226 Q_DISABLE_COPY(QwtSymbol) 228 227 229 228 class PrivateData; 230 PrivateData *d_data;229 PrivateData* m_data; 231 230 }; 232 231 233 232 /*! 234 \brief Draw the symbol at a specified position 235 236 \param painter Painter 237 \param pos Position of the symbol in screen coordinates 238 */ 233 \brief Draw the symbol at a specified position 234 235 \param painter Painter 236 \param pos Position of the symbol in screen coordinates 237 */ 239 238 inline void QwtSymbol::drawSymbol( 240 QPainter *painter, const QPointF&pos ) const239 QPainter* painter, const QPointF& pos ) const 241 240 { 242 241 drawSymbols( painter, &pos, 1 ); … … 244 243 245 244 /*! 246 \brief Draw symbols at the specified points 247 248 \param painter Painter 249 \param points Positions of the symbols in screen coordinates 250 */ 245 \brief Draw symbols at the specified points 246 247 \param painter Painter 248 \param points Positions of the symbols in screen coordinates 249 */ 251 250 252 251 inline void QwtSymbol::drawSymbols( 253 QPainter *painter, const QPolygonF&points ) const252 QPainter* painter, const QPolygonF& points ) const 254 253 { 255 254 drawSymbols( painter, points.data(), points.size() ); -
trunk/BNC/qwt/qwt_system_clock.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_system_clock.h" 11 12 #if QT_VERSION >= 0x04080013 #define USE_ELAPSED_TIMER 114 #endif15 16 #if USE_ELAPSED_TIMER17 18 11 #include <qelapsedtimer.h> 19 12 20 class QwtSystemClock::PrivateData 13 //! \return true, if the elapsed timer is valid 14 bool QwtSystemClock::isNull() const 21 15 { 22 public: 23 QElapsedTimer timer; 24 }; 25 26 QwtSystemClock::QwtSystemClock() 27 { 28 d_data = new PrivateData(); 16 return m_timer.isValid(); 29 17 } 30 18 31 QwtSystemClock::~QwtSystemClock() 19 //! Start the elapsed timer 20 void QwtSystemClock::start() 32 21 { 33 delete d_data;22 m_timer.start(); 34 23 } 35 24 36 bool QwtSystemClock::isNull() const 37 { 38 return d_data->timer.isValid(); 39 } 40 41 void QwtSystemClock::start() 42 { 43 d_data->timer.start(); 44 } 45 25 /*! 26 Restart the elapsed timer 27 \return elapsed time in multiples of milliseconds 28 */ 46 29 double QwtSystemClock::restart() 47 30 { 48 const qint64 nsecs = d_data->timer.restart();31 const qint64 nsecs = m_timer.restart(); 49 32 return nsecs / 1e6; 50 33 } 51 34 35 //! \return elapsed time in multiples of milliseconds 52 36 double QwtSystemClock::elapsed() const 53 37 { 54 const qint64 nsecs = d_data->timer.nsecsElapsed();38 const qint64 nsecs = m_timer.nsecsElapsed(); 55 39 return nsecs / 1e6; 56 40 } 57 58 #else // !USE_ELAPSED_TIMER59 60 #include <qdatetime.h>61 62 #if !defined(Q_OS_WIN)63 #include <unistd.h>64 #endif65 66 #if defined(Q_OS_MAC)67 #include <stdint.h>68 #include <mach/mach_time.h>69 #define QWT_HIGH_RESOLUTION_CLOCK70 #elif defined(_POSIX_TIMERS)71 #include <time.h>72 #define QWT_HIGH_RESOLUTION_CLOCK73 #elif defined(Q_OS_WIN)74 #define QWT_HIGH_RESOLUTION_CLOCK75 #include <qt_windows.h>76 #endif77 78 #if defined(QWT_HIGH_RESOLUTION_CLOCK)79 80 class QwtHighResolutionClock81 {82 public:83 QwtHighResolutionClock();84 85 void start();86 double restart();87 double elapsed() const;88 89 bool isNull() const;90 91 static double precision();92 93 private:94 95 #if defined(Q_OS_MAC)96 static double msecsTo( uint64_t, uint64_t );97 98 uint64_t d_timeStamp;99 #elif defined(_POSIX_TIMERS)100 101 static double msecsTo( const struct timespec &,102 const struct timespec & );103 104 static bool isMonotonic();105 106 struct timespec d_timeStamp;107 clockid_t d_clockId;108 109 #elif defined(Q_OS_WIN)110 111 LARGE_INTEGER d_startTicks;112 LARGE_INTEGER d_ticksPerSecond;113 #endif114 };115 116 #if defined(Q_OS_MAC)117 QwtHighResolutionClock::QwtHighResolutionClock():118 d_timeStamp( 0 )119 {120 }121 122 double QwtHighResolutionClock::precision()123 {124 return 1e-6;125 }126 127 void QwtHighResolutionClock::start()128 {129 d_timeStamp = mach_absolute_time();130 }131 132 double QwtHighResolutionClock::restart()133 {134 const uint64_t timeStamp = mach_absolute_time();135 const double elapsed = msecsTo( d_timeStamp, timeStamp );136 d_timeStamp = timeStamp;137 138 return elapsed;139 }140 141 double QwtHighResolutionClock::elapsed() const142 {143 return msecsTo( d_timeStamp, mach_absolute_time() );144 }145 146 bool QwtHighResolutionClock::isNull() const147 {148 return d_timeStamp == 0;149 }150 151 double QwtHighResolutionClock::msecsTo(152 uint64_t from, uint64_t to )153 {154 const uint64_t difference = to - from;155 156 static double conversion = 0.0;157 if ( conversion == 0.0 )158 {159 mach_timebase_info_data_t info;160 kern_return_t err = mach_timebase_info( &info );161 162 // convert the timebase into ms163 if ( err == 0 )164 conversion = 1e-6 * ( double ) info.numer / ( double ) info.denom;165 }166 167 return conversion * ( double ) difference;168 }169 170 #elif defined(_POSIX_TIMERS)171 172 QwtHighResolutionClock::QwtHighResolutionClock()173 {174 d_clockId = isMonotonic() ? CLOCK_MONOTONIC : CLOCK_REALTIME;175 d_timeStamp.tv_sec = d_timeStamp.tv_nsec = 0;176 }177 178 double QwtHighResolutionClock::precision()179 {180 struct timespec resolution;181 182 int clockId = isMonotonic() ? CLOCK_MONOTONIC : CLOCK_REALTIME;183 ::clock_getres( clockId, &resolution );184 185 return resolution.tv_nsec / 1e3;186 }187 188 inline bool QwtHighResolutionClock::isNull() const189 {190 return d_timeStamp.tv_sec <= 0 && d_timeStamp.tv_nsec <= 0;191 }192 193 inline void QwtHighResolutionClock::start()194 {195 ::clock_gettime( d_clockId, &d_timeStamp );196 }197 198 double QwtHighResolutionClock::restart()199 {200 struct timespec timeStamp;201 ::clock_gettime( d_clockId, &timeStamp );202 203 const double elapsed = msecsTo( d_timeStamp, timeStamp );204 205 d_timeStamp = timeStamp;206 return elapsed;207 }208 209 inline double QwtHighResolutionClock::elapsed() const210 {211 struct timespec timeStamp;212 ::clock_gettime( d_clockId, &timeStamp );213 214 return msecsTo( d_timeStamp, timeStamp );215 }216 217 inline double QwtHighResolutionClock::msecsTo(218 const struct timespec &t1, const struct timespec &t2 )219 {220 return ( t2.tv_sec - t1.tv_sec ) * 1e3221 + ( t2.tv_nsec - t1.tv_nsec ) * 1e-6;222 }223 224 bool QwtHighResolutionClock::isMonotonic()225 {226 // code copied from qcore_unix.cpp227 228 #if (_POSIX_MONOTONIC_CLOCK-0 > 0)229 return true;230 #else231 static int returnValue = 0;232 233 if ( returnValue == 0 )234 {235 #if (_POSIX_MONOTONIC_CLOCK-0 < 0) || !defined(_SC_MONOTONIC_CLOCK)236 returnValue = -1;237 #elif (_POSIX_MONOTONIC_CLOCK == 0)238 // detect if the system support monotonic timers239 const long x = sysconf( _SC_MONOTONIC_CLOCK );240 returnValue = ( x >= 200112L ) ? 1 : -1;241 #endif242 }243 244 return returnValue != -1;245 #endif246 }247 248 #elif defined(Q_OS_WIN)249 250 QwtHighResolutionClock::QwtHighResolutionClock()251 {252 d_startTicks.QuadPart = 0;253 QueryPerformanceFrequency( &d_ticksPerSecond );254 }255 256 double QwtHighResolutionClock::precision()257 {258 LARGE_INTEGER ticks;259 if ( QueryPerformanceFrequency( &ticks ) && ticks.QuadPart > 0 )260 return 1e3 / ticks.QuadPart;261 262 return 0.0;263 }264 265 inline bool QwtHighResolutionClock::isNull() const266 {267 return d_startTicks.QuadPart <= 0;268 }269 270 inline void QwtHighResolutionClock::start()271 {272 QueryPerformanceCounter( &d_startTicks );273 }274 275 inline double QwtHighResolutionClock::restart()276 {277 LARGE_INTEGER ticks;278 QueryPerformanceCounter( &ticks );279 280 const double dt = ticks.QuadPart - d_startTicks.QuadPart;281 d_startTicks = ticks;282 283 return dt / d_ticksPerSecond.QuadPart * 1e3;284 }285 286 inline double QwtHighResolutionClock::elapsed() const287 {288 LARGE_INTEGER ticks;289 QueryPerformanceCounter( &ticks );290 291 const double dt = ticks.QuadPart - d_startTicks.QuadPart;292 return dt / d_ticksPerSecond.QuadPart * 1e3;293 }294 295 #endif296 297 #endif // QWT_HIGH_RESOLUTION_CLOCK298 299 class QwtSystemClock::PrivateData300 {301 public:302 #if defined(QWT_HIGH_RESOLUTION_CLOCK)303 QwtHighResolutionClock *clock;304 #endif305 QTime time;306 };307 308 //! Constructs a null clock object.309 QwtSystemClock::QwtSystemClock()310 {311 d_data = new PrivateData;312 313 #if defined(QWT_HIGH_RESOLUTION_CLOCK)314 d_data->clock = NULL;315 if ( QwtHighResolutionClock::precision() > 0.0 )316 d_data->clock = new QwtHighResolutionClock;317 #endif318 }319 320 //! Destructor321 QwtSystemClock::~QwtSystemClock()322 {323 #if defined(QWT_HIGH_RESOLUTION_CLOCK)324 delete d_data->clock;325 #endif326 delete d_data;327 }328 329 /*!330 \return true if the clock has never been started.331 */332 bool QwtSystemClock::isNull() const333 {334 #if defined(QWT_HIGH_RESOLUTION_CLOCK)335 if ( d_data->clock )336 return d_data->clock->isNull();337 #endif338 339 return d_data->time.isNull();340 }341 342 /*!343 Sets the start time to the current time.344 */345 void QwtSystemClock::start()346 {347 #if defined(QWT_HIGH_RESOLUTION_CLOCK)348 if ( d_data->clock )349 {350 d_data->clock->start();351 return;352 }353 #endif354 355 d_data->time.start();356 }357 358 /*!359 Set the start time to the current time360 \return Time, that is elapsed since the previous start time.361 */362 double QwtSystemClock::restart()363 {364 #if defined(QWT_HIGH_RESOLUTION_CLOCK)365 if ( d_data->clock )366 return d_data->clock->restart();367 #endif368 369 return d_data->time.restart();370 }371 372 /*!373 \return Number of milliseconds that have elapsed since the last time374 start() or restart() was called or 0.0 for null clocks.375 */376 double QwtSystemClock::elapsed() const377 {378 double elapsed = 0.0;379 380 #if defined(QWT_HIGH_RESOLUTION_CLOCK)381 if ( d_data->clock )382 {383 if ( !d_data->clock->isNull() )384 elapsed = d_data->clock->elapsed();385 386 return elapsed;387 }388 #endif389 390 if ( !d_data->time.isNull() )391 elapsed = d_data->time.elapsed();392 393 return elapsed;394 }395 396 #endif -
trunk/BNC/qwt/qwt_system_clock.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include <qelapsedtimer.h> 14 15 15 16 /*! 16 \brief QwtSystemClock provides high resolution clock time functions. 17 \brief QwtSystemClock provides high resolution clock time functions. 17 18 18 Sometimes the resolution offered by QTime ( millisecond ) is not accurate 19 enough for implementing time measurements ( f.e. sampling ). 20 QwtSystemClock offers a subset of the QTime functionality using higher 21 resolution timers ( if possible ). 19 Precision and time intervals are multiples of milliseconds (ms). 22 20 23 Precision and time intervals are multiples of milliseconds (ms). 24 25 ( QwtSystemClock is obsolete since Qt 4.8 as QElapsedTimer offers the same 26 precision ) 27 28 \note The implementation uses high-resolution performance counter on Windows, 29 mach_absolute_time() on the Mac or POSIX timers on other systems. 30 If none is available it falls back on QTimer. 31 */ 21 ( QwtSystemClock is deprecated as QElapsedTimer offers the same precision ) 22 */ 32 23 33 24 class QWT_EXPORT QwtSystemClock 34 25 { 35 public: 36 QwtSystemClock(); 37 virtual ~QwtSystemClock(); 38 26 public: 39 27 bool isNull() const; 40 28 … … 43 31 double elapsed() const; 44 32 45 private: 46 class PrivateData; 47 PrivateData *d_data; 33 private: 34 QElapsedTimer m_timer; 48 35 }; 49 36 -
trunk/BNC/qwt/qwt_text.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_painter.h" 12 12 #include "qwt_text_engine.h" 13 #include "qwt_math.h" 14 13 15 #include <qmap.h> 14 16 #include <qfont.h> … … 17 19 #include <qbrush.h> 18 20 #include <qpainter.h> 19 #include <qapplication.h> 20 #include <qdesktopwidget.h> 21 #include <qmath.h> 22 23 class QwtTextEngineDict 24 { 25 public: 26 static QwtTextEngineDict &dict(); 27 28 void setTextEngine( QwtText::TextFormat, QwtTextEngine * ); 29 30 const QwtTextEngine *textEngine( QwtText::TextFormat ) const; 31 const QwtTextEngine *textEngine( const QString &, 32 QwtText::TextFormat ) const; 33 34 private: 35 QwtTextEngineDict(); 36 ~QwtTextEngineDict(); 37 38 typedef QMap<int, QwtTextEngine *> EngineMap; 39 40 inline const QwtTextEngine *engine( EngineMap::const_iterator &it ) const 41 { 42 return it.value(); 43 } 44 45 EngineMap d_map; 46 }; 47 48 QwtTextEngineDict &QwtTextEngineDict::dict() 49 { 50 static QwtTextEngineDict engineDict; 51 return engineDict; 52 } 53 54 QwtTextEngineDict::QwtTextEngineDict() 55 { 56 d_map.insert( QwtText::PlainText, new QwtPlainTextEngine() ); 57 #ifndef QT_NO_RICHTEXT 58 d_map.insert( QwtText::RichText, new QwtRichTextEngine() ); 21 22 #if QT_VERSION >= 0x050200 23 24 static QwtText qwtStringToText( const QString& text ) 25 { 26 return QwtText( text ); 27 } 28 59 29 #endif 60 } 61 62 QwtTextEngineDict::~QwtTextEngineDict() 63 { 64 for ( EngineMap::const_iterator it = d_map.constBegin(); 65 it != d_map.constEnd(); ++it ) 66 { 67 const QwtTextEngine *textEngine = engine( it ); 68 delete textEngine; 69 } 70 } 71 72 const QwtTextEngine *QwtTextEngineDict::textEngine( const QString& text, 73 QwtText::TextFormat format ) const 74 { 75 if ( format == QwtText::AutoText ) 76 { 77 for ( EngineMap::const_iterator it = d_map.begin(); 78 it != d_map.end(); ++it ) 30 31 namespace 32 { 33 static const struct RegisterQwtText 34 { 35 inline RegisterQwtText() 79 36 { 80 if ( it.key() != QwtText::PlainText ) 37 qRegisterMetaType< QwtText >(); 38 39 #if QT_VERSION >= 0x050200 40 QMetaType::registerConverter< QString, QwtText >( qwtStringToText ); 41 #endif 42 } 43 44 } qwtRegisterQwtText; 45 } 46 47 namespace 48 { 49 class TextEngineDict 50 { 51 public: 52 static TextEngineDict& dict(); 53 54 void setTextEngine( QwtText::TextFormat, QwtTextEngine* ); 55 56 const QwtTextEngine* textEngine( QwtText::TextFormat ) const; 57 const QwtTextEngine* textEngine( const QString&, 58 QwtText::TextFormat ) const; 59 60 private: 61 TextEngineDict(); 62 ~TextEngineDict(); 63 64 typedef QMap< int, QwtTextEngine* > EngineMap; 65 66 inline const QwtTextEngine* engine( EngineMap::const_iterator& it ) const 67 { 68 return it.value(); 69 } 70 71 EngineMap m_map; 72 }; 73 74 TextEngineDict& TextEngineDict::dict() 75 { 76 static TextEngineDict engineDict; 77 return engineDict; 78 } 79 80 TextEngineDict::TextEngineDict() 81 { 82 m_map.insert( QwtText::PlainText, new QwtPlainTextEngine() ); 83 #ifndef QT_NO_RICHTEXT 84 m_map.insert( QwtText::RichText, new QwtRichTextEngine() ); 85 #endif 86 } 87 88 TextEngineDict::~TextEngineDict() 89 { 90 for ( EngineMap::const_iterator it = m_map.constBegin(); 91 it != m_map.constEnd(); ++it ) 92 { 93 const QwtTextEngine* textEngine = engine( it ); 94 delete textEngine; 95 } 96 } 97 98 const QwtTextEngine* TextEngineDict::textEngine( const QString& text, 99 QwtText::TextFormat format ) const 100 { 101 if ( format == QwtText::AutoText ) 102 { 103 for ( EngineMap::const_iterator it = m_map.begin(); 104 it != m_map.end(); ++it ) 81 105 { 82 const QwtTextEngine *e = engine( it ); 83 if ( e && e->mightRender( text ) ) 84 return e; 106 if ( it.key() != QwtText::PlainText ) 107 { 108 const QwtTextEngine* e = engine( it ); 109 if ( e && e->mightRender( text ) ) 110 return e; 111 } 85 112 } 86 113 } 87 } 88 89 EngineMap::const_iterator it = d_map.find( format );90 if ( it != d_map.end() )91 {92 const QwtTextEngine *e = engine( it );93 if ( e )94 return e;95 } 96 97 it = d_map.find( QwtText::PlainText );98 return engine( it );99 } 100 101 voidQwtTextEngineDict::setTextEngine( QwtText::TextFormat format,102 QwtTextEngine *engine )103 { 104 if ( format == QwtText::AutoText )105 return; 106 107 if ( format == QwtText::PlainText && engine == NULL )108 return; 109 110 EngineMap::const_iterator it = d_map.constFind( format );111 if ( it != d_map.constEnd() )112 {113 delete this->engine( it );114 d_map.remove( format );115 } 116 117 if (engine!= NULL )118 d_map.insert( format, engine );119 } 120 121 constQwtTextEngine *QwtTextEngineDict::textEngine(122 QwtText::TextFormat format ) const123 { 124 const QwtTextEngine *e = NULL; 125 126 EngineMap::const_iterator it = d_map.find( format );127 if ( it != d_map.end() )128 e = engine( it ); 129 130 return e;114 115 EngineMap::const_iterator it = m_map.find( format ); 116 if ( it != m_map.end() ) 117 { 118 const QwtTextEngine* e = engine( it ); 119 if ( e ) 120 return e; 121 } 122 123 it = m_map.find( QwtText::PlainText ); 124 return engine( it ); 125 } 126 127 void TextEngineDict::setTextEngine( QwtText::TextFormat format, 128 QwtTextEngine* engine ) 129 { 130 if ( format == QwtText::AutoText ) 131 return; 132 133 if ( format == QwtText::PlainText && engine == NULL ) 134 return; 135 136 EngineMap::const_iterator it = m_map.constFind( format ); 137 if ( it != m_map.constEnd() ) 138 { 139 delete this->engine( it ); 140 m_map.remove( format ); 141 } 142 143 if ( engine != NULL ) 144 m_map.insert( format, engine ); 145 } 146 147 const QwtTextEngine* TextEngineDict::textEngine( 148 QwtText::TextFormat format ) const 149 { 150 const QwtTextEngine* e = NULL; 151 152 EngineMap::const_iterator it = m_map.find( format ); 153 if ( it != m_map.end() ) 154 e = engine( it ); 155 156 return e; 157 } 131 158 } 132 159 133 160 class QwtText::PrivateData 134 161 { 135 public: 162 public: 136 163 PrivateData(): 137 164 renderFlags( Qt::AlignCenter ), … … 139 166 borderPen( Qt::NoPen ), 140 167 backgroundBrush( Qt::NoBrush ), 141 paintAttributes( 0 ),142 layoutAttributes( 0 ),143 168 textEngine( NULL ) 144 169 { … … 156 181 QwtText::LayoutAttributes layoutAttributes; 157 182 158 const QwtTextEngine *textEngine;183 const QwtTextEngine* textEngine; 159 184 }; 160 185 161 186 class QwtText::LayoutCache 162 187 { 163 public: 188 public: 164 189 void invalidate() 165 190 { … … 173 198 /*! 174 199 Constructor 200 */ 201 QwtText::QwtText() 202 { 203 m_data = new PrivateData; 204 m_data->textEngine = textEngine( m_data->text, PlainText ); 205 206 m_layoutCache = new LayoutCache; 207 } 208 209 /*! 210 Constructor 175 211 176 212 \param text Text content 177 213 \param textFormat Text format 178 */ 179 QwtText::QwtText( const QString &text, QwtText::TextFormat textFormat )180 { 181 d_data = new PrivateData;182 d_data->text = text;183 d_data->textEngine = textEngine( text, textFormat );184 185 d_layoutCache = new LayoutCache;214 */ 215 QwtText::QwtText( const QString& text, QwtText::TextFormat textFormat ) 216 { 217 m_data = new PrivateData; 218 m_data->text = text; 219 m_data->textEngine = textEngine( text, textFormat ); 220 221 m_layoutCache = new LayoutCache; 186 222 } 187 223 188 224 //! Copy constructor 189 QwtText::QwtText( const QwtText &other )190 { 191 d_data = new PrivateData;192 * d_data = *other.d_data;193 194 d_layoutCache = new LayoutCache;195 * d_layoutCache = *other.d_layoutCache;225 QwtText::QwtText( const QwtText& other ) 226 { 227 m_data = new PrivateData; 228 *m_data = *other.m_data; 229 230 m_layoutCache = new LayoutCache; 231 *m_layoutCache = *other.m_layoutCache; 196 232 } 197 233 … … 199 235 QwtText::~QwtText() 200 236 { 201 delete d_data;202 delete d_layoutCache;237 delete m_data; 238 delete m_layoutCache; 203 239 } 204 240 205 241 //! Assignment operator 206 QwtText &QwtText::operator=( const QwtText& other )207 { 208 * d_data = *other.d_data;209 * d_layoutCache = *other.d_layoutCache;242 QwtText& QwtText::operator=( const QwtText& other ) 243 { 244 *m_data = *other.m_data; 245 *m_layoutCache = *other.m_layoutCache; 210 246 return *this; 211 247 } 212 248 213 249 //! Relational operator 214 bool QwtText::operator==( const QwtText &other ) const215 { 216 return d_data->renderFlags == other.d_data->renderFlags &&217 d_data->text == other.d_data->text &&218 d_data->font == other.d_data->font &&219 d_data->color == other.d_data->color &&220 d_data->borderRadius == other.d_data->borderRadius &&221 d_data->borderPen == other.d_data->borderPen &&222 d_data->backgroundBrush == other.d_data->backgroundBrush &&223 d_data->paintAttributes == other.d_data->paintAttributes &&224 d_data->textEngine == other.d_data->textEngine;250 bool QwtText::operator==( const QwtText& other ) const 251 { 252 return m_data->renderFlags == other.m_data->renderFlags && 253 m_data->text == other.m_data->text && 254 m_data->font == other.m_data->font && 255 m_data->color == other.m_data->color && 256 m_data->borderRadius == other.m_data->borderRadius && 257 m_data->borderPen == other.m_data->borderPen && 258 m_data->backgroundBrush == other.m_data->backgroundBrush && 259 m_data->paintAttributes == other.m_data->paintAttributes && 260 m_data->textEngine == other.m_data->textEngine; 225 261 } 226 262 227 263 //! Relational operator 228 bool QwtText::operator!=( const QwtText &other ) const // invalidate264 bool QwtText::operator!=( const QwtText& other ) const // invalidate 229 265 { 230 266 return !( other == *this ); … … 238 274 239 275 \sa text() 240 */ 241 void QwtText::setText( const QString &text,276 */ 277 void QwtText::setText( const QString& text, 242 278 QwtText::TextFormat textFormat ) 243 279 { 244 d_data->text = text;245 d_data->textEngine = textEngine( text, textFormat );246 d_layoutCache->invalidate();280 m_data->text = text; 281 m_data->textEngine = textEngine( text, textFormat ); 282 m_layoutCache->invalidate(); 247 283 } 248 284 … … 250 286 \return Text as QString. 251 287 \sa setText() 252 */ 288 */ 253 289 QString QwtText::text() const 254 290 { 255 return d_data->text;291 return m_data->text; 256 292 } 257 293 … … 265 301 \sa renderFlags(), QwtTextEngine::draw() 266 302 \note Some renderFlags might have no effect, depending on the text format. 267 */ 303 */ 268 304 void QwtText::setRenderFlags( int renderFlags ) 269 305 { 270 if ( renderFlags != d_data->renderFlags )271 { 272 d_data->renderFlags = renderFlags;273 d_layoutCache->invalidate();306 if ( renderFlags != m_data->renderFlags ) 307 { 308 m_data->renderFlags = renderFlags; 309 m_layoutCache->invalidate(); 274 310 } 275 311 } … … 278 314 \return Render flags 279 315 \sa setRenderFlags() 280 */ 316 */ 281 317 int QwtText::renderFlags() const 282 318 { 283 return d_data->renderFlags;319 return m_data->renderFlags; 284 320 } 285 321 … … 290 326 \note Setting the font might have no effect, when 291 327 the text contains control sequences for setting fonts. 292 */ 293 void QwtText::setFont( const QFont &font )294 { 295 d_data->font = font;328 */ 329 void QwtText::setFont( const QFont& font ) 330 { 331 m_data->font = font; 296 332 setPaintAttribute( PaintUsingTextFont ); 297 333 } … … 300 336 QFont QwtText::font() const 301 337 { 302 return d_data->font;338 return m_data->font; 303 339 } 304 340 … … 311 347 312 348 \sa setFont(), font(), PaintAttributes 313 */ 314 QFont QwtText::usedFont( const QFont &defaultFont ) const315 { 316 if ( d_data->paintAttributes & PaintUsingTextFont )317 return d_data->font;349 */ 350 QFont QwtText::usedFont( const QFont& defaultFont ) const 351 { 352 if ( m_data->paintAttributes & PaintUsingTextFont ) 353 return m_data->font; 318 354 319 355 return defaultFont; … … 326 362 \note Setting the color might have no effect, when 327 363 the text contains control sequences for setting colors. 328 */ 329 void QwtText::setColor( const QColor &color )330 { 331 d_data->color = color;364 */ 365 void QwtText::setColor( const QColor& color ) 366 { 367 m_data->color = color; 332 368 setPaintAttribute( PaintUsingTextColor ); 333 369 } … … 336 372 QColor QwtText::color() const 337 373 { 338 return d_data->color;339 } 340 341 /*! 342 Return the color of the text, if it has one. 343 Otherwise return defaultColor. 344 345 \param defaultColor Default color 346 \return Color used for drawing the text 347 348 \sa setColor(), color(), PaintAttributes 349 */ 350 QColor QwtText::usedColor( const QColor &defaultColor ) const351 { 352 if ( d_data->paintAttributes & PaintUsingTextColor )353 return d_data->color;374 return m_data->color; 375 } 376 377 /*! 378 Return the color of the text, if it has one. 379 Otherwise return defaultColor. 380 381 \param defaultColor Default color 382 \return Color used for drawing the text 383 384 \sa setColor(), color(), PaintAttributes 385 */ 386 QColor QwtText::usedColor( const QColor& defaultColor ) const 387 { 388 if ( m_data->paintAttributes & PaintUsingTextColor ) 389 return m_data->color; 354 390 355 391 return defaultColor; … … 357 393 358 394 /*! 359 Set the radius for the corners of the border frame 360 361 \param radius Radius of a rounded corner 362 \sa borderRadius(), setBorderPen(), setBackgroundBrush() 363 */ 395 Set the radius for the corners of the border frame 396 397 \param radius Radius of a rounded corner 398 \sa borderRadius(), setBorderPen(), setBackgroundBrush() 399 */ 364 400 void QwtText::setBorderRadius( double radius ) 365 401 { 366 d_data->borderRadius = qMax( 0.0, radius );367 } 368 369 /*! 370 \return Radius for the corners of the border frame 371 \sa setBorderRadius(), borderPen(), backgroundBrush() 372 */ 402 m_data->borderRadius = qwtMaxF( 0.0, radius ); 403 } 404 405 /*! 406 \return Radius for the corners of the border frame 407 \sa setBorderRadius(), borderPen(), backgroundBrush() 408 */ 373 409 double QwtText::borderRadius() const 374 410 { 375 return d_data->borderRadius;411 return m_data->borderRadius; 376 412 } 377 413 … … 381 417 \param pen Background pen 382 418 \sa borderPen(), setBackgroundBrush() 383 */ 384 void QwtText::setBorderPen( const QPen &pen )385 { 386 d_data->borderPen = pen;419 */ 420 void QwtText::setBorderPen( const QPen& pen ) 421 { 422 m_data->borderPen = pen; 387 423 setPaintAttribute( PaintBackground ); 388 424 } … … 391 427 \return Background pen 392 428 \sa setBorderPen(), backgroundBrush() 393 */ 429 */ 394 430 QPen QwtText::borderPen() const 395 431 { 396 return d_data->borderPen;432 return m_data->borderPen; 397 433 } 398 434 … … 402 438 \param brush Background brush 403 439 \sa backgroundBrush(), setBorderPen() 404 */ 405 void QwtText::setBackgroundBrush( const QBrush &brush )406 { 407 d_data->backgroundBrush = brush;440 */ 441 void QwtText::setBackgroundBrush( const QBrush& brush ) 442 { 443 m_data->backgroundBrush = brush; 408 444 setPaintAttribute( PaintBackground ); 409 445 } … … 412 448 \return Background brush 413 449 \sa setBackgroundBrush(), borderPen() 414 */ 450 */ 415 451 QBrush QwtText::backgroundBrush() const 416 452 { 417 return d_data->backgroundBrush;453 return m_data->backgroundBrush; 418 454 } 419 455 … … 427 463 setBorderPen() and setBackgroundBrush() 428 464 \sa testPaintAttribute() 429 */ 465 */ 430 466 void QwtText::setPaintAttribute( PaintAttribute attribute, bool on ) 431 467 { 432 468 if ( on ) 433 d_data->paintAttributes |= attribute;469 m_data->paintAttributes |= attribute; 434 470 else 435 d_data->paintAttributes &= ~attribute;471 m_data->paintAttributes &= ~attribute; 436 472 } 437 473 … … 443 479 444 480 \sa setPaintAttribute() 445 */ 481 */ 446 482 bool QwtText::testPaintAttribute( PaintAttribute attribute ) const 447 483 { 448 return d_data->paintAttributes & attribute;484 return m_data->paintAttributes & attribute; 449 485 } 450 486 … … 455 491 \param on On/Off 456 492 \sa testLayoutAttribute() 457 */ 493 */ 458 494 void QwtText::setLayoutAttribute( LayoutAttribute attribute, bool on ) 459 495 { 460 496 if ( on ) 461 d_data->layoutAttributes |= attribute;497 m_data->layoutAttributes |= attribute; 462 498 else 463 d_data->layoutAttributes &= ~attribute;499 m_data->layoutAttributes &= ~attribute; 464 500 } 465 501 … … 471 507 472 508 \sa setLayoutAttribute() 473 */ 509 */ 474 510 bool QwtText::testLayoutAttribute( LayoutAttribute attribute ) const 475 511 { 476 return d_data->layoutAttributes | attribute; 512 return m_data->layoutAttributes | attribute; 513 } 514 515 /*! 516 Find the height for a given width 517 518 \param width Width 519 \return Calculated height 520 */ 521 522 double QwtText::heightForWidth( double width ) const 523 { 524 return heightForWidth( width, QFont() ); 477 525 } 478 526 … … 484 532 485 533 \return Calculated height 486 */ 487 double QwtText::heightForWidth( double width, const QFont &defaultFont ) const534 */ 535 double QwtText::heightForWidth( double width, const QFont& defaultFont ) const 488 536 { 489 537 // We want to calculate in screen metrics. So 490 538 // we need a font that uses screen metrics 491 539 492 const QFont font( usedFont( defaultFont ), QApplication::desktop() );540 const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) ); 493 541 494 542 double h = 0; 495 543 496 if ( d_data->layoutAttributes & MinimumLayout )544 if ( m_data->layoutAttributes & MinimumLayout ) 497 545 { 498 546 double left, right, top, bottom; 499 d_data->textEngine->textMargins( font,d_data->text,547 m_data->textEngine->textMargins( font, m_data->text, 500 548 left, right, top, bottom ); 501 549 502 h = d_data->textEngine->heightForWidth(503 font, d_data->renderFlags,d_data->text,550 h = m_data->textEngine->heightForWidth( 551 font, m_data->renderFlags, m_data->text, 504 552 width + left + right ); 505 553 … … 508 556 else 509 557 { 510 h = d_data->textEngine->heightForWidth(511 font, d_data->renderFlags,d_data->text, width );558 h = m_data->textEngine->heightForWidth( 559 font, m_data->renderFlags, m_data->text, width ); 512 560 } 513 561 514 562 return h; 563 } 564 565 /*! 566 Returns the size, that is needed to render text 567 568 \return Calculated size 569 */ 570 QSizeF QwtText::textSize() const 571 { 572 return textSize( QFont() ); 515 573 } 516 574 … … 520 578 \param defaultFont Font of the text 521 579 \return Calculated size 522 */ 523 QSizeF QwtText::textSize( const QFont &defaultFont ) const580 */ 581 QSizeF QwtText::textSize( const QFont& defaultFont ) const 524 582 { 525 583 // We want to calculate in screen metrics. So 526 584 // we need a font that uses screen metrics 527 585 528 const QFont font( usedFont( defaultFont ), QApplication::desktop() );529 530 if ( ! d_layoutCache->textSize.isValid()531 || d_layoutCache->font != font )532 { 533 d_layoutCache->textSize =d_data->textEngine->textSize(534 font, d_data->renderFlags,d_data->text );535 d_layoutCache->font = font;536 } 537 538 QSizeF sz = d_layoutCache->textSize;539 540 if ( d_data->layoutAttributes & MinimumLayout )586 const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) ); 587 588 if ( !m_layoutCache->textSize.isValid() 589 || m_layoutCache->font != font ) 590 { 591 m_layoutCache->textSize = m_data->textEngine->textSize( 592 font, m_data->renderFlags, m_data->text ); 593 m_layoutCache->font = font; 594 } 595 596 QSizeF sz = m_layoutCache->textSize; 597 598 if ( m_data->layoutAttributes & MinimumLayout ) 541 599 { 542 600 double left, right, top, bottom; 543 d_data->textEngine->textMargins( font,d_data->text,601 m_data->textEngine->textMargins( font, m_data->text, 544 602 left, right, top, bottom ); 545 603 sz -= QSizeF( left + right, top + bottom ); … … 554 612 \param painter Painter 555 613 \param rect Rectangle 556 */ 557 void QwtText::draw( QPainter *painter, const QRectF&rect ) const558 { 559 if ( d_data->paintAttributes & PaintBackground )560 { 561 if ( d_data->borderPen != Qt::NoPen ||562 d_data->backgroundBrush != Qt::NoBrush )614 */ 615 void QwtText::draw( QPainter* painter, const QRectF& rect ) const 616 { 617 if ( m_data->paintAttributes & PaintBackground ) 618 { 619 if ( m_data->borderPen != Qt::NoPen || 620 m_data->backgroundBrush != Qt::NoBrush ) 563 621 { 564 622 painter->save(); 565 623 566 painter->setPen( d_data->borderPen );567 painter->setBrush( d_data->backgroundBrush );568 569 if ( d_data->borderRadius == 0 )624 painter->setPen( m_data->borderPen ); 625 painter->setBrush( m_data->backgroundBrush ); 626 627 if ( m_data->borderRadius == 0 ) 570 628 { 571 629 QwtPainter::drawRect( painter, rect ); … … 575 633 painter->setRenderHint( QPainter::Antialiasing, true ); 576 634 painter->drawRoundedRect( rect, 577 d_data->borderRadius,d_data->borderRadius );635 m_data->borderRadius, m_data->borderRadius ); 578 636 } 579 637 … … 584 642 painter->save(); 585 643 586 if ( d_data->paintAttributes & PaintUsingTextFont )587 { 588 painter->setFont( d_data->font );589 } 590 591 if ( d_data->paintAttributes & PaintUsingTextColor )592 { 593 if ( d_data->color.isValid() )594 painter->setPen( d_data->color );644 if ( m_data->paintAttributes & PaintUsingTextFont ) 645 { 646 painter->setFont( m_data->font ); 647 } 648 649 if ( m_data->paintAttributes & PaintUsingTextColor ) 650 { 651 if ( m_data->color.isValid() ) 652 painter->setPen( m_data->color ); 595 653 } 596 654 597 655 QRectF expandedRect = rect; 598 if ( d_data->layoutAttributes & MinimumLayout )656 if ( m_data->layoutAttributes & MinimumLayout ) 599 657 { 600 658 // We want to calculate in screen metrics. So 601 659 // we need a font that uses screen metrics 602 660 603 const QFont font( painter->font (), QApplication::desktop() );661 const QFont font = QwtPainter::scaledFont( painter->font() ); 604 662 605 663 double left, right, top, bottom; 606 d_data->textEngine->textMargins(607 font, d_data->text, left, right, top, bottom );664 m_data->textEngine->textMargins( 665 font, m_data->text, left, right, top, bottom ); 608 666 609 667 expandedRect.setTop( rect.top() - top ); … … 613 671 } 614 672 615 d_data->textEngine->draw( painter, expandedRect,616 d_data->renderFlags,d_data->text );673 m_data->textEngine->draw( painter, expandedRect, 674 m_data->renderFlags, m_data->text ); 617 675 618 676 painter->restore(); … … 627 685 628 686 If no text engine is registered for the format QwtPlainTextEngine 629 is returnd. 687 is returned. 630 688 631 689 \param text Text, needed in case of AutoText … … 633 691 634 692 \return Corresponding text engine 635 */ 636 const QwtTextEngine *QwtText::textEngine( const QString&text,693 */ 694 const QwtTextEngine* QwtText::textEngine( const QString& text, 637 695 QwtText::TextFormat format ) 638 696 { 639 return QwtTextEngineDict::dict().textEngine( text, format );697 return TextEngineDict::dict().textEngine( text, format ); 640 698 } 641 699 … … 651 709 \param engine Text engine 652 710 653 \sa QwtMathMLTextEngine654 711 \warning Using QwtText::AutoText does nothing. 655 */ 712 */ 656 713 void QwtText::setTextEngine( QwtText::TextFormat format, 657 QwtTextEngine *engine )658 { 659 QwtTextEngineDict::dict().setTextEngine( format, engine );714 QwtTextEngine* engine ) 715 { 716 TextEngineDict::dict().setTextEngine( format, engine ); 660 717 } 661 718 … … 667 724 \param format Text format 668 725 \return The text engine, or NULL if no engine is available. 669 */ 670 const QwtTextEngine *QwtText::textEngine( QwtText::TextFormat format ) 671 { 672 return QwtTextEngineDict::dict().textEngine( format ); 673 } 726 */ 727 const QwtTextEngine* QwtText::textEngine( QwtText::TextFormat format ) 728 { 729 return TextEngineDict::dict().textEngine( format ); 730 } 731 732 //! \return text().isNull() 733 bool QwtText::isNull() const 734 { 735 return m_data->text.isNull(); 736 } 737 738 //! \return text().isEmpty() 739 bool QwtText::isEmpty() const 740 { 741 return m_data->text.isEmpty(); 742 } 743 -
trunk/BNC/qwt/qwt_text.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 13 13 #include "qwt_global.h" 14 #include <qstring.h>15 #include <qsize.h>16 #include <qfont.h>17 14 #include <qmetatype.h> 18 15 16 class QFont; 17 class QString; 19 18 class QColor; 20 19 class QPen; 21 20 class QBrush; 21 class QSizeF; 22 22 class QRectF; 23 23 class QPainter; … … 25 25 26 26 /*! 27 \brief A class representing a text 28 29 A QwtText is a text including a set of attributes how to render it. 30 31 - Format\n 27 \brief A class representing a text 28 29 A QwtText is a text including a set of attributes how to render it. 30 31 - Format\n 32 32 A text might include control sequences (f.e tags) describing 33 33 how to render it. Each format (f.e MathML, TeX, Qt Rich Text) 34 34 has its own set of control sequences, that can be handles by 35 35 a special QwtTextEngine for this format. 36 - Background\n 36 - Background\n 37 37 A text might have a background, defined by a QPen and QBrush 38 38 to improve its visibility. The corners of the background might 39 39 be rounded. 40 - Font\n 40 - Font\n 41 41 A text might have an individual font. 42 - Color\n 42 - Color\n 43 43 A text might have an individual color. 44 - Render Flags\n 44 - Render Flags\n 45 45 Flags from Qt::AlignmentFlag and Qt::TextFlag used like in 46 46 QPainter::drawText(). 47 47 48 \sa QwtTextEngine, QwtTextLabel 49 */ 48 \sa QwtTextEngine, QwtTextLabel 49 */ 50 50 51 51 class QWT_EXPORT QwtText 52 52 { 53 public: 53 public: 54 54 55 55 /*! 56 \brief Text format 57 58 The text format defines the QwtTextEngine, that is used to render 59 the text. 60 61 \sa QwtTextEngine, setTextEngine() 62 */ 56 \brief Text format 57 58 The text format defines the QwtTextEngine, that is used to render 59 the text. 60 61 \sa QwtTextEngine, setTextEngine() 62 */ 63 63 64 64 enum TextFormat 65 65 { 66 66 /*! 67 The text format is determined using QwtTextEngine::mightRender() for 68 all available text engines in increasing order > PlainText. 69 If none of the text engines can render the text is rendered 70 like QwtText::PlainText. 67 The text format is determined using QwtTextEngine::mightRender() for 68 all available text engines in increasing order > PlainText. 69 If none of the text engines can render the text is rendered 70 like QwtText::PlainText. 71 71 */ 72 72 AutoText = 0, … … 79 79 80 80 /*! 81 Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine 82 to display the text. The Qwt MathML extension offers such an engine 83 based on the MathML renderer of the former Qt solutions package. 84 To enable MathML support the following code needs to be added to the 85 application: 86 87 \code 81 Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine 82 to display the text. In earlier versions of Qwt such an engine 83 was included - since Qwt 6.2 it can be found here: 84 https://github.com/uwerat/qwt-mml-dev 85 86 To enable MathML support the following code needs to be added to the 87 application: 88 89 \code 88 90 QwtText::setTextEngine( QwtText::MathMLText, new QwtMathMLTextEngine() ); 89 \endcode 91 \endcode 90 92 */ 91 93 MathMLText, 92 94 93 95 /*! 94 Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine 95 to display the text ( not implemented yet ). 96 Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine 97 to display the text ( not implemented yet ). 96 98 */ 97 99 TeXText, 98 100 99 101 /*! 100 The number of text formats can be extended using setTextEngine. 101 Formats >= QwtText::OtherFormat are not used by Qwt. 102 The number of text formats can be extended using setTextEngine. 103 Formats >= QwtText::OtherFormat are not used by Qwt. 102 104 */ 103 105 OtherFormat = 100 … … 105 107 106 108 /*! 107 \brief Paint Attributes 108 109 Font and color and background are optional attributes of a QwtText. 110 The paint attributes hold the information, if they are set. 111 */ 109 \brief Paint Attributes 110 111 Font and color and background are optional attributes of a QwtText. 112 The paint attributes hold the information, if they are set. 113 */ 112 114 enum PaintAttribute 113 115 { … … 122 124 }; 123 125 124 //! Paint attributes 125 typedef QFlags<PaintAttribute> PaintAttributes; 126 Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute ) 126 127 127 128 /*! 128 \brief Layout Attributes 129 The layout attributes affects some aspects of the layout of the text. 130 */ 129 \brief Layout Attributes 130 The layout attributes affects some aspects of the layout of the text. 131 */ 131 132 enum LayoutAttribute 132 133 { 133 134 /*! 134 Layout the text without its margins. This mode is useful if a 135 text needs to be aligned accurately, like the tick labels of a scale. 136 If QwtTextEngine::textMargins is not implemented for the format 137 of the text, MinimumLayout has no effect. 135 Layout the text without its margins. This mode is useful if a 136 text needs to be aligned accurately, like the tick labels of a scale. 137 If QwtTextEngine::textMargins is not implemented for the format 138 of the text, MinimumLayout has no effect. 138 139 */ 139 140 MinimumLayout = 0x01 140 141 }; 141 142 142 //!Layoutattributes143 typedef QFlags<LayoutAttribute> LayoutAttributes; 144 145 QwtText( const QString & = QString(),146 TextFormat textFormat = AutoText);147 QwtText( const QwtText & ); 143 Q_DECLARE_FLAGS( LayoutAttributes, LayoutAttribute ) 144 145 QwtText(); 146 QwtText( const QString&, TextFormat textFormat = AutoText ); 147 QwtText( const QwtText& ); 148 148 149 ~QwtText(); 149 150 150 QwtText &operator=( const QwtText& );151 152 bool operator==( const QwtText & ) const;153 bool operator!=( const QwtText & ) const;154 155 void setText( const QString &,151 QwtText& operator=( const QwtText& ); 152 153 bool operator==( const QwtText& ) const; 154 bool operator!=( const QwtText& ) const; 155 156 void setText( const QString&, 156 157 QwtText::TextFormat textFormat = AutoText ); 157 158 QString text() const; … … 160 161 bool isEmpty() const; 161 162 162 void setFont( const QFont & );163 void setFont( const QFont& ); 163 164 QFont font() const; 164 165 165 QFont usedFont( const QFont & ) const;166 QFont usedFont( const QFont& ) const; 166 167 167 168 void setRenderFlags( int ); 168 169 int renderFlags() const; 169 170 170 void setColor( const QColor & );171 void setColor( const QColor& ); 171 172 QColor color() const; 172 173 173 QColor usedColor( const QColor & ) const;174 QColor usedColor( const QColor& ) const; 174 175 175 176 void setBorderRadius( double ); 176 177 double borderRadius() const; 177 178 178 void setBorderPen( const QPen & );179 void setBorderPen( const QPen& ); 179 180 QPen borderPen() const; 180 181 181 void setBackgroundBrush( const QBrush & );182 void setBackgroundBrush( const QBrush& ); 182 183 QBrush backgroundBrush() const; 183 184 … … 188 189 bool testLayoutAttribute( LayoutAttribute ) const; 189 190 190 double heightForWidth( double width, const QFont & = QFont() ) const; 191 QSizeF textSize( const QFont & = QFont() ) const; 192 193 void draw( QPainter *painter, const QRectF &rect ) const; 194 195 static const QwtTextEngine *textEngine( 196 const QString &text, QwtText::TextFormat = AutoText ); 197 198 static const QwtTextEngine *textEngine( QwtText::TextFormat ); 199 static void setTextEngine( QwtText::TextFormat, QwtTextEngine * ); 200 201 private: 191 double heightForWidth( double width ) const; 192 double heightForWidth( double width, const QFont& ) const; 193 194 QSizeF textSize() const; 195 QSizeF textSize( const QFont& ) const; 196 197 void draw( QPainter* painter, const QRectF& rect ) const; 198 199 static const QwtTextEngine* textEngine( 200 const QString& text, QwtText::TextFormat = AutoText ); 201 202 static const QwtTextEngine* textEngine( QwtText::TextFormat ); 203 static void setTextEngine( QwtText::TextFormat, QwtTextEngine* ); 204 205 private: 202 206 class PrivateData; 203 PrivateData *d_data;207 PrivateData* m_data; 204 208 205 209 class LayoutCache; 206 LayoutCache *d_layoutCache;210 LayoutCache* m_layoutCache; 207 211 }; 208 209 //! \return text().isNull()210 inline bool QwtText::isNull() const211 {212 return text().isNull();213 }214 215 //! \return text().isEmpty()216 inline bool QwtText::isEmpty() const217 {218 return text().isEmpty();219 }220 212 221 213 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::PaintAttributes ) -
trunk/BNC/qwt/qwt_text_engine.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_text_engine.h" 11 #include "qwt_math.h"12 11 #include "qwt_painter.h" 12 13 13 #include <qpainter.h> 14 14 #include <qpixmap.h> … … 20 20 #include <qabstracttextdocumentlayout.h> 21 21 22 static QString taggedRichText( const QString &text, int flags )22 static QString taggedRichText( const QString& text, int flags ) 23 23 { 24 24 QString richText = text; … … 27 27 if ( flags & Qt::AlignJustify ) 28 28 { 29 richText.prepend( Q String::fromLatin1( "<div align=\"justify\">" ) );30 richText.append( Q String::fromLatin1( "</div>" ) );29 richText.prepend( QLatin1String( "<div align=\"justify\">" ) ); 30 richText.append( QLatin1String ( "</div>" ) ); 31 31 } 32 32 else if ( flags & Qt::AlignRight ) 33 33 { 34 richText.prepend( Q String::fromLatin1( "<div align=\"right\">" ) );35 richText.append( Q String::fromLatin1( "</div>" ) );34 richText.prepend( QLatin1String ( "<div align=\"right\">" ) ); 35 richText.append( QLatin1String ( "</div>" ) ); 36 36 } 37 37 else if ( flags & Qt::AlignHCenter ) 38 38 { 39 richText.prepend( Q String::fromLatin1( "<div align=\"center\">" ) );40 richText.append( Q String::fromLatin1( "</div>" ) );39 richText.prepend( QLatin1String ( "<div align=\"center\">" ) ); 40 richText.append( QLatin1String ( "</div>" ) ); 41 41 } 42 42 … … 44 44 } 45 45 46 class QwtRichTextDocument: public QTextDocument 47 { 48 public: 49 QwtRichTextDocument( const QString &text, int flags, const QFont &font ) 50 { 51 setUndoRedoEnabled( false ); 52 setDefaultFont( font ); 53 setHtml( text ); 54 55 // make sure we have a document layout 56 ( void )documentLayout(); 57 58 QTextOption option = defaultTextOption(); 59 if ( flags & Qt::TextWordWrap ) 60 option.setWrapMode( QTextOption::WordWrap ); 61 else 62 option.setWrapMode( QTextOption::NoWrap ); 63 64 option.setAlignment( static_cast<Qt::Alignment>( flags ) ); 65 setDefaultTextOption( option ); 66 67 QTextFrame *root = rootFrame(); 68 QTextFrameFormat fm = root->frameFormat(); 69 fm.setBorder( 0 ); 70 fm.setMargin( 0 ); 71 fm.setPadding( 0 ); 72 fm.setBottomMargin( 0 ); 73 fm.setLeftMargin( 0 ); 74 root->setFrameFormat( fm ); 75 76 adjustSize(); 77 } 78 }; 46 namespace 47 { 48 class QwtRichTextDocument : public QTextDocument 49 { 50 public: 51 QwtRichTextDocument( const QString& text, int flags, const QFont& font ) 52 { 53 setUndoRedoEnabled( false ); 54 setDefaultFont( font ); 55 setHtml( text ); 56 57 // make sure we have a document layout 58 ( void )documentLayout(); 59 60 QTextOption option = defaultTextOption(); 61 if ( flags & Qt::TextWordWrap ) 62 option.setWrapMode( QTextOption::WordWrap ); 63 else 64 option.setWrapMode( QTextOption::NoWrap ); 65 66 option.setAlignment( static_cast< Qt::Alignment >( flags ) ); 67 setDefaultTextOption( option ); 68 69 QTextFrame* root = rootFrame(); 70 QTextFrameFormat fm = root->frameFormat(); 71 fm.setBorder( 0 ); 72 fm.setMargin( 0 ); 73 fm.setPadding( 0 ); 74 fm.setBottomMargin( 0 ); 75 fm.setLeftMargin( 0 ); 76 root->setFrameFormat( fm ); 77 78 adjustSize(); 79 } 80 }; 81 } 79 82 80 83 class QwtPlainTextEngine::PrivateData 81 84 { 82 public: 83 int effectiveAscent( const QFont &font ) const85 public: 86 int effectiveAscent( const QFont& font ) const 84 87 { 85 88 const QString fontKey = font.key(); 86 89 87 QMap<QString, int>::const_iterator it = 88 d_ascentCache.constFind( fontKey );89 90 if ( it != d_ascentCache.constEnd() )90 QMap< QString, int >::const_iterator it = 91 m_ascentCache.constFind( fontKey ); 92 93 if ( it != m_ascentCache.constEnd() ) 91 94 return *it; 92 95 93 96 const int ascent = findAscent( font ); 94 d_ascentCache.insert( fontKey, ascent );97 m_ascentCache.insert( fontKey, ascent ); 95 98 96 99 return ascent; 97 100 } 98 101 99 private: 100 int findAscent( const QFont &font ) const102 private: 103 static int findAscent( const QFont& font ) 101 104 { 102 105 static const QString dummy( "E" ); … … 104 107 105 108 const QFontMetrics fm( font ); 106 QPixmap pm( fm.width( dummy ), fm.height() ); 109 110 QPixmap pm( QwtPainter::horizontalAdvance( fm, dummy ), fm.height() ); 107 111 pm.fill( white ); 108 112 … … 117 121 for ( row = 0; row < img.height(); row++ ) 118 122 { 119 const QRgb *line = reinterpret_cast<const QRgb*>(123 const QRgb* line = reinterpret_cast< const QRgb* >( 120 124 img.scanLine( row ) ); 121 125 … … 131 135 } 132 136 133 mutable QMap<QString, int > d_ascentCache;137 mutable QMap< QString, int > m_ascentCache; 134 138 }; 135 139 … … 147 151 QwtPlainTextEngine::QwtPlainTextEngine() 148 152 { 149 d_data = new PrivateData;153 m_data = new PrivateData; 150 154 } 151 155 … … 153 157 QwtPlainTextEngine::~QwtPlainTextEngine() 154 158 { 155 delete d_data;159 delete m_data; 156 160 } 157 161 … … 165 169 166 170 \return Calculated height 167 */ 171 */ 168 172 double QwtPlainTextEngine::heightForWidth( const QFont& font, int flags, 169 const QString& text, double width ) const173 const QString& text, double width ) const 170 174 { 171 175 const QFontMetricsF fm( font ); … … 177 181 178 182 /*! 179 Returns the size, that is needed to render text 180 181 \param font Font of the text 182 \param flags Bitwise OR of the flags used like in QPainter::drawText 183 \param text Text to be rendered 184 185 \return Calculated size 186 */ 187 QSizeF QwtPlainTextEngine::textSize( const QFont &font,183 Returns the size, that is needed to render text 184 185 \param font Font of the text 186 \param flags Bitwise OR of the flags used like in QPainter::drawText 187 \param text Text to be rendered 188 189 \return Calculated size 190 */ 191 QSizeF QwtPlainTextEngine::textSize( const QFont& font, 188 192 int flags, const QString& text ) const 189 193 { … … 196 200 197 201 /*! 198 Return margins around the texts 199 200 \param font Font of the text 201 \param left Return 0 202 \param right Return 0 203 \param top Return value for the top margin 204 \param bottom Return value for the bottom margin 205 */ 206 void QwtPlainTextEngine::textMargins( const QFont &font, const QString&,207 double &left, double&right, double&top, double&bottom ) const202 Return margins around the texts 203 204 \param font Font of the text 205 \param left Return 0 206 \param right Return 0 207 \param top Return value for the top margin 208 \param bottom Return value for the bottom margin 209 */ 210 void QwtPlainTextEngine::textMargins( const QFont& font, const QString&, 211 double& left, double& right, double& top, double& bottom ) const 208 212 { 209 213 left = right = top = 0; 210 214 211 215 const QFontMetricsF fm( font ); 212 top = fm.ascent() - d_data->effectiveAscent( font );216 top = fm.ascent() - m_data->effectiveAscent( font ); 213 217 bottom = fm.descent(); 214 218 } 215 219 216 220 /*! 217 \brief Draw the text in a clipping rectangle 218 219 A wrapper for QPainter::drawText. 220 221 \param painter Painter 222 \param rect Clipping rectangle 223 \param flags Bitwise OR of the flags used like in QPainter::drawText 224 \param text Text to be rendered 225 */ 226 void QwtPlainTextEngine::draw( QPainter *painter, const QRectF&rect,221 \brief Draw the text in a clipping rectangle 222 223 A wrapper for QPainter::drawText. 224 225 \param painter Painter 226 \param rect Clipping rectangle 227 \param flags Bitwise OR of the flags used like in QPainter::drawText 228 \param text Text to be rendered 229 */ 230 void QwtPlainTextEngine::draw( QPainter* painter, const QRectF& rect, 227 231 int flags, const QString& text ) const 228 232 { … … 231 235 232 236 /*! 233 Test if a string can be rendered by this text engine. 234 \return Always true. All texts can be rendered by QwtPlainTextEngine 235 */ 236 bool QwtPlainTextEngine::mightRender( const QString & ) const237 Test if a string can be rendered by this text engine. 238 \return Always true. All texts can be rendered by QwtPlainTextEngine 239 */ 240 bool QwtPlainTextEngine::mightRender( const QString& ) const 237 241 { 238 242 return true; … … 255 259 256 260 \return Calculated height 257 */ 261 */ 258 262 double QwtRichTextEngine::heightForWidth( const QFont& font, int flags, 259 const QString& text, double width ) const263 const QString& text, double width ) const 260 264 { 261 265 QwtRichTextDocument doc( text, flags, font ); … … 266 270 267 271 /*! 268 Returns the size, that is needed to render text 269 270 \param font Font of the text 271 \param flags Bitwise OR of the flags used like in QPainter::drawText() 272 \param text Text to be rendered 273 274 \return Calculated size 275 */ 276 277 QSizeF QwtRichTextEngine::textSize( const QFont &font,272 Returns the size, that is needed to render text 273 274 \param font Font of the text 275 \param flags Bitwise OR of the flags used like in QPainter::drawText() 276 \param text Text to be rendered 277 278 \return Calculated size 279 */ 280 281 QSizeF QwtRichTextEngine::textSize( const QFont& font, 278 282 int flags, const QString& text ) const 279 283 { … … 292 296 293 297 /*! 294 Draw the text in a clipping rectangle 295 296 \param painter Painter 297 \param rect Clipping rectangle 298 \param flags Bitwise OR of the flags like in for QPainter::drawText() 299 \param text Text to be rendered 300 */ 301 void QwtRichTextEngine::draw( QPainter *painter, const QRectF&rect,298 Draw the text in a clipping rectangle 299 300 \param painter Painter 301 \param rect Clipping rectangle 302 \param flags Bitwise OR of the flags like in for QPainter::drawText() 303 \param text Text to be rendered 304 */ 305 void QwtRichTextEngine::draw( QPainter* painter, const QRectF& rect, 302 306 int flags, const QString& text ) const 303 307 { … … 313 317 314 318 \return Tagged text 315 */ 316 QString QwtRichTextEngine::taggedText( const QString &text, int flags ) const319 */ 320 QString QwtRichTextEngine::taggedText( const QString& text, int flags ) const 317 321 { 318 322 return taggedRichText( text, flags ); … … 320 324 321 325 /*! 322 Test if a string can be rendered by this text engine 323 324 \param text Text to be tested 325 \return Qt::mightBeRichText(text); 326 */ 327 bool QwtRichTextEngine::mightRender( const QString &text ) const326 Test if a string can be rendered by this text engine 327 328 \param text Text to be tested 329 \return Qt::mightBeRichText(text); 330 */ 331 bool QwtRichTextEngine::mightRender( const QString& text ) const 328 332 { 329 333 return Qt::mightBeRichText( text ); … … 331 335 332 336 /*! 333 Return margins around the texts 334 335 \param left Return 0 336 \param right Return 0 337 \param top Return 0 338 \param bottom Return 0 339 */ 340 void QwtRichTextEngine::textMargins( const QFont &, const QString&,341 double &left, double&right, double&top, double&bottom ) const337 Return margins around the texts 338 339 \param left Return 0 340 \param right Return 0 341 \param top Return 0 342 \param bottom Return 0 343 */ 344 void QwtRichTextEngine::textMargins( const QFont&, const QString&, 345 double& left, double& right, double& top, double& bottom ) const 342 346 { 343 347 left = right = top = bottom = 0; -
trunk/BNC/qwt/qwt_text_engine.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_TEXT_ENGINE_H 11 #define QWT_TEXT_ENGINE_H 111 #define QWT_TEXT_ENGINE_H 12 12 13 13 #include "qwt_global.h" … … 20 20 21 21 /*! 22 \brief Abstract base class for rendering text strings 22 \brief Abstract base class for rendering text strings 23 23 24 A text engine is responsible for rendering texts for a 25 specific text format. They are used by QwtText to render a text. 24 A text engine is responsible for rendering texts for a 25 specific text format. They are used by QwtText to render a text. 26 26 27 QwtPlainTextEngine and QwtRichTextEngine are part of the Qwt library. 28 The implementation of QwtMathMLTextEngine uses code from the 29 Qt solution package. Because of license implications it is built into 30 a separate library. 31 32 \sa QwtText::setTextEngine() 33 */ 27 \sa QwtText::setTextEngine() 28 */ 34 29 35 30 class QWT_EXPORT QwtTextEngine 36 31 { 37 public: 32 public: 38 33 virtual ~QwtTextEngine(); 39 34 40 35 /*! 41 Find the height for a given width 36 Find the height for a given width 42 37 43 \param font Font of the text 44 \param flags Bitwise OR of the flags used like in QPainter::drawText 45 \param text Text to be rendered 46 \param width Width 38 \param font Font of the text 39 \param flags Bitwise OR of the flags used like in QPainter::drawText 40 \param text Text to be rendered 41 \param width Width 47 42 48 \return Calculated height 43 \return Calculated height 49 44 */ 50 virtual double heightForWidth( const QFont &font, int flags,51 const QString &text, double width ) const = 0;45 virtual double heightForWidth( const QFont& font, int flags, 46 const QString& text, double width ) const = 0; 52 47 53 48 /*! 54 Returns the size, that is needed to render text 49 Returns the size, that is needed to render text 55 50 56 \param font Font of the text 57 \param flags Bitwise OR of the flags like in for QPainter::drawText 58 \param text Text to be rendered 51 \param font Font of the text 52 \param flags Bitwise OR of the flags like in for QPainter::drawText 53 \param text Text to be rendered 59 54 60 \return Calculated size 55 \return Calculated size 61 56 */ 62 virtual QSizeF textSize( const QFont &font, int flags,63 const QString &text ) const = 0;57 virtual QSizeF textSize( const QFont& font, int flags, 58 const QString& text ) const = 0; 64 59 65 60 /*! 66 Test if a string can be rendered by this text engine 61 Test if a string can be rendered by this text engine 67 62 68 \param text Text to be tested 69 \return true, if it can be rendered 63 \param text Text to be tested 64 \return true, if it can be rendered 70 65 */ 71 virtual bool mightRender( const QString &text ) const = 0;66 virtual bool mightRender( const QString& text ) const = 0; 72 67 73 68 /*! 74 Return margins around the texts 69 Return margins around the texts 75 70 76 The textSize might include margins around the 77 text, like QFontMetrics::descent(). In situations 78 where texts need to be aligned in detail, knowing 79 these margins might improve the layout calculations. 71 The textSize might include margins around the 72 text, like QFontMetrics::descent(). In situations 73 where texts need to be aligned in detail, knowing 74 these margins might improve the layout calculations. 80 75 81 \param font Font of the text 82 \param text Text to be rendered 83 \param left Return value for the left margin 84 \param right Return value for the right margin 85 \param top Return value for the top margin 86 \param bottom Return value for the bottom margin 76 \param font Font of the text 77 \param text Text to be rendered 78 \param left Return value for the left margin 79 \param right Return value for the right margin 80 \param top Return value for the top margin 81 \param bottom Return value for the bottom margin 87 82 */ 88 virtual void textMargins( const QFont &font, const QString&text,89 double &left, double&right, double&top, double&bottom ) const = 0;83 virtual void textMargins( const QFont& font, const QString& text, 84 double& left, double& right, double& top, double& bottom ) const = 0; 90 85 91 86 /*! 92 Draw the text in a clipping rectangle 87 Draw the text in a clipping rectangle 93 88 94 \param painter Painter 95 \param rect Clipping rectangle 96 \param flags Bitwise OR of the flags like in for QPainter::drawText() 97 \param text Text to be rendered 89 \param painter Painter 90 \param rect Clipping rectangle 91 \param flags Bitwise OR of the flags like in for QPainter::drawText() 92 \param text Text to be rendered 98 93 */ 99 virtual void draw( QPainter *painter, const QRectF&rect,100 int flags, const QString &text ) const = 0;94 virtual void draw( QPainter* painter, const QRectF& rect, 95 int flags, const QString& text ) const = 0; 101 96 102 protected: 97 protected: 103 98 QwtTextEngine(); 99 100 private: 101 Q_DISABLE_COPY(QwtTextEngine) 104 102 }; 105 103 106 104 107 105 /*! 108 \brief A text engine for plain texts 106 \brief A text engine for plain texts 109 107 110 QwtPlainTextEngine renders texts using the basic Qt classes 111 QPainter and QFontMetrics. 112 */ 113 class QWT_EXPORT QwtPlainTextEngine: public QwtTextEngine 108 QwtPlainTextEngine renders texts using the basic Qt classes 109 QPainter and QFontMetrics. 110 */ 111 class QWT_EXPORT QwtPlainTextEngine : public QwtTextEngine 114 112 { 115 public: 113 public: 116 114 QwtPlainTextEngine(); 117 115 virtual ~QwtPlainTextEngine(); 118 116 119 virtual double heightForWidth( const QFont &font, int flags,120 const QString &text, double width ) const;117 virtual double heightForWidth( const QFont& font, int flags, 118 const QString& text, double width ) const QWT_OVERRIDE; 121 119 122 virtual QSizeF textSize( const QFont &font, int flags,123 const QString &text ) const;120 virtual QSizeF textSize( const QFont& font, int flags, 121 const QString& text ) const QWT_OVERRIDE; 124 122 125 virtual void draw( QPainter *painter, const QRectF&rect,126 int flags, const QString &text ) const;123 virtual void draw( QPainter*, const QRectF& rect, 124 int flags, const QString& text ) const QWT_OVERRIDE; 127 125 128 virtual bool mightRender( const QString & ) const;126 virtual bool mightRender( const QString& ) const QWT_OVERRIDE; 129 127 130 virtual void textMargins( const QFont &, const QString &, 131 double &left, double &right, double &top, double &bottom ) const; 128 virtual void textMargins( 129 const QFont&, const QString&, 130 double& left, double& right, 131 double& top, double& bottom ) const QWT_OVERRIDE; 132 132 133 private: 133 private: 134 134 class PrivateData; 135 PrivateData *d_data;135 PrivateData* m_data; 136 136 }; 137 137 … … 140 140 141 141 /*! 142 \brief A text engine for Qt rich texts 142 \brief A text engine for Qt rich texts 143 143 144 QwtRichTextEngine renders Qt rich texts using the classes 145 of the Scribe framework of Qt. 146 */ 147 class QWT_EXPORT QwtRichTextEngine: public QwtTextEngine 144 QwtRichTextEngine renders Qt rich texts using the classes 145 of the Scribe framework of Qt. 146 */ 147 class QWT_EXPORT QwtRichTextEngine : public QwtTextEngine 148 148 { 149 public: 149 public: 150 150 QwtRichTextEngine(); 151 151 152 virtual double heightForWidth( const QFont &font, int flags,153 const QString &text, double width ) const;152 virtual double heightForWidth( const QFont& font, int flags, 153 const QString& text, double width ) const QWT_OVERRIDE; 154 154 155 virtual QSizeF textSize( const QFont &font, int flags,156 const QString &text ) const;155 virtual QSizeF textSize( const QFont& font, int flags, 156 const QString& text ) const QWT_OVERRIDE; 157 157 158 virtual void draw( QPainter *painter, const QRectF&rect,159 int flags, const QString &text ) const;158 virtual void draw( QPainter*, const QRectF& rect, 159 int flags, const QString& text ) const QWT_OVERRIDE; 160 160 161 virtual bool mightRender( const QString & ) const;161 virtual bool mightRender( const QString& ) const QWT_OVERRIDE; 162 162 163 virtual void textMargins( const QFont &, const QString &, 164 double &left, double &right, double &top, double &bottom ) const; 163 virtual void textMargins( 164 const QFont&, const QString&, 165 double& left, double& right, 166 double& top, double& bottom ) const QWT_OVERRIDE; 165 167 166 private: 167 QString taggedText( const QString &, int flags ) const;168 private: 169 QString taggedText( const QString&, int flags ) const; 168 170 }; 169 171 -
trunk/BNC/qwt/qwt_text_label.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_text.h" 12 12 #include "qwt_painter.h" 13 #include "qwt_math.h" 14 15 #include <qstyle.h> 16 #include <qstyleoption.h> 13 17 #include <qpainter.h> 14 18 #include <qevent.h> 15 #include <qma th.h>19 #include <qmargins.h> 16 20 17 21 class QwtTextLabel::PrivateData 18 22 { 19 public: 20 PrivateData() :21 indent( 4 ) ,22 margin( 0 ) 23 public: 24 PrivateData() 25 : indent( 4 ) 26 , margin( 0 ) 23 27 { 24 28 } … … 30 34 31 35 /*! 32 Constructs an empty label. 33 \param parent Parent widget 34 */ 35 QwtTextLabel::QwtTextLabel( QWidget *parent ):36 QFrame( parent ) 36 Constructs an empty label. 37 \param parent Parent widget 38 */ 39 QwtTextLabel::QwtTextLabel( QWidget* parent ) 40 : QFrame( parent ) 37 41 { 38 42 init(); … … 40 44 41 45 /*! 42 Constructs a label that displays the text, text 43 \param parent Parent widget 44 \param text Text 45 */ 46 QwtTextLabel::QwtTextLabel( const QwtText &text, QWidget*parent ):47 QFrame( parent ) 46 Constructs a label that displays the text, text 47 \param parent Parent widget 48 \param text Text 49 */ 50 QwtTextLabel::QwtTextLabel( const QwtText& text, QWidget* parent ) 51 : QFrame( parent ) 48 52 { 49 53 init(); 50 d_data->text = text;54 m_data->text = text; 51 55 } 52 56 … … 54 58 QwtTextLabel::~QwtTextLabel() 55 59 { 56 delete d_data;60 delete m_data; 57 61 } 58 62 59 63 void QwtTextLabel::init() 60 64 { 61 d_data = new PrivateData();65 m_data = new PrivateData(); 62 66 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); 63 67 } … … 67 71 \sa plainText() 68 72 */ 69 void QwtTextLabel::setPlainText( const QString &text )73 void QwtTextLabel::setPlainText( const QString& text ) 70 74 { 71 75 setText( QwtText( text ) ); … … 80 84 QString QwtTextLabel::plainText() const 81 85 { 82 return d_data->text.text();86 return m_data->text.text(); 83 87 } 84 88 … … 88 92 \param textFormat Format of text 89 93 90 \sa QwtText 91 */ 92 void QwtTextLabel::setText( const QString &text,94 \sa QwtText 95 */ 96 void QwtTextLabel::setText( const QString& text, 93 97 QwtText::TextFormat textFormat ) 94 98 { 95 d_data->text.setText( text, textFormat );99 m_data->text.setText( text, textFormat ); 96 100 97 101 update(); … … 102 106 Change the label's text 103 107 \param text New text 104 */ 105 void QwtTextLabel::setText( const QwtText &text )106 { 107 d_data->text = text;108 */ 109 void QwtTextLabel::setText( const QwtText& text ) 110 { 111 m_data->text = text; 108 112 109 113 update(); … … 112 116 113 117 //! Return the text 114 const QwtText &QwtTextLabel::text() const115 { 116 return d_data->text;118 const QwtText& QwtTextLabel::text() const 119 { 120 return m_data->text; 117 121 } 118 122 … … 120 124 void QwtTextLabel::clear() 121 125 { 122 d_data->text = QwtText();126 m_data->text = QwtText(); 123 127 124 128 update(); … … 129 133 int QwtTextLabel::indent() const 130 134 { 131 return d_data->indent;132 } 133 134 /*! 135 Set label's text indent in pixels 136 \param indent Indentation in pixels 137 */ 135 return m_data->indent; 136 } 137 138 /*! 139 Set label's text indent in pixels 140 \param indent Indentation in pixels 141 */ 138 142 void QwtTextLabel::setIndent( int indent ) 139 143 { … … 141 145 indent = 0; 142 146 143 d_data->indent = indent;147 m_data->indent = indent; 144 148 145 149 update(); … … 150 154 int QwtTextLabel::margin() const 151 155 { 152 return d_data->margin;153 } 154 155 /*! 156 Set label's margin in pixels 157 \param margin Margin in pixels 158 */ 156 return m_data->margin; 157 } 158 159 /*! 160 Set label's margin in pixels 161 \param margin Margin in pixels 162 */ 159 163 void QwtTextLabel::setMargin( int margin ) 160 164 { 161 d_data->margin = margin;165 m_data->margin = margin; 162 166 163 167 update(); … … 174 178 QSize QwtTextLabel::minimumSizeHint() const 175 179 { 176 QSizeF sz = d_data->text.textSize( font() ); 177 178 int mw = 2 * ( frameWidth() + d_data->margin ); 179 int mh = mw; 180 181 int indent = d_data->indent; 180 QSizeF sz = m_data->text.textSize( font() ); 181 182 const QMargins m = contentsMargins(); 183 184 int mw = m.left() + m.right() + 2 * m_data->margin; 185 int mh = m.top() + m.bottom() + 2 * m_data->margin; 186 187 int indent = m_data->indent; 182 188 if ( indent <= 0 ) 183 189 indent = defaultIndent(); … … 185 191 if ( indent > 0 ) 186 192 { 187 const int align = d_data->text.renderFlags();193 const int align = m_data->text.renderFlags(); 188 194 if ( align & Qt::AlignLeft || align & Qt::AlignRight ) 189 mw += d_data->indent;195 mw += m_data->indent; 190 196 else if ( align & Qt::AlignTop || align & Qt::AlignBottom ) 191 mh += d_data->indent;197 mh += m_data->indent; 192 198 } 193 199 194 200 sz += QSizeF( mw, mh ); 195 201 196 return QSize( qCeil( sz.width() ), qCeil( sz.height() ) ); 202 return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) ); 197 203 } 198 204 … … 200 206 \param width Width 201 207 \return Preferred height for this widget, given the width. 202 */ 208 */ 203 209 int QwtTextLabel::heightForWidth( int width ) const 204 210 { 205 const int renderFlags = d_data->text.renderFlags();206 207 int indent = d_data->indent;211 const int renderFlags = m_data->text.renderFlags(); 212 213 int indent = m_data->indent; 208 214 if ( indent <= 0 ) 209 215 indent = defaultIndent(); 210 216 211 width -= 2 * frameWidth(); 217 const QMargins m = contentsMargins(); 218 219 width -= m.left() + m.right() - 2 * m_data->margin; 212 220 if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight ) 213 221 width -= indent; 214 222 215 int height = q Ceil( d_data->text.heightForWidth( width, font() ) );223 int height = qwtCeil( m_data->text.heightForWidth( width, font() ) ); 216 224 if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) ) 217 225 height += indent; 218 226 219 height += 2 * frameWidth();227 height += m.top() + m.bottom() + 2 * m_data->margin; 220 228 221 229 return height; … … 225 233 Qt paint event 226 234 \param event Paint event 227 */ 228 void QwtTextLabel::paintEvent( QPaintEvent *event )235 */ 236 void QwtTextLabel::paintEvent( QPaintEvent* event ) 229 237 { 230 238 QPainter painter( this ); 239 painter.setClipRegion( event->region() ); 240 241 QStyleOption opt; 242 opt.initFrom(this); 243 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 231 244 232 245 if ( !contentsRect().contains( event->rect() ) ) 233 246 { 234 painter.save();235 247 painter.setClipRegion( event->region() & frameRect() ); 236 248 drawFrame( &painter ); 237 painter.restore();238 249 } 239 250 … … 244 255 245 256 //! Redraw the text and focus indicator 246 void QwtTextLabel::drawContents( QPainter *painter )257 void QwtTextLabel::drawContents( QPainter* painter ) 247 258 { 248 259 const QRect r = textRect(); … … 266 277 267 278 //! Redraw the text 268 void QwtTextLabel::drawText( QPainter *painter, const QRectF&textRect )269 { 270 d_data->text.draw( painter, textRect );271 } 272 273 /*! 274 Calculate geometry for the text in widget coordinates 275 \return Geometry for the text 276 */ 279 void QwtTextLabel::drawText( QPainter* painter, const QRectF& textRect ) 280 { 281 m_data->text.draw( painter, textRect ); 282 } 283 284 /*! 285 Calculate geometry for the text in widget coordinates 286 \return Geometry for the text 287 */ 277 288 QRect QwtTextLabel::textRect() const 278 289 { 279 290 QRect r = contentsRect(); 280 291 281 if ( !r.isEmpty() && d_data->margin > 0 )282 { 283 r.setRect( r.x() + d_data->margin, r.y() + d_data->margin,284 r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin);292 if ( !r.isEmpty() && m_data->margin > 0 ) 293 { 294 const int m = m_data->margin; 295 r.adjust( m, m, -m, -m ); 285 296 } 286 297 287 298 if ( !r.isEmpty() ) 288 299 { 289 int indent = d_data->indent;300 int indent = m_data->indent; 290 301 if ( indent <= 0 ) 291 302 indent = defaultIndent(); … … 293 304 if ( indent > 0 ) 294 305 { 295 const int renderFlags = d_data->text.renderFlags();306 const int renderFlags = m_data->text.renderFlags(); 296 307 297 308 if ( renderFlags & Qt::AlignLeft ) 309 { 298 310 r.setX( r.x() + indent ); 311 } 299 312 else if ( renderFlags & Qt::AlignRight ) 313 { 300 314 r.setWidth( r.width() - indent ); 315 } 301 316 else if ( renderFlags & Qt::AlignTop ) 317 { 302 318 r.setY( r.y() + indent ); 319 } 303 320 else if ( renderFlags & Qt::AlignBottom ) 321 { 304 322 r.setHeight( r.height() - indent ); 323 } 305 324 } 306 325 } … … 315 334 316 335 QFont fnt; 317 if ( d_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )318 fnt = d_data->text.font();336 if ( m_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) 337 fnt = m_data->text.font(); 319 338 else 320 339 fnt = font(); 321 340 322 return QFontMetrics( fnt ).width( 'x' ) / 2; 323 } 324 341 return QwtPainter::horizontalAdvance( QFontMetrics( fnt ), 'x' ) / 2; 342 } 343 344 #include "moc_qwt_text_label.cpp" -
trunk/BNC/qwt/qwt_text_label.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include "qwt_text.h" 15 15 16 #include <qframe.h> 16 17 … … 21 22 /*! 22 23 \brief A Widget which displays a QwtText 23 */ 24 */ 24 25 25 26 class QWT_EXPORT QwtTextLabel : public QFrame … … 31 32 Q_PROPERTY( QString plainText READ plainText WRITE setPlainText ) 32 33 33 public: 34 explicit QwtTextLabel( QWidget *parent = NULL );35 explicit QwtTextLabel( const QwtText &, QWidget*parent = NULL );34 public: 35 explicit QwtTextLabel( QWidget* parent = NULL ); 36 explicit QwtTextLabel( const QwtText&, QWidget* parent = NULL ); 36 37 virtual ~QwtTextLabel(); 37 38 38 void setPlainText( const QString & );39 void setPlainText( const QString& ); 39 40 QString plainText() const; 40 41 41 public Q_SLOTS: 42 void setText( const QString &,42 public Q_SLOTS: 43 void setText( const QString&, 43 44 QwtText::TextFormat textFormat = QwtText::AutoText ); 44 virtual void setText( const QwtText & );45 virtual void setText( const QwtText& ); 45 46 46 47 void clear(); 47 48 48 public: 49 const QwtText &text() const;49 public: 50 const QwtText& text() const; 50 51 51 52 int indent() const; … … 55 56 void setMargin( int ); 56 57 57 virtual QSize sizeHint() const; 58 virtual QSize minimumSizeHint() const; 59 virtual int heightForWidth( int ) const; 58 virtual QSize sizeHint() const QWT_OVERRIDE; 59 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 60 virtual int heightForWidth( int ) const QWT_OVERRIDE; 60 61 61 62 QRect textRect() const; 62 63 63 virtual void drawText( QPainter *, const QRectF& );64 virtual void drawText( QPainter*, const QRectF& ); 64 65 65 protected: 66 virtual void paintEvent( QPaintEvent * );67 virtual void drawContents( QPainter * );66 protected: 67 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 68 virtual void drawContents( QPainter* ); 68 69 69 private: 70 private: 70 71 void init(); 71 72 int defaultIndent() const; 72 73 73 74 class PrivateData; 74 PrivateData *d_data;75 PrivateData* m_data; 75 76 }; 76 77 -
trunk/BNC/qwt/qwt_thermo.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_thermo.h" 11 #include "qwt_scale_engine.h"12 11 #include "qwt_scale_draw.h" 13 12 #include "qwt_scale_map.h" 14 13 #include "qwt_color_map.h" 14 #include "qwt_math.h" 15 15 16 #include <qpainter.h> 16 17 #include <qevent.h> … … 18 19 #include <qstyle.h> 19 20 #include <qstyleoption.h> 20 #include <qmath.h> 21 22 static inline void qwtDrawLine( QPainter *painter, int pos, 23 const QColor &color, const QRect &pipeRect, const QRect &liquidRect, 21 #include <qmargins.h> 22 23 #include <algorithm> 24 #include <functional> 25 26 static inline void qwtDrawLine( QPainter* painter, int pos, 27 const QColor& color, const QRect& pipeRect, const QRect& liquidRect, 24 28 Qt::Orientation orientation ) 25 29 { … … 37 41 } 38 42 39 QVector< double> qwtTickList( const QwtScaleDiv&scaleDiv )40 { 41 QVector< double> values;43 static QVector< double > qwtTickList( const QwtScaleDiv& scaleDiv ) 44 { 45 QVector< double > values; 42 46 43 47 double lowerLimit = scaleDiv.interval().minValue(); … … 52 56 tickType < QwtScaleDiv::NTickTypes; tickType++ ) 53 57 { 54 const QList< double> ticks = scaleDiv.ticks( tickType );58 const QList< double > ticks = scaleDiv.ticks( tickType ); 55 59 56 60 for ( int i = 0; i < ticks.count(); i++ ) … … 69 73 class QwtThermo::PrivateData 70 74 { 71 public: 72 PrivateData() :73 orientation( Qt::Vertical ) ,74 scalePosition( QwtThermo::TrailingScale ) ,75 spacing( 3 ) ,76 borderWidth( 2 ) ,77 pipeWidth( 10 ) ,78 alarmLevel( 0.0 ) ,79 alarmEnabled( false ) ,80 autoFillPipe( true ) ,81 originMode( QwtThermo::OriginMinimum ) ,82 origin( 0.0 ) ,83 colorMap( NULL ) ,84 value( 0.0 ) 75 public: 76 PrivateData() 77 : orientation( Qt::Vertical ) 78 , scalePosition( QwtThermo::TrailingScale ) 79 , spacing( 3 ) 80 , borderWidth( 2 ) 81 , pipeWidth( 10 ) 82 , alarmLevel( 0.0 ) 83 , alarmEnabled( false ) 84 , autoFillPipe( true ) 85 , originMode( QwtThermo::OriginMinimum ) 86 , origin( 0.0 ) 87 , colorMap( NULL ) 88 , value( 0.0 ) 85 89 { 86 90 rangeFlags = QwtInterval::IncludeBorders; … … 106 110 double origin; 107 111 108 QwtColorMap *colorMap;112 QwtColorMap* colorMap; 109 113 110 114 double value; … … 112 116 113 117 /*! 114 Constructor 115 \param parent Parent widget 116 */ 117 QwtThermo::QwtThermo( QWidget *parent ):118 QwtAbstractScale( parent ) 119 { 120 d_data = new PrivateData;118 Constructor 119 \param parent Parent widget 120 */ 121 QwtThermo::QwtThermo( QWidget* parent ) 122 : QwtAbstractScale( parent ) 123 { 124 m_data = new PrivateData; 121 125 122 126 QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); 123 if ( d_data->orientation == Qt::Vertical )127 if ( m_data->orientation == Qt::Vertical ) 124 128 policy.transpose(); 125 129 … … 133 137 QwtThermo::~QwtThermo() 134 138 { 135 delete d_data;136 } 137 138 /*! 139 \brief Exclude/Include min/max values 140 141 According to the flags minValue() and maxValue() 142 are included/excluded from the pipe. In case of an 143 excluded value the corresponding tick is painted 144 1 pixel off of the pipeRect(). 145 146 F.e. when a minimum 147 of 0.0 has to be displayed as an empty pipe the minValue() 148 needs to be excluded. 149 150 \param flags Range flags 151 \sa rangeFlags() 152 */ 139 delete m_data; 140 } 141 142 /*! 143 \brief Exclude/Include min/max values 144 145 According to the flags minValue() and maxValue() 146 are included/excluded from the pipe. In case of an 147 excluded value the corresponding tick is painted 148 1 pixel off of the pipeRect(). 149 150 F.e. when a minimum 151 of 0.0 has to be displayed as an empty pipe the minValue() 152 needs to be excluded. 153 154 \param flags Range flags 155 \sa rangeFlags() 156 */ 153 157 void QwtThermo::setRangeFlags( QwtInterval::BorderFlags flags ) 154 158 { 155 if ( d_data->rangeFlags != flags )156 { 157 d_data->rangeFlags = flags;159 if ( m_data->rangeFlags != flags ) 160 { 161 m_data->rangeFlags = flags; 158 162 update(); 159 163 } … … 161 165 162 166 /*! 163 \return Range flags 164 \sa setRangeFlags() 165 */ 167 \return Range flags 168 \sa setRangeFlags() 169 */ 166 170 QwtInterval::BorderFlags QwtThermo::rangeFlags() const 167 171 { 168 return d_data->rangeFlags;169 } 170 171 /*! 172 Set the current value. 173 174 \param value New Value 175 \sa value() 176 */ 172 return m_data->rangeFlags; 173 } 174 175 /*! 176 Set the current value. 177 178 \param value New Value 179 \sa value() 180 */ 177 181 void QwtThermo::setValue( double value ) 178 182 { 179 if ( d_data->value != value )180 { 181 d_data->value = value;183 if ( m_data->value != value ) 184 { 185 m_data->value = value; 182 186 update(); 183 187 } … … 187 191 double QwtThermo::value() const 188 192 { 189 return d_data->value;190 } 191 192 /*! 193 \brief Set a scale draw 194 195 For changing the labels of the scales, it 196 is necessary to derive from QwtScaleDraw and 197 overload QwtScaleDraw::label(). 198 199 \param scaleDraw ScaleDraw object, that has to be created with 193 return m_data->value; 194 } 195 196 /*! 197 \brief Set a scale draw 198 199 For changing the labels of the scales, it 200 is necessary to derive from QwtScaleDraw and 201 overload QwtScaleDraw::label(). 202 203 \param scaleDraw ScaleDraw object, that has to be created with 200 204 new and will be deleted in ~QwtThermo() or the next 201 205 call of setScaleDraw(). 202 */ 203 void QwtThermo::setScaleDraw( QwtScaleDraw *scaleDraw )206 */ 207 void QwtThermo::setScaleDraw( QwtScaleDraw* scaleDraw ) 204 208 { 205 209 setAbstractScaleDraw( scaleDraw ); … … 210 214 \return the scale draw of the thermo 211 215 \sa setScaleDraw() 212 */ 213 const QwtScaleDraw *QwtThermo::scaleDraw() const214 { 215 return static_cast<const QwtScaleDraw *>( abstractScaleDraw() );216 */ 217 const QwtScaleDraw* QwtThermo::scaleDraw() const 218 { 219 return static_cast< const QwtScaleDraw* >( abstractScaleDraw() ); 216 220 } 217 221 … … 219 223 \return the scale draw of the thermo 220 224 \sa setScaleDraw() 221 */ 222 QwtScaleDraw *QwtThermo::scaleDraw()223 { 224 return static_cast<QwtScaleDraw *>( abstractScaleDraw() );225 } 226 227 /*! 228 Paint event handler 229 \param event Paint event 230 */ 231 void QwtThermo::paintEvent( QPaintEvent *event )225 */ 226 QwtScaleDraw* QwtThermo::scaleDraw() 227 { 228 return static_cast< QwtScaleDraw* >( abstractScaleDraw() ); 229 } 230 231 /*! 232 Paint event handler 233 \param event Paint event 234 */ 235 void QwtThermo::paintEvent( QPaintEvent* event ) 232 236 { 233 237 QPainter painter( this ); … … 235 239 236 240 QStyleOption opt; 237 opt.init(this); 241 opt.initFrom(this); 238 242 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 239 243 … … 242 246 if ( !tRect.contains( event->rect() ) ) 243 247 { 244 if ( d_data->scalePosition != QwtThermo::NoScale )248 if ( m_data->scalePosition != QwtThermo::NoScale ) 245 249 scaleDraw()->draw( &painter, palette() ); 246 250 } 247 251 248 const int bw = d_data->borderWidth;252 const int bw = m_data->borderWidth; 249 253 250 254 const QBrush brush = palette().brush( QPalette::Base ); … … 252 256 tRect.adjusted( -bw, -bw, bw, bw ), 253 257 palette(), true, bw, 254 d_data->autoFillPipe ? &brush : NULL );258 m_data->autoFillPipe ? &brush : NULL ); 255 259 256 260 drawLiquid( &painter, tRect ); … … 258 262 259 263 /*! 260 Resize event handler 261 \param event Resize event 262 */ 263 void QwtThermo::resizeEvent( QResizeEvent *event )264 Resize event handler 265 \param event Resize event 266 */ 267 void QwtThermo::resizeEvent( QResizeEvent* event ) 264 268 { 265 269 Q_UNUSED( event ); … … 268 272 269 273 /*! 270 Qt change event handler 271 \param event Event 272 */ 273 void QwtThermo::changeEvent( QEvent *event )274 Qt change event handler 275 \param event Event 276 */ 277 void QwtThermo::changeEvent( QEvent* event ) 274 278 { 275 279 switch( event->type() ) … … 287 291 288 292 /*! 289 Recalculate the QwtThermo geometry and layout based on 290 pipeRect() and the fonts. 291 292 \param update_geometry notify the layout system and call update 293 Recalculate the QwtThermo geometry and layout based on 294 pipeRect() and the fonts. 295 296 \param update_geometry notify the layout system and call update 293 297 to redraw the scale 294 */ 298 */ 295 299 void QwtThermo::layoutThermo( bool update_geometry ) 296 300 { 297 301 const QRect tRect = pipeRect(); 298 const int bw = d_data->borderWidth +d_data->spacing;302 const int bw = m_data->borderWidth + m_data->spacing; 299 303 const bool inverted = ( upperBound() < lowerBound() ); 300 304 301 305 int from, to; 302 306 303 if ( d_data->orientation == Qt::Horizontal )307 if ( m_data->orientation == Qt::Horizontal ) 304 308 { 305 309 from = tRect.left(); 306 310 to = tRect.right(); 307 311 308 if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )312 if ( m_data->rangeFlags & QwtInterval::ExcludeMinimum ) 309 313 { 310 314 if ( inverted ) … … 313 317 from--; 314 318 } 315 if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )319 if ( m_data->rangeFlags & QwtInterval::ExcludeMaximum ) 316 320 { 317 321 if ( inverted ) … … 321 325 } 322 326 323 if ( d_data->scalePosition == QwtThermo::TrailingScale )327 if ( m_data->scalePosition == QwtThermo::TrailingScale ) 324 328 { 325 329 scaleDraw()->setAlignment( QwtScaleDraw::TopScale ); … … 339 343 to = tRect.bottom(); 340 344 341 if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )345 if ( m_data->rangeFlags & QwtInterval::ExcludeMinimum ) 342 346 { 343 347 if ( inverted ) … … 346 350 to++; 347 351 } 348 if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )352 if ( m_data->rangeFlags & QwtInterval::ExcludeMaximum ) 349 353 { 350 354 if ( inverted ) … … 354 358 } 355 359 356 if ( d_data->scalePosition == QwtThermo::LeadingScale )360 if ( m_data->scalePosition == QwtThermo::LeadingScale ) 357 361 { 358 362 scaleDraw()->setAlignment( QwtScaleDraw::RightScale ); … … 376 380 377 381 /*! 378 \return Bounding rectangle of the pipe ( without borders ) 382 \return Bounding rectangle of the pipe ( without borders ) 379 383 in widget coordinates 380 */ 384 */ 381 385 QRect QwtThermo::pipeRect() const 382 386 { 383 387 int mbd = 0; 384 if ( d_data->scalePosition != QwtThermo::NoScale )388 if ( m_data->scalePosition != QwtThermo::NoScale ) 385 389 { 386 390 int d1, d2; … … 388 392 mbd = qMax( d1, d2 ); 389 393 } 390 const int bw = d_data->borderWidth;394 const int bw = m_data->borderWidth; 391 395 const int scaleOff = bw + mbd; 392 396 … … 394 398 395 399 QRect pipeRect = cr; 396 if ( d_data->orientation == Qt::Horizontal )400 if ( m_data->orientation == Qt::Horizontal ) 397 401 { 398 402 pipeRect.adjust( scaleOff, 0, -scaleOff, 0 ); 399 403 400 if ( d_data->scalePosition == QwtThermo::TrailingScale )401 pipeRect.setTop( cr.top() + cr.height() - bw - d_data->pipeWidth );404 if ( m_data->scalePosition == QwtThermo::TrailingScale ) 405 pipeRect.setTop( cr.top() + cr.height() - bw - m_data->pipeWidth ); 402 406 else 403 407 pipeRect.setTop( bw ); 404 408 405 pipeRect.setHeight( d_data->pipeWidth );409 pipeRect.setHeight( m_data->pipeWidth ); 406 410 } 407 411 else // Qt::Vertical … … 409 413 pipeRect.adjust( 0, scaleOff, 0, -scaleOff ); 410 414 411 if ( d_data->scalePosition == QwtThermo::LeadingScale )415 if ( m_data->scalePosition == QwtThermo::LeadingScale ) 412 416 pipeRect.setLeft( bw ); 413 417 else 414 pipeRect.setLeft( cr.left() + cr.width() - bw - d_data->pipeWidth );415 416 pipeRect.setWidth( d_data->pipeWidth );418 pipeRect.setLeft( cr.left() + cr.width() - bw - m_data->pipeWidth ); 419 420 pipeRect.setWidth( m_data->pipeWidth ); 417 421 } 418 422 … … 421 425 422 426 /*! 423 \brief Set the orientation. 424 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 425 426 \sa orientation(), scalePosition() 427 */ 427 \brief Set the orientation. 428 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 429 430 \sa orientation(), scalePosition() 431 */ 428 432 void QwtThermo::setOrientation( Qt::Orientation orientation ) 429 433 { 430 if ( orientation == d_data->orientation )434 if ( orientation == m_data->orientation ) 431 435 return; 432 436 433 d_data->orientation = orientation;437 m_data->orientation = orientation; 434 438 435 439 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) … … 446 450 447 451 /*! 448 \return Orientation 449 \sa setOrientation() 450 */ 452 \return Orientation 453 \sa setOrientation() 454 */ 451 455 Qt::Orientation QwtThermo::orientation() const 452 456 { 453 return d_data->orientation;454 } 455 456 /*! 457 \brief Change how the origin is determined. 458 \sa originMode(), serOrigin(), origin() 457 return m_data->orientation; 458 } 459 460 /*! 461 \brief Change how the origin is determined. 462 \sa originMode(), serOrigin(), origin() 459 463 */ 460 464 void QwtThermo::setOriginMode( OriginMode m ) 461 465 { 462 if ( m == d_data->originMode )466 if ( m == m_data->originMode ) 463 467 return; 464 468 465 d_data->originMode = m;469 m_data->originMode = m; 466 470 update(); 467 471 } 468 472 469 473 /*! 470 \return Mode, how the origin is determined. 471 \sa setOriginMode(), serOrigin(), origin() 474 \return Mode, how the origin is determined. 475 \sa setOriginMode(), serOrigin(), origin() 472 476 */ 473 477 QwtThermo::OriginMode QwtThermo::originMode() const 474 478 { 475 return d_data->originMode;476 } 477 478 /*! 479 \brief Specifies the custom origin. 480 481 If originMode is set to OriginCustom this property controls where the 482 liquid starts. 483 484 \param origin New origin level 485 \sa setOriginMode(), originMode(), origin() 479 return m_data->originMode; 480 } 481 482 /*! 483 \brief Specifies the custom origin. 484 485 If originMode is set to OriginCustom this property controls where the 486 liquid starts. 487 488 \param origin New origin level 489 \sa setOriginMode(), originMode(), origin() 486 490 */ 487 491 void QwtThermo::setOrigin( double origin ) 488 492 { 489 if ( origin == d_data->origin )493 if ( origin == m_data->origin ) 490 494 return; 491 495 492 d_data->origin = origin;496 m_data->origin = origin; 493 497 update(); 494 498 } 495 499 496 500 /*! 497 \return Origin of the thermo, when OriginCustom is enabled 498 \sa setOrigin(), setOriginMode(), originMode() 501 \return Origin of the thermo, when OriginCustom is enabled 502 \sa setOrigin(), setOriginMode(), originMode() 499 503 */ 500 504 double QwtThermo::origin() const 501 505 { 502 return d_data->origin;503 } 504 505 /*! 506 \brief Change the position of the scale 507 \param scalePosition Position of the scale. 508 509 \sa ScalePosition, scalePosition() 510 */ 506 return m_data->origin; 507 } 508 509 /*! 510 \brief Change the position of the scale 511 \param scalePosition Position of the scale. 512 513 \sa ScalePosition, scalePosition() 514 */ 511 515 void QwtThermo::setScalePosition( ScalePosition scalePosition ) 512 516 { 513 if ( d_data->scalePosition == scalePosition )517 if ( m_data->scalePosition == scalePosition ) 514 518 return; 515 519 516 d_data->scalePosition = scalePosition;520 m_data->scalePosition = scalePosition; 517 521 518 522 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 523 527 \return Scale position. 524 528 \sa setScalePosition() 525 */ 529 */ 526 530 QwtThermo::ScalePosition QwtThermo::scalePosition() const 527 531 { 528 return d_data->scalePosition;532 return m_data->scalePosition; 529 533 } 530 534 … … 539 543 \param painter Painter 540 544 \param pipeRect Bounding rectangle of the pipe without borders 541 */ 545 */ 542 546 void QwtThermo::drawLiquid( 543 QPainter *painter, const QRect&pipeRect ) const547 QPainter* painter, const QRect& pipeRect ) const 544 548 { 545 549 painter->save(); … … 551 555 QRect liquidRect = fillRect( pipeRect ); 552 556 553 if ( d_data->colorMap != NULL )557 if ( m_data->colorMap != NULL ) 554 558 { 555 559 const QwtInterval interval = scaleDiv().interval().normalized(); … … 558 562 // we calculate the colors for the rounded tick values 559 563 560 QVector< double> values = qwtTickList( scaleDraw()->scaleDiv() );564 QVector< double > values = qwtTickList( scaleDraw()->scaleDiv() ); 561 565 562 566 if ( scaleMap.isInverting() ) 563 qSort( values.begin(), values.end(),qGreater<double>() );567 std::sort( values.begin(), values.end(), std::greater< double >() ); 564 568 else 565 qSort( values.begin(), values.end(),qLess<double>() );569 std::sort( values.begin(), values.end(), std::less< double >() ); 566 570 567 571 int from; … … 570 574 from = qRound( scaleMap.transform( values[0] ) ); 571 575 qwtDrawLine( painter, from, 572 d_data->colorMap->color( interval, values[0] ),573 pipeRect, liquidRect, d_data->orientation );576 m_data->colorMap->color( interval, values[0] ), 577 pipeRect, liquidRect, m_data->orientation ); 574 578 } 575 579 … … 583 587 584 588 qwtDrawLine( painter, pos, 585 d_data->colorMap->color( interval, v ),586 pipeRect, liquidRect, d_data->orientation );589 m_data->colorMap->color( interval, v ), 590 pipeRect, liquidRect, m_data->orientation ); 587 591 } 588 592 589 593 qwtDrawLine( painter, to, 590 d_data->colorMap->color( interval, values[i] ),591 pipeRect, liquidRect, d_data->orientation );594 m_data->colorMap->color( interval, values[i] ), 595 pipeRect, liquidRect, m_data->orientation ); 592 596 593 597 from = to; … … 596 600 else 597 601 { 598 if ( !liquidRect.isEmpty() && d_data->alarmEnabled )602 if ( !liquidRect.isEmpty() && m_data->alarmEnabled ) 599 603 { 600 604 const QRect r = alarmRect( liquidRect ); … … 613 617 614 618 /*! 615 \brief Change the spacing between pipe and scale 616 617 A spacing of 0 means, that the backbone of the scale is below 618 the pipe. 619 620 The default setting is 3 pixels. 621 622 \param spacing Number of pixels 623 \sa spacing(); 624 */ 619 \brief Change the spacing between pipe and scale 620 621 A spacing of 0 means, that the backbone of the scale is below 622 the pipe. 623 624 The default setting is 3 pixels. 625 626 \param spacing Number of pixels 627 \sa spacing(); 628 */ 625 629 void QwtThermo::setSpacing( int spacing ) 626 630 { … … 628 632 spacing = 0; 629 633 630 if ( spacing != d_data->spacing )631 { 632 d_data->spacing = spacing;634 if ( spacing != m_data->spacing ) 635 { 636 m_data->spacing = spacing; 633 637 layoutThermo( true ); 634 638 } … … 636 640 637 641 /*! 638 \return Number of pixels between pipe and scale 639 \sa setSpacing() 640 */ 642 \return Number of pixels between pipe and scale 643 \sa setSpacing() 644 */ 641 645 int QwtThermo::spacing() const 642 646 { 643 return d_data->spacing;647 return m_data->spacing; 644 648 } 645 649 … … 648 652 \param width Border width 649 653 \sa borderWidth() 650 */ 654 */ 651 655 void QwtThermo::setBorderWidth( int width ) 652 656 { … … 654 658 width = 0; 655 659 656 if ( width != d_data->borderWidth )657 { 658 d_data->borderWidth = width;660 if ( width != m_data->borderWidth ) 661 { 662 m_data->borderWidth = width; 659 663 layoutThermo( true ); 660 664 } … … 664 668 \return Border width of the thermometer pipe. 665 669 \sa setBorderWidth() 666 */ 670 */ 667 671 int QwtThermo::borderWidth() const 668 672 { 669 return d_data->borderWidth;670 } 671 672 /*! 673 \brief Assign a color map for the fill color 674 675 \param colorMap Color map 676 \warning The alarm threshold has no effect, when 673 return m_data->borderWidth; 674 } 675 676 /*! 677 \brief Assign a color map for the fill color 678 679 \param colorMap Color map 680 \warning The alarm threshold has no effect, when 677 681 a color map has been assigned 678 */ 679 void QwtThermo::setColorMap( QwtColorMap *colorMap )680 { 681 if ( colorMap != d_data->colorMap )682 { 683 delete d_data->colorMap;684 d_data->colorMap = colorMap;685 } 686 } 687 688 /*! 689 \return Color map for the fill color 690 \warning The alarm threshold has no effect, when 682 */ 683 void QwtThermo::setColorMap( QwtColorMap* colorMap ) 684 { 685 if ( colorMap != m_data->colorMap ) 686 { 687 delete m_data->colorMap; 688 m_data->colorMap = colorMap; 689 } 690 } 691 692 /*! 693 \return Color map for the fill color 694 \warning The alarm threshold has no effect, when 691 695 a color map has been assigned 692 */ 693 QwtColorMap *QwtThermo::colorMap()694 { 695 return d_data->colorMap;696 } 697 698 /*! 699 \return Color map for the fill color 700 \warning The alarm threshold has no effect, when 696 */ 697 QwtColorMap* QwtThermo::colorMap() 698 { 699 return m_data->colorMap; 700 } 701 702 /*! 703 \return Color map for the fill color 704 \warning The alarm threshold has no effect, when 701 705 a color map has been assigned 702 */ 703 const QwtColorMap *QwtThermo::colorMap() const704 { 705 return d_data->colorMap;706 } 707 708 /*! 709 \brief Change the brush of the liquid. 710 711 Changes the QPalette::ButtonText brush of the palette. 712 713 \param brush New brush. 714 \sa fillBrush(), QWidget::setPalette() 715 */ 706 */ 707 const QwtColorMap* QwtThermo::colorMap() const 708 { 709 return m_data->colorMap; 710 } 711 712 /*! 713 \brief Change the brush of the liquid. 714 715 Changes the QPalette::ButtonText brush of the palette. 716 717 \param brush New brush. 718 \sa fillBrush(), QWidget::setPalette() 719 */ 716 720 void QwtThermo::setFillBrush( const QBrush& brush ) 717 721 { … … 722 726 723 727 /*! 724 \return Liquid ( QPalette::ButtonText ) brush. 725 \sa setFillBrush(), QWidget::palette() 726 */ 728 \return Liquid ( QPalette::ButtonText ) brush. 729 \sa setFillBrush(), QWidget::palette() 730 */ 727 731 QBrush QwtThermo::fillBrush() const 728 732 { … … 731 735 732 736 /*! 733 \brief Specify the liquid brush above the alarm threshold 734 735 Changes the QPalette::Highlight brush of the palette. 736 737 \param brush New brush. 738 \sa alarmBrush(), QWidget::setPalette() 739 740 \warning The alarm threshold has no effect, when 737 \brief Specify the liquid brush above the alarm threshold 738 739 Changes the QPalette::Highlight brush of the palette. 740 741 \param brush New brush. 742 \sa alarmBrush(), QWidget::setPalette() 743 744 \warning The alarm threshold has no effect, when 741 745 a color map has been assigned 742 */ 746 */ 743 747 void QwtThermo::setAlarmBrush( const QBrush& brush ) 744 748 { … … 749 753 750 754 /*! 751 \return Liquid brush ( QPalette::Highlight ) above the alarm threshold. 752 \sa setAlarmBrush(), QWidget::palette() 753 754 \warning The alarm threshold has no effect, when 755 \return Liquid brush ( QPalette::Highlight ) above the alarm threshold. 756 \sa setAlarmBrush(), QWidget::palette() 757 758 \warning The alarm threshold has no effect, when 755 759 a color map has been assigned 756 */ 760 */ 757 761 QBrush QwtThermo::alarmBrush() const 758 762 { … … 761 765 762 766 /*! 763 Specify the alarm threshold. 764 765 \param level Alarm threshold 766 \sa alarmLevel() 767 768 \warning The alarm threshold has no effect, when 767 Specify the alarm threshold. 768 769 \param level Alarm threshold 770 \sa alarmLevel() 771 772 \warning The alarm threshold has no effect, when 769 773 a color map has been assigned 770 */ 774 */ 771 775 void QwtThermo::setAlarmLevel( double level ) 772 776 { 773 d_data->alarmLevel = level;774 d_data->alarmEnabled = 1;777 m_data->alarmLevel = level; 778 m_data->alarmEnabled = 1; 775 779 update(); 776 780 } 777 781 778 782 /*! 779 \return Alarm threshold. 780 \sa setAlarmLevel() 781 782 \warning The alarm threshold has no effect, when 783 \return Alarm threshold. 784 \sa setAlarmLevel() 785 786 \warning The alarm threshold has no effect, when 783 787 a color map has been assigned 784 */ 788 */ 785 789 double QwtThermo::alarmLevel() const 786 790 { 787 return d_data->alarmLevel;788 } 789 790 /*! 791 Change the width of the pipe. 792 793 \param width Width of the pipe 794 \sa pipeWidth() 795 */ 791 return m_data->alarmLevel; 792 } 793 794 /*! 795 Change the width of the pipe. 796 797 \param width Width of the pipe 798 \sa pipeWidth() 799 */ 796 800 void QwtThermo::setPipeWidth( int width ) 797 801 { 798 802 if ( width > 0 ) 799 803 { 800 d_data->pipeWidth = width;804 m_data->pipeWidth = width; 801 805 layoutThermo( true ); 802 806 } … … 804 808 805 809 /*! 806 \return Width of the pipe. 807 \sa setPipeWidth() 808 */ 810 \return Width of the pipe. 811 \sa setPipeWidth() 812 */ 809 813 int QwtThermo::pipeWidth() const 810 814 { 811 return d_data->pipeWidth;812 } 813 814 /*! 815 \brief Enable or disable the alarm threshold 816 \param on true (disabled) or false (enabled) 817 818 \warning The alarm threshold has no effect, when 815 return m_data->pipeWidth; 816 } 817 818 /*! 819 \brief Enable or disable the alarm threshold 820 \param on true (disabled) or false (enabled) 821 822 \warning The alarm threshold has no effect, when 819 823 a color map has been assigned 820 */ 824 */ 821 825 void QwtThermo::setAlarmEnabled( bool on ) 822 826 { 823 d_data->alarmEnabled = on;827 m_data->alarmEnabled = on; 824 828 update(); 825 829 } 826 830 827 831 /*! 828 \return True, when the alarm threshold is enabled. 829 830 \warning The alarm threshold has no effect, when 832 \return True, when the alarm threshold is enabled. 833 834 \warning The alarm threshold has no effect, when 831 835 a color map has been assigned 832 */ 836 */ 833 837 bool QwtThermo::alarmEnabled() const 834 838 { 835 return d_data->alarmEnabled;836 } 837 838 /*! 839 \return the minimum size hint 840 \sa minimumSizeHint() 841 */ 839 return m_data->alarmEnabled; 840 } 841 842 /*! 843 \return the minimum size hint 844 \sa minimumSizeHint() 845 */ 842 846 QSize QwtThermo::sizeHint() const 843 847 { … … 846 850 847 851 /*! 848 \return Minimum size hint 849 \warning The return value depends on the font and the scale. 850 \sa sizeHint() 851 */ 852 \return Minimum size hint 853 \warning The return value depends on the font and the scale. 854 \sa sizeHint() 855 */ 852 856 QSize QwtThermo::minimumSizeHint() const 853 857 { 854 858 int w = 0, h = 0; 855 859 856 if ( d_data->scalePosition != NoScale )857 { 858 const int sdExtent = qCeil( scaleDraw()->extent( font() ) ); 860 if ( m_data->scalePosition != NoScale ) 861 { 862 const int sdExtent = qwtCeil( scaleDraw()->extent( font() ) ); 859 863 const int sdLength = scaleDraw()->minLength( font() ); 860 864 861 865 w = sdLength; 862 h = d_data->pipeWidth + sdExtent +d_data->spacing;866 h = m_data->pipeWidth + sdExtent + m_data->spacing; 863 867 864 868 } … … 866 870 { 867 871 w = 200; 868 h = d_data->pipeWidth;869 } 870 871 if ( d_data->orientation == Qt::Vertical )872 h = m_data->pipeWidth; 873 } 874 875 if ( m_data->orientation == Qt::Vertical ) 872 876 qSwap( w, h ); 873 877 874 w += 2 * d_data->borderWidth;875 h += 2 * d_data->borderWidth;878 w += 2 * m_data->borderWidth; 879 h += 2 * m_data->borderWidth; 876 880 877 881 // finally add the margins 878 int left, right, top, bottom; 879 getContentsMargins( &left, &top, &right, &bottom ); 880 w += left + right; 881 h += top + bottom; 882 const QMargins m = contentsMargins(); 883 w += m.left() + m.right(); 884 h += m.top() + m.bottom(); 882 885 883 886 return QSize( w, h ); … … 885 888 886 889 /*! 887 \brief Calculate the filled rectangle of the pipe 888 889 \param pipeRect Rectangle of the pipe 890 \return Rectangle to be filled ( fill and alarm brush ) 891 892 \sa pipeRect(), alarmRect() 893 */ 894 QRect QwtThermo::fillRect( const QRect &pipeRect ) const890 \brief Calculate the filled rectangle of the pipe 891 892 \param pipeRect Rectangle of the pipe 893 \return Rectangle to be filled ( fill and alarm brush ) 894 895 \sa pipeRect(), alarmRect() 896 */ 897 QRect QwtThermo::fillRect( const QRect& pipeRect ) const 895 898 { 896 899 double origin; 897 if ( d_data->originMode == OriginMinimum )900 if ( m_data->originMode == OriginMinimum ) 898 901 { 899 902 origin = qMin( lowerBound(), upperBound() ); 900 903 } 901 else if ( d_data->originMode == OriginMaximum )904 else if ( m_data->originMode == OriginMaximum ) 902 905 { 903 906 origin = qMax( lowerBound(), upperBound() ); … … 905 908 else // OriginCustom 906 909 { 907 origin = d_data->origin;910 origin = m_data->origin; 908 911 } 909 912 910 913 const QwtScaleMap scaleMap = scaleDraw()->scaleMap(); 911 914 912 int from = qRound( scaleMap.transform( d_data->value ) );915 int from = qRound( scaleMap.transform( m_data->value ) ); 913 916 int to = qRound( scaleMap.transform( origin ) ); 914 917 … … 917 920 918 921 QRect fillRect = pipeRect; 919 if ( d_data->orientation == Qt::Horizontal )922 if ( m_data->orientation == Qt::Horizontal ) 920 923 { 921 924 fillRect.setLeft( from ); … … 932 935 933 936 /*! 934 \brief Calculate the alarm rectangle of the pipe 935 936 \param fillRect Filled rectangle in the pipe 937 \return Rectangle to be filled with the alarm brush 938 939 \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush() 940 */ 941 QRect QwtThermo::alarmRect( const QRect &fillRect ) const937 \brief Calculate the alarm rectangle of the pipe 938 939 \param fillRect Filled rectangle in the pipe 940 \return Rectangle to be filled with the alarm brush 941 942 \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush() 943 */ 944 QRect QwtThermo::alarmRect( const QRect& fillRect ) const 942 945 { 943 946 QRect alarmRect( 0, 0, -1, -1); // something invalid 944 947 945 if ( ! d_data->alarmEnabled )948 if ( !m_data->alarmEnabled ) 946 949 return alarmRect; 947 950 … … 949 952 950 953 bool increasing; 951 if ( d_data->originMode == OriginCustom )952 { 953 increasing = d_data->value >d_data->origin;954 if ( m_data->originMode == OriginCustom ) 955 { 956 increasing = m_data->value > m_data->origin; 954 957 } 955 958 else 956 959 { 957 increasing = d_data->originMode == OriginMinimum;960 increasing = m_data->originMode == OriginMinimum; 958 961 } 959 962 960 963 const QwtScaleMap map = scaleDraw()->scaleMap(); 961 const int alarmPos = qRound( map.transform( d_data->alarmLevel ) );962 const int valuePos = qRound( map.transform( d_data->value ) );963 964 if ( d_data->orientation == Qt::Horizontal )964 const int alarmPos = qRound( map.transform( m_data->alarmLevel ) ); 965 const int valuePos = qRound( map.transform( m_data->value ) ); 966 967 if ( m_data->orientation == Qt::Horizontal ) 965 968 { 966 969 int v1, v2; … … 1004 1007 return alarmRect; 1005 1008 } 1009 1010 #include "moc_qwt_thermo.cpp" -
trunk/BNC/qwt/qwt_thermo.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 19 19 20 20 /*! 21 \brief The Thermometer Widget 21 \brief The Thermometer Widget 22 22 23 QwtThermo is a widget which displays a value in an interval. It supports: 24 - a horizontal or vertical layout; 25 - a range; 26 - a scale; 27 - an alarm level. 23 QwtThermo is a widget which displays a value in an interval. It supports: 24 - a horizontal or vertical layout; 25 - a range; 26 - a scale; 27 - an alarm level. 28 28 29 \image html sysinfo.png 29 \image html sysinfo.png 30 30 31 The fill colors might be calculated from an optional color map 32 If no color map has been assigned QwtThermo uses the 33 following colors/brushes from the widget palette: 31 The fill colors might be calculated from an optional color map 32 If no color map has been assigned QwtThermo uses the 33 following colors/brushes from the widget palette: 34 34 35 - QPalette::Base 35 - QPalette::Base 36 36 Background of the pipe 37 - QPalette::ButtonText 37 - QPalette::ButtonText 38 38 Fill brush below the alarm level 39 - QPalette::Highlight 39 - QPalette::Highlight 40 40 Fill brush for the values above the alarm level 41 - QPalette::WindowText 41 - QPalette::WindowText 42 42 For the axis of the scale 43 - QPalette::Text 43 - QPalette::Text 44 44 For the labels of the scale 45 */ 46 class QWT_EXPORT QwtThermo: public QwtAbstractScale 45 */ 46 class QWT_EXPORT QwtThermo : public QwtAbstractScale 47 47 { 48 48 Q_OBJECT … … 63 63 Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth ) 64 64 Q_PROPERTY( int pipeWidth READ pipeWidth WRITE setPipeWidth ) 65 Q_PROPERTY( double value READ value WRITE setValue ) 65 Q_PROPERTY( double value READ value WRITE setValue USER true ) 66 66 67 public: 67 public: 68 68 69 69 /*! 70 Position of the scale 71 \sa setScalePosition(), setOrientation() 70 Position of the scale 71 \sa setScalePosition(), setOrientation() 72 72 */ 73 73 enum ScalePosition … … 84 84 85 85 /*! 86 Origin mode. This property specifies where the beginning of the liquid 87 is placed. 86 Origin mode. This property specifies where the beginning of the liquid 87 is placed. 88 88 89 \sa setOriginMode(), setOrigin() 90 */ 89 \sa setOriginMode(), setOrigin() 90 */ 91 91 enum OriginMode 92 92 { … … 101 101 }; 102 102 103 explicit QwtThermo( QWidget *parent = NULL );103 explicit QwtThermo( QWidget* parent = NULL ); 104 104 virtual ~QwtThermo(); 105 105 … … 122 122 double origin() const; 123 123 124 void setFillBrush( const QBrush & );124 void setFillBrush( const QBrush& ); 125 125 QBrush fillBrush() const; 126 126 127 void setAlarmBrush( const QBrush & );127 void setAlarmBrush( const QBrush& ); 128 128 QBrush alarmBrush() const; 129 129 … … 134 134 bool alarmEnabled() const; 135 135 136 void setColorMap( QwtColorMap * );137 QwtColorMap *colorMap();138 const QwtColorMap *colorMap() const;136 void setColorMap( QwtColorMap* ); 137 QwtColorMap* colorMap(); 138 const QwtColorMap* colorMap() const; 139 139 140 140 void setPipeWidth( int ); … … 146 146 double value() const; 147 147 148 virtual QSize sizeHint() const; 149 virtual QSize minimumSizeHint() const; 148 virtual QSize sizeHint() const QWT_OVERRIDE; 149 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 150 150 151 void setScaleDraw( QwtScaleDraw * );152 const QwtScaleDraw *scaleDraw() const;151 void setScaleDraw( QwtScaleDraw* ); 152 const QwtScaleDraw* scaleDraw() const; 153 153 154 public Q_SLOTS: 154 public Q_SLOTS: 155 155 virtual void setValue( double ); 156 156 157 protected: 158 virtual void drawLiquid( QPainter *, const QRect& ) const;159 virtual void scaleChange(); 157 protected: 158 virtual void drawLiquid( QPainter*, const QRect& ) const; 159 virtual void scaleChange() QWT_OVERRIDE; 160 160 161 virtual void paintEvent( QPaintEvent * );162 virtual void resizeEvent( QResizeEvent * );163 virtual void changeEvent( QEvent * );161 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 162 virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE; 163 virtual void changeEvent( QEvent* ) QWT_OVERRIDE; 164 164 165 QwtScaleDraw *scaleDraw();165 QwtScaleDraw* scaleDraw(); 166 166 167 167 QRect pipeRect() const; 168 QRect fillRect( const QRect & ) const;169 QRect alarmRect( const QRect & ) const;168 QRect fillRect( const QRect& ) const; 169 QRect alarmRect( const QRect& ) const; 170 170 171 private: 171 private: 172 172 void layoutThermo( bool ); 173 173 174 174 class PrivateData; 175 PrivateData *d_data;175 PrivateData* m_data; 176 176 }; 177 177 -
trunk/BNC/qwt/qwt_transform.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_math.h" 12 12 13 #if QT_VERSION < 0x04060114 #define qExp(x) ::exp(x)15 #endif16 17 #if QT_VERSION >= 0x05040018 19 13 //! Smallest allowed value for logarithmic scales: 1.0e-150 20 14 const double QwtLogTransform::LogMin = 1.0e-150; … … 22 16 //! Largest allowed value for logarithmic scales: 1.0e150 23 17 const double QwtLogTransform::LogMax = 1.0e150; 24 25 #else26 27 //! Smallest allowed value for logarithmic scales: 1.0e-15028 QT_STATIC_CONST_IMPL double QwtLogTransform::LogMin = 1.0e-150;29 30 //! Largest allowed value for logarithmic scales: 1.0e15031 QT_STATIC_CONST_IMPL double QwtLogTransform::LogMax = 1.0e150;32 33 #endif34 18 35 19 //! Constructor … … 44 28 45 29 /*! 46 \param value Value to be bounded 47 \return value unmodified 30 \param value Value to be bounded 31 \return value unmodified 48 32 */ 49 33 double QwtTransform::bounded( double value ) const … … 64 48 65 49 /*! 66 \param value Value to be transformed 67 \return value unmodified 50 \param value Value to be transformed 51 \return value unmodified 68 52 */ 69 53 double QwtNullTransform::transform( double value ) const … … 73 57 74 58 /*! 75 \param value Value to be transformed 76 \return value unmodified 59 \param value Value to be transformed 60 \return value unmodified 77 61 */ 78 62 double QwtNullTransform::invTransform( double value ) const … … 82 66 83 67 //! \return Clone of the transformation 84 QwtTransform *QwtNullTransform::copy() const68 QwtTransform* QwtNullTransform::copy() const 85 69 { 86 70 return new QwtNullTransform(); … … 99 83 100 84 /*! 101 \param value Value to be transformed 102 \return log( value ) 85 \param value Value to be transformed 86 \return log( value ) 103 87 */ 104 88 double QwtLogTransform::transform( double value ) const 105 89 { 106 return ::log( value ); 90 return std::log( value ); 107 91 } 108 92 109 93 /*! 110 \param value Value to be transformed 111 \return exp( value ) 94 \param value Value to be transformed 95 \return exp( value ) 112 96 */ 113 97 double QwtLogTransform::invTransform( double value ) const 114 98 { 115 return qExp( value );99 return std::exp( value ); 116 100 } 117 101 118 102 /*! 119 \param value Value to be bounded 120 \return qBound( LogMin, value, LogMax ) 103 \param value Value to be bounded 104 \return qBound( LogMin, value, LogMax ) 121 105 */ 122 106 double QwtLogTransform::bounded( double value ) const … … 126 110 127 111 //! \return Clone of the transformation 128 QwtTransform *QwtLogTransform::copy() const112 QwtTransform* QwtLogTransform::copy() const 129 113 { 130 114 return new QwtLogTransform(); … … 132 116 133 117 /*! 134 Constructor 135 \param exponent Exponent 136 */ 118 Constructor 119 \param exponent Exponent 120 */ 137 121 QwtPowerTransform::QwtPowerTransform( double exponent ): 138 122 QwtTransform(), 139 d_exponent( exponent )123 m_exponent( exponent ) 140 124 { 141 125 } … … 147 131 148 132 /*! 149 \param value Value to be transformed 150 \return Exponentiation preserving the sign 133 \param value Value to be transformed 134 \return Exponentiation preserving the sign 151 135 */ 152 136 double QwtPowerTransform::transform( double value ) const 153 137 { 154 138 if ( value < 0.0 ) 155 return - qPow( -value, 1.0 /d_exponent );139 return -std::pow( -value, 1.0 / m_exponent ); 156 140 else 157 return qPow( value, 1.0 /d_exponent );141 return std::pow( value, 1.0 / m_exponent ); 158 142 159 143 } 160 144 161 145 /*! 162 \param value Value to be transformed 163 \return Inverse exponentiation preserving the sign 146 \param value Value to be transformed 147 \return Inverse exponentiation preserving the sign 164 148 */ 165 149 double QwtPowerTransform::invTransform( double value ) const 166 150 { 167 151 if ( value < 0.0 ) 168 return - qPow( -value,d_exponent );152 return -std::pow( -value, m_exponent ); 169 153 else 170 return qPow( value,d_exponent );154 return std::pow( value, m_exponent ); 171 155 } 172 156 173 157 //! \return Clone of the transformation 174 QwtTransform *QwtPowerTransform::copy() const158 QwtTransform* QwtPowerTransform::copy() const 175 159 { 176 return new QwtPowerTransform( d_exponent );160 return new QwtPowerTransform( m_exponent ); 177 161 } -
trunk/BNC/qwt/qwt_transform.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 32 32 - p = p1 + ( p2 - p1 ) * ( T( s ) - T( s1 ) / ( T( s2 ) - T( s1 ) ); 33 33 - s = invT ( T( s1 ) + ( T( s2 ) - T( s1 ) ) * ( p - p1 ) / ( p2 - p1 ) ); 34 */ 34 */ 35 35 class QWT_EXPORT QwtTransform 36 36 { 37 public: 37 public: 38 38 QwtTransform(); 39 39 virtual ~QwtTransform(); … … 66 66 67 67 //! Virtualized copy operation 68 virtual QwtTransform *copy() const = 0; 68 virtual QwtTransform* copy() const = 0; 69 70 private: 71 Q_DISABLE_COPY(QwtTransform) 69 72 }; 70 73 … … 75 78 76 79 */ 77 class QWT_EXPORT QwtNullTransform: public QwtTransform 80 class QWT_EXPORT QwtNullTransform : public QwtTransform 78 81 { 79 public: 82 public: 80 83 QwtNullTransform(); 81 84 virtual ~QwtNullTransform(); 82 85 83 virtual double transform( double value ) const; 84 virtual double invTransform( double value ) const; 86 virtual double transform( double value ) const QWT_OVERRIDE; 87 virtual double invTransform( double value ) const QWT_OVERRIDE; 85 88 86 virtual QwtTransform *copy() const;89 virtual QwtTransform* copy() const QWT_OVERRIDE; 87 90 }; 88 91 /*! … … 95 98 for log2(), log10() or any other logarithmic scale. 96 99 */ 97 class QWT_EXPORT QwtLogTransform: public QwtTransform 100 class QWT_EXPORT QwtLogTransform : public QwtTransform 98 101 { 99 public: 102 public: 100 103 QwtLogTransform(); 101 104 virtual ~QwtLogTransform(); 102 105 103 virtual double transform( double value ) const; 104 virtual double invTransform( double value ) const; 106 virtual double transform( double value ) const QWT_OVERRIDE; 107 virtual double invTransform( double value ) const QWT_OVERRIDE; 105 108 106 virtual double bounded( double value ) const; 109 virtual double bounded( double value ) const QWT_OVERRIDE; 107 110 108 virtual QwtTransform *copy() const;111 virtual QwtTransform* copy() const QWT_OVERRIDE; 109 112 110 #if QT_VERSION >= 0x050400111 113 static const double LogMin; 112 114 static const double LogMax; 113 #else114 QT_STATIC_CONST double LogMin;115 QT_STATIC_CONST double LogMax;116 #endif117 115 }; 118 116 … … 125 123 can be used for scales including negative values. 126 124 */ 127 class QWT_EXPORT QwtPowerTransform: public QwtTransform 125 class QWT_EXPORT QwtPowerTransform : public QwtTransform 128 126 { 129 public: 130 QwtPowerTransform( double exponent ); 127 public: 128 explicit QwtPowerTransform( double exponent ); 131 129 virtual ~QwtPowerTransform(); 132 130 133 virtual double transform( double value ) const; 134 virtual double invTransform( double value ) const; 131 virtual double transform( double value ) const QWT_OVERRIDE; 132 virtual double invTransform( double value ) const QWT_OVERRIDE; 135 133 136 virtual QwtTransform *copy() const;134 virtual QwtTransform* copy() const QWT_OVERRIDE; 137 135 138 private: 139 const double d_exponent;136 private: 137 const double m_exponent; 140 138 }; 141 139 -
trunk/BNC/qwt/qwt_wheel.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_math.h" 12 12 #include "qwt_painter.h" 13 #include "qwt.h" 14 13 15 #include <qevent.h> 14 16 #include <qdrawutil.h> … … 16 18 #include <qstyle.h> 17 19 #include <qstyleoption.h> 18 #include <qapplication.h> 19 #include <qdatetime.h> 20 21 #if QT_VERSION < 0x040601 22 #define qFabs(x) ::fabs(x) 23 #define qFastSin(x) ::sin(x) 24 #define qExp(x) ::exp(x) 25 #endif 20 #include <qelapsedtimer.h> 21 #include <qmath.h> 26 22 27 23 class QwtWheel::PrivateData 28 24 { 29 public: 30 PrivateData() :31 orientation( Qt::Horizontal ) ,32 viewAngle( 175.0 ) ,33 totalAngle( 360.0 ) ,34 tickCount( 10 ) ,35 wheelBorderWidth( 2 ) ,36 borderWidth( 2 ) ,37 wheelWidth( 20 ) ,38 isScrolling( false ),39 mouseOffset( 0.0 ),40 tracking( true ),41 pendingValueChanged( false ),42 updateInterval( 50 ),43 mass( 0.0 ),44 timerId( 0 ),45 speed( 0.0 ),46 mouseValue( 0.0 ),47 flyingValue( 0.0 ),48 minimum( 0.0 ),49 maximum( 100.0 ),50 singleStep( 1.0 ),51 pageStepCount( 1 ),52 stepAlignment( true ) ,53 value( 0.0 ),54 inverted( false ) ,55 wrapping( false ) 25 public: 26 PrivateData() 27 : orientation( Qt::Horizontal ) 28 , viewAngle( 175.0 ) 29 , totalAngle( 360.0 ) 30 , tickCount( 10 ) 31 , wheelBorderWidth( 2 ) 32 , borderWidth( 2 ) 33 , wheelWidth( 20 ) 34 , mouseOffset( 0.0 ) 35 , updateInterval( 50 ) 36 , mass( 0.0 ) 37 , timerId( 0 ) 38 , speed( 0.0 ) 39 , mouseValue( 0.0 ) 40 , flyingValue( 0.0 ) 41 , minimum( 0.0 ) 42 , maximum( 100.0 ) 43 , singleStep( 1.0 ) 44 , pageStepCount( 1 ) 45 , value( 0.0 ) 46 , isScrolling( false ) 47 , tracking( true ) 48 , stepAlignment( true ) 49 , pendingValueChanged( false ) 50 , inverted( false ) 51 , wrapping( false ) 56 52 { 57 53 } … … 65 61 int wheelWidth; 66 62 67 bool isScrolling;68 63 double mouseOffset; 69 70 bool tracking;71 bool pendingValueChanged; // when not tracking72 64 73 65 int updateInterval; … … 76 68 // for the flying wheel effect 77 69 int timerId; 78 Q Time time;70 QElapsedTimer timer; 79 71 double speed; 80 72 double mouseValue; … … 86 78 double singleStep; 87 79 int pageStepCount; 80 81 double value; 82 83 bool isScrolling; 84 bool tracking; 88 85 bool stepAlignment; 89 90 double value; 91 86 bool pendingValueChanged; // when not tracking 92 87 bool inverted; 93 88 bool wrapping; … … 95 90 96 91 //! Constructor 97 QwtWheel::QwtWheel( QWidget *parent ):92 QwtWheel::QwtWheel( QWidget* parent ): 98 93 QWidget( parent ) 99 94 { 100 d_data = new PrivateData;95 m_data = new PrivateData; 101 96 102 97 setFocusPolicy( Qt::StrongFocus ); … … 108 103 QwtWheel::~QwtWheel() 109 104 { 110 delete d_data;111 } 112 113 /*! 114 \brief En/Disable tracking 115 116 If tracking is enabled (the default), the wheel emits the valueChanged() 117 signal while the wheel is moving. If tracking is disabled, the wheel 118 emits the valueChanged() signal only when the wheel movement is terminated. 119 120 The wheelMoved() signal is emitted regardless id tracking is enabled or not. 121 122 \param enable On/Off 123 \sa isTracking() 105 delete m_data; 106 } 107 108 /*! 109 \brief En/Disable tracking 110 111 If tracking is enabled (the default), the wheel emits the valueChanged() 112 signal while the wheel is moving. If tracking is disabled, the wheel 113 emits the valueChanged() signal only when the wheel movement is terminated. 114 115 The wheelMoved() signal is emitted regardless id tracking is enabled or not. 116 117 \param enable On/Off 118 \sa isTracking() 124 119 */ 125 120 void QwtWheel::setTracking( bool enable ) 126 121 { 127 d_data->tracking = enable;128 } 129 130 /*! 131 \return True, when tracking is enabled 132 \sa setTracking(), valueChanged(), wheelMoved() 133 */ 122 m_data->tracking = enable; 123 } 124 125 /*! 126 \return True, when tracking is enabled 127 \sa setTracking(), valueChanged(), wheelMoved() 128 */ 134 129 bool QwtWheel::isTracking() const 135 130 { 136 return d_data->tracking;137 } 138 139 /*! 140 \brief Specify the update interval when the wheel is flying 141 142 Default and minimum value is 50 ms. 143 144 \param interval Interval in milliseconds 145 \sa updateInterval(), setMass(), setTracking() 146 */ 131 return m_data->tracking; 132 } 133 134 /*! 135 \brief Specify the update interval when the wheel is flying 136 137 Default and minimum value is 50 ms. 138 139 \param interval Interval in milliseconds 140 \sa updateInterval(), setMass(), setTracking() 141 */ 147 142 void QwtWheel::setUpdateInterval( int interval ) 148 143 { 149 d_data->updateInterval = qMax( interval, 50 );150 } 151 152 /*! 153 \return Update interval when the wheel is flying 154 \sa setUpdateInterval(), mass(), isTracking() 144 m_data->updateInterval = qMax( interval, 50 ); 145 } 146 147 /*! 148 \return Update interval when the wheel is flying 149 \sa setUpdateInterval(), mass(), isTracking() 155 150 */ 156 151 int QwtWheel::updateInterval() const 157 152 { 158 return d_data->updateInterval;153 return m_data->updateInterval; 159 154 } 160 155 … … 165 160 166 161 \param event Mouse event 167 */ 168 void QwtWheel::mousePressEvent( QMouseEvent *event )162 */ 163 void QwtWheel::mousePressEvent( QMouseEvent* event ) 169 164 { 170 165 stopFlying(); 171 166 172 d_data->isScrolling = wheelRect().contains( event->pos() );173 174 if ( d_data->isScrolling )175 { 176 d_data->time.start();177 d_data->speed = 0.0;178 d_data->mouseValue = valueAt( event->pos() );179 d_data->mouseOffset =d_data->mouseValue -d_data->value;180 d_data->pendingValueChanged = false;167 m_data->isScrolling = wheelRect().contains( event->pos() ); 168 169 if ( m_data->isScrolling ) 170 { 171 m_data->timer.start(); 172 m_data->speed = 0.0; 173 m_data->mouseValue = valueAt( event->pos() ); 174 m_data->mouseOffset = m_data->mouseValue - m_data->value; 175 m_data->pendingValueChanged = false; 181 176 182 177 Q_EMIT wheelPressed(); … … 190 185 191 186 \param event Mouse event 192 */ 193 void QwtWheel::mouseMoveEvent( QMouseEvent *event )194 { 195 if ( ! d_data->isScrolling )187 */ 188 void QwtWheel::mouseMoveEvent( QMouseEvent* event ) 189 { 190 if ( !m_data->isScrolling ) 196 191 return; 197 192 198 193 double mouseValue = valueAt( event->pos() ); 199 194 200 if ( d_data->mass > 0.0 )201 { 202 double ms = d_data->time.restart();195 if ( m_data->mass > 0.0 ) 196 { 197 double ms = m_data->timer.restart(); 203 198 204 199 // the interval when mouse move events are posted are somehow … … 207 202 ms = qMax( ms, 5.0 ); 208 203 209 d_data->speed = ( mouseValue -d_data->mouseValue ) / ms;210 } 211 212 d_data->mouseValue = mouseValue;213 214 double value = boundedValue( mouseValue - d_data->mouseOffset );215 if ( d_data->stepAlignment )204 m_data->speed = ( mouseValue - m_data->mouseValue ) / ms; 205 } 206 207 m_data->mouseValue = mouseValue; 208 209 double value = boundedValue( mouseValue - m_data->mouseOffset ); 210 if ( m_data->stepAlignment ) 216 211 value = alignedValue( value ); 217 212 218 if ( value != d_data->value )219 { 220 d_data->value = value;213 if ( value != m_data->value ) 214 { 215 m_data->value = value; 221 216 222 217 update(); 223 218 224 Q_EMIT wheelMoved( d_data->value );225 226 if ( d_data->tracking )227 Q_EMIT valueChanged( d_data->value );219 Q_EMIT wheelMoved( m_data->value ); 220 221 if ( m_data->tracking ) 222 Q_EMIT valueChanged( m_data->value ); 228 223 else 229 d_data->pendingValueChanged = true;224 m_data->pendingValueChanged = true; 230 225 } 231 226 } … … 238 233 239 234 \param event Mouse event 240 */ 241 242 void QwtWheel::mouseReleaseEvent( QMouseEvent *event )235 */ 236 237 void QwtWheel::mouseReleaseEvent( QMouseEvent* event ) 243 238 { 244 239 Q_UNUSED( event ); 245 240 246 if ( ! d_data->isScrolling )241 if ( !m_data->isScrolling ) 247 242 return; 248 243 249 d_data->isScrolling = false;244 m_data->isScrolling = false; 250 245 251 246 bool startFlying = false; 252 247 253 if ( d_data->mass > 0.0 )254 { 255 const int ms = d_data->time.elapsed();256 if ( ( qFabs( d_data->speed ) > 0.0 ) && ( ms < 50 ) )248 if ( m_data->mass > 0.0 ) 249 { 250 const qint64 ms = m_data->timer.elapsed(); 251 if ( ( std::fabs( m_data->speed ) > 0.0 ) && ( ms < 50 ) ) 257 252 startFlying = true; 258 253 } … … 260 255 if ( startFlying ) 261 256 { 262 d_data->flyingValue =263 boundedValue( d_data->mouseValue -d_data->mouseOffset );264 265 d_data->timerId = startTimer(d_data->updateInterval );257 m_data->flyingValue = 258 boundedValue( m_data->mouseValue - m_data->mouseOffset ); 259 260 m_data->timerId = startTimer( m_data->updateInterval ); 266 261 } 267 262 else 268 263 { 269 if ( d_data->pendingValueChanged )270 Q_EMIT valueChanged( d_data->value );271 } 272 273 d_data->pendingValueChanged = false;274 d_data->mouseOffset = 0.0;264 if ( m_data->pendingValueChanged ) 265 Q_EMIT valueChanged( m_data->value ); 266 } 267 268 m_data->pendingValueChanged = false; 269 m_data->mouseOffset = 0.0; 275 270 276 271 Q_EMIT wheelReleased(); … … 278 273 279 274 /*! 280 \brief Qt timer event 281 282 The flying wheel effect is implemented using a timer 283 284 \param event Timer event 285 286 \sa updateInterval() 287 */ 288 void QwtWheel::timerEvent( QTimerEvent *event )289 { 290 if ( event->timerId() != d_data->timerId )275 \brief Qt timer event 276 277 The flying wheel effect is implemented using a timer 278 279 \param event Timer event 280 281 \sa updateInterval() 282 */ 283 void QwtWheel::timerEvent( QTimerEvent* event ) 284 { 285 if ( event->timerId() != m_data->timerId ) 291 286 { 292 287 QWidget::timerEvent( event ); … … 294 289 } 295 290 296 d_data->speed *=qExp( -d_data->updateInterval * 0.001 /d_data->mass );297 298 d_data->flyingValue +=d_data->speed *d_data->updateInterval;299 d_data->flyingValue = boundedValue(d_data->flyingValue );300 301 double value = d_data->flyingValue;302 if ( d_data->stepAlignment )291 m_data->speed *= std::exp( -m_data->updateInterval * 0.001 / m_data->mass ); 292 293 m_data->flyingValue += m_data->speed * m_data->updateInterval; 294 m_data->flyingValue = boundedValue( m_data->flyingValue ); 295 296 double value = m_data->flyingValue; 297 if ( m_data->stepAlignment ) 303 298 value = alignedValue( value ); 304 299 305 if ( qFabs( d_data->speed ) < 0.001 *d_data->singleStep )306 { 307 // stop if d_data->speed < one step per second300 if ( std::fabs( m_data->speed ) < 0.001 * m_data->singleStep ) 301 { 302 // stop if m_data->speed < one step per second 308 303 stopFlying(); 309 304 } 310 305 311 if ( value != d_data->value )312 { 313 d_data->value = value;306 if ( value != m_data->value ) 307 { 308 m_data->value = value; 314 309 update(); 315 310 316 if ( d_data->tracking || d_data->timerId == 0 ) 317 Q_EMIT valueChanged( d_data->value ); 318 } 319 } 320 321 322 /*! 323 \brief Handle wheel events 324 325 In/Decrement the value 326 327 \param event Wheel event 328 */ 329 void QwtWheel::wheelEvent( QWheelEvent *event ) 330 { 331 if ( !wheelRect().contains( event->pos() ) ) 311 if ( m_data->tracking || m_data->timerId == 0 ) 312 Q_EMIT valueChanged( m_data->value ); 313 } 314 } 315 316 317 /*! 318 \brief Handle wheel events 319 320 In/Decrement the value 321 322 \param event Wheel event 323 */ 324 void QwtWheel::wheelEvent( QWheelEvent* event ) 325 { 326 #if QT_VERSION < 0x050e00 327 const QPoint wheelPos = event->pos(); 328 const int wheelDelta = event->delta(); 329 #else 330 const QPoint wheelPos = event->position().toPoint(); 331 332 const QPoint delta = event->angleDelta(); 333 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) ) 334 ? delta.x() : delta.y(); 335 #endif 336 337 if ( !wheelRect().contains( wheelPos ) ) 332 338 { 333 339 event->ignore(); … … 335 341 } 336 342 337 if ( d_data->isScrolling )343 if ( m_data->isScrolling ) 338 344 return; 339 345 … … 342 348 double increment = 0.0; 343 349 344 if ( ( event->modifiers() & Qt::ControlModifier) || 350 if ( ( event->modifiers() & Qt::ControlModifier ) || 345 351 ( event->modifiers() & Qt::ShiftModifier ) ) 346 352 { 347 353 // one page regardless of delta 348 increment = d_data->singleStep *d_data->pageStepCount;349 if ( event->delta()< 0 )354 increment = m_data->singleStep * m_data->pageStepCount; 355 if ( wheelDelta < 0 ) 350 356 increment = -increment; 351 357 } 352 358 else 353 359 { 354 const int numSteps = event->delta()/ 120;355 increment = d_data->singleStep * numSteps;356 } 357 358 if ( d_data->orientation == Qt::Vertical &&d_data->inverted )360 const int numSteps = wheelDelta / 120; 361 increment = m_data->singleStep * numSteps; 362 } 363 364 if ( m_data->orientation == Qt::Vertical && m_data->inverted ) 359 365 increment = -increment; 360 366 361 double value = boundedValue( d_data->value + increment );362 363 if ( d_data->stepAlignment )367 double value = boundedValue( m_data->value + increment ); 368 369 if ( m_data->stepAlignment ) 364 370 value = alignedValue( value ); 365 371 366 if ( value != d_data->value )367 { 368 d_data->value = value;372 if ( value != m_data->value ) 373 { 374 m_data->value = value; 369 375 update(); 370 376 371 Q_EMIT valueChanged( d_data->value );372 Q_EMIT wheelMoved( d_data->value );373 } 374 } 375 376 /*! 377 Handle key events 378 379 - Qt::Key_Home\n 377 Q_EMIT valueChanged( m_data->value ); 378 Q_EMIT wheelMoved( m_data->value ); 379 } 380 } 381 382 /*! 383 Handle key events 384 385 - Qt::Key_Home\n 380 386 Step to minimum() 381 387 382 - Qt::Key_End\n 388 - Qt::Key_End\n 383 389 Step to maximum() 384 390 385 - Qt::Key_Up\n 391 - Qt::Key_Up\n 386 392 In case of a horizontal or not inverted vertical wheel the value 387 393 will be incremented by the step size. For an inverted vertical wheel 388 394 the value will be decremented by the step size. 389 395 390 - Qt::Key_Down\n 396 - Qt::Key_Down\n 391 397 In case of a horizontal or not inverted vertical wheel the value 392 398 will be decremented by the step size. For an inverted vertical wheel 393 399 the value will be incremented by the step size. 394 400 395 - Qt::Key_PageUp\n 401 - Qt::Key_PageUp\n 396 402 The value will be incremented by pageStepSize() * singleStepSize(). 397 403 398 - Qt::Key_PageDown\n 404 - Qt::Key_PageDown\n 399 405 The value will be decremented by pageStepSize() * singleStepSize(). 400 406 401 \param event Key event 402 */ 403 void QwtWheel::keyPressEvent( QKeyEvent *event )404 { 405 if ( d_data->isScrolling )407 \param event Key event 408 */ 409 void QwtWheel::keyPressEvent( QKeyEvent* event ) 410 { 411 if ( m_data->isScrolling ) 406 412 { 407 413 // don't interfere mouse scrolling … … 409 415 } 410 416 411 double value = d_data->value;417 double value = m_data->value; 412 418 double increment = 0.0; 413 419 … … 416 422 case Qt::Key_Down: 417 423 { 418 if ( d_data->orientation == Qt::Vertical &&d_data->inverted )419 increment = d_data->singleStep;424 if ( m_data->orientation == Qt::Vertical && m_data->inverted ) 425 increment = m_data->singleStep; 420 426 else 421 increment = - d_data->singleStep;427 increment = -m_data->singleStep; 422 428 423 429 break; … … 425 431 case Qt::Key_Up: 426 432 { 427 if ( d_data->orientation == Qt::Vertical &&d_data->inverted )428 increment = - d_data->singleStep;433 if ( m_data->orientation == Qt::Vertical && m_data->inverted ) 434 increment = -m_data->singleStep; 429 435 else 430 increment = d_data->singleStep;436 increment = m_data->singleStep; 431 437 432 438 break; … … 434 440 case Qt::Key_Left: 435 441 { 436 if ( d_data->orientation == Qt::Horizontal )442 if ( m_data->orientation == Qt::Horizontal ) 437 443 { 438 if ( d_data->inverted )439 increment = d_data->singleStep;444 if ( m_data->inverted ) 445 increment = m_data->singleStep; 440 446 else 441 increment = - d_data->singleStep;447 increment = -m_data->singleStep; 442 448 } 443 449 break; … … 445 451 case Qt::Key_Right: 446 452 { 447 if ( d_data->orientation == Qt::Horizontal )453 if ( m_data->orientation == Qt::Horizontal ) 448 454 { 449 if ( d_data->inverted )450 increment = - d_data->singleStep;455 if ( m_data->inverted ) 456 increment = -m_data->singleStep; 451 457 else 452 increment = d_data->singleStep;458 increment = m_data->singleStep; 453 459 } 454 460 break; … … 456 462 case Qt::Key_PageUp: 457 463 { 458 increment = d_data->pageStepCount *d_data->singleStep;464 increment = m_data->pageStepCount * m_data->singleStep; 459 465 break; 460 466 } 461 467 case Qt::Key_PageDown: 462 468 { 463 increment = - d_data->pageStepCount *d_data->singleStep;469 increment = -m_data->pageStepCount * m_data->singleStep; 464 470 break; 465 471 } 466 472 case Qt::Key_Home: 467 473 { 468 value = d_data->minimum;474 value = m_data->minimum; 469 475 break; 470 476 } 471 477 case Qt::Key_End: 472 478 { 473 value = d_data->maximum;479 value = m_data->maximum; 474 480 break; 475 481 } 476 482 default:; 477 { 478 event->ignore(); 479 } 483 { 484 event->ignore(); 485 } 480 486 } 481 487 … … 485 491 if ( increment != 0.0 ) 486 492 { 487 value = boundedValue( d_data->value + increment );488 489 if ( d_data->stepAlignment )493 value = boundedValue( m_data->value + increment ); 494 495 if ( m_data->stepAlignment ) 490 496 value = alignedValue( value ); 491 497 } 492 498 493 if ( value != d_data->value )494 { 495 d_data->value = value;499 if ( value != m_data->value ) 500 { 501 m_data->value = value; 496 502 update(); 497 503 498 Q_EMIT valueChanged( d_data->value );499 Q_EMIT wheelMoved( d_data->value );500 } 501 } 502 503 /*! 504 \brief Adjust the number of grooves in the wheel's surface. 505 506 The number of grooves is limited to 6 <= count <= 50. 507 Values outside this range will be clipped. 508 The default value is 10. 509 510 \param count Number of grooves per 360 degrees 511 \sa tickCount() 512 */ 504 Q_EMIT valueChanged( m_data->value ); 505 Q_EMIT wheelMoved( m_data->value ); 506 } 507 } 508 509 /*! 510 \brief Adjust the number of grooves in the wheel's surface. 511 512 The number of grooves is limited to 6 <= count <= 50. 513 Values outside this range will be clipped. 514 The default value is 10. 515 516 \param count Number of grooves per 360 degrees 517 \sa tickCount() 518 */ 513 519 void QwtWheel::setTickCount( int count ) 514 520 { 515 521 count = qBound( 6, count, 50 ); 516 522 517 if ( count != d_data->tickCount )518 { 519 d_data->tickCount = qBound( 6, count, 50 );523 if ( count != m_data->tickCount ) 524 { 525 m_data->tickCount = qBound( 6, count, 50 ); 520 526 update(); 521 527 } … … 523 529 524 530 /*! 525 \return Number of grooves in the wheel's surface. 526 \sa setTickCnt() 527 */ 531 \return Number of grooves in the wheel's surface. 532 \sa setTickCnt() 533 */ 528 534 int QwtWheel::tickCount() const 529 535 { 530 return d_data->tickCount;531 } 532 533 /*! 534 \brief Set the wheel border width of the wheel. 535 536 The wheel border must not be smaller than 1 537 and is limited in dependence on the wheel's size. 538 Values outside the allowed range will be clipped. 539 540 The wheel border defaults to 2. 541 542 \param borderWidth Border width 543 \sa internalBorder() 544 */ 536 return m_data->tickCount; 537 } 538 539 /*! 540 \brief Set the wheel border width of the wheel. 541 542 The wheel border must not be smaller than 1 543 and is limited in dependence on the wheel's size. 544 Values outside the allowed range will be clipped. 545 546 The wheel border defaults to 2. 547 548 \param borderWidth Border width 549 \sa internalBorder() 550 */ 545 551 void QwtWheel::setWheelBorderWidth( int borderWidth ) 546 552 { 547 553 const int d = qMin( width(), height() ) / 3; 548 554 borderWidth = qMin( borderWidth, d ); 549 d_data->wheelBorderWidth = qMax( borderWidth, 1 );555 m_data->wheelBorderWidth = qMax( borderWidth, 1 ); 550 556 update(); 551 557 } … … 554 560 \return Wheel border width 555 561 \sa setWheelBorderWidth() 556 */ 562 */ 557 563 int QwtWheel::wheelBorderWidth() const 558 564 { 559 return d_data->wheelBorderWidth;560 } 561 562 /*! 563 \brief Set the border width 564 565 The border defaults to 2. 566 567 \param width Border width 568 \sa borderWidth() 569 */ 565 return m_data->wheelBorderWidth; 566 } 567 568 /*! 569 \brief Set the border width 570 571 The border defaults to 2. 572 573 \param width Border width 574 \sa borderWidth() 575 */ 570 576 void QwtWheel::setBorderWidth( int width ) 571 577 { 572 d_data->borderWidth = qMax( width, 0 );578 m_data->borderWidth = qMax( width, 0 ); 573 579 update(); 574 580 } … … 577 583 \return Border width 578 584 \sa setBorderWidth() 579 */ 585 */ 580 586 int QwtWheel::borderWidth() const 581 587 { 582 return d_data->borderWidth;588 return m_data->borderWidth; 583 589 } 584 590 585 591 /*! 586 592 \return Rectangle of the wheel without the outer border 587 */ 593 */ 588 594 QRect QwtWheel::wheelRect() const 589 595 { 590 const int bw = d_data->borderWidth;596 const int bw = m_data->borderWidth; 591 597 return contentsRect().adjusted( bw, bw, -bw, -bw ); 592 598 } 593 599 594 600 /*! 595 \brief Set the total angle which the wheel can be turned. 596 597 One full turn of the wheel corresponds to an angle of 598 360 degrees. A total angle of n*360 degrees means 599 that the wheel has to be turned n times around its axis 600 to get from the minimum value to the maximum value. 601 602 The default setting of the total angle is 360 degrees. 603 604 \param angle total angle in degrees 605 \sa totalAngle() 606 */ 601 \brief Set the total angle which the wheel can be turned. 602 603 One full turn of the wheel corresponds to an angle of 604 360 degrees. A total angle of n*360 degrees means 605 that the wheel has to be turned n times around its axis 606 to get from the minimum value to the maximum value. 607 608 The default setting of the total angle is 360 degrees. 609 610 \param angle total angle in degrees 611 \sa totalAngle() 612 */ 607 613 void QwtWheel::setTotalAngle( double angle ) 608 614 { … … 610 616 angle = 0.0; 611 617 612 d_data->totalAngle = angle;618 m_data->totalAngle = angle; 613 619 update(); 614 620 } 615 621 616 622 /*! 617 \return Total angle which the wheel can be turned. 618 \sa setTotalAngle() 619 */ 623 \return Total angle which the wheel can be turned. 624 \sa setTotalAngle() 625 */ 620 626 double QwtWheel::totalAngle() const 621 627 { 622 return d_data->totalAngle;623 } 624 625 /*! 626 \brief Set the wheel's orientation. 627 628 The default orientation is Qt::Horizontal. 629 630 \param orientation Qt::Horizontal or Qt::Vertical. 631 \sa orientation() 632 */ 628 return m_data->totalAngle; 629 } 630 631 /*! 632 \brief Set the wheel's orientation. 633 634 The default orientation is Qt::Horizontal. 635 636 \param orientation Qt::Horizontal or Qt::Vertical. 637 \sa orientation() 638 */ 633 639 void QwtWheel::setOrientation( Qt::Orientation orientation ) 634 640 { 635 if ( d_data->orientation == orientation )641 if ( m_data->orientation == orientation ) 636 642 return; 637 643 … … 645 651 } 646 652 647 d_data->orientation = orientation;653 m_data->orientation = orientation; 648 654 update(); 649 655 } 650 656 651 657 /*! 652 \return Orientation 653 \sa setOrientation() 654 */ 658 \return Orientation 659 \sa setOrientation() 660 */ 655 661 Qt::Orientation QwtWheel::orientation() const 656 662 { 657 return d_data->orientation;658 } 659 660 /*! 661 \brief Specify the visible portion of the wheel. 662 663 You may use this function for fine-tuning the appearance of 664 the wheel. The default value is 175 degrees. The value is 665 limited from 10 to 175 degrees. 666 667 \param angle Visible angle in degrees 668 \sa viewAngle(), setTotalAngle() 669 */ 663 return m_data->orientation; 664 } 665 666 /*! 667 \brief Specify the visible portion of the wheel. 668 669 You may use this function for fine-tuning the appearance of 670 the wheel. The default value is 175 degrees. The value is 671 limited from 10 to 175 degrees. 672 673 \param angle Visible angle in degrees 674 \sa viewAngle(), setTotalAngle() 675 */ 670 676 void QwtWheel::setViewAngle( double angle ) 671 677 { 672 d_data->viewAngle = qBound( 10.0, angle, 175.0 );678 m_data->viewAngle = qBound( 10.0, angle, 175.0 ); 673 679 update(); 674 680 } 675 681 676 682 /*! 677 \return Visible portion of the wheel 678 \sa setViewAngle(), totalAngle() 679 */ 683 \return Visible portion of the wheel 684 \sa setViewAngle(), totalAngle() 685 */ 680 686 double QwtWheel::viewAngle() const 681 687 { 682 return d_data->viewAngle;683 } 684 685 /*! 686 Determine the value corresponding to a specified point 687 688 \param pos Position 689 \return Value corresponding to pos 690 */ 691 double QwtWheel::valueAt( const QPoint &pos ) const688 return m_data->viewAngle; 689 } 690 691 /*! 692 Determine the value corresponding to a specified point 693 694 \param pos Position 695 \return Value corresponding to pos 696 */ 697 double QwtWheel::valueAt( const QPoint& pos ) const 692 698 { 693 699 const QRectF rect = wheelRect(); 694 700 695 701 double w, dx; 696 if ( d_data->orientation == Qt::Vertical )702 if ( m_data->orientation == Qt::Vertical ) 697 703 { 698 704 w = rect.height(); … … 708 714 return 0.0; 709 715 710 if ( d_data->inverted )716 if ( m_data->inverted ) 711 717 { 712 718 dx = w - dx; … … 715 721 // w pixels is an arc of viewAngle degrees, 716 722 // so we convert change in pixels to change in angle 717 const double ang = dx * d_data->viewAngle / w;723 const double ang = dx * m_data->viewAngle / w; 718 724 719 725 // value range maps to totalAngle degrees, 720 726 // so convert the change in angle to a change in value 721 const double val = ang * ( maximum() - minimum() ) / d_data->totalAngle;727 const double val = ang * ( maximum() - minimum() ) / m_data->totalAngle; 722 728 723 729 return val; … … 727 733 \brief Qt Paint Event 728 734 \param event Paint event 729 */ 730 void QwtWheel::paintEvent( QPaintEvent *event )735 */ 736 void QwtWheel::paintEvent( QPaintEvent* event ) 731 737 { 732 738 QPainter painter( this ); … … 734 740 735 741 QStyleOption opt; 736 opt.init(this); 742 opt.initFrom(this); 737 743 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 738 744 739 745 qDrawShadePanel( &painter, 740 contentsRect(), palette(), true, d_data->borderWidth );746 contentsRect(), palette(), true, m_data->borderWidth ); 741 747 742 748 drawWheelBackground( &painter, wheelRect() ); … … 752 758 \param painter Painter 753 759 \param rect Geometry for the wheel 754 */ 760 */ 755 761 void QwtWheel::drawWheelBackground( 756 QPainter *painter, const QRectF&rect )762 QPainter* painter, const QRectF& rect ) 757 763 { 758 764 painter->save(); … … 762 768 // draw shaded background 763 769 QLinearGradient gradient( rect.topLeft(), 764 ( d_data->orientation == Qt::Horizontal ) ? rect.topRight() : rect.bottomLeft() );770 ( m_data->orientation == Qt::Horizontal ) ? rect.topRight() : rect.bottomLeft() ); 765 771 gradient.setColorAt( 0.0, pal.color( QPalette::Button ) ); 766 772 gradient.setColorAt( 0.2, pal.color( QPalette::Midlight ) ); … … 773 779 774 780 const QPen lightPen( palette().color( QPalette::Light ), 775 d_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );781 m_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap ); 776 782 const QPen darkPen( pal.color( QPalette::Dark ), 777 d_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );778 779 const double bw2 = 0.5 * d_data->wheelBorderWidth;780 781 if ( d_data->orientation == Qt::Horizontal )783 m_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap ); 784 785 const double bw2 = 0.5 * m_data->wheelBorderWidth; 786 787 if ( m_data->orientation == Qt::Horizontal ) 782 788 { 783 789 painter->setPen( lightPen ); … … 808 814 \param painter Painter 809 815 \param rect Geometry for the wheel 810 */ 811 void QwtWheel::drawTicks( QPainter *painter, const QRectF&rect )812 { 813 const double range = d_data->maximum -d_data->minimum;814 815 if ( range == 0.0 || d_data->totalAngle == 0.0 )816 */ 817 void QwtWheel::drawTicks( QPainter* painter, const QRectF& rect ) 818 { 819 const double range = m_data->maximum - m_data->minimum; 820 821 if ( range == 0.0 || m_data->totalAngle == 0.0 ) 816 822 { 817 823 return; … … 823 829 0, Qt::SolidLine, Qt::FlatCap ); 824 830 825 const double cnvFactor = qAbs( d_data->totalAngle / range );826 const double halfIntv = 0.5 * d_data->viewAngle / cnvFactor;831 const double cnvFactor = qAbs( m_data->totalAngle / range ); 832 const double halfIntv = 0.5 * m_data->viewAngle / cnvFactor; 827 833 const double loValue = value() - halfIntv; 828 834 const double hiValue = value() + halfIntv; 829 const double tickWidth = 360.0 / double( d_data->tickCount ) / cnvFactor;830 const double sinArc = qFastSin( d_data->viewAngle * M_PI / 360.0 );831 832 if ( d_data->orientation == Qt::Horizontal )835 const double tickWidth = 360.0 / double( m_data->tickCount ) / cnvFactor; 836 const double sinArc = qFastSin( m_data->viewAngle * M_PI / 360.0 ); 837 838 if ( m_data->orientation == Qt::Horizontal ) 833 839 { 834 840 const double radius = rect.width() * 0.5; 835 841 836 double l1 = rect.top() + d_data->wheelBorderWidth;837 double l2 = rect.bottom() - d_data->wheelBorderWidth - 1;842 double l1 = rect.top() + m_data->wheelBorderWidth; 843 double l2 = rect.bottom() - m_data->wheelBorderWidth - 1; 838 844 839 845 // draw one point over the border if border > 1 840 if ( d_data->wheelBorderWidth > 1 )846 if ( m_data->wheelBorderWidth > 1 ) 841 847 { 842 848 l1--; … … 848 854 849 855 // draw tick marks 850 for ( double tickValue = ::ceil( loValue / tickWidth ) * tickWidth; 856 for ( double tickValue = std::ceil( loValue / tickWidth ) * tickWidth; 851 857 tickValue < hiValue; tickValue += tickWidth ) 852 858 { … … 857 863 858 864 double tickPos; 859 if ( d_data->inverted )865 if ( m_data->inverted ) 860 866 tickPos = rect.left() + off; 861 867 else … … 865 871 { 866 872 painter->setPen( darkPen ); 867 painter->drawLine( QPointF( tickPos - 1 , l1 ),873 painter->drawLine( QPointF( tickPos - 1, l1 ), 868 874 QPointF( tickPos - 1, l2 ) ); 869 875 painter->setPen( lightPen ); … … 877 883 const double radius = rect.height() * 0.5; 878 884 879 double l1 = rect.left() + d_data->wheelBorderWidth;880 double l2 = rect.right() - d_data->wheelBorderWidth - 1;881 882 if ( d_data->wheelBorderWidth > 1 )885 double l1 = rect.left() + m_data->wheelBorderWidth; 886 double l2 = rect.right() - m_data->wheelBorderWidth - 1; 887 888 if ( m_data->wheelBorderWidth > 1 ) 883 889 { 884 890 l1--; … … 889 895 const double minpos = rect.top() + 2; 890 896 891 for ( double tickValue = ::ceil( loValue / tickWidth ) * tickWidth; 897 for ( double tickValue = std::ceil( loValue / tickWidth ) * tickWidth; 892 898 tickValue < hiValue; tickValue += tickWidth ) 893 899 { … … 899 905 double tickPos; 900 906 901 if ( d_data->inverted )907 if ( m_data->inverted ) 902 908 tickPos = rect.bottom() - off; 903 909 else … … 918 924 919 925 /*! 920 \brief Set the width of the wheel 921 922 Corresponds to the wheel height for horizontal orientation, 923 and the wheel width for vertical orientation. 924 925 \param width the wheel's width 926 \sa wheelWidth() 927 */ 926 \brief Set the width of the wheel 927 928 Corresponds to the wheel height for horizontal orientation, 929 and the wheel width for vertical orientation. 930 931 \param width the wheel's width 932 \sa wheelWidth() 933 */ 928 934 void QwtWheel::setWheelWidth( int width ) 929 935 { 930 d_data->wheelWidth = width;936 m_data->wheelWidth = width; 931 937 update(); 932 938 } 933 939 934 940 /*! 935 \return Width of the wheel 936 \sa setWheelWidth() 937 */ 941 \return Width of the wheel 942 \sa setWheelWidth() 943 */ 938 944 int QwtWheel::wheelWidth() const 939 945 { 940 return d_data->wheelWidth;941 } 942 943 /*! 944 \return a size hint 945 */ 946 return m_data->wheelWidth; 947 } 948 949 /*! 950 \return a size hint 951 */ 946 952 QSize QwtWheel::sizeHint() const 947 953 { 948 954 const QSize hint = minimumSizeHint(); 949 return hint.expandedTo( QApplication::globalStrut());950 } 951 952 /*! 953 \return Minimum size hint 954 \warning The return value is based on the wheel width. 955 */ 955 return qwtExpandedToGlobalStrut( hint ); 956 } 957 958 /*! 959 \return Minimum size hint 960 \warning The return value is based on the wheel width. 961 */ 956 962 QSize QwtWheel::minimumSizeHint() const 957 963 { 958 QSize sz( 3 * d_data->wheelWidth + 2 *d_data->borderWidth,959 d_data->wheelWidth + 2 *d_data->borderWidth );960 if ( d_data->orientation != Qt::Horizontal )964 QSize sz( 3 * m_data->wheelWidth + 2 * m_data->borderWidth, 965 m_data->wheelWidth + 2 * m_data->borderWidth ); 966 if ( m_data->orientation != Qt::Horizontal ) 961 967 sz.transpose(); 962 968 … … 965 971 966 972 /*! 967 \brief Set the step size of the counter 968 969 A value <= 0.0 disables stepping 970 971 \param stepSize Single step size 972 \sa singleStep(), setPageStepCount() 973 */ 973 \brief Set the step size of the counter 974 975 A value <= 0.0 disables stepping 976 977 \param stepSize Single step size 978 \sa singleStep(), setPageStepCount() 979 */ 974 980 void QwtWheel::setSingleStep( double stepSize ) 975 981 { 976 d_data->singleStep = qMax( stepSize, 0.0 );977 } 978 979 /*! 980 \return Single step size 981 \sa setSingleStep() 982 m_data->singleStep = qwtMaxF( stepSize, 0.0 ); 983 } 984 985 /*! 986 \return Single step size 987 \sa setSingleStep() 982 988 */ 983 989 double QwtWheel::singleStep() const 984 990 { 985 return d_data->singleStep;986 } 987 988 /*! 989 \brief En/Disable step alignment 990 991 When step alignment is enabled value changes initiated by 992 user input ( mouse, keyboard, wheel ) are aligned to 993 the multiples of the single step. 994 995 \param on On/Off 996 \sa stepAlignment(), setSingleStep() 991 return m_data->singleStep; 992 } 993 994 /*! 995 \brief En/Disable step alignment 996 997 When step alignment is enabled value changes initiated by 998 user input ( mouse, keyboard, wheel ) are aligned to 999 the multiples of the single step. 1000 1001 \param on On/Off 1002 \sa stepAlignment(), setSingleStep() 997 1003 */ 998 1004 void QwtWheel::setStepAlignment( bool on ) 999 1005 { 1000 if ( on != d_data->stepAlignment )1001 { 1002 d_data->stepAlignment = on;1003 } 1004 } 1005 1006 /*! 1007 \return True, when the step alignment is enabled 1008 \sa setStepAlignment(), singleStep() 1006 if ( on != m_data->stepAlignment ) 1007 { 1008 m_data->stepAlignment = on; 1009 } 1010 } 1011 1012 /*! 1013 \return True, when the step alignment is enabled 1014 \sa setStepAlignment(), singleStep() 1009 1015 */ 1010 1016 bool QwtWheel::stepAlignment() const 1011 1017 { 1012 return d_data->stepAlignment;1013 } 1014 1015 /*! 1016 \brief Set the page step count 1017 1018 pageStepCount is a multiplicator for the single step size 1019 that typically corresponds to the user pressing PageUp or PageDown. 1020 1021 A value of 0 disables page stepping. 1022 1023 The default value is 1. 1024 1025 \param count Multiplicator for the single step size 1026 \sa pageStepCount(), setSingleStep() 1018 return m_data->stepAlignment; 1019 } 1020 1021 /*! 1022 \brief Set the page step count 1023 1024 pageStepCount is a multiplicator for the single step size 1025 that typically corresponds to the user pressing PageUp or PageDown. 1026 1027 A value of 0 disables page stepping. 1028 1029 The default value is 1. 1030 1031 \param count Multiplicator for the single step size 1032 \sa pageStepCount(), setSingleStep() 1027 1033 */ 1028 1034 void QwtWheel::setPageStepCount( int count ) 1029 1035 { 1030 d_data->pageStepCount = qMax( 0, count );1031 } 1032 1033 /*! 1034 \return Page step count 1035 \sa setPageStepCount(), singleStep() 1036 m_data->pageStepCount = qMax( 0, count ); 1037 } 1038 1039 /*! 1040 \return Page step count 1041 \sa setPageStepCount(), singleStep() 1036 1042 */ 1037 1043 int QwtWheel::pageStepCount() const 1038 1044 { 1039 return d_data->pageStepCount;1040 } 1041 1042 /*! 1043 \brief Set the minimum and maximum values 1044 1045 The maximum is adjusted if necessary to ensure that the range remains valid. 1046 The value might be modified to be inside of the range. 1047 1048 \param min Minimum value 1049 \param max Maximum value 1050 1051 \sa minimum(), maximum() 1045 return m_data->pageStepCount; 1046 } 1047 1048 /*! 1049 \brief Set the minimum and maximum values 1050 1051 The maximum is adjusted if necessary to ensure that the range remains valid. 1052 The value might be modified to be inside of the range. 1053 1054 \param min Minimum value 1055 \param max Maximum value 1056 1057 \sa minimum(), maximum() 1052 1058 */ 1053 1059 void QwtWheel::setRange( double min, double max ) 1054 1060 { 1055 max = q Max( min, max );1056 1057 if ( d_data->minimum == min &&d_data->maximum == max )1061 max = qwtMaxF( min, max ); 1062 1063 if ( m_data->minimum == min && m_data->maximum == max ) 1058 1064 return; 1059 1065 1060 d_data->minimum = min;1061 d_data->maximum = max;1062 1063 if ( d_data->value < min ||d_data->value > max )1064 { 1065 d_data->value = qBound( min,d_data->value, max );1066 m_data->minimum = min; 1067 m_data->maximum = max; 1068 1069 if ( m_data->value < min || m_data->value > max ) 1070 { 1071 m_data->value = qBound( min, m_data->value, max ); 1066 1072 1067 1073 update(); 1068 Q_EMIT valueChanged( d_data->value );1069 } 1070 } 1071 /*! 1072 Set the minimum value of the range 1073 1074 \param value Minimum value 1075 \sa setRange(), setMaximum(), minimum() 1076 1077 \note The maximum is adjusted if necessary to ensure that the range remains valid. 1078 */ 1074 Q_EMIT valueChanged( m_data->value ); 1075 } 1076 } 1077 /*! 1078 Set the minimum value of the range 1079 1080 \param value Minimum value 1081 \sa setRange(), setMaximum(), minimum() 1082 1083 \note The maximum is adjusted if necessary to ensure that the range remains valid. 1084 */ 1079 1085 void QwtWheel::setMinimum( double value ) 1080 1086 { … … 1083 1089 1084 1090 /*! 1085 \return The minimum of the range 1086 \sa setRange(), setMinimum(), maximum() 1087 */ 1091 \return The minimum of the range 1092 \sa setRange(), setMinimum(), maximum() 1093 */ 1088 1094 double QwtWheel::minimum() const 1089 1095 { 1090 return d_data->minimum;1091 } 1092 1093 /*! 1094 Set the maximum value of the range 1095 1096 \param value Maximum value 1097 \sa setRange(), setMinimum(), maximum() 1098 */ 1096 return m_data->minimum; 1097 } 1098 1099 /*! 1100 Set the maximum value of the range 1101 1102 \param value Maximum value 1103 \sa setRange(), setMinimum(), maximum() 1104 */ 1099 1105 void QwtWheel::setMaximum( double value ) 1100 1106 { … … 1103 1109 1104 1110 /*! 1105 \return The maximum of the range 1106 \sa setRange(), setMaximum(), minimum() 1107 */ 1111 \return The maximum of the range 1112 \sa setRange(), setMaximum(), minimum() 1113 */ 1108 1114 double QwtWheel::maximum() const 1109 1115 { 1110 return d_data->maximum;1111 } 1112 1113 /*! 1114 \brief Set a new value without adjusting to the step raster 1115 1116 \param value New value 1117 1118 \sa value(), valueChanged() 1119 \warning The value is clipped when it lies outside the range. 1120 */ 1116 return m_data->maximum; 1117 } 1118 1119 /*! 1120 \brief Set a new value without adjusting to the step raster 1121 1122 \param value New value 1123 1124 \sa value(), valueChanged() 1125 \warning The value is clipped when it lies outside the range. 1126 */ 1121 1127 void QwtWheel::setValue( double value ) 1122 1128 { 1123 1129 stopFlying(); 1124 d_data->isScrolling = false;1125 1126 value = qBound( d_data->minimum, value,d_data->maximum );1127 1128 if ( d_data->value != value )1129 { 1130 d_data->value = value;1130 m_data->isScrolling = false; 1131 1132 value = qBound( m_data->minimum, value, m_data->maximum ); 1133 1134 if ( m_data->value != value ) 1135 { 1136 m_data->value = value; 1131 1137 1132 1138 update(); 1133 Q_EMIT valueChanged( d_data->value );1134 } 1135 } 1136 1137 /*! 1138 \return Current value of the wheel 1139 \sa setValue(), valueChanged() 1139 Q_EMIT valueChanged( m_data->value ); 1140 } 1141 } 1142 1143 /*! 1144 \return Current value of the wheel 1145 \sa setValue(), valueChanged() 1140 1146 */ 1141 1147 double QwtWheel::value() const 1142 1148 { 1143 return d_data->value;1144 } 1145 1146 /*! 1147 \brief En/Disable inverted appearance 1148 1149 An inverted wheel increases its values in the opposite direction. 1150 The direction of an inverted horizontal wheel will be from right to left 1151 an inverted vertical wheel will increase from bottom to top. 1152 1153 \param on En/Disable inverted appearance 1154 \sa isInverted() 1149 return m_data->value; 1150 } 1151 1152 /*! 1153 \brief En/Disable inverted appearance 1154 1155 An inverted wheel increases its values in the opposite direction. 1156 The direction of an inverted horizontal wheel will be from right to left 1157 an inverted vertical wheel will increase from bottom to top. 1158 1159 \param on En/Disable inverted appearance 1160 \sa isInverted() 1155 1161 1156 1162 */ 1157 1163 void QwtWheel::setInverted( bool on ) 1158 1164 { 1159 if ( d_data->inverted != on )1160 { 1161 d_data->inverted = on;1165 if ( m_data->inverted != on ) 1166 { 1167 m_data->inverted = on; 1162 1168 update(); 1163 1169 } … … 1165 1171 1166 1172 /*! 1167 \return True, when the wheel is inverted 1168 \sa setInverted() 1173 \return True, when the wheel is inverted 1174 \sa setInverted() 1169 1175 */ 1170 1176 bool QwtWheel::isInverted() const 1171 1177 { 1172 return d_data->inverted;1173 } 1174 1175 /*! 1176 \brief En/Disable wrapping 1177 1178 If wrapping is true stepping up from maximum() value will take 1179 you to the minimum() value and vice versa. 1180 1181 \param on En/Disable wrapping 1182 \sa wrapping() 1178 return m_data->inverted; 1179 } 1180 1181 /*! 1182 \brief En/Disable wrapping 1183 1184 If wrapping is true stepping up from maximum() value will take 1185 you to the minimum() value and vice versa. 1186 1187 \param on En/Disable wrapping 1188 \sa wrapping() 1183 1189 */ 1184 1190 void QwtWheel::setWrapping( bool on ) 1185 1191 { 1186 d_data->wrapping = on;1187 } 1188 1189 /*! 1190 \return True, when wrapping is set 1191 \sa setWrapping() 1192 m_data->wrapping = on; 1193 } 1194 1195 /*! 1196 \return True, when wrapping is set 1197 \sa setWrapping() 1192 1198 */ 1193 1199 bool QwtWheel::wrapping() const 1194 1200 { 1195 return d_data->wrapping;1196 } 1197 1198 /*! 1199 \brief Set the slider's mass for flywheel effect. 1200 1201 If the slider's mass is greater then 0, it will continue 1202 to move after the mouse button has been released. Its speed 1203 decreases with time at a rate depending on the slider's mass. 1204 A large mass means that it will continue to move for a 1205 long time. 1206 1207 Derived widgets may overload this function to make it public. 1208 1209 \param mass New mass in kg 1210 1211 \bug If the mass is smaller than 1g, it is set to zero. 1201 return m_data->wrapping; 1202 } 1203 1204 /*! 1205 \brief Set the slider's mass for flywheel effect. 1206 1207 If the slider's mass is greater then 0, it will continue 1208 to move after the mouse button has been released. Its speed 1209 decreases with time at a rate depending on the slider's mass. 1210 A large mass means that it will continue to move for a 1211 long time. 1212 1213 Derived widgets may overload this function to make it public. 1214 1215 \param mass New mass in kg 1216 1217 \bug If the mass is smaller than 1g, it is set to zero. 1212 1218 The maximal mass is limited to 100kg. 1213 \sa mass() 1214 */ 1219 \sa mass() 1220 */ 1215 1221 void QwtWheel::setMass( double mass ) 1216 1222 { 1217 1223 if ( mass < 0.001 ) 1218 1224 { 1219 d_data->mass = 0.0;1225 m_data->mass = 0.0; 1220 1226 } 1221 1227 else 1222 1228 { 1223 d_data->mass = qMin( 100.0, mass );1224 } 1225 1226 if ( d_data->mass <= 0.0 )1229 m_data->mass = qwtMinF( 100.0, mass ); 1230 } 1231 1232 if ( m_data->mass <= 0.0 ) 1227 1233 stopFlying(); 1228 1234 } 1229 1235 1230 1236 /*! 1231 \return mass 1232 \sa setMass() 1233 */ 1237 \return mass 1238 \sa setMass() 1239 */ 1234 1240 double QwtWheel::mass() const 1235 1241 { 1236 return d_data->mass;1242 return m_data->mass; 1237 1243 } 1238 1244 … … 1240 1246 void QwtWheel::stopFlying() 1241 1247 { 1242 if ( d_data->timerId != 0 )1243 { 1244 killTimer( d_data->timerId );1245 d_data->timerId = 0;1246 d_data->speed = 0.0;1248 if ( m_data->timerId != 0 ) 1249 { 1250 killTimer( m_data->timerId ); 1251 m_data->timerId = 0; 1252 m_data->speed = 0.0; 1247 1253 } 1248 1254 } … … 1250 1256 double QwtWheel::boundedValue( double value ) const 1251 1257 { 1252 const double range = d_data->maximum -d_data->minimum;1253 1254 if ( d_data->wrapping && range >= 0.0 )1255 { 1256 if ( value < d_data->minimum )1257 { 1258 value += ::ceil( ( d_data->minimum - value ) / range ) * range;1259 } 1260 else if ( value > d_data->maximum )1261 { 1262 value -= ::ceil( ( value - d_data->maximum ) / range ) * range;1258 const double range = m_data->maximum - m_data->minimum; 1259 1260 if ( m_data->wrapping && range >= 0.0 ) 1261 { 1262 if ( value < m_data->minimum ) 1263 { 1264 value += std::ceil( ( m_data->minimum - value ) / range ) * range; 1265 } 1266 else if ( value > m_data->maximum ) 1267 { 1268 value -= std::ceil( ( value - m_data->maximum ) / range ) * range; 1263 1269 } 1264 1270 } 1265 1271 else 1266 1272 { 1267 value = qBound( d_data->minimum, value,d_data->maximum );1273 value = qBound( m_data->minimum, value, m_data->maximum ); 1268 1274 } 1269 1275 … … 1273 1279 double QwtWheel::alignedValue( double value ) const 1274 1280 { 1275 const double stepSize = d_data->singleStep;1281 const double stepSize = m_data->singleStep; 1276 1282 1277 1283 if ( stepSize > 0.0 ) 1278 1284 { 1279 value = d_data->minimum +1280 qRound( ( value - d_data->minimum ) / stepSize ) * stepSize;1285 value = m_data->minimum + 1286 qRound( ( value - m_data->minimum ) / stepSize ) * stepSize; 1281 1287 1282 1288 if ( stepSize > 1e-12 ) … … 1287 1293 value = 0.0; 1288 1294 } 1289 else if ( qFuzzyCompare( value, d_data->maximum ) )1295 else if ( qFuzzyCompare( value, m_data->maximum ) ) 1290 1296 { 1291 1297 // correct rounding error at the border 1292 value = d_data->maximum;1298 value = m_data->maximum; 1293 1299 } 1294 1300 } … … 1298 1304 } 1299 1305 1306 #include "moc_qwt_wheel.cpp" -
trunk/BNC/qwt/qwt_wheel.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 16 16 /*! 17 \brief The Wheel Widget 17 \brief The Wheel Widget 18 18 19 The wheel widget can be used to change values over a very large range 20 in very small steps. Using the setMass() member, it can be configured 21 as a flying wheel. 19 The wheel widget can be used to change values over a very large range 20 in very small steps. Using the setMass() member, it can be configured 21 as a flying wheel. 22 22 23 The default range of the wheel is [0.0, 100.0] 23 The default range of the wheel is [0.0, 100.0] 24 24 25 \sa The radio example. 26 */ 27 class QWT_EXPORT QwtWheel: public QWidget 25 \sa The radio example. 26 */ 27 class QWT_EXPORT QwtWheel : public QWidget 28 28 { 29 29 Q_OBJECT 30 30 31 31 Q_PROPERTY( Qt::Orientation orientation 32 READ orientation WRITE setOrientation )32 READ orientation WRITE setOrientation ) 33 33 34 Q_PROPERTY( double value READ value WRITE setValue ) 34 Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged USER true ) 35 35 36 Q_PROPERTY( double minimum READ minimum WRITE setMinimum ) 36 37 Q_PROPERTY( double maximum READ maximum WRITE setMaximum ) … … 54 55 Q_PROPERTY( int wheelBorderWidth READ wheelBorderWidth WRITE setWheelBorderWidth ) 55 56 56 public: 57 explicit QwtWheel( QWidget *parent = NULL );57 public: 58 explicit QwtWheel( QWidget* parent = NULL ); 58 59 virtual ~QwtWheel(); 59 60 … … 109 110 double mass() const; 110 111 111 public Q_SLOTS: 112 public Q_SLOTS: 112 113 void setValue( double ); 113 114 void setTotalAngle ( double ); … … 115 116 void setMass( double ); 116 117 117 Q_SIGNALS: 118 Q_SIGNALS: 118 119 119 120 /*! 120 \brief Notify a change of value. 121 \brief Notify a change of value. 121 122 122 When tracking is enabled this signal will be emitted every 123 time the value changes. 123 When tracking is enabled this signal will be emitted every 124 time the value changes. 124 125 125 \param value new value 126 \sa setTracking() 127 */ 126 \param value new value 127 \sa setTracking() 128 */ 128 129 void valueChanged( double value ); 129 130 130 131 /*! 131 This signal is emitted when the user presses the 132 the wheel with the mouse 133 */ 132 This signal is emitted when the user presses the 133 the wheel with the mouse 134 */ 134 135 void wheelPressed(); 135 136 136 137 /*! 137 This signal is emitted when the user releases the mouse 138 */ 138 This signal is emitted when the user releases the mouse 139 */ 139 140 void wheelReleased(); 140 141 141 142 /*! 142 This signal is emitted when the user moves the 143 wheel with the mouse. 143 This signal is emitted when the user moves the 144 wheel with the mouse. 144 145 145 \param value new value 146 */ 146 \param value new value 147 */ 147 148 void wheelMoved( double value ); 148 149 149 protected: 150 virtual void paintEvent( QPaintEvent * );151 virtual void mousePressEvent( QMouseEvent * );152 virtual void mouseReleaseEvent( QMouseEvent * );153 virtual void mouseMoveEvent( QMouseEvent * );154 virtual void keyPressEvent( QKeyEvent * );155 virtual void wheelEvent( QWheelEvent * );156 virtual void timerEvent( QTimerEvent * );150 protected: 151 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 152 virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE; 153 virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE; 154 virtual void mouseMoveEvent( QMouseEvent* ) QWT_OVERRIDE; 155 virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE; 156 virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE; 157 virtual void timerEvent( QTimerEvent* ) QWT_OVERRIDE; 157 158 158 159 void stopFlying(); … … 160 161 QRect wheelRect() const; 161 162 162 virtual QSize sizeHint() const; 163 virtual QSize minimumSizeHint() const; 163 virtual QSize sizeHint() const QWT_OVERRIDE; 164 virtual QSize minimumSizeHint() const QWT_OVERRIDE; 164 165 165 virtual void drawTicks( QPainter *, const QRectF& );166 virtual void drawWheelBackground( QPainter *, const QRectF& );166 virtual void drawTicks( QPainter*, const QRectF& ); 167 virtual void drawWheelBackground( QPainter*, const QRectF& ); 167 168 168 virtual double valueAt( const QPoint & ) const;169 virtual double valueAt( const QPoint& ) const; 169 170 170 private: 171 private: 171 172 double alignedValue( double ) const; 172 173 double boundedValue( double ) const; 173 174 174 175 class PrivateData; 175 PrivateData *d_data;176 PrivateData* m_data; 176 177 }; 177 178 -
trunk/BNC/qwt/qwt_widget_overlay.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_widget_overlay.h" 11 11 #include "qwt_painter.h" 12 12 13 #include <qpainter.h> 13 14 #include <qpaintengine.h> … … 16 17 #include <qevent.h> 17 18 19 #include <cstdlib> 20 18 21 static QImage::Format qwtMaskImageFormat() 19 22 { … … 24 27 } 25 28 26 static QRegion qwtAlphaMask( 27 const QImage& image, const QVector<QRect> &rects ) 29 static QRegion qwtAlphaMask( const QImage& image, const QRegion& region ) 28 30 { 29 31 const int w = image.width(); 30 32 const int h = image.height(); 31 33 32 QRegion region;34 QRegion mask; 33 35 QRect rect; 34 36 37 #if QT_VERSION >= 0x050800 38 for ( QRegion::const_iterator it = region.cbegin(); 39 it != region.cend(); ++it ) 40 { 41 const QRect& r = *it; 42 #else 43 const QVector< QRect > rects = region.rects(); 35 44 for ( int i = 0; i < rects.size(); i++ ) 36 45 { 46 const QRect& r = rects[i]; 47 #endif 37 48 int x1, x2, y1, y2; 38 r ects[i].getCoords( &x1, &y1, &x2, &y2 );49 r.getCoords( &x1, &y1, &x2, &y2 ); 39 50 40 51 x1 = qMax( x1, 0 ); … … 48 59 int rx0 = -1; 49 60 50 const uint *line =51 reinterpret_cast<const uint *> ( image.scanLine( y ) ) + x1;61 const uint* line = 62 reinterpret_cast< const uint* > ( image.scanLine( y ) ) + x1; 52 63 for ( int x = x1; x <= x2; x++ ) 53 64 { … … 58 69 { 59 70 rect.setCoords( rx0, y, x - 1, y ); 60 region+= rect;71 mask += rect; 61 72 } 62 73 else … … 72 83 { 73 84 rect.setCoords( rx0, y, x2, y ); 74 region = region.united( rect );85 mask = mask.united( rect ); 75 86 } 76 87 } 77 88 } 78 89 79 return region;90 return mask; 80 91 } 81 92 82 93 class QwtWidgetOverlay::PrivateData 83 94 { 84 public: 85 PrivateData() :86 maskMode( QwtWidgetOverlay::MaskHint ) ,87 renderMode( QwtWidgetOverlay::AutoRenderMode ) ,88 rgbaBuffer( NULL ) 95 public: 96 PrivateData() 97 : maskMode( QwtWidgetOverlay::MaskHint ) 98 , renderMode( QwtWidgetOverlay::AutoRenderMode ) 99 , rgbaBuffer( NULL ) 89 100 { 90 101 } … … 99 110 if ( rgbaBuffer ) 100 111 { 101 ::free( rgbaBuffer ); 112 std::free( rgbaBuffer ); 102 113 rgbaBuffer = NULL; 103 114 } … … 106 117 MaskMode maskMode; 107 118 RenderMode renderMode; 108 uchar *rgbaBuffer;119 uchar* rgbaBuffer; 109 120 }; 110 121 … … 112 123 \brief Constructor 113 124 \param widget Parent widget, where the overlay is aligned to 114 */ 115 QwtWidgetOverlay::QwtWidgetOverlay( QWidget* widget ) :116 QWidget( widget ) 117 { 118 d_data = new PrivateData;125 */ 126 QwtWidgetOverlay::QwtWidgetOverlay( QWidget* widget ) 127 : QWidget( widget ) 128 { 129 m_data = new PrivateData; 119 130 120 131 setAttribute( Qt::WA_TransparentForMouseEvents ); … … 132 143 QwtWidgetOverlay::~QwtWidgetOverlay() 133 144 { 134 delete d_data;145 delete m_data; 135 146 } 136 147 … … 143 154 void QwtWidgetOverlay::setMaskMode( MaskMode mode ) 144 155 { 145 if ( mode != d_data->maskMode )146 { 147 d_data->maskMode = mode;148 d_data->resetRgbaBuffer();156 if ( mode != m_data->maskMode ) 157 { 158 m_data->maskMode = mode; 159 m_data->resetRgbaBuffer(); 149 160 } 150 161 } … … 156 167 QwtWidgetOverlay::MaskMode QwtWidgetOverlay::maskMode() const 157 168 { 158 return d_data->maskMode;169 return m_data->maskMode; 159 170 } 160 171 … … 164 175 165 176 \sa RenderMode, renderMode() 166 */ 177 */ 167 178 void QwtWidgetOverlay::setRenderMode( RenderMode mode ) 168 179 { 169 d_data->renderMode = mode;180 m_data->renderMode = mode; 170 181 } 171 182 … … 176 187 QwtWidgetOverlay::RenderMode QwtWidgetOverlay::renderMode() const 177 188 { 178 return d_data->renderMode;189 return m_data->renderMode; 179 190 } 180 191 … … 190 201 void QwtWidgetOverlay::updateMask() 191 202 { 192 d_data->resetRgbaBuffer();203 m_data->resetRgbaBuffer(); 193 204 194 205 QRegion mask; 195 206 196 if ( d_data->maskMode == QwtWidgetOverlay::MaskHint )207 if ( m_data->maskMode == QwtWidgetOverlay::MaskHint ) 197 208 { 198 209 mask = maskHint(); 199 210 } 200 else if ( d_data->maskMode == QwtWidgetOverlay::AlphaMask )211 else if ( m_data->maskMode == QwtWidgetOverlay::AlphaMask ) 201 212 { 202 213 // TODO: the image doesn't need to be larger than … … 211 222 // QImage::fill( 0 ) or memset() 212 223 213 d_data->rgbaBuffer = ( uchar* )::calloc( width() * height(), 4 );214 215 QImage image( d_data->rgbaBuffer,224 m_data->rgbaBuffer = ( uchar* )::calloc( width() * height(), 4 ); 225 226 QImage image( m_data->rgbaBuffer, 216 227 width(), height(), qwtMaskImageFormat() ); 217 228 … … 220 231 painter.end(); 221 232 222 mask = qwtAlphaMask( image, hint .rects());223 224 if ( d_data->renderMode == QwtWidgetOverlay::DrawOverlay )233 mask = qwtAlphaMask( image, hint ); 234 235 if ( m_data->renderMode == QwtWidgetOverlay::DrawOverlay ) 225 236 { 226 237 // we don't need the buffer later 227 d_data->resetRgbaBuffer();238 m_data->resetRgbaBuffer(); 228 239 } 229 240 } … … 243 254 244 255 /*! 245 Paint event 246 \param event Paint event 247 248 \sa drawOverlay() 249 */ 256 Paint event 257 \param event Paint event 258 259 \sa drawOverlay() 260 */ 250 261 void QwtWidgetOverlay::paintEvent( QPaintEvent* event ) 251 262 { 252 const QRegion &clipRegion = event->region();263 const QRegion& clipRegion = event->region(); 253 264 254 265 QPainter painter( this ); 255 266 256 267 bool useRgbaBuffer = false; 257 if ( d_data->renderMode == QwtWidgetOverlay::CopyAlphaMask )268 if ( m_data->renderMode == QwtWidgetOverlay::CopyAlphaMask ) 258 269 { 259 270 useRgbaBuffer = true; 260 271 } 261 else if ( d_data->renderMode == QwtWidgetOverlay::AutoRenderMode )272 else if ( m_data->renderMode == QwtWidgetOverlay::AutoRenderMode ) 262 273 { 263 274 if ( painter.paintEngine()->type() == QPaintEngine::Raster ) … … 265 276 } 266 277 267 if ( d_data->rgbaBuffer && useRgbaBuffer )268 { 269 const QImage image( d_data->rgbaBuffer,278 if ( m_data->rgbaBuffer && useRgbaBuffer ) 279 { 280 const QImage image( m_data->rgbaBuffer, 270 281 width(), height(), qwtMaskImageFormat() ); 271 282 272 QVector<QRect> rects; 273 if ( clipRegion.rects().size() > 2000 ) 283 const int rectCount = clipRegion.rectCount(); 284 285 if ( rectCount > 2000 ) 274 286 { 275 287 // the region is to complex 276 288 painter.setClipRegion( clipRegion ); 277 rects += clipRegion.boundingRect(); 289 290 const QRect r = clipRegion.boundingRect(); 291 painter.drawImage( r.topLeft(), image, r ); 278 292 } 279 293 else 280 294 { 281 rects = clipRegion.rects(); 282 } 283 284 for ( int i = 0; i < rects.size(); i++ ) 285 { 286 const QRect r = rects[i]; 287 painter.drawImage( r.topLeft(), image, r ); 295 #if QT_VERSION >= 0x050800 296 for ( QRegion::const_iterator it = clipRegion.cbegin(); 297 it != clipRegion.cend(); ++it ) 298 { 299 const QRect& r = *it; 300 painter.drawImage( r.topLeft(), image, r ); 301 } 302 #else 303 const QVector< QRect > rects = clipRegion.rects(); 304 for ( int i = 0; i < rects.size(); i++ ) 305 { 306 const QRect& r = rects[i]; 307 painter.drawImage( r.topLeft(), image, r ); 308 } 309 #endif 288 310 } 289 311 } … … 296 318 297 319 /*! 298 Resize event 299 \param event Resize event 300 */ 320 Resize event 321 \param event Resize event 322 */ 301 323 void QwtWidgetOverlay::resizeEvent( QResizeEvent* event ) 302 324 { 303 325 Q_UNUSED( event ); 304 326 305 d_data->resetRgbaBuffer(); 306 } 307 308 void QwtWidgetOverlay::draw( QPainter *painter ) const 309 { 310 QWidget *widget = const_cast< QWidget *>( parentWidget() ); 311 if ( widget ) 312 { 313 painter->setClipRect( parentWidget()->contentsRect() ); 327 m_data->resetRgbaBuffer(); 328 } 329 330 void QwtWidgetOverlay::draw( QPainter* painter ) const 331 { 332 if ( QWidget* widget = parentWidget() ) 333 { 334 painter->setClipRect( widget->contentsRect() ); 314 335 315 336 // something special for the plot canvas … … 324 345 Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, rect() ) ); 325 346 326 if (!clipPath.isEmpty()) 347 if (!clipPath.isEmpty() ) 327 348 painter->setClipPath( clipPath, Qt::IntersectClip ); 328 349 } … … 356 377 357 378 /*! 358 \brief Event filter 359 360 Resize the overlay according to the size of the parent widget. 361 362 \param object Object to be filtered 363 \param event Event 364 365 \return See QObject::eventFilter() 366 */ 379 \brief Event filter 380 381 Resize the overlay according to the size of the parent widget. 382 383 \param object Object to be filtered 384 \param event Event 385 386 \return See QObject::eventFilter() 387 */ 367 388 368 389 bool QwtWidgetOverlay::eventFilter( QObject* object, QEvent* event ) … … 370 391 if ( object == parent() && event->type() == QEvent::Resize ) 371 392 { 372 QResizeEvent *resizeEvent = static_cast<QResizeEvent*>( event );393 QResizeEvent* resizeEvent = static_cast< QResizeEvent* >( event ); 373 394 resize( resizeEvent->size() ); 374 395 } … … 376 397 return QObject::eventFilter( object, event ); 377 398 } 399 400 #include "moc_qwt_widget_overlay.cpp" -
trunk/BNC/qwt/qwt_widget_overlay.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_global.h" 14 14 #include <qwidget.h> 15 #include <qregion.h>16 15 17 16 class QPainter; 17 class QRegion; 18 18 19 19 /*! … … 38 38 \sa QwtPlotCanvas::BackingStore 39 39 */ 40 class QWT_EXPORT QwtWidgetOverlay: public QWidget 40 class QWT_EXPORT QwtWidgetOverlay : public QWidget 41 41 { 42 public: 42 Q_OBJECT 43 44 public: 43 45 /*! 44 46 \brief Mask mode … … 112 114 }; 113 115 114 QwtWidgetOverlay( QWidget* ); 116 explicit QwtWidgetOverlay( QWidget* ); 115 117 virtual ~QwtWidgetOverlay(); 116 118 … … 121 123 RenderMode renderMode() const; 122 124 125 virtual bool eventFilter( QObject*, QEvent*) QWT_OVERRIDE; 126 127 public Q_SLOTS: 123 128 void updateOverlay(); 124 129 125 virtual bool eventFilter( QObject *, QEvent *); 126 127 protected: 128 virtual void paintEvent( QPaintEvent* event ); 129 virtual void resizeEvent( QResizeEvent* event ); 130 protected: 131 virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE; 132 virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE; 130 133 131 134 virtual QRegion maskHint() const; … … 135 138 \param painter Painter 136 139 */ 137 virtual void drawOverlay( QPainter *painter ) const = 0;140 virtual void drawOverlay( QPainter* painter ) const = 0; 138 141 139 private: 142 private: 140 143 void updateMask(); 141 void draw( QPainter * ) const;144 void draw( QPainter* ) const; 142 145 143 private: 146 private: 144 147 class PrivateData; 145 PrivateData *d_data;148 PrivateData* m_data; 146 149 }; 147 150 -
trunk/BNC/qwt/src.pri
r9383 r11158 12 12 qwt.h \ 13 13 qwt_abstract_scale_draw.h \ 14 qwt_bezier.h \ 14 15 qwt_clipper.h \ 15 16 qwt_color_map.h \ 16 qwt_compat.h \17 17 qwt_column_symbol.h \ 18 18 qwt_date.h \ … … 41 41 qwt_scale_map.h \ 42 42 qwt_spline.h \ 43 qwt_spline_basis.h \ 44 qwt_spline_parametrization.h \ 45 qwt_spline_local.h \ 46 qwt_spline_cubic.h \ 47 qwt_spline_pleasing.h \ 48 qwt_spline_polynomial.h \ 43 49 qwt_symbol.h \ 44 50 qwt_system_clock.h \ … … 50 56 51 57 SOURCES += \ 58 qwt.cpp \ 52 59 qwt_abstract_scale_draw.cpp \ 60 qwt_bezier.cpp \ 53 61 qwt_clipper.cpp \ 54 62 qwt_color_map.cpp \ … … 77 85 qwt_scale_draw.cpp \ 78 86 qwt_scale_map.cpp \ 87 qwt_scale_engine.cpp \ 79 88 qwt_spline.cpp \ 80 qwt_scale_engine.cpp \ 89 qwt_spline_basis.cpp \ 90 qwt_spline_parametrization.cpp \ 91 qwt_spline_local.cpp \ 92 qwt_spline_cubic.cpp \ 93 qwt_spline_pleasing.cpp \ 94 qwt_spline_polynomial.cpp \ 81 95 qwt_symbol.cpp \ 82 96 qwt_system_clock.cpp \ … … 91 105 92 106 HEADERS += \ 107 qwt_axis.h \ 108 qwt_axis_id.h \ 93 109 qwt_curve_fitter.h \ 110 qwt_spline_curve_fitter.h \ 111 qwt_weeding_curve_fitter.h \ 94 112 qwt_event_pattern.h \ 95 113 qwt_abstract_legend.h \ … … 102 120 qwt_plot_dict.h \ 103 121 qwt_plot_directpainter.h \ 122 qwt_plot_graphicitem.h \ 104 123 qwt_plot_grid.h \ 105 124 qwt_plot_histogram.h \ … … 121 140 qwt_plot_seriesitem.h \ 122 141 qwt_plot_shapeitem.h \ 142 qwt_plot_vectorfield.h \ 143 qwt_plot_abstract_canvas.h \ 123 144 qwt_plot_canvas.h \ 124 145 qwt_plot_panner.h \ … … 130 151 qwt_raster_data.h \ 131 152 qwt_matrix_raster_data.h \ 153 qwt_vectorfield_symbol.h \ 132 154 qwt_sampling_thread.h \ 133 155 qwt_samples.h \ … … 139 161 SOURCES += \ 140 162 qwt_curve_fitter.cpp \ 163 qwt_spline_curve_fitter.cpp \ 164 qwt_weeding_curve_fitter.cpp \ 141 165 qwt_abstract_legend.cpp \ 142 166 qwt_legend.cpp \ … … 145 169 qwt_plot.cpp \ 146 170 qwt_plot_renderer.cpp \ 147 qwt_plot_xml.cpp \148 171 qwt_plot_axis.cpp \ 149 172 qwt_plot_curve.cpp \ 150 173 qwt_plot_dict.cpp \ 151 174 qwt_plot_directpainter.cpp \ 175 qwt_plot_graphicitem.cpp \ 152 176 qwt_plot_grid.cpp \ 153 177 qwt_plot_histogram.cpp \ … … 165 189 qwt_plot_seriesitem.cpp \ 166 190 qwt_plot_shapeitem.cpp \ 191 qwt_plot_vectorfield.cpp \ 167 192 qwt_plot_marker.cpp \ 168 193 qwt_plot_textlabel.cpp \ 169 194 qwt_plot_layout.cpp \ 195 qwt_plot_abstract_canvas.cpp \ 170 196 qwt_plot_canvas.cpp \ 171 197 qwt_plot_panner.cpp \ … … 178 204 qwt_raster_data.cpp \ 179 205 qwt_matrix_raster_data.cpp \ 206 qwt_vectorfield_symbol.cpp \ 180 207 qwt_sampling_thread.cpp \ 181 208 qwt_series_data.cpp \ … … 185 212 contains(QWT_CONFIG, QwtOpenGL) { 186 213 187 HEADERS += \ 188 qwt_plot_glcanvas.h 189 190 SOURCES += \ 191 qwt_plot_glcanvas.cpp 214 lessThan(QT_MAJOR_VERSION, 6) { 215 216 HEADERS += \ 217 qwt_plot_glcanvas.h 218 219 SOURCES += \ 220 qwt_plot_glcanvas.cpp 221 } 222 223 greaterThan(QT_MAJOR_VERSION, 4) { 224 225 lessThan( QT_MAJOR_VERSION, 6) { 226 227 greaterThan(QT_MINOR_VERSION, 3) { 228 229 HEADERS += qwt_plot_opengl_canvas.h 230 SOURCES += qwt_plot_opengl_canvas.cpp 231 } 232 } 233 else { 234 QT += openglwidgets 235 236 HEADERS += qwt_plot_opengl_canvas.h 237 SOURCES += qwt_plot_opengl_canvas.cpp 238 } 239 240 } 241 192 242 } 193 243 … … 199 249 SOURCES += \ 200 250 qwt_plot_svgitem.cpp 251 } 252 253 contains(QWT_CONFIG, QwtPolar) { 254 255 HEADERS += \ 256 qwt_polar.h \ 257 qwt_polar_canvas.h \ 258 qwt_polar_curve.h \ 259 qwt_polar_fitter.h \ 260 qwt_polar_grid.h \ 261 qwt_polar_itemdict.h \ 262 qwt_polar_item.h \ 263 qwt_polar_layout.h \ 264 qwt_polar_magnifier.h \ 265 qwt_polar_marker.h \ 266 qwt_polar_panner.h \ 267 qwt_polar_picker.h \ 268 qwt_polar_plot.h \ 269 qwt_polar_renderer.h \ 270 qwt_polar_spectrogram.h 271 272 SOURCES += \ 273 qwt_polar_canvas.cpp \ 274 qwt_polar_curve.cpp \ 275 qwt_polar_fitter.cpp \ 276 qwt_polar_grid.cpp \ 277 qwt_polar_item.cpp \ 278 qwt_polar_itemdict.cpp \ 279 qwt_polar_layout.cpp \ 280 qwt_polar_magnifier.cpp \ 281 qwt_polar_marker.cpp \ 282 qwt_polar_panner.cpp \ 283 qwt_polar_picker.cpp \ 284 qwt_polar_plot.cpp \ 285 qwt_polar_renderer.cpp \ 286 qwt_polar_spectrogram.cpp 201 287 } 202 288 } … … 229 315 230 316 contains(QWT_CONFIG, QwtOpenGL) { 317 318 greaterThan(QT_MAJOR_VERSION, 4) { 319 320 qtHaveModule(opengl) { 321 QT += opengl 322 } 323 else { 324 warning("QwtOpenGL is enabled in qwtconfig.pri, but Qt has not been built with opengl support") 325 } 326 } 327 else { 328 QT += opengl 329 } 231 330 232 331 QT += opengl
Note:
See TracChangeset
for help on using the changeset viewer.
