void SceneGraphTreeModel::removeNode(NodeUnrecPtr nodeToBeRemoved)
{

    NodeRefPtr parent = nodeToBeRemoved->getParent();

    TreePath pathOfNode = createPath(nodeToBeRemoved);
    if(parent!=NULL)
    {
        UInt32 ChildIndex(parent->findChild(nodeToBeRemoved));


        produceTreeNodesWillBeRemoved(pathOfNode.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeRemoved));
        parent->subChild(nodeToBeRemoved);
        produceTreeNodesRemoved(pathOfNode.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, nodeToBeRemoved));

        if(parent->getNChildren() == 0)
        {
            if(parent->getParent() != NULL)
            {
                std::vector<UInt32> childIndices;
                childIndices.push_back(parent->getParent()->findChild(parent));
                std::vector<boost::any> ChildUserObjects;
                for(UInt32 i(0) ; i< childIndices.size() ; ++i)
                {
                    ChildUserObjects.push_back(boost::any(NodeUnrecPtr(parent->getParent()->getChild(childIndices[i]))));
                }
                produceTreeNodesChanged(createPath(parent->getParent()), childIndices, ChildUserObjects);
            }
        }
    }
}
Example #2
0
void AVLTree::Find(TreeNode *node, int x, QAnimationGroup *group)
{
    if (node == NULL) return;
    TreePath *path;
    if (node->parent && group)
    {
        path = new TreePath(node->parent, node, view);
        group->addAnimation(path->getToSonAnim());
    }
    if (group)
        group->addAnimation(node->getTurnRedAnim());
    if (node->data == x)
    {
        if (group)
            group->addAnimation(node->getPopAnim());
        else
            node->getPopAnim()->start(QAbstractAnimation::DeleteWhenStopped);
    }
    else if (node->data > x)
        Find(node->Lson, x, group);
    else
        Find(node->Rson, x, group);
    if (group)
        group->addAnimation(node->getTurnBlackAnim());
    if (node->parent && group)
    {
        group->addAnimation(path->getToParentAnim());
    }
}
void SceneTreeModel::setAsNotVisible(const TreePath& path)
{
    boost::any value = path.getLastPathComponent();

    if(value.type() == typeid(Scene* const))
    {
        dettachChangeHandler(boost::any_cast<Scene* const>(value), 
                             path.getParentPath(),
                             path);
    }
    else if(value.type() == typeid(Light* const))
    {
        dettachChangeHandler(boost::any_cast<Light* const>(value), 
                             path.getParentPath(),
                             path);
    }
    else if(value.type() == typeid(Foreground* const))
    {
        dettachChangeHandler(boost::any_cast<Foreground* const>(value), 
                             path.getParentPath(),
                             path);
    }
    else if(value.type() == typeid(SceneObject* const))
    {
        dettachChangeHandler(boost::any_cast<SceneObject* const>(value), 
                             path.getParentPath(),
                             path);
    }
}
UInt32 FixedHeightTreeModelLayout::getVisibleChildCount(const TreePath& path) const
{
    if(isVisible(path) ||
       (path.getPathCount() == 1 && isExpanded(path)))
    {
        return _TreeModel->getChildCount(path.getLastPathComponent());
    }
    else
    {
        return 0;
    }
}
TreePath PropertyTreeModel::pathFromRow(PropertyRow* row)
{
	TreePath result;
	if(row)
		while(row->parent()){
            int childIndex = row->parent()->childIndex(row);
            YASLI_ESCAPE(childIndex >= 0, return TreePath());
			result.insert(result.begin(), childIndex);
			row = row->parent();
		}
		return result;
}
Example #6
0
void AVLTree::PostOrder(TreeNode *node, QAnimationGroup *group)
{
    if (node == NULL) return;
    group->addAnimation(node->getTurnRedAnim());
    TreePath *path = new TreePath(node, node->Lson, view);
    group->addAnimation(path->getToSonAnim());
    PreOrder(node->Lson, group);
    group->addAnimation(path->getToParentAnim());
    path = new TreePath(node, node->Rson, view);
    group->addAnimation(path->getToSonAnim());
    PreOrder(node->Rson, group);
    group->addAnimation(path->getToParentAnim());
    group->addAnimation(node->getPopAnim());
    group->addAnimation(node->getTurnBlackAnim());
}
ModelTreeNodeRefPtr DefaultTreeModel::getNodeForPath(const TreePath& ThePath) const
{
    try
    {
        ModelTreeNodeRefPtr TheNode = boost::any_cast<ModelTreeNodeRefPtr>(ThePath.getLastPathComponent());

        return TheNode;
    }
    catch(boost::bad_any_cast &)
    {
        return NULL;
    }
}
Example #8
0
/*public*/ void CPTreeSelectionListener::valueChanged(TreeSelectionEvent* e)
{
 TreePath* path = e->getPath();
 CatalogTreeNode* n = (CatalogTreeNode*)path->getLastPathComponent();
 cp->log->debug(tr("%1 ").arg(e->getPath()->toString()));
 NamedIcon* icon = cp->getSelectedIcon();
 if (!cp->dTree->isSelectionEmpty() && cp->dTree->getSelectionPath() != NULL && icon != NULL)
 {
     // somebody has been selected
     //cp->preview->setIcon(cp->getSelectedIcon());
  QPixmap p =QPixmap(icon->getFilename());
//  // get label dimensions
//  int w = cp->preview->width();
//  int h = cp->preview->height();
//  cp->preview->setPixmap(p.scaled(w,h,Qt::KeepAspectRatio));
  cp->preview->resize(p.size());
  cp->preview->setPixmap(p);
 }
 else {
     cp->preview->setPixmap(QPixmap());
 }
}
void SceneGraphTreeModel::valueForPathChanged(TreePath path, const boost::any& newValue)
{
    try
    {
        NodeUnrecPtr NewNode = boost::any_cast<NodeUnrecPtr>(newValue);
        NodeUnrecPtr OldNode = boost::any_cast<NodeUnrecPtr>(path.getLastPathComponent());
        if(NewNode != NULL &&
           OldNode  != NULL &&
           NewNode != OldNode &&
           OldNode->getParent() != NULL)
        {
            NodeUnrecPtr ParentNode(OldNode->getParent());
            if(ParentNode->replaceChildBy(OldNode, NewNode))
            {
                UInt32 ChildIndex(ParentNode->findChild(NewNode));
                produceTreeStructureChanged(path.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, newValue));
            }
        }
    }
    catch(boost::bad_any_cast &ex)
    {
        SWARNING << "Bad any cast: " << ex.what() << std::endl;
    }
}
void ComponentTreeModel::valueForPathChanged(TreePath path, const boost::any& newValue)
{
    try
    {
        ComponentWeakPtr NewComponent = boost::any_cast<ComponentWeakPtr>(newValue);
        ComponentWeakPtr OldComponent = boost::any_cast<ComponentWeakPtr>(path.getLastPathComponent());
        if(NewComponent != NULL &&
           OldComponent  != NULL &&
           NewComponent != OldComponent &&
           OldComponent->getParentContainer() != NULL)
        {
            ComponentContainerRefPtr ParentContainer(OldComponent->getParentContainer());
            Int32 ChildIndex(ParentContainer->getChildIndex(OldComponent));
            if(ChildIndex >= 0)
            {
                (*ParentContainer->editMFChildren())[ChildIndex] = NewComponent;
                produceTreeStructureChanged(path.getParentPath(),std::vector<UInt32>(1, ChildIndex),std::vector<boost::any>(1, newValue));
            }
        }
    }
    catch(boost::bad_any_cast &)
    {
    }
}
void FixedHeightTreeModelLayout::setExpanded(const TreePath& path, bool Expand)
{
    if(!_TreeModel->isLeaf(path.getLastPathComponent()))
    {
        if(Expand)
        {
            _VetoPathExpantion = false;

            if(!isExpanded(path))
            {
                produceTreeWillExpand(path);
                if(!_VetoPathExpantion)
                {
                    _ExpandedPathSet.insert(path);

                    insertVisibleDecendents(path);

                    produceTreeExpanded(path);
                }
            }
        }
        else
        {
            _VetoPathCollapse = false;
            if(isExpanded(path))
            {
                produceTreeWillCollapse(path);
                if(!_VetoPathCollapse)
                {
                    _ExpandedPathSet.erase(path);

                    removeVisibleDecendents(path);

                    produceTreeCollapsed(path);
                }
            }
        }
    }
}
Example #12
0
/*public*/ NamedIcon* CatalogPane::getSelectedIcon() {
    if (dTree->isSelectionEmpty() || dTree->getSelectionPath() == NULL) {
        return NULL;
    }
    // somebody has been selected
    if (log->isDebugEnabled()) log->debug(tr("getSelectedIcon with %1").arg(dTree->getSelectionPath()->toString()));
    TreePath* path = dTree->getSelectionPath();
    int level = path->getPathCount();
    if (level < 3) {
        return NULL;
    }
    QString buf;
    QString name;
    if (((DefaultMutableTreeNode*) path->getPathComponent(1))->getUserObject().toString() == ("resources")) {
        // process a .jar icon
        buf = QString(CatalogTreeModel::resourceRoot);
        for (int i = 2; i < level; i++) {
            buf.append("/");
            buf.append(/*(String) */((DefaultMutableTreeNode*) path->getPathComponent(i))->getUserObject().toString());
        }
    } else if (((DefaultMutableTreeNode*) path->getPathComponent(1))->getUserObject().toString() == ("files")) {
        // process a file
        buf = QString(CatalogTreeModel::fileRoot);
        buf.append(/*(String)*/ ((DefaultMutableTreeNode*) path->getPathComponent(2))->getUserObject().toString());
        for (int i = 3; i < level; i++) {
            buf.append(File::separator);
            buf.append(/*(String)*/ ((DefaultMutableTreeNode*) path->getPathComponent(i))->getUserObject().toString());
        }
    } else {
        log->error(tr("unexpected first element on getSelectedIcon: %1").arg(((TreePath*)path->getPathComponent(1))->toString()));
        return NULL;
    }
    name = buf/*.toString()*/;
    if (log->isDebugEnabled()) log->debug(tr("attempt to load file from %1").arg(name));
    NamedIcon* icon = NamedIcon::getIconByName(name);
    return icon;
}
Example #13
0
void AVLTree::Delete(TreeNode * &node, int x, QAnimationGroup *group)
{
    if (node == NULL)
        return;
    if (group&& node->parent)
        group->addAnimation(node->parent->getTurnRedAnim());
    TreePath *path;
    if (group && node->parent)
    {
        path = new TreePath(node->parent, node, view);
        group->addAnimation(path->getToSonAnim());
    }
    TreeNode* parent = node->parent;
    if (x < node->data)
    {
        //如果x小于节点的值,就继续在节点的左子树中删除x
        Delete(node->Lson, x, group);
        if (group && node->parent)
            group->addAnimation(path->getToParentAnim());
        if (2 == height(node->Rson) - height(node->Lson))
        {
            if (node->Rson->Lson != NULL &&
                (height(node->Rson->Lson)>height(node->Rson->Rson)))
                RL(node, group);
            else
                RR(node, group);
        }

    }
    else if (x > node->data)
    {
        Delete(node->Rson, x, group);//如果x大于节点的值,就继续在节点的右子树中删除x
        if (group && node->parent)
            group->addAnimation(path->getToParentAnim());
        if (2 == height(node->Lson) - height(node->Rson))
        {
            if (node->Lson->Rson != NULL &&
                (height(node->Lson->Rson)>height(node->Lson->Lson)))
                LR(node, group);
            else
                LL(node, group);
        }

    }
    else//如果相等,此节点就是要删除的节点
    {
        if (group)
            group->addAnimation(node->getPopAnim());
        else
            node->getPopAnim()->start(QAbstractAnimation::DeleteWhenStopped);
        if (node->Lson && node->Rson)//此节点有两个儿子
        {
            TreeNode* temp = node->Rson;//temp指向节点的右儿子
            while (temp->Lson != NULL) temp = temp->Lson;//找到右子树中值最小的节点
            //把右子树中最小节点的值赋值给本节点
            if (group)
                group->addAnimation(node->getValueAnim(temp->data));
            else
                node->data = temp->data;
            //node->freq = temp->freq;
            Delete(node->Rson, temp->data, group);//删除右子树中最小值的节点
            if (group && node->parent)
                group->addAnimation(path->getToParentAnim());
            if (2 == height(node->Lson) - height(node->Rson))
            {
                if (node->Lson->Rson != NULL &&
                    (height(node->Lson->Rson)>height(node->Lson->Lson)))
                    LR(node, group);
                else
                    LL(node, group);
            }
        }
        else//此节点有1个或0个儿子
        {
            TreeNode* temp = node;
            TreeNode* parent = node->parent;
            if (group && node->parent)
                group->addAnimation(path->getToParentAnim());
            if (node->Lson == NULL)//有右儿子或者没有儿子
                node = node->Rson;
            else if (node->Rson == NULL)//有左儿子
                node = node->Lson;
            if (group)
            {
                QParallelAnimationGroup *anim = new QParallelAnimationGroup;
                anim->addAnimation(temp->getFadeOutAnim());
                if (node)
                    anim->addAnimation(node->setParent(parent));
                group->addAnimation(anim);
            }
            else
            {
                temp->getFadeOutAnim()->start(QAbstractAnimation::DeleteWhenStopped);
                if (node)
                    node->setParent(parent)->start(QAbstractAnimation::DeleteWhenStopped);
            }
            if (group)
                group->addAnimation(getPosAnim());
        }
    }
    if (group && parent)
        group->addAnimation(parent->getTurnBlackAnim());
    if (node == NULL)
        return;
    node->h = max(height(node->Lson), height(node->Rson)) + 1;
    return;
}
Example #14
0
void AVLTree::Insert(TreeNode * &node, TreeNode *parent, int x, QAnimationGroup *group)
{
    if (group && parent)
        group->addAnimation(parent->getTurnRedAnim());
    if (node == NULL)
    {
        QParallelAnimationGroup *anim = new QParallelAnimationGroup;
        node = new TreeNode();
        view->addItem(node);
        node->data = x;
        node->setPos(parent ? parent->pos() : QPointF(0, 0));
        anim->addAnimation(node->getFadeInAnim());
        if (group)
        {
            anim->addAnimation(node->setParent(parent));
            anim->addAnimation(getPosAnim());
            group->addAnimation(anim);
            if (parent)
                group->addAnimation(parent->getTurnBlackAnim());
        }
        else
        {
            anim->start(QAbstractAnimation::DeleteWhenStopped);
        }
        return;
    }
    TreePath *path;
    if (group && parent)
    {
        path = new TreePath(parent, node, view);
        group->addAnimation(path->getToSonAnim());
    }
    if (node->data > x)
    {
        Insert(node->Lson, node, x, group);
        if (group && parent)
            group->addAnimation(path->getToParentAnim());
        if (2 == height(node->Lson) - height(node->Rson))
        {
            if (x < node->Lson->data)
                LL(node, group);
            else
                LR(node, group);
        }
    }
    else if (node->data < x)
    {
        Insert(node->Rson, node, x, group);
        if (group && parent)
            group->addAnimation(path->getToParentAnim());
        if (2 == height(node->Rson) - height(node->Lson))
        {
            if (x > node->Rson->data)
                RR(node, group);
            else
                RL(node, group);
        }
    }
    else if (group && parent)
        group->addAnimation(path->getToParentAnim());
    if (group && parent)
        group->addAnimation(parent->getTurnBlackAnim());
    node->h = max(height(node->Lson), height(node->Rson)) + 1;
}