Changeset 9383 in ntrip for trunk/BNC/qwt/qwt_plot_renderer.cpp


Ignore:
Timestamp:
Mar 19, 2021, 9:15:03 AM (3 years ago)
Author:
stoecker
Message:

update to qwt verion 6.1.1 to fix build with newer Qt5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_plot_renderer.cpp

    r8127 r9383  
    1515#include "qwt_scale_widget.h"
    1616#include "qwt_scale_engine.h"
     17#include "qwt_scale_map.h"
    1718#include "qwt_text.h"
    1819#include "qwt_text_label.h"
    1920#include "qwt_math.h"
     21
    2022#include <qpainter.h>
    21 #include <qpaintengine.h>
     23#include <qpainterpath.h>
    2224#include <qtransform.h>
    2325#include <qprinter.h>
    24 #include <qprintdialog.h>
    2526#include <qfiledialog.h>
    2627#include <qfileinfo.h>
    27 #include <qstyle.h>
    28 #include <qstyleoption.h>
    2928#include <qimagewriter.h>
     29#include <qvariant.h>
     30
    3031#ifndef QWT_NO_SVG
    3132#ifdef QT_SVG_LIB
     33#if QT_VERSION >= 0x040500
     34#define QWT_FORMAT_SVG 1
     35#endif
     36#endif
     37#endif
     38
     39#ifndef QT_NO_PRINTER
     40#define QWT_FORMAT_PDF 1
     41#endif
     42
     43#ifndef QT_NO_PDF
     44
     45// QPdfWriter::setResolution() has been introduced with
     46// Qt 5.3. Guess it is o.k. to stay with QPrinter for older
     47// versions.
     48
     49#if QT_VERSION >= 0x050300
     50
     51#ifndef QWT_FORMAT_PDF
     52#define QWT_FORMAT_PDF 1
     53#endif
     54
     55#define QWT_PDF_WRITER 1
     56
     57#endif
     58#endif
     59
     60#ifndef QT_NO_PRINTER
     61// postscript support has been dropped in Qt5
     62#if QT_VERSION < 0x050000
     63#define QWT_FORMAT_POSTSCRIPT 1
     64#endif
     65#endif
     66
     67#if QWT_FORMAT_SVG
    3268#include <qsvggenerator.h>
    3369#endif
    34 #endif
    35 
    36 static QPainterPath qwtCanvasClip(
     70
     71#if QWT_PDF_WRITER
     72#include <qpdfwriter.h>
     73#endif
     74
     75static QPainterPath qwtCanvasClip(
    3776    const QWidget* canvas, const QRectF &canvasRect )
    3877{
     
    5897}
    5998
     99static inline QFont qwtResolvedFont( const QWidget *widget )
     100{
     101    QFont font = widget->font();
     102    font.resolve( QFont::AllPropertiesResolved );
     103
     104    return font;
     105}
     106
    60107class QwtPlotRenderer::PrivateData
    61108{
     
    71118};
    72119
    73 /*! 
     120/*!
    74121   Constructor
    75122   \param parent Parent object
     
    239286
    240287    const QString fmt = format.toLower();
    241     if ( fmt == "pdf" )
    242     {
    243 #ifndef QT_NO_PRINTER
     288    if ( fmt == QLatin1String( "pdf" ) )
     289    {
     290#if QWT_FORMAT_PDF
     291
     292#if QWT_PDF_WRITER
     293        QPdfWriter pdfWriter( fileName );
     294        pdfWriter.setPageSizeMM( sizeMM );
     295        pdfWriter.setTitle( title );
     296        pdfWriter.setPageMargins( QMarginsF() );
     297        pdfWriter.setResolution( resolution );
     298
     299        QPainter painter( &pdfWriter );
     300        render( plot, &painter, documentRect );
     301#else
    244302        QPrinter printer;
    245303        printer.setOutputFormat( QPrinter::PdfFormat );
     
    254312        render( plot, &painter, documentRect );
    255313#endif
    256     }
    257     else if ( fmt == "ps" )
    258     {
    259 #if QT_VERSION < 0x050000
    260 #ifndef QT_NO_PRINTER
     314#endif
     315    }
     316    else if ( fmt == QLatin1String( "ps" ) )
     317    {
     318#if QWT_FORMAT_POSTSCRIPT
    261319        QPrinter printer;
    262320        printer.setOutputFormat( QPrinter::PostScriptFormat );
     
    271329        render( plot, &painter, documentRect );
    272330#endif
    273 #endif
    274     }
    275     else if ( fmt == "svg" )
    276     {
    277 #ifndef QWT_NO_SVG
    278 #ifdef QT_SVG_LIB
    279 #if QT_VERSION >= 0x040500
     331    }
     332    else if ( fmt == QLatin1String( "svg" ) )
     333    {
     334#if QWT_FORMAT_SVG
    280335        QSvgGenerator generator;
    281336        generator.setTitle( title );
     
    287342        render( plot, &painter, documentRect );
    288343#endif
    289 #endif
    290 #endif
    291344    }
    292345    else
     
    367420#endif
    368421
    369 #ifndef QWT_NO_SVG
    370 #ifdef QT_SVG_LIB
    371 #if QT_VERSION >= 0x040500
     422#if QWT_FORMAT_SVG
    372423
    373424/*!
     
    395446    render( plot, &p, rect );
    396447}
    397 #endif
    398 #endif
     448
    399449#endif
    400450
     
    461511            if ( !plot->axisEnabled( axisId ) )
    462512            {
    463                 int left = 0;
    464                 int right = 0;
    465                 int top = 0;
    466                 int bottom = 0;
    467 
    468513                // When we have a scale the frame is painted on
    469514                // the position of the backbone - otherwise we
     
    487532                        break;
    488533                }
    489                 layoutRect.adjust( left, top, right, bottom );
    490534            }
    491535        }
     
    500544    {
    501545        layoutOptions |= QwtPlotLayout::IgnoreFrames;
    502     }
    503 
     546    }
    504547
    505548    if ( d_data->discardFlags & DiscardLegend )
     
    591634  \param plot Plot widget
    592635  \param painter Painter
    593   \param rect Bounding rectangle
     636  \param titleRect Bounding rectangle for the title
    594637*/
    595638void QwtPlotRenderer::renderTitle( const QwtPlot *plot,
    596     QPainter *painter, const QRectF &rect ) const
    597 {
    598     painter->setFont( plot->titleLabel()->font() );
     639    QPainter *painter, const QRectF &titleRect ) const
     640{
     641    painter->setFont( qwtResolvedFont( plot->titleLabel() ) );
    599642
    600643    const QColor color = plot->titleLabel()->palette().color(
     
    602645
    603646    painter->setPen( color );
    604     plot->titleLabel()->text().draw( painter, rect );
     647    plot->titleLabel()->text().draw( painter, titleRect );
    605648}
    606649
     
    610653  \param plot Plot widget
    611654  \param painter Painter
    612   \param rect Bounding rectangle
     655  \param footerRect Bounding rectangle for the footer
    613656*/
    614657void QwtPlotRenderer::renderFooter( const QwtPlot *plot,
    615     QPainter *painter, const QRectF &rect ) const
    616 {
    617     painter->setFont( plot->footerLabel()->font() );
     658    QPainter *painter, const QRectF &footerRect ) const
     659{
     660    painter->setFont( qwtResolvedFont( plot->footerLabel() ) );
    618661
    619662    const QColor color = plot->footerLabel()->palette().color(
     
    621664
    622665    painter->setPen( color );
    623     plot->footerLabel()->text().draw( painter, rect );
    624 }
    625 
     666    plot->footerLabel()->text().draw( painter, footerRect );
     667}
    626668
    627669/*!
     
    630672  \param plot Plot widget
    631673  \param painter Painter
    632   \param rect Bounding rectangle
     674  \param legendRect Bounding rectangle for the legend
    633675*/
    634676void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    635     QPainter *painter, const QRectF &rect ) const
     677    QPainter *painter, const QRectF &legendRect ) const
    636678{
    637679    if ( plot->legend() )
    638680    {
    639681        bool fillBackground = !( d_data->discardFlags & DiscardBackground );
    640         plot->legend()->renderLegend( painter, rect, fillBackground );
     682        plot->legend()->renderLegend( painter, legendRect, fillBackground );
    641683    }
    642684}
     
    652694  \param endDist End border distance
    653695  \param baseDist Base distance
    654   \param rect Bounding rectangle
     696  \param scaleRect Bounding rectangle for the scale
    655697*/
    656698void QwtPlotRenderer::renderScale( const QwtPlot *plot,
    657699    QPainter *painter,
    658700    int axisId, int startDist, int endDist, int baseDist,
    659     const QRectF &rect ) const
     701    const QRectF &scaleRect ) const
    660702{
    661703    if ( !plot->axisEnabled( axisId ) )
     
    666708        && scaleWidget->colorBarWidth() > 0 )
    667709    {
    668         scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) );
     710        scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( scaleRect ) );
    669711        baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing();
    670712    }
     
    679721        case QwtPlot::yLeft:
    680722        {
    681             x = rect.right() - 1.0 - baseDist;
    682             y = rect.y() + startDist;
    683             w = rect.height() - startDist - endDist;
     723            x = scaleRect.right() - 1.0 - baseDist;
     724            y = scaleRect.y() + startDist;
     725            w = scaleRect.height() - startDist - endDist;
    684726            align = QwtScaleDraw::LeftScale;
    685727            break;
     
    687729        case QwtPlot::yRight:
    688730        {
    689             x = rect.left() + baseDist;
    690             y = rect.y() + startDist;
    691             w = rect.height() - startDist - endDist;
     731            x = scaleRect.left() + baseDist;
     732            y = scaleRect.y() + startDist;
     733            w = scaleRect.height() - startDist - endDist;
    692734            align = QwtScaleDraw::RightScale;
    693735            break;
     
    695737        case QwtPlot::xTop:
    696738        {
    697             x = rect.left() + startDist;
    698             y = rect.bottom() - 1.0 - baseDist;
    699             w = rect.width() - startDist - endDist;
     739            x = scaleRect.left() + startDist;
     740            y = scaleRect.bottom() - 1.0 - baseDist;
     741            w = scaleRect.width() - startDist - endDist;
    700742            align = QwtScaleDraw::TopScale;
    701743            break;
     
    703745        case QwtPlot::xBottom:
    704746        {
    705             x = rect.left() + startDist;
    706             y = rect.top() + baseDist;
    707             w = rect.width() - startDist - endDist;
     747            x = scaleRect.left() + startDist;
     748            y = scaleRect.top() + baseDist;
     749            w = scaleRect.width() - startDist - endDist;
    708750            align = QwtScaleDraw::BottomScale;
    709751            break;
     
    713755    }
    714756
    715     scaleWidget->drawTitle( painter, align, rect );
    716 
    717     painter->setFont( scaleWidget->font() );
     757    scaleWidget->drawTitle( painter, align, scaleRect );
     758
     759    painter->setFont( qwtResolvedFont( scaleWidget ) );
    718760
    719761    QwtScaleDraw *sd = const_cast<QwtScaleDraw *>( scaleWidget->scaleDraw() );
     
    740782  \param plot Plot widget
    741783  \param painter Painter
    742   \param map Maps mapping between plot and paint device coordinates
     784  \param maps Maps mapping between plot and paint device coordinates
    743785  \param canvasRect Canvas rectangle
    744786*/
    745787void QwtPlotRenderer::renderCanvas( const QwtPlot *plot,
    746     QPainter *painter, const QRectF &canvasRect, 
    747     const QwtScaleMap *map ) const
     788    QPainter *painter, const QRectF &canvasRect,
     789    const QwtScaleMap *maps ) const
    748790{
    749791    const QWidget *canvas = plot->canvas();
     
    771813
    772814        painter->setClipRect( canvasRect );
    773         plot->drawItems( painter, canvasRect, map );
     815        plot->drawItems( painter, canvasRect, maps );
    774816
    775817        painter->restore();
     
    795837            painter->setClipPath( clipPath );
    796838
    797         plot->drawItems( painter, canvasRect, map );
     839        plot->drawItems( painter, canvasRect, maps );
    798840
    799841        painter->restore();
     
    814856        }
    815857
    816         QRectF innerRect = canvasRect.adjusted( 
     858        QRectF innerRect = canvasRect.adjusted(
    817859            frameWidth, frameWidth, -frameWidth, -frameWidth );
    818860
     
    833875        }
    834876
    835         plot->drawItems( painter, innerRect, map );
     877        plot->drawItems( painter, innerRect, maps );
    836878
    837879        painter->restore();
     
    845887                canvas->property( "frameShape" ).toInt();
    846888
    847             const int frameWidth = canvas->property( "frameWidth" ).toInt();
    848 
    849 
    850889            const QVariant borderRadius = canvas->property( "borderRadius" );
    851             if ( borderRadius.type() == QVariant::Double 
     890            if ( borderRadius.type() == QVariant::Double
    852891                && borderRadius.toDouble() > 0.0 )
    853892            {
    854                 const double r = borderRadius.toDouble();
     893                const double radius = borderRadius.toDouble();
    855894
    856895                QwtPainter::drawRoundedFrame( painter, canvasRect,
    857                     r, r, canvas->palette(), frameWidth, frameStyle );
     896                    radius, radius, canvas->palette(), frameWidth, frameStyle );
    858897            }
    859898            else
     
    933972    double margins[QwtPlot::axisCnt];
    934973    plot->getCanvasMarginsHint( maps, canvasRect,
    935         margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 
     974        margins[QwtPlot::yLeft], margins[QwtPlot::xTop],
    936975        margins[QwtPlot::yRight], margins[QwtPlot::xBottom] );
    937976
     
    9631002bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName,
    9641003     const QSizeF &sizeMM, int resolution )
    965 {       
     1004{
    9661005    if ( plot == NULL )
    9671006        return false;
    968    
     1007
    9691008    QString fileName = documentName;
    9701009
    971     // What about translation 
     1010    // What about translation
    9721011
    9731012#ifndef QT_NO_FILEDIALOG
    9741013    const QList<QByteArray> imageFormats =
    9751014        QImageWriter::supportedImageFormats();
    976        
     1015
    9771016    QStringList filter;
    978 #ifndef QT_NO_PRINTER
     1017#if QWT_FORMAT_PDF
    9791018    filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)";
    9801019#endif
    981 #ifndef QWT_NO_SVG
     1020#if QWT_FORMAT_SVG
    9821021    filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)";
    9831022#endif
    984 #ifndef QT_NO_PRINTER
     1023#if QWT_FORMAT_POSTSCRIPT
    9851024    filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)";
    9861025#endif
    987    
     1026
    9881027    if ( imageFormats.size() > 0 )
    9891028    {
     
    9941033            if ( i > 0 )
    9951034                imageFilter += " ";
    996             imageFilter += "*."; 
     1035            imageFilter += "*.";
    9971036            imageFilter += imageFormats[i];
    998         }   
     1037        }
    9991038        imageFilter += ")";
    1000        
     1039
    10011040        filter += imageFilter;
    1002     }   
    1003    
     1041    }
     1042
    10041043    fileName = QFileDialog::getSaveFileName(
    10051044        NULL, tr( "Export File Name" ), fileName,
    10061045        filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
    1007 #endif 
     1046#endif
    10081047    if ( fileName.isEmpty() )
    10091048        return false;
     
    10121051
    10131052    return true;
    1014 }   
     1053}
Note: See TracChangeset for help on using the changeset viewer.