/*!
   Calculated the scale maps for rendering the canvas

   \param plot Plot widget
   \param canvasRect Target rectangle
   \param maps Scale maps to be calculated
*/
QwtScaleMapTable QwtPlotRenderer::buildCanvasMaps( 
    const QwtPlot *plot, const QRectF &canvasRect ) const
{
    QwtScaleMapTable mapTable;

    for ( int axisPos = 0; axisPos < QwtAxis::PosCount; axisPos++ )
    {
        for ( int i = 0; i < plot->axesCount( axisPos ); i++ )
        {
            const QwtAxisId axisId( axisPos, i );

            QwtScaleMap scaleMap;

            scaleMap.setTransformation( plot->axisScaleEngine( axisId )->transformation() );

            const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
            scaleMap.setScaleInterval(
                scaleDiv.lowerBound(), scaleDiv.upperBound() );

            double from, to;
            if ( plot->isAxisVisible( axisId ) )
            {
                const int sDist = plot->axisWidget( axisId )->startBorderDist();
                const int eDist = plot->axisWidget( axisId )->endBorderDist();
                const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );

                if ( QwtAxis::isXAxis( axisPos ) )
                {
                    from = scaleRect.left() + sDist;
                    to = scaleRect.right() - eDist;
                }
                else
                {
                    from = scaleRect.bottom() - eDist;
                    to = scaleRect.top() + sDist;
                }
            }
            else
            {
                int margin = 0;
                if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) )
                    margin = plot->plotLayout()->canvasMargin( axisPos );

                if ( QwtAxis::isYAxis( axisPos ) )
                {
                    from = canvasRect.bottom() - margin;
                    to = canvasRect.top() + margin;
                }
                else
                {
                    from = canvasRect.left() + margin;
                    to = canvasRect.right() - margin;
                }
            }
            scaleMap.setPaintInterval( from, to );

            mapTable.maps[axisPos] += scaleMap;

        }
    }

    return mapTable;
}
Esempio n. 2
0
void ScaleDraw::drawBackbone(QPainter *painter) const
{
    ScaleEngine *sc_engine = static_cast<ScaleEngine *>(d_plot->axisScaleEngine(axis()));
    /*QwtScaleEngine *qwtsc_engine=d_plot->axisScaleEngine(axis());
    ScaleEngine *sc_engine =dynamic_cast<ScaleEngine*>(qwtsc_engine);
    if(sc_engine!=NULL)
    {*/
    if (!sc_engine->hasBreak()) {
        const int len = length();
        const int bw = painter->pen().width();
        const int bw2 = bw / 2;
        QPoint pos = this->pos();
        switch(alignment()) {
        case LeftScale:
            QwtPainter::drawLine(painter, pos.x() - bw2,
                                 pos.y(), pos.x() - bw2, pos.y() + len );
            break;
        case RightScale:
            QwtPainter::drawLine(painter, pos.x() + bw2,
                                 pos.y(), pos.x() + bw2, pos.y() + len);
            break;
        case TopScale:
            QwtPainter::drawLine(painter, pos.x(), pos.y() - bw2,
                                 pos.x() + len, pos.y() - bw2);
            break;
        case BottomScale:
            QwtPainter::drawLine(painter, pos.x(), pos.y() + bw2,
                                 pos.x() + len, pos.y() + bw2);
            break;
        }
        return;
    }

    QwtScaleMap scaleMap = map();
    const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
    QPoint pos = this->pos();

    if ( !metricsMap.isIdentity() ) {
        QwtPainter::resetMetricsMap();
        pos = metricsMap.layoutToDevice(pos);

        if ( orientation() == Qt::Vertical ) {
            scaleMap.setPaintInterval(
                metricsMap.layoutToDeviceY((int)scaleMap.p1()),
                metricsMap.layoutToDeviceY((int)scaleMap.p2()));
        } else {
            scaleMap.setPaintInterval(
                metricsMap.layoutToDeviceX((int)scaleMap.p1()),
                metricsMap.layoutToDeviceX((int)scaleMap.p2()));
        }
    }

    const int start = scaleMap.transform(sc_engine->axisBreakLeft());
    const int end = scaleMap.transform(sc_engine->axisBreakRight());
    int lb = start, rb = end;
    if (sc_engine->testAttribute(QwtScaleEngine::Inverted)) {
        lb = end;
        rb = start;
    }

    const int bw = painter->pen().width();
    const int bw2 = bw / 2;
    const int len = length() - 1;
    int aux;
    switch(alignment())
    {
    case LeftScale:
        aux = pos.x() - bw2;
        QwtPainter::drawLine(painter, aux, pos.y(), aux, rb);
        QwtPainter::drawLine(painter, aux, lb + bw, aux, pos.y() + len);
        break;
    case RightScale:
        aux = pos.x() + bw2;
        QwtPainter::drawLine(painter, aux, pos.y(), aux, rb - bw - 1);
        QwtPainter::drawLine(painter, aux, lb - bw2, aux, pos.y() + len);
        break;
    case TopScale:
        aux = pos.y() - bw2;
        QwtPainter::drawLine(painter, pos.x(), aux, lb - bw2, aux);
        QwtPainter::drawLine(painter, rb + bw, aux, pos.x() + len, aux);
        break;
    case BottomScale:
        aux = pos.y() + bw2;
        QwtPainter::drawLine(painter, pos.x(), aux, lb - bw, aux);
        QwtPainter::drawLine(painter, rb, aux, pos.x() + len, aux);
        break;
    }
    //}
}
void QwtPainter::drawColorBar(QPainter *painter,
        const QwtColorMap &colorMap, const QwtDoubleInterval &interval,
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
        const QRect &rect)
{
    painter->save();

    QwtPainter::setClipRect(painter, rect);

#if QT_VERSION < 0x040000
    QValueVector<QRgb> colorTable;
#else
    QVector<QRgb> colorTable;
#endif
    if ( colorMap.format() == QwtColorMap::Indexed )
        colorTable = colorMap.colorTable(interval);

    QColor c;

    const QRect devRect = d_metricsMap.layoutToDevice(rect);

    if ( orientation == Qt::Horizontal )
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval(devRect.left(), devRect.right());

        for ( int x = devRect.left(); x <= devRect.right(); x++ )
        {
            const double value = sMap.invTransform(x);

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb(colorMap.rgb(interval, value));
            else
                c = colorTable[colorMap.colorIndex(interval, value)];

            painter->setBrush(QBrush(c));

            const QRect r(x, devRect.top(), 1, devRect.height());
            QwtPainter::drawRect(painter, r);
            painter->setPen(c);
            painter->drawLine(x, devRect.top(), x, devRect.bottom() - 1);
        }
    }
    else // Vertical
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval(devRect.bottom(), devRect.top());

        for ( int y = devRect.top(); y <= devRect.bottom(); y++ )
        {
            const double value = sMap.invTransform(y);

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb(colorMap.rgb(interval, value));
            else
                c = colorTable[colorMap.colorIndex(interval, value)];

            painter->setPen(c);
            painter->drawLine(devRect.left(), y, devRect.right() - 1, y);
        }
    }
    painter->restore();
}
Esempio n. 4
0
void ScaleDraw::drawBreak(QPainter *painter) const
{
    ScaleEngine *sc_engine = static_cast<ScaleEngine *>(d_plot->axisScaleEngine(axis()));
    /*const QwtScaleEngine * qwtsc_engine=d_plot->axisScaleEngine(axis());
    const ScaleEngine *sc_engine =dynamic_cast<const ScaleEngine*>(qwtsc_engine);
    if(sc_engine!=NULL)
    {*/
    if (!sc_engine->hasBreak() || !sc_engine->hasBreakDecoration())
        return;

    painter->save();
    painter->setRenderHint(QPainter::Antialiasing);

    int len = majTickLength();

    QwtScaleMap scaleMap = map();
    const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
    QPoint pos = this->pos();

    if ( !metricsMap.isIdentity() ) {
        QwtPainter::resetMetricsMap();
        pos = metricsMap.layoutToDevice(pos);

        if ( orientation() == Qt::Vertical ) {
            scaleMap.setPaintInterval(
                metricsMap.layoutToDeviceY((int)scaleMap.p1()),
                metricsMap.layoutToDeviceY((int)scaleMap.p2()));
            len = metricsMap.layoutToDeviceX(len);
        } else {
            scaleMap.setPaintInterval(
                metricsMap.layoutToDeviceX((int)scaleMap.p1()),
                metricsMap.layoutToDeviceX((int)scaleMap.p2()));
            len = metricsMap.layoutToDeviceY(len);
        }
    }

    int lval = scaleMap.transform(sc_engine->axisBreakLeft());
    int rval = scaleMap.transform(sc_engine->axisBreakRight());
    switch(alignment()) {
    case LeftScale:
        QwtPainter::drawLine(painter, pos.x(), lval, pos.x() - len, lval + len);
        QwtPainter::drawLine(painter, pos.x(), rval, pos.x() - len, rval + len);
        break;
    case RightScale:
        QwtPainter::drawLine(painter, pos.x(), lval, pos.x() + len, lval - len);
        QwtPainter::drawLine(painter, pos.x(), rval, pos.x() + len, rval - len);
        break;
    case BottomScale:
        QwtPainter::drawLine(painter, lval, pos.y(), lval - len, pos.y() + len);
        QwtPainter::drawLine(painter, rval, pos.y(), rval - len, pos.y() + len);
        break;
    case TopScale:
        QwtPainter::drawLine(painter, lval, pos.y(), lval + len, pos.y() - len);
        QwtPainter::drawLine(painter, rval, pos.y(), rval + len, pos.y() - len);
        break;
    }

    QwtPainter::setMetricsMap(metricsMap); // restore metrics map
    painter->restore();
    //}
}
Esempio n. 5
0
void QwtPainter::drawColorBar(QPainter *painter,
        const QwtColorMap &colorMap, const QwtDoubleInterval &interval,
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
        const QRect &rect)
{
#if QT_VERSION < 0x040000
    QValueVector<QRgb> colorTable;
#else
    QVector<QRgb> colorTable;
#endif
    if ( colorMap.format() == QwtColorMap::Indexed )
        colorTable = colorMap.colorTable(interval);

    QColor c;

    const QRect devRect = d_metricsMap.layoutToDevice(rect);

    /*
      We paint to a pixmap first to have something scalable for printing
      ( f.e. in a Pdf document )
     */
      
    QPixmap pixmap(devRect.size());
    QPainter pmPainter(&pixmap);
    pmPainter.translate(-devRect.x(), -devRect.y());

    if ( orientation == Qt::Horizontal )
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval(devRect.left(), devRect.right());

        for ( int x = devRect.left(); x <= devRect.right(); x++ )
        {
            const double value = sMap.invTransform(x);

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb(colorMap.rgb(interval, value));
            else
                c = colorTable[colorMap.colorIndex(interval, value)];

            pmPainter.setPen(c);
            pmPainter.drawLine(x, devRect.top(), x, devRect.bottom());
        }
    }
    else // Vertical
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval(devRect.bottom(), devRect.top());

        for ( int y = devRect.top(); y <= devRect.bottom(); y++ )
        {
            const double value = sMap.invTransform(y);

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb(colorMap.rgb(interval, value));
            else
                c = colorTable[colorMap.colorIndex(interval, value)];

            pmPainter.setPen(c);
            pmPainter.drawLine(devRect.left(), y, devRect.right(), y);
        }
    }
    pmPainter.end();
    painter->drawPixmap(devRect, pixmap);
}