Skip to content

Commit

Permalink
QDoc: Introduce a variable to set table of contents depth.
Browse files Browse the repository at this point in the history
-"HTML.tocdepth" variable controls depth value.
-setting to "0" disables table of contents.
-sections 3 and 4 usually don't have descriptive titles
 to warrant their listing in the table of contents.
-table width and CSS (online and offline) don't support wide entries.
-Config class' getInt() function now returns -1 if a variable is
 not set.
-for Qt 5 and projects which use html-config.qdocconf, tocdepth is
 set to "2".
-added variable documentation.

Task-number: QTBUG-38967
Change-Id: Ibd612f5b846ecb9c4b575e7ac11605c6efd2b77c
Reviewed-by: Martin Smith <[email protected]>
Reviewed-by: Venugopal Shivashankar <[email protected]>
Reviewed-by: Sze Howe Koh <[email protected]>
Reviewed-by: Topi Reiniö <[email protected]>
  • Loading branch information
jeromepasion authored and The Qt Project committed Jun 11, 2014
1 parent de1afe4 commit e2a7293
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
2 changes: 2 additions & 0 deletions doc/global/html-config.qdocconf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

HTML.nonavigationbar = "false"

HTML.tocdepth = 2

HTML.extraimages += template/images/arrow_bc.png \
template/images/home.png \
template/images/ico_out.png \
Expand Down
7 changes: 5 additions & 2 deletions src/tools/qdoc/config.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the tools applications of the Qt Toolkit.
Expand Down Expand Up @@ -328,11 +328,14 @@ bool Config::getBool(const QString& var) const
Looks up the configuration variable \a var in the string list
map. Iterates through the string list found, interpreting each
string in the list as an integer and adding it to a total sum.
Returns the sum.
Returns the sum or \c -1 if \a var is not set.
*/
int Config::getInt(const QString& var) const
{
QStringList strs = getStringList(var);
if (strs.isEmpty())
return -1;

QStringList::ConstIterator s = strs.constBegin();
int sum = 0;

Expand Down
9 changes: 8 additions & 1 deletion src/tools/qdoc/doc/qdoc-manual-qdocconf.qdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
Expand Down Expand Up @@ -1331,6 +1331,13 @@
\l qtgui.qdocconf file, and it will copy those specified to the output
directory alongside the HTML pages.

\target HTML.tocdepth
\section1 HTML.tocdepth

The HTML.tocdepth variable defines how many document sections are printed in
the table of contents. Setting tocdepth to \c 0 disables the table of
contents while not setting the variable prints all document sections.

*/

/*!
Expand Down
38 changes: 25 additions & 13 deletions src/tools/qdoc/htmlgenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the tools applications of the Qt Toolkit.
Expand Down Expand Up @@ -169,6 +169,9 @@ void HtmlGenerator::initializeGenerator(const Config &config)
noNavigationBar = config.getBool(HtmlGenerator::format() +
Config::dot +
HTMLGENERATOR_NONAVIGATIONBAR);
tocDepth = config.getInt(HtmlGenerator::format() +
Config::dot +
HTMLGENERATOR_TOCDEPTH);

project = config.getString(CONFIG_PROJECT);

Expand Down Expand Up @@ -2243,6 +2246,10 @@ void HtmlGenerator::generateTableOfContents(const Node *node,
if (toc.isEmpty() && !sections && !node->isModule())
return;

//turn off table of contents if HTML.tocdepth is set to 0
if (tocDepth == 0)
return;

QStringList sectionNumber;
int detailsBase = 0;

Expand Down Expand Up @@ -2324,18 +2331,23 @@ void HtmlGenerator::generateTableOfContents(const Node *node,
sectionNumber.last() = QString::number(sectionNumber.last().toInt() + 1);
}
}
int numAtoms;
Text headingText = Text::sectionHeading(atom);
QString s = headingText.toString();
out() << "<li class=\"level"
<< sectionNumber.size()
<< "\">";
out() << "<a href=\""
<< '#'
<< Doc::canonicalTitle(s)
<< "\">";
generateAtomList(headingText.firstAtom(), node, marker, true, numAtoms);
out() << "</a></li>\n";

//restrict the ToC depth to the one set by the HTML.tocdepth variable or
//print all levels if tocDepth is not set.
if (sectionNumber.size() <= tocDepth || tocDepth < 0) {
int numAtoms;
Text headingText = Text::sectionHeading(atom);
QString s = headingText.toString();
out() << "<li class=\"level"
<< sectionNumber.size()
<< "\">";
out() << "<a href=\""
<< '#'
<< Doc::canonicalTitle(s)
<< "\">";
generateAtomList(headingText.firstAtom(), node, marker, true, numAtoms);
out() << "</a></li>\n";
}
}
while (!sectionNumber.isEmpty()) {
sectionNumber.removeLast();
Expand Down
4 changes: 3 additions & 1 deletion src/tools/qdoc/htmlgenerator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the tools applications of the Qt Toolkit.
Expand Down Expand Up @@ -265,6 +265,7 @@ class HtmlGenerator : public Generator
QString qmltypespage;
QString buildversion;
QString qflagsHref_;
int tocDepth;

public:
static bool debugging_on;
Expand All @@ -278,6 +279,7 @@ class HtmlGenerator : public Generator
#define HTMLGENERATOR_POSTPOSTHEADER "postpostheader"
#define HTMLGENERATOR_NONAVIGATIONBAR "nonavigationbar"
#define HTMLGENERATOR_NOSUBDIRS "nosubdirs"
#define HTMLGENERATOR_TOCDEPTH "tocdepth"


QT_END_NAMESPACE
Expand Down

0 comments on commit e2a7293

Please sign in to comment.