MCPcopy Create free account
hub / github.com/KDE/kdevelop / data

Method data

kdevplatform/language/codecompletion/normaldeclarationcompletionitem.cpp:121–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121QVariant NormalDeclarationCompletionItem::data(const QModelIndex& index, int role,
122 const KDevelop::CodeCompletionModel* model) const
123{
124 DUChainReadLocker lock(DUChain::lock(), 500);
125 if (!lock.locked()) {
126 qCDebug(LANGUAGE) << "Failed to lock the du-chain in time";
127 return QVariant();
128 }
129
130 if (!m_declaration)
131 return QVariant();
132
133 switch (role) {
134 case Qt::DisplayRole:
135 if (index.column() == CodeCompletionModel::Name) {
136 return declarationName();
137 } else if (index.column() == CodeCompletionModel::Postfix) {
138 if (FunctionType::Ptr functionType = m_declaration->type<FunctionType>()) {
139 // Retrieve const/volatile string
140 return functionType->AbstractType::toString();
141 }
142 } else if (index.column() == CodeCompletionModel::Prefix) {
143 if (m_declaration->kind() == Declaration::Namespace)
144 return QStringLiteral("namespace");
145 if (m_declaration->abstractType()) {
146 if (EnumeratorType::Ptr enumerator = m_declaration->type<EnumeratorType>()) {
147 if (m_declaration->context()->owner() && m_declaration->context()->owner()->abstractType()) {
148 if (!m_declaration->context()->owner()->identifier().isEmpty())
149 return shortenedTypeString(DeclarationPointer(
150 m_declaration->context()->owner()), desiredTypeLength);
151 else
152 return QStringLiteral("enum");
153 }
154 }
155 if (FunctionType::Ptr functionType = m_declaration->type<FunctionType>()) {
156 auto* funDecl = dynamic_cast<ClassFunctionDeclaration*>(m_declaration.data());
157
158 if (functionType->returnType()) {
159 QString ret = shortenedTypeString(m_declaration, desiredTypeLength);
160 if (shortenArgumentHintReturnValues && argumentHintDepth() &&
161 ret.length() > maximumArgumentHintReturnValueLength)
162 return QStringLiteral("...");
163 else
164 return ret;
165 } else if (argumentHintDepth()) {
166 return QString();//Don't show useless prefixes in the argument-hints
167 } else if (funDecl && funDecl->isConstructor())
168 return QStringLiteral("<constructor>");
169 else if (funDecl && funDecl->isDestructor())
170 return QStringLiteral("<destructor>");
171 else
172 return QStringLiteral("<incomplete type>");
173 } else {
174 return shortenedTypeString(m_declaration, desiredTypeLength);
175 }
176 } else {
177 return QStringLiteral("<incomplete type>");
178 }

Callers

nothing calls this directly

Calls 15

shortenedTypeStringFunction · 0.85
lockedMethod · 0.80
isConstructorMethod · 0.80
isDestructorMethod · 0.80
partToStringMethod · 0.80
QVariantClass · 0.50
QStringClass · 0.50
columnMethod · 0.45
kindMethod · 0.45
abstractTypeMethod · 0.45
ownerMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected