From d4f08b8f15607ac2859c079e94bf8d02a9b8380c Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 22:14:16 +0100 Subject: eliminate TranslatorMessagePtr from the Translator api --- tools/linguist/lconvert/main.cpp | 4 +-- tools/linguist/linguist/messagemodel.cpp | 13 +++++---- tools/linguist/lrelease/main.cpp | 2 +- tools/linguist/shared/translator.cpp | 47 ++++++++++++++++++++++++------- tools/linguist/shared/translator.h | 7 +++-- tools/linguist/shared/translatormessage.h | 26 ----------------- 6 files changed, 51 insertions(+), 48 deletions(-) diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp index 6f5f86a..7807761 100644 --- a/tools/linguist/lconvert/main.cpp +++ b/tools/linguist/lconvert/main.cpp @@ -239,7 +239,7 @@ int main(int argc, char *argv[]) qWarning() << qPrintable(cd.error()); return 2; } - Translator::reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose); + tr.reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose); for (int i = 1; i < inFiles.size(); ++i) { Translator tr2; @@ -247,7 +247,7 @@ int main(int argc, char *argv[]) qWarning() << qPrintable(cd.error()); return 2; } - Translator::reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose); + tr2.reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose); for (int j = 0; j < tr2.messageCount(); ++j) tr.replaceSorted(tr2.message(j)); } diff --git a/tools/linguist/linguist/messagemodel.cpp b/tools/linguist/linguist/messagemodel.cpp index e6bb9af..8966624 100644 --- a/tools/linguist/linguist/messagemodel.cpp +++ b/tools/linguist/linguist/messagemodel.cpp @@ -209,19 +209,20 @@ bool DataModel::load(const QString &fileName, bool *langGuessed, QWidget *parent return false; } - QSet dupes = tor.resolveDuplicates(); - if (!dupes.isEmpty()) { + Translator::Duplicates dupes = tor.resolveDuplicates(); + if (!dupes.byContents.isEmpty()) { QString err = tr("Duplicate messages found in '%1':").arg(Qt::escape(fileName)); int numdups = 0; - foreach (const TranslatorMessagePtr &msg, dupes) { + foreach (int j, dupes.byContents) { + const TranslatorMessage &msg = tor.message(j); if (++numdups >= 5) { err += tr("

[more duplicates omitted]"); break; } err += tr("

* Context: %1
* Source: %2") - .arg(Qt::escape(msg->context()), Qt::escape(msg->sourceText())); - if (!msg->comment().isEmpty()) - err += tr("
* Comment: %3").arg(Qt::escape(msg->comment())); + .arg(Qt::escape(msg.context()), Qt::escape(msg.sourceText())); + if (!msg.comment().isEmpty()) + err += tr("
* Comment: %3").arg(Qt::escape(msg.comment())); } QMessageBox::warning(parent, QObject::tr("Qt Linguist"), err); } diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp index ecaed27..742c2e6 100644 --- a/tools/linguist/lrelease/main.cpp +++ b/tools/linguist/lrelease/main.cpp @@ -105,7 +105,7 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo static bool releaseTranslator(Translator &tor, const QString &qmFileName, ConversionData &cd, bool removeIdentical) { - Translator::reportDuplicates(tor.resolveDuplicates(), qmFileName, cd.isVerbose()); + tor.reportDuplicates(tor.resolveDuplicates(), qmFileName, cd.isVerbose()); if (cd.isVerbose()) printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName)); 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 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 dups; + Duplicates dups; QHash refs; for (int i = 0; i < m_messages.count();) { const TranslatorMessage &msg = m_messages.at(i); @@ -426,7 +452,7 @@ QSet 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 Translator::resolveDuplicates() return dups; } -void Translator::reportDuplicates(const QSet &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 resolveDuplicates(); - static void reportDuplicates(const QSet &dupes, - const QString &fileName, bool verbose); + + struct Duplicates { QSet 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 -- cgit v0.12