File indexing completed on 2024-04-28 05:41:23

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  * KCachegrind top level window
0011  */
0012 
0013 #ifndef TOPLEVEL_H
0014 #define TOPLEVEL_H
0015 
0016 #include <QElapsedTimer>
0017 #include <QLabel>
0018 #include <QProcess>
0019 #include <QUrl>
0020 
0021 #include <KXmlGuiWindow>
0022 
0023 #include "logger.h"
0024 #include "traceitemview.h"
0025 #include "tracedata.h"
0026 #include "toplevelbase.h"
0027 
0028 class MultiView;
0029 class QLineEdit;
0030 class QDockWidget;
0031 class QLabel;
0032 class QProgressBar;
0033 class QMenu;
0034 
0035 class QUrl;
0036 class KSelectAction;
0037 class KToggleAction;
0038 class KToolBarPopupAction;
0039 class KStatusBar;
0040 
0041 class TraceData;
0042 class KRecentFilesAction;
0043 class MainWidget;
0044 class PartSelection;
0045 class FunctionSelection;
0046 class DumpSelection;
0047 class StackSelection;
0048 class TraceFunction;
0049 
0050 class TopLevel : public KXmlGuiWindow, public Logger, public TopLevelBase
0051 {
0052     Q_OBJECT
0053     Q_CLASSINFO("D-Bus Interface", "org.kde.kcachegrind")
0054 public:
0055     TopLevel();
0056     ~TopLevel() override;
0057 
0058     TraceData* data() { return _data; }
0059     void setData(TraceData*);
0060 
0061     void saveProperties(KConfigGroup &) override;
0062     void readProperties(const KConfigGroup &) override;
0063 
0064     void createActions();
0065     void createDocks();
0066 
0067     ProfileContext::Type groupType() { return _groupType; }
0068     EventType* eventType() { return _eventType; }
0069     EventType* eventType2() { return _eventType2; }
0070     TracePartList activeParts() { return _activeParts; }
0071     TracePartList hiddenParts() override { return _hiddenParts; }
0072 
0073     // current config
0074     bool showPercentage() const { return _showPercentage; }
0075     bool showExpanded() const { return _showExpanded; }
0076     bool showCycles() const { return _showCycles; }
0077 
0078     /* convenience functions for often used context menu items */
0079     void addEventTypeMenu(QMenu*,bool) override;
0080     void addGoMenu(QMenu*) override;
0081 
0082     // Logger overwrites: notifications for file loading
0083     void loadStart(const QString& filename) override;
0084     void loadProgress(int progress) override; // 0 - 100
0085     void loadWarning(int line, const QString& msg) override;
0086     void loadError(int line, const QString& msg) override;
0087     void loadFinished(const QString& msg) override; // msg could be error
0088 
0089 public Q_SLOTS:
0090     void load();
0091     void load(const QUrl&);
0092     void load(QString);
0093     void add();
0094     void add(const QUrl&);
0095     void add(QString);
0096 
0097     // for quickly showing the main window...
0098     void loadDelayed(QString);
0099     void loadDelayed(QStringList);
0100 
0101     void reload();
0102     void exportGraph();
0103     void newWindow();
0104     void configure();
0105     void querySlot();
0106     void dummySlot();
0107 
0108     // layouts
0109     void layoutDuplicate();
0110     void layoutRemove();
0111     void layoutNext();
0112     void layoutPrevious();
0113     void layoutSave();
0114     void layoutRestore();
0115     void updateLayoutActions();
0116 
0117     void updateStatusBar();
0118     void eventTypeSelected(const QString&);
0119     void eventType2Selected(const QString&);
0120     void groupTypeSelected(int);
0121     void splitSlot();
0122     void splitDirSlot();
0123     void configureToolbars() override;
0124     void configureKeys();
0125     bool queryClose() override;
0126     void togglePartDock();
0127     void toggleStackDock();
0128     void toggleFunctionDock();
0129     void toggleDumpDock();
0130     void toggleStatusBar();
0131     void partVisibilityChanged(bool);
0132     void dumpVisibilityChanged(bool);
0133     void stackVisibilityChanged(bool);
0134     void functionVisibilityChanged(bool);
0135     void togglePercentage();
0136     void setPercentage(bool);
0137     void setAbsoluteCost();
0138     void setRelativeCost();
0139     void toggleExpanded();
0140     void toggleCycles();
0141     void toggleHideTemplates();
0142     void forceTrace();
0143     void forwardAboutToShow();
0144     void forwardTriggered(QAction*);
0145     void backAboutToShow();
0146     void backTriggered(QAction*);
0147     void upAboutToShow();
0148     void upTriggered(QAction*);
0149 
0150     bool setEventType(EventType*);
0151     bool setEventType2(EventType*);
0152     bool setEventType(QString);
0153     bool setEventType2(QString);
0154     bool setEventType(QAction*);
0155     bool setEventType2(QAction*);
0156     bool setGroupType(ProfileContext::Type);
0157     bool setGroupType(QString);
0158     bool setGroup(TraceCostItem*);
0159     bool setGroup(QString);
0160     bool setFunction(TraceFunction*);
0161     bool setFunction(QString);
0162     void activePartsChangedSlot(const TracePartList& list) override;
0163     void partsHideSelectedSlot();
0164     void partsUnhideAllSlot();
0165 
0166     /* These go back to mainloop first by using a timer.
0167      * So they can be called from event handlers that
0168      * are not allowed to delete list entries.
0169      */
0170     void setEventTypeDelayed(EventType*) override;
0171     void setEventType2Delayed(EventType*) override;
0172     void setGroupTypeDelayed(ProfileContext::Type) override;
0173     void setGroupDelayed(TraceCostItem*) override;
0174     void setTraceItemDelayed(CostItem*) override;
0175     void partsHideSelectedSlotDelayed();
0176     void partsUnhideAllSlotDelayed();
0177     void goBack();
0178     void goForward();
0179     void goUp();
0180     void setDirectionDelayed(TraceItemView::Direction) override;
0181 
0182     /* SingleShot Slots (without parameters) for the delayed versions */
0183     void setEventTypeDelayed();
0184     void setEventType2Delayed();
0185     void setGroupTypeDelayed();
0186     void setGroupDelayed();
0187     void setTraceItemDelayed();
0188     void loadTraceDelayed();
0189     void setDirectionDelayed();
0190 
0191     // configuration has changed
0192     void configChanged() override;
0193 
0194     //void refresh();
0195 
0196     // progress in status bar, empty message disables progress display
0197     void showStatus(const QString& msg, int progress);
0198     void showMessage(const QString&, int msec) override;
0199 
0200     // for running callgrind_control in the background
0201     void ccReadOutput();
0202     void ccError(QProcess::ProcessError);
0203     void ccExit(int,QProcess::ExitStatus);
0204 
0205 private:
0206     void resetState();
0207     void createLayoutActions();
0208     void createMiscActions();
0209     void setupMainWidget(MainWidget*);
0210     void setupPartSelection(PartSelection*);
0211     void restoreCurrentState(const QString& postfix);
0212     void saveCurrentState(const QString& postfix);
0213     void saveTraceSettings();
0214     QString traceKey();
0215     void restoreTraceTypes();
0216     void restoreTraceSettings();
0217     void updateViewsOnChange(int);
0218     /// open @p file, might be compressed
0219     /// @return true when the file could be opened, false otherwise.
0220     bool openDataFile(const QString& file);
0221 
0222     QStatusBar* _statusbar;
0223     QLabel* _statusLabel;
0224     KRecentFilesAction* _openRecent;
0225     bool _twoMainWidgets;
0226     Qt::Orientation _spOrientation;
0227 
0228     MultiView* _multiView;
0229     FunctionSelection* _functionSelection;
0230     DumpSelection* _dumpSelection;
0231     PartSelection* _partSelection;
0232     StackSelection* _stackSelection;
0233     QLineEdit* queryLineEdit;
0234 
0235     QDockWidget *_partDock, *_stackDock, *_functionDock, *_dumpDock;
0236     bool _forcePartDock;
0237 
0238     KSelectAction *_saCost, *_saCost2, *saGroup;
0239     KToggleAction *_partDockShown, *_stackDockShown;
0240     KToggleAction *_functionDockShown, *_dumpDockShown;
0241     KToggleAction *_taPercentage, *_taExpanded, *_taCycles, *_taHideTemplates;
0242     KToggleAction *_taDump, *_taSplit, *_taSplitDir;
0243     KToolBarPopupAction *_paForward, *_paBack, *_paUp;
0244 
0245     TraceFunction* _function;
0246     const QObject* _lastSender;
0247 
0248     // trace data shown in this window
0249     TraceData* _data;
0250     // subcost types used for visualization
0251     EventType* _eventType;
0252     EventType* _eventType2;
0253     // grouping of function list
0254     ProfileContext::Type _groupType;
0255     // selected group
0256     TraceCostItem* _group;
0257     // selected parts
0258     TracePartList _activeParts;
0259     // hidden parts
0260     TracePartList _hiddenParts;
0261     // layouts
0262     int _layoutCurrent, _layoutCount;
0263 
0264     // for delayed slots
0265     EventType* _eventTypeDelayed;
0266     EventType* _eventType2Delayed;
0267     ProfileContext::Type _groupTypeDelayed;
0268     TraceCostItem* _groupDelayed;
0269     CostItem* _traceItemDelayed;
0270     QStringList _loadFilesDelayed;
0271     TraceItemView::Direction _directionDelayed;
0272 
0273     // for status progress display
0274     QString _progressMsg;
0275     QElapsedTimer _progressStart;
0276     QProgressBar* _progressBar;
0277 
0278     // toplevel configuration options
0279     bool _showPercentage, _showExpanded, _showCycles, _hideTemplates;
0280 
0281     // for running callgrind_control in the background
0282     QProcess* _ccProcess;
0283     QString _ccOutput;
0284 };
0285 
0286 #endif