keep motifs after closing window
[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
27     //! return what analysis we were attached to
28     const MussaRef getAnalysis() const;
29     
30     //! \defgroup VectorInterface
31     //! \addtogroup VectorInterface
32     //! \@{
33     //! assign num copies of val to our vector
34     void assign(size_type num, const MotifElement& val);
35     //! return a specific element
36     MotifElement& at(size_type index);
37     //! return the last element
38     MotifElement& back();
39     //! return an iterator to the beginning of the model
40     iterator begin();
41     //! return an iterator to the beginning of the model
42     const_iterator begin() const;
43     //! empty the model
44     void clear();
45     //! return an iterator to the end of the model
46     iterator end();
47     //! return an iterator to the end of the model
48     const_iterator end() const;
49     //! is the model empty?
50     bool empty() const;
51     //! return a specific element
52     MotifElement& operator[](size_type index);
53     //! remove the last element from our model
54     void pop_back();
55     //! add a MotifElement location to the end of our model
56     void push_back(const MotifElement&);
57     //! add an empty element to the end of our model
58     void push_empty();
59     //! how many elements are in our model.
60     size_type size() const;
61     //! \@}
62
63     //! \defgroup QtModelInterface
64     //! \addtogroup QtModel
65     //! \@{
66     int rowCount(const QModelIndex& parent=QModelIndex()) const;
67     int columnCount(const QModelIndex& parent=QModelIndex()) const;
68     QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
69
70     QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const;
71
72     bool setData(const QModelIndex& index, const QVariant &value, 
73                  int role=Qt::EditRole);
74     Qt::ItemFlags flags(const QModelIndex& index) const;
75
76     //bool insertRows(int row, int count, 
77     //                const QModelIndex& parent=QModelIndex());
78     //bool removeRows(int row, int count,
79     //                const QModelIndex& parent=QModelIndex());
80     //! \@}
81   private:      
82     MussaRef analysis;
83     model_type motifs;
84 };
85
86 #endif