From f1dc8ed5d852a02dcacafb79195d8ca17d4a20ea Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 21 May 2010 13:28:38 +0200 Subject: QComboBox: Fix documentation and make auto-test pass. Reviewed-by: Olivier --- src/gui/widgets/qcombobox.cpp | 2 +- tests/auto/qcombobox/tst_qcombobox.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 1504066..6cf24a6 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -1293,7 +1293,7 @@ QComboBox::~QComboBox() By default, this property has a value of 10. \note This property is ignored for non-editable comboboxes in styles that returns - false for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style. + true for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style. */ int QComboBox::maxVisibleItems() const { diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index 1fcea9e..aa821c2 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -2553,9 +2553,11 @@ void tst_QComboBox::maxVisibleItems() QAbstractItemView *v = comboBox.view(); int itemHeight = v->visualRect(v->model()->index(0,0)).height(); - if (v->style()->styleHint(QStyle::SH_ComboBox_Popup)) + QListView *lv = qobject_cast(v); + if (lv) + itemHeight += lv->spacing(); + if (!v->style()->styleHint(QStyle::SH_ComboBox_Popup)) QCOMPARE(v->viewport()->height(), itemHeight * comboBox.maxVisibleItems()); - // QCombobox without a popup does not work, see QTBUG-760 } -- cgit v0.12 From c9607f069f0fb98021daf0af9f1d1b2981018e0c Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 19 May 2010 07:18:27 +0200 Subject: Use binarysort to find items. Task: http://bugreports.qt.nokia.com/browse/QTBUG-231 Reviwed-by: Eskil --- src/gui/text/qtextengine.cpp | 19 ++++++++++++------- src/gui/text/qtextlayout.cpp | 24 +++++++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index d34553f..dc099fc 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1518,14 +1518,19 @@ void QTextEngine::itemize() const int QTextEngine::findItem(int strPos) const { itemize(); - - // ##### use binary search - int item; - for (item = layoutData->items.size()-1; item > 0; --item) { - if (layoutData->items[item].position <= strPos) - break; + int left = 0; + int right = layoutData->items.size()-1; + while(left <= right) { + int middle = ((right-left)/2)+left; + if (strPos > layoutData->items[middle].position) + left = middle+1; + else if(strPos < layoutData->items[middle].position) + right = middle-1; + else { + return middle; + } } - return item; + return right; } QFixed QTextEngine::width(int from, int len) const diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index ce7915d..94d9d67 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1208,7 +1208,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVectorlayoutData->items.size()-1; newItem > 0; --newItem) { - if (eng->layoutData->items[newItem].position <= line.from) + int newItem = -1; + int left = 0; + int right = eng->layoutData->items.size()-1; + while(left <= right) { + int middle = ((right-left)/2)+left; + if (line.from > eng->layoutData->items[middle].position) + left = middle+1; + else if(line.from < eng->layoutData->items[middle].position) + right = middle-1; + else { + newItem = middle; break; + } } + if (newItem == -1) + newItem = right; LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, eng->layoutData->items.size(), line.width.toReal()); @@ -1939,7 +1949,7 @@ void QTextLine::layout_helper(int maxGlyphs) } LB_DEBUG("reached end of line"); lbh.checkFullOtherwiseExtend(line); -found: +found: if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted lbh.adjustRightBearing(); line.textAdvance = line.textWidth; -- cgit v0.12 From 2e0ac76a76f02e22f101b24ba222f8251d0c2580 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 25 May 2010 14:20:31 +0200 Subject: Fix tst_QComboBox::maxVisibleItems() auto-test on Mac Reviewed-by: Olivier --- tests/auto/qcombobox/tst_qcombobox.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index aa821c2..fb6c741 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -2556,7 +2556,9 @@ void tst_QComboBox::maxVisibleItems() QListView *lv = qobject_cast(v); if (lv) itemHeight += lv->spacing(); - if (!v->style()->styleHint(QStyle::SH_ComboBox_Popup)) + QStyleOptionComboBox opt; + opt.initFrom(&comboBox); + if (!comboBox.style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) QCOMPARE(v->viewport()->height(), itemHeight * comboBox.maxVisibleItems()); } -- cgit v0.12