2 #include "dbobjectdialog.h"
3 #include "../db/databasemanager.h"
5 DbObjectDialog::DbObjectDialog(QWidget *parent)
6 : EmuFrontDialog(parent)
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
23 void DbObjectDialog::connectSignals()
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()));
34 void DbObjectDialog::updateList() const
36 // fetch items from database (virtual function for this)
37 // update the item list
40 void DbObjectDialog::addButtonClicked()
46 void DbObjectDialog::editButtonClicked()
51 void DbObjectDialog::deleteButtonClicked()
56 void DbObjectDialog::layout()
58 QHBoxLayout *mainLayout = new QHBoxLayout;
59 mainLayout->addWidget(objectList);
60 mainLayout->addWidget(buttonBox);
61 setLayout(mainLayout);
64 void DbObjectDialog::listObjectClicked(const QModelIndex &index)
66 setButtonsEnabled(index.isValid());
71 void DbObjectDialog::setButtonsEnabled(bool enabled)
73 editButton->setEnabled(enabled);
74 deleteButton->setEnabled(enabled);
77 void DbObjectDialog::disableSelection()
79 setButtonsEnabled(false);