Writing Qt Documentation: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=Writing Qt Documentation=
[[Category:Developing Qt::Documentation]]<br />[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]
 
= Writing Qt Documentation =


This document contains some documentation style guidelines that have been used when documenting Qt over the past few years.
This document contains some documentation style guidelines that have been used when documenting Qt over the past few years.


It may be helpful to refer to the online [http://doc.qt.digia.com/qdoc qdoc manual] ''[doc.qt.digia.com]''.
It may be helpful to refer to the online &quot;qdoc manual&amp;quot;:http://doc.qt.digia.com/qdoc.


See [[Building Qt Documentation|Building_Qt_Documentation]] for instructions on the usual way to build the Qt documentation.
See [[Building_Qt_Documentation]] for instructions on the usual way to build the Qt documentation.


See [[Troubleshooting-Qt-Documentation|Troubleshooting Qt Documentation]] for advice on what to look for if your documentation is not processed correctly by qdoc.
See [[Troubleshooting Qt Documentation]] for advice on what to look for if your documentation is not processed correctly by qdoc.


See [[:Category:Developing Qt::Documentation|Developing Qt Documentation]] ''[qt.io]'' for information about the documentation process.<br /> h2. <span class="caps">API</span> documentation
See &quot;Developing Qt Documentation&amp;quot;:http://wiki.qt.io/Category:Developing_Qt::Documentation for information about the documentation process.<br />h2. API documentation


==General==
== General ==


* Write complete sentences for \value items in \enum lists.
* Write complete sentences for items in lists.
* Use only real <span class="caps">URL</span>s if absolutely necessary, otherwise use “[http://example.xn--com-9o0a. http://example.com”.] Use \externalpage documents to create fake pages for external documents that you can refer to by title.
* Use only real URLs if absolutely necessary, otherwise use &quot;http://example.com&amp;quot;. Use documents to create fake pages for external documents that you can refer to by title.
* Indent using spaces, not tabs.
* Indent using spaces, not tabs.


==Use of language==
== Use of language ==


* Hyphenation is not normally needed nor used.
* Hyphenation is not normally needed nor used.
* Shorthand is discouraged.
* Shorthand is discouraged.
** For example, “and” should be used in preference to &amp;unless there is a very good reason.
** For example, &quot;and&amp;quot; should be used in preference to &quot;&amp;&quot; unless there is a very good reason.
* Each word in a title (either a page title or a section title) should start with an upper case letter, except for the [http://en.wikipedia.org/wiki/Preposition most common prepositions] ''[en.wikipedia.org]'' (of, to, in, for, with and on) and [http://en.wikipedia.org/wiki/Grammatical_conjunction coordinating conjunctions] ''[en.wikipedia.org]'' (for, and, nor, but, or, yet, and so).
* Each word in a title (either a page title or a section title) should start with an upper case letter, except for the &quot;most common prepositions&amp;quot;:http://en.wikipedia.org/wiki/Preposition (of, to, in, for, with and on) and &quot;coordinating conjunctions&amp;quot;:http://en.wikipedia.org/wiki/Grammatical_conjunction (for, and, nor, but, or, yet, and so).
** For example, “Anchor Margins and Offsets” not “Anchor margins and offsets” (lower case is wrong) or “Anchor Margins And Offsets” (“and” should be lower case).
** For example, &quot;Anchor Margins and Offsets&amp;quot; not &quot;Anchor margins and offsets&amp;quot; (lower case is wrong) or &quot;Anchor Margins And Offsets&amp;quot; (&quot;and&amp;quot; should be lower case).


===Overview/modules===
=== Overview/modules ===


* Shows/describes how classes in the module are used together.
* Shows/describes how classes in the module are used together.
* Describes the main concepts and features of groups of classes.
* Describes the main concepts and features of groups of classes.


===Class descriptions===
=== Class descriptions ===


* Brief overview
* Brief overview
* Start the main body of text with something like, “A &lt;plain language name&gt; is a…”
* Start the main body of text with something like, &quot;A &lt;plain language name&amp;gt; is a…&quot;
* Alternative classes, e.g.
* Alternative classes, e.g.
** <code>QTable</code> / <code>QListView</code>
** &lt;code&amp;gt;QTable&amp;lt;/code&amp;gt; / &lt;code&amp;gt;QListView&amp;lt;/code&amp;gt;
** <code>QListBox</code> / <code>QComboBox</code>
** &lt;code&amp;gt;QListBox&amp;lt;/code&amp;gt; / &lt;code&amp;gt;QComboBox&amp;lt;/code&amp;gt;
** <code>QDial</code> / <code>QSlider</code> / <code>QSpinBox</code>
** &lt;code&amp;gt;QDial&amp;lt;/code&amp;gt; / &lt;code&amp;gt;QSlider&amp;lt;/code&amp;gt; / &lt;code&amp;gt;QSpinBox&amp;lt;/code&amp;gt;
* Patterns of use
* Patterns of use
** Minimal
** Minimal
** Realistic: quotes from snippets in the ''doc'' directory, and examples in the ''qt/examples'' directory
** Realistic: quotes from snippets in the ''doc'' directory, and examples in the ''qt/examples'' directory
* Concepts; e.g.
* Concepts; e.g.
** <code>QTextEdit</code>: lines vs. paragraphs
** &lt;code&amp;gt;QTextEdit&amp;lt;/code&amp;gt;: lines vs. paragraphs
** In Qt 3, <code>QCanvas</code> is abstract; <code>QCanvasView</code> actually displays the canvas
** In Qt 3, &lt;code&amp;gt;QCanvas&amp;lt;/code&amp;gt; is abstract; &lt;code&amp;gt;QCanvasView&amp;lt;/code&amp;gt; actually displays the canvas
* Details
* Details
** Describes and groups together functions with common features
** Describes and groups together functions with common features
Line 49: Line 51:
Some examples of Qt documentation:
Some examples of Qt documentation:


* [http://doc.qt.digia.com/4.6/qstring.html QString] ''[doc.qt.digia.com]'' covers the use cases but is a little too technical at the start.
* &quot;QString&amp;quot;:http://doc.qt.digia.com/4.6/qstring.html covers the use cases but is a little too technical at the start.
* [http://doc.qt.digia.com/4.6/qdir.html QDir] ''[doc.qt.digia.com]'' is an example of a newer style where we used titles to split up different use cases.
* &quot;QDir&amp;quot;:http://doc.qt.digia.com/4.6/qdir.html is an example of a newer style where we used titles to split up different use cases.
* [http://doc.qt.digia.com/4.6/qmenu.html QMenu] ''[doc.qt.digia.com]'' is brief, but to the point, though it could use some code examples.
* &quot;QMenu&amp;quot;:http://doc.qt.digia.com/4.6/qmenu.html is brief, but to the point, though it could use some code examples.
* [http://doc.qt.digia.com/4.6/qdialog.html QDialog] ''[doc.qt.digia.com]'' cover various important concepts but should really address the practicalities of subclassing QDialog to implement your own dialog.
* &quot;QDialog&amp;quot;:http://doc.qt.digia.com/4.6/qdialog.html cover various important concepts but should really address the practicalities of subclassing QDialog to implement your own dialog.
* [http://doc.qt.digia.com/4.6/qpushbutton.html QPushButton] ''[doc.qt.digia.com]'' is a reasonable example of documentation for a simple widget.
* &quot;QPushButton&amp;quot;:http://doc.qt.digia.com/4.6/qpushbutton.html is a reasonable example of documentation for a simple widget.
* [http://doc.qt.digia.com/4.6/qgraphicsscene.html QGraphicsScene] ''[doc.qt.digia.com]'' is OK but could really use some code examples.
* &quot;QGraphicsScene&amp;quot;:http://doc.qt.digia.com/4.6/qgraphicsscene.html is OK but could really use some code examples.
* [http://doc.qt.digia.com/4.6/qpainter.html QPainter] ''[doc.qt.digia.com]'' is quite good at showing what the class does (in the documentation for the functions), but the main description tends to contain lists of functions. A lot of that should have been moved into an overview, in my opinion.
* &quot;QPainter&amp;quot;:http://doc.qt.digia.com/4.6/qpainter.html is quite good at showing what the class does (in the documentation for the functions), but the main description tends to contain lists of functions. A lot of that should have been moved into an overview, in my opinion.


I’m sure I haven’t found the “best” examples of documentation. These are just a few cases that I didn’t consider to be in need of radical improvement.
I'm sure I haven't found the &quot;best&amp;quot; examples of documentation. These are just a few cases that I didn't consider to be in need of radical improvement.


The guidelines I learned basically followed the “pyramid” approach of providing a bit of simple information, then some more detailed information, followed by even more complex information about each class.
The guidelines I learned basically followed the &quot;pyramid&amp;quot; approach of providing a bit of simple information, then some more detailed information, followed by even more complex information about each class.


# Describe what the class is/does.
# Describe what the class is/does.
Line 71: Line 73:
There should, of course, be links to functions/methods and other classes throughout. Images are also good to include, either in terms of showing what a widget looks like or to illustrate a concept.
There should, of course, be links to functions/methods and other classes throughout. Images are also good to include, either in terms of showing what a widget looks like or to illustrate a concept.


===Function descriptions===
=== Function descriptions ===


* <code>\brief</code> descriptions:
* &lt;code&amp;gt;&lt;/code&amp;gt; descriptions:
** Property descriptions should start with a lower case letter and have no ending period.
** Property descriptions should start with a lower case letter and have no ending period.
** Class descriptions should be complete sentences.
** Class descriptions should be complete sentences.
* Constructors should read something like, “Constructs the … with the given \a parent.
* Constructors should read something like, &quot;Constructs the … with the given parent.&quot;
* Introduce arguments/parameters using the following two phrases:
* Introduce arguments/parameters using the following two phrases:
** … is specified by …
** … is specified by …
Line 83: Line 85:
** … is given by …
** … is given by …


==Use of parameter names==
== Use of parameter names ==


'''Don’t use natural language phrases that make the operation ambiguous:'''
'''Don't use natural language phrases that make the operation ambiguous:'''
 
<code><br />void Treasure::setValue(SomeClass *value)<br /></code>


Sets the ''value'' of the treasure.
Sets the ''value'' of the treasure.
Line 93: Line 97:
Sets the value of the treasure to ''value''.
Sets the value of the treasure to ''value''.


The above use relies on a coincidence between the action on the instance and<br /> the value to use. It could also give the impression that <code>value</code> is<br /> changed in some way.
The above use relies on a coincidence between the action on the instance and<br />the value to use. It could also give the impression that &lt;code&amp;gt;value&amp;lt;/code&amp;gt; is<br />changed in some way.


'''Avoid overspecifying definitions:'''
'''Avoid overspecifying definitions:'''
<code><br />MyWidget::MyWidget(const QString &amp;name;, QWidget *parent)<br /></code>


Constructs a new widget with name ''name'' and parent ''parent''.
Constructs a new widget with name ''name'' and parent ''parent''.
Line 103: Line 109:
Constructs a new widget with the given ''name'' and ''parent''.
Constructs a new widget with the given ''name'' and ''parent''.


'''Don’t change commonly used parameter names to suit local documentation requirements:'''
'''Don't change commonly used parameter names to suit local documentation requirements:'''
 
<code><br />void CanvasItem::setBoundingRect(const QRect &amp;rectangle);<br /></code>


Sets the bounding ''rectangle'' of the widget.
Sets the bounding ''rectangle'' of the widget.


The original <code>rect</code> parameter should not be renamed to ''rectangle''.<br /> Instead we would write something explicit:
The original &lt;code&amp;gt;rect&amp;lt;/code&amp;gt; parameter should not be renamed to ''rectangle''.<br />Instead we would write something explicit:


Sets the bounding rectangle of the widget to ''rect''.
Sets the bounding rectangle of the widget to ''rect''.


===Miscellaneous===
=== Miscellaneous ===


* Use <code>\omit</code> and <code>\endomit</code> to omit sections from the documentation.
* Use &lt;code&amp;gt;&lt;/code&amp;gt; and &lt;code&amp;gt;&lt;/code&amp;gt; to omit sections from the documentation.
** Remember that they are still present in the documentation source text.
** Remember that they are still present in the documentation source text.
* Use <code>\omitvalue</code> to omit enum values from the documentation, but still allow ''qdoc'' to process them without complaint.
* Use &lt;code&amp;gt;&lt;/code&amp;gt; to omit enum values from the documentation, but still allow ''qdoc'' to process them without complaint.


==Style of example code==
== Style of example code ==


See WritingQtExamples for more detailed guidance about writing and documenting examples.
See WritingQtExamples for more detailed guidance about writing and documenting examples.


===Objectives===
=== Objectives ===


Examples should be
Examples should be
Line 129: Line 137:
* Cover the key concepts
* Cover the key concepts


===In header files===
=== In header files ===


* Give parameter names for used parameters.
* Give parameter names for used parameters.
Line 136: Line 144:
* Only include header files that are absolutely necessary.
* Only include header files that are absolutely necessary.


===In C++ files===
=== In C++ files ===


* Order of actions in the constructor:
* Order of actions in the constructor:
Line 142: Line 150:
** Set the connections.
** Set the connections.
** Create layout and insert items.
** Create layout and insert items.
** Set the title of top-level widgets with <code>setWindowTitle()</code>.
** Set the title of top-level widgets with &lt;code&amp;gt;setWindowTitle()&lt;/code&amp;gt;.


* Accelerators and translations
* Accelerators and translations
** Use translation strings rather than hardcoded accelerator flags; e.g. <code>tr(“Ctrl+Q”)</code> rather than <code><span class="caps">CTRL</span> + Key_Q</code>
** Use translation strings rather than hardcoded accelerator flags; e.g. &lt;code&amp;gt;tr(&quot;Ctrl+Q&amp;quot;)&lt;/code&amp;gt; rather than &lt;code&amp;gt;CTRL + Key_Q&amp;lt;/code&amp;gt;
** Note that Qt provides [http://doc.qt.digia.com/stable/qkeysequence.html#StandardKey-enum enum values for standard shortcuts] ''[doc.qt.digia.com]'' which should be used in preference
** Note that Qt provides &quot;enum values for standard shortcuts&amp;quot;:http://doc.qt.digia.com/stable/qkeysequence.html#StandardKey-enum which should be used in preference
* Comments:
* Comments:
** Introductory comment for each file. What the file is for.
** Introductory comment for each file. What the file is for.
Line 152: Line 160:
** General comments about functions go outside the function in a multiline comment.
** General comments about functions go outside the function in a multiline comment.
** What: the code itself.
** What: the code itself.
** Why: reason something is needed high level. (Outside function.)
** Why: reason something is needed - high level. (Outside function.)
** How: the way these actions are performed. (Outside function.)
** How: the way these actions are performed. (Outside function.)


===Variable naming===
=== Variable naming ===


From a commit message made on 2004/05/28 16:08:34:
From a commit message made on 2004/05/28 16:08:34:


&lt;pre&gt; Renamed some “flag enum” types to be more consistent (i.e. the enum type associated to a flag type through Q_DECLARE_FLAGS).
&lt;pre&amp;gt;<br /> Renamed some &quot;flag enum&amp;quot; types to be more consistent (i.e.<br /> the enum type associated to a flag type through Q_DECLARE_FLAGS).
 
Usually, the enum type isn't used directly; only the flags type<br /> is. Still, sometimes we do use it, and then it's important to have<br /> a good name. Also, the documentation shows that name.
 
The rule I've tried to follow were:


Usually, the enum type isn’t used directly; only the flags type is. Still, sometimes we do use it, and then it’s important to have a good name. Also, the documentation shows that name. The rule I’ve tried to follow were: 1. If the flags type is a plural (e.g. Options, Actions, Flags), make the enum type a singular (e.g. Option, Action, Flag). 2. Otherwise, make the enum type by appending “Flag” to the flags type (e.g. Alignment is the flags type, AlignmentFlag is the enum type). Notice that “Flag” is a singular. This is because an enum of that type can only store one flag at a time (whereas a variable of the “flags” type can store many). &lt;/pre&gt;
1. If the flags type is a plural (e.g. Options, Actions, Flags),<br /> make the enum type a singular (e.g. Option, Action, Flag).


===Documentation structure===
2. Otherwise, make the enum type by appending &quot;Flag&amp;quot; to the<br /> flags type (e.g. Alignment is the flags type, AlignmentFlag<br /> is the enum type).
 
Notice that &quot;Flag&amp;quot; is a singular. This is because an enum of that<br /> type can only store one flag at a time (whereas a variable of the<br /> &quot;flags&amp;quot; type can store many).<br />&lt;/pre&amp;gt;
 
=== Documentation structure ===


* Necessary files to build the example.
* Necessary files to build the example.
* Overview document (to be converted by ''qdoc'' to some other format).
* Overview document (to be converted by ''qdoc'' to some other format).


[toc align_right=
[[Category:Developing Qt::Documentation]]
 
===Categories:===
 
* [[:Category:Developing-Qt|Developing Qt]]
** [[:Category:Developing-Qt::Documentation|Documentation]]

Revision as of 14:44, 23 February 2015


[toc align_right="yes&quot; depth="3&quot;]

Writing Qt Documentation

This document contains some documentation style guidelines that have been used when documenting Qt over the past few years.

It may be helpful to refer to the online "qdoc manual&quot;:http://doc.qt.digia.com/qdoc.

See Building_Qt_Documentation for instructions on the usual way to build the Qt documentation.

See Troubleshooting Qt Documentation for advice on what to look for if your documentation is not processed correctly by qdoc.

See "Developing Qt Documentation&quot;:http://wiki.qt.io/Category:Developing_Qt::Documentation for information about the documentation process.
h2. API documentation

General

  • Write complete sentences for items in lists.
  • Use only real URLs if absolutely necessary, otherwise use "http://example.com&quot;. Use documents to create fake pages for external documents that you can refer to by title.
  • Indent using spaces, not tabs.

Use of language

  • Hyphenation is not normally needed nor used.
  • Shorthand is discouraged.
    • For example, "and&quot; should be used in preference to "&" unless there is a very good reason.
  • Each word in a title (either a page title or a section title) should start with an upper case letter, except for the "most common prepositions&quot;:http://en.wikipedia.org/wiki/Preposition (of, to, in, for, with and on) and "coordinating conjunctions&quot;:http://en.wikipedia.org/wiki/Grammatical_conjunction (for, and, nor, but, or, yet, and so).
    • For example, "Anchor Margins and Offsets&quot; not "Anchor margins and offsets&quot; (lower case is wrong) or "Anchor Margins And Offsets&quot; ("and&quot; should be lower case).

Overview/modules

  • Shows/describes how classes in the module are used together.
  • Describes the main concepts and features of groups of classes.

Class descriptions

  • Brief overview
  • Start the main body of text with something like, "A <plain language name&gt; is a…"
  • Alternative classes, e.g.
    • <code&gt;QTable&lt;/code&gt; / <code&gt;QListView&lt;/code&gt;
    • <code&gt;QListBox&lt;/code&gt; / <code&gt;QComboBox&lt;/code&gt;
    • <code&gt;QDial&lt;/code&gt; / <code&gt;QSlider&lt;/code&gt; / <code&gt;QSpinBox&lt;/code&gt;
  • Patterns of use
    • Minimal
    • Realistic: quotes from snippets in the doc directory, and examples in the qt/examples directory
  • Concepts; e.g.
    • <code&gt;QTextEdit&lt;/code&gt;: lines vs. paragraphs
    • In Qt 3, <code&gt;QCanvas&lt;/code&gt; is abstract; <code&gt;QCanvasView&lt;/code&gt; actually displays the canvas
  • Details
    • Describes and groups together functions with common features

Some examples of Qt documentation:

I'm sure I haven't found the "best&quot; examples of documentation. These are just a few cases that I didn't consider to be in need of radical improvement.

The guidelines I learned basically followed the "pyramid&quot; approach of providing a bit of simple information, then some more detailed information, followed by even more complex information about each class.

  1. Describe what the class is/does.
  2. Refer the reader to other relevant classes or documents describing the concepts.
  3. Show a simple use case, if possible.
  4. Describe the features, beginning with the simplest, most commonly used ones, showing relevant, simple code snippets. Try to group these into categories.
  5. Describe more complex features that may involve interaction with other classes.
  6. Discuss subclassing if relevant, and describe what the developer needs to take care of when doing this.
  7. Put links to relevant documents, perhaps in a section of their own, but at least in a see-also line at the end of the detailed description.

There should, of course, be links to functions/methods and other classes throughout. Images are also good to include, either in terms of showing what a widget looks like or to illustrate a concept.

Function descriptions

  • <code&gt;</code&gt; descriptions:
    • Property descriptions should start with a lower case letter and have no ending period.
    • Class descriptions should be complete sentences.
  • Constructors should read something like, "Constructs the … with the given parent."
  • Introduce arguments/parameters using the following two phrases:
    • … is specified by …
    • … in the given …
  • Do not use
    • … is given by …

Use of parameter names

Don't use natural language phrases that make the operation ambiguous:

<br />void Treasure::setValue(SomeClass *value)<br />

Sets the value of the treasure.

It would be better to write something explicit:

Sets the value of the treasure to value.

The above use relies on a coincidence between the action on the instance and
the value to use. It could also give the impression that <code&gt;value&lt;/code&gt; is
changed in some way.

Avoid overspecifying definitions:

<br />MyWidget::MyWidget(const QString &amp;name;, QWidget *parent)<br />

Constructs a new widget with name name and parent parent.

Maybe something like the following would be acceptable:

Constructs a new widget with the given name and parent.

Don't change commonly used parameter names to suit local documentation requirements:

<br />void CanvasItem::setBoundingRect(const QRect &amp;rectangle);<br />

Sets the bounding rectangle of the widget.

The original <code&gt;rect&lt;/code&gt; parameter should not be renamed to rectangle.
Instead we would write something explicit:

Sets the bounding rectangle of the widget to rect.

Miscellaneous

  • Use <code&gt;</code&gt; and <code&gt;</code&gt; to omit sections from the documentation.
    • Remember that they are still present in the documentation source text.
  • Use <code&gt;</code&gt; to omit enum values from the documentation, but still allow qdoc to process them without complaint.

Style of example code

See WritingQtExamples for more detailed guidance about writing and documenting examples.

Objectives

Examples should be

  • Simple
  • Bland (not necessarily)
  • Cover the key concepts

In header files

  • Give parameter names for used parameters.
  • Write declared variables of the same type on separate lines.
  • No underscores in names.
  • Only include header files that are absolutely necessary.

In C++ files

  • Order of actions in the constructor:
    • Create each widget and set options for it.
    • Set the connections.
    • Create layout and insert items.
    • Set the title of top-level widgets with <code&gt;setWindowTitle()</code&gt;.
  • Accelerators and translations
  • Comments:
    • Introductory comment for each file. What the file is for.
    • No comments where the purpose of the code is clear.
    • General comments about functions go outside the function in a multiline comment.
    • What: the code itself.
    • Why: reason something is needed - high level. (Outside function.)
    • How: the way these actions are performed. (Outside function.)

Variable naming

From a commit message made on 2004/05/28 16:08:34:

<pre&gt;
Renamed some "flag enum&quot; types to be more consistent (i.e.
the enum type associated to a flag type through Q_DECLARE_FLAGS).

Usually, the enum type isn't used directly; only the flags type
is. Still, sometimes we do use it, and then it's important to have
a good name. Also, the documentation shows that name.

The rule I've tried to follow were:

1. If the flags type is a plural (e.g. Options, Actions, Flags),
make the enum type a singular (e.g. Option, Action, Flag).

2. Otherwise, make the enum type by appending "Flag&quot; to the
flags type (e.g. Alignment is the flags type, AlignmentFlag
is the enum type).

Notice that "Flag&quot; is a singular. This is because an enum of that
type can only store one flag at a time (whereas a variable of the
"flags&quot; type can store many).
</pre&gt;

Documentation structure

  • Necessary files to build the example.
  • Overview document (to be converted by qdoc to some other format).