Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
parameter.cpp
Go to the documentation of this file.
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
#
include
"parameter.h"
5
6
#
include
<
QtCore
/
qregularexpression
.
h
>
7
8
QT_BEGIN_NAMESPACE
9
10
/*!
11
\class Parameter
12
\brief The Parameter class describes one function parameter.
13
14
A parameter can be a function parameter or a macro parameter.
15
It has a name, a data type, and an optional default value.
16
These are all stored as strings so they can be compared with
17
a parameter in a function signature to find a match.
18
*/
19
20
/*!
21
\fn Parameter::Parameter(const QString &type, const QString &name, const QString &defaultValue)
22
23
Constructs the parameter from the \a type, the optional \a name,
24
and the optional \a defaultValue.
25
*/
26
27
/*!
28
Returns the position within the type string where the parameter
29
name should be inserted, or -1 if the name belongs at the end.
30
31
For types with inside-out declarator syntax (such as references
32
to arrays, pointers to functions, or pointers to members), the
33
parameter name must be inserted inside the type rather than
34
appended after it. Clang produces types like "const char (&)[Size]"
35
or "void (Cls::*)(int)" where the name belongs before the closing
36
paren: "const char (&data)[Size]", "void (Cls::*cb)(int)".
37
*/
38
qsizetype Parameter::nameInsertionPoint()
const
39
{
40
static
const
QRegularExpression insideOutDeclarator(
41
QStringLiteral(R"((\([^)]*[&*]\))\s*(\[|\())"));
42
auto
match = insideOutDeclarator.match(m_type);
43
if
(match.hasMatch())
44
return
match.capturedStart(1) + match.capturedLength(1) - 1;
45
return
-1;
46
}
47
48
/*!
49
Reconstructs the text signature for the parameter and returns
50
it. If \a includeValue is true and there is a default value,
51
the default value is appended with '='.
52
*/
53
QString
Parameter
::
signature
(
bool
includeValue)
const
54
{
55
QString p = m_type;
56
if
(!m_name.isEmpty()) {
57
qsizetype insertPos = nameInsertionPoint();
58
if
(insertPos >= 0) {
59
p.insert(insertPos, m_name);
60
}
else
{
61
if
(!p.isEmpty() && !p.endsWith(QChar(
'*'
)) && !p.endsWith(QChar(
'&'
))
62
&& !p.endsWith(QChar(
' '
))) {
63
p += QLatin1Char(
' '
);
64
}
65
p += m_name;
66
}
67
}
68
if
(includeValue && !m_defaultValue.isEmpty())
69
p +=
" = "
+ m_defaultValue;
70
return
p;
71
}
72
73
QT_END_NAMESPACE
Parameter
The Parameter class describes one function parameter.
Definition
parameter.h:14
Parameter::signature
QString signature(bool includeValue=false) const
Reconstructs the text signature for the parameter and returns it.
Definition
parameter.cpp:53
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qttools
src
qdoc
qdoc
src
qdoc
parameter.cpp
Generated on
for Qt by
1.18.0