aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/inheritance_diagram.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-12-06 08:47:21 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-12-07 09:26:54 +0100
commitf76cf34a5777dbc08d4c171c1e7afd9180d2e7c7 (patch)
tree221d622a25d4dca8fe214c659377b5c92f23f042 /sources/pyside6/doc/inheritance_diagram.py
parentcd0341574551c52c7ff8ff747caa3d895e3efb48 (diff)
Documentation: Enable URLs in inheritance diagram
Switch graphviz generation to use SVG and add some functions to derive URLs from the attributes. This currently works only within one module; links to classes from other modules lack the required refuri node attribute. Task-number: PYSIDE-1725 Pick-to: 6.2 Change-Id: If93e78a6ba60168992b1acc0b926b5cfb57eeb7d Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/doc/inheritance_diagram.py')
-rw-r--r--sources/pyside6/doc/inheritance_diagram.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/sources/pyside6/doc/inheritance_diagram.py b/sources/pyside6/doc/inheritance_diagram.py
index f7541086c..846367050 100644
--- a/sources/pyside6/doc/inheritance_diagram.py
+++ b/sources/pyside6/doc/inheritance_diagram.py
@@ -246,6 +246,7 @@ class InheritanceGraph(object):
url = urls.get(fullname)
if url is not None:
this_node_attrs['URL'] = f'"{url}"'
+ this_node_attrs['target'] = '"_top"' # Browser target frame attribute (same page)
attribute = self._format_node_attrs(this_node_attrs)
res.append(f' "{name}" [{attribute}];\n')
@@ -314,6 +315,27 @@ def get_graph_hash(node):
return md5(hashString.encode('utf-8')).hexdigest()[-10:]
+def fix_class_name(name):
+ """Fix duplicated modules 'PySide6.QtCore.PySide6.QtCore.QObject'"""
+ mod_pos = name.rfind('.PySide')
+ return name[mod_pos + 1:] if mod_pos != -1 else name
+
+
+def expand_ref_uri(uri):
+ """Fix a ref URI like 'QObject.html#PySide6.QtCore.PySide6.QtCore.QObject'
+ to point from the image directory back to the HTML directory."""
+ anchor_pos = uri.find('#')
+ if anchor_pos == -1:
+ return uri
+ # Determine the path from the anchor "#PySide6.QtCore.PySide6.QtCore.QObject"
+ class_name = fix_class_name(uri[anchor_pos + 1:])
+ path = '../'
+ modules = class_name.split('.')
+ for m in range(min(2, len(modules))):
+ path += f'{modules[m]}/'
+ return path + uri[:anchor_pos] # Strip anchor
+
+
def html_visit_inheritance_diagram(self, node):
"""
Output the graph for HTML. This will insert a PNG with clickable
@@ -327,10 +349,10 @@ def html_visit_inheritance_diagram(self, node):
# Create a mapping from fully-qualified class names to URLs.
urls = {}
for child in node:
- if child.get('refuri') is not None:
- urls[child['reftitle']] = child.get('refuri')
- elif child.get('refid') is not None:
- urls[child['reftitle']] = '#' + child.get('refid')
+ ref_title = child.get('reftitle')
+ uri = child.get('refuri')
+ if uri and ref_title:
+ urls[fix_class_name(ref_title)] = expand_ref_uri(uri)
dotcode = graph.generate_dot(name, urls, env=self.builder.env)
render_dot_html(self, node, dotcode, {}, 'inheritance', 'inheritance',