X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=blobdiff_plain;f=qui%2Fmotif_editor%2FMotifEditor.cpp;h=acde2d3af74c8a756bb9e05f4855748215f69138;hp=288f7134b0a2b1acdd43ea4a558e223a94c54bea;hb=f88eea68b95773eb5683dcca6cf3fa59b9f00036;hpb=6db5a8de6d687d72c6ce5eac867b3d28f06c9261 diff --git a/qui/motif_editor/MotifEditor.cpp b/qui/motif_editor/MotifEditor.cpp index 288f713..acde2d3 100644 --- a/qui/motif_editor/MotifEditor.cpp +++ b/qui/motif_editor/MotifEditor.cpp @@ -6,39 +6,66 @@ 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 &motif = analysis->motifs(); - vector motif_seq(motif.begin(), motif.end()); + const set &motif = analysis->motifs(); + vector 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 @@ -47,22 +74,38 @@ void MotifEditor::updateMotifs() analysis->colorMapper()->appendTypeColor("motif", motif_default); // add our motifs back - vector motifs; - vector colors; + vector new_motifs; + vector new_colors; - for(std::vector::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); +} +