Fixed a bug: the edit dialog fields were not cleared if an
[emufront] / src / dialogs / namedialog.cpp
index 64f3ddc..0bbffbf 100644 (file)
@@ -1,23 +1,43 @@
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
+
 #include <QtGui>
 #include "namedialog.h"
 
 NameDialog::NameDialog(QWidget *parent, EmuFrontObject *efObj)
-        : EmuFrontDialog(parent), efObject(efObj)
+        : DataObjectEditDialog(parent, efObj)
 {
        nameLabel = new QLabel(tr("&Name: "));  
        nameEdit = new QLineEdit;
        nameLabel->setBuddy(nameEdit);
-    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Abort, Qt::Horizontal);
     connectSignals();
        layout();
+    emit test();
        setWindowTitle(tr("Set names"));
 }
 
 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
         */
@@ -25,9 +45,8 @@ NameDialog::~NameDialog()
 
 void NameDialog::connectSignals()
 {
+    DataObjectEditDialog::connectSignals();
     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()));
 }
 
 void NameDialog::layout()
@@ -54,13 +73,17 @@ void NameDialog::acceptChanges()
     }
 
        QString name = nameEdit->text().simplified();
-    setDataObject(name);
-    emit dataObjectUpdated();
-    efObject = 0; // TODO we should also se efObject to null when user clicks abort
+    qDebug() << "We have a name " << name << ".";
+    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();
 }
 
-void NameDialog::enableSaveButton(const QString &text)
+void NameDialog::enableSaveButton(const QString &/*text*/)
 {
     //saveButton->setEnabled(!text.isEmpty());
 }
@@ -68,8 +91,14 @@ void NameDialog::enableSaveButton(const QString &text)
 void NameDialog::setDataObject(EmuFrontObject *ob)
 {
     if (!ob) return;
-    // delete efObject; -> we should not delete the previously referenced data object here, it may be still used in the parent widget
-    // the parent widget will take of destruction
+    // delete efObject; -> we should not delete the previously referenced data object here, it
+    // may be still used in the parent widget
+    // the parent widget will take care of destruction
     // we'll just refresh the name dialog pointer to a new object
     efObject = ob;
 }
+
+void NameDialog::clear()
+{
+    nameEdit->clear();
+}