📄 qwt_plot.cpp
字号:
\sa QwtPlot::drawCanvasItems*/void QwtPlot::drawCanvas(QPainter *painter){ QwtArray<QwtDiMap> map(axisCnt); for ( int axis = 0; axis < axisCnt; axis++ ) map[axis] = canvasMap(axis); drawCanvasItems(painter, d_canvas->contentsRect(), map, QwtPlotPrintFilter());}/*! Redraw the canvas items. \param painter Painter used for drawing \param rect Bounding rectangle where to paint \param map QwtPlot::axisCnt maps, mapping between plot and paint device coordinates \param pfilter Plot print filter*/void QwtPlot::drawCanvasItems(QPainter *painter, const QRect &rect, const QwtArray<QwtDiMap> &map, const QwtPlotPrintFilter &pfilter) const{ // // draw grid // if ( pfilter.options() & QwtPlotPrintFilter::PrintGrid ) { if ( d_grid->enabled() ) { d_grid->draw(painter, rect, map[d_grid->xAxis()], map[d_grid->yAxis()]); } } // // draw curves // QwtPlotCurveIterator itc = curveIterator(); for (QwtPlotCurve *curve = itc.toFirst(); curve != 0; curve = ++itc ) { if ( curve->enabled() ) { curve->draw(painter, map[curve->xAxis()], map[curve->yAxis()]); } } // // draw markers // QwtPlotMarkerIterator itm = markerIterator(); for (QwtPlotMarker *marker = itm.toFirst(); marker != 0; marker = ++itm ) { if ( marker->enabled() ) { marker->draw(painter, map[marker->xAxis()].transform(marker->xValue()), map[marker->yAxis()].transform(marker->yValue()), rect); } }}/*! \brief Draw a set of points of a curve. When observing an measurement while it is running, new points have to be added to an existing curve. drawCurve can be used to display them avoiding a complete redraw of the canvas. \param key curve key \param from index of the first point to be painted \param to index of the last point to be painted. If to < 0 the curve will be painted to its last point. \sa QwtCurve::draw*/void QwtPlot::drawCurve(long key, int from, int to){ QwtPlotCurve *curve = d_curves->find(key); if ( !curve ) return; QPainter p(canvas()); p.setClipping(TRUE); p.setClipRect(canvas()->contentsRect()); curve->draw(&p, canvasMap(curve->xAxis()), canvasMap(curve->yAxis()), from, to); if ( canvas()->cacheMode() && canvas()->cache()) { QPainter cachePainter(canvas()->cache()); cachePainter.translate(-canvas()->contentsRect().x(), -canvas()->contentsRect().y()); curve->draw(&cachePainter, canvasMap(curve->xAxis()), canvasMap(curve->yAxis()), from, to); }}/*! \param axis Axis \return Map for the axis on the canvas. With this map pixel coordinates can translated to plot coordinates and vice versa. \sa QwtDiMap, QwtPlot::transform, QwtPlot::invTransform */QwtDiMap QwtPlot::canvasMap(int axis) const{ QwtDiMap map; if ( !d_canvas ) return map; const QwtScaleDiv &sd = d_as[axis].scaleDiv(); map.setDblRange(sd.lBound(), sd.hBound(), sd.logScale()); if ( axisEnabled(axis) ) { const QwtScale *s = d_scale[axis]; if ( axis == yLeft || axis == yRight ) { int y = s->y() + s->startBorderDist() - d_canvas->y(); int h = s->height() - s->startBorderDist() - s->endBorderDist(); map.setIntRange(y + h - 1, y); } else { int x = s->x() + s->startBorderDist() - d_canvas->x(); int w = s->width() - s->startBorderDist() - s->endBorderDist(); map.setIntRange(x, x + w - 1); } } else { const int margin = plotLayout()->canvasMargin(axis); const QRect &canvasRect = d_canvas->contentsRect(); if ( axis == yLeft || axis == yRight ) { map.setIntRange(canvasRect.bottom() - margin, canvasRect.top() + margin); } else { map.setIntRange(canvasRect.left() + margin, canvasRect.right() - margin); } } return map;}/*! Change the margin of the plot. The margin is the space around all components. \param margin new margin \sa QwtPlotLayout::setMargin(), QwtPlot::margin(), QwtPlot::plotLayout()*/void QwtPlot::setMargin(int margin){ if ( margin < 0 ) margin = 0; if ( margin != d_layout->margin() ) { d_layout->setMargin(margin); updateLayout(); }}/*! \return margin \sa QwtPlot::setMargin(), QwtPlotLayout::margin(), QwtPlot::plotLayout()*/int QwtPlot::margin() const{ return d_layout->margin();}/*! \brief Change the background of the plotting area Sets c to QColorGroup::Background of all colorgroups of the palette of the canvas. Using canvas()->setPalette() is a more powerful way to set these colors. \param c new background color*/void QwtPlot::setCanvasBackground(const QColor &c){ QPalette p = d_canvas->palette(); for ( int i = 0; i < QPalette::NColorGroups; i++ ) p.setColor((QPalette::ColorGroup)i, QColorGroup::Background, c); canvas()->setPalette(p);}/*! Nothing else than: canvas()->palette().color( QPalette::Normal, QColorGroup::Background); \return the background color of the plotting area.*/const QColor & QwtPlot::canvasBackground() const{ return canvas()->palette().color( QPalette::Normal, QColorGroup::Background);}/*! \brief Change the border width of the plotting area Nothing else than canvas()->setLineWidth(w), left for compatibility only. \param w new border width*/void QwtPlot::setCanvasLineWidth(int w){ canvas()->setLineWidth(w);} /*! Nothing else than: canvas()->lineWidth(), left for compatibility only. \return the border width of the plotting area*/int QwtPlot::canvasLineWidth() const{ return canvas()->lineWidth();}#ifndef QWT_NO_COMPAT/*! \brief Enables or disables outline drawing. When the outline feature is enabled, a shape will be drawn in the plotting region when the user presses or drags the mouse. It can be used to implement crosshairs, mark a selected region, etc. \param tf \c TRUE (enabled) or \c FALSE (disabled) \warning An outline style has to be specified. \sa setOutlineStyle()*/void QwtPlot::enableOutline(bool tf){ d_canvas->enableOutline(tf);}/*! \brief Specify the style of the outline The outline style determines which kind of shape is drawn in the plotting region when the user presses a mouse button or drags the mouse. Valid Styles are: \param os Outline Style. Valid values are: \c Qwt::HLine, \c Qwt::VLine, \c Qwt::Cross, \c Qwt::Rect, \c Qwt::Ellipse <dl> <dt>Qwt::Cross <dd>Cross hairs are drawn across the plotting area when the user presses a mouse button. The lines intersect at the point where the mouse was pressed and move with the mouse pointer. <dt>Qwt::HLine, Qwt::VLine <dd>A horizontal or vertical line appears when the user presses a mouse button. This is useful for moving line markers. <dt>Qwt::Rect <dd>A rectangle is displayed when the user drags the mouse. One corner is fixed at the point where the mouse was pressed, and the opposite corner moves with the mouse pointer. This can be used for selecting regions. <dt>Qwt::Ellipse <dd>Similar to Qwt::Rect, but with an ellipse inside a bounding rectangle. </dl> \sa enableOutline()*/void QwtPlot::setOutlineStyle(Qwt::Shape os){ d_canvas->setOutlineStyle(os);}/*! \brief Specify a pen for the outline \param pn new pen*/void QwtPlot::setOutlinePen(const QPen &pn){ d_canvas->setOutlinePen(pn);}/*! \return \c TRUE if the outline feature is enabled*/bool QwtPlot::outlineEnabled() const{ return d_canvas->outlineEnabled();}/*! \return the pen used to draw outlines*/const QPen & QwtPlot::outlinePen() const{ return d_canvas->outlinePen();}/*! \return the outline style \sa setOutlineStyle()*/Qwt::Shape QwtPlot::outlineStyle() const{ return d_canvas->outlineStyle();}#endif // ! QWT_NO_COMPAT/*! \return \c TRUE if the specified axis exists, otherwise \c FALSE \param axis axis index */bool QwtPlot::axisValid(int axis){ return ((axis >= QwtPlot::yLeft) && (axis < QwtPlot::axisCnt));}/*! Called internally when the legend has been clicked on. Emits a legendClicked() signal.*/void QwtPlot::lgdClicked(){ if ( sender()->isWidgetType() ) { long key = d_legend->key((QWidget *)sender()); if ( key >= 0 ) emit legendClicked(key); }}//! Remove all curves and markersvoid QwtPlot::clear(){ d_legend->clear(); d_curves->clear(); d_markers->clear();}//! Remove all curvesvoid QwtPlot::removeCurves(){ d_curves->clear(); d_legend->clear(); autoRefresh();}//! Remove all markersvoid QwtPlot::removeMarkers(){ d_markers->clear(); autoRefresh();}/*! \brief Set or reset the autoLegend option If the autoLegend option is set, a item will be added to the legend whenever a curve is inserted. The autoLegend option is set to FALSE by default, which means that the user has to call enableLegend. \param tf \c TRUE or \c FALSE. Defaults to \c FALSE. \sa QwtPlot::enableLegend()*/void QwtPlot::setAutoLegend(bool tf){ d_autoLegend = tf;}/*! \return TRUE if the autoLegend option is set.*/bool QwtPlot::autoLegend() const{ return d_autoLegend;}/*! \brief Enable or disable the legend \param enable \c TRUE (enabled) or \c FALSE (disabled) \param curveKey Key of a existing curve. If curveKey < 0 the legends for all curves will be updated. \sa QwtPlot::setAutoLegend() \sa QwtPlot::setLegendPos()*/void QwtPlot::enableLegend(bool enable, long curveKey){ bool isUpdateEnabled = d_legend->isUpdatesEnabled(); d_legend->setUpdatesEnabled(FALSE); if ( curveKey < 0 ) // legends for all curves { if ( enable ) { if ( d_legend->itemCount() < d_curves->count() ) { // not all curves have a legend d_legend->clear(); QwtPlotCurveIterator itc = curveIterator(); for ( const QwtPlotCurve *curve = itc.toFirst(); curve != 0; curve = ++itc ) { insertLegendItem(itc.currentKey()); } } } else { d_legend->clear(); } } else { QWidget *legendItem = d_legend->findItem(curveKey); if ( enable ) { if ( d_curves->find(curveKey) && !legendItem ) insertLegendItem(curveKey); } else delete legendItem; } d_legend->setUpdatesEnabled(isUpdateEnabled); updateLayout();}/*! \param curveKey Curve key. \return \c TRUE if legend is enabled, otherwise \c FALSE*/bool QwtPlot::legendEnabled(long curveKey) const{ return d_legend->findItem(curveKey) != 0;}/*! Specify the position of the legend within the widget. If the position legend is \c Qwt::Left or \c Qwt::Right the legend will be organized in one column from top to down. Otherwise the legend items will be placed be placed in a table with a best fit number of columns from left to right. \param pos The legend's position. Valid values are \c Qwt::Left, \c Qwt::Right, \c Qwt::Top, \c QwtBottom. \param ratio Ratio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked if it would need more space than the given ratio. The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 it will be reset to the default ratio. The default vertical/horizontal ratio is 0.33/0.5. \sa QwtPlot::legendPos(), QwtPlotLayout::setLegendPos()*/void QwtPlot::setLegendPos(int pos, double ratio){ if (pos != d_layout->legendPos()) { d_layout->setLegendPos(pos, ratio); QLayout *l = d_legend->contentsWidget()->layout(); if ( l && l->inherits("QwtDynGridLayout") ) { QwtDynGridLayout *tl = (QwtDynGridLayout *)l; if ( d_layout->legendPos() == Qwt::Top || d_layout->legendPos() == Qwt::Bottom ) { tl->setMaxCols(0); // unlimited } else tl->setMaxCols(1); // 1 column: align vertical } updateLayout(); updateTabOrder(); }}/*! \return position of the legend \sa QwtPlot::setLegendPos, QwtPlotLayout::legendPos()*/int QwtPlot::legendPos() const{ return d_layout->legendPos();}/*! \brief Change the font of the legend items \param f new font*/void QwtPlot::setLegendFont(const QFont &f){ d_legend->setFont(f); if (d_legend->isVisible()) updateLayout();}/*! \brief Change the legend's frame style \param st Frame Style. See Qt manual on QFrame.*/void QwtPlot::setLegendFrameStyle(int st){ d_legend->setFrameStyle(st); updateLayout();}/*! \return the frame style of the legend*/int QwtPlot::legendFrameStyle() const{ return d_legend->frameStyle();}/*! \return the font of the legend items*/const QFont QwtPlot::legendFont() const{ return d_legend->font();}/*! Set the identifier display policy of the legend. \param policy new policy. \param mode new mode. \sa QwtLegend::setDisplayPolicy, QwtLegend::LegendDisplayPolicy*/void QwtPlot::setLegendDisplayPolicy( QwtLegend::LegendDisplayPolicy policy, int mode){ d_legend->setDisplayPolicy(policy, mode); for (QwtPlotCurveIterator iter=curveIterator(); iter.current(); ++iter) updateLegendItem(iter.currentKey());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -