File indexing completed on 2024-05-12 09:47:09

0001 /*
0002     This file is part of KCachegrind.
0003 
0004     SPDX-FileCopyrightText: 2010-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only
0007 */
0008 
0009 #ifndef FUNCTIONLISTMODEL_H
0010 #define FUNCTIONLISTMODEL_H
0011 
0012 #include <QAbstractItemModel>
0013 #include <QPixmap>
0014 #include <QRegularExpression>
0015 #include <QList>
0016 
0017 #include "tracedata.h"
0018 #include "subcost.h"
0019 
0020 // helper for setting function filter
0021 QString glob2Regex(QString pattern);
0022 
0023 class FunctionListModel : public QAbstractItemModel
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     FunctionListModel();
0029     ~FunctionListModel() override;
0030 
0031     /* Data to show: all functions from <data>
0032      * - which are part of function group <group>
0033      * - whose name contains <filter>
0034      */
0035     void resetModelData(TraceData* data, TraceCostItem* group, QString filter,
0036                         EventType* eventType);
0037 
0038     // reimplemented from QAbstractItemModel
0039     QVariant data(const QModelIndex&, int) const override;
0040     Qt::ItemFlags flags(const QModelIndex&) const override;
0041     QVariant headerData(int section, Qt::Orientation orientation,
0042                         int role = Qt::DisplayRole) const override;
0043     QModelIndex index(int row, int column = 0,
0044                       const QModelIndex &parent = QModelIndex()) const override;
0045     QModelIndex parent(const QModelIndex &index) const override;
0046     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0047     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0048     void sort(int column, Qt::SortOrder order) override;
0049 
0050     void setFilter(QString filter);
0051     void setEventType(EventType*);
0052     void setMaxCount(int);
0053 
0054     TraceFunction* function(const QModelIndex &index);
0055     // get index of an entry showing a function, optionally adding it if needed
0056     QModelIndex indexForFunction(TraceFunction *f, bool add = false);
0057 
0058     class FunctionLessThan
0059     {
0060     public:
0061         FunctionLessThan(int column, Qt::SortOrder order, EventType* et)
0062         { _column = column; _order = order; _eventType = et; }
0063 
0064         bool operator()(TraceFunction *left, TraceFunction *right);
0065 
0066     private:
0067         int _column;
0068         Qt::SortOrder _order;
0069         EventType* _eventType;
0070     };
0071 
0072 private:
0073     QString getName(TraceFunction *f) const;
0074     QPixmap getNamePixmap(TraceFunction  *f) const;
0075     QString getInclCost(TraceFunction *f) const;
0076     QPixmap getInclPixmap(TraceFunction *f) const;
0077     QString getSelfCost(TraceFunction *f) const;
0078     QPixmap getSelfPixmap(TraceFunction *f) const;
0079     QString getCallCount(TraceFunction *f) const;
0080     QString getLocation(TraceFunction *f) const;
0081     QString getSkippedCost(TraceFunction *f, QPixmap *pixmap) const;
0082 
0083     // compute the list of candidates to show, ignoring order
0084     void computeFilteredList();
0085     // computes entries to show from candidates using current order
0086     void computeTopList();
0087 
0088     QList<QVariant> _headerData;
0089     EventType *_eventType;
0090     ProfileContext::Type _groupType;
0091     int _maxCount;
0092 
0093     QList<TraceFunction*> _list;
0094     QList<TraceFunction*> _filteredList;
0095     QList<TraceFunction*> _topList;
0096 
0097     // functions with max values at col.0/1/2 from candidate list:
0098     // these are always shown to have same column widths when resorting
0099     TraceFunction *_max0, *_max1, *_max2;
0100 
0101     int _sortColumn;
0102     Qt::SortOrder _sortOrder;
0103     QRegularExpression _filter;
0104     QString _filterString;
0105 };
0106 
0107 #endif