From 5ae714e5842422ae1fec727d1892f9c8f3263bf5 Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Tue, 5 May 2026 17:46:00 +0200 Subject: [PATCH 1/8] centralize context menu code - moved some "refresh interval" code to UIHelper.cpp, to deduplicate code. - called the new UIHelper functions from the graphs, adding the "refresh interval" options to them. --- src/perf/cpudetailwidget.cpp | 3 +- src/perf/diskdetailwidget.cpp | 4 +- src/perf/gpudetailwidget.cpp | 8 +-- src/perf/memorydetailwidget.cpp | 2 +- src/perf/networkdetailwidget.cpp | 2 +- src/perf/swapdetailwidget.cpp | 4 +- src/performancewidget.cpp | 11 ++-- src/processeswidget.cpp | 16 ++--- src/serviceswidget.cpp | 8 +-- src/ui/uihelper.cpp | 108 +++++++++++++++++++------------ src/ui/uihelper.h | 11 ++-- src/userswidget.cpp | 8 +-- 12 files changed, 96 insertions(+), 89 deletions(-) diff --git a/src/perf/cpudetailwidget.cpp b/src/perf/cpudetailwidget.cpp index db2ee3b..dd271ff 100644 --- a/src/perf/cpudetailwidget.cpp +++ b/src/perf/cpudetailwidget.cpp @@ -236,7 +236,8 @@ void CpuDetailWidget::onContextMenuRequested(const QPoint &globalPos) menu.addSeparator(); // ── Copy ───────────────────────────────────────────────────────────────── - UIHelper::AddCopyWidgetAction(&menu, this->m_graphArea, tr("Copy graph")); + // UIHelper::AddCopyWidgetAction(&menu, this->m_graphArea, tr("Copy graph")); + UIHelper::AddGraphContextMenuItems(&menu, this->m_graphArea); menu.exec(globalPos); } diff --git a/src/perf/diskdetailwidget.cpp b/src/perf/diskdetailwidget.cpp index 7250373..e6ef1c6 100644 --- a/src/perf/diskdetailwidget.cpp +++ b/src/perf/diskdetailwidget.cpp @@ -76,8 +76,8 @@ DiskDetailWidget::DiskDetailWidget(QWidget *parent) : QWidget(parent), ui(new Ui this->ui->transferGraphWidget->SetGridRows(4); this->ui->transferGraphWidget->SetSeriesNames(tr("Read"), tr("Write")); this->ui->transferGraphWidget->SetValueFormat(GraphWidget::ValueFormat::BytesPerSec); - UIHelper::EnableCopyWidgetContextMenu(this->ui->activeGraphWidget); - UIHelper::EnableCopyWidgetContextMenu(this->ui->transferGraphWidget); + UIHelper::EnableGraphContextMenu(this->ui->activeGraphWidget); + UIHelper::EnableGraphContextMenu(this->ui->transferGraphWidget); this->ui->activeGraphMaxLabel->setText(tr("100%")); UIHelper::EnableCopyLabelContextMenu(this->ui->activeValueLabel); UIHelper::EnableCopyLabelContextMenu(this->ui->capacityValueLabel); diff --git a/src/perf/gpudetailwidget.cpp b/src/perf/gpudetailwidget.cpp index e88074c..22f3f13 100644 --- a/src/perf/gpudetailwidget.cpp +++ b/src/perf/gpudetailwidget.cpp @@ -78,7 +78,7 @@ GpuDetailWidget::GpuDetailWidget(QWidget *parent) : QWidget(parent), ui(new Ui:: auto *graph = new GraphWidget(this); configureGraph(graph); graph->setMinimumHeight(120); - UIHelper::EnableCopyWidgetContextMenu(graph); + UIHelper::EnableGraphContextMenu(graph); this->m_engineSelectors.append(selector); this->m_engineValueLabels.append(value); @@ -103,17 +103,17 @@ GpuDetailWidget::GpuDetailWidget(QWidget *parent) : QWidget(parent), ui(new Ui:: configureGraph(this->ui->dedicatedMemGraphWidget); this->ui->dedicatedMemGraphWidget->SetSeriesNames(tr("Dedicated memory usage")); - UIHelper::EnableCopyWidgetContextMenu(this->ui->dedicatedMemGraphWidget); + UIHelper::EnableGraphContextMenu(this->ui->dedicatedMemGraphWidget); configureGraph(this->ui->sharedMemGraphWidget); this->ui->sharedMemGraphWidget->SetSeriesNames(tr("Shared memory usage")); - UIHelper::EnableCopyWidgetContextMenu(this->ui->sharedMemGraphWidget); + UIHelper::EnableGraphContextMenu(this->ui->sharedMemGraphWidget); configureGraph(this->ui->copyBwGraphWidget); this->ui->copyBwGraphWidget->SetSeriesNames(tr("TX"), tr("RX")); this->ui->copyBwGraphWidget->SetValueFormat(GraphWidget::ValueFormat::BytesPerSec); this->ui->copyBwGraphWidget->setToolTip(tr("Copy bandwidth: light trace = TX, dark trace = RX")); - UIHelper::EnableCopyWidgetContextMenu(this->ui->copyBwGraphWidget); + UIHelper::EnableGraphContextMenu(this->ui->copyBwGraphWidget); UIHelper::EnableCopyLabelContextMenu(this->ui->utilValueLabel); UIHelper::EnableCopyLabelContextMenu(this->ui->tempValueLabel); diff --git a/src/perf/memorydetailwidget.cpp b/src/perf/memorydetailwidget.cpp index 7b7b18c..2acd4e6 100644 --- a/src/perf/memorydetailwidget.cpp +++ b/src/perf/memorydetailwidget.cpp @@ -73,7 +73,7 @@ MemoryDetailWidget::MemoryDetailWidget(QWidget *parent) : QWidget(parent), ui(ne this->ui->graphWidget->SetGridRows(4); this->ui->graphWidget->SetSeriesNames(tr("Used memory")); this->ui->graphWidget->SetValueFormat(GraphWidget::ValueFormat::Percent); - UIHelper::EnableCopyWidgetContextMenu(this->ui->graphWidget); + UIHelper::EnableGraphContextMenu(this->ui->graphWidget); UIHelper::EnableCopyLabelContextMenu(this->ui->statInUseValue); UIHelper::EnableCopyLabelContextMenu(this->ui->statAvailValue); UIHelper::EnableCopyLabelContextMenu(this->ui->statCompressedValue); diff --git a/src/perf/networkdetailwidget.cpp b/src/perf/networkdetailwidget.cpp index 110ec13..0953bb6 100644 --- a/src/perf/networkdetailwidget.cpp +++ b/src/perf/networkdetailwidget.cpp @@ -176,7 +176,7 @@ void NetworkDetailWidget::onGraphContextMenuRequested(const QPoint &pos) connect(bytesAction, &QAction::triggered, this, &NetworkDetailWidget::onShowBytesTriggered); menu.addSeparator(); - UIHelper::AddCopyWidgetAction(&menu, this->ui->throughputGraphWidget, tr("Copy graph")); + UIHelper::AddGraphContextMenuItems(&menu, this->ui->throughputGraphWidget); menu.exec(this->ui->throughputGraphWidget->mapToGlobal(pos)); } diff --git a/src/perf/swapdetailwidget.cpp b/src/perf/swapdetailwidget.cpp index 57fa8a1..cec700f 100644 --- a/src/perf/swapdetailwidget.cpp +++ b/src/perf/swapdetailwidget.cpp @@ -89,7 +89,7 @@ SwapDetailWidget::SwapDetailWidget(QWidget *parent) : QWidget(parent), ui(new Ui this->ui->activityGraphWidget->setToolTip( tr("Swap in: disk -> RAM (pages read back into memory)\n" "Swap out: RAM -> disk (pages written to swap storage)")); - UIHelper::EnableCopyWidgetContextMenu(this->ui->activityGraphWidget); + UIHelper::EnableGraphContextMenu(this->ui->activityGraphWidget); UIHelper::EnableCopyLabelContextMenu(this->ui->usageValueLabel); UIHelper::EnableCopyLabelContextMenu(this->ui->inUseValueLabel); @@ -221,7 +221,7 @@ void SwapDetailWidget::onContextMenuRequested(const QPoint &globalPos) menu.addSeparator(); - UIHelper::AddCopyWidgetAction(&menu, this->ui->usageGraphArea, tr("Copy graph")); + UIHelper::AddGraphContextMenuItems(&menu, this->ui->usageGraphArea); menu.exec(globalPos); } diff --git a/src/performancewidget.cpp b/src/performancewidget.cpp index a79beac..d423e64 100644 --- a/src/performancewidget.cpp +++ b/src/performancewidget.cpp @@ -378,8 +378,6 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c { QMenu menu(this); QHash graphWindowActions; - QHash refreshIntervalActions; - QAction *pausedRefreshAction = nullptr; QAction *cpu = menu.addAction(tr("CPU")); cpu->setCheckable(true); @@ -427,8 +425,10 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c graphWindowActions.insert(a, sec); } - QMenu *refreshMenu = menu.addMenu(tr("Refresh interval")); - UIHelper::PopulateRefreshIntervalMenu(refreshMenu, refreshIntervalActions, pausedRefreshAction); + menu.addSeparator(); + UIHelper::AddRefreshIntervalContextMenu(&menu); + + menu.addSeparator(); UIHelper::AddGlobalContextMenuItems(&menu, this); QAction *picked = menu.exec(globalPos); @@ -445,9 +445,6 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c return; } - if (UIHelper::ApplyRefreshIntervalAction(picked, refreshIntervalActions, pausedRefreshAction)) - return; - if (picked == customizeOrder) { SidePanelOrderDialog dialog(sanitizeSidePanelGroupOrder(CFG->PerfSidePanelGroupOrder), this); diff --git a/src/processeswidget.cpp b/src/processeswidget.cpp index 11d445f..99f89db 100644 --- a/src/processeswidget.cpp +++ b/src/processeswidget.cpp @@ -565,8 +565,6 @@ void ProcessesWidget::onTableContextMenu(const QPoint &pos) { // Pause refresh during context menu so we don't loose the selection this->m_tableContextMenuOpen = true; - QHash refreshIntervalActions; - QAction *pausedRefreshAction = nullptr; const QModelIndex clickedIndex = this->ui->tableView->indexAt(pos); const QModelIndex targetIndex = clickedIndex.isValid() ? clickedIndex : this->ui->tableView->currentIndex(); @@ -681,12 +679,10 @@ void ProcessesWidget::onTableContextMenu(const QPoint &pos) connect(reniceAction, &QAction::triggered, this, &ProcessesWidget::reniceSelected); menu.addSeparator(); - QMenu *refreshMenu = menu.addMenu(tr("Refresh interval")); - UIHelper::PopulateRefreshIntervalMenu(refreshMenu, refreshIntervalActions, pausedRefreshAction); + UIHelper::AddRefreshIntervalContextMenu(&menu); UIHelper::AddGlobalContextMenuItems(&menu, this); - QAction *picked = menu.exec(this->ui->tableView->viewport()->mapToGlobal(pos)); - UIHelper::ApplyRefreshIntervalAction(picked, refreshIntervalActions, pausedRefreshAction, this->m_refreshTimer, this->m_active); + menu.exec(this->ui->tableView->viewport()->mapToGlobal(pos)); this->m_contextMenuTargetIndex = QModelIndex(); this->m_tableContextMenuOpen = false; @@ -698,8 +694,6 @@ void ProcessesWidget::onTreeContextMenu(const QPoint &pos) { this->m_tableContextMenuOpen = true; QMenu menu(this); - QHash refreshIntervalActions; - QAction *pausedRefreshAction = nullptr; QMenu *viewMenu = menu.addMenu(tr("View")); QAction *kernelAct = viewMenu->addAction(tr("Kernel tasks")); @@ -740,12 +734,10 @@ void ProcessesWidget::onTreeContextMenu(const QPoint &pos) connect(reniceAction, &QAction::triggered, this, &ProcessesWidget::reniceSelected); menu.addSeparator(); - QMenu *refreshMenu = menu.addMenu(tr("Refresh interval")); - UIHelper::PopulateRefreshIntervalMenu(refreshMenu, refreshIntervalActions, pausedRefreshAction); + UIHelper::AddRefreshIntervalContextMenu(&menu); UIHelper::AddGlobalContextMenuItems(&menu, this); - QAction *picked = menu.exec(this->m_treeView->viewport()->mapToGlobal(pos)); - UIHelper::ApplyRefreshIntervalAction(picked, refreshIntervalActions, pausedRefreshAction, this->m_refreshTimer, this->m_active); + menu.exec(this->m_treeView->viewport()->mapToGlobal(pos)); this->m_tableContextMenuOpen = false; if (this->m_active && this->m_refreshPending && !CFG->RefreshPaused) diff --git a/src/serviceswidget.cpp b/src/serviceswidget.cpp index f021db6..216e1e1 100644 --- a/src/serviceswidget.cpp +++ b/src/serviceswidget.cpp @@ -232,8 +232,6 @@ void ServicesWidget::onHeaderContextMenu(const QPoint &pos) void ServicesWidget::onTableContextMenu(const QPoint &pos) { this->m_tableContextMenuOpen = true; - QHash refreshIntervalActions; - QAction *pausedRefreshAction = nullptr; const QModelIndex clickedIndex = this->ui->tableView->indexAt(pos); const QModelIndex targetIndex = clickedIndex.isValid() ? clickedIndex : this->ui->tableView->currentIndex(); @@ -320,12 +318,10 @@ void ServicesWidget::onTableContextMenu(const QPoint &pos) }); menu.addSeparator(); - QMenu *refreshMenu = menu.addMenu(tr("Refresh interval")); - UIHelper::PopulateRefreshIntervalMenu(refreshMenu, refreshIntervalActions, pausedRefreshAction); + UIHelper::AddRefreshIntervalContextMenu(&menu); UIHelper::AddGlobalContextMenuItems(&menu, this); - QAction *picked = menu.exec(this->ui->tableView->viewport()->mapToGlobal(pos)); - UIHelper::ApplyRefreshIntervalAction(picked, refreshIntervalActions, pausedRefreshAction, this->m_refreshTimer, this->m_active); + menu.exec(this->ui->tableView->viewport()->mapToGlobal(pos)); this->m_tableContextMenuOpen = false; } diff --git a/src/ui/uihelper.cpp b/src/ui/uihelper.cpp index 54be159..c06466a 100644 --- a/src/ui/uihelper.cpp +++ b/src/ui/uihelper.cpp @@ -144,26 +144,26 @@ void UIHelper::RestoreTableSelection(QTableView *view, vsb->setValue(snapshot.ScrollPos); } -void UIHelper::PopulateRefreshIntervalMenu(QMenu *menu, QHash &intervalActions, QAction *&pausedAction) -{ - intervalActions.clear(); - pausedAction = nullptr; - if (!menu) - return; - - for (int ms : CFG->RefreshRateAvailableIntervals) - { - QAction *a = menu->addAction(Misc::SimplifyTimeMS(ms)); - a->setCheckable(true); - a->setChecked(!CFG->RefreshPaused && CFG->RefreshRateMs == ms); - intervalActions.insert(a, ms); - } - - menu->addSeparator(); - pausedAction = menu->addAction(QObject::tr("Paused")); - pausedAction->setCheckable(true); - pausedAction->setChecked(CFG->RefreshPaused); -} +// void UIHelper::PopulateRefreshIntervalMenu(QMenu *menu, QHash &intervalActions, QAction *&pausedAction) +// { +// intervalActions.clear(); +// pausedAction = nullptr; +// if (!menu) +// return; + +// for (int ms : CFG->RefreshRateAvailableIntervals) +// { +// QAction *a = menu->addAction(Misc::SimplifyTimeMS(ms)); +// a->setCheckable(true); +// a->setChecked(!CFG->RefreshPaused && CFG->RefreshRateMs == ms); +// intervalActions.insert(a, ms); +// } + +// menu->addSeparator(); +// pausedAction = menu->addAction(QObject::tr("Paused")); +// pausedAction->setCheckable(true); +// pausedAction->setChecked(CFG->RefreshPaused); +// } void UIHelper::AddGlobalContextMenuItems(QMenu *menu, QWidget *parent) { @@ -230,31 +230,59 @@ void UIHelper::EnableCopyWidgetContextMenu(QWidget *widget, const QString &text) }); } -bool UIHelper::ApplyRefreshIntervalAction(QAction *picked, - const QHash &intervalActions, - QAction *pausedAction, - QTimer *timer, - bool timerOwnerActive) +void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu) { - if (!picked) - return false; + QMenu *refreshMenu = menu->addMenu(QObject::tr("Refresh interval")); + + QHash intervalActions; + intervalActions.clear(); - if (intervalActions.contains(picked)) + for (int ms : CFG->RefreshRateAvailableIntervals) { - const int ms = intervalActions.value(picked); - CFG->RefreshPaused = false; - CFG->RefreshRateMs = ms; - Metrics::Get()->SetInterval(ms); - if (timer && timerOwnerActive) - timer->start(ms); - return true; + QAction *a = refreshMenu->addAction(Misc::SimplifyTimeMS(ms)); + a->setCheckable(true); + a->setChecked(!CFG->RefreshPaused && CFG->RefreshRateMs == ms); + intervalActions.insert(a, ms); + + QObject::connect(a, &QAction::triggered, menu, [=]() + { + const int ms = intervalActions.value(a); + CFG->RefreshPaused = false; + CFG->RefreshRateMs = ms; + Metrics::Get()->SetInterval(ms); + }); } - if (picked == pausedAction) - { + refreshMenu->addSeparator(); + + QAction *pausedAction = refreshMenu->addAction(QObject::tr("Paused")); + pausedAction->setCheckable(true); + pausedAction->setChecked(CFG->RefreshPaused); + + QObject::connect(pausedAction, &QAction::triggered, []{ CFG->RefreshPaused = true; - return true; - } + }); +} - return false; +void UIHelper::AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea) +{ + AddRefreshIntervalContextMenu(menu); + + menu->addSeparator(); + + AddCopyWidgetAction(menu, graphArea, QObject::tr("Copy graph")); } + +void UIHelper::EnableGraphContextMenu(QWidget *widget) +{ + if (!widget) + return; + + widget->setContextMenuPolicy(Qt::CustomContextMenu); + QObject::connect(widget, &QWidget::customContextMenuRequested, widget, [widget](const QPoint &pos) + { + QMenu menu(widget); + AddGraphContextMenuItems(&menu, widget); + menu.exec(widget->mapToGlobal(pos)); + }); +} \ No newline at end of file diff --git a/src/ui/uihelper.h b/src/ui/uihelper.h index 66bf354..407ab90 100644 --- a/src/ui/uihelper.h +++ b/src/ui/uihelper.h @@ -56,20 +56,17 @@ namespace UIHelper const std::function &sourceKeyResolver, const TableSelectionSnapshot &snapshot); - void PopulateRefreshIntervalMenu(QMenu *menu, QHash &intervalActions, QAction *&pausedAction); + // void PopulateRefreshIntervalMenu(QMenu *menu, QHash &intervalActions, QAction *&pausedAction); void AddGlobalContextMenuItems(QMenu *menu, QWidget *parent = nullptr); + void AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea); + void EnableGraphContextMenu(QWidget *widget); + void AddRefreshIntervalContextMenu(QMenu *menu); //! Adds a context menu with a Copy action that copies the label text to the clipboard. void EnableCopyLabelContextMenu(QLabel *label); //! Adds a Copy graph action to an existing menu that copies the widget snapshot to the clipboard. QAction *AddCopyWidgetAction(QMenu *menu, QWidget *widget, const QString &text = QString()); //! Adds a context menu with a Copy graph action that copies the widget snapshot to the clipboard. void EnableCopyWidgetContextMenu(QWidget *widget, const QString &text = QString()); - - bool ApplyRefreshIntervalAction(QAction *picked, - const QHash &intervalActions, - QAction *pausedAction, - QTimer *timer = nullptr, - bool timerOwnerActive = true); } #endif // UI_UIHELPER_H diff --git a/src/userswidget.cpp b/src/userswidget.cpp index 2dc7ab7..6e8beef 100644 --- a/src/userswidget.cpp +++ b/src/userswidget.cpp @@ -193,8 +193,6 @@ void UsersWidget::onRefreshFinished(int consumer, quint64 token, const QList refreshIntervalActions; - QAction *pausedRefreshAction = nullptr; const QTreeWidgetItem *item = this->ui->treeWidget->itemAt(pos); const bool isProcessItem = item && item->parent(); @@ -212,12 +210,10 @@ void UsersWidget::onContextMenu(const QPoint &pos) menu.addSeparator(); } - QMenu *refreshMenu = menu.addMenu(tr("Refresh interval")); - UIHelper::PopulateRefreshIntervalMenu(refreshMenu, refreshIntervalActions, pausedRefreshAction); + UIHelper::AddRefreshIntervalContextMenu(&menu); UIHelper::AddGlobalContextMenuItems(&menu, this); - QAction *picked = menu.exec(this->ui->treeWidget->viewport()->mapToGlobal(pos)); - UIHelper::ApplyRefreshIntervalAction(picked, refreshIntervalActions, pausedRefreshAction, this->m_refreshTimer, this->m_active); + menu.exec(this->ui->treeWidget->viewport()->mapToGlobal(pos)); } void UsersWidget::rebuildTree(const QList &allProcs) From dc97d70a318ae342ab7d040839fc7ff0ec5c6cc7 Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Tue, 5 May 2026 19:21:21 +0200 Subject: [PATCH 2/8] Move "graph time" context option to UIHelper Moved the "graph time" code to UIHelper, making it also available for the graphs Added PerformanceWidget::Get() to be able to call it's functions from UIHelper. --- src/performancewidget.cpp | 30 +++++------------------------- src/performancewidget.h | 9 ++++++--- src/ui/uihelper.cpp | 33 ++++++++++++++++++++++++++++++++- src/ui/uihelper.h | 1 + 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/performancewidget.cpp b/src/performancewidget.cpp index d423e64..46cf213 100644 --- a/src/performancewidget.cpp +++ b/src/performancewidget.cpp @@ -74,8 +74,12 @@ namespace // Construction //////////////////////////////////////////////////////////////////////////////////////////////////// +PerformanceWidget *PerformanceWidget::s_instance = nullptr; + PerformanceWidget::PerformanceWidget(QWidget *parent) : QWidget(parent), ui(new Ui::PerformanceWidget) { + s_instance = this; + // Ensure the metrics are initialized before we start enumerating devices Metrics::Get(); @@ -122,6 +126,7 @@ PerformanceWidget::PerformanceWidget(QWidget *parent) : QWidget(parent), ui(new PerformanceWidget::~PerformanceWidget() { + s_instance = nullptr; delete this->ui; } @@ -377,7 +382,6 @@ void PerformanceWidget::SetActive(bool active) void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, const QPoint &globalPos) { QMenu menu(this); - QHash graphWindowActions; QAction *cpu = menu.addAction(tr("CPU")); cpu->setCheckable(true); @@ -411,20 +415,6 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c showGrid->setCheckable(true); showGrid->setChecked(CFG->SidePanelGridEnabled); - menu.addSeparator(); - QMenu *timeMenu = menu.addMenu(tr("Graph time")); - QVector intervals = CFG->DataWindowAvailableIntervals; - if (intervals.isEmpty()) - intervals.append(CFG->PerfGraphWindowSec); - - for (int sec : intervals) - { - QAction *a = timeMenu->addAction(Misc::SimplifyTime(sec)); - a->setCheckable(true); - a->setChecked(CFG->PerfGraphWindowSec == sec); - graphWindowActions.insert(a, sec); - } - menu.addSeparator(); UIHelper::AddRefreshIntervalContextMenu(&menu); @@ -435,16 +425,6 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c if (!picked) return; - if (graphWindowActions.contains(picked)) - { - const int requestedWindow = graphWindowActions.value(picked); - CFG->PerfGraphWindowSec = requestedWindow; - this->applyGraphWindowSeconds(); - if (this->m_active) - this->onProviderUpdated(); - return; - } - if (picked == customizeOrder) { SidePanelOrderDialog dialog(sanitizeSidePanelGroupOrder(CFG->PerfSidePanelGroupOrder), this); diff --git a/src/performancewidget.h b/src/performancewidget.h index 89e118b..6084495 100644 --- a/src/performancewidget.h +++ b/src/performancewidget.h @@ -40,6 +40,8 @@ QT_END_NAMESPACE class PerformanceWidget : public QWidget { Q_OBJECT + + static PerformanceWidget *s_instance; public: explicit PerformanceWidget(QWidget *parent = nullptr); @@ -47,9 +49,11 @@ class PerformanceWidget : public QWidget void SetActive(bool active); bool IsActive() const { return this->m_active; } void ApplyColorScheme(); - - private slots: + static PerformanceWidget *Get() { return s_instance; }; void onProviderUpdated(); + void applyGraphWindowSeconds(); + + private slots: void onSidePanelContextMenu(Perf::SidePanelItem *item, const QPoint &globalPos); private: @@ -81,7 +85,6 @@ class PerformanceWidget : public QWidget void setupGpuPanels(); void applySidePanelOrder(); void tagTimeAxisLabels(); - void applyGraphWindowSeconds(); void applyPanelVisibility(); void applySidePanelGridEnabled(); void updateSamplingPolicy(); diff --git a/src/ui/uihelper.cpp b/src/ui/uihelper.cpp index c06466a..55394dc 100644 --- a/src/ui/uihelper.cpp +++ b/src/ui/uihelper.cpp @@ -21,6 +21,7 @@ #include "../configuration.h" #include "../metrics.h" #include "../misc.h" +#include "../performancewidget.h" #include #include @@ -264,12 +265,42 @@ void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu) }); } +void UIHelper::AddGraphWindowContextMenu(QMenu *menu) +{ + QMenu *timeMenu = menu->addMenu(QObject::tr("Graph time")); + QVector intervals = CFG->DataWindowAvailableIntervals; + if (intervals.isEmpty()) + intervals.append(CFG->PerfGraphWindowSec); + QHash graphWindowActions; + + for (int sec : intervals) + { + QAction *a = timeMenu->addAction(Misc::SimplifyTime(sec)); + a->setCheckable(true); + a->setChecked(CFG->PerfGraphWindowSec == sec); + graphWindowActions.insert(a, sec); + + QObject::connect(a, &QAction::triggered, menu, [=]() + { + const int requestedWindow = graphWindowActions.value(a); + CFG->PerfGraphWindowSec = requestedWindow; + PerformanceWidget *pw = PerformanceWidget::Get(); + if (pw) + { + pw->applyGraphWindowSeconds(); + if (pw->IsActive()) + pw->onProviderUpdated(); + } + }); + } +} + void UIHelper::AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea) { AddRefreshIntervalContextMenu(menu); + AddGraphWindowContextMenu(menu); menu->addSeparator(); - AddCopyWidgetAction(menu, graphArea, QObject::tr("Copy graph")); } diff --git a/src/ui/uihelper.h b/src/ui/uihelper.h index 407ab90..8693cef 100644 --- a/src/ui/uihelper.h +++ b/src/ui/uihelper.h @@ -60,6 +60,7 @@ namespace UIHelper void AddGlobalContextMenuItems(QMenu *menu, QWidget *parent = nullptr); void AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea); void EnableGraphContextMenu(QWidget *widget); + void AddGraphWindowContextMenu(QMenu *menu); void AddRefreshIntervalContextMenu(QMenu *menu); //! Adds a context menu with a Copy action that copies the label text to the clipboard. void EnableCopyLabelContextMenu(QLabel *label); From 3e52f4ff934e2b9226a6089b2d731ab5977fd0ed Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Tue, 5 May 2026 20:09:39 +0200 Subject: [PATCH 3/8] add back timer updates ported the timer and onProviderUpdated calls that were present in the old performanceWidget code --- src/performancewidget.cpp | 2 +- src/processeswidget.cpp | 4 ++-- src/serviceswidget.cpp | 2 +- src/ui/uihelper.cpp | 20 +++++++++++++++++--- src/ui/uihelper.h | 2 +- src/userswidget.cpp | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/performancewidget.cpp b/src/performancewidget.cpp index 46cf213..dca9efa 100644 --- a/src/performancewidget.cpp +++ b/src/performancewidget.cpp @@ -416,7 +416,7 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c showGrid->setChecked(CFG->SidePanelGridEnabled); menu.addSeparator(); - UIHelper::AddRefreshIntervalContextMenu(&menu); + UIHelper::AddRefreshIntervalContextMenu(&menu, nullptr, this->m_active); menu.addSeparator(); UIHelper::AddGlobalContextMenuItems(&menu, this); diff --git a/src/processeswidget.cpp b/src/processeswidget.cpp index 99f89db..44f2a60 100644 --- a/src/processeswidget.cpp +++ b/src/processeswidget.cpp @@ -679,7 +679,7 @@ void ProcessesWidget::onTableContextMenu(const QPoint &pos) connect(reniceAction, &QAction::triggered, this, &ProcessesWidget::reniceSelected); menu.addSeparator(); - UIHelper::AddRefreshIntervalContextMenu(&menu); + UIHelper::AddRefreshIntervalContextMenu(&menu, this->m_refreshTimer, this->m_active); UIHelper::AddGlobalContextMenuItems(&menu, this); menu.exec(this->ui->tableView->viewport()->mapToGlobal(pos)); @@ -734,7 +734,7 @@ void ProcessesWidget::onTreeContextMenu(const QPoint &pos) connect(reniceAction, &QAction::triggered, this, &ProcessesWidget::reniceSelected); menu.addSeparator(); - UIHelper::AddRefreshIntervalContextMenu(&menu); + UIHelper::AddRefreshIntervalContextMenu(&menu, this->m_refreshTimer, this->m_active); UIHelper::AddGlobalContextMenuItems(&menu, this); menu.exec(this->m_treeView->viewport()->mapToGlobal(pos)); diff --git a/src/serviceswidget.cpp b/src/serviceswidget.cpp index 216e1e1..b2e856a 100644 --- a/src/serviceswidget.cpp +++ b/src/serviceswidget.cpp @@ -318,7 +318,7 @@ void ServicesWidget::onTableContextMenu(const QPoint &pos) }); menu.addSeparator(); - UIHelper::AddRefreshIntervalContextMenu(&menu); + UIHelper::AddRefreshIntervalContextMenu(&menu, this->m_refreshTimer, this->m_active); UIHelper::AddGlobalContextMenuItems(&menu, this); menu.exec(this->ui->tableView->viewport()->mapToGlobal(pos)); diff --git a/src/ui/uihelper.cpp b/src/ui/uihelper.cpp index 55394dc..142137c 100644 --- a/src/ui/uihelper.cpp +++ b/src/ui/uihelper.cpp @@ -231,7 +231,7 @@ void UIHelper::EnableCopyWidgetContextMenu(QWidget *widget, const QString &text) }); } -void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu) +void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu, QTimer *timer, bool timerOwnerActive) { QMenu *refreshMenu = menu->addMenu(QObject::tr("Refresh interval")); @@ -245,12 +245,19 @@ void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu) a->setChecked(!CFG->RefreshPaused && CFG->RefreshRateMs == ms); intervalActions.insert(a, ms); - QObject::connect(a, &QAction::triggered, menu, [=]() + QObject::connect(a, &QAction::triggered, menu, [menu, a, intervalActions, timer, timerOwnerActive]() { const int ms = intervalActions.value(a); CFG->RefreshPaused = false; CFG->RefreshRateMs = ms; Metrics::Get()->SetInterval(ms); + PerformanceWidget *pw = PerformanceWidget::Get(); + if (pw && pw->IsActive()) { + pw->onProviderUpdated(); + } + if (timer && timerOwnerActive) { + timer->start(ms); + } }); } @@ -260,8 +267,15 @@ void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu) pausedAction->setCheckable(true); pausedAction->setChecked(CFG->RefreshPaused); - QObject::connect(pausedAction, &QAction::triggered, []{ + QObject::connect(pausedAction, &QAction::triggered, menu, [menu, timer, timerOwnerActive](){ CFG->RefreshPaused = true; + PerformanceWidget *pw = PerformanceWidget::Get(); + if (pw && pw->IsActive()) { + pw->onProviderUpdated(); + } + if (timer && timerOwnerActive) { + timer->stop(); + } }); } diff --git a/src/ui/uihelper.h b/src/ui/uihelper.h index 8693cef..add2e8c 100644 --- a/src/ui/uihelper.h +++ b/src/ui/uihelper.h @@ -61,7 +61,7 @@ namespace UIHelper void AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea); void EnableGraphContextMenu(QWidget *widget); void AddGraphWindowContextMenu(QMenu *menu); - void AddRefreshIntervalContextMenu(QMenu *menu); + void AddRefreshIntervalContextMenu(QMenu *menu, QTimer *timer = nullptr, bool timerOwnerActive = false); //! Adds a context menu with a Copy action that copies the label text to the clipboard. void EnableCopyLabelContextMenu(QLabel *label); //! Adds a Copy graph action to an existing menu that copies the widget snapshot to the clipboard. diff --git a/src/userswidget.cpp b/src/userswidget.cpp index 6e8beef..f4adb09 100644 --- a/src/userswidget.cpp +++ b/src/userswidget.cpp @@ -210,7 +210,7 @@ void UsersWidget::onContextMenu(const QPoint &pos) menu.addSeparator(); } - UIHelper::AddRefreshIntervalContextMenu(&menu); + UIHelper::AddRefreshIntervalContextMenu(&menu, this->m_refreshTimer, this->m_active); UIHelper::AddGlobalContextMenuItems(&menu, this); menu.exec(this->ui->treeWidget->viewport()->mapToGlobal(pos)); From 5a1fa191b441cea7afe46847f70f80e4df30867d Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Tue, 5 May 2026 20:24:39 +0200 Subject: [PATCH 4/8] remove old code --- src/perf/cpudetailwidget.cpp | 1 - src/ui/uihelper.cpp | 21 --------------------- src/ui/uihelper.h | 1 - 3 files changed, 23 deletions(-) diff --git a/src/perf/cpudetailwidget.cpp b/src/perf/cpudetailwidget.cpp index dd271ff..39a933e 100644 --- a/src/perf/cpudetailwidget.cpp +++ b/src/perf/cpudetailwidget.cpp @@ -236,7 +236,6 @@ void CpuDetailWidget::onContextMenuRequested(const QPoint &globalPos) menu.addSeparator(); // ── Copy ───────────────────────────────────────────────────────────────── - // UIHelper::AddCopyWidgetAction(&menu, this->m_graphArea, tr("Copy graph")); UIHelper::AddGraphContextMenuItems(&menu, this->m_graphArea); menu.exec(globalPos); diff --git a/src/ui/uihelper.cpp b/src/ui/uihelper.cpp index 142137c..95efafd 100644 --- a/src/ui/uihelper.cpp +++ b/src/ui/uihelper.cpp @@ -145,27 +145,6 @@ void UIHelper::RestoreTableSelection(QTableView *view, vsb->setValue(snapshot.ScrollPos); } -// void UIHelper::PopulateRefreshIntervalMenu(QMenu *menu, QHash &intervalActions, QAction *&pausedAction) -// { -// intervalActions.clear(); -// pausedAction = nullptr; -// if (!menu) -// return; - -// for (int ms : CFG->RefreshRateAvailableIntervals) -// { -// QAction *a = menu->addAction(Misc::SimplifyTimeMS(ms)); -// a->setCheckable(true); -// a->setChecked(!CFG->RefreshPaused && CFG->RefreshRateMs == ms); -// intervalActions.insert(a, ms); -// } - -// menu->addSeparator(); -// pausedAction = menu->addAction(QObject::tr("Paused")); -// pausedAction->setCheckable(true); -// pausedAction->setChecked(CFG->RefreshPaused); -// } - void UIHelper::AddGlobalContextMenuItems(QMenu *menu, QWidget *parent) { if (!menu) diff --git a/src/ui/uihelper.h b/src/ui/uihelper.h index add2e8c..873aa40 100644 --- a/src/ui/uihelper.h +++ b/src/ui/uihelper.h @@ -56,7 +56,6 @@ namespace UIHelper const std::function &sourceKeyResolver, const TableSelectionSnapshot &snapshot); - // void PopulateRefreshIntervalMenu(QMenu *menu, QHash &intervalActions, QAction *&pausedAction); void AddGlobalContextMenuItems(QMenu *menu, QWidget *parent = nullptr); void AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea); void EnableGraphContextMenu(QWidget *widget); From 0760aac8626b6d6f50545cee13dc03c57709cedc Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Tue, 5 May 2026 22:03:49 +0200 Subject: [PATCH 5/8] add back "graph time" option to side panel --- src/performancewidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/performancewidget.cpp b/src/performancewidget.cpp index dca9efa..e7a1afc 100644 --- a/src/performancewidget.cpp +++ b/src/performancewidget.cpp @@ -417,6 +417,7 @@ void PerformanceWidget::onSidePanelContextMenu(Perf::SidePanelItem * /*item*/, c menu.addSeparator(); UIHelper::AddRefreshIntervalContextMenu(&menu, nullptr, this->m_active); + UIHelper::AddGraphWindowContextMenu(&menu); menu.addSeparator(); UIHelper::AddGlobalContextMenuItems(&menu, this); From 0fe40ebfe2ea7b82759dd69d2b63981b737a13f8 Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Wed, 6 May 2026 15:18:08 +0200 Subject: [PATCH 6/8] add comments about UIHelper functions --- src/ui/uihelper.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ui/uihelper.h b/src/ui/uihelper.h index 873aa40..1eaf473 100644 --- a/src/ui/uihelper.h +++ b/src/ui/uihelper.h @@ -57,9 +57,13 @@ namespace UIHelper const TableSelectionSnapshot &snapshot); void AddGlobalContextMenuItems(QMenu *menu, QWidget *parent = nullptr); + //! Adds context actions relevant to graphs to a context menu. void AddGraphContextMenuItems(QMenu *menu, QWidget *graphArea); + //! Adds context menu relevant to graphs to a widget. void EnableGraphContextMenu(QWidget *widget); + //! Adds a "Graph time" contex menu to an existing menu that gives options to change the timespan of a graph. void AddGraphWindowContextMenu(QMenu *menu); + //! Adds a "Refresh interval" contex menu to an existing menu that gives options to change the refresh rate. void AddRefreshIntervalContextMenu(QMenu *menu, QTimer *timer = nullptr, bool timerOwnerActive = false); //! Adds a context menu with a Copy action that copies the label text to the clipboard. void EnableCopyLabelContextMenu(QLabel *label); From 3136c6a31e85c9fb217ba870df3985dbbdbef09d Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Wed, 6 May 2026 16:25:41 +0200 Subject: [PATCH 7/8] remove unused EnableCopyWidgetContextMenu() function --- src/ui/uihelper.cpp | 14 -------------- src/ui/uihelper.h | 2 -- 2 files changed, 16 deletions(-) diff --git a/src/ui/uihelper.cpp b/src/ui/uihelper.cpp index 95efafd..bd62992 100644 --- a/src/ui/uihelper.cpp +++ b/src/ui/uihelper.cpp @@ -196,20 +196,6 @@ QAction *UIHelper::AddCopyWidgetAction(QMenu *menu, QWidget *widget, const QStri return copyAction; } -void UIHelper::EnableCopyWidgetContextMenu(QWidget *widget, const QString &text) -{ - if (!widget) - return; - - widget->setContextMenuPolicy(Qt::CustomContextMenu); - QObject::connect(widget, &QWidget::customContextMenuRequested, widget, [widget, text](const QPoint &pos) - { - QMenu menu(widget); - AddCopyWidgetAction(&menu, widget, text); - menu.exec(widget->mapToGlobal(pos)); - }); -} - void UIHelper::AddRefreshIntervalContextMenu(QMenu *menu, QTimer *timer, bool timerOwnerActive) { QMenu *refreshMenu = menu->addMenu(QObject::tr("Refresh interval")); diff --git a/src/ui/uihelper.h b/src/ui/uihelper.h index 1eaf473..8e791e4 100644 --- a/src/ui/uihelper.h +++ b/src/ui/uihelper.h @@ -69,8 +69,6 @@ namespace UIHelper void EnableCopyLabelContextMenu(QLabel *label); //! Adds a Copy graph action to an existing menu that copies the widget snapshot to the clipboard. QAction *AddCopyWidgetAction(QMenu *menu, QWidget *widget, const QString &text = QString()); - //! Adds a context menu with a Copy graph action that copies the widget snapshot to the clipboard. - void EnableCopyWidgetContextMenu(QWidget *widget, const QString &text = QString()); } #endif // UI_UIHELPER_H From 8f8bdb4a1383bd38ccf0bf3a6f144af9fab55c12 Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Fri, 8 May 2026 20:00:00 +0200 Subject: [PATCH 8/8] make `*s_instance` private --- src/performancewidget.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/performancewidget.h b/src/performancewidget.h index 6084495..46b379e 100644 --- a/src/performancewidget.h +++ b/src/performancewidget.h @@ -41,8 +41,6 @@ class PerformanceWidget : public QWidget { Q_OBJECT - static PerformanceWidget *s_instance; - public: explicit PerformanceWidget(QWidget *parent = nullptr); ~PerformanceWidget(); @@ -57,6 +55,8 @@ class PerformanceWidget : public QWidget void onSidePanelContextMenu(Perf::SidePanelItem *item, const QPoint &globalPos); private: + static PerformanceWidget *s_instance; + Ui::PerformanceWidget *ui; Perf::SidePanel *m_sidePanel; QStackedWidget *m_stack;