Commit 8e6ffb78 authored by Josef Weidendorfer's avatar Josef Weidendorfer
Browse files

QCachegrind View menu now same as in KCachegrind

It may be confusing if menu items are missing, and so
add sub-menus to QCachegrind View menu for event type
selection and grouping. Both where already reachable
by context menues, but better show them explicit.
parent 446a8170
......@@ -302,7 +302,8 @@ void FunctionSelection::functionContext(const QPoint & p)
}
}
addGroupMenu(&popup);
QMenu* m = popup.addMenu(tr("Grouping"));
updateGroupingMenu(m);
popup.addSeparator();
addGoMenu(&popup);
......@@ -321,7 +322,8 @@ void FunctionSelection::groupContext(const QPoint & p)
addEventTypeMenu(&popup,false);
popup.addSeparator();
}
addGroupMenu(&popup);
QMenu* m = popup.addMenu(tr("Grouping"));
updateGroupingMenu(m);
popup.addSeparator();
addGoMenu(&popup);
......@@ -343,24 +345,29 @@ void FunctionSelection::addGroupAction(QMenu* m,
a->setChecked(_groupType == v);
}
void FunctionSelection::addGroupMenu(QMenu* menu)
// Clears and repopulates the given menu with dynamic items for grouping.
// Menu item handlers for setting the grouping are installed.
void FunctionSelection::updateGroupingMenu(QMenu* m)
{
QMenu* m = menu->addMenu(tr("Grouping"));
if (!m) return;
m->clear();
// use a unique connection, as we may be called multiple times
// for same menu (e.g. for repopulating a menu related to a QAction)
connect(m, SIGNAL(triggered(QAction*)),
this, SLOT(groupTypeSelected(QAction*)), Qt::UniqueConnection);
if (_groupType != ProfileContext::Function) {
addGroupAction(m, ProfileContext::Function, tr("No Grouping"));
m->addSeparator();
addGroupAction(m, ProfileContext::Function, tr("No Grouping"));
m->addSeparator();
}
if (_data && _data->objectMap().count()>1)
addGroupAction(m, ProfileContext::Object);
addGroupAction(m, ProfileContext::Object);
if (_data && _data->fileMap().count()>1)
addGroupAction(m, ProfileContext::File);
addGroupAction(m, ProfileContext::File);
if (_data && _data->classMap().count()>1)
addGroupAction(m, ProfileContext::Class);
addGroupAction(m, ProfileContext::Class);
addGroupAction(m, ProfileContext::FunctionCycle);
connect(m, SIGNAL(triggered(QAction*)),
this, SLOT(groupTypeSelected(QAction*)));
}
......
......@@ -60,7 +60,7 @@ public:
QString whatsThis() const;
void setData(TraceData*);
void addGroupMenu(QMenu*);
void updateGroupingMenu(QMenu*);
public slots:
void searchReturnPressed();
......
......@@ -258,6 +258,24 @@ void QCGTopLevel::recentFilesTriggered(QAction* action)
load(QStringList(QDir::fromNativeSeparators(action->text())));
}
void QCGTopLevel::primaryAboutToShow()
{
updateEventTypeMenu(_primaryMenuAction->menu(), false);
}
void QCGTopLevel::secondaryAboutToShow()
{
updateEventTypeMenu(_secondaryMenuAction->menu(), true);
}
void QCGTopLevel::groupingAboutToShow()
{
if (!_functionSelection) return;
_functionSelection->updateGroupingMenu(_groupingMenuAction->menu());
}
void QCGTopLevel::createDocks()
{
// part visualization/selection side bar
......@@ -356,6 +374,20 @@ void QCGTopLevel::createActions()
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
// view menu actions
_primaryMenuAction = new QAction(tr( "Primary Event Type" ), this );
_primaryMenuAction->setMenu(new QMenu(this));
connect(_primaryMenuAction->menu(), &QMenu::aboutToShow,
this, &QCGTopLevel::primaryAboutToShow );
_secondaryMenuAction = new QAction(tr( "Secondary Event Type" ), this );
_secondaryMenuAction->setMenu(new QMenu(this));
connect(_secondaryMenuAction->menu(), &QMenu::aboutToShow,
this, &QCGTopLevel::secondaryAboutToShow );
_groupingMenuAction = new QAction(tr( "Grouping" ), this );
_groupingMenuAction->setMenu(new QMenu(this));
connect(_groupingMenuAction->menu(), &QMenu::aboutToShow,
this, &QCGTopLevel::groupingAboutToShow );
icon = QApplication::style()->standardIcon(QStyle::SP_BrowserReload);
_cyclesToggleAction = new QAction(icon, tr("Detect Cycles"), this);
_cyclesToggleAction->setCheckable(true);
......@@ -559,14 +591,18 @@ void QCGTopLevel::createMenu()
layoutMenu->addAction(_layoutRestore);
QMenu* viewMenu = mBar->addMenu(tr("&View"));
viewMenu->addAction(_primaryMenuAction);
viewMenu->addAction(_secondaryMenuAction);
viewMenu->addAction(_groupingMenuAction);
viewMenu->addSeparator();
viewMenu->addMenu(layoutMenu);
viewMenu->addAction(_splittedToggleAction);
viewMenu->addAction(_splitDirectionToggleAction);
viewMenu->addSeparator();
viewMenu->addAction(_cyclesToggleAction);
viewMenu->addAction(_percentageToggleAction);
viewMenu->addAction(_expandedToggleAction);
viewMenu->addAction(_hideTemplatesToggleAction);
viewMenu->addSeparator();
viewMenu->addAction(_splittedToggleAction);
viewMenu->addAction(_splitDirectionToggleAction);
viewMenu->addMenu(layoutMenu);
QMenu* goMenu = mBar->addMenu(tr("&Go"));
goMenu->addAction(_backAction);
......@@ -1291,60 +1327,66 @@ void QCGTopLevel::setData(TraceData* data)
updateStatusBar();
}
void QCGTopLevel::addEventTypeMenu(QMenu* popup, bool withCost2)
// Clears and repopulates the given menu with dynamic items for event types.
// Menu item handlers for setting the types are installed.
void QCGTopLevel::updateEventTypeMenu(QMenu* m, bool secondary)
{
if (_data) {
QMenu *popup1, *popup2 = 0;
QAction* action;
popup1 = popup->addMenu(tr("Primary Event Type"));
connect(popup1, SIGNAL(triggered(QAction*)),
this, SLOT(setEventType(QAction*)));
if (!m) return;
m->clear();
if (withCost2) {
popup2 = popup->addMenu(tr("Secondary Event Type"));
connect(popup2, SIGNAL(triggered(QAction*)),
this, SLOT(setEventType2(QAction*)));
if (_eventType2) {
action = popup2->addAction(tr("Hide"));
action->setData(199);
popup2->addSeparator();
}
if (!_data) {
// no data loaded yet
m->addAction(tr("(None)"));
return;
}
EventTypeSet* m = _data->eventTypes();
EventType* ct;
for (int i=0;i<m->realCount();i++) {
ct = m->realType(i);
if (secondary) {
connect(m, SIGNAL(triggered(QAction*)),
this, SLOT(setEventType2(QAction*)), Qt::UniqueConnection);
action = popup1->addAction(ct->longName());
action->setCheckable(true);
action->setData(100+i);
if (_eventType == ct) action->setChecked(true);
if (popup2) {
action = popup2->addAction(ct->longName());
action->setCheckable(true);
action->setData(100+i);
if (_eventType2 == ct) action->setChecked(true);
}
if (_eventType2 != 0) {
action = m->addAction(tr("Hide"));
action->setData(199);
m->addSeparator();
}
}
else {
connect(m, SIGNAL(triggered(QAction*)),
this, SLOT(setEventType(QAction*)), Qt::UniqueConnection);
}
for (int i=0;i<m->derivedCount();i++) {
ct = m->derivedType(i);
EventTypeSet* ets = _data->eventTypes();
EventType* et;
EventType* selected = secondary ? _eventType2 : _eventType;
for (int i = 0; i < ets->realCount(); i++) {
et = ets->realType(i);
action = popup1->addAction(ct->longName());
action = m->addAction(et->longName());
action->setCheckable(true);
action->setData(100+i);
if (et == selected) action->setChecked(true);
}
for (int i = 0; i < ets->derivedCount(); i++) {
et = ets->derivedType(i);
action = m->addAction(et->longName());
action->setCheckable(true);
action->setData(200+i);
if (_eventType == ct) action->setChecked(true);
if (et == selected) action->setChecked(true);
}
}
if (popup2) {
action = popup2->addAction(ct->longName());
action->setCheckable(true);
action->setData(200+i);
if (_eventType2 == ct) action->setChecked(true);
}
void QCGTopLevel::addEventTypeMenu(QMenu* popup, bool withCost2)
{
if (_data) {
QMenu* menu = popup->addMenu(tr("Primary Event Type"));
updateEventTypeMenu(menu, false);
if (withCost2) {
QMenu* menu = popup->addMenu(tr("Secondary Event Type"));
updateEventTypeMenu(menu, true);
}
}
......
......@@ -134,6 +134,9 @@ public slots:
void backTriggered(QAction*);
void upAboutToShow();
void upTriggered(QAction*);
void primaryAboutToShow();
void secondaryAboutToShow();
void groupingAboutToShow();
bool setEventType(EventType*);
bool setEventType2(EventType*);
......@@ -191,6 +194,7 @@ private:
void createMiscActions();
void setupMainWidget(MainWidget*);
void setupPartSelection(PartSelection*);
void updateEventTypeMenu(QMenu* m, bool secondary);
void restoreCurrentState(const QString& postfix);
void saveCurrentState(const QString& postfix);
void saveTraceSettings();
......@@ -219,6 +223,8 @@ private:
QAction *_sidebarMenuAction, *_recentFilesMenuAction;
QAction *_cyclesToggleAction, *_percentageToggleAction;
QAction *_expandedToggleAction, *_hideTemplatesToggleAction;
QAction *_primaryMenuAction, *_secondaryMenuAction;
QAction *_groupingMenuAction;
QAction *_splittedToggleAction, *_splitDirectionToggleAction;
QAction *_layoutNext, *_layoutPrev, *_layoutRemove, *_layoutDup;
QAction *_layoutRestore, *_layoutSave;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment