/*! * \brief Remove the item from the tree * * \param item Item to be removed * \param deleteNode Also delete the node from the tree? Modifies the tree. * * \return True if successful */ void MythUIButtonTree::RemoveItem(MythUIButtonListItem *item, bool deleteNode) { if (!item || !m_rootNode) return; MythGenericTree *node = qVariantValue<MythGenericTree *>(item->GetData()); if (node && node->getParent()) { DoSetCurrentNode(node->getParent()); if (deleteNode) node->getParent()->deleteNode(node); else node->SetVisible(false); } MythUIButtonList *list = item->parent(); list->RemoveItem(item); if (list->IsEmpty()) { if (m_currentDepth > 0) m_currentDepth--; else if (m_activeListID > 1) m_activeListID--; SetTreeState(true); } }
/*! * \brief Set the widget active/inactive * * \param active */ void MythUIButtonTree::SetActive(bool active) { m_active = active; if (m_initialized) SetTreeState(); }
//------------------------------------------------------------------------------ // void Uct::UpdateState(const GameStatePtr &state) // //------------------------------------------------------------------------------ { auto stateCopy = state->Clone(); stateCopy->SetTreeState(true); m_rootNode = ChildPtr(new GameNode(stateCopy)); m_rootNode->ClearNodeTable(); }
/*! * \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; }
/*! * \brief Using a path based on the node IDs, set the currently * selected node * * \param route List defining the path using node IDs starting at the root node * * \return True if successful */ bool MythUIButtonTree::SetNodeById(QList<int> route) { MythGenericTree *node = m_rootNode->findNode(route); if (node && node->isSelectable()) { DoSetCurrentNode(node); SetTreeState(); return true; } return false; }
/*! * \copydoc MythUIType::Reset() */ void MythUIButtonTree::Reset(void) { m_rootNode = m_currentNode = NULL; m_visibleLists = 0; m_currentDepth = m_oldDepth = 0; m_activeList = NULL; m_activeListID = 0; m_active = true; SetTreeState(true); MythUIType::Reset(); }
/*! * \brief Assign the root node of the tree to be displayed * * MythUIButtonTree() is merely responsible for the display and navigation of a * tree, the structure of that tree and the data it contains are the * responsibility of MythGenericTree(). Generally MythUIButtonTree() will not * modify the tree, for technical reason RemoteItem() is an exception to the rule. * * You should operate directly on MythGenericTree() to change it's content. * * \param tree The node to make the root of the displayed tree * * \return True if successful */ bool MythUIButtonTree::AssignTree(MythGenericTree *tree) { if (!tree || !tree->visibleChildCount()) return false; if (m_rootNode) Reset(); m_rootNode = tree; m_currentNode = m_rootNode->getSelectedChild(); // The node we are given may not be the root node of that tree, we need // to keep track of our depth in the tree so that we can navigate // as though the parent nodes do not exist m_depthOffset = m_rootNode->currentDepth(); SetTreeState(true); return true; }
/*! * \brief Move from list, or one level of the tree, to another * * \param right If true move to the right or away from the root, if false move to * the left or towards the root */ void MythUIButtonTree::SwitchList(bool right) { bool doUpdate = false; if (right) { if ((m_activeListID + 1 < m_visibleLists) && (m_activeListID + 1 < (uint)m_buttonlists.count())) m_activeListID++; else if (m_currentNode && m_currentNode->visibleChildCount() > 0) { m_currentDepth++; doUpdate = true; } else return; } else if (!right) { if (m_activeListID > 0) m_activeListID--; else if (m_currentDepth > 0) { m_currentDepth--; doUpdate = true; } else return; } if (doUpdate) SetTreeState(); else { if (m_activeList) m_activeList->Deselect(); if (m_activeListID < (uint)m_buttonlists.count()) { m_activeList = m_buttonlists[m_activeListID]; m_activeList->Select(); } } }
/*! * \brief Handle a list item receiving focus * * \param item The list item */ void MythUIButtonTree::handleSelect(MythUIButtonListItem *item) { if (!item) return; MythUIButtonList *list = item->parent(); QString name = list->objectName(); // New list is automatically selected so we just need to deselect the old // list if (m_activeList) m_activeList->Deselect(); m_activeListID = name.section(' ',2,2).toInt(); m_activeList = list; MythGenericTree *node = qVariantValue<MythGenericTree*> (item->GetData()); DoSetCurrentNode(node); SetTreeState(); }