| 1 | // Copyright (C) 2025 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 "nativeenum.h" |
| 5 | |
| 6 | #include "enumnode.h" |
| 7 | #include "node.h" |
| 8 | #include "qdocdatabase.h" |
| 9 | |
| 10 | using namespace Qt::Literals::StringLiterals; |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | /*! |
| 15 | \class NativeEnum |
| 16 | \brief Encapsulates information about native (C++) enum values. |
| 17 | |
| 18 | The NativeEnum resolves a qualified path to a C++ enum into a |
| 19 | EnumNode pointer. This information is used for replicating the |
| 20 | enumerator documentation in QML API reference. |
| 21 | */ |
| 22 | |
| 23 | /*! |
| 24 | \class NativeEnumInterface |
| 25 | \brief Interface implemented by Node subclasses that can refer |
| 26 | to a C++ enum. |
| 27 | |
| 28 | Nodes implementing this interface provide a const and a non-const |
| 29 | getter returning a NativeEnum pointer. |
| 30 | */ |
| 31 | |
| 32 | /*! |
| 33 | Locates the node specified by \a path and sets it as the C++ enumeration |
| 34 | associated with this property. |
| 35 | |
| 36 | \a registeredQmlName is a prefix to use in the generated enum value |
| 37 | documentation; each enumerator is prefixed with \c {<registeredQmlName>.} |
| 38 | |
| 39 | \note The target EnumNode is searched under the primary tree only. |
| 40 | |
| 41 | Returns \c true on success. |
| 42 | */ |
| 43 | bool NativeEnum::resolve(const QString &path, const QString ®isteredQmlName) |
| 44 | { |
| 45 | m_enumNode = static_cast<EnumNode*>( |
| 46 | QDocDatabase::qdocDB()->primaryTree()->findNodeByNameAndType(path: path.split(sep: u"::"_s ), isMatch: &Node::isEnumType) |
| 47 | ); |
| 48 | if (m_enumNode && !registeredQmlName.isEmpty()) |
| 49 | m_prefix = registeredQmlName; |
| 50 | return m_enumNode != nullptr; |
| 51 | } |
| 52 | |
| 53 | QT_END_NAMESPACE |
| 54 | |