/*! Translate a point from pixel into plot coordinates \return Point in plot coordinates \sa transform() */ QPointF QwtPlotPicker::invTransform( const QPoint &pos ) const { QwtScaleMap xMap = plot()->canvasMap( d_xAxis ); QwtScaleMap yMap = plot()->canvasMap( d_yAxis ); return QPointF( xMap.invTransform( pos.x() ), yMap.invTransform( pos.y() ) ); }
/*! Transform a rectangle from paint to scale coordinates \param xMap X map \param yMap Y map \param rect Rectangle in paint coordinates \return Rectangle in scale coordinates \sa transform() */ QRectF QwtScaleMap::invTransform( const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect ) { const double x1 = xMap.invTransform( rect.left() ); const double x2 = xMap.invTransform( rect.right() - 1 ); const double y1 = yMap.invTransform( rect.top() ); const double y2 = yMap.invTransform( rect.bottom() - 1 ); const QRectF r( x1, y1, x2 - x1, y2 - y1 ); return r.normalized(); }
/*! Translate a rectangle from pixel into plot coordinates \return Rectangle in plot coordinates \sa QwtPlotPicker::transform() */ QwtDoubleRect QwtPlotPicker::invTransform(const QRect &rect) const { QwtScaleMap xMap = plot()->canvasMap(d_xAxis); QwtScaleMap yMap = plot()->canvasMap(d_yAxis); const double left = xMap.invTransform(rect.left()); const double right = xMap.invTransform(rect.right()); const double top = yMap.invTransform(rect.top()); const double bottom = yMap.invTransform(rect.bottom()); return QwtDoubleRect(left, top, right - left, bottom - top); }
QwtInterval QwtPlotScaleItem::PrivateData::scaleInterval( const QRectF &canvasRect, const QwtScaleMap &xMap, const QwtScaleMap &yMap ) const { QwtInterval interval; if ( scaleDraw->orientation() == Qt::Horizontal ) { interval.setMinValue( xMap.invTransform( canvasRect.left() ) ); interval.setMaxValue( xMap.invTransform( canvasRect.right() - 1 ) ); } else { interval.setMinValue( yMap.invTransform( canvasRect.bottom() - 1 ) ); interval.setMaxValue( yMap.invTransform( canvasRect.top() ) ); } return interval; }
int MarkerSell::move (PluginData *pd) { if (! pd->data) return 0; Marker *sell = (Marker *) pd->data; switch (pd->status) { case PlotStatus::_MOVE: { Entity *e = sell->settings(); QVariant *price = e->get(QString("price")); if (! price) return 0; QVariant *date = e->get(QString("date")); if (! date) return 0; QwtScaleMap map = sell->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); if (! g_symbol) return 0; Bar *tbar = g_symbol->bar(x); if (! tbar) return 0; date->setValue(tbar->date()); map = sell->plot()->canvasMap(QwtPlot::yRight); price->setValue(map.invTransform((double) pd->point.y())); sell->setModified(TRUE); sell->plot()->replot(); break; } default: break; } return 1; }
/*! Adjust the enabled axes according to dx/dy \param dx Pixel offset in x direction \param dy Pixel offset in y direction \sa QwtPanner::panned() */ void QwtPlotPanner::moveCanvas( int dx, int dy ) { if ( dx == 0 && dy == 0 ) return; QwtPlot *plot = this->plot(); if ( plot == NULL ) return; const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot( false ); for ( int axisPos = 0; axisPos < QwtAxis::PosCount; axisPos++ ) { const int axesCount = plot->axesCount( axisPos ); for ( int i = 0; i < axesCount; i++ ) { const QwtAxisId axisId( axisPos, i ); if ( !isAxisEnabled( axisId ) ) continue; const QwtScaleMap map = plot->canvasMap( axisId ); const double p1 = map.transform( plot->axisScaleDiv( axisId ).lowerBound() ); const double p2 = map.transform( plot->axisScaleDiv( axisId ).upperBound() ); double d1, d2; if ( QwtAxis::isXAxis( axisPos ) ) { d1 = map.invTransform( p1 - dx ); d2 = map.invTransform( p2 - dx ); } else { d1 = map.invTransform( p1 - dy ); d2 = map.invTransform( p2 - dy ); } plot->setAxisScale( axisId, d1, d2 ); } } plot->setAutoReplot( doAutoReplot ); plot->replot(); }
/*! \brief Render a tile of an image. Rendering in tiles can be used to composite an image in parallel threads. \param xMap X-Scale Map \param yMap Y-Scale Map \param tile Geometry of the tile in image coordinates \param image Image to be rendered */ void QwtPlotSpectrogram::renderTile( const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &tile, QImage *image ) const { const QwtInterval range = d_data->data->interval( Qt::ZAxis ); if ( !range.isValid() ) return; if ( d_data->colorMap->format() == QwtColorMap::RGB ) { for ( int y = tile.top(); y <= tile.bottom(); y++ ) { const double ty = yMap.invTransform( y ); QRgb *line = reinterpret_cast<QRgb *>( image->scanLine( y ) ); line += tile.left(); for ( int x = tile.left(); x <= tile.right(); x++ ) { const double tx = xMap.invTransform( x ); *line++ = d_data->colorMap->rgb( range, d_data->data->value( tx, ty ) ); } } } else if ( d_data->colorMap->format() == QwtColorMap::Indexed ) { for ( int y = tile.top(); y <= tile.bottom(); y++ ) { const double ty = yMap.invTransform( y ); unsigned char *line = image->scanLine( y ); line += tile.left(); for ( int x = tile.left(); x <= tile.right(); x++ ) { const double tx = xMap.invTransform( x ); *line++ = d_data->colorMap->colorIndex( range, d_data->data->value( tx, ty ) ); } } } }
void Plot::updateLayout() { QwtPlot::updateLayout(); const QwtScaleMap xMap = canvasMap( QwtPlot::xBottom ); const QwtScaleMap yMap = canvasMap( QwtPlot::yLeft ); const QRect cr = canvas()->contentsRect(); const double x1 = xMap.invTransform( cr.left() ); const double x2 = xMap.invTransform( cr.right() ); const double y1 = yMap.invTransform( cr.bottom() ); const double y2 = yMap.invTransform( cr.top() ); const double xRatio = ( x2 - x1 ) / cr.width(); const double yRatio = ( y2 - y1 ) / cr.height(); Q_EMIT resized( xRatio, yRatio ); }
/*! Adjust the enabled axes according to dx/dy \param dx Pixel offset in x direction \param dy Pixel offset in y direction \sa QwtPanner::panned() */ void QwtPlotPanner::moveCanvas(int dx, int dy) { if ( dx == 0 && dy == 0 ) return; QwtPlot *plot = QwtPlotPanner::plot(); if ( plot == NULL ) return; const bool doAutoReplot = plot->autoReplot(); plot->setAutoReplot(false); for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( !d_data->isAxisEnabled[axis] ) continue; const QwtScaleMap map = plot->canvasMap(axis); const int i1 = map.transform(plot->axisScaleDiv(axis)->lowerBound()); const int i2 = map.transform(plot->axisScaleDiv(axis)->upperBound()); double d1, d2; if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) { d1 = map.invTransform(i1 - dx); d2 = map.invTransform(i2 - dx); } else { d1 = map.invTransform(i1 - dy); d2 = map.invTransform(i2 - dy); } plot->setAxisScale(axis, d1, d2); } plot->setAutoReplot(doAutoReplot); plot->replot(); }
void moveCanvas( int dx, int dy ) { if ( dx == 0 && dy == 0 ) return; if (!mPlot->isStopped()) dx = 0; for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { const QwtScaleMap map = mPlot->canvasMap( axis ); #if QWT_VERSION < 0x060102 const QwtScaleDiv* scaleDiv = mPlot->axisScaleDiv( axis ); #else const QwtScaleDiv* scaleDiv = &mPlot->axisScaleDiv( axis ); #endif const double p1 = map.transform( scaleDiv->lowerBound() ); const double p2 = map.transform( scaleDiv->upperBound() ); double d1, d2; if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) { d1 = map.invTransform( p1 - dx ); d2 = map.invTransform( p2 - dx ); } else { d1 = map.invTransform( p1 - dy ); d2 = map.invTransform( p2 - dy ); } mPlot->setAxisScale( axis, d1, d2 ); } mPlot->flagAxisSyncRequired(); mPlot->replot(); }
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; }
int MarkerTLine::move (PluginData *pd) { if (! pd->data) return 0; Marker *tline = (Marker *) pd->data; Entity *e = tline->settings(); switch (pd->status) { case PlotStatus::_MOVE: case PlotStatus::_CREATE_MOVE: { QVariant *price = e->get(QString("price")); if (! price) return 0; QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *price2 = e->get(QString("price2")); if (! price2) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QwtScaleMap map = tline->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date->setValue(bar->date()); map = tline->plot()->canvasMap(QwtPlot::yRight); price->setValue(map.invTransform((double) pd->point.y())); if (pd->status == PlotStatus::_CREATE_MOVE) { date2->setValue(bar->date()); price2->setValue(price->toDouble()); } tline->plot()->replot(); tline->setModified(TRUE); break; } case PlotStatus::_MOVE2: { QVariant *price2 = e->get(QString("price2")); if (! price2) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QwtScaleMap map = tline->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date2->setValue(bar->date()); map = tline->plot()->canvasMap(QwtPlot::yRight); price2->setValue(map.invTransform((double) pd->point.y())); tline->plot()->replot(); tline->setModified(TRUE); break; } default: break; } return 1; }
QPointF PlotMagnifier::invTransform(QPoint pos) { QwtScaleMap xMap = plot()->canvasMap( QwtPlot::xBottom ); QwtScaleMap yMap = plot()->canvasMap( QwtPlot::yLeft ); return QPointF ( xMap.invTransform( pos.x() ), yMap.invTransform( pos.y() ) ); }
/*! Calculate the bounding interval of the radial scale that is visible on the canvas. */ QwtDoubleInterval QwtPolarPlot::visibleInterval() const { const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius ); const QwtDoubleRect cRect = canvas()->contentsRect(); const QwtDoubleRect pRect = plotRect( cRect.toRect() ); if ( cRect.contains( pRect.toRect() ) || !cRect.intersects( pRect ) ) { #if QWT_VERSION < 0x050200 return QwtDoubleInterval( sd->lBound(), sd->hBound() ); #else return QwtDoubleInterval( sd->lowerBound(), sd->upperBound() ); #endif } const QwtDoublePoint pole = pRect.center(); const QwtDoubleRect scaleRect = pRect & cRect; const QwtScaleMap map = scaleMap( QwtPolar::Radius ); double dmin = 0.0; double dmax = 0.0; if ( scaleRect.contains( pole ) ) { dmin = 0.0; QwtDoublePoint corners[4]; corners[0] = scaleRect.bottomRight(); corners[1] = scaleRect.topRight(); corners[2] = scaleRect.topLeft(); corners[3] = scaleRect.bottomLeft(); dmax = 0.0; for ( int i = 0; i < 4; i++ ) { const double dist = qwtDistance( pole, corners[i] ); if ( dist > dmax ) dmax = dist; } } else { if ( pole.x() < scaleRect.left() ) { if ( pole.y() < scaleRect.top() ) { dmin = qwtDistance( pole, scaleRect.topLeft() ); dmax = qwtDistance( pole, scaleRect.bottomRight() ); } else if ( pole.y() > scaleRect.bottom() ) { dmin = qwtDistance( pole, scaleRect.bottomLeft() ); dmax = qwtDistance( pole, scaleRect.topRight() ); } else { dmin = scaleRect.left() - pole.x(); dmax = qwtMax( qwtDistance( pole, scaleRect.bottomRight() ), qwtDistance( pole, scaleRect.topRight() ) ); } } else if ( pole.x() > scaleRect.right() ) { if ( pole.y() < scaleRect.top() ) { dmin = qwtDistance( pole, scaleRect.topRight() ); dmax = qwtDistance( pole, scaleRect.bottomLeft() ); } else if ( pole.y() > scaleRect.bottom() ) { dmin = qwtDistance( pole, scaleRect.bottomRight() ); dmax = qwtDistance( pole, scaleRect.topLeft() ); } else { dmin = pole.x() - scaleRect.right(); dmax = qwtMax( qwtDistance( pole, scaleRect.bottomLeft() ), qwtDistance( pole, scaleRect.topLeft() ) ); } } else if ( pole.y() < scaleRect.top() ) { dmin = scaleRect.top() - pole.y(); dmax = qwtMax( qwtDistance( pole, scaleRect.bottomLeft() ), qwtDistance( pole, scaleRect.bottomRight() ) ); } else if ( pole.y() > scaleRect.bottom() ) { dmin = pole.y() - scaleRect.bottom(); dmax = qwtMax( qwtDistance( pole, scaleRect.topLeft() ), qwtDistance( pole, scaleRect.topRight() ) ); } } const double radius = pRect.width() / 2.0; if ( dmax > radius ) dmax = radius; QwtDoubleInterval interval; interval.setMinValue( map.invTransform( dmin ) ); interval.setMaxValue( map.invTransform( dmax ) ); return interval; }
void QxrdImagePlot::contextMenuEvent(QContextMenuEvent * event) { if (m_ContextMenuEnabled) { QxrdImagePlotSettingsPtr set(m_ImagePlotSettings); if (set) { QMenu plotMenu(NULL, NULL); QAction *auSc = plotMenu.addAction("Autoscale"); QAction *prGr = plotMenu.addAction("Print Graph..."); plotMenu.addSeparator(); QxrdDataProcessorPtr dp(m_DataProcessor); if (dp) { QxrdCenterFinderPtr cf(dp->centerFinder()); if (cf) { QwtScaleMap xMap = canvasMap(QwtPlot::xBottom); QwtScaleMap yMap = canvasMap(QwtPlot::yLeft); QWidget *canv = canvas(); QPoint evlocal = canv->mapFromParent(event->pos()); double x = xMap.invTransform(evlocal.x()); double y = yMap.invTransform(evlocal.y()); QxrdPowderPoint nearest = cf->nearestPowderPoint(x, y); QAction *fitCircle = plotMenu.addAction(tr("Fit Circle Center from Points on Ring %1").arg(nearest.n1())); QAction *fitEllipse = plotMenu.addAction(tr("Fit Ellipse from Points on Ring %1").arg(nearest.n1())); QAction *fitEllipses = plotMenu.addAction(tr("Fit Ellipses to all powder rings")); QAction *delPoint = plotMenu.addAction(tr("Delete point at (%1,%2)").arg(nearest.x()).arg(nearest.y())); QAction *delRing = plotMenu.addAction(tr("Delete Ring %1").arg(nearest.n1())); QAction *deleteAllPoints = plotMenu.addAction(tr("Delete all Rings")); QAction *disableRing = plotMenu.addAction(tr("Disable Ring %1").arg(nearest.n1())); QAction *enableRing = plotMenu.addAction(tr("Enable Ring %1").arg(nearest.n1())); QAction *normalizeRings = plotMenu.addAction(tr("Normalize Powder Rings")); QAction *fitPeakNear = plotMenu.addAction(tr("Fit Diffracted Peak near (%1,%2) [%3,%4]").arg(x).arg(y).arg(event->x()).arg(event->y())); QAction *fitRingNear = plotMenu.addAction(tr("Fit Point on Diffracted Ring near (%1,%2) [%3,%4]").arg(x).arg(y).arg(event->x()).arg(event->y())); QAction *traceRingClockwise = plotMenu.addAction(tr("Trace Diffracted Ring starting at (%1,%2) [%3,%4]").arg(x).arg(y).arg(event->x()).arg(event->y())); QAction *missingRing = plotMenu.addAction(tr("Missing Diffracted Ring near (%1,%2)").arg(x).arg(y)); // QAction *traceRingParallel = plotMenu.addAction(tr("Trace Diffracted Ring starting at (%1,%2) [%3,%4] in parallel").arg(x).arg(y).arg(event->x()).arg(event->y())); QAction *zapPixel = plotMenu.addAction(tr("Zap (replace with avg of neighboring values) pixel [%1,%2]").arg((int)x).arg(int(y))); QAction *action = plotMenu.exec(event->globalPos()); if (action == auSc) { autoScale(); } else if (action == prGr) { printGraph(); } else if (action == fitCircle) { cf->fitPowderCircle(nearest.n1()); } else if (action == fitEllipse) { cf->fitPowderEllipse(nearest.n1()); } else if (action == fitEllipses) { cf->fitPowderEllipses(); } else if (action == delPoint) { cf->deletePowderPointNear(x,y); } else if (action == delRing) { cf->deletePowderRing(nearest.n1()); } else if (action == deleteAllPoints) { cf->deletePowderPoints(); } else if (action == enableRing) { cf->enablePowderRing(nearest.n1()); } else if (action == disableRing) { cf->disablePowderRing(nearest.n1()); } else if (action == normalizeRings) { cf->normalizePowderRings(); } else if (action == fitPeakNear) { QMetaObject::invokeMethod(cf.data(), "fitPeakNear", Q_ARG(double,x), Q_ARG(double,y)); } else if (action == fitRingNear) { QMetaObject::invokeMethod(cf.data(), "fitRingNear", Q_ARG(double,x), Q_ARG(double,y)); } else if (action == traceRingClockwise) { QMetaObject::invokeMethod(cf.data(), "traceRingNear", Q_ARG(double,x), Q_ARG(double,y), Q_ARG(double,25.0)); } else if (action == missingRing) {
void PlotMagnifier::rescale( double factor, AxisMode axis ) { factor = qAbs( 1.0/factor ); QwtPlot* plt = plot(); if ( plt == nullptr || factor == 1.0 ){ return; } bool doReplot = false; const bool autoReplot = plt->autoReplot(); plt->setAutoReplot( false ); const int axis_list[2] = {QwtPlot::xBottom, QwtPlot::yLeft}; QRectF new_rect; for ( int i = 0; i <2; i++ ) { double temp_factor = factor; if( i==1 && axis == X_AXIS) { temp_factor = 1.0; } if( i==0 && axis == Y_AXIS) { temp_factor = 1.0; } int axisId = axis_list[i]; if ( isAxisEnabled( axisId ) ) { const QwtScaleMap scaleMap = plt->canvasMap( axisId ); double v1 = scaleMap.s1(); double v2 = scaleMap.s2(); double center = _mouse_position.x(); if( axisId == QwtPlot::yLeft){ center = _mouse_position.y(); } if ( scaleMap.transformation() ) { // the coordinate system of the paint device is always linear v1 = scaleMap.transform( v1 ); // scaleMap.p1() v2 = scaleMap.transform( v2 ); // scaleMap.p2() } const double width = ( v2 - v1 ); const double ratio = (v2-center)/ (width); v1 = center - width*temp_factor*(1-ratio); v2 = center + width*temp_factor*(ratio); if( v1 > v2 ) std::swap( v1, v2 ); if ( scaleMap.transformation() ) { v1 = scaleMap.invTransform( v1 ); v2 = scaleMap.invTransform( v2 ); } if( v1 < _lower_bounds[axisId]) v1 = _lower_bounds[axisId]; if( v2 > _upper_bounds[axisId]) v2 = _upper_bounds[axisId]; plt->setAxisScale( axisId, v1, v2 ); if( axisId == QwtPlot::xBottom) { new_rect.setLeft( v1 ); new_rect.setRight( v2 ); } else{ new_rect.setBottom( v1 ); new_rect.setTop( v2 ); } doReplot = true; } } plt->setAutoReplot( autoReplot ); if ( doReplot ){ emit rescaled( new_rect ); } }
/*! \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 ); } } } }
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 QwtPainter::drawColorBar(QPainter *painter, const QwtColorMap &colorMap, const QwtDoubleInterval &interval, const QwtScaleMap &scaleMap, Qt::Orientation orientation, const QRect &rect) { painter->save(); QwtPainter::setClipRect(painter, rect); #if QT_VERSION < 0x040000 QValueVector<QRgb> colorTable; #else QVector<QRgb> colorTable; #endif if ( colorMap.format() == QwtColorMap::Indexed ) colorTable = colorMap.colorTable(interval); QColor c; const QRect devRect = d_metricsMap.layoutToDevice(rect); if ( orientation == Qt::Horizontal ) { QwtScaleMap sMap = scaleMap; sMap.setPaintInterval(devRect.left(), devRect.right()); for ( int x = devRect.left(); x <= devRect.right(); x++ ) { const double value = sMap.invTransform(x); if ( colorMap.format() == QwtColorMap::RGB ) c.setRgb(colorMap.rgb(interval, value)); else c = colorTable[colorMap.colorIndex(interval, value)]; painter->setBrush(QBrush(c)); const QRect r(x, devRect.top(), 1, devRect.height()); QwtPainter::drawRect(painter, r); painter->setPen(c); painter->drawLine(x, devRect.top(), x, devRect.bottom() - 1); } } else // Vertical { QwtScaleMap sMap = scaleMap; sMap.setPaintInterval(devRect.bottom(), devRect.top()); for ( int y = devRect.top(); y <= devRect.bottom(); y++ ) { const double value = sMap.invTransform(y); if ( colorMap.format() == QwtColorMap::RGB ) c.setRgb(colorMap.rgb(interval, value)); else c = colorTable[colorMap.colorIndex(interval, value)]; painter->setPen(c); painter->drawLine(devRect.left(), y, devRect.right() - 1, y); } } painter->restore(); }
/*! Redraw the liquid in thermometer pipe. \param painter Painter \param pipeRect Bounding rectangle of the pipe without borders */ void QwtThermo::drawLiquid( QPainter *painter, const QRect &pipeRect ) const { painter->save(); painter->setClipRect( pipeRect, Qt::IntersectClip ); painter->setPen( Qt::NoPen ); const QwtScaleMap scaleMap = scaleDraw()->scaleMap(); QRect liquidRect = fillRect( pipeRect ); if ( d_data->colorMap != NULL ) { const QwtInterval interval = scaleDiv().interval().normalized(); // Because the positions of the ticks are rounded // we calculate the colors for the rounded tick values QVector<double> values = qwtTickList( scaleDraw()->scaleDiv() ); if ( scaleMap.isInverting() ) qSort( values.begin(), values.end(), qGreater<double>() ); else qSort( values.begin(), values.end(), qLess<double>() ); int from; if ( !values.isEmpty() ) { from = qRound( scaleMap.transform( values[0] ) ); qwtDrawLine( painter, from, d_data->colorMap->color( interval, values[0] ), pipeRect, liquidRect, d_data->orientation ); } for ( int i = 1; i < values.size(); i++ ) { const int to = qRound( scaleMap.transform( values[i] ) ); for ( int pos = from + 1; pos < to; pos++ ) { const double v = scaleMap.invTransform( pos ); qwtDrawLine( painter, pos, d_data->colorMap->color( interval, v ), pipeRect, liquidRect, d_data->orientation ); } qwtDrawLine( painter, to, d_data->colorMap->color( interval, values[i] ), pipeRect, liquidRect, d_data->orientation ); from = to; } } else { if ( !liquidRect.isEmpty() && d_data->alarmEnabled ) { const QRect r = alarmRect( liquidRect ); if ( !r.isEmpty() ) { painter->fillRect( r, palette().brush( QPalette::Highlight ) ); liquidRect = QRegion( liquidRect ).subtracted( r ).boundingRect(); } } painter->fillRect( liquidRect, palette().brush( QPalette::ButtonText ) ); } painter->restore(); }
int MarkerRetracement::move (PluginData *pd) { if (! pd->data) return 0; Marker *m = (Marker *) pd->data; Entity *e = m->settings(); switch (pd->status) { case PlotStatus::_MOVE: case PlotStatus::_CREATE_MOVE: { QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *high = e->get(QString("high")); if (! high) return 0; QVariant *low = e->get(QString("low")); if (! low) return 0; QwtScaleMap map = m->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date->setValue(bar->date()); map = m->plot()->canvasMap(QwtPlot::yRight); high->setValue(map.invTransform((double) pd->point.y())); if (pd->status == PlotStatus::_CREATE_MOVE) { date2->setValue(bar->date()); low->setValue(high->toDouble()); } m->plot()->replot(); m->setModified(TRUE); break; } case PlotStatus::_MOVE2: { QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *low = e->get(QString("low")); if (! low) return 0; QwtScaleMap map = m->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date2->setValue(bar->date()); map = m->plot()->canvasMap(QwtPlot::yRight); low->setValue(map.invTransform((double) pd->point.y())); m->plot()->replot(); m->setModified(TRUE); break; } default: break; } return 1; }
/*! 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 ); }
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; }