1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #pragma once
27
28 #include "cpptools_global.h"
29
30 #include <cplusplus/Overview.h>
31
QT_FORWARD_DECLARE_CLASS(QTextCursor)32 QT_FORWARD_DECLARE_CLASS(QTextCursor)
33
34 namespace CPlusPlus { class DeclarationAST; }
35 namespace CPlusPlus { class Snapshot; }
36 namespace Utils { class FilePath; }
37
38 namespace CppTools {
39
40 class CPPTOOLS_EXPORT DoxygenGenerator
41 {
42 public:
43 DoxygenGenerator();
44
45 enum DocumentationStyle {
46 JavaStyle, ///< JavaStyle comment: /**
47 QtStyle, ///< QtStyle comment: /*!
48 CppStyleA, ///< CppStyle comment variant A: ///
49 CppStyleB ///< CppStyle comment variant B: //!
50 };
51
52 void setStyle(DocumentationStyle style);
53 void setStartComment(bool start);
54 void setGenerateBrief(bool gen);
55 void setAddLeadingAsterisks(bool add);
56
57 QString generate(QTextCursor cursor,
58 const CPlusPlus::Snapshot &snapshot,
59 const Utils::FilePath &documentFilePath);
60 QString generate(QTextCursor cursor, CPlusPlus::DeclarationAST *decl);
61
62 private:
63 QChar startMark() const;
64 QChar styleMark() const;
65
66 enum Command {
67 BriefCommand,
68 ParamCommand,
69 ReturnCommand
70 };
71 static QString commandSpelling(Command command);
72
73 void writeStart(QString *comment) const;
74 void writeEnd(QString *comment) const;
75 void writeContinuation(QString *comment) const;
76 void writeNewLine(QString *comment) const;
77 void writeCommand(QString *comment,
78 Command command,
79 const QString &commandContent = QString()) const;
80 void writeBrief(QString *comment,
81 const QString &brief,
82 const QString &prefix = QString(),
83 const QString &suffix = QString());
84
85 void assignCommentOffset(QTextCursor cursor);
86 QString offsetString() const;
87
88 bool m_addLeadingAsterisks = true;
89 bool m_generateBrief = true;
90 bool m_startComment = true;
91 DocumentationStyle m_style = QtStyle;
92 CPlusPlus::Overview m_printer;
93 QString m_commentOffset;
94 };
95
96 } // namespace CppTools
97