void ProfileGraphicsView::plot_pp_text()
{
	double pp, dpp, m;
	int hpos;
	static text_render_options_t tro = {PP_TEXT_SIZE, PP_LINES, LEFT, MIDDLE};

	setup_pp_limits(&gc);
	pp = floor(gc.pi.maxpp * 10.0) / 10.0 + 0.2;
	dpp = pp > 4 ? 1.0 : 0.5;
	hpos = gc.pi.entry[gc.pi.nr - 1].sec;
	QColor c = profile_color[PP_LINES].first();

	for (m = 0.0; m <= pp; m += dpp) {
		QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, m), SCALEGC(hpos, m));
		QPen pen(defaultPen);
		pen.setColor(c);
		item->setPen(pen);
		scene()->addItem(item);
		plot_text(&tro, QPointF(hpos + 30, m), QString::number(m));
	}
}
void ProfileGraphicsView::plot_pp_gas_profile()
{
    int i;
    struct plot_data *entry;
    struct plot_info *pi = &gc.pi;

    setup_pp_limits(&gc);
    QColor c;
    QPointF from, to;
    if (prefs.pp_graphs.pn2) {
        c = getColor(PN2);
        entry = pi->entry;
        from = QPointF(SCALEGC(entry->sec, entry->pn2));
        for (i = 1; i < pi->nr; i++) {
            entry++;
            if (entry->pn2 < prefs.pp_graphs.pn2_threshold)
                plot_add_line(entry->sec, entry->pn2, c, from);
            else
                from = QPointF(SCALEGC(entry->sec, entry->pn2));
        }

        c = getColor(PN2_ALERT);
        entry = pi->entry;
        from = QPointF(SCALEGC(entry->sec, entry->pn2));
        for (i = 1; i < pi->nr; i++) {
            entry++;
            if (entry->pn2 >= prefs.pp_graphs.pn2_threshold)
                plot_add_line(entry->sec, entry->pn2, c, from);
            else
                from = QPointF(SCALEGC(entry->sec, entry->pn2));
        }
    }

    if (prefs.pp_graphs.phe) {
        c = getColor(PHE);
        entry = pi->entry;

        from = QPointF(SCALEGC(entry->sec, entry->phe));
        for (i = 1; i < pi->nr; i++) {
            entry++;
            if (entry->phe < prefs.pp_graphs.phe_threshold)
                plot_add_line(entry->sec, entry->phe, c, from);
            else
                from = QPointF(SCALEGC(entry->sec, entry->phe));
        }

        c = getColor(PHE_ALERT);
        entry = pi->entry;
        from = QPointF(SCALEGC(entry->sec, entry->phe));
        for (i = 1; i < pi->nr; i++) {
            entry++;
            if (entry->phe >= prefs.pp_graphs.phe_threshold)
                plot_add_line(entry->sec, entry->phe, c, from);
            else
                from = QPointF(SCALEGC(entry->sec, entry->phe));
        }
    }
    if (prefs.pp_graphs.po2) {
        c = getColor(PO2);
        entry = pi->entry;
        from = QPointF(SCALEGC(entry->sec, entry->po2));
        for (i = 1; i < pi->nr; i++) {
            entry++;
            if (entry->po2 < prefs.pp_graphs.po2_threshold)
                plot_add_line(entry->sec, entry->po2, c, from);
            else
                from = QPointF(SCALEGC(entry->sec, entry->po2));
        }

        c = getColor(PO2_ALERT);
        entry = pi->entry;
        from = QPointF(SCALEGC(entry->sec, entry->po2));
        for (i = 1; i < pi->nr; i++) {
            entry++;
            if (entry->po2 >= prefs.pp_graphs.po2_threshold)
                plot_add_line(entry->sec, entry->po2, c, from);
            else
                from = QPointF(SCALEGC(entry->sec, entry->po2));
        }
    }
}
void ProfileGraphicsView::plot_pp_gas_profile()
{
	int i;
	struct plot_data *entry;
	struct plot_info *pi = &gc.pi;

	setup_pp_limits(&gc);
	QColor c;
	QPointF from, to;
	if (prefs.pp_graphs.pn2) {
		c = profile_color[PN2].first();
		entry = pi->entry;
		from = QPointF(SCALEGC(entry->sec, entry->pn2));
		for (i = 1; i < pi->nr; i++) {
			entry++;
			if (entry->pn2 < prefs.pp_graphs.pn2_threshold) {
				to = QPointF(SCALEGC(entry->sec, entry->pn2));
				QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
				QPen pen(defaultPen);
				pen.setColor(c);
				item->setPen(pen);
				scene()->addItem(item);
				from = to;
			} else {
				from = QPointF(SCALEGC(entry->sec, entry->pn2));
			}
		}

		c = profile_color[PN2_ALERT].first();
		entry = pi->entry;
		from = QPointF(SCALEGC(entry->sec, entry->pn2));
		for (i = 1; i < pi->nr; i++) {
			entry++;
			if (entry->pn2 >= prefs.pp_graphs.pn2_threshold) {
				to = QPointF(SCALEGC(entry->sec, entry->pn2));
				QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
				QPen pen(defaultPen);
				pen.setColor(c);
				item->setPen(pen);
				scene()->addItem(item);
				from = to;
			} else {
				from = QPointF(SCALEGC(entry->sec, entry->pn2));
			}
		}
	}

	if (prefs.pp_graphs.phe) {
		c = profile_color[PHE].first();
		entry = pi->entry;

		from = QPointF(SCALEGC(entry->sec, entry->phe));
		for (i = 1; i < pi->nr; i++) {
			entry++;
			if (entry->phe < prefs.pp_graphs.phe_threshold) {
				to = QPointF(SCALEGC(entry->sec, entry->phe));
				QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
				QPen pen(defaultPen);
				pen.setColor(c);
				item->setPen(pen);
				scene()->addItem(item);
				from = to;
			} else {
				from = QPointF(SCALEGC(entry->sec, entry->phe));
			}
		}

		c = profile_color[PHE_ALERT].first();
		entry = pi->entry;
		from = QPointF(SCALEGC(entry->sec, entry->phe));
		for (i = 1; i < pi->nr; i++) {
			entry++;
			if (entry->phe >= prefs.pp_graphs.phe_threshold) {
				to = QPointF(SCALEGC(entry->sec, entry->phe));
				QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
				QPen pen(defaultPen);
				pen.setColor(c);
				item->setPen(pen);
				scene()->addItem(item);
				from = to;
			} else {
				from = QPointF(SCALEGC(entry->sec, entry->phe));
			}
		}
	}
	if (prefs.pp_graphs.po2) {
		c = profile_color[PO2].first();
		entry = pi->entry;
		from = QPointF(SCALEGC(entry->sec, entry->po2));
		for (i = 1; i < pi->nr; i++) {
			entry++;
			if (entry->po2 < prefs.pp_graphs.po2_threshold) {
				to = QPointF(SCALEGC(entry->sec, entry->po2));
				QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
				QPen pen(defaultPen);
				pen.setColor(c);
				item->setPen(pen);
				scene()->addItem(item);
				from = to;
			} else {
				from = QPointF(SCALEGC(entry->sec, entry->po2));
			}
		}

		c = profile_color[PO2_ALERT].first();
		entry = pi->entry;
		from = QPointF(SCALEGC(entry->sec, entry->po2));
		for (i = 1; i < pi->nr; i++) {
			entry++;
			if (entry->po2 >= prefs.pp_graphs.po2_threshold) {
				to = QPointF(SCALEGC(entry->sec, entry->po2));
				QGraphicsLineItem *item = new QGraphicsLineItem(from.x(), from.y(), to.x(), to.y());
				item->setPen(QPen(c));
				scene()->addItem(item);
				from = to;
			} else {
				from = QPointF(SCALEGC(entry->sec, entry->po2));
			}
		}
	}
}