@@ -49,9 +49,7 @@ KsMainWindow::KsMainWindow(QWidget *parent)
_quitAction("Quit", this),
_importFilterAction("Import Filter", this),
_exportFilterAction("Export Filter", this),
- _graphFilterSyncAction(this),
_graphFilterSyncCBox(nullptr),
- _listFilterSyncAction(this),
_listFilterSyncCBox(nullptr),
_showEventsAction("Show events", this),
_showTasksAction("Show tasks", this),
@@ -292,22 +290,13 @@ void KsMainWindow::_createMenus()
/* Filter menu */
filter = menuBar()->addMenu("Filter");
+
+ connect(filter, &QMenu::aboutToShow,
+ this, &KsMainWindow::_updateFilterMenu);
+
filter->addAction(&_importFilterAction);
filter->addAction(&_exportFilterAction);
- auto lamMakeCBAction = [&](QWidgetAction *action, QString name)
- {
- QWidget *containerWidget = new QWidget(filter);
- containerWidget->setLayout(new QHBoxLayout());
- containerWidget->layout()->setContentsMargins(FONT_WIDTH, FONT_HEIGHT/5,
- FONT_WIDTH, FONT_HEIGHT/5);
- QCheckBox *checkBox = new QCheckBox(name, filter);
- checkBox->setChecked(true);
- containerWidget->layout()->addWidget(checkBox);
- action->setDefaultWidget(containerWidget);
- return checkBox;
- };
-
/*
* Set the default filter mask. Filter will apply to both View and
* Graph.
@@ -317,20 +306,20 @@ void KsMainWindow::_createMenus()
kshark_ctx->filter_mask |= KS_EVENT_VIEW_FILTER_MASK;
- _graphFilterSyncCBox = lamMakeCBAction(&_graphFilterSyncAction,
- "Apply filters to Graph");
+ _graphFilterSyncCBox =
+ KsUtils::addCheckBoxToMenu(filter, "Apply filters to Graph");
+ _graphFilterSyncCBox->setChecked(true);
connect(_graphFilterSyncCBox, &QCheckBox::stateChanged,
this, &KsMainWindow::_graphFilterSync);
- _listFilterSyncCBox = lamMakeCBAction(&_listFilterSyncAction,
- "Apply filters to List");
+ _listFilterSyncCBox =
+ KsUtils::addCheckBoxToMenu(filter, "Apply filters to List");
+ _listFilterSyncCBox->setChecked(true);
connect(_listFilterSyncCBox, &QCheckBox::stateChanged,
this, &KsMainWindow::_listFilterSync);
- filter->addAction(&_graphFilterSyncAction);
- filter->addAction(&_listFilterSyncAction);
filter->addAction(&_showEventsAction);
filter->addAction(&_showTasksAction);
filter->addAction(&_hideTasksAction);
@@ -446,6 +435,14 @@ void KsMainWindow::_filterSyncCBoxUpdate(kshark_context *kshark_ctx)
_graphFilterSyncCBox->setChecked(false);
}
+void KsMainWindow::_updateFilterMenu()
+{
+ kshark_context *kshark_ctx(nullptr);
+
+ if (kshark_instance(&kshark_ctx))
+ _filterSyncCBoxUpdate(kshark_ctx);
+}
+
void KsMainWindow::_importFilter()
{
kshark_context *kshark_ctx(nullptr);
@@ -110,12 +110,8 @@ private:
QAction _exportFilterAction;
- QWidgetAction _graphFilterSyncAction;
-
QCheckBox *_graphFilterSyncCBox;
- QWidgetAction _listFilterSyncAction;
-
QCheckBox *_listFilterSyncCBox;
QAction _showEventsAction;
@@ -222,6 +218,8 @@ private:
void _deselect();
+ void _updateFilterMenu();
+
void _filterSyncCBoxUpdate(kshark_context *kshark_ctx);
private slots:
@@ -95,6 +95,31 @@ void graphFilterSync(bool state)
}
}
+
+/**
+ * @brief Add a checkbox to a menu.
+ *
+ * @param menu: Input location for the menu object, to which the checkbox will be added.
+ * @param name: The name of the checkbox.
+ *
+ * @returns The checkbox object;
+ */
+QCheckBox *addCheckBoxToMenu(QMenu *menu, QString name)
+{
+ QWidget *containerWidget = new QWidget(menu);
+ containerWidget->setLayout(new QHBoxLayout());
+ containerWidget->layout()->setContentsMargins(FONT_WIDTH, FONT_HEIGHT/5,
+ FONT_WIDTH, FONT_HEIGHT/5);
+ QCheckBox *checkBox = new QCheckBox(name, menu);
+ containerWidget->layout()->addWidget(checkBox);
+
+ QWidgetAction *action = new QWidgetAction(menu);
+ action->setDefaultWidget(containerWidget);
+ menu->addAction(action);
+
+ return checkBox;
+}
+
/**
* @brief Simple CPU matching function to be user for data collections.
*
@@ -93,6 +93,8 @@ void listFilterSync(bool state);
void graphFilterSync(bool state);
+QCheckBox *addCheckBoxToMenu(QMenu *menu, QString name);
+
/** @brief Convert the timestamp of the trace record into a string showing
* the time in seconds.
*
The code responsible for the creation of the "Apply filters to Graph" and "Apply filters to List" checkboxes (showing in the "Filtering" menu), has been moved outside of the KsMainWindow class and is now available in KsUtils. This is done because we want to have the same checkboxes available in the KsQuickContextMenu. Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com> --- kernel-shark-qt/src/KsMainWindow.cpp | 39 +++++++++++++--------------- kernel-shark-qt/src/KsMainWindow.hpp | 6 ++--- kernel-shark-qt/src/KsUtils.cpp | 25 ++++++++++++++++++ kernel-shark-qt/src/KsUtils.hpp | 2 ++ 4 files changed, 47 insertions(+), 25 deletions(-)