Skip to content

Commit

Permalink
Merge pull request #54 from celeron533/lookup_performance
Browse files Browse the repository at this point in the history
Lookup performance
  • Loading branch information
celeron533 authored Jan 21, 2024
2 parents 5b19f88 + 78b235b commit 6764972
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
11 changes: 8 additions & 3 deletions DicomGrep/Views/DicomDictionaryLookupView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Name="header" MinHeight="40">
<Grid Name="header" MinHeight="40" Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
Expand Down Expand Up @@ -47,6 +48,10 @@
<DataGridTextColumn Header="Private Creator" Binding="{Binding Tag.PrivateCreator, Mode=OneWay}"/>
</DataGrid.Columns>
</DataGrid>

<StatusBar Grid.Row="2">
<StatusBarItem>
<Label Content="{Binding ElementName=dataGridUid, Path=Items.Count}" ContentStringFormat="Tags: {0}"/>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>
22 changes: 19 additions & 3 deletions DicomGrep/Views/DicomDictionaryLookupView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace DicomGrep.Views
{
Expand All @@ -21,14 +22,22 @@ namespace DicomGrep.Views
/// </summary>
public partial class DicomDictionaryLookupView : Window
{
// delayed search for better performance
private DispatcherTimer timer = new DispatcherTimer();

public DicomDictionaryLookupView()
{
InitializeComponent();

timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
}

private void Filter_TextChanged(object sender, TextChangedEventArgs e)
private void Timer_Tick(object sender, EventArgs e)
{
TextBox filterTextBox = (TextBox)sender;
timer.Stop();

TextBox filterTextBox = filter;
string filterText = filterTextBox.Text;
ICollectionView cv = CollectionViewSource.GetDefaultView(dataGridUid.ItemsSource);

Expand All @@ -39,7 +48,7 @@ private void Filter_TextChanged(object sender, TextChangedEventArgs e)
DicomDictionaryEntry dictionary = obj as DicomDictionaryEntry;
return dictionary.ToString().Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase) ||
(
dictionary.Tag.PrivateCreator != null &&
dictionary.Tag.PrivateCreator != null &&
dictionary.Tag.PrivateCreator.Creator.Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase)
) ||
dictionary.Name.Contains(filterText.Trim(), StringComparison.OrdinalIgnoreCase);
Expand All @@ -52,6 +61,13 @@ private void Filter_TextChanged(object sender, TextChangedEventArgs e)
}
}

private void Filter_TextChanged(object sender, TextChangedEventArgs e)
{
// reset the timer
timer.Stop();
timer.Start();
}

private void pick_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
Expand Down
13 changes: 9 additions & 4 deletions DicomGrep/Views/SopClassLookupView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="20"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Name="header" MinHeight="40">
<Grid Name="header" MinHeight="40" Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
Expand All @@ -34,6 +35,10 @@
<DataGrid Name="dataGridUid" ItemsSource="{Binding SOPClassUIDs, Mode=OneWay}" AutoGenerateColumns="True"
SelectedItem="{Binding SelectedUID, Mode=OneWayToSource}" SelectionMode="Single"
Grid.Row="1" MouseDoubleClick="dataGridUid_MouseDoubleClick"/>

<StatusBar Grid.Row="2">
<StatusBarItem>
<Label Content="{Binding ElementName=dataGridUid, Path=Items.Count}" ContentStringFormat="UIDs: {0}"/>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>
20 changes: 18 additions & 2 deletions DicomGrep/Views/SopClassLookupView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace DicomGrep.Views
{
Expand All @@ -21,14 +22,22 @@ namespace DicomGrep.Views
/// </summary>
public partial class SopClassLookupView : Window
{
// delayed search for better performance
private DispatcherTimer timer = new DispatcherTimer();

public SopClassLookupView()
{
InitializeComponent();

timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
}

private void Filter_TextChanged(object sender, TextChangedEventArgs e)
private void Timer_Tick(object sender, EventArgs e)
{
TextBox filterTextBox = (TextBox)sender;
timer.Stop();

TextBox filterTextBox = filter;
string filterText = filterTextBox.Text;
ICollectionView cv = CollectionViewSource.GetDefaultView(dataGridUid.ItemsSource);

Expand All @@ -47,6 +56,13 @@ private void Filter_TextChanged(object sender, TextChangedEventArgs e)
}
}

private void Filter_TextChanged(object sender, TextChangedEventArgs e)
{
// reset the timer
timer.Stop();
timer.Start();
}

private void pick_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
Expand Down

0 comments on commit 6764972

Please sign in to comment.