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>