In cb80ff746b internal columns
were added to the cylinder model. These were not hidden in
the planner. Nobody complained?
Remove this clutter from the UI by hiding the columns.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The logic did not consider the WORKINGPRESS_INT and SIZE_INT
columns added in cb80ff746b.
By some unknown magic this worked by routing everything
through the CylindersModelFiltered model.
Let's fix it and explicitly ignore these columns. Put
the test whether a column should be ignored in a function
to avoid inconsistencies should new columns be added.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
CCRs are different. It does not make sense to compute
a depth dependent SAC. You could compute the rate of O2
consumption but even that is likely wrong (as O2 in the
diluent would enter that as well), so simply don't attempt
it.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
And while doing that, have all the cases where we already include
qthelper.h simply use a define in that header file - but keep the two
other instances of the define where the C++ source don't need qthelper.h
otherwise.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Qt 6 will drop support for QRegExp.
Use QRegularExpression instead.
The syntax for matches and captures has changed and needed to be
adjusted.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Qt 6 will drop support for QRegExp.
Use QRegularExpression instead.
The syntax for matches has changed and needed to be adjusted.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Qt 6 will drop support for QRegExp.
Use QRegularExpression instead.
The syntax for matches and captures has changed and needed to be
adjusted.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The camera sync feature has been moved above the Ok and Cancel buttons
and given its own descriptive header. The checkbox to ignore unaligned
image timestamps has been moved closer to the buttons.
Signed-off-by: Tim Segers <tsegers@pm.me>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The QTimeEdit field is severely limited when it comes to the supported
time range. By coding our own input / validation we can allow far larger
time shifts. For simplicity, this always assumes hours:minutes format.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When using the camera sync feature to sync media to the dive timeline,
the calculated time difference was considered invalid if it was more
than 24 hours.
To prevent this, this commit disables the manual time offset input
fields when the camera sync button is clicked. It then uses the epoch
difference in the final offset calculation, enabling arbitrary time
differences between camera and divecomputer.
Signed-off-by: Tim Segers <tsegers@pm.me>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This tries to make our fingerprinting code work better, by avoiding
using the "deviceid" field that has always been unreliable because we've
calculated it multiple different ways, and even for the same version of
subsurface, it ends up changing in the middle (ie we calculate one value
initially, then re-calculate it when we have a proper serial number
string).
So instead, the fingerprinting code will look up and save the
fingerprint file using purely "stable" information that is available
early during the download:
- the device model name (which is a string with vendor and product name
separated by a space)
- the DC_EVENT_DEVINFO 32-bit 'serial' number (which is not necessarily
a real serial number at all, but hopefully at least a unique number
for the particular product)
but because the model name is not necessarily a good filename (think
slashes and other possibly invalid characters), we hash that model name
and use the resulting hex number in the fingerprint file name.
This way the fingerprint file is unambiguous at load and save time, and
depends purely on libdivecomputer data.
But because we also need to verify that we have the actual _dive_
associated with that fingerprint, we also need to save the final
deviceid and diveid when saving the fingerprint file, so that when we
load it again we can look up the dive and verify that we have it before
we use the fingerprint data.
To do that, the fingerprint file itself contains not just the
fingerprint data from libdivecomputer, but the last 8 bytes of the file
are the (subsurface) deviceid and the diveid of the dive that is
associated with the fingerprint.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The TabDiveComputer model won't work in the new world order, where you
can't even insert a new device entry without a nickname to be edited.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Commit e42fc1a1e9 introduced a
crash condition. Apparently the code attempts to test whether
the clicked-on item is a top-level dive. The "Collapse others"
menu item should not be shown in that case. It does this by
testing "d->divetrip". However, "d" might quite logically be
null if clicking on an unexpanded trip header.
Therefore, check explicitly for the trip header case (which
should show the menu item) and for good measure prevent
the nullpointer access (that should be caught by testing
for trip, but who knows).
Fixes#3301.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Thus, the membuffer data is automatically freed when going
out of scope - one thing less to worry about.
This fixes one use-after-free bug in uploadDiveLogsDE.cpp
and one extremely questionable practice in divetooltipitem.cpp:
The membuffer was a shared instance across all instances
of the DiveToolTipItem.
Remves unnecessary #include directives in files that didn't
even use membuffer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The changes in commit 4daf687876 ("profile: remove [disable|enable]Shortcuts()
signals") resulted in us no longer enabling the shortcuts on the desktop (at
least on macOS where I debugged this). This placement of the call feels like a
bit of overkill, but at least it shouldn't be wrong.
Fixes#3293
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This variable is not used outside a single function, where it
is reset every time the function runs. This can be realized by
a function-local variable just as well.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This occurs upon importing dives for example via CSV.
Make sure the profile display is cleared when selecting
such a dive rather than showing a different dive.
Allow editing the profile for such a dive.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The ADD state is not used for adding dives since adding dives
was made undoable. Therefore, rename it to EDIT state, since
that is what it is used for.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add numerus translation lookup for the right-click context menu in the dive
list to show proper singular/plural text.
Fixes#3256
Signed-off-by: Mark Stiebel <mark@aretha.stiebel.me>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is adding the capability to select 'Dive number' and 'Date / Time'
in the 'Copy dive components' dialog, and then copy them into the
clipboard.
When using 'Paste dive components, these values will then be pasted into
the selected dive(s).
This is intended to help with workflows that import dive information
from two different sources, like general information from another
logging program, and CCR ppO2 sensor readings from a unit log, and then
stitch them together into one cohesive entry with all data per dive.
Copied data is also output into formatted text when pasting the
clipboard outside of the application:
```
Dive number: 401
Date / time: Sun 2 May 2021 12:00 AM
```
No translations have been added as of now - I could not find any
information on how strings are translated for this project.
Signed-off-by: Michael Keller <github@ike.ch>
We are matching translated header names. Thus, when composing
a header line for APD, make sure it contains translations.
This mechanism is quite brittle. Our German translations had
two different translations for "Sample time" and this already
broke it. This is why this patch also includes a fix for a
translation string (should be fixed in transiflex as well
of course).
Fixes#3246
Signed-off-by: Robert C. Helling <helling@atdotde.de>
When printing the plan, a print-dialog was created with "new",
but not freed later. Strictly speaking, this is not a leak,
because the dialog is attached to the main-window in Qt's
object hierarchy. Thus it is freed on application exit. On
the other hand, it is a leak in the sense that resources are
pointlessly hogged until application exit.
Let's just turn it into a stack-allocated object.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The TeX exports may hang the UI for a long time.
Show a progress-dialog that is updated after every exported dive
and allows the user to cancel the export.
This is pretty lame, because it is synchronous (export still runs
in UI thread) and therefore the UI still is sluggish. But it
is an improvement.
Since the TeX-exporting code is in a shared directory (desktop and
mobile), this uses a slim interface class. Mobile does not
yet use TeX export, but you never know. Better than #ifdefs
sprinkled all around, I reckon.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If QString::isEmpty() is false, QString::isNull() is likewise
false, so these tests are redundant.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When printing, the animation speed was set to 0 by the
caller and later reset to the original value. Instead of
modifying global state, set it internally (in the profile-code)
to zero when in print mode.
This is another small step in making the printing independent
from the shown profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This flag is handled directly by the profile code
since 2015 (000c9cc21c).
The function therefore can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The backend infrastructure will soon be able to support more than one
cloud server which automagically stay in sync with each other.
One critical requirement for that to work is that once a session was
started with one of the servers, the complete session happens with that
server - we must not switch from server to server while doing a git
transaction. To make sure that's the case, we aren't trying to use DNS
tricks to make this load balancing scheme work, but instead try to
determine at program start which server is the best one to use.
Right now this is super simplistic. Two servers, one in the US, one in
Europe. By default we use the European server (most of our users appear
to be in Europe), but if we can figure out that the client is actually
in the Americas, use the US server. We might improve that heuristic over
time, but as a first attempt it seems not entirely bogus.
The way this is implemented is a simple combination of two free
webservices that together appear to give us a very reliable estimate
which continent the user is located on.
api.ipify.org gives us our external IP address
ip-api.com gives us the continent that IP address is on
If any of this fails or takes too long to respond, we simply ignore it
since either server will work. One oddity is that if we decide to change
servers we only change the settings that are stored on disk, not the
runtime preferences. This goes back to the comment above that we have to
avoid changing servers in mid sync.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We know the preference is never empty, so stop testing for this. But
don't maintain two different preferences with basically the same
content. Instead add the '/git' suffix where needed and keep this all in
one place.
Simplify the extraction of the branch name from the cloud URL.
Also a typo fix and a new comment.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When showing the "empty-state", the profile toolbar was
disabled. This was done via a "reverse" signal from the
profile to the MainWindow. Instead control the toolbar
in the MainWindow directly. Break out the plot-dive
functionality into a member function and there test
whether a dive is shown or not.
The signal makes no sense in the context of mobile
or printing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When switching to the "plan" or "add" (which should rather be
called "edit", by the way) mode of the profile, the "shortcuts"
for copy&paste, undo&redo, etc. are disabled. When switching
to "profile" mode, they are reenabled.
This was done in a most convoluted way:
- The MainWindow calls the set*State() function of the profile.
- The Profile emits [disable|enable]Shortcuts() signals.
- The MainWindow catches these signals and does the enabling
or disabling.
Not only is this very hard to reason about, it is also in
contradiction to the profile being part of the display layer.
Moreover, in editCurrentDive() the MainWindow disabled the
shortcuts itself, so this was all redundant.
For the sake of sanity, let's just move this logic to the
MainWindow, unslotify the [disable|enable]Shortcuts() functions
and make them private.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive handlers are only updated by signals. This means that
switching into edit-mode has to be done in steps:
1) initialize the DivePointsPlannerModel
2) switch profile mode
3) load dive into DivePointsPlannerModel
2) and 3) cannot be exchanged, or the dive handlers are not
initialized.
To avoid this sandwitching of profile- and model-initialization,
populate the dive handlers when switching the profile mode.
Thus, the profile can be switched into edit/plan mode when
the DivePointsPlannerModel is fully initialized.
This will be important in upcoming commits, when the initialization
of the dive is moved from the profile to the DivePointsPlannerModel.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only external user of setRecalc() was turning recalculation
on. In fact, this happened when constructing the planner-widget.
However, for example editing of the profile only works when
the recalc flag is on.
This is all very confusing, let's just turn the flag on by
default and remove the accessor. Internally, the planner can
simply use the std::exchange function to set and reset the
recalc flag.
Perhaps the setting/resetting can be replaced by simple
recalc = true;
...
recalc = false;
pairs. It is unclear whether there is need for recursion.
Something to be investigated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
MainTab::updateDiveInfo() is not executed when in the planner.
To decide whether the application is in the planner state,
it queried the profile. Instead, query the DivePlannerPointsModel.
Currently, there is no autoritative carrier of that flag.
However, the MainTab has a dependency on DivePlannerPointsModel
anyway, and therefore this removes a dependency on the
profile. This brings us closer to a state where we can have
multiple profiles.
Ultimately, it is hoped that the whole check can be removed
at this place, making the point moot.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove mainwindow-access from the planner, by setting
the profile to planner state in the owner of the profile,
viz. the MainWindow.
The MainWindow sets the application state to planner, so
it seems legit that it also sets the profile state.
This removes a further interdependency.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The accept / reject message is only shown in edit-mode, no
need to check it. This is a step in simplification / removal
of the edit mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
So far the profile operated on the global displayed_dive. Instead,
take the dive to be displayed as a parameter to the plotDive()
functions.
This is necessary if we want to have multiple concurrent
profile objects. Think for example for printing or for mobile
where multiple dive objects are active at the same time.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To remove global state, make the dive that DivePlannerModel
works on a member variable. Pass the dive in createSimpleDive()
and loadFromDive(). Moreover, this should pave the way to more
fine-grained undo in the planner. Ultimately, the planner
should not be modal.
Attention: for now, the dive must still be displayed_dive,
because of the convoluted way in which the profile and the
planner work on the same dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Both loadFromDive() callers were clearing the model before
calling loadFromDive(). Move the clearing into that function
since it makes no sense to load into a non-cleared model.
Apparently this changes the way that no-cylinder dives are
treated and the code in ProfileWidget2::repositionDiveHandlers()
must now explicitly check for that condition.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This model is only needed when in plan mode. To enable multiple
profilewidgets at the same time (e.g. for the mobile app or
for printing), make the pointer to DivePlannerPointsModel a
member variable that is initialized at construction time.
Moreover, allow passing null as the DivePlannerPointsModel,
in which case planning will be disabled. This will be useful
for simple printing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When clicking on "+" in the planner, a default stop point was
added using a signal/slot connection. This used the archaic
string-based connect syntax, because it was realized with
default parameters passed to "addStop()". Instead, add a
"addDefaultStop()" slot, which passes the default parameters.
Since all other callers do not use callbacks, unslotify
"addStop()". The slot was the only user of the default parameters,
so they can be removed alltogether.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The font-size in printed profiles is based on the size of the profile
in the main window. This makes no sense. Why should changing the
window size change the font-size on printouts?
Matter of fact, when making shrinking the height of the window to
its minimum, comical printouts are obtained (font way too big).
Therefore use an arbitrary rule: Say that profiles 600 pixels high
look reasonable and then scale up to the actual size on the printout.
This may need some tweaking for high-DPI mode. But that seems not
to be supported on desktop anyway?
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Apparently, the visibility flag of the view is not inherited
from the statistics widget. Therefore, the statistics is
redrawn on every action even if not visible.
Set the visibility explicitly in the show- and hide-events.
This is crazy.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The application state is a desktop-only thing. The mobile UI
also has its application state, but that is something completely
different.
The last remaining user of the application state was to flag
whether the planner is active. Since this has all been
unglobalized, the ApplicationState structure can be moved
from core to the desktop UI. And there it can be made local
to the MainWindow class.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The TemplateLayout prints different dives depending on
whether the planner is active. Instead of accessing a
global variable, pass the status down from the MainWindow.
That's all quite convoluted, since there are multiple
layers involved.
On the positive side, the in_planner() function has now
no users an can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Allow the user to restrict the analyzed dives based on the
current selection. One button restricts to the current selection
and one button resets the restriction.
Thus, the user can for example select bars in the bar chart
or a range in the scatter plot and perform statistics on
these sets.
The restriction works on top of the filter.
The UI can certainly be improved, but it is a start.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In TemplateLayout, there was a progress indication, which reported
the progress - not of the actual rendering - but of adding the
dives to the "to render" list. Which is of course done in less than
a ms, making the whole thing completely pointless.
Instead, emit progress when actually looping over the dives or
statistics.
Nobody ever noticed the problem because even rendering is done in
fractions of a second and indeed is accounted to only one fifth
of the total progress.
The real purpose of this "fix" is to get rid of the getTotalWork()
function, which was just insane. Instead of asking the TemplateLayout
how many dives it rendered, this number was extracted from
global state. Simply store the number of dives in the TemplateLayout
object instead.
Moreover, fix two coding style issues:
- "Page" variable identifier starting with a capital
- The Printer::render() being defined (as opposed to declared) with
a default parameter. This is not how C++'s default parameters work,
sorry.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On first startup, use the splitter values suggested by Dirk:
Top/Bottom: 60/40
Info/Profile: 50/50
List/Map: 60/40
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The profile must be replotted when the dive mode changes.
Weirdly, this was routed via the dive-information tab
(making it inherently non-mobile compatible). Detect
such a change directly in the profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On state change, the splitters were completely emptied and
refilled. Instead try to reuse already existing splitter
slots. This reduces annoying flickering.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The MainWindow has a function to replot the profile. Use that
instead of accessing the profile directly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The memory management of the quadrant widgets is a total mess:
When setting the widget, the QSplitters take ownership, which
means that they will delete the widget in their destructor.
This is inherently incompatible with singletons, which must
not be deleted.
To avoid all these troubles, remove the widgets from the
QSplitters in the desctructor of the MainWindow. This of
course means that we now have to take care about deletion
of the widgets.
For local widgets use std::unique_ptr, for singletons use
a static variable that is deleted on application exit.
Sadly, for the map widget we can't use a normal singleton,
because the QML MapWidget's memory management is buggy.
Add a comment in the source code explaining this.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When in planner mode, don't allow the user to change the application
state. This brought us nothing but troubles and inconsistencies.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was the "application state", which decided what to show
in the "quadrants" and the "view state" which decided which
quadrant to show. These interacted in a hard-to-grasp way.
The "view state" is used to show the map or dive list in
full screen.
I simply couldn't get these two orthogonal states to interact
properly. Moreover the thing was buggy: If a quadrant was hidden,
the user could still show it, by dragging from the side of the
window, at least under KDE.
To solve these woes, merge the two states into a single
application state. If the widget of a quadrant is set to null,
don't show it. So the four "view states" are now "application
states" where three of the four quadrants are not shown.
This also changes the memory management of the widgets:
widgets that are not shown are now removed from the QSplitter
objects. This makes it possible that the same widget is
shown in *different* quadrants.
While writing this, I stumbled upon a Qt bug, which is known
since 2014:
https://forum.qt.io/topic/43176/qsplitter-sizes-return-0
When restoring the quadrant sizes there was a test whether
the quadrant size is 0. If that was the case, a default size
was set. This seems not to work if the widgets were recently
added. Since this test now always fails, make the quadrants
non-collapsible and thus guarantee that 0 is never saved as
a size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The way the starting time of a new plan was set was bonkers:
1) PlannerWidgets::planDive() invokes DivePlannerPointsModel::
createSimpleDive().
2) createSimpleDive() calls DivePlannerPointsModel::
setupStartTime()
3) setupStartTime() emits a signal startTimeChanged()
4) startTimeChanged is caught by PlannerWidget and sets
the UI field
5) change of the UI field emits a timeChanged() signal which
is connected to DivePlannerPointsModel::setStartTime()
6) setStartTime() sets the time of the plan and displayed_dive
and emits dataChanged()
7) dataChanged() replots the dive()
8) Back in DivePlannerPointsModel::createSimpleDive() the diveplan
start time is overwritten with displayed_dive (the value are
equal owing to 6)
Wow!
But it gets worse:
9) The initial dive plan is set up in createSimpleDive().
Since the profile is drawn in 7) after clearing the displayed_dive
and before constructing the initial plan, the profile is shown
on a dive without samples. It therefore generates a dummy profile.
To make this somewhat less insane, remove the startTimeChanged()
signal in 3), explicitly set the start time of plan and dive to
the one calculated by setupStartTime() and explicitly set the UI
filed in the plannerWidget.
This still indirectly draws the profile via signals in a convoluted
way, but at it straightens out things somewhat. Most importantly,
the profile doesn't have to generate a fake DC.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Up to now, when the user changed the visibility of chart features
(legend, quartiles, labels, etc.) the whole chart was replot.
Instead, only change the visibility status of these items.
After all, this modularity is one of the things the conversion
to QSG was all about.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Turn the background grid into QSGNodes. Each grid line is
represented by a QSG line item. An alternative would be
drawing the grid into a QImage and blasting that onto the
screen. It is unclear which one is preferred.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Adds fields to the advanced preferences page to modify GFLow and GFHigh for
the Buhlmann decompression model for calculating ceilings. Updated preferences
code to set the Buhlmann parameters in core/deco.c when the GF prefs are
updated.
Signed-off-by: Doug Junkins <douglas.junkins@gmail.com>
When creating the RenumberDive undo command, the MainTab
would manually call invalidate_dive_cache(). However, this
is done on undo/redo, therefore the call can (should) be
removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Checking a field that we intentionally don't store to disk is obviously
wrong. It's been this way for a long time and it has annoyed me many
times, but somehow I never spent the time to track down why this was
happening.
It makes much more sense to use the presence of either the don't check
flag or a next check date as an indication that we have already asked
this question.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It seems to make more sense to have it there with the 'Yearly Statistics'
and not in the Log menu. Interestingly enough, both locations were clearly
considered when first adding this in commit 106f7a8e0e ("desktop: add
statistics widget dummy and application state") as you can tell by the
never implemented actionViewStats.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
We now have three different things that are kinda like statistics:
- the summary tab (reasonably useful when looking at selected dives)
- the yearly statistics (Ctrl/CMD-Y)
- the full statistics (Ctrl/CMD-T)
I'd argue that's at least one too many. But I'm sure some people will disagree.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The old ways was to select the chart first, then depending on
the chart choose the binning.
Willem says that it should work the other way round: select
the binning (or operation) and make the charts depend on
that.
I'm not arguing one way or the other, just note that the new
way is much more tricky, because it is easy to get unsupported
combinations. For example, there is no chart where the
first variable is unbinned, but the second axis is binned
or has an operation. This makes things distinctly more tricky
and this code still needs a thorough audit.
Since this is all more tricky, implement a "invalid" chart
state. Ideally that should be never shown to the user, but
let's try to be defensive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a new "statistics" application state. In the statistics state
show the statistics widget and the filter in the top quadrants.
The idea is to allow filtering and doing statistics at the same
time.
Sadly, we can't use the filter-widget in different quadrants,
because Qt's ownership model is completely broken / inflexible.
It does not support a widget having different parents and
thus a widget can only belong to one QStackedWidget.
Hiding the map in the statistics view is quite hacky:
Since the view of the quadrants is not determined by the
"ApplicationState", we have to restore the original quadrant
visibility when exiting the stats mode. Therefore, set the
original visibility-state when changing application state.
The MainWindow-quadrant code really needs to be rewritten!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement a widget that shows the statistics state as comboboxes
and the statistics chart. Calls into the statistics code if any
of the comboboxes changes.
The hardest part here is the formatting of the charts list with
its icons and with headings. Sadly, it is not trivial to arrange
icons horizontally. Therefore we would have to fully reimplement
the ComboBox view, which is probably not fun.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was not used anywhere. Moreover, remove a few
unused includes from qthelper.h. Surprisingly, a number of users
of qthelper.h depend on these, so readd them at the appropriate
places.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
With the removal of grantlee, this became pointless glue
code. Call the formatting functions directly.
Since the printing code was the only user of CylinderObjectHelper,
remove the whole thing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
At this point (post grantlee), DiveObjectHelper is just pointless
glue code. Let's remove it from the printing code and call the
formatting functions directly. If necessary, move these functions
to core/string-format.cpp.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was a weird helper object, needed for grantlee. Instead
of storing this object, loop over cylinders and dives directly.
The actual accessor function is unchanged and now generates
a DiveObjectHelper or DiveCylinderHelper for every variable
access. Obviously, this is very inefficient. However, this
will be replaced in future commits by direct calls to formatting
functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
QPointer is a strange "smart" pointer class, which resets itself
when the pointed-to QObject is deleted. It does this by listening
to the corresponding signal and therefore is surprisingly heavy
for a plain pointer. A cynic would say that the existence of
QPointer is an expression of Qt's broken ownership model.
In any case, QPointer was only used at two places, were it was
100% useless: As a parameter to a function and as a locally scoped
pointer. It only makes sense if
a) there is a chance that the object disappears during the pointer's
lifetime and
b) it is actually checked for null before use
None of which was the case here. Remove.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a wrapper around "stats *" used to pass statistics
through Qt's weird metatype system. Not needed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The loop code was buggy: the current position was only increased
inside when executing the loop once. This would obviously fail
for empty lists. Moreover, the whole thing was quite difficult
to reason about, since a reference to the current position was
passed down in the call hierarchy.
Instead, pass from and to values to the parse function and
create a generic function that can search for the end of
loop and if blocks. This function handles nested if and for
loops.
The if-code now formats the block only if the condition is true.
The old code would format the block and throw it away if not
needed.
This should now provide better diagnostics for mismatched tags.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
An artifact from the old grantlee code: the whole parser state
was kept in an untyped QVariant map. One case was particularly
bizarre: the options were a class member and yet added to the
weird map.
Replace this by a strongly typed state structure. Ultimately,
this will allow us to replace the "dive object helper".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These two structs describe options used during printing.
They are passed through numerous classes as pointer. In this
case, reference semantics are preferred, as references:
- can never be null
- can not change during their lifetime
This not only helps the compiler, as it can optimize away null
checks, but also your fellow coder. Moreover, it prevents
unintentional creation of uninitialized references: one can't
create an instance of a class without initializing a reference
member. It does not prevent references from going dangling.
However, pointers have the same disadvantage.
Contains a few whitespace cleanups.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A user complained about the default cylinders list. Provide
a preferences option to turn this off.
When changing the preferences, the tank-info model will be
completely rebuilt. Currently, this is a bit crude as this
will be done for any preferences change.
Suggested-by: Adolph Weidanz <weidanz.adolph@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a tank info with an empty name. According to a comment,
this is needed for the "no cylinder" case. However, we now support
empty cylinder tables, so this is not needed anymore. Therefore,
remove it.
Make sure that the user can still enter the empty name, just in
case. But don't save the size and pressure in that case.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There seems to be no point to saving data to the tank with
the empty name. Don't save tank-pressure and size to that
tank info.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The list of known tank types were kept in a fixed size table.
Instead, use a dynamic table with our horrendous table macros.
This is more flexible and sensible.
While doing this, clean up the TankInfoModel, which was leaking
memory.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The mainwindow was connecting preferences changes to the profile.
Do this directly in the profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These are the small dots that describe dragable points on
the profile when in the planner. It makes no sense to have
them in desktop's planner-widget code. They belong to the
profile.
Therefore, move the code there and compile on mobile.
Not everything can be compiled on mobile for now, but it
is a start.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function, which removes the handlers from the profile, was called
in setAddState() but not in setPlanState(). In the latter case it was
called explicitly by the caller.
Move the call from the caller into the function. This allows us to
make clearHandlers() private in to the profile widget.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Around 2015 there was a push to move planner UI code from
mainwindow.cpp to diveplanner.cpp. That never was completed,
presumably because the planner is actually three widgets.
Collect these widgets in one PlannerWidgets class and move
the code there.
This is not a full dis-entanglement, as the plannerwidgets
have to access the profile via the mainwindow. But at least
it collects the planner UI code at a single place.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the list view two functions were still manually collecting
the selected dives. Use getDiveSelection() there as well.
Careful: that means that the check for dives that are already
outside of a trip now has to be done in the RemoveDivesFromTrip
command.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The main window called a function to init the header actions
(i.e. the context menu) of the dive-list. There is no reason why
this shouldn't be done in the constructor of the dive list, since
it only accesses the QSettings, which are available at application
startup. This improves modularity of the code (by a tiny, tiny bit).
Moreover, the initialization function was at the same time the
header-reloading function. That function can now be folded
into the settings-changed function, since that is the only
remaining user.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Weirdly, the settingsChanged() signal of the dialog-pages was
connected() to the settingsChanged() signal of the dialog
every time the settings were accepted. Do it only once
in the constructor.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was called when opening the preferences dialog
to update all the pages with the current preferences.
For unknown reasons it also removed / readded all the pages.
Remove that code and use the now leaner function when refreshing
the pages.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
After each addition of a page in the constructor, the list was
resorted. This appears pointless. Instead, sort the list only
after all pages were added.
Since the add-page function is now a single line, remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
So far, the PreferencesDialog emitted a settingsChanged signal.
This meant that models that listened to that signal had to
conditionally compile out the code for mobile or the connection
had to be made in MainWindow.
Instead, introduce a global signal that does this and move
the connects to the listeners to remove inter-dependencies.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These did not appear in our templates. With this commit,
there are two lists to iterate over, cylinders and
cylinderObjects:
cylinders has just one property: description which is a string
summarizing cylinder information
cylinderObjects has the individual properties addresable
This also fixes a bug when the iterator variable did not
have the singular name of the list it iterates over.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This used to reload the completion models. Moreover, remove two
obsolete member-function declarations.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of programatically reload the completion models, listen
to the relevant signals in the models. To that goal, derive all
the models from a base class.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the main-tab, when changing tag, buddy or divemaster,
update the corresponding completion model.
This is a quick-fix and the wrong thing to do. It works only
if the currently shown dive is changed, which is not a given.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DPI value in the print_options structure was never initialized.
This could lead to random DPI values and crashes. How this ever
worked is a mystery.
Therefore, read and write the DPI value from the settings just
as the other print-options. And initialize the corresponding dialog
widget to this value.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When constructing an action, '&' is used as the keyboard shortcut
marker. Since this mangles preset names, use the setIconText()
function of the action instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Qt's memory management scheme is completely broken and messes
with common expectations.
QObjects are organized as a tree. The children are destroyed
in the destructor of QObject. This means that they are destructed
after the destructor of the parent object has run and its
sub-object were destructed. Obviously, this makes no sense as
the child objects should be able to access their parent at
any time.
To restore the commonly expected deterministic order of
construction and destruction, one might simply do away with
Qt's silly object tree and organise things using classical
subobjects. However, that breaks with the Qt-generated UI
classes: The objects generated by these classes are *not*
destructed with the UI class. Instead, they are attached
to the widget's QObject tree. Thus these are again destructed
*after* the widget! Who comes up with such a scheme?
In our case this means that we cannot have models used for
TableViews as subobjects, because the TableView needs the
model to save the column widths in the destructor. Which,
as detailed above is called *after* the desctructor of the
widget! Thus, turn these models into heap-allocated objects
and add them to the QObject tree.
Funilly, this exposes another insanity of Qt's QObject tree:
Children are destructed in order of construction! One would
expect that if objects are constructed in the sequence
A, B, C one can expect that C can, at any time, access B and A.
Not so in Qt: The destruction order is likewise A, B, C!
Thus, take care to init the widgets before the model. Jeez.
Finally, print a warning in the column-saving code of
TableWidget, so that these kind of subtleties are caught
in the future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The custom TableView widget saves the table width on destruction.
For that, it uses the "objectName()". Since the table of the
DiveComputerTab was simply called "table" in the UI file, the
widths were saved in that generic section. To avoid future
name-conflicts, rename the widget to "devices".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was just ugly: the column with the "trash" symbol and the
name had the same size. On creation of the object, make the last
column expand and adapt the size of the "trash" column according
to its content.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Because of subsequent changes there is no clean way to just revert the changes
introduced in commit 8b36cf1051 ("desktop: offer different colors for info tab
titles"), so this manually removes the parts we don't need anymore.
This also restores a tooltip value that was inadvertantly removed in that
commit.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The preference setting seemed far too strange to do this. And not very user
friendly. So instead we figure out if this is a dark theme or not by looking at
text and background colors in the palette, and make sure we get notified if
that changes.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of doing it just for the Information tab, do it for all of the tabs.
There's still room for improvement. But this certainly feels more consistent.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Adding a new virtual function to all of these classes may seem like overkill,
but of course the idea is that likely we'd allow similar changes to all of
them.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Add a preference option to set the color of the text on the information tab to
either MediumBlue, LightBlue or Black. The last two of these colors are meant
to enable areadable font contrast on displays with dark mode.
The choice is saved with the other preferences.
[Dirk Hohndel: this isn't really about dark mode, so changed many of the types
and variable names, changed the user visible texts, and
addressed some whitespace issues]
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There was no "title" property on the dive computer table which
was causing an default label of "GroupBox" to appear above the
table. Added a title property to clean up the UI.
Signed-off-by: Doug Junkins <junkins@foghead.com>
Removed the style change to force a style change for the labels on
the dive information page to Medium Blue. This makes labels more
readable in MacOSX dark mode since the default style changes colors
when the mode is shifted from light to dark or vice versa.
Signed-off-by: Doug Junkins <junkins@foghead.com>
This is its only user and the widget is scheduled for removal.
Let's move it there temporarilly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Let's simply forward declare the needed structures.
Also removes removes two more unnecessary includes.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Annoyingly, the replacement has only been available since Qt 5.14.
To make the code less messy, implement our own stdToQt conversion helper.
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is slightly different from the previous cleanup around QFlag use as this
one is related to QtWebKit flags. But the logic is the same.
Just syntax to avoid a warning.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
For multiple-choice constraints we use a bit field of type
uint64_t. This means we theoretically support up to 64 items.
Currently use at most seven.
Coverity complained (correctly) that we use the expression
"1 << x" to generate the bitfields. However 1 is a 32-bit
literal on most platforms, which makes this undefined
behavior for x >= 32. Change the integer literal to 64-bit
1ULL.
Moreover, when detecting items with an index >= 64, don't
even attempt to set the according bit, since this is
undefined behavior and the compiler is free to do as it
pleases in such a case.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function
1) was misnamed: it determined the time of the first selcted dive.
2) had only one caller.
3) would crash if there was no selected dive.
Let's just fold the functionality into the caller. It's a one-liner
anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was used to unify both methods of tracking unsaved
changes. Since desktop now only uses the undo system, it can
be replaced by a single call to "Command::setClean()".
Arguably, the UI is the wrong place to do this and the appropriate
calls should be done by the core. However, let's play it safe
for now and avoid any breaking change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was used to unify both methods of checking for
unsaved changes: the global unsaved_changes() flag and the
Command::clean() function of the undo-system.
However, all desktop functions are now undoable and therefore
the function is not needed and can be replaced by calls
to !Command::clean().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of modifying the device table directly, call the undo
commands. Moreover, don't keep our own copy in the mode - show
the original version. Connect to the appropriate signals.
This means that the calls from the DiveComputerManagement
dialog have to be removed, since this mode of editing is
not supported. The whole dialog will be removed in a future
commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If we want to include dive computer names in the undo system,
there should be visual feedback on undo/redo.
This would mean opening the divecomputer dialog, which would
appear quite strange. Therefore, add a tab. This is not ideal,
but consistent with the dive site tab, which probably shouldn't
be there either. In the future, the UI needs some rethinking.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a device_table parameters to Command::importTable() and
add_imported_dives(). The content of this table will be added
to the global device list (respectively removed on undo).
This is currently a no-op, as the parser doesn't yet fill
out the device table, but adds devices directly to the global
device table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If we want to avoid the parsers to directly modify global data,
we have to provide a device_table to parse into. This adds such
a state and the corresponding function parameters. However,
for now this is unused.
Adding new parameters is very painful and this commit shows that
we urgently need a "struct divelog" collecting all those tables!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The interaction of Qt's drag & drop with GroupedLineEdit was
exceedingly weird. The user was able to scroll the viewport
making the text invisible.
This implements a very primitive alternative drag & drop
functionality: dropped text is regarged as a distinct tag.
This means that it is not possible to modify existing tags
by dropping in the middle of them. Arguably, this might even
be better than arbitrary drag & drop. But even if not perfect,
this fixes a very nasty UI behavior.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If the user manages to "scroll" through the QPlainTextEdit by
a drag&drop action, the state of the widget becomes inconsistent.
On the one hand, the text-block says that it has one line.
On the other hand, its layout says that it has no line.
When trying to fetch the line, a crash occurs.
Try to detect such a strange state and return early in
GroupedLineEdit::paintEvent().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When importing dive-sites we would add to the global filter-preset
table. This data should be thrown away, just like the other tables
that might be imported.
This shows that we really should introduce a "struct divelog",
which collects all those tables into a single structure.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We used a typedef "filter_preset_table_t" for the filter preset table,
because it is a "std::vector<filter_preset>". However, that is in
contrast to all the other global tables (dives, trips, sites) that we
have.
Therefore, turn this into a standard struct, which simply inherits
from "std::vector<filter_preset>". Note that while inheriting from
std::vector<> is generally not recommended, it is not a problem
here, because we don't modify it in any shape or form.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a small proxy-model on top of DiveComputerModel so that clicking
on table headers makes the table sortable.
The UI feature here is not as important as the fact that the UI does
its own sorting and we can keep the device-table in the core sorted
differently.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These are no longer needed. What is still missing is removing Grantlee from the
various build systems.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is a first step of an efford to get rid of the Grantlee dependency. This
implements template processing for those constructs used in our divelist and
statistics printing templates.
It implements a template parser for loops over dives, cylinders and year and
variable replacement. As the previous Grantlee code, it does not really use
Qt's QObject introspection capabilities but reuses the old long chain of
if-else-statements.
The grantlee code is not yet removed.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The pointer-to-member-function version is compile-time checked
and therefore less risky with respect to refactoring.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the filter the dropdown lists for selecting dive mode or day-of-week
has a lot of white space at the bottom. This PR removes that white space.
Actually the white space at the bottom of a QListWidget appears to
be a known bug (actually an omission) for the current Qt V15. The above
solution is a brute-force workaround to achieve the same end result.
The active line is actually the setFixedSize(). The other line, however,
comprises good QT layout policy to minimise widget size.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
In OstcFirmwareCheck::saveOstcFirmware() we find the connect() call
connect(dialog, SIGNAL(finished(int)), config, SLOT(dc_close()));
whereby "config" is of the type "ConfigureDiveComputer".
However, the function signature of ConfigureDiveComputer::dc_close
reads as
void dc_close(device_data_t *data);
and indeed "data" is accessed inside the function. I don't understand
how this doesn't crash, but clearly something is amiss.
Let's remove that connect statement.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Using non-sensical depth and times for segments in the planner may
lead to an unresponsive UI. Therefore limit depth to 1000 m/3300 ft
and time to 100 h. Limiting of depth is done in settingsChanged()
since it has to adapt to the user changig their preferred units.
Fixes#2762.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
getDiveSelection() returns a vector of the selected dives.
Use that instead of looping over the dive table and checking
manually.
This removes a few lines of code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The UI only allowed adding dives to trips above or below the
current dive (and even that is buggy). This is a strange
restriction, since trips are designed to be non-contiguous.
Allow adding dives to any trip using the new trip selection
dialog. The undo-command is already there, so only little
code to write.
This feature was requested on the mailing list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A simple dialog to select a trip. Simply fill a QListWidget without
the model/view rigmarole. So much less painful! Of course that means
that the dialog has to be regenerated everytime it is used.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the dive list we have horrible code, which intercepts all events
to save the selection before/after the event. This was necessary
because we couldn't get Qt's selection data flow under control.
This means intercepting all events that can change the selection.
The page-up, page-down, home and end keys were forgotten. Add these
cases.
Fixes#2957.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The name "FilterWidget2" is historical and has no meaning anymore,
since the current version has little to nothing to do with the
"second" version of the widget.
Rename the class and source files accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When loading a stored filter set, we would get numerous
constraintChanged signals, which caused filter recalculations.
Use the ignoreSignal flag to prevent these.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing the filter, the modified flag is set and shown to the
user. After saving / loading / clearing the filter, the flag is
reset. This simulates (probably badly) a usual load/save interface.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This provides some visual feedback on the currently selected preset.
Update when changing selection or clearing the filter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The goal here is to let the user edit already existing sets and
save them using their old name. This is a stop-gap measure until
we get a proper filter-set editing interface.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When importing a divelog, import filter presets. If there are
equal names, import only if the presets differ. In that case,
disambiguate the name. This made things a bit more complicated,
as comparison of filter presets had to be implemented.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The filter widget was caching whether the filter was active and
used that flag to calculate the "# dives shown" string. Move this
directly to the DiveFilter class to remove interdependencies and
to unify with mobile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Thus, the user can easily overwrite already existing settings.
Not perfect, but the easy solution for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.
Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a table view that shows all presets and a button to delete
old presets. When clicking on an item, load the preset.
When the filter is reset, deselect any item.
Change the preset-loading code: instead of simply loading the
preset, select the preset in the table. Thus, it will be loaded
implicitly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a button to the filter preset widget that allows the
user to load a previously saved filter preset.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dialog asks the user for a name and warns if the name
already exists, i.e. an old filter preset will be overwritten.
Possibly, this should contain an auto-completion facility in
the case that the user wants to overwrite old presets.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the static filterwidget with a list of filterconstraints.
The first attempt of using a table widget failed, because Qt's
table delegates are dysfunctional. It's not that they are bad, they
just don't work at all.
Therefore, this code "simulates" a table in that on addition / deletion
of constraints it keeps track of the rows of all constraints so
that each constraint-widget can be associated with a row of the
constraint model.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This add a widget that represents a single filter constraint. Since
filter constraints are very general, the widget has to consider a
number of cases:
- numerical ranges
- star-widget ranges
- string lists
- multiple choice lists
Moreover, it supports units, which must be updated when the preferences
change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The water type strings were static and therefore passed through
gettextFromC::tr() before main(). One would hope to get a warning
in such a case, but this is not the case.
Therefore, use the QT_TRANSLATE_NOOP macro to register the strings
in Qt's translation system and translate the list when needed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If we set the size on the QPushButton, the button no longer receives any input
(tested on macOS). With this change we get an odd visual artifact when clicking
on the 'add' button, but it least it works, so this is good enough for the next
release.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The SAC factor is only used for minimal gas calculations which
don't make sense in the CCR context.
Additionally, make bailout stop for at least minimum switch
time or problem solving time.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This functionality never came to be and there are fundamentally
different plans floating around. Therefore, remove these empty
files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
User request: when entering a cylinder type, do a substring
search. For example, when entering "100" also find "AL100".
Currently, a starts-with search was used.
This is simply done by setting the "filterMode" of the
ComboBoxDelegate to "Qt::MatchContains".
Suggested-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When planning a dive, dc_number was set to 1, which actually is
the second dc! The code seems to handle this gracefully, however
it appears weird. Let's set dc_number to 0 instead.
Originally, the assignment was introduced in a422957cd6
and moved later in 4f5621c4c6.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of getting the index and using that to access values, use
the taxonomy_get_value() helper function. Two places are affected:
1) reverse geo-lookup
2) location filter delegate
The behavior of reverse geo-lookup is changed slightly: now an
empty string is likewise recognized as missing "TC_ADMIN_L3".
Before, only a missing category was interpreted as such.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Some remote dive sites have no populated places (towns, cities)
nearby. For such sites, we now fall back to looking up
unpopulated place names, such as the reef or island name.
Also some code refactorisation:
the actual network access is now encapsulated in its own
function removing some duplicated code handling in the
reverseGeoLookup function and making it more readable.
Furthermore, reverseGeoLookup() was completely refactored as
most of its functionality was due to legacy requirements; the
current code-base only calls this function from a single
location and only with an empty taxonomy_data object. This
makes the function more focussed and much simpler and more
readable.
Finally, a resource leak in reverseGeocde introduced in
4f3b26f9b6 was fixed.
Signed-off-by: Michael Werle <micha@michaelwerle.com>
When plotting the profile in higher resolution for export,
increase the icon size in the same way.
This is commented out for the mobile version as that
uses printMode for profile display.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The way we export the profile image (as direct export but
also used for printing) is that we render the profile
from the screen to a Pixmap and save that to a file. Unfortunately
this results in very bad resultion and a blurred image.
This is an attempt to improve that situation but it's still far
from perfect: Rather than a QPixmap and grab, I now use a QImage
(where I can set the size) and render, and indeed the picture resolution
(when vied at fixed size) get's better this way. The disadvantage
is that icons get smaller at the same rate und so
there is a natural limit on how big we can get. Maybe somebody
with better Qt knowledge can take off from here. In my opinion
this is already a step in the right direction.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
You need a better resolution to plot a picture with high resolution...
Connection done with a lambda expression thanks to @dirkhh.
Signed-off-by: Robert C. Helling <helling@atdotde.de> (+1 squashed commit)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If a user exits the LocationInformationWidget (Edit Dive Site)
while a reverseGeocode lookup is in progress, the object's
diveSite variable is set to null.
When the reverseGeocode lookup completes, this variable is
dereferenced causing an application crash.
Signed-off-by: Michael Werle <micha@michaelwerle.com>
When the dive has no explicity salinity, our conversion
between pressure and depth assumed salt water. Make this
explicity by using the corresponding macro.
When the planner starts and no salinity is set explicity,
set the water type chooser to salt water to reflect
our default assumption.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Most (all?) BLE dive computers actually don't need to be paired, and some
apparently can't be paired. So let's not enforce that.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This function was globalized in be462ae1a6 to be used for the calender
widget, but that never came to be. Therefore, for now unglobalize it
until it is needed. That said, there probably is a helper function to
turn pictures into gray-scale.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is no reason that this dialog is a singleton. Since it is modal,
it can be created on demand. Apart from removing superfluous global state,
this simplifies code, because preparing the widget can now be done in
the constructor instead of overriding the showEvent() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is no reason that this dialog is a singleton. Since it is modal,
it can be created on demand. This simplifies code, because the mode
(selected-only or all-dives) can be set in the constructor.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Use C-style function definitions (squirly brackets on new lines) and
remove empty lines at end of file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The salinity value was not displayed with localized thousands separators.
E.g. to a user of a German locale the density read as slightly over
1 g/l, when it should be approximately 1000 g/l. For consistency, also
localize that value.
Also localize the CNS and OTU numbers, even though these should
(hopefully!) never come with thousands separators.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In analogy to the timestamp -> QDateTime conversion, create a
common function.
1) For symmetry with the opposite conversion.
2) To remove numerous inconsistencies.
3) To remove use of the deprecated QDateTime::toTime_t() function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move this function from maintab.cpp to qthelper.cpp. Since the
functionality was used in numerous places, use the helper function
there as well. This removes a number of inconsistencies. For example,
sometime setTimeSpec(Qt::UTC) was called, even though the
QDateTime object was already created with that time spec.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was more painful than expected, because we get the "preferences"
changed signal too early when the user switches to system format.
The correct format is set by the preferences-widget, not the preferences
subsystem.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When switching to system defaults, refresh the fields in the preferences
UI so that the user can tell how the fields will be formatted.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was an old "optimization" to avoid double plotting of the
pictures, first by the profile itself, then by the picture tab.
Since the profile now updates the pictures itself, this must
be removed: The picture tab doesn't do it anymore.
Fixes#2833
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was still using the archaic macro version, because Qt decided
to parameter-overload the signals (which turned out to be a horrible
idea). However, since we switched to fairly recent Qt this can be
solved using the qOverload template.
In this case things are a bit more complicated because we overload
the corresponding slots. Since we have control over that, let's
just disambiguate their names instead of using the cryptic qOverload.
While doing this, tighten the access specifiers of the slots. Turn
public into private and protected as appropriate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is no point in calling these functions directly, so we can
just make them private. Morover, add override specifiers were they
were missing and remove a pointless default parameter to the
testActivation() function. It was not used anywhere.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We put the pointer and reference modifier to the variable, not the
type. Some people don't like this, but
1) This is consistent with the rest of the code base.
2) This is how C and C++ parse, love it or hate it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This fixes a rather subtle bug.
In btdiscovery.cpp we are detecting dive computers based on their BT name and
are setting up product+vendor as the key for that lookup. QMap always uses case
sensitive comparisons and a tiny inconsistency snuck into our code.
libdivecomputer names for the Aqualung dive computers i200C / i300C / i550C end
in an upper case C (as matches the official branding), but in btdiscovery.cpp
we have those names with lower case c. And therefore didn't recognize these
dive computers.
Obviously this is easy to fix by fixing those three strings, but I decided that
it was silly to set ourselves up for similar oversights in the future. So
instead I switched the matching of the descriptor to simply be allways all
lower case.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Number 3 overall committer with currently 9% of total commits and 27% of all
commits in the last three years.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The tags of the dive site were shown/hidden when changing the
current dive.
Thus the following could happen:
1) User changes to dive with no tags. Tags are hidden.
2) User add image, which creates GPS tag
3) Tag is updated but not shown.
Fix this by showing/hiding tags when they are calculated not
when switching the dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is completely irrelevant, however out of principle,
let's free the tab-widgets at the end of the application.
To do so, use Qt's object hierarchy. I'm not a fan of this
kind of memory management, but it is how it is.
Moreover, remove the explicit constructor of MainTab, since
it doesn't differ from the default constructor anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Clearing displayed_dive here makes no sense for two reasons:
1) This is only called on startup, when displayed_dive is not
yet initialized.
2) The tab-widgets don't use displayed_dive anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The old code used displayed_dive. However, virtually all the
displayed data is now derived from current_dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Since the displayed data is extracted from current_dive it makes no
sense to query displayed_dive for the dive mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
If current_dive was not set, the code would clear the tabs
right after updating the data. We might just as well set the
data only if current_dive is set.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This used the displayed_dive object. However, we now use current_dive
to designate the currently displayed dive. Thus, use this instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This should have been converted a long time ago.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The goal here is to remove a dependency on displayed_dive.
While doing so, make the model more general and display any dc.
Pass in the dc of the current dive instead of displayed dive,
since all other tabs are already converted to show data of
the current dive. The QStrings are cached since we generate
them anyway, so we may just keep them. Thus, there is no
danger of the dc becoming invalid.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To reset the core data structures, the mobile and desktop UIs
were calling into the dive-list models, which then reset the
core data structures, themselves and the unrelated
locationinformation model. The UI code then reset various other
things, such as the TankInformation model or the map. . This was
unsatisfying from a control-flow perspective, as the models should
display the core data, not act on it. Moreover, this meant lots
of intricate intermodule-dependencies.
Thus, straighten up the control flow: give the C core the
possibility to send a "all data reset" event. And do that
in those functions that reset the core data structures.
Let each module react to this event by itself. This removes
inter-module dependencies. For example, the MainWindow now
doesn't have to reset the TankInfoModel or the MapWidget.
Then, to reset the core data structures, let the UI code
simply directly call the respective core functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one is a bit hairy, because two things might happen if the
picture has a geo location:
- A dive gets a newly generated dive site set.
- The dive site of a dive is edited.
Therefore the undo command has to store keep track of that.
Oh my.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If we want to make addition of pictures undoable, then create_picture()
must not add directly to the dive. Instead, return the dive to which the
picture should be added and let the caller perform the addition.
This means that the picture-test has to be adapted.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The code is rather complex. Firstly, we have different representations
of pictures throughout the code. Secondly, this tries to do add the
pictures in batches to the divepicture model and that is always rather
tricky.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
An empty class that was not used anywhere. This allows us to
remove a few include files as well.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
TabDivePhotos::saveSubtitles() had an unused local variable.
Clearly a copy&paste oversight.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It makes no sense to have the view in item-selection mode, since
each picture represents a row. Thus we can remove a few lines
of code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The date and time fields of the main tab posted undo events
for every date/timeChanged signal. Thus, when changing the
day of the month to e.g. 21, this would result in two date
change events: one to the 2nd and one to the 21st. This is
very irritating.
Instead listen to editingFinished() events, which thankfully
exist for these widgets.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The cylinder-based statistics where not updated when an undo
command edited cylinder data. Do so.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The SAC rate, etc were only updated when switching between dives.
They should always be updated when an undo command changes (adds,
edits, removes) the cylinders of a dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It was suggested in a review of a previous patchset that we should
capitalize the use of "use dc" to "Use DC" - but if we were going
to do that we should do it everywhere, not just in the one place.
This is the followup to do that.
Signed-off-by: Monty Taylor <mordred@inaugust.com>
In the code, the difference between SALTYWATER and SALTWATER is hard
to see. More importantly, in the UI - Brackish is the word for water
that has more salt that freshwater but less salt that seawater. The
docs already use the word to clarify what is meant.
These can be useful in a printed divelog, especially if the
log entry is also showing weight and exposure suit.
Signed-off-by: Monty Taylor <mordred@inaugust.com>
When printing, the dive plan was prepended with a logo, a disclaimer
and the profile. Then it was restored by setting the plan of
displayed_dive.
Instead, simply save the original plan in a QString and restore that.
This removes a further dependency on displayed_dive, which I'd like
to make local to the planner.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
MainWindow::editCurrentDive() used to be a general function to enter
edit mode. Nowadays, this is only called for one very specific case,
namely editing the profile of a manually added dive. Therefore, we
can remove the if-branch that dealt with planned dives.
Moreover, we can do the test right at the beginning and remove
a warning message for duplicate "edition", as this is not
possible anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was only one caller of MainWindow::setupForAddAndPlan() left
and that caller immediately called DivePlannerPointsModel::createSimpleDive().
Thus, we might just as fold the former in the latter and thus
concentrate all the prepare-dive-for-plan business in one place.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Thus, the MainWindow doesn't have to extract the plan from
displayed_dive. This is a tiny step in an attempt to detangle
the interfaces. The bigger goal will be to make displayed_dive
local to the planner.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When calculating variations, they were sent to the mainwindow,
which updated displayed_dive accordingly. Do this directly
in the planner-model.
The idea is to detangle interdependencies and to make the
code reusable (planner on mobile?).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DiveListView had a singleSelectedTrip function that
returns the selected trip if exactly one trip is selected.
This could be very slow if numerous non-trip items were
selected, because all the selection indices were back-
translated by the proxy model.
This could make selection changes very slow, because the
MainTab used said function to determine whether it should
show trip or dive data.. Indeed, with a 3500 dive test log,
when selecting all dives in tree mode, the updating of the
TabWidgets is sped up from 130 ms to 5 ms this commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DiveListView would touch the selection-innards directly.
Let's encapsulate that. Moreover, take care to reset the trip
selection when resetting the core data.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When there is no current dive, mainTab->updateDiveInfo() implicitly
clears the tabs. There is no need to call this explicitly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
ProfileWidget2::plotDive() had this weird interface, where passing
in NULL as dive would mean "show current_dive". However, most callers
would already pass in current_dive. Therefore, unify and always pass
in current_dive if the caller wants to draw the current dive.
This allows us to interpret NULL as "show empty profile". Thus,
passing in current_dive when there is no current_dive simply shows
an empty profile. This makes the calling code in
MainWindow::selectionChanged() simpler.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a mix of ProfileWidget2::replot() and
ProfileWidget2::plotDive(current_dive, true), which is equivalent.
Since there was more of the latter and it is more flexible, unify on
that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Firstly, the parameter appears conceptually wrong, as replot suggests
that the currently shown dive is replot. Secondly, the only caller that
passed a parameter was passing in current_dive, which is just what happens
if one doesn't pass a parameter. Therefore, change that caller (call
plotDive directly) and remove the parameter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We used to cancel a plan (or profile edit) when the user quit
the application while planning. This is inconsistent with
respect to closing or opening a different log, where the user
was asked for confirmation.
Thus, for consistency and to avoid loss of a planned dive,
use the okToClose() function in on_actionClose_triggered() of
MainWindow. As an added bonus, this saves a few SLOC.
Fixes#1078
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In 2021035cfc a bug was introduced:
currentTrip of MainTab was not set in trip mode. Thus, when editing
the trip notes, the notes of all selected dives were edited instead.
Set the member variable and not a local variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
No point in slurping in all of dive.h for translation units that only
want to do some time manipulation without ever touching a dive.
Don't call the header "time.h", because we don't want to end up in a
confusion with the system header of the same name.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When the dive mode is changed, the profile has to be replot. This
is by a function of the TabDiveInformation. However, that function
was also executed when populating the tab. Thus, when changing dive,
the profile was plot twice.
Move the profile plotting out of the function. Ultimately, the profile
should listen to the appropriate signals itself.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To check wether the tab widgets should show the trip view, they called
the selectedTrips() function. The trip view was shown if that contained
only one trip. However, the selectedTrips() function was very slow,
because it has to query to core models.
Change the function to singleSelectedTrip(), which returns a trip
if there is exactly one trip selected. The function returns early
if there is more than one trip selected. This makes the select-all
case much faster.
There are two cases which are still very slow:
- List mode, because here all top-level items are queried.
- Dive log with many only top-level items.
Ultimately, we will have to cache the trip selection because
querying the model is too slow.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code would call QItemSelectionModel::select() once for every dive.
Instead collect the selection in a QItemSelection and only call
QItemSelectionModel::select() once. This makes selecting multiple dives
significantly faster.
The loop also expanded the trips with selections. This has now to be
done in an extra loop.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When determining the selected dive sites to highlight them on the
map, the DiveListView code used the local indices of the selected
dives. However, that was unreasonably slow. Even though a layering
violation, let's access the core data structures directly. In my
tests this improved from 700 ms to 0 ms!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It makes reasoning about code so much easier when one knows that
functions cannot be accessed from the outside. Therefore, make
a number of DiveListView slots private. Moreover, unslotize
functions that never were used in connect calls.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DiveListView widget has to differentiate between programmatical
und user-initiated selection changes. It did so by using the
DiveListNotifier::inCommand() flag.
However,
1) There is only one point of entry for such selection changes,
viz. the MultiFilterSortModel::selectionChanged() signal
2) This signal is not only emitted in command-context.
Another source is for example dive-map selection changes.
Therefore, move the programmatical-selection-change status down
to the widget and set/reset it in the diveSelectionChanged() slot.
This makes "select all visible dive sites" somewhat faster. Sadly,
not as much as expected.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Outside callers had no business calling these functions.
Especially some functions that were simply there to override
default DiveListView behavior. Mark these as overridden.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was used by the map to select dives. However, the map now calls
the core function directly, so this can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The map widget called the dive list to select dives. This is
inconsistent and complex. The dive list has to call down to
the core anyway. Therefore, change the code to call the common
core function.
This means that we have to transform integer ids into dive-pointers.
That is a bit sad, because the dives were just transformed into
indices. Let's address that in a future commit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was erroneous, as it should only be called at the end of
a selection change, not after every single dive. It made selection
of multiple dives extremely slow.
Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Debugged-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DiveListView::selectDive() is an overloaded function. The second
version was only called by the first version, so we can fold one
into the other.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The undo-machinery makes sure that a current_dive always exists
after an undo command. This part of the code should never be
called.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This appears to be an artifact. Collapsing does not unselect
the current dive, so reselecting it appears pointless.
Also it is unclear why the selection should be restricted to
a single dive after collapsing.
Probably that was originally meant to expand only the trip
with the current dive in it?
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Thus, it is made clear that these member functions can only be
accessed from DiveListView itself. This should make debugging
easier.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move this to the core so that desktop and mobile don't have
to call this explicitly. Matter of fact, mobile didn't call
this. It is unclear, whether that was even used on mobile,
though.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It makes no sense to keep the device nodes if all the other data
is cleared. Let's do this automatically and not explicitly.
This ensures that the function is also called on mobile.
Currently it was only called on desktop.
Weirdly, the parser-tests were expecting that the device nodes
were not reset by clear_dive_file_data() and therefore divecomputers
were accumulating in the test results. Thus, the additional
computers had to be removed from the expected test results.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This only checks the first divecomputer as the semantics for
multiple dive computers with different dive modes are not
clear. Should we check them all?
The implementation is a bit hackish: the indexes [0...n] of the
combobox are mapped onto [-1...n-1], where -1 means don't filter
and n-1 is the last valid dive mode.
Implements #2329
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It appears that some misguided compiler / library combinations crash
on &vector[0] for empty vectors. Even though very unfriendly, they are
technically correct, so let's remove these constructs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
TabDiveInformation::updateProfile() does some statistics via the
per_cylinder_mean_depth function. It passes down arrays with one
entry per cylinder, which are allocated by means std::vector.
To pass the array, the expression "&vector[0]" is used. It seems
like some compilers through an assertion violation if vector
has no elements. They are technically correct in that this is
undefined, but still this appears like very unfriendly behavior.
After all, std::vector should behave just like a dynamic C-array
that is automatically freed, when going out of scope.
Replace the "&vector[0]" by "vector.data()" and don't do the
call if there aren't any cylinders for good measure.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move the more commonly used filter to the left and the less
commonly used "purge unused sites" button to the right. Add
a spacer so that the filter-textbox doesn't extend over the
whole free space.
With apologies to sinistroverse users (is there an option to
make the layout direction depend on the locale?).
Suggested-by: Hartley Horwitz <hhrwtz@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Perform slight reorganisation and rewording of the divelog export
panel. Specifically the wording is changed and expanded to make clear
the 2 types of export of profile data. All the CSV export options are
grouped together. With respect to profile export to CSV format, it is
made clear that one option concerns export of dive computer-related
profile data, whereas the other option involves export of computed
dive profile data from the Dive Profile panel.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
When creating a TankInfoDelegate editor, reploting of the profile
was disabled to avoid replotting when the user scrolls through
the tank-info list. Since the code was changed to only set the
tank-info when the editor is closed, this became unnecessary
(hopefully). Indeed the clearing of the flag was removed in a
previous commit. This means that we also have to remove the setting
of the flag. Since this is all the TankInfoDelegate::createEditor()
function was doing, we can remove the whole function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
MainWindow::on_actionAddDive_triggered() updated the profile after
calling Command::addDive(). However, that is redundant because the
undo-machinery does the profile reload. Remove the call.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The comment states that Qt treats TAB as cancel when in the combobox.
However, testing shows that this use-case works without this hack.
Since it caused weird behavior (the data was set *after* the editor
was closed, leading to inconsistent state), remove it.
Note: this overrides the previous commit, which is therefore redundant
from a history point of view. However, I'll leave the previous commit
in so that if something turns out to break, we can figure out which
of the two changes it was.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
fixTabBehavior() set the editor text *after* closing the editor.
This left us in an inconsistent state where we thought that the
editor is active. By reversing two connects, this problem is resolved.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All combobox-delegates shared a number of static status fields.
In a quest to make the code more reentrant, move that to the
actual object. The fields have to be defined as mutable, since
they are set in const member functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Update of the profile is now done by the undo-commands. If the
planner needs this, it is probably better to connect directly
to the model, not the delegate.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing cylinders or weights directly in the table widgets,
no warning was shown if multiple dives were affected. To solve this,
emit signals from the respective models and catch them in dive
equipment tab. Not very nice, but it works for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was only one editMode left (MANUALLY_ADDED_DIVE).
Therefore replace by a flag. This makes the code more consistent,
because the conditions "editMode != NONE" and "editMode ==
MANUALLY_ADDED_DIVE) actually meant the same thing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The editMode was set to IGNORE_MODE when programatically setting
fields so that we can ignore changed-signals.
That seems to be orthogonal to whether we are in edit mode
and indeed when setting IGNORE_MODE the edit mode was
saved and restored.
Therefore, replace the IGNORE_MODE by an independent ignoreInput
flag.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For reasons that I don't understand, we keep track of the
current combo-box text for our model-delegates. However,
that text was not initialized when the editor was generated,
leading to a UI bug in the cylinder and weight widgets:
Activate a field, click somewhere else -> either the empty
string or the previous string was set.
Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is a simple copy of the other add-event commands. It could
be made more friendly by stating the pO2 value in the text.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since pointers to divecomputers may not be stable, the undo
commands take a dive + a divecomputer number. Update the
SetpointDialog accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
While touching this dialog, might as well change away from the MOC
version of the connect() statements.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We have too many global objects. There is no reason why this dialog
should be a persistent global object.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
That mode is not used anymore, since only the editing of
profiles of manually added dives enters editing mode. For
that case we have the MANUALLY_ADDED_DIVE edit mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All remaining callers were passing MANUALLY_ADDED_DIVE as a new
mode, so we may just as well remove the parameter and thus
simplify the logic.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only way to enter edit mode is to edit the profile. However,
that means that the profile is already visible, so there is no
need to change the mode. Simply remove the EDIT mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When entering the edit state, we don't want the user to be able
to undo/redo lest things become inconsistent. Since the only way
to enter edit state is to edit the profile, we can simply use
the disableShortcuts() function that is used by the profile
when it goes into edit state.
This has one desirable side-effect: Undo is now also disabled in
the planner. Undo during planning likewise can lead to inconsistent
state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one is tricky, as when browsing through the types-combobox,
the user is presented with presets without actually changing the
dive. We do not want an undo-command for every change-event in
the combo-box.
Therefore, implement a scheme analoguous to the weight-editing:
A temporary row can be set / committed or reset. Sadly, the
code is more complex because we have to consider the planner,
which is not included in the undo system.
Firstly, the planner uses a different model, therefore all
interactions are channeled through setData() with special roles.
Secondly, in the planner we shouldn't place an undo command,
but simply overwrite the dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The profile can only be edited for manually added or planned
dives. No point in keeping code for other kinds of dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The edit state is now only used to edit the profile. There is no
reason to disable random tabs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The editing of the dive site is controlled via an undo command.
No point in centering the map when cancelling a profile-edit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This stored the old editMode. However, it was not read after
editMode was changed, so there is no point to it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The "dive is currently" edited is only shown when the profile is
edited. This affects only the current dive and therefore a
message saying that multiple dives are edited makes no sense.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When enableEdition() was called with mode == NONE and the dive
was a manually added dive, it would call into MainWindow::
editCurrentDive(), which would in turn call enableEdition(),
however with another mode. Since the only caller of
enableEdition() is now editCurrentDive() anyway, we can
remove that weird code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since cylinders are now edited using the undo system, these
functions are not needed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of connecting to the remove() function of the model,
call the removeCylinder undo command. Take care to translate
the index into the source index, should cylinders be hidden!
Apart from the map-to-source call, this copies the weightsystem
code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The CylinderModel always accessed the global "displayed_dive" and in
some special cases also "current_dive". To implement cylinder undo,
the model should work on an arbitrary dive. Therefore, in analogy
to the weight model, make the dive dynamic.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The weightsystem info for new weightsystem types is added by the
undo command. Remove this redundant code. Use the lookup only to
determine the weight and the canonical name (i.e. use the capitalization
according to the saved entry, in analogy to tanks).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In the wightsystem-type and cylinder-type delegates, when entering
data, when entering known weight- or cylinder-types, some ui fields
(notably weight, size and working-pressure) are automatically filled
out. The search was using the default flags provided by Qt: starts-with
and case-insensitive.
This had a few strange effects, when entering a string that is the
beginning of a known string (e.g. "AL6" when "AL63" already exists):
1) The wrong data was used if the new string didn't exist.
2) For cylinders it was impossible to create new cylinder types whose
name is the starting string of a different type.
3) For weights, the new type was not added to the list of known types.
This, however, is no problem, because it will be added by the undo
command anyway. A future commit will address that redundancy.
Therefore use only the case-insensitive flag (which has to be performed
by passing the MatchFixedString flag - very weird).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In DivelogsDeWebServices::updateProgress() QProgressBar::setRange()
and QProgressBar::setValue() were passed floats even though they
expect ints. To silence a compiler warning, cast by hand. Use the
lrint() function, since we generally do it this way. However,
it is not clear whether this is necessary here.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The uiLanguage() function was used for two purposes: to initialize
the language related preferences and to read the current language.
To make things more easy to follow, split this function in two:
one for initializing, one for getting the current language.
Moreover, don't return the current locale in an out-parameter
as there is already a function to do that [getLocale()].
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The user had to restart the application or manually change the filter
if they changed the flag.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When the dive list is cleared or updated, the entries in the
divesite-model become stale and therefore the divesite-model
(with the actual name LocationInformationModel) also must be
updated. This was done manually in some parts of the code and
forgotten in others. Therefore, do it directly in the clear()
and reset() function of the dive list-model.
This might be a bit of a layering violation: why should one
model call into another if they are not in parent/child
relationship? However, this seems easier than introducing
a global "reset dives" function that coordinates the models.
Moreover, it does not appear 100% safe: if the clearing of
the divesite model causes accesses to the divelist-model,
they happen in the midst of a model reset and we had horrible
bugs with that kind of things. However, I don't think that
should happen.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Grammar-nazi ran
git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g'
to prevent future wincing when reading the source code.
Unfortunatly, Qt itself is infected as in
QModelIndexList QItemSelection::indexes() const
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Use the undo-command for importing dives also on mobile. This should make the
whole disconnect-model shenigans unnecessary.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When the dive data is cleared, all pointers in the undo-stack become stale.
Desktop explicitly called Command::clear() in that case, but mobile doesn't.
Thus, move the clear() call into DiveTripModelBase::clear()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
At least in those cases where we are sending a divesChanged signal we can
easily check if the cache was properly invalidated. Of course this won't help
in cases where we don't notify the dive list about changes, either.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There are two cases where dive-times are shifted: in an explicit
dialog and when editing the date/time of a dive.
In each of these cases, the selected dives were collected manually.
Instead use the getDiveSelection() function. Since this returns
a std::vector, change the argument of Command::ShiftTime() to
such a std::vector.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Commit 2cea115ddb "fixed" the selection
by hooking into mouseRelease events. An unintended consequence was
that scrolling with the cursor keys didn't update the current dive.
Therefore, also hook into the corresponding key-press events.
This is just horrible, but I'm not aware of any possibility to fix
it properly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There are now three filter modes:
1) Dive site
2) Fulltext
3) Normal
When doing a fulltext search, get the dives that match the
fulltext filter and then apply the other filters on that list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The FilterData struct has the enum StringMode, which describes how
strings are searched (substring, startswith, exact). To make it
more generally accessible, remove it from the class. Since it is
an "enum class", the values don't pollute the global namespace anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These were used to remove warning-icons to mark tabs with user
changes. However these icons haven't been set since commit
a86aca0378.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The tank-info-delegate cast its model to CylindersModelFiltered,
since this is what the equipment-tab uses since implementing the
filtering of unused cylinders. However, the planner users the same
delegate and still uses the unfiltered CylindersModel. This means
that the (dynamic) cast returns a null pointer and crashes.
One possibility would be to derive CylindersModelFiltered and
CylindersModel from the same class that defines virtual functions
and cast to that class.
This is a different attempt: don't cast (i.e. stay with a
QAbstractItemModel and play it via Qt's model-view system. Firstly,
replace the passInData function by a role to setData(). Secondly,
read the working-pressure and size via new columns using data().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>