tools/qdoc3/helpprojectwriter.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include <QHash>
    42 #include <QHash>
    43 #include <QMap>
    43 #include <QMap>
    44 #include <qdebug.h>
    44 //#include <qdebug.h>
    45 
    45 
    46 #include "atom.h"
    46 #include "atom.h"
    47 #include "helpprojectwriter.h"
    47 #include "helpprojectwriter.h"
    48 #include "htmlgenerator.h"
    48 #include "htmlgenerator.h"
    49 #include "config.h"
    49 #include "config.h"
    89             SubProject subproject;
    89             SubProject subproject;
    90             QString subprefix = prefix + "subprojects" + Config::dot + name + Config::dot;
    90             QString subprefix = prefix + "subprojects" + Config::dot + name + Config::dot;
    91             subproject.title = config.getString(subprefix + "title");
    91             subproject.title = config.getString(subprefix + "title");
    92             subproject.indexTitle = config.getString(subprefix + "indexTitle");
    92             subproject.indexTitle = config.getString(subprefix + "indexTitle");
    93             subproject.sortPages = config.getBool(subprefix + "sortPages");
    93             subproject.sortPages = config.getBool(subprefix + "sortPages");
       
    94             subproject.type = config.getString(subprefix + "type");
    94             readSelectors(subproject, config.getStringList(subprefix + "selectors"));
    95             readSelectors(subproject, config.getStringList(subprefix + "selectors"));
    95             project.subprojects[name] = subproject;
    96             project.subprojects[name] = subproject;
    96         }
    97         }
    97 
    98 
    98         if (project.subprojects.isEmpty()) {
    99         if (project.subprojects.isEmpty()) {
   623     generateSections(project, writer, rootNode);
   624     generateSections(project, writer, rootNode);
   624 
   625 
   625     foreach (const QString &name, project.subprojects.keys()) {
   626     foreach (const QString &name, project.subprojects.keys()) {
   626         SubProject subproject = project.subprojects[name];
   627         SubProject subproject = project.subprojects[name];
   627 
   628 
   628         if (!name.isEmpty()) {
   629         if (subproject.type == QLatin1String("manual")) {
   629             writer.writeStartElement("section");
   630 
   630             QString indexPath = tree->fullDocumentLocation(tree->findFakeNodeByTitle(subproject.indexTitle));
   631             const FakeNode *indexPage = tree->findFakeNodeByTitle(subproject.indexTitle);
   631             writer.writeAttribute("ref", HtmlGenerator::cleanRef(indexPath));
   632             if (indexPage) {
   632             writer.writeAttribute("title", subproject.title);
   633                 Text indexBody = indexPage->doc().body();
   633             project.files.insert(indexPath);
   634                 const Atom *atom = indexBody.firstAtom();
   634         }
   635                 QStack<int> sectionStack;
   635         if (subproject.sortPages) {
   636                 bool inItem = false;
   636             QStringList titles = subproject.nodes.keys();
   637 
   637             titles.sort();
   638                 while (atom) {
   638             foreach (const QString &title, titles)
   639                     switch (atom->type()) {
   639                 writeNode(project, writer, subproject.nodes[title]);
   640                     case Atom::ListLeft:
       
   641                         sectionStack.push(0);
       
   642                         break;
       
   643                     case Atom::ListRight:
       
   644                         if (sectionStack.pop() > 0)
       
   645                             writer.writeEndElement(); // section
       
   646                         break;
       
   647                     case Atom::ListItemLeft:
       
   648                         inItem = true;
       
   649                         break;
       
   650                     case Atom::ListItemRight:
       
   651                         inItem = false;
       
   652                         break;
       
   653                     case Atom::Link:
       
   654                         if (inItem) {
       
   655                             if (sectionStack.top() > 0)
       
   656                                 writer.writeEndElement(); // section
       
   657 
       
   658                             const FakeNode *page = tree->findFakeNodeByTitle(atom->string());
       
   659                             writer.writeStartElement("section");
       
   660                             QString indexPath = tree->fullDocumentLocation(page);
       
   661                             writer.writeAttribute("ref", HtmlGenerator::cleanRef(indexPath));
       
   662                             writer.writeAttribute("title", atom->string());
       
   663                             project.files.insert(indexPath);
       
   664 
       
   665                             sectionStack.top() += 1;
       
   666                         }
       
   667                         break;
       
   668                     default:
       
   669                         ;
       
   670                     }
       
   671 
       
   672                     if (atom == indexBody.lastAtom())
       
   673                         break;
       
   674                     atom = atom->next();
       
   675                 }
       
   676             } else
       
   677                 rootNode->doc().location().warning(
       
   678                     tr("Failed to find index: %1").arg(subproject.indexTitle)
       
   679                     );
       
   680 
   640         } else {
   681         } else {
   641             // Find a contents node and navigate from there, using the NextLink values.
   682 
   642             foreach (const Node *node, subproject.nodes) {
   683             if (!name.isEmpty()) {
   643                 QString nextTitle = node->links().value(Node::NextLink).first;
   684                 writer.writeStartElement("section");
   644                 if (!nextTitle.isEmpty() &&
   685                 QString indexPath = tree->fullDocumentLocation(tree->findFakeNodeByTitle(subproject.indexTitle));
   645                     node->links().value(Node::ContentsLink).first.isEmpty()) {
   686                 writer.writeAttribute("ref", HtmlGenerator::cleanRef(indexPath));
   646 
   687                 writer.writeAttribute("title", subproject.title);
   647                     FakeNode *nextPage = const_cast<FakeNode *>(tree->findFakeNodeByTitle(nextTitle));
   688                 project.files.insert(indexPath);
   648 
   689             }
   649                     // Write the contents node.
   690             if (subproject.sortPages) {
   650                     writeNode(project, writer, node);
   691                 QStringList titles = subproject.nodes.keys();
   651 
   692                 titles.sort();
   652                     while (nextPage) {
   693                 foreach (const QString &title, titles)
   653                         writeNode(project, writer, nextPage);
   694                     writeNode(project, writer, subproject.nodes[title]);
   654                         nextTitle = nextPage->links().value(Node::NextLink).first;
   695             } else {
   655                         if(nextTitle.isEmpty())
   696                 // Find a contents node and navigate from there, using the NextLink values.
   656                             break;
   697                 foreach (const Node *node, subproject.nodes) {
   657                         nextPage = const_cast<FakeNode *>(tree->findFakeNodeByTitle(nextTitle));
   698                     QString nextTitle = node->links().value(Node::NextLink).first;
       
   699                     if (!nextTitle.isEmpty() &&
       
   700                         node->links().value(Node::ContentsLink).first.isEmpty()) {
       
   701 
       
   702                         FakeNode *nextPage = const_cast<FakeNode *>(tree->findFakeNodeByTitle(nextTitle));
       
   703 
       
   704                         // Write the contents node.
       
   705                         writeNode(project, writer, node);
       
   706 
       
   707                         while (nextPage) {
       
   708                             writeNode(project, writer, nextPage);
       
   709                             nextTitle = nextPage->links().value(Node::NextLink).first;
       
   710                             if(nextTitle.isEmpty())
       
   711                                 break;
       
   712                             nextPage = const_cast<FakeNode *>(tree->findFakeNodeByTitle(nextTitle));
       
   713                         }
       
   714                         break;
   658                     }
   715                     }
   659                     break;
   716                 }
   660                 }
   717             }
   661             }
   718 
   662         }
   719             if (!name.isEmpty())
   663 
   720                 writer.writeEndElement(); // section
   664         if (!name.isEmpty())
   721         }
   665             writer.writeEndElement(); // section
       
   666     }
   722     }
   667 
   723 
   668     writer.writeEndElement(); // section
   724     writer.writeEndElement(); // section
   669     writer.writeEndElement(); // toc
   725     writer.writeEndElement(); // toc
   670 
   726