Commit graph

29 commits

Author SHA1 Message Date
Berthold Stoeger
be763452ad DiveObjectHelper: Turn DiveObjectHelper into Q_GADGET based object
DiveObjectHelper is a tiny wrapper around dive * to allow access
to dive data from QML and grantlee. It doesn't have to be a
full-fledged QObject with support for signals, etc. Therefore,
turn it into a Q_GADGET based object. This allows us passing the
object around as object, not as pointer to DiveObjectHelper.
This makes memory-management distinctly easier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
Berthold Stoeger
f25fa2adc5 Cleanup: turn CylinderObjectHelper into value type
CylinderObjectHelper is used for structured formatting of cylinder
values in grantlee types. Instead of keeping a reference to a
cylinder, turn it into a value type containing the formatted strings.

This should be distinctly safer, as we don't risk having stale
references flying around. Moreover, we don't have to use pointers
but can use containers containing plain CylinderObjectHelper. Thus,
no explicit memory management is needed, making the code distinctly
easier to understand.

Sadly, currently grantlee does not support Q_GADGET based Q_PROPERTY.
Therefore a GRANTLEE_*_LOOKUP block has to be added. This can be
removed in due course, as a patch to remedy this issue is in current
grantlee master.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-22 10:13:40 -07:00
Berthold Stoeger
efb98cfd69 Printing: use regexp in preprocessTemplate()
preprocessTemplate() replaces variables of the kind "dive.weight0"
by "dive.weights.0". Replace the old code by regexps. This not
only makes the code significantly shorter, it also makes it independent
from the name of the dive variable (i.e. "dive").

Moreover, it removes a dependency on MAX_WEIGHTSYSTEMS and MAX_CYLINDERS,
which might help in removing these restrictions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-06 14:52:42 +03:00
Berthold Stoeger
ef76905590 Cleanup: simplify YearInfo class
YearInfo is a trivial wrapper around "stats_t *". All the
constructor / destructor rigmarole seems completely unnecessary.
Remove it. Probably the whole class could be removed, but for
that I'd need more insight into Grantlee, which is low on my
list of priorities for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
8165abf2e7 Cleanup: remove stale include in desktop-widgets/templatelayout.cpp
Including <string> is not necessary in this file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
d498fcad61 Printing: fix memory leak
For printing, DiveObjectHelpers are allocated and pointers to these
are stored in a QVariantList. The objects are never freed. To fix
this leak, keep the objects in a std::list<>.

std::list<> was chosen because
1) Pointers to elements stay valid during its lifetime.
2) Objects can be constructed directly in the list with emplace_back()

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
af00361929 Cleanup: rename variable PrintOptions to printOptions
We're quite inconsistent when it comes to variable naming.
The general usage is camelCase for Qt parts and snake_case
for core code. Virtually nowhere do we start variable names
with a capital letter. Therefore, turn this one weird case
into camelCase.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
449dec8269 Cleanup: remove TemplateLayout::m_engine member variable
TemplateLayout::m_engine is a Grantlee::Engine that is reallocated
for every function call. Instead of the archaic memory-management,
remove the member variable and make it a local variable of the
two functions that need it. There seems to be no point in keeping
the object alive beyond the function's scope.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Rolf Eike Beer
c4c8094e32 get rid of some foreach and Q_FOREACH constructs
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-04-12 12:59:17 +03:00
Berthold Stoeger
30230dce10 Cleanup: remove all Q_NULLPTR instances
It expands to nullptr anyway and is inconsitent with the rest of the
code. Let's remove this anachronism.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-02 07:34:46 -07:00
Berthold Stoeger
df16866292 Statistics: only consider selected dives in HTML export statistics
If only selected dives were exported into HTML, the statistics would
nevertheless cover all dives. A counter-intuitive behavior. Fix by
adding a selected_only flag to calculate_stats_summary().

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 17:50:51 +03:00
Berthold Stoeger
97991e2b9f Statistics: remove global state / calculate only when needed
Statistics were calculated into global variables every time the
current dive was changed.

Calculate statistics only when needed and into a structure
provided by the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 17:50:51 +03:00
Berthold Stoeger
36b9e5e31e Cleanup: fold core/helpers.h into core/qthelper.h
helpers.h included qthelper.h and all functions declared in helpers.h
were defined in qthelper.h. Therefore fold the former into the latter,
since the split seems completely arbitrary.

While doing so, change the return-type of get_dc_nichname from
"const QString" to "QString".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04 08:50:10 -07:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
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-03-14 13:55:36 +02:00
Jan Mulder
ba813483dd cleanup: Uninitialized pointer field
CID 208320

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-29 09:14:20 -08:00
Lubomir I. Ivanov
65f0600679 printing: update the coping of bundled templates
This update includes:
- Instead of copyPath() use a new specialized function:
  copy_bundled_templates()
