| 480 | } |
| 481 | |
| 482 | TopContextUsesWidget::TopContextUsesWidget(IndexedDeclaration declaration, |
| 483 | const QList<IndexedDeclaration>& allDeclarations, |
| 484 | IndexedTopDUContext topContext) |
| 485 | : m_topContext(topContext) |
| 486 | , m_declaration(declaration) |
| 487 | , m_allDeclarations(allDeclarations) |
| 488 | , m_usesCount(0) |
| 489 | { |
| 490 | m_itemLayout->setContentsMargins(10, 0, 0, 5); |
| 491 | setFrameShape(NoFrame); |
| 492 | setUpdatesEnabled(false); |
| 493 | DUChainReadLocker lock(DUChain::lock()); |
| 494 | auto* labelLayout = new QHBoxLayout; |
| 495 | labelLayout->setContentsMargins(0, -1, 0, 0); // let's keep the spacing *above* the line |
| 496 | auto* headerWidget = new QWidget; |
| 497 | headerWidget->setLayout(labelLayout); |
| 498 | headerWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); |
| 499 | |
| 500 | auto* label = new QLabel(this); |
| 501 | m_icon = new QLabel(this); |
| 502 | m_toggleButton = new QLabel(this); |
| 503 | m_icon->setPixmap(QIcon::fromTheme(QStringLiteral("code-class")).pixmap(16)); |
| 504 | labelLayout->addWidget(m_icon); |
| 505 | labelLayout->addWidget(label); |
| 506 | labelLayout->addWidget(m_toggleButton); |
| 507 | labelLayout->setAlignment(Qt::AlignLeft); |
| 508 | |
| 509 | if (topContext.isLoaded()) |
| 510 | m_usesCount = DUChainUtils::contextCountUses(topContext.data(), declaration.data()); |
| 511 | |
| 512 | QString labelText = i18ncp("%1: number of uses, %2: filename with uses", "%2: 1 use", "%2: %1 uses", |
| 513 | m_usesCount, |
| 514 | ICore::self()->projectController()->prettyFileName(topContext.url().toUrl())); |
| 515 | label->setText(labelText); |
| 516 | |
| 517 | m_toggleButton->setText(QLatin1String(" <a href='toggleCollapsed'>[") + |
| 518 | i18nc("Refers to closing a UI element", "Collapse") + QLatin1String("]</a>")); |
| 519 | |
| 520 | connect(m_toggleButton, &QLabel::linkActivated, this, &TopContextUsesWidget::labelClicked); |
| 521 | addHeaderItem(headerWidget); |
| 522 | setUpdatesEnabled(true); |
| 523 | } |
| 524 | |
| 525 | int TopContextUsesWidget::usesCount() const |
| 526 | { |
nothing calls this directly
no test coverage detected