void HierarchyTreeWidget::OnSelectedControlNodesChanged(const HierarchyTreeController::SELECTEDCONTROLNODES &selectedControls) { if (internalSelectionChanged) return; internalSelectionChanged = true; ResetSelection(); TREEITEMS items = GetAllItems(); for (HierarchyTreeController::SELECTEDCONTROLNODES::const_iterator iter = selectedControls.begin(); iter != selectedControls.end(); ++iter) { const HierarchyTreeControlNode* node = (*iter); TREEITEMS::iterator itemIter = items.find(node->GetId()); if (itemIter != items.end()) { QTreeWidgetItem* item = itemIter->second; item->setSelected(true); // Force show selected item QTreeWidgetItem* parentItem = item->parent(); while (parentItem) { parentItem->setExpanded(true); parentItem = parentItem->parent(); } } } internalSelectionChanged = false; }
void HierarchyTreeWidget::OnTreeUpdated(bool needRestoreSelection) { EXPANDEDITEMS expandedItems; EXPANDEDITEMS selectedItems; //save opened node TREEITEMS oldItems = GetAllItems(); for (TREEITEMS::iterator iter = oldItems.begin(); iter != oldItems.end(); ++iter) { QTreeWidgetItem* item = iter->second; if (item->isExpanded()) { QVariant data = item->data(ITEM_ID); expandedItems.insert(data.toInt()); } } //save selected node for (TREEITEMS::iterator iter = oldItems.begin(); iter != oldItems.end(); ++iter) { QTreeWidgetItem* item = iter->second; if (item->isSelected()) { QVariant data = item->data(ITEM_ID); selectedItems.insert(data.toInt()); HierarchyTreeNode* baseNode = HierarchyTreeController::Instance()->GetTree().GetNode(data.toInt()); HierarchyTreeControlNode* selectedControl = dynamic_cast<HierarchyTreeControlNode* >(baseNode); if(NULL != selectedControl) { internalSelectionChanged = true; } } } //reset tree ui->treeWidget->clear(); const HierarchyTree& tree = HierarchyTreeController::Instance()->GetTree(); const HierarchyTreeRootNode* rootNode = tree.GetRootNode(); for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = rootNode->GetChildNodes().begin(); iter != rootNode->GetChildNodes().end(); ++iter) { //add platform node const HierarchyTreePlatformNode* platformNode = (const HierarchyTreePlatformNode*)(*iter); QTreeWidgetItem* platformItem = new QTreeWidgetItem(); platformItem->setData(ITEM_ID, platformNode->GetId()); QString platformName = platformNode->GetName(); if (platformNode->IsNeedSave()) { platformName += " *"; } platformItem->setText(0, platformName); platformItem->setIcon(0, QIcon(IconHelper::GetPlatformIconPath())); ui->treeWidget->insertTopLevelItem(ui->treeWidget->topLevelItemCount(), platformItem); for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = platformNode->GetChildNodes().begin(); iter != platformNode->GetChildNodes().end(); ++iter) { const HierarchyTreeScreenNode* screenNode = dynamic_cast<const HierarchyTreeScreenNode*>(*iter); DVASSERT(screenNode); QTreeWidgetItem* screenItem = new QTreeWidgetItem(); screenItem->setData(ITEM_ID, screenNode->GetId()); // Check whether this screen was changed. QString screenItemText = screenNode->GetName(); if (screenNode->IsNeedSave()) { screenItemText += " *"; } screenItem->setText(0, screenItemText); if (dynamic_cast<const HierarchyTreeAggregatorNode*>(screenNode)) screenItem->setIcon(0, QIcon(IconHelper::GetAggregatorIconPath())); else screenItem->setIcon(0, QIcon(IconHelper::GetScreenIconPath())); platformItem->insertChild(platformItem->childCount(), screenItem); AddControlItem(screenItem, screenNode->GetChildNodes()); } } // Restore the selected items only after the tree is fully built. int itemsCount = ui->treeWidget->topLevelItemCount(); for (int i = 0; i < itemsCount; i ++) { QTreeWidgetItem* rootItem = ui->treeWidget->topLevelItem(i); RestoreTreeItemExpandedStateRecursive(rootItem, expandedItems); if (needRestoreSelection) { RestoreTreeItemSelectedStateRecursive(rootItem, selectedItems); } } internalSelectionChanged = false; }
void HierarchyTreeWidget::OnTreeUpdated() { EXPANDEDITEMS expandedItems; EXPANDEDITEMS selectedItems; //save opened node TREEITEMS oldItems = GetAllItems(); for (TREEITEMS::iterator iter = oldItems.begin(); iter != oldItems.end(); ++iter) { QTreeWidgetItem* item = iter->second; if (item->isExpanded()) { QVariant data = item->data(ITEM_ID); expandedItems.insert(data.toInt()); } } //save selected node for (TREEITEMS::iterator iter = oldItems.begin(); iter != oldItems.end(); ++iter) { QTreeWidgetItem* item = iter->second; if (item->isSelected()) { QVariant data = item->data(ITEM_ID); selectedItems.insert(data.toInt()); HierarchyTreeNode* baseNode = HierarchyTreeController::Instance()->GetTree().GetNode(data.toInt()); HierarchyTreeControlNode* selectedControl = dynamic_cast<HierarchyTreeControlNode* >(baseNode); if(NULL != selectedControl) { internalSelectionChanged = true; } } } //reset tree ui->treeWidget->clear(); const HierarchyTree& tree = HierarchyTreeController::Instance()->GetTree(); const HierarchyTreeRootNode* rootNode = tree.GetRootNode(); for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = rootNode->GetChildNodes().begin(); iter != rootNode->GetChildNodes().end(); ++iter) { //add platform node const HierarchyTreePlatformNode* platformNode = (const HierarchyTreePlatformNode*)(*iter); QTreeWidgetItem* platformItem = new QTreeWidgetItem(); platformItem->setData(ITEM_ID, platformNode->GetId()); platformItem->setText(0, platformNode->GetName()); platformItem->setIcon(0, QIcon(":/Icons/079i.png")); ui->treeWidget->insertTopLevelItem(ui->treeWidget->topLevelItemCount(), platformItem); for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = platformNode->GetChildNodes().begin(); iter != platformNode->GetChildNodes().end(); ++iter) { const HierarchyTreeScreenNode* screenNode = dynamic_cast<const HierarchyTreeScreenNode*>(*iter); DVASSERT(screenNode); QTreeWidgetItem* screenItem = new QTreeWidgetItem(); screenItem->setData(ITEM_ID, screenNode->GetId()); // Check whether this screen was changed. QString screenItemText = screenNode->GetName(); if (screenNode->GetUnsavedChanges() != 0) { screenItemText += " *"; } screenItem->setText(0, screenItemText); if (dynamic_cast<const HierarchyTreeAggregatorNode*>(screenNode)) screenItem->setIcon(0, QIcon(":/Icons/170.png")); else screenItem->setIcon(0, QIcon(":/Icons/068i.png")); platformItem->insertChild(platformItem->childCount(), screenItem); AddControlItem(screenItem, selectedItems, expandedItems, screenNode->GetChildNodes()); if (expandedItems.find(screenNode->GetId()) != expandedItems.end()) screenItem->setExpanded(true); if (selectedItems.find(screenNode->GetId()) != selectedItems.end()) { screenItem->setSelected(true); } } if (expandedItems.find(platformNode->GetId()) != expandedItems.end()) platformItem->setExpanded(true); if (selectedItems.find(platformNode->GetId()) != selectedItems.end()) { platformItem->setSelected(true); } } internalSelectionChanged = false; }