One indirect call site of plotDive, MainTab::acceptChanges, can
trigger a replot several times during one pass through
acceptChanges.  Avoiding some of the replots is both an
optimization and a small bug-fix.  A replot could happen when
displayed_dive is presently zeroed-out, which made no sense.

Signed-off-by: K. Heller <[email protected]>
---
 dive.h                           |  5 +++++
 qt-ui/profile/profilewidget2.cpp | 17 +++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/dive.h b/dive.h
index cef1106..cdb05ee 100644
--- a/dive.h
+++ b/dive.h
@@ -562,6 +562,11 @@ static inline struct divecomputer *get_dive_dc(struct dive 
*dive, int nr)
        return dc;
 }
 
+static inline bool dive_has_meaningful_state(struct dive *dive)
+{
+       return dive && (dive->id > 0);
+}
+
 extern timestamp_t dive_endtime(const struct dive *dive);
 
 extern void make_first_dc(void);
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 3ccd1bb..2fa8f88 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -489,17 +489,22 @@ void ProfileWidget2::resetZoom()
 // Currently just one dive, but the plan is to enable All of the selected 
dives.
 void ProfileWidget2::plotDive(struct dive *d, bool force)
 {
+       if (!d) {
+               if (selected_dive == -1)
+                       return;
+               d = current_dive; // display the current dive
+       }
+
+       // check for 'meaningful' dive. saves spurious repaint(s) while 
carrying out
+       // updates due to clicking 'Apply changes' (or similar actions)
+       if (!dive_has_meaningful_state(d))
+               return;
+
        static bool firstCall = true;
        QTime measureDuration; // let's measure how long this takes us (maybe 
we'll turn of TTL calculation later
        measureDuration.start();
 
        if (currentState != ADD && currentState != PLAN) {
-               if (!d) {
-                       if (selected_dive == -1)
-                               return;
-                       d = current_dive; // display the current dive
-               }
-
                // No need to do this again if we are already showing the same 
dive
                // computer of the same dive, so we check the unique id of the 
dive
                // and the selected dive computer number against the ones we are
-- 
2.5.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to