Introduce GuiApplication::languageModel() and use it in GuiPrefs.cpp

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24679 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-05-08 09:03:38 +00:00
parent f8ab97698c
commit 207470d385
3 changed files with 26 additions and 19 deletions

View File

@ -30,6 +30,7 @@
#include "Font.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Language.h"
#include "LyX.h"
#include "LyXFunc.h"
#include "LyXRC.h"
@ -46,7 +47,6 @@
#include "support/os.h"
#include "support/Package.h"
#include <QApplication>
#include <QClipboard>
#include <QEventLoop>
#include <QFileOpenEvent>
@ -57,6 +57,7 @@
#include <QRegExp>
#include <QSessionManager>
#include <QSocketNotifier>
#include <QStandardItemModel>
#include <QTextCodec>
#include <QTimer>
#include <QTranslator>
@ -237,6 +238,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
connect(&general_timer_, SIGNAL(timeout()),
this, SLOT(handleRegularEvents()));
general_timer_.start();
#ifdef Q_WS_MACX
if (global_menubar_ == 0) {
@ -244,7 +246,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
// and if no GuiView is visible.
global_menubar_ = new GlobalMenuBar();
}
#endif
#endif
}
@ -457,6 +459,19 @@ void GuiApplication::exit(int status)
void GuiApplication::execBatchCommands()
{
LyX::ref().execBatchCommands();
language_model_ = new QStandardItemModel(this);
language_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);
}
}

View File

@ -29,6 +29,7 @@
#include <map>
#include <vector>
class QAbstractItemModel;
class QSessionManager;
namespace lyx {
@ -105,6 +106,8 @@ public:
///
ColorCache & colorCache() { return color_cache_; }
QStandardItemModel * languageModel() { return language_model_; }
/// return a suitable serif font name.
virtual QString const romanFontName();
@ -144,6 +147,8 @@ private:
///
ColorCache color_cache_;
///
QStandardItemModel * language_model_;
///
QTranslator qt_trans_;
///
std::map<int, SocketNotifier *> socket_notifiers_;

View File

@ -218,15 +218,6 @@ string const catLanguage = N_("Language Settings");
string const catOutput = N_("Output");
string const catFiles = N_("File Handling");
static int findPos_helper(QStringList const & vec, QString const & val)
{
for (int i = 0; i != vec.size(); ++i)
if (vec[i] == val)
return i;
return 0;
}
static void parseFontName(QString const & mangled0,
string & name, string & foundry)
{
@ -1659,12 +1650,7 @@ PrefLanguage::PrefLanguage(QWidget * parent)
defaultLanguageCO->clear();
Languages::const_iterator lit = languages.begin();
Languages::const_iterator lend = languages.end();
for (; lit != lend; ++lit) {
lang_.append(toqstr(lit->second.lang()));
defaultLanguageCO->addItem(qt_(lit->second.display()));
}
defaultLanguageCO->setModel(guiApp->languageModel());
}
@ -1681,7 +1667,8 @@ void PrefLanguage::apply(LyXRC & rc) const
rc.language_package = fromqstr(languagePackageED->text());
rc.language_command_begin = fromqstr(startCommandED->text());
rc.language_command_end = fromqstr(endCommandED->text());
rc.default_language = fromqstr(lang_[defaultLanguageCO->currentIndex()]);
rc.default_language = fromqstr(
defaultLanguageCO->itemData(defaultLanguageCO->currentIndex()).toString());
}
@ -1702,7 +1689,7 @@ void PrefLanguage::update(LyXRC const & rc)
startCommandED->setText(toqstr(rc.language_command_begin));
endCommandED->setText(toqstr(rc.language_command_end));
int const pos = findPos_helper(lang_, toqstr(rc.default_language));
int const pos = defaultLanguageCO->findData(toqstr(rc.default_language));
defaultLanguageCO->setCurrentIndex(pos);
}