Make MussaWindow UI objects pointers
[mussa.git] / qui / MussaWindow.cpp
index 6b0e8a7e9e07614ea9e596e12bde4a2dfd4660eb..a079974dd5666005aef4d0f49171fa4dc6735cff 100644 (file)
@@ -34,11 +34,12 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
   analysis(analysis_),
   default_dir(QDir::home().absolutePath().toStdString(), fs::native),
   motif_editor(0),
-  setup_analysis_dialog(this),
-  browser(this),
-  mussaViewTB("Path Views"),
-  zoom(),
-  threshold(),
+  setup_analysis_dialog(new MussaSetupDialog(this)),
+  subanalysis_window(new SubanalysisWindow),
+  browser(new SequenceBrowserWidget(this)),  
+  mussaViewTB(new QToolBar("Path Views")),
+  zoom(new ZoomWidget),
+  threshold(new ThresholdWidget),
   progress_dialog(0),
   aboutAction(0),
   closeAction(0),
@@ -66,28 +67,28 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
   // a segfault when using WhatsThis feature with 
   // opengl widget.
   //scene->setWhatsThis(tr("Mussa in OpenGL!"));
-  setCentralWidget(&browser);
+  setCentralWidget(browser);
   // well updatePosition isn't quite right as we really just need
   // to call update()
-  connect(this, SIGNAL(changedAnnotations()), &browser, SLOT(update()));
+  connect(this, SIGNAL(changedAnnotations()), browser, SLOT(update()));
 
-  //mussaViewTB.addAction(toggleMotifsAction);
-  mussaViewTB.addWidget(&zoom);
+  //mussaViewTB->addAction(toggleMotifsAction);
+  mussaViewTB->addWidget(zoom);
   
-  connect(&zoom, SIGNAL(valueChanged(double)), 
-          &browser, SLOT(setZoom(double)));
+  connect(zoom, SIGNAL(valueChanged(double)), 
+          browser, SLOT(setZoom(double)));
   
   // threshold range is set in updateAnalysis
   
   //scene->setClipPlane(20);
   // FIXME: for when we get the paths drawn at the appropriate depth
-  //connect(&threshold, SIGNAL(thresholdChanged(int)),
+  //connect(threshold, SIGNAL(thresholdChanged(int)),
   //        this, SLOT(setClipPlane(int)));
-  connect(&threshold, SIGNAL(thresholdChanged(int)),
+  connect(threshold, SIGNAL(thresholdChanged(int)),
           this, SLOT(setSoftThreshold(int)));
-  mussaViewTB.addWidget(&threshold);
+  mussaViewTB->addWidget(threshold);
 
-  addToolBar(&mussaViewTB);
+  addToolBar(mussaViewTB);
 
   statusBar()->showMessage("Welcome to mussa", 2000);
   connect(analysis, SIGNAL(progress(const std::string&, int, int)),
@@ -194,7 +195,7 @@ void MussaWindow::setupActions()
   //Save pixel map action
   saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
   connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
-         &browser, SLOT(promptSaveBrowserPixmap()));
+         browser, SLOT(promptSaveBrowserPixmap()));
   saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
 
   viewMussaAlignmentAction = new QAction(tr("View sequence alignment"), this);
@@ -242,7 +243,7 @@ void MussaWindow::setupMainMenu()
 
   newMenu = menuBar()->addMenu(tr("&Edit"));
   newMenu->addAction(editMotifsAction);
-  newMenu->addAction(&browser.getCopySelectedSequenceAsFastaAction());
+  newMenu->addAction(browser->getCopySelectedSequenceAsFastaAction());
   newMenu->addAction(createSubAnalysisAction);
  
   newMenu = menuBar()->addMenu(tr("&View"));
@@ -256,9 +257,11 @@ void MussaWindow::setupMainMenu()
   newMenu->addAction(aboutAction);
 
   // add some extra features to the context menu
-  QMenu& popupMenu = browser.getPopupMenu();
-  popupMenu.addAction(viewMussaAlignmentAction);
-  popupMenu.addAction(createSubAnalysisAction);
+  QMenu *popupMenu = browser->getPopupMenu();
+  if (popupMenu) {
+    popupMenu->addAction(viewMussaAlignmentAction);
+    popupMenu->addAction(createSubAnalysisAction);
+  }
 }
 
 void MussaWindow::setupAssistant()
