Classes | Macros | Functions | Variables
ftvhelp.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <qlist.h>
#include <qdict.h>
#include <qfileinfo.h>
#include "ftvhelp.h"
#include "config.h"
#include "message.h"
#include "doxygen.h"
#include "language.h"
#include "htmlgen.h"
#include "layout.h"
#include "pagedef.h"
#include "docparser.h"
#include "htmldocvisitor.h"
#include "filedef.h"
#include "util.h"
#include "resourcemgr.h"

Go to the source code of this file.

Classes

struct  FTVNode
 
struct  NavIndexEntry
 
class  NavIndexEntryList
 

Macros

#define MAX_INDENT   1024
 

Functions

static QCString node2URL (FTVNode *n, bool overruleFile=FALSE, bool srcLink=FALSE)
 
static void generateBriefDoc (FTextStream &t, Definition *def)
 
static QCString pathToNode (FTVNode *leaf, FTVNode *n)
 
static bool dupOfParent (const FTVNode *n)
 
static void generateJSLink (FTextStream &t, FTVNode *n)
 
static QCString convertFileId2Var (const QCString &fileId)
 
static bool generateJSTree (NavIndexEntryList &navIndex, FTextStream &t, const QList< FTVNode > &nl, int level, bool &first)
 
static void generateJSNavTree (const QList< FTVNode > &nodeList)
 

Variables

static int folderId =1
 

Macro Definition Documentation

#define MAX_INDENT   1024

Definition at line 41 of file ftvhelp.cpp.

Function Documentation

static QCString convertFileId2Var ( const QCString fileId)
static

Definition at line 482 of file ftvhelp.cpp.

483 {
484  QCString varId = fileId;
485  int i=varId.findRev('/');
486  if (i>=0) varId = varId.mid(i+1);
487  return substitute(varId,"-","_");
488 }
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition: qcstring.cpp:95
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: util.cpp:5088
static bool dupOfParent ( const FTVNode n)
static

Definition at line 460 of file ftvhelp.cpp.

461 {
462  if (n->parent==0) return FALSE;
463  if (n->file==n->parent->file) return TRUE;
464  return FALSE;
465 }
const bool FALSE
Definition: qglobal.h:370
QCString file
Definition: ftvhelp.cpp:57
FTVNode * parent
Definition: ftvhelp.cpp:62
const bool TRUE
Definition: qglobal.h:371
static void generateBriefDoc ( FTextStream t,
Definition def 
)
static

Definition at line 308 of file ftvhelp.cpp.

309 {
311  //printf("*** %p: generateBriefDoc(%s)='%s'\n",def,def->name().data(),brief.data());
312  if (!brief.isEmpty())
313  {
314  DocNode *root = validatingParseDoc(def->briefFile(),def->briefLine(),
315  def,0,brief,FALSE,FALSE,0,TRUE,TRUE);
317  HtmlCodeGenerator htmlGen(t,relPath);
318  HtmlDocVisitor *visitor = new HtmlDocVisitor(t,htmlGen,def);
319  root->accept(visitor);
320  delete visitor;
321  delete root;
322  }
323 }
bool brief
bool isEmpty() const
Definition: qcstring.h:189
Concrete visitor implementation for HTML output.
const bool FALSE
Definition: qglobal.h:370
DocRoot * validatingParseDoc(const char *fileName, int startLine, Definition *ctx, MemberDef *md, const char *input, bool indexWords, bool isExample, const char *exampleName, bool singleLine, bool linkFromIndex)
Definition: docparser.cpp:7179
int briefLine() const
QCString relativePathToRoot(const char *name)
Definition: util.cpp:5436
virtual QCString getOutputFileBase() const =0
QCString briefFile() const
virtual QCString briefDescription(bool abbreviate=FALSE) const
virtual void accept(DocVisitor *v)=0
const bool TRUE
Definition: qglobal.h:371
static void generateJSLink ( FTextStream t,
FTVNode n 
)
static

Definition at line 467 of file ftvhelp.cpp.

468 {
469  if (n->file.isEmpty()) // no link
470  {
471  t << "\"" << convertToJSString(n->name) << "\", null, ";
472  }
473  else // link into other page
474  {
475  t << "\"" << convertToJSString(n->name) << "\", \"";
476  t << externalRef("",n->ref,TRUE);
477  t << node2URL(n);
478  t << "\", ";
479  }
480 }
bool isEmpty() const
Definition: qcstring.h:189
QCString file
Definition: ftvhelp.cpp:57
QCString convertToJSString(const char *s)
Definition: util.cpp:5792
QCString ref
Definition: ftvhelp.cpp:56
static QCString node2URL(FTVNode *n, bool overruleFile=FALSE, bool srcLink=FALSE)
Definition: ftvhelp.cpp:210
QCString name
Definition: ftvhelp.cpp:59
const bool TRUE
Definition: qglobal.h:371
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition: util.cpp:7856
static void generateJSNavTree ( const QList< FTVNode > &  nodeList)
static

