]> git.lyx.org Git - features.git/commitdiff
* qt_helpers:
authorAbdelrazak Younes <younes@lyx.org>
Sat, 7 Oct 2006 16:30:26 +0000 (16:30 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 7 Oct 2006 16:30:26 +0000 (16:30 +0000)
  - ucs4_to_qchar() and qchar_to_ucs4() have been inlined.
  - ucs4_to_qstring(): pass a QString to avoid a copy.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15266 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiFontMetrics.C
src/frontends/qt4/QLPainter.C
src/frontends/qt4/qt_helpers.C
src/frontends/qt4/qt_helpers.h

index b5a2b0a3d6671d5f5dbddc4fd7737ac8eb82b473..6fcc79930a665a007854097e3b846c5f4c698881 100644 (file)
@@ -137,7 +137,8 @@ int GuiFontMetrics::width(char_type const * s, size_t ls) const
        if (!lyx_gui::use_gui)
                return ls;
 
-       QString ucs2 = ucs4_to_qstring(s, ls);
+       QString ucs2;
+       ucs4_to_qstring(s, ls, ucs2);
 
        if (smallcaps_shape_)
                return smallcapsWidth(ucs2);
index 3fcfba0ee199fbbc83b9ec7f3e697bc2fc5e4a07..92744f0d2a75a9bb389bc5ea9d8409e39b860517 100644 (file)
@@ -231,14 +231,8 @@ void QLPainter::text(int x, int y, char_type const * s, size_t ls,
                encoding = encodings.symbol_encoding();
 #endif
 
-#if 0
        QString str;
-       str.setLength(ls);
-       for (unsigned int i = 0; i < ls; ++i)
-               str[i] = QChar(encoding->ucs(s[i]));
-#else
-       QString str = ucs4_to_qstring(s, ls);
-#endif
+       ucs4_to_qstring(s, ls, str);
 
 #if 0
        // HACK: QT3 refuses to show single compose characters
index 394c13341d5384b05946f2e9bfaec452bf1f17ac..37649e144e2590120c24aa389ee0d910c32276c3 100644 (file)
@@ -120,15 +120,12 @@ QString const toqstr(string const & str)
 }
 
 
-QString const ucs4_to_qstring(char_type const * str, size_t ls)
+void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
 {
-       QString s;
        s.reserve(ls);
 
        for (size_t i = 0; i < ls; ++i)
                s.append(ucs4_to_qchar(str[i]));
-
-       return s;
 }
 
 
@@ -164,18 +161,6 @@ void qstring_to_ucs4(QString const & qstr, vector<char_type> & ucs4)
 }
 
 
-char_type const qchar_to_ucs4(QChar const & qchar)
-{
-       return static_cast<lyx::char_type>(qchar.unicode());
-}
-
-
-QChar const ucs4_to_qchar(char_type const & ucs4)
-{
-       return QChar(static_cast<unsigned short>(ucs4));
-}
-
-
 QString const qt_(char const * str)
 {
        return toqstr(_(str));
index 9574965f41502f0ed97f69913cfe3312209e6764..bdefc8bbe8f65b683ade4cea6aa05387adf38ecb 100644 (file)
 
 #include "support/docstring.h"
 
+#include <QChar>
+
 #include <vector>
 
 class LengthCombo;
 class QComboBox;
 class QLineEdit;
 class QString;
-class QChar;
 
 std::string makeFontName(std::string const & family, std::string const & foundry);
 
@@ -68,16 +69,19 @@ QString const toqstr(std::string const & str);
  */
 QString const toqstr(lyx::docstring const & ucs4);
 
-QString const ucs4_to_qstring(lyx::char_type const * str, size_t ls);
+void ucs4_to_qstring(lyx::char_type const * str, size_t ls, QString & s);
 
 lyx::docstring const qstring_to_ucs4(QString const & qstr);
 
 void qstring_to_ucs4(QString const & qstr, std::vector<lyx::char_type> & ucs4);
 
-lyx::char_type const qchar_to_ucs4(QChar const & qchar);
-
-QChar const ucs4_to_qchar(lyx::char_type const & ucs4);
+inline lyx::char_type const qchar_to_ucs4(QChar const & qchar) {
+       return static_cast<lyx::char_type>(qchar.unicode());
+}
 
+inline QChar const ucs4_to_qchar(lyx::char_type const ucs4) {
+       return QChar(static_cast<unsigned short>(ucs4));
+}
 
 /**
  * qt_ - i18nize string and convert to unicode