Forgot to clean dynamic object.
[emufront] / src / dialogs / dbobjectdialog.cpp
1 #include <QtGui>
2 #include "dbobjectdialog.h"
3 #include "../db/databasemanager.h"
4
5 DbObjectDialog::DbObjectDialog(QWidget *parent)
6     : EmuFrontDialog(parent)
7 {
8     dbObject = 0;
9     dbManager = new DatabaseManager(this);
10     editButton = new QPushButton(tr("&Edit")); 
11     editButton->setEnabled(false);
12     addButton = new QPushButton(tr("&Add"));
13     deleteButton = new QPushButton(tr("&Delete"));
14     deleteButton->setEnabled(false);
15     objectList = new QTableView(this);
16     buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Vertical);
17     buttonBox->addButton(editButton, QDialogButtonBox::ActionRole);
18     buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
19     buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
20     // nameDialog will be created on request
21     
22     connectSignals();
23     layout();
24
25
26 DbObjectDialog::~DbObjectDialog()
27 {
28     delete dbObject;
29 }
30
31 void DbObjectDialog::connectSignals()
32 {
33     connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
34     connect(objectList, SIGNAL(clicked(const QModelIndex &)), 
35                 this, SLOT(listObjectClicked(const QModelIndex &)));
36     connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
37     connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
38     connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
39     connect(nameDialog, SIGNAL(accepted()), this, SLOT(updateList()));
40 }
41
42 void DbObjectDialog::updateList() const
43 {
44         // fetch items from database (virtual function for this)
45         // update the item list
46 }
47
48 void DbObjectDialog::addButtonClicked()
49 {
50     disableSelection();
51     addObject();
52 }
53
54 void DbObjectDialog::editButtonClicked()
55 {
56     disableSelection();
57 }
58
59 void DbObjectDialog::deleteButtonClicked()
60 {
61     disableSelection();
62 }
63
64 void DbObjectDialog::layout()
65 {
66     QHBoxLayout *mainLayout = new QHBoxLayout;
67     mainLayout->addWidget(objectList);
68     mainLayout->addWidget(buttonBox);
69     setLayout(mainLayout);
70 }
71
72 void DbObjectDialog::listObjectClicked(const QModelIndex &index)
73 {
74     setButtonsEnabled(index.isValid());
75     if(!index.isValid()) 
76         return;
77 }
78
79 void DbObjectDialog::setButtonsEnabled(bool enabled)
80 {
81     editButton->setEnabled(enabled);
82     deleteButton->setEnabled(enabled);
83 }
84
85 void DbObjectDialog::disableSelection()
86 {
87     setButtonsEnabled(false);
88 }