1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2019 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the tools applications of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 /* 30 doc.h 31 */ 32 33 #ifndef DOC_H 34 #define DOC_H 35 36 #include "location.h" 37 38 #include <QtCore/qmap.h> 39 #include <QtCore/qset.h> 40 #include <QtCore/qstring.h> 41 42 QT_BEGIN_NAMESPACE 43 44 class Atom; 45 class CodeMarker; 46 class DocPrivate; 47 class Quoter; 48 class Text; 49 class DitaRef; 50 51 typedef QPair<QString, Location> ArgLocPair; 52 typedef QVector<ArgLocPair> ArgList; 53 typedef QMap<QString, QString> QStringMap; 54 typedef QMultiMap<QString, QString> QStringMultiMap; 55 56 struct Topic 57 { 58 QString topic; 59 QString args; TopicTopic60 Topic() {} TopicTopic61 Topic(QString &t, const QString &a) : topic(t), args(a) {} isEmptyTopic62 bool isEmpty() const { return topic.isEmpty(); } clearTopic63 void clear() 64 { 65 topic.clear(); 66 args.clear(); 67 } 68 }; 69 typedef QVector<Topic> TopicList; 70 71 typedef QVector<DitaRef *> DitaRefList; 72 73 class DitaRef 74 { 75 public: DitaRef()76 DitaRef() {} ~DitaRef()77 virtual ~DitaRef() {} 78 navtitle()79 const QString &navtitle() const { return navtitle_; } href()80 const QString &href() const { return href_; } setNavtitle(const QString & t)81 void setNavtitle(const QString &t) { navtitle_ = t; } setHref(const QString & t)82 void setHref(const QString &t) { href_ = t; } 83 virtual bool isMapRef() const = 0; subrefs()84 virtual const DitaRefList *subrefs() const { return nullptr; } appendSubref(DitaRef *)85 virtual void appendSubref(DitaRef *) {} 86 87 private: 88 QString navtitle_; 89 QString href_; 90 }; 91 92 class TopicRef : public DitaRef 93 { 94 public: TopicRef()95 TopicRef() {} 96 ~TopicRef() override; 97 isMapRef()98 bool isMapRef() const override { return false; } subrefs()99 const DitaRefList *subrefs() const override { return &subrefs_; } appendSubref(DitaRef * t)100 void appendSubref(DitaRef *t) override { subrefs_.append(t); } 101 102 private: 103 DitaRefList subrefs_; 104 }; 105 106 class MapRef : public DitaRef 107 { 108 public: MapRef()109 MapRef() {} 110 isMapRef()111 bool isMapRef() const override { return true; } 112 }; 113 114 class Doc 115 { 116 Q_DECLARE_TR_FUNCTIONS(QDoc::Doc) 117 118 public: 119 // the order is important 120 enum Sections { 121 NoSection = -2, 122 Part = -1, 123 Chapter = 1, 124 Section1 = 1, 125 Section2 = 2, 126 Section3 = 3, 127 Section4 = 4 128 }; 129 Doc()130 Doc() : priv(nullptr) {} 131 Doc(const Location &start_loc, const Location &end_loc, const QString &source, 132 const QSet<QString> &metaCommandSet, const QSet<QString> &topics); 133 Doc(const Doc &doc); 134 ~Doc(); 135 136 Doc &operator=(const Doc &doc); 137 void simplifyEnumDoc(); 138 void setBody(const Text &body); 139 const DitaRefList &ditamap() const; 140 141 const Location &location() const; 142 const Location &startLocation() const; 143 const Location &endLocation() const; 144 bool isEmpty() const; 145 const QString &source() const; 146 const Text &body() const; 147 Text briefText(bool inclusive = false) const; 148 Text trimmedBriefText(const QString &className) const; 149 Text legaleseText() const; 150 Sections granularity() const; 151 const QSet<QString> ¶meterNames() const; 152 const QStringList &enumItemNames() const; 153 const QStringList &omitEnumItemNames() const; 154 const QSet<QString> &metaCommandsUsed() const; 155 const TopicList &topicsUsed() const; 156 ArgList metaCommandArgs(const QString &metaCommand) const; 157 const QVector<Text> &alsoList() const; 158 bool hasTableOfContents() const; 159 bool hasKeywords() const; 160 bool hasTargets() const; 161 bool isInternal() const; 162 bool isMarkedReimp() const; 163 const QVector<Atom *> &tableOfContents() const; 164 const QVector<int> &tableOfContentsLevels() const; 165 const QVector<Atom *> &keywords() const; 166 const QVector<Atom *> &targets() const; 167 const QStringMultiMap &metaTagMap() const; 168 169 static void initialize(); 170 static void terminate(); 171 static QString alias(const QString &english); 172 static void trimCStyleComment(Location &location, QString &str); 173 static QString resolveFile(const Location &location, const QString &fileName, 174 QString *userFriendlyFilePath = nullptr); 175 static CodeMarker *quoteFromFile(const Location &location, Quoter "er, 176 const QString &fileName); 177 static QString canonicalTitle(const QString &title); 178 179 private: 180 void detach(); 181 DocPrivate *priv; 182 }; 183 Q_DECLARE_TYPEINFO(Doc, Q_MOVABLE_TYPE); 184 typedef QVector<Doc> DocList; 185 186 QT_END_NAMESPACE 187 188 #endif 189