ModelDataTableModel.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2008 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_MODEL_DATA_TABLE_MODEL_H
17 #define SV_MODEL_DATA_TABLE_MODEL_H
18 
19 #include <QAbstractItemModel>
20 
21 #include <vector>
22 
23 #include "base/BaseTypes.h"
24 
25 #include "TabularModel.h"
26 #include "Model.h"
27 
28 class TabularModel;
29 class Command;
30 
31 class ModelDataTableModel : public QAbstractItemModel
32 {
33  Q_OBJECT
34 
35 public:
36  ModelDataTableModel(ModelId modelId); // a TabularModel
37  virtual ~ModelDataTableModel();
38 
39  QVariant data(const QModelIndex &index, int role) const override;
40 
41  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
42 
43  bool insertRow(int row, const QModelIndex &parent = QModelIndex());
44  bool removeRow(int row, const QModelIndex &parent = QModelIndex());
45 
46  Qt::ItemFlags flags(const QModelIndex &index) const override;
47 
48  QVariant headerData(int section, Qt::Orientation orientation,
49  int role = Qt::DisplayRole) const override;
50 
51  QModelIndex index(int row, int column,
52  const QModelIndex &parent = QModelIndex()) const override;
53 
54  QModelIndex parent(const QModelIndex &index) const override;
55 
56  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
57  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
58 
59  QModelIndex getModelIndexForFrame(sv_frame_t frame) const;
60  sv_frame_t getFrameForModelIndex(const QModelIndex &) const;
61 
62  void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
63 
64  QModelIndex findText(QString text) const;
65 
66  void setCurrentRow(int row);
67  int getCurrentRow() const;
68 
69 signals:
70  void frameSelected(int);
71  void addCommand(Command *);
72  void currentChanged(const QModelIndex &);
73  void modelRemoved();
74 
75 protected slots:
76  void modelChanged(ModelId);
78 
79 protected:
80  std::shared_ptr<TabularModel> getTabularModel() const {
81  return ModelById::getAs<TabularModel>(m_model);
82  }
83 
86  Qt::SortOrder m_sortOrdering;
88  typedef std::vector<int> RowList;
89  mutable RowList m_sort;
90  mutable RowList m_rsort;
91  int getSorted(int row) const;
92  int getUnsorted(int row) const;
93  void resort() const;
94  void resortNumeric() const;
95  void resortAlphabetical() const;
96  void clearSort();
97 };
98 
99 #endif
void modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)
ModelDataTableModel(ModelId modelId)
int getUnsorted(int row) const
bool removeRow(int row, const QModelIndex &parent=QModelIndex())
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
QModelIndex parent(const QModelIndex &index) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
std::vector< int > RowList
QModelIndex getModelIndexForFrame(sv_frame_t frame) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
int getSorted(int row) const
void resortAlphabetical() const
bool insertRow(int row, const QModelIndex &parent=QModelIndex())
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
TabularModel is an abstract base class for models that support direct access to data in a tabular for...
Definition: TabularModel.h:35
Qt::SortOrder m_sortOrdering
bool setData(const QModelIndex &index, const QVariant &value, int role) override
std::shared_ptr< TabularModel > getTabularModel() const
Qt::ItemFlags flags(const QModelIndex &index) const override
sv_frame_t getFrameForModelIndex(const QModelIndex &) const
void addCommand(Command *)
QModelIndex findText(QString text) const
void frameSelected(int)
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Definition: ById.h:115
void currentChanged(const QModelIndex &)