1 #include "qui/SubanalysisWindow.hpp"
2 #include "qui/MussaWindow.hpp"
4 #include "mussa_exceptions.hpp"
5 #include "alg/mussa.hpp"
10 #include <QGridLayout>
12 SubanalysisWindow::SubanalysisWindow(MussaRef m, QWidget *parent)
21 QGridLayout *parameterLayout = new QGridLayout;
23 QLabel *thresholdLabel = new QLabel(tr("threshold (bp)"));
24 parameterLayout->addWidget(thresholdLabel, 0, 0);
25 threshold = new QSpinBox(this);
26 threshold->setValue(8);
27 parameterLayout->addWidget(threshold, 1, 0);
28 QLabel *windowLabel = new QLabel(tr("window (bp)"));
29 parameterLayout->addWidget(windowLabel, 0, 1);
30 window = new QSpinBox(this);
32 parameterLayout->addWidget(window, 1, 1);
34 ok = new QPushButton(tr("&OK"), this);
35 ok->setEnabled( false );
36 connect(ok, SIGNAL(clicked()), this, SLOT(run()));
38 cancel = new QPushButton(tr("Cancel"), this);
39 connect(cancel, SIGNAL(clicked()), this, SLOT(abort()));
41 table = new QTableView(this);
42 table->setModel(&model);
45 QHBoxLayout *buttonLayout = new QHBoxLayout;
46 buttonLayout->addWidget(ok);
47 buttonLayout->addWidget(cancel);
49 // layout verticle space
50 QVBoxLayout *verticalLayout = new QVBoxLayout;
51 verticalLayout->addLayout(parameterLayout);
52 verticalLayout->addWidget(table);
53 verticalLayout->addLayout(buttonLayout);
54 setLayout(verticalLayout);
56 // now that we're all setup lets get notices when we're updated
57 connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
58 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
59 connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
60 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
65 SequenceLocationModel& SubanalysisWindow::getModel()
70 void SubanalysisWindow::abort()
76 void SubanalysisWindow::run()
78 if (window == 0 or threshold == 0) {
79 throw std::runtime_error("SubanalysisWindow misconstructed");
82 if (model.size() == 0) {
83 throw std::runtime_error("It shouldn't be possible to call run with an "
87 MussaRef m(new Mussa);
89 for(SequenceLocationModel::iterator itor = model.begin();
93 // append_sequence from a const Sequence & will make a copy
94 // for the shared pointer.
95 m->append_sequence(itor->getSelectedSequence());
99 m->set_window(window->value());
100 m->set_threshold(threshold->value());
102 MussaWindow *mw = new MussaWindow(m);
106 } catch(mussa_error e) {
107 QMessageBox::critical(this,
108 "Mussa Subanalysis Error",
110 QMessageBox::Ok, 0, 0);
114 void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )
116 // if the model is empty we shouldn't be able to click ok
117 if (ok) ok->setEnabled(not model.empty());
120 void SubanalysisWindow::updateTitle()
122 std::string title("Subanalysis: ");
124 title += analysis->get_title();
126 setWindowTitle(title.c_str());