- The new function supports overwriting of templates
in the user path, but only if a template file is read-only
- If the file is RW create a backup of the file in the
form of: <file-name>-User.html
- Collect backup files and store them in a QStringList
which is then shown in a QMessageBox from MainWindow
to notifying the user about the backup

This change allows moving the maintenance of the bundled
templates back to the application developers and contributors
as currently the only one who can edit the templates in the user
path was the user.

Suggested-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-24 23:06:52 +02:00
Lubomir I. Ivanov
fc48cde77c printing: only load *.html files in the UI
The function find_all_templates() thus far handled
all files in the user template directory.

This patch makes it so that only files with the .html
extension are loaded.

Also remove brackets for single lined `if` statement.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-24 23:06:51 +02:00
Lubomir I. Ivanov
9209382c18 printing: add set_bundled_templates_as_read_only()
Add the function set_bundled_templates_as_read_only()
in templatelayout.cpp/h. The function is used to
mark the bundled template files as read-only in
the user folder. It is called in mainwindow.cpp,
after the files are copied from the bundle.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-24 21:50:12 +02:00
Robert C. Helling
a6f186279f Add a checkbox to turn off plan variations
... as those come with a performance penalty

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-09-20 08:54:41 -07:00
Dirk Hohndel
9021a44ccc Add SPDX header to desktop widgets
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Jeremie Guichard
597539ce39 Fix double to int truncation in C++ code
Wfloat-conversion enabled for C++ part of the code
Fix warnings raised by the flag using lrint

Original issue reported on the mailing list:
The ascent/descent rates are sometimes not what is expected.
E.g. setting the ascent rate to 10m/min results in an actual
ascent rate of 9m/min.
This is due to truncating the ascent rate preference,
then effectively rounding up the time to reach each stop to 2s intervals.
The result being that setting the ascent rate to 10m/min
results in 20s to ascend 3m (9m/min), when it should be exactly 18s.

Reported-by: John Smith <noseygit@hotmail.com>
Reported-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-24 09:39:25 -07:00
Linus Torvalds
ad2ac58ea2 Fix include paths
As expected, commit 7be962bfc2 ("Move subsurface-core to core and qt-mobile
to mobile-widgets") caused some breakage.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 09:40:58 -07:00
Lubomir I. Ivanov
b275e604c1 templatelayout.cpp: fix potential issue in preprocessTemplate()
The function preprocessTemplate(), did not account well
for indexes in Grantlee variables, such as:
dive.weight# (where # is the index)
dive.cylinder#

To solve the issue the list (QList<QPair<QString, QString> >)
for variables to be replaced is populated will all possible
indexes:
0 - MAX_WEIGHTSYSTEM for weights
0 - MAX_CYLINDERS for cylinders

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 15:42:33 -08:00
Lubomir I. Ivanov
0aa8ef918d templatelayout.cpp: add a HTML preprocessor stage
The current Grantlee template loading scheme does not
allow a preprocessing layer. With the recent DiveObjectHelper
changes the layer is required if we don't want to add a set
of dummy methods and Q_PROPERTIES which will only inflate
the DiveObjectHelper class.

Use the already present helper readTemplate() to load the
raw HTML template and pass it to a static function which
does some variable replacement to accomudate DiveObjectHelper.

This change is done for the sake of not breaking the Grantlee
HTML variables on the user side!

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-29 07:32:57 -08:00
Tomaz Canabrava
04d4da50c4 Fix memory leak on the printing system
We forgot to delete the Grantlee object before creating a new one

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-08 10:03:12 -08:00
Tomaz Canabrava
f07a9fa09f Simplify Finding the Templates
We don't need a list of QFileInfo if we are not using it
much better to have a list of the files directly

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-08 10:03:06 -08:00
Tomaz Canabrava
a809eec853 Don't iterate over the dive_table to discover the number of dives
dive_table.nr is exactly that.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-08 10:02:35 -08:00
Tomaz Canabrava
25aa80846b Move Dive class from qthelper.h/cpp to it's own file
and rename it to DiveObjectHelper, since it should be an QObject
based class to make it easier on the QML, grantlee and widgets
side to display the dive's internal data.

each Q_PROPERTY defined in the DiveObjectHelper.h file
can be acessed directly via it's name.

So, if you are on a model that  returns a dive, acess it's name
by dive.name

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-08 08:04:44 -08:00
Tomaz Canabrava
e49d6213ad Move qt-ui to desktop-widgets
Since we have now destkop and mobile versions, 'qt-ui' was a very
poor name choice for a folder that contains only destkop-enabled
widgets.

Also, move the graphicsview-common.h/cpp to subsurface-core because
it doesn't depend on qgraphicsview, it merely implements all the
colors that we use throughout Subsurface, and we will use colors on both
desktop and mobile versions

Same thing applies for metrics.h/cpp

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-30 10:36:49 -07:00
Renamed from qt-ui/templatelayout.cpp (Browse further)