From 79864599ec3a1ce5a5ede84ea2d3d7ba437a3257 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 5 Nov 2009 22:39:24 +0100 Subject: don't construct a new message for look-up purposes only --- tools/linguist/lupdate/merge.cpp | 8 +++++--- tools/linguist/shared/translator.cpp | 8 -------- tools/linguist/shared/translator.h | 2 -- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp index b5f77cd..cffbfa3 100644 --- a/tools/linguist/lupdate/merge.cpp +++ b/tools/linguist/lupdate/merge.cpp @@ -351,8 +351,9 @@ Translator merge(const Translator &tor, const Translator &virginTor, if (!mv.isNull()) m.setComment(mv.comment()); } else { - TranslatorMessage mv = virginTor.find(m.context(), m.sourceText(), m.comment()); - if (mv.isNull()) { + TranslatorMessage mv; + int mvi = virginTor.messages().indexOf(m); + if (mvi < 0) { if (!(options & HeuristicSimilarText)) { newType = TranslatorMessage::Obsolete; if (m.type() != TranslatorMessage::Obsolete) @@ -402,6 +403,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, } } } else { + mv = virginTor.message(mvi); switch (m.type()) { case TranslatorMessage::Finished: default: @@ -446,7 +448,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, if (tor.contains(mv.context())) continue; } else { - if (tor.contains(mv.context(), mv.sourceText(), mv.comment())) + if (tor.messages().contains(mv)) 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 cd670cc..3b7ee9a 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -319,14 +319,6 @@ bool Translator::contains(const QString &context, } TranslatorMessage Translator::find(const QString &context, - const QString &sourceText, const QString &comment) const -{ - TranslatorMessage needle(context, sourceText, comment, QString(), QString(), 0); - int index = m_messages.indexOf(needle); - return index == -1 ? TranslatorMessage() : m_messages.at(index); -} - -TranslatorMessage Translator::find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const { if (!refs.isEmpty()) { diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index ef81d2a..6db6f3a 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -115,8 +115,6 @@ public: bool contains(const QString &context, const QString &sourceText, const QString &comment) const; - TranslatorMessage find(const QString &context, - const QString &sourceText, const QString &comment) const; TranslatorMessage find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const; -- cgit v0.12 From ffa332a3c8eef08695791b9fdccfd2677ec325fc Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 5 Nov 2009 20:01:22 +0100 Subject: cut code dupe ... ... with gotos :) --- tools/linguist/lupdate/merge.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp index cffbfa3..1ae4cfb 100644 --- a/tools/linguist/lupdate/merge.cpp +++ b/tools/linguist/lupdate/merge.cpp @@ -355,6 +355,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, int mvi = virginTor.messages().indexOf(m); if (mvi < 0) { if (!(options & HeuristicSimilarText)) { + makeObsolete: newType = TranslatorMessage::Obsolete; if (m.type() != TranslatorMessage::Obsolete) obsoleted++; @@ -363,10 +364,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, mv = virginTor.find(m.context(), m.comment(), m.allReferences()); if (mv.isNull()) { // did not find it in the virgin, mark it as obsolete - newType = TranslatorMessage::Obsolete; - if (m.type() != TranslatorMessage::Obsolete) - obsoleted++; - m.clearReferences(); + goto makeObsolete; } else { // Do not just accept it if its on the same line number, // but different source text. @@ -388,17 +386,11 @@ Translator merge(const Translator &tor, const Translator &virginTor, m.setExtra(QLatin1String("po-old_msgid_plural"), oldpluralsource); m.unsetExtra(QLatin1String("po-msgid_plural")); } - m.setReferences(mv.allReferences()); // Update secondary references - m.setPlural(mv.isPlural()); - m.setUtf8(mv.isUtf8()); - m.setExtraComment(mv.extraComment()); + goto copyAttribs; // Update secondary references } else { // The virgin and vernacular sourceTexts are so // different that we could not find it. - newType = TranslatorMessage::Obsolete; - if (m.type() != TranslatorMessage::Obsolete) - obsoleted++; - m.clearReferences(); + goto makeObsolete; } } } @@ -428,6 +420,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, // This should also enable us to read a file that does not // have the element. // why not use operator=()? Because it overwrites e.g. userData. + copyAttribs: m.setReferences(mv.allReferences()); m.setPlural(mv.isPlural()); m.setUtf8(mv.isUtf8()); -- cgit v0.12 From cfb02f6e1434b0d9ebf9d65cc5048036418bb64d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 5 Nov 2009 22:47:54 +0100 Subject: remove unused TranslatorMessage::operator<() it was once needed for QMap, but we don't use that any more --- tools/linguist/shared/translatormessage.cpp | 11 ----------- tools/linguist/shared/translatormessage.h | 1 - 2 files changed, 12 deletions(-) diff --git a/tools/linguist/shared/translatormessage.cpp b/tools/linguist/shared/translatormessage.cpp index db6f333..0e7cb18 100644 --- a/tools/linguist/shared/translatormessage.cpp +++ b/tools/linguist/shared/translatormessage.cpp @@ -156,17 +156,6 @@ bool TranslatorMessage::operator==(const TranslatorMessage& m) const } -bool TranslatorMessage::operator<(const TranslatorMessage& m) const -{ - if (m_context != m.m_context) - return m_context < m.m_context; - if (m_sourcetext != m.m_sourcetext) - return m_sourcetext < m.m_sourcetext; - if (m_comment != m.m_comment) - return m_comment < m.m_comment; - return m_id < m.m_id; -} - int qHash(const TranslatorMessage &msg) { return diff --git a/tools/linguist/shared/translatormessage.h b/tools/linguist/shared/translatormessage.h index 675bba7..fb3cc4b 100644 --- a/tools/linguist/shared/translatormessage.h +++ b/tools/linguist/shared/translatormessage.h @@ -110,7 +110,6 @@ public: } bool operator==(const TranslatorMessage& m) const; - bool operator<(const TranslatorMessage& m) const; QString fileName() const { return m_fileName; } void setFileName(const QString &fileName) { m_fileName = fileName; } -- cgit v0.12 From 60b6fcdd18c4a21df086a0965bd2d536a39d2094 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 16:37:33 +0100 Subject: do not consider plural source in comparisons two messages with identical singular but different plural sources simply make no sense. this should be quite a bit faster, as it saves lots of QHash lookups. --- tools/linguist/shared/translatormessage.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/linguist/shared/translatormessage.cpp b/tools/linguist/shared/translatormessage.cpp index 0e7cb18..876b129 100644 --- a/tools/linguist/shared/translatormessage.cpp +++ b/tools/linguist/shared/translatormessage.cpp @@ -145,12 +145,9 @@ bool TranslatorMessage::needs8Bit() const bool TranslatorMessage::operator==(const TranslatorMessage& m) const { - static QString msgIdPlural = QLatin1String("po-msgid_plural"); - // Special treatment for context comments (empty source). return (m_context == m.m_context) && m_sourcetext == m.m_sourcetext - && m_extra[msgIdPlural] == m.m_extra[msgIdPlural] && m_id == m.m_id && (m_sourcetext.isEmpty() || m_comment == m.m_comment); } @@ -161,7 +158,6 @@ int qHash(const TranslatorMessage &msg) return qHash(msg.context()) ^ qHash(msg.sourceText()) ^ - qHash(msg.extra(QLatin1String("po-msgid_plural"))) ^ qHash(msg.comment()) ^ qHash(msg.id()); } -- cgit v0.12 From 60acaf5ec7edcd1baf4dd8f80cf93b3e2cb520e4 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 21:05:18 +0100 Subject: use right method to record new messages consistent with all other source parsers --- tools/linguist/lupdate/qscript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linguist/lupdate/qscript.cpp b/tools/linguist/lupdate/qscript.cpp index 4600656..6c94588 100644 --- a/tools/linguist/lupdate/qscript.cpp +++ b/tools/linguist/lupdate/qscript.cpp @@ -776,7 +776,7 @@ static void recordMessage( fileName, lineNo, QStringList(), TranslatorMessage::Unfinished, plural); msg.setExtraComment(extracomment.simplified()); - tor->replace(msg); + tor->extend(msg); } -- cgit v0.12 From 92e9a481518d1c13df32bc2f1a9c8a0ba0b8961a Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 21:07:15 +0100 Subject: eliminate Translator::replace() --- tools/linguist/lupdate/merge.cpp | 10 +++------- tools/linguist/shared/translator.cpp | 9 --------- tools/linguist/shared/translator.h | 1 - 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp index 1ae4cfb..6b8d4bb 100644 --- a/tools/linguist/lupdate/merge.cpp +++ b/tools/linguist/lupdate/merge.cpp @@ -247,10 +247,8 @@ int applyNumberHeuristic(Translator &tor) t = translated.find(zeroKey((*u).sourceText())); if (t != translated.end() && !t.key().isEmpty() && t->sourceText() != u->sourceText()) { - TranslatorMessage m = *u; - m.setTranslation(translationAttempt(t->translation(), t->sourceText(), - u->sourceText())); - tor.replace(m); + u->setTranslation(translationAttempt(t->translation(), t->sourceText(), + u->sourceText())); inserted++; } } @@ -305,9 +303,7 @@ int applySameTextHeuristic(Translator &tor) QString key = u->sourceText(); t = translated.find(key); if (t != translated.end()) { - TranslatorMessage m = *u; - m.setTranslations(t->translations()); - tor.replace(m); + u->setTranslations(t->translations()); ++inserted; } } diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 3b7ee9a..92ecf07 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -80,15 +80,6 @@ QList &Translator::registeredFileFormats() return theFormats; } -void Translator::replace(const TranslatorMessage &msg) -{ - int index = m_messages.indexOf(msg); - if (index == -1) - m_messages.append(msg); - else - m_messages[index] = msg; -} - void Translator::replaceSorted(const TranslatorMessage &msg) { int index = m_messages.indexOf(msg); diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index 6db6f3a..c51993d 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -122,7 +122,6 @@ public: bool contains(const QString &context) const; TranslatorMessage find(const QString &context) const; - void replace(const TranslatorMessage &msg); void replaceSorted(const TranslatorMessage &msg); void extend(const TranslatorMessage &msg); // Only for single-location messages void append(const TranslatorMessage &msg); -- cgit v0.12 From e9a0d840133f53e2a2fb138b9042000c883d0283 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 21:14:15 +0100 Subject: eliminate Translator::contains() replace the one use case with something more efficient --- tools/linguist/shared/qm.cpp | 12 +++++++++++- tools/linguist/shared/translator.cpp | 7 ------- tools/linguist/shared/translator.h | 3 --- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp index 5965aac..99aedef 100644 --- a/tools/linguist/shared/qm.cpp +++ b/tools/linguist/shared/qm.cpp @@ -685,6 +685,16 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd) +static bool containsStripped(const Translator &translator, const TranslatorMessage &msg) +{ + foreach (const TranslatorMessage &tmsg, translator.messages()) + if (tmsg.sourceText() == msg.sourceText() + && tmsg.context() == msg.context() + && tmsg.comment().isEmpty()) + return true; + return false; +} + static bool saveQM(const Translator &translator, QIODevice &dev, ConversionData &cd) { Releaser releaser; @@ -741,7 +751,7 @@ static bool saveQM(const Translator &translator, QIODevice &dev, ConversionData bool forceComment = msg.comment().isEmpty() || msg.context().isEmpty() - || translator.contains(msg.context(), msg.sourceText(), QString()); + || containsStripped(translator, msg); releaser.insert(msg, tlns, forceComment); } } diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 92ecf07..a35666d 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -302,13 +302,6 @@ bool Translator::release(QFile *iod, ConversionData &cd) const return false; } -bool Translator::contains(const QString &context, - const QString &sourceText, const QString &comment) const -{ - return m_messages.contains(TranslatorMessage(context, sourceText, comment, - QString(), QString(), 0)); -} - TranslatorMessage Translator::find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const { diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index c51993d..a44d53c 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -113,9 +113,6 @@ public: bool save(const QString &filename, ConversionData &err, const QString &format /*= "auto"*/) const; bool release(QFile *iod, ConversionData &cd) const; - bool contains(const QString &context, const QString &sourceText, - const QString &comment) const; - TranslatorMessage find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const; -- cgit v0.12 From 1bf836526332626825c21e7e62305d2019c65701 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 14:23:19 +0100 Subject: improve ordered message insertion in a ts file, the top level categorization are the contexts, so it makes no sense to make messages adjoint by file when the context is different. a more clever algorithm which tries to order the entire contexts is conceivable. that would be advantageous for files which use multiple contexts subsequentially if each context appears in only one file. --- tools/linguist/shared/translator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index a35666d..8ff6719 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -136,7 +136,7 @@ void Translator::appendSorted(const TranslatorMessage &msg) int prevLine = 0; int curIdx = 0; foreach (const TranslatorMessage &mit, m_messages) { - bool sameFile = mit.fileName() == msg.fileName(); + bool sameFile = mit.fileName() == msg.fileName() && mit.context() == msg.context(); int curLine; if (sameFile && (curLine = mit.lineNumber()) >= prevLine) { if (msgLine >= prevLine && msgLine < curLine) { -- cgit v0.12 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 From 44cc160733a70f5dc613faed2051005de7e48f04 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 22:04:57 +0100 Subject: kill TranslatorMessage::operator==() and qHash(TranslatorMessage) preparation work ... --- tools/linguist/lupdate/merge.cpp | 4 ++-- tools/linguist/shared/translator.cpp | 28 ++++++++++++++++++++++++---- tools/linguist/shared/translator.h | 1 + tools/linguist/shared/translatormessage.cpp | 19 ------------------- tools/linguist/shared/translatormessage.h | 4 ---- 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::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 -- cgit v0.12 From a66698f947e8ded2e020defa626b154aca1fde9f Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 6 Nov 2009 22:40:23 +0100 Subject: handle messages with ids (more) correctly when comparing two messages which both have ids, compare only the ids. this affects finding/reporting duplicates and merging. --- .../lupdate/testdata/good/mergecpp/finddialog.cpp | 13 +- .../testdata/good/mergecpp/project.ts.before | 18 +++ .../testdata/good/mergecpp/project.ts.result | 19 +++ .../good/mergecpp_noobsolete/finddialog.cpp | 3 + .../good/mergecpp_noobsolete/project.ts.before | 13 ++ .../good/mergecpp_noobsolete/project.ts.result | 8 ++ .../testdata/good/mergecpp_obsolete/finddialog.cpp | 3 + .../good/mergecpp_obsolete/project.ts.before | 13 ++ .../good/mergecpp_obsolete/project.ts.result | 12 ++ tools/linguist/linguist/messagemodel.cpp | 10 +- tools/linguist/lupdate/merge.cpp | 44 ++++--- tools/linguist/shared/translator.cpp | 134 +++++++++++++++------ tools/linguist/shared/translator.h | 2 +- 13 files changed, 239 insertions(+), 53 deletions(-) diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp b/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp index 53eba32..f27e1f0 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp @@ -63,5 +63,16 @@ void FindDialog::reset() { tr("%n item(s)", "merge from singular to plural form", 4); tr("%n item(s)", "merge from a finished singular form to an unfinished plural form", 4); -} + + + //% "Hello" + qtTrId("xx_hello"); + + //% "New world" + qtTrId("xx_world"); + + + //= new_id + tr("this is just some text"); +} diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before index d06252c..ad2f65f 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before @@ -1,6 +1,19 @@ + + + + Hello + Hallo + + + + World + Welt + + + FindDialog @@ -44,5 +57,10 @@ + + + this is just some text + Unfertige Uebersetzung + diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result index be4e02e..e9abf89 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result @@ -2,6 +2,20 @@ + + + + Hello + Hallo + + + + New world + World + Welt + + + FindDialog @@ -45,5 +59,10 @@ + + + this is just some text + Unfertige Uebersetzung + diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/finddialog.cpp b/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/finddialog.cpp index e1464a2..9abb367 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/finddialog.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/finddialog.cpp @@ -148,4 +148,7 @@ void FindDialog::doFind(bool forward) bool FindDialog::hasFindExpression() const { // statusMessage(tr( "Should be obsolete" )); + + //% "This is some random text" + qtTrId("keep_id") } diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.before b/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.before index 834f512..feab169 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.before +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.before @@ -1,6 +1,19 @@ + + + + This is some random text + + + + + Should be obsolete, too + SHOULD BE OBSOLETE AS WELL + + + FindDialog diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.result index b328e90..ee3d0f6 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/project.ts.result @@ -2,6 +2,14 @@ + + + + This is some random text + + + + FindDialog diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/finddialog.cpp b/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/finddialog.cpp index 7b28c75..cc3af48 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/finddialog.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/finddialog.cpp @@ -150,6 +150,9 @@ void FindDialog::doFind(bool forward) bool FindDialog::hasFindExpression() const { + //% "This is some random text" + qtTrId("keep_id") + return !findExpr.isEmpty(); } diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.before b/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.before index 1fa0fd3..2bc6049 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.before +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.before @@ -1,6 +1,19 @@ + + + + This is some random text + + + + + Should be obsolete, too + SHOULD BE OBSOLETE AS WELL + + + FindDialog diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.result index cfd11b1..f442cbc 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp_obsolete/project.ts.result @@ -2,6 +2,18 @@ + + + + This is some random text + + + + Should be obsolete, too + SHOULD BE OBSOLETE AS WELL + + + FindDialog Enter the text you are looking for. diff --git a/tools/linguist/linguist/messagemodel.cpp b/tools/linguist/linguist/messagemodel.cpp index 8966624..024fd91 100644 --- a/tools/linguist/linguist/messagemodel.cpp +++ b/tools/linguist/linguist/messagemodel.cpp @@ -210,9 +210,16 @@ bool DataModel::load(const QString &fileName, bool *langGuessed, QWidget *parent } Translator::Duplicates dupes = tor.resolveDuplicates(); - if (!dupes.byContents.isEmpty()) { + if (!dupes.byId.isEmpty() || !dupes.byContents.isEmpty()) { QString err = tr("Duplicate messages found in '%1':").arg(Qt::escape(fileName)); int numdups = 0; + foreach (int i, dupes.byId) { + if (++numdups >= 5) { + err += tr("

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

* ID: %1").arg(Qt::escape(tor.message(i).id())); + } foreach (int j, dupes.byContents) { const TranslatorMessage &msg = tor.message(j); if (++numdups >= 5) { @@ -224,6 +231,7 @@ bool DataModel::load(const QString &fileName, bool *langGuessed, QWidget *parent if (!msg.comment().isEmpty()) err += tr("
* Comment: %3").arg(Qt::escape(msg.comment())); } + doWarn: QMessageBox::warning(parent, QObject::tr("Qt Linguist"), err); } diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp index 13ba4ae..a721439 100644 --- a/tools/linguist/lupdate/merge.cpp +++ b/tools/linguist/lupdate/merge.cpp @@ -375,6 +375,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, ++similarTextHeuristicCount; neww++; + outdateSource: m.setOldSourceText(m.sourceText()); m.setSourceText(mv.sourceText()); const QString &oldpluralsource = m.extra(QLatin1String("po-msgid_plural")); @@ -392,23 +393,35 @@ Translator merge(const Translator &tor, const Translator &virginTor, } } else { mv = virginTor.message(mvi); - switch (m.type()) { - case TranslatorMessage::Finished: - default: - if (m.isPlural() == mv.isPlural()) { - newType = TranslatorMessage::Finished; - } else { - newType = TranslatorMessage::Unfinished; - } + if (!mv.id().isEmpty() + && (mv.context() != m.context() + || mv.sourceText() != m.sourceText() + || mv.comment() != m.comment())) { known++; - break; - case TranslatorMessage::Unfinished: newType = TranslatorMessage::Unfinished; - known++; - break; - case TranslatorMessage::Obsolete: - newType = TranslatorMessage::Unfinished; - neww++; + m.setContext(mv.context()); + m.setComment(mv.comment()); + if (mv.sourceText() != m.sourceText()) + goto outdateSource; + } else { + switch (m.type()) { + case TranslatorMessage::Finished: + default: + if (m.isPlural() == mv.isPlural()) { + newType = TranslatorMessage::Finished; + } else { + newType = TranslatorMessage::Unfinished; + } + known++; + break; + case TranslatorMessage::Unfinished: + newType = TranslatorMessage::Unfinished; + known++; + break; + case TranslatorMessage::Obsolete: + newType = TranslatorMessage::Unfinished; + neww++; + } } // Always get the filename and linenumber info from the @@ -421,6 +434,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, m.setPlural(mv.isPlural()); m.setUtf8(mv.isUtf8()); m.setExtraComment(mv.extraComment()); + m.setId(mv.id()); } } diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 0a59668..77faabd 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -306,10 +306,15 @@ 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; + if (msg.id().isEmpty() || tmsg.id().isEmpty()) { + if (msg.context() == tmsg.context() + && msg.sourceText() == tmsg.sourceText() + && msg.comment() == tmsg.comment()) + return i; + } else { + if (msg.id() == tmsg.id()) + return i; + } } return -1; } @@ -423,8 +428,34 @@ void Translator::dropUiLines() } } -struct TranslatorMessagePtr { - TranslatorMessagePtr(const TranslatorMessage &tm) +struct TranslatorMessageIdPtr { + explicit TranslatorMessageIdPtr(const TranslatorMessage &tm) + { + ptr = &tm; + } + + inline const TranslatorMessage *operator->() const + { + return ptr; + } + + const TranslatorMessage *ptr; +}; + +Q_DECLARE_TYPEINFO(TranslatorMessageIdPtr, Q_MOVABLE_TYPE); + +inline int qHash(TranslatorMessageIdPtr tmp) +{ + return qHash(tmp->id()); +} + +inline bool operator==(TranslatorMessageIdPtr tmp1, TranslatorMessageIdPtr tmp2) +{ + return tmp1->id() == tmp2->id(); +} + +struct TranslatorMessageContentPtr { + explicit TranslatorMessageContentPtr(const TranslatorMessage &tm) { ptr = &tm; } @@ -437,50 +468,81 @@ struct TranslatorMessagePtr { const TranslatorMessage *ptr; }; -Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(TranslatorMessageContentPtr, Q_MOVABLE_TYPE); -inline int qHash(TranslatorMessagePtr tmp) +inline int qHash(TranslatorMessageContentPtr tmp) { - return - qHash(tmp->context()) ^ - qHash(tmp->sourceText()) ^ - qHash(tmp->comment()) ^ - qHash(tmp->id()); + int hash = qHash(tmp->context()) ^ qHash(tmp->sourceText()); + if (!tmp->sourceText().isEmpty()) + // Special treatment for context comments (empty source). + hash ^= qHash(tmp->comment()); + return hash; } -inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2) +inline bool operator==(TranslatorMessageContentPtr tmp1, TranslatorMessageContentPtr tmp2) { + if (tmp1->context() != tmp2->context() || tmp1->sourceText() != tmp2->sourceText()) + return false; // 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()); + if (tmp1->sourceText().isEmpty()) + return true; + return tmp1->comment() == tmp2->comment(); } Translator::Duplicates Translator::resolveDuplicates() { Duplicates dups; - QHash refs; + QHash idRefs; + QHash contentRefs; for (int i = 0; i < m_messages.count();) { const TranslatorMessage &msg = m_messages.at(i); - QHash::ConstIterator it = refs.constFind(msg); - if (it != refs.constEnd()) { - TranslatorMessage &omsg = m_messages[*it]; - if (omsg.isUtf8() != msg.isUtf8() && !omsg.isNonUtf8()) { - // Dual-encoded message - omsg.setUtf8(true); - omsg.setNonUtf8(true); - } else { - // Duplicate - dups.byContents.insert(*it); + TranslatorMessage *omsg; + int oi; + QSet *pDup; + if (!msg.id().isEmpty()) { + QHash::ConstIterator it = + idRefs.constFind(TranslatorMessageIdPtr(msg)); + if (it != idRefs.constEnd()) { + oi = *it; + omsg = &m_messages[oi]; + pDup = &dups.byId; + goto gotDupe; + } + } + { + QHash::ConstIterator it = + contentRefs.constFind(TranslatorMessageContentPtr(msg)); + if (it != contentRefs.constEnd()) { + oi = *it; + omsg = &m_messages[oi]; + if (msg.id().isEmpty() || omsg->id().isEmpty()) { + if (!msg.id().isEmpty() && omsg->id().isEmpty()) { + omsg->setId(msg.id()); + idRefs[TranslatorMessageIdPtr(*omsg)] = oi; + } + pDup = &dups.byContents; + goto gotDupe; + } + // This is really a content dupe, but with two distinct IDs. } - if (!omsg.isTranslated() && msg.isTranslated()) - omsg.setTranslations(msg.translations()); - m_messages.removeAt(i); + } + if (!msg.id().isEmpty()) + idRefs[TranslatorMessageIdPtr(msg)] = i; + contentRefs[TranslatorMessageContentPtr(msg)] = i; + ++i; + continue; + gotDupe: + if (omsg->isUtf8() != msg.isUtf8() && !omsg->isNonUtf8()) { + // Dual-encoded message + omsg->setUtf8(true); + omsg->setNonUtf8(true); } else { - refs[msg] = i; - ++i; + // Duplicate + pDup->insert(oi); } + if (!omsg->isTranslated() && msg.isTranslated()) + omsg->setTranslations(msg.translations()); + m_messages.removeAt(i); } return dups; } @@ -488,12 +550,14 @@ Translator::Duplicates Translator::resolveDuplicates() void Translator::reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose) { - if (!dupes.byContents.isEmpty()) { + if (!dupes.byId.isEmpty() || !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 (int i, dupes.byId) + qWarning("\n* ID: %s", qPrintable(message(i).id())); foreach (int j, dupes.byContents) { const TranslatorMessage &msg = message(j); qWarning("\n* Context: %s\n* Source: %s", diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index b957fa2..eec704a 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -134,7 +134,7 @@ public: void dropUiLines(); void makeFileNamesAbsolute(const QDir &originalPath); - struct Duplicates { QSet byContents; }; + struct Duplicates { QSet byId, byContents; }; Duplicates resolveDuplicates(); void reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose); -- cgit v0.12 From 0a1db39ba70060f305e5694d1a12dd3c2e5bca4c Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 5 Nov 2009 15:19:02 +0100 Subject: record id-based messages even if they have an empty source this makes sense if one uses lupdate only for validation purposes, i.e. to find out if the code uses only ids which are defined in some external specification. --- .../lupdate/testdata/good/mergecpp/finddialog.cpp | 4 ++++ .../testdata/good/mergecpp/project.ts.before | 4 ++++ .../testdata/good/mergecpp/project.ts.result | 6 +++++ .../lupdate/testdata/good/parsecpp/main.cpp | 5 +++++ .../testdata/good/parsecpp/project.ts.result | 6 +++++ tools/linguist/lupdate/cpp.cpp | 26 +++++++++------------- tools/linguist/lupdate/merge.cpp | 6 ++--- tools/linguist/shared/translator.cpp | 4 ++-- 8 files changed, 41 insertions(+), 20 deletions(-) diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp b/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp index f27e1f0..5bd7a0a 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp/finddialog.cpp @@ -75,4 +75,8 @@ void FindDialog::reset() //= new_id tr("this is just some text"); + + + //: A message without source string + qtTrId("qtn_virtual"); } diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before index ad2f65f..379cce4 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.before @@ -12,6 +12,10 @@ World Welt + + + A message without source string + FindDialog diff --git a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result index e9abf89..de43266 100644 --- a/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/mergecpp/project.ts.result @@ -14,6 +14,12 @@ World Welt + + + + A message without source string + + FindDialog diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp index e243e66..386d9b7 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp @@ -247,3 +247,8 @@ class YetAnotherTest : QObject { tr("nothing"); } }; + + + +//: This is a message without a source string +QString test = qtTrId("yet_another_id"); diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result index 26e5a65..6d50c21 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result @@ -18,6 +18,12 @@ backslashed \ stuff. thing + + + + This is a message without a source string + + Dialog2 diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index fb95a95..443abd0 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -1883,22 +1883,18 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) case Tok_trid: if (!tor) goto case_default; - if (sourcetext.isEmpty()) { - yyTok = getToken(); - } else { - if (!msgid.isEmpty()) - qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n", - qPrintable(yyFileName), yyLineNo); - //utf8 = false; // Maybe use //%% or something like that - line = yyLineNo; - yyTok = getToken(); - if (match(Tok_LeftParen) && matchString(&msgid) && !msgid.isEmpty()) { - bool plural = match(Tok_Comma); - recordMessage(line, QString(), sourcetext, QString(), extracomment, - msgid, extra, false, plural); - } - sourcetext.clear(); + if (!msgid.isEmpty()) + qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n", + qPrintable(yyFileName), yyLineNo); + //utf8 = false; // Maybe use //%% or something like that + line = yyLineNo; + yyTok = getToken(); + if (match(Tok_LeftParen) && matchString(&msgid) && !msgid.isEmpty()) { + bool plural = match(Tok_Comma); + recordMessage(line, QString(), sourcetext, QString(), extracomment, + msgid, extra, false, plural); } + sourcetext.clear(); extracomment.clear(); msgid.clear(); extra.clear(); diff --git a/tools/linguist/lupdate/merge.cpp b/tools/linguist/lupdate/merge.cpp index a721439..fa0dd3d 100644 --- a/tools/linguist/lupdate/merge.cpp +++ b/tools/linguist/lupdate/merge.cpp @@ -341,7 +341,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, foreach (TranslatorMessage m, tor.messages()) { TranslatorMessage::Type newType = TranslatorMessage::Finished; - if (m.sourceText().isEmpty()) { + if (m.sourceText().isEmpty() && m.id().isEmpty()) { // context/file comment TranslatorMessage mv = virginTor.find(m.context()); if (!mv.isNull()) @@ -447,7 +447,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, vernacular translator. */ foreach (const TranslatorMessage &mv, virginTor.messages()) { - if (mv.sourceText().isEmpty()) { + if (mv.sourceText().isEmpty() && mv.id().isEmpty()) { if (tor.contains(mv.context())) continue; } else { @@ -465,7 +465,7 @@ Translator merge(const Translator &tor, const Translator &virginTor, outTor.append(mv); else outTor.appendSorted(mv); - if (!mv.sourceText().isEmpty()) + if (!mv.sourceText().isEmpty() || !mv.id().isEmpty()) ++neww; } diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 77faabd..bc27daf 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -337,7 +337,7 @@ TranslatorMessage Translator::find(const QString &context, bool Translator::contains(const QString &context) const { foreach (const TranslatorMessage &msg, m_messages) - if (msg.context() == context && msg.sourceText().isEmpty()) + if (msg.context() == context && msg.sourceText().isEmpty() && msg.id().isEmpty()) return true; return false; } @@ -345,7 +345,7 @@ bool Translator::contains(const QString &context) const TranslatorMessage Translator::find(const QString &context) const { foreach (const TranslatorMessage &msg, m_messages) - if (msg.context() == context && msg.sourceText().isEmpty()) + if (msg.context() == context && msg.sourceText().isEmpty() && msg.id().isEmpty()) return msg; return TranslatorMessage(); } -- cgit v0.12 From 0fa5e302d2a4b7b79342f58905812f8ef3bd54b1 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 9 Nov 2009 11:43:34 +0100 Subject: Assistant: Fix bugs related to setting the current filter remotely. 1. Filter combo box now gets updated on remote setCurrentFilter. 2. Argument to remote setCurrentFilter now gets checked. If there is no such filter, we reject it. --- tools/assistant/tools/assistant/mainwindow.cpp | 21 +++++++++++---------- tools/assistant/tools/assistant/mainwindow.h | 1 + tools/assistant/tools/assistant/remotecontrol.cpp | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/assistant/tools/assistant/mainwindow.cpp b/tools/assistant/tools/assistant/mainwindow.cpp index de3f695..c56e7e4 100644 --- a/tools/assistant/tools/assistant/mainwindow.cpp +++ b/tools/assistant/tools/assistant/mainwindow.cpp @@ -227,16 +227,8 @@ MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent) if (!m_cmdLine->currentFilter().isEmpty()) { const QString &curFilter = m_cmdLine->currentFilter(); - m_helpEngine->setCurrentFilter(curFilter); - if (m_filterCombo) { - int idx = m_filterCombo->findText(curFilter); - if (idx >= 0) { - bool blocked = m_filterCombo->signalsBlocked(); - m_filterCombo->blockSignals(true); - m_filterCombo->setCurrentIndex(idx); - m_filterCombo->blockSignals(blocked); - } - } + if (m_helpEngine->customFilters().contains(curFilter)) + m_helpEngine->setCurrentFilter(curFilter); } if (usesDefaultCollection()) @@ -664,6 +656,8 @@ void MainWindow::setupFilterToolbar() SLOT(setupFilterCombo())); connect(m_filterCombo, SIGNAL(activated(QString)), this, SLOT(filterDocumentation(QString))); + connect(m_helpEngine, SIGNAL(currentFilterChanged(QString)), this, + SLOT(currentFilterChanged(QString))); setupFilterCombo(); } @@ -1041,4 +1035,11 @@ QString MainWindow::defaultHelpCollectionFileName() arg(QLatin1String(QT_VERSION_STR)); } +void MainWindow::currentFilterChanged(const QString &filter) +{ + const int index = m_filterCombo->findText(filter); + Q_ASSERT(index != -1); + m_filterCombo->setCurrentIndex(index); +} + QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/mainwindow.h b/tools/assistant/tools/assistant/mainwindow.h index 6b858e9..7559fe4 100644 --- a/tools/assistant/tools/assistant/mainwindow.h +++ b/tools/assistant/tools/assistant/mainwindow.h @@ -95,6 +95,7 @@ public slots: void showSearchWidget(); void syncContents(); void activateCurrentCentralWidgetTab(); + void currentFilterChanged(const QString &filter); private slots: void insertLastPages(); diff --git a/tools/assistant/tools/assistant/remotecontrol.cpp b/tools/assistant/tools/assistant/remotecontrol.cpp index be1c197..474a681 100644 --- a/tools/assistant/tools/assistant/remotecontrol.cpp +++ b/tools/assistant/tools/assistant/remotecontrol.cpp @@ -237,6 +237,8 @@ void RemoteControl::handleCommandString(const QString &cmdString) else m_mainWindow->expandTOC(depth); } else if (cmd == QLatin1String("setcurrentfilter")) { + if (!m_helpEngine->customFilters().contains(arg)) + return; if (m_caching) { clearCache(); m_currentFilter = arg; -- cgit v0.12 From 46a9b3e8e627b63b6d2ffe89311c00b2a1a5434d Mon Sep 17 00:00:00 2001 From: kh1 Date: Fri, 6 Nov 2009 12:15:14 +0100 Subject: Fix some warnings. Reviewed-by: ck --- tools/assistant/tools/assistant/helpviewer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index c888a5f..3547652 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -133,10 +133,9 @@ HelpNetworkAccessManager::HelpNetworkAccessManager(QHelpEngine *engine, { } -QNetworkReply *HelpNetworkAccessManager::createRequest(Operation op, - const QNetworkRequest &request, QIODevice *outgoingData) +QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, + const QNetworkRequest &request, QIODevice* /*outgoingData*/) { - const QString& scheme = request.url().scheme(); const QUrl& url = request.url(); QString mimeType = url.toString(); if (mimeType.endsWith(QLatin1String(".svg")) -- cgit v0.12 From b183a1d916b42e174da1d4ee71d387b6b8c48f72 Mon Sep 17 00:00:00 2001 From: kh1 Date: Mon, 9 Nov 2009 11:50:10 +0100 Subject: Fix Assistant losing font settings across invocations. Task-number: QTBUG-5333 Reviewed-by: ck --- tools/assistant/tools/assistant/centralwidget.cpp | 120 +++++++++++----------- tools/assistant/tools/assistant/centralwidget.h | 9 +- 2 files changed, 67 insertions(+), 62 deletions(-) diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index 62b4736..67d803d 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -666,34 +666,16 @@ void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom) tabWidget->setCurrentIndex(tabWidget->addTab(viewer, quoteTabTitle(viewer->documentTitle()))); - QFont font = qApp->font(); - bool userFont = helpEngine->customValue(QLatin1String("useBrowserFont")).toBool(); - if (userFont) { - font = qVariantValue(helpEngine->customValue( - QLatin1String("browserFont"))); - } - -#if !defined(QT_NO_WEBKIT) - QWebSettings *settings = QWebSettings::globalSettings(); - if (!userFont) { - int fontSize = settings->fontSize(QWebSettings::DefaultFontSize); - QString fontFamily = settings->fontFamily(QWebSettings::StandardFont); - font = QFont(fontFamily, fontSize); - } + QFont font; + getBrowserFontFor(viewer, &font); - QWebView *view = qobject_cast (viewer); - if (view) { - settings = view->settings(); - settings->setFontFamily(QWebSettings::StandardFont, font.family()); - settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize()); - } else if (viewer) { - viewer->setFont(font); - } - viewer->setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom); -#else +#if defined(QT_NO_WEBKIT) font.setPointSize((int)(font.pointSize() + zoom)); - viewer->setFont(font); + setBrowserFontFor(viewer, font); viewer->setZoom((int)zoom); +#else + setBrowserFontFor(viewer, font); + viewer->setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom); #endif connectSignals(); @@ -1011,41 +993,17 @@ bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf, void CentralWidget::updateBrowserFont() { - QFont font = qApp->font(); - bool userFont = helpEngine->customValue(QLatin1String("useBrowserFont")).toBool(); - if (userFont) { - font = qVariantValue(helpEngine->customValue( - QLatin1String("browserFont"))); - } - -#if !defined(QT_NO_WEBKIT) - QWebSettings *settings = QWebSettings::globalSettings(); - if (!userFont) { - int fontSize = settings->fontSize(QWebSettings::DefaultFontSize); - QString fontFamily = settings->fontFamily(QWebSettings::StandardFont); - font = QFont(fontFamily, fontSize); + QFont font; + bool searchAttached = searchWidgetAttached(); + if (searchAttached) { + getBrowserFontFor(m_searchWidget, &font); + setBrowserFontFor(m_searchWidget, font); } -#endif - QWidget *widget = 0; - for (int i = 0; i < tabWidget->count(); ++i) { - widget = tabWidget->widget(i); -#if !defined(QT_NO_WEBKIT) - QWebView *view = qobject_cast (widget); - if (view) { - settings = view->settings(); - settings->setFontFamily(QWebSettings::StandardFont, font.family()); - settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize()); - } else if (widget) { - if (!userFont) - font = qApp->font(); - widget->setFont(font); - } -#else - if (widget && widget->font() != font) - widget->setFont(font); -#endif - } + int i = searchAttached ? 1 : 0; + getBrowserFontFor(tabWidget->widget(i), &font); + for (i; i < tabWidget->count(); ++i) + setBrowserFontFor(tabWidget->widget(i), font); } void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) @@ -1058,6 +1016,10 @@ void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) SLOT(setSourceFromSearch(QUrl))); connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)), this, SLOT(setSourceFromSearchInNewTab(QUrl))); + + QFont font; + getBrowserFontFor(m_searchWidget, &font); + setBrowserFontFor(m_searchWidget, font); } void CentralWidget::activateSearchWidget(bool updateLastTabPage) @@ -1079,7 +1041,7 @@ void CentralWidget::activateSearchWidget(bool updateLastTabPage) void CentralWidget::removeSearchWidget() { - if (m_searchWidget && m_searchWidget->isAttached()) { + if (searchWidgetAttached()) { tabWidget->removeTab(0); m_searchWidget->setAttached(false); } @@ -1088,7 +1050,7 @@ void CentralWidget::removeSearchWidget() int CentralWidget::availableHelpViewer() const { int count = tabWidget->count(); - if (m_searchWidget && m_searchWidget->isAttached()) + if (searchWidgetAttached()) count--; return count; } @@ -1096,7 +1058,7 @@ int CentralWidget::availableHelpViewer() const bool CentralWidget::enableTabCloseAction() const { int minTabCount = 1; - if (m_searchWidget && m_searchWidget->isAttached()) + if (searchWidgetAttached()) minTabCount = 2; return (tabWidget->count() > minTabCount); @@ -1199,4 +1161,40 @@ QMap CentralWidget::currentSourceFileList() const return sourceList; } +void CentralWidget::getBrowserFontFor(QWidget *viewer, QFont *font) +{ + const QLatin1String key("useBrowserFont"); + if (!helpEngine->customValue(key, false).toBool()) { + *font = qApp->font(); // case for QTextBrowser and SearchWidget +#if !defined(QT_NO_WEBKIT) + QWebView *view = qobject_cast (viewer); + if (view) { + QWebSettings *settings = QWebSettings::globalSettings(); + *font = QFont(settings->fontFamily(QWebSettings::StandardFont), + settings->fontSize(QWebSettings::DefaultFontSize)); + } +#endif + } else { + *font = qVariantValue(helpEngine->customValue( + QLatin1String("browserFont"))); + } +} + +void CentralWidget::setBrowserFontFor(QWidget *widget, const QFont &font) +{ +#if !defined(QT_NO_WEBKIT) + QWebView *view = qobject_cast (widget); + if (view) { + QWebSettings *settings = view->settings(); + settings->setFontFamily(QWebSettings::StandardFont, font.family()); + settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize()); + } else if (widget && widget->font() != font) { + widget->setFont(font); + } +#else + if (widget && widget->font() != font) + widget->setFont(font); +#endif +} + QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h index 7ae8ee5..8c186f0 100644 --- a/tools/assistant/tools/assistant/centralwidget.h +++ b/tools/assistant/tools/assistant/centralwidget.h @@ -48,6 +48,8 @@ #include +#include "searchwidget.h" + QT_BEGIN_NAMESPACE class QEvent; @@ -65,7 +67,6 @@ class CentralWidget; class PrintHelper; class MainWindow; -class SearchWidget; class QHelpSearchEngine; class FindWidget : public QWidget @@ -123,6 +124,9 @@ public: HelpViewer *currentHelpViewer() const; void activateTab(bool onlyHelpViewer = false); + bool searchWidgetAttached() const { + return m_searchWidget && m_searchWidget->isAttached(); + } void createSearchWidget(QHelpSearchEngine *searchEngine); void activateSearchWidget(bool updateLastTabPage = false); void removeSearchWidget(); @@ -190,6 +194,9 @@ private: void highlightSearchTerms(); void setLastShownPages(); + void getBrowserFontFor(QWidget* viewer, QFont *font); + void setBrowserFontFor(QWidget *widget, const QFont &font); + private: int lastTabPage; QString collectionFile; -- cgit v0.12 From 10e3bb5c7b88c26cc96d08f887a4457643276d89 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 9 Nov 2009 16:21:40 +0100 Subject: Assistant: Add missing initialization of member variable. Reviewed-by: kh1 --- tools/assistant/tools/assistant/bookmarkmanager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/assistant/tools/assistant/bookmarkmanager.cpp b/tools/assistant/tools/assistant/bookmarkmanager.cpp index 9cccd82..511a56e 100644 --- a/tools/assistant/tools/assistant/bookmarkmanager.cpp +++ b/tools/assistant/tools/assistant/bookmarkmanager.cpp @@ -621,6 +621,7 @@ Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const BookmarkManager::BookmarkManager(QHelpEngineCore *_helpEngine) : treeModel(new BookmarkModel(0, 1, this)) , listModel(new BookmarkModel(0, 1, this)) + , renameItem(0) , helpEngine(_helpEngine) { folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon); -- cgit v0.12 From af0c43f19218996bab844da4dd6f298d405ebcee Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 9 Nov 2009 16:51:05 +0100 Subject: Code in gui/* should be completely namespaced And not rely on random QT_USE_NAMESPACE being pulled in from *.moc files. --- src/gui/kernel/qwidget.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 271b939..2d2aa2e 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11781,10 +11781,6 @@ void QWidget::ungrabGesture(Qt::GestureType gesture) } -QT_END_NAMESPACE - -#include "moc_qwidget.cpp" - /*! \typedef WId \relates QWidget @@ -12101,3 +12097,8 @@ void QWidgetPrivate::_q_delayedDestroy(WId winId) delete winId; } #endif + +QT_END_NAMESPACE + +#include "moc_qwidget.cpp" + -- cgit v0.12 From 19f8781c17019048693ec32833af49ce00be4c72 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Mon, 9 Nov 2009 17:52:57 +0100 Subject: Move QCustomScopedPointer to a private header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The API is internal, so it should live in its private header. The class was introduced during the lifetime of 4.6 (not in 4.5), so the move is binary compatible. Task-number: QTBUG-5617 Reviewed-by: João Abecasis --- src/corelib/io/qsettings_p.h | 1 + src/corelib/tools/qscopedpointer.h | 84 ------------ src/corelib/tools/qscopedpointer_p.h | 151 +++++++++++++++++++++ src/corelib/tools/tools.pri | 3 +- .../qscriptdebuggerconsolecommandgroupdata_p.h | 2 +- src/scripttools/debugging/qscriptdebuggervalue_p.h | 2 +- .../debugging/qscriptdebuggervalueproperty_p.h | 2 +- src/scripttools/debugging/qscriptscriptdata_p.h | 2 +- src/scripttools/debugging/qscriptvalueproperty_p.h | 2 +- 9 files changed, 159 insertions(+), 90 deletions(-) create mode 100644 src/corelib/tools/qscopedpointer_p.h diff --git a/src/corelib/io/qsettings_p.h b/src/corelib/io/qsettings_p.h index bcd8744..5ad72e4 100644 --- a/src/corelib/io/qsettings_p.h +++ b/src/corelib/io/qsettings_p.h @@ -62,6 +62,7 @@ #ifndef QT_NO_QOBJECT #include "private/qobject_p.h" #endif +#include "private/qscopedpointer_p.h" #ifdef Q_OS_WIN #include "QtCore/qt_windows.h" diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h index 7cbdb6c..2dedcc5 100644 --- a/src/corelib/tools/qscopedpointer.h +++ b/src/corelib/tools/qscopedpointer.h @@ -217,90 +217,6 @@ private: Q_DISABLE_COPY(QScopedArrayPointer) }; -/* Internal helper class - exposes the data through data_ptr (legacy from QShared). - Required for some internal Qt classes, do not use otherwise. */ -template > -class QCustomScopedPointer : public QScopedPointer -{ -public: - explicit inline QCustomScopedPointer(T *p = 0) - : QScopedPointer(p) - { - } - - inline T *&data_ptr() - { - return this->d; - } - - inline bool operator==(const QCustomScopedPointer &other) const - { - return this->d == other.d; - } - - inline bool operator!=(const QCustomScopedPointer &other) const - { - return this->d != other.d; - } - -private: - Q_DISABLE_COPY(QCustomScopedPointer) -}; - -/* Internal helper class - a handler for QShared* classes, to be used in QCustomScopedPointer */ -template -class QScopedPointerSharedDeleter -{ -public: - static inline void cleanup(T *d) - { - if (d && !d->ref.deref()) - delete d; - } -}; - -/* Internal. - This class is basically a scoped pointer pointing to a ref-counted object - */ -template -class QScopedSharedPointer : public QCustomScopedPointer > -{ -public: - explicit inline QScopedSharedPointer(T *p = 0) - : QCustomScopedPointer >(p) - { - } - - inline void detach() - { - qAtomicDetach(this->d); - } - - inline void assign(T *other) - { - if (this->d == other) - return; - if (other) - other->ref.ref(); - T *oldD = this->d; - this->d = other; - QScopedPointerSharedDeleter::cleanup(oldD); - } - - inline bool operator==(const QScopedSharedPointer &other) const - { - return this->d == other.d; - } - - inline bool operator!=(const QScopedSharedPointer &other) const - { - return this->d != other.d; - } - -private: - Q_DISABLE_COPY(QScopedSharedPointer) -}; - QT_END_NAMESPACE QT_END_HEADER diff --git a/src/corelib/tools/qscopedpointer_p.h b/src/corelib/tools/qscopedpointer_p.h new file mode 100644 index 0000000..fb627a4 --- /dev/null +++ b/src/corelib/tools/qscopedpointer_p.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of internal files. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#ifndef QSCOPEDPOINTER_P_H +#define QSCOPEDPOINTER_P_H + +#include "QtCore/qscopedpointer.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE +QT_MODULE(Core) + + +/* Internal helper class - exposes the data through data_ptr (legacy from QShared). + Required for some internal Qt classes, do not use otherwise. */ +template > +class QCustomScopedPointer : public QScopedPointer +{ +public: + explicit inline QCustomScopedPointer(T *p = 0) + : QScopedPointer(p) + { + } + + inline T *&data_ptr() + { + return this->d; + } + + inline bool operator==(const QCustomScopedPointer &other) const + { + return this->d == other.d; + } + + inline bool operator!=(const QCustomScopedPointer &other) const + { + return this->d != other.d; + } + +private: + Q_DISABLE_COPY(QCustomScopedPointer) +}; + +/* Internal helper class - a handler for QShared* classes, to be used in QCustomScopedPointer */ +template +class QScopedPointerSharedDeleter +{ +public: + static inline void cleanup(T *d) + { + if (d && !d->ref.deref()) + delete d; + } +}; + +/* Internal. + This class is basically a scoped pointer pointing to a ref-counted object + */ +template +class QScopedSharedPointer : public QCustomScopedPointer > +{ +public: + explicit inline QScopedSharedPointer(T *p = 0) + : QCustomScopedPointer >(p) + { + } + + inline void detach() + { + qAtomicDetach(this->d); + } + + inline void assign(T *other) + { + if (this->d == other) + return; + if (other) + other->ref.ref(); + T *oldD = this->d; + this->d = other; + QScopedPointerSharedDeleter::cleanup(oldD); + } + + inline bool operator==(const QScopedSharedPointer &other) const + { + return this->d == other.d; + } + + inline bool operator!=(const QScopedSharedPointer &other) const + { + return this->d != other.d; + } + +private: + Q_DISABLE_COPY(QScopedSharedPointer) +}; + + +QT_END_NAMESPACE +QT_END_HEADER + +#endif diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 007b763..3406e41 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -44,7 +44,8 @@ HEADERS += \ tools/qunicodetables_p.h \ tools/qvarlengtharray.h \ tools/qvector.h \ - tools/qscopedpointer.h + tools/qscopedpointer.h \ + tools/qscopedpointer_p.h SOURCES += \ diff --git a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h index 4a9447a..2513a8c 100644 --- a/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h +++ b/src/scripttools/debugging/qscriptdebuggerconsolecommandgroupdata_p.h @@ -54,7 +54,7 @@ // #include -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/scripttools/debugging/qscriptdebuggervalue_p.h b/src/scripttools/debugging/qscriptdebuggervalue_p.h index 2f1da1e..452f7ea 100644 --- a/src/scripttools/debugging/qscriptdebuggervalue_p.h +++ b/src/scripttools/debugging/qscriptdebuggervalue_p.h @@ -54,7 +54,7 @@ // #include -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h b/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h index 2ec6124..b130307 100644 --- a/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h +++ b/src/scripttools/debugging/qscriptdebuggervalueproperty_p.h @@ -55,7 +55,7 @@ #include #include -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/scripttools/debugging/qscriptscriptdata_p.h b/src/scripttools/debugging/qscriptscriptdata_p.h index 5006c19..f42ffa5 100644 --- a/src/scripttools/debugging/qscriptscriptdata_p.h +++ b/src/scripttools/debugging/qscriptscriptdata_p.h @@ -54,7 +54,7 @@ // #include -#include +#include #include #include diff --git a/src/scripttools/debugging/qscriptvalueproperty_p.h b/src/scripttools/debugging/qscriptvalueproperty_p.h index 61b239d..ca290a1 100644 --- a/src/scripttools/debugging/qscriptvalueproperty_p.h +++ b/src/scripttools/debugging/qscriptvalueproperty_p.h @@ -55,7 +55,7 @@ #include #include -#include +#include #include QT_BEGIN_NAMESPACE -- cgit v0.12 From 86048e1a09fce11f557d0e8b117229a754ee9098 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 10 Nov 2009 13:00:22 +0100 Subject: Designer: Use toolbar in Signal/Slot editor as in the other tool windows. Reviewed-by: Jarek Kobus Task-number: QTCREATORBUG-239 --- .../signalsloteditor/signalsloteditorwindow.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp b/tools/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp index 7ab7cb4..e36e828 100644 --- a/tools/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp +++ b/tools/designer/src/components/signalsloteditor/signalsloteditorwindow.cpp @@ -73,6 +73,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -724,20 +725,20 @@ SignalSlotEditorWindow::SignalSlotEditorWindow(QDesignerFormEditorInterface *cor QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(0); - layout->addWidget(m_view); + layout->setSpacing(0); - QHBoxLayout *layout2 = new QHBoxLayout; - layout2->setMargin(3); - layout->addLayout(layout2); - layout2->addStretch(); + QToolBar *toolBar = new QToolBar; + toolBar->setIconSize(QSize(22, 22)); + m_add_button->setIcon(createIconSet(QLatin1String("plus.png"))); + connect(m_add_button, SIGNAL(clicked()), this, SLOT(addConnection())); + toolBar->addWidget(m_add_button); m_remove_button->setIcon(createIconSet(QLatin1String("minus.png"))); connect(m_remove_button, SIGNAL(clicked()), this, SLOT(removeConnection())); - layout2->addWidget(m_remove_button); + toolBar->addWidget(m_remove_button); - m_add_button->setIcon(createIconSet(QLatin1String("plus.png"))); - connect(m_add_button, SIGNAL(clicked()), this, SLOT(addConnection())); - layout2->addWidget(m_add_button); + layout->addWidget(toolBar); + layout->addWidget(m_view); connect(core->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)), -- cgit v0.12