Multiple QSGGeometryNodes simple xy line graph
-
I'm trying to create a simple x/y line graph, I'm very confused on how to managed multiple nodes, ie, x axis line, y axis line, and the actual real line. If the code just returns x_axis, or y_axis, and not calling the AppendChildNode works OK for the line.
Also, noticed that once all the nodes are added the application crashes on closing. Is there a special method to dispose of the Node objects?
@QSGNode *VtyGraphQT::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
QSGGeometryNode *background, *x_axis, *y_axis, *line = 0;
QSGGeometry *geometry=0, *x_axisGeo=0, *y_axisGeo=0, *lineGeo = 0;if (!oldNode) { background = new QSGGeometryNode; x_axis = new QSGGeometryNode; y_axis = new QSGGeometryNode; line = new QSGGeometryNode; x_axisGeo = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2); y_axisGeo = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2); lineGeo = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 1024); x_axisGeo->setLineWidth(2); x_axisGeo->setDrawingMode(GL_LINE_STRIP); x_axis->setGeometry(x_axisGeo); x_axis->setFlag(QSGNode::OwnsGeometry); y_axisGeo->setLineWidth(2); y_axisGeo->setDrawingMode(GL_LINE_STRIP); y_axis->setGeometry(y_axisGeo); y_axis->setFlag(QSGNode::OwnsGeometry); lineGeo->setLineWidth(2); lineGeo->setDrawingMode(GL_LINE_STRIP); line->setGeometry(lineGeo); line->setFlag(QSGNode::OwnsGeometry); QSGFlatColorMaterial *material = new QSGFlatColorMaterial; material->setColor(QColor(255, 0, 0)); x_axis->setMaterial(material); x_axis->setFlag(QSGNode::OwnsMaterial); y_axis->setMaterial(material); y_axis->setFlag(QSGNode::OwnsMaterial); line->setMaterial(material); line->setFlag(QSGNode::OwnsMaterial); background->setMaterial(material); background->setFlag(QSGNode::OwnsMaterial); background->appendChildNode(x_axis); background->appendChildNode(y_axis); background->appendChildNode(line); x_axisGeo->allocate(2); x_axisGeo->vertexDataAsPoint2D()[0].set(0,0); x_axisGeo->vertexDataAsPoint2D()[1].set(width(),0); y_axisGeo->allocate(2); y_axisGeo->vertexDataAsPoint2D()[0].set(0,0); y_axisGeo->vertexDataAsPoint2D()[1].set(0,height()); }else { background = static_cast<QSGGeometryNode *>(oldNode); } return background;
}@
-
OK, I have this working now. But, how do you add text? i.e numbers on the axis?