diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-10 13:36:53 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-11-10 13:36:53 (GMT) |
commit | 7b15c669c336a1d76e3ac001fadde38a294e3e80 (patch) | |
tree | 2b8e9631019d1bc9af37d9a93bb93ce0eb16381a /tools | |
parent | 47bc34f413d9a0c6efac6ca3eead95eed7da2e40 (diff) | |
parent | 86048e1a09fce11f557d0e8b117229a754ee9098 (diff) | |
download | Qt-7b15c669c336a1d76e3ac001fadde38a294e3e80.zip Qt-7b15c669c336a1d76e3ac001fadde38a294e3e80.tar.gz Qt-7b15c669c336a1d76e3ac001fadde38a294e3e80.tar.bz2 |
Merge branch 'tools-team/4.6' (early part) into 4.6
Conflicts:
src/corelib/tools/qscopedpointer.h
Diffstat (limited to 'tools')
19 files changed, 323 insertions, 275 deletions
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); 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<QFont>(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<QWebView*> (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<QFont>(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<QWebView*> (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<int, QString> 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<QWebView*> (viewer); + if (view) { + QWebSettings *settings = QWebSettings::globalSettings(); + *font = QFont(settings->fontFamily(QWebSettings::StandardFont), + settings->fontSize(QWebSettings::DefaultFontSize)); + } +#endif + } else { + *font = qVariantValue<QFont>(helpEngine->customValue( + QLatin1String("browserFont"))); + } +} + +void CentralWidget::setBrowserFontFor(QWidget *widget, const QFont &font) +{ +#if !defined(QT_NO_WEBKIT) + QWebView *view = qobject_cast<QWebView*> (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 <QtGui/QWidget> +#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; 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")) 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; 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 <QtGui/QVBoxLayout> #include <QtGui/QToolButton> #include <QtGui/QButtonGroup> +#include <QtGui/QToolBar> 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*)), 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..024fd91 100644 --- a/tools/linguist/linguist/messagemodel.cpp +++ b/tools/linguist/linguist/messagemodel.cpp @@ -209,20 +209,29 @@ 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.byId.isEmpty() || !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 i, dupes.byId) { + if (++numdups >= 5) { + err += tr("<p>[more duplicates omitted]"); + goto doWarn; + } + err += tr("<p>* ID: %1").arg(Qt::escape(tor.message(i).id())); + } + 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())); } + doWarn: 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/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<QString> &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 b5f77cd..fa0dd3d 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; } } @@ -345,15 +341,17 @@ 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()) m.setComment(mv.comment()); } else { - TranslatorMessage mv = virginTor.find(m.context(), m.sourceText(), m.comment()); - if (mv.isNull()) { + TranslatorMessage mv; + int mvi = virginTor.find(m); + if (mvi < 0) { if (!(options & HeuristicSimilarText)) { + makeObsolete: newType = TranslatorMessage::Obsolete; if (m.type() != TranslatorMessage::Obsolete) obsoleted++; @@ -362,10 +360,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. @@ -380,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")); @@ -387,38 +383,45 @@ 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; } } } } else { - switch (m.type()) { - case TranslatorMessage::Finished: - default: - if (m.isPlural() == mv.isPlural()) { - newType = TranslatorMessage::Finished; - } else { - newType = TranslatorMessage::Unfinished; - } + mv = virginTor.message(mvi); + 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 @@ -426,10 +429,12 @@ Translator merge(const Translator &tor, const Translator &virginTor, // This should also enable us to read a file that does not // have the <location> element. // why not use operator=()? Because it overwrites e.g. userData. + copyAttribs: m.setReferences(mv.allReferences()); m.setPlural(mv.isPlural()); m.setUtf8(mv.isUtf8()); m.setExtraComment(mv.extraComment()); + m.setId(mv.id()); } } @@ -442,11 +447,11 @@ 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 { - if (tor.contains(mv.context(), mv.sourceText(), mv.comment())) + if (tor.find(mv) >= 0) continue; if (options & HeuristicSimilarText) { TranslatorMessage m = tor.find(mv.context(), mv.comment(), mv.allReferences()); @@ -460,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/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); } 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 cd670cc..bc27daf 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -80,18 +80,9 @@ QList<Translator::FileFormat> &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); + int index = find(msg); if (index == -1) appendSorted(msg); else @@ -100,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 { @@ -145,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) { @@ -311,19 +302,21 @@ 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 &sourceText, const QString &comment) const +int Translator::find(const TranslatorMessage &msg) const { - TranslatorMessage needle(context, sourceText, comment, QString(), QString(), 0); - int index = m_messages.indexOf(needle); - return index == -1 ? TranslatorMessage() : m_messages.at(index); + for (int i = 0; i < m_messages.count(); ++i) { + const TranslatorMessage &tmsg = m_messages.at(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; } TranslatorMessage Translator::find(const QString &context, @@ -344,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; } @@ -352,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(); } @@ -435,49 +428,143 @@ void Translator::dropUiLines() } } -QSet<TranslatorMessagePtr> Translator::resolveDuplicates() +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; + } + + inline const TranslatorMessage *operator->() const + { + return ptr; + } + + const TranslatorMessage *ptr; +}; + +Q_DECLARE_TYPEINFO(TranslatorMessageContentPtr, Q_MOVABLE_TYPE); + +inline int qHash(TranslatorMessageContentPtr tmp) +{ + 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==(TranslatorMessageContentPtr tmp1, TranslatorMessageContentPtr tmp2) +{ + if (tmp1->context() != tmp2->context() || tmp1->sourceText() != tmp2->sourceText()) + return false; + // Special treatment for context comments (empty source). + if (tmp1->sourceText().isEmpty()) + return true; + return tmp1->comment() == tmp2->comment(); +} + +Translator::Duplicates Translator::resolveDuplicates() { - QSet<TranslatorMessagePtr> dups; - QHash<TranslatorMessagePtr, int> refs; + Duplicates dups; + QHash<TranslatorMessageIdPtr, int> idRefs; + QHash<TranslatorMessageContentPtr, int> contentRefs; for (int i = 0; i < m_messages.count();) { const TranslatorMessage &msg = m_messages.at(i); - QHash<TranslatorMessagePtr, int>::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.insert(omsg); + TranslatorMessage *omsg; + int oi; + QSet<int> *pDup; + if (!msg.id().isEmpty()) { + QHash<TranslatorMessageIdPtr, int>::ConstIterator it = + idRefs.constFind(TranslatorMessageIdPtr(msg)); + if (it != idRefs.constEnd()) { + oi = *it; + omsg = &m_messages[oi]; + pDup = &dups.byId; + goto gotDupe; } - if (!omsg.isTranslated() && msg.isTranslated()) - omsg.setTranslations(msg.translations()); - m_messages.removeAt(i); + } + { + QHash<TranslatorMessageContentPtr, int>::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 (!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; } -void Translator::reportDuplicates(const QSet<TranslatorMessagePtr> &dupes, +void Translator::reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose) { - if (!dupes.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 (const TranslatorMessagePtr &msg, dupes) { + 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", - 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 ef81d2a..eec704a 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -113,18 +113,13 @@ 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 &sourceText, const QString &comment) const; - + int find(const TranslatorMessage &msg) const; TranslatorMessage find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const; 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); @@ -138,9 +133,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> byId, 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.cpp b/tools/linguist/shared/translatormessage.cpp index db6f333..5151ebd 100644 --- a/tools/linguist/shared/translatormessage.cpp +++ b/tools/linguist/shared/translatormessage.cpp @@ -143,40 +143,6 @@ 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); -} - - -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 - qHash(msg.context()) ^ - qHash(msg.sourceText()) ^ - qHash(msg.extra(QLatin1String("po-msgid_plural"))) ^ - 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 675bba7..60b60c5 100644 --- a/tools/linguist/shared/translatormessage.h +++ b/tools/linguist/shared/translatormessage.h @@ -109,9 +109,6 @@ public: return false; } - 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; } int lineNumber() const { return m_lineNumber; } @@ -177,34 +174,6 @@ private: 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 |