00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2015, Southwest Research Institute® (SwRI®) 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above copyright 00011 // notice, this list of conditions and the following disclaimer in the 00012 // documentation and/or other materials provided with the distribution. 00013 // * Neither the name of Southwest Research Institute® (SwRI®) nor the 00014 // names of its contributors may be used to endorse or promote products 00015 // derived from this software without specific prior written permission. 00016 // 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE 00021 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00023 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00024 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00027 // DAMAGE. 00028 // 00029 // ***************************************************************************** 00030 #ifndef SWRI_PROFILER_TOOLS_PROFILE_TREE_WIDGET_H_ 00031 #define SWRI_PROFILER_TOOLS_PROFILE_TREE_WIDGET_H_ 00032 00033 #include <unordered_map> 00034 00035 #include <QWidget> 00036 #include <swri_profiler_tools/database_key.h> 00037 00038 QT_BEGIN_NAMESPACE 00039 class QPoint; 00040 class QTreeWidget; 00041 class QTreeWidgetItem; 00042 QT_END_NAMESPACE 00043 00044 namespace swri_profiler_tools 00045 { 00046 class ProfileDatabase; 00047 class Profile; 00048 00049 class ProfileTreeWidget : public QWidget 00050 { 00051 Q_OBJECT; 00052 00053 ProfileDatabase *db_; 00054 QTreeWidget *tree_widget_; 00055 00056 DatabaseKey active_key_; 00057 std::unordered_map<DatabaseKey, QTreeWidgetItem*> items_; 00058 00059 public: 00060 ProfileTreeWidget(QWidget *parent=0); 00061 ~ProfileTreeWidget(); 00062 00063 void setDatabase(ProfileDatabase *db); 00064 00065 Q_SIGNALS: 00066 void activeNodeChanged(int profile_key, int node_key); 00067 00068 public Q_SLOTS: 00069 void setActiveNode(int profile_key, int node_key); 00070 00071 private Q_SLOTS: 00072 void handleProfileAdded(int profile_key); 00073 void handleNodesAdded(int profile_key); 00074 00075 void handleItemActivated(QTreeWidgetItem *item, int column); 00076 void handleTreeContextMenuRequest(const QPoint &pos); 00077 00078 private: 00079 void synchronizeWidget(); 00080 void addProfile(int profile_key); 00081 void addNode(QTreeWidgetItem *parent, const Profile &profile, const int node_key); 00082 00083 QString nameForKey(const DatabaseKey &key) const; 00084 void markItemActive(const DatabaseKey &key); 00085 void markItemInactive(const DatabaseKey &key); 00086 }; // class ProfileTreeWidget 00087 } // namespace swri_profiler_tools 00088 #endif // SWRI_PROFILER_TOOLS_PROFILE_TREE_WIDGET_H_ 00089 00090