Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_shapeitem.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_shapeitem.cpp (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_shapeitem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 10 10 #include "qwt_plot_shapeitem.h" 11 11 #include "qwt_scale_map.h" 12 #include "qwt_text.h" 13 #include "qwt_graphic.h" 12 14 #include "qwt_painter.h" 13 #include "qwt_curve_fitter.h" 15 #include "qwt_weeding_curve_fitter.h" 14 16 #include "qwt_clipper.h" 15 16 static QPainterPath qwtTransformPath( const QwtScaleMap &xMap, 17 const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign ) 17 #include "qwt_math.h" 18 19 #include <qpainter.h> 20 #include <qpainterpath.h> 21 22 static QPainterPath qwtTransformPath( const QwtScaleMap& xMap, 23 const QwtScaleMap& yMap, const QPainterPath& path, bool doAlign ) 18 24 { 19 25 QPainterPath shape; … … 22 28 for ( int i = 0; i < path.elementCount(); i++ ) 23 29 { 24 const QPainterPath::Element &element = path.elementAt( i );30 const QPainterPath::Element element = path.elementAt( i ); 25 31 26 32 double x = xMap.transform( element.x ); … … 53 59 case QPainterPath::CurveToElement: 54 60 { 55 const QPainterPath::Element &element1 = path.elementAt( ++i );61 const QPainterPath::Element element1 = path.elementAt( ++i ); 56 62 const double x1 = xMap.transform( element1.x ); 57 63 const double y1 = yMap.transform( element1.y ); 58 64 59 const QPainterPath::Element &element2 = path.elementAt( ++i );65 const QPainterPath::Element element2 = path.elementAt( ++i ); 60 66 const double x2 = xMap.transform( element2.x ); 61 67 const double y2 = yMap.transform( element2.y ); … … 77 83 class QwtPlotShapeItem::PrivateData 78 84 { 79 public: 80 PrivateData() :81 legendMode( QwtPlotShapeItem::LegendColor ) ,82 renderTolerance( 0.0 ) 85 public: 86 PrivateData() 87 : legendMode( QwtPlotShapeItem::LegendColor ) 88 , renderTolerance( 0.0 ) 83 89 { 84 90 } … … 103 109 104 110 \param title Title 105 */ 106 QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ) :107 QwtPlotItem( QwtText( title ) ) 111 */ 112 QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ) 113 : QwtPlotItem( QwtText( title ) ) 108 114 { 109 115 init(); … … 118 124 119 125 \param title Title 120 */ 121 QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ) :122 QwtPlotItem( title ) 126 */ 127 QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ) 128 : QwtPlotItem( title ) 123 129 { 124 130 init(); … … 128 134 QwtPlotShapeItem::~QwtPlotShapeItem() 129 135 { 130 delete d_data;136 delete m_data; 131 137 } 132 138 133 139 void QwtPlotShapeItem::init() 134 140 { 135 d_data = new PrivateData();136 d_data->boundingRect = QwtPlotItem::boundingRect();141 m_data = new PrivateData(); 142 m_data->boundingRect = QwtPlotItem::boundingRect(); 137 143 138 144 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 149 155 150 156 /*! 151 Specify an attribute how to draw the shape 152 153 \param attribute Paint attribute 154 \param on On/Off 155 \sa testPaintAttribute() 156 */ 157 Specify an attribute how to draw the shape 158 159 \param attribute Paint attribute 160 \param on On/Off 161 \sa testPaintAttribute() 162 */ 157 163 void QwtPlotShapeItem::setPaintAttribute( PaintAttribute attribute, bool on ) 158 164 { 159 165 if ( on ) 160 d_data->paintAttributes |= attribute;166 m_data->paintAttributes |= attribute; 161 167 else 162 d_data->paintAttributes &= ~attribute;163 } 164 165 /*! 166 \return True, when attribute is enabled 167 \sa setPaintAttribute() 168 */ 168 m_data->paintAttributes &= ~attribute; 169 } 170 171 /*! 172 \return True, when attribute is enabled 173 \sa setPaintAttribute() 174 */ 169 175 bool QwtPlotShapeItem::testPaintAttribute( PaintAttribute attribute ) const 170 176 { 171 return ( d_data->paintAttributes & attribute );172 } 173 174 /*! 175 Set the mode how to represent the item on the legend 176 177 \param mode Mode 178 \sa legendMode() 177 return ( m_data->paintAttributes & attribute ); 178 } 179 180 /*! 181 Set the mode how to represent the item on the legend 182 183 \param mode Mode 184 \sa legendMode() 179 185 */ 180 186 void QwtPlotShapeItem::setLegendMode( LegendMode mode ) 181 187 { 182 if ( mode != d_data->legendMode )183 { 184 d_data->legendMode = mode;188 if ( mode != m_data->legendMode ) 189 { 190 m_data->legendMode = mode; 185 191 legendChanged(); 186 192 } … … 188 194 189 195 /*! 190 \return Mode how to represent the item on the legend 191 \sa legendMode() 196 \return Mode how to represent the item on the legend 197 \sa legendMode() 192 198 */ 193 199 QwtPlotShapeItem::LegendMode QwtPlotShapeItem::legendMode() const 194 200 { 195 return d_data->legendMode;201 return m_data->legendMode; 196 202 } 197 203 … … 199 205 QRectF QwtPlotShapeItem::boundingRect() const 200 206 { 201 return d_data->boundingRect;202 } 203 204 /*! 205 \brief Set a path built from a rectangle 206 207 \param rect Rectangle 208 \sa setShape(), setPolygon(), shape() 209 */ 210 void QwtPlotShapeItem::setRect( const QRectF &rect )207 return m_data->boundingRect; 208 } 209 210 /*! 211 \brief Set a path built from a rectangle 212 213 \param rect Rectangle 214 \sa setShape(), setPolygon(), shape() 215 */ 216 void QwtPlotShapeItem::setRect( const QRectF& rect ) 211 217 { 212 218 QPainterPath path; … … 217 223 218 224 /*! 219 \brief Set a path built from a polygon 220 221 \param polygon Polygon 222 \sa setShape(), setRect(), shape() 223 */ 224 void QwtPlotShapeItem::setPolygon( const QPolygonF &polygon )225 \brief Set a path built from a polygon 226 227 \param polygon Polygon 228 \sa setShape(), setRect(), shape() 229 */ 230 void QwtPlotShapeItem::setPolygon( const QPolygonF& polygon ) 225 231 { 226 232 QPainterPath shape; … … 231 237 232 238 /*! 233 \brief Set the shape to be displayed 234 235 \param shape Shape 236 \sa setShape(), shape() 237 */ 238 void QwtPlotShapeItem::setShape( const QPainterPath &shape )239 { 240 if ( shape != d_data->shape )241 { 242 d_data->shape = shape;239 \brief Set the shape to be displayed 240 241 \param shape Shape 242 \sa setShape(), shape() 243 */ 244 void QwtPlotShapeItem::setShape( const QPainterPath& shape ) 245 { 246 if ( shape != m_data->shape ) 247 { 248 m_data->shape = shape; 243 249 if ( shape.isEmpty() ) 244 250 { 245 d_data->boundingRect = QwtPlotItem::boundingRect();251 m_data->boundingRect = QwtPlotItem::boundingRect(); 246 252 } 247 253 else 248 254 { 249 d_data->boundingRect = shape.boundingRect();255 m_data->boundingRect = shape.boundingRect(); 250 256 } 251 257 … … 255 261 256 262 /*! 257 \return Shape to be displayed 258 \sa setShape() 263 \return Shape to be displayed 264 \sa setShape() 259 265 */ 260 266 QPainterPath QwtPlotShapeItem::shape() const 261 267 { 262 return d_data->shape;263 } 264 265 /*! 266 Build and assign a pen 267 268 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 269 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 270 to hide this incompatibility. 271 272 \param color Pen color 273 \param width Pen width 274 \param style Pen style 275 276 \sa pen(), brush() 277 */ 278 void QwtPlotShapeItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )268 return m_data->shape; 269 } 270 271 /*! 272 Build and assign a pen 273 274 In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it 275 non cosmetic ( see QPen::isCosmetic() ). This method has been introduced 276 to hide this incompatibility. 277 278 \param color Pen color 279 \param width Pen width 280 \param style Pen style 281 282 \sa pen(), brush() 283 */ 284 void QwtPlotShapeItem::setPen( const QColor& color, qreal width, Qt::PenStyle style ) 279 285 { 280 286 setPen( QPen( color, width, style ) ); … … 282 288 283 289 /*! 284 \brief Assign a pen 285 286 The pen is used to draw the outline of the shape 287 288 \param pen Pen 289 \sa pen(), brush() 290 */ 291 void QwtPlotShapeItem::setPen( const QPen &pen )292 { 293 if ( pen != d_data->pen )294 { 295 d_data->pen = pen;290 \brief Assign a pen 291 292 The pen is used to draw the outline of the shape 293 294 \param pen Pen 295 \sa pen(), brush() 296 */ 297 void QwtPlotShapeItem::setPen( const QPen& pen ) 298 { 299 if ( pen != m_data->pen ) 300 { 301 m_data->pen = pen; 296 302 itemChanged(); 297 303 } … … 301 307 \return Pen used to draw the outline of the shape 302 308 \sa setPen(), brush() 303 */ 309 */ 304 310 QPen QwtPlotShapeItem::pen() const 305 311 { 306 return d_data->pen;307 } 308 309 /*! 310 Assign a brush. 311 312 The brush is used to fill the path 313 314 \param brush Brush 315 \sa brush(), pen() 316 */ 317 void QwtPlotShapeItem::setBrush( const QBrush &brush )318 { 319 if ( brush != d_data->brush )320 { 321 d_data->brush = brush;312 return m_data->pen; 313 } 314 315 /*! 316 Assign a brush. 317 318 The brush is used to fill the path 319 320 \param brush Brush 321 \sa brush(), pen() 322 */ 323 void QwtPlotShapeItem::setBrush( const QBrush& brush ) 324 { 325 if ( brush != m_data->brush ) 326 { 327 m_data->brush = brush; 322 328 itemChanged(); 323 329 } … … 325 331 326 332 /*! 327 \return Brush used to fill the shape 328 \sa setBrush(), pen() 329 */ 333 \return Brush used to fill the shape 334 \sa setBrush(), pen() 335 */ 330 336 QBrush QwtPlotShapeItem::brush() const 331 337 { 332 return d_data->brush;333 } 334 335 /*! 336 \brief Set the tolerance for the weeding optimization 337 338 After translating the shape into target device coordinate 339 ( usually widget geometries ) the painter path can be simplified 340 by a point weeding algorithm ( Douglas-Peucker ). 341 342 For shapes built from curves and ellipses weeding might 343 have the opposite effect because they have to be expanded 344 to polygons. 345 346 \param tolerance Accepted error when reducing the number of points 338 return m_data->brush; 339 } 340 341 /*! 342 \brief Set the tolerance for the weeding optimization 343 344 After translating the shape into target device coordinate 345 ( usually widget geometries ) the painter path can be simplified 346 by a point weeding algorithm ( Douglas-Peucker ). 347 348 For shapes built from curves and ellipses weeding might 349 have the opposite effect because they have to be expanded 350 to polygons. 351 352 \param tolerance Accepted error when reducing the number of points 347 353 A value <= 0.0 disables weeding. 348 354 349 \sa renderTolerance(), QwtWeedingCurveFitter 355 \sa renderTolerance(), QwtWeedingCurveFitter 350 356 */ 351 357 void QwtPlotShapeItem::setRenderTolerance( double tolerance ) 352 358 { 353 tolerance = q Max( tolerance, 0.0 );354 355 if ( tolerance != d_data->renderTolerance )356 { 357 d_data->renderTolerance = tolerance;359 tolerance = qwtMaxF( tolerance, 0.0 ); 360 361 if ( tolerance != m_data->renderTolerance ) 362 { 363 m_data->renderTolerance = tolerance; 358 364 itemChanged(); 359 365 } … … 361 367 362 368 /*! 363 \return Tolerance for the weeding optimization 364 \sa setRenderTolerance() 369 \return Tolerance for the weeding optimization 370 \sa setRenderTolerance() 365 371 */ 366 372 double QwtPlotShapeItem::renderTolerance() const 367 373 { 368 return d_data->renderTolerance;369 } 370 371 /*! 372 Draw the shape item 373 374 \param painter Painter 375 \param xMap X-Scale Map 376 \param yMap Y-Scale Map 377 \param canvasRect Contents rect of the plot canvas 378 */ 379 void QwtPlotShapeItem::draw( QPainter *painter,380 const QwtScaleMap &xMap, const QwtScaleMap&yMap,381 const QRectF &canvasRect ) const382 { 383 if ( d_data->shape.isEmpty() )374 return m_data->renderTolerance; 375 } 376 377 /*! 378 Draw the shape item 379 380 \param painter Painter 381 \param xMap X-Scale Map 382 \param yMap Y-Scale Map 383 \param canvasRect Contents rect of the plot canvas 384 */ 385 void QwtPlotShapeItem::draw( QPainter* painter, 386 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 387 const QRectF& canvasRect ) const 388 { 389 if ( m_data->shape.isEmpty() ) 384 390 return; 385 391 386 if ( d_data->pen.style() == Qt::NoPen387 && d_data->brush.style() == Qt::NoBrush )392 if ( m_data->pen.style() == Qt::NoPen 393 && m_data->brush.style() == Qt::NoBrush ) 388 394 { 389 395 return; … … 393 399 xMap, yMap, canvasRect.toRect() ); 394 400 395 const QRectF &br = d_data->boundingRect;401 const QRectF& br = m_data->boundingRect; 396 402 397 403 if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() ) 398 404 || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) ) 399 405 { 400 // outside the visi sble area406 // outside the visible area 401 407 return; 402 408 } … … 405 411 406 412 QPainterPath path = qwtTransformPath( xMap, yMap, 407 d_data->shape, doAlign );413 m_data->shape, doAlign ); 408 414 409 415 if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) ) 410 416 { 411 qreal pw = qMax( qreal( 1.0 ),painter->pen().widthF());412 QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 417 const qreal pw = QwtPainter::effectivePenWidth( painter->pen() ); 418 const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw ); 413 419 414 420 QPainterPath clippedPath; 415 421 clippedPath.setFillRule( path.fillRule() ); 416 422 417 const QList<QPolygonF> polygons = path.toSubpathPolygons();423 QList< QPolygonF > polygons = path.toSubpathPolygons(); 418 424 for ( int i = 0; i < polygons.size(); i++ ) 419 425 { 420 const QPolygonF p = QwtClipper::clipPolygonF( 421 clipRect, polygons[i], true ); 422 423 clippedPath.addPolygon( p ); 426 QwtClipper::clipPolygonF( clipRect, polygons[i], true ); 427 clippedPath.addPolygon( polygons[i] ); 424 428 425 429 } … … 428 432 } 429 433 430 if ( d_data->renderTolerance > 0.0 )431 { 432 QwtWeedingCurveFitter fitter( d_data->renderTolerance );434 if ( m_data->renderTolerance > 0.0 ) 435 { 436 QwtWeedingCurveFitter fitter( m_data->renderTolerance ); 433 437 434 438 QPainterPath fittedPath; 435 439 fittedPath.setFillRule( path.fillRule() ); 436 440 437 const QList<QPolygonF> polygons = path.toSubpathPolygons(); 441 const QList< QPolygonF > polygons = path.toSubpathPolygons(); 438 442 for ( int i = 0; i < polygons.size(); i++ ) 439 443 fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) ); … … 442 446 } 443 447 444 painter->setPen( d_data->pen );445 painter->setBrush( d_data->brush );448 painter->setPen( m_data->pen ); 449 painter->setBrush( m_data->brush ); 446 450 447 451 painter->drawPath( path ); … … 449 453 450 454 /*! 451 \return A rectangle filled with the color of the brush ( or the pen ) 452 453 \param index Index of the legend entry 455 \return A rectangle filled with the color of the brush ( or the pen ) 456 457 \param index Index of the legend entry 454 458 ( usually there is only one ) 455 \param size Icon size 456 457 \sa setLegendIconSize(), legendData() 458 */ 459 \param size Icon size 460 461 \sa setLegendIconSize(), legendData() 462 */ 459 463 QwtGraphic QwtPlotShapeItem::legendIcon( int index, 460 const QSizeF &size ) const464 const QSizeF& size ) const 461 465 { 462 466 Q_UNUSED( index ); … … 468 472 return icon; 469 473 470 if ( d_data->legendMode == QwtPlotShapeItem::LegendShape )471 { 472 const QRectF &br = d_data->boundingRect;474 if ( m_data->legendMode == QwtPlotShapeItem::LegendShape ) 475 { 476 const QRectF& br = m_data->boundingRect; 473 477 474 478 QPainter painter( &icon ); … … 478 482 painter.translate( -br.topLeft() ); 479 483 480 painter.setPen( d_data->pen );481 painter.setBrush( d_data->brush );482 painter.drawPath( d_data->shape );484 painter.setPen( m_data->pen ); 485 painter.setBrush( m_data->brush ); 486 painter.drawPath( m_data->shape ); 483 487 } 484 488 else 485 489 { 486 490 QColor iconColor; 487 if ( d_data->brush.style() != Qt::NoBrush )488 iconColor = d_data->brush.color();491 if ( m_data->brush.style() != Qt::NoBrush ) 492 iconColor = m_data->brush.color(); 489 493 else 490 iconColor = d_data->pen.color();494 iconColor = m_data->pen.color(); 491 495 492 496 icon = defaultIcon( iconColor, size );
Note:
See TracChangeset
for help on using the changeset viewer.
