comparison data/model/ModelDataTableModel.h @ 420:50a956688baa

* reorganise tabular data editor model support
author Chris Cannam
date Wed, 11 Jun 2008 16:13:25 +0000
parents 64e7bbb255d3
children 4caa28a0a8a2
comparison
equal deleted inserted replaced
419:64e7bbb255d3 420:50a956688baa
16 #ifndef _MODEL_DATA_TABLE_MODEL_H_ 16 #ifndef _MODEL_DATA_TABLE_MODEL_H_
17 #define _MODEL_DATA_TABLE_MODEL_H_ 17 #define _MODEL_DATA_TABLE_MODEL_H_
18 18
19 #include <QAbstractItemModel> 19 #include <QAbstractItemModel>
20 20
21 #include "Model.h" 21 #include <vector>
22 22
23 class TabularModel;
23 class Command; 24 class Command;
24 25
25 class ModelDataTableModel : public QAbstractItemModel 26 class ModelDataTableModel : public QAbstractItemModel
26 { 27 {
27 Q_OBJECT 28 Q_OBJECT
28 29
29 public: 30 public:
30 ModelDataTableModel(Model *m); 31 ModelDataTableModel(TabularModel *m);
31 virtual ~ModelDataTableModel(); 32 virtual ~ModelDataTableModel();
32 33
33 QVariant data(const QModelIndex &index, int role) const; 34 QVariant data(const QModelIndex &index, int role) const;
34 35
35 bool setData(const QModelIndex &index, const QVariant &value, int role); 36 bool setData(const QModelIndex &index, const QVariant &value, int role);
48 int columnCount(const QModelIndex &parent = QModelIndex()) const; 49 int columnCount(const QModelIndex &parent = QModelIndex()) const;
49 50
50 QModelIndex getModelIndexForFrame(size_t frame) const; 51 QModelIndex getModelIndexForFrame(size_t frame) const;
51 size_t getFrameForModelIndex(const QModelIndex &) const; 52 size_t getFrameForModelIndex(const QModelIndex &) const;
52 53
53 static bool canHandleModelType(Model *); 54 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
54 55
55 signals: 56 signals:
56 void frameSelected(size_t); 57 void frameSelected(size_t);
57 void executeCommand(Command *); 58 void executeCommand(Command *);
58 59
59 protected slots: 60 protected slots:
60 void modelChanged(); 61 void modelChanged();
61 void modelChanged(size_t, size_t); 62 void modelChanged(size_t, size_t);
62 63
63 protected: 64 protected:
64 // We need to have some sort of map between row and time in sample 65 TabularModel *m_model;
65 // frames. I guess this will do for now. 66 int m_sortColumn;
66 67 Qt::SortOrder m_sortOrdering;
67 std::vector<size_t> m_rows; // contains sample frame 68 typedef std::vector<int> RowList;
68 69 RowList m_sort;
69 Model *m_model; 70 int getSorted(int row);
70 71 int getUnsorted(int row);
71 void rebuildRowVector(); 72 void resort();
72 template <typename PointType> void rebuildRowVectorSparse();
73 template <typename PointType> QVariant dataSparse(int row, int col,
74 bool withUnit) const;
75 template <typename PointType> bool setDataSparse(int row, int col,
76 QVariant value);
77 }; 73 };
78 74
79 #endif 75 #endif