diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index 557457c4..d3b7f96b 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -196,81 +196,60 @@ QVariant FunctionModel::data(const QModelIndex &index, int role) const return static_cast(Qt::AlignLeft | Qt::AlignVCenter); case Qt::ToolTipRole: { - const QJsonArray &info = Core()->cmdj("afij @ " + function.name).array(); - if (!info.isEmpty()) { - const QJsonObject &funcInfo = info[0].toObject(); + QJsonArray jDisasmEntries; + { + // temporarily simplify the disasm output to get it colorful and simple to read + TempConfig tempConfig; + tempConfig.set("scr.html", true) + .set("scr.color", COLOR_MODE_16M) + .set("asm.lines", false) + .set("asm.var", false) + .set("asm.comments", false) + .set("asm.bytes", false) + .set("asm.lines.fcn", false) + .set("asm.lines.out", false) + .set("asm.lines.bb", false) + .set("asm.bbline", false); - static const QStringList kRequiredFields{ "size", "cc", "nbbs" }; - for (const auto& key : kRequiredFields) { - if (!funcInfo.contains(key)) { - return QVariant(); - } - } - const int size = funcInfo["size"].toInt(); - const int complex = funcInfo["cc"].toInt(); - const int bb = funcInfo["nbbs"].toInt(); - QStringList disasmPreview; - - QJsonArray jDisasmEntries; - { - // temporarily simplify the disasm output to get it colorful and simple to read - TempConfig tempConfig; - tempConfig.set("scr.html", true) - .set("scr.color", COLOR_MODE_16M) - .set("asm.lines", false) - .set("asm.var", false) - .set("asm.comments", false) - .set("asm.bytes", false) - .set("asm.lines.fcn", false) - .set("asm.lines.out", false) - .set("asm.lines.bb", false) - .set("asm.bbline", false); - - jDisasmEntries = Core()->cmdj(QString("pDJ %1 @ %2").arg(function.size).arg(function.offset)).array(); - } - for (const QJsonValue &value : jDisasmEntries) { - const QJsonObject &object = value.toObject(); - - disasmPreview << object["text"].toString(); - if (disasmPreview.length() >= kMaxTooltipDisasmPreviewLines) { - disasmPreview << "..."; - break; - } - } - - const QStringList &summary = Core()->cmd("pdsf @ " + function.name).split("\n", QString::SkipEmptyParts); - - const QFont &fnt = Config()->getFont(); - QFontMetrics fm{ fnt }; - - // elide long strings using current didsam font metrics - QStringList highlights; - for (const QString &s : summary) { - highlights << fm.elidedText(s, Qt::ElideRight, kMaxTooltipWidth); - if (highlights.length() > kMaxTooltipHighlightsLines) { - highlights << "..."; - break; - } - } - QString toolTipContent = QString("
") - .arg(fnt.family()) - .arg(qMax(6, fnt.pointSize() - 1)) // slightly decrease font size, to keep more text in the same box - + tr("
Summary:
") - + tr("Size: %1, Cyclomatic complexity: %2, Basic blocks: %3") - .arg(size) - .arg(complex) - .arg(bb) - + tr("
Disassembly preview:
%1
") - .arg(disasmPreview.join("
")); - - if (!highlights.isEmpty()) { - toolTipContent += tr("
Highlights:
%1
") - .arg(highlights.join("\n").toHtmlEscaped().replace("\n", "
")); - } - toolTipContent += "
"; - return toolTipContent; + jDisasmEntries = Core()->cmdj(QString("pDJ %1 @ %2").arg(function.size).arg(function.offset)).array(); } - return QVariant(); + QStringList disasmPreview; + for (const QJsonValue &value : jDisasmEntries) { + const QJsonObject &object = value.toObject(); + + disasmPreview << object["text"].toString(); + if (disasmPreview.length() >= kMaxTooltipDisasmPreviewLines) { + disasmPreview << "..."; + break; + } + } + + const QStringList &summary = Core()->cmd("pdsf @ " + function.name).split("\n", QString::SkipEmptyParts); + + const QFont &fnt = Config()->getFont(); + QFontMetrics fm{ fnt }; + + // elide long strings using current didsam font metrics + QStringList highlights; + for (const QString &s : summary) { + highlights << fm.elidedText(s, Qt::ElideRight, kMaxTooltipWidth); + if (highlights.length() > kMaxTooltipHighlightsLines) { + highlights << "..."; + break; + } + } + QString toolTipContent = QString("
") + .arg(fnt.family()) + .arg(qMax(6, fnt.pointSize() - 1)) // slightly decrease font size, to keep more text in the same box + + tr("
Disassembly preview:
%1
") + .arg(disasmPreview.join("
")); + + if (!highlights.isEmpty()) { + toolTipContent += tr("
Highlights:
%1
") + .arg(highlights.join("\n").toHtmlEscaped().replace("\n", "
")); + } + toolTipContent += "
"; + return toolTipContent; } case Qt::ForegroundRole: