MotifEditor::MotifEditor(MussaRef m, QWidget *parent)
: QWidget(parent),
analysis(m),
- editor_layout(new QVBoxLayout(parent)),
- button_layout(new QHBoxLayout(parent)),
- table(new QTableView(this)),
- delegate(new MotifEditorDelegate(this)),
- applyButton(new QPushButton("apply")),
+ editor_layout(0),
+ button_layout(0),
+ table(0),
+ delegate(0),
+ applyButton(0),
model(0)
{
+ setupWidgets();
+
assert (m != 0);
const set<Sequence> &motif = analysis->motifs();
vector<Sequence> motif_seq(motif.begin(), motif.end());
+
+ updateTitle();
+ updateModel();
+}
+
+void MotifEditor::setupWidgets()
+{
+ editor_layout = new QVBoxLayout;
+ button_layout = new QHBoxLayout;
+ // remove default layout (very safely)
+ if (layout()) delete layout();
+
+ table = new QTableView;
+ delegate = new MotifEditorDelegate(this);
+ applyButton = new QPushButton("apply");
applyButton->setFocusPolicy(Qt::StrongFocus);
- connect(applyButton, SIGNAL(clicked()), this, SLOT(updateMotifs()));
+ connect(applyButton, SIGNAL(clicked()), this, SLOT(updateAnalysisMotifs()));
button_layout->addStretch();
button_layout->addWidget(applyButton);
-
- table->setItemDelegate(delegate);
+ table->setItemDelegate(delegate);
+
editor_layout->addWidget(table);
editor_layout->addLayout(button_layout);
setLayout(editor_layout);
-
- updateTitle();
- updateModel();
}
void MotifEditor::updateModel()
{
- MotifModel *new_model = new MotifModel();
-
- new_model->push_empty();
-
- // if there was an old model, delete it
- if (model) {
+ // 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;
}
- // update the QTableView
- model = new_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
void MotifEditor::updateTitle()
{
- QString title("Motif Editor: ");
- title.append(analysis->get_name().c_str());
- setWindowTitle(title);
-
+ std::string title("Motif Editor: ");
+ if (analysis) {
+ title += analysis->get_title();
+ }
+ setWindowTitle(title.c_str());
}
void MotifEditor::updateView()