Skip to content

Commit

Permalink
Added an option to select list filtering methods (fix #562)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Jun 19, 2024
1 parent fc5ae6c commit 6c8641c
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 52 deletions.
2 changes: 1 addition & 1 deletion locales/Afrikaans.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Belarusian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Chinese Simplified.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Dutch.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/English.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single ; tree border style
972=Double ; tree border style
Expand Down
2 changes: 1 addition & 1 deletion locales/Hungarian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Icelandic.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Japanese.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Kazakh (Cyrillic).lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Portuguese.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Serbian (Latin).lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/Spanish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/czech.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/french.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/german.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>14.06.2024 [v2.30.1 &amp; v3.6.1]</b><ul>
<li>Added an option to select list filtering methods (differences in speed).
<li>Added an option to display the full name in one line in trees, for countries with a short form of the full name (hieroglyphs).
<li>Added custom event types, the feature to turn off events and add custom ones.
<li>Added localizable names for tree borders.
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>14.06.2024 [v2.30.1 &amp; v3.6.1]</b><ul>
<li>Добавлена опция выбора методов фильтрации списков (различия по скорости).
<li>Добавлена опция вывода в деревьях полного имени в одну строку, для стран с короткой формой полного имени (иероглифы).
<li>Добавлены настраиваемые типы событий, возможность выключения событий и добавления пользовательских.
<li>Добавлены локализуемые названия границ деревьев.
Expand Down
2 changes: 1 addition & 1 deletion locales/italian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/polish.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
2 changes: 1 addition & 1 deletion locales/russian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=Для пользовательских событий и фактов необходимо ввести тип
968=Определение события
969=Полное имя в одну строку
970=<?>
970=Метод фильтрации

971=Одинарная
972=Двойная
Expand Down
2 changes: 1 addition & 1 deletion locales/ukrainian.lng
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@
967=For custom events and facts, the type must be entered
968=Event Definition
969=Full name on one line
970=<?>
970=Match pattern method

971=Single
972=Double
Expand Down
11 changes: 11 additions & 0 deletions projects/GKCore/GKCore/Controllers/OptionsDlgController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ public void UpdateInterfaceOptions()

GetControl<ICheckBox>("chkUseSurnamesInPSF").Checked = fOptions.UseSurnamesInPersonSelectionFilter;
GetControl<ICheckBox>("chkUseBirthDatesInPSF").Checked = fOptions.UseBirthDatesInPersonSelectionFilter;

var combo = GetControl<IComboBox>("cmbMatchPatternMethod");
combo.Clear();
for (MatchPatternMethod itm = MatchPatternMethod.RegEx; itm <= MatchPatternMethod.Fast; itm++) {
combo.AddItem(itm.ToString(), itm);
}
combo.SetSelectedTag(fOptions.MatchPatternMethod);
}

public NameFormat GetSelectedNameFormat()
Expand Down Expand Up @@ -425,6 +432,8 @@ public void AcceptInterfaceOptions()

fOptions.UseSurnamesInPersonSelectionFilter = GetControl<ICheckBox>("chkUseSurnamesInPSF").Checked;
fOptions.UseBirthDatesInPersonSelectionFilter = GetControl<ICheckBox>("chkUseBirthDatesInPSF").Checked;

fOptions.MatchPatternMethod = GetControl<IComboBox>("cmbMatchPatternMethod").GetSelectedTag<MatchPatternMethod>();
}

public void ResetSpecialsOptions()
Expand Down Expand Up @@ -981,6 +990,8 @@ public override void SetLocale()
GetControl<ITabPage>("pageViewPersons").Text = LangMan.LS(LSID.ListPersons);
GetControl<IButton>("btnResetDefaults").Text = LangMan.LS(LSID.DefList);

GetControl<ILabel>("lblMatchPatternMethod").Text = LangMan.LS(LSID.MatchPatternMethod);

// Pedigree
GetControl<ITabPage>("pagePedigree").Text = LangMan.LS(LSID.Pedigrees);

Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GKCore/LangMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ public enum LSID
/* 967 */ TagTypeWarning,
/* 968 */ EventDefinition,
/* 969 */ FullNameOnOneLine,
/* 970 */ Reserved_970,
/* 970 */ MatchPatternMethod,

/* 971 */ TBS_Single,
/* 972 */ TBS_Double,
Expand Down Expand Up @@ -2053,7 +2053,7 @@ public static class LangMan
/* 967 */ "For custom events and facts, the type must be entered",
/* 968 */ "Event Definition",
/* 969 */ "Full name on one line",
/* 970 */ "<?>",
/* 970 */ "Match pattern method",

