map管理存储模型节点

class InfoVisitor : public osg::NodeVisitor
{

public:
    InfoVisitor():osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
    { 
        count = 0;
    }

    virtual void apply(osg::Node& node)
    {
        std::string str=node.className();
        if (count == 0)
        {
            QTreeWidgetItem* item=new QTreeWidgetItem;
            item->setText(0,QString(str.data()));
            map[count].push_back(item);
            rootList.append(item);
        }
        else
        {
           QVector<QTreeWidgetItem *> parent=map[count-1];
           QTreeWidgetItem* item=new QTreeWidgetItem(parent[parent.size()-1],QStringList(QString(str.data()))); 
           parent[parent.size()-1]->addChild(item);
           map[count].push_back(item);
        }
        count ++;
        traverse(node);
        count --;
    }
    /*virtual void apply(osg::Geometry& geometry)
    {
        traverse(geometry);
    }*/

public:
    int count;
    QList<QTreeWidgetItem *> rootList;
    QMap<int,QVector<QTreeWidgetItem *>>  map;
};

 

上一篇:洛谷月赛2021.07成绩登记


下一篇:LeetCode-238-除自身以外数组的乘积