b077cdcb5d8de92dee7c1d25493b3afe5e6c5f60
[mussa.git] / qui / motif_editor / MotifModel.hpp
1 #ifndef _MOTIF_MODEL_HPP_
2 #define _MOTIF_MODEL_HPP_
3
4 #include "alg/sequence.hpp"
5 #include "alg/mussa.hpp"
6 #include "qui/motif_editor/MotifElement.hpp"
7 #include "qui/motif_editor/MotifEditorDelegate.hpp"
8
9 #include <QAbstractTableModel>
10
11 #include <vector>
12
13 class MotifModel : public QAbstractTableModel
14 {
15   Q_OBJECT
16
17   public:
18     MotifModel(MussaRef m, QObject *parent = 0);
19
20     typedef std::vector<MotifElement> model_type;
21     typedef model_type::size_type size_type;
22     typedef model_type::iterator iterator; 
23     typedef model_type::const_iterator const_iterator; 
24
25     enum cell_names { EnabledCell, ColorCell, NameCell, SequenceCell };
26     //! \defgroup VectorInterface
27     //! \addtogroup VectorInterface
28     //! \@{
29     //! assign num copies of val to our vector
30     void assign(size_type num, const MotifElement& val);
31     //! return a specific element
32     MotifElement& at(size_type index);
33     //! return the last element
34     MotifElement& back();
35     //! return an iterator to the beginning of the model
36     iterator begin();
37     //! return an iterator to the beginning of the model
38     const_iterator begin() const;
39     //! empty the model
40     void clear();
41     //! return an iterator to the end of the model
42     iterator end();
43     //! return an iterator to the end of the model
44     const_iterator end() const;
45     //! is the model empty?
46     bool empty() const;
47     //! return a specific element
48     MotifElement& operator[](size_type index);
49     //! remove the last element from our model
50     void pop_back();
51     //! add a MotifElement location to the end of our model
52     void push_back(const MotifElement&);
53     //! add an empty element to the end of our model
54     void push_empty();
55     //! how many elements are in our model.
56     size_type size() const;
57     //! \@}
58
59     //! \defgroup QtModelInterface
60     //! \addtogroup QtModel
61     //! \@{
62     int rowCount(const QModelIndex& parent=QModelIndex()) const;
63     int columnCount(const QModelIndex& parent=QModelIndex()) const;
64     QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
65
66     QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const;
67
68     bool setData(const QModelIndex& index, const QVariant &value, 
69                  int role=Qt::EditRole);
70     Qt::ItemFlags flags(const QModelIndex& index) const;
71
72     //bool insertRows(int row, int count, 
73     //                const QModelIndex& parent=QModelIndex());
74     //bool removeRows(int row, int count,
75     //                const QModelIndex& parent=QModelIndex());
76     //! \@}
77   private:      
78     model_type motifs;
79 };
80
81 #endif