# HG changeset patch # User Chris Cannam # Date 1553692516 0 # Node ID 82d03c9661f953c6e9b7173b1c7f7482b60391fe # Parent 6232317124707e7cb6d2242d5278c4287428f38a 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(). diff -r 623231712470 -r 82d03c9661f9 data/model/AggregateWaveModel.h --- 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"); } diff -r 623231712470 -r 82d03c9661f9 data/model/AlignmentModel.h --- 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"); } diff -r 623231712470 -r 82d03c9661f9 data/model/Model.h --- 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 diff -r 623231712470 -r 82d03c9661f9 data/model/NoteModel.h --- 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) { diff -r 623231712470 -r 82d03c9661f9 data/model/ReadOnlyWaveFileModel.h --- 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; } diff -r 623231712470 -r 82d03c9661f9 data/model/RegionModel.h --- 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) { diff -r 623231712470 -r 82d03c9661f9 data/model/SparseOneDimensionalModel.h --- 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) { diff -r 623231712470 -r 82d03c9661f9 data/model/SparseTimeValueModel.h --- 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) { diff -r 623231712470 -r 82d03c9661f9 data/model/TextModel.h --- 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) { diff -r 623231712470 -r 82d03c9661f9 data/model/WritableWaveFileModel.cpp --- 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) { diff -r 623231712470 -r 82d03c9661f9 data/model/WritableWaveFileModel.h --- 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; diff -r 623231712470 -r 82d03c9661f9 data/model/test/MockWaveModel.h --- 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"); }