summaryrefslogtreecommitdiffstats
path: root/profile-widget/profilewidget2.cpp
AgeCommit message (Collapse)Author
2020-05-06profile: clear pictures when displaying empty diveGravatar Berthold Stoeger
Since the profile does not listen to DivePictureModel resets anymore, the pictures weren't cleared when clearing the canvas. Do this explicitly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06undo: make picture (media) deletion undoableGravatar Berthold Stoeger
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>
2020-05-06undo: implement undo of setting a picture time by drag&dropGravatar Berthold Stoeger
Even though the functionality is seemingly trivial, this is a bit invasive, as the code has to be split into two distinct parts: 1) Post undo command 2) React to changes to the divelist Don't compile that code on mobile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03profile: don't interpret NULL as current_dive in plotDive()Gravatar Berthold Stoeger
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>
2020-05-03profile: use member-to-function style connect() statementsGravatar Berthold Stoeger
This makes things compile-time instead of run-time checked. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03cleanup: remove parameter to ProfleWidget2::replot()Gravatar Berthold Stoeger
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>
2020-05-01profile: properly update lastgasmix when populating eventsGravatar Berthold Stoeger
When populating the events of a profile, a pointer to the current gasmix was passed around to properly calculate isobaric_counterdiffusion. The DiveEventItem::setupToolTipString() function updated this gasmix when processing gas change events. I inadvertently broke the code when replacing gasmix-pointers by values. We could of course simply revert this part of the commit. However, the data flow was horrible anyway: for example is supposed that the setup functions were called in the correct order (i.e. DiveEventItem::setupToolTipString() is called after all other functions using the gasmix). Not exactly easy to follow. Therefore, keep passing around the gasmix as value to make it clear that the functions don't modify it. Keep the gasmix up-to-date at the caller's site in ProfileWidget2::plotDive(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-27profile: set empty state when there is no current dive to showGravatar Berthold Stoeger
The profile data was not properly cleared when not showing a dive. Fixes #2787 Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24cleanup: move get_dc_nickname from qthelper.cpp to divecomputer.cppGravatar Berthold Stoeger
1) qthelper is already huge. 2) set_dc_nickname et al. is already there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-12profile: remove ProfileWidget2::replotEnabledGravatar Berthold Stoeger
The last setter was removed in the previous commit. Let's remove this complexity. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-11Merge pull request #2643 from bstoeger/cylinder4Gravatar Dirk Hohndel
First steps of cylinder-editing undo
2020-04-10media: move picture function from dive.c to picture.cGravatar Berthold Stoeger
Currently, move only those functions that do not access dive structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: implement gas switchGravatar Berthold Stoeger
This is a bit hairy as - in theory - one gas switch can remove other gas switch(es) at the same timestamp. However, I did not find a way to test it. Moreover, it is not clear whether the dive-tabs are properly updated on undo/redo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: add event removal undo commandGravatar Berthold Stoeger
This was a trivial copy & past of the event-adding undo command with a switch of the undo() and redo() actions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: implement renaming of eventsGravatar Berthold Stoeger
There is a slight complexity here owing to the fact that the profile works on a copy of the current dive: We get a copy of the event and have to search for the original event in the current dive. This could be done in the undo command. Nevertheless, here we do it in the profile so that when in the future the profile can work on a non-copied dive we can simply remove this function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: switch SetpointDialog from divecomputer to dive + dc-numberGravatar Berthold Stoeger
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>
2020-04-07cleanup: un-singletonify SetpointDialogGravatar Berthold Stoeger
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>
2020-04-07undo: add undo command for dive-mode switchGravatar Berthold Stoeger
This basically copies the bookmark code, with the addition that the dive mode is recorded in the text of the undo command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: replot profile if event changedGravatar Berthold Stoeger
Add a DiveListNotifer::eventsChanged signal, which is emitted when the events changed. This is very coarse, at it doesn't differentiate between signal addition / editing / deletion. We might want to be finer in the future. Catch the signal in the profile-widget to replot the dive if this is the currently displayed dive. Reuse the cylindersChanged() slot, but rename it to the now more appropriate profileChanged(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: implement addBookmark undo commandGravatar Berthold Stoeger
Create a new translation unit for event-related undo commands. Create a base class of commands that add events and one subclass that adds a bookmark event. Use this command in the profile-widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use QMenu::addAction() convenience overloadGravatar Berthold Stoeger
Since we removed the setData() calls of the QActions in ProfileWidget2::contextMenuEvent(), we don't have to manually generate the QActions. We can simply use the convenience overload of addAction() that takes a string and a functional. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use lambdas to transport DiveEventItem to actionsGravatar Berthold Stoeger
The removeEvent(), hideEvents() and editName() actions need the DiveEventItem they are applied to. This was transported via QAction's user-data, which means casting to void and back. By using lambdas instead, this can be made perfectly type-safe: First we are 100% sure that we have a DiveEventItem because we check the result of a dynamic_cast<>. Then we can pass it to the even using its proper type. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use lambda to transport event-time to context menu actionsGravatar Berthold Stoeger
This is not such a big gain as for addDivemodeSwitch(), but still simpler. Therefore, let's do it for consistency. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: don't set unnecessary action userdata for unhideEventsGravatar Berthold Stoeger
The unhideEvents context menu action was fed with the click-position. However, that was not used. Therefore, remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07profile: use lambda for addDivemodeSwitch callsGravatar Berthold Stoeger
The data was transported via the action in a most complicated way: The text was backtranslated. Simply use a lambda - perhaps hard to read, but much simpler to follow and less brittle. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use SAMPLE_EVENT_BOOKMARK in add_event() callsGravatar Berthold Stoeger
In two cases we were passing the magic value 8 instead of the symbolic SAMPLE_EVENT_BOOKMARK. Use the symbolic version instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: update profile on cylinder editingGravatar Berthold Stoeger
In the profile, catch cylinder-editing signals and redraw the profile if the currently displayed dive has changed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-11Grammar: replaces 'indexes' by 'indices'Gravatar Robert C. Helling
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>
2020-01-30Profile: fill gas change context menu from current diveGravatar Berthold Stoeger
The gas change context menu was filled from the CylindersModel. This means that even before saving new cylinders, the user could add a gas change event to these cylinders. Instead, fill from the current dive. Fixes #2552. Reported-by: Doug Junkins <junkins@foghead.com> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-01-30Profile: transport gas id and timestamp via lambdaGravatar Berthold Stoeger
When adding a gas change event via a context menu, the gas-id and timestamp were passed in two distinct ways. 1) The gas id was extracted from the text of the action. This meant doing rather complicated parsing. 2) The timestamp was passed via the "user data" of the action, which means transporting via "QVariant". There is a much simpler way to pass arbitrary data, that is strongly typed: lambdas. Instead of shoehorning the data onto the action in an archaic way, we can simply connect to a stateful lambda. That's what they're for after all. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16Profile: clear tooltip's plotInfo in ProfileWidget2::setEmptyStateGravatar Berthold Stoeger
The tooltip's plotInfo was not cleared when clearing the profile. With the new cylinder code, this lead to crashes, because the displayed_dive's cylinder array is now cleared. The old code would happily read stale data from the fixed-size cylinders array. Clear the plotInfo explicitly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14Refactoring: move undo commands to top levelGravatar Berthold Stoeger
In the future we might want to use undo-commands for mobile as well (even if not implementing undo). Therefore, move the undo-command source from desktop-widgets to their own commands top-level folder. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cleanup: free plot data on exitGravatar Berthold Stoeger
Some widgets copy the full plot info. Free these data on exit to prevent monstrous valgrind reports. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: switch pressure-accessing functions to indexesGravatar Berthold Stoeger
Continue with replacing pointers to struct plot_data entries by indexes. Thus the pressure data can be kept in its own array and can by dynamically sized. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cleanup: comment out function that is used by commented out codeGravatar Berthold Stoeger
The ProfileWidget2::getEntryFromPos() function was only used by code that was commented out. Thus comment it out as well. Moreover, turn the accompanying FIXME comments into TODO comments to avoid a new LGTML alert. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-08Profile: remove ProfileWidget2::recalcCeiling()Gravatar Berthold Stoeger
The ProfileWidget2::recalcCeiling() function is used in one place, namely when an undo-command changes the mode. It recalculates decompression data and repaints the ceilings and thus avoids a full profile-redraw. This is smart, but it becomes problematic when the dive is changed and the ceiling is recalculated before the profile is redrawn. The DivePlotDataModel then still has data from the previous dive but cylinders of the new dive are accessed. This kind of situation may arise if multiple dive fields are updated, as for example when replanning a dive. Currently, this only causes a temporary mis-calculation. When removing MAX_CYLINDERS this will lead to crashes. One might attempt to fix the whole data-dependency mess. This commit goes the cheap route and simply redraws the profile when the mode is changed. Yes, it is in a way ineffective, but we do worse things. The ProfileWidget2::recalcCeiling() thus becomes unused and is removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Cleanup: use correct loop boundsGravatar Dirk Hohndel
I'm a bit confused why this enum has two extra values, NUM_DIVEMODE and UNDEF_COMP_TYPE. I can see how this could create confusion. This may benefit from addition review. Found by Coverity. Fixes CID 350092. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-20Cleanup: use pointer-to-member-function in addAction() callsGravatar Berthold Stoeger
Since requiring Qt >= 5.9.1, we can use the pointer-to-member-function overloads of addAction (introduced in Qt 5.6). This has the advantage of compile-time checking of the signal/slot parameters. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-28Profile: properly initialize plot_info structuresGravatar Berthold Stoeger
The create_plot_info_new() function releases old plot data. This can only work if the plot_info structure was initialized previously. The ProfileWidget2 did that by a memset, but other parts of the code did not. Therefore, introduce a init_plot_info() function and call that when generating a plot_info struct. Constructors would make this so much easier - but since this is called from C, we can't use them. Fixes #2251 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
Move the declarations of the "report_error()" and "set_error_cb()" functions and the "verbose" variable to errorhelper.h. Thus, error-reporting translation units don't have to import the big dive.h header file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: replace pressure reading macros by inline functionsGravatar Berthold Stoeger
Replace the INTERPOLATED_PRESSURE and SENSOR_PRESSURE macros by inline functions. Generate a common inline function that reads a pressure value for a dynamic sensor. Not all SENSOR_PRESSURE macros can be replaced, because the macro is also used to set the value and C sadly doesn't know the concept of "return reference from a function". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-12Profile: stop animations on exportGravatar Berthold Stoeger
The plotDive() function had a flag to plot pictures asynchronously. This was used on export. Rename this field to "instant" and disable animations when set. This should make sure that the axes are properly exported. Fixes #2170 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-12Profile: store animation speed in profile objectGravatar Berthold Stoeger
When exporting dive pictures we don't want animations. Therefore, store the animation speed in the profile object to avoid nasty hacks with the preferences. This actually removes such a hack. Pictures and tooltips for now still use the values stored in the preferences, because their animations happen only on user-interactions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-12Profile: take int instead of bool in DiveEventItem::recalculatePosGravatar Berthold Stoeger
The goal here is to slowly make animation speed a variable of the profile widget, not of the global preferences. Currently the code does some trickeries with setting / unsetting the global animation speed. Start by not taking a bool "instant" but a speed in DiveEventItem::recalculatePos(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-06Cleanup: call calculate_max_limits_new() in create_plot_info_new()Gravatar Berthold Stoeger
All callers of create_plot_info_new() called calculate_max_limits_new() a line before. Thus, simply call the latter in the former. This allows us to automatically free the plot data in create_plot_info_new(). The old code overwrote the corresponding field with NULL. As a side-effect, this removes a bogus static variable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-06Cleanup: fix memory management of the plot dataGravatar Berthold Stoeger
There was a global variable last_pi_entry_new, which stored the recently allocated plot data. This was freed when new plot data was generated. A very scary proposition: You can never have two plot datas at the same time! But exactly that happens when you export for example subtitles. The only reason why this didn't lead to very crazy behavior is that at least on my Linux machine, the calloc() call would just return the previously freed memory. Fix this mess by removing the global variable and freeing the data in the callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-04Cleanup: remove unnecessary display refreshGravatar Berthold Stoeger
In ProfileWidget2::splitDive() updateDiveInfo was emitted, but the UndoCommand does this by itself. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-20Core: let count_divecomputers() operate on an arbitrary diveGravatar Berthold Stoeger
Currently, count_divecomputers only works on the current_dive. Instead, let it take a pointer to an arbitrary dive. This is in preparation for being smarter in the undo code concerning which dive computer to show on deletion. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>