annotate data/model/TabularModel.h @ 1658:5b7b01da430a single-point

Start updating SparseOneDimensionalModel
author Chris Cannam
date Wed, 20 Mar 2019 16:22:13 +0000
parents 7a23dfe65d66
children 343ef2a866a4
rev   line source
Chris@420 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@420 2
Chris@420 3 /*
Chris@420 4 Sonic Visualiser
Chris@420 5 An audio file viewer and annotation editor.
Chris@420 6 Centre for Digital Music, Queen Mary, University of London.
Chris@420 7 This file copyright 2008 QMUL.
Chris@420 8
Chris@420 9 This program is free software; you can redistribute it and/or
Chris@420 10 modify it under the terms of the GNU General Public License as
Chris@420 11 published by the Free Software Foundation; either version 2 of the
Chris@420 12 License, or (at your option) any later version. See the file
Chris@420 13 COPYING included with this distribution for more information.
Chris@420 14 */
Chris@420 15
Chris@1581 16 #ifndef SV_TABULAR_MODEL_H
Chris@1581 17 #define SV_TABULAR_MODEL_H
Chris@420 18
Chris@420 19 #include <QVariant>
Chris@420 20 #include <QString>
Chris@420 21
Chris@1643 22 #include "base/RealTime.h"
Chris@1643 23
Chris@420 24 class Command;
Chris@420 25
Chris@420 26 /**
Chris@420 27 * TabularModel is an abstract base class for models that support
Chris@420 28 * direct access to data in a tabular form. A model that implements
Chris@420 29 * TabularModel may be displayed and, perhaps, edited in a data
Chris@420 30 * spreadsheet window.
Chris@420 31 *
Chris@420 32 * This is very like a cut-down QAbstractItemModel. It assumes a
Chris@420 33 * relationship between row number and frame time.
Chris@420 34 */
Chris@420 35
Chris@420 36 class TabularModel
Chris@420 37 {
Chris@420 38 public:
Chris@462 39 virtual ~TabularModel() { }
Chris@462 40
Chris@420 41 virtual int getRowCount() const = 0;
Chris@420 42 virtual int getColumnCount() const = 0;
Chris@420 43
Chris@420 44 virtual QString getHeading(int column) const = 0;
Chris@422 45
Chris@422 46 enum { SortRole = Qt::UserRole };
Chris@422 47 enum SortType { SortNumeric, SortAlphabetical };
Chris@422 48
Chris@420 49 virtual QVariant getData(int row, int column, int role) const = 0;
Chris@422 50 virtual bool isColumnTimeValue(int col) const = 0;
Chris@422 51 virtual SortType getSortType(int col) const = 0;
Chris@420 52
Chris@1055 53 virtual sv_frame_t getFrameForRow(int row) const = 0;
Chris@1055 54 virtual int getRowForFrame(sv_frame_t frame) const = 0;
Chris@420 55
Chris@420 56 virtual bool isEditable() const { return false; }
Chris@425 57 virtual Command *getSetDataCommand(int /* row */, int /* column */, const QVariant &, int /* role */) { return 0; }
Chris@427 58 virtual Command *getInsertRowCommand(int /* beforeRow */) { return 0; }
Chris@427 59 virtual Command *getRemoveRowCommand(int /* row */) { return 0; }
Chris@1643 60
Chris@1643 61 QVariant adaptFrameForRole(sv_frame_t frame,
Chris@1643 62 sv_samplerate_t rate,
Chris@1643 63 int role) const {
Chris@1643 64 if (role == SortRole) return int(frame);
Chris@1643 65 RealTime rt = RealTime::frame2RealTime(frame, rate);
Chris@1643 66 if (role == Qt::EditRole) return rt.toString().c_str();
Chris@1643 67 else return rt.toText().c_str();
Chris@1643 68 }
Chris@1643 69
Chris@1643 70 QVariant adaptValueForRole(float value,
Chris@1643 71 QString unit,
Chris@1643 72 int role) const {
Chris@1643 73 if (role == SortRole || role == Qt::EditRole) return value;
Chris@1643 74 else return QString("%1 %2").arg(value).arg(unit);
Chris@1643 75 }
Chris@420 76 };
Chris@420 77
Chris@420 78 #endif