internal void SortItems(
      SortDescriptionInfo[] sortDescriptionInfos,
      GroupSortComparer[] groupSortComparers,
      int level,
      List<RawItem> globalRawItems,
      DataGridCollectionViewGroup newSortedGroup )
    {
      int itemCount = this.ItemCount;

      if( itemCount == 0 )
        return;

      ObservableCollection<object> groupItems = this.ProtectedItems;

      if( this.IsBottomLevel )
      {
        int[] indexes;

        indexes = new int[ itemCount + 1 ];

        for( int i = 0; i < itemCount; i++ )
        {
          indexes[ i ] = m_sortedRawItems[ i ].Index;
        }

        // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
        DataGridCollectionViewSort collectionViewSort =
          new DataGridCollectionViewSort( indexes, sortDescriptionInfos );

        collectionViewSort.Sort( itemCount );
        int index = 0;

        for( int i = 1; i <= itemCount; i++ )
        {
          newSortedGroup.InsertRawItem( index, globalRawItems[ indexes[ i ] ] );
          index++;
        }
      }
      else
      {
        int[] indexes;

        indexes = new int[ itemCount + 1 ];

        for( int i = 0; i < itemCount; i++ )
        {
          indexes[ i ] = i;
        }

        // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
        DataGridCollectionViewGroupSort collectionViewSort =
          new DataGridCollectionViewGroupSort( indexes, groupSortComparers[ level ], this );

        collectionViewSort.Sort( itemCount );
        int index = 0;
        level++;

        for( int i = 1; i <= itemCount; i++ )
        {
          DataGridCollectionViewGroup oldGroup = ( DataGridCollectionViewGroup )groupItems[ indexes[ i ] ];
          DataGridCollectionViewGroup newGroup = new DataGridCollectionViewGroup( oldGroup, newSortedGroup );

          // Sort sub items
          oldGroup.SortItems( sortDescriptionInfos, groupSortComparers, level, globalRawItems, newGroup );

          newSortedGroup.InsertGroup( index, newGroup );
          index++;
        }
      }
    }
示例#2
0
        internal void SortItems(
            SortDescriptionInfo[] sortDescriptionInfos,
            GroupSortComparer[] groupSortComparers,
            int level,
            List <RawItem> globalRawItems,
            DataGridCollectionViewGroup newSortedGroup)
        {
            int itemCount = this.ItemCount;

            if (itemCount == 0)
            {
                return;
            }

            ObservableCollection <object> groupItems = this.ProtectedItems;

            if (this.IsBottomLevel)
            {
                int[] indexes;

                indexes = new int[itemCount + 1];

                for (int i = 0; i < itemCount; i++)
                {
                    indexes[i] = m_sortedRawItems[i].Index;
                }

                // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
                DataGridCollectionViewSort collectionViewSort =
                    new DataGridCollectionViewSort(indexes, sortDescriptionInfos);

                collectionViewSort.Sort(itemCount);
                int index = 0;

                for (int i = 1; i <= itemCount; i++)
                {
                    newSortedGroup.InsertRawItem(index, globalRawItems[indexes[i]]);
                    index++;
                }
            }
            else
            {
                int[] indexes;

                indexes = new int[itemCount + 1];

                for (int i = 0; i < itemCount; i++)
                {
                    indexes[i] = i;
                }

                // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
                DataGridCollectionViewGroupSort collectionViewSort =
                    new DataGridCollectionViewGroupSort(indexes, groupSortComparers[level], this);

                collectionViewSort.Sort(itemCount);
                int index = 0;
                level++;

                for (int i = 1; i <= itemCount; i++)
                {
                    DataGridCollectionViewGroup oldGroup = ( DataGridCollectionViewGroup )groupItems[indexes[i]];
                    DataGridCollectionViewGroup newGroup = new DataGridCollectionViewGroup(oldGroup, newSortedGroup);

                    // Sort sub items
                    oldGroup.SortItems(sortDescriptionInfos, groupSortComparers, level, globalRawItems, newGroup);

                    newSortedGroup.InsertGroup(index, newGroup);
                    index++;
                }
            }
        }
        internal void SortItems(
            IList <SortDescriptionInfo> sortDescriptionInfos,
            List <GroupSortComparer> groupSortComparers,
            int level,
            List <RawItem> globalRawItems,
            DataGridCollectionViewGroup newSortedGroup)
        {
            var itemCount = this.ProtectedItemCount;

            if (itemCount == 0)
            {
                return;
            }

            if (this.IsBottomLevel)
            {
                var indexes = new int[itemCount + 1];

                for (int i = 0; i < itemCount; i++)
                {
                    indexes[i] = m_sortedRawItems[i].Index;
                }

                // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
                var collectionViewSort = new DataGridCollectionViewSort(indexes, sortDescriptionInfos);

                collectionViewSort.Sort(itemCount);
                var index = 0;

                for (int i = 1; i <= itemCount; i++)
                {
                    newSortedGroup.InsertRawItem(index, globalRawItems[indexes[i]]);
                    index++;
                }
            }
            else
            {
                var indexes = new int[itemCount + 1];

                for (int i = 0; i < itemCount; i++)
                {
                    indexes[i] = i;
                }

                var subGroupsArray = new DataGridCollectionViewGroup[itemCount];
                m_subGroups.Values.CopyTo(subGroupsArray, 0);

                // "Weak heap sort" sort array[0..NUM_ELEMENTS-1] to array[1..NUM_ELEMENTS]
                var collectionViewSort = new DataGridCollectionViewGroupSort(indexes, groupSortComparers[level], subGroupsArray);

                collectionViewSort.Sort(itemCount);
                int index = 0;
                level++;

                for (int i = 1; i <= itemCount; i++)
                {
                    DataGridCollectionViewGroup oldGroup = subGroupsArray[indexes[i]];
                    DataGridCollectionViewGroup newGroup = new DataGridCollectionViewGroup(oldGroup, newSortedGroup);

                    // Sort sub items
                    oldGroup.SortItems(sortDescriptionInfos, groupSortComparers, level, globalRawItems, newGroup);

                    newSortedGroup.InsertGroup(index, newGroup);
                    index++;
                }
            }
        }