mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Planner: remove planner disclaimer from old notes
There used to be code to remove the old planner notes when replanning a dive. It used a global variable and seemed rather brittle. Moreover, the place that set the global variable was inadvertently removed. Therefore has been effectively dead code. Reimplement the functionality, but be more robust by considering that the deco-type may have changed: Split the translated disclaimer string in two parts, before and after the "%s" place-holder. Search for these two parts. Remove the disclaimer and everything after the disclaimer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8ac48a96c7
commit
4706b0f11a
3 changed files with 28 additions and 9 deletions
|
@ -1127,11 +1127,24 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
|
|||
QTextDocument notesDocument;
|
||||
notesDocument.setHtml(current_dive->notes);
|
||||
QString oldnotes(notesDocument.toPlainText());
|
||||
int disclaimerPosition = oldnotes.indexOf(disclaimer);
|
||||
if (disclaimerPosition == 0)
|
||||
oldnotes.clear();
|
||||
else if (disclaimerPosition >= 1)
|
||||
oldnotes.truncate(disclaimerPosition-1);
|
||||
QString disclaimer = get_planner_disclaimer();
|
||||
int disclaimerMid = disclaimer.indexOf("%s");
|
||||
QString disclaimerBegin, disclaimerEnd;
|
||||
if (disclaimerMid >= 0) {
|
||||
disclaimerBegin = disclaimer.left(disclaimerMid);
|
||||
disclaimerEnd = disclaimer.mid(disclaimerMid + 2);
|
||||
} else {
|
||||
disclaimerBegin = disclaimer;
|
||||
}
|
||||
int disclaimerPositionStart = oldnotes.indexOf(disclaimerBegin);
|
||||
if (disclaimerPositionStart >= 0) {
|
||||
if (oldnotes.indexOf(disclaimerEnd, disclaimerPositionStart) >= 0) {
|
||||
// We found a disclaimer according to the current locale.
|
||||
// Remove the disclaimer and anything after the disclaimer, because
|
||||
// that's supposedly the old planner notes.
|
||||
oldnotes = oldnotes.left(disclaimerPositionStart);
|
||||
}
|
||||
}
|
||||
// Deal with line breaks
|
||||
oldnotes.replace("\n", "<br>");
|
||||
oldnotes.append(displayed_dive.notes);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue