move the string conversion functions out-of-line to minimize #includes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24396 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-04-20 20:32:00 +00:00
parent aff97fe9b5
commit 1e4f4fcd91
9 changed files with 141 additions and 49 deletions

View File

@ -80,9 +80,10 @@ void FileDialog::setButton2(QString const & label, QString const & dir)
FileDialog::Result FileDialog::save(QString const & path,
QStringList const & filters, QString const & suggested)
{
LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", mask \"" << fromqstr(filters.join(";;"))
<< "\", suggested \"" << fromqstr(suggested) << '"');
LYXERR(Debug::GUI, "Select with path \"" << path
<< "\", mask \"" << filters.join(";;")
<< "\", suggested \"" << suggested << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
@ -117,9 +118,9 @@ FileDialog::Result FileDialog::save(QString const & path,
FileDialog::Result FileDialog::open(QString const & path,
QStringList const & filters, QString const & suggested)
{
LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", mask \"" << fromqstr(filters.join(";;"))
<< "\", suggested \"" << fromqstr(suggested) << '"');
LYXERR(Debug::GUI, "Select with path \"" << path
<< "\", mask \"" << filters.join(";;")
<< "\", suggested \"" << suggested << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;
@ -148,8 +149,8 @@ FileDialog::Result FileDialog::open(QString const & path,
FileDialog::Result FileDialog::opendir(QString const & path,
QString const & suggested)
{
LYXERR(Debug::GUI, "Select with path \"" << fromqstr(path)
<< "\", suggested \"" << fromqstr(suggested) << '"');
LYXERR(Debug::GUI, "Select with path \"" << path
<< "\", suggested \"" << suggested << '"');
FileDialog::Result result;
result.first = FileDialog::Chosen;

View File

@ -223,8 +223,8 @@ void GuiCharacter::change_adaptor()
}
template<class B>
static int findPos2nd(QList<pair<QString, B> > const & vec, B const & val)
template<class P, class B>
static int findPos2nd(QList<P> const & vec, B const & val)
{
for (int i = 0; i != vec.size(); ++i)
if (vec[i].second == val)

View File

@ -19,6 +19,8 @@
#include "qt_helpers.h" // for LanguagePair
#include "Font.h"
#include <utility>
namespace lyx {
namespace frontend {

View File

@ -88,7 +88,7 @@ void TocModel::populate(Toc const & toc)
model_map_[iter] = top_level_item;
LYXERR(Debug::GUI, "Toc: at depth " << iter->depth()
<< ", added item " << to_utf8(iter->str()));
<< ", added item " << toqstr(iter->str()));
populate(iter, end, top_level_item);
@ -110,10 +110,9 @@ void TocModel::populate(TocIterator & iter, TocIterator const & end,
int current_row;
QModelIndex child_item;
insertColumns(0, 1, parent);
while (iter != end) {
while (iter != end) {
++iter;
if (iter == end)

View File

@ -54,12 +54,19 @@ using namespace lyx::support;
namespace lyx {
LyXErr & operator<<(LyXErr & err, QString const & str)
{
return err << fromqstr(str);
}
FileName libFileSearch(QString const & dir, QString const & name,
QString const & ext)
{
return support::libFileSearch(fromqstr(dir), fromqstr(name), fromqstr(ext));
}
namespace frontend {
string widgetsToLength(QLineEdit const * input, LengthCombo const * combo)

View File

@ -15,9 +15,10 @@
#include "Length.h"
#include "support/qstring_helpers.h"
#include "support/strfwd.h"
#include "qt_i18n.h"
#include <QString>
class QComboBox;
class QLineEdit;
class QCheckBox;
@ -31,6 +32,10 @@ namespace lyx {
namespace support { class FileName; }
class LyXErr;
LyXErr & operator<<(LyXErr &, QString const &);
namespace frontend {
/// method to get a Length from widgets (LengthCombo)
@ -63,7 +68,7 @@ void setValid(QWidget * widget, bool valid);
QString const qt_(std::string const & str);
///
typedef std::pair<QString, QString> LanguagePair;
struct LanguagePair { QString first; QString second; };
/** If the caller is the character dialog, add "No change" and "Reset"
* to the vector.

View File

@ -5,6 +5,7 @@
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
* \author Dekel Tsur
*
* Full author contact details are available in file CREDITS.
*/
@ -20,6 +21,9 @@
#include <boost/tokenizer.hpp>
#include "support/assert.h"
#include <QString>
#include <QVector>
#include <algorithm>
using namespace std;
@ -56,6 +60,45 @@ static inline char_type qchar_to_ucs4(QChar const & qchar)
}
QString toqstr(char const * str)
{
return QString::fromUtf8(str);
}
QString toqstr(std::string const & str)
{
return toqstr(str.c_str());
}
QString toqstr(docstring const & ucs4)
{
// If possible we let qt do the work, since this version does not
// need to be superfast.
return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
}
QString toqstr(char_type ucs4)
{
union { char_type c; uint i; } u = { ucs4 };
return QString::fromUcs4(&u.i, 1);
}
docstring qstring_to_ucs4(QString const & qstr)
{
if (qstr.isEmpty())
return docstring();
QVector<uint> const ucs4 = qstr.toUcs4();
return docstring((char_type const *)(ucs4.constData()), ucs4.size());
}
std::string fromqstr(QString const & str)
{
return str.isEmpty() ? std::string() : std::string(str.toUtf8());
}
/**
* Convert a UCS4 character into a QChar.
* This is a hack (it does only make sense for the common part of the UCS4

View File

@ -0,0 +1,60 @@
/**
* \file qstring_helper.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Dekel Tsur
*
* Full author contact details are available in file CREDITS.
*
* A collection of unicode conversion functions, using iconv.
*/
#include <config.h>
#include "support/docstring.h"
#include "support/docstring.h"
#include <QString>
#include <QVector>
namespace lyx {
QString toqstr(char const * str)
{
return QString::fromUtf8(str);
}
QString toqstr(std::string const & str)
{
return toqstr(str.c_str());
}
QString toqstr(docstring const & ucs4)
{
// If possible we let qt do the work, since this version does not
// need to be superfast.
return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
}
QString toqstr(char_type ucs4)
{
union { char_type c; uint i; } u = { ucs4 };
return QString::fromUcs4(&u.i, 1);
}
docstring qstring_to_ucs4(QString const & qstr)
{
if (qstr.isEmpty())
return docstring();
QVector<uint> const ucs4 = qstr.toUcs4();
return docstring((char_type const *)(ucs4.constData()), ucs4.size());
}
std::string fromqstr(QString const & str)
{
return str.isEmpty() ? std::string() : std::string(str.toUtf8());
}
} // namespace lyx

View File

@ -12,10 +12,9 @@
#ifndef QSTRING_HELPERS_H
#define QSTRING_HELPERS_H
#include "support/docstring.h"
#include "support/strfwd.h"
#include <QString>
#include <QVector>
class QString;
namespace lyx {
@ -25,10 +24,7 @@ namespace lyx {
* This should not be used, since all possibly non-ASCII stuff should be
* stored in a docstring.
*/
inline QString const toqstr(char const * str)
{
return QString::fromUtf8(str);
}
QString toqstr(char const * str);
/**
@ -37,14 +33,11 @@ inline QString const toqstr(char const * str)
* This should not be used, since all possibly non-ASCII stuff should be
* stored in a docstring.
*/
inline QString const toqstr(std::string const & str)
{
return toqstr(str.c_str());
}
QString toqstr(std::string const & str);
/// Is \p c a valid utf16 char?
inline bool is_utf16(char_type c)
inline bool is_utf16(unsigned int c)
{
// 0xd800 ... 0xdfff is the range of surrogate pairs.
return c < 0xd800 || (c > 0xdfff && c < 0x10000);
@ -57,12 +50,7 @@ inline bool is_utf16(char_type c)
* This is the preferred method of converting anything that possibly
* contains non-ASCII stuff to QString.
*/
inline QString const toqstr(docstring const & ucs4)
{
// If possible we let qt do the work, since this version does not
// need to be superfast.
return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
}
QString toqstr(docstring const & ucs4);
/**
* toqstr - convert a UCS4 encoded character into a QString
@ -70,11 +58,7 @@ inline QString const toqstr(docstring const & ucs4)
* This is the preferred method of converting anything that possibly
* contains non-ASCII stuff to QString.
*/
inline QString const toqstr(char_type ucs4)
{
union { char_type c; uint i; } u = { ucs4 };
return QString::fromUcs4(&u.i, 1);
}
QString toqstr(char_type ucs4);
/**
* qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
@ -82,13 +66,7 @@ inline QString const toqstr(char_type ucs4)
* This is the preferred method of converting anything that possibly
* contains non-ASCII stuff to docstring.
*/
inline docstring const qstring_to_ucs4(QString const & qstr)
{
if (qstr.isEmpty())
return docstring();
QVector<uint> const ucs4 = qstr.toUcs4();
return docstring((char_type const *)(ucs4.constData()), ucs4.size());
}
docstring qstring_to_ucs4(QString const & qstr);
/**
* fromqstr - convert a QString into a UTF8 encoded std::string
@ -96,10 +74,7 @@ inline docstring const qstring_to_ucs4(QString const & qstr)
* This should not be used except for output to lyxerr, since all possibly
* non-ASCII stuff should be stored in a docstring.
*/
inline std::string const fromqstr(QString const & str)
{
return str.isEmpty() ? std::string() : std::string(str.toUtf8());
}
std::string fromqstr(QString const & str);
} // namespace lyx