예제 #1
0
        /// <summary>
        /// Adds the item as child of the specified parent, at the specified position.
        ///
        /// After the addition, the \a parent's node will contain \a item as child
        /// at the \a position.
        /// </summary>
        /// <param name="newItem"></param>
        /// <param name="parentIndex"></param>
        /// <param name="position"></param>
        public virtual void AddItemAtPosition(GenericItem newItem, ModelIndex parentIndex, int position)
        {
            NotifyChildrenWillBeAdded(parentIndex, position, 1);

            var parent = (GenericItem)parentIndex.d_modelData;

            if (position > parent.GetChildren().Count)
            {
                throw new InvalidRequestException("The specified position is out of range.");
            }

            newItem.SetParent(parent);
            parent.GetChildren().Insert(position, newItem);

            NotifyChildrenAdded(parentIndex, position, 1);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <summary>
        /// Deletes all children of the specified item, optionally invoking the
        /// EventChildren(WillBe)Removed event
        /// </summary>
        /// <param name="item"></param>
        /// <param name="notify"></param>
        protected void DeleteChildren(GenericItem item, bool notify)
        {
            if (item == null)
            {
                throw new InvalidRequestException("Cannot delete children of a NULL item!");
            }

            var itemsCount = item.GetChildren().Count;

            //std::vector<GenericItem*>::iterator itor = item->getChildren().begin();

            if (notify)
            {
                NotifyChildrenWillBeRemoved(new ModelIndex(item), 0, itemsCount);
            }

            while (item.GetChildren().Count != 0)
            {
                var itor = item.GetChildren()[0];
                DeleteChildren(itor, notify);
                // TODO: delete *itor;
                item.GetChildren().Remove(itor);
            }

            //while (itor != item->getChildren().end())
            //{
            //    DeleteChildren(*itor, notify);
            //    // TODO: delete *itor;
            //    itor = item->getChildren().erase(itor);
            //}

            if (notify)
            {
                NotifyChildrenRemoved(new ModelIndex(item), 0, itemsCount);
            }
        }
예제 #4
0
 /// <summary>
 /// Adds the item as child of the root at the specified position.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="pos"></param>
 public virtual void AddItemAtPosition(GenericItem item, int pos)
 {
     AddItemAtPosition(item, GetRootIndex(), pos);
 }