qcgtoplevel.h 8.56 KB
Newer Older
1
/* This file is part of KCachegrind.
Josef Weidendorfer's avatar
Josef Weidendorfer committed
2
   Copyright (c) 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/*
 * QCachegrind top level window
 */

23 24
#ifndef QCGTOPLEVEL_H
#define QCGTOPLEVEL_H
25

26
#include <QElapsedTimer>
27 28
#include <QLabel>
#include <QMainWindow>
29 30
#include <QStringList>
#include <QString>
31 32 33 34 35 36 37 38 39

#include "logger.h"
#include "traceitemview.h"
#include "tracedata.h"
#include "toplevelbase.h"

class MultiView;
class QDockWidget;
class QLabel;
40
class QComboBox;
41 42 43 44 45
class QProgressBar;
class QMenu;

class TraceData;
class MainWidget;
46
class PartSelection;
47
class FunctionSelection;
48
class StackSelection;
49 50
class TraceFunction;

51
class QCGTopLevel : public QMainWindow, public Logger, public TopLevelBase
52
{
53 54
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "io.github.qcachegrind")
55

56
public:
57
    QCGTopLevel();
58
    ~QCGTopLevel() override;
59

60 61
    TraceData* data() { return _data; }
    void setData(TraceData*);
62

63 64 65 66
    void createActions();
    void createDocks();
    void createMenu();
    void createToolbar();
67

68
    void closeEvent(QCloseEvent*) override;
69

70 71 72 73
    ProfileContext::Type groupType() { return _groupType; }
    EventType* eventType() { return _eventType; }
    EventType* eventType2() { return _eventType2; }
    TracePartList activeParts() { return _activeParts; }
74
    TracePartList hiddenParts() override { return _hiddenParts; }
75

76
    /* convenience functions for often used context menu items */
77 78
    void addEventTypeMenu(QMenu*,bool) override;
    void addGoMenu(QMenu*) override;
79

80
    // Logger overwrites: notifications for file loading
81 82 83 84 85
    void loadStart(const QString& filename) override;
    void loadProgress(int progress) override; // 0 - 100
    void loadWarning(int line, const QString& msg) override;
    void loadError(int line, const QString& msg) override;
    void loadFinished(const QString& msg) override; // msg could be error
86

87
public Q_SLOTS:
88 89 90 91 92 93 94 95 96 97 98
    void load();
    void load(QStringList files, bool addToRecentFiles = true);
    void add();
    void add(QStringList files);

    // shows the main window before loading to see loading progress
    void loadDelayed(QString file, bool addToRecentFiles = true);
    void loadDelayed(QStringList files, bool addToRecentFiles = true);

    void exportGraph();
    void newWindow();
99
    void configure(QString page = QString());
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    void about();

    // layouts
    void layoutDuplicate();
    void layoutRemove();
    void layoutNext();
    void layoutPrevious();
    void layoutSave();
    void layoutRestore();
    void updateLayoutActions();

    void updateStatusBar();
    void eventTypeSelected(const QString&);
    void eventType2Selected(const QString&);
    void groupTypeSelected(int);
    void toggleSplitted();
    void toggleSplitDirection();
    void togglePartDock();
    void toggleStackDock();
    void toggleFunctionDock();
    void functionVisibilityChanged(bool);
    void togglePercentage();
    void setPercentage(bool);
    void setAbsoluteCost();
    void setRelativeCost();
    void toggleHideTemplates();
    void toggleExpanded();
    void toggleCycles();
    void recentFilesMenuAboutToShow();
    void recentFilesTriggered(QAction*);
    void sidebarMenuAboutToShow();
    void forwardAboutToShow();
    void forwardTriggered(QAction*);
    void backAboutToShow();
    void backTriggered(QAction*);
    void upAboutToShow();
    void upTriggered(QAction*);
    void primaryAboutToShow();
    void secondaryAboutToShow();
    void groupingAboutToShow();
Calvin Buckley's avatar
Calvin Buckley committed
140 141
    void windowListTriggered(QAction*);
    void windowListAboutToShow();
142 143
    void macDockMenuAboutToShow();
    void insertWindowList(QMenu*);
144 145 146 147 148 149 150 151 152 153 154 155 156

    bool setEventType(EventType*);
    bool setEventType2(EventType*);
    bool setEventType(QString);
    bool setEventType2(QString);
    bool setEventType(QAction*);
    bool setEventType2(QAction*);
    bool setGroupType(ProfileContext::Type);
    bool setGroupType(QString);
    bool setGroup(TraceCostItem*);
    bool setGroup(QString);
    bool setFunction(TraceFunction*);
    bool setFunction(QString);
