1 #include "qui/motif_editor/MotifEditor.hpp"
2 #include "alg/sequence.hpp"
9 MotifEditor::MotifEditor(MussaRef m, QWidget *parent)
12 editor_layout(new QVBoxLayout(parent)),
13 button_layout(new QHBoxLayout(parent)),
14 table(new QTableView(this)),
15 delegate(new MotifEditorDelegate(this)),
16 applyButton(new QPushButton("apply")),
20 const set<Sequence> &motif = analysis->motifs();
21 vector<Sequence> motif_seq(motif.begin(), motif.end());
23 applyButton->setFocusPolicy(Qt::StrongFocus);
24 connect(applyButton, SIGNAL(clicked()), this, SLOT(updateMotifs()));
25 button_layout->addStretch();
26 button_layout->addWidget(applyButton);
28 table->setItemDelegate(delegate);
30 editor_layout->addWidget(table);
31 editor_layout->addLayout(button_layout);
32 setLayout(editor_layout);
38 void MotifEditor::updateModel()
40 MotifModel *new_model = new MotifModel();
42 new_model->push_empty();
44 // if there was an old model, delete it
48 // update the QTableView
50 table->setModel(model);
54 void MotifEditor::updateMotifs()
56 // This function is _sooo_ not thread safe
58 Color motif_default = analysis->colorMapper()->typeColor("motif");
59 analysis->colorMapper()->erase("motif");
60 analysis->colorMapper()->appendTypeColor("motif", motif_default);
62 // add our motifs back
63 vector<Sequence> new_motifs;
64 vector<Color> new_colors;
66 for(MotifModel::iterator md_i = model->begin();
70 if (md_i->getSequence().size() > 0 && md_i->isEnabled()) {
71 new_motifs.push_back(md_i->getSequence());
72 new_colors.push_back(md_i->getColor());
75 analysis->set_motifs(new_motifs, new_colors);
80 void MotifEditor::updateTitle()
82 QString title("Motif Editor: ");
83 title.append(analysis->get_name().c_str());
84 setWindowTitle(title);
88 void MotifEditor::updateView()
90 for (int row = 0; row < model->rowCount(QModelIndex()); ++row)
91 table->resizeRowToContents(row);
92 for (int column = 0; column < model->columnCount(QModelIndex()); ++column)
93 table->resizeColumnToContents(column);