2016-06-26 18:56:40 +03:00
|
|
|
/************************************************************************
|
|
|
|
* 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
|
2016-06-26 19:06:53 +03:00
|
|
|
* : and renamed classes from My* to Prof*.
|
2016-06-27 22:11:26 +03:00
|
|
|
* : * 2016/06/27 Victor Zarubkin: Added possibility to colorize rows
|
|
|
|
* : with profiler blocks' colors.
|
2016-06-26 18:56:40 +03:00
|
|
|
* : *
|
|
|
|
* ----------------- :
|
|
|
|
* license : TODO: add license text
|
|
|
|
************************************************************************/
|
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>
|
2016-06-27 22:11:26 +03:00
|
|
|
#include <vector>
|
2016-06-26 18:46:51 +03:00
|
|
|
#include "profiler/reader.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
namespace btw {
|
|
|
|
|
|
|
|
template <const size_t SIZEOF_T>
|
|
|
|
struct no_hasher {
|
|
|
|
template <class T> inline size_t operator () (const T& _data) const {
|
|
|
|
return (size_t)_data;
|
|
|
|
}
|
|
|
|
};
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
#ifdef _WIN64
|
2016-06-26 19:06:53 +03:00
|
|
|
template <> struct no_hasher<8> {
|
|
|
|
template <class T> inline size_t operator () (T _data) const {
|
|
|
|
return (size_t)_data;
|
|
|
|
}
|
|
|
|
};
|
2016-06-26 18:46:51 +03:00
|
|
|
#endif
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
template <> struct no_hasher<4> {
|
|
|
|
template <class T> inline size_t operator () (T _data) const {
|
|
|
|
return (size_t)_data;
|
|
|
|
}
|
|
|
|
};
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
template <> struct no_hasher<2> {
|
|
|
|
template <class T> inline size_t operator () (T _data) const {
|
|
|
|
return (size_t)_data;
|
|
|
|
}
|
|
|
|
};
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
template <> struct no_hasher<1> {
|
|
|
|
template <class T> inline size_t operator () (T _data) const {
|
|
|
|
return (size_t)_data;
|
|
|
|
}
|
|
|
|
};
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
template <class T>
|
|
|
|
struct do_no_hash {
|
|
|
|
typedef no_hasher<sizeof(T)> hasher_t;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // END of namespace btw.
|
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
|
|
|
{
|
2016-06-27 22:11:26 +03:00
|
|
|
typedef QTreeWidgetItem Parent;
|
|
|
|
typedef ProfTreeWidgetItem This;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
const BlocksTree* m_block;
|
2016-06-27 22:11:26 +03:00
|
|
|
QBrush m_customBGColor;
|
|
|
|
QBrush m_customTextColor;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
using Parent::setBackgroundColor;
|
|
|
|
using Parent::setTextColor;
|
|
|
|
|
|
|
|
ProfTreeWidgetItem(const BlocksTree* _treeBlock, Parent* _parent = nullptr);
|
2016-06-26 20:54:16 +03:00
|
|
|
virtual ~ProfTreeWidgetItem();
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
bool operator < (const Parent& _other) const override;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
const BlocksTree* block() 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);
|
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
void setBackgroundColor(const QColor& _color);
|
|
|
|
|
|
|
|
void setTextColor(const QColor& _color);
|
|
|
|
|
|
|
|
void colorize(bool _colorize);
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
}; // END of class ProfTreeWidgetItem.
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
class ProfItemAction : public QAction
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
ProfTreeWidgetItem* m_item;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
ProfItemAction(const char* _label, ProfTreeWidgetItem* _item) : QAction(_label, nullptr), m_item(_item)
|
2016-06-26 18:46:51 +03:00
|
|
|
{
|
2016-06-26 19:06:53 +03:00
|
|
|
connect(this, &QAction::triggered, this, &ProfItemAction::onToggle);
|
2016-06-26 18:46:51 +03:00
|
|
|
}
|
|
|
|
|
2016-06-26 20:54:16 +03:00
|
|
|
virtual ~ProfItemAction()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-26 18:46:51 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
void onToggle(bool)
|
|
|
|
{
|
|
|
|
emit clicked(m_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
void clicked(ProfTreeWidgetItem* _item);
|
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
|
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
typedef QTreeWidget Parent;
|
|
|
|
typedef ProfTreeWidget This;
|
|
|
|
|
2016-06-26 18:46:51 +03:00
|
|
|
protected:
|
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
typedef ::std::vector<ProfTreeWidgetItem*> Items;
|
2016-06-26 19:06:53 +03:00
|
|
|
typedef ::std::unordered_map<const ::profiler::SerilizedBlock*, ProfTreeWidgetItem*, ::btw::do_no_hash<const ::profiler::SerilizedBlock*>::hasher_t> BlockItemMap;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
Items m_items;
|
2016-06-26 18:46:51 +03:00
|
|
|
BlockItemMap m_itemblocks;
|
|
|
|
::profiler::timestamp_t m_beginTime;
|
2016-06-27 22:11:26 +03:00
|
|
|
bool m_bColorRows;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-06-26 20:54:16 +03:00
|
|
|
ProfTreeWidget(QWidget* _parent = nullptr);
|
2016-06-27 22:11:26 +03:00
|
|
|
ProfTreeWidget(const unsigned int _blocksNumber, const thread_blocks_tree_t& _blocksTree, QWidget* _parent = nullptr);
|
2016-06-26 20:54:16 +03:00
|
|
|
virtual ~ProfTreeWidget();
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
void setTree(const unsigned int _blocksNumber, const thread_blocks_tree_t& _blocksTree);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
void setTreeInternal(const unsigned int _blocksNumber, const thread_blocks_tree_t& _blocksTree);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
void setTreeInternal(const BlocksTree::children_t& _children, ProfTreeWidgetItem* _parent);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-26 20:54:16 +03:00
|
|
|
void contextMenuEvent(QContextMenuEvent* _event) override;
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
void onJumpToMinItemClicked(ProfTreeWidgetItem* _item);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
2016-06-26 19:06:53 +03:00
|
|
|
void onJumpToMaxItemClicked(ProfTreeWidgetItem* _item);
|
2016-06-26 18:46:51 +03:00
|
|
|
|
|
|
|
void onCollapseAllClicked(bool);
|
|
|
|
|
|
|
|
void onExpandAllClicked(bool);
|
|
|
|
|
|
|
|
void onItemExpand(QTreeWidgetItem*);
|
|
|
|
|
2016-06-27 22:11:26 +03:00
|
|
|
void onColorizeRowsTriggered(bool _colorize);
|
|
|
|
|
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
|