comparison data/model/SparseModel.h @ 1580:c01cbe41aeb5 fix-static-analysis

Use override throughout
author Chris Cannam
date Mon, 26 Nov 2018 13:48:45 +0000
parents f68911282993
children 0e0947896fd3
comparison
equal deleted inserted replaced
1579:232d6ddf257d 1580:c01cbe41aeb5
53 public: 53 public:
54 SparseModel(sv_samplerate_t sampleRate, int resolution, 54 SparseModel(sv_samplerate_t sampleRate, int resolution,
55 bool notifyOnAdd = true); 55 bool notifyOnAdd = true);
56 virtual ~SparseModel() { } 56 virtual ~SparseModel() { }
57 57
58 virtual bool isOK() const { return true; } 58 bool isOK() const override { return true; }
59 virtual sv_frame_t getStartFrame() const; 59 virtual sv_frame_t getStartFrame() const;
60 virtual sv_frame_t getEndFrame() const; 60 virtual sv_frame_t getEndFrame() const;
61 virtual sv_samplerate_t getSampleRate() const { return m_sampleRate; } 61 sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
62 62
63 // Number of frames of the underlying sample rate that this model 63 // Number of frames of the underlying sample rate that this model
64 // is capable of resolving to. For example, if m_resolution == 10 64 // is capable of resolving to. For example, if m_resolution == 10
65 // then every point in this model will be at a multiple of 10 65 // then every point in this model will be at a multiple of 10
66 // sample frames and should be considered to cover a window ending 66 // sample frames and should be considered to cover a window ending
145 * Return true if the given point is found in this model, false 145 * Return true if the given point is found in this model, false
146 * otherwise. 146 * otherwise.
147 */ 147 */
148 virtual bool containsPoint(const PointType &point); 148 virtual bool containsPoint(const PointType &point);
149 149
150 virtual bool isReady(int *completion = 0) const { 150 bool isReady(int *completion = 0) const override {
151 bool ready = isOK() && (m_completion == 100); 151 bool ready = isOK() && (m_completion == 100);
152 if (completion) *completion = m_completion; 152 if (completion) *completion = m_completion;
153 return ready; 153 return ready;
154 } 154 }
155 155
156 virtual void setCompletion(int completion, bool update = true); 156 virtual void setCompletion(int completion, bool update = true);
157 virtual int getCompletion() const { return m_completion; } 157 virtual int getCompletion() const { return m_completion; }
158 158
159 virtual bool hasTextLabels() const { return m_hasTextLabels; } 159 virtual bool hasTextLabels() const { return m_hasTextLabels; }
160 160
161 virtual bool isSparse() const { return true; } 161 bool isSparse() const override { return true; }
162 162
163 QString getTypeName() const { return tr("Sparse"); } 163 QString getTypeName() const override { return tr("Sparse"); }
164 164
165 virtual QString getXmlOutputType() const { return "sparse"; } 165 virtual QString getXmlOutputType() const { return "sparse"; }
166 166
167 virtual void toXml(QTextStream &out, 167 virtual void toXml(QTextStream &out,
168 QString indent = "", 168 QString indent = "",
169 QString extraAttributes = "") const; 169 QString extraAttributes = "") const;
170 170
171 virtual QString toDelimitedDataString(QString delimiter) const { 171 QString toDelimitedDataString(QString delimiter) const override {
172 return toDelimitedDataStringWithOptions 172 return toDelimitedDataStringWithOptions
173 (delimiter, DataExportDefaults); 173 (delimiter, DataExportDefaults);
174 } 174 }
175 175
176 virtual QString toDelimitedDataStringWithOptions(QString delimiter, 176 QString toDelimitedDataStringWithOptions(QString delimiter,
177 DataExportOptions opts) const { 177 DataExportOptions opts) const override {
178 return toDelimitedDataStringSubsetWithOptions 178 return toDelimitedDataStringSubsetWithOptions
179 (delimiter, opts, 179 (delimiter, opts,
180 std::min(getStartFrame(), sv_frame_t(0)), getEndFrame()); 180 std::min(getStartFrame(), sv_frame_t(0)), getEndFrame());
181 } 181 }
182 182
183 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const { 183 QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const override {
184 return toDelimitedDataStringSubsetWithOptions 184 return toDelimitedDataStringSubsetWithOptions
185 (delimiter, DataExportDefaults, f0, f1); 185 (delimiter, DataExportDefaults, f0, f1);
186 } 186 }
187 187
188 virtual QString toDelimitedDataStringSubsetWithOptions(QString delimiter, DataExportOptions opts, sv_frame_t f0, sv_frame_t f1) const { 188 QString toDelimitedDataStringSubsetWithOptions(QString delimiter, DataExportOptions opts, sv_frame_t f0, sv_frame_t f1) const override {
189 if (opts & DataExportFillGaps) { 189 if (opts & DataExportFillGaps) {
190 return toDelimitedDataStringSubsetFilled(delimiter, opts, f0, f1); 190 return toDelimitedDataStringSubsetFilled(delimiter, opts, f0, f1);
191 } else { 191 } else {
192 QString s; 192 QString s;
193 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { 193 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
208 AddPointCommand(SparseModel<PointType> *model, 208 AddPointCommand(SparseModel<PointType> *model,
209 const PointType &point, 209 const PointType &point,
210 QString name = "") : 210 QString name = "") :
211 m_model(model), m_point(point), m_name(name) { } 211 m_model(model), m_point(point), m_name(name) { }
212 212
213 virtual QString getName() const { 213 QString getName() const override {
214 return (m_name == "" ? tr("Add Point") : m_name); 214 return (m_name == "" ? tr("Add Point") : m_name);
215 } 215 }
216 216
217 virtual void execute() { m_model->addPoint(m_point); } 217 void execute() override { m_model->addPoint(m_point); }
218 virtual void unexecute() { m_model->deletePoint(m_point); } 218 void unexecute() override { m_model->deletePoint(m_point); }
219 219
220 const PointType &getPoint() const { return m_point; } 220 const PointType &getPoint() const { return m_point; }
221 221
222 private: 222 private:
223 SparseModel<PointType> *m_model; 223 SparseModel<PointType> *m_model;
234 public: 234 public:
235 DeletePointCommand(SparseModel<PointType> *model, 235 DeletePointCommand(SparseModel<PointType> *model,
236 const PointType &point) : 236 const PointType &point) :
237 m_model(model), m_point(point) { } 237 m_model(model), m_point(point) { }
238 238
239 virtual QString getName() const { return tr("Delete Point"); } 239 QString getName() const override { return tr("Delete Point"); }
240 240
241 virtual void execute() { m_model->deletePoint(m_point); } 241 void execute() override { m_model->deletePoint(m_point); }
242 virtual void unexecute() { m_model->addPoint(m_point); } 242 void unexecute() override { m_model->addPoint(m_point); }
243 243
244 const PointType &getPoint() const { return m_point; } 244 const PointType &getPoint() const { return m_point; }
245 245
246 private: 246 private:
247 SparseModel<PointType> *m_model; 247 SparseModel<PointType> *m_model;
262 virtual void deletePoint(const PointType &point); 262 virtual void deletePoint(const PointType &point);
263 263
264 /** 264 /**
265 * Stack an arbitrary other command in the same sequence. 265 * Stack an arbitrary other command in the same sequence.
266 */ 266 */
267 virtual void addCommand(Command *command) { addCommand(command, true); } 267 void addCommand(Command *command) override { addCommand(command, true); }
268 268
269 /** 269 /**
270 * If any points have been added or deleted, return this 270 * If any points have been added or deleted, return this
271 * command (so the caller can add it to the command history). 271 * command (so the caller can add it to the command history).
272 * Otherwise delete the command and return NULL. 272 * Otherwise delete the command and return NULL.
291 QString newLabel) : 291 QString newLabel) :
292 m_model(model), m_oldPoint(point), m_newPoint(point) { 292 m_model(model), m_oldPoint(point), m_newPoint(point) {
293 m_newPoint.label = newLabel; 293 m_newPoint.label = newLabel;
294 } 294 }
295 295
296 virtual QString getName() const { return tr("Re-Label Point"); } 296 QString getName() const override { return tr("Re-Label Point"); }
297 297
298 virtual void execute() { 298 void execute() override {
299 m_model->deletePoint(m_oldPoint); 299 m_model->deletePoint(m_oldPoint);
300 m_model->addPoint(m_newPoint); 300 m_model->addPoint(m_newPoint);
301 std::swap(m_oldPoint, m_newPoint); 301 std::swap(m_oldPoint, m_newPoint);
302 } 302 }
303 303
304 virtual void unexecute() { execute(); } 304 void unexecute() override { execute(); }
305 305
306 private: 306 private:
307 SparseModel<PointType> *m_model; 307 SparseModel<PointType> *m_model;
308 PointType m_oldPoint; 308 PointType m_oldPoint;
309 PointType m_newPoint; 309 PointType m_newPoint;
311 311
312 /** 312 /**
313 * TabularModel methods. 313 * TabularModel methods.
314 */ 314 */
315 315
316 virtual int getRowCount() const 316 int getRowCount() const override
317 { 317 {
318 return int(m_points.size()); 318 return int(m_points.size());
319 } 319 }
320 320
321 virtual sv_frame_t getFrameForRow(int row) const 321 sv_frame_t getFrameForRow(int row) const override
322 { 322 {
323 PointListConstIterator i = getPointListIteratorForRow(row); 323 PointListConstIterator i = getPointListIteratorForRow(row);
324 if (i == m_points.end()) return 0; 324 if (i == m_points.end()) return 0;
325 return i->frame; 325 return i->frame;
326 } 326 }
327 327
328 virtual int getRowForFrame(sv_frame_t frame) const 328 int getRowForFrame(sv_frame_t frame) const override
329 { 329 {
330 if (m_rows.empty()) rebuildRowVector(); 330 if (m_rows.empty()) rebuildRowVector();
331 std::vector<sv_frame_t>::iterator i = 331 std::vector<sv_frame_t>::iterator i =
332 std::lower_bound(m_rows.begin(), m_rows.end(), frame); 332 std::lower_bound(m_rows.begin(), m_rows.end(), frame);
333 ssize_t row = std::distance(m_rows.begin(), i); 333 ssize_t row = std::distance(m_rows.begin(), i);
335 --row; 335 --row;
336 } 336 }
337 return int(row); 337 return int(row);
338 } 338 }
339 339
340 virtual int getColumnCount() const { return 1; } 340 int getColumnCount() const override { return 1; }
341 virtual QVariant getData(int row, int column, int role) const 341 QVariant getData(int row, int column, int role) const override
342 { 342 {
343 PointListConstIterator i = getPointListIteratorForRow(row); 343 PointListConstIterator i = getPointListIteratorForRow(row);
344 if (i == m_points.end()) { 344 if (i == m_points.end()) {
345 // cerr << "no iterator for row " << row << " (have " << getRowCount() << " rows)" << endl; 345 // cerr << "no iterator for row " << row << " (have " << getRowCount() << " rows)" << endl;
346 return QVariant(); 346 return QVariant();
359 } 359 }
360 360
361 return QVariant(); 361 return QVariant();
362 } 362 }
363 363
364 virtual Command *getSetDataCommand(int row, int column, 364 Command *getSetDataCommand(int row, int column,
365 const QVariant &value, int role) 365 const QVariant &value, int role) override
366 { 366 {
367 if (role != Qt::EditRole) return 0; 367 if (role != Qt::EditRole) return 0;
368 PointListIterator i = getPointListIteratorForRow(row); 368 PointListIterator i = getPointListIteratorForRow(row);
369 if (i == m_points.end()) return 0; 369 if (i == m_points.end()) return 0;
370 EditCommand *command = new EditCommand(this, tr("Edit Data")); 370 EditCommand *command = new EditCommand(this, tr("Edit Data"));
379 379
380 command->addPoint(point); 380 command->addPoint(point);
381 return command->finish(); 381 return command->finish();
382 } 382 }
383 383
384 virtual Command *getInsertRowCommand(int row) 384 Command *getInsertRowCommand(int row) override
385 { 385 {
386 EditCommand *command = new EditCommand(this, tr("Insert Data Point")); 386 EditCommand *command = new EditCommand(this, tr("Insert Data Point"));
387 Point point(0); 387 Point point(0);
388 PointListIterator i = getPointListIteratorForRow(row); 388 PointListIterator i = getPointListIteratorForRow(row);
389 if (i == m_points.end() && i != m_points.begin()) --i; 389 if (i == m_points.end() && i != m_points.begin()) --i;
390 if (i != m_points.end()) point = *i; 390 if (i != m_points.end()) point = *i;
391 command->addPoint(point); 391 command->addPoint(point);
392 return command->finish(); 392 return command->finish();
393 } 393 }
394 394
395 virtual Command *getRemoveRowCommand(int row) 395 Command *getRemoveRowCommand(int row) override
396 { 396 {
397 PointListIterator i = getPointListIteratorForRow(row); 397 PointListIterator i = getPointListIteratorForRow(row);
398 if (i == m_points.end()) return 0; 398 if (i == m_points.end()) return 0;
399 EditCommand *command = new EditCommand(this, tr("Delete Data Point")); 399 EditCommand *command = new EditCommand(this, tr("Delete Data Point"));
400 command->deletePoint(*i); 400 command->deletePoint(*i);