void Grid::enableZeroLineY(bool enable) { Plot *d_plot = dynamic_cast<Plot *>(plot()); if (!d_plot) return; if (mrkY < 0 && enable) { QwtPlotMarker *m = new QwtPlotMarker(); mrkY = d_plot->insertMarker(m); m->setRenderHint(QwtPlotItem::RenderAntialiased, false); m->setAxis(xAxis(), yAxis()); m->setLineStyle(QwtPlotMarker::HLine); m->setValue(0.0, 0.0); double width = 1; if (d_plot->canvas()->lineWidth()) width = d_plot->canvas()->lineWidth(); else if (d_plot->axisEnabled(QwtPlot::xBottom) || d_plot->axisEnabled(QwtPlot::xTop)) width = d_plot->axesLinewidth(); m->setLinePen(QPen(Qt::black, width, Qt::SolidLine)); } else if (mrkY >= 0 && !enable) { d_plot->removeMarker(mrkY); mrkY = -1; } }
/*! This function is a shortcut to insert a horizontal or vertical line marker, dependent on the specified axis. \param label Label \param axis Axis to be attached \return New key if the marker could be inserted, 0 if not. */ long QwtPlot::insertLineMarker(const QString &label, int axis) { QwtMarker::LineStyle lineStyle = QwtMarker::NoLine; int xAxis = QwtPlot::xBottom; int yAxis = QwtPlot::yLeft; switch(axis) { case yLeft: case yRight: yAxis = axis; lineStyle = QwtMarker::HLine; break; case xTop: case xBottom: xAxis = axis; lineStyle = QwtMarker::VLine; break; } QwtPlotMarker *marker = new QwtPlotMarker(this); if ( marker == 0 ) return 0; marker->setAxis(xAxis, yAxis); marker->setLabel(label); marker->setLineStyle(lineStyle); marker->setLabelAlignment(Qt::AlignRight|Qt::AlignTop); long key = insertMarker(marker); if ( key == 0 ) delete marker; return key; }
void Grid::enableZeroLineX(bool enable) { Plot *d_plot = (Plot *)plot(); if (!d_plot) return; if (mrkX<0 && enable) { QwtPlotMarker *m = new QwtPlotMarker(); mrkX = d_plot->insertMarker(m); m->setRenderHint(QwtPlotItem::RenderAntialiased, false); m->setAxis(xAxis(), yAxis()); m->setLineStyle(QwtPlotMarker::VLine); m->setValue(0.0, 0.0); double width = 1; if (d_plot->canvas()->lineWidth()) width = d_plot->canvas()->lineWidth(); else if (d_plot->axisEnabled (QwtPlot::yLeft) || d_plot->axisEnabled (QwtPlot::yRight)) width = d_plot->axesLinewidth(); m->setLinePen(QPen(Qt::black, width, Qt::SolidLine)); } else if (mrkX >= 0 && !enable) { d_plot->removeMarker(mrkX); mrkX=-1; } }
/*! \brief Insert a new marker \param label Label \param xAxis X axis to be attached \param yAxis Y axis to be attached \return New key if the marker could be inserted, 0 if not. */ long QwtPlot::insertMarker(const QString &label, int xAxis, int yAxis) { QwtPlotMarker *marker = new QwtPlotMarker(this); if ( marker == 0 ) return 0; marker->setAxis(xAxis, yAxis); marker->setLabel(label); long key = insertMarker(marker); if ( key == 0 ) delete marker; return key; }