From a55b0297c987f8885a255527a0599f813e3bb8dc Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 21 Feb 2007 01:46:24 +0000 Subject: [PATCH] keep motifs after closing window ticket:195 My previous implementation kept destroying and recreating the motif editing dialog box. This version only deletes the motif editor when MussaWindow.clear() is called. --- qui/MussaWindow.cpp | 15 +++++++++------ qui/motif_editor/MotifEditor.cpp | 15 +++++++++------ qui/motif_editor/MotifModel.cpp | 7 ++++++- qui/motif_editor/MotifModel.hpp | 5 +++++ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 883703f..5d934fa 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -324,6 +324,11 @@ void MussaWindow::about() void MussaWindow::clear() { + if (motif_editor != 0) { + motif_editor->hide(); + delete motif_editor; + } + aligned_windows.clear(); browser->clear(); } @@ -459,13 +464,11 @@ bool MussaWindow::isClearingAnalysisSafe() void MussaWindow::editMotifs() { - if (motif_editor != 0) { - motif_editor->hide(); - delete motif_editor; + if (not motif_editor) { + motif_editor = new MotifEditor(analysis); + connect(motif_editor, SIGNAL(changedMotifs()), + this, SLOT(updateAnnotations())); } - motif_editor = new MotifEditor(analysis); - connect(motif_editor, SIGNAL(changedMotifs()), - this, SLOT(updateAnnotations())); motif_editor->show(); } diff --git a/qui/motif_editor/MotifEditor.cpp b/qui/motif_editor/MotifEditor.cpp index f984026..8166e37 100644 --- a/qui/motif_editor/MotifEditor.cpp +++ b/qui/motif_editor/MotifEditor.cpp @@ -48,14 +48,17 @@ void MotifEditor::setupWidgets() void MotifEditor::updateModel() { - MotifModel *new_model = new MotifModel(analysis); - - // 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 + 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(); } diff --git a/qui/motif_editor/MotifModel.cpp b/qui/motif_editor/MotifModel.cpp index 5bf0ad1..0785721 100644 --- a/qui/motif_editor/MotifModel.cpp +++ b/qui/motif_editor/MotifModel.cpp @@ -3,7 +3,8 @@ #include MotifModel::MotifModel(MussaRef m, QObject *parent) - : QAbstractTableModel(parent) + : analysis(m), + QAbstractTableModel(parent) { const std::set& motif_set = m->motifs(); boost::shared_ptr cm = m->colorMapper(); @@ -20,6 +21,10 @@ MotifModel::MotifModel(MussaRef m, QObject *parent) push_empty(); } +const MussaRef MotifModel::getAnalysis() const { + return analysis; +} + void MotifModel::assign( MotifModel::size_type num, const MotifElement& val diff --git a/qui/motif_editor/MotifModel.hpp b/qui/motif_editor/MotifModel.hpp index b077cdc..5cf288a 100644 --- a/qui/motif_editor/MotifModel.hpp +++ b/qui/motif_editor/MotifModel.hpp @@ -23,6 +23,10 @@ class MotifModel : public QAbstractTableModel typedef model_type::const_iterator const_iterator; enum cell_names { EnabledCell, ColorCell, NameCell, SequenceCell }; + + //! return what analysis we were attached to + const MussaRef getAnalysis() const; + //! \defgroup VectorInterface //! \addtogroup VectorInterface //! \@{ @@ -75,6 +79,7 @@ class MotifModel : public QAbstractTableModel // const QModelIndex& parent=QModelIndex()); //! \@} private: + MussaRef analysis; model_type motifs; }; -- 2.30.2