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-30 02:57:57 +03:00
|
|
|
* :
|
|
|
|
* : * 2016/06/29 Victor Zarubkin: Highly optimized painting performance and memory consumption.
|
|
|
|
* :
|
2016-06-30 03:45:11 +03:00
|
|
|
* : * 2016/06/30 Victor Zarubkin: Replaced doubles with floats (in ProfBlockItem) for less memory consumption.
|
|
|
|
* :
|
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>
|
2016-07-31 18:48:41 +03:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QFont>
|
2016-06-26 20:54:16 +03:00
|
|
|
#include <QPoint>
|
2016-07-27 22:52:13 +03:00
|
|
|
#include <QTimer>
|
2016-06-26 18:46:51 +03:00
|
|
|
#include <stdlib.h>
|
2016-06-30 02:57:57 +03:00
|
|
|
#include <vector>
|
2016-07-31 13:13:48 +03:00
|
|
|
#include "graphics_scrollbar.h"
|
2016-06-26 18:46:51 +03:00
|
|
|
#include "profiler/reader.h"
|
2016-07-31 18:48:41 +03:00
|
|
|
#include "common_types.h"
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct ProfBlockItem
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 13:13:48 +03:00
|
|
|
const BlocksTree* block;
|
|
|
|
qreal x;
|
|
|
|
float w;
|
|
|
|
float y;
|
|
|
|
float h;
|
|
|
|
QRgb color;
|
|
|
|
unsigned int children_begin;
|
|
|
|
unsigned short totalHeight;
|
|
|
|
char state;
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
void setRect(qreal _x, float _y, float _w, float _h);
|
|
|
|
qreal left() const;
|
|
|
|
float top() const;
|
|
|
|
float width() const;
|
|
|
|
float height() const;
|
|
|
|
qreal right() const;
|
|
|
|
float bottom() const;
|
2016-06-30 02:57:57 +03:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-31 13:13:48 +03:00
|
|
|
|
|
|
|
class ProfGraphicsView;
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
class ProfGraphicsItem : public QGraphicsItem
|
|
|
|
{
|
2016-07-31 13:13:48 +03:00
|
|
|
typedef ::std::vector<ProfBlockItem> Children;
|
|
|
|
typedef ::std::vector<unsigned int> DrawIndexes;
|
|
|
|
typedef ::std::vector<Children> Sublevels;
|
2016-06-30 03:45:11 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
DrawIndexes m_levelsIndexes;
|
|
|
|
Sublevels m_levels;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
QRectF m_boundingRect;
|
|
|
|
const BlocksTree* m_pRoot;
|
|
|
|
::profiler::thread_id_t m_thread_id;
|
|
|
|
QRgb m_backgroundColor;
|
|
|
|
const bool m_bTest;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
public:
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
ProfGraphicsItem();
|
|
|
|
ProfGraphicsItem(bool _test);
|
2016-07-31 18:48:41 +03:00
|
|
|
ProfGraphicsItem(::profiler::thread_id_t _thread_id, const BlocksTree* _root);
|
2016-06-30 02:57:57 +03:00
|
|
|
virtual ~ProfGraphicsItem();
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
QRectF boundingRect() const override;
|
|
|
|
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
public:
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
|
|
|
|
void setBoundingRect(const QRectF& _rect);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
void setBackgroundColor(QRgb _color);
|
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
unsigned short levels() const;
|
2016-07-10 01:24:31 +03:00
|
|
|
void setLevels(unsigned short _levels);
|
|
|
|
void reserve(unsigned short _level, size_t _items);
|
|
|
|
const Children& items(unsigned short _level) const;
|
|
|
|
const ProfBlockItem& getItem(unsigned short _level, size_t _index) const;
|
|
|
|
ProfBlockItem& getItem(unsigned short _level, size_t _index);
|
|
|
|
size_t addItem(unsigned short _level);
|
|
|
|
size_t addItem(unsigned short _level, const ProfBlockItem& _item);
|
|
|
|
size_t addItem(unsigned short _level, ProfBlockItem&& _item);
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
void getBlocks(qreal _left, qreal _right, TreeBlocks& _blocks) const;
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
const ProfGraphicsView* view() const;
|
2016-06-30 03:45:11 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
}; // END of class ProfGraphicsItem.
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
class ProfChronometerItem : public QGraphicsItem
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
QFont m_font;
|
|
|
|
QRectF m_boundingRect;
|
|
|
|
qreal m_left, m_right;
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
public:
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
ProfChronometerItem();
|
|
|
|
virtual ~ProfChronometerItem();
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
QRectF boundingRect() const override;
|
|
|
|
void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget = nullptr) override;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
void setBoundingRect(qreal x, qreal y, qreal w, qreal h);
|
|
|
|
void setBoundingRect(const QRectF& _rect);
|
|
|
|
void setLeftRight(qreal _left, qreal _right);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
inline qreal left() const
|
|
|
|
{
|
|
|
|
return m_left;
|
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
inline qreal right() const
|
|
|
|
{
|
|
|
|
return m_right;
|
|
|
|
}
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
inline qreal width() const
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
return m_right - m_left;
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
private:
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
const ProfGraphicsView* view() const;
|
|
|
|
|
|
|
|
}; // END of class ProfChronometerItem.
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
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:
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
typedef ProfGraphicsView This;
|
2016-07-31 18:48:41 +03:00
|
|
|
typedef ::std::vector<ProfGraphicsItem*> Items;
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
Items m_items;
|
|
|
|
TreeBlocks m_selectedBlocks;
|
2016-07-31 13:13:48 +03:00
|
|
|
QTimer m_flickerTimer;
|
|
|
|
QRectF m_visibleSceneRect;
|
2016-07-31 18:48:41 +03:00
|
|
|
::profiler::timestamp_t m_beginTime;
|
2016-07-31 13:13:48 +03:00
|
|
|
qreal m_scale;
|
|
|
|
qreal m_offset; ///< Have to use manual offset for all scene content instead of using scrollbars because QScrollBar::value is 32-bit integer :(
|
|
|
|
QPoint m_mousePressPos;
|
|
|
|
Qt::MouseButtons m_mouseButtons;
|
|
|
|
GraphicsHorizontalScrollbar* m_pScrollbar;
|
2016-07-31 18:48:41 +03:00
|
|
|
ProfChronometerItem* m_chronometerItem;
|
2016-07-31 13:13:48 +03:00
|
|
|
int m_flickerSpeed;
|
|
|
|
bool m_bUpdatingRect;
|
2016-07-31 18:48:41 +03:00
|
|
|
bool m_bTest;
|
|
|
|
bool m_bEmpty;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-06-26 20:54:16 +03:00
|
|
|
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
|
|
|
|
2016-06-26 20:54:16 +03:00
|
|
|
void wheelEvent(QWheelEvent* _event) override;
|
|
|
|
void mousePressEvent(QMouseEvent* _event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent* _event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent* _event) override;
|
2016-07-31 18:48:41 +03:00
|
|
|
void resizeEvent(QResizeEvent* _event) override;
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
inline qreal scale() const
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
|
|
|
return m_scale;
|
|
|
|
}
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
inline qreal offset() const
|
|
|
|
{
|
|
|
|
return m_offset;
|
|
|
|
}
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
inline const QRectF& visibleSceneRect() const
|
|
|
|
{
|
|
|
|
return m_visibleSceneRect;
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
inline qreal time2position(const profiler::timestamp_t& _time) const
|
|
|
|
{
|
|
|
|
return qreal(_time - m_beginTime) * 1e-6;
|
|
|
|
}
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
void setScrollbar(GraphicsHorizontalScrollbar* _scrollbar);
|
2016-06-30 02:57:57 +03:00
|
|
|
void clearSilent();
|
|
|
|
|
|
|
|
void test(size_t _frames_number, size_t _total_items_number_estimate, int _depth);
|
2016-07-31 18:48:41 +03:00
|
|
|
void setTree(const thread_blocks_tree_t& _blocksTree);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void treeblocksChanged(const TreeBlocks& _blocks, ::profiler::timestamp_t _begin_time);
|
2016-06-30 02:57:57 +03:00
|
|
|
|
|
|
|
private:
|
2016-06-26 20:54:16 +03:00
|
|
|
|
|
|
|
void initMode();
|
2016-06-30 02:57:57 +03:00
|
|
|
void updateVisibleSceneRect();
|
2016-07-31 13:13:48 +03:00
|
|
|
void updateScene();
|
2016-07-31 18:48:41 +03:00
|
|
|
qreal setTree(ProfGraphicsItem* _item, const BlocksTree::children_t& _children, qreal& _height, qreal _y, unsigned short _level);
|
2016-06-30 02:57:57 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
void onScrollbarValueChange(int);
|
2016-07-31 13:13:48 +03:00
|
|
|
void onGraphicsScrollbarValueChange(qreal);
|
2016-07-27 22:52:13 +03:00
|
|
|
void onFlickerTimeout();
|
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
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
class ProfGraphicsViewWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ProfGraphicsView* m_view;
|
|
|
|
GraphicsHorizontalScrollbar* m_scrollbar;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ProfGraphicsViewWidget(bool _test = false);
|
|
|
|
ProfGraphicsViewWidget(const thread_blocks_tree_t& _blocksTree);
|
|
|
|
virtual ~ProfGraphicsViewWidget();
|
|
|
|
|
|
|
|
ProfGraphicsView* view();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
}; // END of class ProfGraphicsViewWidget.
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-06-26 18:46:51 +03:00
|
|
|
#endif // MY____GRAPHICS___VIEW_H
|