Fixed bugs: dialogs remained disabled (signals were not attached to
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 16 Nov 2010 23:19:03 +0000 (01:19 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 16 Nov 2010 23:19:03 +0000 (01:19 +0200)
current objects). Crashes while using configuration dialogs second time
(data objects were not cleaned propely).

15 files changed:
src/dialogs/dataobjecteditdialog.cpp
src/dialogs/dataobjecteditdialog.h
src/dialogs/dbobjectdialog.cpp
src/dialogs/dbobjectdialog.h
src/dialogs/executablemaindialog.cpp
src/dialogs/executablemaindialog.h
src/dialogs/mediaimagepathmaindialog.cpp
src/dialogs/mediaimagepathmaindialog.h
src/dialogs/mediatypedialog.cpp
src/dialogs/mediatypedialog.h
src/dialogs/platformdialog.cpp
src/dialogs/platformdialog.h
src/dialogs/setupeditdialog.cpp
src/dialogs/setupmaindialog.cpp
src/dialogs/setupmaindialog.h

index 0a75f28..c6644ba 100644 (file)
@@ -39,6 +39,7 @@ void DataObjectEditDialog::connectSignals()
 
 void DataObjectEditDialog::closeEvent(QCloseEvent *ev)
 {
+    qDebug() << "Emitting dialog closed";
     emit dialogClosed();
     ev->accept();
 }
index 250d0f3..e54b79e 100644 (file)
@@ -34,13 +34,13 @@ public:
     DataObjectEditDialog(QWidget *parent, EmuFrontObject *ob, Qt::Orientation orientation = Qt::Horizontal);
     virtual void setDataObject(EmuFrontObject *) = 0;
     virtual void updateData();
-    virtual void closeEvent(QCloseEvent *);
 
 protected:
     virtual void connectSignals();
     EmuFrontObject *efObject;
     QDialogButtonBox *buttonBox;
     void setSelected(QComboBox*, const EmuFrontObject*, int idIndex);
+    virtual void closeEvent(QCloseEvent *);
 
 signals:
     void updateRejected();
index 418cdca..a87c9a5 100644 (file)
@@ -62,6 +62,10 @@ void DbObjectDialog::connectSignals()
     connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
     connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
     connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
+}
+
+void DbObjectDialog::connectNameDialogSignals()
+{
     connect(nameDialog, SIGNAL(dataObjectUpdated()), this, SLOT(updateData()));
     connect(nameDialog, SIGNAL(updateRejected()), this, SLOT(updateReject()));
     connect(nameDialog, SIGNAL(test()), this, SLOT(testSlot()));
@@ -79,10 +83,19 @@ void DbObjectDialog::insertDb(const EmuFrontObject *ob) const
         errorMessage->showMessage(tr("Inserting data object %1 failed.").arg(ob->getName()));
 }
 
+void DbObjectDialog::createEditDialog()
+{
+    initEditDialog();
+    // call this from implementing classes:
+    //connectNameDialogSignals();
+}
+
 void DbObjectDialog::addObject()
 {
     setUIEnabled(false);
-    if (!nameDialog) initEditDialog();
+    if (!nameDialog) {
+       createEditDialog();
+    }
     deleteCurrentObject();
     dbObject = createObject();
     nameDialog->setDataObject(dbObject);
@@ -94,7 +107,9 @@ void DbObjectDialog::editObject()
     QModelIndex index = objectList->currentIndex();
     if (!index.isValid())
         return;
-    if (!nameDialog) initEditDialog();
+    if (!nameDialog) {
+        createEditDialog();
+    }
     deleteCurrentObject();
     dbObject = dbManager->getDataObjectFromModel(&index);
     activateNameDialog();
@@ -296,3 +311,11 @@ void DbObjectDialog::hideColumns()
     foreach(int c, hiddenColumns)
         objectList->hideColumn(c);
 }
+
+void DbObjectDialog::closeEvent(QCloseEvent *ev)
+{
+    qDebug() << "DbObjectDialog closing!";
+    setUIEnabled(true);
+    cleanUp();
+}
+
index 1fac258..38442d0 100644 (file)
@@ -53,10 +53,13 @@ private slots:
 protected:
     // implementation specific, deletes current data object from memory
     virtual void deleteCurrentObject() = 0;
+    virtual void cleanUp() = 0;
     virtual void initEditDialog() = 0;
     virtual EmuFrontObject* createObject() = 0;
+    virtual void closeEvent(QCloseEvent *);
     void initDataTable();
     virtual void connectSignals();