@@ -289,7 +292,7 @@ void MussaWindow::about()
 void MussaWindow::clear()
 {
   aligned_windows.clear();
-  browser.clear();
+  browser->clear();
 }
 
 void MussaWindow::createNewAnalysis()
@@ -299,9 +302,9 @@ void MussaWindow::createNewAnalysis()
     // but this should work for the moment.
     if (not isClearingAnalysisSafe()) return;
 
-    if (setup_analysis_dialog.exec()) {
+    if (setup_analysis_dialog->exec()) {
       Mussa *m = 0;
-      m = setup_analysis_dialog.getMussa();
+      m = setup_analysis_dialog->getMussa();
       setAnalysis(m);
     }
   } catch(mussa_error e) {
@@ -313,8 +316,8 @@ void MussaWindow::createNewAnalysis()
 void MussaWindow::createSubAnalysis()
 {
   list<SequenceLocation> result;
-  SequenceLocationModel& model = subanalysis_window.getModel();
-  browser.copySelectedTracksAsSeqLocation(result);
+  SequenceLocationModel& model = subanalysis_window->getModel();
+  browser->copySelectedTracksAsSeqLocation(result);
   for(list<SequenceLocation>::iterator result_itor = result.begin();
       result_itor != result.end();
       ++result_itor)
@@ -322,8 +325,8 @@ void MussaWindow::createSubAnalysis()
     model.push_back(*result_itor);
   }
 
-  if (not subanalysis_window.isVisible()) {
-    subanalysis_window.show();
+  if (not subanalysis_window->isVisible()) {
+    subanalysis_window->show();
   }
 }
 
@@ -557,10 +560,10 @@ void MussaWindow::setSoftThreshold(int threshold)
 
 void MussaWindow::showMussaToolbar()
 {
-  if (mussaViewTB.isVisible())
-    mussaViewTB.hide();
+  if (mussaViewTB->isVisible())
+    mussaViewTB->hide();
   else
-    mussaViewTB.show();
+    mussaViewTB->show();
 }
 
 void MussaWindow::toggleMotifs()
@@ -597,7 +600,7 @@ void MussaWindow::NotImplementedBox()
 
 void MussaWindow::viewMussaAlignment()
 {
-  const set<int>& selected_paths = browser.selectedPaths();
+  const set<int>& selected_paths = browser->selectedPaths();
   if (selected_paths.size() == 0 ) {
     QMessageBox::warning(this, 
                          QObject::tr("mussa"),
@@ -617,13 +620,17 @@ void MussaWindow::viewMussaAlignment()
                         
 void MussaWindow::updateAnalysis()
 {
-  threshold.setRange(analysis->get_threshold(),analysis->get_window());
-
   const Mussa::vector_sequence_type& seqs = analysis->sequences();
-  browser.setSequences(seqs, analysis->colorMapper());
+  browser->setSequences(seqs, analysis->colorMapper());
+  assert(browser->sequences().size() == analysis->size());
+
+  // setRange eventually emits something that causes updateLinks to be called
+  // but it's possible for us to not have had a chance to set out sequences
+  // yet.
+  threshold->setRange(analysis->get_threshold(),analysis->get_window());
   updateLinks();
-  browser.zoomOut();
-  zoom.setValue(browser.zoom());
+  browser->zoomOut();
+  zoom->setValue(browser->zoom());
 }
 
 void MussaWindow::updateAnnotations()
@@ -631,12 +638,17 @@ void MussaWindow::updateAnnotations()
   // motifs were changed in the sequences by 
   // Mussa::update_sequences_motifs
   emit changedAnnotations();
-  browser.update();
+  browser->update();
 }
 
 void MussaWindow::updateLinks()
 {
-  browser.clear_links();
+  if(browser->sequences().size() == 0) {
+    // we don't have any sequences load so we have no business setting links
+    return;
+  }
+
+  browser->clear_links();
   bool reversed = false;
   const NwayPaths& nway = analysis->paths();
 
@@ -674,9 +686,9 @@ void MussaWindow::updateLinks()
       normalized_path.push_back(x);
       rc_flags.push_back(reversed);
     }
-    browser.link(normalized_path, rc_flags, path_itor->window_size);
+    browser->link(normalized_path, rc_flags, path_itor->window_size);
   }
-  browser.update();
+  browser->update();
 }
 
 void