Sandboxie/SandboxiePlus/SandMan/Models/TraceModel.h

101 lines
2.7 KiB
C
Raw Normal View History

2021-10-15 16:39:43 +01:00
#pragma once
#include <qwidget.h>
#include "../../QSbieAPI/SbieAPI.h"
#include "../../MiscHelpers/Common/TreeItemModel.h"
2023-01-07 15:57:55 +00:00
#include "../../MiscHelpers/Common/PoolAllocator.h"
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
class CTraceModel : public QAbstractItemModelEx
2021-10-15 16:39:43 +01:00
{
Q_OBJECT
public:
CTraceModel(QObject* parent = 0);
~CTraceModel();
2022-09-29 17:28:48 +01:00
void SetTree(bool bTree) { m_bTree = bTree; }
bool IsTree() const { return m_bTree; }
2023-01-07 15:57:55 +00:00
QList<QModelIndex> Sync(const QVector<CTraceEntryPtr>& EntryList);
2021-10-15 16:39:43 +01:00
CTraceEntryPtr GetEntry(const QModelIndex& index) const;
2023-01-07 15:57:55 +00:00
QVariant GetItemID(const QModelIndex& index) const;
QVariant Data(const QModelIndex &index, int role, int section) const;
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
// derived functions
virtual QVariant data(const QModelIndex &index, int role) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex &index) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
void Clear(bool bMem = false);
2021-10-15 16:39:43 +01:00
enum EColumns
{
eProcess = 0,
//eTimeStamp,
eType,
eStatus,
eValue,
eCount
};
2023-01-07 15:57:55 +00:00
protected:
//struct STracePath {
// STracePath() { Q_ASSERT(0); }
// STracePath(quint32* p, int c) : path(p), count(c), owner(false) {}
// STracePath(const STracePath& other)
// {
// count = other.count;
// path = new quint32[count];
// memcpy(path, other.path, count * sizeof(quint32));
// owner = true;
// }
// ~STracePath() {
// if (owner)
// delete[] path;
// }
// STracePath& operator = (const STracePath& other) { Q_ASSERT(0); return *this; }
// quint32* path;
// int count;
// bool owner;
//};
//
//friend uint qHash(const STracePath& var);
//friend bool operator == (const STracePath& l, const STracePath& r);
struct STreeNode
2021-10-15 16:39:43 +01:00
{
2023-01-07 15:57:55 +00:00
STreeNode(quint64 Id) { ID = Id; }
//virtual ~STreeNode(){}
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
quint64 ID;
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
STreeNode* Parent = NULL;
//int Row = 0;
QVector<STreeNode*> Children;
2021-10-15 16:39:43 +01:00
CTraceEntryPtr pEntry;
};
2023-01-07 15:57:55 +00:00
2022-09-29 17:28:48 +01:00
bool m_bTree;
2021-10-15 16:39:43 +01:00
QVariant m_LastID;
int m_LastCount;
2023-01-07 15:57:55 +00:00
virtual QVariant NodeData(STreeNode* pNode, int role, int section) const;
virtual STreeNode* MkNode(quint64 Id);
virtual void FreeNode(STreeNode* pNode);
STreeNode* FindParentNode(STreeNode* pParent, quint64 Path, int PathsIndex, QList<QModelIndex>* pNewBranches);
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
STreeNode* m_Root;
QHash<quint64, STreeNode*> m_Branches;
2021-10-15 16:39:43 +01:00
2023-01-07 15:57:55 +00:00
static PoolAllocator<sizeof(STreeNode)> m_NodeAllocator;
2021-10-15 16:39:43 +01:00
};