Skip to content

Commit

Permalink
Allow instructions/source lines to be activated
Browse files Browse the repository at this point in the history
The selection mechanism after activation was buggy.
Now we just reset the selection after activation, and
every view may decide on its own about a useful selection
on updating its contents.

The term "activation" is used in KCachegrind when e.g. a new
function is shown in all visualization views; a "selection" is
just a selected item within a visualization.
  • Loading branch information
weidendo committed Jul 23, 2014
1 parent 9be3466 commit d1d1041
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 90 deletions.
36 changes: 16 additions & 20 deletions libviews/instrview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,28 +338,19 @@ void InstrView::keyPressEvent(QKeyEvent* event)
CostItem* InstrView::canShow(CostItem* i)
{
ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;
TraceFunction* f = 0;

switch(t) {
case ProfileContext::Function:
f = (TraceFunction*) i;
break;
switch(t) {
case ProfileContext::Function:
case ProfileContext::Instr:
case ProfileContext::InstrJump:
case ProfileContext::Line:
return i;

case ProfileContext::Instr:
f = ((TraceInstr*)i)->function();
select(i);
break;

case ProfileContext::Line:
f = ((TraceLine*)i)->functionSource()->function();
select(i);
break;

default:
break;
}
default:
break;
}

return f;
return 0;
}


Expand All @@ -382,12 +373,17 @@ void InstrView::doUpdate(int changeType, bool)
(ii->instrCall()->call()->called() == _selectedItem)) return;
}

TraceInstrJump* ij = 0;
if (_selectedItem->type() == ProfileContext::InstrJump)
ij = (TraceInstrJump*) _selectedItem;

