aboutsummaryrefslogtreecommitdiffstats
path: root/profile-widget
AgeCommit message (Collapse)Author
2021-01-10profile: pass dive to RulerItemGravatar Berthold Stoeger
Instead of accessing the global displayed_dive variable in RulerItem, pass the dive. This is a step in making the profile reentrant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: pass dive to ToolTipItem::refresh()Gravatar Berthold Stoeger
Don't access the global displayed_dive variable in a step to make the profile reentrant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: pass dive to plot function of profile-itemsGravatar Berthold Stoeger
Instead of accessing the global displayed_dive variable, pass the dive to the various profile items. This is a step in making the profile code reentrant. This removes the last user of the displayed_dc macro, which can now be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: pass dive to EventItemGravatar Berthold Stoeger
Don't access the global displayed_dive variable in an effort to make the profile reentrant. Note that this still accesses the global dc_number variable, which will likely have to be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: move adding of ceiling-violation-eventGravatar Berthold Stoeger
The profile item that shows the ceilings adds a warning event if the ceiling is violated. This is very unfortunate. Improve this situation by adding the event up to the function that calculates the ceiling. This is still not how it should be - the display layer should not modify the dive that it displays. To make this clear, add a comment that details that this is a contract between planner and display layer: The planner uses a dive that can be trampled upon by the profile. Still, this should be solved differently. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: use a parameter to determine planner stateGravatar Berthold Stoeger
The in_planner() function is incompatible with a reentrant profile, since it accesses a global variable. In create_plot_info_new() it is essentially redundant, because there is a planner_ds (ds = deco_state) parameter that is used only when in the planner. Therefore use that as the in_planner indicator: when non-null, the profile is showing a planned dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove DiveProfileItem::settingsToggledGravatar Berthold Stoeger
This was used to force a replot on preferences changes. However, the profile now does a replot in such a case by itself. This can be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: move calculations out of DiveGasPressureItem::paint()Gravatar Berthold Stoeger
With the same argument as for DivePercentageItem, move access to live data out of the paint() function. Instead, calculate colors in replot(), where the other data are calculated. This is slightly more complicated than in DivePercentageItem, since there are multiple polygons. Therefore, replace QPolygonF by a vector of structures contained the position and color of the data point. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: move calculations out of DivePercentageItem::paint()Gravatar Berthold Stoeger
The DivePercentageItem is a polygon-item with a custom paint() method. Calculation of the polygon is done once in replot(), but calculation of the corresponding colors is done in every paint() call. The problem is, we have no control over paint(). It is called whenever Qt feels like. Therefore using live dive data is a dangerous proposition if we ever want to get rid of the global displayed_dive. Do all the calculations in replot(). Store the colors in an additional array of the same size as the polygon. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove displayed_dive from TankItemGravatar Berthold Stoeger
The only time the TankItem is replot is when new data is set. Therefore, replot() can be folded into setData(). The good thing is that setData() is passed the dive to be plot. So the data can be extracted from there instead of the global displayed_dive variable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: unconditionally replot chart when settings changeGravatar Berthold Stoeger
The code tried to only replot the profile if necessary, notably when in edit mode or the ceilings are shown. That seems like pointless premature optimization, which only complicates things: The profile is replot every time a "dive handle" is moved, which means that we depend on the replotting being reasonably fast. Why should it then not be redrawn if the settings change? Let's remove this, as it makes control flow easier to reason about. This makes the isPlotZoomed member variable redundant. Remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove AbstractProfilePolygonItem::modelDataChanged()Gravatar Berthold Stoeger
The old mechanism to replot the profile items was to listen to model-change signals. Then the code checked whether it actually had to update anything by looking at the changed model-indices. However, the crucial replot was always initialized with emitDataChanged(), which simple invalidated the full model and therefore shouldCalculateStuff() always returned true. Since now the replot() is called explicitly, remove the whole logic and simply rename modelDataChanged() to replot(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: explicitly update profile itemsGravatar Berthold Stoeger
Instead of listening to the dive-data-model changed and axis changed signals, update the profile items explicitly once per plot() call. This avoids double replotting of the dive items. The old code had at least two replots per plot() call: one after profileYAxis()->setMaximum() and one after dataModel->emitDataChanged(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: explicitly update gas-axisGravatar Berthold Stoeger
On each profile replot, the gas axis was implicitly reset by calling "dataModel->emitDataChanged()", which would send a signal recieved by the axis. To make the code less confusing and, more importantly, make order of execution deterministic, explicitly reset the axis. Rename the function that resets the axis from "settingsChanged" to "update" to reflect its usage. Moreover, remove the "setModel()" function and pass the model to the constructore. Make it a const reference to make clear that it can't change during the life time of the axis. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10cleanup: unslotify DiveCartesianAxis::updateTicksGravatar Berthold Stoeger
This virtual function is not used as the target of a signal anywhere, which means that it shouldn't be a slot. Moreover, mark the one place it is overriden as override. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: explicitly clear profile itemsGravatar Berthold Stoeger
In contrast to most other items, which are cleared in the setEmptyState() function, the profile items are cleared indirectly via a signal from the model. Very hard to follow and indeed, I thought I could just remove the slot. Do this explicitly instead for deterministic code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: turn static into member variableGravatar Berthold Stoeger
When the settings change, the depth axis is redrawn to reflect metric/imperial units. To check whether the units changed, the old length unit is saved in a static variable. This makes no sense and allows for only one depth axis. Make this a normal member variable that is initialized in the constructor. Also remove the settingsChanged() call in the constructor, since this is a no-op (the depth unit is unchanged). Contains a whitespace fix. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: cleanup includes in tankitem.cppGravatar Berthold Stoeger
If possible, forward declare and move the include to the .cpp file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: set axis in constructor of TankItemGravatar Berthold Stoeger
There is no point in a separate set-axis function if we never change the axis anyway. Make the axis a const-reference to show that it can never be changed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove TankItem's connection to the resize signalGravatar Berthold Stoeger
Since the initial commit introducing TankItem, there was a connection that replotted the item if the horizontal axis sent the sizeChanged() signal. I never managed to create this signal for the horizontal axis, only for the vertical axes. Therefore remove this thing. If it turns out that we need it after all, readd it in a more deterministic way (i.e. call where it is needed). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove model parameter from TankItem::setData()Gravatar Berthold Stoeger
This one is extremely obscure: TankItem::setData(), which is called on every replot, was passed the DivePlotDataModel, even though it doesn't access that model at all. Instead, it connect()s to the model to stay informed of changes to the data. First of all, this should obviously be done once in the constructor, not on every replot. But also, the setData() function is called on every replot one lines before sending the model-changed signal. Thus, the tankitem was always repainted twice. Just remove the whole connect() thing and go for a more deterministic model. Should the tankbar not be repainted anywhere, add the appropriate calls there. Accordingly rename the "modelDataChanged" slot to "replot". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove AbstractProfilePolygonItem::settingsChanged()Gravatar Berthold Stoeger
settingsChanged() is a virtual function, which is called when the preferences dialog signals changes. In most derived classes, the function does nothing. In two classes, DiveProfileItem and DiveCalculatedTissue, it replots the item respectively changes its visibility. However, these two flags are *not* controlled by the preferences dialog. Indeed, the functions are also connected to finer-grained qPref signals. Therefore, settingsChanged() can be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: collect dive-profile items in a vectorGravatar Berthold Stoeger
Collect all the created profile items in a dynamic vector. This allows us to loop over them when adding them to the scene, instead of addressing each item individually. Hopefully, this will also allow for a more deterministic repaint logic, without relying on signals. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10cleanup: remove obsolete #undef in profilewidget2.cppGravatar Berthold Stoeger
The macro was removed quite some time ago. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove ProfileWidget2::setupItem()Gravatar Berthold Stoeger
The only thing left that this function did, was setting the Z-value of the item. This can be done directly on construction. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: construct PP gas items with createPPGas() functionGravatar Berthold Stoeger
This function was called after creating the items. It can be called directly to create the items. Less chance of mixups. For this to work, the initialization of isGrayscale has to be moved to the front, because createPPGas sets the color according to this flag. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: move allocation of DiveProfileItems into a templateGravatar Berthold Stoeger
Instead of typing out the same arguments again and again, do the allocation of DiveProfileItems in a templated function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: initialize axis of DiveProfileItems on constructionGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10cleanup: make DiveCartesianAxis functions constGravatar Berthold Stoeger
A few DiveCartesianAxis functions that were pure accessors were not const. Make them so. Moreover, mark a few overridden virtual functions as such. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove ProfileWidget2::dateTimeChanged()Gravatar Berthold Stoeger
This function sent a signal and the only listener was removed in the previous commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: set model of profile items on constructionGravatar Berthold Stoeger
The profile items had a "setModel()" function to set the DivePlotDataModel post creation. The model is never changed. It does however mean that the model might be null in a short period between construction and setting the model. To simplify reasoning about this code, set the model in the constructor. To drive the point home that the can never change and cannot be null, turn it into a reference. Yes, this is gratuitous bike-shedding, but it helps me analysis the code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: remove redundant code in DiveCalculatedCeilingGravatar Berthold Stoeger
The DiveCalculatedCeiling profile-item has a recalc() function, which calls "dataModel->calculateDecompression()". This is a questionable reversal of control-flow: The profile-item should paint the model-data not change it. The code was supposed to be called under two conditions: 1) The value of the calcceiling3m preferences flag changed. This code was buggy for two reasons: Firstly, the cached value was always initialized to false, which means that sometimes the first call was missed. Secondly, the settingsChanged() functions was only called when closing the preferences window, not when changing the flag in the profile widgets. 2) The datetime of the dive changed. The whole control-flow is pretty absurd (due to "bit rot"): - The replan-dive command sends a date-time changed signal. - The main tab changes the date-time and informs the profile. - The profile sends a signal to the item. - The item instructs the model to recalculate the decompression. - The model causes the profile to be redrawn. In any case, the whole thing is moot, because the decompression is recalculated for *every* profile plot in create_plot_info_new(). Let's remove the code from the DiveCalculatedCeiling profile-item and the calculateDecompression() function, which is now not used anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-03statistics: use RoundRectItem for legend and info-boxGravatar Berthold Stoeger
Dirk says rounded corners look better. This now looks a bit extreme to me and probably the border size should be increased. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-03ui: create a RoundRectItem classGravatar Berthold Stoeger
Factor out code from ProfileWidget's ToolTipItem, but make the radius of the corners dynamic. Move into backend-shared, though a new ui-shared might be preferred. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-21mobile/profile: listen to dive changes and redraw profileGravatar Dirk Hohndel
If a dive changes, we should simply redraw the profile. This could be improved by checking for the fields that might impact the profile at all, but this is definitely a step in the right direction. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-12-20profile: remove clearHandlers function (fixes crash)Gravatar Berthold Stoeger
Recently (674c20227b2), the call to ProfileWidget::clearHandlers() was moved from PlannerWidgets::replanDive() to ProfileWidget2. This cause a crash, because the code assumes that the number of elements in the handles-vector the divepointplanner model is the same. Clearing the handles violates this assumption. It turns out that the clearHandlers() function is broken anyway: it clear the handles-vector, but not the gases-vector, which should likewise have the same number of elements. It appears that the clearHandlers() function is an artifact and it is mysterious how this has worked so far. Remove. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-19profile: move picture removal from DivePictureItem to ProfileWidget2Gravatar Berthold Stoeger
On clicking the DivePictureItem "trash" icon, the item would delete the picture it represents in the currently displayed dive. This needed an access to the global "displayed_dive" variable, which we want to get rid of to make the profile more flexible. For example, we want to render the profile for printing without messing with global state. One solution would be to save the dive with every DivePictureItem. This commit follows a more Qt-ish strategy by handling this via signals: The close button emits a signal that is recast by the DivePictureItem and ultimately handled by the ProfileWidget2, which knows which dive it represents. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-19cleanup: remove CloseButtonItem::show() and hide() slotsGravatar Berthold Stoeger
These were only calling the corresponding functions in the base class. So just don't override them..? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-12profile: move connect() calls to profileGravatar Berthold Stoeger
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>
2020-12-12cleanup: remove unused signal ProfileWidget2::updateDiveInfoGravatar Berthold Stoeger
Last user was remove in 0bd821183d. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-12profile: move DiveHandler to profile-widget folderGravatar Berthold Stoeger
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>
2020-12-12profile: call clearHandlers() in setPlanState()Gravatar Berthold Stoeger
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>
2020-12-12preferences: create global settingsChanged signalGravatar Berthold Stoeger
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>
2020-10-26cleanup: replace deprecated swap() usageGravatar Dirk Hohndel
Instead of using the two different ways Qt supports swap, depending on the Qt version in use, let's simply use std::swap() Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26cleanup: replace deprecated pos() memberGravatar Dirk Hohndel
Again, replacement was just recently added. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26cleanup: replace long obsolete delta() memberGravatar Dirk Hohndel
This has been deprecated for years. The delta() member dealt with the old style mouse wheel that is associated with a vertical scroll - so we need the y-component. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: break out event-related code into event.[c|h]Gravatar Berthold Stoeger
In an effort to reduce the size of dive.h and dive.c, break out the event related functions. Moreover event-names were handled by the profile-code, collect that also in the new source files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05Use get_n2 helper functionGravatar Robert C. Helling
Now, that we have this helper function that should have been introduced long ago, we can make some more expressions more idiomatic. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-13cleanup: fold core/divecomputer.cpp into core/device.cGravatar Berthold Stoeger
core/device.h was declaring a number of functions that were related to divecomputers (dcs): creating a fake dc for manually entered dives and registering / accessing dc nicknames. On could argue whether these should be lumped together, but it is what it is. However, part of that was implemented in C++/Qt code in a separate core/divecomputer.cpp file. Some function therein where only accessible to C++ and declared in core/divecomputer.h. All in all, a big mess. Let's simply combine the files and conditionally compile the C++-only functions depending on the __cplusplus define. Yes, that means turning device.c into device.cpp. A brave soul might turn the C++/Qt code into C code if they whish later on. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>