1 #include "qui/motif_editor/MotifEditor.hpp"
2 #include "alg/sequence.hpp"
9 MotifEditor::MotifEditor(MussaRef m, QWidget *parent)
22 const set<Sequence> &motif = analysis->motifs();
23 vector<Sequence> motif_seq(motif.begin(), motif.end());
25 applyButton->setFocusPolicy(Qt::StrongFocus);
26 connect(applyButton, SIGNAL(clicked()), this, SLOT(updateAnalysisMotifs()));
27 button_layout->addStretch();
28 button_layout->addWidget(applyButton);
30 table->setItemDelegate(delegate);
32 editor_layout->addWidget(table);
33 editor_layout->addLayout(button_layout);
34 setLayout(editor_layout);
40 void MotifEditor::setupWidgets()
42 editor_layout = new QVBoxLayout(this);
43 button_layout = new QHBoxLayout(this);
44 table = new QTableView(this);
45 delegate = new MotifEditorDelegate(this);
46 applyButton = new QPushButton("apply");
49 void MotifEditor::updateModel()
51 // if our current analysis doesn't match the one in our
52 // model, we probalby changed the analysis.
53 // so delete and restart
54 if (model and model->getAnalysis() != analysis) {
58 // if we don't have a model, create a new one
60 model = new MotifModel(analysis);
62 table->setModel(model);
66 void MotifEditor::updateAnalysisMotifs()
68 // This function is _sooo_ not thread safe
70 Color motif_default = analysis->colorMapper()->typeColor("motif");
71 analysis->colorMapper()->erase("motif");
72 analysis->colorMapper()->appendTypeColor("motif", motif_default);
74 // add our motifs back
75 vector<Sequence> new_motifs;
76 vector<Color> new_colors;
78 for(MotifModel::iterator md_i = model->begin();
82 if (md_i->getSequence().size() > 0 && md_i->isEnabled()) {
83 new_motifs.push_back(md_i->getSequence());
84 new_colors.push_back(md_i->getColor());
87 analysis->set_motifs(new_motifs, new_colors);
92 void MotifEditor::updateTitle()
94 std::string title("Motif Editor: ");
96 title += analysis->get_title();
98 setWindowTitle(title.c_str());
101 void MotifEditor::updateView()
103 for (int row = 0; row < model->rowCount(QModelIndex()); ++row)
104 table->resizeRowToContents(row);
105 for (int column = 0; column < model->columnCount(QModelIndex()); ++column)
106 table->resizeColumnToContents(column);