QmlProfiler: Only emit gotoSourceLocation on internal updates

If we're merely synchronizing to another view the source location has
already been taken care of.

Change-Id: I272c1f3a664271327d3a59d851632eb1241108a0
Task-number: QTCREATORBUG-13360
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2015-11-11 11:46:21 +01:00
parent b604e91f5b
commit 1b8c1af2c6
2 changed files with 38 additions and 20 deletions

View File

@@ -51,6 +51,7 @@
#include <QMenu> #include <QMenu>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <functional>
using namespace QmlDebug; using namespace QmlDebug;
@@ -179,6 +180,16 @@ static QString displayHeader(Fields header)
} }
} }
static void getSourceLocation(QStandardItem *infoItem,
std::function<void (const QString &, int, int)> receiver)
{
int line = infoItem->data(LineRole).toInt();
int column = infoItem->data(ColumnRole).toInt();
QString fileName = infoItem->data(FilenameRole).toString();
if (line != -1 && !fileName.isEmpty())
receiver(fileName, line, column);
}
QmlProfilerEventsWidget::QmlProfilerEventsWidget(QWidget *parent, QmlProfilerEventsWidget::QmlProfilerEventsWidget(QWidget *parent,
QmlProfilerTool *profilerTool, QmlProfilerTool *profilerTool,
QmlProfilerViewManager *container, QmlProfilerViewManager *container,
@@ -210,6 +221,10 @@ QmlProfilerEventsWidget::QmlProfilerEventsWidget(QWidget *parent,
d->m_eventTree, &QmlProfilerEventsMainView::selectType); d->m_eventTree, &QmlProfilerEventsMainView::selectType);
connect(d->m_eventParents, &QmlProfilerEventRelativesView::typeClicked, connect(d->m_eventParents, &QmlProfilerEventRelativesView::typeClicked,
d->m_eventTree, &QmlProfilerEventsMainView::selectType); d->m_eventTree, &QmlProfilerEventsMainView::selectType);
connect(d->m_eventChildren, &QmlProfilerEventRelativesView::gotoSourceLocation,
this, &QmlProfilerEventsWidget::gotoSourceLocation);
connect(d->m_eventParents, &QmlProfilerEventRelativesView::gotoSourceLocation,
this, &QmlProfilerEventsWidget::gotoSourceLocation);
// widget arrangement // widget arrangement
QVBoxLayout *groupLayout = new QVBoxLayout; QVBoxLayout *groupLayout = new QVBoxLayout;
@@ -389,7 +404,6 @@ public:
QHash<int, int> m_columnIndex; // maps field enum to column index QHash<int, int> m_columnIndex; // maps field enum to column index
bool m_showExtendedStatistics; bool m_showExtendedStatistics;
int m_firstNumericColumn; int m_firstNumericColumn;
bool m_preventSelectBounce;
}; };
QmlProfilerEventsMainView::QmlProfilerEventsMainView(QWidget *parent, QmlProfilerEventsMainView::QmlProfilerEventsMainView(QWidget *parent,
@@ -412,7 +426,6 @@ QmlProfilerEventsMainView::QmlProfilerEventsMainView(QWidget *parent,
connect(d->modelProxy, &QmlProfilerEventsModelProxy::notesAvailable, connect(d->modelProxy, &QmlProfilerEventsModelProxy::notesAvailable,
this, &QmlProfilerEventsMainView::updateNotes); this, &QmlProfilerEventsMainView::updateNotes);
d->m_firstNumericColumn = 0; d->m_firstNumericColumn = 0;
d->m_preventSelectBounce = false;
d->m_showExtendedStatistics = false; d->m_showExtendedStatistics = false;
setFieldViewable(Name, true); setFieldViewable(Name, true);
@@ -700,6 +713,16 @@ void QmlProfilerEventsMainView::parseModelProxy()
} }
} }
QStandardItem *QmlProfilerEventsMainView::itemFromIndex(const QModelIndex &index) const
{
QStandardItem *indexItem = d->m_model->itemFromIndex(index);
if (indexItem->parent())
return indexItem->parent()->child(indexItem->row(), 0);
else
return d->m_model->item(index.row(), 0);
}
QString QmlProfilerEventsMainView::nameForType(RangeType typeNumber) QString QmlProfilerEventsMainView::nameForType(RangeType typeNumber)
{ {
switch (typeNumber) { switch (typeNumber) {
@@ -727,31 +750,17 @@ int QmlProfilerEventsMainView::selectedTypeId() const
return item->data(TypeIdRole).toInt(); return item->data(TypeIdRole).toInt();
} }
void QmlProfilerEventsMainView::jumpToItem(const QModelIndex &index) void QmlProfilerEventsMainView::jumpToItem(const QModelIndex &index)
{ {
if (d->m_preventSelectBounce) QStandardItem *infoItem = itemFromIndex(index);
return;
d->m_preventSelectBounce = true;
QStandardItem *clickedItem = d->m_model->itemFromIndex(index);
QStandardItem *infoItem;
if (clickedItem->parent())
infoItem = clickedItem->parent()->child(clickedItem->row(), 0);
else
infoItem = d->m_model->item(index.row(), 0);
// show in editor // show in editor
int line = infoItem->data(LineRole).toInt(); getSourceLocation(infoItem, [this](const QString &fileName, int line, int column) {
int column = infoItem->data(ColumnRole).toInt();
QString fileName = infoItem->data(FilenameRole).toString();
if (line!=-1 && !fileName.isEmpty())
emit gotoSourceLocation(fileName, line, column); emit gotoSourceLocation(fileName, line, column);
});
// show in callers/callees subwindow // show in callers/callees subwindow
emit typeSelected(infoItem->data(TypeIdRole).toInt()); emit typeSelected(infoItem->data(TypeIdRole).toInt());
d->m_preventSelectBounce = false;
} }
void QmlProfilerEventsMainView::selectItem(const QStandardItem *item) void QmlProfilerEventsMainView::selectItem(const QStandardItem *item)
@@ -760,7 +769,9 @@ void QmlProfilerEventsMainView::selectItem(const QStandardItem *item)
QModelIndex index = d->m_model->indexFromItem(item); QModelIndex index = d->m_model->indexFromItem(item);
if (index != currentIndex()) { if (index != currentIndex()) {
setCurrentIndex(index); setCurrentIndex(index);
jumpToItem(index);
// show in callers/callees subwindow
emit typeSelected(itemFromIndex(index)->data(TypeIdRole).toInt());
} }
} }
@@ -987,6 +998,11 @@ void QmlProfilerEventRelativesView::jumpToItem(const QModelIndex &index)
{ {
if (treeModel()) { if (treeModel()) {
QStandardItem *infoItem = treeModel()->item(index.row(), 0); QStandardItem *infoItem = treeModel()->item(index.row(), 0);
// show in editor
getSourceLocation(infoItem, [this](const QString &fileName, int line, int column) {
emit gotoSourceLocation(fileName, line, column);
});
emit typeClicked(infoItem->data(TypeIdRole).toInt()); emit typeClicked(infoItem->data(TypeIdRole).toInt());
} }
} }

View File

@@ -156,6 +156,7 @@ private:
void selectItem(const QStandardItem *item); void selectItem(const QStandardItem *item);
void setHeaderLabels(); void setHeaderLabels();
void parseModelProxy(); void parseModelProxy();
QStandardItem *itemFromIndex(const QModelIndex &index) const;
private: private:
class QmlProfilerEventsMainViewPrivate; class QmlProfilerEventsMainViewPrivate;
@@ -173,6 +174,7 @@ public:
signals: signals:
void typeClicked(int typeIndex); void typeClicked(int typeIndex);
void gotoSourceLocation(const QString &fileName, int lineNumber, int columnNumber);
public slots: public slots:
void displayType(int typeIndex); void displayType(int typeIndex);