| 298 | } |
| 299 | |
| 300 | QVariant CodeCompletionModel::data(const QModelIndex& index, int role) const |
| 301 | { |
| 302 | if (role == Qt::TextAlignmentRole && index.column() == 0) { |
| 303 | return Qt::AlignRight; |
| 304 | } |
| 305 | auto element = static_cast<const CompletionTreeElement*>(index.internalPointer()); |
| 306 | if (!element) |
| 307 | return QVariant(); |
| 308 | |
| 309 | if (role == CodeCompletionModel::GroupRole) { |
| 310 | if (element->asNode()) { |
| 311 | return QVariant(element->asNode()->role); |
| 312 | } else { |
| 313 | qCDebug(LANGUAGE) << "Requested group-role from leaf tree element"; |
| 314 | return QVariant(); |
| 315 | } |
| 316 | } else { |
| 317 | if (element->asNode()) { |
| 318 | if (role == CodeCompletionModel::InheritanceDepth) { |
| 319 | auto customGroupNode = dynamic_cast<const CompletionCustomGroupNode*>(element); |
| 320 | if (customGroupNode) |
| 321 | return QVariant(customGroupNode->inheritanceDepth); |
| 322 | } |
| 323 | if (role == element->asNode()->role) { |
| 324 | return element->asNode()->roleValue; |
| 325 | } else { |
| 326 | return QVariant(); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | if (!element->asItem()) { |
| 332 | qCWarning(LANGUAGE) << "Error in completion model"; |
| 333 | return QVariant(); |
| 334 | } |
| 335 | |
| 336 | //Navigation widget interaction is done here, the other stuff is done within the tree-elements |
| 337 | switch (role) { |
| 338 | case CodeCompletionModel::InheritanceDepth: |
| 339 | return element->asItem()->inheritanceDepth(); |
| 340 | case CodeCompletionModel::ArgumentHintDepth: |
| 341 | return element->asItem()->argumentHintDepth(); |
| 342 | |
| 343 | case CodeCompletionModel::ItemSelected: { |
| 344 | DeclarationPointer decl = element->asItem()->declaration(); |
| 345 | if (decl) { |
| 346 | DUChain::self()->emitDeclarationSelected(decl); |
| 347 | } |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | //In minimal completion mode, hide all columns except the "name" one |
| 353 | if (!m_fullCompletion && role == Qt::DisplayRole && index.column() != Name && |
| 354 | (element->asItem()->argumentHintDepth() == 0 || index.column() == Prefix)) |
| 355 | return QVariant(); |
| 356 | |
| 357 | //In reduced completion mode, don't show information text with the selected items |
no test coverage detected