void DiveLogExportDialog::exportHTMLstatistics(const QString &filename) { QFile file(filename); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); int i = 0; out << "divestat=["; while (stats_yearly != NULL && stats_yearly[i].period) { out << "{"; out << "\"YEAR\":\"" << stats_yearly[i].period << "\","; out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\","; out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\","; out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\","; out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\","; out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\","; out << "\"AVG_DEPTH\":\"" << get_depth_string(stats_yearly[i].avg_depth) << "\","; out << "\"MIN_DEPTH\":\"" << get_depth_string(stats_yearly[i].min_depth) << "\","; out << "\"MAX_DEPTH\":\"" << get_depth_string(stats_yearly[i].max_depth) << "\","; out << "\"AVG_SAC\":\"" << get_volume_string(stats_yearly[i].avg_sac) << "\","; out << "\"MIN_SAC\":\"" << get_volume_string(stats_yearly[i].min_sac) << "\","; out << "\"MAX_SAC\":\"" << get_volume_string(stats_yearly[i].max_sac) << "\","; out << "\"AVG_TEMP\":\"" << QString::number(stats_yearly[i].combined_temp / stats_yearly[i].combined_count, 'f', 1) << "\","; out << "\"MIN_TEMP\":\"" << get_temp_units(stats_yearly[i].min_temp, NULL) << "\","; out << "\"MAX_TEMP\":\"" << get_temp_units(stats_yearly[i].max_temp, NULL) << "\","; out << "},"; i++; } out << "]"; file.close(); }
static void exportHTMLstatistics(const QString filename, struct htmlExportSetting &hes) { QFile file(filename); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); stats_summary_auto_free stats; stats_t total_stats; calculate_stats_summary(&stats, hes.selectedOnly); total_stats.selection_size = 0; total_stats.total_time.seconds = 0; int i = 0; out << "divestat=["; if (hes.yearlyStatistics) { while (stats.stats_yearly != NULL && stats.stats_yearly[i].period) { out << "{"; out << "\"YEAR\":\"" << stats.stats_yearly[i].period << "\","; out << "\"DIVES\":\"" << stats.stats_yearly[i].selection_size << "\","; out << "\"TOTAL_TIME\":\"" << get_dive_duration_string(stats.stats_yearly[i].total_time.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"), gettextFromC::tr("sec"), " ") << "\","; out << "\"AVERAGE_TIME\":\"" << get_minutes(stats.stats_yearly[i].total_time.seconds / stats.stats_yearly[i].selection_size) << "\","; out << "\"SHORTEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].shortest_time.seconds) << "\","; out << "\"LONGEST_TIME\":\"" << get_minutes(stats.stats_yearly[i].longest_time.seconds) << "\","; out << "\"AVG_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].avg_depth) << "\","; out << "\"MIN_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].min_depth) << "\","; out << "\"MAX_DEPTH\":\"" << get_depth_string(stats.stats_yearly[i].max_depth) << "\","; out << "\"AVG_SAC\":\"" << get_volume_string(stats.stats_yearly[i].avg_sac) << "\","; out << "\"MIN_SAC\":\"" << get_volume_string(stats.stats_yearly[i].min_sac) << "\","; out << "\"MAX_SAC\":\"" << get_volume_string(stats.stats_yearly[i].max_sac) << "\","; if (stats.stats_yearly[i].combined_count) { temperature_t avg_temp; avg_temp.mkelvin = stats.stats_yearly[i].combined_temp.mkelvin / stats.stats_yearly[i].combined_count; out << "\"AVG_TEMP\":\"" << get_temperature_string(avg_temp) << "\","; } else { out << "\"AVG_TEMP\":\"0.0\","; } out << "\"MIN_TEMP\":\"" << (stats.stats_yearly[i].min_temp.mkelvin == 0 ? 0 : get_temperature_string(stats.stats_yearly[i].min_temp)) << "\","; out << "\"MAX_TEMP\":\"" << (stats.stats_yearly[i].max_temp.mkelvin == 0 ? 0 : get_temperature_string(stats.stats_yearly[i].max_temp)) << "\","; out << "},"; total_stats.selection_size += stats.stats_yearly[i].selection_size; total_stats.total_time.seconds += stats.stats_yearly[i].total_time.seconds; i++; } exportHTMLstatisticsTotal(out, &total_stats); } out << "]"; file.close(); }
QVariant YearStatisticsItem::data(int column, int role) const { double value; QVariant ret; if (role == Qt::FontRole) { QFont font = defaultModelFont(); font.setBold(stats_interval.is_year); return font; } else if (role != Qt::DisplayRole) { return ret; } switch(column) { case YEAR: if (stats_interval.is_trip) { ret = stats_interval.location; } else { ret = stats_interval.period; } break; case DIVES: ret = stats_interval.selection_size; break; case TOTAL_TIME: ret = get_time_string(stats_interval.total_time.seconds, 0); break; case AVERAGE_TIME: ret = get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size); break; case SHORTEST_TIME: ret = get_minutes(stats_interval.shortest_time.seconds); break; case LONGEST_TIME: ret = get_minutes(stats_interval.longest_time.seconds); break; case AVG_DEPTH: ret = get_depth_string(stats_interval.avg_depth); break; case MIN_DEPTH: ret = get_depth_string(stats_interval.min_depth); break; case MAX_DEPTH: ret = get_depth_string(stats_interval.max_depth); break; case AVG_SAC: ret = get_volume_string(stats_interval.avg_sac); break; case MIN_SAC: ret = get_volume_string(stats_interval.min_sac); break; case MAX_SAC: ret = get_volume_string(stats_interval.max_sac); break; case AVG_TEMP: if (stats_interval.combined_temp && stats_interval.combined_count) { ret = QString::number(stats_interval.combined_temp / stats_interval.combined_count, 'f', 1); } break; case MIN_TEMP: value = get_temp_units(stats_interval.min_temp, NULL); if (value > -100.0) ret = QString::number(value, 'f', 1); break; case MAX_TEMP: value = get_temp_units(stats_interval.max_temp, NULL); if (value > -100.0) ret = QString::number(value, 'f', 1); break; } return ret; }
void draw_note_13(int x, int y, const song_note_t *note, int cursor_pos, int fg, int bg) { int cursor_pos_map[9] = { 0, 2, 4, 5, 7, 8, 10, 11, 12 }; char note_text[16], note_buf[4], vol_buf[4]; char instbuf[4]; get_note_string(note->note, note_buf); get_volume_string(note->volparam, note->voleffect, vol_buf); /* come to think of it, maybe the instrument text should be * created the same way as the volume. */ if (note->instrument) num99tostr(note->instrument, instbuf); else strcpy(instbuf, "\xad\xad"); snprintf(note_text, 16, "%s %s %s %c%02X", note_buf, instbuf, vol_buf, get_effect_char(note->effect), note->param); if (show_default_volumes && note->voleffect == VOLFX_NONE && note->instrument > 0 && NOTE_IS_NOTE(note->note)) { song_sample_t *smp = song_is_instrument_mode() ? csf_translate_keyboard(current_song, song_get_instrument(note->instrument), note->note, NULL) : song_get_sample(note->instrument); if (smp) { /* Modplug-specific hack: volume bit shift */ int n = smp->volume >> 2; note_text[6] = 0xbf; note_text[7] = '0' + n / 10 % 10; note_text[8] = '0' + n / 1 % 10; note_text[9] = 0xc0; } }
QString CylinderObjectHelper::size() const { return get_volume_string(m_cyl->type.size, true); }
void TabDiveStatistics::updateData() { clear(); ui->depthLimits->setMaximum(get_depth_string(stats_selection.max_depth, true)); if (amount_selected > 1) ui->depthLimits->setMinimum(get_depth_string(stats_selection.min_depth, true)); else ui->depthLimits->setMinimum(""); // the overall average depth is really confusing when listed between the // deepest and shallowest dive - let's just not set it // ui->depthLimits->setAverage(get_depth_string(stats_selection.avg_depth, true)); // Also hide the avgIco, so its clear that its not there. ui->depthLimits->overrideAvgToolTipText(""); ui->depthLimits->setAvgVisibility(false); if (stats_selection.max_sac.mliter && (stats_selection.max_sac.mliter != stats_selection.avg_sac.mliter)) ui->sacLimits->setMaximum(get_volume_string(stats_selection.max_sac, true).append(tr("/min"))); else ui->sacLimits->setMaximum(""); if (stats_selection.min_sac.mliter && (stats_selection.min_sac.mliter != stats_selection.avg_sac.mliter)) ui->sacLimits->setMinimum(get_volume_string(stats_selection.min_sac, true).append(tr("/min"))); else ui->sacLimits->setMinimum(""); if (stats_selection.avg_sac.mliter) ui->sacLimits->setAverage(get_volume_string(stats_selection.avg_sac, true).append(tr("/min"))); else ui->sacLimits->setAverage(""); temperature_t temp; temp.mkelvin = stats_selection.max_temp; ui->tempLimits->setMaximum(get_temperature_string(temp, true)); temp.mkelvin = stats_selection.min_temp; ui->tempLimits->setMinimum(get_temperature_string(temp, true)); if (stats_selection.combined_temp && stats_selection.combined_count) { const char *unit; get_temp_units(0, &unit); ui->tempLimits->setAverage(QString("%1%2").arg(stats_selection.combined_temp / stats_selection.combined_count, 0, 'f', 1).arg(unit)); } ui->divesAllText->setText(QString::number(stats_selection.selection_size)); ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ", displayed_dive.dc.divemode == FREEDIVE)); int seconds = stats_selection.total_time.seconds; if (stats_selection.selection_size) seconds /= stats_selection.selection_size; ui->timeLimits->setAverage(get_dive_duration_string(seconds, tr("h"), tr("min"), tr("sec"), " ", displayed_dive.dc.divemode == FREEDIVE)); if (amount_selected > 1) { ui->timeLimits->setMaximum(get_dive_duration_string(stats_selection.longest_time.seconds, tr("h"), tr("min"), tr("sec"), " ", displayed_dive.dc.divemode == FREEDIVE)); ui->timeLimits->setMinimum(get_dive_duration_string(stats_selection.shortest_time.seconds, tr("h"), tr("min"), tr("sec"), " ", displayed_dive.dc.divemode == FREEDIVE)); } else { ui->timeLimits->setMaximum(""); ui->timeLimits->setMinimum(""); } QVector<QPair<QString, int> > gasUsed; QString gasUsedString; volume_t vol; selectedDivesGasUsed(gasUsed); for (int j = 0; j < 20; j++) { if (gasUsed.isEmpty()) break; QPair<QString, int> gasPair = gasUsed.last(); gasUsed.pop_back(); vol.mliter = gasPair.second; gasUsedString.append(gasPair.first).append(": ").append(get_volume_string(vol, true)).append("\n"); } if (!gasUsed.isEmpty()) gasUsedString.append("..."); volume_t o2_tot = {}, he_tot = {}; selected_dives_gas_parts(&o2_tot, &he_tot); /* No need to show the gas mixing information if diving * with pure air, and only display the he / O2 part when * it is used. */ if (he_tot.mliter || o2_tot.mliter) { gasUsedString.append(tr("These gases could be\nmixed from Air and using:\n")); if (he_tot.mliter) { gasUsedString.append(tr("He")); gasUsedString.append(QString(": %1").arg(get_volume_string(he_tot, true))); } if (he_tot.mliter && o2_tot.mliter) gasUsedString.append(" ").append(tr("and")).append(" "); if (o2_tot.mliter) { gasUsedString.append(tr("O₂")); gasUsedString.append(QString(": %2\n").arg(get_volume_string(o2_tot, true))); } } ui->gasConsumption->setText(gasUsedString); }
QVariant CylindersModel::data(const QModelIndex &index, int role) const { QVariant ret; if (!index.isValid() || index.row() >= MAX_CYLINDERS) return ret; cylinder_t *cyl = &displayed_dive.cylinder[index.row()]; switch (role) { case Qt::BackgroundRole: { switch (index.column()) { // mark the cylinder start / end pressure in red if the values // seem implausible case START: case END: if ((cyl->start.mbar && !cyl->end.mbar) || (cyl->end.mbar && cyl->start.mbar <= cyl->end.mbar)) ret = REDORANGE1_HIGH_TRANS; else ret = WHITE1; break; } break; } case Qt::FontRole: { QFont font = defaultModelFont(); switch (index.column()) { case START: font.setItalic(!cyl->start.mbar); break; case END: font.setItalic(!cyl->end.mbar); break; } ret = font; break; } case Qt::TextAlignmentRole: ret = Qt::AlignCenter; break; case Qt::DisplayRole: case Qt::EditRole: switch (index.column()) { case TYPE: ret = QString(cyl->type.description); break; case SIZE: if (cyl->type.size.mliter) ret = get_volume_string(cyl->type.size, true, cyl->type.workingpressure.mbar); break; case WORKINGPRESS: if (cyl->type.workingpressure.mbar) ret = get_pressure_string(cyl->type.workingpressure, true); break; case START: if (cyl->start.mbar) ret = get_pressure_string(cyl->start, true); else if (cyl->sample_start.mbar) ret = get_pressure_string(cyl->sample_start, true); break; case END: if (cyl->end.mbar) ret = get_pressure_string(cyl->end, true); else if (cyl->sample_end.mbar) ret = get_pressure_string(cyl->sample_end, true); break; case O2: ret = percent_string(cyl->gasmix.o2); break; case HE: ret = percent_string(cyl->gasmix.he); break; case DEPTH: ret = get_depth_string(cyl->depth, true); break; } break; case Qt::DecorationRole: if (index.column() == REMOVE) ret = QIcon(":trash"); break; case Qt::ToolTipRole: if (index.column() == REMOVE) ret = tr("Clicking here will remove this cylinder."); break; } return ret; }