diff options
author | Paul Wicking <paul.wicking@qt.io> | 2020-05-31 15:52:40 +0200 |
---|---|---|
committer | Paul Wicking <paul.wicking@qt.io> | 2020-06-04 13:08:39 +0200 |
commit | f82b82ff016734ad045a35e3ef31339239285724 (patch) | |
tree | 42944aabe055f99b34c93b8e9f3635f5e75ab6c0 | |
parent | f954d06c5b254c059edab8aa6b4fb6a35139d0bb (diff) | |
download | qttools-f82b82ff016734ad045a35e3ef31339239285724.tar.gz |
QDoc: Extract QmlTypeNode from Node
Task-number: QTBUG-84578
Change-Id: Ia3a0010e9791b69ca73d12a1e98322477e1569aa
Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io>
-rw-r--r-- | src/qdoc/.prev_CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/qdoc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/qdoc/cppcodeparser.cpp | 1 | ||||
-rw-r--r-- | src/qdoc/doc.cpp | 1 | ||||
-rw-r--r-- | src/qdoc/generator.cpp | 1 | ||||
-rw-r--r-- | src/qdoc/generator.h | 1 | ||||
-rw-r--r-- | src/qdoc/node.cpp | 129 | ||||
-rw-r--r-- | src/qdoc/node.h | 64 | ||||
-rw-r--r-- | src/qdoc/qdoc.pro | 2 | ||||
-rw-r--r-- | src/qdoc/qmltypenode.cpp | 157 | ||||
-rw-r--r-- | src/qdoc/qmltypenode.h | 110 | ||||
-rw-r--r-- | src/qdoc/qmlvisitor.h | 1 | ||||
-rw-r--r-- | src/qdoc/sections.cpp | 1 | ||||
-rw-r--r-- | src/qdoc/sharedcommentnode.cpp | 7 | ||||
-rw-r--r-- | src/qdoc/sharedcommentnode.h | 8 | ||||
-rw-r--r-- | src/qdoc/tree.h | 1 |
16 files changed, 289 insertions, 197 deletions
diff --git a/src/qdoc/.prev_CMakeLists.txt b/src/qdoc/.prev_CMakeLists.txt index 7cec47f4a..70d0aed47 100644 --- a/src/qdoc/.prev_CMakeLists.txt +++ b/src/qdoc/.prev_CMakeLists.txt @@ -48,6 +48,7 @@ qt_add_tool(qdoc qmlcodeparser.cpp qmlcodeparser.h qmlmarkupvisitor.cpp qmlmarkupvisitor.h qmlpropertynode.cpp qmlpropertynode.h + qmltypenode.cpp qmltypenode.h qmlvisitor.cpp qmlvisitor.h quoter.cpp quoter.h relatedclass.cpp relatedclass.h diff --git a/src/qdoc/CMakeLists.txt b/src/qdoc/CMakeLists.txt index e787c8bce..b1c3ff78c 100644 --- a/src/qdoc/CMakeLists.txt +++ b/src/qdoc/CMakeLists.txt @@ -49,6 +49,7 @@ qt_add_tool(qdoc qmlcodeparser.cpp qmlcodeparser.h qmlmarkupvisitor.cpp qmlmarkupvisitor.h qmlpropertynode.cpp qmlpropertynode.h + qmltypenode.cpp qmltypenode.h qmlvisitor.cpp qmlvisitor.h quoter.cpp quoter.h relatedclass.cpp relatedclass.h diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index d74d89be6..dbf7c0e35 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -34,6 +34,7 @@ #include "generator.h" #include "loggingcategory.h" #include "qdocdatabase.h" +#include "qmltypenode.h" #include "qmlpropertynode.h" #include "sharedcommentnode.h" diff --git a/src/qdoc/doc.cpp b/src/qdoc/doc.cpp index def487f66..274a06850 100644 --- a/src/qdoc/doc.cpp +++ b/src/qdoc/doc.cpp @@ -34,6 +34,7 @@ #include "docparser.h" #include "docprivate.h" #include "generator.h" +#include "qmltypenode.h" #include "quoter.h" #include "text.h" diff --git a/src/qdoc/generator.cpp b/src/qdoc/generator.cpp index b99e99e2d..0562cf54d 100644 --- a/src/qdoc/generator.cpp +++ b/src/qdoc/generator.cpp @@ -43,6 +43,7 @@ #include "openedlist.h" #include "propertynode.h" #include "qdocdatabase.h" +#include "qmltypenode.h" #include "quoter.h" #include "separator.h" #include "sharedcommentnode.h" diff --git a/src/qdoc/generator.h b/src/qdoc/generator.h index 6f5e08427..cf2fe8608 100644 --- a/src/qdoc/generator.h +++ b/src/qdoc/generator.h @@ -47,6 +47,7 @@ class FunctionNode; class Location; class Node; class QDocDatabase; +class QmlBasicTypeNode; class Generator { diff --git a/src/qdoc/node.cpp b/src/qdoc/node.cpp index f803f2846..8867adb23 100644 --- a/src/qdoc/node.cpp +++ b/src/qdoc/node.cpp @@ -36,6 +36,7 @@ #include "generator.h" #include "propertynode.h" #include "qdocdatabase.h" +#include "qmltypenode.h" #include "qmlpropertynode.h" #include "relatedclass.h" #include "sharedcommentnode.h" @@ -3597,134 +3598,6 @@ bool PageNode::setTitle(const QString &title) type is Node::ExternalPage, and the page type is Node::ArticlePage. */ -bool QmlTypeNode::qmlOnly = false; -QMultiMap<const Node *, Node *> QmlTypeNode::inheritedBy; - -/*! - Constructs a Qml type node or a Js type node depending on - the value of \a type, which is Node::QmlType by default, - but which can also be Node::JsType. The new node has the - given \a parent and \a name. - */ -QmlTypeNode::QmlTypeNode(Aggregate *parent, const QString &name, NodeType type) - : Aggregate(type, parent, name), - abstract_(false), - cnodeRequired_(false), - wrapper_(false), - cnode_(nullptr), - logicalModule_(nullptr), - qmlBaseNode_(nullptr) -{ - int i = 0; - if (name.startsWith("QML:")) { - qDebug() << "BOGUS QML qualifier:" << name; - i = 4; - } - setTitle(name.mid(i)); -} - -/*! - Clear the static maps so that subsequent runs don't try to use - contents from a previous run. - */ -void QmlTypeNode::terminate() -{ - inheritedBy.clear(); -} - -/*! - Record the fact that QML class \a base is inherited by - QML class \a sub. - */ -void QmlTypeNode::addInheritedBy(const Node *base, Node *sub) -{ - if (sub->isInternal()) - return; - if (!inheritedBy.contains(base, sub)) - inheritedBy.insert(base, sub); -} - -/*! - Loads the list \a subs with the nodes of all the subclasses of \a base. - */ -void QmlTypeNode::subclasses(const Node *base, NodeList &subs) -{ - subs.clear(); - if (inheritedBy.count(base) > 0) { - subs = inheritedBy.values(base); - } -} - -/*! - If this QML type node has a base type node, - return the fully qualified name of that QML - type, i.e. <QML-module-name>::<QML-type-name>. - */ -QString QmlTypeNode::qmlFullBaseName() const -{ - QString result; - if (qmlBaseNode_) { - result = qmlBaseNode_->logicalModuleName() + "::" + qmlBaseNode_->name(); - } - return result; -} - -/*! - If the QML type's QML module pointer is set, return the QML - module name from the QML module node. Otherwise, return the - empty string. - */ -QString QmlTypeNode::logicalModuleName() const -{ - return (logicalModule_ ? logicalModule_->logicalModuleName() : QString()); -} - -/*! - If the QML type's QML module pointer is set, return the QML - module version from the QML module node. Otherwise, return - the empty string. - */ -QString QmlTypeNode::logicalModuleVersion() const -{ - return (logicalModule_ ? logicalModule_->logicalModuleVersion() : QString()); -} - -/*! - If the QML type's QML module pointer is set, return the QML - module identifier from the QML module node. Otherwise, return - the empty string. - */ -QString QmlTypeNode::logicalModuleIdentifier() const -{ - return (logicalModule_ ? logicalModule_->logicalModuleIdentifier() : QString()); -} - -/*! - Returns true if this QML type inherits \a type. - */ -bool QmlTypeNode::inherits(Aggregate *type) -{ - QmlTypeNode *qtn = qmlBaseNode(); - while (qtn != nullptr) { - if (qtn == type) - return true; - qtn = qtn->qmlBaseNode(); - } - return false; -} - -/*! - Constructs either a Qml basic type node or a Javascript - basic type node, depending on the value pf \a type, which - must be either Node::QmlBasicType or Node::JsBasicType. - The new node has the given \a parent and \a name. - */ -QmlBasicTypeNode::QmlBasicTypeNode(Aggregate *parent, const QString &name, Node::NodeType type) - : Aggregate(type, parent, name) -{ - setTitle(name); -} - /*! \class ProxyNode \brief A class for representing an Aggregate that is documented in a different module. diff --git a/src/qdoc/node.h b/src/qdoc/node.h index 6c1173504..ed269185b 100644 --- a/src/qdoc/node.h +++ b/src/qdoc/node.h @@ -695,70 +695,6 @@ private: QStringList images_; }; -typedef QVector<ImportRec> ImportList; - -class QmlTypeNode : public Aggregate -{ -public: - QmlTypeNode(Aggregate *parent, const QString &name, NodeType type = QmlType); - bool isFirstClassAggregate() const override { return true; } - bool isQtQuickNode() const override - { - return (logicalModuleName() == QLatin1String("QtQuick")); - } - ClassNode *classNode() override { return cnode_; } - void setClassNode(ClassNode *cn) override { cnode_ = cn; } - bool isAbstract() const override { return abstract_; } - bool isWrapper() const override { return wrapper_; } - void setAbstract(bool b) override { abstract_ = b; } - void setWrapper() override { wrapper_ = true; } - bool isInternal() const override { return (status() == Internal); } - QString qmlFullBaseName() const override; - QString obsoleteLink() const override { return obsoleteLink_; } - void setObsoleteLink(const QString &t) override { obsoleteLink_ = t; } - QString logicalModuleName() const override; - QString logicalModuleVersion() const override; - QString logicalModuleIdentifier() const override; - CollectionNode *logicalModule() const override { return logicalModule_; } - void setQmlModule(CollectionNode *t) override { logicalModule_ = t; } - - const ImportList &importList() const { return importList_; } - void setImportList(const ImportList &il) { importList_ = il; } - const QString &qmlBaseName() const { return qmlBaseName_; } - void setQmlBaseName(const QString &name) { qmlBaseName_ = name; } - bool qmlBaseNodeNotSet() const { return (qmlBaseNode_ == nullptr); } - QmlTypeNode *qmlBaseNode() const override { return qmlBaseNode_; } - void setQmlBaseNode(QmlTypeNode *b) { qmlBaseNode_ = b; } - void requireCppClass() { cnodeRequired_ = true; } - bool cppClassRequired() const { return cnodeRequired_; } - static void addInheritedBy(const Node *base, Node *sub); - static void subclasses(const Node *base, NodeList &subs); - static void terminate(); - bool inherits(Aggregate *type); - -public: - static bool qmlOnly; - static QMultiMap<const Node *, Node *> inheritedBy; - -private: - bool abstract_; - bool cnodeRequired_; - bool wrapper_; - ClassNode *cnode_; - QString qmlBaseName_; - QString obsoleteLink_; - CollectionNode *logicalModule_; - QmlTypeNode *qmlBaseNode_; - ImportList importList_; -}; - -class QmlBasicTypeNode : public Aggregate -{ -public: - QmlBasicTypeNode(Aggregate *parent, const QString &name, NodeType type = QmlBasicType); - bool isFirstClassAggregate() const override { return true; } -}; - class CollectionNode : public PageNode { public: diff --git a/src/qdoc/qdoc.pro b/src/qdoc/qdoc.pro index da51394c5..e5b23ff4a 100644 --- a/src/qdoc/qdoc.pro +++ b/src/qdoc/qdoc.pro @@ -65,6 +65,7 @@ HEADERS += access.h \ qdocdatabase.h \ qdocindexfiles.h \ qdoctagfiles.h \ + qmltypenode.h \ qmlpropertynode.h \ quoter.h \ relatedclass.h \ @@ -112,6 +113,7 @@ SOURCES += atom.cpp \ qdocdatabase.cpp \ qdocindexfiles.cpp \ qdoctagfiles.cpp \ + qmltypenode.cpp \ qmlpropertynode.cpp \ quoter.cpp \ relatedclass.cpp \ diff --git a/src/qdoc/qmltypenode.cpp b/src/qdoc/qmltypenode.cpp new file mode 100644 index 000000000..415a11266 --- /dev/null +++ b/src/qdoc/qmltypenode.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmltypenode.h" + +#include <QtCore/qdebug.h> + +QT_BEGIN_NAMESPACE + +bool QmlTypeNode::qmlOnly = false; +QMultiMap<const Node *, Node *> QmlTypeNode::inheritedBy; + +/*! + Constructs a Qml type node or a Js type node depending on + the value of \a type, which is Node::QmlType by default, + but which can also be Node::JsType. The new node has the + given \a parent and \a name. + */ +QmlTypeNode::QmlTypeNode(Aggregate *parent, const QString &name, NodeType type) + : Aggregate(type, parent, name) +{ + int i = 0; + if (name.startsWith("QML:")) { + qDebug() << "BOGUS QML qualifier:" << name; + i = 4; + } + setTitle(name.mid(i)); +} + +/*! + Clear the static maps so that subsequent runs don't try to use + contents from a previous run. + */ +void QmlTypeNode::terminate() +{ + inheritedBy.clear(); +} + +/*! + Record the fact that QML class \a base is inherited by + QML class \a sub. + */ +void QmlTypeNode::addInheritedBy(const Node *base, Node *sub) +{ + if (sub->isInternal()) + return; + if (!inheritedBy.contains(base, sub)) + inheritedBy.insert(base, sub); +} + +/*! + Loads the list \a subs with the nodes of all the subclasses of \a base. + */ +void QmlTypeNode::subclasses(const Node *base, NodeList &subs) +{ + subs.clear(); + if (inheritedBy.count(base) > 0) { + subs = inheritedBy.values(base); + } +} + +/*! + If this QML type node has a base type node, + return the fully qualified name of that QML + type, i.e. <QML-module-name>::<QML-type-name>. + */ +QString QmlTypeNode::qmlFullBaseName() const +{ + QString result; + if (m_qmlBaseNode) { + result = m_qmlBaseNode->logicalModuleName() + "::" + m_qmlBaseNode->name(); + } + return result; +} + +/*! + If the QML type's QML module pointer is set, return the QML + module name from the QML module node. Otherwise, return the + empty string. + */ +QString QmlTypeNode::logicalModuleName() const +{ + return (m_logicalModule ? m_logicalModule->logicalModuleName() : QString()); +} + +/*! + If the QML type's QML module pointer is set, return the QML + module version from the QML module node. Otherwise, return + the empty string. + */ +QString QmlTypeNode::logicalModuleVersion() const +{ + return (m_logicalModule ? m_logicalModule->logicalModuleVersion() : QString()); +} + +/*! + If the QML type's QML module pointer is set, return the QML + module identifier from the QML module node. Otherwise, return + the empty string. + */ +QString QmlTypeNode::logicalModuleIdentifier() const +{ + return (m_logicalModule ? m_logicalModule->logicalModuleIdentifier() : QString()); +} + +/*! + Returns true if this QML type inherits \a type. + */ +bool QmlTypeNode::inherits(Aggregate *type) +{ + QmlTypeNode *qtn = qmlBaseNode(); + while (qtn != nullptr) { + if (qtn == type) + return true; + qtn = qtn->qmlBaseNode(); + } + return false; +} + +/*! + Constructs either a Qml basic type node or a Javascript + basic type node, depending on the value pf \a type, which + must be either Node::QmlBasicType or Node::JsBasicType. + The new node has the given \a parent and \a name. + */ +QmlBasicTypeNode::QmlBasicTypeNode(Aggregate *parent, const QString &name, Node::NodeType type) + : Aggregate(type, parent, name) +{ + setTitle(name); +} + +QT_END_NAMESPACE diff --git a/src/qdoc/qmltypenode.h b/src/qdoc/qmltypenode.h new file mode 100644 index 000000000..8dc153ccb --- /dev/null +++ b/src/qdoc/qmltypenode.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTYPENODE_H +#define QMLTYPENODE_H + +#include "importrec.h" +#include "node.h" + +#include <QtCore/qglobal.h> +#include <QtCore/qstring.h> +#include <QtCore/qvector.h> + +QT_BEGIN_NAMESPACE + +class ClassNode; +class CollectionNode; + +typedef QVector<ImportRec> ImportList; + +class QmlTypeNode : public Aggregate +{ +public: + QmlTypeNode(Aggregate *parent, const QString &name, NodeType type = QmlType); + bool isFirstClassAggregate() const override { return true; } + bool isQtQuickNode() const override + { + return (logicalModuleName() == QLatin1String("QtQuick")); + } + ClassNode *classNode() override { return m_classNode; } + void setClassNode(ClassNode *cn) override { m_classNode = cn; } + bool isAbstract() const override { return m_abstract; } + bool isWrapper() const override { return m_wrapper; } + void setAbstract(bool b) override { m_abstract = b; } + void setWrapper() override { m_wrapper = true; } + bool isInternal() const override { return (status() == Internal); } + QString qmlFullBaseName() const override; + QString obsoleteLink() const override { return m_obsoleteLink; } + void setObsoleteLink(const QString &t) override { m_obsoleteLink = t; } + QString logicalModuleName() const override; + QString logicalModuleVersion() const override; + QString logicalModuleIdentifier() const override; + CollectionNode *logicalModule() const override { return m_logicalModule; } + void setQmlModule(CollectionNode *t) override { m_logicalModule = t; } + + const ImportList &importList() const { return m_importList; } + void setImportList(const ImportList &il) { m_importList = il; } + const QString &qmlBaseName() const { return m_qmlBaseName; } + void setQmlBaseName(const QString &name) { m_qmlBaseName = name; } + bool qmlBaseNodeNotSet() const { return (m_qmlBaseNode == nullptr); } + QmlTypeNode *qmlBaseNode() const override { return m_qmlBaseNode; } + void setQmlBaseNode(QmlTypeNode *b) { m_qmlBaseNode = b; } + void requireCppClass() { m_classNodeRequired = true; } + bool cppClassRequired() const { return m_classNodeRequired; } + static void addInheritedBy(const Node *base, Node *sub); + static void subclasses(const Node *base, NodeList &subs); + static void terminate(); + bool inherits(Aggregate *type); + +public: + static bool qmlOnly; + static QMultiMap<const Node *, Node *> inheritedBy; + +private: + bool m_abstract { false }; + bool m_classNodeRequired { false }; + bool m_wrapper { false }; + ClassNode *m_classNode { nullptr }; + QString m_qmlBaseName {}; + QString m_obsoleteLink {}; + CollectionNode *m_logicalModule { nullptr }; + QmlTypeNode *m_qmlBaseNode { nullptr }; + ImportList m_importList {}; +}; + +class QmlBasicTypeNode : public Aggregate +{ +public: + QmlBasicTypeNode(Aggregate *parent, const QString &name, NodeType type = QmlBasicType); + bool isFirstClassAggregate() const override { return true; } +}; + +QT_END_NAMESPACE + +#endif // QMLTYPENODE_H diff --git a/src/qdoc/qmlvisitor.h b/src/qdoc/qmlvisitor.h index d46bdfb7f..6d24b50a3 100644 --- a/src/qdoc/qmlvisitor.h +++ b/src/qdoc/qmlvisitor.h @@ -30,6 +30,7 @@ #define QMLVISITOR_H #include "node.h" +#include "qmltypenode.h" #include <QtCore/qstring.h> diff --git a/src/qdoc/sections.cpp b/src/qdoc/sections.cpp index af9fe8e3e..7e229776e 100644 --- a/src/qdoc/sections.cpp +++ b/src/qdoc/sections.cpp @@ -34,6 +34,7 @@ #include "generator.h" #include "loggingcategory.h" #include "qmlpropertynode.h" +#include "qmltypenode.h" #include "sharedcommentnode.h" #include "typedefnode.h" #include "variablenode.h" diff --git a/src/qdoc/sharedcommentnode.cpp b/src/qdoc/sharedcommentnode.cpp index b5a07ee98..fc512fe25 100644 --- a/src/qdoc/sharedcommentnode.cpp +++ b/src/qdoc/sharedcommentnode.cpp @@ -29,9 +29,16 @@ #include "sharedcommentnode.h" #include "functionnode.h" +#include "qmltypenode.h" QT_BEGIN_NAMESPACE +SharedCommentNode::SharedCommentNode(QmlTypeNode *parent, int count, QString &group) + : Node(Node::SharedComment, parent, group) +{ + m_collective.reserve(count); +} + /*! Searches the shared comment node's member nodes for function nodes. Each function node's overload flag is set. diff --git a/src/qdoc/sharedcommentnode.h b/src/qdoc/sharedcommentnode.h index dd90f2a79..ccb9f2c83 100644 --- a/src/qdoc/sharedcommentnode.h +++ b/src/qdoc/sharedcommentnode.h @@ -36,6 +36,8 @@ QT_BEGIN_NAMESPACE +class QmlTypeNode; + class SharedCommentNode : public Node { public: @@ -44,11 +46,7 @@ public: m_collective.reserve(1); append(node); } - SharedCommentNode(QmlTypeNode *parent, int count, QString &group) - : Node(Node::SharedComment, parent, group) - { - m_collective.reserve(count); - } + SharedCommentNode(QmlTypeNode *parent, int count, QString &group); ~SharedCommentNode() override { m_collective.clear(); } bool isPropertyGroup() const override diff --git a/src/qdoc/tree.h b/src/qdoc/tree.h index 6f95dbe2e..ab1672b6e 100644 --- a/src/qdoc/tree.h +++ b/src/qdoc/tree.h @@ -35,6 +35,7 @@ #include "node.h" #include "propertynode.h" +#include "qmltypenode.h" #include <QtCore/qstack.h> |