[chronojump] DB: 2.1. Inserted into preferences: SessionLoadDisplay, and management of 3 booleans - 1 int



commit 689bc72cf054af95a62c5bea7428b391b4486ff3
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Mar 18 15:49:14 2021 +0100

    DB: 2.1. Inserted into preferences: SessionLoadDisplay, and management of 3 booleans - 1 int

 src/gui/app1/session/loadAndImport.cs | 143 ++++++++++++++++++++++++++++++++--
 src/gui/chronojumpImporter.cs         |   3 +
 src/preferences.cs                    |   2 +-
 src/sqlite/main.cs                    |  11 ++-
 src/sqlite/preferences.cs             |   4 +
 5 files changed, 155 insertions(+), 8 deletions(-)
---
diff --git a/src/gui/app1/session/loadAndImport.cs b/src/gui/app1/session/loadAndImport.cs
index 6510ddab..d550644c 100644
--- a/src/gui/app1/session/loadAndImport.cs
+++ b/src/gui/app1/session/loadAndImport.cs
@@ -71,6 +71,7 @@ public partial class ChronoJumpWindow
         */
 
        private app1s_windowType app1s_type;
+       private bool sessionLoadWinSignals; //to be able to set radiobuttons at first without recreating the 
treeview
 
        private void app1s_initializeGui()
        {
@@ -116,10 +117,29 @@ public partial class ChronoJumpWindow
                app1s_entry_search_filter.Text = "";
                app1s_button_manage_tags.Sensitive = (app1s_selected != "-1");
 
-               app1s_createTreeView(app1s_treeview_session_load, app1s_type == 
app1s_windowType.LOAD_SESSION, false, false, false);
-               app1s_store = app1s_getStore(true, false, false, false);
+               //radio buttons
+               sessionLoadWinSignals = false;
+               app1s_checkbutton_show_data_persons.Active = preferences.sessionLoadDisplay.ShowAthletesInfo;
+               app1s_checkbutton_show_data_jump_run.Active = preferences.sessionLoadDisplay.ShowJumpsRaces;
+               app1s_checkbutton_show_data_other_tests.Active = 
preferences.sessionLoadDisplay.ShowOtherTests;
+               sessionLoadWinSignals = true;
+
+               app1s_createTreeView(app1s_treeview_session_load, app1s_type == app1s_windowType.LOAD_SESSION,
+                               app1s_checkbutton_show_data_persons.Active,
+                               app1s_checkbutton_show_data_jump_run.Active,
+                               app1s_checkbutton_show_data_other_tests.Active);
+
+               app1s_store = app1s_getStore(true,
+                               app1s_checkbutton_show_data_persons.Active,
+                               app1s_checkbutton_show_data_jump_run.Active,
+                               app1s_checkbutton_show_data_other_tests.Active);
+
                app1s_treeview_session_load.Model = app1s_store;
-               app1s_fillTreeView(app1s_treeview_session_load, app1s_store, false, false, false);
+
+               app1s_fillTreeView(app1s_treeview_session_load, app1s_store,
+                               app1s_checkbutton_show_data_persons.Active,
+                               app1s_checkbutton_show_data_jump_run.Active,
+                               app1s_checkbutton_show_data_other_tests.Active);
 
                app1s_store.SetSortColumnId(1, Gtk.SortType.Descending); //date
                app1s_store.ChangeSortColumn();
@@ -298,15 +318,51 @@ public partial class ChronoJumpWindow
                app1s_recreateTreeView ("file path changed");
        }
 
