1 /************************************************************************
2 * file name         : blocks_tree_widget.h
3 * ----------------- :
4 * creation time     : 2016/06/26
5 * author            : Victor Zarubkin
6 * email             : v.s.zarubkin@gmail.com
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 
63 #ifndef EASY_TREE_WIDGET_H
64 #define EASY_TREE_WIDGET_H
65 
66 #include <QTreeWidget>
67 #include <QTimer>
68 
69 #include "tree_widget_loader.h"
70 #include "tree_widget_item.h"
71 
72 #include <easy/reader.h>
73 
74 //////////////////////////////////////////////////////////////////////////
75 
76 class EasyTreeWidget : public QTreeWidget
77 {
78     Q_OBJECT
79 
80     typedef QTreeWidget    Parent;
81     typedef EasyTreeWidget   This;
82 
83 protected:
84 
85     EasyTreeWidgetLoader  m_hierarchyBuilder;
86     Items                            m_items;
87     RootsMap                         m_roots;
88     ::profiler_gui::TreeBlocks m_inputBlocks;
89     QTimer                       m_fillTimer;
90     QString                     m_lastSearch;
91     QTreeWidgetItem*             m_lastFound;
92     ::profiler::timestamp_t      m_beginTime;
93     class QProgressDialog*        m_progress;
94     class QLabel*                m_hintLabel;
95     EasyTreeMode                      m_mode;
96     bool                           m_bLocked;
97     bool             m_bSilentExpandCollapse;
98     char m_columnsHiddenStatus[COL_COLUMNS_NUMBER];
99 
100 public:
101 
102     explicit EasyTreeWidget(QWidget* _parent = nullptr);
103     virtual ~EasyTreeWidget();
104 
105     void contextMenuEvent(QContextMenuEvent* _event) override;
106 
107     void clearSilent(bool _global = false);
108     int findNext(const QString& _str, Qt::MatchFlags _flags);
109     int findPrev(const QString& _str, Qt::MatchFlags _flags);
110 
111 public slots:
112 
113     void setTree(const unsigned int _blocksNumber, const ::profiler::thread_blocks_tree_t& _blocksTree);
114 
115     void setTreeBlocks(const ::profiler_gui::TreeBlocks& _blocks, ::profiler::timestamp_t _session_begin_time, ::profiler::timestamp_t _left, ::profiler::timestamp_t _right, bool _strict);
116 
117 protected:
118 
119     void resizeEvent(QResizeEvent* _event) override;
120     void moveEvent(QMoveEvent* _event) override;
121 
122 private slots:
123 
124     void onJumpToItemClicked(bool);
125 
126     void onCollapseAllClicked(bool);
127 
128     void onExpandAllClicked(bool);
129 
130     void onCollapseAllChildrenClicked(bool);
131 
132     void onExpandAllChildrenClicked(bool);
133 
134     void onItemExpand(QTreeWidgetItem* _item);
135     void onItemCollapse(QTreeWidgetItem* _item);
136     void onCurrentItemChange(QTreeWidgetItem* _item, QTreeWidgetItem*);
137 
138     void onSelectedThreadChange(::profiler::thread_id_t _id);
139 
140     void onSelectedBlockChange(uint32_t _block_index);
141 
142     void onBlockStatusChangeClicked(bool);
143 
144     void resizeColumnsToContents();
145 
146     void onHideShowColumn(bool);
147     void onModeChange(bool);
148 
149     void onFillTimerTimeout();
150 
151 protected:
152 
153     void loadSettings();
154     void saveSettings();
155     void alignProgressBar();
156 
157 private:
158 
159     void destroyProgressDialog();
160     void createProgressDialog();
161 
162 }; // END of class EasyTreeWidget.
163 
164 //////////////////////////////////////////////////////////////////////////
165 
166 class EasyHierarchyWidget : public QWidget
167 {
168     Q_OBJECT
169 
170     typedef QWidget           Parent;
171     typedef EasyHierarchyWidget This;
172 
173 private:
174 
175     EasyTreeWidget*                 m_tree;
176     class QLineEdit*           m_searchBox;
177     class QLabel*            m_foundNumber;
178     class QAction*          m_searchButton;
179     bool            m_bCaseSensitiveSearch;
180 
181 public:
182 
183     // Public virtual methods
184 
185     explicit EasyHierarchyWidget(QWidget* _parent = nullptr);
186     virtual ~EasyHierarchyWidget();
187     void keyPressEvent(QKeyEvent* _event) override;
188     void contextMenuEvent(QContextMenuEvent* _event) override;
189 
190 public:
191 
192     // Public non-virtual methods
193 
194     EasyTreeWidget* tree();
195     void clear(bool _global = false);
196 
197 private slots:
198 
199     // Private slots
200 
201     void onSeachBoxReturnPressed();
202     void findNext(bool);
203     void findPrev(bool);
204     void findNextFromMenu(bool);
205     void findPrevFromMenu(bool);
206 
207 private:
208 
209     // Private non-virtual methods
210 
211     void loadSettings();
212     void saveSettings();
213 
214 }; // END of class EasyHierarchyWidget.
215 
216 
217 //////////////////////////////////////////////////////////////////////////
218 
219 #endif // EASY_TREE_WIDGET_H
220