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 | QHash<QString, const Node *> m_nodes {}; |
29 | QStringList m_groups {}; |
30 | }; |
31 | |
32 | /* |
33 | * Name is the human-readable name to be shown in Assistant. |
34 | * Ids is a list of unique identifiers. |
35 | * Ref is the location of the documentation for the keyword. |
36 | */ |
37 | struct Keyword { |
38 | QString m_name {}; |
39 | QStringList m_ids {}; |
40 | QString m_ref {}; |
41 | Keyword(QString name, const QString &id, QString ref) |
42 | : m_name(std::move(name)), m_ids(QStringList(id)), m_ref(std::move(ref)) |
43 | { |
44 | } |
45 | Keyword(QString name, QStringList ids, QString ref) |
46 | : m_name(std::move(name)), m_ids(std::move(ids)), m_ref(std::move(ref)) |
47 | { |
48 | } |
49 | bool operator<(const Keyword &o) const |
50 | { |
51 | // Order by name; use ref as a secondary sort key |
52 | return (m_name == o.m_name) ? m_ref < o.m_ref : m_name < o.m_name; |
53 | } |
54 | }; |
55 | |
56 | struct HelpProject |
57 | { |
58 | using NodeStatusSet = QSet<unsigned char>; |
59 | |
60 | QString m_name {}; |
61 | QString m_helpNamespace {}; |
62 | QString m_virtualFolder {}; |
63 | QString m_version {}; |
64 | QString m_fileName {}; |
65 | QString m_indexRoot {}; |
66 | QString m_indexTitle {}; |
67 | QList<Keyword> m_keywords {}; |
68 | QSet<QString> m_files {}; |
69 | QSet<QString> {}; |
70 | QSet<QString> m_filterAttributes {}; |
71 | QHash<QString, QSet<QString>> m_customFilters {}; |
72 | QSet<QString> m_excluded {}; |
73 | QList<SubProject> m_subprojects {}; |
74 | QHash<const Node *, NodeStatusSet> m_memberStatus {}; |
75 | bool m_includeIndexNodes {}; |
76 | }; |
77 | |
78 | |
79 | class HelpProjectWriter |
80 | { |
81 | public: |
82 | HelpProjectWriter(const QString &defaultFileName, Generator *g); |
83 | void reset(const QString &defaultFileName, Generator *g); |
84 | void (const QString &file); |
85 | void generate(); |
86 | |
87 | private: |
88 | void generateProject(HelpProject &project); |
89 | void generateSections(HelpProject &project, QXmlStreamWriter &writer, const Node *node); |
90 | bool generateSection(HelpProject &project, QXmlStreamWriter &writer, const Node *node); |
91 | Keyword keywordDetails(const Node *node) const; |
92 | void writeHashFile(QFile &file); |
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 | |