keep motifs after closing window
authorDiane Trout <diane@caltech.edu>
Wed, 21 Feb 2007 01:46:24 +0000 (01:46 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 21 Feb 2007 01:46:24 +0000 (01:46 +0000)
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
qui/motif_editor/MotifEditor.cpp
qui/motif_editor/MotifModel.cpp
qui/motif_editor/MotifModel.hpp

index 883703fd3be49d8867128640dbad020699262bf5..5d934fa36d637536fa33b03ccac033cdaa5c8f72 100644 (file)
@@ -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();
 }
 
index f98402689b3e763c41216b02fe008624109f8268..8166e37cbca86fa16092717ea12e2146aa085ac5 100644 (file)
@@ -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();
 }
index 5bf0ad1db4b43445f714642c54baf8f28f325efc..0785721f1f74ea74b89aca3abe4a3e38061ac43d 100644 (file)
@@ -3,7 +3,8 @@
 #include <QColor>
 
 MotifModel::MotifModel(MussaRef m, QObject *parent) 
-  : QAbstractTableModel(parent)
+  : analysis(m),
+    QAbstractTableModel(parent)
 {
   const std::set<Sequence>& motif_set = m->motifs();
   boost::shared_ptr<AnnotationColors> 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
index b077cdcb5d8de92dee7c1d25493b3afe5e6c5f60..5cf288a99c6a1b21b0614b7bdc4911799f08ad66 100644 (file)
@@ -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;
 };