svcore  1.9
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 _MODEL_DATA_TABLE_MODEL_H_
17 #define _MODEL_DATA_TABLE_MODEL_H_
18 
19 #include <QAbstractItemModel>
20 
21 #include <vector>
22 
23 class TabularModel;
24 class Command;
25 
26 class ModelDataTableModel : public QAbstractItemModel
27 {
28  Q_OBJECT
29 
30 public:
32  virtual ~ModelDataTableModel();
33 
34  QVariant data(const QModelIndex &index, int role) const;
35 
36  bool setData(const QModelIndex &index, const QVariant &value, int role);
37 
38  bool insertRow(int row, const QModelIndex &parent = QModelIndex());
39  bool removeRow(int row, const QModelIndex &parent = QModelIndex());
40 
41  Qt::ItemFlags flags(const QModelIndex &index) const;
42 
43  QVariant headerData(int section, Qt::Orientation orientation,
44  int role = Qt::DisplayRole) const;
45 
46  QModelIndex index(int row, int column,
47  const QModelIndex &parent = QModelIndex()) const;
48 
49  QModelIndex parent(const QModelIndex &index) const;
50 
51  int rowCount(const QModelIndex &parent = QModelIndex()) const;
52  int columnCount(const QModelIndex &parent = QModelIndex()) const;
53 
54  QModelIndex getModelIndexForFrame(int frame) const;
55  int getFrameForModelIndex(const QModelIndex &) const;
56 
57  void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
58 
59  QModelIndex findText(QString text) const;
60 
61  void setCurrentRow(int row);
62  int getCurrentRow() const;
63 
64 signals:
65  void frameSelected(int);
66  void addCommand(Command *);
67  void currentChanged(const QModelIndex &);
68  void modelRemoved();
69 
70 protected slots:
71  void modelChanged();
72  void modelChangedWithin(int, int);
73  void modelAboutToBeDeleted();
74 
75 protected:
78  Qt::SortOrder m_sortOrdering;
80  typedef std::vector<int> RowList;
81  mutable RowList m_sort;
82  mutable RowList m_rsort;
83  int getSorted(int row) const;
84  int getUnsorted(int row) const;
85  void resort() const;
86  void resortNumeric() const;
87  void resortAlphabetical() const;
88  void clearSort();
89 };
90 
91 #endif
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
int rowCount(const QModelIndex &parent=QModelIndex()) const
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
int getUnsorted(int row) const
bool removeRow(int row, const QModelIndex &parent=QModelIndex())
int getSorted(int row) const
std::vector< int > RowList
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Qt::ItemFlags flags(const QModelIndex &index) const
ModelDataTableModel(TabularModel *m)
bool setData(const QModelIndex &index, const QVariant &value, int role)
QModelIndex getModelIndexForFrame(int frame) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
bool insertRow(int row, const QModelIndex &parent=QModelIndex())
TabularModel is an abstract base class for models that support direct access to data in a tabular for...
Definition: TabularModel.h:34
Qt::SortOrder m_sortOrdering
int getFrameForModelIndex(const QModelIndex &) const
QVariant data(const QModelIndex &index, int role) const
QModelIndex findText(QString text) const
QModelIndex parent(const QModelIndex &index) const
void modelChangedWithin(int, int)
void addCommand(Command *)
void frameSelected(int)
void currentChanged(const QModelIndex &)