diff options
author | Martin Smith <martin.smith@nokia.com> | 2011-01-14 13:02:57 (GMT) |
---|---|---|
committer | Martin Smith <martin.smith@nokia.com> | 2011-01-14 13:02:57 (GMT) |
commit | 74f63cebc430ef6634917577783dafeed9a233d5 (patch) | |
tree | 663d030b0ca0f6dba36260aa542d11c62792a7d8 /tools | |
parent | 02d904d5983ff0597f52d8d6ec76439f81da6504 (diff) | |
download | Qt-74f63cebc430ef6634917577783dafeed9a233d5.zip Qt-74f63cebc430ef6634917577783dafeed9a233d5.tar.gz Qt-74f63cebc430ef6634917577783dafeed9a233d5.tar.bz2 |
qdoc: Added colorizing of individual table cells.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qdoc3/atom.h | 65 | ||||
-rw-r--r-- | tools/qdoc3/doc.cpp | 146 | ||||
-rw-r--r-- | tools/qdoc3/htmlgenerator.cpp | 38 |
3 files changed, 148 insertions, 101 deletions
diff --git a/tools/qdoc3/atom.h b/tools/qdoc3/atom.h index 739d8e3..c2b7cd6 100644 --- a/tools/qdoc3/atom.h +++ b/tools/qdoc3/atom.h @@ -46,7 +46,7 @@ #ifndef ATOM_H #define ATOM_H -#include <qstring.h> +#include <qstringlist.h> #define QDOC_QML @@ -137,24 +137,51 @@ class Atom Last = UnknownCommand }; - Atom(Type type, const QString &string = "") - : nxt(0), typ(type), str(string) { } - Atom(Atom *prev, Type type, const QString &string = "") - : nxt(prev->nxt), typ(type), str(string) { prev->nxt = this; } - - void appendChar(QChar ch) { str += ch; } - void appendString(const QString& string) { str += string; } - void chopString() { str.chop(1); } - void setString(const QString &string) { str = string; } - Atom *next() { return nxt; } - void setNext(Atom *newNext) { nxt = newNext; } - - const Atom *next() const { return nxt; } - const Atom *next(Type t) const; - const Atom *next(Type t, const QString& s) const; + Atom(Type type, const QString& string = "") + : nxt(0), typ(type) + { + strs << string; + } + + Atom(Type type, const QString& p1, const QString& p2) + : nxt(0), typ(type) + { + strs << p1; + if (!p2.isEmpty()) + strs << p2; + } + + Atom(Atom* prev, Type type, const QString& string = "") + : nxt(prev->nxt), typ(type) + { + strs << string; + prev->nxt = this; + } + + Atom(Atom* prev, Type type, const QString& p1, const QString& p2) + : nxt(prev->nxt), typ(type) + { + strs << p1; + if (!p2.isEmpty()) + strs << p2; + prev->nxt = this; + } + + void appendChar(QChar ch) { strs[0] += ch; } + void appendString(const QString& string) { strs[0] += string; } + void chopString() { strs[0].chop(1); } + void setString(const QString& string) { strs[0] = string; } + Atom* next() { return nxt; } + void setNext(Atom* newNext) { nxt = newNext; } + + const Atom* next() const { return nxt; } + const Atom* next(Type t) const; + const Atom* next(Type t, const QString& s) const; Type type() const { return typ; } QString typeString() const; - const QString& string() const { return str; } + const QString& string() const { return strs[0]; } + const QString& string(int i) const { return strs[i]; } + int count() const { return strs.size(); } void dump() const; static QString BOLD_; @@ -177,9 +204,9 @@ class Atom static QString UPPERROMAN_; private: - Atom *nxt; + Atom* nxt; Type typ; - QString str; + QStringList strs; }; #define ATOM_FORMATTING_BOLD "bold" diff --git a/tools/qdoc3/doc.cpp b/tools/qdoc3/doc.cpp index 7c3d141..36c1d94 100644 --- a/tools/qdoc3/doc.cpp +++ b/tools/qdoc3/doc.cpp @@ -364,6 +364,7 @@ class DocParser void endSection(int unit, int endCmd); void parseAlso(); void append(Atom::Type type, const QString& string = ""); + void append(Atom::Type type, const QString& p1, const QString& p2); void appendChar(QChar ch); void appendWord(const QString &word); void appendToCode(const QString &code); @@ -467,7 +468,7 @@ void DocParser::parse(const QString& source, CodeMarker *marker = 0; Atom *currentLinkAtom = 0; - QString x; + QString p1, p2; QStack<bool> preprocessorSkipping; int numPreprocessorSkipping = 0; @@ -506,11 +507,11 @@ void DocParser::parse(const QString& source, switch (cmd) { case CMD_A: enterPara(); - x = getArgument(); + p1 = getArgument(); append(Atom::FormattingLeft,ATOM_FORMATTING_PARAMETER); - append(Atom::String, x); + append(Atom::String, p1); append(Atom::FormattingRight,ATOM_FORMATTING_PARAMETER); - priv->params.insert(x); + priv->params.insert(p1); break; case CMD_ABSTRACT: if (openCommand(cmd)) { @@ -535,9 +536,9 @@ void DocParser::parse(const QString& source, break; case CMD_C: enterPara(); - x = untabifyEtc(getArgument(true)); - marker = CodeMarker::markerForCode(x); - append(Atom::C, marker->markedUpCode(x, 0, "")); + p1 = untabifyEtc(getArgument(true)); + marker = CodeMarker::markerForCode(p1); + append(Atom::C, marker->markedUpCode(p1, 0, "")); break; case CMD_CAPTION: leavePara(); @@ -560,14 +561,14 @@ void DocParser::parse(const QString& source, break; #endif case CMD_DIV: - x = getArgument(true); + p1 = getArgument(true); leavePara(); - if (x.contains('=')) { - enterPara(Atom::DivLeft, Atom::DivRight,x); + if (p1.contains('=')) { + enterPara(Atom::DivLeft, Atom::DivRight,p1); openedCommands.push(cmd); } else { - append(Atom::DivLeft, x); + append(Atom::DivLeft, p1); openedCommands.push(cmd); enterPara(); } @@ -823,23 +824,23 @@ void DocParser::parse(const QString& source, case CMD_L: enterPara(); if (isLeftBraceAhead()) { - x = getArgument(); - append(Atom::Link, x); + p1 = getArgument(); + append(Atom::Link, p1); if (isLeftBraceAhead()) { currentLinkAtom = priv->text.lastAtom(); startFormat(ATOM_FORMATTING_LINK, cmd); } else { append(Atom::FormattingLeft, ATOM_FORMATTING_LINK); - append(Atom::String, cleanLink(x)); + append(Atom::String, cleanLink(p1)); append(Atom::FormattingRight, ATOM_FORMATTING_LINK); } } else { - x = getArgument(); - append(Atom::Link, x); + p1 = getArgument(); + append(Atom::Link, p1); append(Atom::FormattingLeft, ATOM_FORMATTING_LINK); - append(Atom::String, cleanLink(x)); + append(Atom::String, cleanLink(p1)); append(Atom::FormattingRight, ATOM_FORMATTING_LINK); } break; @@ -852,8 +853,8 @@ void DocParser::parse(const QString& source, case CMD_LINK: if (openCommand(cmd)) { enterPara(); - x = getArgument(); - append(Atom::Link, x); + p1 = getArgument(); + append(Atom::Link, p1); append(Atom::FormattingLeft, ATOM_FORMATTING_LINK); skipSpacesOrOneEndl(); } @@ -867,8 +868,8 @@ void DocParser::parse(const QString& source, break; case CMD_META: priv->constructExtra(); - x = getArgument(); - priv->extra->metaMap.insert(x, getRestOfLine()); + p1 = getArgument(); + priv->extra->metaMap.insert(p1, getRestOfLine()); break; case CMD_NEWCODE: location().warning(tr("Unexpected '\\%1'").arg(cmdName(CMD_NEWCODE))); @@ -892,9 +893,13 @@ void DocParser::parse(const QString& source, enterPara(); } else if (openedCommands.top() == CMD_TABLE) { - x = "1,1"; - if (isLeftBraceAhead()) - x = getArgument(); + p1 = "1,1"; + if (isLeftBraceAhead()) { + p1 = getArgument(); + if (isLeftBraceAhead()) { + p2 = getArgument(); + } + } if (!inTableHeader && !inTableRow) { location().warning(tr("Missing '\\%1' or '\\%1' before '\\%3'") @@ -909,7 +914,7 @@ void DocParser::parse(const QString& source, inTableItem = false; } - append(Atom::TableItemLeft, x); + append(Atom::TableItemLeft, p1, p2); inTableItem = true; } else { @@ -928,11 +933,11 @@ void DocParser::parse(const QString& source, getUntilEnd(cmd); break; case CMD_OMITVALUE: - x = getArgument(); - if (!priv->enumItemList.contains(x)) - priv->enumItemList.append(x); - if (!priv->omitEnumItemList.contains(x)) - priv->omitEnumItemList.append(x); + p1 = getArgument(); + if (!priv->enumItemList.contains(p1)) + priv->enumItemList.append(p1); + if (!priv->omitEnumItemList.contains(p1)) + priv->omitEnumItemList.append(p1); break; case CMD_PART: startSection(Doc::Part, cmd); @@ -1001,36 +1006,38 @@ void DocParser::parse(const QString& source, case CMD_QUOTEFUNCTION: leavePara(); marker = quoteFromFile(); - x = getRestOfLine(); + p1 = getRestOfLine(); if (!quoting) { quoter.quoteTo(location(), cmdStr, - slashed(marker->functionBeginRegExp(x))); + slashed(marker->functionBeginRegExp(p1))); append(Atom::Code, quoter.quoteUntil(location(), cmdStr, - slashed(marker->functionEndRegExp(x)))); + slashed(marker->functionEndRegExp(p1)))); quoter.reset(); } else { append(Atom::CodeQuoteCommand, cmdStr); - append(Atom::CodeQuoteArgument, slashed(marker->functionEndRegExp(x))); + append(Atom::CodeQuoteArgument, slashed(marker->functionEndRegExp(p1))); } break; case CMD_RAW: leavePara(); - x = getRestOfLine(); - if (x.isEmpty()) + p1 = getRestOfLine(); + if (p1.isEmpty()) location().warning(tr("Missing format name after '\\%1") .arg(cmdName(CMD_RAW))); - append(Atom::FormatIf, x); + append(Atom::FormatIf, p1); append(Atom::RawString, untabifyEtc(getUntilEnd(cmd))); append(Atom::FormatElse); append(Atom::FormatEndif); break; case CMD_ROW: if (openedCommands.top() == CMD_TABLE) { - x = getArgument(true); + p1.clear(); + if (isLeftBraceAhead()) + p1 = getArgument(true); leaveTableRow(); - append(Atom::TableRowLeft,x); + append(Atom::TableRowLeft,p1); inTableRow = true; } else { @@ -1124,22 +1131,22 @@ void DocParser::parse(const QString& source, startFormat(ATOM_FORMATTING_SUPERSCRIPT, cmd); break; case CMD_TABLE: - x = getRestOfLine(); + p1 = getRestOfLine(); if (openCommand(cmd)) { leavePara(); - append(Atom::TableLeft, x); + append(Atom::TableLeft, p1); inTableHeader = false; inTableRow = false; inTableItem = false; } break; case CMD_TABLEOFCONTENTS: - x = "1"; + p1 = "1"; if (isLeftBraceAhead()) - x = getArgument(); - x += ","; - x += QString::number((int)getSectioningUnit()); - append(Atom::TableOfContents, x); + p1 = getArgument(); + p1 += ","; + p1 += QString::number((int)getSectioningUnit()); + append(Atom::TableOfContents, p1); break; case CMD_TARGET: insertTarget(getRestOfLine(),false); @@ -1152,16 +1159,16 @@ void DocParser::parse(const QString& source, break; case CMD_UNICODE: enterPara(); - x = getArgument(); + p1 = getArgument(); { bool ok; - uint unicodeChar = x.toUInt(&ok, 0); + uint unicodeChar = p1.toUInt(&ok, 0); if (!ok || (unicodeChar == 0x0000) || (unicodeChar > 0xFFFE)) { location().warning(tr("Invalid Unicode character '%1' specified " "with '%2'") - .arg(x, cmdName(CMD_UNICODE))); + .arg(p1, cmdName(CMD_UNICODE))); } else { append(Atom::String, QChar(unicodeChar)); @@ -1171,13 +1178,13 @@ void DocParser::parse(const QString& source, case CMD_VALUE: leaveValue(); if (openedLists.top().style() == OpenedList::Value) { - x = getArgument(); - if (!priv->enumItemList.contains(x)) - priv->enumItemList.append(x); + p1 = getArgument(); + if (!priv->enumItemList.contains(p1)) + priv->enumItemList.append(p1); openedLists.top().next(); append(Atom::ListTagLeft, ATOM_LIST_VALUE); - append(Atom::String, x); + append(Atom::String, p1); append(Atom::ListTagRight, ATOM_LIST_VALUE); append(Atom::ListItemLeft, ATOM_LIST_VALUE); @@ -1198,13 +1205,13 @@ void DocParser::parse(const QString& source, break; case CMD_OVERLOAD: priv->metacommandsUsed.insert(cmdStr); - x.clear(); + p1.clear(); if (!isBlankLine()) - x = getRestOfLine(); - if (!x.isEmpty()) { + p1 = getRestOfLine(); + if (!p1.isEmpty()) { append(Atom::ParaLeft); append(Atom::String, "This function overloads "); - append(Atom::AutoLink,x); + append(Atom::AutoLink,p1); append(Atom::String, "."); append(Atom::ParaRight); } @@ -1212,9 +1219,9 @@ void DocParser::parse(const QString& source, append(Atom::ParaLeft); append(Atom::String,"This is an overloaded function."); append(Atom::ParaRight); - x = getMetaCommandArgument(cmdStr); + p1 = getMetaCommandArgument(cmdStr); } - priv->metaCommandMap[cmdStr].append(x); + priv->metaCommandMap[cmdStr].append(p1); break; case NOT_A_CMD: if (metaCommandSet.contains(cmdStr)) { @@ -1816,9 +1823,6 @@ void DocParser::parseAlso() } //static bool debug = false; - -void DocParser::append(Atom::Type type, const QString &string) -{ #if 0 if (type == Atom::DivLeft) debug = true; @@ -1827,17 +1831,23 @@ void DocParser::append(Atom::Type type, const QString &string) if (type == Atom::DivRight) debug = false; #endif + +void DocParser::append(Atom::Type type, const QString &string) +{ Atom::Type lastType = priv->text.lastAtom()->type(); -#ifdef QDOC_QML - if (((lastType == Atom::Code) || (lastType == Atom::Code)) && -#else - if ((lastType == Atom::Code) && -#endif - priv->text.lastAtom()->string().endsWith(QLatin1String("\n\n"))) + if ((lastType == Atom::Code) && priv->text.lastAtom()->string().endsWith(QLatin1String("\n\n"))) priv->text.lastAtom()->chopString(); priv->text << Atom(type, string); } +void DocParser::append(Atom::Type type, const QString& p1, const QString& p2) +{ + Atom::Type lastType = priv->text.lastAtom()->type(); + if ((lastType == Atom::Code) && priv->text.lastAtom()->string().endsWith(QLatin1String("\n\n"))) + priv->text.lastAtom()->chopString(); + priv->text << Atom(type, p1, p2); +} + void DocParser::appendChar(QChar ch) { if (priv->text.lastAtom()->type() != Atom::String) diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index 81bd7a8..2f990b0 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -1091,14 +1091,14 @@ int HtmlGenerator::generateAtom(const Atom *atom, out() << "</table>\n"; break; case Atom::TableHeaderLeft: - out() << "<thead><tr class=\"qt-style topAlign\">"; + out() << "<thead><tr class=\"qt-style\">"; inTableHeader = true; break; case Atom::TableHeaderRight: out() << "</tr>"; if (matchAhead(atom, Atom::TableHeaderLeft)) { skipAhead = 1; - out() << "\n<tr class=\"qt-style topAlign\">"; + out() << "\n<tr class=\"qt-style\">"; } else { out() << "</thead>\n"; @@ -1114,9 +1114,9 @@ int HtmlGenerator::generateAtom(const Atom *atom, out() << " class=\"" << atom->string() << "\">"; } else if (++numTableRows % 2 == 1) - out() << "<tr class=\"odd topAlign\">"; + out() << "<tr class=\"odd\">"; else - out() << "<tr class=\"even topAlign\">"; + out() << "<tr class=\"even\">"; break; case Atom::TableRowRight: out() << "</tr>\n"; @@ -1128,19 +1128,29 @@ int HtmlGenerator::generateAtom(const Atom *atom, else out() << "<td "; - QStringList spans = atom->string().split(","); - if (spans.size() == 2) { - if (spans.at(0) != "1") - out() << " colspan=\"" << spans.at(0) << "\""; - if (spans.at(1) != "1") - out() << " rowspan=\"" << spans.at(1) << "\""; - if (inTableHeader) - out() << ">"; + for (int i=0; i<atom->count(); ++i) { + if (i > 0) + out() << " "; + QString p = atom->string(i); + if (p.contains('=')) { + out() << p; + } else { - out() << ">"; - //out() << "><p>"; + QStringList spans = p.split(","); + if (spans.size() == 2) { + if (spans.at(0) != "1") + out() << " colspan=\"" << spans.at(0) << "\""; + if (spans.at(1) != "1") + out() << " rowspan=\"" << spans.at(1) << "\""; + } } } + if (inTableHeader) + out() << ">"; + else { + out() << ">"; + //out() << "><p>"; + } if (matchAhead(atom, Atom::ParaLeft)) skipAhead = 1; } |