QmlProfiler: Reduce the amount of useless signals on item selection

By passing signals with identification information of varying accurary
between the different views the event being selected could be changed
while it was selected. By checking the current selection against the
information given in the signal and not reselecting when it matches the
situation is improved.

Also, the selection methods are given more appropriate names. We hardly
ever want to select the "next" event, but rather the "best fitting" one.

Task-number: QTCREATORBUG-11945
Change-Id: I659b4929cb88f4c931a0893aa95a3bc92da5a23b
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-04-03 11:15:56 +02:00
parent 38220ba4bb
commit 9e802e3af1
7 changed files with 34 additions and 25 deletions

View File

@@ -162,14 +162,12 @@ Rectangle {
rangeDetails.isBindingLoop = false; rangeDetails.isBindingLoop = false;
} }
function selectNextByHash(hash) { function selectById(eventId)
var eventId = qmlProfilerModelProxy.getEventIdForHash(hash);
if (eventId !== -1)
selectNextById(eventId);
}
function selectNextById(eventId)
{ {
if (eventId === -1 ||
eventId === qmlProfilerModelProxy.getEventId(view.selectedModel, view.selectedItem))
return;
// this is a slot responding to events from the other pane // this is a slot responding to events from the other pane
// which tracks only events from the basic model // which tracks only events from the basic model
if (!lockItemSelection) { if (!lockItemSelection) {

View File

@@ -699,13 +699,22 @@ void QmlProfilerEventsMainView::jumpToItem(const QModelIndex &index)
d->m_preventSelectBounce = false; d->m_preventSelectBounce = false;
} }
void QmlProfilerEventsMainView::selectItem(const QStandardItem *item)
{
// If the same item is already selected, don't reselect it.
QModelIndex index = d->m_model->indexFromItem(item);
if (index != currentIndex()) {
setCurrentIndex(index);
jumpToItem(index);
}
}
void QmlProfilerEventsMainView::selectEvent(const QString &eventHash) void QmlProfilerEventsMainView::selectEvent(const QString &eventHash)
{ {
for (int i=0; i<d->m_model->rowCount(); i++) { for (int i=0; i<d->m_model->rowCount(); i++) {
QStandardItem *infoItem = d->m_model->item(i, 0); QStandardItem *infoItem = d->m_model->item(i, 0);
if (infoItem->data(EventHashStrRole).toString() == eventHash) { if (infoItem->data(EventHashStrRole).toString() == eventHash) {
setCurrentIndex(d->m_model->indexFromItem(infoItem)); selectItem(infoItem);
jumpToItem(currentIndex());
return; return;
} }
} }
@@ -718,13 +727,11 @@ void QmlProfilerEventsMainView::selectEventByLocation(const QString &filename, i
for (int i=0; i<d->m_model->rowCount(); i++) { for (int i=0; i<d->m_model->rowCount(); i++) {
QStandardItem *infoItem = d->m_model->item(i, 0); QStandardItem *infoItem = d->m_model->item(i, 0);
if (currentIndex() != d->m_model->indexFromItem(infoItem) && if (infoItem->data(FilenameRole).toString() == filename &&
infoItem->data(FilenameRole).toString() == filename &&
infoItem->data(LineRole).toInt() == line && infoItem->data(LineRole).toInt() == line &&
(column == -1 || (column == -1 ||
infoItem->data(ColumnRole).toInt() == column)) { infoItem->data(ColumnRole).toInt() == column)) {
setCurrentIndex(d->m_model->indexFromItem(infoItem)); selectItem(infoItem);
jumpToItem(currentIndex());
return; return;
} }
} }

View File

@@ -143,6 +143,7 @@ private slots:
void profilerDataModelStateChanged(); void profilerDataModelStateChanged();
private: private:
void selectItem(const QStandardItem *item);
void setHeaderLabels(); void setHeaderLabels();
void parseModelProxy(); void parseModelProxy();

View File

@@ -371,24 +371,23 @@ void QmlProfilerTraceView::clear()
QMetaObject::invokeMethod(d->m_timebar->rootObject(), "clear"); QMetaObject::invokeMethod(d->m_timebar->rootObject(), "clear");
} }
void QmlProfilerTraceView::selectNextEventByHash(const QString &hash) void QmlProfilerTraceView::selectByHash(const QString &hash)
{ {
QQuickItem *rootObject = d->m_mainView->rootObject(); QQuickItem *rootObject = d->m_mainView->rootObject();
if (rootObject) if (rootObject)
QMetaObject::invokeMethod(rootObject, "selectNextByHash", QMetaObject::invokeMethod(rootObject, "selectById",
Q_ARG(QVariant,QVariant(hash))); Q_ARG(QVariant,QVariant(d->m_modelProxy->getEventIdForHash(hash))));
} }
void QmlProfilerTraceView::selectNextEventByLocation(const QString &filename, const int line, const int column) void QmlProfilerTraceView::selectBySourceLocation(const QString &filename, int line, int column)
{ {
int eventId = d->m_modelProxy->getEventIdForLocation(filename, line, column); int eventId = d->m_modelProxy->getEventIdForLocation(filename, line, column);
if (eventId != -1) { if (eventId != -1) {
QQuickItem *rootObject = d->m_mainView->rootObject(); QQuickItem *rootObject = d->m_mainView->rootObject();
if (rootObject) if (rootObject)
QMetaObject::invokeMethod(rootObject, "selectNextById", QMetaObject::invokeMethod(rootObject, "selectById", Q_ARG(QVariant,QVariant(eventId)));
Q_ARG(QVariant,QVariant(eventId)));
} }
} }

View File

@@ -100,8 +100,8 @@ public:
public slots: public slots:
void clear(); void clear();
void selectNextEventByHash(const QString &eventHash); void selectByHash(const QString &eventHash);
void selectNextEventByLocation(const QString &filename, const int line, const int column); void selectBySourceLocation(const QString &filename, int line, int column);
private slots: private slots:
void updateCursorPosition(); void updateCursorPosition();

View File

@@ -105,8 +105,8 @@ void QmlProfilerViewManager::createViews()
d->profilerModelManager); d->profilerModelManager);
connect(d->eventsView, SIGNAL(gotoSourceLocation(QString,int,int)), this, connect(d->eventsView, SIGNAL(gotoSourceLocation(QString,int,int)), this,
SIGNAL(gotoSourceLocation(QString,int,int))); SIGNAL(gotoSourceLocation(QString,int,int)));
connect(d->eventsView, SIGNAL(eventSelectedByHash(QString)), d->traceView, connect(d->eventsView, SIGNAL(eventSelectedByHash(QString)),
SLOT(selectNextEventByHash(QString))); d->traceView, SLOT(selectByHash(QString)));
connect(d->traceView, SIGNAL(gotoSourceLocation(QString,int,int)), connect(d->traceView, SIGNAL(gotoSourceLocation(QString,int,int)),
d->eventsView, SLOT(selectBySourceLocation(QString,int,int))); d->eventsView, SLOT(selectBySourceLocation(QString,int,int)));
@@ -117,7 +117,7 @@ void QmlProfilerViewManager::createViews()
connect(d->traceView, SIGNAL(gotoSourceLocation(QString,int,int)), connect(d->traceView, SIGNAL(gotoSourceLocation(QString,int,int)),
d->v8profilerView, SLOT(selectBySourceLocation(QString,int,int))); d->v8profilerView, SLOT(selectBySourceLocation(QString,int,int)));
connect(d->v8profilerView, SIGNAL(gotoSourceLocation(QString,int,int)), connect(d->v8profilerView, SIGNAL(gotoSourceLocation(QString,int,int)),
d->traceView, SLOT(selectNextEventByLocation(QString,int,int))); d->traceView, SLOT(selectBySourceLocation(QString,int,int)));
connect(d->v8profilerView, SIGNAL(gotoSourceLocation(QString,int,int)), connect(d->v8profilerView, SIGNAL(gotoSourceLocation(QString,int,int)),
d->eventsView, SLOT(selectBySourceLocation(QString,int,int))); d->eventsView, SLOT(selectBySourceLocation(QString,int,int)));
connect(d->eventsView, SIGNAL(gotoSourceLocation(QString,int,int)), connect(d->eventsView, SIGNAL(gotoSourceLocation(QString,int,int)),

View File

@@ -309,11 +309,15 @@ void TimelineRenderer::manageClicked()
setSelectionLocked(!m_selectionLocked); setSelectionLocked(!m_selectionLocked);
else else
setSelectionLocked(true); setSelectionLocked(true);
// itemPressed() will trigger an update of the events and JavaScript views. Make sure the
// correct event is already selected when that happens, to prevent confusion.
selectFromId(m_currentSelection.modelIndex, m_currentSelection.eventIndex);
emit itemPressed(m_currentSelection.modelIndex, m_currentSelection.eventIndex); emit itemPressed(m_currentSelection.modelIndex, m_currentSelection.eventIndex);
} else { } else {
setSelectionLocked(false); setSelectionLocked(false);
selectFromId(m_currentSelection.modelIndex, m_currentSelection.eventIndex);
} }
selectFromId(m_currentSelection.modelIndex, m_currentSelection.eventIndex);
} }
void TimelineRenderer::manageHovered(int mouseX, int mouseY) void TimelineRenderer::manageHovered(int mouseX, int mouseY)