1 /* 2 This file is part of KCachegrind. 3 4 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 5 6 SPDX-License-Identifier: GPL-2.0-only 7 */ 8 9 /* 10 * QCachegrind top level window 11 */ 12 13 #ifndef QCGTOPLEVEL_H 14 #define QCGTOPLEVEL_H 15 16 #include <QElapsedTimer> 17 #include <QLabel> 18 #include <QMainWindow> 19 #include <QStringList> 20 #include <QString> 21 22 #include "logger.h" 23 #include "traceitemview.h" 24 #include "tracedata.h" 25 #include "toplevelbase.h" 26 27 class MultiView; 28 class QDockWidget; 29 class QLabel; 30 class QComboBox; 31 class QProgressBar; 32 class QMenu; 33 34 class TraceData; 35 class MainWidget; 36 class PartSelection; 37 class FunctionSelection; 38 class StackSelection; 39 class TraceFunction; 40 41 class QCGTopLevel : public QMainWindow, public Logger, public TopLevelBase 42 { 43 Q_OBJECT 44 Q_CLASSINFO("D-Bus Interface", "io.github.qcachegrind") 45 46 public: 47 QCGTopLevel(); 48 ~QCGTopLevel() override; 49 data()50 TraceData* data() { return _data; } 51 void setData(TraceData*); 52 53 void createActions(); 54 void createDocks(); 55 void createMenu(); 56 void createToolbar(); 57 58 void closeEvent(QCloseEvent*) override; 59 groupType()60 ProfileContext::Type groupType() { return _groupType; } eventType()61 EventType* eventType() { return _eventType; } eventType2()62 EventType* eventType2() { return _eventType2; } activeParts()63 TracePartList activeParts() { return _activeParts; } hiddenParts()64 TracePartList hiddenParts() override { return _hiddenParts; } 65 66 /* convenience functions for often used context menu items */ 67 void addEventTypeMenu(QMenu*,bool) override; 68 void addGoMenu(QMenu*) override; 69 70 // Logger overwrites: notifications for file loading 71 void loadStart(const QString& filename) override; 72 void loadProgress(int progress) override; // 0 - 100 73 void loadWarning(int line, const QString& msg) override; 74 void loadError(int line, const QString& msg) override; 75 void loadFinished(const QString& msg) override; // msg could be error 76 77 public Q_SLOTS: 78 void load(); 79 void load(QStringList files, bool addToRecentFiles = true); 80 void add(); 81 void add(QStringList files); 82 83 // shows the main window before loading to see loading progress 84 void loadDelayed(QString file, bool addToRecentFiles = true); 85 void loadDelayed(QStringList files, bool addToRecentFiles = true); 86 87 void exportGraph(); 88 void newWindow(); 89 void configure(QString page = QString()); 90 void about(); 91 92 // layouts 93 void layoutDuplicate(); 94 void layoutRemove(); 95 void layoutNext(); 96 void layoutPrevious(); 97 void layoutSave(); 98 void layoutRestore(); 99 void updateLayoutActions(); 100 101 void updateStatusBar(); 102 void eventTypeSelected(const QString&); 103 void eventType2Selected(const QString&); 104 void groupTypeSelected(int); 105 void toggleSplitted(); 106 void toggleSplitDirection(); 107 void togglePartDock(); 108 void toggleStackDock(); 109 void toggleFunctionDock(); 110 void functionVisibilityChanged(bool); 111 void togglePercentage(); 112 void setPercentage(bool); 113 void setAbsoluteCost(); 114 void setRelativeCost(); 115 void toggleHideTemplates(); 116 void toggleExpanded(); 117 void toggleCycles(); 118 void recentFilesMenuAboutToShow(); 119 void recentFilesTriggered(QAction*); 120 void sidebarMenuAboutToShow(); 121 void forwardAboutToShow(); 122 void forwardTriggered(QAction*); 123 void backAboutToShow(); 124 void backTriggered(QAction*); 125 void upAboutToShow(); 126 void upTriggered(QAction*); 127 void primaryAboutToShow(); 128 void secondaryAboutToShow(); 129 void groupingAboutToShow(); 130 void windowListTriggered(QAction*); 131 void windowListAboutToShow(); 132 void macDockMenuAboutToShow(); 133 void insertWindowList(QMenu*); 134 void reinstallMacDock(); 135 136 bool setEventType(EventType*); 137 bool setEventType2(EventType*); 138 bool setEventType(QString); 139 bool setEventType2(QString); 140 bool setEventType(QAction*); 141 bool setEventType2(QAction*); 142 bool setGroupType(ProfileContext::Type); 143 bool setGroupType(QString); 144 bool setGroup(TraceCostItem*); 145 bool setGroup(QString); 146 bool setFunction(TraceFunction*); 147 bool setFunction(QString); 148 void activePartsChangedSlot(const TracePartList& list) override; 149 void partsHideSelectedSlot(); 150 void partsUnhideAllSlot(); 151 152 /* These go back to mainloop first by using a timer. 153 * So they can be called from event handlers that 154 * are not allowed to delete list entries. 155 */ 156 void setEventTypeDelayed(EventType*) override; 157 void setEventType2Delayed(EventType*) override; 158 void setGroupTypeDelayed(ProfileContext::Type) override; 159 void setGroupDelayed(TraceCostItem*) override; 160 void setTraceItemDelayed(CostItem*) override; 161 void partsHideSelectedSlotDelayed(); 162 void partsUnhideAllSlotDelayed(); 163 void goBack(); 164 void goForward(); 165 void goUp(); 166 void setDirectionDelayed(TraceItemView::Direction) override; 167 168 /* SingleShot Slots (without parameters) for the delayed versions */ 169 void setEventTypeDelayed(); 170 void setEventType2Delayed(); 171 void setGroupTypeDelayed(); 172 void setGroupDelayed(); 173 void setTraceItemDelayed(); 174 void loadFilesDelayed(); 175 void setDirectionDelayed(); 176 177 // configuration has changed 178 void configChanged() override; 179 180 //void refresh(); 181 182 // progress in status bar, empty message disables progress display 183 void showStatus(const QString& msg, int progress); 184 void showMessage(const QString&, int msec) override; 185 186 private: 187 void resetState(); 188 void createLayoutActions(); 189 void createMiscActions(); 190 void setupMainWidget(MainWidget*); 191 void setupPartSelection(PartSelection*); 192 void updateEventTypeMenu(QMenu* m, bool secondary); 193 void restoreCurrentState(const QString& postfix); 194 void saveCurrentState(const QString& postfix); 195 void saveTraceSettings(); 196 QString traceKey(); 197 void restoreTraceTypes(); 198 void restoreTraceSettings(); 199 200 QStatusBar* _statusbar; 201 QLabel* _statusLabel; 202 QString _progressMsg; 203 QElapsedTimer _progressStart; 204 QProgressBar* _progressBar; 205 206 MultiView* _multiView; 207 Qt::Orientation _spOrientation; 208 bool _twoMainWidgets; 209 FunctionSelection* _functionSelection; 210 PartSelection* _partSelection; 211 StackSelection* _stackSelection; 212 QDockWidget *_partDock, *_stackDock, *_functionDock; 213 bool _forcePartDock; 214 215 // menu/toolbar actions 216 QAction *_newAction, *_openAction, *_addAction, *_reloadAction; 217 QAction *_exportAction, *_dumpToggleAction, *_exitAction; 218 QAction *_sidebarMenuAction, *_recentFilesMenuAction; 219 QAction *_cyclesToggleAction, *_percentageToggleAction; 220 QAction *_expandedToggleAction, *_hideTemplatesToggleAction; 221 QAction *_primaryMenuAction, *_secondaryMenuAction; 222 QAction *_groupingMenuAction, *_closeAction; 223 QAction *_splittedToggleAction, *_splitDirectionToggleAction; 224 QAction *_layoutNext, *_layoutPrev, *_layoutRemove, *_layoutDup; 225 QAction *_layoutRestore, *_layoutSave, *_toolbarToggleAction; 226 QAction *_upAction, *_forwardAction, *_backAction; 227 QAction *_configureAction, *_aboutAction, *_aboutQtAction; 228 QAction *_minimizeAction, *_zoomAction; 229 QMenu *windowMenu, *macDockMenu; 230 QToolBar *tb; 231 QComboBox* _eventTypeBox; 232 233 TraceFunction* _function; 234 const QObject* _lastSender; 235 236 // trace data shown in this window 237 TraceData* _data; 238 // subcost types used for visualization 239 EventType* _eventType; 240 EventType* _eventType2; 241 QStringList _eventTypes; 242 // grouping of function list 243 ProfileContext::Type _groupType; 244 // selected group 245 TraceCostItem* _group; 246 // selected parts 247 TracePartList _activeParts; 248 // hidden parts 249 TracePartList _hiddenParts; 250 // layouts 251 int _layoutCurrent, _layoutCount; 252 // remember last file directory for new QFileDialogs 253 QString _lastFile; 254 255 // for delayed slots 256 EventType* _eventTypeDelayed; 257 EventType* _eventType2Delayed; 258 ProfileContext::Type _groupTypeDelayed; 259 TraceCostItem* _groupDelayed; 260 CostItem* _traceItemDelayed; 261 QStringList _loadFilesDelayed; 262 bool _addToRecentFiles; 263 TraceItemView::Direction _directionDelayed; 264 }; 265 266 #endif // QCGTOPLEVEL_H 267