Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_series_data.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.