diff --git a/src/SeerParallelStacksCommon.cpp b/src/SeerParallelStacksCommon.cpp index 4927dea..52791af 100644 --- a/src/SeerParallelStacksCommon.cpp +++ b/src/SeerParallelStacksCommon.cpp @@ -144,12 +144,12 @@ QString SeerParallelStacksThread::toString() const { return result; } -static std::shared_ptr buildImpl(const QVector& threads, const QString& currentFunction, int depth) { +static SeerParallelStacksNode buildImpl(const QVector& threads, const QString& currentFunction, int depth) { - auto node = std::make_shared(); - node->depth = depth; - node->function = currentFunction; - node->threads = threads; + SeerParallelStacksNode node; + node.depth = depth; + node.function = currentFunction; + node.threads = threads; // Group threads by the function at position [-depth-1] (bottom-up). QMap> functionThreads; @@ -157,6 +157,7 @@ static std::shared_ptr buildImpl(const QVector= t.frames().size()) { @@ -170,45 +171,45 @@ static std::shared_ptr buildImpl(const QVectorchildren.append(child); + node.children.append(child); } return node; } -std::shared_ptr SeerParallelStacksBuildParallelStacks(const QVector& threads) { +SeerParallelStacksNode SeerParallelStacksBuildParallelStacks(const QVector& threads) { return buildImpl(threads, QString(), 0); } // --------------------------------------------------------------- -// fillStack — flatten SeerParallelStacksStackNode tree into Stack tree for graphing +// fillStack — flatten SeerParallelStacksNode tree into Stack tree for graphing // --------------------------------------------------------------- -std::shared_ptr SeerParallelStacksFillStack(const std::shared_ptr& node) { +SeerParallelStacksStack SeerParallelStacksFillStack(const SeerParallelStacksNode& node) { - auto stack = std::make_shared(); - stack->threadCount = static_cast(node->threads.size()); + SeerParallelStacksStack stack; + stack.threadCount = node.threads.size(); // Collect thread IDs for this node - for (const SeerParallelStacksThread& t : node->threads) { - stack->threadIds.append(t.id()); + for (const SeerParallelStacksThread& t : node.threads) { + stack.threadIds.append(t.id()); } - if (!node->function.isEmpty()) { - stack->functions.append(node->function); + if (!node.function.isEmpty()) { + stack.functions.append(node.function); } - if (node->children.size() == 1) { + if (node.children.size() == 1) { // Merge single child into this stack (chain of frames). // Keep the IDs from the leaf (most specific) node. - auto child = SeerParallelStacksFillStack(node->children[0]); - stack->functions += child->functions; - stack->stacks = child->stacks; - stack->threadCount = child->threadCount; - stack->threadIds = child->threadIds; + auto child = SeerParallelStacksFillStack(node.children[0]); + stack.functions += child.functions; + stack.stacks = child.stacks; + stack.threadCount = child.threadCount; + stack.threadIds = child.threadIds; } else { - for (const auto& childNode : node->children) { - stack->stacks.append(SeerParallelStacksFillStack(childNode)); + for (const auto& childNode : node.children) { + stack.stacks.append(SeerParallelStacksFillStack(childNode)); } } diff --git a/src/SeerParallelStacksCommon.h b/src/SeerParallelStacksCommon.h index d3f1486..df18b27 100644 --- a/src/SeerParallelStacksCommon.h +++ b/src/SeerParallelStacksCommon.h @@ -72,22 +72,22 @@ class SeerParallelStacksThread { typedef QVector SeerParallelStacksThreads; -struct SeerParallelStacksStackNode { - QString function; // empty == root - int depth = 0; - QVector threads; - QVector> children; +struct SeerParallelStacksNode { + QString function; // empty == root + int depth = 0; + QVector threads; + QVector children; }; // Flat "Stack" representation used when building the graph. struct SeerParallelStacksStack { - QVector threadIds; // IDs of every thread in this node - QVector functions; + QVector threadIds; // IDs of every thread in this node + QVector functions; - QVector> stacks; - int threadCount = 0; + QVector stacks; + int threadCount = 0; }; -std::shared_ptr SeerParallelStacksBuildParallelStacks (const QVector& threads); // Build the parallel-stacks tree from a flat list of threads. -std::shared_ptr SeerParallelStacksFillStack (const std::shared_ptr& node); +SeerParallelStacksNode SeerParallelStacksBuildParallelStacks (const QVector& threads); // Build the parallel-stacks tree from a flat list of threads. +SeerParallelStacksStack SeerParallelStacksFillStack (const SeerParallelStacksNode& node); diff --git a/src/SeerParallelStacksGraphicsView.cpp b/src/SeerParallelStacksGraphicsView.cpp index 970a8fb..1bd84d2 100644 --- a/src/SeerParallelStacksGraphicsView.cpp +++ b/src/SeerParallelStacksGraphicsView.cpp @@ -749,11 +749,11 @@ void SeerParallelStacksGraphicsView::mouseReleaseEvent(QMouseEvent* event) { } -void SeerParallelStacksGraphicsView::setStack(const std::shared_ptr& root) { +void SeerParallelStacksGraphicsView::setStack(const SeerParallelStacksStack& root) { _scene->clear(); - if (!root) return; + // XXX if (!root) return; auto* rootPN = new PlacedNode; buildPlacedTree(rootPN, root, nullptr); @@ -826,17 +826,17 @@ void SeerParallelStacksGraphicsView::alignParentlessToBottom(PlacedNode* pn, qre } } -void SeerParallelStacksGraphicsView::buildPlacedTree(PlacedNode* pn, const std::shared_ptr& stack, PlacedNode* parentPN) { +void SeerParallelStacksGraphicsView::buildPlacedTree(PlacedNode* pn, const SeerParallelStacksStack& stack, PlacedNode* parentPN) { pn->stack = stack; pn->parent = parentPN; - if (!stack->functions.isEmpty()) { - pn->item = new SeerParallelStacksStackBoxItem(*stack); + if (!stack.functions.isEmpty()) { + pn->item = new SeerParallelStacksStackBoxItem(stack); _scene->addItem(pn->item); } - for (const auto& child : stack->stacks) { + for (const auto& child : stack.stacks) { auto* childPN = new PlacedNode; buildPlacedTree(childPN, child, pn); pn->children.append(childPN); diff --git a/src/SeerParallelStacksGraphicsView.h b/src/SeerParallelStacksGraphicsView.h index ff3c108..0e74d1e 100644 --- a/src/SeerParallelStacksGraphicsView.h +++ b/src/SeerParallelStacksGraphicsView.h @@ -177,7 +177,7 @@ class SeerParallelStacksGraphicsView : public QGraphicsView { public: explicit SeerParallelStacksGraphicsView(QWidget* parent = nullptr); - void setStack (const std::shared_ptr& root); + void setStack (const SeerParallelStacksStack& root); protected: void wheelEvent (QWheelEvent* event) override; @@ -198,26 +198,26 @@ class SeerParallelStacksGraphicsView : public QGraphicsView { private: struct PlacedNode { - std::shared_ptr stack; - SeerParallelStacksStackBoxItem* item = nullptr; - PlacedNode* parent = nullptr; - QVector children; - qreal cx = 0; - qreal cy = 0; + SeerParallelStacksStack stack; + SeerParallelStacksStackBoxItem* item = nullptr; + PlacedNode* parent = nullptr; + QVector children; + qreal cx = 0; + qreal cy = 0; }; - void buildPlacedTree (PlacedNode* pn, const std::shared_ptr& stack, PlacedNode* parentPN); - void layoutTree (PlacedNode* pn, qreal& xCursor, qreal yTop); - void collectMaxBottom (PlacedNode* pn, qreal& maxBottom); - void alignParentlessToBottom (PlacedNode* pn, qreal maxBottom); - void addEdges (PlacedNode* pn); - void deleteTree (PlacedNode* pn); - void repositionMiniMap (); // keeps it pinned to bottom-right corner + void buildPlacedTree (PlacedNode* pn, const SeerParallelStacksStack& stack, PlacedNode* parentPN); + void layoutTree (PlacedNode* pn, qreal& xCursor, qreal yTop); + void collectMaxBottom (PlacedNode* pn, qreal& maxBottom); + void alignParentlessToBottom (PlacedNode* pn, qreal maxBottom); + void addEdges (PlacedNode* pn); + void deleteTree (PlacedNode* pn); + void repositionMiniMap (); // keeps it pinned to bottom-right corner - QGraphicsScene* _scene; - SeerParallelStacksMiniMapWidget* _miniMap; - bool _panning = false; - QPoint _panStartPos; // viewport coords at pan start + QGraphicsScene* _scene; + SeerParallelStacksMiniMapWidget* _miniMap; + bool _panning = false; + QPoint _panStartPos; // viewport coords at pan start friend class SeerParallelStacksMiniMapWidget; // needs sceneRect()/mapToScene()/centerOn() access };