From: Milian Wolff Date: Sat, 21 Jan 2017 23:42:23 +0000 (+0100) Subject: Elide text of flamegraph items X-Git-Tag: submit/tizen/20180620.112952^2~137 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4413e89a6735c9d36edf2b05621e08d652f20666;p=sdk%2Ftools%2Fheaptrack.git Elide text of flamegraph items This prevents the flickering when hovering an item with a long text. That lead the label to wordwrap, increasing the height of the label, decreasing the height of the view, moving the scene, thus the mouse points to a different view and we would repeat again. Now we simply elide the text on the right of the label. This works, but it's cutting of the text too soon, since it cannot cope with the HTML and thinks all of these chars will get painted... --- diff --git a/src/analyze/gui/flamegraph.cpp b/src/analyze/gui/flamegraph.cpp index f815485..5a56487 100644 --- a/src/analyze/gui/flamegraph.cpp +++ b/src/analyze/gui/flamegraph.cpp @@ -343,8 +343,6 @@ FlameGraph::FlameGraph(QWidget* parent, Qt::WindowFlags flags) , m_scene(new QGraphicsScene(this)) , m_view(new QGraphicsView(this)) , m_displayLabel(new QLabel) - , m_rootItem(nullptr) - , m_minRootWidth(0) { qRegisterMetaType(); @@ -459,19 +457,16 @@ bool FlameGraph::eventFilter(QObject* object, QEvent* event) } else if (event->type() == QEvent::MouseMove) { QMouseEvent* mouseEvent = static_cast(event); auto item = static_cast(m_view->itemAt(mouseEvent->pos())); - if (item) { - setDisplayText(item->description()); - } else { - setDisplayText({}); - } + setTooltipItem(item); } else if (event->type() == QEvent::Leave) { - setDisplayText({}); + setTooltipItem(nullptr); } else if (event->type() == QEvent::Resize || event->type() == QEvent::Show) { if (!m_rootItem) { showData(); } else { selectItem(m_selectionHistory.at(m_selectedItem)); } + updateTooltip(); } else if (event->type() == QEvent::Hide) { setData(nullptr); } @@ -508,15 +503,26 @@ void FlameGraph::showData() }); } -void FlameGraph::setDisplayText(const QString& text) +void FlameGraph::setTooltipItem(const FrameGraphicsItem* item) { - if (text.isEmpty() && m_selectedItem != -1 && m_selectionHistory.at(m_selectedItem)) { - m_displayLabel->setText(m_selectionHistory.at(m_selectedItem)->description()); + if (!item && m_selectedItem != -1 && m_selectionHistory.at(m_selectedItem)) { + item = m_selectionHistory.at(m_selectedItem); m_view->setCursor(Qt::ArrowCursor); } else { - m_displayLabel->setText(text); m_view->setCursor(Qt::PointingHandCursor); } + m_tooltipItem = item; + updateTooltip(); +} + +void FlameGraph::updateTooltip() +{ + const auto text = m_tooltipItem ? m_tooltipItem->description() : QString(); + m_displayLabel->setToolTip(text); + const auto metrics = m_displayLabel->fontMetrics(); + // FIXME: the HTML text has tons of stuff that is not printed, + // which lets the text get cut-off too soon... + m_displayLabel->setText(metrics.elidedText(text, Qt::ElideRight, m_displayLabel->width())); } void FlameGraph::setData(FrameGraphicsItem* rootItem) @@ -572,7 +578,7 @@ void FlameGraph::selectItem(FrameGraphicsItem* item) // and make sure it's visible m_view->centerOn(item); - setDisplayText(item->description()); + setTooltipItem(item); } void FlameGraph::navigateBack() diff --git a/src/analyze/gui/flamegraph.h b/src/analyze/gui/flamegraph.h index c106686..aef55da 100644 --- a/src/analyze/gui/flamegraph.h +++ b/src/analyze/gui/flamegraph.h @@ -42,8 +42,6 @@ public: void setTopDownData(const TreeData& topDownData); void setBottomUpData(const TreeData& bottomUpData); - void setDisplayText(const QString& text); - protected: bool eventFilter(QObject* object, QEvent* event) override; @@ -51,6 +49,8 @@ private slots: void setData(FrameGraphicsItem* rootItem); private: + void setTooltipItem(const FrameGraphicsItem* item); + void updateTooltip(); void navigateBack(); void navigateForward(); void showData(); @@ -63,7 +63,8 @@ private: QGraphicsScene* m_scene; QGraphicsView* m_view; QLabel* m_displayLabel; - FrameGraphicsItem* m_rootItem; + const FrameGraphicsItem* m_tooltipItem = nullptr; + FrameGraphicsItem* m_rootItem = nullptr; QVector m_selectionHistory; int m_selectedItem = -1; int m_minRootWidth = 0;