{
dbObject = 0;
dbManager = 0;
- //dbManager = new DatabaseManager(this);
editButton = new QPushButton(tr("&Edit"));
editButton->setEnabled(false);
addButton = new QPushButton(tr("&Add"));
buttonBox->addButton(editButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
- // nameDialog will be created on request
-
+ // this be called from the implementing classes:
//connectSignals();
layout();
}
DbObjectDialog::~DbObjectDialog()
{
- delete dbObject;
+ // no need to explicitically delete widgets within a parented layout
+ // they are automatically parented and will be deleted
+ // dbManager is also parented and will be implicitically deleted
+ // this must be deleted in an implementing class
+ //delete dbObject;
}
void DbObjectDialog::connectSignals()
connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
- //connect(nameDialog, SIGNAL(accepted()), this, SLOT(updateList()));
connect(nameDialog, SIGNAL(dataObjectUpdated()), this, SLOT(updateData()));
}
updateList();
}
-void DbObjectDialog::activateNameDialog() const
+void DbObjectDialog::activateNameDialog()
{
if (!nameDialog) return;
nameDialog->show();
{
Q_OBJECT
- public:
+public:
DbObjectDialog(QWidget *parent = 0);
~DbObjectDialog();
- protected slots:
+protected slots:
void editButtonClicked();
void addButtonClicked();
void deleteButtonClicked();
- //void enableEditButton();
- //void enableDeleteButton();
void listObjectClicked(const QModelIndex &);
virtual void updateData();
void updateList() const;
- protected:
+protected:
virtual int deleteObject() =0;
virtual void addObject() =0;
virtual void editObject() =0;
virtual bool deleteItem() = 0;
+ virtual void updateDb(const EmuFrontObject*) const = 0;
+ virtual void insertDb(const EmuFrontObject*) const = 0;
+ void connectSignals();
+ void activateNameDialog();
NameDialog *nameDialog;
DatabaseManager *dbManager;
QTableView *objectList;
EmuFrontObject *dbObject;
- void connectSignals();
- void activateNameDialog() const;
- virtual void updateDb(const EmuFrontObject*) const = 0;
- virtual void insertDb(const EmuFrontObject*) const = 0;
- //virtual QSqlTableModel* getDataObjects() = 0;
-
- private:
- QDialogButtonBox *buttonBox;
- QPushButton *editButton;
- QPushButton *addButton;
- QPushButton *deleteButton;
+private:
void setButtonsEnabled(bool);
void layout();
void disableSelection();
+ QDialogButtonBox *buttonBox;
+ QPushButton *editButton;
+ QPushButton *addButton;
+ QPushButton *deleteButton;
+
};
#endif
NameDialog::~NameDialog()
{
- delete efObject;
+ // should be deleted in implementing classes
+ // delete efObject;
- /* deleting parenteed QT-objects in heap is not needed here
+ /* no need to delete parented QT-objects in heap here
* because when deleting a parent widget
* the child widgets will be also deleted
*/
{
connect(nameEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableSaveButton(const QString &)));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptChanges()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(rejectChanges()));
}
void NameDialog::layout()
setLayout(mainLayout);
}
+void NameDialog::rejectChanges()
+{
+ efObject = 0;
+ close();
+}
+
void NameDialog::acceptChanges()
{
if (nameEdit->text() == 0 || nameEdit->text().trimmed().isEmpty())
QString name = nameEdit->text().simplified();
setDataObject(name);
emit dataObjectUpdated();
- efObject = 0; // TODO we should also se efObject to null when user clicks abort
+ efObject = 0; // TODO we should also set efObject to null when user clicks abort
close();
}
#include "../dataobjects/emufrontobject.h"
#include "emufrontdialog.h"
-
class QLabel;
class QLineEdit;
class QPushButton;
protected slots:
void acceptChanges();
- void enableSaveButton(const QString &);
+ void rejectChanges();
+ void enableSaveButton(const QString &);
protected:
virtual void setDataObject(QString name) =0;
objectList->setModel(dbManager->getDataModel());
objectList->setSelectionMode(QAbstractItemView::SingleSelection);
- //objectList->setColumnHidden(DatabaseManager::Platform_Id, true);
+ //objectList->setColumnHidden(Platform_Id, true);
objectList->resizeColumnsToContents();
// do not move to parent class:
void PlatformDialog::addObject()
{
- cout << "PlaformDialog::addObject" << endl;
/*if (!nameDialog)
{
if (!dbObject) dbObject = new Platform;
- cout << "PlaformDialog::addObject: creating nameDialog..." << endl;
nameDialog = new PlatformNameDialog(this, dynamic_cast<Platform*>(dbObject));
}*/
delete dynamic_cast<Platform*>(dbObject);
dbObject = new Platform;
- // we need to fetch a new id for this platform
nameDialog->setDataObject(dbObject);
activateNameDialog();
}
qDebug() << "dbObject is not 0";
- QMessageBox::information(this, "Test", "We have a " + dbObject->getName());
+ qDebug() << "We have a " + dbObject->getName();
qDebug() << "Data will be inserted/updated...";
if (dbObject->getId() > -1) updateDb(dbObject);
else insertDb(dbObject);
+ // we don't need dbObject anymore
+ delete dynamic_cast<Platform*>(dbObject);
+ dbObject = 0;
+
// refresh...
DbObjectDialog::updateData();
}
setWindowTitle(tr("Set platform name"));
}
+PlatformNameDialog::~PlatformNameDialog()
+{
+ // no need to delete efObject here, the calling widget will take care of it
+ // delete dynamic_cast<Platform*>(efObject);
+}
+
void PlatformNameDialog::setDataObject(QString name)
{
efObject->setName(name);
public:
PlatformNameDialog(QWidget *parent = 0, Platform * = 0);
+ ~PlatformNameDialog();
virtual void setDataObject(EmuFrontObject*);
protected:
QTextStream cout(stdout, QIODevice::WriteOnly);
if (DatabaseManager::openDB())
- cout << " Database opened succesflly!" << endl;
+ cout << " Database opened succesfully!" << endl;
else cout << " Database connection failed!" << endl;
if (DatabaseManager::dbExists())
exit(1);
}
}
- /*
-
- if (dbm.insertPerson("Testi","Tapaus",1) > 0)
- cout << "Database insert successfull!" << endl;
- else cout << "Database insert failed!" << endl;
-
-
- cout << "Trying to select from database: " << dbm.getName(1) << endl;
- */
-
- /*PlatformNameDialog *nameDialog = new PlatformNameDialog;
- nameDialog->show();*/
MainWindow *mw = new MainWindow;
mw->show();
return app.exec();
createStatusBar();
readSettings();
platformDialog = 0;
- //dbManager = new DatabaseManager;
}
void MainWindow::createActions()