[longomatch] Add new filters by period
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Add new filters by period
- Date: Fri, 10 Oct 2014 12:35:02 +0000 (UTC)
commit 80a7eb4ccf1f8081ccffeb3f6ff5d0e795b0adca
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Oct 9 13:15:03 2014 +0200
Add new filters by period
LongoMatch.Core/Common/EventsFilter.cs | 160 ++++++++++++--------
LongoMatch.Core/Store/TimeNode.cs | 9 +
LongoMatch.Drawing/Widgets/PlaysTimeline.cs | 2 +-
.../Gui/TreeView/CategoriesFilterTreeView.cs | 91 +++++++----
4 files changed, 166 insertions(+), 96 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsFilter.cs b/LongoMatch.Core/Common/EventsFilter.cs
index 9961fac..c6c528f 100644
--- a/LongoMatch.Core/Common/EventsFilter.cs
+++ b/LongoMatch.Core/Common/EventsFilter.cs
@@ -18,7 +18,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-
using LongoMatch.Core.Handlers;
using LongoMatch.Core.Store;
@@ -28,20 +27,22 @@ namespace LongoMatch.Core.Common
{
public event FilterUpdatedHandler FilterUpdated;
-
+
Dictionary<EventType, List<Tag>> eventsFilter;
List<Player> playersFilter;
+ List<Period> periodsFilter;
Project project;
-
+
public EventsFilter (Project project)
{
this.project = project;
- eventsFilter = new Dictionary<EventType, List<Tag>>();
- playersFilter = new List<Player>();
- ClearAll();
- UpdateFilters();
+ eventsFilter = new Dictionary<EventType, List<Tag>> ();
+ playersFilter = new List<Player> ();
+ periodsFilter = new List<Period> ();
+ ClearAll ();
+ UpdateFilters ();
}
-
+
public bool Silent {
set;
get;
@@ -51,123 +52,147 @@ namespace LongoMatch.Core.Common
get;
protected set;
}
-
+
public List<Player> VisiblePlayers {
get;
protected set;
}
-
+
public List<TimelineEvent> VisiblePlays {
get;
protected set;
}
-
- public void ClearEventTypesFilter (bool update=true) {
- eventsFilter.Clear();
+
+ public void ClearEventTypesFilter (bool update=true)
+ {
+ eventsFilter.Clear ();
if (update)
Update ();
}
-
- public void ClearPlayersFilter (bool update=true) {
- playersFilter.Clear();
+
+ public void ClearPlayersFilter (bool update=true)
+ {
+ playersFilter.Clear ();
if (update)
Update ();
}
- public void ClearAll (bool update=true) {
- ClearEventTypesFilter(false);
- ClearPlayersFilter(false);
+ public void ClearAll (bool update=true)
+ {
+ ClearEventTypesFilter (false);
+ ClearPlayersFilter (false);
if (update)
Update ();
}
-
- public void FilterPlayer (Player player, bool visible) {
+
+ public void FilterPlayer (Player player, bool visible)
+ {
if (visible) {
- if (!playersFilter.Contains(player))
- playersFilter.Add(player);
+ if (!playersFilter.Contains (player))
+ playersFilter.Add (player);
} else {
- if (playersFilter.Contains(player))
- playersFilter.Remove(player);
+ if (playersFilter.Contains (player))
+ playersFilter.Remove (player);
}
- Update();
+ Update ();
}
-
- public void FilterEventType (EventType evType, bool visible) {
+
+ public void FilterEventType (EventType evType, bool visible)
+ {
if (visible) {
if (!eventsFilter.ContainsKey (evType))
- eventsFilter[evType] = new List<Tag> ();
+ eventsFilter [evType] = new List<Tag> ();
} else {
if (eventsFilter.ContainsKey (evType))
eventsFilter.Remove (evType);
}
- Update();
+ Update ();
}
- public void FilterEventTag (EventType evType, Tag tag, bool visible) {
+ public void FilterPeriod (Period period, bool visible)
+ {
+ if (visible) {
+ if (!periodsFilter.Contains (period))
+ periodsFilter.Add (period);
+ } else {
+ if (periodsFilter.Contains (period))
+ periodsFilter.Remove (period);
+ }
+ Update ();
+ }
+
+ public void FilterEventTag (EventType evType, Tag tag, bool visible)
+ {
List<Tag> tags;
if (visible) {
FilterEventType (evType, true);
- tags = eventsFilter[evType];
+ tags = eventsFilter [evType];
if (!tags.Contains (tag))
tags.Add (tag);
} else {
- if (eventsFilter.ContainsKey(evType)) {
- tags = eventsFilter[evType];
+ if (eventsFilter.ContainsKey (evType)) {
+ tags = eventsFilter [evType];
if (tags.Contains (tag))
tags.Remove (tag);
}
}
- Update();
+ Update ();
}
-
- public bool IsVisible(object o) {
+
+ public bool IsVisible (object o)
+ {
if (o is Player) {
- return VisiblePlayers.Contains(o as Player);
+ return VisiblePlayers.Contains (o as Player);
} else if (o is TimelineEvent) {
return VisiblePlays.Contains (o as TimelineEvent);
}
return true;
}
-
- public void Update () {
- UpdateFilters();
- EmitFilterUpdated();
+
+ public void Update ()
+ {
+ UpdateFilters ();
+ EmitFilterUpdated ();
}
-
- void UpdateFilters () {
+
+ void UpdateFilters ()
+ {
UpdateVisiblePlayers ();
UpdateVisibleCategories ();
UpdateVisiblePlays ();
}
-
- void UpdateVisiblePlayers () {
+
+ void UpdateVisiblePlayers ()
+ {
if (playersFilter.Count == 0) {
- VisiblePlayers = project.LocalTeamTemplate.List.Concat
(project.VisitorTeamTemplate.List).ToList();
+ VisiblePlayers = project.LocalTeamTemplate.List.Concat
(project.VisitorTeamTemplate.List).ToList ();
} else {
- VisiblePlayers = playersFilter.ToList();
+ VisiblePlayers = playersFilter.ToList ();
}
}
-
- void UpdateVisibleCategories () {
+
+ void UpdateVisibleCategories ()
+ {
if (eventsFilter.Count == 0) {
VisibleEventTypes = project.EventTypes;
} else {
- VisibleEventTypes = eventsFilter.Keys.ToList();
+ VisibleEventTypes = eventsFilter.Keys.ToList ();
}
}
-
- void UpdateVisiblePlays () {
- bool cat_match=true, player_match=true;
- VisiblePlays = new List<TimelineEvent>();
+
+ void UpdateVisiblePlays ()
+ {
+ bool cat_match = true, player_match = true, period_match = true;
+ VisiblePlays = new List<TimelineEvent> ();
foreach (TimelineEvent play in project.Timeline) {
cat_match = false;
if (VisibleEventTypes.Contains (play.EventType)) {
cat_match = true;
if (eventsFilter.ContainsKey (play.EventType)) {
- List<Tag> tags = eventsFilter[play.EventType];
- if (tags.Count == 0 || tags.Intersect (play.Tags).Count() >
0) {
+ List<Tag> tags = eventsFilter [play.EventType];
+ if (tags.Count == 0 || tags.Intersect (play.Tags).Count () >
0) {
cat_match = true;
} else {
cat_match = false;
@@ -176,18 +201,29 @@ namespace LongoMatch.Core.Common
}
if (play.Players.Count == 0 && VisiblePlayers.Count ==
- project.LocalTeamTemplate.List.Count +
project.VisitorTeamTemplate.List.Count) {
+ project.LocalTeamTemplate.List.Count +
project.VisitorTeamTemplate.List.Count) {
player_match = true;
} else {
- player_match = VisiblePlayers.Intersect(play.Players).Count() != 0;
+ player_match = VisiblePlayers.Intersect (play.Players).Count () != 0;
+ }
+
+ if (periodsFilter.Count != 0) {
+ period_match = false;
+ }
+ foreach (Period p in periodsFilter) {
+ if (p.PeriodNode.Join (play) != null) {
+ period_match = true;
+ }
}
- if (player_match && cat_match) {
+
+ if (player_match && cat_match && period_match) {
VisiblePlays.Add (play);
}
}
}
-
- void EmitFilterUpdated () {
+
+ void EmitFilterUpdated ()
+ {
if (!Silent && FilterUpdated != null)
FilterUpdated ();
}
diff --git a/LongoMatch.Core/Store/TimeNode.cs b/LongoMatch.Core/Store/TimeNode.cs
index c288984..b75a7e1 100644
--- a/LongoMatch.Core/Store/TimeNode.cs
+++ b/LongoMatch.Core/Store/TimeNode.cs
@@ -110,6 +110,15 @@ namespace LongoMatch.Core.Store
set;
}
+ public TimeNode Join (TimeNode tn) {
+ if (tn.Stop < Start || tn.Start > Stop)
+ return null;
+ else
+ return new TimeNode {
+ Start = new Time (Math.Min (Start.MSeconds, tn.Start.MSeconds)),
+ Stop = new Time (Math.Max (Stop.MSeconds, tn.Stop.MSeconds))};
+ }
+
#endregion
}
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index f082611..385e160 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -157,7 +157,7 @@ namespace LongoMatch.Drawing.Widgets
int i = 0;
tl = new TimerTimeline (project.Periods.Select (p => p as Timer).ToList(),
- false, true, false, duration,
+ true, true, false, duration,
i * StyleConf.TimelineCategoryHeight,
Utils.ColorForRow (i), Config.Style.PaletteBackgroundDark);
AddTimeline (tl, null);
diff --git a/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
b/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
index 6996bab..3c95a50 100644
--- a/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/CategoriesFilterTreeView.cs
@@ -18,7 +18,6 @@
using System;
using Gtk;
using Mono.Unix;
-
using LongoMatch.Core.Common;
using LongoMatch.Core.Interfaces;
using LongoMatch.Core.Store;
@@ -26,56 +25,64 @@ using LongoMatch.Core.Store.Templates;
namespace LongoMatch.Gui.Component
{
-
- [System.ComponentModel.Category("LongoMatch")]
+ [System.ComponentModel.Category("LongoMatch")]
[System.ComponentModel.ToolboxItem(true)]
public class CategoriesFilterTreeView: FilterTreeViewBase
{
Project project;
-
+
public CategoriesFilterTreeView (): base()
{
- firstColumnName = Catalog.GetString("Category");
+ firstColumnName = Catalog.GetString ("Category");
HeadersVisible = false;
}
-
- public override void SetFilter (EventsFilter filter, Project project) {
+
+ public override void SetFilter (EventsFilter filter, Project project)
+ {
this.project = project;
- base.SetFilter(filter, project);
+ base.SetFilter (filter, project);
}
-
+
protected override void FillTree ()
{
+ TreeIter catIter;
store = new TreeStore (typeof(object), typeof(bool));
+ /* Periods */
+ catIter = store.AppendValues (new StringObject (Catalog.GetString ("Periods")),
false);
+ foreach (Period p in project.Periods) {
+ store.AppendValues (catIter, p, false);
+ }
+
foreach (EventType evType in project.EventTypes) {
- TreeIter catIter;
-
catIter = store.AppendValues (evType, true);
filter.FilterEventType (evType, true);
if (evType is AnalysisEventType) {
foreach (Tag tag in (evType as AnalysisEventType).Tags) {
- store.AppendValues(catIter, tag, false);
+ store.AppendValues (catIter, tag, false);
}
}
}
Model = store;
}
-
- void UpdateSelectionPriv(TreeIter iter, bool active, bool checkParents=true, bool
recurse=true) {
+
+ void UpdateSelectionPriv (TreeIter iter, bool active, bool checkParents=true, bool
recurse=true)
+ {
TreeIter child, parent;
- object o = store.GetValue(iter, 0);
+ object o = store.GetValue (iter, 0);
store.IterParent (out parent, iter);
if (o is Tag) {
EventType evType = store.GetValue (parent, 0) as EventType;
filter.FilterEventTag (evType, o as Tag, active);
- } else {
+ } else if (o is EventType) {
filter.FilterEventType (o as EventType, active);
+ } else if (o is Period) {
+ filter.FilterPeriod (o as Period, active);
}
- store.SetValue(iter, 1, active);
+ store.SetValue (iter, 1, active);
/* Check its parents */
if (active && checkParents && store.IterIsValid (parent)) {
@@ -84,54 +91,72 @@ namespace LongoMatch.Gui.Component
/* Check/Uncheck all children */
if (recurse) {
- store.IterChildren(out child, iter);
+ store.IterChildren (out child, iter);
while (store.IterIsValid(child)) {
UpdateSelectionPriv (child, active, false, true);
- store.IterNext(ref child);
+ store.IterNext (ref child);
}
}
if (recurse && checkParents)
- filter.Update();
+ filter.Update ();
}
-
- protected override void UpdateSelection(TreeIter iter, bool active) {
+
+ protected override void UpdateSelection (TreeIter iter, bool active)
+ {
UpdateSelectionPriv (iter, active, true, true);
}
-
+
protected override void RenderColumn (TreeViewColumn column, CellRenderer cell, TreeModel
model, TreeIter iter)
{
- object obj = store.GetValue(iter, 0);
+ object obj = store.GetValue (iter, 0);
string text = "";
if (obj is EventType) {
EventType evType = obj as EventType;
text = evType.Name;
- }
- else if (obj is Tag){
+ } else if (obj is Tag) {
text = (obj as Tag).Value;
+ } else if (obj is Period) {
+ text = (obj as Period).Name;
+ } else if (obj is StringObject) {
+ text = (obj as StringObject).Text;
}
(cell as CellRendererText).Text = text;
}
-
- protected override void Select(bool select_all) {
+
+ protected override void Select (bool select_all)
+ {
TreeIter iter;
filter.Silent = true;
- store.GetIterFirst(out iter);
- while (store.IterIsValid(iter)){
- UpdateSelection(iter, select_all);
- store.IterNext(ref iter);
+ store.GetIterFirst (out iter);
+ while (store.IterIsValid(iter)) {
+ UpdateSelection (iter, select_all);
+ store.IterNext (ref iter);
}
filter.Silent = false;
filter.Update ();
}
-
+
protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
{
return false;
}
+
+ class StringObject
+ {
+ public StringObject (string text)
+ {
+ Text = text;
+ }
+
+ public string Text {
+ get;
+ set;
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]