Reading platforms from database and creating a table to platform dialog.
[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     dbManager = new DatabaseManager(this);
9     editButton = new QPushButton(tr("&Edit")); 
10     addButton = new QPushButton(tr("&Add"));
11     deleteButton = new QPushButton(tr("&Delete"));
12     objectList = new QTableView(this);
13     buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Vertical);
14     buttonBox->addButton(editButton, QDialogButtonBox::ActionRole);
15     buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
16     buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
17     // nameDialog will be created on request
18     
19     connectSignals();
20     layout();
21
22
23 void DbObjectDialog::connectSignals()
24 {
25     connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
26     connect(objectList, SIGNAL(clicked(const QModelIndex &)), 
27                 this, SLOT(listObjectClicked(const QModelIndex &)));
28     connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
29     connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
30     connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
31     connect(nameDialog, SIGNAL(accepted()), this, SLOT(updateList()));
32 }
33
34 void DbObjectDialog::updateList() const
35 {
36         // fetch items from database (virtual function for this)
37         // update the item list
38 }
39
40 void DbObjectDialog::addButtonClicked()
41 {
42     disableSelection();
43     addObject();
44 }
45
46 void DbObjectDialog::editButtonClicked()
47 {
48     disableSelection();
49 }
50
51 void DbObjectDialog::deleteButtonClicked()
52 {
53     disableSelection();
54 }
55
56 void DbObjectDialog::layout()
57 {
58     QHBoxLayout *mainLayout = new QHBoxLayout;
59     mainLayout->addWidget(objectList);
60     mainLayout->addWidget(buttonBox);
61     setLayout(mainLayout);
62 }
63
64 void DbObjectDialog::listObjectClicked(const QModelIndex &index)
65 {
66     setButtonsEnabled(index.isValid());
67     if(!index.isValid()) 
68         return;
69 }
70
71 void DbObjectDialog::setButtonsEnabled(bool enabled)
72 {
73     editButton->setEnabled(enabled);
74     deleteButton->setEnabled(enabled);
75 }
76
77 void DbObjectDialog::disableSelection()
78 {
79     setButtonsEnabled(false);
80 }