From b078633eb04954d5f7f601b0d4be4858ef61d9d7 Mon Sep 17 00:00:00 2001 From: deveee Date: Wed, 4 Sep 2013 16:43:52 +0000 Subject: [PATCH] Fixed problem with switching between name and date column. Now everything should work properly. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@13629 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/widgets/list_widget.cpp | 28 +++++++++++++++------------ src/guiengine/widgets/list_widget.hpp | 3 +++ src/states_screens/addons_screen.cpp | 24 +++++++++++------------ src/states_screens/addons_screen.hpp | 2 ++ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/guiengine/widgets/list_widget.cpp b/src/guiengine/widgets/list_widget.cpp index 31e73901c..df0acff87 100644 --- a/src/guiengine/widgets/list_widget.cpp +++ b/src/guiengine/widgets/list_widget.cpp @@ -300,8 +300,8 @@ void ListWidget::elementRemoved() } m_header_elements.clearAndDeleteAll(); m_selected_column = NULL; - m_sort_desc = 1; - m_sort_default = 1; + m_sort_desc = true; + m_sort_default = true; } // ----------------------------------------------------------------------------- @@ -371,18 +371,22 @@ EventPropagation ListWidget::transmitEvent(Widget* w, if (originator.find(m_properties[PROP_ID] + "_column_") != std::string::npos) { - int col = originator[ (m_properties[PROP_ID] + "_column_").size() ] - '0'; - - m_selected_column = m_header_elements.get(col); - - /** \brief Allows sort icon to change depending on sort order **/ - if (m_sort_desc && !m_sort_default) - m_sort_default = true; - else + if (m_sort_col != originator[(m_properties[PROP_ID] + "_column_").size()] - '0') { - m_sort_desc = !m_sort_desc; + m_sort_desc = false; m_sort_default = false; } + else + { + m_sort_default = m_sort_desc && !m_sort_default; + if (!m_sort_default) m_sort_desc = !m_sort_desc; + } + + m_sort_col = originator[(m_properties[PROP_ID] + "_column_").size()] - '0'; + m_selected_column = m_header_elements.get(m_sort_col); + + /** \brief Allows sort icon to change depending on sort order **/ + /* for (int n=0; n()->setPressed(true); */ - if (m_listener) m_listener->onColumnClicked(col); + if (m_listener) m_listener->onColumnClicked(m_sort_col); return EVENT_BLOCK; } diff --git a/src/guiengine/widgets/list_widget.hpp b/src/guiengine/widgets/list_widget.hpp index f61a0f868..778e5578f 100644 --- a/src/guiengine/widgets/list_widget.hpp +++ b/src/guiengine/widgets/list_widget.hpp @@ -73,6 +73,9 @@ namespace GUIEngine /** true when deault sorting is enabled */ bool m_sort_default; + /** index of column*/ + int m_sort_col; + struct Column { irr::core::stringw m_text; diff --git a/src/states_screens/addons_screen.cpp b/src/states_screens/addons_screen.cpp index 3a945ca6b..56e18e85f 100644 --- a/src/states_screens/addons_screen.cpp +++ b/src/states_screens/addons_screen.cpp @@ -138,6 +138,7 @@ void AddonsScreen::init() m_sort_desc = true; m_sort_default = true; + m_sort_col = 0; getWidget("category")->setDeactivated(); @@ -381,27 +382,26 @@ void AddonsScreen::loadList() // ---------------------------------------------------------------------------- void AddonsScreen::onColumnClicked(int column_id) { - if (m_sort_desc && !m_sort_default) - m_sort_default = true; - else + if (m_sort_col != column_id) { - m_sort_desc = !m_sort_desc; + m_sort_desc = false; m_sort_default = false; } + else + { + m_sort_default = m_sort_desc && !m_sort_default; + if (!m_sort_default) m_sort_desc = !m_sort_desc; + } + + m_sort_col = column_id; switch(column_id) { case 0: - if (!m_sort_default) - Addon::setSortOrder(Addon::SO_NAME); - else - Addon::setSortOrder(Addon::SO_DEFAULT); + Addon::setSortOrder(m_sort_default ? Addon::SO_DEFAULT : Addon::SO_NAME); break; case 1: - if (!m_sort_default) - Addon::setSortOrder(Addon::SO_DATE); - else - Addon::setSortOrder(Addon::SO_DEFAULT); + Addon::setSortOrder(m_sort_default ? Addon::SO_DEFAULT : Addon::SO_DATE); break; default: assert(0); } // switch diff --git a/src/states_screens/addons_screen.hpp b/src/states_screens/addons_screen.hpp index e397d970a..a454545b2 100644 --- a/src/states_screens/addons_screen.hpp +++ b/src/states_screens/addons_screen.hpp @@ -78,6 +78,8 @@ private: bool m_sort_desc; bool m_sort_default; + + int m_sort_col; /** List of date filters **/ std::vector m_date_filters;