+    virtual void connectNameDialogSignals();
     DataObjectEditDialog *nameDialog;
     EmuFrontObject *dbObject;
     DatabaseManager *dbManager;
@@ -77,6 +80,7 @@ private:
     void setUIEnabled(bool);
     void layout();
     void disableSelection();
+    void createEditDialog();
     QPushButton *editButton;
     QPushButton *addButton;
     QPushButton *deleteButton;
index 585bbd5..6fea959 100644 (file)
@@ -46,12 +46,29 @@ void ExecutableMainDialog::initEditDialog()
 {
     nameDialog = new ExecutableEditDialog(
         this, dynamic_cast<Executable*>(dbObject));
+    connectNameDialogSignals();
 }
 
 void ExecutableMainDialog::deleteCurrentObject()
 {
-   delete dynamic_cast<Executable*>(dbObject);
-   dbObject = 0;
+    if (dbObject) {
+        Executable *exe =  dynamic_cast<Executable*>(dbObject);
+        if (exe) delete exe;
+        else qDebug() << "Failed deleting Executable";
+        dbObject = 0;
+    }
+}
+
+void ExecutableMainDialog::cleanUp()
+{
+    deleteCurrentObject();
+    if (nameDialog) {
+        ExecutableEditDialog *pnd =
+            dynamic_cast<ExecutableEditDialog *>(nameDialog);
+        if (pnd) delete pnd;
+        else qDebug() << "Failed to delete PlatformNameDialog";
+        nameDialog = 0;
+    }
 }
 
 EmuFrontObject* ExecutableMainDialog::createObject()
index fbdbf46..f6845fb 100644 (file)
@@ -32,6 +32,7 @@ public:
 
 protected:
     virtual void deleteCurrentObject();
+    virtual void cleanUp();
     virtual EmuFrontObject* createObject();
     virtual void initEditDialog();
 
index 89e281d..1ba8a02 100644 (file)
@@ -55,6 +55,7 @@ void MediaImagePathMainDialog::connectSignals()
 void MediaImagePathMainDialog::initEditDialog()
 {
     nameDialog = new MediaImagePathDialog(this, dynamic_cast<FilePathObject*>(dbObject));
+    connectNameDialogSignals();
 }
 
 void MediaImagePathMainDialog::beginScanFilePath()
@@ -111,6 +112,22 @@ MediaImagePathMainDialog::~MediaImagePathMainDialog()
 
 void MediaImagePathMainDialog::deleteCurrentObject()
 {
-    delete dynamic_cast<FilePathObject*>(dbObject);
-    dbObject = 0;
+    if (dbObject) {
+        FilePathObject* fpo =  dynamic_cast<FilePathObject*>(dbObject);
+        if (fpo) delete fpo;
+        else qDebug() << "Failed deleteing FilePathObject";
+        dbObject = 0;
+    }
+}
+
+void MediaImagePathMainDialog::cleanUp()
+{
+    deleteCurrentObject();
+    if (nameDialog) {
+        MediaImagePathDialog *pnd =
+            dynamic_cast<MediaImagePathDialog*>(nameDialog);
+        if (pnd) delete pnd;
+        else qDebug() << "Failed to delete MediaImagePathDialog";
+        nameDialog = 0;
+    }
 }
index bbd843a..1f11d61 100644 (file)
@@ -36,6 +36,7 @@ protected:
     virtual void deleteCurrentObject();
     virtual EmuFrontObject* createObject();
     virtual void connectSignals();
+    virtual void cleanUp();
 
 private slots:
     void beginScanFilePath();
index afc3b4a..4e2d688 100644 (file)
@@ -47,6 +47,7 @@ MediaTypeDialog::~MediaTypeDialog()
 void MediaTypeDialog::initEditDialog()
 {
     nameDialog = new MediaTypeNameDialog(this, dynamic_cast<MediaType*>(dbObject));
+    connectNameDialogSignals();
 }
 
 EmuFrontObject* MediaTypeDialog::createObject()
@@ -59,3 +60,15 @@ void MediaTypeDialog::deleteCurrentObject()
     delete dynamic_cast<MediaType*>(dbObject);
     dbObject = 0;
 }
+
+void MediaTypeDialog::cleanUp()
+{
+    deleteCurrentObject();
+    if (nameDialog) {
+        MediaTypeNameDialog *pnd =
+            dynamic_cast<MediaTypeNameDialog*>(nameDialog);
+        if (pnd) delete pnd;
+        else qDebug() << "Failed to delete MediaTypeNameDialog";
+        nameDialog = 0;
+    }
+}
index d70944b..c9cb058 100644 (file)
@@ -32,6 +32,7 @@ public:
 
 protected:
     virtual void deleteCurrentObject();
