Empty Subanalyses should not be run
authorDiane Trout <diane@caltech.edu>
Thu, 6 Jul 2006 19:36:38 +0000 (19:36 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 6 Jul 2006 19:36:38 +0000 (19:36 +0000)
brandon found a problem ticket:110 where clicking run with an empty
set of sequences caused a segfault. This patch disables the run button
when the model is empty.

qui/SubanalysisWindow.cpp
qui/SubanalysisWindow.hpp

index efed5de9526f6e8441a6de9702628c81f273665d..5ac41ac8c8fd92024aaa319db19b79534bec994c 100644 (file)
@@ -30,9 +30,12 @@ SubanalysisWindow::SubanalysisWindow(QWidget *parent)
   parameterLayout->addWidget(window, 1, 1);
 
   ok = new QPushButton(tr("&OK"), this);
+  ok->setEnabled( false );
   connect(ok, SIGNAL(clicked()), this, SLOT(run()));
+
   cancel = new QPushButton(tr("Cancel"), this);
   connect(cancel, SIGNAL(clicked()), this, SLOT(abort()));
+
   table = new QTableView(this);
   table->setModel(&model);
 
@@ -47,6 +50,12 @@ SubanalysisWindow::SubanalysisWindow(QWidget *parent)
   verticalLayout->addWidget(table);
   verticalLayout->addLayout(buttonLayout);
   setLayout(verticalLayout);
+
+  // now that we're all setup lets get notices when we're updated
+  connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), 
+          this, SLOT(modelUpdated(const QModelIndex&, int, int)));
+  connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), 
+          this, SLOT(modelUpdated(const QModelIndex&, int, int)));
 }
 
 SequenceLocationModel& SubanalysisWindow::getModel()
@@ -62,8 +71,14 @@ void SubanalysisWindow::abort()
 
 void SubanalysisWindow::run()
 {
-  if (window == 0 or threshold == 0) 
+  if (window == 0 or threshold == 0) {
     throw std::runtime_error("SubanalysisWindow misconstructed");
+  }
+
+  if (model.size() == 0) {
+    throw std::runtime_error("It shouldn't be possible to call run with an "
+                             "empty model now.");
+  }
 
   std::auto_ptr<Mussa> m(new Mussa);
 
@@ -83,3 +98,8 @@ void SubanalysisWindow::run()
   hide();
 }
 
+void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )
+{
+  // if the model is empty we shouldn't be able to click ok
+  if (ok) ok->setEnabled(not model.empty());
+}
index b081d1d0e2d53bc9dc712052f53adf918d41c8fa..ce141e8f689b854d6b9844c0c56a0c207ab9ee95 100644 (file)
@@ -22,9 +22,10 @@ public:
 public slots:
   //! clear our model and close the window
   void abort();
-
   //! create a subanalysis and run it
   void run();
+  //! provide a way for the model to tell us to update our gui
+  void modelUpdated(const QModelIndex&, int, int);
 
 private:  
   QSpinBox *window;