| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "codelens.h" |
| 6 | #include "codelenstree.h" |
| 7 | #include <QGridLayout> |
| 8 | |
| 9 | class CodeLensPrivate |
| 10 | { |
| 11 | friend class CodeLens; |
| 12 | CodeLensTree *lens {nullptr}; |
| 13 | QGridLayout *gLayout {nullptr}; |
| 14 | static CodeLens *ins; |
| 15 | }; |
| 16 | CodeLens * CodeLensPrivate::ins {nullptr}; |
| 17 | |
| 18 | CodeLens *CodeLens::instance() |
| 19 | { |
| 20 | if (!CodeLensPrivate::ins) { |
| 21 | CodeLensPrivate::ins= new CodeLens; |
| 22 | } |
| 23 | return CodeLensPrivate::ins; |
| 24 | } |
| 25 | |
| 26 | CodeLens::CodeLens(QWidget *parent) |
| 27 | : QWidget(parent) |
| 28 | , d (new CodeLensPrivate()) |
| 29 | { |
| 30 | d->lens = new CodeLensTree(); |
| 31 | d->gLayout = new QGridLayout(); |
| 32 | d->gLayout->addWidget(d->lens); |
| 33 | setLayout(d->gLayout); |
| 34 | QObject::connect(d->lens, &CodeLensTree::doubleClicked, this, &CodeLens::doubleClicked); |
| 35 | } |
| 36 | |
| 37 | CodeLens::~CodeLens() |
| 38 | { |
| 39 | if (d) { |
| 40 | delete d; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void CodeLens::displayReference(const lsp::References &data) |
| 45 | { |
| 46 | editor.switchContext(tr("Code &Lens")); |
| 47 | d->lens->setData(data); |
| 48 | } |
| 49 |