2 #include "dbobjectdialog.h"
3 #include "../db/databasemanager.h"
5 DbObjectDialog::DbObjectDialog(QWidget *parent)
6 : EmuFrontDialog(parent)
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
26 void DbObjectDialog::connectSignals()
28 connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
29 connect(objectList, SIGNAL(clicked(const QModelIndex &)),
30 this, SLOT(listObjectClicked(const QModelIndex &)));
31 connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
32 connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
33 connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
34 connect(nameDialog, SIGNAL(accepted()), this, SLOT(updateList()));
37 void DbObjectDialog::updateList() const
39 // fetch items from database (virtual function for this)
40 // update the item list
43 void DbObjectDialog::addButtonClicked()
49 void DbObjectDialog::editButtonClicked()
54 void DbObjectDialog::deleteButtonClicked()
59 void DbObjectDialog::layout()
61 QHBoxLayout *mainLayout = new QHBoxLayout;
62 mainLayout->addWidget(objectList);
63 mainLayout->addWidget(buttonBox);
64 setLayout(mainLayout);
67 void DbObjectDialog::listObjectClicked(const QModelIndex &index)
69 setButtonsEnabled(index.isValid());
74 void DbObjectDialog::setButtonsEnabled(bool enabled)
76 editButton->setEnabled(enabled);
77 deleteButton->setEnabled(enabled);
80 void DbObjectDialog::disableSelection()
82 setButtonsEnabled(false);