From 1f00130097f81bc78aebb3c055f38c066221bc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Tue, 13 Apr 2010 16:24:34 +0200 Subject: Revert "Revert "Implement heightForWidth support for QTabWidget and QStackedLayout."" This reverts commit 42fc3d36260c409918431c1fc058ee2d10f6c147. --- src/gui/kernel/qlayoutitem.cpp | 4 +-- src/gui/kernel/qstackedlayout.cpp | 26 +++++++++++++++++ src/gui/kernel/qstackedlayout.h | 2 ++ src/gui/kernel/qwidget.cpp | 17 +++++++++++ src/gui/kernel/qwidget.h | 1 + src/gui/kernel/qwidget_p.h | 1 + src/gui/widgets/qsizegrip.cpp | 17 +++-------- src/gui/widgets/qtabwidget.cpp | 49 ++++++++++++++++++++++++++++++++ src/gui/widgets/qtabwidget.h | 1 + tests/auto/qtabwidget/tst_qtabwidget.cpp | 47 ++++++++++++++++++++++++++++++ 10 files changed, 149 insertions(+), 16 deletions(-) diff --git a/src/gui/kernel/qlayoutitem.cpp b/src/gui/kernel/qlayoutitem.cpp index 6a91d95..e615b2d 100644 --- a/src/gui/kernel/qlayoutitem.cpp +++ b/src/gui/kernel/qlayoutitem.cpp @@ -516,9 +516,7 @@ bool QWidgetItem::hasHeightForWidth() const { if (isEmpty()) return false; - if (wid->layout()) - return wid->layout()->hasHeightForWidth(); - return wid->sizePolicy().hasHeightForWidth(); + return wid->hasHeightForWidth(); } /*! diff --git a/src/gui/kernel/qstackedlayout.cpp b/src/gui/kernel/qstackedlayout.cpp index 7559066..4b49638 100644 --- a/src/gui/kernel/qstackedlayout.cpp +++ b/src/gui/kernel/qstackedlayout.cpp @@ -475,6 +475,32 @@ void QStackedLayout::setGeometry(const QRect &rect) } } +bool QStackedLayout::hasHeightForWidth() const +{ + const int n = count(); + + for (int i = 0; i < n; ++i) { + if (QLayoutItem *item = itemAt(i)) { + if (item->hasHeightForWidth()) + return true; + } + } + return false; +} + +int QStackedLayout::heightForWidth(int width) const +{ + const int n = count(); + + int hfw = 0; + for (int i = 0; i < n; ++i) { + if (QLayoutItem *item = itemAt(i)) { + hfw = qMax(hfw, item->heightForWidth(width)); + } + } + return hfw; +} + /*! \enum QStackedLayout::StackingMode \since 4.4 diff --git a/src/gui/kernel/qstackedlayout.h b/src/gui/kernel/qstackedlayout.h index c069149..842b62b 100644 --- a/src/gui/kernel/qstackedlayout.h +++ b/src/gui/kernel/qstackedlayout.h @@ -95,6 +95,8 @@ public: QLayoutItem *itemAt(int) const; QLayoutItem *takeAt(int); void setGeometry(const QRect &rect); + bool hasHeightForWidth() const; + int heightForWidth(int width) const; Q_SIGNALS: void widgetRemoved(int index); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 4fba8cf..b19f7aa 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -3820,6 +3820,11 @@ void QWidget::setMaximumSize(int maxw, int maxh) d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); } +bool QWidgetPrivate::hasHeightForWidth() const +{ + return layout ? layout->hasHeightForWidth() : size_policy.hasHeightForWidth(); +} + /*! \overload @@ -7965,6 +7970,18 @@ QSize QWidget::minimumSizeHint() const return QSize(-1, -1); } +/*! + \internal + This is a bit hackish, but ideally this would have been a virtual + function so that subclasses could reimplement their own function. + Instead we add a virtual function to QWidgetPrivate. +*/ +bool QWidget::hasHeightForWidth() const +{ + Q_D(const QWidget); + return d->hasHeightForWidth(); +} + /*! \fn QWidget *QWidget::parentWidget() const diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index e12148b..6e5de7d 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -524,6 +524,7 @@ public: virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; + bool hasHeightForWidth() const; QSizePolicy sizePolicy() const; void setSizePolicy(QSizePolicy); diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 89ea256..05a859c 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -493,6 +493,7 @@ public: bool setMinimumSize_helper(int &minw, int &minh); bool setMaximumSize_helper(int &maxw, int &maxh); + virtual bool hasHeightForWidth() const; void setConstraints_sys(); QWidget *childAt_helper(const QPoint &, bool) const; void updateGeometry_helper(bool forceUpdate); diff --git a/src/gui/widgets/qsizegrip.cpp b/src/gui/widgets/qsizegrip.cpp index c9d613a..40f3129 100644 --- a/src/gui/widgets/qsizegrip.cpp +++ b/src/gui/widgets/qsizegrip.cpp @@ -78,15 +78,6 @@ static QWidget *qt_sizegrip_topLevelWidget(QWidget* w) return w; } -static inline bool hasHeightForWidth(QWidget *widget) -{ - if (!widget) - return false; - if (QLayout *layout = widget->layout()) - return layout->hasHeightForWidth(); - return widget->sizePolicy().hasHeightForWidth(); -} - class QSizeGripPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QSizeGrip) @@ -318,7 +309,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) #ifdef Q_WS_X11 // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) - && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) { + && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); @@ -340,7 +331,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) } #endif // Q_WS_X11 #ifdef Q_WS_WIN - if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) { + if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { uint orientation = 0; if (d->atBottom()) orientation = d->atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; @@ -429,12 +420,12 @@ void QSizeGrip::mouseMoveEvent(QMouseEvent * e) #ifdef Q_WS_X11 if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) - && tlw->isTopLevel() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) + && tlw->isTopLevel() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) return; #endif #ifdef Q_WS_WIN if (tlw->isWindow() && GetSystemMenu(tlw->winId(), FALSE) != 0 && internalWinId() - && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) { + && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !tlw->hasHeightForWidth()) { MSG msg; while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)); return; diff --git a/src/gui/widgets/qtabwidget.cpp b/src/gui/widgets/qtabwidget.cpp index 047a905..fb7ca64 100644 --- a/src/gui/widgets/qtabwidget.cpp +++ b/src/gui/widgets/qtabwidget.cpp @@ -195,6 +195,7 @@ public: void _q_removeTab(int); void _q_tabMoved(int from, int to); void init(); + bool hasHeightForWidth() const; QTabBar *tabs; QStackedWidget *stack; @@ -871,6 +872,46 @@ QSize QTabWidget::minimumSizeHint() const .expandedTo(QApplication::globalStrut()); } +int QTabWidget::heightForWidth(int width) const +{ + Q_D(const QTabWidget); + QStyleOption opt(0); + opt.init(this); + opt.state = QStyle::State_None; + + QSize zero(0,0); + const QSize padding = style()->sizeFromContents(QStyle::CT_TabWidget, &opt, zero, this) + .expandedTo(QApplication::globalStrut()); + + QSize lc(0, 0), rc(0, 0); + if (d->leftCornerWidget) + lc = d->leftCornerWidget->sizeHint(); + if(d->rightCornerWidget) + rc = d->rightCornerWidget->sizeHint(); + if (!d->dirty) { + QTabWidget *that = (QTabWidget*)this; + that->setUpLayout(true); + } + QSize t(d->tabs->sizeHint()); + + if(usesScrollButtons()) + t = t.boundedTo(QSize(200,200)); + else + t = t.boundedTo(QApplication::desktop()->size()); + + const bool tabIsHorizontal = (d->pos == North || d->pos == South); + const int contentsWidth = width - padding.width(); + int stackWidth = contentsWidth; + if (!tabIsHorizontal) + stackWidth -= qMax(t.width(), qMax(lc.width(), rc.width())); + + int stackHeight = d->stack->heightForWidth(stackWidth); + QSize s(stackWidth, stackHeight); + + QSize contentSize = basicSize(tabIsHorizontal, lc, rc, s, t); + return (contentSize + padding).expandedTo(QApplication::globalStrut()).height(); +} + /*! \reimp */ @@ -903,6 +944,14 @@ void QTabWidgetPrivate::updateTabBarPosition() q->setUpLayout(); } +bool QTabWidgetPrivate::hasHeightForWidth() const +{ + bool has = size_policy.hasHeightForWidth(); + if (!has && stack) + has = stack->hasHeightForWidth(); + return has; +} + /*! \property QTabWidget::tabPosition \brief the position of the tabs in this tab widget diff --git a/src/gui/widgets/qtabwidget.h b/src/gui/widgets/qtabwidget.h index 68200c8..ee50655 100644 --- a/src/gui/widgets/qtabwidget.h +++ b/src/gui/widgets/qtabwidget.h @@ -129,6 +129,7 @@ public: QSize sizeHint() const; QSize minimumSizeHint() const; + int heightForWidth(int width) const; void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner); QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const; diff --git a/tests/auto/qtabwidget/tst_qtabwidget.cpp b/tests/auto/qtabwidget/tst_qtabwidget.cpp index 4491fb3..204c27a 100644 --- a/tests/auto/qtabwidget/tst_qtabwidget.cpp +++ b/tests/auto/qtabwidget/tst_qtabwidget.cpp @@ -45,6 +45,7 @@ #include #include #include +#include //TESTED_CLASS= //TESTED_FILES= @@ -120,6 +121,8 @@ class tst_QTabWidget:public QObject { void clear(); void keyboardNavigation(); void paintEventCount(); + void heightForWidth(); + void heightForWidth_data(); private: int addPage(); @@ -621,6 +624,50 @@ void tst_QTabWidget::paintEventCount() QCOMPARE(tab2->count, 1); } +void tst_QTabWidget::heightForWidth_data() +{ + QTest::addColumn("tabPosition"); + QTest::newRow("West") << int(QTabWidget::West); + QTest::newRow("North") << int(QTabWidget::North); + QTest::newRow("East") << int(QTabWidget::East); + QTest::newRow("South") << int(QTabWidget::South); +} + +void tst_QTabWidget::heightForWidth() +{ + QFETCH(int, tabPosition); + + QWidget *window = new QWidget; + QVBoxLayout *lay = new QVBoxLayout(window); + lay->setMargin(0); + lay->setSpacing(0); + QTabWidget *tabWid = new QTabWidget(window); + QWidget *w = new QWidget; + tabWid->addTab(w, QLatin1String("HFW page")); + tabWid->setTabPosition(QTabWidget::TabPosition(tabPosition)); + QVBoxLayout *lay2 = new QVBoxLayout(w); + QLabel *label = new QLabel("Label with wordwrap turned on makes it trade height for width." + " Make it a really long text so that it spans on several lines" + " when the label is on its narrowest." + " I don't like to repeat myself." + " I don't like to repeat myself." + " I don't like to repeat myself." + " I don't like to repeat myself." + ); + label->setWordWrap(true); + lay2->addWidget(label); + lay2->setMargin(0); + + lay->addWidget(tabWid); + int h = window->heightForWidth(160); + window->resize(160, h); + window->show(); + + QTest::qWaitForWindowShown(window); + QVERIFY(label->height() >= label->heightForWidth(label->width())); + + delete window; +} QTEST_MAIN(tst_QTabWidget) #include "tst_qtabwidget.moc" -- cgit v0.12 From 939fdb8f03b998996e532cb89c8e522565c1aecc Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Tue, 27 Apr 2010 11:16:10 +0200 Subject: Fix crash when using opengl graphicssystem on desktop Reviewed-By: Eskil Task-number: QTBUG-10225 --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 6 +++++- src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h | 3 ++- src/opengl/qgl.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 8460430..4461358 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1337,9 +1337,12 @@ void QGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) d->drawCachedGlyphs(glyphType, textItem, true); } -void QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) +bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) { Q_D(QGL2PaintEngineEx); + if (!d->shaderManager) + return false; + ensureActive(); d->transferMode(ImageDrawingMode); @@ -1354,6 +1357,7 @@ void QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, state()->renderHints & QPainter::SmoothPixmapTransform, textureId); d->drawTexture(dest, srcRect, size, false); + return true; } void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index 30f6634..6ba0c42 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -123,7 +123,6 @@ public: virtual void renderHintsChanged(); virtual void transformChanged(); - virtual void drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr); virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr); virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, QPainter::PixmapFragmentHints hints); @@ -136,6 +135,8 @@ public: virtual void drawStaticTextItem(QStaticTextItem *textItem); + bool drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr); + Type type() const { return OpenGL2; } virtual void setState(QPainterState *s); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 72ed6be..52efea5 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2774,8 +2774,8 @@ void QGLContext::drawTexture(const QRectF &target, GLuint textureId, GLenum text if (!eng->isNativePaintingActive()) { QRectF src(0, 0, target.width(), target.height()); QSize size(target.width(), target.height()); - eng->drawTexture(target, textureId, size, src); - return; + if (eng->drawTexture(target, textureId, size, src)) + return; } } @@ -2850,8 +2850,8 @@ void QGLContext::drawTexture(const QPointF &point, GLuint textureId, GLenum text QRectF dest(point, QSizeF(textureWidth, textureHeight)); QRectF src(0, 0, textureWidth, textureHeight); QSize size(textureWidth, textureHeight); - eng->drawTexture(dest, textureId, size, src); - return; + if (eng->drawTexture(dest, textureId, size, src)) + return; } } -- cgit v0.12 From 346b680ab51776e6660df635b0921637f727cc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 27 Apr 2010 15:53:13 +0200 Subject: Fix crash when CoreText fails to shape text for us As a fallback we assume one glyph per character and manually build a list of invalid glyphs with zero advance. Reviewed-and-inspired-by: Simon Hausmann --- src/gui/text/qfontengine_mac.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index 0bfdbc0..a6510cb 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -226,8 +226,19 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay QFixed *outAdvances_y = glyphs->advances_y; glyph_t *initialGlyph = outGlyphs; - if (arraySize == 0) - return false; + if (arraySize == 0) { + // CoreText failed to shape the text we gave it, so we assume one glyph + // per character and build a list of invalid glyphs with zero advance + *nglyphs = len; + for (int i = 0; i < len; ++i) { + outGlyphs[i] = 0; + logClusters[i] = i; + outAdvances_x[i] = QFixed(); + outAdvances_y[i] = QFixed(); + outAttributes[i].clusterStart = true; + } + return true; + } const bool rtl = (CTRunGetStatus(static_cast(CFArrayGetValueAtIndex(array, 0))) & kCTRunStatusRightToLeft); -- cgit v0.12 From 83a59e90ebf3aa2b8381f746a2c731426805b649 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 27 Apr 2010 13:13:42 +0100 Subject: Add unit tests covering most of QVector's API. Similarly to the QList tests, if this breaks, it'll be found out quickly - but it is nice to have tests to pinpoint exactly what, and why. Reviewed-by: Olivier Goffart Merge-Request: 584 --- tests/auto/qvector/tst_qvector.cpp | 600 +++++++++++++++++++++++++++++++++++++ 1 file changed, 600 insertions(+) diff --git a/tests/auto/qvector/tst_qvector.cpp b/tests/auto/qvector/tst_qvector.cpp index ebc19ed..2bc8d15 100644 --- a/tests/auto/qvector/tst_qvector.cpp +++ b/tests/auto/qvector/tst_qvector.cpp @@ -55,10 +55,610 @@ public: virtual ~tst_QVector() {} private slots: + void constructors() const; + void append() const; + void at() const; + void capacity() const; + void clear() const; + void constData() const; + void contains() const; + void count() const; + void data() const; + void empty() const; + void endsWith() const; + void fill() const; + void first() const; + void fromList() const; + void fromStdVector() const; + void indexOf() const; + void insert() const; + void isEmpty() const; + void last() const; + void lastIndexOf() const; + void mid() const; + void prepend() const; + void remove() const; + void size() const; + void startsWith() const; + void toList() const; + void toStdVector() const; + void value() const; + + void testOperators() const; + void outOfMemory(); void QTBUG6416_reserve(); }; +void tst_QVector::constructors() const +{ + // pre-reserve capacity + { + QVector myvec(5); + + QVERIFY(myvec.capacity() == 5); + } + + // default-initialise items + { + QVector myvec(5, 42); + + QVERIFY(myvec.capacity() == 5); + + // make sure all items are initialised ok + foreach (int meaningoflife, myvec) { + QCOMPARE(meaningoflife, 42); + } + } +} + +void tst_QVector::append() const +{ + QVector myvec; + myvec.append(42); + myvec.append(43); + myvec.append(44); + + QVERIFY(myvec.size() == 3); + QCOMPARE(myvec, QVector() << 42 << 43 << 44); +} + +void tst_QVector::at() const +{ + QVector myvec; + myvec << "foo" << "bar" << "baz"; + + QVERIFY(myvec.size() == 3); + QCOMPARE(myvec.at(0), QLatin1String("foo")); + QCOMPARE(myvec.at(1), QLatin1String("bar")); + QCOMPARE(myvec.at(2), QLatin1String("baz")); + + // append an item + myvec << "hello"; + QVERIFY(myvec.size() == 4); + QCOMPARE(myvec.at(0), QLatin1String("foo")); + QCOMPARE(myvec.at(1), QLatin1String("bar")); + QCOMPARE(myvec.at(2), QLatin1String("baz")); + QCOMPARE(myvec.at(3), QLatin1String("hello")); + + // remove an item + myvec.remove(1); + QVERIFY(myvec.size() == 3); + QCOMPARE(myvec.at(0), QLatin1String("foo")); + QCOMPARE(myvec.at(1), QLatin1String("baz")); + QCOMPARE(myvec.at(2), QLatin1String("hello")); +} + +void tst_QVector::capacity() const +{ + QVector myvec; + + // TODO: is this guarenteed? seems a safe assumption, but I suppose preallocation of a + // few items isn't an entirely unforseeable possibility. + QVERIFY(myvec.capacity() == 0); + + // test it gets a size + myvec << "aaa" << "bbb" << "ccc"; + QVERIFY(myvec.capacity() >= 3); + + // make sure it grows ok + myvec << "aaa" << "bbb" << "ccc"; + QVERIFY(myvec.capacity() >= 6); + + // let's try squeeze a bit + myvec.remove(3); + myvec.remove(3); + myvec.remove(3); + // TODO: is this a safe assumption? presumably it won't release memory until shrink(), but can we asser that is true? + QVERIFY(myvec.capacity() >= 6); + myvec.squeeze(); + QVERIFY(myvec.capacity() >= 3); + + myvec.remove(0); + myvec.remove(0); + myvec.remove(0); + // TODO: as above note + QVERIFY(myvec.capacity() >= 3); + myvec.squeeze(); + QVERIFY(myvec.capacity() == 0); +} + +void tst_QVector::clear() const +{ + QVector myvec; + myvec << "aaa" << "bbb" << "ccc"; + + QVERIFY(myvec.size() == 3); + myvec.clear(); + QVERIFY(myvec.size() == 0); + QVERIFY(myvec.capacity() == 0); +} + +void tst_QVector::constData() const +{ + int arr[] = { 42, 43, 44 }; + QVector myvec; + myvec << 42 << 43 << 44; + + QVERIFY(memcmp(myvec.constData(), reinterpret_cast(&arr), sizeof(int) * 3) == 0); +} + +void tst_QVector::contains() const +{ + QVector myvec; + myvec << "aaa" << "bbb" << "ccc"; + + QVERIFY(myvec.contains(QLatin1String("aaa"))); + QVERIFY(myvec.contains(QLatin1String("bbb"))); + QVERIFY(myvec.contains(QLatin1String("ccc"))); + QVERIFY(!myvec.contains(QLatin1String("I don't exist"))); + + // add it and make sure it does :) + myvec.append(QLatin1String("I don't exist")); + QVERIFY(myvec.contains(QLatin1String("I don't exist"))); +} + +void tst_QVector::count() const +{ + // total size + { + // zero size + QVector myvec; + QVERIFY(myvec.count() == 0); + + // grow + myvec.append(42); + QVERIFY(myvec.count() == 1); + myvec.append(42); + QVERIFY(myvec.count() == 2); + + // shrink + myvec.remove(0); + QVERIFY(myvec.count() == 1); + myvec.remove(0); + QVERIFY(myvec.count() == 0); + } + + // count of items + { + QVector myvec; + myvec << "aaa" << "bbb" << "ccc"; + + // initial tests + QVERIFY(myvec.count(QLatin1String("aaa")) == 1); + QVERIFY(myvec.count(QLatin1String("pirates")) == 0); + + // grow + myvec.append(QLatin1String("aaa")); + QVERIFY(myvec.count(QLatin1String("aaa")) == 2); + + // shrink + myvec.remove(0); + QVERIFY(myvec.count(QLatin1String("aaa")) == 1); + } +} + +void tst_QVector::data() const +{ + QVector myvec; + myvec << 42 << 43 << 44; + + // make sure it starts off ok + QCOMPARE(*(myvec.data() + 1), 43); + + // alter it + *(myvec.data() + 1) = 69; + + // check it altered + QCOMPARE(*(myvec.data() + 1), 69); + + int arr[] = { 42, 69, 44 }; + QVERIFY(memcmp(myvec.data(), reinterpret_cast(&arr), sizeof(int) * 3) == 0); +} + +void tst_QVector::empty() const +{ + QVector myvec; + + // starts empty + QVERIFY(myvec.empty()); + + // not empty + myvec.append(1); + QVERIFY(!myvec.empty()); + + // empty again + myvec.remove(0); + QVERIFY(myvec.empty()); +} + +void tst_QVector::endsWith() const +{ + QVector myvec; + + // empty vector + QVERIFY(!myvec.endsWith(1)); + + // add the one, should work + myvec.append(1); + QVERIFY(myvec.endsWith(1)); + + // add something else, fails now + myvec.append(3); + QVERIFY(!myvec.endsWith(1)); + + // remove it again :) + myvec.remove(1); + QVERIFY(myvec.endsWith(1)); +} + +void tst_QVector::fill() const +{ + QVector myvec; + + // resize + myvec.resize(5); + myvec.fill(69); + QCOMPARE(myvec, QVector() << 69 << 69 << 69 << 69 << 69); + + // make sure it can resize itself too + myvec.fill(42, 10); + QCOMPARE(myvec, QVector() << 42 << 42 << 42 << 42 << 42 << 42 << 42 << 42 << 42 << 42); +} + +void tst_QVector::first() const +{ + QVector myvec; + myvec << 69 << 42 << 3; + + // test it starts ok + QCOMPARE(myvec.first(), 69); + + // test removal changes + myvec.remove(0); + QCOMPARE(myvec.first(), 42); + + // test prepend changes + myvec.prepend(23); + QCOMPARE(myvec.first(), 23); +} + +void tst_QVector::fromList() const +{ + QList list; + list << "aaa" << "bbb" << "ninjas" << "pirates"; + + QVector myvec; + myvec = QVector::fromList(list); + + // test it worked ok + QCOMPARE(myvec, QVector() << "aaa" << "bbb" << "ninjas" << "pirates"); + QCOMPARE(list, QList() << "aaa" << "bbb" << "ninjas" << "pirates"); +} + +void tst_QVector::fromStdVector() const +{ + // stl = :( + std::vector svec; + svec.push_back(QLatin1String("aaa")); + svec.push_back(QLatin1String("bbb")); + svec.push_back(QLatin1String("ninjas")); + svec.push_back(QLatin1String("pirates")); + QVector myvec = QVector::fromStdVector(svec); + + // test it converts ok + QCOMPARE(myvec, QVector() << "aaa" << "bbb" << "ninjas" << "pirates"); +} + +void tst_QVector::indexOf() const +{ + QVector myvec; + myvec << "A" << "B" << "C" << "B" << "A"; + + QVERIFY(myvec.indexOf("B") == 1); + QVERIFY(myvec.indexOf("B", 1) == 1); + QVERIFY(myvec.indexOf("B", 2) == 3); + QVERIFY(myvec.indexOf("X") == -1); + QVERIFY(myvec.indexOf("X", 2) == -1); + + // add an X + myvec << "X"; + QVERIFY(myvec.indexOf("X") == 5); + QVERIFY(myvec.indexOf("X", 5) == 5); + QVERIFY(myvec.indexOf("X", 6) == -1); + + // remove first A + myvec.remove(0); + QVERIFY(myvec.indexOf("A") == 3); + QVERIFY(myvec.indexOf("A", 3) == 3); + QVERIFY(myvec.indexOf("A", 4) == -1); +} + +void tst_QVector::insert() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + // first position + QCOMPARE(myvec.at(0), QLatin1String("A")); + myvec.insert(0, QLatin1String("X")); + QCOMPARE(myvec.at(0), QLatin1String("X")); + QCOMPARE(myvec.at(1), QLatin1String("A")); + + // middle + myvec.insert(1, QLatin1String("Z")); + QCOMPARE(myvec.at(0), QLatin1String("X")); + QCOMPARE(myvec.at(1), QLatin1String("Z")); + QCOMPARE(myvec.at(2), QLatin1String("A")); + + // end + myvec.insert(5, QLatin1String("T")); + QCOMPARE(myvec.at(5), QLatin1String("T")); + QCOMPARE(myvec.at(4), QLatin1String("C")); + + // insert a lot of garbage in the middle + myvec.insert(2, 2, QLatin1String("infinity")); + QCOMPARE(myvec, QVector() << "X" << "Z" << "infinity" << "infinity" + << "A" << "B" << "C" << "T"); +} + +void tst_QVector::isEmpty() const +{ + QVector myvec; + + // starts ok + QVERIFY(myvec.isEmpty()); + + // not empty now + myvec.append(QLatin1String("hello there")); + QVERIFY(!myvec.isEmpty()); + + // empty again + myvec.remove(0); + QVERIFY(myvec.isEmpty()); +} + +void tst_QVector::last() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + // test starts ok + QCOMPARE(myvec.last(), QLatin1String("C")); + + // test it changes ok + myvec.append(QLatin1String("X")); + QCOMPARE(myvec.last(), QLatin1String("X")); + + // and remove again + myvec.remove(3); + QCOMPARE(myvec.last(), QLatin1String("C")); +} + +void tst_QVector::lastIndexOf() const +{ + QVector myvec; + myvec << "A" << "B" << "C" << "B" << "A"; + + QVERIFY(myvec.lastIndexOf("B") == 3); + QVERIFY(myvec.lastIndexOf("B", 2) == 1); + QVERIFY(myvec.lastIndexOf("X") == -1); + QVERIFY(myvec.lastIndexOf("X", 2) == -1); + + // add an X + myvec << "X"; + QVERIFY(myvec.lastIndexOf("X") == 5); + QVERIFY(myvec.lastIndexOf("X", 5) == 5); + QVERIFY(myvec.lastIndexOf("X", 3) == -1); + + // remove first A + myvec.remove(0); + QVERIFY(myvec.lastIndexOf("A") == 3); + QVERIFY(myvec.lastIndexOf("A", 3) == 3); + QVERIFY(myvec.lastIndexOf("A", 2) == -1); +} + +void tst_QVector::mid() const +{ + QVector list; + list << "foo" << "bar" << "baz" << "bak" << "buck" << "hello" << "kitty"; + + QCOMPARE(list.mid(3, 3), QVector() << "bak" << "buck" << "hello"); + QCOMPARE(list.mid(4), QVector() << "buck" << "hello" << "kitty"); +} + +void tst_QVector::prepend() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + // starts ok + QVERIFY(myvec.size() == 3); + QCOMPARE(myvec.at(0), QLatin1String("A")); + + // add something + myvec.prepend(QLatin1String("X")); + QCOMPARE(myvec.at(0), QLatin1String("X")); + QCOMPARE(myvec.at(1), QLatin1String("A")); + QVERIFY(myvec.size() == 4); + + // something else + myvec.prepend(QLatin1String("Z")); + QCOMPARE(myvec.at(0), QLatin1String("Z")); + QCOMPARE(myvec.at(1), QLatin1String("X")); + QCOMPARE(myvec.at(2), QLatin1String("A")); + QVERIFY(myvec.size() == 5); + + // clear and append to an empty vector + myvec.clear(); + QVERIFY(myvec.size() == 0); + myvec.prepend(QLatin1String("ninjas")); + QVERIFY(myvec.size() == 1); + QCOMPARE(myvec.at(0), QLatin1String("ninjas")); +} + +void tst_QVector::remove() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + // remove middle + myvec.remove(1); + QCOMPARE(myvec, QVector() << "A" << "C"); + + // remove rest + myvec.remove(0, 2); + QCOMPARE(myvec, QVector()); +} + +// ::reserve() is really hard to think of tests for, so not doing it. +// ::resize() is tested in ::capacity(). + +void tst_QVector::size() const +{ + // total size + { + // zero size + QVector myvec; + QVERIFY(myvec.size() == 0); + + // grow + myvec.append(42); + QVERIFY(myvec.size() == 1); + myvec.append(42); + QVERIFY(myvec.size() == 2); + + // shrink + myvec.remove(0); + QVERIFY(myvec.size() == 1); + myvec.remove(0); + QVERIFY(myvec.size() == 0); + } +} + +// ::squeeze() is tested in ::capacity(). + +void tst_QVector::startsWith() const +{ + QVector myvec; + + // empty vector + QVERIFY(!myvec.startsWith(1)); + + // add the one, should work + myvec.prepend(1); + QVERIFY(myvec.startsWith(1)); + + // add something else, fails now + myvec.prepend(3); + QVERIFY(!myvec.startsWith(1)); + + // remove it again :) + myvec.remove(0); + QVERIFY(myvec.startsWith(1)); +} + +void tst_QVector::toList() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + // make sure it converts and doesn't modify the original vector + QCOMPARE(myvec.toList(), QList() << "A" << "B" << "C"); + QCOMPARE(myvec, QVector() << "A" << "B" << "C"); +} + +void tst_QVector::toStdVector() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + std::vector svec = myvec.toStdVector(); + QCOMPARE(svec.at(0), QLatin1String("A")); + QCOMPARE(svec.at(1), QLatin1String("B")); + QCOMPARE(svec.at(2), QLatin1String("C")); + + QCOMPARE(myvec, QVector() << "A" << "B" << "C"); +} + +void tst_QVector::value() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + + // valid calls + QCOMPARE(myvec.value(0), QLatin1String("A")); + QCOMPARE(myvec.value(1), QLatin1String("B")); + QCOMPARE(myvec.value(2), QLatin1String("C")); + + // default calls + QCOMPARE(myvec.value(-1), QString()); + QCOMPARE(myvec.value(3), QString()); + + // test calls with a provided default, valid calls + QCOMPARE(myvec.value(0, QLatin1String("default")), QLatin1String("A")); + QCOMPARE(myvec.value(1, QLatin1String("default")), QLatin1String("B")); + QCOMPARE(myvec.value(2, QLatin1String("default")), QLatin1String("C")); + + // test calls with a provided default that will return the default + QCOMPARE(myvec.value(-1, QLatin1String("default")), QLatin1String("default")); + QCOMPARE(myvec.value(3, QLatin1String("default")), QLatin1String("default")); +} + +void tst_QVector::testOperators() const +{ + QVector myvec; + myvec << "A" << "B" << "C"; + QVector myvectwo; + myvectwo << "D" << "E" << "F"; + QVector combined; + combined << "A" << "B" << "C" << "D" << "E" << "F"; + + // != + QVERIFY(myvec != myvectwo); + + // + + QCOMPARE(myvec + myvectwo, combined); + QCOMPARE(myvec, QVector() << "A" << "B" << "C"); + QCOMPARE(myvectwo, QVector() << "D" << "E" << "F"); + + // += + myvec += myvectwo; + QCOMPARE(myvec, combined); + + // == + QVERIFY(myvec == combined); + + // [] + QCOMPARE(myvec[0], QLatin1String("A")); + QCOMPARE(myvec[1], QLatin1String("B")); + QCOMPARE(myvec[2], QLatin1String("C")); + QCOMPARE(myvec[3], QLatin1String("D")); + QCOMPARE(myvec[4], QLatin1String("E")); + QCOMPARE(myvec[5], QLatin1String("F")); +} + + int fooCtor; int fooDtor; -- cgit v0.12 From 3eded761167af317bab4f4d8c1ac0a12433eb03a Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Wed, 28 Apr 2010 03:50:42 +0200 Subject: A small mistake when comparing the flag. Qt::NoTextInteraction is equal to 0 so you can't compare using & because it will always be false even if the flag is set. Reviewed-by:janarve --- src/gui/text/qtextcontrol.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index 3c596e5..a2ee659 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -885,8 +885,10 @@ void QTextControl::processEvent(QEvent *e, const QPointF &coordinateOffset, QWid void QTextControl::processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget) { Q_D(QTextControl); - if (d->interactionFlags & Qt::NoTextInteraction) + if (d->interactionFlags == Qt::NoTextInteraction) { + e->ignore(); return; + } d->contextWidget = contextWidget; -- cgit v0.12 From f35b1fd3807c634f5fe60efecd401db7683a37fb Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 28 Apr 2010 11:52:33 +0200 Subject: Revert "Try to use multisampled opengl graphicssystem on all platforms" This reverts commit 5f63f95def838ce72af99dc697ecce092fe7eb69. Fixes GL graphics system on Windows. With the patch, windows would pop up as completely empty. --- src/opengl/qwindowsurface_gl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 92a347b..7efa9bc 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -97,7 +97,6 @@ extern Q_GUI_EXPORT bool qt_win_owndc_required; QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL) : QGraphicsSystem(), m_useX11GL(useX11GL) { - QGLWindowSurface::surfaceFormat.setSampleBuffers(true); #if defined(Q_WS_X11) && !defined(QT_OPENGL_ES) // only override the system defaults if the user hasn't already // picked a visual -- cgit v0.12 From 18480fd6cec52722d9d096991790e32837a7ebd8 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Wed, 28 Apr 2010 11:05:29 +0200 Subject: Null pointer check Fixes crash for certain SVGs Reviewed-by: Kim --- src/svg/qsvghandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index b6e771f..d545440 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -3751,7 +3751,7 @@ bool QSvgHandler::characters(const QStringRef &str) QCss::Parser(css).parse(&sheet); m_selector->styleSheets.append(sheet); return true; - } else if (m_skipNodes.isEmpty() || m_skipNodes.top() == Unknown) + } else if (m_skipNodes.isEmpty() || m_skipNodes.top() == Unknown || m_nodes.isEmpty()) return true; if (m_nodes.top()->type() == QSvgNode::TEXT || m_nodes.top()->type() == QSvgNode::TEXTAREA) { -- cgit v0.12 From b7496ee877e3c0eef51ba982bf7acff082e1d5a1 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 28 Apr 2010 12:36:27 +0200 Subject: Updated WebKit to 862268aeb7150d3795d05bfc05f661bb5c598a27 Integrated bugfixes: || || [RVCT] ACID3 test crash || || || Spatial Navigation: make hasOffscreenRect() to earlier return 'true' if absoluteClippedOverflowRect() gives an empty rect || || || Repaint of fixed, transformed element is broken || || || [Qt] Fix or remove the runtime flag for accelerated compositing. || || || [Qt] [Performance] GraphicsLayer: constructing the layers takes too long || || || Spatial Navigation: bail out as soon as algorithm finds a focus candidate is not applicable || || || [Qt] HTTP pipelining efficiency increase || || || Allow building smoothly on win32 and win64 using GCC || || || No default selection for menu lists. + https://bugs.webkit.org/show_bug.cgi?id=37530 + + Manual test: manual-tests/no-listbox-rendering.html + + For menu lists, if the selection is not indicated by the html file, the first