0
0
mirror of https://github.com/yse/easy_profiler.git synced 2025-01-14 00:27:55 +08:00
easy_profiler/profiler_gui/blocks_graphics_view.h

132 lines
4.0 KiB
C
Raw Normal View History

2016-06-26 18:56:40 +03:00
/************************************************************************
* file name : blocks_graphics_view.h
* ----------------- :
* creation time : 2016/06/26
* copyright : (c) 2016 Victor Zarubkin
* author : Victor Zarubkin
* email : v.s.zarubkin@gmail.com
* ----------------- :
* description : The file contains declaration of GraphicsScene and GraphicsView and
* : it's auxiliary classes for displyaing easy_profiler blocks tree.
* ----------------- :
* change log : * 2016/06/26 Victor Zarubkin: moved sources from graphics_view.h
2016-06-26 19:06:53 +03:00
* : and renamed classes from My* to Prof*.
2016-06-26 18:56:40 +03:00
* : *
* ----------------- :
* license : TODO: add license text
************************************************************************/
2016-06-26 18:46:51 +03:00
#ifndef MY____GRAPHICS___VIEW_H
#define MY____GRAPHICS___VIEW_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPolygonItem>
#include <QGraphicsSimpleTextItem>
#include <QPoint>
2016-06-26 18:46:51 +03:00
#include <stdlib.h>
#include "profiler/reader.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-26 19:06:53 +03:00
class ProfGraphicsPolygonItem : public QGraphicsPolygonItem
2016-06-26 18:46:51 +03:00
{
bool m_bDrawBorders;
2016-06-26 18:46:51 +03:00
public:
ProfGraphicsPolygonItem(bool _drawBorders, QGraphicsItem* _parent = nullptr);
2016-06-26 19:06:53 +03:00
virtual ~ProfGraphicsPolygonItem();
2016-06-26 18:46:51 +03:00
//void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = Q_NULLPTR) override;
2016-06-26 19:06:53 +03:00
}; // END of class ProfGraphicsPolygonItem.
2016-06-26 18:46:51 +03:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class ProfGraphicsTextItem : public QGraphicsSimpleTextItem
2016-06-26 18:46:51 +03:00
{
public:
2016-06-26 19:06:53 +03:00
ProfGraphicsTextItem(const char* _text, QGraphicsItem* _parent = nullptr);
virtual ~ProfGraphicsTextItem();
2016-06-26 18:46:51 +03:00
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = Q_NULLPTR) override;
2016-06-26 18:46:51 +03:00
2016-06-26 19:06:53 +03:00
}; // END of class ProfGraphicsTextItem.
2016-06-26 18:46:51 +03:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-26 19:06:53 +03:00
class ProfGraphicsScene : public QGraphicsScene
2016-06-26 18:46:51 +03:00
{
friend class ProfGraphicsView;
2016-06-26 18:46:51 +03:00
Q_OBJECT
private:
profiler::timestamp_t m_start;
public:
ProfGraphicsScene(QGraphicsView* _parent, bool _test = false);
2016-06-26 19:06:53 +03:00
ProfGraphicsScene(const thread_blocks_tree_t& _blocksTree, QGraphicsView* _parent);
virtual ~ProfGraphicsScene();
2016-06-26 18:46:51 +03:00
private:
2016-06-26 18:46:51 +03:00
void test();
void clearSilent();
2016-06-26 18:46:51 +03:00
void setTree(const thread_blocks_tree_t& _blocksTree);
void setTreeInternal(const thread_blocks_tree_t& _blocksTree);
qreal setTreeInternal(const BlocksTree::children_t& _children, unsigned short& _depth, qreal _y, unsigned short _level);
2016-06-26 18:46:51 +03:00
inline qreal time2position(const profiler::timestamp_t& _time) const
{
return qreal(_time - m_start) * 1e-6;
}
2016-06-26 19:06:53 +03:00
}; // END of class ProfGraphicsScene.
2016-06-26 18:46:51 +03:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2016-06-26 19:06:53 +03:00
class ProfGraphicsView : public QGraphicsView
2016-06-26 18:46:51 +03:00
{
Q_OBJECT
private:
qreal m_scale;
qreal m_scaleCoeff;
QPoint m_mousePressPos;
Qt::MouseButtons m_mouseButtons;
2016-06-26 18:46:51 +03:00
public:
ProfGraphicsView(bool _test = false);
2016-06-26 19:06:53 +03:00
ProfGraphicsView(const thread_blocks_tree_t& _blocksTree);
virtual ~ProfGraphicsView();
2016-06-26 18:46:51 +03:00
void wheelEvent(QWheelEvent* _event) override;
void mousePressEvent(QMouseEvent* _event) override;
void mouseReleaseEvent(QMouseEvent* _event) override;
void mouseMoveEvent(QMouseEvent* _event) override;
inline qreal currentScale() const
{
return m_scale;
}
2016-06-26 18:46:51 +03:00
void setTree(const thread_blocks_tree_t& _blocksTree);
void initMode();
2016-06-26 18:46:51 +03:00
2016-06-26 19:06:53 +03:00
}; // END of class ProfGraphicsView.
2016-06-26 18:46:51 +03:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#endif // MY____GRAPHICS___VIEW_H