From fc90a00874ee01d84237a9b0e0fda706da258fdb Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 25 Mar 2011 12:29:10 +0100 Subject: qdoc: Added default values to config file for DITA Also added the handling of these default values: dita.metadata.default.author = Qt Development Frameworks dita.metadata.default.permissions = all dita.metadata.default.publisher = Nokia dita.metadata.default.copyryear = 2011 dita.metadata.default.copyrholder = Nokia dita.metadata.default.audience = programmer --- src/gui/kernel/qwidget.cpp | 3 +++ tools/qdoc3/config.cpp | 26 +++++++++++++++++++++++++- tools/qdoc3/config.h | 3 +++ tools/qdoc3/ditaxmlgenerator.cpp | 35 +++++++++++++++++++++-------------- tools/qdoc3/ditaxmlgenerator.h | 3 ++- tools/qdoc3/test/qt-project.qdocconf | 7 +++++++ 6 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 18255a1..6a44bcc 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -598,6 +598,9 @@ void QWidget::setAutoFillBackground(bool enabled) \ingroup basicwidgets + \meta {technology} {User Interface} + \meta {platform} {all} + The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a diff --git a/tools/qdoc3/config.cpp b/tools/qdoc3/config.cpp index 08a8187..267a09c 100644 --- a/tools/qdoc3/config.cpp +++ b/tools/qdoc3/config.cpp @@ -329,7 +329,10 @@ QList Config::getRegExpList(const QString& var) const } /*! - This function is slower than it could be. + This function is slower than it could be. What it does is + find all the keys that begin with \a var + dot and return + the matching keys in a set, stripped of the matching prefix + and dot. */ QSet Config::subVars(const QString& var) const { @@ -350,6 +353,27 @@ QSet Config::subVars(const QString& var) const } /*! + Same as subVars(), but in this case we return a string map + with the matching keys (stripped of the prefix \a var and + mapped to their values. The pairs are inserted into \a t + */ +void Config::subVarsAndValues(const QString& var, QStringMap& t) const +{ + QString varDot = var + QLatin1Char('.'); + QMap::ConstIterator v = stringValueMap.begin(); + while (v != stringValueMap.end()) { + if (v.key().startsWith(varDot)) { + QString subVar = v.key().mid(varDot.length()); + int dot = subVar.indexOf(QLatin1Char('.')); + if (dot != -1) + subVar.truncate(dot); + t.insert(subVar,v.value()); + } + ++v; + } +} + +/*! Builds and returns a list of file pathnames for the file type specified by \a filesVar (e.g. "headers" or "sources"). The files are found in the directories specified by diff --git a/tools/qdoc3/config.h b/tools/qdoc3/config.h index 9ebc0f8..767acb1 100644 --- a/tools/qdoc3/config.h +++ b/tools/qdoc3/config.h @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE +typedef QMap QStringMap; + class Config { public: @@ -74,6 +76,7 @@ class Config QRegExp getRegExp(const QString& var) const; QList getRegExpList(const QString& var) const; QSet subVars(const QString& var) const; + void subVarsAndValues(const QString& var, QStringMap& t) const; QStringList getAllFiles(const QString& filesVar, const QString& dirsVar, const QSet &excludedDirs = QSet()); diff --git a/tools/qdoc3/ditaxmlgenerator.cpp b/tools/qdoc3/ditaxmlgenerator.cpp index 018cbc7..4b4f776 100644 --- a/tools/qdoc3/ditaxmlgenerator.cpp +++ b/tools/qdoc3/ditaxmlgenerator.cpp @@ -482,6 +482,7 @@ void DitaXmlGenerator::initializeGenerator(const Config &config) if (naturalLanguage.isEmpty()) naturalLanguage = QLatin1String("en"); + config.subVarsAndValues("dita.metadata.default",metadataDefaults); QSet editionNames = config.subVars(CONFIG_EDITION); QSet::ConstIterator edition = editionNames.begin(); while (edition != editionNames.end()) { @@ -5577,7 +5578,7 @@ bool DitaXmlGenerator::writeMetadataElement(const InnerNode* inner, QStringMap& metaTagMap = const_cast(inner->doc().metaTagMap()); QStringMap::iterator i = metaTagMap.find(ditaTags[t]); if (i == metaTagMap.end()) { - // get the default author, if there is one. + s = metadataDefault(t); } else { s = i.value(); @@ -5610,10 +5611,22 @@ QString DitaXmlGenerator::getMetadataElement(const InnerNode* inner, DitaXmlGene s = i.value(); metaTagMap.erase(i); } + else { + s = metadataDefault(t); + } return s; } /*! + Returns the value of key \a t or an empty string + if \a t is not found in the map. + */ +QString DitaXmlGenerator::metadataDefault(DitaTag t) const +{ + return metadataDefaults.value(ditaTags[t]); +} + +/*! Writes the element for the \a inner node using the \a marker. The element contains the element, plus some others. This @@ -5625,10 +5638,10 @@ QString DitaXmlGenerator::getMetadataElement(const InnerNode* inner, DitaXmlGene \o \o * \o * - \o - \o + \o * + \o * \o - \o + \o * \o \o \o @@ -5661,24 +5674,18 @@ DitaXmlGenerator::writeProlog(const InnerNode* inner, CodeMarker* marker) writeMetadataElement(inner,DT_author); writeMetadataElement(inner,DT_publisher); QString s = getMetadataElement(inner,DT_copyryear); - if (s.isEmpty()) { - s = "2011"; // zzz - } QString t = getMetadataElement(inner,DT_copyrholder); - if (t.isEmpty()) { - t = "Nokia"; // zzz - } writeStartTag(DT_copyright); writeStartTag(DT_copyryear); - xmlWriter().writeAttribute("year",s); + if (!s.isEmpty()) + xmlWriter().writeAttribute("year",s); writeEndTag(); // writeStartTag(DT_copyrholder); - xmlWriter().writeCharacters(t); + if (!s.isEmpty()) + xmlWriter().writeCharacters(t); writeEndTag(); // writeEndTag(); // s = getMetadataElement(inner,DT_permissions); - if (s.isEmpty()) - s = "all"; writeStartTag(DT_permissions); xmlWriter().writeAttribute("view",s); writeEndTag(); // diff --git a/tools/qdoc3/ditaxmlgenerator.h b/tools/qdoc3/ditaxmlgenerator.h index 972688a..c7400bb 100644 --- a/tools/qdoc3/ditaxmlgenerator.h +++ b/tools/qdoc3/ditaxmlgenerator.h @@ -447,7 +447,7 @@ class DitaXmlGenerator : public PageGenerator int leaveSection(); bool inSection() const { return (sectionNestingLevel > 0); } int currentSectionNestingLevel() const { return sectionNestingLevel; } - + QString metadataDefault(DitaTag t) const; private: /* @@ -516,6 +516,7 @@ class DitaXmlGenerator : public PageGenerator static QString ditaTags[]; QStack xmlWriterStack; QStack tagStack; + QStringMap metadataDefaults; }; #define DITAXMLGENERATOR_ADDRESS "address" diff --git a/tools/qdoc3/test/qt-project.qdocconf b/tools/qdoc3/test/qt-project.qdocconf index 2f6ab9d..9c18608 100644 --- a/tools/qdoc3/test/qt-project.qdocconf +++ b/tools/qdoc3/test/qt-project.qdocconf @@ -35,6 +35,13 @@ qhp.Qt.subprojects.examples.title = Tutorials and Examples qhp.Qt.subprojects.examples.indexTitle = Qt Examples qhp.Qt.subprojects.examples.selectors = fake:example +dita.metadata.default.author = Qt Development Frameworks +dita.metadata.default.permissions = all +dita.metadata.default.publisher = Nokia +dita.metadata.default.copyryear = 2011 +dita.metadata.default.copyrholder = Nokia +dita.metadata.default.audience = programmer + language = Cpp headerdirs = $QT_SOURCE_TREE/src \ -- cgit v0.12