2016-08-08 22:45:57 +03:00
|
|
|
/************************************************************************
|
|
|
|
* file name : blocks_graphics_view.cpp
|
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/06/26
|
|
|
|
* copyright : (c) 2016 Victor Zarubkin
|
|
|
|
* author : Victor Zarubkin
|
|
|
|
* email : v.s.zarubkin@gmail.com
|
|
|
|
* ----------------- :
|
|
|
|
* description : The file contains implementation 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
|
|
|
|
* : and renamed classes from My* to Prof*.
|
|
|
|
* :
|
|
|
|
* : * 2016/06/27 Victor Zarubkin: Added text shifting relatively to it's parent item.
|
|
|
|
* : Disabled border lines painting because of vertical lines painting bug.
|
|
|
|
* : Changed height of blocks. Variable thread-block height.
|
|
|
|
* :
|
|
|
|
* : * 2016/06/29 Victor Zarubkin: Highly optimized painting performance and memory consumption.
|
|
|
|
* :
|
|
|
|
* : * 2016/06/30 Victor Zarubkin: Replaced doubles with floats (in ProfBlockItem) for less memory consumption.
|
|
|
|
* :
|
|
|
|
* : *
|
|
|
|
* ----------------- :
|
|
|
|
* license : TODO: add license text
|
2016-06-26 18:56:40 +03:00
|
|
|
************************************************************************/
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
#include <QGraphicsScene>
|
2016-06-26 18:46:51 +03:00
|
|
|
#include <QWheelEvent>
|
2016-06-26 20:54:16 +03:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QScrollBar>
|
2016-08-10 22:08:27 +03:00
|
|
|
#include <QGridLayout>
|
2016-08-18 23:26:41 +03:00
|
|
|
#include <QFont>
|
2016-07-31 18:48:41 +03:00
|
|
|
#include <QFontMetrics>
|
2016-08-11 23:43:34 +03:00
|
|
|
#include <QDebug>
|
2016-06-30 02:57:57 +03:00
|
|
|
#include <math.h>
|
2016-07-10 01:24:31 +03:00
|
|
|
#include <algorithm>
|
2016-06-26 18:46:51 +03:00
|
|
|
#include "blocks_graphics_view.h"
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
#include "globals.h"
|
|
|
|
|
2016-08-06 14:50:31 +03:00
|
|
|
using namespace profiler_gui;
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
const qreal SCALING_COEFFICIENT = 1.25;
|
|
|
|
const qreal SCALING_COEFFICIENT_INV = 1.0 / SCALING_COEFFICIENT;
|
2016-08-01 22:21:59 +03:00
|
|
|
const qreal MIN_SCALE = pow(SCALING_COEFFICIENT_INV, 70);
|
|
|
|
const qreal MAX_SCALE = pow(SCALING_COEFFICIENT, 30); // ~800
|
|
|
|
const qreal BASE_SCALE = pow(SCALING_COEFFICIENT_INV, 25); // ~0.003
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
const unsigned short GRAPHICS_ROW_SIZE = 16;
|
2016-08-11 23:43:34 +03:00
|
|
|
const unsigned short GRAPHICS_ROW_SPACING = 2;
|
|
|
|
const unsigned short GRAPHICS_ROW_SIZE_FULL = GRAPHICS_ROW_SIZE + GRAPHICS_ROW_SPACING;
|
2016-08-14 22:22:44 +03:00
|
|
|
const unsigned short THREADS_ROW_SPACING = 8;
|
2016-08-21 14:26:04 +03:00
|
|
|
const unsigned short TIMELINE_ROW_SIZE = 20;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
const QRgb BORDERS_COLOR = 0x00a07050;
|
2016-08-03 23:00:04 +03:00
|
|
|
const QRgb BACKGROUND_1 = 0x00dddddd;
|
2016-08-01 22:21:59 +03:00
|
|
|
const QRgb BACKGROUND_2 = 0x00ffffff;
|
2016-08-10 22:08:27 +03:00
|
|
|
const QRgb TIMELINE_BACKGROUND = 0x20303030;
|
|
|
|
const QRgb SELECTED_ITEM_COLOR = 0x000050a0;
|
2016-08-21 14:26:04 +03:00
|
|
|
const QColor CHRONOMETER_COLOR2 = QColor::fromRgba(0x40408040);
|
2016-08-01 22:21:59 +03:00
|
|
|
|
2016-08-04 22:38:45 +03:00
|
|
|
const unsigned int TEST_PROGRESSION_BASE = 4;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-06 14:50:31 +03:00
|
|
|
const int FLICKER_INTERVAL = 16; // 60Hz
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const auto CHRONOMETER_FONT = QFont("CourierNew", 16, 2);
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
auto const sign = [](int _value) { return _value < 0 ? -1 : 1; };
|
|
|
|
auto const absmin = [](int _a, int _b) { return abs(_a) < abs(_b) ? _a : _b; };
|
|
|
|
auto const clamp = [](qreal _minValue, qreal _value, qreal _maxValue) { return _value < _minValue ? _minValue : (_value > _maxValue ? _maxValue : _value); };
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
template <int N, class T>
|
|
|
|
inline T logn(T _value)
|
|
|
|
{
|
|
|
|
static const double div = 1.0 / log2((double)N);
|
|
|
|
return log2(_value) * div;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsItem::EasyGraphicsItem(unsigned char _index, const::profiler::BlocksTreeRoot* _root)
|
|
|
|
: QGraphicsItem(nullptr)
|
|
|
|
, m_pRoot(_root)
|
|
|
|
, m_index(_index)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsItem::~EasyGraphicsItem()
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const EasyGraphicsView* EasyGraphicsItem::view() const
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
return static_cast<const EasyGraphicsView*>(scene()->parent());
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
QRectF EasyGraphicsItem::boundingRect() const
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-07-31 13:13:48 +03:00
|
|
|
//const auto sceneView = view();
|
2016-07-31 18:48:41 +03:00
|
|
|
//return QRectF(m_boundingRect.left() - sceneView->offset() / sceneView->scale(), m_boundingRect.top(), m_boundingRect.width() * sceneView->scale(), m_boundingRect.height());
|
|
|
|
return m_boundingRect;
|
2016-06-30 02:57:57 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
|
|
|
if (m_levels.empty() || m_levels.front().empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
const auto sceneView = view();
|
|
|
|
const auto visibleSceneRect = sceneView->visibleSceneRect(); // Current visible scene rect
|
2016-07-31 18:48:41 +03:00
|
|
|
const auto currentScale = sceneView->scale(); // Current GraphicsView scale
|
2016-07-31 13:13:48 +03:00
|
|
|
const auto offset = sceneView->offset();
|
|
|
|
const auto sceneLeft = offset, sceneRight = offset + visibleSceneRect.width() / currentScale;
|
|
|
|
|
|
|
|
//printf("VISIBLE = {%lf, %lf}\n", sceneLeft, sceneRight);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
|
|
|
QRectF rect;
|
|
|
|
QBrush brush;
|
|
|
|
QRgb previousColor = 0;
|
2016-08-04 23:35:38 +03:00
|
|
|
Qt::PenStyle previousPenStyle = Qt::NoPen;
|
2016-07-10 01:24:31 +03:00
|
|
|
brush.setStyle(Qt::SolidPattern);
|
|
|
|
|
|
|
|
_painter->save();
|
2016-08-21 14:26:04 +03:00
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
// Reset indices of first visible item for each layer
|
|
|
|
const auto levelsNumber = levels();
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned char i = 1; i < levelsNumber; ++i) ::profiler_gui::set_max(m_levelsIndexes[i]);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Search for first visible top-level item
|
2016-08-08 22:17:56 +03:00
|
|
|
auto& level0 = m_levels.front();
|
2016-08-03 23:00:04 +03:00
|
|
|
auto first = ::std::lower_bound(level0.begin(), level0.end(), sceneLeft, [](const ::profiler_gui::ProfBlockItem& _item, qreal _value)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
|
|
|
return _item.left() < _value;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (first != level0.end())
|
|
|
|
{
|
|
|
|
m_levelsIndexes[0] = first - level0.begin();
|
|
|
|
if (m_levelsIndexes[0] > 0)
|
|
|
|
m_levelsIndexes[0] -= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
m_levelsIndexes[0] = static_cast<unsigned int>(level0.size() - 1);
|
2016-07-10 01:24:31 +03:00
|
|
|
}
|
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
// This is to make _painter->drawText() work properly
|
|
|
|
// (it seems there is a bug in Qt5.6 when drawText called for big coordinates,
|
|
|
|
// drawRect at the same time called for actually same coordinates
|
2016-07-31 13:13:48 +03:00
|
|
|
// works fine without using this additional shifting)
|
2016-08-01 22:21:59 +03:00
|
|
|
auto dx = level0[m_levelsIndexes[0]].left() * currentScale;
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
// Shifting coordinates to current screen offset
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(dx - offset * currentScale, -y()), true);
|
2016-08-21 14:26:04 +03:00
|
|
|
_painter->setClipRect(QRectF(0, visibleSceneRect.top(), scene()->width(), visibleSceneRect.height()));
|
2016-08-10 22:08:27 +03:00
|
|
|
|
|
|
|
|
2016-08-04 23:35:38 +03:00
|
|
|
if (::profiler_gui::EASY_GLOBALS.draw_graphics_items_borders)
|
|
|
|
{
|
|
|
|
previousPenStyle = Qt::SolidLine;
|
|
|
|
_painter->setPen(BORDERS_COLOR);
|
|
|
|
}
|
2016-08-18 23:26:41 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
}
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
|
|
|
|
|
2016-07-27 21:50:11 +03:00
|
|
|
// Iterate through layers and draw visible items
|
2016-08-08 23:03:11 +03:00
|
|
|
bool selectedItemsWasPainted = false;
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned char l = 0; l < levelsNumber; ++l)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
|
|
|
auto& level = m_levels[l];
|
2016-08-11 23:43:34 +03:00
|
|
|
const short next_level = l + 1;
|
2016-07-27 21:50:11 +03:00
|
|
|
char state = 1;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
const auto top = levelY(l);
|
2016-08-04 22:38:45 +03:00
|
|
|
for (unsigned int i = m_levelsIndexes[l], end = static_cast<unsigned int>(level.size()); i < end; ++i)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
|
|
|
auto& item = level[i];
|
2016-08-11 23:43:34 +03:00
|
|
|
static const auto MAX_CHILD_INDEX = ::profiler_gui::numeric_max(item.children_begin);
|
2016-07-31 13:13:48 +03:00
|
|
|
|
|
|
|
if (item.state != 0)
|
|
|
|
{
|
|
|
|
state = item.state;
|
|
|
|
}
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
if (item.right() < sceneLeft || state == -1 || (l == 0 && (top > visibleSceneRect.bottom() || (top + item.totalHeight) < visibleSceneRect.top())))
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
// This item is not visible
|
2016-08-21 14:26:04 +03:00
|
|
|
|
|
|
|
if (next_level < levelsNumber && item.children_begin != MAX_CHILD_INDEX)
|
|
|
|
{
|
|
|
|
// Mark that we would not paint children of current item
|
|
|
|
m_levels[next_level][item.children_begin].state = -1;
|
|
|
|
}
|
|
|
|
|
2016-07-10 01:24:31 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal x = 0;
|
|
|
|
int h = 0, flags = 0;
|
2016-07-27 21:50:11 +03:00
|
|
|
auto w = ::std::max(item.width() * currentScale, 1.0);
|
2016-08-18 23:26:41 +03:00
|
|
|
if (w < 20 || !::profiler_gui::EASY_GLOBALS.gui_blocks[item.block->block_index].expanded)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
2016-07-27 21:50:11 +03:00
|
|
|
// Items which width is less than 20 will be painted as big rectangles which are hiding it's children
|
|
|
|
if (item.left() > sceneRight)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
// This is first totally invisible item. No need to check other items.
|
2016-07-27 21:50:11 +03:00
|
|
|
break;
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
x = item.left() * currentScale - dx;
|
|
|
|
h = item.totalHeight;
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-08 22:17:56 +03:00
|
|
|
bool changepen = false;
|
2016-08-18 23:26:41 +03:00
|
|
|
if (item.block->block_index == ::profiler_gui::EASY_GLOBALS.selected_block)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
2016-08-08 23:03:11 +03:00
|
|
|
selectedItemsWasPainted = true;
|
2016-08-08 22:17:56 +03:00
|
|
|
changepen = true;
|
|
|
|
QPen pen(Qt::SolidLine);
|
|
|
|
pen.setColor(Qt::red);
|
|
|
|
pen.setWidth(2);
|
|
|
|
_painter->setPen(pen);
|
2016-08-08 22:35:21 +03:00
|
|
|
|
2016-08-08 22:54:20 +03:00
|
|
|
previousColor = SELECTED_ITEM_COLOR;
|
|
|
|
brush.setColor(previousColor);
|
2016-08-08 22:35:21 +03:00
|
|
|
_painter->setBrush(brush);
|
2016-08-08 22:17:56 +03:00
|
|
|
}
|
2016-08-08 22:35:21 +03:00
|
|
|
else
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-08-08 22:54:20 +03:00
|
|
|
if (previousColor != item.color)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-08-08 22:54:20 +03:00
|
|
|
// Set background color brush for rectangle
|
|
|
|
previousColor = item.color;
|
|
|
|
brush.setColor(previousColor);
|
|
|
|
_painter->setBrush(brush);
|
2016-08-08 22:35:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (::profiler_gui::EASY_GLOBALS.draw_graphics_items_borders)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-08-08 22:35:21 +03:00
|
|
|
if (w < 3)
|
2016-08-04 23:35:38 +03:00
|
|
|
{
|
2016-08-08 22:35:21 +03:00
|
|
|
// Do not paint borders for very narrow items
|
|
|
|
if (previousPenStyle != Qt::NoPen)
|
|
|
|
{
|
|
|
|
previousPenStyle = Qt::NoPen;
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (previousPenStyle != Qt::SolidLine)
|
|
|
|
{
|
|
|
|
// Restore pen for item which is wide enough to paint borders
|
|
|
|
previousPenStyle = Qt::SolidLine;
|
|
|
|
_painter->setPen(BORDERS_COLOR);
|
2016-08-04 23:35:38 +03:00
|
|
|
}
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Draw rectangle
|
2016-08-11 23:43:34 +03:00
|
|
|
rect.setRect(x, top, w, item.totalHeight);
|
2016-07-27 21:50:11 +03:00
|
|
|
_painter->drawRect(rect);
|
|
|
|
|
2016-08-08 22:17:56 +03:00
|
|
|
if (changepen)
|
|
|
|
{
|
2016-08-08 22:45:57 +03:00
|
|
|
if (previousPenStyle == Qt::NoPen)
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
else
|
|
|
|
_painter->setPen(BORDERS_COLOR); // restore pen for rectangle painting
|
2016-08-08 22:17:56 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
if (next_level < levelsNumber && item.children_begin != MAX_CHILD_INDEX)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
// Mark that we would not paint children of current item
|
|
|
|
m_levels[next_level][item.children_begin].state = -1;
|
|
|
|
}
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (w < 20)
|
|
|
|
continue;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
flags = Qt::AlignCenter;
|
|
|
|
}
|
|
|
|
else
|
2016-07-27 21:50:11 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
if (next_level < levelsNumber && item.children_begin != MAX_CHILD_INDEX)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
if (m_levelsIndexes[next_level] == MAX_CHILD_INDEX)
|
|
|
|
{
|
|
|
|
// Mark first potentially visible child item on next sublevel
|
|
|
|
m_levelsIndexes[next_level] = item.children_begin;
|
|
|
|
}
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
// Mark children items that we want to draw them
|
|
|
|
m_levels[next_level][item.children_begin].state = 1;
|
|
|
|
}
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (item.left() > sceneRight)
|
|
|
|
{
|
|
|
|
// This is first totally invisible item. No need to check other items.
|
|
|
|
break;
|
|
|
|
}
|
2016-08-08 22:35:21 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (item.block->block_index == ::profiler_gui::EASY_GLOBALS.selected_block)
|
2016-08-08 22:54:20 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
selectedItemsWasPainted = true;
|
|
|
|
QPen pen(Qt::SolidLine);
|
|
|
|
pen.setColor(Qt::red);
|
|
|
|
pen.setWidth(2);
|
|
|
|
_painter->setPen(pen);
|
|
|
|
|
|
|
|
previousColor = SELECTED_ITEM_COLOR;
|
2016-08-08 22:54:20 +03:00
|
|
|
brush.setColor(previousColor);
|
|
|
|
_painter->setBrush(brush);
|
2016-08-08 22:35:21 +03:00
|
|
|
}
|
2016-08-18 23:26:41 +03:00
|
|
|
else
|
2016-08-08 22:35:21 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
if (previousColor != item.color)
|
|
|
|
{
|
|
|
|
// Set background color brush for rectangle
|
|
|
|
previousColor = item.color;
|
|
|
|
brush.setColor(previousColor);
|
|
|
|
_painter->setBrush(brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (::profiler_gui::EASY_GLOBALS.draw_graphics_items_borders && previousPenStyle != Qt::SolidLine)
|
|
|
|
{
|
|
|
|
// Restore pen for item which is wide enough to paint borders
|
|
|
|
previousPenStyle = Qt::SolidLine;
|
|
|
|
_painter->setPen(BORDERS_COLOR);
|
|
|
|
}
|
2016-08-08 22:54:20 +03:00
|
|
|
}
|
2016-08-08 22:45:57 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
// Draw rectangle
|
|
|
|
x = item.left() * currentScale - dx;
|
|
|
|
h = GRAPHICS_ROW_SIZE;
|
|
|
|
rect.setRect(x, top, w, GRAPHICS_ROW_SIZE);
|
|
|
|
_painter->drawRect(rect);
|
|
|
|
|
|
|
|
flags = item.width() < 1 ? 0 : Qt::AlignHCenter;
|
|
|
|
}
|
2016-08-08 22:45:57 +03:00
|
|
|
|
|
|
|
// Draw text-----------------------------------
|
|
|
|
// calculating text coordinates
|
2016-07-31 13:13:48 +03:00
|
|
|
auto xtext = x;
|
2016-07-27 21:50:11 +03:00
|
|
|
if (item.left() < sceneLeft)
|
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
// if item left border is out of screen then attach text to the left border of the screen
|
|
|
|
// to ensure text is always visible for items presenting on the screen.
|
2016-07-27 21:50:11 +03:00
|
|
|
w += (item.left() - sceneLeft) * currentScale;
|
2016-07-31 13:13:48 +03:00
|
|
|
xtext = sceneLeft * currentScale - dx;
|
2016-07-27 21:50:11 +03:00
|
|
|
}
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (item.right() > sceneRight)
|
|
|
|
{
|
|
|
|
w -= (item.right() - sceneRight) * currentScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.setRect(xtext + 1, top, w - 1, h);
|
2016-08-08 22:45:57 +03:00
|
|
|
|
|
|
|
// text will be painted with inverse color
|
|
|
|
auto textColor = 0x00ffffff - previousColor;
|
|
|
|
if (textColor == previousColor) textColor = 0;
|
|
|
|
_painter->setPen(textColor);
|
|
|
|
|
|
|
|
// drawing text
|
2016-08-18 23:26:41 +03:00
|
|
|
_painter->drawText(rect, flags, ::profiler_gui::toUnicode(item.block->node->getName()));
|
2016-08-08 22:45:57 +03:00
|
|
|
|
|
|
|
// restore previous pen color
|
|
|
|
if (previousPenStyle == Qt::NoPen)
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
else
|
|
|
|
_painter->setPen(BORDERS_COLOR); // restore pen for rectangle painting
|
|
|
|
// END Draw text~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-07-10 01:24:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (!selectedItemsWasPainted && ::profiler_gui::EASY_GLOBALS.selected_block < ::profiler_gui::EASY_GLOBALS.gui_blocks.size())
|
2016-08-08 23:03:11 +03:00
|
|
|
{
|
|
|
|
const auto& guiblock = ::profiler_gui::EASY_GLOBALS.gui_blocks[::profiler_gui::EASY_GLOBALS.selected_block];
|
2016-08-11 23:43:34 +03:00
|
|
|
if (guiblock.graphics_item == m_index)
|
2016-08-08 23:03:11 +03:00
|
|
|
{
|
|
|
|
const auto& item = m_levels[guiblock.graphics_item_level][guiblock.graphics_item_index];
|
|
|
|
if (item.left() < sceneRight && item.right() > sceneLeft)
|
|
|
|
{
|
|
|
|
QPen pen(Qt::SolidLine);
|
|
|
|
pen.setColor(Qt::red);
|
|
|
|
pen.setWidth(2);
|
|
|
|
_painter->setPen(pen);
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
brush.setColor(SELECTED_ITEM_COLOR);
|
2016-08-08 23:03:11 +03:00
|
|
|
_painter->setBrush(brush);
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
auto top = levelY(guiblock.graphics_item_level);
|
|
|
|
auto x = item.left() * currentScale - dx;
|
|
|
|
auto w = ::std::max(item.width() * currentScale, 1.0);
|
|
|
|
rect.setRect(x, top, w, item.totalHeight);
|
2016-08-08 23:03:11 +03:00
|
|
|
_painter->drawRect(rect);
|
2016-08-18 23:26:41 +03:00
|
|
|
|
|
|
|
if (w > 20)
|
|
|
|
{
|
|
|
|
// Draw text-----------------------------------
|
|
|
|
// calculating text coordinates
|
|
|
|
auto xtext = x;
|
|
|
|
if (item.left() < sceneLeft)
|
|
|
|
{
|
|
|
|
// if item left border is out of screen then attach text to the left border of the screen
|
|
|
|
// to ensure text is always visible for items presenting on the screen.
|
|
|
|
w += (item.left() - sceneLeft) * currentScale;
|
|
|
|
xtext = sceneLeft * currentScale - dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.right() > sceneRight)
|
|
|
|
{
|
|
|
|
w -= (item.right() - sceneRight) * currentScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.setRect(xtext + 1, top, w - 1, item.totalHeight);
|
|
|
|
|
|
|
|
// text will be painted with inverse color
|
|
|
|
auto textColor = 0x00ffffff - previousColor;
|
|
|
|
if (textColor == previousColor) textColor = 0;
|
|
|
|
_painter->setPen(textColor);
|
|
|
|
|
|
|
|
// drawing text
|
|
|
|
_painter->drawText(rect, Qt::AlignCenter, ::profiler_gui::toUnicode(item.block->node->getName()));
|
|
|
|
|
|
|
|
// restore previous pen color
|
|
|
|
if (previousPenStyle == Qt::NoPen)
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
else
|
|
|
|
_painter->setPen(BORDERS_COLOR); // restore pen for rectangle painting
|
|
|
|
// END Draw text~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
}
|
2016-08-08 23:03:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-10 01:24:31 +03:00
|
|
|
_painter->restore();
|
|
|
|
}
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QRect EasyGraphicsItem::getRect() const
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
|
|
|
return view()->mapFromScene(m_boundingRect).boundingRect();
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsItem::getBlocks(qreal _left, qreal _right, ::profiler_gui::TreeBlocks& _blocks) const
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-08-08 22:45:57 +03:00
|
|
|
//if (m_bTest)
|
|
|
|
//{
|
|
|
|
// return;
|
|
|
|
//}
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Search for first visible top-level item
|
2016-08-08 22:17:56 +03:00
|
|
|
auto& level0 = m_levels.front();
|
2016-08-03 23:00:04 +03:00
|
|
|
auto first = ::std::lower_bound(level0.begin(), level0.end(), _left, [](const ::profiler_gui::ProfBlockItem& _item, qreal _value)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
return _item.left() < _value;
|
|
|
|
});
|
|
|
|
|
|
|
|
size_t itemIndex = 0;
|
|
|
|
if (first != level0.end())
|
|
|
|
{
|
|
|
|
itemIndex = first - level0.begin();
|
|
|
|
if (itemIndex > 0)
|
|
|
|
itemIndex -= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itemIndex = level0.size() - 1;
|
|
|
|
}
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Add all visible top-level items into array of visible blocks
|
2016-07-31 18:48:41 +03:00
|
|
|
for (size_t i = itemIndex, end = level0.size(); i < end; ++i)
|
|
|
|
{
|
|
|
|
const auto& item = level0[i];
|
|
|
|
|
|
|
|
if (item.left() > _right)
|
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
// First invisible item. No need to check other items.
|
2016-07-31 18:48:41 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.right() < _left)
|
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
// This item is not visible yet
|
|
|
|
// This is just to be sure
|
2016-07-31 18:48:41 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
_blocks.emplace_back(m_pRoot, item.block);
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const ::profiler_gui::ProfBlockItem* EasyGraphicsItem::intersect(const QPointF& _pos) const
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
if (m_levels.empty() || m_levels.front().empty())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& level0 = m_levels.front();
|
2016-08-11 23:43:34 +03:00
|
|
|
const auto top = y();
|
2016-08-08 22:17:56 +03:00
|
|
|
|
|
|
|
if (top > _pos.y())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto bottom = top + m_levels.size() * GRAPHICS_ROW_SIZE_FULL;
|
|
|
|
if (bottom < _pos.y())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned int levelIndex = static_cast<unsigned int>(_pos.y() - top) / GRAPHICS_ROW_SIZE_FULL;
|
|
|
|
if (levelIndex >= m_levels.size())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto currentScale = view()->scale();
|
|
|
|
unsigned int i = 0;
|
2016-08-11 23:43:34 +03:00
|
|
|
size_t itemIndex = ::std::numeric_limits<size_t>::max();
|
2016-08-08 22:17:56 +03:00
|
|
|
size_t firstItem = 0, lastItem = static_cast<unsigned int>(level0.size());
|
|
|
|
while (i <= levelIndex)
|
|
|
|
{
|
|
|
|
const auto& level = m_levels[i];
|
|
|
|
|
|
|
|
// Search for first visible item
|
|
|
|
auto first = ::std::lower_bound(level.begin() + firstItem, level.begin() + lastItem, _pos.x(), [](const ::profiler_gui::ProfBlockItem& _item, qreal _value)
|
|
|
|
{
|
|
|
|
return _item.left() < _value;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (first != level.end())
|
|
|
|
{
|
|
|
|
itemIndex = first - level.begin();
|
|
|
|
if (itemIndex != 0)
|
|
|
|
--itemIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itemIndex = level.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto size = level.size(); itemIndex < size; ++itemIndex)
|
|
|
|
{
|
|
|
|
const auto& item = level[itemIndex];
|
2016-08-11 23:43:34 +03:00
|
|
|
static const auto MAX_CHILD_INDEX = ::profiler_gui::numeric_max(item.children_begin);
|
2016-08-08 22:17:56 +03:00
|
|
|
|
|
|
|
if (item.left() > _pos.x())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.right() < _pos.x())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto w = item.width() * currentScale;
|
2016-08-18 23:26:41 +03:00
|
|
|
if (i == levelIndex || w < 20 || !::profiler_gui::EASY_GLOBALS.gui_blocks[item.block->block_index].expanded)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
return &item;
|
|
|
|
}
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
if (item.children_begin == MAX_CHILD_INDEX)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
if (itemIndex != 0)
|
|
|
|
{
|
|
|
|
auto j = itemIndex;
|
|
|
|
firstItem = 0;
|
|
|
|
do {
|
|
|
|
|
|
|
|
--j;
|
|
|
|
const auto& item2 = level[j];
|
2016-08-11 23:43:34 +03:00
|
|
|
if (item2.children_begin != MAX_CHILD_INDEX)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
firstItem = item2.children_begin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (j != 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstItem = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstItem = item.children_begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastItem = m_levels[i + 1].size();
|
|
|
|
for (auto j = itemIndex + 1; j < size; ++j)
|
|
|
|
{
|
|
|
|
const auto& item2 = level[j];
|
2016-08-11 23:43:34 +03:00
|
|
|
if (item2.children_begin != MAX_CHILD_INDEX)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
lastItem = item2.children_begin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
m_boundingRect.setRect(x, y, w, h);
|
2016-06-30 02:57:57 +03:00
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsItem::setBoundingRect(const QRectF& _rect)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
m_boundingRect = _rect;
|
2016-06-30 02:57:57 +03:00
|
|
|
}
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
::profiler::thread_id_t EasyGraphicsItem::threadId() const
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
|
|
|
return m_pRoot->thread_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
unsigned char EasyGraphicsItem::levels() const
|
2016-07-27 21:50:11 +03:00
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
return static_cast<unsigned char>(m_levels.size());
|
2016-07-27 21:50:11 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
float EasyGraphicsItem::levelY(unsigned char _level) const
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
return y() + static_cast<int>(_level) * static_cast<int>(GRAPHICS_ROW_SIZE_FULL);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsItem::setLevels(unsigned char _levels)
|
2016-08-11 23:43:34 +03:00
|
|
|
{
|
|
|
|
typedef decltype(m_levelsIndexes) IndexesT;
|
|
|
|
static const auto MAX_CHILD_INDEX = ::profiler_gui::numeric_max<IndexesT::value_type>();
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
m_levels.resize(_levels);
|
2016-08-11 23:43:34 +03:00
|
|
|
m_levelsIndexes.resize(_levels, MAX_CHILD_INDEX);
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsItem::reserve(unsigned char _level, unsigned int _items)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
m_levels[_level].reserve(_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const EasyGraphicsItem::Children& EasyGraphicsItem::items(unsigned char _level) const
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
return m_levels[_level];
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const ::profiler_gui::ProfBlockItem& EasyGraphicsItem::getItem(unsigned char _level, unsigned int _index) const
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
return m_levels[_level][_index];
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
::profiler_gui::ProfBlockItem& EasyGraphicsItem::getItem(unsigned char _level, unsigned int _index)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
return m_levels[_level][_index];
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
unsigned int EasyGraphicsItem::addItem(unsigned char _level)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
m_levels[_level].emplace_back();
|
|
|
|
return static_cast<unsigned int>(m_levels[_level].size() - 1);
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyChronometerItem::EasyChronometerItem(bool _main)
|
|
|
|
: QGraphicsItem()
|
|
|
|
, m_color(CHRONOMETER_COLOR)
|
|
|
|
, m_left(0)
|
|
|
|
, m_right(0)
|
|
|
|
, m_bMain(_main)
|
|
|
|
, m_bReverse(false)
|
|
|
|
, m_bHoverIndicator(false)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-08-10 22:08:27 +03:00
|
|
|
//setZValue(_main ? 10 : 9);
|
2016-08-06 14:50:31 +03:00
|
|
|
m_indicator.reserve(3);
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyChronometerItem::~EasyChronometerItem()
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
QRectF EasyChronometerItem::boundingRect() const
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
return m_boundingRect;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
const auto sceneView = view();
|
|
|
|
const auto currentScale = sceneView->scale();
|
|
|
|
const auto offset = sceneView->offset();
|
|
|
|
const auto visibleSceneRect = sceneView->visibleSceneRect();
|
2016-08-02 22:24:22 +03:00
|
|
|
auto sceneLeft = offset, sceneRight = offset + visibleSceneRect.width() / currentScale;
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-08 22:17:56 +03:00
|
|
|
if (m_bMain)
|
|
|
|
m_indicator.clear();
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_left > sceneRight || m_right < sceneLeft)
|
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
// This item is out of screen
|
2016-08-06 14:50:31 +03:00
|
|
|
|
|
|
|
if (m_bMain)
|
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
const int size = m_bHoverIndicator ? 12 : 10;
|
2016-08-06 14:50:31 +03:00
|
|
|
auto vcenter = visibleSceneRect.top() + visibleSceneRect.height() * 0.5;
|
2016-08-08 22:17:56 +03:00
|
|
|
auto color = QColor::fromRgb(m_color.rgb());
|
|
|
|
auto pen = _painter->pen();
|
|
|
|
pen.setColor(color);
|
2016-08-06 14:50:31 +03:00
|
|
|
|
|
|
|
m_indicator.clear();
|
|
|
|
if (m_left > sceneRight)
|
|
|
|
{
|
2016-08-07 20:16:15 +03:00
|
|
|
sceneRight = (sceneRight - offset) * currentScale;
|
2016-08-08 22:17:56 +03:00
|
|
|
m_indicator.push_back(QPointF(sceneRight - size, vcenter - size));
|
2016-08-06 14:50:31 +03:00
|
|
|
m_indicator.push_back(QPointF(sceneRight, vcenter));
|
2016-08-08 22:17:56 +03:00
|
|
|
m_indicator.push_back(QPointF(sceneRight - size, vcenter + size));
|
2016-08-06 14:50:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sceneLeft = (sceneLeft - offset) * currentScale;
|
2016-08-08 22:17:56 +03:00
|
|
|
m_indicator.push_back(QPointF(sceneLeft + size, vcenter - size));
|
2016-08-06 14:50:31 +03:00
|
|
|
m_indicator.push_back(QPointF(sceneLeft, vcenter));
|
2016-08-08 22:17:56 +03:00
|
|
|
m_indicator.push_back(QPointF(sceneLeft + size, vcenter + size));
|
2016-08-06 14:50:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_painter->save();
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(-x(), -y()), true);
|
2016-08-18 23:26:41 +03:00
|
|
|
_painter->setBrush(m_bHoverIndicator ? QColor::fromRgb(0xffff0000) : color);
|
2016-08-08 22:17:56 +03:00
|
|
|
_painter->setPen(pen);
|
2016-08-06 14:50:31 +03:00
|
|
|
_painter->drawPolygon(m_indicator);
|
|
|
|
_painter->restore();
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
auto selectedInterval = width();
|
2016-08-01 22:21:59 +03:00
|
|
|
QRectF rect((m_left - offset) * currentScale, visibleSceneRect.top(), ::std::max(selectedInterval * currentScale, 1.0), visibleSceneRect.height());
|
2016-08-10 22:08:27 +03:00
|
|
|
selectedInterval = units2microseconds(selectedInterval);
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
const QString text = ::profiler_gui::timeStringReal(selectedInterval); // Displayed text
|
2016-08-21 14:26:04 +03:00
|
|
|
const auto textRect = QFontMetricsF(CHRONOMETER_FONT).boundingRect(text); // Calculate displayed text boundingRect
|
2016-08-10 22:08:27 +03:00
|
|
|
const auto rgb = m_color.rgb() & 0x00ffffff;
|
|
|
|
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Paint!--------------------------
|
2016-07-31 18:48:41 +03:00
|
|
|
_painter->save();
|
2016-06-30 03:45:11 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// instead of scrollbar we're using manual offset
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(-x(), -y()), true);
|
|
|
|
|
|
|
|
// draw transparent rectangle
|
2016-08-21 14:26:04 +03:00
|
|
|
auto vcenter = rect.top() + rect.height() * 0.5;
|
|
|
|
QLinearGradient g(rect.left(), vcenter, rect.right(), vcenter);
|
|
|
|
g.setColorAt(0, m_color);
|
|
|
|
g.setColorAt(0.15, QColor::fromRgba(0x14000000 | rgb));
|
|
|
|
g.setColorAt(0.85, QColor::fromRgba(0x14000000 | rgb));
|
|
|
|
g.setColorAt(1, m_color);
|
|
|
|
_painter->setBrush(g);
|
2016-07-31 18:48:41 +03:00
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
_painter->drawRect(rect);
|
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
// draw left and right borders
|
|
|
|
_painter->setBrush(Qt::NoBrush);
|
2016-08-21 14:26:04 +03:00
|
|
|
_painter->setPen(QColor::fromRgba(0xd0000000 | rgb));
|
2016-08-10 22:08:27 +03:00
|
|
|
if (m_left > sceneLeft)
|
|
|
|
_painter->drawLine(QPointF(rect.left(), rect.top()), QPointF(rect.left(), rect.bottom()));
|
|
|
|
if (m_right < sceneRight)
|
|
|
|
_painter->drawLine(QPointF(rect.right(), rect.top()), QPointF(rect.right(), rect.bottom()));
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// draw text
|
2016-08-07 19:38:31 +03:00
|
|
|
_painter->setCompositionMode(QPainter::CompositionMode_Difference); // This lets the text to be visible on every background
|
2016-08-10 22:08:27 +03:00
|
|
|
_painter->setPen(0xffffffff - rgb);
|
2016-08-18 23:26:41 +03:00
|
|
|
_painter->setFont(CHRONOMETER_FONT);
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-08-02 22:24:22 +03:00
|
|
|
if (m_left < sceneLeft)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-08-02 22:24:22 +03:00
|
|
|
rect.setLeft(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_right > sceneRight)
|
|
|
|
{
|
|
|
|
rect.setWidth((sceneRight - offset) * currentScale - rect.left());
|
|
|
|
}
|
|
|
|
|
2016-08-06 14:50:31 +03:00
|
|
|
if (!m_bMain)
|
|
|
|
{
|
2016-08-07 19:38:31 +03:00
|
|
|
rect.setTop(rect.top() + textRect.height() * 1.5);
|
2016-08-06 14:50:31 +03:00
|
|
|
}
|
|
|
|
|
2016-08-02 22:24:22 +03:00
|
|
|
if (textRect.width() < rect.width())
|
|
|
|
{
|
|
|
|
// Text will be drawed inside rectangle
|
|
|
|
_painter->drawText(rect, Qt::AlignCenter, text);
|
|
|
|
_painter->restore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (m_right + textRect.width() < sceneRight)
|
2016-08-02 22:24:22 +03:00
|
|
|
{
|
|
|
|
// Text will be drawed to the right of rectangle
|
|
|
|
_painter->drawText(QPointF(rect.right(), rect.top() + rect.height() * 0.5 + textRect.height() * 0.33), text);
|
|
|
|
}
|
2016-08-18 23:26:41 +03:00
|
|
|
else if (m_left - textRect.width() > sceneLeft)
|
2016-08-02 22:24:22 +03:00
|
|
|
{
|
|
|
|
// Text will be drawed to the left of rectangle
|
|
|
|
_painter->drawText(QPointF(rect.left() - textRect.width(), rect.top() + rect.height() * 0.5 + textRect.height() * 0.33), text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Text will be drawed inside rectangle
|
|
|
|
_painter->drawText(rect, Qt::AlignCenter | Qt::TextDontClip, text);
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_painter->restore();
|
2016-08-01 22:21:59 +03:00
|
|
|
// END Paint!~~~~~~~~~~~~~~~~~~~~~~
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
bool EasyChronometerItem::contains(const QPointF& _pos) const
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
const auto sceneView = view();
|
|
|
|
const auto clickX = (_pos.x() - sceneView->offset()) * sceneView->scale() - x();
|
|
|
|
if (!m_indicator.empty() && m_indicator.containsPoint(QPointF(clickX, _pos.y()), Qt::OddEvenFill))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::setColor(const QColor& _color)
|
2016-08-06 14:50:31 +03:00
|
|
|
{
|
|
|
|
m_color = _color;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
m_boundingRect.setRect(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::setBoundingRect(const QRectF& _rect)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
m_boundingRect = _rect;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::setLeftRight(qreal _left, qreal _right)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
if (_left < _right)
|
|
|
|
{
|
|
|
|
m_left = _left;
|
|
|
|
m_right = _right;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_left = _right;
|
|
|
|
m_right = _left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::setReverse(bool _reverse)
|
2016-08-06 14:50:31 +03:00
|
|
|
{
|
|
|
|
m_bReverse = _reverse;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyChronometerItem::setHover(bool _hover)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
m_bHoverIndicator = _hover;
|
2016-08-08 22:17:56 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const EasyGraphicsView* EasyChronometerItem::view() const
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
return static_cast<const EasyGraphicsView*>(scene()->parent());
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyBackgroundItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
const auto sceneView = static_cast<const EasyGraphicsView*>(scene()->parent());
|
2016-08-10 22:08:27 +03:00
|
|
|
const auto visibleSceneRect = sceneView->visibleSceneRect();
|
|
|
|
const auto currentScale = sceneView->scale();
|
|
|
|
const auto offset = sceneView->offset();
|
|
|
|
const auto left = offset * currentScale;
|
2016-08-21 14:26:04 +03:00
|
|
|
const auto h = visibleSceneRect.height();
|
2016-08-10 22:08:27 +03:00
|
|
|
|
|
|
|
QRectF rect;
|
|
|
|
|
|
|
|
_painter->save();
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(-x(), -y()));
|
2016-08-21 14:26:04 +03:00
|
|
|
_painter->setClipRect(QRectF(0, 0, visibleSceneRect.width(), h));
|
2016-08-10 22:08:27 +03:00
|
|
|
|
|
|
|
const auto& items = sceneView->getItems();
|
|
|
|
if (!items.empty())
|
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
static const auto OVERLAP = THREADS_ROW_SPACING >> 1;
|
2016-08-10 22:08:27 +03:00
|
|
|
static const QBrush brushes[2] = {QColor::fromRgb(BACKGROUND_1), QColor::fromRgb(BACKGROUND_2)};
|
|
|
|
const bool isTest = (items.front()->items(0).front().block == nullptr);
|
|
|
|
int i = -1;
|
|
|
|
|
|
|
|
// Draw background
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
for (auto item : items)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
|
|
|
|
auto br = item->boundingRect();
|
|
|
|
auto top = item->y() + br.top() - visibleSceneRect.top();
|
|
|
|
auto bottom = top + br.height();
|
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
if (top > h || bottom < 0)
|
2016-08-10 22:08:27 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isTest && item->threadId() == ::profiler_gui::EASY_GLOBALS.selected_thread)
|
|
|
|
{
|
|
|
|
_painter->setBrush(QBrush(QColor::fromRgb(::profiler_gui::SELECTED_THREAD_BACKGROUND)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_painter->setBrush(brushes[i & 1]);
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
rect.setRect(0, top - OVERLAP, visibleSceneRect.width(), br.height() + THREADS_ROW_SPACING);
|
2016-08-10 22:08:27 +03:00
|
|
|
_painter->drawRect(rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw timeline scale marks ----------------
|
|
|
|
_painter->setBrush(QColor::fromRgba(TIMELINE_BACKGROUND));
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
const auto sceneStep = sceneView->timelineStep();
|
|
|
|
const auto factor = ::profiler_gui::timeFactor(sceneStep);
|
|
|
|
const auto step = sceneStep * currentScale;
|
|
|
|
auto first = static_cast<quint64>(offset / sceneStep);
|
|
|
|
const int odd = first & 1;
|
|
|
|
const auto nsteps = (1 + odd) * 2 + static_cast<int>(visibleSceneRect.width() / step);
|
|
|
|
first -= odd;
|
|
|
|
|
|
|
|
QPen pen(Qt::gray);
|
|
|
|
pen.setWidth(2);
|
|
|
|
_painter->setClipping(false);
|
|
|
|
_painter->setPen(pen);
|
|
|
|
_painter->drawLine(QPointF(0, h), QPointF(visibleSceneRect.width(), h));
|
|
|
|
_painter->setPen(Qt::gray);
|
|
|
|
|
|
|
|
QLineF marks[20];
|
|
|
|
qreal first_x = first * sceneStep;
|
|
|
|
const auto textWidth = QFontMetricsF(_painter->font()).boundingRect(QString::number(static_cast<quint64>(0.5 + first_x * factor))).width() + 10;
|
|
|
|
const int n = 1 + static_cast<int>(textWidth / step);
|
|
|
|
int next = first % n;
|
|
|
|
if (next)
|
|
|
|
next = n - next;
|
|
|
|
|
|
|
|
first_x *= currentScale;
|
|
|
|
for (int i = 0; i < nsteps; ++i, --next)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-08-21 14:26:04 +03:00
|
|
|
auto current = first_x - left + step * i;
|
|
|
|
|
|
|
|
if ((i & 1) == 0)
|
|
|
|
{
|
|
|
|
rect.setRect(current, 0, step, h);
|
|
|
|
_painter->drawRect(rect);
|
|
|
|
|
|
|
|
for (int j = 0; j < 20; ++j)
|
|
|
|
{
|
|
|
|
auto xmark = current + j * step * 0.1;
|
|
|
|
marks[j].setP1(QPointF(xmark, h));
|
|
|
|
marks[j].setP2(QPointF(xmark, h + ((j % 5) ? 4 : 8)));
|
|
|
|
}
|
|
|
|
|
|
|
|
_painter->drawLines(marks, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next <= 0)
|
|
|
|
{
|
|
|
|
next = n;
|
|
|
|
_painter->setPen(Qt::black);
|
|
|
|
_painter->drawText(QPointF(current + 1, h + 17), QString::number(static_cast<quint64>(0.5 + (current + left) * factor / currentScale)));
|
|
|
|
_painter->setPen(Qt::gray);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TEST
|
|
|
|
// this is for testing (order of lines will be painted):
|
|
|
|
//_painter->setPen(Qt::black);
|
|
|
|
//_painter->drawText(QPointF(current + step * 0.4, h - 20), QString::number(i));
|
|
|
|
//_painter->setPen(Qt::gray);
|
|
|
|
// TEST
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
2016-08-10 22:08:27 +03:00
|
|
|
// END Draw timeline scale marks ~~~~~~~~~~~~
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
_painter->restore();
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyTimelineIndicatorItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem* _option, QWidget* _widget)
|
2016-08-10 22:08:27 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
const auto sceneView = static_cast<const EasyGraphicsView*>(scene()->parent());
|
2016-08-10 22:08:27 +03:00
|
|
|
const auto visibleSceneRect = sceneView->visibleSceneRect();
|
|
|
|
const auto step = sceneView->timelineStep() * sceneView->scale();
|
|
|
|
const QString text = ::profiler_gui::timeStringInt(units2microseconds(sceneView->timelineStep())); // Displayed text
|
|
|
|
|
|
|
|
// Draw scale indicator
|
|
|
|
_painter->save();
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(-x(), -y()));
|
|
|
|
_painter->setCompositionMode(QPainter::CompositionMode_Difference);
|
|
|
|
_painter->setBrush(Qt::white);
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
QRectF rect(visibleSceneRect.width() - 10 - step, visibleSceneRect.height() - 20, step, 5);
|
2016-08-10 22:08:27 +03:00
|
|
|
_painter->drawRect(rect);
|
|
|
|
|
|
|
|
rect.translate(0, 5);
|
|
|
|
_painter->setPen(Qt::white);
|
|
|
|
_painter->drawText(rect, Qt::AlignRight | Qt::TextDontClip, text);
|
|
|
|
|
|
|
|
_painter->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsView::EasyGraphicsView(QWidget* _parent)
|
2016-08-10 22:08:27 +03:00
|
|
|
: QGraphicsView(_parent)
|
2016-08-11 23:43:34 +03:00
|
|
|
, m_beginTime(::std::numeric_limits<decltype(m_beginTime)>::max())
|
2016-07-31 18:48:41 +03:00
|
|
|
, m_scale(1)
|
|
|
|
, m_offset(0)
|
|
|
|
, m_mouseButtons(Qt::NoButton)
|
|
|
|
, m_pScrollbar(nullptr)
|
|
|
|
, m_chronometerItem(nullptr)
|
2016-08-06 14:50:31 +03:00
|
|
|
, m_chronometerItemAux(nullptr)
|
|
|
|
, m_flickerSpeedX(0)
|
|
|
|
, m_flickerSpeedY(0)
|
|
|
|
, m_bDoubleClick(false)
|
2016-07-31 18:48:41 +03:00
|
|
|
, m_bUpdatingRect(false)
|
2016-08-18 23:26:41 +03:00
|
|
|
//, m_bTest(false)
|
2016-07-31 18:48:41 +03:00
|
|
|
, m_bEmpty(true)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
initMode();
|
|
|
|
setScene(new QGraphicsScene(this));
|
|
|
|
updateVisibleSceneRect();
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsView::~EasyGraphicsView()
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyChronometerItem* EasyGraphicsView::createChronometer(bool _main)
|
2016-08-06 14:50:31 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
auto chronoItem = new EasyChronometerItem(_main);
|
2016-08-06 14:50:31 +03:00
|
|
|
chronoItem->setColor(_main ? CHRONOMETER_COLOR : CHRONOMETER_COLOR2);
|
|
|
|
chronoItem->setBoundingRect(scene()->sceneRect());
|
|
|
|
chronoItem->hide();
|
|
|
|
scene()->addItem(chronoItem);
|
|
|
|
|
|
|
|
return chronoItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
/*void EasyGraphicsView::fillTestChildren(EasyGraphicsItem* _item, const int _maxlevel, int _level, qreal _x, unsigned int _childrenNumber, unsigned int& _total_items)
|
2016-06-30 03:45:11 +03:00
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
unsigned int nchildren = _childrenNumber;
|
2016-08-01 22:21:59 +03:00
|
|
|
_childrenNumber = TEST_PROGRESSION_BASE;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-04 22:38:45 +03:00
|
|
|
for (unsigned int i = 0; i < nchildren; ++i)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
auto j = _item->addItem(_level);
|
2016-07-10 01:24:31 +03:00
|
|
|
auto& b = _item->getItem(_level, j);
|
2016-08-03 23:00:04 +03:00
|
|
|
b.color = ::profiler_gui::toRgb(30 + rand() % 225, 30 + rand() % 225, 30 + rand() % 225);
|
2016-07-27 21:50:11 +03:00
|
|
|
b.state = 0;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
if (_level < _maxlevel)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
|
|
|
const auto& children = _item->items(_level + 1);
|
|
|
|
b.children_begin = static_cast<unsigned int>(children.size());
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
fillTestChildren(_item, _maxlevel, _level + 1, _x, _childrenNumber, _total_items);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
|
|
|
const auto& last = children.back();
|
2016-08-11 23:43:34 +03:00
|
|
|
b.setPos(_x, last.right() - _x);
|
2016-07-27 21:50:11 +03:00
|
|
|
b.totalHeight = GRAPHICS_ROW_SIZE_FULL + last.totalHeight;
|
2016-07-10 01:24:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
b.setPos(_x, units2microseconds(10 + rand() % 190));
|
2016-07-10 01:24:31 +03:00
|
|
|
b.totalHeight = GRAPHICS_ROW_SIZE;
|
2016-08-11 23:43:34 +03:00
|
|
|
::profiler_gui::set_max(b.children_begin);
|
2016-07-10 01:24:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_x = b.right();
|
|
|
|
++_total_items;
|
|
|
|
}
|
2016-06-30 03:45:11 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::test(unsigned int _frames_number, unsigned int _total_items_number_estimate, unsigned char _rows)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
2016-07-27 21:50:11 +03:00
|
|
|
static const qreal X_BEGIN = 50;
|
|
|
|
static const qreal Y_BEGIN = 0;
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
clearSilent(); // Clear scene
|
|
|
|
|
|
|
|
// Calculate items number for first level
|
2016-08-11 23:43:34 +03:00
|
|
|
_rows = ::std::max((unsigned char)1, _rows);
|
2016-08-04 22:38:45 +03:00
|
|
|
const auto children_per_frame = static_cast<unsigned int>(0.5 + static_cast<double>(_total_items_number_estimate) / static_cast<double>(_rows * _frames_number));
|
2016-08-11 23:43:34 +03:00
|
|
|
const unsigned char max_depth = ::std::min(254, static_cast<int>(logn<TEST_PROGRESSION_BASE>(children_per_frame * (TEST_PROGRESSION_BASE - 1) * 0.5 + 1)));
|
2016-08-04 22:38:45 +03:00
|
|
|
const auto first_level_children_count = static_cast<unsigned int>(static_cast<double>(children_per_frame) * (1.0 - TEST_PROGRESSION_BASE) / (1.0 - pow(TEST_PROGRESSION_BASE, max_depth)) + 0.5);
|
2016-08-01 22:21:59 +03:00
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
auto bgItem = new EasyBackgroundItem();
|
2016-08-10 22:08:27 +03:00
|
|
|
scene()->addItem(bgItem);
|
|
|
|
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
::std::vector<EasyGraphicsItem*> thread_items(_rows);
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned char i = 0; i < _rows; ++i)
|
2016-08-01 22:21:59 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
auto item = new EasyGraphicsItem(i, true);
|
2016-08-01 22:21:59 +03:00
|
|
|
thread_items[i] = item;
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
item->setPos(0, Y_BEGIN + i * (max_depth * GRAPHICS_ROW_SIZE_FULL + THREADS_ROW_SPACING * 5));
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
item->setLevels(max_depth + 1);
|
|
|
|
item->reserve(0, _frames_number);
|
|
|
|
}
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Calculate items number for each sublevel
|
2016-08-04 22:38:45 +03:00
|
|
|
auto chldrn = first_level_children_count;
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned char i = 1; i <= max_depth; ++i)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned char j = 0; j < _rows; ++j)
|
2016-08-01 22:21:59 +03:00
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
auto item = thread_items[j];
|
2016-08-01 22:21:59 +03:00
|
|
|
item->reserve(i, chldrn * _frames_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
chldrn *= TEST_PROGRESSION_BASE;
|
2016-07-10 01:24:31 +03:00
|
|
|
}
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Create required number of items
|
2016-08-04 22:38:45 +03:00
|
|
|
unsigned int total_items = 0;
|
2016-08-01 22:21:59 +03:00
|
|
|
qreal maxX = 0;
|
2016-08-18 23:26:41 +03:00
|
|
|
const EasyGraphicsItem* longestItem = nullptr;
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned char i = 0; i < _rows; ++i)
|
2016-07-10 01:24:31 +03:00
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
auto item = thread_items[i];
|
|
|
|
qreal x = X_BEGIN, y = item->y();
|
2016-08-11 23:43:34 +03:00
|
|
|
for (unsigned int f = 0; f < _frames_number; ++f)
|
2016-08-01 22:21:59 +03:00
|
|
|
{
|
2016-08-04 22:38:45 +03:00
|
|
|
auto j = item->addItem(0);
|
2016-08-01 22:21:59 +03:00
|
|
|
auto& b = item->getItem(0, j);
|
2016-08-03 23:00:04 +03:00
|
|
|
b.color = ::profiler_gui::toRgb(30 + rand() % 225, 30 + rand() % 225, 30 + rand() % 225);
|
2016-08-01 22:21:59 +03:00
|
|
|
b.state = 0;
|
|
|
|
|
|
|
|
const auto& children = item->items(1);
|
|
|
|
b.children_begin = static_cast<unsigned int>(children.size());
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
fillTestChildren(item, max_depth, 1, x, first_level_children_count, total_items);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
const auto& last = children.back();
|
2016-08-11 23:43:34 +03:00
|
|
|
b.setPos(x, last.right() - x);
|
2016-08-01 22:21:59 +03:00
|
|
|
b.totalHeight = GRAPHICS_ROW_SIZE_FULL + last.totalHeight;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
x += b.width() * 1.2;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
++total_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto h = item->getItem(0, 0).totalHeight;
|
|
|
|
item->setBoundingRect(0, 0, x, h);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
m_items.push_back(item);
|
|
|
|
scene()->addItem(item);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
if (maxX < x)
|
|
|
|
{
|
|
|
|
maxX = x;
|
2016-08-03 00:06:36 +03:00
|
|
|
longestItem = item;
|
2016-08-01 22:21:59 +03:00
|
|
|
}
|
2016-07-10 01:24:31 +03:00
|
|
|
}
|
|
|
|
|
2016-08-04 22:38:45 +03:00
|
|
|
printf("TOTAL ITEMS = %u\n", total_items);
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Calculate scene rect
|
|
|
|
auto item = thread_items.back();
|
|
|
|
scene()->setSceneRect(0, 0, maxX, item->y() + item->getItem(0, 0).totalHeight);
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Reset necessary values
|
2016-07-31 18:48:41 +03:00
|
|
|
m_offset = 0;
|
|
|
|
updateVisibleSceneRect();
|
|
|
|
setScrollbar(m_pScrollbar);
|
2016-08-08 22:17:56 +03:00
|
|
|
|
|
|
|
if (longestItem != nullptr)
|
|
|
|
{
|
|
|
|
m_pScrollbar->setMinimapFrom(0, longestItem->items(0));
|
|
|
|
::profiler_gui::EASY_GLOBALS.selected_thread = 0;
|
|
|
|
emit::profiler_gui::EASY_GLOBALS.events.selectedThreadChanged(0);
|
|
|
|
}
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Create new chronometer item (previous item was destroyed by scene on scene()->clear()).
|
|
|
|
// It will be shown on mouse right button click.
|
2016-08-06 14:50:31 +03:00
|
|
|
m_chronometerItemAux = createChronometer(false);
|
2016-08-10 22:08:27 +03:00
|
|
|
m_chronometerItem = createChronometer(true);
|
|
|
|
|
|
|
|
bgItem->setBoundingRect(scene()->sceneRect());
|
2016-08-18 23:26:41 +03:00
|
|
|
auto indicator = new EasyTimelineIndicatorItem();
|
2016-08-10 22:08:27 +03:00
|
|
|
indicator->setBoundingRect(scene()->sceneRect());
|
|
|
|
scene()->addItem(indicator);
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Set necessary flags
|
2016-07-31 18:48:41 +03:00
|
|
|
m_bTest = true;
|
|
|
|
m_bEmpty = false;
|
2016-08-01 22:21:59 +03:00
|
|
|
|
|
|
|
scaleTo(BASE_SCALE);
|
2016-08-18 23:26:41 +03:00
|
|
|
}*/
|
2016-07-10 01:24:31 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::clearSilent()
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
const QSignalBlocker blocker(this), sceneBlocker(scene()); // block all scene signals (otherwise clear() would be extremely slow!)
|
2016-08-01 22:21:59 +03:00
|
|
|
|
|
|
|
// Stop flicking
|
2016-07-31 18:48:41 +03:00
|
|
|
m_flickerTimer.stop();
|
2016-08-06 14:50:31 +03:00
|
|
|
m_flickerSpeedX = 0;
|
|
|
|
m_flickerSpeedY = 0;
|
2016-08-01 22:21:59 +03:00
|
|
|
|
|
|
|
// Clear all items
|
2016-07-31 18:48:41 +03:00
|
|
|
scene()->clear();
|
|
|
|
m_items.clear();
|
|
|
|
m_selectedBlocks.clear();
|
2016-08-01 22:21:59 +03:00
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
m_beginTime = ::std::numeric_limits<decltype(m_beginTime)>::max(); // reset begin time
|
2016-07-31 18:48:41 +03:00
|
|
|
m_scale = 1; // scale back to initial 100% scale
|
2016-08-10 22:08:27 +03:00
|
|
|
m_timelineStep = 1;
|
2016-08-01 22:21:59 +03:00
|
|
|
m_offset = 0; // scroll back to the beginning of the scene
|
|
|
|
|
|
|
|
// Reset necessary flags
|
2016-08-18 23:26:41 +03:00
|
|
|
//m_bTest = false;
|
2016-07-31 18:48:41 +03:00
|
|
|
m_bEmpty = true;
|
2016-08-01 22:21:59 +03:00
|
|
|
|
|
|
|
// notify ProfTreeWidget that selection was reset
|
|
|
|
emit intervalChanged(m_selectedBlocks, m_beginTime, 0, 0, false);
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::setTree(const ::profiler::thread_blocks_tree_t& _blocksTree)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
// clear scene
|
2016-08-08 22:45:57 +03:00
|
|
|
clearSilent();
|
|
|
|
|
|
|
|
if (_blocksTree.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
auto bgItem = new EasyBackgroundItem();
|
2016-08-10 22:08:27 +03:00
|
|
|
scene()->addItem(bgItem);
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
// set new blocks tree
|
2016-06-30 02:57:57 +03:00
|
|
|
// calculate scene size and fill it with items
|
2016-07-31 18:48:41 +03:00
|
|
|
|
|
|
|
// Calculating start and end time
|
2016-06-27 23:22:12 +03:00
|
|
|
::profiler::timestamp_t finish = 0;
|
2016-08-03 23:00:04 +03:00
|
|
|
const ::profiler::BlocksTree* longestTree = nullptr;
|
2016-08-18 23:26:41 +03:00
|
|
|
const EasyGraphicsItem* longestItem = nullptr;
|
2016-06-26 18:46:51 +03:00
|
|
|
for (const auto& threadTree : _blocksTree)
|
|
|
|
{
|
2016-08-03 23:00:04 +03:00
|
|
|
const auto& tree = threadTree.second.tree;
|
|
|
|
const auto timestart = tree.children.front().node->block()->getBegin();
|
|
|
|
const auto timefinish = tree.children.back().node->block()->getEnd();
|
2016-06-27 23:22:12 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_beginTime > timestart)
|
|
|
|
{
|
|
|
|
m_beginTime = timestart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (finish < timefinish)
|
|
|
|
{
|
|
|
|
finish = timefinish;
|
2016-08-03 23:00:04 +03:00
|
|
|
longestTree = &tree;
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filling scene with items
|
|
|
|
m_items.reserve(_blocksTree.size());
|
2016-08-21 14:26:04 +03:00
|
|
|
qreal y = TIMELINE_ROW_SIZE;
|
2016-07-31 18:48:41 +03:00
|
|
|
for (const auto& threadTree : _blocksTree)
|
|
|
|
{
|
2016-06-30 02:57:57 +03:00
|
|
|
// fill scene with new items
|
2016-08-03 23:00:04 +03:00
|
|
|
const auto& tree = threadTree.second.tree;
|
|
|
|
qreal h = 0, x = time2position(tree.children.front().node->block()->getBegin());
|
2016-08-18 23:26:41 +03:00
|
|
|
auto item = new EasyGraphicsItem(static_cast<unsigned char>(m_items.size()), &threadTree.second);
|
2016-08-03 23:00:04 +03:00
|
|
|
item->setLevels(tree.depth);
|
2016-07-31 13:13:48 +03:00
|
|
|
item->setPos(0, y);
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
const auto children_duration = setTree(item, tree.children, h, y, 0);
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
item->setBoundingRect(0, 0, children_duration + x, h);
|
2016-07-31 18:48:41 +03:00
|
|
|
m_items.push_back(item);
|
|
|
|
scene()->addItem(item);
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
y += h + THREADS_ROW_SPACING;
|
2016-08-03 00:06:36 +03:00
|
|
|
|
2016-08-03 23:00:04 +03:00
|
|
|
if (longestTree == &tree)
|
2016-08-03 00:06:36 +03:00
|
|
|
{
|
|
|
|
longestItem = item;
|
|
|
|
}
|
2016-08-11 23:43:34 +03:00
|
|
|
|
|
|
|
if (m_items.size() == 0xff)
|
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
qWarning() << "Maximum threads number (255 threads) exceeded! See EasyGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__;
|
2016-08-11 23:43:34 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
// Calculating scene rect
|
2016-08-07 19:38:31 +03:00
|
|
|
const qreal endX = time2position(finish) + 1500.0;
|
2016-08-21 14:26:04 +03:00
|
|
|
scene()->setSceneRect(0, 0, endX, y + TIMELINE_ROW_SIZE);
|
2016-08-10 22:08:27 +03:00
|
|
|
//for (auto item : m_items)
|
|
|
|
// item->setBoundingRect(0, 0, endX, item->boundingRect().height());
|
2016-07-31 18:48:41 +03:00
|
|
|
|
|
|
|
// Center view on the beginning of the scene
|
2016-08-08 22:45:57 +03:00
|
|
|
updateVisibleSceneRect();
|
2016-07-31 18:48:41 +03:00
|
|
|
setScrollbar(m_pScrollbar);
|
2016-08-08 22:17:56 +03:00
|
|
|
|
|
|
|
if (longestItem != nullptr)
|
|
|
|
{
|
|
|
|
m_pScrollbar->setMinimapFrom(longestItem->threadId(), longestItem->items(0));
|
|
|
|
::profiler_gui::EASY_GLOBALS.selected_thread = longestItem->threadId();
|
|
|
|
emit::profiler_gui::EASY_GLOBALS.events.selectedThreadChanged(longestItem->threadId());
|
|
|
|
}
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Create new chronometer item (previous item was destroyed by scene on scene()->clear()).
|
|
|
|
// It will be shown on mouse right button click.
|
2016-08-06 14:50:31 +03:00
|
|
|
m_chronometerItemAux = createChronometer(false);
|
2016-08-10 22:08:27 +03:00
|
|
|
m_chronometerItem = createChronometer(true);
|
|
|
|
|
|
|
|
bgItem->setBoundingRect(0, 0, endX, y);
|
2016-08-18 23:26:41 +03:00
|
|
|
auto indicator = new EasyTimelineIndicatorItem();
|
2016-08-10 22:08:27 +03:00
|
|
|
indicator->setBoundingRect(0, 0, endX, y);
|
|
|
|
scene()->addItem(indicator);
|
2016-07-31 18:48:41 +03:00
|
|
|
|
|
|
|
// Setting flags
|
2016-08-18 23:26:41 +03:00
|
|
|
//m_bTest = false;
|
2016-07-31 18:48:41 +03:00
|
|
|
m_bEmpty = false;
|
2016-08-01 22:21:59 +03:00
|
|
|
|
|
|
|
scaleTo(BASE_SCALE);
|
2016-06-27 23:22:12 +03:00
|
|
|
}
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
const EasyGraphicsView::Items &EasyGraphicsView::getItems() const
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
|
|
|
return m_items;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, qreal _y, short _level)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
static const qreal MIN_DURATION = 0.25;
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
if (_children.empty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
const auto level = static_cast<unsigned char>(_level);
|
|
|
|
_item->reserve(level, static_cast<unsigned int>(_children.size()));
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
const short next_level = _level + 1;
|
|
|
|
bool warned = false;
|
2016-06-30 02:57:57 +03:00
|
|
|
qreal total_duration = 0, prev_end = 0, maxh = 0;
|
2016-07-31 13:13:48 +03:00
|
|
|
qreal start_time = -1;
|
2016-06-30 02:57:57 +03:00
|
|
|
for (const auto& child : _children)
|
|
|
|
{
|
2016-07-31 13:13:48 +03:00
|
|
|
auto xbegin = time2position(child.node->block()->getBegin());
|
|
|
|
if (start_time < 0)
|
|
|
|
{
|
|
|
|
start_time = xbegin;
|
|
|
|
}
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
auto duration = time2position(child.node->block()->getEnd()) - xbegin;
|
|
|
|
|
|
|
|
const auto dt = xbegin - prev_end;
|
2016-06-30 02:57:57 +03:00
|
|
|
if (dt < 0)
|
|
|
|
{
|
|
|
|
duration += dt;
|
|
|
|
xbegin -= dt;
|
|
|
|
}
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
if (duration < MIN_DURATION)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-08-01 22:21:59 +03:00
|
|
|
duration = MIN_DURATION;
|
2016-06-30 02:57:57 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
auto i = _item->addItem(level);
|
|
|
|
auto& b = _item->getItem(level, i);
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-08-04 22:38:45 +03:00
|
|
|
auto& gui_block = ::profiler_gui::EASY_GLOBALS.gui_blocks[child.block_index];
|
2016-08-11 23:43:34 +03:00
|
|
|
gui_block.graphics_item = _item->index();
|
|
|
|
gui_block.graphics_item_level = level;
|
2016-08-04 22:38:45 +03:00
|
|
|
gui_block.graphics_item_index = i;
|
|
|
|
|
2016-08-11 23:43:34 +03:00
|
|
|
if (next_level < 256 && next_level < _item->levels() && !child.children.empty())
|
2016-07-27 21:50:11 +03:00
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
b.children_begin = static_cast<unsigned int>(_item->items(static_cast<unsigned char>(next_level)).size());
|
2016-07-27 21:50:11 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-11 23:43:34 +03:00
|
|
|
::profiler_gui::set_max(b.children_begin);
|
2016-07-27 21:50:11 +03:00
|
|
|
}
|
2016-06-30 02:57:57 +03:00
|
|
|
|
|
|
|
qreal h = 0;
|
2016-08-11 23:43:34 +03:00
|
|
|
qreal children_duration = 0;
|
|
|
|
|
|
|
|
if (next_level < 256)
|
|
|
|
{
|
|
|
|
children_duration = setTree(_item, child.children, h, _y + GRAPHICS_ROW_SIZE_FULL, next_level);
|
|
|
|
}
|
|
|
|
else if (!child.children.empty() && !warned)
|
|
|
|
{
|
|
|
|
warned = true;
|
2016-08-18 23:26:41 +03:00
|
|
|
qWarning() << "Maximum blocks depth (255) exceeded! See EasyGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__;
|
2016-08-11 23:43:34 +03:00
|
|
|
}
|
|
|
|
|
2016-06-27 23:22:12 +03:00
|
|
|
if (duration < children_duration)
|
|
|
|
{
|
|
|
|
duration = children_duration;
|
|
|
|
}
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
if (h > maxh)
|
|
|
|
{
|
|
|
|
maxh = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto color = child.node->block()->getColor();
|
|
|
|
b.block = &child;
|
2016-08-07 19:38:31 +03:00
|
|
|
b.color = ::profiler_gui::fromProfilerRgb(::profiler::colors::get_red(color), ::profiler::colors::get_green(color), ::profiler::colors::get_blue(color));
|
2016-08-11 23:43:34 +03:00
|
|
|
b.setPos(xbegin, duration);
|
2016-06-30 02:57:57 +03:00
|
|
|
b.totalHeight = GRAPHICS_ROW_SIZE + h;
|
2016-06-27 23:22:12 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
prev_end = xbegin + duration;
|
2016-07-31 13:13:48 +03:00
|
|
|
total_duration = prev_end - start_time;
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
2016-06-27 23:22:12 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
_height += GRAPHICS_ROW_SIZE_FULL + maxh;
|
|
|
|
|
2016-06-27 23:22:12 +03:00
|
|
|
return total_duration;
|
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-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-07-31 13:13:48 +03:00
|
|
|
if (m_pScrollbar)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
disconnect(m_pScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
m_pScrollbar = _scrollbar;
|
2016-08-03 23:00:04 +03:00
|
|
|
m_pScrollbar->setMinimapFrom(0, nullptr);
|
2016-08-03 00:06:36 +03:00
|
|
|
m_pScrollbar->hideChrono();
|
2016-07-31 13:13:48 +03:00
|
|
|
m_pScrollbar->setRange(0, scene()->width());
|
|
|
|
m_pScrollbar->setSliderWidth(m_visibleSceneRect.width());
|
|
|
|
m_pScrollbar->setValue(0);
|
2016-08-18 23:26:41 +03:00
|
|
|
connect(m_pScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
2016-08-03 23:00:04 +03:00
|
|
|
|
|
|
|
::profiler_gui::EASY_GLOBALS.selected_thread = 0;
|
|
|
|
emit ::profiler_gui::EASY_GLOBALS.events.selectedThreadChanged(0);
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::updateVisibleSceneRect()
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
m_visibleSceneRect = mapToScene(rect()).boundingRect();
|
2016-08-07 19:38:31 +03:00
|
|
|
|
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
if (vbar && vbar->isVisible())
|
|
|
|
m_visibleSceneRect.setWidth(m_visibleSceneRect.width() - vbar->width() - 2);
|
2016-08-21 14:26:04 +03:00
|
|
|
m_visibleSceneRect.setHeight(m_visibleSceneRect.height() - TIMELINE_ROW_SIZE);
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::updateTimelineStep(qreal _windowWidth)
|
2016-08-10 22:08:27 +03:00
|
|
|
{
|
|
|
|
const auto time = units2microseconds(_windowWidth);
|
|
|
|
if (time < 100)
|
|
|
|
m_timelineStep = 1e-2;
|
|
|
|
else if (time < 10e3)
|
|
|
|
m_timelineStep = 1;
|
|
|
|
else if (time < 10e6)
|
|
|
|
m_timelineStep = 1e3;
|
|
|
|
else
|
|
|
|
m_timelineStep = 1e6;
|
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
const auto optimal_steps = static_cast<int>(40 * m_visibleSceneRect.width() / 1500);
|
2016-08-10 22:08:27 +03:00
|
|
|
auto steps = time / m_timelineStep;
|
2016-08-21 14:26:04 +03:00
|
|
|
while (steps > optimal_steps) {
|
2016-08-10 22:08:27 +03:00
|
|
|
m_timelineStep *= 10;
|
|
|
|
steps *= 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_timelineStep = microseconds2units(m_timelineStep);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::updateScene()
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
scene()->update(m_visibleSceneRect);
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::scaleTo(qreal _scale)
|
2016-08-01 22:21:59 +03:00
|
|
|
{
|
|
|
|
if (m_bEmpty)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// have to limit scale because of Qt's QPainter feature: it doesn't draw text
|
|
|
|
// with very big coordinates (but it draw rectangles with the same coordinates good).
|
|
|
|
m_scale = clamp(MIN_SCALE, _scale, MAX_SCALE);
|
|
|
|
updateVisibleSceneRect();
|
|
|
|
|
|
|
|
// Update slider width for scrollbar
|
|
|
|
const auto windowWidth = m_visibleSceneRect.width() / m_scale;
|
|
|
|
m_pScrollbar->setSliderWidth(windowWidth);
|
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
updateTimelineStep(windowWidth);
|
2016-08-01 22:21:59 +03:00
|
|
|
updateScene();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::wheelEvent(QWheelEvent* _event)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_bEmpty)
|
|
|
|
{
|
|
|
|
_event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
const decltype(m_scale) scaleCoeff = _event->delta() > 0 ? SCALING_COEFFICIENT : SCALING_COEFFICIENT_INV;
|
|
|
|
|
|
|
|
// Remember current mouse position
|
|
|
|
const auto mouseX = mapToScene(_event->pos()).x();
|
|
|
|
const auto mousePosition = m_offset + mouseX / m_scale;
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// have to limit scale because of Qt's QPainter feature: it doesn't draw text
|
|
|
|
// with very big coordinates (but it draw rectangles with the same coordinates good).
|
|
|
|
m_scale = clamp(MIN_SCALE, m_scale * scaleCoeff, MAX_SCALE);
|
2016-06-26 20:54:16 +03:00
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
updateVisibleSceneRect(); // Update scene rect
|
2016-06-27 23:22:12 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
// Update slider width for scrollbar
|
|
|
|
const auto windowWidth = m_visibleSceneRect.width() / m_scale;
|
|
|
|
m_pScrollbar->setSliderWidth(windowWidth);
|
|
|
|
|
|
|
|
// Calculate new offset to simulate QGraphicsView::AnchorUnderMouse scaling behavior
|
|
|
|
m_offset = clamp(0., mousePosition - mouseX / m_scale, scene()->width() - windowWidth);
|
|
|
|
|
|
|
|
// Update slider position
|
2016-08-01 22:21:59 +03:00
|
|
|
m_bUpdatingRect = true; // To be sure that updateVisibleSceneRect will not be called by scrollbar change
|
2016-07-31 13:13:48 +03:00
|
|
|
m_pScrollbar->setValue(m_offset);
|
|
|
|
m_bUpdatingRect = false;
|
|
|
|
|
2016-08-10 22:08:27 +03:00
|
|
|
updateTimelineStep(windowWidth);
|
2016-07-31 13:13:48 +03:00
|
|
|
updateScene(); // repaint scene
|
2016-06-26 20:54:16 +03:00
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::mousePressEvent(QMouseEvent* _event)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_bEmpty)
|
|
|
|
{
|
|
|
|
_event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
m_mouseButtons = _event->buttons();
|
|
|
|
m_mousePressPos = _event->pos();
|
|
|
|
|
|
|
|
if (m_mouseButtons & Qt::RightButton)
|
|
|
|
{
|
|
|
|
const auto mouseX = m_offset + mapToScene(m_mousePressPos).x() / m_scale;
|
|
|
|
m_chronometerItem->setLeftRight(mouseX, mouseX);
|
|
|
|
m_chronometerItem->setReverse(false);
|
|
|
|
m_chronometerItem->hide();
|
|
|
|
m_pScrollbar->hideChrono();
|
|
|
|
}
|
|
|
|
|
|
|
|
_event->accept();
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::mouseDoubleClickEvent(QMouseEvent* _event)
|
2016-08-06 14:50:31 +03:00
|
|
|
{
|
|
|
|
if (m_bEmpty)
|
|
|
|
{
|
|
|
|
_event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mouseButtons = _event->buttons();
|
2016-08-08 22:17:56 +03:00
|
|
|
m_mousePressPos = _event->pos();
|
2016-08-06 14:50:31 +03:00
|
|
|
m_bDoubleClick = true;
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
const auto mouseX = m_offset + mapToScene(m_mousePressPos).x() / m_scale;
|
|
|
|
m_chronometerItemAux->setLeftRight(mouseX, mouseX);
|
|
|
|
m_chronometerItemAux->setReverse(false);
|
|
|
|
m_chronometerItemAux->hide();
|
2016-08-06 14:50:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::mouseReleaseEvent(QMouseEvent* _event)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_bEmpty)
|
|
|
|
{
|
|
|
|
_event->accept();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-08 22:45:57 +03:00
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
bool changedSelection = false, changedSelectedItem = false;
|
2016-08-08 22:45:57 +03:00
|
|
|
if (m_mouseButtons & Qt::RightButton)
|
|
|
|
{
|
|
|
|
if (m_chronometerItem->isVisible() && m_chronometerItem->width() < 1e-6)
|
|
|
|
{
|
|
|
|
m_chronometerItem->hide();
|
|
|
|
m_chronometerItem->setHover(false);
|
|
|
|
m_pScrollbar->hideChrono();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_selectedBlocks.empty())
|
|
|
|
{
|
|
|
|
changedSelection = true;
|
|
|
|
m_selectedBlocks.clear();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (m_chronometerItem->isVisible())
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
//printf("INTERVAL: {%lf, %lf} ms\n", m_chronometerItem->left(), m_chronometerItem->right());
|
|
|
|
|
|
|
|
for (auto item : m_items)
|
|
|
|
{
|
|
|
|
item->getBlocks(m_chronometerItem->left(), m_chronometerItem->right(), m_selectedBlocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_selectedBlocks.empty())
|
|
|
|
{
|
|
|
|
changedSelection = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
2016-08-21 14:26:04 +03:00
|
|
|
bool clicked = false;
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
if (m_chronometerItemAux->isVisible() && m_chronometerItemAux->width() < 1e-6)
|
|
|
|
{
|
|
|
|
m_chronometerItemAux->hide();
|
|
|
|
}
|
2016-08-18 23:26:41 +03:00
|
|
|
else if (m_chronometerItem->isVisible() && m_chronometerItem->hoverIndicator())
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
// Jump to selected zone
|
|
|
|
clicked = true;
|
|
|
|
m_flickerSpeedX = m_flickerSpeedY = 0;
|
|
|
|
m_pScrollbar->setValue(m_chronometerItem->left() + m_chronometerItem->width() * 0.5 - m_pScrollbar->sliderHalfWidth());
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
if (!clicked && m_mouseMovePath.manhattanLength() < 5)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
|
|
|
// Handle Click
|
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
//clicked = true;
|
2016-08-08 22:45:57 +03:00
|
|
|
auto mouseClickPos = mapToScene(m_mousePressPos);
|
|
|
|
mouseClickPos.setX(m_offset + mouseClickPos.x() / m_scale);
|
|
|
|
|
|
|
|
// Try to select one of item blocks
|
|
|
|
for (auto item : m_items)
|
|
|
|
{
|
|
|
|
auto block = item->intersect(mouseClickPos);
|
|
|
|
if (block)
|
|
|
|
{
|
|
|
|
changedSelectedItem = true;
|
|
|
|
::profiler_gui::EASY_GLOBALS.selected_block = block->block->block_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bDoubleClick = false;
|
|
|
|
m_mouseButtons = _event->buttons();
|
|
|
|
m_mouseMovePath = QPoint();
|
|
|
|
_event->accept();
|
|
|
|
|
|
|
|
if (changedSelection)
|
|
|
|
{
|
|
|
|
emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_chronometerItem->left()), position2time(m_chronometerItem->right()), m_chronometerItem->reverse());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_chronometerItem->setReverse(false);
|
|
|
|
|
|
|
|
if (changedSelectedItem)
|
|
|
|
{
|
|
|
|
m_bUpdatingRect = true;
|
|
|
|
emit ::profiler_gui::EASY_GLOBALS.events.selectedBlockChanged(::profiler_gui::EASY_GLOBALS.selected_block);
|
|
|
|
m_bUpdatingRect = false;
|
|
|
|
|
|
|
|
updateScene();
|
|
|
|
}
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
bool EasyGraphicsView::moveChrono(EasyChronometerItem* _chronometerItem, qreal _mouseX)
|
2016-08-06 14:50:31 +03:00
|
|
|
{
|
2016-08-08 22:45:57 +03:00
|
|
|
if (_chronometerItem->reverse())
|
|
|
|
{
|
|
|
|
if (_mouseX > _chronometerItem->right())
|
|
|
|
{
|
|
|
|
_chronometerItem->setReverse(false);
|
|
|
|
_chronometerItem->setLeftRight(_chronometerItem->right(), _mouseX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_chronometerItem->setLeftRight(_mouseX, _chronometerItem->right());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_mouseX < _chronometerItem->left())
|
|
|
|
{
|
|
|
|
_chronometerItem->setReverse(true);
|
|
|
|
_chronometerItem->setLeftRight(_mouseX, _chronometerItem->left());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_chronometerItem->setLeftRight(_chronometerItem->left(), _mouseX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_chronometerItem->isVisible() && _chronometerItem->width() > 1e-6)
|
|
|
|
{
|
|
|
|
_chronometerItem->show();
|
|
|
|
return true;
|
2016-08-06 14:50:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::mouseMoveEvent(QMouseEvent* _event)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-08-08 22:17:56 +03:00
|
|
|
if (m_bEmpty || (m_mouseButtons == 0 && !m_chronometerItem->isVisible()))
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
|
|
|
_event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool needUpdate = false;
|
2016-08-08 22:45:57 +03:00
|
|
|
const auto pos = _event->pos();
|
|
|
|
const auto delta = pos - m_mousePressPos;
|
2016-08-08 22:17:56 +03:00
|
|
|
m_mousePressPos = pos;
|
|
|
|
|
|
|
|
if (m_mouseButtons != 0)
|
|
|
|
{
|
|
|
|
m_mouseMovePath.setX(m_mouseMovePath.x() + ::std::abs(delta.x()));
|
|
|
|
m_mouseMovePath.setY(m_mouseMovePath.y() + ::std::abs(delta.y()));
|
|
|
|
}
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
auto mouseScenePos = mapToScene(m_mousePressPos);
|
2016-08-08 22:17:56 +03:00
|
|
|
mouseScenePos.setX(m_offset + mouseScenePos.x() / m_scale);
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
if (m_mouseButtons & Qt::RightButton)
|
|
|
|
{
|
|
|
|
bool showItem = moveChrono(m_chronometerItem, mouseScenePos.x());
|
|
|
|
m_pScrollbar->setChronoPos(m_chronometerItem->left(), m_chronometerItem->right());
|
|
|
|
|
|
|
|
if (showItem)
|
|
|
|
{
|
|
|
|
m_pScrollbar->showChrono();
|
|
|
|
}
|
|
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
if (m_bDoubleClick)
|
|
|
|
{
|
|
|
|
moveChrono(m_chronometerItemAux, mouseScenePos.x());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
|
|
|
|
m_bUpdatingRect = true; // Block scrollbars from updating scene rect to make it possible to do it only once
|
|
|
|
vbar->setValue(vbar->value() - delta.y());
|
|
|
|
m_pScrollbar->setValue(m_pScrollbar->value() - delta.x() / m_scale);
|
|
|
|
m_bUpdatingRect = false;
|
|
|
|
// Seems like an ugly stub, but QSignalBlocker is also a bad decision
|
|
|
|
// because if scrollbar does not emit valueChanged signal then viewport does not move
|
|
|
|
|
|
|
|
updateVisibleSceneRect(); // Update scene visible rect only once
|
|
|
|
|
|
|
|
// Update flicker speed
|
|
|
|
m_flickerSpeedX += delta.x() >> 1;
|
|
|
|
m_flickerSpeedY += delta.y() >> 1;
|
|
|
|
if (!m_flickerTimer.isActive())
|
|
|
|
{
|
|
|
|
// If flicker timer is not started, then start it
|
|
|
|
m_flickerTimer.start(FLICKER_INTERVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_chronometerItem->isVisible())
|
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
auto prevValue = m_chronometerItem->hoverIndicator();
|
2016-08-08 22:45:57 +03:00
|
|
|
m_chronometerItem->setHover(m_chronometerItem->contains(mouseScenePos));
|
2016-08-18 23:26:41 +03:00
|
|
|
needUpdate = needUpdate || (prevValue != m_chronometerItem->hoverIndicator());
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (needUpdate)
|
|
|
|
{
|
|
|
|
updateScene(); // repaint scene
|
|
|
|
}
|
|
|
|
|
|
|
|
_event->accept();
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::resizeEvent(QResizeEvent* _event)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-08-07 20:16:15 +03:00
|
|
|
QGraphicsView::resizeEvent(_event);
|
2016-07-31 18:48:41 +03:00
|
|
|
updateVisibleSceneRect(); // Update scene visible rect only once
|
|
|
|
updateScene(); // repaint scene
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::initMode()
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-06-27 23:22:12 +03:00
|
|
|
// TODO: find mode with least number of bugs :)
|
|
|
|
// There are always some display bugs...
|
|
|
|
|
|
|
|
setCacheMode(QGraphicsView::CacheNone);
|
2016-06-26 20:54:16 +03:00
|
|
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
2016-07-10 01:24:31 +03:00
|
|
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
|
|
|
setOptimizationFlag(QGraphicsView::DontSavePainterState, true);
|
2016-06-27 23:22:12 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2016-06-30 02:57:57 +03:00
|
|
|
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &This::onScrollbarValueChange);
|
2016-07-27 22:52:13 +03:00
|
|
|
connect(&m_flickerTimer, &QTimer::timeout, this, &This::onFlickerTimeout);
|
2016-08-18 23:26:41 +03:00
|
|
|
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
|
|
|
|
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange);
|
|
|
|
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::itemsExpandStateChanged, this, &This::onItemsEspandStateChange);
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onScrollbarValueChange(int)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
if (!m_bUpdatingRect && !m_bEmpty)
|
2016-06-30 02:57:57 +03:00
|
|
|
updateVisibleSceneRect();
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onGraphicsScrollbarValueChange(qreal _value)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
if (!m_bEmpty)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-07-31 18:48:41 +03:00
|
|
|
m_offset = _value;
|
|
|
|
if (!m_bUpdatingRect)
|
|
|
|
{
|
|
|
|
updateVisibleSceneRect();
|
|
|
|
updateScene();
|
|
|
|
}
|
2016-07-31 13:13:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onFlickerTimeout()
|
2016-07-27 22:52:13 +03:00
|
|
|
{
|
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
// Fast slow-down and stop if mouse button is pressed, no flicking.
|
2016-08-06 14:50:31 +03:00
|
|
|
m_flickerSpeedX >>= 1;
|
|
|
|
m_flickerSpeedY >>= 1;
|
2016-07-27 22:52:13 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Flick when mouse button is not pressed
|
|
|
|
|
2016-08-06 14:50:31 +03:00
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
m_bUpdatingRect = true; // Block scrollbars from updating scene rect to make it possible to do it only once
|
|
|
|
m_pScrollbar->setValue(m_pScrollbar->value() - m_flickerSpeedX / m_scale);
|
|
|
|
vbar->setValue(vbar->value() - m_flickerSpeedY);
|
|
|
|
m_bUpdatingRect = false;
|
|
|
|
// Seems like an ugly stub, but QSignalBlocker is also a bad decision
|
|
|
|
// because if scrollbar does not emit valueChanged signal then viewport does not move
|
|
|
|
|
2016-07-27 22:52:13 +03:00
|
|
|
updateVisibleSceneRect(); // Update scene visible rect only once
|
2016-07-31 13:13:48 +03:00
|
|
|
updateScene(); // repaint scene
|
2016-08-06 14:50:31 +03:00
|
|
|
|
|
|
|
m_flickerSpeedX -= absmin(sign(m_flickerSpeedX), m_flickerSpeedX);
|
|
|
|
m_flickerSpeedY -= absmin(sign(m_flickerSpeedY), m_flickerSpeedY);
|
2016-07-27 22:52:13 +03:00
|
|
|
}
|
|
|
|
|
2016-08-06 14:50:31 +03:00
|
|
|
if (m_flickerSpeedX == 0 && m_flickerSpeedY == 0)
|
2016-07-27 22:52:13 +03:00
|
|
|
{
|
|
|
|
// Flicker stopped, no timer needed.
|
|
|
|
m_flickerTimer.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onSelectedThreadChange(::profiler::thread_id_t _id)
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
2016-08-18 23:26:41 +03:00
|
|
|
if (m_pScrollbar == nullptr || m_pScrollbar->minimapThread() == _id)
|
2016-08-03 23:00:04 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_id == 0)
|
|
|
|
{
|
|
|
|
m_pScrollbar->setMinimapFrom(0, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto item : m_items)
|
|
|
|
{
|
|
|
|
if (item->threadId() == _id)
|
|
|
|
{
|
|
|
|
m_pScrollbar->setMinimapFrom(_id, item->items(0));
|
|
|
|
updateScene();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pScrollbar->setMinimapFrom(0, nullptr);
|
|
|
|
updateScene();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onSelectedBlockChange(unsigned int _block_index)
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
if (!m_bUpdatingRect)
|
|
|
|
{
|
|
|
|
if (_block_index < ::profiler_gui::EASY_GLOBALS.gui_blocks.size())
|
|
|
|
{
|
|
|
|
// Scroll to item
|
|
|
|
|
|
|
|
const auto& guiblock = ::profiler_gui::EASY_GLOBALS.gui_blocks[_block_index];
|
2016-08-11 23:43:34 +03:00
|
|
|
const auto thread_item = m_items[guiblock.graphics_item];
|
|
|
|
const auto& item = thread_item->items(guiblock.graphics_item_level)[guiblock.graphics_item_index];
|
2016-08-08 22:17:56 +03:00
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
m_flickerSpeedX = m_flickerSpeedY = 0;
|
2016-08-09 00:15:40 +03:00
|
|
|
|
|
|
|
m_bUpdatingRect = true;
|
2016-08-11 23:43:34 +03:00
|
|
|
verticalScrollBar()->setValue(static_cast<int>(thread_item->levelY(guiblock.graphics_item_level) - m_visibleSceneRect.height() * 0.5));
|
2016-08-08 22:17:56 +03:00
|
|
|
m_pScrollbar->setValue(item.left() + item.width() * 0.5 - m_pScrollbar->sliderHalfWidth());
|
2016-08-09 00:15:40 +03:00
|
|
|
m_bUpdatingRect = false;
|
2016-08-08 22:17:56 +03:00
|
|
|
}
|
|
|
|
|
2016-08-09 00:15:40 +03:00
|
|
|
updateVisibleSceneRect();
|
2016-08-08 22:17:56 +03:00
|
|
|
updateScene();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onItemsEspandStateChange()
|
|
|
|
{
|
|
|
|
if (!m_bUpdatingRect)
|
|
|
|
{
|
|
|
|
updateScene();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
EasyGraphicsViewWidget::EasyGraphicsViewWidget(QWidget* _parent)
|
2016-08-10 22:08:27 +03:00
|
|
|
: QWidget(_parent)
|
2016-08-18 23:26:41 +03:00
|
|
|
, m_scrollbar(new EasyGraphicsScrollbar(nullptr))
|
|
|
|
, m_view(new EasyGraphicsView(nullptr))
|
|
|
|
//, m_threadWidget(new EasyThreadViewWidget(this,m_view))
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-08-09 00:45:45 +03:00
|
|
|
initWidget();
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsViewWidget::initWidget()
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
|
|
|
auto lay = new QGridLayout(this);
|
2016-08-01 22:21:59 +03:00
|
|
|
lay->setContentsMargins(1, 0, 1, 0);
|
2016-08-10 22:08:27 +03:00
|
|
|
lay->addWidget(m_view, 0, 1);
|
2016-08-01 22:21:59 +03:00
|
|
|
lay->setSpacing(1);
|
2016-08-10 22:08:27 +03:00
|
|
|
lay->addWidget(m_scrollbar, 1, 1);
|
2016-08-09 00:45:45 +03:00
|
|
|
//lay->setSpacing(1);
|
2016-08-10 22:08:27 +03:00
|
|
|
//lay->addWidget(m_threadWidget, 0, 0);
|
2016-07-31 13:13:48 +03:00
|
|
|
setLayout(lay);
|
2016-08-10 22:08:27 +03:00
|
|
|
|
2016-07-31 13:13:48 +03:00
|
|
|
m_view->setScrollbar(m_scrollbar);
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsViewWidget::~EasyGraphicsViewWidget()
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsView* EasyGraphicsViewWidget::view()
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
return m_view;
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-08-09 00:45:45 +03:00
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyThreadViewWidget::EasyThreadViewWidget(QWidget *parent, EasyGraphicsView* view):QWidget(parent),
|
2016-08-09 00:45:45 +03:00
|
|
|
m_view(view)
|
|
|
|
, m_label(new QLabel("",this))
|
|
|
|
{
|
|
|
|
m_layout = new QHBoxLayout;
|
|
|
|
//QPushButton *button1 = new QPushButton();
|
|
|
|
|
|
|
|
//m_layout->addWidget(m_label);
|
|
|
|
//setLayout(m_layout);
|
|
|
|
//show();
|
2016-08-18 23:26:41 +03:00
|
|
|
connect(&::profiler_gui::EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
|
2016-08-09 00:45:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyThreadViewWidget::~EasyThreadViewWidget()
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyThreadViewWidget::onSelectedThreadChange(::profiler::thread_id_t _id)
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
auto threadName = ::profiler_gui::EASY_GLOBALS.profiler_blocks[::profiler_gui::EASY_GLOBALS.selected_thread].thread_name;
|
|
|
|
if(threadName[0]!=0)
|
|
|
|
{
|
|
|
|
m_label->setText(threadName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_label->setText(QString("Thread %1").arg(::profiler_gui::EASY_GLOBALS.selected_thread));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
QLayoutItem *ditem;
|
|
|
|
while ((ditem = m_layout->takeAt(0)))
|
|
|
|
delete ditem;
|
|
|
|
|
|
|
|
const auto& items = m_view->getItems();
|
|
|
|
for(const auto& item: items)
|
|
|
|
{
|
|
|
|
m_layout->addWidget(new QLabel(QString("Thread %1").arg(item->threadId())));
|
|
|
|
m_layout->setSpacing(1);
|
|
|
|
}
|
|
|
|
setLayout(m_layout);
|
|
|
|
|
|
|
|
}
|