File indexing completed on 2024-04-28 05:41:41
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 /* 0010 * QCachegrind top level window 0011 */ 0012 0013 #ifndef QCGTOPLEVEL_H 0014 #define QCGTOPLEVEL_H 0015 0016 #include <QElapsedTimer> 0017 #include <QLabel> 0018 #include <QMainWindow> 0019 #include <QStringList> 0020 #include <QString> 0021 0022 #include "logger.h" 0023 #include "traceitemview.h" 0024 #include "tracedata.h" 0025 #include "toplevelbase.h" 0026 0027 class MultiView; 0028 class QDockWidget; 0029 class QLabel; 0030 class QComboBox; 0031 class QProgressBar; 0032 class QMenu; 0033 0034 class TraceData; 0035 class MainWidget; 0036 class PartSelection; 0037 class FunctionSelection; 0038 class StackSelection; 0039 class TraceFunction; 0040 0041 class QCGTopLevel : public QMainWindow, public Logger, public TopLevelBase 0042 { 0043 Q_OBJECT 0044 Q_CLASSINFO("D-Bus Interface", "io.github.qcachegrind") 0045 0046 public: 0047 QCGTopLevel(); 0048 ~QCGTopLevel() override; 0049 0050 TraceData* data() { return _data; } 0051 void setData(TraceData*); 0052 0053 void createActions(); 0054 void createDocks(); 0055 void createMenu(); 0056 void createToolbar(); 0057 0058 void closeEvent(QCloseEvent*) override; 0059 0060 ProfileContext::Type groupType() { return _groupType; } 0061 EventType* eventType() { return _eventType; } 0062 EventType* eventType2() { return _eventType2; } 0063 TracePartList activeParts() { return _activeParts; } 0064 TracePartList hiddenParts() override { return _hiddenParts; } 0065 0066 /* convenience functions for often used context menu items */ 0067 void addEventTypeMenu(QMenu*,bool) override; 0068 void addGoMenu(QMenu*) override; 0069 0070 // Logger overwrites: notifications for file loading 0071 void loadStart(const QString& filename) override; 0072 void loadProgress(int progress) override; // 0 - 100 0073 void loadWarning(int line, const QString& msg) override; 0074 void loadError(int line, const QString& msg) override; 0075 void loadFinished(const QString& msg) override; // msg could be error 0076 0077 public Q_SLOTS: 0078 void load(); 0079 void load(QStringList files, bool addToRecentFiles = true); 0080 void add(); 0081 void add(QStringList files); 0082 0083 // shows the main window before loading to see loading progress 0084 void loadDelayed(QString file, bool addToRecentFiles = true); 0085 void loadDelayed(QStringList files, bool addToRecentFiles = true); 0086 0087 void exportGraph(); 0088 void newWindow(); 0089 void configure(QString page = QString()); 0090 void about(); 0091 0092 // layouts 0093 void layoutDuplicate(); 0094 void layoutRemove(); 0095 void layoutNext(); 0096 void layoutPrevious(); 0097 void layoutSave(); 0098 void layoutRestore(); 0099 void updateLayoutActions(); 0100 0101 void updateStatusBar(); 0102 void eventTypeSelected(const QString&); 0103 void eventType2Selected(const QString&); 0104 void groupTypeSelected(int); 0105 void toggleSplitted(); 0106 void toggleSplitDirection(); 0107 void togglePartDock(); 0108 void toggleStackDock(); 0109 void toggleFunctionDock(); 0110 void functionVisibilityChanged(bool); 0111 void togglePercentage(); 0112 void setPercentage(bool); 0113 void setAbsoluteCost(); 0114 void setRelativeCost(); 0115 void toggleHideTemplates(); 0116 void toggleExpanded(); 0117 void toggleCycles(); 0118 void recentFilesMenuAboutToShow(); 0119 void recentFilesTriggered(QAction*); 0120 void sidebarMenuAboutToShow(); 0121 void forwardAboutToShow(); 0122 void forwardTriggered(QAction*); 0123 void backAboutToShow(); 0124 void backTriggered(QAction*); 0125 void upAboutToShow(); 0126 void upTriggered(QAction*); 0127 void primaryAboutToShow(); 0128 void secondaryAboutToShow(); 0129 void groupingAboutToShow(); 0130 void windowListTriggered(QAction*); 0131 void windowListAboutToShow(); 0132 void macDockMenuAboutToShow(); 0133 void insertWindowList(QMenu*); 0134 void reinstallMacDock(); 0135 0136 bool setEventType(EventType*); 0137 bool setEventType2(EventType*); 0138 bool setEventType(QString); 0139 bool setEventType2(QString); 0140 bool setEventType(QAction*); 0141 bool setEventType2(QAction*); 0142 bool setGroupType(ProfileContext::Type); 0143 bool setGroupType(QString); 0144 bool setGroup(TraceCostItem*); 0145 bool setGroup(QString); 0146 bool setFunction(TraceFunction*); 0147 bool setFunction(QString); 0148 void activePartsChangedSlot(const TracePartList& list) override; 0149 void partsHideSelectedSlot(); 0150 void partsUnhideAllSlot(); 0151 0152 /* These go back to mainloop first by using a timer. 0153 * So they can be called from event handlers that 0154 * are not allowed to delete list entries. 0155 */ 0156 void setEventTypeDelayed(EventType*) override; 0157 void setEventType2Delayed(EventType*) override; 0158 void setGroupTypeDelayed(ProfileContext::Type) override; 0159 void setGroupDelayed(TraceCostItem*) override; 0160 void setTraceItemDelayed(CostItem*) override; 0161 void partsHideSelectedSlotDelayed(); 0162 void partsUnhideAllSlotDelayed(); 0163 void goBack(); 0164 void goForward(); 0165 void goUp(); 0166 void setDirectionDelayed(TraceItemView::Direction) override; 0167 0168 /* SingleShot Slots (without parameters) for the delayed versions */ 0169 void setEventTypeDelayed(); 0170 void setEventType2Delayed(); 0171 void setGroupTypeDelayed(); 0172 void setGroupDelayed(); 0173 void setTraceItemDelayed(); 0174 void loadFilesDelayed(); 0175 void setDirectionDelayed(); 0176 0177 // configuration has changed 0178 void configChanged() override; 0179 0180 //void refresh(); 0181 0182 // progress in status bar, empty message disables progress display 0183 void showStatus(const QString& msg, int progress); 0184 void showMessage(const QString&, int msec) override; 0185 0186 private: 0187 void resetState(); 0188 void createLayoutActions(); 0189 void createMiscActions(); 0190 void setupMainWidget(MainWidget*); 0191 void setupPartSelection(PartSelection*); 0192 void updateEventTypeMenu(QMenu* m, bool secondary); 0193 void restoreCurrentState(const QString& postfix); 0194 void saveCurrentState(const QString& postfix); 0195 void saveTraceSettings(); 0196 QString traceKey(); 0197 void restoreTraceTypes(); 0198 void restoreTraceSettings(); 0199 0200 QStatusBar* _statusbar; 0201 QLabel* _statusLabel; 0202 QString _progressMsg; 0203 QElapsedTimer _progressStart; 0204 QProgressBar* _progressBar; 0205 0206 MultiView* _multiView; 0207 Qt::Orientation _spOrientation; 0208 bool _twoMainWidgets; 0209 FunctionSelection* _functionSelection; 0210 PartSelection* _partSelection; 0211 StackSelection* _stackSelection; 0212 QDockWidget *_partDock, *_stackDock, *_functionDock; 0213 bool _forcePartDock; 0214 0215 // menu/toolbar actions 0216 QAction *_newAction, *_openAction, *_addAction, *_reloadAction; 0217 QAction *_exportAction, *_dumpToggleAction, *_exitAction; 0218 QAction *_sidebarMenuAction, *_recentFilesMenuAction; 0219 QAction *_cyclesToggleAction, *_percentageToggleAction; 0220 QAction *_expandedToggleAction, *_hideTemplatesToggleAction; 0221 QAction *_primaryMenuAction, *_secondaryMenuAction; 0222 QAction *_groupingMenuAction, *_closeAction; 0223 QAction *_splittedToggleAction, *_splitDirectionToggleAction; 0224 QAction *_layoutNext, *_layoutPrev, *_layoutRemove, *_layoutDup; 0225 QAction *_layoutRestore, *_layoutSave, *_toolbarToggleAction; 0226 QAction *_upAction, *_forwardAction, *_backAction; 0227 QAction *_configureAction, *_aboutAction, *_aboutQtAction; 0228 QAction *_minimizeAction, *_zoomAction; 0229 QMenu *windowMenu, *macDockMenu; 0230 QToolBar *tb; 0231 QComboBox* _eventTypeBox; 0232 0233 TraceFunction* _function; 0234 const QObject* _lastSender; 0235 0236 // trace data shown in this window 0237 TraceData* _data; 0238 // subcost types used for visualization 0239 EventType* _eventType; 0240 EventType* _eventType2; 0241 QStringList _eventTypes; 0242 // grouping of function list 0243 ProfileContext::Type _groupType; 0244 // selected group 0245 TraceCostItem* _group; 0246 // selected parts 0247 TracePartList _activeParts; 0248 // hidden parts 0249 TracePartList _hiddenParts; 0250 // layouts 0251 int _layoutCurrent, _layoutCount; 0252 // remember last file directory for new QFileDialogs 0253 QString _lastFile; 0254 0255 // for delayed slots 0256 EventType* _eventTypeDelayed; 0257 EventType* _eventType2Delayed; 0258 ProfileContext::Type _groupTypeDelayed; 0259 TraceCostItem* _groupDelayed; 0260 CostItem* _traceItemDelayed; 0261 QStringList _loadFilesDelayed; 0262 bool _addToRecentFiles; 0263 TraceItemView::Direction _directionDelayed; 0264 }; 0265 0266 #endif // QCGTOPLEVEL_H