]> git.lyx.org Git - lyx.git/commitdiff
Hopefully fix locale aware language sorting in document and prefs dialogs.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 14 May 2008 10:34:19 +0000 (10:34 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 14 May 2008 10:34:19 +0000 (10:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24758 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiPrefs.cpp

index 7db6066d163902c004024fd05a264830b09b2844..8aba46e82e1a360fa525cd1cd1a34d19f2565578 100644 (file)
@@ -57,6 +57,7 @@
 #include <QRegExp>
 #include <QSessionManager>
 #include <QSocketNotifier>
+#include <QSortFilterProxyModel>
 #include <QStandardItemModel>
 #include <QTextCodec>
 #include <QTimer>
@@ -156,7 +157,8 @@ GuiApplication * guiApp;
 
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
-       : QApplication(argc, argv), Application(), current_view_(0), global_menubar_(0)
+       : QApplication(argc, argv), Application(), current_view_(0),
+       global_menubar_(0), language_model_(0)
 {
        QString app_name = "LyX";
        QCoreApplication::setOrganizationName(app_name);
@@ -250,10 +252,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
 }
 
 
-GuiApplication::~GuiApplication()
-{}
-
-
 FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
 {
        FuncStatus flag;
@@ -457,20 +455,29 @@ void GuiApplication::exit(int status)
 void GuiApplication::execBatchCommands()
 {
        LyX::ref().execBatchCommands();
+}
+
+QAbstractItemModel * GuiApplication::languageModel()
+{
+       if (language_model_)
+               return language_model_;
 
-       language_model_ = new QStandardItemModel(this);
-       language_model_->insertColumns(0, 1);
+       QStandardItemModel * lang_model = new QStandardItemModel(this);
+       lang_model->insertColumns(0, 1);
        int current_row;
        Languages::const_iterator it = languages.begin();
        Languages::const_iterator end = languages.end();
        for (; it != end; ++it) {
-               current_row = language_model_->rowCount();
-               language_model_->insertRows(current_row, 1);
-               QModelIndex item = language_model_->index(current_row, 0);
-               language_model_->setData(item, qt_(it->second.display()), Qt::DisplayRole);
-               language_model_->setData(item, toqstr(it->second.lang()), Qt::UserRole);
+               current_row = lang_model->rowCount();
+               lang_model->insertRows(current_row, 1);
+               QModelIndex item = lang_model->index(current_row, 0);
+               lang_model->setData(item, qt_(it->second.display()), Qt::DisplayRole);
+               lang_model->setData(item, toqstr(it->second.lang()), Qt::UserRole);
        }
-       language_model_->sort(0);
+       language_model_ = new QSortFilterProxyModel(this);
+    language_model_->setSourceModel(lang_model);
+       language_model_->setSortLocaleAware(true);
+       return language_model_;
 }
 
 
index a39724a6a0d2c40c0d4c95f1ed7b8ba9991e6030..bd2c8c164db88d98b2bcf489a3dccd33a81ba42a 100644 (file)
@@ -30,7 +30,7 @@
 #include <vector>
 
 class QSessionManager;
-class QStandardItemModel;
+class QAbstractItemModel;
 
 namespace lyx {
 
@@ -55,8 +55,6 @@ class GuiApplication : public QApplication, public Application
 
 public:
        GuiApplication(int & argc, char ** argv);
-       ///
-       virtual ~GuiApplication();
 
        /// Method inherited from \c Application class
        //@{
@@ -106,7 +104,7 @@ public:
        ///
        ColorCache & colorCache() { return color_cache_; }
 
-       QStandardItemModel * languageModel() { return language_model_; }
+       QAbstractItemModel * languageModel();
 
        /// return a suitable serif font name.
        virtual QString const romanFontName();
@@ -147,7 +145,7 @@ private:
        ///
        ColorCache color_cache_;
        ///
-       QStandardItemModel * language_model_;
+       QSortFilterProxyModel * language_model_;
        ///
        QTranslator qt_trans_;
        ///
index 5382c32f8d664327c7a21024119de2caf024283e..a36e8226f0c57dd5a0804283ae7fc10a1ee95b86 100644 (file)
@@ -50,9 +50,9 @@
 
 #include "frontends/alert.h"
 
+#include <QAbstractItemModel>
 #include <QCloseEvent>
 #include <QScrollBar>
-#include <QStandardItemModel>
 #include <QTextCursor>
 
 #include <sstream>
@@ -788,7 +788,10 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
        // language & quotes
-       langModule->languageCO->setModel(guiApp->languageModel());
+       QAbstractItemModel * language_model = guiApp->languageModel();
+       // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
+       language_model->sort(0);
+       langModule->languageCO->setModel(language_model);
 
        // Always put the default encoding in the first position.
        // It is special because the displayed text is translated.
index 40e080ca8289978a1c3b070bef033b67bfd81e3e..9fde251ca87efa2ea9dfec3cb721104bdbb55e3a 100644 (file)
@@ -46,6 +46,7 @@
 #include "frontends/alert.h"
 #include "frontends/Application.h"
 
+#include <QAbstractItemModel>
 #include <QCheckBox>
 #include <QColorDialog>
 #include <QFontDatabase>
@@ -54,7 +55,6 @@
 #include <QPixmapCache>
 #include <QPushButton>
 #include <QSpinBox>
-#include <QStandardItemModel>
 #include <QString>
 #include <QTreeWidget>
 #include <QTreeWidgetItem>
@@ -1651,7 +1651,10 @@ PrefLanguage::PrefLanguage(QWidget * parent)
 
        defaultLanguageCO->clear();
 
-       defaultLanguageCO->setModel(guiApp->languageModel());
+       QAbstractItemModel * language_model = guiApp->languageModel();
+       // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
+       language_model->sort(0);
+       defaultLanguageCO->setModel(language_model);
 }