qdoc: Merge PageGenerator into Generator class.

This change also sorts all functions in Generator by alphabet and moves
the implementation of the GenerateQmlInheritedBy function to the
Generator class, since the implementation in both the DITA and HTML
generators was the same.

Task-number: QTBUG-24833
Change-Id: I44588079159e03b7ff7549e5478babb1aabdaf1b
Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
bb10
Casper van Donderen 2012-03-17 19:44:49 +01:00 committed by Qt by Nokia
parent c2e8db5841
commit 5939cd33af
9 changed files with 1540 additions and 1732 deletions

View File

@ -43,6 +43,11 @@
ditaxmlgenerator.cpp
*/
#include <QDebug>
#include <QList>
#include <qiterator.h>
#include <QTextCodec>
#include <QUuid>
#include "codemarker.h"
#include "codeparser.h"
#include "ditaxmlgenerator.h"
@ -51,11 +56,6 @@
#include "separator.h"
#include "tree.h"
#include <ctype.h>
#include <qdebug.h>
#include <qlist.h>
#include <qiterator.h>
#include <qtextcodec.h>
#include <QUuid>
QT_BEGIN_NAMESPACE
@ -636,7 +636,7 @@ void DitaXmlGenerator::generateTree(const Tree *tree)
findAllNamespaces(tree->root());
findAllSince(tree->root());
PageGenerator::generateTree(tree);
Generator::generateTree(tree);
writeDitaMap(tree);
}
@ -3816,7 +3816,7 @@ QString DitaXmlGenerator::protect(const QString& string, const QString& ) //outp
QString DitaXmlGenerator::fileBase(const Node* node) const
{
QString result;
result = PageGenerator::fileBase(node);
result = Generator::fileBase(node);
#if 0
if (!node->isInnerNode()) {
switch (node->status()) {
@ -3898,7 +3898,7 @@ QString DitaXmlGenerator::fileName(const Node* node)
if (static_cast<const FakeNode*>(node)->subType() == Node::Image)
return node->name();
}
return PageGenerator::fileName(node);
return Generator::fileName(node);
}
QString DitaXmlGenerator::linkForNode(const Node* node, const Node* relative)
@ -4162,7 +4162,7 @@ const Node* DitaXmlGenerator::findNodeForTarget(const QString& target,
const QPair<QString,QString> DitaXmlGenerator::anchorForNode(const Node* node)
{
QPair<QString,QString> anchorPair;
anchorPair.first = PageGenerator::fileName(node);
anchorPair.first = Generator::fileName(node);
if (node->type() == Node::Fake) {
const FakeNode *fakeNode = static_cast<const FakeNode*>(node);
anchorPair.second = fakeNode->title();
@ -4593,26 +4593,6 @@ void DitaXmlGenerator::generateQmlInherits(const QmlClassNode* qcn, CodeMarker*
}
}
/*!
Output the "Inherit by" list for the QML element,
if it is inherited by any other elements.
*/
void DitaXmlGenerator::generateQmlInheritedBy(const QmlClassNode* qcn,
CodeMarker* marker)
{
if (qcn) {
NodeList subs;
QmlClassNode::subclasses(qcn->name(),subs);
if (!subs.isEmpty()) {
Text text;
text << Atom::ParaLeft << "Inherited by ";
appendSortedQmlNames(text,qcn,subs,marker);
text << Atom::ParaRight;
generateText(text, qcn, marker);
}
}
}
/*!
Output the "[Xxx instantiates the C++ class QmlGraphicsXxx]"
line for the QML element, if there should be one.
@ -5559,7 +5539,7 @@ void DitaXmlGenerator::writePropertyParameter(const QString& tag, const NodeList
void DitaXmlGenerator::beginSubPage(const InnerNode* node,
const QString& fileName)
{
PageGenerator::beginSubPage(node,fileName);
Generator::beginSubPage(node,fileName);
(void) lookupGuidMap(fileName);
QXmlStreamWriter* writer = new QXmlStreamWriter(out().device());
xmlWriterStack.push(writer);
@ -5580,7 +5560,7 @@ void DitaXmlGenerator::endSubPage()
qDebug() << "Missing </section> in" << outFileName() << sectionNestingLevel;
xmlWriter().writeEndDocument();
delete xmlWriterStack.pop();
PageGenerator::endSubPage();
Generator::endSubPage();
}
/*!

View File

@ -47,14 +47,14 @@
#include <QXmlStreamWriter>
#include "codemarker.h"
#include "config.h"
#include "pagegenerator.h"
#include "generator.h"
QT_BEGIN_NAMESPACE
typedef QMap<QString, QString> GuidMap;
typedef QMap<QString, GuidMap*> GuidMaps;
class DitaXmlGenerator : public PageGenerator
class DitaXmlGenerator : public Generator
{
public:
enum SinceType {
@ -381,7 +381,6 @@ private:
const InnerNode* relative,
CodeMarker* marker);
void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInheritedBy(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInstantiates(const QmlClassNode* qcn, CodeMarker* marker);
void generateInstantiatedBy(const ClassNode* cn, CodeMarker* marker);

File diff suppressed because it is too large Load Diff

View File

@ -46,22 +46,23 @@
#ifndef GENERATOR_H
#define GENERATOR_H
#include <qlist.h>
#include <qmap.h>
#include <qregexp.h>
#include <qstring.h>
#include <qstringlist.h>
#include <QList>
#include <QMap>
#include <QRegExp>
#include <QString>
#include <QStringList>
#include <QTextStream>
#include "node.h"
#include "text.h"
QT_BEGIN_NAMESPACE
typedef QMap<QString, NodeMap> NewClassMaps;
typedef QMap<QString, NodeMultiMap> NewSinceMaps;
typedef QMap<QString, const Node*> NodeMap;
typedef QMultiMap<QString, Node*> NodeMultiMap;
typedef QMap<QString, NodeMultiMap> NewSinceMaps;
typedef QMap<Node*, NodeMultiMap> ParentMaps;
typedef QMap<QString, NodeMap> NewClassMaps;
class ClassNode;
class Config;
@ -80,87 +81,124 @@ public:
Generator();
virtual ~Generator();
virtual bool canHandleFormat(const QString &format) { return format == this->format(); }
virtual QString format() = 0;
virtual void generateTree(const Tree *tree);
virtual void initializeGenerator(const Config &config);
virtual void terminateGenerator();
virtual QString format() = 0;
virtual bool canHandleFormat(const QString &format) { return format == this->format(); }
virtual void generateTree(const Tree *tree) = 0;
static void initialize(const Config& config);
static void terminate();
static Generator *generatorForFormat(const QString& format);
static const QString& outputDir() { return outDir_; }
static const QString& baseDir() { return baseDir_; }
static Generator *generatorForFormat(const QString& format);
static void initialize(const Config& config);
static const QString& outputDir() { return outDir_; }
static void terminate();
protected:
virtual void startText(const Node *relative, CodeMarker *marker);
virtual void beginSubPage(const InnerNode* node, const QString& fileName);
virtual void endSubPage();
virtual void endText(const Node *relative, CodeMarker *marker);
virtual QString fileBase(const Node* node) const;
virtual QString fileExtension(const Node* node) const = 0;
virtual QString fullName(const Node *node,
const Node *relative,
CodeMarker *marker) const;
virtual void generateAlsoList(const Node *node, CodeMarker *marker);
virtual int generateAtom(const Atom *atom,
const Node *relative,
CodeMarker *marker);
virtual void generateBody(const Node *node, CodeMarker *marker);
virtual void generateClassLikeNode(const InnerNode *inner, CodeMarker *marker);
virtual void generateFakeNode(const FakeNode *fake, CodeMarker *marker);
virtual bool generateText(const Text& text,
const Node *relative,
CodeMarker *marker);
virtual void generateInheritedBy(const ClassNode *classe,
CodeMarker *marker);
virtual void generateInherits(const ClassNode *classe,
CodeMarker *marker);
virtual void generateInnerNode(const InnerNode *node);
virtual void generateMaintainerList(const InnerNode* node, CodeMarker* marker);
virtual void generateQmlInheritedBy(const QmlClassNode* qcn, CodeMarker* marker);
virtual void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
virtual bool generateQmlText(const Text& text,
const Node *relative,
CodeMarker *marker,
const QString& qmlName);
virtual void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
virtual void generateBody(const Node *node, CodeMarker *marker);
virtual void generateAlsoList(const Node *node, CodeMarker *marker);
virtual void generateMaintainerList(const InnerNode* node, CodeMarker* marker);
virtual void generateInherits(const ClassNode *classe,
CodeMarker *marker);
virtual void generateInheritedBy(const ClassNode *classe,
CodeMarker *marker);
virtual bool generateText(const Text& text,
const Node *relative,
CodeMarker *marker);
virtual QString imageFileName(const Node *relative, const QString& fileBase);
virtual QString outFileName() { return QString(); }
virtual int skipAtoms(const Atom *atom, Atom::Type type) const;
virtual void startText(const Node *relative, CodeMarker *marker);
virtual QString typeString(const Node *node);
void generateThreadSafeness(const Node *node, CodeMarker *marker);
void generateSince(const Node *node, CodeMarker *marker);
void generateStatus(const Node *node, CodeMarker *marker);
static bool matchAhead(const Atom *atom, Atom::Type expectedAtomType);
static QString outputPrefix(const QString &nodeType);
static void singularPlural(Text& text, const NodeList& nodes);
static void supplementAlsoList(const Node *node, QList<Text> &alsoList);
static QString trimmedTrailing(const QString &string);
static QString sinceTitles[];
QString fileName(const Node* node) const;
void findAllSince(const InnerNode *node);
QMap<QString, QString> &formattingLeftMap();
QMap<QString, QString> &formattingRightMap();
const Atom* generateAtomList(const Atom *atom,
const Node *relative,
CodeMarker *marker,
bool generate,
int& numGeneratedAtoms);
void generateExampleFiles(const FakeNode *fake, CodeMarker *marker);
void generateFileList(const FakeNode* fake,
CodeMarker* marker,
Node::SubType subtype,
const QString& tag);
void generateExampleFiles(const FakeNode *fake, CodeMarker *marker);
virtual int skipAtoms(const Atom *atom, Atom::Type type) const;
virtual QString fullName(const Node *node,
const Node *relative,
CodeMarker *marker) const;
virtual QString outFileName() { return QString(); }
QString indent(int level, const QString& markedCode);
QString plainCode(const QString& markedCode);
virtual QString typeString(const Node *node);
virtual QString imageFileName(const Node *relative, const QString& fileBase);
void setImageFileExtensions(const QStringList& extensions);
void unknownAtom(const Atom *atom);
QMap<QString, QString> &formattingLeftMap();
QMap<QString, QString> &formattingRightMap();
QMap<QString, QStringList> editionModuleMap;
QMap<QString, QStringList> editionGroupMap;
static QString trimmedTrailing(const QString &string);
static bool matchAhead(const Atom *atom, Atom::Type expectedAtomType);
static void supplementAlsoList(const Node *node, QList<Text> &alsoList);
static QString outputPrefix(const QString &nodeType);
void generateSince(const Node *node, CodeMarker *marker);
void generateStatus(const Node *node, CodeMarker *marker);
void generateThreadSafeness(const Node *node, CodeMarker *marker);
QString getMetadataElement(const InnerNode* inner, const QString& t);
QStringList getMetadataElements(const InnerNode* inner, const QString& t);
void findAllSince(const InnerNode *node);
QString indent(int level, const QString& markedCode);
QTextStream& out();
bool parseArg(const QString& src,
const QString& tag,
int* pos,
int n,
QStringRef* contents,
QStringRef* par1 = 0,
bool debug = false);
QString plainCode(const QString& markedCode);
void setImageFileExtensions(const QStringList& extensions);
void unknownAtom(const Atom *atom);
QList<NameCollisionNode*> collisionNodes;
QMap<QString, QStringList> editionGroupMap;
QMap<QString, QStringList> editionModuleMap;
QString naturalLanguage;
QTextCodec* outputCodec;
QString outputEncoding;
QStack<QTextStream*> outStreamStack;
NewClassMaps newClassMaps;
NewClassMaps newQmlClassMaps;
NewSinceMaps newSinceMaps;
private:
void generateReimplementedFrom(const FunctionNode *func,
CodeMarker *marker);
static QString baseDir_;
static QStringList exampleDirs;
static QStringList exampleImgExts;
static QMap<QString, QMap<QString, QString> > fmtLeftMaps;
static QMap<QString, QMap<QString, QString> > fmtRightMaps;
static QList<Generator *> generators;
static QStringList imageDirs;
static QStringList imageFiles;
static QMap<QString, QStringList> imgFileExts;
static QString project;
static QString outDir_;
static QSet<QString> outputFormats;
static QHash<QString, QString> outputPrefixes;
static QStringList scriptDirs;
static QStringList scriptFiles;
static QStringList styleDirs;
static QStringList styleFiles;
void appendFullName(Text& text,
const Node *apparentNode,
const Node *relative,
@ -178,42 +216,18 @@ private:
const ClassNode *classe,
const QList<RelatedClass> &classes,
CodeMarker *marker);
protected:
void appendSortedQmlNames(Text& text,
const Node* base,
const NodeList& subs,
CodeMarker *marker);
void generateReimplementedFrom(const FunctionNode *func,
CodeMarker *marker);
static QString sinceTitles[];
NewSinceMaps newSinceMaps;
NewClassMaps newClassMaps;
NewClassMaps newQmlClassMaps;
private:
QString amp;
QString lt;
QString gt;
QString lt;
QString quot;
QRegExp tag;
static QList<Generator *> generators;
static QMap<QString, QMap<QString, QString> > fmtLeftMaps;
static QMap<QString, QMap<QString, QString> > fmtRightMaps;
static QMap<QString, QStringList> imgFileExts;
static QSet<QString> outputFormats;
static QStringList imageFiles;
static QStringList imageDirs;
static QStringList exampleDirs;
static QStringList exampleImgExts;
static QStringList scriptFiles;
static QStringList scriptDirs;
static QStringList styleFiles;
static QStringList styleDirs;
static QString outDir_;
static QString baseDir_;
static QString project;
static QHash<QString, QString> outputPrefixes;
};
QT_END_NAMESPACE

View File

@ -273,7 +273,7 @@ void HtmlGenerator::generateTree(const Tree *tree)
findAllNamespaces(tree->root());
findAllSince(tree->root());
PageGenerator::generateTree(tree);
Generator::generateTree(tree);
reportOrphans(tree->root());
generateDisambiguationPages();
@ -1375,7 +1375,7 @@ void HtmlGenerator::generateDisambiguationPages()
for (int i=0; i<collisionNodes.size(); ++i) {
NameCollisionNode* ncn = collisionNodes.at(i);
ncn->clearCurrentChild();
beginSubPage(ncn, PageGenerator::fileName(ncn));
beginSubPage(ncn, Generator::fileName(ncn));
QString fullTitle = "Name Collision: " + ncn->fullTitle();
QString htmlTitle = fullTitle;
CodeMarker* marker = CodeMarker::markerForFileName(ncn->location().filePath());
@ -3270,7 +3270,7 @@ QString HtmlGenerator::fileBase(const Node *node) const
{
QString result;
result = PageGenerator::fileBase(node);
result = Generator::fileBase(node);
if (!node->isInnerNode()) {
switch (node->status()) {
@ -3295,7 +3295,7 @@ QString HtmlGenerator::fileName(const Node *node)
if (static_cast<const FakeNode *>(node)->subType() == Node::Image)
return node->name();
}
return PageGenerator::fileName(node);
return Generator::fileName(node);
}
QString HtmlGenerator::refForNode(const Node *node)
@ -3719,7 +3719,7 @@ const QPair<QString,QString> HtmlGenerator::anchorForNode(const Node *node)
{
QPair<QString,QString> anchorPair;
anchorPair.first = PageGenerator::fileName(node);
anchorPair.first = Generator::fileName(node);
if (node->type() == Node::Fake) {
const FakeNode *fakeNode = static_cast<const FakeNode*>(node);
anchorPair.second = fakeNode->title();
@ -4227,25 +4227,6 @@ void HtmlGenerator::generateQmlInherits(const QmlClassNode* qcn, CodeMarker* mar
}
}
/*!
Output the "Inherit by" list for the QML element,
if it is inherited by any other elements.
*/
void HtmlGenerator::generateQmlInheritedBy(const QmlClassNode* qcn, CodeMarker* marker)
{
if (qcn) {
NodeList subs;
QmlClassNode::subclasses(qcn->name(),subs);
if (!subs.isEmpty()) {
Text text;
text << Atom::ParaLeft << "Inherited by ";
appendSortedQmlNames(text,qcn,subs,marker);
text << Atom::ParaRight;
generateText(text, qcn, marker);
}
}
}
/*!
Output the "[Xxx instantiates the C++ class QmlGraphicsXxx]"
line for the QML element, if there should be one.
@ -4332,7 +4313,7 @@ bool HtmlGenerator::generatePageElement(QXmlStreamWriter& writer,
QString url = node->outputSubdirectory();
if (!url.isEmpty())
url.append(QLatin1Char('/'));
url.append(PageGenerator::fileName(node));
url.append(Generator::fileName(node));
writer.writeStartElement("page");
@ -5042,7 +5023,7 @@ QXmlStreamWriter& HtmlGenerator::xmlWriter()
*/
void HtmlGenerator::beginDitamapPage(const InnerNode* node, const QString& fileName)
{
PageGenerator::beginSubPage(node,fileName);
Generator::beginSubPage(node,fileName);
QXmlStreamWriter* writer = new QXmlStreamWriter(out().device());
xmlWriterStack.push(writer);
writer->setAutoFormatting(true);
@ -5061,7 +5042,7 @@ void HtmlGenerator::endDitamapPage()
{
xmlWriter().writeEndDocument();
delete xmlWriterStack.pop();
PageGenerator::endSubPage();
Generator::endSubPage();
}
/*!

View File

@ -46,18 +46,18 @@
#ifndef HTMLGENERATOR_H
#define HTMLGENERATOR_H
#include <qmap.h>
#include <qregexp.h>
#include <QMap>
#include <QRegExp>
#include <QXmlStreamWriter>
#include "codemarker.h"
#include "config.h"
#include "pagegenerator.h"
#include "generator.h"
QT_BEGIN_NAMESPACE
class HelpProjectWriter;
class HtmlGenerator : public PageGenerator
class HtmlGenerator : public Generator
{
public:
enum SinceType {
@ -180,7 +180,6 @@ private:
const InnerNode *relative,
CodeMarker *marker);
void generateQmlInherits(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInheritedBy(const QmlClassNode* qcn, CodeMarker* marker);
void generateQmlInstantiates(const QmlClassNode* qcn, CodeMarker* marker);
void generateInstantiatedBy(const ClassNode* cn, CodeMarker* marker);

View File

@ -1,389 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/*
pagegenerator.cpp
*/
#include <qfile.h>
#include <qfileinfo.h>
#include <qdebug.h>
#include "codemarker.h"
#include "pagegenerator.h"
#include "tree.h"
QT_BEGIN_NAMESPACE
/*!
Nothing to do in the constructor.
*/
PageGenerator::PageGenerator()
: outputCodec(0)
{
// nothing.
}
/*!
The destructor
*/
PageGenerator::~PageGenerator()
{
while (!outStreamStack.isEmpty())
endSubPage();
}
bool PageGenerator::parseArg(const QString& src,
const QString& tag,
int* pos,
int n,
QStringRef* contents,
QStringRef* par1,
bool debug)
{
#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
}
/*!
This function is recursive.
*/
void PageGenerator::generateTree(const Tree *tree)
{
generateInnerNode(tree->root());
}
QString PageGenerator::fileBase(const Node *node) const
{
if (node->relates())
node = node->relates();
else if (!node->isInnerNode())
node = node->parent();
if (node->subType() == Node::QmlPropertyGroup) {
node = node->parent();
}
QString base = node->doc().baseName();
if (!base.isEmpty())
return base;
const Node *p = node;
forever {
const Node *pp = p->parent();
base.prepend(p->name());
if (!p->qmlModuleIdentifier().isEmpty())
base.prepend(p->qmlModuleIdentifier()+QChar('-'));
/*
To avoid file name conflicts in the html directory,
we prepend a prefix (by default, "qml-") to the file name of QML
element doc files.
*/
if ((p->subType() == Node::QmlClass) ||
(p->subType() == Node::QmlBasicType)) {
base.prepend(outputPrefix(QLatin1String("QML")));
}
if (!pp || pp->name().isEmpty() || pp->type() == Node::Fake)
break;
base.prepend(QLatin1Char('-'));
p = pp;
}
if (node->type() == Node::Fake) {
if (node->subType() == Node::Collision) {
const NameCollisionNode* ncn = static_cast<const NameCollisionNode*>(node);
if (ncn->currentChild())
return fileBase(ncn->currentChild());
base.prepend("collision-");
}
#ifdef QDOC2_COMPAT
if (base.endsWith(".html"))
base.truncate(base.length() - 5);
#endif
}
// the code below is effectively equivalent to:
// base.replace(QRegExp("[^A-Za-z0-9]+"), " ");
// base = base.trimmed();
// base.replace(QLatin1Char(' '), QLatin1Char('-'));
// base = base.toLower();
// as this function accounted for ~8% of total running time
// we optimize a bit...
QString res;
// +5 prevents realloc in fileName() below
res.reserve(base.size() + 5);
bool begun = false;
for (int i = 0; i != base.size(); ++i) {
QChar c = base.at(i);
uint u = c.unicode();
if (u >= 'A' && u <= 'Z')
u -= 'A' - 'a';
if ((u >= 'a' && u <= 'z') || (u >= '0' && u <= '9')) {
res += QLatin1Char(u);
begun = true;
}
else if (begun) {
res += QLatin1Char('-');
begun = false;
}
}
while (res.endsWith(QLatin1Char('-')))
res.chop(1);
return res;
}
/*!
If the \a node has a URL, return the URL as the file name.
Otherwise, construct the file name from the fileBase() and
the fileExtension(), and return the constructed name.
*/
QString PageGenerator::fileName(const Node* node) const
{
if (!node->url().isEmpty())
return node->url();
QString name = fileBase(node);
name += QLatin1Char('.');
name += fileExtension(node);
return name;
}
/*!
Return the current output file name.
*/
QString PageGenerator::outFileName()
{
return QFileInfo(static_cast<QFile*>(out().device())->fileName()).fileName();
}
/*!
Creates the file named \a fileName in the output directory.
Attaches a QTextStream to the created file, which is written
to all over the place using out().
*/
void PageGenerator::beginSubPage(const InnerNode* node, const QString& fileName)
{
QString path = outputDir() + QLatin1Char('/');
if (!node->outputSubdirectory().isEmpty())
path += node->outputSubdirectory() + QLatin1Char('/');
path += fileName;
QFile* outFile = new QFile(path);
if (!outFile->open(QFile::WriteOnly))
node->location().fatal(tr("Cannot open output file '%1'").arg(outFile->fileName()));
QTextStream* out = new QTextStream(outFile);
if (outputCodec)
out->setCodec(outputCodec);
outStreamStack.push(out);
const_cast<InnerNode*>(node)->setOutputFileName(fileName);
}
/*!
Flush the text stream associated with the subpage, and
then pop it off the text stream stack and delete it.
This terminates output of the subpage.
*/
void PageGenerator::endSubPage()
{
outStreamStack.top()->flush();
delete outStreamStack.top()->device();
delete outStreamStack.pop();
}
/*!
Used for writing to the current output stream. Returns a
reference to the crrent output stream, which is then used
with the \c {<<} operator for writing.
*/
QTextStream &PageGenerator::out()
{
return *outStreamStack.top();
}
/*!
Recursive writing of HTML files from the root \a node.
\note NameCollisionNodes are skipped here and processed
later. See HtmlGenerator::generateDisambiguationPages()
for more on this.
*/
void
PageGenerator::generateInnerNode(const InnerNode* node)
{
if (!node->url().isNull())
return;
if (node->type() == Node::Fake) {
const FakeNode *fakeNode = static_cast<const FakeNode *>(node);
if (fakeNode->subType() == Node::ExternalPage)
return;
if (fakeNode->subType() == Node::Image)
return;
if (fakeNode->subType() == Node::QmlPropertyGroup)
return;
if (fakeNode->subType() == Node::Page) {
if (node->count() > 0)
qDebug("PAGE %s HAS CHILDREN", qPrintable(fakeNode->title()));
}
}
/*
Obtain a code marker for the source file.
*/
CodeMarker *marker = CodeMarker::markerForFileName(node->location().filePath());
if (node->parent() != 0) {
/*
Skip name collision nodes here and process them
later in generateDisambiguationPages(). Each one
is appended to a list for later.
*/
if ((node->type() == Node::Fake) && (node->subType() == Node::Collision)) {
const NameCollisionNode* ncn = static_cast<const NameCollisionNode*>(node);
collisionNodes.append(const_cast<NameCollisionNode*>(ncn));
}
else {
beginSubPage(node, fileName(node));
if (node->type() == Node::Namespace || node->type() == Node::Class) {
generateClassLikeNode(node, marker);
}
else if (node->type() == Node::Fake) {
generateFakeNode(static_cast<const FakeNode *>(node), marker);
}
endSubPage();
}
}
NodeList::ConstIterator c = node->childNodes().begin();
while (c != node->childNodes().end()) {
if ((*c)->isInnerNode() && (*c)->access() != Node::Private) {
generateInnerNode((const InnerNode *) *c);
}
++c;
}
}
QT_END_NAMESPACE

View File

@ -1,99 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/*
pagegenerator.h
*/
#ifndef PAGEGENERATOR_H
#define PAGEGENERATOR_H
#include <QStack>
#include <qtextstream.h>
#include "generator.h"
#include "location.h"
QT_BEGIN_NAMESPACE
class QTextCodec;
class ClassNode;
class InnerNode;
class NamespaceNode;
class NameCollisionNode;
class PageGenerator : public Generator
{
public:
PageGenerator();
~PageGenerator();
virtual void generateTree(const Tree *tree);
virtual void generateDisambiguationPages() { }
protected:
virtual QString fileBase(const Node* node) const;
virtual QString fileExtension(const Node* node) const = 0;
QString fileName(const Node* node) const;
QString outFileName();
virtual void beginSubPage(const InnerNode* node, const QString& fileName);
virtual void endSubPage();
virtual void generateInnerNode(const InnerNode *node);
QTextStream& out();
QString naturalLanguage;
QString outputEncoding;
QTextCodec* outputCodec;
bool parseArg(const QString& src,
const QString& tag,
int* pos,
int n,
QStringRef* contents,
QStringRef* par1 = 0,
bool debug = false);
protected:
QStack<QTextStream*> outStreamStack;
QList<NameCollisionNode*> collisionNodes;
};
QT_END_NAMESPACE
#endif

View File

@ -39,7 +39,6 @@ HEADERS += atom.h \
location.h \
node.h \
openedlist.h \
pagegenerator.h \
plaincodemarker.h \
puredocparser.h \
quoter.h \
@ -65,7 +64,6 @@ SOURCES += atom.cpp \
main.cpp \
node.cpp \
openedlist.cpp \
pagegenerator.cpp \
plaincodemarker.cpp \
puredocparser.cpp \
quoter.cpp \