blocks_tree_widget.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /************************************************************************
  2. * file name : blocks_tree_widget.h
  3. * ----------------- :
  4. * creation time : 2016/06/26
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains declaration of EasyTreeWidget and it's auxiliary classes
  9. * : for displyaing EasyProfiler blocks tree.
  10. * ----------------- :
  11. * change log : * 2016/06/26 Victor Zarubkin: moved sources from tree_view.h
  12. * : and renamed classes from My* to Prof*.
  13. * :
  14. * : * 2016/06/27 Victor Zarubkin: Added possibility to colorize rows
  15. * : with profiler blocks' colors.
  16. * :
  17. * : * 2016/06/29 Victor Zarubkin: Added clearSilent() method.
  18. * :
  19. * : * 2016/08/18 Victor Zarubkin: Added loading blocks hierarchy in separate thread;
  20. * : Moved sources of TreeWidgetItem into tree_widget_item.h/.cpp
  21. * ----------------- :
  22. * license : Lightweight profiler library for c++
  23. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  24. * :
  25. * : Licensed under either of
  26. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  27. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  28. * : at your option.
  29. * :
  30. * : The MIT License
  31. * :
  32. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  33. * : of this software and associated documentation files (the "Software"), to deal
  34. * : in the Software without restriction, including without limitation the rights
  35. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  36. * : of the Software, and to permit persons to whom the Software is furnished
  37. * : to do so, subject to the following conditions:
  38. * :
  39. * : The above copyright notice and this permission notice shall be included in all
  40. * : copies or substantial portions of the Software.
  41. * :
  42. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  43. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  44. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  45. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  46. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  47. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  48. * :
  49. * : The Apache License, Version 2.0 (the "License")
  50. * :
  51. * : You may not use this file except in compliance with the License.
  52. * : You may obtain a copy of the License at
  53. * :
  54. * : http://www.apache.org/licenses/LICENSE-2.0
  55. * :
  56. * : Unless required by applicable law or agreed to in writing, software
  57. * : distributed under the License is distributed on an "AS IS" BASIS,
  58. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  59. * : See the License for the specific language governing permissions and
  60. * : limitations under the License.
  61. ************************************************************************/
  62. #ifndef EASY_TREE_WIDGET_H
  63. #define EASY_TREE_WIDGET_H
  64. #include <QTreeWidget>
  65. #include <QTimer>
  66. #include "tree_widget_loader.h"
  67. #include "tree_widget_item.h"
  68. #include <easy/reader.h>
  69. //////////////////////////////////////////////////////////////////////////
  70. class EasyTreeWidget : public QTreeWidget
  71. {
  72. Q_OBJECT
  73. typedef QTreeWidget Parent;
  74. typedef EasyTreeWidget This;
  75. protected:
  76. EasyTreeWidgetLoader m_hierarchyBuilder;
  77. Items m_items;
  78. RootsMap m_roots;
  79. ::profiler_gui::TreeBlocks m_inputBlocks;
  80. QTimer m_fillTimer;
  81. QString m_lastSearch;
  82. QTreeWidgetItem* m_lastFound;
  83. ::profiler::timestamp_t m_beginTime;
  84. class QProgressDialog* m_progress;
  85. class QLabel* m_hintLabel;
  86. EasyTreeMode m_mode;
  87. bool m_bColorRows;
  88. bool m_bLocked;
  89. bool m_bSilentExpandCollapse;
  90. char m_columnsHiddenStatus[COL_COLUMNS_NUMBER];
  91. public:
  92. explicit EasyTreeWidget(QWidget* _parent = nullptr);
  93. virtual ~EasyTreeWidget();
  94. void contextMenuEvent(QContextMenuEvent* _event) override;
  95. void clearSilent(bool _global = false);
  96. int findNext(const QString& _str, Qt::MatchFlags _flags);
  97. int findPrev(const QString& _str, Qt::MatchFlags _flags);
  98. public slots:
  99. void setTree(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree);
  100. void setTreeBlocks(const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _session_begin_time, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict);
  101. protected:
  102. void resizeEvent(QResizeEvent* _event) override;
  103. void moveEvent(QMoveEvent* _event) override;
  104. private slots:
  105. void onJumpToItemClicked(bool);
  106. void onCollapseAllClicked(bool);
  107. void onExpandAllClicked(bool);
  108. void onCollapseAllChildrenClicked(bool);
  109. void onExpandAllChildrenClicked(bool);
  110. void onItemExpand(QTreeWidgetItem* _item);
  111. void onItemCollapse(QTreeWidgetItem* _item);
  112. void onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem*);
  113. void onColorizeRowsTriggered(bool _colorize);
  114. void onSelectedThreadChange(::profiler::thread_id_t _id);
  115. void onSelectedBlockChange(uint32_t _block_index);
  116. void onBlockStatusChangeClicked(bool);
  117. void resizeColumnsToContents();
  118. void onHideShowColumn(bool);
  119. void onModeChange(bool);
  120. void onFillTimerTimeout();
  121. protected:
  122. void loadSettings();
  123. void saveSettings();
  124. void alignProgressBar();
  125. }; // END of class EasyTreeWidget.
  126. //////////////////////////////////////////////////////////////////////////
  127. class EasyHierarchyWidget : public QWidget
  128. {
  129. Q_OBJECT
  130. typedef QWidget Parent;
  131. typedef EasyHierarchyWidget This;
  132. private:
  133. EasyTreeWidget* m_tree;
  134. class QLineEdit* m_searchBox;
  135. class QLabel* m_foundNumber;
  136. class QAction* m_searchButton;
  137. bool m_bCaseSensitiveSearch;
  138. public:
  139. // Public virtual methods
  140. explicit EasyHierarchyWidget(QWidget* _parent = nullptr);
  141. virtual ~EasyHierarchyWidget();
  142. void keyPressEvent(QKeyEvent* _event) override;
  143. void contextMenuEvent(QContextMenuEvent* _event) override;
  144. public:
  145. // Public non-virtual methods
  146. EasyTreeWidget* tree();
  147. void clear(bool _global = false);
  148. private slots:
  149. // Private slots
  150. void onSeachBoxReturnPressed();
  151. void findNext(bool);
  152. void findPrev(bool);
  153. void findNextFromMenu(bool);
  154. void findPrevFromMenu(bool);
  155. private:
  156. // Private non-virtual methods
  157. void loadSettings();
  158. void saveSettings();
  159. }; // END of class EasyHierarchyWidget.
  160. //////////////////////////////////////////////////////////////////////////
  161. #endif // EASY_TREE_WIDGET_H