#include <QGraphicsScene>
#include <QStyleOption>
#include <QGraphicsView>
+#include <QLabel>
#include <QGraphicsRectItem>
#include <QWheelEvent>
#include <QEvent>
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
+ QString description() const;
+
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
- void showToolTip() const;
private:
quint64 m_cost;
{
QGraphicsRectItem::hoverEnterEvent(event);
m_isHovered = true;
- showToolTip();
}
-void FrameGraphicsItem::showToolTip() const
+QString FrameGraphicsItem::description() const
{
// we build the tooltip text on demand, which is much faster than doing that for potentially thousands of items when we load the data
QString tooltip;
"%1 (%2%) allocated in %3 and below.", format.formatByteSize(m_cost), fraction, m_function);
break;
}
- QToolTip::showText(QCursor::pos(), tooltip);
+
+ return tooltip;
}
void FrameGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsRectItem::hoverLeaveEvent(event);
m_isHovered = false;
-
- if (auto parent = static_cast<FrameGraphicsItem*>(parentItem())) {
- parent->showToolTip();
- }
}
namespace {
, m_costSource(new QComboBox(this))
, m_scene(new QGraphicsScene(this))
, m_view(new QGraphicsView(this))
+ , m_displayLabel(new QLabel)
, m_rootItem(nullptr)
, m_selectedItem(nullptr)
, m_minRootWidth(0)
setLayout(new QVBoxLayout);
layout()->addWidget(controls);
layout()->addWidget(m_view);
+ layout()->addWidget(m_displayLabel);
}
FlameGraph::~FlameGraph() = default;
if (mouseEvent->button() == Qt::LeftButton) {
selectItem(static_cast<FrameGraphicsItem*>(m_view->itemAt(mouseEvent->pos())));
}
+ } else if (event->type() == QEvent::MouseMove) {
+ QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
+ auto item = static_cast<FrameGraphicsItem*>(m_view->itemAt(mouseEvent->pos()));
+ if (item) {
+ setDisplayText(item->description());
+ } else {
+ setDisplayText(QString());
+ }
} else if (event->type() == QEvent::Resize || event->type() == QEvent::Show) {
if (!m_rootItem) {
showData();
});
}
+void FlameGraph::setDisplayText(const QString& text)
+{
+ m_displayLabel->setText(text);
+}
+
void FlameGraph::setData(FrameGraphicsItem* rootItem)
{
m_scene->clear();
class QGraphicsScene;
class QGraphicsView;
class QComboBox;
+class QLabel;
class FrameGraphicsItem;
void setTopDownData(const TreeData& topDownData);
void setBottomUpData(const TreeData& bottomUpData);
+ void setDisplayText(const QString& text);
+
protected:
bool eventFilter(QObject* object, QEvent* event) override;
QComboBox* m_costSource;
QGraphicsScene* m_scene;
QGraphicsView* m_view;
+ QLabel* m_displayLabel;
FrameGraphicsItem* m_rootItem;
FrameGraphicsItem* m_selectedItem;
int m_minRootWidth;