Example #1
0
void ProfileGraphicsView::plot_cylinder_pressure_text()
{
    int i;
    int mbar, cyl;
    int seen_cyl[MAX_CYLINDERS] = { FALSE, };
    int last_pressure[MAX_CYLINDERS] = { 0, };
    int last_time[MAX_CYLINDERS] = { 0, };
    struct plot_data *entry;
    struct plot_info *pi = &gc.pi;

    if (!get_cylinder_pressure_range(&gc))
        return;

    cyl = -1;
    for (i = 0; i < pi->nr; i++) {
        entry = pi->entry + i;
        mbar = GET_PRESSURE(entry);

        if (!mbar)
            continue;
        if (cyl != entry->cylinderindex) {
            cyl = entry->cylinderindex;
            if (!seen_cyl[cyl]) {
                plot_pressure_value(mbar, entry->sec, LEFT, BOTTOM);
                plot_gas_value(mbar, entry->sec, LEFT, TOP,
                               get_o2(&dive->cylinder[cyl].gasmix),
                               get_he(&dive->cylinder[cyl].gasmix));
                seen_cyl[cyl] = TRUE;
            }
        }
        last_pressure[cyl] = mbar;
        last_time[cyl] = entry->sec;
    }

    for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
        if (last_time[cyl]) {
            plot_pressure_value(last_pressure[cyl], last_time[cyl], CENTER, TOP);
        }
    }
}
void DiveGasPressureItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
	// We don't have enougth data to calculate things, quit.
	if (!shouldCalculateStuff(topLeft, bottomRight))
		return;
	int last_index = -1;
	QPolygonF boundingPoly; // This is the "Whole Item", but a pressure can be divided in N Polygons.
	polygons.clear();

	for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
		plot_data* entry = dataModel->data().entry + i;
		int mbar = GET_PRESSURE(entry);

		if (entry->cylinderindex != last_index) {
			polygons.append(QPolygonF()); // this is the polygon that will be actually drawned on screen.
			last_index = entry->cylinderindex;
		}
		if (!mbar) {
			continue;
		}

		QPointF point(hAxis->posAtValue(entry->sec), vAxis->posAtValue(mbar));
		boundingPoly.push_back(point); // The BoundingRect
		polygons.last().push_back(point); // The polygon thta will be plotted.
	}
	setPolygon(boundingPoly);
	qDeleteAll(texts);
	texts.clear();
	int mbar, cyl;
	int seen_cyl[MAX_CYLINDERS] = { false, };
	int last_pressure[MAX_CYLINDERS] = { 0, };
	int last_time[MAX_CYLINDERS] = { 0, };
	struct plot_data *entry;
	struct dive *dive = getDiveById(dataModel->id());
	Q_ASSERT(dive != NULL);

	cyl = -1;
	for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
		entry = dataModel->data().entry + i;
		mbar = GET_PRESSURE(entry);

		if (!mbar)
			continue;
		if (cyl != entry->cylinderindex) {
			cyl = entry->cylinderindex;
			if (!seen_cyl[cyl]) {
				plot_pressure_value(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop);
				plot_gas_value(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom,
						get_o2(&dive->cylinder[cyl].gasmix),
						get_he(&dive->cylinder[cyl].gasmix));
				seen_cyl[cyl] = true;
			}
		}
		last_pressure[cyl] = mbar;
		last_time[cyl] = entry->sec;
	}

	for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
		if (last_time[cyl]) {
			plot_pressure_value(last_pressure[cyl], last_time[cyl], Qt::AlignLeft | Qt::AlignTop);
		}
	}
}