summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-06 21:04:57 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-06 21:58:01 (GMT)
commit44cc160733a70f5dc613faed2051005de7e48f04 (patch)
tree214a5d22918c752af5aff3ddf2dde07e6ced2060
parentd4f08b8f15607ac2859c079e94bf8d02a9b8380c (diff)
downloadQt-44cc160733a70f5dc613faed2051005de7e48f04.zip
Qt-44cc160733a70f5dc613faed2051005de7e48f04.tar.gz
Qt-44cc160733a70f5dc613faed2051005de7e48f04.tar.bz2
kill TranslatorMessage::operator==() and qHash(TranslatorMessage)
preparation work ...
-rw-r--r--tools/linguist/lupdate/merge.cpp4
-rw-r--r--tools/linguist/shared/translator.cpp28
-rw-r--r--tools/linguist/shared/translator.h1
-rw-r--r--tools/linguist/shared/translatormessage.cpp19
-rw-r--r--tools/linguist/shared/translatormessage.h4
5 files changed, 27 insertions, 29 deletions
diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp
index 6b8d4bb..13ba4ae 100644
--- a/tools/linguist/lupdate/merge.cpp
+++ b/tools/linguist/lupdate/merge.cpp
@@ -348,7 +348,7 @@ Translator merge(const Translator &tor, const Translator &virginTor,
m.setComment(mv.comment());
} else {
TranslatorMessage mv;
- int mvi = virginTor.messages().indexOf(m);
+ int mvi = virginTor.find(m);
if (mvi < 0) {
if (!(options & HeuristicSimilarText)) {
makeObsolete:
@@ -437,7 +437,7 @@ Translator merge(const Translator &tor, const Translator &virginTor,
if (tor.contains(mv.context()))
continue;
} else {
- if (tor.messages().contains(mv))
+ if (tor.find(mv) >= 0)
continue;
if (options & HeuristicSimilarText) {
TranslatorMessage m = tor.find(mv.context(), mv.comment(), mv.allReferences());
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index 5bdd133..0a59668 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -82,7 +82,7 @@ QList<Translator::FileFormat> &Translator::registeredFileFormats()
void Translator::replaceSorted(const TranslatorMessage &msg)
{
- int index = m_messages.indexOf(msg);
+ int index = find(msg);
if (index == -1)
appendSorted(msg);
else
@@ -91,7 +91,7 @@ void Translator::replaceSorted(const TranslatorMessage &msg)
void Translator::extend(const TranslatorMessage &msg)
{
- int index = m_messages.indexOf(msg);
+ int index = find(msg);
if (index == -1) {
m_messages.append(msg);
} else {
@@ -302,6 +302,18 @@ bool Translator::release(QFile *iod, ConversionData &cd) const
return false;
}
+int Translator::find(const TranslatorMessage &msg) const
+{
+ for (int i = 0; i < m_messages.count(); ++i) {
+ const TranslatorMessage &tmsg = m_messages.at(i);
+ if (msg.context() == tmsg.context()
+ && msg.sourceText() == tmsg.sourceText()
+ && msg.comment() == tmsg.comment())
+ return i;
+ }
+ return -1;
+}
+
TranslatorMessage Translator::find(const QString &context,
const QString &comment, const TranslatorMessage::References &refs) const
{
@@ -429,12 +441,20 @@ Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE);
inline int qHash(TranslatorMessagePtr tmp)
{
- return qHash(*tmp.ptr);
+ return
+ qHash(tmp->context()) ^
+ qHash(tmp->sourceText()) ^
+ qHash(tmp->comment()) ^
+ qHash(tmp->id());
}
inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2)
{
- return *tmp1.ptr == *tmp2.ptr;
+ // Special treatment for context comments (empty source).
+ return (tmp1->context() == tmp2->context())
+ && tmp1->sourceText() == tmp2->sourceText()
+ && tmp1->id() == tmp2->id()
+ && (tmp1->sourceText().isEmpty() || tmp1->comment() == tmp2->comment());
}
Translator::Duplicates Translator::resolveDuplicates()
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index 654c6ab..b957fa2 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -113,6 +113,7 @@ public:
bool save(const QString &filename, ConversionData &err, const QString &format /*= "auto"*/) const;
bool release(QFile *iod, ConversionData &cd) const;
+ int find(const TranslatorMessage &msg) const;
TranslatorMessage find(const QString &context,
const QString &comment, const TranslatorMessage::References &refs) const;
diff --git a/tools/linguist/shared/translatormessage.cpp b/tools/linguist/shared/translatormessage.cpp
index 876b129..5151ebd 100644
--- a/tools/linguist/shared/translatormessage.cpp
+++ b/tools/linguist/shared/translatormessage.cpp
@@ -143,25 +143,6 @@ bool TranslatorMessage::needs8Bit() const
}
-bool TranslatorMessage::operator==(const TranslatorMessage& m) const
-{
- // Special treatment for context comments (empty source).
- return (m_context == m.m_context)
- && m_sourcetext == m.m_sourcetext
- && m_id == m.m_id
- && (m_sourcetext.isEmpty() || m_comment == m.m_comment);
-}
-
-
-int qHash(const TranslatorMessage &msg)
-{
- return
- qHash(msg.context()) ^
- qHash(msg.sourceText()) ^
- qHash(msg.comment()) ^
- qHash(msg.id());
-}
-
bool TranslatorMessage::hasExtra(const QString &key) const
{
return m_extra.contains(key);
diff --git a/tools/linguist/shared/translatormessage.h b/tools/linguist/shared/translatormessage.h
index 2eb6e5e..60b60c5 100644
--- a/tools/linguist/shared/translatormessage.h
+++ b/tools/linguist/shared/translatormessage.h
@@ -109,8 +109,6 @@ public:
return false;
}
- bool operator==(const TranslatorMessage& m) const;
-
QString fileName() const { return m_fileName; }
void setFileName(const QString &fileName) { m_fileName = fileName; }
int lineNumber() const { return m_lineNumber; }
@@ -176,8 +174,6 @@ private:
Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE);
-int qHash(const TranslatorMessage &msg);
-
QT_END_NAMESPACE
#endif // QT_NO_TRANSLATION