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(updateAnalysisMotifs()));
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(analysis);
42 // if there was an old model, delete it
46 // update the QTableView
48 table->setModel(model);
52 void MotifEditor::updateAnalysisMotifs()
54 // This function is _sooo_ not thread safe
56 Color motif_default = analysis->colorMapper()->typeColor("motif");
57 analysis->colorMapper()->erase("motif");
58 analysis->colorMapper()->appendTypeColor("motif", motif_default);
60 // add our motifs back
61 vector<Sequence> new_motifs;
62 vector<Color> new_colors;
64 for(MotifModel::iterator md_i = model->begin();
68 if (md_i->getSequence().size() > 0 && md_i->isEnabled()) {
69 new_motifs.push_back(md_i->getSequence());
70 new_colors.push_back(md_i->getColor());
73 analysis->set_motifs(new_motifs, new_colors);
78 void MotifEditor::updateTitle()
80 std::string title("Motif Editor: ");
82 title += analysis->get_title();
84 setWindowTitle(title.c_str());
87 void MotifEditor::updateView()
89 for (int row = 0; row < model->rowCount(QModelIndex()); ++row)
90 table->resizeRowToContents(row);
91 for (int column = 0; column < model->columnCount(QModelIndex()); ++column)
92 table->resizeColumnToContents(column);