changeset 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 623231712470
children b5580d93f28b
files data/model/AggregateWaveModel.h data/model/AlignmentModel.h data/model/Model.h data/model/NoteModel.h data/model/ReadOnlyWaveFileModel.h data/model/RegionModel.h data/model/SparseOneDimensionalModel.h data/model/SparseTimeValueModel.h data/model/TextModel.h data/model/WritableWaveFileModel.cpp data/model/WritableWaveFileModel.h data/model/test/MockWaveModel.h
diffstat 12 files changed, 54 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/AggregateWaveModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/AggregateWaveModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -41,6 +41,11 @@
 
     bool isOK() const override;
     bool isReady(int *) const override;
+    int getCompletion() const override {
+        int c = 0;
+        (void)isReady(&c);
+        return c;
+    }
 
     QString getTypeName() const override { return tr("Aggregate Wave"); }
 
--- a/data/model/AlignmentModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/AlignmentModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -41,6 +41,11 @@
     sv_frame_t getEndFrame() const override;
     sv_samplerate_t getSampleRate() const override;
     bool isReady(int *completion = 0) const override;
+    int getCompletion() const override {
+        int c = 0;
+        (void)isReady(&c);
+        return c;
+    }
     const ZoomConstraint *getZoomConstraint() const override;
 
     QString getTypeName() const override { return tr("Alignment"); }
--- 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
--- a/data/model/NoteModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/NoteModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -129,7 +129,7 @@
     float getValueMinimum() const { return m_valueMinimum; }
     float getValueMaximum() const { return m_valueMaximum; }
     
-    int getCompletion() const { return m_completion; }
+    int getCompletion() const override { return m_completion; }
 
     void setCompletion(int completion, bool update = true) {
 
--- a/data/model/ReadOnlyWaveFileModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/ReadOnlyWaveFileModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -54,6 +54,11 @@
 
     bool isOK() const override;
     bool isReady(int *) const override;
+    int getCompletion() const override {
+        int c = 0;
+        (void)isReady(&c);
+        return c;
+    }
 
     const ZoomConstraint *getZoomConstraint() const override { return &m_zoomConstraint; }
 
--- a/data/model/RegionModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/RegionModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -107,7 +107,7 @@
     float getValueMinimum() const { return m_valueMinimum; }
     float getValueMaximum() const { return m_valueMaximum; }
     
-    int getCompletion() const { return m_completion; }
+    int getCompletion() const override { return m_completion; }
 
     void setCompletion(int completion, bool update = true) {
 
--- a/data/model/SparseOneDimensionalModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/SparseOneDimensionalModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -81,8 +81,8 @@
     QString getDefaultPlayClipId() const override { return "tap"; }
     
     bool hasTextLabels() const { return m_haveTextLabels; }
-    
-    int getCompletion() const { return m_completion; }
+        
+    int getCompletion() const override { return m_completion; }
 
     void setCompletion(int completion, bool update = true) {
         
--- a/data/model/SparseTimeValueModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/SparseTimeValueModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -111,7 +111,7 @@
     float getValueMinimum() const { return m_valueMinimum; }
     float getValueMaximum() const { return m_valueMaximum; }
     
-    int getCompletion() const { return m_completion; }
+    int getCompletion() const override { return m_completion; }
 
     void setCompletion(int completion, bool update = true) {
         
--- a/data/model/TextModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/TextModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -69,7 +69,7 @@
     sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
     int getResolution() const { return m_resolution; }
     
-    int getCompletion() const { return m_completion; }
+    int getCompletion() const override { return m_completion; }
 
     void setCompletion(int completion, bool update = true) {
         
--- a/data/model/WritableWaveFileModel.cpp	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/WritableWaveFileModel.cpp	Wed Mar 27 13:15:16 2019 +0000
@@ -221,15 +221,6 @@
     return (m_model && m_model->isOK());
 }
 
-bool
-WritableWaveFileModel::isReady(int *completion) const
-{
-    int c = getCompletion();
-    if (completion) *completion = c;
-    if (!isOK()) return false;
-    return (c == 100);
-}
-
 void
 WritableWaveFileModel::setWriteProportion(int proportion)
 {
--- a/data/model/WritableWaveFileModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/WritableWaveFileModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -139,7 +139,6 @@
     int getWriteProportion() const;
     
     bool isOK() const override;
-    bool isReady(int *) const override;
     
     /**
      * Return the generation completion percentage of this model. This
@@ -147,7 +146,7 @@
      * -- it just contains varying amounts of data depending on how
      * much has been written.
      */
-    virtual int getCompletion() const { return 100; }
+    int getCompletion() const override { return 100; }
 
     const ZoomConstraint *getZoomConstraint() const override {
         static PowerOfSqrtTwoZoomConstraint zc;
--- a/data/model/test/MockWaveModel.h	Wed Mar 27 11:26:22 2019 +0000
+++ b/data/model/test/MockWaveModel.h	Wed Mar 27 13:15:16 2019 +0000
@@ -51,6 +51,7 @@
     sv_frame_t getEndFrame() const override { return m_data[0].size(); }
     sv_samplerate_t getSampleRate() const override { return 44100; }
     bool isOK() const override { return true; }
+    int getCompletion() const override { return 100; }
     
     QString getTypeName() const override { return tr("Mock Wave"); }