| 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 HELPPROJECTWRITER_H |
| 5 | #define HELPPROJECTWRITER_H |
| 6 | |
| 7 | #include "node.h" |
| 8 | |
| 9 | #include <QtCore/qstring.h> |
| 10 | #include <QtCore/qxmlstream.h> |
| 11 | |
| 12 | #include <utility> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class QDocDatabase; |
| 17 | class Generator; |
| 18 | |
| 19 | using NodeTypeSet = QSet<unsigned char>; |
| 20 | |
| 21 | struct SubProject |
| 22 | { |
| 23 | QString m_title {}; |
| 24 | QString m_indexTitle {}; |
| 25 | NodeTypeSet m_selectors {}; |
| 26 | bool m_sortPages {}; |
| 27 | QString m_type {}; |
| 28 | QString m_prefix {}; |
| 29 | QHash<QString, const Node *> m_nodes {}; |
| 30 | QStringList m_groups {}; |
| 31 | }; |
| 32 | |
| 33 | /* |
| 34 | * Name is the human-readable name to be shown in Assistant. |
| 35 | * Ids is a list of unique identifiers. |
| 36 | * Ref is the location of the documentation for the keyword. |
| 37 | */ |
| 38 | struct Keyword { |
| 39 | QString m_name {}; |
| 40 | QStringList m_ids {}; |
| 41 | QString m_ref {}; |
| 42 | Keyword(QString name, const QString &id, QString ref) |
| 43 | : m_name(std::move(name)), m_ids(QStringList(id)), m_ref(std::move(ref)) |
| 44 | { |
| 45 | } |
| 46 | Keyword(QString name, QStringList ids, QString ref) |
| 47 | : m_name(std::move(name)), m_ids(std::move(ids)), m_ref(std::move(ref)) |
| 48 | { |
| 49 | } |
| 50 | bool operator<(const Keyword &o) const |
| 51 | { |
| 52 | // Order by name; use ref as a secondary sort key |
| 53 | return (m_name == o.m_name) ? m_ref < o.m_ref : m_name < o.m_name; |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | struct HelpProject |
| 58 | { |
| 59 | using NodeStatusSet = QSet<unsigned char>; |
| 60 | |
| 61 | QString m_name {}; |
| 62 | QString m_helpNamespace {}; |
| 63 | QString m_virtualFolder {}; |
| 64 | QString m_version {}; |
| 65 | QString m_fileName {}; |
| 66 | QString m_indexRoot {}; |
| 67 | QString m_indexTitle {}; |
| 68 | QList<Keyword> m_keywords {}; |
| 69 | QSet<QString> m_files {}; |
| 70 | QSet<QString> {}; |
| 71 | QSet<QString> m_filterAttributes {}; |
| 72 | QHash<QString, QSet<QString>> m_customFilters {}; |
| 73 | QSet<QString> m_excluded {}; |
| 74 | QList<SubProject> m_subprojects {}; |
| 75 | QHash<const Node *, NodeStatusSet> m_memberStatus {}; |
| 76 | bool m_includeIndexNodes {}; |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | class HelpProjectWriter |
| 81 | { |
| 82 | public: |
| 83 | HelpProjectWriter(const QString &defaultFileName, Generator *g); |
| 84 | void reset(const QString &defaultFileName, Generator *g); |
| 85 | void (const QString &file); |
| 86 | void generate(); |
| 87 | |
| 88 | private: |
| 89 | void generateProject(HelpProject &project); |
| 90 | void generateSections(HelpProject &project, QXmlStreamWriter &writer, const Node *node); |
| 91 | bool generateSection(HelpProject &project, QXmlStreamWriter &writer, const Node *node); |
| 92 | Keyword keywordDetails(const Node *node) const; |
| 93 | void writeNode(HelpProject &project, QXmlStreamWriter &writer, const Node *node); |
| 94 | void readSelectors(SubProject &subproject, const QStringList &selectors); |
| 95 | void addMembers(HelpProject &project, QXmlStreamWriter &writer, const Node *node); |
| 96 | void writeSection(QXmlStreamWriter &writer, const QString &path, const QString &value); |
| 97 | |
| 98 | QDocDatabase *m_qdb {}; |
| 99 | Generator *m_gen {}; |
| 100 | |
| 101 | QString m_outputDir {}; |
| 102 | QList<HelpProject> m_projects {}; |
| 103 | }; |
| 104 | |
| 105 | QT_END_NAMESPACE |
| 106 | |
| 107 | #endif |
| 108 | |