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 DbObjectDialog::~DbObjectDialog()
31 void DbObjectDialog::connectSignals()
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()));
42 void DbObjectDialog::updateList() const
44 // fetch items from database (virtual function for this)
45 // update the item list
48 void DbObjectDialog::addButtonClicked()
54 void DbObjectDialog::editButtonClicked()
59 void DbObjectDialog::deleteButtonClicked()
64 void DbObjectDialog::layout()
66 QHBoxLayout *mainLayout = new QHBoxLayout;
67 mainLayout->addWidget(objectList);
68 mainLayout->addWidget(buttonBox);
69 setLayout(mainLayout);
72 void DbObjectDialog::listObjectClicked(const QModelIndex &index)
74 setButtonsEnabled(index.isValid());
79 void DbObjectDialog::setButtonsEnabled(bool enabled)
81 editButton->setEnabled(enabled);
82 deleteButton->setEnabled(enabled);
85 void DbObjectDialog::disableSelection()
87 setButtonsEnabled(false);