Removed unnecessary updating to database if no object
authorMikko Keinänen <mikko.keinanen@gmail.com>
Thu, 11 Nov 2010 22:47:03 +0000 (00:47 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Thu, 11 Nov 2010 22:47:03 +0000 (00:47 +0200)
member values were changed. Overloaded == and !=
operators in the base class.

doc/todo
src/dataobjects/emufrontobject.cpp
src/dataobjects/emufrontobject.h
src/dataobjects/setup.cpp
src/dataobjects/setup.h
src/dialogs/executableeditdialog.cpp
src/dialogs/mediaimagepathdialog.cpp
src/dialogs/namedialog.cpp
src/dialogs/setupeditdialog.cpp

index 78d57ea..ae438d4 100644 (file)
--- a/doc/todo
+++ b/doc/todo
@@ -1,2 +1,4 @@
 - Check all the exceptions, are they catched? Is the allocated data cleaned?
 - check all the needed closeEvents for dialogs!
+- bug: select media image path for editing, click done -> media image path is
+  deleted.
index 1767bda..4dd7cae 100644 (file)
@@ -46,3 +46,14 @@ EmuFrontObject& EmuFrontObject::operator =(const EmuFrontObject &ob)
     return (*this);
 }
 
+
+bool EmuFrontObject::operator ==(const EmuFrontObject &sup)
+{
+    return (id >= 0 && id == sup.id && name == sup.name);
+}
+
+bool EmuFrontObject::operator !=(const EmuFrontObject &sup)
+{
+    return !(*this == sup);
+}
+
index 7ea2cf1..ebbd6cd 100644 (file)
@@ -31,6 +31,8 @@ public:
     EmuFrontObject(const EmuFrontObject &);
     ~EmuFrontObject();
     EmuFrontObject &operator=(const EmuFrontObject &);
+    bool operator==(const EmuFrontObject &);
+    bool operator!=(const EmuFrontObject &);
 
     virtual const QString getName() const
     { return name; }
index d03f4a1..9195a14 100644 (file)
@@ -67,6 +67,21 @@ Setup& Setup::operator =(const Setup &sup)
     return (*this);
 }
 
+// TODO:
+/*bool Setup::operator ==(const Setup &sup)
+{
+
+    // TODO: more precise ... this is exact copy from EmuFrontObject
+    return (id >= 0 && id == sup.id);
+
+}
+
+bool Setup::operator !=(const Setup &sup)
+{
+    // TODO: more precise ... this is exact copy from EmuFrontObject
+    return !(*this == sup);
+}*/
+
 Platform* Setup::getPlatform() const
 { return platform; }
 void Setup::setPlatform(Platform *plf)
index de43c95..97a91bd 100644 (file)
@@ -33,6 +33,9 @@ public:
     Setup(int id, Platform *, MediaType *, QStringList fileTypeExtensions);
     Setup(const Setup &);
     Setup& operator=(const Setup &);
+    // TODO:
+    //bool operator==(const Setup &);
+    //bool operator!=(const Setup &);
     Platform* getPlatform() const;
     MediaType* getMediaType() const;
     QStringList getSupportedFileTypeExtensions() const;
index 3ec89dc..442d6c6 100644 (file)
@@ -97,15 +97,28 @@ void ExecutableEditDialog::acceptChanges()
         if (opts.isEmpty()) {
             throw new EmuFrontException(tr("Options not set"));
         }
+        bool change = false;
         Setup *supTmp = ex->getSetup();
-        if (supTmp != su) {
+        if (*supTmp != *su) {
             delete supTmp;
             ex->setSetup(su);
+            change = true;
         }
-        ex->setName(name);
-        ex->setExecutable(exec);
-        ex->setOptions(opts);
-        emit dataObjectUpdated();
+
+        if (name != ex->getName()) {
+            ex->setName(name);
+            change = true;
+        }
+
+        if (exec != ex->getExecutable()) {
+            ex->setExecutable(exec);
+            change = true;
+        }
+        if (opts != ex->getOptions()) {
+            ex->setOptions(opts);
+            change = true;
+        }
+        if (change) emit dataObjectUpdated();
         efObject = 0;
         close();
     } catch(EmuFrontException x) {
index 3838657..5aaab3a 100644 (file)
@@ -116,6 +116,7 @@ void MediaImagePathDialog::acceptChanges()
         QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
         return;
     }
+    bool change = false;
     qDebug() << "Setup selected " << sup->getName();
     QString filePath = filePathLabel->text();
     if (filePath.isEmpty())
@@ -123,14 +124,23 @@ void MediaImagePathDialog::acceptChanges()
         QMessageBox::information(this, tr("File path"), tr("File path was not selected"), QMessageBox::Ok);
         return;
     }
+    if (filePath != fpo->getName()) {
+        fpo->setName(filePath);
+        change = true;
+    }
+
     Setup *tmp = fpo->getSetup();
-    if (sup != tmp)
+
+    int idSup = sup->getId();
+    int idTmp = tmp->getId();
+
+    if (*sup != *tmp)
     {
         delete tmp;
         fpo->setSetup(sup);
+        change = true;
     }
-    fpo->setName(filePath);
-    emit dataObjectUpdated();
+    if (change) emit dataObjectUpdated();
     efObject = 0;
     close();
 }
index 95bc5f0..2824dd7 100644 (file)
@@ -74,8 +74,10 @@ void NameDialog::acceptChanges()
 
        QString name = nameEdit->text().simplified();
     qDebug() << "We have a name " << name << ".";
-    setDataObject(name);
-    emit dataObjectUpdated();
+    if (name != efObject->getName()) {
+        setDataObject(name);
+        emit dataObjectUpdated();
+    }
     qDebug() << "Signal emitted.";
     efObject = 0; // TODO we should also set efObject to null when user clicks abort
     close();
index c61cb41..e687bf9 100644 (file)
@@ -85,20 +85,28 @@ void SetupEditDialog::acceptChanges()
     qDebug() << "Media type selected " << mt->getName();
 
 
+    bool change = false;
     Platform *ptmp = sup->getPlatform();
-    if (plf != ptmp)
+    if (*plf != *ptmp)
     {
         delete ptmp;
         sup->setPlatform(plf);
+        change = true;
     }
     MediaType *mtmp = sup->getMediaType();
-    if (mt != mtmp)
+    if (*mt != *mtmp)
     {
         delete mtmp;
         sup->setMediaType(mt);
+        change = true;
     }
-    sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
-    emit dataObjectUpdated();
+
+    // "Two lists are considered equal if they contain the same values in the same order."
+    if (supportedFileTypesList->getItems() != sup->getSupportedFileTypeExtensions()) {
+        sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
+        change = true;
+    }
+    if (change) emit dataObjectUpdated();
     efObject = 0;
     close();
 }