From 41f57bd5eba433676b52d4f8dfebe5e671ba48e5 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 3 Jun 2010 11:57:26 +0200 Subject: Ensure that we only have one QLayoutStruct struct by renaming the other Since QTextDocumentLayout and QLayoutEngine code referred to their own instances of QLayoutStruct it was causing problems with the Visual Studio debugger as it kept confusing the two together. Reviewed-by: Eskil --- src/gui/text/qtextdocumentlayout.cpp | 58 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index f12bf0b2f5..eeb66cea8b 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -79,7 +79,7 @@ Q_GUI_EXPORT extern int qt_defaultDpi(); // ################ should probably add frameFormatChange notification! -struct QLayoutStruct; +struct QTextLayoutStruct; class QTextFrameData : public QTextFrameLayoutData { @@ -109,7 +109,7 @@ public: QFixed minimumWidth; QFixed maximumWidth; - QLayoutStruct *currentLayoutStruct; + QTextLayoutStruct *currentLayoutStruct; bool sizeDirty; bool layoutDirty; @@ -123,8 +123,8 @@ QTextFrameData::QTextFrameData() { } -struct QLayoutStruct { - QLayoutStruct() : maximumWidth(QFIXED_MAX), fullLayout(false) +struct QTextLayoutStruct { + QTextLayoutStruct() : maximumWidth(QFIXED_MAX), fullLayout(false) {} QTextFrame *frame; QFixed x_left; @@ -477,9 +477,9 @@ public: HitPoint hitTest(QTextTable *table, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; HitPoint hitTest(QTextBlock bl, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; - QLayoutStruct layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, - int layoutFrom, int layoutTo, QTextTableData *tableData, QFixed absoluteTableY, - bool withPageBreaks); + QTextLayoutStruct layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, + int layoutFrom, int layoutTo, QTextTableData *tableData, QFixed absoluteTableY, + bool withPageBreaks); void setCellPosition(QTextTable *t, const QTextTableCell &cell, const QPointF &pos); QRectF layoutTable(QTextTable *t, int layoutFrom, int layoutTo, QFixed parentY); @@ -490,13 +490,13 @@ public: QRectF layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed frameWidth, QFixed frameHeight, QFixed parentY = 0); void layoutBlock(const QTextBlock &bl, int blockPosition, const QTextBlockFormat &blockFormat, - QLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat); - void layoutFlow(QTextFrame::Iterator it, QLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width = 0); - void pageBreakInsideTable(QTextTable *table, QLayoutStruct *layoutStruct); + QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat); + void layoutFlow(QTextFrame::Iterator it, QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width = 0); + void pageBreakInsideTable(QTextTable *table, QTextLayoutStruct *layoutStruct); - void floatMargins(const QFixed &y, const QLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const; - QFixed findY(QFixed yFrom, const QLayoutStruct *layoutStruct, QFixed requiredWidth) const; + void floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const; + QFixed findY(QFixed yFrom, const QTextLayoutStruct *layoutStruct, QFixed requiredWidth) const; QVector checkPoints; @@ -1487,12 +1487,12 @@ static QFixed firstChildPos(const QTextFrame *f) return flowPosition(f->begin()); } -QLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, - int layoutFrom, int layoutTo, QTextTableData *td, - QFixed absoluteTableY, bool withPageBreaks) +QTextLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, + int layoutFrom, int layoutTo, QTextTableData *td, + QFixed absoluteTableY, bool withPageBreaks) { LDEBUG << "layoutCell"; - QLayoutStruct layoutStruct; + QTextLayoutStruct layoutStruct; layoutStruct.frame = t; layoutStruct.minimumWidth = 0; layoutStruct.maximumWidth = QFIXED_MAX; @@ -1641,9 +1641,9 @@ recalc_minmax_widths: // to figure out the min and the max width lay out the cell at // maximum width. otherwise the maxwidth calculation sometimes // returns wrong values - QLayoutStruct layoutStruct = layoutCell(table, cell, QFIXED_MAX, layoutFrom, - layoutTo, td, absoluteTableY, - /*withPageBreaks =*/false); + QTextLayoutStruct layoutStruct = layoutCell(table, cell, QFIXED_MAX, layoutFrom, + layoutTo, td, absoluteTableY, + /*withPageBreaks =*/false); // distribute the minimum width over all columns the cell spans QFixed widthToDistribute = layoutStruct.minimumWidth + widthPadding; @@ -1868,10 +1868,10 @@ relayout: ++rowCellCount; const QFixed width = td->cellWidth(c, cspan) - widthPadding; - QLayoutStruct layoutStruct = layoutCell(table, cell, width, - layoutFrom, layoutTo, - td, absoluteTableY, - /*withPageBreaks =*/true); + QTextLayoutStruct layoutStruct = layoutCell(table, cell, width, + layoutFrom, layoutTo, + td, absoluteTableY, + /*withPageBreaks =*/true); const QFixed height = layoutStruct.y + bottomPadding + topPadding; @@ -1976,7 +1976,7 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur QTextFrameData *pd = data(parent); Q_ASSERT(pd && pd->currentLayoutStruct); - QLayoutStruct *layoutStruct = pd->currentLayoutStruct; + QTextLayoutStruct *layoutStruct = pd->currentLayoutStruct; if (!pd->floats.contains(frame)) pd->floats.append(frame); @@ -2116,7 +2116,7 @@ QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, in // function. fd->contentsWidth = newContentsWidth; - QLayoutStruct layoutStruct; + QTextLayoutStruct layoutStruct; layoutStruct.frame = f; layoutStruct.x_left = fd->leftMargin + fd->border + fd->padding; layoutStruct.x_right = layoutStruct.x_left + newContentsWidth; @@ -2179,7 +2179,7 @@ QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, in return layoutStruct.updateRect; } -void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QLayoutStruct *layoutStruct, +void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width) { LDEBUG << "layoutFlow from=" << layoutFrom << "to=" << layoutTo; @@ -2509,7 +2509,7 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QLayoutStru } void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosition, const QTextBlockFormat &blockFormat, - QLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat) + QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat) { Q_Q(QTextDocumentLayout); @@ -2718,7 +2718,7 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi } } -void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QLayoutStruct *layoutStruct, +void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const { // qDebug() << "floatMargins y=" << y; @@ -2740,7 +2740,7 @@ void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QLayoutStru // qDebug() << "floatMargins: left="<<*left<<"right="<<*right<<"y="<x_right - layoutStruct->x_left); -- cgit v1.2.3 From 29e294aee281b7a4dcdd1277eef0fe1552015536 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Thu, 3 Jun 2010 17:50:06 +0200 Subject: Styled item view backgrounds in Gtk+ These were currently never themed but used a fake gradient to mimick ClearLooks. I had to add a workaround for the case where you were using custom QItemDelegates since this could result in styled background on tree branches but flat items. Task-number: QTBUG-11209 Reviewed-by: thorbjorn --- src/gui/styles/qgtkstyle.cpp | 56 ++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index 5465c7b5e8..b59a03361e 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #undef signals // Collides with GTK stymbols #include @@ -817,24 +818,49 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, option->state & State_Open ? openState : closedState , gtkTreeView->style); } break; + + case PE_PanelItemViewRow: + // This primitive is only used to draw selection behind selected expander arrows. + // We try not to decorate the tree branch background unless you inherit from StyledItemDelegate + // The reason for this is that a lot of code that relies on custom item delegates will look odd having + // a gradient on the branch but a flat shaded color on the item itself. + QCommonStyle::drawPrimitive(element, option, painter, widget); + if (!option->state & State_Selected) { + break; + } else { + if (const QAbstractItemView *view = qobject_cast(widget)) { + if (!qobject_cast(view->itemDelegate())) + break; + } + } // fall through + case PE_PanelItemViewItem: if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast(option)) { - if (vopt->state & State_Selected) { - QLinearGradient gradient; - gradient.setStart(option->rect.left(), option->rect.top()); - gradient.setFinalStop(option->rect.left(), option->rect.bottom()); - gradient.setColorAt(0, option->palette.highlight().color().lighter(105)); - gradient.setColorAt(0.5, option->palette.highlight().color().lighter(101)); - gradient.setColorAt(0.51, option->palette.highlight().color().darker(101)); - gradient.setColorAt(1, option->palette.highlight().color().darker(105)); - painter->fillRect(option->rect, gradient); - } else { - if (vopt->backgroundBrush.style() != Qt::NoBrush) { - QPointF oldBO = painter->brushOrigin(); - painter->setBrushOrigin(vopt->rect.topLeft()); - painter->fillRect(vopt->rect, vopt->backgroundBrush); - painter->setBrushOrigin(oldBO); + if (vopt->backgroundBrush.style() != Qt::NoBrush) { + QPointF oldBO = painter->brushOrigin(); + painter->setBrushOrigin(vopt->rect.topLeft()); + painter->fillRect(vopt->rect, vopt->backgroundBrush); + painter->setBrushOrigin(oldBO); + if (!(option->state & State_Selected)) + break; + } + if (GtkWidget *gtkTreeView = d->gtkWidget("GtkTreeView")) { + const char *detail = "cell_even_ruled"; + if (vopt && vopt->features & QStyleOptionViewItemV2::Alternate) + detail = "cell_odd_ruled"; + bool isActive = option->state & State_Active; + QString key; + if (isActive ) { + // Required for active/non-active window appearance + key = QLS("a"); + GTK_WIDGET_SET_FLAGS(gtkTreeView, GTK_HAS_FOCUS); } + gtkPainter.paintFlatBox(gtkTreeView, detail, option->rect, + option->state & State_Selected ? GTK_STATE_SELECTED : + option->state & State_Enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE, + GTK_SHADOW_OUT, gtkTreeView->style, key); + if (isActive ) + GTK_WIDGET_UNSET_FLAGS(gtkTreeView, GTK_HAS_FOCUS); } } break; -- cgit v1.2.3 From 482159bddec1736a8854dc2db1b75cf856d00255 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 3 Jun 2010 18:03:52 +0200 Subject: don't use qWarning() - or even qFatal()! - gratuitously. Task-number: QTBUG-8044 --- .../testdata/good/lacksqobject/expectedoutput.txt | 4 - .../testdata/good/parsecpp2/expectedoutput.txt | 4 - tools/linguist/lconvert/main.cpp | 8 +- tools/linguist/lrelease/main.cpp | 23 ++-- tools/linguist/lupdate/cpp.cpp | 124 ++++++++++----------- tools/linguist/lupdate/java.cpp | 40 ++++--- tools/linguist/lupdate/main.cpp | 90 +++++++-------- tools/linguist/lupdate/qscript.cpp | 22 ++-- tools/linguist/lupdate/qscript.g | 22 ++-- tools/linguist/shared/profileevaluator.cpp | 6 +- tools/linguist/shared/translator.cpp | 21 ++-- 11 files changed, 178 insertions(+), 186 deletions(-) diff --git a/tests/auto/linguist/lupdate/testdata/good/lacksqobject/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/lacksqobject/expectedoutput.txt index 72ec3c598c..f6fc400360 100644 --- a/tests/auto/linguist/lupdate/testdata/good/lacksqobject/expectedoutput.txt +++ b/tests/auto/linguist/lupdate/testdata/good/lacksqobject/expectedoutput.txt @@ -1,8 +1,4 @@ .*/lupdate/testdata/good/lacksqobject/main.cpp:58: Class 'B' lacks Q_OBJECT macro - .*/lupdate/testdata/good/lacksqobject/main.cpp:65: Class 'C' lacks Q_OBJECT macro - .*/lupdate/testdata/good/lacksqobject/main.cpp:78: Class 'nsB::B' lacks Q_OBJECT macro - .*/lupdate/testdata/good/lacksqobject/main.cpp:84: Class 'nsB::C' lacks Q_OBJECT macro - diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/expectedoutput.txt index e3543c958d..195c0e65c5 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2/expectedoutput.txt +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp2/expectedoutput.txt @@ -1,8 +1,4 @@ .*/lupdate/testdata/good/parsecpp2/main.cpp:51: Excess closing brace .* - .*/lupdate/testdata/good/parsecpp2/main.cpp:55: Excess closing brace .* - .*/lupdate/testdata/good/parsecpp2/main.cpp:61: Excess closing brace .* - .*/lupdate/testdata/good/parsecpp2/main.cpp:65: Excess closing brace .* - diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp index 543c405f6f..049ea43856 100644 --- a/tools/linguist/lconvert/main.cpp +++ b/tools/linguist/lconvert/main.cpp @@ -240,7 +240,7 @@ int main(int argc, char *argv[]) tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name)); if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) { - qWarning() << qPrintable(cd.error()); + std::cerr << qPrintable(cd.error()) << std::endl; return 2; } tr.reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose); @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) for (int i = 1; i < inFiles.size(); ++i) { Translator tr2; if (!tr2.load(inFiles[i].name, cd, inFiles[i].format)) { - qWarning() << qPrintable(cd.error()); + std::cerr << qPrintable(cd.error()) << std::endl; return 2; } tr2.reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose); @@ -273,11 +273,11 @@ int main(int argc, char *argv[]) tr.normalizeTranslations(cd); if (!cd.errors().isEmpty()) { - qWarning("%s", qPrintable(cd.error())); + std::cerr << qPrintable(cd.error()) << std::endl; cd.clearErrors(); } if (!tr.save(outFileName, cd, outFormat)) { - qWarning("%s", qPrintable(cd.error())); + std::cerr << qPrintable(cd.error()) << std::endl; return 3; } return 0; diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp index 266474e22a..df0b430aae 100644 --- a/tools/linguist/lrelease/main.cpp +++ b/tools/linguist/lrelease/main.cpp @@ -55,6 +55,8 @@ #include #include +#include + QT_USE_NAMESPACE #ifdef QT_BOOTSTRAPPED @@ -106,7 +108,7 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo ConversionData cd; bool ok = tor.load(tsFileName, cd, QLatin1String("auto")); if (!ok) { - qWarning("lrelease error: %s\n", qPrintable(cd.error())); + std::cerr << "lrelease error: " << qPrintable(cd.error()) << std::endl; } else { if (!cd.errors().isEmpty()) printOut(cd.error()); @@ -130,8 +132,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName, QFile file(qmFileName); if (!file.open(QIODevice::WriteOnly)) { - qWarning("lrelease error: cannot create '%s': %s\n", - qPrintable(qmFileName), qPrintable(file.errorString())); + std::cerr << "lrelease error: cannot create '" << qPrintable(qmFileName) + << "': " << qPrintable(file.errorString()) << std::endl; return false; } @@ -140,8 +142,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName, file.close(); if (!ok) { - qWarning("lrelease error: cannot save '%s': %s\n", - qPrintable(qmFileName), qPrintable(cd.error())); + std::cerr << "lrelease error: cannot save '" << qPrintable(qmFileName) + << "': " << qPrintable(cd.error()) << std::endl; } else if (!cd.errors().isEmpty()) { printOut(cd.error()); } @@ -253,19 +255,20 @@ int main(int argc, char **argv) visitor.setVerbose(cd.isVerbose()); if (!visitor.queryProFile(&pro)) { - qWarning("lrelease error: cannot read project file '%s'.", qPrintable(inputFile)); + std::cerr << "lrelease error: cannot read project file '" + << qPrintable(inputFile) << "'.\n"; continue; } if (!visitor.accept(&pro)) { - qWarning("lrelease error: cannot process project file '%s'.", qPrintable(inputFile)); + std::cerr << "lrelease error: cannot process project file '" + << qPrintable(inputFile) << "'.\n"; continue; } QStringList translations = visitor.values(QLatin1String("TRANSLATIONS")); if (translations.isEmpty()) { - qWarning("lrelease warning: Met no 'TRANSLATIONS' entry in" - " project file '%s'\n", - qPrintable(inputFile)); + std::cerr << "lrelease warning: Met no 'TRANSLATIONS' entry in project file '" + << qPrintable(inputFile) << "'\n"; } else { QDir proDir(fi.absolutePath()); foreach (const QString &trans, translations) diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index db4bbcac2e..b3e7e84f80 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include // for isXXX() QT_BEGIN_NAMESPACE @@ -226,6 +228,8 @@ private: int elseLine; }; + std::ostream &yyMsg(int line = 0); + uint getChar(); uint getToken(); bool getMacroArgs(); @@ -352,6 +356,12 @@ CppParser::CppParser(ParseResults *_results) inDefine = false; } + +std::ostream &CppParser::yyMsg(int line) +{ + return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": "; +} + void CppParser::setInput(const QString &in) { yyInStr = in; @@ -613,9 +623,9 @@ uint CppParser::getToken() if (yyBracketDepth != is.bracketDepth1st || yyBraceDepth != is.braceDepth1st || yyParenDepth != is.parenDepth1st) - qWarning("%s:%d: Parenthesis/bracket/brace mismatch between " - "#if and #else branches; using #if branch\n", - qPrintable(yyFileName), is.elseLine); + yyMsg(is.elseLine) + << "Parenthesis/bracket/brace mismatch between " + "#if and #else branches; using #if branch\n"; } else { is.bracketDepth1st = yyBracketDepth; is.braceDepth1st = yyBraceDepth; @@ -636,9 +646,9 @@ uint CppParser::getToken() if (yyBracketDepth != is.bracketDepth1st || yyBraceDepth != is.braceDepth1st || yyParenDepth != is.parenDepth1st) - qWarning("%s:%d: Parenthesis/brace mismatch between " - "#if and #else branches; using #if branch\n", - qPrintable(yyFileName), is.elseLine); + yyMsg(is.elseLine) + << "Parenthesis/brace mismatch between " + "#if and #else branches; using #if branch\n"; yyBracketDepth = is.bracketDepth1st; yyBraceDepth = is.braceDepth1st; yyParenDepth = is.parenDepth1st; @@ -664,8 +674,7 @@ uint CppParser::getToken() forever { yyCh = getChar(); if (yyCh == EOF) { - qWarning("%s:%d: Unterminated C++ comment\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Unterminated C++ comment\n"; break; } @@ -795,8 +804,7 @@ uint CppParser::getToken() forever { yyCh = getChar(); if (yyCh == EOF) { - qWarning("%s:%d: Unterminated C++ comment\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Unterminated C++ comment\n"; break; } *ptr++ = yyCh; @@ -829,8 +837,7 @@ uint CppParser::getToken() yyWord.resize(ptr - (ushort *)yyWord.unicode()); if (yyCh != '"') - qWarning("%s:%d: Unterminated C++ string\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Unterminated C++ string\n"; else yyCh = getChar(); return Tok_String; @@ -867,8 +874,7 @@ uint CppParser::getToken() forever { if (yyCh == EOF || yyCh == '\n') { - qWarning("%s:%d: Unterminated C++ character\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Unterminated C++ character\n"; break; } yyCh = getChar(); @@ -887,9 +893,9 @@ uint CppParser::getToken() case '}': if (yyBraceDepth == yyMinBraceDepth) { if (!inDefine) - qWarning("%s:%d: Excess closing brace in C++ code" - " (or abuse of the C++ preprocessor)\n", - qPrintable(yyFileName), yyCurLineNo); + yyMsg(yyCurLineNo) + << "Excess closing brace in C++ code" + " (or abuse of the C++ preprocessor)\n"; // Avoid things getting messed up even more yyCh = getChar(); return Tok_Semicolon; @@ -905,9 +911,9 @@ uint CppParser::getToken() return Tok_LeftParen; case ')': if (yyParenDepth == 0) - qWarning("%s:%d: Excess closing parenthesis in C++ code" - " (or abuse of the C++ preprocessor)\n", - qPrintable(yyFileName), yyCurLineNo); + yyMsg(yyCurLineNo) + << "Excess closing parenthesis in C++ code" + " (or abuse of the C++ preprocessor)\n"; else yyParenDepth--; yyCh = getChar(); @@ -920,9 +926,9 @@ uint CppParser::getToken() return Tok_LeftBracket; case ']': if (yyBracketDepth == 0) - qWarning("%s:%d: Excess closing bracket in C++ code" - " (or abuse of the C++ preprocessor)\n", - qPrintable(yyFileName), yyCurLineNo); + yyMsg(yyCurLineNo) + << "Excess closing bracket in C++ code" + " (or abuse of the C++ preprocessor)\n"; else yyBracketDepth--; yyCh = getChar(); @@ -1290,8 +1296,7 @@ void CppParser::processInclude(const QString &file, ConversionData &cd, QString cleanFile = QDir::cleanPath(file); if (inclusions.contains(cleanFile)) { - qWarning("%s:%d: circular inclusion of %s\n", - qPrintable(yyFileName), yyLineNo, qPrintable(cleanFile)); + yyMsg() << "circular inclusion of " << qPrintable(cleanFile) << std::endl; return; } @@ -1315,9 +1320,9 @@ void CppParser::processInclude(const QString &file, ConversionData &cd, QFile f(cleanFile); if (!f.open(QIODevice::ReadOnly)) { - qWarning("%s:%d: Cannot open %s: %s\n", - qPrintable(yyFileName), yyLineNo, - qPrintable(cleanFile), qPrintable(f.errorString())); + yyMsg() + << "Cannot open " << qPrintable(cleanFile) << ": " + << qPrintable(f.errorString()) << std::endl; return; } @@ -1656,8 +1661,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) // Forward-declared class definitions can be namespaced. NamespaceList nsl; if (!fullyQualify(namespaces, quali, true, &nsl, 0)) { - qWarning("%s:%d: Ignoring definition of undeclared qualified class\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Ignoring definition of undeclared qualified class\n"; break; } namespaceDepths.push(namespaces.count()); @@ -1757,8 +1761,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) if (!tor) goto case_default; if (!sourcetext.isEmpty()) - qWarning("%s:%d: //%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "//%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n"; utf8 = (yyTok == Tok_trUtf8); line = yyLineNo; yyTok = getToken(); @@ -1779,10 +1782,9 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) QStringList unresolved; if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) { functionContextUnresolved = unresolved.join(strColons); - qWarning("%s:%d: Qualifying with unknown namespace/class %s::%s\n", - qPrintable(yyFileName), yyLineNo, - qPrintable(stringifyNamespace(functionContext)), - qPrintable(unresolved.first())); + yyMsg() << "Qualifying with unknown namespace/class " + << qPrintable(stringifyNamespace(functionContext)) << "::" + << qPrintable(unresolved.first()) << std::endl; } pendingContext.clear(); } @@ -1790,8 +1792,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) if (functionContextUnresolved.isEmpty()) { int idx = functionContext.length(); if (idx < 2) { - qWarning("%s:%d: tr() cannot be called without context\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "tr() cannot be called without context\n"; break; } Namespace *fctx; @@ -1800,9 +1801,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) context = stringifyNamespace(functionContext); fctx = findNamespace(functionContext)->classDef; if (!fctx->complained) { - qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n", - qPrintable(yyFileName), yyLineNo, - qPrintable(context)); + yyMsg() << "Class '" << qPrintable(context) + << "' lacks Q_OBJECT macro\n"; fctx->complained = true; } goto gotctx; @@ -1830,9 +1830,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) int last = prefix.lastIndexOf(strColons); QString className = prefix.mid(last == -1 ? 0 : last + 2); if (!className.isEmpty() && className == functionName) { - qWarning("%s::%d: It is not recommended to call tr() from within a constructor '%s::%s' ", - qPrintable(yyFileName), yyLineNo, - className.constData(), functionName.constData()); + yyMsg() << "It is not recommended to call tr() from within a constructor '" + << qPrintable(className) << "::" << qPrintable(functionName) << "'\n"; } #endif prefix.chop(2); @@ -1847,9 +1846,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) context = fctx->trQualification; } if (!fctx->hasTrFunctions && !fctx->complained) { - qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n", - qPrintable(yyFileName), yyLineNo, - qPrintable(context)); + yyMsg() << "Class '" << qPrintable(context) << "' lacks Q_OBJECT macro\n"; fctx->complained = true; } } else { @@ -1870,8 +1867,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) if (!tor) goto case_default; if (!sourcetext.isEmpty()) - qWarning("%s:%d: //%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "//%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n"; utf8 = (yyTok == Tok_translateUtf8); line = yyLineNo; yyTok = getToken(); @@ -1925,8 +1921,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) if (!tor) goto case_default; if (!msgid.isEmpty()) - qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n"; //utf8 = false; // Maybe use //%% or something like that line = yyLineNo; yyTok = getToken(); @@ -1993,15 +1988,13 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) if (isspace(c)) continue; if (c != '"') { - qWarning("%s:%d: Unexpected character in meta string\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Unexpected character in meta string\n"; break; } forever { if (p >= yyWord.length()) { whoops: - qWarning("%s:%d: Unterminated meta string\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Unterminated meta string\n"; break; } c = yyWord.unicode()[p++].unicode(); @@ -2054,8 +2047,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) case Tok_Arrow: yyTok = getToken(); if (yyTok == Tok_tr || yyTok == Tok_trUtf8) - qWarning("%s:%d: Cannot invoke tr() like this\n", - qPrintable(yyFileName), yyLineNo); + yyMsg() << "Cannot invoke tr() like this\n"; break; case Tok_ColonColon: if (yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0 && !yyTokColonSeen) @@ -2123,17 +2115,17 @@ void CppParser::parseInternal(ConversionData &cd, QSet &inclusions) } if (yyBraceDepth != 0) - qWarning("%s:%d: Unbalanced opening brace in C++ code" - " (or abuse of the C++ preprocessor)\n", - qPrintable(yyFileName), yyBraceLineNo); + yyMsg(yyBraceLineNo) + << "Unbalanced opening brace in C++ code" + " (or abuse of the C++ preprocessor)\n"; else if (yyParenDepth != 0) - qWarning("%s:%d: Unbalanced opening parenthesis in C++ code" - " (or abuse of the C++ preprocessor)\n", - qPrintable(yyFileName), yyParenLineNo); + yyMsg(yyParenLineNo) + << "Unbalanced opening parenthesis in C++ code" + " (or abuse of the C++ preprocessor)\n"; else if (yyBracketDepth != 0) - qWarning("%s:%d: Unbalanced opening bracket in C++ code" - " (or abuse of the C++ preprocessor)\n", - qPrintable(yyFileName), yyBracketLineNo); + yyMsg(yyBracketLineNo) + << "Unbalanced opening bracket in C++ code" + " (or abuse of the C++ preprocessor)\n"; } const ParseResults *CppParser::recordResults(bool isHeader) diff --git a/tools/linguist/lupdate/java.cpp b/tools/linguist/lupdate/java.cpp index 27988b0458..dc66e2b365 100644 --- a/tools/linguist/lupdate/java.cpp +++ b/tools/linguist/lupdate/java.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include QT_BEGIN_NAMESPACE @@ -107,6 +109,11 @@ static QString yyPackage; static QStack yyScope; static QString yyDefaultContext; +std::ostream &yyMsg(int line = 0) +{ + return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": "; +} + static QChar getChar() { if (yyInPos >= yyInStr.size()) @@ -189,10 +196,7 @@ static int getToken() while ( !metAsterSlash ) { yyCh = getChar(); if ( yyCh == EOF ) { - qFatal( "%s: Unterminated Java comment starting at" - " line %d\n", - qPrintable(yyFileName), yyLineNo ); - + yyMsg() << "Unterminated Java comment.\n"; return Tok_Comment; } @@ -228,8 +232,8 @@ static int getToken() else { int sub(yyCh.toLower().toAscii() - 87); if( sub > 15 || sub < 10) { - qFatal( "%s:%d: Invalid Unicode", - qPrintable(yyFileName), yyLineNo ); + yyMsg() << "Invalid Unicode value.\n"; + break; } unicode += sub; } @@ -251,8 +255,7 @@ static int getToken() } if ( yyCh != QLatin1Char('"') ) - qFatal( "%s:%d: Unterminated string", - qPrintable(yyFileName), yyLineNo ); + yyMsg() << "Unterminated string.\n"; yyCh = getChar(); @@ -365,9 +368,8 @@ static bool matchString( QString &s ) if (yyTok == Tok_String) s += yyString; else { - qWarning( "%s:%d: String used in translation can only contain strings" - " concatenated with other strings, not expressions or numbers.", - qPrintable(yyFileName), yyLineNo ); + yyMsg() << "String used in translation can contain only literals" + " concatenated with other literals, not expressions or numbers.\n"; return false; } yyTok = getToken(); @@ -475,8 +477,8 @@ static void parse( Translator *tor ) yyScope.push(new Scope(yyIdent, Scope::Clazz, yyLineNo)); } else { - qFatal( "%s:%d: Class must be followed by a classname", - qPrintable(yyFileName), yyLineNo ); + yyMsg() << "'class' must be followed by a class name.\n"; + break; } while (!match(Tok_LeftBrace)) { yyTok = getToken(); @@ -547,8 +549,7 @@ static void parse( Translator *tor ) case Tok_RightBrace: if ( yyScope.isEmpty() ) { - qFatal( "%s:%d: Unbalanced right brace in Java code\n", - qPrintable(yyFileName), yyLineNo ); + yyMsg() << "Excess closing brace.\n"; } else delete (yyScope.pop()); @@ -577,8 +578,7 @@ static void parse( Translator *tor ) yyPackage.append(QLatin1String(".")); break; default: - qFatal( "%s:%d: Package keyword should be followed by com.package.name;", - qPrintable(yyFileName), yyLineNo ); + yyMsg() << "'package' must be followed by package name.\n"; break; } yyTok = getToken(); @@ -591,11 +591,9 @@ static void parse( Translator *tor ) } if ( !yyScope.isEmpty() ) - qFatal( "%s:%d: Unbalanced braces in Java code\n", - qPrintable(yyFileName), yyScope.top()->line ); + yyMsg(yyScope.top()->line) << "Unbalanced opening brace.\n"; else if ( yyParenDepth != 0 ) - qFatal( "%s:%d: Unbalanced parentheses in Java code\n", - qPrintable(yyFileName), yyParenLineNo ); + yyMsg(yyParenLineNo) << "Unbalanced opening parenthesis.\n"; } diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp index 6c9157a3ec..1715b794a0 100644 --- a/tools/linguist/lupdate/main.cpp +++ b/tools/linguist/lupdate/main.cpp @@ -57,16 +57,15 @@ static QString m_defaultExtensions; -static void printErr(const QString & out) -{ - qWarning("%s", qPrintable(out)); -} - static void printOut(const QString & out) { std::cerr << qPrintable(out); } +class LU { + Q_DECLARE_TR_FUNCTIONS(LUpdate); +}; + static void recursiveFileInfoList(const QDir &dir, const QSet &nameFilters, QDir::Filters filter, QFileInfoList *fileinfolist) @@ -150,24 +149,25 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil cd.m_sortContexts = !(options & NoSort); if (QFile(fileName).exists()) { if (!tor.load(fileName, cd, QLatin1String("auto"))) { - printErr(cd.error()); + printOut(cd.error()); *fail = true; continue; } tor.resolveDuplicates(); cd.clearErrors(); if (setCodec && fetchedTor.codec() != tor.codec()) - qWarning("lupdate warning: Codec for tr() '%s' disagrees with " - "existing file's codec '%s'. Expect trouble.", - fetchedTor.codecName().constData(), tor.codecName().constData()); + printOut(LU::tr("lupdate warning: Codec for tr() '%1' disagrees with" + " existing file's codec '%2'. Expect trouble.\n") + .arg(QString::fromLatin1(fetchedTor.codecName()), + QString::fromLatin1(tor.codecName()))); if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode()) - qWarning("lupdate warning: Specified target language '%s' disagrees with " - "existing file's language '%s'. Ignoring.", - qPrintable(targetLanguage), qPrintable(tor.languageCode())); + printOut(LU::tr("lupdate warning: Specified target language '%1' disagrees with" + " existing file's language '%2'. Ignoring.\n") + .arg(targetLanguage, tor.languageCode())); if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode()) - qWarning("lupdate warning: Specified source language '%s' disagrees with " - "existing file's language '%s'. Ignoring.", - qPrintable(sourceLanguage), qPrintable(tor.sourceLanguageCode())); + printOut(LU::tr("lupdate warning: Specified source language '%1' disagrees with" + " existing file's language '%2'. Ignoring.\n") + .arg(sourceLanguage, tor.sourceLanguageCode())); } else { if (setCodec) tor.setCodec(fetchedTor.codec()); @@ -210,11 +210,11 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil out.normalizeTranslations(cd); if (!cd.errors().isEmpty()) { - printErr(cd.error()); + printOut(cd.error()); cd.clearErrors(); } if (!out.save(fileName, cd, QLatin1String("auto"))) { - printErr(cd.error()); + printOut(cd.error()); *fail = true; } } @@ -296,8 +296,9 @@ static void processProject( if (!tmp.isEmpty()) { codecForSource = tmp.last().toLatin1(); if (!QTextCodec::codecForName(codecForSource)) { - qWarning("lupdate warning: Codec for source '%s' is invalid. " - "Falling back to codec for tr().", codecForSource.constData()); + printOut(LU::tr("lupdate warning: Codec for source '%1' is invalid." + " Falling back to codec for tr().\n") + .arg(QString::fromLatin1(codecForSource))); codecForSource.clear(); } } @@ -452,7 +453,7 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("-target-language")) { ++i; if (i == argc) { - qWarning("The option -target-language requires a parameter."); + printOut(LU::tr("The option -target-language requires a parameter.\n")); return 1; } targetLanguage = args[i]; @@ -460,7 +461,7 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("-source-language")) { ++i; if (i == argc) { - qWarning("The option -source-language requires a parameter."); + printOut(LU::tr("The option -source-language requires a parameter.\n")); return 1; } sourceLanguage = args[i]; @@ -468,7 +469,7 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("-disable-heuristic")) { ++i; if (i == argc) { - qWarning("The option -disable-heuristic requires a parameter."); + printOut(LU::tr("The option -disable-heuristic requires a parameter.\n")); return 1; } arg = args[i]; @@ -479,14 +480,14 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("number")) { options &= ~HeuristicNumber; } else { - qWarning("Invalid heuristic name passed to -disable-heuristic."); + printOut(LU::tr("Invalid heuristic name passed to -disable-heuristic.\n")); return 1; } continue; } else if (arg == QLatin1String("-locations")) { ++i; if (i == argc) { - qWarning("The option -locations requires a parameter."); + printOut(LU::tr("The option -locations requires a parameter.\n")); return 1; } if (args[i] == QLatin1String("none")) { @@ -496,7 +497,7 @@ int main(int argc, char **argv) } else if (args[i] == QLatin1String("absolute")) { options |= AbsoluteLocations; } else { - qWarning("Invalid parameter passed to -locations."); + printOut(LU::tr("Invalid parameter passed to -locations.\n")); return 1; } continue; @@ -522,7 +523,7 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("-codecfortr")) { ++i; if (i == argc) { - qWarning("The -codecfortr option should be followed by a codec name."); + printOut(LU::tr("The -codecfortr option should be followed by a codec name.\n")); return 1; } codecForTr = args[i].toLatin1(); @@ -533,7 +534,7 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("-extensions")) { ++i; if (i == argc) { - qWarning("The -extensions option should be followed by an extension list."); + printOut(LU::tr("The -extensions option should be followed by an extension list.\n")); return 1; } extensions = args[i]; @@ -541,7 +542,7 @@ int main(int argc, char **argv) } else if (arg == QLatin1String("-pro")) { ++i; if (i == argc) { - qWarning("The -pro option should be followed by a filename of .pro file."); + printOut(LU::tr("The -pro option should be followed by a filename of .pro file.\n")); return 1; } proFiles += args[i]; @@ -551,7 +552,7 @@ int main(int argc, char **argv) if (arg.length() == 2) { ++i; if (i == argc) { - qWarning("The -I option should be followed by a path."); + printOut(LU::tr("The -I option should be followed by a path.\n")); return 1; } includePath += args[i]; @@ -560,7 +561,7 @@ int main(int argc, char **argv) } continue; } else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) { - qWarning("Unrecognized option '%s'", qPrintable(arg)); + printOut(LU::tr("Unrecognized option '%1'.\n").arg(arg)); return 1; } @@ -568,8 +569,8 @@ int main(int argc, char **argv) if (arg.startsWith(QLatin1String("@"))) { QFile lstFile(arg.mid(1)); if (!lstFile.open(QIODevice::ReadOnly)) { - qWarning("lupdate error: List file '%s' is not readable", - qPrintable(lstFile.fileName())); + printOut(LU::tr("lupdate error: List file '%1' is not readable.\n") + .arg(lstFile.fileName())); return 1; } while (!lstFile.atEnd()) @@ -586,16 +587,16 @@ int main(int argc, char **argv) if (!fi.exists() || fi.isWritable()) { tsFileNames.append(QFileInfo(file).absoluteFilePath()); } else { - qWarning("lupdate warning: For some reason, '%s' is not writable.\n", - qPrintable(file)); + printOut(LU::tr("lupdate warning: For some reason, '%1' is not writable.\n") + .arg(file)); } found = true; break; } } if (!found) { - qWarning("lupdate error: File '%s' has no recognized extension\n", - qPrintable(file)); + printOut(LU::tr("lupdate error: File '%1' has no recognized extension.\n") + .arg(file)); return 1; } } @@ -604,7 +605,7 @@ int main(int argc, char **argv) foreach (const QString &file, files) { QFileInfo fi(file); if (!fi.exists()) { - qWarning("lupdate error: File '%s' does not exists\n", qPrintable(file)); + printOut(LU::tr("lupdate error: File '%1' does not exist.\n").arg(file)); return 1; } if (file.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) @@ -612,7 +613,7 @@ int main(int argc, char **argv) proFiles << file; } else if (fi.isDir()) { if (options & Verbose) - printOut(QObject::tr("Scanning directory '%1'...").arg(file)); + printOut(QObject::tr("Scanning directory '%1'...\n").arg(file)); QDir dir = QDir(fi.filePath()); projectRoots.insert(dir.absolutePath() + QLatin1Char('/')); if (extensionsNameFilters.isEmpty()) { @@ -662,16 +663,16 @@ int main(int argc, char **argv) } if (!targetLanguage.isEmpty() && tsFileNames.count() != 1) - std::cerr << "lupdate warning: -target-language usually only " - "makes sense with exactly one TS file.\n"; + printOut(LU::tr("lupdate warning: -target-language usually only" + " makes sense with exactly one TS file.\n")); if (!codecForTr.isEmpty() && tsFileNames.isEmpty()) - std::cerr << "lupdate warning: -codecfortr has no effect without -ts.\n"; + printOut(LU::tr("lupdate warning: -codecfortr has no effect without -ts.\n")); bool fail = false; if (proFiles.isEmpty()) { if (tsFileNames.isEmpty()) - std::cerr << "lupdate warning: no TS files specified. " - "Only diagnostics will be produced.\n"; + printOut(LU::tr("lupdate warning:" + " no TS files specified. Only diagnostics will be produced.\n")); Translator fetchedTor; ConversionData cd; @@ -685,7 +686,8 @@ int main(int argc, char **argv) sourceLanguage, targetLanguage, options, &fail); } else { if (!sourceFiles.isEmpty() || !includePath.isEmpty()) { - qWarning("lupdate error: Both project and source files / include paths specified.\n"); + printOut(LU::tr("lupdate error:" + " Both project and source files / include paths specified.\n")); return 1; } if (!tsFileNames.isEmpty()) { diff --git a/tools/linguist/lupdate/qscript.cpp b/tools/linguist/lupdate/qscript.cpp index 33276e67aa..188ac3695f 100644 --- a/tools/linguist/lupdate/qscript.cpp +++ b/tools/linguist/lupdate/qscript.cpp @@ -53,6 +53,8 @@ #include #include +#include + #include #include #include @@ -2214,13 +2216,13 @@ case 66: { if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) { QVariantList args = sym(2).toList(); if (args.size() < 2) { - qWarning("%s:%d: %s() requires at least two arguments", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "() requires at least two arguments.\n"; } else { if ((args.at(0).type() != QVariant::String) || (args.at(1).type() != QVariant::String)) { - qWarning("%s:%d: %s(): both arguments must be literal strings", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "(): both arguments must be literal strings.\n"; } else { QString context = args.at(0).toString(); QString text = args.at(1).toString(); @@ -2234,12 +2236,12 @@ case 66: { } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) { QVariantList args = sym(2).toList(); if (args.size() < 1) { - qWarning("%s:%d: %s() requires at least one argument", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "() requires at least one argument.\n"; } else { if (args.at(0).type() != QVariant::String) { - qWarning("%s:%d: %s(): text to translate must be a literal string", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "(): text to translate must be a literal string.\n"; } else { QString context = QFileInfo(fileName).baseName(); QString text = args.at(0).toString(); @@ -2377,8 +2379,8 @@ bool loadQScript(Translator &translator, const QString &filename, ConversionData lexer.setCode(code, /*lineNumber=*/1); QScriptParser parser; if (!parser.parse(&lexer, filename, &translator)) { - qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(), - qPrintable(parser.errorMessage())); + std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": " + << qPrintable(parser.errorMessage()) << std::endl; return false; } diff --git a/tools/linguist/lupdate/qscript.g b/tools/linguist/lupdate/qscript.g index a473500ad5..a07753c35d 100644 --- a/tools/linguist/lupdate/qscript.g +++ b/tools/linguist/lupdate/qscript.g @@ -90,6 +90,8 @@ #include #include +#include + #include #include #include @@ -1630,13 +1632,13 @@ case $rule_number: { if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) { QVariantList args = sym(2).toList(); if (args.size() < 2) { - qWarning("%s:%d: %s() requires at least two arguments", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "() requires at least two arguments.\n"; } else { if ((args.at(0).type() != QVariant::String) || (args.at(1).type() != QVariant::String)) { - qWarning("%s:%d: %s(): both arguments must be literal strings", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "(): both arguments must be literal strings.\n"; } else { QString context = args.at(0).toString(); QString text = args.at(1).toString(); @@ -1650,12 +1652,12 @@ case $rule_number: { } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) { QVariantList args = sym(2).toList(); if (args.size() < 1) { - qWarning("%s:%d: %s() requires at least one argument", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "() requires at least one argument.\n"; } else { if (args.at(0).type() != QVariant::String) { - qWarning("%s:%d: %s(): text to translate must be a literal string", - qPrintable(fileName), identLineNo, qPrintable(name)); + std::cerr << qPrintable(fileName) << ':' << identLineNo << ": " + << qPrintable(name) << "(): text to translate must be a literal string.\n"; } else { QString context = QFileInfo(fileName).baseName(); QString text = args.at(0).toString(); @@ -2009,8 +2011,8 @@ bool loadQScript(Translator &translator, const QString &filename, ConversionData lexer.setCode(code, /*lineNumber=*/1); QScriptParser parser; if (!parser.parse(&lexer, filename, &translator)) { - qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(), - qPrintable(parser.errorMessage())); + std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": " + << qPrintable(parser.errorMessage()) << std::endl; return false; } diff --git a/tools/linguist/shared/profileevaluator.cpp b/tools/linguist/shared/profileevaluator.cpp index 5e1ee1fb77..a21408c96b 100644 --- a/tools/linguist/shared/profileevaluator.cpp +++ b/tools/linguist/shared/profileevaluator.cpp @@ -2594,19 +2594,19 @@ void ProFileEvaluator::addProperties(const QHash &properties) void ProFileEvaluator::logMessage(const QString &message) { if (d->m_verbose && !d->m_skipLevel) - qWarning("%s", qPrintable(message)); + fprintf(stderr, "%s\n", qPrintable(message)); } void ProFileEvaluator::fileMessage(const QString &message) { if (!d->m_skipLevel) - qWarning("%s", qPrintable(message)); + fprintf(stderr, "%s\n", qPrintable(message)); } void ProFileEvaluator::errorMessage(const QString &message) { if (!d->m_skipLevel) - qWarning("%s", qPrintable(message)); + fprintf(stderr, "%s\n", qPrintable(message)); } void ProFileEvaluator::setVerbose(bool on) diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index c86a9dd2c5..8223dc62a8 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -43,6 +43,8 @@ #include "simtexth.h" +#include + #include #ifdef Q_OS_WIN // required for _setmode, to avoid _O_TEXT streams... @@ -586,22 +588,21 @@ void Translator::reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose) { if (!dupes.byId.isEmpty() || !dupes.byContents.isEmpty()) { + std::cerr << "Warning: dropping duplicate messages in '" << qPrintable(fileName); if (!verbose) { - qWarning("Warning: dropping duplicate messages in '%s'\n(try -verbose for more info).", - qPrintable(fileName)); + std::cerr << "'\n(try -verbose for more info).\n"; } else { - qWarning("Warning: dropping duplicate messages in '%s':", qPrintable(fileName)); + std::cerr << "':\n"; foreach (int i, dupes.byId) - qWarning("\n* ID: %s", qPrintable(message(i).id())); + std::cerr << "\n* ID: " << qPrintable(message(i).id()) << std::endl; foreach (int j, dupes.byContents) { const TranslatorMessage &msg = message(j); - qWarning("\n* Context: %s\n* Source: %s", - qPrintable(msg.context()), - qPrintable(msg.sourceText())); + std::cerr << "\n* Context: " << qPrintable(msg.context()) + << "\n* Source: " << qPrintable(msg.sourceText()) << std::endl; if (!msg.comment().isEmpty()) - qWarning("* Comment: %s", qPrintable(msg.comment())); + std::cerr << "* Comment: " << qPrintable(msg.comment()) << std::endl; } - qWarning(); + std::cerr << std::endl; } } } @@ -737,7 +738,7 @@ void Translator::setCodecName(const QByteArray &name) QTextCodec *codec = QTextCodec::codecForName(name); if (!codec) { if (!name.isEmpty()) - qWarning("No QTextCodec for %s available. Using Latin1\n", name.constData()); + std::cerr << "No QTextCodec for " << name.constData() << " available. Using Latin1.\n"; m_codec = QTextCodec::codecForName("ISO-8859-1"); } else { m_codec = codec; -- cgit v1.2.3 From 068177288001c46896d6b04c520731adb56ed288 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 3 Jun 2010 18:05:47 +0200 Subject: remove spurious empty lines in the linguist tools' output ConversionData::error() does already newline-terminate the strings. --- tools/linguist/lconvert/main.cpp | 8 ++++---- tools/linguist/lrelease/main.cpp | 4 ++-- tools/linguist/shared/po.cpp | 16 ++++++++-------- tools/linguist/shared/qm.cpp | 4 ++-- tools/linguist/shared/translator.cpp | 2 +- tools/linguist/shared/translator.h | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp index 049ea43856..094406c984 100644 --- a/tools/linguist/lconvert/main.cpp +++ b/tools/linguist/lconvert/main.cpp @@ -240,7 +240,7 @@ int main(int argc, char *argv[]) tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name)); if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) { - std::cerr << qPrintable(cd.error()) << std::endl; + std::cerr << qPrintable(cd.error()); return 2; } tr.reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose); @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) for (int i = 1; i < inFiles.size(); ++i) { Translator tr2; if (!tr2.load(inFiles[i].name, cd, inFiles[i].format)) { - std::cerr << qPrintable(cd.error()) << std::endl; + std::cerr << qPrintable(cd.error()); return 2; } tr2.reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose); @@ -273,11 +273,11 @@ int main(int argc, char *argv[]) tr.normalizeTranslations(cd); if (!cd.errors().isEmpty()) { - std::cerr << qPrintable(cd.error()) << std::endl; + std::cerr << qPrintable(cd.error()); cd.clearErrors(); } if (!tr.save(outFileName, cd, outFormat)) { - std::cerr << qPrintable(cd.error()) << std::endl; + std::cerr << qPrintable(cd.error()); return 3; } return 0; diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp index df0b430aae..b5cff90a77 100644 --- a/tools/linguist/lrelease/main.cpp +++ b/tools/linguist/lrelease/main.cpp @@ -108,7 +108,7 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo ConversionData cd; bool ok = tor.load(tsFileName, cd, QLatin1String("auto")); if (!ok) { - std::cerr << "lrelease error: " << qPrintable(cd.error()) << std::endl; + std::cerr << "lrelease error: " << qPrintable(cd.error()); } else { if (!cd.errors().isEmpty()) printOut(cd.error()); @@ -143,7 +143,7 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName, if (!ok) { std::cerr << "lrelease error: cannot save '" << qPrintable(qmFileName) - << "': " << qPrintable(cd.error()) << std::endl; + << "': " << qPrintable(cd.error()); } else if (!cd.errors().isEmpty()) { printOut(cd.error()); } diff --git a/tools/linguist/shared/po.cpp b/tools/linguist/shared/po.cpp index 6a1d426a98..a6923328ae 100644 --- a/tools/linguist/shared/po.cpp +++ b/tools/linguist/shared/po.cpp @@ -461,7 +461,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) continue; int idx = hdr.indexOf(':'); if (idx < 0) { - cd.appendError(QString::fromLatin1("Unexpected PO header format '%1'\n") + cd.appendError(QString::fromLatin1("Unexpected PO header format '%1'") .arg(QString::fromLatin1(hdr))); error = true; break; @@ -482,7 +482,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) } else if (hdrName == "Content-Type") { if (cd.m_codecForSource.isEmpty()) { if (!hdrValue.startsWith("text/plain; charset=")) { - cd.appendError(QString::fromLatin1("Unexpected Content-Type header '%1'\n") + cd.appendError(QString::fromLatin1("Unexpected Content-Type header '%1'") .arg(QString::fromLatin1(hdrValue))); error = true; // This will avoid a flood of conversion errors. @@ -491,7 +491,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) QByteArray cod = hdrValue.mid(20); QTextCodec *cdc = QTextCodec::codecForName(cod); if (!cdc) { - cd.appendError(QString::fromLatin1("Unsupported codec '%1'\n") + cd.appendError(QString::fromLatin1("Unsupported codec '%1'") .arg(QString::fromLatin1(cod))); error = true; // This will avoid a flood of conversion errors. @@ -503,7 +503,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) } } else if (hdrName == "Content-Transfer-Encoding") { if (hdrValue != "8bit") { - cd.appendError(QString::fromLatin1("Unexpected Content-Transfer-Encoding '%1'\n") + cd.appendError(QString::fromLatin1("Unexpected Content-Transfer-Encoding '%1'") .arg(QString::fromLatin1(hdrValue))); return false; } @@ -644,7 +644,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) if (qtContexts) splitContext(&item.oldTscomment, &item.context); } else { - cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'\n")) + cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'")) .arg(l + 1).arg(codec->toUnicode(lines[l]))); error = true; } @@ -661,13 +661,13 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) } else if (line.startsWith("#~ msgctxt ")) { item.tscomment = slurpEscapedString(lines, l, 11, "#~ ", cd); } else { - cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'\n")) + cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'")) .arg(l + 1).arg(codec->toUnicode(lines[l]))); error = true; } break; default: - cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'\n")) + cd.appendError(QString(QLatin1String("PO-format parse error in line %1: '%2'")) .arg(l + 1).arg(codec->toUnicode(lines[l]))); error = true; break; @@ -685,7 +685,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) item.extra[QLatin1String("po-msgid_plural")] = codec->toUnicode(extra); item.isPlural = true; } else { - cd.appendError(QString(QLatin1String("PO-format error in line %1: '%2'\n")) + cd.appendError(QString(QLatin1String("PO-format error in line %1: '%2'")) .arg(l + 1).arg(codec->toUnicode(lines[l]))); error = true; } diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp index e2c4f4acef..66789432e1 100644 --- a/tools/linguist/shared/qm.cpp +++ b/tools/linguist/shared/qm.cpp @@ -773,11 +773,11 @@ static bool saveQM(const Translator &translator, QIODevice &dev, ConversionData if (saved && cd.isVerbose()) { int generatedCount = finished + unfinished; cd.appendError(QCoreApplication::translate("LRelease", - " Generated %n translation(s) (%1 finished and %2 unfinished)\n", 0, + " Generated %n translation(s) (%1 finished and %2 unfinished)", 0, QCoreApplication::CodecForTr, generatedCount).arg(finished).arg(unfinished)); if (untranslated) cd.appendError(QCoreApplication::translate("LRelease", - " Ignored %n untranslated source text(s)\n", 0, + " Ignored %n untranslated source text(s)", 0, QCoreApplication::CodecForTr, untranslated)); } return saved; diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp index 8223dc62a8..36af8dae90 100644 --- a/tools/linguist/shared/translator.cpp +++ b/tools/linguist/shared/translator.cpp @@ -689,7 +689,7 @@ void Translator::normalizeTranslations(ConversionData &cd) cd.appendError(QLatin1String( "Removed plural forms as the target language has less " "forms.\nIf this sounds wrong, possibly the target language is " - "not set or recognized.\n")); + "not set or recognized.")); } QString Translator::guessLanguageCodeFromFileName(const QString &filename) diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index bb199f086e..cfb2178425 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -92,7 +92,7 @@ public: bool sortContexts() const { return m_sortContexts; } void appendError(const QString &error) { m_errors.append(error); } - QString error() const { return m_errors.join(QLatin1String("\n")); } + QString error() const { return m_errors.isEmpty() ? QString() : m_errors.join(QLatin1String("\n")) + QLatin1Char('\n'); } QStringList errors() const { return m_errors; } void clearErrors() { m_errors.clear(); } -- cgit v1.2.3