Commit 37161a41 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlProfiler: next and previous buttons have now consistent behaviour



Having them behave differently depending on the locked mode was
confusing.  This patch moves that functionality to the event labels,
thus next and prev just select next and previous events in the
timeline, in strict chronological order.

Change-Id: I5bd996199dd6a4af4c65e3205493f17495d0135b
Reviewed-by: default avatarAurindam Jana <aurindam.jana@nokia.com>
parent 02bbf4ff
......@@ -1200,6 +1200,12 @@ QString QmlProfilerEventList::eventTextForType(int type, int index) const {
return d->m_eventDescriptions.values().at(d->m_typeCounts[type]->eventIds[index])->details;
}
int QmlProfilerEventList::eventIdForType(int type, int index) const {
if (!d->m_typeCounts.contains(type))
return -1;
return d->m_typeCounts[type]->eventIds[index];
}
int QmlProfilerEventList::eventPosInType(int index) const {
int eventType = d->m_startTimeSortedList[index].description->eventType;
return d->m_typeCounts[eventType]->eventIds.indexOf(d->m_startTimeSortedList[index].description->eventId);
......
......@@ -118,6 +118,7 @@ public:
Q_INVOKABLE int uniqueEventsOfType(int type) const;
Q_INVOKABLE int maxNestingForType(int type) const;
Q_INVOKABLE QString eventTextForType(int type, int index) const;
Q_INVOKABLE int eventIdForType(int type, int index) const;
Q_INVOKABLE int eventPosInType(int index) const;
Q_INVOKABLE qint64 traceStartTime() const;
......
......@@ -39,6 +39,7 @@ Item {
property int typeIndex: index
property variant descriptions: []
property variant eventIds: []
height: root.singleRowHeight
width: 150
......@@ -48,7 +49,7 @@ Item {
rE[typeIndex] = expanded;
labels.rowExpanded = rE;
backgroundMarks.requestRedraw();
view.rowExpanded(typeIndex, expanded);
view.setRowExpanded(typeIndex, expanded);
updateHeight();
}
......@@ -65,13 +66,18 @@ Item {
target: qmlEventList
onDataReady: {
var desc=[];
for (var i=0; i<qmlEventList.uniqueEventsOfType(typeIndex); i++)
var ids=[];
for (var i=0; i<qmlEventList.uniqueEventsOfType(typeIndex); i++) {
desc[i] = qmlEventList.eventTextForType(typeIndex, i);
ids[i] = qmlEventList.eventIdForType(typeIndex, i);
}
descriptions = desc;
eventIds = ids;
updateHeight();
}
onDataClear: {
descriptions = [];
eventIds = [];
updateHeight();
}
}
......@@ -113,6 +119,15 @@ Item {
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
if (mouse.modifiers & Qt.ShiftModifier)
view.selectPrevFromId(eventIds[index]);
else
view.selectNextFromId(eventIds[index]);
}
}
}
}
}
......
......@@ -164,15 +164,13 @@ void TimelineView::drawSelectionBoxes(QPainter *p)
p->setPen(lightPen);
int x, y, width, eventType;
p->setPen(lightPen);
QRect selectedItemRect(0,0,0,0);
for (int i = fromIndex; i <= toIndex; i++) {
if (m_eventList->getEventId(i) != id)
continue;
if (i == m_selectedItem)
p->setPen(strongPen);
else
p->setPen(lightPen);
x = (m_eventList->getStartTime(i) - m_startTime) * m_spacing;
eventType = m_eventList->getType(i);
if (m_rowsExpanded[eventType])
......@@ -184,7 +182,16 @@ void TimelineView::drawSelectionBoxes(QPainter *p)
if (width<1)
width = 1;
p->drawRect(x,y,width,DefaultRowHeight);
if (i == m_selectedItem)
selectedItemRect = QRect(x,y,width,DefaultRowHeight);
else
p->drawRect(x,y,width,DefaultRowHeight);
}
// draw the selected item rectangle the last, so that it's overlayed
if (selectedItemRect.width() != 0) {
p->setPen(strongPen);
p->drawRect(selectedItemRect);
}
}
......@@ -319,6 +326,40 @@ QString TimelineView::getDetails(int index) const
return m_eventList->getDetails(index);
}
void TimelineView::setRowExpanded(int rowIndex, bool expanded)
{
m_rowsExpanded[rowIndex] = expanded;
update();
}
void TimelineView::selectNext()
{
if (m_eventList->count() == 0)
return;
// select next in view or after
int newIndex = m_selectedItem+1;
if (newIndex >= m_eventList->count())
newIndex = 0;
if (m_eventList->getEndTime(newIndex) < m_startTime)
newIndex = m_eventList->findFirstIndexNoParents(m_startTime);
setSelectedItem(newIndex);
}
void TimelineView::selectPrev()
{
if (m_eventList->count() == 0)
return;
// select last in view or before
int newIndex = m_selectedItem-1;
if (newIndex < 0)
newIndex = m_eventList->count()-1;
if (m_eventList->getStartTime(newIndex) > m_endTime)
newIndex = m_eventList->findLastIndex(m_endTime);
setSelectedItem(newIndex);
}
int TimelineView::nextItemFromId(int eventId) const
{
int ndx = -1;
......@@ -337,64 +378,35 @@ int TimelineView::nextItemFromId(int eventId) const
return -1;
}
void TimelineView::rowExpanded(int rowIndex, bool expanded)
int TimelineView::prevItemFromId(int eventId) const
{
m_rowsExpanded[rowIndex] = expanded;
update();
int ndx = -1;
if (m_selectedItem == -1)
ndx = m_eventList->findFirstIndexNoParents(m_startTime);
else
ndx = m_selectedItem - 1;
if (ndx < 0)
ndx = m_eventList->count() - 1;
int startIndex = ndx;
do {
if (m_eventList->getEventId(ndx) == eventId)
return ndx;
if (--ndx < 0)
ndx = m_eventList->count()-1;
} while (ndx != startIndex);
return -1;
}
void TimelineView::selectNext()
void TimelineView::selectNextFromId(int eventId)
{
if (m_eventList->count() == 0)
return;
if (m_selectionLocked && m_selectedItem !=-1 ) {
// find next item with same eventId
int eventId = m_eventList->getEventId(m_selectedItem);
int i = m_selectedItem + 1;
while (i<m_eventList->count() && m_eventList->getEventId(i) != eventId)
i++;
if (i == m_eventList->count()) {
i = 0;
while (i<m_selectedItem && m_eventList->getEventId(i) != eventId)
i++;
}
setSelectedItem(i);
} else {
// select next in view or after
int newIndex = m_selectedItem + 1;
if (newIndex >= m_eventList->count())
newIndex = 0;
if (m_eventList->getEndTime(newIndex) < m_startTime)
newIndex = m_eventList->findFirstIndexNoParents(m_startTime);
setSelectedItem(newIndex);
}
int eventIndex = nextItemFromId(eventId);
if (eventIndex != -1)
setSelectedItem(eventIndex);
}
void TimelineView::selectPrev()
void TimelineView::selectPrevFromId(int eventId)
{
if (m_eventList->count() == 0)
return;
if (m_selectionLocked && m_selectedItem !=-1) {
// find previous item with same eventId
int eventId = m_eventList->getEventId(m_selectedItem);
int i = m_selectedItem-1;
while (i>-1 && m_eventList->getEventId(i) != eventId)
i--;
if (i == -1) {
i = m_eventList->count()-1;
while (i>m_selectedItem && m_eventList->getEventId(i) != eventId)
i--;
}
setSelectedItem(i);
} else {
// select last in view or before
int newIndex = m_selectedItem-1;
if (newIndex < 0)
newIndex = m_eventList->count()-1;
if (m_eventList->getStartTime(newIndex) > m_endTime)
newIndex = m_eventList->findLastIndex(m_endTime);
setSelectedItem(newIndex);
}
int eventIndex = prevItemFromId(eventId);
if (eventIndex != -1)
setSelectedItem(eventIndex);
}
......@@ -91,17 +91,19 @@ public:
emit eventListChanged(m_eventList);
}
Q_INVOKABLE void selectNext();
Q_INVOKABLE void selectPrev();
Q_INVOKABLE void rowExpanded(int rowIndex, bool expanded);
Q_INVOKABLE qint64 getDuration(int index) const;
Q_INVOKABLE QString getFilename(int index) const;
Q_INVOKABLE int getLine(int index) const;
Q_INVOKABLE QString getDetails(int index) const;
Q_INVOKABLE void setRowExpanded(int rowIndex, bool expanded);
Q_INVOKABLE void selectNext();
Q_INVOKABLE void selectPrev();
Q_INVOKABLE int nextItemFromId(int eventId) const;
Q_INVOKABLE int prevItemFromId(int eventId) const;
Q_INVOKABLE void selectNextFromId(int eventId);
Q_INVOKABLE void selectPrevFromId(int eventId);
signals:
void startTimeChanged(qint64 arg);
......
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