Definition at line 580 of file ftvhelp.cpp.

581 {
582  QCString htmlOutput = Config_getString("HTML_OUTPUT");
583  QFile f(htmlOutput+"/navtreedata.js");
584  NavIndexEntryList navIndex;
585  if (f.open(IO_WriteOnly) /*&& fidx.open(IO_WriteOnly)*/)
586  {
587  //FTextStream tidx(&fidx);
588  //tidx << "var NAVTREEINDEX =" << endl;
589  //tidx << "{" << endl;
590  FTextStream t(&f);
591  t << "var NAVTREE =" << endl;
592  t << "[" << endl;
593  t << " [ ";
594  QCString &projName = Config_getString("PROJECT_NAME");
595  if (projName.isEmpty())
596  {
597  if (Doxygen::mainPage && !Doxygen::mainPage->title().isEmpty()) // Use title of main page as root
598  {
599  t << "\"" << convertToJSString(Doxygen::mainPage->title()) << "\", ";
600  }
601  else // Use default section title as root
602  {
604  t << "\"" << convertToJSString(lne->title()) << "\", ";
605  }
606  }
607  else // use PROJECT_NAME as root tree element
608  {
609  t << "\"" << convertToJSString(projName) << "\", ";
610  }
611  t << "\"index" << Doxygen::htmlFileExtension << "\", ";
612 
613  // add special entry for index page
614  navIndex.append(new NavIndexEntry("index"+Doxygen::htmlFileExtension,""));
615  // related page index is written as a child of index.html, so add this as well
616  navIndex.append(new NavIndexEntry("pages"+Doxygen::htmlFileExtension,""));
617 
618  bool first=TRUE;
619  generateJSTree(navIndex,t,nodeList,1,first);
620 
621  if (first)
622  t << "]" << endl;
623  else
624  t << endl << " ] ]" << endl;
625  t << "];" << endl << endl;
626 
627  // write the navigation index (and sub-indices)
628  navIndex.sort();
629  int subIndex=0;
630  int elemCount=0;
631  const int maxElemCount=250;
632  //QFile fidx(htmlOutput+"/navtreeindex.js");
633  QFile fsidx(htmlOutput+"/navtreeindex0.js");
634  if (/*fidx.open(IO_WriteOnly) &&*/ fsidx.open(IO_WriteOnly))
635  {
636  //FTextStream tidx(&fidx);
637  FTextStream tsidx(&fsidx);
638  t << "var NAVTREEINDEX =" << endl;
639  t << "[" << endl;
640  tsidx << "var NAVTREEINDEX" << subIndex << " =" << endl;
641  tsidx << "{" << endl;
642  QListIterator<NavIndexEntry> li(navIndex);
643  NavIndexEntry *e;
644  bool first=TRUE;
645  for (li.toFirst();(e=li.current());) // for each entry
646  {
647  if (elemCount==0)
648  {
649  if (!first)
650  {
651  t << "," << endl;
652  }
653  else
654  {
655  first=FALSE;
656  }
657  t << "\"" << e->url << "\"";
658  }
659  tsidx << "\"" << e->url << "\":[" << e->path << "]";
660  ++li;
661  if (li.current() && elemCount<maxElemCount-1) tsidx << ","; // not last entry
662  tsidx << endl;
663 
664  elemCount++;
665  if (li.current() && elemCount>=maxElemCount) // switch to new sub-index
666  {
667  tsidx << "};" << endl;
668  elemCount=0;
669  fsidx.close();
670  subIndex++;
671  fsidx.setName(htmlOutput+"/navtreeindex"+QCString().setNum(subIndex)+".js");
672  if (!fsidx.open(IO_WriteOnly)) break;
673  tsidx.setDevice(&fsidx);
674  tsidx << "var NAVTREEINDEX" << subIndex << " =" << endl;
675  tsidx << "{" << endl;
676  }
677  }
678  tsidx << "};" << endl;
679  t << endl << "];" << endl;
680  }
681  t << endl << "var SYNCONMSG = '" << theTranslator->trPanelSynchronisationTooltip(FALSE) << "';";
682  t << endl << "var SYNCOFFMSG = '" << theTranslator->trPanelSynchronisationTooltip(TRUE) << "';";
683  }
684  ResourceMgr::instance().copyResource("navtree.js",htmlOutput);
685 }
LayoutNavEntry * find(LayoutNavEntry::Kind k, const char *file=0) const
Definition: layout.cpp:76
bool isEmpty() const
Definition: qcstring.h:189
void append(const type *d)
Definition: qlist.h:73
#define IO_WriteOnly
Definition: qiodevice.h:62
static QCString htmlFileExtension
Definition: doxygen.h:130
const bool FALSE
Definition: qglobal.h:370
bool copyResource(const char *name, const char *targetDir) const
static LayoutDocManager & instance()
Definition: layout.cpp:1359
static ResourceMgr & instance()
Definition: resourcemgr.cpp:35
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
Base class for the layout of a navigation item at the top of the HTML pages.
Definition: layout.h:118
QCString path
Definition: ftvhelp.cpp:432
const double e
static bool generateJSTree(NavIndexEntryList &navIndex, FTextStream &t, const QList< FTVNode > &nl, int level, bool &first)
Definition: ftvhelp.cpp:490
QCString convertToJSString(const char *s)
Definition: util.cpp:5792
void sort()
Definition: qlist.h:85
#define Config_getString(val)
Definition: config.cpp:660
virtual QCString trPanelSynchronisationTooltip(bool enable)=0
QCString url
Definition: ftvhelp.cpp:431
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
LayoutNavEntry * rootNavEntry() const
Definition: layout.cpp:1370
void setDevice(QIODevice *)
QCString title() const
Definition: layout.h:150
Translator * theTranslator
Definition: language.cpp:157
static PageDef * mainPage
Definition: doxygen.h:103
const bool TRUE
Definition: qglobal.h:371
QTextStream & endl(QTextStream &s)
static bool generateJSTree ( NavIndexEntryList navIndex,
FTextStream t,
const QList< FTVNode > &  nl,
int  level,
bool first 
)
static

