Hopefully fix locale aware language sorting in document and prefs dialogs.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24758 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-05-14 10:34:19 +00:00
parent aa7d21d98b
commit 09a3be216e
4 changed files with 33 additions and 22 deletions

View 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();
}
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);
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_;
}

View 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_;
///

View 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.

View 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);
}