qdoc: Fixed incorrect href attribute values in qdoc

There were two fileBase() functions, but only one
was correct. The wrong one was being called in some
cases. Now there is only one fileBase() function,
which is always called.

Task nr: QTBUG-26591

Change-Id: I2c40e2152a8c7ad1bb9db256ecf1367148f0e7f6
Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
This commit is contained in:
Martin Smith 2012-07-24 14:27:37 +02:00 committed by Qt by Nokia
parent 48d439833a
commit a4cd6ef25d
11 changed files with 99 additions and 105 deletions

View File

@ -284,6 +284,29 @@ QString DitaXmlGenerator::ditaTags[] =
""
};
/*!
Composes a string to be used as an href attribute in DITA
XML. It is composed of the file name and the UUID separated
by a '#'. If this node is a class node, the file name is
taken from this node; if this node is a function node, the
file name is taken from the parent node of this node.
*/
QString DitaXmlGenerator::ditaXmlHref(Node* n)
{
QString href;
if ((n->type() == Node::Function) ||
(n->type() == Node::Property) ||
(n->type() == Node::Variable)) {
href = fileBase(n->parent());
}
else {
href = fileBase(n);
}
if (!href.endsWith(".xml") && !href.endsWith(".dita"))
href += ".dita";
return href + QLatin1Char('#') + n->guid();
}
void DitaXmlGenerator::debugPara(const QString& t)
{
writeStartTag(DT_p);
@ -4218,7 +4241,7 @@ void DitaXmlGenerator::generateIndex(const QString& fileBase,
const QString& url,
const QString& title)
{
tree_->generateIndex(outputDir() + QLatin1Char('/') + fileBase + ".index", url, title);
tree_->generateIndex(outputDir() + QLatin1Char('/') + fileBase + ".index", url, title, this);
}
void DitaXmlGenerator::generateStatus(const Node* node, CodeMarker* marker)
@ -4907,7 +4930,7 @@ void DitaXmlGenerator::writeFunctions(const Section& s,
FunctionNode* rfn = (FunctionNode*)fn->reimplementedFrom();
if (rfn && !rfn->isInternal()) {
writeStartTag(DT_cxxFunctionReimplemented);
xmlWriter().writeAttribute("href",rfn->ditaXmlHref());
xmlWriter().writeAttribute("href",ditaXmlHref(rfn));
writeCharacters(marker->plainFullName(rfn));
writeEndTag(); // </cxxFunctionReimplemented>
}
@ -5299,7 +5322,7 @@ void DitaXmlGenerator::writeProperties(const Section& s,
if (pn->overriddenFrom() != 0) {
PropertyNode* opn = (PropertyNode*)pn->overriddenFrom();
writeStartTag(DT_cxxVariableReimplemented);
xmlWriter().writeAttribute("href",opn->ditaXmlHref());
xmlWriter().writeAttribute("href",ditaXmlHref(opn));
writeCharacters(marker->plainFullName(opn));
writeEndTag(); // </cxxVariableReimplemented>
}
@ -5461,7 +5484,7 @@ void DitaXmlGenerator::writeMacros(const Section& s,
if (fn->reimplementedFrom() != 0) {
FunctionNode* rfn = (FunctionNode*)fn->reimplementedFrom();
writeStartTag(DT_cxxDefineReimplemented);
xmlWriter().writeAttribute("href",rfn->ditaXmlHref());
xmlWriter().writeAttribute("href",ditaXmlHref(rfn));
writeCharacters(marker->plainFullName(rfn));
writeEndTag(); // </cxxDefineReimplemented>
}

View File

@ -503,6 +503,7 @@ private:
void writeTopicrefs(NodeMultiMap* nmm, const QString& navtitle, Node* headingnode = 0);
bool isDuplicate(NodeMultiMap* nmm, const QString& key, Node* node);
void debugPara(const QString& t);
QString ditaXmlHref(Node* n);
private:
/*

View File

@ -497,15 +497,15 @@ QString Generator::fullDocumentLocation(const Node *node, bool subdir)
// The root namespace has no name - check for this before creating
// an attribute containing the location of any documentation.
if (!node->fileBase().isEmpty())
parentName = node->fileBase() + QLatin1Char('.') + currentGenerator()->fileExtension();
if (!fileBase(node).isEmpty())
parentName = fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension();
else
return QString();
}
else if (node->type() == Node::Fake) {
if ((node->subType() == Node::QmlClass) ||
(node->subType() == Node::QmlBasicType)) {
QString fb = node->fileBase();
QString fb = fileBase(node);
if (fb.startsWith(Generator::outputPrefix(QLatin1String("QML"))))
return fb + QLatin1Char('.') + currentGenerator()->fileExtension();
else {
@ -515,13 +515,14 @@ QString Generator::fullDocumentLocation(const Node *node, bool subdir)
mq = mq.toLower() + QLatin1Char('-');
}
return fdl+ Generator::outputPrefix(QLatin1String("QML")) + mq +
node->fileBase() + QLatin1Char('.') + currentGenerator()->fileExtension();
fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension();
}
}
else
parentName = node->fileBase() + QLatin1Char('.') + currentGenerator()->fileExtension();
else {
parentName = fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension();
}
}
else if (node->fileBase().isEmpty())
else if (fileBase(node).isEmpty())
return QString();
Node *parentNode = 0;
@ -534,8 +535,9 @@ QString Generator::fullDocumentLocation(const Node *node, bool subdir)
parentNode = parentNode->parent();
parentName = fullDocumentLocation(parentNode);
}
else
else {
parentName = fullDocumentLocation(node->parent());
}
}
switch (node->type()) {
@ -544,17 +546,13 @@ QString Generator::fullDocumentLocation(const Node *node, bool subdir)
if (parentNode && !parentNode->name().isEmpty()) {
parentName.remove(QLatin1Char('.') + currentGenerator()->fileExtension());
parentName += QLatin1Char('-')
+ node->fileBase().toLower() + QLatin1Char('.') + currentGenerator()->fileExtension();
+ fileBase(node).toLower() + QLatin1Char('.') + currentGenerator()->fileExtension();
} else {
parentName = node->fileBase() + QLatin1Char('.') + currentGenerator()->fileExtension();
parentName = fileBase(node) + QLatin1Char('.') + currentGenerator()->fileExtension();
}
break;
case Node::Function:
{
/*
Functions can be destructors, overloaded, or
have associated properties.
*/
const FunctionNode *functionNode =
static_cast<const FunctionNode *>(node);
@ -569,14 +567,13 @@ QString Generator::fullDocumentLocation(const Node *node, bool subdir)
+ QLatin1Char('-') + QString::number(functionNode->overloadNumber());
else
anchorRef = QLatin1Char('#') + functionNode->name();
}
/*
Use node->name() instead of node->fileBase() as
the latter returns the name in lower-case. For
HTML anchors, we need to preserve the case.
*/
break;
}
/*
Use node->name() instead of fileBase(node) as
the latter returns the name in lower-case. For
HTML anchors, we need to preserve the case.
*/
case Node::Enum:
anchorRef = QLatin1Char('#') + node->name() + "-enum";
break;
@ -604,10 +601,10 @@ QString Generator::fullDocumentLocation(const Node *node, bool subdir)
case Node::Fake:
{
/*
Use node->fileBase() for fake nodes because they are represented
Use fileBase(node) for fake nodes because they are represented
by pages whose file names are lower-case.
*/
parentName = node->fileBase();
parentName = fileBase(node);
parentName.replace(QLatin1Char('/'), QLatin1Char('-')).replace(QLatin1Char('.'), QLatin1Char('-'));
parentName += QLatin1Char('.') + currentGenerator()->fileExtension();
}

View File

@ -89,9 +89,10 @@ public:
virtual void initializeGenerator(const Config &config);
virtual void terminateGenerator();
QString fullDocumentLocation(const Node *node, bool subdir = false);
static const QString& baseDir() { return baseDir_; }
static Generator *currentGenerator() { return currentGenerator_; }
static QString fullDocumentLocation(const Node *node, bool subdir = false);
static Generator *generatorForFormat(const QString& format);
static void initialize(const Config& config);
static const QString& outputDir() { return outDir_; }

View File

@ -52,7 +52,10 @@
QT_BEGIN_NAMESPACE
HelpProjectWriter::HelpProjectWriter(const Config &config, const QString &defaultFileName)
HelpProjectWriter::HelpProjectWriter(const Config &config,
const QString &defaultFileName,
Generator* g)
: gen_(g)
{
// The output directory should already have been checked by the calling
// generator.
@ -211,7 +214,7 @@ QStringList HelpProjectWriter::keywordDetails(const Node *node) const
details << node->name();
details << node->name();
}
details << Generator::fullDocumentLocation(node,true);
details << gen_->fullDocumentLocation(node,true);
return details;
}
@ -271,12 +274,12 @@ bool HelpProjectWriter::generateSection(HelpProject &project,
case Node::Class:
project.keywords.append(keywordDetails(node));
project.files.insert(Generator::fullDocumentLocation(node,true));
project.files.insert(gen_->fullDocumentLocation(node,true));
break;
case Node::Namespace:
project.keywords.append(keywordDetails(node));
project.files.insert(Generator::fullDocumentLocation(node,true));
project.files.insert(gen_->fullDocumentLocation(node,true));
break;
case Node::Enum:
@ -296,7 +299,7 @@ bool HelpProjectWriter::generateSection(HelpProject &project,
details << item.name(); // "name"
details << item.name(); // "id"
}
details << Generator::fullDocumentLocation(node,true);
details << gen_->fullDocumentLocation(node,true);
project.keywords.append(details);
}
}
@ -328,7 +331,7 @@ bool HelpProjectWriter::generateSection(HelpProject &project,
if (node->relates()) {
project.memberStatus[node->relates()].insert(node->status());
project.files.insert(Generator::fullDocumentLocation(node->relates(),true));
project.files.insert(gen_->fullDocumentLocation(node->relates(),true));
} else if (node->parent())
project.memberStatus[node->parent()].insert(node->status());
}
@ -342,7 +345,7 @@ bool HelpProjectWriter::generateSection(HelpProject &project,
// Use the location of any associated enum node in preference
// to that of the typedef.
if (enumNode)
typedefDetails[2] = Generator::fullDocumentLocation(enumNode,true);
typedefDetails[2] = gen_->fullDocumentLocation(enumNode,true);
project.keywords.append(typedefDetails);
}
@ -350,7 +353,7 @@ bool HelpProjectWriter::generateSection(HelpProject &project,
case Node::Variable:
{
QString location = Generator::fullDocumentLocation(node,true);
QString location = gen_->fullDocumentLocation(node,true);
project.files.insert(location.left(location.lastIndexOf(QLatin1Char('#'))));
project.keywords.append(keywordDetails(node));
}
@ -370,35 +373,18 @@ bool HelpProjectWriter::generateSection(HelpProject &project,
QStringList details;
details << keyword->string()
<< keyword->string()
<< Generator::fullDocumentLocation(node,true) +
<< gen_->fullDocumentLocation(node,true) +
QLatin1Char('#') + Doc::canonicalTitle(keyword->string());
project.keywords.append(details);
} else
fakeNode->doc().location().warning(
tr("Bad keyword in %1").arg(Generator::fullDocumentLocation(node,true))
tr("Bad keyword in %1").arg(gen_->fullDocumentLocation(node,true))
);
}
}
project.keywords.append(keywordDetails(node));
}
/*
if (fakeNode->doc().hasTableOfContents()) {
foreach (const Atom *item, fakeNode->doc().tableOfContents()) {
QString title = Text::sectionHeading(item).toString();
if (!title.isEmpty()) {
QStringList details;
details << title
<< title
<< HtmlGenerator::fullDocumentLocation(node,true) +
QLatin1Char('#') + Doc::canonicalTitle(title);
project.keywords.append(details);
} else
fakeNode->doc().location().warning(
tr("Bad contents item in %1").arg(HtmlGenerator::fullDocumentLocation(node,true)));
}
}
*/
project.files.insert(Generator::fullDocumentLocation(node,true));
project.files.insert(gen_->fullDocumentLocation(node,true));
}
break;
}
@ -467,9 +453,9 @@ void HelpProjectWriter::generateSections(HelpProject &project,
}
}
void HelpProjectWriter::generate(const Tree *tre)
void HelpProjectWriter::generate(const Tree *t)
{
this->tree = tre;
this->tree = t;
for (int i = 0; i < projects.size(); ++i)
generateProject(projects[i]);
}
@ -477,7 +463,7 @@ void HelpProjectWriter::generate(const Tree *tre)
void HelpProjectWriter::writeNode(HelpProject &project, QXmlStreamWriter &writer,
const Node *node)
{
QString href = Generator::fullDocumentLocation(node,true);
QString href = gen_->fullDocumentLocation(node,true);
QString objName = node->name();
switch (node->type()) {
@ -628,12 +614,12 @@ void HelpProjectWriter::generateProject(HelpProject &project)
node = tree->findNode(QStringList("index.html"));
QString indexPath;
if (node)
indexPath = Generator::fullDocumentLocation(node,true);
indexPath = gen_->fullDocumentLocation(node,true);
else
indexPath = "index.html";
writer.writeAttribute("ref", indexPath);
writer.writeAttribute("title", project.indexTitle);
project.files.insert(Generator::fullDocumentLocation(rootNode));
project.files.insert(gen_->fullDocumentLocation(rootNode));
generateSections(project, writer, rootNode);
@ -671,7 +657,7 @@ void HelpProjectWriter::generateProject(HelpProject &project)
const FakeNode *page = tree->findFakeNodeByTitle(atom->string());
writer.writeStartElement("section");
QString indexPath = Generator::fullDocumentLocation(page,true);
QString indexPath = gen_->fullDocumentLocation(page,true);
writer.writeAttribute("ref", indexPath);
writer.writeAttribute("title", atom->string());
project.files.insert(indexPath);
@ -696,7 +682,7 @@ void HelpProjectWriter::generateProject(HelpProject &project)
if (!name.isEmpty()) {
writer.writeStartElement("section");
QString indexPath = Generator::fullDocumentLocation(tree->findFakeNodeByTitle(subproject.indexTitle),true);
QString indexPath = gen_->fullDocumentLocation(tree->findFakeNodeByTitle(subproject.indexTitle),true);
writer.writeAttribute("ref", indexPath);
writer.writeAttribute("title", subproject.title);
project.files.insert(indexPath);

View File

@ -52,6 +52,7 @@
QT_BEGIN_NAMESPACE
class Tree;
class Generator;
typedef QPair<QString, const Node*> QStringNodePair;
struct SubProject
@ -85,10 +86,12 @@ struct HelpProject
class HelpProjectWriter
{
public:
HelpProjectWriter(const Config &config, const QString &defaultFileName);
HelpProjectWriter(const Config &config,
const QString &defaultFileName,
Generator* g);
void addExtraFile(const QString &file);
void addExtraFiles(const QSet<QString> &files);
void generate(const Tree *tre);
void generate(const Tree *t);
private:
void generateProject(HelpProject &project);
@ -101,6 +104,7 @@ private:
void readSelectors(SubProject &subproject, const QStringList &selectors);
const Tree *tree;
Generator* gen_;
QString outputDir;
QList<HelpProject> projects;

View File

@ -210,8 +210,8 @@ void HtmlGenerator::initializeGenerator(const Config &config)
codeIndent = config.getInt(CONFIG_CODEINDENT);
helpProjectWriter = new HelpProjectWriter(config,
project.toLower() +
".qhp");
project.toLower() + ".qhp",
this);
// Documentation template handling
headerScripts = config.getString(HtmlGenerator::format() + Config::dot +
@ -3838,7 +3838,7 @@ void HtmlGenerator::generateIndex(const QString &fileBase,
const QString &url,
const QString &title)
{
tree_->generateIndex(outputDir() + QLatin1Char('/') + fileBase + ".index", url, title);
tree_->generateIndex(outputDir() + QLatin1Char('/') + fileBase + ".index", url, title, this);
}
void HtmlGenerator::generateStatus(const Node *node, CodeMarker *marker)
@ -4318,7 +4318,7 @@ void HtmlGenerator::generateManifestFile(QString manifest, QString element)
}
writer.writeStartElement(element);
writer.writeAttribute("name", en->title());
QString docUrl = manifestDir + en->fileBase() + ".html";
QString docUrl = manifestDir + fileBase(en) + ".html";
writer.writeAttribute("docUrl", docUrl);
QStringList proFiles;
foreach (const Node* child, en->childNodes()) {

View File

@ -505,6 +505,7 @@ Node::ThreadSafeness Node::inheritedThreadSafeness() const
return safeness_;
}
#if 0
/*!
Returns the sanitized file name without the path.
If the the file is an html file, the html suffix
@ -520,7 +521,7 @@ QString Node::fileBase() const
base.replace(QLatin1Char(' '), QLatin1Char('-'));
return base.toLower();
}
#endif
/*!
Returns this node's Universally Unique IDentifier as a
QString. Creates the UUID first, if it has not been created.
@ -532,29 +533,6 @@ QString Node::guid() const
return uuid_;
}
/*!
Composes a string to be used as an href attribute in DITA
XML. It is composed of the file name and the UUID separated
by a '#'. If this node is a class node, the file name is
taken from this node; if this node is a function node, the
file name is taken from the parent node of this node.
*/
QString Node::ditaXmlHref()
{
QString href;
if ((type() == Function) ||
(type() == Property) ||
(type() == Variable)) {
href = parent()->fileBase();
}
else {
href = fileBase();
}
if (!href.endsWith(".xml") && !href.endsWith(".dita"))
href += ".dita";
return href + QLatin1Char('#') + guid();
}
/*!
If this node is a QML class node, return a pointer to it.
If it is a child of a QML class node, return a pointer to
@ -2086,6 +2064,7 @@ QmlClassNode* QmlClassNode::lookupQmlTypeNode(const QString& qmid, const QString
return qmlModuleMemberMap_.value(qmid + "::" + name);
}
#if 0
/*!
The base file name for this kind of node has "qml_"
prepended to it.
@ -2096,7 +2075,7 @@ QString QmlClassNode::fileBase() const
{
return Node::fileBase();
}
#endif
/*!
Record the fact that QML class \a base is inherited by
QML class \a sub.

View File

@ -227,9 +227,8 @@ public:
void clearRelated() { relatesTo_ = 0; }
virtual QString fileBase() const;
//virtual QString fileBase() const;
QString guid() const;
QString ditaXmlHref();
QString extractClassName(const QString &string) const;
virtual QString qmlTypeName() const { return name_; }
virtual QString qmlModuleName() const { return qmlModuleName_; }
@ -529,7 +528,7 @@ public:
virtual bool isQmlNode() const { return true; }
virtual bool isQtQuickNode() const { return (qmlModuleName() == QLatin1String("QtQuick")); }
virtual ClassNode* classNode() { return cnode_; }
virtual QString fileBase() const;
//virtual QString fileBase() const;
virtual void setCurrentChild();
virtual void clearCurrentChild();
virtual const ImportList* importList() const { return &importList_; }

View File

@ -1493,7 +1493,7 @@ bool Tree::generateIndexSection(QXmlStreamWriter& writer,
QString href = node->outputSubdirectory();
if (!href.isEmpty())
href.append(QLatin1Char('/'));
href.append(Generator::fullDocumentLocation(node));
href.append(gen_->fullDocumentLocation(node));
writer.writeAttribute("href", href);
if ((node->type() != Node::Fake) && (!node->isQmlNode()))
writer.writeAttribute("location", node->location().fileName());
@ -1928,12 +1928,14 @@ void Tree::generateIndexSections(QXmlStreamWriter& writer,
void Tree::generateIndex(const QString& fileName,
const QString& url,
const QString& title,
Generator* g,
bool generateInternalNodes)
{
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text))
return ;
gen_ = g;
QXmlStreamWriter writer(&file);
writer.setAutoFormatting(true);
writer.writeStartDocument();
@ -2006,7 +2008,7 @@ void Tree::generateTagFileCompounds(QXmlStreamWriter& writer, const InnerNode* i
if (node->type() == Node::Class) {
writer.writeTextElement("name", node->fullDocumentName());
writer.writeTextElement("filename", Generator::fullDocumentLocation(node,true));
writer.writeTextElement("filename", gen_->fullDocumentLocation(node,true));
// Classes contain information about their base classes.
const ClassNode* classNode = static_cast<const ClassNode*>(node);
@ -2024,7 +2026,7 @@ void Tree::generateTagFileCompounds(QXmlStreamWriter& writer, const InnerNode* i
generateTagFileCompounds(writer, static_cast<const InnerNode*>(node));
} else {
writer.writeTextElement("name", node->fullDocumentName());
writer.writeTextElement("filename", Generator::fullDocumentLocation(node,true));
writer.writeTextElement("filename", gen_->fullDocumentLocation(node,true));
// Recurse to write all members.
generateTagFileMembers(writer, static_cast<const InnerNode*>(node));
@ -2143,7 +2145,7 @@ void Tree::generateTagFileMembers(QXmlStreamWriter& writer, const InnerNode* inn
"virtual " + functionNode->returnType());
writer.writeTextElement("name", objName);
QStringList pieces = Generator::fullDocumentLocation(node,true).split(QLatin1Char('#'));
QStringList pieces = gen_->fullDocumentLocation(node,true).split(QLatin1Char('#'));
writer.writeTextElement("anchorfile", pieces[0]);
writer.writeTextElement("anchor", pieces[1]);
@ -2182,7 +2184,7 @@ void Tree::generateTagFileMembers(QXmlStreamWriter& writer, const InnerNode* inn
const PropertyNode* propertyNode = static_cast<const PropertyNode*>(node);
writer.writeAttribute("type", propertyNode->dataType());
writer.writeTextElement("name", objName);
QStringList pieces = Generator::fullDocumentLocation(node,true).split(QLatin1Char('#'));
QStringList pieces = gen_->fullDocumentLocation(node,true).split(QLatin1Char('#'));
writer.writeTextElement("anchorfile", pieces[0]);
writer.writeTextElement("anchor", pieces[1]);
writer.writeTextElement("arglist", "");
@ -2194,7 +2196,7 @@ void Tree::generateTagFileMembers(QXmlStreamWriter& writer, const InnerNode* inn
{
const EnumNode* enumNode = static_cast<const EnumNode*>(node);
writer.writeTextElement("name", objName);
QStringList pieces = Generator::fullDocumentLocation(node).split(QLatin1Char('#'));
QStringList pieces = gen_->fullDocumentLocation(node).split(QLatin1Char('#'));
writer.writeTextElement("anchor", pieces[1]);
writer.writeTextElement("arglist", "");
writer.writeEndElement(); // member
@ -2218,7 +2220,7 @@ void Tree::generateTagFileMembers(QXmlStreamWriter& writer, const InnerNode* inn
else
writer.writeAttribute("type", "");
writer.writeTextElement("name", objName);
QStringList pieces = Generator::fullDocumentLocation(node,true).split(QLatin1Char('#'));
QStringList pieces = gen_->fullDocumentLocation(node,true).split(QLatin1Char('#'));
writer.writeTextElement("anchorfile", pieces[0]);
writer.writeTextElement("anchor", pieces[1]);
writer.writeTextElement("arglist", "");

View File

@ -52,6 +52,7 @@
QT_BEGIN_NAMESPACE
class Generator;
class QStringList;
class TreePrivate;
@ -148,6 +149,7 @@ public:
void generateIndex(const QString &fileName,
const QString &url,
const QString &title,
Generator* g,
bool generateInternalNodes = false);
void generateTagFileCompounds(QXmlStreamWriter &writer,
const InnerNode *inner);
@ -155,7 +157,6 @@ public:
const InnerNode *inner);
void generateTagFile(const QString &fileName);
void addExternalLink(const QString &url, const Node *relative);
QString fullDocumentLocation(const Node *node) const;
void resolveQmlInheritance();
private:
@ -173,6 +174,7 @@ private:
private:
NamespaceNode roo;
QString vers;
Generator* gen_;
TreePrivate *priv;
};