descriptors_tree_widget.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /************************************************************************
  2. * file name : descriptors_tree_widget.h
  3. * ----------------- :
  4. * creation time : 2016/09/17
  5. * author : Victor Zarubkin
  6. * email : [email protected]
  7. * ----------------- :
  8. * description : The file contains declaration of EasyDescTreeWidget and it's auxiliary classes
  9. * : for displyaing EasyProfiler blocks descriptors tree.
  10. * ----------------- :
  11. * change log : * 2016/09/17 Victor Zarubkin: initial commit.
  12. * :
  13. * : *
  14. * ----------------- :
  15. * license : Lightweight profiler library for c++
  16. * : Copyright(C) 2016-2017 Sergey Yagovtsev, Victor Zarubkin
  17. * :
  18. * : Licensed under either of
  19. * : * MIT license (LICENSE.MIT or http://opensource.org/licenses/MIT)
  20. * : * Apache License, Version 2.0, (LICENSE.APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  21. * : at your option.
  22. * :
  23. * : The MIT License
  24. * :
  25. * : Permission is hereby granted, free of charge, to any person obtaining a copy
  26. * : of this software and associated documentation files (the "Software"), to deal
  27. * : in the Software without restriction, including without limitation the rights
  28. * : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  29. * : of the Software, and to permit persons to whom the Software is furnished
  30. * : to do so, subject to the following conditions:
  31. * :
  32. * : The above copyright notice and this permission notice shall be included in all
  33. * : copies or substantial portions of the Software.
  34. * :
  35. * : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  36. * : INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  37. * : PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  38. * : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  39. * : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  40. * : USE OR OTHER DEALINGS IN THE SOFTWARE.
  41. * :
  42. * : The Apache License, Version 2.0 (the "License")
  43. * :
  44. * : You may not use this file except in compliance with the License.
  45. * : You may obtain a copy of the License at
  46. * :
  47. * : http://www.apache.org/licenses/LICENSE-2.0
  48. * :
  49. * : Unless required by applicable law or agreed to in writing, software
  50. * : distributed under the License is distributed on an "AS IS" BASIS,
  51. * : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  52. * : See the License for the specific language governing permissions and
  53. * : limitations under the License.
  54. ************************************************************************/
  55. #ifndef EASY_DESCRIPTORS_WIDGET_H
  56. #define EASY_DESCRIPTORS_WIDGET_H
  57. #include <QTreeWidget>
  58. #include <QString>
  59. #include <vector>
  60. #include <unordered_set>
  61. #include <easy/profiler.h>
  62. //////////////////////////////////////////////////////////////////////////
  63. class EasyDescWidgetItem : public QTreeWidgetItem
  64. {
  65. typedef QTreeWidgetItem Parent;
  66. typedef EasyDescWidgetItem This;
  67. ::profiler::block_id_t m_desc;
  68. public:
  69. explicit EasyDescWidgetItem(::profiler::block_id_t _desc, Parent* _parent = nullptr);
  70. virtual ~EasyDescWidgetItem();
  71. bool operator < (const Parent& _other) const override;
  72. public:
  73. // Public inline methods
  74. inline ::profiler::block_id_t desc() const
  75. {
  76. return m_desc;
  77. }
  78. }; // END of class EasyDescWidgetItem.
  79. //////////////////////////////////////////////////////////////////////////
  80. class EasyDescTreeWidget : public QTreeWidget
  81. {
  82. Q_OBJECT
  83. typedef QTreeWidget Parent;
  84. typedef EasyDescTreeWidget This;
  85. typedef ::std::vector<EasyDescWidgetItem*> Items;
  86. typedef ::std::vector<QTreeWidgetItem*> TreeItems;
  87. typedef ::std::unordered_set<::std::string> ExpandedFiles;
  88. protected:
  89. ExpandedFiles m_expandedFilesTemp;
  90. Items m_items;
  91. TreeItems m_highlightItems;
  92. QString m_lastSearch;
  93. QTreeWidgetItem* m_lastFound;
  94. int m_lastSearchColumn;
  95. int m_searchColumn;
  96. bool m_bLocked;
  97. public:
  98. // Public virtual methods
  99. explicit EasyDescTreeWidget(QWidget* _parent = nullptr);
  100. virtual ~EasyDescTreeWidget();
  101. void contextMenuEvent(QContextMenuEvent* _event) override;
  102. public:
  103. // Public non-virtual methods
  104. int findNext(const QString& _str, Qt::MatchFlags _flags);
  105. int findPrev(const QString& _str, Qt::MatchFlags _flags);
  106. public slots:
  107. void clearSilent(bool _global = false);
  108. void build();
  109. private slots:
  110. void onSearchColumnChange(bool);
  111. void onBlockStatusChangeClicked(bool);
  112. void onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem* _prev);
  113. void onItemExpand(QTreeWidgetItem* _item);
  114. void onDoubleClick(QTreeWidgetItem* _item, int _column);
  115. void onSelectedBlockChange(uint32_t _block_index);
  116. void onBlockStatusChange(::profiler::block_id_t _id, ::profiler::EasyBlockStatus _status);
  117. void resizeColumnsToContents();
  118. private:
  119. // Private methods
  120. void resetHighlight();
  121. void loadSettings();
  122. void saveSettings();
  123. }; // END of class EasyDescTreeWidget.
  124. //////////////////////////////////////////////////////////////////////////
  125. class EasyDescWidget : public QWidget
  126. {
  127. Q_OBJECT
  128. typedef QWidget Parent;
  129. typedef EasyDescWidget This;
  130. private:
  131. EasyDescTreeWidget* m_tree;
  132. class QLineEdit* m_searchBox;
  133. class QLabel* m_foundNumber;
  134. class QAction* m_searchButton;
  135. bool m_bCaseSensitiveSearch;
  136. public:
  137. // Public virtual methods
  138. explicit EasyDescWidget(QWidget* _parent = nullptr);
  139. virtual ~EasyDescWidget();
  140. void keyPressEvent(QKeyEvent* _event) override;
  141. void contextMenuEvent(QContextMenuEvent* _event) override;
  142. public:
  143. // Public non-virtual methods
  144. void build();
  145. void clear();
  146. private slots:
  147. void onSeachBoxReturnPressed();
  148. void findNext(bool);
  149. void findPrev(bool);
  150. void findNextFromMenu(bool);
  151. void findPrevFromMenu(bool);
  152. private:
  153. // Private non-virtual slots
  154. void loadSettings();
  155. void saveSettings();
  156. }; // END of class EasyDescWidget.
  157. //////////////////////////////////////////////////////////////////////////
  158. #endif // EASY_DESCRIPTORS_WIDGET_H