1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef COLLECTIONNODE_H
5#define COLLECTIONNODE_H
6
7#include "pagenode.h"
8
9#include <QtCore/qglobal.h>
10#include <QtCore/qstring.h>
11
12QT_BEGIN_NAMESPACE
13
14class CollectionNode : public PageNode
15{
16public:
17 CollectionNode(NodeType type, Aggregate *parent, const QString &name)
18 : PageNode(type, parent, name)
19 {
20 }
21
22 [[nodiscard]] bool isCollectionNode() const override { return true; }
23 [[nodiscard]] QString qtVariable() const override { return m_qtVariable; }
24 void setQtVariable(const QString &v) override { m_qtVariable = v; }
25 [[nodiscard]] QString qtCMakeComponent() const override { return m_qtCMakeComponent; }
26 void setQtCMakeComponent(const QString &target) override { m_qtCMakeComponent = target; }
27 void addMember(Node *node) override;
28 [[nodiscard]] bool hasNamespaces() const override;
29 [[nodiscard]] bool hasClasses() const override;
30 void getMemberNamespaces(NodeMap &out);
31 void getMemberClasses(NodeMap &out) const;
32 [[nodiscard]] bool wasSeen() const override { return m_seen; }
33
34 [[nodiscard]] QString fullTitle() const override { return title(); }
35 [[nodiscard]] QString logicalModuleName() const override { return m_logicalModuleName; }
36 [[nodiscard]] QString logicalModuleVersion() const override;
37 [[nodiscard]] QString logicalModuleIdentifier() const override
38 {
39 return m_logicalModuleName + m_logicalModuleVersionMajor;
40 }
41 [[nodiscard]] QString state() const { return m_state; }
42
43 void setLogicalModuleInfo(const QStringList &info) override;
44 void setState(const QString &state) { m_state = state; }
45
46 // REMARK: Those methods are used by QDocDatabase as a performance
47 // detail to avoid merging a collection node multiple times. They
48 // should not be addressed in any other part of the code nor
49 // should their usage appear more than once in QDocDatabase,
50 // albeit this is not enforced.
51 // More information are provided in the comment for the definition
52 // of m_merged.
53 void markMerged() { m_merged = true; }
54 bool isMerged() { return m_merged; }
55
56 [[nodiscard]] const NodeList &members() const { return m_members; }
57
58 void markSeen() { m_seen = true; }
59 void markNotSeen() { m_seen = false; }
60
61private:
62 bool m_seen { false };
63 // REMARK: This is set by the database when merging the collection
64 // node and is later used to avoid merging the same collection
65 // multiple times.
66 // Currently, collection nodes may come from multiple projects,
67 // such that to have a complete overview of the members of a
68 // collection we need to rejoin all members for all instances of
69 // the "same" collection.
70 // This is done in QDocDatabase, generally through an external
71 // method call that is done ad-hoc when a source-of-truth
72 // collection node is needed.
73 // As each part of the code that need such a source-of-truth will
74 // need to merge the node, to avoid the overhead of a relatively
75 // expensive operation being performed multiple times, we expose
76 // this detail so that QDocDatabase can avoid performing the
77 // operation again.
78 // To avoid the coupling, QDocDatabase could keep track of the
79 // merged nodes itself, this is a bit less trivial that this
80 // implementation and doesn't address the source of the problem
81 // (the multiple merges themselves and the sequencing of the
82 // related operations) and as such was discarded in favor of this
83 // simpler implementation.
84 // Do note that outside the very specific purpose for which this
85 // member was made, no part of the code should refer to it and its
86 // associated methods.
87 // Should this start to be the case, we can switch to the more
88 // complex encapsulation into QDocDatabase without having to touch
89 // the outside user of the merges.
90 // Further down the line, this is expected to go away completely
91 // as other part of the code are streamlined.
92 // KLUDGE: Note that this whole exposure is done as a hackish
93 // solution to QTBUG-104237 and should not be considered final or
94 // dependable.
95 bool m_merged { false };
96 NodeList m_members {};
97 QString m_logicalModuleName {};
98 QString m_logicalModuleVersionMajor {};
99 QString m_logicalModuleVersionMinor {};
100 QString m_qtVariable {};
101 QString m_qtCMakeComponent {};
102 QString m_state {};
103};
104
105QT_END_NAMESPACE
106
107#endif // COLLECTIONNODE_H
108

source code of qttools/src/qdoc/qdoc/collectionnode.h