diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-07 14:55:37 +0100 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-07 14:55:37 +0100 |
commit | a26811fc6001ed03e0eb3f671418d1247758aab2 (patch) | |
tree | e0ad0419f45add4285e35f82fa37ed272ff32a44 | |
parent | 086ce30bd9cb294e084e37854bc3006e601cb234 (diff) |
Scatterplot: simplified drawing code.
-rw-r--r-- | scatterplot.cpp | 44 | ||||
-rw-r--r-- | scatterplot.h | 5 |
2 files changed, 27 insertions, 22 deletions
diff --git a/scatterplot.cpp b/scatterplot.cpp index 0812d28..2c9a57a 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -105,7 +105,7 @@ void Scatterplot::updateMaterials() update(); } -QSGNode *Scatterplot::createSplatNode() +QSGNode *Scatterplot::newSplatNode() { if (m_xy.n_rows < 1) { return 0; @@ -129,7 +129,7 @@ QSGNode *Scatterplot::createSplatNode() return node; } -QSGNode *Scatterplot::createGlyphNodeTree() +QSGNode *Scatterplot::newGlyphTree() { // NOTE: // The glyph graph is structured as: @@ -176,30 +176,32 @@ QSGNode *Scatterplot::createGlyphNodeTree() return node; } -QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +QSGNode *Scatterplot::newSceneGraph() { // NOTE: // The hierarchy in the scene graph is as follows: // root [[splatNode] [glyphsRoot [glyph [...]]] [selectionNode]] - QSGNode *root = 0; - if (!oldNode) { - root = new QSGNode; - QSGNode *splatNode = createSplatNode(); - if (splatNode) { - root->appendChildNode(splatNode); - } - QSGNode *glyphTreeRoot = createGlyphNodeTree(); - if (glyphTreeRoot) { - root->appendChildNode(glyphTreeRoot); - } - - QSGSimpleRectNode *selectionRectNode = new QSGSimpleRectNode; - selectionRectNode->setColor(SELECTION_COLOR); - root->appendChildNode(selectionRectNode); - } else { - root = oldNode; + QSGNode *root = new QSGNode; + QSGNode *splatNode = newSplatNode(); + if (splatNode) { + root->appendChildNode(splatNode); + } + QSGNode *glyphTreeRoot = newGlyphTree(); + if (glyphTreeRoot) { + root->appendChildNode(glyphTreeRoot); } + QSGSimpleRectNode *selectionRectNode = new QSGSimpleRectNode; + selectionRectNode->setColor(SELECTION_COLOR); + root->appendChildNode(selectionRectNode); + + return root; +} + +QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + QSGNode *root = oldNode ? oldNode : newSceneGraph(); + if (m_xy.n_rows < 1) { return root; } @@ -210,6 +212,7 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) QSGNode *glyphsRootNode = root->firstChild()->nextSibling(); updateGlyphs(glyphsRootNode->firstChild()); + // Change update hints to false; the splat and glyphs were just updated if (m_shouldUpdateGeometry) { m_shouldUpdateGeometry = false; } @@ -224,6 +227,7 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) selectionRectNode->setRect(QRectF(m_dragOriginPos, m_dragCurrentPos)); selectionRectNode->markDirty(QSGNode::DirtyGeometry); } else { + // Hide selection rect selectionRectNode->setRect(QRectF(-1, -1, 0, 0)); } diff --git a/scatterplot.h b/scatterplot.h index 2887752..50af274 100644 --- a/scatterplot.h +++ b/scatterplot.h @@ -38,8 +38,9 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private: - QSGNode *createSplatNode(); - QSGNode *createGlyphNodeTree(); + QSGNode *newSceneGraph(); + QSGNode *newSplatNode(); + QSGNode *newGlyphTree(); bool updateSelection(bool mergeSelection); void applyManipulation(); |