svcore  1.9
ModelDataTableModel.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2008 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _MODEL_DATA_TABLE_MODEL_H_
00017 #define _MODEL_DATA_TABLE_MODEL_H_
00018 
00019 #include <QAbstractItemModel>
00020 
00021 #include <vector>
00022 
00023 class TabularModel;
00024 class Command;
00025 
00026 class ModelDataTableModel : public QAbstractItemModel
00027 {
00028     Q_OBJECT
00029 
00030 public:
00031     ModelDataTableModel(TabularModel *m);
00032     virtual ~ModelDataTableModel();
00033 
00034     QVariant data(const QModelIndex &index, int role) const;
00035 
00036     bool setData(const QModelIndex &index, const QVariant &value, int role);
00037 
00038     bool insertRow(int row, const QModelIndex &parent = QModelIndex());
00039     bool removeRow(int row, const QModelIndex &parent = QModelIndex());
00040 
00041     Qt::ItemFlags flags(const QModelIndex &index) const;
00042 
00043     QVariant headerData(int section, Qt::Orientation orientation,
00044                         int role = Qt::DisplayRole) const;
00045 
00046     QModelIndex index(int row, int column,
00047                       const QModelIndex &parent = QModelIndex()) const;
00048 
00049     QModelIndex parent(const QModelIndex &index) const;
00050 
00051     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00052     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00053 
00054     QModelIndex getModelIndexForFrame(int frame) const;
00055     int getFrameForModelIndex(const QModelIndex &) const;
00056 
00057     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
00058 
00059     QModelIndex findText(QString text) const;
00060 
00061     void setCurrentRow(int row);
00062     int getCurrentRow() const;
00063 
00064 signals:
00065     void frameSelected(int);
00066     void addCommand(Command *);
00067     void currentChanged(const QModelIndex &);
00068     void modelRemoved();
00069 
00070 protected slots:
00071     void modelChanged();
00072     void modelChangedWithin(int, int);
00073     void modelAboutToBeDeleted();
00074 
00075 protected:
00076     TabularModel *m_model;
00077     int m_sortColumn;
00078     Qt::SortOrder m_sortOrdering;
00079     int m_currentRow;
00080     typedef std::vector<int> RowList;
00081     mutable RowList m_sort;
00082     mutable RowList m_rsort;
00083     int getSorted(int row) const;
00084     int getUnsorted(int row) const;
00085     void resort() const;
00086     void resortNumeric() const;
00087     void resortAlphabetical() const;
00088     void clearSort();
00089 };
00090 
00091 #endif