+    virtual void cleanUp();
     virtual EmuFrontObject* createObject();
     virtual void initEditDialog();
 };
index f747a41..7d8aaf3 100644 (file)
@@ -46,6 +46,7 @@ PlatformDialog::~PlatformDialog()
 void PlatformDialog::initEditDialog()
 {
     nameDialog = new PlatformNameDialog(this, dynamic_cast<Platform*>(dbObject));
+    connectNameDialogSignals();
 }
 
 EmuFrontObject* PlatformDialog::createObject()
@@ -56,7 +57,23 @@ EmuFrontObject* PlatformDialog::createObject()
 
 void PlatformDialog::deleteCurrentObject()
 {
-    qDebug() << "PlatformDialog deleting a Platform object.";
-    delete dynamic_cast<Platform*>(dbObject);
-    dbObject = 0;
+    if (dbObject) {
+        qDebug() << "PlatformDialog deleting a Platform object.";
+        Platform *plf = dynamic_cast<Platform*>(dbObject);
+        if (plf) delete plf;
+        else qDebug() << "Failed deleting Platform";
+        dbObject = 0;
+    }
+}
+
+void PlatformDialog::cleanUp()
+{
+    deleteCurrentObject();
+    if (nameDialog) {
+        PlatformNameDialog *pnd =
+            dynamic_cast<PlatformNameDialog*>(nameDialog);
+        if (pnd) delete pnd;
+        else qDebug() << "Failed to delete PlatformNameDialog";
+        nameDialog = 0;
+    }
 }
index 8c0f3c3..fda4f8c 100644 (file)
@@ -32,6 +32,7 @@ public:
 
 protected:
     virtual void deleteCurrentObject();
+    virtual void cleanUp();
     virtual EmuFrontObject* createObject();
     virtual void initEditDialog();
 };
index 77154b6..c6fa561 100644 (file)
@@ -109,6 +109,7 @@ void SetupEditDialog::acceptChanges()
         sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
         change = true;
     }
+    // TODO: the second time around this signal is not received!
     if (change) emit dataObjectUpdated();
     efObject = 0;
     close();
@@ -123,6 +124,10 @@ void SetupEditDialog::setDataObject(EmuFrontObject *ob)
         delete dynamic_cast<Setup*>(efObject); // TODO: caused crash if another instance of setupeditdialog was created and new instance destroyed object being referenced in another existing dialog.
     efObject = ob;
     Setup *sup= dynamic_cast<Setup*>(ob);
+    if (!sup) {
+        qDebug() << "Failed casting to Setup";
+        return;
+    }
     if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
     if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
     supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());
index 010f9e3..c0c97a9 100644 (file)
@@ -43,17 +43,41 @@ SetupMainDialog::~SetupMainDialog()
 
 void SetupMainDialog::initEditDialog()
 {
-    if (nameDialog) delete dynamic_cast<SetupEditDialog*>(nameDialog);
+    if (nameDialog)  {
+        SetupEditDialog *sed =
+            dynamic_cast<SetupEditDialog*>(nameDialog);
+        if (sed) delete sed;
+        else qDebug() << "Failed to delete SetupEditDialog!";
+    }
     nameDialog = new SetupEditDialog(this, dynamic_cast<Setup*>(dbObject));
+    connectNameDialogSignals();
 }
 
 void SetupMainDialog::deleteCurrentObject()
 {
-   delete dynamic_cast<Setup*>(dbObject);
-   dbObject = 0;
+    if (dbObject) {
+        Setup *sup = dynamic_cast<Setup*>(dbObject);
+        if (sup)
+            delete sup;
+        else
+            qDebug() << "Failed to delete Setup data objec data object.";
+        dbObject = 0;
+    }
 }
 
 EmuFrontObject* SetupMainDialog::createObject()
 {
     return new Setup;
 }
+
+void SetupMainDialog::cleanUp()
+{
+    deleteCurrentObject();
+    if (nameDialog) {
+        SetupEditDialog *sed =
+                dynamic_cast<SetupEditDialog*>(nameDialog);
+        if (sed) delete sed;
+        else qDebug() << "Failed to delete SetupEditDialog!";
+        nameDialog = 0;
+    }
+}
index e1b363f..df7d7b8 100644 (file)
@@ -32,6 +32,7 @@ public:
 
 protected:
     virtual void deleteCurrentObject();
+    virtual void cleanUp();
     virtual EmuFrontObject* createObject();
     virtual void initEditDialog();
 };