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

0001 /*
0002     This file is part of KCachegrind.
0003 
0004     SPDX-FileCopyrightText: 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only
0007 */
0008 
0009 /*
0010  * Items of instruction view.
0011  */
0012 
0013 #ifndef INSTRITEM_H
0014 #define INSTRITEM_H
0015 
0016 
0017 #include <QTreeWidget>
0018 #include <QItemDelegate>
0019 
0020 #include "tracedata.h"
0021 
0022 class InstrView;
0023 
0024 class InstrItem: public QTreeWidgetItem
0025 {
0026 
0027 public:
0028     // for messages
0029     InstrItem(InstrView* iv, QTreeWidget* parent,
0030               Addr addr, const QString&);
0031 
0032     // for instruction lines
0033     InstrItem(InstrView* iv, QTreeWidget* parent,
0034               Addr addr, bool inside,
0035               const QString&, const QString&, const QString&,
0036               TraceInstr* instr);
0037 
0038     // for call instr
0039     InstrItem(InstrView* iv, QTreeWidgetItem* parent, Addr addr,
0040               TraceInstr* instr, TraceInstrCall* instrCall);
0041 
0042     // for jump lines
0043     InstrItem(InstrView* iv, QTreeWidgetItem* parent, Addr addr,
0044               TraceInstr* instr, TraceInstrJump* instrJump);
0045 
0046     Addr addr() const { return _addr; }
0047     bool inside() const { return _inside; }
0048     TraceInstr* instr() const { return _instr; }
0049     TraceInstrCall* instrCall() const { return _instrCall; }
0050     TraceInstrJump* instrJump() const { return _instrJump; }
0051     TraceInstrJump* jump(int i) const { return _jump[i]; }
0052     int jumpCount() const { return _jump.size(); }
0053     bool operator< ( const QTreeWidgetItem & other ) const override;
0054 
0055     void updateGroup();
0056     void updateCost();
0057 
0058     // arrow lines
0059     void setJumpArray(const QVector<TraceInstrJump*>& a);
0060 
0061 private:
0062     InstrView* _view;
0063     SubCost _pure, _pure2;
0064     Addr _addr;
0065     TraceInstr* _instr;
0066     TraceInstrJump* _instrJump;
0067     TraceInstrCall* _instrCall;
0068     bool _inside;
0069 
0070     QVector<TraceInstrJump*> _jump;
0071 };
0072 
0073 // Delegate for drawing the arrows column
0074 
0075 class InstrItemDelegate : public QItemDelegate
0076 {
0077     Q_OBJECT
0078 public:
0079     explicit InstrItemDelegate(InstrView *parent);
0080     void paint(QPainter *painter, const QStyleOptionViewItem &option,
0081                const QModelIndex & index ) const override;
0082     QSize sizeHint(const QStyleOptionViewItem &option,
0083                    const QModelIndex &index) const override;
0084 
0085 protected:
0086     void paintArrows(QPainter *p,
0087                      const QStyleOptionViewItem &option,
0088                      const QModelIndex &index) const;
0089 
0090     InstrView* _parent;
0091 };
0092 
0093 
0094 #endif // INSTRITEM_H