using namespace std;
-MotifEditor::MotifEditor(Mussa *m, QWidget *parent)
+MotifEditor::MotifEditor(MussaRef m, QWidget *parent)
: QWidget(parent),
analysis(m),
- applyButton("set motifs")
+ editor_layout(0),
+ button_layout(0),
+ table(0),
+ delegate(0),
+ applyButton(0),
+ model(0)
{
+ setupWidgets();
+
assert (m != 0);
- const set<string> &motif = analysis->motifs();
- vector<string> motif_seq(motif.begin(), motif.end());
+ 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(updateAnalysisMotifs()));
+ 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]);
- detail->setColor(analysis->colorMapper()->lookup("motif", motif_seq[i]));
- }
- motif_details.push_back(detail);
- layout.addWidget(detail);
- }
- setLayout(&layout);
+ editor_layout->addWidget(table);
+ editor_layout->addLayout(button_layout);
+ setLayout(editor_layout);
+
+ updateTitle();
+ updateModel();
+}
+
+void MotifEditor::setupWidgets()
+{
+ editor_layout = new QVBoxLayout(this);
+ button_layout = new QHBoxLayout(this);
+ table = new QTableView(this);
+ delegate = new MotifEditorDelegate(this);
+ applyButton = new QPushButton("apply");
}
-MotifEditor::MotifEditor(const MotifEditor& me)
- : QWidget((QWidget*)me.parent()),
- analysis(me.analysis),
- applyButton(me.applyButton.text())
+void MotifEditor::updateModel()
{
+ // if our current analysis doesn't match the one in our
+ // model, we probalby changed the analysis.
+ // so delete and restart
+ // DET 2007mar30 (can this if statement ever be true? it doesn't look
+ // like there's a way to change the analysis?)
+ if (model and model->getAnalysis() != analysis) {
+ delete model;
+ }
+
+ // if we don't have a model, create a new one
+ if (not model) {
+ model = new MotifModel(analysis);
+ }
+ table->setModel(model);
+ updateView();
}
-void MotifEditor::updateMotifs()
+void MotifEditor::updateAnalysisMotifs()
{
// This function is _sooo_ not thread safe
// erase motifs
analysis->colorMapper()->appendTypeColor("motif", motif_default);
// add our motifs back
- vector<string> 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()) {
- 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()
+{
+ std::string title("Motif Editor: ");
+ if (analysis) {
+ title += analysis->get_title();
+ }
+ setWindowTitle(title.c_str());
+}
+
+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);
+}
+