void QwtErrorPlotCurve::drawErrorBars(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const { int sh = 0, sw =0; const QwtSymbol symbol = d_master_curve->symbol(); if (symbol.style() != QwtSymbol::NoSymbol){ sh = symbol.size().height(); sw = symbol.size().width(); } double d_xOffset = 0.0; double d_yOffset = 0.0; if (d_master_curve->type() == Graph::VerticalBars) d_xOffset = ((QwtBarCurve *)d_master_curve)->dataOffset(); else if (d_master_curve->type() == Graph::HorizontalBars) d_yOffset = ((QwtBarCurve *)d_master_curve)->dataOffset(); ScaleEngine *yScaleEngine = (ScaleEngine *)plot()->axisScaleEngine(yAxis()); bool logYScale = (yScaleEngine->type() == QwtScaleTransformation::Log10) ? true : false; for (int i = from; i <= to; i++){ const int xi = xMap.transform(x(i) + d_xOffset); const int yi = yMap.transform(y(i) + d_yOffset); if (type == Vertical){ const int yh = yMap.transform(y(i) + err[i]); const int yl = yMap.transform(y(i) - err[i]); const int yhl = yi - sh/2; const int ylh = yi + sh/2; if (plus){ QwtPainter::drawLine(painter, xi, yhl, xi, yh); QwtPainter::drawLine(painter, xi - cap/2, yh, xi + cap/2, yh); } if (minus && (!logYScale || (logYScale && yl > 0))){ QwtPainter::drawLine(painter, xi, ylh, xi, yl); QwtPainter::drawLine(painter, xi - cap/2, yl, xi + cap/2, yl); } if (through) QwtPainter::drawLine(painter, xi, yhl, xi, ylh); } else if (type == Horizontal) { const int xp = xMap.transform(x(i) + err[i]); const int xm = xMap.transform(x(i) - err[i]); const int xpm = xi + sw/2; const int xmp = xi - sw/2; if (plus){ QwtPainter::drawLine(painter, xp, yi, xpm, yi); QwtPainter::drawLine(painter, xp, yi - cap/2, xp, yi + cap/2); } if (minus){ QwtPainter::drawLine(painter, xm, yi, xmp, yi); QwtPainter::drawLine(painter, xm, yi - cap/2, xm, yi + cap/2); } if (through) QwtPainter::drawLine(painter, xmp, yi, xpm, yi); } } }
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(); //} }
/*! Transform a point from scale to paint coordinates \param xMap X map \param yMap Y map \param pos Position in scale coordinates \return Position in paint coordinates \sa invTransform() */ QPointF QwtScaleMap::transform( const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QPointF &pos ) { return QPointF( xMap.transform( pos.x() ), yMap.transform( pos.y() ) ); }
void ImageMarker::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const { const int x0 = xMap.transform(xValue()); const int y0 = yMap.transform(yValue()); const int x1 = xMap.transform(d_x_right); const int y1 = yMap.transform(d_y_bottom); p->drawPixmap(QRect(x0, y0, abs(x1 - x0), abs(y1 - y0)), d_pic); }
void PeakPickerTool::draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const { try { MantidQt::MantidWidgets::PropertyHandler *h = m_fitPropertyBrowser->getHandler(); if (!h) return; QList<MantidQt::MantidWidgets::PropertyHandler *> peaks = h->getPeakList(); foreach (MantidQt::MantidWidgets::PropertyHandler *peak, peaks) { double c = peak->centre(); if (c >= xMap.s1() && c <= xMap.s2()) { int ic = xMap.transform(c); if (peak == m_fitPropertyBrowser->currentHandler()) { // draw current peak double width = peak->fwhm(); QPen pen; pen.setColor(QColor(255, 0, 0)); pen.setStyle(Qt::DashLine); p->setPen(pen); int x1 = xMap.transform(c - width / 2); int x2 = xMap.transform(c + width / 2); QwtPainter::drawLine(p, x1, int(yMap.p1()), x1, int(yMap.p2())); QwtPainter::drawLine(p, x2, int(yMap.p1()), x2, int(yMap.p2())); pen.setStyle(Qt::SolidLine); p->setPen(pen); int ih = yMap.transform(peak->height() + peak->base()); int ib = yMap.transform(peak->base()); QwtPainter::drawLine(p, ic, ib, ic, ih); QwtPainter::drawLine(p, x1, ib, x2, ib); } else { p->setPen(QPen(QColor(200, 200, 200))); QwtPainter::drawLine(p, ic, int(yMap.p1()), ic, int(yMap.p2())); } } } } catch (...) { // Do nothing } QPen pen; pen.setColor(QColor(0, 0, 255)); pen.setStyle(Qt::DashLine); p->setPen(pen); int x1 = xMap.transform(xMin()); int x2 = xMap.transform(xMax()); QwtPainter::drawLine(p, x1, int(yMap.p1()), x1, int(yMap.p2())); QwtPainter::drawLine(p, x2, int(yMap.p1()), x2, int(yMap.p2())); pen.setColor(QColor(0, 0, 255)); pen.setStyle(Qt::SolidLine); p->setPen(pen); QwtPainter::drawLine(p, x1, int(yMap.p1()), x1 + 3, int(yMap.p1())); QwtPainter::drawLine(p, x1, int(yMap.p2()), x1 + 3, int(yMap.p2())); QwtPainter::drawLine(p, x2, int(yMap.p1()), x2 - 3, int(yMap.p1())); QwtPainter::drawLine(p, x2, int(yMap.p2()), x2 - 3, int(yMap.p2())); }
void ImageMarker::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) 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->drawPixmap(QRect(QPoint(x0, y0), QPoint(x1, y1)), d_pic); }
void Plot::drawItems (QPainter *painter, const QRect &rect, const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const { painter->save(); painter->setRenderHint(QPainter::Antialiasing); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; drawBreak(painter, rect, map[i], i); } painter->restore(); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; const ScaleEngine *sc_engine = (const ScaleEngine *)axisScaleEngine(i); /*const QwtScaleEngine *qwtsc_engine=axisScaleEngine(i); const ScaleEngine *sc_engine =dynamic_cast<const ScaleEngine*>(qwtsc_engine); if(sc_engine!=NULL) { */ if (!sc_engine->hasBreak()) continue; QwtScaleMap m = map[i]; int lb = m.transform(sc_engine->axisBreakLeft()); int rb = m.transform(sc_engine->axisBreakRight()); int start = lb, end = rb; if (sc_engine->testAttribute(QwtScaleEngine::Inverted)){ end = lb; start = rb; } QRegion cr(rect); if (i == QwtPlot::xBottom || i == QwtPlot::xTop) painter->setClipRegion(cr.subtracted(QRegion(start, rect.y(), abs(end - start), rect.height())), Qt::IntersectClip); else if (i == QwtPlot::yLeft || i == QwtPlot::yRight) painter->setClipRegion(cr.subtracted(QRegion(rect.x(), end, rect.width(), abs(end - start))), Qt::IntersectClip); //} } QwtPlot::drawItems(painter, rect, map, pfilter); for (int i=0; i<QwtPlot::axisCnt; i++){ if (!axisEnabled(i)) continue; const ScaleDraw *sd = (const ScaleDraw *) axisScaleDraw (i); int majorTicksType = sd->majorTicksStyle(); int minorTicksType = sd->minorTicksStyle(); bool min = (minorTicksType == ScaleDraw::In || minorTicksType == ScaleDraw::Both); bool maj = (majorTicksType == ScaleDraw::In || majorTicksType == ScaleDraw::Both); if (min || maj) drawInwardTicks(painter, rect, map[i], i, min, maj); } }
static inline Polygon qwtToPoints( const QRectF &boundingRect, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtSeriesData<QPointF> *series, int from, int to, Round round ) { Polygon polyline( to - from + 1 ); Point *points = polyline.data(); int numPoints = 0; if ( boundingRect.isValid() ) { // iterating over all values // filtering out all points outside of // the bounding rectangle for ( int i = from; i <= to; i++ ) { const QPointF sample = series->sample( i ); const double x = xMap.transform( sample.x() ); const double y = yMap.transform( sample.y() ); if ( boundingRect.contains( x, y ) ) { points[ numPoints ].rx() = round( x ); points[ numPoints ].ry() = round( y ); numPoints++; } } polyline.resize( numPoints ); } else { // simply iterating over all values // without any filtering for ( int i = from; i <= to; i++ ) { const QPointF sample = series->sample( i ); const double x = xMap.transform( sample.x() ); const double y = yMap.transform( sample.y() ); points[ numPoints ].rx() = round( x ); points[ numPoints ].ry() = round( y ); numPoints++; } } return polyline; }
void LineMarker::draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) 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(); p->setPen(pen); QBrush brush=QBrush(pen.color(), QBrush::SolidPattern); QwtPainter::drawLine(p,x0,y0,x1,y1); p->restore(); if (endArrow) { p->save(); p->translate(x1,y1); const double t = teta(x0, y0, x1, y1); p->rotate(-t); const QPointArray endArray(3); endArray[0] = QPoint(0,0); int d=(int)floor(d_headLength*tan(M_PI*d_headAngle/180.0)+0.5); endArray[1] = QPoint(-d_headLength,d); endArray[2] = QPoint(-d_headLength,-d); p->setPen(QPen(pen.color(),pen.width(),Qt::SolidLine)); if (filledArrow) p->setBrush(brush); QwtPainter::drawPolygon(p,endArray); p->restore(); } if (startArrow) { p->save(); p->translate(x0,y0); const double t = teta(x0, y0, x1, y1); p->rotate(-t); const QPointArray startArray(3); startArray[0] = QPoint(0,0); int d=(int)floor(d_headLength*tan(M_PI*d_headAngle/180.0)+0.5); startArray[1] = QPoint(d_headLength,d); startArray[2] = QPoint(d_headLength,-d); p->setPen(QPen(pen.color(), pen.width(), Qt::SolidLine)); if (filledArrow) p->setBrush(brush); QwtPainter::drawPolygon(p,startArray); p->restore(); } }
void ScaleDraw::drawTick(QPainter *p, double value, int len) const { int axis = this->axis(); ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis); if (sc_engine->hasBreak()){ double dlb = sc_engine->axisBreakLeft(); double drb = sc_engine->axisBreakRight(); if ((dlb < value && drb > value) || ((axis == QwtPlot::yLeft || axis == QwtPlot::xBottom) && value == dlb) || ((axis == QwtPlot::yRight || axis == QwtPlot::xTop) && value == drb) || (sc_engine->testAttribute(QwtScaleEngine::Inverted) && (value == dlb || value == drb))) return; if (d_plot->isPrinting()){ QwtScaleMap scaleMap = map(); double val = scaleMap.transform(value); if (val >= scaleMap.transform(dlb) && val <= scaleMap.transform(drb)) return; } } QwtScaleDiv scDiv = scaleDiv(); QwtValueList majTicks = scDiv.ticks(QwtScaleDiv::MajorTick); if (majTicks.contains(value)){ if (d_majTicks == In || d_majTicks == None) return; switch (d_show_ticks_policy){ case ShowAll: break; case HideBegin: if (majTicks.first() == value) return; break; case HideEnd: if (majTicks.last() == value) return; break; case HideBeginEnd: if (majTicks.first() == value || majTicks.last() == value) return; break; } } QwtValueList medTicks = scDiv.ticks(QwtScaleDiv::MediumTick); if (medTicks.contains(value) && (d_minTicks == In || d_minTicks == None)) return; QwtValueList minTicks = scDiv.ticks(QwtScaleDiv::MinorTick); if (minTicks.contains(value) && (d_minTicks == In || d_minTicks == None)) return; QwtScaleDraw::drawTick(p, value, len); }
/*! Translate a point from plot into pixel coordinates \return Point in pixel coordinates \sa invTransform() */ QPoint QwtPlotPicker::transform( const QPointF &pos ) const { QwtScaleMap xMap = plot()->canvasMap( d_xAxis ); QwtScaleMap yMap = plot()->canvasMap( d_yAxis ); const QPointF p( xMap.transform( pos.x() ), yMap.transform( pos.y() ) ); return p.toPoint(); }
void ScaleDraw::drawBreak(QPainter *painter) const { ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis()); if (!sc_engine->hasBreak() || !sc_engine->hasBreakDecoration()) return; painter->save(); painter->setRenderHint(QPainter::Antialiasing); QPen pen = painter->pen(); pen.setColor(d_plot->axisWidget(axis())->palette().color(QPalette::Active, QColorGroup::Foreground)); painter->setPen(pen); int len = d_plot->majorTickLength(); QwtScaleMap scaleMap = map(); const QwtMetricsMap metricsMap = QwtPainter::metricsMap(); QPoint pos = this->pos(); if (!d_plot->isPrinting()){ 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: case RightScale: QwtPainter::drawLine(painter, pos.x() + len, lval - len, pos.x() - len, lval + len); QwtPainter::drawLine(painter, pos.x() + len, rval - len, pos.x() - len, rval + len); break; case TopScale: case BottomScale: QwtPainter::drawLine(painter, lval + len, pos.y() - len, lval - len, pos.y() + len); QwtPainter::drawLine(painter, rval + len, pos.y() - len, rval - len, pos.y() + len); break; } if (!d_plot->isPrinting()) QwtPainter::setMetricsMap(metricsMap); // restore metrics map painter->restore(); }
/*! 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 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 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; int i, ip; for ( i = from, ip = 0; i <= to; i++, ip += 2 ) { 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 ( 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 ) polygon = QwtClipper::clipPolygonF( canvasRect, polygon ); QwtPainter::drawPolyline( painter, polygon ); if ( d_data->brush.style() != Qt::NoBrush ) fillCurve( painter, xMap, yMap, polygon ); }
/*! Draw symbols for a subset of the samples \param painter Painter \param symbol Interval symbol \param xMap x map \param yMap y map \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 \sa setSymbol(), drawSeries(), drawTube() */ void QwtPlotIntervalCurve::drawSymbols( QPainter *painter, const QwtIntervalSymbol &symbol, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to ) const { painter->save(); QPen pen = symbol.pen(); pen.setCapStyle( Qt::FlatCap ); painter->setPen( pen ); painter->setBrush( symbol.brush() ); const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect); const double xMin = tr.left(); const double xMax = tr.right(); const double yMin = tr.top(); const double yMax = tr.bottom(); const bool doClip = d_data->paintAttributes & ClipPolygons; for ( int i = from; i <= to; i++ ) { const QwtIntervalSample s = sample( i ); if ( orientation() == Qt::Vertical ) { if ( !doClip || qwtIsVSampleInside( s, xMin, xMax, yMin, yMax ) ) { const double x = xMap.transform( s.value ); const double y1 = yMap.transform( s.interval.minValue() ); const double y2 = yMap.transform( s.interval.maxValue() ); symbol.draw( painter, orientation(), QPointF( x, y1 ), QPointF( x, y2 ) ); } } else { if ( !doClip || qwtIsHSampleInside( s, xMin, xMax, yMin, yMax ) ) { const double y = yMap.transform( s.value ); const double x1 = xMap.transform( s.interval.minValue() ); const double x2 = xMap.transform( s.interval.maxValue() ); symbol.draw( painter, orientation(), QPointF( x1, y ), QPointF( x2, y ) ); } } } painter->restore(); }
/*! Draw a subset of the points \param painter Painter \param xMap Maps x-values into pixel coordinates. \param yMap Maps y-values into pixel coordinates. \param canvasRect Contents rectangle 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() */ void CpPlotCurve::drawDots( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to ) const { if ( !d_data->colorRange.isValid() ) return; const bool doAlign = QwtPainter::roundingAlignment( painter ); const QwtColorMap::Format format = d_data->colorMap->format(); if ( format == QwtColorMap::Indexed ) d_data->colorTable = d_data->colorMap->colorTable( d_data->colorRange ); const QwtSeriesData<QwtPoint3D> *series = data(); for ( int i = from; i <= to; i++ ) { const QwtPoint3D 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 ( d_data->paintAttributes & CpPlotCurve::ClipPoints ) { if ( !canvasRect.contains( xi, yi ) ) continue; } if ( format == QwtColorMap::RGB ) { const QRgb rgb = d_data->colorMap->rgb( d_data->colorRange, sample.z() ); painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) ); } else { const unsigned char index = d_data->colorMap->colorIndex( d_data->colorRange, sample.z() ); painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ), d_data->penWidth ) ); } QwtPainter::drawPoint( painter, QPointF( xi, yi ) ); } d_data->colorTable.clear(); }
/*! Translate a rectangle from plot into pixel coordinates \return Rectangle in pixel coordinates \sa QwtPlotPicker::invTransform() */ QRect QwtPlotPicker::transform(const QwtDoubleRect &rect) const { QwtScaleMap xMap = plot()->canvasMap(d_xAxis); QwtScaleMap yMap = plot()->canvasMap(d_yAxis); const int left = xMap.transform(rect.left()); const int right = xMap.transform(rect.right()); const int top = yMap.transform(rect.top()); const int bottom = yMap.transform(rect.bottom()); return QRect(left, top, right - left, bottom - top); }
/// Draw curve in Dots style void FunctionCurve::drawDots(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const { const double start = xMap.s1(); const double end = xMap.s2(); const size_t n = m_x->size(); // find first point to draw which is 0 or the one before first visible size_t istart = 0; for(; istart < n; ++istart) { const double& x = (*m_x)[istart]; if ( x < start ) continue; if ( x > end ) break; if ( istart > 0 ) --istart; break; } if ( istart >= n ) return; size_t iend = n; bool doDrawSymbols = m_symbol->style() != QwtSymbol::NoSymbol; if ( doDrawSymbols && m_pointCoords.size() != n ) { m_pointCoords.resize(n); } // draw the points for(size_t i = istart; i < n; ++i) { const double& x = (*m_x)[i]; if ( x > end ) { iend = i; break; } int x1 = xMap.transform(x); int y1 = yMap.transform(m_y.getCalculated(i)); painter->drawPoint(x1,y1); if ( doDrawSymbols ) { m_pointCoords[i] = QPoint(x1,y1); } } // draw the symbols if ( doDrawSymbols ) { drawSymbols(painter,istart,iend); } }
virtual void draw( QPainter *painter, const QwtScaleMap &, const QwtScaleMap &yMap, const QRectF &canvasRect ) const { QColor c( Qt::white ); QRectF r = canvasRect; for ( int i = 100; i > 0; i -= 10 ) { r.setBottom( yMap.transform( i - 10 ) ); r.setTop( yMap.transform( i ) ); painter->fillRect( r, c ); c = c.dark( 110 ); } }
/*! \brief Draw lines If the CurveAttribute Fitted is enabled a QwtCurveFitter tries to interpolate/smooth the curve, before it is painted. \param painter Painter \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 setCurveAttribute(), setCurveFitter(), draw(), drawLines(), drawDots(), drawSteps(), drawSticks() */ void QwtPlotCurve::drawLines( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to ) const { int size = to - from + 1; if ( size <= 0 ) return; const bool doAlign = QwtPainter::roundingAlignment( painter ); QPolygonF polyline( size ); QPointF *points = polyline.data(); for ( int i = from; i <= to; i++ ) { const QPointF sample = d_series->sample( i ); double x = xMap.transform( sample.x() ); double y = yMap.transform( sample.y() ); if ( doAlign ) { x = qRound( x ); y = qRound( y ); } points[i - from].rx() = x; points[i - from].ry() = y; } if ( ( d_data->attributes & Fitted ) && d_data->curveFitter ) polyline = d_data->curveFitter->fitCurve( polyline ); if ( d_data->paintAttributes & ClipPolygons ) { qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); const QPolygonF clipped = QwtClipper::clipPolygonF( canvasRect.adjusted(-pw, -pw, pw, pw), polyline, false ); QwtPainter::drawPolyline( painter, clipped ); } else { QwtPainter::drawPolyline( painter, polyline ); } if ( d_data->brush.style() != Qt::NoBrush ) fillCurve( painter, xMap, yMap, canvasRect, polyline ); }
/*! \brief Calculate the bounding rect of the plot area The plot area depends on the zoom parameters. \param canvasRect Rectangle of the canvas \return Rectangle for displaying 100% of the plot */ QRectF QwtPolarPlot::plotRect( const QRectF &canvasRect ) const { const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius ); const QwtScaleEngine *se = scaleEngine( QwtPolar::Radius ); const int margin = plotMarginHint(); const QRectF cr = canvasRect; const int radius = qMin( cr.width(), cr.height() ) / 2 - margin; QwtScaleMap map; map.setTransformation( se->transformation() ); map.setPaintInterval( 0.0, radius / d_data->zoomFactor ); map.setScaleInterval( sd->lowerBound(), sd->upperBound() ); double v = map.s1(); if ( map.s1() <= map.s2() ) v += d_data->zoomPos.radius(); else v -= d_data->zoomPos.radius(); v = map.transform( v ); const QPointF off = QwtPointPolar( d_data->zoomPos.azimuth(), v ).toPoint(); QPointF center( cr.center().x(), cr.top() + margin + radius ); center -= QPointF( off.x(), -off.y() ); QRectF rect( 0, 0, 2 * map.p2(), 2 * map.p2() ); rect.moveCenter( center ); return rect; }
/*! Draw lines from the pole \param painter Painter \param canvasRect Contents rect of the canvas in painter coordinates \param pole Position of the pole in painter coordinates \param radius Length of the lines in painter coordinates \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI \param values Azimuth values, indicating the direction of the lines */ void QwtPolarGrid::drawRays( QPainter *painter, const QRectF &canvasRect, const QPointF &pole, double radius, const QwtScaleMap &azimuthMap, const QList<double> &values ) const { for ( int i = 0; i < int( values.size() ); i++ ) { double azimuth = azimuthMap.transform( values[i] ); azimuth = ::fmod( azimuth, 2 * M_PI ); bool skipLine = false; if ( testDisplayFlag( SmartScaleDraw ) ) { const QwtAbstractScaleDraw::ScaleComponent bone = QwtAbstractScaleDraw::Backbone; if ( isClose( azimuth, 0.0 ) ) { const AxisData &axis = d_data->axisData[QwtPolar::AxisRight]; if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) ) skipLine = true; } else if ( isClose( azimuth, M_PI / 2 ) ) { const AxisData &axis = d_data->axisData[QwtPolar::AxisTop]; if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) ) skipLine = true; } else if ( isClose( azimuth, M_PI ) ) { const AxisData &axis = d_data->axisData[QwtPolar::AxisLeft]; if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) ) skipLine = true; } else if ( isClose( azimuth, 3 * M_PI / 2.0 ) ) { const AxisData &axis = d_data->axisData[QwtPolar::AxisBottom]; if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) ) skipLine = true; } } if ( !skipLine ) { const QPointF pos = qwtPolar2Pos( pole, radius, azimuth ); /* Qt4 is horrible slow, when painting primitives, with coordinates far outside the visible area. */ QPolygonF polygon( 2 ); polygon[0] = pole.toPoint(); polygon[1] = pos.toPoint(); if ( testDisplayFlag( ClipGridLines ) ) polygon = QwtClipper::clipPolygonF( canvasRect, polygon ); QwtPainter::drawPolyline( painter, polygon ); } } }
void Grid::drawLines(QPainter *painter, const QRect &rect, Qt::Orientation orientation, const QwtScaleMap &map, const QwtValueList &values) const { const int x1 = rect.left(); const int x2 = rect.right() + 1; const int y1 = rect.top(); const int y2 = rect.bottom() + 1; const int margin = 10; for (uint i = 0; i < (uint)values.count(); i++) { const int value = map.transform(values[i]); if ( orientation == Qt::Horizontal ) { if ((value >= y1 + margin) && (value <= y2 - margin)) QwtPainter::drawLine(painter, x1, value, x2, value); } else { if ((value >= x1 + margin) && (value <= x2 - margin)) QwtPainter::drawLine(painter, value, y1, value, y2); } } }
void LegendMarker::draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const { const int x = xMap.transform(xValue()); const int y = yMap.transform(yValue()); const int symbolLineLength = symbolsMaxLineLength(); int width, height; QwtArray<long> heights = itemsHeight(y, symbolLineLength, width, height); QRect rs = QRect(QPoint(x, y), QSize(width, height)); drawFrame(p, d_frame, rs); drawSymbols(p, rs, heights, symbolLineLength); drawLegends(p, rs, heights, symbolLineLength); }
void QwtPlotGrid::drawLines( QPainter *painter, const QRectF &canvasRect, Qt::Orientation orientation, const QwtScaleMap &scaleMap, const QList<double> &values ) const { const double x1 = canvasRect.left(); const double x2 = canvasRect.right() - 1.0; const double y1 = canvasRect.top(); const double y2 = canvasRect.bottom() - 1.0; const bool doAlign = QwtPainter::roundingAlignment( painter ); for ( uint i = 0; i < ( uint )values.count(); i++ ) { double value = scaleMap.transform( values[i] ); if ( doAlign ) value = qRound( value ); if ( orientation == Qt::Horizontal ) { if ( qwtFuzzyGreaterOrEqual( value, y1 ) && qwtFuzzyLessOrEqual( value, y2 ) ) { QwtPainter::drawLine( painter, x1, value, x2, value ); } } else { if ( qwtFuzzyGreaterOrEqual( value, x1 ) && qwtFuzzyLessOrEqual( value, x2 ) ) { QwtPainter::drawLine( painter, value, y1, value, y2 ); } } } }
void Plot::drawBreak(QPainter *painter, const QRect &rect, const QwtScaleMap &map, int axis) const { const ScaleEngine *sc_engine = (const ScaleEngine *)axisScaleEngine(axis); /*const QwtScaleEngine *qwtsc_engine=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(); QColor color = axisWidget(axis)->palette().color(QPalette::Active, QColorGroup::Foreground); painter->setPen(QPen(color, axesLinewidth(), Qt::SolidLine)); int left = map.transform(sc_engine->axisBreakLeft()); int right = map.transform(sc_engine->axisBreakRight()); int x, y; int len = majTickLength; switch (axis){ case QwtPlot::yLeft: x = rect.left() - 1; QwtPainter::drawLine(painter, x, left, x + len, left - len); QwtPainter::drawLine(painter, x, right, x + len, right - len); break; case QwtPlot::yRight: x = rect.right() + 1; QwtPainter::drawLine(painter, x - len, left + len, x, left); QwtPainter::drawLine(painter, x - len, right + len, x, right); break; case QwtPlot::xBottom: y = rect.bottom() + 1; QwtPainter::drawLine(painter, left, y, left + len, y - len); QwtPainter::drawLine(painter, right, y, right + len, y - len); break; case QwtPlot::xTop: y = rect.top() - 1; QwtPainter::drawLine(painter, left - len, y + len, left, y); QwtPainter::drawLine(painter, right - len, y + len, right, y); break; } painter->restore(); //} }
/*! Draw a sample \param painter Painter \param xMap x map \param yMap y map \param canvasRect Contents rect of the canvas \param boundingInterval Bounding interval of sample values \param index Index of the sample \param sample Value of the sample \sa drawSeries() */ void QwtPlotBarChart::drawSample( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, const QwtInterval &boundingInterval, int index, const QPointF &sample ) const { QwtColumnRect barRect; if ( orientation() == Qt::Horizontal ) { const double barHeight = sampleWidth( yMap, canvasRect.height(), boundingInterval.width(), sample.y() ); const double x1 = xMap.transform( baseline() ); const double x2 = xMap.transform( sample.y() ); const double y = yMap.transform( sample.x() ); const double y1 = y - 0.5 * barHeight; const double y2 = y + 0.5 * barHeight; barRect.direction = ( x1 < x2 ) ? QwtColumnRect::LeftToRight : QwtColumnRect::RightToLeft; barRect.hInterval = QwtInterval( x1, x2 ).normalized(); barRect.vInterval = QwtInterval( y1, y2 ); } else { const double barWidth = sampleWidth( xMap, canvasRect.width(), boundingInterval.width(), sample.y() ); const double x = xMap.transform( sample.x() ); const double x1 = x - 0.5 * barWidth; const double x2 = x + 0.5 * barWidth; const double y1 = yMap.transform( baseline() ); const double y2 = yMap.transform( sample.y() ); barRect.direction = ( y1 < y2 ) ? QwtColumnRect::TopToBottom : QwtColumnRect::BottomToTop; barRect.hInterval = QwtInterval( x1, x2 ); barRect.vInterval = QwtInterval( y1, y2 ).normalized(); } drawBar( painter, index, sample, barRect ); }
/*! Draw sticks \param painter Painter \param xMap x map \param yMap y map \param from index of the first point to be painted \param to index of the last point to be painted \sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps() */ void QwtPlotCurve::drawSticks(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const { int x0 = xMap.transform(d_data->reference); int y0 = yMap.transform(d_data->reference); for (int i = from; i <= to; i++) { const int xi = xMap.transform(x(i)); const int yi = yMap.transform(y(i)); if (d_data->curveType == Xfy) QwtPainter::drawLine(painter, x0, yi, xi, yi); else QwtPainter::drawLine(painter, xi, y0, xi, yi); } }
/*! \brief Draw symbols \param painter Painter \param symbol Curve symbol \param xMap x map \param yMap y map \param from index of the first point to be painted \param to index of the last point to be painted \sa setSymbol(), draw(), drawCurve() */ void QwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const { painter->setBrush(symbol.brush()); painter->setPen(QwtPainter::scaledPen(symbol.pen())); const QwtMetricsMap &metricsMap = QwtPainter::metricsMap(); QRect rect; rect.setSize(metricsMap.screenToLayout(symbol.size())); if ( to > from && d_data->paintAttributes & PaintFiltered ) { const QRect window = painter->window(); if ( window.isEmpty() ) return; PrivateData::PixelMatrix pixelMatrix(window); for (int i = from; i <= to; i++) { const QPoint pi( xMap.transform(x(i)), yMap.transform(y(i)) ); if ( pixelMatrix.testPixel(pi) ) { rect.moveCenter(pi); symbol.draw(painter, rect); } } } else { for (int i = from; i <= to; i++) { const int xi = xMap.transform(x(i)); const int yi = yMap.transform(y(i)); rect.moveCenter(QPoint(xi, yi)); symbol.draw(painter, rect); } } }
static inline double qwtTransformWidth( const QwtScaleMap &map, double value, double width ) { const double w2 = 0.5 * width; const double v1 = map.transform( value - w2 ); const double v2 = map.transform( value + w2 ); return qAbs( v2 - v1 ); }
/*! \brief Complete a polygon to be a closed polygon including the area between the original polygon and the baseline. \param painter Painter \param xMap X map \param yMap Y map \param polygon Polygon to be completed */ void QwtPlotCurve::closePolyline( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, QPolygonF &polygon ) const { if ( polygon.size() < 2 ) return; const bool doAlign = QwtPainter::roundingAlignment( painter ); double baseline = d_data->baseline; if ( orientation() == Qt::Vertical ) { if ( yMap.transformation()->type() == QwtScaleTransformation::Log10 ) { if ( baseline < QwtScaleMap::LogMin ) baseline = QwtScaleMap::LogMin; } double refY = yMap.transform( baseline ); if ( doAlign ) refY = qRound( refY ); polygon += QPointF( polygon.last().x(), refY ); polygon += QPointF( polygon.first().x(), refY ); } else { if ( xMap.transformation()->type() == QwtScaleTransformation::Log10 ) { if ( baseline < QwtScaleMap::LogMin ) baseline = QwtScaleMap::LogMin; } double refX = xMap.transform( baseline ); if ( doAlign ) refX = qRound( refX ); polygon += QPointF( refX, polygon.last().y() ); polygon += QPointF( refX, polygon.first().y() ); } }