- Timestamp:
- May 10, 2017, 3:20:54 PM (8 years ago)
- Location:
- trunk/BNC
- Files:
-
- 73 added
- 3 deleted
- 155 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt.h
r4271 r8127 18 18 namespace Qwt 19 19 { 20 } ;20 } 21 21 22 22 #endif -
trunk/BNC/qwt/qwt.pro
r5182 r8127 7 7 CONFIG -= debug 8 8 CONFIG += release 9 10 ###DEFINES += QWT_NO_SVG 11 QT += svg 9 QWT_CONFIG = QwtPlot QwtWidgets QwtSvg 12 10 13 11 OBJECTS_DIR = .obj 14 12 MOC_DIR = .moc 15 13 16 HEADERS += \ 17 qwt.h \ 18 qwt_abstract_scale_draw.h \ 19 qwt_interval_symbol.h \ 20 qwt_clipper.h \ 21 qwt_color_map.h \ 22 qwt_compat.h \ 23 qwt_column_symbol.h \ 24 qwt_interval.h \ 25 qwt_dyngrid_layout.h \ 26 qwt_global.h \ 27 qwt_math.h \ 28 qwt_magnifier.h \ 29 qwt_null_paintdevice.h \ 30 qwt_painter.h \ 31 qwt_panner.h \ 32 qwt_picker.h \ 33 qwt_picker_machine.h \ 34 qwt_point_3d.h \ 35 qwt_point_polar.h \ 36 qwt_round_scale_draw.h \ 37 qwt_scale_div.h \ 38 qwt_scale_draw.h \ 39 qwt_scale_engine.h \ 40 qwt_scale_map.h \ 41 qwt_spline.h \ 42 qwt_symbol.h \ 43 qwt_system_clock.h \ 44 qwt_text_engine.h \ 45 qwt_text_label.h \ 46 qwt_text.h \ 47 qwt_curve_fitter.h \ 48 qwt_event_pattern.h \ 49 qwt_legend.h \ 50 qwt_legend_item.h \ 51 qwt_legend_itemmanager.h \ 52 qwt_plot.h \ 53 qwt_plot_renderer.h \ 54 qwt_plot_curve.h \ 55 qwt_plot_dict.h \ 56 qwt_plot_directpainter.h \ 57 qwt_plot_grid.h \ 58 qwt_plot_histogram.h \ 59 qwt_plot_item.h \ 60 qwt_plot_intervalcurve.h \ 61 qwt_plot_layout.h \ 62 qwt_plot_marker.h \ 63 qwt_plot_rasteritem.h \ 64 qwt_plot_spectrogram.h \ 65 qwt_plot_spectrocurve.h \ 66 qwt_plot_scaleitem.h \ 67 qwt_plot_seriesitem.h \ 68 qwt_plot_canvas.h \ 69 qwt_plot_panner.h \ 70 qwt_plot_picker.h \ 71 qwt_plot_zoomer.h \ 72 qwt_plot_magnifier.h \ 73 qwt_plot_rescaler.h \ 74 qwt_raster_data.h \ 75 qwt_matrix_raster_data.h \ 76 qwt_sampling_thread.h \ 77 qwt_series_data.h \ 78 qwt_scale_widget.h \ 79 qwt_plot_svgitem.h 80 81 SOURCES += \ 82 qwt_abstract_scale_draw.cpp \ 83 qwt_interval_symbol.cpp \ 84 qwt_clipper.cpp \ 85 qwt_color_map.cpp \ 86 qwt_column_symbol.cpp \ 87 qwt_interval.cpp \ 88 qwt_dyngrid_layout.cpp \ 89 qwt_math.cpp \ 90 qwt_magnifier.cpp \ 91 qwt_panner.cpp \ 92 qwt_null_paintdevice.cpp \ 93 qwt_painter.cpp \ 94 qwt_picker.cpp \ 95 qwt_round_scale_draw.cpp \ 96 qwt_scale_div.cpp \ 97 qwt_scale_draw.cpp \ 98 qwt_scale_map.cpp \ 99 qwt_spline.cpp \ 100 qwt_text_engine.cpp \ 101 qwt_text_label.cpp \ 102 qwt_text.cpp \ 103 qwt_event_pattern.cpp \ 104 qwt_picker_machine.cpp \ 105 qwt_point_3d.cpp \ 106 qwt_point_polar.cpp \ 107 qwt_scale_engine.cpp \ 108 qwt_symbol.cpp \ 109 qwt_system_clock.cpp \ 110 qwt_curve_fitter.cpp \ 111 qwt_legend.cpp \ 112 qwt_legend_item.cpp \ 113 qwt_plot.cpp \ 114 qwt_plot_renderer.cpp \ 115 qwt_plot_xml.cpp \ 116 qwt_plot_axis.cpp \ 117 qwt_plot_curve.cpp \ 118 qwt_plot_dict.cpp \ 119 qwt_plot_directpainter.cpp \ 120 qwt_plot_grid.cpp \ 121 qwt_plot_histogram.cpp \ 122 qwt_plot_item.cpp \ 123 qwt_plot_intervalcurve.cpp \ 124 qwt_plot_spectrogram.cpp \ 125 qwt_plot_spectrocurve.cpp \ 126 qwt_plot_scaleitem.cpp \ 127 qwt_plot_seriesitem.cpp \ 128 qwt_plot_marker.cpp \ 129 qwt_plot_layout.cpp \ 130 qwt_plot_canvas.cpp \ 131 qwt_plot_panner.cpp \ 132 qwt_plot_rasteritem.cpp \ 133 qwt_plot_picker.cpp \ 134 qwt_plot_zoomer.cpp \ 135 qwt_plot_magnifier.cpp \ 136 qwt_plot_rescaler.cpp \ 137 qwt_raster_data.cpp \ 138 qwt_matrix_raster_data.cpp \ 139 qwt_sampling_thread.cpp \ 140 qwt_series_data.cpp \ 141 qwt_scale_widget.cpp \ 142 qwt_plot_svgitem.cpp 14 include ( src.pri ) -
trunk/BNC/qwt/qwt_abstract_scale_draw.cpp
r4271 r8127 38 38 39 39 QwtScaleMap map; 40 QwtScaleDiv sc ldiv;40 QwtScaleDiv scaleDiv; 41 41 42 42 double spacing; … … 86 86 /*! 87 87 Check if a component is enabled 88 89 \param component Component type 90 \return true, when component is enabled 88 91 \sa enableComponent() 89 92 */ … … 95 98 /*! 96 99 Change the scale division 97 \param s dNew scale division98 */ 99 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &s d)100 { 101 d_data->sc ldiv = sd;102 d_data->map.setScaleInterval( s d.lowerBound(), sd.upperBound() );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() ); 103 106 d_data->labelCache.clear(); 104 107 } … … 109 112 */ 110 113 void QwtAbstractScaleDraw::setTransformation( 111 Qwt ScaleTransformation*transformation )114 QwtTransform *transformation ) 112 115 { 113 116 d_data->map.setTransformation( transformation ); … … 129 132 const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const 130 133 { 131 return d_data->sc ldiv;134 return d_data->scaleDiv; 132 135 } 133 136 … … 179 182 180 183 const QList<double> &majorTicks = 181 d_data->sc ldiv.ticks( QwtScaleDiv::MajorTick );184 d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick ); 182 185 183 186 for ( int i = 0; i < majorTicks.count(); i++ ) 184 187 { 185 188 const double v = majorTicks[i]; 186 if ( d_data->sc ldiv.contains( v ) )187 drawLabel( painter, majorTicks[i]);189 if ( d_data->scaleDiv.contains( v ) ) 190 drawLabel( painter, v ); 188 191 } 189 192 … … 204 207 tickType < QwtScaleDiv::NTickTypes; tickType++ ) 205 208 { 206 const QList<double> &ticks = d_data->scldiv.ticks( tickType ); 209 const double tickLen = d_data->tickLength[tickType]; 210 if ( tickLen <= 0.0 ) 211 continue; 212 213 const QList<double> &ticks = d_data->scaleDiv.ticks( tickType ); 207 214 for ( int i = 0; i < ticks.count(); i++ ) 208 215 { 209 216 const double v = ticks[i]; 210 if ( d_data->sc ldiv.contains( v ) )211 drawTick( painter, v, d_data->tickLength[tickType]);217 if ( d_data->scaleDiv.contains( v ) ) 218 drawTick( painter, v, tickLen ); 212 219 } 213 220 } … … 258 265 The default spacing is 4 pixels. 259 266 267 \return Spacing 260 268 \sa setSpacing() 261 269 */ … … 268 276 \brief Set a minimum for the extent 269 277 270 The extent is calculated from the co omponents of the278 The extent is calculated from the components of the 271 279 scale draw. In situations, where the labels are 272 280 changing and the layout depends on the extent (f.e scrolling … … 288 296 /*! 289 297 Get the minimum extent 298 \return Minimum extent 290 299 \sa extent(), setMinimumExtent() 291 300 */ … … 323 332 324 333 /*! 325 Return the length of the ticks 326 334 \return Length of the ticks 327 335 \sa setTickLength(), maxTickLength() 328 336 */ … … 357 365 358 366 The value is converted to a plain text using 359 QLocale ::system().toString(value).367 QLocale().toString(value). 360 368 This method is often overloaded by applications to have individual 361 369 labels. … … 401 409 402 410 /*! 403 Invalidate the cache used by QwtAbstractScaleDraw::tickLabel411 Invalidate the cache used by tickLabel() 404 412 405 413 The cache is invalidated, when a new QwtScaleDiv is set. If -
trunk/BNC/qwt/qwt_abstract_scale_draw.h
r4271 r8127 18 18 class QPainter; 19 19 class QFont; 20 class Qwt ScaleTransformation;20 class QwtTransform; 21 21 class QwtScaleMap; 22 22 … … 27 27 28 28 After a scale division has been specified as a QwtScaleDiv object 29 using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), 30 the scale can be drawn with the QwtAbstractScaleDraw::draw() member. 29 using setScaleDiv(), the scale can be drawn with the draw() member. 31 30 */ 32 31 class QWT_EXPORT QwtAbstractScaleDraw … … 59 58 const QwtScaleDiv& scaleDiv() const; 60 59 61 void setTransformation( Qwt ScaleTransformation* );60 void setTransformation( QwtTransform * ); 62 61 const QwtScaleMap &scaleMap() const; 63 62 QwtScaleMap &scaleMap(); … … 83 82 Calculate the extent 84 83 85 The extent is the dist cance from the baseline to the outermost84 The extent is the distance from the baseline to the outermost 86 85 pixel of the scale draw in opposite to its orientation. 87 86 It is at least minimumExtent() pixels. 88 87 88 \param font Font used for drawing the tick labels 89 \return Number of pixels 90 89 91 \sa setMinimumExtent(), minimumExtent() 90 92 */ 91 virtual double extent( const QFont & ) const = 0;93 virtual double extent( const QFont &font ) const = 0; 92 94 93 95 void setMinimumExtent( double ); … … 100 102 \param painter Painter 101 103 \param value Value of the tick 102 \param len Leng htof the tick104 \param len Length of the tick 103 105 104 106 \sa drawBackbone(), drawLabel() -
trunk/BNC/qwt/qwt_clipper.cpp
r4271 r8127 11 11 #include "qwt_point_polar.h" 12 12 #include <qrect.h> 13 #include <string.h> 14 #include <stdlib.h> 13 15 14 16 #if QT_VERSION < 0x040601 … … 44 46 { 45 47 double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() ); 46 return Point( d_x1, ( Value )( p2.y() + ( d_x1 - p2.x() ) * dy ) );48 return Point( d_x1, static_cast< Value >( p2.y() + ( d_x1 - p2.x() ) * dy ) ); 47 49 } 48 50 private: … … 67 69 { 68 70 double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() ); 69 return Point( d_x2, ( Value )( p2.y() + ( d_x2 - p2.x() ) * dy ) );71 return Point( d_x2, static_cast<Value>( p2.y() + ( d_x2 - p2.x() ) * dy ) ); 70 72 } 71 73 … … 91 93 { 92 94 double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() ); 93 return Point( ( Value )( p2.x() + ( d_y1 - p2.y() ) * dx ), d_y1 );95 return Point( static_cast<Value>( p2.x() + ( d_y1 - p2.y() ) * dx ), d_y1 ); 94 96 } 95 97 … … 115 117 { 116 118 double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() ); 117 return Point( ( Value )( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 );119 return Point( static_cast<Value>( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 ); 118 120 } 119 121 … … 138 140 { 139 141 if ( m_buffer ) 140 qFree( m_buffer );142 ::free( m_buffer ); 141 143 } 142 144 … … 146 148 147 149 m_size = numPoints; 148 qMemCopy( m_buffer, points, m_size * sizeof( Point ) );150 ::memcpy( m_buffer, points, m_size * sizeof( Point ) ); 149 151 } 150 152 … … 191 193 m_capacity *= 2; 192 194 193 m_buffer = ( Point * ) qRealloc(194 m_buffer, m_capacity * sizeof( Point) );195 m_buffer = static_cast<Point *>( 196 ::realloc( m_buffer, m_capacity * sizeof( Point ) ) ); 195 197 } 196 198 … … 230 232 Polygon p; 231 233 p.resize( points1.size() ); 232 qMemCopy( p.data(), points1.data(), points1.size() * sizeof( Point ) );234 ::memcpy( p.data(), points1.data(), points1.size() * sizeof( Point ) ); 233 235 234 236 return p; … … 335 337 QList<QPointF> points; 336 338 for ( int edge = 0; edge < NEdges; edge++ ) 337 points += cuttingPoints( ( Edge )edge, pos, radius );339 points += cuttingPoints( static_cast<Edge>(edge), pos, radius ); 338 340 339 341 QVector<QwtInterval> intv; … … 444 446 */ 445 447 QPolygon QwtClipper::clipPolygon( 448 const QRectF &clipRect, const QPolygon &polygon, bool closePolygon ) 449 { 450 const int minX = qCeil( clipRect.left() ); 451 const int maxX = qFloor( clipRect.right() ); 452 const int minY = qCeil( clipRect.top() ); 453 const int maxY = qFloor( clipRect.bottom() ); 454 455 const QRect r( minX, minY, maxX - minX, maxY - minY ); 456 457 QwtPolygonClipper<QPolygon, QRect, QPoint, int> clipper( r ); 458 return clipper.clipPolygon( polygon, closePolygon ); 459 } 460 /*! 461 Sutherland-Hodgman polygon clipping 462 463 \param clipRect Clip rectangle 464 \param polygon Polygon 465 \param closePolygon True, when the polygon is closed 466 467 \return Clipped polygon 468 */ 469 QPolygon QwtClipper::clipPolygon( 446 470 const QRect &clipRect, const QPolygon &polygon, bool closePolygon ) 447 471 { … … 469 493 Circle clipping 470 494 471 clipCircle() d evides a circle into intervals of angles representing arcs495 clipCircle() divides a circle into intervals of angles representing arcs 472 496 of the circle. When the circle is completely inside the clip rectangle 473 497 an interval [0.0, 2 * M_PI] is returned. -
trunk/BNC/qwt/qwt_clipper.h
r4271 r8127 20 20 21 21 /*! 22 \brief Some clipping algo s22 \brief Some clipping algorithms 23 23 */ 24 24 … … 28 28 static QPolygon clipPolygon( const QRect &, 29 29 const QPolygon &, bool closePolygon = false ); 30 static QPolygon clipPolygon( const QRectF &, 31 const QPolygon &, bool closePolygon = false ); 32 30 33 static QPolygonF clipPolygonF( const QRectF &, 31 34 const QPolygonF &, bool closePolygon = false ); -
trunk/BNC/qwt/qwt_color_map.cpp
r4271 r8127 16 16 { 17 17 public: 18 ColorStops() 19 { 20 _stops.reserve( 256 ); 18 ColorStops(): 19 d_doAlpha( false ) 20 { 21 d_stops.reserve( 256 ); 21 22 } 22 23 … … 39 40 ColorStop( double p, const QColor &c ): 40 41 pos( p ), 41 rgb( c.rgb () )42 rgb( c.rgba() ) 42 43 { 43 44 r = qRed( rgb ); 44 45 g = qGreen( rgb ); 45 46 b = qBlue( rgb ); 47 a = qAlpha( rgb ); 48 49 /* 50 when mapping a value to rgb we will have to calcualate: 51 - const int v = int( ( s1.v0 + ratio * s1.vStep ) + 0.5 ); 52 53 Thus adding 0.5 ( for rounding ) can be done in advance 54 */ 55 r0 = r + 0.5; 56 g0 = g + 0.5; 57 b0 = b + 0.5; 58 a0 = a + 0.5; 59 60 rStep = gStep = bStep = aStep = 0.0; 61 posStep = 0.0; 62 } 63 64 void updateSteps( const ColorStop &nextStop ) 65 { 66 rStep = nextStop.r - r; 67 gStep = nextStop.g - g; 68 bStep = nextStop.b - b; 69 aStep = nextStop.a - a; 70 posStep = nextStop.pos - pos; 46 71 } 47 72 48 73 double pos; 49 74 QRgb rgb; 50 int r, g, b; 75 int r, g, b, a; 76 77 // precalculated values 78 double rStep, gStep, bStep, aStep; 79 double r0, g0, b0, a0; 80 double posStep; 51 81 }; 52 82 53 83 inline int findUpper( double pos ) const; 54 QVector<ColorStop> _stops; 84 QVector<ColorStop> d_stops; 85 bool d_doAlpha; 55 86 }; 56 87 … … 64 95 65 96 int index; 66 if ( _stops.size() == 0 )97 if ( d_stops.size() == 0 ) 67 98 { 68 99 index = 0; 69 _stops.resize( 1 );100 d_stops.resize( 1 ); 70 101 } 71 102 else 72 103 { 73 104 index = findUpper( pos ); 74 if ( index == _stops.size() || 75 qAbs( _stops[index].pos - pos ) >= 0.001 ) 76 { 77 _stops.resize( _stops.size() + 1 ); 78 for ( int i = _stops.size() - 1; i > index; i-- ) 79 _stops[i] = _stops[i-1]; 80 } 81 } 82 83 _stops[index] = ColorStop( pos, color ); 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 ); 115 if ( color.alpha() != 255 ) 116 d_doAlpha = true; 117 118 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] ); 84 123 } 85 124 86 125 inline QVector<double> QwtLinearColorMap::ColorStops::stops() const 87 126 { 88 QVector<double> positions( _stops.size() );89 for ( int i = 0; i < _stops.size(); i++ )90 positions[i] = _stops[i].pos;127 QVector<double> positions( d_stops.size() ); 128 for ( int i = 0; i < d_stops.size(); i++ ) 129 positions[i] = d_stops[i].pos; 91 130 return positions; 92 131 } … … 95 134 { 96 135 int index = 0; 97 int n = _stops.size();98 99 const ColorStop *stops = _stops.data();136 int n = d_stops.size(); 137 138 const ColorStop *stops = d_stops.data(); 100 139 101 140 while ( n > 0 ) … … 120 159 { 121 160 if ( pos <= 0.0 ) 122 return _stops[0].rgb;161 return d_stops[0].rgb; 123 162 if ( pos >= 1.0 ) 124 return _stops[_stops.size() - 1 ].rgb;163 return d_stops[ d_stops.size() - 1 ].rgb; 125 164 126 165 const int index = findUpper( pos ); 127 166 if ( mode == FixedColors ) 128 167 { 129 return _stops[index-1].rgb;168 return d_stops[index-1].rgb; 130 169 } 131 170 else 132 171 { 133 const ColorStop &s1 = _stops[index-1]; 134 const ColorStop &s2 = _stops[index]; 135 136 const double ratio = ( pos - s1.pos ) / ( s2.pos - s1.pos ); 137 138 const int r = s1.r + qRound( ratio * ( s2.r - s1.r ) ); 139 const int g = s1.g + qRound( ratio * ( s2.g - s1.g ) ); 140 const int b = s1.b + qRound( ratio * ( s2.b - s1.b ) ); 141 142 return qRgb( r, g, b ); 172 const ColorStop &s1 = d_stops[index-1]; 173 174 const double ratio = ( pos - s1.pos ) / ( s1.posStep ); 175 176 const int r = int( s1.r0 + ratio * s1.rStep ); 177 const int g = int( s1.g0 + ratio * s1.gStep ); 178 const int b = int( s1.b0 + ratio * s1.bStep ); 179 180 if ( d_doAlpha ) 181 { 182 if ( s1.aStep ) 183 { 184 const int a = int( s1.a0 + ratio * s1.aStep ); 185 return qRgba( r, g, b, a ); 186 } 187 else 188 { 189 return qRgba( r, g, b, s1.a ); 190 } 191 } 192 else 193 { 194 return qRgb( r, g, b ); 195 } 143 196 } 144 197 } … … 205 258 \param color1 Color used for the minimum value of the value interval 206 259 \param color2 Color used for the maximum value of the value interval 207 \param format Preferred format of the coor map260 \param format Preferred format for the color map 208 261 */ 209 262 QwtLinearColorMap::QwtLinearColorMap( const QColor &color1, … … 280 333 281 334 /*! 282 Return all positions of color stops in increasing order335 \return Positions of color stops in increasing order 283 336 */ 284 337 QVector<double> QwtLinearColorMap::colorStops() const … … 306 359 307 360 /*! 308 Map a value of a given interval into a rgbvalue361 Map a value of a given interval into a RGB value 309 362 310 363 \param interval Range for all values 311 \param value Value to map into a rgb value 364 \param value Value to map into a RGB value 365 366 \return RGB value for value 312 367 */ 313 368 QRgb QwtLinearColorMap::rgb( … … 315 370 { 316 371 if ( qIsNaN(value) ) 317 return qRgba(0, 0, 0, 0);372 return 0u; 318 373 319 374 const double width = interval.width(); 320 321 double ratio = 0.0; 322 if ( width > 0.0 ) 323 ratio = ( value - interval.minValue() ) / width; 324 375 if ( width <= 0.0 ) 376 return 0u; 377 378 const double ratio = ( value - interval.minValue() ) / width; 325 379 return d_data->colorStops.rgb( d_data->mode, ratio ); 326 380 } 327 381 328 382 /*! 329 Map a value of a given interval into a color index, between 0 and 255383 \brief Map a value of a given interval into a color index 330 384 331 385 \param interval Range for all values 332 386 \param value Value to map into a color index 387 388 \return Index, between 0 and 255 333 389 */ 334 390 unsigned char QwtLinearColorMap::colorIndex( … … 341 397 342 398 if ( value >= interval.maxValue() ) 343 return ( unsigned char )255;399 return 255; 344 400 345 401 const double ratio = ( value - interval.minValue() ) / width; … … 347 403 unsigned char index; 348 404 if ( d_data->mode == FixedColors ) 349 index = ( unsigned char )( ratio * 255 ); // always floor405 index = static_cast<unsigned char>( ratio * 255 ); // always floor 350 406 else 351 index = ( unsigned char )qRound( ratio * 255 );407 index = static_cast<unsigned char>( ratio * 255 + 0.5 ); 352 408 353 409 return index; … … 359 415 QColor color; 360 416 QRgb rgb; 417 QRgb rgbMax; 361 418 }; 362 419 … … 370 427 { 371 428 d_data = new PrivateData; 429 setColor( color ); 430 } 431 432 //! Destructor 433 QwtAlphaColorMap::~QwtAlphaColorMap() 434 { 435 delete d_data; 436 } 437 438 /*! 439 Set the color 440 441 \param color Color 442 \sa color() 443 */ 444 void QwtAlphaColorMap::setColor( const QColor &color ) 445 { 372 446 d_data->color = color; 373 447 d_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 ); 374 } 375 376 //! Destructor 377 QwtAlphaColorMap::~QwtAlphaColorMap() 378 { 379 delete d_data; 380 } 381 382 /*! 383 Set the color 384 385 \param color Color 386 \sa color() 387 */ 388 void QwtAlphaColorMap::setColor( const QColor &color ) 389 { 390 d_data->color = color; 391 d_data->rgb = color.rgb(); 448 d_data->rgbMax = d_data->rgb | ( 255 << 24 ); 392 449 } 393 450 … … 407 464 408 465 \param interval Range for all values 409 \param value Value to map into a rgbvalue410 \return rgbvalue, with an alpha value466 \param value Value to map into a RGB value 467 \return RGB value, with an alpha value 411 468 */ 412 469 QRgb QwtAlphaColorMap::rgb( const QwtInterval &interval, double value ) const 413 470 { 471 if ( qIsNaN(value) ) 472 return 0u; 473 414 474 const double width = interval.width(); 415 if ( !qIsNaN(value) && width >= 0.0 ) 416 { 417 const double ratio = ( value - interval.minValue() ) / width; 418 int alpha = qRound( 255 * ratio ); 419 if ( alpha < 0 ) 420 alpha = 0; 421 if ( alpha > 255 ) 422 alpha = 255; 423 424 return d_data->rgb | ( alpha << 24 ); 425 } 426 return d_data->rgb; 475 if ( width <= 0.0 ) 476 return 0u; 477 478 if ( value <= interval.minValue() ) 479 return d_data->rgb; 480 481 if ( value >= interval.maxValue() ) 482 return d_data->rgbMax; 483 484 const double ratio = ( value - interval.minValue() ) / width; 485 return d_data->rgb | ( qRound( 255 * ratio ) << 24 ); 427 486 } 428 487 -
trunk/BNC/qwt/qwt_color_map.h
r4271 r8127 41 41 enum Format 42 42 { 43 //! The map is intended to map into QRgbvalues.43 //! The map is intended to map into RGB values. 44 44 RGB, 45 45 … … 57 57 58 58 /*! 59 Map a value of a given interval into a rgb value. 59 Map a value of a given interval into a RGB value. 60 60 61 \param interval Range for the values 61 62 \param value Value 62 \return rgbvalue, corresponding to value63 \return RGB value, corresponding to value 63 64 */ 64 65 virtual QRgb rgb( const QwtInterval &interval, … … 67 68 /*! 68 69 Map a value of a given interval into a color index 70 69 71 \param interval Range for the values 70 72 \param value Value … … 136 138 137 139 /*! 138 \brief QwtAlphaColorMap vari ies the alpha value of a color140 \brief QwtAlphaColorMap varies the alpha value of a color 139 141 */ 140 142 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap … … 178 180 if ( d_format == RGB ) 179 181 { 180 return QColor ( rgb( interval, value ) );182 return QColor::fromRgba( rgb( interval, value ) ); 181 183 } 182 184 else -
trunk/BNC/qwt/qwt_column_symbol.cpp
r4271 r8127 10 10 #include "qwt_column_symbol.h" 11 11 #include "qwt_math.h" 12 #include "qwt_text.h"13 12 #include "qwt_painter.h" 14 13 #include <qpainter.h> 15 14 #include <qpalette.h> 16 15 17 static void drawBox( QPainter *p, const QRectF &rect,16 static void qwtDrawBox( QPainter *p, const QRectF &rect, 18 17 const QPalette &pal, double lw ) 19 18 { … … 58 57 } 59 58 60 static void drawPanel( QPainter *painter, const QRectF &rect,59 static void qwtDrawPanel( QPainter *painter, const QRectF &rect, 61 60 const QPalette &pal, double lw ) 62 61 { … … 125 124 126 125 QPalette palette; 127 QwtText label;128 129 126 int lineWidth; 130 127 }; … … 281 278 case QwtColumnSymbol::Raised: 282 279 { 283 ::drawPanel( painter, r, d_data->palette, d_data->lineWidth );280 qwtDrawPanel( painter, r, d_data->palette, d_data->lineWidth ); 284 281 break; 285 282 } 286 283 case QwtColumnSymbol::Plain: 287 284 { 288 ::drawBox( painter, r, d_data->palette, d_data->lineWidth );285 qwtDrawBox( painter, r, d_data->palette, d_data->lineWidth ); 289 286 break; 290 287 } -
trunk/BNC/qwt/qwt_column_symbol.h
r4271 r8127 23 23 24 24 /*! 25 \brief Directed rectangle representing bounding rectangle und orientation25 \brief Directed rectangle representing bounding rectangle and orientation 26 26 of a column. 27 27 */ -
trunk/BNC/qwt/qwt_compat.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_interval.h" 15 #include "qwt_point_3d.h" 14 16 #include <qlist.h> 15 17 #include <qvector.h> -
trunk/BNC/qwt/qwt_curve_fitter.cpp
r4271 r8127 247 247 public: 248 248 PrivateData(): 249 tolerance( 1.0 ) 249 tolerance( 1.0 ), 250 chunkSize( 0 ) 250 251 { 251 252 } 252 253 253 254 double tolerance; 255 uint chunkSize; 254 256 }; 255 257 … … 288 290 Assign the tolerance 289 291 290 The tolerance is the maximum distance, that is acc aptable292 The tolerance is the maximum distance, that is acceptable 291 293 between the original curve and the smoothed curve. 292 294 … … 313 315 314 316 /*! 317 Limit the number of points passed to a run of the algorithm 318 319 The runtime of the Douglas Peucker algorithm increases non linear 320 with the number of points. For a chunk size > 0 the polygon 321 is split into pieces passed to the algorithm one by one. 322 323 \param numPoints Maximum for the number of points passed to the algorithm 324 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 337 \return Maximum for the number of points passed to a run 338 of the algorithm - or 0, when unlimited 339 \sa setChunkSize() 340 */ 341 uint QwtWeedingCurveFitter::chunkSize() const 342 { 343 return d_data->chunkSize; 344 } 345 346 /*! 315 347 \param points Series of data points 316 348 \return Curve points … … 318 350 QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const 319 351 { 352 QPolygonF fittedPoints; 353 354 if ( d_data->chunkSize == 0 ) 355 { 356 fittedPoints = simplify( points ); 357 } 358 else 359 { 360 for ( int i = 0; i < points.size(); i += d_data->chunkSize ) 361 { 362 const QPolygonF p = points.mid( i, d_data->chunkSize ); 363 fittedPoints += simplify( p ); 364 } 365 } 366 367 return fittedPoints; 368 } 369 370 QPolygonF QwtWeedingCurveFitter::simplify( const QPolygonF &points ) const 371 { 372 const double toleranceSqr = d_data->tolerance * d_data->tolerance; 373 320 374 QStack<Line> stack; 321 375 stack.reserve( 500 ); … … 325 379 326 380 QVector<bool> usePoint( nPoints, false ); 327 328 double distToSegment;329 381 330 382 stack.push( Line( 0, nPoints - 1 ) ); … … 343 395 const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0; 344 396 345 double maxDist = 0.0;397 double maxDistSqr = 0.0; 346 398 int nVertexIndexMaxDistance = r.from + 1; 347 399 for ( int i = r.from + 1; i < r.to; i++ ) … … 350 402 const double fromVecX = p[i].x() - p[r.from].x(); 351 403 const double fromVecY = p[i].y() - p[r.from].y(); 352 const double fromVecLength = 353 qSqrt( fromVecX * fromVecX + fromVecY * fromVecY ); 354 404 405 double distToSegmentSqr; 355 406 if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) 356 407 { 357 distToSegment = fromVecLength; 358 } 359 if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) 360 { 361 distToSegment = fromVecLength; 408 distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY; 362 409 } 363 410 else … … 365 412 const double toVecX = p[i].x() - p[r.to].x(); 366 413 const double toVecY = p[i].y() - p[r.to].y(); 367 const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY ); 414 const double toVecLength = toVecX * toVecX + toVecY * toVecY; 415 368 416 const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY ); 369 417 if ( s < 0.0 ) 370 distToSegment = toVecLength; 418 { 419 distToSegmentSqr = toVecLength; 420 } 371 421 else 372 422 { 373 distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ));423 distToSegmentSqr = qFabs( toVecLength - s * s ); 374 424 } 375 425 } 376 426 377 if ( maxDist < distToSegment)427 if ( maxDistSqr < distToSegmentSqr ) 378 428 { 379 maxDist = distToSegment;429 maxDistSqr = distToSegmentSqr; 380 430 nVertexIndexMaxDistance = i; 381 431 } 382 432 } 383 if ( maxDist <= d_data->tolerance)433 if ( maxDistSqr <= toleranceSqr ) 384 434 { 385 435 usePoint[r.from] = true; … … 393 443 } 394 444 395 int cnt = 0; 396 397 QPolygonF stripped( nPoints ); 445 QPolygonF stripped; 398 446 for ( int i = 0; i < nPoints; i++ ) 399 447 { 400 448 if ( usePoint[i] ) 401 stripped [cnt++]= p[i];402 } 403 stripped.resize( cnt ); 449 stripped += p[i]; 450 } 451 404 452 return stripped; 405 453 } -
trunk/BNC/qwt/qwt_curve_fitter.h
r4271 r8127 100 100 smoothed curve. 101 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 102 108 The smoothed curve consists of a subset of the points that defined the 103 109 original curve. … … 117 123 double tolerance() const; 118 124 125 void setChunkSize( uint ); 126 uint chunkSize() const; 127 119 128 virtual QPolygonF fitCurve( const QPolygonF & ) const; 120 129 121 130 private: 131 virtual QPolygonF simplify( const QPolygonF & ) const; 132 122 133 class Line; 123 134 -
trunk/BNC/qwt/qwt_dyngrid_layout.cpp
r4271 r8127 10 10 #include "qwt_dyngrid_layout.h" 11 11 #include "qwt_math.h" 12 #include <q widget.h>12 #include <qvector.h> 13 13 #include <qlist.h> 14 14 … … 25 25 mutable QList<QLayoutItem*> itemList; 26 26 27 uint maxCol s;27 uint maxColumns; 28 28 uint numRows; 29 uint numCol s;29 uint numColumns; 30 30 31 31 Qt::Orientations expanding; … … 82 82 { 83 83 d_data = new QwtDynGridLayout::PrivateData; 84 d_data->maxCol s = d_data->numRows = d_data->numCols = 0;84 d_data->maxColumns = d_data->numRows = d_data->numColumns = 0; 85 85 d_data->expanding = 0; 86 86 } … … 105 105 /*! 106 106 Limit the number of columns. 107 \param maxCols upper limit, 0 means unlimited 108 \sa maxCols() 109 */ 110 void QwtDynGridLayout::setMaxCols( uint maxCols ) 111 { 112 d_data->maxCols = maxCols; 113 } 114 115 /*! 116 Return the upper limit for the number of columns. 107 \param maxColumns upper limit, 0 means unlimited 108 \sa maxColumns() 109 */ 110 void QwtDynGridLayout::setMaxColumns( uint maxColumns ) 111 { 112 d_data->maxColumns = maxColumns; 113 } 114 115 /*! 116 \brief Return the upper limit for the number of columns. 117 117 118 0 means unlimited, what is the default. 118 \sa setMaxCols() 119 */ 120 121 uint QwtDynGridLayout::maxCols() const 122 { 123 return d_data->maxCols; 124 } 125 126 //! Adds item to the next free position. 127 119 120 \return Upper limit for the number of columns 121 \sa setMaxColumns() 122 */ 123 uint QwtDynGridLayout::maxColumns() const 124 { 125 return d_data->maxColumns; 126 } 127 128 /*! 129 \brief Add an item to the next free position. 130 \param item Layout item 131 */ 128 132 void QwtDynGridLayout::addItem( QLayoutItem *item ) 129 133 { … … 135 139 \return true if this layout is empty. 136 140 */ 137 138 141 bool QwtDynGridLayout::isEmpty() const 139 142 { … … 144 147 \return number of layout items 145 148 */ 146 147 149 uint QwtDynGridLayout::itemCount() const 148 150 { … … 151 153 152 154 /*! 153 Find the item at a sp cific index155 Find the item at a specific index 154 156 155 157 \param index Index 158 \return Item at a specific index 156 159 \sa takeAt() 157 160 */ … … 165 168 166 169 /*! 167 Find the item at a sp cific index and remove it from the layout170 Find the item at a specific index and remove it from the layout 168 171 169 172 \param index Index 173 \return Layout item, removed from the layout 170 174 \sa itemAt() 171 175 */ … … 200 204 201 205 /*! 202 Returns whether this layout can make use of more space than sizeHint(). 206 \brief Returns whether this layout can make use of more space than sizeHint(). 207 203 208 A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only 204 209 one dimension, while Qt::Vertical | Qt::Horizontal means that it wants 205 210 to grow in both dimensions. 211 212 \return Orientations, where the layout expands 206 213 \sa setExpandingDirections() 207 214 */ … … 212 219 213 220 /*! 214 Reorganizes columns and rows and resizes managed widgets within215 the rectangle rect.221 Reorganizes columns and rows and resizes managed items within 222 a rectangle. 216 223 217 224 \param rect Layout geometry … … 224 231 return; 225 232 226 d_data->numCol s = columnsForWidth( rect.width() );227 d_data->numRows = itemCount() / d_data->numCol s;228 if ( itemCount() % d_data->numCol s )233 d_data->numColumns = columnsForWidth( rect.width() ); 234 d_data->numRows = itemCount() / d_data->numColumns; 235 if ( itemCount() % d_data->numColumns ) 229 236 d_data->numRows++; 230 237 231 QList<QRect> itemGeometries = layoutItems( rect, d_data->numCol s );238 QList<QRect> itemGeometries = layoutItems( rect, d_data->numColumns ); 232 239 233 240 int index = 0; … … 235 242 it != d_data->itemList.end(); ++it ) 236 243 { 237 QWidget *w = ( *it )->widget(); 238 if ( w ) 239 { 240 w->setGeometry( itemGeometries[index] ); 241 index++; 242 } 243 } 244 } 245 246 /*! 247 Calculate the number of columns for a given width. It tries to 248 use as many columns as possible (limited by maxCols()) 244 ( *it )->setGeometry( itemGeometries[index] ); 245 index++; 246 } 247 } 248 249 /*! 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() ) 249 254 250 255 \param width Available width for all columns 251 \sa maxCols(), setMaxCols() 252 */ 253 256 \return Number of columns for a given width 257 258 \sa maxColumns(), setMaxColumns() 259 */ 254 260 uint QwtDynGridLayout::columnsForWidth( int width ) const 255 261 { … … 257 263 return 0; 258 264 259 const int maxCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); 260 if ( maxRowWidth( maxCols ) <= width ) 261 return maxCols; 262 263 for ( int numCols = 2; numCols <= maxCols; numCols++ ) 264 { 265 const int rowWidth = maxRowWidth( numCols ); 265 uint maxColumns = itemCount(); 266 if ( d_data->maxColumns > 0 ) 267 maxColumns = qMin( d_data->maxColumns, maxColumns ); 268 269 if ( maxRowWidth( maxColumns ) <= width ) 270 return maxColumns; 271 272 for ( uint numColumns = 2; numColumns <= maxColumns; numColumns++ ) 273 { 274 const int rowWidth = maxRowWidth( numColumns ); 266 275 if ( rowWidth > width ) 267 return numCol s - 1;276 return numColumns - 1; 268 277 } 269 278 … … 275 284 columns. 276 285 277 \param numCol s Given number of columns286 \param numColumns Given number of columns 278 287 \param itemWidth Array of the width hints for all items 279 288 */ 280 int QwtDynGridLayout::maxRowWidth( int numCol s ) const289 int QwtDynGridLayout::maxRowWidth( int numColumns ) const 281 290 { 282 291 int col; 283 292 284 QVector<int> colWidth( numCol s );285 for ( col = 0; col < numCol s; col++ )293 QVector<int> colWidth( numColumns ); 294 for ( col = 0; col < numColumns; col++ ) 286 295 colWidth[col] = 0; 287 296 … … 292 301 index < d_data->itemSizeHints.count(); index++ ) 293 302 { 294 col = index % numCol s;303 col = index % numColumns; 295 304 colWidth[col] = qMax( colWidth[col], 296 305 d_data->itemSizeHints[int( index )].width() ); 297 306 } 298 307 299 int rowWidth = 2 * margin() + ( numCol s - 1 ) * spacing();300 for ( col = 0; col < numCol s; col++ )308 int rowWidth = 2 * margin() + ( numColumns - 1 ) * spacing(); 309 for ( col = 0; col < numColumns; col++ ) 301 310 rowWidth += colWidth[col]; 302 311 … … 328 337 /*! 329 338 Calculate the geometries of the layout items for a layout 330 with numCol s columns and a given rect.339 with numColumns columns and a given rectangle. 331 340 332 341 \param rect Rect where to place the items 333 \param numCol s Number of columns342 \param numColumns Number of columns 334 343 \return item geometries 335 344 */ 336 345 337 346 QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect, 338 uint numCol s ) const347 uint numColumns ) const 339 348 { 340 349 QList<QRect> itemGeometries; 341 if ( numCol s == 0 || isEmpty() )350 if ( numColumns == 0 || isEmpty() ) 342 351 return itemGeometries; 343 352 344 uint numRows = itemCount() / numCol s;345 if ( num Rows % itemCount() )353 uint numRows = itemCount() / numColumns; 354 if ( numColumns % itemCount() ) 346 355 numRows++; 347 356 357 if ( numRows == 0 ) 358 return itemGeometries; 359 348 360 QVector<int> rowHeight( numRows ); 349 QVector<int> colWidth( numCol s );350 351 layoutGrid( numCol s, rowHeight, colWidth );361 QVector<int> colWidth( numColumns ); 362 363 layoutGrid( numColumns, rowHeight, colWidth ); 352 364 353 365 bool expandH, expandV; … … 356 368 357 369 if ( expandH || expandV ) 358 stretchGrid( rect, numCol s, rowHeight, colWidth );359 360 const int maxCol s = d_data->maxCols;361 d_data->maxCol s = numCols;370 stretchGrid( rect, numColumns, rowHeight, colWidth ); 371 372 const int maxColumns = d_data->maxColumns; 373 d_data->maxColumns = numColumns; 362 374 const QRect alignedRect = alignmentRect( rect ); 363 d_data->maxCol s = maxCols;375 d_data->maxColumns = maxColumns; 364 376 365 377 const int xOffset = expandH ? 0 : alignedRect.x(); 366 378 const int yOffset = expandV ? 0 : alignedRect.y(); 367 379 368 QVector<int> colX( numCol s );380 QVector<int> colX( numColumns ); 369 381 QVector<int> rowY( numRows ); 370 382 … … 372 384 373 385 rowY[0] = yOffset + margin(); 374 for ( int r = 1; r < ( int )numRows; r++ )386 for ( uint r = 1; r < numRows; r++ ) 375 387 rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace; 376 388 377 389 colX[0] = xOffset + margin(); 378 for ( int c = 1; c < ( int )numCols; c++ )390 for ( uint c = 1; c < numColumns; c++ ) 379 391 colX[c] = colX[c-1] + colWidth[c-1] + xySpace; 380 392 … … 382 394 for ( int i = 0; i < itemCount; i++ ) 383 395 { 384 const int row = i / numCol s;385 const int col = i % numCol s;396 const int row = i / numColumns; 397 const int col = i % numColumns; 386 398 387 399 QRect itemGeometry( colX[col], rowY[row], … … 396 408 /*! 397 409 Calculate the dimensions for the columns and rows for a grid 398 of numCol s columns.399 400 \param numCol s Number of columns.410 of numColumns columns. 411 412 \param numColumns Number of columns. 401 413 \param rowHeight Array where to fill in the calculated row heights. 402 414 \param colWidth Array where to fill in the calculated column widths. 403 415 */ 404 416 405 void QwtDynGridLayout::layoutGrid( uint numCol s,417 void QwtDynGridLayout::layoutGrid( uint numColumns, 406 418 QVector<int>& rowHeight, QVector<int>& colWidth ) const 407 419 { 408 if ( numCol s <= 0 )420 if ( numColumns <= 0 ) 409 421 return; 410 422 … … 412 424 d_data->updateLayoutCache(); 413 425 414 for ( uint index = 0; 415 index < ( uint )d_data->itemSizeHints.count(); index++ ) 416 { 417 const int row = index / numCols; 418 const int col = index % numCols; 426 for ( int index = 0; index < d_data->itemSizeHints.count(); index++ ) 427 { 428 const int row = index / numColumns; 429 const int col = index % numColumns; 419 430 420 431 const QSize &size = d_data->itemSizeHints[int( index )]; … … 428 439 429 440 /*! 430 \return true: QwtDynGridLayout implements heightForWidth .441 \return true: QwtDynGridLayout implements heightForWidth(). 431 442 \sa heightForWidth() 432 443 */ … … 437 448 438 449 /*! 439 \return The preferred height for this layout, given the width w.450 \return The preferred height for this layout, given a width. 440 451 \sa hasHeightForWidth() 441 452 */ … … 445 456 return 0; 446 457 447 const uint numCol s = columnsForWidth( width );448 uint numRows = itemCount() / numCol s;449 if ( itemCount() % numCol s )458 const uint numColumns = columnsForWidth( width ); 459 uint numRows = itemCount() / numColumns; 460 if ( itemCount() % numColumns ) 450 461 numRows++; 451 462 452 463 QVector<int> rowHeight( numRows ); 453 QVector<int> colWidth( numCol s );454 455 layoutGrid( numCol s, rowHeight, colWidth );464 QVector<int> colWidth( numColumns ); 465 466 layoutGrid( numColumns, rowHeight, colWidth ); 456 467 457 468 int h = 2 * margin() + ( numRows - 1 ) * spacing(); 458 for ( int row = 0; row < ( int )numRows; row++ )469 for ( uint row = 0; row < numRows; row++ ) 459 470 h += rowHeight[row]; 460 471 … … 467 478 rect. Rows and columns are stretched with the same factor. 468 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 469 485 \sa setExpanding(), expanding() 470 486 */ 471 487 void QwtDynGridLayout::stretchGrid( const QRect &rect, 472 uint numCol s, QVector<int>& rowHeight, QVector<int>& colWidth ) const473 { 474 if ( numCol s == 0 || isEmpty() )488 uint numColumns, QVector<int>& rowHeight, QVector<int>& colWidth ) const 489 { 490 if ( numColumns == 0 || isEmpty() ) 475 491 return; 476 492 … … 481 497 if ( expandH ) 482 498 { 483 int xDelta = rect.width() - 2 * margin() - ( numCol s - 1 ) * spacing();484 for ( int col = 0; col < ( int )numCols; col++ )499 int xDelta = rect.width() - 2 * margin() - ( numColumns - 1 ) * spacing(); 500 for ( uint col = 0; col < numColumns; col++ ) 485 501 xDelta -= colWidth[col]; 486 502 487 503 if ( xDelta > 0 ) 488 504 { 489 for ( int col = 0; col < ( int )numCols; col++ )505 for ( uint col = 0; col < numColumns; col++ ) 490 506 { 491 const int space = xDelta / ( numCol s - col );507 const int space = xDelta / ( numColumns - col ); 492 508 colWidth[col] += space; 493 509 xDelta -= space; … … 498 514 if ( expandV ) 499 515 { 500 uint numRows = itemCount() / numCol s;501 if ( itemCount() % numCol s )516 uint numRows = itemCount() / numColumns; 517 if ( itemCount() % numColumns ) 502 518 numRows++; 503 519 504 520 int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing(); 505 for ( int row = 0; row < ( int )numRows; row++ )521 for ( uint row = 0; row < numRows; row++ ) 506 522 yDelta -= rowHeight[row]; 507 523 508 524 if ( yDelta > 0 ) 509 525 { 510 for ( int row = 0; row < ( int )numRows; row++ )526 for ( uint row = 0; row < numRows; row++ ) 511 527 { 512 528 const int space = yDelta / ( numRows - row ); … … 519 535 520 536 /*! 521 Return the size hint. If maxCol s() > 0 it is the size for522 a grid with maxCol s() columns, otherwise it is the size for537 Return the size hint. If maxColumns() > 0 it is the size for 538 a grid with maxColumns() columns, otherwise it is the size for 523 539 a grid with only one row. 524 540 525 \sa maxCols(), setMaxCols() 541 \return Size hint 542 \sa maxColumns(), setMaxColumns() 526 543 */ 527 544 QSize QwtDynGridLayout::sizeHint() const … … 530 547 return QSize(); 531 548 532 const uint numCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); 533 uint numRows = itemCount() / numCols; 534 if ( itemCount() % numCols ) 549 uint numColumns = itemCount(); 550 if ( d_data->maxColumns > 0 ) 551 numColumns = qMin( d_data->maxColumns, numColumns ); 552 553 uint numRows = itemCount() / numColumns; 554 if ( itemCount() % numColumns ) 535 555 numRows++; 536 556 537 557 QVector<int> rowHeight( numRows ); 538 QVector<int> colWidth( numCol s );539 540 layoutGrid( numCol s, rowHeight, colWidth );558 QVector<int> colWidth( numColumns ); 559 560 layoutGrid( numColumns, rowHeight, colWidth ); 541 561 542 562 int h = 2 * margin() + ( numRows - 1 ) * spacing(); 543 for ( int row = 0; row < ( int )numRows; row++ )563 for ( uint row = 0; row < numRows; row++ ) 544 564 h += rowHeight[row]; 545 565 546 int w = 2 * margin() + ( numCol s - 1 ) * spacing();547 for ( int col = 0; col < ( int )numCols; col++ )566 int w = 2 * margin() + ( numColumns - 1 ) * spacing(); 567 for ( uint col = 0; col < numColumns; col++ ) 548 568 w += colWidth[col]; 549 569 … … 553 573 /*! 554 574 \return Number of rows of the current layout. 555 \sa numCol s()575 \sa numColumns() 556 576 \warning The number of rows might change whenever the geometry changes 557 577 */ … … 566 586 \warning The number of columns might change whenever the geometry changes 567 587 */ 568 uint QwtDynGridLayout::numCol s() const569 { 570 return d_data->numCol s;571 } 588 uint QwtDynGridLayout::numColumns() const 589 { 590 return d_data->numColumns; 591 } -
trunk/BNC/qwt/qwt_dyngrid_layout.h
r4271 r8127 22 22 QwtDynGridLayout takes the space it gets, divides it up into rows and 23 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 maxCol s()).24 It lays out as many number of columns as possible (limited by maxColumns()). 25 25 */ 26 26 … … 36 36 virtual void invalidate(); 37 37 38 void setMaxCol s( uint maxCols );39 uint maxCol s() const;38 void setMaxColumns( uint maxCols ); 39 uint maxColumns() const; 40 40 41 41 uint numRows () const; 42 uint numCol s () const;42 uint numColumns () const; 43 43 44 44 virtual void addItem( QLayoutItem * ); -
trunk/BNC/qwt/qwt_event_pattern.cpp
r4271 r8127 38 38 void QwtEventPattern::initMousePattern( int numButtons ) 39 39 { 40 const int altButton = Qt::AltModifier;41 const int controlButton = Qt::ControlModifier;42 const int shiftButton = Qt::ShiftModifier;43 44 40 d_mousePattern.resize( MousePatternCount ); 45 41 … … 49 45 { 50 46 setMousePattern( MouseSelect1, Qt::LeftButton ); 51 setMousePattern( MouseSelect2, Qt::LeftButton, controlButton);52 setMousePattern( MouseSelect3, Qt::LeftButton, altButton);47 setMousePattern( MouseSelect2, Qt::LeftButton, Qt::ControlModifier ); 48 setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier ); 53 49 break; 54 50 } … … 57 53 setMousePattern( MouseSelect1, Qt::LeftButton ); 58 54 setMousePattern( MouseSelect2, Qt::RightButton ); 59 setMousePattern( MouseSelect3, Qt::LeftButton, altButton);55 setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier ); 60 56 break; 61 57 } … … 67 63 } 68 64 } 69 for ( int i = 0; i < 3; i++ ) 70 { 71 setMousePattern( MouseSelect4 + i, 72 d_mousePattern[MouseSelect1 + i].button, 73 d_mousePattern[MouseSelect1 + i].state | shiftButton ); 74 } 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 ); 75 74 } 76 75 … … 103 102 \param pattern Index of the pattern 104 103 \param button Button 105 \param state State104 \param modifiers Keyboard modifiers 106 105 107 106 \sa QMouseEvent 108 107 */ 109 void QwtEventPattern::setMousePattern( uint pattern, int button, int state ) 110 { 111 if ( pattern < ( uint )d_mousePattern.count() ) 108 void QwtEventPattern::setMousePattern( MousePatternCode pattern, 109 Qt::MouseButton button, Qt::KeyboardModifiers modifiers ) 110 { 111 if ( pattern >= 0 && pattern < MousePatternCount ) 112 112 { 113 d_mousePattern[ int( pattern )].button = button;114 d_mousePattern[ int( pattern )].state = state;113 d_mousePattern[ pattern ].button = button; 114 d_mousePattern[ pattern ].modifiers = modifiers; 115 115 } 116 116 } … … 121 121 \param pattern Index of the pattern 122 122 \param key Key 123 \param state State123 \param modifiers Keyboard modifiers 124 124 125 125 \sa QKeyEvent 126 126 */ 127 void QwtEventPattern::setKeyPattern( uint pattern, int key, int state ) 128 { 129 if ( pattern < ( uint )d_keyPattern.count() ) 127 void QwtEventPattern::setKeyPattern( KeyPatternCode pattern, 128 int key, Qt::KeyboardModifiers modifiers ) 129 { 130 if ( pattern >= 0 && pattern < KeyPatternCount ) 130 131 { 131 d_keyPattern[ int( pattern )].key = key;132 d_keyPattern[ int( pattern )].state = state;132 d_keyPattern[ pattern ].key = key; 133 d_keyPattern[ pattern ].modifiers = modifiers; 133 134 } 134 135 } … … 146 147 } 147 148 148 //! Return mouse patterns149 //! \return Mouse pattern 149 150 const QVector<QwtEventPattern::MousePattern> & 150 151 QwtEventPattern::mousePattern() const … … 153 154 } 154 155 155 //! Return key patterns156 //! \return Key pattern 156 157 const QVector<QwtEventPattern::KeyPattern> & 157 158 QwtEventPattern::keyPattern() const … … 160 161 } 161 162 162 //! Return ,ouse patterns163 //! \return Mouse pattern 163 164 QVector<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern() 164 165 { … … 166 167 } 167 168 168 //! Return Key patterns169 //! \return Key pattern 169 170 QVector<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern() 170 171 { … … 179 180 are set. 180 181 181 \param patternIndex of the event pattern182 \param code Index of the event pattern 182 183 \param event Mouse event 183 184 \return true if matches … … 185 186 \sa keyMatch() 186 187 */ 187 bool QwtEventPattern::mouseMatch( uint pattern,188 bool QwtEventPattern::mouseMatch( MousePatternCode code, 188 189 const QMouseEvent *event ) const 189 190 { 190 bool ok = false; 191 192 if ( event && pattern < ( uint )d_mousePattern.count() ) 193 ok = mouseMatch( d_mousePattern[int( pattern )], event ); 194 195 return ok; 191 if ( code >= 0 && code < MousePatternCount ) 192 return mouseMatch( d_mousePattern[ code ], event ); 193 194 return false; 196 195 } 197 196 … … 213 212 const QMouseEvent *event ) const 214 213 { 215 if ( event ->button() != pattern.button)214 if ( event == NULL ) 216 215 return false; 217 216 218 const bool matched = 219 ( event->modifiers() & Qt::KeyboardModifierMask ) == 220 ( int )( pattern.state & Qt::KeyboardModifierMask ); 221 222 return matched; 217 const MousePattern mousePattern( event->button(), event->modifiers() ); 218 return mousePattern == pattern; 223 219 } 224 220 … … 230 226 are set. 231 227 232 \param patternIndex of the event pattern228 \param code Index of the event pattern 233 229 \param event Key event 234 230 \return true if matches … … 236 232 \sa mouseMatch() 237 233 */ 238 bool QwtEventPattern::keyMatch( uint pattern,234 bool QwtEventPattern::keyMatch( KeyPatternCode code, 239 235 const QKeyEvent *event ) const 240 236 { 241 bool ok = false; 242 243 if ( event && pattern < ( uint )d_keyPattern.count() ) 244 ok = keyMatch( d_keyPattern[int( pattern )], event ); 245 246 return ok; 237 if ( code >= 0 && code < KeyPatternCount ) 238 return keyMatch( d_keyPattern[ code ], event ); 239 240 return false; 247 241 } 248 242 … … 264 258 const KeyPattern &pattern, const QKeyEvent *event ) const 265 259 { 266 if ( event ->key() != pattern.key)260 if ( event == NULL ) 267 261 return false; 268 262 269 const bool matched = 270 ( event->modifiers() & Qt::KeyboardModifierMask ) == 271 ( int )( pattern.state & Qt::KeyboardModifierMask ); 272 273 return matched; 274 } 263 const KeyPattern keyPattern( event->key(), event->modifiers() ); 264 return keyPattern == pattern; 265 } -
trunk/BNC/qwt/qwt_event_pattern.h
r4271 r8127 33 33 \brief Symbolic mouse input codes 34 34 35 The default initialization for 3 button mice is: 36 - MouseSelect1\n 37 Qt::LeftButton 38 - MouseSelect2\n 39 Qt::RightButton 40 - MouseSelect3\n 41 Qt::MidButton 42 - MouseSelect4\n 43 Qt::LeftButton + Qt::ShiftButton 44 - MouseSelect5\n 45 Qt::RightButton + Qt::ShiftButton 46 - MouseSelect6\n 47 Qt::MidButton + Qt::ShiftButton 48 49 The default initialization for 2 button mice is: 50 - MouseSelect1\n 51 Qt::LeftButton 52 - MouseSelect2\n 53 Qt::RightButton 54 - MouseSelect3\n 55 Qt::LeftButton + Qt::AltButton 56 - MouseSelect4\n 57 Qt::LeftButton + Qt::ShiftButton 58 - MouseSelect5\n 59 Qt::RightButton + Qt::ShiftButton 60 - MouseSelect6\n 61 Qt::LeftButton + Qt::AltButton + Qt::ShiftButton 62 63 The default initialization for 1 button mice is: 64 - MouseSelect1\n 65 Qt::LeftButton 66 - MouseSelect2\n 67 Qt::LeftButton + Qt::ControlButton 68 - MouseSelect3\n 69 Qt::LeftButton + Qt::AltButton 70 - MouseSelect4\n 71 Qt::LeftButton + Qt::ShiftButton 72 - MouseSelect5\n 73 Qt::LeftButton + Qt::ControlButton + Qt::ShiftButton 74 - MouseSelect6\n 75 Qt::LeftButton + Qt::AltButton + Qt::ShiftButton 76 77 \sa initMousePattern() 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() 78 43 */ 79 80 44 enum MousePatternCode 81 45 { 46 /*! 47 The default setting for 1, 2 and 3 button mice is: 48 49 - Qt::LeftButton 50 - Qt::LeftButton 51 - Qt::LeftButton 52 */ 82 53 MouseSelect1, 54 55 /*! 56 The default setting for 1, 2 and 3 button mice is: 57 58 - Qt::LeftButton + Qt::ControlModifier 59 - Qt::RightButton 60 - Qt::RightButton 61 */ 83 62 MouseSelect2, 63 64 /*! 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 70 */ 84 71 MouseSelect3, 72 73 /*! 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 79 */ 85 80 MouseSelect4, 81 82 /*! 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 88 */ 86 89 MouseSelect5, 90 91 /*! 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 97 */ 87 98 MouseSelect6, 88 99 100 //! Number of mouse patterns 89 101 MousePatternCount 90 102 }; … … 93 105 \brief Symbolic keyboard input codes 94 106 95 Default initialization: 96 - KeySelect1\n 97 Qt::Key_Return 98 - KeySelect2\n 99 Qt::Key_Space 100 - KeyAbort\n 101 Qt::Key_Escape 102 103 - KeyLeft\n 104 Qt::Key_Left 105 - KeyRight\n 106 Qt::Key_Right 107 - KeyUp\n 108 Qt::Key_Up 109 - KeyDown\n 110 Qt::Key_Down 111 112 - KeyUndo\n 113 Qt::Key_Minus 114 - KeyRedo\n 115 Qt::Key_Plus 116 - KeyHome\n 117 Qt::Key_Escape 107 Individual settings can be configured using setKeyPattern() 108 109 \sa setKeyPattern(), setMousePattern() 118 110 */ 119 111 enum KeyPatternCode 120 112 { 113 //! Qt::Key_Return 121 114 KeySelect1, 115 116 //! Qt::Key_Space 122 117 KeySelect2, 118 119 //! Qt::Key_Escape 123 120 KeyAbort, 124 121 122 //! Qt::Key_Left 125 123 KeyLeft, 124 125 //! Qt::Key_Right 126 126 KeyRight, 127 128 //! Qt::Key_Up 127 129 KeyUp, 130 131 //! Qt::Key_Down 128 132 KeyDown, 129 133 134 //! Qt::Key_Plus 130 135 KeyRedo, 136 137 //! Qt::Key_Minus 131 138 KeyUndo, 139 140 //! Qt::Key_Escape 132 141 KeyHome, 133 142 143 //! Number of key patterns 134 144 KeyPatternCount 135 145 }; … … 140 150 public: 141 151 //! Constructor 142 MousePattern( int btn = Qt::NoButton, int st = Qt::NoButton ) 152 MousePattern( Qt::MouseButton btn = Qt::NoButton, 153 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ): 154 button( btn ), 155 modifiers( modifierCodes ) 143 156 { 144 button = btn;145 state = st;146 157 } 147 158 148 //! Button code149 intbutton;150 151 //! State152 int state;159 //! Button 160 Qt::MouseButton button; 161 162 //! Keyboard modifier 163 Qt::KeyboardModifiers modifiers; 153 164 }; 154 165 … … 158 169 public: 159 170 //! Constructor 160 KeyPattern( int k = 0, int st = Qt::NoButton ) 171 KeyPattern( int keyCode = Qt::Key_unknown, 172 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ): 173 key( keyCode ), 174 modifiers( modifierCodes ) 161 175 { 162 key = k;163 state = st;164 176 } 165 177 … … 167 179 int key; 168 180 169 //! State170 int state;181 //! Modifiers 182 Qt::KeyboardModifiers modifiers; 171 183 }; 172 184 … … 177 189 void initKeyPattern(); 178 190 179 void setMousePattern( uint pattern, int button, int state = Qt::NoButton ); 180 void setKeyPattern( uint pattern, int key, int state = Qt::NoButton ); 191 void setMousePattern( MousePatternCode, Qt::MouseButton button, 192 Qt::KeyboardModifiers = Qt::NoModifier ); 193 194 void setKeyPattern( KeyPatternCode, int keyCode, 195 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ); 181 196 182 197 void setMousePattern( const QVector<MousePattern> & ); … … 189 204 QVector<KeyPattern> &keyPattern(); 190 205 191 bool mouseMatch( uint pattern, const QMouseEvent * ) const;192 bool keyMatch( uint pattern, const QKeyEvent * ) const;206 bool mouseMatch( MousePatternCode, const QMouseEvent * ) const; 207 bool keyMatch( KeyPatternCode, const QKeyEvent * ) const; 193 208 194 209 protected: … … 213 228 QwtEventPattern::MousePattern b2 ) 214 229 { 215 return b1.button == b2.button && b1. state == b2.state;230 return b1.button == b2.button && b1.modifiers == b2.modifiers; 216 231 } 217 232 … … 220 235 QwtEventPattern::KeyPattern b2 ) 221 236 { 222 return b1.key == b2.key && b1. state == b2.state;237 return b1.key == b2.key && b1.modifiers == b2.modifiers; 223 238 } 224 239 -
trunk/BNC/qwt/qwt_global.h
r4271 r8127 15 15 // QWT_VERSION is (major << 16) + (minor << 8) + patch. 16 16 17 #define QWT_VERSION 0x060001 18 #define QWT_VERSION_STR "6.0.1" 19 20 #if defined(Q_WS_WIN) || defined(Q_WS_S60) 17 #define QWT_VERSION 0x060104 18 #define QWT_VERSION_STR "6.1.4" 21 19 22 20 #if defined(_MSC_VER) /* MSVC Compiler */ 23 21 /* template-class specialization 'identifier' is already instantiated */ 24 22 #pragma warning(disable: 4660) 23 /* inherits via dominance */ 24 #pragma warning(disable: 4250) 25 25 #endif // _MSC_VER 26 26 … … 28 28 29 29 #if defined(QWT_MAKEDLL) // create a Qwt DLL library 30 #define QWT_EXPORT __declspec(dllexport) 31 #define QWT_TEMPLATEDLL 30 #define QWT_EXPORT Q_DECL_EXPORT 32 31 #else // use a Qwt DLL library 33 #define QWT_EXPORT __declspec(dllimport)32 #define QWT_EXPORT Q_DECL_IMPORT 34 33 #endif 35 34 36 35 #endif // QWT_DLL 37 38 #endif // Q_WS_WIN || Q_WS_S6039 36 40 37 #ifndef QWT_EXPORT … … 42 39 #endif 43 40 44 // #define QWT_NO_COMPAT 1 // disable withdrawn functionality45 46 41 #endif -
trunk/BNC/qwt/qwt_interval.cpp
r4271 r8127 13 13 14 14 /*! 15 16 17 18 19 20 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 21 */ 22 22 QwtInterval QwtInterval::normalized() const … … 35 35 36 36 /*! 37 38 39 37 Invert the limits of the interval 38 \return Inverted interval 39 \sa normalized() 40 40 */ 41 41 QwtInterval QwtInterval::inverted() const … … 131 131 } 132 132 133 //! Intersect 2 intervals 133 /*! 134 \brief Intersect 2 intervals 135 136 \param other Interval to be intersect with 137 \return Intersection 138 */ 134 139 QwtInterval QwtInterval::intersect( const QwtInterval &other ) const 135 140 { … … 193 198 } 194 199 195 //! Unites this interval with the given interval. 196 QwtInterval& QwtInterval::operator|=( const QwtInterval & interval ) 197 { 198 *this = *this | interval; 200 /*! 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 ) 207 { 208 *this = *this | other; 199 209 return *this; 200 210 } 201 211 202 //! Intersects this interval with the given interval. 203 QwtInterval& QwtInterval::operator&=( const QwtInterval & interval ) 204 { 205 *this = *this & interval; 212 /*! 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 ) 219 { 220 *this = *this & other; 206 221 return *this; 207 222 } 208 223 209 224 /*! 210 Test if two intervals overlap 225 \brief Test if two intervals overlap 226 227 \param other Interval 228 \return True, when the intervals are intersecting 211 229 */ 212 230 bool QwtInterval::intersects( const QwtInterval &other ) const … … 244 262 245 263 /*! 246 247 248 249 250 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 251 269 */ 252 270 QwtInterval QwtInterval::symmetrize( double value ) const … … 262 280 263 281 /*! 264 265 266 267 268 269 282 Limit the interval, keeping the border modes 283 284 \param lowerBound Lower limit 285 \param upperBound Upper limit 286 287 \return Limited interval 270 288 */ 271 289 QwtInterval QwtInterval::limited( double lowerBound, double upperBound ) const … … 284 302 285 303 /*! 286 Extend the interval 287 288 If value is below minValue, value becomes the lower limit. 289 If value is above maxValue, value becomes the upper limit. 290 291 extend has no effect for invalid intervals 292 293 \param value Value 294 \sa isValid() 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() 295 315 */ 296 316 QwtInterval QwtInterval::extend( double value ) const … … 304 324 305 325 /*! 306 307 308 309 310 311 326 Extend an interval 327 328 \param value Value 329 \return Reference of the extended interval 330 331 \sa extend() 312 332 */ 313 333 QwtInterval& QwtInterval::operator|=( double value ) -
trunk/BNC/qwt/qwt_interval.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include <qmetatype.h> 15 14 16 #ifndef QT_NO_DEBUG_STREAM 15 17 #include <qdebug.h> … … 200 202 201 203 /*! 202 Return the width of an interval203 The width of invalid intervals is 0.0, otherwise the result is204 maxValue() - minValue().205 206 \sa isValid()207 */208 inline double QwtInterval::width() const209 {210 return isValid() ? ( d_maxValue - d_minValue ) : 0.0;211 }212 213 /*!214 Intersection of two intervals215 \sa intersect()216 */217 inline QwtInterval QwtInterval::operator&(218 const QwtInterval &interval ) const219 {220 return intersect( interval );221 }222 223 /*!224 Union of two intervals225 \sa unite()226 */227 inline QwtInterval QwtInterval::operator|(228 const QwtInterval &interval ) const229 {230 return unite( interval );231 }232 233 //! Compare two intervals234 inline bool QwtInterval::operator==( const QwtInterval &other ) const235 {236 return ( d_minValue == other.d_minValue ) &&237 ( d_maxValue == other.d_maxValue ) &&238 ( d_borderFlags == other.d_borderFlags );239 }240 241 //! Compare two intervals242 inline bool QwtInterval::operator!=( const QwtInterval &other ) const243 {244 return ( !( *this == other ) );245 }246 247 /*!248 Extend an interval249 250 \param value Value251 \return Extended interval252 \sa extend()253 */254 inline QwtInterval QwtInterval::operator|( double value ) const255 {256 return extend( value );257 }258 259 //! \return true, if isValid() && (minValue() >= maxValue())260 inline bool QwtInterval::isNull() const261 {262 return isValid() && d_minValue >= d_maxValue;263 }264 265 /*!266 204 A interval is valid when minValue() <= maxValue(). 267 205 In case of QwtInterval::ExcludeBorders it is true 268 206 when minValue() < maxValue() 207 208 \return True, when the interval is valid 269 209 */ 270 210 inline bool QwtInterval::isValid() const … … 277 217 278 218 /*! 219 \brief Return the width of an interval 220 221 The width of invalid intervals is 0.0, otherwise the result is 222 maxValue() - minValue(). 223 224 \return Interval width 225 \sa isValid() 226 */ 227 inline double QwtInterval::width() const 228 { 229 return isValid() ? ( d_maxValue - d_minValue ) : 0.0; 230 } 231 232 /*! 233 \brief Intersection of two intervals 234 235 \param other Interval to intersect with 236 \return Intersection of this and other 237 238 \sa intersect() 239 */ 240 inline QwtInterval QwtInterval::operator&( 241 const QwtInterval &other ) const 242 { 243 return intersect( other ); 244 } 245 246 /*! 247 Union of two intervals 248 249 \param other Interval to unite with 250 \return Union of this and other 251 252 \sa unite() 253 */ 254 inline QwtInterval QwtInterval::operator|( 255 const QwtInterval &other ) const 256 { 257 return unite( other ); 258 } 259 260 /*! 261 \brief Compare two intervals 262 263 \param other Interval to compare with 264 \return True, when this and other are equal 265 */ 266 inline bool QwtInterval::operator==( const QwtInterval &other ) const 267 { 268 return ( d_minValue == other.d_minValue ) && 269 ( d_maxValue == other.d_maxValue ) && 270 ( d_borderFlags == other.d_borderFlags ); 271 } 272 /*! 273 \brief Compare two intervals 274 275 \param other Interval to compare with 276 \return True, when this and other are not equal 277 */ 278 inline bool QwtInterval::operator!=( const QwtInterval &other ) const 279 { 280 return ( !( *this == other ) ); 281 } 282 283 /*! 284 Extend an interval 285 286 \param value Value 287 \return Extended interval 288 \sa extend() 289 */ 290 inline QwtInterval QwtInterval::operator|( double value ) const 291 { 292 return extend( value ); 293 } 294 295 //! \return true, if isValid() && (minValue() >= maxValue()) 296 inline bool QwtInterval::isNull() const 297 { 298 return isValid() && d_minValue >= d_maxValue; 299 } 300 301 /*! 279 302 Invalidate the interval 280 303 … … 289 312 290 313 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags ) 314 Q_DECLARE_METATYPE( QwtInterval ) 291 315 292 316 #ifndef QT_NO_DEBUG_STREAM -
trunk/BNC/qwt/qwt_interval_symbol.cpp
r4271 r8127 15 15 #if QT_VERSION < 0x040601 16 16 #define qAtan2(y, x) ::atan2(y, x) 17 #define qFastSin(x) qSin(x) 18 #define qFastCos(x) qCos(x) 17 19 #endif 18 20 … … 149 151 { 150 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, 169 qreal width, Qt::PenStyle style ) 170 { 171 setPen( QPen( color, width, style ) ); 151 172 } 152 173 … … 232 253 double dw2 = sw / 2.0; 233 254 234 const double cx = q Cos( angle ) * dw2;235 const double sy = q Sin( angle ) * dw2;255 const double cx = qFastCos( angle ) * dw2; 256 const double sy = qFastSin( angle ) * dw2; 236 257 237 258 QwtPainter::drawLine( painter, … … 280 301 double dw2 = sw / 2.0; 281 302 282 const int cx = qCos( angle ) * dw2;283 const int sy = qSin( angle ) * dw2;303 const double cx = qFastCos( angle ) * dw2; 304 const double sy = qFastSin( angle ) * dw2; 284 305 285 306 QPolygonF polygon; -
trunk/BNC/qwt/qwt_interval_symbol.h
r4271 r8127 69 69 const QBrush& brush() const; 70 70 71 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 71 72 void setPen( const QPen & ); 72 73 const QPen& pen() const; -
trunk/BNC/qwt/qwt_legend.cpp
r4271 r8127 9 9 10 10 #include "qwt_legend.h" 11 #include "qwt_legend_itemmanager.h" 12 #include "qwt_legend_item.h" 11 #include "qwt_legend_label.h" 13 12 #include "qwt_dyngrid_layout.h" 14 13 #include "qwt_math.h" 14 #include "qwt_plot_item.h" 15 #include "qwt_painter.h" 15 16 #include <qapplication.h> 16 #include <qmap.h>17 17 #include <qscrollbar.h> 18 18 #include <qscrollarea.h> 19 #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; 47 }; 48 49 QList< Entry > d_entries; 50 }; 51 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 } 19 124 20 125 class QwtLegend::PrivateData 21 126 { 22 127 public: 23 class LegendMap 24 { 25 public: 26 void insert( const QwtLegendItemManager *, QWidget * ); 27 28 void remove( const QwtLegendItemManager * ); 29 void remove( QWidget * ); 30 31 void clear(); 32 33 uint count() const; 34 35 inline const QWidget *find( const QwtLegendItemManager * ) const; 36 inline QWidget *find( const QwtLegendItemManager * ); 37 38 inline const QwtLegendItemManager *find( const QWidget * ) const; 39 inline QwtLegendItemManager *find( const QWidget * ); 40 41 const QMap<QWidget *, const QwtLegendItemManager *> &widgetMap() const; 42 QMap<QWidget *, const QwtLegendItemManager *> &widgetMap(); 43 44 private: 45 QMap<QWidget *, const QwtLegendItemManager *> d_widgetMap; 46 QMap<const QwtLegendItemManager *, QWidget *> d_itemMap; 47 }; 48 49 QwtLegend::LegendItemMode itemMode; 50 51 LegendMap map; 128 PrivateData(): 129 itemMode( QwtLegendData::ReadOnly ), 130 view( NULL ) 131 { 132 } 133 134 QwtLegendData::Mode itemMode; 135 QwtLegendMap itemMap; 52 136 53 137 class LegendView; … … 61 145 QScrollArea( parent ) 62 146 { 63 setFocusPolicy( Qt::NoFocus );64 65 147 contentsWidget = new QWidget( this ); 66 148 contentsWidget->setObjectName( "QwtLegendViewContents" ); … … 77 159 } 78 160 79 virtual bool viewportEvent( QEvent *e ) 80 { 81 bool ok = QScrollArea::viewportEvent( e ); 82 83 if ( e->type() == QEvent::Resize ) 84 { 85 QEvent event( QEvent::LayoutRequest ); 86 QApplication::sendEvent( contentsWidget, &event ); 161 virtual bool event( QEvent *event ) 162 { 163 if ( event->type() == QEvent::PolishRequest ) 164 { 165 setFocusPolicy( Qt::NoFocus ); 166 } 167 168 if ( event->type() == QEvent::Resize ) 169 { 170 // adjust the size to en/disable the scrollbars 171 // before QScrollArea adjusts the viewport size 172 173 const QRect cr = contentsRect(); 174 175 int w = cr.width(); 176 int h = contentsWidget->heightForWidth( cr.width() ); 177 if ( h > w ) 178 { 179 w -= verticalScrollBar()->sizeHint().width(); 180 h = contentsWidget->heightForWidth( w ); 181 } 182 183 contentsWidget->resize( w, h ); 184 } 185 186 return QScrollArea::event( event ); 187 } 188 189 virtual bool viewportEvent( QEvent *event ) 190 { 191 bool ok = QScrollArea::viewportEvent( event ); 192 193 if ( event->type() == QEvent::Resize ) 194 { 195 layoutContents(); 87 196 } 88 197 return ok; … … 112 221 } 113 222 223 void layoutContents() 224 { 225 const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>( 226 contentsWidget->layout() ); 227 if ( tl == NULL ) 228 return; 229 230 const QSize visibleSize = viewport()->contentsRect().size(); 231 232 const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin(); 233 234 int w = qMax( visibleSize.width(), minW ); 235 int h = qMax( tl->heightForWidth( w ), visibleSize.height() ); 236 237 const int vpWidth = viewportSize( w, h ).width(); 238 if ( w > vpWidth ) 239 { 240 w = qMax( vpWidth, minW ); 241 h = qMax( tl->heightForWidth( w ), visibleSize.height() ); 242 } 243 244 contentsWidget->resize( w, h ); 245 } 246 114 247 QWidget *contentsWidget; 115 248 }; 116 249 117 void QwtLegend::PrivateData::LegendMap::insert(118 const QwtLegendItemManager *item, QWidget *widget )119 {120 d_itemMap.insert( item, widget );121 d_widgetMap.insert( widget, item );122 }123 124 void QwtLegend::PrivateData::LegendMap::remove( const QwtLegendItemManager *item )125 {126 QWidget *widget = d_itemMap[item];127 d_itemMap.remove( item );128 d_widgetMap.remove( widget );129 }130 131 void QwtLegend::PrivateData::LegendMap::remove( QWidget *widget )132 {133 const QwtLegendItemManager *item = d_widgetMap[widget];134 d_itemMap.remove( item );135 d_widgetMap.remove( widget );136 }137 138 void QwtLegend::PrivateData::LegendMap::clear()139 {140 141 /*142 We can't delete the widgets in the following loop, because143 we would get ChildRemoved events, changing d_itemMap, while144 we are iterating.145 */146 147 QList<const QWidget *> widgets;148 149 QMap<const QwtLegendItemManager *, QWidget *>::const_iterator it;150 for ( it = d_itemMap.begin(); it != d_itemMap.end(); ++it )151 widgets.append( it.value() );152 153 d_itemMap.clear();154 d_widgetMap.clear();155 156 for ( int i = 0; i < widgets.size(); i++ )157 delete widgets[i];158 }159 160 uint QwtLegend::PrivateData::LegendMap::count() const161 {162 return d_itemMap.count();163 }164 165 inline const QWidget *QwtLegend::PrivateData::LegendMap::find(166 const QwtLegendItemManager *item ) const167 {168 if ( !d_itemMap.contains( item ) )169 return NULL;170 171 return d_itemMap[item];172 }173 174 inline QWidget *QwtLegend::PrivateData::LegendMap::find(175 const QwtLegendItemManager *item )176 {177 if ( !d_itemMap.contains( item ) )178 return NULL;179 180 return d_itemMap[item];181 }182 183 inline const QwtLegendItemManager *QwtLegend::PrivateData::LegendMap::find(184 const QWidget *widget ) const185 {186 QWidget *w = const_cast<QWidget *>( widget );187 if ( !d_widgetMap.contains( w ) )188 return NULL;189 190 return d_widgetMap[w];191 }192 193 inline QwtLegendItemManager *QwtLegend::PrivateData::LegendMap::find(194 const QWidget *widget )195 {196 QWidget *w = const_cast<QWidget *>( widget );197 if ( !d_widgetMap.contains( w ) )198 return NULL;199 200 return const_cast<QwtLegendItemManager *>( d_widgetMap[w] );201 }202 203 inline const QMap<QWidget *, const QwtLegendItemManager *> &204 QwtLegend::PrivateData::LegendMap::widgetMap() const205 {206 return d_widgetMap;207 }208 209 inline QMap<QWidget *, const QwtLegendItemManager *> &210 QwtLegend::PrivateData::LegendMap::widgetMap()211 {212 return d_widgetMap;213 }214 215 250 /*! 216 251 Constructor 217 218 252 \param parent Parent widget 219 253 */ 220 254 QwtLegend::QwtLegend( QWidget *parent ): 221 Q Frame( parent )255 QwtAbstractLegend( parent ) 222 256 { 223 257 setFrameStyle( NoFrame ); 224 258 225 259 d_data = new QwtLegend::PrivateData; 226 d_data->itemMode = QwtLegend::ReadOnlyItem;227 260 228 261 d_data->view = new QwtLegend::PrivateData::LegendView( this ); … … 247 280 } 248 281 249 //! \sa LegendItemMode 250 void QwtLegend::setItemMode( LegendItemMode mode ) 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() 291 */ 292 void QwtLegend::setMaxColumns( uint numColums ) 293 { 294 QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>( 295 d_data->view->contentsWidget->layout() ); 296 if ( tl ) 297 tl->setMaxColumns( numColums ); 298 } 299 300 /*! 301 \return Maximum number of entries in a row 302 \sa setMaxColumns(), QwtDynGridLayout::maxColumns() 303 */ 304 uint QwtLegend::maxColumns() const 305 { 306 uint maxCols = 0; 307 308 const QwtDynGridLayout *tl = qobject_cast<const QwtDynGridLayout *>( 309 d_data->view->contentsWidget->layout() ); 310 if ( tl ) 311 maxCols = tl->maxColumns(); 312 313 return maxCols; 314 } 315 316 /*! 317 \brief Set the default mode for legend labels 318 319 Legend labels will be constructed according to the 320 attributes in a QwtLegendData object. When it doesn't 321 contain a value for the QwtLegendData::ModeRole the 322 label will be initialized with the default mode of the legend. 323 324 \param mode Default item mode 325 326 \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData() 327 \note Changing the mode doesn't have any effect on existing labels. 328 */ 329 void QwtLegend::setDefaultItemMode( QwtLegendData::Mode mode ) 251 330 { 252 331 d_data->itemMode = mode; 253 332 } 254 333 255 //! \sa LegendItemMode 256 QwtLegend::LegendItemMode QwtLegend::itemMode() const 334 /*! 335 \return Default item mode 336 \sa setDefaultItemMode() 337 */ 338 QwtLegendData::Mode QwtLegend::defaultItemMode() const 257 339 { 258 340 return d_data->itemMode; … … 261 343 /*! 262 344 The contents widget is the only child of the viewport of 263 the internal QScrollArea 345 the internal QScrollArea and the parent widget of all legend items. 264 346 265 347 \return Container widget of the legend items … … 290 372 /*! 291 373 The contents widget is the only child of the viewport of 292 the internal QScrollArea 374 the internal QScrollArea and the parent widget of all legend items. 293 375 294 376 \return Container widget of the legend items … … 301 383 302 384 /*! 303 Insert a new item for a plot item 304 \param plotItem Plot item 305 \param legendItem New legend item 306 \note The parent of item will be changed to contentsWidget() 307 */ 308 void QwtLegend::insert( const QwtLegendItemManager *plotItem, QWidget *legendItem ) 309 { 310 if ( legendItem == NULL || plotItem == NULL ) 311 return; 312 313 QWidget *contentsWidget = d_data->view->contentsWidget; 314 315 if ( legendItem->parent() != contentsWidget ) 316 legendItem->setParent( contentsWidget ); 317 318 legendItem->show(); 319 320 d_data->map.insert( plotItem, legendItem ); 321 322 layoutContents(); 323 324 if ( contentsWidget->layout() ) 325 { 326 contentsWidget->layout()->addWidget( legendItem ); 327 385 \brief Update the entries for an item 386 387 \param itemInfo Info for an item 388 \param data List of legend entry attributes for the item 389 */ 390 void QwtLegend::updateLegend( const QVariant &itemInfo, 391 const QList<QwtLegendData> &data ) 392 { 393 QList<QWidget *> widgetList = legendWidgets( itemInfo ); 394 395 if ( widgetList.size() != data.size() ) 396 { 397 QLayout *contentsLayout = d_data->view->contentsWidget->layout(); 398 399 while ( widgetList.size() > data.size() ) 400 { 401 QWidget *w = widgetList.takeLast(); 402 403 contentsLayout->removeWidget( w ); 404 405 // updates might be triggered by signals from the legend widget 406 // itself. So we better don't delete it here. 407 408 w->hide(); 409 w->deleteLater(); 410 } 411 412 for ( int i = widgetList.size(); i < data.size(); i++ ) 413 { 414 QWidget *widget = createWidget( data[i] ); 415 416 if ( contentsLayout ) 417 contentsLayout->addWidget( widget ); 418 419 if ( isVisible() ) 420 { 421 // QLayout does a delayed show, with the effect, that 422 // the size hint will be wrong, when applications 423 // call replot() right after changing the list 424 // of plot items. So we better do the show now. 425 426 widget->setVisible( true ); 427 } 428 429 widgetList += widget; 430 } 431 432 if ( widgetList.isEmpty() ) 433 { 434 d_data->itemMap.remove( itemInfo ); 435 } 436 else 437 { 438 d_data->itemMap.insert( itemInfo, widgetList ); 439 } 440 441 updateTabOrder(); 442 } 443 444 for ( int i = 0; i < data.size(); i++ ) 445 updateWidget( widgetList[i], data[i] ); 446 } 447 448 /*! 449 \brief Create a widget to be inserted into the legend 450 451 The default implementation returns a QwtLegendLabel. 452 453 \param data Attributes of the legend entry 454 \return Widget representing data on the legend 455 456 \note updateWidget() will called soon after createWidget() 457 with the same attributes. 458 */ 459 QWidget *QwtLegend::createWidget( const QwtLegendData &data ) const 460 { 461 Q_UNUSED( data ); 462 463 QwtLegendLabel *label = new QwtLegendLabel(); 464 label->setItemMode( defaultItemMode() ); 465 466 connect( label, SIGNAL( clicked() ), SLOT( itemClicked() ) ); 467 connect( label, SIGNAL( checked( bool ) ), SLOT( itemChecked( bool ) ) ); 468 469 return label; 470 } 471 472 /*! 473 \brief Update the widget 474 475 \param widget Usually a QwtLegendLabel 476 \param data Attributes to be displayed 477 478 \sa createWidget() 479 \note When widget is no QwtLegendLabel updateWidget() does nothing. 480 */ 481 void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData &data ) 482 { 483 QwtLegendLabel *label = qobject_cast<QwtLegendLabel *>( widget ); 484 if ( label ) 485 { 486 label->setData( data ); 487 if ( !data.value( QwtLegendData::ModeRole ).isValid() ) 488 { 489 // use the default mode, when there is no specific 490 // hint from the legend data 491 492 label->setItemMode( defaultItemMode() ); 493 } 494 } 495 } 496 497 void QwtLegend::updateTabOrder() 498 { 499 QLayout *contentsLayout = d_data->view->contentsWidget->layout(); 500 if ( contentsLayout ) 501 { 328 502 // set tab focus chain 329 503 330 504 QWidget *w = NULL; 331 505 332 for ( int i = 0; i < contents Widget->layout()->count(); i++ )333 { 334 QLayoutItem *item = contents Widget->layout()->itemAt( i );506 for ( int i = 0; i < contentsLayout->count(); i++ ) 507 { 508 QLayoutItem *item = contentsLayout->itemAt( i ); 335 509 if ( w && item->widget() ) 336 510 QWidget::setTabOrder( w, item->widget() ); … … 339 513 } 340 514 } 341 if ( parentWidget() && parentWidget()->layout() == NULL )342 {343 /*344 updateGeometry() doesn't post LayoutRequest in certain345 situations, like when we are hidden. But we want the346 parent widget notified, so it can show/hide the legend347 depending on its items.348 */349 QApplication::postEvent( parentWidget(),350 new QEvent( QEvent::LayoutRequest ) );351 }352 }353 354 /*!355 Find the widget that represents a plot item356 357 \param plotItem Plot item358 \return Widget on the legend, or NULL359 */360 QWidget *QwtLegend::find( const QwtLegendItemManager *plotItem ) const361 {362 return d_data->map.find( plotItem );363 }364 365 /*!366 Find the widget that represents a plot item367 368 \param legendItem Legend item369 \return Widget on the legend, or NULL370 */371 QwtLegendItemManager *QwtLegend::find( const QWidget *legendItem ) const372 {373 return d_data->map.find( legendItem );374 }375 376 /*!377 Find the corresponding item for a plotItem and remove it378 from the item list.379 380 \param plotItem Plot item381 */382 void QwtLegend::remove( const QwtLegendItemManager *plotItem )383 {384 QWidget *legendItem = d_data->map.find( plotItem );385 d_data->map.remove( legendItem );386 delete legendItem;387 }388 389 //! Remove all items.390 void QwtLegend::clear()391 {392 bool doUpdate = updatesEnabled();393 if ( doUpdate )394 setUpdatesEnabled( false );395 396 d_data->map.clear();397 398 if ( doUpdate )399 setUpdatesEnabled( true );400 401 update();402 515 } 403 516 … … 412 525 413 526 /*! 414 \return The preferred height, for the width w.527 \return The preferred height, for a width. 415 528 \param width Width 416 529 */ … … 426 539 } 427 540 428 /*!429 Adjust contents widget and item layout to the size of the viewport().430 */431 void QwtLegend::layoutContents()432 {433 const QSize visibleSize =434 d_data->view->viewport()->contentsRect().size();435 436 const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(437 d_data->view->contentsWidget->layout() );438 if ( tl )439 {440 const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin();441 442 int w = qMax( visibleSize.width(), minW );443 int h = qMax( tl->heightForWidth( w ), visibleSize.height() );444 445 const int vpWidth = d_data->view->viewportSize( w, h ).width();446 if ( w > vpWidth )447 {448 w = qMax( vpWidth, minW );449 h = qMax( tl->heightForWidth( w ), visibleSize.height() );450 }451 452 d_data->view->contentsWidget->resize( w, h );453 }454 }455 541 456 542 /*! … … 460 546 \param object Object to be filtered 461 547 \param event Event 548 549 \return Forwarded to QwtAbstractLegend::eventFilter() 462 550 */ 463 551 bool QwtLegend::eventFilter( QObject *object, QEvent *event ) … … 474 562 { 475 563 QWidget *w = static_cast< QWidget * >( ce->child() ); 476 d_data-> map.remove( w );564 d_data->itemMap.removeWidget( w ); 477 565 } 478 566 break; … … 480 568 case QEvent::LayoutRequest: 481 569 { 482 layoutContents(); 570 d_data->view->layoutContents(); 571 572 if ( parentWidget() && parentWidget()->layout() == NULL ) 573 { 574 /* 575 We want the parent widget ( usually QwtPlot ) to recalculate 576 its layout, when the contentsWidget has changed. But 577 because of the scroll view we have to forward the LayoutRequest 578 event manually. 579 580 We don't use updateGeometry() because it doesn't post LayoutRequest 581 events when the legend is hidden. But we want the 582 parent widget notified, so it can show/hide the legend 583 depending on its items. 584 */ 585 QApplication::postEvent( parentWidget(), 586 new QEvent( QEvent::LayoutRequest ) ); 587 } 483 588 break; 484 589 } … … 488 593 } 489 594 490 return QFrame::eventFilter( object, event ); 491 } 492 493 494 //! Return true, if there are no legend items. 595 return QwtAbstractLegend::eventFilter( object, event ); 596 } 597 598 /*! 599 Called internally when the legend has been clicked on. 600 Emits a clicked() signal. 601 */ 602 void QwtLegend::itemClicked() 603 { 604 QWidget *w = qobject_cast<QWidget *>( sender() ); 605 if ( w ) 606 { 607 const QVariant itemInfo = d_data->itemMap.itemInfo( w ); 608 if ( itemInfo.isValid() ) 609 { 610 const QList<QWidget *> widgetList = 611 d_data->itemMap.legendWidgets( itemInfo ); 612 613 const int index = widgetList.indexOf( w ); 614 if ( index >= 0 ) 615 Q_EMIT clicked( itemInfo, index ); 616 } 617 } 618 } 619 620 /*! 621 Called internally when the legend has been checked 622 Emits a checked() signal. 623 */ 624 void QwtLegend::itemChecked( bool on ) 625 { 626 QWidget *w = qobject_cast<QWidget *>( sender() ); 627 if ( w ) 628 { 629 const QVariant itemInfo = d_data->itemMap.itemInfo( w ); 630 if ( itemInfo.isValid() ) 631 { 632 const QList<QWidget *> widgetList = 633 d_data->itemMap.legendWidgets( itemInfo ); 634 635 const int index = widgetList.indexOf( w ); 636 if ( index >= 0 ) 637 Q_EMIT checked( itemInfo, on, index ); 638 } 639 } 640 } 641 642 /*! 643 Render the legend into a given rectangle. 644 645 \param painter Painter 646 \param rect Bounding rectangle 647 \param fillBackground When true, fill rect with the widget background 648 649 \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself 650 */ 651 void QwtLegend::renderLegend( QPainter *painter, 652 const QRectF &rect, bool fillBackground ) const 653 { 654 if ( d_data->itemMap.isEmpty() ) 655 return; 656 657 if ( fillBackground ) 658 { 659 if ( autoFillBackground() || 660 testAttribute( Qt::WA_StyledBackground ) ) 661 { 662 QwtPainter::drawBackgound( painter, rect, this ); 663 } 664 } 665 666 const QwtDynGridLayout *legendLayout = 667 qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() ); 668 if ( legendLayout == NULL ) 669 return; 670 671 int left, right, top, bottom; 672 getContentsMargins( &left, &top, &right, &bottom ); 673 674 QRect layoutRect; 675 layoutRect.setLeft( qCeil( rect.left() ) + left ); 676 layoutRect.setTop( qCeil( rect.top() ) + top ); 677 layoutRect.setRight( qFloor( rect.right() ) - right ); 678 layoutRect.setBottom( qFloor( rect.bottom() ) - bottom ); 679 680 uint numCols = legendLayout->columnsForWidth( layoutRect.width() ); 681 QList<QRect> itemRects = 682 legendLayout->layoutItems( layoutRect, numCols ); 683 684 int index = 0; 685 686 for ( int i = 0; i < legendLayout->count(); i++ ) 687 { 688 QLayoutItem *item = legendLayout->itemAt( i ); 689 QWidget *w = item->widget(); 690 if ( w ) 691 { 692 painter->save(); 693 694 painter->setClipRect( itemRects[index], Qt::IntersectClip ); 695 renderItem( painter, w, itemRects[index], fillBackground ); 696 697 index++; 698 painter->restore(); 699 } 700 } 701 } 702 703 /*! 704 Render a legend entry into a given rectangle. 705 706 \param painter Painter 707 \param widget Widget representing a legend entry 708 \param rect Bounding rectangle 709 \param fillBackground When true, fill rect with the widget background 710 711 \note When widget is not derived from QwtLegendLabel renderItem 712 does nothing beside the background 713 */ 714 void QwtLegend::renderItem( QPainter *painter, 715 const QWidget *widget, const QRectF &rect, bool fillBackground ) const 716 { 717 if ( fillBackground ) 718 { 719 if ( widget->autoFillBackground() || 720 widget->testAttribute( Qt::WA_StyledBackground ) ) 721 { 722 QwtPainter::drawBackgound( painter, rect, widget ); 723 } 724 } 725 726 const QwtLegendLabel *label = qobject_cast<const QwtLegendLabel *>( widget ); 727 if ( label ) 728 { 729 // icon 730 731 const QwtGraphic &icon = label->data().icon(); 732 const QSizeF sz = icon.defaultSize(); 733 734 const QRectF iconRect( rect.x() + label->margin(), 735 rect.center().y() - 0.5 * sz.height(), 736 sz.width(), sz.height() ); 737 738 icon.render( painter, iconRect, Qt::KeepAspectRatio ); 739 740 // title 741 742 QRectF titleRect = rect; 743 titleRect.setX( iconRect.right() + 2 * label->spacing() ); 744 745 painter->setFont( label->font() ); 746 painter->setPen( label->palette().color( QPalette::Text ) ); 747 const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect ); 748 } 749 } 750 751 /*! 752 \return List of widgets associated to a item 753 \param itemInfo Info about an item 754 \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo() 755 */ 756 QList<QWidget *> QwtLegend::legendWidgets( const QVariant &itemInfo ) const 757 { 758 return d_data->itemMap.legendWidgets( itemInfo ); 759 } 760 761 /*! 762 \return First widget in the list of widgets associated to an item 763 \param itemInfo Info about an item 764 \sa itemInfo(), QwtPlot::itemToInfo() 765 \note Almost all types of items have only one widget 766 */ 767 QWidget *QwtLegend::legendWidget( const QVariant &itemInfo ) const 768 { 769 const QList<QWidget *> list = d_data->itemMap.legendWidgets( itemInfo ); 770 if ( list.isEmpty() ) 771 return NULL; 772 773 return list[0]; 774 } 775 776 /*! 777 Find the item that is associated to a widget 778 779 \param widget Widget on the legend 780 \return Associated item info 781 \sa legendWidget() 782 */ 783 QVariant QwtLegend::itemInfo( const QWidget *widget ) const 784 { 785 return d_data->itemMap.itemInfo( widget ); 786 } 787 788 //! \return True, when no item is inserted 495 789 bool QwtLegend::isEmpty() const 496 790 { 497 return d_data->map.count() == 0; 498 } 499 500 //! Return the number of legend items. 501 uint QwtLegend::itemCount() const 502 { 503 return d_data->map.count(); 504 } 505 506 //! Return a list of all legend items 507 QList<QWidget *> QwtLegend::legendItems() const 508 { 509 const QMap<QWidget *, const QwtLegendItemManager *> &map = 510 d_data->map.widgetMap(); 511 512 QList<QWidget *> list; 513 514 QMap<QWidget *, const QwtLegendItemManager *>::const_iterator it; 515 for ( it = map.begin(); it != map.end(); ++it ) 516 list += it.key(); 517 518 return list; 519 } 791 return d_data->itemMap.isEmpty(); 792 } 793 794 /*! 795 Return the extent, that is needed for the scrollbars 796 797 \param orientation Orientation ( 798 \return The width of the vertical scrollbar for Qt::Horizontal and v.v. 799 */ 800 int QwtLegend::scrollExtent( Qt::Orientation orientation ) const 801 { 802 int extent = 0; 803 804 if ( orientation == Qt::Horizontal ) 805 extent = verticalScrollBar()->sizeHint().width(); 806 else 807 extent = horizontalScrollBar()->sizeHint().height(); 808 809 return extent; 810 } 811 -
trunk/BNC/qwt/qwt_legend.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include <qframe.h>15 #include <q list.h>14 #include "qwt_abstract_legend.h" 15 #include <qvariant.h> 16 16 17 17 class QScrollBar; 18 class QwtLegendItemManager;19 18 20 19 /*! … … 23 22 The QwtLegend widget is a tabular arrangement of legend items. Legend 24 23 items might be any type of widget, but in general they will be 25 a QwtLegend Item.24 a QwtLegendLabel. 26 25 27 \sa QwtLegend Item, QwtLegendItemManagerQwtPlot26 \sa QwtLegendLabel, QwtPlotItem, QwtPlot 28 27 */ 29 28 30 class QWT_EXPORT QwtLegend : public Q Frame29 class QWT_EXPORT QwtLegend : public QwtAbstractLegend 31 30 { 32 31 Q_OBJECT 33 32 34 33 public: 35 /*!36 \brief Interaction mode for the legend items37 38 The default is QwtLegend::ReadOnlyItem.39 40 \sa setItemMode(), itemMode(), QwtLegendItem::IdentifierMode41 QwtLegendItem::clicked(), QwtLegendItem::checked(),42 QwtPlot::legendClicked(), QwtPlot::legendChecked()43 */44 45 enum LegendItemMode46 {47 //! The legend item is not interactive, like a label48 ReadOnlyItem,49 50 //! The legend item is clickable, like a push button51 ClickableItem,52 53 //! The legend item is checkable, like a checkable button54 CheckableItem55 };56 57 34 explicit QwtLegend( QWidget *parent = NULL ); 58 35 virtual ~QwtLegend(); 59 36 60 void setItemMode( LegendItemMode ); 61 LegendItemMode itemMode() const; 37 void setMaxColumns( uint numColums ); 38 uint maxColumns() const; 39 40 void setDefaultItemMode( QwtLegendData::Mode ); 41 QwtLegendData::Mode defaultItemMode() const; 62 42 63 43 QWidget *contentsWidget(); 64 44 const QWidget *contentsWidget() const; 65 45 66 void insert( const QwtLegendItemManager *, QWidget * );67 void remove( const QwtLegendItemManager * );46 QWidget *legendWidget( const QVariant & ) const; 47 QList<QWidget *> legendWidgets( const QVariant & ) const; 68 48 69 QWidget *find( const QwtLegendItemManager * ) const; 70 QwtLegendItemManager *find( const QWidget * ) const; 71 72 virtual QList<QWidget *> legendItems() const; 73 74 void clear(); 75 76 bool isEmpty() const; 77 uint itemCount() const; 49 QVariant itemInfo( const QWidget * ) const; 78 50 79 51 virtual bool eventFilter( QObject *, QEvent * ); … … 85 57 QScrollBar *verticalScrollBar() const; 86 58 59 virtual void renderLegend( QPainter *, 60 const QRectF &, bool fillBackground ) const; 61 62 virtual void renderItem( QPainter *, 63 const QWidget *, const QRectF &, bool fillBackground ) const; 64 65 virtual bool isEmpty() const; 66 virtual int scrollExtent( Qt::Orientation ) const; 67 68 Q_SIGNALS: 69 /*! 70 A signal which is emitted when the user has clicked on 71 a legend label, which is in QwtLegendData::Clickable mode. 72 73 \param itemInfo Info for the item item of the 74 selected legend item 75 \param index Index of the legend label in the list of widgets 76 that are associated with the plot item 77 78 \note clicks are disabled as default 79 \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo() 80 */ 81 void clicked( const QVariant &itemInfo, int index ); 82 83 /*! 84 A signal which is emitted when the user has clicked on 85 a legend label, which is in QwtLegendData::Checkable mode 86 87 \param itemInfo Info for the item of the 88 selected legend label 89 \param index Index of the legend label in the list of widgets 90 that are associated with the plot item 91 \param on True when the legend label is checked 92 93 \note clicks are disabled as default 94 \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo() 95 */ 96 void checked( const QVariant &itemInfo, bool on, int index ); 97 98 public Q_SLOTS: 99 virtual void updateLegend( const QVariant &, 100 const QList<QwtLegendData> & ); 101 102 protected Q_SLOTS: 103 void itemClicked(); 104 void itemChecked( bool ); 105 87 106 protected: 88 virtual void layoutContents(); 107 virtual QWidget *createWidget( const QwtLegendData & ) const; 108 virtual void updateWidget( QWidget *widget, const QwtLegendData &data ); 89 109 90 110 private: 111 void updateTabOrder(); 112 91 113 class PrivateData; 92 114 PrivateData *d_data; -
trunk/BNC/qwt/qwt_magnifier.cpp
r4271 r8127 19 19 isEnabled( false ), 20 20 wheelFactor( 0.9 ), 21 wheel ButtonState( Qt::NoButton),21 wheelModifiers( Qt::NoModifier ), 22 22 mouseFactor( 0.95 ), 23 23 mouseButton( Qt::RightButton ), 24 mouseButton State( Qt::NoButton),24 mouseButtonModifiers( Qt::NoModifier ), 25 25 keyFactor( 0.9 ), 26 26 zoomInKey( Qt::Key_Plus ), 27 zoomInKeyModifiers( Qt::NoModifier ), 27 28 zoomOutKey( Qt::Key_Minus ), 28 zoomInKeyModifiers( Qt::NoModifier ),29 29 zoomOutKeyModifiers( Qt::NoModifier ), 30 30 mousePressed( false ) … … 35 35 36 36 double wheelFactor; 37 int wheelButtonState;37 Qt::KeyboardModifiers wheelModifiers; 38 38 39 39 double mouseFactor; 40 int mouseButton; 41 int mouseButtonState; 40 41 Qt::MouseButton mouseButton; 42 Qt::KeyboardModifiers mouseButtonModifiers; 42 43 43 44 double keyFactor; 45 44 46 int zoomInKey; 47 Qt::KeyboardModifiers zoomInKeyModifiers; 48 45 49 int zoomOutKey; 46 int zoomInKeyModifiers; 47 int zoomOutKeyModifiers; 50 Qt::KeyboardModifiers zoomOutKeyModifiers; 48 51 49 52 bool mousePressed; … … 109 112 The wheel factor defines the ratio between the current range 110 113 on the parent widget and the zoomed range for each step of the wheel. 114 115 Use values > 1 for magnification (i.e. 2.0) and values < 1 for 116 scaling down (i.e. 1/2.0 = 0.5). You can use this feature for 117 inverting the direction of the wheel. 118 111 119 The default value is 0.9. 112 120 … … 130 138 131 139 /*! 132 Assign a mandatory button statefor zooming in/out using the wheel.133 The default button state is Qt::NoButton.134 135 \param buttonState Button state136 \sa wheel ButtonState()137 */ 138 void QwtMagnifier::setWheel ButtonState( int buttonState)139 { 140 d_data->wheel ButtonState = buttonState;141 } 142 143 /*! 144 \return Wheel button state145 \sa setWheel ButtonState()146 */ 147 int QwtMagnifier::wheelButtonState() const148 { 149 return d_data->wheel ButtonState;140 Assign keyboard modifiers for zooming in/out using the wheel. 141 The default modifiers are Qt::NoModifiers. 142 143 \param modifiers Keyboard modifiers 144 \sa wheelModifiers() 145 */ 146 void QwtMagnifier::setWheelModifiers( Qt::KeyboardModifiers modifiers ) 147 { 148 d_data->wheelModifiers = modifiers; 149 } 150 151 /*! 152 \return Wheel modifiers 153 \sa setWheelModifiers() 154 */ 155 Qt::KeyboardModifiers QwtMagnifier::wheelModifiers() const 156 { 157 return d_data->wheelModifiers; 150 158 } 151 159 … … 179 187 180 188 \param button Button 181 \param buttonState Button state 189 \param modifiers Keyboard modifiers 190 182 191 \sa getMouseButton() 183 192 */ 184 void QwtMagnifier::setMouseButton( int button, int buttonState ) 193 void QwtMagnifier::setMouseButton( 194 Qt::MouseButton button, Qt::KeyboardModifiers modifiers ) 185 195 { 186 196 d_data->mouseButton = button; 187 d_data->mouseButton State = buttonState;197 d_data->mouseButtonModifiers = modifiers; 188 198 } 189 199 190 200 //! \sa setMouseButton() 191 201 void QwtMagnifier::getMouseButton( 192 int &button, int &buttonState) const202 Qt::MouseButton &button, Qt::KeyboardModifiers &modifiers ) const 193 203 { 194 204 button = d_data->mouseButton; 195 buttonState = d_data->mouseButtonState;205 modifiers = d_data->mouseButtonModifiers; 196 206 } 197 207 … … 229 239 \sa getZoomInKey(), setZoomOutKey() 230 240 */ 231 void QwtMagnifier::setZoomInKey( int key, int modifiers ) 241 void QwtMagnifier::setZoomInKey( int key, 242 Qt::KeyboardModifiers modifiers ) 232 243 { 233 244 d_data->zoomInKey = key; … … 235 246 } 236 247 237 //! \sa setZoomInKey() 238 void QwtMagnifier::getZoomInKey( int &key, int &modifiers ) const 248 /*! 249 \brief Retrieve the settings of the zoom in key 250 251 \param key Key code, see Qt::Key 252 \param modifiers Keyboard modifiers 253 254 \sa setZoomInKey() 255 */ 256 void QwtMagnifier::getZoomInKey( int &key, 257 Qt::KeyboardModifiers &modifiers ) const 239 258 { 240 259 key = d_data->zoomInKey; … … 250 269 \sa getZoomOutKey(), setZoomOutKey() 251 270 */ 252 void QwtMagnifier::setZoomOutKey( int key, int modifiers ) 271 void QwtMagnifier::setZoomOutKey( int key, 272 Qt::KeyboardModifiers modifiers ) 253 273 { 254 274 d_data->zoomOutKey = key; … … 256 276 } 257 277 258 //! \sa setZoomOutKey() 259 void QwtMagnifier::getZoomOutKey( int &key, int &modifiers ) const 278 /*! 279 \brief Retrieve the settings of the zoom out key 280 281 \param key Key code, see Qt::Key 282 \param modifiers Keyboard modifiers 283 284 \sa setZoomOutKey() 285 */ 286 void QwtMagnifier::getZoomOutKey( int &key, 287 Qt::KeyboardModifiers &modifiers ) const 260 288 { 261 289 key = d_data->zoomOutKey; … … 266 294 \brief Event filter 267 295 268 When isEnabled() the mouse events of the observed widget are filtered. 296 When isEnabled() is true, the mouse events of the 297 observed widget are filtered. 269 298 270 299 \param object Object to be filtered 271 300 \param event Event 301 302 \return Forwarded to QObject::eventFilter() 272 303 273 304 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), … … 283 314 case QEvent::MouseButtonPress: 284 315 { 285 widgetMousePressEvent( ( QMouseEvent * )event);316 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) ); 286 317 break; 287 318 } 288 319 case QEvent::MouseMove: 289 320 { 290 widgetMouseMoveEvent( ( QMouseEvent * )event);321 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) ); 291 322 break; 292 323 } 293 324 case QEvent::MouseButtonRelease: 294 325 { 295 widgetMouseReleaseEvent( ( QMouseEvent * )event);326 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) ); 296 327 break; 297 328 } 298 329 case QEvent::Wheel: 299 330 { 300 widgetWheelEvent( ( QWheelEvent * )event);331 widgetWheelEvent( static_cast<QWheelEvent *>( event ) ); 301 332 break; 302 333 } 303 334 case QEvent::KeyPress: 304 335 { 305 widgetKeyPressEvent( ( QKeyEvent * )event);336 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) ); 306 337 break; 307 338 } 308 339 case QEvent::KeyRelease: 309 340 { 310 widgetKeyReleaseEvent( ( QKeyEvent * )event);341 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) ); 311 342 break; 312 343 } … … 325 356 void QwtMagnifier::widgetMousePressEvent( QMouseEvent *mouseEvent ) 326 357 { 327 if ( ( mouseEvent->button() != d_data->mouseButton) 328 || parentWidget() == NULL ) 329 { 358 if ( parentWidget() == NULL ) 330 359 return; 331 } 332 333 if ( ( mouseEvent->modifiers() & Qt::KeyboardModifierMask ) != 334 ( int )( d_data->mouseButtonState & Qt::KeyboardModifierMask ) ) 360 361 if ( ( mouseEvent->button() != d_data->mouseButton ) || 362 ( mouseEvent->modifiers() != d_data->mouseButtonModifiers ) ) 335 363 { 336 364 return; … … 338 366 339 367 d_data->hasMouseTracking = parentWidget()->hasMouseTracking(); 368 340 369 parentWidget()->setMouseTracking( true ); 341 370 d_data->mousePos = mouseEvent->pos(); … … 393 422 void QwtMagnifier::widgetWheelEvent( QWheelEvent *wheelEvent ) 394 423 { 395 if ( ( wheelEvent->modifiers() & Qt::KeyboardModifierMask ) != 396 ( int )( d_data->wheelButtonState & Qt::KeyboardModifierMask ) ) 424 if ( wheelEvent->modifiers() != d_data->wheelModifiers ) 397 425 { 398 426 return; … … 411 439 */ 412 440 double f = qPow( d_data->wheelFactor, 413 qAbs( wheelEvent->delta() / 120 ) );441 qAbs( wheelEvent->delta() / 120.0 ) ); 414 442 415 443 if ( wheelEvent->delta() > 0 ) … … 428 456 void QwtMagnifier::widgetKeyPressEvent( QKeyEvent *keyEvent ) 429 457 { 430 const int key = keyEvent->key(); 431 const int state = keyEvent->modifiers(); 432 433 if ( key == d_data->zoomInKey && 434 state == d_data->zoomInKeyModifiers ) 458 if ( keyEvent->key() == d_data->zoomInKey && 459 keyEvent->modifiers() == d_data->zoomInKeyModifiers ) 435 460 { 436 461 rescale( d_data->keyFactor ); 437 462 } 438 else if ( key == d_data->zoomOutKey &&439 state== d_data->zoomOutKeyModifiers )463 else if ( keyEvent->key() == d_data->zoomOutKey && 464 keyEvent->modifiers() == d_data->zoomOutKeyModifiers ) 440 465 { 441 466 rescale( 1.0 / d_data->keyFactor ); … … 457 482 QWidget *QwtMagnifier::parentWidget() 458 483 { 459 if ( parent()->inherits( "QWidget" ) ) 460 return ( QWidget * )parent(); 461 462 return NULL; 484 return qobject_cast<QWidget *>( parent() ); 463 485 } 464 486 … … 466 488 const QWidget *QwtMagnifier::parentWidget() const 467 489 { 468 if ( parent()->inherits( "QWidget" ) ) 469 return ( const QWidget * )parent(); 470 471 return NULL; 472 } 473 490 return qobject_cast<const QWidget *>( parent() ); 491 } 492 -
trunk/BNC/qwt/qwt_magnifier.h
r4271 r8127 43 43 double mouseFactor() const; 44 44 45 void setMouseButton( int button, int buttonState = Qt::NoButton);46 void getMouseButton( int &button, int &buttonState) const;45 void setMouseButton( Qt::MouseButton, Qt::KeyboardModifiers = Qt::NoModifier ); 46 void getMouseButton( Qt::MouseButton &, Qt::KeyboardModifiers & ) const; 47 47 48 48 // mouse wheel … … 50 50 double wheelFactor() const; 51 51 52 void setWheel ButtonState( int buttonState);53 int wheelButtonState() const;52 void setWheelModifiers( Qt::KeyboardModifiers ); 53 Qt::KeyboardModifiers wheelModifiers() const; 54 54 55 55 // keyboard … … 57 57 double keyFactor() const; 58 58 59 void setZoomInKey( int key, int modifiers);60 void getZoomInKey( int &key, int &modifiers) const;59 void setZoomInKey( int key, Qt::KeyboardModifiers = Qt::NoModifier ); 60 void getZoomInKey( int &key, Qt::KeyboardModifiers & ) const; 61 61 62 void setZoomOutKey( int key, int modifiers);63 void getZoomOutKey( int &key, int &modifiers) const;62 void setZoomOutKey( int key, Qt::KeyboardModifiers = Qt::NoModifier ); 63 void getZoomOutKey( int &key, Qt::KeyboardModifiers & ) const; 64 64 65 65 virtual bool eventFilter( QObject *, QEvent * ); -
trunk/BNC/qwt/qwt_math.cpp
r4271 r8127 44 44 return rv; 45 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 */ 52 double qwtNormalizeRadians( double radians ) 53 { 54 double a = ::fmod( radians, 2.0 * M_PI ); 55 if ( a < 0.0 ) 56 a += 2.0 * M_PI; 57 58 return a; 59 60 } 61 62 /*! 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 */ 67 double qwtNormalizeDegrees( double degrees ) 68 { 69 double a = ::fmod( degrees, 360.0 ); 70 if ( a < 0.0 ) 71 a += 360.0; 72 73 return a; 74 } -
trunk/BNC/qwt/qwt_math.h
r4271 r8127 24 24 #endif 25 25 26 #include <qpoint.h>27 26 #include <qmath.h> 28 27 #include "qwt_global.h" 29 28 30 #ifndef LOG10_2 31 #define LOG10_2 0.30102999566398119802 /* log10(2) */ 32 #endif 33 34 #ifndef LOG10_3 35 #define LOG10_3 0.47712125471966243540 /* log10(3) */ 36 #endif 37 38 #ifndef LOG10_5 39 #define LOG10_5 0.69897000433601885749 /* log10(5) */ 40 #endif 41 42 #ifndef M_2PI 43 #define M_2PI 6.28318530717958623200 /* 2 pi */ 29 #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) 44 33 #endif 45 34 46 35 #ifndef LOG_MIN 47 //! Mini num value for logarithmic scales36 //! Minimum value for logarithmic scales 48 37 #define LOG_MIN 1.0e-100 49 38 #endif … … 54 43 #endif 55 44 56 #ifndef M_E57 #define M_E 2.7182818284590452354 /* e */58 #endif59 60 #ifndef M_LOG2E61 #define M_LOG2E 1.4426950408889634074 /* log_2 e */62 #endif63 64 #ifndef M_LOG10E65 #define M_LOG10E 0.43429448190325182765 /* log_10 e */66 #endif67 68 #ifndef M_LN269 #define M_LN2 0.69314718055994530942 /* log_e 2 */70 #endif71 72 #ifndef M_LN1073 #define M_LN10 2.30258509299404568402 /* log_e 10 */74 #endif75 76 #ifndef M_PI77 #define M_PI 3.14159265358979323846 /* pi */78 #endif79 80 #ifndef M_PI_281 #define M_PI_2 1.57079632679489661923 /* pi/2 */82 #endif83 84 #ifndef M_PI_485 #define M_PI_4 0.78539816339744830962 /* pi/4 */86 #endif87 88 #ifndef M_1_PI89 #define M_1_PI 0.31830988618379067154 /* 1/pi */90 #endif91 92 #ifndef M_2_PI93 #define M_2_PI 0.63661977236758134308 /* 2/pi */94 #endif95 96 #ifndef M_2_SQRTPI97 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */98 #endif99 100 #ifndef M_SQRT2101 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */102 #endif103 104 #ifndef M_SQRT1_2105 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */106 #endif107 108 45 QWT_EXPORT double qwtGetMin( const double *array, int size ); 109 46 QWT_EXPORT double qwtGetMax( const double *array, int size ); 47 48 QWT_EXPORT double qwtNormalizeRadians( double radians ); 49 QWT_EXPORT double qwtNormalizeDegrees( double degrees ); 110 50 111 51 /*! … … 162 102 } 163 103 164 //! Like qRound, but without converting the result to an int 165 inline double qwtRoundF(double d) 166 { 167 return ::floor( d + 0.5 ); 104 //! Approximation of arc tangent ( error below 0,005 radians ) 105 inline double qwtFastAtan( double x ) 106 { 107 if ( x < -1.0 ) 108 return -M_PI_2 - x / ( x * x + 0.28 ); 109 110 if ( x > 1.0 ) 111 return M_PI_2 - x / ( x * x + 0.28 ); 112 113 return x / ( 1.0 + x * x * 0.28 ); 168 114 } 169 115 170 //! Like qFloor, but without converting the result to an int 171 inline double qwtFloorF(double d) 172 { 173 return ::floor( d ); 116 //! Approximation of arc tangent ( error below 0,005 radians ) 117 inline double qwtFastAtan2( double y, double x ) 118 { 119 if ( x > 0 ) 120 return qwtFastAtan( y / x ); 121 122 if ( x < 0 ) 123 { 124 const double d = qwtFastAtan( y / x ); 125 return ( y >= 0 ) ? d + M_PI : d - M_PI; 126 } 127 128 if ( y < 0.0 ) 129 return -M_PI_2; 130 131 if ( y > 0.0 ) 132 return M_PI_2; 133 134 return 0.0; 174 135 } 175 136 176 //! Like qCeil, but without converting the result to an int 177 inline double qwtCeilF(double d) 178 { 179 return ::ceil( d ); 137 //! Translate degrees into radians 138 inline double qwtRadians( double degrees ) 139 { 140 return degrees * M_PI / 180.0; 141 } 142 143 //! Translate radians into degrees 144 inline double qwtDegrees( double degrees ) 145 { 146 return degrees * 180.0 / M_PI; 180 147 } 181 148 -
trunk/BNC/qwt/qwt_matrix_raster_data.cpp
r4271 r8127 21 21 } 22 22 23 inline double value( size_t row, size_t col) const23 inline double value(int row, int col) const 24 24 { 25 25 return values.data()[ row * numColumns + col ]; … … 29 29 30 30 QVector<double> values; 31 size_t numColumns;32 size_t numRows;31 int numColumns; 32 int numRows; 33 33 34 34 double dx; … … 55 55 \sa resampleMode(), value() 56 56 */ 57 void QwtMatrixRasterData::setResampleMode( ResampleMode mode)57 void QwtMatrixRasterData::setResampleMode( ResampleMode mode ) 58 58 { 59 59 d_data->resampleMode = mode; … … 106 106 */ 107 107 void QwtMatrixRasterData::setValueMatrix( 108 const QVector<double> &values, size_t numColumns )108 const QVector<double> &values, int numColumns ) 109 109 { 110 110 d_data->values = values; 111 d_data->numColumns = numColumns;111 d_data->numColumns = qMax( numColumns, 0 ); 112 112 update(); 113 113 } … … 123 123 124 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 */ 133 void QwtMatrixRasterData::setValue( int row, int col, double value ) 134 { 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; 140 } 141 } 142 143 /*! 125 144 \return Number of columns of the value matrix 126 145 \sa valueMatrix(), numRows(), setValueMatrix() 127 146 */ 128 size_t QwtMatrixRasterData::numColumns() const147 int QwtMatrixRasterData::numColumns() const 129 148 { 130 149 return d_data->numColumns; … … 135 154 \sa valueMatrix(), numColumns(), setValueMatrix() 136 155 */ 137 size_t QwtMatrixRasterData::numRows() const156 int QwtMatrixRasterData::numRows() const 138 157 { 139 158 return d_data->numRows; … … 141 160 142 161 /*! 143 \brief Pixel hint 162 \brief Calculate the pixel hint 163 164 pixelHint() returns the geometry of a pixel, that can be used 165 to calculate the resolution and alignment of the plot item, that is 166 representing the data. 144 167 145 168 - NearestNeighbour\n … … 151 174 to render in target device ( f.e. screen ) resolution. 152 175 176 \param area Requested area, ignored 177 \return Calculated hint 178 153 179 \sa ResampleMode, setMatrix(), setInterval() 154 180 */ 155 QRectF QwtMatrixRasterData::pixelHint( const QRectF & ) const 156 { 181 QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const 182 { 183 Q_UNUSED( area ) 184 157 185 QRectF rect; 158 186 if ( d_data->resampleMode == NearestNeighbour ) … … 199 227 if ( col1 < 0 ) 200 228 col1 = col2; 201 else if ( col2 >= (int)d_data->numColumns)229 else if ( col2 >= static_cast<int>( d_data->numColumns ) ) 202 230 col2 = col1; 203 231 204 232 if ( row1 < 0 ) 205 233 row1 = row2; 206 else if ( row2 >= (int)d_data->numRows)234 else if ( row2 >= static_cast<int>( d_data->numRows ) ) 207 235 row2 = row1; 208 236 … … 230 258 default: 231 259 { 232 uint row = uint( (y - yInterval.minValue() ) / d_data->dy );233 uint col = uint( (x - xInterval.minValue() ) / d_data->dx );260 int row = int( (y - yInterval.minValue() ) / d_data->dy ); 261 int col = int( (x - xInterval.minValue() ) / d_data->dx ); 234 262 235 263 // In case of intervals, where the maximum is included -
trunk/BNC/qwt/qwt_matrix_raster_data.h
r4271 r8127 52 52 53 53 virtual void setInterval( Qt::Axis, const QwtInterval & ); 54 void setValueMatrix( const QVector<double> &values, size_t numColumns ); 55 54 55 void setValueMatrix( const QVector<double> &values, int numColumns ); 56 56 const QVector<double> valueMatrix() const; 57 size_t numColumns() const; 58 size_t numRows() const; 57 58 void setValue( int row, int col, double value ); 59 60 int numColumns() const; 61 int numRows() const; 59 62 60 63 virtual QRectF pixelHint( const QRectF & ) const; -
trunk/BNC/qwt/qwt_null_paintdevice.cpp
r4271 r8127 16 16 public: 17 17 PrivateData(): 18 size( 0, 0)19 { 20 } 21 22 Q Size size;18 mode( QwtNullPaintDevice::NormalMode ) 19 { 20 } 21 22 QwtNullPaintDevice::Mode mode; 23 23 }; 24 24 … … 26 26 { 27 27 public: 28 PaintEngine( QPaintEngine::PaintEngineFeatures);28 PaintEngine(); 29 29 30 30 virtual bool begin( QPaintDevice * ); … … 55 55 56 56 virtual void drawTextItem(const QPointF &, const QTextItem &); 57 57 58 virtual void drawTiledPixmap(const QRectF &, 58 59 const QPixmap &, const QPointF &s); 60 59 61 virtual void drawImage(const QRectF &, 60 62 const QImage &, const QRectF &, Qt::ImageConversionFlags ); 61 63 62 64 private: 63 QwtNullPaintDevice * d_device;65 QwtNullPaintDevice *nullDevice(); 64 66 }; 65 67 66 QwtNullPaintDevice::PaintEngine::PaintEngine( 67 QPaintEngine::PaintEngineFeatures features ): 68 QPaintEngine( features ), 69 d_device(NULL) 70 { 71 } 72 73 bool QwtNullPaintDevice::PaintEngine::begin( 74 QPaintDevice *device ) 75 { 76 d_device = static_cast<QwtNullPaintDevice *>( device ); 68 QwtNullPaintDevice::PaintEngine::PaintEngine(): 69 QPaintEngine( QPaintEngine::AllFeatures ) 70 { 71 } 72 73 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * ) 74 { 75 setActive( true ); 77 76 return true; 78 77 } … … 80 79 bool QwtNullPaintDevice::PaintEngine::end() 81 80 { 82 d_device = NULL;81 setActive( false ); 83 82 return true; 84 83 } 85 84 86 QPaintEngine::Type 87 QwtNullPaintDevice::PaintEngine::type () const 85 QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const 88 86 { 89 87 return QPaintEngine::User; … … 93 91 const QRect *rects, int rectCount) 94 92 { 95 if ( d_device ) 96 d_device->drawRects( rects, rectCount ); 93 QwtNullPaintDevice *device = nullDevice(); 94 if ( device == NULL ) 95 return; 96 97 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 98 { 99 QPaintEngine::drawRects( rects, rectCount ); 100 return; 101 } 102 103 device->drawRects( rects, rectCount ); 97 104 } 98 105 … … 100 107 const QRectF *rects, int rectCount) 101 108 { 102 if ( d_device ) 103 d_device->drawRects( rects, rectCount ); 109 QwtNullPaintDevice *device = nullDevice(); 110 if ( device == NULL ) 111 return; 112 113 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 114 { 115 QPaintEngine::drawRects( rects, rectCount ); 116 return; 117 } 118 119 device->drawRects( rects, rectCount ); 104 120 } 105 121 … … 107 123 const QLine *lines, int lineCount) 108 124 { 109 if ( d_device ) 110 d_device->drawLines( lines, lineCount ); 125 QwtNullPaintDevice *device = nullDevice(); 126 if ( device == NULL ) 127 return; 128 129 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 130 { 131 QPaintEngine::drawLines( lines, lineCount ); 132 return; 133 } 134 135 device->drawLines( lines, lineCount ); 111 136 } 112 137 … … 114 139 const QLineF *lines, int lineCount) 115 140 { 116 if ( d_device ) 117 d_device->drawLines( lines, lineCount ); 141 QwtNullPaintDevice *device = nullDevice(); 142 if ( device == NULL ) 143 return; 144 145 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 146 { 147 QPaintEngine::drawLines( lines, lineCount ); 148 return; 149 } 150 151 device->drawLines( lines, lineCount ); 118 152 } 119 153 … … 121 155 const QRectF &rect) 122 156 { 123 if ( d_device ) 124 d_device->drawEllipse( rect ); 157 QwtNullPaintDevice *device = nullDevice(); 158 if ( device == NULL ) 159 return; 160 161 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 162 { 163 QPaintEngine::drawEllipse( rect ); 164 return; 165 } 166 167 device->drawEllipse( rect ); 125 168 } 126 169 … … 128 171 const QRect &rect) 129 172 { 130 if ( d_device ) 131 d_device->drawEllipse( rect ); 173 QwtNullPaintDevice *device = nullDevice(); 174 if ( device == NULL ) 175 return; 176 177 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 178 { 179 QPaintEngine::drawEllipse( rect ); 180 return; 181 } 182 183 device->drawEllipse( rect ); 132 184 } 133 185 … … 136 188 const QPainterPath &path) 137 189 { 138 if ( d_device ) 139 d_device->drawPath( path ); 190 QwtNullPaintDevice *device = nullDevice(); 191 if ( device == NULL ) 192 return; 193 194 device->drawPath( path ); 140 195 } 141 196 … … 143 198 const QPointF *points, int pointCount) 144 199 { 145 if ( d_device ) 146 d_device->drawPoints( points, pointCount ); 200 QwtNullPaintDevice *device = nullDevice(); 201 if ( device == NULL ) 202 return; 203 204 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 205 { 206 QPaintEngine::drawPoints( points, pointCount ); 207 return; 208 } 209 210 device->drawPoints( points, pointCount ); 147 211 } 148 212 … … 150 214 const QPoint *points, int pointCount) 151 215 { 152 if ( d_device ) 153 d_device->drawPoints( points, pointCount ); 216 QwtNullPaintDevice *device = nullDevice(); 217 if ( device == NULL ) 218 return; 219 220 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 221 { 222 QPaintEngine::drawPoints( points, pointCount ); 223 return; 224 } 225 226 device->drawPoints( points, pointCount ); 154 227 } 155 228 … … 157 230 const QPointF *points, int pointCount, PolygonDrawMode mode) 158 231 { 159 if ( d_device ) 160 d_device->drawPolygon( points, pointCount, mode ); 232 QwtNullPaintDevice *device = nullDevice(); 233 if ( device == NULL ) 234 return; 235 236 if ( device->mode() == QwtNullPaintDevice::PathMode ) 237 { 238 QPainterPath path; 239 240 if ( pointCount > 0 ) 241 { 242 path.moveTo( points[0] ); 243 for ( int i = 1; i < pointCount; i++ ) 244 path.lineTo( points[i] ); 245 246 if ( mode != PolylineMode ) 247 path.closeSubpath(); 248 } 249 250 device->drawPath( path ); 251 return; 252 } 253 254 device->drawPolygon( points, pointCount, mode ); 161 255 } 162 256 … … 164 258 const QPoint *points, int pointCount, PolygonDrawMode mode) 165 259 { 166 if ( d_device ) 167 d_device->drawPolygon( points, pointCount, mode ); 260 QwtNullPaintDevice *device = nullDevice(); 261 if ( device == NULL ) 262 return; 263 264 if ( device->mode() == QwtNullPaintDevice::PathMode ) 265 { 266 QPainterPath path; 267 268 if ( pointCount > 0 ) 269 { 270 path.moveTo( points[0] ); 271 for ( int i = 1; i < pointCount; i++ ) 272 path.lineTo( points[i] ); 273 274 if ( mode != PolylineMode ) 275 path.closeSubpath(); 276 } 277 278 device->drawPath( path ); 279 return; 280 } 281 282 device->drawPolygon( points, pointCount, mode ); 168 283 } 169 284 … … 171 286 const QRectF &rect, const QPixmap &pm, const QRectF &subRect ) 172 287 { 173 if ( d_device ) 174 d_device->drawPixmap( rect, pm, subRect ); 288 QwtNullPaintDevice *device = nullDevice(); 289 if ( device == NULL ) 290 return; 291 292 device->drawPixmap( rect, pm, subRect ); 175 293 } 176 294 … … 178 296 const QPointF &pos, const QTextItem &textItem) 179 297 { 180 if ( d_device ) 181 d_device->drawTextItem( pos, textItem ); 298 QwtNullPaintDevice *device = nullDevice(); 299 if ( device == NULL ) 300 return; 301 302 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 303 { 304 QPaintEngine::drawTextItem( pos, textItem ); 305 return; 306 } 307 308 device->drawTextItem( pos, textItem ); 182 309 } 183 310 … … 186 313 const QPointF &subRect) 187 314 { 188 if ( d_device ) 189 d_device->drawTiledPixmap( rect, pixmap, subRect ); 315 QwtNullPaintDevice *device = nullDevice(); 316 if ( device == NULL ) 317 return; 318 319 if ( device->mode() != QwtNullPaintDevice::NormalMode ) 320 { 321 QPaintEngine::drawTiledPixmap( rect, pixmap, subRect ); 322 return; 323 } 324 325 device->drawTiledPixmap( rect, pixmap, subRect ); 190 326 } 191 327 … … 194 330 const QRectF &subRect, Qt::ImageConversionFlags flags) 195 331 { 196 if ( d_device ) 197 d_device->drawImage( rect, image, subRect, flags ); 332 QwtNullPaintDevice *device = nullDevice(); 333 if ( device == NULL ) 334 return; 335 336 device->drawImage( rect, image, subRect, flags ); 198 337 } 199 338 … … 201 340 const QPaintEngineState &state) 202 341 { 203 if ( d_device ) 204 d_device->updateState( state ); 342 QwtNullPaintDevice *device = nullDevice(); 343 if ( device == NULL ) 344 return; 345 346 device->updateState( state ); 347 } 348 349 inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice() 350 { 351 if ( !isActive() ) 352 return NULL; 353 354 return static_cast<QwtNullPaintDevice *>( paintDevice() ); 205 355 } 206 356 207 357 //! Constructor 208 QwtNullPaintDevice::QwtNullPaintDevice( 209 QPaintEngine::PaintEngineFeatures features ) 210 { 211 init( features ); 212 } 213 214 //! Constructor 215 QwtNullPaintDevice::QwtNullPaintDevice( const QSize &size, 216 QPaintEngine::PaintEngineFeatures features ) 217 { 218 init( features ); 219 d_data->size = size; 220 } 221 222 void QwtNullPaintDevice::init( 223 QPaintEngine::PaintEngineFeatures features ) 224 { 225 d_engine = new PaintEngine( features ); 358 QwtNullPaintDevice::QwtNullPaintDevice(): 359 d_engine( NULL ) 360 { 226 361 d_data = new PrivateData; 227 362 } … … 235 370 236 371 /*! 237 Set the size of the paint device 238 239 \param size Size 240 \sa size() 372 Set the render mode 373 374 \param mode New mode 375 \sa mode() 376 */ 377 void QwtNullPaintDevice::setMode( Mode mode ) 378 { 379 d_data->mode = mode; 380 } 381 382 /*! 383 \return Render mode 384 \sa setMode() 241 385 */ 242 void QwtNullPaintDevice::setSize( const QSize & size ) 243 { 244 d_data->size = size; 245 } 246 247 /*! 248 \return Size of the paint device 249 \sa setSize() 250 */ 251 QSize QwtNullPaintDevice::size() const 252 { 253 return d_data->size; 386 QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const 387 { 388 return d_data->mode; 254 389 } 255 390 … … 257 392 QPaintEngine *QwtNullPaintDevice::paintEngine() const 258 393 { 394 if ( d_engine == NULL ) 395 { 396 QwtNullPaintDevice *that = 397 const_cast< QwtNullPaintDevice * >( this ); 398 399 that->d_engine = new PaintEngine(); 400 } 401 259 402 return d_engine; 260 403 } … … 262 405 /*! 263 406 See QPaintDevice::metric() 264 \sa setSize() 407 408 \param deviceMetric Type of metric 409 \return Metric information for the given paint device metric. 410 411 \sa sizeMetrics() 265 412 */ 266 int QwtNullPaintDevice::metric( PaintDeviceMetric metric ) const 267 { 268 static QPixmap pm; 269 413 int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const 414 { 270 415 int value; 271 416 272 switch ( metric )417 switch ( deviceMetric ) 273 418 { 274 419 case PdmWidth: 275 value = qMax( d_data->size.width(), 0 ); 276 break; 420 { 421 value = sizeMetrics().width(); 422 break; 423 } 277 424 case PdmHeight: 278 value = qMax( d_data->size.height(), 0 ); 279 break; 425 { 426 value = sizeMetrics().height(); 427 break; 428 } 280 429 case PdmNumColors: 281 value = 16777216; 282 break; 430 { 431 value = 0xffffffff; 432 break; 433 } 283 434 case PdmDepth: 284 value = 24; 285 break; 435 { 436 value = 32; 437 break; 438 } 286 439 case PdmPhysicalDpiX: 440 case PdmPhysicalDpiY: 287 441 case PdmDpiY: 288 case PdmPhysicalDpiY: 442 case PdmDpiX: 443 { 444 value = 72; 445 break; 446 } 289 447 case PdmWidthMM: 448 { 449 value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) ); 450 break; 451 } 290 452 case PdmHeightMM: 291 case PdmDpiX: 453 { 454 value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) ); 455 break; 456 } 292 457 default: 293 458 value = 0; -
trunk/BNC/qwt/qwt_null_paintdevice.h
r4271 r8127 19 19 20 20 Sometimes important layout/rendering geometries are not 21 available or chang able from the public Qt class interface.21 available or changeable from the public Qt class interface. 22 22 ( f.e hidden in the style implementation ). 23 23 24 24 QwtNullPaintDevice can be used to manipulate or filter out 25 th ese informationsby analyzing the stream of paint primitives.25 this information by analyzing the stream of paint primitives. 26 26 27 27 F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify … … 32 32 { 33 33 public: 34 QwtNullPaintDevice( QPaintEngine::PaintEngineFeatures ); 35 QwtNullPaintDevice( const QSize &size, 36 QPaintEngine::PaintEngineFeatures ); 34 /*! 35 \brief Render mode 37 36 37 \sa setMode(), mode() 38 */ 39 enum Mode 40 { 41 /*! 42 All vector graphic primitives are painted by 43 the corresponding draw methods 44 */ 45 NormalMode, 46 47 /*! 48 Vector graphic primitives ( beside polygons ) are mapped to a QPainterPath 49 and are painted by drawPath. In PathMode mode 50 only a few draw methods are called: 51 52 - drawPath() 53 - drawPixmap() 54 - drawImage() 55 - drawPolygon() 56 */ 57 PolygonPathMode, 58 59 /*! 60 Vector graphic primitives are mapped to a QPainterPath 61 and are painted by drawPath. In PathMode mode 62 only a few draw methods are called: 63 64 - drawPath() 65 - drawPixmap() 66 - drawImage() 67 */ 68 PathMode 69 }; 70 71 QwtNullPaintDevice(); 38 72 virtual ~QwtNullPaintDevice(); 39 73 40 void set Size( const QSize &);41 QSize size() const;74 void setMode( Mode ); 75 Mode mode() const; 42 76 43 77 virtual QPaintEngine *paintEngine() const; 78 44 79 virtual int metric( PaintDeviceMetric metric ) const; 45 80 … … 77 112 virtual void updateState( const QPaintEngineState &state ); 78 113 114 protected: 115 //! \return Size needed to implement metric() 116 virtual QSize sizeMetrics() const = 0; 117 79 118 private: 80 void init( QPaintEngine::PaintEngineFeatures );81 82 119 class PaintEngine; 83 120 PaintEngine *d_engine; -
trunk/BNC/qwt/qwt_painter.cpp
r4271 r8127 29 29 #include <qdesktopwidget.h> 30 30 31 #if QT_VERSION >= 0x050000 32 #include <qwindow.h> 33 #endif 34 35 #if QT_VERSION < 0x050000 36 37 #ifdef Q_WS_X11 38 #include <qx11info_x11.h> 39 #endif 40 41 #endif 42 31 43 bool QwtPainter::d_polylineSplitting = true; 32 44 bool QwtPainter::d_roundingAlignment = true; 33 45 34 static inline bool isClippingNeeded( const QPainter *painter, QRectF &clipRect ) 46 static inline bool qwtIsClippingNeeded( 47 const QPainter *painter, QRectF &clipRect ) 35 48 { 36 49 bool doClipping = false; … … 50 63 } 51 64 52 static inline void drawPolyline( QPainter *painter, 53 const QPointF *points, int pointCount, bool polylineSplitting ) 65 template <class T> 66 static inline void qwtDrawPolyline( QPainter *painter, 67 const T *points, int pointCount, bool polylineSplitting ) 54 68 { 55 69 bool doSplit = false; … … 71 85 if ( doSplit ) 72 86 { 73 const int splitSize = 20; 87 const int splitSize = 6; 88 74 89 for ( int i = 0; i < pointCount; i += splitSize ) 75 90 { … … 79 94 } 80 95 else 96 { 81 97 painter->drawPolyline( points, pointCount ); 82 } 83 84 static inline void unscaleFont( QPainter *painter ) 98 } 99 } 100 101 static inline QSize qwtScreenResolution() 102 { 103 static QSize screenResolution; 104 if ( !screenResolution.isValid() ) 105 { 106 QDesktopWidget *desktop = QApplication::desktop(); 107 if ( desktop ) 108 { 109 screenResolution.setWidth( desktop->logicalDpiX() ); 110 screenResolution.setHeight( desktop->logicalDpiY() ); 111 } 112 } 113 114 return screenResolution; 115 } 116 117 static inline void qwtUnscaleFont( QPainter *painter ) 85 118 { 86 119 if ( painter->font().pixelSize() >= 0 ) 87 120 return; 88 121 89 static QSize screenResolution; 90 if ( !screenResolution.isValid() ) 91 { 92 QDesktopWidget *desktop = QApplication::desktop(); 93 if ( desktop ) 94 { 95 screenResolution.setWidth( desktop->logicalDpiX() ); 96 screenResolution.setHeight( desktop->logicalDpiY() ); 97 } 98 } 122 const QSize screenResolution = qwtScreenResolution(); 99 123 100 124 const QPaintDevice *pd = painter->device(); … … 107 131 painter->setFont( pixelFont ); 108 132 } 133 } 134 135 /*! 136 Check is the application is running with the X11 graphics system 137 that has some special capabilities that can be used for incremental 138 painting to a widget. 139 140 \return True, when the graphics system is X11 141 */ 142 bool QwtPainter::isX11GraphicsSystem() 143 { 144 static int onX11 = -1; 145 if ( onX11 < 0 ) 146 { 147 QPixmap pm( 1, 1 ); 148 QPainter painter( &pm ); 149 150 onX11 = ( painter.paintEngine()->type() == QPaintEngine::X11 ) ? 1 : 0; 151 } 152 153 return onX11 == 1; 109 154 } 110 155 … … 114 159 beside QPaintEngine::Pdf and QPaintEngine::SVG. 115 160 161 If we have an integer based paint engine it is also 162 checked if the painter has a transformation matrix, 163 that rotates or scales. 164 116 165 \param painter Painter 117 \return true, when the paint engineis aligning166 \return true, when the painter is aligning 118 167 119 168 \sa setRoundingAlignment() … … 131 180 default:; 132 181 } 182 183 const QTransform tr = painter->transform(); 184 if ( tr.isRotating() || tr.isScaling() ) 185 { 186 // we might have to check translations too 187 return false; 188 } 133 189 } 134 190 … … 139 195 Enable whether coordinates should be rounded, before they are painted 140 196 to a paint engine that floors to integer values. For other paint engines 141 this ( Pdf, SVG ),this flag has no effect.142 QwtPainter stores this flag only, the rounding its self is done in197 ( PDF, SVG ) this flag has no effect. 198 QwtPainter stores this flag only, the rounding itself is done in 143 199 the painting code ( f.e the plot items ). 144 200 … … 155 211 \brief En/Disable line splitting for the raster paint engine 156 212 157 The raster paint engine paints polylines of many points 158 much faster when they are splitted in smaller chunks. 213 In some Qt versions the raster paint engine paints polylines of many points 214 much faster when they are split in smaller chunks: f.e all supported Qt versions 215 >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2. 216 217 The default setting is true. 159 218 160 219 \sa polylineSplitting() … … 183 242 184 243 QRectF clipRect; 185 const bool deviceClipping = isClippingNeeded( painter, clipRect );244 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 186 245 187 246 if ( deviceClipping ) … … 214 273 215 274 QRectF clipRect; 216 const bool deviceClipping = isClippingNeeded( painter, clipRect );275 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 217 276 218 277 /* 219 Performance of Qt4 is horrible for non trivial brushs. Without220 clipping expect minutes or hours for repainting large rect s278 Performance of Qt4 is horrible for a non trivial brush. Without 279 clipping expect minutes or hours for repainting large rectangles 221 280 (might result from zooming) 222 281 */ … … 232 291 QRectF r = rect; 233 292 if ( deviceClipping ) 234 r = r.intersect ( clipRect );293 r = r.intersected( clipRect ); 235 294 236 295 if ( r.isValid() ) … … 243 302 { 244 303 QRectF clipRect; 245 const bool deviceClipping = isClippingNeeded( painter, clipRect );304 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 246 305 if ( deviceClipping && !clipRect.contains( rect ) ) 247 306 return; … … 254 313 { 255 314 QRectF clipRect; 256 const bool deviceClipping = isClippingNeeded( painter, clipRect );315 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 257 316 258 317 if ( deviceClipping && !clipRect.contains( rect ) ) … … 274 333 { 275 334 QRectF clipRect; 276 const bool deviceClipping = isClippingNeeded( painter, clipRect );335 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 277 336 278 337 if ( deviceClipping && !clipRect.contains( pos ) ) … … 281 340 282 341 painter->save(); 283 unscaleFont( painter );342 qwtUnscaleFont( painter ); 284 343 painter->drawText( pos, text ); 285 344 painter->restore(); … … 299 358 { 300 359 painter->save(); 301 unscaleFont( painter );360 qwtUnscaleFont( painter ); 302 361 painter->drawText( rect, flags, text ); 303 362 painter->restore(); … … 321 380 painter->save(); 322 381 323 painter->setFont( txt->defaultFont() ); 324 unscaleFont( painter ); 382 QRectF unscaledRect = rect; 383 384 if ( painter->font().pixelSize() < 0 ) 385 { 386 const QSize res = qwtScreenResolution(); 387 388 const QPaintDevice *pd = painter->device(); 389 if ( pd->logicalDpiX() != res.width() || 390 pd->logicalDpiY() != res.height() ) 391 { 392 QTransform transform; 393 transform.scale( res.width() / double( pd->logicalDpiX() ), 394 res.height() / double( pd->logicalDpiY() )); 395 396 painter->setWorldTransform( transform, true ); 397 unscaledRect = transform.inverted().mapRect(rect); 398 } 399 } 325 400 326 401 txt->setDefaultFont( painter->font() ); 327 txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );402 txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) ); 328 403 329 404 QAbstractTextDocumentLayout* layout = txt->documentLayout(); 330 405 331 406 const double height = layout->documentSize().height(); 332 double y = rect.y();407 double y = unscaledRect.y(); 333 408 if ( flags & Qt::AlignBottom ) 334 y += ( rect.height() - height );409 y += ( unscaledRect.height() - height ); 335 410 else if ( flags & Qt::AlignVCenter ) 336 y += ( rect.height() - height ) / 2;411 y += ( unscaledRect.height() - height ) / 2; 337 412 338 413 QAbstractTextDocumentLayout::PaintContext context; 339 414 context.palette.setColor( QPalette::Text, painter->pen().color() ); 340 415 341 painter->translate( rect.x(), y );416 painter->translate( unscaledRect.x(), y ); 342 417 layout->draw( painter, context ); 343 418 … … 354 429 { 355 430 QRectF clipRect; 356 const bool deviceClipping = isClippingNeeded( painter, clipRect );431 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 357 432 358 433 if ( deviceClipping && … … 373 448 { 374 449 QRectF clipRect; 375 const bool deviceClipping = isClippingNeeded( painter, clipRect );450 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 376 451 377 452 QPolygonF cpa = polygon; … … 386 461 { 387 462 QRectF clipRect; 388 const bool deviceClipping = isClippingNeeded( painter, clipRect );463 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 389 464 390 465 QPolygonF cpa = polygon; … … 392 467 cpa = QwtClipper::clipPolygonF( clipRect, cpa ); 393 468 394 ::drawPolyline( painter,469 qwtDrawPolyline<QPointF>( painter, 395 470 cpa.constData(), cpa.size(), d_polylineSplitting ); 396 471 } … … 401 476 { 402 477 QRectF clipRect; 403 const bool deviceClipping = isClippingNeeded( painter, clipRect );478 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 404 479 405 480 if ( deviceClipping ) 406 481 { 407 482 QPolygonF polygon( pointCount ); 408 qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) );483 ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) ); 409 484 410 485 polygon = QwtClipper::clipPolygonF( clipRect, polygon ); 411 ::drawPolyline( painter,486 qwtDrawPolyline<QPointF>( painter, 412 487 polygon.constData(), polygon.size(), d_polylineSplitting ); 413 488 } 414 489 else 415 ::drawPolyline( painter, points, pointCount, d_polylineSplitting ); 490 { 491 qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting ); 492 } 493 } 494 495 //! Wrapper for QPainter::drawPolygon() 496 void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon ) 497 { 498 QRectF clipRect; 499 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 500 501 QPolygon cpa = polygon; 502 if ( deviceClipping ) 503 cpa = QwtClipper::clipPolygon( clipRect, polygon ); 504 505 painter->drawPolygon( cpa ); 506 } 507 508 //! Wrapper for QPainter::drawPolyline() 509 void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon ) 510 { 511 QRectF clipRect; 512 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 513 514 QPolygon cpa = polygon; 515 if ( deviceClipping ) 516 cpa = QwtClipper::clipPolygon( clipRect, cpa ); 517 518 qwtDrawPolyline<QPoint>( painter, 519 cpa.constData(), cpa.size(), d_polylineSplitting ); 520 } 521 522 //! Wrapper for QPainter::drawPolyline() 523 void QwtPainter::drawPolyline( QPainter *painter, 524 const QPoint *points, int pointCount ) 525 { 526 QRectF clipRect; 527 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 528 529 if ( deviceClipping ) 530 { 531 QPolygon polygon( pointCount ); 532 ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) ); 533 534 polygon = QwtClipper::clipPolygon( clipRect, polygon ); 535 qwtDrawPolyline<QPoint>( painter, 536 polygon.constData(), polygon.size(), d_polylineSplitting ); 537 } 538 else 539 qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting ); 416 540 } 417 541 … … 420 544 { 421 545 QRectF clipRect; 422 const bool deviceClipping = isClippingNeeded( painter, clipRect );546 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 423 547 424 548 if ( deviceClipping && !clipRect.contains( pos ) ) … … 426 550 427 551 painter->drawPoint( pos ); 552 } 553 554 //! Wrapper for QPainter::drawPoint() 555 void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos ) 556 { 557 QRectF clipRect; 558 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 559 560 if ( deviceClipping ) 561 { 562 const int minX = qCeil( clipRect.left() ); 563 const int maxX = qFloor( clipRect.right() ); 564 const int minY = qCeil( clipRect.top() ); 565 const int maxY = qFloor( clipRect.bottom() ); 566 567 if ( pos.x() < minX || pos.x() > maxX 568 || pos.y() < minY || pos.y() > maxY ) 569 { 570 return; 571 } 572 } 573 574 painter->drawPoint( pos ); 575 } 576 577 //! Wrapper for QPainter::drawPoints() 578 void QwtPainter::drawPoints( QPainter *painter, 579 const QPoint *points, int pointCount ) 580 { 581 QRectF clipRect; 582 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 583 584 if ( deviceClipping ) 585 { 586 const int minX = qCeil( clipRect.left() ); 587 const int maxX = qFloor( clipRect.right() ); 588 const int minY = qCeil( clipRect.top() ); 589 const int maxY = qFloor( clipRect.bottom() ); 590 591 const QRect r( minX, minY, maxX - minX, maxY - minY ); 592 593 QPolygon clippedPolygon( pointCount ); 594 QPoint *clippedData = clippedPolygon.data(); 595 596 int numClippedPoints = 0; 597 for ( int i = 0; i < pointCount; i++ ) 598 { 599 if ( r.contains( points[i] ) ) 600 clippedData[ numClippedPoints++ ] = points[i]; 601 } 602 painter->drawPoints( clippedData, numClippedPoints ); 603 } 604 else 605 { 606 painter->drawPoints( points, pointCount ); 607 } 608 } 609 610 //! Wrapper for QPainter::drawPoints() 611 void QwtPainter::drawPoints( QPainter *painter, 612 const QPointF *points, int pointCount ) 613 { 614 QRectF clipRect; 615 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 616 617 if ( deviceClipping ) 618 { 619 QPolygonF clippedPolygon( pointCount ); 620 QPointF *clippedData = clippedPolygon.data(); 621 622 int numClippedPoints = 0; 623 for ( int i = 0; i < pointCount; i++ ) 624 { 625 if ( clipRect.contains( points[i] ) ) 626 clippedData[ numClippedPoints++ ] = points[i]; 627 } 628 painter->drawPoints( clippedData, numClippedPoints ); 629 } 630 else 631 { 632 painter->drawPoints( points, pointCount ); 633 } 428 634 } 429 635 … … 471 677 472 678 //! Draw a focus rectangle on a widget using its style. 473 void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget )679 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget ) 474 680 { 475 681 drawFocusRect( painter, widget, widget->rect() ); … … 477 683 478 684 //! Draw a focus rectangle on a widget using its style. 479 void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget,685 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget, 480 686 const QRect &rect ) 481 687 { … … 484 690 opt.rect = rect; 485 691 opt.state |= QStyle::State_HasFocus; 486 487 widget->style()->drawPrimitive( QStyle::PE_FrameFocusRect, 488 &opt, painter, widget ); 692 opt.backgroundColor = widget->palette().color( widget->backgroundRole() ); 693 694 widget->style()->drawPrimitive( 695 QStyle::PE_FrameFocusRect, &opt, painter, widget ); 489 696 } 490 697 491 698 /*! 492 Draw a frame with rounded borders 699 Draw a round frame 700 701 \param painter Painter 702 \param rect Frame rectangle 703 \param palette QPalette::WindowText is used for plain borders 704 QPalette::Dark and QPalette::Light for raised 705 or sunken borders 706 \param lineWidth Line width 707 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 708 */ 709 void QwtPainter::drawRoundFrame( QPainter *painter, 710 const QRectF &rect, const QPalette &palette, 711 int lineWidth, int frameStyle ) 712 { 713 enum Style 714 { 715 Plain, 716 Sunken, 717 Raised 718 }; 719 720 Style style = Plain; 721 if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken ) 722 style = Sunken; 723 else if ( (frameStyle & QFrame::Raised) == QFrame::Raised ) 724 style = Raised; 725 726 const double lw2 = 0.5 * lineWidth; 727 QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 ); 728 729 QBrush brush; 730 731 if ( style != Plain ) 732 { 733 QColor c1 = palette.color( QPalette::Light ); 734 QColor c2 = palette.color( QPalette::Dark ); 735 736 if ( style == Sunken ) 737 qSwap( c1, c2 ); 738 739 QLinearGradient gradient( r.topLeft(), r.bottomRight() ); 740 gradient.setColorAt( 0.0, c1 ); 741 #if 0 742 gradient.setColorAt( 0.3, c1 ); 743 gradient.setColorAt( 0.7, c2 ); 744 #endif 745 gradient.setColorAt( 1.0, c2 ); 746 747 brush = QBrush( gradient ); 748 } 749 else // Plain 750 { 751 brush = palette.brush( QPalette::WindowText ); 752 } 753 754 painter->save(); 755 756 painter->setPen( QPen( brush, lineWidth ) ); 757 painter->setBrush( Qt::NoBrush ); 758 759 painter->drawEllipse( r ); 760 761 painter->restore(); 762 } 763 764 /*! 765 Draw a rectangular frame 766 767 \param painter Painter 768 \param rect Frame rectangle 769 \param palette Palette 770 \param foregroundRole Foreground role used for QFrame::Plain 771 \param frameWidth Frame width 772 \param midLineWidth Used for QFrame::Box 773 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 774 */ 775 void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect, 776 const QPalette &palette, QPalette::ColorRole foregroundRole, 777 int frameWidth, int midLineWidth, int frameStyle ) 778 { 779 if ( frameWidth <= 0 || rect.isEmpty() ) 780 return; 781 782 const int shadow = frameStyle & QFrame::Shadow_Mask; 783 784 painter->save(); 785 786 if ( shadow == QFrame::Plain ) 787 { 788 const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 ); 789 const QRectF innerRect = outerRect.adjusted( 790 frameWidth, frameWidth, -frameWidth, -frameWidth ); 791 792 QPainterPath path; 793 path.addRect( outerRect ); 794 path.addRect( innerRect ); 795 796 painter->setPen( Qt::NoPen ); 797 painter->setBrush( palette.color( foregroundRole ) ); 798 799 painter->drawPath( path ); 800 } 801 else 802 { 803 const int shape = frameStyle & QFrame::Shape_Mask; 804 805 if ( shape == QFrame::Box ) 806 { 807 const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 ); 808 const QRectF midRect1 = outerRect.adjusted( 809 frameWidth, frameWidth, -frameWidth, -frameWidth ); 810 const QRectF midRect2 = midRect1.adjusted( 811 midLineWidth, midLineWidth, -midLineWidth, -midLineWidth ); 812 813 const QRectF innerRect = midRect2.adjusted( 814 frameWidth, frameWidth, -frameWidth, -frameWidth ); 815 816 QPainterPath path1; 817 path1.moveTo( outerRect.bottomLeft() ); 818 path1.lineTo( outerRect.topLeft() ); 819 path1.lineTo( outerRect.topRight() ); 820 path1.lineTo( midRect1.topRight() ); 821 path1.lineTo( midRect1.topLeft() ); 822 path1.lineTo( midRect1.bottomLeft() ); 823 824 QPainterPath path2; 825 path2.moveTo( outerRect.bottomLeft() ); 826 path2.lineTo( outerRect.bottomRight() ); 827 path2.lineTo( outerRect.topRight() ); 828 path2.lineTo( midRect1.topRight() ); 829 path2.lineTo( midRect1.bottomRight() ); 830 path2.lineTo( midRect1.bottomLeft() ); 831 832 QPainterPath path3; 833 path3.moveTo( midRect2.bottomLeft() ); 834 path3.lineTo( midRect2.topLeft() ); 835 path3.lineTo( midRect2.topRight() ); 836 path3.lineTo( innerRect.topRight() ); 837 path3.lineTo( innerRect.topLeft() ); 838 path3.lineTo( innerRect.bottomLeft() ); 839 840 QPainterPath path4; 841 path4.moveTo( midRect2.bottomLeft() ); 842 path4.lineTo( midRect2.bottomRight() ); 843 path4.lineTo( midRect2.topRight() ); 844 path4.lineTo( innerRect.topRight() ); 845 path4.lineTo( innerRect.bottomRight() ); 846 path4.lineTo( innerRect.bottomLeft() ); 847 848 QPainterPath path5; 849 path5.addRect( midRect1 ); 850 path5.addRect( midRect2 ); 851 852 painter->setPen( Qt::NoPen ); 853 854 QBrush brush1 = palette.dark().color(); 855 QBrush brush2 = palette.light().color(); 856 857 if ( shadow == QFrame::Raised ) 858 qSwap( brush1, brush2 ); 859 860 painter->setBrush( brush1 ); 861 painter->drawPath( path1 ); 862 painter->drawPath( path4 ); 863 864 painter->setBrush( brush2 ); 865 painter->drawPath( path2 ); 866 painter->drawPath( path3 ); 867 868 painter->setBrush( palette.mid() ); 869 painter->drawPath( path5 ); 870 } 871 #if 0 872 // qDrawWinPanel doesn't result in something nice 873 // on a scalable document like PDF. Better draw a 874 // Panel. 875 876 else if ( shape == QFrame::WinPanel ) 877 { 878 painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true ); 879 qDrawWinPanel ( painter, rect.toRect(), palette, 880 frameStyle & QFrame::Sunken ); 881 } 882 else if ( shape == QFrame::StyledPanel ) 883 { 884 } 885 #endif 886 else 887 { 888 const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 ); 889 const QRectF innerRect = outerRect.adjusted( 890 frameWidth - 1.0, frameWidth - 1.0, 891 -( frameWidth - 1.0 ), -( frameWidth - 1.0 ) ); 892 893 QPainterPath path1; 894 path1.moveTo( outerRect.bottomLeft() ); 895 path1.lineTo( outerRect.topLeft() ); 896 path1.lineTo( outerRect.topRight() ); 897 path1.lineTo( innerRect.topRight() ); 898 path1.lineTo( innerRect.topLeft() ); 899 path1.lineTo( innerRect.bottomLeft() ); 900 901 902 QPainterPath path2; 903 path2.moveTo( outerRect.bottomLeft() ); 904 path2.lineTo( outerRect.bottomRight() ); 905 path2.lineTo( outerRect.topRight() ); 906 path2.lineTo( innerRect.topRight() ); 907 path2.lineTo( innerRect.bottomRight() ); 908 path2.lineTo( innerRect.bottomLeft() ); 909 910 painter->setPen( Qt::NoPen ); 911 912 QBrush brush1 = palette.dark().color(); 913 QBrush brush2 = palette.light().color(); 914 915 if ( shadow == QFrame::Raised ) 916 qSwap( brush1, brush2 ); 917 918 painter->setBrush( brush1 ); 919 painter->drawPath( path1 ); 920 921 painter->setBrush( brush2 ); 922 painter->drawPath( path2 ); 923 } 924 925 } 926 927 painter->restore(); 928 } 929 930 /*! 931 Draw a rectangular frame with rounded borders 493 932 494 933 \param painter Painter … … 567 1006 568 1007 QPen arcPen; 1008 arcPen.setCapStyle( Qt::FlatCap ); 569 1009 arcPen.setWidth( lineWidth ); 570 1010 571 1011 QPen linePen; 1012 linePen.setCapStyle( Qt::FlatCap ); 572 1013 linePen.setWidth( lineWidth ); 573 1014 … … 660 1101 661 1102 QPixmap pixmap( devRect.size() ); 1103 pixmap.fill( Qt::transparent ); 1104 662 1105 QPainter pmPainter( &pixmap ); 663 1106 pmPainter.translate( -devRect.x(), -devRect.y() ); … … 673 1116 674 1117 if ( colorMap.format() == QwtColorMap::RGB ) 675 c.setRgb ( colorMap.rgb( interval, value ) );1118 c.setRgba( colorMap.rgb( interval, value ) ); 676 1119 else 677 1120 c = colorTable[colorMap.colorIndex( interval, value )]; … … 691 1134 692 1135 if ( colorMap.format() == QwtColorMap::RGB ) 693 c.setRgb ( colorMap.rgb( interval, value ) );1136 c.setRgba( colorMap.rgb( interval, value ) ); 694 1137 else 695 1138 c = colorTable[colorMap.colorIndex( interval, value )]; … … 703 1146 drawPixmap( painter, rect, pixmap ); 704 1147 } 1148 1149 static inline void qwtFillRect( const QWidget *widget, QPainter *painter, 1150 const QRect &rect, const QBrush &brush) 1151 { 1152 if ( brush.style() == Qt::TexturePattern ) 1153 { 1154 painter->save(); 1155 1156 painter->setClipRect( rect ); 1157 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); 1158 1159 painter->restore(); 1160 } 1161 else if ( brush.gradient() ) 1162 { 1163 painter->save(); 1164 1165 painter->setClipRect( rect ); 1166 painter->fillRect(0, 0, widget->width(), 1167 widget->height(), brush); 1168 1169 painter->restore(); 1170 } 1171 else 1172 { 1173 painter->fillRect(rect, brush); 1174 } 1175 } 1176 1177 /*! 1178 Fill a pixmap with the content of a widget 1179 1180 In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy 1181 for backgrounds with gradients. Thus fillPixmap() offers 1182 an alternative implementation. 1183 1184 \param widget Widget 1185 \param pixmap Pixmap to be filled 1186 \param offset Offset 1187 1188 \sa QPixmap::fill() 1189 */ 1190 void QwtPainter::fillPixmap( const QWidget *widget, 1191 QPixmap &pixmap, const QPoint &offset ) 1192 { 1193 const QRect rect( offset, pixmap.size() ); 1194 1195 QPainter painter( &pixmap ); 1196 painter.translate( -offset ); 1197 1198 const QBrush autoFillBrush = 1199 widget->palette().brush( widget->backgroundRole() ); 1200 1201 if ( !( widget->autoFillBackground() && autoFillBrush.isOpaque() ) ) 1202 { 1203 const QBrush bg = widget->palette().brush( QPalette::Window ); 1204 qwtFillRect( widget, &painter, rect, bg); 1205 } 1206 1207 if ( widget->autoFillBackground() ) 1208 qwtFillRect( widget, &painter, rect, autoFillBrush); 1209 1210 if ( widget->testAttribute(Qt::WA_StyledBackground) ) 1211 { 1212 painter.setClipRegion( rect ); 1213 1214 QStyleOption opt; 1215 opt.initFrom( widget ); 1216 widget->style()->drawPrimitive( QStyle::PE_Widget, 1217 &opt, &painter, widget ); 1218 } 1219 } 1220 1221 /*! 1222 Fill rect with the background of a widget 1223 1224 \param painter Painter 1225 \param rect Rectangle to be filled 1226 \param widget Widget 1227 1228 \sa QStyle::PE_Widget, QWidget::backgroundRole() 1229 */ 1230 void QwtPainter::drawBackgound( QPainter *painter, 1231 const QRectF &rect, const QWidget *widget ) 1232 { 1233 if ( widget->testAttribute( Qt::WA_StyledBackground ) ) 1234 { 1235 QStyleOption opt; 1236 opt.initFrom( widget ); 1237 opt.rect = rect.toAlignedRect(); 1238 1239 widget->style()->drawPrimitive( 1240 QStyle::PE_Widget, &opt, painter, widget); 1241 } 1242 else 1243 { 1244 const QBrush brush = 1245 widget->palette().brush( widget->backgroundRole() ); 1246 1247 painter->fillRect( rect, brush ); 1248 } 1249 } 1250 1251 /*! 1252 \return A pixmap that can be used as backing store 1253 1254 \param widget Widget, for which the backingstore is intended 1255 \param size Size of the pixmap 1256 */ 1257 QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size ) 1258 { 1259 QPixmap pm; 1260 1261 #define QWT_HIGH_DPI 1 1262 1263 #if QT_VERSION >= 0x050000 && QWT_HIGH_DPI 1264 qreal pixelRatio = 1.0; 1265 1266 if ( widget && widget->windowHandle() ) 1267 { 1268 #if QT_VERSION < 0x050100 1269 pixelRatio = widget->windowHandle()->devicePixelRatio(); 1270 #else 1271 pixelRatio = widget->devicePixelRatio(); 1272 #endif 1273 } 1274 else 1275 { 1276 if ( qApp ) 1277 pixelRatio = qApp->devicePixelRatio(); 1278 } 1279 1280 pm = QPixmap( size * pixelRatio ); 1281 pm.setDevicePixelRatio( pixelRatio ); 1282 #else 1283 Q_UNUSED( widget ) 1284 pm = QPixmap( size ); 1285 #endif 1286 1287 #if QT_VERSION < 0x050000 1288 #ifdef Q_WS_X11 1289 if ( widget && isX11GraphicsSystem() ) 1290 { 1291 if ( pm.x11Info().screen() != widget->x11Info().screen() ) 1292 pm.x11SetScreen( widget->x11Info().screen() ); 1293 } 1294 #endif 1295 #endif 1296 1297 return pm; 1298 } 1299 -
trunk/BNC/qwt/qwt_painter.h
r4271 r8127 17 17 #include <qpen.h> 18 18 #include <qline.h> 19 #include <qpalette.h> 19 20 20 21 class QPainter; … … 30 31 class QwtInterval; 31 32 32 class QPalette;33 33 class QTextDocument; 34 34 class QPainterPath; … … 70 70 static void drawLine( QPainter *, const QLineF & ); 71 71 72 static void drawPolygon( QPainter *, const QPolygonF & pa);73 static void drawPolyline( QPainter *, const QPolygonF & pa);72 static void drawPolygon( QPainter *, const QPolygonF & ); 73 static void drawPolyline( QPainter *, const QPolygonF & ); 74 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 ); 75 83 76 84 static void drawPoint( QPainter *, double x, double y ); 77 85 static void drawPoint( QPainter *, const QPointF & ); 86 static void drawPoints( QPainter *, const QPolygonF & ); 87 static void drawPoints( QPainter *, const QPointF *, int pointCount ); 78 88 79 89 static void drawPath( QPainter *, const QPainterPath & ); … … 81 91 static void drawPixmap( QPainter *, const QRectF &, const QPixmap & ); 82 92 93 static void drawRoundFrame( QPainter *, 94 const QRectF &, const QPalette &, int lineWidth, int frameStyle ); 95 83 96 static void drawRoundedFrame( QPainter *, 84 97 const QRectF &, double xRadius, double yRadius, 85 98 const QPalette &, int lineWidth, int frameStyle ); 86 99 87 static void drawFocusRect( QPainter *, QWidget * ); 88 static void drawFocusRect( QPainter *, QWidget *, const QRect & ); 100 static void drawFrame( QPainter *, const QRectF &rect, 101 const QPalette &palette, QPalette::ColorRole foregroundRole, 102 int lineWidth, int midLineWidth, int frameStyle ); 103 104 static void drawFocusRect( QPainter *, const QWidget * ); 105 static void drawFocusRect( QPainter *, const QWidget *, const QRect & ); 89 106 90 107 static void drawColorBar( QPainter *painter, … … 93 110 94 111 static bool isAligning( QPainter *painter ); 112 static bool isX11GraphicsSystem(); 113 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 & ); 95 121 96 122 private: … … 103 129 { 104 130 QwtPainter::drawPoint( painter, QPointF( x, y ) ); 131 } 132 133 //! Wrapper for QPainter::drawPoints() 134 inline void QwtPainter::drawPoints( QPainter *painter, const QPolygon &polygon ) 135 { 136 drawPoints( painter, polygon.data(), polygon.size() ); 137 } 138 139 //! Wrapper for QPainter::drawPoints() 140 inline void QwtPainter::drawPoints( QPainter *painter, const QPolygonF &polygon ) 141 { 142 drawPoints( painter, polygon.data(), polygon.size() ); 105 143 } 106 144 … … 119 157 120 158 /*! 121 Returns whetherline splitting for the raster paint engine is enabled.159 \return True, when line splitting for the raster paint engine is enabled. 122 160 \sa setPolylineSplitting() 123 161 */ … … 128 166 129 167 /*! 130 Returnswhether coordinates should be rounded, before they are painted131 to a paint engine that floors to integer values.For other paint engines132 this ( Pdf, SVG ), this flag has no effect.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. 133 171 172 \return True, when rounding is enabled 134 173 \sa setRoundingAlignment(), isAligning() 135 174 */ -
trunk/BNC/qwt/qwt_panner.cpp
r4271 r8127 10 10 #include "qwt_panner.h" 11 11 #include "qwt_picker.h" 12 #include "qwt_painter.h" 12 13 #include <qpainter.h> 13 14 #include <qpixmap.h> … … 23 24 for ( int i = 0; i < children.size(); i++ ) 24 25 { 25 QObject *obj = children[i]; 26 if ( obj->inherits( "QwtPicker" ) ) 27 { 28 QwtPicker *picker = ( QwtPicker * )obj; 29 if ( picker->isEnabled() ) 30 pickers += picker; 31 } 26 QwtPicker *picker = qobject_cast<QwtPicker *>( children[i] ); 27 if ( picker && picker->isEnabled() ) 28 pickers += picker; 32 29 } 33 30 … … 40 37 PrivateData(): 41 38 button( Qt::LeftButton ), 42 button State( Qt::NoButton),39 buttonModifiers( Qt::NoModifier ), 43 40 abortKey( Qt::Key_Escape ), 44 abortKey State( Qt::NoButton),41 abortKeyModifiers( Qt::NoModifier ), 45 42 #ifndef QT_NO_CURSOR 46 43 cursor( NULL ), … … 61 58 } 62 59 63 int button; 64 int buttonState; 60 Qt::MouseButton button; 61 Qt::KeyboardModifiers buttonModifiers; 62 65 63 int abortKey; 66 int abortKeyState;64 Qt::KeyboardModifiers abortKeyModifiers; 67 65 68 66 QPoint initialPos; … … 106 104 107 105 /*! 108 Change the mouse button 109 The defaults are Qt::LeftButton and Qt::NoButton 110 */ 111 void QwtPanner::setMouseButton( int button, int buttonState ) 106 Change the mouse button and modifiers used for panning 107 The defaults are Qt::LeftButton and Qt::NoModifier 108 */ 109 void QwtPanner::setMouseButton( Qt::MouseButton button, 110 Qt::KeyboardModifiers modifiers ) 112 111 { 113 112 d_data->button = button; 114 d_data->buttonState = buttonState; 115 } 116 117 //! Get the mouse button 118 void QwtPanner::getMouseButton( int &button, int &buttonState ) const 113 d_data->buttonModifiers = modifiers; 114 } 115 116 //! Get mouse button and modifiers used for panning 117 void QwtPanner::getMouseButton( Qt::MouseButton &button, 118 Qt::KeyboardModifiers &modifiers ) const 119 119 { 120 120 button = d_data->button; 121 buttonState = d_data->buttonState;121 modifiers = d_data->buttonModifiers; 122 122 } 123 123 124 124 /*! 125 125 Change the abort key 126 The defaults are Qt::Key_Escape and Qt::No Button126 The defaults are Qt::Key_Escape and Qt::NoModifiers 127 127 128 128 \param key Key ( See Qt::Keycode ) 129 \param state State 130 */ 131 void QwtPanner::setAbortKey( int key, int state ) 129 \param modifiers Keyboard modifiers 130 */ 131 void QwtPanner::setAbortKey( int key, 132 Qt::KeyboardModifiers modifiers ) 132 133 { 133 134 d_data->abortKey = key; 134 d_data->abortKeyState = state; 135 } 136 137 //! Get the abort key 138 void QwtPanner::getAbortKey( int &key, int &state ) const 135 d_data->abortKeyModifiers = modifiers; 136 } 137 138 //! Get the abort key and modifiers 139 void QwtPanner::getAbortKey( int &key, 140 Qt::KeyboardModifiers &modifiers ) const 139 141 { 140 142 key = d_data->abortKey; 141 state = d_data->abortKeyState;143 modifiers = d_data->abortKeyModifiers; 142 144 } 143 145 … … 223 225 224 226 /*! 225 Return true if a orientatiois enabled227 \return True if an orientation is enabled 226 228 \sa orientations(), setOrientations() 227 229 */ … … 257 259 258 260 QPixmap pm( size() ); 259 pm.fill( parentWidget(), 0, 0);261 QwtPainter::fillPixmap( parentWidget(), pm ); 260 262 261 263 QPainter painter( &pm ); … … 298 300 /*! 299 301 Grab the widget into a pixmap. 302 \return Grabbed pixmap 300 303 */ 301 304 QPixmap QwtPanner::grab() const 302 305 { 306 #if QT_VERSION >= 0x050000 307 return parentWidget()->grab( parentWidget()->rect() ); 308 #else 303 309 return QPixmap::grabWidget( parentWidget() ); 310 #endif 304 311 } 305 312 … … 307 314 \brief Event filter 308 315 309 When isEnabled() the mouse events of the observed widget are filtered. 316 When isEnabled() is true mouse events of the 317 observed widget are filtered. 310 318 311 319 \param object Object to be filtered 312 320 \param event Event 313 321 322 \return Always false, beside for paint events for the 323 parent widget. 324 314 325 \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), 315 326 widgetMouseMoveEvent() … … 324 335 case QEvent::MouseButtonPress: 325 336 { 326 widgetMousePressEvent( ( QMouseEvent * )event);337 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) ); 327 338 break; 328 339 } 329 340 case QEvent::MouseMove: 330 341 { 331 widgetMouseMoveEvent( ( QMouseEvent * )event);342 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) ); 332 343 break; 333 344 } 334 345 case QEvent::MouseButtonRelease: 335 346 { 336 widgetMouseReleaseEvent( ( QMouseEvent * )event);347 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) ); 337 348 break; 338 349 } 339 350 case QEvent::KeyPress: 340 351 { 341 widgetKeyPressEvent( ( QKeyEvent * )event);352 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) ); 342 353 break; 343 354 } 344 355 case QEvent::KeyRelease: 345 356 { 346 widgetKeyReleaseEvent( ( QKeyEvent * )event);357 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) ); 347 358 break; 348 359 } … … 368 379 void QwtPanner::widgetMousePressEvent( QMouseEvent *mouseEvent ) 369 380 { 370 if ( mouseEvent->button() != d_data->button ) 381 if ( ( mouseEvent->button() != d_data->button ) 382 || ( mouseEvent->modifiers() != d_data->buttonModifiers ) ) 383 { 371 384 return; 385 } 372 386 373 387 QWidget *w = parentWidget(); … … 375 389 return; 376 390 377 if ( ( mouseEvent->modifiers() & Qt::KeyboardModifierMask ) !=378 ( int )( d_data->buttonState & Qt::KeyboardModifierMask ) )379 {380 return;381 }382 383 391 #ifndef QT_NO_CURSOR 384 392 showCursor( true ); … … 391 399 // We don't want to grab the picker ! 392 400 QVector<QwtPicker *> pickers = qwtActivePickers( parentWidget() ); 393 for ( int i = 0; i < ( int )pickers.size(); i++ )401 for ( int i = 0; i < pickers.size(); i++ ) 394 402 pickers[i]->setEnabled( false ); 395 403 … … 397 405 d_data->contentsMask = contentsMask(); 398 406 399 for ( int i = 0; i < ( int )pickers.size(); i++ )407 for ( int i = 0; i < pickers.size(); i++ ) 400 408 pickers[i]->setEnabled( true ); 401 409 … … 472 480 void QwtPanner::widgetKeyPressEvent( QKeyEvent *keyEvent ) 473 481 { 474 if ( keyEvent->key() == d_data->abortKey ) 475 { 476 const bool matched = 477 ( keyEvent->modifiers() & Qt::KeyboardModifierMask ) == 478 ( int )( d_data->abortKeyState & Qt::KeyboardModifierMask ); 479 if ( matched ) 480 { 481 hide(); 482 #ifndef QT_NO_CURSOR 483 showCursor( false ); 484 #endif 485 d_data->pixmap = QPixmap(); 486 } 482 if ( ( keyEvent->key() == d_data->abortKey ) 483 && ( keyEvent->modifiers() == d_data->abortKeyModifiers ) ) 484 { 485 hide(); 486 487 #ifndef QT_NO_CURSOR 488 showCursor( false ); 489 #endif 490 d_data->pixmap = QPixmap(); 487 491 } 488 492 } -
trunk/BNC/qwt/qwt_panner.h
r4271 r8127 44 44 bool isEnabled() const; 45 45 46 void setMouseButton( int button, int buttonState = Qt::NoButton ); 47 void getMouseButton( int &button, int &buttonState ) const; 48 void setAbortKey( int key, int state = Qt::NoButton ); 49 void getAbortKey( int &key, int &state ) const; 46 void setMouseButton( Qt::MouseButton, 47 Qt::KeyboardModifiers = Qt::NoModifier ); 48 void getMouseButton( Qt::MouseButton &button, 49 Qt::KeyboardModifiers & ) const; 50 51 void setAbortKey( int key, Qt::KeyboardModifiers = Qt::NoModifier ); 52 void getAbortKey( int &key, Qt::KeyboardModifiers & ) const; 50 53 51 54 void setCursor( const QCursor & ); -
trunk/BNC/qwt/qwt_picker.cpp
r4271 r8127 12 12 #include "qwt_painter.h" 13 13 #include "qwt_math.h" 14 #include "qwt_widget_overlay.h" 14 15 #include <qapplication.h> 15 16 #include <qevent.h> … … 22 23 #include <qmath.h> 23 24 24 class QwtPicker::PickerWidget: public QWidget 25 static inline QRegion qwtMaskRegion( const QRect &r, int penWidth ) 26 { 27 const int pw = qMax( penWidth, 1 ); 28 const int pw2 = penWidth / 2; 29 30 int x1 = r.left() - pw2; 31 int x2 = r.right() + 1 + pw2 + ( pw % 2 ); 32 33 int y1 = r.top() - pw2; 34 int y2 = r.bottom() + 1 + pw2 + ( pw % 2 ); 35 36 QRegion region; 37 38 region += QRect( x1, y1, x2 - x1, pw ); 39 region += QRect( x1, y1, pw, y2 - y1 ); 40 region += QRect( x1, y2 - pw, x2 - x1, pw ); 41 region += QRect( x2 - pw, y1, pw, y2 - y1 ); 42 43 return region; 44 } 45 46 static inline QRegion qwtMaskRegion( const QLine &l, int penWidth ) 47 { 48 const int pw = qMax( penWidth, 1 ); 49 const int pw2 = penWidth / 2; 50 51 QRegion region; 52 53 if ( l.x1() == l.x2() ) 54 { 55 region += QRect( l.x1() - pw2, l.y1(), 56 pw, l.y2() ).normalized(); 57 } 58 else if ( l.y1() == l.y2() ) 59 { 60 region += QRect( l.x1(), l.y1() - pw2, 61 l.x2(), pw ).normalized(); 62 } 63 64 return region; 65 } 66 67 class QwtPickerRubberband: public QwtWidgetOverlay 25 68 { 26 69 public: 27 enum Type 28 { 29 RubberBand, 30 Text 31 }; 32 33 PickerWidget( QwtPicker *, QWidget *, Type ); 34 void updateMask(); 35 36 /* 37 For a tracker text with a background we can use the background 38 rect as mask. Also for "regular" Qt widgets >= 4.3.0 we 39 don't need to mask the text anymore. 40 */ 41 bool d_hasTextMask; 70 QwtPickerRubberband( QwtPicker *, QWidget * ); 42 71 43 72 protected: 44 virtual void paintEvent( QPaintEvent * ); 73 virtual void drawOverlay( QPainter * ) const; 74 virtual QRegion maskHint() const; 45 75 46 76 QwtPicker *d_picker; 47 Type d_type;48 77 }; 49 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 91 50 92 class QwtPicker::PrivateData 51 93 { 52 94 public: 95 PrivateData(): 96 enabled( false ), 97 stateMachine( NULL ), 98 resizeMode( QwtPicker::Stretch ), 99 rubberBand( QwtPicker::NoRubberBand ), 100 trackerMode( QwtPicker::AlwaysOff ), 101 isActive( false ), 102 trackerPosition( -1, -1 ), 103 mouseTracking( false ), 104 openGL( false ) 105 { 106 } 107 53 108 bool enabled; 54 109 … … 70 125 bool mouseTracking; // used to save previous value 71 126 72 /* 73 On X11 the widget below the picker widgets gets paint events 74 with a region that is the bounding rect of the mask, if it is complex. 75 In case of (f.e) a CrossRubberBand and a text this creates complete 76 repaints of the widget. So we better use two different widgets. 77 */ 78 79 QPointer<PickerWidget> rubberBandWidget; 80 QPointer<PickerWidget> trackerWidget; 127 QPointer< QwtPickerRubberband > rubberBandOverlay; 128 QPointer< QwtPickerTracker> trackerOverlay; 129 130 bool openGL; 81 131 }; 82 132 83 QwtPicker::PickerWidget::PickerWidget( 84 QwtPicker *picker, QWidget *parent, Type type ): 85 QWidget( parent ), 86 d_hasTextMask( false ), 87 d_picker( picker ), 88 d_type( type ) 89 { 90 setAttribute( Qt::WA_TransparentForMouseEvents ); 91 setAttribute( Qt::WA_NoSystemBackground ); 92 setFocusPolicy( Qt::NoFocus ); 93 } 94 95 void QwtPicker::PickerWidget::updateMask() 96 { 97 QRegion mask; 98 99 if ( d_type == RubberBand ) 100 { 101 QBitmap bm( width(), height() ); 102 bm.fill( Qt::color0 ); 103 104 QPainter painter( &bm ); 105 QPen pen = d_picker->rubberBandPen(); 106 pen.setColor( Qt::color1 ); 107 painter.setPen( pen ); 108 109 d_picker->drawRubberBand( &painter ); 110 111 mask = QRegion( bm ); 112 } 113 if ( d_type == Text ) 114 { 115 d_hasTextMask = parentWidget()->testAttribute( Qt::WA_PaintOnScreen ); 116 117 if ( d_hasTextMask ) 118 { 119 const QwtText label = d_picker->trackerText( 120 d_picker->trackerPosition() ); 121 122 if ( label.testPaintAttribute( QwtText::PaintBackground ) 123 && label.backgroundBrush().style() != Qt::NoBrush ) 124 { 125 if ( label.backgroundBrush().color().alpha() > 0 ) 126 { 127 // We don't need a text mask, when we have a background 128 d_hasTextMask = false; 129 } 130 } 131 } 132 133 if ( d_hasTextMask ) 134 { 135 QBitmap bm( width(), height() ); 136 bm.fill( Qt::color0 ); 137 138 QPainter painter( &bm ); 139 painter.setFont( font() ); 140 141 QPen pen = d_picker->trackerPen(); 142 pen.setColor( Qt::color1 ); 143 painter.setPen( pen ); 144 145 d_picker->drawTracker( &painter ); 146 147 mask = QRegion( bm ); 148 } 149 else 150 { 151 mask = d_picker->trackerRect( font() ); 152 } 153 } 154 155 QWidget *w = parentWidget(); 156 if ( w && !w->testAttribute( Qt::WA_PaintOnScreen ) ) 157 { 158 // The parent widget gets an update for its complete rectangle 159 // when the mask is changed in visible state. 160 // With this hide/show we only get an update for the 161 // previous mask. 162 163 hide(); 164 } 165 setMask( mask ); 166 setVisible( !mask.isEmpty() ); 167 } 168 169 void QwtPicker::PickerWidget::paintEvent( QPaintEvent *e ) 170 { 171 QPainter painter( this ); 172 painter.setClipRegion( e->region() ); 173 174 if ( d_type == RubberBand ) 175 { 176 painter.setPen( d_picker->rubberBandPen() ); 177 d_picker->drawRubberBand( &painter ); 178 } 179 180 if ( d_type == Text ) 181 { 182 /* 183 If we have a text mask we simply fill the region of 184 the mask. This gives better results for antialiased fonts. 185 */ 186 if ( d_hasTextMask ) 187 { 188 painter.fillRect( e->rect(), 189 QBrush( d_picker->trackerPen().color() ) ); 190 } 191 else 192 { 193 painter.setPen( d_picker->trackerPen() ); 194 d_picker->drawTracker( &painter ); 195 } 196 } 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 ); 197 169 } 198 170 … … 201 173 202 174 Creates an picker that is enabled, but without a state machine. 203 rubber band and tracker are disabled.175 rubber band and tracker are disabled. 204 176 205 177 \param parent Parent widget, that will be observed … … 215 187 Constructor 216 188 217 \param rubberBand Rubber band style189 \param rubberBand Rubber band style 218 190 \param trackerMode Tracker mode 219 191 \param parent Parent widget, that will be observed … … 230 202 { 231 203 setMouseTracking( false ); 204 232 205 delete d_data->stateMachine; 233 delete d_data->rubberBandWidget; 234 delete d_data->trackerWidget; 206 delete d_data->rubberBandOverlay; 207 delete d_data->trackerOverlay; 208 235 209 delete d_data; 236 210 } 237 211 238 //! Init the picker,used by the constructors212 //! Initialize the picker - used by the constructors 239 213 void QwtPicker::init( QWidget *parent, 240 214 RubberBand rubberBand, DisplayMode trackerMode ) … … 242 216 d_data = new PrivateData; 243 217 244 d_data->rubberBandWidget = NULL;245 d_data->trackerWidget = NULL;246 247 218 d_data->rubberBand = rubberBand; 248 d_data->enabled = false;249 d_data->resizeMode = Stretch;250 d_data->trackerMode = AlwaysOff;251 d_data->isActive = false;252 d_data->trackerPosition = QPoint( -1, -1 );253 d_data->mouseTracking = false;254 255 d_data->stateMachine = NULL;256 219 257 220 if ( parent ) … … 260 223 parent->setFocusPolicy( Qt::WheelFocus ); 261 224 225 d_data->openGL = parent->inherits( "QGLWidget" ); 262 226 d_data->trackerFont = parent->font(); 263 227 d_data->mouseTracking = parent->hasMouseTracking(); 228 264 229 setEnabled( true ); 265 230 } 231 266 232 setTrackerMode( trackerMode ); 267 233 } … … 326 292 327 293 /*! 328 Set the rubber band style329 330 \param rubberBand Rubber band style294 Set the rubber band style 295 296 \param rubberBand Rubber band style 331 297 The default value is NoRubberBand. 332 298 … … 339 305 340 306 /*! 341 \return Rubber band style307 \return Rubber band style 342 308 \sa setRubberBand(), RubberBand, rubberBandPen() 343 309 */ … … 500 466 Set the pen for the rubberband 501 467 502 \param pen Rubber band pen468 \param pen Rubber band pen 503 469 \sa rubberBandPen(), setRubberBand() 504 470 */ … … 513 479 514 480 /*! 515 \return Rubber band pen481 \return Rubber band pen 516 482 \sa setRubberBandPen(), rubberBand() 517 483 */ … … 553 519 554 520 /*! 555 Draw a rubberband, depending on rubberBand()556 557 \param painter Painter, initialized with clip rect558 559 \sa rubberBand(), RubberBand560 */ 561 562 void QwtPicker::drawRubberBand( QPainter *painter ) const 563 { 521 Calculate the mask for the rubber band overlay 522 523 \return Region for the mask 524 \sa QWidget::setMask() 525 */ 526 QRegion QwtPicker::rubberBandMask() const 527 { 528 QRegion mask; 529 564 530 if ( !isActive() || rubberBand() == NoRubberBand || 565 531 rubberBandPen().style() == Qt::NoPen ) 566 532 { 567 return; 568 } 569 570 const QRect &pRect = pickRect(); 533 return mask; 534 } 535 571 536 const QPolygon pa = adjustedPoints( d_data->pickedPoints ); 572 537 … … 583 548 { 584 549 if ( pa.count() < 1 ) 550 return mask; 551 552 const QPoint pos = pa[0]; 553 const int pw = rubberBandPen().width(); 554 555 const QRect pRect = pickArea().boundingRect().toRect(); 556 switch ( rubberBand() ) 557 { 558 case VLineRubberBand: 559 { 560 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 561 pos.x(), pRect.bottom() ), pw ); 562 break; 563 } 564 case HLineRubberBand: 565 { 566 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 567 pRect.right(), pos.y() ), pw ); 568 break; 569 } 570 case CrossRubberBand: 571 { 572 mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), 573 pos.x(), pRect.bottom() ), pw ); 574 mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), 575 pRect.right(), pos.y() ), pw ); 576 break; 577 } 578 default: 579 break; 580 } 581 break; 582 } 583 case QwtPickerMachine::RectSelection: 584 { 585 if ( pa.count() < 2 ) 586 return mask; 587 588 const int pw = rubberBandPen().width(); 589 590 switch ( rubberBand() ) 591 { 592 case RectRubberBand: 593 { 594 const QRect r = QRect( pa.first(), pa.last() ); 595 mask = qwtMaskRegion( r.normalized(), pw ); 596 break; 597 } 598 case EllipseRubberBand: 599 { 600 const QRect r = QRect( pa.first(), pa.last() ); 601 mask += r.adjusted( -pw, -pw, pw, pw ); 602 break; 603 } 604 default: 605 break; 606 } 607 break; 608 } 609 case QwtPickerMachine::PolygonSelection: 610 { 611 const int pw = rubberBandPen().width(); 612 if ( pw <= 1 ) 613 { 614 // because of the join style we better 615 // return a mask for a pen width <= 1 only 616 617 const int off = 2 * pw; 618 const QRect r = pa.boundingRect(); 619 mask += r.adjusted( -off, -off, off, off ); 620 } 621 break; 622 } 623 default: 624 break; 625 } 626 627 return mask; 628 } 629 630 /*! 631 Draw a rubber band, depending on rubberBand() 632 633 \param painter Painter, initialized with a clip region 634 635 \sa rubberBand(), RubberBand 636 */ 637 638 void QwtPicker::drawRubberBand( QPainter *painter ) const 639 { 640 if ( !isActive() || rubberBand() == NoRubberBand || 641 rubberBandPen().style() == Qt::NoPen ) 642 { 643 return; 644 } 645 646 const QPolygon pa = adjustedPoints( d_data->pickedPoints ); 647 648 QwtPickerMachine::SelectionType selectionType = 649 QwtPickerMachine::NoSelection; 650 651 if ( d_data->stateMachine ) 652 selectionType = d_data->stateMachine->selectionType(); 653 654 switch ( selectionType ) 655 { 656 case QwtPickerMachine::NoSelection: 657 case QwtPickerMachine::PointSelection: 658 { 659 if ( pa.count() < 1 ) 585 660 return; 586 661 587 662 const QPoint pos = pa[0]; 588 663 664 const QRect pRect = pickArea().boundingRect().toRect(); 589 665 switch ( rubberBand() ) 590 666 { 591 667 case VLineRubberBand: 668 { 592 669 QwtPainter::drawLine( painter, pos.x(), 593 670 pRect.top(), pos.x(), pRect.bottom() ); 594 671 break; 595 672 } 596 673 case HLineRubberBand: 674 { 597 675 QwtPainter::drawLine( painter, pRect.left(), 598 676 pos.y(), pRect.right(), pos.y() ); 599 677 break; 600 678 } 601 679 case CrossRubberBand: 680 { 602 681 QwtPainter::drawLine( painter, pos.x(), 603 682 pRect.top(), pos.x(), pRect.bottom() ); … … 605 684 pos.y(), pRect.right(), pos.y() ); 606 685 break; 686 } 607 687 default: 608 688 break; … … 615 695 return; 616 696 617 const QPoint p1 = pa[0]; 618 const QPoint p2 = pa[int( pa.count() - 1 )]; 619 620 const QRect rect = QRect( p1, p2 ).normalized(); 697 const QRect rect = QRect( pa.first(), pa.last() ).normalized(); 621 698 switch ( rubberBand() ) 622 699 { 623 700 case EllipseRubberBand: 701 { 624 702 QwtPainter::drawEllipse( painter, rect ); 625 703 break; 704 } 626 705 case RectRubberBand: 706 { 627 707 QwtPainter::drawRect( painter, rect ); 628 708 break; 709 } 629 710 default: 630 711 break; … … 694 775 return adjusted; 695 776 }\endverbatim\n 777 778 \param points Selected points 779 \return Selected points unmodified 696 780 */ 697 781 QPolygon QwtPicker::adjustedPoints( const QPolygon &points ) const … … 773 857 textRect.moveTopLeft( QPoint( x, y ) ); 774 858 775 int right = qMin( textRect.right(), pickRect().right() - margin ); 776 int bottom = qMin( textRect.bottom(), pickRect().bottom() - margin ); 859 const QRect pickRect = pickArea().boundingRect().toRect(); 860 861 int right = qMin( textRect.right(), pickRect.right() - margin ); 862 int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin ); 777 863 textRect.moveBottomRight( QPoint( right, bottom ) ); 778 864 779 int left = qMax( textRect.left(), pickRect ().left() + margin );780 int top = qMax( textRect.top(), pickRect ().top() + margin );865 int left = qMax( textRect.left(), pickRect.left() + margin ); 866 int top = qMax( textRect.top(), pickRect.top() + margin ); 781 867 textRect.moveTopLeft( QPoint( left, top ) ); 782 868 … … 787 873 \brief Event filter 788 874 789 When isEnabled() ==true all events of the observed widget are filtered.875 When isEnabled() is true all events of the observed widget are filtered. 790 876 Mouse and keyboard events are translated into widgetMouse- and widgetKey- 791 877 and widgetWheel-events. Paint and Resize events are handled to keep 792 rubber band and tracker up to date.878 rubber band and tracker up to date. 793 879 794 880 \param object Object to be filtered 795 881 \param event Event 882 883 \return Always false. 796 884 797 885 \sa widgetEnterEvent(), widgetLeaveEvent(), … … 809 897 case QEvent::Resize: 810 898 { 811 const QResizeEvent *re = ( QResizeEvent * )event; 899 const QResizeEvent *re = static_cast<QResizeEvent *>( event ); 900 901 /* 902 Adding/deleting additional event filters inside of an event filter 903 is not safe dues to the implementation in Qt ( changing alist while iterating ). 904 So we create the overlays in a way, that they don't install en event filter 905 ( parent set to NULL ) and do the resizing here. 906 */ 907 if ( d_data->trackerOverlay ) 908 d_data->trackerOverlay->resize( re->size() ); 909 910 if ( d_data->rubberBandOverlay ) 911 d_data->rubberBandOverlay->resize( re->size() ); 912 812 913 if ( d_data->resizeMode == Stretch ) 813 914 stretchSelection( re->oldSize(), re->size() ); 814 915 815 if ( d_data->rubberBandWidget ) 816 d_data->rubberBandWidget->resize( re->size() ); 817 818 if ( d_data->trackerWidget ) 819 d_data->trackerWidget->resize( re->size() ); 916 updateDisplay(); 820 917 break; 821 918 } 822 919 case QEvent::Enter: 920 { 823 921 widgetEnterEvent( event ); 824 922 break; 923 } 825 924 case QEvent::Leave: 925 { 826 926 widgetLeaveEvent( event ); 827 927 break; 928 } 828 929 case QEvent::MouseButtonPress: 829 widgetMousePressEvent( ( QMouseEvent * )event ); 930 { 931 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) ); 830 932 break; 933 } 831 934 case QEvent::MouseButtonRelease: 832 widgetMouseReleaseEvent( ( QMouseEvent * )event ); 935 { 936 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) ); 833 937 break; 938 } 834 939 case QEvent::MouseButtonDblClick: 835 widgetMouseDoubleClickEvent( ( QMouseEvent * )event ); 940 { 941 widgetMouseDoubleClickEvent( static_cast<QMouseEvent *>( event ) ); 836 942 break; 943 } 837 944 case QEvent::MouseMove: 838 widgetMouseMoveEvent( ( QMouseEvent * )event ); 945 { 946 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) ); 839 947 break; 948 } 840 949 case QEvent::KeyPress: 841 widgetKeyPressEvent( ( QKeyEvent * )event ); 950 { 951 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) ); 842 952 break; 953 } 843 954 case QEvent::KeyRelease: 844 widgetKeyReleaseEvent( ( QKeyEvent * )event ); 955 { 956 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) ); 845 957 break; 958 } 846 959 case QEvent::Wheel: 847 widgetWheelEvent( ( QWheelEvent * )event ); 960 { 961 widgetWheelEvent( static_cast<QWheelEvent *>( event ) ); 848 962 break; 963 } 849 964 default: 850 965 break; … … 879 994 void QwtPicker::widgetMouseMoveEvent( QMouseEvent *mouseEvent ) 880 995 { 881 if ( pick Rect().contains( mouseEvent->pos() ) )996 if ( pickArea().contains( mouseEvent->pos() ) ) 882 997 d_data->trackerPosition = mouseEvent->pos(); 883 998 else … … 923 1038 924 1039 /*! 925 Handle a mouse rel ase event for the observed widget.1040 Handle a mouse release event for the observed widget. 926 1041 927 1042 \param mouseEvent Mouse event … … 964 1079 void QwtPicker::widgetWheelEvent( QWheelEvent *wheelEvent ) 965 1080 { 966 if ( pick Rect().contains( wheelEvent->pos() ) )1081 if ( pickArea().contains( wheelEvent->pos() ) ) 967 1082 d_data->trackerPosition = wheelEvent->pos(); 968 1083 else … … 1014 1129 if ( dx != 0 || dy != 0 ) 1015 1130 { 1016 const QRect rect = pick Rect();1131 const QRect rect = pickArea().boundingRect().toRect(); 1017 1132 const QPoint pos = parentWidget()->mapFromGlobal( QCursor::pos() ); 1018 1133 … … 1048 1163 Passes an event to the state machine and executes the resulting 1049 1164 commands. Append and Move commands use the current position 1050 of the cursor ( QCursor::pos()).1165 of the cursor ( QCursor::pos() ). 1051 1166 1052 1167 \param event Event … … 1177 1292 1178 1293 /*! 1179 Reset the state machine and terminate ( end(false)) the selection1294 Reset the state machine and terminate ( end(false) ) the selection 1180 1295 */ 1181 1296 void QwtPicker::reset() … … 1189 1304 1190 1305 /*! 1191 Append a point to the selection and update rubber band and tracker.1306 Append a point to the selection and update rubber band and tracker. 1192 1307 The appended() signal is emitted. 1193 1308 … … 1259 1374 1260 1375 /*! 1261 \brief Validate and fix up the selection1376 \brief Validate and fix up the selection 1262 1377 1263 1378 Accepts all selections unmodified 1264 1379 1265 \param selection Selection to validate and fix up1380 \param selection Selection to validate and fix up 1266 1381 \return true, when accepted, false otherwise 1267 1382 */ … … 1359 1474 \return parentWidget()->contentsRect() 1360 1475 */ 1361 QRect QwtPicker::pickRect() const 1362 { 1476 QPainterPath QwtPicker::pickArea() const 1477 { 1478 QPainterPath path; 1479 1363 1480 const QWidget *widget = parentWidget(); 1364 1481 if ( widget ) 1365 return widget->contentsRect();1366 1367 return QRect();1368 } 1369 1370 //! Update the state of rubber band and tracker label1482 path.addRect( widget->contentsRect() ); 1483 1484 return path; 1485 } 1486 1487 //! Update the state of rubber band and tracker label 1371 1488 void QwtPicker::updateDisplay() 1372 1489 { … … 1375 1492 bool showRubberband = false; 1376 1493 bool showTracker = false; 1494 1377 1495 if ( w && w->isVisible() && d_data->enabled ) 1378 1496 { … … 1386 1504 ( trackerMode() == ActiveOnly && isActive() ) ) 1387 1505 { 1388 if ( trackerPen() != Qt::NoPen ) 1506 if ( trackerPen() != Qt::NoPen 1507 && !trackerRect( QFont() ).isEmpty() ) 1508 { 1389 1509 showTracker = true; 1390 } 1391 } 1392 1393 QPointer<PickerWidget> &rw = d_data->rubberBandWidget; 1510 } 1511 } 1512 } 1513 1514 QPointer< QwtPickerRubberband > &rw = d_data->rubberBandOverlay; 1394 1515 if ( showRubberband ) 1395 1516 { 1396 1517 if ( rw.isNull() ) 1397 1518 { 1398 rw = new PickerWidget( this, w, PickerWidget::RubberBand ); 1519 rw = new QwtPickerRubberband( this, NULL ); // NULL -> no extra event filter 1520 rw->setObjectName( "PickerRubberBand" ); 1521 rw->setParent( w ); 1399 1522 rw->resize( w->size() ); 1400 1523 } 1401 rw->updateMask(); 1402 rw->update(); // Needed, when the mask doesn't change 1524 1525 if ( d_data->rubberBand <= RectRubberBand ) 1526 rw->setMaskMode( QwtWidgetOverlay::MaskHint ); 1527 else 1528 rw->setMaskMode( QwtWidgetOverlay::AlphaMask ); 1529 1530 rw->updateOverlay(); 1403 1531 } 1404 1532 else 1405 delete rw; 1406 1407 QPointer<PickerWidget> &tw = d_data->trackerWidget; 1533 { 1534 if ( d_data->openGL ) 1535 { 1536 // Qt 4.8 crashes for a delete 1537 if ( !rw.isNull() ) 1538 { 1539 rw->hide(); 1540 rw->deleteLater(); 1541 rw = NULL; 1542 } 1543 } 1544 else 1545 { 1546 delete rw; 1547 } 1548 } 1549 1550 QPointer< QwtPickerTracker > &tw = d_data->trackerOverlay; 1408 1551 if ( showTracker ) 1409 1552 { 1410 1553 if ( tw.isNull() ) 1411 1554 { 1412 tw = new PickerWidget( this, w, PickerWidget::Text ); 1555 tw = new QwtPickerTracker( this, NULL ); // NULL -> no extra event filter 1556 tw->setObjectName( "PickerTracker" ); 1557 tw->setParent( w ); 1413 1558 tw->resize( w->size() ); 1414 1559 } 1415 1560 tw->setFont( d_data->trackerFont ); 1416 tw->updateMask(); 1417 tw->update(); // Needed, when the mask doesn't change 1561 tw->updateOverlay(); 1418 1562 } 1419 1563 else 1420 delete tw; 1421 } 1422 1423 //! \return Widget displaying the rubberband 1424 const QWidget *QwtPicker::rubberBandWidget() const 1425 { 1426 return d_data->rubberBandWidget; 1427 } 1428 1429 //! \return Widget displaying the tracker text 1430 const QWidget *QwtPicker::trackerWidget() const 1431 { 1432 return d_data->trackerWidget; 1433 } 1434 1564 { 1565 if ( d_data->openGL ) 1566 { 1567 // Qt 4.8 crashes for a delete 1568 if ( !tw.isNull() ) 1569 { 1570 tw->hide(); 1571 tw->deleteLater(); 1572 tw = NULL; 1573 } 1574 } 1575 else 1576 { 1577 delete tw; 1578 } 1579 } 1580 } 1581 1582 //! \return Overlay displaying the rubber band 1583 const QwtWidgetOverlay *QwtPicker::rubberBandOverlay() const 1584 { 1585 return d_data->rubberBandOverlay; 1586 } 1587 1588 //! \return Overlay displaying the tracker text 1589 const QwtWidgetOverlay *QwtPicker::trackerOverlay() const 1590 { 1591 return d_data->trackerOverlay; 1592 } 1593 -
trunk/BNC/qwt/qwt_picker.h
r4271 r8127 18 18 #include <qfont.h> 19 19 #include <qrect.h> 20 #include <qpainterpath.h> 20 21 21 22 class QWidget; … … 24 25 class QKeyEvent; 25 26 class QwtPickerMachine; 27 class QwtWidgetOverlay; 26 28 27 29 /*! … … 48 50 49 51 QwtPicker translates the picked points into a selection using the 50 adjustedPoints method. adjustedPointsis intended to be reimplemented51 to fix up the selection according to application specific requirements.52 adjustedPoints() method. adjustedPoints() is intended to be reimplemented 53 to fix up the selection according to application specific requirements. 52 54 (F.e. when an application accepts rectangles of a fixed aspect ratio only.) 53 55 54 56 Optionally QwtPicker support the process of collecting points by a 55 rubber band and tracker displaying a text for the current mouse57 rubber band and tracker displaying a text for the current mouse 56 58 position. 57 59 … … 79 81 80 82 The picker is active (isActive()), between begin() and end(). 81 In active state the rubber band is displayed, and the tracker is visible83 In active state the rubber band is displayed, and the tracker is visible 82 84 in case of trackerMode is ActiveOnly or AlwaysOn. 83 85 … … 95 97 Q_OBJECT 96 98 97 Q_ENUMS( RubberBand ) 98 Q_ENUMS( DisplayMode ) 99 Q_ENUMS( ResizeMode ) 99 Q_ENUMS( RubberBand DisplayMode ResizeMode ) 100 100 101 101 Q_PROPERTY( bool isEnabled READ isEnabled WRITE setEnabled ) … … 111 111 public: 112 112 /*! 113 Rubber band style113 Rubber band style 114 114 115 115 The default value is QwtPicker::NoRubberBand. … … 122 122 NoRubberBand = 0, 123 123 124 //! A horizontal line ( only for QwtPicker ::PointSelection )124 //! A horizontal line ( only for QwtPickerMachine::PointSelection ) 125 125 HLineRubberBand, 126 126 127 //! A vertical line ( only for QwtPicker ::PointSelection )127 //! A vertical line ( only for QwtPickerMachine::PointSelection ) 128 128 VLineRubberBand, 129 129 130 //! A crosshair ( only for QwtPicker ::PointSelection )130 //! A crosshair ( only for QwtPickerMachine::PointSelection ) 131 131 CrossRubberBand, 132 132 133 //! A rectangle ( only for QwtPicker ::RectSelection )133 //! A rectangle ( only for QwtPickerMachine::RectSelection ) 134 134 RectRubberBand, 135 135 136 //! An ellipse ( only for QwtPicker ::RectSelection )136 //! An ellipse ( only for QwtPickerMachine::RectSelection ) 137 137 EllipseRubberBand, 138 138 139 //! A polygon ( only for QwtPicker ::&PolygonSelection )139 //! A polygon ( only for QwtPickerMachine::PolygonSelection ) 140 140 PolygonRubberBand, 141 141 … … 216 216 const QWidget *parentWidget() const; 217 217 218 virtual Q Rect pickRect() const;218 virtual QPainterPath pickArea() const; 219 219 220 220 virtual void drawRubberBand( QPainter * ) const; 221 221 virtual void drawTracker( QPainter * ) const; 222 223 virtual QRegion rubberBandMask() const; 222 224 223 225 virtual QwtText trackerText( const QPoint &pos ) const; … … 269 271 selection has been removed. 270 272 273 \param pos Position of the point, that has been removed 271 274 \sa remove(), appended() 272 275 */ … … 310 313 virtual void updateDisplay(); 311 314 312 const Q Widget *rubberBandWidget() const;313 const Q Widget *trackerWidget() const;315 const QwtWidgetOverlay *rubberBandOverlay() const; 316 const QwtWidgetOverlay *trackerOverlay() const; 314 317 315 318 const QPolygon &pickedPoints() const; … … 320 323 void setMouseTracking( bool ); 321 324 322 class PickerWidget;323 325 class PrivateData; 324 326 PrivateData *d_data; -
trunk/BNC/qwt/qwt_picker_machine.cpp
r4271 r8127 98 98 //! Transition 99 99 QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition( 100 const QwtEventPattern &eventPattern, const QEvent *e )101 { 102 QList<QwtPickerMachine::Command> cmdList; 103 104 switch ( e ->type() )100 const QwtEventPattern &eventPattern, const QEvent *event ) 101 { 102 QList<QwtPickerMachine::Command> cmdList; 103 104 switch ( event->type() ) 105 105 { 106 106 case QEvent::MouseButtonPress: 107 107 { 108 if ( eventPattern.mouseMatch( 109 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e) )108 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 109 static_cast<const QMouseEvent *>( event ) ) ) 110 110 { 111 111 cmdList += Begin; … … 117 117 case QEvent::KeyPress: 118 118 { 119 if ( eventPattern.keyMatch( 120 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) 121 { 122 cmdList += Begin; 123 cmdList += Append; 124 cmdList += End; 119 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event ); 120 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 121 { 122 if ( !keyEvent->isAutoRepeat() ) 123 { 124 cmdList += Begin; 125 cmdList += Append; 126 cmdList += End; 127 } 125 128 } 126 129 break; … … 141 144 //! Transition 142 145 QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition( 143 const QwtEventPattern &eventPattern, const QEvent *e )144 { 145 QList<QwtPickerMachine::Command> cmdList; 146 147 switch ( e ->type() )146 const QwtEventPattern &eventPattern, const QEvent *event ) 147 { 148 QList<QwtPickerMachine::Command> cmdList; 149 150 switch ( event->type() ) 148 151 { 149 152 case QEvent::MouseButtonPress: 150 153 { 151 if ( eventPattern.mouseMatch( 152 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e) )154 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 155 static_cast<const QMouseEvent *>( event ) ) ) 153 156 { 154 157 if ( state() == 0 ) … … 179 182 case QEvent::KeyPress: 180 183 { 181 if ( eventPattern.keyMatch( 182 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) 183 { 184 if ( state() == 0 ) 185 { 186 cmdList += Begin; 187 cmdList += Append; 188 setState( 1 ); 189 } 190 else 191 { 192 cmdList += End; 193 setState( 0 ); 184 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event ); 185 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 186 { 187 if ( !keyEvent->isAutoRepeat() ) 188 { 189 if ( state() == 0 ) 190 { 191 cmdList += Begin; 192 cmdList += Append; 193 setState( 1 ); 194 } 195 else 196 { 197 cmdList += End; 198 setState( 0 ); 199 } 194 200 } 195 201 } … … 211 217 //! Transition 212 218 QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition( 213 const QwtEventPattern &eventPattern, const QEvent *e )214 { 215 QList<QwtPickerMachine::Command> cmdList; 216 217 switch ( e ->type() )219 const QwtEventPattern &eventPattern, const QEvent *event ) 220 { 221 QList<QwtPickerMachine::Command> cmdList; 222 223 switch ( event->type() ) 218 224 { 219 225 case QEvent::MouseButtonPress: 220 226 { 221 if ( eventPattern.mouseMatch( 222 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e) )227 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 228 static_cast<const QMouseEvent *>( event ) ) ) 223 229 { 224 230 switch ( state() ) … … 243 249 } 244 250 } 251 break; 245 252 } 246 253 case QEvent::MouseMove: … … 253 260 case QEvent::MouseButtonRelease: 254 261 { 255 if ( eventPattern.mouseMatch( 256 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e) )262 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 263 static_cast<const QMouseEvent *>( event ) ) ) 257 264 { 258 265 if ( state() == 1 ) … … 266 273 case QEvent::KeyPress: 267 274 { 268 if ( eventPattern.keyMatch( 269 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) 275 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event ); 276 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 277 { 278 if ( !keyEvent->isAutoRepeat() ) 279 { 280 if ( state() == 0 ) 281 { 282 cmdList += Begin; 283 cmdList += Append; 284 setState( 1 ); 285 } 286 else 287 { 288 if ( state() == 1 ) 289 { 290 cmdList += Append; 291 setState( 2 ); 292 } 293 else if ( state() == 2 ) 294 { 295 cmdList += End; 296 setState( 0 ); 297 } 298 } 299 } 300 } 301 break; 302 } 303 default: 304 break; 305 } 306 307 return cmdList; 308 } 309 310 //! Constructor 311 QwtPickerDragRectMachine::QwtPickerDragRectMachine(): 312 QwtPickerMachine( RectSelection ) 313 { 314 } 315 316 //! Transition 317 QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition( 318 const QwtEventPattern &eventPattern, const QEvent *event ) 319 { 320 QList<QwtPickerMachine::Command> cmdList; 321 322 switch ( event->type() ) 323 { 324 case QEvent::MouseButtonPress: 325 { 326 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 327 static_cast<const QMouseEvent *>( event ) ) ) 270 328 { 271 329 if ( state() == 0 ) … … 273 331 cmdList += Begin; 274 332 cmdList += Append; 333 cmdList += Append; 334 setState( 2 ); 335 } 336 } 337 break; 338 } 339 case QEvent::MouseMove: 340 case QEvent::Wheel: 341 { 342 if ( state() != 0 ) 343 cmdList += Move; 344 break; 345 } 346 case QEvent::MouseButtonRelease: 347 { 348 if ( state() == 2 ) 349 { 350 cmdList += End; 351 setState( 0 ); 352 } 353 break; 354 } 355 case QEvent::KeyPress: 356 { 357 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, 358 static_cast<const QKeyEvent *> ( event ) ) ) 359 { 360 if ( state() == 0 ) 361 { 362 cmdList += Begin; 363 cmdList += Append; 364 cmdList += Append; 365 setState( 2 ); 366 } 367 else 368 { 369 cmdList += End; 370 setState( 0 ); 371 } 372 } 373 break; 374 } 375 default: 376 break; 377 } 378 379 return cmdList; 380 } 381 382 //! Constructor 383 QwtPickerPolygonMachine::QwtPickerPolygonMachine(): 384 QwtPickerMachine( PolygonSelection ) 385 { 386 } 387 388 //! Transition 389 QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition( 390 const QwtEventPattern &eventPattern, const QEvent *event ) 391 { 392 QList<QwtPickerMachine::Command> cmdList; 393 394 switch ( event->type() ) 395 { 396 case QEvent::MouseButtonPress: 397 { 398 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 399 static_cast<const QMouseEvent *>( event ) ) ) 400 { 401 if ( state() == 0 ) 402 { 403 cmdList += Begin; 404 cmdList += Append; 405 cmdList += Append; 275 406 setState( 1 ); 276 407 } 277 408 else 278 409 { 410 cmdList += Append; 411 } 412 } 413 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2, 414 static_cast<const QMouseEvent *>( event ) ) ) 415 { 416 if ( state() == 1 ) 417 { 418 cmdList += End; 419 setState( 0 ); 420 } 421 } 422 break; 423 } 424 case QEvent::MouseMove: 425 case QEvent::Wheel: 426 { 427 if ( state() != 0 ) 428 cmdList += Move; 429 break; 430 } 431 case QEvent::KeyPress: 432 { 433 const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event ); 434 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) ) 435 { 436 if ( !keyEvent->isAutoRepeat() ) 437 { 438 if ( state() == 0 ) 439 { 440 cmdList += Begin; 441 cmdList += Append; 442 cmdList += Append; 443 setState( 1 ); 444 } 445 else 446 { 447 cmdList += Append; 448 } 449 } 450 } 451 else if ( eventPattern.keyMatch( QwtEventPattern::KeySelect2, keyEvent ) ) 452 { 453 if ( !keyEvent->isAutoRepeat() ) 454 { 279 455 if ( state() == 1 ) 280 {281 cmdList += Append;282 setState( 2 );283 }284 else if ( state() == 2 )285 456 { 286 457 cmdList += End; … … 299 470 300 471 //! Constructor 301 QwtPickerDrag RectMachine::QwtPickerDragRectMachine():302 QwtPickerMachine( RectSelection )303 { 304 } 305 306 //! Transition 307 QList<QwtPickerMachine::Command> QwtPickerDrag RectMachine::transition(308 const QwtEventPattern &eventPattern, const QEvent *e )309 { 310 QList<QwtPickerMachine::Command> cmdList; 311 312 switch ( e->type() )472 QwtPickerDragLineMachine::QwtPickerDragLineMachine(): 473 QwtPickerMachine( PolygonSelection ) 474 { 475 } 476 477 //! Transition 478 QList<QwtPickerMachine::Command> QwtPickerDragLineMachine::transition( 479 const QwtEventPattern &eventPattern, const QEvent *event ) 480 { 481 QList<QwtPickerMachine::Command> cmdList; 482 483 switch( event->type() ) 313 484 { 314 485 case QEvent::MouseButtonPress: 315 486 { 316 if ( eventPattern.mouseMatch( 317 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e) )487 if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1, 488 static_cast<const QMouseEvent *>( event ) ) ) 318 489 { 319 490 if ( state() == 0 ) … … 322 493 cmdList += Append; 323 494 cmdList += Append; 324 setState( 2 ); 495 setState( 1 ); 496 } 497 } 498 break; 499 } 500 case QEvent::KeyPress: 501 { 502 if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, 503 static_cast<const QKeyEvent *> ( event ) ) ) 504 { 505 if ( state() == 0 ) 506 { 507 cmdList += Begin; 508 cmdList += Append; 509 cmdList += Append; 510 setState( 1 ); 511 } 512 else 513 { 514 cmdList += End; 515 setState( 0 ); 325 516 } 326 517 } … … 332 523 if ( state() != 0 ) 333 524 cmdList += Move; 525 334 526 break; 335 527 } 336 528 case QEvent::MouseButtonRelease: 337 529 { 338 if ( state() == 2)530 if ( state() != 0 ) 339 531 { 340 532 cmdList += End; 341 533 setState( 0 ); 342 534 } 343 break; 344 } 345 case QEvent::KeyPress: 346 { 347 if ( eventPattern.keyMatch( 348 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) 349 { 350 if ( state() == 0 ) 351 { 352 cmdList += Begin; 353 cmdList += Append; 354 cmdList += Append; 355 setState( 2 ); 356 } 357 else 358 { 359 cmdList += End; 360 setState( 0 ); 361 } 362 } 363 break; 364 } 365 default: 366 break; 367 } 368 369 return cmdList; 370 } 371 372 //! Constructor 373 QwtPickerPolygonMachine::QwtPickerPolygonMachine(): 374 QwtPickerMachine( PolygonSelection ) 375 { 376 } 377 378 //! Transition 379 QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition( 380 const QwtEventPattern &eventPattern, const QEvent *e ) 381 { 382 QList<QwtPickerMachine::Command> cmdList; 383 384 switch ( e->type() ) 385 { 386 case QEvent::MouseButtonPress: 387 { 388 if ( eventPattern.mouseMatch( 389 QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) 390 { 391 if ( state() == 0 ) 392 { 393 cmdList += Begin; 394 cmdList += Append; 395 cmdList += Append; 396 setState( 1 ); 397 } 398 else 399 { 400 cmdList += End; 401 setState( 0 ); 402 } 403 } 404 if ( eventPattern.mouseMatch( 405 QwtEventPattern::MouseSelect2, ( const QMouseEvent * )e ) ) 406 { 407 if ( state() == 1 ) 408 cmdList += Append; 409 } 410 break; 411 } 412 case QEvent::MouseMove: 413 case QEvent::Wheel: 414 { 415 if ( state() != 0 ) 416 cmdList += Move; 417 break; 418 } 419 case QEvent::KeyPress: 420 { 421 if ( eventPattern.keyMatch( 422 QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) 423 { 424 if ( state() == 0 ) 425 { 426 cmdList += Begin; 427 cmdList += Append; 428 cmdList += Append; 429 setState( 1 ); 430 } 431 else 432 { 433 cmdList += End; 434 setState( 0 ); 435 } 436 } 437 else if ( eventPattern.keyMatch( 438 QwtEventPattern::KeySelect2, ( const QKeyEvent * )e ) ) 439 { 440 if ( state() == 1 ) 441 cmdList += Append; 442 } 443 break; 444 } 445 default: 446 break; 447 } 448 449 return cmdList; 450 } 535 } 536 default: 537 break; 538 } 539 540 return cmdList; 541 } -
trunk/BNC/qwt/qwt_picker_machine.h
r4271 r8127 169 169 170 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 QwtPickerDragLineMachine(); 189 190 virtual QList<Command> transition( 191 const QwtEventPattern &, const QEvent * ); 192 }; 193 194 /*! 171 195 \brief A state machine for polygon selections 172 196 -
trunk/BNC/qwt/qwt_plot.cpp
r4271 r8127 15 15 #include "qwt_text_label.h" 16 16 #include "qwt_legend.h" 17 #include "qwt_ dyngrid_layout.h"17 #include "qwt_legend_data.h" 18 18 #include "qwt_plot_canvas.h" 19 #include <qmath.h> 19 20 #include <qpainter.h> 20 21 #include <qpointer.h> … … 23 24 #include <qevent.h> 24 25 26 static inline void qwtEnableLegendItems( QwtPlot *plot, bool on ) 27 { 28 if ( on ) 29 { 30 QObject::connect( 31 plot, SIGNAL( legendDataChanged( 32 const QVariant &, const QList<QwtLegendData> & ) ), 33 plot, SLOT( updateLegendItems( 34 const QVariant &, const QList<QwtLegendData> & ) ) ); 35 } 36 else 37 { 38 QObject::disconnect( 39 plot, SIGNAL( legendDataChanged( 40 const QVariant &, const QList<QwtLegendData> & ) ), 41 plot, SLOT( updateLegendItems( 42 const QVariant &, const QList<QwtLegendData> & ) ) ); 43 } 44 } 45 46 static void qwtSetTabOrder( 47 QWidget *first, QWidget *second, bool withChildren ) 48 { 49 QList<QWidget *> tabChain; 50 tabChain += first; 51 tabChain += second; 52 53 if ( withChildren ) 54 { 55 QList<QWidget *> children = second->findChildren<QWidget *>(); 56 57 QWidget *w = second->nextInFocusChain(); 58 while ( children.contains( w ) ) 59 { 60 children.removeAll( w ); 61 62 tabChain += w; 63 w = w->nextInFocusChain(); 64 } 65 } 66 67 for ( int i = 0; i < tabChain.size() - 1; i++ ) 68 { 69 QWidget *from = tabChain[i]; 70 QWidget *to = tabChain[i+1]; 71 72 const Qt::FocusPolicy policy1 = from->focusPolicy(); 73 const Qt::FocusPolicy policy2 = to->focusPolicy(); 74 75 QWidget *proxy1 = from->focusProxy(); 76 QWidget *proxy2 = to->focusProxy(); 77 78 from->setFocusPolicy( Qt::TabFocus ); 79 from->setFocusProxy( NULL); 80 81 to->setFocusPolicy( Qt::TabFocus ); 82 to->setFocusProxy( NULL); 83 84 QWidget::setTabOrder( from, to ); 85 86 from->setFocusPolicy( policy1 ); 87 from->setFocusProxy( proxy1); 88 89 to->setFocusPolicy( policy2 ); 90 to->setFocusProxy( proxy2 ); 91 } 92 } 93 25 94 class QwtPlot::PrivateData 26 95 { 27 96 public: 28 QPointer<QwtTextLabel> lblTitle; 29 QPointer<QwtPlotCanvas> canvas; 30 QPointer<QwtLegend> legend; 97 QPointer<QwtTextLabel> titleLabel; 98 QPointer<QwtTextLabel> footerLabel; 99 QPointer<QWidget> canvas; 100 QPointer<QwtAbstractLegend> legend; 31 101 QwtPlotLayout *layout; 32 102 … … 58 128 QwtPlot::~QwtPlot() 59 129 { 130 setAutoReplot( false ); 60 131 detachItems( QwtPlotItem::Rtti_PlotItem, autoDelete() ); 61 132 … … 76 147 d_data->autoReplot = false; 77 148 78 d_data->lblTitle = new QwtTextLabel( title, this );79 d_data-> lblTitle->setObjectName( "QwtPlotTitle");80 81 d_data-> lblTitle->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );149 // title 150 d_data->titleLabel = new QwtTextLabel( this ); 151 d_data->titleLabel->setObjectName( "QwtPlotTitle" ); 152 d_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) ); 82 153 83 154 QwtText text( title ); 84 155 text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); 85 d_data->lblTitle->setText( text ); 86 156 d_data->titleLabel->setText( text ); 157 158 // footer 159 d_data->footerLabel = new QwtTextLabel( this ); 160 d_data->footerLabel->setObjectName( "QwtPlotFooter" ); 161 162 QwtText footer; 163 footer.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); 164 d_data->footerLabel->setText( footer ); 165 166 // legend 87 167 d_data->legend = NULL; 88 168 169 // axis 89 170 initAxesData(); 90 171 172 // canvas 91 173 d_data->canvas = new QwtPlotCanvas( this ); 92 174 d_data->canvas->setObjectName( "QwtPlotCanvas" ); 93 d_data->canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 94 d_data->canvas->setLineWidth( 2 ); 95 96 updateTabOrder(); 175 d_data->canvas->installEventFilter( this ); 97 176 98 177 setSizePolicy( QSizePolicy::MinimumExpanding, … … 100 179 101 180 resize( 200, 200 ); 181 182 QList<QWidget *> focusChain; 183 focusChain << this << d_data->titleLabel << axisWidget( xTop ) 184 << axisWidget( yLeft ) << d_data->canvas << axisWidget( yRight ) 185 << axisWidget( xBottom ) << d_data->footerLabel; 186 187 for ( int i = 0; i < focusChain.size() - 1; i++ ) 188 qwtSetTabOrder( focusChain[i], focusChain[i+1], false ); 189 190 qwtEnableLegendItems( this, true ); 191 } 192 193 /*! 194 \brief Set the drawing canvas of the plot widget 195 196 QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ). 197 In opposite to using conventional C++ techniques like virtual methods 198 they allow to use canvas implementations that are derived from 199 QWidget or QGLWidget. 200 201 The following meta methods could be implemented: 202 203 - replot() 204 When the canvas doesn't offer a replot method, QwtPlot calls 205 update() instead. 206 207 - borderPath() 208 The border path is necessary to clip the content of the canvas 209 When the canvas doesn't have any special border ( f.e rounded corners ) 210 it is o.k. not to implement this method. 211 212 The default canvas is a QwtPlotCanvas 213 214 \param canvas Canvas Widget 215 \sa canvas() 216 */ 217 void QwtPlot::setCanvas( QWidget *canvas ) 218 { 219 if ( canvas == d_data->canvas ) 220 return; 221 222 delete d_data->canvas; 223 d_data->canvas = canvas; 224 225 if ( canvas ) 226 { 227 canvas->setParent( this ); 228 canvas->installEventFilter( this ); 229 230 if ( isVisible() ) 231 canvas->show(); 232 } 102 233 } 103 234 … … 105 236 \brief Adds handling of layout requests 106 237 \param event Event 238 239 \return See QFrame::event() 107 240 */ 108 241 bool QwtPlot::event( QEvent *event ) … … 122 255 } 123 256 257 /*! 258 \brief Event filter 259 260 The plot handles the following events for the canvas: 261 262 - QEvent::Resize 263 The canvas margins might depend on its size 264 265 - QEvent::ContentsRectChange 266 The layout needs to be recalculated 267 268 \param object Object to be filtered 269 \param event Event 270 271 \return See QFrame::eventFilter() 272 273 \sa updateCanvasMargins(), updateLayout() 274 */ 275 bool QwtPlot::eventFilter( QObject *object, QEvent *event ) 276 { 277 if ( object == d_data->canvas ) 278 { 279 if ( event->type() == QEvent::Resize ) 280 { 281 updateCanvasMargins(); 282 } 283 else if ( event->type() == QEvent::ContentsRectChange ) 284 { 285 updateLayout(); 286 } 287 } 288 289 return QFrame::eventFilter( object, event ); 290 } 291 124 292 //! Replots the plot if autoReplot() is \c true. 125 293 void QwtPlot::autoRefresh() … … 164 332 void QwtPlot::setTitle( const QString &title ) 165 333 { 166 if ( title != d_data-> lblTitle->text().text() )167 { 168 d_data-> lblTitle->setText( title );334 if ( title != d_data->titleLabel->text().text() ) 335 { 336 d_data->titleLabel->setText( title ); 169 337 updateLayout(); 170 338 } … … 177 345 void QwtPlot::setTitle( const QwtText &title ) 178 346 { 179 if ( title != d_data-> lblTitle->text() )180 { 181 d_data-> lblTitle->setText( title );347 if ( title != d_data->titleLabel->text() ) 348 { 349 d_data->titleLabel->setText( title ); 182 350 updateLayout(); 183 351 } 184 352 } 185 353 186 //! \return the plot's title354 //! \return Title of the plot 187 355 QwtText QwtPlot::title() const 188 356 { 189 return d_data->lblTitle->text(); 190 } 191 192 //! \return the plot's title 357 return d_data->titleLabel->text(); 358 } 359 360 //! \return Title label widget. 361 QwtTextLabel *QwtPlot::titleLabel() 362 { 363 return d_data->titleLabel; 364 } 365 366 //! \return Title label widget. 367 const QwtTextLabel *QwtPlot::titleLabel() const 368 { 369 return d_data->titleLabel; 370 } 371 372 /*! 373 Change the text the footer 374 \param text New text of the footer 375 */ 376 void QwtPlot::setFooter( const QString &text ) 377 { 378 if ( text != d_data->footerLabel->text().text() ) 379 { 380 d_data->footerLabel->setText( text ); 381 updateLayout(); 382 } 383 } 384 385 /*! 386 Change the text the footer 387 \param text New text of the footer 388 */ 389 void QwtPlot::setFooter( const QwtText &text ) 390 { 391 if ( text != d_data->footerLabel->text() ) 392 { 393 d_data->footerLabel->setText( text ); 394 updateLayout(); 395 } 396 } 397 398 //! \return Text of the footer 399 QwtText QwtPlot::footer() const 400 { 401 return d_data->footerLabel->text(); 402 } 403 404 //! \return Footer label widget. 405 QwtTextLabel *QwtPlot::footerLabel() 406 { 407 return d_data->footerLabel; 408 } 409 410 //! \return Footer label widget. 411 const QwtTextLabel *QwtPlot::footerLabel() const 412 { 413 return d_data->footerLabel; 414 } 415 416 /*! 417 \brief Assign a new plot layout 418 419 \param layout Layout() 420 \sa plotLayout() 421 */ 422 void QwtPlot::setPlotLayout( QwtPlotLayout *layout ) 423 { 424 if ( layout != d_data->layout ) 425 { 426 delete d_data->layout; 427 d_data->layout = layout; 428 429 updateLayout(); 430 } 431 } 432 433 //! \return the plot's layout 193 434 QwtPlotLayout *QwtPlot::plotLayout() 194 435 { … … 196 437 } 197 438 198 //! \return the plot's titel label.439 //! \return the plot's layout 199 440 const QwtPlotLayout *QwtPlot::plotLayout() const 200 441 { 201 442 return d_data->layout; 202 }203 204 //! \return the plot's titel label.205 QwtTextLabel *QwtPlot::titleLabel()206 {207 return d_data->lblTitle;208 }209 210 /*!211 \return the plot's titel label.212 */213 const QwtTextLabel *QwtPlot::titleLabel() const214 {215 return d_data->lblTitle;216 443 } 217 444 … … 220 447 \sa insertLegend() 221 448 */ 222 Qwt Legend *QwtPlot::legend()449 QwtAbstractLegend *QwtPlot::legend() 223 450 { 224 451 return d_data->legend; … … 229 456 \sa insertLegend() 230 457 */ 231 const Qwt Legend *QwtPlot::legend() const458 const QwtAbstractLegend *QwtPlot::legend() const 232 459 { 233 460 return d_data->legend; … … 238 465 \return the plot's canvas 239 466 */ 240 Q wtPlotCanvas*QwtPlot::canvas()467 QWidget *QwtPlot::canvas() 241 468 { 242 469 return d_data->canvas; … … 246 473 \return the plot's canvas 247 474 */ 248 const Q wtPlotCanvas*QwtPlot::canvas() const475 const QWidget *QwtPlot::canvas() const 249 476 { 250 477 return d_data->canvas; … … 252 479 253 480 /*! 254 Return sizeHint481 \return Size hint for the plot widget 255 482 \sa minimumSizeHint() 256 483 */ 257 258 484 QSize QwtPlot::sizeHint() const 259 485 { … … 316 542 be refreshed explicitly in order to make changes visible. 317 543 318 \sa setAutoReplot() 319 \warning Calls canvas()->repaint, take care of infinite recursions 544 \sa updateAxes(), setAutoReplot() 320 545 */ 321 546 void QwtPlot::replot() … … 333 558 QApplication::sendPostedEvents( this, QEvent::LayoutRequest ); 334 559 335 d_data->canvas->replot(); 560 if ( d_data->canvas ) 561 { 562 const bool ok = QMetaObject::invokeMethod( 563 d_data->canvas, "replot", Qt::DirectConnection ); 564 if ( !ok ) 565 { 566 // fallback, when canvas has no a replot method 567 d_data->canvas->update( d_data->canvas->contentsRect() ); 568 } 569 } 336 570 337 571 setAutoReplot( doAutoReplot ); … … 347 581 348 582 QRect titleRect = d_data->layout->titleRect().toRect(); 583 QRect footerRect = d_data->layout->footerRect().toRect(); 349 584 QRect scaleRect[QwtPlot::axisCnt]; 350 585 for ( int axisId = 0; axisId < axisCnt; axisId++ ) … … 353 588 QRect canvasRect = d_data->layout->canvasRect().toRect(); 354 589 355 //356 590 // resize and show the visible widgets 357 // 358 if ( !d_data-> lblTitle->text().isEmpty() )359 { 360 d_data-> lblTitle->setGeometry( titleRect );361 if ( !d_data-> lblTitle->isVisibleTo( this ) )362 d_data-> lblTitle->show();591 592 if ( !d_data->titleLabel->text().isEmpty() ) 593 { 594 d_data->titleLabel->setGeometry( titleRect ); 595 if ( !d_data->titleLabel->isVisibleTo( this ) ) 596 d_data->titleLabel->show(); 363 597 } 364 598 else 365 d_data->lblTitle->hide(); 599 d_data->titleLabel->hide(); 600 601 if ( !d_data->footerLabel->text().isEmpty() ) 602 { 603 d_data->footerLabel->setGeometry( footerRect ); 604 if ( !d_data->footerLabel->isVisibleTo( this ) ) 605 d_data->footerLabel->show(); 606 } 607 else 608 { 609 d_data->footerLabel->hide(); 610 } 366 611 367 612 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 368 613 { 614 QwtScaleWidget* scaleWidget = axisWidget( axisId ); 615 369 616 if ( axisEnabled( axisId ) ) 370 617 { 371 axisWidget( axisId )->setGeometry( scaleRect[axisId] ); 372 618 if ( scaleRect[axisId] != scaleWidget->geometry() ) 619 { 620 scaleWidget->setGeometry( scaleRect[axisId] ); 621 622 int startDist, endDist; 623 scaleWidget->getBorderDistHint( startDist, endDist ); 624 scaleWidget->setBorderDist( startDist, endDist ); 625 } 626 627 #if 1 373 628 if ( axisId == xBottom || axisId == xTop ) 374 629 { 630 // do we need this code any longer ??? 631 375 632 QRegion r( scaleRect[axisId] ); 376 633 if ( axisEnabled( yLeft ) ) 377 r = r.subtract ( QRegion( scaleRect[yLeft] ) );634 r = r.subtracted( QRegion( scaleRect[yLeft] ) ); 378 635 if ( axisEnabled( yRight ) ) 379 r = r.subtract ( QRegion( scaleRect[yRight] ) );380 r.translate( - d_data->layout->scaleRect( axisId ).x(),636 r = r.subtracted( QRegion( scaleRect[yRight] ) ); 637 r.translate( -scaleRect[ axisId ].x(), 381 638 -scaleRect[axisId].y() ); 382 639 383 axisWidget( axisId )->setMask( r );640 scaleWidget->setMask( r ); 384 641 } 385 if ( !axisWidget( axisId )->isVisibleTo( this ) ) 386 axisWidget( axisId )->show(); 642 #endif 643 if ( !scaleWidget->isVisibleTo( this ) ) 644 scaleWidget->show(); 387 645 } 388 646 else 389 axisWidget( axisId )->hide(); 390 } 391 392 if ( d_data->legend && 393 d_data->layout->legendPosition() != ExternalLegend ) 394 { 395 if ( d_data->legend->itemCount() > 0 ) 647 { 648 scaleWidget->hide(); 649 } 650 } 651 652 if ( d_data->legend ) 653 { 654 if ( d_data->legend->isEmpty() ) 655 { 656 d_data->legend->hide(); 657 } 658 else 396 659 { 397 660 d_data->legend->setGeometry( legendRect ); 398 661 d_data->legend->show(); 399 662 } 400 else401 d_data->legend->hide();402 663 } 403 664 … … 406 667 407 668 /*! 408 Update the focus tab order 409 410 The order is changed so that the canvas will be in front of the 411 first legend item, or behind the last legend item - depending 412 on the position of the legend. 413 */ 414 415 void QwtPlot::updateTabOrder() 416 { 417 if ( d_data->canvas->focusPolicy() == Qt::NoFocus ) 418 return; 419 if ( d_data->legend.isNull() 420 || d_data->layout->legendPosition() == ExternalLegend 421 || d_data->legend->legendItems().count() == 0 ) 422 { 423 return; 424 } 425 426 // Depending on the position of the legend the 427 // tab order will be changed that the canvas is 428 // next to the last legend item, or before 429 // the first one. 430 431 const bool canvasFirst = 432 d_data->layout->legendPosition() == QwtPlot::BottomLegend || 433 d_data->layout->legendPosition() == QwtPlot::RightLegend; 434 435 QWidget *previous = NULL; 436 437 QWidget *w = d_data->canvas; 438 while ( ( w = w->nextInFocusChain() ) != d_data->canvas ) 439 { 440 bool isLegendItem = false; 441 if ( w->focusPolicy() != Qt::NoFocus 442 && w->parent() && w->parent() == d_data->legend->contentsWidget() ) 443 { 444 isLegendItem = true; 445 } 446 447 if ( canvasFirst ) 448 { 449 if ( isLegendItem ) 450 break; 451 452 previous = w; 453 } 454 else 455 { 456 if ( isLegendItem ) 457 previous = w; 458 else 459 { 460 if ( previous ) 461 break; 462 } 463 } 464 } 465 466 if ( previous && previous != d_data->canvas ) 467 setTabOrder( previous, d_data->canvas ); 669 \brief Calculate the canvas margins 670 671 \param maps QwtPlot::axisCnt maps, mapping between plot and paint device coordinates 672 \param canvasRect Bounding rectangle where to paint 673 \param left Return parameter for the left margin 674 \param top Return parameter for the top margin 675 \param right Return parameter for the right margin 676 \param bottom Return parameter for the bottom margin 677 678 Plot items might indicate, that they need some extra space 679 at the borders of the canvas by the QwtPlotItem::Margins flag. 680 681 updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint() 682 */ 683 void QwtPlot::getCanvasMarginsHint( 684 const QwtScaleMap maps[], const QRectF &canvasRect, 685 double &left, double &top, double &right, double &bottom) const 686 { 687 left = top = right = bottom = -1.0; 688 689 const QwtPlotItemList& itmList = itemList(); 690 for ( QwtPlotItemIterator it = itmList.begin(); 691 it != itmList.end(); ++it ) 692 { 693 const QwtPlotItem *item = *it; 694 if ( item->testItemAttribute( QwtPlotItem::Margins ) ) 695 { 696 double m[ QwtPlot::axisCnt ]; 697 item->getCanvasMarginHint( 698 maps[ item->xAxis() ], maps[ item->yAxis() ], 699 canvasRect, m[yLeft], m[xTop], m[yRight], m[xBottom] ); 700 701 left = qMax( left, m[yLeft] ); 702 top = qMax( top, m[xTop] ); 703 right = qMax( right, m[yRight] ); 704 bottom = qMax( bottom, m[xBottom] ); 705 } 706 } 707 } 708 709 /*! 710 \brief Update the canvas margins 711 712 Plot items might indicate, that they need some extra space 713 at the borders of the canvas by the QwtPlotItem::Margins flag. 714 715 getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint() 716 */ 717 void QwtPlot::updateCanvasMargins() 718 { 719 QwtScaleMap maps[axisCnt]; 720 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 721 maps[axisId] = canvasMap( axisId ); 722 723 double margins[axisCnt]; 724 getCanvasMarginsHint( maps, canvas()->contentsRect(), 725 margins[yLeft], margins[xTop], margins[yRight], margins[xBottom] ); 726 727 bool doUpdate = false; 728 for ( int axisId = 0; axisId < axisCnt; axisId++ ) 729 { 730 if ( margins[axisId] >= 0.0 ) 731 { 732 const int m = qCeil( margins[axisId] ); 733 plotLayout()->setCanvasMargin( m, axisId); 734 doUpdate = true; 735 } 736 } 737 738 if ( doUpdate ) 739 updateLayout(); 468 740 } 469 741 … … 488 760 /*! 489 761 Redraw the canvas items. 762 490 763 \param painter Painter used for drawing 491 764 \param canvasRect Bounding rectangle where to paint 492 \param map QwtPlot::axisCnt maps, mapping between plot and paint device coordinates 765 \param maps QwtPlot::axisCnt maps, mapping between plot and paint device coordinates 766 767 \note Usually canvasRect is contentsRect() of the plot canvas. 768 Due to a bug in Qt this rectangle might be wrong for certain 769 frame styles ( f.e QFrame::Box ) and it might be necessary to 770 fix the margins manually using QWidget::setContentsMargins() 493 771 */ 494 772 495 773 void QwtPlot::drawItems( QPainter *painter, const QRectF &canvasRect, 496 const QwtScaleMap map [axisCnt] ) const774 const QwtScaleMap maps[axisCnt] ) const 497 775 { 498 776 const QwtPlotItemList& itmList = itemList(); … … 507 785 painter->setRenderHint( QPainter::Antialiasing, 508 786 item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 787 painter->setRenderHint( QPainter::HighQualityAntialiasing, 788 item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 509 789 510 790 item->draw( painter, 511 map [item->xAxis()], map[item->yAxis()],791 maps[item->xAxis()], maps[item->yAxis()], 512 792 canvasRect ); 513 793 … … 532 812 map.setTransformation( axisScaleEngine( axisId )->transformation() ); 533 813 534 const QwtScaleDiv *sd = axisScaleDiv( axisId );535 map.setScaleInterval( sd ->lowerBound(), sd->upperBound() );814 const QwtScaleDiv &sd = axisScaleDiv( axisId ); 815 map.setScaleInterval( sd.lowerBound(), sd.upperBound() ); 536 816 537 817 if ( axisEnabled( axisId ) ) … … 553 833 else 554 834 { 555 int margin = 0;556 if ( !plotLayout()->alignCanvasToScales() )557 margin = plotLayout()->canvasMargin( axisId );558 559 835 const QRect &canvasRect = d_data->canvas->contentsRect(); 560 836 if ( axisId == yLeft || axisId == yRight ) 561 837 { 562 map.setPaintInterval( canvasRect.bottom() - margin, 563 canvasRect.top() + margin ); 838 int top = 0; 839 if ( !plotLayout()->alignCanvasToScale( xTop ) ) 840 top = plotLayout()->canvasMargin( xTop ); 841 842 int bottom = 0; 843 if ( !plotLayout()->alignCanvasToScale( xBottom ) ) 844 bottom = plotLayout()->canvasMargin( xBottom ); 845 846 map.setPaintInterval( canvasRect.bottom() - bottom, 847 canvasRect.top() + top ); 564 848 } 565 849 else 566 850 { 567 map.setPaintInterval( canvasRect.left() + margin, 568 canvasRect.right() - margin ); 569 } 570 } 851 int left = 0; 852 if ( !plotLayout()->alignCanvasToScale( yLeft ) ) 853 left = plotLayout()->canvasMargin( yLeft ); 854 855 int right = 0; 856 if ( !plotLayout()->alignCanvasToScale( yRight ) ) 857 right = plotLayout()->canvasMargin( yRight ); 858 859 map.setPaintInterval( canvasRect.left() + left, 860 canvasRect.right() - right ); 861 } 862 } 863 571 864 return map; 572 865 } … … 575 868 \brief Change the background of the plotting area 576 869 577 Sets brush to QPalette::Window of all color groups of870 Sets brush to QPalette::Window of all color groups of 578 871 the palette of the canvas. Using canvas()->setPalette() 579 872 is a more powerful way to set these colors. … … 585 878 { 586 879 QPalette pal = d_data->canvas->palette(); 587 588 for ( int i = 0; i < QPalette::NColorGroups; i++ ) 589 pal.setBrush( ( QPalette::ColorGroup )i, QPalette::Window, brush ); 880 pal.setBrush( QPalette::Window, brush ); 590 881 591 882 canvas()->setPalette( pal ); … … 606 897 607 898 /*! 608 \brief Change the border width of the plotting area609 610 Nothing else than canvas()->setLineWidth(w),611 left for compatibility only.612 613 \param width New border width614 */615 void QwtPlot::setCanvasLineWidth( int width )616 {617 canvas()->setLineWidth( width );618 updateLayout();619 }620 621 /*!622 Nothing else than: canvas()->lineWidth(),623 left for compatibility only.624 625 \return the border width of the plotting area626 */627 int QwtPlot::canvasLineWidth() const628 {629 return canvas()->lineWidth();630 }631 632 /*!633 899 \return \c true if the specified axis exists, otherwise \c false 634 900 \param axisId axis index … … 637 903 { 638 904 return ( ( axisId >= QwtPlot::yLeft ) && ( axisId < QwtPlot::axisCnt ) ); 639 }640 641 /*!642 Called internally when the legend has been clicked on.643 Emits a legendClicked() signal.644 */645 void QwtPlot::legendItemClicked()646 {647 if ( d_data->legend && sender()->isWidgetType() )648 {649 QwtPlotItem *plotItem =650 ( QwtPlotItem* )d_data->legend->find( ( QWidget * )sender() );651 if ( plotItem )652 Q_EMIT legendClicked( plotItem );653 }654 }655 656 /*!657 Called internally when the legend has been checked658 Emits a legendClicked() signal.659 */660 void QwtPlot::legendItemChecked( bool on )661 {662 if ( d_data->legend && sender()->isWidgetType() )663 {664 QwtPlotItem *plotItem =665 ( QwtPlotItem* )d_data->legend->find( ( QWidget * )sender() );666 if ( plotItem )667 Q_EMIT legendChecked( plotItem, on );668 }669 905 } 670 906 … … 677 913 with a best fit number of columns from left to right. 678 914 679 If pos != QwtPlot::ExternalLegend the plot widget will become 680 parent of the legend. It will be deleted when the plot is deleted, 681 or another legend is set with insertLegend(). 915 insertLegend() will set the plot widget as parent for the legend. 916 The legend will be deleted in the destructor of the plot or when 917 another legend is inserted. 918 919 Legends, that are not inserted into the layout of the plot widget 920 need to connect to the legendDataChanged() signal. Calling updateLegend() 921 initiates this signal for an initial update. When the application code 922 wants to implement its own layout this also needs to be done for 923 rendering plots to a document ( see QwtPlotRenderer ). 682 924 683 925 \param legend Legend 684 926 \param pos The legend's position. For top/left position the number 685 of colum s will be limited to 1, otherwise it will be set to927 of columns will be limited to 1, otherwise it will be set to 686 928 unlimited. 687 929 688 \param ratio Ratio between legend and the bounding rect 689 of title, canvas and axes. The legend will be shr inked930 \param ratio Ratio between legend and the bounding rectangle 931 of title, canvas and axes. The legend will be shrunk 690 932 if it would need more space than the given ratio. 691 933 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 … … 696 938 QwtPlotLayout::setLegendPosition() 697 939 */ 698 void QwtPlot::insertLegend( Qwt Legend *legend,940 void QwtPlot::insertLegend( QwtAbstractLegend *legend, 699 941 QwtPlot::LegendPosition pos, double ratio ) 700 942 { … … 710 952 if ( d_data->legend ) 711 953 { 712 if ( pos != ExternalLegend ) 713 { 714 if ( d_data->legend->parent() != this ) 715 d_data->legend->setParent( this ); 716 } 717 718 const QwtPlotItemList& itmList = itemList(); 719 for ( QwtPlotItemIterator it = itmList.begin(); 720 it != itmList.end(); ++it ) 721 { 722 ( *it )->updateLegend( d_data->legend ); 723 } 724 725 QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>( 726 d_data->legend->contentsWidget()->layout() ); 727 if ( tl ) 954 connect( this, 955 SIGNAL( legendDataChanged( 956 const QVariant &, const QList<QwtLegendData> & ) ), 957 d_data->legend, 958 SLOT( updateLegend( 959 const QVariant &, const QList<QwtLegendData> & ) ) 960 ); 961 962 if ( d_data->legend->parent() != this ) 963 d_data->legend->setParent( this ); 964 965 qwtEnableLegendItems( this, false ); 966 updateLegend(); 967 qwtEnableLegendItems( this, true ); 968 969 QwtLegend *lgd = qobject_cast<QwtLegend *>( legend ); 970 if ( lgd ) 728 971 { 729 972 switch ( d_data->layout->legendPosition() ) … … 731 974 case LeftLegend: 732 975 case RightLegend: 733 tl->setMaxCols( 1 ); // 1 column: align vertical 976 { 977 if ( lgd->maxColumns() == 0 ) 978 lgd->setMaxColumns( 1 ); // 1 column: align vertical 734 979 break; 980 } 735 981 case TopLegend: 736 982 case BottomLegend: 737 tl->setMaxCols( 0 ); // unlimited 983 { 984 lgd->setMaxColumns( 0 ); // unlimited 738 985 break; 739 case ExternalLegend: 986 } 987 default: 740 988 break; 741 989 } 742 990 } 743 } 744 updateTabOrder(); 991 992 QWidget *previousInChain = NULL; 993 switch ( d_data->layout->legendPosition() ) 994 { 995 case LeftLegend: 996 { 997 previousInChain = axisWidget( QwtPlot::xTop ); 998 break; 999 } 1000 case TopLegend: 1001 { 1002 previousInChain = this; 1003 break; 1004 } 1005 case RightLegend: 1006 { 1007 previousInChain = axisWidget( QwtPlot::yRight ); 1008 break; 1009 } 1010 case BottomLegend: 1011 { 1012 previousInChain = footerLabel(); 1013 break; 1014 } 1015 } 1016 1017 if ( previousInChain ) 1018 qwtSetTabOrder( previousInChain, legend, true ); 1019 } 745 1020 } 746 1021 747 1022 updateLayout(); 748 1023 } 1024 1025 /*! 1026 Emit legendDataChanged() for all plot item 1027 1028 \sa QwtPlotItem::legendData(), legendDataChanged() 1029 */ 1030 void QwtPlot::updateLegend() 1031 { 1032 const QwtPlotItemList& itmList = itemList(); 1033 for ( QwtPlotItemIterator it = itmList.begin(); 1034 it != itmList.end(); ++it ) 1035 { 1036 updateLegend( *it ); 1037 } 1038 } 1039 1040 /*! 1041 Emit legendDataChanged() for a plot item 1042 1043 \param plotItem Plot item 1044 \sa QwtPlotItem::legendData(), legendDataChanged() 1045 */ 1046 void QwtPlot::updateLegend( const QwtPlotItem *plotItem ) 1047 { 1048 if ( plotItem == NULL ) 1049 return; 1050 1051 QList<QwtLegendData> legendData; 1052 1053 if ( plotItem->testItemAttribute( QwtPlotItem::Legend ) ) 1054 legendData = plotItem->legendData(); 1055 1056 const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem *>( plotItem) ); 1057 Q_EMIT legendDataChanged( itemInfo, legendData ); 1058 } 1059 1060 /*! 1061 \brief Update all plot items interested in legend attributes 1062 1063 Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest 1064 flag is set. 1065 1066 \param itemInfo Info about the plot item 1067 \param legendData Entries to be displayed for the plot item ( usually 1 ) 1068 1069 \sa QwtPlotItem::LegendInterest, 1070 QwtPlotLegendItem, QwtPlotItem::updateLegend() 1071 */ 1072 void QwtPlot::updateLegendItems( const QVariant &itemInfo, 1073 const QList<QwtLegendData> &legendData ) 1074 { 1075 QwtPlotItem *plotItem = infoToItem( itemInfo ); 1076 if ( plotItem ) 1077 { 1078 const QwtPlotItemList& itmList = itemList(); 1079 for ( QwtPlotItemIterator it = itmList.begin(); 1080 it != itmList.end(); ++it ) 1081 { 1082 QwtPlotItem *item = *it; 1083 if ( item->testItemInterest( QwtPlotItem::LegendInterest ) ) 1084 item->updateLegend( plotItem, legendData ); 1085 } 1086 } 1087 } 1088 1089 /*! 1090 \brief Attach/Detach a plot item 1091 1092 \param plotItem Plot item 1093 \param on When true attach the item, otherwise detach it 1094 */ 1095 void QwtPlot::attachItem( QwtPlotItem *plotItem, bool on ) 1096 { 1097 if ( plotItem->testItemInterest( QwtPlotItem::LegendInterest ) ) 1098 { 1099 // plotItem is some sort of legend 1100 1101 const QwtPlotItemList& itmList = itemList(); 1102 for ( QwtPlotItemIterator it = itmList.begin(); 1103 it != itmList.end(); ++it ) 1104 { 1105 QwtPlotItem *item = *it; 1106 1107 QList<QwtLegendData> legendData; 1108 if ( on && item->testItemAttribute( QwtPlotItem::Legend ) ) 1109 { 1110 legendData = item->legendData(); 1111 plotItem->updateLegend( item, legendData ); 1112 } 1113 } 1114 } 1115 1116 if ( on ) 1117 insertItem( plotItem ); 1118 else 1119 removeItem( plotItem ); 1120 1121 Q_EMIT itemAttached( plotItem, on ); 1122 1123 if ( plotItem->testItemAttribute( QwtPlotItem::Legend ) ) 1124 { 1125 // the item wants to be represented on the legend 1126 1127 if ( on ) 1128 { 1129 updateLegend( plotItem ); 1130 } 1131 else 1132 { 1133 const QVariant itemInfo = itemToInfo( plotItem ); 1134 Q_EMIT legendDataChanged( itemInfo, QList<QwtLegendData>() ); 1135 } 1136 } 1137 1138 autoRefresh(); 1139 } 1140 1141 /*! 1142 \brief Build an information, that can be used to identify 1143 a plot item on the legend. 1144 1145 The default implementation simply wraps the plot item 1146 into a QVariant object. When overloading itemToInfo() 1147 usually infoToItem() needs to reimplemeted too. 1148 1149 \code 1150 QVariant itemInfo; 1151 qVariantSetValue( itemInfo, plotItem ); 1152 \endcode 1153 1154 \param plotItem Plot item 1155 \return Plot item embedded in a QVariant 1156 \sa infoToItem() 1157 */ 1158 QVariant QwtPlot::itemToInfo( QwtPlotItem *plotItem ) const 1159 { 1160 QVariant itemInfo; 1161 qVariantSetValue( itemInfo, plotItem ); 1162 1163 return itemInfo; 1164 } 1165 1166 /*! 1167 \brief Identify the plot item according to an item info object, 1168 that has bee generated from itemToInfo(). 1169 1170 The default implementation simply tries to unwrap a QwtPlotItem 1171 pointer: 1172 1173 \code 1174 if ( itemInfo.canConvert<QwtPlotItem *>() ) 1175 return qvariant_cast<QwtPlotItem *>( itemInfo ); 1176 \endcode 1177 \param itemInfo Plot item 1178 \return A plot item, when successful, otherwise a NULL pointer. 1179 \sa itemToInfo() 1180 */ 1181 QwtPlotItem *QwtPlot::infoToItem( const QVariant &itemInfo ) const 1182 { 1183 if ( itemInfo.canConvert<QwtPlotItem *>() ) 1184 return qvariant_cast<QwtPlotItem *>( itemInfo ); 1185 1186 return NULL; 1187 } 1188 1189 -
trunk/BNC/qwt/qwt_plot.h
r4271 r8127 17 17 #include "qwt_interval.h" 18 18 #include <qframe.h> 19 #include <qlist.h> 20 #include <qvariant.h> 19 21 20 22 class QwtPlotLayout; 21 class Qwt Legend;23 class QwtAbstractLegend; 22 24 class QwtScaleWidget; 23 25 class QwtScaleEngine; … … 25 27 class QwtScaleDraw; 26 28 class QwtTextLabel; 27 class QwtPlotCanvas;28 29 29 30 /*! … … 36 37 from QwtPlotItem. 37 38 A plot can have up to four axes, with each plot item attached to an x- and 38 a y axis. The scales at the axes can be explicit ely set (QwtScaleDiv), or39 a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or 39 40 are calculated from the plot items, using algorithms (QwtScaleEngine) which 40 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. 41 45 42 46 \image html plot.png … … 56 60 QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2"); 57 61 58 // co py the data into the curves62 // connect or copy the data to the curves 59 63 curve1->setData(...); 60 64 curve2->setData(...); … … 71 75 { 72 76 Q_OBJECT 77 78 Q_PROPERTY( QBrush canvasBackground 79 READ canvasBackground WRITE setCanvasBackground ) 80 Q_PROPERTY( bool autoReplot READ autoReplot WRITE setAutoReplot ) 81 82 #if 0 83 // This property is intended to configure the plot 84 // widget from a special dialog in the deigner plugin. 85 // Disabled until such a dialog has been implemented. 86 73 87 Q_PROPERTY( QString propertiesDocument 74 88 READ grabProperties WRITE applyProperties ) 89 #endif 75 90 76 91 public: … … 98 113 99 114 \sa insertLegend() 100 \note In case of ExternalLegend, the legend is not101 handled by QwtPlotRenderer102 115 */ 103 116 enum LegendPosition … … 109 122 RightLegend, 110 123 111 //! The legend will be below QwtPlot::xBottom axis.124 //! The legend will be below the footer 112 125 BottomLegend, 113 126 114 //! The legend will be between QwtPlot::xTop axis and the title. 115 TopLegend, 116 117 /*! 118 External means that only the content of the legend 119 will be handled by QwtPlot, but not its geometry. 120 This type can be used to have a legend in an 121 external window ( or on the canvas ). 122 */ 123 ExternalLegend 127 //! The legend will be above the title 128 TopLegend 124 129 }; 125 130 126 131 explicit QwtPlot( QWidget * = NULL ); 127 explicit QwtPlot( const QwtText &title, QWidget * p= NULL );132 explicit QwtPlot( const QwtText &title, QWidget * = NULL ); 128 133 129 134 virtual ~QwtPlot(); … … 132 137 QString grabProperties() const; 133 138 134 void setAutoReplot( bool tf= true );139 void setAutoReplot( bool = true ); 135 140 bool autoReplot() const; 136 141 137 142 // Layout 143 144 void setPlotLayout( QwtPlotLayout * ); 138 145 139 146 QwtPlotLayout *plotLayout(); … … 149 156 const QwtTextLabel *titleLabel() const; 150 157 158 // Footer 159 160 void setFooter( const QString & ); 161 void setFooter( const QwtText &t ); 162 QwtText footer() const; 163 164 QwtTextLabel *footerLabel(); 165 const QwtTextLabel *footerLabel() const; 166 151 167 // Canvas 152 168 153 QwtPlotCanvas *canvas(); 154 const QwtPlotCanvas *canvas() const; 169 void setCanvas( QWidget * ); 170 171 QWidget *canvas(); 172 const QWidget *canvas() const; 155 173 156 174 void setCanvasBackground( const QBrush & ); 157 175 QBrush canvasBackground() const; 158 159 void setCanvasLineWidth( int w );160 int canvasLineWidth() const;161 176 162 177 virtual QwtScaleMap canvasMap( int axisId ) const; … … 187 202 QwtInterval axisInterval( int axisId ) const; 188 203 189 const QwtScaleDiv *axisScaleDiv( int axisId ) const; 190 QwtScaleDiv *axisScaleDiv( int axisId ); 204 const QwtScaleDiv &axisScaleDiv( int axisId ) const; 191 205 192 206 const QwtScaleDraw *axisScaleDraw( int axisId ) const; … … 211 225 // Legend 212 226 213 void insertLegend( QwtLegend *, LegendPosition = QwtPlot::RightLegend, 214 double ratio = -1.0 ); 215 216 QwtLegend *legend(); 217 const QwtLegend *legend() const; 227 void insertLegend( QwtAbstractLegend *, 228 LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 ); 229 230 QwtAbstractLegend *legend(); 231 const QwtAbstractLegend *legend() const; 232 233 void updateLegend(); 234 void updateLegend( const QwtPlotItem * ); 218 235 219 236 // Misc … … 226 243 227 244 void updateAxes(); 245 void updateCanvasMargins(); 246 247 virtual void getCanvasMarginsHint( 248 const QwtScaleMap maps[], const QRectF &canvasRect, 249 double &left, double &top, double &right, double &bottom) const; 228 250 229 251 virtual bool event( QEvent * ); 252 virtual bool eventFilter( QObject *, QEvent * ); 230 253 231 254 virtual void drawItems( QPainter *, const QRectF &, 232 255 const QwtScaleMap maps[axisCnt] ) const; 233 256 257 virtual QVariant itemToInfo( QwtPlotItem * ) const; 258 virtual QwtPlotItem *infoToItem( const QVariant & ) const; 259 234 260 Q_SIGNALS: 235 261 /*! 236 A signal which is emitted when the user has clicked on 237 a legend item, which is in QwtLegend::ClickableItem mode. 238 239 \param plotItem Corresponding plot item of the 240 selected legend item 241 242 \note clicks are disabled as default 243 \sa QwtLegend::setItemMode(), QwtLegend::itemMode() 262 A signal indicating, that an item has been attached/detached 263 264 \param plotItem Plot item 265 \param on Attached/Detached 244 266 */ 245 void legendClicked( QwtPlotItem *plotItem);267 void itemAttached( QwtPlotItem *plotItem, bool on ); 246 268 247 269 /*! 248 A signal which is emitted when the user has clicked on 249 a legend item, which is in QwtLegend::CheckableItem mode 250 251 \param plotItem Corresponding plot item of the 252 selected legend item 253 \param on True when the legen item is checked 254 255 \note clicks are disabled as default 256 \sa QwtLegend::setItemMode(), QwtLegend::itemMode() 270 A signal with the attributes how to update 271 the legend entries for a plot item. 272 273 \param itemInfo Info about a plot item, build from itemToInfo() 274 \param data Attributes of the entries ( usually <= 1 ) for 275 the plot item. 276 277 \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend() 257 278 */ 258 259 void legendChecked( QwtPlotItem *plotItem, bool on);279 void legendDataChanged( const QVariant &itemInfo, 280 const QList<QwtLegendData> &data ); 260 281 261 282 public Q_SLOTS: … … 263 284 void autoRefresh(); 264 285 265 protected Q_SLOTS:266 virtual void legendItemClicked();267 virtual void legendItemChecked( bool );268 269 286 protected: 270 287 static bool axisValid( int axisId ); 271 288 272 virtual void updateTabOrder();273 274 289 virtual void resizeEvent( QResizeEvent *e ); 275 290 291 private Q_SLOTS: 292 void updateLegendItems( const QVariant &itemInfo, 293 const QList<QwtLegendData> &data ); 294 276 295 private: 296 friend class QwtPlotItem; 297 void attachItem( QwtPlotItem *, bool ); 298 277 299 void initAxesData(); 278 300 void deleteAxesData(); -
trunk/BNC/qwt/qwt_plot_axis.cpp
r4271 r8127 27 27 int maxMinor; 28 28 29 bool isValid; 30 29 31 QwtScaleDiv scaleDiv; 30 32 QwtScaleEngine *scaleEngine; … … 54 56 d_axisData[xBottom]->scaleWidget->setObjectName( "QwtPlotAxisXBottom" ); 55 57 58 #if 1 59 // better find the font sizes from the application font 56 60 QFont fscl( fontInfo().family(), 10 ); 57 61 QFont fttl( fontInfo().family(), 12, QFont::Bold ); 62 #endif 58 63 59 64 for ( axisId = 0; axisId < axisCnt; axisId++ ) 60 65 { 61 66 AxisData &d = *d_axisData[axisId]; 67 68 d.scaleEngine = new QwtLinearScaleEngine; 69 70 d.scaleWidget->setTransformation( 71 d.scaleEngine->transformation() ); 62 72 63 73 d.scaleWidget->setFont( fscl ); … … 77 87 d.maxMajor = 8; 78 88 79 d.scaleEngine = new QwtLinearScaleEngine; 80 81 d.scaleDiv.invalidate(); 89 90 d.isValid = false; 82 91 } 83 92 … … 99 108 100 109 /*! 101 \return specified axis, or NULL if axisId is invalid.102 \param axisId axis index110 \return Scale widget of the specified axis, or NULL if axisId is invalid. 111 \param axisId Axis index 103 112 */ 104 113 const QwtScaleWidget *QwtPlot::axisWidget( int axisId ) const … … 111 120 112 121 /*! 113 \return specified axis, or NULL if axisId is invalid.114 \param axisId axis index122 \return Scale widget of the specified axis, or NULL if axisId is invalid. 123 \param axisId Axis index 115 124 */ 116 125 QwtScaleWidget *QwtPlot::axisWidget( int axisId ) … … 123 132 124 133 /*! 125 126 127 \param axisId axis index134 Change the scale engine for an axis 135 136 \param axisId Axis index 128 137 \param scaleEngine Scale engine 129 138 … … 139 148 d.scaleEngine = scaleEngine; 140 149 141 d.scaleDiv.invalidate(); 150 d_axisData[axisId]->scaleWidget->setTransformation( 151 scaleEngine->transformation() ); 152 153 d.isValid = false; 142 154 143 155 autoRefresh(); … … 146 158 147 159 /*! 148 \param axisId axis index160 \param axisId Axis index 149 161 \return Scale engine for a specific axis 150 162 */ … … 158 170 159 171 /*! 160 \param axisId axis index172 \param axisId Axis index 161 173 \return Scale engine for a specific axis 162 174 */ … … 169 181 } 170 182 /*! 171 \return \c trueif autoscaling is enabled172 \param axisId axis index183 \return \c True, if autoscaling is enabled 184 \param axisId Axis index 173 185 */ 174 186 bool QwtPlot::axisAutoScale( int axisId ) const … … 182 194 183 195 /*! 184 \return \c trueif a specified axis is enabled185 \param axisId axis index196 \return \c True, if a specified axis is enabled 197 \param axisId Axis index 186 198 */ 187 199 bool QwtPlot::axisEnabled( int axisId ) const … … 194 206 195 207 /*! 196 \return the font of the scale labels for a specified axis197 \param axisId axis index208 \return The font of the scale labels for a specified axis 209 \param axisId Axis index 198 210 */ 199 211 QFont QwtPlot::axisFont( int axisId ) const … … 207 219 208 220 /*! 209 \return the maximum number of major ticks for a specified axis210 \param axisId axis index211 \sa setAxisMaxMajor() 221 \return The maximum number of major ticks for a specified axis 222 \param axisId Axis index 223 \sa setAxisMaxMajor(), QwtScaleEngine::divideScale() 212 224 */ 213 225 int QwtPlot::axisMaxMajor( int axisId ) const … … 221 233 /*! 222 234 \return the maximum number of minor ticks for a specified axis 223 \param axisId axis index224 \sa setAxisMaxMinor() 235 \param axisId Axis index 236 \sa setAxisMaxMinor(), QwtScaleEngine::divideScale() 225 237 */ 226 238 int QwtPlot::axisMaxMinor( int axisId ) const … … 235 247 \brief Return the scale division of a specified axis 236 248 237 axisScaleDiv(axisId) ->lowerBound(), axisScaleDiv(axisId)->upperBound()249 axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound() 238 250 are the current limits of the axis scale. 239 251 240 \param axisId axis index252 \param axisId Axis index 241 253 \return Scale division 242 254 243 \sa QwtScaleDiv, setAxisScaleDiv() 244 */ 245 const QwtScaleDiv *QwtPlot::axisScaleDiv( int axisId ) const 255 \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale() 256 */ 257 const QwtScaleDiv &QwtPlot::axisScaleDiv( int axisId ) const 258 { 259 return d_axisData[axisId]->scaleDiv; 260 } 261 262 /*! 263 \brief Return the scale draw of a specified axis 264 265 \param axisId Axis index 266 \return Specified scaleDraw for axis, or NULL if axis is invalid. 267 */ 268 const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const 246 269 { 247 270 if ( !axisValid( axisId ) ) 248 271 return NULL; 249 272 250 return &d_axisData[axisId]->scaleDiv; 251 } 252 253 /*! 254 \brief Return the scale division of a specified axis 255 256 axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound() 257 are the current limits of the axis scale. 258 259 \param axisId axis index 260 \return Scale division 261 262 \sa QwtScaleDiv, setAxisScaleDiv() 263 */ 264 QwtScaleDiv *QwtPlot::axisScaleDiv( int axisId ) 273 return axisWidget( axisId )->scaleDraw(); 274 } 275 276 /*! 277 \brief Return the scale draw of a specified axis 278 279 \param axisId Axis index 280 \return Specified scaleDraw for axis, or NULL if axis is invalid. 281 */ 282 QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) 265 283 { 266 284 if ( !axisValid( axisId ) ) 267 285 return NULL; 268 286 269 return &d_axisData[axisId]->scaleDiv;270 }271 272 /*!273 \returns the scale draw of a specified axis274 \param axisId axis index275 \return specified scaleDraw for axis, or NULL if axis is invalid.276 \sa QwtScaleDraw277 */278 const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const279 {280 if ( !axisValid( axisId ) )281 return NULL;282 283 287 return axisWidget( axisId )->scaleDraw(); 284 288 } 285 289 286 290 /*! 287 \returns the scale draw of a specified axis 288 \param axisId axis index 289 \return specified scaleDraw for axis, or NULL if axis is invalid. 290 \sa QwtScaleDraw 291 */ 292 QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) 293 { 294 if ( !axisValid( axisId ) ) 295 return NULL; 296 297 return axisWidget( axisId )->scaleDraw(); 298 } 299 300 /*! 301 Return the step size parameter, that has been set 302 in setAxisScale. This doesn't need to be the step size 303 of the current scale. 304 305 \param axisId axis index 291 \brief Return the step size parameter that has been set in setAxisScale. 292 293 This doesn't need to be the step size of the current scale. 294 295 \param axisId Axis index 306 296 \return step size parameter value 307 297 308 \sa setAxisScale() 298 \sa setAxisScale(), QwtScaleEngine::divideScale() 309 299 */ 310 300 double QwtPlot::axisStepSize( int axisId ) const … … 321 311 This is only a convenience function for axisScaleDiv( axisId )->interval(); 322 312 323 \param axisId axis index313 \param axisId Axis index 324 314 \return Scale interval 325 315 … … 335 325 336 326 /*! 337 \return the title of a specified axis338 \param axisId axis index327 \return Title of a specified axis 328 \param axisId Axis index 339 329 */ 340 330 QwtText QwtPlot::axisTitle( int axisId ) const … … 355 345 356 346 Only xBottom and yLeft are enabled by default. 357 \param axisId axis index 347 348 \param axisId Axis index 358 349 \param tf \c true (enabled) or \c false (disabled) 359 350 */ … … 370 361 Transform the x or y coordinate of a position in the 371 362 drawing region into a value. 372 \param axisId axis index 363 364 \param axisId Axis index 373 365 \param pos position 366 367 \return Position as axis coordinate 368 374 369 \warning The position can be an x or a y coordinate, 375 370 depending on the specified axis. … … 386 381 /*! 387 382 \brief Transform a value into a coordinate in the plotting region 388 \param axisId axis index 383 384 \param axisId Axis index 389 385 \param value value 390 \return X or ycoordinate in the plotting region corresponding386 \return X or Y coordinate in the plotting region corresponding 391 387 to the value. 392 388 */ … … 401 397 /*! 402 398 \brief Change the font of an axis 403 \param axisId axis index 404 \param f font 399 400 \param axisId Axis index 401 \param font Font 405 402 \warning This function changes the font of the tick labels, 406 403 not of the axis title. 407 404 */ 408 void QwtPlot::setAxisFont( int axisId, const QFont &f )409 { 410 if ( axisValid( axisId ) ) 411 axisWidget( axisId )->setFont( f );405 void QwtPlot::setAxisFont( int axisId, const QFont &font ) 406 { 407 if ( axisValid( axisId ) ) 408 axisWidget( axisId )->setFont( font ); 412 409 } 413 410 … … 418 415 after a fixed scale has been set. Autoscaling is enabled by default. 419 416 420 \param axisId axis index417 \param axisId Axis index 421 418 \param on On/Off 422 419 \sa setAxisScale(), setAxisScaleDiv(), updateAxes() … … 436 433 /*! 437 434 \brief Disable autoscaling and specify a fixed scale for a selected axis. 438 \param axisId axis index 439 \param min 440 \param max minimum and maximum of the scale 435 436 In updateAxes() the scale engine calculates a scale division from the 437 specified parameters, that will be assigned to the scale widget. So 438 updates of the scale widget usually happen delayed with the next replot. 439 440 \param axisId Axis index 441 \param min Minimum of the scale 442 \param max Maximum of the scale 441 443 \param stepSize Major step size. If <code>step == 0</code>, the step size is 442 calculated automatically using the maxMajor setting. 443 \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize() 444 calculated automatically using the maxMajor setting. 445 446 \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale() 444 447 */ 445 448 void QwtPlot::setAxisScale( int axisId, double min, double max, double stepSize ) … … 450 453 451 454 d.doAutoScale = false; 452 d. scaleDiv.invalidate();455 d.isValid = false; 453 456 454 457 d.minValue = min; … … 462 465 /*! 463 466 \brief Disable autoscaling and specify a fixed scale for a selected axis. 464 \param axisId axis index 467 468 The scale division will be stored locally only until the next call 469 of updateAxes(). So updates of the scale widget usually happen delayed with 470 the next replot. 471 472 \param axisId Axis index 465 473 \param scaleDiv Scale division 474 466 475 \sa setAxisScale(), setAxisAutoScale() 467 476 */ … … 474 483 d.doAutoScale = false; 475 484 d.scaleDiv = scaleDiv; 485 d.isValid = true; 476 486 477 487 autoRefresh(); … … 481 491 /*! 482 492 \brief Set a scale draw 483 \param axisId axis index 484 \param scaleDraw object responsible for drawing scales. 493 494 \param axisId Axis index 495 \param scaleDraw Object responsible for drawing scales. 485 496 486 497 By passing scaleDraw it is possible to extend QwtScaleDraw … … 505 516 /*! 506 517 Change the alignment of the tick labels 507 \param axisId axis index 518 519 \param axisId Axis index 508 520 \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h> 521 509 522 \sa QwtScaleDraw::setLabelAlignment() 510 523 */ … … 517 530 /*! 518 531 Rotate all tick labels 519 \param axisId axis index 532 533 \param axisId Axis index 520 534 \param rotation Angle in degrees. When changing the label rotation, 521 535 the label alignment might be adjusted too. 536 522 537 \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment() 523 538 */ … … 531 546 Set the maximum number of minor scale intervals for a specified axis 532 547 533 \param axisId axis index 534 \param maxMinor maximum number of minor steps 548 \param axisId Axis index 549 \param maxMinor Maximum number of minor steps 550 535 551 \sa axisMaxMinor() 536 552 */ … … 545 561 { 546 562 d.maxMinor = maxMinor; 547 d. scaleDiv.invalidate();563 d.isValid = false; 548 564 autoRefresh(); 549 565 } … … 554 570 Set the maximum number of major scale intervals for a specified axis 555 571 556 \param axisId axis index 557 \param maxMajor maximum number of major steps 572 \param axisId Axis index 573 \param maxMajor Maximum number of major steps 574 558 575 \sa axisMaxMajor() 559 576 */ … … 568 585 { 569 586 d.maxMajor = maxMajor; 570 d. scaleDiv.invalidate();587 d.isValid = false; 571 588 autoRefresh(); 572 589 } … … 576 593 /*! 577 594 \brief Change the title of a specified axis 578 \param axisId axis index 595 596 \param axisId Axis index 579 597 \param title axis title 580 598 */ … … 587 605 /*! 588 606 \brief Change the title of a specified axis 589 \param axisId axis index 590 \param title axis title 607 608 \param axisId Axis index 609 \param title Axis title 591 610 */ 592 611 void QwtPlot::setAxisTitle( int axisId, const QwtText &title ) … … 596 615 } 597 616 598 //! Rebuild the scales 617 /*! 618 \brief Rebuild the axes scales 619 620 In case of autoscaling the boundaries of a scale are calculated 621 from the bounding rectangles of all plot items, having the 622 QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ). 623 Then a scale division is calculated ( QwtScaleEngine::didvideScale() ) 624 and assigned to scale widget. 625 626 When the scale boundaries have been assigned with setAxisScale() a 627 scale division is calculated ( QwtScaleEngine::didvideScale() ) 628 for this interval and assigned to the scale widget. 629 630 When the scale has been set explicitly by setAxisScaleDiv() the 631 locally stored scale division gets assigned to the scale widget. 632 633 The scale widget indicates modifications by emitting a 634 QwtScaleWidget::scaleDivChanged() signal. 635 636 updateAxes() is usually called by replot(). 637 638 \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot() 639 QwtPlotItem::boundingRect() 640 */ 599 641 void QwtPlot::updateAxes() 600 642 { … … 620 662 { 621 663 const QRectF rect = item->boundingRect(); 622 intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() ); 623 intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() ); 664 665 if ( rect.width() >= 0.0 ) 666 intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() ); 667 668 if ( rect.height() >= 0.0 ) 669 intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() ); 624 670 } 625 671 } … … 637 683 if ( d.doAutoScale && intv[axisId].isValid() ) 638 684 { 639 d. scaleDiv.invalidate();685 d.isValid = false; 640 686 641 687 minValue = intv[axisId].minValue(); … … 645 691 minValue, maxValue, stepSize ); 646 692 } 647 if ( !d. scaleDiv.isValid())693 if ( !d.isValid ) 648 694 { 649 695 d.scaleDiv = d.scaleEngine->divideScale( 650 696 minValue, maxValue, 651 697 d.maxMajor, d.maxMinor, stepSize ); 698 d.isValid = true; 652 699 } 653 700 654 701 QwtScaleWidget *scaleWidget = axisWidget( axisId ); 655 scaleWidget->setScaleDiv( 656 d.scaleEngine->transformation(), d.scaleDiv ); 702 scaleWidget->setScaleDiv( d.scaleDiv ); 657 703 658 704 int startDist, endDist; … … 664 710 { 665 711 QwtPlotItem *item = *it; 666 item->updateScaleDiv( *axisScaleDiv( item->xAxis() ), 667 *axisScaleDiv( item->yAxis() ) ); 668 } 669 } 670 712 if ( item->testItemInterest( QwtPlotItem::ScaleInterest ) ) 713 { 714 item->updateScaleDiv( axisScaleDiv( item->xAxis() ), 715 axisScaleDiv( item->yAxis() ) ); 716 } 717 } 718 } 719 -
trunk/BNC/qwt/qwt_plot_canvas.cpp
r4271 r8127 18 18 #include <qpaintengine.h> 19 19 #include <qevent.h> 20 #include <qbitmap.h>21 #ifdef Q_WS_X1122 #include <qx11info_x11.h>23 #endif24 20 25 21 class QwtStyleSheetRecorder: public QwtNullPaintDevice … … 27 23 public: 28 24 QwtStyleSheetRecorder( const QSize &size ): 29 QwtNullPaintDevice( QPaintEngine::AllFeatures ) 30 { 31 setSize( size ); 25 d_size( size ) 26 { 32 27 } 33 28 … … 56 51 virtual void drawPath( const QPainterPath &path ) 57 52 { 58 const QRectF rect( QPointF( 0.0, 0.0 ) , size());53 const QRectF rect( QPointF( 0.0, 0.0 ), d_size ); 59 54 if ( path.controlPointRect().contains( rect.center() ) ) 60 55 { … … 117 112 } 118 113 114 protected: 115 virtual QSize sizeMetrics() const 116 { 117 return d_size; 118 } 119 119 120 private: 120 121 void alignCornerRects( const QRectF &rect ) … … 154 155 155 156 private: 157 const QSize d_size; 158 156 159 QPen d_pen; 157 160 QBrush d_brush; … … 159 162 }; 160 163 161 static void qwtDrawBackground( QPainter *painter, QWidget *widget ) 162 { 164 static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas ) 165 { 166 painter->save(); 167 168 const QPainterPath borderClip = canvas->borderPath( canvas->rect() ); 169 if ( !borderClip.isEmpty() ) 170 painter->setClipPath( borderClip, Qt::IntersectClip ); 171 163 172 const QBrush &brush = 164 widget->palette().brush( widget->backgroundRole() );173 canvas->palette().brush( canvas->backgroundRole() ); 165 174 166 175 if ( brush.style() == Qt::TexturePattern ) 167 176 { 168 QPixmap pm( widget->size() );169 pm.fill( widget, 0, 0);177 QPixmap pm( canvas->size() ); 178 QwtPainter::fillPixmap( canvas, pm ); 170 179 painter->drawPixmap( 0, 0, pm ); 171 180 } … … 176 185 if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode ) 177 186 { 178 rects += widget->rect();187 rects += canvas->rect(); 179 188 } 180 189 else … … 215 224 } 216 225 217 QImage image( widget->size(), format );226 QImage image( canvas->size(), format ); 218 227 219 228 QPainter p( &image ); … … 229 238 else 230 239 { 231 painter->save();232 233 240 painter->setPen( Qt::NoPen ); 234 241 painter->setBrush( brush ); 235 242 236 243 painter->drawRects( rects ); 237 238 painter->restore();239 244 } 240 245 } 241 246 else 242 247 { 243 painter->save();244 245 248 painter->setPen( Qt::NoPen ); 246 249 painter->setBrush( brush ); … … 248 251 painter->drawRects( painter->clipRegion().rects() ); 249 252 250 painter->restore(); 251 } 253 } 254 255 painter->restore(); 252 256 } 253 257 … … 256 260 if ( path.elementCount() == 4 ) 257 261 { 258 QPainterPath::Element &el0 = 259 const_cast<QPainterPath::Element &>( path.elementAt(0) ); 260 QPainterPath::Element &el2 = 261 const_cast<QPainterPath::Element &>( path.elementAt(3) ); 262 263 qSwap( el0.x, el2.x ); 264 qSwap( el0.y, el2.y ); 262 QPainterPath::Element el0 = path.elementAt(0); 263 QPainterPath::Element el3 = path.elementAt(3); 264 265 path.setElementPositionAt( 0, el3.x, el3.y ); 266 path.setElementPositionAt( 3, el0.x, el0.y ); 265 267 } 266 268 } … … 439 441 { 440 442 QPixmap pm( rect.size() ); 441 pm.fill( bgWidget, widget->mapTo( bgWidget, rect.topLeft() ) );443 QwtPainter::fillPixmap( bgWidget, pm, widget->mapTo( bgWidget, rect.topLeft() ) ); 442 444 painter->drawPixmap( rect, pm ); 443 445 } … … 468 470 if ( radius > 0.0 ) 469 471 { 470 QSize sz( radius, radius );472 QSizeF sz( radius, radius ); 471 473 472 474 rects += QRectF( r.topLeft(), sz ); … … 519 521 }; 520 522 521 //! Sets a cross cursor, enables QwtPlotCanvas::BackingStore 522 523 /*! 524 \brief Constructor 525 526 \param plot Parent plot widget 527 \sa QwtPlot::setCanvas() 528 */ 523 529 QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ): 524 530 QFrame( plot ) 525 531 { 532 setFrameStyle( QFrame::Panel | QFrame::Sunken ); 533 setLineWidth( 2 ); 534 526 535 d_data = new PrivateData; 527 536 … … 545 554 QwtPlot *QwtPlotCanvas::plot() 546 555 { 547 return qobject_cast<QwtPlot *>( parent Widget() );556 return qobject_cast<QwtPlot *>( parent() ); 548 557 } 549 558 … … 551 560 const QwtPlot *QwtPlotCanvas::plot() const 552 561 { 553 return qobject_cast<const QwtPlot *>( parent Widget() );562 return qobject_cast<const QwtPlot *>( parent() ); 554 563 } 555 564 … … 583 592 if ( isVisible() ) 584 593 { 594 #if QT_VERSION >= 0x050000 595 *d_data->backingStore = grab( rect() ); 596 #else 585 597 *d_data->backingStore = 586 598 QPixmap::grabWidget( this, rect() ); 599 #endif 587 600 } 588 601 } … … 610 623 611 624 /*! 612 Test w ether a paint attribute is enabled625 Test whether a paint attribute is enabled 613 626 614 627 \param attribute Paint attribute 615 \return true if theattribute is enabled628 \return true, when attribute is enabled 616 629 \sa setPaintAttribute() 617 630 */ … … 676 689 /*! 677 690 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 691 678 692 \param event Qt Event 693 \return See QFrame::event() 679 694 */ 680 695 bool QwtPlotCanvas::event( QEvent *event ) … … 716 731 if ( bs.size() != size() ) 717 732 { 718 bs = QPixmap( size() ); 719 720 #ifdef Q_WS_X11 721 if ( bs.x11Info().screen() != x11Info().screen() ) 722 bs.x11SetScreen( x11Info().screen() ); 723 #endif 733 bs = QwtPainter::backingStore( this, size() ); 724 734 725 735 if ( testAttribute(Qt::WA_StyledBackground) ) … … 734 744 if ( d_data->borderRadius <= 0.0 ) 735 745 { 736 bs.fill( this, 0, 0);746 QwtPainter::fillPixmap( this, bs ); 737 747 p.begin( &bs ); 738 748 drawCanvas( &p, false ); … … 771 781 { 772 782 if ( autoFillBackground() ) 783 { 784 qwtFillBackground( &painter, this ); 773 785 qwtDrawBackground( &painter, this ); 786 } 787 } 788 else 789 { 790 if ( borderRadius() > 0.0 ) 791 { 792 QPainterPath clipPath; 793 clipPath.addRect( rect() ); 794 clipPath = clipPath.subtracted( borderPath( rect() ) ); 795 796 painter.save(); 797 798 painter.setClipPath( clipPath, Qt::IntersectClip ); 799 qwtFillBackground( &painter, this ); 800 qwtDrawBackground( &painter, this ); 801 802 painter.restore(); 803 } 774 804 } 775 805 … … 838 868 painter->setBrush( palette().brush( backgroundRole() ) ); 839 869 840 if ( d_data->borderRadius > 0.0 )870 if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) ) 841 871 { 842 872 if ( frameWidth() > 0 ) … … 853 883 else 854 884 { 855 painter->drawRect( contentsRect() );885 painter->drawRect( rect() ); 856 886 } 857 887 } … … 870 900 { 871 901 if ( d_data->borderRadius > 0.0 ) 872 painter->setClipPath( borderPath( rect() ), Qt::IntersectClip );902 painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip ); 873 903 else 874 904 painter->setClipRect( contentsRect(), Qt::IntersectClip ); … … 892 922 893 923 \param painter Painter 894 \sa setBorderRadius() , QFrame::drawFrame()924 \sa setBorderRadius() 895 925 */ 896 926 void QwtPlotCanvas::drawBorder( QPainter *painter ) … … 900 930 if ( frameWidth() > 0 ) 901 931 { 902 QwtPainter::drawRoundedFrame( painter, QRectF( rect() ),932 QwtPainter::drawRoundedFrame( painter, QRectF( frameRect() ), 903 933 d_data->borderRadius, d_data->borderRadius, 904 934 palette(), frameWidth(), frameStyle() ); … … 907 937 else 908 938 { 939 #if QT_VERSION >= 0x040500 940 #if QT_VERSION < 0x050000 941 QStyleOptionFrameV3 opt; 942 #else 943 QStyleOptionFrame opt; 944 #endif 945 opt.init(this); 946 947 int frameShape = frameStyle() & QFrame::Shape_Mask; 948 int frameShadow = frameStyle() & QFrame::Shadow_Mask; 949 950 opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape ); 951 #if 0 952 opt.rect = frameRect(); 953 #endif 954 955 switch (frameShape) 956 { 957 case QFrame::Box: 958 case QFrame::HLine: 959 case QFrame::VLine: 960 case QFrame::StyledPanel: 961 case QFrame::Panel: 962 { 963 opt.lineWidth = lineWidth(); 964 opt.midLineWidth = midLineWidth(); 965 break; 966 } 967 default: 968 { 969 opt.lineWidth = frameWidth(); 970 break; 971 } 972 } 973 974 if ( frameShadow == Sunken ) 975 opt.state |= QStyle::State_Sunken; 976 else if ( frameShadow == Raised ) 977 opt.state |= QStyle::State_Raised; 978 979 style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, this); 980 #else 909 981 drawFrame( painter ); 982 #endif 910 983 } 911 984 } … … 950 1023 } 951 1024 952 //! Update the cached information sabout the current style sheet1025 //! Update the cached information about the current style sheet 953 1026 void QwtPlotCanvas::updateStyleSheetInfo() 954 1027 { … … 1027 1100 return QPainterPath(); 1028 1101 } 1029 1030 /*!1031 Calculate a mask, that can be used to clip away the border frame1032 1033 \param size Size including the frame1034 */1035 QBitmap QwtPlotCanvas::borderMask( const QSize &size ) const1036 {1037 const QRect r( 0, 0, size.width(), size.height() );1038 1039 const QPainterPath path = borderPath( r );1040 if ( path.isEmpty() )1041 return QBitmap();1042 1043 QImage image( size, QImage::Format_ARGB32_Premultiplied );1044 image.fill( Qt::color0 );1045 1046 QPainter painter( &image );1047 painter.setClipPath( path );1048 painter.fillRect( r, Qt::color1 );1049 1050 // now erase the frame1051 1052 painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );1053 1054 if ( testAttribute(Qt::WA_StyledBackground ) )1055 {1056 QStyleOptionFrame opt;1057 opt.initFrom(this);1058 opt.rect = r;1059 style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );1060 }1061 else1062 {1063 if ( d_data->borderRadius > 0 && frameWidth() > 0 )1064 {1065 painter.setPen( QPen( Qt::color1, frameWidth() ) );1066 painter.setBrush( Qt::NoBrush );1067 painter.setRenderHint( QPainter::Antialiasing, true );1068 1069 painter.drawPath( path );1070 }1071 }1072 1073 painter.end();1074 1075 const QImage mask = image.createMaskFromColor(1076 QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );1077 1078 return QBitmap::fromImage( mask );1079 } -
trunk/BNC/qwt/qwt_plot_canvas.h
r4271 r8127 13 13 #include "qwt_global.h" 14 14 #include <qframe.h> 15 #include <qpen.h>16 15 #include <qpainterpath.h> 17 #include <qbitmap.h>18 16 19 17 class QwtPlot; … … 22 20 /*! 23 21 \brief Canvas of a QwtPlot. 24 \sa QwtPlot 22 23 Canvas is the widget where all plot items are displayed 24 25 \sa QwtPlot::setCanvas(), QwtPlotGLCanvas 25 26 */ 26 27 class QWT_EXPORT QwtPlotCanvas : public QFrame 27 28 { 28 29 Q_OBJECT 30 31 Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius ) 29 32 30 33 public: … … 44 47 45 48 Using a backing store might improve the performance 46 significantly, when workin with widget overlays ( like rubberbands ).49 significantly, when working with widget overlays ( like rubber bands ). 47 50 Disabling the cache might improve the performance for 48 51 incremental paints (using QwtPlotDirectPainter ). … … 78 81 79 82 When HackStyledBackground is enabled the plot canvas tries 80 to sep erate the background from the background border81 by reverse eng eneering to paint the background before and83 to separate the background from the background border 84 by reverse engineering to paint the background before and 82 85 the border after the plot items. In this order the border 83 gets p refectly antialiased and you can avoid some pixel86 gets perfectly antialiased and you can avoid some pixel 84 87 artifacts in the corners. 85 88 */ … … 100 103 /*! 101 104 \brief Focus indicator 102 103 - NoFocusIndicator\n 104 Don't paint a focus indicator 105 106 - CanvasFocusIndicator\n 107 The focus is related to the complete canvas. 108 Paint the focus indicator using paintFocus() 109 110 - ItemFocusIndicator\n 111 The focus is related to an item (curve, point, ...) on 112 the canvas. It is up to the application to display a 113 focus indication using f.e. highlighting. 114 115 \sa setFocusIndicator(), focusIndicator(), paintFocus() 105 The default setting is NoFocusIndicator 106 \sa setFocusIndicator(), focusIndicator(), drawFocusIndicator() 116 107 */ 117 108 118 109 enum FocusIndicator 119 110 { 111 //! Don't paint a focus indicator 120 112 NoFocusIndicator, 113 114 /*! 115 The focus is related to the complete canvas. 116 Paint the focus indicator using drawFocusIndicator() 117 */ 121 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 */ 122 125 ItemFocusIndicator 123 126 }; 124 127 125 explicit QwtPlotCanvas( QwtPlot * );128 explicit QwtPlotCanvas( QwtPlot * = NULL ); 126 129 virtual ~QwtPlotCanvas(); 127 130 … … 135 138 double borderRadius() const; 136 139 137 QPainterPath borderPath( const QRect &rect ) const;138 QBitmap borderMask( const QSize & ) const;139 140 140 void setPaintAttribute( PaintAttribute, bool on = true ); 141 141 bool testPaintAttribute( PaintAttribute ) const; … … 144 144 void invalidateBackingStore(); 145 145 146 virtual bool event( QEvent * ); 147 148 Q_INVOKABLE QPainterPath borderPath( const QRect & ) const; 149 150 public Q_SLOTS: 146 151 void replot(); 147 148 virtual bool event( QEvent * );149 152 150 153 protected: -
trunk/BNC/qwt/qwt_plot_curve.cpp
r4271 r8127 9 9 10 10 #include "qwt_plot_curve.h" 11 #include "qwt_point_data.h" 11 12 #include "qwt_math.h" 12 13 #include "qwt_clipper.h" 13 14 #include "qwt_painter.h" 14 #include "qwt_legend.h"15 #include "qwt_legend_item.h"16 15 #include "qwt_scale_map.h" 17 16 #include "qwt_plot.h" 18 #include "qwt_plot_canvas.h"19 17 #include "qwt_curve_fitter.h" 20 18 #include "qwt_symbol.h" 19 #include "qwt_point_mapper.h" 21 20 #include <qpainter.h> 22 21 #include <qpixmap.h> … … 24 23 #include <qmath.h> 25 24 26 static int verifyRange( int size, int &i1, int &i2 ) 25 static void qwtUpdateLegendIconSize( QwtPlotCurve *curve ) 26 { 27 if ( curve->symbol() && 28 curve->testLegendAttribute( QwtPlotCurve::LegendShowSymbol ) ) 29 { 30 QSize sz = curve->symbol()->boundingRect().size(); 31 sz += QSize( 2, 2 ); // margin 32 33 if ( curve->testLegendAttribute( QwtPlotCurve::LegendShowLine ) ) 34 { 35 // Avoid, that the line is completely covered by the symbol 36 37 int w = qCeil( 1.5 * sz.width() ); 38 if ( w % 2 ) 39 w++; 40 41 sz.setWidth( qMax( 8, w ) ); 42 } 43 44 curve->setLegendIconSize( sz ); 45 } 46 } 47 48 static int qwtVerifyRange( int size, int &i1, int &i2 ) 27 49 { 28 50 if ( size < 1 ) … … 46 68 symbol( NULL ), 47 69 attributes( 0 ), 48 paintAttributes( QwtPlotCurve::ClipPolygons ), 70 paintAttributes( 71 QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints ), 49 72 legendAttributes( 0 ) 50 73 { … … 79 102 */ 80 103 QwtPlotCurve::QwtPlotCurve( const QwtText &title ): 81 QwtPlotSeriesItem <QPointF>( title )104 QwtPlotSeriesItem( title ) 82 105 { 83 106 init(); … … 89 112 */ 90 113 QwtPlotCurve::QwtPlotCurve( const QString &title ): 91 QwtPlotSeriesItem <QPointF>( QwtText( title ) )114 QwtPlotSeriesItem( QwtText( title ) ) 92 115 { 93 116 init(); … … 107 130 108 131 d_data = new PrivateData; 109 d_series = new QwtPointSeriesData();132 setData( new QwtPointSeriesData() ); 110 133 111 134 setZ( 20.0 ); … … 134 157 135 158 /*! 136 \ brief Return the current paint attributes159 \return True, when attribute is enabled 137 160 \sa setPaintAttribute() 138 161 */ … … 143 166 144 167 /*! 145 Specify an attribute how to draw the legend i dentifier168 Specify an attribute how to draw the legend icon 146 169 147 170 \param attribute Attribute 148 171 \param on On/Off 149 /sa testLegendAttribute() 172 /sa testLegendAttribute(). legendIcon() 150 173 */ 151 174 void QwtPlotCurve::setLegendAttribute( LegendAttribute attribute, bool on ) 152 175 { 153 if ( on ) 154 d_data->legendAttributes |= attribute; 155 else 156 d_data->legendAttributes &= ~attribute; 157 } 158 159 /*! 160 \brief Return the current paint attributes 161 \sa setLegendAttribute() 176 if ( on != testLegendAttribute( attribute ) ) 177 { 178 if ( on ) 179 d_data->legendAttributes |= attribute; 180 else 181 d_data->legendAttributes &= ~attribute; 182 183 qwtUpdateLegendIconSize( this ); 184 legendChanged(); 185 } 186 } 187 188 /*! 189 \return True, when attribute is enabled 190 \sa setLegendAttribute() 162 191 */ 163 192 bool QwtPlotCurve::testLegendAttribute( LegendAttribute attribute ) const … … 177 206 { 178 207 d_data->style = style; 208 209 legendChanged(); 179 210 itemChanged(); 180 211 } … … 182 213 183 214 /*! 184 Return the current style185 215 \return Style of the curve 216 \sa setStyle() 186 217 */ 187 218 QwtPlotCurve::CurveStyle QwtPlotCurve::style() const … … 191 222 192 223 /*! 193 Assign a symbol 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. 194 229 195 230 \param symbol Symbol 196 231 \sa symbol() 197 232 */ 198 void QwtPlotCurve::setSymbol( constQwtSymbol *symbol )233 void QwtPlotCurve::setSymbol( QwtSymbol *symbol ) 199 234 { 200 235 if ( symbol != d_data->symbol ) … … 202 237 delete d_data->symbol; 203 238 d_data->symbol = symbol; 239 240 qwtUpdateLegendIconSize( this ); 241 242 legendChanged(); 204 243 itemChanged(); 205 244 } … … 216 255 217 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 ) 270 { 271 setPen( QPen( color, width, style ) ); 272 } 273 274 /*! 218 275 Assign a pen 219 276 … … 226 283 { 227 284 d_data->pen = pen; 285 286 legendChanged(); 228 287 itemChanged(); 229 288 } … … 259 318 { 260 319 d_data->brush = brush; 320 321 legendChanged(); 261 322 itemChanged(); 262 323 } … … 278 339 \param xMap Maps x-values into pixel coordinates. 279 340 \param yMap Maps y-values into pixel coordinates. 280 \param canvasRect Contents rect of the canvas341 \param canvasRect Contents rectangle of the canvas 281 342 \param from Index of the first point to be painted 282 343 \param to Index of the last point to be painted. If to < 0 the … … 289 350 const QRectF &canvasRect, int from, int to ) const 290 351 { 291 if ( !painter || dataSize() <= 0 ) 352 const size_t numSamples = dataSize(); 353 354 if ( !painter || numSamples <= 0 ) 292 355 return; 293 356 294 357 if ( to < 0 ) 295 to = dataSize()- 1;296 297 if ( verifyRange( dataSize(), from, to ) > 0 )358 to = numSamples - 1; 359 360 if ( qwtVerifyRange( numSamples, from, to ) > 0 ) 298 361 { 299 362 painter->save(); … … 326 389 \param xMap x map 327 390 \param yMap y map 328 \param canvasRect Contents rect of the canvas391 \param canvasRect Contents rectangle of the canvas 329 392 \param from index of the first point to be painted 330 393 \param to index of the last point to be painted … … 371 434 \param xMap x map 372 435 \param yMap y map 373 \param canvasRect Contents rect of the canvas436 \param canvasRect Contents rectangle of the canvas 374 437 \param from index of the first point to be painted 375 438 \param to index of the last point to be painted … … 382 445 const QRectF &canvasRect, int from, int to ) const 383 446 { 384 int size = to - from + 1; 385 if ( size <= 0 ) 447 if ( from > to ) 386 448 return; 387 449 388 450 const bool doAlign = QwtPainter::roundingAlignment( painter ); 389 390 QPolygonF polyline( size ); 391 392 QPointF *points = polyline.data(); 393 for ( int i = from; i <= to; i++ ) 394 { 395 const QPointF sample = d_series->sample( i ); 396 397 double x = xMap.transform( sample.x() ); 398 double y = yMap.transform( sample.y() ); 399 if ( doAlign ) 400 { 401 x = qRound( x ); 402 y = qRound( y ); 403 } 404 405 points[i - from].rx() = x; 406 points[i - from].ry() = y; 407 } 408 409 if ( ( d_data->attributes & Fitted ) && d_data->curveFitter ) 410 polyline = d_data->curveFitter->fitCurve( polyline ); 411 451 const bool doFit = ( d_data->attributes & Fitted ) && d_data->curveFitter; 452 const bool doFill = ( d_data->brush.style() != Qt::NoBrush ) 453 && ( d_data->brush.color().alpha() > 0 ); 454 455 QRectF clipRect; 412 456 if ( d_data->paintAttributes & ClipPolygons ) 413 457 { 414 458 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); 415 const QPolygonF clipped = QwtClipper::clipPolygonF( 416 canvasRect.adjusted(-pw, -pw, pw, pw), polyline, false ); 417 418 QwtPainter::drawPolyline( painter, clipped ); 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; 482 483 QwtPointMapper mapper; 484 mapper.setFlag( QwtPointMapper::RoundPoints, doAlign ); 485 mapper.setFlag( QwtPointMapper::WeedOutPoints, noDuplicates ); 486 mapper.setBoundingRect( canvasRect ); 487 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 ); 419 500 } 420 501 else 421 502 { 422 QwtPainter::drawPolyline( painter, polyline ); 423 } 424 425 if ( d_data->brush.style() != Qt::NoBrush ) 426 fillCurve( painter, xMap, yMap, canvasRect, polyline ); 503 QPolygonF polyline = mapper.toPolygonF( xMap, yMap, data(), from, to ); 504 505 if ( doFit ) 506 polyline = d_data->curveFitter->fitCurve( polyline ); 507 508 if ( doFill ) 509 { 510 if ( painter->pen().style() != Qt::NoPen ) 511 { 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 ); 526 } 527 else 528 { 529 fillCurve( painter, xMap, yMap, canvasRect, polyline ); 530 } 531 } 532 else 533 { 534 if ( d_data->paintAttributes & ClipPolygons ) 535 { 536 polyline = QwtClipper::clipPolygonF( 537 clipRect, polyline, false ); 538 } 539 540 QwtPainter::drawPolyline( painter, polyline ); 541 } 542 } 427 543 } 428 544 … … 433 549 \param xMap x map 434 550 \param yMap y map 435 \param canvasRect Contents rect of the canvas551 \param canvasRect Contents rectangle of the canvas 436 552 \param from index of the first point to be painted 437 553 \param to index of the last point to be painted … … 458 574 const Qt::Orientation o = orientation(); 459 575 576 const QwtSeriesData<QPointF> *series = data(); 577 460 578 for ( int i = from; i <= to; i++ ) 461 579 { 462 const QPointF sample = d_series->sample( i );580 const QPointF sample = series->sample( i ); 463 581 double xi = xMap.transform( sample.x() ); 464 582 double yi = yMap.transform( sample.y() ); … … 484 602 \param xMap x map 485 603 \param yMap y map 486 \param canvasRect Contents rect of the canvas604 \param canvasRect Contents rectangle of the canvas 487 605 \param from index of the first point to be painted 488 606 \param to index of the last point to be painted … … 494 612 const QRectF &canvasRect, int from, int to ) const 495 613 { 496 const bool doFill = d_data->brush.style() != Qt::NoBrush; 614 const QColor color = painter->pen().color(); 615 616 if ( painter->pen().style() == Qt::NoPen || color.alpha() == 0 ) 617 { 618 return; 619 } 620 621 const bool doFill = ( d_data->brush.style() != Qt::NoBrush ) 622 && ( d_data->brush.color().alpha() > 0 ); 497 623 const bool doAlign = QwtPainter::roundingAlignment( painter ); 498 624 499 QPolygonF polyline; 625 QwtPointMapper mapper; 626 mapper.setBoundingRect( canvasRect ); 627 mapper.setFlag( QwtPointMapper::RoundPoints, doAlign ); 628 629 if ( d_data->paintAttributes & FilterPoints ) 630 { 631 if ( ( color.alpha() == 255 ) 632 && !( painter->renderHints() & QPainter::Antialiasing ) ) 633 { 634 mapper.setFlag( QwtPointMapper::WeedOutPoints, true ); 635 } 636 } 637 500 638 if ( doFill ) 501 polyline.resize( to - from + 1 ); 502 503 QPointF *points = polyline.data(); 504 505 for ( int i = from; i <= to; i++ ) 506 { 507 const QPointF sample = d_series->sample( i ); 508 double xi = xMap.transform( sample.x() ); 509 double yi = yMap.transform( sample.y() ); 639 { 640 mapper.setFlag( QwtPointMapper::WeedOutPoints, false ); 641 642 QPolygonF points = mapper.toPointsF( 643 xMap, yMap, data(), from, to ); 644 645 QwtPainter::drawPoints( painter, points ); 646 fillCurve( painter, xMap, yMap, canvasRect, points ); 647 } 648 else if ( d_data->paintAttributes & ImageBuffer ) 649 { 650 const QImage image = mapper.toImage( xMap, yMap, 651 data(), from, to, d_data->pen, 652 painter->testRenderHint( QPainter::Antialiasing ), 653 renderThreadCount() ); 654 655 painter->drawImage( canvasRect.toAlignedRect(), image ); 656 } 657 else if ( d_data->paintAttributes & MinimizeMemory ) 658 { 659 const QwtSeriesData<QPointF> *series = data(); 660 661 for ( int i = from; i <= to; i++ ) 662 { 663 const QPointF sample = series->sample( i ); 664 665 double xi = xMap.transform( sample.x() ); 666 double yi = yMap.transform( sample.y() ); 667 668 if ( doAlign ) 669 { 670 xi = qRound( xi ); 671 yi = qRound( yi ); 672 } 673 674 QwtPainter::drawPoint( painter, QPointF( xi, yi ) ); 675 } 676 } 677 else 678 { 510 679 if ( doAlign ) 511 680 { 512 xi = qRound( xi ); 513 yi = qRound( yi ); 514 } 515 516 QwtPainter::drawPoint( painter, QPointF( xi, yi ) ); 517 518 if ( doFill ) 519 { 520 points[i - from].rx() = xi; 521 points[i - from].ry() = yi; 522 } 523 } 524 525 if ( doFill ) 526 fillCurve( painter, xMap, yMap, canvasRect, polyline ); 681 const QPolygon points = mapper.toPoints( 682 xMap, yMap, data(), from, to ); 683 684 QwtPainter::drawPoints( painter, points ); 685 } 686 else 687 { 688 const QPolygonF points = mapper.toPointsF( 689 xMap, yMap, data(), from, to ); 690 691 QwtPainter::drawPoints( painter, points ); 692 } 693 } 527 694 } 528 695 … … 535 702 \param xMap x map 536 703 \param yMap y map 537 \param canvasRect Contents rect of the canvas704 \param canvasRect Contents rectangle of the canvas 538 705 \param from index of the first point to be painted 539 706 \param to index of the last point to be painted … … 555 722 inverted = !inverted; 556 723 724 const QwtSeriesData<QPointF> *series = data(); 725 557 726 int i, ip; 558 727 for ( i = from, ip = 0; i <= to; i++, ip += 2 ) 559 728 { 560 const QPointF sample = d_series->sample( i );729 const QPointF sample = series->sample( i ); 561 730 double xi = xMap.transform( sample.x() ); 562 731 double yi = yMap.transform( sample.y() ); … … 590 759 if ( d_data->paintAttributes & ClipPolygons ) 591 760 { 761 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); 762 const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw); 763 592 764 const QPolygonF clipped = QwtClipper::clipPolygonF( 593 c anvasRect, polygon, false );765 clipRect, polygon, false ); 594 766 595 767 QwtPainter::drawPolyline( painter, clipped ); … … 678 850 \param xMap x map 679 851 \param yMap y map 680 \param canvasRect Contents rect of the canvas852 \param canvasRect Contents rectangle of the canvas 681 853 \param polygon Polygon - will be modified ! 682 854 … … 733 905 if ( orientation() == Qt::Vertical ) 734 906 { 735 if ( yMap.transformation()->type() == QwtScaleTransformation::Log10 ) 736 { 737 if ( baseline < QwtScaleMap::LogMin ) 738 baseline = QwtScaleMap::LogMin; 739 } 907 if ( yMap.transformation() ) 908 baseline = yMap.transformation()->bounded( baseline ); 740 909 741 910 double refY = yMap.transform( baseline ); … … 748 917 else 749 918 { 750 if ( xMap.transformation()->type() == QwtScaleTransformation::Log10 ) 751 { 752 if ( baseline < QwtScaleMap::LogMin ) 753 baseline = QwtScaleMap::LogMin; 754 } 919 if ( xMap.transformation() ) 920 baseline = xMap.transformation()->bounded( baseline ); 755 921 756 922 double refX = xMap.transform( baseline ); … … 770 936 \param xMap x map 771 937 \param yMap y map 772 \param canvasRect Contents rect of the canvas938 \param canvasRect Contents rectangle of the canvas 773 939 \param from Index of the first point to be painted 774 940 \param to Index of the last point to be painted … … 780 946 const QRectF &canvasRect, int from, int to ) const 781 947 { 782 const bool doAlign = QwtPainter::roundingAlignment( painter ); 783 784 bool usePixmap = testPaintAttribute( CacheSymbols ); 785 if ( usePixmap && !doAlign ) 786 { 787 // Don't use the pixmap, when the paint device 788 // could generate scalable vectors 789 790 usePixmap = false; 791 } 792 793 if ( usePixmap ) 794 { 795 QPixmap pm( symbol.boundingSize() ); 796 pm.fill( Qt::transparent ); 797 798 const double pw2 = 0.5 * pm.width(); 799 const double ph2 = 0.5 * pm.height(); 800 801 QPainter p( &pm ); 802 p.setRenderHints( painter->renderHints() ); 803 symbol.drawSymbol( &p, QPointF( pw2, ph2 ) ); 804 p.end(); 805 806 for ( int i = from; i <= to; i++ ) 807 { 808 const QPointF sample = d_series->sample( i ); 809 810 double xi = xMap.transform( sample.x() ); 811 double yi = yMap.transform( sample.y() ); 812 if ( doAlign ) 813 { 814 xi = qRound( xi ); 815 yi = qRound( yi ); 816 } 817 818 if ( canvasRect.contains( xi, yi ) ) 819 { 820 const int left = qCeil( xi ) - pw2; 821 const int top = qCeil( yi ) - ph2; 822 823 painter->drawPixmap( left, top, pm ); 824 } 825 } 826 } 827 else 828 { 829 const int chunkSize = 500; 830 831 for ( int i = from; i <= to; i += chunkSize ) 832 { 833 const int n = qMin( chunkSize, to - i + 1 ); 834 835 QPolygonF points; 836 for ( int j = 0; j < n; j++ ) 837 { 838 const QPointF sample = d_series->sample( i + j ); 839 840 const double xi = xMap.transform( sample.x() ); 841 const double yi = yMap.transform( sample.y() ); 842 843 if ( canvasRect.contains( xi, yi ) ) 844 points += QPointF( xi, yi ); 845 } 846 847 if ( points.size() > 0 ) 848 symbol.drawSymbols( painter, points ); 849 } 948 QwtPointMapper mapper; 949 mapper.setFlag( QwtPointMapper::RoundPoints, 950 QwtPainter::roundingAlignment( painter ) ); 951 mapper.setFlag( QwtPointMapper::WeedOutPoints, 952 testPaintAttribute( QwtPlotCurve::FilterPoints ) ); 953 mapper.setBoundingRect( canvasRect ); 954 955 const int chunkSize = 500; 956 957 for ( int i = from; i <= to; i += chunkSize ) 958 { 959 const int n = qMin( chunkSize, to - i + 1 ); 960 961 const QPolygonF points = mapper.toPointsF( xMap, yMap, 962 data(), i, i + n - 1 ); 963 964 if ( points.size() > 0 ) 965 symbol.drawSymbols( painter, points ); 850 966 } 851 967 } … … 856 972 The baseline is needed for filling the curve with a brush or 857 973 the Sticks drawing style. 858 The interpretation of the baseline depends on the CurveType. 859 With QwtPlotCurve::Yfx, the baseline is interpreted as a horizontal line 860 at y = baseline(), with QwtPlotCurve::Yfy, it is interpreted as a vertical 974 975 The interpretation of the baseline depends on the orientation(). 976 With Qt::Horizontal, the baseline is interpreted as a horizontal line 977 at y = baseline(), with Qt::Vertical, it is interpreted as a vertical 861 978 line at x = baseline(). 862 979 … … 864 981 865 982 \param value Value of the baseline 866 \sa baseline(), setBrush(), setStyle(), setStyle()983 \sa baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation() 867 984 */ 868 985 void QwtPlotCurve::setBaseline( double value ) … … 889 1006 \param pos Position, where to look for the closest curve point 890 1007 \param dist If dist != NULL, closestPoint() returns the distance between 891 the position and the clos test curve point1008 the position and the closest curve point 892 1009 \return Index of the closest curve point, or -1 if none can be found 893 1010 ( f.e when the curve has no points ) … … 897 1014 int QwtPlotCurve::closestPoint( const QPoint &pos, double *dist ) const 898 1015 { 899 if ( plot() == NULL || dataSize() <= 0 ) 1016 const size_t numSamples = dataSize(); 1017 1018 if ( plot() == NULL || numSamples <= 0 ) 900 1019 return -1; 1020 1021 const QwtSeriesData<QPointF> *series = data(); 901 1022 902 1023 const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); … … 906 1027 double dmin = 1.0e10; 907 1028 908 for ( uint i = 0; i < dataSize(); i++ )909 { 910 const QPointF sample = d_series->sample( i );1029 for ( uint i = 0; i < numSamples; i++ ) 1030 { 1031 const QPointF sample = series->sample( i ); 911 1032 912 1033 const double cx = xMap.transform( sample.x() ) - pos.x(); … … 927 1048 928 1049 /*! 929 \brief Update the widget that represents the item on the legend 930 931 \param legend Legend 932 \sa drawLegendIdentifier(), legendItem(), QwtPlotItem::Legend 933 */ 934 void QwtPlotCurve::updateLegend( QwtLegend *legend ) const 935 { 936 if ( legend && testItemAttribute( QwtPlotItem::Legend ) 937 && ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol ) 938 && d_data->symbol 939 && d_data->symbol->style() != QwtSymbol::NoSymbol ) 940 { 941 QWidget *lgdItem = legend->find( this ); 942 if ( lgdItem == NULL ) 943 { 944 lgdItem = legendItem(); 945 if ( lgdItem ) 946 legend->insert( this, lgdItem ); 947 } 948 949 QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem ); 950 if ( l ) 951 { 952 QSize sz = d_data->symbol->boundingSize(); 953 sz += QSize( 2, 2 ); // margin 954 955 if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine ) 1050 \return Icon representing the curve on the legend 1051 1052 \param index Index of the legend entry 1053 ( ignored as there is only one ) 1054 \param size Icon size 1055 1056 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 1057 */ 1058 QwtGraphic QwtPlotCurve::legendIcon( int index, 1059 const QSizeF &size ) const 1060 { 1061 Q_UNUSED( index ); 1062 1063 if ( size.isEmpty() ) 1064 return QwtGraphic(); 1065 1066 QwtGraphic graphic; 1067 graphic.setDefaultSize( size ); 1068 graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 1069 1070 QPainter painter( &graphic ); 1071 painter.setRenderHint( QPainter::Antialiasing, 1072 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 1073 1074 if ( d_data->legendAttributes == 0 || 1075 d_data->legendAttributes & QwtPlotCurve::LegendShowBrush ) 1076 { 1077 QBrush brush = d_data->brush; 1078 1079 if ( brush.style() == Qt::NoBrush && 1080 d_data->legendAttributes == 0 ) 1081 { 1082 if ( style() != QwtPlotCurve::NoCurve ) 956 1083 { 957 // Avoid, that the line is completely covered by the symbol 958 959 int w = qCeil( 1.5 * sz.width() ); 960 if ( w % 2 ) 961 w++; 962 963 sz.setWidth( qMax( 8, w ) ); 1084 brush = QBrush( pen().color() ); 964 1085 } 965 966 l->setIdentifierSize( sz );967 }968 }969 970 QwtPlotItem::updateLegend( legend );971 }972 973 /*!974 \brief Draw the identifier representing the curve on the legend975 976 \param painter Painter977 \param rect Bounding rectangle for the identifier978 979 \sa setLegendAttribute(), QwtPlotItem::Legend980 */981 void QwtPlotCurve::drawLegendIdentifier(982 QPainter *painter, const QRectF &rect ) const983 {984 if ( rect.isEmpty() )985 return;986 987 const int dim = qMin( rect.width(), rect.height() );988 989 QSize size( dim, dim );990 991 QRectF r( 0, 0, size.width(), size.height() );992 r.moveCenter( rect.center() );993 994 if ( d_data->legendAttributes == 0 )995 {996 QBrush brush = d_data->brush;997 if ( brush.style() == Qt::NoBrush )998 {999 if ( style() != QwtPlotCurve::NoCurve )1000 brush = QBrush( pen().color() );1001 1086 else if ( d_data->symbol && 1002 1087 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) … … 1005 1090 } 1006 1091 } 1092 1007 1093 if ( brush.style() != Qt::NoBrush ) 1008 painter->fillRect( r, brush ); 1009 } 1010 if ( d_data->legendAttributes & QwtPlotCurve::LegendShowBrush ) 1011 { 1012 if ( d_data->brush.style() != Qt::NoBrush ) 1013 painter->fillRect( r, d_data->brush ); 1014 } 1094 { 1095 QRectF r( 0, 0, size.width(), size.height() ); 1096 painter.fillRect( r, brush ); 1097 } 1098 } 1099 1015 1100 if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine ) 1016 1101 { 1017 1102 if ( pen() != Qt::NoPen ) 1018 1103 { 1019 painter->setPen( pen() ); 1020 QwtPainter::drawLine( painter, rect.left(), rect.center().y(), 1021 rect.right() - 1.0, rect.center().y() ); 1022 } 1023 } 1104 QPen pn = pen(); 1105 pn.setCapStyle( Qt::FlatCap ); 1106 1107 painter.setPen( pn ); 1108 1109 const double y = 0.5 * size.height(); 1110 QwtPainter::drawLine( &painter, 0.0, y, size.width(), y ); 1111 } 1112 } 1113 1024 1114 if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol ) 1025 1115 { 1026 if ( d_data->symbol && 1027 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) 1028 { 1029 QSize symbolSize = d_data->symbol->boundingSize(); 1030 symbolSize -= QSize( 2, 2 ); 1031 1032 // scale the symbol size down if it doesn't fit into rect. 1033 1034 double xRatio = 1.0; 1035 if ( rect.width() < symbolSize.width() ) 1036 xRatio = rect.width() / symbolSize.width(); 1037 double yRatio = 1.0; 1038 if ( rect.height() < symbolSize.height() ) 1039 yRatio = rect.height() / symbolSize.height(); 1040 1041 const double ratio = qMin( xRatio, yRatio ); 1042 1043 painter->save(); 1044 painter->scale( ratio, ratio ); 1045 1046 d_data->symbol->drawSymbol( painter, rect.center() / ratio ); 1047 1048 painter->restore(); 1049 } 1050 } 1051 } 1052 1053 /*! 1054 Initialize data with an array of points (explicitly shared). 1116 if ( d_data->symbol ) 1117 { 1118 QRectF r( 0, 0, size.width(), size.height() ); 1119 d_data->symbol->drawSymbol( &painter, r ); 1120 } 1121 } 1122 1123 return graphic; 1124 } 1125 1126 /*! 1127 Initialize data with an array of points. 1055 1128 1056 1129 \param samples Vector of points 1130 \note QVector is implicitly shared 1131 \note QPolygonF is derived from QVector<QPointF> 1057 1132 */ 1058 1133 void QwtPlotCurve::setSamples( const QVector<QPointF> &samples ) 1059 1134 { 1060 delete d_series; 1061 d_series = new QwtPointSeriesData( samples ); 1062 itemChanged(); 1135 setData( new QwtPointSeriesData( samples ) ); 1136 } 1137 1138 /*! 1139 Assign a series of points 1140 1141 setSamples() is just a wrapper for setData() without any additional 1142 value - beside that it is easier to find for the developer. 1143 1144 \param data Data 1145 \warning The item takes ownership of the data object, deleting 1146 it when its not used anymore. 1147 */ 1148 void QwtPlotCurve::setSamples( QwtSeriesData<QPointF> *data ) 1149 { 1150 setData( data ); 1063 1151 } 1064 1152 … … 1082 1170 const double *xData, const double *yData, int size ) 1083 1171 { 1084 delete d_series; 1085 d_series = new QwtCPointerData( xData, yData, size ); 1086 itemChanged(); 1172 setData( new QwtCPointerData( xData, yData, size ) ); 1087 1173 } 1088 1174 … … 1101 1187 const double *xData, const double *yData, int size ) 1102 1188 { 1103 delete d_series; 1104 d_series = new QwtPointArrayData( xData, yData, size ); 1105 itemChanged(); 1189 setData( new QwtPointArrayData( xData, yData, size ) ); 1106 1190 } 1107 1191 … … 1117 1201 const QVector<double> &yData ) 1118 1202 { 1119 delete d_series; 1120 d_series = new QwtPointArrayData( xData, yData ); 1121 itemChanged(); 1122 } 1203 setData( new QwtPointArrayData( xData, yData ) ); 1204 } 1205 1123 1206 #endif // !QWT_NO_COMPAT 1124 1207 -
trunk/BNC/qwt/qwt_plot_curve.h
r4271 r8127 53 53 \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap 54 54 */ 55 class QWT_EXPORT QwtPlotCurve: public QwtPlotSeriesItem<QPointF> 55 class QWT_EXPORT QwtPlotCurve: 56 public QwtPlotSeriesItem, public QwtSeriesStore<QPointF> 56 57 { 57 58 public: … … 120 121 interpolate/smooth the curve, before it is painted. 121 122 122 \note Curve fitting requires tem orary memory123 \note Curve fitting requires temporary memory 123 124 for calculating coefficients and additional points. 124 125 If painting in QwtPlotCurve::Fitted mode is slow it might be better … … 135 136 136 137 \sa setLegendAttribute(), testLegendAttribute(), 137 drawLegendIdentifier()138 QwtPlotItem::legendData(), legendIcon() 138 139 */ 139 140 … … 169 170 /*! 170 171 Attributes to modify the drawing algorithm. 171 The default setting enables ClipPolygons 172 The default setting enables ClipPolygons | FilterPoints 172 173 173 174 \sa setPaintAttribute(), testPaintAttribute() … … 183 184 184 185 /*! 185 Paint the symbol to a QPixmap and paint the pixmap 186 instead rendering the symbol for each point. The flag has 187 no effect, when the curve is not painted to the canvas 188 ( f.e when exporting the plot to a PDF document ). 189 */ 190 CacheSymbols = 0x02 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 */ 191 FilterPoints = 0x02, 192 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 197 */ 198 MinimizeMemory = 0x04, 199 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 191 208 }; 192 209 … … 213 230 #endif 214 231 void setSamples( const QVector<QPointF> & ); 232 void setSamples( QwtSeriesData<QPointF> * ); 215 233 216 234 int closestPoint( const QPoint &pos, double *dist = NULL ) const; … … 224 242 bool testCurveAttribute( CurveAttribute ) const; 225 243 244 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 226 245 void setPen( const QPen & ); 227 246 const QPen &pen() const; … … 230 249 const QBrush &brush() const; 231 250 232 void setBaseline( double ref);251 void setBaseline( double ); 233 252 double baseline() const; 234 253 … … 236 255 CurveStyle style() const; 237 256 238 void setSymbol( const QwtSymbol *s);257 void setSymbol( QwtSymbol * ); 239 258 const QwtSymbol *symbol() const; 240 259 … … 246 265 const QRectF &canvasRect, int from, int to ) const; 247 266 248 virtual void updateLegend( QwtLegend * ) const; 249 virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const; 267 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 250 268 251 269 protected: … … 261 279 const QRectF &canvasRect, int from, int to ) const; 262 280 263 v oid drawLines( QPainter *p,264 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 265 const QRectF &canvasRect, int from, int to ) const; 266 267 v oid drawSticks( QPainter *p,268 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 269 const QRectF &canvasRect, int from, int to ) const; 270 271 v oid drawDots( QPainter *p,272 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 273 const QRectF &canvasRect, int from, int to ) const; 274 275 v oid drawSteps( QPainter *p,281 virtual void drawLines( QPainter *p, 282 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 283 const QRectF &canvasRect, int from, int to ) const; 284 285 virtual void drawSticks( QPainter *p, 286 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 287 const QRectF &canvasRect, int from, int to ) const; 288 289 virtual void drawDots( QPainter *p, 290 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 291 const QRectF &canvasRect, int from, int to ) const; 292 293 virtual void drawSteps( QPainter *p, 276 294 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 277 295 const QRectF &canvasRect, int from, int to ) const; -
trunk/BNC/qwt/qwt_plot_dict.cpp
r4271 r8127 64 64 65 65 Auto deletion is enabled. 66 \sa setAutoDelete(), attachItem()66 \sa setAutoDelete(), QwtPlotItem::attach() 67 67 */ 68 68 QwtPlotDict::QwtPlotDict() … … 75 75 Destructor 76 76 77 If autoDelete is on, all attached items will be deleted78 \sa setAutoDelete(), autoDelete(), attachItem()77 If autoDelete() is on, all attached items will be deleted 78 \sa setAutoDelete(), autoDelete(), QwtPlotItem::attach() 79 79 */ 80 80 QwtPlotDict::~QwtPlotDict() … … 90 90 in the destructor of QwtPlotDict. The default value is on. 91 91 92 \sa autoDelete(), attachItem()92 \sa autoDelete(), insertItem() 93 93 */ 94 94 void QwtPlotDict::setAutoDelete( bool autoDelete ) … … 99 99 /*! 100 100 \return true if auto deletion is enabled 101 \sa setAutoDelete(), attachItem()101 \sa setAutoDelete(), insertItem() 102 102 */ 103 103 bool QwtPlotDict::autoDelete() const … … 107 107 108 108 /*! 109 Attach/Detacha plot item109 Insert a plot item 110 110 111 Attached items will be deleted in the destructor, 112 if auto deletion is enabled (default). Manually detached 113 items are not deleted. 111 \param item PlotItem 112 \sa removeItem() 113 */ 114 void QwtPlotDict::insertItem( QwtPlotItem *item ) 115 { 116 d_data->itemList.insertItem( item ); 117 } 114 118 115 \param item Plot item to attach/detach 116 \ on If true attach, else detach theitem119 /*! 120 Remove a plot item 117 121 118 \sa setAutoDelete(), ~QwtPlotDict() 119 */ 120 void QwtPlotDict::attachItem( QwtPlotItem *item, bool on ) 122 \param item PlotItem 123 \sa insertItem() 124 */ 125 void QwtPlotDict::removeItem( QwtPlotItem *item ) 121 126 { 122 if ( on ) 123 d_data->itemList.insertItem( item ); 124 else 125 d_data->itemList.removeItem( item ); 127 d_data->itemList.removeItem( item ); 126 128 } 127 129 … … 168 170 /*! 169 171 \return List of all attached plot items of a specific type. 172 \param rtti See QwtPlotItem::RttiValues 170 173 \sa QwtPlotItem::rtti() 171 174 */ -
trunk/BNC/qwt/qwt_plot_dict.h
r4271 r8127 27 27 If autoDelete() is enabled, all attached items will be deleted 28 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. 29 31 30 32 \sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z() … … 45 47 bool autoDelete = true ); 46 48 49 protected: 50 void insertItem( QwtPlotItem * ); 51 void removeItem( QwtPlotItem * ); 52 47 53 private: 48 friend class QwtPlotItem;49 50 void attachItem( QwtPlotItem *, bool );51 52 54 class PrivateData; 53 55 PrivateData *d_data; -
trunk/BNC/qwt/qwt_plot_directpainter.cpp
r4271 r8127 18 18 #include <qpixmap.h> 19 19 20 static inline void renderItem(20 static inline void qwtRenderItem( 21 21 QPainter *painter, const QRect &canvasRect, 22 QwtPlot AbstractSeriesItem *seriesItem, int from, int to )22 QwtPlotSeriesItem *seriesItem, int from, int to ) 23 23 { 24 24 // A minor performance improvement is possible … … 32 32 seriesItem->testRenderHint( QwtPlotItem::RenderAntialiased ) ); 33 33 seriesItem->drawSeries( painter, xMap, yMap, canvasRect, from, to ); 34 } 35 36 static inline bool qwtHasBackingStore( const QwtPlotCanvas *canvas ) 37 { 38 return canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) 39 && canvas->backingStore() && !canvas->backingStore()->isNull(); 34 40 } 35 41 … … 40 46 attributes( 0 ), 41 47 hasClipping(false), 42 seriesItem( NULL ) 48 seriesItem( NULL ), 49 from( 0 ), 50 to( 0 ) 43 51 { 44 52 } … … 51 59 QPainter painter; 52 60 53 QwtPlot AbstractSeriesItem *seriesItem;61 QwtPlotSeriesItem *seriesItem; 54 62 int from; 55 63 int to; … … 92 100 93 101 /*! 94 Check if a attribute is set. 95 102 \return True, when attribute is enabled 96 103 \param attribute Attribute to be tested 97 104 \sa Attribute, setAttribute() … … 152 159 153 160 When observing an measurement while it is running, new points have to be 154 added to an existing seriesItem. drawSeries can be used to display them avoiding161 added to an existing seriesItem. drawSeries() can be used to display them avoiding 155 162 a complete redraw of the canvas. 156 163 … … 165 172 */ 166 173 void QwtPlotDirectPainter::drawSeries( 167 QwtPlot AbstractSeriesItem *seriesItem, int from, int to )174 QwtPlotSeriesItem *seriesItem, int from, int to ) 168 175 { 169 176 if ( seriesItem == NULL || seriesItem->plot() == NULL ) 170 177 return; 171 178 172 Q wtPlotCanvas*canvas = seriesItem->plot()->canvas();179 QWidget *canvas = seriesItem->plot()->canvas(); 173 180 const QRect canvasRect = canvas->contentsRect(); 174 181 175 const bool hasBackingStore = 176 canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) 177 && canvas->backingStore() && !canvas->backingStore()->isNull(); 178 179 if ( hasBackingStore ) 180 { 181 QPainter painter( const_cast<QPixmap *>( canvas->backingStore() ) ); 182 painter.translate( -canvasRect.x(), -canvasRect.y() ); 182 QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( canvas ); 183 184 if ( plotCanvas && qwtHasBackingStore( plotCanvas ) ) 185 { 186 QPainter painter( const_cast<QPixmap *>( plotCanvas->backingStore() ) ); 183 187 184 188 if ( d_data->hasClipping ) 185 189 painter.setClipRegion( d_data->clipRegion ); 186 190 187 renderItem( &painter, canvasRect, seriesItem, from, to ); 191 qwtRenderItem( &painter, canvasRect, seriesItem, from, to ); 192 193 painter.end(); 188 194 189 195 if ( testAttribute( QwtPlotDirectPainter::FullRepaint ) ) 190 196 { 191 canvas->repaint();197 plotCanvas->repaint(); 192 198 return; 193 199 } … … 195 201 196 202 bool immediatePaint = true; 197 if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) && 198 !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) ) 199 { 200 immediatePaint = false; 203 if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) ) 204 { 205 #if QT_VERSION < 0x050000 206 if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) ) 207 #endif 208 immediatePaint = false; 201 209 } 202 210 203 211 if ( immediatePaint ) 204 212 { 205 QwtPlotCanvas *canvas = seriesItem->plot()->canvas();206 213 if ( !d_data->painter.isActive() ) 207 214 { … … 223 230 } 224 231 225 renderItem( &d_data->painter, canvasRect, seriesItem, from, to );232 qwtRenderItem( &d_data->painter, canvasRect, seriesItem, from, to ); 226 233 227 234 if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter ) … … 260 267 if ( d_data->painter.isActive() ) 261 268 { 262 QWidget *w = ( QWidget * )d_data->painter.device();269 QWidget *w = static_cast<QWidget *>( d_data->painter.device() ); 263 270 if ( w ) 264 271 w->removeEventFilter( this ); … … 279 286 const QPaintEvent *pe = static_cast< QPaintEvent *>( event ); 280 287 281 Q wtPlotCanvas*canvas = d_data->seriesItem->plot()->canvas();288 QWidget *canvas = d_data->seriesItem->plot()->canvas(); 282 289 283 290 QPainter painter( canvas ); 284 291 painter.setClipRegion( pe->region() ); 285 292 286 bool copyCache = testAttribute( CopyBackingStore ) 287 && canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ); 288 289 if ( copyCache ) 293 bool doCopyCache = testAttribute( CopyBackingStore ); 294 295 if ( doCopyCache ) 290 296 { 291 // is something valid in the cache ? 292 copyCache = ( canvas->backingStore() != NULL ) 293 && !canvas->backingStore()->isNull(); 297 QwtPlotCanvas *plotCanvas = 298 qobject_cast<QwtPlotCanvas *>( canvas ); 299 if ( plotCanvas ) 300 { 301 doCopyCache = qwtHasBackingStore( plotCanvas ); 302 if ( doCopyCache ) 303 { 304 painter.drawPixmap( plotCanvas->rect().topLeft(), 305 *plotCanvas->backingStore() ); 306 } 307 } 294 308 } 295 309 296 if ( copyCache )310 if ( !doCopyCache ) 297 311 { 298 painter.drawPixmap( 299 canvas->contentsRect().topLeft(), 300 *canvas->backingStore() ); 301 } 302 else 303 { 304 renderItem( &painter, canvas->contentsRect(), 312 qwtRenderItem( &painter, canvas->contentsRect(), 305 313 d_data->seriesItem, d_data->from, d_data->to ); 306 314 } -
trunk/BNC/qwt/qwt_plot_directpainter.h
r4271 r8127 15 15 16 16 class QRegion; 17 class QwtPlot AbstractSeriesItem;17 class QwtPlotSeriesItem; 18 18 19 19 /*! … … 55 55 56 56 /*! 57 When FullRepaint is set the plot canvas is explicit ely repainted57 When FullRepaint is set the plot canvas is explicitly repainted 58 58 after the samples have been rendered. 59 59 */ … … 64 64 has to paint to the backing store and the widget. In certain 65 65 situations/environments it might be faster to paint to 66 the backing store only and then copy the backing store to the canvas.66 the backing store only and then copy the backing store to the canvas. 67 67 This flag can also be useful for settings, where Qt fills the 68 68 the clip region with the widget background. … … 86 86 QRegion clipRegion() const; 87 87 88 void drawSeries( QwtPlot AbstractSeriesItem *, int from, int to );88 void drawSeries( QwtPlotSeriesItem *, int from, int to ); 89 89 void reset(); 90 90 -
trunk/BNC/qwt/qwt_plot_grid.cpp
r4271 r8127 36 36 QwtScaleDiv yScaleDiv; 37 37 38 QPen maj Pen;39 QPen min Pen;38 QPen majorPen; 39 QPen minorPen; 40 40 }; 41 41 … … 45 45 { 46 46 d_data = new PrivateData; 47 48 setItemInterest( QwtPlotItem::ScaleInterest, true ); 47 49 setZ( 10.0 ); 48 50 } … … 61 63 62 64 /*! 63 \brief Enable or disable vertical grid lines64 \param tfEnable (true) or disable65 66 \sa Minor grid lines can be enabled or disabled with65 \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 67 69 enableXMin() 68 70 */ 69 void QwtPlotGrid::enableX( bool tf ) 70 { 71 if ( d_data->xEnabled != tf ) 72 { 73 d_data->xEnabled = tf; 74 itemChanged(); 75 } 76 } 77 78 /*! 79 \brief Enable or disable horizontal gridlines 80 \param tf Enable (true) or disable 81 \sa Minor gridlines can be enabled or disabled with enableYMin() 82 */ 83 void QwtPlotGrid::enableY( bool tf ) 84 { 85 if ( d_data->yEnabled != tf ) 86 { 87 d_data->yEnabled = tf; 88 itemChanged(); 89 } 90 } 91 92 /*! 93 \brief Enable or disable minor vertical gridlines. 94 \param tf Enable (true) or disable 71 void QwtPlotGrid::enableX( bool on ) 72 { 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 */ 87 void QwtPlotGrid::enableY( bool on ) 88 { 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 95 101 \sa enableX() 96 102 */ 97 void QwtPlotGrid::enableXMin( bool tf ) 98 { 99 if ( d_data->xMinEnabled != tf ) 100 { 101 d_data->xMinEnabled = tf; 102 itemChanged(); 103 } 104 } 105 106 /*! 107 \brief Enable or disable minor horizontal gridlines 108 \param tf Enable (true) or disable 103 void QwtPlotGrid::enableXMin( bool on ) 104 { 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 109 117 \sa enableY() 110 118 */ 111 void QwtPlotGrid::enableYMin( bool tf ) 112 { 113 if ( d_data->yMinEnabled != tf ) 114 { 115 d_data->yMinEnabled = tf; 119 void QwtPlotGrid::enableYMin( bool on ) 120 { 121 if ( d_data->yMinEnabled != on ) 122 { 123 d_data->yMinEnabled = on; 124 125 legendChanged(); 116 126 itemChanged(); 117 127 } … … 147 157 148 158 /*! 149 Assign a pen for both major and minor gridlines 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 ) 172 { 173 setPen( QPen( color, width, style ) ); 174 } 175 176 /*! 177 Assign a pen for both major and minor grid lines 150 178 151 179 \param pen Pen 152 \sa setMaj Pen(), setMinPen()180 \sa setMajorPen(), setMinorPen() 153 181 */ 154 182 void QwtPlotGrid::setPen( const QPen &pen ) 155 183 { 156 if ( d_data->majPen != pen || d_data->minPen != pen ) 157 { 158 d_data->majPen = pen; 159 d_data->minPen = pen; 160 itemChanged(); 161 } 162 } 163 164 /*! 165 Assign a pen for the major gridlines 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 ) 208 { 209 setMajorPen( QPen( color, width, style ) ); 210 } 211 212 /*! 213 Assign a pen for the major grid lines 166 214 167 215 \param pen Pen 168 \sa majPen(), setMinPen(), setPen() 169 */ 170 void QwtPlotGrid::setMajPen( const QPen &pen ) 171 { 172 if ( d_data->majPen != pen ) 173 { 174 d_data->majPen = pen; 175 itemChanged(); 176 } 177 } 178 179 /*! 180 Assign a pen for the minor gridlines 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 ) 243 { 244 setMinorPen( QPen( color, width, style ) ); 245 } 246 247 /*! 248 Assign a pen for the minor grid lines 181 249 182 250 \param pen Pen 183 \sa minPen(), setMajPen(), setPen() 184 */ 185 void QwtPlotGrid::setMinPen( const QPen &pen ) 186 { 187 if ( d_data->minPen != pen ) 188 { 189 d_data->minPen = 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(); 190 260 itemChanged(); 191 261 } … … 196 266 197 267 The grid is drawn into the bounding rectangle such that 198 grid lines begin and end at the rectangle's borders. The X and Y268 grid lines begin and end at the rectangle's borders. The X and Y 199 269 maps are used to map the scale divisions into the drawing region 200 270 screen. 271 201 272 \param painter Painter 202 273 \param xMap X axis map 203 274 \param yMap Y axis 204 \param canvasRect Contents rect of the plot canvas275 \param canvasRect Contents rectangle of the plot canvas 205 276 */ 206 277 void QwtPlotGrid::draw( QPainter *painter, … … 208 279 const QRectF &canvasRect ) const 209 280 { 210 // draw minor grid lines211 QPen min Pen = d_data->minPen;212 min Pen.setCapStyle( Qt::FlatCap );213 214 painter->setPen( min Pen );281 // draw minor grid lines 282 QPen minorPen = d_data->minorPen; 283 minorPen.setCapStyle( Qt::FlatCap ); 284 285 painter->setPen( minorPen ); 215 286 216 287 if ( d_data->xEnabled && d_data->xMinEnabled ) … … 230 301 } 231 302 232 // draw major grid lines233 QPen maj Pen = d_data->majPen;234 maj Pen.setCapStyle( Qt::FlatCap );235 236 painter->setPen( maj Pen );303 // draw major grid lines 304 QPen majorPen = d_data->majorPen; 305 majorPen.setCapStyle( Qt::FlatCap ); 306 307 painter->setPen( majorPen ); 237 308 238 309 if ( d_data->xEnabled ) … … 286 357 287 358 /*! 288 \return the pen for the major grid lines289 \sa setMaj Pen(), setMinPen(), setPen()290 */ 291 const QPen &QwtPlotGrid::maj Pen() const292 { 293 return d_data->maj Pen;294 } 295 296 /*! 297 \return the pen for the minor grid lines298 \sa setMin Pen(), setMajPen(), setPen()299 */ 300 const QPen &QwtPlotGrid::min Pen() const301 { 302 return d_data->min Pen;303 } 304 305 /*! 306 \return true if vertical grid lines are enabled359 \return the pen for the major grid lines 360 \sa setMajorPen(), setMinorPen(), setPen() 361 */ 362 const QPen &QwtPlotGrid::majorPen() const 363 { 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() const 372 { 373 return d_data->minorPen; 374 } 375 376 /*! 377 \return true if vertical grid lines are enabled 307 378 \sa enableX() 308 379 */ … … 313 384 314 385 /*! 315 \return true if minor vertical grid lines are enabled386 \return true if minor vertical grid lines are enabled 316 387 \sa enableXMin() 317 388 */ … … 322 393 323 394 /*! 324 \return true if horizontal grid lines are enabled395 \return true if horizontal grid lines are enabled 325 396 \sa enableY() 326 397 */ … … 331 402 332 403 /*! 333 \return true if minor horizontal grid lines are enabled404 \return true if minor horizontal grid lines are enabled 334 405 \sa enableYMin() 335 406 */ -
trunk/BNC/qwt/qwt_plot_grid.h
r4271 r8127 25 25 The QwtPlotGrid class can be used to draw a coordinate grid. 26 26 A coordinate grid consists of major and minor vertical 27 and horizontal grid lines. The locations of the gridlines27 and horizontal grid lines. The locations of the grid lines 28 28 are determined by the X and Y scale divisions which can 29 29 be assigned with setXDiv() and setYDiv(). … … 58 58 const QwtScaleDiv &yScaleDiv() const; 59 59 60 void setPen( const QPen &p ); 60 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 61 void setPen( const QPen & ); 61 62 62 void setMajPen( const QPen &p ); 63 const QPen& majPen() const; 63 void setMajorPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 64 void setMajorPen( const QPen & ); 65 const QPen& majorPen() const; 64 66 65 void setMinPen( const QPen &p ); 66 const QPen& minPen() const; 67 void setMinorPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 68 void setMinorPen( const QPen &p ); 69 const QPen& minorPen() const; 67 70 68 71 virtual void draw( QPainter *p, -
trunk/BNC/qwt/qwt_plot_histogram.cpp
r4271 r8127 10 10 #include "qwt_plot_histogram.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_legend.h"13 #include "qwt_legend_item.h"14 12 #include "qwt_painter.h" 15 13 #include "qwt_column_symbol.h" … … 18 16 #include <qpainter.h> 19 17 20 static inline bool isCombinable( const QwtInterval &d1,18 static inline bool qwtIsCombinable( const QwtInterval &d1, 21 19 const QwtInterval &d2 ) 22 20 { … … 63 61 \param title Title of the histogram. 64 62 */ 65 66 63 QwtPlotHistogram::QwtPlotHistogram( const QwtText &title ): 67 QwtPlotSeriesItem <QwtIntervalSample>( title )64 QwtPlotSeriesItem( title ) 68 65 { 69 66 init(); … … 75 72 */ 76 73 QwtPlotHistogram::QwtPlotHistogram( const QString &title ): 77 QwtPlotSeriesItem <QwtIntervalSample>( title )74 QwtPlotSeriesItem( title ) 78 75 { 79 76 init(); … … 90 87 { 91 88 d_data = new PrivateData(); 92 d_series = new QwtIntervalSeriesData();89 setData( new QwtIntervalSeriesData() ); 93 90 94 91 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 109 106 { 110 107 d_data->style = style; 108 109 legendChanged(); 111 110 itemChanged(); 112 111 } … … 114 113 115 114 /*! 116 Return the current style115 \return Style of the histogram 117 116 \sa HistogramStyle, setStyle() 118 117 */ … … 121 120 return d_data->style; 122 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 ) 137 { 138 setPen( QPen( color, width, style ) ); 139 } 123 140 124 141 /*! … … 133 150 { 134 151 d_data->pen = pen; 152 153 legendChanged(); 135 154 itemChanged(); 136 155 } … … 157 176 { 158 177 d_data->brush = brush; 178 179 legendChanged(); 159 180 itemChanged(); 160 181 } … … 181 202 182 203 \note In applications, where different intervals need to be displayed 183 in a different way ( f.e different colors or even using differ nt symbols)204 in a different way ( f.e different colors or even using different symbols) 184 205 it is recommended to overload drawColumn(). 185 206 */ … … 190 211 delete d_data->symbol; 191 212 d_data->symbol = symbol; 213 214 legendChanged(); 192 215 itemChanged(); 193 216 } … … 238 261 QRectF QwtPlotHistogram::boundingRect() const 239 262 { 240 QRectF rect = d _series->boundingRect();263 QRectF rect = data()->boundingRect(); 241 264 if ( !rect.isValid() ) 242 265 return rect; … … 276 299 const QVector<QwtIntervalSample> &samples ) 277 300 { 278 delete d_series; 279 d_series = new QwtIntervalSeriesData( samples ); 280 itemChanged(); 301 setData( new QwtIntervalSeriesData( samples ) ); 302 } 303 304 /*! 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 312 it when its not used anymore. 313 */ 314 void QwtPlotHistogram::setSamples( 315 QwtSeriesData<QwtIntervalSample> *data ) 316 { 317 setData( data ); 281 318 } 282 319 … … 287 324 \param xMap Maps x-values into pixel coordinates. 288 325 \param yMap Maps y-values into pixel coordinates. 289 \param canvasRect Contents rect of the canvas326 \param canvasRect Contents rectangle of the canvas 290 327 \param from Index of the first sample to be painted 291 328 \param to Index of the last sample to be painted. If to < 0 the … … 350 387 for ( int i = from; i <= to; i++ ) 351 388 { 352 const QwtIntervalSample sample = d_series->sample( i );389 const QwtIntervalSample sample = this->sample( i ); 353 390 354 391 if ( !sample.interval.isValid() ) … … 361 398 if ( previous.interval.isValid() ) 362 399 { 363 if ( ! isCombinable( previous.interval, sample.interval ) )400 if ( !qwtIsCombinable( previous.interval, sample.interval ) ) 364 401 flushPolygon( painter, v0, polygon ); 365 402 } … … 426 463 painter->setBrush( d_data->brush ); 427 464 465 const QwtSeriesData<QwtIntervalSample> *series = data(); 466 428 467 for ( int i = from; i <= to; i++ ) 429 468 { 430 const QwtIntervalSample sample = d_series->sample( i );469 const QwtIntervalSample sample = series->sample( i ); 431 470 if ( !sample.interval.isNull() ) 432 471 { … … 458 497 painter->setBrush( Qt::NoBrush ); 459 498 499 const QwtSeriesData<QwtIntervalSample> *series = data(); 500 460 501 for ( int i = from; i <= to; i++ ) 461 502 { 462 const QwtIntervalSample sample = d_series->sample( i );503 const QwtIntervalSample sample = series->sample( i ); 463 504 if ( !sample.interval.isNull() ) 464 505 { … … 532 573 polygon += QPointF( baseLine, polygon.first().y() ); 533 574 } 575 534 576 QwtPainter::drawPolygon( painter, polygon ); 535 polygon.resize( polygon.size() - 2 ); 577 578 polygon.pop_back(); 579 polygon.pop_back(); 536 580 } 537 581 if ( d_data->pen.style() != Qt::NoPen ) … … 601 645 602 646 \note In applications, where different intervals need to be displayed 603 in a different way ( f.e different colors or even using differ nt symbols)647 in a different way ( f.e different colors or even using different symbols) 604 648 it is recommended to overload drawColumn(). 605 649 */ … … 630 674 631 675 /*! 632 Draw a plain rectangle without pen using the brush() as identifier 633 634 \param painter Painter 635 \param rect Bounding rectangle for the identifier 636 */ 637 void QwtPlotHistogram::drawLegendIdentifier( 638 QPainter *painter, const QRectF &rect ) const 639 { 640 const double dim = qMin( rect.width(), rect.height() ); 641 642 QSizeF size( dim, dim ); 643 644 QRectF r( 0, 0, size.width(), size.height() ); 645 r.moveCenter( rect.center() ); 646 647 painter->fillRect( r, d_data->brush ); 648 } 676 A plain rectangle without pen using the brush() 677 678 \param index Index of the legend entry 679 ( ignored as there is only one ) 680 \param size Icon size 681 \return A graphic displaying the icon 682 683 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 684 */ 685 QwtGraphic QwtPlotHistogram::legendIcon( int index, 686 const QSizeF &size ) const 687 { 688 Q_UNUSED( index ); 689 return defaultIcon( d_data->brush, size ); 690 } -
trunk/BNC/qwt/qwt_plot_histogram.h
r4271 r8127 33 33 While "image histograms" can be displayed by a QwtPlotCurve there 34 34 is no applicable plot item for a "color histogram" yet. 35 36 \sa QwtPlotBarChart, QwtPlotMultiBarChart 35 37 */ 36 38 37 class QWT_EXPORT QwtPlotHistogram: public QwtPlotSeriesItem<QwtIntervalSample> 39 class QWT_EXPORT QwtPlotHistogram: 40 public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample> 38 41 { 39 42 public: … … 80 83 virtual int rtti() const; 81 84 85 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 82 86 void setPen( const QPen & ); 83 87 const QPen &pen() const; … … 87 91 88 92 void setSamples( const QVector<QwtIntervalSample> & ); 93 void setSamples( QwtSeriesData<QwtIntervalSample> * ); 89 94 90 95 void setBaseline( double reference ); … … 103 108 virtual QRectF boundingRect() const; 104 109 105 virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const;110 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 106 111 107 112 protected: -
trunk/BNC/qwt/qwt_plot_intervalcurve.cpp
r4271 r8127 13 13 #include "qwt_clipper.h" 14 14 #include "qwt_painter.h" 15 #include <string.h> 15 16 16 17 #include <qpainter.h> … … 24 25 25 26 const bool isOffScreen = ( y < yMin ) || ( y > yMax ) 26 || ( x1 < xMin && x2 < xMin ) || ( x1 > yMax && x2 > xMax );27 || ( x1 < xMin && x2 < xMin ) || ( x1 > xMax && x2 > xMax ); 27 28 28 29 return !isOffScreen; … … 46 47 public: 47 48 PrivateData(): 48 style( Tube ),49 style( QwtPlotIntervalCurve::Tube ), 49 50 symbol( NULL ), 50 51 pen( Qt::black ), … … 53 54 paintAttributes = QwtPlotIntervalCurve::ClipPolygons; 54 55 paintAttributes |= QwtPlotIntervalCurve::ClipSymbol; 55 56 56 57 pen.setCapStyle( Qt::FlatCap ); 57 58 } … … 62 63 } 63 64 64 CurveStyle style;65 QwtPlotIntervalCurve::CurveStyle style; 65 66 const QwtIntervalSymbol *symbol; 66 67 … … 76 77 */ 77 78 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ): 78 QwtPlotSeriesItem <QwtIntervalSample>( title )79 QwtPlotSeriesItem( title ) 79 80 { 80 81 init(); … … 86 87 */ 87 88 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ): 88 QwtPlotSeriesItem <QwtIntervalSample>( QwtText( title ) )89 QwtPlotSeriesItem( QwtText( title ) ) 89 90 { 90 91 init(); … … 104 105 105 106 d_data = new PrivateData; 106 d_series = new QwtIntervalSeriesData();107 setData( new QwtIntervalSeriesData() ); 107 108 108 109 setZ( 19.0 ); … … 122 123 \sa testPaintAttribute() 123 124 */ 124 void QwtPlotIntervalCurve::setPaintAttribute( 125 void QwtPlotIntervalCurve::setPaintAttribute( 125 126 PaintAttribute attribute, bool on ) 126 127 { … … 132 133 133 134 /*! 134 \ brief Return the current paint attributes135 \return True, when attribute is enabled 135 136 \sa PaintAttribute, setPaintAttribute() 136 137 */ 137 bool QwtPlotIntervalCurve::testPaintAttribute( 138 bool QwtPlotIntervalCurve::testPaintAttribute( 138 139 PaintAttribute attribute ) const 139 140 { … … 148 149 const QVector<QwtIntervalSample> &samples ) 149 150 { 150 delete d_series; 151 d_series = new QwtIntervalSeriesData( samples ); 152 itemChanged(); 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 ); 153 168 } 154 169 … … 164 179 { 165 180 d_data->style = style; 181 182 legendChanged(); 166 183 itemChanged(); 167 184 } … … 169 186 170 187 /*! 171 \ brief Return the current style188 \return Style of the curve 172 189 \sa setStyle() 173 190 */ … … 189 206 delete d_data->symbol; 190 207 d_data->symbol = symbol; 208 209 legendChanged(); 191 210 itemChanged(); 192 211 } … … 201 220 return d_data->symbol; 202 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 } 203 240 204 241 /*! … … 212 249 { 213 250 d_data->pen = pen; 251 252 legendChanged(); 214 253 itemChanged(); 215 254 } … … 217 256 218 257 /*! 219 \ brief Return the pen used to draw the lines258 \return Pen used to draw the lines 220 259 \sa setPen(), brush() 221 260 */ … … 238 277 { 239 278 d_data->brush = brush; 279 280 legendChanged(); 240 281 itemChanged(); 241 282 } … … 257 298 QRectF QwtPlotIntervalCurve::boundingRect() const 258 299 { 259 QRectF rect = QwtPlotSeriesItem <QwtIntervalSample>::boundingRect();300 QRectF rect = QwtPlotSeriesItem::boundingRect(); 260 301 if ( rect.isValid() && orientation() == Qt::Vertical ) 261 302 rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() ); … … 270 311 \param xMap Maps x-values into pixel coordinates. 271 312 \param yMap Maps y-values into pixel coordinates. 272 \param canvasRect Contents rect of the canvas313 \param canvasRect Contents rectangle of the canvas 273 314 \param from Index of the first sample to be painted 274 315 \param to Index of the last sample to be painted. If to < 0 the … … 304 345 ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) 305 346 { 306 drawSymbols( painter, *d_data->symbol, 347 drawSymbols( painter, *d_data->symbol, 307 348 xMap, yMap, canvasRect, from, to ); 308 349 } … … 319 360 \param xMap Maps x-values into pixel coordinates. 320 361 \param yMap Maps y-values into pixel coordinates. 321 \param canvasRect Contents rect of the canvas362 \param canvasRect Contents rectangle of the canvas 322 363 \param from Index of the first sample to be painted 323 364 \param to Index of the last sample to be painted. If to < 0 the … … 388 429 { 389 430 const qreal m = 1.0; 390 const QPolygonF p = QwtClipper::clipPolygonF( 391 canvasRect.adjusted(-m, -m, m, m), polygon, true );431 const QPolygonF p = QwtClipper::clipPolygonF( 432 canvasRect.adjusted( -m, -m, m, m ), polygon, true ); 392 433 393 434 QwtPainter::drawPolygon( painter, p ); … … 406 447 if ( d_data->paintAttributes & ClipPolygons ) 407 448 { 408 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );409 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw);449 qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() ); 450 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 410 451 411 452 QPolygonF p; 412 453 413 454 p.resize( size ); 414 qMemCopy( p.data(), points, size * sizeof( QPointF ) );415 p = QwtClipper::clipPolygonF( c anvasRect, p );455 ::memcpy( p.data(), points, size * sizeof( QPointF ) ); 456 p = QwtClipper::clipPolygonF( clipRect, p ); 416 457 QwtPainter::drawPolyline( painter, p ); 417 458 418 459 p.resize( size ); 419 qMemCopy( p.data(), points + size, size * sizeof( QPointF ) );420 p = QwtClipper::clipPolygonF( c anvasRect, p );460 ::memcpy( p.data(), points + size, size * sizeof( QPointF ) ); 461 p = QwtClipper::clipPolygonF( clipRect, p ); 421 462 QwtPainter::drawPolyline( painter, p ); 422 463 } … … 438 479 \param xMap x map 439 480 \param yMap y map 440 \param canvasRect Contents rect of the canvas481 \param canvasRect Contents rectangle of the canvas 441 482 \param from Index of the first sample to be painted 442 483 \param to Index of the last sample to be painted … … 457 498 painter->setBrush( symbol.brush() ); 458 499 459 const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect);500 const QRectF tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect ); 460 501 461 502 const double xMin = tr.left(); … … 464 505 const double yMax = tr.bottom(); 465 506 466 const bool doClip = d_data->paintAttributes & Clip Polygons;507 const bool doClip = d_data->paintAttributes & ClipSymbol; 467 508 468 509 for ( int i = from; i <= to; i++ ) … … 500 541 501 542 /*! 502 In case of Tibe stale() a plain rectangle is painted without a pen filled 503 the brush(). If a symbol is assigned it is painted cebtered into rect. 504 505 \param painter Painter 506 \param rect Bounding rectangle for the identifier 507 */ 508 509 void QwtPlotIntervalCurve::drawLegendIdentifier( 510 QPainter *painter, const QRectF &rect ) const 511 { 512 const double dim = qMin( rect.width(), rect.height() ); 513 514 QSizeF size( dim, dim ); 515 516 QRectF r( 0, 0, size.width(), size.height() ); 517 r.moveCenter( rect.center() ); 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 549 ( ignored as there is only one ) 550 \param size Icon size 551 552 \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData() 553 */ 554 QwtGraphic QwtPlotIntervalCurve::legendIcon( 555 int index, const QSizeF &size ) const 556 { 557 Q_UNUSED( index ); 558 559 if ( size.isEmpty() ) 560 return QwtGraphic(); 561 562 QwtGraphic icon; 563 icon.setDefaultSize( size ); 564 icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 565 566 QPainter painter( &icon ); 567 painter.setRenderHint( QPainter::Antialiasing, 568 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 518 569 519 570 if ( d_data->style == Tube ) 520 571 { 521 painter->fillRect( r, d_data->brush ); 572 QRectF r( 0, 0, size.width(), size.height() ); 573 painter.fillRect( r, d_data->brush ); 522 574 } 523 575 … … 529 581 pen.setCapStyle( Qt::FlatCap ); 530 582 531 painter ->setPen( pen );532 painter ->setBrush( d_data->symbol->brush() );583 painter.setPen( pen ); 584 painter.setBrush( d_data->symbol->brush() ); 533 585 534 586 if ( orientation() == Qt::Vertical ) 535 587 { 536 d_data->symbol->draw( painter, orientation(), 537 QPointF( r.center().x(), r.top() ), 538 QPointF( r.center().x(), r.bottom() - 1 ) ); 588 const double x = 0.5 * size.width(); 589 590 d_data->symbol->draw( &painter, orientation(), 591 QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) ); 539 592 } 540 593 else 541 594 { 542 d_data->symbol->draw( painter, orientation(), 543 QPointF( r.left(), r.center().y() ), 544 QPointF( r.right() - 1, r.center().y() ) ); 545 } 546 } 547 } 595 const double y = 0.5 * size.height(); 596 597 d_data->symbol->draw( &painter, orientation(), 598 QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) ); 599 } 600 } 601 602 return icon; 603 } -
trunk/BNC/qwt/qwt_plot_intervalcurve.h
r4271 r8127 23 23 The representation depends on the style() and an optional symbol() 24 24 that is displayed for each interval. QwtPlotIntervalCurve might be used 25 to displ y error bars or the area between 2 curves.25 to display error bars or the area between 2 curves. 26 26 */ 27 28 class QWT_EXPORT QwtPlotIntervalCurve: public QwtPlotSeriesItem<QwtIntervalSample>27 class QWT_EXPORT QwtPlotIntervalCurve: 28 public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample> 29 29 { 30 30 public: … … 35 35 \sa setStyle(), style() 36 36 */ 37 38 37 enum CurveStyle 39 38 { … … 89 88 90 89 void setSamples( const QVector<QwtIntervalSample> & ); 90 void setSamples( QwtSeriesData<QwtIntervalSample> * ); 91 91 92 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 92 93 void setPen( const QPen & ); 93 94 const QPen &pen() const; … … 107 108 108 109 virtual QRectF boundingRect() const; 109 virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const; 110 111 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 110 112 111 113 protected: -
trunk/BNC/qwt/qwt_plot_item.cpp
r4271 r8127 11 11 #include "qwt_text.h" 12 12 #include "qwt_plot.h" 13 #include "qwt_legend.h" 14 #include "qwt_legend_item.h" 13 #include "qwt_legend_data.h" 15 14 #include "qwt_scale_div.h" 15 #include "qwt_graphic.h" 16 16 #include <qpainter.h> 17 17 … … 23 23 isVisible( true ), 24 24 attributes( 0 ), 25 interests( 0 ), 25 26 renderHints( 0 ), 27 renderThreadCount( 1 ), 26 28 z( 0.0 ), 27 29 xAxis( QwtPlot::xBottom ), 28 yAxis( QwtPlot::yLeft ) 30 yAxis( QwtPlot::yLeft ), 31 legendIconSize( 8, 8 ) 29 32 { 30 33 } … … 33 36 34 37 bool isVisible; 38 35 39 QwtPlotItem::ItemAttributes attributes; 40 QwtPlotItem::ItemInterests interests; 41 36 42 QwtPlotItem::RenderHints renderHints; 43 uint renderThreadCount; 44 37 45 double z; 38 46 … … 41 49 42 50 QwtText title; 51 QSize legendIconSize; 43 52 }; 44 53 … … 76 85 return; 77 86 78 // remove the item from the previous plot79 80 87 if ( d_data->plot ) 81 {82 if ( d_data->plot->legend() )83 d_data->plot->legend()->remove( this );84 85 88 d_data->plot->attachItem( this, false ); 86 89 87 if ( d_data->plot->autoReplot() )88 d_data->plot->update();89 }90 91 90 d_data->plot = plot; 92 91 93 92 if ( d_data->plot ) 94 {95 // insert the item into the current plot96 97 93 d_data->plot->attachItem( this, true ); 98 itemChanged();99 }100 94 } 101 95 … … 191 185 { 192 186 d_data->title = title; 193 itemChanged(); 187 188 legendChanged(); 189 #if 0 190 itemChanged(); 191 #endif 194 192 } 195 193 } … … 210 208 \param on true/false 211 209 212 \sa testItemAttribute(), Item Attribute210 \sa testItemAttribute(), ItemInterest 213 211 */ 214 212 void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on ) 215 213 { 216 if ( bool( d_data->attributes &attribute ) != on )214 if ( d_data->attributes.testFlag( attribute ) != on ) 217 215 { 218 216 if ( on ) … … 221 219 d_data->attributes &= ~attribute; 222 220 221 if ( attribute == QwtPlotItem::Legend ) 222 legendChanged(); 223 223 224 itemChanged(); 224 225 } … … 230 231 \param attribute Attribute type 231 232 \return true/false 232 \sa setItemAttribute(), Item Attribute233 \sa setItemAttribute(), ItemInterest 233 234 */ 234 235 bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const 235 236 { 236 return ( d_data->attributes & attribute ); 237 return d_data->attributes.testFlag( attribute ); 238 } 239 240 /*! 241 Toggle an item interest 242 243 \param interest Interest type 244 \param on true/false 245 246 \sa testItemInterest(), ItemAttribute 247 */ 248 void QwtPlotItem::setItemInterest( ItemInterest interest, bool on ) 249 { 250 if ( d_data->interests.testFlag( interest ) != on ) 251 { 252 if ( on ) 253 d_data->interests |= interest; 254 else 255 d_data->interests &= ~interest; 256 257 itemChanged(); 258 } 259 } 260 261 /*! 262 Test an item interest 263 264 \param interest Interest type 265 \return true/false 266 \sa setItemInterest(), ItemAttribute 267 */ 268 bool QwtPlotItem::testItemInterest( ItemInterest interest ) const 269 { 270 return d_data->interests.testFlag( interest ); 237 271 } 238 272 … … 247 281 void QwtPlotItem::setRenderHint( RenderHint hint, bool on ) 248 282 { 249 if ( ( ( d_data->renderHints & hint ) != 0) != on )283 if ( d_data->renderHints.testFlag( hint ) != on ) 250 284 { 251 285 if ( on ) … … 267 301 bool QwtPlotItem::testRenderHint( RenderHint hint ) const 268 302 { 269 return ( d_data->renderHints & hint ); 270 } 303 return d_data->renderHints.testFlag( hint ); 304 } 305 306 /*! 307 On multi core systems rendering of certain plot item 308 ( f.e QwtPlotRasterItem ) can be done in parallel in 309 several threads. 310 311 The default setting is set to 1. 312 313 \param numThreads Number of threads to be used for rendering. 314 If numThreads is set to 0, the system specific 315 ideal thread count is used. 316 317 The default thread count is 1 ( = no additional threads ) 318 */ 319 void QwtPlotItem::setRenderThreadCount( uint numThreads ) 320 { 321 d_data->renderThreadCount = numThreads; 322 } 323 324 /*! 325 \return Number of threads to be used for rendering. 326 If numThreads() is set to 0, the system specific 327 ideal thread count is used. 328 */ 329 uint QwtPlotItem::renderThreadCount() const 330 { 331 return d_data->renderThreadCount; 332 } 333 334 /*! 335 Set the size of the legend icon 336 337 The default setting is 8x8 pixels 338 339 \param size Size 340 \sa legendIconSize(), legendIcon() 341 */ 342 void QwtPlotItem::setLegendIconSize( const QSize &size ) 343 { 344 if ( d_data->legendIconSize != size ) 345 { 346 d_data->legendIconSize = size; 347 legendChanged(); 348 } 349 } 350 351 /*! 352 \return Legend icon size 353 \sa setLegendIconSize(), legendIcon() 354 */ 355 QSize QwtPlotItem::legendIconSize() const 356 { 357 return d_data->legendIconSize; 358 } 359 360 /*! 361 \return Icon representing the item on the legend 362 363 The default implementation returns an invalid icon 364 365 \param index Index of the legend entry 366 ( usually there is only one ) 367 \param size Icon size 368 369 \sa setLegendIconSize(), legendData() 370 */ 371 QwtGraphic QwtPlotItem::legendIcon( 372 int index, const QSizeF &size ) const 373 { 374 Q_UNUSED( index ) 375 Q_UNUSED( size ) 376 377 return QwtGraphic(); 378 } 379 380 /*! 381 \brief Return a default icon from a brush 382 383 The default icon is a filled rectangle used 384 in several derived classes as legendIcon(). 385 386 \param brush Fill brush 387 \param size Icon size 388 389 \return A filled rectangle 390 */ 391 QwtGraphic QwtPlotItem::defaultIcon( 392 const QBrush &brush, const QSizeF &size ) const 393 { 394 QwtGraphic icon; 395 if ( !size.isEmpty() ) 396 { 397 icon.setDefaultSize( size ); 398 399 QRectF r( 0, 0, size.width(), size.height() ); 400 401 QPainter painter( &icon ); 402 painter.fillRect( r, brush ); 403 } 404 405 return icon; 406 } 271 407 272 408 //! Show the item … … 307 443 308 444 /*! 309 Update the legend and call QwtPlot::autoRefresh for the445 Update the legend and call QwtPlot::autoRefresh() for the 310 446 parent plot. 311 447 312 \sa updateLegend()448 \sa QwtPlot::legendChanged(), QwtPlot::autoRefresh() 313 449 */ 314 450 void QwtPlotItem::itemChanged() 315 451 { 316 452 if ( d_data->plot ) 317 {318 if ( d_data->plot->legend() )319 updateLegend( d_data->plot->legend() );320 321 453 d_data->plot->autoRefresh(); 322 } 454 } 455 456 /*! 457 Update the legend of the parent plot. 458 \sa QwtPlot::updateLegend(), itemChanged() 459 */ 460 void QwtPlotItem::legendChanged() 461 { 462 if ( testItemAttribute( QwtPlotItem::Legend ) && d_data->plot ) 463 d_data->plot->updateLegend( this ); 323 464 } 324 465 … … 326 467 Set X and Y axis 327 468 328 The item will painted according to the coordinates its Axes.329 330 \param xAxis X Axis 331 \param yAxis Y Axis 332 333 \sa setXAxis(), setYAxis(), xAxis(), yAxis() 469 The item will painted according to the coordinates of its Axes. 470 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::Axis 334 475 */ 335 476 void QwtPlotItem::setAxes( int xAxis, int yAxis ) … … 349 490 The item will painted according to the coordinates its Axes. 350 491 351 \param axis X Axis 352 \sa setAxes(), setYAxis(), xAxis() 492 \param axis X Axis ( QwtPlot::xBottom or QwtPlot::xTop ) 493 \sa setAxes(), setYAxis(), xAxis(), QwtPlot::Axis 353 494 */ 354 495 void QwtPlotItem::setXAxis( int axis ) … … 366 507 The item will painted according to the coordinates its Axes. 367 508 368 \param axis Y Axis 369 \sa setAxes(), setXAxis(), yAxis() 509 \param axis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight ) 510 \sa setAxes(), setXAxis(), yAxis(), QwtPlot::Axis 370 511 */ 371 512 void QwtPlotItem::setYAxis( int axis ) … … 392 533 /*! 393 534 \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0) 535 \note A width or height < 0.0 is ignored by the autoscaler 394 536 */ 395 537 QRectF QwtPlotItem::boundingRect() const … … 399 541 400 542 /*! 401 \brief Allocate the widget that represents the item on the legend 402 403 The default implementation returns a QwtLegendItem(), but an item 404 could be represented by any type of widget, 405 by overloading legendItem() and updateLegend(). 406 407 \return QwtLegendItem() 408 \sa updateLegend() QwtLegend() 409 */ 410 QWidget *QwtPlotItem::legendItem() const 411 { 412 QwtLegendItem *item = new QwtLegendItem; 413 if ( d_data->plot ) 414 { 415 QObject::connect( item, SIGNAL( clicked() ), 416 d_data->plot, SLOT( legendItemClicked() ) ); 417 QObject::connect( item, SIGNAL( checked( bool ) ), 418 d_data->plot, SLOT( legendItemChecked( bool ) ) ); 419 } 420 return item; 421 } 422 423 /*! 424 \brief Update the widget that represents the item on the legend 425 426 updateLegend() is called from itemChanged() to adopt the widget 427 representing the item on the legend to its new configuration. 428 429 The default implementation updates a QwtLegendItem(), 430 but an item could be represented by any type of widget, 431 by overloading legendItem() and updateLegend(). 432 433 \param legend Legend 434 435 \sa legendItem(), itemChanged(), QwtLegend() 436 */ 437 void QwtPlotItem::updateLegend( QwtLegend *legend ) const 438 { 439 if ( legend == NULL ) 440 return; 441 442 QWidget *lgdItem = legend->find( this ); 443 if ( testItemAttribute( QwtPlotItem::Legend ) ) 444 { 445 if ( lgdItem == NULL ) 446 { 447 lgdItem = legendItem(); 448 if ( lgdItem ) 449 legend->insert( this, lgdItem ); 450 } 451 452 QwtLegendItem *label = qobject_cast<QwtLegendItem *>( lgdItem ); 453 if ( label ) 454 { 455 // paint the identifier 456 const QSize sz = label->identifierSize(); 457 458 QPixmap identifier( sz.width(), sz.height() ); 459 identifier.fill( Qt::transparent ); 460 461 QPainter painter( &identifier ); 462 painter.setRenderHint( QPainter::Antialiasing, 463 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 464 drawLegendIdentifier( &painter, 465 QRect( 0, 0, sz.width(), sz.height() ) ); 466 painter.end(); 467 468 const bool doUpdate = label->updatesEnabled(); 469 if ( doUpdate ) 470 label->setUpdatesEnabled( false ); 471 472 label->setText( title() ); 473 label->setIdentifier( identifier ); 474 label->setItemMode( legend->itemMode() ); 475 476 if ( doUpdate ) 477 label->setUpdatesEnabled( true ); 478 479 label->update(); 480 } 481 } 482 else 483 { 484 if ( lgdItem ) 485 { 486 lgdItem->hide(); 487 lgdItem->deleteLater(); 488 } 489 } 543 \brief Calculate a hint for the canvas margin 544 545 When the QwtPlotItem::Margins flag is enabled the plot item 546 indicates, that it needs some margins at the borders of the canvas. 547 This is f.e. used by bar charts to reserve space for displaying 548 the bars. 549 550 The margins are in target device coordinates ( pixels on screen ) 551 552 \param xMap Maps x-values into pixel coordinates. 553 \param yMap Maps y-values into pixel coordinates. 554 \param canvasRect Contents rectangle of the canvas in painter coordinates 555 \param left Returns the left margin 556 \param top Returns the top margin 557 \param right Returns the right margin 558 \param bottom Returns the bottom margin 559 560 \return The default implementation returns 0 for all margins 561 562 \sa QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins() 563 */ 564 void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap &xMap, 565 const QwtScaleMap &yMap, const QRectF &canvasRect, 566 double &left, double &top, double &right, double &bottom ) const 567 { 568 Q_UNUSED( xMap ); 569 Q_UNUSED( yMap ); 570 Q_UNUSED( canvasRect ); 571 572 // use QMargins, when we don't need to support Qt < 4.6 anymore 573 left = top = right = bottom = 0.0; 574 } 575 576 /*! 577 \brief Return all information, that is needed to represent 578 the item on the legend 579 580 Most items are represented by one entry on the legend 581 showing an icon and a text, but f.e. QwtPlotMultiBarChart 582 displays one entry for each bar. 583 584 QwtLegendData is basically a list of QVariants that makes it 585 possible to overload and reimplement legendData() to 586 return almost any type of information, that is understood 587 by the receiver that acts as the legend. 588 589 The default implementation returns one entry with 590 the title() of the item and the legendIcon(). 591 592 \return Data, that is needed to represent the item on the legend 593 \sa title(), legendIcon(), QwtLegend, QwtPlotLegendItem 594 */ 595 QList<QwtLegendData> QwtPlotItem::legendData() const 596 { 597 QwtLegendData data; 598 599 QwtText label = title(); 600 label.setRenderFlags( label.renderFlags() & Qt::AlignLeft ); 601 602 QVariant titleValue; 603 qVariantSetValue( titleValue, label ); 604 data.setValue( QwtLegendData::TitleRole, titleValue ); 605 606 const QwtGraphic graphic = legendIcon( 0, legendIconSize() ); 607 if ( !graphic.isNull() ) 608 { 609 QVariant iconValue; 610 qVariantSetValue( iconValue, graphic ); 611 data.setValue( QwtLegendData::IconRole, iconValue ); 612 } 613 614 QList<QwtLegendData> list; 615 list += data; 616 617 return list; 490 618 } 491 619 … … 498 626 updateScaleDiv() 499 627 628 updateScaleDiv() is only called when the ScaleInterest interest 629 is enabled. The default implementation does nothing. 630 500 631 \param xScaleDiv Scale division of the x-axis 501 632 \param yScaleDiv Scale division of the y-axis 502 633 503 \sa QwtPlot::updateAxes() 634 \sa QwtPlot::updateAxes(), ScaleInterest 504 635 */ 505 636 void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv, … … 511 642 512 643 /*! 513 \brief Calculate the bounding scale rect of 2 maps 514 515 \param xMap X map 516 \param yMap X map 517 518 \return Bounding scale rect of the scale maps, normalized 644 \brief Update the item to changes of the legend info 645 646 Plot items that want to display a legend ( not those, that want to 647 be displayed on a legend ! ) will have to implement updateLegend(). 648 649 updateLegend() is only called when the LegendInterest interest 650 is enabled. The default implementation does nothing. 651 652 \param item Plot item to be displayed on a legend 653 \param data Attributes how to display item on the legend 654 655 \sa QwtPlotLegendItem 656 657 \note Plot items, that want to be displayed on a legend 658 need to enable the QwtPlotItem::Legend flag and to implement 659 legendData() and legendIcon() 660 */ 661 void QwtPlotItem::updateLegend( const QwtPlotItem *item, 662 const QList<QwtLegendData> &data ) 663 { 664 Q_UNUSED( item ); 665 Q_UNUSED( data ); 666 } 667 668 /*! 669 \brief Calculate the bounding scale rectangle of 2 maps 670 671 \param xMap Maps x-values into pixel coordinates. 672 \param yMap Maps y-values into pixel coordinates. 673 674 \return Bounding scale rect of the scale maps, not normalized 519 675 */ 520 676 QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap, … … 526 682 527 683 /*! 528 \brief Calculate the bounding paint rect of 2 maps529 530 \param xMap X map531 \param yMap X map532 533 \return Bounding paint rect of the scale maps,normalized684 \brief Calculate the bounding paint rectangle of 2 maps 685 686 \param xMap Maps x-values into pixel coordinates. 687 \param yMap Maps y-values into pixel coordinates. 688 689 \return Bounding paint rectangle of the scale maps, not normalized 534 690 */ 535 691 QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap, -
trunk/BNC/qwt/qwt_plot_item.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_legend_itemmanager.h"15 14 #include "qwt_text.h" 15 #include "qwt_legend_data.h" 16 #include "qwt_graphic.h" 16 17 #include <qrect.h> 17 18 class QString; 18 #include <qlist.h> 19 #include <qmetatype.h> 20 19 21 class QPainter; 20 class QWidget;21 class QwtPlot;22 class QwtLegend;23 22 class QwtScaleMap; 24 23 class QwtScaleDiv; 24 class QwtPlot; 25 25 26 26 /*! … … 51 51 52 52 Depending on the QwtPlotItem::ItemAttribute flags, an item is included 53 into autoscaling or has an entry on the leg nd.53 into autoscaling or has an entry on the legend. 54 54 55 55 Before misusing the existing item classes it might be better to … … 62 62 */ 63 63 64 class QWT_EXPORT QwtPlotItem : public QwtLegendItemManager64 class QWT_EXPORT QwtPlotItem 65 65 { 66 66 public: … … 73 73 enum RttiValues 74 74 { 75 //! Unspecific value, that can be used, when it doesn't matter 75 76 Rtti_PlotItem = 0, 76 77 78 //! For QwtPlotGrid 77 79 Rtti_PlotGrid, 80 81 //! For QwtPlotScaleItem 78 82 Rtti_PlotScale, 83 84 //! For QwtPlotLegendItem 85 Rtti_PlotLegend, 86 87 //! For QwtPlotMarker 79 88 Rtti_PlotMarker, 89 90 //! For QwtPlotCurve 80 91 Rtti_PlotCurve, 92 93 //! For QwtPlotSpectroCurve 81 94 Rtti_PlotSpectroCurve, 95 96 //! For QwtPlotIntervalCurve 82 97 Rtti_PlotIntervalCurve, 98 99 //! For QwtPlotHistogram 83 100 Rtti_PlotHistogram, 101 102 //! For QwtPlotSpectrogram 84 103 Rtti_PlotSpectrogram, 104 105 //! For QwtPlotSvgItem 85 106 Rtti_PlotSVG, 86 107 108 //! For QwtPlotTradingCurve 109 Rtti_PlotTradingCurve, 110 111 //! For QwtPlotBarChart 112 Rtti_PlotBarChart, 113 114 //! For QwtPlotMultiBarChart 115 Rtti_PlotMultiBarChart, 116 117 //! For QwtPlotShapeItem 118 Rtti_PlotShape, 119 120 //! For QwtPlotTextLabel 121 Rtti_PlotTextLabel, 122 123 //! For QwtPlotZoneItem 124 Rtti_PlotZone, 125 126 /*! 127 Values >= Rtti_PlotUserItem are reserved for plot items 128 not implemented in the Qwt library. 129 */ 87 130 Rtti_PlotUserItem = 1000 88 131 }; 89 132 90 133 /*! 91 Plot Item Attributes 92 \sa setItemAttribute(), testItemAttribute() 134 \brief Plot Item Attributes 135 136 Various aspects of a plot widget depend on the attributes of 137 the attached plot items. If and how a single plot item 138 participates in these updates depends on its attributes. 139 140 \sa setItemAttribute(), testItemAttribute(), ItemInterest 93 141 */ 94 142 enum ItemAttribute … … 98 146 99 147 /*! 100 The boundingRect() of the item is included in the 101 autoscaling calculation. 102 */ 103 AutoScale = 0x02 148 The boundingRect() of the item is included in the 149 autoscaling calculation as long as its width or height 150 is >= 0.0. 151 */ 152 AutoScale = 0x02, 153 154 /*! 155 The item needs extra space to display something outside 156 its bounding rectangle. 157 \sa getCanvasMarginHint() 158 */ 159 Margins = 0x04 104 160 }; 105 161 106 162 //! Plot Item Attributes 107 163 typedef QFlags<ItemAttribute> ItemAttributes; 164 165 /*! 166 \brief Plot Item Interests 167 168 Plot items might depend on the situation of the corresponding 169 plot widget. By enabling an interest the plot item will be 170 notified, when the corresponding attribute of the plot widgets 171 has changed. 172 173 \sa setItemAttribute(), testItemAttribute(), ItemInterest 174 */ 175 enum ItemInterest 176 { 177 /*! 178 The item is interested in updates of the scales 179 \sa updateScaleDiv() 180 */ 181 ScaleInterest = 0x01, 182 183 /*! 184 The item is interested in updates of the legend ( of other items ) 185 This flag is intended for items, that want to implement a legend 186 for displaying entries of other plot item. 187 188 \note If the plot item wants to be represented on a legend 189 enable QwtPlotItem::Legend instead. 190 191 \sa updateLegend() 192 */ 193 LegendInterest = 0x02 194 }; 195 196 //! Plot Item Interests 197 typedef QFlags<ItemInterest> ItemInterests; 108 198 109 199 //! Render hints … … 111 201 { 112 202 //! Enable antialiasing 113 RenderAntialiased = 1203 RenderAntialiased = 0x1 114 204 }; 115 205 … … 134 224 bool testItemAttribute( ItemAttribute ) const; 135 225 226 void setItemInterest( ItemInterest, bool on = true ); 227 bool testItemInterest( ItemInterest ) const; 228 136 229 void setRenderHint( RenderHint, bool on = true ); 137 230 bool testRenderHint( RenderHint ) const; 231 232 void setRenderThreadCount( uint numThreads ); 233 uint renderThreadCount() const; 234 235 void setLegendIconSize( const QSize & ); 236 QSize legendIconSize() const; 138 237 139 238 double z() const; … … 154 253 155 254 virtual void itemChanged(); 255 virtual void legendChanged(); 156 256 157 257 /*! … … 169 269 virtual QRectF boundingRect() const; 170 270 171 virtual void updateLegend( QwtLegend * ) const; 271 virtual void getCanvasMarginHint( 272 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 273 const QRectF &canvasSize, 274 double &left, double &top, double &right, double &bottom) const; 275 172 276 virtual void updateScaleDiv( 173 277 const QwtScaleDiv&, const QwtScaleDiv& ); 174 278 175 virtual QWidget *legendItem() const; 279 virtual void updateLegend( const QwtPlotItem *, 280 const QList<QwtLegendData> & ); 176 281 177 282 QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const; 178 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; 179 291 180 292 private: … … 188 300 189 301 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemAttributes ) 302 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemInterests ) 190 303 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::RenderHints ) 191 304 305 Q_DECLARE_METATYPE( QwtPlotItem * ) 306 192 307 #endif -
trunk/BNC/qwt/qwt_plot_layout.cpp
r4271 r8127 11 11 #include "qwt_text.h" 12 12 #include "qwt_text_label.h" 13 #include "qwt_plot_canvas.h"14 13 #include "qwt_scale_widget.h" 15 #include "qwt_ legend.h"14 #include "qwt_abstract_legend.h" 16 15 #include <qscrollbar.h> 17 16 #include <qmath.h> … … 25 24 { 26 25 int frameWidth; 27 int vScrollBarWidth;28 int hScrollBarHeight;26 int hScrollExtent; 27 int vScrollExtent; 29 28 QSize hint; 30 29 } legend; … … 35 34 int frameWidth; 36 35 } title; 36 37 struct t_footerData 38 { 39 QwtText text; 40 int frameWidth; 41 } footer; 37 42 38 43 struct t_scaleData … … 44 49 int end; 45 50 int baseLineOffset; 46 inttickOffset;51 double tickOffset; 47 52 int dimWithoutTitle; 48 53 } scale[QwtPlot::axisCnt]; … … 50 55 struct t_canvasData 51 56 { 52 int frameWidth; 57 int contentsMargins[ QwtPlot::axisCnt ]; 58 53 59 } canvas; 54 60 }; … … 57 63 Extract all layout relevant data from the plot components 58 64 */ 59 60 65 void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect ) 61 66 { 62 67 // legend 63 68 64 if ( plot->plotLayout()->legendPosition() != QwtPlot::ExternalLegend 65 && plot->legend() ) 69 if ( plot->legend() ) 66 70 { 67 71 legend.frameWidth = plot->legend()->frameWidth(); 68 legend. vScrollBarWidth=69 plot->legend()-> verticalScrollBar()->sizeHint().width();70 legend. hScrollBarHeight =71 plot->legend()-> horizontalScrollBar()->sizeHint().height();72 legend.hScrollExtent = 73 plot->legend()->scrollExtent( Qt::Horizontal ); 74 legend.vScrollExtent = 75 plot->legend()->scrollExtent( Qt::Vertical ); 72 76 73 77 const QSize hint = plot->legend()->sizeHint(); 74 78 75 int w = qMin( hint.width(), qFloor( rect.width() ) ); 79 const int w = qMin( hint.width(), qFloor( rect.width() ) ); 80 76 81 int h = plot->legend()->heightForWidth( w ); 77 if ( h == 0 )82 if ( h <= 0 ) 78 83 h = hint.height(); 79 80 if ( h > rect.height() )81 w += legend.vScrollBarWidth;82 84 83 85 legend.hint = QSize( w, h ); … … 99 101 } 100 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 101 118 // scales 102 119 … … 140 157 scale[axis].end = 0; 141 158 scale[axis].baseLineOffset = 0; 142 scale[axis].tickOffset = 0 ;159 scale[axis].tickOffset = 0.0; 143 160 scale[axis].dimWithoutTitle = 0; 144 161 } … … 147 164 // canvas 148 165 149 canvas.frameWidth = plot->canvas()->frameWidth(); 166 plot->canvas()->getContentsMargins( 167 &canvas.contentsMargins[ QwtPlot::yLeft ], 168 &canvas.contentsMargins[ QwtPlot::xTop ], 169 &canvas.contentsMargins[ QwtPlot::yRight ], 170 &canvas.contentsMargins[ QwtPlot::xBottom ] ); 150 171 } 151 172 … … 154 175 public: 155 176 PrivateData(): 156 spacing( 5 ), 157 alignCanvasToScales( false ) 177 spacing( 5 ) 158 178 { 159 179 } 160 180 161 181 QRectF titleRect; 182 QRectF footerRect; 162 183 QRectF legendRect; 163 184 QRectF scaleRect[QwtPlot::axisCnt]; … … 170 191 unsigned int spacing; 171 192 unsigned int canvasMargin[QwtPlot::axisCnt]; 172 bool alignCanvasToScales ;193 bool alignCanvasToScales[QwtPlot::axisCnt]; 173 194 }; 174 195 … … 183 204 setLegendPosition( QwtPlot::BottomLegend ); 184 205 setCanvasMargin( 4 ); 206 setAlignCanvasToScales( false ); 185 207 186 208 invalidate(); … … 203 225 \sa canvasMargin() 204 226 205 \warning The margin will have no effect when alignCanvasToScale sis true227 \warning The margin will have no effect when alignCanvasToScale() is true 206 228 */ 207 229 … … 221 243 222 244 /*! 245 \param axisId Axis index 223 246 \return Margin around the scale tick borders 224 247 \sa setCanvasMargin() 225 248 */ 226 int QwtPlotLayout::canvasMargin( int axis ) const227 { 228 if ( axis < 0 || axis>= QwtPlot::axisCnt )249 int QwtPlotLayout::canvasMargin( int axisId ) const 250 { 251 if ( axisId < 0 || axisId >= QwtPlot::axisCnt ) 229 252 return 0; 230 253 231 return d_data->canvasMargin[axis]; 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; 232 267 } 233 268 234 269 /*! 235 270 Change the align-canvas-to-axis-scales setting. The canvas may: 271 236 272 - extend beyond the axis scale ends to maximize its size, 237 273 - align with the axis scale ends to control its size. 238 274 239 \param alignCanvasToScales New align-canvas-to-axis-scales setting 240 241 \sa setCanvasMargin() 242 \note In this context the term 'scale' means the backbone of a scale. 243 \warning In case of alignCanvasToScales == true canvasMargin will have 244 no effect 245 */ 246 void QwtPlotLayout::setAlignCanvasToScales( bool alignCanvasToScales ) 247 { 248 d_data->alignCanvasToScales = alignCanvasToScales; 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; 249 290 } 250 291 … … 254 295 - align with the axis scale ends to control its size. 255 296 297 \param axisId Axis index 256 298 \return align-canvas-to-axis-scales setting 257 \sa setAlignCanvasToScales, setCanvasMargin() 258 \note In this context the term 'scale' means the backbone of a scale. 259 */ 260 bool QwtPlotLayout::alignCanvasToScales() const 261 { 262 return d_data->alignCanvasToScales; 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 ]; 263 307 } 264 308 … … 267 311 between the plot components. 268 312 269 \param spacing new spacing270 \sa set Margin(), spacing()313 \param spacing New spacing 314 \sa setCanvasMargin(), spacing() 271 315 */ 272 316 void QwtPlotLayout::setSpacing( int spacing ) … … 276 320 277 321 /*! 278 \return spacing322 \return Spacing 279 323 \sa margin(), setSpacing() 280 324 */ … … 287 331 \brief Specify the position of the legend 288 332 \param pos The legend's position. 289 \param ratio Ratio between legend and the bounding rect 290 of title, canvas and axes. The legend will be shrinked333 \param ratio Ratio between legend and the bounding rectangle 334 of title, footer, canvas and axes. The legend will be shrunk 291 335 if it would need more space than the given ratio. 292 336 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 … … 318 362 d_data->legendPos = pos; 319 363 break; 320 case QwtPlot::ExternalLegend:321 d_data->legendRatio = ratio; // meaningless322 d_data->legendPos = pos;323 364 default: 324 365 break; … … 351 392 /*! 352 393 Specify the relative size of the legend in the plot 353 \param ratio Ratio between legend and the bounding rect 354 of title, canvas and axes. The legend will be shrinked394 \param ratio Ratio between legend and the bounding rectangle 395 of title, footer, canvas and axes. The legend will be shrunk 355 396 if it would need more space than the given ratio. 356 397 The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 … … 373 414 374 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 /*! 375 429 \return Geometry for the title 376 430 \sa activate(), invalidate() 377 431 */ 378 379 const QRectF &QwtPlotLayout::titleRect() const 432 QRectF QwtPlotLayout::titleRect() const 380 433 { 381 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; 382 472 } 383 473 … … 386 476 \sa activate(), invalidate() 387 477 */ 388 389 const QRectF &QwtPlotLayout::legendRect() const 478 QRectF QwtPlotLayout::legendRect() const 390 479 { 391 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; 392 498 } 393 499 … … 397 503 \sa activate(), invalidate() 398 504 */ 399 400 const QRectF &QwtPlotLayout::scaleRect( int axis ) const 505 QRectF QwtPlotLayout::scaleRect( int axis ) const 401 506 { 402 507 if ( axis < 0 || axis >= QwtPlot::axisCnt ) … … 409 514 410 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 /*! 411 529 \return Geometry for the canvas 412 530 \sa activate(), invalidate() 413 531 */ 414 415 const QRectF &QwtPlotLayout::canvasRect() const 532 QRectF QwtPlotLayout::canvasRect() const 416 533 { 417 534 return d_data->canvasRect; … … 424 541 void QwtPlotLayout::invalidate() 425 542 { 426 d_data->titleRect = d_data->legendRect = d_data->canvasRect = QRect(); 543 d_data->titleRect = d_data->footerRect 544 = d_data->legendRect = d_data->canvasRect = QRect(); 545 427 546 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 428 547 d_data->scaleRect[axis] = QRect(); … … 430 549 431 550 /*! 432 \brief Return a minimum size hint 551 \return Minimum size hint 552 \param plot Plot widget 553 433 554 \sa QwtPlot::minimumSizeHint() 434 555 */ … … 453 574 int canvasBorder[QwtPlot::axisCnt]; 454 575 576 int fw; 577 plot->canvas()->getContentsMargins( &fw, NULL, NULL, NULL ); 578 455 579 int axis; 456 580 for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) … … 467 591 sd.tickOffset = scl->margin(); 468 592 if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) 469 sd.tickOffset += scl->scaleDraw()->maxTickLength(); 470 } 471 472 canvasBorder[axis] = plot->canvas()->frameWidth() + 473 d_data->canvasMargin[axis] + 1; 474 593 sd.tickOffset += qCeil( scl->scaleDraw()->maxTickLength() ); 594 } 595 596 canvasBorder[axis] = fw + d_data->canvasMargin[axis] + 1; 475 597 } 476 598 … … 524 646 } 525 647 526 const QwtPlotCanvas *canvas = plot->canvas(); 648 const QWidget *canvas = plot->canvas(); 649 650 int left, top, right, bottom; 651 canvas->getContentsMargins( &left, &top, &right, &bottom ); 652 527 653 const QSize minCanvasSize = canvas->minimumSize(); 528 654 529 655 int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; 530 656 int cw = qMax( scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w ) 531 + 2 * ( canvas->frameWidth() + 1 );657 + left + 1 + right + 1; 532 658 w += qMax( cw, minCanvasSize.width() ); 533 659 534 660 int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h; 535 661 int ch = qMax( scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h ) 536 + 2 * ( canvas->frameWidth() + 1 );662 + top + 1 + bottom + 1; 537 663 h += qMax( ch, minCanvasSize.height() ); 538 664 539 const QwtTextLabel *title = plot->titleLabel(); 540 if ( title && !title->text().isEmpty() ) 541 { 542 // If only QwtPlot::yLeft or QwtPlot::yRight is showing, 543 // we center on the plot canvas. 544 const bool centerOnCanvas = !( plot->axisEnabled( QwtPlot::yLeft ) 545 && plot->axisEnabled( QwtPlot::yRight ) ); 546 547 int titleW = w; 548 if ( centerOnCanvas ) 549 { 550 titleW -= scaleData[QwtPlot::yLeft].w 551 + scaleData[QwtPlot::yRight].w; 552 } 553 554 int titleH = title->heightForWidth( titleW ); 555 if ( titleH > titleW ) // Compensate for a long title 556 { 557 w = titleW = titleH; 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; 558 680 if ( centerOnCanvas ) 559 681 { 560 w += scaleData[QwtPlot::yLeft].w682 labelW -= scaleData[QwtPlot::yLeft].w 561 683 + scaleData[QwtPlot::yRight].w; 562 684 } 563 685 564 titleH = title->heightForWidth( titleW ); 565 } 566 h += titleH + d_data->spacing; 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 } 567 700 } 568 701 569 702 // Compute the legend contribution 570 703 571 const QwtLegend *legend = plot->legend(); 572 if ( d_data->legendPos != QwtPlot::ExternalLegend 573 && legend && !legend->isEmpty() ) 704 const QwtAbstractLegend *legend = plot->legend(); 705 if ( legend && !legend->isEmpty() ) 574 706 { 575 707 if ( d_data->legendPos == QwtPlot::LeftLegend … … 583 715 584 716 if ( legendH > h ) 585 legendW += legend-> verticalScrollBar()->sizeHint().height();717 legendW += legend->scrollExtent( Qt::Horizontal ); 586 718 587 719 if ( d_data->legendRatio < 1.0 ) … … 610 742 /*! 611 743 Find the geometry for the legend 744 612 745 \param options Options how to layout the legend 613 746 \param rect Rectangle where to place the legend 747 614 748 \return Geometry for the legend 615 749 \sa Options … … 637 771 // space for the vertical scrollbar. 638 772 639 dim += d_data->layoutData.legend. vScrollBarWidth;773 dim += d_data->layoutData.legend.hScrollExtent; 640 774 } 641 775 } … … 644 778 { 645 779 dim = qMin( hint.height(), int( rect.height() * d_data->legendRatio ) ); 646 dim = qMax( dim, d_data->layoutData.legend. hScrollBarHeight );780 dim = qMax( dim, d_data->layoutData.legend.vScrollExtent ); 647 781 } 648 782 … … 664 798 legendRect.setHeight( dim ); 665 799 break; 666 case QwtPlot::ExternalLegend:667 break;668 800 } 669 801 … … 673 805 /*! 674 806 Align the legend to the canvas 807 675 808 \param canvasRect Geometry of the canvas 676 809 \param legendRect Maximum geometry for the legend 810 677 811 \return Geometry for the aligned legend 678 812 */ … … 708 842 709 843 \param options Options how to layout the legend 710 \param rect Bounding rect for title, axes and canvas.844 \param rect Bounding rectangle for title, footer, axes and canvas. 711 845 \param dimTitle Expanded height of the title widget 846 \param dimFooter Expanded height of the footer widget 712 847 \param dimAxis Expanded heights of the axis in axis orientation. 713 848 714 849 \sa Options 715 850 */ 716 void QwtPlotLayout::expandLineBreaks( intoptions, const QRectF &rect,717 int &dimTitle, int dimAxis[QwtPlot::axisCnt] ) const718 { 719 dimTitle = 0;851 void QwtPlotLayout::expandLineBreaks( Options options, const QRectF &rect, 852 int &dimTitle, int &dimFooter, int dimAxis[QwtPlot::axisCnt] ) const 853 { 854 dimTitle = dimFooter = 0; 720 855 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 721 856 dimAxis[axis] = 0; … … 725 860 { 726 861 backboneOffset[axis] = 0; 727 if ( !d_data->alignCanvasToScales ) 862 if ( !( options & IgnoreFrames ) ) 863 backboneOffset[axis] += d_data->layoutData.canvas.contentsMargins[ axis ]; 864 865 if ( !d_data->alignCanvasToScales[axis] ) 728 866 backboneOffset[axis] += d_data->canvasMargin[axis]; 729 if ( !( options & IgnoreFrames ) )730 backboneOffset[axis] += d_data->layoutData.canvas.frameWidth;731 867 } 732 868 … … 744 880 // axis ... . So we loop as long until no size changes. 745 881 746 if ( !d_data->layoutData.title.text.isEmpty() ) 747 { 748 int w = rect.width(); 882 if ( !( ( options & IgnoreTitle ) || 883 d_data->layoutData.title.text.isEmpty() ) ) 884 { 885 double w = rect.width(); 749 886 750 887 if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled … … 766 903 } 767 904 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 -= dimAxis[QwtPlot::yLeft] + dimAxis[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; 924 done = false; 925 } 926 } 927 768 928 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 769 929 { … … 773 933 if ( scaleData.isEnabled ) 774 934 { 775 intlength;935 double length; 776 936 if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) 777 937 { … … 804 964 length += qMin( 805 965 d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, 806 scaleData.start - backboneOffset[QwtPlot::xBottom]);966 double( scaleData.start - backboneOffset[QwtPlot::xBottom] ) ); 807 967 } 808 968 if ( dimAxis[QwtPlot::xTop] > 0 ) … … 810 970 length += qMin( 811 971 d_data->layoutData.scale[QwtPlot::xTop].tickOffset, 812 scaleData.end - backboneOffset[QwtPlot::xTop]);972 double( scaleData.end - backboneOffset[QwtPlot::xTop] ) ); 813 973 } 814 974 … … 820 980 if ( !scaleData.scaleWidget->title().isEmpty() ) 821 981 { 822 d += scaleData.scaleWidget->titleHeightForWidth( length);982 d += scaleData.scaleWidget->titleHeightForWidth( qFloor( length ) ); 823 983 } 824 984 … … 838 998 the empty corners. 839 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 840 1004 \sa Options 841 1005 */ 842 1006 843 void QwtPlotLayout::alignScales( intoptions,1007 void QwtPlotLayout::alignScales( Options options, 844 1008 QRectF &canvasRect, QRectF scaleRect[QwtPlot::axisCnt] ) const 845 1009 { … … 848 1012 { 849 1013 backboneOffset[axis] = 0; 850 if ( !d_data->alignCanvasToScales ) 1014 1015 if ( !d_data->alignCanvasToScales[axis] ) 1016 { 851 1017 backboneOffset[axis] += d_data->canvasMargin[axis]; 1018 } 1019 852 1020 if ( !( options & IgnoreFrames ) ) 853 backboneOffset[axis] += d_data->layoutData.canvas.frameWidth; 1021 { 1022 backboneOffset[axis] += 1023 d_data->layoutData.canvas.contentsMargins[axis]; 1024 } 854 1025 } 855 1026 … … 872 1043 if ( leftScaleRect.isValid() ) 873 1044 { 874 const intdx = leftOffset + leftScaleRect.width();875 if ( d_data->alignCanvasToScales && dx <0 )1045 const double dx = leftOffset + leftScaleRect.width(); 1046 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && dx < 0.0 ) 876 1047 { 877 1048 /* … … 879 1050 of the left scale. 880 1051 */ 881 c anvasRect.setLeft( qMax( canvasRect.left(),882 1052 const double cLeft = canvasRect.left(); // qreal -> double 1053 canvasRect.setLeft( qMax( cLeft, axisRect.left() - dx ) ); 883 1054 } 884 1055 else … … 891 1062 else 892 1063 { 893 if ( d_data->alignCanvasToScales && leftOffset < 0 )1064 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && leftOffset < 0 ) 894 1065 { 895 1066 canvasRect.setLeft( qMax( canvasRect.left(), … … 909 1080 if ( rightScaleRect.isValid() ) 910 1081 { 911 const intdx = rightOffset + rightScaleRect.width();912 if ( d_data->alignCanvasToScales && dx < 0 )1082 const double dx = rightOffset + rightScaleRect.width(); 1083 if ( d_data->alignCanvasToScales[QwtPlot::yRight] && dx < 0 ) 913 1084 { 914 1085 /* … … 916 1087 of the right scale. 917 1088 */ 918 c anvasRect.setRight( qMin( canvasRect.right(),919 1089 const double cRight = canvasRect.right(); // qreal -> double 1090 canvasRect.setRight( qMin( cRight, axisRect.right() + dx ) ); 920 1091 } 921 1092 … … 926 1097 else 927 1098 { 928 if ( d_data->alignCanvasToScales && rightOffset < 0 )1099 if ( d_data->alignCanvasToScales[QwtPlot::yRight] && rightOffset < 0 ) 929 1100 { 930 1101 canvasRect.setRight( qMin( canvasRect.right(), … … 946 1117 if ( bottomScaleRect.isValid() ) 947 1118 { 948 const intdy = bottomOffset + bottomScaleRect.height();949 if ( d_data->alignCanvasToScales && dy < 0 )1119 const double dy = bottomOffset + bottomScaleRect.height(); 1120 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && dy < 0 ) 950 1121 { 951 1122 /* … … 953 1124 of the bottom scale. 954 1125 */ 955 c anvasRect.setBottom( qMin( canvasRect.bottom(),956 1126 const double cBottom = canvasRect.bottom(); // qreal -> double 1127 canvasRect.setBottom( qMin( cBottom, axisRect.bottom() + dy ) ); 957 1128 } 958 1129 else … … 966 1137 else 967 1138 { 968 if ( d_data->alignCanvasToScales && bottomOffset < 0 )1139 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && bottomOffset < 0 ) 969 1140 { 970 1141 canvasRect.setBottom( qMin( canvasRect.bottom(), … … 983 1154 if ( topScaleRect.isValid() ) 984 1155 { 985 const intdy = topOffset + topScaleRect.height();986 if ( d_data->alignCanvasToScales && dy < 0 )1156 const double dy = topOffset + topScaleRect.height(); 1157 if ( d_data->alignCanvasToScales[QwtPlot::xTop] && dy < 0 ) 987 1158 { 988 1159 /* … … 990 1161 of the top scale. 991 1162 */ 992 c anvasRect.setTop( qMax( canvasRect.top(),993 1163 const double cTop = canvasRect.top(); // qreal -> double 1164 canvasRect.setTop( qMax( cTop, axisRect.top() - dy ) ); 994 1165 } 995 1166 else … … 1003 1174 else 1004 1175 { 1005 if ( d_data->alignCanvasToScales && topOffset < 0 )1176 if ( d_data->alignCanvasToScales[QwtPlot::xTop] && topOffset < 0 ) 1006 1177 { 1007 1178 canvasRect.setTop( qMax( canvasRect.top(), … … 1017 1188 } 1018 1189 1019 if ( d_data->alignCanvasToScales ) 1020 { 1021 /* 1022 The canvas has been aligned to the scale with largest 1023 border distances. Now we have to realign the other scale. 1024 */ 1025 1026 int fw = 0; 1027 if ( !( options & IgnoreFrames ) ) 1028 fw = d_data->layoutData.canvas.frameWidth; 1029 1030 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) 1031 { 1032 if ( !scaleRect[axis].isValid() ) 1033 continue; 1034 1035 if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) 1036 { 1037 scaleRect[axis].setLeft( canvasRect.left() + fw 1038 - d_data->layoutData.scale[axis].start ); 1039 scaleRect[axis].setRight( canvasRect.right() - fw - 1 1040 + d_data->layoutData.scale[axis].end ); 1041 } 1042 else 1043 { 1044 scaleRect[axis].setTop( canvasRect.top() + fw 1045 - d_data->layoutData.scale[axis].start ); 1046 scaleRect[axis].setBottom( canvasRect.bottom() - fw - 1 1047 + d_data->layoutData.scale[axis].end ); 1048 } 1049 } 1050 1051 if ( scaleRect[QwtPlot::xTop].isValid() ) 1052 scaleRect[QwtPlot::xTop].setBottom( canvasRect.top() ); 1053 if ( scaleRect[QwtPlot::xBottom].isValid() ) 1054 scaleRect[QwtPlot::xBottom].setTop( canvasRect.bottom() ); 1055 if ( scaleRect[QwtPlot::yLeft].isValid() ) 1056 scaleRect[QwtPlot::yLeft].setRight( canvasRect.left() ); 1057 if ( scaleRect[QwtPlot::yRight].isValid() ) 1058 scaleRect[QwtPlot::yRight].setLeft( canvasRect.right() ); 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 } 1229 } 1230 else 1231 { 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 } 1059 1257 } 1060 1258 } … … 1064 1262 1065 1263 \param plot Plot to be layout 1066 \param plotRect Rect where to place the components1264 \param plotRect Rectangle where to place the components 1067 1265 \param options Layout options 1068 1266 1069 \sa invalidate(), titleRect(), 1267 \sa invalidate(), titleRect(), footerRect() 1070 1268 legendRect(), scaleRect(), canvasRect() 1071 1269 */ … … 1077 1275 QRectF rect( plotRect ); // undistributed rest of the plot rect 1078 1276 1079 // We extract all layout relevant datafrom the widgets,1080 // filter them through pfilterand save them to d_data->layoutData.1277 // We extract all layout relevant parameters from the widgets, 1278 // and save them to d_data->layoutData. 1081 1279 1082 1280 d_data->layoutData.init( plot, rect ); 1083 1281 1084 1282 if ( !( options & IgnoreLegend ) 1085 && d_data->legendPos != QwtPlot::ExternalLegend1086 1283 && plot->legend() && !plot->legend()->isEmpty() ) 1087 1284 { … … 1091 1288 1092 1289 const QRegion region( rect.toRect() ); 1093 rect = region.subtract ( d_data->legendRect.toRect() ).boundingRect();1290 rect = region.subtracted( d_data->legendRect.toRect() ).boundingRect(); 1094 1291 1095 1292 switch ( d_data->legendPos ) … … 1107 1304 rect.setBottom( rect.bottom() - d_data->spacing ); 1108 1305 break; 1109 case QwtPlot::ExternalLegend:1110 break; // suppress compiler warning1111 1306 } 1112 1307 } … … 1125 1320 | | Axis | | 1126 1321 +---+-----------+---+ 1322 | Footer | 1323 +---+-----------+---+ 1127 1324 */ 1128 1325 1129 // axes and titleinclude text labels. The height of each1326 // title, footer and axes include text labels. The height of each 1130 1327 // label depends on its line breaks, that depend on the width 1131 1328 // for the label. A line break in a horizontal text will reduce 1132 1329 // the available width for vertical texts and vice versa. 1133 // expandLineBreaks finds the height/width for title and axes1330 // expandLineBreaks finds the height/width for title, footer and axes 1134 1331 // including all line breaks. 1135 1332 1136 int dimTitle, dim Axes[QwtPlot::axisCnt];1137 expandLineBreaks( options, rect, dimTitle, dim Axes );1333 int dimTitle, dimFooter, dimAxes[QwtPlot::axisCnt]; 1334 expandLineBreaks( options, rect, dimTitle, dimFooter, dimAxes ); 1138 1335 1139 1336 if ( dimTitle > 0 ) 1140 1337 { 1141 d_data->titleRect = QRect( rect.x(), rect.y(), 1142 rect.width(), dimTitle ); 1338 d_data->titleRect.setRect( 1339 rect.left(), rect.top(), rect.width(), dimTitle ); 1340 1341 rect.setTop( d_data->titleRect.bottom() + d_data->spacing ); 1143 1342 1144 1343 if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != … … 1148 1347 // the title centered to the canvas 1149 1348 1150 d_data->titleRect.setX( rect. x() + dimAxes[QwtPlot::yLeft] );1349 d_data->titleRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] ); 1151 1350 d_data->titleRect.setWidth( rect.width() 1152 1351 - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] ); 1153 1352 } 1154 1155 // subtract title 1156 rect.setTop( rect.top() + dimTitle + d_data->spacing ); 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 ) 1364 { 1365 // if only one of the y axes is missing we align 1366 // the footer centered to the canvas 1367 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 } 1157 1372 } 1158 1373 -
trunk/BNC/qwt/qwt_plot_layout.h
r4271 r8127 20 20 or by QwtPlot::print() to render its content to a QPaintDevice like 21 21 a QPrinter, QPixmap/QImage or QSvgRenderer. 22 23 \sa QwtPlot::setPlotLayout() 22 24 */ 23 25 … … 44 46 45 47 //! Ignore the legend. 46 IgnoreLegend = 0x08 48 IgnoreLegend = 0x08, 49 50 //! Ignore the title. 51 IgnoreTitle = 0x10, 52 53 //! Ignore the footer. 54 IgnoreFooter = 0x20 47 55 }; 48 56 … … 57 65 58 66 void setAlignCanvasToScales( bool ); 59 bool alignCanvasToScales() const; 67 68 void setAlignCanvasToScale( int axisId, bool ); 69 bool alignCanvasToScale( int axisId ) const; 60 70 61 71 void setSpacing( int ); … … 76 86 virtual void invalidate(); 77 87 78 const QRectF &titleRect() const; 79 const QRectF &legendRect() const; 80 const QRectF &scaleRect( int axis ) const; 81 const QRectF &canvasRect() const; 88 QRectF titleRect() const; 89 QRectF footerRect() const; 90 QRectF legendRect() const; 91 QRectF scaleRect( int axis ) const; 92 QRectF canvasRect() const; 82 93 83 94 class LayoutData; … … 85 96 protected: 86 97 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 & ); 103 87 104 QRectF layoutLegend( Options options, const QRectF & ) const; 88 105 QRectF alignLegend( const QRectF &canvasRect, 89 106 const QRectF &legendRect ) const; 90 107 91 void expandLineBreaks( intoptions, const QRectF &rect,92 int &dimTitle, int dimAxes[QwtPlot::axisCnt] ) const;108 void expandLineBreaks( Options options, const QRectF &rect, 109 int &dimTitle, int &dimFooter, int dimAxes[QwtPlot::axisCnt] ) const; 93 110 94 void alignScales( intoptions, QRectF &canvasRect,111 void alignScales( Options options, QRectF &canvasRect, 95 112 QRectF scaleRect[QwtPlot::axisCnt] ) const; 96 113 -
trunk/BNC/qwt/qwt_plot_magnifier.cpp
r4271 r8127 9 9 10 10 #include "qwt_plot.h" 11 #include "qwt_plot_canvas.h"12 11 #include "qwt_scale_div.h" 13 12 #include "qwt_plot_magnifier.h" … … 30 29 \param canvas Plot canvas to be magnified 31 30 */ 32 QwtPlotMagnifier::QwtPlotMagnifier( Q wtPlotCanvas*canvas ):31 QwtPlotMagnifier::QwtPlotMagnifier( QWidget *canvas ): 33 32 QwtMagnifier( canvas ) 34 33 { … … 76 75 77 76 //! Return observed plot canvas 78 Q wtPlotCanvas*QwtPlotMagnifier::canvas()77 QWidget *QwtPlotMagnifier::canvas() 79 78 { 80 return qobject_cast<QwtPlotCanvas *>( parent());79 return parentWidget(); 81 80 } 82 81 83 82 //! Return Observed plot canvas 84 const Q wtPlotCanvas*QwtPlotMagnifier::canvas() const83 const QWidget *QwtPlotMagnifier::canvas() const 85 84 { 86 return qobject_cast<const QwtPlotCanvas *>( parent());85 return parentWidget(); 87 86 } 88 87 … … 90 89 QwtPlot *QwtPlotMagnifier::plot() 91 90 { 92 Q wtPlotCanvas*w = canvas();91 QWidget *w = canvas(); 93 92 if ( w ) 94 return w->plot();93 w = w->parentWidget(); 95 94 96 return NULL;95 return qobject_cast<QwtPlot *>( w ); 97 96 } 98 97 … … 100 99 const QwtPlot *QwtPlotMagnifier::plot() const 101 100 { 102 const Q wtPlotCanvas*w = canvas();101 const QWidget *w = canvas(); 103 102 if ( w ) 104 return w->plot();103 w = w->parentWidget(); 105 104 106 return NULL;105 return qobject_cast<const QwtPlot *>( w ); 107 106 } 108 107 … … 113 112 void QwtPlotMagnifier::rescale( double factor ) 114 113 { 114 QwtPlot* plt = plot(); 115 if ( plt == NULL ) 116 return; 117 115 118 factor = qAbs( factor ); 116 119 if ( factor == 1.0 || factor == 0.0 ) … … 118 121 119 122 bool doReplot = false; 120 QwtPlot* plt = plot();121 123 122 124 const bool autoReplot = plt->autoReplot(); … … 125 127 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 126 128 { 127 const QwtScaleDiv *scaleDiv = plt->axisScaleDiv( axisId ); 128 if ( isAxisEnabled( axisId ) && scaleDiv->isValid() ) 129 if ( isAxisEnabled( axisId ) ) 129 130 { 130 const double center = 131 scaleDiv->lowerBound() + scaleDiv->range() / 2; 132 const double width_2 = scaleDiv->range() / 2 * factor; 131 const QwtScaleMap scaleMap = plt->canvasMap( axisId ); 133 132 134 plt->setAxisScale( axisId, center - width_2, center + width_2 ); 133 double v1 = scaleMap.s1(); 134 double v2 = scaleMap.s2(); 135 136 if ( scaleMap.transformation() ) 137 { 138 // the coordinate system of the paint device is always linear 139 140 v1 = scaleMap.transform( v1 ); // scaleMap.p1() 141 v2 = scaleMap.transform( v2 ); // scaleMap.p2() 142 } 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 ); 135 157 doReplot = true; 136 158 } -
trunk/BNC/qwt/qwt_plot_magnifier.h
r4271 r8127 14 14 #include "qwt_magnifier.h" 15 15 16 class QwtPlotCanvas;17 16 class QwtPlot; 18 17 … … 33 32 34 33 public: 35 explicit QwtPlotMagnifier( Q wtPlotCanvas* );34 explicit QwtPlotMagnifier( QWidget * ); 36 35 virtual ~QwtPlotMagnifier(); 37 36 … … 39 38 bool isAxisEnabled( int axis ) const; 40 39 41 Q wtPlotCanvas*canvas();42 const Q wtPlotCanvas*canvas() const;40 QWidget *canvas(); 41 const QWidget *canvas() const; 43 42 44 43 QwtPlot *plot(); -
trunk/BNC/qwt/qwt_plot_marker.cpp
r4271 r8127 14 14 #include "qwt_text.h" 15 15 #include "qwt_math.h" 16 #include "qwt_legend.h"17 #include "qwt_legend_item.h"18 16 #include <qpainter.h> 19 17 … … 51 49 52 50 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 53 QwtPlotMarker::QwtPlotMarker(): 54 QwtPlotItem( QwtText( "Marker" ) ) 51 QwtPlotMarker::QwtPlotMarker( const QString &title ): 52 QwtPlotItem( QwtText( title ) ) 53 { 54 d_data = new PrivateData; 55 setZ( 30.0 ); 56 } 57 58 //! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine 59 QwtPlotMarker::QwtPlotMarker( const QwtText &title ): 60 QwtPlotItem( title ) 55 61 { 56 62 d_data = new PrivateData; … … 123 129 \param xMap x Scale Map 124 130 \param yMap y Scale Map 125 \param canvasRect Contents rect of the canvas in painter coordinates131 \param canvasRect Contents rectangle of the canvas in painter coordinates 126 132 */ 127 133 void QwtPlotMarker::draw( QPainter *painter, … … 140 146 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) 141 147 { 142 d_data->symbol->drawSymbol( painter, pos ); 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 ); 143 155 } 144 156 … … 150 162 151 163 \param painter Painter 152 \param canvasRect Contents rect of the canvas in painter coordinates164 \param canvasRect Contents rectangle of the canvas in painter coordinates 153 165 \param pos Position of the marker, translated into widget coordinates 154 166 … … 190 202 191 203 \param painter Painter 192 \param canvasRect Contents rect of the canvas in painter coordinates204 \param canvasRect Contents rectangle of the canvas in painter coordinates 193 205 \param pos Position of the marker, translated into widget coordinates 194 206 … … 334 346 { 335 347 d_data->style = style; 348 349 legendChanged(); 336 350 itemChanged(); 337 351 } … … 358 372 delete d_data->symbol; 359 373 d_data->symbol = symbol; 374 375 if ( symbol ) 376 setLegendIconSize( symbol->boundingRect().size() ); 377 378 legendChanged(); 360 379 itemChanged(); 361 380 } … … 373 392 /*! 374 393 \brief Set the label 375 \param label label text394 \param label Label text 376 395 \sa label() 377 396 */ … … 484 503 } 485 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 ) 519 { 520 setLinePen( QPen( color, width, style ) ); 521 } 522 486 523 /*! 487 524 Specify a pen for the line. … … 495 532 { 496 533 d_data->pen = pen; 534 535 legendChanged(); 497 536 itemChanged(); 498 537 } … … 514 553 515 554 /*! 516 \brief Update the widget that represents the item on the legend 517 518 \param legend Legend 519 \sa drawLegendIdentifier(), legendItem(), itemChanged(), QwtLegend() 520 521 \note In the default setting QwtPlotItem::Legend is disabled 522 */ 523 void QwtPlotMarker::updateLegend( QwtLegend *legend ) const 524 { 525 if ( legend && testItemAttribute( QwtPlotItem::Legend ) 526 && d_data->symbol && d_data->symbol->style() != QwtSymbol::NoSymbol ) 527 { 528 QWidget *lgdItem = legend->find( this ); 529 if ( lgdItem == NULL ) 530 { 531 lgdItem = legendItem(); 532 if ( lgdItem ) 533 legend->insert( this, lgdItem ); 534 } 535 536 QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem ); 537 if ( l ) 538 l->setIdentifierSize( d_data->symbol->boundingSize() ); 539 } 540 541 QwtPlotItem::updateLegend( legend ); 542 } 543 544 /*! 545 \brief Draw the identifier representing the marker on the legend 546 547 \param painter Painter 548 \param rect Bounding rectangle for the identifier 549 550 \sa updateLegend(), QwtPlotItem::Legend 551 */ 552 void QwtPlotMarker::drawLegendIdentifier( 553 QPainter *painter, const QRectF &rect ) const 554 { 555 if ( rect.isEmpty() ) 556 return; 557 558 painter->save(); 559 painter->setClipRect( rect, Qt::IntersectClip ); 555 \return Icon representing the marker on the legend 556 557 \param index Index of the legend entry 558 ( usually there is only one ) 559 \param size Icon size 560 561 \sa setLegendIconSize(), legendData() 562 */ 563 QwtGraphic QwtPlotMarker::legendIcon( int index, 564 const QSizeF &size ) const 565 { 566 Q_UNUSED( index ); 567 568 if ( size.isEmpty() ) 569 return QwtGraphic(); 570 571 QwtGraphic icon; 572 icon.setDefaultSize( size ); 573 icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 574 575 QPainter painter( &icon ); 576 painter.setRenderHint( QPainter::Antialiasing, 577 testRenderHint( QwtPlotItem::RenderAntialiased ) ); 560 578 561 579 if ( d_data->style != QwtPlotMarker::NoLine ) 562 580 { 563 painter ->setPen( d_data->pen );581 painter.setPen( d_data->pen ); 564 582 565 583 if ( d_data->style == QwtPlotMarker::HLine || 566 584 d_data->style == QwtPlotMarker::Cross ) 567 585 { 568 QwtPainter::drawLine( painter, rect.left(), rect.center().y(), 569 rect.right(), rect.center().y() ); 586 const double y = 0.5 * size.height(); 587 588 QwtPainter::drawLine( &painter, 589 0.0, y, size.width(), y ); 570 590 } 571 591 … … 573 593 d_data->style == QwtPlotMarker::Cross ) 574 594 { 575 QwtPainter::drawLine( painter, rect.center().x(), rect.top(), 576 rect.center().x(), rect.bottom() ); 595 const double x = 0.5 * size.width(); 596 597 QwtPainter::drawLine( &painter, 598 x, 0.0, x, size.height() ); 577 599 } 578 600 } 579 601 580 if ( d_data->symbol && d_data->symbol->style() != QwtSymbol::NoSymbol ) 581 { 582 QSize symbolSize = d_data->symbol->boundingSize(); 583 symbolSize -= QSize( 2, 2 ); 584 585 // scale the symbol size down if it doesn't fit into rect. 586 587 double xRatio = 1.0; 588 if ( rect.width() < symbolSize.width() ) 589 xRatio = rect.width() / symbolSize.width(); 590 double yRatio = 1.0; 591 if ( rect.height() < symbolSize.height() ) 592 yRatio = rect.height() / symbolSize.height(); 593 594 const double ratio = qMin( xRatio, yRatio ); 595 596 painter->scale( ratio, ratio ); 597 d_data->symbol->drawSymbol( painter, rect.center() / ratio ); 598 } 599 600 painter->restore(); 601 } 602 602 if ( d_data->symbol ) 603 { 604 const QRect r( 0.0, 0.0, size.width(), size.height() ); 605 d_data->symbol->drawSymbol( &painter, r ); 606 } 607 608 return icon; 609 } 610 -
trunk/BNC/qwt/qwt_plot_marker.h
r4271 r8127 29 29 be drawn around a center point inside a bounding rectangle. 30 30 31 The QwtPlotMarker::setSymbol() member assigns a symbol to the marker.31 The setSymbol() member assigns a symbol to the marker. 32 32 The symbol is drawn at the specified point. 33 33 … … 40 40 left above the center point if the alignment was set to 41 41 Qt::AlignLeft | Qt::AlignTop. 42 43 \note QwtPlotTextLabel is intended to align a text label 44 according to the geometry of canvas 45 ( unrelated to plot coordinates ) 42 46 */ 43 47 … … 65 69 }; 66 70 67 explicit QwtPlotMarker(); 71 explicit QwtPlotMarker( const QString &title = QString::null ); 72 explicit QwtPlotMarker( const QwtText &title ); 73 68 74 virtual ~QwtPlotMarker(); 69 75 … … 82 88 LineStyle lineStyle() const; 83 89 90 void setLinePen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 84 91 void setLinePen( const QPen &p ); 85 92 const QPen &linePen() const; … … 106 113 virtual QRectF boundingRect() const; 107 114 108 virtual void updateLegend( QwtLegend * ) const; 109 virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const; 115 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 110 116 111 117 protected: -
trunk/BNC/qwt/qwt_plot_panner.cpp
r4271 r8127 11 11 #include "qwt_scale_div.h" 12 12 #include "qwt_plot.h" 13 #include "qwt_plot_canvas.h" 13 #include "qwt_painter.h" 14 #include <qbitmap.h> 15 #include <qstyle.h> 16 #include <qstyleoption.h> 17 18 static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size ) 19 { 20 const QRect r( 0, 0, size.width(), size.height() ); 21 22 QPainterPath borderPath; 23 24 ( void )QMetaObject::invokeMethod( 25 const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection, 26 Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) ); 27 28 if ( borderPath.isEmpty() ) 29 { 30 if ( canvas->contentsRect() == canvas->rect() ) 31 return QBitmap(); 32 33 QBitmap mask( size ); 34 mask.fill( Qt::color0 ); 35 36 QPainter painter( &mask ); 37 painter.fillRect( canvas->contentsRect(), Qt::color1 ); 38 39 return mask; 40 } 41 42 QImage image( size, QImage::Format_ARGB32_Premultiplied ); 43 image.fill( Qt::color0 ); 44 45 QPainter painter( &image ); 46 painter.setClipPath( borderPath ); 47 painter.fillRect( r, Qt::color1 ); 48 49 // now erase the frame 50 51 painter.setCompositionMode( QPainter::CompositionMode_DestinationOut ); 52 53 if ( canvas->testAttribute(Qt::WA_StyledBackground ) ) 54 { 55 QStyleOptionFrame opt; 56 opt.initFrom(canvas); 57 opt.rect = r; 58 canvas->style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, canvas ); 59 } 60 else 61 { 62 const QVariant borderRadius = canvas->property( "borderRadius" ); 63 const QVariant frameWidth = canvas->property( "frameWidth" ); 64 65 if ( borderRadius.type() == QVariant::Double 66 && frameWidth.type() == QVariant::Int ) 67 { 68 const double br = borderRadius.toDouble(); 69 const int fw = frameWidth.toInt(); 70 71 if ( br > 0.0 && fw > 0 ) 72 { 73 painter.setPen( QPen( Qt::color1, fw ) ); 74 painter.setBrush( Qt::NoBrush ); 75 painter.setRenderHint( QPainter::Antialiasing, true ); 76 77 painter.drawPath( borderPath ); 78 } 79 } 80 } 81 82 painter.end(); 83 84 const QImage mask = image.createMaskFromColor( 85 QColor( Qt::color1 ).rgb(), Qt::MaskOutColor ); 86 87 return QBitmap::fromImage( mask ); 88 } 14 89 15 90 class QwtPlotPanner::PrivateData … … 26 101 27 102 /*! 28 \brief Create a plot panner103 \brief A panner for the canvas of a QwtPlot 29 104 30 105 The panner is enabled for all axes … … 34 109 \sa setAxisEnabled() 35 110 */ 36 QwtPlotPanner::QwtPlotPanner( Q wtPlotCanvas*canvas ):111 QwtPlotPanner::QwtPlotPanner( QWidget *canvas ): 37 112 QwtPanner( canvas ) 38 113 { … … 83 158 84 159 //! Return observed plot canvas 85 Q wtPlotCanvas*QwtPlotPanner::canvas()86 { 87 return qobject_cast<QwtPlotCanvas *>( parentWidget());160 QWidget *QwtPlotPanner::canvas() 161 { 162 return parentWidget(); 88 163 } 89 164 90 165 //! Return Observed plot canvas 91 const Q wtPlotCanvas*QwtPlotPanner::canvas() const92 { 93 return qobject_cast<const QwtPlotCanvas *>( parentWidget());166 const QWidget *QwtPlotPanner::canvas() const 167 { 168 return parentWidget(); 94 169 } 95 170 … … 97 172 QwtPlot *QwtPlotPanner::plot() 98 173 { 99 Q wtPlotCanvas*w = canvas();174 QWidget *w = canvas(); 100 175 if ( w ) 101 return w->plot();102 103 return NULL;176 w = w->parentWidget(); 177 178 return qobject_cast<QwtPlot *>( w ); 104 179 } 105 180 … … 107 182 const QwtPlot *QwtPlotPanner::plot() const 108 183 { 109 const Q wtPlotCanvas*w = canvas();184 const QWidget *w = canvas(); 110 185 if ( w ) 111 return w->plot();112 113 return NULL;186 w = w->parentWidget(); 187 188 return qobject_cast<const QwtPlot *>( w ); 114 189 } 115 190 … … 141 216 const QwtScaleMap map = plot->canvasMap( axis ); 142 217 143 const double p1 = map.transform( plot->axisScaleDiv( axis ) ->lowerBound() );144 const double p2 = map.transform( plot->axisScaleDiv( axis ) ->upperBound() );218 const double p1 = map.transform( plot->axisScaleDiv( axis ).lowerBound() ); 219 const double p2 = map.transform( plot->axisScaleDiv( axis ).upperBound() ); 145 220 146 221 double d1, d2; … … 164 239 165 240 /*! 166 Calculate a mask from the border mask of the canvas 167 \sa QwtPlotCanvas::borderMask() 241 Calculate a mask from the border path of the canvas 242 243 \return Mask as bitmap 244 \sa QwtPlotCanvas::borderPath() 168 245 */ 169 246 QBitmap QwtPlotPanner::contentsMask() const 170 247 { 171 248 if ( canvas() ) 172 return canvas()->borderMask(size() );249 return qwtBorderMask( canvas(), size() ); 173 250 174 251 return QwtPanner::contentsMask(); 175 252 } 253 254 /*! 255 \return Pixmap with the content of the canvas 256 */ 257 QPixmap QwtPlotPanner::grab() const 258 { 259 const QWidget *cv = canvas(); 260 if ( cv && cv->inherits( "QGLWidget" ) ) 261 { 262 // we can't grab from a QGLWidget 263 264 QPixmap pm( cv->size() ); 265 QwtPainter::fillPixmap( cv, pm ); 266 267 QPainter painter( &pm ); 268 const_cast<QwtPlot *>( plot() )->drawCanvas( &painter ); 269 270 return pm; 271 } 272 273 return QwtPanner::grab(); 274 } 275 -
trunk/BNC/qwt/qwt_plot_panner.h
r4271 r8127 14 14 #include "qwt_panner.h" 15 15 16 class QwtPlotCanvas;17 16 class QwtPlot; 18 17 … … 20 19 \brief QwtPlotPanner provides panning of a plot canvas 21 20 22 QwtPlotPanner is a panner for a QwtPlotCanvas, that21 QwtPlotPanner is a panner for a plot canvas, that 23 22 adjusts the scales of the axes after dropping 24 23 the canvas on its new position. … … 35 34 36 35 public: 37 explicit QwtPlotPanner( Q wtPlotCanvas* );36 explicit QwtPlotPanner( QWidget * ); 38 37 virtual ~QwtPlotPanner(); 39 38 40 Q wtPlotCanvas*canvas();41 const Q wtPlotCanvas*canvas() const;39 QWidget *canvas(); 40 const QWidget *canvas() const; 42 41 43 42 QwtPlot *plot(); … … 52 51 protected: 53 52 virtual QBitmap contentsMask() const; 53 virtual QPixmap grab() const; 54 54 55 55 private: -
trunk/BNC/qwt/qwt_plot_picker.cpp
r4271 r8127 28 28 */ 29 29 30 QwtPlotPicker::QwtPlotPicker( Q wtPlotCanvas*canvas ):30 QwtPlotPicker::QwtPlotPicker( QWidget *canvas ): 31 31 QwtPicker( canvas ), 32 32 d_xAxis( -1 ), … … 66 66 \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect() 67 67 */ 68 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, Q wtPlotCanvas*canvas ):68 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, QWidget *canvas ): 69 69 QwtPicker( canvas ), 70 70 d_xAxis( xAxis ), … … 78 78 \param xAxis X axis of the picker 79 79 \param yAxis Y axis of the picker 80 \param rubberBand Rubber band style80 \param rubberBand Rubber band style 81 81 \param trackerMode Tracker mode 82 82 \param canvas Plot canvas to observe, also the parent object … … 89 89 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, 90 90 RubberBand rubberBand, DisplayMode trackerMode, 91 Q wtPlotCanvas*canvas ):91 QWidget *canvas ): 92 92 QwtPicker( rubberBand, trackerMode, canvas ), 93 93 d_xAxis( xAxis ), … … 101 101 } 102 102 103 //! Return observed plot canvas104 Q wtPlotCanvas*QwtPlotPicker::canvas()105 { 106 return qobject_cast<QwtPlotCanvas *>( parentWidget());107 } 108 109 //! Return Observed plot canvas110 const Q wtPlotCanvas*QwtPlotPicker::canvas() const111 { 112 return qobject_cast<const QwtPlotCanvas *>( parentWidget());113 } 114 115 //! Return plot widget, containing the observed plot canvas103 //! \return Observed plot canvas 104 QWidget *QwtPlotPicker::canvas() 105 { 106 return parentWidget(); 107 } 108 109 //! \return Observed plot canvas 110 const QWidget *QwtPlotPicker::canvas() const 111 { 112 return parentWidget(); 113 } 114 115 //! \return Plot widget, containing the observed plot canvas 116 116 QwtPlot *QwtPlotPicker::plot() 117 117 { 118 Q wtPlotCanvas*w = canvas();118 QWidget *w = canvas(); 119 119 if ( w ) 120 return w->plot();121 122 return NULL;123 } 124 125 //! Return plot widget, containing the observed plot canvas120 w = w->parentWidget(); 121 122 return qobject_cast<QwtPlot *>( w ); 123 } 124 125 //! \return Plot widget, containing the observed plot canvas 126 126 const QwtPlot *QwtPlotPicker::plot() const 127 127 { 128 const Q wtPlotCanvas*w = canvas();128 const QWidget *w = canvas(); 129 129 if ( w ) 130 return w->plot(); 131 132 return NULL; 133 } 134 135 /*! 136 Return normalized bounding rect of the axes 137 130 w = w->parentWidget(); 131 132 return qobject_cast<const QwtPlot *>( w ); 133 } 134 135 /*! 136 \return Normalized bounding rectangle of the axes 138 137 \sa QwtPlot::autoReplot(), QwtPlot::replot(). 139 138 */ … … 144 143 if ( plot() ) 145 144 { 146 const QwtScaleDiv *xs = plot()->axisScaleDiv( xAxis() ); 147 const QwtScaleDiv *ys = plot()->axisScaleDiv( yAxis() ); 148 149 if ( xs && ys ) 150 { 151 rect = QRectF( xs->lowerBound(), ys->lowerBound(), 152 xs->range(), ys->range() ); 153 rect = rect.normalized(); 154 } 145 const QwtScaleDiv &xs = plot()->axisScaleDiv( xAxis() ); 146 const QwtScaleDiv &ys = plot()->axisScaleDiv( yAxis() ); 147 148 rect = QRectF( xs.lowerBound(), ys.lowerBound(), 149 xs.range(), ys.range() ); 150 rect = rect.normalized(); 155 151 } 156 152 … … 231 227 232 228 /*! 233 Append a point to the selection and update rubber band and tracker.229 Append a point to the selection and update rubber band and tracker. 234 230 235 231 \param pos Additional point … … 265 261 \param ok If true, complete the selection and emit selected signals 266 262 otherwise discard the selection. 267 \return true if the selection isaccepted, false otherwise263 \return True if the selection has been accepted, false otherwise 268 264 */ 269 265 … … 278 274 return false; 279 275 280 const QPolygon p a= selection();281 if ( p a.count() == 0 )276 const QPolygon points = selection(); 277 if ( points.count() == 0 ) 282 278 return false; 283 279 … … 292 288 case QwtPickerMachine::PointSelection: 293 289 { 294 const QPointF pos = invTransform( p a[0]);290 const QPointF pos = invTransform( points.first() ); 295 291 Q_EMIT selected( pos ); 296 292 break; … … 298 294 case QwtPickerMachine::RectSelection: 299 295 { 300 if ( p a.count() >= 2 )296 if ( points.count() >= 2 ) 301 297 { 302 const QPoint p1 = p a[0];303 const QPoint p2 = p a[int( pa.count() - 1 )];298 const QPoint p1 = points.first(); 299 const QPoint p2 = points.last(); 304 300 305 301 const QRect rect = QRect( p1, p2 ).normalized(); … … 310 306 case QwtPickerMachine::PolygonSelection: 311 307 { 312 QVector<QPointF> dpa( p a.count() );313 for ( int i = 0; i < int( pa.count()); i++ )314 dpa[i] = invTransform( p a[i] );308 QVector<QPointF> dpa( points.count() ); 309 for ( int i = 0; i < points.count(); i++ ) 310 dpa[i] = invTransform( points[i] ); 315 311 316 312 Q_EMIT selected( dpa ); -
trunk/BNC/qwt/qwt_plot_picker.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_plot_canvas.h"15 14 #include "qwt_picker.h" 16 15 #include <qvector.h> … … 23 22 QwtPlotPicker is a QwtPicker tailored for selections on 24 23 a plot canvas. It is set to a x-Axis and y-Axis and 25 translates all pixel coordinates into this coo dinate system.24 translates all pixel coordinates into this coordinate system. 26 25 */ 27 26 … … 31 30 32 31 public: 33 explicit QwtPlotPicker( Q wtPlotCanvas *);32 explicit QwtPlotPicker( QWidget *canvas ); 34 33 virtual ~QwtPlotPicker(); 35 34 36 explicit QwtPlotPicker( int xAxis, int yAxis, Q wtPlotCanvas* );35 explicit QwtPlotPicker( int xAxis, int yAxis, QWidget * ); 37 36 38 37 explicit QwtPlotPicker( int xAxis, int yAxis, 39 RubberBand rubberBand, DisplayMode trackerMode, 40 QwtPlotCanvas * ); 38 RubberBand rubberBand, DisplayMode trackerMode, QWidget * ); 41 39 42 40 virtual void setAxis( int xAxis, int yAxis ); … … 48 46 const QwtPlot *plot() const; 49 47 50 Q wtPlotCanvas*canvas();51 const Q wtPlotCanvas*canvas() const;48 QWidget *canvas(); 49 const QWidget *canvas() const; 52 50 53 51 Q_SIGNALS: 54 52 55 53 /*! 56 A signal emitted in case of selectionFlags() &PointSelection.54 A signal emitted in case of QwtPickerMachine::PointSelection. 57 55 \param pos Selected point 58 56 */ … … 60 58 61 59 /*! 62 A signal emitted in case of selectionFlags() &RectSelection.60 A signal emitted in case of QwtPickerMachine::RectSelection. 63 61 \param rect Selected rectangle 64 62 */ -
trunk/BNC/qwt/qwt_plot_rasteritem.cpp
r4271 r8127 9 9 10 10 #include "qwt_plot_rasteritem.h" 11 #include "qwt_legend.h"12 #include "qwt_legend_item.h"13 11 #include "qwt_scale_map.h" 14 12 #include "qwt_painter.h" … … 17 15 #include <qpainter.h> 18 16 #include <qpaintengine.h> 17 #include <qmath.h> 18 #if QT_VERSION >= 0x040400 19 #include <qthread.h> 20 #include <qfuture.h> 21 #include <qtconcurrentrun.h> 22 #endif 19 23 #include <float.h> 20 24 … … 30 34 31 35 int alpha; 36 32 37 QwtPlotRasterItem::PaintAttributes paintAttributes; 33 38 … … 186 191 } 187 192 188 const quint32 *line1 = (const quint32 *) image.scanLine( y1 ); 193 const quint32 *line1 = 194 reinterpret_cast<const quint32 *>( image.scanLine( y1 ) ); 189 195 190 196 for ( int x1 = 0; x1 < w; x1++ ) … … 217 223 for ( int y2 = yy1; y2 < yy2; y2++ ) 218 224 { 219 quint32 *line2 = ( quint32 *) expanded.scanLine( y2 ); 225 quint32 *line2 = reinterpret_cast<quint32 *>( 226 expanded.scanLine( y2 ) ); 227 220 228 for ( int x2 = xx1; x2 < xx2; x2++ ) 221 229 line2[x2] = rgb; … … 297 305 } 298 306 299 static QRectF expandToPixels(const QRectF &rect, const QRectF &pixelRect)307 static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF &pixelRect) 300 308 { 301 309 const double pw = pixelRect.width(); … … 316 324 } 317 325 318 static void transformMaps( const QTransform &tr,326 static void qwtTransformMaps( const QTransform &tr, 319 327 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 320 328 QwtScaleMap &xxMap, QwtScaleMap &yyMap ) … … 330 338 } 331 339 332 static void adjustMaps( QwtScaleMap &xMap, QwtScaleMap &yMap,340 static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap &yMap, 333 341 const QRectF &area, const QRectF &paintRect) 334 342 { … … 351 359 } 352 360 353 static bool useCache( QwtPlotRasterItem::CachePolicy policy,361 static bool qwtUseCache( QwtPlotRasterItem::CachePolicy policy, 354 362 const QPainter *painter ) 355 363 { … … 377 385 } 378 386 379 static QImage toRgba( const QImage& image, int alpha ) 380 { 381 if ( alpha < 0 || alpha >= 255 ) 382 return image; 383 384 QImage alphaImage( image.size(), QImage::Format_ARGB32 ); 385 387 static void qwtToRgba( const QImage* from, QImage* to, 388 const QRect& tile, int alpha ) 389 { 386 390 const QRgb mask1 = qRgba( 0, 0, 0, alpha ); 387 391 const QRgb mask2 = qRgba( 255, 255, 255, 0 ); 388 392 const QRgb mask3 = qRgba( 0, 0, 0, 255 ); 389 393 390 const int w = image.size().width(); 391 const int h = image.size().height(); 392 393 if ( image.depth() == 8 ) 394 { 395 for ( int y = 0; y < h; y++ ) 396 { 397 QRgb* alphaLine = ( QRgb* )alphaImage.scanLine( y ); 398 const unsigned char *line = image.scanLine( y ); 399 400 for ( int x = 0; x < w; x++ ) 401 *alphaLine++ = ( image.color( *line++ ) & mask2 ) | mask1; 402 } 403 } 404 else if ( image.depth() == 32 ) 405 { 406 for ( int y = 0; y < h; y++ ) 407 { 408 QRgb* alphaLine = ( QRgb* )alphaImage.scanLine( y ); 409 const QRgb* line = ( const QRgb* ) image.scanLine( y ); 410 411 for ( int x = 0; x < w; x++ ) 394 const int y0 = tile.top(); 395 const int y1 = tile.bottom(); 396 const int x0 = tile.left(); 397 const int x1 = tile.right(); 398 399 if ( from->depth() == 8 ) 400 { 401 for ( int y = y0; y <= y1; y++ ) 402 { 403 QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) ); 404 const unsigned char *line = from->scanLine( y ); 405 406 for ( int x = x0; x <= x1; x++ ) 407 *alphaLine++ = ( from->color( *line++ ) & mask2 ) | mask1; 408 } 409 } 410 else if ( from->depth() == 32 ) 411 { 412 for ( int y = y0; y <= y1; y++ ) 413 { 414 QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) ); 415 const QRgb *line = reinterpret_cast<const QRgb *>( from->scanLine( y ) ); 416 417 for ( int x = x0; x <= x1; x++ ) 412 418 { 413 419 const QRgb rgb = *line++; … … 419 425 } 420 426 } 421 422 return alphaImage;423 427 } 424 428 … … 469 473 470 474 /*! 471 \ brief Return the current paint attributes475 \return True, when attribute is enabled 472 476 \sa PaintAttribute, setPaintAttribute() 473 477 */ … … 572 576 573 577 Width and height of the hint need to be the horizontal 574 and vertical distances between 2 neighbo ured points.578 and vertical distances between 2 neighbored points. 575 579 The center of the hint has to be the position of any point 576 580 ( it doesn't matter which one ). … … 602 606 \param xMap X-Scale Map 603 607 \param yMap Y-Scale Map 604 \param canvasRect Contents rect of the plot canvas608 \param canvasRect Contents rectangle of the plot canvas 605 609 */ 606 610 void QwtPlotRasterItem::draw( QPainter *painter, … … 611 615 return; 612 616 613 const bool doCache = useCache( d_data->cache.policy, painter );617 const bool doCache = qwtUseCache( d_data->cache.policy, painter ); 614 618 615 619 const QwtInterval xInterval = interval( Qt::XAxis ); … … 617 621 618 622 /* 619 Scaling a rasteredimage always results in a loss of623 Scaling an image always results in a loss of 620 624 precision/quality. So we always render the image in 621 625 paint device resolution. … … 623 627 624 628 QwtScaleMap xxMap, yyMap; 625 transformMaps( painter->transform(), xMap, yMap, xxMap, yyMap );629 qwtTransformMaps( painter->transform(), xMap, yMap, xxMap, yyMap ); 626 630 627 631 QRectF paintRect = painter->transform().mapRect( canvasRect ); … … 644 648 if ( !pixelRect.isEmpty() ) 645 649 { 646 const QRectF r = QwtScaleMap::invTransform(647 xxMap, yyMap, QRectF(0, 0, 1, 1) ).normalized();648 649 if ( r.width() > pixelRect.width() && 650 r.height()> pixelRect.height() )650 // one pixel of the target device in plot coordinates 651 const double dx = qAbs( xxMap.invTransform( 1 ) - xxMap.invTransform( 0 ) ); 652 const double dy = qAbs( yyMap.invTransform( 1 ) - yyMap.invTransform( 0 ) ); 653 654 if ( dx > pixelRect.width() && dy > pixelRect.height() ) 651 655 { 652 656 /* … … 657 661 pixelRect = QRectF(); 658 662 } 663 else 664 { 665 /* 666 If only one dimension is of the data pixel is higher 667 we expand the pixel rect to the resolution of the target device. 668 */ 669 670 if ( dx > pixelRect.width() ) 671 pixelRect.setWidth( dx ); 672 673 if ( dy > pixelRect.height() ) 674 pixelRect.setHeight( dy ); 675 } 659 676 } 660 677 … … 667 684 668 685 paintRect = qwtAlignRect(paintRect); 669 adjustMaps(xxMap, yyMap, area, paintRect);686 qwtAdjustMaps(xxMap, yyMap, area, paintRect); 670 687 } 671 688 … … 701 718 702 719 // align the area to the data pixels 703 QRectF imageArea = expandToPixels(area, pixelRect);720 QRectF imageArea = qwtExpandToPixels(area, pixelRect); 704 721 705 722 if ( imageArea.right() == xInterval.maxValue() && … … 717 734 imageSize.setWidth( qRound( imageArea.width() / pixelRect.width() ) ); 718 735 imageSize.setHeight( qRound( imageArea.height() / pixelRect.height() ) ); 736 719 737 image = compose(xxMap, yyMap, 720 738 imageArea, paintRect, imageSize, doCache ); 739 721 740 if ( image.isNull() ) 722 741 return; … … 760 779 761 780 /*! 762 \return Bounding rect of the data781 \return Bounding rectangle of the data 763 782 \sa QwtPlotRasterItem::interval() 764 783 */ … … 844 863 845 864 if ( d_data->alpha >= 0 && d_data->alpha < 255 ) 846 image = toRgba( image, d_data->alpha ); 865 { 866 QImage alphaImage( image.size(), QImage::Format_ARGB32 ); 867 868 #if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE) 869 uint numThreads = renderThreadCount(); 870 871 if ( numThreads <= 0 ) 872 numThreads = QThread::idealThreadCount(); 873 874 if ( numThreads <= 0 ) 875 numThreads = 1; 876 877 const int numRows = image.height() / numThreads; 878 879 QList< QFuture<void> > futures; 880 for ( uint i = 0; i < numThreads; i++ ) 881 { 882 QRect tile( 0, i * numRows, image.width(), numRows ); 883 if ( i == numThreads - 1 ) 884 { 885 tile.setHeight( image.height() - i * numRows ); 886 qwtToRgba( &image, &alphaImage, tile, d_data->alpha ); 887 } 888 else 889 { 890 futures += QtConcurrent::run( 891 &qwtToRgba, &image, &alphaImage, tile, d_data->alpha ); 892 } 893 } 894 for ( int i = 0; i < futures.size(); i++ ) 895 futures[i].waitForFinished(); 896 #else 897 const QRect tile( 0, 0, image.width(), image.height() ); 898 qwtToRgba( &image, &alphaImage, tile, d_data->alpha ); 899 #endif 900 image = alphaImage; 901 } 847 902 848 903 return image; … … 857 912 \param imageSize Image size 858 913 \param pixelSize Width/Height of a data pixel 914 915 \return Calculated scale map 859 916 */ 860 917 QwtScaleMap QwtPlotRasterItem::imageMap( -
trunk/BNC/qwt/qwt_plot_rasteritem.h
r4271 r8127 39 39 public: 40 40 /*! 41 - NoCache\n 42 renderImage() is called, whenever the item has to be repainted 43 - PaintCache\n 44 renderImage() is called, whenever the image cache is not valid, 45 or the scales, or the size of the canvas has changed. This type 46 of cache is only useful for improving the performance of hide/show 47 operations. All other situations are already handled by the 48 plot canvas cache. 49 41 \brief Cache policy 50 42 The default policy is NoCache 51 43 */ 52 44 enum CachePolicy 53 45 { 46 /*! 47 renderImage() is called each time the item has to be repainted 48 */ 54 49 NoCache, 50 51 /*! 52 renderImage() is called, whenever the image cache is not valid, 53 or the scales, or the size of the canvas has changed. 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. 58 */ 55 59 PaintCache 56 60 }; … … 118 122 \param area Requested area for the image in scale coordinates 119 123 \param imageSize Requested size of the image 124 125 \return Rendered image 120 126 */ 121 127 virtual QImage renderImage( const QwtScaleMap &xMap, -
trunk/BNC/qwt/qwt_plot_renderer.cpp
r4271 r8127 11 11 #include "qwt_plot.h" 12 12 #include "qwt_painter.h" 13 #include "qwt_plot_canvas.h"14 13 #include "qwt_plot_layout.h" 15 #include "qwt_legend.h" 16 #include "qwt_legend_item.h" 17 #include "qwt_dyngrid_layout.h" 14 #include "qwt_abstract_legend.h" 18 15 #include "qwt_scale_widget.h" 19 16 #include "qwt_scale_engine.h" … … 25 22 #include <qtransform.h> 26 23 #include <qprinter.h> 24 #include <qprintdialog.h> 25 #include <qfiledialog.h> 26 #include <qfileinfo.h> 27 27 #include <qstyle.h> 28 28 #include <qstyleoption.h> 29 29 #include <qimagewriter.h> 30 #include <qfileinfo.h>31 30 #ifndef QWT_NO_SVG 32 31 #ifdef QT_SVG_LIB … … 35 34 #endif 36 35 36 static QPainterPath qwtCanvasClip( 37 const QWidget* canvas, const QRectF &canvasRect ) 38 { 39 // The clip region is calculated in integers 40 // To avoid too much rounding errors better 41 // calculate it in target device resolution 42 43 int x1 = qCeil( canvasRect.left() ); 44 int x2 = qFloor( canvasRect.right() ); 45 int y1 = qCeil( canvasRect.top() ); 46 int y2 = qFloor( canvasRect.bottom() ); 47 48 const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 ); 49 50 QPainterPath clipPath; 51 52 ( void ) QMetaObject::invokeMethod( 53 const_cast< QWidget *>( canvas ), "borderPath", 54 Qt::DirectConnection, 55 Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) ); 56 57 return clipPath; 58 } 59 37 60 class QwtPlotRenderer::PrivateData 38 61 { 39 62 public: 40 63 PrivateData(): 41 discardFlags( QwtPlotRenderer::Discard Background),64 discardFlags( QwtPlotRenderer::DiscardNone ), 42 65 layoutFlags( QwtPlotRenderer::DefaultLayout ) 43 66 { … … 47 70 QwtPlotRenderer::LayoutFlags layoutFlags; 48 71 }; 49 50 static void qwtRenderBackground( QPainter *painter,51 const QRectF &rect, const QWidget *widget )52 {53 if ( widget->testAttribute( Qt::WA_StyledBackground ) )54 {55 QStyleOption opt;56 opt.initFrom( widget );57 opt.rect = rect.toAlignedRect();58 59 widget->style()->drawPrimitive(60 QStyle::PE_Widget, &opt, painter, widget);61 }62 else63 {64 const QBrush brush =65 widget->palette().brush( widget->backgroundRole() );66 67 painter->fillRect( rect, brush );68 }69 }70 72 71 73 /*! … … 102 104 103 105 /*! 104 Check if a flag is set. 105 106 \return True, if flag is enabled. 106 107 \param flag Flag to be tested 107 108 \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags() … … 149 150 150 151 /*! 151 Check if a flag is set. 152 152 \return True, if flag is enabled. 153 153 \param flag Flag to be tested 154 154 \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags() … … 182 182 Render a plot to a file 183 183 184 The format of the document will be auto detected from the185 suffix of the file name.184 The format of the document will be auto-detected from the 185 suffix of the file name. 186 186 187 187 \param plot Plot widget … … 239 239 240 240 const QString fmt = format.toLower(); 241 if ( fmt == "pdf" || fmt == "ps")241 if ( fmt == "pdf" ) 242 242 { 243 243 #ifndef QT_NO_PRINTER 244 244 QPrinter printer; 245 printer.setOutputFormat( QPrinter::PdfFormat ); 246 printer.setColorMode( QPrinter::Color ); 245 247 printer.setFullPage( true ); 246 248 printer.setPaperSize( sizeMM, QPrinter::Millimeter ); 247 249 printer.setDocName( title ); 248 250 printer.setOutputFileName( fileName ); 249 printer.setOutputFormat( ( format == "pdf" )250 ? QPrinter::PdfFormat : QPrinter::PostScriptFormat );251 251 printer.setResolution( resolution ); 252 252 253 253 QPainter painter( &printer ); 254 254 render( plot, &painter, documentRect ); 255 #endif 256 } 257 else if ( fmt == "ps" ) 258 { 259 #if QT_VERSION < 0x050000 260 #ifndef QT_NO_PRINTER 261 QPrinter printer; 262 printer.setOutputFormat( QPrinter::PostScriptFormat ); 263 printer.setColorMode( QPrinter::Color ); 264 printer.setFullPage( true ); 265 printer.setPaperSize( sizeMM, QPrinter::Millimeter ); 266 printer.setDocName( title ); 267 printer.setOutputFileName( fileName ); 268 printer.setResolution( resolution ); 269 270 QPainter painter( &printer ); 271 render( plot, &painter, documentRect ); 272 #endif 255 273 #endif 256 274 } … … 393 411 QPainter *painter, const QRectF &plotRect ) const 394 412 { 395 int axisId;396 397 413 if ( painter == 0 || !painter->isActive() || 398 414 !plotRect.isValid() || plot->size().isNull() ) 415 { 399 416 return; 417 } 400 418 401 419 if ( !( d_data->discardFlags & DiscardBackground ) ) 402 qwtRenderBackground( painter, plotRect, plot );420 QwtPainter::drawBackgound( painter, plotRect, plot ); 403 421 404 422 /* … … 412 430 double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() ); 413 431 414 painter->save(); 432 QRectF layoutRect = transform.inverted().mapRect( plotRect ); 433 434 if ( !( d_data->discardFlags & DiscardBackground ) ) 435 { 436 // subtract the contents margins 437 438 int left, top, right, bottom; 439 plot->getContentsMargins( &left, &top, &right, &bottom ); 440 layoutRect.adjust( left, top, -right, -bottom ); 441 } 442 443 QwtPlotLayout *layout = plot->plotLayout(); 415 444 416 445 int baseLineDists[QwtPlot::axisCnt]; 417 if ( d_data->layoutFlags & FrameWithScales ) 418 { 419 for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 446 int canvasMargins[QwtPlot::axisCnt]; 447 448 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 449 { 450 canvasMargins[ axisId ] = layout->canvasMargin( axisId ); 451 452 if ( d_data->layoutFlags & FrameWithScales ) 420 453 { 421 454 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); … … 425 458 scaleWidget->setMargin( 0 ); 426 459 } 427 } 428 } 429 // Calculate the layout for the print. 430 431 QwtPlotLayout::Options layoutOptions = 432 QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames; 460 461 if ( !plot->axisEnabled( axisId ) ) 462 { 463 int left = 0; 464 int right = 0; 465 int top = 0; 466 int bottom = 0; 467 468 // When we have a scale the frame is painted on 469 // the position of the backbone - otherwise we 470 // need to introduce a margin around the canvas 471 472 switch( axisId ) 473 { 474 case QwtPlot::yLeft: 475 layoutRect.adjust( 1, 0, 0, 0 ); 476 break; 477 case QwtPlot::yRight: 478 layoutRect.adjust( 0, 0, -1, 0 ); 479 break; 480 case QwtPlot::xTop: 481 layoutRect.adjust( 0, 1, 0, 0 ); 482 break; 483 case QwtPlot::xBottom: 484 layoutRect.adjust( 0, 0, 0, -1 ); 485 break; 486 default: 487 break; 488 } 489 layoutRect.adjust( left, top, right, bottom ); 490 } 491 } 492 } 493 494 // Calculate the layout for the document. 495 496 QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars; 497 498 if ( ( d_data->layoutFlags & FrameWithScales ) || 499 ( d_data->discardFlags & DiscardCanvasFrame ) ) 500 { 501 layoutOptions |= QwtPlotLayout::IgnoreFrames; 502 } 503 504 433 505 if ( d_data->discardFlags & DiscardLegend ) 434 506 layoutOptions |= QwtPlotLayout::IgnoreLegend; 435 507 436 const QRectF layoutRect = transform.inverted().mapRect( plotRect ); 437 plot->plotLayout()->activate( plot, layoutRect, layoutOptions ); 438 508 if ( d_data->discardFlags & DiscardTitle ) 509 layoutOptions |= QwtPlotLayout::IgnoreTitle; 510 511 if ( d_data->discardFlags & DiscardFooter ) 512 layoutOptions |= QwtPlotLayout::IgnoreFooter; 513 514 layout->activate( plot, layoutRect, layoutOptions ); 515 516 // canvas 517 518 QwtScaleMap maps[QwtPlot::axisCnt]; 519 buildCanvasMaps( plot, layout->canvasRect(), maps ); 520 if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) ) 521 { 522 // recalculate maps and layout, when the margins 523 // have been changed 524 525 layout->activate( plot, layoutRect, layoutOptions ); 526 buildCanvasMaps( plot, layout->canvasRect(), maps ); 527 } 528 529 // now start painting 530 531 painter->save(); 439 532 painter->setWorldTransform( transform, true ); 440 533 441 // canvas 442 443 QwtScaleMap maps[QwtPlot::axisCnt]; 444 buildCanvasMaps( plot, plot->plotLayout()->canvasRect(), maps ); 445 renderCanvas( plot, painter, plot->plotLayout()->canvasRect(), maps ); 534 renderCanvas( plot, painter, layout->canvasRect(), maps ); 446 535 447 536 if ( !( d_data->discardFlags & DiscardTitle ) 448 537 && ( !plot->titleLabel()->text().isEmpty() ) ) 449 538 { 450 renderTitle( plot, painter, plot->plotLayout()->titleRect() ); 539 renderTitle( plot, painter, layout->titleRect() ); 540 } 541 542 if ( !( d_data->discardFlags & DiscardFooter ) 543 && ( !plot->footerLabel()->text().isEmpty() ) ) 544 { 545 renderFooter( plot, painter, layout->footerRect() ); 451 546 } 452 547 … … 454 549 && plot->legend() && !plot->legend()->isEmpty() ) 455 550 { 456 renderLegend( plot, painter, plot->plotLayout()->legendRect() );457 } 458 459 for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )551 renderLegend( plot, painter, layout->legendRect() ); 552 } 553 554 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 460 555 { 461 556 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); … … 468 563 469 564 renderScale( plot, painter, axisId, startDist, endDist, 470 baseDist, plot->plotLayout()->scaleRect( axisId ) ); 471 } 472 } 473 474 475 plot->plotLayout()->invalidate(); 476 477 // reset all widgets with their original attributes. 478 if ( d_data->layoutFlags & FrameWithScales ) 479 { 480 // restore the previous base line dists 481 482 for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 565 baseDist, layout->scaleRect( axisId ) ); 566 } 567 } 568 569 painter->restore(); 570 571 // restore all setting to their original attributes. 572 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 573 { 574 if ( d_data->layoutFlags & FrameWithScales ) 483 575 { 484 576 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); … … 486 578 scaleWidget->setMargin( baseLineDists[axisId] ); 487 579 } 488 } 489 490 painter->restore(); 580 581 layout->setCanvasMargin( canvasMargins[axisId] ); 582 } 583 584 layout->invalidate(); 585 491 586 } 492 587 … … 511 606 512 607 /*! 513 Render the legendinto a given rectangle.608 Render the footer into a given rectangle. 514 609 515 610 \param plot Plot widget … … 517 612 \param rect Bounding rectangle 518 613 */ 614 void QwtPlotRenderer::renderFooter( const QwtPlot *plot, 615 QPainter *painter, const QRectF &rect ) const 616 { 617 painter->setFont( plot->footerLabel()->font() ); 618 619 const QColor color = plot->footerLabel()->palette().color( 620 QPalette::Active, QPalette::Text ); 621 622 painter->setPen( color ); 623 plot->footerLabel()->text().draw( painter, rect ); 624 } 625 626 627 /*! 628 Render the legend into a given rectangle. 629 630 \param plot Plot widget 631 \param painter Painter 632 \param rect Bounding rectangle 633 */ 519 634 void QwtPlotRenderer::renderLegend( const QwtPlot *plot, 520 635 QPainter *painter, const QRectF &rect ) const 521 636 { 522 if ( !plot->legend() || plot->legend()->isEmpty() ) 523 return; 524 525 if ( !( d_data->discardFlags & DiscardBackground ) ) 526 { 527 if ( plot->legend()->autoFillBackground() || 528 plot->legend()->testAttribute( Qt::WA_StyledBackground ) ) 529 { 530 qwtRenderBackground( painter, rect, plot->legend() ); 531 } 532 } 533 534 const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( 535 plot->legend()->contentsWidget()->layout() ); 536 if ( legendLayout == NULL ) 537 return; 538 539 uint numCols = legendLayout->columnsForWidth( rect.width() ); 540 QList<QRect> itemRects = 541 legendLayout->layoutItems( rect.toRect(), numCols ); 542 543 int index = 0; 544 545 for ( int i = 0; i < legendLayout->count(); i++ ) 546 { 547 QLayoutItem *item = legendLayout->itemAt( i ); 548 QWidget *w = item->widget(); 549 if ( w ) 550 { 551 painter->save(); 552 553 painter->setClipRect( itemRects[index] ); 554 renderLegendItem( plot, painter, w, itemRects[index] ); 555 556 index++; 557 painter->restore(); 558 } 559 } 560 } 561 562 /*! 563 Render the legend item into a given rectangle. 564 565 \param plot Plot widget 566 \param painter Painter 567 \param widget Widget representing a legend item 568 \param rect Bounding rectangle 569 570 \note When widget is not derived from QwtLegendItem renderLegendItem 571 does nothing and needs to be overloaded 572 */ 573 void QwtPlotRenderer::renderLegendItem( const QwtPlot *plot, 574 QPainter *painter, const QWidget *widget, const QRectF &rect ) const 575 { 576 if ( !( d_data->discardFlags & DiscardBackground ) ) 577 { 578 if ( widget->autoFillBackground() || 579 widget->testAttribute( Qt::WA_StyledBackground ) ) 580 { 581 qwtRenderBackground( painter, rect, widget ); 582 } 583 } 584 585 const QwtLegendItem *item = qobject_cast<const QwtLegendItem *>( widget ); 586 if ( item ) 587 { 588 const QSize sz = item->identifierSize(); 589 590 const QRectF identifierRect( rect.x() + item->margin(), 591 rect.center().y() - 0.5 * sz.height(), sz.width(), sz.height() ); 592 593 QwtLegendItemManager *itemManger = plot->legend()->find( item ); 594 if ( itemManger ) 595 { 596 painter->save(); 597 painter->setClipRect( identifierRect, Qt::IntersectClip ); 598 itemManger->drawLegendIdentifier( painter, identifierRect ); 599 painter->restore(); 600 } 601 602 // Label 603 604 QRectF titleRect = rect; 605 titleRect.setX( identifierRect.right() + 2 * item->spacing() ); 606 607 painter->setFont( item->font() ); 608 item->text().draw( painter, titleRect ); 637 if ( plot->legend() ) 638 { 639 bool fillBackground = !( d_data->discardFlags & DiscardBackground ); 640 plot->legend()->renderLegend( painter, rect, fillBackground ); 609 641 } 610 642 } … … 635 667 { 636 668 scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) ); 637 638 const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing(); 639 if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal ) 640 baseDist += off; 641 else 642 baseDist += off; 669 baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing(); 643 670 } 644 671 … … 720 747 const QwtScaleMap *map ) const 721 748 { 722 painter->save(); 723 724 QPainterPath clipPath; 749 const QWidget *canvas = plot->canvas(); 725 750 726 751 QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 ); … … 728 753 if ( d_data->layoutFlags & FrameWithScales ) 729 754 { 755 painter->save(); 756 730 757 r.adjust( -1.0, -1.0, 1.0, 1.0 ); 731 758 painter->setPen( QPen( Qt::black ) ); … … 734 761 { 735 762 const QBrush bgBrush = 736 plot->canvas()->palette().brush( plot->backgroundRole() );763 canvas->palette().brush( plot->backgroundRole() ); 737 764 painter->setBrush( bgBrush ); 738 765 } 739 766 740 767 QwtPainter::drawRect( painter, r ); 768 769 painter->restore(); 770 painter->save(); 771 772 painter->setClipRect( canvasRect ); 773 plot->drawItems( painter, canvasRect, map ); 774 775 painter->restore(); 776 } 777 else if ( canvas->testAttribute( Qt::WA_StyledBackground ) ) 778 { 779 QPainterPath clipPath; 780 781 painter->save(); 782 783 if ( !( d_data->discardFlags & DiscardCanvasBackground ) ) 784 { 785 QwtPainter::drawBackgound( painter, r, canvas ); 786 clipPath = qwtCanvasClip( canvas, canvasRect ); 787 } 788 789 painter->restore(); 790 painter->save(); 791 792 if ( clipPath.isEmpty() ) 793 painter->setClipRect( canvasRect ); 794 else 795 painter->setClipPath( clipPath ); 796 797 plot->drawItems( painter, canvasRect, map ); 798 799 painter->restore(); 741 800 } 742 801 else 743 802 { 803 QPainterPath clipPath; 804 805 int frameWidth = 0; 806 807 if ( !( d_data->discardFlags & DiscardCanvasFrame ) ) 808 { 809 const QVariant fw = canvas->property( "frameWidth" ); 810 if ( fw.type() == QVariant::Int ) 811 frameWidth = fw.toInt(); 812 813 clipPath = qwtCanvasClip( canvas, canvasRect ); 814 } 815 816 QRectF innerRect = canvasRect.adjusted( 817 frameWidth, frameWidth, -frameWidth, -frameWidth ); 818 819 painter->save(); 820 821 if ( clipPath.isEmpty() ) 822 { 823 painter->setClipRect( innerRect ); 824 } 825 else 826 { 827 painter->setClipPath( clipPath ); 828 } 829 744 830 if ( !( d_data->discardFlags & DiscardCanvasBackground ) ) 745 831 { 746 qwtRenderBackground( painter, r, plot->canvas() ); 747 748 if ( plot->canvas()->testAttribute( Qt::WA_StyledBackground ) ) 832 QwtPainter::drawBackgound( painter, innerRect, canvas ); 833 } 834 835 plot->drawItems( painter, innerRect, map ); 836 837 painter->restore(); 838 839 if ( frameWidth > 0 ) 840 { 841 painter->save(); 842 843 const int frameStyle = 844 canvas->property( "frameShadow" ).toInt() | 845 canvas->property( "frameShape" ).toInt(); 846 847 const int frameWidth = canvas->property( "frameWidth" ).toInt(); 848 849 850 const QVariant borderRadius = canvas->property( "borderRadius" ); 851 if ( borderRadius.type() == QVariant::Double 852 && borderRadius.toDouble() > 0.0 ) 749 853 { 750 // The clip region is calculated in integers 751 // To avoid too much rounding errors better 752 // calculate it in target device resolution 753 // TODO ... 754 755 int x1 = qCeil( canvasRect.left() ); 756 int x2 = qFloor( canvasRect.right() ); 757 int y1 = qCeil( canvasRect.top() ); 758 int y2 = qFloor( canvasRect.bottom() ); 759 760 clipPath = plot->canvas()->borderPath( 761 QRect( x1, y1, x2 - x1 - 1, y2 - y1 - 1 ) ); 854 const double r = borderRadius.toDouble(); 855 856 QwtPainter::drawRoundedFrame( painter, canvasRect, 857 r, r, canvas->palette(), frameWidth, frameStyle ); 762 858 } 763 } 764 } 765 766 painter->restore(); 767 768 painter->save(); 769 770 if ( clipPath.isEmpty() ) 771 painter->setClipRect( canvasRect ); 772 else 773 painter->setClipPath( clipPath ); 774 775 plot->drawItems( painter, canvasRect, map ); 776 777 painter->restore(); 859 else 860 { 861 const int midLineWidth = canvas->property( "midLineWidth" ).toInt(); 862 863 QwtPainter::drawFrame( painter, canvasRect, 864 canvas->palette(), canvas->foregroundRole(), 865 frameWidth, midLineWidth, frameStyle ); 866 } 867 painter->restore(); 868 } 869 } 778 870 } 779 871 … … 793 885 plot->axisScaleEngine( axisId )->transformation() ); 794 886 795 const QwtScaleDiv &scaleDiv = *plot->axisScaleDiv( axisId );887 const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId ); 796 888 maps[axisId].setScaleInterval( 797 889 scaleDiv.lowerBound(), scaleDiv.upperBound() ); … … 802 894 const int sDist = plot->axisWidget( axisId )->startBorderDist(); 803 895 const int eDist = plot->axisWidget( axisId )->endBorderDist(); 804 const QRectF &scaleRect = plot->plotLayout()->scaleRect( axisId );896 const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId ); 805 897 806 898 if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom ) … … 817 909 else 818 910 { 819 int margin = plot->plotLayout()->canvasMargin( axisId ); 911 int margin = 0; 912 if ( !plot->plotLayout()->alignCanvasToScale( axisId ) ) 913 margin = plot->plotLayout()->canvasMargin( axisId ); 914 820 915 if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight ) 821 916 { … … 832 927 } 833 928 } 929 930 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot *plot, 931 const QRectF &canvasRect, const QwtScaleMap maps[] ) const 932 { 933 double margins[QwtPlot::axisCnt]; 934 plot->getCanvasMarginsHint( maps, canvasRect, 935 margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 936 margins[QwtPlot::yRight], margins[QwtPlot::xBottom] ); 937 938 bool marginsChanged = false; 939 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 940 { 941 if ( margins[axisId] >= 0.0 ) 942 { 943 const int m = qCeil( margins[axisId] ); 944 plot->plotLayout()->setCanvasMargin( m, axisId); 945 marginsChanged = true; 946 } 947 } 948 949 return marginsChanged; 950 } 951 952 /*! 953 \brief Execute a file dialog and render the plot to the selected file 954 955 \param plot Plot widget 956 \param documentName Default document name 957 \param sizeMM Size for the document in millimeters. 958 \param resolution Resolution in dots per Inch (dpi) 959 960 \return True, when exporting was successful 961 \sa renderDocument() 962 */ 963 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName, 964 const QSizeF &sizeMM, int resolution ) 965 { 966 if ( plot == NULL ) 967 return false; 968 969 QString fileName = documentName; 970 971 // What about translation 972 973 #ifndef QT_NO_FILEDIALOG 974 const QList<QByteArray> imageFormats = 975 QImageWriter::supportedImageFormats(); 976 977 QStringList filter; 978 #ifndef QT_NO_PRINTER 979 filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)"; 980 #endif 981 #ifndef QWT_NO_SVG 982 filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)"; 983 #endif 984 #ifndef QT_NO_PRINTER 985 filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)"; 986 #endif 987 988 if ( imageFormats.size() > 0 ) 989 { 990 QString imageFilter( tr( "Images" ) ); 991 imageFilter += " ("; 992 for ( int i = 0; i < imageFormats.size(); i++ ) 993 { 994 if ( i > 0 ) 995 imageFilter += " "; 996 imageFilter += "*."; 997 imageFilter += imageFormats[i]; 998 } 999 imageFilter += ")"; 1000 1001 filter += imageFilter; 1002 } 1003 1004 fileName = QFileDialog::getSaveFileName( 1005 NULL, tr( "Export File Name" ), fileName, 1006 filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite ); 1007 #endif 1008 if ( fileName.isEmpty() ) 1009 return false; 1010 1011 renderDocument( plot, fileName, sizeMM, resolution ); 1012 1013 return true; 1014 } -
trunk/BNC/qwt/qwt_plot_renderer.h
r4271 r8127 13 13 #include "qwt_global.h" 14 14 #include <qobject.h> 15 #include <qsize.h> 15 16 16 17 class QwtPlot; 17 18 class QwtScaleMap; 18 class QSizeF;19 19 class QRectF; 20 20 class QPainter; … … 56 56 57 57 //! Don't render the background of the canvas 58 DiscardCanvasBackground = 0x08 58 DiscardCanvasBackground = 0x08, 59 60 //! Don't render the footer of the plot 61 DiscardFooter = 0x10, 62 63 /*! 64 Don't render the frame of the canvas 65 66 \note This flag has no effect when using 67 style sheets, where the frame is part 68 of the background 69 */ 70 DiscardCanvasFrame = 0x20 71 59 72 }; 60 73 … … 68 81 enum LayoutFlag 69 82 { 70 //! Use the default layout without margins and frames83 //! Use the default layout as on screen 71 84 DefaultLayout = 0x00, 72 73 //! Render all frames of the plot74 KeepFrames = 0x01,75 85 76 86 /*! … … 78 88 where the scale ticks are aligned to. 79 89 */ 80 FrameWithScales = 0x0 290 FrameWithScales = 0x01 81 91 }; 82 92 … … 99 109 LayoutFlags layoutFlags() const; 100 110 101 void renderDocument( QwtPlot *, const QString &f ormat,111 void renderDocument( QwtPlot *, const QString &fileName, 102 112 const QSizeF &sizeMM, int resolution = 85 ); 103 113 104 114 void renderDocument( QwtPlot *, 105 const QString & title, const QString &format,115 const QString &fileName, const QString &format, 106 116 const QSizeF &sizeMM, int resolution = 85 ); 107 117 … … 123 133 QPainter *, const QRectF &rect ) const; 124 134 125 virtual void render LegendItem( const QwtPlot *,126 QPainter *, const Q Widget *, const QRectF & ) const;135 virtual void renderTitle( const QwtPlot *, 136 QPainter *, const QRectF & ) const; 127 137 128 virtual void render Title( const QwtPlot *,138 virtual void renderFooter( const QwtPlot *, 129 139 QPainter *, const QRectF & ) const; 130 140 … … 140 150 const QwtPlot *, QPainter *, const QRectF & ) const; 141 151 142 protected: 152 bool exportTo( QwtPlot *, const QString &documentName, 153 const QSizeF &sizeMM = QSizeF( 300, 200 ), int resolution = 85 ); 154 155 private: 143 156 void buildCanvasMaps( const QwtPlot *, 144 157 const QRectF &, QwtScaleMap maps[] ) const; 158 159 bool updateCanvasMargins( QwtPlot *, 160 const QRectF &, const QwtScaleMap maps[] ) const; 145 161 146 162 private: -
trunk/BNC/qwt/qwt_plot_rescaler.cpp
r4271 r8127 10 10 #include "qwt_plot_rescaler.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_plot_canvas.h"13 12 #include "qwt_scale_div.h" 14 13 #include "qwt_interval.h" 14 #include "qwt_plot_canvas.h" 15 15 #include <qevent.h> 16 16 #include <qalgorithms.h> … … 59 59 \sa setRescalePolicy(), setReferenceAxis() 60 60 */ 61 QwtPlotRescaler::QwtPlotRescaler( Q wtPlotCanvas*canvas,61 QwtPlotRescaler::QwtPlotRescaler( QWidget *canvas, 62 62 int referenceAxis, RescalePolicy policy ): 63 63 QObject( canvas ) … … 179 179 180 180 /*! 181 Return direction in which an axis should be expanded181 \return Direction in which an axis should be expanded 182 182 183 183 \param axis Axis index ( see QwtPlot::AxisId ) … … 224 224 225 225 /*! 226 Return aspect ratio between an axis and the reference axis.226 \return Aspect ratio between an axis and the reference axis. 227 227 228 228 \param axis Axis index ( see QwtPlot::AxisId ) … … 241 241 242 242 In Fitting mode, the hint is used as minimal interval 243 t aht always needs to be displayed.243 that always needs to be displayed. 244 244 245 245 \param axis Axis, see QwtPlot::Axis … … 268 268 269 269 //! \return plot canvas 270 Q wtPlotCanvas*QwtPlotRescaler::canvas()271 { 272 return qobject_cast<Q wtPlotCanvas*>( parent() );270 QWidget *QwtPlotRescaler::canvas() 271 { 272 return qobject_cast<QWidget *>( parent() ); 273 273 } 274 274 275 275 //! \return plot canvas 276 const Q wtPlotCanvas*QwtPlotRescaler::canvas() const277 { 278 return qobject_cast<const Q wtPlotCanvas*>( parent() );276 const QWidget *QwtPlotRescaler::canvas() const 277 { 278 return qobject_cast<const QWidget *>( parent() ); 279 279 } 280 280 … … 282 282 QwtPlot *QwtPlotRescaler::plot() 283 283 { 284 Q wtPlotCanvas*w = canvas();284 QWidget *w = canvas(); 285 285 if ( w ) 286 return w->plot();287 288 return NULL;286 w = w->parentWidget(); 287 288 return qobject_cast<QwtPlot *>( w ); 289 289 } 290 290 … … 292 292 const QwtPlot *QwtPlotRescaler::plot() const 293 293 { 294 const Q wtPlotCanvas*w = canvas();294 const QWidget *w = canvas(); 295 295 if ( w ) 296 return w->plot();297 298 return NULL;296 w = w->parentWidget(); 297 298 return qobject_cast<const QwtPlot *>( w ); 299 299 } 300 300 301 301 //! Event filter for the plot canvas 302 bool QwtPlotRescaler::eventFilter( QObject *o , QEvent *e)303 { 304 if ( o && o== canvas() )305 { 306 switch ( e ->type() )302 bool QwtPlotRescaler::eventFilter( QObject *object, QEvent *event ) 303 { 304 if ( object && object == canvas() ) 305 { 306 switch ( event->type() ) 307 307 { 308 308 case QEvent::Resize: 309 canvasResizeEvent( ( QResizeEvent * )e ); 309 { 310 canvasResizeEvent( static_cast<QResizeEvent *>( event ) ); 310 311 break; 312 } 311 313 case QEvent::PolishRequest: 314 { 312 315 rescale(); 313 316 break; 317 } 314 318 default:; 315 319 } … … 327 331 void QwtPlotRescaler::canvasResizeEvent( QResizeEvent* event ) 328 332 { 329 const int fw = 2 * canvas()->frameWidth(); 330 const QSize newSize = event->size() - QSize( fw, fw ); 331 const QSize oldSize = event->oldSize() - QSize( fw, fw ); 333 int left, top, right, bottom; 334 canvas()->getContentsMargins( &left, &top, &right, &bottom ); 335 336 const QSize marginSize( left + right, top + bottom ); 337 338 const QSize newSize = event->size() - marginSize; 339 const QSize oldSize = event->oldSize() - marginSize; 332 340 333 341 rescale( oldSize, newSize ); … … 433 441 434 442 /*! 435 443 Synchronize an axis scale according to the scale of the reference axis 436 444 437 445 \param axis Axis index ( see QwtPlot::AxisId ) 438 446 \param reference Interval of the reference axis 439 447 \param size Size of the canvas 448 449 \return New interval for axis 440 450 */ 441 451 QwtInterval QwtPlotRescaler::syncScale( int axis, … … 467 477 468 478 /*! 469 Return orientation of an axis479 \return Orientation of an axis 470 480 \param axis Axis index ( see QwtPlot::AxisId ) 471 481 */ … … 479 489 480 490 /*! 481 Return interval of an axis482 \ param axis Axis index ( see QwtPlot::AxisId )491 \param axis Axis index ( see QwtPlot::AxisId ) 492 \return Normalized interval of an axis 483 493 */ 484 494 QwtInterval QwtPlotRescaler::interval( int axis ) const … … 487 497 return QwtInterval(); 488 498 489 const QwtPlot *plt = plot(); 490 491 const double v1 = plt->axisScaleDiv( axis )->lowerBound(); 492 const double v2 = plt->axisScaleDiv( axis )->upperBound(); 493 494 return QwtInterval( v1, v2 ).normalized(); 499 return plot()->axisScaleDiv( axis ).interval().normalized(); 495 500 } 496 501 … … 584 589 double v2 = intervals[axis].maxValue(); 585 590 586 if ( plt->axisScaleDiv( axis )->lowerBound() > 587 plt->axisScaleDiv( axis )->upperBound() ) 588 { 591 if ( !plt->axisScaleDiv( axis ).isIncreasing() ) 589 592 qSwap( v1, v2 ); 590 }591 593 592 594 if ( d_data->inReplot >= 1 ) 593 { 594 d_data->axisData[axis].scaleDiv = *plt->axisScaleDiv( axis ); 595 } 595 d_data->axisData[axis].scaleDiv = plt->axisScaleDiv( axis ); 596 596 597 597 if ( d_data->inReplot >= 2 ) … … 610 610 } 611 611 612 const bool immediatePaint = 613 plt->canvas()->testPaintAttribute( QwtPlotCanvas::ImmediatePaint ); 614 plt->canvas()->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false ); 612 QwtPlotCanvas *canvas = qobject_cast<QwtPlotCanvas *>( plt->canvas() ); 613 614 bool immediatePaint = false; 615 if ( canvas ) 616 { 617 immediatePaint = canvas->testPaintAttribute( QwtPlotCanvas::ImmediatePaint ); 618 canvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, false ); 619 } 615 620 616 621 plt->setAutoReplot( doReplot ); … … 620 625 d_data->inReplot--; 621 626 622 plt->canvas()->setPaintAttribute( 623 QwtPlotCanvas::ImmediatePaint, immediatePaint ); 624 } 627 if ( canvas && immediatePaint ) 628 { 629 canvas->setPaintAttribute( QwtPlotCanvas::ImmediatePaint, true ); 630 } 631 } -
trunk/BNC/qwt/qwt_plot_rescaler.h
r4271 r8127 16 16 #include <qobject.h> 17 17 18 class QwtPlotCanvas;19 18 class QwtPlot; 20 19 class QResizeEvent; … … 23 22 \brief QwtPlotRescaler takes care of fixed aspect ratios for plot scales 24 23 25 QwtPlotRescaler auto adjusts the axes of a QwtPlot according24 QwtPlotRescaler auto adjusts the axes of a QwtPlot according 26 25 to fixed aspect ratios. 27 26 */ … … 46 45 47 46 /*! 48 The interval of the reference axis will be shr inked/expanded,47 The interval of the reference axis will be shrunk/expanded, 49 48 when the geometry of the canvas changes. All other axes 50 49 will be adjusted according to their aspect ratio. … … 78 77 }; 79 78 80 explicit QwtPlotRescaler( Q wtPlotCanvas *,79 explicit QwtPlotRescaler( QWidget *canvas, 81 80 int referenceAxis = QwtPlot::xBottom, 82 81 RescalePolicy = Expanding ); … … 104 103 QwtInterval intervalHint( int axis ) const; 105 104 106 Q wtPlotCanvas*canvas();107 const Q wtPlotCanvas*canvas() const;105 QWidget *canvas(); 106 const QWidget *canvas() const; 108 107 109 108 QwtPlot *plot(); -
trunk/BNC/qwt/qwt_plot_scaleitem.cpp
r4271 r8127 10 10 #include "qwt_plot_scaleitem.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_plot_canvas.h"13 12 #include "qwt_scale_map.h" 14 13 #include "qwt_interval.h" … … 32 31 } 33 32 34 void updateBorders( const QRectF &,35 const QwtScaleMap &, const QwtScaleMap & ) ;33 QwtInterval scaleInterval( const QRectF &, 34 const QwtScaleMap &, const QwtScaleMap & ) const; 36 35 37 36 QPalette palette; … … 41 40 bool scaleDivFromAxis; 42 41 QwtScaleDraw *scaleDraw; 43 QRectF canvasRectCache;44 42 }; 45 43 46 void QwtPlotScaleItem::PrivateData::updateBorders( const QRectF &canvasRect, 47 const QwtScaleMap &xMap, const QwtScaleMap &yMap ) 48 { 49 canvasRectCache = canvasRect; 50 44 QwtInterval QwtPlotScaleItem::PrivateData::scaleInterval( const QRectF &canvasRect, 45 const QwtScaleMap &xMap, const QwtScaleMap &yMap ) const 46 { 51 47 QwtInterval interval; 52 48 if ( scaleDraw->orientation() == Qt::Horizontal ) … … 61 57 } 62 58 63 QwtScaleDiv scaleDiv = scaleDraw->scaleDiv(); 64 scaleDiv.setInterval( interval ); 65 scaleDraw->setScaleDiv( scaleDiv ); 66 } 59 return interval; 60 } 61 67 62 /*! 68 63 \brief Constructor for scale item at the position pos. … … 84 79 d_data->scaleDraw->setAlignment( alignment ); 85 80 81 setItemInterest( QwtPlotItem::ScaleInterest, true ); 86 82 setZ( 11.0 ); 87 83 } … … 137 133 if ( plt ) 138 134 { 139 updateScaleDiv( *plt->axisScaleDiv( xAxis() ),140 *plt->axisScaleDiv( yAxis() ) );135 updateScaleDiv( plt->axisScaleDiv( xAxis() ), 136 plt->axisScaleDiv( yAxis() ) ); 141 137 itemChanged(); 142 138 } … … 164 160 { 165 161 d_data->palette = palette; 162 163 legendChanged(); 166 164 itemChanged(); 167 165 } … … 223 221 if ( plt ) 224 222 { 225 updateScaleDiv( *plt->axisScaleDiv( xAxis() ),226 *plt->axisScaleDiv( yAxis() ) );223 updateScaleDiv( plt->axisScaleDiv( xAxis() ), 224 plt->axisScaleDiv( yAxis() ) ); 227 225 } 228 226 … … 282 280 283 281 If distance is >= 0 the scale will be aligned to a 284 border of the contents rect of the canvas. If282 border of the contents rectangle of the canvas. If 285 283 alignment() is QwtScaleDraw::LeftScale, the scale will 286 284 be aligned to the right border, if it is QwtScaleDraw::TopScale … … 348 346 const QRectF &canvasRect ) const 349 347 { 348 QwtScaleDraw *sd = d_data->scaleDraw; 349 350 350 if ( d_data->scaleDivFromAxis ) 351 351 { 352 if ( canvasRect != d_data->canvasRectCache ) 353 d_data->updateBorders( canvasRect, xMap, yMap ); 352 const QwtInterval interval = 353 d_data->scaleInterval( canvasRect, xMap, yMap ); 354 355 if ( interval != sd->scaleDiv().interval() ) 356 { 357 QwtScaleDiv scaleDiv = sd->scaleDiv(); 358 scaleDiv.setInterval( interval ); 359 sd->setScaleDiv( scaleDiv ); 360 } 354 361 } 355 362 … … 358 365 painter->setPen( pen ); 359 366 360 QwtScaleDraw *sd = d_data->scaleDraw;361 367 if ( sd->orientation() == Qt::Horizontal ) 362 368 { … … 382 388 sd->move( canvasRect.left(), y ); 383 389 sd->setLength( canvasRect.width() - 1 ); 384 sd->setTransformation( xMap.transformation()->copy() ); 390 391 QwtTransform *transform = NULL; 392 if ( xMap.transformation() ) 393 transform = xMap.transformation()->copy(); 394 395 sd->setTransformation( transform ); 385 396 } 386 397 else // == Qt::Vertical … … 405 416 sd->move( x, canvasRect.top() ); 406 417 sd->setLength( canvasRect.height() - 1 ); 407 sd->setTransformation( yMap.transformation()->copy() ); 418 419 QwtTransform *transform = NULL; 420 if ( yMap.transformation() ) 421 transform = yMap.transformation()->copy(); 422 423 sd->setTransformation( transform ); 408 424 } 409 425 … … 428 444 const QwtScaleDiv& yScaleDiv ) 429 445 { 430 QwtScaleDraw *sd = d_data->scaleDraw; 431 if ( d_data->scaleDivFromAxis && sd ) 432 { 433 sd->setScaleDiv( 434 sd->orientation() == Qt::Horizontal ? xScaleDiv : yScaleDiv ); 446 QwtScaleDraw *scaleDraw = d_data->scaleDraw; 447 448 if ( d_data->scaleDivFromAxis && scaleDraw ) 449 { 450 const QwtScaleDiv &scaleDiv = 451 scaleDraw->orientation() == Qt::Horizontal ? xScaleDiv : yScaleDiv; 435 452 436 453 const QwtPlot *plt = plot(); 437 454 if ( plt != NULL ) 438 455 { 439 d_data->updateBorders( plt->canvas()->contentsRect(), 440 plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) ); 441 } 442 } 443 } 456 const QRectF canvasRect = plt->canvas()->contentsRect(); 457 458 const QwtInterval interval = d_data->scaleInterval( 459 canvasRect, plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) ); 460 461 QwtScaleDiv sd = scaleDiv; 462 sd.setInterval( interval ); 463 464 if ( sd != scaleDraw->scaleDiv() ) 465 { 466 // the internal label cache of QwtScaleDraw 467 // is cleared here, so better avoid pointless 468 // assignments. 469 470 scaleDraw->setScaleDiv( sd ); 471 } 472 } 473 else 474 { 475 scaleDraw->setScaleDiv( scaleDiv ); 476 } 477 } 478 } -
trunk/BNC/qwt/qwt_plot_seriesitem.cpp
r4271 r8127 10 10 #include "qwt_plot_seriesitem.h" 11 11 12 class QwtPlot AbstractSeriesItem::PrivateData12 class QwtPlotSeriesItem::PrivateData 13 13 { 14 14 public: … … 25 25 \param title Title of the curve 26 26 */ 27 QwtPlot AbstractSeriesItem::QwtPlotAbstractSeriesItem( const QwtText &title ):27 QwtPlotSeriesItem::QwtPlotSeriesItem( const QwtText &title ): 28 28 QwtPlotItem( title ) 29 29 { 30 30 d_data = new PrivateData(); 31 setItemInterest( QwtPlotItem::ScaleInterest, true ); 31 32 } 32 33 … … 35 36 \param title Title of the curve 36 37 */ 37 QwtPlot AbstractSeriesItem::QwtPlotAbstractSeriesItem( const QString &title ):38 QwtPlotSeriesItem::QwtPlotSeriesItem( const QString &title ): 38 39 QwtPlotItem( QwtText( title ) ) 39 40 { … … 42 43 43 44 //! Destructor 44 QwtPlot AbstractSeriesItem::~QwtPlotAbstractSeriesItem()45 QwtPlotSeriesItem::~QwtPlotSeriesItem() 45 46 { 46 47 delete d_data; … … 56 57 \sa orientation() 57 58 */ 58 void QwtPlot AbstractSeriesItem::setOrientation( Qt::Orientation orientation )59 void QwtPlotSeriesItem::setOrientation( Qt::Orientation orientation ) 59 60 { 60 61 if ( d_data->orientation != orientation ) 61 62 { 62 63 d_data->orientation = orientation; 64 65 legendChanged(); 63 66 itemChanged(); 64 67 } … … 69 72 \sa setOrientation() 70 73 */ 71 Qt::Orientation QwtPlot AbstractSeriesItem::orientation() const74 Qt::Orientation QwtPlotSeriesItem::orientation() const 72 75 { 73 76 return d_data->orientation; … … 80 83 \param xMap Maps x-values into pixel coordinates. 81 84 \param yMap Maps y-values into pixel coordinates. 82 \param canvasRect Contents rect of the canvas85 \param canvasRect Contents rectangle of the canvas 83 86 */ 84 void QwtPlot AbstractSeriesItem::draw( QPainter *painter,87 void QwtPlotSeriesItem::draw( QPainter *painter, 85 88 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 86 89 const QRectF &canvasRect ) const … … 89 92 } 90 93 94 QRectF QwtPlotSeriesItem::boundingRect() const 95 { 96 return dataRect(); 97 } 98 99 void QwtPlotSeriesItem::updateScaleDiv( 100 const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv ) 101 { 102 const QRectF rect = QRectF( 103 xScaleDiv.lowerBound(), yScaleDiv.lowerBound(), 104 xScaleDiv.range(), yScaleDiv.range() ); 105 106 setRectOfInterest( rect ); 107 } 108 109 void QwtPlotSeriesItem::dataChanged() 110 { 111 itemChanged(); 112 } -
trunk/BNC/qwt/qwt_plot_seriesitem.h
r4271 r8127 15 15 #include "qwt_scale_div.h" 16 16 #include "qwt_series_data.h" 17 #include "qwt_series_store.h" 17 18 18 19 /*! 19 20 \brief Base class for plot items representing a series of samples 20 21 */ 21 class QWT_EXPORT QwtPlotAbstractSeriesItem: public QwtPlotItem 22 class QWT_EXPORT QwtPlotSeriesItem: public QwtPlotItem, 23 public virtual QwtAbstractSeriesStore 22 24 { 23 25 public: 24 explicit QwtPlot AbstractSeriesItem( const QString &title = QString::null );25 explicit QwtPlot AbstractSeriesItem( const QwtText &title );26 explicit QwtPlotSeriesItem( const QString &title = QString::null ); 27 explicit QwtPlotSeriesItem( const QwtText &title ); 26 28 27 virtual ~QwtPlot AbstractSeriesItem();29 virtual ~QwtPlotSeriesItem(); 28 30 29 31 void setOrientation( Qt::Orientation ); … … 40 42 \param xMap Maps x-values into pixel coordinates. 41 43 \param yMap Maps y-values into pixel coordinates. 42 \param canvasRect Contents rect of the canvas44 \param canvasRect Contents rectangle of the canvas 43 45 \param from Index of the first point to be painted 44 46 \param to Index of the last point to be painted. If to < 0 the … … 49 51 const QRectF &canvasRect, int from, int to ) const = 0; 50 52 53 virtual QRectF boundingRect() const; 54 55 virtual void updateScaleDiv( 56 const QwtScaleDiv &, const QwtScaleDiv & ); 57 58 protected: 59 virtual void dataChanged(); 60 51 61 private: 52 62 class PrivateData; … … 54 64 }; 55 65 56 /*!57 \brief Class template for plot items representing a series of samples58 */59 template <typename T>60 class QwtPlotSeriesItem: public QwtPlotAbstractSeriesItem61 {62 public:63 explicit QwtPlotSeriesItem<T>( const QString &title = QString::null );64 explicit QwtPlotSeriesItem<T>( const QwtText &title );65 66 virtual ~QwtPlotSeriesItem<T>();67 68 void setData( QwtSeriesData<T> * );69 70 QwtSeriesData<T> *data();71 const QwtSeriesData<T> *data() const;72 73 size_t dataSize() const;74 T sample( int index ) const;75 76 virtual QRectF boundingRect() const;77 virtual void updateScaleDiv( const QwtScaleDiv &,78 const QwtScaleDiv & );79 80 protected:81 //! Series82 QwtSeriesData<T> *d_series;83 };84 85 /*!86 Constructor87 \param title Title of the series item88 */89 template <typename T>90 QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QString &title ):91 QwtPlotAbstractSeriesItem( QwtText( title ) ),92 d_series( NULL )93 {94 }95 96 /*!97 Constructor98 \param title Title of the series item99 */100 template <typename T>101 QwtPlotSeriesItem<T>::QwtPlotSeriesItem( const QwtText &title ):102 QwtPlotAbstractSeriesItem( title ),103 d_series( NULL )104 {105 }106 107 //! Destructor108 template <typename T>109 QwtPlotSeriesItem<T>::~QwtPlotSeriesItem()110 {111 delete d_series;112 }113 114 //! \return the the curve data115 template <typename T>116 inline QwtSeriesData<T> *QwtPlotSeriesItem<T>::data()117 {118 return d_series;119 }120 121 //! \return the the curve data122 template <typename T>123 inline const QwtSeriesData<T> *QwtPlotSeriesItem<T>::data() const124 {125 return d_series;126 }127 128 /*!129 \param index Index130 \return Sample at position index131 */132 template <typename T>133 inline T QwtPlotSeriesItem<T>::sample( int index ) const134 {135 return d_series ? d_series->sample( index ) : T();136 }137 138 /*!139 Assign a series of samples140 141 \param data Data142 \warning The item takes ownership of the data object, deleting143 it when its not used anymore.144 */145 template <typename T>146 void QwtPlotSeriesItem<T>::setData( QwtSeriesData<T> *data )147 {148 if ( d_series != data )149 {150 delete d_series;151 d_series = data;152 itemChanged();153 }154 }155 156 /*!157 Return the size of the data arrays158 \sa setData()159 */160 template <typename T>161 size_t QwtPlotSeriesItem<T>::dataSize() const162 {163 if ( d_series == NULL )164 return 0;165 166 return d_series->size();167 }168 169 /*!170 \return Bounding rectangle of the data.171 If there is no bounding rect, like for empty data the rectangle is invalid.172 173 \sa QwtSeriesData<T>::boundingRect(), QRectF::isValid()174 */175 template <typename T>176 QRectF QwtPlotSeriesItem<T>::boundingRect() const177 {178 if ( d_series == NULL )179 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid180 181 return d_series->boundingRect();182 }183 184 /*!185 Update the rect of interest according to the current scale ranges186 187 \param xScaleDiv Scale division of the x-axis188 \param yScaleDiv Scale division of the y-axis189 190 \sa QwtSeriesData<T>::setRectOfInterest()191 */192 template <typename T>193 void QwtPlotSeriesItem<T>::updateScaleDiv(194 const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv )195 {196 const QRectF rect = QRectF(197 xScaleDiv.lowerBound(), yScaleDiv.lowerBound(),198 xScaleDiv.range(), yScaleDiv.range() );199 200 d_series->setRectOfInterest( rect );201 }202 203 66 #endif -
trunk/BNC/qwt/qwt_plot_spectrocurve.cpp
r4271 r8127 42 42 */ 43 43 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QwtText &title ): 44 QwtPlotSeriesItem <QwtPoint3D>( title )44 QwtPlotSeriesItem( title ) 45 45 { 46 46 init(); … … 52 52 */ 53 53 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString &title ): 54 QwtPlotSeriesItem <QwtPoint3D>( QwtText( title ) )54 QwtPlotSeriesItem( QwtText( title ) ) 55 55 { 56 56 init(); … … 72 72 73 73 d_data = new PrivateData; 74 d_series = new QwtPoint3DSeriesData();74 setData( new QwtPoint3DSeriesData() ); 75 75 76 76 setZ( 20.0 ); … … 99 99 100 100 /*! 101 \ brief Return the current paint attributes101 \return True, when attribute is enabled 102 102 \sa PaintAttribute, setPaintAttribute() 103 103 */ … … 113 113 void QwtPlotSpectroCurve::setSamples( const QVector<QwtPoint3D> &samples ) 114 114 { 115 delete d_series; 116 d_series = new QwtPoint3DSeriesData( samples ); 117 itemChanged(); 118 } 115 setData( new QwtPoint3DSeriesData( samples ) ); 116 } 117 118 /*! 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 126 it when its not used anymore. 127 */ 128 void QwtPlotSpectroCurve::setSamples( 129 QwtSeriesData<QwtPoint3D> *data ) 130 { 131 setData( data ); 132 } 119 133 120 134 /*! … … 137 151 } 138 152 153 legendChanged(); 139 154 itemChanged(); 140 155 } … … 162 177 { 163 178 d_data->colorRange = interval; 179 180 legendChanged(); 164 181 itemChanged(); 165 182 } … … 189 206 { 190 207 d_data->penWidth = penWidth; 208 209 legendChanged(); 191 210 itemChanged(); 192 211 } … … 208 227 \param xMap Maps x-values into pixel coordinates. 209 228 \param yMap Maps y-values into pixel coordinates. 210 \param canvasRect Contents rect of the canvas229 \param canvasRect Contents rectangle of the canvas 211 230 \param from Index of the first sample to be painted 212 231 \param to Index of the last sample to be painted. If to < 0 the … … 228 247 from = 0; 229 248 230 if ( from > =to )249 if ( from > to ) 231 250 return; 232 251 … … 240 259 \param xMap Maps x-values into pixel coordinates. 241 260 \param yMap Maps y-values into pixel coordinates. 242 \param canvasRect Contents rect of the canvas261 \param canvasRect Contents rectangle of the canvas 243 262 \param from Index of the first sample to be painted 244 263 \param to Index of the last sample to be painted. If to < 0 the … … 260 279 d_data->colorTable = d_data->colorMap->colorTable( d_data->colorRange ); 261 280 281 const QwtSeriesData<QwtPoint3D> *series = data(); 282 262 283 for ( int i = from; i <= to; i++ ) 263 284 { 264 const QwtPoint3D sample = d_series->sample( i );285 const QwtPoint3D sample = series->sample( i ); 265 286 266 287 double xi = xMap.transform( sample.x() ); … … 283 304 d_data->colorRange, sample.z() ); 284 305 285 painter->setPen( QPen( QColor ( rgb ), d_data->penWidth ) );306 painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) ); 286 307 } 287 308 else … … 290 311 d_data->colorRange, sample.z() ); 291 312 292 painter->setPen( QPen( QColor ( d_data->colorTable[index] ),313 painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ), 293 314 d_data->penWidth ) ); 294 315 } -
trunk/BNC/qwt/qwt_plot_spectrocurve.h
r4271 r8127 22 22 mapped to a color. 23 23 */ 24 class QWT_EXPORT QwtPlotSpectroCurve: public QwtPlotSeriesItem<QwtPoint3D> 24 class QWT_EXPORT QwtPlotSpectroCurve: 25 public QwtPlotSeriesItem, QwtSeriesStore<QwtPoint3D> 25 26 { 26 27 public: … … 46 47 47 48 void setSamples( const QVector<QwtPoint3D> & ); 49 void setSamples( QwtSeriesData<QwtPoint3D> * ); 50 48 51 49 52 void setColorMap( QwtColorMap * ); -
trunk/BNC/qwt/qwt_plot_spectrogram.cpp
r4271 r8127 24 24 #endif 25 25 26 #define DEBUG_RENDER 0 27 28 #if DEBUG_RENDER 29 #include <QElapsedTimer> 30 #endif 31 26 32 class QwtPlotSpectrogram::PrivateData 27 33 { 28 34 public: 29 35 PrivateData(): 30 data( NULL ), 31 renderThreadCount( 1 ) 36 data( NULL ) 32 37 { 33 38 colorMap = new QwtLinearColorMap(); … … 35 40 36 41 conrecFlags = QwtRasterData::IgnoreAllVerticesOnLevel; 42 #if 0 37 43 conrecFlags |= QwtRasterData::IgnoreOutOfRange; 44 #endif 38 45 } 39 46 ~PrivateData() … … 46 53 QwtColorMap *colorMap; 47 54 DisplayModes displayMode; 48 49 uint renderThreadCount;50 55 51 56 QList<double> contourLevels; … … 108 113 } 109 114 115 legendChanged(); 110 116 itemChanged(); 111 117 } … … 123 129 124 130 /*! 125 Rendering an image from the raster data can often be done126 parallel on a multicore system.127 128 \param numThreads Number of threads to be used for rendering.129 If numThreads is set to 0, the system specific130 ideal thread count is used.131 132 The default thread count is 1 ( = no additional threads )133 134 \warning Rendering in multiple threads is only supported for Qt >= 4.4135 \sa renderThreadCount(), renderImage(), renderTile()136 */137 void QwtPlotSpectrogram::setRenderThreadCount( uint numThreads )138 {139 d_data->renderThreadCount = numThreads;140 }141 142 /*!143 \return Number of threads to be used for rendering.144 If numThreads is set to 0, the system specific145 ideal thread count is used.146 147 \warning Rendering in multiple threads is only supported for Qt >= 4.4148 \sa setRenderThreadCount(), renderImage(), renderTile()149 */150 uint QwtPlotSpectrogram::renderThreadCount() const151 {152 return d_data->renderThreadCount;153 }154 155 /*!156 131 Change the color map 157 132 … … 173 148 174 149 invalidateCache(); 150 151 legendChanged(); 175 152 itemChanged(); 176 153 } … … 183 160 { 184 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() 176 */ 177 void QwtPlotSpectrogram::setDefaultContourPen( 178 const QColor &color, qreal width, Qt::PenStyle style ) 179 { 180 setDefaultContourPen( QPen( color, width, style ) ); 185 181 } 186 182 … … 200 196 { 201 197 d_data->defaultContourPen = pen; 198 199 legendChanged(); 202 200 itemChanged(); 203 201 } … … 266 264 \return true, is enabled 267 265 266 The default setting enables QwtRasterData::IgnoreAllVerticesOnLevel 267 268 268 \sa setConrecClag(), renderContourLines(), 269 269 QwtRasterData::contourLines() … … 288 288 d_data->contourLevels = levels; 289 289 qSort( d_data->contourLevels ); 290 291 legendChanged(); 290 292 itemChanged(); 291 293 } 292 294 293 295 /*! 294 \ brief Return the levels of the contour lines.296 \return Levels of the contour lines. 295 297 296 298 The levels are sorted in increasing order. … … 384 386 \brief Render an image from data and color map. 385 387 386 For each pixel of rectthe value is mapped into a color.388 For each pixel of area the value is mapped into a color. 387 389 388 390 \param xMap X-Scale Map … … 421 423 d_data->data->initRaster( area, image.size() ); 422 424 425 #if DEBUG_RENDER 426 QElapsedTimer time; 427 time.start(); 428 #endif 429 423 430 #if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE) 424 uint numThreads = d_data->renderThreadCount;431 uint numThreads = renderThreadCount(); 425 432 426 433 if ( numThreads <= 0 ) … … 456 463 #endif 457 464 465 #if DEBUG_RENDER 466 const qint64 elapsed = time.elapsed(); 467 qDebug() << "renderImage" << imageSize << elapsed; 468 #endif 469 458 470 d_data->data->discardRaster(); 459 471 … … 486 498 const double ty = yMap.invTransform( y ); 487 499 488 QRgb *line = ( QRgb * )image->scanLine( y);500 QRgb *line = reinterpret_cast<QRgb *>( image->scanLine( y ) ); 489 501 line += tile.left(); 490 502 … … 521 533 \brief Return the raster to be used by the CONREC contour algorithm. 522 534 523 A larger size will improve the precisi sion of the CONREC algorithm,535 A larger size will improve the precision of the CONREC algorithm, 524 536 but will slow down the time that is needed to calculate the lines. 525 537 … … 527 539 the resolution depending on pixelSize(). 528 540 529 \param area Rect , where to calculate the contour lines530 \param rect Rect in pixel coordinates, where to paint the contour lines541 \param area Rectangle, where to calculate the contour lines 542 \param rect Rectangle in pixel coordinates, where to paint the contour lines 531 543 \return Raster to be used by the CONREC contour algorithm. 532 544 … … 556 568 \param rect Rectangle, where to calculate the contour lines 557 569 \param raster Raster, used by the CONREC algorithm 570 \return Calculated contour lines 558 571 559 572 \sa contourLevels(), setConrecFlag(), … … 586 599 if ( d_data->data == NULL ) 587 600 return; 588 589 const QwtInterval intensityRange = d_data->data->interval( Qt::ZAxis );590 601 591 602 const int numLevels = d_data->contourLevels.size(); … … 622 633 \param xMap Maps x-values into pixel coordinates. 623 634 \param yMap Maps y-values into pixel coordinates. 624 \param canvasRect Contents rect of the canvas in painter coordinates635 \param canvasRect Contents rectangle of the canvas in painter coordinates 625 636 626 637 \sa setDisplayMode(), renderImage(), -
trunk/BNC/qwt/qwt_plot_spectrogram.h
r4271 r8127 21 21 \brief A plot item, which displays a spectrogram 22 22 23 A spectrogram displays threedimenional data, where the 3rd dimension23 A spectrogram displays 3-dimensional data, where the 3rd dimension 24 24 ( the intensity ) is displayed using colors. The colors are calculated 25 25 from the values using a color map. 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() ). 26 30 27 31 In ContourMode contour lines are painted for the contour levels. … … 29 33 \image html spectrogram3.png 30 34 31 \sa QwtRasterData, QwtColorMap 35 \sa QwtRasterData, QwtColorMap, QwtPlotItem::setRenderThreadCount() 32 36 */ 33 37 … … 55 59 virtual ~QwtPlotSpectrogram(); 56 60 57 void setRenderThreadCount( uint numThreads );58 uint renderThreadCount() const;59 60 61 void setDisplayMode( DisplayMode, bool on = true ); 61 62 bool testDisplayMode( DisplayMode ) const; … … 71 72 virtual QRectF pixelHint( const QRectF & ) const; 72 73 74 void setDefaultContourPen( const QColor &, 75 qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 73 76 void setDefaultContourPen( const QPen & ); 74 77 QPen defaultContourPen() const; -
trunk/BNC/qwt/qwt_plot_svgitem.cpp
r4621 r8127 10 10 #include "qwt_plot_svgitem.h" 11 11 #include "qwt_scale_map.h" 12 #include "qwt_legend.h"13 #include "qwt_legend_item.h"14 12 #include "qwt_painter.h" 15 13 #include <qpainter.h> … … 66 64 { 67 65 d_data = new PrivateData(); 66 d_data->boundingRect = QwtPlotItem::boundingRect(); 68 67 69 68 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 92 91 d_data->boundingRect = rect; 93 92 const bool ok = d_data->renderer.load( fileName ); 93 94 legendChanged(); 94 95 itemChanged(); 96 95 97 return ok; 96 98 } … … 109 111 d_data->boundingRect = rect; 110 112 const bool ok = d_data->renderer.load( data ); 113 114 legendChanged(); 111 115 itemChanged(); 116 112 117 return ok; 113 118 } 114 119 115 //! Bounding rect of the item120 //! Bounding rectangle of the item 116 121 QRectF QwtPlotSvgItem::boundingRect() const 117 122 { … … 161 166 162 167 \param painter Painter 163 \param viewBox View Box, see QSvgRenderer::viewBox 164 \param rect T raget rectangle on the paint device168 \param viewBox View Box, see QSvgRenderer::viewBox() 169 \param rect Target rectangle on the paint device 165 170 */ 166 171 void QwtPlotSvgItem::render( QPainter *painter, … … 185 190 186 191 /*! 187 Calculate the view Box from anrect and boundingRect().192 Calculate the view box from rect and boundingRect(). 188 193 189 194 \param rect Rectangle in scale coordinates 190 \return viewBox View Box, see QSvgRenderer::viewBox195 \return View box, see QSvgRenderer::viewBox() 191 196 */ 192 197 QRectF QwtPlotSvgItem::viewBox( const QRectF &rect ) const -
trunk/BNC/qwt/qwt_plot_xml.cpp
r4271 r8127 29 29 from a specific editor in the Qwt designer plugin. 30 30 31 \return QString::null 31 32 \warning The plot editor has never been implemented. 32 33 */ -
trunk/BNC/qwt/qwt_plot_zoomer.cpp
r4271 r8127 10 10 #include "qwt_plot_zoomer.h" 11 11 #include "qwt_plot.h" 12 #include "qwt_plot_canvas.h"13 12 #include "qwt_scale_div.h" 14 13 #include "qwt_picker_machine.h" 15 14 #include <qalgorithms.h> 15 16 static QwtInterval qwtExpandedZoomInterval( double v1, double v2, 17 double minRange, const QwtTransform* transform ) 18 { 19 double min = v1; 20 double max = v2; 21 22 if ( max - min < minRange ) 23 { 24 min = 0.5 * ( min + max - minRange ); 25 max = min + minRange; 26 27 if ( transform ) 28 { 29 // f.e the logarithmic scale doesn't allow values 30 // outside [QwtLogTransform::LogMin/QwtLogTransform::LogMax] 31 32 double minBounded = transform->bounded( min ); 33 double maxBounded = transform->bounded( max ); 34 35 if ( minBounded != min ) 36 { 37 maxBounded = transform->bounded( minBounded + minRange ); 38 } 39 else if ( maxBounded != max ) 40 { 41 minBounded = transform->bounded( maxBounded - minRange ); 42 } 43 44 min = minBounded; 45 max = maxBounded; 46 } 47 } 48 49 return QwtInterval( min, max ); 50 } 51 52 static QRectF qwtExpandedZoomRect( const QRectF &zoomRect, const QSizeF &minSize, 53 const QwtTransform* transformX, const QwtTransform* transformY ) 54 { 55 QRectF r = zoomRect; 56 57 if ( minSize.width() > r.width() ) 58 { 59 const QwtInterval intv = qwtExpandedZoomInterval( 60 r.left(), r.right(), minSize.width(), transformX ); 61 62 r.setLeft( intv.minValue() ); 63 r.setRight( intv.maxValue() ); 64 } 65 66 if ( minSize.height() > r.height() ) 67 { 68 const QwtInterval intv = qwtExpandedZoomInterval( 69 zoomRect.top(), zoomRect.bottom(), minSize.height(), transformY ); 70 71 r.setTop( intv.minValue() ); 72 r.setBottom( intv.maxValue() ); 73 } 74 75 return r; 76 } 16 77 17 78 class QwtPlotZoomer::PrivateData … … 33 94 34 95 The zoomer is initialized with a QwtPickerDragRectMachine, 35 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band96 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 36 97 is set to QwtPicker::RectRubberBand 37 98 38 99 \param canvas Plot canvas to observe, also the parent object 39 \param doReplot Call replotfor the attached plot before initializing100 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 40 101 the zoomer with its scales. This might be necessary, 41 102 when the plot is in a state with pending scale changes. … … 43 104 \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase() 44 105 */ 45 QwtPlotZoomer::QwtPlotZoomer( Q wtPlotCanvas*canvas, bool doReplot ):106 QwtPlotZoomer::QwtPlotZoomer( QWidget *canvas, bool doReplot ): 46 107 QwtPlotPicker( canvas ) 47 108 { … … 54 115 55 116 The zoomer is initialized with a QwtPickerDragRectMachine, 56 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band117 the tracker mode is set to QwtPicker::ActiveOnly and the rubber band 57 118 is set to QwtPicker;;RectRubberBand 58 119 … … 60 121 \param yAxis Y axis of the zoomer 61 122 \param canvas Plot canvas to observe, also the parent object 62 \param doReplot Call replotfor the attached plot before initializing123 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 63 124 the zoomer with its scales. This might be necessary, 64 125 when the plot is in a state with pending scale changes. … … 68 129 69 130 QwtPlotZoomer::QwtPlotZoomer( int xAxis, int yAxis, 70 Q wtPlotCanvas*canvas, bool doReplot ):131 QWidget *canvas, bool doReplot ): 71 132 QwtPlotPicker( xAxis, yAxis, canvas ) 72 133 { … … 141 202 142 203 /*! 143 Return the zoom stack. zoomStack()[0] is the zoom base,144 zoomStack()[1] the first zoomed rectangle.204 \return The zoom stack. zoomStack()[0] is the zoom base, 205 zoomStack()[1] the first zoomed rectangle. 145 206 146 207 \sa setZoomStack(), zoomRectIndex() … … 163 224 Reinitialized the zoom stack with scaleRect() as base. 164 225 165 \param doReplot Call replotfor the attached plot before initializing226 \param doReplot Call QwtPlot::replot() for the attached plot before initializing 166 227 the zoomer with its scales. This might be necessary, 167 228 when the plot is in a state with pending scale changes. … … 189 250 190 251 base is united with the current scaleRect() and the zoom stack is 191 reinit alized with it as zoom base. plot is zoomed to scaleRect().252 reinitialized with it as zoom base. plot is zoomed to scaleRect(). 192 253 193 254 \param base Zoom base … … 218 279 219 280 /*! 220 Rectangle at the current position on the zoom stack. 221 281 \return Rectangle at the current position on the zoom stack. 222 282 \sa zoomRectIndex(), scaleRect(). 223 283 */ … … 239 299 240 300 Clears all rectangles above the current position of the 241 zoom stack and push s the normalized recton it.301 zoom stack and pushes the normalized rectangle on it. 242 302 243 303 \note If the maximal stack depth is reached, zoom is ignored. … … 275 335 276 336 Activate a rectangle on the zoom stack with an offset relative 277 to the current position. Negative values of off est will zoom out,337 to the current position. Negative values of offset will zoom out, 278 338 positive zoom in. A value of 0 zooms out to the zoom base. 279 339 … … 344 404 Adjust the observed plot to zoomRect() 345 405 346 \note Initiates QwtPlot::replot 406 \note Initiates QwtPlot::replot() 347 407 */ 348 408 … … 361 421 double x1 = rect.left(); 362 422 double x2 = rect.right(); 363 if ( plt->axisScaleDiv( xAxis() )->lowerBound() > 364 plt->axisScaleDiv( xAxis() )->upperBound() ) 365 { 423 if ( !plt->axisScaleDiv( xAxis() ).isIncreasing() ) 366 424 qSwap( x1, x2 ); 367 }368 425 369 426 plt->setAxisScale( xAxis(), x1, x2 ); … … 371 428 double y1 = rect.top(); 372 429 double y2 = rect.bottom(); 373 if ( plt->axisScaleDiv( yAxis() )->lowerBound() > 374 plt->axisScaleDiv( yAxis() )->upperBound() ) 375 { 430 if ( !plt->axisScaleDiv( yAxis() ).isIncreasing() ) 376 431 qSwap( y1, y2 ); 377 } 432 378 433 plt->setAxisScale( yAxis(), y1, y2 ); 379 434 … … 495 550 \brief Check and correct a selected rectangle 496 551 497 Reject rectangles with a h ight or width < 2, otherwise552 Reject rectangles with a height or width < 2, otherwise 498 553 expand the selected rectangle to a minimum size of 11x11 499 554 and accept it. 500 555 501 \return true If rectis accepted, or has been changed502 to a accepted rectangle.556 \return true If the rectangle is accepted, or has been changed 557 to an accepted one. 503 558 */ 504 559 … … 573 628 if accepted. 574 629 630 \param ok If true, complete the selection and emit selected signals 631 otherwise discard the selection. 632 575 633 \sa accept(), minZoomSize() 634 \return True if the selection has been accepted, false otherwise 576 635 */ 577 636 bool QwtPlotZoomer::end( bool ok ) … … 592 651 rect = rect.normalized(); 593 652 594 QRectF zoomRect = invTransform( rect ).normalized(); 595 596 const QSizeF minSize = minZoomSize(); 597 if ( minSize.isValid() ) 598 { 599 const QPointF center = zoomRect.center(); 600 zoomRect.setSize( zoomRect.size().expandedTo( minZoomSize() ) ); 601 zoomRect.moveCenter( center ); 602 } 653 const QwtScaleMap xMap = plot->canvasMap( xAxis() ); 654 const QwtScaleMap yMap = plot->canvasMap( yAxis() ); 655 656 QRectF zoomRect = QwtScaleMap::invTransform( xMap, yMap, rect ).normalized(); 657 658 zoomRect = qwtExpandedZoomRect( zoomRect, minZoomSize(), 659 xMap.transformation(), yMap.transformation() ); 603 660 604 661 zoom( zoomRect ); -
trunk/BNC/qwt/qwt_plot_zoomer.h
r4271 r8127 18 18 \brief QwtPlotZoomer provides stacked zooming for a plot widget 19 19 20 QwtPlotZoomer offers rubberband selections on the plot canvas, 21 translating the selected rectangles into plot coordinates and 22 adjusting the axes to them. Zooming can repeated as often as 23 possible, limited only by maxStackDepth() or minZoomSize(). 24 Each rectangle is pushed on a stack. 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. 25 24 26 Zoom rectangles can be selected depending on selectionFlags() using the 27 mouse or keyboard (QwtEventPattern, QwtPickerMachine). 28 QwtEventPattern::MouseSelect3,QwtEventPattern::KeyUndo, 29 or QwtEventPattern::MouseSelect6,QwtEventPattern::KeyRedo 30 walk up and down the zoom stack. 31 QwtEventPattern::MouseSelect2 or QwtEventPattern::KeyHome unzoom to 32 the initial size. 25 Zooming can be repeated as often as possible, limited only by 26 maxStackDepth() or minZoomSize(). Each rectangle is pushed on a stack. 27 28 The default setting how to select rectangles is 29 a QwtPickerDragRectMachine with the following bindings: 30 31 - QwtEventPattern::MouseSelect1\n 32 The first point of the zoom rectangle is selected by a mouse press, 33 the second point from the position, where the mouse is released. 34 35 - QwtEventPattern::KeySelect1\n 36 The first key press selects the first, the second key press 37 selects the second point. 38 39 - QwtEventPattern::KeyAbort\n 40 Discard the selection in the state, where the first point 41 is selected. 42 43 To traverse the zoom stack the following bindings are used: 44 45 - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n 46 Zoom out one position on the zoom stack 47 48 - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n 49 Zoom in one position on the zoom stack 50 51 - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n 52 Zoom to the zoom base 53 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. 59 60 \code 61 zoomer = new QwtPlotZoomer( plot ); 62 zoomer->setKeyPattern( QwtEventPattern::KeyRedo, Qt::Key_I, Qt::ShiftModifier ); 63 zoomer->setKeyPattern( QwtEventPattern::KeyUndo, Qt::Key_O, Qt::ShiftModifier ); 64 zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home ); 65 \endcode 33 66 34 67 QwtPlotZoomer is tailored for plots with one x and y axis, but it is 35 allowed to attach a second QwtPlotZoomer for the other axes. 68 allowed to attach a second QwtPlotZoomer ( without rubber band and tracker ) 69 for the other axes. 36 70 37 71 \note The realtime example includes an derived zoomer class that adds 38 72 scrollbars to the plot canvas. 73 74 \sa QwtPlotPanner, QwtPlotMagnifier 39 75 */ 40 76 … … 43 79 Q_OBJECT 44 80 public: 45 explicit QwtPlotZoomer( Q wtPlotCanvas*, bool doReplot = true );81 explicit QwtPlotZoomer( QWidget *, bool doReplot = true ); 46 82 explicit QwtPlotZoomer( int xAxis, int yAxis, 47 Q wtPlotCanvas*, bool doReplot = true );83 QWidget *, bool doReplot = true ); 48 84 49 85 virtual ~QwtPlotZoomer(); -
trunk/BNC/qwt/qwt_point_3d.h
r4271 r8127 103 103 104 104 /*! 105 Returns true if the point is null; otherwise returns false.105 \return True if the point is null; otherwise returns false. 106 106 107 107 A point is considered to be null if x, y and z-coordinates … … 110 110 inline bool QwtPoint3D::isNull() const 111 111 { 112 return d_x == 0.0 && d_y == 0.0 && d_z == 0 ;112 return d_x == 0.0 && d_y == 0.0 && d_z == 0.0; 113 113 } 114 114 115 //! Returns the x-coordinate of the point.115 //! \return The x-coordinate of the point. 116 116 inline double QwtPoint3D::x() const 117 117 { … … 119 119 } 120 120 121 //! Returns the y-coordinate of the point.121 //! \return The y-coordinate of the point. 122 122 inline double QwtPoint3D::y() const 123 123 { … … 125 125 } 126 126 127 //! Returns the z-coordinate of the point.127 //! \return The z-coordinate of the point. 128 128 inline double QwtPoint3D::z() const 129 129 { … … 131 131 } 132 132 133 //! Returns areference to the x-coordinate of the point.133 //! \return A reference to the x-coordinate of the point. 134 134 inline double &QwtPoint3D::rx() 135 135 { … … 137 137 } 138 138 139 //! Returns areference to the y-coordinate of the point.139 //! \return A reference to the y-coordinate of the point. 140 140 inline double &QwtPoint3D::ry() 141 141 { … … 143 143 } 144 144 145 //! Returns areference to the z-coordinate of the point.145 //! \return A reference to the z-coordinate of the point. 146 146 inline double &QwtPoint3D::rz() 147 147 { … … 168 168 169 169 /*! 170 Rounds2D point, where the z coordinate is dropped.170 \return 2D point, where the z coordinate is dropped. 171 171 */ 172 172 inline QPointF QwtPoint3D::toPoint() const … … 175 175 } 176 176 177 //! Returns trueif this point and other are equal; otherwise returns false.177 //! \return True, if this point and other are equal; otherwise returns false. 178 178 inline bool QwtPoint3D::operator==( const QwtPoint3D &other ) const 179 179 { … … 181 181 } 182 182 183 //! Returns true if this rect and other are different; otherwise returns false.183 //! \return True if this rect and other are different; otherwise returns false. 184 184 inline bool QwtPoint3D::operator!=( const QwtPoint3D &other ) const 185 185 { -
trunk/BNC/qwt/qwt_point_polar.cpp
r4271 r8127 39 39 Convert and return values in Cartesian coordinates 40 40 41 \return Converted point in Cartesian coordinates 42 41 43 \note Invalid or null points will be returned as QPointF(0.0, 0.0) 42 44 \sa isValid(), isNull() … … 54 56 55 57 /*! 56 Returns true if point1 is equal to point2; otherwise returns false.58 \brief Compare 2 points 57 59 58 60 Two points are equal to each other if radius and 59 61 azimuth-coordinates are the same. Points are not equal, when 60 62 the azimuth differs, but other.azimuth() == azimuth() % (2 * PI). 63 64 \return True if the point is equal to other; otherwise return false. 61 65 62 66 \sa normalized() … … 68 72 69 73 /*! 70 Returns true if point1 is not equal to point2; otherwise returns false.74 Compare 2 points 71 75 72 76 Two points are equal to each other if radius and … … 74 78 the azimuth differs, but other.azimuth() == azimuth() % (2 * PI). 75 79 80 \return True if the point is not equal to other; otherwise return false. 76 81 \sa normalized() 77 82 */ … … 86 91 When the radius is < 0.0 it is set to 0.0. The azimuth is 87 92 a value >= 0.0 and < 2 * M_PI. 93 94 \return Normalized point 88 95 */ 89 96 QwtPointPolar QwtPointPolar::normalized() const -
trunk/BNC/qwt/qwt_point_polar.h
r4331 r8127 63 63 /*! 64 64 Constructs a null point, with a radius and azimuth set to 0.0. 65 \sa QPointF::isNull 65 \sa QPointF::isNull() 66 66 */ 67 67 inline QwtPointPolar::QwtPointPolar(): … … 195 195 } 196 196 197 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos ) 198 { 199 return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ), 200 qSqrt( qwtSqr( pos.x() ) + qwtSqr( pos.y() ) ) ); 201 } 202 197 203 #endif -
trunk/BNC/qwt/qwt_raster_data.cpp
r4271 r8127 10 10 #include "qwt_raster_data.h" 11 11 #include "qwt_point_3d.h" 12 #include <qnumeric.h> 12 13 13 14 class QwtRasterData::ContourPlane … … 94 95 case 6: 95 96 // e(-1,1,0), e(1,0,-1) 96 line[0] = vertex[ 1].toPoint();97 line[0] = vertex[2].toPoint(); 97 98 line[1] = intersection( vertex[0], vertex[1] ); 98 99 break; … … 181 182 \brief Initialize a raster 182 183 183 Before the composition of an image QwtPlotSpectrogram calls initRaster ,184 Before the composition of an image QwtPlotSpectrogram calls initRaster(), 184 185 announcing the area and its resolution that will be requested. 185 186 186 187 The default implementation does nothing, but for data sets that 187 are stored in files, it might be good idea to reimplement initRaster ,188 are stored in files, it might be good idea to reimplement initRaster(), 188 189 where the data is resampled and loaded into memory. 189 190 … … 221 222 222 223 Width and height of the hint need to be the horizontal 223 and vertical distances between 2 neighbo ured points.224 and vertical distances between 2 neighbored points. 224 225 The center of the hint has to be the position of any point 225 226 ( it doesn't matter which one ). … … 247 248 /*! 248 249 Calculate contour lines 250 251 \param rect Bounding rectangle for the contour lines 252 \param raster Number of data pixels of the raster data 253 \param levels List of limits, where to insert contour lines 254 \param flags Flags to customize the contouring algorithm 255 256 \return Calculated contour lines 249 257 250 258 An adaption of CONREC, a simple contouring algorithm. … … 337 345 if ( z > zMax ) 338 346 zMax = z; 347 } 348 349 if ( qIsNaN( zSum ) ) 350 { 351 // one of the points is NaN 352 continue; 339 353 } 340 354 -
trunk/BNC/qwt/qwt_raster_data.h
r4271 r8127 39 39 enum ConrecFlag 40 40 { 41 //! Ignore all ver ices on the same level41 //! Ignore all vertices on the same level 42 42 IgnoreAllVerticesOnLevel = 0x01, 43 43 -
trunk/BNC/qwt/qwt_round_scale_draw.cpp
r4271 r8127 12 12 #include "qwt_scale_div.h" 13 13 #include "qwt_scale_map.h" 14 #include "qwt_math.h" 14 15 #include <qpen.h> 15 16 #include <qpainter.h> … … 21 22 public: 22 23 PrivateData(): 23 center( 50 , 50 ),24 radius( 50 ),25 startAngle( -135 * 16),26 endAngle( 135 * 16)24 center( 50.0, 50.0 ), 25 radius( 50.0 ), 26 startAngle( -135.0 ), 27 endAngle( 135.0 ) 27 28 { 28 29 } … … 64 65 \sa moveCenter() 65 66 */ 66 void QwtRoundScaleDraw::setRadius( intradius )67 void QwtRoundScaleDraw::setRadius( double radius ) 67 68 { 68 69 d_data->radius = radius; … … 74 75 Radius is the radius of the backbone without ticks and labels. 75 76 77 \return Radius of the scale 76 78 \sa setRadius(), extent() 77 79 */ 78 intQwtRoundScaleDraw::radius() const80 double QwtRoundScaleDraw::radius() const 79 81 { 80 82 return d_data->radius; … … 110 112 <li>The angle range is limited to [-360, 360] degrees. Angles exceeding 111 113 this range will be clipped. 112 <li>For angles more than 359degrees above or below min(angle1, angle2),114 <li>For angles more or equal than 360 degrees above or below min(angle1, angle2), 113 115 scale marks will not be drawn. 114 <li>If you need a counterclockwise scale, use QwtScaleDiv::set Range116 <li>If you need a counterclockwise scale, use QwtScaleDiv::setInterval() 115 117 </ul> 116 118 */ 117 119 void QwtRoundScaleDraw::setAngleRange( double angle1, double angle2 ) 118 120 { 121 #if 0 119 122 angle1 = qBound( -360.0, angle1, 360.0 ); 120 123 angle2 = qBound( -360.0, angle2, 360.0 ); 121 122 d_data->startAngle = angle1 * 16.0; 123 d_data->endAngle = angle2 * 16.0; 124 #endif 125 126 d_data->startAngle = angle1; 127 d_data->endAngle = angle2; 124 128 125 129 if ( d_data->startAngle == d_data->endAngle ) … … 142 146 void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const 143 147 { 148 const double tval = scaleMap().transform( value ); 149 if ( ( tval >= d_data->startAngle + 360.0 ) 150 || ( tval <= d_data->startAngle - 360.0 ) ) 151 { 152 return; 153 } 154 144 155 const QwtText label = tickLabel( painter->font(), value ); 145 156 if ( label.isEmpty() ) 146 157 return; 147 158 148 const double tval = scaleMap().transform( value );149 if ( ( tval > d_data->startAngle + 359 * 16 )150 || ( tval < d_data->startAngle - 359 * 16 ) )151 {152 return;153 }154 155 159 double radius = d_data->radius; 156 160 if ( hasComponent( QwtAbstractScaleDraw::Ticks ) || … … 164 168 165 169 const QSizeF sz = label.textSize( painter->font() ); 166 const double arc = tval / 16.0 / 360.0 * 2 * M_PI;170 const double arc = qwtRadians( tval ); 167 171 168 172 const double x = d_data->center.x() + 169 173 ( radius + sz.width() / 2.0 ) * qSin( arc ); 170 174 const double y = d_data->center.y() - 171 ( radius + sz.height() / 2.0 ) * cos( arc );175 ( radius + sz.height() / 2.0 ) * qCos( arc ); 172 176 173 177 const QRectF r( x - sz.width() / 2, y - sz.height() / 2, … … 196 200 const double radius = d_data->radius; 197 201 198 if ( ( tval < = d_data->startAngle + 359 * 16)199 || ( tval >= d_data->startAngle - 359 * 16) )200 { 201 const double arc = double( tval ) / 16.0 * M_PI / 180.0;202 if ( ( tval < d_data->startAngle + 360.0 ) 203 && ( tval > d_data->startAngle - 360.0 ) ) 204 { 205 const double arc = qwtRadians( tval ); 202 206 203 207 const double sinArc = qSin( arc ); … … 221 225 void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const 222 226 { 223 const double a1 = qMin( scaleMap().p1(), scaleMap().p2() ) - 90 * 16; 224 const double a2 = qMax( scaleMap().p1(), scaleMap().p2() ) - 90 * 16; 227 const double deg1 = scaleMap().p1(); 228 const double deg2 = scaleMap().p2(); 229 230 const int a1 = qRound( qMin( deg1, deg2 ) - 90 ); 231 const int a2 = qRound( qMax( deg1, deg2 ) - 90 ); 225 232 226 233 const double radius = d_data->radius; … … 228 235 const double y = d_data->center.y() - radius; 229 236 230 painter->drawArc( x, y, 2 * radius, 2 * radius,231 -a2 , a2 - a1 + 1); // counterclockwise237 painter->drawArc( QRectF( x, y, 2 * radius, 2 * radius ), 238 -a2 * 16, ( a2 - a1 + 1 ) * 16 ); // counterclockwise 232 239 } 233 240 … … 240 247 241 248 \param font Font used for painting the labels 249 \return Calculated extent 242 250 243 251 \sa setMinimumExtent(), minimumExtent() 244 \warning The implemented algo is not too smart and252 \warning The implemented algorithm is not too smart and 245 253 calculates only an upper limit, that might be a 246 254 few pixels too large … … 260 268 continue; 261 269 262 const QwtText label = tickLabel( font, value );263 if ( label.isEmpty() )264 continue;265 266 270 const double tval = scaleMap().transform( value ); 267 if ( ( tval < d_data->startAngle + 360 * 16)268 && ( tval > d_data->startAngle - 360 * 16) )271 if ( ( tval < d_data->startAngle + 360 ) 272 && ( tval > d_data->startAngle - 360 ) ) 269 273 { 270 const double arc = tval / 16.0 / 360.0 * 2 * M_PI; 274 const QwtText label = tickLabel( font, value ); 275 if ( label.isEmpty() ) 276 continue; 277 278 const double arc = qwtRadians( tval ); 271 279 272 280 const QSizeF sz = label.textSize( font ); … … 290 298 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 291 299 { 292 const double pw = qMax( 1, penWidth() ); // pen width can be zero300 const double pw = qMax( 1, penWidth() ); // pen width can be zero 293 301 d += pw; 294 302 } -
trunk/BNC/qwt/qwt_round_scale_draw.h
r4271 r8127 15 15 #include <qpoint.h> 16 16 17 class QPen;18 19 17 /*! 20 18 \brief A class for drawing round scales 21 19 22 20 QwtRoundScaleDraw can be used to draw round scales. 23 The circle segment can be adjusted by QwtRoundScaleDraw::setAngleRange().21 The circle segment can be adjusted by setAngleRange(). 24 22 The geometry of the scale can be specified with 25 QwtRoundScaleDraw::moveCenter() and QwtRoundScaleDraw::setRadius().23 moveCenter() and setRadius(). 26 24 27 25 After a scale division has been specified as a QwtScaleDiv object … … 36 34 virtual ~QwtRoundScaleDraw(); 37 35 38 void setRadius( intradius );39 intradius() const;36 void setRadius( double radius ); 37 double radius() const; 40 38 41 39 void moveCenter( double x, double y ); … … 48 46 49 47 protected: 50 virtual void drawTick( QPainter * p, double val, double len ) const;51 virtual void drawBackbone( QPainter * p) const;52 virtual void drawLabel( QPainter * p, double val ) const;48 virtual void drawTick( QPainter *, double val, double len ) const; 49 virtual void drawBackbone( QPainter * ) const; 50 virtual void drawLabel( QPainter *, double val ) const; 53 51 54 52 private: -
trunk/BNC/qwt/qwt_sampling_thread.h
r4271 r8127 8 8 \brief A thread collecting samples at regular intervals. 9 9 10 Conti ounous signals are converted into a discrete signal by10 Continuous signals are converted into a discrete signal by 11 11 collecting samples at regular intervals. A discrete signal 12 12 can be displayed by a QwtPlotSeriesItem on a QwtPlot widget. 13 13 14 QwtSamplingThread starts a thread calling per odically sample(),14 QwtSamplingThread starts a thread calling periodically sample(), 15 15 to collect and store ( or emit ) a single sample. 16 16 … … 39 39 Collect a sample 40 40 41 \param elapsed Time since the thread was started in mil iseconds41 \param elapsed Time since the thread was started in milliseconds 42 42 */ 43 43 virtual void sample( double elapsed ) = 0; -
trunk/BNC/qwt/qwt_scale_div.cpp
r4271 r8127 10 10 #include "qwt_scale_div.h" 11 11 #include "qwt_math.h" 12 #include "qwt_interval.h"13 12 #include <qalgorithms.h> 14 13 15 //! Construct an invalid QwtScaleDiv instance. 16 QwtScaleDiv::QwtScaleDiv(): 17 d_lowerBound( 0.0 ), 18 d_upperBound( 0.0 ), 19 d_isValid( false ) 20 { 21 } 22 23 /*! 24 Construct QwtScaleDiv instance. 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 25 30 26 31 \param interval Interval … … 30 35 QList<double> ticks[NTickTypes] ): 31 36 d_lowerBound( interval.minValue() ), 32 d_upperBound( interval.maxValue() ), 33 d_isValid( true ) 37 d_upperBound( interval.maxValue() ) 34 38 { 35 39 for ( int i = 0; i < NTickTypes; i++ ) … … 38 42 39 43 /*! 40 Construct QwtScaleDiv instance.41 42 \param lowerBound First interval limit43 \param upperBound Second interval limit44 Construct a scale division 45 46 \param lowerBound First boundary 47 \param upperBound Second boundary 44 48 \param ticks List of major, medium and minor ticks 45 */ 46 QwtScaleDiv::QwtScaleDiv( 47 double lowerBound, double upperBound, 49 50 \note lowerBound might be greater than upperBound for inverted scales 51 */ 52 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound, 48 53 QList<double> ticks[NTickTypes] ): 49 54 d_lowerBound( lowerBound ), 50 d_upperBound( upperBound ), 51 d_isValid( true ) 55 d_upperBound( upperBound ) 52 56 { 53 57 for ( int i = 0; i < NTickTypes; i++ ) … … 56 60 57 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 */ 72 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 */ 92 void QwtScaleDiv::setInterval( double lowerBound, double upperBound ) 93 { 94 d_lowerBound = lowerBound; 95 d_upperBound = upperBound; 96 } 97 98 /*! 58 99 Change the interval 100 59 101 \param interval Interval 60 102 */ 61 103 void QwtScaleDiv::setInterval( const QwtInterval &interval ) 62 104 { 63 setInterval( interval.minValue(), interval.maxValue() ); 105 d_lowerBound = interval.minValue(); 106 d_upperBound = interval.maxValue(); 107 } 108 109 /*! 110 \return lowerBound -> upperBound 111 */ 112 QwtInterval QwtScaleDiv::interval() const 113 { 114 return QwtInterval( d_lowerBound, d_upperBound ); 115 } 116 117 /*! 118 Set the first boundary 119 120 \param lowerBound First boundary 121 \sa lowerBiound(), setUpperBound() 122 */ 123 void QwtScaleDiv::setLowerBound( double lowerBound ) 124 { 125 d_lowerBound = lowerBound; 126 } 127 128 /*! 129 \return First boundary 130 \sa upperBound() 131 */ 132 double QwtScaleDiv::lowerBound() const 133 { 134 return d_lowerBound; 135 } 136 137 /*! 138 Set the second boundary 139 140 \param upperBound Second boundary 141 \sa upperBound(), setLowerBound() 142 */ 143 void QwtScaleDiv::setUpperBound( double upperBound ) 144 { 145 d_upperBound = upperBound; 146 } 147 148 /*! 149 \return upper bound 150 \sa lowerBound() 151 */ 152 double QwtScaleDiv::upperBound() const 153 { 154 return d_upperBound; 155 } 156 157 /*! 158 \return upperBound() - lowerBound() 159 */ 160 double QwtScaleDiv::range() const 161 { 162 return d_upperBound - d_lowerBound; 64 163 } 65 164 … … 71 170 { 72 171 if ( d_lowerBound != other.d_lowerBound || 73 d_upperBound != other.d_upperBound || 74 d_isValid != other.d_isValid ) 172 d_upperBound != other.d_upperBound ) 75 173 { 76 174 return false; … … 88 186 /*! 89 187 \brief Inequality 90 \return true if this instance is not equal to s 91 */ 92 bool QwtScaleDiv::operator!=( const QwtScaleDiv &s ) const 93 { 94 return ( !( *this == s ) ); 95 } 96 97 //! Invalidate the scale division 98 void QwtScaleDiv::invalidate() 99 { 100 d_isValid = false; 101 102 // detach arrays 103 for ( int i = 0; i < NTickTypes; i++ ) 104 d_ticks[i].clear(); 105 106 d_lowerBound = d_upperBound = 0; 107 } 108 109 //! Check if the scale division is valid 110 bool QwtScaleDiv::isValid() const 111 { 112 return d_isValid; 188 \return true if this instance is not equal to other 189 */ 190 bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const 191 { 192 return ( !( *this == other ) ); 193 } 194 195 //! Check if the scale division is empty( lowerBound() == upperBound() ) 196 bool QwtScaleDiv::isEmpty() const 197 { 198 return ( d_lowerBound == d_upperBound ); 199 } 200 201 //! Check if the scale division is increasing( lowerBound() <= upperBound() ) 202 bool QwtScaleDiv::isIncreasing() const 203 { 204 return d_lowerBound <= d_upperBound; 113 205 } 114 206 … … 121 213 bool QwtScaleDiv::contains( double value ) const 122 214 { 123 if ( !d_isValid )124 return false;125 126 215 const double min = qMin( d_lowerBound, d_upperBound ); 127 216 const double max = qMax( d_lowerBound, d_upperBound ); … … 130 219 } 131 220 132 //! Invert the scale divison 221 /*! 222 Invert the scale division 223 \sa inverted() 224 */ 133 225 void QwtScaleDiv::invert() 134 226 { … … 142 234 const int size2 = size / 2; 143 235 144 for ( int i = 0; i < size2; i++ )145 qSwap( ticks[ i], ticks[size - 1 - i] );236 for ( int j = 0; j < size2; j++ ) 237 qSwap( ticks[j], ticks[size - 1 - j] ); 146 238 } 239 } 240 241 /*! 242 \return A scale division with inverted boundaries and ticks 243 \sa invert() 244 */ 245 QwtScaleDiv QwtScaleDiv::inverted() const 246 { 247 QwtScaleDiv other = *this; 248 other.invert(); 249 250 return other; 251 } 252 253 /*! 254 Return a scale division with an interval [lowerBound, upperBound] 255 where all ticks outside this interval are removed 256 257 \param lowerBound Lower bound 258 \param upperBound Upper bound 259 260 \return Scale division with all ticks inside of the given interval 261 262 \note lowerBound might be greater than upperBound for inverted scales 263 */ 264 QwtScaleDiv QwtScaleDiv::bounded( 265 double lowerBound, double upperBound ) const 266 { 267 const double min = qMin( lowerBound, upperBound ); 268 const double max = qMax( lowerBound, upperBound ); 269 270 QwtScaleDiv sd; 271 sd.setInterval( lowerBound, upperBound ); 272 273 for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ ) 274 { 275 const QList<double> &ticks = d_ticks[ tickType ]; 276 277 QList<double> boundedTicks; 278 for ( int i = 0; i < ticks.size(); i++ ) 279 { 280 const double tick = ticks[i]; 281 if ( tick >= min && tick <= max ) 282 boundedTicks += tick; 283 } 284 285 sd.setTicks( tickType, boundedTicks ); 286 } 287 288 return sd; 289 147 290 } 148 291 … … 155 298 void QwtScaleDiv::setTicks( int type, const QList<double> &ticks ) 156 299 { 157 if ( type >= 0 ||type < NTickTypes )300 if ( type >= 0 && type < NTickTypes ) 158 301 d_ticks[type] = ticks; 159 302 } … … 163 306 164 307 \param type MinorTick, MediumTick or MajorTick 165 */ 166 const QList<double> &QwtScaleDiv::ticks( int type ) const 167 { 168 if ( type >= 0 || type < NTickTypes ) 308 \return Tick list 309 */ 310 QList<double> QwtScaleDiv::ticks( int type ) const 311 { 312 if ( type >= 0 && type < NTickTypes ) 169 313 return d_ticks[type]; 170 314 171 static QList<double> noTicks; 172 return noTicks; 173 } 315 return QList<double>(); 316 } 317 318 #ifndef QT_NO_DEBUG_STREAM 319 320 QDebug operator<<( QDebug debug, const QwtScaleDiv &scaleDiv ) 321 { 322 debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound(); 323 debug << "Major: " << scaleDiv.ticks( QwtScaleDiv::MajorTick ); 324 debug << "Medium: " << scaleDiv.ticks( QwtScaleDiv::MediumTick ); 325 debug << "Minor: " << scaleDiv.ticks( QwtScaleDiv::MinorTick ); 326 327 return debug; 328 } 329 330 #endif 331 -
trunk/BNC/qwt/qwt_scale_div.h
r4271 r8127 15 15 #include <qlist.h> 16 16 17 class QwtInterval; 17 #ifndef QT_NO_DEBUG_STREAM 18 #include <qdebug.h> 19 #endif 18 20 19 21 /*! 20 22 \brief A class representing a scale division 21 23 22 A scale division consists of its limits and 3 list23 of tick values qualified asmajor, medium and minor ticks.24 A Qwt scale is defined by its boundaries and 3 list 25 for the positions of the major, medium and minor ticks. 24 26 25 In most cases scale divisions are calculated by a QwtScaleEngine. 27 The upperBound() might be smaller than the lowerBound() 28 to indicate inverted scales. 26 29 27 \sa subDivideInto(), subDivide() 30 Scale divisions can be calculated from a QwtScaleEngine. 31 32 \sa QwtScaleEngine::divideScale(), QwtPlot::setAxisScaleDiv(), 33 QwtAbstractSlider::setScaleDiv() 28 34 */ 29 35 … … 50 56 }; 51 57 52 explicit QwtScaleDiv(); 58 explicit QwtScaleDiv( double lowerBound = 0.0, 59 double upperBound = 0.0 ); 60 53 61 explicit QwtScaleDiv( const QwtInterval &, QList<double>[NTickTypes] ); 54 explicit QwtScaleDiv(55 double lowerBound, double upperBound, QList<double>[NTickTypes] );56 62 57 bool operator==( const QwtScaleDiv &s ) const; 58 bool operator!=( const QwtScaleDiv &s ) const; 63 explicit QwtScaleDiv( double lowerBound, double upperBound, 64 QList<double>[NTickTypes] ); 65 66 explicit QwtScaleDiv( double lowerBound, double upperBound, 67 const QList<double> &minorTicks, const QList<double> &mediumTicks, 68 const QList<double> &majorTicks ); 69 70 bool operator==( const QwtScaleDiv & ) const; 71 bool operator!=( const QwtScaleDiv & ) const; 59 72 60 73 void setInterval( double lowerBound, double upperBound ); … … 62 75 QwtInterval interval() const; 63 76 77 void setLowerBound( double ); 64 78 double lowerBound() const; 79 80 void setUpperBound( double ); 65 81 double upperBound() const; 82 66 83 double range() const; 67 84 68 bool contains( double v ) const;85 bool contains( double value ) const; 69 86 70 void setTicks( int t ype, const QList<double> & );71 const QList<double> &ticks( int type ) const;87 void setTicks( int tickType, const QList<double> & ); 88 QList<double> ticks( int tickType ) const; 72 89 73 void invalidate();74 bool is Valid() const;90 bool isEmpty() const; 91 bool isIncreasing() const; 75 92 76 93 void invert(); 94 QwtScaleDiv inverted() const; 95 96 QwtScaleDiv bounded( double lowerBound, double upperBound ) const; 77 97 78 98 private: … … 80 100 double d_upperBound; 81 101 QList<double> d_ticks[NTickTypes]; 82 83 bool d_isValid;84 102 }; 85 103 86 Q_DECLARE_TYPEINFO( QwtScaleDiv, Q_MOVABLE_TYPE);104 Q_DECLARE_TYPEINFO( QwtScaleDiv, Q_MOVABLE_TYPE ); 87 105 88 /*! 89 Change the interval 90 \param lowerBound lower bound 91 \param upperBound upper bound 92 */ 93 inline void QwtScaleDiv::setInterval( double lowerBound, double upperBound ) 94 { 95 d_lowerBound = lowerBound; 96 d_upperBound = upperBound; 97 } 106 #ifndef QT_NO_DEBUG_STREAM 107 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleDiv & ); 108 #endif 98 109 99 /*!100 \return lowerBound -> upperBound101 */102 inline QwtInterval QwtScaleDiv::interval() const103 {104 return QwtInterval( d_lowerBound, d_upperBound );105 }106 107 /*!108 \return lower bound109 \sa upperBound()110 */111 inline double QwtScaleDiv::lowerBound() const112 {113 return d_lowerBound;114 }115 116 /*!117 \return upper bound118 \sa lowerBound()119 */120 inline double QwtScaleDiv::upperBound() const121 {122 return d_upperBound;123 }124 125 /*!126 \return upperBound() - lowerBound()127 */128 inline double QwtScaleDiv::range() const129 {130 return d_upperBound - d_lowerBound;131 }132 110 #endif -
trunk/BNC/qwt/qwt_scale_draw.cpp
r4271 r8127 17 17 #include <qmath.h> 18 18 19 #if QT_VERSION < 0x040601 20 #define qFastSin(x) qSin(x) 21 #define qFastCos(x) qCos(x) 22 #endif 23 19 24 class QwtScaleDraw::PrivateData 20 25 { … … 59 64 Return alignment of the scale 60 65 \sa setAlignment() 66 \return Alignment of the scale 61 67 */ 62 68 QwtScaleDraw::Alignment QwtScaleDraw::alignment() const … … 67 73 /*! 68 74 Set the alignment of the scale 75 76 \param align Alignment of the scale 69 77 70 78 The default alignment is QwtScaleDraw::BottomScale … … 81 89 TopScale, BottomScale are horizontal (Qt::Horizontal) scales, 82 90 LeftScale, RightScale are vertical (Qt::Vertical) scales. 91 92 \return Orientation of the scale 83 93 84 94 \sa alignment() … … 108 118 \param end End border distance 109 119 */ 110 void QwtScaleDraw::getBorderDistHint( const QFont &font,111 120 void QwtScaleDraw::getBorderDistHint( 121 const QFont &font, int &start, int &end ) const 112 122 { 113 123 start = 0; 114 end = 0;124 end = 1.0; 115 125 116 126 if ( !hasComponent( QwtAbstractScaleDraw::Labels ) ) … … 189 199 190 200 const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); 191 if ( ticks. count() == 0)201 if ( ticks.isEmpty() ) 192 202 return 0; 193 203 … … 200 210 if ( vertical ) 201 211 { 202 bRect2.setRect( -bRect2.bottom(), 0, bRect2.height(), bRect2.width() ); 203 } 204 int maxDist = 0; 212 bRect2.setRect( -bRect2.bottom(), 0.0, bRect2.height(), bRect2.width() ); 213 } 214 215 double maxDist = 0.0; 205 216 206 217 for ( int i = 1; i < ticks.count(); i++ ) … … 210 221 if ( vertical ) 211 222 { 212 bRect2.setRect( -bRect2.bottom(), 0 ,223 bRect2.setRect( -bRect2.bottom(), 0.0, 213 224 bRect2.height(), bRect2.width() ); 214 225 } 215 226 216 intdist = fm.leading(); // space between the labels227 double dist = fm.leading(); // space between the labels 217 228 if ( bRect1.right() > 0 ) 218 229 dist += bRect1.right(); … … 224 235 } 225 236 226 double angle = labelRotation() / 180.0 * M_PI;237 double angle = qwtRadians( labelRotation() ); 227 238 if ( vertical ) 228 239 angle += M_PI / 2; 229 240 230 if ( qSin( angle ) == 0.0 ) 231 return maxDist; 241 const double sinA = qFastSin( angle ); // qreal -> double 242 if ( qFuzzyCompare( sinA + 1.0, 1.0 ) ) 243 return qCeil( maxDist ); 232 244 233 245 const int fmHeight = fm.ascent() - 2; … … 235 247 // The distance we need until there is 236 248 // the height of the label font. This height is needed 237 // for the neighbo ur labal.238 239 int labelDist = qFloor( fmHeight / qSin( angle ) * qCos( angle ));249 // for the neighbored label. 250 251 double labelDist = fmHeight / qFastSin( angle ) * qFastCos( angle ); 240 252 if ( labelDist < 0 ) 241 253 labelDist = -labelDist; 242 254 243 // The cast above floored labelDist. We want to ceil.244 labelDist++;245 246 255 // For text orientations close to the scale orientation 247 256 … … 255 264 labelDist = fmHeight; 256 265 257 return labelDist;266 return qCeil( labelDist ); 258 267 } 259 268 … … 267 276 268 277 \param font Font used for painting the labels 278 \return Extent 269 279 270 280 \sa minLength() … … 292 302 if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) 293 303 { 294 const double pw = qMax( 1, penWidth() ); // pen width can be zero304 const double pw = qMax( 1, penWidth() ); // pen width can be zero 295 305 d += pw; 296 306 } … … 304 314 305 315 \param font Font used for painting the labels 316 \return Minimum length that is needed to draw the scale 306 317 307 318 \sa extent() … … 337 348 Find the position, where to paint a label 338 349 339 The position has a distance of majTickLength() + spacing() + 1340 from the backbone. The direction depends on the alignment()350 The position has a distance that depends on the length of the ticks 351 in direction of the alignment(). 341 352 342 353 \param value Value 354 \return Position, where to paint a label 343 355 */ 344 356 QPointF QwtScaleDraw::labelPosition( double value ) const … … 391 403 \param painter Painter 392 404 \param value Value of the tick 393 \param len Leng htof the tick405 \param len Length of the tick 394 406 395 407 \sa drawBackbone(), drawLabel() … … 597 609 overlapping labels. 598 610 611 \param length Length of the backbone 612 599 613 \sa move(), minLabelDist() 600 614 */ 601 615 void QwtScaleDraw::setLength( double length ) 602 616 { 617 #if 1 603 618 if ( length >= 0 && length < 10 ) 604 619 length = 10; 620 621 // why should we accept negative lengths ??? 605 622 if ( length < 0 && length > -10 ) 606 623 length = -10; 624 #else 625 length = qMax( length, 10 ); 626 #endif 607 627 608 628 d_data->len = length; … … 648 668 649 669 /*! 650 Find the bounding rect for the label. The coordinates of 651 the rect are absolute coordinates ( calculated from pos() ). 670 \brief Find the bounding rectangle for the label. 671 672 The coordinates of the rectangle are absolute ( calculated from pos() ). 652 673 in direction of the tick. 653 674 … … 655 676 \param value Value 656 677 678 \return Bounding rectangle 657 679 \sa labelRect() 658 680 */ … … 677 699 \param size Size of the label 678 700 701 \return Transformation matrix 679 702 \sa setLabelAlignment(), setLabelRotation() 680 703 */ … … 740 763 741 764 /*! 742 Find the bounding rect for the label. The coordinates of743 the rect are relative to spacing + ticklength from the backbone765 Find the bounding rectangle for the label. The coordinates of 766 the rectangle are relative to spacing + tick length from the backbone 744 767 in direction of the tick. 745 768 746 769 \param font Font used for painting 747 770 \param value Value 771 772 \return Bounding rectangle that is needed to draw a label 748 773 */ 749 774 QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const … … 769 794 \param font Label font 770 795 \param value Value 796 797 \return Size that is needed to draw a label 771 798 */ 772 799 QSizeF QwtScaleDraw::labelSize( const QFont &font, double value ) const … … 805 832 \brief Change the label flags 806 833 807 Labels are aligned to the point tick length + spacing away from the backbone.834 Labels are aligned to the point tick length + spacing away from the backbone. 808 835 809 836 The alignment is relative to the orientation of the label text. … … 824 851 The alignment of the label is not the alignment 825 852 of the scale and is not the alignment of the flags 826 ( QwtText::flags()) returned from QwtAbstractScaleDraw::label().853 ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label(). 827 854 */ 828 855 … … 847 874 int QwtScaleDraw::maxLabelWidth( const QFont &font ) const 848 875 { 849 int maxWidth =0;876 double maxWidth = 0.0; 850 877 851 878 const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); … … 855 882 if ( scaleDiv().contains( v ) ) 856 883 { 857 const intw = labelSize( font, ticks[i] ).width();884 const double w = labelSize( font, ticks[i] ).width(); 858 885 if ( w > maxWidth ) 859 886 maxWidth = w; … … 861 888 } 862 889 863 return maxWidth;890 return qCeil( maxWidth ); 864 891 } 865 892 … … 870 897 int QwtScaleDraw::maxLabelHeight( const QFont &font ) const 871 898 { 872 int maxHeight =0;899 double maxHeight = 0.0; 873 900 874 901 const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); … … 878 905 if ( scaleDiv().contains( v ) ) 879 906 { 880 const inth = labelSize( font, ticks[i] ).height();907 const double h = labelSize( font, ticks[i] ).height(); 881 908 if ( h > maxHeight ) 882 909 maxHeight = h; … … 884 911 } 885 912 886 return maxHeight;913 return qCeil( maxHeight ); 887 914 } 888 915 -
trunk/BNC/qwt/qwt_scale_draw.h
r4271 r8127 29 29 the scale can be drawn with the QwtAbstractScaleDraw::draw() member. 30 30 */ 31 32 31 class QWT_EXPORT QwtScaleDraw: public QwtAbstractScaleDraw 33 32 { … … 108 107 /*! 109 108 Move the position of the scale 109 110 \param x X coordinate 111 \param y Y coordinate 112 110 113 \sa move(const QPointF &) 111 114 */ -
trunk/BNC/qwt/qwt_scale_engine.cpp
r4271 r8127 13 13 #include <qalgorithms.h> 14 14 #include <qmath.h> 15 #include <float.h> 16 #include <limits> 15 17 16 18 #if QT_VERSION < 0x040601 … … 19 21 #endif 20 22 23 static inline double qwtLog( double base, double value ) 24 { 25 return log( value ) / log( base ); 26 } 27 28 static inline QwtInterval qwtLogInterval( double base, const QwtInterval &interval ) 29 { 30 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() ); 47 } 48 49 #if 1 50 51 // this version often doesn't find the best ticks: f.e for 15: 5, 10 52 static double qwtStepSize( double intervalSize, int maxSteps, uint base ) 53 { 54 const double minStep = 55 QwtScaleArithmetic::divideInterval( intervalSize, maxSteps, base ); 56 57 if ( minStep != 0.0 ) 58 { 59 // # ticks per interval 60 const int numTicks = qCeil( qAbs( intervalSize / minStep ) ) - 1; 61 62 // Do the minor steps fit into the interval? 63 if ( qwtFuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ), 64 qAbs( intervalSize ), intervalSize ) > 0 ) 65 { 66 // The minor steps doesn't fit into the interval 67 return 0.5 * intervalSize; 68 } 69 } 70 71 return minStep; 72 } 73 74 #else 75 76 static double qwtStepSize( double intervalSize, int maxSteps, uint base ) 77 { 78 if ( maxSteps <= 0 ) 79 return 0.0; 80 81 if ( maxSteps > 2 ) 82 { 83 for ( int numSteps = maxSteps; numSteps > 1; numSteps-- ) 84 { 85 const double stepSize = intervalSize / numSteps; 86 87 const double p = ::floor( ::log( stepSize ) / ::log( base ) ); 88 const double fraction = qPow( base, p ); 89 90 for ( uint n = base; n > 1; n /= 2 ) 91 { 92 if ( qFuzzyCompare( stepSize, n * fraction ) ) 93 return stepSize; 94 95 if ( n == 3 && ( base % 2 ) == 0 ) 96 { 97 if ( qFuzzyCompare( stepSize, 2 * fraction ) ) 98 return stepSize; 99 } 100 } 101 } 102 } 103 104 return intervalSize * 0.5; 105 } 106 107 #endif 108 21 109 static const double _eps = 1.0e-6; 22 110 … … 24 112 Ceil a value, relative to an interval 25 113 26 \param value Value to ceil114 \param value Value to be ceiled 27 115 \param intervalSize Interval size 116 117 \return Rounded value 28 118 29 119 \sa floorEps() … … 35 125 36 126 value = ( value - eps ) / intervalSize; 37 return qwtCeilF( value ) * intervalSize;127 return ::ceil( value ) * intervalSize; 38 128 } 39 129 … … 41 131 Floor a value, relative to an interval 42 132 43 \param value Value to floor133 \param value Value to be floored 44 134 \param intervalSize Interval size 45 135 136 \return Rounded value 46 137 \sa floorEps() 47 138 */ … … 51 142 52 143 value = ( value + eps ) / intervalSize; 53 return qwtFloorF( value ) * intervalSize;144 return ::floor( value ) * intervalSize; 54 145 } 55 146 … … 72 163 73 164 /*! 74 Find the smallest value out of {1,2,5}*10^n with an integer number n 75 which is greater than or equal to x 76 77 \param x Input value 78 */ 79 double QwtScaleArithmetic::ceil125( double x ) 80 { 81 if ( x == 0.0 ) 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 172 */ 173 double QwtScaleArithmetic::divideInterval( 174 double intervalSize, int numSteps, uint base ) 175 { 176 if ( numSteps <= 0 ) 82 177 return 0.0; 83 178 84 const double sign = ( x > 0 ) ? 1.0 : -1.0; 85 const double lx = ::log10( qFabs( x ) ); 86 const double p10 = qwtFloorF( lx ); 87 88 double fr = qPow( 10.0, lx - p10 ); 89 if ( fr <= 1.0 ) 90 fr = 1.0; 91 else if ( fr <= 2.0 ) 92 fr = 2.0; 93 else if ( fr <= 5.0 ) 94 fr = 5.0; 95 else 96 fr = 10.0; 97 98 return sign * fr * qPow( 10.0, p10 ); 99 } 100 101 /*! 102 \brief Find the largest value out of {1,2,5}*10^n with an integer number n 103 which is smaller than or equal to x 104 105 \param x Input value 106 */ 107 double QwtScaleArithmetic::floor125( double x ) 108 { 109 if ( x == 0.0 ) 179 const double v = QwtScaleArithmetic::divideEps( intervalSize, numSteps ); 180 if ( v == 0.0 ) 110 181 return 0.0; 111 182 112 double sign = ( x > 0 ) ? 1.0 : -1.0; 113 const double lx = ::log10( qFabs( x ) ); 114 const double p10 = qwtFloorF( lx ); 115 116 double fr = qPow( 10.0, lx - p10 ); 117 if ( fr >= 10.0 ) 118 fr = 10.0; 119 else if ( fr >= 5.0 ) 120 fr = 5.0; 121 else if ( fr >= 2.0 ) 122 fr = 2.0; 123 else 124 fr = 1.0; 125 126 return sign * fr * qPow( 10.0, p10 ); 183 const double lx = qwtLog( base, qFabs( v ) ); 184 const double p = ::floor( lx ); 185 186 const double fraction = qPow( base, lx - p ); 187 188 uint n = base; 189 while ( ( n > 1 ) && ( fraction <= n / 2 ) ) 190 n /= 2; 191 192 double stepSize = n * qPow( base, p ); 193 if ( v < 0 ) 194 stepSize = -stepSize; 195 196 return stepSize; 127 197 } 128 198 … … 134 204 lowerMargin( 0.0 ), 135 205 upperMargin( 0.0 ), 136 referenceValue( 0.0 ) 137 { 138 } 139 140 QwtScaleEngine::Attributes attributes; // scale attributes 141 142 double lowerMargin; // margins 206 referenceValue( 0.0 ), 207 base( 10 ), 208 transform( NULL ) 209 { 210 } 211 212 ~PrivateData() 213 { 214 delete transform; 215 } 216 217 QwtScaleEngine::Attributes attributes; 218 219 double lowerMargin; 143 220 double upperMargin; 144 221 145 double referenceValue; // reference value 146 222 double referenceValue; 223 224 uint base; 225 226 QwtTransform* transform; 147 227 }; 148 228 149 //! Constructor 150 QwtScaleEngine::QwtScaleEngine() 229 /*! 230 Constructor 231 232 \param base Base of the scale engine 233 \sa setBase() 234 */ 235 QwtScaleEngine::QwtScaleEngine( uint base ) 151 236 { 152 237 d_data = new PrivateData; 238 setBase( base ); 153 239 } 154 240 … … 158 244 { 159 245 delete d_data; 246 } 247 248 /*! 249 Assign a transformation 250 251 \param transform Transformation 252 253 The transformation object is used as factory for clones 254 that are returned by transformation() 255 256 The scale engine takes ownership of the transformation. 257 258 \sa QwtTransform::copy(), transformation() 259 260 */ 261 void QwtScaleEngine::setTransformation( QwtTransform *transform ) 262 { 263 if ( transform != d_data->transform ) 264 { 265 delete d_data->transform; 266 d_data->transform = transform; 267 } 268 } 269 270 /*! 271 Create and return a clone of the transformation 272 of the engine. When the engine has no special transformation 273 NULL is returned, indicating no transformation. 274 275 \return A clone of the transfomation 276 \sa setTransformation() 277 */ 278 QwtTransform *QwtScaleEngine::transformation() const 279 { 280 QwtTransform *transform = NULL; 281 if ( d_data->transform ) 282 transform = d_data->transform->copy(); 283 284 return transform; 160 285 } 161 286 … … 193 318 194 319 \warning 195 \li QwtLog 10ScaleEngine measures the margins in decades.320 \li QwtLogScaleEngine measures the margins in decades. 196 321 197 322 \sa upperMargin(), lowerMargin() … … 215 340 double intervalSize, int numSteps ) const 216 341 { 217 if ( numSteps <= 0 ) 218 return 0.0; 219 220 double v = QwtScaleArithmetic::divideEps( intervalSize, numSteps ); 221 return QwtScaleArithmetic::ceil125( v ); 342 return QwtScaleArithmetic::divideInterval( 343 intervalSize, numSteps, d_data->base ); 222 344 } 223 345 … … 228 350 \param value Value 229 351 230 \ sa QwtScaleArithmetic::compareEps()352 \return True, when the value is inside the interval 231 353 */ 232 354 bool QwtScaleEngine::contains( … … 275 397 276 398 /*! 277 \brief Build an interval fora value399 \brief Build an interval around a value 278 400 279 401 In case of v == 0.0 the interval is [-0.5, 0.5], 280 402 otherwide it is [0.5 * v, 1.5 * v] 281 */ 282 283 QwtInterval QwtScaleEngine::buildInterval( double v ) const 284 { 285 const double delta = ( v == 0.0 ) ? 0.5 : qAbs( 0.5 * v ); 286 return QwtInterval( v - delta, v + delta ); 403 404 \param value Initial value 405 \return Calculated interval 406 */ 407 408 QwtInterval QwtScaleEngine::buildInterval( double value ) const 409 { 410 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 ); 417 418 return QwtInterval( value - delta, value + delta ); 287 419 } 288 420 … … 304 436 305 437 /*! 306 Check if a attribute is set.438 \return True, if attribute is enabled. 307 439 308 440 \param attribute Attribute to be tested … … 326 458 327 459 /*! 328 Return the scale attributes460 \return Scale attributes 329 461 \sa Attribute, setAttributes(), testAttribute() 330 462 */ … … 349 481 350 482 /*! 351 \return the reference value352 \sa setReference(), setAttribute()483 \return the reference value 484 \sa setReference(), setAttribute() 353 485 */ 354 486 double QwtScaleEngine::reference() const … … 358 490 359 491 /*! 360 Return a transformation, for linear scales 361 */ 362 QwtScaleTransformation *QwtLinearScaleEngine::transformation() const 363 { 364 return new QwtScaleTransformation( QwtScaleTransformation::Linear ); 365 } 366 367 /*! 368 Align and divide an interval 369 370 \param maxNumSteps Max. number of steps 371 \param x1 First limit of the interval (In/Out) 372 \param x2 Second limit of the interval (In/Out) 373 \param stepSize Step size (Out) 374 375 \sa setAttribute() 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() 502 */ 503 void QwtScaleEngine::setBase( uint base ) 504 { 505 d_data->base = qMax( base, 2U ); 506 } 507 508 /*! 509 \return base Base of the scale engine 510 \sa setBase() 511 */ 512 uint QwtScaleEngine::base() const 513 { 514 return d_data->base; 515 } 516 517 /*! 518 Constructor 519 520 \param base Base of the scale engine 521 \sa setBase() 522 */ 523 QwtLinearScaleEngine::QwtLinearScaleEngine( uint base ): 524 QwtScaleEngine( base ) 525 { 526 } 527 528 //! Destructor 529 QwtLinearScaleEngine::~QwtLinearScaleEngine() 530 { 531 } 532 533 /*! 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() 376 542 */ 377 543 void QwtLinearScaleEngine::autoScale( int maxNumSteps, … … 393 559 interval = buildInterval( interval.minValue() ); 394 560 395 stepSize = divideInterval( interval.width(), qMax( maxNumSteps, 1 ) ); 561 stepSize = QwtScaleArithmetic::divideInterval( 562 interval.width(), qMax( maxNumSteps, 1 ), base() ); 396 563 397 564 if ( !testAttribute( QwtScaleEngine::Floating ) ) … … 409 576 410 577 /*! 411 \brief Calculate a scale division 578 \brief Calculate a scale division for an interval 412 579 413 580 \param x1 First interval limit 414 581 \param x2 Second interval limit 415 \param maxMaj Steps Maximum for the number of major steps416 \param maxMin Steps Maximum number of minor steps417 \param stepSize Step size. If stepSize == 0, the scaleEngine582 \param maxMajorSteps Maximum for the number of major steps 583 \param maxMinorSteps Maximum number of minor steps 584 \param stepSize Step size. If stepSize == 0, the engine 418 585 calculates one. 419 586 420 \ sa QwtScaleEngine::stepSize(), QwtScaleEngine::subDivide()587 \return Calculated scale division 421 588 */ 422 589 QwtScaleDiv QwtLinearScaleEngine::divideScale( double x1, double x2, 423 int maxMaj Steps, int maxMinSteps, double stepSize ) const590 int maxMajorSteps, int maxMinorSteps, double stepSize ) const 424 591 { 425 592 QwtInterval interval = QwtInterval( x1, x2 ).normalized(); 593 594 if ( qwtIntervalWidthL( interval ) > std::numeric_limits<double>::max() ) 595 { 596 qWarning() << "QwtLinearScaleEngine::divideScale: overflow"; 597 return QwtScaleDiv(); 598 } 599 426 600 if ( interval.width() <= 0 ) 427 601 return QwtScaleDiv(); … … 430 604 if ( stepSize == 0.0 ) 431 605 { 432 if ( maxMajSteps < 1 ) 433 maxMajSteps = 1; 434 435 stepSize = divideInterval( interval.width(), maxMajSteps ); 606 if ( maxMajorSteps < 1 ) 607 maxMajorSteps = 1; 608 609 stepSize = QwtScaleArithmetic::divideInterval( 610 interval.width(), maxMajorSteps, base() ); 436 611 } 437 612 … … 441 616 { 442 617 QList<double> ticks[QwtScaleDiv::NTickTypes]; 443 buildTicks( interval, stepSize, maxMin Steps, ticks );618 buildTicks( interval, stepSize, maxMinorSteps, ticks ); 444 619 445 620 scaleDiv = QwtScaleDiv( interval, ticks ); … … 457 632 \param interval Interval 458 633 \param stepSize Step size 459 \param maxMin Steps Maximum number of minor steps634 \param maxMinorSteps Maximum number of minor steps 460 635 \param ticks Arrays to be filled with the calculated ticks 461 636 … … 463 638 */ 464 639 void QwtLinearScaleEngine::buildTicks( 465 const QwtInterval& interval, double stepSize, int maxMin Steps,640 const QwtInterval& interval, double stepSize, int maxMinorSteps, 466 641 QList<double> ticks[QwtScaleDiv::NTickTypes] ) const 467 642 { 468 const QwtInterval boundingInterval = 469 align( interval, stepSize ); 643 const QwtInterval boundingInterval = align( interval, stepSize ); 470 644 471 645 ticks[QwtScaleDiv::MajorTick] = 472 646 buildMajorTicks( boundingInterval, stepSize ); 473 647 474 if ( maxMin Steps > 0 )475 { 476 buildMinorTicks( ticks[QwtScaleDiv::MajorTick], maxMin Steps, stepSize,648 if ( maxMinorSteps > 0 ) 649 { 650 buildMinorTicks( ticks[QwtScaleDiv::MajorTick], maxMinorSteps, stepSize, 477 651 ticks[QwtScaleDiv::MinorTick], ticks[QwtScaleDiv::MediumTick] ); 478 652 } … … 522 696 523 697 \param majorTicks Major ticks 524 \param maxMin Steps Maximum number of minor steps698 \param maxMinorSteps Maximum number of minor steps 525 699 \param stepSize Step size 526 700 \param minorTicks Array to be filled with the calculated minor ticks … … 530 704 void QwtLinearScaleEngine::buildMinorTicks( 531 705 const QList<double>& majorTicks, 532 int maxMin Steps, double stepSize,706 int maxMinorSteps, double stepSize, 533 707 QList<double> &minorTicks, 534 708 QList<double> &mediumTicks ) const 535 709 { 536 double minStep = divideInterval( stepSize, maxMinSteps);710 double minStep = qwtStepSize( stepSize, maxMinorSteps, base() ); 537 711 if ( minStep == 0.0 ) 538 712 return; 539 713 540 714 // # ticks per interval 541 int numTicks = qCeil( qAbs( stepSize / minStep ) ) - 1; 542 543 // Do the minor steps fit into the interval? 544 if ( qwtFuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ), 545 qAbs( stepSize ), stepSize ) > 0 ) 546 { 547 numTicks = 1; 548 minStep = stepSize * 0.5; 549 } 715 const int numTicks = qCeil( qAbs( stepSize / minStep ) ) - 1; 550 716 551 717 int medIndex = -1; … … 588 754 const QwtInterval &interval, double stepSize ) const 589 755 { 590 double x1 = QwtScaleArithmetic::floorEps( interval.minValue(), stepSize ); 591 if ( qwtFuzzyCompare( interval.minValue(), x1, stepSize ) == 0 ) 592 x1 = interval.minValue(); 593 594 double x2 = QwtScaleArithmetic::ceilEps( interval.maxValue(), stepSize ); 595 if ( qwtFuzzyCompare( interval.maxValue(), x2, stepSize ) == 0 ) 596 x2 = interval.maxValue(); 756 double x1 = interval.minValue(); 757 double x2 = interval.maxValue(); 758 759 // when there is no rounding beside some effect, when 760 // calculating with doubles, we keep the original value 761 762 const double eps = 0.000000000001; // since Qt 4.8: qFuzzyIsNull 763 if ( -DBL_MAX + stepSize <= x1 ) 764 { 765 const double x = QwtScaleArithmetic::floorEps( x1, stepSize ); 766 if ( qAbs(x) <= eps || !qFuzzyCompare( x1, x ) ) 767 x1 = x; 768 } 769 770 if ( DBL_MAX - stepSize >= x2 ) 771 { 772 const double x = QwtScaleArithmetic::ceilEps( x2, stepSize ); 773 if ( qAbs(x) <= eps || !qFuzzyCompare( x2, x ) ) 774 x2 = x; 775 } 597 776 598 777 return QwtInterval( x1, x2 ); … … 600 779 601 780 /*! 602 Return a transformation, for logarithmic (base 10) scales 603 */ 604 QwtScaleTransformation *QwtLog10ScaleEngine::transformation() const 605 { 606 return new QwtScaleTransformation( QwtScaleTransformation::Log10 ); 781 Constructor 782 783 \param base Base of the scale engine 784 \sa setBase() 785 */ 786 QwtLogScaleEngine::QwtLogScaleEngine( uint base ): 787 QwtScaleEngine( base ) 788 { 789 setTransformation( new QwtLogTransform() ); 790 } 791 792 //! Destructor 793 QwtLogScaleEngine::~QwtLogScaleEngine() 794 { 607 795 } 608 796 … … 617 805 \sa QwtScaleEngine::setAttribute() 618 806 */ 619 void QwtLog 10ScaleEngine::autoScale( int maxNumSteps,620 807 void QwtLogScaleEngine::autoScale( int maxNumSteps, 808 double &x1, double &x2, double &stepSize ) const 621 809 { 622 810 if ( x1 > x2 ) 623 811 qSwap( x1, x2 ); 624 812 625 QwtInterval interval( x1 / qPow( 10.0, lowerMargin() ), 626 x2 * qPow( 10.0, upperMargin() ) ); 627 628 if ( interval.maxValue() / interval.minValue() < 10.0 ) 629 { 630 // scale width is less than one decade -> build linear scale 813 const double logBase = base(); 814 815 QwtInterval interval( x1 / qPow( logBase, lowerMargin() ), 816 x2 * qPow( logBase, upperMargin() ) ); 817 818 if ( interval.maxValue() / interval.minValue() < logBase ) 819 { 820 // scale width is less than one step -> try to build a linear scale 631 821 632 822 QwtLinearScaleEngine linearScaler; … … 636 826 637 827 linearScaler.autoScale( maxNumSteps, x1, x2, stepSize ); 638 stepSize = ::log10( stepSize ); 639 640 return; 828 829 QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized(); 830 linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX ); 831 832 if ( linearInterval.maxValue() / linearInterval.minValue() < logBase ) 833 { 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 847 return; 848 } 641 849 } 642 850 … … 660 868 interval = buildInterval( interval.minValue() ); 661 869 662 stepSize = divideInterval( log10( interval ).width(), qMax( maxNumSteps, 1 ) ); 870 stepSize = divideInterval( qwtLogInterval( logBase, interval ).width(), 871 qMax( maxNumSteps, 1 ) ); 663 872 if ( stepSize < 1.0 ) 664 873 stepSize = 1.0; … … 678 887 679 888 /*! 680 \brief Calculate a scale division 889 \brief Calculate a scale division for an interval 681 890 682 891 \param x1 First interval limit 683 892 \param x2 Second interval limit 684 \param maxMaj Steps Maximum for the number of major steps685 \param maxMin Steps Maximum number of minor steps686 \param stepSize Step size. If stepSize == 0, the scaleEngine893 \param maxMajorSteps Maximum for the number of major steps 894 \param maxMinorSteps Maximum number of minor steps 895 \param stepSize Step size. If stepSize == 0, the engine 687 896 calculates one. 688 897 689 \ sa QwtScaleEngine::stepSize(), QwtLog10ScaleEngine::subDivide()690 */ 691 QwtScaleDiv QwtLog 10ScaleEngine::divideScale( double x1, double x2,692 int maxMaj Steps, int maxMinSteps, double stepSize ) const898 \return Calculated scale division 899 */ 900 QwtScaleDiv QwtLogScaleEngine::divideScale( double x1, double x2, 901 int maxMajorSteps, int maxMinorSteps, double stepSize ) const 693 902 { 694 903 QwtInterval interval = QwtInterval( x1, x2 ).normalized(); … … 698 907 return QwtScaleDiv(); 699 908 700 if ( interval.maxValue() / interval.minValue() < 10.0 ) 909 const double logBase = base(); 910 911 if ( interval.maxValue() / interval.minValue() < logBase ) 701 912 { 702 913 // scale width is less than one decade -> build linear scale … … 707 918 linearScaler.setMargins( lowerMargin(), upperMargin() ); 708 919 709 if ( stepSize != 0.0 )710 stepSize = qPow( 10.0, stepSize );711 712 920 return linearScaler.divideScale( x1, x2, 713 maxMaj Steps, maxMinSteps, stepSize);921 maxMajorSteps, maxMinorSteps, 0.0 ); 714 922 } 715 923 … … 717 925 if ( stepSize == 0.0 ) 718 926 { 719 if ( maxMajSteps < 1 ) 720 maxMajSteps = 1; 721 722 stepSize = divideInterval( log10( interval ).width(), maxMajSteps ); 927 if ( maxMajorSteps < 1 ) 928 maxMajorSteps = 1; 929 930 stepSize = divideInterval( 931 qwtLogInterval( logBase, interval ).width(), maxMajorSteps ); 723 932 if ( stepSize < 1.0 ) 724 933 stepSize = 1.0; // major step must be >= 1 decade … … 729 938 { 730 939 QList<double> ticks[QwtScaleDiv::NTickTypes]; 731 buildTicks( interval, stepSize, maxMin Steps, ticks );940 buildTicks( interval, stepSize, maxMinorSteps, ticks ); 732 941 733 942 scaleDiv = QwtScaleDiv( interval, ticks ); … … 744 953 745 954 \param interval Interval 746 \param maxMin Steps Maximum number of minor steps955 \param maxMinorSteps Maximum number of minor steps 747 956 \param stepSize Step size 748 957 \param ticks Arrays to be filled with the calculated ticks … … 750 959 \sa buildMajorTicks(), buildMinorTicks 751 960 */ 752 void QwtLog 10ScaleEngine::buildTicks(753 const QwtInterval& interval, double stepSize, int maxMin Steps,961 void QwtLogScaleEngine::buildTicks( 962 const QwtInterval& interval, double stepSize, int maxMinorSteps, 754 963 QList<double> ticks[QwtScaleDiv::NTickTypes] ) const 755 964 { … … 759 968 buildMajorTicks( boundingInterval, stepSize ); 760 969 761 if ( maxMin Steps > 0 )762 { 763 ticks[QwtScaleDiv::MinorTick] = buildMinorTicks(764 ticks[QwtScaleDiv::M ajorTick], maxMinSteps, stepSize);970 if ( maxMinorSteps > 0 ) 971 { 972 buildMinorTicks( ticks[QwtScaleDiv::MajorTick], maxMinorSteps, stepSize, 973 ticks[QwtScaleDiv::MinorTick], ticks[QwtScaleDiv::MediumTick] ); 765 974 } 766 975 … … 777 986 \return Calculated ticks 778 987 */ 779 QList<double> QwtLog 10ScaleEngine::buildMajorTicks(988 QList<double> QwtLogScaleEngine::buildMajorTicks( 780 989 const QwtInterval &interval, double stepSize ) const 781 990 { 782 double width = log10(interval ).width();991 double width = qwtLogInterval( base(), interval ).width(); 783 992 784 993 int numTicks = qRound( width / stepSize ) + 1; … … 806 1015 807 1016 \param majorTicks Major ticks 808 \param maxMin Steps Maximum number of minor steps1017 \param maxMinorSteps Maximum number of minor steps 809 1018 \param stepSize Step size 810 */ 811 QList<double> QwtLog10ScaleEngine::buildMinorTicks( 1019 \param minorTicks Array to be filled with the calculated minor ticks 1020 \param mediumTicks Array to be filled with the calculated medium ticks 1021 */ 1022 void QwtLogScaleEngine::buildMinorTicks( 812 1023 const QList<double> &majorTicks, 813 int maxMinSteps, double stepSize ) const 814 { 815 if ( stepSize < 1.1 ) // major step width is one decade 816 { 817 if ( maxMinSteps < 1 ) 818 return QList<double>(); 819 820 int k0, kstep, kmax; 821 822 if ( maxMinSteps >= 8 ) 1024 int maxMinorSteps, double stepSize, 1025 QList<double> &minorTicks, 1026 QList<double> &mediumTicks ) const 1027 { 1028 const double logBase = base(); 1029 1030 if ( stepSize < 1.1 ) // major step width is one base 1031 { 1032 double minStep = divideInterval( stepSize, maxMinorSteps + 1 ); 1033 if ( minStep == 0.0 ) 1034 return; 1035 1036 const int numSteps = qRound( stepSize / minStep ); 1037 1038 int mediumTickIndex = -1; 1039 if ( ( numSteps > 2 ) && ( numSteps % 2 == 0 ) ) 1040 mediumTickIndex = numSteps / 2; 1041 1042 for ( int i = 0; i < majorTicks.count() - 1; i++ ) 823 1043 { 824 k0 = 2; 825 kmax = 9; 826 kstep = 1; 1044 const double v = majorTicks[i]; 1045 const double s = logBase / numSteps; 1046 1047 if ( s >= 1.0 ) 1048 { 1049 if ( !qFuzzyCompare( s, 1.0 ) ) 1050 minorTicks += v * s; 1051 1052 for ( int j = 2; j < numSteps; j++ ) 1053 { 1054 minorTicks += v * j * s; 1055 } 1056 } 1057 else 1058 { 1059 for ( int j = 1; j < numSteps; j++ ) 1060 { 1061 const double tick = v + j * v * ( logBase - 1 ) / numSteps; 1062 if ( j == mediumTickIndex ) 1063 mediumTicks += tick; 1064 else 1065 minorTicks += tick; 1066 } 1067 } 827 1068 } 828 else if ( maxMinSteps >= 4 ) 1069 } 1070 else 1071 { 1072 double minStep = divideInterval( stepSize, maxMinorSteps ); 1073 if ( minStep == 0.0 ) 1074 return; 1075 1076 if ( minStep < 1.0 ) 1077 minStep = 1.0; 1078 1079 // # subticks per interval 1080 int numTicks = qRound( stepSize / minStep ) - 1; 1081 1082 // Do the minor steps fit into the interval? 1083 if ( qwtFuzzyCompare( ( numTicks + 1 ) * minStep, 1084 stepSize, stepSize ) > 0 ) 829 1085 { 830 k0 = 2; 831 kmax = 8; 832 kstep = 2; 1086 numTicks = 0; 833 1087 } 834 else if ( maxMinSteps >= 2 ) 835 { 836 k0 = 2; 837 kmax = 5; 838 kstep = 3; 839 } 840 else 841 { 842 k0 = 5; 843 kmax = 5; 844 kstep = 1; 845 } 846 847 QList<double> minorTicks; 1088 1089 if ( numTicks < 1 ) 1090 return; 1091 1092 int mediumTickIndex = -1; 1093 if ( ( numTicks > 2 ) && ( numTicks % 2 ) ) 1094 mediumTickIndex = numTicks / 2; 1095 1096 // substep factor = base^substeps 1097 const qreal minFactor = qMax( qPow( logBase, minStep ), qreal( logBase ) ); 848 1098 849 1099 for ( int i = 0; i < majorTicks.count(); i++ ) 850 1100 { 851 const double v = majorTicks[i]; 852 for ( int k = k0; k <= kmax; k += kstep ) 853 minorTicks += v * double( k ); 854 } 855 856 return minorTicks; 857 } 858 else // major step > one decade 859 { 860 double minStep = divideInterval( stepSize, maxMinSteps ); 861 if ( minStep == 0.0 ) 862 return QList<double>(); 863 864 if ( minStep < 1.0 ) 865 minStep = 1.0; 866 867 // # subticks per interval 868 int nMin = qRound( stepSize / minStep ) - 1; 869 870 // Do the minor steps fit into the interval? 871 872 if ( qwtFuzzyCompare( ( nMin + 1 ) * minStep, 873 qAbs( stepSize ), stepSize ) > 0 ) 874 { 875 nMin = 0; 876 } 877 878 if ( nMin < 1 ) 879 return QList<double>(); // no subticks 880 881 // substep factor = 10^substeps 882 const qreal minFactor = qMax( qPow( 10.0, minStep ), qreal( 10.0 ) ); 883 884 QList<double> minorTicks; 885 for ( int i = 0; i < majorTicks.count(); i++ ) 886 { 887 double val = majorTicks[i]; 888 for ( int k = 0; k < nMin; k++ ) 1101 double tick = majorTicks[i]; 1102 for ( int j = 0; j < numTicks; j++ ) 889 1103 { 890 val *= minFactor; 891 minorTicks += val; 1104 tick *= minFactor; 1105 1106 if ( j == mediumTickIndex ) 1107 mediumTicks += tick; 1108 else 1109 minorTicks += tick; 892 1110 } 893 1111 } 894 return minorTicks;895 1112 } 896 1113 } … … 907 1124 \return Aligned interval 908 1125 */ 909 QwtInterval QwtLog 10ScaleEngine::align(1126 QwtInterval QwtLogScaleEngine::align( 910 1127 const QwtInterval &interval, double stepSize ) const 911 1128 { 912 const QwtInterval intv = log10(interval );1129 const QwtInterval intv = qwtLogInterval( base(), interval ); 913 1130 914 1131 double x1 = QwtScaleArithmetic::floorEps( intv.minValue(), stepSize ); … … 920 1137 x2 = interval.maxValue(); 921 1138 922 return pow10( QwtInterval( x1, x2 ) ); 923 } 924 925 /*! 926 Return the interval [log10(interval.minValue(), log10(interval.maxValue] 927 */ 928 929 QwtInterval QwtLog10ScaleEngine::log10( const QwtInterval &interval ) const 930 { 931 return QwtInterval( ::log10( interval.minValue() ), 932 ::log10( interval.maxValue() ) ); 933 } 934 935 /*! 936 Return the interval [pow10(interval.minValue(), pow10(interval.maxValue] 937 */ 938 QwtInterval QwtLog10ScaleEngine::pow10( const QwtInterval &interval ) const 939 { 940 return QwtInterval( qPow( 10.0, interval.minValue() ), 941 qPow( 10.0, interval.maxValue() ) ); 942 } 1139 return qwtPowInterval( base(), QwtInterval( x1, x2 ) ); 1140 } -
trunk/BNC/qwt/qwt_scale_engine.h
r4271 r8127 15 15 #include "qwt_interval.h" 16 16 17 class Qwt ScaleTransformation;17 class QwtTransform; 18 18 19 19 /*! … … 28 28 static double divideEps( double interval, double steps ); 29 29 30 static double ceil125( double x );31 static double floor125( double x);30 static double divideInterval( double interval, 31 int numSteps, uint base ); 32 32 }; 33 33 … … 40 40 The layout of the scale can be varied with setAttribute(). 41 41 42 Qwt offers implementations for logarithmic (log10) 43 and linear scales. Contributions for other types of scale engines 44 (date/time, log2 ... ) are welcome. 42 Qwt offers implementations for logarithmic and linear scales. 45 43 */ 46 44 … … 81 79 typedef QFlags<Attribute> Attributes; 82 80 83 explicit QwtScaleEngine( );81 explicit QwtScaleEngine( uint base = 10 ); 84 82 virtual ~QwtScaleEngine(); 83 84 void setBase( uint base ); 85 uint base() const; 85 86 86 87 void setAttribute( Attribute, bool on = true ); … … 113 114 \param x1 First interval limit 114 115 \param x2 Second interval limit 115 \param maxMaj Steps Maximum for the number of major steps116 \param maxMin Steps Maximum number of minor steps116 \param maxMajorSteps Maximum for the number of major steps 117 \param maxMinorSteps Maximum number of minor steps 117 118 \param stepSize Step size. If stepSize == 0.0, the scaleEngine 118 119 calculates one. 120 121 \return Calculated scale division 119 122 */ 120 123 virtual QwtScaleDiv divideScale( double x1, double x2, 121 int maxMaj Steps, int maxMinSteps,124 int maxMajorSteps, int maxMinorSteps, 122 125 double stepSize = 0.0 ) const = 0; 123 126 124 //! \return a transformation125 virtual QwtScaleTransformation *transformation() const = 0;127 void setTransformation( QwtTransform * ); 128 QwtTransform *transformation() const; 126 129 127 130 protected: 128 131 bool contains( const QwtInterval &, double val ) const; 129 132 QList<double> strip( const QList<double>&, const QwtInterval & ) const; 133 130 134 double divideInterval( double interval, int numSteps ) const; 131 135 … … 147 151 { 148 152 public: 153 QwtLinearScaleEngine( uint base = 10 ); 154 virtual ~QwtLinearScaleEngine(); 155 149 156 virtual void autoScale( int maxSteps, 150 157 double &x1, double &x2, double &stepSize ) const; … … 154 161 double stepSize = 0.0 ) const; 155 162 156 virtual QwtScaleTransformation *transformation() const;157 163 158 164 protected: … … 166 172 const QwtInterval &interval, double stepSize ) const; 167 173 168 void buildMinorTicks( 169 const QList<double>& majorTicks, 170 int maxMinMark, double step, 171 QList<double> &, QList<double> & ) const; 172 }; 173 174 /*! 175 \brief A scale engine for logarithmic (base 10) scales 174 void buildMinorTicks( const QList<double>& majorTicks, 175 int maxMinorSteps, double stepSize, 176 QList<double> &minorTicks, QList<double> &mediumTicks ) const; 177 }; 178 179 /*! 180 \brief A scale engine for logarithmic scales 176 181 177 182 The step size is measured in *decades* … … 183 188 */ 184 189 185 class QWT_EXPORT QwtLog10ScaleEngine: public QwtScaleEngine 186 { 187 public: 190 class QWT_EXPORT QwtLogScaleEngine: public QwtScaleEngine 191 { 192 public: 193 QwtLogScaleEngine( uint base = 10 ); 194 virtual ~QwtLogScaleEngine(); 195 188 196 virtual void autoScale( int maxSteps, 189 197 double &x1, double &x2, double &stepSize ) const; … … 193 201 double stepSize = 0.0 ) const; 194 202 195 virtual QwtScaleTransformation *transformation() const;196 197 203 protected: 198 QwtInterval log10( const QwtInterval& ) const;199 QwtInterval pow10( const QwtInterval& ) const;200 201 204 QwtInterval align( const QwtInterval&, double stepSize ) const; 202 205 … … 208 211 const QwtInterval &interval, double stepSize ) const; 209 212 210 QList<double> buildMinorTicks(211 const QList<double>& majorTicks,212 int maxMinMark, double step) const;213 void buildMinorTicks( const QList<double>& majorTicks, 214 int maxMinorSteps, double stepSize, 215 QList<double> &minorTicks, QList<double> &mediumTicks ) const; 213 216 }; 214 217 -
trunk/BNC/qwt/qwt_scale_map.cpp
r4271 r8127 9 9 10 10 #include "qwt_scale_map.h" 11 #include "qwt_math.h" 11 12 #include <qrect.h> 12 #include <qalgorithms.h>13 #include <qmath.h>14 13 #include <qdebug.h> 15 16 #if QT_VERSION < 0x04060117 #define qExp(x) ::exp(x)18 #endif19 20 //! Smallest allowed value for logarithmic scales: 1.0e-15021 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMin = 1.0e-150;22 23 //! Largest allowed value for logarithmic scales: 1.0e15024 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMax = 1.0e150;25 26 //! Constructor for a linear transformation27 QwtScaleTransformation::QwtScaleTransformation( Type type ):28 d_type( type )29 {30 }31 32 //! Destructor33 QwtScaleTransformation::~QwtScaleTransformation()34 {35 }36 37 //! Create a clone of the transformation38 QwtScaleTransformation *QwtScaleTransformation::copy() const39 {40 return new QwtScaleTransformation( d_type );41 }42 43 /*!44 \brief Transform a value from the coordinate system of a scale45 into the coordinate system of the paint device46 47 \param s Value related to the coordinate system of the scale48 \param s1 First border of the coordinate system of the scale49 \param s2 Second border of the coordinate system of the scale50 \param p1 First border of the coordinate system of the paint device51 \param p2 Second border of the coordinate system of the paint device52 \return53 <dl>54 <dt>linear mapping:<dd>p1 + (p2 - p1) / (s2 - s1) * (s - s1);</dd>55 </dl>56 <dl>57 <dt>log10 mapping: <dd>p1 + (p2 - p1) / log(s2 / s1) * log(s / s1);</dd>58 </dl>59 */60 61 double QwtScaleTransformation::xForm(62 double s, double s1, double s2, double p1, double p2 ) const63 {64 if ( d_type == Log10 )65 return p1 + ( p2 - p1 ) / log( s2 / s1 ) * log( s / s1 );66 else67 return p1 + ( p2 - p1 ) / ( s2 - s1 ) * ( s - s1 );68 }69 70 /*!71 \brief Transform a value from the coordinate system of the paint device72 into the coordinate system of a scale.73 74 \param p Value related to the coordinate system of the paint device75 \param p1 First border of the coordinate system of the paint device76 \param p2 Second border of the coordinate system of the paint device77 \param s1 First border of the coordinate system of the scale78 \param s2 Second border of the coordinate system of the scale79 \return80 <dl>81 <dt>linear mapping:<dd>s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );</dd>82 </dl>83 <dl>84 <dt>log10 mapping:<dd>exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1;</dd>85 </dl>86 */87 88 double QwtScaleTransformation::invXForm( double p, double p1, double p2,89 double s1, double s2 ) const90 {91 if ( d_type == Log10 )92 return qExp( ( p - p1 ) / ( p2 - p1 ) * log( s2 / s1 ) ) * s1;93 else94 return s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );95 }96 14 97 15 /*! … … 105 23 d_p1( 0.0 ), 106 24 d_p2( 1.0 ), 107 d_cnv( 1.0 ) 108 { 109 d_transform ation = new QwtScaleTransformation(110 QwtScaleTransformation::Linear ); 25 d_cnv( 1.0 ), 26 d_ts1( 0.0 ), 27 d_transform( NULL ) 28 { 111 29 } 112 30 … … 117 35 d_p1( other.d_p1 ), 118 36 d_p2( other.d_p2 ), 119 d_cnv( other.d_cnv ) 120 { 121 d_transformation = other.d_transformation->copy(); 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(); 122 43 } 123 44 … … 127 48 QwtScaleMap::~QwtScaleMap() 128 49 { 129 delete d_transform ation;50 delete d_transform; 130 51 } 131 52 … … 138 59 d_p2 = other.d_p2; 139 60 d_cnv = other.d_cnv; 140 141 delete d_transformation; 142 d_transformation = other.d_transformation->copy(); 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(); 143 68 144 69 return *this; … … 148 73 Initialize the map with a transformation 149 74 */ 150 void QwtScaleMap::setTransformation( 151 QwtScaleTransformation *transformation ) 152 { 153 if ( transformation == NULL ) 154 return; 155 156 if ( transformation != d_transformation ) 75 void QwtScaleMap::setTransformation( QwtTransform *transform ) 76 { 77 if ( transform != d_transform ) 157 78 { 158 delete d_transform ation;159 d_transform ation = transformation;79 delete d_transform; 80 d_transform = transform; 160 81 } 161 82 … … 164 85 165 86 //! Get the transformation 166 const Qwt ScaleTransformation*QwtScaleMap::transformation() const167 { 168 return d_transform ation;87 const QwtTransform *QwtScaleMap::transformation() const 88 { 89 return d_transform; 169 90 } 170 91 … … 173 94 \param s1 first border 174 95 \param s2 second border 175 \warning logarithmic scales might be aligned to [LogMin, LogMax] 96 \warning scales might be aligned to 97 transformation depending boundaries 176 98 */ 177 99 void QwtScaleMap::setScaleInterval( double s1, double s2 ) 178 100 { 179 if ( d_transformation->type() == QwtScaleTransformation::Log10 )180 {181 if ( s1 < LogMin )182 s1 = LogMin;183 else if ( s1 > LogMax )184 s1 = LogMax;185 186 if ( s2 < LogMin )187 s2 = LogMin;188 else if ( s2 > LogMax )189 s2 = LogMax;190 }191 192 101 d_s1 = s1; 193 102 d_s2 = s2; 194 103 195 if ( d_transformation->type() != QwtScaleTransformation::Other ) 196 newFactor(); 104 if ( d_transform ) 105 { 106 d_s1 = d_transform->bounded( d_s1 ); 107 d_s2 = d_transform->bounded( d_s2 ); 108 } 109 110 updateFactor(); 197 111 } 198 112 … … 207 121 d_p2 = p2; 208 122 209 if ( d_transformation->type() != QwtScaleTransformation::Other ) 210 newFactor(); 211 } 212 213 /*! 214 \brief Re-calculate the conversion factor. 215 */ 216 void QwtScaleMap::newFactor() 217 { 218 d_cnv = 0.0; 219 220 switch ( d_transformation->type() ) 123 updateFactor(); 124 } 125 126 void QwtScaleMap::updateFactor() 127 { 128 d_ts1 = d_s1; 129 double ts2 = d_s2; 130 131 if ( d_transform ) 221 132 { 222 case QwtScaleTransformation::Linear: 223 { 224 if ( d_s2 != d_s1 ) 225 d_cnv = ( d_p2 - d_p1 ) / ( d_s2 - d_s1 ); 226 break; 227 } 228 case QwtScaleTransformation::Log10: 229 { 230 if ( d_s1 != 0 ) 231 d_cnv = ( d_p2 - d_p1 ) / log( d_s2 / d_s1 ); 232 break; 233 } 234 default:; 133 d_ts1 = d_transform->transform( d_ts1 ); 134 ts2 = d_transform->transform( ts2 ); 235 135 } 136 137 d_cnv = 1.0; 138 if ( d_ts1 != ts2 ) 139 d_cnv = ( d_p2 - d_p1 ) / ( ts2 - d_ts1 ); 236 140 } 237 141 … … 334 238 { 335 239 debug.nospace() << "QwtScaleMap(" 336 << static_cast<int>( map.transformation()->type())240 << map.transformation() 337 241 << ", s:" << map.s1() << "->" << map.s2() 338 242 << ", p:" << map.p1() << "->" << map.p2() -
trunk/BNC/qwt/qwt_scale_map.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_math.h" 14 #include "qwt_transform.h" 15 #include <qrect.h> 16 15 17 #ifndef QT_NO_DEBUG_STREAM 16 18 #include <qdebug.h> … … 18 20 19 21 class QRectF; 20 21 /*!22 \brief A transformation between coordinate systems23 24 QwtScaleTransformation offers transformations from the coordinate system25 of a scale into the linear coordinate system of a paint device26 and vice versa.27 */28 class QWT_EXPORT QwtScaleTransformation29 {30 public:31 //! Transformation type32 enum Type33 {34 //! Transformation between 2 linear scales35 Linear,36 37 //! Transformation between a linear and a logarithmic ( base 10 ) scale38 Log10,39 40 //! Any other type of transformation41 Other42 };43 44 QwtScaleTransformation( Type type );45 virtual ~QwtScaleTransformation();46 47 virtual double xForm( double x, double s1, double s2,48 double p1, double p2 ) const;49 virtual double invXForm( double x, double p1, double p2,50 double s1, double s2 ) const;51 52 Type type() const;53 54 virtual QwtScaleTransformation *copy() const;55 56 private:57 QwtScaleTransformation();58 QwtScaleTransformation &operator=( const QwtScaleTransformation );59 60 const Type d_type;61 };62 63 //! \return Transformation type64 inline QwtScaleTransformation::Type QwtScaleTransformation::type() const65 {66 return d_type;67 }68 22 69 23 /*! … … 84 38 QwtScaleMap &operator=( const QwtScaleMap & ); 85 39 86 void setTransformation( Qwt ScaleTransformation* );87 const Qwt ScaleTransformation*transformation() const;40 void setTransformation( QwtTransform * ); 41 const QwtTransform *transformation() const; 88 42 89 43 void setPaintInterval( double p1, double p2 ); … … 102 56 double sDist() const; 103 57 104 QT_STATIC_CONST double LogMin;105 QT_STATIC_CONST double LogMax;106 107 58 static QRectF transform( const QwtScaleMap &, 108 59 const QwtScaleMap &, const QRectF & ); … … 118 69 119 70 private: 120 void newFactor();71 void updateFactor(); 121 72 122 73 double d_s1, d_s2; // scale interval boundaries … … 124 75 125 76 double d_cnv; // conversion factor 77 double d_ts1; 126 78 127 Qwt ScaleTransformation *d_transformation;79 QwtTransform *d_transform; 128 80 }; 129 81 … … 181 133 182 134 \param s Value relative to the coordinates of the scale 135 \return Transformed value 136 137 \sa invTransform() 183 138 */ 184 139 inline double QwtScaleMap::transform( double s ) const 185 140 { 186 // try to inline code from QwtScaleTransformation 141 if ( d_transform ) 142 s = d_transform->transform( s ); 187 143 188 if ( d_transformation->type() == QwtScaleTransformation::Linear ) 189 return d_p1 + ( s - d_s1 ) * d_cnv; 190 191 if ( d_transformation->type() == QwtScaleTransformation::Log10 ) 192 return d_p1 + log( s / d_s1 ) * d_cnv; 193 194 return d_transformation->xForm( s, d_s1, d_s2, d_p1, d_p2 ); 144 return d_p1 + ( s - d_ts1 ) * d_cnv; 195 145 } 196 146 … … 200 150 201 151 \param p Value relative to the coordinates of the paint device 152 \return Transformed value 153 202 154 \sa transform() 203 155 */ 204 156 inline double QwtScaleMap::invTransform( double p ) const 205 157 { 206 return d_transformation->invXForm( p, d_p1, d_p2, d_s1, d_s2 ); 158 double s = d_ts1 + ( p - d_p1 ) / d_cnv; 159 if ( d_transform ) 160 s = d_transform->invTransform( s ); 161 162 return s; 207 163 } 208 164 -
trunk/BNC/qwt/qwt_scale_widget.cpp
r4271 r8127 15 15 #include "qwt_scale_div.h" 16 16 #include "qwt_text.h" 17 #include "qwt_scale_engine.h" 17 18 #include <qpainter.h> 18 19 #include <qevent.h> … … 107 108 d_data->scaleDraw->setLength( 10 ); 108 109 110 d_data->scaleDraw->setScaleDiv( 111 QwtLinearScaleEngine().divideScale( 0.0, 100.0, 10, 5 ) ); 112 109 113 d_data->colorBar.colorMap = new QwtLinearColorMap(); 110 114 d_data->colorBar.isEnabled = false; … … 202 206 void QwtScaleWidget::setAlignment( QwtScaleDraw::Alignment alignment ) 203 207 { 208 if ( d_data->scaleDraw ) 209 d_data->scaleDraw->setAlignment( alignment ); 210 204 211 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) 205 212 { … … 208 215 if ( d_data->scaleDraw->orientation() == Qt::Vertical ) 209 216 policy.transpose(); 217 210 218 setSizePolicy( policy ); 211 219 … … 213 221 } 214 222 215 if ( d_data->scaleDraw )216 d_data->scaleDraw->setAlignment( alignment );217 223 layoutScale(); 218 224 } … … 305 311 /*! 306 312 Set a scale draw 307 sd has to be created with new and will be deleted in 313 314 scaleDraw has to be created with new and will be deleted in 308 315 ~QwtScaleWidget() or the next call of setScaleDraw(). 309 310 \param sd ScaleDraw object 316 scaleDraw will be initialized with the attributes of 317 the previous scaleDraw object. 318 319 \param scaleDraw ScaleDraw object 311 320 \sa scaleDraw() 312 321 */ 313 void QwtScaleWidget::setScaleDraw( QwtScaleDraw *s d)314 { 315 if ( sd == NULL || sd == d_data->scaleDraw)322 void QwtScaleWidget::setScaleDraw( QwtScaleDraw *scaleDraw ) 323 { 324 if ( ( scaleDraw == NULL ) || ( scaleDraw == d_data->scaleDraw ) ) 316 325 return; 317 326 318 if ( d_data->scaleDraw ) 319 sd->setAlignment( d_data->scaleDraw->alignment() ); 327 const QwtScaleDraw* sd = d_data->scaleDraw; 328 if ( sd ) 329 { 330 scaleDraw->setAlignment( sd->alignment() ); 331 scaleDraw->setScaleDiv( sd->scaleDiv() ); 332 333 QwtTransform *transform = NULL; 334 if ( sd->scaleMap().transformation() ) 335 transform = sd->scaleMap().transformation()->copy(); 336 337 scaleDraw->setTransformation( transform ); 338 } 320 339 321 340 delete d_data->scaleDraw; 322 d_data->scaleDraw = s d;341 d_data->scaleDraw = scaleDraw; 323 342 324 343 layoutScale(); … … 326 345 327 346 /*! 328 scaleDraw of this scale347 \return scaleDraw of this scale 329 348 \sa setScaleDraw(), QwtScaleDraw::setScaleDraw() 330 349 */ … … 335 354 336 355 /*! 337 scaleDraw of this scale356 \return scaleDraw of this scale 338 357 \sa QwtScaleDraw::setScaleDraw() 339 358 */ … … 436 455 437 456 \param rect Bounding rectangle for all components of the scale 438 \return Recta bgle for the color bar457 \return Rectangle for the color bar 439 458 */ 440 459 QRectF QwtScaleWidget::colorBarRect( const QRectF& rect ) const … … 490 509 491 510 /*! 492 Event handler for resize event 511 Event handler for resize events 493 512 \param event Resize event 494 513 */ … … 501 520 /*! 502 521 Recalculate the scale's geometry and layout based on 503 the current rectand fonts.522 the current geometry and fonts. 504 523 505 524 \param update_geometry Notify the layout system and call update … … 646 665 QwtText title = d_data->title; 647 666 title.setRenderFlags( flags ); 648 title.draw( painter, QRect ( 0,0, r.width(), r.height() ) );667 title.draw( painter, QRectF( 0.0, 0.0, r.width(), r.height() ) ); 649 668 650 669 painter->restore(); … … 713 732 int QwtScaleWidget::titleHeightForWidth( int width ) const 714 733 { 715 return d_data->title.heightForWidth( width, font() );734 return qCeil( d_data->title.heightForWidth( width, font() ) ); 716 735 } 717 736 … … 749 768 is returned. 750 769 770 \param start Return parameter for the border width at 771 the beginning of the scale 772 \param end Return parameter for the border width at the 773 end of the scale 774 751 775 \warning 752 776 <ul> <li>The minimum border distance depends on the font.</ul> … … 784 808 the widget borders. 785 809 810 \param start Return parameter for the border width at 811 the beginning of the scale 812 \param end Return parameter for the border width at the 813 end of the scale 814 786 815 \sa setMinBorderDist(), getBorderDistHint() 787 816 */ … … 797 826 The scale division determines where to set the tick marks. 798 827 799 \param transformation Transformation, needed to translate between800 scale and pixal values801 828 \param scaleDiv Scale Division 802 829 \sa For more information about scale divisions, see QwtScaleDiv. 803 830 */ 804 void QwtScaleWidget::setScaleDiv( 805 QwtScaleTransformation *transformation, 806 const QwtScaleDiv &scaleDiv ) 831 void QwtScaleWidget::setScaleDiv( const QwtScaleDiv &scaleDiv ) 807 832 { 808 833 QwtScaleDraw *sd = d_data->scaleDraw; 809 if ( sd->scaleDiv() != scaleDiv || 810 sd->scaleMap().transformation()->type() != transformation->type() ) 811 { 812 sd->setTransformation( transformation ); 834 if ( sd->scaleDiv() != scaleDiv ) 835 { 813 836 sd->setScaleDiv( scaleDiv ); 814 837 layoutScale(); … … 816 839 Q_EMIT scaleDivChanged(); 817 840 } 818 else 819 { 820 /* 821 The transformation doesn't anything different as the 822 previous one. So we better throw it silently away instead of 823 initiating heavy updates 824 */ 825 826 delete transformation; 827 } 841 } 842 843 /*! 844 Set the transformation 845 846 \param transformation Transformation 847 \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap 848 */ 849 void QwtScaleWidget::setTransformation( QwtTransform *transformation ) 850 { 851 d_data->scaleDraw->setTransformation( transformation ); 852 layoutScale(); 828 853 } 829 854 -
trunk/BNC/qwt/qwt_scale_widget.h
r4271 r8127 20 20 21 21 class QPainter; 22 class Qwt ScaleTransformation;22 class QwtTransform; 23 23 class QwtScaleDiv; 24 24 class QwtColorMap; … … 54 54 55 55 Q_SIGNALS: 56 //! Signal emitted, whenever the scale divis on changes56 //! Signal emitted, whenever the scale division changes 57 57 void scaleDivChanged(); 58 58 … … 80 80 int spacing() const; 81 81 82 void setScaleDiv( QwtScaleTransformation *, const QwtScaleDiv &sd ); 82 void setScaleDiv( const QwtScaleDiv &sd ); 83 void setTransformation( QwtTransform * ); 83 84 84 85 void setScaleDraw( QwtScaleDraw * ); -
trunk/BNC/qwt/qwt_series_data.cpp
r4271 r8127 34 34 static inline QRectF qwtBoundingRect( const QwtSetSample &sample ) 35 35 { 36 double min X= sample.set[0];37 double max X= sample.set[0];38 39 for ( int i = 1; i < ( int )sample.set.size(); i++ )36 double minY = sample.set[0]; 37 double maxY = sample.set[0]; 38 39 for ( int i = 1; i < sample.set.size(); i++ ) 40 40 { 41 if ( sample.set[i] < min X)42 min X= sample.set[i];43 if ( sample.set[i] > max X)44 max X= sample.set[i];41 if ( sample.set[i] < minY ) 42 minY = sample.set[i]; 43 if ( sample.set[i] > maxY ) 44 maxY = sample.set[i]; 45 45 } 46 46 47 double min Y= sample.value;48 double max Y= sample.value;47 double minX = sample.value; 48 double maxX = sample.value; 49 49 50 50 return QRectF( minX, minY, maxX - minX, maxY - minY ); 51 51 } 52 52 53 /*! 54 \brief Calculate the bounding rect of a series subset 53 static inline QRectF qwtBoundingRect( const QwtOHLCSample &sample ) 54 { 55 const QwtInterval interval = sample.boundingInterval(); 56 return QRectF( interval.minValue(), sample.time, interval.width(), 0.0 ); 57 } 58 59 /*! 60 \brief Calculate the bounding rectangle of a series subset 55 61 56 62 Slow implementation, that iterates over the series. … … 64 70 65 71 template <class T> 66 QRectF qwtBoundingRectT( 72 QRectF qwtBoundingRectT( 67 73 const QwtSeriesData<T>& series, int from, int to ) 68 74 { … … 106 112 107 113 /*! 108 \brief Calculate the bounding rect of a series subset109 110 Slow implementation, that iterates over the series. 111 112 \param series Series 113 \param from Index of the first sample, <= 0 means from the beginning 114 \param to Index of the last sample, < 0 means to the end 115 116 \return Bounding rectangle 117 */ 118 QRectF qwtBoundingRect( 114 \brief Calculate the bounding rectangle of a series subset 115 116 Slow implementation, that iterates over the series. 117 118 \param series Series 119 \param from Index of the first sample, <= 0 means from the beginning 120 \param to Index of the last sample, < 0 means to the end 121 122 \return Bounding rectangle 123 */ 124 QRectF qwtBoundingRect( 119 125 const QwtSeriesData<QPointF> &series, int from, int to ) 120 126 { … … 123 129 124 130 /*! 125 \brief Calculate the bounding rect of a series subset126 127 Slow implementation, that iterates over the series. 128 129 \param series Series 130 \param from Index of the first sample, <= 0 means from the beginning 131 \param to Index of the last sample, < 0 means to the end 132 133 \return Bounding rectangle 134 */ 135 QRectF qwtBoundingRect( 131 \brief Calculate the bounding rectangle of a series subset 132 133 Slow implementation, that iterates over the series. 134 135 \param series Series 136 \param from Index of the first sample, <= 0 means from the beginning 137 \param to Index of the last sample, < 0 means to the end 138 139 \return Bounding rectangle 140 */ 141 QRectF qwtBoundingRect( 136 142 const QwtSeriesData<QwtPoint3D> &series, int from, int to ) 137 143 { … … 140 146 141 147 /*! 142 \brief Calculate the bounding rect of a series subset148 \brief Calculate the bounding rectangle of a series subset 143 149 144 150 The horizontal coordinates represent the azimuth, the … … 153 159 \return Bounding rectangle 154 160 */ 155 QRectF qwtBoundingRect( 161 QRectF qwtBoundingRect( 156 162 const QwtSeriesData<QwtPointPolar> &series, int from, int to ) 157 163 { … … 160 166 161 167 /*! 162 \brief Calculate the bounding rect of a series subset163 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( 168 \brief Calculate the bounding rectangle of a series subset 169 170 Slow implementation, that iterates over the series. 171 172 \param series Series 173 \param from Index of the first sample, <= 0 means from the beginning 174 \param to Index of the last sample, < 0 means to the end 175 176 \return Bounding rectangle 177 */ 178 QRectF qwtBoundingRect( 173 179 const QwtSeriesData<QwtIntervalSample>& series, int from, int to ) 174 180 { … … 177 183 178 184 /*! 179 \brief Calculate the bounding rect 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( 185 \brief Calculate the bounding rectangle of a series subset 186 187 Slow implementation, that iterates over the series. 188 189 \param series Series 190 \param from Index of the first sample, <= 0 means from the beginning 191 \param to Index of the last sample, < 0 means to the end 192 193 \return Bounding rectangle 194 */ 195 QRectF qwtBoundingRect( 196 const QwtSeriesData<QwtOHLCSample>& series, int from, int to ) 197 { 198 return qwtBoundingRectT<QwtOHLCSample>( series, from, to ); 199 } 200 201 /*! 202 \brief Calculate the bounding rectangle of a series subset 203 204 Slow implementation, that iterates over the series. 205 206 \param series Series 207 \param from Index of the first sample, <= 0 means from the beginning 208 \param to Index of the last sample, < 0 means to the end 209 210 \return Bounding rectangle 211 */ 212 QRectF qwtBoundingRect( 190 213 const QwtSeriesData<QwtSetSample>& series, int from, int to ) 191 214 { … … 204 227 205 228 /*! 206 \brief Calculate the bounding rect 229 \brief Calculate the bounding rectangle 207 230 208 231 The bounding rectangle is calculated once by iterating over all … … 230 253 231 254 /*! 232 \brief Calculate the bounding rect 255 \brief Calculate the bounding rectangle 233 256 234 257 The bounding rectangle is calculated once by iterating over all … … 256 279 257 280 /*! 258 \brief Calculate the bounding rect 281 \brief Calculate the bounding rectangle 259 282 260 283 The bounding rectangle is calculated once by iterating over all … … 282 305 283 306 /*! 284 \brief Calculate the bounding rect 307 \brief Calculate the bounding rectangle 285 308 286 309 The bounding rectangle is calculated once by iterating over all … … 298 321 299 322 /*! 300 Constructor 301 302 \param x Array of x values 303 \param y Array of y values 304 305 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 306 */ 307 QwtPointArrayData::QwtPointArrayData( 308 const QVector<double> &x, const QVector<double> &y ): 309 d_x( x ), 310 d_y( y ) 311 { 312 } 313 314 /*! 315 Constructor 316 317 \param x Array of x values 318 \param y Array of y values 319 \param size Size of the x and y arrays 320 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 321 */ 322 QwtPointArrayData::QwtPointArrayData( const double *x, 323 const double *y, size_t size ) 324 { 325 d_x.resize( size ); 326 qMemCopy( d_x.data(), x, size * sizeof( double ) ); 327 328 d_y.resize( size ); 329 qMemCopy( d_y.data(), y, size * sizeof( double ) ); 330 } 331 332 /*! 333 \brief Calculate the bounding rect 334 335 The bounding rectangle is calculated once by iterating over all 336 points and is stored for all following requests. 337 338 \return Bounding rectangle 339 */ 340 QRectF QwtPointArrayData::boundingRect() const 341 { 342 if ( d_boundingRect.width() < 0 ) 343 d_boundingRect = qwtBoundingRect( *this ); 344 345 return d_boundingRect; 346 } 347 348 //! \return Size of the data set 349 size_t QwtPointArrayData::size() const 350 { 351 return qMin( d_x.size(), d_y.size() ); 352 } 353 354 /*! 355 Return the sample at position i 356 357 \param i Index 358 \return Sample at position i 359 */ 360 QPointF QwtPointArrayData::sample( size_t i ) const 361 { 362 return QPointF( d_x[int( i )], d_y[int( i )] ); 363 } 364 365 //! \return Array of the x-values 366 const QVector<double> &QwtPointArrayData::xData() const 367 { 368 return d_x; 369 } 370 371 //! \return Array of the y-values 372 const QVector<double> &QwtPointArrayData::yData() const 373 { 374 return d_y; 375 } 376 377 /*! 378 Constructor 379 380 \param x Array of x values 381 \param y Array of y values 382 \param size Size of the x and y arrays 383 384 \warning The programmer must assure that the memory blocks referenced 385 by the pointers remain valid during the lifetime of the 386 QwtPlotCPointer object. 387 388 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples() 389 */ 390 QwtCPointerData::QwtCPointerData( 391 const double *x, const double *y, size_t size ): 392 d_x( x ), 393 d_y( y ), 394 d_size( size ) 395 { 396 } 397 398 /*! 399 \brief Calculate the bounding rect 400 401 The bounding rectangle is calculated once by iterating over all 402 points and is stored for all following requests. 403 404 \return Bounding rectangle 405 */ 406 QRectF QwtCPointerData::boundingRect() const 407 { 408 if ( d_boundingRect.width() < 0 ) 409 d_boundingRect = qwtBoundingRect( *this ); 410 411 return d_boundingRect; 412 } 413 414 //! \return Size of the data set 415 size_t QwtCPointerData::size() const 416 { 417 return d_size; 418 } 419 420 /*! 421 Return the sample at position i 422 423 \param i Index 424 \return Sample at position i 425 */ 426 QPointF QwtCPointerData::sample( size_t i ) const 427 { 428 return QPointF( d_x[int( i )], d_y[int( i )] ); 429 } 430 431 //! \return Array of the x-values 432 const double *QwtCPointerData::xData() const 433 { 434 return d_x; 435 } 436 437 //! \return Array of the y-values 438 const double *QwtCPointerData::yData() const 439 { 440 return d_y; 441 } 442 443 /*! 444 Constructor 445 446 \param size Number of points 447 \param interval Bounding interval for the points 448 449 \sa setInterval(), setSize() 450 */ 451 QwtSyntheticPointData::QwtSyntheticPointData( 452 size_t size, const QwtInterval &interval ): 453 d_size( size ), 454 d_interval( interval ) 455 { 456 } 457 458 /*! 459 Change the number of points 460 461 \param size Number of points 462 \sa size(), setInterval() 463 */ 464 void QwtSyntheticPointData::setSize( size_t size ) 465 { 466 d_size = size; 467 } 468 469 /*! 470 \return Number of points 471 \sa setSize(), interval() 472 */ 473 size_t QwtSyntheticPointData::size() const 474 { 475 return d_size; 476 } 477 478 /*! 479 Set the bounding interval 480 481 \param interval Interval 482 \sa interval(), setSize() 483 */ 484 void QwtSyntheticPointData::setInterval( const QwtInterval &interval ) 485 { 486 d_interval = interval.normalized(); 487 } 488 489 /*! 490 \return Bounding interval 491 \sa setInterval(), size() 492 */ 493 QwtInterval QwtSyntheticPointData::interval() const 494 { 495 return d_interval; 496 } 497 498 /*! 499 Set a the "rect of interest" 500 501 QwtPlotSeriesItem defines the current area of the plot canvas 502 as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ). 503 504 If interval().isValid() == false the x values are calculated 505 in the interval rect.left() -> rect.right(). 506 507 \sa rectOfInterest() 508 */ 509 void QwtSyntheticPointData::setRectOfInterest( const QRectF &rect ) 510 { 511 d_rectOfInterest = rect; 512 d_intervalOfInterest = QwtInterval( 513 rect.left(), rect.right() ).normalized(); 514 } 515 516 /*! 517 \return "rect of interest" 518 \sa setRectOfInterest() 519 */ 520 QRectF QwtSyntheticPointData::rectOfInterest() const 521 { 522 return d_rectOfInterest; 523 } 524 525 /*! 526 \brief Calculate the bounding rect 527 528 This implementation iterates over all points, what could often 529 be implemented much faster using the characteristics of the series. 530 When there are many points it is recommended to overload and 531 reimplement this method using the characteristics of the series 532 ( if possible ). 533 534 \return Bounding rectangle 535 */ 536 QRectF QwtSyntheticPointData::boundingRect() const 537 { 538 if ( d_size == 0 || 539 !( d_interval.isValid() || d_intervalOfInterest.isValid() ) ) 540 { 541 return QRectF(1.0, 1.0, -2.0, -2.0); // something invalid 542 } 543 544 return qwtBoundingRect( *this ); 545 } 546 547 /*! 548 Calculate the point from an index 549 550 \param index Index 551 \return QPointF(x(index), y(x(index))); 552 553 \warning For invalid indices ( index < 0 || index >= size() ) 554 (0, 0) is returned. 555 */ 556 QPointF QwtSyntheticPointData::sample( size_t index ) const 557 { 558 if ( index >= d_size ) 559 return QPointF( 0, 0 ); 560 561 const double xValue = x( index ); 562 const double yValue = y( xValue ); 563 564 return QPointF( xValue, yValue ); 565 } 566 567 /*! 568 Calculate a x-value from an index 569 570 x values are calculated by deviding an interval into 571 equidistant steps. If !interval().isValid() the 572 interval is calculated from the "rect of interest". 573 574 \sa interval(), rectOfInterest(), y() 575 */ 576 double QwtSyntheticPointData::x( uint index ) const 577 { 578 const QwtInterval &interval = d_interval.isValid() ? 579 d_interval : d_intervalOfInterest; 580 581 if ( !interval.isValid() || d_size == 0 || index >= d_size ) 582 return 0.0; 583 584 const double dx = interval.width() / d_size; 585 return interval.minValue() + index * dx; 586 } 323 Constructor 324 \param samples Samples 325 */ 326 QwtTradingChartData::QwtTradingChartData( 327 const QVector<QwtOHLCSample> &samples ): 328 QwtArraySeriesData<QwtOHLCSample>( samples ) 329 { 330 } 331 332 /*! 333 \brief Calculate the bounding rectangle 334 335 The bounding rectangle is calculated once by iterating over all 336 points and is stored for all following requests. 337 338 \return Bounding rectangle 339 */ 340 QRectF QwtTradingChartData::boundingRect() const 341 { 342 if ( d_boundingRect.width() < 0.0 ) 343 d_boundingRect = qwtBoundingRect( *this ); 344 345 return d_boundingRect; 346 } -
trunk/BNC/qwt/qwt_series_data.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include "qwt_ interval.h"14 #include "qwt_samples.h" 15 15 #include "qwt_point_3d.h" 16 16 #include "qwt_point_polar.h" … … 18 18 #include <qrect.h> 19 19 20 //! \brief A sample of the types (x1-x2, y) or (x, y1-y2)21 class QWT_EXPORT QwtIntervalSample22 {23 public:24 QwtIntervalSample();25 QwtIntervalSample( double, const QwtInterval & );26 QwtIntervalSample( double value, double min, double max );27 28 bool operator==( const QwtIntervalSample & ) const;29 bool operator!=( const QwtIntervalSample & ) const;30 31 //! Value32 double value;33 34 //! Interval35 QwtInterval interval;36 };37 38 /*!39 Constructor40 The value is set to 0.0, the interval is invalid41 */42 inline QwtIntervalSample::QwtIntervalSample():43 value( 0.0 )44 {45 }46 47 //! Constructor48 inline QwtIntervalSample::QwtIntervalSample(49 double v, const QwtInterval &intv ):50 value( v ),51 interval( intv )52 {53 }54 55 //! Constructor56 inline QwtIntervalSample::QwtIntervalSample(57 double v, double min, double max ):58 value( v ),59 interval( min, max )60 {61 }62 63 //! Compare operator64 inline bool QwtIntervalSample::operator==(65 const QwtIntervalSample &other ) const66 {67 return value == other.value && interval == other.interval;68 }69 70 //! Compare operator71 inline bool QwtIntervalSample::operator!=(72 const QwtIntervalSample &other ) const73 {74 return !( *this == other );75 }76 77 //! \brief A sample of the types (x1...xn, y) or (x, y1..yn)78 class QWT_EXPORT QwtSetSample79 {80 public:81 QwtSetSample();82 bool operator==( const QwtSetSample &other ) const;83 bool operator!=( const QwtSetSample &other ) const;84 85 //! value86 double value;87 88 //! Vector of values associated to value89 QVector<double> set;90 };91 92 /*!93 Constructor94 The value is set to 0.095 */96 inline QwtSetSample::QwtSetSample():97 value( 0.0 )98 {99 }100 101 //! Compare operator102 inline bool QwtSetSample::operator==( const QwtSetSample &other ) const103 {104 return value == other.value && set == other.set;105 }106 107 //! Compare operator108 inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const109 {110 return !( *this == other );111 }112 113 20 /*! 114 21 \brief Abstract interface for iterating over samples … … 118 25 needs to be displayed, without having to copy it, it is recommended 119 26 to implement an individual data access. 27 28 A subclass of QwtSeriesData<QPointF> must implement: 29 30 - size()\n 31 Should return number of data points. 32 33 - sample()\n 34 Should return values x and y values of the sample at specific position 35 as QPointF object. 36 37 - boundingRect()\n 38 Should return the bounding rectangle of the data series. 39 It is used for autoscaling and might help certain algorithms for displaying 40 the data. You can use qwtBoundingRect() for an implementation 41 but often it is possible to implement a more efficient algorithm 42 depending on the characteristics of the series. 43 The member d_boundingRect is intended for caching the calculated rectangle. 44 120 45 */ 121 46 template <typename T> … … 123 48 { 124 49 public: 50 //! Constructor 125 51 QwtSeriesData(); 52 53 //! Destructor 126 54 virtual ~QwtSeriesData(); 127 55 … … 144 72 qwtBoundingRect(...) offers slow implementations iterating 145 73 over the samples. For large sets it is recommended to implement 146 something faster f.e. by caching the bounding rect. 74 something faster f.e. by caching the bounding rectangle. 75 76 \return Bounding rectangle 147 77 */ 148 78 virtual QRectF boundingRect() const = 0; 149 79 150 virtual void setRectOfInterest( const QRectF & ); 80 /*! 81 Set a the "rect of interest" 82 83 QwtPlotSeriesItem defines the current area of the plot canvas 84 as "rectangle of interest" ( QwtPlotSeriesItem::updateScaleDiv() ). 85 It can be used to implement different levels of details. 86 87 The default implementation does nothing. 88 89 \param rect Rectangle of interest 90 */ 91 virtual void setRectOfInterest( const QRectF &rect ); 151 92 152 93 protected: … … 158 99 }; 159 100 160 //! Constructor161 101 template <typename T> 162 102 QwtSeriesData<T>::QwtSeriesData(): … … 165 105 } 166 106 167 //! Destructor168 107 template <typename T> 169 108 QwtSeriesData<T>::~QwtSeriesData() … … 171 110 } 172 111 173 /*!174 Set a the "rect of interest"175 176 QwtPlotSeriesItem defines the current area of the plot canvas177 as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ).178 It can be used to implement different levels of details.179 180 The default implementation does nothing.181 */182 112 template <typename T> 183 113 void QwtSeriesData<T>::setRectOfInterest( const QRectF & ) … … 195 125 { 196 126 public: 127 //! Constructor 197 128 QwtArraySeriesData(); 198 QwtArraySeriesData( const QVector<T> & ); 199 200 void setSamples( const QVector<T> & ); 129 130 /*! 131 Constructor 132 \param samples Array of samples 133 */ 134 QwtArraySeriesData( const QVector<T> &samples ); 135 136 /*! 137 Assign an array of samples 138 \param samples Array of samples 139 */ 140 void setSamples( const QVector<T> &samples ); 141 142 //! \return Array of samples 201 143 const QVector<T> samples() const; 202 144 145 //! \return Number of samples 203 146 virtual size_t size() const; 204 virtual T sample( size_t ) const; 147 148 /*! 149 \return Sample at a specific position 150 151 \param index Index 152 \return Sample at position index 153 */ 154 virtual T sample( size_t index ) const; 205 155 206 156 protected: … … 209 159 }; 210 160 211 //! Constructor212 161 template <typename T> 213 162 QwtArraySeriesData<T>::QwtArraySeriesData() … … 215 164 } 216 165 217 /*!218 Constructor219 \param samples Array of samples220 */221 166 template <typename T> 222 167 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ): … … 225 170 } 226 171 227 /*!228 Assign an array of samples229 \param samples Array of samples230 */231 172 template <typename T> 232 173 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples ) … … 236 177 } 237 178 238 //! \return Array of samples239 179 template <typename T> 240 180 const QVector<T> QwtArraySeriesData<T>::samples() const … … 243 183 } 244 184 245 //! \return Number of samples246 185 template <typename T> 247 186 size_t QwtArraySeriesData<T>::size() const … … 250 189 } 251 190 252 /*!253 Return a sample254 \param i Index255 \return Sample at position i256 */257 191 template <typename T> 258 192 T QwtArraySeriesData<T>::sample( size_t i ) const 259 193 { 260 return d_samples[ i];194 return d_samples[ static_cast<int>( i ) ]; 261 195 } 262 196 … … 301 235 302 236 /*! 303 \brief Interface for iterating over two QVector<double> objects.237 Interface for iterating over an array of OHLC samples 304 238 */ 305 class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF> 306 { 307 public: 308 QwtPointArrayData( const QVector<double> &x, const QVector<double> &y ); 309 QwtPointArrayData( const double *x, const double *y, size_t size ); 310 311 virtual QRectF boundingRect() const; 312 313 virtual size_t size() const; 314 virtual QPointF sample( size_t i ) const; 315 316 const QVector<double> &xData() const; 317 const QVector<double> &yData() const; 318 319 private: 320 QVector<double> d_x; 321 QVector<double> d_y; 322 }; 239 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample> 240 { 241 public: 242 QwtTradingChartData( 243 const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() ); 244 245 virtual QRectF boundingRect() const; 246 }; 247 248 QWT_EXPORT QRectF qwtBoundingRect( 249 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 ); 250 251 QWT_EXPORT QRectF qwtBoundingRect( 252 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 ); 253 254 QWT_EXPORT QRectF qwtBoundingRect( 255 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 ); 256 257 QWT_EXPORT QRectF qwtBoundingRect( 258 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 ); 259 260 QWT_EXPORT QRectF qwtBoundingRect( 261 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 ); 262 263 QWT_EXPORT QRectF qwtBoundingRect( 264 const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 ); 323 265 324 266 /*! 325 \brief Data class containing two pointers to memory blocks of doubles. 326 */ 327 class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF> 328 { 329 public: 330 QwtCPointerData( const double *x, const double *y, size_t size ); 331 332 virtual QRectF boundingRect() const; 333 virtual size_t size() const; 334 virtual QPointF sample( size_t i ) const; 335 336 const double *xData() const; 337 const double *yData() const; 338 339 private: 340 const double *d_x; 341 const double *d_y; 342 size_t d_size; 343 }; 344 345 /*! 346 \brief Synthetic point data 347 348 QwtSyntheticPointData provides a fixed number of points for an interval. 349 The points are calculated in equidistant steps in x-direction. 350 351 If the interval is invalid, the points are calculated for 352 the "rect of interest", what normally is the displayed area on the 353 plot canvas. In this mode you get different levels of detail, when 354 zooming in/out. 267 Binary search for a sorted series of samples 268 269 qwtUpperSampleIndex returns the index of sample that is the upper bound 270 of value. Is the the value smaller than the smallest value the return 271 value will be 0. Is the value greater or equal than the largest 272 value the return value will be -1. 355 273 356 274 \par Example 357 358 The following example shows how to implement a sinus curve.275 The following example shows finds a point of curve from an x 276 coordinate 359 277 360 278 \verbatim 361 #include <cmath>362 279 #include <qwt_series_data.h> 363 280 #include <qwt_plot_curve.h> 364 #include <qwt_plot.h> 365 #include <qapplication.h> 366 367 class SinusData: public QwtSyntheticPointData 368 { 369 public: 370 SinusData(): 371 QwtSyntheticPointData(100) 281 282 struct compareX 283 { 284 inline bool operator()( const double x, const QPointF &pos ) const 372 285 { 286 return ( x < pos.x() ); 373 287 } 374 virtual double y(double x) const 288 }; 289 290 QLineF curveLineAt( const QwtPlotCurve *curve, double x ) 291 { 292 int index = qwtUpperSampleIndex<QPointF>( 293 *curve->data(), x, compareX() ); 294 295 if ( index == -1 && 296 x == curve->sample( curve->dataSize() - 1 ).x() ) 297 { 298 // the last sample is excluded from qwtUpperSampleIndex 299 index = curve->dataSize() - 1; 300 } 301 302 QLineF line; // invalid 303 if ( index > 0 ) 375 304 { 376 return qSin(x); 305 line.setP1( curve->sample( index - 1 ) ); 306 line.setP2( curve->sample( index ) ); 377 307 } 378 }; 379 380 int main(int argc, char **argv) 381 { 382 QApplication a(argc, argv); 383 384 QwtPlot plot; 385 plot.setAxisScale(QwtPlot::xBottom, 0.0, 10.0); 386 plot.setAxisScale(QwtPlot::yLeft, -1.0, 1.0); 387 388 QwtPlotCurve *curve = new QwtPlotCurve("y = sin(x)"); 389 curve->setData(SinusData()); 390 curve->attach(&plot); 391 392 plot.show(); 393 return a.exec(); 394 } 395 \endverbatim 396 */ 397 class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData<QPointF> 398 { 399 public: 400 QwtSyntheticPointData( size_t size, 401 const QwtInterval & = QwtInterval() ); 402 403 void setSize( size_t size ); 404 size_t size() const; 405 406 void setInterval( const QwtInterval& ); 407 QwtInterval interval() const; 408 409 virtual QRectF boundingRect() const; 410 virtual QPointF sample( size_t i ) const; 411 412 /*! 413 Calculate a y value for a x value 414 415 \param x x value 416 \return Corresponding y value 417 */ 418 virtual double y( double x ) const = 0; 419 virtual double x( uint index ) const; 420 421 virtual void setRectOfInterest( const QRectF & ); 422 QRectF rectOfInterest() const; 423 424 private: 425 size_t d_size; 426 QwtInterval d_interval; 427 QRectF d_rectOfInterest; 428 QwtInterval d_intervalOfInterest; 429 }; 430 431 QWT_EXPORT QRectF qwtBoundingRect( 432 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 ); 433 QWT_EXPORT QRectF qwtBoundingRect( 434 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 ); 435 QWT_EXPORT QRectF qwtBoundingRect( 436 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 ); 437 QWT_EXPORT QRectF qwtBoundingRect( 438 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 ); 439 QWT_EXPORT QRectF qwtBoundingRect( 440 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 ); 441 442 #endif 308 309 return line; 310 } 311 312 \endverbatim 313 314 315 \param series Series of samples 316 \param value Value 317 \param lessThan Compare operation 318 319 \note The samples must be sorted according to the order specified 320 by the lessThan object 321 322 of the range [begin, end) and returns the position of the one-past-the-last occurrence of value. If no such item is found, returns the position where the item should be inserted. 323 */ 324 template <typename T, typename LessThan> 325 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series, 326 double value, LessThan lessThan ) 327 { 328 const int indexMax = series.size() - 1; 329 330 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) ) 331 return -1; 332 333 int indexMin = 0; 334 int n = indexMax; 335 336 while ( n > 0 ) 337 { 338 const int half = n >> 1; 339 const int indexMid = indexMin + half; 340 341 if ( lessThan( value, series.sample( indexMid ) ) ) 342 { 343 n = half; 344 } 345 else 346 { 347 indexMin = indexMid + 1; 348 n -= half + 1; 349 } 350 } 351 352 return indexMin; 353 } 354 355 #endif -
trunk/BNC/qwt/qwt_spline.cpp
r4271 r8127 69 69 /*! 70 70 Copy constructor 71 \param other Spline used for initi lization71 \param other Spline used for initialization 72 72 */ 73 73 QwtSpline::QwtSpline( const QwtSpline& other ) … … 78 78 /*! 79 79 Assignment operator 80 \param other Spline used for initilization 80 \param other Spline used for initialization 81 \return *this 81 82 */ 82 83 QwtSpline &QwtSpline::operator=( const QwtSpline & other ) … … 153 154 154 155 /*! 155 Return points passed by setPoints156 \return Points, that have been by setPoints() 156 157 */ 157 158 QPolygonF QwtSpline::points() const … … 197 198 Calculate the interpolated function value corresponding 198 199 to a given argument x. 200 201 \param x Coordinate 202 \return Interpolated coordinate 199 203 */ 200 204 double QwtSpline::value( double x ) const -
trunk/BNC/qwt/qwt_symbol.cpp
r4271 r8127 10 10 #include "qwt_symbol.h" 11 11 #include "qwt_painter.h" 12 #include "qwt_graphic.h" 12 13 #include <qapplication.h> 13 14 #include <qpainter.h> 15 #include <qpainterpath.h> 16 #include <qpixmap.h> 17 #include <qpaintengine.h> 14 18 #include <qmath.h> 19 #ifndef QWT_NO_SVG 20 #include <qsvgrenderer.h> 21 #endif 15 22 16 23 namespace QwtTriangle … … 23 30 Down 24 31 }; 32 } 33 34 static QwtGraphic qwtPathGraphic( const QPainterPath &path, 35 const QPen &pen, const QBrush& brush ) 36 { 37 QwtGraphic graphic; 38 graphic.setRenderHint( QwtGraphic::RenderPensUnscaled ); 39 40 QPainter painter( &graphic ); 41 painter.setPen( pen ); 42 painter.setBrush( brush ); 43 painter.drawPath( path ); 44 painter.end(); 45 46 return graphic; 47 } 48 49 static inline QRectF qwtScaledBoundingRect( 50 const QwtGraphic &graphic, const QSizeF size ) 51 { 52 QSizeF scaledSize = size; 53 if ( scaledSize.isEmpty() ) 54 scaledSize = graphic.defaultSize(); 55 56 const QSizeF sz = graphic.controlPointRect().size(); 57 58 double sx = 1.0; 59 if ( sz.width() > 0.0 ) 60 sx = scaledSize.width() / sz.width(); 61 62 double sy = 1.0; 63 if ( sz.height() > 0.0 ) 64 sy = scaledSize.height() / sz.height(); 65 66 return graphic.scaledBoundingRect( sx, sy ); 67 } 68 69 static inline void qwtDrawPixmapSymbols( QPainter *painter, 70 const QPointF *points, int numPoints, const QwtSymbol &symbol ) 71 { 72 QSize size = symbol.size(); 73 if ( size.isEmpty() ) 74 size = symbol.pixmap().size(); 75 76 const QTransform transform = painter->transform(); 77 if ( transform.isScaling() ) 78 { 79 const QRect r( 0, 0, size.width(), size.height() ); 80 size = transform.mapRect( r ).size(); 81 } 82 83 QPixmap pm = symbol.pixmap(); 84 if ( pm.size() != size ) 85 pm = pm.scaled( size ); 86 87 QPointF pinPoint( 0.5 * size.width(), 0.5 * size.height() ); 88 if ( symbol.isPinPointEnabled() ) 89 pinPoint = symbol.pinPoint(); 90 91 painter->resetTransform(); 92 93 for ( int i = 0; i < numPoints; i++ ) 94 { 95 const QPointF pos = transform.map( points[i] ) - pinPoint; 96 97 QwtPainter::drawPixmap( painter, 98 QRect( pos.toPoint(), pm.size() ), pm ); 99 } 100 } 101 102 #ifndef QWT_NO_SVG 103 104 static inline void qwtDrawSvgSymbols( QPainter *painter, 105 const QPointF *points, int numPoints, 106 QSvgRenderer *renderer, const QwtSymbol &symbol ) 107 { 108 if ( renderer == NULL || !renderer->isValid() ) 109 return; 110 111 const QRectF viewBox = renderer->viewBoxF(); 112 if ( viewBox.isEmpty() ) 113 return; 114 115 QSizeF sz = symbol.size(); 116 if ( !sz.isValid() ) 117 sz = viewBox.size(); 118 119 const double sx = sz.width() / viewBox.width(); 120 const double sy = sz.height() / viewBox.height(); 121 122 QPointF pinPoint = viewBox.center(); 123 if ( symbol.isPinPointEnabled() ) 124 pinPoint = symbol.pinPoint(); 125 126 const double dx = sx * ( pinPoint.x() - viewBox.left() ); 127 const double dy = sy * ( pinPoint.y() - viewBox.top() ); 128 129 for ( int i = 0; i < numPoints; i++ ) 130 { 131 const double x = points[i].x() - dx; 132 const double y = points[i].y() - dy; 133 134 renderer->render( painter, 135 QRectF( x, y, sz.width(), sz.height() ) ); 136 } 137 } 138 139 #endif 140 141 static inline void qwtDrawGraphicSymbols( QPainter *painter, 142 const QPointF *points, int numPoints, const QwtGraphic &graphic, 143 const QwtSymbol &symbol ) 144 { 145 const QRectF pointRect = graphic.controlPointRect(); 146 if ( pointRect.isEmpty() ) 147 return; 148 149 double sx = 1.0; 150 double sy = 1.0; 151 152 const QSize sz = symbol.size(); 153 if ( sz.isValid() ) 154 { 155 sx = sz.width() / pointRect.width(); 156 sy = sz.height() / pointRect.height(); 157 } 158 159 QPointF pinPoint = pointRect.center(); 160 if ( symbol.isPinPointEnabled() ) 161 pinPoint = symbol.pinPoint(); 162 163 const QTransform transform = painter->transform(); 164 165 for ( int i = 0; i < numPoints; i++ ) 166 { 167 QTransform tr = transform; 168 tr.translate( points[i].x(), points[i].y() ); 169 tr.scale( sx, sy ); 170 tr.translate( -pinPoint.x(), -pinPoint.y() ); 171 172 painter->setTransform( tr ); 173 174 graphic.render( painter ); 175 } 176 177 painter->setTransform( transform ); 25 178 } 26 179 … … 623 776 size( sz ), 624 777 brush( br ), 625 pen( pn ) 626 { 627 } 628 629 bool operator==( const PrivateData &other ) const 630 { 631 return ( style == other.style ) 632 && ( size == other.size ) 633 && ( brush == other.brush ) 634 && ( pen == other.pen ); 635 } 636 778 pen( pn ), 779 isPinPointEnabled( false ) 780 { 781 cache.policy = QwtSymbol::AutoCache; 782 #ifndef QWT_NO_SVG 783 svg.renderer = NULL; 784 #endif 785 } 786 787 ~PrivateData() 788 { 789 #ifndef QWT_NO_SVG 790 delete svg.renderer; 791 #endif 792 } 637 793 638 794 Style style; … … 640 796 QBrush brush; 641 797 QPen pen; 798 799 bool isPinPointEnabled; 800 QPointF pinPoint; 801 802 struct Path 803 { 804 QPainterPath path; 805 QwtGraphic graphic; 806 807 } path; 808 809 struct Pixmap 810 { 811 QPixmap pixmap; 812 813 } pixmap; 814 815 struct Graphic 816 { 817 QwtGraphic graphic; 818 819 } graphic; 820 821 #ifndef QWT_NO_SVG 822 struct SVG 823 { 824 QSvgRenderer *renderer; 825 } svg; 826 #endif 827 828 struct PaintCache 829 { 830 QwtSymbol::CachePolicy policy; 831 QPixmap pixmap; 832 833 } cache; 642 834 }; 643 835 … … 652 844 { 653 845 d_data = new PrivateData( style, QBrush( Qt::gray ), 654 QPen( Qt::black ), QSize( 0.0, 0.0) );846 QPen( Qt::black, 0 ), QSize() ); 655 847 } 656 848 … … 671 863 672 864 /*! 673 \brief Copy constructor 674 675 \param other Symbol 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() 676 876 */ 677 QwtSymbol::QwtSymbol( const QwtSymbol &other ) 678 { 679 d_data = new PrivateData( other.style(), other.brush(), 680 other.pen(), other.size() ); 681 }; 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() ); 882 setPath( path ); 883 } 682 884 683 885 //! Destructor … … 687 889 } 688 890 689 //! \brief Assignment operator 690 QwtSymbol &QwtSymbol::operator=( const QwtSymbol &other ) 691 { 692 *d_data = *other.d_data; 693 return *this; 694 } 695 696 //! \brief Compare two symbols 697 bool QwtSymbol::operator==( const QwtSymbol &other ) const 698 { 699 return *d_data == *other.d_data; 700 } 701 702 //! \brief Compare two symbols 703 bool QwtSymbol::operator!=( const QwtSymbol &other ) const 704 { 705 return !( *d_data == *other.d_data ); 706 } 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 void QwtSymbol::setCachePolicy( 900 QwtSymbol::CachePolicy policy ) 901 { 902 if ( d_data->cache.policy != policy ) 903 { 904 d_data->cache.policy = policy; 905 invalidateCache(); 906 } 907 } 908 909 /*! 910 \return Cache policy 911 \sa CachePolicy, setCachePolicy() 912 */ 913 QwtSymbol::CachePolicy QwtSymbol::cachePolicy() const 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 The following code defines a symbol drawing an arrow: 930 931 \verbatim 932 #include <qwt_symbol.h> 933 934 QwtSymbol *symbol = new QwtSymbol(); 935 936 QPen pen( Qt::black, 2 ); 937 pen.setJoinStyle( Qt::MiterJoin ); 938 939 symbol->setPen( pen ); 940 symbol->setBrush( Qt::red ); 941 942 QPainterPath path; 943 path.moveTo( 0, 8 ); 944 path.lineTo( 0, 5 ); 945 path.lineTo( -3, 5 ); 946 path.lineTo( 0, 0 ); 947 path.lineTo( 3, 5 ); 948 path.lineTo( 0, 5 ); 949 950 QTransform transform; 951 transform.rotate( -30.0 ); 952 path = transform.map( path ); 953 954 symbol->setPath( path ); 955 symbol->setPinPoint( QPointF( 0.0, 0.0 ) ); 956 957 setSize( 10, 14 ); 958 \endverbatim 959 960 \param path Painter path 961 962 \note The style is implicitely set to QwtSymbol::Path. 963 \sa path(), setSize() 964 */ 965 void QwtSymbol::setPath( const QPainterPath &path ) 966 { 967 d_data->style = QwtSymbol::Path; 968 d_data->path.path = path; 969 d_data->path.graphic.reset(); 970 } 971 972 /*! 973 \return Painter path for displaying the symbol 974 \sa setPath() 975 */ 976 const QPainterPath &QwtSymbol::path() const 977 { 978 return d_data->path.path; 979 } 980 981 /*! 982 Set a pixmap as symbol 983 984 \param pixmap Pixmap 985 986 \sa pixmap(), setGraphic() 987 988 \note the style() is set to QwtSymbol::Pixmap 989 \note brush() and pen() have no effect 990 */ 991 void QwtSymbol::setPixmap( const QPixmap &pixmap ) 992 { 993 d_data->style = QwtSymbol::Pixmap; 994 d_data->pixmap.pixmap = pixmap; 995 } 996 997 /*! 998 \return Assigned pixmap 999 \sa setPixmap() 1000 */ 1001 const QPixmap &QwtSymbol::pixmap() const 1002 { 1003 return d_data->pixmap.pixmap; 1004 } 1005 1006 /*! 1007 Set a graphic as symbol 1008 1009 \param graphic Graphic 1010 1011 \sa graphic(), setPixmap() 1012 1013 \note the style() is set to QwtSymbol::Graphic 1014 \note brush() and pen() have no effect 1015 */ 1016 void QwtSymbol::setGraphic( const QwtGraphic &graphic ) 1017 { 1018 d_data->style = QwtSymbol::Graphic; 1019 d_data->graphic.graphic = graphic; 1020 } 1021 1022 /*! 1023 \return Assigned graphic 1024 \sa setGraphic() 1025 */ 1026 const QwtGraphic &QwtSymbol::graphic() const 1027 { 1028 return d_data->graphic.graphic; 1029 } 1030 1031 #ifndef QWT_NO_SVG 1032 1033 /*! 1034 Set a SVG icon as symbol 1035 1036 \param svgDocument SVG icon 1037 1038 \sa setGraphic(), setPixmap() 1039 1040 \note the style() is set to QwtSymbol::SvgDocument 1041 \note brush() and pen() have no effect 1042 */ 1043 void QwtSymbol::setSvgDocument( const QByteArray &svgDocument ) 1044 { 1045 d_data->style = QwtSymbol::SvgDocument; 1046 if ( d_data->svg.renderer == NULL ) 1047 d_data->svg.renderer = new QSvgRenderer(); 1048 1049 d_data->svg.renderer->load( svgDocument ); 1050 } 1051 1052 #endif 707 1053 708 1054 /*! … … 712 1058 and the 'w' parameter is greater than or equal to 0, 713 1059 the symbol size will be set to (w,w). 1060 714 1061 \param width Width 715 1062 \param height Height (defaults to -1) … … 722 1069 height = width; 723 1070 724 d_data->size = QSize( width, height);1071 setSize( QSize( width, height ) ); 725 1072 } 726 1073 … … 733 1080 void QwtSymbol::setSize( const QSize &size ) 734 1081 { 735 if ( size.isValid() ) 1082 if ( size.isValid() && size != d_data->size ) 1083 { 736 1084 d_data->size = size; 1085 invalidateCache(); 1086 } 737 1087 } 738 1088 … … 756 1106 void QwtSymbol::setBrush( const QBrush &brush ) 757 1107 { 758 d_data->brush = brush; 1108 if ( brush != d_data->brush ) 1109 { 1110 d_data->brush = brush; 1111 invalidateCache(); 1112 1113 if ( d_data->style == QwtSymbol::Path ) 1114 d_data->path.graphic.reset(); 1115 } 759 1116 } 760 1117 … … 769 1126 770 1127 /*! 1128 Build and assign a pen 1129 1130 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) 1131 what makes it non cosmetic ( see QPen::isCosmetic() ). 1132 This method has been introduced to hide this incompatibility. 1133 1134 \param color Pen color 1135 \param width Pen width 1136 \param style Pen style 1137 1138 \sa pen(), brush() 1139 */ 1140 void QwtSymbol::setPen( const QColor &color, 1141 qreal width, Qt::PenStyle style ) 1142 { 1143 setPen( QPen( color, width, style ) ); 1144 } 1145 1146 /*! 771 1147 Assign a pen 772 1148 … … 778 1154 void QwtSymbol::setPen( const QPen &pen ) 779 1155 { 780 d_data->pen = pen; 1156 if ( pen != d_data->pen ) 1157 { 1158 d_data->pen = pen; 1159 invalidateCache(); 1160 1161 if ( d_data->style == QwtSymbol::Path ) 1162 d_data->path.graphic.reset(); 1163 } 781 1164 } 782 1165 … … 815 1198 case QwtSymbol::Hexagon: 816 1199 { 817 d_data->brush.setColor( color ); 1200 if ( d_data->brush.color() != color ) 1201 { 1202 d_data->brush.setColor( color ); 1203 invalidateCache(); 1204 } 818 1205 break; 819 1206 } … … 824 1211 case QwtSymbol::Star1: 825 1212 { 826 d_data->pen.setColor( color ); 1213 if ( d_data->pen.color() != color ) 1214 { 1215 d_data->pen.setColor( color ); 1216 invalidateCache(); 1217 } 827 1218 break; 828 1219 } 829 1220 default: 830 1221 { 1222 if ( d_data->brush.color() != color || 1223 d_data->pen.color() != color ) 1224 { 1225 invalidateCache(); 1226 } 1227 831 1228 d_data->brush.setColor( color ); 832 1229 d_data->pen.setColor( color ); … … 836 1233 837 1234 /*! 838 Draw an array of symbols 1235 \brief Set and enable a pin point 1236 1237 The position of a complex symbol is not always aligned to its center 1238 ( f.e an arrow, where the peak points to a position ). The pin point 1239 defines the position inside of a Pixmap, Graphic, SvgDocument 1240 or PainterPath symbol where the represented point has to 1241 be aligned to. 1242 1243 \param pos Position 1244 \param enable En/Disable the pin point alignment 1245 1246 \sa pinPoint(), setPinPointEnabled() 1247 */ 1248 void QwtSymbol::setPinPoint( const QPointF &pos, bool enable ) 1249 { 1250 if ( d_data->pinPoint != pos ) 1251 { 1252 d_data->pinPoint = pos; 1253 if ( d_data->isPinPointEnabled ) 1254 { 1255 invalidateCache(); 1256 } 1257 } 1258 1259 setPinPointEnabled( enable ); 1260 } 1261 1262 /*! 1263 \return Pin point 1264 \sa setPinPoint(), setPinPointEnabled() 1265 */ 1266 QPointF QwtSymbol::pinPoint() const 1267 { 1268 return d_data->pinPoint; 1269 } 1270 1271 /*! 1272 En/Disable the pin point alignment 1273 1274 \param on Enabled, when on is true 1275 \sa setPinPoint(), isPinPointEnabled() 1276 */ 1277 void QwtSymbol::setPinPointEnabled( bool on ) 1278 { 1279 if ( d_data->isPinPointEnabled != on ) 1280 { 1281 d_data->isPinPointEnabled = on; 1282 invalidateCache(); 1283 } 1284 } 1285 1286 /*! 1287 \return True, when the pin point translation is enabled 1288 \sa setPinPoint(), setPinPointEnabled() 1289 */ 1290 bool QwtSymbol::isPinPointEnabled() const 1291 { 1292 return d_data->isPinPointEnabled; 1293 } 1294 1295 /*! 1296 Render an array of symbols 839 1297 840 1298 Painting several symbols is more effective than drawing symbols … … 852 1310 return; 853 1311 854 painter->save(); 855 1312 bool useCache = false; 1313 1314 // Don't use the pixmap, when the paint device 1315 // could generate scalable vectors 1316 1317 if ( QwtPainter::roundingAlignment( painter ) && 1318 !painter->transform().isScaling() ) 1319 { 1320 if ( d_data->cache.policy == QwtSymbol::Cache ) 1321 { 1322 useCache = true; 1323 } 1324 else if ( d_data->cache.policy == QwtSymbol::AutoCache ) 1325 { 1326 if ( painter->paintEngine()->type() == QPaintEngine::Raster ) 1327 { 1328 useCache = true; 1329 } 1330 else 1331 { 1332 switch( d_data->style ) 1333 { 1334 case QwtSymbol::XCross: 1335 case QwtSymbol::HLine: 1336 case QwtSymbol::VLine: 1337 case QwtSymbol::Cross: 1338 break; 1339 1340 case QwtSymbol::Pixmap: 1341 { 1342 if ( !d_data->size.isEmpty() && 1343 d_data->size != d_data->pixmap.pixmap.size() ) 1344 { 1345 useCache = true; 1346 } 1347 break; 1348 } 1349 default: 1350 useCache = true; 1351 } 1352 } 1353 } 1354 } 1355 1356 if ( useCache ) 1357 { 1358 const QRect br = boundingRect(); 1359 1360 const QRect rect( 0, 0, br.width(), br.height() ); 1361 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 ); 1368 p.setRenderHints( painter->renderHints() ); 1369 p.translate( -br.topLeft() ); 1370 1371 const QPointF pos; 1372 renderSymbols( &p, &pos, 1 ); 1373 } 1374 1375 const int dx = br.left(); 1376 const int dy = br.top(); 1377 1378 for ( int i = 0; i < numPoints; i++ ) 1379 { 1380 const int left = qRound( points[i].x() ) + dx; 1381 const int top = qRound( points[i].y() ) + dy; 1382 1383 painter->drawPixmap( left, top, d_data->cache.pixmap ); 1384 } 1385 } 1386 else 1387 { 1388 painter->save(); 1389 renderSymbols( painter, points, numPoints ); 1390 painter->restore(); 1391 } 1392 } 1393 1394 /*! 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 ) const 1407 { 1408 if ( d_data->style == QwtSymbol::NoSymbol ) 1409 return; 1410 1411 if ( d_data->style == QwtSymbol::Graphic ) 1412 { 1413 d_data->graphic.graphic.render( 1414 painter, rect, Qt::KeepAspectRatio ); 1415 } 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( 1425 painter, rect, Qt::KeepAspectRatio ); 1426 return; 1427 } 1428 else if ( d_data->style == QwtSymbol::SvgDocument ) 1429 { 1430 #ifndef QWT_NO_SVG 1431 if ( d_data->svg.renderer ) 1432 { 1433 QRectF scaledRect; 1434 1435 QSizeF sz = d_data->svg.renderer->viewBoxF().size(); 1436 if ( !sz.isEmpty() ) 1437 { 1438 sz.scale( rect.size(), Qt::KeepAspectRatio ); 1439 scaledRect.setSize( sz ); 1440 scaledRect.moveCenter( rect.center() ); 1441 } 1442 else 1443 { 1444 scaledRect = rect; 1445 } 1446 1447 d_data->svg.renderer->render( 1448 painter, scaledRect ); 1449 } 1450 #endif 1451 } 1452 else 1453 { 1454 const QRect br = boundingRect(); 1455 1456 // scale the symbol size to fit into rect. 1457 1458 const double ratio = qMin( rect.width() / br.width(), 1459 rect.height() / br.height() ); 1460 1461 painter->save(); 1462 1463 painter->translate( rect.center() ); 1464 painter->scale( ratio, ratio ); 1465 1466 const bool isPinPointEnabled = d_data->isPinPointEnabled; 1467 d_data->isPinPointEnabled = false; 1468 1469 const QPointF pos; 1470 renderSymbols( painter, &pos, 1 ); 1471 1472 d_data->isPinPointEnabled = isPinPointEnabled; 1473 1474 painter->restore(); 1475 } 1476 } 1477 1478 /*! 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 ) const 1487 { 856 1488 switch ( d_data->style ) 857 1489 { … … 934 1566 break; 935 1567 } 1568 case QwtSymbol::Path: 1569 { 1570 if ( d_data->path.graphic.isNull() ) 1571 { 1572 d_data->path.graphic = qwtPathGraphic( d_data->path.path, 1573 d_data->pen, d_data->brush ); 1574 } 1575 1576 qwtDrawGraphicSymbols( painter, points, numPoints, 1577 d_data->path.graphic, *this ); 1578 break; 1579 } 1580 case QwtSymbol::Pixmap: 1581 { 1582 qwtDrawPixmapSymbols( painter, points, numPoints, *this ); 1583 break; 1584 } 1585 case QwtSymbol::Graphic: 1586 { 1587 qwtDrawGraphicSymbols( painter, points, numPoints, 1588 d_data->graphic.graphic, *this ); 1589 break; 1590 } 1591 case QwtSymbol::SvgDocument: 1592 { 1593 #ifndef QWT_NO_SVG 1594 qwtDrawSvgSymbols( painter, points, numPoints, 1595 d_data->svg.renderer, *this ); 1596 #endif 1597 break; 1598 } 936 1599 default:; 937 1600 } 938 painter->restore(); 939 } 940 941 //! \return Size of the bounding rectangle of a symbol 942 QSize QwtSymbol::boundingSize() const 943 { 944 QSize size; 1601 } 1602 1603 /*! 1604 Calculate the bounding rectangle for a symbol 1605 at position (0,0). 1606 1607 \return Bounding rectangle 1608 */ 1609 QRect QwtSymbol::boundingRect() const 1610 { 1611 QRectF rect; 1612 1613 bool pinPointTranslation = false; 945 1614 946 1615 switch ( d_data->style ) … … 954 1623 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) ); 955 1624 956 size = d_data->size + QSize( pw, pw ); 1625 rect.setSize( d_data->size + QSizeF( pw, pw ) ); 1626 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 957 1627 958 1628 break; … … 972 1642 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) ); 973 1643 974 size = d_data->size + QSize( 2 * pw, 2 * pw ); 975 break; 976 } 1644 rect.setSize( d_data->size + QSizeF( 2 * pw, 2 * pw ) ); 1645 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1646 break; 1647 } 1648 case QwtSymbol::Path: 1649 { 1650 if ( d_data->path.graphic.isNull() ) 1651 { 1652 d_data->path.graphic = qwtPathGraphic( 1653 d_data->path.path, d_data->pen, d_data->brush ); 1654 } 1655 1656 rect = qwtScaledBoundingRect( 1657 d_data->path.graphic, d_data->size ); 1658 pinPointTranslation = true; 1659 1660 break; 1661 } 1662 case QwtSymbol::Pixmap: 1663 { 1664 if ( d_data->size.isEmpty() ) 1665 rect.setSize( d_data->pixmap.pixmap.size() ); 1666 else 1667 rect.setSize( d_data->size ); 1668 1669 pinPointTranslation = true; 1670 1671 break; 1672 } 1673 case QwtSymbol::Graphic: 1674 { 1675 rect = qwtScaledBoundingRect( 1676 d_data->graphic.graphic, d_data->size ); 1677 pinPointTranslation = true; 1678 1679 break; 1680 } 1681 #ifndef QWT_NO_SVG 1682 case QwtSymbol::SvgDocument: 1683 { 1684 if ( d_data->svg.renderer ) 1685 rect = d_data->svg.renderer->viewBoxF(); 1686 1687 if ( d_data->size.isValid() && !rect.isEmpty() ) 1688 { 1689 QSizeF sz = rect.size(); 1690 1691 const double sx = d_data->size.width() / sz.width(); 1692 const double sy = d_data->size.height() / sz.height(); 1693 1694 QTransform transform; 1695 transform.scale( sx, sy ); 1696 1697 rect = transform.mapRect( rect ); 1698 } 1699 pinPointTranslation = true; 1700 break; 1701 } 1702 #endif 977 1703 default: 978 1704 { 979 size = d_data->size; 980 } 981 } 982 983 return size + QSize( 1, 1 ); // for antialiasing 1705 rect.setSize( d_data->size ); 1706 rect.moveCenter( QPointF( 0.0, 0.0 ) ); 1707 } 1708 } 1709 1710 if ( pinPointTranslation ) 1711 { 1712 QPointF pinPoint( 0.0, 0.0 ); 1713 if ( d_data->isPinPointEnabled ) 1714 pinPoint = rect.center() - d_data->pinPoint; 1715 1716 rect.moveCenter( pinPoint ); 1717 } 1718 1719 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 ) 1726 r.adjust( -1, -1, 1, 1 ); // for antialiasing 1727 1728 return r; 1729 } 1730 1731 /*! 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() 1741 */ 1742 void QwtSymbol::invalidateCache() 1743 { 1744 if ( !d_data->cache.pixmap.isNull() ) 1745 d_data->cache.pixmap = QPixmap(); 984 1746 } 985 1747 … … 992 1754 void QwtSymbol::setStyle( QwtSymbol::Style style ) 993 1755 { 994 d_data->style = style; 1756 if ( d_data->style != style ) 1757 { 1758 d_data->style = style; 1759 invalidateCache(); 1760 } 995 1761 } 996 1762 -
trunk/BNC/qwt/qwt_symbol.h
r4271 r8127 12 12 13 13 #include "qwt_global.h" 14 #include < QPolygonF>14 #include <qpolygon.h> 15 15 16 16 class QPainter; … … 21 21 class QColor; 22 22 class QPointF; 23 class QPolygonF; 24 class QPainterPath; 25 class QPixmap; 26 class QByteArray; 27 class QwtGraphic; 23 28 24 29 //! A class for drawing symbols … … 81 86 82 87 /*! 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() 93 */ 94 Path, 95 96 /*! 97 The symbol is represented by a pixmap. The pixmap is centered 98 or aligned to its pin point. 99 100 \sa setPinPoint() 101 */ 102 Pixmap, 103 104 /*! 105 The symbol is represented by a graphic. The graphic is centered 106 or aligned to its pin point. 107 108 \sa setPinPoint() 109 */ 110 Graphic, 111 112 /*! 113 The symbol is represented by a SVG graphic. The graphic is centered 114 or aligned to its pin point. 115 116 \sa setPinPoint() 117 */ 118 SvgDocument, 119 120 /*! 83 121 Styles >= QwtSymbol::UserSymbol are reserved for derived 84 122 classes of QwtSymbol that overload drawSymbols() with … … 88 126 }; 89 127 128 /*! 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 145 to a vector graphics format ( PDF, SVG ). 146 \warning Since Qt 4.8 raster is the default backend on X11 147 */ 148 149 enum CachePolicy 150 { 151 //! Don't use a pixmap cache 152 NoCache, 153 154 //! Always use a pixmap cache 155 Cache, 156 157 /*! 158 Use a cache when one of the following conditions is true: 159 160 - The symbol is rendered with the software 161 renderer ( QPaintEngine::Raster ) 162 */ 163 AutoCache 164 }; 165 90 166 public: 91 167 QwtSymbol( Style = NoSymbol ); 92 168 QwtSymbol( Style, const QBrush &, const QPen &, const QSize & ); 93 QwtSymbol( const QwtSymbol & ); 169 QwtSymbol( const QPainterPath &, const QBrush &, const QPen & ); 170 94 171 virtual ~QwtSymbol(); 95 172 96 QwtSymbol &operator=( const QwtSymbol & ); 97 bool operator==( const QwtSymbol & ) const; 98 bool operator!=( const QwtSymbol & ) const; 173 void setCachePolicy( CachePolicy ); 174 CachePolicy cachePolicy() const; 99 175 100 176 void setSize( const QSize & ); … … 102 178 const QSize& size() const; 103 179 180 void setPinPoint( const QPointF &pos, bool enable = true ); 181 QPointF pinPoint() const; 182 183 void setPinPointEnabled( bool ); 184 bool isPinPointEnabled() const; 185 104 186 virtual void setColor( const QColor & ); 105 187 … … 107 189 const QBrush& brush() const; 108 190 191 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 109 192 void setPen( const QPen & ); 110 193 const QPen& pen() const; … … 113 196 Style style() const; 114 197 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; 206 207 #ifndef QWT_NO_SVG 208 void setSvgDocument( const QByteArray & ); 209 #endif 210 211 void drawSymbol( QPainter *, const QRectF & ) const; 115 212 void drawSymbol( QPainter *, const QPointF & ) const; 116 213 void drawSymbols( QPainter *, const QPolygonF & ) const; 117 118 virtual QSize boundingSize() const; 214 void drawSymbols( QPainter *, 215 const QPointF *, int numPoints ) const; 216 217 virtual QRect boundingRect() const; 218 void invalidateCache(); 119 219 120 220 protected: 121 virtual void drawSymbols( QPainter *,221 virtual void renderSymbols( QPainter *, 122 222 const QPointF *, int numPoints ) const; 123 223 124 224 private: 225 // Disabled copy constructor and operator= 226 QwtSymbol( const QwtSymbol & ); 227 QwtSymbol &operator=( const QwtSymbol & ); 228 125 229 class PrivateData; 126 230 PrivateData *d_data; -
trunk/BNC/qwt/qwt_system_clock.cpp
r4271 r8127 9 9 10 10 #include "qwt_system_clock.h" 11 12 #if QT_VERSION >= 0x040800 13 #define USE_ELAPSED_TIMER 1 14 #endif 15 16 #if USE_ELAPSED_TIMER 17 18 #include <qelapsedtimer.h> 19 20 class QwtSystemClock::PrivateData 21 { 22 public: 23 QElapsedTimer timer; 24 }; 25 26 QwtSystemClock::QwtSystemClock() 27 { 28 d_data = new PrivateData(); 29 } 30 31 QwtSystemClock::~QwtSystemClock() 32 { 33 delete d_data; 34 } 35 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 46 double QwtSystemClock::restart() 47 { 48 const qint64 nsecs = d_data->timer.restart(); 49 return nsecs / 1e6; 50 } 51 52 double QwtSystemClock::elapsed() const 53 { 54 const qint64 nsecs = d_data->timer.nsecsElapsed(); 55 return nsecs / 1e6; 56 } 57 58 #else // !USE_ELAPSED_TIMER 59 11 60 #include <qdatetime.h> 12 61 … … 111 160 kern_return_t err = mach_timebase_info( &info ); 112 161 113 // Convert the timebase into ms162 // convert the timebase into ms 114 163 if ( err == 0 ) 115 164 conversion = 1e-6 * ( double ) info.numer / ( double ) info.denom; … … 308 357 309 358 /*! 310 The start time to the current time and 311 return the time, that is elapsed since the 312 previous start time. 359 Set the start time to the current time 360 \return Time, that is elapsed since the previous start time. 313 361 */ 314 362 double QwtSystemClock::restart() … … 346 394 } 347 395 348 /*! 349 \return Accuracy of the system clock in milliseconds. 350 */ 351 double QwtSystemClock::precision() 352 { 353 static double prec = 0.0; 354 if ( prec <= 0.0 ) 355 { 356 #if defined(QWT_HIGH_RESOLUTION_CLOCK) 357 prec = QwtHighResolutionClock::precision(); 358 #endif 359 if ( prec <= 0.0 ) 360 prec = 1.0; // QTime offers 1 ms 361 } 362 363 return prec; 364 } 396 #endif -
trunk/BNC/qwt/qwt_system_clock.h
r4271 r8127 40 40 double elapsed() const; 41 41 42 static double precision();43 44 42 private: 45 43 class PrivateData; -
trunk/BNC/qwt/qwt_text.cpp
r4271 r8127 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen 4 * Copyright (C) 200 3Uwe Rathmann4 * Copyright (C) 2002 Uwe Rathmann 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 139 139 PrivateData(): 140 140 renderFlags( Qt::AlignCenter ), 141 backgroundPen( Qt::NoPen ), 141 borderRadius( 0 ), 142 borderPen( Qt::NoPen ), 142 143 backgroundBrush( Qt::NoBrush ), 143 144 paintAttributes( 0 ), … … 151 152 QFont font; 152 153 QColor color; 153 QPen backgroundPen; 154 double borderRadius; 155 QPen borderPen; 154 156 QBrush backgroundBrush; 155 157 … … 219 221 d_data->font == other.d_data->font && 220 222 d_data->color == other.d_data->color && 221 d_data->backgroundPen == other.d_data->backgroundPen && 223 d_data->borderRadius == other.d_data->borderRadius && 224 d_data->borderPen == other.d_data->borderPen && 222 225 d_data->backgroundBrush == other.d_data->backgroundBrush && 223 226 d_data->paintAttributes == other.d_data->paintAttributes && … … 248 251 249 252 /*! 250 Return the text.253 \return Text as QString. 251 254 \sa setText() 252 255 */ … … 261 264 The default setting is Qt::AlignCenter 262 265 263 \param renderFlags Bitwise OR of the flags used like in QPainter::drawText 266 \param renderFlags Bitwise OR of the flags used like in QPainter::drawText() 264 267 265 268 \sa renderFlags(), QwtTextEngine::draw() … … 304 307 305 308 /*! 306 Return the font of the text, if it has one. 307 Otherwise return defaultFont. 308 309 \param defaultFont Default font 310 \sa setFont(), font(), PaintAttributes 309 Return the font of the text, if it has one. 310 Otherwise return defaultFont. 311 312 \param defaultFont Default font 313 \return Font used for drawing the text 314 315 \sa setFont(), font(), PaintAttributes 311 316 */ 312 317 QFont QwtText::usedFont( const QFont &defaultFont ) const … … 319 324 320 325 /*! 321 Set the pen color used for painting the text.326 Set the pen color used for drawing the text. 322 327 323 328 \param color Color … … 342 347 343 348 \param defaultColor Default color 349 \return Color used for drawing the text 350 344 351 \sa setColor(), color(), PaintAttributes 345 352 */ … … 353 360 354 361 /*! 362 Set the radius for the corners of the border frame 363 364 \param radius Radius of a rounded corner 365 \sa borderRadius(), setBorderPen(), setBackgroundBrush() 366 */ 367 void QwtText::setBorderRadius( double radius ) 368 { 369 d_data->borderRadius = qMax( 0.0, radius ); 370 } 371 372 /*! 373 \return Radius for the corners of the border frame 374 \sa setBorderRadius(), borderPen(), backgroundBrush() 375 */ 376 double QwtText::borderRadius() const 377 { 378 return d_data->borderRadius; 379 } 380 381 /*! 355 382 Set the background pen 356 383 357 384 \param pen Background pen 358 \sa b ackgroundPen(), setBackgroundBrush()359 */ 360 void QwtText::setB ackgroundPen( const QPen &pen )361 { 362 d_data->b ackgroundPen = pen;385 \sa borderPen(), setBackgroundBrush() 386 */ 387 void QwtText::setBorderPen( const QPen &pen ) 388 { 389 d_data->borderPen = pen; 363 390 setPaintAttribute( PaintBackground ); 364 391 } … … 366 393 /*! 367 394 \return Background pen 368 \sa setB ackgroundPen(), backgroundBrush()369 */ 370 QPen QwtText::b ackgroundPen() const371 { 372 return d_data->b ackgroundPen;395 \sa setBorderPen(), backgroundBrush() 396 */ 397 QPen QwtText::borderPen() const 398 { 399 return d_data->borderPen; 373 400 } 374 401 … … 377 404 378 405 \param brush Background brush 379 \sa backgroundBrush(), setB ackgroundPen()406 \sa backgroundBrush(), setBorderPen() 380 407 */ 381 408 void QwtText::setBackgroundBrush( const QBrush &brush ) … … 387 414 /*! 388 415 \return Background brush 389 \sa setBackgroundBrush(), b ackgroundPen()416 \sa setBackgroundBrush(), borderPen() 390 417 */ 391 418 QBrush QwtText::backgroundBrush() const … … 401 428 402 429 \note Used by setFont(), setColor(), 403 setB ackgroundPen() and setBackgroundBrush()430 setBorderPen() and setBackgroundBrush() 404 431 \sa testPaintAttribute() 405 432 */ … … 492 519 493 520 /*! 494 Find the height for a given width495 496 \param defaultFont Font, used for the calculation if the text has no font497 498 \return Calculated height499 */500 501 /*!502 521 Returns the size, that is needed to render text 503 522 504 523 \param defaultFont Font of the text 505 \return Cal uclated size524 \return Calculated size 506 525 */ 507 526 QSizeF QwtText::textSize( const QFont &defaultFont ) const … … 543 562 if ( d_data->paintAttributes & PaintBackground ) 544 563 { 545 if ( d_data->b ackgroundPen != Qt::NoPen ||564 if ( d_data->borderPen != Qt::NoPen || 546 565 d_data->backgroundBrush != Qt::NoBrush ) 547 566 { 548 567 painter->save(); 549 painter->setPen( d_data->backgroundPen ); 568 569 painter->setPen( d_data->borderPen ); 550 570 painter->setBrush( d_data->backgroundBrush ); 551 QwtPainter::drawRect( painter, rect ); 571 572 if ( d_data->borderRadius == 0 ) 573 { 574 QwtPainter::drawRect( painter, rect ); 575 } 576 else 577 { 578 painter->setRenderHint( QPainter::Antialiasing, true ); 579 painter->drawRoundedRect( rect, 580 d_data->borderRadius, d_data->borderRadius ); 581 } 582 552 583 painter->restore(); 553 584 } … … 596 627 In case of QwtText::AutoText the first text engine 597 628 (beside QwtPlainTextEngine) is returned, where QwtTextEngine::mightRender 598 returns true. If there is none QwtPlainTextEngine is return d.629 returns true. If there is none QwtPlainTextEngine is returned. 599 630 600 631 If no text engine is registered for the format QwtPlainTextEngine … … 603 634 \param text Text, needed in case of AutoText 604 635 \param format Text format 636 637 \return Corresponding text engine 605 638 */ 606 639 const QwtTextEngine *QwtText::textEngine( const QString &text, -
trunk/BNC/qwt/qwt_text.h
r4271 r8127 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen 4 * Copyright (C) 200 3Uwe Rathmann4 * Copyright (C) 2002 Uwe Rathmann 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 15 15 #include <qsize.h> 16 16 #include <qfont.h> 17 #include <qmetatype.h> 17 18 18 19 class QColor; … … 32 33 how to render it. Each format (f.e MathML, TeX, Qt Rich Text) 33 34 has its own set of control sequences, that can be handles by 34 a QwtTextEngine for this format.35 a special QwtTextEngine for this format. 35 36 - Background\n 36 37 A text might have a background, defined by a QPen and QBrush 37 to improve its visibility. 38 to improve its visibility. The corners of the background might 39 be rounded. 38 40 - Font\n 39 41 A text might have an individual font. … … 42 44 - Render Flags\n 43 45 Flags from Qt::AlignmentFlag and Qt::TextFlag used like in 44 QPainter::drawText .46 QPainter::drawText(). 45 47 46 48 \sa QwtTextEngine, QwtTextLabel … … 63 65 { 64 66 /*! 65 The text format is determined using QwtTextEngine::mightRender for67 The text format is determined using QwtTextEngine::mightRender() for 66 68 all available text engines in increasing order > PlainText. 67 69 If none of the text engines can render the text is rendered … … 168 170 QColor usedColor( const QColor & ) const; 169 171 170 void setBackgroundPen( const QPen & ); 171 QPen backgroundPen() const; 172 void setBorderRadius( double ); 173 double borderRadius() const; 174 175 void setBorderPen( const QPen & ); 176 QPen borderPen() const; 172 177 173 178 void setBackgroundBrush( const QBrush & ); … … 214 219 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::LayoutAttributes ) 215 220 221 Q_DECLARE_METATYPE( QwtText ) 222 216 223 #endif -
trunk/BNC/qwt/qwt_text_engine.cpp
r4271 r8127 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen 4 * Copyright (C) 200 3Uwe Rathmann4 * Copyright (C) 2002 Uwe Rathmann 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 62 62 option.setWrapMode( QTextOption::NoWrap ); 63 63 64 option.setAlignment( ( Qt::Alignment ) flags);64 option.setAlignment( static_cast<Qt::Alignment>( flags ) ); 65 65 setDefaultTextOption( option ); 66 66 … … 116 116 for ( row = 0; row < img.height(); row++ ) 117 117 { 118 const QRgb *line = ( const QRgb * )img.scanLine( row ); 118 const QRgb *line = reinterpret_cast<const QRgb *>( 119 img.scanLine( row ) ); 119 120 120 121 const int w = pm.width(); … … 181 182 \param text Text to be rendered 182 183 183 \return Cal uclated size184 \return Calculated size 184 185 */ 185 186 QSizeF QwtPlainTextEngine::textSize( const QFont &font, … … 248 249 249 250 \param font Font of the text 250 \param flags Bitwise OR of the flags used like in QPainter::drawText 251 \param flags Bitwise OR of the flags used like in QPainter::drawText() 251 252 \param text Text to be rendered 252 253 \param width Width … … 267 268 268 269 \param font Font of the text 269 \param flags Bitwise OR of the flags used like in QPainter::drawText 270 \param flags Bitwise OR of the flags used like in QPainter::drawText() 270 271 \param text Text to be rendered 271 272 272 \return Cal uclated size273 \return Calculated size 273 274 */ 274 275 … … 294 295 \param painter Painter 295 296 \param rect Clipping rectangle 296 \param flags Bitwise OR of the flags like in for QPainter::drawText 297 \param flags Bitwise OR of the flags like in for QPainter::drawText() 297 298 \param text Text to be rendered 298 299 */ … … 308 309 309 310 \param text Text 310 \param flags Bitwise OR of the flags like in for QPainter::drawText 311 \param flags Bitwise OR of the flags like in for QPainter::drawText() 311 312 312 313 \return Tagged text … … 321 322 322 323 \param text Text to be tested 323 \return Q StyleSheet::mightBeRichText(text);324 \return Qt::mightBeRichText(text); 324 325 */ 325 326 bool QwtRichTextEngine::mightRender( const QString &text ) const -
trunk/BNC/qwt/qwt_text_engine.h
r4271 r8127 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen 4 * Copyright (C) 200 3Uwe Rathmann4 * Copyright (C) 2002 Uwe Rathmann 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 58 58 \param text Text to be rendered 59 59 60 \return Cal uclated size60 \return Calculated size 61 61 */ 62 62 virtual QSizeF textSize( const QFont &font, int flags, … … 75 75 76 76 The textSize might include margins around the 77 text, like QFontMetrics::descent . In situations78 where texts need to be alig end in detail, knowing77 text, like QFontMetrics::descent(). In situations 78 where texts need to be aligned in detail, knowing 79 79 these margins might improve the layout calculations. 80 80 … … 94 94 \param painter Painter 95 95 \param rect Clipping rectangle 96 \param flags Bitwise OR of the flags like in for QPainter::drawText 96 \param flags Bitwise OR of the flags like in for QPainter::drawText() 97 97 \param text Text to be rendered 98 98 */ -
trunk/BNC/qwt/qwt_text_label.cpp
r4271 r8127 64 64 65 65 /*! 66 Interface for the designer plugin - does the same as setText() 67 \sa plainText() 68 */ 69 void QwtTextLabel::setPlainText( const QString &text ) 70 { 71 setText( QwtText( text ) ); 72 } 73 74 /*! 75 Interface for the designer plugin 76 77 \return Text as plain text 78 \sa setPlainText(), text() 79 */ 80 QString QwtTextLabel::plainText() const 81 { 82 return d_data->text.text(); 83 } 84 85 /*! 66 86 Change the label's text, keeping all other QwtText attributes 67 87 \param text New text … … 70 90 \sa QwtText 71 91 */ 72 void QwtTextLabel::setText( const QString &text, QwtText::TextFormat textFormat ) 92 void QwtTextLabel::setText( const QString &text, 93 QwtText::TextFormat textFormat ) 73 94 { 74 95 d_data->text.setText( text, textFormat ); … … 126 147 } 127 148 128 //! Return label's text indentin pixels149 //! Return label's text margin in pixels 129 150 int QwtTextLabel::margin() const 130 151 { … … 144 165 } 145 166 146 //! Return label's margin in pixels167 //! Return a size hint 147 168 QSize QwtTextLabel::sizeHint() const 148 169 { … … 177 198 178 199 /*! 179 Returns the preferred height for this widget, given the width.180 200 \param width Width 201 \return Preferred height for this widget, given the width. 181 202 */ 182 203 int QwtTextLabel::heightForWidth( int width ) const … … 192 213 width -= indent; 193 214 194 int height = d_data->text.heightForWidth( width, font() );195 if ( renderFlags & Qt::AlignTop || renderFlags & Qt::AlignBottom)215 int height = qCeil( d_data->text.heightForWidth( width, font() ) ); 216 if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) ) 196 217 height += indent; 197 218 … … 232 253 painter->setPen( palette().color( QPalette::Active, QPalette::Text ) ); 233 254 234 drawText( painter, r);255 drawText( painter, QRectF( r ) ); 235 256 236 257 if ( hasFocus() ) 237 258 { 238 const int margin = 2; 239 240 QRect focusRect = contentsRect(); 241 focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin, 242 focusRect.width() - 2 * margin - 2, 243 focusRect.height() - 2 * margin - 2 ); 259 const int m = 2; 260 261 QRect focusRect = contentsRect().adjusted( m, m, -m + 1, -m + 1); 244 262 245 263 QwtPainter::drawFocusRect( painter, this, focusRect ); … … 248 266 249 267 //! Redraw the text 250 void QwtTextLabel::drawText( QPainter *painter, const QRect &textRect )268 void QwtTextLabel::drawText( QPainter *painter, const QRectF &textRect ) 251 269 { 252 270 d_data->text.draw( painter, textRect ); … … 254 272 255 273 /*! 256 Calculate the rectfor the text in widget coordinates257 \return Text rect274 Calculate geometry for the text in widget coordinates 275 \return Geometry for the text 258 276 */ 259 277 QRect QwtTextLabel::textRect() const -
trunk/BNC/qwt/qwt_text_label.h
r4271 r8127 29 29 Q_PROPERTY( int indent READ indent WRITE setIndent ) 30 30 Q_PROPERTY( int margin READ margin WRITE setMargin ) 31 Q_PROPERTY( QString plainText READ plainText WRITE setPlainText ) 31 32 32 33 public: … … 34 35 explicit QwtTextLabel( const QwtText &, QWidget *parent = NULL ); 35 36 virtual ~QwtTextLabel(); 37 38 void setPlainText( const QString & ); 39 QString plainText() const; 36 40 37 41 public Q_SLOTS: … … 57 61 QRect textRect() const; 58 62 63 virtual void drawText( QPainter *, const QRectF & ); 64 59 65 protected: 60 66 virtual void paintEvent( QPaintEvent *e ); 61 67 virtual void drawContents( QPainter * ); 62 virtual void drawText( QPainter *, const QRect & );63 68 64 69 private: -
trunk/BNC/qwtpolar/qwt_polar_canvas.cpp
r4272 r8127 9 9 #include "qwt_polar_canvas.h" 10 10 #include "qwt_polar_plot.h" 11 #include <qwt_painter.h> 11 12 #include <qpainter.h> 12 13 #include <qevent.h> … … 213 214 { 214 215 QWidget *bgWidget = qwtBackgroundWidget( plot() ); 215 bs.fill( bgWidget, mapTo( bgWidget, rect().topLeft() ) ); 216 217 QwtPainter::fillPixmap( bgWidget, bs, 218 mapTo( bgWidget, rect().topLeft() ) ); 219 216 220 p.begin( &bs ); 217 221 } -
trunk/BNC/qwtpolar/qwt_polar_curve.cpp
r7990 r8127 14 14 #include <qwt_symbol.h> 15 15 #include <qwt_legend.h> 16 #include <qwt_legend_item.h>17 16 #include <qwt_curve_fitter.h> 18 17 #include <qwt_clipper.h> … … 174 173 \sa symbol() 175 174 */ 176 void QwtPolarCurve::setSymbol( constQwtSymbol *symbol )175 void QwtPolarCurve::setSymbol( QwtSymbol *symbol ) 177 176 { 178 177 if ( symbol != d_data->symbol ) … … 434 433 if ( !clipRect.isEmpty() ) 435 434 { 436 double off = qCeil( qMax( qreal(1.0), painter->pen().widthF() ) );435 double off = qCeil( qMax( qreal( 1.0 ), painter->pen().widthF() ) ); 437 436 clipRect = clipRect.toRect().adjusted( -off, -off, off, off ); 438 437 polyline = QwtClipper::clipPolygonF( clipRect, polyline ); … … 501 500 } 502 501 503 //! Update the widget that represents the curve on the legend 504 void QwtPolarCurve::updateLegend( QwtLegend *legend ) const 505 { 506 if ( legend && testItemAttribute( QwtPolarCurve::Legend ) 507 && ( d_data->legendAttributes & QwtPolarCurve::LegendShowSymbol ) 508 && d_data->symbol 509 && d_data->symbol->style() != QwtSymbol::NoSymbol ) 510 { 511 QWidget *lgdItem = legend->find( this ); 512 if ( lgdItem == NULL ) 513 { 514 lgdItem = legendItem(); 515 if ( lgdItem ) 516 legend->insert( this, lgdItem ); 517 } 518 519 QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem ); 520 if ( l ) 521 { 522 QSize sz = d_data->symbol->boundingSize(); 523 sz += QSize( 2, 2 ); // margin 524 525 if ( d_data->legendAttributes & QwtPolarCurve::LegendShowLine ) 526 { 527 // Avoid, that the line is completely covered by the symbol 528 529 int w = qCeil( 1.5 * sz.width() ); 530 if ( w % 2 ) 531 w++; 532 533 sz.setWidth( qMax( 8, w ) ); 534 } 535 536 l->setIdentifierSize( sz ); 537 } 538 } 539 540 QwtPolarItem::updateLegend( legend ); 541 } 542 543 /*! 544 \brief Draw the identifier representing the curve on the legend 545 546 \param painter Qt Painter 547 \param rect Bounding rectangle for the identifier 548 549 \sa setLegendAttribute 550 */ 551 void QwtPolarCurve::drawLegendIdentifier( 552 QPainter *painter, const QRectF &rect ) const 553 { 554 if ( rect.isEmpty() ) 555 return; 556 557 const double dim = qMin( rect.width(), rect.height() ); 558 559 QSizeF size( dim, dim ); 560 561 QRectF r( 0, 0, size.width(), size.height() ); 562 r.moveCenter( rect.center() ); 502 /*! 503 \return Icon representing the curve on the legend 504 505 \param index Index of the legend entry 506 ( ignored as there is only one ) 507 \param size Icon size 508 509 \sa QwtPolarItem::setLegendIconSize(), QwtPolarItem::legendData() 510 */ 511 QwtGraphic QwtPolarCurve::legendIcon( int index, 512 const QSizeF &size ) const 513 { 514 Q_UNUSED( index ); 515 516 if ( size.isEmpty() ) 517 return QwtGraphic(); 518 519 QwtGraphic graphic; 520 graphic.setDefaultSize( size ); 521 graphic.setRenderHint( QwtGraphic::RenderPensUnscaled, true ); 522 523 QPainter painter( &graphic ); 524 painter.setRenderHint( QPainter::Antialiasing, 525 testRenderHint( QwtPolarItem::RenderAntialiased ) ); 563 526 564 527 if ( d_data->legendAttributes == 0 ) 565 528 { 566 529 QBrush brush; 530 567 531 if ( style() != QwtPolarCurve::NoCurve ) 532 { 568 533 brush = QBrush( pen().color() ); 534 } 569 535 else if ( d_data->symbol && 570 536 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) … … 572 538 brush = QBrush( d_data->symbol->pen().color() ); 573 539 } 540 574 541 if ( brush.style() != Qt::NoBrush ) 575 painter->fillRect( r, brush ); 576 } 542 { 543 QRectF r( 0, 0, size.width(), size.height() ); 544 painter.fillRect( r, brush ); 545 } 546 } 547 577 548 if ( d_data->legendAttributes & QwtPolarCurve::LegendShowLine ) 578 549 { 579 550 if ( pen() != Qt::NoPen ) 580 551 { 581 painter->setPen( pen() ); 582 QwtPainter::drawLine( painter, rect.left(), rect.center().y(), 583 rect.right() - 1.0, rect.center().y() ); 584 } 585 } 552 QPen pn = pen(); 553 pn.setCapStyle( Qt::FlatCap ); 554 555 painter.setPen( pn ); 556 557 const double y = 0.5 * size.height(); 558 QwtPainter::drawLine( &painter, 0.0, y, size.width(), y ); 559 } 560 } 561 586 562 if ( d_data->legendAttributes & QwtPolarCurve::LegendShowSymbol ) 587 563 { 588 if ( d_data->symbol && 589 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) 590 { 591 QSize symbolSize = d_data->symbol->boundingSize(); 592 symbolSize -= QSize( 2, 2 ); 593 594 // scale the symbol size down if it doesn't fit into rect. 595 596 double xRatio = 1.0; 597 if ( rect.width() < symbolSize.width() ) 598 xRatio = rect.width() / symbolSize.width(); 599 double yRatio = 1.0; 600 if ( rect.height() < symbolSize.height() ) 601 yRatio = rect.height() / symbolSize.height(); 602 603 const double ratio = qMin( xRatio, yRatio ); 604 605 painter->save(); 606 painter->scale( ratio, ratio ); 607 608 d_data->symbol->drawSymbol( painter, rect.center() / ratio ); 609 610 painter->restore(); 611 } 612 } 564 if ( d_data->symbol ) 565 { 566 QRectF r( 0, 0, size.width(), size.height() ); 567 d_data->symbol->drawSymbol( &painter, r ); 568 } 569 } 570 571 return graphic; 613 572 } 614 573 … … 634 593 return QwtInterval(); 635 594 } 595 596 -
trunk/BNC/qwtpolar/qwt_polar_curve.h
r4272 r8127 58 58 In the default setting all attributes are off. 59 59 60 \sa setLegendAttribute(), testLegendAttribute(), 61 drawLegendIdentifier() 60 \sa setLegendAttribute(), testLegendAttribute() 62 61 */ 63 62 … … 101 100 CurveStyle style() const; 102 101 103 void setSymbol( constQwtSymbol * );102 void setSymbol( QwtSymbol * ); 104 103 const QwtSymbol *symbol() const; 105 104 … … 116 115 const QPointF &pole, int from, int to ) const; 117 116 118 virtual void updateLegend( QwtLegend * ) const;119 117 virtual QwtInterval boundingInterval( int scaleId ) const; 120 118 121 virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const;119 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 122 120 123 121 protected: -
trunk/BNC/qwtpolar/qwt_polar_global.h
r4272 r8127 14 14 // QWT_POLAR_VERSION is (major << 16) + (minor << 8) + patch. 15 15 16 #define QWT_POLAR_VERSION 0x010000 17 #define QWT_POLAR_VERSION_STR "1.0.0" 18 19 #if defined(Q_WS_WIN) || defined(Q_WS_S60) 16 #define QWT_POLAR_VERSION 0x010101 17 #define QWT_POLAR_VERSION_STR "1.1.1" 20 18 21 19 #if defined(_MSC_VER) /* MSVC Compiler */ … … 26 24 #ifdef QWT_POLAR_DLL 27 25 28 #if defined(QWT_POLAR_MAKEDLL) // create a QwtDLL library29 #define QWT_POLAR_EXPORT __declspec(dllexport)26 #if defined(QWT_POLAR_MAKEDLL) // create DLL library 27 #define QWT_POLAR_EXPORT Q_DECL_EXPORT 30 28 #define QWT_POLAR_TEMPLATEDLL 31 #else // use a QwtDLL library32 #define QWT_POLAR_EXPORT __declspec(dllimport)29 #else // use DLL library 30 #define QWT_POLAR_EXPORT Q_DECL_IMPORT 33 31 #endif 34 32 35 #endif // QWT_POLAR_MAKEDLL 36 37 #endif // Q_WS_WIN 33 #endif // QWT_POLAR_DLL 38 34 39 35 #ifndef QWT_POLAR_EXPORT -
trunk/BNC/qwtpolar/qwt_polar_grid.cpp
r4272 r8127 877 877 878 878 scaleDraw->setAngleRange( from, from - 360.0 ); 879 scaleDraw->setTransformation( azimuthMap.transformation()->copy() ); 879 880 const QwtTransform *transform = azimuthMap.transformation(); 881 if ( transform ) 882 scaleDraw->setTransformation( transform->copy() ); 883 else 884 scaleDraw->setTransformation( NULL ); 880 885 } 881 886 else … … 911 916 } 912 917 } 913 scaleDraw->setTransformation( radialMap.transformation()->copy() ); 918 const QwtTransform *transform = radialMap.transformation(); 919 if ( transform ) 920 scaleDraw->setTransformation( transform->copy() ); 921 else 922 scaleDraw->setTransformation( NULL ); 914 923 } 915 924 } … … 976 985 QwtScaleDiv sd = radialGrid.scaleDiv; 977 986 978 QList<double> &ticks = 979 const_cast<QList<double> &>( sd.ticks( QwtScaleDiv::MajorTick ) ); 987 QList<double> ticks = sd.ticks( QwtScaleDiv::MajorTick ); 980 988 981 989 if ( testDisplayFlag( SmartOriginLabel ) ) … … 1011 1019 } 1012 1020 1021 sd.setTicks( QwtScaleDiv::MajorTick, ticks ); 1013 1022 axis.scaleDraw->setScaleDiv( sd ); 1014 1023 … … 1049 1058 const QwtScaleDraw *QwtPolarGrid::scaleDraw( int axisId ) const 1050 1059 { 1051 if ( axisId >= QwtPolar::AxisLeft ||axisId <= QwtPolar::AxisBottom )1060 if ( axisId >= QwtPolar::AxisLeft && axisId <= QwtPolar::AxisBottom ) 1052 1061 return static_cast<QwtScaleDraw *>( d_data->axisData[axisId].scaleDraw ); 1053 1062 … … 1064 1073 QwtScaleDraw *QwtPolarGrid::scaleDraw( int axisId ) 1065 1074 { 1066 if ( axisId >= QwtPolar::AxisLeft ||axisId <= QwtPolar::AxisBottom )1075 if ( axisId >= QwtPolar::AxisLeft && axisId <= QwtPolar::AxisBottom ) 1067 1076 return static_cast<QwtScaleDraw *>( d_data->axisData[axisId].scaleDraw ); 1068 1077 -
trunk/BNC/qwtpolar/qwt_polar_item.cpp
r4272 r8127 10 10 #include "qwt_polar_item.h" 11 11 #include <qwt_legend.h> 12 #include <qwt_legend_item.h>13 12 #include <qwt_scale_div.h> 14 13 #include <qpainter.h> … … 22 21 attributes( 0 ), 23 22 renderHints( 0 ), 24 z( 0.0 ) 23 renderThreadCount( 1 ), 24 z( 0.0 ), 25 legendIconSize( 8, 8 ) 25 26 { 26 27 } … … 31 32 QwtPolarItem::ItemAttributes attributes; 32 33 QwtPolarItem::RenderHints renderHints; 34 uint renderThreadCount; 35 33 36 double z; 34 37 35 38 QwtText title; 39 QSize legendIconSize; 36 40 }; 37 41 … … 74 78 return; 75 79 76 // remove the item from the previous plot77 78 80 if ( d_data->plot ) 79 {80 if ( d_data->plot->legend() )81 d_data->plot->legend()->remove( this );82 83 81 d_data->plot->attachItem( this, false ); 84 82 85 if ( d_data->plot->autoReplot() )86 d_data->plot->update();87 }88 89 83 d_data->plot = plot; 90 84 91 85 if ( d_data->plot ) 92 {93 // insert the item into the current plot94 95 86 d_data->plot->attachItem( this, true ); 96 itemChanged(); 97 } 87 } 88 89 /*! 90 \brief This method detaches a QwtPolarItem from the QwtPolarPlot it 91 has been associated with. 92 93 detach() is equivalent to calling attach( NULL ) 94 \sa attach() 95 */ 96 void QwtPolarItem::detach() 97 { 98 attach( NULL ); 98 99 } 99 100 … … 257 258 } 258 259 260 /*! 261 On multi core systems rendering of certain plot item 262 ( f.e QwtPolarSpectrogram ) can be done in parallel in 263 several threads. 264 265 The default setting is set to 1. 266 267 \param numThreads Number of threads to be used for rendering. 268 If numThreads is set to 0, the system specific 269 ideal thread count is used. 270 271 The default thread count is 1 ( = no additional threads ) 272 */ 273 void QwtPolarItem::setRenderThreadCount( uint numThreads ) 274 { 275 d_data->renderThreadCount = numThreads; 276 } 277 278 /*! 279 \return Number of threads to be used for rendering. 280 If numThreads() is set to 0, the system specific 281 ideal thread count is used. 282 */ 283 uint QwtPolarItem::renderThreadCount() const 284 { 285 return d_data->renderThreadCount; 286 } 287 288 /*! 289 Set the size of the legend icon 290 291 The default setting is 8x8 pixels 292 293 \param size Size 294 \sa legendIconSize(), legendIcon() 295 */ 296 void QwtPolarItem::setLegendIconSize( const QSize &size ) 297 { 298 if ( d_data->legendIconSize != size ) 299 { 300 d_data->legendIconSize = size; 301 legendChanged(); 302 } 303 } 304 305 /*! 306 \return Legend icon size 307 \sa setLegendIconSize(), legendIcon() 308 */ 309 QSize QwtPolarItem::legendIconSize() const 310 { 311 return d_data->legendIconSize; 312 } 313 259 314 //! Show the item 260 315 void QwtPolarItem::show() … … 302 357 { 303 358 if ( d_data->plot ) 304 {305 if ( d_data->plot->legend() )306 updateLegend( d_data->plot->legend() );307 308 359 d_data->plot->autoRefresh(); 309 } 360 } 361 362 /*! 363 Update the legend of the parent plot. 364 \sa QwtPolarPlot::updateLegend(), itemChanged() 365 */ 366 void QwtPolarItem::legendChanged() 367 { 368 if ( testItemAttribute( QwtPolarItem::Legend ) && d_data->plot ) 369 d_data->plot->updateLegend( this ); 310 370 } 311 371 … … 351 411 352 412 /*! 353 \brief Update the widget that represents the item on the legend 354 355 updateLegend() is called from itemChanged() to adopt the widget 356 representing the item on the legend to its new configuration. 357 358 The default implementation is made for QwtPolarCurve and updates a 359 QwtLegendItem(), but an item could be represented by any type of widget, 360 by overloading legendItem() and updateLegend(). 361 362 \sa legendItem(), itemChanged(), QwtLegend() 363 */ 364 void QwtPolarItem::updateLegend( QwtLegend *legend ) const 365 { 366 if ( legend == NULL ) 367 return; 368 369 QWidget *lgdItem = legend->find( this ); 370 if ( testItemAttribute( QwtPolarItem::Legend ) ) 371 { 372 if ( lgdItem == NULL ) 373 { 374 lgdItem = legendItem(); 375 if ( lgdItem ) 376 legend->insert( this, lgdItem ); 377 } 378 379 QwtLegendItem* label = qobject_cast<QwtLegendItem *>( lgdItem ); 380 if ( label ) 381 { 382 // paint the identifier 383 const QSize sz = label->identifierSize(); 384 385 QPixmap identifier( sz.width(), sz.height() ); 386 identifier.fill( Qt::transparent ); 387 388 QPainter painter( &identifier ); 389 painter.setRenderHint( QPainter::Antialiasing, 390 testRenderHint( QwtPolarItem::RenderAntialiased ) ); 391 392 drawLegendIdentifier( &painter, 393 QRect( 0, 0, sz.width(), sz.height() ) ); 394 395 painter.end(); 396 397 const bool doUpdate = label->updatesEnabled(); 398 if ( doUpdate ) 399 label->setUpdatesEnabled( false ); 400 401 label->setText( title() ); 402 label->setIdentifier( identifier ); 403 label->setItemMode( legend->itemMode() ); 404 405 if ( doUpdate ) 406 label->setUpdatesEnabled( true ); 407 408 label->update(); 409 } 410 } 411 else 412 { 413 if ( lgdItem ) 414 { 415 lgdItem->hide(); 416 lgdItem->deleteLater(); 417 } 418 } 419 } 420 /*! 421 \brief Allocate the widget that represents the item on the legend 422 423 The default implementation is made for QwtPolarCurve and returns a 424 QwtLegendItem(), but an item could be represented by any type of widget, 425 by overloading legendItem() and updateLegend(). 426 427 \return QwtLegendItem() 428 \sa updateLegend() QwtLegend() 429 */ 430 QWidget *QwtPolarItem::legendItem() const 431 { 432 QwtLegendItem *item = new QwtLegendItem; 433 if ( d_data->plot ) 434 { 435 QObject::connect( item, SIGNAL( clicked() ), 436 d_data->plot, SLOT( legendItemClicked() ) ); 437 QObject::connect( item, SIGNAL( checked( bool ) ), 438 d_data->plot, SLOT( legendItemChecked( bool ) ) ); 439 } 440 return item; 413 \brief Return all information, that is needed to represent 414 the item on the legend 415 416 Most items are represented by one entry on the legend 417 showing an icon and a text. 418 419 QwtLegendData is basically a list of QVariants that makes it 420 possible to overload and reimplement legendData() to 421 return almost any type of information, that is understood 422 by the receiver that acts as the legend. 423 424 The default implementation returns one entry with 425 the title() of the item and the legendIcon(). 426 427 \sa title(), legendIcon(), QwtLegend 428 */ 429 QList<QwtLegendData> QwtPolarItem::legendData() const 430 { 431 QwtLegendData data; 432 433 QwtText label = title(); 434 label.setRenderFlags( label.renderFlags() & Qt::AlignLeft ); 435 436 QVariant titleValue; 437 qVariantSetValue( titleValue, label ); 438 data.setValue( QwtLegendData::TitleRole, titleValue ); 439 440 const QwtGraphic graphic = legendIcon( 0, legendIconSize() ); 441 if ( !graphic.isNull() ) 442 { 443 QVariant iconValue; 444 qVariantSetValue( iconValue, graphic ); 445 data.setValue( QwtLegendData::IconRole, iconValue ); 446 } 447 448 QList<QwtLegendData> list; 449 list += data; 450 451 return list; 452 } 453 454 /*! 455 \return Icon representing the item on the legend 456 457 The default implementation returns an invalid icon 458 459 \param index Index of the legend entry 460 ( usually there is only one ) 461 \param size Icon size 462 463 \sa setLegendIconSize(), legendData() 464 */ 465 QwtGraphic QwtPolarItem::legendIcon( 466 int index, const QSizeF &size ) const 467 { 468 Q_UNUSED( index ) 469 Q_UNUSED( size ) 470 471 return QwtGraphic(); 441 472 } 442 473 -
trunk/BNC/qwtpolar/qwt_polar_item.h
r4272 r8127 12 12 #include "qwt_polar_global.h" 13 13 #include <qwt_text.h> 14 #include <qwt_legend_itemmanager.h> 14 #include <qwt_legend_data.h> 15 #include <qwt_graphic.h> 15 16 #include <qwt_interval.h> 16 17 … … 34 35 types of items. 35 36 */ 36 class QWT_POLAR_EXPORT QwtPolarItem : public QwtLegendItemManager37 class QWT_POLAR_EXPORT QwtPolarItem 37 38 { 38 39 public: … … 103 104 104 105 void attach( QwtPolarPlot *plot ); 105 106 /*! 107 \brief This method detaches a QwtPolarItem from any QwtPolarPlot it 108 has been associated with. 109 110 detach() is equivalent to calling attach( NULL ) 111 \sa attach( QwtPolarPlot* plot ) 112 */ 113 void detach() { attach( NULL ); } 106 void detach(); 114 107 115 108 QwtPolarPlot *plot() const; … … 127 120 bool testRenderHint( RenderHint ) const; 128 121 122 void setRenderThreadCount( uint numThreads ); 123 uint renderThreadCount() const; 124 129 125 double z() const; 130 126 void setZ( double z ); … … 136 132 137 133 virtual void itemChanged(); 134 virtual void legendChanged(); 138 135 139 136 /*! … … 154 151 virtual QwtInterval boundingInterval( int scaleId ) const; 155 152 156 virtual QWidget *legendItem() const;157 158 virtual void updateLegend( QwtLegend * ) const;159 153 virtual void updateScaleDiv( const QwtScaleDiv &, 160 154 const QwtScaleDiv &, const QwtInterval & ); 161 155 162 156 virtual int marginHint() const; 157 158 void setLegendIconSize( const QSize & ); 159 QSize legendIconSize() const; 160 161 virtual QList<QwtLegendData> legendData() const; 162 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 163 163 164 164 private: … … 174 174 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPolarItem::RenderHints ) 175 175 176 Q_DECLARE_METATYPE( QwtPolarItem * ) 177 176 178 #endif -
trunk/BNC/qwtpolar/qwt_polar_itemdict.cpp
r4272 r8127 110 110 111 111 /*! 112 Attach/Detacha plot item112 Insert a plot item 113 113 114 Attached items will be deleted in the destructor, 115 if auto deletion is enabled (default). Manually detached 116 items are not deleted. 114 \param item PlotItem 115 \sa removeItem() 116 */ 117 void QwtPolarItemDict::insertItem( QwtPolarItem *item ) 118 { 119 d_data->itemList.insertItem( item ); 120 } 117 121 118 \param item Plot item to attach/detach 119 \ on If true attach, else detach theitem122 /*! 123 Remove a plot item 120 124 121 \sa setAutoDelete, ~QwtPolarItemDict 122 */ 123 void QwtPolarItemDict::attachItem( QwtPolarItem *item, bool on ) 125 \param item PlotItem 126 \sa insertItem() 127 */ 128 void QwtPolarItemDict::removeItem( QwtPolarItem *item ) 124 129 { 125 if ( on ) 126 d_data->itemList.insertItem( item ); 127 else 128 d_data->itemList.removeItem( item ); 130 d_data->itemList.removeItem( item ); 129 131 } 130 132 -
trunk/BNC/qwtpolar/qwt_polar_itemdict.h
r4272 r8127 44 44 bool autoDelete = true ); 45 45 46 protected: 47 void insertItem( QwtPolarItem * ); 48 void removeItem( QwtPolarItem * ); 49 46 50 private: 47 friend class QwtPolarItem;48 49 void attachItem( QwtPolarItem *, bool );50 51 51 class PrivateData; 52 52 PrivateData *d_data; -
trunk/BNC/qwtpolar/qwt_polar_layout.cpp
r7990 r8127 23 23 { 24 24 int frameWidth; 25 int vScrollBarWidth;26 int hScrollBarHeight;25 int hScrollExtent; 26 int vScrollExtent; 27 27 QSizeF hint; 28 28 } legend; … … 49 49 { 50 50 legend.frameWidth = plot->legend()->frameWidth(); 51 legend. vScrollBarWidth=52 plot->legend()-> verticalScrollBar()->sizeHint().width();53 legend. hScrollBarHeight =54 plot->legend()-> horizontalScrollBar()->sizeHint().height();51 legend.hScrollExtent = 52 plot->legend()->scrollExtent( Qt::Horizontal ); 53 legend.vScrollExtent = 54 plot->legend()->scrollExtent( Qt::Vertical ); 55 55 56 56 const QSizeF hint = plot->legend()->sizeHint(); … … 62 62 63 63 if ( h > rect.height() ) 64 w += legend. vScrollBarWidth;64 w += legend.hScrollExtent; 65 65 66 66 legend.hint = QSizeF( w, h ); … … 279 279 // half of the available space. 280 280 281 dim = qMin( hint.width(), qreal(rect.width() * d_data->legendRatio));281 dim = qMin( double( hint.width() ), rect.width() * d_data->legendRatio ); 282 282 283 283 if ( !( options & IgnoreScrollbars ) ) … … 288 288 // space for the vertical scrollbar. 289 289 290 dim += d_data->layoutData.legend. vScrollBarWidth;290 dim += d_data->layoutData.legend.hScrollExtent; 291 291 } 292 292 } … … 294 294 else 295 295 { 296 dim = qMin( hint.width(), qreal(rect.width() * d_data->legendRatio));297 dim = qMax( dim, d_data->layoutData.legend. hScrollBarHeight );296 dim = qMin( double( hint.height() ), rect.height() * d_data->legendRatio ); 297 dim = qMax( dim, d_data->layoutData.legend.vScrollExtent ); 298 298 } 299 299 -
trunk/BNC/qwtpolar/qwt_polar_plot.cpp
r4272 r8127 16 16 #include <qwt_round_scale_draw.h> 17 17 #include <qwt_legend.h> 18 #include <qwt_legend_item.h>19 18 #include <qwt_dyngrid_layout.h> 20 19 #include <qpointer.h> … … 35 34 public: 36 35 ScaleData(): 36 isValid( false ), 37 37 scaleEngine( NULL ) 38 38 { … … 53 53 int maxMinor; 54 54 55 bool isValid; 56 55 57 QwtScaleDiv scaleDiv; 56 58 QwtScaleEngine *scaleEngine; … … 70 72 QPointer<QwtTextLabel> titleLabel; 71 73 QPointer<QwtPolarCanvas> canvas; 72 QPointer<Qwt Legend> legend;74 QPointer<QwtAbstractLegend> legend; 73 75 double azimuthOrigin; 74 76 … … 183 185 QwtPolarLayout::setLegendPosition() 184 186 */ 185 void QwtPolarPlot::insertLegend( Qwt Legend *legend,187 void QwtPolarPlot::insertLegend( QwtAbstractLegend *legend, 186 188 QwtPolarPlot::LegendPosition pos, double ratio ) 187 189 { 188 190 d_data->layout->setLegendPosition( pos, ratio ); 191 189 192 if ( legend != d_data->legend ) 190 193 { … … 196 199 if ( d_data->legend ) 197 200 { 198 if ( pos != ExternalLegend ) 201 connect( this, 202 SIGNAL( legendDataChanged( 203 const QVariant &, const QList<QwtLegendData> & ) ), 204 d_data->legend, 205 SLOT( updateLegend( 206 const QVariant &, const QList<QwtLegendData> & ) ) 207 ); 208 209 if ( d_data->legend->parent() != this ) 210 d_data->legend->setParent( this ); 211 212 updateLegend(); 213 214 QwtLegend *lgd = qobject_cast<QwtLegend *>( legend ); 215 if ( lgd ) 199 216 { 200 if ( d_data->legend->parent() != this ) 201 d_data->legend->setParent( this ); 202 } 203 204 const QwtPolarItemList& itmList = itemList(); 205 for ( QwtPolarItemIterator it = itmList.begin(); 206 it != itmList.end(); ++it ) 207 { 208 ( *it )->updateLegend( d_data->legend ); 209 } 210 211 QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>( 212 d_data->legend->contentsWidget()->layout() ); 213 214 if ( tl ) 215 { 216 switch( d_data->layout->legendPosition() ) 217 switch ( d_data->layout->legendPosition() ) 217 218 { 218 219 case LeftLegend: 219 220 case RightLegend: 220 tl->setMaxCols( 1 ); // 1 column: align vertical 221 { 222 if ( lgd->maxColumns() == 0 ) 223 lgd->setMaxColumns( 1 ); // 1 column: align vertical 221 224 break; 222 225 } 223 226 case TopLegend: 224 227 case BottomLegend: 225 tl->setMaxCols( 0 ); // unlimited 228 { 229 lgd->setMaxColumns( 0 ); // unlimited 226 230 break; 227 228 case ExternalLegend:231 } 232 default: 229 233 break; 230 234 } 231 235 } 232 } 233 } 236 237 } 238 } 239 234 240 updateLayout(); 241 } 242 243 /*! 244 Emit legendDataChanged() for all plot item 245 246 \sa QwtPlotItem::legendData(), legendDataChanged() 247 */ 248 void QwtPolarPlot::updateLegend() 249 { 250 const QwtPolarItemList& itmList = itemList(); 251 for ( QwtPolarItemIterator it = itmList.begin(); 252 it != itmList.end(); ++it ) 253 { 254 updateLegend( *it ); 255 } 256 } 257 258 /*! 259 Emit legendDataChanged() for a plot item 260 261 \param plotItem Plot item 262 \sa QwtPlotItem::legendData(), legendDataChanged() 263 */ 264 void QwtPolarPlot::updateLegend( const QwtPolarItem *plotItem ) 265 { 266 if ( plotItem == NULL ) 267 return; 268 269 QList<QwtLegendData> legendData; 270 271 if ( plotItem->testItemAttribute( QwtPolarItem::Legend ) ) 272 legendData = plotItem->legendData(); 273 274 const QVariant itemInfo = itemToInfo( const_cast< QwtPolarItem *>( plotItem) ); 275 Q_EMIT legendDataChanged( itemInfo, legendData ); 235 276 } 236 277 … … 239 280 \sa insertLegend() 240 281 */ 241 Qwt Legend *QwtPolarPlot::legend()282 QwtAbstractLegend *QwtPolarPlot::legend() 242 283 { 243 284 return d_data->legend; … … 248 289 \sa insertLegend() 249 290 */ 250 const Qwt Legend *QwtPolarPlot::legend() const291 const QwtAbstractLegend *QwtPolarPlot::legend() const 251 292 { 252 293 return d_data->legend; 253 }254 255 /*!256 Called internally when the legend has been clicked on.257 Emits a legendClicked() signal.258 */259 void QwtPolarPlot::legendItemClicked()260 {261 if ( d_data->legend && sender()->isWidgetType() )262 {263 QwtPolarItem *plotItem = static_cast< QwtPolarItem* >(264 d_data->legend->find( qobject_cast<const QWidget *>( sender() ) ) );265 if ( plotItem )266 Q_EMIT legendClicked( plotItem );267 }268 }269 270 /*!271 Called internally when the legend has been checked272 Emits a legendClicked() signal.273 */274 void QwtPolarPlot::legendItemChecked( bool on )275 {276 if ( d_data->legend && sender()->isWidgetType() )277 {278 QwtPolarItem *plotItem = static_cast< QwtPolarItem* >(279 d_data->legend->find( qobject_cast<const QWidget *>( sender() ) ) );280 if ( plotItem )281 Q_EMIT legendChecked( plotItem, on );282 }283 294 } 284 295 … … 389 400 return; 390 401 391 if ( maxMinor < 0 ) 392 maxMinor = 0; 393 if ( maxMinor > 100 ) 394 maxMinor = 100; 402 maxMinor = qBound( 0, maxMinor, 100 ); 395 403 396 404 ScaleData &scaleData = d_data->scaleData[scaleId]; … … 399 407 { 400 408 scaleData.maxMinor = maxMinor; 401 scaleData. scaleDiv.invalidate();409 scaleData.isValid = false; 402 410 autoRefresh(); 403 411 } … … 429 437 return; 430 438 431 if ( maxMajor < 1 ) 432 maxMajor = 1; 433 if ( maxMajor > 1000 ) 434 maxMajor = 10000; 439 maxMajor = qBound( 1, maxMajor, 10000 ); 435 440 436 441 ScaleData &scaleData = d_data->scaleData[scaleId]; … … 438 443 { 439 444 scaleData.maxMajor = maxMajor; 440 scaleData. scaleDiv.invalidate();445 scaleData.isValid = false; 441 446 autoRefresh(); 442 447 } … … 477 482 scaleData.scaleEngine = scaleEngine; 478 483 479 scaleData. scaleDiv.invalidate();484 scaleData.isValid = false; 480 485 481 486 autoRefresh(); … … 527 532 ScaleData &scaleData = d_data->scaleData[scaleId]; 528 533 529 scaleData. scaleDiv.invalidate();534 scaleData.isValid = false; 530 535 531 536 scaleData.minValue = min; … … 551 556 552 557 scaleData.scaleDiv = scaleDiv; 558 scaleData.isValid = true; 553 559 scaleData.doAutoScale = false; 554 560 … … 732 738 { 733 739 map.setPaintInterval( d_data->azimuthOrigin, 734 d_data->azimuthOrigin + M_2PI );740 d_data->azimuthOrigin + 2 * M_PI ); 735 741 } 736 742 else … … 820 826 scaleData.maxMajor = 8; 821 827 828 scaleData.isValid = false; 829 822 830 scaleData.scaleEngine = new QwtLinearScaleEngine; 823 scaleData.scaleDiv.invalidate();824 831 } 825 832 d_data->zoomFactor = 1.0; … … 858 865 } 859 866 860 if ( d_data->legend && 861 d_data->layout->legendPosition() != ExternalLegend ) 862 { 863 if ( d_data->legend->itemCount() > 0 ) 864 { 865 d_data->legend->setGeometry( d_data->layout->legendRect().toRect() ); 867 if ( d_data->legend ) 868 { 869 if ( d_data->legend->isEmpty() ) 870 { 871 d_data->legend->hide(); 872 } 873 else 874 { 875 const QRectF legendRect = d_data->layout->legendRect(); 876 d_data->legend->setGeometry( legendRect.toRect() ); 866 877 d_data->legend->show(); 867 878 } 868 else869 d_data->legend->hide();870 879 } 871 880 … … 1054 1063 d.scaleEngine->autoScale( d.maxMajor, 1055 1064 minValue, maxValue, stepSize ); 1056 d. scaleDiv.invalidate();1057 } 1058 1059 if ( !d. scaleDiv.isValid())1065 d.isValid = false; 1066 } 1067 1068 if ( !d.isValid ) 1060 1069 { 1061 1070 d.scaleDiv = d.scaleEngine->divideScale( 1062 1071 minValue, maxValue, d.maxMajor, d.maxMinor, stepSize ); 1072 d.isValid = true; 1063 1073 } 1064 1074 … … 1270 1280 return d_data->layout; 1271 1281 } 1282 1283 /*! 1284 \brief Attach/Detach a plot item 1285 1286 \param plotItem Plot item 1287 \param on When true attach the item, otherwise detach it 1288 */ 1289 void QwtPolarPlot::attachItem( QwtPolarItem *plotItem, bool on ) 1290 { 1291 if ( on ) 1292 insertItem( plotItem ); 1293 else 1294 removeItem( plotItem ); 1295 1296 Q_EMIT itemAttached( plotItem, on ); 1297 1298 if ( plotItem->testItemAttribute( QwtPolarItem::Legend ) ) 1299 { 1300 // the item wants to be represented on the legend 1301 1302 if ( on ) 1303 { 1304 updateLegend( plotItem ); 1305 } 1306 else 1307 { 1308 const QVariant itemInfo = itemToInfo( plotItem ); 1309 Q_EMIT legendDataChanged( itemInfo, QList<QwtLegendData>() ); 1310 } 1311 } 1312 1313 if ( autoReplot() ) 1314 update(); 1315 } 1316 1317 /*! 1318 \brief Build an information, that can be used to identify 1319 a plot item on the legend. 1320 1321 The default implementation simply wraps the plot item 1322 into a QVariant object. When overloading itemToInfo() 1323 usually infoToItem() needs to reimplemeted too. 1324 1325 \code 1326 QVariant itemInfo; 1327 qVariantSetValue( itemInfo, plotItem ); 1328 \endcode 1329 1330 \param plotItem Plot item 1331 \sa infoToItem() 1332 */ 1333 QVariant QwtPolarPlot::itemToInfo( QwtPolarItem *plotItem ) const 1334 { 1335 QVariant itemInfo; 1336 qVariantSetValue( itemInfo, plotItem ); 1337 1338 return itemInfo; 1339 } 1340 1341 /*! 1342 \brief Identify the plot item according to an item info object, 1343 that has bee generated from itemToInfo(). 1344 1345 The default implementation simply tries to unwrap a QwtPlotItem 1346 pointer: 1347 1348 \code 1349 if ( itemInfo.canConvert<QwtPlotItem *>() ) 1350 return qvariant_cast<QwtPlotItem *>( itemInfo ); 1351 \endcode 1352 \param itemInfo Plot item 1353 \return A plot item, when successful, otherwise a NULL pointer. 1354 \sa itemToInfo() 1355 */ 1356 QwtPolarItem *QwtPolarPlot::infoToItem( const QVariant &itemInfo ) const 1357 { 1358 if ( itemInfo.canConvert<QwtPolarItem *>() ) 1359 return qvariant_cast<QwtPolarItem *>( itemInfo ); 1360 1361 return NULL; 1362 } -
trunk/BNC/qwtpolar/qwt_polar_plot.h
r4272 r8127 24 24 class QwtPolarCanvas; 25 25 class QwtPolarLayout; 26 class QwtAbstractLegend; 26 27 27 28 /*! … … 141 142 // Legend 142 143 143 void insertLegend( Qwt Legend *,144 void insertLegend( QwtAbstractLegend *, 144 145 LegendPosition = RightLegend, double ratio = -1.0 ); 145 146 146 QwtLegend *legend(); 147 const QwtLegend *legend() const; 147 QwtAbstractLegend *legend(); 148 const QwtAbstractLegend *legend() const; 149 150 void updateLegend(); 151 void updateLegend( const QwtPolarItem * ); 148 152 149 153 // Layout … … 157 161 int plotMarginHint() const; 158 162 163 virtual QVariant itemToInfo( QwtPolarItem * ) const; 164 virtual QwtPolarItem *infoToItem( const QVariant & ) const; 165 159 166 Q_SIGNALS: 160 167 /*! 161 A signal which is emitted when the user has clicked on 162 a legend item, which is in QwtLegend::ClickableItem mode. 163 164 \param plotItem Corresponding plot item of the 165 selected legend item 166 167 \note clicks are disabled as default 168 \sa QwtLegend::setItemMode, QwtLegend::itemMode 169 */ 170 void legendClicked( QwtPolarItem *plotItem ); 171 172 /*! 173 A signal which is emitted when the user has clicked on 174 a legend item, which is in QwtLegend::CheckableItem mode 175 176 \param plotItem Corresponding plot item of the 177 selected legend item 178 \param on True when the legen item is checked 179 180 \note clicks are disabled as default 181 \sa QwtLegend::setItemMode, QwtLegend::itemMode 182 */ 183 void legendChecked( QwtPolarItem *plotItem, bool on ); 168 A signal indicating, that an item has been attached/detached 169 170 \param plotItem Plot item 171 \param on Attached/Detached 172 */ 173 void itemAttached( QwtPolarItem *plotItem, bool on ); 174 175 /*! 176 A signal with the attributes how to update 177 the legend entries for a plot item. 178 179 \param itemInfo Info about a plot, build from itemToInfo() 180 181 \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend() 182 */ 183 void legendDataChanged( const QVariant &itemInfo, 184 const QList<QwtLegendData> &data ); 184 185 185 186 /*! … … 194 195 void setAzimuthOrigin( double ); 195 196 196 protected Q_SLOTS:197 virtual void legendItemClicked();198 virtual void legendItemChecked( bool );199 200 197 protected: 201 198 virtual bool event( QEvent * ); … … 210 207 211 208 private: 209 friend class QwtPolarItem; 210 void attachItem( QwtPolarItem *, bool ); 211 212 212 void initPlot( const QwtText & ); 213 213 -
trunk/BNC/qwtpolar/qwt_polar_renderer.cpp
r4272 r8127 11 11 #include "qwt_polar_layout.h" 12 12 #include <qwt_legend.h> 13 #include <qwt_legend_item.h>14 13 #include <qwt_dyngrid_layout.h> 15 14 #include <qwt_text_label.h> … … 17 16 #include <qpainter.h> 18 17 #include <qprinter.h> 18 #include <qprintdialog.h> 19 #include <qfiledialog.h> 19 20 #include <qimagewriter.h> 20 21 #include <qfileinfo.h> … … 115 116 116 117 const QString fmt = format.toLower(); 117 if ( format == "pdf" || format == "ps" ) 118 { 118 if ( format == "pdf" ) 119 { 120 #ifndef QT_NO_PRINTER 119 121 QPrinter printer; 122 printer.setColorMode( QPrinter::Color ); 120 123 printer.setFullPage( true ); 121 124 printer.setPaperSize( sizeMM, QPrinter::Millimeter ); 122 125 printer.setDocName( title ); 123 126 printer.setOutputFileName( fileName ); 124 printer.setOutputFormat( ( format == "pdf" ) 125 ? QPrinter::PdfFormat : QPrinter::PostScriptFormat ); 127 printer.setOutputFormat( QPrinter::PdfFormat ); 126 128 printer.setResolution( resolution ); 127 129 128 130 QPainter painter( &printer ); 129 131 render( plot, &painter, documentRect ); 132 #endif 133 } 134 else if ( format == "ps" ) 135 { 136 #if QT_VERSION < 0x050000 137 #ifndef QT_NO_PRINTER 138 QPrinter printer; 139 printer.setColorMode( QPrinter::Color ); 140 printer.setFullPage( true ); 141 printer.setPaperSize( sizeMM, QPrinter::Millimeter ); 142 printer.setDocName( title ); 143 printer.setOutputFileName( fileName ); 144 printer.setOutputFormat( QPrinter::PostScriptFormat ); 145 printer.setResolution( resolution ); 146 147 QPainter painter( &printer ); 148 render( plot, &painter, documentRect ); 149 #endif 150 #endif 130 151 } 131 152 #ifndef QWT_NO_POLAR_SVG … … 300 321 301 322 painter->save(); 302 renderLegend( p ainter, layout->legendRect() );323 renderLegend( plot, painter, layout->legendRect() ); 303 324 painter->restore(); 304 325 … … 340 361 Render the legend into a given rectangle. 341 362 363 \param plot Plot widget 342 364 \param painter Painter 343 365 \param rect Bounding rectangle 344 366 */ 345 346 void QwtPolarRenderer::renderLegend( 367 void QwtPolarRenderer::renderLegend( const QwtPolarPlot *plot, 347 368 QPainter *painter, const QRectF &rect ) const 348 369 { 349 QwtLegend *legend = d_data->plot->legend(); 350 if ( legend == NULL || legend->isEmpty() ) 351 return; 352 353 const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( 354 legend->contentsWidget()->layout() ); 355 if ( legendLayout == NULL ) 356 return; 357 358 uint numCols = legendLayout->columnsForWidth( rect.width() ); 359 const QList<QRect> itemRects = 360 legendLayout->layoutItems( rect.toRect(), numCols ); 361 362 int index = 0; 363 364 for ( int i = 0; i < legendLayout->count(); i++ ) 365 { 366 QLayoutItem *item = legendLayout->itemAt( i ); 367 QWidget *w = item->widget(); 368 if ( w ) 370 if ( plot->legend() ) 371 plot->legend()->renderLegend( painter, rect, true ); 372 } 373 374 /*! 375 \brief Execute a file dialog and render the plot to the selected file 376 377 The document will be rendered in 85 dpi for a size 30x30 cm 378 379 \param plot Plot widget 380 \param documentName Default document name 381 \param sizeMM Size for the document in millimeters. 382 \param resolution Resolution in dots per Inch (dpi) 383 384 \sa renderDocument() 385 */ 386 bool QwtPolarRenderer::exportTo( QwtPolarPlot *plot, 387 const QString &documentName, const QSizeF &sizeMM, int resolution ) 388 { 389 if ( plot == NULL ) 390 return false; 391 392 QString fileName = documentName; 393 394 // What about translation 395 396 #ifndef QT_NO_FILEDIALOG 397 const QList<QByteArray> imageFormats = 398 QImageWriter::supportedImageFormats(); 399 400 QStringList filter; 401 #ifndef QT_NO_PRINTER 402 filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)"; 403 #endif 404 #ifndef QWT_NO_SVG 405 filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)"; 406 #endif 407 #ifndef QT_NO_PRINTER 408 filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)"; 409 #endif 410 411 if ( imageFormats.size() > 0 ) 412 { 413 QString imageFilter( tr( "Images" ) ); 414 imageFilter += " ("; 415 for ( int i = 0; i < imageFormats.size(); i++ ) 369 416 { 370 painter->save(); 371 372 painter->setClipRect( itemRects[index] ); 373 renderLegendItem( painter, w, itemRects[index] ); 374 375 index++; 376 painter->restore(); 417 if ( i > 0 ) 418 imageFilter += " "; 419 imageFilter += "*."; 420 imageFilter += imageFormats[i]; 377 421 } 378 } 379 380 } 381 382 /*! 383 Print the legend item into a given rectangle. 384 385 \param painter Painter 386 \param widget Widget representing a legend item 387 \param rect Bounding rectangle 388 389 \note When widget is not derived from QwtLegendItem renderLegendItem 390 does nothing and needs to be overloaded 391 */ 392 void QwtPolarRenderer::renderLegendItem( QPainter *painter, 393 const QWidget *widget, const QRectF &rect ) const 394 { 395 const QwtLegendItem *item = qobject_cast<const QwtLegendItem *>( widget ); 396 if ( item ) 397 { 398 const QSize sz = item->identifierSize(); 399 400 const QRectF identifierRect( rect.x() + item->margin(), 401 rect.center().y() - 0.5 * sz.height(), sz.width(), sz.height() ); 402 403 QwtLegendItemManager *itemManger = d_data->plot->legend()->find( item ); 404 if ( itemManger ) 405 { 406 painter->save(); 407 painter->setClipRect( identifierRect, Qt::IntersectClip ); 408 itemManger->drawLegendIdentifier( painter, identifierRect ); 409 painter->restore(); 410 } 411 412 // Label 413 414 QRectF titleRect = rect; 415 titleRect.setX( identifierRect.right() + 2 * item->spacing() ); 416 417 painter->setFont( item->font() ); 418 item->text().draw( painter, titleRect ); 419 } 420 } 421 422 imageFilter += ")"; 423 424 filter += imageFilter; 425 } 426 427 fileName = QFileDialog::getSaveFileName( 428 NULL, tr( "Export File Name" ), fileName, 429 filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite ); 430 #endif 431 if ( fileName.isEmpty() ) 432 return false; 433 434 renderDocument( plot, fileName, sizeMM, resolution ); 435 436 return true; 437 } -
trunk/BNC/qwtpolar/qwt_polar_renderer.h
r4272 r8127 12 12 #include "qwt_polar_global.h" 13 13 #include <qobject.h> 14 #include <qsize.h> 14 15 15 16 class QwtPolarPlot; 16 class QSizeF;17 17 class QRectF; 18 18 class QPainter; … … 52 52 #endif 53 53 void renderTo( QwtPolarPlot *, QPrinter & ) const; 54 void renderTo( QwtPolarPlot *, QPaintDevice & p) const;54 void renderTo( QwtPolarPlot *, QPaintDevice & ) const; 55 55 56 56 virtual void render( QwtPolarPlot *, 57 57 QPainter *, const QRectF &rect ) const; 58 58 59 protected: 59 bool exportTo( QwtPolarPlot *, const QString &documentName, 60 const QSizeF &sizeMM = QSizeF( 200, 200 ), int resolution = 85 ); 61 60 62 virtual void renderTitle( QPainter *, const QRectF & ) const; 61 virtual void renderLegend( QPainter *, const QRectF & ) const;62 63 63 virtual void renderLegend Item( QPainter *,64 const Q Widget*, const QRectF & ) const;64 virtual void renderLegend( 65 const QwtPolarPlot *, QPainter *, const QRectF & ) const; 65 66 66 67 private: -
trunk/BNC/qwtpolar/qwt_polar_spectrogram.cpp
r4272 r8127 95 95 public: 96 96 PrivateData(): 97 data( NULL ), 98 renderThreadCount( 1 ) 97 data( NULL ) 99 98 { 100 99 colorMap = new QwtLinearColorMap(); … … 109 108 QwtRasterData *data; 110 109 QwtColorMap *colorMap; 111 112 uint renderThreadCount;113 110 114 111 QwtPolarSpectrogram::PaintAttributes paintAttributes; … … 223 220 { 224 221 return ( d_data->paintAttributes & attribute ); 225 }226 227 /*!228 Rendering an image from the raster data can often be done229 parallel on a multicore system.230 231 \param numThreads Number of threads to be used for rendering.232 If numThreads is set to 0, the system specific233 ideal thread count is used.234 235 The default thread count is 1 ( = no additional threads )236 237 \warning Rendering in multiple threads is only supported for Qt >= 4.4238 \sa renderThreadCount(), renderImage(), renderTile()239 */240 void QwtPolarSpectrogram::setRenderThreadCount( uint numThreads )241 {242 d_data->renderThreadCount = numThreads;243 }244 245 /*!246 \return Number of threads to be used for rendering.247 If numThreads is set to 0, the system specific248 ideal thread count is used.249 250 \warning Rendering in multiple threads is only supported for Qt >= 4.4251 \sa setRenderThreadCount(), renderImage(), renderTile()252 */253 uint QwtPolarSpectrogram::renderThreadCount() const254 {255 return d_data->renderThreadCount;256 222 } 257 223 … … 357 323 358 324 #if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE) 359 uint numThreads = d_data->renderThreadCount;325 uint numThreads = renderThreadCount(); 360 326 361 327 if ( numThreads <= 0 ) -
trunk/BNC/qwtpolar/qwt_polar_spectrogram.h
r4272 r8127 60 60 bool testPaintAttribute( PaintAttribute ) const; 61 61 62 void setRenderThreadCount( uint numThreads );63 uint renderThreadCount() const;64 65 62 virtual int rtti() const; 66 63 -
trunk/BNC/qwtpolar/qwtpolar.pro
r5182 r8127 6 6 CONFIG += release 7 7 DEFINES += QWT_POLAR_NO_SVG 8 greaterThan(QT_MAJOR_VERSION, 4) { 9 QT += printsupport 10 QT += concurrent 11 } 8 12 9 13 INCLUDEPATH += ../qwt … … 45 49 qwt_polar_renderer.cpp \ 46 50 qwt_polar_plot.cpp 47 -
trunk/BNC/src/PPP_SSR_I/pppFilter.h
r7929 r8127 90 90 double lkB; 91 91 unsigned obsIndex; 92 char system() const {return prn.to Ascii()[0];}92 char system() const {return prn.toLatin1()[0];} 93 93 }; 94 94 -
trunk/BNC/src/bnccaster.cpp
r8119 r8127 208 208 emit( newMessage(QString("%1: Old epoch %2 thrown away") 209 209 .arg(staID.data()).arg(string(obs._time).c_str()) 210 .to Ascii(), true) );210 .toLatin1(), true) ); 211 211 } 212 212 } … … 232 232 _sockets->push_back( _server->nextPendingConnection() ); 233 233 emit( newMessage(QString("New client connection on sync port: # %1") 234 .arg(_sockets->size()).to Ascii(), true) );234 .arg(_sockets->size()).toLatin1(), true) ); 235 235 } 236 236 … … 238 238 _uSockets->push_back( _uServer->nextPendingConnection() ); 239 239 emit( newMessage(QString("New client connection on usync port: # %1") 240 .arg(_uSockets->size()).to Ascii(), true) );240 .arg(_uSockets->size()).toLatin1(), true) ); 241 241 } 242 242 … … 286 286 _staIDs.removeAll(staID); 287 287 emit( newMessage( 288 QString("Decoding %1 stream(s)").arg(_staIDs.size()).to Ascii(), true) );288 QString("Decoding %1 stream(s)").arg(_staIDs.size()).toLatin1(), true) ); 289 289 if (_staIDs.size() == 0) { 290 290 emit(newMessage("bncCaster: Last get thread terminated", true)); … … 406 406 // ---------------- 407 407 if (!existFlg) { 408 QByteArray format = hlp[1].to Ascii();409 QByteArray latitude = hlp[3].to Ascii();410 QByteArray longitude = hlp[4].to Ascii();411 QByteArray nmea = hlp[5].to Ascii();412 QByteArray ntripVersion = hlp[6].to Ascii();408 QByteArray format = hlp[1].toLatin1(); 409 QByteArray latitude = hlp[3].toLatin1(); 410 QByteArray longitude = hlp[4].toLatin1(); 411 QByteArray nmea = hlp[5].toLatin1(); 412 QByteArray ntripVersion = hlp[6].toLatin1(); 413 413 414 414 bncGetThread* getThread = new bncGetThread(url, format, latitude, … … 450 450 + BNC_CORE->confFileName() 451 451 + ", %1 stream(s)") 452 .arg(_threads.count()).to Ascii(), true) );452 .arg(_threads.count()).toLatin1(), true) ); 453 453 454 454 // (Re-) Start the configuration timer … … 555 555 _miscSockets->push_back( _miscServer->nextPendingConnection() ); 556 556 emit( newMessage(QString("New client connection on Miscellaneous Output Port: # %1") 557 .arg(_miscSockets->size()).to Ascii(), true) );558 } 557 .arg(_miscSockets->size()).toLatin1(), true) ); 558 } -
trunk/BNC/src/bnccore.cpp
r7999 r8127 170 170 expandEnvVar(logFileName); 171 171 _logFile = new QFile(logFileName + "_" + 172 currDate.toString("yyMMdd").to Ascii().data());172 currDate.toString("yyMMdd").toLatin1().data()); 173 173 _fileDate = currDate; 174 174 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) { … … 189 189 msgLocal = msg.mid(1); 190 190 } 191 *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").to Ascii().data();191 *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toLatin1().data(); 192 192 *_logStream << msgLocal.data() << endl; 193 193 _logStream->flush(); … … 202 202 t_irc ircPut = _ephUser.putNewEph(eph, true); 203 203 if (eph->checkState() == t_eph::bad) { 204 messagePrivate("WRONG EPHEMERIS\n" + eph->toString(3.0).to Ascii());204 messagePrivate("WRONG EPHEMERIS\n" + eph->toString(3.0).toLatin1()); 205 205 return failure; 206 206 } 207 207 else if (eph->checkState() == t_eph::outdated) { 208 messagePrivate("OUTDATED EPHEMERIS\n" + eph->toString(3.0).to Ascii());208 messagePrivate("OUTDATED EPHEMERIS\n" + eph->toString(3.0).toLatin1()); 209 209 return failure; 210 210 } … … 270 270 comments.append("Source: " + decoder + 271 271 " " + url.encodedHost() + 272 "/" + url.path().mid(1).to Ascii());272 "/" + url.path().mid(1).toLatin1()); 273 273 } 274 274 … … 388 388 line.sprintf( 389 389 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n", 390 t_rnxNavFile::defaultRnxNavVersion3, "", "");390 defaultRnxNavVersion3, "", ""); 391 391 *_ephStreamGPS << line; 392 392 393 393 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true); 394 *_ephStreamGPS << _pgmName.to Ascii().data()395 << _userName.to Ascii().data()396 << hlp.to Ascii().data()394 *_ephStreamGPS << _pgmName.toLatin1().data() 395 << _userName.toLatin1().data() 396 << hlp.toLatin1().data() 397 397 << "PGM / RUN BY / DATE" << endl; 398 398 … … 415 415 QString line; 416 416 line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 417 t_rnxNavFile::defaultRnxNavVersion2, "", "");417 defaultRnxNavVersion2, "", ""); 418 418 *_ephStreamGPS << line; 419 419 420 420 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true); 421 *_ephStreamGPS << _pgmName.to Ascii().data()422 << _userName.to Ascii().data()423 << hlp.to Ascii().data()421 *_ephStreamGPS << _pgmName.toLatin1().data() 422 << _userName.toLatin1().data() 423 << hlp.toLatin1().data() 424 424 << "PGM / RUN BY / DATE" << endl; 425 425 … … 437 437 QString line; 438 438 line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n", 439 t_rnxNavFile::defaultRnxNavVersion2, "", "");439 defaultRnxNavVersion2, "", ""); 440 440 *_ephStreamGlonass << line; 441 441 442 442 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true); 443 *_ephStreamGlonass << _pgmName.to Ascii().data()444 << _userName.to Ascii().data()445 << hlp.to Ascii().data()443 *_ephStreamGlonass << _pgmName.toLatin1().data() 444 << _userName.toLatin1().data() 445 << hlp.toLatin1().data() 446 446 << "PGM / RUN BY / DATE" << endl; 447 447 … … 464 464 void t_bncCore::printEph(const t_eph& eph, bool printFile) { 465 465 466 QString strV2 = eph.toString( t_rnxNavFile::defaultRnxNavVersion2);467 QString strV3 = eph.toString( t_rnxObsHeader::defaultRnxObsVersion3);466 QString strV2 = eph.toString(defaultRnxNavVersion2); 467 QString strV3 = eph.toString(defaultRnxObsVersion3); 468 468 469 469 if (_rinexVers == 2 && eph.type() == t_eph::GLONASS) { … … 487 487 if (printFile && stream) { 488 488 if (_rinexVers == 2) { 489 *stream << strV2.to Ascii();489 *stream << strV2.toLatin1(); 490 490 } 491 491 else { 492 *stream << strV3.to Ascii();492 *stream << strV3.toLatin1(); 493 493 } 494 494 stream->flush(); … … 502 502 QTcpSocket* sock = is.next(); 503 503 if (sock->state() == QAbstractSocket::ConnectedState) { 504 if (sock->write(strV3.to Ascii()) == -1) {504 if (sock->write(strV3.toLatin1()) == -1) { 505 505 delete sock; 506 506 is.remove(); -
trunk/BNC/src/bncfigureppp.h
r6730 r8127 43 43 44 44 private: 45 const static double _tRange = 300;45 enum {_tRange = 300}; 46 46 47 47 class pppPos { -
trunk/BNC/src/bncgetthread.cpp
r8123 r8127 43 43 #include <sstream> 44 44 45 #include <QComboBox> 46 #include <QDialog> 45 47 #include <QFile> 46 48 #include <QTextStream> 47 49 #include <QMutex> 48 50 #include <QtNetwork> 51 #include <QPushButton> 52 #include <QTableWidget> 49 53 #include <QTime> 50 54 … … 90 94 _rawFile = 0; 91 95 _mountPoint = mountPoint; 92 _staID = mountPoint.path().mid(1).to Ascii();96 _staID = mountPoint.path().mid(1).toLatin1(); 93 97 _format = format; 94 98 _latitude = latitude; … … 134 138 continue; 135 139 } 136 QByteArray mp = hlp[0].to Ascii();140 QByteArray mp = hlp[0].toLatin1(); 137 141 if (_staID == mp) { 138 142 nmeaPort = hlp[9].toInt(); … … 275 279 hlp = "0.0"; 276 280 } 277 QByteArray _serialHeightNMEA = hlp.to Ascii();281 QByteArray _serialHeightNMEA = hlp.toLatin1(); 278 282 _manualNMEAString = ggaString(_latitude, _longitude, _serialHeightNMEA, 279 283 nmeaMode); … … 603 607 QString prn(obs._prn.toString().c_str()); 604 608 emit(newMessage( 605 _staID + " (" + prn.to Ascii() + ")"609 _staID + " (" + prn.toLatin1() + ")" 606 610 + ": Wrong observation epoch(s)", false)); 607 611 continue; … … 619 623 long oldTime = it.value(); 620 624 if (obsTime < oldTime) { 621 emit(newMessage(_staID + ": old observation " + prn.to Ascii(),625 emit(newMessage(_staID + ": old observation " + prn.toLatin1(), 622 626 false)); 623 627 continue; … … 625 629 emit(newMessage( 626 630 _staID + ": observation coming more than once " 627 + prn.to Ascii(), false));631 + prn.toLatin1(), false)); 628 632 continue; 629 633 } … … 774 778 for (int ii = 0; ii < decoder()->_typeList.size(); ii++) { 775 779 QString type = QString("%1 ").arg(decoder()->_typeList[ii]); 776 emit(newMessage(_staID + ": Received message type " + type.to Ascii(),780 emit(newMessage(_staID + ": Received message type " + type.toLatin1(), 777 781 true)); 778 782 } … … 847 851 str << " " << rnxTypes[iType]; 848 852 } 849 emit(newMessage(_staID + ": Observation Types: " + msg.to Ascii(),853 emit(newMessage(_staID + ": Observation Types: " + msg.toLatin1(), 850 854 true)); 851 855 } … … 856 860 for (int ii = 0; ii < decoder()->_antType.size(); ii++) { 857 861 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]); 858 emit(newMessage(_staID + ": Antenna descriptor " + ant1.to Ascii(), true));862 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toLatin1(), true)); 859 863 } 860 864 … … 870 874 QByteArray ant1, ant2, ant3; 871 875 ant1 = 872 QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).to Ascii();876 QString("%1 ").arg(decoder()->_antList[ii].xx, 0, 'f', 4).toLatin1(); 873 877 ant2 = 874 QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).to Ascii();878 QString("%1 ").arg(decoder()->_antList[ii].yy, 0, 'f', 4).toLatin1(); 875 879 ant3 = 876 QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).to Ascii();880 QString("%1 ").arg(decoder()->_antList[ii].zz, 0, 'f', 4).toLatin1(); 877 881 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true)); 878 882 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true)); … … 881 885 if (decoder()->_antList[ii].height_f) { 882 886 hh = decoder()->_antList[ii].height; 883 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).to Ascii();887 QByteArray ant4 = QString("%1 ").arg(hh, 0, 'f', 4).toLatin1(); 884 888 emit(newMessage( 885 889 _staID + ": Antenna height above marker " + ant4 + "m", true)); … … 902 906 _gloSlots.sort(); 903 907 emit(newMessage( 904 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").to Ascii(),908 _staID + ": GLONASS Slot:Freq " + _gloSlots.join(" ").toLatin1(), 905 909 true)); 906 910 } … … 983 987 _nmeaSockets->push_back(_nmeaServer->nextPendingConnection()); 984 988 emit(newMessage( 985 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).to Ascii(),989 QString("New PPP client on port: # %1").arg(_nmeaSockets->size()).toLatin1(), 986 990 true)); 987 991 } -
trunk/BNC/src/bncmap_svg.cpp
r7667 r8127 247 247 QwtPlotRenderer renderer; 248 248 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false); 249 renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);249 //renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true); 250 250 renderer.renderTo(_mapPlot, printer); 251 251 } -
trunk/BNC/src/bncrinex.cpp
r7878 r8127 124 124 QStringList tags = line.split(";"); 125 125 if (tags.size() > 7) { 126 if (tags.at(1) == _mountPoint.path().mid(1).to Ascii()) {126 if (tags.at(1) == _mountPoint.path().mid(1).toLatin1()) { 127 127 net = tags.at(7); 128 128 break; … … 368 368 } 369 369 370 _fName = path.to Ascii();370 _fName = path.toLatin1(); 371 371 } 372 372 -
trunk/BNC/src/bnctabledlg.cpp
r7680 r8127 40 40 41 41 #include <iostream> 42 #include <QHeaderView> 43 #include <QLabel> 44 #include <QLineEdit> 45 #include <QMessageBox> 46 #include <QVBoxLayout> 42 47 43 48 #include "bnctabledlg.h" … … 492 497 if (url.host() == newHost) { 493 498 _casterUserLineEdit->setText( 494 QUrl::fromPercentEncoding(url.userName().to Ascii()));499 QUrl::fromPercentEncoding(url.userName().toLatin1())); 495 500 _casterPasswordLineEdit->setText( 496 QUrl::fromPercentEncoding(url.password().to Ascii()));501 QUrl::fromPercentEncoding(url.password().toLatin1())); 497 502 if (url.port() > 0) { 498 503 _casterPortLineEdit->setText(QString("%1").arg(url.port())); -
trunk/BNC/src/bnctabledlg.h
r4658 r8127 28 28 #include <QtCore> 29 29 #include <QtGui> 30 #include <QComboBox> 31 #include <QDialog> 32 #include <QPushButton> 33 #include <QTableWidget> 30 34 #include <QWhatsThis> 31 35 -
trunk/BNC/src/bncwindow.cpp
r8119 r8127 40 40 41 41 #include <iostream> 42 43 #include <QAction> 44 #include <QApplication> 45 #include <QCheckBox> 46 #include <QComboBox> 47 #include <QDialog> 48 #include <QFontDialog> 49 #include <QGridLayout> 50 #include <QHeaderView> 51 #include <QLabel> 52 #include <QLineEdit> 53 #include <QMenu> 54 #include <QMenuBar> 55 #include <QMessageBox> 56 #include <QPushButton> 57 #include <QRadioButton> 58 #include <QSpinBox> 59 #include <QTableWidgetItem> 60 #include <QTextEdit> 61 #include <QToolBar> 42 62 43 63 #include <unistd.h> … … 409 429 _mountPointsTable->horizontalHeader()->resizeSection(6,5*ww); 410 430 _mountPointsTable->horizontalHeader()->resizeSection(7,5*ww); 431 #if QT_VERSION < 0x050000 411 432 _mountPointsTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive); 433 #else 434 _mountPointsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); 435 #endif 412 436 _mountPointsTable->horizontalHeader()->setStretchLastSection(true); 413 437 _mountPointsTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); … … 439 463 _cmbTable->horizontalHeader()->resizeSection(1,8*ww); 440 464 _cmbTable->horizontalHeader()->resizeSection(2,8*ww); 465 #if QT_VERSION < 0x050000 441 466 _cmbTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive); 467 #else 468 _cmbTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); 469 #endif 442 470 _cmbTable->horizontalHeader()->setStretchLastSection(true); 443 471 _cmbTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); … … 501 529 _uploadTable->horizontalHeader()->resizeSection(10, 4*ww); 502 530 _uploadTable->horizontalHeader()->resizeSection(11,12*ww); 531 #if QT_VERSION < 0x050000 503 532 _uploadTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive); 533 #else 534 _uploadTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); 535 #endif 504 536 _uploadTable->horizontalHeader()->setStretchLastSection(true); 505 537 _uploadTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); … … 576 608 _uploadEphTable->horizontalHeader()->resizeSection( 4,10*ww); 577 609 _uploadEphTable->horizontalHeader()->resizeSection( 5,12*ww); 610 #if QT_VERSION < 0x050000 578 611 _uploadEphTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive); 612 #else 613 _uploadEphTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); 614 #endif 579 615 _uploadEphTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); 580 616 … … 2077 2113 this, SLOT(slotMountPointsRead(QList<bncGetThread*>))); 2078 2114 2079 BNC_CORE->slotMessage("========== Start BNC v" BNCVERSION " ("BNC_OS") ==========", true);2115 BNC_CORE->slotMessage("========== Start BNC v" BNCVERSION " (" BNC_OS ") ==========", true); 2080 2116 2081 2117 bncSettings settings; … … 2317 2353 img->setPixmap(QPixmap(":ntrip-logo.png")); 2318 2354 dlgLayout->addWidget(img, 0,0); 2319 dlgLayout->addWidget(new QLabel("BKG Ntrip Client (BNC) Version " BNCVERSION), 0,1);2355 dlgLayout->addWidget(new QLabel("BKG Ntrip Client (BNC) Version " BNCVERSION), 0,1); 2320 2356 dlgLayout->addWidget(tb,1,0,1,2); 2321 2357 dlgLayout->addWidget(_closeButton,2,1,Qt::AlignRight); -
trunk/BNC/src/bncwindow.h
r7889 r8127 27 27 28 28 #include <QtGui> 29 #include <QMainWindow> 29 30 #include <QWhatsThis> 30 31 -
trunk/BNC/src/rinex/availplot.cpp
r6542 r8127 75 75 76 76 setCanvasBackground(QColor(Qt::white)); 77 canvas()->setFrameStyle(QFrame::NoFrame | QFrame::Plain);77 ((QwtPlotCanvas *)canvas())->setFrameStyle(QFrame::NoFrame | QFrame::Plain); 78 78 79 79 // Axes … … 203 203 const QVector<double>& yData) { 204 204 QwtPlotCurve* curve = new QwtPlotCurve(name); 205 curve->setSymbol(new QwtSymbol(symbol)); 205 QwtSymbol *s = new QwtSymbol(symbol.style()); 206 s->setSize(symbol.size()); 207 s->setBrush(symbol.brush()); 208 s->setPen(symbol.pen()); 209 curve->setSymbol(s); 206 210 curve->setStyle(QwtPlotCurve::NoCurve); 207 211 curve->setXAxis(QwtPlot::xBottom); -
trunk/BNC/src/rinex/dopplot.cpp
r6537 r8127 65 65 66 66 setCanvasBackground(QColor(Qt::white)); 67 canvas()->setFrameStyle(QFrame::NoFrame | QFrame::Plain);67 ((QwtPlotCanvas *)canvas())->setFrameStyle(QFrame::NoFrame | QFrame::Plain); 68 68 69 69 // Axes -
trunk/BNC/src/rinex/eleplot.cpp
r6537 r8127 65 65 66 66 setCanvasBackground(QColor(Qt::white)); 67 canvas()->setFrameStyle(QFrame::NoFrame | QFrame::Plain);67 ((QwtPlotCanvas *)canvas())->setFrameStyle(QFrame::NoFrame | QFrame::Plain); 68 68 69 69 // Axes … … 115 115 const QVector<double>& yData) { 116 116 QwtPlotCurve* curve = new QwtPlotCurve(name); 117 curve->setSymbol(new QwtSymbol(symbol)); 117 QwtSymbol *s = new QwtSymbol(symbol.style()); 118 s->setSize(symbol.size()); 119 s->setBrush(symbol.brush()); 120 s->setPen(symbol.pen()); 121 curve->setSymbol(s); 118 122 curve->setStyle(QwtPlotCurve::NoCurve); 119 123 curve->setXAxis(QwtPlot::xBottom); -
trunk/BNC/src/rinex/graphwin.cpp
r6262 r8127 89 89 90 90 QwtLinearScaleEngine scaleEngine; 91 _colorScale->set ScaleDiv(scaleEngine.transformation(),92 91 _colorScale->setTransformation(scaleEngine.transformation()); 92 _colorScale->setScaleDiv(scaleEngine.divideScale(scaleInterval->minValue(), 93 93 scaleInterval->maxValue(), 94 94 8, 5)); -
trunk/BNC/src/rinex/polarplot.cpp
r6262 r8127 32 32 t_colorMap colorMap; 33 33 for (int ii = from; ii <= to; ii++) { 34 QwtSymbol ss(symbol); 34 QwtSymbol ss(symbol.style()); 35 ss.setSize(symbol.size()); 35 36 const QwtPointPolar& point = sample(ii); 36 37 const QColor color = colorMap.color(_scaleInterval, point._value); -
trunk/BNC/src/rinex/polarplot.h
r4356 r8127 51 51 virtual QwtPointPolar sample(size_t ii) const { 52 52 const t_polarPoint* point = _data->at(ii); 53 QwtPointPolar qp(point->_az, point->_zen); qp._value = point->_value;53 QwtPointPolar qp(point->_az, point->_zen); qp._value = point->_value; 54 54 return qp; 55 55 } -
trunk/BNC/src/rinex/reqcedit.cpp
r7999 r8127 64 64 int version = settings.value("reqcRnxVersion").toInt(); 65 65 if (version < 3) { 66 _rnxVersion = t_rnxObsHeader::defaultRnxObsVersion2;66 _rnxVersion = defaultRnxObsVersion2; 67 67 } 68 68 else { 69 _rnxVersion = t_rnxObsHeader::defaultRnxObsVersion3;69 _rnxVersion = defaultRnxObsVersion3; 70 70 } 71 71 _samplingRate = settings.value("reqcSampling").toInt(); … … 578 578 579 579 if ( (haveGPS && haveGlonass) || _rnxVersion >= 3.0) { 580 outNavFile.setVersion( t_rnxNavFile::defaultRnxNavVersion3);580 outNavFile.setVersion(defaultRnxNavVersion3); 581 581 } 582 582 else { 583 outNavFile.setVersion( t_rnxNavFile::defaultRnxNavVersion2);583 outNavFile.setVersion(defaultRnxNavVersion2); 584 584 } 585 585 -
trunk/BNC/src/rinex/rnxnavfile.h
r7999 r8127 35 35 class t_eph; 36 36 37 #define defaultRnxNavVersion2 2.11 38 #define defaultRnxNavVersion3 3.03 39 37 40 class t_rnxNavFile { 38 41 39 42 public: 40 43 enum e_inpOut {input, output}; 41 static const double defaultRnxNavVersion2 = 2.11;42 static const double defaultRnxNavVersion3 = 3.03;43 44 44 private: 45 45 class t_rnxNavHeader { -
trunk/BNC/src/rinex/rnxobsfile.cpp
r8112 r8127 166 166 else if (key == "# / TYPES OF OBSERV") { 167 167 if (_version == 0.0) { 168 _version = t_rnxObsHeader::defaultRnxObsVersion2;168 _version = defaultRnxObsVersion2; 169 169 } 170 170 QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly); … … 190 190 else if (key == "SYS / # / OBS TYPES") { 191 191 if (_version == 0.0) { 192 _version = t_rnxObsHeader::defaultRnxObsVersion3;192 _version = defaultRnxObsVersion3; 193 193 } 194 194 QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly); … … 307 307 308 308 if (version <= 2) { 309 _version = t_rnxObsHeader::defaultRnxObsVersion2;309 _version = defaultRnxObsVersion2; 310 310 } 311 311 else { 312 _version = t_rnxObsHeader::defaultRnxObsVersion3;312 _version = defaultRnxObsVersion3; 313 313 } 314 314 … … 371 371 372 372 if (version <= 2) { 373 _version = t_rnxObsHeader::defaultRnxObsVersion2;373 _version = defaultRnxObsVersion2; 374 374 } 375 375 else { 376 _version = t_rnxObsHeader::defaultRnxObsVersion3;376 _version = defaultRnxObsVersion3; 377 377 } 378 378 _interval = header._interval; -
trunk/BNC/src/rinex/rnxobsfile.h
r7980 r8127 38 38 #include "satObs.h" 39 39 40 #define defaultRnxObsVersion2 2.11 41 #define defaultRnxObsVersion3 3.03 42 40 43 class t_rnxObsHeader { 41 44 … … 43 46 44 47 public: 45 static const double defaultRnxObsVersion2 = 2.11;46 static const double defaultRnxObsVersion3 = 3.03;47 48 static const QString defaultSystems; 48 49
Note:
See TracChangeset
for help on using the changeset viewer.