From 9a36ffd1e3f55660eb22690e126f97faae2b0ccb Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 9 Aug 2017 16:09:50 +0200 Subject: [PATCH] Sort external templates locale-aware Fixes: #10738 --- src/frontends/qt4/GuiExternal.cpp | 12 +++++++++--- src/frontends/qt4/qt_helpers.cpp | 6 ++++++ src/frontends/qt4/qt_helpers.h | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index 07eb8fce2d..f994aafaef 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -202,10 +202,16 @@ GuiExternal::GuiExternal(GuiView & lv) external::TemplateManager::Templates::const_iterator i1, i2; i1 = external::TemplateManager::get().getTemplates().begin(); i2 = external::TemplateManager::get().getTemplates().end(); + QMap localizedTemplates; for (; i1 != i2; ++i1) - externalCO->addItem(qt_(i1->second.guiName), toqstr(i1->second.lyxName)); - // Sort alphabetically by(localized) GUI name - externalCO->model()->sort(0); + localizedTemplates.insert(qt_(i1->second.guiName), toqstr(i1->second.lyxName)); + // Sort alphabetically by (localized) GUI name + QStringList keys = localizedTemplates.keys(); + qSort(keys.begin(), keys.end(), SortLocaleAware); + for (QString & key : keys) { + QString const value = localizedTemplates[key]; + externalCO->addItem(key, value); + } // Fill the origins combo for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i) diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 63125d8c5c..d228510119 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -214,6 +214,12 @@ QString formatLocFPNumber(double d) } +bool SortLocaleAware(QString const & lhs, QString const & rhs) +{ + return QString::localeAwareCompare(lhs, rhs) < 0; +} + + bool ColorSorter(ColorCode lhs, ColorCode rhs) { return compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) < 0; diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 023e86afcf..52057fc494 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -76,6 +76,9 @@ void doubleToWidget(QLineEdit * input, std::string const & value, */ QString formatLocFPNumber(double d); +/// Method to sort QStrings locale-aware (e.g. in combo widgets) +bool SortLocaleAware(QString const & lhs, QString const & rhs); + /// Method to sort colors by GUI name in combo widgets bool ColorSorter(ColorCode lhs, ColorCode rhs); -- 2.39.2