Empty Subanalyses should not be run
[mussa.git] / qui / SubanalysisWindow.cpp
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());
+}