1 #include "qui/SubanalysisWindow.hpp"
2 #include "qui/MussaWindow.hpp"
4 #include "mussa_exceptions.hpp"
5 #include "alg/mussa.hpp"
11 SubanalysisWindow::SubanalysisWindow(MussaRef m, QWidget *parent)
20 QGridLayout *parameterLayout = new QGridLayout;
22 QLabel *thresholdLabel = new QLabel(tr("threshold (bp)"));
23 parameterLayout->addWidget(thresholdLabel, 0, 0);
24 threshold = new QSpinBox(this);
25 threshold->setValue(8);
26 parameterLayout->addWidget(threshold, 1, 0);
27 QLabel *windowLabel = new QLabel(tr("window (bp)"));
28 parameterLayout->addWidget(windowLabel, 0, 1);
29 window = new QSpinBox(this);
31 parameterLayout->addWidget(window, 1, 1);
33 ok = new QPushButton(tr("&OK"), this);
34 ok->setEnabled( false );
35 connect(ok, SIGNAL(clicked()), this, SLOT(run()));
37 cancel = new QPushButton(tr("Cancel"), this);
38 connect(cancel, SIGNAL(clicked()), this, SLOT(abort()));
40 table = new QTableView(this);
41 table->setModel(&model);
44 QHBoxLayout *buttonLayout = new QHBoxLayout;
45 buttonLayout->addWidget(ok);
46 buttonLayout->addWidget(cancel);
48 // layout verticle space
49 QVBoxLayout *verticalLayout = new QVBoxLayout;
50 verticalLayout->addLayout(parameterLayout);
51 verticalLayout->addWidget(table);
52 verticalLayout->addLayout(buttonLayout);
53 setLayout(verticalLayout);
55 // now that we're all setup lets get notices when we're updated
56 connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
57 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
58 connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
59 this, SLOT(modelUpdated(const QModelIndex&, int, int)));
64 SequenceLocationModel& SubanalysisWindow::getModel()
69 void SubanalysisWindow::abort()
75 void SubanalysisWindow::run()
77 if (window == 0 or threshold == 0) {
78 throw std::runtime_error("SubanalysisWindow misconstructed");
81 if (model.size() == 0) {
82 throw std::runtime_error("It shouldn't be possible to call run with an "
86 MussaRef m(new Mussa);
88 for(SequenceLocationModel::iterator itor = model.begin();
92 // append_sequence from a const Sequence & will make a copy
93 // for the shared pointer.
94 m->append_sequence(itor->getSelectedSequence());
97 m->set_window(window->value());
98 m->set_threshold(threshold->value());
100 MussaWindow *mw = new MussaWindow(m);
106 void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int )
108 // if the model is empty we shouldn't be able to click ok
109 if (ok) ok->setEnabled(not model.empty());
112 void SubanalysisWindow::updateTitle()
114 std::string title("Subanalysis: ");
116 title += analysis->get_title();
118 setWindowTitle(title.c_str());