C++ドキュメントのスタイル

ドキュメントを生成するために、QDocはソース・コードを調べ、クラスなどのC++型のドキュメントを生成します。その後、QDoc はメンバ関数、プロパティ、その他の型を適切なクラスに関連付けます。

ドキュメントは、.cpp などの実装ファイルに記述する必要があります。

クラス・ドキュメント

クラス・ドキュメントは、第1引数にクラス名を指定し、[class]コマンドを使用して生成されま す。

/*!
    \class QCache
    \brief The QCache class is a template class that provides a cache.

    \ingroup tools
    \ingroup shared

    \reentrant

    QCache\<Key, T\> defines a cache that stores objects of type T
    associated with keys of type Key. For example, here's the
    definition of a cache that stores objects of type Employee
    associated with an integer key:

    \snippet code/doc_src_qcache.cpp 0

    Here's how to insert an object in the cache:

    \snippet code/doc_src_qcache.cpp 1

    ... detailed description omitted

    \sa QPixmapCache, QHash, QMap
*/

コンテキスト・コマンドは、モジュールやクラスが追加されたバージョンなど、クラスに関する 情報を追加します。

一般的なコンテキスト・コマンドは以下のとおりです:

  • \brief- クラスの簡単な説明(必須)
  • \since- クラスが追加されたバージョン(必須)。
  • \internal- クラスを内部クラスとしてマークします。内部クラスは、パブリック API ドキュメントには表示されません。

簡単な説明と詳細な説明

簡単な説明は、クラスの目的や機能を要約するためのものですC++ クラスの場合、QDoc はクラスを受け取り、クラスに対する注釈情報を作成します。注釈付き情報は、クラスを表示するリストや表に表示されます。

C++ の概要は、次のように始まります:

"The <C++ class name> class"

詳細説明セクションは、概要説明の後に始まります。このセクションでは、クラスに関する詳細な情報を提供します。詳細説明には、画像、スニペットコード、他の関連ドキュメントへのリンクを含めることができます。簡単な説明と詳細な説明を区切る空行が必要です。

メンバ関数

通常、関数のドキュメントは、.cpp ファイル内の関数の実装の直前にあります。実装のすぐ上にない関数のドキュメンテーションには、୧⃛(⃙⃘'ᴗ'๑⃙⃘)۶⁾⁾が必要です。

/*!
  \fn QString &QString::remove(int position, int n)

  Removes \a n characters from the string, starting at the given \a
  position index, and returns a reference to the string.

  If the specified \a position index is within the string, but \a
  position + \a n is beyond the end of the string, the string is
  truncated at the specified \a position.

  \snippet qstring/main.cpp 37

  \sa insert(), replace()
*/
QString &QString::remove(int pos, int len)

関数ドキュメントは動詞で始まり、関数が実行する操作を示します。これはコンストラクタとデストラクタにも当てはまります。

関数ドキュメンテーションの一般的な動詞

  • "コンストラクタ..."- コンストラクタの場合
  • "デストロイ..."- デストラクタの場合
  • 「戻り値- アクセサ関数の場合

関数のドキュメントには、以下の内容を記述しなければなりません:

  • 戻り値の型
  • パラメータ
  • 関数のアクション

関数ドキュメンテーションは、以下のことを文書化する必要があります。戻り値の型に関するドキュメントは、型に関するドキュメントにリンクするか、ブーリアン値の 場合は、" \c"コマンドでマークする必要があります。

/*!
    Returns \c true if a QScroller object was already created for \a target; \c false otherwise.

    \sa scroller()
*/
bool QScroller::hasScroller(QObject *target)

プロパティ

プロパティのドキュメントは、read関数の実装のすぐ上にあります。プロパティのトピック・コマンドは \property です。

/*!
    \property QVariantAnimation::duration
    \brief the duration of the animation

    This property describes the duration in milliseconds of the
    animation. The default duration is 250 milliseconds.

    \sa QAbstractAnimation::duration()
 */
int QVariantAnimation::duration() const

プロパティのドキュメントは通常、"This property... "で始まりますが、これは代替表現です:

  • "このプロパティは..."
  • "このプロパティは... "を記述します。
  • "このプロパティは... "を表します。
  • "・・・のときtrue を返し、・・・のときfalse を返す"- 読み込まれるプロパティの場合
  • 「を設定します。- を設定します。

プロパティのドキュメントには、以下を含める必要があります:

  • プロパティの説明と動作
  • プロパティの許容値
  • プロパティのデフォルト値

関数と同様に、デフォルト型はリンクされるか、\c コマンドでマークされるかもしれません。

値域スタイルの例は

値の範囲は0.0(ぼかしなし)からmaximumRadius(最大ぼかし)までです。デフォルトでは、このプロパティは0.0(ぼかしなし)に設定されています。

シグナル、通知、およびスロット

シグナル、ノーティファイア、スロットのトピックコマンドは"˶fn "です。シグナルのドキュメントには、シグナルがトリガーされたとき、または発信されたときの状 況が記載されています。

/*!
  \fn QAbstractTransition::triggered()

  This signal is emitted when the transition has been triggered (after
  onTransition() has been called).
*/

シグナルのドキュメントは通常、"This signal is triggered when... "で始まります。以下は別のスタイルです:

  • 「このシグナルは...のときにトリガーされます。
  • "いつトリガーされるか..."
  • "いつ発せられるか..."

スロットやノーティファイアについては、それらがシグナルによって実行されたりトリガされたりするときの条件を文書化する必要がある。

  • "いつ実行されるか..."
  • "このスロットが実行されるのは..."

オーバーロードされたシグナルを持つプロパティでは、QDocはオーバーロードされたノーティファイアをグループ化します。ノーティファイアやシグナルの特定のバージョンを参照するには、単にプロパティを参照し、ノーティファイアに異なるバージョンがあることに言及してください。

/*!
\property QSpinBox::value
\brief the value of the spin box

setValue() will emit valueChanged() if the new value is different
from the old one. The \l{QSpinBox::}{value} property has a second notifier
signal which includes the spin box's prefix and suffix.
*/

列挙型、名前空間、その他の型

列挙型、名前空間、およびマクロには、それらのドキュメント用のトピック・コマンドがあります:

これらの型の言語スタイルは、それらが列挙型またはマクロであることに言及し、型の説明 を続けます。

列挙型の場合、"value "コマンドは値をリストするためのものです。QDocはenumの値のテーブルを作成します。

/*!
    \enum QSql::TableType

    This enum type describes types of SQL tables.

    \value Tables  All the tables visible to the user.
    \value SystemTables  Internal tables used by the database.
    \value Views  All the views visible to the user.
    \value AllTables  All of the above.
*/

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.