Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit a3775b6

Browse files
Sort sub list in Groups by any Column,
see src\AddIns\Analysis\CodeQuality\Reporting\DependencyReport.cs for example
1 parent 7c9994a commit a3775b6

4 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/AddIns/Analysis/CodeQuality/Reporting/DependencyReport.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
using System;
2020
using System.Collections.Generic;
2121
using System.Collections.ObjectModel;
22+
using System.ComponentModel;
2223
using System.Reflection;
2324

2425
using ICSharpCode.Reporting;
2526
using ICSharpCode.Reporting.Interfaces;
27+
using ICSharpCode.Reporting.Items;
2628
using ICSharpCode.CodeQuality.Engine.Dom;
2729

2830
namespace ICSharpCode.CodeQuality.Reporting
@@ -46,6 +48,11 @@ public IReportCreator Run(ReadOnlyCollection<AssemblyNode> list)
4648
var reportingFactory = new ReportingFactory();
4749
var reportCreator = reportingFactory.ReportCreator (stream,newList);
4850
ReportSettings = reportingFactory.ReportModel.ReportSettings;
51+
var groupColumn = (GroupColumn)ReportSettings.GroupColumnsCollection[0];
52+
groupColumn.GroupSortColumn = new SortColumn() {
53+
ColumnName = "ReferenceCount",
54+
SortDirection = ListSortDirection.Ascending
55+
};
4956
reportCreator.BuildExportList();
5057
return reportCreator;
5158
}

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,13 @@ void Group()
143143

144144

145145
IEnumerable<IGrouping<object, object>> GroupInternal () {
146+
PropertyDescriptor sortProperty = null;
146147
var groupProperty = listProperties.Find(reportSettings.GroupColumnsCollection[0].ColumnName,true);
147-
var sortProperty = listProperties.Find("Randomint",true);
148+
var groupColumn = (GroupColumn)reportSettings.GroupColumnsCollection[0];
149+
150+
if (groupColumn.GroupSortColumn != null) {
151+
sortProperty = listProperties.Find(groupColumn.GroupSortColumn.ColumnName,true);
152+
}
148153
IEnumerable<IGrouping<object, object>> groupedList;
149154
if (sortProperty == null) {
150155
groupedList = baseList.GroupBy(a => a.GetType().GetProperty(groupProperty.Name).GetValue(a, null)).OrderBy(c => c.Key);
@@ -155,7 +160,6 @@ IEnumerable<IGrouping<object, object>> GroupInternal () {
155160
return groupedList;
156161
}
157162

158-
159163
#endregion
160164

161165
public void Bind()
@@ -167,8 +171,8 @@ public void Bind()
167171
}
168172
}
169173

170-
#region Fill
171174

175+
#region Fill
172176

173177
public void Fill (List<IPrintableObject> collection, object current) {
174178
Current = current;

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/GroupColumn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public GroupColumn(string columnName,int groupLevel, ListSortDirection sortDirec
4343

4444
public int GroupLevel {get;private set;}
4545

46-
46+
public SortColumn GroupSortColumn {get;set;}
4747
}
4848
}

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,47 @@ public void AvailableFieldsEqualContibutorsPropertyCount() {
4646
}
4747

4848

49+
[Test]
50+
public void GroupbyOneColumnSortSubList () {
51+
var rs = new ReportSettings();
52+
var gc = new GroupColumn() {
53+
ColumnName ="GroupItem",
54+
SortDirection = ListSortDirection.Ascending,
55+
GroupSortColumn = new SortColumn() {
56+
ColumnName = "Randomint",
57+
SortDirection = ListSortDirection.Ascending
58+
}
59+
};
60+
rs.GroupColumnsCollection.Add(gc);
61+
var collectionSource = new CollectionDataSource (list,rs);
62+
collectionSource.Bind();
63+
var testKey = String.Empty;
64+
var testSubKey = -1;
65+
var groupedList = collectionSource.GroupedList;
66+
foreach (var element in groupedList) {
67+
Assert.That(element.Key,Is.GreaterThan(testKey));
68+
testKey = element.Key.ToString();
69+
foreach (Contributor sub in element) {
70+
Assert.That(sub.RandomInt,Is.GreaterThanOrEqualTo(testSubKey));
71+
testSubKey = sub.RandomInt;
72+
}
73+
testSubKey = -1;
74+
}
75+
}
76+
4977

5078
[Test]
5179
public void GroupbyOneColumn () {
5280
var rs = new ReportSettings();
5381
rs.GroupColumnsCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending));
5482
var collectionSource = new CollectionDataSource (list,rs);
5583
collectionSource.Bind();
84+
var testKey = String.Empty;
85+
var groupedList = collectionSource.GroupedList;
86+
foreach (var element in groupedList) {
87+
Assert.That(element.Key,Is.GreaterThan(testKey));
88+
testKey = element.Key.ToString();
89+
}
5690
}
5791

5892

0 commit comments

Comments
 (0)