rename ok/cancel to okButton/cancelButton
[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     okButton(0),
18     cancelButton(0),
19     model(glseqs)
20 {
21   QGridLayout *parameterLayout = new QGridLayout;
22
23   okButton = new QPushButton(tr("&OK"), this);
24   okButton->setEnabled( false );
25   connect(okButton, SIGNAL(clicked()), this, SLOT(apply()));
26
27   cancelButton = new QPushButton(tr("Cancel"), this);
28   connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
29
30   table = new QTableView(this);
31   table->setModel(&model);
32
33   // layout buttons
34   QHBoxLayout *buttonLayout = new QHBoxLayout;
35   buttonLayout->addWidget(okButton);
36   buttonLayout->addWidget(cancelButton);
37
38   // layout verticle space
39   QVBoxLayout *verticalLayout = new QVBoxLayout;
40   verticalLayout->addWidget(table);
41   verticalLayout->addLayout(buttonLayout);
42   setLayout(verticalLayout);
43
44   // now that we're all setup lets get notices when we're updated
45   connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), 
46           this, SLOT(modelUpdated(const QModelIndex&, int, int)));
47   connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), 
48           this, SLOT(modelUpdated(const QModelIndex&, int, int)));
49           
50   updateTitle();        
51 }
52
53 SequencePropertiesModel& PropertiesWindow::getModel()
54 {
55   return model;
56 }
57
58 void PropertiesWindow::cancel()
59 {
60   model.clear();
61   hide();
62 }
63
64 void PropertiesWindow::apply()
65 {
66   std::cout << "implement PropertiesWindow::apply" << std::endl;
67   
68   for(SequencePropertiesModel::iterator itor = model.begin();
69       itor != model.end();
70       ++itor)
71   {
72   }
73 }
74
75 void PropertiesWindow::modelUpdated(const QModelIndex&, int, int )
76 {
77   // if the model is empty we shouldn't be able to click ok
78   if (okButton) okButton->setEnabled(not model.empty());
79 }
80
81 void PropertiesWindow::updateTitle()
82 {
83   std::string title("Sequence Properites: ");
84   if (analysis) {
85     title += analysis->get_title();
86   }
87   setWindowTitle(title.c_str());  
88 }