Abdelrazak Younes wrote:
Abdelrazak Younes wrote:
> Abdelrazak Younes wrote:
>> Pavel Sanda wrote:
>>>>>> Author: younes Date: Thu May 8 11:31:00 2008 New
>>>>>> Revision: 24681
>>>>>>
>>>>>> URL: http://www.lyx.org/trac/changeset/24681 Log: sort
>>>>>> the languages.
>>>>>>
>>>>>
>>>>>
>>>>>> + language_model_->sort(0);
>>>>>>
>>>>> i didnt followed exactly these patches about languages;
>>>>> where in gui can i find the result?
>>>> In the preference and document dialogs. Not yet in the
>>>> character dialog.
>>>>
>>>>> we should keep locale-sensitive sorting for the languages
>>>>> in ui (see http://bugzilla.lyx.org/show_bug.cgi?id=2738 ).
>>>>>
>>>> It should work fine. Please test.
>>>
>>> no, its broken. for correct locale sorting one has to use
>>> std::locale, http://www.lyx.org/trac/changeset/21598
>>
>> Is it really broken or is it something you can live with? AFAIU
>> QStandardItemModel::sort() will sort the strings alphabetically
>> and the strings are already translated when this is called so it
>> cannot be that bad, can it? Do you have a use case where this
>> does not work correctly? If yes, then we'll have to do the
>> sorting at Languages level, just after the information is read.
>> The method used in r21598 can be reused.
>
> AFAIU the method used in r21598 won't work for all platforms. It
> seems that Qt provides some facility for this with
> QString::localeAwareCompare(); but I fail to see how I can use that
> in conjonction with QStandardItemModel::sort(). Well I guess I
> could if I read a bit more deeply the Qt docs but, André, if you
> have an idea here it would be very welcome.
I read a bit docu nevertheless... it seems that using
QSortFilterProxyModel instead of QStandardItemModel could do the job.
QSortFilterProxyModel is local aware ( see setSortLocaleAware()). So,
with a bit of work, we can make this happen. The advantage of going
that way is that we could then reuse the method for other list in our
dialogs.
FYI I did that:
Author: younes
Date: Wed May 14 12:34:19 2008
New Revision: 24758
URL: http://www.lyx.org/trac/changeset/24758
Log:
Hopefully fix locale aware language sorting in document and prefs dialogs.
Modified:
lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp
lyx-devel/trunk/src/frontends/qt4/GuiApplication.h
lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp
lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp
Modified: lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp?rev=24758
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp (original)
+++ lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp Wed May 14 12:34:19
2008
@@ -57,6 +57,7 @@
#include <QRegExp>
#include <QSessionManager>
#include <QSocketNotifier>
+#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QTextCodec>
#include <QTimer>
@@ -156,7 +157,8 @@
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()
-{}
-
-
FuncStatus GuiApplication::getStatus(FuncRequest const & cmd)
{
FuncStatus flag;
@@ -457,20 +455,29 @@
void GuiApplication::execBatchCommands()
{
LyX::ref().execBatchCommands();
-
- language_model_ = new QStandardItemModel(this);
- language_model_->insertColumns(0, 1);
+}
+
+QAbstractItemModel * GuiApplication::languageModel()
+{
+ if (language_model_)
+ return language_model_;
+
+ 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);
- }
- language_model_->sort(0);
+ 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_ = new QSortFilterProxyModel(this);
+ language_model_->setSourceModel(lang_model);
+ language_model_->setSortLocaleAware(true);
+ return language_model_;
}
Modified: lyx-devel/trunk/src/frontends/qt4/GuiApplication.h
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/qt4/GuiApplication.h?rev=24758
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiApplication.h (original)
+++ lyx-devel/trunk/src/frontends/qt4/GuiApplication.h Wed May 14 12:34:19 2008
@@ -30,7 +30,7 @@
#include <vector>
class QSessionManager;
-class QStandardItemModel;
+class QAbstractItemModel;
namespace lyx {
@@ -55,8 +55,6 @@
public:
GuiApplication(int & argc, char ** argv);
- ///
- virtual ~GuiApplication();
/// Method inherited from \c Application class
//@{
@@ -106,7 +104,7 @@
///
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 @@
///
ColorCache color_cache_;
///
- QStandardItemModel * language_model_;
+ QSortFilterProxyModel * language_model_;
///
QTranslator qt_trans_;
///
Modified: lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp?rev=24758
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp (original)
+++ lyx-devel/trunk/src/frontends/qt4/GuiDocument.cpp Wed May 14 12:34:19 2008
@@ -50,9 +50,9 @@
#include "frontends/alert.h"
+#include <QAbstractItemModel>
#include <QCloseEvent>
#include <QScrollBar>
-#include <QStandardItemModel>
#include <QTextCursor>
#include <sstream>
@@ -788,7 +788,10 @@
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.
Modified: lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp?rev=24758
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp (original)
+++ lyx-devel/trunk/src/frontends/qt4/GuiPrefs.cpp Wed May 14 12:34:19 2008
@@ -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 @@
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);
}