tools/qdoc3/generator.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tools/qdoc3/generator.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tools/qdoc3/generator.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -65,6 +65,8 @@
 QSet<QString> Generator::outputFormats;
 QStringList Generator::imageFiles;
 QStringList Generator::imageDirs;
+QStringList Generator::exampleDirs;
+QStringList Generator::exampleImgExts;
 QString Generator::outDir;
 QString Generator::project;
 
@@ -120,12 +122,19 @@
         if (!dirInfo.mkdir(outDir + "/images"))
             config.lastLocation().fatal(tr("Cannot create output directory '%1'")
                                         .arg(outDir + "/images"));
+        if (!dirInfo.mkdir(outDir + "/images/used-in-examples"))
+            config.lastLocation().fatal(tr("Cannot create output directory '%1'")
+                                        .arg(outDir + "/images/used-in-examples"));
     }
 
     imageFiles = config.getStringList(CONFIG_IMAGES);
     imageDirs = config.getStringList(CONFIG_IMAGEDIRS);
+    exampleDirs = config.getStringList(CONFIG_EXAMPLEDIRS);
+    exampleImgExts = config.getStringList(CONFIG_EXAMPLES + Config::dot +
+                                          CONFIG_IMAGEEXTENSIONS);
 
-    QString imagesDotFileExtensions = CONFIG_IMAGES + Config::dot + CONFIG_FILEEXTENSIONS;
+    QString imagesDotFileExtensions =
+        CONFIG_IMAGES + Config::dot + CONFIG_FILEEXTENSIONS;
     QSet<QString> formats = config.subVars(imagesDotFileExtensions);
     QSet<QString>::ConstIterator f = formats.begin();
     while (f != formats.end()) {
@@ -138,14 +147,15 @@
     while (g != generators.end()) {
         if (outputFormats.contains((*g)->format())) {
             (*g)->initializeGenerator(config);
-            QStringList extraImages = config.getStringList(CONFIG_EXTRAIMAGES +
-                                                           Config::dot +
-                                                           (*g)->format());
+            QStringList extraImages =
+                config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format());
             QStringList::ConstIterator e = extraImages.begin();
             while (e != extraImages.end()) {
                 QString userFriendlyFilePath;
                 QString filePath = Config::findFile(config.lastLocation(),
-                                                    imageFiles, imageDirs, *e,
+                                                    imageFiles,
+                                                    imageDirs,
+                                                    *e,
                                                     imgFileExts[(*g)->format()],
                                                     userFriendlyFilePath);
                 if (!filePath.isEmpty())
@@ -322,7 +332,7 @@
         const FakeNode *fake = static_cast<const FakeNode *>(node);
         if (fake->subType() == Node::Example)
             generateExampleFiles(fake, marker);
-        else if (fake->subType() == Node::File)
+        else if ((fake->subType() == Node::File) || (fake->subType() == Node::Image))
             quiet = true;
     }
 
@@ -529,32 +539,107 @@
     }
 }
 
+/*!
+  This function is called when the documentation for an
+  example is being formatted. It outputs the list of source
+  files comprising the example, and the list of images used
+  by the example. The images are copied into a subtree of
+  \c{...doc/html/images/used-in-examples/...} 
+ */
+void Generator::generateFileList(const FakeNode* fake,
+                                 CodeMarker* marker,
+                                 Node::SubType subtype,
+                                 const QString& tag)
+{
+    int count = 0;
+    Text text;
+    OpenedList openedList(OpenedList::Bullet);
+
+    text << Atom::ParaLeft << tag << Atom::ParaRight
+         << Atom(Atom::ListLeft, openedList.styleString());
+
+    foreach (const Node* child, fake->childNodes()) {
+        if (child->subType() == subtype) {
+            ++count;
+            QString file = child->name();
+            if (subtype == Node::Image) {
+                if (!file.isEmpty()) {
+                    QDir dirInfo;
+                    QString userFriendlyFilePath;
+                    QString srcPath = Config::findFile(fake->location(),
+                                                       QStringList(),
+                                                       exampleDirs,
+                                                       file,
+                                                       exampleImgExts,
+                                                       userFriendlyFilePath);
+                    userFriendlyFilePath.truncate(userFriendlyFilePath.lastIndexOf('/'));
+
+                    QString imgOutDir = outDir + "/images/used-in-examples/" + userFriendlyFilePath;
+                    if (!dirInfo.mkpath(imgOutDir))
+                        fake->location().fatal(tr("Cannot create output directory '%1'")
+                                               .arg(imgOutDir));
+
+                    QString imgOutName = Config::copyFile(fake->location(),
+                                                          srcPath,
+                                                          file,
+                                                          imgOutDir);
+                }
+
+            }
+
+            openedList.next();
+            text << Atom(Atom::ListItemNumber, openedList.numberString())
+                 << Atom(Atom::ListItemLeft, openedList.styleString())
+                 << Atom::ParaLeft
+                 << Atom(Atom::Link, file)
+                 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
+                 << file
+                 << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK)
+                 << Atom::ParaRight
+                 << Atom(Atom::ListItemRight, openedList.styleString());
+        }
+    }
+    text << Atom(Atom::ListRight, openedList.styleString());
+    if (count > 0)
+        generateText(text, fake, marker);
+}
+
 void Generator::generateExampleFiles(const FakeNode *fake, CodeMarker *marker)
 {
     if (fake->childNodes().isEmpty())
         return;
-
-    OpenedList openedList(OpenedList::Bullet);
+    generateFileList(fake, marker, Node::File, QString("Files:"));
+    generateFileList(fake, marker, Node::Image, QString("Images:"));
+}
 
-    Text text;
-    text << Atom::ParaLeft << "Files:" << Atom::ParaRight
-         << Atom(Atom::ListLeft, openedList.styleString());
-    foreach (const Node *child, fake->childNodes()) {
-        QString exampleFile = child->name();
-        openedList.next();
-        text << Atom(Atom::ListItemNumber, openedList.numberString())
-             << Atom(Atom::ListItemLeft, openedList.styleString())
-             << Atom::ParaLeft
-             << Atom(Atom::Link, exampleFile)
-             << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
-             << exampleFile
-             << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK)
-             << Atom::ParaRight
-             << Atom(Atom::ListItemRight, openedList.styleString());
+#if 0
+    QList<Generator *>::ConstIterator g = generators.begin();
+    while (g != generators.end()) {
+        if (outputFormats.contains((*g)->format())) {
+            (*g)->initializeGenerator(config);
+            QStringList extraImages =
+                config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format());
+            QStringList::ConstIterator e = extraImages.begin();
+            while (e != extraImages.end()) {
+                QString userFriendlyFilePath;
+                QString filePath = Config::findFile(config.lastLocation(),
+                                                    imageFiles,
+                                                    imageDirs,
+                                                    *e,
+                                                    imgFileExts[(*g)->format()],
+                                                    userFriendlyFilePath);
+                if (!filePath.isEmpty())
+                    Config::copyFile(config.lastLocation(),
+                                     filePath,
+                                     userFriendlyFilePath,
+                                     (*g)->outputDir() +
+                                     "/images");
+                ++e;
+            }
+        }
+        ++g;
     }
-    text << Atom(Atom::ListRight, openedList.styleString());
-    generateText(text, fake, marker);
-}
+#endif
 
 void Generator::generateModuleWarning(const ClassNode *classe,
                                       CodeMarker *marker)