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

189 lines
4.9 KiB
C
Raw Normal View History

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-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>
#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
{
//Q_OBJECT
const BlocksTree* m_block;
public:
2016-06-26 19:06:53 +03:00
ProfTreeWidgetItem(const BlocksTree* _block, QTreeWidgetItem* _parent = nullptr);
virtual ~ProfTreeWidgetItem();
2016-06-26 18:46:51 +03:00
const BlocksTree* block() const;
inline bool operator < (const QTreeWidgetItem& _other) const
{
const auto col = treeWidget()->sortColumn();
if (col > 0 && col < 7)
{
2016-06-26 18:46:51 +03:00
#ifndef _DEBUG
return data(col, Qt::UserRole).toULongLong() < _other.data(col, Qt::UserRole).toULongLong();
2016-06-26 18:46:51 +03:00
#else
const auto selfdata = data(col, Qt::UserRole).toULongLong();
const auto otherdata = _other.data(col, Qt::UserRole).toULongLong();
return selfdata < otherdata;
2016-06-26 18:46:51 +03:00
#endif
}
2016-06-26 18:46:51 +03:00
return QTreeWidgetItem::operator < (_other);
}
void setTimeSmart(int _column, const ::profiler::timestamp_t& _time);
void setTimeMs(int _column, const ::profiler::timestamp_t& _time);
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
}
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
protected:
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
BlockItemMap m_itemblocks;
::profiler::timestamp_t m_beginTime;
public:
ProfTreeWidget(QWidget* _parent = nullptr);
2016-06-26 19:06:53 +03:00
ProfTreeWidget(const thread_blocks_tree_t& _blocksTree, QWidget* _parent = nullptr);
virtual ~ProfTreeWidget();
2016-06-26 18:46:51 +03:00
void setTree(const thread_blocks_tree_t& _blocksTree);
protected:
void setTreeInternal(const thread_blocks_tree_t& _blocksTree);
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
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-26 19:06:53 +03:00
}; // END of class ProfTreeWidget.
2016-06-26 18:46:51 +03:00
//////////////////////////////////////////////////////////////////////////
#endif // MY____TREE___VIEW_H