Example #1
0
/*!
 * \brief Using a path based on the node string, set the currently
 *        selected node
 *
 * \param route List defining the path using node strings starting at the root node
 *
 * \return True if successful
 */
bool MythUIButtonTree::SetNodeByString(QStringList route)
{
    if (!m_rootNode)
    {
        DoSetCurrentNode(NULL);
        return false;
    }

    MythGenericTree *foundNode = m_rootNode;

    bool foundit = false;

    if (!route.isEmpty())
    {
        if (route[0] == m_rootNode->getString())
        {
            if (route.size() > 1)
            {
                for (int i = 1; i < route.size(); i ++)
                {
                    MythGenericTree *node = foundNode->getChildByName(route[i]);

                    if (node)
                    {
                        node->becomeSelectedChild();
                        foundNode = node;
                        foundit = true;
                    }
                    else
                    {
                        node = foundNode->getChildAt(0);

                        if (node)
                        {
                            node->becomeSelectedChild();
                            foundNode = node;
                        }

                        break;
                    }
                }
            }
            else
                foundit = true;
        }
    }

    DoSetCurrentNode(foundNode);

    m_currentDepth = qMax(0, (int)(foundNode->currentDepth() - m_depthOffset - m_numLists));
    m_activeListID = qMin(foundNode->currentDepth() - m_depthOffset - 1, (int)(m_numLists - 1));

    SetTreeState(true);

    return foundit;
}