public virtual void RemoveItem(GenericItem item) { var parentItem = item.GetParent(); var childId = parentItem.GetChildren().IndexOf(item); NotifyChildrenWillBeRemoved(new ModelIndex(parentItem), childId, 1); DeleteChildren(item, true); // TODO: delete* itor; parentItem.GetChildren().Remove(item); NotifyChildrenRemoved(new ModelIndex(parentItem), childId, 1); //std::vector<GenericItem*>::iterator itor = std::find( // parent_item->getChildren().begin(), parent_item->getChildren().end(), // item); //if (itor != parent_item->getChildren().end()) //{ // size_t child_id = std::distance(parent_item->getChildren().begin(), itor); // notifyChildrenWillBeRemoved(ModelIndex(parent_item), child_id, 1); // deleteChildren(*itor, true); // delete *itor; // parent_item->getChildren().erase(itor); // notifyChildrenRemoved(ModelIndex(parent_item), child_id, 1); //} }
/// <summary> /// Gets the ordinal id (index) of the specified item in parent's children list. /// </summary> /// <param name="item"></param> /// <returns></returns> public virtual int GetChildId(GenericItem item) { if (item == null || item.GetParent() == null) { return(-1); } var parentItem = item.GetParent(); return(parentItem.GetChildren().IndexOf(item)); //std::vector<GenericItem*>::iterator itor = std::find( // parent_item->getChildren().begin(), parent_item->getChildren().end(), item); //if (itor == parent_item->getChildren().end()) // return -1; //return std::distance(parent_item->getChildren().begin(), itor); }
/// <summary> /// Creates a ModelIndex that represents the specified index. /// /// This method is the inverse of getItemForIndex(const ModelIndex&). /// </summary> /// <param name="item"></param> /// <returns></returns> public virtual ModelIndex GetIndexForItem(GenericItem item) { // TODO: this is annoying. We should be able to just hand out the ModelIndex // Right now we can't, since we're in a const method, operating on a const item // In hindsight, the index we hand out will be modifiable so maybe we need // to change the const-ness of the item parameter. var parent = item.GetParent(); var child_id = GetChildId(item); return(new ModelIndex(child_id != -1 ? parent.GetChildren()[child_id] : null)); }