/*!
   Draw a tick

   \param painter Painter
   \param value Value of the tick
   \param len Lenght of the tick

   \sa drawBackbone(), drawLabel()
*/
void QwtScaleDraw::drawTick( QPainter *painter, double value, double len ) const
{
    if ( len <= 0 )
        return;

    const bool roundingAlignment = QwtPainter::roundingAlignment( painter );

    QwtScaleMap scaleMap = map();
    QPointF pos = d_data->pos;

    double tval = scaleMap.transform( value );
    if ( roundingAlignment )
        tval = qRound( tval );

    const int pw = penWidth();
    int a = 0;
    if ( pw > 1 && roundingAlignment )
        a = 1;

    switch ( alignment() )
    {
        case LeftScale:
        {
            double x1 = pos.x() + a;
            double x2 = pos.x() + a - pw - len;
            if ( roundingAlignment )
            {
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            QwtPainter::drawLine( painter, x1, tval, x2, tval );
            break;
        }

        case RightScale:
        {
            double x1 = pos.x();
            double x2 = pos.x() + pw + len;
            if ( roundingAlignment )
            {
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            QwtPainter::drawLine( painter, x1, tval, x2, tval );
            break;
        }

        case BottomScale:
        {
            double y1 = pos.y();
            double y2 = pos.y() + pw + len;
            if ( roundingAlignment )
            {
                y1 = qRound( y1 );
                y2 = qRound( y2 );
            }

            QwtPainter::drawLine( painter, tval, y1, tval, y2 );
            break;
        }

        case TopScale:
        {
            double y1 = pos.y() + a;
            double y2 = pos.y() - pw - len + a;
            if ( roundingAlignment )
            {
                y1 = qRound( y1 );
                y2 = qRound( y2 );
            }

            QwtPainter::drawLine( painter, tval, y1, tval, y2 );
            break;
        }
    }
}
Example #2
0
/*!
  Draw dots

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rectangle of the canvas
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawDots( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const QColor color = painter->pen().color();

    if ( painter->pen().style() == Qt::NoPen || color.alpha() == 0 )
    {
        return;
    }

    const bool doFill = ( d_data->brush.style() != Qt::NoBrush )
            && ( d_data->brush.color().alpha() > 0 );
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    QwtPointMapper mapper;
    mapper.setBoundingRect( canvasRect );
    mapper.setFlag( QwtPointMapper::RoundPoints, doAlign );

    if ( d_data->paintAttributes & FilterPoints )
    {
        if ( ( color.alpha() == 255 )
            && !( painter->renderHints() & QPainter::Antialiasing ) )
        {
            mapper.setFlag( QwtPointMapper::WeedOutPoints, true );
        }
    }

    if ( doFill )
    {
        mapper.setFlag( QwtPointMapper::WeedOutPoints, false );

        QPolygonF points = mapper.toPointsF( 
            xMap, yMap, data(), from, to );

        QwtPainter::drawPoints( painter, points );
        fillCurve( painter, xMap, yMap, canvasRect, points );
    }
    else if ( d_data->paintAttributes & ImageBuffer )
    {
        const QImage image = mapper.toImage( xMap, yMap,
            data(), from, to, d_data->pen, 
            painter->testRenderHint( QPainter::Antialiasing ),
            renderThreadCount() );

        painter->drawImage( canvasRect.toAlignedRect(), image );
    }
    else if ( d_data->paintAttributes & MinimizeMemory )
    {
        const QwtSeriesData<QPointF> *series = data();

        for ( int i = from; i <= to; i++ )
        {
            const QPointF sample = series->sample( i );

            double xi = xMap.transform( sample.x() );
            double yi = yMap.transform( sample.y() );

            if ( doAlign )
            {
                xi = qRound( xi );
                yi = qRound( yi );
            }

            QwtPainter::drawPoint( painter, QPointF( xi, yi ) );
        }
    }
    else
    {
        if ( doAlign )
        {
            const QPolygon points = mapper.toPoints(
                xMap, yMap, data(), from, to ); 

            QwtPainter::drawPoints( painter, points );
        }
        else
        {
            const QPolygonF points = mapper.toPointsF( 
                xMap, yMap, data(), from, to );

            QwtPainter::drawPoints( painter, points );
        }
    }
}
Example #3
0
void Plot::drawInwardTicks(QPainter *painter, const QRect &rect,
		const QwtScaleMap &map, int axis, bool min, bool maj) const
{
	int x1=rect.left();
	int x2=rect.right();
	int y1=rect.top();
	int y2=rect.bottom();

	QPalette pal=axisWidget(axis)->palette();
	QColor color=pal.color(QPalette::Active, QColorGroup::Foreground);

	painter->save();
	painter->setPen(QPen(color, axesLinewidth(), Qt::SolidLine));

	const QwtScaleDiv *scDiv=(const QwtScaleDiv *)axisScaleDiv(axis);
	const QwtValueList minTickList = scDiv->ticks(QwtScaleDiv::MinorTick);
	int minTicks = (int)minTickList.count();

	const QwtValueList medTickList = scDiv->ticks(QwtScaleDiv::MediumTick);
	int medTicks = (int)medTickList.count();

	const QwtValueList majTickList = scDiv->ticks(QwtScaleDiv::MajorTick);
	int majTicks = (int)majTickList.count();

	int j, x, y, low,high;
	switch (axis)
	{
		case QwtPlot::yLeft:
			x=x1;
			low=y1+majTickLength;
			high=y2-majTickLength;
			if (min){
				for (j = 0; j < minTicks; j++){
					y = map.transform(minTickList[j]);
					if (y>low && y< high)
						QwtPainter::drawLine(painter, x, y, x+minTickLength, y);
				}
				for (j = 0; j < medTicks; j++){
					y = map.transform(medTickList[j]);
					if (y>low && y< high)
						QwtPainter::drawLine(painter, x, y, x+minTickLength, y);
				}
			}

			if (maj){
				for (j = 0; j < majTicks; j++){
					y = map.transform(majTickList[j]);
					if (y>low && y< high)
						QwtPainter::drawLine(painter, x, y, x+majTickLength, y);
				}
			}
			break;

		case QwtPlot::yRight:
			{
				x=x2;
				low=y1+majTickLength;
				high=y2-majTickLength;
				if (min){
					for (j = 0; j < minTicks; j++){
						y = map.transform(minTickList[j]);
						if (y>low && y< high)
							QwtPainter::drawLine(painter, x+1, y, x-minTickLength, y);
					}
					for (j = 0; j < medTicks; j++){
						y = map.transform(medTickList[j]);
						if (y>low && y< high)
							QwtPainter::drawLine(painter, x+1, y, x-minTickLength, y);
					}
				}

				if (maj){
					for (j = 0; j <majTicks; j++){
						y = map.transform(majTickList[j]);
						if (y>low && y< high)
							QwtPainter::drawLine(painter, x+1, y, x-majTickLength, y);
					}
				}
			}
			break;

		case QwtPlot::xBottom:
			y=y2;
			low=x1+majTickLength;
			high=x2-majTickLength;
			if (min){
				for (j = 0; j < minTicks; j++){
					x = map.transform(minTickList[j]);
					if (x>low && x<high)
						QwtPainter::drawLine(painter, x, y+1, x, y-minTickLength);
				}
				for (j = 0; j < medTicks; j++){
					x = map.transform(medTickList[j]);
					if (x>low && x<high)
						QwtPainter::drawLine(painter, x, y+1, x, y-minTickLength);
				}
			}

			if (maj){
				for (j = 0; j < majTicks; j++){
					x = map.transform(majTickList[j]);
					if (x>low && x<high)
						QwtPainter::drawLine(painter, x, y+1, x, y-majTickLength);
				}
			}
			break;

		case QwtPlot::xTop:
			y=y1;
			low=x1+majTickLength;
			high=x2-majTickLength;

			if (min){
				for (j = 0; j < minTicks; j++){
					x = map.transform(minTickList[j]);
					if (x>low && x<high)
						QwtPainter::drawLine(painter, x, y, x, y + minTickLength);
				}
				for (j = 0; j < medTicks; j++){
					x = map.transform(medTickList[j]);
					if (x>low && x<high)
						QwtPainter::drawLine(painter, x, y, x, y + minTickLength);
				}
			}

			if (maj){
				for (j = 0; j <majTicks; j++){
					x = map.transform(majTickList[j]);
					if (x>low && x<high)
						QwtPainter::drawLine(painter, x, y, x, y + majTickLength);
				}
			}
			break;
	}
	painter->restore();
}
void ScaleDraw::drawBackbone(QPainter *painter) const
{
    ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
    if (!sc_engine->hasBreak()){
    	if (d_plot->isPrinting()){
			const int len = length();
			QPoint pos = this->pos();
			switch(alignment()){
				case LeftScale:
					QwtPainter::drawLine(painter, pos.x(), pos.y(), pos.x(), pos.y() + len );
				break;
				case RightScale:
					QwtPainter::drawLine(painter, pos.x(), pos.y(), pos.x(), pos.y() + len);
				break;
				case TopScale:
					QwtPainter::drawLine(painter, pos.x(), pos.y(), pos.x() + len, pos.y());
				break;
				case BottomScale:
					QwtPainter::drawLine(painter, pos.x(), pos.y(), pos.x() + len, pos.y());
				break;
			}
    	} else
			QwtScaleDraw::drawBackbone(painter);
        return;
    }

    QwtScaleMap scaleMap = map();
    QPoint pos = this->pos();
	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;
	}

	if (d_plot->isPrinting()){
		const int len = length();
		switch(alignment()){
			case LeftScale:
			case RightScale:
				QwtPainter::drawLine(painter, pos.x(), pos.y(), pos.x(), rb - 1);
				QwtPainter::drawLine(painter, pos.x(), lb + 1, pos.x(), pos.y() + len);
			break;
			case TopScale:
			case BottomScale:
				QwtPainter::drawLine(painter, pos.x(), pos.y(), lb - 1, pos.y());
				QwtPainter::drawLine(painter, rb + 1, pos.y(), pos.x() + len, pos.y());
			break;
		}
	} else {
		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;
		}
	}
}
Example #5
0
/*!
  Draw a color bar into a rectangle

  \param painter Painter
  \param colorMap Color map
  \param interval Value range
  \param scaleMap Scale map
  \param orientation Orientation
  \param rect Traget rectangle
*/
void QwtPainter::drawColorBar( QPainter *painter,
        const QwtColorMap &colorMap, const QwtInterval &interval,
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
        const QRectF &rect )
{
    QVector<QRgb> colorTable;
    if ( colorMap.format() == QwtColorMap::Indexed )
        colorTable = colorMap.colorTable( interval );

    QColor c;

    const QRect devRect = rect.toAlignedRect();

    /*
      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( rect.left(), rect.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( rect.bottom(), rect.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();

    drawPixmap( painter, rect, pixmap );
}
static QImage qwtExpandImage(const QImage &image,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &area, const QRectF &area2, const QRectF &paintRect,
    const QwtInterval &xInterval, const QwtInterval &yInterval )
{
    const QRectF strippedRect = qwtStripRect(paintRect, area2,
        xMap, yMap, xInterval, yInterval);
    const QSize sz = strippedRect.toRect().size();

    const int w = image.width();
    const int h = image.height();

    const QRectF r = QwtScaleMap::transform(xMap, yMap, area).normalized();
    const double pw = ( r.width() - 1) / w;
    const double ph = ( r.height() - 1) / h;

    double px0, py0;
    if ( !xMap.isInverting() )
    {
        px0 = xMap.transform( area2.left() );
        px0 = qRound( px0 );
        px0 = px0 - xMap.transform( area.left() );
    }
    else
    {
        px0 = xMap.transform( area2.right() );
        px0 = qRound( px0 );
        px0 -= xMap.transform( area.right() );

        px0 -= 1.0;
    }
    px0 += strippedRect.left() - paintRect.left();

    if ( !yMap.isInverting() )
    {
        py0 = yMap.transform( area2.top() );
        py0 = qRound( py0 );
        py0 -= yMap.transform( area.top() );
    }
    else
    {
        py0 = yMap.transform( area2.bottom() );
        py0 = qRound( py0 );
        py0 -= yMap.transform( area.bottom() );

        py0 -= 1.0;
    }
    py0 += strippedRect.top() - paintRect.top();

    QImage expanded(sz, image.format());

    switch( image.depth() )
    {
        case 32:
        {
            for ( int y1 = 0; y1 < h; y1++ )
            {
                int yy1;
                if ( y1 == 0 )
                {
                    yy1 = 0;
                }
                else
                {
                    yy1 = qRound( y1 * ph - py0 );
                    if ( yy1 < 0 )
                        yy1 = 0;
                }

                int yy2;
                if ( y1 == h - 1 )
                {
                    yy2 = sz.height();
                }
                else
                {
                    yy2 = qRound( ( y1 + 1 ) * ph - py0 );
                    if ( yy2 > sz.height() )
                        yy2 = sz.height();
                }

                const quint32 *line1 =
                    reinterpret_cast<const quint32 *>( image.scanLine( y1 ) );

                for ( int x1 = 0; x1 < w; x1++ )
                {
                    int xx1;
                    if ( x1 == 0 )
                    {
                        xx1 = 0;
                    }
                    else
                    {
                        xx1 = qRound( x1 * pw - px0 );
                        if ( xx1 < 0 )
                            xx1 = 0;
                    }

                    int xx2;
                    if ( x1 == w - 1 )
                    {
                        xx2 = sz.width();
                    }
                    else
                    {
                        xx2 = qRound( ( x1 + 1 ) * pw - px0 );
                        if ( xx2 > sz.width() )
                            xx2 = sz.width();
                    }

                    const quint32 rgb( line1[x1] );
                    for ( int y2 = yy1; y2 < yy2; y2++ )
                    {
                        quint32 *line2 = reinterpret_cast<quint32 *>(
                            expanded.scanLine( y2 ) );

                        for ( int x2 = xx1; x2 < xx2; x2++ )
                            line2[x2] = rgb;
                    }
                }
            }
            break;
        }
        case 8:
        {
            for ( int y1 = 0; y1 < h; y1++ )
            {
                int yy1;
                if ( y1 == 0 )
                {
                    yy1 = 0;
                }
                else
                {
                    yy1 = qRound( y1 * ph - py0 );
                    if ( yy1 < 0 )
                        yy1 = 0;
                }

                int yy2;
                if ( y1 == h - 1 )
                {
                    yy2 = sz.height();
                }
                else
                {
                    yy2 = qRound( ( y1 + 1 ) * ph - py0 );
                    if ( yy2 > sz.height() )
                        yy2 = sz.height();
                }

                const uchar *line1 = image.scanLine( y1 );

                for ( int x1 = 0; x1 < w; x1++ )
                {
                    int xx1;
                    if ( x1 == 0 )
                    {
                        xx1 = 0;
                    }
                    else
                    {
                        xx1 = qRound( x1 * pw - px0 );
                        if ( xx1 < 0 )
                            xx1 = 0;
                    }

                    int xx2;
                    if ( x1 == w - 1 )
                    {
                        xx2 = sz.width();
                    }
                    else
                    {
                        xx2 = qRound( ( x1 + 1 ) * pw - px0 );
                        if ( xx2 > sz.width() )
                            xx2 = sz.width();
                    }

                    for ( int y2 = yy1; y2 < yy2; y2++ )
                    {
                        uchar *line2 = expanded.scanLine( y2 );
                        memset( line2 + xx1, line1[x1], xx2 - xx1 );
                    }
                }
            }
            break;
        }
        default:
            expanded = image;
    }

    return expanded;
}
Example #7
0
/*!
  \brief Draw the raster data
  \param painter Painter
  \param xMap X-Scale Map
  \param yMap Y-Scale Map
  \param canvasRect Contents rect of the plot canvas
*/
void QwtPlotRasterItem::draw(QPainter *painter,
                             const QwtScaleMap &xMap, const QwtScaleMap &yMap,
                             const QRect &canvasRect) const
{
    if ( canvasRect.isEmpty() || d_data->alpha == 0 )
        return;

    QwtDoubleRect area = invTransform(xMap, yMap, canvasRect);
    if ( boundingRect().isValid() )
        area &= boundingRect();

    const QRect paintRect = transform(xMap, yMap, area);
    if ( !paintRect.isValid() )
        return;

    QImage image;

    bool doCache = true;
    if ( painter->device()->devType() == QInternal::Printer
            || painter->device()->devType() == QInternal::Picture )
    {
        doCache = false;
    }

    if ( !doCache || d_data->cache.policy == NoCache )
    {
        image = renderImage(xMap, yMap, area);
        if ( d_data->alpha >= 0 && d_data->alpha < 255 )
            image = toRgba(image, d_data->alpha);

    }
    else if ( d_data->cache.policy == PaintCache )
    {
        if ( d_data->cache.image.isNull() || d_data->cache.rect != area
                || d_data->cache.size != paintRect.size() )
        {
            d_data->cache.image = renderImage(xMap, yMap, area);
            d_data->cache.rect = area;
            d_data->cache.size = paintRect.size();
        }

        image = d_data->cache.image;
        if ( d_data->alpha >= 0 && d_data->alpha < 255 )
            image = toRgba(image, d_data->alpha);
    }
    else if ( d_data->cache.policy == ScreenCache )
    {
        const QSize screenSize =
            QApplication::desktop()->screenGeometry().size();

        if ( paintRect.width() > screenSize.width() ||
                paintRect.height() > screenSize.height() )
        {
            image = renderImage(xMap, yMap, area);
        }
        else
        {
            if ( d_data->cache.image.isNull() || d_data->cache.rect != area )
            {
                QwtScaleMap cacheXMap = xMap;
                cacheXMap.setPaintInterval( 0, screenSize.width());

                QwtScaleMap cacheYMap = yMap;
                cacheYMap.setPaintInterval(screenSize.height(), 0);

                d_data->cache.image = renderImage(
                                          cacheXMap, cacheYMap, area);
                d_data->cache.rect = area;
                d_data->cache.size = paintRect.size();
            }

            image = d_data->cache.image;
        }
        image = toRgba(image, d_data->alpha);
    }

    painter->drawImage(paintRect, image);
}
Example #8
0
/*!
   Update the axis scale draw geometries

   \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
   \param radialMap Maps radius values into painter coordinates.
   \param pole Position of the pole in painter coordinates
   \param radius Radius of the complete plot area in painter coordinates

   \sa updateScaleDiv()
*/
void QwtPolarGrid::updateScaleDraws(
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, double radius ) const
{
    const QPoint p = pole.toPoint();

    const QwtInterval interval =
        d_data->gridData[QwtPolar::ScaleRadius].scaleDiv.interval();

    const int min = radialMap.transform( interval.minValue() );
    const int max = radialMap.transform( interval.maxValue() );
    const int l = max - min;

    for ( int axisId = 0; axisId < QwtPolar::AxesCount; axisId++ )
    {
        AxisData &axis = d_data->axisData[axisId];

        if ( axisId == QwtPolar::AxisAzimuth )
        {
            QwtRoundScaleDraw *scaleDraw =
                static_cast<QwtRoundScaleDraw *>( axis.scaleDraw );

            scaleDraw->setRadius( qRound( radius ) );
            scaleDraw->moveCenter( p );

            double from = ::fmod( 90.0 - azimuthMap.p1() * 180.0 / M_PI, 360.0 );
            if ( from < 0.0 )
                from += 360.0;

            scaleDraw->setAngleRange( from, from - 360.0 );

            const QwtTransform *transform = azimuthMap.transformation();
            if ( transform )
                scaleDraw->setTransformation( transform->copy() );
            else
                scaleDraw->setTransformation( NULL );
        }
        else
        {
            QwtScaleDraw *scaleDraw =
                static_cast<QwtScaleDraw *>( axis.scaleDraw );

            switch( axisId )
            {
                case QwtPolar::AxisLeft:
                {
                    scaleDraw->move( p.x() - min, p.y() );
                    scaleDraw->setLength( -l );
                    break;
                }
                case QwtPolar::AxisRight:
                {
                    scaleDraw->move( p.x() + min, p.y() );
                    scaleDraw->setLength( l );
                    break;
                }
                case QwtPolar::AxisTop:
                {
                    scaleDraw->move( p.x(), p.y() - max );
                    scaleDraw->setLength( l );
                    break;
                }
                case QwtPolar::AxisBottom:
                {
                    scaleDraw->move( p.x(), p.y() + max );
                    scaleDraw->setLength( -l );
                    break;
                }
            }
            const QwtTransform *transform = radialMap.transformation();
            if ( transform )
                scaleDraw->setTransformation( transform->copy() );
            else
                scaleDraw->setTransformation( NULL );
        }
    }
}
Example #9
0
void QwtPieCurve::drawSlices(QPainter *painter, const QwtScaleMap &xMap,
                             const QwtScaleMap &yMap, int from, int to) const {
  const double x_width = fabs(xMap.p1() - xMap.p2());
  const double x_center =
      (xMap.p1() + xMap.p2()) * 0.5 + d_horizontal_offset * 0.01 * x_width;
  const double y_center = (yMap.p1() + yMap.p2()) * 0.5;
  const double ray_x =
      d_pie_ray * 0.005 * qMin(x_width, fabs(yMap.p1() - yMap.p2()));
  const double view_angle_rad = d_view_angle * M_PI / 180.0;
  const double ray_y = ray_x * sin(view_angle_rad);
  const double thick = 0.01 * d_thickness * ray_x * cos(view_angle_rad);

  QRectF pieRect;
  pieRect.setX(x_center - ray_x);
  pieRect.setY(y_center - ray_y);
  pieRect.setWidth(2 * ray_x);
  pieRect.setHeight(2 * ray_y);

  QRectF pieRect2 = pieRect;
  pieRect2.translate(0, thick);

  double sum = 0.0;
  for (int i = from; i <= to; i++)
    sum += y(i);

  const int sign = d_counter_clockwise ? 1 : -1;

  const int size = dataSize();
  double *start_angle = new double[size];
  double *end_angle = new double[size];
  double aux_angle = d_start_azimuth;
  for (int i = from; i <= to; i++) {
    double a = -sign * y(i) / sum * 360.0;
    start_angle[i] = aux_angle;

    double end = aux_angle + a;
    if (end >= 360)
      end -= 360;
    else if (end < 0)
      end += 360;

    end_angle[i] = end;
    aux_angle = end;
  }

  int angle = (int)(5760 * d_start_azimuth / 360.0);
  if (d_counter_clockwise)
    angle = (int)(5760 * (1 - d_start_azimuth / 360.0));

  painter->save();

  QLocale locale = (static_cast<Plot *>(plot()))->locale();
  for (int i = from; i <= to; i++) {
    const double yi = y(i);
    const double q = yi / sum;
    const int value = (int)(q * 5760);

    painter->setPen(QwtPlotCurve::pen());
    painter->setBrush(QBrush(color(i), QwtPlotCurve::brush().style()));

    double deg = q * 360;
    double start_3D_view_angle = start_angle[i];
    double end_3D_view_angle = end_angle[i];
    if (d_counter_clockwise) {
      start_3D_view_angle = end_angle[i];
      end_3D_view_angle = start_angle[i];
    }

    bool draw3D = false;
    if (deg <= 180 && start_3D_view_angle >= 0 && start_3D_view_angle < 180) {
      if ((end_3D_view_angle > 180 &&
           end_3D_view_angle > start_3D_view_angle)) {
        deg = 180 - start_3D_view_angle;
        end_3D_view_angle = 180.0;
      }
      draw3D = true;
    } else if (start_3D_view_angle >= 180 &&
               end_3D_view_angle < start_3D_view_angle) {
      if (end_3D_view_angle > 180)
        end_3D_view_angle = 180;
      deg = end_3D_view_angle;
      start_3D_view_angle = 0;
      draw3D = true;
    } else if (deg > 180 && start_3D_view_angle >= 180) {
      deg = 180;
      end_3D_view_angle = 180;
      start_3D_view_angle = 0;
      draw3D = true;
    }

    if (draw3D) {
      double rad = start_3D_view_angle / 180.0 * M_PI;
      QPointF start(x_center + ray_x * cos(rad), y_center + ray_y * sin(rad));
      QPainterPath path(start);
      path.lineTo(start.x(), start.y() + thick);
      path.arcTo(pieRect2, -start_3D_view_angle, -deg);
      QPointF aux = path.currentPosition();
      path.lineTo(aux.x(), aux.y() - thick);
      path.arcTo(pieRect, -end_3D_view_angle, deg);
      painter->drawPath(path);
    } else {
      if (start_3D_view_angle >= 0 && start_3D_view_angle < 180) {
        if (end_3D_view_angle > 180)
          end_3D_view_angle = 0;

        double rad = start_3D_view_angle / 180.0 * M_PI;
        QPointF start(x_center + ray_x * cos(rad), y_center + ray_y * sin(rad));
        QPainterPath path(start);
        path.lineTo(start.x(), start.y() + thick);

        deg = 180 - start_3D_view_angle;
        path.arcTo(pieRect2, -start_3D_view_angle, -deg);
        QPointF aux = path.currentPosition();
        path.lineTo(aux.x(), aux.y() - thick);
        path.arcTo(pieRect, -180, deg);
        painter->drawPath(path);

        path.moveTo(QPointF(x_center + ray_x, y_center));
        aux = path.currentPosition();
        path.lineTo(aux.x(), aux.y() + thick);
        path.arcTo(pieRect2, 0, -end_3D_view_angle);
        aux = path.currentPosition();
        path.lineTo(aux.x(), aux.y() - thick);
        path.arcTo(pieRect, -end_3D_view_angle, end_3D_view_angle);
        painter->drawPath(path);
      }
    }

    painter->drawPie(pieRect, sign * angle, sign * value);
    angle += value;

    if (i >= d_texts_list.size())
      continue;

    PieLabel *l = d_texts_list[i];
    if (l) {
      QString s;
      if (d_auto_labeling) {
        if (d_categories)
          s += QString::number(d_table_rows[i]) + "\n";
        if (d_values && d_percentages)
          s += locale.toString(yi, 'g', 4) + " (" +
               locale.toString(q * 100, 'g', 4) + "%)";
        else if (d_values)
          s += locale.toString(yi, 'g', 4);
        else if (d_percentages)
          s += locale.toString(q * 100, 'g', 4) + "%";
        l->setText(s);
        if (l->isHidden())
          l->show();
      } else
        l->setText(l->customText());

      if (d_fixed_labels_pos) {
        double a_deg = start_angle[i] - sign * q * 180.0;
        if (a_deg > 360)
          a_deg -= 360.0;
        double a_rad = a_deg * M_PI / 180.0;

        double rx = ray_x * (1 + 0.01 * d_edge_dist);
        const double x = x_center + rx * cos(a_rad);

        double ry = ray_y * (1 + 0.01 * d_edge_dist);
        double y = y_center + ry * sin(a_rad);
        if (a_deg > 0 && a_deg < 180)
          y += thick;

        double dx = xMap.invTransform(x - l->width() / 2);
        double dy = yMap.invTransform(y - l->height() / 2);
        l->setOriginCoord(dx, dy);
      }
    }
  }
  painter->restore();
  delete[] start_angle;
  delete[] end_angle;
}
Example #10
0
/*!
  Draw a tube

  Builds 2 curves from the upper and lower limits of the intervals
  and draws them with the pen(). The area between the curves is
  filled with the brush().

  \param painter Painter
  \param xMap Maps x-values into pixel coordinates.
  \param yMap Maps y-values into pixel coordinates.
  \param canvasRect Contents rect of the canvas
  \param from Index of the first sample to be painted
  \param to Index of the last sample to be painted. If to < 0 the
         series will be painted to its last sample.

  \sa drawSeries(), drawSymbols()
*/
void QwtPlotIntervalCurve::drawTube( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    painter->save();

    const size_t size = to - from + 1;
    QPolygonF polygon( 2 * size );
    QPointF *points = polygon.data();

    for ( uint i = 0; i < size; i++ )
    {
        QPointF &minValue = points[i];
        QPointF &maxValue = points[2 * size - 1 - i];

        const QwtIntervalSample intervalSample = sample( from + i );
        if ( orientation() == Qt::Vertical )
        {
            double x = xMap.transform( intervalSample.value );
            double y1 = yMap.transform( intervalSample.interval.minValue() );
            double y2 = yMap.transform( intervalSample.interval.maxValue() );
            if ( doAlign )
            {
                x = qRound( x );
                y1 = qRound( y1 );
                y2 = qRound( y2 );
            }

            minValue.rx() = x;
            minValue.ry() = y1;
            maxValue.rx() = x;
            maxValue.ry() = y2;
        }
        else
        {
            double y = yMap.transform( intervalSample.value );
            double x1 = xMap.transform( intervalSample.interval.minValue() );
            double x2 = xMap.transform( intervalSample.interval.maxValue() );
            if ( doAlign )
            {
                y = qRound( y );
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            minValue.rx() = x1;
            minValue.ry() = y;
            maxValue.rx() = x2;
            maxValue.ry() = y;
        }
    }

    if ( d_data->brush.style() != Qt::NoBrush )
    {
        painter->setPen( QPen( Qt::NoPen ) );
        painter->setBrush( d_data->brush );

        if ( d_data->paintAttributes & ClipPolygons )
        {
            const qreal m = 1.0;
            const QPolygonF p = QwtClipper::clipPolygonF(
               canvasRect.adjusted( -m, -m, m, m ), polygon, true );

            QwtPainter::drawPolygon( painter, p );
        }
        else
        {
            QwtPainter::drawPolygon( painter, polygon );
        }
    }

    if ( d_data->pen.style() != Qt::NoPen )
    {
        painter->setPen( d_data->pen );
        painter->setBrush( Qt::NoBrush );

        if ( d_data->paintAttributes & ClipPolygons )
        {
            qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );
            const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );

            QPolygonF p;

            p.resize( size );
            memcpy( p.data(), points, size * sizeof( QPointF ) );
            p = QwtClipper::clipPolygonF( clipRect, p );
            QwtPainter::drawPolyline( painter, p );

            p.resize( size );
            memcpy( p.data(), points + size, size * sizeof( QPointF ) );
            p = QwtClipper::clipPolygonF( clipRect, p );
            QwtPainter::drawPolyline( painter, p );
        }
        else
        {
            QwtPainter::drawPolyline( painter, points, size );
            QwtPainter::drawPolyline( painter, points + size, size );
        }
    }

    painter->restore();
}
Example #11
0
/*!
  Draw circles

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radialMap Maps radius values into painter coordinates.
  \param values Radial values, indicating the distances from the pole
*/
void QwtPolarGrid::drawCircles(
    QPainter *painter, const QRectF &canvasRect,
    const QPointF &pole, const QwtScaleMap &radialMap,
    const QList<double> &values ) const
{
    for ( int i = 0; i < int( values.size() ); i++ )
    {
        const double val = values[i];

        const GridData &gridData =
            d_data->gridData[QwtPolar::Radius];

        bool skipLine = false;
        if ( testDisplayFlag( SmartScaleDraw ) )
        {
            const AxisData &axis = d_data->axisData[QwtPolar::AxisAzimuth];
            if ( axis.isVisible &&
                axis.scaleDraw->hasComponent( QwtAbstractScaleDraw::Backbone ) )
            {
                if ( isClose( val, gridData.scaleDiv.upperBound() ) )
                    skipLine = true;
            }
        }

        if ( isClose( val, gridData.scaleDiv.lowerBound() ) )
            skipLine = true;

        if ( !skipLine )
        {
            const double radius = radialMap.transform( val );

            QRectF outerRect( 0, 0, 2 * radius, 2 * radius );
            outerRect.moveCenter( pole );

            if ( testDisplayFlag( ClipGridLines ) )
            {
                /*
                    Qt4 is horrible slow, when painting primitives,
                    with coordinates far outside the visible area.
                    We need to clip.
                */

                const QVector<QwtInterval> angles =
                    QwtClipper::clipCircle( canvasRect, pole, radius );
                for ( int i = 0; i < angles.size(); i++ )
                {
                    const QwtInterval intv = angles[i];
                    if ( intv.minValue() == 0 && intv.maxValue() == 2 * M_PI )
                        QwtPainter::drawEllipse( painter, outerRect );
                    else
                    {
                        const double from = intv.minValue() / M_PI * 180;
                        const double to = intv.maxValue() / M_PI * 180;
                        double span = to - from;
                        if ( span < 0.0 )
                            span += 360.0;

                        painter->drawArc( outerRect,
                            qRound( from * 16 ), qRound( span * 16 ) );
                    }
                }
            }
            else
            {
                QwtPainter::drawEllipse( painter, outerRect );
            }
        }
    }
}
Example #12
0
void GridItem::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    const QRectF area = QwtScaleMap::invTransform( xMap, yMap, canvasRect );

    QList<double> xValues;
    if ( m_orientations & Qt::Horizontal )
    {
        xValues = m_xScaleDiv.ticks( QwtScaleDiv::MajorTick );

        if ( m_isXMinEnabled )
        {
            xValues += m_xScaleDiv.ticks( QwtScaleDiv::MediumTick );
            xValues += m_xScaleDiv.ticks( QwtScaleDiv::MinorTick );
        }

        if ( m_gridAttributes & FillCanvas )
        {
            xValues += area.left();
            xValues += area.right();
        }

        qSort( xValues );
    }

    QList<double> yValues;
    if ( m_orientations & Qt::Vertical )
    {
        yValues = m_yScaleDiv.ticks( QwtScaleDiv::MajorTick );

        if ( m_isYMinEnabled )
        {
            yValues += m_yScaleDiv.ticks( QwtScaleDiv::MediumTick );
            yValues += m_yScaleDiv.ticks( QwtScaleDiv::MinorTick );
        }

        if ( m_gridAttributes & FillCanvas )
        {
            yValues += area.top();
            yValues += area.bottom();
        }

        qSort( yValues );
    }

    painter->setPen( Qt::NoPen );

    if ( ( m_orientations & Qt::Horizontal ) &&
        ( m_orientations & Qt::Vertical ) )
    {
        for ( int i = 1; i < xValues.size(); i++ )
        {
            double x1 = xMap.transform( xValues[i - 1] );
            double x2 = xMap.transform( xValues[i] );

            if ( doAlign )
            {
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            for ( int j = 1; j < yValues.size(); j++ )
            {
                const QRectF rect( xValues[i - 1], yValues[j - 1],
                    xValues[i] - xValues[i - 1], yValues[j] - yValues[j - 1] );

                painter->setBrush( brush( i - 1, j - 1, rect ) );

                double y1 = yMap.transform( yValues[j - 1] );
                double y2 = yMap.transform( yValues[j] );

                if ( doAlign )
                {
                    y1 = qRound( y1 );
                    y2 = qRound( y2 );
                }

                QwtPainter::drawRect( painter, x1, y1, x2 - x1, y2 - y1 );
            }
        }
    }
    else if ( m_orientations & Qt::Horizontal )
    {
        for ( int i = 1; i < xValues.size(); i++ )
        {
            const QRectF rect( xValues[i - 1], area.top(),
                xValues[i] - xValues[i - 1], area.bottom() );

            painter->setBrush( brush( i - 1, 0, rect ) );

            double x1 = xMap.transform( xValues[i - 1] );
            double x2 = xMap.transform( xValues[i] );

            if ( doAlign )
            {
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            QwtPainter::drawRect( painter,
                x1, canvasRect.top(), x2 - x1, canvasRect.height() );
        }
    }
    else if ( m_orientations & Qt::Vertical )
    {
        for ( int i = 1; i < yValues.size(); i++ )
        {
            const QRectF rect( area.left(), yValues[i - 1],
                area.width(), yValues[i] - yValues[i - 1] );

            painter->setBrush( brush( 0, i - 1, rect ) );

            double y1 = yMap.transform( yValues[i - 1] );
            double y2 = yMap.transform( yValues[i] );

            if ( doAlign )
            {
                y1 = qRound( y1 );
                y2 = qRound( y2 );
            }

            QwtPainter::drawRect( painter, canvasRect.left(), y1,
                                  canvasRect.width(), y2 - y1 );
        }
    }
}
bool ThresholdItem::eventFilter(QObject *object, QEvent *event)
{
  if (object != plot()->canvas())
    return false;
  QwtScaleMap xMap = plot()->canvasMap(QwtPlot::xBottom);
  switch (event->type())
  {
  case QEvent::MouseButtonPress:
    {
      int currentValue =
          qBound(0,
                 (int) xMap.invTransform(((QMouseEvent*)event)->x()),
                 MAX_COLOR_VALUE);
      draggingValue = -1;
      for (int i = 0;i < _thresholds.size();++i)
        if (_thresholds[i] - currentValue >= -2 &&
            _thresholds[i] - currentValue <= 2)
        {
          draggingValue = _thresholds[i];
          break;
        }
      break;
    }
  case QEvent::MouseButtonDblClick:
    {
      int currentValue =
          qBound(0,
                 (int) xMap.invTransform(((QMouseEvent*)event)->x()),
                 MAX_COLOR_VALUE);
      draggingValue = -1;
      if (((QMouseEvent*)event)->button() == Qt::LeftButton)
      {
        int i = 0;
        for (;i < _thresholds.size();++i)
          if (_thresholds[i] >= currentValue)
          {
            _thresholds.insert(i, currentValue);
            draggingValue = currentValue;
            plot()->replot();
            emit thresholdChanged(_thresholds);
            break;
          }
        if (i == _thresholds.size())
        {
          _thresholds.push_back(currentValue);
          draggingValue = currentValue;
          plot()->replot();
          emit thresholdChanged(_thresholds);
        }
      }
      else if (((QMouseEvent*)event)->button() == Qt::RightButton)
      {
        int i = 0;
        for (;i < _thresholds.size();++i)
          if (_thresholds[i] - currentValue >= -2 &&
              _thresholds[i] - currentValue <= 2)
          {
            _thresholds.remove(i);
            plot()->replot();
            emit thresholdChanged(_thresholds);
            break;
          }
      }
      break;
    }
  case QEvent::MouseMove:
    {
      int currentValue =
          qBound(0,
                 (int) xMap.invTransform(((QMouseEvent*)event)->x()),
                 MAX_COLOR_VALUE);
      int i = 0;
      for (;i < _thresholds.size();++i)
        if (_thresholds[i] == draggingValue)
          break;
      if (i != _thresholds.size())
      {
        _thresholds[i] = currentValue;
        draggingValue = currentValue;
      }
      plot()->replot();
      emit thresholdChanged(_thresholds);
      break;
    }
  case QEvent::MouseButtonRelease:
    {
      draggingValue = -1;
      break;
    }
  default:
    break;
  }
  return false;
}
// draw the ALT/SLOPE curve
void AllPlotSlopeCurve::drawCurve( QPainter *painter, int,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &, int from, int to ) const
{

    const QwtSeriesData<QPointF> *series = data();

    // parameter (will move to data

    // use sensible defaults
    double section_delta = 0.1;
    bool byDistance = true;

    switch (d_data->style) {

    // time-section is defined in minutes, distance-section in km
    case SlopeTime1 : { section_delta = 1.0; byDistance = false; break; }
    case SlopeTime2 : { section_delta = 5.0; byDistance = false; break; }
    case SlopeTime3 : { section_delta = 10.0; byDistance = false; break; }
    case SlopeDist1 : { section_delta = 0.1; byDistance = true; break; }
    case SlopeDist2 : { section_delta = 0.5; byDistance = true; break; }
    case SlopeDist3 : { section_delta = 1; byDistance = true; break; }
    }

    // create single polygons to be painted (in different colors depending on slope)
    QList<QPolygonF*> polygons;
    // store the polygon edge points (original coordinates) for slope/distance & m/time calculation
    QList<QPointF> calcPoints;

    // prepare Y-Axis baseline info for painting the polygon
    double baseline = d_data->baseline;
    if ( yMap.transformation() )
        baseline = yMap.transformation()->bounded( baseline );
    double refY = yMap.transform( baseline );
    double sectionStart = 0.0;
    QPolygonF *polygon;
    QPointF *points = NULL;
    for (int i = from; i <= to; i++ ) {
        const QPointF sample = series->sample( i );
        if (i == from) {
            // first polygon
            polygon = new QPolygonF (4);
            points = polygon->data();
            sectionStart = sample.x();
            double xi = xMap.transform( sample.x() );
            double yi = yMap.transform( sample.y() );
            points[0].rx() = xi;
            points[0].ry() = refY;
            points[1].rx() = xi;
            points[1].ry() = yi;
            // first point for slope/mperh calcuation
            QPointF calcPoint;
            calcPoint.rx() = sample.x();
            calcPoint.ry() = sample.y();
            calcPoints.append(calcPoint);
        };

        // we are in a section - so search for the end and if found close polygon
        if (points && sample.x() >= (sectionStart+section_delta)) {
            // we are at the end - close and create polygon and go to next
            double xi = xMap.transform( sample.x() );
            double yi = yMap.transform( sample.y() );
            points[2].rx() = xi;
            points[2].ry() = yi;
            points[3].rx() = xi;
            points[3].ry() = refY;
            // append to list
            polygons.append(polygon);
            // next point for slope/mperh calcuation
            QPointF calcPoint;
            calcPoint.rx() = sample.x();
            calcPoint.ry() = sample.y();
            calcPoints.append(calcPoint);

            // start the next polygon with the SAME point than the previous one to have a step-free graph
            polygon = new QPolygonF (4);
            points = polygon->data();
            sectionStart = sample.x();
            double xi2 = xMap.transform( sample.x() );
            double yi2 = yMap.transform( sample.y() );
            points[0].rx() = xi2;
            points[0].ry() = refY;
            points[1].rx() = xi2;
            points[1].ry() = yi2;
        }
        // last started polygon is not closed and painted by intent since it would be smaller than then the others
    }

    // paint the polygons & text per polygon
    int i = 0;
    foreach (QPolygonF *p, polygons) {

        double slope=0.0f; // slope of a section (byDistance = true)
        double mperh=0.0f; // meter per hour (climb or descent) (byDistance = false)
        QPointF point1 = calcPoints.at(i);
        QPointF point2 = calcPoints.at(i+1);

        QBrush brush;
        if (byDistance) {
            // if Y-Axis did not change, no calculation
            // distance - X-Axis is in KM, Y-Axis in m ! and at the end *100 to get %value
            if (point2.ry() != point1.ry()) {
                slope = 100 * ((point2.ry() - point1.ry()) / ((point2.rx() - point1.rx())*1000));
            } else {
                slope = 0.0;
            }
            // set the brush
            if (slope >= 0 && slope < 5) brush = d_data->brushes[0];
            if (slope >= 4 && slope < 7) brush = d_data->brushes[1];
            if (slope >= 7 && slope < 10) brush = d_data->brushes[2];
            if (slope >= 10 && slope < 15) brush = d_data->brushes[3];
            if (slope >= 15) brush = d_data->brushes[4];
            if (slope < 0 && slope > -2) brush = d_data->brushes[5];
            if (slope <= -2 && slope > -5) brush = d_data->brushes[6];
            if (slope <= -5 && slope > -9) brush = d_data->brushes[7];
            if (slope <= -9 && slope > -15) brush = d_data->brushes[8];
            if (slope <= -15) brush = d_data->brushes[5];
        } else {
            // if Y-Axis did not change, no calculation
            // distance - X-Axis is in min, Y-Axis in m !
            if (point2.ry() != point1.ry()) {
                mperh = 60 * ((point2.ry() - point1.ry()) / (point2.rx() - point1.rx()));
            } else {
                mperh = 0.0;
            }
            // set the brush
            if (mperh >= 0 && mperh < 100) brush = d_data->brushes[0];
            if (mperh >= 100 && mperh < 200) brush = d_data->brushes[1];
            if (mperh >= 200 && mperh < 300) brush = d_data->brushes[2];
            if (mperh >= 300 && mperh < 500) brush = d_data->brushes[3];
            if (mperh >= 500) brush = d_data->brushes[4];
            if (mperh < 0 && mperh > -100) brush = d_data->brushes[5];
            if (mperh <= -100 && mperh > -200) brush = d_data->brushes[6];
            if (mperh <= -200 && mperh > -300) brush = d_data->brushes[7];
            if (mperh <= -300 && mperh > -500) brush = d_data->brushes[8];
            if (mperh <= -500) brush = d_data->brushes[5];

        };
        painter->setPen(QColor(127,127,127));
        painter->setBrush( brush );
        // paint the polygon
        QwtPainter::drawPolygon( painter, *p );

        // determine Y-Width of polygon / don't show text if too small
        if (p->at(3).x() - p->at(0).x() > 25) {

            // draw the text (find the point, draw the text)
            QPointF pText = p->at(1);
            if (p->at(1).y() >= p->at(2).y()) pText.setY(p->at(2).y()); else pText.setY(p->at(1).y());
            pText.rx() +=5.0;
            pText.ry() -=30.0;
            QString text;
            if (byDistance) {
                text.setNum(slope, 'f', 2);
            } else {
                text.setNum(mperh, 'f', 0);
            }
            painter->setPen(GCColor::invertColor(GColor(CPLOTBACKGROUND)));
            painter->setFont(QFont("Helvetica",8));
            QwtPainter::drawText(painter, pText, text );
        }

        i++;
    }
Example #15
0
MainWin::MainWin() 
{
    int i;

    xMap.setScaleInterval(-0.5, 10.5);
    yMap.setScaleInterval(-1.1, 1.1);

    //
    //  Frame style
    //  
    setFrameStyle(QFrame::Box|QFrame::Raised);
    setLineWidth(2);
    setMidLineWidth(3);

    //
    // Calculate values
    //
    for(i=0; i<Size;i++)
    {   xval[i] = double(i) * 10.0 / double(Size - 1);
        yval[i] = sin(xval[i]) * cos(2.0 * xval[i]);
    }
    
    //
    //  define curve styles
    // 
    QwtSymbol sym;
    i = 0;

    sym.setStyle(QwtSymbol::Cross);
    sym.setPen(QColor(Qt::black));
    sym.setSize(5);
    crv[i].setSymbol(sym);
    crv[i].setPen(QColor(Qt::darkGreen));
    crv[i].setStyle(QwtPlotCurve::Lines);
    crv[i].setCurveAttribute(QwtPlotCurve::Fitted);
    i++;

    sym.setStyle(QwtSymbol::Ellipse);
    sym.setPen(QColor(Qt::blue));
    sym.setBrush(QColor(Qt::yellow));
    sym.setSize(5);
    crv[i].setSymbol(sym);
    crv[i].setPen(QColor(Qt::red));
    crv[i].setStyle(QwtPlotCurve::Sticks);
    i++;

    crv[i].setPen(QColor(Qt::darkBlue));
    crv[i].setStyle(QwtPlotCurve::Lines);
    i++;

#if QT_VERSION >= 0x040000
    crv[i].setPen(QColor(Qt::darkBlue));
    crv[i].setStyle(QwtPlotCurve::Lines);
    crv[i].setRenderHint(QwtPlotItem::RenderAntialiased);
    i++;
#endif


    crv[i].setPen(QColor(Qt::darkCyan));
    crv[i].setStyle(QwtPlotCurve::Steps);
    i++;

    sym.setStyle(QwtSymbol::XCross);
    sym.setPen(QColor(Qt::darkMagenta));
    crv[i].setSymbol(sym);
    crv[i].setStyle(QwtPlotCurve::NoCurve);
    i++;


    //
    // attach data
    //
    for(i=0;i<CurvCnt;i++)
        crv[i].setRawData(xval,yval,Size);
}
Example #16
0
void QwtPieCurve::drawDisk(QPainter *painter, const QwtScaleMap &xMap,
                           const QwtScaleMap &yMap) const {
  const double x_width = fabs(xMap.p1() - xMap.p2());
  const double x_center =
      (xMap.p1() + xMap.p2()) * 0.5 + d_horizontal_offset * 0.01 * x_width;
  const double y_center = (yMap.p1() + yMap.p2()) * 0.5;
  const double ray_x =
      d_pie_ray * 0.005 * qMin(x_width, fabs(yMap.p1() - yMap.p2()));
  const double view_angle_rad = d_view_angle * M_PI / 180.0;
  const double ray_y = ray_x * sin(view_angle_rad);
  const double thick = 0.01 * d_thickness * ray_x * cos(view_angle_rad);

  QRectF pieRect;
  pieRect.setX(x_center - ray_x);
  pieRect.setY(y_center - ray_y);
  pieRect.setWidth(2 * ray_x);
  pieRect.setHeight(2 * ray_y);

  QRectF pieRect2 = pieRect;
  pieRect2.translate(0, thick);

  painter->save();

  painter->setPen(QwtPlotCurve::pen());
  painter->setBrush(QBrush(color(0), QwtPlotCurve::brush().style()));

  QPointF start(x_center + ray_x, y_center);
  QPainterPath path(start);
  path.lineTo(start.x(), start.y() + thick);
  path.arcTo(pieRect2, 0, -180.0);
  QPointF aux = path.currentPosition();
  path.lineTo(aux.x(), aux.y() - thick);
  path.arcTo(pieRect, -180.0, 180.0);
  painter->drawPath(path);

  painter->drawEllipse(pieRect);

  if (d_texts_list.size() > 0) {
    PieLabel *l = d_texts_list[0];
    if (l) {
      QString s;
      if (d_auto_labeling) {
        if (d_categories)
          s += QString::number(d_table_rows[0]) + "\n";

        if (d_values && d_percentages)
          s += (static_cast<Plot *>(plot()))->locale().toString(y(0), 'g', 4) +
               " (100%)";
        else if (d_values)
          s += (static_cast<Plot *>(plot()))->locale().toString(y(0), 'g', 4);
        else if (d_percentages)
          s += "100%";
        l->setText(s);
        if (l->isHidden())
          l->show();
      } else
        l->setText(l->customText());

      if (d_fixed_labels_pos) {
        double a_deg = d_start_azimuth + 180.0;
        if (a_deg > 360)
          a_deg -= 360;
        double a_rad = a_deg * M_PI / 180.0;
        double rx = ray_x * (1 + 0.01 * d_edge_dist);
        const double x = x_center + rx * cos(a_rad);
        double ry = ray_y * (1 + 0.01 * d_edge_dist);
        double y = y_center + ry * sin(a_rad);
        if (a_deg > 0 && a_deg < 180)
          y += thick;

        double dx = xMap.invTransform(x - l->width() / 2);
        double dy = yMap.invTransform(y - l->height() / 2);
        l->setOriginCoord(dx, dy);
      }
    }
  }
  painter->restore();
}
void ArrowMarker::draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const
{
	const int x0 = xMap.transform(d_rect.left());
	const int y0 = yMap.transform(d_rect.top());
	const int x1 = xMap.transform(d_rect.right());
	const int y1 = yMap.transform(d_rect.bottom());

	p->save();
	QPen pen = linePen();
	p->setPen(pen);

	QBrush brush = QBrush(pen.color(), Qt::SolidPattern);
	QwtPainter::drawLine(p,x0,y0,x1,y1);
	p->restore();

	if (d_end_arrow){
		p->save();
		p->translate(x1,y1);
		const double t = theta(x0, y0, x1, y1);
		p->rotate(-t);

		QPolygon endArray(3);
		endArray[0] = QPoint(0,0);

		int d=(int)floor(d_head_length*tan(M_PI*d_head_angle/180.0)+0.5);
		endArray[1] = QPoint(-d_head_length,d);
		endArray[2] = QPoint(-d_head_length,-d);

		p->setPen(QPen(pen.color(), pen.width(), Qt::SolidLine));
		if (d_fill_head)
			p->setBrush(brush);

		QwtPainter::drawPolygon(p,endArray);
		p->restore();
    }

	if (d_start_arrow){
		p->save();
		p->translate(x0,y0);
		const double t = theta(x0, y0, x1, y1);
		p->rotate(-t);

		QPolygon startArray(3);
		startArray[0] = QPoint(0,0);

		int d=(int)floor(d_head_length*tan(M_PI*d_head_angle/180.0)+0.5);
		startArray[1] = QPoint(d_head_length,d);
		startArray[2] = QPoint(d_head_length,-d);

		p->setPen(QPen(pen.color(), pen.width(), Qt::SolidLine));
		if (d_fill_head)
			p->setBrush(brush);
		QwtPainter::drawPolygon(p,startArray);
		p->restore();
    }

	if (d_editable) {
		p->save();
		p->setPen(QPen(Qt::black,1,Qt::SolidLine));
		QRect handler(QPoint(0,0), QSize(10,10));
		handler.moveCenter(startPoint());
		p->fillRect(handler, QBrush(Qt::black));
		handler.moveCenter(endPoint());
		p->fillRect(handler, QBrush(Qt::black));
		p->restore();
	}
}
Example #18
0
static inline bool qwtInsidePole( const QwtScaleMap &map, double radius )
{
    return map.isInverting() ? ( radius > map.s1() ) : ( radius < map.s1() );
}
/*!
  \brief Render a sub-rectangle of an image 

  renderTile() is called by renderImage() to render different parts
  of the image by concurrent threads.

  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param imagePos Top/left position of the image in painter coordinates
  \param tile Sub-rectangle of the tile in painter coordinates
  \param image Image to be rendered

   \sa setRenderThreadCount()
   \note renderTile needs to be reentrant
*/
void QwtPolarSpectrogram::renderTile(
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, const QPoint &imagePos,
    const QRect &tile, QImage *image ) const
{
    const QwtInterval intensityRange = d_data->data->interval( Qt::ZAxis );
    if ( !intensityRange.isValid() )
        return;

    const bool doFastAtan = testPaintAttribute( ApproximatedAtan );

    const int y0 = imagePos.y();
    const int y1 = tile.top();
    const int y2 = tile.bottom();

    const int x0 = imagePos.x();
    const int x1 = tile.left();
    const int x2 = tile.right();

    if ( d_data->colorMap->format() == QwtColorMap::RGB )
    {
        for ( int y = y1; y <= y2; y++ )
        {
            const double dy = pole.y() - y;
            const double dy2 = qwtSqr( dy );

            QRgb *line = reinterpret_cast<QRgb *>( image->scanLine( y - y0 ) );
            line += x1 - x0;

            for ( int x = x1; x <= x2; x++ )
            {
                const double dx = x - pole.x();

                double a =  doFastAtan ? qwtFastAtan2( dy, dx ) : qAtan2( dy, dx );
                if ( a < 0.0 )
                    a += 2 * M_PI;
                if ( a < azimuthMap.p1() )
                    a += 2 * M_PI;

                const double r = qSqrt( qwtSqr( dx ) + dy2 );

                const double azimuth = azimuthMap.invTransform( a );
                const double radius = radialMap.invTransform( r );

                const double value = d_data->data->value( azimuth, radius );
                *line++ = d_data->colorMap->rgb( intensityRange, value );
            }
        }
    }
    else if ( d_data->colorMap->format() == QwtColorMap::Indexed )
    {
        for ( int y = y1; y <= y2; y++ )
        {
            const double dy = pole.y() - y;
            const double dy2 = qwtSqr( dy );

            unsigned char *line = image->scanLine( y - y0 );
            line += x1 - x0;
            for ( int x = x1; x <= x2; x++ )
            {
                const double dx = x - pole.x();

                double a =  doFastAtan ? qwtFastAtan2( dy, dx ) : qAtan2( dy, dx );
                if ( a < 0.0 )
                    a += 2 * M_PI;
                if ( a < azimuthMap.p1() )
                    a += 2 * M_PI;

                const double r = qSqrt( qwtSqr( dx ) + dy2 );

                const double azimuth = azimuthMap.invTransform( a );
                const double radius = radialMap.invTransform( r );

                const double value = d_data->data->value( azimuth, radius );
                *line++ = d_data->colorMap->colorIndex( intensityRange, value );
            }
        }
    }
}
Example #20
0
/*!
  Draw lines

  \param painter Painter
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa draw(), drawLines(), setCurveFitter()
*/
void QwtPolarCurve::drawLines( QPainter *painter,
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, int from, int to ) const
{
    int size = to - from + 1;
    if ( size <= 0 )
        return;

    QPolygonF polyline;
    if ( d_data->curveFitter )
    {
        QPolygonF points( size );
        for ( int j = from; j <= to; j++ )
        {
            const QwtPointPolar point = sample( j );
            points[j - from] = QPointF( point.azimuth(), point.radius() );
        }

        points = d_data->curveFitter->fitCurve( points );

        polyline.resize( points.size() );

        QPointF *polylineData = polyline.data();
        QPointF *pointsData = points.data();

        for ( int i = 0; i < points.size(); i++ )
        {
            const QwtPointPolar point( pointsData[i].x(), pointsData[i].y() );

            double r = radialMap.transform( point.radius() );
            const double a = azimuthMap.transform( point.azimuth() );

            polylineData[i] = qwtPolar2Pos( pole, r, a );
        }
    }
    else
    {
        polyline.resize( size );
        QPointF *polylineData = polyline.data();

        for ( int i = from; i <= to; i++ )
        {
            QwtPointPolar point = sample( i );
            if ( !qwtInsidePole( radialMap, point.radius() ) )
            {
                double r = radialMap.transform( point.radius() );
                const double a = azimuthMap.transform( point.azimuth() );
                polylineData[i - from] = qwtPolar2Pos( pole, r, a );
            }
            else
            {
                polylineData[i - from] = pole;
            }
        }
    }

    QRectF clipRect;
    if ( painter->hasClipping() )
        clipRect = painter->clipRegion().boundingRect();
    else
    {
        clipRect = painter->window();
        if ( !clipRect.isEmpty() )
            clipRect = painter->transform().inverted().mapRect( clipRect );
    }

    if ( !clipRect.isEmpty() )
    {
        double off = qCeil( qMax( qreal( 1.0 ), painter->pen().widthF() ) );
        clipRect = clipRect.toRect().adjusted( -off, -off, off, off );
        polyline = QwtClipper::clipPolygonF( clipRect, polyline );
    }

    QwtPainter::drawPolyline( painter, polyline );
    painter->drawPolyline( polyline );
}
void ScaleDraw::drawInwardTick(QPainter *painter, double value, int len) const
{
	ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
	if (sc_engine->hasBreak() && (sc_engine->axisBreakLeft() <= value && sc_engine->axisBreakRight() >= value))
		return;

	int pw2 = qwtMin((int)painter->pen().width(), len) / 2;

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

	int majLen = tickLength(QwtScaleDiv::MajorTick);

	if ( !metricsMap.isIdentity() ){
		/*
		   The perfect position of the ticks is important.
		   To avoid rounding errors we have to use
		   device coordinates.
		 */
		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);
			majLen = metricsMap.layoutToDeviceX(majLen);
		} else {
			scaleMap.setPaintInterval(
				metricsMap.layoutToDeviceX((int)scaleMap.p1()),
				metricsMap.layoutToDeviceX((int)scaleMap.p2())
			);
			len = metricsMap.layoutToDeviceY(len);
			majLen = metricsMap.layoutToDeviceY(majLen);
		}
	}

	const int clw = d_plot->canvasLineWidth();
	const int tval = scaleMap.transform(value);

	bool draw = false;
	if ( orientation() == Qt::Vertical ){
		int low = (int)scaleMap.p2() + majLen;
		int high = (int)scaleMap.p1() - majLen;
		if ((tval > low && tval < high) ||
			(tval > high && !d_plot->axisEnabled (QwtPlot::xBottom) && !clw) ||
			(tval < low && !d_plot->axisEnabled(QwtPlot::xTop) && !clw)) draw = true;
	} else {
		int low = (int)scaleMap.p1() + majLen;
		int high = (int)scaleMap.p2() - majLen;
		if ((tval > low && tval < high) ||
			(tval > high && !d_plot->axisEnabled(QwtPlot::yRight) && !clw) ||
			(tval < low && !d_plot->axisEnabled(QwtPlot::yLeft) && !clw)) draw = true;
	}

	if (draw){
		switch(alignment()){
			case LeftScale:
			{
				QwtPainter::drawLine(painter, pos.x() + pw2, tval, pos.x() + len, tval);
				break;
			}
			case RightScale:
			{
				QwtPainter::drawLine(painter, pos.x() - pw2, tval, pos.x() - len, tval);
				break;
			}
			case BottomScale:
			{
				QwtPainter::drawLine(painter, tval, pos.y() - pw2, tval, pos.y() - len);
				break;
			}
			case TopScale:
			{
				QwtPainter::drawLine(painter, tval, pos.y() + pw2, tval, pos.y() + len);
				break;
			}
		}
	}
	QwtPainter::setMetricsMap(metricsMap); // restore metrics map
}
Example #22
0
void VectorCurve::drawVector(QPainter *painter, const QwtScaleMap &xMap,
                             const QwtScaleMap &yMap, int from, int to) const {
  if (d_style == XYAM) {
    for (int i = from; i <= to; i++) {
      const double x0 = x(i);
      const double y0 = y(i);
      const double angle = vectorEnd->x(i);
      const double mag = vectorEnd->y(i);

      int xs = 0, ys = 0, xe = 0, ye = 0;
      switch (d_position) {
      case Tail:
        xs = xMap.transform(x0);
        ys = yMap.transform(y0);
        xe = xMap.transform(x0 + mag * cos(angle));
        ye = yMap.transform(y0 + mag * sin(angle));
        break;

      case Middle: {
        double dxh = 0.5 * mag * cos(angle);
        double dyh = 0.5 * mag * sin(angle);
        xs = xMap.transform(x0 - dxh);
        ys = yMap.transform(y0 - dyh);
        xe = xMap.transform(x0 + dxh);
        ye = yMap.transform(y0 + dyh);
      } break;

      case Head:
        xs = xMap.transform(x0 - mag * cos(angle));
        ys = yMap.transform(y0 - mag * sin(angle));
        xe = xMap.transform(x0);
        ye = yMap.transform(y0);
        break;
      }
      QwtPainter::drawLine(painter, xs, ys, xe, ye);
      drawArrowHead(painter, xs, ys, xe, ye);
    }
  } else {
    for (int i = from; i <= to; i++) {
      const int xs = xMap.transform(x(i));
      const int ys = yMap.transform(y(i));
      const int xe = xMap.transform(vectorEnd->x(i));
      const int ye = yMap.transform(vectorEnd->y(i));
      QwtPainter::drawLine(painter, xs, ys, xe, ye);
      drawArrowHead(painter, xs, ys, xe, ye);
    }
  }
}
void QwtBarCurve::draw(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
{
   if ( !painter || dataSize() <= 0 )
        return;

    if (to < 0)
        to = dataSize() - 1;

    painter->save();
    painter->setPen(QwtPlotCurve::pen());
    painter->setBrush(QwtPlotCurve::brush());

    int dx, dy, ref;
	double bar_width = 0;

    if (bar_style == Vertical)
       ref= yMap.transform(1e-100); //smalest positive value for log scales
    else
       ref= xMap.transform(1e-100);

	if (bar_style == Vertical)
	{
		dx = abs(xMap.transform(x(from+1))-xMap.transform(x(from)));
		for (int i=from+2; i<to; i++)
		{
			int min = abs(xMap.transform(x(i+1))-xMap.transform(x(i)));
			if (min <= dx)
				dx=min;
		}
		bar_width = dx*(1-bar_gap*0.01);
	}
	else
	{
		dy = abs(yMap.transform(y(from+1))-yMap.transform(y(from)));
		for (int i=from+2; i<to; i++)
		{
			int min = abs(yMap.transform(y(i+1))-yMap.transform(y(i)));
			if (min <= dy)
				dy=min;
		}
		bar_width = dy*(1-bar_gap*0.01);
	}

	const int half_width = int((0.5-bar_offset*0.01)*bar_width);
	int bw1 = int(bar_width) + 1;
	for (int i=from; i<=to; i++)
	{
		const int px = xMap.transform(x(i));
        const int py = yMap.transform(y(i));

		if (bar_style == Vertical)
		{
			if (y(i) < 0)
				painter->drawRect(px-half_width, ref, bw1, (py-ref));
			else
				painter->drawRect(px-half_width, py, bw1, (ref-py+1));
		}
		else
		{
			if (x(i) < 0)
				painter->drawRect(px, py-half_width, (ref-px), bw1);
			else
				painter->drawRect(ref, py-half_width, (px-ref), bw1);
		}
	}
	painter->restore();
}
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rect of the canvas
  \param from Index of the first point to be painted
  \param to Index of the last point to be painted

  \sa setSymbol(), drawSeries(), drawCurve()
*/
void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    bool usePixmap = testPaintAttribute( CacheSymbols );
    if ( usePixmap && !doAlign )
    {
        // Don't use the pixmap, when the paint device
        // could generate scalable vectors

        usePixmap = false;
    }

    if ( usePixmap )
    {
        QPixmap pm( symbol.boundingSize() );
        pm.fill( Qt::transparent );

        const double pw2 = 0.5 * pm.width();
        const double ph2 = 0.5 * pm.height();

        QPainter p( &pm );
        p.setRenderHints( painter->renderHints() );
        symbol.drawSymbol( &p, QPointF( pw2, ph2 ) );
        p.end();

        for ( int i = from; i <= to; i++ )
        {
            const QPointF sample = d_series->sample( i );

            double xi = xMap.transform( sample.x() );
            double yi = yMap.transform( sample.y() );
            if ( doAlign )
            {
                xi = qRound( xi );
                yi = qRound( yi );
            }

            if ( canvasRect.contains( xi, yi ) )
            {
                const int left = qCeil( xi ) - pw2;
                const int top = qCeil( yi ) - ph2;

                painter->drawPixmap( left, top, pm );
            }
        }
    }
    else
    {
        const int chunkSize = 500;

        for ( int i = from; i <= to; i += chunkSize )
        {
            const int n = qMin( chunkSize, to - i + 1 );

            QPolygonF points;
            for ( int j = 0; j < n; j++ )
            {
                const QPointF sample = d_series->sample( i + j );

                const double xi = xMap.transform( sample.x() );
                const double yi = yMap.transform( sample.y() );

                if ( canvasRect.contains( xi, yi ) )
                    points += QPointF( xi, yi );
            }

            if ( points.size() > 0 )
                symbol.drawSymbols( painter, points );
        }
    }
}
/*!
  \brief Draw the marker
  \param p Painter
  \param xMap x Scale Map
  \param yMap y Scale Map
  \param r Bounding rect, where to paint
*/
void QwtPlotMarker::draw(QPainter *p,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRect &r) const
{
    const int x = xMap.transform(d_data->xValue);
    const int y = yMap.transform(d_data->yValue);

    // draw lines
    if (d_data->style != NoLine)
    {
        p->setPen(d_data->pen);
        if ((d_data->style == HLine) || (d_data->style == Cross))
            QwtPainter::drawLine(p, r.left(), y, r.right(), y);
        if ((d_data->style == VLine)||(d_data->style == Cross))
            QwtPainter::drawLine(p, x, r.top(), x, r.bottom());
    }

    // draw symbol
    QSize sSym(0, 0);
    if (d_data->sym.style() != QwtSymbol::None)
    {
        sSym = d_data->sym.size();
        d_data->sym.draw(p, x, y);
    }

    // draw label
    if (!d_data->label.isEmpty())
    {
        int xlw = qwtMax(int(d_data->pen.width()), 1);
        int ylw = xlw;
        int xlw1;
        int ylw1;

        const int xLabelDist = 
            QwtPainter::metricsMap().screenToLayoutX(LabelDist);
        const int yLabelDist = 
            QwtPainter::metricsMap().screenToLayoutY(LabelDist);

        if ((d_data->style == VLine) || (d_data->style == HLine))
        {
            xlw1 = (xlw + 1) / 2 + xLabelDist;
            xlw = xlw / 2 + xLabelDist;
            ylw1 = (ylw + 1) / 2 + yLabelDist;
            ylw = ylw / 2 + yLabelDist;
        }
        else 
        {
            xlw1 = qwtMax((xlw + 1) / 2, (sSym.width() + 1) / 2) + xLabelDist;
            xlw = qwtMax(xlw / 2, (sSym.width() + 1) / 2) + xLabelDist;
            ylw1 = qwtMax((ylw + 1) / 2, (sSym.height() + 1) / 2) + yLabelDist;
            ylw = qwtMax(ylw / 2, (sSym. height() + 1) / 2) + yLabelDist;
        }

        QRect tr(QPoint(0, 0), d_data->label.textSize(p->font()));
        tr.moveCenter(QPoint(0, 0));

        int dx = x;
        int dy = y;

        if (d_data->style == VLine)
        {
            if (d_data->align & (int) Qt::AlignTop)
                dy = r.top() + yLabelDist - tr.y();
            else if (d_data->align & (int) Qt::AlignBottom)
                dy = r.bottom() - yLabelDist + tr.y();
            else
                dy = r.top() + r.height() / 2;
        }
        else
        {
            if (d_data->align & (int) Qt::AlignTop)
                dy += tr.y() - ylw1;
            else if (d_data->align & (int) Qt::AlignBottom)
                dy -= tr.y() - ylw1;
        }


        if (d_data->style == HLine)
        {
            if (d_data->align & (int) Qt::AlignLeft)
                dx = r.left() + xLabelDist - tr.x();
            else if (d_data->align & (int) Qt::AlignRight)
                dx = r.right() - xLabelDist + tr.x();
            else
                dx = r.left() + r.width() / 2;
        }
        else
        {
            if (d_data->align & (int) Qt::AlignLeft)
                dx += tr.x() - xlw1;
            else if (d_data->align & (int) Qt::AlignRight)
                dx -= tr.x() - xlw1;
        }

#if QT_VERSION < 0x040000
        tr.moveBy(dx, dy);
#else
        tr.translate(dx, dy);
#endif
        d_data->label.draw(p, tr);
    }
}
/*!
  \brief Draw the scale
*/
void QwtPlotScaleItem::draw(QPainter *painter, 
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRect &canvasRect) const
{
    if ( canvasRect != d_data->canvasRectCache )
    {
        QwtPlotScaleItem* that = (QwtPlotScaleItem*)this;
        that->updateBorders();
    }

    QPen pen = painter->pen();
    pen.setStyle(Qt::SolidLine);
    painter->setPen(pen);

    int pw = painter->pen().width();
    if ( pw == 0 )
        pw = 1;

    QwtScaleDraw *sd = d_data->scaleDraw;
    if ( sd->orientation() == Qt::Horizontal )
    {
        int y;
        if ( d_data->borderDistance >= 0 )
        {
            if ( sd->alignment() == QwtScaleDraw::BottomScale )
                y = canvasRect.top() + d_data->borderDistance;
            else
            {
                y = canvasRect.bottom() - d_data->borderDistance - pw + 1;
            }

        }
        else
        {
            y = yMap.transform(d_data->position);
        }

        if ( y < canvasRect.top() || y > canvasRect.bottom() )
            return;

        sd->move(canvasRect.left(), y);
        sd->setLength(canvasRect.width() - 1);
        sd->setTransformation(xMap.transformation()->copy());
    }
    else // == Qt::Vertical
    {
        int x;
        if ( d_data->borderDistance >= 0 )
        {
            if ( sd->alignment() == QwtScaleDraw::RightScale )
                x = canvasRect.left() + d_data->borderDistance;
            else
            {
                x = canvasRect.right() - d_data->borderDistance - pw + 1;
            }
        }
        else
        {
            x = xMap.transform(d_data->position);
        }
        if ( x < canvasRect.left() || x > canvasRect.right() )
            return;

        sd->move(x, canvasRect.top());
        sd->setLength(canvasRect.height() - 1);
        sd->setTransformation(yMap.transformation()->copy());
    }

    painter->setFont(d_data->font);

#if QT_VERSION < 0x040000
    sd->draw(painter, d_data->colorGroup);
#else
    sd->draw(painter, d_data->palette);
#endif
    
}
Example #27
0
/*!
  Draw step function

  The direction of the steps depends on Inverted attribute.

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rectangle of the canvas
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa CurveAttribute, setCurveAttribute(),
      draw(), drawCurve(), drawDots(), drawLines(), drawSticks()
*/
void QwtPlotCurve::drawSteps( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    QPolygonF polygon( 2 * ( to - from ) + 1 );
    QPointF *points = polygon.data();

    bool inverted = orientation() == Qt::Vertical;
    if ( d_data->attributes & Inverted )
        inverted = !inverted;

    const QwtSeriesData<QPointF> *series = data();

    int i, ip;
    for ( i = from, ip = 0; i <= to; i++, ip += 2 )
    {
        const QPointF sample = series->sample( i );
        double xi = xMap.transform( sample.x() );
        double yi = yMap.transform( sample.y() );
        if ( doAlign )
        {
            xi = qRound( xi );
            yi = qRound( yi );
        }

        if ( ip > 0 )
        {
            const QPointF &p0 = points[ip - 2];
            QPointF &p = points[ip - 1];

            if ( inverted )
            {
                p.rx() = p0.x();
                p.ry() = yi;
            }
            else
            {
                p.rx() = xi;
                p.ry() = p0.y();
            }
        }

        points[ip].rx() = xi;
        points[ip].ry() = yi;
    }

    if ( d_data->paintAttributes & ClipPolygons )
    {
        qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
        const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw);
        
        const QPolygonF clipped = QwtClipper::clipPolygonF( 
            clipRect, polygon, false );

        QwtPainter::drawPolyline( painter, clipped );
    }
    else
    {
        QwtPainter::drawPolyline( painter, polygon );
    }

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve( painter, xMap, yMap, canvasRect, polygon );
}
Example #28
0
//
//  REDRAW CONTENTS
//
void MainWin::drawContents(QPainter *painter)
{
    int deltay,i;

    QRect r = contentsRect();

    deltay = r.height() / CurvCnt - 1;

    r.setHeight(deltay);

    //
    //  draw curves
    //
    for (i=0;i<CurvCnt;i++)
    {
        xMap.setPaintInterval(r.left(), r.right());
        yMap.setPaintInterval(r.top(), r.bottom());

#if QT_VERSION >= 0x040000
        painter->setRenderHint(QPainter::Antialiasing,
            crv[i].testRenderHint(QwtPlotItem::RenderAntialiased) );
#endif
        crv[i].draw(painter, xMap, yMap, r);

        shiftDown(r, deltay);
    }

    //
    // draw titles
    //
    r = contentsRect();     // reset r
    painter->setFont(QFont("Helvetica", 8));
    
    const int alignment = Qt::AlignTop|Qt::AlignHCenter;

    painter->setPen(Qt::black);

    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Line/Fitted, Symbol: Cross");
    shiftDown(r, deltay);

    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Sticks, Symbol: Ellipse");
    shiftDown(r, deltay);
    
    painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Lines, Symbol: None");
    shiftDown(r, deltay);

#if QT_VERSION >= 0x040000
    painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Lines, Symbol: None, Antialiased");
    shiftDown(r, deltay);
#endif
    
    
    painter->drawText(0, r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Steps, Symbol: None");
    shiftDown(r, deltay);
    
    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: NoCurve, Symbol: XCross");
}
Example #29
0
/*!
  Draw circles

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radialMap Maps radius values into painter coordinates.
  \param values Radial values, indicating the distances from the pole
*/
void QwtPolarGrid::drawCircles(
  QPainter *painter, const QwtDoubleRect &canvasRect,
  const QwtDoublePoint &pole, const QwtScaleMap &radialMap,
  const QwtValueList &values ) const
{
  for ( int i = 0; i < int( values.size() ); i++ )
  {
    const double val = values[i];

    const GridData &gridData =
      d_data->gridData[QwtPolar::Radius];

    bool skipLine = false;
    if ( testDisplayFlag( SmartScaleDraw ) )
    {
      const AxisData &axis = d_data->axisData[QwtPolar::AxisAzimuth];
      if ( axis.isVisible &&
           axis.scaleDraw->hasComponent( QwtAbstractScaleDraw::Backbone ) )
      {
#if QWT_VERSION < 0x050200
        if ( isClose( val, gridData.scaleDiv.hBound() ) )
#else
        if ( isClose( val, gridData.scaleDiv.upperBound() ) )
#endif
          skipLine = true;
      }
    }

#if QWT_VERSION < 0x050200
    if ( isClose( val, gridData.scaleDiv.lBound() ) )
#else
    if ( isClose( val, gridData.scaleDiv.lowerBound() ) )
#endif
      skipLine = true;

    if ( !skipLine )
    {
      const double radius = radialMap.transform( val );

      QwtDoubleRect outerRect( 0, 0, 2 * radius, 2 * radius );
      outerRect.moveCenter( pole );

#if QT_VERSION < 0x040000
      QwtPainter::drawEllipse( painter, outerRect.toRect() );
#else
      if ( testDisplayFlag( ClipGridLines ) )
      {

        /*
            Qt4 is horrible slow, when painting primitives,
            with coordinates far outside the visible area.
            We need to clip.
        */

        const QwtArray<QwtDoubleInterval> angles =
          QwtClipper::clipCircle( canvasRect, pole, radius );
        for ( int i = 0; i < angles.size(); i++ )
        {
          const QwtDoubleInterval intv = angles[i];
          if ( intv.minValue() == 0 && intv.maxValue() == 2 * M_PI )
            QwtPainter::drawEllipse( painter, outerRect.toRect() );
          else
          {
            const double from = intv.minValue() / M_PI * 180;
            const double to = intv.maxValue() / M_PI * 180;
            double span = to - from;
            if ( span < 0.0 )
              span += 360.0;

            const QwtMetricsMap &mm = QwtPainter::metricsMap();
            const QRect r = outerRect.toRect();

            painter->drawArc( mm.layoutToDevice( r, painter ),
                              qRound( from * 16 ), qRound( span * 16 ) );
          }

        }
      }
      else
      {
        QwtPainter::drawEllipse( painter, outerRect.toRect() );
      }
#endif
    }
  }
}
Example #30
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;
  }
  //}
}