| 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 | #include "collectionnode.h" |
| 5 | |
| 6 | #include <QtCore/qstringlist.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | /*! |
| 11 | \class CollectionNode |
| 12 | \brief A class for holding the members of a collection of doc pages. |
| 13 | */ |
| 14 | |
| 15 | /*! |
| 16 | Appends \a node to the collection node's member list, if |
| 17 | and only if it isn't already in the member list. |
| 18 | */ |
| 19 | void CollectionNode::addMember(Node *node) |
| 20 | { |
| 21 | if (!m_members.contains(t: node)) |
| 22 | m_members.append(t: node); |
| 23 | } |
| 24 | |
| 25 | /*! |
| 26 | Returns \c true if this collection node contains at least |
| 27 | one namespace node. |
| 28 | */ |
| 29 | bool CollectionNode::hasNamespaces() const |
| 30 | { |
| 31 | return std::any_of(first: m_members.cbegin(), last: m_members.cend(), pred: [](const Node *member) { |
| 32 | return member->isClassNode() && member->isInAPI(); |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | /*! |
| 37 | Returns \c true if this collection node contains at least |
| 38 | one class node. |
| 39 | */ |
| 40 | bool CollectionNode::hasClasses() const |
| 41 | { |
| 42 | return std::any_of(first: m_members.cbegin(), last: m_members.cend(), pred: [](const Node *member) { |
| 43 | return member->isClassNode() && member->isInAPI(); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | /*! |
| 48 | \fn template <typename F> NodeMap CollectionNode::getMembers(const F &&predicate) const |
| 49 | |
| 50 | Returns a map containing this collection node's member nodes for which \c |
| 51 | predicate(node) returns \c true. The \a predicate is a function or a |
| 52 | lambda that takes a const Node pointer as an argument and returns a bool. |
| 53 | */ |
| 54 | |
| 55 | /*! |
| 56 | \fn NodeMap CollectionNode::getMembers(Node::NodeType type) const |
| 57 | |
| 58 | Returns a map containing this collection node's member nodes with |
| 59 | a specified node \a type. |
| 60 | */ |
| 61 | |
| 62 | /*! |
| 63 | Returns the logical module version. |
| 64 | */ |
| 65 | QString CollectionNode::logicalModuleVersion() const |
| 66 | { |
| 67 | QStringList version; |
| 68 | version << m_logicalModuleVersionMajor << m_logicalModuleVersionMinor; |
| 69 | version.removeAll(t: QString()); |
| 70 | return version.join(sep: "." ); |
| 71 | } |
| 72 | |
| 73 | /*! |
| 74 | This function accepts the logical module \a info as a string |
| 75 | list. If the logical module info contains the version number, |
| 76 | it splits the version number on the '.' character to get the |
| 77 | major and minor version numbers. Both major and minor version |
| 78 | numbers should be provided, but the minor version number is |
| 79 | not strictly necessary. |
| 80 | */ |
| 81 | void CollectionNode::setLogicalModuleInfo(const QStringList &info) |
| 82 | { |
| 83 | m_logicalModuleName = info[0]; |
| 84 | if (info.size() > 1) { |
| 85 | QStringList dotSplit = info[1].split(sep: QLatin1Char('.')); |
| 86 | m_logicalModuleVersionMajor = dotSplit[0]; |
| 87 | if (dotSplit.size() > 1) |
| 88 | m_logicalModuleVersionMinor = dotSplit[1]; |
| 89 | else |
| 90 | m_logicalModuleVersionMinor = "0" ; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /*! |
| 95 | \fn void CollectionNode::setState(const QString &state) |
| 96 | \fn QString CollectionNode::state() |
| 97 | |
| 98 | Sets or gets a description of this module's state. For example, |
| 99 | \e {"Technical Preview"}. This string is used when generating the |
| 100 | module's documentation page and reference pages of the module's |
| 101 | members. |
| 102 | */ |
| 103 | |
| 104 | QT_END_NAMESPACE |
| 105 | |