mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 00:27:55 +08:00
added main window with both graphics view and tree widget;
* further improvement of graphics view: highly improved scene scaling and added scene drag with left mouse button pressed.
This commit is contained in:
parent
98035ae705
commit
e6c105561a
@ -19,6 +19,8 @@ add_executable(${PROJECT_NAME}
|
||||
blocks_graphics_view.cpp
|
||||
blocks_tree_widget.h
|
||||
blocks_tree_widget.cpp
|
||||
main_window.h
|
||||
main_window.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} Qt5::Widgets easy_profiler)
|
||||
|
@ -17,57 +17,71 @@
|
||||
************************************************************************/
|
||||
|
||||
#include <QWheelEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QSignalBlocker>
|
||||
#include <QScrollBar>
|
||||
#include "blocks_graphics_view.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const ProfViewGlobalSignals GLOBALS;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfGraphicsPolygonItem::ProfGraphicsPolygonItem(QGraphicsItem* _parent) : QGraphicsPolygonItem(_parent)
|
||||
ProfGraphicsPolygonItem::ProfGraphicsPolygonItem(bool _drawBorders, QGraphicsItem* _parent)
|
||||
: QGraphicsPolygonItem(_parent)
|
||||
, m_bDrawBorders(_drawBorders)
|
||||
{
|
||||
if (!_drawBorders)
|
||||
{
|
||||
setPen(QPen(Qt::NoPen));
|
||||
}
|
||||
}
|
||||
|
||||
ProfGraphicsPolygonItem::~ProfGraphicsPolygonItem()
|
||||
{
|
||||
}
|
||||
|
||||
void ProfGraphicsPolygonItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
{
|
||||
if (m_bDrawBorders)
|
||||
{
|
||||
const auto currentScale = static_cast<ProfGraphicsView*>(scene()->parent())->currentScale();
|
||||
if (boundingRect().width() * currentScale < 5)
|
||||
{
|
||||
auto linePen = pen();
|
||||
if (linePen.style() != Qt::NoPen)
|
||||
{
|
||||
linePen.setStyle(Qt::NoPen);
|
||||
setPen(linePen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto linePen = pen();
|
||||
linePen.setWidthF(1. / currentScale);
|
||||
setPen(linePen);
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsPolygonItem::paint(painter, option, widget);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfGraphicsTextItem::ProfGraphicsTextItem(const char* _text, QGraphicsItem* _parent) : QGraphicsSimpleTextItem(_text, _parent), QObject()
|
||||
ProfGraphicsTextItem::ProfGraphicsTextItem(const char* _text, QGraphicsItem* _parent)
|
||||
: QGraphicsSimpleTextItem(_text, _parent)
|
||||
{
|
||||
connect(&GLOBALS, &ProfViewGlobalSignals::scaleIncreased, this, &ProfGraphicsTextItem::onScaleIncrease);
|
||||
connect(&GLOBALS, &ProfViewGlobalSignals::scaleDecreased, this, &ProfGraphicsTextItem::onScaleDecrease);
|
||||
}
|
||||
|
||||
ProfGraphicsTextItem::~ProfGraphicsTextItem()
|
||||
{
|
||||
}
|
||||
|
||||
void ProfGraphicsTextItem::onScaleIncrease(qreal _scale)
|
||||
void ProfGraphicsTextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
{
|
||||
setScale(100.0 / _scale);
|
||||
|
||||
if (!isVisible())
|
||||
const auto currentScale = static_cast<ProfGraphicsView*>(parentItem()->scene()->parent())->currentScale();
|
||||
if (boundingRect().width() < parentItem()->boundingRect().width() * currentScale)
|
||||
{
|
||||
if (boundingRect().width() * 100.0 < parentItem()->boundingRect().width() * _scale)
|
||||
{
|
||||
show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProfGraphicsTextItem::onScaleDecrease(qreal _scale)
|
||||
{
|
||||
setScale(100.0 / _scale);
|
||||
|
||||
if (isVisible())
|
||||
{
|
||||
if (boundingRect().width() * 100.0 > parentItem()->boundingRect().width() * _scale)
|
||||
{
|
||||
hide();
|
||||
}
|
||||
painter->setTransform(QTransform::fromScale(1. / currentScale, 1), true);
|
||||
//setScale(1. / currentScale);
|
||||
QGraphicsSimpleTextItem::paint(painter, option, widget);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,15 +91,18 @@ const qreal LEFT = -2500000;
|
||||
const qreal WIDTH = 5000000;
|
||||
const int N_ITEMS = 200000;
|
||||
|
||||
ProfGraphicsScene::ProfGraphicsScene(QGraphicsView* _parent) : QGraphicsScene(_parent), m_start(0)
|
||||
ProfGraphicsScene::ProfGraphicsScene(QGraphicsView* _parent, bool _test) : QGraphicsScene(_parent), m_start(-1)
|
||||
{
|
||||
setSceneRect(QRectF(LEFT, -200, WIDTH, 220));
|
||||
test();
|
||||
if (_test)
|
||||
{
|
||||
setSceneRect(QRectF(LEFT, -200, WIDTH, 220));
|
||||
test();
|
||||
}
|
||||
}
|
||||
|
||||
ProfGraphicsScene::ProfGraphicsScene(const thread_blocks_tree_t& _blocksTree, QGraphicsView* _parent) : QGraphicsScene(_parent), m_start(0)
|
||||
ProfGraphicsScene::ProfGraphicsScene(const thread_blocks_tree_t& _blocksTree, QGraphicsView* _parent) : QGraphicsScene(_parent), m_start(-1)
|
||||
{
|
||||
setTree(_blocksTree);
|
||||
setTreeInternal(_blocksTree);
|
||||
}
|
||||
|
||||
ProfGraphicsScene::~ProfGraphicsScene()
|
||||
@ -97,7 +114,7 @@ void ProfGraphicsScene::test()
|
||||
QPolygonF poly(QRectF(-5, -180, 10, 180));
|
||||
for (int i = 0; i < N_ITEMS; ++i)
|
||||
{
|
||||
ProfGraphicsPolygonItem* item = new ProfGraphicsPolygonItem();
|
||||
ProfGraphicsPolygonItem* item = new ProfGraphicsPolygonItem(true);
|
||||
int h = 50 + rand() % 131;
|
||||
item->setPolygon(QRectF(-5, -h, 10, h));
|
||||
item->setPos(LEFT + i * 10, 0);
|
||||
@ -106,13 +123,28 @@ void ProfGraphicsScene::test()
|
||||
}
|
||||
}
|
||||
|
||||
void ProfGraphicsScene::clearSilent()
|
||||
{
|
||||
const QSignalBlocker b(this); // block all scene signals (otherwise clear() would be extremely slow!)
|
||||
clear(); // clear would be VERY SLOW if signals would not be blocked!
|
||||
}
|
||||
|
||||
void ProfGraphicsScene::setTree(const thread_blocks_tree_t& _blocksTree)
|
||||
{
|
||||
// delete all items created for previous session
|
||||
clearSilent();
|
||||
|
||||
// fill scene with new items
|
||||
m_start = -1;
|
||||
setTreeInternal(_blocksTree);
|
||||
}
|
||||
|
||||
void ProfGraphicsScene::setTreeInternal(const thread_blocks_tree_t& _blocksTree)
|
||||
{
|
||||
// calculate scene size
|
||||
profiler::timestamp_t finish = 0;
|
||||
for (const auto& threadTree : _blocksTree)
|
||||
{
|
||||
++items_couinter;
|
||||
const auto timestart = threadTree.second.children.front().node->block()->getBegin();
|
||||
const auto timefinish = threadTree.second.children.back().node->block()->getEnd();
|
||||
if (m_start > timestart) m_start = timestart;
|
||||
@ -122,58 +154,56 @@ void ProfGraphicsScene::setTree(const thread_blocks_tree_t& _blocksTree)
|
||||
const qreal endX = time2position(finish + 1000000);
|
||||
setSceneRect(QRectF(0, 0, endX, 110 * _blocksTree.size()));
|
||||
|
||||
// fill scene with items
|
||||
qreal y = 0;
|
||||
for (const auto& threadTree : _blocksTree)
|
||||
{
|
||||
setTree(threadTree.second.children, y);
|
||||
y += 110;
|
||||
setTreeInternal(threadTree.second.children, y);
|
||||
y += 110; // each thread is shifted to 110 points down
|
||||
}
|
||||
}
|
||||
|
||||
void ProfGraphicsScene::setTree(const BlocksTree::children_t& _children, qreal _y, int _level)
|
||||
void ProfGraphicsScene::setTreeInternal(const BlocksTree::children_t& _children, qreal _y, int _level)
|
||||
{
|
||||
for (const auto& child : _children)
|
||||
{
|
||||
++items_couinter;
|
||||
ProfGraphicsPolygonItem* item = new ProfGraphicsPolygonItem();
|
||||
|
||||
const qreal xbegin = time2position(child.node->block()->getBegin());
|
||||
const qreal height = 100 - _level * 5;
|
||||
qreal duration = time2position(child.node->block()->getEnd()) - xbegin;
|
||||
if (duration < 1)
|
||||
duration = 1;
|
||||
|
||||
const bool drawBorders = duration > 1;
|
||||
if (!drawBorders)
|
||||
{
|
||||
duration = 1;
|
||||
}
|
||||
|
||||
ProfGraphicsPolygonItem* item = new ProfGraphicsPolygonItem(drawBorders);
|
||||
item->setPolygon(QRectF(0, _level * 5, duration, height));
|
||||
item->setPos(xbegin, _y);
|
||||
item->setZValue(_level);
|
||||
|
||||
const auto color = child.node->block()->getColor();
|
||||
item->setBrush(QBrush(QColor(profiler::colors::get_red(color), profiler::colors::get_green(color), profiler::colors::get_blue(color))));
|
||||
item->setPen(QPen(Qt::NoPen)); // disable borders painting
|
||||
|
||||
addItem(item);
|
||||
|
||||
ProfGraphicsTextItem* text = new ProfGraphicsTextItem(child.node->getBlockName(), item);
|
||||
QRectF textRect = text->boundingRect();
|
||||
text->setPos(0, _level * 5);
|
||||
|
||||
QRectF itemRect = item->boundingRect();
|
||||
if (textRect.width() > itemRect.width())
|
||||
text->hide();
|
||||
|
||||
setTree(child.children, _y, _level + 1);
|
||||
setTreeInternal(child.children, _y, _level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfGraphicsView::ProfGraphicsView() : QGraphicsView(), m_scale(100), m_scaleCoeff(1.25)
|
||||
ProfGraphicsView::ProfGraphicsView(bool _test) : QGraphicsView(), m_scale(1), m_scaleCoeff(1.25), m_mouseButtons(Qt::NoButton)
|
||||
{
|
||||
initMode();
|
||||
setScene(new ProfGraphicsScene(this));
|
||||
setScene(new ProfGraphicsScene(this, _test));
|
||||
centerOn(0, 0);
|
||||
}
|
||||
|
||||
ProfGraphicsView::ProfGraphicsView(const thread_blocks_tree_t& _blocksTree) : QGraphicsView(), m_scale(100), m_scaleCoeff(1.25)
|
||||
ProfGraphicsView::ProfGraphicsView(const thread_blocks_tree_t& _blocksTree) : QGraphicsView(), m_scale(1), m_scaleCoeff(1.25), m_mouseButtons(Qt::NoButton)
|
||||
{
|
||||
initMode();
|
||||
setScene(new ProfGraphicsScene(_blocksTree, this));
|
||||
@ -184,29 +214,81 @@ ProfGraphicsView::~ProfGraphicsView()
|
||||
{
|
||||
}
|
||||
|
||||
void ProfGraphicsView::wheelEvent(QWheelEvent* _event)
|
||||
{
|
||||
qreal scaleCoeff;
|
||||
if (_event->delta() > 0)
|
||||
{
|
||||
scaleCoeff = m_scaleCoeff;
|
||||
}
|
||||
else
|
||||
{
|
||||
scaleCoeff = 1. / m_scaleCoeff;
|
||||
}
|
||||
|
||||
scale(scaleCoeff, 1);// scaleCoeff);
|
||||
m_scale *= scaleCoeff;
|
||||
|
||||
_event->accept();
|
||||
//QGraphicsView::wheelEvent(_event);
|
||||
}
|
||||
|
||||
void ProfGraphicsView::mousePressEvent(QMouseEvent* _event)
|
||||
{
|
||||
m_mouseButtons = _event->buttons();
|
||||
|
||||
if (m_mouseButtons & Qt::LeftButton)
|
||||
{
|
||||
m_mousePressPos = _event->globalPos();
|
||||
}
|
||||
|
||||
_event->accept();
|
||||
//QGraphicsView::mousePressEvent(_event);
|
||||
}
|
||||
|
||||
void ProfGraphicsView::mouseReleaseEvent(QMouseEvent* _event)
|
||||
{
|
||||
m_mouseButtons = _event->buttons();
|
||||
_event->accept();
|
||||
//QGraphicsView::mouseReleaseEvent(_event);
|
||||
}
|
||||
|
||||
void ProfGraphicsView::mouseMoveEvent(QMouseEvent* _event)
|
||||
{
|
||||
if (m_mouseButtons & Qt::LeftButton)
|
||||
{
|
||||
const auto pos = _event->globalPos();
|
||||
const auto delta = pos - m_mousePressPos;
|
||||
m_mousePressPos = pos;
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value() - delta.y());
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - delta.x());
|
||||
}
|
||||
|
||||
//_event->accept();
|
||||
QGraphicsView::mouseMoveEvent(_event); // This is to be able to use setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
}
|
||||
|
||||
void ProfGraphicsView::initMode()
|
||||
{
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
//setTransformationAnchor(QGraphicsView::AnchorViewCenter);
|
||||
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||
}
|
||||
|
||||
void ProfGraphicsView::wheelEvent(QWheelEvent* _event)
|
||||
void ProfGraphicsView::setTree(const thread_blocks_tree_t& _blocksTree)
|
||||
{
|
||||
//ProfGraphicsScene* myscene = (ProfGraphicsScene*)scene();
|
||||
if (_event->delta() > 0)
|
||||
{
|
||||
scale(m_scaleCoeff, m_scaleCoeff);
|
||||
m_scale *= m_scaleCoeff;
|
||||
emit GLOBALS.scaleIncreased(m_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
const qreal scaleCoeff = 1.0 / m_scaleCoeff;
|
||||
scale(scaleCoeff, scaleCoeff);
|
||||
m_scale *= scaleCoeff;
|
||||
emit GLOBALS.scaleDecreased(m_scale);
|
||||
}
|
||||
// block all signals for faster scene recreation
|
||||
const QSignalBlocker b(this);
|
||||
|
||||
// scale back to initial 100% scale
|
||||
scale(1. / m_scale, 1);
|
||||
m_scale = 1;
|
||||
|
||||
// set new blocks tree
|
||||
static_cast<ProfGraphicsScene*>(scene())->setTree(_blocksTree);
|
||||
|
||||
// center view on the beginning of the scene
|
||||
centerOn(0, 0);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -23,54 +23,35 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsPolygonItem>
|
||||
#include <QGraphicsSimpleTextItem>
|
||||
#include <QPoint>
|
||||
#include <stdlib.h>
|
||||
#include "profiler/reader.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProfViewGlobalSignals : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ProfViewGlobalSignals() : QObject() {}
|
||||
virtual ~ProfViewGlobalSignals() {}
|
||||
|
||||
signals:
|
||||
|
||||
void scaleIncreased(qreal _scale) const;
|
||||
void scaleDecreased(qreal _scale) const;
|
||||
|
||||
}; // END of class ProfViewGlobalSignals.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProfGraphicsPolygonItem : public QGraphicsPolygonItem
|
||||
{
|
||||
bool m_bDrawBorders;
|
||||
|
||||
public:
|
||||
|
||||
ProfGraphicsPolygonItem(QGraphicsItem* _parent = nullptr);
|
||||
ProfGraphicsPolygonItem(bool _drawBorders, QGraphicsItem* _parent = nullptr);
|
||||
virtual ~ProfGraphicsPolygonItem();
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = Q_NULLPTR) override;
|
||||
|
||||
}; // END of class ProfGraphicsPolygonItem.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProfGraphicsTextItem : public QObject, public QGraphicsSimpleTextItem
|
||||
class ProfGraphicsTextItem : public QGraphicsSimpleTextItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
ProfGraphicsTextItem(const char* _text, QGraphicsItem* _parent = nullptr);
|
||||
virtual ~ProfGraphicsTextItem();
|
||||
|
||||
private slots:
|
||||
|
||||
void onScaleIncrease(qreal _scale);
|
||||
|
||||
void onScaleDecrease(qreal _scale);
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = Q_NULLPTR) override;
|
||||
|
||||
}; // END of class ProfGraphicsTextItem.
|
||||
|
||||
@ -78,6 +59,8 @@ private slots:
|
||||
|
||||
class ProfGraphicsScene : public QGraphicsScene
|
||||
{
|
||||
friend class ProfGraphicsView;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
@ -86,25 +69,26 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
int items_couinter = 0;
|
||||
|
||||
ProfGraphicsScene(QGraphicsView* _parent);
|
||||
ProfGraphicsScene(QGraphicsView* _parent, bool _test = false);
|
||||
ProfGraphicsScene(const thread_blocks_tree_t& _blocksTree, QGraphicsView* _parent);
|
||||
virtual ~ProfGraphicsScene();
|
||||
|
||||
private:
|
||||
|
||||
void test();
|
||||
|
||||
void clearSilent();
|
||||
|
||||
void setTree(const thread_blocks_tree_t& _blocksTree);
|
||||
|
||||
private:
|
||||
void setTreeInternal(const thread_blocks_tree_t& _blocksTree);
|
||||
void setTreeInternal(const BlocksTree::children_t& _children, qreal _y, int _level = 0);
|
||||
|
||||
inline qreal time2position(const profiler::timestamp_t& _time) const
|
||||
{
|
||||
return qreal(_time - m_start) * 1e-6;
|
||||
}
|
||||
|
||||
void setTree(const BlocksTree::children_t& _children, qreal _y, int _level = 0);
|
||||
|
||||
}; // END of class ProfGraphicsScene.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -115,18 +99,30 @@ class ProfGraphicsView : public QGraphicsView
|
||||
|
||||
private:
|
||||
|
||||
qreal m_scale;
|
||||
qreal m_scaleCoeff;
|
||||
qreal m_scale;
|
||||
qreal m_scaleCoeff;
|
||||
QPoint m_mousePressPos;
|
||||
Qt::MouseButtons m_mouseButtons;
|
||||
|
||||
public:
|
||||
|
||||
ProfGraphicsView();
|
||||
ProfGraphicsView(bool _test = false);
|
||||
ProfGraphicsView(const thread_blocks_tree_t& _blocksTree);
|
||||
virtual ~ProfGraphicsView();
|
||||
|
||||
void initMode();
|
||||
void wheelEvent(QWheelEvent* _event) override;
|
||||
void mousePressEvent(QMouseEvent* _event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* _event) override;
|
||||
void mouseMoveEvent(QMouseEvent* _event) override;
|
||||
|
||||
void wheelEvent(QWheelEvent* _event);
|
||||
inline qreal currentScale() const
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
void setTree(const thread_blocks_tree_t& _blocksTree);
|
||||
|
||||
void initMode();
|
||||
|
||||
}; // END of class ProfGraphicsView.
|
||||
|
||||
|
@ -26,6 +26,10 @@ ProfTreeWidgetItem::ProfTreeWidgetItem(const BlocksTree* _block, QTreeWidgetItem
|
||||
{
|
||||
}
|
||||
|
||||
ProfTreeWidgetItem::~ProfTreeWidgetItem()
|
||||
{
|
||||
}
|
||||
|
||||
const BlocksTree* ProfTreeWidgetItem::block() const
|
||||
{
|
||||
return m_block;
|
||||
@ -64,13 +68,13 @@ void ProfTreeWidgetItem::setTimeMs(int _column, const ::profiler::timestamp_t& _
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfTreeWidget::ProfTreeWidget(const thread_blocks_tree_t& _blocksTree, QWidget* _parent) : QTreeWidget(_parent), m_beginTime(-1)
|
||||
ProfTreeWidget::ProfTreeWidget(QWidget* _parent) : QTreeWidget(_parent), m_beginTime(-1)
|
||||
{
|
||||
setAlternatingRowColors(true);
|
||||
setItemsExpandable(true);
|
||||
setAnimated(true);
|
||||
setSortingEnabled(false);
|
||||
setColumnCount(10);
|
||||
setColumnCount(8);
|
||||
|
||||
auto header = new QTreeWidgetItem();
|
||||
header->setText(0, "Name");
|
||||
@ -82,7 +86,10 @@ ProfTreeWidget::ProfTreeWidget(const thread_blocks_tree_t& _blocksTree, QWidget*
|
||||
header->setText(6, "Average dur.");
|
||||
header->setText(7, "N Calls");
|
||||
setHeaderItem(header);
|
||||
}
|
||||
|
||||
ProfTreeWidget::ProfTreeWidget(const thread_blocks_tree_t& _blocksTree, QWidget* _parent) : ProfTreeWidget(_parent)
|
||||
{
|
||||
setTreeInternal(_blocksTree);
|
||||
|
||||
setSortingEnabled(true);
|
||||
@ -92,6 +99,10 @@ ProfTreeWidget::ProfTreeWidget(const thread_blocks_tree_t& _blocksTree, QWidget*
|
||||
connect(this, &QTreeWidget::itemExpanded, this, &ProfTreeWidget::onItemExpand);
|
||||
}
|
||||
|
||||
ProfTreeWidget::~ProfTreeWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ProfTreeWidget::setTree(const thread_blocks_tree_t& _blocksTree)
|
||||
{
|
||||
m_itemblocks.clear();
|
||||
@ -100,6 +111,8 @@ void ProfTreeWidget::setTree(const thread_blocks_tree_t& _blocksTree)
|
||||
|
||||
disconnect(this, &QTreeWidget::itemExpanded, this, &ProfTreeWidget::onItemExpand);
|
||||
setSortingEnabled(false);
|
||||
|
||||
m_beginTime = -1;
|
||||
setTreeInternal(_blocksTree);
|
||||
|
||||
setSortingEnabled(true);
|
||||
|
@ -80,28 +80,23 @@ class ProfTreeWidgetItem : public QTreeWidgetItem
|
||||
public:
|
||||
|
||||
ProfTreeWidgetItem(const BlocksTree* _block, QTreeWidgetItem* _parent = nullptr);
|
||||
virtual ~ProfTreeWidgetItem();
|
||||
|
||||
const BlocksTree* block() const;
|
||||
|
||||
inline bool operator < (const QTreeWidgetItem& _other) const
|
||||
{
|
||||
const auto col = treeWidget()->sortColumn();
|
||||
//switch (col)
|
||||
//{
|
||||
// case 1:
|
||||
// case 2:
|
||||
// case 3:
|
||||
if (col > 0 && col < 7)
|
||||
{
|
||||
if (col > 0 && col < 7)
|
||||
{
|
||||
#ifndef _DEBUG
|
||||
return data(col, Qt::UserRole).toULongLong() < _other.data(col, Qt::UserRole).toULongLong();
|
||||
return data(col, Qt::UserRole).toULongLong() < _other.data(col, Qt::UserRole).toULongLong();
|
||||
#else
|
||||
const auto selfdata = data(col, Qt::UserRole).toULongLong();
|
||||
const auto otherdata = _other.data(col, Qt::UserRole).toULongLong();
|
||||
return selfdata < otherdata;
|
||||
const auto selfdata = data(col, Qt::UserRole).toULongLong();
|
||||
const auto otherdata = _other.data(col, Qt::UserRole).toULongLong();
|
||||
return selfdata < otherdata;
|
||||
#endif
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
return QTreeWidgetItem::operator < (_other);
|
||||
}
|
||||
@ -129,6 +124,10 @@ public:
|
||||
connect(this, &QAction::triggered, this, &ProfItemAction::onToggle);
|
||||
}
|
||||
|
||||
virtual ~ProfItemAction()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void onToggle(bool)
|
||||
@ -156,7 +155,9 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
ProfTreeWidget(QWidget* _parent = nullptr);
|
||||
ProfTreeWidget(const thread_blocks_tree_t& _blocksTree, QWidget* _parent = nullptr);
|
||||
virtual ~ProfTreeWidget();
|
||||
|
||||
void setTree(const thread_blocks_tree_t& _blocksTree);
|
||||
|
||||
@ -166,7 +167,7 @@ protected:
|
||||
|
||||
void setTreeInternal(const BlocksTree::children_t& _children, ProfTreeWidgetItem* _parent);
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* _event);
|
||||
void contextMenuEvent(QContextMenuEvent* _event) override;
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -4,13 +4,13 @@
|
||||
#include "treemodel.h"
|
||||
#include "blocks_graphics_view.h"
|
||||
#include "blocks_tree_widget.h"
|
||||
#include "main_window.h"
|
||||
#include "profiler/reader.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
|
||||
//QFileSystemModel *model = new QFileSystemModel;
|
||||
//model->setRootPath(QDir::currentPath());
|
||||
// const char* filename = 0;
|
||||
@ -31,7 +31,7 @@ int main(int argc, char **argv)
|
||||
//
|
||||
// tree->show();
|
||||
|
||||
int mode = 1;
|
||||
int mode = 2;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
@ -46,7 +46,7 @@ int main(int argc, char **argv)
|
||||
srand(*rseed);
|
||||
delete rseed;
|
||||
|
||||
ProfGraphicsView gview;
|
||||
ProfGraphicsView gview(true);
|
||||
gview.show();
|
||||
|
||||
return app.exec();
|
||||
@ -71,6 +71,13 @@ int main(int argc, char **argv)
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
ProfMainWindow window;
|
||||
window.show();
|
||||
return app.exec();
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
140
profiler_gui/main_window.cpp
Normal file
140
profiler_gui/main_window.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
/************************************************************************
|
||||
* file name : main_window.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 MainWindow for easy_profiler GUI.
|
||||
* ----------------- :
|
||||
* change log : * 2016/06/26 Victor Zarubkin: initial commit.
|
||||
* : *
|
||||
* ----------------- :
|
||||
* license : TODO: add license text
|
||||
************************************************************************/
|
||||
|
||||
#include <QStatusBar>
|
||||
#include <QDockWidget>
|
||||
#include <QFileDialog>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QToolBar>
|
||||
#include <QApplication>
|
||||
#include <thread>
|
||||
#include "main_window.h"
|
||||
#include "blocks_tree_widget.h"
|
||||
#include "blocks_graphics_view.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void graphicsViewDeleterThread(ProfGraphicsView* _widget)
|
||||
{
|
||||
delete _widget;
|
||||
}
|
||||
|
||||
void treeDeleterThread(ProfTreeWidget* _widget)
|
||||
{
|
||||
delete _widget;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graphicsView(nullptr)
|
||||
{
|
||||
setObjectName("ProfilerGUI_MainWindow");
|
||||
setWindowTitle("easy_profiler reader");
|
||||
setDockNestingEnabled(true);
|
||||
resize(800, 600);
|
||||
|
||||
setStatusBar(new QStatusBar());
|
||||
|
||||
auto graphicsView = new ProfGraphicsView();
|
||||
m_graphicsView = new QDockWidget("Blocks diagram");
|
||||
m_graphicsView->setMinimumHeight(50);
|
||||
m_graphicsView->setAllowedAreas(Qt::AllDockWidgetAreas);
|
||||
m_graphicsView->setWidget(graphicsView);
|
||||
|
||||
auto treeWidget = new ProfTreeWidget();
|
||||
m_treeWidget = new QDockWidget("Blocks hierarchy");
|
||||
m_treeWidget->setMinimumHeight(50);
|
||||
m_treeWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
|
||||
m_treeWidget->setWidget(treeWidget);
|
||||
|
||||
addDockWidget(Qt::TopDockWidgetArea, m_graphicsView);
|
||||
addDockWidget(Qt::BottomDockWidgetArea, m_treeWidget);
|
||||
|
||||
auto actionOpen = new QAction("Open", nullptr);
|
||||
connect(actionOpen, &QAction::triggered, this, &ProfMainWindow::onOpenFileClicked);
|
||||
|
||||
auto actionReload = new QAction("Reload", nullptr);
|
||||
connect(actionReload, &QAction::triggered, this, &ProfMainWindow::onReloadFileClicked);
|
||||
|
||||
auto actionExit = new QAction("Exit", nullptr);
|
||||
connect(actionExit, &QAction::triggered, this, &ProfMainWindow::onExitClicked);
|
||||
|
||||
auto menuFile = new QMenu("File");
|
||||
menuFile->addAction(actionOpen);
|
||||
menuFile->addAction(actionReload);
|
||||
menuFile->addSeparator();
|
||||
menuFile->addAction(actionExit);
|
||||
|
||||
menuBar()->addMenu(menuFile);
|
||||
}
|
||||
|
||||
ProfMainWindow::~ProfMainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ProfMainWindow::onOpenFileClicked(bool)
|
||||
{
|
||||
auto filename = QFileDialog::getOpenFileName(this, "Open profiler log", m_lastFile.c_str(), "Profiler Log File (*.prof);;All Files (*.*)");
|
||||
auto stdfilename = filename.toStdString();
|
||||
|
||||
thread_blocks_tree_t prof_blocks;
|
||||
auto nblocks = fillTreesFromFile(stdfilename.c_str(), prof_blocks, true);
|
||||
|
||||
if (nblocks > 0)
|
||||
{
|
||||
m_lastFile.swap(stdfilename);
|
||||
m_currentProf.swap(prof_blocks);
|
||||
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(m_currentProf);
|
||||
static_cast<ProfGraphicsView*>(m_graphicsView->widget())->setTree(m_currentProf);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ProfMainWindow::onReloadFileClicked(bool)
|
||||
{
|
||||
if (m_lastFile.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
thread_blocks_tree_t prof_blocks;
|
||||
auto nblocks = fillTreesFromFile(m_lastFile.c_str(), prof_blocks, true);
|
||||
|
||||
if (nblocks > 0)
|
||||
{
|
||||
m_currentProf.swap(prof_blocks);
|
||||
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(m_currentProf);
|
||||
static_cast<ProfGraphicsView*>(m_graphicsView->widget())->setTree(m_currentProf);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ProfMainWindow::onExitClicked(bool)
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
56
profiler_gui/main_window.h
Normal file
56
profiler_gui/main_window.h
Normal file
@ -0,0 +1,56 @@
|
||||
/************************************************************************
|
||||
* file name : main_window.h
|
||||
* ----------------- :
|
||||
* creation time : 2016/06/26
|
||||
* copyright : (c) 2016 Victor Zarubkin
|
||||
* author : Victor Zarubkin
|
||||
* email : v.s.zarubkin@gmail.com
|
||||
* ----------------- :
|
||||
* description : The file contains declaration of MainWindow for easy_profiler GUI.
|
||||
* ----------------- :
|
||||
* change log : * 2016/06/26 Victor Zarubkin: initial commit.
|
||||
* : *
|
||||
* ----------------- :
|
||||
* license : TODO: add license text
|
||||
************************************************************************/
|
||||
|
||||
#ifndef EASY_PROFILER_GUI__MAIN_WINDOW__H
|
||||
#define EASY_PROFILER_GUI__MAIN_WINDOW__H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <string>
|
||||
#include "profiler/reader.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProfTreeWidget;
|
||||
class ProfGraphicsView;
|
||||
class QDockWidget;
|
||||
|
||||
class ProfMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
|
||||
::std::string m_lastFile;
|
||||
thread_blocks_tree_t m_currentProf;
|
||||
QDockWidget* m_treeWidget;
|
||||
QDockWidget* m_graphicsView;
|
||||
|
||||
public:
|
||||
|
||||
ProfMainWindow();
|
||||
virtual ~ProfMainWindow();
|
||||
|
||||
protected slots:
|
||||
|
||||
void onOpenFileClicked(bool);
|
||||
void onReloadFileClicked(bool);
|
||||
void onExitClicked(bool);
|
||||
|
||||
}; // END of class ProfMainWindow.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // EASY_PROFILER_GUI__MAIN_WINDOW__H
|
Loading…
x
Reference in New Issue
Block a user