diff options
author | Martin Smith <martin.smith@nokia.com> | 2011-04-14 11:40:36 (GMT) |
---|---|---|
committer | Martin Smith <martin.smith@nokia.com> | 2011-04-14 11:40:36 (GMT) |
commit | 6414bda3218790fb8a20a8ff5b3acf6fc6e206da (patch) | |
tree | 6fa3e4e26d7373ac5cff8c892bac28598595be07 | |
parent | acaaa87b5ff35981d96a4ed9666f436822ccdb3f (diff) | |
download | Qt-6414bda3218790fb8a20a8ff5b3acf6fc6e206da.zip Qt-6414bda3218790fb8a20a8ff5b3acf6fc6e206da.tar.gz Qt-6414bda3218790fb8a20a8ff5b3acf6fc6e206da.tar.bz2 |
qdoc: Completed task QTBUG-18733
-rw-r--r-- | tools/qdoc3/codemarker.h | 3 | ||||
-rw-r--r-- | tools/qdoc3/ditaxmlgenerator.cpp | 76 | ||||
-rw-r--r-- | tools/qdoc3/ditaxmlgenerator.h | 13 | ||||
-rw-r--r-- | tools/qdoc3/htmlgenerator.cpp | 101 | ||||
-rw-r--r-- | tools/qdoc3/pagegenerator.cpp | 6 |
5 files changed, 74 insertions, 125 deletions
diff --git a/tools/qdoc3/codemarker.h b/tools/qdoc3/codemarker.h index 21bc31f..00660e7 100644 --- a/tools/qdoc3/codemarker.h +++ b/tools/qdoc3/codemarker.h @@ -165,10 +165,11 @@ class CodeMarker static const Node *nodeForString(const QString& string); static QString stringForNode(const Node *node); + QString typified(const QString &string); + protected: virtual QString sortName(const Node *node); QString protect(const QString &string); - QString typified(const QString &string); QString taggedNode(const Node* node); #ifdef QDOC_QML QString taggedQmlNode(const Node* node); diff --git a/tools/qdoc3/ditaxmlgenerator.cpp b/tools/qdoc3/ditaxmlgenerator.cpp index 69afde9..e394249 100644 --- a/tools/qdoc3/ditaxmlgenerator.cpp +++ b/tools/qdoc3/ditaxmlgenerator.cpp @@ -92,6 +92,7 @@ QString DitaXmlGenerator::ditaTags[] = "apiDesc", "APIMap", "apiName", + "apiRelation", "audience", "author", "b", @@ -284,14 +285,15 @@ void DitaXmlGenerator::writeCharacters(const QString& text) with the \a href attribute and the \a text. */ void DitaXmlGenerator::addLink(const QString& href, - const QStringRef& text) + const QStringRef& text, + DitaTag t) { if (!href.isEmpty()) { - writeStartTag(DT_xref); + writeStartTag(t); // formathtml xmlWriter().writeAttribute("href", href); writeCharacters(text.toString()); - writeEndTag(); // </xref> + writeEndTag(); // </t> } else { writeCharacters(text.toString()); @@ -1718,7 +1720,7 @@ DitaXmlGenerator::generateClassLikeNode(const InnerNode* inner, CodeMarker* mark */ generateHeader(inner, fullTitle); generateBrief(inner, marker); // <shortdesc> - writeProlog(inner,marker); + writeProlog(inner); writeStartTag(DT_cxxClassDetail); writeStartTag(DT_cxxClassDefinition); @@ -1838,7 +1840,7 @@ DitaXmlGenerator::generateClassLikeNode(const InnerNode* inner, CodeMarker* mark generateHeader(inner, fullTitle); generateBrief(inner, marker); // <shortdesc> - writeProlog(inner,marker); + writeProlog(inner); writeStartTag(DT_cxxClassDetail); writeStartTag(DT_cxxClassDefinition); @@ -1974,7 +1976,7 @@ DitaXmlGenerator::generateClassLikeNode(const InnerNode* inner, CodeMarker* mark */ generateHeader(inner, fullTitle); generateBrief(inner, marker); // <shortdesc> - writeProlog(inner,marker); + writeProlog(inner); writeStartTag(DT_cxxClassDetail); enterApiDesc(QString(),title); @@ -2093,7 +2095,7 @@ DitaXmlGenerator::generateClassLikeNode(const InnerNode* inner, CodeMarker* mark generateHeader(inner, fullTitle); generateBrief(inner, marker); // <shortdesc> - writeProlog(inner,marker); + writeProlog(inner); writeStartTag(DT_cxxClassDetail); enterApiDesc(QString(),title); @@ -2195,7 +2197,7 @@ void DitaXmlGenerator::generateFakeNode(const FakeNode* fake, CodeMarker* marker generateHeader(fake, fullTitle); generateBrief(fake, marker); // <shortdesc> - writeProlog(fake, marker); + writeProlog(fake); writeStartTag(DT_body); enterSection(QString(),QString()); @@ -4712,7 +4714,7 @@ void DitaXmlGenerator::writeLocation(const Node* n) Write the <cxxFunction> elements. */ void DitaXmlGenerator::writeFunctions(const Section& s, - const Node* n, + const InnerNode* parent, CodeMarker* marker, const QString& attribute) { @@ -4775,7 +4777,7 @@ void DitaXmlGenerator::writeFunctions(const Section& s, } } - if (fn->name() == n->name()) { + if (fn->name() == parent->name()) { writeStartTag(DT_cxxFunctionConstructor); xmlWriter().writeAttribute("name","constructor"); xmlWriter().writeAttribute("value","constructor"); @@ -4789,7 +4791,8 @@ void DitaXmlGenerator::writeFunctions(const Section& s, } else { writeStartTag(DT_cxxFunctionDeclaredType); - writeCharacters(fn->returnType()); + QString src = marker->typified(fn->returnType()); + replaceTypesWithLinks(fn,parent,marker,src); writeEndTag(); // <cxxFunctionDeclaredType> } @@ -4825,7 +4828,7 @@ void DitaXmlGenerator::writeFunctions(const Section& s, writeEndTag(); // </cxxFunctionReimplemented> } } - writeParameters(fn); + writeParameters(fn,parent,marker); writeLocation(fn); writeEndTag(); // <cxxFunctionDefinition> @@ -4846,10 +4849,51 @@ void DitaXmlGenerator::writeFunctions(const Section& s, } } +static const QString typeTag("type"); +static const QChar charLangle = '<'; +static const QChar charAt = '@'; + +/*! + This function replaces class and enum names with <apiRelation> + elements, i.e. links. + */ +void DitaXmlGenerator::replaceTypesWithLinks(const Node* n, + const InnerNode* parent, + CodeMarker* marker, + QString& src) +{ + QStringRef arg; + QStringRef par1; + int srcSize = src.size(); + QString text; + for (int i=0; i<srcSize;) { + if (src.at(i) == charLangle && src.at(i+1) == charAt) { + if (!text.isEmpty()) { + writeCharacters(text); + text.clear(); + } + i += 2; + if (parseArg(src, typeTag, &i, srcSize, &arg, &par1)) { + const Node* tn = marker->resolveTarget(arg.toString(), myTree, parent, n); + addLink(linkForNode(tn,parent),arg,DT_apiRelation); + } + } + else { + text += src.at(i++); + } + } + if (!text.isEmpty()) { + writeCharacters(text); + text.clear(); + } +} + /*! This function writes the <cxxFunctionParameters> element. */ -void DitaXmlGenerator::writeParameters(const FunctionNode* fn) +void DitaXmlGenerator::writeParameters(const FunctionNode* fn, + const InnerNode* parent, + CodeMarker* marker) { const QList<Parameter>& parameters = fn->parameters(); if (!parameters.isEmpty()) { @@ -4858,7 +4902,9 @@ void DitaXmlGenerator::writeParameters(const FunctionNode* fn) while (p != parameters.end()) { writeStartTag(DT_cxxFunctionParameter); writeStartTag(DT_cxxFunctionParameterDeclaredType); - writeCharacters((*p).leftType()); + QString src = marker->typified((*p).leftType()); + replaceTypesWithLinks(fn,parent,marker,src); + //writeCharacters((*p).leftType()); if (!(*p).rightType().isEmpty()) writeCharacters((*p).rightType()); writeEndTag(); // <cxxFunctionParameterDeclaredType> @@ -5695,7 +5741,7 @@ QString DitaXmlGenerator::metadataDefault(DitaTag t) const */ void -DitaXmlGenerator::writeProlog(const InnerNode* inner, CodeMarker* marker) +DitaXmlGenerator::writeProlog(const InnerNode* inner) { if (!inner) return; diff --git a/tools/qdoc3/ditaxmlgenerator.h b/tools/qdoc3/ditaxmlgenerator.h index ffca234..0044eff 100644 --- a/tools/qdoc3/ditaxmlgenerator.h +++ b/tools/qdoc3/ditaxmlgenerator.h @@ -87,6 +87,7 @@ class DitaXmlGenerator : public PageGenerator DT_apiDesc, DT_APIMap, DT_apiName, + DT_apiRelation, DT_audience, DT_author, DT_b, @@ -292,11 +293,15 @@ class DitaXmlGenerator : public PageGenerator void writeDerivations(const ClassNode* cn, CodeMarker* marker); void writeLocation(const Node* n); void writeFunctions(const Section& s, - const Node* n, + const InnerNode* parent, CodeMarker* marker, const QString& attribute = QString()); void writeNestedClasses(const Section& s, const Node* n); - void writeParameters(const FunctionNode* fn); + void replaceTypesWithLinks(const Node* n, + const InnerNode* parent, + CodeMarker* marker, + QString& src); + void writeParameters(const FunctionNode* fn, const InnerNode* parent, CodeMarker* marker); void writeEnumerations(const Section& s, CodeMarker* marker, const QString& attribute = QString()); @@ -315,7 +320,7 @@ class DitaXmlGenerator : public PageGenerator void writePropertyParameter(const QString& tag, const NodeList& nlist); void writeRelatedLinks(const FakeNode* fake, CodeMarker* marker); void writeLink(const Node* node, const QString& tex, const QString& role); - void writeProlog(const InnerNode* inner, CodeMarker* marker); + void writeProlog(const InnerNode* inner); bool writeMetadataElement(const InnerNode* inner, DitaXmlGenerator::DitaTag t, bool force=true); @@ -438,7 +443,7 @@ class DitaXmlGenerator : public PageGenerator virtual void generateInnerNode(const InnerNode* node); QXmlStreamWriter& xmlWriter(); void writeApiDesc(const Node* node, CodeMarker* marker, const QString& title); - void addLink(const QString& href, const QStringRef& text); + void addLink(const QString& href, const QStringRef& text, DitaTag t = DT_xref); void writeDitaMap(); void writeStartTag(DitaTag t); void writeEndTag(DitaTag t=DT_NONE); diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index 88bc3e2..a6cf646 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -93,104 +93,6 @@ static QRegExp typeTag("(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)(</@\\2>)"); static QRegExp spanTag("</@(?:comment|preprocessor|string|char|number|op|type|name|keyword)>"); static QRegExp unknownTag("</?@[^>]*>"); -bool parseArg(const QString &src, - const QString &tag, - int *pos, - int n, - QStringRef *contents, - QStringRef *par1 = 0, - bool debug = false) -{ -#define SKIP_CHAR(c) \ - if (debug) \ - qDebug() << "looking for " << c << " at " << QString(src.data() + i, n - i); \ - if (i >= n || src[i] != c) { \ - if (debug) \ - qDebug() << " char '" << c << "' not found"; \ - return false; \ - } \ - ++i; - - -#define SKIP_SPACE \ - while (i < n && src[i] == ' ') \ - ++i; - - int i = *pos; - int j = i; - - // assume "<@" has been parsed outside - //SKIP_CHAR('<'); - //SKIP_CHAR('@'); - - if (tag != QStringRef(&src, i, tag.length())) { - if (0 && debug) - qDebug() << "tag " << tag << " not found at " << i; - return false; - } - - if (debug) - qDebug() << "haystack:" << src << "needle:" << tag << "i:" <<i; - - // skip tag - i += tag.length(); - - // parse stuff like: linkTag("(<@link node=\"([^\"]+)\">).*(</@link>)"); - if (par1) { - SKIP_SPACE; - // read parameter name - j = i; - while (i < n && src[i].isLetter()) - ++i; - if (src[i] == '=') { - if (debug) - qDebug() << "read parameter" << QString(src.data() + j, i - j); - SKIP_CHAR('='); - SKIP_CHAR('"'); - // skip parameter name - j = i; - while (i < n && src[i] != '"') - ++i; - *par1 = QStringRef(&src, j, i - j); - SKIP_CHAR('"'); - SKIP_SPACE; - } else { - if (debug) - qDebug() << "no optional parameter found"; - } - } - SKIP_SPACE; - SKIP_CHAR('>'); - - // find contents up to closing "</@tag> - j = i; - for (; true; ++i) { - if (i + 4 + tag.length() > n) - return false; - if (src[i] != '<') - continue; - if (src[i + 1] != '/') - continue; - if (src[i + 2] != '@') - continue; - if (tag != QStringRef(&src, i + 3, tag.length())) - continue; - if (src[i + 3 + tag.length()] != '>') - continue; - break; - } - - *contents = QStringRef(&src, j, i - j); - - i += tag.length() + 4; - - *pos = i; - if (debug) - qDebug() << " tag " << tag << " found: pos now: " << i; - return true; -#undef SKIP_CHAR -} - static void addLink(const QString &linkTarget, const QStringRef &nestedStuff, QString *res) @@ -2849,7 +2751,7 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, static const QString headerTag("headerfile"); static const QString funcTag("func"); static const QString linkTag("link"); - + // replace all <@link> tags: "(<@link node=\"([^\"]+)\">).*(</@link>)" bool done = false; for (int i = 0, srcSize = src.size(); i < srcSize;) { @@ -2884,6 +2786,7 @@ QString HtmlGenerator::highlightedCode(const QString& markedCode, if (src.at(i) == charLangle && src.at(i + 1) == charAt) { i += 2; if (parseArg(src, funcTag, &i, srcSize, &arg, &par1)) { + const Node* n = marker->resolveTarget(par1.toString(), myTree, relative); diff --git a/tools/qdoc3/pagegenerator.cpp b/tools/qdoc3/pagegenerator.cpp index d5564f7..d331d41 100644 --- a/tools/qdoc3/pagegenerator.cpp +++ b/tools/qdoc3/pagegenerator.cpp @@ -70,12 +70,6 @@ PageGenerator::~PageGenerator() endSubPage(); } -static QRegExp linkTag("(<@link node=\"([^\"]+)\">).*(</@link>)"); -static QRegExp funcTag("(<@func target=\"([^\"]*)\">)(.*)(</@func>)"); -static QRegExp typeTag("(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)(</@\\2>)"); -static QRegExp spanTag("</@(?:comment|preprocessor|string|char)>"); -static QRegExp unknownTag("</?@[^>]*>"); - bool PageGenerator::parseArg(const QString& src, const QString& tag, int* pos, |