2016-08-08 22:45:57 +03:00
|
|
|
/************************************************************************
|
|
|
|
* file name : blocks_graphics_view.cpp
|
|
|
|
* ----------------- :
|
|
|
|
* creation time : 2016/06/26
|
|
|
|
* 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.
|
|
|
|
* :
|
2016-09-15 22:30:32 +03:00
|
|
|
* : * 2016/09/15 Victor Zarubkin: Moved sources of EasyGraphicsItem and EasyChronometerItem to separate files.
|
|
|
|
* :
|
2016-08-08 22:45:57 +03:00
|
|
|
* : *
|
|
|
|
* ----------------- :
|
2016-09-06 21:49:32 +03:00
|
|
|
* license : Lightweight profiler library for c++
|
|
|
|
* : Copyright(C) 2016 Sergey Yagovtsev, Victor Zarubkin
|
|
|
|
* :
|
|
|
|
* : This program is free software : you can redistribute it and / or modify
|
|
|
|
* : it under the terms of the GNU General Public License as published by
|
|
|
|
* : the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* : (at your option) any later version.
|
|
|
|
* :
|
|
|
|
* : This program is distributed in the hope that it will be useful,
|
|
|
|
* : but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* : GNU General Public License for more details.
|
|
|
|
* :
|
|
|
|
* : You should have received a copy of the GNU General Public License
|
|
|
|
* : along with this program.If not, see <http://www.gnu.org/licenses/>.
|
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-09-13 23:03:01 +03:00
|
|
|
#include <QGraphicsProxyWidget>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLabel>
|
2016-06-26 18:46:51 +03:00
|
|
|
#include <QWheelEvent>
|
2016-06-26 20:54:16 +03:00
|
|
|
#include <QMouseEvent>
|
2016-09-09 00:07:27 +03:00
|
|
|
#include <QKeyEvent>
|
2016-06-26 20:54:16 +03:00
|
|
|
#include <QScrollBar>
|
2016-08-10 22:08:27 +03:00
|
|
|
#include <QGridLayout>
|
2016-08-11 23:43:34 +03:00
|
|
|
#include <QDebug>
|
2016-08-19 01:40:14 +03:00
|
|
|
#include <QSignalBlocker>
|
2016-09-15 23:20:37 +03:00
|
|
|
#include <math.h>
|
2016-06-26 18:46:51 +03:00
|
|
|
#include "blocks_graphics_view.h"
|
2016-09-15 22:30:32 +03:00
|
|
|
#include "easy_graphics_item.h"
|
|
|
|
#include "easy_chronometer_item.h"
|
|
|
|
#include "easy_graphics_scrollbar.h"
|
2016-08-08 22:45:57 +03:00
|
|
|
#include "globals.h"
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-08-23 22:42:20 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-07 21:48:50 +03:00
|
|
|
const qreal MIN_SCALE = pow(::profiler_gui::SCALING_COEFFICIENT_INV, 70); // Up to 1000 sec scale
|
|
|
|
const qreal MAX_SCALE = pow(::profiler_gui::SCALING_COEFFICIENT, 45); // ~23000 --- Up to 10 ns scale
|
2016-08-21 22:44:03 +03:00
|
|
|
const qreal BASE_SCALE = pow(::profiler_gui::SCALING_COEFFICIENT_INV, 25); // ~0.003
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
const uint16_t TIMELINE_ROW_SIZE = 20;
|
2016-07-10 01:24:31 +03:00
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
const QRgb BACKGROUND_1 = ::profiler::colors::Grey300;
|
|
|
|
const QRgb BACKGROUND_2 = ::profiler::colors::White;
|
|
|
|
const QRgb TIMELINE_BACKGROUND = 0x20000000 | (::profiler::colors::Grey800 & 0x00ffffff);// 0x20303030;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
const int IDLE_TIMER_INTERVAL = 200; // 5Hz
|
|
|
|
const uint64_t IDLE_TIME = 400;
|
|
|
|
|
|
|
|
const int FLICKER_INTERVAL = 10; // 100Hz
|
|
|
|
const qreal FLICKER_FACTOR = 16.0 / FLICKER_INTERVAL;
|
2016-08-06 14:50:31 +03:00
|
|
|
|
2016-09-14 23:14:24 +03:00
|
|
|
const auto BG_FONT = ::profiler_gui::EFont("Helvetica", 10, QFont::Bold);
|
|
|
|
const auto CHRONOMETER_FONT = ::profiler_gui::EFont("Helvetica", 16, QFont::Bold);
|
2016-09-11 16:53:34 +03:00
|
|
|
|
|
|
|
#ifdef max
|
|
|
|
#undef max
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef min
|
|
|
|
#undef min
|
|
|
|
#endif
|
2016-08-18 23:26:41 +03:00
|
|
|
|
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-09-09 00:07:27 +03:00
|
|
|
void EasyBackgroundItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-09-11 16:53:34 +03:00
|
|
|
auto const sceneView = static_cast<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-21 18:04:38 +03:00
|
|
|
const auto visibleBottom = h - 1;
|
2016-08-10 22:08:27 +03:00
|
|
|
|
|
|
|
QRectF rect;
|
|
|
|
|
|
|
|
_painter->save();
|
|
|
|
_painter->setTransform(QTransform::fromTranslate(-x(), -y()));
|
|
|
|
|
|
|
|
const auto& items = sceneView->getItems();
|
|
|
|
if (!items.empty())
|
|
|
|
{
|
2016-09-15 22:30:32 +03:00
|
|
|
static const uint16_t OVERLAP = ::profiler_gui::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)};
|
|
|
|
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;
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
if (item->threadId() == EASY_GLOBALS.selected_thread)
|
2016-08-10 22:08:27 +03:00
|
|
|
_painter->setBrush(QBrush(QColor::fromRgb(::profiler_gui::SELECTED_THREAD_BACKGROUND)));
|
|
|
|
else
|
|
|
|
_painter->setBrush(brushes[i & 1]);
|
|
|
|
|
2016-09-15 22:30:32 +03:00
|
|
|
rect.setRect(0, top - OVERLAP, visibleSceneRect.width(), br.height() + ::profiler_gui::THREADS_ROW_SPACING);
|
2016-08-21 18:04:38 +03:00
|
|
|
const auto dh = rect.bottom() - visibleBottom;
|
|
|
|
if (dh > 0)
|
|
|
|
rect.setHeight(rect.height() - dh);
|
|
|
|
|
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->setPen(pen);
|
|
|
|
_painter->drawLine(QPointF(0, h), QPointF(visibleSceneRect.width(), h));
|
|
|
|
_painter->setPen(Qt::gray);
|
|
|
|
|
|
|
|
QLineF marks[20];
|
|
|
|
qreal first_x = first * sceneStep;
|
2016-09-15 22:30:32 +03:00
|
|
|
const auto textWidth = QFontMetricsF(_painter->font(), sceneView).width(QString::number(static_cast<quint64>(0.5 + first_x * factor))) * ::profiler_gui::FONT_METRICS_FACTOR + 10;
|
2016-08-21 14:26:04 +03:00
|
|
|
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);
|
2016-08-10 22:08:27 +03:00
|
|
|
|
2016-08-21 14:26:04 +03:00
|
|
|
for (int j = 0; j < 20; ++j)
|
|
|
|
{
|
|
|
|
auto xmark = current + j * step * 0.1;
|
2016-08-21 22:44:03 +03:00
|
|
|
marks[j].setLine(xmark, h, xmark, h + ((j % 5) ? 4 : 8));
|
2016-08-21 14:26:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_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-09-09 00:07:27 +03:00
|
|
|
void EasyTimelineIndicatorItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*)
|
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()));
|
2016-09-07 21:48:50 +03:00
|
|
|
//_painter->setCompositionMode(QPainter::CompositionMode_Difference);
|
2016-08-21 22:44:03 +03:00
|
|
|
_painter->setBrush(Qt::NoBrush);
|
2016-08-10 22:08:27 +03:00
|
|
|
|
2016-09-07 21:48:50 +03:00
|
|
|
QPen pen(Qt::black);
|
2016-08-21 22:44:03 +03:00
|
|
|
pen.setWidth(2);
|
|
|
|
pen.setJoinStyle(Qt::MiterJoin);
|
|
|
|
_painter->setPen(pen);
|
2016-08-10 22:08:27 +03:00
|
|
|
|
2016-08-21 22:44:03 +03:00
|
|
|
QRectF rect(visibleSceneRect.width() - 10 - step, visibleSceneRect.height() - 20, step, 10);
|
|
|
|
const auto rect_right = rect.right();
|
|
|
|
const QPointF points[] = {{rect.left(), rect.bottom()}, {rect.left(), rect.top()}, {rect_right, rect.top()}, {rect_right, rect.top() + 5}};
|
|
|
|
_painter->drawPolyline(points, sizeof(points) / sizeof(QPointF));
|
|
|
|
|
|
|
|
rect.translate(0, 3);
|
2016-08-10 22:08:27 +03:00
|
|
|
_painter->drawText(rect, Qt::AlignRight | Qt::TextDontClip, text);
|
|
|
|
|
|
|
|
_painter->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
EasyGraphicsView::EasyGraphicsView(QWidget* _parent)
|
2016-09-11 16:53:34 +03:00
|
|
|
: Parent(_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)
|
2016-08-21 22:44:03 +03:00
|
|
|
, m_timelineStep(0)
|
2016-09-13 23:03:01 +03:00
|
|
|
, m_idleTime(0)
|
2016-07-31 18:48:41 +03:00
|
|
|
, m_mouseButtons(Qt::NoButton)
|
|
|
|
, m_pScrollbar(nullptr)
|
|
|
|
, m_chronometerItem(nullptr)
|
2016-08-06 14:50:31 +03:00
|
|
|
, m_chronometerItemAux(nullptr)
|
2016-09-13 23:03:01 +03:00
|
|
|
, m_csInfoWidget(nullptr)
|
2016-08-06 14:50:31 +03:00
|
|
|
, m_flickerSpeedX(0)
|
|
|
|
, m_flickerSpeedY(0)
|
2016-09-13 23:03:01 +03:00
|
|
|
, m_flickerCounterX(0)
|
|
|
|
, m_flickerCounterY(0)
|
2016-08-06 14:50:31 +03:00
|
|
|
, m_bDoubleClick(false)
|
2016-07-31 18:48:41 +03:00
|
|
|
, m_bUpdatingRect(false)
|
|
|
|
, 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-09-15 22:30:32 +03:00
|
|
|
qreal EasyGraphicsView::chronoTime() const
|
|
|
|
{
|
|
|
|
return m_chronometerItem->width();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal EasyGraphicsView::chronoTimeAux() const
|
|
|
|
{
|
|
|
|
return m_chronometerItemAux->width();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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-09-15 22:30:32 +03:00
|
|
|
chronoItem->setColor(_main ? ::profiler_gui::CHRONOMETER_COLOR : ::profiler_gui::CHRONOMETER_COLOR2);
|
2016-08-06 14:50:31 +03:00
|
|
|
chronoItem->setBoundingRect(scene()->sceneRect());
|
|
|
|
chronoItem->hide();
|
|
|
|
scene()->addItem(chronoItem);
|
|
|
|
|
|
|
|
return chronoItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-21 22:09:04 +03:00
|
|
|
void EasyGraphicsView::clear()
|
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-09-13 23:03:01 +03:00
|
|
|
m_flickerCounterX = 0;
|
|
|
|
m_flickerCounterY = 0;
|
2016-08-01 22:21:59 +03:00
|
|
|
|
2016-09-13 23:40:58 +03:00
|
|
|
if (m_csInfoWidget != nullptr)
|
|
|
|
{
|
|
|
|
auto widget = m_csInfoWidget->widget();
|
|
|
|
widget->setParent(nullptr);
|
|
|
|
m_csInfoWidget->setWidget(nullptr);
|
|
|
|
delete widget;
|
|
|
|
m_csInfoWidget = nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTimer.stop();
|
|
|
|
m_idleTime = 0;
|
|
|
|
|
2016-08-01 22:21:59 +03:00
|
|
|
// Reset necessary flags
|
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-09-21 22:09:04 +03:00
|
|
|
clear();
|
2016-08-08 22:45:57 +03:00
|
|
|
|
|
|
|
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-09-08 22:42:35 +03:00
|
|
|
::profiler::thread_id_t longestTree = 0, mainTree = 0;
|
2016-06-26 18:46:51 +03:00
|
|
|
for (const auto& threadTree : _blocksTree)
|
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
const auto& t = threadTree.second;
|
2016-09-04 19:35:58 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
auto timestart = m_beginTime;
|
|
|
|
auto timefinish = finish;
|
|
|
|
|
|
|
|
if (!t.children.empty())
|
|
|
|
timestart = blocksTree(t.children.front()).node->begin();
|
2016-09-08 22:42:35 +03:00
|
|
|
if (!t.sync.empty())
|
|
|
|
timestart = ::std::min(timestart, blocksTree(t.sync.front()).node->begin());
|
2016-09-04 19:35:58 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
if (!t.children.empty())
|
|
|
|
timefinish = blocksTree(t.children.back()).node->end();
|
|
|
|
if (!t.sync.empty())
|
|
|
|
timefinish = ::std::max(timefinish, blocksTree(t.sync.back()).node->end());
|
2016-06-27 23:22:12 +03:00
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_beginTime > timestart)
|
|
|
|
m_beginTime = timestart;
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
if (finish < timefinish) {
|
2016-07-31 18:48:41 +03:00
|
|
|
finish = timefinish;
|
2016-08-30 22:51:18 +03:00
|
|
|
longestTree = threadTree.first;
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
2016-09-08 22:42:35 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
if (mainTree == 0 && !strcmp(t.name(), "Main"))
|
2016-09-08 22:42:35 +03:00
|
|
|
mainTree = threadTree.first;
|
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-09-08 22:42:35 +03:00
|
|
|
const EasyGraphicsItem *longestItem = nullptr, *mainThreadItem = nullptr;
|
2016-07-31 18:48:41 +03:00
|
|
|
for (const auto& threadTree : _blocksTree)
|
|
|
|
{
|
2016-08-23 22:42:20 +03:00
|
|
|
if (m_items.size() == 0xff)
|
|
|
|
{
|
|
|
|
qWarning() << "Warning: Maximum threads number (255 threads) exceeded! See EasyGraphicsView::setTree() : " << __LINE__ << " in file " << __FILE__;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
const auto& t = threadTree.second;
|
|
|
|
|
2016-06-30 02:57:57 +03:00
|
|
|
// fill scene with new items
|
2016-09-13 23:03:01 +03:00
|
|
|
qreal h = 0, x = 0;
|
|
|
|
|
|
|
|
if (!t.children.empty())
|
|
|
|
x = time2position(blocksTree(t.children.front()).node->begin());
|
|
|
|
else if (!t.sync.empty())
|
|
|
|
x = time2position(blocksTree(t.sync.front()).node->begin());
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
auto item = new EasyGraphicsItem(static_cast<uint8_t>(m_items.size()), t);
|
2016-09-13 23:03:01 +03:00
|
|
|
if (t.depth)
|
|
|
|
item->setLevels(t.depth);
|
2016-07-31 13:13:48 +03:00
|
|
|
item->setPos(0, y);
|
2016-07-27 21:50:11 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
qreal children_duration = 0;
|
|
|
|
|
|
|
|
if (!t.children.empty())
|
|
|
|
{
|
|
|
|
children_duration = setTree(item, t.children, h, y, 0);
|
|
|
|
}
|
|
|
|
else if (!t.sync.empty())
|
|
|
|
{
|
|
|
|
children_duration = time2position(blocksTree(t.sync.back()).node->end()) - x;
|
2016-09-15 22:30:32 +03:00
|
|
|
h = ::profiler_gui::GRAPHICS_ROW_SIZE;
|
2016-09-13 23:03:01 +03:00
|
|
|
}
|
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-09-15 22:30:32 +03:00
|
|
|
y += h + ::profiler_gui::THREADS_ROW_SPACING;
|
2016-08-03 00:06:36 +03:00
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
if (longestTree == threadTree.first)
|
2016-08-03 00:06:36 +03:00
|
|
|
longestItem = item;
|
2016-09-07 21:48:50 +03:00
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
if (mainTree == threadTree.first)
|
2016-09-07 21:48:50 +03:00
|
|
|
mainThreadItem = item;
|
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-09-21 22:09:04 +03:00
|
|
|
setSceneRect(0, 0, endX, y + TIMELINE_ROW_SIZE);
|
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
|
|
|
|
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
|
|
|
|
m_bEmpty = false;
|
2016-08-01 22:21:59 +03:00
|
|
|
|
|
|
|
scaleTo(BASE_SCALE);
|
2016-09-08 22:42:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
emit treeChanged();
|
|
|
|
|
|
|
|
if (mainThreadItem != nullptr)
|
2016-09-13 23:03:01 +03:00
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
longestItem = mainThreadItem;
|
2016-09-13 23:03:01 +03:00
|
|
|
}
|
2016-09-08 22:42:35 +03:00
|
|
|
|
|
|
|
if (longestItem != nullptr)
|
|
|
|
{
|
|
|
|
m_pScrollbar->setMinimapFrom(longestItem->threadId(), longestItem->items(0));
|
|
|
|
EASY_GLOBALS.selected_thread = longestItem->threadId();
|
|
|
|
emit EASY_GLOBALS.events.selectedThreadChanged(longestItem->threadId());
|
|
|
|
}
|
2016-09-13 23:03:01 +03:00
|
|
|
|
|
|
|
m_idleTimer.start(IDLE_TIMER_INTERVAL);
|
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-09-04 14:48:35 +03:00
|
|
|
const auto level = static_cast<uint8_t>(_level);
|
2016-08-11 23:43:34 +03:00
|
|
|
_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-08-30 22:51:18 +03:00
|
|
|
for (auto child_index : _children)
|
2016-06-30 02:57:57 +03:00
|
|
|
{
|
2016-08-30 22:51:18 +03:00
|
|
|
auto& gui_block = easyBlock(child_index);
|
|
|
|
const auto& child = gui_block.tree;
|
|
|
|
|
2016-08-28 18:19:12 +03:00
|
|
|
auto xbegin = time2position(child.node->begin());
|
2016-07-31 13:13:48 +03:00
|
|
|
if (start_time < 0)
|
|
|
|
{
|
|
|
|
start_time = xbegin;
|
|
|
|
}
|
2016-06-30 02:57:57 +03:00
|
|
|
|
2016-08-28 18:19:12 +03:00
|
|
|
auto duration = time2position(child.node->end()) - xbegin;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
2016-08-23 22:42:20 +03:00
|
|
|
//const auto dt = xbegin - prev_end;
|
|
|
|
//if (dt < 0)
|
|
|
|
//{
|
|
|
|
// duration += dt;
|
|
|
|
// xbegin -= dt;
|
|
|
|
//}
|
2016-06-30 02:57:57 +03:00
|
|
|
|
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-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-09-04 14:48:35 +03:00
|
|
|
b.children_begin = static_cast<unsigned int>(_item->items(static_cast<uint8_t>(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)
|
|
|
|
{
|
2016-09-15 22:30:32 +03:00
|
|
|
children_duration = setTree(_item, child.children, h, _y + ::profiler_gui::GRAPHICS_ROW_SIZE_FULL, next_level);
|
2016-08-11 23:43:34 +03:00
|
|
|
}
|
|
|
|
else if (!child.children.empty() && !warned)
|
|
|
|
{
|
|
|
|
warned = true;
|
2016-08-23 22:42:20 +03:00
|
|
|
qWarning() << "Warning: 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;
|
|
|
|
}
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
b.block = child_index;// &child;
|
2016-08-11 23:43:34 +03:00
|
|
|
b.setPos(xbegin, duration);
|
2016-09-15 22:30:32 +03:00
|
|
|
b.totalHeight = ::profiler_gui::GRAPHICS_ROW_SIZE + h;
|
|
|
|
b.state = 0;
|
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-09-15 22:30:32 +03:00
|
|
|
_height += ::profiler_gui::GRAPHICS_ROW_SIZE_FULL + maxh;
|
2016-06-30 02:57:57 +03:00
|
|
|
|
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-08-21 16:48:42 +03:00
|
|
|
auto const prevScrollbar = m_pScrollbar;
|
|
|
|
const bool makeConnect = prevScrollbar == nullptr || prevScrollbar != _scrollbar;
|
|
|
|
|
|
|
|
if (prevScrollbar != nullptr && prevScrollbar != _scrollbar)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-08-21 16:48:42 +03:00
|
|
|
disconnect(prevScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
2016-08-21 17:12:28 +03:00
|
|
|
disconnect(prevScrollbar, &EasyGraphicsScrollbar::wheeled, this, &This::onGraphicsScrollbarWheel);
|
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-09-21 22:09:04 +03:00
|
|
|
m_pScrollbar->clear();
|
2016-07-31 13:13:48 +03:00
|
|
|
m_pScrollbar->setRange(0, scene()->width());
|
|
|
|
m_pScrollbar->setSliderWidth(m_visibleSceneRect.width());
|
2016-08-21 16:48:42 +03:00
|
|
|
|
|
|
|
if (makeConnect)
|
|
|
|
{
|
|
|
|
connect(m_pScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
2016-08-21 17:12:28 +03:00
|
|
|
connect(m_pScrollbar, &EasyGraphicsScrollbar::wheeled, this, &This::onGraphicsScrollbarWheel);
|
2016-08-21 16:48:42 +03:00
|
|
|
}
|
2016-08-03 23:00:04 +03:00
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
EASY_GLOBALS.selected_thread = 0;
|
|
|
|
emit 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-09-09 00:07:27 +03:00
|
|
|
void EasyGraphicsView::repaintScene()
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
|
|
|
scene()->update(m_visibleSceneRect);
|
2016-09-09 00:07:27 +03:00
|
|
|
emit sceneUpdated();
|
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::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-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
2016-08-01 22:21:59 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::wheelEvent(QWheelEvent* _event)
|
2016-07-31 13:13:48 +03:00
|
|
|
{
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
|
|
|
|
2016-08-21 16:48:42 +03:00
|
|
|
if (!m_bEmpty)
|
|
|
|
onWheel(mapToScene(_event->pos()).x(), _event->delta());
|
|
|
|
_event->accept();
|
|
|
|
}
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-21 17:12:28 +03:00
|
|
|
void EasyGraphicsView::onGraphicsScrollbarWheel(qreal _mouseX, int _wheelDelta)
|
2016-08-21 16:48:42 +03:00
|
|
|
{
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
|
|
|
|
2016-08-21 17:12:28 +03:00
|
|
|
for (auto item : m_items)
|
|
|
|
{
|
2016-08-30 22:51:18 +03:00
|
|
|
if (item->threadId() == EASY_GLOBALS.selected_thread)
|
2016-08-21 17:12:28 +03:00
|
|
|
{
|
|
|
|
m_bUpdatingRect = true;
|
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
vbar->setValue(item->y() + (item->boundingRect().height() - vbar->pageStep()) * 0.5);
|
|
|
|
m_bUpdatingRect = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-21 16:48:42 +03:00
|
|
|
|
2016-08-21 17:12:28 +03:00
|
|
|
onWheel(_mouseX, _wheelDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EasyGraphicsView::onWheel(qreal _mouseX, int _wheelDelta)
|
|
|
|
{
|
2016-08-21 22:44:03 +03:00
|
|
|
const decltype(m_scale) scaleCoeff = _wheelDelta > 0 ? ::profiler_gui::SCALING_COEFFICIENT : ::profiler_gui::SCALING_COEFFICIENT_INV;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
|
|
|
// Remember current mouse position
|
2016-09-09 00:07:27 +03:00
|
|
|
_mouseX = clamp(0., _mouseX, scene()->width());
|
2016-08-21 16:48:42 +03:00
|
|
|
const auto mousePosition = m_offset + _mouseX / m_scale;
|
2016-07-31 13:13:48 +03:00
|
|
|
|
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-08-21 17:12:28 +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
|
2016-08-21 16:48:42 +03:00
|
|
|
m_offset = clamp(0., mousePosition - _mouseX / m_scale, scene()->width() - windowWidth);
|
2016-07-31 13:13:48 +03:00
|
|
|
|
|
|
|
// 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-21 17:12:28 +03:00
|
|
|
updateVisibleSceneRect(); // Update scene rect
|
2016-08-10 22:08:27 +03:00
|
|
|
updateTimelineStep(windowWidth);
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene(); // repaint scene
|
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::mousePressEvent(QMouseEvent* _event)
|
2016-06-26 20:54:16 +03:00
|
|
|
{
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
|
|
|
|
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
|
|
|
{
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
|
|
|
|
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-09-09 00:07:27 +03:00
|
|
|
emit sceneUpdated();
|
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-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
if (m_bEmpty)
|
|
|
|
{
|
|
|
|
_event->accept();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-08 22:45:57 +03:00
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
bool chronoHidden = false;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
const ::profiler_gui::EasyBlockItem* selectedBlock = nullptr;
|
|
|
|
const auto previouslySelectedBlock = EASY_GLOBALS.selected_block;
|
2016-08-08 22:45:57 +03:00
|
|
|
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)
|
|
|
|
{
|
2016-09-09 00:07:27 +03:00
|
|
|
chronoHidden = true;
|
2016-08-08 22:45:57 +03:00
|
|
|
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);
|
2016-09-08 22:42:35 +03:00
|
|
|
if (mouseClickPos.x() >= 0)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
mouseClickPos.setX(m_offset + mouseClickPos.x() / m_scale);
|
|
|
|
|
|
|
|
// Try to select one of item blocks
|
|
|
|
for (auto item : m_items)
|
2016-08-08 22:45:57 +03:00
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
auto block = item->intersect(mouseClickPos);
|
|
|
|
if (block)
|
|
|
|
{
|
|
|
|
changedSelectedItem = true;
|
|
|
|
selectedBlock = block;
|
|
|
|
EASY_GLOBALS.selected_block = block->block;
|
|
|
|
break;
|
|
|
|
}
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
2016-08-21 22:44:03 +03:00
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
if (!changedSelectedItem && EASY_GLOBALS.selected_block != ::profiler_gui::numeric_max(EASY_GLOBALS.selected_block))
|
|
|
|
{
|
|
|
|
changedSelectedItem = true;
|
|
|
|
::profiler_gui::set_max(EASY_GLOBALS.selected_block);
|
|
|
|
}
|
2016-08-21 22:44:03 +03:00
|
|
|
}
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-08-30 22:51:18 +03:00
|
|
|
if (selectedBlock != nullptr && previouslySelectedBlock == EASY_GLOBALS.selected_block && !blocksTree(selectedBlock->block).children.empty())
|
2016-08-21 22:44:03 +03:00
|
|
|
{
|
2016-08-30 22:51:18 +03:00
|
|
|
EASY_GLOBALS.gui_blocks[previouslySelectedBlock].expanded = !EASY_GLOBALS.gui_blocks[previouslySelectedBlock].expanded;
|
|
|
|
emit EASY_GLOBALS.events.itemsExpandStateChanged();
|
2016-08-21 22:44:03 +03:00
|
|
|
}
|
2016-08-30 22:51:18 +03:00
|
|
|
emit EASY_GLOBALS.events.selectedBlockChanged(EASY_GLOBALS.selected_block);
|
2016-08-08 22:45:57 +03:00
|
|
|
m_bUpdatingRect = false;
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
|
|
|
}
|
|
|
|
else if (chronoHidden)
|
|
|
|
{
|
|
|
|
emit sceneUpdated();
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
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-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
|
|
|
|
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-09-09 00:07:27 +03:00
|
|
|
const auto x = clamp(0., mouseScenePos.x(), scene()->width());
|
2016-07-31 18:48:41 +03:00
|
|
|
|
2016-08-08 22:45:57 +03:00
|
|
|
if (m_mouseButtons & Qt::RightButton)
|
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
bool showItem = moveChrono(m_chronometerItem, x);
|
2016-08-08 22:45:57 +03:00
|
|
|
m_pScrollbar->setChronoPos(m_chronometerItem->left(), m_chronometerItem->right());
|
|
|
|
|
|
|
|
if (showItem)
|
|
|
|
{
|
|
|
|
m_pScrollbar->showChrono();
|
|
|
|
}
|
|
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_mouseButtons & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
if (m_bDoubleClick)
|
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
moveChrono(m_chronometerItemAux, x);
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
|
|
|
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;
|
2016-09-13 23:03:01 +03:00
|
|
|
m_flickerSpeedY += delta.y();
|
2016-08-08 22:45:57 +03:00
|
|
|
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)
|
|
|
|
{
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene(); // repaint scene
|
2016-08-08 22:45:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_event->accept();
|
2016-06-26 20:54:16 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
void EasyGraphicsView::keyPressEvent(QKeyEvent* _event)
|
|
|
|
{
|
|
|
|
static const int KeyStep = 100;
|
|
|
|
|
|
|
|
const int key = _event->key();
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
2016-09-09 00:07:27 +03:00
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case Qt::Key_Right:
|
|
|
|
case Qt::Key_6:
|
|
|
|
{
|
|
|
|
m_pScrollbar->setValue(m_pScrollbar->value() + KeyStep / m_scale);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Qt::Key_Left:
|
|
|
|
case Qt::Key_4:
|
|
|
|
{
|
|
|
|
m_pScrollbar->setValue(m_pScrollbar->value() - KeyStep / m_scale);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_8:
|
|
|
|
{
|
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
vbar->setValue(vbar->value() - KeyStep);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Qt::Key_Down:
|
|
|
|
case Qt::Key_2:
|
|
|
|
{
|
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
vbar->setValue(vbar->value() + KeyStep);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Qt::Key_Plus:
|
|
|
|
case Qt::Key_Equal:
|
|
|
|
{
|
|
|
|
onWheel(mapToScene(mapFromGlobal(QCursor::pos())).x(), KeyStep);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Qt::Key_Minus:
|
|
|
|
{
|
|
|
|
onWheel(mapToScene(mapFromGlobal(QCursor::pos())).x(), -KeyStep);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_keys.insert(key);
|
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EasyGraphicsView::keyReleaseEvent(QKeyEvent* _event)
|
|
|
|
{
|
|
|
|
const int key = _event->key();
|
2016-09-13 23:03:01 +03:00
|
|
|
m_idleTime = 0;
|
2016-09-09 00:07:27 +03:00
|
|
|
|
|
|
|
m_keys.erase(key);
|
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::resizeEvent(QResizeEvent* _event)
|
2016-07-31 18:48:41 +03:00
|
|
|
{
|
2016-09-11 16:53:34 +03:00
|
|
|
Parent::resizeEvent(_event);
|
|
|
|
|
|
|
|
const QRectF previousRect = m_visibleSceneRect;
|
|
|
|
updateVisibleSceneRect(); // Update scene visible rect only once
|
|
|
|
|
|
|
|
// Update slider width for scrollbar
|
|
|
|
const auto windowWidth = m_visibleSceneRect.width() / m_scale;
|
|
|
|
m_pScrollbar->setSliderWidth(windowWidth);
|
|
|
|
|
|
|
|
// Calculate new offset to save old screen center
|
|
|
|
const auto deltaWidth = m_visibleSceneRect.width() - previousRect.width();
|
|
|
|
m_offset = clamp(0., m_offset - deltaWidth * 0.5 / m_scale, scene()->width() - windowWidth);
|
|
|
|
|
|
|
|
// Update slider position
|
|
|
|
m_bUpdatingRect = true; // To be sure that updateVisibleSceneRect will not be called by scrollbar change
|
|
|
|
m_pScrollbar->setValue(m_offset);
|
|
|
|
m_bUpdatingRect = false;
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene(); // repaint scene
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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-09-13 23:03:01 +03:00
|
|
|
connect(&m_idleTimer, &QTimer::timeout, this, &This::onIdleTimeout);
|
2016-08-24 01:00:24 +03:00
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
auto globalSignals = &EASY_GLOBALS.events;
|
2016-08-24 01:00:24 +03:00
|
|
|
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
|
|
|
|
connect(globalSignals, &::profiler_gui::EasyGlobalSignals::selectedBlockChanged, this, &This::onSelectedBlockChange);
|
|
|
|
connect(globalSignals, &::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();
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
2016-07-31 18:48:41 +03:00
|
|
|
}
|
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
|
|
|
{
|
2016-09-13 23:03:01 +03:00
|
|
|
++m_flickerCounterX;
|
|
|
|
++m_flickerCounterY;
|
|
|
|
|
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-08-21 22:44:03 +03:00
|
|
|
if (m_flickerSpeedX == -1) m_flickerSpeedX = 0;
|
|
|
|
if (m_flickerSpeedY == -1) m_flickerSpeedY = 0;
|
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-09-09 00:07:27 +03:00
|
|
|
repaintScene(); // repaint scene
|
2016-08-06 14:50:31 +03:00
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
const int dx = static_cast<int>(sign(m_flickerSpeedX) * m_flickerCounterX / FLICKER_FACTOR);
|
|
|
|
const int dy = static_cast<int>(sign(m_flickerSpeedY) * m_flickerCounterY / FLICKER_FACTOR);
|
|
|
|
|
|
|
|
if (abs(dx) > 0)
|
|
|
|
{
|
|
|
|
m_flickerSpeedX -= absmin(dx, m_flickerSpeedX);
|
|
|
|
m_flickerCounterX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(dy) > 0)
|
|
|
|
{
|
|
|
|
m_flickerSpeedY -= absmin(dy, m_flickerSpeedY);
|
|
|
|
m_flickerCounterY = 0;
|
|
|
|
}
|
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-09-13 23:03:01 +03:00
|
|
|
m_flickerSpeedX = 0;
|
|
|
|
m_flickerSpeedY = 0;
|
|
|
|
m_flickerCounterX = 0;
|
|
|
|
m_flickerCounterY = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void EasyGraphicsView::onIdleTimeout()
|
|
|
|
{
|
|
|
|
m_idleTime += IDLE_TIMER_INTERVAL;
|
|
|
|
|
|
|
|
if (m_idleTime > IDLE_TIME)
|
|
|
|
{
|
|
|
|
if (m_csInfoWidget != nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto scenePos = mapToScene(mapFromGlobal(QCursor::pos()));
|
2016-09-15 22:30:32 +03:00
|
|
|
|
|
|
|
if (scenePos.x() < m_visibleSceneRect.left() || scenePos.x() > m_visibleSceneRect.right())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (scenePos.y() < m_visibleSceneRect.top() || scenePos.y() > m_visibleSceneRect.bottom())
|
|
|
|
return;
|
|
|
|
|
2016-09-13 23:03:01 +03:00
|
|
|
decltype(scenePos) pos(m_offset + scenePos.x() / m_scale, scenePos.y());
|
|
|
|
|
|
|
|
// Try to select one of context switches or items
|
|
|
|
for (auto item : m_items)
|
|
|
|
{
|
|
|
|
auto block = item->intersect(pos);
|
|
|
|
if (block)
|
|
|
|
{
|
2016-09-13 23:40:58 +03:00
|
|
|
const auto& itemBlock = blocksTree(block->block);
|
|
|
|
auto name = *itemBlock.node->name() != 0 ? itemBlock.node->name() : easyDescriptor(itemBlock.node->id()).name();
|
2016-09-13 23:03:01 +03:00
|
|
|
|
|
|
|
auto widget = new QWidget();
|
|
|
|
auto lay = new QFormLayout(widget);
|
|
|
|
lay->setLabelAlignment(Qt::AlignRight);
|
|
|
|
lay->addRow("Name:", new QLabel(name));
|
2016-09-13 23:40:58 +03:00
|
|
|
lay->addRow("Duration:", new QLabel(::profiler_gui::timeStringReal(PROF_MICROSECONDS(itemBlock.node->duration()), 3)));
|
|
|
|
if (itemBlock.per_thread_stats)
|
|
|
|
{
|
|
|
|
lay->addRow("%/Thread:", new QLabel(QString::number(::profiler_gui::percent(itemBlock.per_thread_stats->total_duration, item->root()->active_time))));
|
|
|
|
lay->addRow("N/Thread:", new QLabel(QString::number(itemBlock.per_thread_stats->calls_number)));
|
|
|
|
if (itemBlock.per_parent_stats->parent_block == item->threadId())
|
|
|
|
{
|
|
|
|
auto percent = ::profiler_gui::percentReal(itemBlock.node->duration(), item->root()->active_time);
|
|
|
|
lay->addRow("%:", new QLabel(percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent))));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto percent = ::profiler_gui::percentReal(itemBlock.node->duration(), blocksTree(itemBlock.per_parent_stats->parent_block).node->duration());
|
|
|
|
lay->addRow("%:", new QLabel(percent < 0.5001 ? QString::number(percent, 'f', 2) : QString::number(static_cast<int>(0.5 + percent))));
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 23:03:01 +03:00
|
|
|
|
|
|
|
m_csInfoWidget = new QGraphicsProxyWidget();
|
|
|
|
m_csInfoWidget->setWidget(widget);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cse = item->intersectEvent(pos);
|
|
|
|
if (cse)
|
|
|
|
{
|
|
|
|
auto widget = new QWidget();
|
|
|
|
auto lay = new QFormLayout(widget);
|
|
|
|
lay->setLabelAlignment(Qt::AlignRight);
|
|
|
|
|
|
|
|
auto it = EASY_GLOBALS.profiler_blocks.find(cse->tree.node->id());
|
|
|
|
if (it != EASY_GLOBALS.profiler_blocks.end())
|
|
|
|
lay->addRow("Thread:", new QLabel(QString("%1 %2").arg(cse->tree.node->id()).arg(it->second.name())));
|
|
|
|
else
|
|
|
|
lay->addRow("Thread:", new QLabel(QString::number(cse->tree.node->id())));
|
|
|
|
lay->addRow("Process:", new QLabel(cse->tree.node->name()));
|
|
|
|
lay->addRow("Duration:", new QLabel(::profiler_gui::timeStringReal(PROF_MICROSECONDS(cse->tree.node->duration()), 3)));
|
|
|
|
|
|
|
|
m_csInfoWidget = new QGraphicsProxyWidget();
|
|
|
|
m_csInfoWidget->setWidget(widget);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_csInfoWidget != nullptr)
|
|
|
|
{
|
|
|
|
scene()->addItem(m_csInfoWidget);
|
|
|
|
|
|
|
|
auto br = m_csInfoWidget->boundingRect();
|
|
|
|
if (scenePos.y() + br.height() > m_visibleSceneRect.bottom())
|
|
|
|
scenePos.setY(scenePos.y() - br.height());
|
|
|
|
if (scenePos.x() + br.width() > m_visibleSceneRect.right())
|
|
|
|
scenePos.setX(scenePos.x() - br.width());
|
|
|
|
|
|
|
|
m_csInfoWidget->setPos(scenePos);
|
|
|
|
m_csInfoWidget->setOpacity(0.85);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_csInfoWidget != nullptr)
|
|
|
|
{
|
2016-09-13 23:40:58 +03:00
|
|
|
auto widget = m_csInfoWidget->widget();
|
|
|
|
widget->setParent(nullptr);
|
|
|
|
m_csInfoWidget->setWidget(nullptr);
|
|
|
|
delete widget;
|
2016-09-13 23:03:01 +03:00
|
|
|
scene()->removeItem(m_csInfoWidget);
|
|
|
|
m_csInfoWidget = nullptr;
|
2016-07-27 22:52:13 +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 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));
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
2016-08-03 23:00:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pScrollbar->setMinimapFrom(0, nullptr);
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
2016-08-03 23:00:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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)
|
|
|
|
{
|
2016-08-30 22:51:18 +03:00
|
|
|
if (_block_index < EASY_GLOBALS.gui_blocks.size())
|
2016-08-08 22:17:56 +03:00
|
|
|
{
|
|
|
|
// Scroll to item
|
|
|
|
|
2016-08-30 22:51:18 +03:00
|
|
|
const auto& guiblock = 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-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
2016-08-08 22:17:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-08-18 23:26:41 +03:00
|
|
|
void EasyGraphicsView::onItemsEspandStateChange()
|
|
|
|
{
|
|
|
|
if (!m_bUpdatingRect)
|
|
|
|
{
|
2016-09-09 00:07:27 +03:00
|
|
|
repaintScene();
|
2016-08-18 23:26:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
EasyGraphicsViewWidget::EasyGraphicsViewWidget(QWidget* _parent)
|
2016-08-10 22:08:27 +03:00
|
|
|
: QWidget(_parent)
|
2016-09-08 22:42:35 +03:00
|
|
|
, m_scrollbar(new EasyGraphicsScrollbar(this))
|
|
|
|
, m_view(new EasyGraphicsView(this))
|
2016-09-09 00:07:27 +03:00
|
|
|
, m_threadNamesWidget(new EasyThreadNamesWidget(m_view, m_scrollbar->height(), this))
|
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-09-09 00:07:27 +03:00
|
|
|
lay->addWidget(m_threadNamesWidget, 0, 0, 2, 1);
|
2016-09-08 22:42:35 +03:00
|
|
|
lay->setSpacing(1);
|
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-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-09-21 22:09:04 +03:00
|
|
|
void EasyGraphicsViewWidget::clear()
|
|
|
|
{
|
|
|
|
m_scrollbar->clear();
|
|
|
|
m_threadNamesWidget->clear();
|
|
|
|
m_view->clear();
|
|
|
|
m_view->setSceneRect(0, 0, 10, 10);
|
|
|
|
}
|
|
|
|
|
2016-07-31 18:48:41 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-08-09 00:45:45 +03:00
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
void EasyThreadNameItem::paint(QPainter* _painter, const QStyleOptionGraphicsItem*, QWidget*)
|
|
|
|
{
|
2016-09-11 16:53:34 +03:00
|
|
|
auto const parentView = static_cast<EasyThreadNamesWidget*>(scene()->parent());
|
|
|
|
const auto view = parentView->view();
|
2016-09-08 22:42:35 +03:00
|
|
|
const auto& items = view->getItems();
|
|
|
|
if (items.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto visibleSceneRect = view->visibleSceneRect();
|
2016-09-09 00:07:27 +03:00
|
|
|
const auto h = visibleSceneRect.height() + TIMELINE_ROW_SIZE - 2;
|
2016-09-08 22:42:35 +03:00
|
|
|
const auto w = scene()->sceneRect().width();
|
|
|
|
|
2016-09-15 22:30:32 +03:00
|
|
|
static const uint16_t OVERLAP = ::profiler_gui::THREADS_ROW_SPACING >> 1;
|
2016-09-08 22:42:35 +03:00
|
|
|
static const QBrush brushes[2] = {QColor::fromRgb(BACKGROUND_1), QColor::fromRgb(BACKGROUND_2)};
|
|
|
|
int i = -1;
|
|
|
|
|
|
|
|
QRectF rect;
|
|
|
|
|
|
|
|
_painter->resetTransform();
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
// Draw thread names
|
|
|
|
_painter->setFont(BG_FONT);
|
2016-09-08 22:42:35 +03:00
|
|
|
for (auto item : items)
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
++i;
|
|
|
|
|
|
|
|
auto br = item->boundingRect();
|
|
|
|
auto top = item->y() + br.top() - visibleSceneRect.top() - OVERLAP;
|
2016-09-15 22:30:32 +03:00
|
|
|
auto hgt = br.height() + ::profiler_gui::THREADS_ROW_SPACING;
|
2016-09-08 22:42:35 +03:00
|
|
|
auto bottom = top + hgt;
|
|
|
|
|
|
|
|
if (top > h || bottom < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (item->threadId() == EASY_GLOBALS.selected_thread)
|
|
|
|
_painter->setBrush(QBrush(QColor::fromRgb(::profiler_gui::SELECTED_THREAD_BACKGROUND)));
|
|
|
|
else
|
|
|
|
_painter->setBrush(brushes[i & 1]);
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
if (top < 0)
|
|
|
|
{
|
|
|
|
hgt += top;
|
|
|
|
top = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto dh = top + hgt - h;
|
|
|
|
if (dh > 0)
|
|
|
|
hgt -= dh;
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
rect.setRect(0, top, w, hgt);
|
|
|
|
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
_painter->drawRect(rect);
|
|
|
|
|
|
|
|
rect.translate(-5, 0);
|
|
|
|
_painter->setPen(QColor::fromRgb(::profiler::colors::Dark));
|
|
|
|
_painter->drawText(rect, Qt::AlignRight | Qt::AlignVCenter, item->threadName());
|
2016-08-09 00:45:45 +03:00
|
|
|
}
|
2016-09-09 00:07:27 +03:00
|
|
|
|
2016-09-21 22:09:04 +03:00
|
|
|
const auto rect_bottom = rect.bottom();
|
|
|
|
if (rect_bottom < h)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
rect.translate(5, rect.height());
|
|
|
|
rect.setHeight(h - rect_bottom);
|
|
|
|
_painter->setBrush(brushes[i & 1]);
|
|
|
|
_painter->setPen(Qt::NoPen);
|
|
|
|
_painter->drawRect(rect);
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
// Draw separator between thread names area and information area
|
|
|
|
_painter->setPen(Qt::darkGray);
|
|
|
|
_painter->drawLine(QLineF(0, h, w, h));
|
|
|
|
_painter->drawLine(QLineF(0, h + 2, w, h + 2));
|
|
|
|
|
|
|
|
// Draw information
|
|
|
|
_painter->setFont(CHRONOMETER_FONT);
|
2016-09-11 16:53:34 +03:00
|
|
|
QFontMetricsF fm(CHRONOMETER_FONT, parentView);
|
2016-09-09 00:07:27 +03:00
|
|
|
const qreal time1 = view->chronoTime();
|
|
|
|
const qreal time2 = view->chronoTimeAux();
|
|
|
|
|
|
|
|
auto y = h + 2;
|
|
|
|
|
|
|
|
auto drawTimeText = [&rect, &w, &y, &fm, &_painter](qreal time, QRgb color)
|
|
|
|
{
|
|
|
|
if (time > 0)
|
|
|
|
{
|
|
|
|
const QString text = ::profiler_gui::timeStringReal(time); // Displayed text
|
2016-09-11 16:53:34 +03:00
|
|
|
const auto th = fm.height(); // Calculate displayed text height
|
|
|
|
rect.setRect(0, y, w, th);
|
2016-09-09 00:07:27 +03:00
|
|
|
|
|
|
|
_painter->setPen(color);
|
|
|
|
_painter->drawText(rect, Qt::AlignCenter, text);
|
|
|
|
|
2016-09-11 16:53:34 +03:00
|
|
|
y += th;
|
2016-09-09 00:07:27 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-15 22:30:32 +03:00
|
|
|
drawTimeText(time1, ::profiler_gui::CHRONOMETER_COLOR.rgb() & 0x00ffffff);
|
|
|
|
drawTimeText(time2, ::profiler_gui::CHRONOMETER_COLOR2.rgb() & 0x00ffffff);
|
2016-09-08 22:42:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-11 16:53:34 +03:00
|
|
|
EasyThreadNamesWidget::EasyThreadNamesWidget(EasyGraphicsView* _view, int _additionalHeight, QWidget* _parent)
|
|
|
|
: Parent(_parent)
|
2016-09-08 22:42:35 +03:00
|
|
|
, m_view(_view)
|
2016-09-09 00:07:27 +03:00
|
|
|
, m_additionalHeight(_additionalHeight + 1)
|
2016-09-08 22:42:35 +03:00
|
|
|
{
|
2016-09-11 16:53:34 +03:00
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
setScene(new QGraphicsScene(this));
|
|
|
|
|
|
|
|
setCacheMode(QGraphicsView::CacheNone);
|
|
|
|
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setFixedWidth(100);
|
|
|
|
|
|
|
|
connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::selectedThreadChanged, this, &This::onSelectedThreadChange);
|
|
|
|
connect(m_view, &EasyGraphicsView::treeChanged, this, &This::onTreeChange);
|
2016-09-09 00:07:27 +03:00
|
|
|
connect(m_view, &EasyGraphicsView::sceneUpdated, this, &This::repaintScene);
|
2016-09-08 22:42:35 +03:00
|
|
|
connect(m_view->verticalScrollBar(), &QScrollBar::valueChanged, verticalScrollBar(), &QScrollBar::setValue);
|
2016-09-09 00:07:27 +03:00
|
|
|
connect(m_view->verticalScrollBar(), &QScrollBar::rangeChanged, this, &This::setVerticalScrollbarRange);
|
2016-09-08 22:42:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EasyThreadNamesWidget::~EasyThreadNamesWidget()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-21 22:09:04 +03:00
|
|
|
void EasyThreadNamesWidget::clear()
|
|
|
|
{
|
|
|
|
const QSignalBlocker b(this);
|
|
|
|
scene()->clear();
|
|
|
|
setFixedWidth(100);
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
void EasyThreadNamesWidget::setVerticalScrollbarRange(int _minValue, int _maxValue)
|
|
|
|
{
|
|
|
|
verticalScrollBar()->setRange(_minValue, _maxValue + m_additionalHeight);
|
|
|
|
}
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
void EasyThreadNamesWidget::onTreeChange()
|
|
|
|
{
|
2016-09-11 16:53:34 +03:00
|
|
|
const QSignalBlocker b(this);
|
2016-09-08 22:42:35 +03:00
|
|
|
scene()->clear();
|
|
|
|
|
2016-09-11 16:53:34 +03:00
|
|
|
QFontMetricsF fm(BG_FONT, this);
|
2016-09-08 22:42:35 +03:00
|
|
|
qreal maxLength = 0;
|
|
|
|
const auto& graphicsItems = m_view->getItems();
|
|
|
|
for (auto graphicsItem : graphicsItems)
|
2016-09-15 22:30:32 +03:00
|
|
|
maxLength = ::std::max(maxLength, fm.width(graphicsItem->threadName()) * ::profiler_gui::FONT_METRICS_FACTOR);
|
2016-09-08 22:42:35 +03:00
|
|
|
|
|
|
|
auto vbar = verticalScrollBar();
|
|
|
|
auto viewBar = m_view->verticalScrollBar();
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
setVerticalScrollbarRange(viewBar->minimum(), viewBar->maximum());
|
2016-09-08 22:42:35 +03:00
|
|
|
vbar->setSingleStep(viewBar->singleStep());
|
|
|
|
vbar->setPageStep(viewBar->pageStep());
|
|
|
|
|
|
|
|
auto r = m_view->sceneRect();
|
2016-09-09 00:07:27 +03:00
|
|
|
setSceneRect(0, r.top(), maxLength, r.height() + m_additionalHeight);
|
2016-09-08 22:42:35 +03:00
|
|
|
|
|
|
|
auto item = new EasyThreadNameItem();
|
|
|
|
item->setPos(0, 0);
|
|
|
|
item->setBoundingRect(sceneRect());
|
|
|
|
scene()->addItem(item);
|
|
|
|
|
|
|
|
setFixedWidth(maxLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EasyThreadNamesWidget::onSelectedThreadChange(::profiler::thread_id_t)
|
|
|
|
{
|
|
|
|
scene()->update();
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
void EasyThreadNamesWidget::repaintScene()
|
|
|
|
{
|
|
|
|
scene()->update();
|
|
|
|
}
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
void EasyThreadNamesWidget::mousePressEvent(QMouseEvent* _event)
|
|
|
|
{
|
|
|
|
QMouseEvent e(_event->type(), _event->pos() - QPointF(sceneRect().width(), 0), _event->button(), _event->buttons() & ~Qt::RightButton, _event->modifiers());
|
|
|
|
m_view->mousePressEvent(&e);
|
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EasyThreadNamesWidget::mouseDoubleClickEvent(QMouseEvent* _event)
|
|
|
|
{
|
2016-09-15 22:30:32 +03:00
|
|
|
static const auto OVERLAP = ::profiler_gui::THREADS_ROW_SPACING >> 1;
|
2016-09-08 22:42:35 +03:00
|
|
|
|
|
|
|
auto y = mapToScene(_event->pos()).y();
|
2016-08-09 00:45:45 +03:00
|
|
|
const auto& items = m_view->getItems();
|
2016-09-08 22:42:35 +03:00
|
|
|
for (auto item : items)
|
2016-08-09 00:45:45 +03:00
|
|
|
{
|
2016-09-08 22:42:35 +03:00
|
|
|
auto br = item->boundingRect();
|
|
|
|
auto top = item->y() + br.top() - OVERLAP;
|
|
|
|
auto bottom = top + br.height() + OVERLAP;
|
|
|
|
|
|
|
|
if (y < top || y > bottom)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto thread_id = item->threadId();
|
|
|
|
if (thread_id != EASY_GLOBALS.selected_thread)
|
|
|
|
{
|
|
|
|
EASY_GLOBALS.selected_thread = thread_id;
|
|
|
|
emit EASY_GLOBALS.events.selectedThreadChanged(thread_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2016-08-09 00:45:45 +03:00
|
|
|
}
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EasyThreadNamesWidget::mouseReleaseEvent(QMouseEvent* _event)
|
|
|
|
{
|
|
|
|
QMouseEvent e(_event->type(), _event->pos() - QPointF(sceneRect().width(), 0), _event->button(), _event->buttons() & ~Qt::RightButton, _event->modifiers());
|
|
|
|
m_view->mouseReleaseEvent(&e);
|
|
|
|
_event->accept();
|
2016-08-09 00:45:45 +03:00
|
|
|
}
|
2016-09-08 22:42:35 +03:00
|
|
|
|
|
|
|
void EasyThreadNamesWidget::mouseMoveEvent(QMouseEvent* _event)
|
|
|
|
{
|
|
|
|
QMouseEvent e(_event->type(), _event->pos() - QPointF(sceneRect().width(), 0), _event->button(), _event->buttons() & ~Qt::RightButton, _event->modifiers());
|
|
|
|
m_view->mouseMoveEvent(&e);
|
|
|
|
_event->accept();
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:07:27 +03:00
|
|
|
void EasyThreadNamesWidget::keyPressEvent(QKeyEvent* _event)
|
|
|
|
{
|
|
|
|
m_view->keyPressEvent(_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EasyThreadNamesWidget::keyReleaseEvent(QKeyEvent* _event)
|
|
|
|
{
|
|
|
|
m_view->keyReleaseEvent(_event);
|
|
|
|
}
|
|
|
|
|
2016-09-08 22:42:35 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|