tools/qdoc3/generator.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    63 QMap<QString, QMap<QString, QString> > Generator::fmtRightMaps;
    63 QMap<QString, QMap<QString, QString> > Generator::fmtRightMaps;
    64 QMap<QString, QStringList> Generator::imgFileExts;
    64 QMap<QString, QStringList> Generator::imgFileExts;
    65 QSet<QString> Generator::outputFormats;
    65 QSet<QString> Generator::outputFormats;
    66 QStringList Generator::imageFiles;
    66 QStringList Generator::imageFiles;
    67 QStringList Generator::imageDirs;
    67 QStringList Generator::imageDirs;
       
    68 QStringList Generator::exampleDirs;
       
    69 QStringList Generator::exampleImgExts;
    68 QString Generator::outDir;
    70 QString Generator::outDir;
    69 QString Generator::project;
    71 QString Generator::project;
    70 
    72 
    71 static void singularPlural(Text& text, const NodeList& nodes)
    73 static void singularPlural(Text& text, const NodeList& nodes)
    72 {
    74 {
   118         }
   120         }
   119 
   121 
   120         if (!dirInfo.mkdir(outDir + "/images"))
   122         if (!dirInfo.mkdir(outDir + "/images"))
   121             config.lastLocation().fatal(tr("Cannot create output directory '%1'")
   123             config.lastLocation().fatal(tr("Cannot create output directory '%1'")
   122                                         .arg(outDir + "/images"));
   124                                         .arg(outDir + "/images"));
       
   125         if (!dirInfo.mkdir(outDir + "/images/used-in-examples"))
       
   126             config.lastLocation().fatal(tr("Cannot create output directory '%1'")
       
   127                                         .arg(outDir + "/images/used-in-examples"));
   123     }
   128     }
   124 
   129 
   125     imageFiles = config.getStringList(CONFIG_IMAGES);
   130     imageFiles = config.getStringList(CONFIG_IMAGES);
   126     imageDirs = config.getStringList(CONFIG_IMAGEDIRS);
   131     imageDirs = config.getStringList(CONFIG_IMAGEDIRS);
   127 
   132     exampleDirs = config.getStringList(CONFIG_EXAMPLEDIRS);
   128     QString imagesDotFileExtensions = CONFIG_IMAGES + Config::dot + CONFIG_FILEEXTENSIONS;
   133     exampleImgExts = config.getStringList(CONFIG_EXAMPLES + Config::dot +
       
   134                                           CONFIG_IMAGEEXTENSIONS);
       
   135 
       
   136     QString imagesDotFileExtensions =
       
   137         CONFIG_IMAGES + Config::dot + CONFIG_FILEEXTENSIONS;
   129     QSet<QString> formats = config.subVars(imagesDotFileExtensions);
   138     QSet<QString> formats = config.subVars(imagesDotFileExtensions);
   130     QSet<QString>::ConstIterator f = formats.begin();
   139     QSet<QString>::ConstIterator f = formats.begin();
   131     while (f != formats.end()) {
   140     while (f != formats.end()) {
   132         imgFileExts[*f] = config.getStringList(imagesDotFileExtensions +
   141         imgFileExts[*f] = config.getStringList(imagesDotFileExtensions +
   133                                                Config::dot + *f);
   142                                                Config::dot + *f);
   136 
   145 
   137     QList<Generator *>::ConstIterator g = generators.begin();
   146     QList<Generator *>::ConstIterator g = generators.begin();
   138     while (g != generators.end()) {
   147     while (g != generators.end()) {
   139         if (outputFormats.contains((*g)->format())) {
   148         if (outputFormats.contains((*g)->format())) {
   140             (*g)->initializeGenerator(config);
   149             (*g)->initializeGenerator(config);
   141             QStringList extraImages = config.getStringList(CONFIG_EXTRAIMAGES +
   150             QStringList extraImages =
   142                                                            Config::dot +
   151                 config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format());
   143                                                            (*g)->format());
       
   144             QStringList::ConstIterator e = extraImages.begin();
   152             QStringList::ConstIterator e = extraImages.begin();
   145             while (e != extraImages.end()) {
   153             while (e != extraImages.end()) {
   146                 QString userFriendlyFilePath;
   154                 QString userFriendlyFilePath;
   147                 QString filePath = Config::findFile(config.lastLocation(),
   155                 QString filePath = Config::findFile(config.lastLocation(),
   148                                                     imageFiles, imageDirs, *e,
   156                                                     imageFiles,
       
   157                                                     imageDirs,
       
   158                                                     *e,
   149                                                     imgFileExts[(*g)->format()],
   159                                                     imgFileExts[(*g)->format()],
   150                                                     userFriendlyFilePath);
   160                                                     userFriendlyFilePath);
   151                 if (!filePath.isEmpty())
   161                 if (!filePath.isEmpty())
   152                     Config::copyFile(config.lastLocation(),
   162                     Config::copyFile(config.lastLocation(),
   153                                      filePath,
   163                                      filePath,
   320     }
   330     }
   321     else if (node->type() == Node::Fake) {
   331     else if (node->type() == Node::Fake) {
   322         const FakeNode *fake = static_cast<const FakeNode *>(node);
   332         const FakeNode *fake = static_cast<const FakeNode *>(node);
   323         if (fake->subType() == Node::Example)
   333         if (fake->subType() == Node::Example)
   324             generateExampleFiles(fake, marker);
   334             generateExampleFiles(fake, marker);
   325         else if (fake->subType() == Node::File)
   335         else if ((fake->subType() == Node::File) || (fake->subType() == Node::Image))
   326             quiet = true;
   336             quiet = true;
   327     }
   337     }
   328 
   338 
   329     if (node->doc().isEmpty()) {
   339     if (node->doc().isEmpty()) {
   330         if (!quiet && !node->isReimp()) // ### might be unnecessary
   340         if (!quiet && !node->isReimp()) // ### might be unnecessary
   527         text << Atom::ParaRight;
   537         text << Atom::ParaRight;
   528         generateText(text, classe, marker);
   538         generateText(text, classe, marker);
   529     }
   539     }
   530 }
   540 }
   531 
   541 
       
   542 /*!
       
   543   This function is called when the documentation for an
       
   544   example is being formatted. It outputs the list of source
       
   545   files comprising the example, and the list of images used
       
   546   by the example. The images are copied into a subtree of
       
   547   \c{...doc/html/images/used-in-examples/...} 
       
   548  */
       
   549 void Generator::generateFileList(const FakeNode* fake,
       
   550                                  CodeMarker* marker,
       
   551                                  Node::SubType subtype,
       
   552                                  const QString& tag)
       
   553 {
       
   554     int count = 0;
       
   555     Text text;
       
   556     OpenedList openedList(OpenedList::Bullet);
       
   557 
       
   558     text << Atom::ParaLeft << tag << Atom::ParaRight
       
   559          << Atom(Atom::ListLeft, openedList.styleString());
       
   560 
       
   561     foreach (const Node* child, fake->childNodes()) {
       
   562         if (child->subType() == subtype) {
       
   563             ++count;
       
   564             QString file = child->name();
       
   565             if (subtype == Node::Image) {
       
   566                 if (!file.isEmpty()) {
       
   567                     QDir dirInfo;
       
   568                     QString userFriendlyFilePath;
       
   569                     QString srcPath = Config::findFile(fake->location(),
       
   570                                                        QStringList(),
       
   571                                                        exampleDirs,
       
   572                                                        file,
       
   573                                                        exampleImgExts,
       
   574                                                        userFriendlyFilePath);
       
   575                     userFriendlyFilePath.truncate(userFriendlyFilePath.lastIndexOf('/'));
       
   576 
       
   577                     QString imgOutDir = outDir + "/images/used-in-examples/" + userFriendlyFilePath;
       
   578                     if (!dirInfo.mkpath(imgOutDir))
       
   579                         fake->location().fatal(tr("Cannot create output directory '%1'")
       
   580                                                .arg(imgOutDir));
       
   581 
       
   582                     QString imgOutName = Config::copyFile(fake->location(),
       
   583                                                           srcPath,
       
   584                                                           file,
       
   585                                                           imgOutDir);
       
   586                 }
       
   587 
       
   588             }
       
   589 
       
   590             openedList.next();
       
   591             text << Atom(Atom::ListItemNumber, openedList.numberString())
       
   592                  << Atom(Atom::ListItemLeft, openedList.styleString())
       
   593                  << Atom::ParaLeft
       
   594                  << Atom(Atom::Link, file)
       
   595                  << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
       
   596                  << file
       
   597                  << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK)
       
   598                  << Atom::ParaRight
       
   599                  << Atom(Atom::ListItemRight, openedList.styleString());
       
   600         }
       
   601     }
       
   602     text << Atom(Atom::ListRight, openedList.styleString());
       
   603     if (count > 0)
       
   604         generateText(text, fake, marker);
       
   605 }
       
   606 
   532 void Generator::generateExampleFiles(const FakeNode *fake, CodeMarker *marker)
   607 void Generator::generateExampleFiles(const FakeNode *fake, CodeMarker *marker)
   533 {
   608 {
   534     if (fake->childNodes().isEmpty())
   609     if (fake->childNodes().isEmpty())
   535         return;
   610         return;
   536 
   611     generateFileList(fake, marker, Node::File, QString("Files:"));
   537     OpenedList openedList(OpenedList::Bullet);
   612     generateFileList(fake, marker, Node::Image, QString("Images:"));
   538 
   613 }
   539     Text text;
   614 
   540     text << Atom::ParaLeft << "Files:" << Atom::ParaRight
   615 #if 0
   541          << Atom(Atom::ListLeft, openedList.styleString());
   616     QList<Generator *>::ConstIterator g = generators.begin();
   542     foreach (const Node *child, fake->childNodes()) {
   617     while (g != generators.end()) {
   543         QString exampleFile = child->name();
   618         if (outputFormats.contains((*g)->format())) {
   544         openedList.next();
   619             (*g)->initializeGenerator(config);
   545         text << Atom(Atom::ListItemNumber, openedList.numberString())
   620             QStringList extraImages =
   546              << Atom(Atom::ListItemLeft, openedList.styleString())
   621                 config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format());
   547              << Atom::ParaLeft
   622             QStringList::ConstIterator e = extraImages.begin();
   548              << Atom(Atom::Link, exampleFile)
   623             while (e != extraImages.end()) {
   549              << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
   624                 QString userFriendlyFilePath;
   550              << exampleFile
   625                 QString filePath = Config::findFile(config.lastLocation(),
   551              << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK)
   626                                                     imageFiles,
   552              << Atom::ParaRight
   627                                                     imageDirs,
   553              << Atom(Atom::ListItemRight, openedList.styleString());
   628                                                     *e,
   554     }
   629                                                     imgFileExts[(*g)->format()],
   555     text << Atom(Atom::ListRight, openedList.styleString());
   630                                                     userFriendlyFilePath);
   556     generateText(text, fake, marker);
   631                 if (!filePath.isEmpty())
   557 }
   632                     Config::copyFile(config.lastLocation(),
       
   633                                      filePath,
       
   634                                      userFriendlyFilePath,
       
   635                                      (*g)->outputDir() +
       
   636                                      "/images");
       
   637                 ++e;
       
   638             }
       
   639         }
       
   640         ++g;
       
   641     }
       
   642 #endif
   558 
   643 
   559 void Generator::generateModuleWarning(const ClassNode *classe,
   644 void Generator::generateModuleWarning(const ClassNode *classe,
   560                                       CodeMarker *marker)
   645                                       CodeMarker *marker)
   561 {
   646 {
   562     QString module = classe->moduleName();
   647     QString module = classe->moduleName();