diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-06 21:14:16 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-06 21:58:01 (GMT) |
commit | d4f08b8f15607ac2859c079e94bf8d02a9b8380c (patch) | |
tree | c57c37ae148bffde5bddfabf085e8a8c7e8a8893 /tools/linguist/shared | |
parent | 1bf836526332626825c21e7e62305d2019c65701 (diff) | |
download | Qt-d4f08b8f15607ac2859c079e94bf8d02a9b8380c.zip Qt-d4f08b8f15607ac2859c079e94bf8d02a9b8380c.tar.gz Qt-d4f08b8f15607ac2859c079e94bf8d02a9b8380c.tar.bz2 |
eliminate TranslatorMessagePtr from the Translator api
Diffstat (limited to 'tools/linguist/shared')
-rw-r--r-- | tools/linguist/shared/translator.cpp | 47 | ||||
-rw-r--r-- | tools/linguist/shared/translator.h | 7 | ||||
-rw-r--r-- | tools/linguist/shared/translatormessage.h | 26 |
3 files changed, 41 insertions, 39 deletions
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 8ff6719..5bdd133 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -411,9 +411,35 @@ void Translator::dropUiLines() } } -QSet<TranslatorMessagePtr> Translator::resolveDuplicates() +struct TranslatorMessagePtr { + TranslatorMessagePtr(const TranslatorMessage &tm) + { + ptr = &tm; + } + + inline const TranslatorMessage *operator->() const + { + return ptr; + } + + const TranslatorMessage *ptr; +}; + +Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE); + +inline int qHash(TranslatorMessagePtr tmp) +{ + return qHash(*tmp.ptr); +} + +inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2) +{ + return *tmp1.ptr == *tmp2.ptr; +} + +Translator::Duplicates Translator::resolveDuplicates() { - QSet<TranslatorMessagePtr> dups; + Duplicates dups; QHash<TranslatorMessagePtr, int> refs; for (int i = 0; i < m_messages.count();) { const TranslatorMessage &msg = m_messages.at(i); @@ -426,7 +452,7 @@ QSet<TranslatorMessagePtr> Translator::resolveDuplicates() omsg.setNonUtf8(true); } else { // Duplicate - dups.insert(omsg); + dups.byContents.insert(*it); } if (!omsg.isTranslated() && msg.isTranslated()) omsg.setTranslations(msg.translations()); @@ -439,21 +465,22 @@ QSet<TranslatorMessagePtr> Translator::resolveDuplicates() return dups; } -void Translator::reportDuplicates(const QSet<TranslatorMessagePtr> &dupes, +void Translator::reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose) { - if (!dupes.isEmpty()) { + if (!dupes.byContents.isEmpty()) { if (!verbose) { qWarning("Warning: dropping duplicate messages in '%s'\n(try -verbose for more info).", qPrintable(fileName)); } else { qWarning("Warning: dropping duplicate messages in '%s':", qPrintable(fileName)); - foreach (const TranslatorMessagePtr &msg, dupes) { + foreach (int j, dupes.byContents) { + const TranslatorMessage &msg = message(j); qWarning("\n* Context: %s\n* Source: %s", - qPrintable(msg->context()), - qPrintable(msg->sourceText())); - if (!msg->comment().isEmpty()) - qWarning("* Comment: %s", qPrintable(msg->comment())); + qPrintable(msg.context()), + qPrintable(msg.sourceText())); + if (!msg.comment().isEmpty()) + qWarning("* Comment: %s", qPrintable(msg.comment())); } qWarning(); } diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index a44d53c..654c6ab 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -132,9 +132,10 @@ public: void dropTranslations(); void dropUiLines(); void makeFileNamesAbsolute(const QDir &originalPath); - QSet<TranslatorMessagePtr> resolveDuplicates(); - static void reportDuplicates(const QSet<TranslatorMessagePtr> &dupes, - const QString &fileName, bool verbose); + + struct Duplicates { QSet<int> byContents; }; + Duplicates resolveDuplicates(); + void reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose); void setCodecName(const QByteArray &name); QByteArray codecName() const { return m_codecName; } diff --git a/tools/linguist/shared/translatormessage.h b/tools/linguist/shared/translatormessage.h index fb3cc4b..2eb6e5e 100644 --- a/tools/linguist/shared/translatormessage.h +++ b/tools/linguist/shared/translatormessage.h @@ -178,32 +178,6 @@ Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE); int qHash(const TranslatorMessage &msg); -struct TranslatorMessagePtr { - TranslatorMessagePtr(const TranslatorMessage &tm) - { - ptr = &tm; - } - - inline const TranslatorMessage *operator->() const - { - return ptr; - } - - const TranslatorMessage *ptr; -}; - -Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE); - -inline int qHash(TranslatorMessagePtr tmp) -{ - return qHash(*tmp.ptr); -} - -inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2) -{ - return *tmp1.ptr == *tmp2.ptr; -} - QT_END_NAMESPACE #endif // QT_NO_TRANSLATION |