1 #include "qui/SequenceLocationModel.hpp"
3 SequenceLocationModel::SequenceLocationModel(QObject *parent)
4 : QAbstractTableModel(parent)
8 void SequenceLocationModel::assign(
9 SequenceLocationModel::size_type num,
10 const SequenceLocation& val
13 sequence_locations.assign(num, val);
16 SequenceLocation& SequenceLocationModel::at(
17 SequenceLocationModel::size_type index
20 return sequence_locations.at(index);
23 SequenceLocation& SequenceLocationModel::back()
25 return sequence_locations.back();
28 SequenceLocationModel::iterator SequenceLocationModel::begin()
30 return sequence_locations.begin();
33 SequenceLocationModel::const_iterator SequenceLocationModel::begin() const
35 return sequence_locations.begin();
38 void SequenceLocationModel::clear()
40 if (sequence_locations.size() != 0) {
41 beginRemoveRows(QModelIndex(), 0, sequence_locations.size()-1);
42 sequence_locations.clear();
47 SequenceLocationModel::iterator SequenceLocationModel::end()
49 return sequence_locations.end();
52 SequenceLocationModel::const_iterator SequenceLocationModel::end() const
54 return sequence_locations.end();
57 bool SequenceLocationModel::empty() const
59 return sequence_locations.empty();
62 SequenceLocation& SequenceLocationModel::operator[](
63 SequenceLocationModel::size_type index
66 return sequence_locations[index];
69 void SequenceLocationModel::pop_back()
71 int last_element = sequence_locations.size()-1;
72 if (last_element >= 0) {
73 beginRemoveRows(QModelIndex(), last_element, last_element);
74 sequence_locations.pop_back();
79 void SequenceLocationModel::push_back(SequenceLocation& item)
81 int last_element = sequence_locations.size();
82 beginInsertRows(QModelIndex(), last_element, last_element);
83 sequence_locations.push_back(item);
87 SequenceLocationModel::size_type SequenceLocationModel::size() const
89 return sequence_locations.size();
93 SequenceLocationModel::rowCount( const QModelIndex& parent) const
95 return sequence_locations.size();
99 SequenceLocationModel::columnCount(const QModelIndex& parent) const
105 SequenceLocationModel::data(const QModelIndex &index, int role) const
107 if (!index.isValid())
110 if (index.row() >= sequence_locations.size())
113 if (index.column() >= 3)
116 if (role == Qt::DisplayRole) {
117 if (index.column() == 0 ) {
118 const Sequence& seq = sequence_locations[index.row()].getSequence();
119 std::string name(seq.get_name());
120 if (name.size() == 0) {
121 return QString(tr("Unnamed Sequence"));
123 return QVariant(QString(name.c_str()));
125 } else if (index.column() == 1) {
126 return QVariant(sequence_locations[index.row()].getLeft());
127 } else if (index.column() == 2) {
128 return QVariant(sequence_locations[index.row()].getRight());
135 SequenceLocationModel::headerData(
137 Qt::Orientation orientation,
141 if (role != Qt::DisplayRole)
144 if (orientation == Qt::Horizontal) {
147 return QString("Sequence");
150 return QString("Left");
153 return QString("Right");
163 bool SequenceLocationModel::setData(
164 const QModelIndex& index,
165 const QVariant &value,
170 int intValue(value.toInt(&isInt));
171 if (index.isValid() and role == Qt::EditRole and isInt) {
172 SequenceLocation& location = sequence_locations[index.row()];
173 switch(index.column()) {
178 location.setLeft(intValue);
181 location.setRight(intValue);
187 emit dataChanged(index, index);
194 Qt::ItemFlags SequenceLocationModel::flags(const QModelIndex& index) const
196 if (!index.isValid())
197 return Qt::ItemIsEnabled;
199 // first column is not editable
200 if (index.column() == 0)
201 return QAbstractItemModel::flags(index);
203 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;