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/geopolitics/RelationshipPanel.cpp
#include "screens/geopolitics/RelationshipPanel.h"
#include "ui/theme/Theme.h"
#include <QAction>
#include <QCursor>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QMenu>
#include <QMouseEvent>
#include <QScrollArea>
namespace fincept::screens {
using namespace fincept::services::geo;
static QVector<RelationshipNode> build_nodes() {
QVector<RelationshipNode> nodes;
// Illustrative structure only (SAMPLE DATA badge + banner). There are no
// per-node figures: the invented "N datasets" counts read like live HDX
// numbers. A card's click menu browses the real HDX datasets instead.
// Primary conflicts
nodes.append({"ukraine", "Ukraine", "conflict", "critical", {"displacement", "humanitarian", "food_security"}});
nodes.append({"gaza", "Gaza", "conflict", "critical", {"displacement", "humanitarian", "health"}});
nodes.append({"sudan", "Sudan", "conflict", "critical", {"displacement", "food_security", "humanitarian"}});
nodes.append({"yemen", "Yemen", "conflict", "high", {"food_security", "humanitarian", "health"}});
nodes.append({"syria", "Syria", "conflict", "high", {"displacement", "humanitarian"}});
nodes.append({"myanmar", "Myanmar", "conflict", "high", {"displacement", "humanitarian"}});
// Crisis types
nodes.append({"displacement", "Displacement", "crisis", "high", {"unhcr"}});
nodes.append({"food_security", "Food Security", "crisis", "high", {"wfp", "fao"}});
nodes.append({"humanitarian", "Humanitarian", "crisis", "critical", {"unhcr", "wfp", "who"}});
nodes.append({"health", "Health Crisis", "crisis", "medium", {"who"}});
// Organizations
nodes.append({"unhcr", "UNHCR", "organization", "", {"displacement", "humanitarian"}});
nodes.append({"wfp", "WFP", "organization", "", {"food_security", "humanitarian"}});
nodes.append({"who", "WHO", "organization", "", {"health", "humanitarian"}});
nodes.append({"fao", "FAO", "organization", "", {"food_security"}});
return nodes;
}
static QColor severity_color(const QString& sev) {
if (sev == "critical")
return QColor(ui::colors::NEGATIVE());
if (sev == "high")
return QColor(ui::colors::WARNING());
if (sev == "medium")
return QColor(ui::colors::WARNING()).lighter(120);
if (sev == "low")
return QColor(ui::colors::POSITIVE());
return QColor(ui::colors::INFO()); // organization
}
RelationshipPanel::RelationshipPanel(QWidget* parent) : QWidget(parent) {
build_ui();
}
void RelationshipPanel::build_ui() {
auto* root = new QVBoxLayout(this);
root->setContentsMargins(0, 0, 0, 0);
root->setSpacing(0);
// Header
auto* header = new QWidget(this);
header->setFixedHeight(48);
header->setStyleSheet(
QString("background:%1; border-bottom:1px solid %2;").arg(ui::colors::BG_RAISED(), ui::colors::BORDER_DIM()));
auto* hhl = new QHBoxLayout(header);
hhl->setContentsMargins(16, 0, 16, 0);
hhl->setSpacing(12);
title_lbl_ = new QLabel(tr("GEOPOLITICAL RELATIONSHIP NETWORK"), header);
title_lbl_->setStyleSheet(QString("color:%1; font-size:%2px; font-weight:700; font-family:%3; letter-spacing:1px;")
.arg(ui::colors::INFO())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY()));
hhl->addWidget(title_lbl_);
// The network below is illustrative sample data (see build_nodes), not a live
// feed — surface that honestly with a badge so the figures are never mistaken
// for real conflict/humanitarian metrics.
sample_badge_ = new QLabel(tr("SAMPLE DATA"), header);
sample_badge_->setToolTip(tr("Illustrative network — not sourced from a live data feed."));
sample_badge_->setStyleSheet(QString("color:#000; background:%1; font-size:%2px; font-weight:700;"
"font-family:%3; padding:2px 6px; border-radius:2px; letter-spacing:1px;")
.arg(ui::colors::WARNING())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY));
hhl->addWidget(sample_badge_);
hhl->addStretch();
auto nodes = build_nodes();
int conflicts = 0, orgs = 0;
for (const auto& n : nodes) {
if (n.type == "conflict")
conflicts++;
if (n.type == "organization")
orgs++;
}
node_count_ = nodes.size();
conflict_count_ = conflicts;
org_count_ = orgs;
stats_lbl_ = new QLabel(
tr("NODES: %1 | CONFLICTS: %2 | ORGANIZATIONS: %3").arg(nodes.size()).arg(conflicts).arg(orgs), header);
stats_lbl_->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3; padding:2px 8px;"
"background:rgba(255,255,255,0.04); border:1px solid %4;")
.arg(ui::colors::TEXT_TERTIARY())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY)
.arg(ui::colors::BORDER_DIM()));
hhl->addWidget(stats_lbl_);
root->addWidget(header);
// Network view
auto* scroll = new QScrollArea(this);
scroll->setWidgetResizable(true);
scroll->setStyleSheet(QString("QScrollArea { border:none; background:%1; }"
"QScrollBar:vertical { background:%1; width:6px; }"
"QScrollBar::handle:vertical { background:%2; border-radius:3px; }"
"QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { height:0; }")
.arg(ui::colors::BG_BASE(), ui::colors::BORDER_MED()));
auto* content = new QWidget(scroll);
content->setStyleSheet(QString("background:%1;").arg(ui::colors::BG_BASE()));
auto* cvl = new QVBoxLayout(content);
cvl->setContentsMargins(16, 16, 16, 16);
cvl->setSpacing(16);
// Honesty banner — the nodes/dataset counts are hardcoded sample data.
{
QColor warnc(ui::colors::WARNING());
const QString warn_rgb = QString("%1,%2,%3").arg(warnc.red()).arg(warnc.green()).arg(warnc.blue());
sample_note_ =
new QLabel(tr("Sample data — this relationship network is illustrative and is not sourced from a live "
"feed. Severities and connections are placeholders, not real-time conflict metrics. "
"Click a conflict or crisis card for its live events and HDX datasets."),
content);
sample_note_->setWordWrap(true);
sample_note_->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3; padding:8px 10px;"
"background:rgba(%4,0.10); border:1px solid %1;")
.arg(ui::colors::WARNING())
.arg(ui::fonts::SMALL)
.arg(ui::fonts::DATA_FAMILY)
.arg(warn_rgb));
cvl->addWidget(sample_note_);
}
// Helper: add a titled section with a 3-column card grid
auto add_section = [&](const QString& title, const QString& color, const QString& type, QLabel** out) {
auto* sec_lbl = new QLabel(title, content);
if (out)
*out = sec_lbl;
sec_lbl->setStyleSheet(QString("color:%1; font-size:%2px; font-weight:700; font-family:%3;"
"letter-spacing:2px; padding-bottom:4px; border-bottom:1px solid rgba(%4,0.3);")
.arg(color)
.arg(ui::fonts::SMALL)
.arg(ui::fonts::DATA_FAMILY)
.arg(color.mid(1)));
cvl->addWidget(sec_lbl);
auto* grid_w = new QWidget(content);
auto* gl = new QGridLayout(grid_w);
gl->setContentsMargins(0, 0, 0, 0);
gl->setSpacing(10);
// All 3 columns equal width
gl->setColumnStretch(0, 1);
gl->setColumnStretch(1, 1);
gl->setColumnStretch(2, 1);
int col = 0, row = 0;
for (const auto& n : nodes) {
if (n.type != type)
continue;
gl->addWidget(build_node_card(n, grid_w), row, col);
if (++col >= 3) {
col = 0;
row++;
}
}
// Fill remaining cells so columns stay even
while (col > 0 && col < 3) {
auto* spacer = new QWidget(grid_w);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
gl->addWidget(spacer, row, col++);
}
cvl->addWidget(grid_w);
};
add_section(tr("ACTIVE CONFLICTS"), ui::colors::NEGATIVE(), "conflict", &sec_conflicts_);
add_section(tr("CRISIS TYPES"), ui::colors::WARNING(), "crisis", &sec_crisis_);
add_section(tr("ORGANIZATIONS"), ui::colors::INFO(), "organization", &sec_orgs_);
cvl->addStretch();
scroll->setWidget(content);
root->addWidget(scroll, 1);
}
QWidget* RelationshipPanel::build_node_card(const RelationshipNode& node, QWidget* parent) {
auto color = severity_color(node.severity.isEmpty() ? "organization" : node.severity);
const QString col_hex = color.name();
const QString col_rgb = QString("%1,%2,%3").arg(color.red()).arg(color.green()).arg(color.blue());
auto* card = new QWidget(parent);
card->setObjectName("nodeCard");
card->setMinimumHeight(110);
card->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// Conflict and crisis cards open a "show events / browse HDX" menu on click;
// organisations have no drill-down so they stay inert.
if (node.type == QLatin1String("conflict") || node.type == QLatin1String("crisis")) {
card->setProperty("node_id", node.id);
card->setProperty("node_type", node.type);
card->setProperty("node_label", node.label);
card->setCursor(Qt::PointingHandCursor);
card->setToolTip(tr("Click for related events and HDX datasets"));
card->installEventFilter(this);
}
card->setStyleSheet(QString("#nodeCard { background:%1; border:1px solid rgba(%2,0.25);"
"border-left:3px solid %3; }")
.arg(ui::colors::BG_RAISED())
.arg(col_rgb)
.arg(col_hex));
auto* vl = new QVBoxLayout(card);
vl->setContentsMargins(12, 10, 12, 10);
vl->setSpacing(4);
// Name row
auto* name_row = new QWidget(card);
auto* name_hl = new QHBoxLayout(name_row);
name_hl->setContentsMargins(0, 0, 0, 0);
name_hl->setSpacing(6);
auto* name = new QLabel(node.label.toUpper(), name_row);
name->setStyleSheet(QString("color:%1; font-size:%2px; font-weight:700; font-family:%3;")
.arg(col_hex)
.arg(ui::fonts::SMALL)
.arg(ui::fonts::DATA_FAMILY));
name_hl->addWidget(name, 1);
const QString badge_text = node.severity.isEmpty() ? node.type.toUpper() : node.severity.toUpper();
auto* badge = new QLabel(badge_text, name_row);
badge->setStyleSheet(QString("color:%1; font-size:%2px; font-weight:700; font-family:%3;"
"padding:2px 6px; background:rgba(%4,0.12); border:1px solid rgba(%4,0.3);"
"border-radius:8px; letter-spacing:1px;")
.arg(col_hex)
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY)
.arg(col_rgb));
name_hl->addWidget(badge);
vl->addWidget(name_row);
// Type label
auto* type_lbl = new QLabel(node.type.toUpper(), card);
type_lbl->setStyleSheet(QString("color:%1; font-size:%2px; font-family:%3;")
.arg(ui::colors::TEXT_TERTIARY())
.arg(ui::fonts::TINY)
.arg(ui::fonts::DATA_FAMILY));
vl->addWidget(type_lbl);
// Connection pills (max 3)
if (!node.connections.isEmpty()) {
auto* pills_row = new QWidget(card);
auto* pills_hl = new QHBoxLayout(pills_row);
pills_hl->setContentsMargins(0, 2, 0, 0);
pills_hl->setSpacing(4);
const int max_pills = 3;
int shown = qMin(node.connections.size(), max_pills);
for (int i = 0; i < shown; ++i) {
auto* pill = new QLabel(node.connections[i], pills_row);
pill->setStyleSheet(QString("color:%1; font-size:%2px; padding:1px 6px;"
"background:rgba(255,255,255,0.05); border:1px solid %3;"
"border-radius:8px; font-family:%4;")
.arg(ui::colors::TEXT_SECONDARY())
.arg(ui::fonts::TINY)
.arg(ui::colors::BORDER_DIM())
.arg(ui::fonts::DATA_FAMILY));
pills_hl->addWidget(pill);
}
if (node.connections.size() > max_pills) {
auto* more = new QLabel(QString("+%1").arg(node.connections.size() - max_pills), pills_row);
more->setStyleSheet(QString("color:%1; font-size:%2px; padding:1px 6px;"
"background:rgba(255,255,255,0.05); border:1px solid %3;"
"border-radius:8px; font-family:%4;")
.arg(ui::colors::TEXT_TERTIARY())
.arg(ui::fonts::TINY)
.arg(ui::colors::BORDER_DIM())
.arg(ui::fonts::DATA_FAMILY));
pills_hl->addWidget(more);
}
pills_hl->addStretch();
vl->addWidget(pills_row);
}
return card;
}
bool RelationshipPanel::eventFilter(QObject* obj, QEvent* event) {
// Labels inside a card ignore the press, so it propagates up to the card.
if (event->type() == QEvent::MouseButtonPress) {
auto* card = qobject_cast<QWidget*>(obj);
auto* me = static_cast<QMouseEvent*>(event);
if (card && me->button() == Qt::LeftButton && !card->property("node_type").toString().isEmpty()) {
show_node_menu(card);
return true;
}
}
return QWidget::eventFilter(obj, event);
}
void RelationshipPanel::show_node_menu(QWidget* card) {
const QString type = card->property("node_type").toString();
const QString id = card->property("node_id").toString();
const QString label = card->property("node_label").toString();
QMenu menu(this);
if (type == QLatin1String("conflict")) {
connect(menu.addAction(tr("Show %1 events in Monitor").arg(label)), &QAction::triggered, this,
[this, label]() { emit events_requested(label); });
connect(menu.addAction(tr("Browse %1 datasets on HDX").arg(label)), &QAction::triggered, this,
[this, label]() { emit hdx_country_requested(label); });
} else if (type == QLatin1String("crisis")) {
// Node ids are snake_case slugs ("food_security"); HDX topics are plain words.
QString topic = id;
topic.replace(QLatin1Char('_'), QLatin1Char(' '));
connect(menu.addAction(tr("Browse HDX datasets: %1").arg(label)), &QAction::triggered, this,
[this, topic]() { emit hdx_topic_requested(topic); });
}
if (!menu.isEmpty())
menu.exec(QCursor::pos());
}
void RelationshipPanel::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange)
retranslateUi();
QWidget::changeEvent(event);
}
void RelationshipPanel::retranslateUi() {
if (title_lbl_)
title_lbl_->setText(tr("GEOPOLITICAL RELATIONSHIP NETWORK"));
if (sample_badge_) {
sample_badge_->setText(tr("SAMPLE DATA"));
sample_badge_->setToolTip(tr("Illustrative network — not sourced from a live data feed."));
}
if (sample_note_)
sample_note_->setText(
tr("Sample data — this relationship network is illustrative and is not sourced from a live "
"feed. Severities and connections are placeholders, not real-time conflict metrics. "
"Click a conflict or crisis card for its live events and HDX datasets."));
if (stats_lbl_)
stats_lbl_->setText(tr("NODES: %1 | CONFLICTS: %2 | ORGANIZATIONS: %3")
.arg(node_count_)
.arg(conflict_count_)
.arg(org_count_));
if (sec_conflicts_)
sec_conflicts_->setText(tr("ACTIVE CONFLICTS"));
if (sec_crisis_)
sec_crisis_->setText(tr("CRISIS TYPES"));
if (sec_orgs_)
sec_orgs_->setText(tr("ORGANIZATIONS"));
// Node-card entity names/types/connections are fixed data values (not translated).
}
} // namespace fincept::screens