summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-06 21:14:16 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-11-06 21:58:01 (GMT)
commitd4f08b8f15607ac2859c079e94bf8d02a9b8380c (patch)
treec57c37ae148bffde5bddfabf085e8a8c7e8a8893
parent1bf836526332626825c21e7e62305d2019c65701 (diff)
downloadQt-d4f08b8f15607ac2859c079e94bf8d02a9b8380c.zip
Qt-d4f08b8f15607ac2859c079e94bf8d02a9b8380c.tar.gz
Qt-d4f08b8f15607ac2859c079e94bf8d02a9b8380c.tar.bz2
eliminate TranslatorMessagePtr from the Translator api
-rw-r--r--tools/linguist/lconvert/main.cpp4
-rw-r--r--tools/linguist/linguist/messagemodel.cpp13
-rw-r--r--tools/linguist/lrelease/main.cpp2
-rw-r--r--tools/linguist/shared/translator.cpp47
-rw-r--r--tools/linguist/shared/translator.h7
-rw-r--r--tools/linguist/shared/translatormessage.h26
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<TranslatorMessagePtr> dupes = tor.resolveDuplicates();
- if (!dupes.isEmpty()) {
+ Translator::Duplicates dupes = tor.resolveDuplicates();
+ if (!dupes.byContents.isEmpty()) {
QString err = tr("<qt>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("<p>[more duplicates omitted]");
break;
}
err += tr("<p>* Context: %1<br>* Source: %2")
- .arg(Qt::escape(msg->context()), Qt::escape(msg->sourceText()));
- if (!msg->comment().isEmpty())
- err += tr("<br>* Comment: %3").arg(Qt::escape(msg->comment()));
+ .arg(Qt::escape(msg.context()), Qt::escape(msg.sourceText()));
+ if (!msg.comment().isEmpty())
+ err += tr("<br>* 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<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