示例#1
0
void QwtPlot::drawItems(QPainter *painter, const QRect &rect, 
        const QwtScaleMap map[axisCnt], 
        const QwtPlotPrintFilter &pfilter) const
{
    const QwtPlotItemList& itmList = itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item && item->isVisible() )
        {
            if ( !(pfilter.options() & QwtPlotPrintFilter::PrintGrid)
                && item->rtti() == QwtPlotItem::Rtti_PlotGrid )
            {
                continue;
            }

            painter->save();

#if QT_VERSION >= 0x040000
            painter->setRenderHint(QPainter::Antialiasing,
                item->testRenderHint(QwtPlotItem::RenderAntialiased) );
#endif

            item->draw(painter, 
                map[item->xAxis()], map[item->yAxis()],
                rect);

            painter->restore();
        }
    }
}
示例#2
0
void QwtPlot::drawItems( QPainter *painter, const QRectF &canvasRect,
        const QwtScaleMap maps[axisCnt] ) const
{
    const QwtPlotItemList& itmList = itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item && item->isVisible() )
        {
            painter->save();

            painter->setRenderHint( QPainter::Antialiasing,
                item->testRenderHint( QwtPlotItem::RenderAntialiased ) );
            painter->setRenderHint( QPainter::HighQualityAntialiasing,
                item->testRenderHint( QwtPlotItem::RenderAntialiased ) );

            item->draw( painter,
                maps[item->xAxis()], maps[item->yAxis()],
                canvasRect );

            painter->restore();
        }
    }
}
示例#3
0
QwtPlotShapeItem* Editor::itemAt( const QPoint& pos ) const
{
    const QwtPlot *plot = this->plot();
    if ( plot == NULL )
        return NULL;

    // translate pos into the plot coordinates
    double coords[ QwtPlot::axisCnt ];
    coords[ QwtPlot::xBottom ] =
        plot->canvasMap( QwtPlot::xBottom ).invTransform( pos.x() );
    coords[ QwtPlot::xTop ] =
        plot->canvasMap( QwtPlot::xTop ).invTransform( pos.x() );
    coords[ QwtPlot::yLeft ] =
        plot->canvasMap( QwtPlot::yLeft ).invTransform( pos.y() );
    coords[ QwtPlot::yRight ] =
        plot->canvasMap( QwtPlot::yRight ).invTransform( pos.y() );

    QwtPlotItemList items = plot->itemList();
    for ( int i = items.size() - 1; i >= 0; i-- )
    {
        QwtPlotItem *item = items[ i ];
        if ( item->isVisible() &&
            item->rtti() == QwtPlotItem::Rtti_PlotShape )
        {
            QwtPlotShapeItem *shapeItem = static_cast<QwtPlotShapeItem *>( item );
            const QPointF p( coords[ item->xAxis() ], coords[ item->yAxis() ] );

            if ( shapeItem->boundingRect().contains( p )
                && shapeItem->shape().contains( p ) )
            {
                return shapeItem;
            }
        }
    }

    return NULL;
}
示例#4
0
void QwtPlot::drawItems(QPainter *painter, const QRect &rect, 
        const QwtArray<QwtScaleMap> &map, 
        const QwtPlotPrintFilter &pfilter) const
{
    painter->save();

    const QwtPlotItemList& itmList = itemList();
    for ( QwtPlotItemIterator it = itmList.begin();
        it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        if ( item && item->isVisible() )
        {
            if ( !(pfilter.options() & QwtPlotPrintFilter::PrintGrid)
                && item->rtti() == QwtPlotItem::Rtti_PlotGrid )
            {
                continue;
            }

#if QT_VERSION >= 0x040000
            const QPaintEngine *pe = painter->device()->paintEngine();
            if (pe->hasFeature(QPaintEngine::Antialiasing) )
            {
                painter->setRenderHint(QPainter::Antialiasing,
                    item->testRenderHint(QwtPlotItem::RenderAntialiased) );
            }
#endif

            item->draw(painter, 
                map[item->xAxis()], map[item->yAxis()],
                rect);
        }
    }

    painter->restore();
}
//! Rebuild the scales and maps
void QwtPlot::updateAxes() 
{
    // Find bounding interval of the item data
    // for all axes, where autoscaling is enabled
    
    QwtDoubleInterval intv[axisCnt];

    const QwtPlotItemList& itmList = itemList();

    QwtPlotItemIterator it;
    for ( it = itmList.begin(); it != itmList.end(); ++it )
    {
        const QwtPlotItem *item = *it;

        if ( !item->testItemAttribute(QwtPlotItem::AutoScale) )
            continue;

        if ( axisAutoScale(item->xAxis()) || axisAutoScale(item->yAxis()) )
        {
            const QwtDoubleRect rect = item->boundingRect();
            intv[item->xAxis()] |= QwtDoubleInterval(rect.left(), rect.right());
            intv[item->yAxis()] |= QwtDoubleInterval(rect.top(), rect.bottom());
        }
    }

    // Adjust scales

    for (int axisId = 0; axisId < axisCnt; axisId++)
    {
        AxisData &d = *d_axisData[axisId];

        double minValue = d.minValue;
        double maxValue = d.maxValue;
        double stepSize = d.stepSize;

        if ( d.doAutoScale && intv[axisId].isValid() )
        {
            d.scaleDiv.invalidate();

            minValue = intv[axisId].minValue();
            maxValue = intv[axisId].maxValue();

            d.scaleEngine->autoScale(d.maxMajor, 
                minValue, maxValue, stepSize);
        }
        if ( !d.scaleDiv.isValid() )
        {
            d.scaleDiv = d.scaleEngine->divideScale(
                minValue, maxValue, 
                d.maxMajor, d.maxMinor, stepSize);
        }

        QwtScaleWidget *scaleWidget = axisWidget(axisId);
        scaleWidget->setScaleDiv(
            d.scaleEngine->transformation(), d.scaleDiv);

        int startDist, endDist;
        scaleWidget->getBorderDistHint(startDist, endDist);
        scaleWidget->setBorderDist(startDist, endDist);
    }

    for ( it = itmList.begin(); it != itmList.end(); ++it )
    {
        QwtPlotItem *item = *it;
        item->updateScaleDiv( *axisScaleDiv(item->xAxis()),
            *axisScaleDiv(item->yAxis()));
    }
}