157
    void activePartsChangedSlot(const TracePartList& list) override;
158 159 160 161
    void partsHideSelectedSlot();
    void partsUnhideAllSlot();

    /* These go back to mainloop first by using a timer.
162 163 164
   * So they can be called from event handlers that
   * are not allowed to delete list entries.
   */
165 166 167 168 169
    void setEventTypeDelayed(EventType*) override;
    void setEventType2Delayed(EventType*) override;
    void setGroupTypeDelayed(ProfileContext::Type) override;
    void setGroupDelayed(TraceCostItem*) override;
    void setTraceItemDelayed(CostItem*) override;
170 171 172 173 174
    void partsHideSelectedSlotDelayed();
    void partsUnhideAllSlotDelayed();
    void goBack();
    void goForward();
    void goUp();
175
    void setDirectionDelayed(TraceItemView::Direction) override;
176 177 178 179 180 181 182 183 184 185 186

    /* SingleShot Slots (without parameters) for the delayed versions */
    void setEventTypeDelayed();
    void setEventType2Delayed();
    void setGroupTypeDelayed();
    void setGroupDelayed();
    void setTraceItemDelayed();
    void loadFilesDelayed();
    void setDirectionDelayed();

    // configuration has changed
187
    void configChanged() override;
188 189 190 191 192

    //void refresh();

    // progress in status bar, empty message disables progress display
    void showStatus(const QString& msg, int progress);
193
    void showMessage(const QString&, int msec) override;
194 195

private:
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    void resetState();
    void createLayoutActions();
    void createMiscActions();
    void setupMainWidget(MainWidget*);
    void setupPartSelection(PartSelection*);
    void updateEventTypeMenu(QMenu* m, bool secondary);
    void restoreCurrentState(const QString& postfix);
    void saveCurrentState(const QString& postfix);
    void saveTraceSettings();
    QString traceKey();
    void restoreTraceTypes();
    void restoreTraceSettings();

    QStatusBar* _statusbar;
    QLabel* _statusLabel;
    QString _progressMsg;
212
    QElapsedTimer _progressStart;
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    QProgressBar* _progressBar;

    MultiView* _multiView;
    Qt::Orientation _spOrientation;
    bool _twoMainWidgets;
    FunctionSelection* _functionSelection;
    PartSelection* _partSelection;
    StackSelection* _stackSelection;
    QDockWidget *_partDock, *_stackDock, *_functionDock;
    bool _forcePartDock;

    // menu/toolbar actions
    QAction *_newAction, *_openAction, *_addAction, *_reloadAction;
    QAction *_exportAction, *_dumpToggleAction, *_exitAction;
    QAction *_sidebarMenuAction, *_recentFilesMenuAction;
    QAction *_cyclesToggleAction, *_percentageToggleAction;
    QAction *_expandedToggleAction, *_hideTemplatesToggleAction;
    QAction *_primaryMenuAction, *_secondaryMenuAction;
231
    QAction *_groupingMenuAction, *_closeAction;
232 233
    QAction *_splittedToggleAction, *_splitDirectionToggleAction;
    QAction *_layoutNext, *_layoutPrev, *_layoutRemove, *_layoutDup;
234
    QAction *_layoutRestore, *_layoutSave, *_toolbarToggleAction;
235 236
    QAction *_upAction, *_forwardAction, *_backAction;
    QAction *_configureAction, *_aboutAction, *_aboutQtAction;
237
    QAction *_minimizeAction, *_zoomAction;
238
    QMenu *windowMenu, *macDockMenu;
239
    QToolBar *tb;
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    QComboBox* _eventTypeBox;

    TraceFunction* _function;
    const QObject* _lastSender;

    // trace data shown in this window
    TraceData* _data;
    // subcost types used for visualization
    EventType* _eventType;
    EventType* _eventType2;
    QStringList _eventTypes;
    // grouping of function list
    ProfileContext::Type _groupType;
    // selected group
    TraceCostItem* _group;
    // selected parts
    TracePartList _activeParts;
    // hidden parts
    TracePartList _hiddenParts;
    // layouts
    int _layoutCurrent, _layoutCount;
    // remember last file directory for new QFileDialogs
    QString _lastFile;

    // for delayed slots
    EventType* _eventTypeDelayed;
    EventType* _eventType2Delayed;
    ProfileContext::Type _groupTypeDelayed;
    TraceCostItem* _groupDelayed;
    CostItem* _traceItemDelayed;
    QStringList _loadFilesDelayed;
    bool _addToRecentFiles;
    TraceItemView::Direction _directionDelayed;
273 274
};

275
#endif // QCGTOPLEVEL_H