comparison 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
comparison
equal deleted inserted replaced
1670:623231712470 1671:82d03c9661f9
131 } 131 }
132 132
133 /** 133 /**
134 * Return true if the model has finished loading or calculating 134 * Return true if the model has finished loading or calculating
135 * all its data, for a model that is capable of calculating in a 135 * all its data, for a model that is capable of calculating in a
136 * background thread. The default implementation is appropriate 136 * background thread.
137 * for a thread that does not background any work but carries out 137 *
138 * all its calculation from the constructor or accessors. 138 * If "completion" is non-NULL, return through it an estimated
139 * 139 * percentage value showing how far through the background
140 * If "completion" is non-NULL, this function should return 140 * operation it thinks it is (for progress reporting). This should
141 * through it an estimated percentage value showing how far 141 * be identical to the value returned by getCompletion().
142 * through the background operation it thinks it is (for progress 142 *
143 * reporting). 143 * A model that carries out all its calculation from the
144 * constructor or accessor functions would typically return true
145 * (and completion == 100) as long as isOK() is true. Other models
146 * may make the return value here depend on the internal
147 * completion status.
144 * 148 *
145 * See also getCompletion(). 149 * See also getCompletion().
146 */ 150 */
147 virtual bool isReady(int *completion = 0) const { 151 virtual bool isReady(int *cp = nullptr) const {
148 bool ok = isOK(); 152 int c = getCompletion();
149 if (completion) *completion = (ok ? 100 : 0); 153 if (cp) *cp = c;
150 return ok; 154 if (!isOK()) return false;
151 } 155 else return (c == 100);
156 }
157
158 /**
159 * Return an estimated percentage value showing how far through
160 * any background operation used to calculate or load the model
161 * data the model thinks it is. Must return 100 when the model is
162 * complete.
163 *
164 * A model that carries out all its calculation from the
165 * constructor or accessor functions might return 0 if isOK() is
166 * false and 100 if isOK() is true. Other models may make the
167 * return value here depend on the internal completion status.
168 *
169 * See also isReady().
170 */
171 virtual int getCompletion() const = 0;
152 172
153 /** 173 /**
154 * If this model imposes a zoom constraint, i.e. some limit to the 174 * If this model imposes a zoom constraint, i.e. some limit to the
155 * set of resolutions at which its data can meaningfully be 175 * set of resolutions at which its data can meaningfully be
156 * displayed, then return it. 176 * displayed, then return it.