Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Multiple QSGGeometryNodes simple xy line graph
Forum Updated to NodeBB v4.3 + New Features

Multiple QSGGeometryNodes simple xy line graph

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tcmichals
    wrote on last edited by
    #1

    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;
    

    }@

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tcmichals
      wrote on last edited by
      #2

      OK, I have this working now. But, how do you add text? i.e numbers on the axis?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved