From 500f2e5d8484bd7233f7a70c51a0d54ff8d574ee Mon Sep 17 00:00:00 2001
From: Olli Werwolff <qtc-commiter@nokia.com>
Date: Wed, 28 Jan 2009 17:01:01 +0100
Subject: [PATCH] Fixes:    Fixed duplicate check when adding files using the
 resource editor

Task:     238308
RevBy:    eike
AutoTest: -
Details:  Instead of the text and prefix of the file to add, pointers were compared. Thus the function always returned false and duplicates were not recognized. Replaced struct FileList with a class FileList, which is inherited from QList and added the function containsList which checks the needed values.
---
 src/shared/qrceditor/resourcefile.cpp | 17 +++++++++++++++--
 src/shared/qrceditor/resourcefile_p.h |  7 ++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/shared/qrceditor/resourcefile.cpp b/src/shared/qrceditor/resourcefile.cpp
index b88444c6e16..bfab4b0315f 100644
--- a/src/shared/qrceditor/resourcefile.cpp
+++ b/src/shared/qrceditor/resourcefile.cpp
@@ -54,6 +54,19 @@ TRANSLATOR qdesigner_internal::ResourceModel
 
 namespace qdesigner_internal {
 
+
+/******************************************************************************
+** FileList
+*/
+
+bool FileList::containsFile(File *file)
+{
+    foreach(File *tmpFile, *this)
+        if (tmpFile->name == file->name && tmpFile->prefix() == file->prefix())
+            return true;
+    return false;
+}
+
 /******************************************************************************
 ** ResourceFile
 */
@@ -375,7 +388,7 @@ bool ResourceFile::contains(const QString &prefix, const QString &file) const
     Prefix * const p = m_prefix_list.at(pref_idx);
     Q_ASSERT(p);
     File equalFile(p, absolutePath(file));
-    return p->file_list.contains(&equalFile);
+    return p->file_list.containsFile(&equalFile);
 }
 
 bool ResourceFile::contains(int pref_idx, const QString &file) const
@@ -383,7 +396,7 @@ bool ResourceFile::contains(int pref_idx, const QString &file) const
     Q_ASSERT(pref_idx >= 0 && pref_idx < m_prefix_list.count());
     Prefix * const p = m_prefix_list.at(pref_idx);
     File equalFile(p, absolutePath(file));
-    return p->file_list.contains(&equalFile);
+    return p->file_list.containsFile(&equalFile);
 }
 
 /*static*/ QString ResourceFile::fixPrefix(const QString &prefix)
diff --git a/src/shared/qrceditor/resourcefile_p.h b/src/shared/qrceditor/resourcefile_p.h
index 61b6c594b64..3ee346cb0e6 100644
--- a/src/shared/qrceditor/resourcefile_p.h
+++ b/src/shared/qrceditor/resourcefile_p.h
@@ -90,7 +90,12 @@ struct File : public Node {
     QString name;
     QString alias;
 };
-typedef QList<File *> FileList;
+
+class FileList : public QList<File *>
+{
+public:
+    bool containsFile(File *file);
+};
 
 /*!
     \class Prefix
-- 
GitLab