Commit graph

36 commits

Author SHA1 Message Date
Berthold Stoeger
8a3a0edb83 cleanup: silence std::move()-related Coverity warnings
Unfortunately Coverity doesn't understand that most Qt data
structures are copy-on-write. It's a mis-feature of Qt, but
it is the way it is. Thus, passing by value is not an issue.

Out of ca. 25 warnings only two were legit. Let's silence
the others by either std::move()ing or passing by reference,
as would be idiomatic C++, which Qt is not.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-15 15:11:36 -08:00
Berthold Stoeger
d51589b9a7 printing: don't access displayed_dive in printing code
To phase out this global variable, avoid access of displayed_dive
in the printing code. This is used when printing a plan. Instead,
when in plan-mode, pass the planned dive to the printing code
as a single dive to be printed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
42cff9b3a5 planner: pass in_planner down to TemplateLayout
The TemplateLayout prints different dives depending on
whether the planner is active. Instead of accessing a
global variable, pass the status down from the MainWindow.
That's all quite convoluted, since there are multiple
layers involved.

On the positive side, the in_planner() function has now
no users an can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
622e9ba373 printing: "fix" progress indicator
In TemplateLayout, there was a progress indication, which reported
the progress - not of the actual rendering - but of adding the
dives to the "to render" list. Which is of course done in less than
a ms, making the whole thing completely pointless.

Instead, emit progress when actually looping over the dives or
statistics.

Nobody ever noticed the problem because even rendering is done in
fractions of a second and indeed is accounted to only one fifth
of the total progress.

The real purpose of this "fix" is to get rid of the getTotalWork()
function, which was just insane. Instead of asking the TemplateLayout
how many dives it rendered, this number was extracted from
global state. Simply store the number of dives in the TemplateLayout
object instead.

Moreover, fix two coding style issues:
 - "Page" variable identifier starting with a capital
 - The Printer::render() being defined (as opposed to declared) with
   a default parameter. This is not how C++'s default parameters work,
   sorry.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 12:20:25 -08:00
Berthold Stoeger
cc5ebd7414 printing: remove CylinderObjectHelper
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>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
d9942269a9 printing: remove DiveObjectHelperGrantlee
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>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
fa6eb6144b printing: move #includes from headers to source files
To decrease include-file interdependencies.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
2239ffe13c printing: remove YearInfo structure
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>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
0310eb31da printing: refactor if and loop code
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>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
f42a70586b printing: remove objects QVariant map
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>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
0cbb448740 cleanup: make templateOptions and printOptions reference types
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>
2020-12-17 13:03:56 -08:00
Robert C. Helling
51c84b3c44 Remove code references to Grantlee
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>
2020-10-08 12:19:39 -07:00
Robert C. Helling
c9106b9dbe Interpret divelist printing templates
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>
2020-10-08 12:19:39 -07:00
Berthold Stoeger
9ed886e4be Cleanup: lower-case filenames in core/subsurface-qt/
We tend to use lower-case filenames. Let's do it for these files
as well. Simple search & replace.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-04 02:16:46 +01:00
Berthold Stoeger
718c07c1a8 Grantlee: split out grantlee-only property from DiveObjectHelper
The cylindersObject list was only used by grantlee but not by
the mobile code. Since it is quite heavy, split it out and thus
don't generate it for every dive on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
Berthold Stoeger
6a9df3bba3 Mobile: transform DiveObjectHelper into value-type
Instead of handing a reference-to-dive to QML, prerender all the needed
properties and store them as values in DiveObjectHelper. Exception:
 - date(): generated from timestamp
 - time(): generated from timestamp
 - cylinderList(): does not depend on dive anyway and should be made
   static.

This hopefully avoids the random mobile crashes that we are seeing.
Clearly, this code needs to be optimized, but it is a start.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
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
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
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
Berthold Stoeger
57c01f7a66 Translations: unify gettextFromC::tr() and QObject::tr()
There were two catch-all classes for translations outside of class
context. gettextFromC was used exclusively from C, but C++ used
both, gettextFromC and QObject. Some of the string were even present
in both. Therefore, unify to gettextFromC throughout the code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-04 05:33:31 +08: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
Stefan Fuchs
95a23cf470 Use temperature_t for temperatures in struct stats_t
Use struct temperature_t for temperatures in struct stats_t and
use get_temperature_string() when printing these temperatures for
statistics and HTML export.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-24 11:45:17 -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
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
Stefan Fuchs
e6d884cf26 Creation of dive duration string and surface interval string
Update the function to create the dive duration string in a way that
it can be used also in info and stats tab and added some more flexibility.

Changed layout for <1h freedives to "0:05:35" (w/o units) or "5:35min"
(with units and :) or "5min 35sec" (with units with space).

Add a new function to create the surface interval string.

Completely remove old function get_time_string() and get_time_string_s().

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-05-26 15:50:52 -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
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
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Tomaz Canabrava
a13fa83046 Removed grantlee template code to deal with non-Qobject
Since we alreday have a Q_PROPERTY on the DiveObjectHelper,
grantlee introspection can use that directly to access it's
data, so there's no need for us to redeclare everything.

More QObject Introspection, Less handmade boilerplate for
Grantlee, QML, and a few other things.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-08 08:05:36 -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
Lubomir I. Ivanov
7e749e8ea4 qthelper: also support "maxcns" and "otu" in Grantlee HTML
Fixes #962

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-16 15:06:32 -08:00
Lubomir I. Ivanov
c78a560442 templatelayout.h: expose cylinders and weights in Grantlee HTML
This patch adds the following HTML variables:
"dive.cylinders" -> Dive::cylinders()
"dive.cylinderX" -> Dive::cylinder(X)
"dive.weights" -> Dive::weights()
"dive.weightX" -> Dive::weight(X)

The patch also creates some macros to ease the Dive variable
lookup visually.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-16 15:04:25 -08:00
Lubomir I. Ivanov
3365a506ef templatelayout.h: expose "dive.suit" as a Grantlee HTML variable
Having {{ dive.suit }} in the HTML will now return the
suit as QString (from struct dive->suit).

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-16 15:03:59 -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.h (Browse further)