aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/locationinformation.cpp
AgeCommit message (Collapse)Author
2019-04-12Dive site: add dive site table parameter to dive site functionsGravatar Berthold Stoeger
To enable undo of dive site functions, it is crucial to work with different dive site tables. Therefore add a dive site table parameter to dive site functions. For now, always pass the global dive site table. Thus, this commit shouldn't alter any functionality. After this change, a simple search for dive_site_table reveals all places where the global dive site table is accessed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12get rid of some foreach and Q_FOREACH constructsGravatar Rolf Eike Beer
See https://www.kdab.com/goodbye-q_foreach/ This is reduced to the places where the container is const or can be made const without the need to always introduce an extra variable. Sadly qAsConst (Qt 5.7) and std::as_const (C++17) are not available in all supported setups. Also do some minor cleanups along the way. Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
2019-03-27Cleanup: provide printGPSCoords in C and C++ versionsGravatar Berthold Stoeger
printGPSCoords() returned a newly allocated C-style string. Most callers simply made a QString out of it and freed the C-style string. This is paradoxical, as printGPSCoords internally works with QStrings and converts them to C-style on return. Therefore, let printGPSCoords() return a QString and create a printGPSCoordsC() wrapper for the two C-callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-24Cleanup: fix printGPSCoords signature and leaksGravatar Berthold Stoeger
The printGPSCoords() function returns a copied C-style string. Since the owndership is transferred to the caller, the correct return type is "char *" instead of "const char *". Thus a number of casts when calling free can be removed. Moreover a number of callers didn't free the string and thus were leaking memory. Fix them. Ultimately we might want two versions of the function: one for QString, one for C-style strings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Drop old filter codeGravatar Tomaz Canabrava
Drop tons of now-unused-code. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2018-10-30Dive site: fix oversight in 920eb7576fGravatar Berthold Stoeger
In commit 920eb7576ff3c5fab19c12b7b291042817422ac5 "dive_site *" was included in Qt's "metatype" system to be able to pass it through QVariants. One instance was forgotten and a "void *" was passed in. On readout NULL was returned, which made it impossible to add new dive-sites under certain circumstances. Convert this one instance to a proper "dive_site *" QVariant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass pointer-to-dive_site via QVariantGravatar Berthold Stoeger
There was this ugly pattern of passing pointers-to-dive_site via a QVariant of void * type. This is of course inherently unsafe. Pass these pointers using their proper types instead. This makes it necessary to register them in Qt's meta-type system. Doing so, fixes a bug: QML couldn't call into updateDiveSiteCoordinates() because it didn't know the type and thus the coordinates of the moved flag were not reflected in the divesite-dialog. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: replace dive->dive_site_uuid by dive_siteGravatar Berthold Stoeger
Replace the UUID reference of struct dive by a pointer to dive_site. This commit is rather large in lines, but nevertheless quite simple since most of the UUID->pointer work was done in previous commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: remove [start|stop]FilterDiveSite signalsGravatar Berthold Stoeger
This is another case of a weird pattern where an object would connect it's own signal to the slot of a different object. There seems to be no reason why the former couldn't simply call the latter. Remove the [start|stop]FilterDiveSite signals of LocationInformationWidget and call the corresponding functions of MultiFilterSortModel directly. While doing so, replace the UUID argument by a pointer-to-divesite. It will be converted anyway right at the beginning of the function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass pointer to updateDiveSiteCoordinates()Gravatar Berthold Stoeger
There are two updateDiveSiteCoordinates() member-functions, viz. in MapWidget and MapWidgetHelper. Adapt them to take a pointer to dive_site instead of a UUID. This is part of an effort to replace UUIDs by pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: Pass dive-site pointer to MapWidgetHelper::enterEditMode()Gravatar Berthold Stoeger
Replace the uuid argument to MapWidgetHelper::enterEditMode() by a pointer. Likewise, adapt the only caller prepareForGetDiveCoordinates(). This is a small step in a bigger effort to replace dive-site UUIDs by pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: remove UUIDs from LocationInformationModelGravatar Berthold Stoeger
Replace UUIDs from LocationInformationModel and fix the fallout. Notably, replace the UUID "column" by a DIVESITE "column". Getting pointers through Qt's QVariant is horrible, we'll have to think about a better solution. RECENTLY_ADDED_DIVESITE now defines to a special pointer to struct dive_site (defined as ~0). This fixes an interesting logic bug: The old code checked the uuid of the LocationInformationModel (currUuid) for the value "1", which corresponded to RECENTLY_ADDED_DIVESITE. If equal, currType would be set to NEW_DIVE_SITE. Later, _currType_ was compared against _RECENTLY_ADDED_DIVESITE_. This would only work because NEW_DIVE_SITE and RECENTLY_ADDED_DIVESITE both were defined as 1. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: remove argument from diveSiteSelected signalGravatar Berthold Stoeger
The diveSiteSelected signal of DiveLocationLineEdit had the dive-site UUID as argument. But the receiving slot would not use that argument. Remove this as a tiny step to remove the UUIDs alltogether. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: replace UUID_ROLE by DIVESITE_ROLEGravatar Berthold Stoeger
Access to dive-sites in the LocationInformationModel was via UUID. Replace this by a direct access to the struct dive_site pointer. Accordingly, rename the UUID_ROLE to DIVESITE_ROLE. This is a small step in replacing dive-site UUIDs by pointers throughout the code base. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointers to merge_dive_sites()Gravatar Berthold Stoeger
Instead of passing uuids, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Add 'location_t' data structureGravatar Linus Torvalds
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-13Cleanup: rename MainWindow member variablesGravatar Berthold Stoeger
Instead of the weirdly named "information" and the inconsistent "dive_list" use the logical "mainTab" and the camel-cased "diveList", respectively. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Cleanup: Turn widget accessor-functions into simple pointersGravatar Berthold Stoeger
The keeps track of different sub widgets needed by other parts of the code, notably: MainTab PlannerDetails PlannerSettingsWidget ProfileWidget2 DivePlannerWidget DiveListView Access to these widgets was provided with accessor functions. Now these functions were very weird: instead of simply returning pointers that were stored in the class, they accessed a data structure which describes the different application states. But this data structure was "duck-typed", so there was an implicit agreement at which position the pointers to the widgets were put inside. The widgets were then down-cast by the accessor functions. This might make sense if the individual widgets could for some reason be replaced by other widgets [dynamic plugins?], but even then it would be strange, as one would expect to get a pointer to some base class. Therefore, directly store the properly typed pointers to the widgets and simply remove the accessor functions. Why bother? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: replace displayed_dive_site by pointerGravatar Berthold Stoeger
In the dive-site-edit widget, a copy of the current dive site was used to store the old (pre-edit) data. This is not necessary, since we can simply access the data in the original dive site. Thus, replace the subobject by a simple pointer. This is part of a series to replace dive-site uuids by pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: don't use displayed_dive_site to store GPS coordinatesGravatar Berthold Stoeger
The displayed_dive_site object is used in the dive-site-edit widget to store the old (before-edit) data. But it was also used to store the GPS data when changed on the map or the input box. Very confusing. Instead, use the text field as only authoritative source of the GPS data. This introduces a small behavioral change: when changing the text of the GPS text field, update the list of dive sites at the same position. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: use own copy of taxonomy in dive-site-edit widgetGravatar Berthold Stoeger
The dive-site-edit widget uses a copy of the to-be-edited site to compare with old values. Generally, this seems overkill (the original dive-site can be used for such a comparison). But one place where it can't simply be removed is the taxonomy, because the widget needs a place to store the unsaved data. Change the code to use an explicit taxonomy structure instead of the one provided in the copy. This should ultimately allow removal of the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: un-globalize displayed_dive_siteGravatar Berthold Stoeger
The global object displayed_dive_site is used a a backing-store by the dive-site-edit widget. All external accesses were removed, therefore make the object local to the widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: explicitly init displayed_dive_site on show widgetGravatar Berthold Stoeger
The global object "displayed_dive_site" is used to store the old dive site data for the edit-dive-site widget. The fields of the widget were initialized from this object in the show event. Therefore the object was updated in numerous parts of the code to make sure that it was up-to-date. Instead, move the initialization of the object to the function that also initiatlizes the fields. Call this function explicitly before showing the widget. This makes the data-fow distinctly easier to understand. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Map: remove access to displayed_dive_site in GPS-filter modelGravatar Berthold Stoeger
The location information shows a list of dive sites at the same location as the edited dive site. This was done by passing a function to an "SsrfSortFilterProxyModel". Unfortunately, the latter does only support function pointers without state and therefore had to access the global "displayed_dive_site" object. Replace the SsrfSortFilterProxyModel by a proper subclass of QSortFilterProxyModel that contains information on the position and id of the currently edited dive site. Update the filter model if the location of the dive site changes. This introduces a behavioral change: editing the GPS location will lead to an updated list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Map: pass down dive site in prepareForGetDiveCoordinates()Gravatar Berthold Stoeger
Instead of reading out the global object "displayed_dive_site", pass the dive site to be edited in arguments to prepareForGetDiveCoordinates() and enter edit mode. Simplify the code in LocationInformationWidget by not using signals to call the prepareForGetDiveCoordinates() function. While doing this, collect common code in accept() and reject() in the already existing resetState() function. This is another entry in a series of commits that makes data-flow more clear by removing access to the global "displayed_dive_site" object. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Map: pass changed coordinates via signalGravatar Berthold Stoeger
The coordinates of a "dragged flag" were passed out-of-bound via the global "displayed_dive_site" object and then a signal was sent to notify of the changed coordinates. Instead, pass the coordinates directly via the signal. This makes the data- and control-flow more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Map: remove LocationInformationWidget::coordinatesChanged signalGravatar Berthold Stoeger
This was used by LocationInformationWidget to instruct the map that the coordinates of the current dive site has changed. There is no reason why this couldn't be a function call, as no other object ever connect()s to this signal. In fact, such a function already exists viz. updateLocationOnMap. Therefore, replace the signal by a simple function call. Moreover, the uuid and coordinates of the dive site were transported via the global "displayed_dive_site" object. Instead, pass this information in the parameters of the function. This makes it easier to reason about data- and control-flow. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Geo lookup: don't pass arguments / result via global objectGravatar Berthold Stoeger
The reverseGeoLookup() fetches dive-site data via GPS coordinates. The coordinates and the result were passed via the global "displayed_dive_site" object. To make data-flow more clear, pass data as in and out parameters instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Cleanup: remove ReverseGeoLookupThreadGravatar Berthold Stoeger
Fetching the taxonomy from GPS coordinates was implemented in a QThread. But the only access to the main function was a direct call to run(). Thus, the thread was *never* started. The function call was always asynchronous [it was using an event loop though, so the UI doesn't hang]. Notably this means that the signals connected to the thread would never fire. And the spinner would never be activated. Thus: 1) Turn the thread into a simple function. 2) Remove the spinner. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-09Dive locations: factor out common code of modelsGravatar Berthold Stoeger
For increased maintainability, use the same columns, roles and the same accessor function for both dive-site models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-09Map: avoid ugly "invalid dive site" message in location boxGravatar Berthold Stoeger
Under certain conditions the user was presented an ugly "invalid dive site" message. The condition would arise because the proxy-model which selects the list of dive sites and the code which creates a proposed dive site name had different filter conditions: - The proxy would select any dive site containing the text - The name-proposing code searched for dive sites *starting* with the text. If the user entered a text contained by a dive site name, but no dive site would start with the second line was filled with a dummy text. This text would be kept if it contained the text entered by the user. To avoid this problem, if no dive site is found, use an empty string instead. This will be filtered out by the proxy because it does not contain the user-entered string. Yes, that's horribly subtle, therefore add a comment. But ultimately, this should be solved in a less brittle way. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-08Map: zoom on dive sites when flipping through dive site listGravatar Berthold Stoeger
The dive site list was connected to centerOnDiveSite(). Apparently, the currently selected dive site should have been shown in the map. Yet, this never worked, because the actual dive site of the selected dive had precedence in centerOnDiveSite(). It seems that centerOnDiveSite() had actually to purposes: 1) center on the passed in dive site 2) center on the dive sites of the selected dives Therefore, split this function in two separate functions for each of these use-cases. This allows us to remove some pre-processor magic (mobile vs. desktop) and to remove a parameter from the MainTab::diveSiteChanged() signal. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-26desktop: fix multi-keystroke input on locationGravatar Murillo Bernardes
When the tooltip is hidden QInputMethodEvent is handled by QLineEdit and works properly. When the tooltip is visible DiveLocationListView gains focus and receives QInputMethodEvent, without handling them properly. This patch just forwards the event back to the QLineEdit object. Fix #1405 Signed-off-by: Murillo Bernardes <mfbernardes@gmail.com>
2018-05-21desktop-widgets: Change Q_UNUSED to no parameter nameGravatar jan Iversen
C++ permits use of parameters without name, which signals unused Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Core: remove dive.h from files that don't need itGravatar Dirk Hohndel
Of course, quite a few of them indirectly get it through other header files. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-03-14Cleanup: introduce copy_qstring() functionGravatar Berthold Stoeger
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common occurrences that they seem worthy of a short helper-function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14Cleanup: consistently use qPrintable()Gravatar Berthold Stoeger
Replace constructs of the kind s.toUtf8().data(), s.toUtf8().constData(), s.toLocal8Bit().data(), s.toLocal8Bit.constData() or qUtf8Printable(s) by qPrintable(s). This is concise, consistent and - in principle - more performant than the .data() versions. Sadly, owing to a suboptimal implementation, qPrintable(s) currently is a pessimization compared to s.toUtf8().data(). A fix is scheduled for new Qt versions: https://codereview.qt-project.org/#/c/221331/ Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
There are ca. 50 constructs of the kind same_string(s, "") to test for empty or null strings. Replace them by the new helper function empty_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-29cleanup: Unchecked return valueGravatar Jan Mulder
CID 208312 Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-28Replace less-or-equal by less-than comparison in lessThan functionGravatar Berthold Stoeger
DiveLocationFilterProxyModel::lessThan() used less-or-equal instead of less-than comparison. This can lead to subtle bugs if two elements compare as equal. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-30Use better aliases for icons.Gravatar Martin Měřinský
Icon aliases were complete mess. Some icons had alias some didn't. Named with underscores vs. hyphens vs. camelCase. Lower vs. upper case. "ICON" prefix vs. suffix vs. nothing. With vs. without filename suffix. Some didn't make sence. Eg. mapwidget-marker-gray (I can see, it's grey, but what does it represent?) Some were duplicated, eg warning vs. warning-icon. Some were name after widget, which is wrong. Do not reinvent wheel. Use widely used naming scheme close to Freedesktop Icon Naming Specification. This will enable usage of common icons from current set in the future. Thus Subsurface will fit nicely to GUI. This changes icon aliases to one, easy grep-able style. Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-29Revert "Use consistent aliases for all icons."Gravatar Dirk Hohndel
This reverts commit 92e9c6606f6ef3ad16d2e31f9f9a8f5fa14f2c1a.
2017-11-29Use consistent aliases for all icons.Gravatar Martin Měřinský
Icon aliases were inconsistent mess. Underscores vs. hyphens vs. camelCase. With vs. without filename suffix. Lower vs. upper case. "icon" suffix vs. prefix vs. nothing. Some were duplicated, eg warning vs. warning-icon. Some icons didn't have alias at all. This changes all icon aliases to one, easy grep-able style which complies to Freedesktop Icon Naming Specification (Guidelines). Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-27locationinformation: don't update map location on typingGravatar Lubomir I. Ivanov
Currently when the user is typing new coordinates the marker on the map changes location right away. Disable that and add a 'flag' button that should be pressed instead. Also make the coordinates update when pressing Enter or when the text field loses focus. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-26Inform LocationFilterModel of changed dive site nameGravatar Berthold Stoeger
Since commit 01d961086c1d175732c597dc9acdba7cc4cd2d26, the location filter list is updated if a dive site is edited. The problem is that if the name of a selected dive site is changed, the selection is lost. Therefore, before repopulating, inform the location filter that a dive site changed its name. The location filter then internally changes the name and can properly transfer the old selection on repopulate. This is performed via the new LocationInformationWidget::nameChanged signal, which is connected to the new LocationFilterModel::changeName slot. A special case to be handled is the following: [ ] Site 1 [x] Site 2 and "Site 2" being renamed to "Site 1", i.e. both sites being merged. Here, the merging is detected and "Site 1" will likewise be checked: [x] Site 1 [x] Site 1 No merging is performed, as the list will be repopulated anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-09map-widget: allow real-time updates of edited markersGravatar Lubomir I. Ivanov
This patch allows updating the location of map markers while editing a dive site and updating the text in the LocationInformationWidget in real-time. Currently it is only possible to see the marker changes by clicking 'Apply'. The modification required the following changes: - add the MapWidget::updateCurrentDiveSiteCoordinatesToMap() slot and call it each time the GPS text updates - separate the updateCurrentDiveSiteCoordinates(FromMap/ToMap) logic by having the FromMap/ToMap suffix to method names - make MapWidgetHelper::updateCurrentDiveSiteCoordinatesToMap() call a new MapLocationModel::updateMapLocationCoordinates() method, which updates selected location coordinates and the model - add MapLocation::setCoordinateNoEmit() that does not emit a signal when updating a coordinate Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-17Tags for geo references: Nicer look, translations and warning messageGravatar Stefan Fuchs
For the geo references tags update the following: - Nicer look w/o "Tags:" text and brackets when inside location UI - Translation for "Tags:" - Warning message when no dive site layout categories are set Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16In location information UI set reverse geo lookup button activ...Gravatar Stefan Fuchs
as soon as coordinates are available . Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-09Use lrint() for all degrees_t related roundingGravatar Lubomir I. Ivanov
In certain places the '(int)' cast is used, while in other the llrint() or lrint() functions. Make the conversation from degrees in the 'double' form to the 'int' degrees_t consistent using lrint(). lrint() is the function which should give the best results, because it accepts a 'double' and results in a 'long' even if degrees_t is 'int'. If the truncation from 'long' to 'int' is discarding some of the precision then the next step would be to turn degrees_t into a 64bit signed integer type. Possible fix for #625. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>