diff data/model/Model.h @ 1671:82d03c9661f9 single-point

Rework isReady()/getCompletion() on models. Previously the new overhauled models were implementing getCompletion() but inheriting a version of isReady() (from the Model base) that didn't call it, referring only to isOK(). So they were reporting completion as soon as they had begun. Instead hoist getCompletion() to abstract base and call it from Model::isReady().
author Chris Cannam
date Wed, 27 Mar 2019 13:15:16 +0000
parents f9b6e99e0520
children 0d89abd631ac
line wrap: on
line diff
--- a/data/model/Model.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/Model.h	Wed Mar 27 13:15:16 2019 +0000
@@ -133,22 +133,42 @@
     /**
      * Return true if the model has finished loading or calculating
      * all its data, for a model that is capable of calculating in a
-     * background thread.  The default implementation is appropriate
-     * for a thread that does not background any work but carries out
-     * all its calculation from the constructor or accessors.
+     * background thread.
      *
-     * If "completion" is non-NULL, this function should return
-     * through it an estimated percentage value showing how far
-     * through the background operation it thinks it is (for progress
-     * reporting).
+     * If "completion" is non-NULL, return through it an estimated
+     * percentage value showing how far through the background
+     * operation it thinks it is (for progress reporting). This should
+     * be identical to the value returned by getCompletion().
+     *
+     * A model that carries out all its calculation from the
+     * constructor or accessor functions would typically return true
+     * (and completion == 100) as long as isOK() is true. Other models
+     * may make the return value here depend on the internal
+     * completion status.
      *
      * See also getCompletion().
      */
-    virtual bool isReady(int *completion = 0) const {
-        bool ok = isOK();
-        if (completion) *completion = (ok ? 100 : 0);
-        return ok;
+    virtual bool isReady(int *cp = nullptr) const {
+        int c = getCompletion();
+        if (cp) *cp = c;
+        if (!isOK()) return false;
+        else return (c == 100);
     }
+    
+    /**
+     * Return an estimated percentage value showing how far through
+     * any background operation used to calculate or load the model
+     * data the model thinks it is. Must return 100 when the model is
+     * complete.
+     *
+     * A model that carries out all its calculation from the
+     * constructor or accessor functions might return 0 if isOK() is
+     * false and 100 if isOK() is true. Other models may make the
+     * return value here depend on the internal completion status.
+     *
+     * See also isReady().
+     */
+    virtual int getCompletion() const = 0;
 
     /**
      * If this model imposes a zoom constraint, i.e. some limit to the