From 6a430fd48a0aaf191274532398315de6bf49b033 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 6 Jul 2006 19:36:38 +0000 Subject: [PATCH] Empty Subanalyses should not be run 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 | 22 +++++++++++++++++++++- qui/SubanalysisWindow.hpp | 3 ++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/qui/SubanalysisWindow.cpp b/qui/SubanalysisWindow.cpp index efed5de..5ac41ac 100644 --- a/qui/SubanalysisWindow.cpp +++ b/qui/SubanalysisWindow.cpp @@ -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 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()); +} diff --git a/qui/SubanalysisWindow.hpp b/qui/SubanalysisWindow.hpp index b081d1d..ce141e8 100644 --- a/qui/SubanalysisWindow.hpp +++ b/qui/SubanalysisWindow.hpp @@ -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; -- 2.30.2