Skip to content

Commit

Permalink
issue #10234 Feature: Add EXTERNAL_NAMESPACES configuration option, o…
Browse files Browse the repository at this point in the history
…r similar
  • Loading branch information
doxygen committed Aug 19, 2023
1 parent 0b0ec2e commit cb2c983
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/config.xml
Expand Up @@ -3631,17 +3631,17 @@ where `loc1` and `loc2` can be relative or absolute paths or URLs.
<option type='bool' id='ALLEXTERNALS' defval='0'>
<docs>
<![CDATA[
If the \c ALLEXTERNALS tag is set to \c YES, all external class will be listed
in the class index. If set to \c NO, only the inherited external classes
will be listed.
If the \c ALLEXTERNALS tag is set to \c YES, all external classes and namespaces
will be listed in the class and namespace index.
If set to \c NO, only the inherited external classes will be listed.
]]>
</docs>
</option>
<option type='bool' id='EXTERNAL_GROUPS' defval='1'>
<docs>
<![CDATA[
If the \c EXTERNAL_GROUPS tag is set to \c YES, all external groups will be listed
in the modules index. If set to \c NO, only the current project's groups will
in the topic index. If set to \c NO, only the current project's groups will
be listed.
]]>
</docs>
Expand Down
2 changes: 1 addition & 1 deletion src/ftvhelp.cpp
Expand Up @@ -193,7 +193,7 @@ void FTVHelp::addContentsItem(bool isDir,
const Definition *def
)
{
//printf("%p: p->indent=%d addContentsItem(%s,%s,%s,%s)\n",(void*)this,p->indent,qPrint(name),qPrint(ref),qPrint(file),qPrint(anchor));
//printf("%p: p->indent=%d addContentsItem(%d,%s,%s,%s,%s)\n",(void*)this,p->indent,isDir,qPrint(name),qPrint(ref),qPrint(file),qPrint(anchor));
auto &nl = p->indentNodes[p->indent];
if (!nl.empty())
{
Expand Down
30 changes: 30 additions & 0 deletions src/groupdef.cpp
Expand Up @@ -84,6 +84,7 @@ class GroupDefImpl : public DefinitionMixin<GroupDef>
virtual size_t numDocMembers() const override;
virtual bool isLinkableInProject() const override;
virtual bool isLinkable() const override;
virtual bool isVisibleInHierarchy() const override;
virtual bool isASubGroup() const override;
virtual void computeAnchors() override;
virtual void countMembers() override;
Expand Down Expand Up @@ -1823,6 +1824,35 @@ void GroupDefImpl::sortSubGroups()
{ return g1->groupTitle() < g2->groupTitle(); });
}

static bool hasNonReferenceNestedGroupRec(const GroupDef *gd,int level)
{
if (level>30)
{
err("Possible recursive group relation while inside %s\n",qPrint(gd->name()));
return false;
}
bool found=gd->isLinkableInProject();
if (found)
{
return true;
}
else
{
for (const auto &igd : gd->getSubGroups())
{
found = found || hasNonReferenceNestedGroupRec(igd,level+1);
if (found) break;
}
}
return found;
}

bool GroupDefImpl::isVisibleInHierarchy() const
{
bool allExternals = Config_getBool(EXTERNAL_GROUPS);
return (allExternals || hasNonReferenceNestedGroupRec(this,0)) && isLinkable();
}

