From: Peter Lohrmann Date: Wed, 4 Feb 2015 03:05:45 +0000 (-0800) Subject: glvdebug: Timeline now supports tooltips. X-Git-Tag: sdk-0.1.0~630 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b7abf1df77b4fba31d4f518f1ae550dc2c8f4c2;p=platform%2Fupstream%2FVulkan-LoaderAndValidationLayers.git glvdebug: Timeline now supports tooltips. * Hovering the mouse cursor over a timeline item now displays a tool tip that shows the call index, and entrypoint name & parameters. * Currently the tooltip has a black background and looks like a window that failed to render, but as far as I can tell that is the default support for tooltips. We can probably spice it up a bit in the future. * This change also implements several virtual methods of QAbstractItemView; I'm not convinced that they all work properly, but I'm sure additional testing and usage will help solidify things. --- diff --git a/tools/glave/src/glvdebug/glvdebug_qtimelineview.cpp b/tools/glave/src/glvdebug/glvdebug_qtimelineview.cpp index 0b6c08b..00e4712 100755 --- a/tools/glave/src/glvdebug/glvdebug_qtimelineview.cpp +++ b/tools/glave/src/glvdebug/glvdebug_qtimelineview.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "glvdebug_qtimelineview.h" #include "glvdebug_QTraceFileModel.h" @@ -167,10 +168,74 @@ void glvdebug_QTimelineView::setModel(QAbstractItemModel* pModel) } } +QRectF glvdebug_QTimelineView::itemRect(const QModelIndex &item) const +{ + QRectF rect; + if (!item.isValid()) + { + return rect; + } + + glv_trace_packet_header* pHeader = (glv_trace_packet_header*)item.internalPointer(); + + // make sure item is valid size + if (pHeader->entrypoint_end_time <= pHeader->entrypoint_begin_time) + { + return rect; + } + + int threadIndex = m_threadIdList.indexOf(pHeader->thread_id); + int topOffset = (m_threadHeight * threadIndex) + (m_threadHeight * 0.5); + + uint64_t duration = pHeader->entrypoint_end_time - pHeader->entrypoint_begin_time; + + float leftOffset = scalePositionHorizontally(pHeader->entrypoint_begin_time); + float scaledWidth = scaleDurationHorizontally(duration); + + // Clamp the item so that it is 1 pixel wide. + // This is intentionally being done before updating the minimum offset + // so that small items after the current item will not be drawn + if (scaledWidth < 1) + { + scaledWidth = 2; + } + + // draw the colored box that represents this item + int itemHeight = m_threadHeight/2; + + rect.setLeft(leftOffset); + rect.setTop(topOffset - (itemHeight/2)); + rect.setWidth(scaledWidth); + rect.setHeight(itemHeight); + + return rect; +} + +bool glvdebug_QTimelineView::event(QEvent * e) +{ + if (e->type() == QEvent::ToolTip) + { + QHelpEvent* pHelp = static_cast(e); + QModelIndex index = indexAt(pHelp->pos()); + if (index.isValid()) + { + glv_trace_packet_header* pHeader = (glv_trace_packet_header*)index.internalPointer(); + QToolTip::showText(pHelp->globalPos(), QString("Call %1:\n%2").arg(pHeader->global_packet_index).arg(index.data().toString())); + return true; + } + else + { + QToolTip::hideText(); + } + } + + return QAbstractItemView::event(e); +} QRect glvdebug_QTimelineView::visualRect(const QModelIndex &index) const { - return QRect(); + QRectF rectf = itemRect(index); + return rectf.toRect(); } void glvdebug_QTimelineView::scrollTo(const QModelIndex &index, ScrollHint hint/* = EnsureVisible*/) @@ -182,28 +247,32 @@ QModelIndex glvdebug_QTimelineView::indexAt(const QPoint &point) const if (model() == NULL) return QModelIndex(); -// // Transform the view coordinates into contents widget coordinates. -// int wx = point.x() + horizontalScrollBar()->value(); -// int wy = point.y() + verticalScrollBar()->value(); - - return model()->index(0, 0); -} + // Transform the view coordinates into contents widget coordinates. + int wx = point.x() + horizontalScrollBar()->value(); + int wy = point.y() + verticalScrollBar()->value(); -//QRect glvdebug_QTimelineView::itemRect(const QModelIndex &item) const -//{ -// if (!item.isValid()) -// return QRect(); + for (int r = 0; r < model()->rowCount(); r++) + { + QModelIndex index = model()->index(r, glvdebug_QTraceFileModel::Column_EntrypointName); + QRectF rectf = itemRect(index); + QRect rect = rectf.toRect(); + int gap = 10; + if (rect.contains(wx-gap, wy)) + { + return index; + } + } -// return viewport()->rect(); -//} + return QModelIndex(); +} -//QRegion glvdebug_QTimelineView::itemRegion(const QModelIndex &index) const -//{ -// if (!index.isValid()) -// return QRegion(); +QRegion glvdebug_QTimelineView::itemRegion(const QModelIndex &index) const +{ + if (!index.isValid()) + return QRegion(); -// return QRegion(); -//} + return QRegion(itemRect(index).toRect()); +} //int glvdebug_QTimelineView::rows(const QModelIndex &index = QModelIndex()) const //{ @@ -399,7 +468,7 @@ void glvdebug_QTimelineView::drawCurrentApiCallMarker(QPainter* painter, painter->restore(); } -float glvdebug_QTimelineView::scaleDurationHorizontally(uint64_t value) +float glvdebug_QTimelineView::scaleDurationHorizontally(uint64_t value) const { float scaled = value * m_horizontalScale; if (scaled <= m_horizontalScale) @@ -410,7 +479,7 @@ float glvdebug_QTimelineView::scaleDurationHorizontally(uint64_t value) return scaled; } -float glvdebug_QTimelineView::scalePositionHorizontally(uint64_t value) +float glvdebug_QTimelineView::scalePositionHorizontally(uint64_t value) const { uint64_t shiftedValue = value - m_rawStartTime; uint64_t duration = m_rawEndTime - m_rawStartTime; @@ -423,9 +492,6 @@ void glvdebug_QTimelineView::drawTimelineItem(QPainter* painter, const QModelInd { glv_trace_packet_header* pHeader = (glv_trace_packet_header*)index.internalPointer(); - int threadIndex = m_threadIdList.indexOf(pHeader->thread_id); - int topOffset = (m_threadHeight * threadIndex) + (m_threadHeight * 0.5); - float duration = u64ToFloat(pHeader->entrypoint_end_time - pHeader->entrypoint_begin_time); if (duration < 0) { @@ -434,35 +500,28 @@ void glvdebug_QTimelineView::drawTimelineItem(QPainter* painter, const QModelInd painter->save(); { + int threadIndex = m_threadIdList.indexOf(pHeader->thread_id); + // only draw if the item will extend beyond the minimum offset - float leftOffset = scalePositionHorizontally(pHeader->entrypoint_begin_time); - float scaledWidth = scaleDurationHorizontally(duration); - if (m_threadIdMinOffset[threadIndex] < leftOffset + scaledWidth) +// float leftOffset = scalePositionHorizontally(pHeader->entrypoint_begin_time); +// float scaledWidth = scaleDurationHorizontally(duration); +// if (m_threadIdMinOffset[threadIndex] < leftOffset + scaledWidth) { - float durationRatio = duration / m_maxItemDuration; - int intensity = std::min(255, (int)(durationRatio * 255.0f)); - QColor color(intensity, 255-intensity, 0); - painter->setBrush(QBrush(color)); - painter->setPen(color); - - // Clamp the item so that it is 1 pixel wide. - // This is intentionally being done before updating the minimum offset - // so that small items after the current item will not be drawn - if (scaledWidth < 1) + QRectF rect = itemRect(index); + + if (rect.isValid()) { - scaledWidth = 1; - } + float durationRatio = duration / m_maxItemDuration; + int intensity = std::min(255, (int)(durationRatio * 255.0f)); + QColor color(intensity, 255-intensity, 0); + painter->setBrush(QBrush(color)); + painter->setPen(color); - // update minimum offset - m_threadIdMinOffset[threadIndex] = leftOffset + scaledWidth; + // update minimum offset + m_threadIdMinOffset[threadIndex] = rect.left() + rect.width(); - // draw the colored box that represents this item - QRectF rect; - rect.setLeft(leftOffset); - rect.setTop(topOffset - (height/2)); - rect.setWidth(scaledWidth); - rect.setHeight(height); - painter->drawRect(rect); + painter->drawRect(rect); + } } } diff --git a/tools/glave/src/glvdebug/glvdebug_qtimelineview.h b/tools/glave/src/glvdebug/glvdebug_qtimelineview.h index 3dcb328..ac49dbf 100755 --- a/tools/glave/src/glvdebug/glvdebug_qtimelineview.h +++ b/tools/glave/src/glvdebug/glvdebug_qtimelineview.h @@ -111,12 +111,12 @@ private: void drawTimelineItem(QPainter* painter, const QModelIndex &index, int height); void drawCurrentApiCallMarker(QPainter *painter, QPolygon &triangle, uint64_t rawTime); - float scaleDurationHorizontally(uint64_t value); - float scalePositionHorizontally(uint64_t value); + float scaleDurationHorizontally(uint64_t value) const; + float scalePositionHorizontally(uint64_t value) const; + QRectF itemRect(const QModelIndex &item) const; // Begin Private... -// virtual QRect itemRect(const QModelIndex &item) const; -// virtual QRegion itemRegion(const QModelIndex &index) const; + virtual QRegion itemRegion(const QModelIndex &index) const; // virtual int rows(const QModelIndex &index = QModelIndex()) const; // End private... @@ -124,6 +124,8 @@ protected: void paintEvent(QPaintEvent *event); void paint(QPainter *painter, QPaintEvent *event); + virtual bool event(QEvent * e); + // Begin protected virtual functions of QAbstractItemView virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)