/* 971 */ "Single",
/* 972 */ "Double",
Expand Down
2 changes: 2 additions & 0 deletions projects/GKCore/GKCore/Lists/IndividualListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ protected override object GetColumnValueEx(int colType, int colSubtype, bool isV

public override void PrepareFilter()
{
base.PrepareFilter();

IndividualListFilter iFilter = (IndividualListFilter)fFilter;

filter_abd = GDMDate.GetUDNByFormattedStr(iFilter.AliveBeforeDate, GDMCalendar.dcGregorian);
Expand Down
67 changes: 39 additions & 28 deletions projects/GKCore/GKCore/Lists/ListSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//#define REGEX_MASKS

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
Expand All @@ -36,6 +34,12 @@

namespace GKCore.Lists
{
public enum MatchPatternMethod
{
RegEx, FastIgnoreCase, Fast
}


/// <summary>
///
/// </summary>
Expand All @@ -55,6 +59,7 @@ public abstract class ListSource<T> : IListSource
protected ExternalFilterHandler fExternalFilter;
protected T fFetchedRec;
protected ListFilter fFilter;
protected MatchPatternMethod fFilterMethod;

protected readonly IBaseContext fBaseContext;
protected readonly List<MapColumnRec> fColumnsMap;
Expand Down Expand Up @@ -238,40 +243,45 @@ public int GetColumnIndex(int columnId)

#region Mask processing

/// <summary>
/// Tests on working database, filtering 691 from 12174 records, pattern `*xxxx*xxx*`.
/// RegEx -> 394.4 ms -> x1
/// FastIgnoreCase -> 142.9 ms -> x2.8
/// Fast -> 37.9 ms -> x10.4
/// </summary>
protected bool IsMatchesMask(string str, string mask)
{
#if !REGEX_MASKS
if (fFilterMethod != MatchPatternMethod.RegEx) {
bool ignoreCase = (fFilterMethod == MatchPatternMethod.FastIgnoreCase);

// This method of processing name matching with a pattern mask compared to using RegEx:
// 4.6 times faster if without unsafe operations (601 -> 129 ms)
// and 11.5 times faster if with unsafe operations (601 -> 52 ms).
return SysUtils.MatchPattern(mask, str);

#else

bool any = false;
if (string.IsNullOrEmpty(mask) || (any = mask.Equals("*"))) {
return true;
}
// This method of processing name matching with a pattern mask compared to using RegEx:
// 4.6 times faster if without unsafe operations (601 -> 129 ms)
// and 11.5 times faster if with unsafe operations (601 -> 52 ms).
return SysUtils.MatchPattern(mask, str, ignoreCase);
} else {
bool any = false;
if (string.IsNullOrEmpty(mask) || (any = mask.Equals("*"))) {
return true;
}

if (string.IsNullOrEmpty(str)) {
return any;
}
if (string.IsNullOrEmpty(str)) {
return any;
}

if (fMask != mask) {
fMask = mask;
fSimpleMask = GetSimpleMask(fMask);
if (fSimpleMask == null) {
fRegexMask = new Regex(GKUtils.PrepareMask(fMask), GKUtils.RegexOpts);
if (fMask != mask) {
fMask = mask;
fSimpleMask = GetSimpleMask(fMask);
if (fSimpleMask == null) {
fRegexMask = new Regex(GKUtils.PrepareMask(fMask), GKUtils.RegexOpts);
}
}
}

if (fSimpleMask != null) {
return str.IndexOf(fSimpleMask, StringComparison.OrdinalIgnoreCase) >= 0;
} else {
return fRegexMask.IsMatch(str, 0);
if (fSimpleMask != null) {
return str.IndexOf(fSimpleMask, StringComparison.OrdinalIgnoreCase) >= 0;
} else {
return fRegexMask.IsMatch(str, 0);
}
}
#endif
}

protected bool IsMatchesMask(GDMLines strList, string mask)
Expand Down Expand Up @@ -337,6 +347,7 @@ protected bool CheckQuickFilter(string str)

public virtual void PrepareFilter()
{
fFilterMethod = GlobalOptions.Instance.MatchPatternMethod;
}

public virtual bool CheckFilter()
Expand Down
5 changes: 5 additions & 0 deletions projects/GKCore/GKCore/Options/GlobalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public ListOptionsCollection ListOptions

public ChartWindowsShowMode ChartWindowsShowMode { get; set; }

public MatchPatternMethod MatchPatternMethod { get; set; }

public MediaStoreType MediaStoreDefault { get; set; }

public List<MRUFile> MRUFiles
Expand Down Expand Up @@ -409,6 +411,7 @@ public void ResetDefaults_Interface()
UseBirthDatesInPersonSelectionFilter = false;
ShowIndiAssociations = false;
ShowIndiNamesakes = true;
MatchPatternMethod = MatchPatternMethod.RegEx;
}

public void ResetDefaults_Specials()
Expand Down Expand Up @@ -844,6 +847,7 @@ public void LoadFromFile(IniFile ini)
ShowIndiAssociations = ini.ReadBool("Common", "ShowIndiAssociations", false);
ShowIndiNamesakes = ini.ReadBool("Common", "ShowIndiNamesakes", false);
ShowNumberOfSubstructures = ini.ReadBool("Common", "ShowNumberOfSubstructures", false);
MatchPatternMethod = (MatchPatternMethod)ini.ReadInteger("Common", "MatchPatternMethod", 0);

Theme = ini.ReadString("Common", "Theme", "");

Expand Down Expand Up @@ -994,6 +998,7 @@ public void SaveToFile(IniFile ini)
ini.WriteBool("Common", "ShowIndiAssociations", ShowIndiAssociations);
ini.WriteBool("Common", "ShowIndiNamesakes", ShowIndiNamesakes);
ini.WriteBool("Common", "ShowNumberOfSubstructures", ShowNumberOfSubstructures);
ini.WriteInteger("Common", "MatchPatternMethod", (int)MatchPatternMethod);

ini.WriteString("Common", "Theme", Theme);

Expand Down
Loading

0 comments on commit 6c8641c

Please sign in to comment.