Much, much smarter way of finding the Tags

The old way manually implemented a parser, where it could simply call a
regexp (or, in my case, a QChar) that will split the QString into many, to
find the beginning and end of the strings on the tags.

This patch also fixes a Qt5 off-by-one bug on the tag Visualization.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dive add: fix crash when canceling

We need to reset the editMode right away, otherwise all the changes to the
input field (when resetting the data after the user cancels) will cause
Subsurface to crash as current_dive will temporarily be NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dive add: remove duplicate code

This is already done when we create the fake dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dive planner: remember the selection before new dives get handled

On an empty dive list we would remember the new dive (which gets
auto-selected since it's the only dive) and then crash when we try to
restore that selection after cancel (in which case that new dive is gone).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dive planner: remove the fake dive earlier on cancel

This way it's already gone from the dive list before it gets reprocessed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Try to clear out the profile when dive list is empty

This only partially works. If I start from an empty dive list, plan a
dive, then abort, there are still leftovers in the profile widget.
Hitting Ctrl-W clears that out. But it just runs the same cleanUpEmpty()
again...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Minor cleanup

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fixes showing the Empty Profile when Add / Plan dive is cancelled.

for some reason the next selected dive is NULL after cancelling the
plan. I'm investigating.

This patch fixes the show of the empty profile and it also untangles
some parts of the code, keeping the mainwindow where it should belong
: the mainwindow.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Dive list: use helper function when restoring selection

Looping over the individual dives will be very slow if there are many of
them, as the profile will try to render each of them in succession.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: prevent crash when canceling plan with existing dive list

There is still something seriously wrong here.
For now let's just not restore the selection and at least this prevents us
from crashing. But I still don't understand why it crashes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: really fix crash after aborting planner

Duh. We had to reload the list (and make sure the internal data structures
are recreated as well) before restoring the selection.

I also switched to simply accessing the widget directly, instead of via
the dive_list() call.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: set up a cylinder, even if no current dive is selected

If there was no current dive we didn't set up any cylinder at all which
was a bit awkward as we use AIR but have no cylinder corresponding to it,
which breaks assumptions elsewhere.

Instead we use either the default cylinder or make one up.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Move code from the Planner that doesn't belongs there.

Moved the connections between DivePlannerPointsModel and
MainWindow from inside the Planner class to the MainWindow.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix crash on adding / removing a dives from add menu

This patch removes some inconsistencies that were happening on the add
dive / cancel actions. a bit of legacy code from the old system was still
in, which made things quite...  EXPLOSIVE.

This fixes restoring the selection only if we have a selection and not
deleting the temporary dive twice.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Fix edition of manually added dives.

This patch correctly sets the state of the planner to "NOTHING"
after trying to edit a manually added dive.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add dive: only copy cylinders when necessary

If the stagingDive is just an alias for the current_dive (as it is in dive
ADD mode), there's no need to copy the cylinders; they are already there.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: make sure stagingDive is reset to NULL

If we first ADD a dive and then PLAN a dive, stagingDive first was an
alias to the current_dive (for ADD) - we need to make sure that when PLAN
is started, a new dive is allocated.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: add missing disclaimer

This may not be the best way to do it, but it's better than just printing
"(null)".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: always recreate staging dive

Instead of even trying to keep one around (which then could cause all
kinds of trouble) we now always delete it at the end of the planner.
So simply always recreate one when starting the planner (and make sure
that the staging dive has always been cleared out, first).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Planner: record the new dive at the correct time

We don't want to do this when calling plan() from createTemporaryPlan() -
we only want to record the dive at the end of createPlan().

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>