0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00
easy_profiler/profiler_gui/blocks_tree_widget.h

178 lines
5.7 KiB
C
Raw Normal View History

/************************************************************************
* file name : blocks_tree_widget.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 TreeWidget and it's auxiliary classes
* : for displyaing easy_profiler blocks tree.
* ----------------- :
* change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h
* : and renamed classes from My* to Prof*.
* :
* : * 2016/06/27 Victor Zarubkin: Added possibility to colorize rows
* : with profiler blocks' colors.
* :
* : * 2016/06/29 Victor Zarubkin: Added clearSilent() method.
* :
* : *
* ----------------- :
* license : TODO: add license text
2016-06-26 18:56:40 +03:00
************************************************************************/
2016-06-26 18:46:51 +03:00
#ifndef MY____TREE___VIEW_H
#define MY____TREE___VIEW_H
#include <QTreeWidget>
#include <QAction>
#include <stdlib.h>
#include <unordered_map>
#include <vector>
2016-06-26 18:46:51 +03:00
#include "profiler/reader.h"
#include "common_types.h"
2016-06-26 18:46:51 +03:00
//////////////////////////////////////////////////////////////////////////
2016-06-26 19:06:53 +03:00
class ProfTreeWidgetItem : public QTreeWidgetItem
2016-06-26 18:46:51 +03:00
{
typedef QTreeWidgetItem Parent;
typedef ProfTreeWidgetItem This;
2016-06-26 18:46:51 +03:00
const ::profiler::BlocksTree* m_block;
QRgb m_customBGColor;
QRgb m_customTextColor;
2016-06-26 18:46:51 +03:00
public:
using Parent::setBackgroundColor;
using Parent::setTextColor;
ProfTreeWidgetItem(const ::profiler::BlocksTree* _treeBlock, Parent* _parent = nullptr);
virtual ~ProfTreeWidgetItem();
2016-06-26 18:46:51 +03:00
bool operator < (const Parent& _other) const override;
2016-06-26 18:46:51 +03:00
public:
const ::profiler::BlocksTree* block() const;
::profiler::timestamp_t duration() const;
::profiler::timestamp_t selfDuration() const;
2016-06-26 18:46:51 +03:00
void setTimeSmart(int _column, const ::profiler::timestamp_t& _time);
void setTimeMs(int _column, const ::profiler::timestamp_t& _time);
void setBackgroundColor(QRgb _color);
void setTextColor(QRgb _color);
void colorize(bool _colorize);
void collapseAll();
void expandAll();
2016-06-26 19:06:53 +03:00
}; // END of class ProfTreeWidgetItem.
2016-06-26 18:46:51 +03:00
//////////////////////////////////////////////////////////////////////////
#define DECLARE_QACTION(ClassName, DataType) \
class ClassName : public QAction { \
Q_OBJECT \
private: \
DataType m_item; \
public: \
ClassName(const char* _label, DataType _item) : QAction(_label, nullptr), m_item(_item) { \
connect(this, &QAction::triggered, this, &ClassName::onToggle); } \
ClassName(const QString& _label, DataType _item) : QAction(_label, nullptr), m_item(_item) { \
connect(this, &QAction::triggered, this, &ClassName::onToggle); } \
virtual ~ClassName() {}\
private: \
void onToggle(bool) { emit clicked(m_item); }
DECLARE_QACTION(ProfItemAction, unsigned int) signals: void clicked(unsigned int _item); };
DECLARE_QACTION(ProfHideShowColumnAction, int) signals: void clicked(int _item); };
#undef DECLARE_QACTION
2016-06-26 18:46:51 +03:00
//////////////////////////////////////////////////////////////////////////
2016-06-26 19:06:53 +03:00
class ProfTreeWidget : public QTreeWidget
2016-06-26 18:46:51 +03:00
{
Q_OBJECT
typedef QTreeWidget Parent;
typedef ProfTreeWidget This;
2016-06-26 18:46:51 +03:00
protected:
typedef ::std::vector<ProfTreeWidgetItem*> Items;
typedef ::std::unordered_map<::profiler::thread_id_t, ProfTreeWidgetItem*, ::profiler_gui::do_no_hash<::profiler::thread_id_t>::hasher_t> RootsMap;
2016-06-26 18:46:51 +03:00
Items m_items;
RootsMap m_roots;
2016-06-26 18:46:51 +03:00
::profiler::timestamp_t m_beginTime;
bool m_bColorRows;
2016-06-26 18:46:51 +03:00
public:
ProfTreeWidget(QWidget* _parent = nullptr);
ProfTreeWidget(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree, QWidget* _parent = nullptr);
virtual ~ProfTreeWidget();
2016-06-26 18:46:51 +03:00
void clearSilent(bool _global = false);
2016-06-26 18:46:51 +03:00
public slots:
void setTree(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree);
void setTreeBlocks(const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _session_begin_time, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict);
2016-06-26 18:46:51 +03:00
protected:
size_t setTreeInternal(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree);
2016-06-26 18:46:51 +03:00
size_t setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict);
size_t setTreeInternal(const ::profiler::BlocksTree::children_t& _children, ProfTreeWidgetItem* _parent, ProfTreeWidgetItem* _frame, ProfTreeWidgetItem* _thread, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict, ::profiler::timestamp_t& _duration);
2016-06-26 18:46:51 +03:00
void contextMenuEvent(QContextMenuEvent* _event) override;
2016-06-26 18:46:51 +03:00
private slots:
void onJumpToItemClicked(unsigned int _block_index);
2016-06-26 18:46:51 +03:00
void onCollapseAllClicked(bool);
void onExpandAllClicked(bool);
void onCollapseAllChildrenClicked(bool);
void onExpandAllChildrenClicked(bool);
2016-06-26 18:46:51 +03:00
void onItemExpand(QTreeWidgetItem*);
void onColorizeRowsTriggered(bool _colorize);
void onSelectedThreadChange(::profiler::thread_id_t _id);
void onSelectedBlockChange(unsigned int _block_index);
void resizeColumnsToContents();
void onHideShowColumn(int _column);
protected:
void loadSettings();
void saveSettings();
2016-06-26 19:06:53 +03:00
}; // END of class ProfTreeWidget.
2016-06-26 18:46:51 +03:00
//////////////////////////////////////////////////////////////////////////
#endif // MY____TREE___VIEW_H