Definition at line 490 of file ftvhelp.cpp.

492 {
493  static QCString htmlOutput = Config_getString("HTML_OUTPUT");
494  QCString indentStr;
495  indentStr.fill(' ',level*2);
496  bool found=FALSE;
497  QListIterator<FTVNode> nli(nl);
498  FTVNode *n;
499  for (nli.toFirst();(n=nli.current());++nli)
500  {
501  // terminate previous entry
502  if (!first) t << "," << endl;
503  first=FALSE;
504 
505  // start entry
506  if (!found)
507  {
508  t << "[" << endl;
509  }
510  found=TRUE;
511 
512  if (n->addToNavIndex) // add entry to the navigation index
513  {
514  if (n->def && n->def->definitionType()==Definition::TypeFile)
515  {
516  FileDef *fd = (FileDef*)n->def;
517  bool doc,src;
518  doc = fileVisibleInIndex(fd,src);
519  if (doc)
520  {
521  navIndex.append(new NavIndexEntry(node2URL(n,TRUE,FALSE),pathToNode(n,n)));
522  }
523  if (src)
524  {
525  navIndex.append(new NavIndexEntry(node2URL(n,TRUE,TRUE),pathToNode(n,n)));
526  }
527  }
528  else
529  {
530  navIndex.append(new NavIndexEntry(node2URL(n),pathToNode(n,n)));
531  }
532  }
533 
534  if (n->separateIndex) // store items in a separate file for dynamic loading
535  {
536  bool firstChild=TRUE;
537  t << indentStr << " [ ";
538  generateJSLink(t,n);
539  if (n->children.count()>0) // write children to separate file for dynamic loading
540  {
541  QCString fileId = n->file;
542  if (n->anchor)
543  {
544  fileId+="_"+n->anchor;
545  }
546  if (dupOfParent(n))
547  {
548  fileId+="_dup";
549  }
550  QFile f(htmlOutput+"/"+fileId+".js");
551  if (f.open(IO_WriteOnly))
552  {
553  FTextStream tt(&f);
554  tt << "var " << convertFileId2Var(fileId) << " =" << endl;
555  generateJSTree(navIndex,tt,n->children,1,firstChild);
556  tt << endl << "];";
557  }
558  t << "\"" << fileId << "\" ]";
559  }
560  else // no children
561  {
562  t << "null ]";
563  }
564  }
565  else // show items in this file
566  {
567  bool firstChild=TRUE;
568  t << indentStr << " [ ";
569  generateJSLink(t,n);
570  bool emptySection = !generateJSTree(navIndex,t,n->children,level+1,firstChild);
571  if (emptySection)
572  t << "null ]";
573  else
574  t << endl << indentStr << " ] ]";
575  }
576  }
577  return found;
578 }
Definition * def
Definition: ftvhelp.cpp:65
bool addToNavIndex
Definition: ftvhelp.cpp:64
static void generateJSLink(FTextStream &t, FTVNode *n)
Definition: ftvhelp.cpp:467
bool fileVisibleInIndex(FileDef *fd, bool &genSourceFile)
Definition: util.cpp:8177
void append(const type *d)
Definition: qlist.h:73
#define IO_WriteOnly
Definition: qiodevice.h:62
const bool FALSE
Definition: qglobal.h:370
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
static QCString pathToNode(FTVNode *leaf, FTVNode *n)
Definition: ftvhelp.cpp:448
static bool dupOfParent(const FTVNode *n)
Definition: ftvhelp.cpp:460
QCString file
Definition: ftvhelp.cpp:57
virtual DefType definitionType() const =0
Definition: type_traits.h:61
uint count() const
Definition: qlist.h:66
QList< FTVNode > children
Definition: ftvhelp.cpp:61
static bool generateJSTree(NavIndexEntryList &navIndex, FTextStream &t, const QList< FTVNode > &nl, int level, bool &first)
Definition: ftvhelp.cpp:490
static QCString convertFileId2Var(const QCString &fileId)
Definition: ftvhelp.cpp:482
std::void_t< T > n
#define Config_getString(val)
Definition: config.cpp:660
QCString anchor
Definition: ftvhelp.cpp:58
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
static QCString node2URL(FTVNode *n, bool overruleFile=FALSE, bool srcLink=FALSE)
Definition: ftvhelp.cpp:210
bool fill(char c, int len=-1)
Definition: qcstring.h:243
QCString doc
const bool TRUE
Definition: qglobal.h:371
bool separateIndex
Definition: ftvhelp.cpp:63
QTextStream & endl(QTextStream &s)
static QCString node2URL ( FTVNode n,
bool  overruleFile = FALSE,
bool  srcLink = FALSE 
)
static

Definition at line 210 of file ftvhelp.cpp.

211 {
212  QCString url = n->file;
213  if (!url.isEmpty() && url.at(0)=='!') // relative URL
214  {
215  // remove leading !
216  url = url.mid(1);
217  }
218  else if (!url.isEmpty() && url.at(0)=='^') // absolute URL
219  {
220  // skip, keep ^ in the output
221  }
222  else // local file (with optional anchor)
223  {
224  if (overruleFile && n->def && n->def->definitionType()==Definition::TypeFile)
225  {
226  FileDef *fd = (FileDef*)n->def;
227  if (srcLink)
228  {
229  url = fd->getSourceFileBase();
230  }
231  else
232  {
233  url = fd->getOutputFileBase();
234  }
235  }
237  if (!n->anchor.isEmpty()) url+="#"+n->anchor;
238  }
239  return url;
240 }
Definition * def
Definition: ftvhelp.cpp:65
bool isEmpty() const
Definition: qcstring.h:189
static QCString htmlFileExtension
Definition: doxygen.h:130
char & at(uint i) const
Definition: qcstring.h:326
QCString file
Definition: ftvhelp.cpp:57
virtual DefType definitionType() const =0
QCString getSourceFileBase() const
Definition: filedef.cpp:1771
QCString anchor
Definition: ftvhelp.cpp:58
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
QCString getOutputFileBase() const
Definition: filedef.h:83
if(!yymsg) yymsg
static QCString pathToNode ( FTVNode leaf,
FTVNode n 
)
static

Definition at line 448 of file ftvhelp.cpp.

449 {
451  if (n->parent)
452  {
453  result+=pathToNode(leaf,n->parent);
454  }
455  result+=QCString().setNum(n->index);
456  if (leaf!=n) result+=",";
457  return result;
458 }
static QCString result
static QCString pathToNode(FTVNode *leaf, FTVNode *n)
Definition: ftvhelp.cpp:448
int index
Definition: ftvhelp.cpp:60
FTVNode * parent
Definition: ftvhelp.cpp:62
QCString & setNum(short n)
Definition: qcstring.cpp:469

Variable Documentation

int folderId =1
static

Definition at line 43 of file ftvhelp.cpp.