From eea978b9744c24200496af4f8a37d76228a29320 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Wed, 19 May 2010 16:33:48 +0200 Subject: Fixed an assert in QMenu The code was changed and changed the behaviour. This is basically a kind of revert. Reviewed-By: gabi Task-Number: QTBUG-10735 --- src/gui/widgets/qmenu.cpp | 12 +--------- tests/auto/qmenu/tst_qmenu.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index f84059d..7941c4e 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -983,19 +983,9 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e) return false; } -class ExceptionGuard -{ -public: - inline ExceptionGuard(bool *w = 0) : watched(w) { Q_ASSERT(!(*watched)); *watched = true; } - inline ~ExceptionGuard() { *watched = false; } - inline operator bool() { return *watched; } -private: - bool *watched; -}; - void QMenuPrivate::activateCausedStack(const QList > &causedStack, QAction *action, QAction::ActionEvent action_e, bool self) { - ExceptionGuard guard(&activationRecursionGuard); + QBoolBlocker guard(activationRecursionGuard); #ifdef QT3_SUPPORT const int actionId = q_func()->findIdForAction(action); #endif diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index e10d7ee..c8dc516 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -106,6 +107,7 @@ private slots: void pushButtonPopulateOnAboutToShow(); void QTBUG7907_submenus_autoselect(); void QTBUG7411_submenus_activate(); + void QTBUG_10735_crashWithDialog(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -969,5 +971,57 @@ void tst_QMenu::QTBUG7411_submenus_activate() +class MyMenu : public QMenu +{ + Q_OBJECT +public: + MyMenu() : m_currentIndex(0) + { + for (int i = 0; i < 2; ++i) + dialogActions[i] = addAction( QString("dialog %1").arg(i), dialogs + i, SLOT(exec())); + } + + + void activateAction(int index) + { + m_currentIndex = index; + popup(QPoint()); + QTest::qWaitForWindowShown(this); + setActiveAction(dialogActions[index]); + QTimer::singleShot(0, this, SLOT(checkVisibility())); + QTest::keyClick(this, Qt::Key_Enter); //activation + } + +public slots: + void activateLastAction() + { + activateAction(1); + } + + void checkVisibility() + { + QTRY_VERIFY(dialogs[m_currentIndex].isVisible()); + if (m_currentIndex == 1) { + QApplication::closeAllWindows(); //this is the end of the test + } + } + + +private: + QAction *dialogActions[2]; + QDialog dialogs[2]; + int m_currentIndex; +}; + +void tst_QMenu::QTBUG_10735_crashWithDialog() +{ + MyMenu menu; + + QTimer::singleShot(1000, &menu, SLOT(activateLastAction())); + menu.activateAction(0); + +} + + QTEST_MAIN(tst_QMenu) #include "tst_qmenu.moc" -- cgit v0.12 From c98ccc13252aa625f552ae2f05f47e7e5f475aaa Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:46:05 +0200 Subject: prefer QChar::*surrogate() over hardcoded values Merge-request: 2393 Reviewed-by: Olivier Goffart --- src/corelib/tools/qstring.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 612c492..9e80938 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -939,11 +939,11 @@ int QString::toWCharArray(wchar_t *array) const const unsigned short *uc = utf16(); for (int i = 0; i < length(); ++i) { uint u = uc[i]; - if (u >= 0xd800 && u < 0xdc00 && i < length()-1) { + if (QChar::isHighSurrogate(u) && i + 1 < length()) { ushort low = uc[i+1]; - if (low >= 0xdc00 && low < 0xe000) { + if (QChar::isLowSurrogate(low)) { + u = QChar::surrogateToUcs4(u, low); ++i; - u = (u - 0xd800)*0x400 + (low - 0xdc00) + 0x10000; } } *a = wchar_t(u); -- cgit v0.12 From 2a00c5582c23e5e7aee858725d27da4d725d03cf Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:46:07 +0200 Subject: prevent fake normalization if normalization was requested for QChar::Unicode_Unassigned version; treat it like latest supported version instead Merge-request: 2393 Reviewed-by: Olivier Goffart --- src/corelib/tools/qstring.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 9e80938..6acbcec 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -6195,8 +6195,10 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar:: if (simple) return; - QString &s = *data; - if (version != UNICODE_DATA_VERSION) { + if (version == QChar::Unicode_Unassigned) { + version = UNICODE_DATA_VERSION; + } else if (version != UNICODE_DATA_VERSION) { + QString &s = *data; for (int i = 0; i < NumNormalizationCorrections; ++i) { const NormalizationCorrection &n = uc_normalization_corrections[i]; if (n.version > version) { -- cgit v0.12 From 8b3efa13709b24b5bc5d6356d8c8d94f06209fd5 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:46:09 +0200 Subject: use new QChar::requiresSurrogates() instead of hardcoded value this also fixes handling of codepoint 0x10000 ("ucs4 > 0x10000" s/>/>=/) Merge-request: 2393 Reviewed-by: Olivier Goffart --- src/corelib/tools/qchar.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index ddb1516..29ecf10 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -1480,9 +1480,9 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion if (!d || (canonical && tag != QChar::Canonical)) continue; - s.replace(uc - utf16, ucs4 > 0x10000 ? 2 : 1, (const QChar *)d, length); - // since the insert invalidates the pointers and we do decomposition recursive int pos = uc - utf16; + s.replace(pos, QChar::requiresSurrogates(ucs4) ? 2 : 1, reinterpret_cast(d), length); + // since the insert invalidates the pointers and we do decomposition recursive utf16 = reinterpret_cast(s.data()); uc = utf16 + pos + length; } @@ -1600,13 +1600,13 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in QChar *uc = s.data(); int p = pos; // exchange characters - if (u2 < 0x10000) { + if (!QChar::requiresSurrogates(u2)) { uc[p++] = u2; } else { uc[p++] = QChar::highSurrogate(u2); uc[p++] = QChar::lowSurrogate(u2); } - if (u1 < 0x10000) { + if (!QChar::requiresSurrogates(u1)) { uc[p++] = u1; } else { uc[p++] = QChar::highSurrogate(u1); @@ -1618,7 +1618,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in --pos; } else { ++pos; - if (u1 > 0x10000) + if (QChar::requiresSurrogates(u1)) ++pos; } } -- cgit v0.12 From 8e5ac76a2907a7a89b31ed562b5d086adaad5faf Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:46:10 +0200 Subject: fix canonicalOrderHelper() for some corner case where string ends with sequence like HiS, LowS, NotS. in this case, if combiningClass(HiS, LowS) > combiningClass(NotS), then result will be invalid due to early exit on (p2 >= s.length()-1) Merge-request: 2393 Reviewed-by: Olivier Goffart --- src/corelib/tools/qchar.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 29ecf10..c3e9f0e 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -1567,20 +1567,20 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in int p2 = pos+1; uint u1 = s.at(pos).unicode(); if (QChar(u1).isHighSurrogate()) { - ushort low = s.at(pos+1).unicode(); + ushort low = s.at(p2).unicode(); if (QChar(low).isLowSurrogate()) { - p2++; u1 = QChar::surrogateToUcs4(u1, low); if (p2 >= l) break; + ++p2; } } uint u2 = s.at(p2).unicode(); - if (QChar(u2).isHighSurrogate() && p2 < l-1) { + if (QChar(u2).isHighSurrogate() && p2 < l) { ushort low = s.at(p2+1).unicode(); if (QChar(low).isLowSurrogate()) { - p2++; u2 = QChar::surrogateToUcs4(u2, low); + ++p2; } } -- cgit v0.12 From 173e2c1ba81b9a2665c040a9e86d085131e5042e Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:46:12 +0200 Subject: nano optimization of canonicalOrderHelper() by inlining & merging QChar::combiningClass() and QChar::unicodeVersion() Merge-request: 2393 Reviewed-by: Olivier Goffart --- src/corelib/tools/qchar.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index c3e9f0e..ed0af4e 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -1584,17 +1584,23 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in } } - int c2 = QChar::combiningClass(u2); - if (QChar::unicodeVersion(u2) > version) - c2 = 0; - + ushort c2 = 0; + { + const QUnicodeTables::Properties *p = qGetProp(u2); + if ((QChar::UnicodeVersion)p->unicodeVersion <= version) + c2 = p->combiningClass; + } if (c2 == 0) { pos = p2+1; continue; } - int c1 = QChar::combiningClass(u1); - if (QChar::unicodeVersion(u1) > version) - c1 = 0; + + ushort c1 = 0; + { + const QUnicodeTables::Properties *p = qGetProp(u1); + if ((QChar::UnicodeVersion)p->unicodeVersion <= version) + c1 = p->combiningClass; + } if (c1 > c2) { QChar *uc = s.data(); -- cgit v0.12 From 9c13272ddeea2408c83eb12a9f1fcceeb6a7589e Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:47:19 +0200 Subject: more subtests for QChar Merge-request: 2392 Reviewed-by: Olivier Goffart --- tests/auto/qchar/tst_qchar.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/auto/qchar/tst_qchar.cpp b/tests/auto/qchar/tst_qchar.cpp index 5ca2255..9f70b8c 100644 --- a/tests/auto/qchar/tst_qchar.cpp +++ b/tests/auto/qchar/tst_qchar.cpp @@ -75,6 +75,7 @@ private slots: void isPrint(); void isUpper(); void isLower(); + void isTitle(); void category(); void direction(); void joining(); @@ -234,6 +235,11 @@ void tst_QChar::isUpper() QVERIFY(!QChar('?').isUpper()); QVERIFY(QChar(0xC2).isUpper()); // A with ^ QVERIFY(!QChar(0xE2).isUpper()); // a with ^ + + for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) { + if (QChar::category(codepoint) == QChar::Letter_Uppercase) + QVERIFY(codepoint == QChar::toUpper(codepoint)); + } } void tst_QChar::isLower() @@ -245,6 +251,19 @@ void tst_QChar::isLower() QVERIFY(!QChar('?').isLower()); QVERIFY(!QChar(0xC2).isLower()); // A with ^ QVERIFY(QChar(0xE2).isLower()); // a with ^ + + for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) { + if (QChar::category(codepoint) == QChar::Letter_Lowercase) + QVERIFY(codepoint == QChar::toLower(codepoint)); + } +} + +void tst_QChar::isTitle() +{ + for (uint codepoint = 0; codepoint <= UNICODE_LAST_CODEPOINT; ++codepoint) { + if (QChar::category(codepoint) == QChar::Letter_Titlecase) + QVERIFY(codepoint == QChar::toTitleCase(codepoint)); + } } void tst_QChar::category() -- cgit v0.12 From 89a5f382e1eff75c3d3f015b3fce0a58b8079e04 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Thu, 20 May 2010 10:47:21 +0200 Subject: improve Unicode Normalization autotest Merge-request: 2392 Reviewed-by: Olivier Goffart --- tests/auto/qchar/tst_qchar.cpp | 85 ++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/tests/auto/qchar/tst_qchar.cpp b/tests/auto/qchar/tst_qchar.cpp index 9f70b8c..93aaf96 100644 --- a/tests/auto/qchar/tst_qchar.cpp +++ b/tests/auto/qchar/tst_qchar.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #if defined(Q_OS_WINCE) #include @@ -84,7 +85,9 @@ private slots: void decomposition(); // void ligature(); void lineBreakClass(); + void normalization_data(); void normalization(); + void normalization_manual(); void normalizationCorrections(); void unicodeVersion(); #if defined(Q_OS_WINCE) @@ -505,31 +508,13 @@ void tst_QChar::lineBreakClass() QVERIFY(QUnicodeTables::lineBreakClass(0x0fffdu) == QUnicodeTables::LineBreak_AL); } -void tst_QChar::normalization() +void tst_QChar::normalization_data() { - { - QString composed; - composed += QChar(0xc0); - QString decomposed; - decomposed += QChar(0x41); - decomposed += QChar(0x300); + QTest::addColumn("columns"); + QTest::addColumn("part"); - QVERIFY(composed.normalized(QString::NormalizationForm_D) == decomposed); - QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); - QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); - QVERIFY(composed.normalized(QString::NormalizationForm_KC) == composed); - } - { - QString composed; - composed += QChar(0xa0); - QString decomposed; - decomposed += QChar(0x20); - - QVERIFY(composed.normalized(QString::NormalizationForm_D) == composed); - QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); - QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); - QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed); - } + int linenum = 0; + int part = 0; QFile f(SRCDIR "NormalizationTest.txt"); QVERIFY(f.exists()); @@ -537,6 +522,8 @@ void tst_QChar::normalization() f.open(QIODevice::ReadOnly); while (!f.atEnd()) { + linenum++; + QByteArray line; line.resize(1024); int len = f.readLine(line.data(), 1024); @@ -546,8 +533,11 @@ void tst_QChar::normalization() if (comment >= 0) line = line.left(comment); - if (line.startsWith("@")) + if (line.startsWith("@")) { + if (line.startsWith("@Part") && line.size() > 5 && QChar(line.at(5)).isDigit()) + part = QChar(line.at(5)).digitValue(); continue; + } if (line.isEmpty()) continue; @@ -560,8 +550,10 @@ void tst_QChar::normalization() Q_ASSERT(l.size() == 5); - QString columns[5]; + QStringList columns; for (int i = 0; i < 5; ++i) { + columns.append(QString()); + QList c = l.at(i).split(' '); Q_ASSERT(!c.isEmpty()); @@ -572,15 +564,26 @@ void tst_QChar::normalization() columns[i].append(QChar(uc)); else { // convert to utf16 - uc -= 0x10000; - ushort high = uc/0x400 + 0xd800; - ushort low = uc%0x400 + 0xdc00; + ushort high = QChar::highSurrogate(uc); + ushort low = QChar::lowSurrogate(uc); columns[i].append(QChar(high)); columns[i].append(QChar(low)); } } } + QString nm = QString("line #%1:").arg(linenum); + QTest::newRow(nm.toLatin1()) << columns << part; + } +} + +void tst_QChar::normalization() +{ + QFETCH(QStringList, columns); + QFETCH(int, part); + + Q_UNUSED(part) + // CONFORMANCE: // 1. The following invariants must be true for all conformant implementations // @@ -630,6 +633,32 @@ void tst_QChar::normalization() // ################# +} + +void tst_QChar::normalization_manual() +{ + { + QString composed; + composed += QChar(0xc0); + QString decomposed; + decomposed += QChar(0x41); + decomposed += QChar(0x300); + + QVERIFY(composed.normalized(QString::NormalizationForm_D) == decomposed); + QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); + QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); + QVERIFY(composed.normalized(QString::NormalizationForm_KC) == composed); + } + { + QString composed; + composed += QChar(0xa0); + QString decomposed; + decomposed += QChar(0x20); + + QVERIFY(composed.normalized(QString::NormalizationForm_D) == composed); + QVERIFY(composed.normalized(QString::NormalizationForm_C) == composed); + QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); + QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed); } } -- cgit v0.12 From d1d8df1076fe7884056798e1974a299ab9d7684e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 20 May 2010 11:21:58 +0200 Subject: Compile with gcc 4.0.1 qstylehelper_p.h now includes qstringbuilder.h This triggers a gcc 4.0.1 bug when doing addition or % on annonymous enum - include qstylehelper_p.h last to avoid errors in 3rd party header - explicitly cast enums to int in qwindowsstyle.cpp Reviewed-by: Thierry --- src/gui/image/qicon.cpp | 3 ++- src/gui/styles/qcleanlooksstyle.cpp | 2 +- src/gui/styles/qcommonstyle.cpp | 3 ++- src/gui/styles/qmacstyle_mac.mm | 2 +- src/gui/styles/qplastiquestyle.cpp | 2 +- src/gui/styles/qproxystyle.cpp | 2 +- src/gui/styles/qstyle_p.h | 1 - src/gui/styles/qstylehelper.cpp | 3 +-- src/gui/styles/qwindowsstyle.cpp | 8 ++++---- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 7696632..a2f429a 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -55,7 +55,6 @@ #include "qcache.h" #include "qdebug.h" #include "private/qguiplatformplugin_p.h" -#include "private/qstylehelper_p.h" #ifdef Q_WS_MAC #include @@ -67,6 +66,8 @@ #include "private/qkde_p.h" #endif +#include "private/qstylehelper_p.h" + #ifndef QT_NO_ICON QT_BEGIN_NAMESPACE diff --git a/src/gui/styles/qcleanlooksstyle.cpp b/src/gui/styles/qcleanlooksstyle.cpp index d9f7df0..883f511 100644 --- a/src/gui/styles/qcleanlooksstyle.cpp +++ b/src/gui/styles/qcleanlooksstyle.cpp @@ -44,7 +44,6 @@ #if !defined(QT_NO_STYLE_CLEANLOOKS) || defined(QT_PLUGIN) -#include #include "qwindowsstyle_p.h" #include #include @@ -67,6 +66,7 @@ #include #include #include +#include #define CL_MAX(a,b) (a)>(b) ? (a):(b) // ### qMin/qMax does not work for vc6 #define CL_MIN(a,b) (a)<(b) ? (a):(b) // remove this when it is working diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 8036728..4978565 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -65,7 +65,6 @@ #include #include #include -#include #include #include #include @@ -88,6 +87,8 @@ # include #endif +#include + QT_BEGIN_NAMESPACE /*! diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index e065bcc..2e2f374 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -56,7 +56,6 @@ #include #include #include -#include #include #include #include @@ -101,6 +100,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index fbb5e4d..c8711f6 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -50,7 +50,6 @@ static const int ProgressBarFps = 25; static const int blueFrameWidth = 2; // with of line edit focus frame #include "qwindowsstyle_p.h" -#include #include #include #include @@ -88,6 +87,7 @@ static const int blueFrameWidth = 2; // with of line edit focus frame #include #include #include +#include QT_BEGIN_NAMESPACE diff --git a/src/gui/styles/qproxystyle.cpp b/src/gui/styles/qproxystyle.cpp index 5235350..511c025 100644 --- a/src/gui/styles/qproxystyle.cpp +++ b/src/gui/styles/qproxystyle.cpp @@ -40,11 +40,11 @@ ****************************************************************************/ #include -#include #include #include #include "qproxystyle.h" #include "qstylefactory.h" +#include #if !defined(QT_NO_STYLE_PROXY) || defined(QT_PLUGIN) diff --git a/src/gui/styles/qstyle_p.h b/src/gui/styles/qstyle_p.h index 4729032..745092f 100644 --- a/src/gui/styles/qstyle_p.h +++ b/src/gui/styles/qstyle_p.h @@ -43,7 +43,6 @@ #define QSTYLE_P_H #include "private/qobject_p.h" -#include "private/qstylehelper_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/gui/styles/qstylehelper.cpp b/src/gui/styles/qstylehelper.cpp index d09d7fa..ccdbf8c 100644 --- a/src/gui/styles/qstylehelper.cpp +++ b/src/gui/styles/qstylehelper.cpp @@ -39,8 +39,6 @@ ** ****************************************************************************/ -#include "qstylehelper_p.h" - #include #include #include @@ -54,6 +52,7 @@ #include #endif +#include "qstylehelper_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp index 1653baa..0314c6f 100644 --- a/src/gui/styles/qwindowsstyle.cpp +++ b/src/gui/styles/qwindowsstyle.cpp @@ -41,7 +41,6 @@ #include "qwindowsstyle.h" #include "qwindowsstyle_p.h" -#include #if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN) @@ -70,13 +69,14 @@ #include #include - #ifdef Q_WS_X11 #include "qfileinfo.h" #include "qdir.h" #include #endif +#include + QT_BEGIN_NAMESPACE #if defined(Q_WS_WIN) @@ -1911,7 +1911,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai p->setPen(discol); } - int xm = QWindowsStylePrivate::windowsItemFrame + checkcol + QWindowsStylePrivate::windowsItemHMargin; + int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin); int xpos = menuitem->rect.x() + xm; QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin, w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin); @@ -3223,7 +3223,7 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, int checkcol = qMax(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column w += checkcol; - w += QWindowsStylePrivate::windowsRightBorder + 10; + w += int(QWindowsStylePrivate::windowsRightBorder) + 10; sz.setWidth(w); } break; -- cgit v0.12 From 76fcf30c0f275a7c9f9752b1be5cb1d5ba98d9b6 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 20 May 2010 12:26:11 +0200 Subject: Autotest fix on macosx --- tests/auto/qmenu/tst_qmenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index c8dc516..b6bdb36 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -988,7 +988,7 @@ public: popup(QPoint()); QTest::qWaitForWindowShown(this); setActiveAction(dialogActions[index]); - QTimer::singleShot(0, this, SLOT(checkVisibility())); + QTimer::singleShot(500, this, SLOT(checkVisibility())); QTest::keyClick(this, Qt::Key_Enter); //activation } -- cgit v0.12 From 2c1d1c136102a17eef9ae3c4e9f0cf01338306ae Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 20 May 2010 13:07:41 +0200 Subject: Deselect the current selection when the QItemSelectionModel::model is reset. Merge-request: 639 Reviewed-by: Olivier Goffart --- src/gui/itemviews/qitemselectionmodel.cpp | 25 +++++++++--- src/gui/itemviews/qitemselectionmodel.h | 1 + src/gui/itemviews/qitemselectionmodel_p.h | 3 ++ .../tst_qitemselectionmodel.cpp | 47 ++++++++++++++++++++-- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp index f848321..fc99439 100644 --- a/src/gui/itemviews/qitemselectionmodel.cpp +++ b/src/gui/itemviews/qitemselectionmodel.cpp @@ -566,6 +566,8 @@ void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model) q, SLOT(_q_layoutAboutToBeChanged())); QObject::connect(model, SIGNAL(layoutChanged()), q, SLOT(_q_layoutChanged())); + QObject::connect(model, SIGNAL(modelAboutToBeReset()), + q, SLOT(_q_modelAboutToBeReset())); } } @@ -896,6 +898,13 @@ void QItemSelectionModelPrivate::_q_layoutChanged() savedPersistentCurrentIndexes.clear(); } +void QItemSelectionModelPrivate::_q_modelAboutToBeReset() +{ + Q_Q(QItemSelectionModel); + q->clearSelection(); + clearCurrentIndex(); +} + /*! \class QItemSelectionModel @@ -1095,12 +1104,18 @@ void QItemSelectionModel::clear() { Q_D(QItemSelectionModel); clearSelection(); - QModelIndex previous = d->currentIndex; - d->currentIndex = QModelIndex(); + d->clearCurrentIndex(); +} + +void QItemSelectionModelPrivate::clearCurrentIndex() +{ + Q_Q(QItemSelectionModel); + QModelIndex previous = currentIndex; + currentIndex = QModelIndex(); if (previous.isValid()) { - emit currentChanged(d->currentIndex, previous); - emit currentRowChanged(d->currentIndex, previous); - emit currentColumnChanged(d->currentIndex, previous); + emit q->currentChanged(currentIndex, previous); + emit q->currentRowChanged(currentIndex, previous); + emit q->currentColumnChanged(currentIndex, previous); } } diff --git a/src/gui/itemviews/qitemselectionmodel.h b/src/gui/itemviews/qitemselectionmodel.h index 436514f..8682109 100644 --- a/src/gui/itemviews/qitemselectionmodel.h +++ b/src/gui/itemviews/qitemselectionmodel.h @@ -197,6 +197,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeInserted(const QModelIndex&, int, int)) Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged()) Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged()) + Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset()) }; Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags) diff --git a/src/gui/itemviews/qitemselectionmodel_p.h b/src/gui/itemviews/qitemselectionmodel_p.h index 5afa90d..c2fe976 100644 --- a/src/gui/itemviews/qitemselectionmodel_p.h +++ b/src/gui/itemviews/qitemselectionmodel_p.h @@ -78,6 +78,7 @@ public: void _q_columnsAboutToBeInserted(const QModelIndex &parent, int start, int end); void _q_layoutAboutToBeChanged(); void _q_layoutChanged(); + void _q_modelAboutToBeReset(); inline void remove(QList &r) { @@ -93,6 +94,8 @@ public: currentSelection.clear(); } + void clearCurrentIndex(); + QPointer model; QItemSelection ranges; QItemSelection currentSelection; diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp index 3b2a716..9858829 100644 --- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -1536,6 +1536,43 @@ public: inline void reset() { QStandardItemModel::reset(); } }; +class ResetObserver : public QObject +{ + QItemSelectionModel * const m_selectionModel; + QItemSelection m_selection; + Q_OBJECT +public: + ResetObserver(QItemSelectionModel *selectionModel) + : m_selectionModel(selectionModel) + { + connect(selectionModel->model(), SIGNAL(modelAboutToBeReset()),SLOT(modelAboutToBeReset())); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection))); + connect(selectionModel->model(), SIGNAL(modelReset()),SLOT(modelReset())); + } + +private slots: + void modelAboutToBeReset() + { + m_selection = m_selectionModel->selection(); + foreach(const QItemSelectionRange &range, m_selection) + { + QVERIFY(range.isValid()); + } + } + + void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) + { + qDebug() << deselected << selected; + QCOMPARE(m_selection, deselected); + m_selection.clear(); + } + + void modelReset() + { + QVERIFY(m_selectionModel->selection().isEmpty()); + } +}; + void tst_QItemSelectionModel::resetModel() { MyStandardItemModel model(20, 20); @@ -1555,11 +1592,13 @@ void tst_QItemSelectionModel::resetModel() view.selectionModel()->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select); - QCOMPARE(spy.count(), 2); - QCOMPARE(spy.at(1).count(), 2); + // We get this signal three times. Twice in this test method and once because the source reset causes the current selection to + // be deselected. + QCOMPARE(spy.count(), 3); + QCOMPARE(spy.at(2).count(), 2); // make sure we don't get an "old selection" - QCOMPARE(spy.at(1).at(1).userType(), qMetaTypeId()); - QVERIFY(qvariant_cast(spy.at(1).at(1)).isEmpty()); + QCOMPARE(spy.at(2).at(1).userType(), qMetaTypeId()); + QVERIFY(qvariant_cast(spy.at(2).at(1)).isEmpty()); } void tst_QItemSelectionModel::removeRows_data() -- cgit v0.12 From ef8cd7f2e68d6d34d70c3a12e82a67ed16b92b72 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 20 May 2010 14:33:37 +0200 Subject: Fix crash when using fonts in non-gui QApplication XLFD requires a DISPLAY connection to work. We would get crashes in a QApplication with GUI disabled when: 1. Not using FontConfig, or 2. Falling back to XLFD for bitmap fonts that require scaling. The patch disables paths to loadXlfd() when GUI is disabled. This means that in XLFD, we will always get a box font, which is the same behavior as when using fonts outside the main thread. There doesn't seem to be any way around this. With FontConfig, we will use the font it returns, even if it's a slightly wrong size. Main consequence will be for using bitmap fonts for printing on a highres printer in a non-gui application. Again, there does not seem to be any way around this. NOTE: I've also added a catch to avoid going into loadXlfd() in the fallback if we're not on the main thread, since this was missing. Task-number: QTBUG-10448 Reviewed-by: Trond --- src/gui/text/qfontdatabase_x11.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index 3b2e4e9..a7aa2ce 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -78,6 +78,9 @@ QT_BEGIN_NAMESPACE extern double qt_pointSize(double pixelSize, int dpi); extern double qt_pixelSize(double pointSize, int dpi); +// from qapplication.cpp +extern bool qt_is_gui_used; + static inline void capitalize (char *s) { bool space = true; @@ -1938,7 +1941,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script) } else if (X11->has_fontconfig) { fe = loadFc(d, script, req); - if (fe != 0 && fe->fontDef.pixelSize != req.pixelSize) { + if (fe != 0 && fe->fontDef.pixelSize != req.pixelSize && mainThread && qt_is_gui_used) { QFontEngine *xlfdFontEngine = loadXlfd(d->screen, script, req); if (xlfdFontEngine->fontDef.family == fe->fontDef.family) { delete fe; @@ -1950,7 +1953,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script) #endif - } else if (mainThread) { + } else if (mainThread && qt_is_gui_used) { fe = loadXlfd(d->screen, script, req); } if (!fe) { -- cgit v0.12 From fd3b00e9aa30f8e15060292f5335b912fe42eeff Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 20 May 2010 22:30:54 +0200 Subject: add missing include ... as instructed by olivier --- src/gui/styles/qwindowsmobilestyle.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/styles/qwindowsmobilestyle.cpp b/src/gui/styles/qwindowsmobilestyle.cpp index 67eb1ef..4e7b92c 100644 --- a/src/gui/styles/qwindowsmobilestyle.cpp +++ b/src/gui/styles/qwindowsmobilestyle.cpp @@ -80,6 +80,8 @@ extern bool qt_wince_is_smartphone(); //defined in qguifunctions_wince.cp extern bool qt_wince_is_windows_mobile_65(); //defined in qguifunctions_wince.cpp #endif // Q_WS_WINCE +#include "qstylehelper_p.h" + QT_BEGIN_NAMESPACE static const int windowsItemFrame = 1; // menu item frame width -- cgit v0.12