QTreeWidgetItem *item, *item2;
for (int i=0; i<topLevelItemCount(); i++) {
item = topLevelItem(i);
ii = (InstrItem*)item;
if ((ii->instr() == _selectedItem) ||
(ii->instr() && (ii->instr()->line() == _selectedItem))) {
(ii->instr() && (ii->instr()->line() == _selectedItem)) ||
(ij && (ij->instrTo() == ii->instr())) ) {
scrollToItem(item);
_inSelectionUpdate = true;
setCurrentItem(item);
Expand Down
34 changes: 13 additions & 21 deletions libviews/sourceview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,29 +208,19 @@ void SourceView::keyPressEvent(QKeyEvent* event)

CostItem* SourceView::canShow(CostItem* i)
{
ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;
TraceFunction* f = 0;

switch(t) {
case ProfileContext::Function:
f = (TraceFunction*) i;
break;

case ProfileContext::Instr:
f = ((TraceInstr*)i)->function();
select(i);
break;
ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;

case ProfileContext::Line:
f = ((TraceLine*)i)->functionSource()->function();
select(i);
break;
switch(t) {
case ProfileContext::Function:
case ProfileContext::Instr:
case ProfileContext::Line:
return i;

default:
break;
}
default:
break;
}

return f;
return 0;
}

void SourceView::doUpdate(int changeType, bool)
Expand Down Expand Up @@ -333,7 +323,8 @@ void SourceView::refresh()
if (t == ProfileContext::Function) f = (TraceFunction*) _activeItem;
if (t == ProfileContext::Instr) {
f = ((TraceInstr*)_activeItem)->function();
if (!_selectedItem) _selectedItem = _activeItem;
if (!_selectedItem)
_selectedItem = ((TraceInstr*)_activeItem)->line();
}
if (t == ProfileContext::Line) {
f = ((TraceLine*)_activeItem)->functionSource()->function();
Expand Down Expand Up @@ -372,6 +363,7 @@ void SourceView::refresh()
}
// reset to the original position - this is useful when the view
// is refreshed just because we change between relative/absolute
// FIXME: this overrides scrolling to selected item
verticalScrollBar()->setValue(originalPosition);
}

Expand Down
90 changes: 50 additions & 40 deletions libviews/traceitemview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "traceitemview.h"

#include <QtGlobal>
#include <QWidget>

#include "toplevelbase.h"
Expand Down Expand Up @@ -109,13 +110,14 @@ void TraceItemView::restoreOptions(const QString&, const QString&)

bool TraceItemView::activate(CostItem* i)
{
i = canShow(i);
if (_activeItem == i) return (i != 0);

_newActiveItem = i;
updateView();
_newActiveItem = canShow(i);
if (_activeItem != _newActiveItem) {
// new item activated, start with empty selection
_newSelectedItem = 0;
updateView();
}

return (i != 0);
return (_newActiveItem != 0);
}

TraceFunction* TraceItemView::activeFunction()
Expand Down Expand Up @@ -146,8 +148,10 @@ bool TraceItemView::set(int changeType, TraceData* d,
_newPartList = l;
_newSelectedItem = s;
_newActiveItem = canShow(a);
if (!_newActiveItem)
if (_activeItem != _newActiveItem) {
// new item activated, start with empty selection
_newSelectedItem = 0;
}
updateView();

return (_newActiveItem != 0);
Expand Down Expand Up @@ -273,35 +277,37 @@ void TraceItemView::triggerUpdate(bool force)
if (!force && (_status == nothingChanged)) return;

#if TRACE_UPDATES
qDebug() << (widget() ? widget()->name() : "TraceItemView")
<< "::doUpdate ( "
<< ((_status & dataChanged) ? "data ":"")
<< ((_status & configChanged) ? "config ":"")
<< ")";
qDebug("%s::doUpate",
widget() ? qPrintable(widget()->objectName()) : "TraceItemView");

if (_status & dataChanged)
qDebug(" data changed");

if (_status & configChanged)
qDebug(" config changed");

if (_status & partsChanged)
qDebug() << " Part List "
<< _partList.names();
qDebug(" parts changed: %s", qPrintable(_partList[0]->name()) );

if (_status & eventTypeChanged)
qDebug() << " Cost type "
<< (_eventType ? qPrintable( _eventType->name() ) : "?");
qDebug(" event type 1 changed: %s",
_eventType ? qPrintable( _eventType->name() ) : "(None)");

if (_status & eventType2Changed)
qDebug() << " Cost type 2 "
<< (_eventType2 ? qPrintable( _eventType2->name() ) : "?");
qDebug(" event type 2 changed: %s",
_eventType2 ? qPrintable( _eventType2->name() ) : "(None)");

if (_status & groupTypeChanged)
qDebug() << " Group type "
<< ProfileContext::typeName(_groupType);
qDebug(" group type changed: %s",
qPrintable(ProfileContext::typeName(_groupType)));

if (_status & activeItemChanged)
qDebug() << " Active: "
<< (_activeItem ? qPrintable( _activeItem->fullName() ) : "?");
qDebug(" active item changed: %s",
_activeItem ? qPrintable( _activeItem->fullName() ) : "(none)");

if (_status & selectedItemChanged)
qDebug() << " Selected: "
<< (_selectedItem ? qPrintable( _selectedItem->fullName() ) : "?");
qDebug(" selected item changed: %s",
_selectedItem ? qPrintable( _selectedItem->fullName() ) : "(none)");
#endif

int st = _status;
Expand All @@ -312,20 +318,19 @@ void TraceItemView::triggerUpdate(bool force)

void TraceItemView::selected(TraceItemView* /*sender*/, CostItem* i)
{
#if TRACE_UPDATES
qDebug() << (widget() ? widget()->name() : "TraceItemView")
<< "::selected "
<< (i ? qPrintable( i->name() ): "(nil)")
<< ", sender "
<< sender->widget()->name() << endl;
#if 0 // TRACE_UPDATES
qDebug("%s::selected( item %s, sender %s )",
widget() ? qPrintable(widget()->objectName()) : "TraceItemView",
i ? qPrintable( i->name() ): "(none)",
qPrintable(sender->widget()->objectName()) );
#endif

if (_parentView) _parentView->selected(this, i);
}

void TraceItemView::partsSelected(TraceItemView* /*sender*/, const TracePartList& l)
{
#if TRACE_UPDATES
#if 0 // TRACE_UPDATES
qDebug() << (widget() ? widget()->name() : "TraceItemView")
<< "::selected "
<< l.names()
Expand All @@ -341,12 +346,11 @@ void TraceItemView::partsSelected(TraceItemView* /*sender*/, const TracePartList

void TraceItemView::activated(TraceItemView* /*sender*/, CostItem* i)
{
#if TRACE_UPDATES
qDebug() << (widget() ? widget()->name() : "TraceItemView")
<< "::activated "
<< (i ? qPrintable( i->name() ) : "(nil)")
<< ", sender "
<< sender->widget()->name();
#if 0 // TRACE_UPDATES
qDebug("%s::activated( item %s, sender %s )",
widget() ? qPrintable(widget()->objectName()) : "TraceItemView",
i ? qPrintable( i->name() ): "(none)",
qPrintable(sender->widget()->objectName()) );
#endif

if (_parentView)
Expand Down Expand Up @@ -394,6 +398,12 @@ void TraceItemView::doUpdate(int, bool)

void TraceItemView::selected(CostItem* i)
{
#if TRACE_UPDATES
qDebug("%s::selected( item %s )",
widget() ? qPrintable(widget()->objectName()) : "TraceItemView",
i ? qPrintable( i->name() ): "(none)" );
#endif

if (_parentView)
_parentView->selected(this, i);

Expand All @@ -410,9 +420,9 @@ void TraceItemView::partsSelected(const TracePartList& l)
void TraceItemView::activated(CostItem* i)
{
#if TRACE_UPDATES
qDebug() << (widget() ? widget()->name() : "TraceItemView")
<< "::activated "
<< (i ? qPrintable( i->name() ): "(nil)");
qDebug("%s::activated( item %s )",
widget() ? qPrintable(widget()->objectName()) : "TraceItemView",
i ? qPrintable( i->name() ): "(none)" );
#endif

if (_parentView)
Expand Down
12 changes: 6 additions & 6 deletions libviews/traceitemview.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class TraceItemView
* - <dataChanged> is used if e.g. cycles are recalculated
*/
enum { nothingChanged = 0,
eventTypeChanged = 1,
eventType2Changed = 2,
eventTypeChanged = 1,
eventType2Changed = 2,
groupTypeChanged = 4,
partsChanged = 8,
activeItemChanged = 16,
Expand Down Expand Up @@ -171,11 +171,11 @@ class TraceItemView
virtual QWidget* widget() = 0;

/**
* This function is called when a new item should become active.
* Reimplement this in subclasses.
* Called when a new item is about to become active.
* Itemviews should reimplement this to notify that a
* given item cannot be shown (return 0) or should be
* redirected to another item to be shown as active.
*
* Returns the real item to become active. You can call select() here.
* Return 0 if nothing can be shown.
* Use the methods like data() instead of _data here, as
* _data possibly will give old/wrong information.
*/
Expand Down
3 changes: 0 additions & 3 deletions qcachegrind/qcgtoplevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,14 +1201,11 @@ void QCGTopLevel::setTraceItemDelayed()
_multiView->activate(_traceItemDelayed);
break;

#if 0
// this conflicts with the selection policy of InstrView ?!?
case ProfileContext::Instr:
case ProfileContext::Line:
// only for multiview
_multiView->activate(_traceItemDelayed);
break;
#endif

default: break;
}
Expand Down

0 comments on commit d1d1041

Please sign in to comment.