FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
// src/screens/ma_analytics/MAModulePanel.cpp
#include "screens/ma_analytics/MAModulePanel.h"
#include "core/currency/Currency.h"
#include "core/logging/Logger.h"
#include "services/ma_analytics/MAAnalyticsService.h"
#include "ui/theme/Theme.h"
#include "ui/theme/ThemeManager.h"
#include <QCoreApplication>
#include <QFormLayout>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QJsonArray>
#include <QJsonDocument>
#include <QLineEdit>
#include <QScrollArea>
#include <QTableWidget>
namespace fincept::screens {
using namespace fincept::services::ma;
// ── Helpers: create styled input widgets ─────────────────────────────────────
QDoubleSpinBox* MAModulePanel::make_double_spin(double min, double max, double val, int decimals, const QString& suffix,
QWidget* parent) {
auto* spin = new QDoubleSpinBox(parent);
spin->setRange(min, max);
spin->setValue(val);
spin->setDecimals(decimals);
if (!suffix.isEmpty())
spin->setSuffix(suffix);
spin->setStyleSheet(QString("QDoubleSpinBox { background:%1; color:%2; border:1px solid %3;"
"font-family:%4; font-size:%5px; padding:4px 6px; }"
"QDoubleSpinBox:focus { border-color:%6; }")
.arg(ui::colors::BG_RAISED(), ui::colors::TEXT_PRIMARY(), ui::colors::BORDER_MED())
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::fonts::SMALL)
.arg(module_.color.name()));
return spin;
}
QSpinBox* MAModulePanel::make_int_spin(int min, int max, int val, QWidget* parent) {
auto* spin = new QSpinBox(parent);
spin->setRange(min, max);
spin->setValue(val);
spin->setStyleSheet(QString("QSpinBox { background:%1; color:%2; border:1px solid %3;"
"font-family:%4; font-size:%5px; padding:4px 6px; }"
"QSpinBox:focus { border-color:%6; }")
.arg(ui::colors::BG_RAISED(), ui::colors::TEXT_PRIMARY(), ui::colors::BORDER_MED())
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::fonts::SMALL)
.arg(module_.color.name()));
return spin;
}
QPushButton* MAModulePanel::make_run_button(const QString& text, QWidget* parent) {
auto* btn = new QPushButton(text, parent);
btn->setCursor(Qt::PointingHandCursor);
btn->setStyleSheet(QString("QPushButton { background:%1; color:%2; font-family:%3; font-size:%4px;"
"font-weight:700; border:none; padding:8px 20px;"
"letter-spacing:1px; }"
"QPushButton:hover { background:%5; }"
"QPushButton:pressed { background:%6; }")
.arg(module_.color.name())
.arg(ui::colors::BG_BASE())
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::fonts::SMALL)
.arg(module_.color.lighter(120).name())
.arg(module_.color.darker(120).name()));
return btn;
}
QWidget* MAModulePanel::build_input_row(const QString& label, QWidget* input, QWidget* parent) {
auto* row = new QWidget(parent);
auto* hl = new QHBoxLayout(row);
hl->setContentsMargins(0, 2, 0, 2);
hl->setSpacing(8);
auto* lbl = new QLabel(row);
lbl->setFixedWidth(160);
// Labels ending in "($)" are a currency-unit hint — bind them so the symbol
// tracks the preferred currency live; others are plain text.
if (label.endsWith("($)")) {
QString base = label;
base.chop(3); // strip "($)"
cur::bindLabel(lbl, base + "(%1)");
} else {
lbl->setText(label);
}
lbl->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3;")
.arg(ui::colors::TEXT_SECONDARY())
.arg(ui::fonts::SMALL)
.arg(ui::fonts::DATA_FAMILY));
hl->addWidget(lbl);
hl->addWidget(input, 1);
return row;
}
QWidget* MAModulePanel::build_metric_card(const QString& label, const QString& value, const QString& color,
QWidget* parent) {
auto* card = new QWidget(parent);
card->setStyleSheet(QString("background:%1; border:1px solid %2; padding:10px;")
.arg(ui::colors::BG_RAISED())
.arg(ui::colors::BORDER_DIM()));
auto* vl = new QVBoxLayout(card);
vl->setContentsMargins(10, 8, 10, 8);
vl->setSpacing(4);
auto* lbl = new QLabel(label, card);
lbl->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3; letter-spacing:1px;")
.arg(ui::colors::TEXT_TERTIARY())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY));
auto* val = new QLabel(value, card);
val->setStyleSheet(QString("color:%1; font-size:%2px; font-weight:700; font-family:%3;")
.arg(color)
.arg(ui::fonts::HEADER)
.arg(ui::fonts::DATA_FAMILY));
vl->addWidget(lbl);
vl->addWidget(val);
return card;
}
// ── Constructor ──────────────────────────────────────────────────────────────
MAModulePanel::MAModulePanel(const ModuleInfo& info, QWidget* parent) : QWidget(parent), module_(info) {
build_ui();
connect_service();
refresh_theme();
}
void MAModulePanel::connect_service() {
auto& svc = MAAnalyticsService::instance();
connect(&svc, &MAAnalyticsService::result_ready, this, &MAModulePanel::on_result_ready);
connect(&svc, &MAAnalyticsService::error_occurred, this, &MAModulePanel::on_error);
}
// ── Build UI ─────────────────────────────────────────────────────────────────
void MAModulePanel::build_ui() {
auto* root = new QVBoxLayout(this);
root->setContentsMargins(0, 0, 0, 0);
root->setSpacing(0);
// Module header bar
header_bar_ = new QWidget(this);
header_bar_->setFixedHeight(36);
auto* hhl = new QHBoxLayout(header_bar_);
hhl->setContentsMargins(16, 0, 16, 0);
header_title_ = new QLabel(module_.label.toUpper(), header_bar_);
hhl->addWidget(header_title_);
auto* div = new QWidget(header_bar_);
div->setFixedSize(1, 14);
div->setObjectName("maPanelDivider");
hhl->addWidget(div);
header_category_ = new QLabel(module_.category.toUpper(), header_bar_);
hhl->addWidget(header_category_);
hhl->addStretch();
status_label_ = new QLabel(header_bar_);
hhl->addWidget(status_label_);
root->addWidget(header_bar_);
// Scrollable content area
auto* scroll = new QScrollArea(this);
scroll->setWidgetResizable(true);
scroll->setStyleSheet("QScrollArea { border:none; background:transparent; }");
QWidget* panel_content = nullptr;
switch (module_.id) {
case ModuleId::Valuation:
panel_content = build_valuation_panel();
break;
case ModuleId::Merger:
panel_content = build_merger_panel();
break;
case ModuleId::Deals:
panel_content = build_deals_panel();
break;
case ModuleId::Startup:
panel_content = build_startup_panel();
break;
case ModuleId::Fairness:
panel_content = build_fairness_panel();
break;
case ModuleId::Industry:
panel_content = build_industry_panel();
break;
case ModuleId::Advanced:
panel_content = build_advanced_panel();
break;
case ModuleId::Comparison:
panel_content = build_comparison_panel();
break;
}
scroll->setWidget(panel_content);
root->addWidget(scroll, 1);
}
// ═══════════════════════════════════════════════════════════════════════════════
// RESULT DISPLAY
// ═══════════════════════════════════════════════════════════════════════════════
void MAModulePanel::clear_results() {
while (results_layout_->count() > 0) {
auto* item = results_layout_->takeAt(0);
if (item->widget())
item->widget()->deleteLater();
delete item;
}
}
void MAModulePanel::display_error(const QString& msg) {
clear_results();
auto* err = new QLabel(msg);
err->setWordWrap(true);
QColor neg(ui::colors::NEGATIVE());
auto neg_rgb = QString("%1,%2,%3").arg(neg.red()).arg(neg.green()).arg(neg.blue());
err->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3; padding:12px;"
"background:rgba(%4,0.08); border:1px solid rgba(%4,0.3);")
.arg(ui::colors::NEGATIVE())
.arg(ui::fonts::SMALL)
.arg(ui::fonts::DATA_FAMILY())
.arg(neg_rgb));
results_layout_->addWidget(err);
status_label_->setText(tr("Error"));
}
// Is this metric a rate whose sub-1.0 value is a fraction to show as a percentage (0.099 -> "9.9%")?
// Previously EVERY value between 0.0001 and 1 was rendered as a percentage, so a beta of 0.8 or an
// EV/Revenue multiple of 0.5 read "80.0%" / "50.0%". Keyed on the metric name instead.
static bool is_rate_key(const QString& key) {
static const QStringList kHints = {"rate", "margin", "growth", "yield", "irr", "wacc",
"premium", "return", "probabil", "weight", "ownership", "cagr", "discount"};
const QString k = key.toLower();
for (const QString& hint : kHints)
if (k.contains(hint))
return true;
return false;
}
// `intrinsic` pins the symbol to a fixed currency (e.g. "USD" for SEC/EDGAR
// data); empty means follow the user's preferred currency. `key` is the metric name (if known).
static QString format_value(const QJsonValue& val, const QString& intrinsic = QString(),
const QString& key = QString()) {
if (val.isDouble()) {
double v = val.toDouble();
// The scripts emit `*_pct` / `*_percent` fields already in percent (23.6, or 0.36 for 0.36%), so they
// are labelled, never rescaled.
if (key.contains(QLatin1String("pct"), Qt::CaseInsensitive) ||
key.contains(QLatin1String("percent"), Qt::CaseInsensitive))
return QString("%1%").arg(v, 0, 'f', 2);
if (std::abs(v) >= 1e3)
return cur::money(v, /*compact=*/true, intrinsic);
if (std::abs(v) < 1.0 && std::abs(v) > 0.0001) {
if (is_rate_key(key))
return QString("%1%").arg(v * 100, 0, 'f', 1);
return QString::number(v, 'g', 4);
}
return QString::number(v, 'f', 2);
}
if (val.isBool())
return val.toBool() ? QCoreApplication::translate("MAModulePanel", "YES")
: QCoreApplication::translate("MAModulePanel", "NO");
if (val.isString())
return val.toString();
return QString::fromUtf8("—");
}
static QTableWidget* build_json_table(const QJsonArray& arr, const QString& accent, QWidget* parent,
const QString& intrinsic = QString()) {
if (arr.isEmpty())
return nullptr;
// Collect all column keys from first object
auto first = arr[0].toObject();
QStringList cols;
for (auto it = first.begin(); it != first.end(); ++it)
if (!it.value().isObject() && !it.value().isArray())
cols.append(it.key());
if (cols.isEmpty())
return nullptr;
auto* table = new QTableWidget(arr.size(), cols.size(), parent);
table->setHorizontalHeaderLabels(cols);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setAlternatingRowColors(true);
table->horizontalHeader()->setStretchLastSection(true);
table->verticalHeader()->setVisible(false);
table->setMaximumHeight(300);
table->setStyleSheet(QString("QTableWidget { background:%1; color:%2; gridline-color:%3;"
"font-family:%4; font-size:%5px; border:1px solid %3; }"
"QTableWidget::item { padding:4px 8px; }"
"QTableWidget::item:selected { background:%6; }"
"QHeaderView::section { background:%7; color:%8; font-weight:700;"
"padding:4px 8px; border:1px solid %3; font-family:%4; font-size:%5px; }"
"QTableWidget::item:alternate { background:%9; }")
.arg(ui::colors::BG_SURFACE(), ui::colors::TEXT_PRIMARY(), ui::colors::BORDER_DIM())
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::fonts::SMALL)
.arg(QString("rgba(%1,0.15)").arg(accent))
.arg(ui::colors::BG_RAISED())
.arg(ui::colors::TEXT_SECONDARY())
.arg(ui::colors::ROW_ALT()));
for (int r = 0; r < arr.size(); ++r) {
auto obj = arr[r].toObject();
for (int c = 0; c < cols.size(); ++c) {
auto* item = new QTableWidgetItem(format_value(obj[cols[c]], intrinsic, cols[c]));
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
table->setItem(r, c, item);
}
}
table->resizeColumnsToContents();
return table;
}
static QTableWidget* build_kv_table(const QJsonObject& obj, const QString& accent, QWidget* parent,
const QString& intrinsic = QString()) {
// Collect only scalar key-value pairs
QStringList keys;
for (auto it = obj.begin(); it != obj.end(); ++it)
if (!it.value().isObject() && !it.value().isArray())
keys.append(it.key());
if (keys.isEmpty())
return nullptr;
auto* table = new QTableWidget(keys.size(), 2, parent);
table->setHorizontalHeaderLabels({QCoreApplication::translate("MAModulePanel", "Metric"),
QCoreApplication::translate("MAModulePanel", "Value")});
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setAlternatingRowColors(true);
table->horizontalHeader()->setStretchLastSection(true);
table->verticalHeader()->setVisible(false);
table->setMaximumHeight(400);
table->setStyleSheet(QString("QTableWidget { background:%1; color:%2; gridline-color:%3;"
"font-family:%4; font-size:%5px; border:1px solid %3; }"
"QTableWidget::item { padding:4px 8px; }"
"QTableWidget::item:selected { background:%6; }"
"QHeaderView::section { background:%7; color:%8; font-weight:700;"
"padding:4px 8px; border:1px solid %3; font-family:%4; font-size:%5px; }"
"QTableWidget::item:alternate { background:%9; }")
.arg(ui::colors::BG_SURFACE(), ui::colors::TEXT_PRIMARY(), ui::colors::BORDER_DIM())
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::fonts::SMALL)
.arg(QString("rgba(%1,0.15)").arg(accent))
.arg(ui::colors::BG_RAISED())
.arg(ui::colors::TEXT_SECONDARY())
.arg(ui::colors::ROW_ALT()));
for (int r = 0; r < keys.size(); ++r) {
auto label = keys[r];
label.replace('_', ' ');
auto* key_item = new QTableWidgetItem(label.toUpper());
key_item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
table->setItem(r, 0, key_item);
auto* val_item = new QTableWidgetItem(format_value(obj[keys[r]], intrinsic, keys[r]));
val_item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
table->setItem(r, 1, val_item);
}
table->resizeColumnsToContents();
return table;
}
void MAModulePanel::display_result(const QJsonObject& envelope) {
clear_results();
// Most scripts answer {"success": true, "data": <result>}: show the result itself, not a "SUCCESS: YES"
// card next to it. Other top-level scalars (count, filings_found, ...) are kept; the raw-JSON viewer
// below still shows the untouched envelope.
QJsonObject payload = envelope;
if (envelope.value(QStringLiteral("success")).toBool(false) && envelope.contains(QStringLiteral("data"))) {
const QJsonValue data = envelope.value(QStringLiteral("data"));
QJsonObject flat;
for (auto it = envelope.begin(); it != envelope.end(); ++it)
if (it.key() != QLatin1String("success") && it.key() != QLatin1String("data") &&
!it.value().isObject() && !it.value().isArray())
flat.insert(it.key(), it.value());
if (data.isObject()) {
const QJsonObject inner = data.toObject();
for (auto it = inner.begin(); it != inner.end(); ++it)
flat.insert(it.key(), it.value());
payload = flat;
} else if (data.isArray()) {
flat.insert(QStringLiteral("results"), data);
payload = flat;
}
}
QString accent = QString("%1,%2,%3").arg(module_.color.red()).arg(module_.color.green()).arg(module_.color.blue());
// The Deals module shows SEC/EDGAR filing values, which are USD — pin them
// so they don't get repainted with the user's preferred currency symbol.
// Every other M&A module is a calculator the user denominates themselves.
const QString intrinsic =
(module_.id == fincept::services::ma::ModuleId::Deals) ? QStringLiteral("USD") : QString();
// Section header
auto* header = new QLabel(tr("RESULTS"));
header->setStyleSheet(QString("color:%1; font-size:9px; font-weight:700; font-family:%2; letter-spacing:1px;"
"padding:4px 0;")
.arg(module_.color.name())
.arg(ui::fonts::DATA_FAMILY));
results_layout_->addWidget(header);
// 1. Metric cards for top-level scalar values
auto* grid = new QWidget(this);
auto* gl = new QGridLayout(grid);
gl->setContentsMargins(0, 0, 0, 0);
gl->setSpacing(8);
int col = 0, row = 0;
bool has_scalars = false;
for (auto it = payload.begin(); it != payload.end(); ++it) {
if (it.value().isObject() || it.value().isArray())
continue;
has_scalars = true;
QString label = it.key();
label.replace('_', ' ');
auto* card = build_metric_card(label.toUpper(), format_value(it.value(), intrinsic, it.key()),
module_.color.name(), grid);
gl->addWidget(card, row, col);
col++;
if (col >= 3) {
col = 0;
row++;
}
}
if (has_scalars)
results_layout_->addWidget(grid);
else
grid->deleteLater();
// 2. Tables for nested objects and arrays
for (auto it = payload.begin(); it != payload.end(); ++it) {
if (it.value().isArray()) {
auto arr = it.value().toArray();
if (arr.isEmpty())
continue;
QString sec_label = it.key();
sec_label.replace('_', ' ');
auto* sec = new QLabel(sec_label.toUpper());
sec->setStyleSheet(QString("color:%1; font-size:9px; font-weight:700; font-family:%2;"
"letter-spacing:1px; padding:8px 0 4px 0;")
.arg(module_.color.name())
.arg(ui::fonts::DATA_FAMILY));
results_layout_->addWidget(sec);
if (arr[0].isObject()) {
auto* table = build_json_table(arr, accent, this, intrinsic);
if (table)
results_layout_->addWidget(table);
} else {
// Simple array — display as comma-separated
QStringList items;
for (const auto& v : arr)
items.append(format_value(v, intrinsic));
auto* lbl = new QLabel(items.join(", "));
lbl->setWordWrap(true);
lbl->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3;"
"padding:4px; background:%4; border:1px solid %5;")
.arg(ui::colors::TEXT_PRIMARY())
.arg(ui::fonts::SMALL)
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::colors::BG_RAISED())
.arg(ui::colors::BORDER_DIM()));
results_layout_->addWidget(lbl);
}
} else if (it.value().isObject()) {
auto obj = it.value().toObject();
if (obj.isEmpty())
continue;
QString sec_label = it.key();
sec_label.replace('_', ' ');
auto* sec = new QLabel(sec_label.toUpper());
sec->setStyleSheet(QString("color:%1; font-size:9px; font-weight:700; font-family:%2;"
"letter-spacing:1px; padding:8px 0 4px 0;")
.arg(module_.color.name())
.arg(ui::fonts::DATA_FAMILY));
results_layout_->addWidget(sec);
auto* table = build_kv_table(obj, accent, this, intrinsic);
if (table)
results_layout_->addWidget(table);
}
}
// 3. Raw JSON viewer (collapsed)
auto* raw_btn = new QPushButton(tr("Show Raw JSON"), this);
raw_btn->setCursor(Qt::PointingHandCursor);
raw_btn->setStyleSheet(QString("QPushButton { color:%1; font-size:%2px; font-family:%3;"
"background:transparent; border:1px solid %4; padding:4px 12px; }"
"QPushButton:hover { background:%5; }")
.arg(ui::colors::TEXT_SECONDARY())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::colors::BORDER_DIM())
.arg(ui::colors::BG_HOVER()));
auto* raw_text = new QTextEdit;
raw_text->setReadOnly(true);
raw_text->setVisible(false);
raw_text->setMaximumHeight(300);
raw_text->setPlainText(QJsonDocument(envelope).toJson(QJsonDocument::Indented));
raw_text->setStyleSheet(QString("QTextEdit { background:%1; color:%2; border:1px solid %3;"
"font-family:%4; font-size:%5px; padding:8px; }")
.arg(ui::colors::BG_RAISED(), ui::colors::TEXT_PRIMARY(), ui::colors::BORDER_DIM())
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::fonts::SMALL));
connect(raw_btn, &QPushButton::clicked, this, [raw_text, raw_btn]() {
bool showing = raw_text->isVisible();
raw_text->setVisible(!showing);
raw_btn->setText(showing ? tr("Show Raw JSON") : tr("Hide Raw JSON"));
});
results_layout_->addWidget(raw_btn);
results_layout_->addWidget(raw_text);
status_label_->setText(tr("Done"));
}
// ── Service signal handlers ──────────────────────────────────────────────────
static const QHash<ModuleId, QStringList>& get_context_map() {
static const QHash<ModuleId, QStringList> map = {
{ModuleId::Valuation,
{"dcf", "dcf_sensitivity", "football_field", "lbo_returns", "lbo_model", "lbo_debt_schedule",
"lbo_sensitivity", "trading_comps", "precedent_txns"}},
{ModuleId::Merger,
{"merger_model", "accretion_dilution", "pro_forma", "sources_uses", "contribution", "revenue_synergies",
"cost_synergies", "synergy_dcf", "integration_costs", "payment_structure", "earnout", "exchange_ratio",
"collar", "cvr"}},
{ModuleId::Deals, {"scan_filings", "all_deals", "search_deals", "create_deal", "update_deal", "parse_filing"}},
{ModuleId::Startup,
{"berkus", "scorecard", "vc_method", "first_chicago", "risk_factor", "startup_comprehensive"}},
{ModuleId::Fairness, {"fairness_opinion", "premium_analysis", "process_quality"}},
{ModuleId::Industry, {"tech_metrics", "healthcare_metrics", "finserv_metrics"}},
{ModuleId::Advanced, {"monte_carlo", "regression"}},
{ModuleId::Comparison,
{"compare_deals", "rank_deals", "benchmark_premium", "payment_structures", "industry_deals"}},
};
return map;
}
void MAModulePanel::on_result_ready(const QString& context, const QJsonObject& payload) {
auto it = get_context_map().find(module_.id);
if (it != get_context_map().end() && it->contains(context)) {
// A script that answers {"success": false, ...} (without the "error" key PythonRunner looks for)
// used to be rendered as a result card reading "SUCCESS: NO".
const QJsonValue ok = payload.value(QStringLiteral("success"));
if (ok.isBool() && !ok.toBool()) {
QString text = payload.value(QStringLiteral("message")).toString();
if (text.isEmpty())
text = payload.value(QStringLiteral("error")).toString();
display_error(QString("[%1] %2").arg(context, text.isEmpty() ? tr("The analysis failed") : text));
return;
}
display_result(payload);
// An empty deal database is the normal first-run state — say what to do about it.
if (module_.id == fincept::services::ma::ModuleId::Deals && payload.value(QStringLiteral("count")).toInt(-1) == 0)
status_label_->setText(tr("No deals stored yet - use SCAN SEC FILINGS, then LOAD ALL DEALS"));
// A scan lists the filings it stored; offer them to PARSE FILING so the user does not have to
// copy accession numbers out of the raw result.
if (context == QLatin1String("scan_filings")) {
QComboBox* picker = combo_inputs_.value(QStringLiteral("parse_accession"), nullptr);
const QJsonArray filings =
payload.value(QStringLiteral("data")).toObject().value(QStringLiteral("filings")).toArray();
if (picker && !filings.isEmpty()) {
const QString typed = picker->currentText();
picker->clear();
for (const QJsonValue& fv : filings) {
const QJsonObject f = fv.toObject();
const QString acc = f.value(QStringLiteral("accession_number")).toString();
if (acc.isEmpty())
continue;
const QString form = f.value(QStringLiteral("filing_type")).toString();
picker->addItem(QStringLiteral("%1 %2 %3 %4")
.arg(acc, form, f.value(QStringLiteral("filing_date")).toString(),
f.value(QStringLiteral("company_name")).toString()),
acc);
picker->setItemData(picker->count() - 1, form, Qt::UserRole + 1);
}
picker->setCurrentIndex(-1);
picker->setEditText(typed);
status_label_->setText(
tr("%1 filing(s) found - pick one under Filing and press PARSE FILING").arg(picker->count()));
}
}
}
}
void MAModulePanel::on_error(const QString& context, const QString& message) {
auto it = get_context_map().find(module_.id);
if (it != get_context_map().end() && it->contains(context)) {
display_error(QString("[%1] %2").arg(context, message));
}
}
// ── Sub-tab registration (records source label for retranslateUi) ────────────
void MAModulePanel::add_sub_tab(QWidget* page, const char* source_label) {
if (!sub_tabs_ || !page)
return;
sub_tabs_->addTab(page, tr(source_label));
sub_tab_sources_.append({page, QString::fromUtf8(source_label)});
}
// ── Live language switch ─────────────────────────────────────────────────────
void MAModulePanel::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange)
retranslateUi();
QWidget::changeEvent(event);
}
void MAModulePanel::retranslateUi() {
// Header label/category come from module_ (data) — not translated here.
// Re-apply sub-tab labels from their recorded source strings.
if (sub_tabs_) {
for (const auto& pair : sub_tab_sources_) {
int idx = sub_tabs_->indexOf(pair.first);
if (idx >= 0)
sub_tabs_->setTabText(idx, tr(pair.second.toUtf8().constData()));
}
}
}
// ── Tab stylesheet helper ───────────────────────────────────────────────────
void MAModulePanel::apply_tab_stylesheet() {
if (!sub_tabs_)
return;
// Never truncate tab labels to "Accreti…"; show full text and scroll on overflow.
sub_tabs_->setElideMode(Qt::ElideNone);
sub_tabs_->setUsesScrollButtons(true);
sub_tabs_->setStyleSheet(QString("QTabWidget::pane { border:1px solid %1; background:%2; }"
"QTabBar::tab { background:%3; color:%4; padding:6px 16px;"
"font-family:%5; font-size:%6px; border:1px solid %1; border-bottom:none; }"
"QTabBar::tab:selected { background:%2; color:%7; font-weight:700;"
"border-bottom:2px solid %7; }")
.arg(ui::colors::BORDER_DIM(), ui::colors::BG_SURFACE(), ui::colors::BG_RAISED())
.arg(ui::colors::TEXT_SECONDARY())
.arg(ui::fonts::DATA_FAMILY())
.arg(ui::fonts::SMALL)
.arg(module_.color.name()));
}
// ── Theme refresh ───────────────────────────────────────────────────────────
void MAModulePanel::refresh_theme() {
// Header bar
if (header_bar_)
header_bar_->setStyleSheet(QString("background:%1; border-bottom:1px solid %2;")
.arg(ui::colors::BG_RAISED(), ui::colors::BORDER_DIM()));
// Header title
if (header_title_)
header_title_->setStyleSheet(
QString("color:%1; font-size:%2px; font-weight:700; font-family:%3; letter-spacing:1px;")
.arg(module_.color.name())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY()));
// Header divider
if (header_bar_) {
auto* div = header_bar_->findChild<QWidget*>("maPanelDivider");
if (div)
div->setStyleSheet(QString("background:%1;").arg(ui::colors::BORDER_DIM()));
}
// Header category
if (header_category_)
header_category_->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3;")
.arg(ui::colors::TEXT_TERTIARY())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY()));
// Status label
if (status_label_)
status_label_->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3;")
.arg(ui::colors::TEXT_TERTIARY())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY()));
// Tab widget
apply_tab_stylesheet();
}
} // namespace fincept::screens