bool GroupDefImpl::isLinkableInProject() const
{
return !isReference() && isLinkable();
Expand Down
1 change: 1 addition & 0 deletions src/groupdef.h
Expand Up @@ -78,6 +78,7 @@ class GroupDef : public DefinitionMutable, public Definition
virtual size_t numDocMembers() const = 0;
virtual bool isLinkableInProject() const = 0;
virtual bool isLinkable() const = 0;
virtual bool isVisibleInHierarchy() const = 0;
virtual bool isASubGroup() const = 0;
virtual void computeAnchors() = 0;
virtual void countMembers() = 0;
Expand Down
40 changes: 19 additions & 21 deletions src/index.cpp
Expand Up @@ -1854,7 +1854,7 @@ static void writeNamespaceTree(const NamespaceLinkedRefMap &nsLinkedMap,FTVHelp
{
for (const auto &nd : nsLinkedMap)
{
if (nd->isLinkable())
if (nd->isVisibleInHierarchy())
{
writeNamespaceTreeElement(nd,ftv,rootOnly,addToIndex);
}
Expand All @@ -1866,7 +1866,7 @@ static void writeNamespaceTree(const NamespaceLinkedMap &nsLinkedMap,FTVHelp *ft
{
for (const auto &nd : nsLinkedMap)
{
if (nd->isLinkable())
if (nd->isVisibleInHierarchy())
{
writeNamespaceTreeElement(nd.get(),ftv,rootOnly,addToIndex);
}
Expand Down Expand Up @@ -3822,14 +3822,14 @@ static void writePages(const PageDef *pd,FTVHelp *ftv)
ftv->addContentsItem(
hasSubPages || hasSections,pageTitle,
pd->getReference(),pd->getOutputFileBase(),
QCString(),hasSubPages,TRUE,pd);
QCString(),FALSE,TRUE,pd);
}
if (addToIndex && pd!=Doxygen::mainPage.get())
{
Doxygen::indexList->addContentsItem(
hasSubPages || hasSections,pageTitle,
pd->getReference(),pd->getOutputFileBase(),
QCString(),hasSubPages,TRUE,pd);
QCString(),FALSE,TRUE,pd);
}
}
if (hasSubPages && ftv) ftv->incContentsDepth();
Expand Down Expand Up @@ -3879,7 +3879,7 @@ static void writePageIndex(OutputList &ol)
{
if ((pd->getOuterScope()==0 ||
pd->getOuterScope()->definitionType()!=Definition::TypePage) && // not a sub page
!pd->isReference() // not an external page
pd->visibleInIndex()
)
{
writePages(pd.get(),&ftv);
Expand Down Expand Up @@ -3997,31 +3997,26 @@ static void writeGroupTreeNode(OutputList &ol, const GroupDef *gd, int level, FT
/* Some groups should appear twice under different parent-groups.
* That is why we should not check if it was visited
*/
if ((!gd->isASubGroup() || level>0) && gd->isVisible() &&
(!gd->isReference() || Config_getBool(EXTERNAL_GROUPS)) // hide external groups by default
)
if ((!gd->isASubGroup() || level>0) && gd->isVisible() && gd->isVisibleInHierarchy())
{
//printf("gd->name()=%s #members=%d\n",qPrint(gd->name()),gd->countMembers());
// write group info
bool hasSubGroups = !gd->getSubGroups().empty();
bool hasSubPages = !gd->getPages().empty();
size_t numSubItems = 0;
if (1 /*Config_getBool(TOC_EXPAND)*/)
for (const auto &ml : gd->getMemberLists())
{
for (const auto &ml : gd->getMemberLists())
if (ml->listType()&MemberListType_documentationLists)
{
if (ml->listType()&MemberListType_documentationLists)
{
numSubItems += ml->size();
}
numSubItems += ml->size();
}
numSubItems += gd->getNamespaces().size();
numSubItems += gd->getClasses().size();
numSubItems += gd->getFiles().size();
numSubItems += gd->getConcepts().size();
numSubItems += gd->getDirs().size();
numSubItems += gd->getPages().size();
}
numSubItems += gd->getNamespaces().size();
numSubItems += gd->getClasses().size();
numSubItems += gd->getFiles().size();
numSubItems += gd->getConcepts().size();
numSubItems += gd->getDirs().size();
numSubItems += gd->getPages().size();

bool isDir = hasSubGroups || hasSubPages || numSubItems>0;
//printf("gd='%s': pageDict=%d\n",qPrint(gd->name()),gd->pageDict->count());
Expand Down Expand Up @@ -4228,7 +4223,10 @@ static void writeGroupHierarchy(OutputList &ol, FTVHelp* ftv,bool addToIndex)
startIndexHierarchy(ol,0);
for (const auto &gd : *Doxygen::groupLinkedMap)
{
writeGroupTreeNode(ol,gd.get(),0,ftv,addToIndex);
if (gd->isVisibleInHierarchy())
{
writeGroupTreeNode(ol,gd.get(),0,ftv,addToIndex);
}
}
endIndexHierarchy(ol,0);
if (ftv)
Expand Down
31 changes: 31 additions & 0 deletions src/namespacedef.cpp
Expand Up @@ -87,6 +87,7 @@ class NamespaceDefImpl : public DefinitionMixin<NamespaceDefMutable>
virtual bool isInline() const override { return m_inline; }
virtual bool isLinkableInProject() const override;
virtual bool isLinkable() const override;
virtual bool isVisibleInHierarchy() const override;
virtual bool hasDetailedDescription() const override;
virtual void addMembersToMemberGroup() override;
virtual void distributeMemberGroupDocumentation() override;
Expand Down Expand Up @@ -213,6 +214,8 @@ class NamespaceDefAliasImpl : public DefinitionAliasMixin<NamespaceDef>
{ return getNSAlias()->isLinkableInProject(); }
virtual bool isLinkable() const
{ return getNSAlias()->isLinkable(); }
virtual bool isVisibleInHierarchy() const
{ return getNSAlias()->isVisibleInHierarchy(); }
virtual bool hasDetailedDescription() const
{ return getNSAlias()->hasDetailedDescription(); }
virtual const Definition *findInnerCompound(const QCString &name) const
Expand Down Expand Up @@ -1491,6 +1494,34 @@ void NamespaceDefImpl::writeMemberDocumentation(OutputList &ol,MemberListType lt
if (ml) ml->writeDocumentation(ol,displayName(),this,title);
}

static bool hasNonReferenceNestedNamespaceRec(const NamespaceDef *nd,int level)
{
if (level>30)
{
err("Possible recursive namespace relation while inside %s\n",qPrint(nd->name()));
return false;
}
bool found=nd->isLinkableInProject();
if (found)
{
return true;
}
else
{
for (const auto &ind : nd->getNamespaces())
{
found = found || hasNonReferenceNestedNamespaceRec(ind,level+1);
if (found) break;
}
}
return found;
}

bool NamespaceDefImpl::isVisibleInHierarchy() const
{
bool allExternals = Config_getBool(ALLEXTERNALS);
return (allExternals || hasNonReferenceNestedNamespaceRec(this,0)) && isLinkable();
}

bool NamespaceDefImpl::isLinkableInProject() const
{
Expand Down
1 change: 1 addition & 0 deletions src/namespacedef.h
Expand Up @@ -69,6 +69,7 @@ class NamespaceDef : public Definition
virtual bool isInline() const = 0;
virtual bool isLinkableInProject() const = 0;
virtual bool isLinkable() const = 0;
virtual bool isVisibleInHierarchy() const = 0;
virtual bool hasDetailedDescription() const = 0;
virtual const Definition *findInnerCompound(const QCString &name) const = 0;
virtual bool subGrouping() const = 0;
Expand Down
9 changes: 7 additions & 2 deletions src/pagedef.cpp
Expand Up @@ -165,6 +165,12 @@ void PageDefImpl::writeTagFile(TextStream &tagFile)
tagFile << " <name>" << name() << "</name>\n";
tagFile << " <title>" << convertToXML(title()) << "</title>\n";
tagFile << " <filename>" << fn << "</filename>\n";
for (const auto &subPage : m_subPages)
{
QCString sfn = subPage->getOutputFileBase();
addHtmlExtensionIfMissing(sfn);
tagFile << " <subpage>" << sfn << "</subpage>\n";
}
writeDocAnchorsToTagFile(tagFile);
tagFile << " </compound>\n";
}
Expand Down Expand Up @@ -339,8 +345,7 @@ bool PageDefImpl::visibleInIndex() const
return // not part of a group
!getGroupDef() &&
// not an externally defined page
(!isReference() || externalPages)
;
(!isReference() || externalPages);
}

bool PageDefImpl::documentedPage() const
Expand Down
26 changes: 25 additions & 1 deletion src/tagreader.cpp
Expand Up @@ -194,6 +194,7 @@ using TagGroupInfoPtr = std::unique_ptr<TagGroupInfo>;
struct TagPageInfo : public TagCompoundInfo
{
QCString title;
StringVector subpages;
};

using TagPageInfoPtr = std::unique_ptr<TagPageInfo>;
Expand Down Expand Up @@ -657,6 +658,22 @@ class TagFileParser
}
}

void endSubpage()
{
switch(m_state)
{
case InPage:
{
TagPageInfo *info = m_curCompound.getPageInfo();
if (info) info->subpages.push_back(m_curString.str());
}
break;
default:
p_warn("Unexpected tag 'subpage' found");
break;
}
}

void endDir()
{
switch(m_state)
Expand Down Expand Up @@ -1056,6 +1073,7 @@ static const std::map< std::string, ElementCallbacks > g_elementHandlers =
{ "file", { startCb(&TagFileParser::startStringValue ), endCb(&TagFileParser::endFile ) } },
{ "dir", { startCb(&TagFileParser::startStringValue ), endCb(&TagFileParser::endDir ) } },
{ "page", { startCb(&TagFileParser::startStringValue ), endCb(&TagFileParser::endPage ) } },
{ "subpage", { startCb(&TagFileParser::startStringValue ), endCb(&TagFileParser::endSubpage ) } },
{ "docanchor", { startCb(&TagFileParser::startDocAnchor ), endCb(&TagFileParser::endDocAnchor ) } },
{ "tagfile", { startCb(&TagFileParser::startIgnoreElement), endCb(&TagFileParser::endIgnoreElement) } },
{ "templarg", { startCb(&TagFileParser::startStringValue ), endCb(&TagFileParser::endTemplateArg ) } },
Expand Down Expand Up @@ -1717,9 +1735,15 @@ void TagFileParser::buildLists(const std::shared_ptr<Entry> &root)
pe->section = isIndex ? Entry::MAINPAGEDOC_SEC : Entry::PAGEDOC_SEC;
pe->name = tpi->name;
pe->args = tpi->title;
for (const auto &subpage : tpi->subpages)
{
// we add subpage labels as a kind of "inheritance" relation to prevent
// needing to add another list to the Entry class.
pe->extends.push_back(BaseInfo(stripExtension(QCString(subpage)),Protection::Public,Specifier::Normal));
}
addDocAnchors(pe,tpi->docAnchors);
pe->tagInfoData.tagName = m_tagName;
pe->tagInfoData.fileName = tpi->filename;
pe->tagInfoData.fileName = stripExtension(tpi->filename);
pe->startLine = tpi->lineNr;
pe->hasTagInfo = TRUE;
root->moveToSubEntryAndKeep(pe);
Expand Down

0 comments on commit cb2c983

Please sign in to comment.