a47b7101e9aa502b15533303019d8f661d32dca5
[mussa.git] / qui / seqbrowser / seqproperties / PropertiesWindow.cpp
1 #include "qui/seqbrowser/seqproperties/PropertiesWindow.hpp"
2
3 #include "mussa_exceptions.hpp"
4 #include "alg/mussa.hpp"
5
6 #include <QMessageBox>
7 #include <QVBoxLayout>
8 #include <QHBoxLayout>
9 #include <QGridLayout>
10
11 PropertiesWindow::PropertiesWindow(/* MussaRef m, */
12                                    SequencePropertiesModel::model_type glseqs,
13                                    QWidget *parent)
14   : QWidget(parent),
15     /* analysis(m), */
16     table(0),
17     applyButton(0),
18     closeButton(0),
19     model(glseqs)
20 {
21   QGridLayout *parameterLayout = new QGridLayout;
22
23   applyButton = new QPushButton(tr("&Apply"), this);
24   applyButton->setFocusPolicy(Qt::StrongFocus);
25   applyButton->setEnabled( not model.empty() );
26   connect(applyButton, SIGNAL(clicked()), this, SLOT(apply()));
27
28   closeButton = new QPushButton(tr("Close"), this);
29   connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
30
31   table = new QTableView(this);
32   table->setModel(&model);
33
34   // layout buttons
35   QHBoxLayout *buttonLayout = new QHBoxLayout;
36   buttonLayout->addWidget(applyButton);
37   buttonLayout->addWidget(closeButton);
38
39   // layout verticle space
40   QVBoxLayout *verticalLayout = new QVBoxLayout;
41   verticalLayout->addWidget(table);
42   verticalLayout->addLayout(buttonLayout);
43   setLayout(verticalLayout);
44
45   // now that we're all setup lets get notices when we're updated
46   connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), 
47           this, SLOT(modelUpdated(const QModelIndex&, int, int)));
48   connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), 
49           this, SLOT(modelUpdated(const QModelIndex&, int, int)));
50           
51   updateTitle();        
52 }
53
54 SequencePropertiesModel& PropertiesWindow::getModel()
55 {
56   return model;
57 }
58
59 void PropertiesWindow::close()
60 {
61   model.clear();
62   hide();
63 }
64
65 void PropertiesWindow::apply()
66 {
67   model.saveChanges();
68   emit propertiesChanged();
69 }
70
71 void PropertiesWindow::modelUpdated(const QModelIndex&, int, int )
72 {
73   // if the model is empty we shouldn't be able to click ok
74   if (applyButton) applyButton->setEnabled(not model.empty());
75 }
76
77 void PropertiesWindow::updateTitle()
78 {
79   std::string title("Sequence Properites: ");
80   if (analysis) {
81     title += analysis->get_title();
82   }
83   setWindowTitle(title.c_str());  
84 }