示例#1
0
void Grid::load(const QStringList& grid)
{
    Plot *d_plot = (Plot *)plot();
    if (!d_plot)
        return;

    bool majorOnX = grid[1].toInt();
    bool minorOnX = grid[2].toInt();
    bool majorOnY = grid[3].toInt();
    bool minorOnY = grid[4].toInt();
    bool xZeroOn = false;
    bool yZeroOn = false;
    int xAxis = QwtPlot::xBottom;
    int yAxis = QwtPlot::yLeft;

    QPen majPenX, minPenX, majPenY, minPenY;
    if (grid.count() >= 21) { // since 0.9 final
        majPenX = QPen(QColor(grid[5]), grid[7].toDouble(), Graph::getPenStyle(grid[6].toInt()));
        minPenX = QPen(QColor(grid[8]), grid[10].toDouble(), Graph::getPenStyle(grid[9].toInt()));
        majPenY = QPen(QColor(grid[11]), grid[13].toDouble(), Graph::getPenStyle(grid[12].toInt()));
        minPenY = QPen(QColor(grid[14]), grid[16].toDouble(), Graph::getPenStyle(grid[15].toInt()));

        xZeroOn = grid[17].toInt();
        yZeroOn = grid[18].toInt();
        xAxis = grid[19].toInt();
        yAxis = grid[20].toInt();
        if (grid.count() >= 22)
            setRenderHint(QwtPlotItem::RenderAntialiased, grid[21].toInt());

    } else { // older versions of QtiPlot (<= 0.9rc3)
        majPenX = QPen(ColorBox::color(grid[5].toInt()), grid[7].toDouble(), Graph::getPenStyle(grid[6].toInt()));
        minPenX = QPen(ColorBox::color(grid[8].toInt()), grid[10].toDouble(), Graph::getPenStyle(grid[9].toInt()));
        majPenY = majPenX;
        minPenY = minPenX;

        xZeroOn = grid[11].toInt();
        yZeroOn = grid[12].toInt();

        if (grid.count() == 15) {
            xAxis = grid[13].toInt();
            yAxis = grid[14].toInt();
        }
    }

    setMajPenX(majPenX);
    setMinPenX(minPenX);
    setMajPenY(majPenY);
    setMinPenY(minPenY);

    enableX(majorOnX);
    enableXMin(minorOnX);
    enableY(majorOnY);
    enableYMin(minorOnY);

    setAxis(xAxis, yAxis);

    enableZeroLineX(xZeroOn);
    enableZeroLineY(yZeroOn);
}
示例#2
0
文件: Grid.cpp 项目: liyulun/mantid
void Grid::copy(Grid *grid) {
  if (!grid)
    return;

  setMajPenX(grid->majPenX());
  setMinPenX(grid->minPenX());
  setMajPenY(grid->majPenY());
  setMinPenY(grid->minPenY());

  enableX(grid->xEnabled());
  enableXMin(grid->xMinEnabled());
  enableY(grid->yEnabled());
  enableYMin(grid->yMinEnabled());

  setAxis(grid->xAxis(), grid->yAxis());

  enableZeroLineX(grid->xZeroLineEnabled());
  enableZeroLineY(grid->yZeroLineEnabled());
  setRenderHint(QwtPlotItem::RenderAntialiased,
                grid->testRenderHint(QwtPlotItem::RenderAntialiased));
}
示例#3
0
	void PlotItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget*)
	{
		const auto& rect = option->rect;
#else
	void PlotItem::paint (QPainter *painter)
	{
		const auto& rect = contentsBoundingRect ().toRect ();
#endif

		QwtPlot plot;
		plot.setFrameShape (QFrame::NoFrame);
		plot.enableAxis (QwtPlot::yLeft, LeftAxisEnabled_);
		plot.enableAxis (QwtPlot::xBottom, BottomAxisEnabled_);
		plot.setAxisTitle (QwtPlot::yLeft, LeftAxisTitle_);
		plot.setAxisTitle (QwtPlot::xBottom, BottomAxisTitle_);
		plot.resize (rect.size ());

		auto setPaletteColor = [&plot] (const QColor& color, QPalette::ColorRole role) -> void
		{
			if (!color.isValid ())
				return;

			auto pal = plot.palette ();
			pal.setColor (role, { color });
			plot.setPalette (pal);
		};

		setPaletteColor (BackgroundColor_, QPalette::Window);
		setPaletteColor (TextColor_, QPalette::WindowText);
		setPaletteColor (TextColor_, QPalette::Text);

		if (!PlotTitle_.isEmpty ())
			plot.setTitle (QwtText { PlotTitle_ });

		if (MinYValue_ < MaxYValue_)
		{
			plot.setAxisAutoScale (QwtPlot::yLeft, false);
			plot.setAxisScale (QwtPlot::yLeft, MinYValue_, MaxYValue_);
		}
		plot.setAutoFillBackground (false);
		plot.setCanvasBackground (Qt::transparent);

		if (YGridEnabled_)
		{
			auto grid = new QwtPlotGrid;
			grid->enableYMin (YMinorGridEnabled_);
			grid->enableX (false);
#if QWT_VERSION >= 0x060100
			grid->setMajorPen (QPen (GridLinesColor_, 1, Qt::SolidLine));
			grid->setMinorPen (QPen (GridLinesColor_, 1, Qt::DashLine));
#else
			grid->setMajPen (QPen (GridLinesColor_, 1, Qt::SolidLine));
			grid->setMinPen (QPen (GridLinesColor_, 1, Qt::DashLine));
#endif
			grid->attach (&plot);
		}

		auto items = Multipoints_;
		if (items.isEmpty ())
			items.push_back ({ Color_, Points_ });

		if (MinXValue_ < MaxXValue_)
			plot.setAxisScale (QwtPlot::xBottom, MinXValue_, MaxXValue_);
		else if (const auto ptsCount = items.first ().Points_.size ())
			plot.setAxisScale (QwtPlot::xBottom, 0, ptsCount - 1);

		std::vector<std::unique_ptr<QwtPlotCurve>> curves;
		for (const auto& item : items)
		{
			curves.emplace_back (new QwtPlotCurve);
			const auto curve = curves.back ().get ();

			curve->setPen (QPen (item.Color_));
			auto transpColor = item.Color_;
			transpColor.setAlphaF (Alpha_);
			curve->setBrush (transpColor);

			curve->setRenderHint (QwtPlotItem::RenderAntialiased);
			curve->attach (&plot);

			curve->setSamples (item.Points_.toVector ());
		}

		plot.replot ();

		QwtPlotRenderer {}.render (&plot, painter, rect);

		const auto xExtent = CalcXExtent (plot);
		const auto yExtent = CalcYExtent (plot);
		if (xExtent != XExtent_ || yExtent != YExtent_)
		{
			XExtent_ = xExtent;
			YExtent_ = yExtent;
			emit extentsChanged ();
		}
	}