Commit d1d1041e authored by Josef Weidendorfer's avatar Josef Weidendorfer
Browse files

Allow instructions/source lines to be activated

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.
parent 9be34668
......@@ -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;
}
......@@ -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);
......
......@@ -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)
......@@ -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();
......@@ -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);
}
......
......@@ -22,6 +22,7 @@
#include "traceitemview.h"
#include <QtGlobal>
#include <QWidget>
#include "toplevelbase.h"
......@@ -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()
......@@ -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);
......@@ -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;
......@@ -312,12 +318,11 @@ 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);
......@@ -325,7 +330,7 @@ void TraceItemView::selected(TraceItemView* /*sender*/, CostItem* i)
void TraceItemView::partsSelected(TraceItemView* /*sender*/, const TracePartList& l)
{
#if TRACE_UPDATES
#if 0 // TRACE_UPDATES
qDebug() << (widget() ? widget()->name() : "TraceItemView")
<< "::selected "
<< l.names()
......@@ -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)
......@@ -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);
......@@ -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)
......
......@@ -78,8 +78,8 @@ public:
* - <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,
......@@ -171,11 +171,11 @@ public:
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.
*/
......
......@@ -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;
}
......
Markdown is supported
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