-       void app1s_on_checkbutton_show_data_persons_toggled (object o, EventArgs args) {
+       void app1s_on_checkbutton_show_data_persons_toggled (object o, EventArgs args)
+       {
+               if(! sessionLoadWinSignals)
+                       return;
+
+               //on import this call will be done t end to affect to our desired database
+               if (app1s_type == app1s_windowType.LOAD_SESSION)
+                       sqlChangeSessionLoadDisplay();
+
                app1s_recreateTreeView("persons " + app1s_checkbutton_show_data_persons.Active.ToString());
        }
-       void app1s_on_checkbutton_show_data_jump_run_toggled (object o, EventArgs args) {
+       void app1s_on_checkbutton_show_data_jump_run_toggled (object o, EventArgs args)
+       {
+               if(! sessionLoadWinSignals)
+                       return;
+
+               //on import this call will be done t end to affect to our desired database
+               if (app1s_type == app1s_windowType.LOAD_SESSION)
+                       sqlChangeSessionLoadDisplay();
+
                app1s_recreateTreeView("jump run " + app1s_checkbutton_show_data_jump_run.Active.ToString());
        }
-       void app1s_on_checkbutton_show_data_other_tests_toggled (object o, EventArgs args) {
+       void app1s_on_checkbutton_show_data_other_tests_toggled (object o, EventArgs args)
+       {
+               if(! sessionLoadWinSignals)
+                       return;
+
+               //on import this call will be done t end to affect to our desired database
+               if (app1s_type == app1s_windowType.LOAD_SESSION)
+                       sqlChangeSessionLoadDisplay();
+
                app1s_recreateTreeView("other tests " + 
app1s_checkbutton_show_data_other_tests.Active.ToString());
        }
+
+       private void sqlChangeSessionLoadDisplay ()
+       {
+               preferences.sessionLoadDisplay = new SessionLoadDisplay(
+                               app1s_checkbutton_show_data_persons.Active,
+                               app1s_checkbutton_show_data_jump_run.Active,
+                               app1s_checkbutton_show_data_other_tests.Active);
+
+               SqlitePreferences.Update (SqlitePreferences.SessionLoadDisplay,
+                               preferences.sessionLoadDisplay.Selection.ToString(), false);
+       }
+
        void app1s_recreateTreeView(string message)
        {
                LogB.Information("Recreate treeview: " + message);
@@ -757,3 +813,78 @@ public partial class ChronoJumpWindow
                get { return app1s_button_load; }
        }
 }
+
+/*
+   manage if show athletes info, jumps/races or other tests
+1: athletes
+2: jumps/races
+4: other tests
+
+eg 6 will be jumps and races
+tested with:
+for(int i = 0; i <= 7; i++)
+       LogB.Information(new SessionLoadDisplay(i).ToString());
+*/
+public class SessionLoadDisplay
+{
+       private int selection;
+
+       //constructor when we have the 0-7 value
+       public SessionLoadDisplay(int selection)
+       {
+               this.selection = selection;
+       }
+
+       //constructo with the 3 booleans
+       public SessionLoadDisplay(bool showBit1, bool showBit2, bool showBit3)
+       {
+               this.selection = 0;
+               if(showBit1)
+                       selection ++;
+               if(showBit2)
+                       selection += 2;
+               if(showBit3)
+                       selection += 4;
+       }
+
+       public bool ShowOtherTests
+       {
+               get { return (selection >= 4); }
+       }
+
+       public bool ShowJumpsRaces
+       {
+               get {
+                       int temp = selection;
+                       if(temp >= 4)
+                               temp -= 4;
+
+                       return (temp >= 2);
+               }
+       }
+
+       public bool ShowAthletesInfo
+       {
+               get {
+                       int temp = selection;
+                       if(temp >= 4)
+                               temp -= 4;
+                       if(temp >= 2)
+                               temp -= 2;
+
+                       return (temp == 1);
+               }
+       }
+
+       public int Selection
+       {
+               get { return selection; }
+       }
+
+       //just to debug
+       public override string ToString()
+       {
+               return string.Format("selected: {0} (AthletesInfo: {1}, JumpsRaces: {2}, Other: {3})",
+                               selection, ShowAthletesInfo, ShowJumpsRaces, ShowOtherTests);
+       }
+}
diff --git a/src/gui/chronojumpImporter.cs b/src/gui/chronojumpImporter.cs
index 9ac5cfc0..3bf5af55 100644
--- a/src/gui/chronojumpImporter.cs
+++ b/src/gui/chronojumpImporter.cs
@@ -112,6 +112,9 @@ public partial class ChronoJumpWindow
                        //to not allow to load a session or create a new session until close session/more
                        menus_sensitive_import_not_danger(false);
 
+                       //change here SQL because radios changed before done on importing session
+                       sqlChangeSessionLoadDisplay();
+
                        LogB.ThreadEnded();
                        return false;
                }
diff --git a/src/preferences.cs b/src/preferences.cs
index a8187549..dcd2644e 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -53,7 +53,7 @@ public class Preferences
        public int lastSessionID;
        public bool loadLastModeAtStart;
        public Constants.Menuitem_modes lastMode;
-
+       public SessionLoadDisplay sessionLoadDisplay;
 
        public enum UnitsEnum { METRIC, IMPERIAL };
        public UnitsEnum units;
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 80a13da2..8ca30c86 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -129,7 +129,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "2.14";
+       static string lastChronojumpDatabaseVersion = "2.15";
 
        public Sqlite()
        {
@@ -2903,6 +2903,14 @@ class Sqlite
 
                                currentVersion = updateVersion("2.14");
                        }
+                       if(currentVersion == "2.14")
+                       {
+                               LogB.SQL("Inserted into preferences: SessionLoadDisplay");
+
+                               SqlitePreferences.Insert (SqlitePreferences. SessionLoadDisplay, "0");
+
+                               currentVersion = updateVersion("2.15");
+                       }
 
 
 
@@ -3124,6 +3132,7 @@ class Sqlite
 //just testing: 1.79 - 1.80 Converted DB to 1.80 Created table ForceSensorElasticBandGlue and moved 
stiffnessString records there
 
 
+               //2.14 - 2.15 Converted DB to 2.15 Inserted into preferences: SessionLoadDisplay
                //2.13 - 2.14 Converted DB to 2.14 Doing alter table run, runInterval, tempRunInterval add 
datetime
                //2.12 - 2.13 Converted DB to 2.13 Inserted prefs: PersonSelectWinImages, ExportGraphWidth, 
ExportGraphHeight
                //2.11 - 2.12 Converted DB to 2.12 Inserted prefs: forceSensorAnalyzeMaxAVGInWindow
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index caab9b6a..0a7496db 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -119,6 +119,7 @@ class SqlitePreferences : Sqlite
        public const string LastSessionID = "lastSessionID";
        public const string LoadLastModeAtStart = "loadLastModeAtStart";
        public const string LastMode = "lastMode";
+       public const string SessionLoadDisplay = "sessionLoadDisplay";
 
        //export
        public const string ExportGraphWidth = "exportGraphWidth";
@@ -339,6 +340,7 @@ class SqlitePreferences : Sqlite
                                Insert (LastSessionID, "-1", dbcmdTr);
                                Insert (LoadLastModeAtStart, "True", dbcmdTr);
                                Insert (LastMode, Constants.Menuitem_modes.UNDEFINED.ToString(), dbcmdTr);
+                               Insert (SessionLoadDisplay, "0", dbcmdTr);
 
                                //export
                                Insert (ExportGraphWidth, "900", dbcmdTr);
@@ -781,6 +783,8 @@ class SqlitePreferences : Sqlite
                        else if(reader[0].ToString() == LastMode)
                                preferences.lastMode = (Constants.Menuitem_modes)
                                        Enum.Parse(typeof(Constants.Menuitem_modes), reader[1].ToString());
+                       else if(reader[0].ToString() == SessionLoadDisplay)
+                               preferences.sessionLoadDisplay = new 
SessionLoadDisplay(Convert.ToInt32(reader[1].ToString()));
 
                        //export
                        else if(reader[0].ToString() == ExportGraphWidth)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]