MotifEditor::MotifEditor(Mussa *m, QWidget *parent)
: QWidget(parent),
analysis(m),
- applyButton("set motifs")
+ editor_layout(new QVBoxLayout(parent)),
+ button_layout(new QHBoxLayout(parent)),
+ table(new QTableView(this)),
+ delegate(new MotifEditorDelegate(this)),
+ applyButton(new QPushButton("apply")),
+ model(0)
{
assert (m != 0);
const set<Sequence> &motif = analysis->motifs();
vector<Sequence> motif_seq(motif.begin(), motif.end());
- connect(&applyButton, SIGNAL(clicked()), this, SLOT(updateMotifs()));
- layout.addWidget(&applyButton);
+ applyButton->setFocusPolicy(Qt::StrongFocus);
+ connect(applyButton, SIGNAL(clicked()), this, SLOT(updateMotifs()));
+ button_layout->addStretch();
+ button_layout->addWidget(applyButton);
+
+ table->setItemDelegate(delegate);
- for(size_t i=0; i != 10; ++i)
- {
- MotifDetail *detail = new MotifDetail;
- if (i < motif_seq.size()) {
- detail->setMotif(motif_seq[i].get_sequence());
- detail->setColor(analysis->colorMapper()->lookup("motif", motif_seq[i].get_sequence()));
- }
- motif_details.push_back(detail);
- layout.addWidget(detail);
- }
- setLayout(&layout);
+ editor_layout->addWidget(table);
+ editor_layout->addLayout(button_layout);
+ setLayout(editor_layout);
+
+ updateTitle();
+ updateModel();
}
-MotifEditor::MotifEditor(const MotifEditor& me)
- : QWidget((QWidget*)me.parent()),
- analysis(me.analysis),
- applyButton(me.applyButton.text())
+void MotifEditor::updateModel()
{
+ MotifModel *new_model = new MotifModel();
+
+ new_model->push_empty();
+
+ // if there was an old model, delete it
+ if (model) {
+ delete model;
+ }
+ // update the QTableView
+ model = new_model;
+ table->setModel(model);
+ updateView();
}
void MotifEditor::updateMotifs()
analysis->colorMapper()->appendTypeColor("motif", motif_default);
// add our motifs back
- vector<Sequence> motifs;
- vector<Color> colors;
+ vector<Sequence> new_motifs;
+ vector<Color> new_colors;
- for(std::vector<MotifDetail *>::iterator md_i = motif_details.begin();
- md_i != motif_details.end();
+ for(MotifModel::iterator md_i = model->begin();
+ md_i != model->end();
++md_i)
{
- if ((*md_i)->motif().size() > 0 && (*md_i)->enabled()) {
- Sequence new_motif((*md_i)->motif());
- new_motif.set_fasta_header((*md_i)->name());
- motifs.push_back((*md_i)->motif());
- colors.push_back((*md_i)->color());
+ if (md_i->getSequence().size() > 0 && md_i->isEnabled()) {
+ new_motifs.push_back(md_i->getSequence());
+ new_colors.push_back(md_i->getColor());
}
}
- analysis->set_motifs(motifs, colors);
+ analysis->set_motifs(new_motifs, new_colors);
emit changedMotifs();
}
-//MotifEditor::
+void MotifEditor::updateTitle()
+{
+ QString title("Motif Editor: ");
+ title.append(analysis->get_name().c_str());
+ setWindowTitle(title);
+
+}
+
+void MotifEditor::updateView()
+{
+ for (int row = 0; row < model->rowCount(QModelIndex()); ++row)
+ table->resizeRowToContents(row);
+ for (int column = 0; column < model->columnCount(QModelIndex()); ++column)
+ table->resizeColumnToContents(column);
+}
+