Plan: introduce function that returns disclaimer

The setting of the disclaimer variable was removed inadvertently
some time ago, which removed the disclaimer from the printed plan.
Instead, introduce a function that returns the disclaimer with
the current deco mode. Use that function to generate the dive
notes and for printing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-09-10 15:29:03 +02:00 committed by Robert C. Helling
parent 4706b0f11a
commit ee365b7341
3 changed files with 21 additions and 12 deletions

View file

@ -51,6 +51,7 @@ extern int get_gasidx(struct dive *dive, struct gasmix mix);
extern bool diveplan_empty(struct diveplan *diveplan); extern bool diveplan_empty(struct diveplan *diveplan);
extern void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error); extern void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error);
extern const char *get_planner_disclaimer(); extern const char *get_planner_disclaimer();
extern char *get_planner_disclaimer_formatted();
extern void free_dps(struct diveplan *diveplan); extern void free_dps(struct diveplan *diveplan);
extern struct dive *planned_dive; extern struct dive *planned_dive;

View file

@ -82,11 +82,21 @@ const char *get_planner_disclaimer()
"PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE."); "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE.");
} }
/* Returns newly allocated buffer. Must be freed by caller */
char *get_planner_disclaimer_formatted()
{
struct membuffer buf = { 0 };
const char *deco = decoMode() == VPMB ? translate("gettextFromC", "VPM-B")
: translate("gettextFromC", "BUHLMANN");
put_format(&buf, get_planner_disclaimer(), deco);
return detach_buffer(&buf);
}
void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error) void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
{ {
struct membuffer buf = { 0 }; struct membuffer buf = { 0 };
struct membuffer icdbuf = { 0 }; struct membuffer icdbuf = { 0 };
const char *deco, *segmentsymbol; const char *segmentsymbol;
int lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1; int lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1;
struct gasmix lastprintgasmix = gasmix_invalid; struct gasmix lastprintgasmix = gasmix_invalid;
struct divedatapoint *dp = diveplan->dp; struct divedatapoint *dp = diveplan->dp;
@ -106,12 +116,6 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
struct icd_data icdvalues; struct icd_data icdvalues;
char *temp; char *temp;
if (decoMode() == VPMB) {
deco = translate("gettextFromC", "VPM-B");
} else {
deco = translate("gettextFromC", "BUHLMANN");
}
if (!dp) if (!dp)
return; return;
@ -123,9 +127,11 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
} }
if (show_disclaimer) { if (show_disclaimer) {
char *disclaimer = get_planner_disclaimer_formatted();
put_string(&buf, "<div><b>"); put_string(&buf, "<div><b>");
put_format(&buf, get_planner_disclaimer(), deco); put_string(&buf, disclaimer);
put_string(&buf, "</b><br></div>"); put_string(&buf, "</b><br></div>");
free(disclaimer);
} }
if (diveplan->surface_interval < 0) { if (diveplan->surface_interval < 0) {

View file

@ -850,8 +850,10 @@ void MainWindow::updateVariations(QString variations)
void MainWindow::printPlan() void MainWindow::printPlan()
{ {
#ifndef NO_PRINTING #ifndef NO_PRINTING
QString diveplan = plannerDetails->divePlanOutput()->toHtml(); char *disclaimer = get_planner_disclaimer_formatted();
QString withDisclaimer = QString("<img height=50 src=\":subsurface-icon\"> ") + diveplan + QString(disclaimer); QString diveplan = QStringLiteral("<img height=50 src=\":subsurface-icon\"> ") +
QString(disclaimer) + plannerDetails->divePlanOutput()->toHtml();
free(disclaimer);
QPrinter printer; QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this); QPrintDialog *dialog = new QPrintDialog(&printer, this);
@ -885,9 +887,9 @@ void MainWindow::printPlan()
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);
pixmap.save(&buffer, "PNG"); pixmap.save(&buffer, "PNG");
QString profileImage = QString("<img src=\"data:image/png;base64,") + byteArray.toBase64() + "\"/><br><br>"; QString profileImage = QString("<img src=\"data:image/png;base64,") + byteArray.toBase64() + "\"/><br><br>";
withDisclaimer = profileImage + withDisclaimer; diveplan = profileImage + diveplan;
plannerDetails->divePlanOutput()->setHtml(withDisclaimer); plannerDetails->divePlanOutput()->setHtml(diveplan);
plannerDetails->divePlanOutput()->print(&printer); plannerDetails->divePlanOutput()->print(&printer);
plannerDetails->divePlanOutput()->setHtml(displayed_dive.notes); plannerDetails->divePlanOutput()->setHtml(displayed_dive.notes);
#endif #endif