Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_renderer.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_renderer.cpp (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_renderer.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 28 28 #include <qimagewriter.h> 29 29 #include <qvariant.h> 30 #include <qmargins.h> 30 31 31 32 #ifndef QWT_NO_SVG 32 33 #ifdef QT_SVG_LIB 33 #if QT_VERSION >= 0x04050034 34 #define QWT_FORMAT_SVG 1 35 #endif36 35 #endif 37 36 #endif … … 73 72 #endif 74 73 74 static qreal qwtScalePenWidth( const QwtPlot* plot ) 75 { 76 qreal pw = 0.0; 77 78 for ( int axisId = 0; axisId < QwtAxis::AxisPositions; axisId++ ) 79 { 80 if ( plot->isAxisVisible( axisId ) ) 81 pw = qMax( pw, plot->axisScaleDraw( axisId )->penWidthF() ); 82 } 83 84 return pw; 85 } 86 87 static QColor qwtScalePenColor( const QwtPlot* plot ) 88 { 89 const QPalette pal = plot->axisWidget( QwtAxis::YLeft )->palette(); 90 return pal.color( QPalette::WindowText ); 91 } 92 75 93 static QPainterPath qwtCanvasClip( 76 const QWidget* canvas, const QRectF &canvasRect )94 const QWidget* canvas, const QRectF& canvasRect ) 77 95 { 78 96 // The clip region is calculated in integers … … 80 98 // calculate it in target device resolution 81 99 82 int x1 = qCeil( canvasRect.left() ); 83 int x2 = qFloor( canvasRect.right() ); 84 int y1 = qCeil( canvasRect.top() ); 85 int y2 = qFloor( canvasRect.bottom() ); 100 int x1 = qwtCeil( canvasRect.left() ); 101 int x2 = qwtFloor( canvasRect.right() ); 102 int y1 = qwtCeil( canvasRect.top() ); 103 int y2 = qwtFloor( canvasRect.bottom() ); 86 104 87 105 const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 ); … … 90 108 91 109 ( void ) QMetaObject::invokeMethod( 92 const_cast< QWidget *>( canvas ), "borderPath",110 const_cast< QWidget* >( canvas ), "borderPath", 93 111 Qt::DirectConnection, 94 112 Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) ); … … 97 115 } 98 116 99 static inline QFont qwtResolvedFont( const QWidget *widget )117 static inline QFont qwtResolvedFont( const QWidget* widget ) 100 118 { 101 119 QFont font = widget->font(); 120 #if QT_VERSION >= 0x060000 121 font.setResolveMask( QFont::AllPropertiesResolved ); 122 #else 102 123 font.resolve( QFont::AllPropertiesResolved ); 124 #endif 103 125 104 126 return font; … … 107 129 class QwtPlotRenderer::PrivateData 108 130 { 109 public: 110 PrivateData() :111 discardFlags( QwtPlotRenderer::DiscardNone ) ,112 layoutFlags( QwtPlotRenderer::DefaultLayout ) 131 public: 132 PrivateData() 133 : discardFlags( QwtPlotRenderer::DiscardNone ) 134 , layoutFlags( QwtPlotRenderer::DefaultLayout ) 113 135 { 114 136 } … … 121 143 Constructor 122 144 \param parent Parent object 123 */ 124 QwtPlotRenderer::QwtPlotRenderer( QObject *parent ):125 QObject( parent ) 126 { 127 d_data = new PrivateData;145 */ 146 QwtPlotRenderer::QwtPlotRenderer( QObject* parent ) 147 : QObject( parent ) 148 { 149 m_data = new PrivateData; 128 150 } 129 151 … … 131 153 QwtPlotRenderer::~QwtPlotRenderer() 132 154 { 133 delete d_data;134 } 135 136 /*! 137 Change a flag, indicating what to discard from rendering 138 139 \param flag Flag to change 140 \param on On/Off 141 142 \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags() 143 */ 155 delete m_data; 156 } 157 158 /*! 159 Change a flag, indicating what to discard from rendering 160 161 \param flag Flag to change 162 \param on On/Off 163 164 \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags() 165 */ 144 166 void QwtPlotRenderer::setDiscardFlag( DiscardFlag flag, bool on ) 145 167 { 146 168 if ( on ) 147 d_data->discardFlags |= flag;169 m_data->discardFlags |= flag; 148 170 else 149 d_data->discardFlags &= ~flag;150 } 151 152 /*! 153 \return True, if flag is enabled. 154 \param flag Flag to be tested 155 \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags() 156 */ 171 m_data->discardFlags &= ~flag; 172 } 173 174 /*! 175 \return True, if flag is enabled. 176 \param flag Flag to be tested 177 \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags() 178 */ 157 179 bool QwtPlotRenderer::testDiscardFlag( DiscardFlag flag ) const 158 180 { 159 return d_data->discardFlags & flag;160 } 161 162 /*! 163 Set the flags, indicating what to discard from rendering 164 165 \param flags Flags 166 \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags() 167 */ 181 return m_data->discardFlags & flag; 182 } 183 184 /*! 185 Set the flags, indicating what to discard from rendering 186 187 \param flags Flags 188 \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags() 189 */ 168 190 void QwtPlotRenderer::setDiscardFlags( DiscardFlags flags ) 169 191 { 170 d_data->discardFlags = flags;171 } 172 173 /*! 174 \return Flags, indicating what to discard from rendering 175 \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag() 176 */ 192 m_data->discardFlags = flags; 193 } 194 195 /*! 196 \return Flags, indicating what to discard from rendering 197 \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag() 198 */ 177 199 QwtPlotRenderer::DiscardFlags QwtPlotRenderer::discardFlags() const 178 200 { 179 return d_data->discardFlags;180 } 181 182 /*! 183 Change a layout flag 184 185 \param flag Flag to change 186 \param on On/Off 187 188 \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags() 189 */ 201 return m_data->discardFlags; 202 } 203 204 /*! 205 Change a layout flag 206 207 \param flag Flag to change 208 \param on On/Off 209 210 \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags() 211 */ 190 212 void QwtPlotRenderer::setLayoutFlag( LayoutFlag flag, bool on ) 191 213 { 192 214 if ( on ) 193 d_data->layoutFlags |= flag;215 m_data->layoutFlags |= flag; 194 216 else 195 d_data->layoutFlags &= ~flag;196 } 197 198 /*! 199 \return True, if flag is enabled. 200 \param flag Flag to be tested 201 \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags() 202 */ 217 m_data->layoutFlags &= ~flag; 218 } 219 220 /*! 221 \return True, if flag is enabled. 222 \param flag Flag to be tested 223 \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags() 224 */ 203 225 bool QwtPlotRenderer::testLayoutFlag( LayoutFlag flag ) const 204 226 { 205 return d_data->layoutFlags & flag;206 } 207 208 /*! 209 Set the layout flags 210 211 \param flags Flags 212 \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags() 213 */ 227 return m_data->layoutFlags & flag; 228 } 229 230 /*! 231 Set the layout flags 232 233 \param flags Flags 234 \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags() 235 */ 214 236 void QwtPlotRenderer::setLayoutFlags( LayoutFlags flags ) 215 237 { 216 d_data->layoutFlags = flags;217 } 218 219 /*! 220 \return Layout flags 221 \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag() 222 */ 238 m_data->layoutFlags = flags; 239 } 240 241 /*! 242 \return Layout flags 243 \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag() 244 */ 223 245 QwtPlotRenderer::LayoutFlags QwtPlotRenderer::layoutFlags() const 224 246 { 225 return d_data->layoutFlags;226 } 227 228 /*! 229 Render a plot to a file 230 231 The format of the document will be auto-detected from the 232 suffix of the file name. 233 234 \param plot Plot widget 235 \param fileName Path of the file, where the document will be stored 236 \param sizeMM Size for the document in millimeters. 237 \param resolution Resolution in dots per Inch (dpi) 238 */ 239 void QwtPlotRenderer::renderDocument( QwtPlot *plot,240 const QString &fileName, const QSizeF&sizeMM, int resolution )247 return m_data->layoutFlags; 248 } 249 250 /*! 251 Render a plot to a file 252 253 The format of the document will be auto-detected from the 254 suffix of the file name. 255 256 \param plot Plot widget 257 \param fileName Path of the file, where the document will be stored 258 \param sizeMM Size for the document in millimeters. 259 \param resolution Resolution in dots per Inch (dpi) 260 */ 261 void QwtPlotRenderer::renderDocument( QwtPlot* plot, 262 const QString& fileName, const QSizeF& sizeMM, int resolution ) 241 263 { 242 264 renderDocument( plot, fileName, … … 245 267 246 268 /*! 247 Render a plot to a file 248 249 Supported formats are: 250 251 - pdf\n 269 Render a plot to a file 270 271 Supported formats are: 272 273 - pdf\n 252 274 Portable Document Format PDF 253 - ps\n 275 - ps\n 254 276 Postcript 255 - svg\n 277 - svg\n 256 278 Scalable Vector Graphics SVG 257 - all image formats supported by Qt\n 279 - all image formats supported by Qt\n 258 280 see QImageWriter::supportedImageFormats() 259 281 260 Scalable vector graphic formats like PDF or SVG are superior to 261 raster graphics formats. 262 263 \param plot Plot widget 264 \param fileName Path of the file, where the document will be stored 265 \param format Format for the document 266 \param sizeMM Size for the document in millimeters. 267 \param resolution Resolution in dots per Inch (dpi) 268 269 \sa renderTo(), render(), QwtPainter::setRoundingAlignment() 270 */ 271 void QwtPlotRenderer::renderDocument( QwtPlot *plot,272 const QString &fileName, const QString&format,273 const QSizeF &sizeMM, int resolution )282 Scalable vector graphic formats like PDF or SVG are superior to 283 raster graphics formats. 284 285 \param plot Plot widget 286 \param fileName Path of the file, where the document will be stored 287 \param format Format for the document 288 \param sizeMM Size for the document in millimeters. 289 \param resolution Resolution in dots per Inch (dpi) 290 291 \sa renderTo(), render(), QwtPainter::setRoundingAlignment() 292 */ 293 void QwtPlotRenderer::renderDocument( QwtPlot* plot, 294 const QString& fileName, const QString& format, 295 const QSizeF& sizeMM, int resolution ) 274 296 { 275 297 if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 ) … … 292 314 #if QWT_PDF_WRITER 293 315 QPdfWriter pdfWriter( fileName ); 294 pdfWriter.setPageSize MM( sizeMM );316 pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) ); 295 317 pdfWriter.setTitle( title ); 296 318 pdfWriter.setPageMargins( QMarginsF() ); … … 366 388 367 389 /*! 368 \brief Render the plot to a \c QPaintDevice 369 370 This function renders the contents of a QwtPlot instance to 371 \c QPaintDevice object. The target rectangle is derived from 372 its device metrics. 373 374 \param plot Plot to be rendered 375 \param paintDevice device to paint on, f.e a QImage 376 377 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 378 */ 390 \brief Render the plot to a \c QPaintDevice 391 392 This function renders the contents of a QwtPlot instance to 393 \c QPaintDevice object. The target rectangle is derived from 394 its device metrics. 395 396 \param plot Plot to be rendered 397 \param paintDevice device to paint on, f.e a QImage 398 399 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 400 */ 379 401 380 402 void QwtPlotRenderer::renderTo( 381 QwtPlot *plot, QPaintDevice&paintDevice ) const403 QwtPlot* plot, QPaintDevice& paintDevice ) const 382 404 { 383 405 int w = paintDevice.width(); … … 389 411 390 412 /*! 391 \brief Render the plot to a QPrinter 392 393 This function renders the contents of a QwtPlot instance to 394 \c QPaintDevice object. The size is derived from the printer 395 metrics. 396 397 \param plot Plot to be rendered 398 \param printer Printer to paint on 399 400 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 401 */ 413 \brief Render the plot to a QPrinter 414 415 This function renders the contents of a QwtPlot instance to 416 \c QPaintDevice object. The size is derived from the printer 417 metrics. 418 419 \param plot Plot to be rendered 420 \param printer Printer to paint on 421 422 \sa renderDocument(), render(), QwtPainter::setRoundingAlignment() 423 */ 402 424 403 425 #ifndef QT_NO_PRINTER 404 426 405 427 void QwtPlotRenderer::renderTo( 406 QwtPlot *plot, QPrinter&printer ) const428 QwtPlot* plot, QPrinter& printer ) const 407 429 { 408 430 int w = printer.width(); … … 423 445 424 446 /*! 425 \brief Render the plot to a QSvgGenerator 426 427 If the generator has a view box, the plot will be rendered into it. 428 If it has no viewBox but a valid size the target coordinates 429 will be (0, 0, generator.width(), generator.height()). Otherwise 430 the target rectangle will be QRectF(0, 0, 800, 600); 431 432 \param plot Plot to be rendered 433 \param generator SVG generator 434 */ 447 \brief Render the plot to a QSvgGenerator 448 449 If the generator has a view box, the plot will be rendered into it. 450 If it has no viewBox but a valid size the target coordinates 451 will be (0, 0, generator.width(), generator.height()). Otherwise 452 the target rectangle will be QRectF(0, 0, 800, 600); 453 454 \param plot Plot to be rendered 455 \param generator SVG generator 456 */ 435 457 void QwtPlotRenderer::renderTo( 436 QwtPlot *plot, QSvgGenerator&generator ) const458 QwtPlot* plot, QSvgGenerator& generator ) const 437 459 { 438 460 QRectF rect = generator.viewBoxF(); … … 450 472 451 473 /*! 452 Paint the contents of a QwtPlot instance into a given rectangle. 453 454 \param plot Plot to be rendered 455 \param painter Painter 456 \param plotRect Bounding rectangle 457 458 \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment() 459 */ 460 void QwtPlotRenderer::render( QwtPlot *plot,461 QPainter *painter, const QRectF&plotRect ) const474 Paint the contents of a QwtPlot instance into a given rectangle. 475 476 \param plot Plot to be rendered 477 \param painter Painter 478 \param plotRect Bounding rectangle 479 480 \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment() 481 */ 482 void QwtPlotRenderer::render( QwtPlot* plot, 483 QPainter* painter, const QRectF& plotRect ) const 462 484 { 463 485 if ( painter == 0 || !painter->isActive() || 464 !plotRect.isValid() || plot->size().isNull() )486 !plotRect.isValid() || plot->size().isNull() ) 465 487 { 466 488 return; 467 489 } 468 490 469 if ( !( d_data->discardFlags & DiscardBackground ) )491 if ( !( m_data->discardFlags & DiscardBackground ) ) 470 492 QwtPainter::drawBackgound( painter, plotRect, plot ); 471 493 472 494 /* 473 The layout engine uses the same methods as they are used 474 by the Qt layout system. Therefore we need to calculate the 475 layout in screen coordinates and paint with a scaled painter. 495 The layout engine uses the same methods as they are used 496 by the Qt layout system. Therefore we need to calculate the 497 layout in screen coordinates and paint with a scaled painter. 476 498 */ 477 499 QTransform transform; … … 482 504 QRectF layoutRect = transform.inverted().mapRect( plotRect ); 483 505 484 if ( !( d_data->discardFlags & DiscardBackground ) )506 if ( !( m_data->discardFlags & DiscardBackground ) ) 485 507 { 486 508 // subtract the contents margins 487 509 488 int left, top, right, bottom; 489 plot->getContentsMargins( &left, &top, &right, &bottom ); 490 layoutRect.adjust( left, top, -right, -bottom ); 491 } 492 493 QwtPlotLayout *layout = plot->plotLayout(); 494 495 int baseLineDists[QwtPlot::axisCnt]; 496 int canvasMargins[QwtPlot::axisCnt]; 497 498 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 499 { 500 canvasMargins[ axisId ] = layout->canvasMargin( axisId ); 501 502 if ( d_data->layoutFlags & FrameWithScales ) 503 { 504 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); 510 const QMargins m = plot->contentsMargins(); 511 layoutRect.adjust( m.left(), m.top(), -m.right(), -m.bottom() ); 512 } 513 514 QwtPlotLayout* layout = plot->plotLayout(); 515 516 int baseLineDists[QwtAxis::AxisPositions]; 517 int canvasMargins[QwtAxis::AxisPositions]; 518 519 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 520 { 521 canvasMargins[axisPos] = layout->canvasMargin( axisPos ); 522 523 if ( m_data->layoutFlags & FrameWithScales ) 524 { 525 const QwtAxisId axisId( axisPos ); 526 527 QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 505 528 if ( scaleWidget ) 506 529 { 507 baseLineDists[axis Id] = scaleWidget->margin();530 baseLineDists[axisPos] = scaleWidget->margin(); 508 531 scaleWidget->setMargin( 0 ); 509 532 } 510 533 511 if ( !plot-> axisEnabled( axisId ) )534 if ( !plot->isAxisVisible( axisId ) ) 512 535 { 513 536 // When we have a scale the frame is painted on … … 515 538 // need to introduce a margin around the canvas 516 539 517 switch( axisId ) 540 const qreal fw = qwtScalePenWidth( plot ); 541 542 switch( axisPos ) 518 543 { 519 case Qwt Plot::yLeft:520 layoutRect.adjust( 1, 0, 0, 0 );544 case QwtAxis::YLeft: 545 layoutRect.adjust( fw, 0, 0, 0 ); 521 546 break; 522 case QwtPlot::yRight: 523 layoutRect.adjust( 0, 0, -1, 0 ); 547 548 case QwtAxis::YRight: 549 layoutRect.adjust( 0, 0, -fw, 0 ); 524 550 break; 525 case QwtPlot::xTop: 526 layoutRect.adjust( 0, 1, 0, 0 ); 551 552 case QwtAxis::XTop: 553 layoutRect.adjust( 0, fw, 0, 0 ); 527 554 break; 528 case QwtPlot::xBottom: 529 layoutRect.adjust( 0, 0, 0, -1 ); 555 556 case QwtAxis::XBottom: 557 layoutRect.adjust( 0, 0, 0, -fw ); 530 558 break; 559 531 560 default: 532 break;561 ; 533 562 } 534 563 } … … 540 569 QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars; 541 570 542 if ( ( d_data->layoutFlags & FrameWithScales ) ||543 ( d_data->discardFlags & DiscardCanvasFrame ) )571 if ( ( m_data->layoutFlags & FrameWithScales ) || 572 ( m_data->discardFlags & DiscardCanvasFrame ) ) 544 573 { 545 574 layoutOptions |= QwtPlotLayout::IgnoreFrames; 546 575 } 547 576 548 if ( d_data->discardFlags & DiscardLegend )577 if ( m_data->discardFlags & DiscardLegend ) 549 578 layoutOptions |= QwtPlotLayout::IgnoreLegend; 550 579 551 if ( d_data->discardFlags & DiscardTitle )580 if ( m_data->discardFlags & DiscardTitle ) 552 581 layoutOptions |= QwtPlotLayout::IgnoreTitle; 553 582 554 if ( d_data->discardFlags & DiscardFooter )583 if ( m_data->discardFlags & DiscardFooter ) 555 584 layoutOptions |= QwtPlotLayout::IgnoreFooter; 556 585 … … 559 588 // canvas 560 589 561 QwtScaleMap maps[Qwt Plot::axisCnt];590 QwtScaleMap maps[QwtAxis::AxisPositions]; 562 591 buildCanvasMaps( plot, layout->canvasRect(), maps ); 563 592 if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) ) … … 577 606 renderCanvas( plot, painter, layout->canvasRect(), maps ); 578 607 579 if ( !( d_data->discardFlags & DiscardTitle )608 if ( !( m_data->discardFlags & DiscardTitle ) 580 609 && ( !plot->titleLabel()->text().isEmpty() ) ) 581 610 { … … 583 612 } 584 613 585 if ( !( d_data->discardFlags & DiscardFooter )614 if ( !( m_data->discardFlags & DiscardFooter ) 586 615 && ( !plot->footerLabel()->text().isEmpty() ) ) 587 616 { … … 589 618 } 590 619 591 if ( !( d_data->discardFlags & DiscardLegend )620 if ( !( m_data->discardFlags & DiscardLegend ) 592 621 && plot->legend() && !plot->legend()->isEmpty() ) 593 622 { … … 595 624 } 596 625 597 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 598 { 599 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); 600 if ( scaleWidget ) 601 { 602 int baseDist = scaleWidget->margin(); 603 604 int startDist, endDist; 605 scaleWidget->getBorderDistHint( startDist, endDist ); 606 607 renderScale( plot, painter, axisId, startDist, endDist, 608 baseDist, layout->scaleRect( axisId ) ); 626 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 627 { 628 { 629 const QwtAxisId axisId( axisPos ); 630 631 QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 632 if ( scaleWidget ) 633 { 634 int baseDist = scaleWidget->margin(); 635 636 int startDist, endDist; 637 scaleWidget->getBorderDistHint( startDist, endDist ); 638 639 renderScale( plot, painter, axisId, startDist, endDist, 640 baseDist, layout->scaleRect( axisId ) ); 641 } 609 642 } 610 643 } … … 613 646 614 647 // restore all setting to their original attributes. 615 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 616 { 617 if ( d_data->layoutFlags & FrameWithScales ) 618 { 619 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); 648 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 649 { 650 if ( m_data->layoutFlags & FrameWithScales ) 651 { 652 const QwtAxisId axisId( axisPos ); 653 654 QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 620 655 if ( scaleWidget ) 621 scaleWidget->setMargin( baseLineDists[axis Id] );622 } 623 624 layout->setCanvasMargin( canvasMargins[axis Id] );656 scaleWidget->setMargin( baseLineDists[axisPos] ); 657 } 658 659 layout->setCanvasMargin( canvasMargins[axisPos] ); 625 660 } 626 661 … … 630 665 631 666 /*! 632 Render the title into a given rectangle. 633 634 \param plot Plot widget 635 \param painter Painter 636 \param titleRect Bounding rectangle for the title 637 */ 638 void QwtPlotRenderer::renderTitle( const QwtPlot *plot,639 QPainter *painter, const QRectF&titleRect ) const667 Render the title into a given rectangle. 668 669 \param plot Plot widget 670 \param painter Painter 671 \param titleRect Bounding rectangle for the title 672 */ 673 void QwtPlotRenderer::renderTitle( const QwtPlot* plot, 674 QPainter* painter, const QRectF& titleRect ) const 640 675 { 641 676 painter->setFont( qwtResolvedFont( plot->titleLabel() ) ); 642 677 643 678 const QColor color = plot->titleLabel()->palette().color( 644 QPalette::Active, QPalette::Text );679 QPalette::Active, QPalette::Text ); 645 680 646 681 painter->setPen( color ); … … 649 684 650 685 /*! 651 Render the footer into a given rectangle. 652 653 \param plot Plot widget 654 \param painter Painter 655 \param footerRect Bounding rectangle for the footer 656 */ 657 void QwtPlotRenderer::renderFooter( const QwtPlot *plot,658 QPainter *painter, const QRectF&footerRect ) const686 Render the footer into a given rectangle. 687 688 \param plot Plot widget 689 \param painter Painter 690 \param footerRect Bounding rectangle for the footer 691 */ 692 void QwtPlotRenderer::renderFooter( const QwtPlot* plot, 693 QPainter* painter, const QRectF& footerRect ) const 659 694 { 660 695 painter->setFont( qwtResolvedFont( plot->footerLabel() ) ); 661 696 662 697 const QColor color = plot->footerLabel()->palette().color( 663 QPalette::Active, QPalette::Text );698 QPalette::Active, QPalette::Text ); 664 699 665 700 painter->setPen( color ); … … 668 703 669 704 /*! 670 Render the legend into a given rectangle. 671 672 \param plot Plot widget 673 \param painter Painter 674 \param legendRect Bounding rectangle for the legend 675 */ 676 void QwtPlotRenderer::renderLegend( const QwtPlot *plot,677 QPainter *painter, const QRectF&legendRect ) const705 Render the legend into a given rectangle. 706 707 \param plot Plot widget 708 \param painter Painter 709 \param legendRect Bounding rectangle for the legend 710 */ 711 void QwtPlotRenderer::renderLegend( const QwtPlot* plot, 712 QPainter* painter, const QRectF& legendRect ) const 678 713 { 679 714 if ( plot->legend() ) 680 715 { 681 bool fillBackground = !( d_data->discardFlags & DiscardBackground );716 bool fillBackground = !( m_data->discardFlags & DiscardBackground ); 682 717 plot->legend()->renderLegend( painter, legendRect, fillBackground ); 683 718 } … … 685 720 686 721 /*! 687 \brief Paint a scale into a given rectangle. 688 Paint the scale into a given rectangle. 689 690 \param plot Plot widget 691 \param painter Painter 692 \param axisId Axis 693 \param startDist Start border distance 694 \param endDist End border distance 695 \param baseDist Base distance 696 \param scaleRect Bounding rectangle for the scale 697 */ 698 void QwtPlotRenderer::renderScale( const QwtPlot *plot, 699 QPainter *painter, 700 int axisId, int startDist, int endDist, int baseDist, 701 const QRectF &scaleRect ) const 702 { 703 if ( !plot->axisEnabled( axisId ) ) 722 \brief Paint a scale into a given rectangle. 723 Paint the scale into a given rectangle. 724 725 \param plot Plot widget 726 \param painter Painter 727 \param axisId Axis 728 \param startDist Start border distance 729 \param endDist End border distance 730 \param baseDist Base distance 731 \param scaleRect Bounding rectangle for the scale 732 */ 733 void QwtPlotRenderer::renderScale( const QwtPlot* plot, QPainter* painter, 734 QwtAxisId axisId, int startDist, int endDist, int baseDist, 735 const QRectF& scaleRect ) const 736 { 737 if ( !plot->isAxisVisible( axisId ) ) 704 738 return; 705 739 706 const QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );740 const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId ); 707 741 if ( scaleWidget->isColorBarEnabled() 708 742 && scaleWidget->colorBarWidth() > 0 ) … … 717 751 double x, y, w; 718 752 753 qreal off = 0.0; 754 if ( m_data->layoutFlags & FrameWithScales ) 755 off = qwtScalePenWidth( plot ); 756 719 757 switch ( axisId ) 720 758 { 721 case Qwt Plot::yLeft:722 { 723 x = scaleRect.right() - 1.0 - baseDist; 759 case QwtAxis::YLeft: 760 { 761 x = scaleRect.right() - 1.0 - baseDist - off; 724 762 y = scaleRect.y() + startDist; 725 763 w = scaleRect.height() - startDist - endDist; … … 727 765 break; 728 766 } 729 case Qwt Plot::yRight:730 { 731 x = scaleRect.left() + baseDist; 767 case QwtAxis::YRight: 768 { 769 x = scaleRect.left() + baseDist + off; 732 770 y = scaleRect.y() + startDist; 733 771 w = scaleRect.height() - startDist - endDist; … … 735 773 break; 736 774 } 737 case Qwt Plot::xTop:775 case QwtAxis::XTop: 738 776 { 739 777 x = scaleRect.left() + startDist; 740 y = scaleRect.bottom() - 1.0 - baseDist; 778 y = scaleRect.bottom() - 1.0 - baseDist - off; 741 779 w = scaleRect.width() - startDist - endDist; 742 780 align = QwtScaleDraw::TopScale; 743 781 break; 744 782 } 745 case Qwt Plot::xBottom:783 case QwtAxis::XBottom: 746 784 { 747 785 x = scaleRect.left() + startDist; 748 y = scaleRect.top() + baseDist; 786 y = scaleRect.top() + baseDist + off; 749 787 w = scaleRect.width() - startDist - endDist; 750 788 align = QwtScaleDraw::BottomScale; … … 759 797 painter->setFont( qwtResolvedFont( scaleWidget ) ); 760 798 761 QwtScaleDraw *sd = const_cast<QwtScaleDraw*>( scaleWidget->scaleDraw() );799 QwtScaleDraw* sd = const_cast< QwtScaleDraw* >( scaleWidget->scaleDraw() ); 762 800 const QPointF sdPos = sd->pos(); 763 801 const double sdLength = sd->length(); 802 803 const bool hasBackbone = sd->hasComponent( QwtAbstractScaleDraw::Backbone ); 804 805 if ( m_data->layoutFlags & FrameWithScales ) 806 sd->enableComponent( QwtAbstractScaleDraw::Backbone, false ); 764 807 765 808 sd->move( x, y ); … … 773 816 sd->move( sdPos ); 774 817 sd->setLength( sdLength ); 818 sd->enableComponent( QwtAbstractScaleDraw::Backbone, hasBackbone ); 775 819 776 820 painter->restore(); … … 778 822 779 823 /*! 780 Render the canvas into a given rectangle. 781 782 \param plot Plot widget 783 \param painter Painter 784 \param maps Maps mapping between plot and paint device coordinates 785 \param canvasRect Canvas rectangle 786 */ 787 void QwtPlotRenderer::renderCanvas( const QwtPlot *plot,788 QPainter *painter, const QRectF&canvasRect,789 const QwtScaleMap *maps ) const790 { 791 const QWidget *canvas = plot->canvas();824 Render the canvas into a given rectangle. 825 826 \param plot Plot widget 827 \param painter Painter 828 \param maps Maps mapping between plot and paint device coordinates 829 \param canvasRect Canvas rectangle 830 */ 831 void QwtPlotRenderer::renderCanvas( const QwtPlot* plot, 832 QPainter* painter, const QRectF& canvasRect, 833 const QwtScaleMap* maps ) const 834 { 835 const QWidget* canvas = plot->canvas(); 792 836 793 837 QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 ); 794 838 795 if ( d_data->layoutFlags & FrameWithScales )839 if ( m_data->layoutFlags & FrameWithScales ) 796 840 { 797 841 painter->save(); 798 842 799 r.adjust( -1.0, -1.0, 1.0, 1.0 ); 800 painter->setPen( QPen( Qt::black ) ); 801 802 if ( !( d_data->discardFlags & DiscardCanvasBackground ) ) 843 QPen pen; 844 pen.setColor( qwtScalePenColor( plot ) ); 845 pen.setWidth( qwtScalePenWidth( plot ) ); 846 pen.setJoinStyle( Qt::MiterJoin ); 847 848 painter->setPen( pen ); 849 850 const qreal pw2 = 0.5 * pen.widthF(); 851 r.adjust( -pw2, -pw2, pw2, pw2 ); 852 853 if ( !( m_data->discardFlags & DiscardCanvasBackground ) ) 803 854 { 804 855 const QBrush bgBrush = … … 823 874 painter->save(); 824 875 825 if ( !( d_data->discardFlags & DiscardCanvasBackground ) )876 if ( !( m_data->discardFlags & DiscardCanvasBackground ) ) 826 877 { 827 878 QwtPainter::drawBackgound( painter, r, canvas ); … … 845 896 QPainterPath clipPath; 846 897 847 intframeWidth = 0;848 849 if ( !( d_data->discardFlags & DiscardCanvasFrame ) )898 double frameWidth = 0.0; 899 900 if ( !( m_data->discardFlags & DiscardCanvasFrame ) ) 850 901 { 851 902 const QVariant fw = canvas->property( "frameWidth" ); 852 if ( fw. type() == QVariant::Int)853 frameWidth = fw. toInt();903 if ( fw.canConvert< double >() ) 904 frameWidth = fw.value< double >(); 854 905 855 906 clipPath = qwtCanvasClip( canvas, canvasRect ); … … 870 921 } 871 922 872 if ( !( d_data->discardFlags & DiscardCanvasBackground ) )923 if ( !( m_data->discardFlags & DiscardCanvasBackground ) ) 873 924 { 874 925 QwtPainter::drawBackgound( painter, innerRect, canvas ); … … 888 939 889 940 const QVariant borderRadius = canvas->property( "borderRadius" ); 890 if ( borderRadius. type() == QVariant::Double891 && borderRadius. toDouble() > 0.0 )941 if ( borderRadius.canConvert< double >() 942 && borderRadius.value< double >() > 0.0 ) 892 943 { 893 const double radius = borderRadius. toDouble();944 const double radius = borderRadius.value< double >(); 894 945 895 946 QwtPainter::drawRoundedFrame( painter, canvasRect, … … 915 966 \param canvasRect Target rectangle 916 967 \param maps Scale maps to be calculated 917 */ 918 void QwtPlotRenderer::buildCanvasMaps( const QwtPlot *plot, 919 const QRectF &canvasRect, QwtScaleMap maps[] ) const 920 { 921 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 922 { 923 maps[axisId].setTransformation( 924 plot->axisScaleEngine( axisId )->transformation() ); 925 926 const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId ); 927 maps[axisId].setScaleInterval( 928 scaleDiv.lowerBound(), scaleDiv.upperBound() ); 929 930 double from, to; 931 if ( plot->axisEnabled( axisId ) ) 932 { 933 const int sDist = plot->axisWidget( axisId )->startBorderDist(); 934 const int eDist = plot->axisWidget( axisId )->endBorderDist(); 935 const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId ); 936 937 if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom ) 968 */ 969 void QwtPlotRenderer::buildCanvasMaps( const QwtPlot* plot, 970 const QRectF& canvasRect, QwtScaleMap maps[] ) const 971 { 972 for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) 973 { 974 { 975 const QwtAxisId axisId( axisPos ); 976 977 QwtScaleMap& scaleMap = maps[axisId]; 978 979 scaleMap.setTransformation( 980 plot->axisScaleEngine( axisId )->transformation() ); 981 982 const QwtScaleDiv& scaleDiv = plot->axisScaleDiv( axisId ); 983 scaleMap.setScaleInterval( 984 scaleDiv.lowerBound(), scaleDiv.upperBound() ); 985 986 double from, to; 987 if ( plot->isAxisVisible( axisId ) ) 938 988 { 939 from = scaleRect.left() + sDist; 940 to = scaleRect.right() - eDist; 989 const int sDist = plot->axisWidget( axisId )->startBorderDist(); 990 const int eDist = plot->axisWidget( axisId )->endBorderDist(); 991 const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId ); 992 993 if ( QwtAxis::isXAxis( axisPos ) ) 994 { 995 from = scaleRect.left() + sDist; 996 to = scaleRect.right() - eDist; 997 } 998 else 999 { 1000 from = scaleRect.bottom() - eDist; 1001 to = scaleRect.top() + sDist; 1002 } 941 1003 } 942 1004 else 943 1005 { 944 from = scaleRect.bottom() - eDist; 945 to = scaleRect.top() + sDist; 1006 int margin = 0; 1007 if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) ) 1008 margin = plot->plotLayout()->canvasMargin( axisPos ); 1009 1010 if ( QwtAxis::isYAxis( axisPos ) ) 1011 { 1012 from = canvasRect.bottom() - margin; 1013 to = canvasRect.top() + margin; 1014 } 1015 else 1016 { 1017 from = canvasRect.left() + margin; 1018 to = canvasRect.right() - margin; 1019 } 946 1020 } 947 } 948 else 949 { 950 int margin = 0; 951 if ( !plot->plotLayout()->alignCanvasToScale( axisId ) ) 952 margin = plot->plotLayout()->canvasMargin( axisId ); 953 954 if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight ) 955 { 956 from = canvasRect.bottom() - margin; 957 to = canvasRect.top() + margin; 958 } 959 else 960 { 961 from = canvasRect.left() + margin; 962 to = canvasRect.right() - margin; 963 } 964 } 965 maps[axisId].setPaintInterval( from, to ); 966 } 967 } 968 969 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot *plot, 970 const QRectF &canvasRect, const QwtScaleMap maps[] ) const 971 { 972 double margins[QwtPlot::axisCnt]; 1021 scaleMap.setPaintInterval( from, to ); 1022 } 1023 } 1024 } 1025 1026 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot* plot, 1027 const QRectF& canvasRect, const QwtScaleMap maps[] ) const 1028 { 1029 using namespace QwtAxis; 1030 1031 double margins[AxisPositions]; 973 1032 plot->getCanvasMarginsHint( maps, canvasRect, 974 margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 975 margins[QwtPlot::yRight], margins[QwtPlot::xBottom] ); 1033 margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] ); 976 1034 977 1035 bool marginsChanged = false; 978 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )1036 for ( int axisId = 0; axisId < AxisPositions; axisId++ ) 979 1037 { 980 1038 if ( margins[axisId] >= 0.0 ) 981 1039 { 982 const int m = qCeil( margins[axisId] ); 1040 const int m = qwtCeil( margins[axisId] ); 983 1041 plot->plotLayout()->setCanvasMargin( m, axisId); 984 1042 marginsChanged = true; … … 999 1057 \return True, when exporting was successful 1000 1058 \sa renderDocument() 1001 */ 1002 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString&documentName,1003 const QSizeF&sizeMM, int resolution )1059 */ 1060 bool QwtPlotRenderer::exportTo( QwtPlot* plot, const QString& documentName, 1061 const QSizeF& sizeMM, int resolution ) 1004 1062 { 1005 1063 if ( plot == NULL ) … … 1011 1069 1012 1070 #ifndef QT_NO_FILEDIALOG 1013 const QList<QByteArray> imageFormats = 1071 const QList< QByteArray > imageFormats = 1014 1072 QImageWriter::supportedImageFormats(); 1015 1073 … … 1052 1110 return true; 1053 1111 } 1112 1113 #include "moc_qwt_plot_renderer.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
