|
28 | 28 | #include "parsers/perf/perfparser.h"
|
29 | 29 | #include "resultsutil.h"
|
30 | 30 |
|
| 31 | +#if KF5SyntaxHighlighting_FOUND |
| 32 | +#include <KSyntaxHighlighting/definition.h> |
| 33 | +#include <KSyntaxHighlighting/repository.h> |
| 34 | +#include <QCompleter> |
| 35 | +#include <QStringListModel> |
| 36 | +#endif |
| 37 | + |
31 | 38 | #include "data.h"
|
32 | 39 | #include "models/codedelegate.h"
|
33 | 40 | #include "models/costdelegate.h"
|
|
41 | 48 | ResultsDisassemblyPage::ResultsDisassemblyPage(QWidget* parent)
|
42 | 49 | : QWidget(parent)
|
43 | 50 | , ui(new Ui::ResultsDisassemblyPage)
|
44 |
| - , m_disassemblyModel(new DisassemblyModel(this)) |
45 |
| - , m_sourceCodeModel(new SourceCodeModel(this)) |
| 51 | +#if KF5SyntaxHighlighting_FOUND |
| 52 | + , m_repository(new KSyntaxHighlighting::Repository) |
| 53 | + , m_disassemblyModel(new DisassemblyModel(m_repository.get(), this)) |
| 54 | + , m_sourceCodeModel(new SourceCodeModel(m_repository.get(), this)) |
| 55 | +#else |
| 56 | + , m_disassemblyModel(new DisassemblyModel(nullptr, this)) |
| 57 | + , m_sourceCodeModel(new SourceCodeModel(nullptr, this)) |
| 58 | +#endif |
46 | 59 | , m_disassemblyCostDelegate(new CostDelegate(DisassemblyModel::CostRole, DisassemblyModel::TotalCostRole, this))
|
47 | 60 | , m_sourceCodeCostDelegate(new CostDelegate(SourceCodeModel::CostRole, SourceCodeModel::TotalCostRole, this))
|
48 | 61 | , m_disassemblyDelegate(new CodeDelegate(DisassemblyModel::RainbowLineNumberRole, DisassemblyModel::HighlightRole,
|
@@ -123,6 +136,39 @@ ResultsDisassemblyPage::ResultsDisassemblyPage(QWidget* parent)
|
123 | 136 | }
|
124 | 137 | }
|
125 | 138 | });
|
| 139 | + |
| 140 | +#if KF5SyntaxHighlighting_FOUND |
| 141 | + QStringList schemes; |
| 142 | + |
| 143 | + for (const auto& entry : m_repository->definitions()) { |
| 144 | + schemes.push_back(entry.name()); |
| 145 | + } |
| 146 | + |
| 147 | + auto connectCompletion = [schemes, this](QComboBox* box, auto* model) { |
| 148 | + auto m = new QStringListModel(this); |
| 149 | + m->setStringList(schemes); |
| 150 | + |
| 151 | + auto completer = new QCompleter(this); |
| 152 | + completer->setModel(m); |
| 153 | + completer->setCaseSensitivity(Qt::CaseInsensitive); |
| 154 | + completer->setCompletionMode(QCompleter::PopupCompletion); |
| 155 | + box->setCompleter(completer); |
| 156 | + |
| 157 | + connect(completer, qOverload<const QModelIndex&>(&QCompleter::activated), this, |
| 158 | + [this, model](const QModelIndex& entry) { |
| 159 | + model->setSyntaxHighlightDefinition(m_repository->definitionForName(entry.data().toString())); |
| 160 | + }); |
| 161 | + connect(box, qOverload<int>(&QComboBox::activated), this, [this, model, box]() { |
| 162 | + model->setSyntaxHighlightDefinition(m_repository->definitionForName(box->currentText())); |
| 163 | + }); |
| 164 | + }; |
| 165 | + |
| 166 | + connectCompletion(ui->sourceCodeComboBox, m_sourceCodeModel); |
| 167 | + connectCompletion(ui->assemblyComboBox, m_disassemblyModel); |
| 168 | +#else |
| 169 | + ui->customSourceCodeHighlighting->setVisible(false); |
| 170 | + ui->customAssemblyHighlighting->setVisible(false); |
| 171 | +#endif |
126 | 172 | }
|
127 | 173 |
|
128 | 174 | ResultsDisassemblyPage::~ResultsDisassemblyPage() = default;
|
@@ -186,6 +232,16 @@ void ResultsDisassemblyPage::showDisassembly(const DisassemblyOutput& disassembl
|
186 | 232 | m_disassemblyModel->clear();
|
187 | 233 | m_sourceCodeModel->clear();
|
188 | 234 |
|
| 235 | +#if KF5SyntaxHighlighting_FOUND |
| 236 | + auto sourceCodeDefinition = m_repository->definitionForFileName(disassemblyOutput.mainSourceFileName); |
| 237 | + |
| 238 | + ui->assemblyComboBox->setCurrentText(QStringLiteral("GNU Assembler")); |
| 239 | + ui->sourceCodeComboBox->setCurrentText(sourceCodeDefinition.name()); |
| 240 | + |
| 241 | + m_sourceCodeModel->setSyntaxHighlightDefinition(sourceCodeDefinition); |
| 242 | + m_disassemblyModel->setSyntaxHighlightDefinition(m_repository->definitionForName(QStringLiteral("GNU Assembler"))); |
| 243 | +#endif |
| 244 | + |
189 | 245 | const auto& entry = m_callerCalleeResults.entry(m_curSymbol);
|
190 | 246 |
|
191 | 247 | ui->filenameLabel->setText(disassemblyOutput.mainSourceFileName);
|
|
0 commit comments