diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-29 23:16:38 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-08-30 09:31:50 -0700 |
commit | 009f47c5dcd5f255aeb24d71f9a7f2e509e533db (patch) | |
tree | e37bfa3e75d7b8f779362313544ce470806d6d47 /desktop-widgets/tab-widgets | |
parent | 98d171630c26709c4f0c3a4bb2d23d50b50b8ed9 (diff) | |
download | subsurface-009f47c5dcd5f255aeb24d71f9a7f2e509e533db.tar.gz |
Desktop: improve recognition of HTML-notes
To recognize HTML-notes the text was scanned for <div> tags. But
apparently the planner notes do not feature such a thing. Therefore
extend recognition of HTML to <table> tags.
Note we can't use the <html> or <span> tags, because these are
*always* produced by the QTextEdit::toHtml() function.
Fixes #2265
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 613398109..5c6e5104c 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -369,11 +369,15 @@ bool MainTab::isEditing() return editMode != NONE; } +static bool isHtml(const QString &s) +{ + return s.contains("<div", Qt::CaseInsensitive) || s.contains("<table", Qt::CaseInsensitive); +} + void MainTab::updateNotes(const struct dive *d) { QString tmp(d->notes); - if (tmp.indexOf("<div") != -1) { - tmp.replace(QString("\n"), QString("<br>")); + if (isHtml(tmp)) { ui.notes->setHtml(tmp); } else { ui.notes->setPlainText(tmp); @@ -881,8 +885,8 @@ void MainTab::on_notes_editingFinished() if (!currentTrip && !current_dive) return; - QString notes = ui.notes->toHtml().indexOf("<div") != -1 ? - ui.notes->toHtml() : ui.notes->toPlainText(); + QString html = ui.notes->toHtml(); + QString notes = isHtml(html) ? html : ui.notes->toPlainText(); if (currentTrip) Command::editTripNotes(currentTrip, notes); |