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());
29 void MotifEditor::setupWidgets()
31 editor_layout = new QVBoxLayout;
32 button_layout = new QHBoxLayout;
33 // remove default layout (very safely)
34 if (layout()) delete layout();
36 table = new QTableView;
37 delegate = new MotifEditorDelegate(this);
38 applyButton = new QPushButton("apply");
40 applyButton->setFocusPolicy(Qt::StrongFocus);
41 connect(applyButton, SIGNAL(clicked()), this, SLOT(updateAnalysisMotifs()));
42 button_layout->addStretch();
43 button_layout->addWidget(applyButton);
45 table->setItemDelegate(delegate);
47 editor_layout->addWidget(table);
48 editor_layout->addLayout(button_layout);
49 setLayout(editor_layout);
52 void MotifEditor::updateModel()
54 // if our current analysis doesn't match the one in our
55 // model, we probalby changed the analysis.
56 // so delete and restart
57 // DET 2007mar30 (can this if statement ever be true? it doesn't look
58 // like there's a way to change the analysis?)
59 if (model and model->getAnalysis() != analysis) {
63 // if we don't have a model, create a new one
65 model = new MotifModel(analysis);
67 table->setModel(model);
71 void MotifEditor::updateAnalysisMotifs()
73 // This function is _sooo_ not thread safe
75 Color motif_default = analysis->colorMapper()->typeColor("motif");
76 analysis->colorMapper()->erase("motif");
77 analysis->colorMapper()->appendTypeColor("motif", motif_default);
79 // add our motifs back
80 vector<Sequence> new_motifs;
81 vector<Color> new_colors;
83 for(MotifModel::iterator md_i = model->begin();
87 if (md_i->getSequence().size() > 0 && md_i->isEnabled()) {
88 new_motifs.push_back(md_i->getSequence());
89 new_colors.push_back(md_i->getColor());
92 analysis->set_motifs(new_motifs, new_colors);
97 void MotifEditor::updateTitle()
99 std::string title("Motif Editor: ");
101 title += analysis->get_title();
103 setWindowTitle(title.c_str());
106 void MotifEditor::updateView()
108 for (int row = 0; row < model->rowCount(QModelIndex()); ++row)
109 table->resizeRowToContents(row);
110 for (int column = 0; column < model->columnCount(QModelIndex()); ++column)
111 table->resizeColumnToContents(column);