QVariant TankInfoModel::data(const QModelIndex& index, int role) const { QVariant ret; if (!index.isValid()) { return ret; } if (role == Qt::FontRole){ return defaultModelFont(); } if (role == Qt::DisplayRole || role == Qt::EditRole) { struct tank_info_t *info = &tank_info[index.row()]; int ml = info->ml; double bar = (info->psi) ? psi_to_bar(info->psi) : info->bar; if (info->cuft && info->psi) ml = cuft_to_l(info->cuft) * 1000 / bar_to_atm(bar); switch(index.column()) { case BAR: ret = bar * 1000; break; case ML: ret = ml; break; case DESCRIPTION: ret = QString(info->name); break; } } return ret; }
static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl, const char *desc, double volume, double pressure, double start, double end, int o2, int he) { int mbar, ml; if (output_units.pressure == PSI) { pressure = psi_to_bar(pressure); start = psi_to_bar(start); end = psi_to_bar(end); } if (pressure && output_units.volume == CUFT) { volume = cuft_to_l(volume); volume /= bar_to_atm(pressure); } ml = volume * 1000 + 0.5; mbar = pressure * 1000 + 0.5; /* Ignore obviously crazy He values */ if (o2 + he > 1000) he = 0; /* We have a rule that normal air is all zeroes */ if (!he && o2 > 208 && o2 < 211) o2 = 0; cyl->type.description = desc; cyl->type.size.mliter = ml; cyl->type.workingpressure.mbar = mbar; cyl->start.mbar = start * 1000 + 0.5; cyl->end.mbar = end * 1000 + 0.5; cyl->gasmix.o2.permille = o2; cyl->gasmix.he.permille = he; /* * Also, insert it into the model if it doesn't already exist */ add_cylinder(cylinder, desc, ml, mbar); }
/* if a default cylinder is set, use that */ void fill_default_cylinder(cylinder_t *cyl) { const char *cyl_name = prefs.default_cylinder; struct tank_info_t *ti = tank_info; pressure_t pO2 = {.mbar = 1600}; if (!cyl_name) return; while (ti->name != NULL) { if (strcmp(ti->name, cyl_name) == 0) break; ti++; } if (ti->name == NULL) /* didn't find it */ return; cyl->type.description = strdup(ti->name); if (ti->ml) { cyl->type.size.mliter = ti->ml; cyl->type.workingpressure.mbar = ti->bar * 1000; } else { cyl->type.workingpressure.mbar = psi_to_mbar(ti->psi); if (ti->psi) cyl->type.size.mliter = cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi)); } // MOD of air cyl->depth = gas_mod(&cyl->gasmix, pO2, 1); } /* make sure that the gas we are switching to is represented in our * list of cylinders */ static int verify_gas_exists(struct gasmix mix_in) { int i; cylinder_t *cyl; for (i = 0; i < MAX_CYLINDERS; i++) { cyl = displayed_dive.cylinder + i; if (cylinder_nodata(cyl)) continue; if (gasmix_distance(&cyl->gasmix, &mix_in) < 200) return i; } fprintf(stderr, "this gas %s should have been on the cylinder list\nThings will fail now\n", gasname(&mix_in)); return -1; }
void TestUnitConversion::testUnitConversions() { QCOMPARE(IS_FP_SAME(grams_to_lbs(1000), 2.204586), true); QCOMPARE(lbs_to_grams(1), 454); QCOMPARE(IS_FP_SAME(ml_to_cuft(1000), 0.0353147), true); QCOMPARE(IS_FP_SAME(cuft_to_l(1), 28.316847), true); QCOMPARE(IS_FP_SAME(mm_to_feet(1000), 3.280840), true); QCOMPARE(feet_to_mm(1), (long unsigned int) 305); QCOMPARE(to_feet((depth_t){ 1000 }), 3); QCOMPARE(IS_FP_SAME(mkelvin_to_C(647000), 373.85), true); QCOMPARE(IS_FP_SAME(mkelvin_to_F(647000), 704.93), true); QCOMPARE(F_to_mkelvin(704.93), (unsigned long)647000); QCOMPARE(C_to_mkelvin(373.85), (unsigned long)647000); QCOMPARE(IS_FP_SAME(psi_to_bar(14.6959488), 1.01325), true); QCOMPARE(psi_to_mbar(14.6959488), (long)1013); QCOMPARE(to_PSI((pressure_t){ 1013 }), (int)15); QCOMPARE(IS_FP_SAME(bar_to_atm(1.013), 1.0), true); QCOMPARE(IS_FP_SAME(mbar_to_atm(1013), 1.0), true); QCOMPARE(mbar_to_PSI(1013), (int)15); get_units(); }